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.
33 (unless (fboundp 'declare-function
) (defmacro declare-function
(&rest r
))))
40 ;; Only for the trivial macros mail-header-from, mail-header-date
41 ;; mail-header-references, mail-header-subject, mail-header-id
42 (eval-when-compile (require 'nnheader
))
43 ;; This is apparently necessary even though things are autoloaded.
44 ;; Because we dynamically bind mail-abbrev-mode-regexp, we'd better
45 ;; require mailabbrev here.
46 (if (featurep 'xemacs
)
47 (require 'mail-abbrevs
)
48 (require 'mailabbrev
))
53 (autoload 'mailclient-send-it
"mailclient") ;; Emacs 22 or contrib/
55 (defvar gnus-message-group-art
)
56 (defvar gnus-list-identifiers
) ; gnus-sum is required where necessary
57 (defvar rmail-enable-mime-composing
)
59 (defgroup message
'((user-mail-address custom-variable
)
60 (user-full-name custom-variable
))
61 "Mail and news message composing."
62 :link
'(custom-manual "(message)Top")
66 (put 'user-mail-address
'custom-type
'string
)
67 (put 'user-full-name
'custom-type
'string
)
69 (defgroup message-various nil
70 "Various Message Variables."
71 :link
'(custom-manual "(message)Various Message Variables")
74 (defgroup message-buffers nil
76 :link
'(custom-manual "(message)Message Buffers")
79 (defgroup message-sending nil
81 :link
'(custom-manual "(message)Sending Variables")
84 (defgroup message-interface nil
86 :link
'(custom-manual "(message)Interface")
89 (defgroup message-forwarding nil
91 :link
'(custom-manual "(message)Forwarding")
92 :group
'message-interface
)
94 (defgroup message-insertion nil
96 :link
'(custom-manual "(message)Insertion")
99 (defgroup message-headers nil
101 :link
'(custom-manual "(message)Message Headers")
104 (defgroup message-news nil
105 "Composing News Messages."
108 (defgroup message-mail nil
109 "Composing Mail Messages."
112 (defgroup message-faces nil
113 "Faces used for message composing."
117 (defcustom message-directory
"~/Mail/"
118 "*Directory from which all other mail file variables are derived."
119 :group
'message-various
122 (defcustom message-max-buffers
10
123 "*How many buffers to keep before starting to kill them off."
124 :group
'message-buffers
127 (defcustom message-send-rename-function nil
128 "Function called to rename the buffer after sending it."
129 :group
'message-buffers
130 :type
'(choice function
(const nil
)))
132 (defcustom message-fcc-handler-function
'message-output
133 "*A function called to save outgoing articles.
134 This function will be called with the name of the file to store the
135 article in. The default function is `message-output' which saves in Unix
137 :type
'(radio (function-item message-output
)
138 (function :tag
"Other"))
139 :group
'message-sending
)
141 (defcustom message-fcc-externalize-attachments nil
142 "If non-nil, attachments are included as external parts in Fcc copies."
145 :group
'message-sending
)
147 (defcustom message-courtesy-message
148 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
149 "*This is inserted at the start of a mailed copy of a posted message.
150 If the string contains the format spec \"%s\", the Newsgroups
151 the article has been posted to will be inserted there.
152 If this variable is nil, no such courtesy message will be added."
153 :group
'message-sending
154 :type
'(radio string
(const nil
)))
156 (defcustom message-ignored-bounced-headers
157 "^\\(Received\\|Return-Path\\|Delivered-To\\):"
158 "*Regexp that matches headers to be removed in resent bounced mail."
159 :group
'message-interface
162 (defcustom message-from-style mail-from-style
163 ;; Default to the value of `mail-from-style', available in all Emacsen
164 ;; that Gnus supports.
165 "*Specifies how \"From\" headers look.
167 If nil, they contain just the return address like:
169 If `parens', they look like:
170 king@grassland.com (Elvis Parsley)
171 If `angles', they look like:
172 Elvis Parsley <king@grassland.com>
174 Otherwise, most addresses look like `angles', but they look like
175 `parens' if `angles' would need quoting and `parens' would not."
177 :type
'(choice (const :tag
"simple" nil
)
181 :group
'message-headers
)
183 (defcustom message-insert-canlock t
184 "Whether to insert a Cancel-Lock header in news postings."
186 :group
'message-headers
189 (defcustom message-syntax-checks
190 (if message-insert-canlock
'((sender . disabled
)) nil
)
191 ;; Guess this one shouldn't be easy to customize...
192 "*Controls what syntax checks should not be performed on outgoing posts.
193 To disable checking of long signatures, for instance, add
194 `(signature . disabled)' to this list.
196 Don't touch this variable unless you really know what you're doing.
198 Checks include `approved', `bogus-recipient', `continuation-headers',
199 `control-chars', `empty', `existing-newsgroups', `from', `illegible-text',
200 `invisible-text', `long-header-lines', `long-lines', `message-id',
201 `multiple-headers', `new-text', `newsgroups', `quoting-style',
202 `repeated-newsgroups', `reply-to', `sender', `sendsys', `shoot',
203 `shorten-followup-to', `signature', `size', `subject', `subject-cmsg'
204 and `valid-newsgroups'."
206 :type
'(repeat sexp
)) ; Fixme: improve this
208 (defcustom message-required-headers
'((optional . References
)
210 "*Headers to be generated or prompted for when sending a message.
211 Also see `message-required-news-headers' and
212 `message-required-mail-headers'."
215 :group
'message-headers
216 :link
'(custom-manual "(message)Message Headers")
217 :type
'(repeat sexp
))
219 (defcustom message-draft-headers
'(References From Date
)
220 "*Headers to be generated when saving a draft message."
223 :group
'message-headers
224 :link
'(custom-manual "(message)Message Headers")
225 :type
'(repeat sexp
))
227 (defcustom message-required-news-headers
228 '(From Newsgroups Subject Date Message-ID
229 (optional . Organization
)
230 (optional . User-Agent
))
231 "*Headers to be generated or prompted for when posting an article.
232 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
233 Message-ID. Organization, Lines, In-Reply-To, Expires, and
234 User-Agent are optional. If you don't want message to insert some
235 header, remove it from this list."
237 :group
'message-headers
238 :link
'(custom-manual "(message)Message Headers")
239 :type
'(repeat sexp
))
241 (defcustom message-required-mail-headers
242 '(From Subject Date
(optional . In-Reply-To
) Message-ID
243 (optional . User-Agent
))
244 "*Headers to be generated or prompted for when mailing a message.
245 It is recommended that From, Date, To, Subject and Message-ID be
246 included. Organization and User-Agent are optional."
248 :group
'message-headers
249 :link
'(custom-manual "(message)Message Headers")
250 :type
'(repeat sexp
))
252 (defcustom message-prune-recipient-rules nil
253 "Rules for how to prune the list of recipients when doing wide replies.
254 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:"
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
'ask
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 ;; Default to the value of `mail-interactive', available in all Emacsen
449 ;; that Gnus supports.
450 "Non-nil means when sending a message wait for and display errors.
451 A value of nil means let mailer mail back a message to report errors."
453 :group
'message-sending
455 :link
'(custom-manual "(message)Sending Variables")
458 (defcustom message-confirm-send nil
459 "When non-nil, ask for confirmation when sending a message."
460 :group
'message-sending
462 :version
"23.1" ;; No Gnus
463 :link
'(custom-manual "(message)Sending Variables")
466 (defcustom message-generate-new-buffers
'unique
467 "*Say whether to create a new message buffer to compose a message.
468 Valid values include:
471 Generate the buffer name in the Message way (e.g., *mail*, *news*,
472 *mail to whom*, *news on group*, etc.) and continue editing in the
473 existing buffer of that name. If there is no such buffer, it will
477 Create the new buffer with the name generated in the Message way.
480 Similar to `unique' but the buffer name begins with \"*unsent \".
483 Similar to nil but the buffer name is simpler like *mail message*.
486 If this is a function, call that function with three parameters:
487 The type, the To address and the group name (any of these may be nil).
488 The function should return the new buffer name."
489 :group
'message-buffers
490 :link
'(custom-manual "(message)Message Buffers")
491 :type
'(choice (const nil
)
492 (sexp :tag
"unique" :format
"unique\n" :value unique
493 :match
(lambda (widget value
) (memq value
'(unique t
))))
496 (function :format
"\n %{%t%}: %v")))
498 (defcustom message-kill-buffer-on-exit nil
499 "*Non-nil means that the message buffer will be killed after sending a message."
500 :group
'message-buffers
501 :link
'(custom-manual "(message)Message Buffers")
504 (defcustom message-kill-buffer-query t
505 "*Non-nil means that killing a modified message buffer has to be confirmed.
506 This is used by `message-kill-buffer'."
507 :version
"23.1" ;; No Gnus
508 :group
'message-buffers
511 (defvar gnus-local-organization
)
512 (defcustom message-user-organization
513 (or (and (boundp 'gnus-local-organization
)
514 (stringp gnus-local-organization
)
515 gnus-local-organization
)
516 (getenv "ORGANIZATION")
518 "*String to be used as an Organization header.
519 If t, use `message-user-organization-file'."
520 :group
'message-headers
521 :type
'(choice string
522 (const :tag
"consult file" t
)))
524 (defcustom message-user-organization-file
526 (dolist (f (list "/etc/organization"
527 "/etc/news/organization"
528 "/usr/lib/news/organization"))
529 (when (file-readable-p f
)
532 "*Local news organization file."
534 :link
'(custom-manual "(message)News Headers")
535 :group
'message-headers
)
537 (defcustom message-make-forward-subject-function
538 #'message-forward-subject-name-subject
539 "*List of functions called to generate subject headers for forwarded messages.
540 The subject generated by the previous function is passed into each
543 The provided functions are:
545 * `message-forward-subject-author-subject' Source of article (author or
546 newsgroup), in brackets followed by the subject
547 * `message-forward-subject-name-subject' Source of article (name of author
548 or newsgroup), in brackets followed by the subject
549 * `message-forward-subject-fwd' Subject of article with 'Fwd:' prepended
551 :group
'message-forwarding
552 :link
'(custom-manual "(message)Forwarding")
553 :type
'(radio (function-item message-forward-subject-author-subject
)
554 (function-item message-forward-subject-fwd
)
555 (function-item message-forward-subject-name-subject
)
556 (repeat :tag
"List of functions" function
)))
558 (defcustom message-forward-as-mime t
559 "*Non-nil means forward messages as an inline/rfc822 MIME section.
560 Otherwise, directly inline the old message in the forwarded message."
562 :group
'message-forwarding
563 :link
'(custom-manual "(message)Forwarding")
566 (defcustom message-forward-show-mml
'best
567 "*Non-nil means show forwarded messages as MML (decoded from MIME).
568 Otherwise, forwarded messages are unchanged.
569 Can also be the symbol `best' to indicate that MML should be
570 used, except when it is a bad idea to use MML. One example where
571 it is a bad idea is when forwarding a signed or encrypted
572 message, because converting MIME to MML would invalidate the
575 :group
'message-forwarding
576 :type
'(choice (const :tag
"use MML" t
)
577 (const :tag
"don't use MML " nil
)
578 (const :tag
"use MML when appropriate" best
)))
580 (defcustom message-forward-before-signature t
581 "*Non-nil means put forwarded message before signature, else after."
582 :group
'message-forwarding
585 (defcustom message-wash-forwarded-subjects nil
586 "*Non-nil means try to remove as much cruft as possible from the subject.
587 Done before generating the new subject of a forward."
588 :group
'message-forwarding
589 :link
'(custom-manual "(message)Forwarding")
592 (defcustom message-ignored-resent-headers
593 ;; `Delivered-To' needs to be removed because some mailers use it to
594 ;; detect loops, so if you resend a message to an address that ultimately
595 ;; comes back to you (e.g. a mailing-list to which you subscribe, in which
596 ;; case you may be removed from the list on the grounds that mail to you
597 ;; bounced with a "mailing loop" error).
598 "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From \\|^Delivered-To:"
599 "*All headers that match this regexp will be deleted when resending a message."
600 :group
'message-interface
601 :link
'(custom-manual "(message)Resending")
602 :type
'(repeat :value-to-internal
(lambda (widget value
)
603 (custom-split-regexp-maybe value
))
604 :match
(lambda (widget value
)
606 (widget-editable-list-match widget value
)))
609 (defcustom message-forward-ignored-headers
"^Content-Transfer-Encoding:\\|^X-Gnus"
610 "*All headers that match this regexp will be deleted when forwarding a message."
612 :group
'message-forwarding
613 :type
'(repeat :value-to-internal
(lambda (widget value
)
614 (custom-split-regexp-maybe value
))
615 :match
(lambda (widget value
)
617 (widget-editable-list-match widget value
)))
620 (defcustom message-ignored-cited-headers
"."
621 "*Delete these headers from the messages you yank."
622 :group
'message-insertion
623 :link
'(custom-manual "(message)Insertion Variables")
626 (defcustom message-cite-prefix-regexp
627 ;; Default to the value of `mail-citation-prefix-regexp' if available.
628 ;; Note: as for Emacs 21, XEmacs 21.4 and 21.5, it is unavailable
629 ;; unless sendmail.el is loaded.
630 (cond ((boundp 'mail-citation-prefix-regexp
)
631 mail-citation-prefix-regexp
)
632 ((string-match "[[:digit:]]" "1")
633 ;; Support POSIX? XEmacs 21.5.27 doesn't.
634 "\\([ \t]*[_.[:word:]]+>+\\|[ \t]*[]>|}]\\)+")
636 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
637 (let (non-word-constituents)
638 (with-syntax-table text-mode-syntax-table
639 (setq non-word-constituents
641 (if (string-match "\\w" "_") "" "_")
642 (if (string-match "\\w" ".") "" "."))))
643 (if (equal non-word-constituents
"")
644 "\\([ \t]*\\(\\w\\)+>+\\|[ \t]*[]>|}]\\)+"
645 (concat "\\([ \t]*\\(\\w\\|["
646 non-word-constituents
647 "]\\)+>+\\|[ \t]*[]>|}]\\)+")))))
648 "*Regexp matching the longest possible citation prefix on a line."
650 :group
'message-insertion
651 :link
'(custom-manual "(message)Insertion Variables")
653 :set
(lambda (symbol value
)
655 (custom-set-default symbol value
)
656 (if (boundp 'gnus-message-cite-prefix-regexp
)
657 (setq gnus-message-cite-prefix-regexp
658 (concat "^\\(?:" value
"\\)"))))))
660 (defcustom message-cancel-message
"I am canceling my own article.\n"
661 "Message to be inserted in the cancel message."
662 :group
'message-interface
663 :link
'(custom-manual "(message)Canceling News")
666 (defun message-send-mail-function ()
667 "Return suitable value for the variable `message-send-mail-function'."
668 (cond ((and (require 'sendmail
)
669 (boundp 'sendmail-program
)
671 (executable-find sendmail-program
))
672 'message-send-mail-with-sendmail
)
673 ((and (locate-library "smtpmail")
674 (boundp 'smtpmail-default-smtp-server
)
675 smtpmail-default-smtp-server
)
676 'message-smtpmail-send-it
)
677 ((locate-library "mailclient")
678 'message-send-mail-with-mailclient
)
680 (error "Don't know how to send mail. Please customize `message-send-mail-function'"))))
682 ;; Useful to set in site-init.el
683 (defcustom message-send-mail-function
684 (cond ((eq send-mail-function
'smtpmail-send-it
) 'message-smtpmail-send-it
)
685 ((eq send-mail-function
'feedmail-send-it
) 'feedmail-send-it
)
686 ((eq send-mail-function
'mailclient-send-it
)
687 'message-send-mail-with-mailclient
)
688 (t (message-send-mail-function)))
689 "Function to call to send the current buffer as mail.
690 The headers should be delimited by a line whose contents match the
691 variable `mail-header-separator'.
693 Valid values include `message-send-mail-with-sendmail'
694 `message-send-mail-with-mh', `message-send-mail-with-qmail',
695 `message-smtpmail-send-it', `smtpmail-send-it',
696 `feedmail-send-it' and `message-send-mail-with-mailclient'. The
697 default is system dependent and determined by the function
698 `message-send-mail-function'.
700 See also `send-mail-function'."
701 :type
'(radio (function-item message-send-mail-with-sendmail
)
702 (function-item message-send-mail-with-mh
)
703 (function-item message-send-mail-with-qmail
)
704 (function-item message-smtpmail-send-it
)
705 (function-item smtpmail-send-it
)
706 (function-item feedmail-send-it
)
707 (function-item message-send-mail-with-mailclient
708 :tag
"Use Mailclient package")
709 (function :tag
"Other"))
710 :group
'message-sending
712 :initialize
'custom-initialize-default
713 :link
'(custom-manual "(message)Mail Variables")
714 :group
'message-mail
)
716 (defcustom message-send-news-function
'message-send-news
717 "Function to call to send the current buffer as news.
718 The headers should be delimited by a line whose contents match the
719 variable `mail-header-separator'."
720 :group
'message-sending
722 :link
'(custom-manual "(message)News Variables")
725 (defcustom message-reply-to-function nil
726 "If non-nil, function that should return a list of headers.
727 This function should pick out addresses from the To, Cc, and From headers
728 and respond with new To and Cc headers."
729 :group
'message-interface
730 :link
'(custom-manual "(message)Reply")
731 :type
'(choice function
(const nil
)))
733 (defcustom message-wide-reply-to-function nil
734 "If non-nil, function that should return a list of headers.
735 This function should pick out addresses from the To, Cc, and From headers
736 and respond with new To and Cc headers."
737 :group
'message-interface
738 :link
'(custom-manual "(message)Wide Reply")
739 :type
'(choice function
(const nil
)))
741 (defcustom message-followup-to-function nil
742 "If non-nil, function that should return a list of headers.
743 This function should pick out addresses from the To, Cc, and From headers
744 and respond with new To and Cc headers."
745 :group
'message-interface
746 :link
'(custom-manual "(message)Followup")
747 :type
'(choice function
(const nil
)))
749 (defcustom message-extra-wide-headers nil
750 "If non-nil, a list of additional address headers.
751 These are used when composing a wide reply."
752 :group
'message-sending
753 :type
'(repeat string
))
755 (defcustom message-use-followup-to
'ask
756 "*Specifies what to do with Followup-To header.
757 If nil, always ignore the header. If it is t, use its value, but
758 query before using the \"poster\" value. If it is the symbol `ask',
759 always query the user whether to use the value. If it is the symbol
760 `use', always use the value."
761 :group
'message-interface
762 :link
'(custom-manual "(message)Followup")
763 :type
'(choice (const :tag
"ignore" nil
)
764 (const :tag
"use & query" t
)
768 (defcustom message-use-mail-followup-to
'use
769 "*Specifies what to do with Mail-Followup-To header.
770 If nil, always ignore the header. If it is the symbol `ask', always
771 query the user whether to use the value. If it is the symbol `use',
772 always use the value."
774 :group
'message-interface
775 :link
'(custom-manual "(message)Mailing Lists")
776 :type
'(choice (const :tag
"ignore" nil
)
780 (defcustom message-subscribed-address-functions nil
781 "*Specifies functions for determining list subscription.
782 If nil, do not attempt to determine list subscription with functions.
783 If non-nil, this variable contains a list of functions which return
784 regular expressions to match lists. These functions can be used in
785 conjunction with `message-subscribed-regexps' and
786 `message-subscribed-addresses'."
788 :group
'message-interface
789 :link
'(custom-manual "(message)Mailing Lists")
790 :type
'(repeat sexp
))
792 (defcustom message-subscribed-address-file nil
793 "*A file containing addresses the user is subscribed to.
794 If nil, do not look at any files to determine list subscriptions. If
795 non-nil, each line of this file should be a mailing list address."
797 :group
'message-interface
798 :link
'(custom-manual "(message)Mailing Lists")
799 :type
'(radio file
(const nil
)))
801 (defcustom message-subscribed-addresses nil
802 "*Specifies a list of addresses the user is subscribed to.
803 If nil, do not use any predefined list subscriptions. This list of
804 addresses can be used in conjunction with
805 `message-subscribed-address-functions' and `message-subscribed-regexps'."
807 :group
'message-interface
808 :link
'(custom-manual "(message)Mailing Lists")
809 :type
'(repeat string
))
811 (defcustom message-subscribed-regexps nil
812 "*Specifies a list of addresses the user is subscribed to.
813 If nil, do not use any predefined list subscriptions. This list of
814 regular expressions can be used in conjunction with
815 `message-subscribed-address-functions' and `message-subscribed-addresses'."
817 :group
'message-interface
818 :link
'(custom-manual "(message)Mailing Lists")
819 :type
'(repeat regexp
))
821 (defcustom message-allow-no-recipients
'ask
822 "Specifies what to do when there are no recipients other than Gcc/Fcc.
823 If it is the symbol `always', the posting is allowed. If it is the
824 symbol `never', the posting is not allowed. If it is the symbol
825 `ask', you are prompted."
827 :group
'message-interface
828 :link
'(custom-manual "(message)Message Headers")
829 :type
'(choice (const always
)
833 (defcustom message-sendmail-f-is-evil nil
834 "*Non-nil means don't add \"-f username\" to the sendmail command line.
835 Doing so would be even more evil than leaving it out."
836 :group
'message-sending
837 :link
'(custom-manual "(message)Mail Variables")
840 (defcustom message-sendmail-envelope-from
841 ;; Default to the value of `mail-envelope-from' if available.
842 ;; Note: as for Emacsen that Gnus supports, except for SXEmacs, it is
843 ;; unavailable unless sendmail.el is loaded.
844 (if (boundp 'mail-envelope-from
) mail-envelope-from
)
845 "*Envelope-from when sending mail with sendmail.
846 If this is nil, use `user-mail-address'. If it is the symbol
847 `header', use the From: header of the message."
849 :type
'(choice (string :tag
"From name")
850 (const :tag
"Use From: header from message" header
)
851 (const :tag
"Use `user-mail-address'" nil
))
852 :link
'(custom-manual "(message)Mail Variables")
853 :group
'message-sending
)
855 (defcustom message-sendmail-extra-arguments nil
856 "Additional arguments to `sendmail-program'."
857 ;; E.g. '("-a" "account") for msmtp
858 :version
"23.1" ;; No Gnus
859 :type
'(repeat string
)
860 ;; :link '(custom-manual "(message)Mail Variables")
861 :group
'message-sending
)
863 ;; qmail-related stuff
864 (defcustom message-qmail-inject-program
"/var/qmail/bin/qmail-inject"
865 "Location of the qmail-inject program."
866 :group
'message-sending
867 :link
'(custom-manual "(message)Mail Variables")
870 (defcustom message-qmail-inject-args nil
871 "Arguments passed to qmail-inject programs.
872 This should be a list of strings, one string for each argument.
873 It may also be a function.
875 For e.g., if you wish to set the envelope sender address so that bounces
876 go to the right place or to deal with listserv's usage of that address, you
877 might set this variable to '(\"-f\" \"you@some.where\")."
878 :group
'message-sending
879 :link
'(custom-manual "(message)Mail Variables")
880 :type
'(choice (function)
883 (defvar gnus-post-method
)
884 (defvar gnus-select-method
)
885 (defcustom message-post-method
886 (cond ((and (boundp 'gnus-post-method
)
887 (listp gnus-post-method
)
890 ((boundp 'gnus-select-method
)
893 "*Method used to post news.
894 Note that when posting from inside Gnus, for instance, this
895 variable isn't used."
897 :group
'message-sending
898 ;; This should be the `gnus-select-method' widget, but that might
899 ;; create a dependence to `gnus.el'.
902 ;; FIXME: This should be a temporary workaround until someone implements a
903 ;; proper solution. If a crash happens while replying, the auto-save file
904 ;; will *not* have a `References:' header if `message-generate-headers-first'
905 ;; is nil. See: http://article.gmane.org/gmane.emacs.gnus.general/51138
906 (defcustom message-generate-headers-first
'(references)
907 "Which headers should be generated before starting to compose a message.
908 If t, generate all required headers. This can also be a list of headers to
909 generate. The variables `message-required-news-headers' and
910 `message-required-mail-headers' specify which headers to generate.
912 Note that the variable `message-deletable-headers' specifies headers which
913 are to be deleted and then re-generated before sending, so this variable
914 will not have a visible effect for those headers."
915 :group
'message-headers
916 :link
'(custom-manual "(message)Message Headers")
917 :type
'(choice (const :tag
"None" nil
)
918 (const :tag
"References" '(references))
920 (repeat (sexp :tag
"Header"))))
922 (defcustom message-fill-column
72
923 "Column beyond which automatic line-wrapping should happen.
924 Local value for message buffers. If non-nil, also turn on
925 auto-fill in message buffers."
926 :group
'message-various
927 ;; :link '(custom-manual "(message)Message Headers")
928 :type
'(choice (const :tag
"Don't turn on auto fill" nil
)
931 (defcustom message-setup-hook nil
932 "Normal hook, run each time a new outgoing message is initialized.
933 The function `message-setup' runs this hook."
934 :group
'message-various
935 :link
'(custom-manual "(message)Various Message Variables")
938 (defcustom message-cancel-hook nil
939 "Hook run when cancelling articles."
940 :group
'message-various
941 :link
'(custom-manual "(message)Various Message Variables")
944 (defcustom message-signature-setup-hook nil
945 "Normal hook, run each time a new outgoing message is initialized.
946 It is run after the headers have been inserted and before
947 the signature is inserted."
948 :group
'message-various
949 :link
'(custom-manual "(message)Various Message Variables")
952 (defcustom message-mode-hook nil
953 "Hook run in message mode buffers."
954 :group
'message-various
957 (defcustom message-header-hook nil
958 "Hook run in a message mode buffer narrowed to the headers."
959 :group
'message-various
962 (defcustom message-header-setup-hook nil
963 "Hook called narrowed to the headers when setting up a message buffer."
964 :group
'message-various
965 :link
'(custom-manual "(message)Various Message Variables")
968 (defcustom message-minibuffer-local-map
969 (let ((map (make-sparse-keymap 'message-minibuffer-local-map
)))
970 (set-keymap-parent map minibuffer-local-map
)
972 "Keymap for `message-read-from-minibuffer'."
974 :group
'message-various
)
976 (defcustom message-citation-line-function
'message-insert-citation-line
977 "*Function called to insert the \"Whomever writes:\" line.
979 Predefined functions include `message-insert-citation-line' and
980 `message-insert-formatted-citation-line' (see the variable
981 `message-citation-line-format').
983 Note that Gnus provides a feature where the reader can click on
984 `writes:' to hide the cited text. If you change this line too much,
985 people who read your message will have to change their Gnus
986 configuration. See the variable `gnus-cite-attribution-suffix'."
988 (function-item :tag
"plain" message-insert-citation-line
)
989 (function-item :tag
"formatted" message-insert-formatted-citation-line
)
990 (function :tag
"Other"))
991 :link
'(custom-manual "(message)Insertion Variables")
992 :group
'message-insertion
)
994 (defcustom message-citation-line-format
"On %a, %b %d %Y, %N wrote:\n"
995 "Format of the \"Whomever writes:\" line.
997 The string is formatted using `format-spec'. The following
998 constructs are replaced:
1000 %f The full From, e.g. \"John Doe <john.doe@example.invalid>\".
1001 %n The mail address, e.g. \"john.doe@example.invalid\".
1002 %N The real name if present, e.g.: \"John Doe\", else fall
1003 back to the mail address.
1004 %F The first name if present, e.g.: \"John\".
1005 %L The last name if present, e.g.: \"Doe\".
1007 All other format specifiers are passed to `format-time-string'
1008 which is called using the date from the article your replying to.
1009 Extracting the first (%F) and last name (%L) is done
1010 heuristically, so you should always check it yourself.
1012 Please also read the note in the documentation of
1013 `message-citation-line-function'."
1014 :type
'(choice (const :tag
"Plain" "%f writes:")
1015 (const :tag
"Include date" "On %a, %b %d %Y, %n wrote:")
1017 :link
'(custom-manual "(message)Insertion Variables")
1018 :version
"23.1" ;; No Gnus
1019 :group
'message-insertion
)
1021 (defcustom message-yank-prefix
1022 ;; Default to the value of `mail-yank-prefix' if available.
1023 ;; Note: as for Emacs 21, it is unavailable unless sendmail.el is loaded.
1024 (if (boundp 'mail-yank-prefix
) mail-yank-prefix
"> ")
1025 "*Prefix inserted on the lines of yanked messages.
1026 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1027 See also `message-yank-cited-prefix' and `message-yank-empty-prefix'."
1030 :link
'(custom-manual "(message)Insertion Variables")
1031 :group
'message-insertion
)
1033 (defcustom message-yank-cited-prefix
">"
1034 "*Prefix inserted on cited lines of yanked messages.
1035 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1036 See also `message-yank-prefix' and `message-yank-empty-prefix'."
1039 :link
'(custom-manual "(message)Insertion Variables")
1040 :group
'message-insertion
)
1042 (defcustom message-yank-empty-prefix
">"
1043 "*Prefix inserted on empty lines of yanked messages.
1044 See also `message-yank-prefix' and `message-yank-cited-prefix'."
1047 :link
'(custom-manual "(message)Insertion Variables")
1048 :group
'message-insertion
)
1050 (defcustom message-indentation-spaces
1051 ;; Default to the value of `mail-indentation-spaces' if available.
1052 ;; Note: as for Emacs 21, XEmacs 21.4 and 21.5, it is unavailable
1053 ;; unless sendmail.el is loaded.
1054 (if (boundp 'mail-indentation-spaces
) mail-indentation-spaces
3)
1055 "*Number of spaces to insert at the beginning of each cited line.
1056 Used by `message-yank-original' via `message-yank-cite'."
1058 :group
'message-insertion
1059 :link
'(custom-manual "(message)Insertion Variables")
1062 (defcustom message-cite-function
'message-cite-original-without-signature
1063 "*Function for citing an original message.
1064 Predefined functions include `message-cite-original' and
1065 `message-cite-original-without-signature'.
1066 Note that these functions use `mail-citation-hook' if that is non-nil."
1067 :type
'(radio (function-item message-cite-original
)
1068 (function-item message-cite-original-without-signature
)
1069 (function-item sc-cite-original
)
1070 (function :tag
"Other"))
1071 :link
'(custom-manual "(message)Insertion Variables")
1072 :version
"22.3" ;; Gnus 5.10.12 (changed default)
1073 :group
'message-insertion
)
1075 (defcustom message-indent-citation-function
'message-indent-citation
1076 "*Function for modifying a citation just inserted in the mail buffer.
1077 This can also be a list of functions. Each function can find the
1078 citation between (point) and (mark t). And each function should leave
1079 point and mark around the citation text as modified."
1081 :link
'(custom-manual "(message)Insertion Variables")
1082 :group
'message-insertion
)
1084 (defcustom message-signature mail-signature
1085 ;; Default to the value of `mail-signature', available in all Emacsen
1086 ;; that Gnus supports.
1087 "*String to be inserted at the end of the message buffer.
1088 If t, the `message-signature-file' file will be inserted instead.
1089 If a function, the result from the function will be used instead.
1090 If a form, the result from the form will be used instead."
1093 :link
'(custom-manual "(message)Insertion Variables")
1094 :group
'message-insertion
)
1096 (defcustom message-signature-file
1097 ;; Default to the value of `mail-signature-file' if available.
1098 ;; Note: as for Emacs 21, XEmacs 21.4 and 21.5, it is unavailable
1099 ;; unless sendmail.el is loaded.
1100 (if (boundp 'mail-signature-file
) mail-signature-file
"~/.signature")
1101 "*Name of file containing the text inserted at end of message buffer.
1102 Ignored if the named file doesn't exist.
1103 If nil, don't insert a signature.
1104 If a path is specified, the value of `message-signature-directory' is ignored,
1107 :type
'(choice file
(const :tags
"None" nil
))
1108 :link
'(custom-manual "(message)Insertion Variables")
1109 :group
'message-insertion
)
1111 (defcustom message-signature-directory nil
1112 "*Name of directory containing signature files.
1113 Comes in handy if you have many such files, handled via posting styles for
1115 If nil, `message-signature-file' is expected to specify the directory if
1117 :type
'(choice string
(const :tags
"None" nil
))
1118 :link
'(custom-manual "(message)Insertion Variables")
1119 :group
'message-insertion
)
1121 (defcustom message-signature-insert-empty-line t
1122 "*If non-nil, insert an empty line before the signature separator."
1125 :link
'(custom-manual "(message)Insertion Variables")
1126 :group
'message-insertion
)
1128 (defcustom message-distribution-function nil
1129 "*Function called to return a Distribution header."
1130 :group
'message-news
1131 :group
'message-headers
1132 :link
'(custom-manual "(message)News Headers")
1133 :type
'(choice function
(const nil
)))
1135 (defcustom message-expires
14
1136 "Number of days before your article expires."
1137 :group
'message-news
1138 :group
'message-headers
1139 :link
'(custom-manual "(message)News Headers")
1142 (defcustom message-user-path nil
1143 "If nil, use the NNTP server name in the Path header.
1144 If stringp, use this; if non-nil, use no host name (user name only)."
1145 :group
'message-news
1146 :group
'message-headers
1147 :link
'(custom-manual "(message)News Headers")
1148 :type
'(choice (const :tag
"nntp" nil
)
1149 (string :tag
"name")
1150 (sexp :tag
"none" :format
"%t" t
)))
1152 ;; This can be the name of a buffer, or a cons cell (FUNCTION . ARGS)
1153 ;; for yanking the original buffer.
1154 (defvar message-reply-buffer nil
)
1155 (defvar message-reply-headers nil
1156 "The headers of the current replied article.
1157 It is a vector of the following headers:
1158 \[number subject from date id references chars lines xref extra].")
1159 (defvar message-newsreader nil
)
1160 (defvar message-mailer nil
)
1161 (defvar message-sent-message-via nil
)
1162 (defvar message-checksum nil
)
1163 (defvar message-send-actions nil
1164 "A list of actions to be performed upon successful sending of a message.")
1165 (defvar message-exit-actions nil
1166 "A list of actions to be performed upon exiting after sending a message.")
1167 (defvar message-kill-actions nil
1168 "A list of actions to be performed before killing a message buffer.")
1169 (defvar message-postpone-actions nil
1170 "A list of actions to be performed after postponing a message.")
1172 (define-widget 'message-header-lines
'text
1173 "All header lines must be LFD terminated."
1174 :format
"%{%t%}:%n%v"
1175 :valid-regexp
"^\\'"
1176 :error
"All header lines must be newline terminated")
1178 (defcustom message-default-headers
""
1179 "*A string containing header lines to be inserted in outgoing messages.
1180 It is inserted before you edit the message, so you can edit or delete
1183 :group
'message-headers
1184 :link
'(custom-manual "(message)Message Headers")
1185 :type
'message-header-lines
)
1187 (defcustom message-default-mail-headers
1188 ;; Ease the transition from mail-mode to message-mode. See bugs#4431, 5555.
1189 (concat (if (and (boundp 'mail-default-reply-to
)
1190 (stringp mail-default-reply-to
))
1191 (format "Reply-to: %s\n" mail-default-reply-to
))
1192 (if (and (boundp 'mail-self-blind
)
1194 (format "BCC: %s\n" user-mail-address
))
1195 (if (and (boundp 'mail-archive-file-name
)
1196 (stringp mail-archive-file-name
))
1197 (format "FCC: %s\n" mail-archive-file-name
))
1198 ;; Use the value of `mail-default-headers' if available.
1199 ;; Note: as for Emacs 21, XEmacs 21.4 and 21.5, it is
1200 ;; unavailable unless sendmail.el is loaded.
1201 (if (boundp 'mail-default-headers
)
1202 mail-default-headers
))
1203 "*A string of header lines to be inserted in outgoing mails."
1205 :group
'message-headers
1206 :group
'message-mail
1207 :link
'(custom-manual "(message)Mail Headers")
1208 :type
'message-header-lines
)
1210 (defcustom message-default-news-headers
""
1211 "*A string of header lines to be inserted in outgoing news articles."
1212 :group
'message-headers
1213 :group
'message-news
1214 :link
'(custom-manual "(message)News Headers")
1215 :type
'message-header-lines
)
1217 ;; Note: could use /usr/ucb/mail instead of sendmail;
1218 ;; options -t, and -v if not interactive.
1219 (defcustom message-mailer-swallows-blank-line
1220 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1221 system-configuration
)
1222 (file-readable-p "/etc/sendmail.cf")
1223 (let ((buffer (get-buffer-create " *temp*")))
1225 (with-current-buffer buffer
1226 (insert-file-contents "/etc/sendmail.cf")
1227 (goto-char (point-min))
1228 (let ((case-fold-search nil
))
1229 (re-search-forward "^OR\\>" nil t
)))
1230 (kill-buffer buffer
))))
1231 ;; According to RFC822, "The field-name must be composed of printable
1232 ;; ASCII characters (i. e., characters that have decimal values between
1233 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1235 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1236 "*Set this non-nil if the system's mailer runs the header and body together.
1237 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1238 The value should be an expression to test whether the problem will
1240 :group
'message-sending
1241 :link
'(custom-manual "(message)Mail Variables")
1245 (define-mail-user-agent 'message-user-agent
1246 'message-mail
'message-send-and-exit
1247 'message-kill-buffer
'message-send-hook
)
1249 (defvar message-mh-deletable-headers
'(Message-ID Date Lines Sender
)
1250 "If non-nil, delete the deletable headers before feeding to mh.")
1252 (defvar message-send-method-alist
1253 '((news message-news-p message-send-via-news
)
1254 (mail message-mail-p message-send-via-mail
))
1255 "Alist of ways to send outgoing messages.
1256 Each element has the form
1258 \(TYPE PREDICATE FUNCTION)
1260 where TYPE is a symbol that names the method; PREDICATE is a function
1261 called without any parameters to determine whether the message is
1262 a message of type TYPE; and FUNCTION is a function to be called if
1263 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1266 (defcustom message-mail-alias-type
'abbrev
1267 "*What alias expansion type to use in Message buffers.
1268 The default is `abbrev', which uses mailabbrev. `ecomplete' uses
1269 an electric completion mode. nil switches mail aliases off.
1270 This can also be a list of values."
1272 :link
'(custom-manual "(message)Mail Aliases")
1273 :type
'(choice (const :tag
"Use Mailabbrev" abbrev
)
1274 (const :tag
"Use ecomplete" ecomplete
)
1275 (const :tag
"No expansion" nil
)))
1277 (defcustom message-self-insert-commands
'(self-insert-command)
1278 "List of `self-insert-command's used to trigger ecomplete.
1279 When one of those commands is invoked to enter a character in To or Cc
1280 header, ecomplete will suggest the candidates of recipients (see also
1281 `message-mail-alias-type'). If you use some tool to enter non-ASCII
1282 text and it replaces `self-insert-command' with the other command, e.g.
1283 `egg-self-insert-command', you may want to add it to this list."
1284 :group
'message-various
1285 :type
'(repeat function
))
1287 (defcustom message-auto-save-directory
1288 (file-name-as-directory (expand-file-name "drafts" message-directory
))
1289 "*Directory where Message auto-saves buffers if Gnus isn't running.
1290 If nil, Message won't auto-save."
1291 :group
'message-buffers
1292 :link
'(custom-manual "(message)Various Message Variables")
1293 :type
'(choice directory
(const :tag
"Don't auto-save" nil
)))
1295 (defcustom message-default-charset
1296 (and (not (mm-multibyte-p)) 'iso-8859-1
)
1297 "Default charset used in non-MULE Emacsen.
1298 If nil, you might be asked to input the charset."
1301 :link
'(custom-manual "(message)Various Message Variables")
1304 (defcustom message-dont-reply-to-names
1305 (and (boundp 'rmail-dont-reply-to-names
) rmail-dont-reply-to-names
)
1306 "*Addresses to prune when doing wide replies.
1307 This can be a regexp or a list of regexps. Also, a value of nil means
1308 exclude your own user name only."
1311 :link
'(custom-manual "(message)Wide Reply")
1312 :type
'(choice (const :tag
"Yourself" nil
)
1314 (repeat :tag
"Regexp List" regexp
)))
1316 (defsubst message-dont-reply-to-names
()
1317 (gmm-regexp-concat message-dont-reply-to-names
))
1319 (defvar message-shoot-gnksa-feet nil
1320 "*A list of GNKSA feet you are allowed to shoot.
1321 Gnus gives you all the opportunity you could possibly want for
1322 shooting yourself in the foot. Also, Gnus allows you to shoot the
1323 feet of Good Net-Keeping Seal of Approval. The following are foot
1325 `empty-article' Allow you to post an empty article;
1326 `quoted-text-only' Allow you to post quoted text only;
1327 `multiple-copies' Allow you to post multiple copies;
1328 `cancel-messages' Allow you to cancel or supersede messages from
1329 your other email addresses.")
1331 (defsubst message-gnksa-enable-p
(feature)
1332 (or (not (listp message-shoot-gnksa-feet
))
1333 (memq feature message-shoot-gnksa-feet
)))
1335 (defcustom message-hidden-headers
'("^References:" "^Face:" "^X-Face:"
1337 "Regexp of headers to be hidden when composing new messages.
1338 This can also be a list of regexps to match headers. Or a list
1339 starting with `not' and followed by regexps."
1342 :link
'(custom-manual "(message)Message Headers")
1344 :format
"%{%t%}: %[Value Type%] %v"
1345 (regexp :menu-tag
"regexp" :format
"regexp\n%t: %v")
1346 (repeat :menu-tag
"(regexp ...)" :format
"(regexp ...)\n%v%i"
1347 (regexp :format
"%t: %v"))
1348 (cons :menu-tag
"(not regexp ...)" :format
"(not regexp ...)\n%v"
1350 (repeat :format
"%v%i"
1351 (regexp :format
"%t: %v")))))
1353 (defcustom message-cite-articles-with-x-no-archive t
1354 "If non-nil, cite text from articles that has X-No-Archive set."
1358 ;;; Internal variables.
1359 ;;; Well, not really internal.
1361 (defvar message-mode-syntax-table
1362 (let ((table (copy-syntax-table text-mode-syntax-table
)))
1363 (modify-syntax-entry ?%
". " table
)
1364 (modify-syntax-entry ?
> ". " table
)
1365 (modify-syntax-entry ?
< ". " table
)
1367 "Syntax table used while in Message mode.")
1369 (defface message-header-to
1372 (:foreground
"DarkOliveGreen1" :bold t
))
1375 (:foreground
"MidnightBlue" :bold t
))
1377 (:bold t
:italic t
)))
1378 "Face used for displaying From headers."
1379 :group
'message-faces
)
1380 ;; backward-compatibility alias
1381 (put 'message-header-to-face
'face-alias
'message-header-to
)
1382 (put 'message-header-to-face
'obsolete-face
"22.1")
1384 (defface message-header-cc
1387 (:foreground
"chartreuse1" :bold t
))
1390 (:foreground
"MidnightBlue"))
1393 "Face used for displaying Cc headers."
1394 :group
'message-faces
)
1395 ;; backward-compatibility alias
1396 (put 'message-header-cc-face
'face-alias
'message-header-cc
)
1397 (put 'message-header-cc-face
'obsolete-face
"22.1")
1399 (defface message-header-subject
1402 (:foreground
"OliveDrab1"))
1405 (:foreground
"navy blue" :bold t
))
1408 "Face used for displaying subject headers."
1409 :group
'message-faces
)
1410 ;; backward-compatibility alias
1411 (put 'message-header-subject-face
'face-alias
'message-header-subject
)
1412 (put 'message-header-subject-face
'obsolete-face
"22.1")
1414 (defface message-header-newsgroups
1417 (:foreground
"yellow" :bold t
:italic t
))
1420 (:foreground
"blue4" :bold t
:italic t
))
1422 (:bold t
:italic t
)))
1423 "Face used for displaying newsgroups headers."
1424 :group
'message-faces
)
1425 ;; backward-compatibility alias
1426 (put 'message-header-newsgroups-face
'face-alias
'message-header-newsgroups
)
1427 (put 'message-header-newsgroups-face
'obsolete-face
"22.1")
1429 (defface message-header-other
1432 (:foreground
"VioletRed1"))
1435 (:foreground
"steel blue"))
1437 (:bold t
:italic t
)))
1438 "Face used for displaying newsgroups headers."
1439 :group
'message-faces
)
1440 ;; backward-compatibility alias
1441 (put 'message-header-other-face
'face-alias
'message-header-other
)
1442 (put 'message-header-other-face
'obsolete-face
"22.1")
1444 (defface message-header-name
1447 (:foreground
"green"))
1450 (:foreground
"cornflower blue"))
1453 "Face used for displaying header names."
1454 :group
'message-faces
)
1455 ;; backward-compatibility alias
1456 (put 'message-header-name-face
'face-alias
'message-header-name
)
1457 (put 'message-header-name-face
'obsolete-face
"22.1")
1459 (defface message-header-xheader
1462 (:foreground
"DeepSkyBlue1"))
1465 (:foreground
"blue"))
1468 "Face used for displaying X-Header headers."
1469 :group
'message-faces
)
1470 ;; backward-compatibility alias
1471 (put 'message-header-xheader-face
'face-alias
'message-header-xheader
)
1472 (put 'message-header-xheader-face
'obsolete-face
"22.1")
1474 (defface message-separator
1477 (:foreground
"LightSkyBlue1"))
1480 (:foreground
"brown"))
1483 "Face used for displaying the separator."
1484 :group
'message-faces
)
1485 ;; backward-compatibility alias
1486 (put 'message-separator-face
'face-alias
'message-separator
)
1487 (put 'message-separator-face
'obsolete-face
"22.1")
1489 (defface message-cited-text
1492 (:foreground
"LightPink1"))
1495 (:foreground
"red"))
1498 "Face used for displaying cited text names."
1499 :group
'message-faces
)
1500 ;; backward-compatibility alias
1501 (put 'message-cited-text-face
'face-alias
'message-cited-text
)
1502 (put 'message-cited-text-face
'obsolete-face
"22.1")
1504 (defface message-mml
1507 (:foreground
"MediumSpringGreen"))
1510 (:foreground
"ForestGreen"))
1513 "Face used for displaying MML."
1514 :group
'message-faces
)
1515 ;; backward-compatibility alias
1516 (put 'message-mml-face
'face-alias
'message-mml
)
1517 (put 'message-mml-face
'obsolete-face
"22.1")
1519 (defun message-font-lock-make-header-matcher (regexp)
1522 (let ((start (point)))
1525 (goto-char (point-min))
1526 (if (re-search-forward
1527 (concat "^" (regexp-quote mail-header-separator
) "$")
1529 (setq limit
(min limit
(match-beginning 0))))
1531 (and (< start limit
)
1532 (re-search-forward ,regexp limit t
))))))
1533 (if (featurep 'bytecomp
)
1537 (defvar message-font-lock-keywords
1538 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1539 `((,(message-font-lock-make-header-matcher
1540 (concat "^\\([Tt]o:\\)" content
))
1541 (1 'message-header-name
)
1542 (2 'message-header-to nil t
))
1543 (,(message-font-lock-make-header-matcher
1544 (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content
))
1545 (1 'message-header-name
)
1546 (2 'message-header-cc nil t
))
1547 (,(message-font-lock-make-header-matcher
1548 (concat "^\\([Ss]ubject:\\)" content
))
1549 (1 'message-header-name
)
1550 (2 'message-header-subject nil t
))
1551 (,(message-font-lock-make-header-matcher
1552 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content
))
1553 (1 'message-header-name
)
1554 (2 'message-header-newsgroups nil t
))
1555 (,(message-font-lock-make-header-matcher
1556 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content
))
1557 (1 'message-header-name
)
1558 (2 'message-header-xheader
))
1559 (,(message-font-lock-make-header-matcher
1560 (concat "^\\([A-Z][^: \n\t]+:\\)" content
))
1561 (1 'message-header-name
)
1562 (2 'message-header-other nil t
))
1563 ,@(if (and mail-header-separator
1564 (not (equal mail-header-separator
"")))
1565 `((,(concat "^\\(" (regexp-quote mail-header-separator
) "\\)$")
1566 1 'message-separator
))
1569 (re-search-forward (concat "^\\("
1570 message-cite-prefix-regexp
1573 (0 'message-cited-text
))
1574 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1576 "Additional expressions to highlight in Message mode.")
1579 ;; XEmacs does it like this. For Emacs, we have to set the
1580 ;; `font-lock-defaults' buffer-local variable.
1581 (put 'message-mode
'font-lock-defaults
'(message-font-lock-keywords t
))
1583 (defvar message-face-alist
1584 '((bold . message-bold-region
)
1585 (underline . underline-region
)
1586 (default .
(lambda (b e
)
1587 (message-unbold-region b e
)
1588 (ununderline-region b e
))))
1589 "Alist of mail and news faces for facemenu.
1590 The cdr of each entry is a function for applying the face to a region.")
1592 (defcustom message-send-hook nil
1593 "Hook run before sending messages.
1594 This hook is run quite early when sending."
1595 :group
'message-various
1596 :options
'(ispell-message)
1597 :link
'(custom-manual "(message)Various Message Variables")
1600 (defcustom message-send-mail-hook nil
1601 "Hook run before sending mail messages.
1602 This hook is run very late -- just before the message is sent as
1604 :group
'message-various
1605 :link
'(custom-manual "(message)Various Message Variables")
1608 (defcustom message-send-news-hook nil
1609 "Hook run before sending news messages.
1610 This hook is run very late -- just before the message is sent as
1612 :group
'message-various
1613 :link
'(custom-manual "(message)Various Message Variables")
1616 (defcustom message-sent-hook nil
1617 "Hook run after sending messages."
1618 :group
'message-various
1621 (defvar message-send-coding-system
'binary
1622 "Coding system to encode outgoing mail.")
1624 (defvar message-draft-coding-system
1625 mm-auto-save-coding-system
1626 "*Coding system to compose mail.
1627 If you'd like to make it possible to share draft files between XEmacs
1628 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1629 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1631 (defcustom message-send-mail-partially-limit nil
1632 "The limitation of messages sent as message/partial.
1633 The lower bound of message size in characters, beyond which the message
1634 should be sent in several parts. If it is nil, the size is unlimited."
1636 :group
'message-buffers
1637 :link
'(custom-manual "(message)Mail Variables")
1638 :type
'(choice (const :tag
"unlimited" nil
)
1641 (defcustom message-alternative-emails nil
1642 "*Regexp matching alternative email addresses.
1643 The first address in the To, Cc or From headers of the original
1644 article matching this variable is used as the From field of
1647 This variable has precedence over posting styles and anything that runs
1648 off `message-setup-hook'."
1649 :group
'message-headers
1650 :link
'(custom-manual "(message)Message Headers")
1651 :type
'(choice (const :tag
"Always use primary" nil
)
1654 (defcustom message-hierarchical-addresses nil
1655 "A list of hierarchical mail address definitions.
1657 Inside each entry, the first address is the \"top\" address, and
1658 subsequent addresses are subaddresses; this is used to indicate that
1659 mail sent to the first address will automatically be delivered to the
1660 subaddresses. So if the first address appears in the recipient list
1661 for a message, the subaddresses will be removed (if present) before
1662 the mail is sent. All addresses in this structure should be
1665 :group
'message-headers
1666 :type
'(repeat (repeat string
)))
1668 (defcustom message-mail-user-agent nil
1669 "Like `mail-user-agent'.
1670 Except if it is nil, use Gnus native MUA; if it is t, use
1673 :type
'(radio (const :tag
"Gnus native"
1676 (const :tag
"`mail-user-agent'"
1679 (function-item :tag
"Default Emacs mail"
1681 sendmail-user-agent
)
1682 (function-item :tag
"Emacs interface to MH"
1685 (function :tag
"Other"))
1689 (defcustom message-wide-reply-confirm-recipients nil
1690 "Whether to confirm a wide reply to multiple email recipients.
1691 If this variable is nil, don't ask whether to reply to all recipients.
1692 If this variable is non-nil, pose the question \"Reply to all
1693 recipients?\" before a wide reply to multiple recipients. If the user
1694 answers yes, reply to all recipients as usual. If the user answers
1695 no, only reply back to the author."
1697 :group
'message-headers
1698 :link
'(custom-manual "(message)Wide Reply")
1701 (defcustom message-user-fqdn nil
1702 "*Domain part of Message-Ids."
1704 :group
'message-headers
1705 :link
'(custom-manual "(message)News Headers")
1706 :type
'(radio (const :format
"%v " nil
)
1707 (string :format
"FQDN: %v")))
1709 (defcustom message-use-idna
(and (condition-case nil
(require 'idna
)
1711 (mm-coding-system-p 'utf-8
)
1712 (executable-find idna-program
)
1713 (string= (idna-to-ascii "räksmörgås")
1714 "xn--rksmrgs-5wao1o")
1716 "Whether to encode non-ASCII in domain names into ASCII according to IDNA.
1717 GNU Libidn, and in particular the elisp package \"idna.el\" and
1718 the external program \"idn\", must be installed for this
1719 functionality to work."
1721 :group
'message-headers
1722 :link
'(custom-manual "(message)IDNA")
1723 :type
'(choice (const :tag
"Ask" ask
)
1724 (const :tag
"Never" nil
)
1725 (const :tag
"Always" t
)))
1727 (defcustom message-generate-hashcash
(if (executable-find "hashcash") t
)
1728 "*Whether to generate X-Hashcash: headers.
1729 If t, always generate hashcash headers. If `opportunistic',
1730 only generate hashcash headers if it can be done without the user
1731 waiting (i.e., only asynchronously).
1733 You must have the \"hashcash\" binary installed, see `hashcash-path'."
1734 :group
'message-headers
1735 :link
'(custom-manual "(message)Mail Headers")
1736 :type
'(choice (const :tag
"Always" t
)
1737 (const :tag
"Never" nil
)
1738 (const :tag
"Opportunistic" opportunistic
)))
1740 ;;; Internal variables.
1742 (defvar message-sending-message
"Sending...")
1743 (defvar message-buffer-list nil
)
1744 (defvar message-this-is-news nil
)
1745 (defvar message-this-is-mail nil
)
1746 (defvar message-draft-article nil
)
1747 (defvar message-mime-part nil
)
1748 (defvar message-posting-charset nil
)
1749 (defvar message-inserted-headers nil
)
1750 (defvar message-inhibit-ecomplete nil
)
1752 ;; Byte-compiler warning
1753 (defvar gnus-active-hashtb
)
1754 (defvar gnus-read-active-file
)
1756 ;;; Regexp matching the delimiter of messages in UNIX mail format
1757 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1758 ;;; of rmail.el's rmail-unix-mail-delimiter.
1759 (defvar message-unix-mail-delimiter
1760 (let ((time-zone-regexp
1761 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1762 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1768 ;; Many things can happen to an RFC 822 mailbox before it is put into
1769 ;; a `From' line. The leading phrase can be stripped, e.g.
1770 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1771 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1772 ;; can be removed, e.g.
1773 ;; From: joe@y.z (Joe K
1775 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1778 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1779 ;; The mailbox can be removed or be replaced by white space, e.g.
1780 ;; From: "Joe User"{space}{tab}
1782 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1783 ;; where {space} and {tab} represent the Ascii space and tab characters.
1784 ;; We want to match the results of any of these manglings.
1785 ;; The following regexp rejects names whose first characters are
1786 ;; obviously bogus, but after that anything goes.
1787 "\\([^\0-\b\n-\r\^?].*\\)?"
1789 ;; The time the message was sent.
1790 "\\([^\0-\r \^?]+\\) +" ; day of the week
1791 "\\([^\0-\r \^?]+\\) +" ; month
1792 "\\([0-3]?[0-9]\\) +" ; day of month
1793 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1795 ;; Perhaps a time zone, specified by an abbreviation, or by a
1800 " \\([0-9][0-9]+\\) *"
1802 ;; On some systems the time zone can appear after the year, too.
1806 "\\(remote from .*\\)?"
1809 "Regexp matching the delimiter of messages in UNIX mail format.")
1811 (defvar message-unsent-separator
1812 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1813 "^ *---+ +Returned message +---+ *$\\|"
1814 "^Start of returned message$\\|"
1815 "^ *---+ +Original message +---+ *$\\|"
1816 "^ *--+ +begin message +--+ *$\\|"
1817 "^ *---+ +Original message follows +---+ *$\\|"
1818 "^ *---+ +Undelivered message follows +---+ *$\\|"
1819 "^------ This is a copy of the message, including all the headers. ------ *$\\|"
1820 "^|? *---+ +Message text follows: +---+ *|?$")
1821 "A regexp that matches the separator before the text of a failed message.")
1823 (defvar message-field-fillers
1824 '((To message-fill-field-address
)
1825 (Cc message-fill-field-address
)
1826 (From message-fill-field-address
))
1827 "Alist of header names/filler functions.")
1829 (defvar message-header-format-alist
1844 (References . message-shorten-references
)
1846 "Alist used for formatting headers.")
1848 (defvar message-options nil
1849 "Some saved answers when sending message.")
1851 (defvar message-send-mail-real-function nil
1852 "Internal send mail function.")
1854 (defvar message-bogus-system-names
"^localhost\\.\\|\\.local$"
1855 "The regexp of bogus system names.")
1857 (defcustom message-valid-fqdn-regexp
1858 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1860 "\\([a-z][a-z]\\|" ;; two letter country TDLs
1861 "aero\\|arpa\\|bitnet\\|biz\\|bofh\\|"
1862 "cat\\|com\\|coop\\|edu\\|gov\\|"
1863 "info\\|int\\|jobs\\|"
1864 "mil\\|mobi\\|museum\\|name\\|net\\|"
1865 "org\\|pro\\|travel\\|uucp\\)")
1866 ;; http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains
1867 ;; http://en.wikipedia.org/wiki/GTLD
1868 ;; `in the process of being approved': .asia .post .tel .sex
1869 ;; "dead" nato bitnet uucp
1870 "Regular expression that matches a valid FQDN."
1871 ;; see also: gnus-button-valid-fqdn-regexp
1873 :group
'message-headers
1876 (autoload 'gnus-alive-p
"gnus-util")
1877 (autoload 'gnus-delay-article
"gnus-delay")
1878 (autoload 'gnus-extract-address-components
"gnus-util")
1879 (autoload 'gnus-find-method-for-group
"gnus")
1880 (autoload 'gnus-group-decoded-name
"gnus-group")
1881 (autoload 'gnus-group-name-charset
"gnus-group")
1882 (autoload 'gnus-group-name-decode
"gnus-group")
1883 (autoload 'gnus-groups-from-server
"gnus")
1884 (autoload 'gnus-make-local-hook
"gnus-util")
1885 (autoload 'gnus-open-server
"gnus-int")
1886 (autoload 'gnus-output-to-mail
"gnus-util")
1887 (autoload 'gnus-output-to-rmail
"gnus-util")
1888 (autoload 'gnus-request-post
"gnus-int")
1889 (autoload 'gnus-select-frame-set-input-focus
"gnus-util")
1890 (autoload 'gnus-server-string
"gnus")
1891 (autoload 'idna-to-ascii
"idna")
1892 (autoload 'message-setup-toolbar
"messagexmas")
1893 (autoload 'mh-new-draft-name
"mh-comp")
1894 (autoload 'mh-send-letter
"mh-comp")
1895 (autoload 'nndraft-request-associate-buffer
"nndraft")
1896 (autoload 'nndraft-request-expire-articles
"nndraft")
1897 (autoload 'nnvirtual-find-group-art
"nnvirtual")
1898 (autoload 'rmail-dont-reply-to
"mail-utils")
1899 (autoload 'rmail-msg-is-pruned
"rmail")
1900 (autoload 'rmail-output
"rmailout")
1905 ;;; Utility functions.
1908 (defmacro message-y-or-n-p
(question show
&rest text
)
1909 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1910 `(message-talkative-question 'y-or-n-p
,question
,show
,@text
))
1912 (defmacro message-delete-line
(&optional n
)
1913 "Delete the current line (and the next N lines)."
1914 `(delete-region (progn (beginning-of-line) (point))
1915 (progn (forward-line ,(or n
1)) (point))))
1917 (defun message-mark-active-p ()
1918 "Non-nil means the mark and region are currently active in this buffer."
1921 (defun message-unquote-tokens (elems)
1922 "Remove double quotes (\") from strings in list ELEMS."
1923 (mapcar (lambda (item)
1924 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item
)
1925 (setq item
(concat (match-string 1 item
)
1926 (match-string 2 item
))))
1930 (defun message-tokenize-header (header &optional separator
)
1931 "Split HEADER into a list of header elements.
1932 SEPARATOR is a string of characters to be used as separators. \",\"
1933 is used by default."
1936 (let ((regexp (format "[%s]+" (or separator
",")))
1938 beg quoted elems paren
)
1940 (mm-enable-multibyte)
1941 (setq beg
(point-min))
1943 (goto-char (point-min))
1948 (cond ((and (> (point) beg
)
1950 (and (looking-at regexp
)
1953 (push (buffer-substring beg
(point)) elems
)
1954 (setq beg
(match-end 0)))
1955 ((eq (char-after) ?
\")
1956 (setq quoted
(not quoted
)))
1957 ((and (eq (char-after) ?\
()
1960 ((and (eq (char-after) ?\
))
1963 (nreverse elems
)))))
1965 (autoload 'nnheader-insert-file-contents
"nnheader")
1967 (defun message-mail-file-mbox-p (file)
1968 "Say whether FILE looks like a Unix mbox file."
1969 (when (and (file-exists-p file
)
1970 (file-readable-p file
)
1971 (file-regular-p file
))
1973 (nnheader-insert-file-contents file
)
1974 (goto-char (point-min))
1975 (looking-at message-unix-mail-delimiter
))))
1977 (defun message-fetch-field (header &optional not-all
)
1978 "The same as `mail-fetch-field', only remove all newlines.
1979 The buffer is expected to be narrowed to just the header of the message;
1980 see `message-narrow-to-headers-or-head'."
1981 (let* ((inhibit-point-motion-hooks t
)
1982 (value (mail-fetch-field header nil
(not not-all
))))
1984 (while (string-match "\n[\t ]+" value
)
1985 (setq value
(replace-match " " t t value
)))
1988 (defun message-field-value (header &optional not-all
)
1989 "The same as `message-fetch-field', only narrow to the headers first."
1992 (message-narrow-to-headers-or-head)
1993 (message-fetch-field header not-all
))))
1995 (defun message-narrow-to-field ()
1996 "Narrow the buffer to the header on the current line."
1998 (while (looking-at "[ \t]")
2004 (if (re-search-forward "^[^ \n\t]" nil t
)
2007 (goto-char (point-min)))
2009 (defun message-add-header (&rest headers
)
2010 "Add the HEADERS to the message header, skipping those already present."
2013 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers
))
2014 (error "Invalid header `%s'" (car headers
)))
2015 (setq hclean
(match-string 1 (car headers
)))
2017 (message-narrow-to-headers)
2018 (unless (re-search-forward (concat "^" (regexp-quote hclean
) ":") nil t
)
2019 (goto-char (point-max))
2020 (if (string-match "\n$" (car headers
))
2021 (insert (car headers
))
2022 (insert (car headers
) ?
\n)))))
2023 (setq headers
(cdr headers
))))
2025 (defmacro message-with-reply-buffer
(&rest forms
)
2026 "Evaluate FORMS in the reply buffer, if it exists."
2027 `(when (and (bufferp message-reply-buffer
)
2028 (buffer-name message-reply-buffer
))
2029 (with-current-buffer message-reply-buffer
2032 (put 'message-with-reply-buffer
'lisp-indent-function
0)
2033 (put 'message-with-reply-buffer
'edebug-form-spec
'(body))
2035 (defun message-fetch-reply-field (header)
2036 "Fetch field HEADER from the message we're replying to."
2037 (message-with-reply-buffer
2039 (mail-narrow-to-head)
2040 (message-fetch-field header
))))
2042 (defun message-strip-list-identifiers (subject)
2043 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
2044 (require 'gnus-sum
) ; for gnus-list-identifiers
2045 (let ((regexp (if (stringp gnus-list-identifiers
)
2046 gnus-list-identifiers
2047 (mapconcat 'identity gnus-list-identifiers
" *\\|"))))
2048 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
2049 " *\\)\\)+\\(Re: +\\)?\\)") subject
)
2050 (concat (substring subject
0 (match-beginning 1))
2051 (or (match-string 3 subject
)
2052 (match-string 5 subject
))
2057 (defun message-strip-subject-re (subject)
2058 "Remove \"Re:\" from subject lines in string SUBJECT."
2059 (if (string-match message-subject-re-regexp subject
)
2060 (substring subject
(match-end 0))
2063 (defcustom message-replacement-char
"."
2064 "Replacement character used instead of unprintable or not decodable chars."
2065 :group
'message-various
2066 :version
"22.1" ;; Gnus 5.10.9
2067 :type
'(choice string
2071 ;; FIXME: We also should call `message-strip-subject-encoded-words'
2072 ;; when forwarding. Probably in `message-make-forward-subject' and
2073 ;; `message-forward-make-body'.
2075 (defun message-strip-subject-encoded-words (subject)
2076 "Fix non-decodable words in SUBJECT."
2077 ;; Cf. `gnus-simplify-subject-fully'.
2078 (let* ((case-fold-search t
)
2079 (replacement-chars (format "[%s%s%s]"
2080 message-replacement-char
2081 message-replacement-char
2082 message-replacement-char
))
2083 (enc-word-re "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?\\([^?]+\\)\\(\\?=\\)")
2088 (goto-char (point-min))
2089 (when (re-search-forward enc-word-re nil t
)
2090 (setq cs-string
(match-string 1)))))
2091 cs-coding q-or-b word-beg word-end
)
2092 (if (or (not have-marker
) ;; No encoded word found...
2093 ;; ... or double encoding was correct:
2094 (and (stringp cs-string
)
2095 (setq cs-string
(downcase cs-string
))
2096 (mm-coding-system-p (intern cs-string
))
2100 Decoded Subject \"%s\"
2101 contains a valid encoded word. Decode again? "
2103 (setq cs-coding
(intern cs-string
))))))
2107 (goto-char (point-min))
2108 (while (re-search-forward enc-word-re nil t
)
2109 (setq cs-string
(downcase (match-string 1))
2110 q-or-b
(match-string 2)
2111 word-beg
(match-beginning 0)
2112 word-end
(match-end 0))
2114 (if (mm-coding-system-p (intern cs-string
))
2115 (setq cs-coding
(intern cs-string
))
2117 ;; No double encoded subject? => bogus charset.
2120 (mm-read-coding-system
2122 Decoded Subject \"%s\"
2123 contains an encoded word. The charset `%s' is unknown or invalid.
2124 Hit RET to replace non-decodable characters with \"%s\" or enter replacement
2126 subject cs-string message-replacement-char
)))
2128 (replace-match (concat "=?" (symbol-name cs-coding
)
2131 (goto-char word-beg
)
2132 (re-search-forward "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?" word-end t
)
2135 (if (string-match "\\`Q\\'" q-or-b
)
2138 (message "Replacing non-decodable characters with \"%s\"."
2139 message-replacement-char
)
2140 (while (re-search-forward "\\(=[A-F0-9][A-F0-9]\\)+"
2142 (replace-match message-replacement-char
)))
2144 (message "Replacing non-decodable characters with \"%s\"."
2146 (re-search-forward "[^?]+" word-end t
)
2147 (replace-match replacement-chars
))
2148 (re-search-forward "\\?=")
2149 (replace-match "")))))
2150 (rfc2047-decode-region (point-min) (point-max))
2153 ;;; Start of functions adopted from `message-utils.el'.
2155 (defun message-strip-subject-trailing-was (subject)
2156 "Remove trailing \"(was: <old subject>)\" from SUBJECT lines.
2157 Leading \"Re: \" is not stripped by this function. Use the function
2158 `message-strip-subject-re' for this."
2159 (let* ((query message-subject-trailing-was-query
)
2164 message-subject-trailing-was-ask-regexp
2165 message-subject-trailing-was-regexp
)
2168 (setq new
(substring subject
0 (match-beginning 0))))
2169 (if (or (not found
) (eq query nil
))
2172 (if (message-y-or-n-p
2173 "Strip `(was: <old subject>)' in subject? " t
2175 "Strip `(was: <old subject>)' in subject "
2176 "and use the new one instead?\n\n"
2177 "Current subject is: \""
2179 "New subject would be: \""
2181 "See the variable `message-subject-trailing-was-query' "
2182 "to get rid of this query."
2187 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
2189 (defun message-change-subject (new-subject)
2190 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
2191 ;; <URL:http://www.landfield.com/usefor/drafts/draft-ietf-usefor-useage--1.02.unpaged>
2194 (read-from-minibuffer "New subject: ")))
2195 (cond ((and (not (or (null new-subject
) ; new subject not empty
2196 (zerop (string-width new-subject
))
2197 (string-match "^[ \t]*$" new-subject
))))
2201 (message-narrow-to-headers)
2202 (message-fetch-field "Subject"))))
2203 (cond ((not old-subject
)
2204 (error "No current subject"))
2207 (regexp-quote new-subject
)
2209 old-subject
)) ; yes, it really is a new subject
2210 ;; delete eventual Re: prefix
2212 (message-strip-subject-re old-subject
))
2213 (message-goto-subject)
2214 (message-delete-line)
2215 (insert (concat "Subject: "
2218 old-subject
")\n")))))))))
2220 (defun message-mark-inserted-region (beg end
&optional verbatim
)
2221 "Mark some region in the current article with enclosing tags.
2222 See `message-mark-insert-begin' and `message-mark-insert-end'.
2223 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2224 (interactive "r\nP")
2226 ;; add to the end of the region first, otherwise end would be invalid
2228 (insert (if verbatim
"#v-\n" message-mark-insert-end
))
2230 (insert (if verbatim
"#v+\n" message-mark-insert-begin
))))
2232 (defun message-mark-insert-file (file &optional verbatim
)
2233 "Insert FILE at point, marking it with enclosing tags.
2234 See `message-mark-insert-begin' and `message-mark-insert-end'.
2235 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2236 (interactive "fFile to insert: \nP")
2237 ;; reverse insertion to get correct result.
2239 (insert (if verbatim
"#v-\n" message-mark-insert-end
))
2241 (insert-file-contents file
)
2243 (insert (if verbatim
"#v+\n" message-mark-insert-begin
))))
2245 (defun message-add-archive-header ()
2246 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
2247 The note can be customized using `message-archive-note'. When called with a
2248 prefix argument, ask for a text to insert. If you don't want the note in the
2249 body, set `message-archive-note' to nil."
2251 (if current-prefix-arg
2252 (setq message-archive-note
2253 (read-from-minibuffer "Reason for No-Archive: "
2254 (cons message-archive-note
0))))
2256 (if (message-goto-signature)
2257 (re-search-backward message-signature-separator
))
2258 (when message-archive-note
2259 (insert message-archive-note
)
2261 (message-add-header message-archive-header
)
2262 (message-sort-headers)))
2264 (defun message-cross-post-followup-to-header (target-group)
2265 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
2266 With prefix-argument just set Follow-Up, don't cross-post."
2268 (list ; Completion based on Gnus
2269 (completing-read "Followup To: "
2270 (if (boundp 'gnus-newsrc-alist
)
2272 nil nil
'("poster" .
0)
2273 (if (boundp 'gnus-group-history
)
2274 'gnus-group-history
))))
2275 (message-remove-header "Follow[Uu]p-[Tt]o" t
)
2276 (message-goto-newsgroups)
2278 ;; if we already did a crosspost before, kill old target
2279 (if (and message-cross-post-old-target
2281 (regexp-quote (concat "," message-cross-post-old-target
))
2284 ;; unless (followup is to poster or user explicitly asked not
2285 ;; to cross-post, or target-group is already in Newsgroups)
2286 ;; add target-group to Newsgroups line.
2288 ;; def: cross-post, req:no
2289 (and message-cross-post-default
(not current-prefix-arg
))
2290 ;; def: no-cross-post, req:yes
2291 (and (not message-cross-post-default
) current-prefix-arg
))
2292 (not (string-match "poster" target-group
))
2293 (not (string-match (regexp-quote target-group
)
2294 (message-fetch-field "Newsgroups"))))
2296 (insert (concat "," target-group
))))
2297 (end-of-line) ; ensure Followup: comes after Newsgroups:
2298 ;; unless new followup would be identical to Newsgroups line
2299 ;; make a new Followup-To line
2300 (if (not (string-match (concat "^[ \t]*"
2303 (message-fetch-field "Newsgroups")))
2304 (insert (concat "\nFollowup-To: " target-group
)))
2305 (setq message-cross-post-old-target target-group
))
2307 (defun message-cross-post-insert-note (target-group cross-post in-old
2309 "Insert a in message body note about a set Followup or Crosspost.
2310 If there have been previous notes, delete them. TARGET-GROUP specifies the
2311 group to Followup-To. When CROSS-POST is t, insert note about
2312 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
2313 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
2314 been made to before the user asked for a Crosspost."
2315 ;; start scanning body for previous uses
2316 (message-goto-signature)
2317 (let ((head (re-search-backward
2318 (concat "^" mail-header-separator
)
2319 nil t
))) ; just search in body
2320 (message-goto-signature)
2321 (while (re-search-backward
2322 (concat "^" (regexp-quote message-cross-post-note
) ".*")
2324 (message-delete-line))
2325 (message-goto-signature)
2326 (while (re-search-backward
2327 (concat "^" (regexp-quote message-followup-to-note
) ".*")
2329 (message-delete-line))
2331 (if (message-goto-signature)
2332 (re-search-backward message-signature-separator
))
2335 (string-match "^[ \t]*poster[ \t]*$" target-group
))
2336 (insert (concat message-followup-to-note target-group
"\n"))
2337 (insert (concat message-cross-post-note target-group
"\n")))))
2339 (defun message-cross-post-followup-to (target-group)
2340 "Crossposts message and set Followup-To to TARGET-GROUP.
2341 With prefix-argument just set Follow-Up, don't cross-post."
2343 (list ; Completion based on Gnus
2344 (completing-read "Followup To: "
2345 (if (boundp 'gnus-newsrc-alist
)
2347 nil nil
'("poster" .
0)
2348 (if (boundp 'gnus-group-history
)
2349 'gnus-group-history
))))
2350 (cond ((not (or (null target-group
) ; new subject not empty
2351 (zerop (string-width target-group
))
2352 (string-match "^[ \t]*$" target-group
)))
2354 (let* ((old-groups (message-fetch-field "Newsgroups"))
2355 (in-old (string-match
2356 (regexp-quote target-group
)
2357 (or old-groups
""))))
2358 ;; check whether target exactly matches old Newsgroups
2359 (cond ((not old-groups
)
2360 (error "No current newsgroup"))
2364 (regexp-quote target-group
)
2367 ;; yes, Newsgroups line must change
2368 (message-cross-post-followup-to-header target-group
)
2369 ;; insert note whether we do cross-post or followup-to
2370 (funcall message-cross-post-note-function
2372 (if (or (and message-cross-post-default
2373 (not current-prefix-arg
))
2374 (and (not message-cross-post-default
)
2375 current-prefix-arg
)) t
)
2376 in-old old-groups
))))))))
2378 ;;; Reduce To: to Cc: or Bcc: header
2380 (defun message-reduce-to-to-cc ()
2381 "Replace contents of To: header with contents of Cc: or Bcc: header."
2384 (save-restriction (message-narrow-to-headers)
2385 (message-fetch-field "cc")))
2387 (if (and (not cc-content
)
2390 (message-narrow-to-headers)
2391 (message-fetch-field "bcc"))))
2396 (message-delete-line)
2397 (insert (concat "To: " cc-content
"\n"))
2399 (message-narrow-to-headers)
2400 (message-remove-header (if bcc
2404 ;;; End of functions adopted from `message-utils.el'.
2406 (defun message-remove-header (header &optional is-regexp first reverse
)
2407 "Remove HEADER in the narrowed buffer.
2408 If IS-REGEXP, HEADER is a regular expression.
2409 If FIRST, only remove the first instance of the header.
2410 Return the number of headers removed."
2411 (goto-char (point-min))
2412 (let ((regexp (if is-regexp header
(concat "^" (regexp-quote header
) ":")))
2414 (case-fold-search t
)
2416 (while (and (not (eobp))
2419 (not (looking-at regexp
))
2420 (looking-at regexp
))
2427 ;; There might be a continuation header, so we have to search
2428 ;; until we find a new non-continuation line.
2431 (if (re-search-forward "^[^ \t]" nil t
)
2432 (goto-char (match-beginning 0))
2435 (if (re-search-forward "^[^ \t]" nil t
)
2436 (goto-char (match-beginning 0))
2437 (goto-char (point-max)))))
2440 (defun message-remove-first-header (header)
2441 "Remove the first instance of HEADER if there is more than one."
2443 (regexp (concat "^" (regexp-quote header
) ":")))
2445 (goto-char (point-min))
2446 (while (re-search-forward regexp nil t
)
2449 (message-remove-header header nil t
)
2452 (defun message-narrow-to-headers ()
2453 "Narrow the buffer to the head of the message."
2456 (goto-char (point-min))
2457 (if (re-search-forward
2458 (concat "^" (regexp-quote mail-header-separator
) "\n") nil t
)
2461 (goto-char (point-min)))
2463 (defun message-narrow-to-head-1 ()
2464 "Like `message-narrow-to-head'. Don't widen."
2466 (goto-char (point-min))
2467 (if (search-forward "\n\n" nil
1)
2470 (goto-char (point-min)))
2472 ;; FIXME: clarify diffference: message-narrow-to-head,
2473 ;; message-narrow-to-headers-or-head, message-narrow-to-headers
2474 (defun message-narrow-to-head ()
2475 "Narrow the buffer to the head of the message.
2476 Point is left at the beginning of the narrowed-to region."
2478 (message-narrow-to-head-1))
2480 (defun message-narrow-to-headers-or-head ()
2481 "Narrow the buffer to the head of the message."
2484 (goto-char (point-min))
2485 (if (re-search-forward (concat "\\(\n\\)\n\\|^\\("
2486 (regexp-quote mail-header-separator
)
2489 (or (match-end 1) (match-beginning 2))
2491 (goto-char (point-min)))
2493 (defun message-news-p ()
2494 "Say whether the current buffer contains a news message."
2495 (and (not message-this-is-mail
)
2496 (or message-this-is-news
2499 (message-narrow-to-headers)
2500 (and (message-fetch-field "newsgroups")
2501 (not (message-fetch-field "posted-to"))))))))
2503 (defun message-mail-p ()
2504 "Say whether the current buffer contains a mail message."
2505 (and (not message-this-is-news
)
2506 (or message-this-is-mail
2509 (message-narrow-to-headers)
2510 (or (message-fetch-field "to")
2511 (message-fetch-field "cc")
2512 (message-fetch-field "bcc")))))))
2514 (defun message-subscribed-p ()
2515 "Say whether we need to insert a MFT header."
2516 (or message-subscribed-regexps
2517 message-subscribed-addresses
2518 message-subscribed-address-file
2519 message-subscribed-address-functions
))
2521 (defun message-next-header ()
2522 "Go to the beginning of the next header."
2524 (or (eobp) (forward-char 1))
2525 (not (if (re-search-forward "^[^ \t]" nil t
)
2527 (goto-char (point-max)))))
2529 (defun message-sort-headers-1 ()
2530 "Sort the buffer as headers using `message-rank' text props."
2531 (goto-char (point-min))
2534 nil
'message-next-header
2536 (message-next-header)
2540 (or (get-text-property (point) 'message-rank
)
2543 (defun message-sort-headers ()
2544 "Sort the headers of the current message according to `message-header-format-alist'."
2548 (let ((max (1+ (length message-header-format-alist
)))
2550 (message-narrow-to-headers)
2551 (while (re-search-forward "^[^ \n]+:" nil t
)
2553 (match-beginning 0) (1+ (match-beginning 0))
2555 (if (setq rank
(length (memq (assq (intern (buffer-substring
2557 (1- (match-end 0))))
2558 message-header-format-alist
)
2559 message-header-format-alist
)))
2562 (message-sort-headers-1))))
2564 (defun message-kill-address ()
2565 "Kill the address under point."
2567 (let ((start (point)))
2568 (message-skip-to-next-address)
2569 (kill-region start
(point))))
2572 (autoload 'Info-goto-node
"info")
2573 (defvar mml2015-use
)
2575 (defun message-info (&optional arg
)
2576 "Display the Message manual.
2578 Prefixed with one \\[universal-argument], display the Emacs MIME
2579 manual. With two \\[universal-argument]'s, display the EasyPG or
2580 PGG manual, depending on the value of `mml2015-use'."
2582 ;; Don't use `info' because support for `(filename)nodename' is not
2583 ;; available in XEmacs < 21.5.12.
2584 (Info-goto-node (format "(%s)Top"
2588 ((eq arg
4) 'emacs-mime
)
2589 ;; `booleanp' only available in Emacs 22+
2590 ((and (not (memq arg
'(nil t
)))
2604 (defvar message-mode-map nil
)
2606 (unless message-mode-map
2607 (setq message-mode-map
(make-keymap))
2608 (set-keymap-parent message-mode-map text-mode-map
)
2609 (define-key message-mode-map
"\C-c?" 'describe-mode
)
2611 (define-key message-mode-map
"\C-c\C-f\C-t" 'message-goto-to
)
2612 (define-key message-mode-map
"\C-c\C-f\C-o" 'message-goto-from
)
2613 (define-key message-mode-map
"\C-c\C-f\C-b" 'message-goto-bcc
)
2614 (define-key message-mode-map
"\C-c\C-f\C-w" 'message-goto-fcc
)
2615 (define-key message-mode-map
"\C-c\C-f\C-c" 'message-goto-cc
)
2616 (define-key message-mode-map
"\C-c\C-f\C-s" 'message-goto-subject
)
2617 (define-key message-mode-map
"\C-c\C-f\C-r" 'message-goto-reply-to
)
2618 (define-key message-mode-map
"\C-c\C-f\C-n" 'message-goto-newsgroups
)
2619 (define-key message-mode-map
"\C-c\C-f\C-d" 'message-goto-distribution
)
2620 (define-key message-mode-map
"\C-c\C-f\C-f" 'message-goto-followup-to
)
2621 (define-key message-mode-map
"\C-c\C-f\C-m" 'message-goto-mail-followup-to
)
2622 (define-key message-mode-map
"\C-c\C-f\C-k" 'message-goto-keywords
)
2623 (define-key message-mode-map
"\C-c\C-f\C-u" 'message-goto-summary
)
2624 (define-key message-mode-map
"\C-c\C-f\C-i"
2625 'message-insert-or-toggle-importance
)
2626 (define-key message-mode-map
"\C-c\C-f\C-a"
2627 'message-generate-unsubscribed-mail-followup-to
)
2629 ;; modify headers (and insert notes in body)
2630 (define-key message-mode-map
"\C-c\C-fs" 'message-change-subject
)
2632 (define-key message-mode-map
"\C-c\C-fx" 'message-cross-post-followup-to
)
2633 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2634 (define-key message-mode-map
"\C-c\C-ft" 'message-reduce-to-to-cc
)
2635 (define-key message-mode-map
"\C-c\C-fa" 'message-add-archive-header
)
2636 ;; mark inserted text
2637 (define-key message-mode-map
"\C-c\M-m" 'message-mark-inserted-region
)
2638 (define-key message-mode-map
"\C-c\M-f" 'message-mark-insert-file
)
2640 (define-key message-mode-map
"\C-c\C-b" 'message-goto-body
)
2641 (define-key message-mode-map
"\C-c\C-i" 'message-goto-signature
)
2643 (define-key message-mode-map
"\C-c\C-t" 'message-insert-to
)
2644 (define-key message-mode-map
"\C-c\C-fw" 'message-insert-wide-reply
)
2645 (define-key message-mode-map
"\C-c\C-n" 'message-insert-newsgroups
)
2646 (define-key message-mode-map
"\C-c\C-l" 'message-to-list-only
)
2647 (define-key message-mode-map
"\C-c\C-f\C-e" 'message-insert-expires
)
2649 (define-key message-mode-map
"\C-c\C-u" 'message-insert-or-toggle-importance
)
2650 (define-key message-mode-map
"\C-c\M-n"
2651 'message-insert-disposition-notification-to
)
2653 (define-key message-mode-map
"\C-c\C-y" 'message-yank-original
)
2654 (define-key message-mode-map
"\C-c\M-\C-y" 'message-yank-buffer
)
2655 (define-key message-mode-map
"\C-c\C-q" 'message-fill-yanked-message
)
2656 (define-key message-mode-map
"\C-c\C-w" 'message-insert-signature
)
2657 (define-key message-mode-map
"\C-c\M-h" 'message-insert-headers
)
2658 (define-key message-mode-map
"\C-c\C-r" 'message-caesar-buffer-body
)
2659 (define-key message-mode-map
"\C-c\C-o" 'message-sort-headers
)
2660 (define-key message-mode-map
"\C-c\M-r" 'message-rename-buffer
)
2662 (define-key message-mode-map
"\C-c\C-c" 'message-send-and-exit
)
2663 (define-key message-mode-map
"\C-c\C-s" 'message-send
)
2664 (define-key message-mode-map
"\C-c\C-k" 'message-kill-buffer
)
2665 (define-key message-mode-map
"\C-c\C-d" 'message-dont-send
)
2666 (define-key message-mode-map
"\C-c\n" 'gnus-delay-article
)
2668 (define-key message-mode-map
"\C-c\M-k" 'message-kill-address
)
2669 (define-key message-mode-map
"\C-c\C-e" 'message-elide-region
)
2670 (define-key message-mode-map
"\C-c\C-v" 'message-delete-not-region
)
2671 (define-key message-mode-map
"\C-c\C-z" 'message-kill-to-signature
)
2672 (define-key message-mode-map
"\M-\r" 'message-newline-and-reformat
)
2673 (define-key message-mode-map
[remap split-line
] 'message-split-line
)
2675 (define-key message-mode-map
"\C-c\C-a" 'mml-attach-file
)
2677 (define-key message-mode-map
"\C-a" 'message-beginning-of-line
)
2678 (define-key message-mode-map
"\t" 'message-tab
)
2679 (define-key message-mode-map
"\M-;" 'comment-region
)
2681 (define-key message-mode-map
"\M-n" 'message-display-abbrev
))
2684 message-mode-menu message-mode-map
"Message Menu."
2686 ["Yank Original" message-yank-original message-reply-buffer
]
2687 ["Fill Yanked Message" message-fill-yanked-message t
]
2688 ["Insert Signature" message-insert-signature t
]
2689 ["Caesar (rot13) Message" message-caesar-buffer-body t
]
2690 ["Caesar (rot13) Region" message-caesar-region
(message-mark-active-p)]
2691 ["Elide Region" message-elide-region
2692 :active
(message-mark-active-p)
2693 ,@(if (featurep 'xemacs
) nil
2694 '(:help
"Replace text in region with an ellipsis"))]
2695 ["Delete Outside Region" message-delete-not-region
2696 :active
(message-mark-active-p)
2697 ,@(if (featurep 'xemacs
) nil
2698 '(:help
"Delete all quoted text outside region"))]
2699 ["Kill To Signature" message-kill-to-signature t
]
2700 ["Newline and Reformat" message-newline-and-reformat t
]
2701 ["Rename buffer" message-rename-buffer t
]
2702 ["Spellcheck" ispell-message
2703 ,@(if (featurep 'xemacs
) '(t)
2704 '(:help
"Spellcheck this message"))]
2706 ["Insert Region Marked" message-mark-inserted-region
2707 :active
(message-mark-active-p)
2708 ,@(if (featurep 'xemacs
) nil
2709 '(:help
"Mark region with enclosing tags"))]
2710 ["Insert File Marked..." message-mark-insert-file
2711 ,@(if (featurep 'xemacs
) '(t)
2712 '(:help
"Insert file at point marked with enclosing tags"))]
2714 ["Send Message" message-send-and-exit
2715 ,@(if (featurep 'xemacs
) '(t)
2716 '(:help
"Send this message"))]
2717 ["Postpone Message" message-dont-send
2718 ,@(if (featurep 'xemacs
) '(t)
2719 '(:help
"File this draft message and exit"))]
2720 ["Send at Specific Time..." gnus-delay-article
2721 ,@(if (featurep 'xemacs
) '(t)
2722 '(:help
"Ask, then arrange to send message at that time"))]
2723 ["Kill Message" message-kill-buffer
2724 ,@(if (featurep 'xemacs
) '(t)
2725 '(:help
"Delete this message without sending"))]
2727 ["Message manual" message-info
2728 ,@(if (featurep 'xemacs
) '(t)
2729 '(:help
"Display the Message manual"))]))
2732 message-mode-field-menu message-mode-map
""
2734 ["To" message-goto-to t
]
2735 ["From" message-goto-from t
]
2736 ["Subject" message-goto-subject t
]
2737 ["Change subject..." message-change-subject t
]
2738 ["Cc" message-goto-cc t
]
2739 ["Bcc" message-goto-bcc t
]
2740 ["Fcc" message-goto-fcc t
]
2741 ["Reply-To" message-goto-reply-to t
]
2742 ["Flag As Important" message-insert-importance-high
2743 ,@(if (featurep 'xemacs
) '(t)
2744 '(:help
"Mark this message as important"))]
2745 ["Flag As Unimportant" message-insert-importance-low
2746 ,@(if (featurep 'xemacs
) '(t)
2747 '(:help
"Mark this message as unimportant"))]
2749 message-insert-disposition-notification-to
2750 ,@(if (featurep 'xemacs
) '(t)
2751 '(:help
"Request a receipt notification"))]
2753 ;; (typical) news stuff
2754 ["Summary" message-goto-summary t
]
2755 ["Keywords" message-goto-keywords t
]
2756 ["Newsgroups" message-goto-newsgroups t
]
2757 ["Fetch Newsgroups" message-insert-newsgroups t
]
2758 ["Followup-To" message-goto-followup-to t
]
2759 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2760 ["Crosspost / Followup-To..." message-cross-post-followup-to t
]
2761 ["Distribution" message-goto-distribution t
]
2762 ["Expires" message-insert-expires t
]
2763 ["X-No-Archive" message-add-archive-header t
]
2765 ;; (typical) mailing-lists stuff
2766 ["Fetch To" message-insert-to
2767 ,@(if (featurep 'xemacs
) '(t)
2768 '(:help
"Insert a To header that points to the author."))]
2769 ["Fetch To and Cc" message-insert-wide-reply
2770 ,@(if (featurep 'xemacs
) '(t)
2772 "Insert To and Cc headers as if you were doing a wide reply."))]
2774 ["Send to list only" message-to-list-only t
]
2775 ["Mail-Followup-To" message-goto-mail-followup-to t
]
2776 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2777 ,@(if (featurep 'xemacs
) '(t)
2778 '(:help
"Insert a reasonable `Mail-Followup-To:' header."))]
2779 ["Reduce To: to Cc:" message-reduce-to-to-cc t
]
2781 ["Sort Headers" message-sort-headers t
]
2782 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t
]
2783 ;; We hide `message-hidden-headers' by narrowing the buffer.
2784 ["Show Hidden Headers" widen t
]
2785 ["Goto Body" message-goto-body t
]
2786 ["Goto Signature" message-goto-signature t
]))
2788 (defvar message-tool-bar-map nil
)
2790 (defvar facemenu-add-face-function
)
2791 (defvar facemenu-remove-face-function
)
2793 ;;; Forbidden properties
2795 ;; We use `after-change-functions' to keep special text properties
2796 ;; that interfere with the normal function of message mode out of the
2799 (defcustom message-strip-special-text-properties t
2800 "Strip special properties from the message buffer.
2802 Emacs has a number of special text properties which can break message
2803 composing in various ways. If this option is set, message will strip
2804 these properties from the message composition buffer. However, some
2805 packages requires these properties to be present in order to work.
2806 If you use one of these packages, turn this option off, and hope the
2807 message composition doesn't break too bad."
2809 :group
'message-various
2810 :link
'(custom-manual "(message)Various Message Variables")
2813 (defconst message-forbidden-properties
2814 ;; No reason this should be clutter up customize. We make it a
2815 ;; property list (rather than a list of property symbols), to be
2816 ;; directly useful for `remove-text-properties'.
2817 '(field nil read-only nil invisible nil intangible nil
2818 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2819 insert-behind-hooks nil point-entered nil point-left nil
)
2820 ;; Other special properties:
2821 ;; category, face, display: probably doesn't do any harm.
2822 ;; fontified: is used by font-lock.
2823 ;; syntax-table, local-map: I dunno.
2824 ;; We need to add XEmacs names to the list.
2825 "Property list of with properties forbidden in message buffers.
2826 The values of the properties are ignored, only the property names are used.")
2828 (defun message-tamago-not-in-use-p (pos)
2829 "Return t when tamago version 4 is not in use at the cursor position.
2830 Tamago version 4 is a popular input method for writing Japanese text.
2831 It uses the properties `intangible', `invisible', `modification-hooks'
2832 and `read-only' when translating ascii or kana text to kanji text.
2833 These properties are essential to work, so we should never strip them."
2834 (not (and (boundp 'egg-modefull-mode
)
2835 (symbol-value 'egg-modefull-mode
)
2836 (or (memq (get-text-property pos
'intangible
)
2837 '(its-part-1 its-part-2
))
2838 (get-text-property pos
'egg-end
)
2839 (get-text-property pos
'egg-lang
)
2840 (get-text-property pos
'egg-start
)))))
2842 (defsubst message-mail-alias-type-p
(type)
2843 (if (atom message-mail-alias-type
)
2844 (eq message-mail-alias-type type
)
2845 (memq type message-mail-alias-type
)))
2847 (defun message-strip-forbidden-properties (begin end
&optional old-length
)
2848 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2849 This function is intended to be called from `after-change-functions'.
2850 See also `message-forbidden-properties'."
2851 (when (and (message-mail-alias-type-p 'ecomplete
)
2852 (memq this-command message-self-insert-commands
))
2853 (message-display-abbrev))
2854 (when (and message-strip-special-text-properties
2855 (message-tamago-not-in-use-p begin
))
2856 (let ((buffer-read-only nil
)
2857 (inhibit-read-only t
))
2858 (remove-text-properties begin end message-forbidden-properties
))))
2860 (autoload 'ecomplete-setup
"ecomplete") ;; for Emacs <23.
2863 (define-derived-mode message-mode text-mode
"Message"
2864 "Major mode for editing mail and news to be sent.
2865 Like Text Mode but with these additional commands:\\<message-mode-map>
2866 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2867 C-c C-d Postpone sending the message C-c C-k Kill the message
2868 C-c C-f move to a header field (and create it if there isn't):
2869 C-c C-f C-t move to To C-c C-f C-s move to Subject
2870 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2871 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2872 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2873 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2874 C-c C-f C-o move to From (\"Originator\")
2875 C-c C-f C-f move to Followup-To
2876 C-c C-f C-m move to Mail-Followup-To
2877 C-c C-f C-e move to Expires
2878 C-c C-f C-i cycle through Importance values
2879 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2880 C-c C-f x crossposting with FollowUp-To header and note in body
2881 C-c C-f t replace To: header with contents of Cc: or Bcc:
2882 C-c C-f a Insert X-No-Archive: header and a note in the body
2883 C-c C-t `message-insert-to' (add a To header to a news followup)
2884 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2885 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2886 C-c C-b `message-goto-body' (move to beginning of message text).
2887 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2888 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2889 C-c C-y `message-yank-original' (insert current message, if any).
2890 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2891 C-c C-e `message-elide-region' (elide the text between point and mark).
2892 C-c C-v `message-delete-not-region' (remove the text outside the region).
2893 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2894 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2895 C-c C-a `mml-attach-file' (attach a file as MIME).
2896 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2897 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2898 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2899 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2900 M-RET `message-newline-and-reformat' (break the line and reformat)."
2901 (setq local-abbrev-table text-mode-abbrev-table
)
2902 (set (make-local-variable 'message-reply-buffer
) nil
)
2903 (set (make-local-variable 'message-inserted-headers
) nil
)
2904 (set (make-local-variable 'message-send-actions
) nil
)
2905 (set (make-local-variable 'message-exit-actions
) nil
)
2906 (set (make-local-variable 'message-kill-actions
) nil
)
2907 (set (make-local-variable 'message-postpone-actions
) nil
)
2908 (set (make-local-variable 'message-draft-article
) nil
)
2909 (setq buffer-offer-save t
)
2910 (set (make-local-variable 'facemenu-add-face-function
)
2912 (let ((face-fun (cdr (assq face message-face-alist
))))
2914 (funcall face-fun
(point) end
)
2915 (error "Face %s not configured for %s mode" face mode-name
)))
2917 (set (make-local-variable 'facemenu-remove-face-function
) t
)
2918 (set (make-local-variable 'message-reply-headers
) nil
)
2919 (make-local-variable 'message-newsreader
)
2920 (make-local-variable 'message-mailer
)
2921 (make-local-variable 'message-post-method
)
2922 (set (make-local-variable 'message-sent-message-via
) nil
)
2923 (set (make-local-variable 'message-checksum
) nil
)
2924 (set (make-local-variable 'message-mime-part
) 0)
2925 (message-setup-fill-variables)
2926 (when message-fill-column
2927 (setq fill-column message-fill-column
)
2928 (turn-on-auto-fill))
2929 ;; Allow using comment commands to add/remove quoting.
2930 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2931 (when message-yank-prefix
2932 (set (make-local-variable 'comment-start
) message-yank-prefix
)
2933 (set (make-local-variable 'comment-start-skip
)
2934 (concat "^" (regexp-quote message-yank-prefix
) "[ \t]*")))
2935 (if (featurep 'xemacs
)
2936 (message-setup-toolbar)
2937 (set (make-local-variable 'font-lock-defaults
)
2938 '(message-font-lock-keywords t
))
2939 (if (boundp 'tool-bar-map
)
2940 (set (make-local-variable 'tool-bar-map
) (message-make-tool-bar))))
2941 (easy-menu-add message-mode-menu message-mode-map
)
2942 (easy-menu-add message-mode-field-menu message-mode-map
)
2943 (gnus-make-local-hook 'after-change-functions
)
2944 ;; Mmmm... Forbidden properties...
2945 (add-hook 'after-change-functions
'message-strip-forbidden-properties
2947 ;; Allow mail alias things.
2949 ((message-mail-alias-type-p 'abbrev
)
2950 (if (fboundp 'mail-abbrevs-setup
)
2951 (mail-abbrevs-setup)
2952 (if (fboundp 'mail-aliases-setup
) ; warning avoidance
2953 (mail-aliases-setup))))
2954 ((message-mail-alias-type-p 'ecomplete
)
2956 (unless buffer-file-name
2957 (message-set-auto-save-file-name))
2958 (unless (buffer-base-buffer)
2959 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2960 ;; multibyte is not necessary at all. -- zsh
2961 (mm-enable-multibyte))
2962 (set (make-local-variable 'indent-tabs-mode
) nil
) ;No tabs for indentation.
2965 (defun message-setup-fill-variables ()
2966 "Setup message fill variables."
2967 (set (make-local-variable 'fill-paragraph-function
)
2968 'message-fill-paragraph
)
2969 (make-local-variable 'paragraph-separate
)
2970 (make-local-variable 'paragraph-start
)
2971 (make-local-variable 'adaptive-fill-regexp
)
2972 (unless (boundp 'adaptive-fill-first-line-regexp
)
2973 (setq adaptive-fill-first-line-regexp nil
))
2974 (make-local-variable 'adaptive-fill-first-line-regexp
)
2975 (let ((quote-prefix-regexp
2976 ;; User should change message-cite-prefix-regexp if
2977 ;; message-yank-prefix is set to an abnormal value.
2978 (concat "\\(" message-cite-prefix-regexp
"\\)[ \t]*")))
2979 (setq paragraph-start
2981 (regexp-quote mail-header-separator
) "$\\|"
2982 "[ \t]*$\\|" ; blank lines
2983 "-- $\\|" ; signature delimiter
2984 "---+$\\|" ; delimiters for forwarded messages
2985 page-delimiter
"$\\|" ; spoiler warnings
2986 ".*wrote:$\\|" ; attribution lines
2987 quote-prefix-regexp
"$\\|" ; empty lines in quoted text
2989 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
2990 (setq paragraph-separate paragraph-start
)
2991 (setq adaptive-fill-regexp
2992 (concat quote-prefix-regexp
"\\|" adaptive-fill-regexp
))
2993 (setq adaptive-fill-first-line-regexp
2994 (concat quote-prefix-regexp
"\\|"
2995 adaptive-fill-first-line-regexp
)))
2996 (make-local-variable 'auto-fill-inhibit-regexp
)
2997 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2998 (setq auto-fill-inhibit-regexp nil
)
2999 (make-local-variable 'normal-auto-fill-function
)
3000 (setq normal-auto-fill-function
'message-do-auto-fill
)
3001 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
3002 ;; In that case, ensure that it uses the right function. The real
3003 ;; solution would be not to use `define-derived-mode', and run
3004 ;; `text-mode-hook' ourself at the end of the mode.
3005 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
3006 ;; This kludge is unneeded in Emacs>=21 since define-derived-mode is
3007 ;; now careful to run parent hooks after the body. --Stef
3008 (when auto-fill-function
3009 (setq auto-fill-function normal-auto-fill-function
)))
3014 ;;; Message mode commands
3017 ;;; Movement commands
3019 (defun message-goto-to ()
3020 "Move point to the To header."
3022 (message-position-on-field "To"))
3024 (defun message-goto-from ()
3025 "Move point to the From header."
3027 (message-position-on-field "From"))
3029 (defun message-goto-subject ()
3030 "Move point to the Subject header."
3032 (message-position-on-field "Subject"))
3034 (defun message-goto-cc ()
3035 "Move point to the Cc header."
3037 (message-position-on-field "Cc" "To"))
3039 (defun message-goto-bcc ()
3040 "Move point to the Bcc header."
3042 (message-position-on-field "Bcc" "Cc" "To"))
3044 (defun message-goto-fcc ()
3045 "Move point to the Fcc header."
3047 (message-position-on-field "Fcc" "To" "Newsgroups"))
3049 (defun message-goto-reply-to ()
3050 "Move point to the Reply-To header."
3052 (message-position-on-field "Reply-To" "Subject"))
3054 (defun message-goto-newsgroups ()
3055 "Move point to the Newsgroups header."
3057 (message-position-on-field "Newsgroups"))
3059 (defun message-goto-distribution ()
3060 "Move point to the Distribution header."
3062 (message-position-on-field "Distribution"))
3064 (defun message-goto-followup-to ()
3065 "Move point to the Followup-To header."
3067 (message-position-on-field "Followup-To" "Newsgroups"))
3069 (defun message-goto-mail-followup-to ()
3070 "Move point to the Mail-Followup-To header."
3072 (message-position-on-field "Mail-Followup-To" "To"))
3074 (defun message-goto-keywords ()
3075 "Move point to the Keywords header."
3077 (message-position-on-field "Keywords" "Subject"))
3079 (defun message-goto-summary ()
3080 "Move point to the Summary header."
3082 (message-position-on-field "Summary" "Subject"))
3084 (defun message-goto-body (&optional interactivep
)
3085 "Move point to the beginning of the message body."
3086 (interactive (list t
))
3087 (when (and interactivep
3088 (looking-at "[ \t]*\n"))
3090 (goto-char (point-min))
3091 (or (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
3092 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t
)))
3094 (defun message-in-body-p ()
3095 "Return t if point is in the message body."
3096 (let ((body (save-excursion (message-goto-body) (point))))
3099 (defun message-goto-eoh ()
3100 "Move point to the end of the headers."
3105 (defun message-goto-signature ()
3106 "Move point to the beginning of the message signature.
3107 If there is no signature in the article, go to the end and
3110 (goto-char (point-min))
3111 (if (re-search-forward message-signature-separator nil t
)
3113 (goto-char (point-max))
3116 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc
)
3117 "Insert a reasonable MFT header in a post to an unsubscribed list.
3118 When making original posts to a mailing list you are not subscribed to,
3119 you have to type in a MFT header by hand. The contents, usually, are
3120 the addresses of the list and your own address. This function inserts
3121 such a header automatically. It fetches the contents of the To: header
3122 in the current mail buffer, and appends the current `user-mail-address'.
3124 If the optional argument INCLUDE-CC is non-nil, the addresses in the
3125 Cc: header are also put into the MFT."
3130 (message-narrow-to-headers)
3131 (message-remove-header "Mail-Followup-To")
3132 (setq cc
(and include-cc
(message-fetch-field "Cc")))
3134 (concat (message-fetch-field "To") "," cc
)
3135 (message-fetch-field "To"))))
3136 (message-goto-mail-followup-to)
3137 (insert (concat tos
", " user-mail-address
))))
3141 (defun message-insert-to (&optional force
)
3142 "Insert a To header that points to the author of the article being replied to.
3143 If the original author requested not to be sent mail, don't insert unless the
3144 prefix FORCE is given."
3146 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
3147 (dont (and mct
(or (equal (downcase mct
) "never")
3148 (equal (downcase mct
) "nobody"))))
3149 (to (or (message-fetch-reply-field "mail-reply-to")
3150 (message-fetch-reply-field "reply-to")
3151 (message-fetch-reply-field "from"))))
3155 "Ignoring the user request not to have copies sent via mail"
3156 "Complying with the user request not to have copies sent via mail")))
3157 (when (and force
(not to
))
3158 (error "No mail address in the article"))
3159 (when (and to
(or force
(not dont
)))
3160 (message-carefully-insert-headers (list (cons 'To to
))))))
3162 (defun message-insert-wide-reply ()
3163 "Insert To and Cc headers as if you were doing a wide reply."
3165 (let ((headers (message-with-reply-buffer
3166 (message-get-reply-headers t
))))
3167 (message-carefully-insert-headers headers
)))
3169 (defcustom message-header-synonyms
3172 "List of lists of header synonyms.
3173 E.g., if this list contains a member list with elements `Cc' and `To',
3174 then `message-carefully-insert-headers' will not insert a `To' header
3175 when the message is already `Cc'ed to the recipient."
3177 :group
'message-headers
3178 :link
'(custom-manual "(message)Message Headers")
3179 :type
'(repeat sexp
))
3181 (defun message-carefully-insert-headers (headers)
3182 "Insert the HEADERS, an alist, into the message buffer.
3183 Does not insert the headers when they are already present there
3184 or in the synonym headers, defined by `message-header-synonyms'."
3185 ;; FIXME: Should compare only the address and not the full name. Comparison
3186 ;; should be done case-folded (and with `string=' rather than
3188 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
3189 (dolist (header headers
)
3190 (let* ((header-name (symbol-name (car header
)))
3191 (new-header (cdr header
))
3192 (synonyms (loop for synonym in message-header-synonyms
3193 when
(memq (car header
) synonym
) return synonym
))
3195 (loop for synonym in synonyms
3196 for old-header
= (mail-fetch-field (symbol-name synonym
))
3197 when
(and old-header
(string-match new-header old-header
))
3200 (message "already have `%s' in `%s'" new-header old-header
)
3201 (when (and (message-position-on-field header-name
)
3202 (setq old-header
(mail-fetch-field header-name
))
3203 (not (string-match "\\` *\\'" old-header
)))
3205 (insert new-header
)))))
3207 (defun message-widen-reply ()
3208 "Widen the reply to include maximum recipients."
3211 (and (bufferp message-reply-buffer
)
3212 (buffer-name message-reply-buffer
)
3213 (with-current-buffer message-reply-buffer
3214 (message-get-reply-headers t
)))))
3217 (message-narrow-to-headers)
3218 (dolist (elem follow-to
)
3219 (message-remove-header (symbol-name (car elem
)))
3220 (goto-char (point-min))
3221 (insert (symbol-name (car elem
)) ": "
3222 (cdr elem
) "\n"))))))
3224 (defun message-insert-newsgroups ()
3225 "Insert the Newsgroups header from the article being replied to."
3227 (when (and (message-position-on-field "Newsgroups")
3228 (mail-fetch-field "newsgroups")
3229 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
3231 (insert (or (message-fetch-reply-field "newsgroups") "")))
3235 ;;; Various commands
3237 (defun message-delete-not-region (beg end
)
3238 "Delete everything in the body of the current message outside of the region."
3243 ;; snarf citation prefix, if appropriate
3244 (unless (eq (point) (progn (beginning-of-line) (point)))
3245 (when (looking-at message-cite-prefix-regexp
)
3246 (setq citeprefix
(match-string 0))))
3248 (delete-region (point) (if (not (message-goto-signature))
3254 (delete-region beg
(progn (message-goto-body)
3258 (insert citeprefix
))))
3259 (when (message-goto-signature)
3262 (defun message-kill-to-signature (&optional arg
)
3263 "Kill all text up to the signature.
3264 If a numeric argument or prefix arg is given, leave that number
3265 of lines before the signature intact."
3269 (let ((point (point)))
3270 (narrow-to-region point
(point-max))
3271 (message-goto-signature)
3273 (if (and arg
(numberp arg
))
3274 (forward-line (- -
1 arg
))
3276 (unless (= point
(point))
3277 (kill-region point
(point))
3281 (defun message-newline-and-reformat (&optional arg not-break
)
3282 "Insert four newlines, and then reformat if inside quoted text.
3283 Prefix arg means justify as well."
3284 (interactive (list (if current-prefix-arg
'full
)))
3285 (let (quoted point beg end leading-space bolp fill-paragraph-function
)
3286 (setq point
(point))
3289 (setq bolp
(= beg point
))
3290 ;; Find first line of the paragraph.
3292 (while (and (not (eobp))
3293 (not (looking-at message-cite-prefix-regexp
))
3294 (looking-at paragraph-start
))
3297 (when (looking-at message-cite-prefix-regexp
)
3298 (setq quoted
(match-string 0))
3299 (goto-char (match-end 0))
3300 (looking-at "[ \t]*")
3301 (setq leading-space
(match-string 0)))
3305 (< (- point beg
) (length quoted
)))
3306 ;; break inside the cite prefix.
3312 (while (and (not (eobp))
3313 (not (looking-at paragraph-separate
))
3314 (looking-at message-cite-prefix-regexp
)
3315 (equal quoted
(match-string 0)))
3316 (goto-char (match-end 0))
3317 (looking-at "[ \t]*")
3318 (if (> (length leading-space
) (length (match-string 0)))
3319 (setq leading-space
(match-string 0)))
3323 (while (and (if (bobp) nil
(forward-line -
1) t
)
3324 (not (looking-at paragraph-start
))
3325 (looking-at message-cite-prefix-regexp
)
3326 (equal quoted
(match-string 0)))
3328 (goto-char (match-end 0))
3329 (looking-at "[ \t]*")
3330 (if (> (length leading-space
) (length (match-string 0)))
3331 (setq leading-space
(match-string 0)))))
3332 (while (and (not (eobp))
3333 (not (looking-at paragraph-separate
))
3334 (not (looking-at message-cite-prefix-regexp
)))
3338 (while (and (if (bobp) nil
(forward-line -
1) t
)
3339 (not (looking-at paragraph-start
))
3340 (not (looking-at message-cite-prefix-regexp
)))
3341 (setq beg
(point))))
3344 (narrow-to-region beg end
)
3351 (setq point
(point))
3352 ;; (newline 2) doesn't mark both newline's as hard, so call
3353 ;; newline twice. -jas
3356 (delete-region (point) (re-search-forward "[ \t]*"))
3357 (when (and quoted
(not bolp
))
3358 (insert quoted leading-space
)))
3361 (let* ((adaptive-fill-regexp
3362 (regexp-quote (concat quoted leading-space
)))
3363 (adaptive-fill-first-line-regexp
3364 adaptive-fill-regexp
))
3365 (fill-paragraph arg
))
3366 (fill-paragraph arg
))
3367 (if point
(goto-char point
)))))
3369 (defun message-fill-paragraph (&optional arg
)
3370 "Message specific function to fill a paragraph.
3371 This function is used as the value of `fill-paragraph-function' in
3372 Message buffers and is not meant to be called directly."
3373 (interactive (list (if current-prefix-arg
'full
)))
3374 (if (if (boundp 'filladapt-mode
) filladapt-mode
)
3376 (if (message-point-in-header-p)
3377 (message-fill-field)
3378 (message-newline-and-reformat arg t
))
3381 (defun message-point-in-header-p ()
3382 "Return t if point is in the header."
3384 (not (re-search-backward
3385 (concat "^" (regexp-quote mail-header-separator
) "\n") nil t
))))
3387 (defun message-do-auto-fill ()
3388 "Like `do-auto-fill', but don't fill in message header."
3389 (unless (message-point-in-header-p)
3392 (defun message-insert-signature (&optional force
)
3393 "Insert a signature. See documentation for variable `message-signature'."
3394 (interactive (list 0))
3397 ((and (null message-signature
)
3400 (goto-char (point-max))
3401 (not (re-search-backward message-signature-separator nil t
))))
3402 ((and (null message-signature
)
3405 ((functionp message-signature
)
3406 (funcall message-signature
))
3407 ((listp message-signature
)
3408 (eval message-signature
))
3409 (t message-signature
)))
3412 (cond ((stringp signature
)
3414 ((and (eq t signature
) message-signature-file
)
3415 (setq signature-file
3416 (if (and message-signature-directory
3417 ;; don't actually use the signature directory
3418 ;; if message-signature-file contains a path.
3419 (not (file-name-directory
3420 message-signature-file
)))
3421 (expand-file-name message-signature-file
3422 message-signature-directory
)
3423 message-signature-file
))
3424 (file-exists-p signature-file
))))
3426 (goto-char (point-max))
3427 ;; Insert the signature.
3430 (when message-signature-insert-empty-line
3433 (if (eq signature t
)
3434 (insert-file-contents signature-file
)
3436 (goto-char (point-max))
3437 (or (bolp) (insert "\n")))))
3439 (defun message-insert-importance-high ()
3440 "Insert header to mark message as important."
3444 (message-narrow-to-headers)
3445 (message-remove-header "Importance"))
3447 (insert "Importance: high\n")))
3449 (defun message-insert-importance-low ()
3450 "Insert header to mark message as unimportant."
3454 (message-narrow-to-headers)
3455 (message-remove-header "Importance"))
3457 (insert "Importance: low\n")))
3459 (defun message-insert-or-toggle-importance ()
3460 "Insert a \"Importance: high\" header, or cycle through the header values.
3461 The three allowed values according to RFC 1327 are `high', `normal'
3468 (message-narrow-to-headers)
3469 (when (setq cur
(message-fetch-field "Importance"))
3470 (message-remove-header "Importance")
3471 (setq new
(cond ((string= cur
"high")
3473 ((string= cur
"low")
3478 (insert (format "Importance: %s\n" new
)))))
3480 (defun message-insert-disposition-notification-to ()
3481 "Request a disposition notification (return receipt) to this message.
3482 Note that this should not be used in newsgroups."
3486 (message-narrow-to-headers)
3487 (message-remove-header "Disposition-Notification-To"))
3489 (insert (format "Disposition-Notification-To: %s\n"
3490 (or (message-field-value "Reply-to")
3491 (message-field-value "From")
3492 (message-make-from))))))
3494 (defun message-elide-region (b e
)
3495 "Elide the text in the region.
3496 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3500 (insert message-elide-ellipsis
))
3502 (defvar message-caesar-translation-table nil
)
3504 (defun message-caesar-region (b e
&optional n
)
3505 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3508 (min (point) (or (mark t
) (point)))
3509 (max (point) (or (mark t
) (point)))
3510 (when current-prefix-arg
3511 (prefix-numeric-value current-prefix-arg
))))
3513 (setq n
(if (numberp n
) (mod n
26) 13)) ;canonize N
3514 (unless (or (zerop n
) ; no action needed for a rot of 0
3515 (= b e
)) ; no region to rotate
3516 ;; We build the table, if necessary.
3517 (when (or (not message-caesar-translation-table
)
3518 (/= (aref message-caesar-translation-table ?a
) (+ ?a n
)))
3519 (setq message-caesar-translation-table
3520 (message-make-caesar-translation-table n
)))
3521 (translate-region b e message-caesar-translation-table
)))
3523 (defun message-make-caesar-translation-table (n)
3524 "Create a rot table with offset N."
3526 (table (make-string 256 0)))
3527 (while (< (incf i
) 256)
3530 (substring table
0 ?A
)
3531 (substring table
(+ ?A n
) (+ ?A n
(- 26 n
)))
3532 (substring table ?A
(+ ?A n
))
3533 (substring table
(+ ?A
26) ?a
)
3534 (substring table
(+ ?a n
) (+ ?a n
(- 26 n
)))
3535 (substring table ?a
(+ ?a n
))
3536 (substring table
(+ ?a
26) 255))))
3538 (defun message-caesar-buffer-body (&optional rotnum wide
)
3539 "Caesar rotate all letters in the current buffer by 13 places.
3540 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3541 With prefix arg, specifies the number of places to rotate each letter forward.
3542 Mail and USENET news headers are not rotated unless WIDE is non-nil."
3543 (interactive (if current-prefix-arg
3544 (list (prefix-numeric-value current-prefix-arg
))
3548 (when (and (not wide
) (message-goto-body))
3549 (narrow-to-region (point) (point-max)))
3550 (message-caesar-region (point-min) (point-max) rotnum
))))
3552 (defun message-pipe-buffer-body (program)
3553 "Pipe the message body in the current buffer through PROGRAM."
3556 (when (message-goto-body)
3557 (narrow-to-region (point) (point-max)))
3558 (shell-command-on-region
3559 (point-min) (point-max) program nil t
))))
3561 (defun message-rename-buffer (&optional enter-string
)
3562 "Rename the *message* buffer to \"*message* RECIPIENT\".
3563 If the function is run with a prefix, it will ask for a new buffer
3564 name, rather than giving an automatic name."
3565 (interactive "Pbuffer name: ")
3568 (goto-char (point-min))
3569 (narrow-to-region (point)
3570 (search-forward mail-header-separator nil
'end
))
3572 (if (message-news-p) (message-fetch-field "Newsgroups")
3573 (message-fetch-field "To"))
3576 (if (string-match "," mail-to
)
3577 (concat (substring mail-to
0 (match-beginning 0)) ", ...")
3579 (name-default (concat "*message* " mail-trimmed-to
))
3580 (name (if enter-string
3581 (read-string "New buffer name: " name-default
)
3583 (rename-buffer name t
)))))
3585 (defun message-fill-yanked-message (&optional justifyp
)
3586 "Fill the paragraphs of a message yanked into this one.
3587 Numeric argument means justify as well."
3590 (goto-char (point-min))
3591 (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
3592 (let ((fill-prefix message-yank-prefix
))
3593 (fill-individual-paragraphs (point) (point-max) justifyp
))))
3595 (defun message-indent-citation (&optional start end yank-only
)
3596 "Modify text just inserted from a message to be cited.
3597 The inserted text should be the region.
3598 When this function returns, the region is again around the modified text.
3600 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3601 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3602 (unless start
(setq start
(point)))
3604 ;; Remove unwanted headers.
3605 (when message-ignored-cited-headers
3610 (if (search-forward "\n\n" nil t
)
3613 (message-remove-header message-ignored-cited-headers t
)
3614 (when (= (point-min) (point-max))
3615 (setq all-removed t
))
3616 (goto-char (point-max)))
3620 ;; Delete blank lines at the start of the buffer.
3621 (while (and (point-min)
3624 (message-delete-line))
3625 ;; Delete blank lines at the end of the buffer.
3626 (goto-char (point-max))
3629 (while (and (zerop (forward-line -
1))
3631 (message-delete-line)))
3632 ;; Do the indentation.
3633 (if (null message-yank-prefix
)
3634 (indent-rigidly start
(or end
(mark t
)) message-indentation-spaces
)
3637 (while (< (point) (or end
(mark t
)))
3638 (cond ((looking-at ">")
3639 (insert message-yank-cited-prefix
))
3641 (insert message-yank-empty-prefix
))
3643 (insert message-yank-prefix
)))
3647 (defun message-remove-blank-cited-lines (&optional remove
)
3648 "Remove cited lines containing only blanks.
3649 If REMOVE is non-nil, remove newlines, too.
3651 To use this automatically, you may add this function to
3652 `gnus-message-setup-hook'."
3657 (when (boundp 'message-yank-cited-prefix
)
3658 (concat message-yank-cited-prefix
"\\|"))
3662 (gnus-message 8 "removing `%s'" citexp
)
3665 (while (re-search-forward citexp nil t
)
3666 (replace-match (if remove
"" "\n"))))))
3668 (defvar message-cite-reply-above nil
3669 "If non-nil, start own text above the quote.
3671 Note: Top posting is bad netiquette. Don't use it unless you
3672 really must. You probably want to set variable only for specific
3673 groups, e.g. using `gnus-posting-styles':
3675 (eval (set (make-local-variable 'message-cite-reply-above) t))
3677 This variable has no effect in news postings.")
3679 (defun message-yank-original (&optional arg
)
3680 "Insert the message being replied to, if any.
3681 Puts point before the text and mark after.
3682 Normally indents each nonblank line ARG spaces (default 3). However,
3683 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3685 This function uses `message-cite-function' to do the actual citing.
3687 Just \\[universal-argument] as argument means don't indent, insert no
3688 prefix, and don't delete any headers."
3690 (let ((modified (buffer-modified-p))
3692 (when (and message-reply-buffer
3693 message-cite-function
)
3694 (when message-cite-reply-above
3695 (if (and (not (message-news-p))
3696 (or (eq message-cite-reply-above
'is-evil
)
3698 Top posting is bad netiquette. Please don't top post unless you really must.
3699 Really top post? ")))
3702 (buffer-substring (message-goto-body)
3704 (delete-region (message-goto-body) (point-max)))
3705 (set (make-local-variable 'message-cite-reply-above
) nil
)))
3706 (if (bufferp message-reply-buffer
)
3707 (delete-windows-on message-reply-buffer t
))
3708 (push-mark (save-excursion
3710 ((bufferp message-reply-buffer
)
3711 (insert-buffer-substring message-reply-buffer
))
3712 ((and (consp message-reply-buffer
)
3713 (functionp (car message-reply-buffer
)))
3714 (apply (car message-reply-buffer
)
3715 (cdr message-reply-buffer
))))
3720 (funcall message-cite-function
)
3721 (unless (eq (char-before (mark t
)) ?
\n)
3723 (goto-char (mark t
))
3724 (insert-before-markers ?
\n)
3726 (when message-cite-reply-above
3729 (insert (if (bolp) "\n" "\n\n"))
3730 (message-goto-body))
3731 ;; Add a `message-setup-very-last-hook' here?
3732 ;; Add `gnus-article-highlight-citation' here?
3734 (setq message-checksum
(message-checksum))))))
3736 (defun message-yank-buffer (buffer)
3737 "Insert BUFFER into the current buffer and quote it."
3738 (interactive "bYank buffer: ")
3739 (let ((message-reply-buffer (get-buffer buffer
)))
3740 (save-window-excursion
3741 (message-yank-original))))
3743 (defun message-buffers ()
3744 "Return a list of active message buffers."
3746 (save-current-buffer
3747 (dolist (buffer (buffer-list t
))
3749 (when (and (eq major-mode
'message-mode
)
3750 (null message-sent-message-via
))
3751 (push (buffer-name buffer
) buffers
))))
3752 (nreverse buffers
)))
3754 (defun message-cite-original-1 (strip-signature)
3755 "Cite an original message.
3756 If STRIP-SIGNATURE is non-nil, strips off the signature from the
3759 This function uses `mail-citation-hook' if that is non-nil."
3760 (if (and (boundp 'mail-citation-hook
)
3762 (run-hooks 'mail-citation-hook
)
3763 (let* ((start (point))
3767 (when message-indent-citation-function
3768 (if (listp message-indent-citation-function
)
3769 message-indent-citation-function
3770 (list message-indent-citation-function
))))
3771 ;; This function may be called by `gnus-summary-yank-message' and
3772 ;; may insert a different article from the original. So, we will
3773 ;; modify the value of `message-reply-headers' with that article.
3774 (message-reply-headers
3776 (narrow-to-region start end
)
3777 (message-narrow-to-head-1)
3778 (setq x-no-archive
(message-fetch-field "x-no-archive"))
3780 (or (message-fetch-field "subject") "none")
3781 (or (message-fetch-field "from") "nobody")
3782 (message-fetch-field "date")
3783 (message-fetch-field "message-id" t
)
3784 (message-fetch-field "references")
3786 (mml-quote-region start end
)
3787 (when strip-signature
3791 (when (re-search-backward message-signature-separator start t
)
3792 ;; Also peel off any blank lines before the signature.
3794 (while (looking-at "^[ \t]*$")
3797 (delete-region (point) end
)
3798 (unless (search-backward "\n\n" start t
)
3799 ;; Insert a blank line if it is peeled off.
3802 (mapc 'funcall functions
)
3803 (when message-citation-line-function
3806 (funcall message-citation-line-function
))
3807 (when (and x-no-archive
3808 (not message-cite-articles-with-x-no-archive
)
3809 (string-match "yes" x-no-archive
))
3811 (delete-region (point) (mark t
))
3812 (insert "> [Quoted text removed due to X-No-Archive]\n")
3814 (forward-line -
1)))))
3816 (defun message-cite-original ()
3817 "Cite function in the standard Message manner."
3818 (message-cite-original-1 nil
))
3820 (defvar gnus-extract-address-components
)
3822 (autoload 'format-spec
"format-spec")
3824 (defun message-insert-formatted-citation-line (&optional from date
)
3825 "Function that inserts a formatted citation line.
3827 See `message-citation-line-format'."
3828 ;; The optional args are for testing/debugging. They will disappear later.
3830 ;; (with-temp-buffer
3831 ;; (message-insert-formatted-citation-line
3832 ;; "John Doe <john.doe@example.invalid>"
3835 (when (or message-reply-headers
(and from date
))
3837 (setq from
(mail-header-from message-reply-headers
)))
3838 (let* ((data (condition-case ()
3839 (funcall (if (boundp gnus-extract-address-components
)
3840 gnus-extract-address-components
3841 'mail-extract-address-components
)
3847 (net (car (cdr data
)))
3848 (name-or-net (or (car data
)
3849 (car (cdr data
)) from
))
3853 ;; We need Gnus functionality if the user wants date or time from
3854 ;; the original article:
3855 (when (string-match "%[^fnNFL]" message-citation-line-format
)
3856 (autoload 'gnus-date-get-time
"gnus-util")
3857 (gnus-date-get-time (mail-header-date message-reply-headers
)))))
3860 (when (stringp name
)
3861 ;; Guess first name and last name:
3862 (cond ((string-match
3863 "\\`\\(\\w\\|[-.]\\)+ \\(\\w\\|[-.]\\)+\\'" name
)
3864 (setq fname
(nth 0 (split-string name
"[ \t]+"))
3865 lname
(nth 1 (split-string name
"[ \t]+"))))
3867 "\\`\\(\\w\\|[-.]\\)+, \\(\\w\\|[-.]\\)+\\'" name
)
3868 (setq fname
(nth 1 (split-string name
"[ \t,]+"))
3869 lname
(nth 0 (split-string name
"[ \t,]+"))))
3871 "\\`\\(\\w\\|[-.]\\)+\\'" name
)
3874 ;; The following letters are not used in `format-time-string':
3875 (push ?E lst
) (push "<E>" lst
)
3876 (push ?F lst
) (push fname lst
)
3877 ;; We might want to use "" instead of "<X>" later.
3878 (push ?J lst
) (push "<J>" lst
)
3879 (push ?K lst
) (push "<K>" lst
)
3880 (push ?L lst
) (push lname lst
)
3881 (push ?N lst
) (push name-or-net lst
)
3882 (push ?O lst
) (push "<O>" lst
)
3883 (push ?P lst
) (push "<P>" lst
)
3884 (push ?Q lst
) (push "<Q>" lst
)
3885 (push ?f lst
) (push from lst
)
3886 (push ?i lst
) (push "<i>" lst
)
3887 (push ?n lst
) (push net lst
)
3888 (push ?o lst
) (push "<o>" lst
)
3889 (push ?q lst
) (push "<q>" lst
)
3890 (push ?t lst
) (push "<t>" lst
)
3891 (push ?v lst
) (push "<v>" lst
)
3892 ;; Delegate the rest to `format-time-string':
3894 (when (and (not (memq i lst
))
3899 (push (condition-case nil
3900 (format-time-string (format "%%%c" i
) replydate
)
3901 (error (format ">%c<" i
)))
3905 (spec (apply 'format-spec-make flist
)))
3906 (insert (format-spec message-citation-line-format spec
)))
3909 (defun message-cite-original-without-signature ()
3910 "Cite function in the standard Message manner.
3911 This function strips off the signature from the original message."
3912 (message-cite-original-1 t
))
3914 (defun message-insert-citation-line ()
3915 "Insert a simple citation line."
3916 (when message-reply-headers
3917 (insert (mail-header-from message-reply-headers
) " writes:")
3921 (defun message-position-on-field (header &rest afters
)
3922 (let ((case-fold-search t
))
3925 (goto-char (point-min))
3928 (concat "^" (regexp-quote mail-header-separator
) "$"))
3929 (match-beginning 0)))
3930 (goto-char (point-min))
3931 (if (re-search-forward (concat "^" (regexp-quote header
) ":") nil t
)
3933 (re-search-forward "^[^ \t]" nil
'move
)
3935 (skip-chars-backward "\n")
3938 (not (re-search-forward
3939 (concat "^" (regexp-quote (car afters
)) ":")
3943 (re-search-forward "^[^ \t]" nil
'move
)
3944 (beginning-of-line))
3945 (insert header
": \n")
3949 (defun message-remove-signature ()
3950 "Remove the signature from the text between point and mark.
3951 The text will also be indented the normal way."
3953 (let ((start (point))
3955 (if (not (re-search-forward message-signature-separator
(mark t
) t
))
3956 ;; No signature here, so we just indent the cited text.
3957 (message-indent-citation)
3958 ;; Find the last non-empty line.
3960 (while (looking-at "[ \t]*$")
3963 (setq mark
(set-marker (make-marker) (point)))
3965 (message-indent-citation)
3966 ;; Enable undoing the deletion.
3968 (delete-region mark
(mark t
))
3969 (set-marker mark nil
)))))
3974 ;;; Sending messages
3977 (defun message-send-and-exit (&optional arg
)
3978 "Send message like `message-send', then, if no errors, exit from mail buffer."
3980 (let ((buf (current-buffer))
3981 (actions message-exit-actions
))
3982 (when (and (message-send arg
)
3984 (if message-kill-buffer-on-exit
3987 (when (eq buf
(current-buffer))
3988 (message-bury buf
)))
3989 (message-do-actions actions
)
3992 (defun message-dont-send ()
3993 "Don't send the message you have been editing.
3994 Instead, just auto-save the buffer and then bury it."
3996 (set-buffer-modified-p t
)
3998 (let ((actions message-postpone-actions
))
3999 (message-bury (current-buffer))
4000 (message-do-actions actions
)))
4002 (defun message-kill-buffer ()
4003 "Kill the current buffer."
4005 (when (or (not (buffer-modified-p))
4006 (not message-kill-buffer-query
)
4007 (yes-or-no-p "Message modified; kill anyway? "))
4008 (let ((actions message-kill-actions
)
4009 (draft-article message-draft-article
)
4010 (auto-save-file-name buffer-auto-save-file-name
)
4011 (file-name buffer-file-name
)
4012 (modified (buffer-modified-p)))
4013 (setq buffer-file-name nil
)
4014 (kill-buffer (current-buffer))
4015 (when (and (or (and auto-save-file-name
4016 (file-exists-p auto-save-file-name
))
4018 (file-exists-p file-name
)))
4020 ;; If the message buffer has lived in a dedicated window,
4021 ;; `kill-buffer' has killed the frame. Thus the
4022 ;; `yes-or-no-p' may show up in a lowered frame. Make sure
4023 ;; that the user can see the question by raising the
4026 (yes-or-no-p (format "Remove the backup file%s? "
4027 (if modified
" too" "")))))
4029 (delete-file auto-save-file-name
))
4030 (let ((message-draft-article draft-article
))
4031 (message-disassociate-draft)))
4032 (message-do-actions actions
))))
4034 (defun message-bury (buffer)
4035 "Bury this mail BUFFER."
4036 (let ((newbuf (other-buffer buffer
)))
4037 (bury-buffer buffer
)
4038 (if (and (window-dedicated-p (selected-window))
4039 (not (null (delq (selected-frame) (visible-frame-list)))))
4040 (delete-frame (selected-frame))
4041 (switch-to-buffer newbuf
))))
4043 (defun message-send (&optional arg
)
4044 "Send the message in the current buffer.
4045 If `message-interactive' is non-nil, wait for success indication or
4046 error messages, and inform user.
4047 Otherwise any failure is reported in a message back to the user from
4049 The usage of ARG is defined by the instance that called Message.
4050 It should typically alter the sending method in some way or other."
4052 ;; Make it possible to undo the coming changes.
4054 (let ((inhibit-read-only t
))
4055 (put-text-property (point-min) (point-max) 'read-only nil
))
4056 (message-fix-before-sending)
4057 (run-hooks 'message-send-hook
)
4058 (when message-confirm-send
4059 (or (y-or-n-p "Send message? ")
4061 (message message-sending-message
)
4062 (let ((alist message-send-method-alist
)
4064 elem sent dont-barf-on-no-method
4065 (message-options message-options
))
4066 (message-options-set-recipient)
4068 (setq elem
(pop alist
)))
4069 (when (funcall (cadr elem
))
4070 (when (and (or (not (memq (car elem
)
4071 message-sent-message-via
))
4072 (message-fetch-field "supersedes")
4073 (if (or (message-gnksa-enable-p 'multiple-copies
)
4074 (not (eq (car elem
) 'news
)))
4077 "Already sent message via %s; resend? "
4079 (error "Denied posting -- multiple copies")))
4080 (setq success
(funcall (caddr elem
) arg
)))
4084 (let ((fcc (message-fetch-field "Fcc"))
4085 (gcc (message-fetch-field "Gcc")))
4087 (or (eq message-allow-no-recipients
'always
)
4088 (and (not (eq message-allow-no-recipients
'never
))
4089 (setq dont-barf-on-no-method
4091 (format "No receiver, perform %s anyway? "
4092 (cond ((and fcc gcc
) "Fcc and Gcc")
4095 (error "No methods specified to send by"))
4096 (when (or dont-barf-on-no-method
4100 (run-hooks 'message-sent-hook
))
4101 (message "Sending...done")
4102 ;; Do ecomplete address snarfing.
4103 (when (and (message-mail-alias-type-p 'ecomplete
)
4104 (not message-inhibit-ecomplete
))
4105 (message-put-addresses-in-ecomplete))
4106 ;; Mark the buffer as unmodified and delete auto-save.
4107 (set-buffer-modified-p nil
)
4108 (delete-auto-save-file-if-necessary t
)
4109 (message-disassociate-draft)
4110 ;; Delete other mail buffers and stuff.
4111 (message-do-send-housekeeping)
4112 (message-do-actions message-send-actions
)
4116 (defun message-send-via-mail (arg)
4117 "Send the current message via mail."
4118 (message-send-mail arg
))
4120 (defun message-send-via-news (arg)
4121 "Send the current message via news."
4122 (funcall message-send-news-function arg
))
4124 (defmacro message-check
(type &rest forms
)
4125 "Eval FORMS if TYPE is to be checked."
4126 `(or (message-check-element ,type
)
4130 (put 'message-check
'lisp-indent-function
1)
4131 (put 'message-check
'edebug-form-spec
'(form body
))
4133 (defun message-text-with-property (prop &optional start end reverse
)
4134 "Return a list of start and end positions where the text has PROP.
4135 START and END bound the search, they default to `point-min' and
4136 `point-max' respectively. If REVERSE is non-nil, find text which does
4139 (setq start
(point-min)))
4141 (setq end
(point-max)))
4145 (setq start
(text-property-any start end prop nil
)))
4146 (setq next
(next-single-property-change start prop nil end
))
4147 (push (cons start
(or next end
)) regions
)
4150 (or (get-text-property start prop
)
4151 (and (setq start
(next-single-property-change
4152 start prop nil end
))
4153 (get-text-property start prop
))))
4154 (setq next
(text-property-any start end prop nil
))
4155 (push (cons start
(or next end
)) regions
)
4157 (nreverse regions
)))
4159 (defcustom message-bogus-addresses
4160 ;; '("noreply" "nospam" "invalid")
4161 '("noreply" "nospam" "invalid" "@@" "[^[:ascii:]].*@" "[ \t]")
4162 "List of regexps of potentially bogus mail addresses.
4163 See `message-check-recipients' how to setup checking.
4165 This list should make it possible to catch typos or warn about
4166 spam-trap addresses. It doesn't aim to verify strict RFC
4168 :version
"23.1" ;; No Gnus
4169 :group
'message-headers
4171 (const :tag
"None" nil
)
4177 (const :tag
"duplicate @" "@@")
4178 (const :tag
"non-ascii local part" "[^[:ascii:]].*@")
4179 ;; Already caught by `message-valid-fqdn-regexp'
4180 ;; (const :tag "`_' in domain part" "@.*_")
4181 (const :tag
"whitespace" "[ \t]"))
4186 (defun message-fix-before-sending ()
4187 "Do various things to make the message nice before sending it."
4188 ;; Make sure there's a newline at the end of the message.
4189 (goto-char (point-max))
4192 ;; Make the hidden headers visible.
4194 ;; Sort headers before sending the message.
4195 (message-sort-headers)
4196 ;; Make invisible text visible.
4197 ;; It doesn't seem as if this is useful, since the invisible property
4198 ;; is clobbered by an after-change hook anyhow.
4199 (message-check 'invisible-text
4200 (let ((regions (message-text-with-property 'invisible
))
4204 (setq from
(caar regions
)
4206 regions
(cdr regions
))
4207 (put-text-property from to
'invisible nil
)
4208 (message-overlay-put (message-make-overlay from to
)
4210 (unless (yes-or-no-p
4211 "Invisible text found and made visible; continue sending? ")
4212 (error "Invisible text found and made visible")))))
4213 (message-check 'illegible-text
4214 (let (char found choice
)
4217 (skip-chars-forward mm-7bit-chars
)
4218 (when (get-text-property (point) 'no-illegible-text
)
4219 ;; There is a signed or encrypted raw message part
4220 ;; that is considered to be safe.
4221 (goto-char (or (next-single-property-change
4222 (point) 'no-illegible-text
)
4224 (setq char
(char-after)))
4225 (when (or (< (mm-char-int char
) 128)
4226 (and (mm-multibyte-p)
4227 (memq (char-charset char
)
4228 '(eight-bit-control eight-bit-graphic
4229 ;; Emacs 23, Bug#1770:
4232 (not (get-text-property
4233 (point) 'untranslated-utf-8
))))
4234 (message-overlay-put (message-make-overlay (point) (1+ (point)))
4240 (gnus-multiple-choice
4241 "Non-printable characters found. Continue sending?"
4242 `((?d
"Remove non-printable characters and send")
4244 "Replace non-printable characters with \"%s\" and send"
4245 message-replacement-char
))
4246 (?i
"Ignore non-printable characters and send")
4247 (?e
"Continue editing"))))
4249 (error "Non-printable characters"))
4251 (skip-chars-forward mm-7bit-chars
)
4253 (when (let ((char (char-after)))
4254 (or (< (mm-char-int char
) 128)
4255 (and (mm-multibyte-p)
4256 ;; FIXME: Wrong for Emacs 23 (unicode) and for
4257 ;; things like undecodable utf-8 (in Emacs 21?).
4258 ;; Should at least use find-coding-systems-region.
4260 (memq (char-charset char
)
4261 '(eight-bit-control eight-bit-graphic
4262 ;; Emacs 23, Bug#1770:
4265 (not (get-text-property
4266 (point) 'untranslated-utf-8
)))))
4268 (message-kill-all-overlays)
4270 (when (eq choice ?r
)
4271 (insert message-replacement-char
))))
4273 (skip-chars-forward mm-7bit-chars
)))))
4274 (message-check 'bogus-recipient
4275 ;; Warn before sending a mail to an invalid address.
4276 (message-check-recipients)))
4278 (defun message-bogus-recipient-p (recipients)
4279 "Check if a mail address in RECIPIENTS looks bogus.
4281 RECIPIENTS is a mail header. Return a list of potentially bogus
4282 addresses. If none is found, return nil.
4284 An address might be bogus if the domain part is not fully
4285 qualified, see `message-valid-fqdn-regexp', or if there's a
4286 matching entry in `message-bogus-addresses'."
4287 ;; FIXME: How about "foo@subdomain", when the MTA adds ".domain.tld"?
4289 (mapc (lambda (address)
4290 (setq address
(cadr address
))
4294 (not (string-match "@" address
))
4297 message-valid-fqdn-regexp
"\\)\\'") address
)))
4298 (and message-bogus-addresses
4300 (if (listp message-bogus-addresses
)
4301 (mapconcat 'identity
4302 message-bogus-addresses
4304 message-bogus-addresses
)))
4305 (string-match re address
))))
4306 (push address found
)))
4308 (mail-extract-address-components recipients t
))
4311 (defun message-check-recipients ()
4312 "Warn before composing or sending a mail to an invalid address.
4314 This function could be useful in `message-setup-hook'."
4317 (message-narrow-to-headers)
4318 (dolist (hdr '("To" "Cc" "Bcc"))
4319 (let ((addr (message-fetch-field hdr
)))
4320 (when (stringp addr
)
4321 (dolist (bog (message-bogus-recipient-p addr
))
4325 "Address `%s' might be bogus. Continue? " bog
)))
4326 (error "Bogus address"))))))))
4328 (custom-add-option 'message-setup-hook
'message-check-recipients
)
4330 (defun message-add-action (action &rest types
)
4331 "Add ACTION to be performed when doing an exit of type TYPES."
4333 (add-to-list (intern (format "message-%s-actions" (pop types
)))
4336 (defun message-delete-action (action &rest types
)
4337 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
4340 (set (setq var
(intern (format "message-%s-actions" (pop types
))))
4341 (delq action
(symbol-value var
))))))
4343 (defun message-do-actions (actions)
4344 "Perform all actions in ACTIONS."
4345 ;; Now perform actions on successful sending.
4346 (dolist (action actions
)
4349 ;; A simple function.
4352 ;; Something to be evaled.
4356 (defun message-send-mail-partially ()
4357 "Send mail as message/partial."
4358 ;; replace the header delimiter with a blank line
4359 (goto-char (point-min))
4361 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4362 (replace-match "\n")
4363 (run-hooks 'message-send-mail-hook
)
4364 (let ((p (goto-char (point-min)))
4365 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
4366 (curbuf (current-buffer))
4367 (id (message-make-message-id)) (n 1)
4368 plist total header required-mail-headers
)
4370 (if (< (point-max) (+ p message-send-mail-partially-limit
))
4371 (goto-char (point-max))
4372 (goto-char (+ p message-send-mail-partially-limit
))
4374 (if (<= (point) p
) (forward-line 1))) ;; In case of bad message.
4377 (setq total
(length plist
))
4378 (push (point-max) plist
)
4379 (setq plist
(nreverse plist
))
4382 (setq p
(pop plist
))
4385 (copy-to-buffer tembuf p
(car plist
))
4387 (goto-char (point-min))
4390 (goto-char (point-min))
4391 (narrow-to-region (point) (point))
4394 (setq header
(buffer-substring (point-min) (point)))
4395 (goto-char (point-min))
4396 (narrow-to-region (point) (point))
4398 (message-remove-header "Mime-Version")
4399 (message-remove-header "Content-Type")
4400 (message-remove-header "Content-Transfer-Encoding")
4401 (message-remove-header "Message-ID")
4402 (message-remove-header "Lines")
4403 (goto-char (point-max))
4404 (insert "Mime-Version: 1.0\n")
4405 (setq header
(buffer-string)))
4406 (goto-char (point-max))
4407 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
4410 (let ((mail-header-separator ""))
4411 (when (memq 'Message-ID message-required-mail-headers
)
4412 (insert "Message-ID: " (message-make-message-id) "\n"))
4413 (when (memq 'Lines message-required-mail-headers
)
4414 (insert "Lines: " (message-make-lines) "\n"))
4415 (message-goto-subject)
4417 (insert (format " (%d/%d)" n total
))
4419 (funcall (or message-send-mail-real-function
4420 message-send-mail-function
)))
4422 (setq p
(pop plist
))
4424 (kill-buffer tembuf
))))
4426 (declare-function hashcash-wait-async
"hashcash" (&optional buffer
))
4428 (defun message-send-mail (&optional arg
)
4429 (require 'mail-utils
)
4430 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
4431 (case-fold-search nil
)
4432 (news (message-news-p))
4433 (mailbuf (current-buffer))
4434 (message-this-is-mail t
)
4435 ;; gnus-setup-posting-charset is autoloaded in mml.el (FIXME
4436 ;; maybe it should not be), which this file requires. Hence
4437 ;; the fboundp test is always true. Loading it from gnus-msg
4438 ;; loads many Gnus files (Bug#5642). If
4439 ;; gnus-group-posting-charset-alist hasn't been customized,
4440 ;; this is just going to return nil anyway. FIXME it would
4441 ;; be good to improve this further, because even if g-g-p-c-a
4442 ;; has been customized, that is likely to just be for news.
4443 ;; Eg either move the definition from gnus-msg, or separate out
4444 ;; the mail and news parts.
4445 (message-posting-charset
4446 (if (and (fboundp 'gnus-setup-posting-charset
)
4447 (boundp 'gnus-group-posting-charset-alist
))
4448 (gnus-setup-posting-charset nil
)
4449 message-posting-charset
))
4450 (headers message-required-mail-headers
))
4451 (when (and message-generate-hashcash
4452 (not (eq message-generate-hashcash
'opportunistic
)))
4453 (message "Generating hashcash...")
4455 ;; Wait for calculations already started to finish...
4456 (hashcash-wait-async)
4457 ;; ...and do calculations not already done. mail-add-payment
4458 ;; will leave existing X-Hashcash headers alone.
4460 (message "Generating hashcash...done"))
4462 (message-narrow-to-headers)
4463 ;; Generate the Mail-Followup-To header if the header is not there...
4464 (if (and (message-subscribed-p)
4465 (not (mail-fetch-field "mail-followup-to")))
4468 (cons "Mail-Followup-To" (message-make-mail-followup-to))
4469 message-required-mail-headers
))
4470 ;; otherwise, delete the MFT header if the field is empty
4471 (when (equal "" (mail-fetch-field "mail-followup-to"))
4472 (message-remove-header "^Mail-Followup-To:")))
4473 ;; Insert some headers.
4474 (let ((message-deletable-headers
4475 (if news nil message-deletable-headers
)))
4476 (message-generate-headers headers
))
4477 ;; Check continuation headers.
4478 (message-check 'continuation-headers
4479 (goto-char (point-min))
4480 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t
)
4481 (goto-char (match-beginning 0))
4482 (if (y-or-n-p "Fix continuation lines? ")
4485 (unless (y-or-n-p "Send anyway? ")
4486 (error "Failed to send the message")))))
4487 ;; Let the user do all of the above.
4488 (run-hooks 'message-header-hook
))
4490 (with-current-buffer tembuf
4492 ;; Avoid copying text props (except hard newlines).
4493 (insert (with-current-buffer mailbuf
4494 (mml-buffer-substring-no-properties-except-hard-newlines
4495 (point-min) (point-max))))
4496 ;; Remove some headers.
4497 (message-encode-message-body)
4499 (message-narrow-to-headers)
4500 ;; We (re)generate the Lines header.
4501 (when (memq 'Lines message-required-mail-headers
)
4502 (message-generate-headers '(Lines)))
4503 ;; Remove some headers.
4504 (message-remove-header message-ignored-mail-headers t
)
4505 (let ((mail-parse-charset message-default-charset
))
4506 (mail-encode-encoded-word-buffer)))
4507 (goto-char (point-max))
4508 ;; require one newline at the end.
4509 (or (= (preceding-char) ?
\n)
4511 (message-cleanup-headers)
4512 ;; FIXME: we're inserting the courtesy copy after encoding.
4513 ;; This is wrong if the courtesy copy string contains
4514 ;; non-ASCII characters. -- jh
4517 (message-narrow-to-headers)
4519 (or (message-fetch-field "cc")
4520 (message-fetch-field "bcc")
4521 (message-fetch-field "to"))
4522 (let ((content-type (message-fetch-field
4527 (string= "text/plain"
4529 (mail-header-parse-content-type
4533 (message-fetch-field
4534 "content-transfer-encoding")))))))
4535 (message-insert-courtesy-copy))
4536 ;; Let's make sure we encoded all the body.
4537 (assert (save-excursion
4538 (goto-char (point-min))
4539 (not (re-search-forward "[^\000-\377]" nil t
))))
4540 (mm-disable-multibyte)
4541 (if (or (not message-send-mail-partially-limit
)
4542 (< (buffer-size) message-send-mail-partially-limit
)
4543 (not (message-y-or-n-p
4544 "The message size is too large, split? "
4548 (/ (buffer-size) 1000) "KB, is too large.
4550 Some mail gateways (MTA's) bounce large messages. To avoid the
4551 problem, answer `y', and the message will be split into several
4552 smaller pieces, the size of each is about "
4553 (/ message-send-mail-partially-limit
1000)
4557 However, some mail readers (MUA's) can't read split messages, i.e.,
4558 mails in message/partially format. Answer `n', and the message will be
4561 The size limit is controlled by `message-send-mail-partially-limit'.
4562 If you always want Gnus to send messages in one piece, set
4563 `message-send-mail-partially-limit' to nil.
4566 (message "Sending via mail...")
4567 (funcall (or message-send-mail-real-function
4568 message-send-mail-function
)))
4569 (message-send-mail-partially)))
4570 (kill-buffer tembuf
))
4571 (set-buffer mailbuf
)
4572 (push 'mail message-sent-message-via
)))
4574 (defun message-send-mail-with-sendmail ()
4575 "Send off the prepared buffer with sendmail."
4577 (let ((errbuf (if message-interactive
4578 (message-generate-new-buffer-clone-locals
4581 resend-to-addresses delimline
)
4584 (let ((case-fold-search t
))
4586 (message-narrow-to-headers)
4587 (setq resend-to-addresses
(message-fetch-field "resent-to")))
4588 ;; Change header-delimiter to be what sendmail expects.
4589 (goto-char (point-min))
4591 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4592 (replace-match "\n")
4594 (setq delimline
(point-marker))
4595 (run-hooks 'message-send-mail-hook
)
4596 ;; Insert an extra newline if we need it to work around
4597 ;; Sun's bug that swallows newlines.
4598 (goto-char (1+ delimline
))
4599 (when (eval message-mailer-swallows-blank-line
)
4601 (when message-interactive
4602 (with-current-buffer errbuf
4604 (let* ((default-directory "/")
4605 (coding-system-for-write message-send-coding-system
)
4607 'call-process-region
4609 (list (point-min) (point-max)
4610 (cond ((boundp 'sendmail-program
)
4612 ((file-exists-p "/usr/sbin/sendmail")
4613 "/usr/sbin/sendmail")
4614 ((file-exists-p "/usr/lib/sendmail")
4615 "/usr/lib/sendmail")
4616 ((file-exists-p "/usr/ucblib/sendmail")
4617 "/usr/ucblib/sendmail")
4619 nil errbuf nil
"-oi")
4620 message-sendmail-extra-arguments
4621 ;; Always specify who from,
4622 ;; since some systems have broken sendmails.
4623 ;; But some systems are more broken with -f, so
4624 ;; we'll let users override this.
4625 (and (null message-sendmail-f-is-evil
)
4626 (list "-f" (message-sendmail-envelope-from)))
4627 ;; These mean "report errors by mail"
4628 ;; and "deliver in background".
4629 (if (null message-interactive
) '("-oem" "-odb"))
4630 ;; Get the addresses from the message
4631 ;; unless this is a resend.
4632 ;; We must not do that for a resend
4633 ;; because we would find the original addresses.
4634 ;; For a resend, include the specific addresses.
4635 (if resend-to-addresses
4636 (list resend-to-addresses
)
4638 (unless (or (null cpr
) (and (numberp cpr
) (zerop cpr
)))
4639 (if errbuf
(pop-to-buffer errbuf
))
4640 (error "Sending...failed with exit value %d" cpr
)))
4641 (when message-interactive
4642 (with-current-buffer errbuf
4643 (goto-char (point-min))
4644 (while (re-search-forward "\n+ *" nil t
)
4645 (replace-match "; "))
4646 (if (not (zerop (buffer-size)))
4647 (error "Sending...failed to %s"
4648 (buffer-string))))))
4649 (when (bufferp errbuf
)
4650 (kill-buffer errbuf
)))))
4652 (defun message-send-mail-with-qmail ()
4653 "Pass the prepared message buffer to qmail-inject.
4654 Refer to the documentation for the variable `message-send-mail-function'
4655 to find out how to use this."
4656 ;; replace the header delimiter with a blank line
4657 (goto-char (point-min))
4659 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4660 (replace-match "\n")
4661 (run-hooks 'message-send-mail-hook
)
4664 (let ((coding-system-for-write message-send-coding-system
))
4666 'call-process-region
(point-min) (point-max)
4667 message-qmail-inject-program nil nil nil
4668 ;; qmail-inject's default behavior is to look for addresses on the
4669 ;; command line; if there're none, it scans the headers.
4670 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4672 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4673 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4674 ;; message from stdin.
4676 ;; qmail also has the advantage of not having been raped by
4677 ;; various vendors, so we don't have to allow for that, either --
4678 ;; compare this with message-send-mail-with-sendmail and weep
4679 ;; for sendmail's lost innocence.
4681 ;; all this is way cool coz it lets us keep the arguments entirely
4682 ;; free for -inject-arguments -- a big win for the user and for us
4683 ;; since we don't have to play that double-guessing game and the user
4684 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4685 (if (functionp message-qmail-inject-args
)
4686 (funcall message-qmail-inject-args
)
4687 message-qmail-inject-args
)))
4688 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4689 ;; we have to look at the retval instead
4691 (100 (error "qmail-inject reported permanent failure"))
4692 (111 (error "qmail-inject reported transient failure"))
4693 ;; should never happen
4694 (t (error "qmail-inject reported unknown failure"))))
4696 (defun message-send-mail-with-mh ()
4697 "Send the prepared message buffer with mh."
4698 (let ((mh-previous-window-config nil
)
4699 (name (mh-new-draft-name)))
4700 (setq buffer-file-name name
)
4701 ;; MH wants to generate these headers itself.
4702 (when message-mh-deletable-headers
4703 (let ((headers message-mh-deletable-headers
))
4705 (goto-char (point-min))
4706 (and (re-search-forward
4707 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
4708 (message-delete-line))
4710 (run-hooks 'message-send-mail-hook
)
4711 ;; Pass it on to mh.
4714 (defun message-smtpmail-send-it ()
4715 "Send the prepared message buffer with `smtpmail-send-it'.
4716 The only difference from `smtpmail-send-it' is that this command
4717 evaluates `message-send-mail-hook' just before sending a message.
4718 It is useful if your ISP requires the POP-before-SMTP
4719 authentication. See the Gnus manual for details."
4720 (run-hooks 'message-send-mail-hook
)
4723 (defun message-send-mail-with-mailclient ()
4724 "Send the prepared message buffer with `mailclient-send-it'.
4725 The only difference from `mailclient-send-it' is that this
4726 command evaluates `message-send-mail-hook' just before sending a message."
4727 (run-hooks 'message-send-mail-hook
)
4728 (mailclient-send-it))
4730 (defun message-canlock-generate ()
4731 "Return a string that is non-trivial to guess.
4732 Do not use this for anything important, it is cryptographically weak."
4734 (let (sha1-maximum-internal-length)
4735 (sha1 (concat (message-unique-id)
4736 (format "%x%x%x" (random) (random t
) (random))
4737 (prin1-to-string (recent-keys))
4738 (prin1-to-string (garbage-collect))))))
4740 (defvar canlock-password
)
4741 (defvar canlock-password-for-verify
)
4743 (defun message-canlock-password ()
4744 "The password used by message for cancel locks.
4745 This is the value of `canlock-password', if that option is non-nil.
4746 Otherwise, generate and save a value for `canlock-password' first."
4748 (unless canlock-password
4749 (customize-save-variable 'canlock-password
(message-canlock-generate))
4750 (setq canlock-password-for-verify canlock-password
))
4753 (defun message-insert-canlock ()
4754 (when message-insert-canlock
4755 (message-canlock-password)
4756 (canlock-insert-header)))
4758 (autoload 'nnheader-get-report
"nnheader")
4760 (declare-function gnus-setup-posting-charset
"gnus-msg" (group))
4762 (defun message-send-news (&optional arg
)
4764 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4765 (case-fold-search nil
)
4766 (method (if (functionp message-post-method
)
4767 (funcall message-post-method arg
)
4768 message-post-method
))
4769 (newsgroups-field (save-restriction
4770 (message-narrow-to-headers-or-head)
4771 (message-fetch-field "Newsgroups")))
4772 (followup-field (save-restriction
4773 (message-narrow-to-headers-or-head)
4774 (message-fetch-field "Followup-To")))
4775 ;; BUG: We really need to get the charset for each name in the
4776 ;; Newsgroups and Followup-To lines to allow crossposting
4777 ;; between group namess with incompatible character sets.
4778 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4779 (group-field-charset
4780 (gnus-group-name-charset method newsgroups-field
))
4781 (followup-field-charset
4782 (gnus-group-name-charset method
(or followup-field
"")))
4783 (rfc2047-header-encoding-alist
4784 (append (when group-field-charset
4785 (list (cons "Newsgroups" group-field-charset
)))
4786 (when followup-field-charset
4787 (list (cons "Followup-To" followup-field-charset
)))
4788 rfc2047-header-encoding-alist
))
4789 (messbuf (current-buffer))
4790 (message-syntax-checks
4792 (listp message-syntax-checks
))
4793 (cons '(existing-newsgroups . disabled
)
4794 message-syntax-checks
)
4795 message-syntax-checks
))
4796 (message-this-is-news t
)
4797 (message-posting-charset
4798 (gnus-setup-posting-charset newsgroups-field
))
4800 (if (not (message-check-news-body-syntax))
4803 (message-narrow-to-headers)
4804 ;; Insert some headers.
4805 (message-generate-headers message-required-news-headers
)
4806 (message-insert-canlock)
4807 ;; Let the user do all of the above.
4808 (run-hooks 'message-header-hook
))
4809 ;; Note: This check will be disabled by the ".*" default value for
4810 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4811 (when (and group-field-charset
4812 (listp message-syntax-checks
))
4813 (setq message-syntax-checks
4814 (cons '(valid-newsgroups . disabled
)
4815 message-syntax-checks
)))
4816 (message-cleanup-headers)
4817 (if (not (let ((message-post-method method
))
4818 (message-check-news-syntax)))
4821 (with-current-buffer tembuf
4822 (buffer-disable-undo)
4824 ;; Avoid copying text props (except hard newlines).
4826 (with-current-buffer messbuf
4827 (mml-buffer-substring-no-properties-except-hard-newlines
4828 (point-min) (point-max))))
4829 (message-encode-message-body)
4830 ;; Remove some headers.
4832 (message-narrow-to-headers)
4833 ;; We (re)generate the Lines header.
4834 (when (memq 'Lines message-required-mail-headers
)
4835 (message-generate-headers '(Lines)))
4836 ;; Remove some headers.
4837 (message-remove-header message-ignored-news-headers t
)
4838 (let ((mail-parse-charset message-default-charset
))
4839 (mail-encode-encoded-word-buffer)))
4840 (goto-char (point-max))
4841 ;; require one newline at the end.
4842 (or (= (preceding-char) ?
\n)
4844 (let ((case-fold-search t
))
4845 ;; Remove the delimiter.
4846 (goto-char (point-min))
4848 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4849 (replace-match "\n")
4851 (run-hooks 'message-send-news-hook
)
4852 (gnus-open-server method
)
4853 (message "Sending news via %s..." (gnus-server-string method
))
4854 (setq result
(let ((mail-header-separator ""))
4855 (gnus-request-post method
))))
4856 (kill-buffer tembuf
))
4857 (set-buffer messbuf
)
4859 (push 'news message-sent-message-via
)
4860 (message "Couldn't send message via news: %s"
4861 (nnheader-get-report (car method
)))
4865 ;;; Header generation & syntax checking.
4868 (defun message-check-element (type)
4869 "Return non-nil if this TYPE is not to be checked."
4870 (if (eq message-syntax-checks
'dont-check-for-anything-just-trust-me
)
4872 (let ((able (assq type message-syntax-checks
)))
4874 (eq (cdr able
) 'disabled
)))))
4876 (defun message-check-news-syntax ()
4877 "Check the syntax of the message."
4881 ;; We narrow to the headers and check them first.
4884 (message-narrow-to-headers)
4885 (message-check-news-header-syntax))))))
4887 (defun message-check-news-header-syntax ()
4889 ;; Check Newsgroups header.
4890 (message-check 'newsgroups
4891 (let ((group (message-fetch-field "newsgroups")))
4894 (not (string-match "\\`[ \t]*\\'" group
)))
4897 "The newsgroups field is empty or missing. Posting is denied.")))))
4898 ;; Check the Subject header.
4899 (message-check 'subject
4900 (let* ((case-fold-search t
)
4901 (subject (message-fetch-field "subject")))
4904 (not (string-match "\\`[ \t]*\\'" subject
)))
4907 "The subject field is empty or missing. Posting is denied.")))))
4908 ;; Check for commands in Subject.
4909 (message-check 'subject-cmsg
4910 (if (string-match "^cmsg " (message-fetch-field "subject"))
4912 "The control code \"cmsg\" is in the subject. Really post? ")
4914 ;; Check long header lines.
4915 (message-check 'long-header-lines
4916 (let ((start (point))
4920 (while (and (not found
)
4921 (re-search-forward "^\\([^ \t:]+\\): " nil t
))
4922 (if (> (- (point) (match-beginning 0)) 998)
4924 length
(- (point) (match-beginning 0)))
4925 (setq header
(match-string-no-properties 1)))
4926 (setq start
(match-beginning 0))
4929 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
4932 ;; Check for multiple identical headers.
4933 (message-check 'multiple-headers
4935 (while (and (not found
)
4936 (re-search-forward "^[^ \t:]+: " nil t
))
4938 (or (re-search-forward
4943 (match-beginning 0) (- (match-end 0) 2))))
4948 (y-or-n-p (format "Multiple %s headers. Really post? " found
))
4950 ;; Check for Version and Sendsys.
4951 (message-check 'sendsys
4952 (if (re-search-forward "^Sendsys:\\|^Version:" nil t
)
4954 (format "The article contains a %s command. Really post? "
4955 (buffer-substring (match-beginning 0)
4956 (1- (match-end 0)))))
4958 ;; See whether we can shorten Followup-To.
4959 (message-check 'shorten-followup-to
4960 (let ((newsgroups (message-fetch-field "newsgroups"))
4961 (followup-to (message-fetch-field "followup-to"))
4963 (when (and newsgroups
4964 (string-match "," newsgroups
)
4969 (setq to
(completing-read
4970 "Followups to (default no Followup-To header): "
4973 (message-tokenize-header
4975 (goto-char (point-min))
4976 (insert "Followup-To: " to
"\n"))
4978 ;; Check "Shoot me".
4979 (message-check 'shoot
4980 (if (re-search-forward
4981 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t
)
4982 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
4984 ;; Check for Approved.
4985 (message-check 'approved
4986 (if (re-search-forward "^Approved:" nil t
)
4987 (y-or-n-p "The article contains an Approved header. Really post? ")
4989 ;; Check the Message-ID header.
4990 (message-check 'message-id
4991 (let* ((case-fold-search t
)
4992 (message-id (message-fetch-field "message-id" t
)))
4993 (or (not message-id
)
4994 ;; Is there an @ in the ID?
4995 (and (string-match "@" message-id
)
4996 ;; Is there a dot in the ID?
4997 (string-match "@[^.]*\\." message-id
)
4998 ;; Does the ID end with a dot?
4999 (not (string-match "\\.>" message-id
)))
5001 (format "The Message-ID looks strange: \"%s\". Really post? "
5003 ;; Check the Newsgroups & Followup-To headers.
5004 (message-check 'existing-newsgroups
5005 (let* ((case-fold-search t
)
5006 (newsgroups (message-fetch-field "newsgroups"))
5007 (followup-to (message-fetch-field "followup-to"))
5008 (groups (message-tokenize-header
5010 (concat newsgroups
"," followup-to
)
5012 (post-method (if (functionp message-post-method
)
5013 (funcall message-post-method
)
5014 message-post-method
))
5015 ;; KLUDGE to handle nnvirtual groups. Doing this right
5016 ;; would probably involve a new nnoo function.
5017 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
5018 (method (if (and (consp post-method
)
5019 (eq (car post-method
) 'nnvirtual
)
5020 gnus-message-group-art
)
5021 (let ((group (car (nnvirtual-find-group-art
5022 (car gnus-message-group-art
)
5023 (cdr gnus-message-group-art
)))))
5024 (gnus-find-method-for-group group
))
5028 (gnus-group-name-decode
5029 (gnus-group-real-name n
)
5030 (gnus-group-name-charset method n
)))
5031 (gnus-groups-from-server method
)))
5034 (when (and (not (equal (car groups
) "poster"))
5035 (not (member (car groups
) known-groups
))
5036 (not (member (car groups
) errors
)))
5037 (push (car groups
) errors
))
5040 ;; Gnus is not running.
5041 ((or (not (and (boundp 'gnus-active-hashtb
)
5042 gnus-active-hashtb
))
5043 (not (boundp 'gnus-read-active-file
)))
5045 ;; We don't have all the group names.
5046 ((and (or (not gnus-read-active-file
)
5047 (eq gnus-read-active-file
'some
))
5051 "Really use %s possibly unknown group%s: %s? "
5052 (if (= (length errors
) 1) "this" "these")
5053 (if (= (length errors
) 1) "" "s")
5054 (mapconcat 'identity errors
", "))))
5055 ;; There were no errors.
5058 ;; There are unknown groups.
5062 "Really post to %s unknown group%s: %s? "
5063 (if (= (length errors
) 1) "this" "these")
5064 (if (= (length errors
) 1) "" "s")
5065 (mapconcat 'identity errors
", ")))))))
5066 ;; Check continuation headers.
5067 (message-check 'continuation-headers
5068 (goto-char (point-min))
5069 (let ((do-posting t
))
5070 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t
)
5071 (goto-char (match-beginning 0))
5072 (if (y-or-n-p "Fix continuation lines? ")
5075 (unless (y-or-n-p "Send anyway? ")
5076 (setq do-posting nil
))))
5078 ;; Check the Newsgroups & Followup-To headers for syntax errors.
5079 (message-check 'valid-newsgroups
5080 (let ((case-fold-search t
)
5081 (headers '("Newsgroups" "Followup-To"))
5083 (while (and headers
(not error
))
5084 (when (setq header
(mail-fetch-field (car headers
)))
5088 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
5093 (not (string-match "\\.\\'\\|\\.\\." g
)))
5094 (message-tokenize-header header
","))))
5101 (format "The %s header looks odd: \"%s\". Really post? "
5102 (car headers
) header
)))))
5103 (message-check 'repeated-newsgroups
5104 (let ((case-fold-search t
)
5105 (headers '("Newsgroups" "Followup-To"))
5106 header error groups group
)
5109 (when (setq header
(mail-fetch-field (pop headers
)))
5110 (setq groups
(message-tokenize-header header
","))
5111 (while (setq group
(pop groups
))
5112 (when (member group groups
)
5118 (format "Group %s is repeated in headers. Really post? " error
)))))
5119 ;; Check the From header.
5120 (message-check 'from
5121 (let* ((case-fold-search t
)
5122 (from (message-fetch-field "from"))
5126 (message "There is no From line. Posting is denied.")
5128 ((or (not (string-match
5130 (setq ad
(nth 1 (mail-extract-address-components
5131 from
))))) ;larsi@ifi
5132 (string-match "\\.\\." ad
) ;larsi@ifi..uio
5133 (string-match "@\\." ad
) ;larsi@.ifi.uio
5134 (string-match "\\.$" ad
) ;larsi@ifi.uio.
5135 (not (string-match "^[^@]+@[^@]+$" ad
)) ;larsi.ifi.uio
5136 (string-match "(.*).*(.*)" from
)) ;(lars) (lars)
5138 "Denied posting -- the From looks strange: \"%s\"." from
)
5140 ((let ((addresses (rfc822-addresses from
)))
5141 ;; `rfc822-addresses' returns a string if parsing fails.
5142 (while (and (consp addresses
)
5143 (not (eq (string-to-char (car addresses
)) ?\
()))
5144 (setq addresses
(cdr addresses
)))
5147 "Denied posting -- bad From address: \"%s\"." from
)
5150 ;; Check the Reply-To header.
5151 (message-check 'reply-to
5152 (let* ((case-fold-search t
)
5153 (reply-to (message-fetch-field "reply-to"))
5158 ((string-match "," reply-to
)
5160 (format "Multiple Reply-To addresses: \"%s\". Really post? "
5162 ((or (not (string-match
5164 (setq ad
(nth 1 (mail-extract-address-components
5165 reply-to
))))) ;larsi@ifi
5166 (string-match "\\.\\." ad
) ;larsi@ifi..uio
5167 (string-match "@\\." ad
) ;larsi@.ifi.uio
5168 (string-match "\\.$" ad
) ;larsi@ifi.uio.
5169 (not (string-match "^[^@]+@[^@]+$" ad
)) ;larsi.ifi.uio
5170 (string-match "(.*).*(.*)" reply-to
)) ;(lars) (lars)
5173 "The Reply-To looks strange: \"%s\". Really post? "
5177 (defun message-check-news-body-syntax ()
5179 ;; Check for long lines.
5180 (message-check 'long-lines
5181 (goto-char (point-min))
5183 (concat "^" (regexp-quote mail-header-separator
) "$"))
5187 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
5190 (< (- (point) p
) 80)))
5191 (zerop (forward-line 1))))
5195 "You have lines longer than 79 characters. Really post? ")))
5196 ;; Check whether the article is empty.
5197 (message-check 'empty
5198 (goto-char (point-min))
5200 (concat "^" (regexp-quote mail-header-separator
) "$"))
5203 (goto-char (point-max))
5204 (re-search-backward message-signature-separator nil t
)
5206 (or (re-search-backward "[^ \n\t]" b t
)
5207 (if (message-gnksa-enable-p 'empty-article
)
5208 (y-or-n-p "Empty article. Really post? ")
5209 (message "Denied posting -- Empty article.")
5211 ;; Check for control characters.
5212 (message-check 'control-chars
5213 (if (re-search-forward
5214 (mm-string-to-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
5217 "The article contains control characters. Really post? ")
5219 ;; Check excessive size.
5220 (message-check 'size
5221 (if (> (buffer-size) 60000)
5223 (format "The article is %d octets long. Really post? "
5226 ;; Check whether any new text has been added.
5227 (message-check 'new-text
5229 (not message-checksum
)
5230 (not (eq (message-checksum) message-checksum
))
5231 (if (message-gnksa-enable-p 'quoted-text-only
)
5233 "It looks like no new text has been added. Really post? ")
5234 (message "Denied posting -- no new text has been added.")
5236 ;; Check the length of the signature.
5237 (message-check 'signature
5238 (let (sig-start sig-end
)
5239 (goto-char (point-max))
5240 (if (not (re-search-backward message-signature-separator nil t
))
5242 (setq sig-start
(1+ (point-at-eol)))
5244 (if (re-search-forward
5245 "<#/?\\(multipart\\|part\\|external\\|mml\\)" nil t
)
5246 (- (point-at-bol) 1)
5248 (if (>= (count-lines sig-start sig-end
) 5)
5249 (if (message-gnksa-enable-p 'signature
)
5251 (format "Signature is excessively long (%d lines). Really post? "
5252 (count-lines sig-start sig-end
)))
5253 (message "Denied posting -- Excessive signature.")
5256 ;; Ensure that text follows last quoted portion.
5257 (message-check 'quoting-style
5258 (goto-char (point-max))
5259 (let ((no-problem t
))
5260 (when (search-backward-regexp "^>[^\n]*\n" nil t
)
5261 (setq no-problem
(search-forward-regexp "^[ \t]*[^>\n]" nil t
)))
5264 (if (message-gnksa-enable-p 'quoted-text-only
)
5265 (y-or-n-p "Your text should follow quoted text. Really post? ")
5267 (goto-char (point-min))
5269 (concat "^" (regexp-quote mail-header-separator
) "$"))
5270 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t
)
5271 (y-or-n-p "Your text should follow quoted text. Really post? ")
5272 (message "Denied posting -- only quoted text.")
5275 (defun message-checksum ()
5276 "Return a \"checksum\" for the current buffer."
5279 (goto-char (point-min))
5281 (concat "^" (regexp-quote mail-header-separator
) "$"))
5283 (when (not (looking-at "[ \t\n]"))
5284 (setq sum
(logxor (ash sum
1) (if (natnump sum
) 0 1)
5289 (defun message-do-fcc ()
5290 "Process Fcc headers in the current buffer."
5291 (let ((case-fold-search t
)
5292 (buf (current-buffer))
5294 (mml-externalize-attachments message-fcc-externalize-attachments
))
5297 (message-narrow-to-headers)
5298 (setq file
(message-fetch-field "fcc" t
)))
5300 (set-buffer (get-buffer-create " *message temp*"))
5302 (insert-buffer-substring buf
)
5303 (message-encode-message-body)
5305 (message-narrow-to-headers)
5306 (while (setq file
(message-fetch-field "fcc" t
))
5308 (message-remove-header "fcc" nil t
))
5309 (let ((mail-parse-charset message-default-charset
)
5310 (rfc2047-header-encoding-alist
5311 (cons '("Newsgroups" . default
)
5312 rfc2047-header-encoding-alist
)))
5313 (mail-encode-encoded-word-buffer)))
5314 (goto-char (point-min))
5315 (when (re-search-forward
5316 (concat "^" (regexp-quote mail-header-separator
) "$")
5318 (replace-match "" t t
))
5319 ;; Process FCC operations.
5321 (setq file
(pop list
))
5322 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file
)
5323 ;; Pipe the article to the program in question.
5324 (call-process-region (point-min) (point-max) shell-file-name
5325 nil nil nil shell-command-switch
5326 (match-string 1 file
))
5327 ;; Save the article.
5328 (setq file
(expand-file-name file
))
5329 (unless (file-exists-p (file-name-directory file
))
5330 (make-directory (file-name-directory file
) t
))
5331 (if (and message-fcc-handler-function
5332 (not (eq message-fcc-handler-function
'rmail-output
)))
5333 (funcall message-fcc-handler-function file
)
5334 ;; FIXME this option, rmail-output (also used if
5335 ;; message-fcc-handler-function is nil) is not
5336 ;; documented anywhere AFAICS. It should work in Emacs
5337 ;; 23; I suspect it does not work in Emacs 22.
5338 ;; FIXME I don't see the need for the two different cases here.
5339 ;; mail-use-rfc822 makes no difference (in Emacs 23),and
5340 ;; the third argument just controls \"Wrote file\" message.
5341 (if (and (file-readable-p file
) (mail-file-babyl-p file
))
5342 (rmail-output file
1 nil t
)
5343 (let ((mail-use-rfc822 t
))
5344 (rmail-output file
1 t t
))))))
5345 (kill-buffer (current-buffer))))))
5347 (defun message-output (filename)
5348 "Append this article to Unix/babyl mail file FILENAME."
5349 (if (and (file-readable-p filename
)
5350 (mail-file-babyl-p filename
))
5351 (gnus-output-to-rmail filename t
)
5352 (gnus-output-to-mail filename t
)))
5354 (defun message-cleanup-headers ()
5355 "Do various automatic cleanups of the headers."
5356 ;; Remove empty lines in the header.
5358 (message-narrow-to-headers)
5359 ;; Remove blank lines.
5360 (while (re-search-forward "^[ \t]*\n" nil t
)
5361 (replace-match "" t t
))
5363 ;; Correct Newsgroups and Followup-To headers: Change sequence of
5364 ;; spaces to comma and eliminate spaces around commas. Eliminate
5365 ;; embedded line breaks.
5366 (goto-char (point-min))
5367 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t
)
5371 (if (re-search-forward "^[^ \t]" nil t
)
5375 (goto-char (point-min))
5376 (while (re-search-forward "\n[ \t]+" nil t
)
5377 (replace-match " " t t
)) ;No line breaks (too confusing)
5378 (goto-char (point-min))
5379 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t
)
5380 (replace-match "," t t
))
5381 (goto-char (point-min))
5382 ;; Remove trailing commas.
5383 (when (re-search-forward ",+$" nil t
)
5384 (replace-match "" t t
))))))
5386 (defun message-make-date (&optional now
)
5387 "Make a valid data header.
5388 If NOW, use that time instead."
5389 (let ((system-time-locale "C"))
5390 (format-time-string "%a, %d %b %Y %T %z" now
)))
5392 (defun message-insert-expires (days)
5393 "Insert the Expires header. Expiry in DAYS days."
5394 (interactive "NExpire article in how many days? ")
5396 (message-position-on-field "Expires" "X-Draft-From")
5397 (insert (message-make-expires-date days
))))
5399 (defun message-make-expires-date (days)
5400 "Make date string for the Expires header. Expiry in DAYS days.
5402 In posting styles use `(\"Expires\" (make-expires-date 30))'."
5403 (let* ((cur (decode-time (current-time)))
5404 (nday (+ days
(nth 3 cur
))))
5405 (setf (nth 3 cur
) nday
)
5406 (message-make-date (apply 'encode-time cur
))))
5408 (defun message-make-message-id ()
5409 "Make a unique Message-ID."
5410 (concat "<" (message-unique-id)
5411 (let ((psubject (save-excursion (message-fetch-field "subject")))
5413 (save-excursion (message-fetch-field "supersedes"))))
5415 (and message-reply-headers
5416 (mail-header-references message-reply-headers
)
5417 (mail-header-subject message-reply-headers
)
5420 (message-strip-subject-re
5421 (mail-header-subject message-reply-headers
))
5422 (message-strip-subject-re psubject
))))
5424 (string-match "_-_@" psupersedes
)))
5426 "@" (message-make-fqdn) ">"))
5428 (defvar message-unique-id-char nil
)
5430 ;; If you ever change this function, make sure the new version
5431 ;; cannot generate IDs that the old version could.
5432 ;; You might for example insert a "." somewhere (not next to another dot
5433 ;; or string boundary), or modify the "fsf" string.
5434 (defun message-unique-id ()
5435 ;; Don't use microseconds from (current-time), they may be unsupported.
5436 ;; Instead we use this randomly inited counter.
5437 (setq message-unique-id-char
5438 (%
(1+ (or message-unique-id-char
(logand (random t
) (1- (lsh 1 20)))))
5439 ;; (current-time) returns 16-bit ints,
5440 ;; and 2^16*25 just fits into 4 digits i base 36.
5442 (let ((tm (current-time)))
5444 (if (or (eq system-type
'ms-dos
)
5445 ;; message-number-base36 doesn't handle bigints.
5446 (floatp (user-uid)))
5447 (let ((user (downcase (user-login-name))))
5448 (while (string-match "[^a-z0-9_]" user
)
5449 (aset user
(match-beginning 0) ?_
))
5451 (message-number-base36 (user-uid) -
1))
5452 (message-number-base36 (+ (car tm
)
5453 (lsh (% message-unique-id-char
25) 16)) 4)
5454 (message-number-base36 (+ (nth 1 tm
)
5455 (lsh (/ message-unique-id-char
25) 16)) 4)
5456 ;; Append a given name, because while the generated ID is unique
5457 ;; to this newsreader, other newsreaders might otherwise generate
5458 ;; the same ID via another algorithm.
5461 (defun message-number-base36 (num len
)
5466 (concat (message-number-base36 (/ num
36) (1- len
))
5467 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
5470 (defun message-make-organization ()
5471 "Make an Organization header."
5472 (let* ((organization
5473 (when message-user-organization
5474 (if (functionp message-user-organization
)
5475 (funcall message-user-organization
)
5476 message-user-organization
))))
5478 (mm-enable-multibyte)
5479 (cond ((stringp organization
)
5480 (insert organization
))
5481 ((and (eq t organization
)
5482 message-user-organization-file
5483 (file-exists-p message-user-organization-file
))
5484 (insert-file-contents message-user-organization-file
)))
5485 (goto-char (point-min))
5486 (while (re-search-forward "[\t\n]+" nil t
)
5487 (replace-match "" t t
))
5488 (unless (zerop (buffer-size))
5491 (defun message-make-lines ()
5492 "Count the number of lines and return numeric string."
5497 (int-to-string (count-lines (point) (point-max))))))
5499 (defun message-make-references ()
5500 "Return the References header for this message."
5501 (when message-reply-headers
5502 (let ((message-id (mail-header-id message-reply-headers
))
5503 (references (mail-header-references message-reply-headers
)))
5504 (if (or references message-id
)
5505 (concat (or references
"") (and references
" ")
5509 (defun message-make-in-reply-to ()
5510 "Return the In-Reply-To header for this message."
5511 (when message-reply-headers
5512 (let ((from (mail-header-from message-reply-headers
))
5513 (date (mail-header-date message-reply-headers
))
5514 (msg-id (mail-header-id message-reply-headers
)))
5516 (let ((name (mail-extract-address-components from
)))
5518 msg-id
(if msg-id
" (")
5520 (if (string-match "[^\000-\177]" (car name
))
5521 ;; Quote a string containing non-ASCII characters.
5522 ;; It will make the RFC2047 encoder cause an error
5523 ;; if there are special characters.
5524 (mm-with-multibyte-buffer
5526 (goto-char (point-min))
5527 (while (search-forward "\"" nil t
)
5530 (zerop (%
(skip-chars-backward "\\\\") 2))
5531 (goto-char (match-beginning 0)))
5534 ;; Those quotes will be removed by the RFC2047 encoder.
5535 (concat "\"" (buffer-string) "\""))
5539 (if (or (not date
) (string= date
""))
5540 "(unknown date)" date
)
5541 "\"" (if msg-id
")")))))))
5543 (defun message-make-distribution ()
5544 "Make a Distribution header."
5545 (let ((orig-distribution (message-fetch-reply-field "distribution")))
5546 (cond ((functionp message-distribution-function
)
5547 (funcall message-distribution-function
))
5548 (t orig-distribution
))))
5550 (defun message-make-expires ()
5551 "Return an Expires header based on `message-expires'."
5552 (let ((current (current-time))
5553 (future (* 1.0 message-expires
60 60 24)))
5554 ;; Add the future to current.
5555 (setcar current
(+ (car current
) (round (/ future
(expt 2 16)))))
5556 (setcar (cdr current
) (+ (nth 1 current
) (%
(round future
) (expt 2 16))))
5557 (message-make-date current
)))
5559 (defun message-make-path ()
5561 (let ((login-name (user-login-name)))
5562 (cond ((null message-user-path
)
5563 (concat (system-name) "!" login-name
))
5564 ((stringp message-user-path
)
5565 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
5566 (concat message-user-path
"!" login-name
))
5569 (defun message-make-from (&optional name address
)
5570 "Make a From header."
5571 (let* ((style message-from-style
)
5572 (login (or address
(message-make-address)))
5574 (and (boundp 'user-full-name
)
5577 (when (string= fullname
"&")
5578 (setq fullname
(user-login-name)))
5580 (mm-enable-multibyte)
5583 (equal fullname
""))
5585 ((or (eq style
'angles
)
5586 (and (not (eq style
'parens
))
5587 ;; Use angles if no quoting is needed, or if parens would
5588 ;; need quoting too.
5589 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname
))
5590 (let ((tmp (concat fullname nil
)))
5591 (while (string-match "([^()]*)" tmp
)
5592 (aset tmp
(match-beginning 0) ?-
)
5593 (aset tmp
(1- (match-end 0)) ?-
))
5594 (string-match "[\\()]" tmp
)))))
5596 (goto-char (point-min))
5597 ;; Look for a character that cannot appear unquoted
5598 ;; according to RFC 822.
5599 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil
1)
5600 ;; Quote fullname, escaping specials.
5601 (goto-char (point-min))
5603 (while (re-search-forward "[\"\\]" nil
1)
5604 (replace-match "\\\\\\&" t
))
5606 (insert " <" login
">"))
5607 (t ; 'parens or default
5609 (let ((fullname-start (point)))
5611 (goto-char fullname-start
)
5612 ;; RFC 822 says \ and nonmatching parentheses
5613 ;; must be escaped in comments.
5614 ;; Escape every instance of ()\ ...
5615 (while (re-search-forward "[()\\]" nil
1)
5616 (replace-match "\\\\\\&" t
))
5617 ;; ... then undo escaping of matching parentheses,
5618 ;; including matching nested parentheses.
5619 (goto-char fullname-start
)
5620 (while (re-search-forward
5621 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
5623 (replace-match "\\1(\\3)" t
)
5624 (goto-char fullname-start
)))
5628 (defun message-make-sender ()
5629 "Return the \"real\" user address.
5630 This function tries to ignore all user modifications, and
5631 give as trustworthy answer as possible."
5632 (concat (user-login-name) "@" (system-name)))
5634 (defun message-make-address ()
5635 "Make the address of the user."
5636 (or (message-user-mail-address)
5637 (concat (user-login-name) "@" (message-make-domain))))
5639 (defun message-user-mail-address ()
5640 "Return the pertinent part of `user-mail-address'."
5641 (when (and user-mail-address
5642 (string-match "@.*\\." user-mail-address
))
5643 (if (string-match " " user-mail-address
)
5644 (nth 1 (mail-extract-address-components user-mail-address
))
5645 user-mail-address
)))
5647 (defun message-sendmail-envelope-from ()
5648 "Return the envelope from."
5649 (cond ((eq message-sendmail-envelope-from
'header
)
5650 (nth 1 (mail-extract-address-components
5651 (message-fetch-field "from"))))
5652 ((stringp message-sendmail-envelope-from
)
5653 message-sendmail-envelope-from
)
5655 (message-make-address))))
5657 (defun message-make-fqdn ()
5658 "Return user's fully qualified domain name."
5659 (let* ((system-name (system-name))
5660 (user-mail (message-user-mail-address))
5663 (string-match "@\\(.*\\)\\'" user-mail
))
5664 (match-string 1 user-mail
)))
5665 (case-fold-search t
))
5667 ((and message-user-fqdn
5668 (stringp message-user-fqdn
)
5669 (string-match message-valid-fqdn-regexp message-user-fqdn
)
5670 (not (string-match message-bogus-system-names message-user-fqdn
)))
5671 ;; `message-user-fqdn' seems to be valid
5673 ((and (string-match message-valid-fqdn-regexp system-name
)
5674 (not (string-match message-bogus-system-names system-name
)))
5675 ;; `system-name' returned the right result.
5677 ;; Try `mail-host-address'.
5678 ((and (boundp 'mail-host-address
)
5679 (stringp mail-host-address
)
5680 (string-match message-valid-fqdn-regexp mail-host-address
)
5681 (not (string-match message-bogus-system-names mail-host-address
)))
5683 ;; We try `user-mail-address' as a backup.
5685 (stringp user-domain
)
5686 (string-match message-valid-fqdn-regexp user-domain
)
5687 (not (string-match message-bogus-system-names user-domain
)))
5689 ;; Default to this bogus thing.
5692 ".i-did-not-set--mail-host-address--so-tickle-me")))))
5694 (defun message-make-host-name ()
5695 "Return the name of the host."
5696 (let ((fqdn (message-make-fqdn)))
5697 (string-match "^[^.]+\\." fqdn
)
5698 (substring fqdn
0 (1- (match-end 0)))))
5700 (defun message-make-domain ()
5701 "Return the domain name."
5702 (or mail-host-address
5703 (message-make-fqdn)))
5705 (defun message-to-list-only ()
5706 "Send a message to the list only.
5707 Remove all addresses but the list address from To and Cc headers."
5709 (let ((listaddr (message-make-mail-followup-to t
)))
5712 (message-remove-header "to")
5713 (message-remove-header "cc")
5714 (message-position-on-field "To" "X-Draft-From")
5715 (insert listaddr
)))))
5717 (defun message-make-mail-followup-to (&optional only-show-subscribed
)
5718 "Return the Mail-Followup-To header.
5719 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5720 subscribed address (and not the additional To and Cc header contents)."
5721 (let* ((case-fold-search t
)
5722 (to (message-fetch-field "To"))
5723 (cc (message-fetch-field "cc"))
5724 (msg-recipients (concat to
(and to cc
", ") cc
))
5726 (mapcar 'mail-strip-quoted-names
5727 (message-tokenize-header msg-recipients
)))
5729 (if message-subscribed-address-file
5730 (let (begin end item re
)
5733 (insert-file-contents message-subscribed-address-file
)
5735 (setq begin
(point))
5738 (if (bolp) (setq end
(1- end
)))
5739 (setq item
(regexp-quote (buffer-substring begin end
)))
5740 (if re
(setq re
(concat re
"\\|" item
))
5741 (setq re
(concat "\\`\\(" item
))))
5742 (and re
(list (concat re
"\\)\\'"))))))))
5743 (mft-regexps (apply 'append message-subscribed-regexps
5744 (mapcar 'regexp-quote
5745 message-subscribed-addresses
)
5748 message-subscribed-address-functions
))))
5751 (loop for recipient in recipients
5752 when
(loop for regexp in mft-regexps
5753 when
(string-match regexp recipient
) return t
)
5756 (if only-show-subscribed
5758 msg-recipients
))))))
5760 (defun message-idna-to-ascii-rhs-1 (header)
5761 "Interactively potentially IDNA encode domain names in HEADER."
5762 (let ((field (message-fetch-field header
))
5766 (mm-delete-duplicates
5767 (mapcar (lambda (rhs) (or (cadr (split-string rhs
"@")) ""))
5771 (mail-extract-address-components field t
))))))
5772 ;; Note that `rhs' will be "" if the address does not have
5773 ;; the domain part, i.e., if it is a local user's address.
5774 (setq ace
(if (string-match "\\`[[:ascii:]]*\\'" rhs
)
5776 (downcase (idna-to-ascii rhs
))))
5777 (when (and (not (equal rhs ace
))
5778 (or (not (eq message-use-idna
'ask
))
5779 (y-or-n-p (format "Replace %s with %s in %s:? "
5781 (goto-char (point-min))
5782 (while (re-search-forward (concat "^" header
":") nil t
)
5783 (message-narrow-to-field)
5784 (while (search-forward (concat "@" rhs
) nil t
)
5785 (replace-match (concat "@" ace
) t t
))
5786 (goto-char (point-max))
5789 (defun message-idna-to-ascii-rhs ()
5790 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
5791 See `message-idna-encode'."
5793 (when message-use-idna
5796 ;; `message-narrow-to-head' that recognizes only the first empty
5797 ;; line as the message header separator used to be used here.
5798 ;; However, since there is the "--text follows this line--" line
5799 ;; normally, it failed in narrowing to the headers and potentially
5800 ;; caused the IDNA encoding on lines that look like headers in
5801 ;; the message body.
5802 (message-narrow-to-headers-or-head)
5803 (message-idna-to-ascii-rhs-1 "From")
5804 (message-idna-to-ascii-rhs-1 "To")
5805 (message-idna-to-ascii-rhs-1 "Reply-To")
5806 (message-idna-to-ascii-rhs-1 "Mail-Reply-To")
5807 (message-idna-to-ascii-rhs-1 "Mail-Followup-To")
5808 (message-idna-to-ascii-rhs-1 "Cc")))))
5810 (defun message-generate-headers (headers)
5811 "Prepare article HEADERS.
5812 Headers already prepared in the buffer are not modified."
5813 (setq headers
(append headers message-required-headers
))
5815 (message-narrow-to-headers)
5816 (let* ((Date (message-make-date))
5817 (Message-ID (message-make-message-id))
5818 (Organization (message-make-organization))
5819 (From (message-make-from))
5820 (Path (message-make-path))
5823 (In-Reply-To (message-make-in-reply-to))
5824 (References (message-make-references))
5826 (Distribution (message-make-distribution))
5827 (Lines (message-make-lines))
5828 (User-Agent message-newsreader
)
5829 (Expires (message-make-expires))
5830 (case-fold-search t
)
5832 header value elem header-string
)
5833 ;; First we remove any old generated headers.
5834 (let ((headers message-deletable-headers
))
5835 (unless (buffer-modified-p)
5836 (setq headers
(delq 'Message-ID
(copy-sequence headers
))))
5838 (goto-char (point-min))
5839 (and (re-search-forward
5840 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
5841 (get-text-property (1+ (match-beginning 0)) 'message-deletable
)
5842 (message-delete-line))
5844 ;; Go through all the required headers and see if they are in the
5845 ;; articles already. If they are not, or are empty, they are
5846 ;; inserted automatically - except for Subject, Newsgroups and
5849 (goto-char (point-min))
5850 (setq elem
(pop headers
))
5852 (if (eq (car elem
) 'optional
)
5853 (setq header
(cdr elem
)
5855 (setq header
(car elem
)))
5857 (setq header-string
(if (stringp header
)
5859 (symbol-name header
)))
5860 (when (or (not (re-search-forward
5862 (regexp-quote (downcase header-string
))
5866 ;; The header was found. We insert a space after the
5867 ;; colon, if there is none.
5868 (if (/= (char-after) ?
) (insert " ") (forward-char 1))
5869 ;; Find out whether the header is empty.
5870 (looking-at "[ \t]*\n[^ \t]")))
5871 ;; So we find out what value we should insert.
5875 (eq (car elem
) 'optional
)
5876 (not (member header-string message-inserted-headers
)))
5877 ;; This is an optional header. If the cdr of this
5878 ;; is something that is nil, then we do not insert
5880 (setq header
(cdr elem
))
5881 (or (and (functionp (cdr elem
))
5882 (funcall (cdr elem
)))
5883 (and (boundp (cdr elem
))
5884 (symbol-value (cdr elem
)))))
5886 ;; The element is a cons. Either the cdr is a
5887 ;; string to be inserted verbatim, or it is a
5888 ;; function, and we insert the value returned from
5890 (or (and (stringp (cdr elem
))
5892 (and (functionp (cdr elem
))
5893 (funcall (cdr elem
)))))
5894 ((and (boundp header
)
5895 (symbol-value header
))
5896 ;; The element is a symbol. We insert the value
5897 ;; of this symbol, if any.
5898 (symbol-value header
))
5899 ((not (message-check-element
5900 (intern (downcase (symbol-name header
)))))
5901 ;; We couldn't generate a value for this header,
5902 ;; so we just ask the user.
5903 (read-from-minibuffer
5904 (format "Empty header for %s; enter value: " header
)))))
5905 ;; Finally insert the header.
5907 (not (equal value
"")))
5911 ;; This header didn't exist, so we insert it.
5912 (goto-char (point-max))
5914 (cdr (assq header message-header-format-alist
))))
5916 (funcall formatter header value
)
5917 (insert header-string
": " value
))
5918 (push header-string message-inserted-headers
)
5919 (goto-char (message-fill-field))
5920 ;; We check whether the value was ended by a
5921 ;; newline. If not, we insert one.
5925 ;; The value of this header was empty, so we clear
5926 ;; totally and insert the new value.
5927 (delete-region (point) (point-at-eol))
5928 ;; If the header is optional, and the header was
5929 ;; empty, we can't insert it anyway.
5931 (push header-string message-inserted-headers
)
5933 (message-fill-field)))
5934 ;; Add the deletable property to the headers that require it.
5935 (and (memq header message-deletable-headers
)
5936 (progn (beginning-of-line) (looking-at "[^:]+: "))
5937 (add-text-properties
5938 (point) (match-end 0)
5939 '(message-deletable t face italic
) (current-buffer)))))))
5940 ;; Insert new Sender if the From is strange.
5941 (let ((from (message-fetch-field "from"))
5942 (sender (message-fetch-field "sender"))
5943 (secure-sender (message-make-sender)))
5945 (not (message-check-element 'sender
))
5948 (cadr (mail-extract-address-components from
)))
5949 (downcase secure-sender
)))
5954 (cadr (mail-extract-address-components sender
)))
5955 (downcase secure-sender
)))))
5956 (goto-char (point-min))
5957 ;; Rename any old Sender headers to Original-Sender.
5958 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t
)
5960 (insert "Original-")
5961 (beginning-of-line))
5962 (when (or (message-news-p)
5963 (string-match "@.+\\.." secure-sender
))
5964 (insert "Sender: " secure-sender
"\n"))))
5966 (message-idna-to-ascii-rhs))))
5968 (defun message-insert-courtesy-copy ()
5969 "Insert a courtesy message in mail copies of combined messages."
5973 (message-narrow-to-headers)
5974 (when (setq newsgroups
(message-fetch-field "newsgroups"))
5975 (goto-char (point-max))
5976 (insert "Posted-To: " newsgroups
"\n")))
5978 (when message-courtesy-message
5980 ((string-match "%s" message-courtesy-message
)
5981 (insert (format message-courtesy-message newsgroups
)))
5983 (insert message-courtesy-message
)))))))
5986 ;;; Setting up a message buffer
5989 (defun message-skip-to-next-address ()
5990 (let ((end (save-excursion
5991 (message-next-header)
5994 (when (looking-at ",")
5996 (while (and (not (= (point) end
))
5997 (or (not (eq char ?
,))
5999 (skip-chars-forward "^,\"" (point-max))
6000 (when (eq (setq char
(following-char)) ?
\")
6001 (setq quoted
(not quoted
)))
6002 (unless (= (point) end
)
6004 (skip-chars-forward " \t\n")))
6006 (defun message-fill-address (header value
)
6007 (insert (capitalize (symbol-name header
))
6009 (if (consp value
) (car value
) value
)
6011 (message-fill-field-address))
6013 (defun message-split-line ()
6014 "Split current line, moving portion beyond point vertically down.
6015 If the current line has `message-yank-prefix', insert it on the new line."
6018 (split-line message-yank-prefix
) ;; Emacs 22.1+ supports arg.
6022 (defun message-insert-header (header value
)
6023 (insert (capitalize (symbol-name header
))
6025 (if (consp value
) (car value
) value
)))
6027 (defun message-field-name ()
6029 (goto-char (point-min))
6030 (when (looking-at "\\([^:]+\\):")
6031 (intern (capitalize (match-string 1))))))
6033 (defun message-fill-field ()
6036 (message-narrow-to-field)
6037 (let ((field-name (message-field-name)))
6038 (funcall (or (cadr (assq field-name message-field-fillers
))
6039 'message-fill-field-general
)))
6042 (defun message-fill-field-address ()
6044 (message-skip-to-next-address)
6046 (if (and (> (current-column) 78)
6052 (setq last
(1+ (point))))
6053 (setq last
(1+ (point)))))))
6055 (defun message-fill-field-general ()
6056 (let ((begin (point))
6059 (while (and (search-forward "\n" nil t
)
6061 (replace-match " " t t
))
6062 (fill-region-as-paragraph begin
(point-max))
6063 ;; Tapdance around looong Message-IDs.
6065 (when (looking-at "[ \t]*$")
6066 (message-delete-line))
6068 (search-forward ":" nil t
)
6069 (when (looking-at "\n[ \t]+")
6070 (replace-match " " t t
))
6071 (goto-char (point-max))))
6073 (defun message-shorten-1 (list cut surplus
)
6074 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
6075 (setcdr (nthcdr (- cut
2) list
)
6076 (nthcdr (+ (- cut
2) surplus
1) list
)))
6078 (defun message-shorten-references (header references
)
6079 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
6080 When sending via news, also check that the REFERENCES are less
6081 than 988 characters long, and if they are not, trim them until
6089 (goto-char (point-min))
6090 ;; Cons a list of valid references. GNKSA says we must not include MIDs
6091 ;; with whitespace or missing brackets (7.a "Does not propagate broken
6092 ;; Message-IDs in original References").
6093 (while (re-search-forward "<[^ <]+@[^ <]+>" nil t
)
6094 (push (match-string 0) refs
))
6095 (setq refs
(nreverse refs
)
6096 count
(length refs
)))
6098 ;; If the list has more than MAXCOUNT elements, trim it by
6099 ;; removing the CUTth element and the required number of
6100 ;; elements that follow.
6101 (when (> count maxcount
)
6102 (let ((surplus (- count maxcount
)))
6103 (message-shorten-1 refs cut surplus
)
6104 (decf count surplus
)))
6106 ;; When sending via news, make sure the total folded length will
6107 ;; be less than 998 characters. This is to cater to broken INN
6108 ;; 2.3 which counts the total number of characters in a header
6109 ;; rather than the physical line length of each line, as it should.
6111 ;; This hack should be removed when it's believed than INN 2.3 is
6112 ;; no longer widely used.
6114 ;; At this point the headers have not been generated, thus we use
6115 ;; message-this-is-news directly.
6116 (when message-this-is-news
6119 (message-insert-header
6120 header
(mapconcat #'identity refs
" "))
6122 (message-shorten-1 refs cut
1)))
6123 ;; Finally, collect the references back into a string and insert
6124 ;; it into the buffer.
6125 (message-insert-header header
(mapconcat #'identity refs
" "))))
6127 (defun message-position-point ()
6128 "Move point to where the user probably wants to find it."
6129 (message-narrow-to-headers)
6131 ((re-search-forward "^[^:]+:[ \t]*$" nil t
)
6132 (search-backward ":" )
6135 (if (eq (char-after) ?
)
6139 (goto-char (point-max))
6142 (unless (looking-at "$")
6146 (defcustom message-beginning-of-line t
6147 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
6148 goes to beginning of header values."
6150 :group
'message-buffers
6151 :link
'(custom-manual "(message)Movement")
6154 (defun message-beginning-of-line (&optional n
)
6155 "Move point to beginning of header value or to beginning of line.
6156 The prefix argument N is passed directly to `beginning-of-line'.
6158 This command is identical to `beginning-of-line' if point is
6159 outside the message header or if the option `message-beginning-of-line'
6162 If point is in the message header and on a (non-continued) header
6163 line, move point to the beginning of the header value or the beginning of line,
6164 whichever is closer. If point is already at beginning of line, move point to
6165 beginning of header value. Therefore, repeated calls will toggle point
6166 between beginning of field and beginning of line."
6168 (let ((zrs 'zmacs-region-stays
))
6169 (when (and (featurep 'xemacs
) (interactive-p) (boundp zrs
))
6171 (if (and message-beginning-of-line
6172 (message-point-in-header-p))
6173 (let* ((here (point))
6174 (bol (progn (beginning-of-line n
) (point)))
6175 (eol (point-at-eol))
6176 (eoh (re-search-forward ": *" eol t
)))
6178 (if (and eoh
(or (< eoh here
) (= bol here
)))
6180 (beginning-of-line n
)))
6182 (defun message-buffer-name (type &optional to group
)
6183 "Return a new (unique) buffer name based on TYPE and TO."
6185 ;; Generate a new buffer name The Message Way.
6186 ((memq message-generate-new-buffers
'(unique t
))
6187 (generate-new-buffer-name
6191 (or (car (mail-extract-address-components to
))
6194 (if (and group
(not (string= group
""))) (concat " on " group
) "")
6196 ;; Check whether `message-generate-new-buffers' is a function,
6197 ;; and if so, call it.
6198 ((functionp message-generate-new-buffers
)
6199 (funcall message-generate-new-buffers type to group
))
6200 ((eq message-generate-new-buffers
'unsent
)
6201 (generate-new-buffer-name
6202 (concat "*unsent " type
6205 (or (car (mail-extract-address-components to
))
6208 (if (and group
(not (string= group
""))) (concat " on " group
) "")
6210 ;; Search for the existing message buffer with the specified name.
6212 (let* ((new (if (eq message-generate-new-buffers
'standard
)
6213 (generate-new-buffer-name (concat "*" type
" message*"))
6214 (let ((message-generate-new-buffers 'unique
))
6215 (message-buffer-name type to group
))))
6216 (regexp (concat "\\`"
6218 (if (string-match "<[0-9]+>\\'" new
)
6219 (substring new
0 (match-beginning 0))
6221 "\\(?:<\\([0-9]+\\)>\\)?\\'"))
6222 (case-fold-search nil
))
6229 (when (and (string-match regexp
(setq b
(buffer-name b
)))
6230 (eq (with-current-buffer b major-mode
)
6232 (cons (string-to-number (or (match-string 1 b
) "1"))
6235 'car-less-than-car
)))
6238 (defun message-pop-to-buffer (name &optional switch-function
)
6239 "Pop to buffer NAME, and warn if it already exists and is modified."
6240 (let ((buffer (get-buffer name
)))
6242 (buffer-name buffer
))
6243 (let ((window (get-buffer-window buffer
0)))
6245 ;; Raise the frame already displaying the message buffer.
6247 (gnus-select-frame-set-input-focus (window-frame window
))
6248 (select-window window
))
6249 (funcall (or switch-function
'pop-to-buffer
) buffer
)
6250 (set-buffer buffer
))
6251 (when (and (buffer-modified-p)
6254 "Message already being composed; erase? ")
6256 (error "Message being composed")))
6257 (funcall (or switch-function
'pop-to-buffer
) name
)
6262 (defun message-do-send-housekeeping ()
6263 "Kill old message buffers."
6264 ;; We might have sent this buffer already. Delete it from the
6266 (setq message-buffer-list
(delq (current-buffer) message-buffer-list
))
6267 (while (and message-max-buffers
6269 (>= (length message-buffer-list
) message-max-buffers
))
6270 ;; Kill the oldest buffer -- unless it has been changed.
6271 (let ((buffer (pop message-buffer-list
)))
6272 (when (and (buffer-name buffer
)
6273 (not (buffer-modified-p buffer
)))
6274 (kill-buffer buffer
))))
6275 ;; Rename the buffer.
6276 (if message-send-rename-function
6277 (funcall message-send-rename-function
)
6278 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
6280 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
6282 (let ((name (match-string 2 (buffer-name)))
6284 (if (not (or (null name
)
6285 (string-equal name
"mail")
6286 (string-equal name
"posting")))
6287 (setq name
(concat "*sent " name
"*"))
6288 (message-narrow-to-headers)
6289 (setq to
(message-fetch-field "to"))
6290 (setq group
(message-fetch-field "newsgroups"))
6294 (to (concat "*sent mail to "
6295 (or (car (mail-extract-address-components to
))
6297 ((and group
(not (string= group
"")))
6298 (concat "*sent posting on " group
"*"))
6299 (t "*sent mail*"))))
6300 (unless (string-equal name
(buffer-name))
6301 (rename-buffer name t
)))))
6302 ;; Push the current buffer onto the list.
6303 (when message-max-buffers
6304 (setq message-buffer-list
6305 (nconc message-buffer-list
(list (current-buffer))))))
6307 (defun message-mail-user-agent ()
6309 ((not message-mail-user-agent
) nil
)
6310 ((eq message-mail-user-agent t
) mail-user-agent
)
6311 (t message-mail-user-agent
))))
6312 (if (memq mua
'(message-user-agent gnus-user-agent
))
6316 ;; YANK-ACTION, if non-nil, can be a buffer or a yank action of the
6317 ;; form (FUNCTION . ARGS).
6318 (defun message-setup (headers &optional yank-action actions
6319 continue switch-function
)
6320 (let ((mua (message-mail-user-agent))
6322 (if (not (and message-this-is-mail mua
))
6323 (message-setup-1 headers yank-action actions
)
6324 (setq headers
(copy-sequence headers
))
6325 (setq field
(assq 'Subject headers
))
6327 (setq subject
(cdr field
))
6328 (setq headers
(delq field headers
)))
6329 (setq field
(assq 'To headers
))
6331 (setq to
(cdr field
))
6332 (setq headers
(delq field headers
)))
6333 (let ((mail-user-agent mua
))
6334 (compose-mail to subject
6335 (mapcar (lambda (item)
6337 (format "%s" (car item
))
6340 continue switch-function
6341 (if (bufferp yank-action
)
6342 (list 'insert-buffer yank-action
)
6346 (defun message-headers-to-generate (headers included-headers excluded-headers
)
6347 "Return a list that includes all headers from HEADERS.
6348 If INCLUDED-HEADERS is a list, just include those headers. If it is
6349 t, include all headers. In any case, headers from EXCLUDED-HEADERS
6353 (dolist (header headers
)
6354 (setq header-name
(cond
6355 ((and (consp header
)
6356 (eq (car header
) 'optional
))
6357 ;; On the form (optional . Header)
6360 ;; On the form (Header . function)
6365 (when (and (not (memq header-name excluded-headers
))
6366 (or (eq included-headers t
)
6367 (memq header-name included-headers
)))
6368 (push header result
)))
6371 (defun message-setup-1 (headers &optional yank-action actions
)
6372 (dolist (action actions
)
6374 (add-to-list 'message-send-actions
6375 `(apply ',(car action
) ',(cdr action
)))))
6376 (setq message-reply-buffer
6377 (if (and (consp yank-action
)
6378 (eq (car yank-action
) 'insert-buffer
))
6381 (goto-char (point-min))
6382 ;; Insert all the headers.
6385 (alist message-header-format-alist
))
6387 (unless (assq (caar h
) message-header-format-alist
)
6388 (push (list (caar h
)) alist
))
6392 (delete-region (point) (progn (forward-line -
1) (point)))
6393 (when message-default-headers
6394 (insert message-default-headers
)
6395 (or (bolp) (insert ?
\n)))
6396 (insert mail-header-separator
"\n")
6398 (when (message-news-p)
6399 (when message-default-news-headers
6400 (insert message-default-news-headers
)
6401 (or (bolp) (insert ?
\n)))
6402 (when message-generate-headers-first
6403 (message-generate-headers
6404 (message-headers-to-generate
6405 (append message-required-news-headers
6406 message-required-headers
)
6407 message-generate-headers-first
6408 '(Lines Subject
)))))
6409 (when (message-mail-p)
6410 (when message-default-mail-headers
6411 (insert message-default-mail-headers
)
6412 (or (bolp) (insert ?
\n)))
6413 (when message-generate-headers-first
6414 (message-generate-headers
6415 (message-headers-to-generate
6416 (append message-required-mail-headers
6417 message-required-headers
)
6418 message-generate-headers-first
6419 '(Lines Subject
)))))
6420 (run-hooks 'message-signature-setup-hook
)
6421 (message-insert-signature)
6423 (message-narrow-to-headers)
6424 (run-hooks 'message-header-setup-hook
))
6425 (setq buffer-undo-list nil
)
6426 (when message-generate-hashcash
6427 ;; Generate hashcash headers for recipients already known
6428 (mail-add-payment-async))
6429 ;; Gnus posting styles are applied via buffer-local `message-setup-hook'
6431 (run-hooks 'message-setup-hook
)
6432 ;; Do this last to give it precedence over posting styles, etc.
6433 (when (message-mail-p)
6435 (message-narrow-to-headers)
6436 (if message-alternative-emails
6437 (message-use-alternative-email-as-from))))
6438 (message-position-point)
6439 ;; Allow correct handling of `message-checksum' in `message-yank-original':
6440 (set-buffer-modified-p nil
)
6443 (defun message-set-auto-save-file-name ()
6444 "Associate the message buffer with a file in the drafts directory."
6445 (when message-auto-save-directory
6446 (unless (file-directory-p
6447 (directory-file-name message-auto-save-directory
))
6448 (make-directory message-auto-save-directory t
))
6450 (setq message-draft-article
6451 (nndraft-request-associate-buffer "drafts"))
6453 ;; If Gnus were alive, draft messages would be saved in the drafts folder.
6454 ;; But Gnus is not alive, so arrange to save the draft message in a
6455 ;; regular file in message-auto-save-directory. Append a unique
6456 ;; time-based suffix to the filename to allow multiple drafts to be saved
6457 ;; simultaneously without overwriting each other (which mimics the
6458 ;; functionality of the Gnus drafts folder).
6459 (setq buffer-file-name
(expand-file-name
6461 (if (memq system-type
6462 '(ms-dos windows-nt cygwin
))
6465 (format-time-string "-%Y%m%d-%H%M%S"))
6466 message-auto-save-directory
))
6467 (setq buffer-auto-save-file-name
(make-auto-save-file-name)))
6468 (clear-visited-file-modtime)
6469 (setq buffer-file-coding-system message-draft-coding-system
)))
6471 (defun message-disassociate-draft ()
6472 "Disassociate the message buffer from the drafts directory."
6473 (when message-draft-article
6474 (nndraft-request-expire-articles
6475 (list message-draft-article
) "drafts" nil t
)))
6477 (defun message-insert-headers ()
6478 "Generate the headers for the article."
6482 (message-narrow-to-headers)
6483 (when (message-news-p)
6484 (message-generate-headers
6487 (copy-sequence message-required-news-headers
)))))
6488 (when (message-mail-p)
6489 (message-generate-headers
6492 (copy-sequence message-required-mail-headers
))))))))
6497 ;;; Commands for interfacing with message
6501 (defun message-mail (&optional to subject
6502 other-headers continue switch-function
6503 yank-action send-actions
)
6504 "Start editing a mail message to be sent.
6505 OTHER-HEADERS is an alist of header/value pairs. CONTINUE says whether
6506 to continue editing a message already being composed. SWITCH-FUNCTION
6507 is a function used to switch to and display the mail buffer."
6509 (let ((message-this-is-mail t
))
6510 (unless (message-mail-user-agent)
6511 (message-pop-to-buffer
6512 ;; Search for the existing message buffer if `continue' is non-nil.
6513 (let ((message-generate-new-buffers
6514 (when (or (not continue
)
6515 (eq message-generate-new-buffers
'standard
)
6516 (functionp message-generate-new-buffers
))
6517 message-generate-new-buffers
)))
6518 (message-buffer-name "mail" to
))
6522 `((To .
,(or to
"")) (Subject .
,(or subject
"")))
6523 (when other-headers other-headers
))
6524 yank-action send-actions continue switch-function
)
6525 ;; FIXME: Should return nil if failure.
6529 (defun message-news (&optional newsgroups subject
)
6530 "Start editing a news article to be sent."
6532 (let ((message-this-is-news t
))
6533 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
))
6534 (message-setup `((Newsgroups .
,(or newsgroups
""))
6535 (Subject .
,(or subject
""))))))
6537 (defun message-alter-recipients-discard-bogus-full-name (addrcell)
6538 "Discard mail address in full names.
6539 When the full name in reply headers contains the mail
6540 address (e.g. \"foo@bar <foo@bar>\"), discard full name.
6541 ADDRCELL is a cons cell where the car is the mail address and the
6542 cdr is the complete address (full name and mail address)."
6543 (if (string-match (concat (regexp-quote (car addrcell
)) ".*"
6544 (regexp-quote (car addrcell
)))
6546 (cons (car addrcell
) (car addrcell
))
6549 (defcustom message-alter-recipients-function nil
6550 "Function called to allow alteration of reply header structures.
6551 It is called in `message-get-reply-headers' for each recipient.
6552 The function is called with one parameter, a cons cell ..."
6553 :type
'(choice (const :tag
"None" nil
)
6554 (const :tag
"Discard bogus full name"
6555 message-alter-recipients-discard-bogus-full-name
)
6557 :version
"23.1" ;; No Gnus
6558 :group
'message-headers
)
6560 (defun message-get-reply-headers (wide &optional to-address address-headers
)
6561 (let (follow-to mct never-mct to cc author mft recipients extra
)
6562 ;; Find all relevant headers we need.
6564 (message-narrow-to-headers-or-head)
6565 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
6566 ;; message-header-synonyms.
6567 (setq to
(or (message-fetch-field "to")
6568 (and (loop for synonym in message-header-synonyms
6569 when
(memq 'Original-To synonym
)
6571 (message-fetch-field "original-to")))
6572 cc
(message-fetch-field "cc")
6573 extra
(when message-extra-wide-headers
6574 (mapconcat 'identity
6575 (mapcar 'message-fetch-field
6576 message-extra-wide-headers
)
6578 mct
(message-fetch-field "mail-copies-to")
6579 author
(or (message-fetch-field "mail-reply-to")
6580 (message-fetch-field "reply-to")
6581 (message-fetch-field "from")
6583 mft
(and message-use-mail-followup-to
6584 (message-fetch-field "mail-followup-to"))))
6586 ;; Handle special values of Mail-Copies-To.
6588 (cond ((or (equal (downcase mct
) "never")
6589 (equal (downcase mct
) "nobody"))
6592 ((or (equal (downcase mct
) "always")
6593 (equal (downcase mct
) "poster"))
6594 (setq mct author
))))
6597 ;; Build (textual) list of new recipient addresses.
6600 (setq recipients
(concat ", " author
)))
6602 (dolist (header address-headers
)
6603 (let ((value (message-fetch-field header
)))
6605 (setq recipients
(concat recipients
", " value
))))))
6607 (string-match "[^ \t,]" mft
)
6608 (or (not (eq message-use-mail-followup-to
'ask
))
6609 (message-y-or-n-p "Obey Mail-Followup-To? " t
"\
6610 You should normally obey the Mail-Followup-To: header. In this
6611 article, it has the value of
6615 which directs your response to " (if (string-match "," mft
)
6616 "the specified addresses"
6617 "that address only") ".
6619 Most commonly, Mail-Followup-To is used by a mailing list poster to
6620 express that responses should be sent to just the list, and not the
6623 If a message is posted to several mailing lists, Mail-Followup-To may
6624 also be used to direct the following discussion to one list only,
6625 because discussions that are spread over several lists tend to be
6626 fragmented and very difficult to follow.
6628 Also, some source/announcement lists are not intended for discussion;
6629 responses here are directed to other addresses.
6631 You may customize the variable `message-use-mail-followup-to', if you
6632 want to get rid of this query permanently.")))
6633 (setq recipients
(concat ", " mft
)))
6635 (setq recipients
(concat ", " to-address
))
6636 ;; If the author explicitly asked for a copy, we don't deny it to them.
6637 (if mct
(setq recipients
(concat recipients
", " mct
))))
6639 (setq recipients
(if never-mct
"" (concat ", " author
)))
6640 (if to
(setq recipients
(concat recipients
", " to
)))
6641 (if cc
(setq recipients
(concat recipients
", " cc
)))
6642 (if extra
(setq recipients
(concat recipients
", " extra
)))
6643 (if mct
(setq recipients
(concat recipients
", " mct
)))))
6644 (if (>= (length recipients
) 2)
6645 ;; Strip the leading ", ".
6646 (setq recipients
(substring recipients
2)))
6647 ;; Squeeze whitespace.
6648 (while (string-match "[ \t][ \t]+" recipients
)
6649 (setq recipients
(replace-match " " t t recipients
)))
6650 ;; Remove addresses that match `rmail-dont-reply-to-names'.
6651 (let ((rmail-dont-reply-to-names (message-dont-reply-to-names)))
6652 (setq recipients
(rmail-dont-reply-to recipients
)))
6653 ;; Perhaps "Mail-Copies-To: never" removed the only address?
6654 (if (string-equal recipients
"")
6655 (setq recipients author
))
6656 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
6660 (if message-alter-recipients-function
6661 (funcall message-alter-recipients-function
6662 (cons (downcase (mail-strip-quoted-names addr
))
6664 (cons (downcase (mail-strip-quoted-names addr
)) addr
)))
6665 (message-tokenize-header recipients
)))
6666 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
6667 (let ((s recipients
))
6669 (setq recipients
(delq (assoc (car (pop s
)) s
) recipients
))))
6671 ;; Remove hierarchical lists that are contained within each other,
6672 ;; if message-hierarchical-addresses is defined.
6673 (when message-hierarchical-addresses
6674 (let ((plain-addrs (mapcar 'car recipients
))
6677 (setq subaddrs
(assoc (car plain-addrs
)
6678 message-hierarchical-addresses
)
6679 plain-addrs
(cdr plain-addrs
))
6681 (setq subaddrs
(cdr subaddrs
))
6683 (setq recip
(assoc (car subaddrs
) recipients
)
6684 subaddrs
(cdr subaddrs
))
6686 (setq recipients
(delq recip recipients
))))))))
6688 (setq recipients
(message-prune-recipients recipients
))
6690 ;; Build the header alist. Allow the user to be asked whether
6691 ;; or not to reply to all recipients in a wide reply.
6692 (setq follow-to
(list (cons 'To
(cdr (pop recipients
)))))
6693 (when (and recipients
6694 (or (not message-wide-reply-confirm-recipients
)
6695 (y-or-n-p "Reply to all recipients? ")))
6696 (setq recipients
(mapconcat
6697 (lambda (addr) (cdr addr
)) recipients
", "))
6698 (if (string-match "^ +" recipients
)
6699 (setq recipients
(substring recipients
(match-end 0))))
6700 (push (cons 'Cc recipients
) follow-to
)))
6703 (defun message-prune-recipients (recipients)
6704 (dolist (rule message-prune-recipient-rules
)
6705 (let ((match (car rule
))
6708 (dolist (recipient recipients
)
6709 (setq address
(car recipient
))
6710 (when (string-match match address
)
6711 (setq dup-match
(replace-match (cadr rule
) nil nil address
))
6712 (dolist (recipient recipients
)
6713 ;; Don't delete the address that triggered this.
6714 (when (and (not (eq address
(car recipient
)))
6715 (string-match dup-match
(car recipient
)))
6716 (setq recipients
(delq recipient recipients
))))))))
6719 (defcustom message-simplify-subject-functions
6720 '(message-strip-list-identifiers
6721 message-strip-subject-re
6722 message-strip-subject-trailing-was
6723 message-strip-subject-encoded-words
)
6724 "List of functions taking a string argument that simplify subjects.
6725 The functions are applied when replying to a message.
6727 Useful functions to put in this list include:
6728 `message-strip-list-identifiers', `message-strip-subject-re',
6729 `message-strip-subject-trailing-was', and
6730 `message-strip-subject-encoded-words'."
6731 :version
"22.1" ;; Gnus 5.10.9
6732 :group
'message-various
6733 :type
'(repeat function
))
6735 (defun message-simplify-subject (subject &optional functions
)
6736 "Return simplified SUBJECT."
6739 (setq functions message-simplify-subject-functions
))
6740 (when (and (memq 'message-strip-list-identifiers functions
)
6741 gnus-list-identifiers
)
6742 (setq subject
(message-strip-list-identifiers subject
)))
6743 (when (memq 'message-strip-subject-re functions
)
6744 (setq subject
(concat "Re: " (message-strip-subject-re subject
))))
6745 (when (and (memq 'message-strip-subject-trailing-was functions
)
6746 message-subject-trailing-was-query
)
6747 (setq subject
(message-strip-subject-trailing-was subject
)))
6748 (when (memq 'message-strip-subject-encoded-words functions
)
6749 (setq subject
(message-strip-subject-encoded-words subject
)))
6753 (defun message-reply (&optional to-address wide
)
6754 "Start editing a reply to the article in the current buffer."
6756 (require 'gnus-sum
) ; for gnus-list-identifiers
6757 (let ((cur (current-buffer))
6758 from subject date reply-to to cc
6759 references message-id follow-to
6760 (inhibit-point-motion-hooks t
)
6761 (message-this-is-mail t
)
6764 (message-narrow-to-head-1)
6765 ;; Allow customizations to have their say.
6767 ;; This is a regular reply.
6768 (when (functionp message-reply-to-function
)
6770 (setq follow-to
(funcall message-reply-to-function
))))
6771 ;; This is a followup.
6772 (when (functionp message-wide-reply-to-function
)
6775 (funcall message-wide-reply-to-function
)))))
6776 (setq message-id
(message-fetch-field "message-id" t
)
6777 references
(message-fetch-field "references")
6778 date
(message-fetch-field "date")
6779 from
(or (message-fetch-field "from") "nobody")
6780 subject
(or (message-fetch-field "subject") "none"))
6782 ;; Strip list identifiers, "Re: ", and "was:"
6783 (setq subject
(message-simplify-subject subject
))
6785 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
6786 (string-match "<[^>]+>" gnus-warning
))
6787 (setq message-id
(match-string 0 gnus-warning
)))
6790 (setq follow-to
(message-get-reply-headers wide to-address
))))
6792 (unless (message-mail-user-agent)
6793 (message-pop-to-buffer
6794 (message-buffer-name
6795 (if wide
"wide reply" "reply") from
6796 (if wide to-address nil
))))
6798 (setq message-reply-headers
6799 (vector 0 subject from date message-id references
0 0 ""))
6802 `((Subject .
,subject
)
6807 (defun message-wide-reply (&optional to-address
)
6808 "Make a \"wide\" reply to the message in the current buffer."
6810 (message-reply to-address t
))
6813 (defun message-followup (&optional to-newsgroups
)
6814 "Follow up to the message in the current buffer.
6815 If TO-NEWSGROUPS, use that as the new Newsgroups line."
6817 (require 'gnus-sum
) ; for gnus-list-identifiers
6818 (let ((cur (current-buffer))
6819 from subject date reply-to mrt mct
6820 references message-id follow-to
6821 (inhibit-point-motion-hooks t
)
6822 (message-this-is-news t
)
6823 followup-to distribution newsgroups gnus-warning posted-to
)
6826 (goto-char (point-min))
6827 (if (search-forward "\n\n" nil t
)
6830 (when (functionp message-followup-to-function
)
6832 (funcall message-followup-to-function
)))
6833 (setq from
(message-fetch-field "from")
6834 date
(message-fetch-field "date")
6835 subject
(or (message-fetch-field "subject") "none")
6836 references
(message-fetch-field "references")
6837 message-id
(message-fetch-field "message-id" t
)
6838 followup-to
(message-fetch-field "followup-to")
6839 newsgroups
(message-fetch-field "newsgroups")
6840 posted-to
(message-fetch-field "posted-to")
6841 reply-to
(message-fetch-field "reply-to")
6842 mrt
(message-fetch-field "mail-reply-to")
6843 distribution
(message-fetch-field "distribution")
6844 mct
(message-fetch-field "mail-copies-to"))
6845 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
6846 (string-match "<[^>]+>" gnus-warning
))
6847 (setq message-id
(match-string 0 gnus-warning
)))
6848 ;; Remove bogus distribution.
6849 (when (and (stringp distribution
)
6850 (let ((case-fold-search t
))
6851 (string-match "world" distribution
)))
6852 (setq distribution nil
))
6853 ;; Strip list identifiers, "Re: ", and "was:"
6854 (setq subject
(message-simplify-subject subject
))
6857 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups
))
6859 (setq message-reply-headers
6860 (vector 0 subject from date message-id references
0 0 ""))
6863 `((Subject .
,subject
)
6866 (list (cons 'Newsgroups to-newsgroups
)))
6867 (follow-to follow-to
)
6868 ((and followup-to message-use-followup-to
)
6871 ((equal (downcase followup-to
) "poster")
6872 (if (or (eq message-use-followup-to
'use
)
6873 (message-y-or-n-p "Obey Followup-To: poster? " t
"\
6874 You should normally obey the Followup-To: header.
6876 `Followup-To: poster' sends your response via e-mail instead of news.
6878 A typical situation where `Followup-To: poster' is used is when the poster
6879 does not read the newsgroup, so he wouldn't see any replies sent to it.
6881 You may customize the variable `message-use-followup-to', if you
6882 want to get rid of this query permanently."))
6884 (setq message-this-is-news nil
)
6885 (cons 'To
(or mrt reply-to from
"")))
6886 (cons 'Newsgroups newsgroups
)))
6888 (if (or (equal followup-to newsgroups
)
6889 (not (eq message-use-followup-to
'ask
))
6891 (concat "Obey Followup-To: " followup-to
"? ") t
"\
6892 You should normally obey the Followup-To: header.
6894 `Followup-To: " followup-to
"'
6895 directs your response to " (if (string-match "," followup-to
)
6896 "the specified newsgroups"
6897 "that newsgroup only") ".
6899 If a message is posted to several newsgroups, Followup-To is often
6900 used to direct the following discussion to one newsgroup only,
6901 because discussions that are spread over several newsgroup tend to
6902 be fragmented and very difficult to follow.
6904 Also, some source/announcement newsgroups are not intended for discussion;
6905 responses here are directed to other newsgroups.
6907 You may customize the variable `message-use-followup-to', if you
6908 want to get rid of this query permanently."))
6909 (cons 'Newsgroups followup-to
)
6910 (cons 'Newsgroups newsgroups
))))))
6912 `((Newsgroups .
,posted-to
)))
6914 `((Newsgroups .
,newsgroups
))))
6915 ,@(and distribution
(list (cons 'Distribution distribution
)))
6917 (not (or (equal (downcase mct
) "never")
6918 (equal (downcase mct
) "nobody"))))
6919 (list (cons 'Cc
(if (or (equal (downcase mct
) "always")
6920 (equal (downcase mct
) "poster"))
6921 (or mrt reply-to from
"")
6926 (defun message-is-yours-p ()
6927 "Non-nil means current article is yours.
6928 If you have added 'cancel-messages to `message-shoot-gnksa-feet', all articles
6929 are yours except those that have Cancel-Lock header not belonging to you.
6930 Instead of shooting GNKSA feet, you should modify `message-alternative-emails'
6931 regexp to match all of yours addresses."
6932 ;; Canlock-logic as suggested by Per Abrahamsen
6933 ;; <abraham@dina.kvl.dk>
6935 ;; IF article has cancel-lock THEN
6936 ;; IF we can verify it THEN
6939 ;; error: cancellock: article is not yours
6941 ;; Use old rules, comparing sender...
6944 (message-narrow-to-head-1)
6945 (if (message-fetch-field "Cancel-Lock")
6946 (if (null (canlock-verify))
6948 (error "Failed to verify Cancel-lock: This article is not yours"))
6951 (message-gnksa-enable-p 'cancel-messages
)
6952 (and (setq sender
(message-fetch-field "sender"))
6953 (string-equal (downcase sender
)
6954 (downcase (message-make-sender))))
6955 ;; Email address in From field equals to our address
6956 (and (setq from
(message-fetch-field "from"))
6958 (downcase (car (mail-header-parse-address from
)))
6959 (downcase (car (mail-header-parse-address
6960 (message-make-from))))))
6961 ;; Email address in From field matches
6962 ;; 'message-alternative-emails' regexp
6964 message-alternative-emails
6966 message-alternative-emails
6967 (car (mail-header-parse-address from
))))))))))
6970 (defun message-cancel-news (&optional arg
)
6971 "Cancel an article you posted.
6972 If ARG, allow editing of the cancellation message."
6974 (unless (message-news-p)
6975 (error "This is not a news article; canceling is impossible"))
6976 (let (from newsgroups message-id distribution buf
)
6978 ;; Get header info from original article.
6980 (message-narrow-to-head-1)
6981 (setq from
(message-fetch-field "from")
6982 newsgroups
(message-fetch-field "newsgroups")
6983 message-id
(message-fetch-field "message-id" t
)
6984 distribution
(message-fetch-field "distribution")))
6985 ;; Make sure that this article was written by the user.
6986 (unless (message-is-yours-p)
6987 (error "This article is not yours"))
6988 (when (yes-or-no-p "Do you really want to cancel this article? ")
6989 ;; Make control message.
6992 (setq buf
(set-buffer (get-buffer-create " *message cancel*"))))
6994 (insert "Newsgroups: " newsgroups
"\n"
6996 "Subject: cmsg cancel " message-id
"\n"
6997 "Control: cancel " message-id
"\n"
6999 (concat "Distribution: " distribution
"\n")
7001 mail-header-separator
"\n"
7002 message-cancel-message
)
7003 (run-hooks 'message-cancel-hook
)
7005 (message "Canceling your article...")
7006 (if (let ((message-syntax-checks
7007 'dont-check-for-anything-just-trust-me
))
7008 (funcall message-send-news-function
))
7009 (message "Canceling your article...done"))
7010 (kill-buffer buf
))))))
7013 (defun message-supersede ()
7014 "Start composing a message to supersede the current message.
7015 This is done simply by taking the old article and adding a Supersedes
7016 header line with the old Message-ID."
7018 (let ((cur (current-buffer)))
7019 ;; Check whether the user owns the article that is to be superseded.
7020 (unless (message-is-yours-p)
7021 (error "This article is not yours"))
7022 ;; Get a normal message buffer.
7023 (message-pop-to-buffer (message-buffer-name "supersede"))
7024 (insert-buffer-substring cur
)
7026 (message-narrow-to-head-1)
7027 ;; Remove unwanted headers.
7028 (when message-ignored-supersedes-headers
7029 (message-remove-header message-ignored-supersedes-headers t
))
7030 (goto-char (point-min))
7031 (if (not (re-search-forward "^Message-ID: " nil t
))
7032 (error "No Message-ID in this article")
7033 (replace-match "Supersedes: " t t
))
7034 (goto-char (point-max))
7035 (insert mail-header-separator
)
7040 (defun message-recover ()
7041 "Reread contents of current buffer from its last auto-save file."
7043 (let ((file-name (make-auto-save-file-name)))
7044 (cond ((save-window-excursion
7045 (with-output-to-temp-buffer "*Directory*"
7046 (with-current-buffer standard-output
7047 (fundamental-mode)) ; for Emacs 20.4+
7048 (buffer-disable-undo standard-output
)
7049 (let ((default-directory "/"))
7051 "ls" nil standard-output nil
"-l" file-name
)))
7052 (yes-or-no-p (format "Recover auto save file %s? " file-name
)))
7053 (let ((buffer-read-only nil
))
7055 (insert-file-contents file-name nil
)))
7056 (t (error "message-recover cancelled")))))
7058 ;;; Washing Subject:
7060 (defun message-wash-subject (subject)
7061 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
7062 Previous forwarders, replyers, etc. may add it."
7065 (goto-char (point-min))
7066 ;; strip Re/Fwd stuff off the beginning
7067 (while (re-search-forward
7068 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t
)
7071 ;; and gnus-style forwards [foo@bar.com] subject
7072 (goto-char (point-min))
7073 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t
)
7077 (goto-char (point-max))
7078 (while (re-search-backward "([Ff][Ww][Dd])" nil t
)
7081 ;; and finally, any whitespace that was left-over
7082 (goto-char (point-min))
7083 (while (re-search-forward "^[ \t]+" nil t
)
7085 (goto-char (point-max))
7086 (while (re-search-backward "[ \t]+$" nil t
)
7091 ;;; Forwarding messages.
7093 (defvar message-forward-decoded-p nil
7094 "Non-nil means the original message is decoded.")
7096 (defun message-forward-subject-name-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 name of the sender, and if the original message was
7100 news, Source is the list of newsgroups is was posted to."
7101 (let* ((group (message-fetch-field "newsgroups"))
7102 (from (message-fetch-field "from"))
7105 (gnus-group-decoded-name group
)
7107 (car (gnus-extract-address-components from
))
7108 (cadr (gnus-extract-address-components from
))))
7111 (if message-forward-decoded-p
7113 (mail-decode-encoded-word-string prefix
))
7116 (defun message-forward-subject-author-subject (subject)
7117 "Generate a SUBJECT for a forwarded message.
7118 The form is: [Source] Subject, where if the original message was mail,
7119 Source is the sender, and if the original message was news, Source is
7120 the list of newsgroups is was posted to."
7121 (let* ((group (message-fetch-field "newsgroups"))
7124 (gnus-group-decoded-name group
)
7125 (or (message-fetch-field "from")
7128 (if message-forward-decoded-p
7130 (mail-decode-encoded-word-string prefix
))
7133 (defun message-forward-subject-fwd (subject)
7134 "Generate a SUBJECT for a forwarded message.
7135 The form is: Fwd: Subject, where Subject is the original subject of
7137 (if (string-match "^Fwd: " subject
)
7139 (concat "Fwd: " subject
)))
7141 (defun message-make-forward-subject ()
7142 "Return a Subject header suitable for the message in the current buffer."
7145 (message-narrow-to-head-1)
7146 (let ((funcs message-make-forward-subject-function
)
7147 (subject (message-fetch-field "Subject")))
7150 (if message-forward-decoded-p
7152 (mail-decode-encoded-word-string subject
))
7154 (when message-wash-forwarded-subjects
7155 (setq subject
(message-wash-subject subject
)))
7156 ;; Make sure funcs is a list.
7159 (setq funcs
(list funcs
)))
7160 ;; Apply funcs in order, passing subject generated by previous
7161 ;; func to the next one.
7162 (dolist (func funcs
)
7163 (when (functionp func
)
7164 (setq subject
(funcall func subject
))))
7167 (defvar gnus-article-decoded-p
)
7171 (defun message-forward (&optional news digest
)
7172 "Forward the current message via mail.
7173 Optional NEWS will use news to forward instead of mail.
7174 Optional DIGEST will use digest to forward."
7176 (let* ((cur (current-buffer))
7177 (message-forward-decoded-p
7178 (if (local-variable-p 'gnus-article-decoded-p
(current-buffer))
7179 gnus-article-decoded-p
;; In an article buffer.
7180 message-forward-decoded-p
))
7181 (subject (message-make-forward-subject)))
7183 (message-news nil subject
)
7184 (message-mail nil subject
))
7185 (message-forward-make-body cur digest
)))
7187 (defun message-forward-make-body-plain (forward-buffer)
7189 "\n-------------------- Start of forwarded message --------------------\n")
7191 (contents (with-current-buffer forward-buffer
(buffer-string)))
7193 (unless (featurep 'xemacs
)
7194 (unless (mm-multibyte-string-p contents
)
7195 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7196 to the multibyte buffer \"%s\""
7197 (if (bufferp forward-buffer
)
7198 (buffer-name forward-buffer
)
7201 (insert (mm-with-multibyte-buffer
7204 (goto-char (point-min))
7205 (when (looking-at "From ")
7206 (replace-match "X-From-Line: "))
7208 (unless (bolp) (insert "\n"))
7211 "-------------------- End of forwarded message --------------------\n")
7212 (message-remove-ignored-headers b e
)))
7214 (defun message-remove-ignored-headers (b e
)
7215 (when message-forward-ignored-headers
7217 (narrow-to-region b e
)
7219 (narrow-to-region (point)
7220 (or (search-forward "\n\n" nil t
) (point)))
7221 (let ((ignored (if (stringp message-forward-ignored-headers
)
7222 (list message-forward-ignored-headers
)
7223 message-forward-ignored-headers
)))
7224 (dolist (elem ignored
)
7225 (message-remove-header elem t
))))))
7227 (defun message-forward-make-body-mime (forward-buffer)
7229 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
7231 (narrow-to-region (point) (point))
7232 (mml-insert-buffer forward-buffer
)
7233 (goto-char (point-min))
7234 (when (looking-at "From ")
7235 (replace-match "X-From-Line: "))
7236 (goto-char (point-max)))
7237 (insert "<#/part>\n")
7238 ;; Consider there is no illegible text.
7239 (add-text-properties
7241 `(no-illegible-text t rear-nonsticky t start-open t
))))
7243 (defun message-forward-make-body-mml (forward-buffer)
7244 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
7245 (let ((b (point)) e
)
7246 (if (not message-forward-decoded-p
)
7247 (let ((contents (with-current-buffer forward-buffer
(buffer-string))))
7248 (unless (featurep 'xemacs
)
7249 (unless (mm-multibyte-string-p contents
)
7250 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7251 to the multibyte buffer \"%s\""
7252 (if (bufferp forward-buffer
)
7253 (buffer-name forward-buffer
)
7256 (insert (mm-with-multibyte-buffer
7259 (goto-char (point-min))
7260 (when (looking-at "From ")
7261 (replace-match "X-From-Line: "))
7264 (narrow-to-region (point) (point))
7265 (mml-insert-buffer forward-buffer
)
7266 (goto-char (point-min))
7267 (when (looking-at "From ")
7268 (replace-match "X-From-Line: "))
7269 (goto-char (point-max))))
7271 (insert "<#/mml>\n")
7272 (when (and (not message-forward-decoded-p
)
7273 message-forward-ignored-headers
)
7274 (message-remove-ignored-headers b e
))))
7276 (defun message-forward-make-body-digest-plain (forward-buffer)
7278 "\n-------------------- Start of forwarded message --------------------\n")
7279 (let ((b (point)) e
)
7280 (mml-insert-buffer forward-buffer
)
7283 "\n-------------------- End of forwarded message --------------------\n")))
7285 (defun message-forward-make-body-digest-mime (forward-buffer)
7286 (insert "\n<#multipart type=digest>\n")
7287 (let ((b (point)) e
)
7288 (insert-buffer-substring forward-buffer
)
7290 (insert "<#/multipart>\n")
7292 (narrow-to-region b e
)
7294 (narrow-to-region (point)
7295 (or (search-forward "\n\n" nil t
) (point)))
7296 (delete-region (point-min) (point-max)))))
7298 (defun message-forward-make-body-digest (forward-buffer)
7299 (if message-forward-as-mime
7300 (message-forward-make-body-digest-mime forward-buffer
)
7301 (message-forward-make-body-digest-plain forward-buffer
)))
7303 (autoload 'mm-uu-dissect-text-parts
"mm-uu")
7304 (autoload 'mm-uu-dissect
"mm-uu")
7306 (defun message-signed-or-encrypted-p (&optional dont-emulate-mime handles
)
7307 "Say whether the current buffer contains signed or encrypted message.
7308 If DONT-EMULATE-MIME is nil, this function does the MIME emulation on
7309 messages that don't conform to PGP/MIME described in RFC2015. HANDLES
7310 is for the internal use."
7312 (let ((mm-decrypt-option 'never
)
7313 (mm-verify-option 'never
))
7314 (if (setq handles
(mm-dissect-buffer nil t
))
7315 (unless dont-emulate-mime
7316 (mm-uu-dissect-text-parts handles
))
7317 (unless dont-emulate-mime
7318 (setq handles
(mm-uu-dissect))))))
7319 ;; Check text/plain message in which there is a signed or encrypted
7320 ;; body that has been encoded by B or Q.
7321 (unless (or handles dont-emulate-mime
)
7322 (let ((cur (current-buffer))
7323 (mm-decrypt-option 'never
)
7324 (mm-verify-option 'never
))
7326 (insert-buffer-substring cur
)
7327 (when (setq handles
(mm-dissect-buffer t t
))
7329 (bufferp (car handles
))
7330 (mm-destroy-parts handles
))
7331 (equal (mm-handle-media-type handles
) "text/plain"))
7333 (mm-decode-content-transfer-encoding
7334 (mm-handle-encoding handles
))
7335 (setq handles
(mm-uu-dissect)))
7336 (setq handles nil
))))))
7340 (dolist (handle (if (stringp (car handles
))
7341 (if (member (car handles
)
7342 '("multipart/signed"
7343 "multipart/encrypted"))
7347 (if (stringp (car handle
))
7348 (when (message-signed-or-encrypted-p dont-emulate-mime handle
)
7350 (when (and (bufferp (car handle
))
7351 (equal (mm-handle-media-type handle
)
7353 (with-current-buffer (mm-handle-buffer handle
)
7354 (when (message-signed-or-encrypted-p dont-emulate-mime
)
7355 (throw 'found t
)))))))
7356 (mm-destroy-parts handles
))))
7359 (defun message-forward-make-body (forward-buffer &optional digest
)
7360 ;; Put point where we want it before inserting the forwarded
7362 (if message-forward-before-signature
7364 (goto-char (point-max)))
7366 (message-forward-make-body-digest forward-buffer
)
7367 (if message-forward-as-mime
7368 (if (and message-forward-show-mml
7369 (not (and (eq message-forward-show-mml
'best
)
7370 ;; Use the raw form in the body if it contains
7371 ;; signed or encrypted message so as not to be
7372 ;; destroyed by re-encoding.
7373 (with-current-buffer forward-buffer
7375 (message-signed-or-encrypted-p)
7377 (message-forward-make-body-mml forward-buffer
)
7378 (message-forward-make-body-mime forward-buffer
))
7379 (message-forward-make-body-plain forward-buffer
)))
7380 (message-position-point))
7382 (declare-function rmail-toggle-header
"rmail" (&optional arg
))
7385 (defun message-forward-rmail-make-body (forward-buffer)
7386 (save-window-excursion
7387 (set-buffer forward-buffer
)
7388 (if (rmail-msg-is-pruned)
7389 (if (fboundp 'rmail-msg-restore-non-pruned-header
)
7390 (rmail-msg-restore-non-pruned-header) ; Emacs 22
7391 (rmail-toggle-header 0)))) ; Emacs 23
7392 (message-forward-make-body forward-buffer
))
7394 ;; Fixme: Should have defcustom.
7396 (defun message-insinuate-rmail ()
7397 "Let RMAIL use message to forward."
7399 (setq rmail-enable-mime-composing t
)
7400 (setq rmail-insert-mime-forwarded-message-function
7401 'message-forward-rmail-make-body
))
7404 (defun message-resend (address)
7405 "Resend the current article to ADDRESS."
7407 (list (message-read-from-minibuffer "Resend message to: ")))
7408 (message "Resending message to %s..." address
)
7410 (let ((cur (current-buffer))
7412 ;; We first set up a normal mail buffer.
7413 (unless (message-mail-user-agent)
7414 (set-buffer (get-buffer-create " *message resend*"))
7416 (let ((message-this-is-mail t
)
7417 message-generate-hashcash
7419 (message-setup `((To .
,address
))))
7420 ;; Insert our usual headers.
7421 (message-generate-headers '(From Date To Message-ID
))
7422 (message-narrow-to-headers)
7423 ;; Remove X-Draft-From header etc.
7424 (message-remove-header message-ignored-mail-headers t
)
7425 ;; Rename them all to "Resent-*".
7426 (goto-char (point-min))
7427 (while (re-search-forward "^[A-Za-z]" nil t
)
7432 (delete-region (point) (point-max))
7434 ;; Insert the message to be resent.
7435 (insert-buffer-substring cur
)
7436 (goto-char (point-min))
7437 (search-forward "\n\n")
7440 (narrow-to-region beg
(point))
7441 (message-remove-header message-ignored-resent-headers t
)
7442 (goto-char (point-max)))
7443 (insert mail-header-separator
)
7444 ;; Rename all old ("Also-")Resent headers.
7445 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t
)
7448 ;; Quote any "From " lines at the beginning.
7450 (when (looking-at "From ")
7451 (replace-match "X-From-Line: "))
7453 (let ((message-inhibit-body-encoding t
)
7454 (message-inhibit-ecomplete t
)
7455 message-required-mail-headers
7456 message-generate-hashcash
7457 rfc2047-encode-encoded-words
)
7458 (message-send-mail))
7459 (kill-buffer (current-buffer)))
7460 (message "Resending message to %s...done" address
)))
7463 (defun message-bounce ()
7464 "Re-mail the current message.
7465 This only makes sense if the current message is a bounce message that
7466 contains some mail you have written which has been bounced back to
7469 (let ((handles (mm-dissect-buffer t
))
7471 (message-pop-to-buffer (message-buffer-name "bounce"))
7472 (if (stringp (car handles
))
7473 ;; This is a MIME bounce.
7474 (mm-insert-part (car (last handles
)))
7475 ;; This is a non-MIME bounce, so we try to remove things
7477 (mm-insert-part handles
)
7479 (goto-char (point-min))
7480 (re-search-forward "\n\n+" nil t
)
7481 (setq boundary
(point))
7482 ;; We remove everything before the bounced mail.
7483 (if (or (re-search-forward message-unsent-separator nil t
)
7485 (search-forward "\n\n" nil
'move
)
7486 (re-search-backward "^Return-Path:.*\n" boundary t
)))
7489 (delete-region (point-min)
7490 (if (re-search-forward "^[^ \n\t]+:" nil t
)
7493 (goto-char boundary
)
7494 (when (re-search-backward "^.?From .*\n" nil t
)
7495 (delete-region (match-beginning 0) (match-end 0)))))
7498 (message-narrow-to-head-1)
7499 (message-remove-header message-ignored-bounced-headers t
)
7500 (goto-char (point-max))
7501 (insert mail-header-separator
))
7502 (message-position-point)))
7505 ;;; Interactive entry points for new message buffers.
7509 (defun message-mail-other-window (&optional to subject
)
7510 "Like `message-mail' command, but display mail buffer in another window."
7512 (unless (message-mail-user-agent)
7513 (let ((pop-up-windows t
)
7514 (special-display-buffer-names nil
)
7515 (special-display-regexps nil
)
7516 (same-window-buffer-names nil
)
7517 (same-window-regexps nil
))
7518 (message-pop-to-buffer (message-buffer-name "mail" to
))))
7519 (let ((message-this-is-mail t
))
7520 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
"")))
7521 nil nil nil
'switch-to-buffer-other-window
)))
7524 (defun message-mail-other-frame (&optional to subject
)
7525 "Like `message-mail' command, but display mail buffer in another frame."
7527 (unless (message-mail-user-agent)
7528 (let ((pop-up-frames t
)
7529 (special-display-buffer-names nil
)
7530 (special-display-regexps nil
)
7531 (same-window-buffer-names nil
)
7532 (same-window-regexps nil
))
7533 (message-pop-to-buffer (message-buffer-name "mail" to
))))
7534 (let ((message-this-is-mail t
))
7535 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
"")))
7536 nil nil nil
'switch-to-buffer-other-frame
)))
7539 (defun message-news-other-window (&optional newsgroups subject
)
7540 "Start editing a news article to be sent."
7542 (let ((pop-up-windows t
)
7543 (special-display-buffer-names nil
)
7544 (special-display-regexps nil
)
7545 (same-window-buffer-names nil
)
7546 (same-window-regexps nil
))
7547 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
)))
7548 (let ((message-this-is-news t
))
7549 (message-setup `((Newsgroups .
,(or newsgroups
""))
7550 (Subject .
,(or subject
""))))))
7553 (defun message-news-other-frame (&optional newsgroups subject
)
7554 "Start editing a news article to be sent."
7556 (let ((pop-up-frames t
)
7557 (special-display-buffer-names nil
)
7558 (special-display-regexps nil
)
7559 (same-window-buffer-names nil
)
7560 (same-window-regexps nil
))
7561 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
)))
7562 (let ((message-this-is-news t
))
7563 (message-setup `((Newsgroups .
,(or newsgroups
""))
7564 (Subject .
,(or subject
""))))))
7568 ;; This code should be moved to underline.el (from which it is stolen).
7571 (defun message-bold-region (start end
)
7572 "Bold all nonblank characters in the region.
7573 Works by overstriking characters.
7574 Called from program, takes two arguments START and END
7575 which specify the range to operate on."
7578 (let ((end1 (make-marker)))
7579 (move-marker end1
(max start end
))
7580 (goto-char (min start end
))
7581 (while (< (point) end1
)
7582 (or (looking-at "[_\^@- ]")
7583 (insert (char-after) "\b"))
7584 (forward-char 1)))))
7587 (defun message-unbold-region (start end
)
7588 "Remove all boldness (overstruck characters) in the region.
7589 Called from program, takes two arguments START and END
7590 which specify the range to operate on."
7593 (let ((end1 (make-marker)))
7594 (move-marker end1
(max start end
))
7595 (goto-char (min start end
))
7596 (while (search-forward "\b" end1 t
)
7597 (if (eq (char-after) (char-after (- (point) 2)))
7598 (delete-char -
2))))))
7600 (defun message-exchange-point-and-mark ()
7601 "Exchange point and mark, but don't activate region if it was inactive."
7602 (goto-char (prog1 (mark t
)
7603 (set-marker (mark-marker) (point)))))
7605 (defalias 'message-make-overlay
'make-overlay
)
7606 (defalias 'message-delete-overlay
'delete-overlay
)
7607 (defalias 'message-overlay-put
'overlay-put
)
7608 (defun message-kill-all-overlays ()
7609 (if (featurep 'xemacs
)
7610 (map-extents (lambda (extent ignore
) (delete-extent extent
)))
7611 (mapcar #'delete-overlay
(overlays-in (point-min) (point-max)))))
7613 ;; Support for toolbar
7614 (defvar tool-bar-mode
)
7616 ;; Note: The :set function in the `message-tool-bar*' variables will only
7617 ;; affect _new_ message buffers. We might add a function that walks thru all
7618 ;; message-mode buffers and force the update.
7619 (defun message-tool-bar-update (&optional symbol value
)
7620 "Update message mode toolbar.
7621 Setter function for custom variables."
7622 (setq-default message-tool-bar-map nil
)
7624 ;; When used as ":set" function:
7625 (set-default symbol value
)))
7627 (defcustom message-tool-bar
(if (eq gmm-tool-bar-style
'gnome
)
7628 'message-tool-bar-gnome
7629 'message-tool-bar-retro
)
7630 "Specifies the message mode tool bar.
7632 It can be either a list or a symbol refering to a list. See
7633 `gmm-tool-bar-from-list' for the format of the list. The
7634 default key map is `message-mode-map'.
7636 Pre-defined symbols include `message-tool-bar-gnome' and
7637 `message-tool-bar-retro'."
7638 :type
'(repeat gmm-tool-bar-list-item
)
7639 :type
'(choice (const :tag
"GNOME style" message-tool-bar-gnome
)
7640 (const :tag
"Retro look" message-tool-bar-retro
)
7641 (repeat :tag
"User defined list" gmm-tool-bar-item
)
7643 :version
"23.1" ;; No Gnus
7644 :initialize
'custom-initialize-default
7645 :set
'message-tool-bar-update
7648 (defcustom message-tool-bar-gnome
7649 '((ispell-message "spell" nil
7650 :visible
(or (not (boundp 'flyspell-mode
))
7651 (not flyspell-mode
)))
7652 (flyspell-buffer "spell" t
7653 :visible
(and (boundp 'flyspell-mode
)
7655 :help
"Flyspell whole buffer")
7656 (gmm-ignore "separator")
7657 (message-send-and-exit "mail/send")
7658 (message-dont-send "mail/save-draft")
7659 (message-kill-buffer "close") ;; stock_cancel
7660 (mml-attach-file "attach" mml-mode-map
)
7661 (mml-preview "mail/preview" mml-mode-map
)
7662 (mml-secure-message-sign-encrypt "lock" mml-mode-map
:visible nil
)
7663 (message-insert-importance-high "important" nil
:visible nil
)
7664 (message-insert-importance-low "unimportant" nil
:visible nil
)
7665 (message-insert-disposition-notification-to "receipt" nil
:visible nil
)
7666 (gmm-customize-mode "preferences" t
:help
"Edit mode preferences")
7667 (message-info "help" t
:help
"Message manual"))
7668 "List of items for the message tool bar (GNOME style).
7670 See `gmm-tool-bar-from-list' for details on the format of the list."
7671 :type
'(repeat gmm-tool-bar-item
)
7672 :version
"23.1" ;; No Gnus
7673 :initialize
'custom-initialize-default
7674 :set
'message-tool-bar-update
7677 (defcustom message-tool-bar-retro
7678 '(;; Old Emacs 21 icon for consistency.
7679 (message-send-and-exit "gnus/mail-send")
7680 (message-kill-buffer "close")
7681 (message-dont-send "cancel")
7682 (mml-attach-file "attach" mml-mode-map
)
7683 (ispell-message "spell")
7684 (mml-preview "preview" mml-mode-map
)
7685 (message-insert-importance-high "gnus/important")
7686 (message-insert-importance-low "gnus/unimportant")
7687 (message-insert-disposition-notification-to "gnus/receipt"))
7688 "List of items for the message tool bar (retro style).
7690 See `gmm-tool-bar-from-list' for details on the format of the list."
7691 :type
'(repeat gmm-tool-bar-item
)
7692 :version
"23.1" ;; No Gnus
7693 :initialize
'custom-initialize-default
7694 :set
'message-tool-bar-update
7697 (defcustom message-tool-bar-zap-list
7698 '(new-file open-file dired kill-buffer write-file
7699 print-buffer customize help
)
7700 "List of icon items from the global tool bar.
7701 These items are not displayed on the message mode tool bar.
7703 See `gmm-tool-bar-from-list' for the format of the list."
7704 :type
'gmm-tool-bar-zap-list
7705 :version
"23.1" ;; No Gnus
7706 :initialize
'custom-initialize-default
7707 :set
'message-tool-bar-update
7710 (defvar image-load-path
)
7712 (defun message-make-tool-bar (&optional force
)
7713 "Make a message mode tool bar from `message-tool-bar-list'.
7714 When FORCE, rebuild the tool bar."
7715 (when (and (not (featurep 'xemacs
))
7716 (boundp 'tool-bar-mode
)
7718 (or (not message-tool-bar-map
) force
))
7719 (setq message-tool-bar-map
7721 (gmm-image-load-path-for-library "message"
7722 "mail/save-draft.xpm"
7724 (image-load-path (cons (car load-path
)
7725 (when (boundp 'image-load-path
)
7727 (gmm-tool-bar-from-list message-tool-bar
7728 message-tool-bar-zap-list
7729 'message-mode-map
))))
7730 message-tool-bar-map
)
7732 ;;; Group name completion.
7734 (defcustom message-newgroups-header-regexp
7735 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
7736 "Regexp that match headers that lists groups."
7740 (defcustom message-completion-alist
7741 (list (cons message-newgroups-header-regexp
'message-expand-group
)
7742 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name
)
7743 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
7744 . message-expand-name
)
7745 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
7746 . message-expand-name
))
7747 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
7750 :type
'(alist :key-type regexp
:value-type function
))
7752 (defcustom message-expand-name-databases
7754 "List of databases to try for name completion (`message-expand-name').
7755 Each element is a symbol and can be `bbdb' or `eudc'."
7757 :type
'(set (const bbdb
) (const eudc
)))
7759 (defcustom message-tab-body-function nil
7760 "*Function to execute when `message-tab' (TAB) is executed in the body.
7761 If nil, the function bound in `text-mode-map' or `global-map' is executed."
7764 :link
'(custom-manual "(message)Various Commands")
7765 :type
'(choice (const nil
)
7768 (declare-function mail-abbrev-in-expansion-header-p
"mailabbrev" ())
7770 (defun message-tab ()
7771 "Complete names according to `message-completion-alist'.
7772 Execute function specified by `message-tab-body-function' when not in
7775 (let ((alist message-completion-alist
))
7777 (let ((mail-abbrev-mode-regexp (caar alist
)))
7778 (not (mail-abbrev-in-expansion-header-p))))
7779 (setq alist
(cdr alist
)))
7780 (funcall (or (cdar alist
) message-tab-body-function
7781 (lookup-key text-mode-map
"\t")
7782 (lookup-key global-map
"\t")
7783 'indent-relative
))))
7788 (let ((standard-output (current-buffer)))
7789 (eval '(display-completion-list nil
"")))
7790 (defalias 'message-display-completion-list
'display-completion-list
))
7791 (error ;; Don't use `wrong-number-of-arguments' here because of XEmacs.
7792 (defun message-display-completion-list (completions &optional ignore
)
7793 "Display the list of completions, COMPLETIONS, using `standard-output'."
7794 (display-completion-list completions
)))))
7796 (defun message-expand-group ()
7797 "Expand the group name under point."
7798 (let* ((b (save-excursion
7803 (skip-chars-forward "^:")
7806 (skip-chars-backward "^, \t\n") (point))))
7807 (completion-ignore-case t
)
7808 (e (progn (skip-chars-forward "^,\t\n ") (point)))
7809 (hashtb (and (boundp 'gnus-active-hashtb
) gnus-active-hashtb
)))
7810 (message-completion-in-region e b hashtb
)))
7812 (defalias 'message-completion-in-region
7813 (if (fboundp 'completion-in-region
)
7814 'completion-in-region
7815 (lambda (e b hashtb
)
7816 (let* ((string (buffer-substring b e
))
7817 (completions (all-completions string hashtb
))
7819 (delete-region b
(point))
7821 ((= (length completions
) 1)
7822 (if (string= (car completions
) string
)
7825 (message "Only matching group"))
7826 (insert (car completions
))))
7827 ((and (setq comp
(try-completion string hashtb
))
7828 (not (string= comp string
)))
7833 (message "No matching groups")
7834 (save-selected-window
7835 (pop-to-buffer "*Completions*")
7836 (buffer-disable-undo)
7837 (let ((buffer-read-only nil
))
7839 (let ((standard-output (current-buffer)))
7840 (message-display-completion-list (sort completions
'string
<)
7842 (setq buffer-read-only nil
)
7843 (goto-char (point-min))
7844 (delete-region (point)
7845 (progn (forward-line 3) (point))))))))))))
7847 (defun message-expand-name ()
7848 (cond ((and (memq 'eudc message-expand-name-databases
)
7849 (boundp 'eudc-protocol
)
7851 (eudc-expand-inline))
7852 ((and (memq 'bbdb message-expand-name-databases
)
7853 (fboundp 'bbdb-complete-name
))
7854 (bbdb-complete-name))
7860 (defun message-talkative-question (ask question show
&rest text
)
7861 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
7862 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
7863 The following arguments may contain lists of values."
7865 (setq text
(message-flatten-list text
)))
7866 (save-window-excursion
7867 (with-output-to-temp-buffer " *MESSAGE information message*"
7868 (with-current-buffer " *MESSAGE information message*"
7869 (fundamental-mode) ; for Emacs 20.4+
7871 (goto-char (point-min))))
7872 (funcall ask question
))
7873 (funcall ask question
)))
7875 (defun message-flatten-list (list)
7876 "Return a new, flat list that contains all elements of LIST.
7878 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
7881 (apply 'append
(mapcar 'message-flatten-list list
)))
7885 (defun message-generate-new-buffer-clone-locals (name &optional varstr
)
7886 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
7887 Then clone the local variables and values from the old buffer to the
7888 new one, cloning only the locals having a substring matching the
7890 (let ((oldbuf (current-buffer)))
7891 (with-current-buffer (generate-new-buffer name
)
7892 (message-clone-locals oldbuf varstr
)
7895 (defun message-clone-locals (buffer &optional varstr
)
7896 "Clone the local variables from BUFFER to the current buffer."
7897 (let ((locals (with-current-buffer buffer
(buffer-local-variables)))
7898 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address"))
7901 (when (and (consp local
)
7903 (string-match regexp
(symbol-name (car local
)))
7905 (string-match varstr
(symbol-name (car local
)))))
7907 (set (make-local-variable (car local
))
7915 (defvar message-inhibit-body-encoding nil
)
7917 (defun message-encode-message-body ()
7918 (unless message-inhibit-body-encoding
7919 (let ((mail-parse-charset (or mail-parse-charset
7920 message-default-charset
))
7921 (case-fold-search t
)
7922 lines content-type-p
)
7925 (narrow-to-region (point) (point-max))
7926 (let ((new (mml-generate-mime)))
7928 (delete-region (point-min) (point-max))
7930 (goto-char (point-min))
7931 (if (eq (aref new
0) ?
\n)
7933 (search-forward "\n\n")
7934 (setq lines
(buffer-substring (point-min) (1- (point))))
7935 (delete-region (point-min) (point))))))
7937 (message-narrow-to-headers-or-head)
7938 (message-remove-header "Mime-Version")
7939 (goto-char (point-max))
7940 (insert "MIME-Version: 1.0\n")
7943 (setq content-type-p
7945 (re-search-backward "^Content-Type:" nil t
))))
7947 (message-narrow-to-headers-or-head)
7948 (message-remove-first-header "Content-Type")
7949 (message-remove-first-header "Content-Transfer-Encoding"))
7950 ;; We always make sure that the message has a Content-Type
7951 ;; header. This is because some broken MTAs and MUAs get
7952 ;; awfully confused when confronted with a message with a
7953 ;; MIME-Version header and without a Content-Type header. For
7954 ;; instance, Solaris' /usr/bin/mail.
7955 (unless content-type-p
7956 (goto-char (point-min))
7957 ;; For unknown reason, MIME-Version doesn't exist.
7958 (when (re-search-forward "^MIME-Version:" nil t
)
7960 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
7962 (defun message-read-from-minibuffer (prompt &optional initial-contents
)
7963 "Read from the minibuffer while providing abbrev expansion."
7964 (if (fboundp 'mail-abbrevs-setup
)
7965 (let ((mail-abbrev-mode-regexp "")
7966 (minibuffer-setup-hook 'mail-abbrevs-setup
)
7967 (minibuffer-local-map message-minibuffer-local-map
))
7968 (read-from-minibuffer prompt initial-contents
))
7969 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook
)
7970 (minibuffer-local-map message-minibuffer-local-map
))
7971 (read-string prompt initial-contents
))))
7973 (defun message-use-alternative-email-as-from ()
7974 "Set From field of the outgoing message to the first matching
7975 address in `message-alternative-emails', looking at To, Cc and
7976 From headers in the original article."
7977 (require 'mail-utils
)
7978 (let* ((fields '("To" "Cc" "From"))
7981 (mail-strip-quoted-names
7982 (mapconcat 'message-fetch-reply-field fields
","))
7986 (if (string-match message-alternative-emails
(car emails
))
7987 (setq email
(car emails
)
7990 (unless (or (not email
) (equal email user-mail-address
))
7991 (message-remove-header "From")
7992 (goto-char (point-max))
7993 (insert "From: " (let ((user-mail-address email
)) (message-make-from))
7996 (defun message-options-get (symbol)
7997 (cdr (assq symbol message-options
)))
7999 (defun message-options-set (symbol value
)
8000 (let ((the-cons (assq symbol message-options
)))
8003 (setcdr the-cons value
)
8004 (setq message-options
(delq the-cons message-options
)))
8006 (push (cons symbol value
) message-options
))))
8009 (defun message-options-set-recipient ()
8011 (message-narrow-to-headers-or-head)
8012 (message-options-set 'message-sender
8013 (mail-strip-quoted-names
8014 (message-fetch-field "from")))
8015 (message-options-set 'message-recipients
8016 (mail-strip-quoted-names
8017 (let ((to (message-fetch-field "to"))
8018 (cc (message-fetch-field "cc"))
8019 (bcc (message-fetch-field "bcc")))
8022 (if (and to cc
) ", ")
8024 (if (and (or to cc
) bcc
) ", ")
8027 (defun message-hide-headers ()
8028 "Hide headers based on the `message-hidden-headers' variable."
8029 (let ((regexps (if (stringp message-hidden-headers
)
8030 (list message-hidden-headers
)
8031 message-hidden-headers
))
8032 (inhibit-point-motion-hooks t
)
8033 (after-change-functions nil
)
8034 (end-of-headers (point-min)))
8038 (message-narrow-to-headers)
8039 (goto-char (point-min))
8041 (if (not (message-hide-header-p regexps
))
8042 (message-next-header)
8043 (let ((begin (point))
8045 (message-next-header)
8046 (setq header
(buffer-substring begin
(point))
8047 header-len
(- (point) begin
))
8048 (delete-region begin
(point))
8049 (goto-char end-of-headers
)
8051 (setq end-of-headers
8052 (+ end-of-headers header-len
))))))))
8053 (narrow-to-region end-of-headers
(point-max))))
8055 (defun message-hide-header-p (regexps)
8058 (when (eq (car regexps
) 'not
)
8061 (dolist (regexp regexps
)
8062 (setq result
(or result
(looking-at regexp
))))
8067 (declare-function ecomplete-add-item
"ecomplete" (type key text
))
8068 (declare-function ecomplete-save
"ecomplete" ())
8070 (defun message-put-addresses-in-ecomplete ()
8071 (require 'ecomplete
)
8072 (dolist (header '("to" "cc" "from" "reply-to"))
8073 (let ((value (message-field-value header
)))
8074 (dolist (string (mail-header-parse-addresses value
'raw
))
8076 (gnus-replace-in-string
8077 (gnus-replace-in-string string
"^ +\\| +$" "") "\n" ""))
8078 (ecomplete-add-item 'mail
(car (mail-header-parse-address string
))
8082 (autoload 'ecomplete-display-matches
"ecomplete")
8084 (defun message-display-abbrev (&optional choose
)
8085 "Display the next possible abbrev for the text before point."
8086 (interactive (list t
))
8087 (when (and (memq (char-after (point-at-bol)) '(?C ?T ?
\t ?
))
8088 (message-point-in-header-p)
8091 (while (and (memq (char-after) '(?
\t ?
))
8092 (zerop (forward-line -
1))))
8093 (looking-at "To:\\|Cc:")))
8094 (let* ((end (point))
8095 (start (save-excursion
8096 (and (re-search-backward "[\n\t ]" nil t
)
8098 (word (when start
(buffer-substring start end
)))
8099 (match (when (and word
8100 (not (zerop (length word
))))
8101 (ecomplete-display-matches 'mail word choose
))))
8102 (when (and choose match
)
8103 (delete-region start end
)
8106 ;; To send pre-formatted letters like the example below, you can use
8107 ;; `message-send-form-letter':
8108 ;; --8<---------------cut here---------------start------------->8---
8109 ;; To: alice@invalid.invalid
8110 ;; Subject: Verification of your contact information
8111 ;; From: Contact verification <admin@foo.invalid>
8112 ;; --text follows this line--
8114 ;; please verify that your contact information is still valid:
8115 ;; Alice A, A avenue 11, 1111 A town, Austria
8116 ;; ----------next form letter message follows this line----------
8117 ;; To: bob@invalid.invalid
8118 ;; Subject: Verification of your contact information
8119 ;; From: Contact verification <admin@foo.invalid>
8120 ;; --text follows this line--
8122 ;; please verify that your contact information is still valid:
8123 ;; Bob, B street 22, 22222 Be town, Belgium
8124 ;; ----------next form letter message follows this line----------
8125 ;; To: charlie@invalid.invalid
8126 ;; Subject: Verification of your contact information
8127 ;; From: Contact verification <admin@foo.invalid>
8128 ;; --text follows this line--
8130 ;; please verify that your contact information is still valid:
8131 ;; Charlie Chaplin, C plaza 33, 33333 C town, Chile
8132 ;; --8<---------------cut here---------------end--------------->8---
8134 ;; FIXME: What is the most common term (circular letter, form letter, serial
8135 ;; letter, standard letter) for such kind of letter? See also
8136 ;; <http://en.wikipedia.org/wiki/Form_letter>
8138 ;; FIXME: Maybe extent message-mode's font-lock support to recognize
8139 ;; `message-form-letter-separator', i.e. highlight each message like a single
8142 (defcustom message-form-letter-separator
8143 "\n----------next form letter message follows this line----------\n"
8144 "Separator for `message-send-form-letter'."
8145 ;; :group 'message-form-letter
8146 :group
'message-various
8147 :version
"23.1" ;; No Gnus
8150 (defcustom message-send-form-letter-delay
1
8151 "Delay in seconds when sending a message with `message-send-form-letter'.
8152 Only used when `message-send-form-letter' is called with non-nil
8154 ;; :group 'message-form-letter
8155 :group
'message-various
8156 :version
"23.1" ;; No Gnus
8159 (defun message-send-form-letter (&optional force
)
8160 "Sent all form letter messages from current buffer.
8161 Unless FORCE, prompt before sending.
8163 The messages are separated by `message-form-letter-separator'.
8164 Header and body are separated by `mail-header-separator'."
8166 (let ((sent 0) (skipped 0)
8170 (goto-char (point-min))
8173 end
(if (search-forward message-form-letter-separator nil t
)
8174 (- (point) (length message-form-letter-separator
) -
1)
8178 (buffer-substring-no-properties start end
))
8179 (setq buff
(generate-new-buffer "*mail - form letter*"))
8180 (with-current-buffer buff
8183 (setq to
(message-fetch-field "To"))
8184 (switch-to-buffer buff
)
8186 (sit-for message-send-form-letter-delay
))
8188 (y-or-n-p (format "Send message to `%s'? " to
)))
8190 (setq sent
(1+ sent
))
8191 (message-send-and-exit))
8192 (message (format "Message to `%s' skipped." to
))
8193 (setq skipped
(1+ skipped
)))
8194 (when (buffer-live-p buff
)
8195 (kill-buffer buff
))))
8196 (message "%s message(s) sent, %s skipped." sent skipped
)))
8198 (defun message-replace-header (header new-value
&optional after force
)
8199 "Remove HEADER and insert the NEW-VALUE.
8200 If AFTER, insert after this header. If FORCE, insert new field
8201 even if NEW-VALUE is empty."
8202 ;; Similar to `nnheader-replace-header' but for message buffers.
8205 (message-narrow-to-headers)
8206 (message-remove-header header
))
8207 (when (or force
(> (length new-value
) 0))
8209 (message-position-on-field header after
)
8210 (message-position-on-field header
))
8211 (insert new-value
))))
8213 (defcustom message-recipients-without-full-name
8214 (list "ding@gnus.org"
8216 "emacs-devel@gnu.org"
8217 "emacs-pretest-bug@gnu.org"
8218 "bug-gnu-emacs@gnu.org")
8219 "Mail addresses that have no full name.
8220 Used in `message-simplify-recipients'."
8221 ;; Maybe the addresses could be extracted from
8222 ;; `gnus-parameter-to-list-alist'?
8223 :type
'(choice (const :tag
"None" nil
)
8225 :version
"23.1" ;; No Gnus
8226 :group
'message-headers
)
8228 (defun message-simplify-recipients ()
8230 (dolist (hdr '("Cc" "To"))
8231 (message-replace-header
8235 (if (and message-recipients-without-full-name
8237 (regexp-opt message-recipients-without-full-name
)
8241 (message-make-from (car addrcomp
) (cadr addrcomp
))
8243 (when (message-fetch-field hdr
)
8244 (mail-extract-address-components
8245 (message-fetch-field hdr
) t
))
8248 (when (featurep 'xemacs
)
8249 (require 'messagexmas
)
8250 (message-xmas-redefine))
8254 (run-hooks 'message-load-hook
)
8257 ;; coding: iso-8859-1
8260 ;; arch-tag: 94b32cac-4504-4b6c-8181-030ebf380ee0
8261 ;;; message.el ends here