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."
257 :group
'message-headers
258 :link
'(custom-manual "(message)Wide Reply")
259 :type
'(repeat regexp
))
261 (defcustom message-deletable-headers
'(Message-ID Date Lines
)
262 "Headers to be deleted if they already exist and were generated by message previously."
263 :group
'message-headers
264 :link
'(custom-manual "(message)Message Headers")
267 (defcustom message-ignored-news-headers
268 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
269 "*Regexp of headers to be removed unconditionally before posting."
271 :group
'message-headers
272 :link
'(custom-manual "(message)Message Headers")
273 :type
'(repeat :value-to-internal
(lambda (widget value
)
274 (custom-split-regexp-maybe value
))
275 :match
(lambda (widget value
)
277 (widget-editable-list-match widget value
)))
280 (defcustom message-ignored-mail-headers
281 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
282 "*Regexp of headers to be removed unconditionally before mailing."
284 :group
'message-headers
285 :link
'(custom-manual "(message)Mail Headers")
288 (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:"
289 "*Header lines matching this regexp will be deleted before posting.
290 It's best to delete old Path and Date headers before posting to avoid
292 :group
'message-interface
293 :link
'(custom-manual "(message)Superseding")
294 :type
'(repeat :value-to-internal
(lambda (widget value
)
295 (custom-split-regexp-maybe value
))
296 :match
(lambda (widget value
)
298 (widget-editable-list-match widget value
)))
301 (defcustom message-subject-re-regexp
302 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)*:[ \t]*\\)*[ \t]*"
303 "*Regexp matching \"Re: \" in the subject line."
304 :group
'message-various
305 :link
'(custom-manual "(message)Message Headers")
308 ;;; Start of variables adopted from `message-utils.el'.
310 (defcustom message-subject-trailing-was-query
'ask
311 "*What to do with trailing \"(was: <old subject>)\" in subject lines.
312 If nil, leave the subject unchanged. If it is the symbol `ask', query
313 the user what do do. In this case, the subject is matched against
314 `message-subject-trailing-was-ask-regexp'. If
315 `message-subject-trailing-was-query' is t, always strip the trailing
316 old subject. In this case, `message-subject-trailing-was-regexp' is
319 :type
'(choice (const :tag
"never" nil
)
320 (const :tag
"always strip" t
)
322 :link
'(custom-manual "(message)Message Headers")
323 :group
'message-various
)
325 (defcustom message-subject-trailing-was-ask-regexp
326 "[ \t]*\\([[(]+[Ww][Aa][Ss][ \t]*.*[\])]+\\)"
327 "*Regexp matching \"(was: <old subject>)\" in the subject line.
329 The function `message-strip-subject-trailing-was' uses this regexp if
330 `message-subject-trailing-was-query' is set to the symbol `ask'. If
331 the variable is t instead of `ask', use
332 `message-subject-trailing-was-regexp' instead.
334 It is okay to create some false positives here, as the user is asked."
336 :group
'message-various
337 :link
'(custom-manual "(message)Message Headers")
340 (defcustom message-subject-trailing-was-regexp
341 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
342 "*Regexp matching \"(was: <old subject>)\" in the subject line.
344 If `message-subject-trailing-was-query' is set to t, the subject is
345 matched against `message-subject-trailing-was-regexp' in
346 `message-strip-subject-trailing-was'. You should use a regexp creating very
347 few false positives here."
349 :group
'message-various
350 :link
'(custom-manual "(message)Message Headers")
353 ;;; marking inserted text
355 (defcustom message-mark-insert-begin
356 "--8<---------------cut here---------------start------------->8---\n"
357 "How to mark the beginning of some inserted text."
360 :link
'(custom-manual "(message)Insertion Variables")
361 :group
'message-various
)
363 (defcustom message-mark-insert-end
364 "--8<---------------cut here---------------end--------------->8---\n"
365 "How to mark the end of some inserted text."
368 :link
'(custom-manual "(message)Insertion Variables")
369 :group
'message-various
)
371 (defcustom message-archive-header
"X-No-Archive: Yes\n"
372 "Header to insert when you don't want your article to be archived.
373 Archives \(such as groups.google.com\) respect this header."
376 :link
'(custom-manual "(message)Header Commands")
377 :group
'message-various
)
379 (defcustom message-archive-note
380 "X-No-Archive: Yes - save http://groups.google.com/"
381 "Note to insert why you wouldn't want this posting archived.
382 If nil, don't insert any text in the body."
384 :type
'(radio string
(const nil
))
385 :link
'(custom-manual "(message)Header Commands")
386 :group
'message-various
)
388 ;;; Crossposts and Followups
389 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
390 ;; new suggestions by R. Weikusat <rw at another.de>
392 (defvar message-cross-post-old-target nil
393 "Old target for cross-posts or follow-ups.")
394 (make-variable-buffer-local 'message-cross-post-old-target
)
396 (defcustom message-cross-post-default t
397 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
398 If nil, `message-cross-post-followup-to' will only do a followup. Note that
399 you can explicitly override this setting by calling
400 `message-cross-post-followup-to' with a prefix."
403 :group
'message-various
)
405 (defcustom message-cross-post-note
"Crosspost & Followup-To: "
406 "Note to insert before signature to notify of cross-post and follow-up."
409 :group
'message-various
)
411 (defcustom message-followup-to-note
"Followup-To: "
412 "Note to insert before signature to notify of follow-up only."
415 :group
'message-various
)
417 (defcustom message-cross-post-note-function
'message-cross-post-insert-note
418 "Function to use to insert note about Crosspost or Followup-To.
419 The function will be called with four arguments. The function should not only
420 insert a note, but also ensure old notes are deleted. See the documentation
421 for `message-cross-post-insert-note'."
424 :group
'message-various
)
426 ;;; End of variables adopted from `message-utils.el'.
428 (defcustom message-signature-separator
"^-- $"
429 "Regexp matching the signature separator.
430 This variable is used to strip off the signature from quoted text
431 when `message-cite-function' is
432 `message-cite-original-without-signature'. Most useful values
433 are \"^-- $\" (strict) and \"^-- *$\" (loose; allow missing
435 :type
'(choice (const :tag
"strict" "^-- $")
436 (const :tag
"loose" "^-- *$")
438 :version
"22.3" ;; Gnus 5.10.12 (changed default)
439 :link
'(custom-manual "(message)Various Message Variables")
440 :group
'message-various
)
442 (defcustom message-elide-ellipsis
"\n[...]\n\n"
443 "*The string which is inserted for elided text."
445 :link
'(custom-manual "(message)Various Commands")
446 :group
'message-various
)
448 (defcustom message-interactive mail-interactive
449 ;; Default to the value of `mail-interactive', available in all Emacsen
450 ;; that Gnus supports.
451 "Non-nil means when sending a message wait for and display errors.
452 A value of nil means let mailer mail back a message to report errors."
454 :group
'message-sending
456 :link
'(custom-manual "(message)Sending Variables")
459 (defcustom message-confirm-send nil
460 "When non-nil, ask for confirmation when sending a message."
461 :group
'message-sending
463 :version
"23.1" ;; No Gnus
464 :link
'(custom-manual "(message)Sending Variables")
467 (defcustom message-generate-new-buffers
'unsent
468 "*Say whether to create a new message buffer to compose a message.
469 Valid values include:
472 Generate the buffer name in the Message way (e.g., *mail*, *news*,
473 *mail to whom*, *news on group*, etc.) and continue editing in the
474 existing buffer of that name. If there is no such buffer, it will
478 Create the new buffer with the name generated in the Message way.
481 Similar to `unique' but the buffer name begins with \"*unsent \".
484 Similar to nil but the buffer name is simpler like *mail message*.
487 If this is a function, call that function with three parameters:
488 The type, the To address and the group name (any of these may be nil).
489 The function should return the new buffer name."
491 :group
'message-buffers
492 :link
'(custom-manual "(message)Message Buffers")
493 :type
'(choice (const nil
)
494 (sexp :tag
"unique" :format
"unique\n" :value unique
495 :match
(lambda (widget value
) (memq value
'(unique t
))))
498 (function :format
"\n %{%t%}: %v")))
500 (defcustom message-kill-buffer-on-exit nil
501 "*Non-nil means that the message buffer will be killed after sending a message."
502 :group
'message-buffers
503 :link
'(custom-manual "(message)Message Buffers")
506 (defcustom message-kill-buffer-query t
507 "*Non-nil means that killing a modified message buffer has to be confirmed.
508 This is used by `message-kill-buffer'."
509 :version
"23.1" ;; No Gnus
510 :group
'message-buffers
513 (defvar gnus-local-organization
)
514 (defcustom message-user-organization
515 (or (and (boundp 'gnus-local-organization
)
516 (stringp gnus-local-organization
)
517 gnus-local-organization
)
518 (getenv "ORGANIZATION")
520 "*String to be used as an Organization header.
521 If t, use `message-user-organization-file'."
522 :group
'message-headers
523 :type
'(choice string
524 (const :tag
"consult file" t
)))
526 (defcustom message-user-organization-file
528 (dolist (f (list "/etc/organization"
529 "/etc/news/organization"
530 "/usr/lib/news/organization"))
531 (when (file-readable-p f
)
534 "*Local news organization file."
536 :link
'(custom-manual "(message)News Headers")
537 :group
'message-headers
)
539 (defcustom message-make-forward-subject-function
540 #'message-forward-subject-name-subject
541 "*List of functions called to generate subject headers for forwarded messages.
542 The subject generated by the previous function is passed into each
545 The provided functions are:
547 * `message-forward-subject-author-subject' Source of article (author or
548 newsgroup), in brackets followed by the subject
549 * `message-forward-subject-name-subject' Source of article (name of author
550 or newsgroup), in brackets followed by the subject
551 * `message-forward-subject-fwd' Subject of article with 'Fwd:' prepended
553 :group
'message-forwarding
554 :link
'(custom-manual "(message)Forwarding")
555 :type
'(radio (function-item message-forward-subject-author-subject
)
556 (function-item message-forward-subject-fwd
)
557 (function-item message-forward-subject-name-subject
)
558 (repeat :tag
"List of functions" function
)))
560 (defcustom message-forward-as-mime t
561 "*Non-nil means forward messages as an inline/rfc822 MIME section.
562 Otherwise, directly inline the old message in the forwarded message."
564 :group
'message-forwarding
565 :link
'(custom-manual "(message)Forwarding")
568 (defcustom message-forward-show-mml
'best
569 "*Non-nil means show forwarded messages as MML (decoded from MIME).
570 Otherwise, forwarded messages are unchanged.
571 Can also be the symbol `best' to indicate that MML should be
572 used, except when it is a bad idea to use MML. One example where
573 it is a bad idea is when forwarding a signed or encrypted
574 message, because converting MIME to MML would invalidate the
577 :group
'message-forwarding
578 :type
'(choice (const :tag
"use MML" t
)
579 (const :tag
"don't use MML " nil
)
580 (const :tag
"use MML when appropriate" best
)))
582 (defcustom message-forward-before-signature t
583 "*Non-nil means put forwarded message before signature, else after."
584 :group
'message-forwarding
587 (defcustom message-wash-forwarded-subjects nil
588 "*Non-nil means try to remove as much cruft as possible from the subject.
589 Done before generating the new subject of a forward."
590 :group
'message-forwarding
591 :link
'(custom-manual "(message)Forwarding")
594 (defcustom message-ignored-resent-headers
595 ;; `Delivered-To' needs to be removed because some mailers use it to
596 ;; detect loops, so if you resend a message to an address that ultimately
597 ;; comes back to you (e.g. a mailing-list to which you subscribe, in which
598 ;; case you may be removed from the list on the grounds that mail to you
599 ;; bounced with a "mailing loop" error).
600 "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From \\|^Delivered-To:"
601 "*All headers that match this regexp will be deleted when resending a message."
602 :group
'message-interface
603 :link
'(custom-manual "(message)Resending")
604 :type
'(repeat :value-to-internal
(lambda (widget value
)
605 (custom-split-regexp-maybe value
))
606 :match
(lambda (widget value
)
608 (widget-editable-list-match widget value
)))
611 (defcustom message-forward-ignored-headers
"^Content-Transfer-Encoding:\\|^X-Gnus"
612 "*All headers that match this regexp will be deleted when forwarding a message."
614 :group
'message-forwarding
615 :type
'(repeat :value-to-internal
(lambda (widget value
)
616 (custom-split-regexp-maybe value
))
617 :match
(lambda (widget value
)
619 (widget-editable-list-match widget value
)))
622 (defcustom message-ignored-cited-headers
"."
623 "*Delete these headers from the messages you yank."
624 :group
'message-insertion
625 :link
'(custom-manual "(message)Insertion Variables")
628 (defcustom message-cite-prefix-regexp
629 ;; Default to the value of `mail-citation-prefix-regexp' if available.
630 ;; Note: as for Emacs 21, XEmacs 21.4 and 21.5, it is unavailable
631 ;; unless sendmail.el is loaded.
632 (cond ((boundp 'mail-citation-prefix-regexp
)
633 mail-citation-prefix-regexp
)
634 ((string-match "[[:digit:]]" "1")
635 ;; Support POSIX? XEmacs 21.5.27 doesn't.
636 "\\([ \t]*[_.[:word:]]+>+\\|[ \t]*[]>|}]\\)+")
638 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
639 (let (non-word-constituents)
640 (with-syntax-table text-mode-syntax-table
641 (setq non-word-constituents
643 (if (string-match "\\w" "_") "" "_")
644 (if (string-match "\\w" ".") "" "."))))
645 (if (equal non-word-constituents
"")
646 "\\([ \t]*\\(\\w\\)+>+\\|[ \t]*[]>|}]\\)+"
647 (concat "\\([ \t]*\\(\\w\\|["
648 non-word-constituents
649 "]\\)+>+\\|[ \t]*[]>|}]\\)+")))))
650 "*Regexp matching the longest possible citation prefix on a line."
652 :group
'message-insertion
653 :link
'(custom-manual "(message)Insertion Variables")
655 :set
(lambda (symbol value
)
657 (custom-set-default symbol value
)
658 (if (boundp 'gnus-message-cite-prefix-regexp
)
659 (setq gnus-message-cite-prefix-regexp
660 (concat "^\\(?:" value
"\\)"))))))
662 (defcustom message-cancel-message
"I am canceling my own article.\n"
663 "Message to be inserted in the cancel message."
664 :group
'message-interface
665 :link
'(custom-manual "(message)Canceling News")
668 (defun message-send-mail-function ()
669 "Return suitable value for the variable `message-send-mail-function'."
670 (cond ((and (require 'sendmail
)
671 (boundp 'sendmail-program
)
673 (executable-find sendmail-program
))
674 'message-send-mail-with-sendmail
)
675 ((and (locate-library "smtpmail")
676 (boundp 'smtpmail-default-smtp-server
)
677 smtpmail-default-smtp-server
)
678 'message-smtpmail-send-it
)
679 ((locate-library "mailclient")
680 'message-send-mail-with-mailclient
)
682 (error "Don't know how to send mail. Please customize `message-send-mail-function'"))))
684 ;; Useful to set in site-init.el
685 (defcustom message-send-mail-function
686 (cond ((eq send-mail-function
'smtpmail-send-it
) 'message-smtpmail-send-it
)
687 ((eq send-mail-function
'feedmail-send-it
) 'feedmail-send-it
)
688 ((eq send-mail-function
'mailclient-send-it
)
689 'message-send-mail-with-mailclient
)
690 (t (message-send-mail-function)))
691 "Function to call to send the current buffer as mail.
692 The headers should be delimited by a line whose contents match the
693 variable `mail-header-separator'.
695 Valid values include `message-send-mail-with-sendmail'
696 `message-send-mail-with-mh', `message-send-mail-with-qmail',
697 `message-smtpmail-send-it', `smtpmail-send-it',
698 `feedmail-send-it' and `message-send-mail-with-mailclient'. The
699 default is system dependent and determined by the function
700 `message-send-mail-function'.
702 See also `send-mail-function'."
703 :type
'(radio (function-item message-send-mail-with-sendmail
)
704 (function-item message-send-mail-with-mh
)
705 (function-item message-send-mail-with-qmail
)
706 (function-item message-smtpmail-send-it
)
707 (function-item smtpmail-send-it
)
708 (function-item feedmail-send-it
)
709 (function-item message-send-mail-with-mailclient
710 :tag
"Use Mailclient package")
711 (function :tag
"Other"))
712 :group
'message-sending
714 :initialize
'custom-initialize-default
715 :link
'(custom-manual "(message)Mail Variables")
716 :group
'message-mail
)
718 (defcustom message-send-news-function
'message-send-news
719 "Function to call to send the current buffer as news.
720 The headers should be delimited by a line whose contents match the
721 variable `mail-header-separator'."
722 :group
'message-sending
724 :link
'(custom-manual "(message)News Variables")
727 (defcustom message-reply-to-function nil
728 "If non-nil, function that should return a list of headers.
729 This function should pick out addresses from the To, Cc, and From headers
730 and respond with new To and Cc headers."
731 :group
'message-interface
732 :link
'(custom-manual "(message)Reply")
733 :type
'(choice function
(const nil
)))
735 (defcustom message-wide-reply-to-function nil
736 "If non-nil, function that should return a list of headers.
737 This function should pick out addresses from the To, Cc, and From headers
738 and respond with new To and Cc headers."
739 :group
'message-interface
740 :link
'(custom-manual "(message)Wide Reply")
741 :type
'(choice function
(const nil
)))
743 (defcustom message-followup-to-function nil
744 "If non-nil, function that should return a list of headers.
745 This function should pick out addresses from the To, Cc, and From headers
746 and respond with new To and Cc headers."
747 :group
'message-interface
748 :link
'(custom-manual "(message)Followup")
749 :type
'(choice function
(const nil
)))
751 (defcustom message-extra-wide-headers nil
752 "If non-nil, a list of additional address headers.
753 These are used when composing a wide reply."
754 :group
'message-sending
755 :type
'(repeat string
))
757 (defcustom message-use-followup-to
'ask
758 "*Specifies what to do with Followup-To header.
759 If nil, always ignore the header. If it is t, use its value, but
760 query before using the \"poster\" value. If it is the symbol `ask',
761 always query the user whether to use the value. If it is the symbol
762 `use', always use the value."
763 :group
'message-interface
764 :link
'(custom-manual "(message)Followup")
765 :type
'(choice (const :tag
"ignore" nil
)
766 (const :tag
"use & query" t
)
770 (defcustom message-use-mail-followup-to
'use
771 "*Specifies what to do with Mail-Followup-To header.
772 If nil, always ignore the header. If it is the symbol `ask', always
773 query the user whether to use the value. If it is the symbol `use',
774 always use the value."
776 :group
'message-interface
777 :link
'(custom-manual "(message)Mailing Lists")
778 :type
'(choice (const :tag
"ignore" nil
)
782 (defcustom message-subscribed-address-functions nil
783 "*Specifies functions for determining list subscription.
784 If nil, do not attempt to determine list subscription with functions.
785 If non-nil, this variable contains a list of functions which return
786 regular expressions to match lists. These functions can be used in
787 conjunction with `message-subscribed-regexps' and
788 `message-subscribed-addresses'."
790 :group
'message-interface
791 :link
'(custom-manual "(message)Mailing Lists")
792 :type
'(repeat sexp
))
794 (defcustom message-subscribed-address-file nil
795 "*A file containing addresses the user is subscribed to.
796 If nil, do not look at any files to determine list subscriptions. If
797 non-nil, each line of this file should be a mailing list address."
799 :group
'message-interface
800 :link
'(custom-manual "(message)Mailing Lists")
801 :type
'(radio file
(const nil
)))
803 (defcustom message-subscribed-addresses nil
804 "*Specifies a list of addresses the user is subscribed to.
805 If nil, do not use any predefined list subscriptions. This list of
806 addresses can be used in conjunction with
807 `message-subscribed-address-functions' and `message-subscribed-regexps'."
809 :group
'message-interface
810 :link
'(custom-manual "(message)Mailing Lists")
811 :type
'(repeat string
))
813 (defcustom message-subscribed-regexps nil
814 "*Specifies a list of addresses the user is subscribed to.
815 If nil, do not use any predefined list subscriptions. This list of
816 regular expressions can be used in conjunction with
817 `message-subscribed-address-functions' and `message-subscribed-addresses'."
819 :group
'message-interface
820 :link
'(custom-manual "(message)Mailing Lists")
821 :type
'(repeat regexp
))
823 (defcustom message-allow-no-recipients
'ask
824 "Specifies what to do when there are no recipients other than Gcc/Fcc.
825 If it is the symbol `always', the posting is allowed. If it is the
826 symbol `never', the posting is not allowed. If it is the symbol
827 `ask', you are prompted."
829 :group
'message-interface
830 :link
'(custom-manual "(message)Message Headers")
831 :type
'(choice (const always
)
835 (defcustom message-sendmail-f-is-evil nil
836 "*Non-nil means don't add \"-f username\" to the sendmail command line.
837 Doing so would be even more evil than leaving it out."
838 :group
'message-sending
839 :link
'(custom-manual "(message)Mail Variables")
842 (defcustom message-sendmail-envelope-from
843 ;; Default to the value of `mail-envelope-from' if available.
844 ;; Note: as for Emacsen that Gnus supports, except for SXEmacs, it is
845 ;; unavailable unless sendmail.el is loaded.
846 (if (boundp 'mail-envelope-from
) mail-envelope-from
)
847 "*Envelope-from when sending mail with sendmail.
848 If this is nil, use `user-mail-address'. If it is the symbol
849 `header', use the From: header of the message."
851 :type
'(choice (string :tag
"From name")
852 (const :tag
"Use From: header from message" header
)
853 (const :tag
"Use `user-mail-address'" nil
))
854 :link
'(custom-manual "(message)Mail Variables")
855 :group
'message-sending
)
857 (defcustom message-sendmail-extra-arguments nil
858 "Additional arguments to `sendmail-program'."
859 ;; E.g. '("-a" "account") for msmtp
860 :version
"23.1" ;; No Gnus
861 :type
'(repeat string
)
862 ;; :link '(custom-manual "(message)Mail Variables")
863 :group
'message-sending
)
865 ;; qmail-related stuff
866 (defcustom message-qmail-inject-program
"/var/qmail/bin/qmail-inject"
867 "Location of the qmail-inject program."
868 :group
'message-sending
869 :link
'(custom-manual "(message)Mail Variables")
872 (defcustom message-qmail-inject-args nil
873 "Arguments passed to qmail-inject programs.
874 This should be a list of strings, one string for each argument.
875 It may also be a function.
877 For e.g., if you wish to set the envelope sender address so that bounces
878 go to the right place or to deal with listserv's usage of that address, you
879 might set this variable to '(\"-f\" \"you@some.where\")."
880 :group
'message-sending
881 :link
'(custom-manual "(message)Mail Variables")
882 :type
'(choice (function)
885 (defvar gnus-post-method
)
886 (defvar gnus-select-method
)
887 (defcustom message-post-method
888 (cond ((and (boundp 'gnus-post-method
)
889 (listp gnus-post-method
)
892 ((boundp 'gnus-select-method
)
895 "*Method used to post news.
896 Note that when posting from inside Gnus, for instance, this
897 variable isn't used."
899 :group
'message-sending
900 ;; This should be the `gnus-select-method' widget, but that might
901 ;; create a dependence to `gnus.el'.
904 ;; FIXME: This should be a temporary workaround until someone implements a
905 ;; proper solution. If a crash happens while replying, the auto-save file
906 ;; will *not* have a `References:' header if `message-generate-headers-first'
907 ;; is nil. See: http://article.gmane.org/gmane.emacs.gnus.general/51138
908 (defcustom message-generate-headers-first
'(references)
909 "Which headers should be generated before starting to compose a message.
910 If t, generate all required headers. This can also be a list of headers to
911 generate. The variables `message-required-news-headers' and
912 `message-required-mail-headers' specify which headers to generate.
914 Note that the variable `message-deletable-headers' specifies headers which
915 are to be deleted and then re-generated before sending, so this variable
916 will not have a visible effect for those headers."
917 :group
'message-headers
918 :link
'(custom-manual "(message)Message Headers")
919 :type
'(choice (const :tag
"None" nil
)
920 (const :tag
"References" '(references))
922 (repeat (sexp :tag
"Header"))))
924 (defcustom message-fill-column
72
925 "Column beyond which automatic line-wrapping should happen.
926 Local value for message buffers. If non-nil, also turn on
927 auto-fill in message buffers."
928 :group
'message-various
929 ;; :link '(custom-manual "(message)Message Headers")
930 :type
'(choice (const :tag
"Don't turn on auto fill" nil
)
933 (defcustom message-setup-hook nil
934 "Normal hook, run each time a new outgoing message is initialized.
935 The function `message-setup' runs this hook."
936 :group
'message-various
937 :link
'(custom-manual "(message)Various Message Variables")
940 (defcustom message-cancel-hook nil
941 "Hook run when cancelling articles."
942 :group
'message-various
943 :link
'(custom-manual "(message)Various Message Variables")
946 (defcustom message-signature-setup-hook nil
947 "Normal hook, run each time a new outgoing message is initialized.
948 It is run after the headers have been inserted and before
949 the signature is inserted."
950 :group
'message-various
951 :link
'(custom-manual "(message)Various Message Variables")
954 (defcustom message-mode-hook nil
955 "Hook run in message mode buffers."
956 :group
'message-various
959 (defcustom message-header-hook nil
960 "Hook run in a message mode buffer narrowed to the headers."
961 :group
'message-various
964 (defcustom message-header-setup-hook nil
965 "Hook called narrowed to the headers when setting up a message buffer."
966 :group
'message-various
967 :link
'(custom-manual "(message)Various Message Variables")
970 (defcustom message-minibuffer-local-map
971 (let ((map (make-sparse-keymap 'message-minibuffer-local-map
)))
972 (set-keymap-parent map minibuffer-local-map
)
974 "Keymap for `message-read-from-minibuffer'."
976 :group
'message-various
)
978 (defcustom message-citation-line-function
'message-insert-citation-line
979 "*Function called to insert the \"Whomever writes:\" line.
981 Predefined functions include `message-insert-citation-line' and
982 `message-insert-formatted-citation-line' (see the variable
983 `message-citation-line-format').
985 Note that Gnus provides a feature where the reader can click on
986 `writes:' to hide the cited text. If you change this line too much,
987 people who read your message will have to change their Gnus
988 configuration. See the variable `gnus-cite-attribution-suffix'."
990 (function-item :tag
"plain" message-insert-citation-line
)
991 (function-item :tag
"formatted" message-insert-formatted-citation-line
)
992 (function :tag
"Other"))
993 :link
'(custom-manual "(message)Insertion Variables")
994 :group
'message-insertion
)
996 (defcustom message-citation-line-format
"On %a, %b %d %Y, %N wrote:\n"
997 "Format of the \"Whomever writes:\" line.
999 The string is formatted using `format-spec'. The following
1000 constructs are replaced:
1002 %f The full From, e.g. \"John Doe <john.doe@example.invalid>\".
1003 %n The mail address, e.g. \"john.doe@example.invalid\".
1004 %N The real name if present, e.g.: \"John Doe\", else fall
1005 back to the mail address.
1006 %F The first name if present, e.g.: \"John\".
1007 %L The last name if present, e.g.: \"Doe\".
1009 All other format specifiers are passed to `format-time-string'
1010 which is called using the date from the article your replying to.
1011 Extracting the first (%F) and last name (%L) is done
1012 heuristically, so you should always check it yourself.
1014 Please also read the note in the documentation of
1015 `message-citation-line-function'."
1016 :type
'(choice (const :tag
"Plain" "%f writes:")
1017 (const :tag
"Include date" "On %a, %b %d %Y, %n wrote:")
1019 :link
'(custom-manual "(message)Insertion Variables")
1020 :version
"23.1" ;; No Gnus
1021 :group
'message-insertion
)
1023 (defcustom message-yank-prefix
1024 ;; Default to the value of `mail-yank-prefix' if available.
1025 ;; Note: as for Emacs 21, it is unavailable unless sendmail.el is loaded.
1026 (if (boundp 'mail-yank-prefix
) mail-yank-prefix
"> ")
1027 "*Prefix inserted on the lines of yanked messages.
1028 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1029 See also `message-yank-cited-prefix' and `message-yank-empty-prefix'."
1032 :link
'(custom-manual "(message)Insertion Variables")
1033 :group
'message-insertion
)
1035 (defcustom message-yank-cited-prefix
">"
1036 "*Prefix inserted on cited lines of yanked messages.
1037 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1038 See also `message-yank-prefix' and `message-yank-empty-prefix'."
1041 :link
'(custom-manual "(message)Insertion Variables")
1042 :group
'message-insertion
)
1044 (defcustom message-yank-empty-prefix
">"
1045 "*Prefix inserted on empty lines of yanked messages.
1046 See also `message-yank-prefix' and `message-yank-cited-prefix'."
1049 :link
'(custom-manual "(message)Insertion Variables")
1050 :group
'message-insertion
)
1052 (defcustom message-indentation-spaces
1053 ;; Default to the value of `mail-indentation-spaces' if available.
1054 ;; Note: as for Emacs 21, XEmacs 21.4 and 21.5, it is unavailable
1055 ;; unless sendmail.el is loaded.
1056 (if (boundp 'mail-indentation-spaces
) mail-indentation-spaces
3)
1057 "*Number of spaces to insert at the beginning of each cited line.
1058 Used by `message-yank-original' via `message-yank-cite'."
1060 :group
'message-insertion
1061 :link
'(custom-manual "(message)Insertion Variables")
1064 (defcustom message-cite-function
'message-cite-original-without-signature
1065 "*Function for citing an original message.
1066 Predefined functions include `message-cite-original' and
1067 `message-cite-original-without-signature'.
1068 Note that these functions use `mail-citation-hook' if that is non-nil."
1069 :type
'(radio (function-item message-cite-original
)
1070 (function-item message-cite-original-without-signature
)
1071 (function-item sc-cite-original
)
1072 (function :tag
"Other"))
1073 :link
'(custom-manual "(message)Insertion Variables")
1074 :version
"22.3" ;; Gnus 5.10.12 (changed default)
1075 :group
'message-insertion
)
1077 (defcustom message-indent-citation-function
'message-indent-citation
1078 "*Function for modifying a citation just inserted in the mail buffer.
1079 This can also be a list of functions. Each function can find the
1080 citation between (point) and (mark t). And each function should leave
1081 point and mark around the citation text as modified."
1083 :link
'(custom-manual "(message)Insertion Variables")
1084 :group
'message-insertion
)
1086 (defcustom message-signature mail-signature
1087 ;; Default to the value of `mail-signature', available in all Emacsen
1088 ;; that Gnus supports.
1089 "*String to be inserted at the end of the message buffer.
1090 If t, the `message-signature-file' file will be inserted instead.
1091 If a function, the result from the function will be used instead.
1092 If a form, the result from the form will be used instead."
1095 :link
'(custom-manual "(message)Insertion Variables")
1096 :group
'message-insertion
)
1098 (defcustom message-signature-file
1099 ;; Default to the value of `mail-signature-file' if available.
1100 ;; Note: as for Emacs 21, XEmacs 21.4 and 21.5, it is unavailable
1101 ;; unless sendmail.el is loaded.
1102 (if (boundp 'mail-signature-file
) mail-signature-file
"~/.signature")
1103 "*Name of file containing the text inserted at end of message buffer.
1104 Ignored if the named file doesn't exist.
1105 If nil, don't insert a signature.
1106 If a path is specified, the value of `message-signature-directory' is ignored,
1109 :type
'(choice file
(const :tags
"None" nil
))
1110 :link
'(custom-manual "(message)Insertion Variables")
1111 :group
'message-insertion
)
1113 (defcustom message-signature-directory nil
1114 "*Name of directory containing signature files.
1115 Comes in handy if you have many such files, handled via posting styles for
1117 If nil, `message-signature-file' is expected to specify the directory if
1119 :type
'(choice string
(const :tags
"None" nil
))
1120 :link
'(custom-manual "(message)Insertion Variables")
1121 :group
'message-insertion
)
1123 (defcustom message-signature-insert-empty-line t
1124 "*If non-nil, insert an empty line before the signature separator."
1127 :link
'(custom-manual "(message)Insertion Variables")
1128 :group
'message-insertion
)
1130 (defcustom message-distribution-function nil
1131 "*Function called to return a Distribution header."
1132 :group
'message-news
1133 :group
'message-headers
1134 :link
'(custom-manual "(message)News Headers")
1135 :type
'(choice function
(const nil
)))
1137 (defcustom message-expires
14
1138 "Number of days before your article expires."
1139 :group
'message-news
1140 :group
'message-headers
1141 :link
'(custom-manual "(message)News Headers")
1144 (defcustom message-user-path nil
1145 "If nil, use the NNTP server name in the Path header.
1146 If stringp, use this; if non-nil, use no host name (user name only)."
1147 :group
'message-news
1148 :group
'message-headers
1149 :link
'(custom-manual "(message)News Headers")
1150 :type
'(choice (const :tag
"nntp" nil
)
1151 (string :tag
"name")
1152 (sexp :tag
"none" :format
"%t" t
)))
1154 ;; This can be the name of a buffer, or a cons cell (FUNCTION . ARGS)
1155 ;; for yanking the original buffer.
1156 (defvar message-reply-buffer nil
)
1157 (defvar message-reply-headers nil
1158 "The headers of the current replied article.
1159 It is a vector of the following headers:
1160 \[number subject from date id references chars lines xref extra].")
1161 (defvar message-newsreader nil
)
1162 (defvar message-mailer nil
)
1163 (defvar message-sent-message-via nil
)
1164 (defvar message-checksum nil
)
1165 (defvar message-send-actions nil
1166 "A list of actions to be performed upon successful sending of a message.")
1167 (defvar message-exit-actions nil
1168 "A list of actions to be performed upon exiting after sending a message.")
1169 (defvar message-kill-actions nil
1170 "A list of actions to be performed before killing a message buffer.")
1171 (defvar message-postpone-actions nil
1172 "A list of actions to be performed after postponing a message.")
1174 (define-widget 'message-header-lines
'text
1175 "All header lines must be LFD terminated."
1176 :format
"%{%t%}:%n%v"
1177 :valid-regexp
"^\\'"
1178 :error
"All header lines must be newline terminated")
1180 (defcustom message-default-headers
""
1181 "*A string containing header lines to be inserted in outgoing messages.
1182 It is inserted before you edit the message, so you can edit or delete
1185 :group
'message-headers
1186 :link
'(custom-manual "(message)Message Headers")
1187 :type
'message-header-lines
)
1189 (defcustom message-default-mail-headers
1190 ;; Ease the transition from mail-mode to message-mode. See bugs#4431, 5555.
1191 (concat (if (and (boundp 'mail-default-reply-to
)
1192 (stringp mail-default-reply-to
))
1193 (format "Reply-to: %s\n" mail-default-reply-to
))
1194 (if (and (boundp 'mail-self-blind
)
1196 (format "BCC: %s\n" user-mail-address
))
1197 (if (and (boundp 'mail-archive-file-name
)
1198 (stringp mail-archive-file-name
))
1199 (format "FCC: %s\n" mail-archive-file-name
))
1200 ;; Use the value of `mail-default-headers' if available.
1201 ;; Note: as for Emacs 21, XEmacs 21.4 and 21.5, it is
1202 ;; unavailable unless sendmail.el is loaded.
1203 (if (boundp 'mail-default-headers
)
1204 mail-default-headers
))
1205 "*A string of header lines to be inserted in outgoing mails."
1207 :group
'message-headers
1208 :group
'message-mail
1209 :link
'(custom-manual "(message)Mail Headers")
1210 :type
'message-header-lines
)
1212 (defcustom message-default-news-headers
""
1213 "*A string of header lines to be inserted in outgoing news articles."
1214 :group
'message-headers
1215 :group
'message-news
1216 :link
'(custom-manual "(message)News Headers")
1217 :type
'message-header-lines
)
1219 ;; Note: could use /usr/ucb/mail instead of sendmail;
1220 ;; options -t, and -v if not interactive.
1221 (defcustom message-mailer-swallows-blank-line
1222 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1223 system-configuration
)
1224 (file-readable-p "/etc/sendmail.cf")
1225 (let ((buffer (get-buffer-create " *temp*")))
1227 (with-current-buffer buffer
1228 (insert-file-contents "/etc/sendmail.cf")
1229 (goto-char (point-min))
1230 (let ((case-fold-search nil
))
1231 (re-search-forward "^OR\\>" nil t
)))
1232 (kill-buffer buffer
))))
1233 ;; According to RFC822, "The field-name must be composed of printable
1234 ;; ASCII characters (i. e., characters that have decimal values between
1235 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1237 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1238 "*Set this non-nil if the system's mailer runs the header and body together.
1239 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1240 The value should be an expression to test whether the problem will
1242 :group
'message-sending
1243 :link
'(custom-manual "(message)Mail Variables")
1247 (define-mail-user-agent 'message-user-agent
1248 'message-mail
'message-send-and-exit
1249 'message-kill-buffer
'message-send-hook
)
1251 (defvar message-mh-deletable-headers
'(Message-ID Date Lines Sender
)
1252 "If non-nil, delete the deletable headers before feeding to mh.")
1254 (defvar message-send-method-alist
1255 '((news message-news-p message-send-via-news
)
1256 (mail message-mail-p message-send-via-mail
))
1257 "Alist of ways to send outgoing messages.
1258 Each element has the form
1260 \(TYPE PREDICATE FUNCTION)
1262 where TYPE is a symbol that names the method; PREDICATE is a function
1263 called without any parameters to determine whether the message is
1264 a message of type TYPE; and FUNCTION is a function to be called if
1265 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1268 (defcustom message-mail-alias-type
'abbrev
1269 "*What alias expansion type to use in Message buffers.
1270 The default is `abbrev', which uses mailabbrev. `ecomplete' uses
1271 an electric completion mode. nil switches mail aliases off.
1272 This can also be a list of values."
1274 :link
'(custom-manual "(message)Mail Aliases")
1275 :type
'(choice (const :tag
"Use Mailabbrev" abbrev
)
1276 (const :tag
"Use ecomplete" ecomplete
)
1277 (const :tag
"No expansion" nil
)))
1279 (defcustom message-self-insert-commands
'(self-insert-command)
1280 "List of `self-insert-command's used to trigger ecomplete.
1281 When one of those commands is invoked to enter a character in To or Cc
1282 header, ecomplete will suggest the candidates of recipients (see also
1283 `message-mail-alias-type'). If you use some tool to enter non-ASCII
1284 text and it replaces `self-insert-command' with the other command, e.g.
1285 `egg-self-insert-command', you may want to add it to this list."
1286 :group
'message-various
1287 :type
'(repeat function
))
1289 (defcustom message-auto-save-directory
1290 (file-name-as-directory (expand-file-name "drafts" message-directory
))
1291 "*Directory where Message auto-saves buffers if Gnus isn't running.
1292 If nil, Message won't auto-save."
1293 :group
'message-buffers
1294 :link
'(custom-manual "(message)Various Message Variables")
1295 :type
'(choice directory
(const :tag
"Don't auto-save" nil
)))
1297 (defcustom message-default-charset
1298 (and (not (mm-multibyte-p)) 'iso-8859-1
)
1299 "Default charset used in non-MULE Emacsen.
1300 If nil, you might be asked to input the charset."
1303 :link
'(custom-manual "(message)Various Message Variables")
1306 (defcustom message-dont-reply-to-names
1307 (and (boundp 'rmail-dont-reply-to-names
) rmail-dont-reply-to-names
)
1308 "*Addresses to prune when doing wide replies.
1309 This can be a regexp or a list of regexps. Also, a value of nil means
1310 exclude your own user name only."
1313 :link
'(custom-manual "(message)Wide Reply")
1314 :type
'(choice (const :tag
"Yourself" nil
)
1316 (repeat :tag
"Regexp List" regexp
)))
1318 (defsubst message-dont-reply-to-names
()
1319 (gmm-regexp-concat message-dont-reply-to-names
))
1321 (defvar message-shoot-gnksa-feet nil
1322 "*A list of GNKSA feet you are allowed to shoot.
1323 Gnus gives you all the opportunity you could possibly want for
1324 shooting yourself in the foot. Also, Gnus allows you to shoot the
1325 feet of Good Net-Keeping Seal of Approval. The following are foot
1327 `empty-article' Allow you to post an empty article;
1328 `quoted-text-only' Allow you to post quoted text only;
1329 `multiple-copies' Allow you to post multiple copies;
1330 `cancel-messages' Allow you to cancel or supersede messages from
1331 your other email addresses.")
1333 (defsubst message-gnksa-enable-p
(feature)
1334 (or (not (listp message-shoot-gnksa-feet
))
1335 (memq feature message-shoot-gnksa-feet
)))
1337 (defcustom message-hidden-headers
'("^References:" "^Face:" "^X-Face:"
1339 "Regexp of headers to be hidden when composing new messages.
1340 This can also be a list of regexps to match headers. Or a list
1341 starting with `not' and followed by regexps."
1344 :link
'(custom-manual "(message)Message Headers")
1346 :format
"%{%t%}: %[Value Type%] %v"
1347 (regexp :menu-tag
"regexp" :format
"regexp\n%t: %v")
1348 (repeat :menu-tag
"(regexp ...)" :format
"(regexp ...)\n%v%i"
1349 (regexp :format
"%t: %v"))
1350 (cons :menu-tag
"(not regexp ...)" :format
"(not regexp ...)\n%v"
1352 (repeat :format
"%v%i"
1353 (regexp :format
"%t: %v")))))
1355 (defcustom message-cite-articles-with-x-no-archive t
1356 "If non-nil, cite text from articles that has X-No-Archive set."
1360 ;;; Internal variables.
1361 ;;; Well, not really internal.
1363 (defvar message-mode-syntax-table
1364 (let ((table (copy-syntax-table text-mode-syntax-table
)))
1365 (modify-syntax-entry ?%
". " table
)
1366 (modify-syntax-entry ?
> ". " table
)
1367 (modify-syntax-entry ?
< ". " table
)
1369 "Syntax table used while in Message mode.")
1371 (defface message-header-to
1374 (:foreground
"DarkOliveGreen1" :bold t
))
1377 (:foreground
"MidnightBlue" :bold t
))
1379 (:bold t
:italic t
)))
1380 "Face used for displaying From headers."
1381 :group
'message-faces
)
1382 ;; backward-compatibility alias
1383 (put 'message-header-to-face
'face-alias
'message-header-to
)
1384 (put 'message-header-to-face
'obsolete-face
"22.1")
1386 (defface message-header-cc
1389 (:foreground
"chartreuse1" :bold t
))
1392 (:foreground
"MidnightBlue"))
1395 "Face used for displaying Cc headers."
1396 :group
'message-faces
)
1397 ;; backward-compatibility alias
1398 (put 'message-header-cc-face
'face-alias
'message-header-cc
)
1399 (put 'message-header-cc-face
'obsolete-face
"22.1")
1401 (defface message-header-subject
1404 (:foreground
"OliveDrab1"))
1407 (:foreground
"navy blue" :bold t
))
1410 "Face used for displaying subject headers."
1411 :group
'message-faces
)
1412 ;; backward-compatibility alias
1413 (put 'message-header-subject-face
'face-alias
'message-header-subject
)
1414 (put 'message-header-subject-face
'obsolete-face
"22.1")
1416 (defface message-header-newsgroups
1419 (:foreground
"yellow" :bold t
:italic t
))
1422 (:foreground
"blue4" :bold t
:italic t
))
1424 (:bold t
:italic t
)))
1425 "Face used for displaying newsgroups headers."
1426 :group
'message-faces
)
1427 ;; backward-compatibility alias
1428 (put 'message-header-newsgroups-face
'face-alias
'message-header-newsgroups
)
1429 (put 'message-header-newsgroups-face
'obsolete-face
"22.1")
1431 (defface message-header-other
1434 (:foreground
"VioletRed1"))
1437 (:foreground
"steel blue"))
1439 (:bold t
:italic t
)))
1440 "Face used for displaying newsgroups headers."
1441 :group
'message-faces
)
1442 ;; backward-compatibility alias
1443 (put 'message-header-other-face
'face-alias
'message-header-other
)
1444 (put 'message-header-other-face
'obsolete-face
"22.1")
1446 (defface message-header-name
1449 (:foreground
"green"))
1452 (:foreground
"cornflower blue"))
1455 "Face used for displaying header names."
1456 :group
'message-faces
)
1457 ;; backward-compatibility alias
1458 (put 'message-header-name-face
'face-alias
'message-header-name
)
1459 (put 'message-header-name-face
'obsolete-face
"22.1")
1461 (defface message-header-xheader
1464 (:foreground
"DeepSkyBlue1"))
1467 (:foreground
"blue"))
1470 "Face used for displaying X-Header headers."
1471 :group
'message-faces
)
1472 ;; backward-compatibility alias
1473 (put 'message-header-xheader-face
'face-alias
'message-header-xheader
)
1474 (put 'message-header-xheader-face
'obsolete-face
"22.1")
1476 (defface message-separator
1479 (:foreground
"LightSkyBlue1"))
1482 (:foreground
"brown"))
1485 "Face used for displaying the separator."
1486 :group
'message-faces
)
1487 ;; backward-compatibility alias
1488 (put 'message-separator-face
'face-alias
'message-separator
)
1489 (put 'message-separator-face
'obsolete-face
"22.1")
1491 (defface message-cited-text
1494 (:foreground
"LightPink1"))
1497 (:foreground
"red"))
1500 "Face used for displaying cited text names."
1501 :group
'message-faces
)
1502 ;; backward-compatibility alias
1503 (put 'message-cited-text-face
'face-alias
'message-cited-text
)
1504 (put 'message-cited-text-face
'obsolete-face
"22.1")
1506 (defface message-mml
1509 (:foreground
"MediumSpringGreen"))
1512 (:foreground
"ForestGreen"))
1515 "Face used for displaying MML."
1516 :group
'message-faces
)
1517 ;; backward-compatibility alias
1518 (put 'message-mml-face
'face-alias
'message-mml
)
1519 (put 'message-mml-face
'obsolete-face
"22.1")
1521 (defun message-font-lock-make-header-matcher (regexp)
1524 (let ((start (point)))
1527 (goto-char (point-min))
1528 (if (re-search-forward
1529 (concat "^" (regexp-quote mail-header-separator
) "$")
1531 (setq limit
(min limit
(match-beginning 0))))
1533 (and (< start limit
)
1534 (re-search-forward ,regexp limit t
))))))
1535 (if (featurep 'bytecomp
)
1539 (defvar message-font-lock-keywords
1540 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1541 `((,(message-font-lock-make-header-matcher
1542 (concat "^\\([Tt]o:\\)" content
))
1543 (1 'message-header-name
)
1544 (2 'message-header-to nil t
))
1545 (,(message-font-lock-make-header-matcher
1546 (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content
))
1547 (1 'message-header-name
)
1548 (2 'message-header-cc nil t
))
1549 (,(message-font-lock-make-header-matcher
1550 (concat "^\\([Ss]ubject:\\)" content
))
1551 (1 'message-header-name
)
1552 (2 'message-header-subject nil t
))
1553 (,(message-font-lock-make-header-matcher
1554 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content
))
1555 (1 'message-header-name
)
1556 (2 'message-header-newsgroups nil t
))
1557 (,(message-font-lock-make-header-matcher
1558 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content
))
1559 (1 'message-header-name
)
1560 (2 'message-header-xheader
))
1561 (,(message-font-lock-make-header-matcher
1562 (concat "^\\([A-Z][^: \n\t]+:\\)" content
))
1563 (1 'message-header-name
)
1564 (2 'message-header-other nil t
))
1565 ,@(if (and mail-header-separator
1566 (not (equal mail-header-separator
"")))
1567 `((,(concat "^\\(" (regexp-quote mail-header-separator
) "\\)$")
1568 1 'message-separator
))
1571 (re-search-forward (concat "^\\("
1572 message-cite-prefix-regexp
1575 (0 'message-cited-text
))
1576 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1578 "Additional expressions to highlight in Message mode.")
1581 ;; XEmacs does it like this. For Emacs, we have to set the
1582 ;; `font-lock-defaults' buffer-local variable.
1583 (put 'message-mode
'font-lock-defaults
'(message-font-lock-keywords t
))
1585 (defvar message-face-alist
1586 '((bold . message-bold-region
)
1587 (underline . underline-region
)
1588 (default .
(lambda (b e
)
1589 (message-unbold-region b e
)
1590 (ununderline-region b e
))))
1591 "Alist of mail and news faces for facemenu.
1592 The cdr of each entry is a function for applying the face to a region.")
1594 (defcustom message-send-hook nil
1595 "Hook run before sending messages.
1596 This hook is run quite early when sending."
1597 :group
'message-various
1598 :options
'(ispell-message)
1599 :link
'(custom-manual "(message)Various Message Variables")
1602 (defcustom message-send-mail-hook nil
1603 "Hook run before sending mail messages.
1604 This hook is run very late -- just before the message is sent as
1606 :group
'message-various
1607 :link
'(custom-manual "(message)Various Message Variables")
1610 (defcustom message-send-news-hook nil
1611 "Hook run before sending news messages.
1612 This hook is run very late -- just before the message is sent as
1614 :group
'message-various
1615 :link
'(custom-manual "(message)Various Message Variables")
1618 (defcustom message-sent-hook nil
1619 "Hook run after sending messages."
1620 :group
'message-various
1623 (defvar message-send-coding-system
'binary
1624 "Coding system to encode outgoing mail.")
1626 (defvar message-draft-coding-system
1627 mm-auto-save-coding-system
1628 "*Coding system to compose mail.
1629 If you'd like to make it possible to share draft files between XEmacs
1630 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1631 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1633 (defcustom message-send-mail-partially-limit nil
1634 "The limitation of messages sent as message/partial.
1635 The lower bound of message size in characters, beyond which the message
1636 should be sent in several parts. If it is nil, the size is unlimited."
1638 :group
'message-buffers
1639 :link
'(custom-manual "(message)Mail Variables")
1640 :type
'(choice (const :tag
"unlimited" nil
)
1643 (defcustom message-alternative-emails nil
1644 "*Regexp matching alternative email addresses.
1645 The first address in the To, Cc or From headers of the original
1646 article matching this variable is used as the From field of
1649 This variable has precedence over posting styles and anything that runs
1650 off `message-setup-hook'."
1651 :group
'message-headers
1652 :link
'(custom-manual "(message)Message Headers")
1653 :type
'(choice (const :tag
"Always use primary" nil
)
1656 (defcustom message-hierarchical-addresses nil
1657 "A list of hierarchical mail address definitions.
1659 Inside each entry, the first address is the \"top\" address, and
1660 subsequent addresses are subaddresses; this is used to indicate that
1661 mail sent to the first address will automatically be delivered to the
1662 subaddresses. So if the first address appears in the recipient list
1663 for a message, the subaddresses will be removed (if present) before
1664 the mail is sent. All addresses in this structure should be
1667 :group
'message-headers
1668 :type
'(repeat (repeat string
)))
1670 (defcustom message-mail-user-agent nil
1671 "Like `mail-user-agent'.
1672 Except if it is nil, use Gnus native MUA; if it is t, use
1675 :type
'(radio (const :tag
"Gnus native"
1678 (const :tag
"`mail-user-agent'"
1681 (function-item :tag
"Default Emacs mail"
1683 sendmail-user-agent
)
1684 (function-item :tag
"Emacs interface to MH"
1687 (function :tag
"Other"))
1691 (defcustom message-wide-reply-confirm-recipients nil
1692 "Whether to confirm a wide reply to multiple email recipients.
1693 If this variable is nil, don't ask whether to reply to all recipients.
1694 If this variable is non-nil, pose the question \"Reply to all
1695 recipients?\" before a wide reply to multiple recipients. If the user
1696 answers yes, reply to all recipients as usual. If the user answers
1697 no, only reply back to the author."
1699 :group
'message-headers
1700 :link
'(custom-manual "(message)Wide Reply")
1703 (defcustom message-user-fqdn nil
1704 "*Domain part of Message-Ids."
1706 :group
'message-headers
1707 :link
'(custom-manual "(message)News Headers")
1708 :type
'(radio (const :format
"%v " nil
)
1709 (string :format
"FQDN: %v")))
1711 (defcustom message-use-idna
(and (condition-case nil
(require 'idna
)
1713 (mm-coding-system-p 'utf-8
)
1714 (executable-find idna-program
)
1715 (string= (idna-to-ascii "räksmörgås")
1716 "xn--rksmrgs-5wao1o")
1718 "Whether to encode non-ASCII in domain names into ASCII according to IDNA.
1719 GNU Libidn, and in particular the elisp package \"idna.el\" and
1720 the external program \"idn\", must be installed for this
1721 functionality to work."
1723 :group
'message-headers
1724 :link
'(custom-manual "(message)IDNA")
1725 :type
'(choice (const :tag
"Ask" ask
)
1726 (const :tag
"Never" nil
)
1727 (const :tag
"Always" t
)))
1729 (defcustom message-generate-hashcash
(if (executable-find "hashcash") 'opportunistic
)
1730 "*Whether to generate X-Hashcash: headers.
1731 If t, always generate hashcash headers. If `opportunistic',
1732 only generate hashcash headers if it can be done without the user
1733 waiting (i.e., only asynchronously).
1735 You must have the \"hashcash\" binary installed, see `hashcash-path'."
1737 :group
'message-headers
1738 :link
'(custom-manual "(message)Mail Headers")
1739 :type
'(choice (const :tag
"Always" t
)
1740 (const :tag
"Never" nil
)
1741 (const :tag
"Opportunistic" opportunistic
)))
1743 ;;; Internal variables.
1745 (defvar message-sending-message
"Sending...")
1746 (defvar message-buffer-list nil
)
1747 (defvar message-this-is-news nil
)
1748 (defvar message-this-is-mail nil
)
1749 (defvar message-draft-article nil
)
1750 (defvar message-mime-part nil
)
1751 (defvar message-posting-charset nil
)
1752 (defvar message-inserted-headers nil
)
1753 (defvar message-inhibit-ecomplete nil
)
1755 ;; Byte-compiler warning
1756 (defvar gnus-active-hashtb
)
1757 (defvar gnus-read-active-file
)
1759 ;;; Regexp matching the delimiter of messages in UNIX mail format
1760 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1761 ;;; of rmail.el's rmail-unix-mail-delimiter.
1762 (defvar message-unix-mail-delimiter
1763 (let ((time-zone-regexp
1764 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1765 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1771 ;; Many things can happen to an RFC 822 mailbox before it is put into
1772 ;; a `From' line. The leading phrase can be stripped, e.g.
1773 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1774 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1775 ;; can be removed, e.g.
1776 ;; From: joe@y.z (Joe K
1778 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1781 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1782 ;; The mailbox can be removed or be replaced by white space, e.g.
1783 ;; From: "Joe User"{space}{tab}
1785 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1786 ;; where {space} and {tab} represent the Ascii space and tab characters.
1787 ;; We want to match the results of any of these manglings.
1788 ;; The following regexp rejects names whose first characters are
1789 ;; obviously bogus, but after that anything goes.
1790 "\\([^\0-\b\n-\r\^?].*\\)?"
1792 ;; The time the message was sent.
1793 "\\([^\0-\r \^?]+\\) +" ; day of the week
1794 "\\([^\0-\r \^?]+\\) +" ; month
1795 "\\([0-3]?[0-9]\\) +" ; day of month
1796 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1798 ;; Perhaps a time zone, specified by an abbreviation, or by a
1803 " \\([0-9][0-9]+\\) *"
1805 ;; On some systems the time zone can appear after the year, too.
1809 "\\(remote from .*\\)?"
1812 "Regexp matching the delimiter of messages in UNIX mail format.")
1814 (defvar message-unsent-separator
1815 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1816 "^ *---+ +Returned message +---+ *$\\|"
1817 "^Start of returned message$\\|"
1818 "^ *---+ +Original message +---+ *$\\|"
1819 "^ *--+ +begin message +--+ *$\\|"
1820 "^ *---+ +Original message follows +---+ *$\\|"
1821 "^ *---+ +Undelivered message follows +---+ *$\\|"
1822 "^------ This is a copy of the message, including all the headers. ------ *$\\|"
1823 "^|? *---+ +Message text follows: +---+ *|?$")
1824 "A regexp that matches the separator before the text of a failed message.")
1826 (defvar message-field-fillers
1827 '((To message-fill-field-address
)
1828 (Cc message-fill-field-address
)
1829 (From message-fill-field-address
))
1830 "Alist of header names/filler functions.")
1832 (defvar message-header-format-alist
1847 (References . message-shorten-references
)
1849 "Alist used for formatting headers.")
1851 (defvar message-options nil
1852 "Some saved answers when sending message.")
1854 (defvar message-send-mail-real-function nil
1855 "Internal send mail function.")
1857 (defvar message-bogus-system-names
"^localhost\\.\\|\\.local$"
1858 "The regexp of bogus system names.")
1860 (defcustom message-valid-fqdn-regexp
1861 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1863 "\\([a-z][a-z]\\|" ;; two letter country TDLs
1864 "aero\\|arpa\\|bitnet\\|biz\\|bofh\\|"
1865 "cat\\|com\\|coop\\|edu\\|gov\\|"
1866 "info\\|int\\|jobs\\|"
1867 "mil\\|mobi\\|museum\\|name\\|net\\|"
1868 "org\\|pro\\|travel\\|uucp\\)")
1869 ;; http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains
1870 ;; http://en.wikipedia.org/wiki/GTLD
1871 ;; `in the process of being approved': .asia .post .tel .sex
1872 ;; "dead" nato bitnet uucp
1873 "Regular expression that matches a valid FQDN."
1874 ;; see also: gnus-button-valid-fqdn-regexp
1876 :group
'message-headers
1879 (autoload 'gnus-alive-p
"gnus-util")
1880 (autoload 'gnus-delay-article
"gnus-delay")
1881 (autoload 'gnus-extract-address-components
"gnus-util")
1882 (autoload 'gnus-find-method-for-group
"gnus")
1883 (autoload 'gnus-group-decoded-name
"gnus-group")
1884 (autoload 'gnus-group-name-charset
"gnus-group")
1885 (autoload 'gnus-group-name-decode
"gnus-group")
1886 (autoload 'gnus-groups-from-server
"gnus")
1887 (autoload 'gnus-make-local-hook
"gnus-util")
1888 (autoload 'gnus-open-server
"gnus-int")
1889 (autoload 'gnus-output-to-mail
"gnus-util")
1890 (autoload 'gnus-output-to-rmail
"gnus-util")
1891 (autoload 'gnus-request-post
"gnus-int")
1892 (autoload 'gnus-select-frame-set-input-focus
"gnus-util")
1893 (autoload 'gnus-server-string
"gnus")
1894 (autoload 'idna-to-ascii
"idna")
1895 (autoload 'message-setup-toolbar
"messagexmas")
1896 (autoload 'mh-new-draft-name
"mh-comp")
1897 (autoload 'mh-send-letter
"mh-comp")
1898 (autoload 'nndraft-request-associate-buffer
"nndraft")
1899 (autoload 'nndraft-request-expire-articles
"nndraft")
1900 (autoload 'nnvirtual-find-group-art
"nnvirtual")
1901 (autoload 'rmail-dont-reply-to
"mail-utils")
1902 (autoload 'rmail-msg-is-pruned
"rmail")
1903 (autoload 'rmail-output
"rmailout")
1908 ;;; Utility functions.
1911 (defmacro message-y-or-n-p
(question show
&rest text
)
1912 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1913 `(message-talkative-question 'y-or-n-p
,question
,show
,@text
))
1915 (defmacro message-delete-line
(&optional n
)
1916 "Delete the current line (and the next N lines)."
1917 `(delete-region (progn (beginning-of-line) (point))
1918 (progn (forward-line ,(or n
1)) (point))))
1920 (defun message-mark-active-p ()
1921 "Non-nil means the mark and region are currently active in this buffer."
1924 (defun message-unquote-tokens (elems)
1925 "Remove double quotes (\") from strings in list ELEMS."
1926 (mapcar (lambda (item)
1927 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item
)
1928 (setq item
(concat (match-string 1 item
)
1929 (match-string 2 item
))))
1933 (defun message-tokenize-header (header &optional separator
)
1934 "Split HEADER into a list of header elements.
1935 SEPARATOR is a string of characters to be used as separators. \",\"
1936 is used by default."
1939 (let ((regexp (format "[%s]+" (or separator
",")))
1941 beg quoted elems paren
)
1943 (mm-enable-multibyte)
1944 (setq beg
(point-min))
1946 (goto-char (point-min))
1951 (cond ((and (> (point) beg
)
1953 (and (looking-at regexp
)
1956 (push (buffer-substring beg
(point)) elems
)
1957 (setq beg
(match-end 0)))
1958 ((eq (char-after) ?
\")
1959 (setq quoted
(not quoted
)))
1960 ((and (eq (char-after) ?\
()
1963 ((and (eq (char-after) ?\
))
1966 (nreverse elems
)))))
1968 (autoload 'nnheader-insert-file-contents
"nnheader")
1970 (defun message-mail-file-mbox-p (file)
1971 "Say whether FILE looks like a Unix mbox file."
1972 (when (and (file-exists-p file
)
1973 (file-readable-p file
)
1974 (file-regular-p file
))
1976 (nnheader-insert-file-contents file
)
1977 (goto-char (point-min))
1978 (looking-at message-unix-mail-delimiter
))))
1980 (defun message-fetch-field (header &optional not-all
)
1981 "The same as `mail-fetch-field', only remove all newlines.
1982 The buffer is expected to be narrowed to just the header of the message;
1983 see `message-narrow-to-headers-or-head'."
1984 (let* ((inhibit-point-motion-hooks t
)
1985 (value (mail-fetch-field header nil
(not not-all
))))
1987 (while (string-match "\n[\t ]+" value
)
1988 (setq value
(replace-match " " t t value
)))
1991 (defun message-field-value (header &optional not-all
)
1992 "The same as `message-fetch-field', only narrow to the headers first."
1995 (message-narrow-to-headers-or-head)
1996 (message-fetch-field header not-all
))))
1998 (defun message-narrow-to-field ()
1999 "Narrow the buffer to the header on the current line."
2001 (while (looking-at "[ \t]")
2007 (if (re-search-forward "^[^ \n\t]" nil t
)
2010 (goto-char (point-min)))
2012 (defun message-add-header (&rest headers
)
2013 "Add the HEADERS to the message header, skipping those already present."
2016 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers
))
2017 (error "Invalid header `%s'" (car headers
)))
2018 (setq hclean
(match-string 1 (car headers
)))
2020 (message-narrow-to-headers)
2021 (unless (re-search-forward (concat "^" (regexp-quote hclean
) ":") nil t
)
2022 (goto-char (point-max))
2023 (if (string-match "\n$" (car headers
))
2024 (insert (car headers
))
2025 (insert (car headers
) ?
\n)))))
2026 (setq headers
(cdr headers
))))
2028 (defmacro message-with-reply-buffer
(&rest forms
)
2029 "Evaluate FORMS in the reply buffer, if it exists."
2030 `(when (and (bufferp message-reply-buffer
)
2031 (buffer-name message-reply-buffer
))
2032 (with-current-buffer message-reply-buffer
2035 (put 'message-with-reply-buffer
'lisp-indent-function
0)
2036 (put 'message-with-reply-buffer
'edebug-form-spec
'(body))
2038 (defun message-fetch-reply-field (header)
2039 "Fetch field HEADER from the message we're replying to."
2040 (message-with-reply-buffer
2042 (mail-narrow-to-head)
2043 (message-fetch-field header
))))
2045 (defun message-strip-list-identifiers (subject)
2046 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
2047 (require 'gnus-sum
) ; for gnus-list-identifiers
2048 (let ((regexp (if (stringp gnus-list-identifiers
)
2049 gnus-list-identifiers
2050 (mapconcat 'identity gnus-list-identifiers
" *\\|"))))
2051 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
2052 " *\\)\\)+\\(Re: +\\)?\\)") subject
)
2053 (concat (substring subject
0 (match-beginning 1))
2054 (or (match-string 3 subject
)
2055 (match-string 5 subject
))
2060 (defun message-strip-subject-re (subject)
2061 "Remove \"Re:\" from subject lines in string SUBJECT."
2062 (if (string-match message-subject-re-regexp subject
)
2063 (substring subject
(match-end 0))
2066 (defcustom message-replacement-char
"."
2067 "Replacement character used instead of unprintable or not decodable chars."
2068 :group
'message-various
2069 :version
"22.1" ;; Gnus 5.10.9
2070 :type
'(choice string
2074 ;; FIXME: We also should call `message-strip-subject-encoded-words'
2075 ;; when forwarding. Probably in `message-make-forward-subject' and
2076 ;; `message-forward-make-body'.
2078 (defun message-strip-subject-encoded-words (subject)
2079 "Fix non-decodable words in SUBJECT."
2080 ;; Cf. `gnus-simplify-subject-fully'.
2081 (let* ((case-fold-search t
)
2082 (replacement-chars (format "[%s%s%s]"
2083 message-replacement-char
2084 message-replacement-char
2085 message-replacement-char
))
2086 (enc-word-re "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?\\([^?]+\\)\\(\\?=\\)")
2091 (goto-char (point-min))
2092 (when (re-search-forward enc-word-re nil t
)
2093 (setq cs-string
(match-string 1)))))
2094 cs-coding q-or-b word-beg word-end
)
2095 (if (or (not have-marker
) ;; No encoded word found...
2096 ;; ... or double encoding was correct:
2097 (and (stringp cs-string
)
2098 (setq cs-string
(downcase cs-string
))
2099 (mm-coding-system-p (intern cs-string
))
2103 Decoded Subject \"%s\"
2104 contains a valid encoded word. Decode again? "
2106 (setq cs-coding
(intern cs-string
))))))
2110 (goto-char (point-min))
2111 (while (re-search-forward enc-word-re nil t
)
2112 (setq cs-string
(downcase (match-string 1))
2113 q-or-b
(match-string 2)
2114 word-beg
(match-beginning 0)
2115 word-end
(match-end 0))
2117 (if (mm-coding-system-p (intern cs-string
))
2118 (setq cs-coding
(intern cs-string
))
2120 ;; No double encoded subject? => bogus charset.
2123 (mm-read-coding-system
2125 Decoded Subject \"%s\"
2126 contains an encoded word. The charset `%s' is unknown or invalid.
2127 Hit RET to replace non-decodable characters with \"%s\" or enter replacement
2129 subject cs-string message-replacement-char
)))
2131 (replace-match (concat "=?" (symbol-name cs-coding
)
2134 (goto-char word-beg
)
2135 (re-search-forward "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?" word-end t
)
2138 (if (string-match "\\`Q\\'" q-or-b
)
2141 (message "Replacing non-decodable characters with \"%s\"."
2142 message-replacement-char
)
2143 (while (re-search-forward "\\(=[A-F0-9][A-F0-9]\\)+"
2145 (replace-match message-replacement-char
)))
2147 (message "Replacing non-decodable characters with \"%s\"."
2149 (re-search-forward "[^?]+" word-end t
)
2150 (replace-match replacement-chars
))
2151 (re-search-forward "\\?=")
2152 (replace-match "")))))
2153 (rfc2047-decode-region (point-min) (point-max))
2156 ;;; Start of functions adopted from `message-utils.el'.
2158 (defun message-strip-subject-trailing-was (subject)
2159 "Remove trailing \"(was: <old subject>)\" from SUBJECT lines.
2160 Leading \"Re: \" is not stripped by this function. Use the function
2161 `message-strip-subject-re' for this."
2162 (let* ((query message-subject-trailing-was-query
)
2167 message-subject-trailing-was-ask-regexp
2168 message-subject-trailing-was-regexp
)
2171 (setq new
(substring subject
0 (match-beginning 0))))
2172 (if (or (not found
) (eq query nil
))
2175 (if (message-y-or-n-p
2176 "Strip `(was: <old subject>)' in subject? " t
2178 "Strip `(was: <old subject>)' in subject "
2179 "and use the new one instead?\n\n"
2180 "Current subject is: \""
2182 "New subject would be: \""
2184 "See the variable `message-subject-trailing-was-query' "
2185 "to get rid of this query."
2190 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
2192 (defun message-change-subject (new-subject)
2193 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
2194 ;; <URL:http://www.landfield.com/usefor/drafts/draft-ietf-usefor-useage--1.02.unpaged>
2197 (read-from-minibuffer "New subject: ")))
2198 (cond ((and (not (or (null new-subject
) ; new subject not empty
2199 (zerop (string-width new-subject
))
2200 (string-match "^[ \t]*$" new-subject
))))
2204 (message-narrow-to-headers)
2205 (message-fetch-field "Subject"))))
2206 (cond ((not old-subject
)
2207 (error "No current subject"))
2210 (regexp-quote new-subject
)
2212 old-subject
)) ; yes, it really is a new subject
2213 ;; delete eventual Re: prefix
2215 (message-strip-subject-re old-subject
))
2216 (message-goto-subject)
2217 (message-delete-line)
2218 (insert (concat "Subject: "
2221 old-subject
")\n")))))))))
2223 (defun message-mark-inserted-region (beg end
&optional verbatim
)
2224 "Mark some region in the current article with enclosing tags.
2225 See `message-mark-insert-begin' and `message-mark-insert-end'.
2226 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2227 (interactive "r\nP")
2229 ;; add to the end of the region first, otherwise end would be invalid
2231 (insert (if verbatim
"#v-\n" message-mark-insert-end
))
2233 (insert (if verbatim
"#v+\n" message-mark-insert-begin
))))
2235 (defun message-mark-insert-file (file &optional verbatim
)
2236 "Insert FILE at point, marking it with enclosing tags.
2237 See `message-mark-insert-begin' and `message-mark-insert-end'.
2238 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2239 (interactive "fFile to insert: \nP")
2240 ;; reverse insertion to get correct result.
2242 (insert (if verbatim
"#v-\n" message-mark-insert-end
))
2244 (insert-file-contents file
)
2246 (insert (if verbatim
"#v+\n" message-mark-insert-begin
))))
2248 (defun message-add-archive-header ()
2249 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
2250 The note can be customized using `message-archive-note'. When called with a
2251 prefix argument, ask for a text to insert. If you don't want the note in the
2252 body, set `message-archive-note' to nil."
2254 (if current-prefix-arg
2255 (setq message-archive-note
2256 (read-from-minibuffer "Reason for No-Archive: "
2257 (cons message-archive-note
0))))
2259 (if (message-goto-signature)
2260 (re-search-backward message-signature-separator
))
2261 (when message-archive-note
2262 (insert message-archive-note
)
2264 (message-add-header message-archive-header
)
2265 (message-sort-headers)))
2267 (defun message-cross-post-followup-to-header (target-group)
2268 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
2269 With prefix-argument just set Follow-Up, don't cross-post."
2271 (list ; Completion based on Gnus
2272 (completing-read "Followup To: "
2273 (if (boundp 'gnus-newsrc-alist
)
2275 nil nil
'("poster" .
0)
2276 (if (boundp 'gnus-group-history
)
2277 'gnus-group-history
))))
2278 (message-remove-header "Follow[Uu]p-[Tt]o" t
)
2279 (message-goto-newsgroups)
2281 ;; if we already did a crosspost before, kill old target
2282 (if (and message-cross-post-old-target
2284 (regexp-quote (concat "," message-cross-post-old-target
))
2287 ;; unless (followup is to poster or user explicitly asked not
2288 ;; to cross-post, or target-group is already in Newsgroups)
2289 ;; add target-group to Newsgroups line.
2291 ;; def: cross-post, req:no
2292 (and message-cross-post-default
(not current-prefix-arg
))
2293 ;; def: no-cross-post, req:yes
2294 (and (not message-cross-post-default
) current-prefix-arg
))
2295 (not (string-match "poster" target-group
))
2296 (not (string-match (regexp-quote target-group
)
2297 (message-fetch-field "Newsgroups"))))
2299 (insert (concat "," target-group
))))
2300 (end-of-line) ; ensure Followup: comes after Newsgroups:
2301 ;; unless new followup would be identical to Newsgroups line
2302 ;; make a new Followup-To line
2303 (if (not (string-match (concat "^[ \t]*"
2306 (message-fetch-field "Newsgroups")))
2307 (insert (concat "\nFollowup-To: " target-group
)))
2308 (setq message-cross-post-old-target target-group
))
2310 (defun message-cross-post-insert-note (target-group cross-post in-old
2312 "Insert a in message body note about a set Followup or Crosspost.
2313 If there have been previous notes, delete them. TARGET-GROUP specifies the
2314 group to Followup-To. When CROSS-POST is t, insert note about
2315 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
2316 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
2317 been made to before the user asked for a Crosspost."
2318 ;; start scanning body for previous uses
2319 (message-goto-signature)
2320 (let ((head (re-search-backward
2321 (concat "^" mail-header-separator
)
2322 nil t
))) ; just search in body
2323 (message-goto-signature)
2324 (while (re-search-backward
2325 (concat "^" (regexp-quote message-cross-post-note
) ".*")
2327 (message-delete-line))
2328 (message-goto-signature)
2329 (while (re-search-backward
2330 (concat "^" (regexp-quote message-followup-to-note
) ".*")
2332 (message-delete-line))
2334 (if (message-goto-signature)
2335 (re-search-backward message-signature-separator
))
2338 (string-match "^[ \t]*poster[ \t]*$" target-group
))
2339 (insert (concat message-followup-to-note target-group
"\n"))
2340 (insert (concat message-cross-post-note target-group
"\n")))))
2342 (defun message-cross-post-followup-to (target-group)
2343 "Crossposts message and set Followup-To to TARGET-GROUP.
2344 With prefix-argument just set Follow-Up, don't cross-post."
2346 (list ; Completion based on Gnus
2347 (completing-read "Followup To: "
2348 (if (boundp 'gnus-newsrc-alist
)
2350 nil nil
'("poster" .
0)
2351 (if (boundp 'gnus-group-history
)
2352 'gnus-group-history
))))
2353 (cond ((not (or (null target-group
) ; new subject not empty
2354 (zerop (string-width target-group
))
2355 (string-match "^[ \t]*$" target-group
)))
2357 (let* ((old-groups (message-fetch-field "Newsgroups"))
2358 (in-old (string-match
2359 (regexp-quote target-group
)
2360 (or old-groups
""))))
2361 ;; check whether target exactly matches old Newsgroups
2362 (cond ((not old-groups
)
2363 (error "No current newsgroup"))
2367 (regexp-quote target-group
)
2370 ;; yes, Newsgroups line must change
2371 (message-cross-post-followup-to-header target-group
)
2372 ;; insert note whether we do cross-post or followup-to
2373 (funcall message-cross-post-note-function
2375 (if (or (and message-cross-post-default
2376 (not current-prefix-arg
))
2377 (and (not message-cross-post-default
)
2378 current-prefix-arg
)) t
)
2379 in-old old-groups
))))))))
2381 ;;; Reduce To: to Cc: or Bcc: header
2383 (defun message-reduce-to-to-cc ()
2384 "Replace contents of To: header with contents of Cc: or Bcc: header."
2387 (save-restriction (message-narrow-to-headers)
2388 (message-fetch-field "cc")))
2390 (if (and (not cc-content
)
2393 (message-narrow-to-headers)
2394 (message-fetch-field "bcc"))))
2399 (message-delete-line)
2400 (insert (concat "To: " cc-content
"\n"))
2402 (message-narrow-to-headers)
2403 (message-remove-header (if bcc
2407 ;;; End of functions adopted from `message-utils.el'.
2409 (defun message-remove-header (header &optional is-regexp first reverse
)
2410 "Remove HEADER in the narrowed buffer.
2411 If IS-REGEXP, HEADER is a regular expression.
2412 If FIRST, only remove the first instance of the header.
2413 Return the number of headers removed."
2414 (goto-char (point-min))
2415 (let ((regexp (if is-regexp header
(concat "^" (regexp-quote header
) ":")))
2417 (case-fold-search t
)
2419 (while (and (not (eobp))
2422 (not (looking-at regexp
))
2423 (looking-at regexp
))
2430 ;; There might be a continuation header, so we have to search
2431 ;; until we find a new non-continuation line.
2434 (if (re-search-forward "^[^ \t]" nil t
)
2435 (goto-char (match-beginning 0))
2438 (if (re-search-forward "^[^ \t]" nil t
)
2439 (goto-char (match-beginning 0))
2440 (goto-char (point-max)))))
2443 (defun message-remove-first-header (header)
2444 "Remove the first instance of HEADER if there is more than one."
2446 (regexp (concat "^" (regexp-quote header
) ":")))
2448 (goto-char (point-min))
2449 (while (re-search-forward regexp nil t
)
2452 (message-remove-header header nil t
)
2455 (defun message-narrow-to-headers ()
2456 "Narrow the buffer to the head of the message."
2459 (goto-char (point-min))
2460 (if (re-search-forward
2461 (concat "^" (regexp-quote mail-header-separator
) "\n") nil t
)
2464 (goto-char (point-min)))
2466 (defun message-narrow-to-head-1 ()
2467 "Like `message-narrow-to-head'. Don't widen."
2469 (goto-char (point-min))
2470 (if (search-forward "\n\n" nil
1)
2473 (goto-char (point-min)))
2475 ;; FIXME: clarify diffference: message-narrow-to-head,
2476 ;; message-narrow-to-headers-or-head, message-narrow-to-headers
2477 (defun message-narrow-to-head ()
2478 "Narrow the buffer to the head of the message.
2479 Point is left at the beginning of the narrowed-to region."
2481 (message-narrow-to-head-1))
2483 (defun message-narrow-to-headers-or-head ()
2484 "Narrow the buffer to the head of the message."
2487 (goto-char (point-min))
2488 (if (re-search-forward (concat "\\(\n\\)\n\\|^\\("
2489 (regexp-quote mail-header-separator
)
2492 (or (match-end 1) (match-beginning 2))
2494 (goto-char (point-min)))
2496 (defun message-news-p ()
2497 "Say whether the current buffer contains a news message."
2498 (and (not message-this-is-mail
)
2499 (or message-this-is-news
2502 (message-narrow-to-headers)
2503 (and (message-fetch-field "newsgroups")
2504 (not (message-fetch-field "posted-to"))))))))
2506 (defun message-mail-p ()
2507 "Say whether the current buffer contains a mail message."
2508 (and (not message-this-is-news
)
2509 (or message-this-is-mail
2512 (message-narrow-to-headers)
2513 (or (message-fetch-field "to")
2514 (message-fetch-field "cc")
2515 (message-fetch-field "bcc")))))))
2517 (defun message-subscribed-p ()
2518 "Say whether we need to insert a MFT header."
2519 (or message-subscribed-regexps
2520 message-subscribed-addresses
2521 message-subscribed-address-file
2522 message-subscribed-address-functions
))
2524 (defun message-next-header ()
2525 "Go to the beginning of the next header."
2527 (or (eobp) (forward-char 1))
2528 (not (if (re-search-forward "^[^ \t]" nil t
)
2530 (goto-char (point-max)))))
2532 (defun message-sort-headers-1 ()
2533 "Sort the buffer as headers using `message-rank' text props."
2534 (goto-char (point-min))
2537 nil
'message-next-header
2539 (message-next-header)
2543 (or (get-text-property (point) 'message-rank
)
2546 (defun message-sort-headers ()
2547 "Sort the headers of the current message according to `message-header-format-alist'."
2551 (let ((max (1+ (length message-header-format-alist
)))
2553 (message-narrow-to-headers)
2554 (while (re-search-forward "^[^ \n]+:" nil t
)
2556 (match-beginning 0) (1+ (match-beginning 0))
2558 (if (setq rank
(length (memq (assq (intern (buffer-substring
2560 (1- (match-end 0))))
2561 message-header-format-alist
)
2562 message-header-format-alist
)))
2565 (message-sort-headers-1))))
2567 (defun message-kill-address ()
2568 "Kill the address under point."
2570 (let ((start (point)))
2571 (message-skip-to-next-address)
2572 (kill-region start
(point))))
2575 (autoload 'Info-goto-node
"info")
2576 (defvar mml2015-use
)
2578 (defun message-info (&optional arg
)
2579 "Display the Message manual.
2581 Prefixed with one \\[universal-argument], display the Emacs MIME
2582 manual. With two \\[universal-argument]'s, display the EasyPG or
2583 PGG manual, depending on the value of `mml2015-use'."
2585 ;; Don't use `info' because support for `(filename)nodename' is not
2586 ;; available in XEmacs < 21.5.12.
2587 (Info-goto-node (format "(%s)Top"
2591 ((eq arg
4) 'emacs-mime
)
2592 ;; `booleanp' only available in Emacs 22+
2593 ((and (not (memq arg
'(nil t
)))
2607 (defvar message-mode-map nil
)
2609 (unless message-mode-map
2610 (setq message-mode-map
(make-keymap))
2611 (set-keymap-parent message-mode-map text-mode-map
)
2612 (define-key message-mode-map
"\C-c?" 'describe-mode
)
2614 (define-key message-mode-map
"\C-c\C-f\C-t" 'message-goto-to
)
2615 (define-key message-mode-map
"\C-c\C-f\C-o" 'message-goto-from
)
2616 (define-key message-mode-map
"\C-c\C-f\C-b" 'message-goto-bcc
)
2617 (define-key message-mode-map
"\C-c\C-f\C-w" 'message-goto-fcc
)
2618 (define-key message-mode-map
"\C-c\C-f\C-c" 'message-goto-cc
)
2619 (define-key message-mode-map
"\C-c\C-f\C-s" 'message-goto-subject
)
2620 (define-key message-mode-map
"\C-c\C-f\C-r" 'message-goto-reply-to
)
2621 (define-key message-mode-map
"\C-c\C-f\C-n" 'message-goto-newsgroups
)
2622 (define-key message-mode-map
"\C-c\C-f\C-d" 'message-goto-distribution
)
2623 (define-key message-mode-map
"\C-c\C-f\C-f" 'message-goto-followup-to
)
2624 (define-key message-mode-map
"\C-c\C-f\C-m" 'message-goto-mail-followup-to
)
2625 (define-key message-mode-map
"\C-c\C-f\C-k" 'message-goto-keywords
)
2626 (define-key message-mode-map
"\C-c\C-f\C-u" 'message-goto-summary
)
2627 (define-key message-mode-map
"\C-c\C-f\C-i"
2628 'message-insert-or-toggle-importance
)
2629 (define-key message-mode-map
"\C-c\C-f\C-a"
2630 'message-generate-unsubscribed-mail-followup-to
)
2632 ;; modify headers (and insert notes in body)
2633 (define-key message-mode-map
"\C-c\C-fs" 'message-change-subject
)
2635 (define-key message-mode-map
"\C-c\C-fx" 'message-cross-post-followup-to
)
2636 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2637 (define-key message-mode-map
"\C-c\C-ft" 'message-reduce-to-to-cc
)
2638 (define-key message-mode-map
"\C-c\C-fa" 'message-add-archive-header
)
2639 ;; mark inserted text
2640 (define-key message-mode-map
"\C-c\M-m" 'message-mark-inserted-region
)
2641 (define-key message-mode-map
"\C-c\M-f" 'message-mark-insert-file
)
2643 (define-key message-mode-map
"\C-c\C-b" 'message-goto-body
)
2644 (define-key message-mode-map
"\C-c\C-i" 'message-goto-signature
)
2646 (define-key message-mode-map
"\C-c\C-t" 'message-insert-to
)
2647 (define-key message-mode-map
"\C-c\C-fw" 'message-insert-wide-reply
)
2648 (define-key message-mode-map
"\C-c\C-n" 'message-insert-newsgroups
)
2649 (define-key message-mode-map
"\C-c\C-l" 'message-to-list-only
)
2650 (define-key message-mode-map
"\C-c\C-f\C-e" 'message-insert-expires
)
2652 (define-key message-mode-map
"\C-c\C-u" 'message-insert-or-toggle-importance
)
2653 (define-key message-mode-map
"\C-c\M-n"
2654 'message-insert-disposition-notification-to
)
2656 (define-key message-mode-map
"\C-c\C-y" 'message-yank-original
)
2657 (define-key message-mode-map
"\C-c\M-\C-y" 'message-yank-buffer
)
2658 (define-key message-mode-map
"\C-c\C-q" 'message-fill-yanked-message
)
2659 (define-key message-mode-map
"\C-c\C-w" 'message-insert-signature
)
2660 (define-key message-mode-map
"\C-c\M-h" 'message-insert-headers
)
2661 (define-key message-mode-map
"\C-c\C-r" 'message-caesar-buffer-body
)
2662 (define-key message-mode-map
"\C-c\C-o" 'message-sort-headers
)
2663 (define-key message-mode-map
"\C-c\M-r" 'message-rename-buffer
)
2665 (define-key message-mode-map
"\C-c\C-c" 'message-send-and-exit
)
2666 (define-key message-mode-map
"\C-c\C-s" 'message-send
)
2667 (define-key message-mode-map
"\C-c\C-k" 'message-kill-buffer
)
2668 (define-key message-mode-map
"\C-c\C-d" 'message-dont-send
)
2669 (define-key message-mode-map
"\C-c\n" 'gnus-delay-article
)
2671 (define-key message-mode-map
"\C-c\M-k" 'message-kill-address
)
2672 (define-key message-mode-map
"\C-c\C-e" 'message-elide-region
)
2673 (define-key message-mode-map
"\C-c\C-v" 'message-delete-not-region
)
2674 (define-key message-mode-map
"\C-c\C-z" 'message-kill-to-signature
)
2675 (define-key message-mode-map
"\M-\r" 'message-newline-and-reformat
)
2676 (define-key message-mode-map
[remap split-line
] 'message-split-line
)
2678 (define-key message-mode-map
"\C-c\C-a" 'mml-attach-file
)
2680 (define-key message-mode-map
"\C-a" 'message-beginning-of-line
)
2681 (define-key message-mode-map
"\t" 'message-tab
)
2682 (define-key message-mode-map
"\M-;" 'comment-region
)
2684 (define-key message-mode-map
"\M-n" 'message-display-abbrev
))
2687 message-mode-menu message-mode-map
"Message Menu."
2689 ["Yank Original" message-yank-original message-reply-buffer
]
2690 ["Fill Yanked Message" message-fill-yanked-message t
]
2691 ["Insert Signature" message-insert-signature t
]
2692 ["Caesar (rot13) Message" message-caesar-buffer-body t
]
2693 ["Caesar (rot13) Region" message-caesar-region
(message-mark-active-p)]
2694 ["Elide Region" message-elide-region
2695 :active
(message-mark-active-p)
2696 ,@(if (featurep 'xemacs
) nil
2697 '(:help
"Replace text in region with an ellipsis"))]
2698 ["Delete Outside Region" message-delete-not-region
2699 :active
(message-mark-active-p)
2700 ,@(if (featurep 'xemacs
) nil
2701 '(:help
"Delete all quoted text outside region"))]
2702 ["Kill To Signature" message-kill-to-signature t
]
2703 ["Newline and Reformat" message-newline-and-reformat t
]
2704 ["Rename buffer" message-rename-buffer t
]
2705 ["Spellcheck" ispell-message
2706 ,@(if (featurep 'xemacs
) '(t)
2707 '(:help
"Spellcheck this message"))]
2709 ["Insert Region Marked" message-mark-inserted-region
2710 :active
(message-mark-active-p)
2711 ,@(if (featurep 'xemacs
) nil
2712 '(:help
"Mark region with enclosing tags"))]
2713 ["Insert File Marked..." message-mark-insert-file
2714 ,@(if (featurep 'xemacs
) '(t)
2715 '(:help
"Insert file at point marked with enclosing tags"))]
2717 ["Send Message" message-send-and-exit
2718 ,@(if (featurep 'xemacs
) '(t)
2719 '(:help
"Send this message"))]
2720 ["Postpone Message" message-dont-send
2721 ,@(if (featurep 'xemacs
) '(t)
2722 '(:help
"File this draft message and exit"))]
2723 ["Send at Specific Time..." gnus-delay-article
2724 ,@(if (featurep 'xemacs
) '(t)
2725 '(:help
"Ask, then arrange to send message at that time"))]
2726 ["Kill Message" message-kill-buffer
2727 ,@(if (featurep 'xemacs
) '(t)
2728 '(:help
"Delete this message without sending"))]
2730 ["Message manual" message-info
2731 ,@(if (featurep 'xemacs
) '(t)
2732 '(:help
"Display the Message manual"))]))
2735 message-mode-field-menu message-mode-map
""
2737 ["To" message-goto-to t
]
2738 ["From" message-goto-from t
]
2739 ["Subject" message-goto-subject t
]
2740 ["Change subject..." message-change-subject t
]
2741 ["Cc" message-goto-cc t
]
2742 ["Bcc" message-goto-bcc t
]
2743 ["Fcc" message-goto-fcc t
]
2744 ["Reply-To" message-goto-reply-to t
]
2745 ["Flag As Important" message-insert-importance-high
2746 ,@(if (featurep 'xemacs
) '(t)
2747 '(:help
"Mark this message as important"))]
2748 ["Flag As Unimportant" message-insert-importance-low
2749 ,@(if (featurep 'xemacs
) '(t)
2750 '(:help
"Mark this message as unimportant"))]
2752 message-insert-disposition-notification-to
2753 ,@(if (featurep 'xemacs
) '(t)
2754 '(:help
"Request a receipt notification"))]
2756 ;; (typical) news stuff
2757 ["Summary" message-goto-summary t
]
2758 ["Keywords" message-goto-keywords t
]
2759 ["Newsgroups" message-goto-newsgroups t
]
2760 ["Fetch Newsgroups" message-insert-newsgroups t
]
2761 ["Followup-To" message-goto-followup-to t
]
2762 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2763 ["Crosspost / Followup-To..." message-cross-post-followup-to t
]
2764 ["Distribution" message-goto-distribution t
]
2765 ["Expires" message-insert-expires t
]
2766 ["X-No-Archive" message-add-archive-header t
]
2768 ;; (typical) mailing-lists stuff
2769 ["Fetch To" message-insert-to
2770 ,@(if (featurep 'xemacs
) '(t)
2771 '(:help
"Insert a To header that points to the author."))]
2772 ["Fetch To and Cc" message-insert-wide-reply
2773 ,@(if (featurep 'xemacs
) '(t)
2775 "Insert To and Cc headers as if you were doing a wide reply."))]
2777 ["Send to list only" message-to-list-only t
]
2778 ["Mail-Followup-To" message-goto-mail-followup-to t
]
2779 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2780 ,@(if (featurep 'xemacs
) '(t)
2781 '(:help
"Insert a reasonable `Mail-Followup-To:' header."))]
2782 ["Reduce To: to Cc:" message-reduce-to-to-cc t
]
2784 ["Sort Headers" message-sort-headers t
]
2785 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t
]
2786 ;; We hide `message-hidden-headers' by narrowing the buffer.
2787 ["Show Hidden Headers" widen t
]
2788 ["Goto Body" message-goto-body t
]
2789 ["Goto Signature" message-goto-signature t
]))
2791 (defvar message-tool-bar-map nil
)
2793 (defvar facemenu-add-face-function
)
2794 (defvar facemenu-remove-face-function
)
2796 ;;; Forbidden properties
2798 ;; We use `after-change-functions' to keep special text properties
2799 ;; that interfere with the normal function of message mode out of the
2802 (defcustom message-strip-special-text-properties t
2803 "Strip special properties from the message buffer.
2805 Emacs has a number of special text properties which can break message
2806 composing in various ways. If this option is set, message will strip
2807 these properties from the message composition buffer. However, some
2808 packages requires these properties to be present in order to work.
2809 If you use one of these packages, turn this option off, and hope the
2810 message composition doesn't break too bad."
2812 :group
'message-various
2813 :link
'(custom-manual "(message)Various Message Variables")
2816 (defconst message-forbidden-properties
2817 ;; No reason this should be clutter up customize. We make it a
2818 ;; property list (rather than a list of property symbols), to be
2819 ;; directly useful for `remove-text-properties'.
2820 '(field nil read-only nil invisible nil intangible nil
2821 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2822 insert-behind-hooks nil point-entered nil point-left nil
)
2823 ;; Other special properties:
2824 ;; category, face, display: probably doesn't do any harm.
2825 ;; fontified: is used by font-lock.
2826 ;; syntax-table, local-map: I dunno.
2827 ;; We need to add XEmacs names to the list.
2828 "Property list of with properties forbidden in message buffers.
2829 The values of the properties are ignored, only the property names are used.")
2831 (defun message-tamago-not-in-use-p (pos)
2832 "Return t when tamago version 4 is not in use at the cursor position.
2833 Tamago version 4 is a popular input method for writing Japanese text.
2834 It uses the properties `intangible', `invisible', `modification-hooks'
2835 and `read-only' when translating ascii or kana text to kanji text.
2836 These properties are essential to work, so we should never strip them."
2837 (not (and (boundp 'egg-modefull-mode
)
2838 (symbol-value 'egg-modefull-mode
)
2839 (or (memq (get-text-property pos
'intangible
)
2840 '(its-part-1 its-part-2
))
2841 (get-text-property pos
'egg-end
)
2842 (get-text-property pos
'egg-lang
)
2843 (get-text-property pos
'egg-start
)))))
2845 (defsubst message-mail-alias-type-p
(type)
2846 (if (atom message-mail-alias-type
)
2847 (eq message-mail-alias-type type
)
2848 (memq type message-mail-alias-type
)))
2850 (defun message-strip-forbidden-properties (begin end
&optional old-length
)
2851 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2852 This function is intended to be called from `after-change-functions'.
2853 See also `message-forbidden-properties'."
2854 (when (and (message-mail-alias-type-p 'ecomplete
)
2855 (memq this-command message-self-insert-commands
))
2856 (message-display-abbrev))
2857 (when (and message-strip-special-text-properties
2858 (message-tamago-not-in-use-p begin
))
2859 (let ((buffer-read-only nil
)
2860 (inhibit-read-only t
))
2861 (remove-text-properties begin end message-forbidden-properties
))))
2863 (autoload 'ecomplete-setup
"ecomplete") ;; for Emacs <23.
2866 (define-derived-mode message-mode text-mode
"Message"
2867 "Major mode for editing mail and news to be sent.
2868 Like Text Mode but with these additional commands:\\<message-mode-map>
2869 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2870 C-c C-d Postpone sending the message C-c C-k Kill the message
2871 C-c C-f move to a header field (and create it if there isn't):
2872 C-c C-f C-t move to To C-c C-f C-s move to Subject
2873 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2874 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2875 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2876 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2877 C-c C-f C-o move to From (\"Originator\")
2878 C-c C-f C-f move to Followup-To
2879 C-c C-f C-m move to Mail-Followup-To
2880 C-c C-f C-e move to Expires
2881 C-c C-f C-i cycle through Importance values
2882 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2883 C-c C-f x crossposting with FollowUp-To header and note in body
2884 C-c C-f t replace To: header with contents of Cc: or Bcc:
2885 C-c C-f a Insert X-No-Archive: header and a note in the body
2886 C-c C-t `message-insert-to' (add a To header to a news followup)
2887 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2888 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2889 C-c C-b `message-goto-body' (move to beginning of message text).
2890 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2891 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2892 C-c C-y `message-yank-original' (insert current message, if any).
2893 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2894 C-c C-e `message-elide-region' (elide the text between point and mark).
2895 C-c C-v `message-delete-not-region' (remove the text outside the region).
2896 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2897 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2898 C-c C-a `mml-attach-file' (attach a file as MIME).
2899 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2900 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2901 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2902 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2903 M-RET `message-newline-and-reformat' (break the line and reformat)."
2904 (setq local-abbrev-table text-mode-abbrev-table
)
2905 (set (make-local-variable 'message-reply-buffer
) nil
)
2906 (set (make-local-variable 'message-inserted-headers
) nil
)
2907 (set (make-local-variable 'message-send-actions
) nil
)
2908 (set (make-local-variable 'message-exit-actions
) nil
)
2909 (set (make-local-variable 'message-kill-actions
) nil
)
2910 (set (make-local-variable 'message-postpone-actions
) nil
)
2911 (set (make-local-variable 'message-draft-article
) nil
)
2912 (setq buffer-offer-save t
)
2913 (set (make-local-variable 'facemenu-add-face-function
)
2915 (let ((face-fun (cdr (assq face message-face-alist
))))
2917 (funcall face-fun
(point) end
)
2918 (error "Face %s not configured for %s mode" face mode-name
)))
2920 (set (make-local-variable 'facemenu-remove-face-function
) t
)
2921 (set (make-local-variable 'message-reply-headers
) nil
)
2922 (make-local-variable 'message-newsreader
)
2923 (make-local-variable 'message-mailer
)
2924 (make-local-variable 'message-post-method
)
2925 (set (make-local-variable 'message-sent-message-via
) nil
)
2926 (set (make-local-variable 'message-checksum
) nil
)
2927 (set (make-local-variable 'message-mime-part
) 0)
2928 (message-setup-fill-variables)
2929 (when message-fill-column
2930 (setq fill-column message-fill-column
)
2931 (turn-on-auto-fill))
2932 ;; Allow using comment commands to add/remove quoting.
2933 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2934 (when message-yank-prefix
2935 (set (make-local-variable 'comment-start
) message-yank-prefix
)
2936 (set (make-local-variable 'comment-start-skip
)
2937 (concat "^" (regexp-quote message-yank-prefix
) "[ \t]*")))
2938 (if (featurep 'xemacs
)
2939 (message-setup-toolbar)
2940 (set (make-local-variable 'font-lock-defaults
)
2941 '(message-font-lock-keywords t
))
2942 (if (boundp 'tool-bar-map
)
2943 (set (make-local-variable 'tool-bar-map
) (message-make-tool-bar))))
2944 (easy-menu-add message-mode-menu message-mode-map
)
2945 (easy-menu-add message-mode-field-menu message-mode-map
)
2946 (gnus-make-local-hook 'after-change-functions
)
2947 ;; Mmmm... Forbidden properties...
2948 (add-hook 'after-change-functions
'message-strip-forbidden-properties
2950 ;; Allow mail alias things.
2952 ((message-mail-alias-type-p 'abbrev
)
2953 (if (fboundp 'mail-abbrevs-setup
)
2954 (mail-abbrevs-setup)
2955 (if (fboundp 'mail-aliases-setup
) ; warning avoidance
2956 (mail-aliases-setup))))
2957 ((message-mail-alias-type-p 'ecomplete
)
2959 (unless buffer-file-name
2960 (message-set-auto-save-file-name))
2961 (unless (buffer-base-buffer)
2962 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2963 ;; multibyte is not necessary at all. -- zsh
2964 (mm-enable-multibyte))
2965 (set (make-local-variable 'indent-tabs-mode
) nil
) ;No tabs for indentation.
2968 (defun message-setup-fill-variables ()
2969 "Setup message fill variables."
2970 (set (make-local-variable 'fill-paragraph-function
)
2971 'message-fill-paragraph
)
2972 (make-local-variable 'paragraph-separate
)
2973 (make-local-variable 'paragraph-start
)
2974 (make-local-variable 'adaptive-fill-regexp
)
2975 (unless (boundp 'adaptive-fill-first-line-regexp
)
2976 (setq adaptive-fill-first-line-regexp nil
))
2977 (make-local-variable 'adaptive-fill-first-line-regexp
)
2978 (let ((quote-prefix-regexp
2979 ;; User should change message-cite-prefix-regexp if
2980 ;; message-yank-prefix is set to an abnormal value.
2981 (concat "\\(" message-cite-prefix-regexp
"\\)[ \t]*")))
2982 (setq paragraph-start
2984 (regexp-quote mail-header-separator
) "$\\|"
2985 "[ \t]*$\\|" ; blank lines
2986 "-- $\\|" ; signature delimiter
2987 "---+$\\|" ; delimiters for forwarded messages
2988 page-delimiter
"$\\|" ; spoiler warnings
2989 ".*wrote:$\\|" ; attribution lines
2990 quote-prefix-regexp
"$\\|" ; empty lines in quoted text
2992 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
2993 (setq paragraph-separate paragraph-start
)
2994 (setq adaptive-fill-regexp
2995 (concat quote-prefix-regexp
"\\|" adaptive-fill-regexp
))
2996 (setq adaptive-fill-first-line-regexp
2997 (concat quote-prefix-regexp
"\\|"
2998 adaptive-fill-first-line-regexp
)))
2999 (make-local-variable 'auto-fill-inhibit-regexp
)
3000 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
3001 (setq auto-fill-inhibit-regexp nil
)
3002 (make-local-variable 'normal-auto-fill-function
)
3003 (setq normal-auto-fill-function
'message-do-auto-fill
)
3004 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
3005 ;; In that case, ensure that it uses the right function. The real
3006 ;; solution would be not to use `define-derived-mode', and run
3007 ;; `text-mode-hook' ourself at the end of the mode.
3008 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
3009 ;; This kludge is unneeded in Emacs>=21 since define-derived-mode is
3010 ;; now careful to run parent hooks after the body. --Stef
3011 (when auto-fill-function
3012 (setq auto-fill-function normal-auto-fill-function
)))
3017 ;;; Message mode commands
3020 ;;; Movement commands
3022 (defun message-goto-to ()
3023 "Move point to the To header."
3025 (message-position-on-field "To"))
3027 (defun message-goto-from ()
3028 "Move point to the From header."
3030 (message-position-on-field "From"))
3032 (defun message-goto-subject ()
3033 "Move point to the Subject header."
3035 (message-position-on-field "Subject"))
3037 (defun message-goto-cc ()
3038 "Move point to the Cc header."
3040 (message-position-on-field "Cc" "To"))
3042 (defun message-goto-bcc ()
3043 "Move point to the Bcc header."
3045 (message-position-on-field "Bcc" "Cc" "To"))
3047 (defun message-goto-fcc ()
3048 "Move point to the Fcc header."
3050 (message-position-on-field "Fcc" "To" "Newsgroups"))
3052 (defun message-goto-reply-to ()
3053 "Move point to the Reply-To header."
3055 (message-position-on-field "Reply-To" "Subject"))
3057 (defun message-goto-newsgroups ()
3058 "Move point to the Newsgroups header."
3060 (message-position-on-field "Newsgroups"))
3062 (defun message-goto-distribution ()
3063 "Move point to the Distribution header."
3065 (message-position-on-field "Distribution"))
3067 (defun message-goto-followup-to ()
3068 "Move point to the Followup-To header."
3070 (message-position-on-field "Followup-To" "Newsgroups"))
3072 (defun message-goto-mail-followup-to ()
3073 "Move point to the Mail-Followup-To header."
3075 (message-position-on-field "Mail-Followup-To" "To"))
3077 (defun message-goto-keywords ()
3078 "Move point to the Keywords header."
3080 (message-position-on-field "Keywords" "Subject"))
3082 (defun message-goto-summary ()
3083 "Move point to the Summary header."
3085 (message-position-on-field "Summary" "Subject"))
3087 (defun message-goto-body (&optional interactivep
)
3088 "Move point to the beginning of the message body."
3089 (interactive (list t
))
3090 (when (and interactivep
3091 (looking-at "[ \t]*\n"))
3093 (goto-char (point-min))
3094 (or (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
3095 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t
)))
3097 (defun message-in-body-p ()
3098 "Return t if point is in the message body."
3099 (let ((body (save-excursion (message-goto-body) (point))))
3102 (defun message-goto-eoh ()
3103 "Move point to the end of the headers."
3108 (defun message-goto-signature ()
3109 "Move point to the beginning of the message signature.
3110 If there is no signature in the article, go to the end and
3113 (goto-char (point-min))
3114 (if (re-search-forward message-signature-separator nil t
)
3116 (goto-char (point-max))
3119 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc
)
3120 "Insert a reasonable MFT header in a post to an unsubscribed list.
3121 When making original posts to a mailing list you are not subscribed to,
3122 you have to type in a MFT header by hand. The contents, usually, are
3123 the addresses of the list and your own address. This function inserts
3124 such a header automatically. It fetches the contents of the To: header
3125 in the current mail buffer, and appends the current `user-mail-address'.
3127 If the optional argument INCLUDE-CC is non-nil, the addresses in the
3128 Cc: header are also put into the MFT."
3133 (message-narrow-to-headers)
3134 (message-remove-header "Mail-Followup-To")
3135 (setq cc
(and include-cc
(message-fetch-field "Cc")))
3137 (concat (message-fetch-field "To") "," cc
)
3138 (message-fetch-field "To"))))
3139 (message-goto-mail-followup-to)
3140 (insert (concat tos
", " user-mail-address
))))
3144 (defun message-insert-to (&optional force
)
3145 "Insert a To header that points to the author of the article being replied to.
3146 If the original author requested not to be sent mail, don't insert unless the
3147 prefix FORCE is given."
3149 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
3150 (dont (and mct
(or (equal (downcase mct
) "never")
3151 (equal (downcase mct
) "nobody"))))
3152 (to (or (message-fetch-reply-field "mail-reply-to")
3153 (message-fetch-reply-field "reply-to")
3154 (message-fetch-reply-field "from"))))
3158 "Ignoring the user request not to have copies sent via mail"
3159 "Complying with the user request not to have copies sent via mail")))
3160 (when (and force
(not to
))
3161 (error "No mail address in the article"))
3162 (when (and to
(or force
(not dont
)))
3163 (message-carefully-insert-headers (list (cons 'To to
))))))
3165 (defun message-insert-wide-reply ()
3166 "Insert To and Cc headers as if you were doing a wide reply."
3168 (let ((headers (message-with-reply-buffer
3169 (message-get-reply-headers t
))))
3170 (message-carefully-insert-headers headers
)))
3172 (defcustom message-header-synonyms
3175 "List of lists of header synonyms.
3176 E.g., if this list contains a member list with elements `Cc' and `To',
3177 then `message-carefully-insert-headers' will not insert a `To' header
3178 when the message is already `Cc'ed to the recipient."
3180 :group
'message-headers
3181 :link
'(custom-manual "(message)Message Headers")
3182 :type
'(repeat sexp
))
3184 (defun message-carefully-insert-headers (headers)
3185 "Insert the HEADERS, an alist, into the message buffer.
3186 Does not insert the headers when they are already present there
3187 or in the synonym headers, defined by `message-header-synonyms'."
3188 ;; FIXME: Should compare only the address and not the full name. Comparison
3189 ;; should be done case-folded (and with `string=' rather than
3191 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
3192 (dolist (header headers
)
3193 (let* ((header-name (symbol-name (car header
)))
3194 (new-header (cdr header
))
3195 (synonyms (loop for synonym in message-header-synonyms
3196 when
(memq (car header
) synonym
) return synonym
))
3198 (loop for synonym in synonyms
3199 for old-header
= (mail-fetch-field (symbol-name synonym
))
3200 when
(and old-header
(string-match new-header old-header
))
3203 (message "already have `%s' in `%s'" new-header old-header
)
3204 (when (and (message-position-on-field header-name
)
3205 (setq old-header
(mail-fetch-field header-name
))
3206 (not (string-match "\\` *\\'" old-header
)))
3208 (insert new-header
)))))
3210 (defun message-widen-reply ()
3211 "Widen the reply to include maximum recipients."
3214 (and (bufferp message-reply-buffer
)
3215 (buffer-name message-reply-buffer
)
3216 (with-current-buffer message-reply-buffer
3217 (message-get-reply-headers t
)))))
3220 (message-narrow-to-headers)
3221 (dolist (elem follow-to
)
3222 (message-remove-header (symbol-name (car elem
)))
3223 (goto-char (point-min))
3224 (insert (symbol-name (car elem
)) ": "
3225 (cdr elem
) "\n"))))))
3227 (defun message-insert-newsgroups ()
3228 "Insert the Newsgroups header from the article being replied to."
3230 (when (and (message-position-on-field "Newsgroups")
3231 (mail-fetch-field "newsgroups")
3232 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
3234 (insert (or (message-fetch-reply-field "newsgroups") "")))
3238 ;;; Various commands
3240 (defun message-delete-not-region (beg end
)
3241 "Delete everything in the body of the current message outside of the region."
3246 ;; snarf citation prefix, if appropriate
3247 (unless (eq (point) (progn (beginning-of-line) (point)))
3248 (when (looking-at message-cite-prefix-regexp
)
3249 (setq citeprefix
(match-string 0))))
3251 (delete-region (point) (if (not (message-goto-signature))
3257 (delete-region beg
(progn (message-goto-body)
3261 (insert citeprefix
))))
3262 (when (message-goto-signature)
3265 (defun message-kill-to-signature (&optional arg
)
3266 "Kill all text up to the signature.
3267 If a numeric argument or prefix arg is given, leave that number
3268 of lines before the signature intact."
3272 (let ((point (point)))
3273 (narrow-to-region point
(point-max))
3274 (message-goto-signature)
3276 (if (and arg
(numberp arg
))
3277 (forward-line (- -
1 arg
))
3279 (unless (= point
(point))
3280 (kill-region point
(point))
3284 (defun message-newline-and-reformat (&optional arg not-break
)
3285 "Insert four newlines, and then reformat if inside quoted text.
3286 Prefix arg means justify as well."
3287 (interactive (list (if current-prefix-arg
'full
)))
3288 (let (quoted point beg end leading-space bolp fill-paragraph-function
)
3289 (setq point
(point))
3292 (setq bolp
(= beg point
))
3293 ;; Find first line of the paragraph.
3295 (while (and (not (eobp))
3296 (not (looking-at message-cite-prefix-regexp
))
3297 (looking-at paragraph-start
))
3300 (when (looking-at message-cite-prefix-regexp
)
3301 (setq quoted
(match-string 0))
3302 (goto-char (match-end 0))
3303 (looking-at "[ \t]*")
3304 (setq leading-space
(match-string 0)))
3308 (< (- point beg
) (length quoted
)))
3309 ;; break inside the cite prefix.
3315 (while (and (not (eobp))
3316 (not (looking-at paragraph-separate
))
3317 (looking-at message-cite-prefix-regexp
)
3318 (equal quoted
(match-string 0)))
3319 (goto-char (match-end 0))
3320 (looking-at "[ \t]*")
3321 (if (> (length leading-space
) (length (match-string 0)))
3322 (setq leading-space
(match-string 0)))
3326 (while (and (if (bobp) nil
(forward-line -
1) t
)
3327 (not (looking-at paragraph-start
))
3328 (looking-at message-cite-prefix-regexp
)
3329 (equal quoted
(match-string 0)))
3331 (goto-char (match-end 0))
3332 (looking-at "[ \t]*")
3333 (if (> (length leading-space
) (length (match-string 0)))
3334 (setq leading-space
(match-string 0)))))
3335 (while (and (not (eobp))
3336 (not (looking-at paragraph-separate
))
3337 (not (looking-at message-cite-prefix-regexp
)))
3341 (while (and (if (bobp) nil
(forward-line -
1) t
)
3342 (not (looking-at paragraph-start
))
3343 (not (looking-at message-cite-prefix-regexp
)))
3344 (setq beg
(point))))
3347 (narrow-to-region beg end
)
3354 (setq point
(point))
3355 ;; (newline 2) doesn't mark both newline's as hard, so call
3356 ;; newline twice. -jas
3359 (delete-region (point) (re-search-forward "[ \t]*"))
3360 (when (and quoted
(not bolp
))
3361 (insert quoted leading-space
)))
3364 (let* ((adaptive-fill-regexp
3365 (regexp-quote (concat quoted leading-space
)))
3366 (adaptive-fill-first-line-regexp
3367 adaptive-fill-regexp
))
3368 (fill-paragraph arg
))
3369 (fill-paragraph arg
))
3370 (if point
(goto-char point
)))))
3372 (defun message-fill-paragraph (&optional arg
)
3373 "Message specific function to fill a paragraph.
3374 This function is used as the value of `fill-paragraph-function' in
3375 Message buffers and is not meant to be called directly."
3376 (interactive (list (if current-prefix-arg
'full
)))
3377 (if (if (boundp 'filladapt-mode
) filladapt-mode
)
3379 (if (message-point-in-header-p)
3380 (message-fill-field)
3381 (message-newline-and-reformat arg t
))
3384 (defun message-point-in-header-p ()
3385 "Return t if point is in the header."
3387 (not (re-search-backward
3388 (concat "^" (regexp-quote mail-header-separator
) "\n") nil t
))))
3390 (defun message-do-auto-fill ()
3391 "Like `do-auto-fill', but don't fill in message header."
3392 (unless (message-point-in-header-p)
3395 (defun message-insert-signature (&optional force
)
3396 "Insert a signature. See documentation for variable `message-signature'."
3397 (interactive (list 0))
3400 ((and (null message-signature
)
3403 (goto-char (point-max))
3404 (not (re-search-backward message-signature-separator nil t
))))
3405 ((and (null message-signature
)
3408 ((functionp message-signature
)
3409 (funcall message-signature
))
3410 ((listp message-signature
)
3411 (eval message-signature
))
3412 (t message-signature
)))
3415 (cond ((stringp signature
)
3417 ((and (eq t signature
) message-signature-file
)
3418 (setq signature-file
3419 (if (and message-signature-directory
3420 ;; don't actually use the signature directory
3421 ;; if message-signature-file contains a path.
3422 (not (file-name-directory
3423 message-signature-file
)))
3424 (expand-file-name message-signature-file
3425 message-signature-directory
)
3426 message-signature-file
))
3427 (file-exists-p signature-file
))))
3429 (goto-char (point-max))
3430 ;; Insert the signature.
3433 (when message-signature-insert-empty-line
3436 (if (eq signature t
)
3437 (insert-file-contents signature-file
)
3439 (goto-char (point-max))
3440 (or (bolp) (insert "\n")))))
3442 (defun message-insert-importance-high ()
3443 "Insert header to mark message as important."
3447 (message-narrow-to-headers)
3448 (message-remove-header "Importance"))
3450 (insert "Importance: high\n")))
3452 (defun message-insert-importance-low ()
3453 "Insert header to mark message as unimportant."
3457 (message-narrow-to-headers)
3458 (message-remove-header "Importance"))
3460 (insert "Importance: low\n")))
3462 (defun message-insert-or-toggle-importance ()
3463 "Insert a \"Importance: high\" header, or cycle through the header values.
3464 The three allowed values according to RFC 1327 are `high', `normal'
3471 (message-narrow-to-headers)
3472 (when (setq cur
(message-fetch-field "Importance"))
3473 (message-remove-header "Importance")
3474 (setq new
(cond ((string= cur
"high")
3476 ((string= cur
"low")
3481 (insert (format "Importance: %s\n" new
)))))
3483 (defun message-insert-disposition-notification-to ()
3484 "Request a disposition notification (return receipt) to this message.
3485 Note that this should not be used in newsgroups."
3489 (message-narrow-to-headers)
3490 (message-remove-header "Disposition-Notification-To"))
3492 (insert (format "Disposition-Notification-To: %s\n"
3493 (or (message-field-value "Reply-to")
3494 (message-field-value "From")
3495 (message-make-from))))))
3497 (defun message-elide-region (b e
)
3498 "Elide the text in the region.
3499 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3503 (insert message-elide-ellipsis
))
3505 (defvar message-caesar-translation-table nil
)
3507 (defun message-caesar-region (b e
&optional n
)
3508 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3511 (min (point) (or (mark t
) (point)))
3512 (max (point) (or (mark t
) (point)))
3513 (when current-prefix-arg
3514 (prefix-numeric-value current-prefix-arg
))))
3516 (setq n
(if (numberp n
) (mod n
26) 13)) ;canonize N
3517 (unless (or (zerop n
) ; no action needed for a rot of 0
3518 (= b e
)) ; no region to rotate
3519 ;; We build the table, if necessary.
3520 (when (or (not message-caesar-translation-table
)
3521 (/= (aref message-caesar-translation-table ?a
) (+ ?a n
)))
3522 (setq message-caesar-translation-table
3523 (message-make-caesar-translation-table n
)))
3524 (translate-region b e message-caesar-translation-table
)))
3526 (defun message-make-caesar-translation-table (n)
3527 "Create a rot table with offset N."
3529 (table (make-string 256 0)))
3530 (while (< (incf i
) 256)
3533 (substring table
0 ?A
)
3534 (substring table
(+ ?A n
) (+ ?A n
(- 26 n
)))
3535 (substring table ?A
(+ ?A n
))
3536 (substring table
(+ ?A
26) ?a
)
3537 (substring table
(+ ?a n
) (+ ?a n
(- 26 n
)))
3538 (substring table ?a
(+ ?a n
))
3539 (substring table
(+ ?a
26) 255))))
3541 (defun message-caesar-buffer-body (&optional rotnum wide
)
3542 "Caesar rotate all letters in the current buffer by 13 places.
3543 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3544 With prefix arg, specifies the number of places to rotate each letter forward.
3545 Mail and USENET news headers are not rotated unless WIDE is non-nil."
3546 (interactive (if current-prefix-arg
3547 (list (prefix-numeric-value current-prefix-arg
))
3551 (when (and (not wide
) (message-goto-body))
3552 (narrow-to-region (point) (point-max)))
3553 (message-caesar-region (point-min) (point-max) rotnum
))))
3555 (defun message-pipe-buffer-body (program)
3556 "Pipe the message body in the current buffer through PROGRAM."
3559 (when (message-goto-body)
3560 (narrow-to-region (point) (point-max)))
3561 (shell-command-on-region
3562 (point-min) (point-max) program nil t
))))
3564 (defun message-rename-buffer (&optional enter-string
)
3565 "Rename the *message* buffer to \"*message* RECIPIENT\".
3566 If the function is run with a prefix, it will ask for a new buffer
3567 name, rather than giving an automatic name."
3568 (interactive "Pbuffer name: ")
3571 (goto-char (point-min))
3572 (narrow-to-region (point)
3573 (search-forward mail-header-separator nil
'end
))
3575 (if (message-news-p) (message-fetch-field "Newsgroups")
3576 (message-fetch-field "To"))
3579 (if (string-match "," mail-to
)
3580 (concat (substring mail-to
0 (match-beginning 0)) ", ...")
3582 (name-default (concat "*message* " mail-trimmed-to
))
3583 (name (if enter-string
3584 (read-string "New buffer name: " name-default
)
3586 (rename-buffer name t
)))))
3588 (defun message-fill-yanked-message (&optional justifyp
)
3589 "Fill the paragraphs of a message yanked into this one.
3590 Numeric argument means justify as well."
3593 (goto-char (point-min))
3594 (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
3595 (let ((fill-prefix message-yank-prefix
))
3596 (fill-individual-paragraphs (point) (point-max) justifyp
))))
3598 (defun message-indent-citation (&optional start end yank-only
)
3599 "Modify text just inserted from a message to be cited.
3600 The inserted text should be the region.
3601 When this function returns, the region is again around the modified text.
3603 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3604 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3605 (unless start
(setq start
(point)))
3607 ;; Remove unwanted headers.
3608 (when message-ignored-cited-headers
3613 (if (search-forward "\n\n" nil t
)
3616 (message-remove-header message-ignored-cited-headers t
)
3617 (when (= (point-min) (point-max))
3618 (setq all-removed t
))
3619 (goto-char (point-max)))
3623 ;; Delete blank lines at the start of the buffer.
3624 (while (and (point-min)
3627 (message-delete-line))
3628 ;; Delete blank lines at the end of the buffer.
3629 (goto-char (point-max))
3632 (while (and (zerop (forward-line -
1))
3634 (message-delete-line)))
3635 ;; Do the indentation.
3636 (if (null message-yank-prefix
)
3637 (indent-rigidly start
(or end
(mark t
)) message-indentation-spaces
)
3640 (while (< (point) (or end
(mark t
)))
3641 (cond ((looking-at ">")
3642 (insert message-yank-cited-prefix
))
3644 (insert message-yank-empty-prefix
))
3646 (insert message-yank-prefix
)))
3650 (defun message-remove-blank-cited-lines (&optional remove
)
3651 "Remove cited lines containing only blanks.
3652 If REMOVE is non-nil, remove newlines, too.
3654 To use this automatically, you may add this function to
3655 `gnus-message-setup-hook'."
3660 (when (boundp 'message-yank-cited-prefix
)
3661 (concat message-yank-cited-prefix
"\\|"))
3665 (gnus-message 8 "removing `%s'" citexp
)
3668 (while (re-search-forward citexp nil t
)
3669 (replace-match (if remove
"" "\n"))))))
3671 (defvar message-cite-reply-above nil
3672 "If non-nil, start own text above the quote.
3674 Note: Top posting is bad netiquette. Don't use it unless you
3675 really must. You probably want to set variable only for specific
3676 groups, e.g. using `gnus-posting-styles':
3678 (eval (set (make-local-variable 'message-cite-reply-above) t))
3680 This variable has no effect in news postings.")
3682 (defun message-yank-original (&optional arg
)
3683 "Insert the message being replied to, if any.
3684 Puts point before the text and mark after.
3685 Normally indents each nonblank line ARG spaces (default 3). However,
3686 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3688 This function uses `message-cite-function' to do the actual citing.
3690 Just \\[universal-argument] as argument means don't indent, insert no
3691 prefix, and don't delete any headers."
3693 (let ((modified (buffer-modified-p))
3695 (when (and message-reply-buffer
3696 message-cite-function
)
3697 (when message-cite-reply-above
3698 (if (and (not (message-news-p))
3699 (or (eq message-cite-reply-above
'is-evil
)
3701 Top posting is bad netiquette. Please don't top post unless you really must.
3702 Really top post? ")))
3705 (buffer-substring (message-goto-body)
3707 (delete-region (message-goto-body) (point-max)))
3708 (set (make-local-variable 'message-cite-reply-above
) nil
)))
3709 (if (bufferp message-reply-buffer
)
3710 (delete-windows-on message-reply-buffer t
))
3711 (push-mark (save-excursion
3713 ((bufferp message-reply-buffer
)
3714 (insert-buffer-substring message-reply-buffer
))
3715 ((and (consp message-reply-buffer
)
3716 (functionp (car message-reply-buffer
)))
3717 (apply (car message-reply-buffer
)
3718 (cdr message-reply-buffer
))))
3723 (funcall message-cite-function
)
3724 (unless (eq (char-before (mark t
)) ?
\n)
3726 (goto-char (mark t
))
3727 (insert-before-markers ?
\n)
3729 (when message-cite-reply-above
3732 (insert (if (bolp) "\n" "\n\n"))
3733 (message-goto-body))
3734 ;; Add a `message-setup-very-last-hook' here?
3735 ;; Add `gnus-article-highlight-citation' here?
3737 (setq message-checksum
(message-checksum))))))
3739 (defun message-yank-buffer (buffer)
3740 "Insert BUFFER into the current buffer and quote it."
3741 (interactive "bYank buffer: ")
3742 (let ((message-reply-buffer (get-buffer buffer
)))
3743 (save-window-excursion
3744 (message-yank-original))))
3746 (defun message-buffers ()
3747 "Return a list of active message buffers."
3749 (save-current-buffer
3750 (dolist (buffer (buffer-list t
))
3752 (when (and (eq major-mode
'message-mode
)
3753 (null message-sent-message-via
))
3754 (push (buffer-name buffer
) buffers
))))
3755 (nreverse buffers
)))
3757 (defun message-cite-original-1 (strip-signature)
3758 "Cite an original message.
3759 If STRIP-SIGNATURE is non-nil, strips off the signature from the
3762 This function uses `mail-citation-hook' if that is non-nil."
3763 (if (and (boundp 'mail-citation-hook
)
3765 (run-hooks 'mail-citation-hook
)
3766 (let* ((start (point))
3770 (when message-indent-citation-function
3771 (if (listp message-indent-citation-function
)
3772 message-indent-citation-function
3773 (list message-indent-citation-function
))))
3774 ;; This function may be called by `gnus-summary-yank-message' and
3775 ;; may insert a different article from the original. So, we will
3776 ;; modify the value of `message-reply-headers' with that article.
3777 (message-reply-headers
3779 (narrow-to-region start end
)
3780 (message-narrow-to-head-1)
3781 (setq x-no-archive
(message-fetch-field "x-no-archive"))
3783 (or (message-fetch-field "subject") "none")
3784 (or (message-fetch-field "from") "nobody")
3785 (message-fetch-field "date")
3786 (message-fetch-field "message-id" t
)
3787 (message-fetch-field "references")
3789 (mml-quote-region start end
)
3790 (when strip-signature
3794 (when (re-search-backward message-signature-separator start t
)
3795 ;; Also peel off any blank lines before the signature.
3797 (while (looking-at "^[ \t]*$")
3800 (delete-region (point) end
)
3801 (unless (search-backward "\n\n" start t
)
3802 ;; Insert a blank line if it is peeled off.
3805 (mapc 'funcall functions
)
3806 (when message-citation-line-function
3809 (funcall message-citation-line-function
))
3810 (when (and x-no-archive
3811 (not message-cite-articles-with-x-no-archive
)
3812 (string-match "yes" x-no-archive
))
3814 (delete-region (point) (mark t
))
3815 (insert "> [Quoted text removed due to X-No-Archive]\n")
3817 (forward-line -
1)))))
3819 (defun message-cite-original ()
3820 "Cite function in the standard Message manner."
3821 (message-cite-original-1 nil
))
3823 (defvar gnus-extract-address-components
)
3825 (autoload 'format-spec
"format-spec")
3827 (defun message-insert-formatted-citation-line (&optional from date
)
3828 "Function that inserts a formatted citation line.
3830 See `message-citation-line-format'."
3831 ;; The optional args are for testing/debugging. They will disappear later.
3833 ;; (with-temp-buffer
3834 ;; (message-insert-formatted-citation-line
3835 ;; "John Doe <john.doe@example.invalid>"
3838 (when (or message-reply-headers
(and from date
))
3840 (setq from
(mail-header-from message-reply-headers
)))
3841 (let* ((data (condition-case ()
3842 (funcall (if (boundp gnus-extract-address-components
)
3843 gnus-extract-address-components
3844 'mail-extract-address-components
)
3850 (net (car (cdr data
)))
3851 (name-or-net (or (car data
)
3852 (car (cdr data
)) from
))
3856 ;; We need Gnus functionality if the user wants date or time from
3857 ;; the original article:
3858 (when (string-match "%[^fnNFL]" message-citation-line-format
)
3859 (autoload 'gnus-date-get-time
"gnus-util")
3860 (gnus-date-get-time (mail-header-date message-reply-headers
)))))
3863 (when (stringp name
)
3864 ;; Guess first name and last name:
3865 (cond ((string-match
3866 "\\`\\(\\w\\|[-.]\\)+ \\(\\w\\|[-.]\\)+\\'" name
)
3867 (setq fname
(nth 0 (split-string name
"[ \t]+"))
3868 lname
(nth 1 (split-string name
"[ \t]+"))))
3870 "\\`\\(\\w\\|[-.]\\)+, \\(\\w\\|[-.]\\)+\\'" name
)
3871 (setq fname
(nth 1 (split-string name
"[ \t,]+"))
3872 lname
(nth 0 (split-string name
"[ \t,]+"))))
3874 "\\`\\(\\w\\|[-.]\\)+\\'" name
)
3877 ;; The following letters are not used in `format-time-string':
3878 (push ?E lst
) (push "<E>" lst
)
3879 (push ?F lst
) (push fname lst
)
3880 ;; We might want to use "" instead of "<X>" later.
3881 (push ?J lst
) (push "<J>" lst
)
3882 (push ?K lst
) (push "<K>" lst
)
3883 (push ?L lst
) (push lname lst
)
3884 (push ?N lst
) (push name-or-net lst
)
3885 (push ?O lst
) (push "<O>" lst
)
3886 (push ?P lst
) (push "<P>" lst
)
3887 (push ?Q lst
) (push "<Q>" lst
)
3888 (push ?f lst
) (push from lst
)
3889 (push ?i lst
) (push "<i>" lst
)
3890 (push ?n lst
) (push net lst
)
3891 (push ?o lst
) (push "<o>" lst
)
3892 (push ?q lst
) (push "<q>" lst
)
3893 (push ?t lst
) (push "<t>" lst
)
3894 (push ?v lst
) (push "<v>" lst
)
3895 ;; Delegate the rest to `format-time-string':
3897 (when (and (not (memq i lst
))
3902 (push (condition-case nil
3903 (format-time-string (format "%%%c" i
) replydate
)
3904 (error (format ">%c<" i
)))
3908 (spec (apply 'format-spec-make flist
)))
3909 (insert (format-spec message-citation-line-format spec
)))
3912 (defun message-cite-original-without-signature ()
3913 "Cite function in the standard Message manner.
3914 This function strips off the signature from the original message."
3915 (message-cite-original-1 t
))
3917 (defun message-insert-citation-line ()
3918 "Insert a simple citation line."
3919 (when message-reply-headers
3920 (insert (mail-header-from message-reply-headers
) " writes:")
3924 (defun message-position-on-field (header &rest afters
)
3925 (let ((case-fold-search t
))
3928 (goto-char (point-min))
3931 (concat "^" (regexp-quote mail-header-separator
) "$"))
3932 (match-beginning 0)))
3933 (goto-char (point-min))
3934 (if (re-search-forward (concat "^" (regexp-quote header
) ":") nil t
)
3936 (re-search-forward "^[^ \t]" nil
'move
)
3938 (skip-chars-backward "\n")
3941 (not (re-search-forward
3942 (concat "^" (regexp-quote (car afters
)) ":")
3946 (re-search-forward "^[^ \t]" nil
'move
)
3947 (beginning-of-line))
3948 (insert header
": \n")
3952 (defun message-remove-signature ()
3953 "Remove the signature from the text between point and mark.
3954 The text will also be indented the normal way."
3956 (let ((start (point))
3958 (if (not (re-search-forward message-signature-separator
(mark t
) t
))
3959 ;; No signature here, so we just indent the cited text.
3960 (message-indent-citation)
3961 ;; Find the last non-empty line.
3963 (while (looking-at "[ \t]*$")
3966 (setq mark
(set-marker (make-marker) (point)))
3968 (message-indent-citation)
3969 ;; Enable undoing the deletion.
3971 (delete-region mark
(mark t
))
3972 (set-marker mark nil
)))))
3977 ;;; Sending messages
3980 (defun message-send-and-exit (&optional arg
)
3981 "Send message like `message-send', then, if no errors, exit from mail buffer."
3983 (let ((buf (current-buffer))
3984 (actions message-exit-actions
))
3985 (when (and (message-send arg
)
3987 (if message-kill-buffer-on-exit
3990 (when (eq buf
(current-buffer))
3991 (message-bury buf
)))
3992 (message-do-actions actions
)
3995 (defun message-dont-send ()
3996 "Don't send the message you have been editing.
3997 Instead, just auto-save the buffer and then bury it."
3999 (set-buffer-modified-p t
)
4001 (let ((actions message-postpone-actions
))
4002 (message-bury (current-buffer))
4003 (message-do-actions actions
)))
4005 (defun message-kill-buffer ()
4006 "Kill the current buffer."
4008 (when (or (not (buffer-modified-p))
4009 (not message-kill-buffer-query
)
4010 (yes-or-no-p "Message modified; kill anyway? "))
4011 (let ((actions message-kill-actions
)
4012 (draft-article message-draft-article
)
4013 (auto-save-file-name buffer-auto-save-file-name
)
4014 (file-name buffer-file-name
)
4015 (modified (buffer-modified-p)))
4016 (setq buffer-file-name nil
)
4017 (kill-buffer (current-buffer))
4018 (when (and (or (and auto-save-file-name
4019 (file-exists-p auto-save-file-name
))
4021 (file-exists-p file-name
)))
4023 ;; If the message buffer has lived in a dedicated window,
4024 ;; `kill-buffer' has killed the frame. Thus the
4025 ;; `yes-or-no-p' may show up in a lowered frame. Make sure
4026 ;; that the user can see the question by raising the
4029 (yes-or-no-p (format "Remove the backup file%s? "
4030 (if modified
" too" "")))))
4032 (delete-file auto-save-file-name
))
4033 (let ((message-draft-article draft-article
))
4034 (message-disassociate-draft)))
4035 (message-do-actions actions
))))
4037 (defun message-bury (buffer)
4038 "Bury this mail BUFFER."
4039 (let ((newbuf (other-buffer buffer
)))
4040 (bury-buffer buffer
)
4041 (if (and (window-dedicated-p (selected-window))
4042 (not (null (delq (selected-frame) (visible-frame-list)))))
4043 (delete-frame (selected-frame))
4044 (switch-to-buffer newbuf
))))
4046 (defun message-send (&optional arg
)
4047 "Send the message in the current buffer.
4048 If `message-interactive' is non-nil, wait for success indication or
4049 error messages, and inform user.
4050 Otherwise any failure is reported in a message back to the user from
4052 The usage of ARG is defined by the instance that called Message.
4053 It should typically alter the sending method in some way or other."
4055 ;; Make it possible to undo the coming changes.
4057 (let ((inhibit-read-only t
))
4058 (put-text-property (point-min) (point-max) 'read-only nil
))
4059 (message-fix-before-sending)
4060 (run-hooks 'message-send-hook
)
4061 (when message-confirm-send
4062 (or (y-or-n-p "Send message? ")
4064 (message message-sending-message
)
4065 (let ((alist message-send-method-alist
)
4067 elem sent dont-barf-on-no-method
4068 (message-options message-options
))
4069 (message-options-set-recipient)
4071 (setq elem
(pop alist
)))
4072 (when (funcall (cadr elem
))
4073 (when (and (or (not (memq (car elem
)
4074 message-sent-message-via
))
4075 (message-fetch-field "supersedes")
4076 (if (or (message-gnksa-enable-p 'multiple-copies
)
4077 (not (eq (car elem
) 'news
)))
4080 "Already sent message via %s; resend? "
4082 (error "Denied posting -- multiple copies")))
4083 (setq success
(funcall (caddr elem
) arg
)))
4087 (let ((fcc (message-fetch-field "Fcc"))
4088 (gcc (message-fetch-field "Gcc")))
4090 (or (eq message-allow-no-recipients
'always
)
4091 (and (not (eq message-allow-no-recipients
'never
))
4092 (setq dont-barf-on-no-method
4094 (format "No receiver, perform %s anyway? "
4095 (cond ((and fcc gcc
) "Fcc and Gcc")
4098 (error "No methods specified to send by"))
4099 (when (or dont-barf-on-no-method
4103 (run-hooks 'message-sent-hook
))
4104 (message "Sending...done")
4105 ;; Do ecomplete address snarfing.
4106 (when (and (message-mail-alias-type-p 'ecomplete
)
4107 (not message-inhibit-ecomplete
))
4108 (message-put-addresses-in-ecomplete))
4109 ;; Mark the buffer as unmodified and delete auto-save.
4110 (set-buffer-modified-p nil
)
4111 (delete-auto-save-file-if-necessary t
)
4112 (message-disassociate-draft)
4113 ;; Delete other mail buffers and stuff.
4114 (message-do-send-housekeeping)
4115 (message-do-actions message-send-actions
)
4119 (defun message-send-via-mail (arg)
4120 "Send the current message via mail."
4121 (message-send-mail arg
))
4123 (defun message-send-via-news (arg)
4124 "Send the current message via news."
4125 (funcall message-send-news-function arg
))
4127 (defmacro message-check
(type &rest forms
)
4128 "Eval FORMS if TYPE is to be checked."
4129 `(or (message-check-element ,type
)
4133 (put 'message-check
'lisp-indent-function
1)
4134 (put 'message-check
'edebug-form-spec
'(form body
))
4136 (defun message-text-with-property (prop &optional start end reverse
)
4137 "Return a list of start and end positions where the text has PROP.
4138 START and END bound the search, they default to `point-min' and
4139 `point-max' respectively. If REVERSE is non-nil, find text which does
4142 (setq start
(point-min)))
4144 (setq end
(point-max)))
4148 (setq start
(text-property-any start end prop nil
)))
4149 (setq next
(next-single-property-change start prop nil end
))
4150 (push (cons start
(or next end
)) regions
)
4153 (or (get-text-property start prop
)
4154 (and (setq start
(next-single-property-change
4155 start prop nil end
))
4156 (get-text-property start prop
))))
4157 (setq next
(text-property-any start end prop nil
))
4158 (push (cons start
(or next end
)) regions
)
4160 (nreverse regions
)))
4162 (defcustom message-bogus-addresses
4163 ;; '("noreply" "nospam" "invalid")
4164 '("noreply" "nospam" "invalid" "@@" "[^[:ascii:]].*@" "[ \t]")
4165 "List of regexps of potentially bogus mail addresses.
4166 See `message-check-recipients' how to setup checking.
4168 This list should make it possible to catch typos or warn about
4169 spam-trap addresses. It doesn't aim to verify strict RFC
4171 :version
"23.1" ;; No Gnus
4172 :group
'message-headers
4174 (const :tag
"None" nil
)
4180 (const :tag
"duplicate @" "@@")
4181 (const :tag
"non-ascii local part" "[^[:ascii:]].*@")
4182 ;; Already caught by `message-valid-fqdn-regexp'
4183 ;; (const :tag "`_' in domain part" "@.*_")
4184 (const :tag
"whitespace" "[ \t]"))
4189 (defun message-fix-before-sending ()
4190 "Do various things to make the message nice before sending it."
4191 ;; Make sure there's a newline at the end of the message.
4192 (goto-char (point-max))
4195 ;; Make the hidden headers visible.
4197 ;; Sort headers before sending the message.
4198 (message-sort-headers)
4199 ;; Make invisible text visible.
4200 ;; It doesn't seem as if this is useful, since the invisible property
4201 ;; is clobbered by an after-change hook anyhow.
4202 (message-check 'invisible-text
4203 (let ((regions (message-text-with-property 'invisible
))
4207 (setq from
(caar regions
)
4209 regions
(cdr regions
))
4210 (put-text-property from to
'invisible nil
)
4211 (message-overlay-put (message-make-overlay from to
)
4213 (unless (yes-or-no-p
4214 "Invisible text found and made visible; continue sending? ")
4215 (error "Invisible text found and made visible")))))
4216 (message-check 'illegible-text
4217 (let (char found choice
)
4220 (skip-chars-forward mm-7bit-chars
)
4221 (when (get-text-property (point) 'no-illegible-text
)
4222 ;; There is a signed or encrypted raw message part
4223 ;; that is considered to be safe.
4224 (goto-char (or (next-single-property-change
4225 (point) 'no-illegible-text
)
4227 (setq char
(char-after)))
4228 (when (or (< (mm-char-int char
) 128)
4229 (and (mm-multibyte-p)
4230 (memq (char-charset char
)
4231 '(eight-bit-control eight-bit-graphic
4232 ;; Emacs 23, Bug#1770:
4235 (not (get-text-property
4236 (point) 'untranslated-utf-8
))))
4237 (message-overlay-put (message-make-overlay (point) (1+ (point)))
4243 (gnus-multiple-choice
4244 "Non-printable characters found. Continue sending?"
4245 `((?d
"Remove non-printable characters and send")
4247 "Replace non-printable characters with \"%s\" and send"
4248 message-replacement-char
))
4249 (?i
"Ignore non-printable characters and send")
4250 (?e
"Continue editing"))))
4252 (error "Non-printable characters"))
4254 (skip-chars-forward mm-7bit-chars
)
4256 (when (let ((char (char-after)))
4257 (or (< (mm-char-int char
) 128)
4258 (and (mm-multibyte-p)
4259 ;; FIXME: Wrong for Emacs 23 (unicode) and for
4260 ;; things like undecodable utf-8 (in Emacs 21?).
4261 ;; Should at least use find-coding-systems-region.
4263 (memq (char-charset char
)
4264 '(eight-bit-control eight-bit-graphic
4265 ;; Emacs 23, Bug#1770:
4268 (not (get-text-property
4269 (point) 'untranslated-utf-8
)))))
4271 (message-kill-all-overlays)
4273 (when (eq choice ?r
)
4274 (insert message-replacement-char
))))
4276 (skip-chars-forward mm-7bit-chars
)))))
4277 (message-check 'bogus-recipient
4278 ;; Warn before sending a mail to an invalid address.
4279 (message-check-recipients)))
4281 (defun message-bogus-recipient-p (recipients)
4282 "Check if a mail address in RECIPIENTS looks bogus.
4284 RECIPIENTS is a mail header. Return a list of potentially bogus
4285 addresses. If none is found, return nil.
4287 An address might be bogus if the domain part is not fully
4288 qualified, see `message-valid-fqdn-regexp', or if there's a
4289 matching entry in `message-bogus-addresses'."
4290 ;; FIXME: How about "foo@subdomain", when the MTA adds ".domain.tld"?
4292 (mapc (lambda (address)
4293 (setq address
(cadr address
))
4297 (not (string-match "@" address
))
4300 message-valid-fqdn-regexp
"\\)\\'") address
)))
4301 (and message-bogus-addresses
4303 (if (listp message-bogus-addresses
)
4304 (mapconcat 'identity
4305 message-bogus-addresses
4307 message-bogus-addresses
)))
4308 (string-match re address
))))
4309 (push address found
)))
4311 (mail-extract-address-components recipients t
))
4314 (defun message-check-recipients ()
4315 "Warn before composing or sending a mail to an invalid address.
4317 This function could be useful in `message-setup-hook'."
4320 (message-narrow-to-headers)
4321 (dolist (hdr '("To" "Cc" "Bcc"))
4322 (let ((addr (message-fetch-field hdr
)))
4323 (when (stringp addr
)
4324 (dolist (bog (message-bogus-recipient-p addr
))
4328 "Address `%s' might be bogus. Continue? " bog
)))
4329 (error "Bogus address"))))))))
4331 (custom-add-option 'message-setup-hook
'message-check-recipients
)
4333 (defun message-add-action (action &rest types
)
4334 "Add ACTION to be performed when doing an exit of type TYPES."
4336 (add-to-list (intern (format "message-%s-actions" (pop types
)))
4339 (defun message-delete-action (action &rest types
)
4340 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
4343 (set (setq var
(intern (format "message-%s-actions" (pop types
))))
4344 (delq action
(symbol-value var
))))))
4346 (defun message-do-actions (actions)
4347 "Perform all actions in ACTIONS."
4348 ;; Now perform actions on successful sending.
4349 (dolist (action actions
)
4352 ;; A simple function.
4355 ;; Something to be evaled.
4359 (defun message-send-mail-partially ()
4360 "Send mail as message/partial."
4361 ;; replace the header delimiter with a blank line
4362 (goto-char (point-min))
4364 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4365 (replace-match "\n")
4366 (run-hooks 'message-send-mail-hook
)
4367 (let ((p (goto-char (point-min)))
4368 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
4369 (curbuf (current-buffer))
4370 (id (message-make-message-id)) (n 1)
4371 plist total header required-mail-headers
)
4373 (if (< (point-max) (+ p message-send-mail-partially-limit
))
4374 (goto-char (point-max))
4375 (goto-char (+ p message-send-mail-partially-limit
))
4377 (if (<= (point) p
) (forward-line 1))) ;; In case of bad message.
4380 (setq total
(length plist
))
4381 (push (point-max) plist
)
4382 (setq plist
(nreverse plist
))
4385 (setq p
(pop plist
))
4388 (copy-to-buffer tembuf p
(car plist
))
4390 (goto-char (point-min))
4393 (goto-char (point-min))
4394 (narrow-to-region (point) (point))
4397 (setq header
(buffer-substring (point-min) (point)))
4398 (goto-char (point-min))
4399 (narrow-to-region (point) (point))
4401 (message-remove-header "Mime-Version")
4402 (message-remove-header "Content-Type")
4403 (message-remove-header "Content-Transfer-Encoding")
4404 (message-remove-header "Message-ID")
4405 (message-remove-header "Lines")
4406 (goto-char (point-max))
4407 (insert "Mime-Version: 1.0\n")
4408 (setq header
(buffer-string)))
4409 (goto-char (point-max))
4410 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
4413 (let ((mail-header-separator ""))
4414 (when (memq 'Message-ID message-required-mail-headers
)
4415 (insert "Message-ID: " (message-make-message-id) "\n"))
4416 (when (memq 'Lines message-required-mail-headers
)
4417 (insert "Lines: " (message-make-lines) "\n"))
4418 (message-goto-subject)
4420 (insert (format " (%d/%d)" n total
))
4422 (funcall (or message-send-mail-real-function
4423 message-send-mail-function
)))
4425 (setq p
(pop plist
))
4427 (kill-buffer tembuf
))))
4429 (declare-function hashcash-wait-async
"hashcash" (&optional buffer
))
4431 (defun message-send-mail (&optional arg
)
4432 (require 'mail-utils
)
4433 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
4434 (case-fold-search nil
)
4435 (news (message-news-p))
4436 (mailbuf (current-buffer))
4437 (message-this-is-mail t
)
4438 ;; gnus-setup-posting-charset is autoloaded in mml.el (FIXME
4439 ;; maybe it should not be), which this file requires. Hence
4440 ;; the fboundp test is always true. Loading it from gnus-msg
4441 ;; loads many Gnus files (Bug#5642). If
4442 ;; gnus-group-posting-charset-alist hasn't been customized,
4443 ;; this is just going to return nil anyway. FIXME it would
4444 ;; be good to improve this further, because even if g-g-p-c-a
4445 ;; has been customized, that is likely to just be for news.
4446 ;; Eg either move the definition from gnus-msg, or separate out
4447 ;; the mail and news parts.
4448 (message-posting-charset
4449 (if (and (fboundp 'gnus-setup-posting-charset
)
4450 (boundp 'gnus-group-posting-charset-alist
))
4451 (gnus-setup-posting-charset nil
)
4452 message-posting-charset
))
4453 (headers message-required-mail-headers
))
4454 (when (and message-generate-hashcash
4455 (not (eq message-generate-hashcash
'opportunistic
)))
4456 (message "Generating hashcash...")
4458 ;; Wait for calculations already started to finish...
4459 (hashcash-wait-async)
4460 ;; ...and do calculations not already done. mail-add-payment
4461 ;; will leave existing X-Hashcash headers alone.
4463 (message "Generating hashcash...done"))
4465 (message-narrow-to-headers)
4466 ;; Generate the Mail-Followup-To header if the header is not there...
4467 (if (and (message-subscribed-p)
4468 (not (mail-fetch-field "mail-followup-to")))
4471 (cons "Mail-Followup-To" (message-make-mail-followup-to))
4472 message-required-mail-headers
))
4473 ;; otherwise, delete the MFT header if the field is empty
4474 (when (equal "" (mail-fetch-field "mail-followup-to"))
4475 (message-remove-header "^Mail-Followup-To:")))
4476 ;; Insert some headers.
4477 (let ((message-deletable-headers
4478 (if news nil message-deletable-headers
)))
4479 (message-generate-headers headers
))
4480 ;; Check continuation headers.
4481 (message-check 'continuation-headers
4482 (goto-char (point-min))
4483 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t
)
4484 (goto-char (match-beginning 0))
4485 (if (y-or-n-p "Fix continuation lines? ")
4488 (unless (y-or-n-p "Send anyway? ")
4489 (error "Failed to send the message")))))
4490 ;; Let the user do all of the above.
4491 (run-hooks 'message-header-hook
))
4493 (with-current-buffer tembuf
4495 ;; Avoid copying text props (except hard newlines).
4496 (insert (with-current-buffer mailbuf
4497 (mml-buffer-substring-no-properties-except-hard-newlines
4498 (point-min) (point-max))))
4499 ;; Remove some headers.
4500 (message-encode-message-body)
4502 (message-narrow-to-headers)
4503 ;; We (re)generate the Lines header.
4504 (when (memq 'Lines message-required-mail-headers
)
4505 (message-generate-headers '(Lines)))
4506 ;; Remove some headers.
4507 (message-remove-header message-ignored-mail-headers t
)
4508 (let ((mail-parse-charset message-default-charset
))
4509 (mail-encode-encoded-word-buffer)))
4510 (goto-char (point-max))
4511 ;; require one newline at the end.
4512 (or (= (preceding-char) ?
\n)
4514 (message-cleanup-headers)
4515 ;; FIXME: we're inserting the courtesy copy after encoding.
4516 ;; This is wrong if the courtesy copy string contains
4517 ;; non-ASCII characters. -- jh
4520 (message-narrow-to-headers)
4522 (or (message-fetch-field "cc")
4523 (message-fetch-field "bcc")
4524 (message-fetch-field "to"))
4525 (let ((content-type (message-fetch-field
4530 (string= "text/plain"
4532 (mail-header-parse-content-type
4536 (message-fetch-field
4537 "content-transfer-encoding")))))))
4538 (message-insert-courtesy-copy))
4539 ;; Let's make sure we encoded all the body.
4540 (assert (save-excursion
4541 (goto-char (point-min))
4542 (not (re-search-forward "[^\000-\377]" nil t
))))
4543 (mm-disable-multibyte)
4544 (if (or (not message-send-mail-partially-limit
)
4545 (< (buffer-size) message-send-mail-partially-limit
)
4546 (not (message-y-or-n-p
4547 "The message size is too large, split? "
4551 (/ (buffer-size) 1000) "KB, is too large.
4553 Some mail gateways (MTA's) bounce large messages. To avoid the
4554 problem, answer `y', and the message will be split into several
4555 smaller pieces, the size of each is about "
4556 (/ message-send-mail-partially-limit
1000)
4560 However, some mail readers (MUA's) can't read split messages, i.e.,
4561 mails in message/partially format. Answer `n', and the message will be
4564 The size limit is controlled by `message-send-mail-partially-limit'.
4565 If you always want Gnus to send messages in one piece, set
4566 `message-send-mail-partially-limit' to nil.
4569 (message "Sending via mail...")
4570 (funcall (or message-send-mail-real-function
4571 message-send-mail-function
)))
4572 (message-send-mail-partially)))
4573 (kill-buffer tembuf
))
4574 (set-buffer mailbuf
)
4575 (push 'mail message-sent-message-via
)))
4577 (defun message-send-mail-with-sendmail ()
4578 "Send off the prepared buffer with sendmail."
4580 (let ((errbuf (if message-interactive
4581 (message-generate-new-buffer-clone-locals
4584 resend-to-addresses delimline
)
4587 (let ((case-fold-search t
))
4589 (message-narrow-to-headers)
4590 (setq resend-to-addresses
(message-fetch-field "resent-to")))
4591 ;; Change header-delimiter to be what sendmail expects.
4592 (goto-char (point-min))
4594 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4595 (replace-match "\n")
4597 (setq delimline
(point-marker))
4598 (run-hooks 'message-send-mail-hook
)
4599 ;; Insert an extra newline if we need it to work around
4600 ;; Sun's bug that swallows newlines.
4601 (goto-char (1+ delimline
))
4602 (when (eval message-mailer-swallows-blank-line
)
4604 (when message-interactive
4605 (with-current-buffer errbuf
4607 (let* ((default-directory "/")
4608 (coding-system-for-write message-send-coding-system
)
4610 'call-process-region
4612 (list (point-min) (point-max)
4613 (cond ((boundp 'sendmail-program
)
4615 ((file-exists-p "/usr/sbin/sendmail")
4616 "/usr/sbin/sendmail")
4617 ((file-exists-p "/usr/lib/sendmail")
4618 "/usr/lib/sendmail")
4619 ((file-exists-p "/usr/ucblib/sendmail")
4620 "/usr/ucblib/sendmail")
4622 nil errbuf nil
"-oi")
4623 message-sendmail-extra-arguments
4624 ;; Always specify who from,
4625 ;; since some systems have broken sendmails.
4626 ;; But some systems are more broken with -f, so
4627 ;; we'll let users override this.
4628 (and (null message-sendmail-f-is-evil
)
4629 (list "-f" (message-sendmail-envelope-from)))
4630 ;; These mean "report errors by mail"
4631 ;; and "deliver in background".
4632 (if (null message-interactive
) '("-oem" "-odb"))
4633 ;; Get the addresses from the message
4634 ;; unless this is a resend.
4635 ;; We must not do that for a resend
4636 ;; because we would find the original addresses.
4637 ;; For a resend, include the specific addresses.
4638 (if resend-to-addresses
4639 (list resend-to-addresses
)
4641 (unless (or (null cpr
) (and (numberp cpr
) (zerop cpr
)))
4642 (if errbuf
(pop-to-buffer errbuf
))
4643 (error "Sending...failed with exit value %d" cpr
)))
4644 (when message-interactive
4645 (with-current-buffer errbuf
4646 (goto-char (point-min))
4647 (while (re-search-forward "\n+ *" nil t
)
4648 (replace-match "; "))
4649 (if (not (zerop (buffer-size)))
4650 (error "Sending...failed to %s"
4651 (buffer-string))))))
4652 (when (bufferp errbuf
)
4653 (kill-buffer errbuf
)))))
4655 (defun message-send-mail-with-qmail ()
4656 "Pass the prepared message buffer to qmail-inject.
4657 Refer to the documentation for the variable `message-send-mail-function'
4658 to find out how to use this."
4659 ;; replace the header delimiter with a blank line
4660 (goto-char (point-min))
4662 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4663 (replace-match "\n")
4664 (run-hooks 'message-send-mail-hook
)
4667 (let ((coding-system-for-write message-send-coding-system
))
4669 'call-process-region
(point-min) (point-max)
4670 message-qmail-inject-program nil nil nil
4671 ;; qmail-inject's default behavior is to look for addresses on the
4672 ;; command line; if there're none, it scans the headers.
4673 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4675 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4676 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4677 ;; message from stdin.
4679 ;; qmail also has the advantage of not having been raped by
4680 ;; various vendors, so we don't have to allow for that, either --
4681 ;; compare this with message-send-mail-with-sendmail and weep
4682 ;; for sendmail's lost innocence.
4684 ;; all this is way cool coz it lets us keep the arguments entirely
4685 ;; free for -inject-arguments -- a big win for the user and for us
4686 ;; since we don't have to play that double-guessing game and the user
4687 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4688 (if (functionp message-qmail-inject-args
)
4689 (funcall message-qmail-inject-args
)
4690 message-qmail-inject-args
)))
4691 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4692 ;; we have to look at the retval instead
4694 (100 (error "qmail-inject reported permanent failure"))
4695 (111 (error "qmail-inject reported transient failure"))
4696 ;; should never happen
4697 (t (error "qmail-inject reported unknown failure"))))
4699 (defun message-send-mail-with-mh ()
4700 "Send the prepared message buffer with mh."
4701 (let ((mh-previous-window-config nil
)
4702 (name (mh-new-draft-name)))
4703 (setq buffer-file-name name
)
4704 ;; MH wants to generate these headers itself.
4705 (when message-mh-deletable-headers
4706 (let ((headers message-mh-deletable-headers
))
4708 (goto-char (point-min))
4709 (and (re-search-forward
4710 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
4711 (message-delete-line))
4713 (run-hooks 'message-send-mail-hook
)
4714 ;; Pass it on to mh.
4717 (defun message-smtpmail-send-it ()
4718 "Send the prepared message buffer with `smtpmail-send-it'.
4719 The only difference from `smtpmail-send-it' is that this command
4720 evaluates `message-send-mail-hook' just before sending a message.
4721 It is useful if your ISP requires the POP-before-SMTP
4722 authentication. See the Gnus manual for details."
4723 (run-hooks 'message-send-mail-hook
)
4726 (defun message-send-mail-with-mailclient ()
4727 "Send the prepared message buffer with `mailclient-send-it'.
4728 The only difference from `mailclient-send-it' is that this
4729 command evaluates `message-send-mail-hook' just before sending a message."
4730 (run-hooks 'message-send-mail-hook
)
4731 (mailclient-send-it))
4733 (defun message-canlock-generate ()
4734 "Return a string that is non-trivial to guess.
4735 Do not use this for anything important, it is cryptographically weak."
4737 (let (sha1-maximum-internal-length)
4738 (sha1 (concat (message-unique-id)
4739 (format "%x%x%x" (random) (random t
) (random))
4740 (prin1-to-string (recent-keys))
4741 (prin1-to-string (garbage-collect))))))
4743 (defvar canlock-password
)
4744 (defvar canlock-password-for-verify
)
4746 (defun message-canlock-password ()
4747 "The password used by message for cancel locks.
4748 This is the value of `canlock-password', if that option is non-nil.
4749 Otherwise, generate and save a value for `canlock-password' first."
4751 (unless canlock-password
4752 (customize-save-variable 'canlock-password
(message-canlock-generate))
4753 (setq canlock-password-for-verify canlock-password
))
4756 (defun message-insert-canlock ()
4757 (when message-insert-canlock
4758 (message-canlock-password)
4759 (canlock-insert-header)))
4761 (autoload 'nnheader-get-report
"nnheader")
4763 (declare-function gnus-setup-posting-charset
"gnus-msg" (group))
4765 (defun message-send-news (&optional arg
)
4767 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4768 (case-fold-search nil
)
4769 (method (if (functionp message-post-method
)
4770 (funcall message-post-method arg
)
4771 message-post-method
))
4772 (newsgroups-field (save-restriction
4773 (message-narrow-to-headers-or-head)
4774 (message-fetch-field "Newsgroups")))
4775 (followup-field (save-restriction
4776 (message-narrow-to-headers-or-head)
4777 (message-fetch-field "Followup-To")))
4778 ;; BUG: We really need to get the charset for each name in the
4779 ;; Newsgroups and Followup-To lines to allow crossposting
4780 ;; between group namess with incompatible character sets.
4781 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4782 (group-field-charset
4783 (gnus-group-name-charset method newsgroups-field
))
4784 (followup-field-charset
4785 (gnus-group-name-charset method
(or followup-field
"")))
4786 (rfc2047-header-encoding-alist
4787 (append (when group-field-charset
4788 (list (cons "Newsgroups" group-field-charset
)))
4789 (when followup-field-charset
4790 (list (cons "Followup-To" followup-field-charset
)))
4791 rfc2047-header-encoding-alist
))
4792 (messbuf (current-buffer))
4793 (message-syntax-checks
4795 (listp message-syntax-checks
))
4796 (cons '(existing-newsgroups . disabled
)
4797 message-syntax-checks
)
4798 message-syntax-checks
))
4799 (message-this-is-news t
)
4800 (message-posting-charset
4801 (gnus-setup-posting-charset newsgroups-field
))
4803 (if (not (message-check-news-body-syntax))
4806 (message-narrow-to-headers)
4807 ;; Insert some headers.
4808 (message-generate-headers message-required-news-headers
)
4809 (message-insert-canlock)
4810 ;; Let the user do all of the above.
4811 (run-hooks 'message-header-hook
))
4812 ;; Note: This check will be disabled by the ".*" default value for
4813 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4814 (when (and group-field-charset
4815 (listp message-syntax-checks
))
4816 (setq message-syntax-checks
4817 (cons '(valid-newsgroups . disabled
)
4818 message-syntax-checks
)))
4819 (message-cleanup-headers)
4820 (if (not (let ((message-post-method method
))
4821 (message-check-news-syntax)))
4824 (with-current-buffer tembuf
4825 (buffer-disable-undo)
4827 ;; Avoid copying text props (except hard newlines).
4829 (with-current-buffer messbuf
4830 (mml-buffer-substring-no-properties-except-hard-newlines
4831 (point-min) (point-max))))
4832 (message-encode-message-body)
4833 ;; Remove some headers.
4835 (message-narrow-to-headers)
4836 ;; We (re)generate the Lines header.
4837 (when (memq 'Lines message-required-mail-headers
)
4838 (message-generate-headers '(Lines)))
4839 ;; Remove some headers.
4840 (message-remove-header message-ignored-news-headers t
)
4841 (let ((mail-parse-charset message-default-charset
))
4842 (mail-encode-encoded-word-buffer)))
4843 (goto-char (point-max))
4844 ;; require one newline at the end.
4845 (or (= (preceding-char) ?
\n)
4847 (let ((case-fold-search t
))
4848 ;; Remove the delimiter.
4849 (goto-char (point-min))
4851 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4852 (replace-match "\n")
4854 (run-hooks 'message-send-news-hook
)
4855 (gnus-open-server method
)
4856 (message "Sending news via %s..." (gnus-server-string method
))
4857 (setq result
(let ((mail-header-separator ""))
4858 (gnus-request-post method
))))
4859 (kill-buffer tembuf
))
4860 (set-buffer messbuf
)
4862 (push 'news message-sent-message-via
)
4863 (message "Couldn't send message via news: %s"
4864 (nnheader-get-report (car method
)))
4868 ;;; Header generation & syntax checking.
4871 (defun message-check-element (type)
4872 "Return non-nil if this TYPE is not to be checked."
4873 (if (eq message-syntax-checks
'dont-check-for-anything-just-trust-me
)
4875 (let ((able (assq type message-syntax-checks
)))
4877 (eq (cdr able
) 'disabled
)))))
4879 (defun message-check-news-syntax ()
4880 "Check the syntax of the message."
4884 ;; We narrow to the headers and check them first.
4887 (message-narrow-to-headers)
4888 (message-check-news-header-syntax))))))
4890 (defun message-check-news-header-syntax ()
4892 ;; Check Newsgroups header.
4893 (message-check 'newsgroups
4894 (let ((group (message-fetch-field "newsgroups")))
4897 (not (string-match "\\`[ \t]*\\'" group
)))
4900 "The newsgroups field is empty or missing. Posting is denied.")))))
4901 ;; Check the Subject header.
4902 (message-check 'subject
4903 (let* ((case-fold-search t
)
4904 (subject (message-fetch-field "subject")))
4907 (not (string-match "\\`[ \t]*\\'" subject
)))
4910 "The subject field is empty or missing. Posting is denied.")))))
4911 ;; Check for commands in Subject.
4912 (message-check 'subject-cmsg
4913 (if (string-match "^cmsg " (message-fetch-field "subject"))
4915 "The control code \"cmsg\" is in the subject. Really post? ")
4917 ;; Check long header lines.
4918 (message-check 'long-header-lines
4919 (let ((start (point))
4923 (while (and (not found
)
4924 (re-search-forward "^\\([^ \t:]+\\): " nil t
))
4925 (if (> (- (point) (match-beginning 0)) 998)
4927 length
(- (point) (match-beginning 0)))
4928 (setq header
(match-string-no-properties 1)))
4929 (setq start
(match-beginning 0))
4932 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
4935 ;; Check for multiple identical headers.
4936 (message-check 'multiple-headers
4938 (while (and (not found
)
4939 (re-search-forward "^[^ \t:]+: " nil t
))
4941 (or (re-search-forward
4946 (match-beginning 0) (- (match-end 0) 2))))
4951 (y-or-n-p (format "Multiple %s headers. Really post? " found
))
4953 ;; Check for Version and Sendsys.
4954 (message-check 'sendsys
4955 (if (re-search-forward "^Sendsys:\\|^Version:" nil t
)
4957 (format "The article contains a %s command. Really post? "
4958 (buffer-substring (match-beginning 0)
4959 (1- (match-end 0)))))
4961 ;; See whether we can shorten Followup-To.
4962 (message-check 'shorten-followup-to
4963 (let ((newsgroups (message-fetch-field "newsgroups"))
4964 (followup-to (message-fetch-field "followup-to"))
4966 (when (and newsgroups
4967 (string-match "," newsgroups
)
4972 (setq to
(completing-read
4973 "Followups to (default no Followup-To header): "
4976 (message-tokenize-header
4978 (goto-char (point-min))
4979 (insert "Followup-To: " to
"\n"))
4981 ;; Check "Shoot me".
4982 (message-check 'shoot
4983 (if (re-search-forward
4984 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t
)
4985 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
4987 ;; Check for Approved.
4988 (message-check 'approved
4989 (if (re-search-forward "^Approved:" nil t
)
4990 (y-or-n-p "The article contains an Approved header. Really post? ")
4992 ;; Check the Message-ID header.
4993 (message-check 'message-id
4994 (let* ((case-fold-search t
)
4995 (message-id (message-fetch-field "message-id" t
)))
4996 (or (not message-id
)
4997 ;; Is there an @ in the ID?
4998 (and (string-match "@" message-id
)
4999 ;; Is there a dot in the ID?
5000 (string-match "@[^.]*\\." message-id
)
5001 ;; Does the ID end with a dot?
5002 (not (string-match "\\.>" message-id
)))
5004 (format "The Message-ID looks strange: \"%s\". Really post? "
5006 ;; Check the Newsgroups & Followup-To headers.
5007 (message-check 'existing-newsgroups
5008 (let* ((case-fold-search t
)
5009 (newsgroups (message-fetch-field "newsgroups"))
5010 (followup-to (message-fetch-field "followup-to"))
5011 (groups (message-tokenize-header
5013 (concat newsgroups
"," followup-to
)
5015 (post-method (if (functionp message-post-method
)
5016 (funcall message-post-method
)
5017 message-post-method
))
5018 ;; KLUDGE to handle nnvirtual groups. Doing this right
5019 ;; would probably involve a new nnoo function.
5020 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
5021 (method (if (and (consp post-method
)
5022 (eq (car post-method
) 'nnvirtual
)
5023 gnus-message-group-art
)
5024 (let ((group (car (nnvirtual-find-group-art
5025 (car gnus-message-group-art
)
5026 (cdr gnus-message-group-art
)))))
5027 (gnus-find-method-for-group group
))
5031 (gnus-group-name-decode
5032 (gnus-group-real-name n
)
5033 (gnus-group-name-charset method n
)))
5034 (gnus-groups-from-server method
)))
5037 (when (and (not (equal (car groups
) "poster"))
5038 (not (member (car groups
) known-groups
))
5039 (not (member (car groups
) errors
)))
5040 (push (car groups
) errors
))
5043 ;; Gnus is not running.
5044 ((or (not (and (boundp 'gnus-active-hashtb
)
5045 gnus-active-hashtb
))
5046 (not (boundp 'gnus-read-active-file
)))
5048 ;; We don't have all the group names.
5049 ((and (or (not gnus-read-active-file
)
5050 (eq gnus-read-active-file
'some
))
5054 "Really use %s possibly unknown group%s: %s? "
5055 (if (= (length errors
) 1) "this" "these")
5056 (if (= (length errors
) 1) "" "s")
5057 (mapconcat 'identity errors
", "))))
5058 ;; There were no errors.
5061 ;; There are unknown groups.
5065 "Really post to %s unknown group%s: %s? "
5066 (if (= (length errors
) 1) "this" "these")
5067 (if (= (length errors
) 1) "" "s")
5068 (mapconcat 'identity errors
", ")))))))
5069 ;; Check continuation headers.
5070 (message-check 'continuation-headers
5071 (goto-char (point-min))
5072 (let ((do-posting t
))
5073 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t
)
5074 (goto-char (match-beginning 0))
5075 (if (y-or-n-p "Fix continuation lines? ")
5078 (unless (y-or-n-p "Send anyway? ")
5079 (setq do-posting nil
))))
5081 ;; Check the Newsgroups & Followup-To headers for syntax errors.
5082 (message-check 'valid-newsgroups
5083 (let ((case-fold-search t
)
5084 (headers '("Newsgroups" "Followup-To"))
5086 (while (and headers
(not error
))
5087 (when (setq header
(mail-fetch-field (car headers
)))
5091 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
5096 (not (string-match "\\.\\'\\|\\.\\." g
)))
5097 (message-tokenize-header header
","))))
5104 (format "The %s header looks odd: \"%s\". Really post? "
5105 (car headers
) header
)))))
5106 (message-check 'repeated-newsgroups
5107 (let ((case-fold-search t
)
5108 (headers '("Newsgroups" "Followup-To"))
5109 header error groups group
)
5112 (when (setq header
(mail-fetch-field (pop headers
)))
5113 (setq groups
(message-tokenize-header header
","))
5114 (while (setq group
(pop groups
))
5115 (when (member group groups
)
5121 (format "Group %s is repeated in headers. Really post? " error
)))))
5122 ;; Check the From header.
5123 (message-check 'from
5124 (let* ((case-fold-search t
)
5125 (from (message-fetch-field "from"))
5129 (message "There is no From line. Posting is denied.")
5131 ((or (not (string-match
5133 (setq ad
(nth 1 (mail-extract-address-components
5134 from
))))) ;larsi@ifi
5135 (string-match "\\.\\." ad
) ;larsi@ifi..uio
5136 (string-match "@\\." ad
) ;larsi@.ifi.uio
5137 (string-match "\\.$" ad
) ;larsi@ifi.uio.
5138 (not (string-match "^[^@]+@[^@]+$" ad
)) ;larsi.ifi.uio
5139 (string-match "(.*).*(.*)" from
)) ;(lars) (lars)
5141 "Denied posting -- the From looks strange: \"%s\"." from
)
5143 ((let ((addresses (rfc822-addresses from
)))
5144 ;; `rfc822-addresses' returns a string if parsing fails.
5145 (while (and (consp addresses
)
5146 (not (eq (string-to-char (car addresses
)) ?\
()))
5147 (setq addresses
(cdr addresses
)))
5150 "Denied posting -- bad From address: \"%s\"." from
)
5153 ;; Check the Reply-To header.
5154 (message-check 'reply-to
5155 (let* ((case-fold-search t
)
5156 (reply-to (message-fetch-field "reply-to"))
5161 ((string-match "," reply-to
)
5163 (format "Multiple Reply-To addresses: \"%s\". Really post? "
5165 ((or (not (string-match
5167 (setq ad
(nth 1 (mail-extract-address-components
5168 reply-to
))))) ;larsi@ifi
5169 (string-match "\\.\\." ad
) ;larsi@ifi..uio
5170 (string-match "@\\." ad
) ;larsi@.ifi.uio
5171 (string-match "\\.$" ad
) ;larsi@ifi.uio.
5172 (not (string-match "^[^@]+@[^@]+$" ad
)) ;larsi.ifi.uio
5173 (string-match "(.*).*(.*)" reply-to
)) ;(lars) (lars)
5176 "The Reply-To looks strange: \"%s\". Really post? "
5180 (defun message-check-news-body-syntax ()
5182 ;; Check for long lines.
5183 (message-check 'long-lines
5184 (goto-char (point-min))
5186 (concat "^" (regexp-quote mail-header-separator
) "$"))
5190 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
5193 (< (- (point) p
) 80)))
5194 (zerop (forward-line 1))))
5198 "You have lines longer than 79 characters. Really post? ")))
5199 ;; Check whether the article is empty.
5200 (message-check 'empty
5201 (goto-char (point-min))
5203 (concat "^" (regexp-quote mail-header-separator
) "$"))
5206 (goto-char (point-max))
5207 (re-search-backward message-signature-separator nil t
)
5209 (or (re-search-backward "[^ \n\t]" b t
)
5210 (if (message-gnksa-enable-p 'empty-article
)
5211 (y-or-n-p "Empty article. Really post? ")
5212 (message "Denied posting -- Empty article.")
5214 ;; Check for control characters.
5215 (message-check 'control-chars
5216 (if (re-search-forward
5217 (mm-string-to-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
5220 "The article contains control characters. Really post? ")
5222 ;; Check excessive size.
5223 (message-check 'size
5224 (if (> (buffer-size) 60000)
5226 (format "The article is %d octets long. Really post? "
5229 ;; Check whether any new text has been added.
5230 (message-check 'new-text
5232 (not message-checksum
)
5233 (not (eq (message-checksum) message-checksum
))
5234 (if (message-gnksa-enable-p 'quoted-text-only
)
5236 "It looks like no new text has been added. Really post? ")
5237 (message "Denied posting -- no new text has been added.")
5239 ;; Check the length of the signature.
5240 (message-check 'signature
5241 (let (sig-start sig-end
)
5242 (goto-char (point-max))
5243 (if (not (re-search-backward message-signature-separator nil t
))
5245 (setq sig-start
(1+ (point-at-eol)))
5247 (if (re-search-forward
5248 "<#/?\\(multipart\\|part\\|external\\|mml\\)" nil t
)
5249 (- (point-at-bol) 1)
5251 (if (>= (count-lines sig-start sig-end
) 5)
5252 (if (message-gnksa-enable-p 'signature
)
5254 (format "Signature is excessively long (%d lines). Really post? "
5255 (count-lines sig-start sig-end
)))
5256 (message "Denied posting -- Excessive signature.")
5259 ;; Ensure that text follows last quoted portion.
5260 (message-check 'quoting-style
5261 (goto-char (point-max))
5262 (let ((no-problem t
))
5263 (when (search-backward-regexp "^>[^\n]*\n" nil t
)
5264 (setq no-problem
(search-forward-regexp "^[ \t]*[^>\n]" nil t
)))
5267 (if (message-gnksa-enable-p 'quoted-text-only
)
5268 (y-or-n-p "Your text should follow quoted text. Really post? ")
5270 (goto-char (point-min))
5272 (concat "^" (regexp-quote mail-header-separator
) "$"))
5273 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t
)
5274 (y-or-n-p "Your text should follow quoted text. Really post? ")
5275 (message "Denied posting -- only quoted text.")
5278 (defun message-checksum ()
5279 "Return a \"checksum\" for the current buffer."
5282 (goto-char (point-min))
5284 (concat "^" (regexp-quote mail-header-separator
) "$"))
5286 (when (not (looking-at "[ \t\n]"))
5287 (setq sum
(logxor (ash sum
1) (if (natnump sum
) 0 1)
5292 (defun message-do-fcc ()
5293 "Process Fcc headers in the current buffer."
5294 (let ((case-fold-search t
)
5295 (buf (current-buffer))
5297 (mml-externalize-attachments message-fcc-externalize-attachments
))
5300 (message-narrow-to-headers)
5301 (setq file
(message-fetch-field "fcc" t
)))
5303 (set-buffer (get-buffer-create " *message temp*"))
5305 (insert-buffer-substring buf
)
5306 (message-encode-message-body)
5308 (message-narrow-to-headers)
5309 (while (setq file
(message-fetch-field "fcc" t
))
5311 (message-remove-header "fcc" nil t
))
5312 (let ((mail-parse-charset message-default-charset
)
5313 (rfc2047-header-encoding-alist
5314 (cons '("Newsgroups" . default
)
5315 rfc2047-header-encoding-alist
)))
5316 (mail-encode-encoded-word-buffer)))
5317 (goto-char (point-min))
5318 (when (re-search-forward
5319 (concat "^" (regexp-quote mail-header-separator
) "$")
5321 (replace-match "" t t
))
5322 ;; Process FCC operations.
5324 (setq file
(pop list
))
5325 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file
)
5326 ;; Pipe the article to the program in question.
5327 (call-process-region (point-min) (point-max) shell-file-name
5328 nil nil nil shell-command-switch
5329 (match-string 1 file
))
5330 ;; Save the article.
5331 (setq file
(expand-file-name file
))
5332 (unless (file-exists-p (file-name-directory file
))
5333 (make-directory (file-name-directory file
) t
))
5334 (if (and message-fcc-handler-function
5335 (not (eq message-fcc-handler-function
'rmail-output
)))
5336 (funcall message-fcc-handler-function file
)
5337 ;; FIXME this option, rmail-output (also used if
5338 ;; message-fcc-handler-function is nil) is not
5339 ;; documented anywhere AFAICS. It should work in Emacs
5340 ;; 23; I suspect it does not work in Emacs 22.
5341 ;; FIXME I don't see the need for the two different cases here.
5342 ;; mail-use-rfc822 makes no difference (in Emacs 23),and
5343 ;; the third argument just controls \"Wrote file\" message.
5344 (if (and (file-readable-p file
) (mail-file-babyl-p file
))
5345 (rmail-output file
1 nil t
)
5346 (let ((mail-use-rfc822 t
))
5347 (rmail-output file
1 t t
))))))
5348 (kill-buffer (current-buffer))))))
5350 (defun message-output (filename)
5351 "Append this article to Unix/babyl mail file FILENAME."
5352 (if (and (file-readable-p filename
)
5353 (mail-file-babyl-p filename
))
5354 (gnus-output-to-rmail filename t
)
5355 (gnus-output-to-mail filename t
)))
5357 (defun message-cleanup-headers ()
5358 "Do various automatic cleanups of the headers."
5359 ;; Remove empty lines in the header.
5361 (message-narrow-to-headers)
5362 ;; Remove blank lines.
5363 (while (re-search-forward "^[ \t]*\n" nil t
)
5364 (replace-match "" t t
))
5366 ;; Correct Newsgroups and Followup-To headers: Change sequence of
5367 ;; spaces to comma and eliminate spaces around commas. Eliminate
5368 ;; embedded line breaks.
5369 (goto-char (point-min))
5370 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t
)
5374 (if (re-search-forward "^[^ \t]" nil t
)
5378 (goto-char (point-min))
5379 (while (re-search-forward "\n[ \t]+" nil t
)
5380 (replace-match " " t t
)) ;No line breaks (too confusing)
5381 (goto-char (point-min))
5382 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t
)
5383 (replace-match "," t t
))
5384 (goto-char (point-min))
5385 ;; Remove trailing commas.
5386 (when (re-search-forward ",+$" nil t
)
5387 (replace-match "" t t
))))))
5389 (defun message-make-date (&optional now
)
5390 "Make a valid data header.
5391 If NOW, use that time instead."
5392 (let ((system-time-locale "C"))
5393 (format-time-string "%a, %d %b %Y %T %z" now
)))
5395 (defun message-insert-expires (days)
5396 "Insert the Expires header. Expiry in DAYS days."
5397 (interactive "NExpire article in how many days? ")
5399 (message-position-on-field "Expires" "X-Draft-From")
5400 (insert (message-make-expires-date days
))))
5402 (defun message-make-expires-date (days)
5403 "Make date string for the Expires header. Expiry in DAYS days.
5405 In posting styles use `(\"Expires\" (make-expires-date 30))'."
5406 (let* ((cur (decode-time (current-time)))
5407 (nday (+ days
(nth 3 cur
))))
5408 (setf (nth 3 cur
) nday
)
5409 (message-make-date (apply 'encode-time cur
))))
5411 (defun message-make-message-id ()
5412 "Make a unique Message-ID."
5413 (concat "<" (message-unique-id)
5414 (let ((psubject (save-excursion (message-fetch-field "subject")))
5416 (save-excursion (message-fetch-field "supersedes"))))
5418 (and message-reply-headers
5419 (mail-header-references message-reply-headers
)
5420 (mail-header-subject message-reply-headers
)
5423 (message-strip-subject-re
5424 (mail-header-subject message-reply-headers
))
5425 (message-strip-subject-re psubject
))))
5427 (string-match "_-_@" psupersedes
)))
5429 "@" (message-make-fqdn) ">"))
5431 (defvar message-unique-id-char nil
)
5433 ;; If you ever change this function, make sure the new version
5434 ;; cannot generate IDs that the old version could.
5435 ;; You might for example insert a "." somewhere (not next to another dot
5436 ;; or string boundary), or modify the "fsf" string.
5437 (defun message-unique-id ()
5438 ;; Don't use microseconds from (current-time), they may be unsupported.
5439 ;; Instead we use this randomly inited counter.
5440 (setq message-unique-id-char
5441 (%
(1+ (or message-unique-id-char
(logand (random t
) (1- (lsh 1 20)))))
5442 ;; (current-time) returns 16-bit ints,
5443 ;; and 2^16*25 just fits into 4 digits i base 36.
5445 (let ((tm (current-time)))
5447 (if (or (eq system-type
'ms-dos
)
5448 ;; message-number-base36 doesn't handle bigints.
5449 (floatp (user-uid)))
5450 (let ((user (downcase (user-login-name))))
5451 (while (string-match "[^a-z0-9_]" user
)
5452 (aset user
(match-beginning 0) ?_
))
5454 (message-number-base36 (user-uid) -
1))
5455 (message-number-base36 (+ (car tm
)
5456 (lsh (% message-unique-id-char
25) 16)) 4)
5457 (message-number-base36 (+ (nth 1 tm
)
5458 (lsh (/ message-unique-id-char
25) 16)) 4)
5459 ;; Append a given name, because while the generated ID is unique
5460 ;; to this newsreader, other newsreaders might otherwise generate
5461 ;; the same ID via another algorithm.
5464 (defun message-number-base36 (num len
)
5469 (concat (message-number-base36 (/ num
36) (1- len
))
5470 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
5473 (defun message-make-organization ()
5474 "Make an Organization header."
5475 (let* ((organization
5476 (when message-user-organization
5477 (if (functionp message-user-organization
)
5478 (funcall message-user-organization
)
5479 message-user-organization
))))
5481 (mm-enable-multibyte)
5482 (cond ((stringp organization
)
5483 (insert organization
))
5484 ((and (eq t organization
)
5485 message-user-organization-file
5486 (file-exists-p message-user-organization-file
))
5487 (insert-file-contents message-user-organization-file
)))
5488 (goto-char (point-min))
5489 (while (re-search-forward "[\t\n]+" nil t
)
5490 (replace-match "" t t
))
5491 (unless (zerop (buffer-size))
5494 (defun message-make-lines ()
5495 "Count the number of lines and return numeric string."
5500 (int-to-string (count-lines (point) (point-max))))))
5502 (defun message-make-references ()
5503 "Return the References header for this message."
5504 (when message-reply-headers
5505 (let ((message-id (mail-header-id message-reply-headers
))
5506 (references (mail-header-references message-reply-headers
)))
5507 (if (or references message-id
)
5508 (concat (or references
"") (and references
" ")
5512 (defun message-make-in-reply-to ()
5513 "Return the In-Reply-To header for this message."
5514 (when message-reply-headers
5515 (let ((from (mail-header-from message-reply-headers
))
5516 (date (mail-header-date message-reply-headers
))
5517 (msg-id (mail-header-id message-reply-headers
)))
5519 (let ((name (mail-extract-address-components from
)))
5521 msg-id
(if msg-id
" (")
5523 (if (string-match "[^\000-\177]" (car name
))
5524 ;; Quote a string containing non-ASCII characters.
5525 ;; It will make the RFC2047 encoder cause an error
5526 ;; if there are special characters.
5527 (mm-with-multibyte-buffer
5529 (goto-char (point-min))
5530 (while (search-forward "\"" nil t
)
5533 (zerop (%
(skip-chars-backward "\\\\") 2))
5534 (goto-char (match-beginning 0)))
5537 ;; Those quotes will be removed by the RFC2047 encoder.
5538 (concat "\"" (buffer-string) "\""))
5542 (if (or (not date
) (string= date
""))
5543 "(unknown date)" date
)
5544 "\"" (if msg-id
")")))))))
5546 (defun message-make-distribution ()
5547 "Make a Distribution header."
5548 (let ((orig-distribution (message-fetch-reply-field "distribution")))
5549 (cond ((functionp message-distribution-function
)
5550 (funcall message-distribution-function
))
5551 (t orig-distribution
))))
5553 (defun message-make-expires ()
5554 "Return an Expires header based on `message-expires'."
5555 (let ((current (current-time))
5556 (future (* 1.0 message-expires
60 60 24)))
5557 ;; Add the future to current.
5558 (setcar current
(+ (car current
) (round (/ future
(expt 2 16)))))
5559 (setcar (cdr current
) (+ (nth 1 current
) (%
(round future
) (expt 2 16))))
5560 (message-make-date current
)))
5562 (defun message-make-path ()
5564 (let ((login-name (user-login-name)))
5565 (cond ((null message-user-path
)
5566 (concat (system-name) "!" login-name
))
5567 ((stringp message-user-path
)
5568 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
5569 (concat message-user-path
"!" login-name
))
5572 (defun message-make-from (&optional name address
)
5573 "Make a From header."
5574 (let* ((style message-from-style
)
5575 (login (or address
(message-make-address)))
5577 (and (boundp 'user-full-name
)
5580 (when (string= fullname
"&")
5581 (setq fullname
(user-login-name)))
5583 (mm-enable-multibyte)
5586 (equal fullname
""))
5588 ((or (eq style
'angles
)
5589 (and (not (eq style
'parens
))
5590 ;; Use angles if no quoting is needed, or if parens would
5591 ;; need quoting too.
5592 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname
))
5593 (let ((tmp (concat fullname nil
)))
5594 (while (string-match "([^()]*)" tmp
)
5595 (aset tmp
(match-beginning 0) ?-
)
5596 (aset tmp
(1- (match-end 0)) ?-
))
5597 (string-match "[\\()]" tmp
)))))
5599 (goto-char (point-min))
5600 ;; Look for a character that cannot appear unquoted
5601 ;; according to RFC 822.
5602 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil
1)
5603 ;; Quote fullname, escaping specials.
5604 (goto-char (point-min))
5606 (while (re-search-forward "[\"\\]" nil
1)
5607 (replace-match "\\\\\\&" t
))
5609 (insert " <" login
">"))
5610 (t ; 'parens or default
5612 (let ((fullname-start (point)))
5614 (goto-char fullname-start
)
5615 ;; RFC 822 says \ and nonmatching parentheses
5616 ;; must be escaped in comments.
5617 ;; Escape every instance of ()\ ...
5618 (while (re-search-forward "[()\\]" nil
1)
5619 (replace-match "\\\\\\&" t
))
5620 ;; ... then undo escaping of matching parentheses,
5621 ;; including matching nested parentheses.
5622 (goto-char fullname-start
)
5623 (while (re-search-forward
5624 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
5626 (replace-match "\\1(\\3)" t
)
5627 (goto-char fullname-start
)))
5631 (defun message-make-sender ()
5632 "Return the \"real\" user address.
5633 This function tries to ignore all user modifications, and
5634 give as trustworthy answer as possible."
5635 (concat (user-login-name) "@" (system-name)))
5637 (defun message-make-address ()
5638 "Make the address of the user."
5639 (or (message-user-mail-address)
5640 (concat (user-login-name) "@" (message-make-domain))))
5642 (defun message-user-mail-address ()
5643 "Return the pertinent part of `user-mail-address'."
5644 (when (and user-mail-address
5645 (string-match "@.*\\." user-mail-address
))
5646 (if (string-match " " user-mail-address
)
5647 (nth 1 (mail-extract-address-components user-mail-address
))
5648 user-mail-address
)))
5650 (defun message-sendmail-envelope-from ()
5651 "Return the envelope from."
5652 (cond ((eq message-sendmail-envelope-from
'header
)
5653 (nth 1 (mail-extract-address-components
5654 (message-fetch-field "from"))))
5655 ((stringp message-sendmail-envelope-from
)
5656 message-sendmail-envelope-from
)
5658 (message-make-address))))
5660 (defun message-make-fqdn ()
5661 "Return user's fully qualified domain name."
5662 (let* ((system-name (system-name))
5663 (user-mail (message-user-mail-address))
5666 (string-match "@\\(.*\\)\\'" user-mail
))
5667 (match-string 1 user-mail
)))
5668 (case-fold-search t
))
5670 ((and message-user-fqdn
5671 (stringp message-user-fqdn
)
5672 (string-match message-valid-fqdn-regexp message-user-fqdn
)
5673 (not (string-match message-bogus-system-names message-user-fqdn
)))
5674 ;; `message-user-fqdn' seems to be valid
5676 ((and (string-match message-valid-fqdn-regexp system-name
)
5677 (not (string-match message-bogus-system-names system-name
)))
5678 ;; `system-name' returned the right result.
5680 ;; Try `mail-host-address'.
5681 ((and (boundp 'mail-host-address
)
5682 (stringp mail-host-address
)
5683 (string-match message-valid-fqdn-regexp mail-host-address
)
5684 (not (string-match message-bogus-system-names mail-host-address
)))
5686 ;; We try `user-mail-address' as a backup.
5688 (stringp user-domain
)
5689 (string-match message-valid-fqdn-regexp user-domain
)
5690 (not (string-match message-bogus-system-names user-domain
)))
5692 ;; Default to this bogus thing.
5695 ".i-did-not-set--mail-host-address--so-tickle-me")))))
5697 (defun message-make-host-name ()
5698 "Return the name of the host."
5699 (let ((fqdn (message-make-fqdn)))
5700 (string-match "^[^.]+\\." fqdn
)
5701 (substring fqdn
0 (1- (match-end 0)))))
5703 (defun message-make-domain ()
5704 "Return the domain name."
5705 (or mail-host-address
5706 (message-make-fqdn)))
5708 (defun message-to-list-only ()
5709 "Send a message to the list only.
5710 Remove all addresses but the list address from To and Cc headers."
5712 (let ((listaddr (message-make-mail-followup-to t
)))
5715 (message-remove-header "to")
5716 (message-remove-header "cc")
5717 (message-position-on-field "To" "X-Draft-From")
5718 (insert listaddr
)))))
5720 (defun message-make-mail-followup-to (&optional only-show-subscribed
)
5721 "Return the Mail-Followup-To header.
5722 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5723 subscribed address (and not the additional To and Cc header contents)."
5724 (let* ((case-fold-search t
)
5725 (to (message-fetch-field "To"))
5726 (cc (message-fetch-field "cc"))
5727 (msg-recipients (concat to
(and to cc
", ") cc
))
5729 (mapcar 'mail-strip-quoted-names
5730 (message-tokenize-header msg-recipients
)))
5732 (if message-subscribed-address-file
5733 (let (begin end item re
)
5736 (insert-file-contents message-subscribed-address-file
)
5738 (setq begin
(point))
5741 (if (bolp) (setq end
(1- end
)))
5742 (setq item
(regexp-quote (buffer-substring begin end
)))
5743 (if re
(setq re
(concat re
"\\|" item
))
5744 (setq re
(concat "\\`\\(" item
))))
5745 (and re
(list (concat re
"\\)\\'"))))))))
5746 (mft-regexps (apply 'append message-subscribed-regexps
5747 (mapcar 'regexp-quote
5748 message-subscribed-addresses
)
5751 message-subscribed-address-functions
))))
5754 (loop for recipient in recipients
5755 when
(loop for regexp in mft-regexps
5756 when
(string-match regexp recipient
) return t
)
5759 (if only-show-subscribed
5761 msg-recipients
))))))
5763 (defun message-idna-to-ascii-rhs-1 (header)
5764 "Interactively potentially IDNA encode domain names in HEADER."
5765 (let ((field (message-fetch-field header
))
5769 (mm-delete-duplicates
5770 (mapcar (lambda (rhs) (or (cadr (split-string rhs
"@")) ""))
5774 (mail-extract-address-components field t
))))))
5775 ;; Note that `rhs' will be "" if the address does not have
5776 ;; the domain part, i.e., if it is a local user's address.
5777 (setq ace
(if (string-match "\\`[[:ascii:]]*\\'" rhs
)
5779 (downcase (idna-to-ascii rhs
))))
5780 (when (and (not (equal rhs ace
))
5781 (or (not (eq message-use-idna
'ask
))
5782 (y-or-n-p (format "Replace %s with %s in %s:? "
5784 (goto-char (point-min))
5785 (while (re-search-forward (concat "^" header
":") nil t
)
5786 (message-narrow-to-field)
5787 (while (search-forward (concat "@" rhs
) nil t
)
5788 (replace-match (concat "@" ace
) t t
))
5789 (goto-char (point-max))
5792 (defun message-idna-to-ascii-rhs ()
5793 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
5794 See `message-idna-encode'."
5796 (when message-use-idna
5799 ;; `message-narrow-to-head' that recognizes only the first empty
5800 ;; line as the message header separator used to be used here.
5801 ;; However, since there is the "--text follows this line--" line
5802 ;; normally, it failed in narrowing to the headers and potentially
5803 ;; caused the IDNA encoding on lines that look like headers in
5804 ;; the message body.
5805 (message-narrow-to-headers-or-head)
5806 (message-idna-to-ascii-rhs-1 "From")
5807 (message-idna-to-ascii-rhs-1 "To")
5808 (message-idna-to-ascii-rhs-1 "Reply-To")
5809 (message-idna-to-ascii-rhs-1 "Mail-Reply-To")
5810 (message-idna-to-ascii-rhs-1 "Mail-Followup-To")
5811 (message-idna-to-ascii-rhs-1 "Cc")))))
5813 (defun message-generate-headers (headers)
5814 "Prepare article HEADERS.
5815 Headers already prepared in the buffer are not modified."
5816 (setq headers
(append headers message-required-headers
))
5818 (message-narrow-to-headers)
5819 (let* ((Date (message-make-date))
5820 (Message-ID (message-make-message-id))
5821 (Organization (message-make-organization))
5822 (From (message-make-from))
5823 (Path (message-make-path))
5826 (In-Reply-To (message-make-in-reply-to))
5827 (References (message-make-references))
5829 (Distribution (message-make-distribution))
5830 (Lines (message-make-lines))
5831 (User-Agent message-newsreader
)
5832 (Expires (message-make-expires))
5833 (case-fold-search t
)
5835 header value elem header-string
)
5836 ;; First we remove any old generated headers.
5837 (let ((headers message-deletable-headers
))
5838 (unless (buffer-modified-p)
5839 (setq headers
(delq 'Message-ID
(copy-sequence headers
))))
5841 (goto-char (point-min))
5842 (and (re-search-forward
5843 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
5844 (get-text-property (1+ (match-beginning 0)) 'message-deletable
)
5845 (message-delete-line))
5847 ;; Go through all the required headers and see if they are in the
5848 ;; articles already. If they are not, or are empty, they are
5849 ;; inserted automatically - except for Subject, Newsgroups and
5852 (goto-char (point-min))
5853 (setq elem
(pop headers
))
5855 (if (eq (car elem
) 'optional
)
5856 (setq header
(cdr elem
)
5858 (setq header
(car elem
)))
5860 (setq header-string
(if (stringp header
)
5862 (symbol-name header
)))
5863 (when (or (not (re-search-forward
5865 (regexp-quote (downcase header-string
))
5869 ;; The header was found. We insert a space after the
5870 ;; colon, if there is none.
5871 (if (/= (char-after) ?
) (insert " ") (forward-char 1))
5872 ;; Find out whether the header is empty.
5873 (looking-at "[ \t]*\n[^ \t]")))
5874 ;; So we find out what value we should insert.
5878 (eq (car elem
) 'optional
)
5879 (not (member header-string message-inserted-headers
)))
5880 ;; This is an optional header. If the cdr of this
5881 ;; is something that is nil, then we do not insert
5883 (setq header
(cdr elem
))
5884 (or (and (functionp (cdr elem
))
5885 (funcall (cdr elem
)))
5886 (and (boundp (cdr elem
))
5887 (symbol-value (cdr elem
)))))
5889 ;; The element is a cons. Either the cdr is a
5890 ;; string to be inserted verbatim, or it is a
5891 ;; function, and we insert the value returned from
5893 (or (and (stringp (cdr elem
))
5895 (and (functionp (cdr elem
))
5896 (funcall (cdr elem
)))))
5897 ((and (boundp header
)
5898 (symbol-value header
))
5899 ;; The element is a symbol. We insert the value
5900 ;; of this symbol, if any.
5901 (symbol-value header
))
5902 ((not (message-check-element
5903 (intern (downcase (symbol-name header
)))))
5904 ;; We couldn't generate a value for this header,
5905 ;; so we just ask the user.
5906 (read-from-minibuffer
5907 (format "Empty header for %s; enter value: " header
)))))
5908 ;; Finally insert the header.
5910 (not (equal value
"")))
5914 ;; This header didn't exist, so we insert it.
5915 (goto-char (point-max))
5917 (cdr (assq header message-header-format-alist
))))
5919 (funcall formatter header value
)
5920 (insert header-string
": " value
))
5921 (push header-string message-inserted-headers
)
5922 (goto-char (message-fill-field))
5923 ;; We check whether the value was ended by a
5924 ;; newline. If not, we insert one.
5928 ;; The value of this header was empty, so we clear
5929 ;; totally and insert the new value.
5930 (delete-region (point) (point-at-eol))
5931 ;; If the header is optional, and the header was
5932 ;; empty, we can't insert it anyway.
5934 (push header-string message-inserted-headers
)
5936 (message-fill-field)))
5937 ;; Add the deletable property to the headers that require it.
5938 (and (memq header message-deletable-headers
)
5939 (progn (beginning-of-line) (looking-at "[^:]+: "))
5940 (add-text-properties
5941 (point) (match-end 0)
5942 '(message-deletable t face italic
) (current-buffer)))))))
5943 ;; Insert new Sender if the From is strange.
5944 (let ((from (message-fetch-field "from"))
5945 (sender (message-fetch-field "sender"))
5946 (secure-sender (message-make-sender)))
5948 (not (message-check-element 'sender
))
5951 (cadr (mail-extract-address-components from
)))
5952 (downcase secure-sender
)))
5957 (cadr (mail-extract-address-components sender
)))
5958 (downcase secure-sender
)))))
5959 (goto-char (point-min))
5960 ;; Rename any old Sender headers to Original-Sender.
5961 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t
)
5963 (insert "Original-")
5964 (beginning-of-line))
5965 (when (or (message-news-p)
5966 (string-match "@.+\\.." secure-sender
))
5967 (insert "Sender: " secure-sender
"\n"))))
5969 (message-idna-to-ascii-rhs))))
5971 (defun message-insert-courtesy-copy ()
5972 "Insert a courtesy message in mail copies of combined messages."
5976 (message-narrow-to-headers)
5977 (when (setq newsgroups
(message-fetch-field "newsgroups"))
5978 (goto-char (point-max))
5979 (insert "Posted-To: " newsgroups
"\n")))
5981 (when message-courtesy-message
5983 ((string-match "%s" message-courtesy-message
)
5984 (insert (format message-courtesy-message newsgroups
)))
5986 (insert message-courtesy-message
)))))))
5989 ;;; Setting up a message buffer
5992 (defun message-skip-to-next-address ()
5993 (let ((end (save-excursion
5994 (message-next-header)
5997 (when (looking-at ",")
5999 (while (and (not (= (point) end
))
6000 (or (not (eq char ?
,))
6002 (skip-chars-forward "^,\"" (point-max))
6003 (when (eq (setq char
(following-char)) ?
\")
6004 (setq quoted
(not quoted
)))
6005 (unless (= (point) end
)
6007 (skip-chars-forward " \t\n")))
6009 (defun message-fill-address (header value
)
6010 (insert (capitalize (symbol-name header
))
6012 (if (consp value
) (car value
) value
)
6014 (message-fill-field-address))
6016 (defun message-split-line ()
6017 "Split current line, moving portion beyond point vertically down.
6018 If the current line has `message-yank-prefix', insert it on the new line."
6021 (split-line message-yank-prefix
) ;; Emacs 22.1+ supports arg.
6025 (defun message-insert-header (header value
)
6026 (insert (capitalize (symbol-name header
))
6028 (if (consp value
) (car value
) value
)))
6030 (defun message-field-name ()
6032 (goto-char (point-min))
6033 (when (looking-at "\\([^:]+\\):")
6034 (intern (capitalize (match-string 1))))))
6036 (defun message-fill-field ()
6039 (message-narrow-to-field)
6040 (let ((field-name (message-field-name)))
6041 (funcall (or (cadr (assq field-name message-field-fillers
))
6042 'message-fill-field-general
)))
6045 (defun message-fill-field-address ()
6047 (message-skip-to-next-address)
6049 (if (and (> (current-column) 78)
6055 (setq last
(1+ (point))))
6056 (setq last
(1+ (point)))))))
6058 (defun message-fill-field-general ()
6059 (let ((begin (point))
6062 (while (and (search-forward "\n" nil t
)
6064 (replace-match " " t t
))
6065 (fill-region-as-paragraph begin
(point-max))
6066 ;; Tapdance around looong Message-IDs.
6068 (when (looking-at "[ \t]*$")
6069 (message-delete-line))
6071 (search-forward ":" nil t
)
6072 (when (looking-at "\n[ \t]+")
6073 (replace-match " " t t
))
6074 (goto-char (point-max))))
6076 (defun message-shorten-1 (list cut surplus
)
6077 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
6078 (setcdr (nthcdr (- cut
2) list
)
6079 (nthcdr (+ (- cut
2) surplus
1) list
)))
6081 (defun message-shorten-references (header references
)
6082 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
6083 When sending via news, also check that the REFERENCES are less
6084 than 988 characters long, and if they are not, trim them until
6092 (goto-char (point-min))
6093 ;; Cons a list of valid references. GNKSA says we must not include MIDs
6094 ;; with whitespace or missing brackets (7.a "Does not propagate broken
6095 ;; Message-IDs in original References").
6096 (while (re-search-forward "<[^ <]+@[^ <]+>" nil t
)
6097 (push (match-string 0) refs
))
6098 (setq refs
(nreverse refs
)
6099 count
(length refs
)))
6101 ;; If the list has more than MAXCOUNT elements, trim it by
6102 ;; removing the CUTth element and the required number of
6103 ;; elements that follow.
6104 (when (> count maxcount
)
6105 (let ((surplus (- count maxcount
)))
6106 (message-shorten-1 refs cut surplus
)
6107 (decf count surplus
)))
6109 ;; When sending via news, make sure the total folded length will
6110 ;; be less than 998 characters. This is to cater to broken INN
6111 ;; 2.3 which counts the total number of characters in a header
6112 ;; rather than the physical line length of each line, as it should.
6114 ;; This hack should be removed when it's believed than INN 2.3 is
6115 ;; no longer widely used.
6117 ;; At this point the headers have not been generated, thus we use
6118 ;; message-this-is-news directly.
6119 (when message-this-is-news
6122 (message-insert-header
6123 header
(mapconcat #'identity refs
" "))
6125 (message-shorten-1 refs cut
1)))
6126 ;; Finally, collect the references back into a string and insert
6127 ;; it into the buffer.
6128 (message-insert-header header
(mapconcat #'identity refs
" "))))
6130 (defun message-position-point ()
6131 "Move point to where the user probably wants to find it."
6132 (message-narrow-to-headers)
6134 ((re-search-forward "^[^:]+:[ \t]*$" nil t
)
6135 (search-backward ":" )
6138 (if (eq (char-after) ?
)
6142 (goto-char (point-max))
6145 (unless (looking-at "$")
6149 (defcustom message-beginning-of-line t
6150 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
6151 goes to beginning of header values."
6153 :group
'message-buffers
6154 :link
'(custom-manual "(message)Movement")
6157 (defun message-beginning-of-line (&optional n
)
6158 "Move point to beginning of header value or to beginning of line.
6159 The prefix argument N is passed directly to `beginning-of-line'.
6161 This command is identical to `beginning-of-line' if point is
6162 outside the message header or if the option `message-beginning-of-line'
6165 If point is in the message header and on a (non-continued) header
6166 line, move point to the beginning of the header value or the beginning of line,
6167 whichever is closer. If point is already at beginning of line, move point to
6168 beginning of header value. Therefore, repeated calls will toggle point
6169 between beginning of field and beginning of line."
6171 (let ((zrs 'zmacs-region-stays
))
6172 (when (and (featurep 'xemacs
) (interactive-p) (boundp zrs
))
6174 (if (and message-beginning-of-line
6175 (message-point-in-header-p))
6176 (let* ((here (point))
6177 (bol (progn (beginning-of-line n
) (point)))
6178 (eol (point-at-eol))
6179 (eoh (re-search-forward ": *" eol t
)))
6181 (if (and eoh
(or (< eoh here
) (= bol here
)))
6183 (beginning-of-line n
)))
6185 (defun message-buffer-name (type &optional to group
)
6186 "Return a new (unique) buffer name based on TYPE and TO."
6188 ;; Generate a new buffer name The Message Way.
6189 ((memq message-generate-new-buffers
'(unique t
))
6190 (generate-new-buffer-name
6194 (or (car (mail-extract-address-components to
))
6197 (if (and group
(not (string= group
""))) (concat " on " group
) "")
6199 ;; Check whether `message-generate-new-buffers' is a function,
6200 ;; and if so, call it.
6201 ((functionp message-generate-new-buffers
)
6202 (funcall message-generate-new-buffers type to group
))
6203 ((eq message-generate-new-buffers
'unsent
)
6204 (generate-new-buffer-name
6205 (concat "*unsent " type
6208 (or (car (mail-extract-address-components to
))
6211 (if (and group
(not (string= group
""))) (concat " on " group
) "")
6213 ;; Search for the existing message buffer with the specified name.
6215 (let* ((new (if (eq message-generate-new-buffers
'standard
)
6216 (generate-new-buffer-name (concat "*" type
" message*"))
6217 (let ((message-generate-new-buffers 'unique
))
6218 (message-buffer-name type to group
))))
6219 (regexp (concat "\\`"
6221 (if (string-match "<[0-9]+>\\'" new
)
6222 (substring new
0 (match-beginning 0))
6224 "\\(?:<\\([0-9]+\\)>\\)?\\'"))
6225 (case-fold-search nil
))
6232 (when (and (string-match regexp
(setq b
(buffer-name b
)))
6233 (eq (with-current-buffer b major-mode
)
6235 (cons (string-to-number (or (match-string 1 b
) "1"))
6238 'car-less-than-car
)))
6241 (defun message-pop-to-buffer (name &optional switch-function
)
6242 "Pop to buffer NAME, and warn if it already exists and is modified."
6243 (let ((buffer (get-buffer name
)))
6245 (buffer-name buffer
))
6246 (let ((window (get-buffer-window buffer
0)))
6248 ;; Raise the frame already displaying the message buffer.
6250 (gnus-select-frame-set-input-focus (window-frame window
))
6251 (select-window window
))
6252 (funcall (or switch-function
'pop-to-buffer
) buffer
)
6253 (set-buffer buffer
))
6254 (when (and (buffer-modified-p)
6257 "Message already being composed; erase? ")
6259 (error "Message being composed")))
6260 (funcall (or switch-function
'pop-to-buffer
) name
)
6265 (defun message-do-send-housekeeping ()
6266 "Kill old message buffers."
6267 ;; We might have sent this buffer already. Delete it from the
6269 (setq message-buffer-list
(delq (current-buffer) message-buffer-list
))
6270 (while (and message-max-buffers
6272 (>= (length message-buffer-list
) message-max-buffers
))
6273 ;; Kill the oldest buffer -- unless it has been changed.
6274 (let ((buffer (pop message-buffer-list
)))
6275 (when (and (buffer-name buffer
)
6276 (not (buffer-modified-p buffer
)))
6277 (kill-buffer buffer
))))
6278 ;; Rename the buffer.
6279 (if message-send-rename-function
6280 (funcall message-send-rename-function
)
6281 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
6283 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
6285 (let ((name (match-string 2 (buffer-name)))
6287 (if (not (or (null name
)
6288 (string-equal name
"mail")
6289 (string-equal name
"posting")))
6290 (setq name
(concat "*sent " name
"*"))
6291 (message-narrow-to-headers)
6292 (setq to
(message-fetch-field "to"))
6293 (setq group
(message-fetch-field "newsgroups"))
6297 (to (concat "*sent mail to "
6298 (or (car (mail-extract-address-components to
))
6300 ((and group
(not (string= group
"")))
6301 (concat "*sent posting on " group
"*"))
6302 (t "*sent mail*"))))
6303 (unless (string-equal name
(buffer-name))
6304 (rename-buffer name t
)))))
6305 ;; Push the current buffer onto the list.
6306 (when message-max-buffers
6307 (setq message-buffer-list
6308 (nconc message-buffer-list
(list (current-buffer))))))
6310 (defun message-mail-user-agent ()
6312 ((not message-mail-user-agent
) nil
)
6313 ((eq message-mail-user-agent t
) mail-user-agent
)
6314 (t message-mail-user-agent
))))
6315 (if (memq mua
'(message-user-agent gnus-user-agent
))
6319 ;; YANK-ACTION, if non-nil, can be a buffer or a yank action of the
6320 ;; form (FUNCTION . ARGS).
6321 (defun message-setup (headers &optional yank-action actions
6322 continue switch-function
)
6323 (let ((mua (message-mail-user-agent))
6325 (if (not (and message-this-is-mail mua
))
6326 (message-setup-1 headers yank-action actions
)
6327 (setq headers
(copy-sequence headers
))
6328 (setq field
(assq 'Subject headers
))
6330 (setq subject
(cdr field
))
6331 (setq headers
(delq field headers
)))
6332 (setq field
(assq 'To headers
))
6334 (setq to
(cdr field
))
6335 (setq headers
(delq field headers
)))
6336 (let ((mail-user-agent mua
))
6337 (compose-mail to subject
6338 (mapcar (lambda (item)
6340 (format "%s" (car item
))
6343 continue switch-function
6344 (if (bufferp yank-action
)
6345 (list 'insert-buffer yank-action
)
6349 (defun message-headers-to-generate (headers included-headers excluded-headers
)
6350 "Return a list that includes all headers from HEADERS.
6351 If INCLUDED-HEADERS is a list, just include those headers. If it is
6352 t, include all headers. In any case, headers from EXCLUDED-HEADERS
6356 (dolist (header headers
)
6357 (setq header-name
(cond
6358 ((and (consp header
)
6359 (eq (car header
) 'optional
))
6360 ;; On the form (optional . Header)
6363 ;; On the form (Header . function)
6368 (when (and (not (memq header-name excluded-headers
))
6369 (or (eq included-headers t
)
6370 (memq header-name included-headers
)))
6371 (push header result
)))
6374 (defun message-setup-1 (headers &optional yank-action actions
)
6375 (dolist (action actions
)
6377 (add-to-list 'message-send-actions
6378 `(apply ',(car action
) ',(cdr action
)))))
6379 (setq message-reply-buffer
6380 (if (and (consp yank-action
)
6381 (eq (car yank-action
) 'insert-buffer
))
6384 (goto-char (point-min))
6385 ;; Insert all the headers.
6388 (alist message-header-format-alist
))
6390 (unless (assq (caar h
) message-header-format-alist
)
6391 (push (list (caar h
)) alist
))
6395 (delete-region (point) (progn (forward-line -
1) (point)))
6396 (when message-default-headers
6397 (insert message-default-headers
)
6398 (or (bolp) (insert ?
\n)))
6399 (insert mail-header-separator
"\n")
6401 (when (message-news-p)
6402 (when message-default-news-headers
6403 (insert message-default-news-headers
)
6404 (or (bolp) (insert ?
\n)))
6405 (when message-generate-headers-first
6406 (message-generate-headers
6407 (message-headers-to-generate
6408 (append message-required-news-headers
6409 message-required-headers
)
6410 message-generate-headers-first
6411 '(Lines Subject
)))))
6412 (when (message-mail-p)
6413 (when message-default-mail-headers
6414 (insert message-default-mail-headers
)
6415 (or (bolp) (insert ?
\n)))
6416 (when message-generate-headers-first
6417 (message-generate-headers
6418 (message-headers-to-generate
6419 (append message-required-mail-headers
6420 message-required-headers
)
6421 message-generate-headers-first
6422 '(Lines Subject
)))))
6423 (run-hooks 'message-signature-setup-hook
)
6424 (message-insert-signature)
6426 (message-narrow-to-headers)
6427 (run-hooks 'message-header-setup-hook
))
6428 (setq buffer-undo-list nil
)
6429 (when message-generate-hashcash
6430 ;; Generate hashcash headers for recipients already known
6431 (mail-add-payment-async))
6432 ;; Gnus posting styles are applied via buffer-local `message-setup-hook'
6434 (run-hooks 'message-setup-hook
)
6435 ;; Do this last to give it precedence over posting styles, etc.
6436 (when (message-mail-p)
6438 (message-narrow-to-headers)
6439 (if message-alternative-emails
6440 (message-use-alternative-email-as-from))))
6441 (message-position-point)
6442 ;; Allow correct handling of `message-checksum' in `message-yank-original':
6443 (set-buffer-modified-p nil
)
6446 (defun message-set-auto-save-file-name ()
6447 "Associate the message buffer with a file in the drafts directory."
6448 (when message-auto-save-directory
6449 (unless (file-directory-p
6450 (directory-file-name message-auto-save-directory
))
6451 (make-directory message-auto-save-directory t
))
6453 (setq message-draft-article
6454 (nndraft-request-associate-buffer "drafts"))
6456 ;; If Gnus were alive, draft messages would be saved in the drafts folder.
6457 ;; But Gnus is not alive, so arrange to save the draft message in a
6458 ;; regular file in message-auto-save-directory. Append a unique
6459 ;; time-based suffix to the filename to allow multiple drafts to be saved
6460 ;; simultaneously without overwriting each other (which mimics the
6461 ;; functionality of the Gnus drafts folder).
6462 (setq buffer-file-name
(expand-file-name
6464 (if (memq system-type
6465 '(ms-dos windows-nt cygwin
))
6468 (format-time-string "-%Y%m%d-%H%M%S"))
6469 message-auto-save-directory
))
6470 (setq buffer-auto-save-file-name
(make-auto-save-file-name)))
6471 (clear-visited-file-modtime)
6472 (setq buffer-file-coding-system message-draft-coding-system
)))
6474 (defun message-disassociate-draft ()
6475 "Disassociate the message buffer from the drafts directory."
6476 (when message-draft-article
6477 (nndraft-request-expire-articles
6478 (list message-draft-article
) "drafts" nil t
)))
6480 (defun message-insert-headers ()
6481 "Generate the headers for the article."
6485 (message-narrow-to-headers)
6486 (when (message-news-p)
6487 (message-generate-headers
6490 (copy-sequence message-required-news-headers
)))))
6491 (when (message-mail-p)
6492 (message-generate-headers
6495 (copy-sequence message-required-mail-headers
))))))))
6500 ;;; Commands for interfacing with message
6504 (defun message-mail (&optional to subject
6505 other-headers continue switch-function
6506 yank-action send-actions
)
6507 "Start editing a mail message to be sent.
6508 OTHER-HEADERS is an alist of header/value pairs. CONTINUE says whether
6509 to continue editing a message already being composed. SWITCH-FUNCTION
6510 is a function used to switch to and display the mail buffer."
6512 (let ((message-this-is-mail t
))
6513 (unless (message-mail-user-agent)
6514 (message-pop-to-buffer
6515 ;; Search for the existing message buffer if `continue' is non-nil.
6516 (let ((message-generate-new-buffers
6517 (when (or (not continue
)
6518 (eq message-generate-new-buffers
'standard
)
6519 (functionp message-generate-new-buffers
))
6520 message-generate-new-buffers
)))
6521 (message-buffer-name "mail" to
))
6525 `((To .
,(or to
"")) (Subject .
,(or subject
"")))
6526 (when other-headers other-headers
))
6527 yank-action send-actions continue switch-function
)
6528 ;; FIXME: Should return nil if failure.
6532 (defun message-news (&optional newsgroups subject
)
6533 "Start editing a news article to be sent."
6535 (let ((message-this-is-news t
))
6536 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
))
6537 (message-setup `((Newsgroups .
,(or newsgroups
""))
6538 (Subject .
,(or subject
""))))))
6540 (defun message-alter-recipients-discard-bogus-full-name (addrcell)
6541 "Discard mail address in full names.
6542 When the full name in reply headers contains the mail
6543 address (e.g. \"foo@bar <foo@bar>\"), discard full name.
6544 ADDRCELL is a cons cell where the car is the mail address and the
6545 cdr is the complete address (full name and mail address)."
6546 (if (string-match (concat (regexp-quote (car addrcell
)) ".*"
6547 (regexp-quote (car addrcell
)))
6549 (cons (car addrcell
) (car addrcell
))
6552 (defcustom message-alter-recipients-function nil
6553 "Function called to allow alteration of reply header structures.
6554 It is called in `message-get-reply-headers' for each recipient.
6555 The function is called with one parameter, a cons cell ..."
6556 :type
'(choice (const :tag
"None" nil
)
6557 (const :tag
"Discard bogus full name"
6558 message-alter-recipients-discard-bogus-full-name
)
6560 :version
"23.1" ;; No Gnus
6561 :group
'message-headers
)
6563 (defun message-get-reply-headers (wide &optional to-address address-headers
)
6564 (let (follow-to mct never-mct to cc author mft recipients extra
)
6565 ;; Find all relevant headers we need.
6567 (message-narrow-to-headers-or-head)
6568 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
6569 ;; message-header-synonyms.
6570 (setq to
(or (message-fetch-field "to")
6571 (and (loop for synonym in message-header-synonyms
6572 when
(memq 'Original-To synonym
)
6574 (message-fetch-field "original-to")))
6575 cc
(message-fetch-field "cc")
6576 extra
(when message-extra-wide-headers
6577 (mapconcat 'identity
6578 (mapcar 'message-fetch-field
6579 message-extra-wide-headers
)
6581 mct
(message-fetch-field "mail-copies-to")
6582 author
(or (message-fetch-field "mail-reply-to")
6583 (message-fetch-field "reply-to")
6584 (message-fetch-field "from")
6586 mft
(and message-use-mail-followup-to
6587 (message-fetch-field "mail-followup-to"))))
6589 ;; Handle special values of Mail-Copies-To.
6591 (cond ((or (equal (downcase mct
) "never")
6592 (equal (downcase mct
) "nobody"))
6595 ((or (equal (downcase mct
) "always")
6596 (equal (downcase mct
) "poster"))
6597 (setq mct author
))))
6600 ;; Build (textual) list of new recipient addresses.
6603 (setq recipients
(concat ", " author
)))
6605 (dolist (header address-headers
)
6606 (let ((value (message-fetch-field header
)))
6608 (setq recipients
(concat recipients
", " value
))))))
6610 (string-match "[^ \t,]" mft
)
6611 (or (not (eq message-use-mail-followup-to
'ask
))
6612 (message-y-or-n-p "Obey Mail-Followup-To? " t
"\
6613 You should normally obey the Mail-Followup-To: header. In this
6614 article, it has the value of
6618 which directs your response to " (if (string-match "," mft
)
6619 "the specified addresses"
6620 "that address only") ".
6622 Most commonly, Mail-Followup-To is used by a mailing list poster to
6623 express that responses should be sent to just the list, and not the
6626 If a message is posted to several mailing lists, Mail-Followup-To may
6627 also be used to direct the following discussion to one list only,
6628 because discussions that are spread over several lists tend to be
6629 fragmented and very difficult to follow.
6631 Also, some source/announcement lists are not intended for discussion;
6632 responses here are directed to other addresses.
6634 You may customize the variable `message-use-mail-followup-to', if you
6635 want to get rid of this query permanently.")))
6636 (setq recipients
(concat ", " mft
)))
6638 (setq recipients
(concat ", " to-address
))
6639 ;; If the author explicitly asked for a copy, we don't deny it to them.
6640 (if mct
(setq recipients
(concat recipients
", " mct
))))
6642 (setq recipients
(if never-mct
"" (concat ", " author
)))
6643 (if to
(setq recipients
(concat recipients
", " to
)))
6644 (if cc
(setq recipients
(concat recipients
", " cc
)))
6645 (if extra
(setq recipients
(concat recipients
", " extra
)))
6646 (if mct
(setq recipients
(concat recipients
", " mct
)))))
6647 (if (>= (length recipients
) 2)
6648 ;; Strip the leading ", ".
6649 (setq recipients
(substring recipients
2)))
6650 ;; Squeeze whitespace.
6651 (while (string-match "[ \t][ \t]+" recipients
)
6652 (setq recipients
(replace-match " " t t recipients
)))
6653 ;; Remove addresses that match `rmail-dont-reply-to-names'.
6654 (let ((rmail-dont-reply-to-names (message-dont-reply-to-names)))
6655 (setq recipients
(rmail-dont-reply-to recipients
)))
6656 ;; Perhaps "Mail-Copies-To: never" removed the only address?
6657 (if (string-equal recipients
"")
6658 (setq recipients author
))
6659 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
6663 (if message-alter-recipients-function
6664 (funcall message-alter-recipients-function
6665 (cons (downcase (mail-strip-quoted-names addr
))
6667 (cons (downcase (mail-strip-quoted-names addr
)) addr
)))
6668 (message-tokenize-header recipients
)))
6669 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
6670 (let ((s recipients
))
6672 (setq recipients
(delq (assoc (car (pop s
)) s
) recipients
))))
6674 ;; Remove hierarchical lists that are contained within each other,
6675 ;; if message-hierarchical-addresses is defined.
6676 (when message-hierarchical-addresses
6677 (let ((plain-addrs (mapcar 'car recipients
))
6680 (setq subaddrs
(assoc (car plain-addrs
)
6681 message-hierarchical-addresses
)
6682 plain-addrs
(cdr plain-addrs
))
6684 (setq subaddrs
(cdr subaddrs
))
6686 (setq recip
(assoc (car subaddrs
) recipients
)
6687 subaddrs
(cdr subaddrs
))
6689 (setq recipients
(delq recip recipients
))))))))
6691 (setq recipients
(message-prune-recipients recipients
))
6693 ;; Build the header alist. Allow the user to be asked whether
6694 ;; or not to reply to all recipients in a wide reply.
6695 (setq follow-to
(list (cons 'To
(cdr (pop recipients
)))))
6696 (when (and recipients
6697 (or (not message-wide-reply-confirm-recipients
)
6698 (y-or-n-p "Reply to all recipients? ")))
6699 (setq recipients
(mapconcat
6700 (lambda (addr) (cdr addr
)) recipients
", "))
6701 (if (string-match "^ +" recipients
)
6702 (setq recipients
(substring recipients
(match-end 0))))
6703 (push (cons 'Cc recipients
) follow-to
)))
6706 (defun message-prune-recipients (recipients)
6707 (dolist (rule message-prune-recipient-rules
)
6708 (let ((match (car rule
))
6711 (dolist (recipient recipients
)
6712 (setq address
(car recipient
))
6713 (when (string-match match address
)
6714 (setq dup-match
(replace-match (cadr rule
) nil nil address
))
6715 (dolist (recipient recipients
)
6716 ;; Don't delete the address that triggered this.
6717 (when (and (not (eq address
(car recipient
)))
6718 (string-match dup-match
(car recipient
)))
6719 (setq recipients
(delq recipient recipients
))))))))
6722 (defcustom message-simplify-subject-functions
6723 '(message-strip-list-identifiers
6724 message-strip-subject-re
6725 message-strip-subject-trailing-was
6726 message-strip-subject-encoded-words
)
6727 "List of functions taking a string argument that simplify subjects.
6728 The functions are applied when replying to a message.
6730 Useful functions to put in this list include:
6731 `message-strip-list-identifiers', `message-strip-subject-re',
6732 `message-strip-subject-trailing-was', and
6733 `message-strip-subject-encoded-words'."
6734 :version
"22.1" ;; Gnus 5.10.9
6735 :group
'message-various
6736 :type
'(repeat function
))
6738 (defun message-simplify-subject (subject &optional functions
)
6739 "Return simplified SUBJECT."
6742 (setq functions message-simplify-subject-functions
))
6743 (when (and (memq 'message-strip-list-identifiers functions
)
6744 gnus-list-identifiers
)
6745 (setq subject
(message-strip-list-identifiers subject
)))
6746 (when (memq 'message-strip-subject-re functions
)
6747 (setq subject
(concat "Re: " (message-strip-subject-re subject
))))
6748 (when (and (memq 'message-strip-subject-trailing-was functions
)
6749 message-subject-trailing-was-query
)
6750 (setq subject
(message-strip-subject-trailing-was subject
)))
6751 (when (memq 'message-strip-subject-encoded-words functions
)
6752 (setq subject
(message-strip-subject-encoded-words subject
)))
6756 (defun message-reply (&optional to-address wide
)
6757 "Start editing a reply to the article in the current buffer."
6759 (require 'gnus-sum
) ; for gnus-list-identifiers
6760 (let ((cur (current-buffer))
6761 from subject date reply-to to cc
6762 references message-id follow-to
6763 (inhibit-point-motion-hooks t
)
6764 (message-this-is-mail t
)
6767 (message-narrow-to-head-1)
6768 ;; Allow customizations to have their say.
6770 ;; This is a regular reply.
6771 (when (functionp message-reply-to-function
)
6773 (setq follow-to
(funcall message-reply-to-function
))))
6774 ;; This is a followup.
6775 (when (functionp message-wide-reply-to-function
)
6778 (funcall message-wide-reply-to-function
)))))
6779 (setq message-id
(message-fetch-field "message-id" t
)
6780 references
(message-fetch-field "references")
6781 date
(message-fetch-field "date")
6782 from
(or (message-fetch-field "from") "nobody")
6783 subject
(or (message-fetch-field "subject") "none"))
6785 ;; Strip list identifiers, "Re: ", and "was:"
6786 (setq subject
(message-simplify-subject subject
))
6788 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
6789 (string-match "<[^>]+>" gnus-warning
))
6790 (setq message-id
(match-string 0 gnus-warning
)))
6793 (setq follow-to
(message-get-reply-headers wide to-address
))))
6795 (unless (message-mail-user-agent)
6796 (message-pop-to-buffer
6797 (message-buffer-name
6798 (if wide
"wide reply" "reply") from
6799 (if wide to-address nil
))))
6801 (setq message-reply-headers
6802 (vector 0 subject from date message-id references
0 0 ""))
6805 `((Subject .
,subject
)
6810 (defun message-wide-reply (&optional to-address
)
6811 "Make a \"wide\" reply to the message in the current buffer."
6813 (message-reply to-address t
))
6816 (defun message-followup (&optional to-newsgroups
)
6817 "Follow up to the message in the current buffer.
6818 If TO-NEWSGROUPS, use that as the new Newsgroups line."
6820 (require 'gnus-sum
) ; for gnus-list-identifiers
6821 (let ((cur (current-buffer))
6822 from subject date reply-to mrt mct
6823 references message-id follow-to
6824 (inhibit-point-motion-hooks t
)
6825 (message-this-is-news t
)
6826 followup-to distribution newsgroups gnus-warning posted-to
)
6829 (goto-char (point-min))
6830 (if (search-forward "\n\n" nil t
)
6833 (when (functionp message-followup-to-function
)
6835 (funcall message-followup-to-function
)))
6836 (setq from
(message-fetch-field "from")
6837 date
(message-fetch-field "date")
6838 subject
(or (message-fetch-field "subject") "none")
6839 references
(message-fetch-field "references")
6840 message-id
(message-fetch-field "message-id" t
)
6841 followup-to
(message-fetch-field "followup-to")
6842 newsgroups
(message-fetch-field "newsgroups")
6843 posted-to
(message-fetch-field "posted-to")
6844 reply-to
(message-fetch-field "reply-to")
6845 mrt
(message-fetch-field "mail-reply-to")
6846 distribution
(message-fetch-field "distribution")
6847 mct
(message-fetch-field "mail-copies-to"))
6848 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
6849 (string-match "<[^>]+>" gnus-warning
))
6850 (setq message-id
(match-string 0 gnus-warning
)))
6851 ;; Remove bogus distribution.
6852 (when (and (stringp distribution
)
6853 (let ((case-fold-search t
))
6854 (string-match "world" distribution
)))
6855 (setq distribution nil
))
6856 ;; Strip list identifiers, "Re: ", and "was:"
6857 (setq subject
(message-simplify-subject subject
))
6860 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups
))
6862 (setq message-reply-headers
6863 (vector 0 subject from date message-id references
0 0 ""))
6866 `((Subject .
,subject
)
6869 (list (cons 'Newsgroups to-newsgroups
)))
6870 (follow-to follow-to
)
6871 ((and followup-to message-use-followup-to
)
6874 ((equal (downcase followup-to
) "poster")
6875 (if (or (eq message-use-followup-to
'use
)
6876 (message-y-or-n-p "Obey Followup-To: poster? " t
"\
6877 You should normally obey the Followup-To: header.
6879 `Followup-To: poster' sends your response via e-mail instead of news.
6881 A typical situation where `Followup-To: poster' is used is when the poster
6882 does not read the newsgroup, so he wouldn't see any replies sent to it.
6884 You may customize the variable `message-use-followup-to', if you
6885 want to get rid of this query permanently."))
6887 (setq message-this-is-news nil
)
6888 (cons 'To
(or mrt reply-to from
"")))
6889 (cons 'Newsgroups newsgroups
)))
6891 (if (or (equal followup-to newsgroups
)
6892 (not (eq message-use-followup-to
'ask
))
6894 (concat "Obey Followup-To: " followup-to
"? ") t
"\
6895 You should normally obey the Followup-To: header.
6897 `Followup-To: " followup-to
"'
6898 directs your response to " (if (string-match "," followup-to
)
6899 "the specified newsgroups"
6900 "that newsgroup only") ".
6902 If a message is posted to several newsgroups, Followup-To is often
6903 used to direct the following discussion to one newsgroup only,
6904 because discussions that are spread over several newsgroup tend to
6905 be fragmented and very difficult to follow.
6907 Also, some source/announcement newsgroups are not intended for discussion;
6908 responses here are directed to other newsgroups.
6910 You may customize the variable `message-use-followup-to', if you
6911 want to get rid of this query permanently."))
6912 (cons 'Newsgroups followup-to
)
6913 (cons 'Newsgroups newsgroups
))))))
6915 `((Newsgroups .
,posted-to
)))
6917 `((Newsgroups .
,newsgroups
))))
6918 ,@(and distribution
(list (cons 'Distribution distribution
)))
6920 (not (or (equal (downcase mct
) "never")
6921 (equal (downcase mct
) "nobody"))))
6922 (list (cons 'Cc
(if (or (equal (downcase mct
) "always")
6923 (equal (downcase mct
) "poster"))
6924 (or mrt reply-to from
"")
6929 (defun message-is-yours-p ()
6930 "Non-nil means current article is yours.
6931 If you have added 'cancel-messages to `message-shoot-gnksa-feet', all articles
6932 are yours except those that have Cancel-Lock header not belonging to you.
6933 Instead of shooting GNKSA feet, you should modify `message-alternative-emails'
6934 regexp to match all of yours addresses."
6935 ;; Canlock-logic as suggested by Per Abrahamsen
6936 ;; <abraham@dina.kvl.dk>
6938 ;; IF article has cancel-lock THEN
6939 ;; IF we can verify it THEN
6942 ;; error: cancellock: article is not yours
6944 ;; Use old rules, comparing sender...
6947 (message-narrow-to-head-1)
6948 (if (message-fetch-field "Cancel-Lock")
6949 (if (null (canlock-verify))
6951 (error "Failed to verify Cancel-lock: This article is not yours"))
6954 (message-gnksa-enable-p 'cancel-messages
)
6955 (and (setq sender
(message-fetch-field "sender"))
6956 (string-equal (downcase sender
)
6957 (downcase (message-make-sender))))
6958 ;; Email address in From field equals to our address
6959 (and (setq from
(message-fetch-field "from"))
6961 (downcase (car (mail-header-parse-address from
)))
6962 (downcase (car (mail-header-parse-address
6963 (message-make-from))))))
6964 ;; Email address in From field matches
6965 ;; 'message-alternative-emails' regexp
6967 message-alternative-emails
6969 message-alternative-emails
6970 (car (mail-header-parse-address from
))))))))))
6973 (defun message-cancel-news (&optional arg
)
6974 "Cancel an article you posted.
6975 If ARG, allow editing of the cancellation message."
6977 (unless (message-news-p)
6978 (error "This is not a news article; canceling is impossible"))
6979 (let (from newsgroups message-id distribution buf
)
6981 ;; Get header info from original article.
6983 (message-narrow-to-head-1)
6984 (setq from
(message-fetch-field "from")
6985 newsgroups
(message-fetch-field "newsgroups")
6986 message-id
(message-fetch-field "message-id" t
)
6987 distribution
(message-fetch-field "distribution")))
6988 ;; Make sure that this article was written by the user.
6989 (unless (message-is-yours-p)
6990 (error "This article is not yours"))
6991 (when (yes-or-no-p "Do you really want to cancel this article? ")
6992 ;; Make control message.
6995 (setq buf
(set-buffer (get-buffer-create " *message cancel*"))))
6997 (insert "Newsgroups: " newsgroups
"\n"
6999 "Subject: cmsg cancel " message-id
"\n"
7000 "Control: cancel " message-id
"\n"
7002 (concat "Distribution: " distribution
"\n")
7004 mail-header-separator
"\n"
7005 message-cancel-message
)
7006 (run-hooks 'message-cancel-hook
)
7008 (message "Canceling your article...")
7009 (if (let ((message-syntax-checks
7010 'dont-check-for-anything-just-trust-me
))
7011 (funcall message-send-news-function
))
7012 (message "Canceling your article...done"))
7013 (kill-buffer buf
))))))
7016 (defun message-supersede ()
7017 "Start composing a message to supersede the current message.
7018 This is done simply by taking the old article and adding a Supersedes
7019 header line with the old Message-ID."
7021 (let ((cur (current-buffer)))
7022 ;; Check whether the user owns the article that is to be superseded.
7023 (unless (message-is-yours-p)
7024 (error "This article is not yours"))
7025 ;; Get a normal message buffer.
7026 (message-pop-to-buffer (message-buffer-name "supersede"))
7027 (insert-buffer-substring cur
)
7029 (message-narrow-to-head-1)
7030 ;; Remove unwanted headers.
7031 (when message-ignored-supersedes-headers
7032 (message-remove-header message-ignored-supersedes-headers t
))
7033 (goto-char (point-min))
7034 (if (not (re-search-forward "^Message-ID: " nil t
))
7035 (error "No Message-ID in this article")
7036 (replace-match "Supersedes: " t t
))
7037 (goto-char (point-max))
7038 (insert mail-header-separator
)
7043 (defun message-recover ()
7044 "Reread contents of current buffer from its last auto-save file."
7046 (let ((file-name (make-auto-save-file-name)))
7047 (cond ((save-window-excursion
7048 (with-output-to-temp-buffer "*Directory*"
7049 (with-current-buffer standard-output
7050 (fundamental-mode)) ; for Emacs 20.4+
7051 (buffer-disable-undo standard-output
)
7052 (let ((default-directory "/"))
7054 "ls" nil standard-output nil
"-l" file-name
)))
7055 (yes-or-no-p (format "Recover auto save file %s? " file-name
)))
7056 (let ((buffer-read-only nil
))
7058 (insert-file-contents file-name nil
)))
7059 (t (error "message-recover cancelled")))))
7061 ;;; Washing Subject:
7063 (defun message-wash-subject (subject)
7064 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
7065 Previous forwarders, replyers, etc. may add it."
7068 (goto-char (point-min))
7069 ;; strip Re/Fwd stuff off the beginning
7070 (while (re-search-forward
7071 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t
)
7074 ;; and gnus-style forwards [foo@bar.com] subject
7075 (goto-char (point-min))
7076 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t
)
7080 (goto-char (point-max))
7081 (while (re-search-backward "([Ff][Ww][Dd])" nil t
)
7084 ;; and finally, any whitespace that was left-over
7085 (goto-char (point-min))
7086 (while (re-search-forward "^[ \t]+" nil t
)
7088 (goto-char (point-max))
7089 (while (re-search-backward "[ \t]+$" nil t
)
7094 ;;; Forwarding messages.
7096 (defvar message-forward-decoded-p nil
7097 "Non-nil means the original message is decoded.")
7099 (defun message-forward-subject-name-subject (subject)
7100 "Generate a SUBJECT for a forwarded message.
7101 The form is: [Source] Subject, where if the original message was mail,
7102 Source is the name of the sender, and if the original message was
7103 news, Source is the list of newsgroups is was posted to."
7104 (let* ((group (message-fetch-field "newsgroups"))
7105 (from (message-fetch-field "from"))
7108 (gnus-group-decoded-name group
)
7110 (car (gnus-extract-address-components from
))
7111 (cadr (gnus-extract-address-components from
))))
7114 (if message-forward-decoded-p
7116 (mail-decode-encoded-word-string prefix
))
7119 (defun message-forward-subject-author-subject (subject)
7120 "Generate a SUBJECT for a forwarded message.
7121 The form is: [Source] Subject, where if the original message was mail,
7122 Source is the sender, and if the original message was news, Source is
7123 the list of newsgroups is was posted to."
7124 (let* ((group (message-fetch-field "newsgroups"))
7127 (gnus-group-decoded-name group
)
7128 (or (message-fetch-field "from")
7131 (if message-forward-decoded-p
7133 (mail-decode-encoded-word-string prefix
))
7136 (defun message-forward-subject-fwd (subject)
7137 "Generate a SUBJECT for a forwarded message.
7138 The form is: Fwd: Subject, where Subject is the original subject of
7140 (if (string-match "^Fwd: " subject
)
7142 (concat "Fwd: " subject
)))
7144 (defun message-make-forward-subject ()
7145 "Return a Subject header suitable for the message in the current buffer."
7148 (message-narrow-to-head-1)
7149 (let ((funcs message-make-forward-subject-function
)
7150 (subject (message-fetch-field "Subject")))
7153 (if message-forward-decoded-p
7155 (mail-decode-encoded-word-string subject
))
7157 (when message-wash-forwarded-subjects
7158 (setq subject
(message-wash-subject subject
)))
7159 ;; Make sure funcs is a list.
7162 (setq funcs
(list funcs
)))
7163 ;; Apply funcs in order, passing subject generated by previous
7164 ;; func to the next one.
7165 (dolist (func funcs
)
7166 (when (functionp func
)
7167 (setq subject
(funcall func subject
))))
7170 (defvar gnus-article-decoded-p
)
7174 (defun message-forward (&optional news digest
)
7175 "Forward the current message via mail.
7176 Optional NEWS will use news to forward instead of mail.
7177 Optional DIGEST will use digest to forward."
7179 (let* ((cur (current-buffer))
7180 (message-forward-decoded-p
7181 (if (local-variable-p 'gnus-article-decoded-p
(current-buffer))
7182 gnus-article-decoded-p
;; In an article buffer.
7183 message-forward-decoded-p
))
7184 (subject (message-make-forward-subject)))
7186 (message-news nil subject
)
7187 (message-mail nil subject
))
7188 (message-forward-make-body cur digest
)))
7190 (defun message-forward-make-body-plain (forward-buffer)
7192 "\n-------------------- Start of forwarded message --------------------\n")
7194 (contents (with-current-buffer forward-buffer
(buffer-string)))
7196 (unless (featurep 'xemacs
)
7197 (unless (mm-multibyte-string-p contents
)
7198 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7199 to the multibyte buffer \"%s\""
7200 (if (bufferp forward-buffer
)
7201 (buffer-name forward-buffer
)
7204 (insert (mm-with-multibyte-buffer
7207 (goto-char (point-min))
7208 (when (looking-at "From ")
7209 (replace-match "X-From-Line: "))
7211 (unless (bolp) (insert "\n"))
7214 "-------------------- End of forwarded message --------------------\n")
7215 (message-remove-ignored-headers b e
)))
7217 (defun message-remove-ignored-headers (b e
)
7218 (when message-forward-ignored-headers
7220 (narrow-to-region b e
)
7222 (narrow-to-region (point)
7223 (or (search-forward "\n\n" nil t
) (point)))
7224 (let ((ignored (if (stringp message-forward-ignored-headers
)
7225 (list message-forward-ignored-headers
)
7226 message-forward-ignored-headers
)))
7227 (dolist (elem ignored
)
7228 (message-remove-header elem t
))))))
7230 (defun message-forward-make-body-mime (forward-buffer)
7232 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
7234 (narrow-to-region (point) (point))
7235 (mml-insert-buffer forward-buffer
)
7236 (goto-char (point-min))
7237 (when (looking-at "From ")
7238 (replace-match "X-From-Line: "))
7239 (goto-char (point-max)))
7240 (insert "<#/part>\n")
7241 ;; Consider there is no illegible text.
7242 (add-text-properties
7244 `(no-illegible-text t rear-nonsticky t start-open t
))))
7246 (defun message-forward-make-body-mml (forward-buffer)
7247 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
7248 (let ((b (point)) e
)
7249 (if (not message-forward-decoded-p
)
7250 (let ((contents (with-current-buffer forward-buffer
(buffer-string))))
7251 (unless (featurep 'xemacs
)
7252 (unless (mm-multibyte-string-p contents
)
7253 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7254 to the multibyte buffer \"%s\""
7255 (if (bufferp forward-buffer
)
7256 (buffer-name forward-buffer
)
7259 (insert (mm-with-multibyte-buffer
7262 (goto-char (point-min))
7263 (when (looking-at "From ")
7264 (replace-match "X-From-Line: "))
7267 (narrow-to-region (point) (point))
7268 (mml-insert-buffer forward-buffer
)
7269 (goto-char (point-min))
7270 (when (looking-at "From ")
7271 (replace-match "X-From-Line: "))
7272 (goto-char (point-max))))
7274 (insert "<#/mml>\n")
7275 (when (and (not message-forward-decoded-p
)
7276 message-forward-ignored-headers
)
7277 (message-remove-ignored-headers b e
))))
7279 (defun message-forward-make-body-digest-plain (forward-buffer)
7281 "\n-------------------- Start of forwarded message --------------------\n")
7282 (let ((b (point)) e
)
7283 (mml-insert-buffer forward-buffer
)
7286 "\n-------------------- End of forwarded message --------------------\n")))
7288 (defun message-forward-make-body-digest-mime (forward-buffer)
7289 (insert "\n<#multipart type=digest>\n")
7290 (let ((b (point)) e
)
7291 (insert-buffer-substring forward-buffer
)
7293 (insert "<#/multipart>\n")
7295 (narrow-to-region b e
)
7297 (narrow-to-region (point)
7298 (or (search-forward "\n\n" nil t
) (point)))
7299 (delete-region (point-min) (point-max)))))
7301 (defun message-forward-make-body-digest (forward-buffer)
7302 (if message-forward-as-mime
7303 (message-forward-make-body-digest-mime forward-buffer
)
7304 (message-forward-make-body-digest-plain forward-buffer
)))
7306 (autoload 'mm-uu-dissect-text-parts
"mm-uu")
7307 (autoload 'mm-uu-dissect
"mm-uu")
7309 (defun message-signed-or-encrypted-p (&optional dont-emulate-mime handles
)
7310 "Say whether the current buffer contains signed or encrypted message.
7311 If DONT-EMULATE-MIME is nil, this function does the MIME emulation on
7312 messages that don't conform to PGP/MIME described in RFC2015. HANDLES
7313 is for the internal use."
7315 (let ((mm-decrypt-option 'never
)
7316 (mm-verify-option 'never
))
7317 (if (setq handles
(mm-dissect-buffer nil t
))
7318 (unless dont-emulate-mime
7319 (mm-uu-dissect-text-parts handles
))
7320 (unless dont-emulate-mime
7321 (setq handles
(mm-uu-dissect))))))
7322 ;; Check text/plain message in which there is a signed or encrypted
7323 ;; body that has been encoded by B or Q.
7324 (unless (or handles dont-emulate-mime
)
7325 (let ((cur (current-buffer))
7326 (mm-decrypt-option 'never
)
7327 (mm-verify-option 'never
))
7329 (insert-buffer-substring cur
)
7330 (when (setq handles
(mm-dissect-buffer t t
))
7332 (bufferp (car handles
))
7333 (mm-destroy-parts handles
))
7334 (equal (mm-handle-media-type handles
) "text/plain"))
7336 (mm-decode-content-transfer-encoding
7337 (mm-handle-encoding handles
))
7338 (setq handles
(mm-uu-dissect)))
7339 (setq handles nil
))))))
7343 (dolist (handle (if (stringp (car handles
))
7344 (if (member (car handles
)
7345 '("multipart/signed"
7346 "multipart/encrypted"))
7350 (if (stringp (car handle
))
7351 (when (message-signed-or-encrypted-p dont-emulate-mime handle
)
7353 (when (and (bufferp (car handle
))
7354 (equal (mm-handle-media-type handle
)
7356 (with-current-buffer (mm-handle-buffer handle
)
7357 (when (message-signed-or-encrypted-p dont-emulate-mime
)
7358 (throw 'found t
)))))))
7359 (mm-destroy-parts handles
))))
7362 (defun message-forward-make-body (forward-buffer &optional digest
)
7363 ;; Put point where we want it before inserting the forwarded
7365 (if message-forward-before-signature
7367 (goto-char (point-max)))
7369 (message-forward-make-body-digest forward-buffer
)
7370 (if message-forward-as-mime
7371 (if (and message-forward-show-mml
7372 (not (and (eq message-forward-show-mml
'best
)
7373 ;; Use the raw form in the body if it contains
7374 ;; signed or encrypted message so as not to be
7375 ;; destroyed by re-encoding.
7376 (with-current-buffer forward-buffer
7378 (message-signed-or-encrypted-p)
7380 (message-forward-make-body-mml forward-buffer
)
7381 (message-forward-make-body-mime forward-buffer
))
7382 (message-forward-make-body-plain forward-buffer
)))
7383 (message-position-point))
7385 (declare-function rmail-toggle-header
"rmail" (&optional arg
))
7388 (defun message-forward-rmail-make-body (forward-buffer)
7389 (save-window-excursion
7390 (set-buffer forward-buffer
)
7391 (if (rmail-msg-is-pruned)
7392 (if (fboundp 'rmail-msg-restore-non-pruned-header
)
7393 (rmail-msg-restore-non-pruned-header) ; Emacs 22
7394 (rmail-toggle-header 0)))) ; Emacs 23
7395 (message-forward-make-body forward-buffer
))
7397 ;; Fixme: Should have defcustom.
7399 (defun message-insinuate-rmail ()
7400 "Let RMAIL use message to forward."
7402 (setq rmail-enable-mime-composing t
)
7403 (setq rmail-insert-mime-forwarded-message-function
7404 'message-forward-rmail-make-body
))
7407 (defun message-resend (address)
7408 "Resend the current article to ADDRESS."
7410 (list (message-read-from-minibuffer "Resend message to: ")))
7411 (message "Resending message to %s..." address
)
7413 (let ((cur (current-buffer))
7415 ;; We first set up a normal mail buffer.
7416 (unless (message-mail-user-agent)
7417 (set-buffer (get-buffer-create " *message resend*"))
7419 (let ((message-this-is-mail t
)
7420 message-generate-hashcash
7422 (message-setup `((To .
,address
))))
7423 ;; Insert our usual headers.
7424 (message-generate-headers '(From Date To Message-ID
))
7425 (message-narrow-to-headers)
7426 ;; Remove X-Draft-From header etc.
7427 (message-remove-header message-ignored-mail-headers t
)
7428 ;; Rename them all to "Resent-*".
7429 (goto-char (point-min))
7430 (while (re-search-forward "^[A-Za-z]" nil t
)
7435 (delete-region (point) (point-max))
7437 ;; Insert the message to be resent.
7438 (insert-buffer-substring cur
)
7439 (goto-char (point-min))
7440 (search-forward "\n\n")
7443 (narrow-to-region beg
(point))
7444 (message-remove-header message-ignored-resent-headers t
)
7445 (goto-char (point-max)))
7446 (insert mail-header-separator
)
7447 ;; Rename all old ("Also-")Resent headers.
7448 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t
)
7451 ;; Quote any "From " lines at the beginning.
7453 (when (looking-at "From ")
7454 (replace-match "X-From-Line: "))
7456 (let ((message-inhibit-body-encoding t
)
7457 (message-inhibit-ecomplete t
)
7458 message-required-mail-headers
7459 message-generate-hashcash
7460 rfc2047-encode-encoded-words
)
7461 (message-send-mail))
7462 (kill-buffer (current-buffer)))
7463 (message "Resending message to %s...done" address
)))
7466 (defun message-bounce ()
7467 "Re-mail the current message.
7468 This only makes sense if the current message is a bounce message that
7469 contains some mail you have written which has been bounced back to
7472 (let ((handles (mm-dissect-buffer t
))
7474 (message-pop-to-buffer (message-buffer-name "bounce"))
7475 (if (stringp (car handles
))
7476 ;; This is a MIME bounce.
7477 (mm-insert-part (car (last handles
)))
7478 ;; This is a non-MIME bounce, so we try to remove things
7480 (mm-insert-part handles
)
7482 (goto-char (point-min))
7483 (re-search-forward "\n\n+" nil t
)
7484 (setq boundary
(point))
7485 ;; We remove everything before the bounced mail.
7486 (if (or (re-search-forward message-unsent-separator nil t
)
7488 (search-forward "\n\n" nil
'move
)
7489 (re-search-backward "^Return-Path:.*\n" boundary t
)))
7492 (delete-region (point-min)
7493 (if (re-search-forward "^[^ \n\t]+:" nil t
)
7496 (goto-char boundary
)
7497 (when (re-search-backward "^.?From .*\n" nil t
)
7498 (delete-region (match-beginning 0) (match-end 0)))))
7501 (message-narrow-to-head-1)
7502 (message-remove-header message-ignored-bounced-headers t
)
7503 (goto-char (point-max))
7504 (insert mail-header-separator
))
7505 (message-position-point)))
7508 ;;; Interactive entry points for new message buffers.
7512 (defun message-mail-other-window (&optional to subject
)
7513 "Like `message-mail' command, but display mail buffer in another window."
7515 (unless (message-mail-user-agent)
7516 (let ((pop-up-windows t
)
7517 (special-display-buffer-names nil
)
7518 (special-display-regexps nil
)
7519 (same-window-buffer-names nil
)
7520 (same-window-regexps nil
))
7521 (message-pop-to-buffer (message-buffer-name "mail" to
))))
7522 (let ((message-this-is-mail t
))
7523 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
"")))
7524 nil nil nil
'switch-to-buffer-other-window
)))
7527 (defun message-mail-other-frame (&optional to subject
)
7528 "Like `message-mail' command, but display mail buffer in another frame."
7530 (unless (message-mail-user-agent)
7531 (let ((pop-up-frames t
)
7532 (special-display-buffer-names nil
)
7533 (special-display-regexps nil
)
7534 (same-window-buffer-names nil
)
7535 (same-window-regexps nil
))
7536 (message-pop-to-buffer (message-buffer-name "mail" to
))))
7537 (let ((message-this-is-mail t
))
7538 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
"")))
7539 nil nil nil
'switch-to-buffer-other-frame
)))
7542 (defun message-news-other-window (&optional newsgroups subject
)
7543 "Start editing a news article to be sent."
7545 (let ((pop-up-windows t
)
7546 (special-display-buffer-names nil
)
7547 (special-display-regexps nil
)
7548 (same-window-buffer-names nil
)
7549 (same-window-regexps nil
))
7550 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
)))
7551 (let ((message-this-is-news t
))
7552 (message-setup `((Newsgroups .
,(or newsgroups
""))
7553 (Subject .
,(or subject
""))))))
7556 (defun message-news-other-frame (&optional newsgroups subject
)
7557 "Start editing a news article to be sent."
7559 (let ((pop-up-frames t
)
7560 (special-display-buffer-names nil
)
7561 (special-display-regexps nil
)
7562 (same-window-buffer-names nil
)
7563 (same-window-regexps nil
))
7564 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
)))
7565 (let ((message-this-is-news t
))
7566 (message-setup `((Newsgroups .
,(or newsgroups
""))
7567 (Subject .
,(or subject
""))))))
7571 ;; This code should be moved to underline.el (from which it is stolen).
7574 (defun message-bold-region (start end
)
7575 "Bold all nonblank characters in the region.
7576 Works by overstriking characters.
7577 Called from program, takes two arguments START and END
7578 which specify the range to operate on."
7581 (let ((end1 (make-marker)))
7582 (move-marker end1
(max start end
))
7583 (goto-char (min start end
))
7584 (while (< (point) end1
)
7585 (or (looking-at "[_\^@- ]")
7586 (insert (char-after) "\b"))
7587 (forward-char 1)))))
7590 (defun message-unbold-region (start end
)
7591 "Remove all boldness (overstruck characters) in the region.
7592 Called from program, takes two arguments START and END
7593 which specify the range to operate on."
7596 (let ((end1 (make-marker)))
7597 (move-marker end1
(max start end
))
7598 (goto-char (min start end
))
7599 (while (search-forward "\b" end1 t
)
7600 (if (eq (char-after) (char-after (- (point) 2)))
7601 (delete-char -
2))))))
7603 (defun message-exchange-point-and-mark ()
7604 "Exchange point and mark, but don't activate region if it was inactive."
7605 (goto-char (prog1 (mark t
)
7606 (set-marker (mark-marker) (point)))))
7608 (defalias 'message-make-overlay
'make-overlay
)
7609 (defalias 'message-delete-overlay
'delete-overlay
)
7610 (defalias 'message-overlay-put
'overlay-put
)
7611 (defun message-kill-all-overlays ()
7612 (if (featurep 'xemacs
)
7613 (map-extents (lambda (extent ignore
) (delete-extent extent
)))
7614 (mapcar #'delete-overlay
(overlays-in (point-min) (point-max)))))
7616 ;; Support for toolbar
7617 (defvar tool-bar-mode
)
7619 ;; Note: The :set function in the `message-tool-bar*' variables will only
7620 ;; affect _new_ message buffers. We might add a function that walks thru all
7621 ;; message-mode buffers and force the update.
7622 (defun message-tool-bar-update (&optional symbol value
)
7623 "Update message mode toolbar.
7624 Setter function for custom variables."
7625 (setq-default message-tool-bar-map nil
)
7627 ;; When used as ":set" function:
7628 (set-default symbol value
)))
7630 (defcustom message-tool-bar
(if (eq gmm-tool-bar-style
'gnome
)
7631 'message-tool-bar-gnome
7632 'message-tool-bar-retro
)
7633 "Specifies the message mode tool bar.
7635 It can be either a list or a symbol refering to a list. See
7636 `gmm-tool-bar-from-list' for the format of the list. The
7637 default key map is `message-mode-map'.
7639 Pre-defined symbols include `message-tool-bar-gnome' and
7640 `message-tool-bar-retro'."
7641 :type
'(repeat gmm-tool-bar-list-item
)
7642 :type
'(choice (const :tag
"GNOME style" message-tool-bar-gnome
)
7643 (const :tag
"Retro look" message-tool-bar-retro
)
7644 (repeat :tag
"User defined list" gmm-tool-bar-item
)
7646 :version
"23.1" ;; No Gnus
7647 :initialize
'custom-initialize-default
7648 :set
'message-tool-bar-update
7651 (defcustom message-tool-bar-gnome
7652 '((ispell-message "spell" nil
7653 :visible
(or (not (boundp 'flyspell-mode
))
7654 (not flyspell-mode
)))
7655 (flyspell-buffer "spell" t
7656 :visible
(and (boundp 'flyspell-mode
)
7658 :help
"Flyspell whole buffer")
7659 (gmm-ignore "separator")
7660 (message-send-and-exit "mail/send")
7661 (message-dont-send "mail/save-draft")
7662 (message-kill-buffer "close") ;; stock_cancel
7663 (mml-attach-file "attach" mml-mode-map
)
7664 (mml-preview "mail/preview" mml-mode-map
)
7665 (mml-secure-message-sign-encrypt "lock" mml-mode-map
:visible nil
)
7666 (message-insert-importance-high "important" nil
:visible nil
)
7667 (message-insert-importance-low "unimportant" nil
:visible nil
)
7668 (message-insert-disposition-notification-to "receipt" nil
:visible nil
)
7669 (gmm-customize-mode "preferences" t
:help
"Edit mode preferences")
7670 (message-info "help" t
:help
"Message manual"))
7671 "List of items for the message tool bar (GNOME style).
7673 See `gmm-tool-bar-from-list' for details on the format of the list."
7674 :type
'(repeat gmm-tool-bar-item
)
7675 :version
"23.1" ;; No Gnus
7676 :initialize
'custom-initialize-default
7677 :set
'message-tool-bar-update
7680 (defcustom message-tool-bar-retro
7681 '(;; Old Emacs 21 icon for consistency.
7682 (message-send-and-exit "gnus/mail-send")
7683 (message-kill-buffer "close")
7684 (message-dont-send "cancel")
7685 (mml-attach-file "attach" mml-mode-map
)
7686 (ispell-message "spell")
7687 (mml-preview "preview" mml-mode-map
)
7688 (message-insert-importance-high "gnus/important")
7689 (message-insert-importance-low "gnus/unimportant")
7690 (message-insert-disposition-notification-to "gnus/receipt"))
7691 "List of items for the message tool bar (retro style).
7693 See `gmm-tool-bar-from-list' for details on the format of the list."
7694 :type
'(repeat gmm-tool-bar-item
)
7695 :version
"23.1" ;; No Gnus
7696 :initialize
'custom-initialize-default
7697 :set
'message-tool-bar-update
7700 (defcustom message-tool-bar-zap-list
7701 '(new-file open-file dired kill-buffer write-file
7702 print-buffer customize help
)
7703 "List of icon items from the global tool bar.
7704 These items are not displayed on the message mode tool bar.
7706 See `gmm-tool-bar-from-list' for the format of the list."
7707 :type
'gmm-tool-bar-zap-list
7708 :version
"23.1" ;; No Gnus
7709 :initialize
'custom-initialize-default
7710 :set
'message-tool-bar-update
7713 (defvar image-load-path
)
7715 (defun message-make-tool-bar (&optional force
)
7716 "Make a message mode tool bar from `message-tool-bar-list'.
7717 When FORCE, rebuild the tool bar."
7718 (when (and (not (featurep 'xemacs
))
7719 (boundp 'tool-bar-mode
)
7721 (or (not message-tool-bar-map
) force
))
7722 (setq message-tool-bar-map
7724 (gmm-image-load-path-for-library "message"
7725 "mail/save-draft.xpm"
7727 (image-load-path (cons (car load-path
)
7728 (when (boundp 'image-load-path
)
7730 (gmm-tool-bar-from-list message-tool-bar
7731 message-tool-bar-zap-list
7732 'message-mode-map
))))
7733 message-tool-bar-map
)
7735 ;;; Group name completion.
7737 (defcustom message-newgroups-header-regexp
7738 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
7739 "Regexp that match headers that lists groups."
7743 (defcustom message-completion-alist
7744 (list (cons message-newgroups-header-regexp
'message-expand-group
)
7745 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name
)
7746 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
7747 . message-expand-name
)
7748 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
7749 . message-expand-name
))
7750 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
7753 :type
'(alist :key-type regexp
:value-type function
))
7755 (defcustom message-expand-name-databases
7757 "List of databases to try for name completion (`message-expand-name').
7758 Each element is a symbol and can be `bbdb' or `eudc'."
7760 :type
'(set (const bbdb
) (const eudc
)))
7762 (defcustom message-tab-body-function nil
7763 "*Function to execute when `message-tab' (TAB) is executed in the body.
7764 If nil, the function bound in `text-mode-map' or `global-map' is executed."
7767 :link
'(custom-manual "(message)Various Commands")
7768 :type
'(choice (const nil
)
7771 (declare-function mail-abbrev-in-expansion-header-p
"mailabbrev" ())
7773 (defun message-tab ()
7774 "Complete names according to `message-completion-alist'.
7775 Execute function specified by `message-tab-body-function' when not in
7778 (let ((alist message-completion-alist
))
7780 (let ((mail-abbrev-mode-regexp (caar alist
)))
7781 (not (mail-abbrev-in-expansion-header-p))))
7782 (setq alist
(cdr alist
)))
7783 (funcall (or (cdar alist
) message-tab-body-function
7784 (lookup-key text-mode-map
"\t")
7785 (lookup-key global-map
"\t")
7786 'indent-relative
))))
7791 (let ((standard-output (current-buffer)))
7792 (eval '(display-completion-list nil
"")))
7793 (defalias 'message-display-completion-list
'display-completion-list
))
7794 (error ;; Don't use `wrong-number-of-arguments' here because of XEmacs.
7795 (defun message-display-completion-list (completions &optional ignore
)
7796 "Display the list of completions, COMPLETIONS, using `standard-output'."
7797 (display-completion-list completions
)))))
7799 (defun message-expand-group ()
7800 "Expand the group name under point."
7801 (let* ((b (save-excursion
7806 (skip-chars-forward "^:")
7809 (skip-chars-backward "^, \t\n") (point))))
7810 (completion-ignore-case t
)
7811 (e (progn (skip-chars-forward "^,\t\n ") (point)))
7812 (hashtb (and (boundp 'gnus-active-hashtb
) gnus-active-hashtb
)))
7813 (message-completion-in-region e b hashtb
)))
7815 (defalias 'message-completion-in-region
7816 (if (fboundp 'completion-in-region
)
7817 'completion-in-region
7818 (lambda (e b hashtb
)
7819 (let* ((string (buffer-substring b e
))
7820 (completions (all-completions string hashtb
))
7822 (delete-region b
(point))
7824 ((= (length completions
) 1)
7825 (if (string= (car completions
) string
)
7828 (message "Only matching group"))
7829 (insert (car completions
))))
7830 ((and (setq comp
(try-completion string hashtb
))
7831 (not (string= comp string
)))
7836 (message "No matching groups")
7837 (save-selected-window
7838 (pop-to-buffer "*Completions*")
7839 (buffer-disable-undo)
7840 (let ((buffer-read-only nil
))
7842 (let ((standard-output (current-buffer)))
7843 (message-display-completion-list (sort completions
'string
<)
7845 (setq buffer-read-only nil
)
7846 (goto-char (point-min))
7847 (delete-region (point)
7848 (progn (forward-line 3) (point))))))))))))
7850 (defun message-expand-name ()
7851 (cond ((and (memq 'eudc message-expand-name-databases
)
7852 (boundp 'eudc-protocol
)
7854 (eudc-expand-inline))
7855 ((and (memq 'bbdb message-expand-name-databases
)
7856 (fboundp 'bbdb-complete-name
))
7857 (bbdb-complete-name))
7863 (defun message-talkative-question (ask question show
&rest text
)
7864 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
7865 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
7866 The following arguments may contain lists of values."
7868 (setq text
(message-flatten-list text
)))
7869 (save-window-excursion
7870 (with-output-to-temp-buffer " *MESSAGE information message*"
7871 (with-current-buffer " *MESSAGE information message*"
7872 (fundamental-mode) ; for Emacs 20.4+
7874 (goto-char (point-min))))
7875 (funcall ask question
))
7876 (funcall ask question
)))
7878 (defun message-flatten-list (list)
7879 "Return a new, flat list that contains all elements of LIST.
7881 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
7884 (apply 'append
(mapcar 'message-flatten-list list
)))
7888 (defun message-generate-new-buffer-clone-locals (name &optional varstr
)
7889 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
7890 Then clone the local variables and values from the old buffer to the
7891 new one, cloning only the locals having a substring matching the
7893 (let ((oldbuf (current-buffer)))
7894 (with-current-buffer (generate-new-buffer name
)
7895 (message-clone-locals oldbuf varstr
)
7898 (defun message-clone-locals (buffer &optional varstr
)
7899 "Clone the local variables from BUFFER to the current buffer."
7900 (let ((locals (with-current-buffer buffer
(buffer-local-variables)))
7901 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address"))
7904 (when (and (consp local
)
7906 (string-match regexp
(symbol-name (car local
)))
7908 (string-match varstr
(symbol-name (car local
)))))
7910 (set (make-local-variable (car local
))
7918 (defvar message-inhibit-body-encoding nil
)
7920 (defun message-encode-message-body ()
7921 (unless message-inhibit-body-encoding
7922 (let ((mail-parse-charset (or mail-parse-charset
7923 message-default-charset
))
7924 (case-fold-search t
)
7925 lines content-type-p
)
7928 (narrow-to-region (point) (point-max))
7929 (let ((new (mml-generate-mime)))
7931 (delete-region (point-min) (point-max))
7933 (goto-char (point-min))
7934 (if (eq (aref new
0) ?
\n)
7936 (search-forward "\n\n")
7937 (setq lines
(buffer-substring (point-min) (1- (point))))
7938 (delete-region (point-min) (point))))))
7940 (message-narrow-to-headers-or-head)
7941 (message-remove-header "Mime-Version")
7942 (goto-char (point-max))
7943 (insert "MIME-Version: 1.0\n")
7946 (setq content-type-p
7948 (re-search-backward "^Content-Type:" nil t
))))
7950 (message-narrow-to-headers-or-head)
7951 (message-remove-first-header "Content-Type")
7952 (message-remove-first-header "Content-Transfer-Encoding"))
7953 ;; We always make sure that the message has a Content-Type
7954 ;; header. This is because some broken MTAs and MUAs get
7955 ;; awfully confused when confronted with a message with a
7956 ;; MIME-Version header and without a Content-Type header. For
7957 ;; instance, Solaris' /usr/bin/mail.
7958 (unless content-type-p
7959 (goto-char (point-min))
7960 ;; For unknown reason, MIME-Version doesn't exist.
7961 (when (re-search-forward "^MIME-Version:" nil t
)
7963 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
7965 (defun message-read-from-minibuffer (prompt &optional initial-contents
)
7966 "Read from the minibuffer while providing abbrev expansion."
7967 (if (fboundp 'mail-abbrevs-setup
)
7968 (let ((mail-abbrev-mode-regexp "")
7969 (minibuffer-setup-hook 'mail-abbrevs-setup
)
7970 (minibuffer-local-map message-minibuffer-local-map
))
7971 (read-from-minibuffer prompt initial-contents
))
7972 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook
)
7973 (minibuffer-local-map message-minibuffer-local-map
))
7974 (read-string prompt initial-contents
))))
7976 (defun message-use-alternative-email-as-from ()
7977 "Set From field of the outgoing message to the first matching
7978 address in `message-alternative-emails', looking at To, Cc and
7979 From headers in the original article."
7980 (require 'mail-utils
)
7981 (let* ((fields '("To" "Cc" "From"))
7984 (mail-strip-quoted-names
7985 (mapconcat 'message-fetch-reply-field fields
","))
7989 (if (string-match message-alternative-emails
(car emails
))
7990 (setq email
(car emails
)
7993 (unless (or (not email
) (equal email user-mail-address
))
7994 (message-remove-header "From")
7995 (goto-char (point-max))
7996 (insert "From: " (let ((user-mail-address email
)) (message-make-from))
7999 (defun message-options-get (symbol)
8000 (cdr (assq symbol message-options
)))
8002 (defun message-options-set (symbol value
)
8003 (let ((the-cons (assq symbol message-options
)))
8006 (setcdr the-cons value
)
8007 (setq message-options
(delq the-cons message-options
)))
8009 (push (cons symbol value
) message-options
))))
8012 (defun message-options-set-recipient ()
8014 (message-narrow-to-headers-or-head)
8015 (message-options-set 'message-sender
8016 (mail-strip-quoted-names
8017 (message-fetch-field "from")))
8018 (message-options-set 'message-recipients
8019 (mail-strip-quoted-names
8020 (let ((to (message-fetch-field "to"))
8021 (cc (message-fetch-field "cc"))
8022 (bcc (message-fetch-field "bcc")))
8025 (if (and to cc
) ", ")
8027 (if (and (or to cc
) bcc
) ", ")
8030 (defun message-hide-headers ()
8031 "Hide headers based on the `message-hidden-headers' variable."
8032 (let ((regexps (if (stringp message-hidden-headers
)
8033 (list message-hidden-headers
)
8034 message-hidden-headers
))
8035 (inhibit-point-motion-hooks t
)
8036 (after-change-functions nil
)
8037 (end-of-headers (point-min)))
8041 (message-narrow-to-headers)
8042 (goto-char (point-min))
8044 (if (not (message-hide-header-p regexps
))
8045 (message-next-header)
8046 (let ((begin (point))
8048 (message-next-header)
8049 (setq header
(buffer-substring begin
(point))
8050 header-len
(- (point) begin
))
8051 (delete-region begin
(point))
8052 (goto-char end-of-headers
)
8054 (setq end-of-headers
8055 (+ end-of-headers header-len
))))))))
8056 (narrow-to-region end-of-headers
(point-max))))
8058 (defun message-hide-header-p (regexps)
8061 (when (eq (car regexps
) 'not
)
8064 (dolist (regexp regexps
)
8065 (setq result
(or result
(looking-at regexp
))))
8070 (declare-function ecomplete-add-item
"ecomplete" (type key text
))
8071 (declare-function ecomplete-save
"ecomplete" ())
8073 (defun message-put-addresses-in-ecomplete ()
8074 (require 'ecomplete
)
8075 (dolist (header '("to" "cc" "from" "reply-to"))
8076 (let ((value (message-field-value header
)))
8077 (dolist (string (mail-header-parse-addresses value
'raw
))
8079 (gnus-replace-in-string
8080 (gnus-replace-in-string string
"^ +\\| +$" "") "\n" ""))
8081 (ecomplete-add-item 'mail
(car (mail-header-parse-address string
))
8085 (autoload 'ecomplete-display-matches
"ecomplete")
8087 (defun message-display-abbrev (&optional choose
)
8088 "Display the next possible abbrev for the text before point."
8089 (interactive (list t
))
8090 (when (and (memq (char-after (point-at-bol)) '(?C ?T ?
\t ?
))
8091 (message-point-in-header-p)
8094 (while (and (memq (char-after) '(?
\t ?
))
8095 (zerop (forward-line -
1))))
8096 (looking-at "To:\\|Cc:")))
8097 (let* ((end (point))
8098 (start (save-excursion
8099 (and (re-search-backward "[\n\t ]" nil t
)
8101 (word (when start
(buffer-substring start end
)))
8102 (match (when (and word
8103 (not (zerop (length word
))))
8104 (ecomplete-display-matches 'mail word choose
))))
8105 (when (and choose match
)
8106 (delete-region start end
)
8109 ;; To send pre-formatted letters like the example below, you can use
8110 ;; `message-send-form-letter':
8111 ;; --8<---------------cut here---------------start------------->8---
8112 ;; To: alice@invalid.invalid
8113 ;; Subject: Verification of your contact information
8114 ;; From: Contact verification <admin@foo.invalid>
8115 ;; --text follows this line--
8117 ;; please verify that your contact information is still valid:
8118 ;; Alice A, A avenue 11, 1111 A town, Austria
8119 ;; ----------next form letter message follows this line----------
8120 ;; To: bob@invalid.invalid
8121 ;; Subject: Verification of your contact information
8122 ;; From: Contact verification <admin@foo.invalid>
8123 ;; --text follows this line--
8125 ;; please verify that your contact information is still valid:
8126 ;; Bob, B street 22, 22222 Be town, Belgium
8127 ;; ----------next form letter message follows this line----------
8128 ;; To: charlie@invalid.invalid
8129 ;; Subject: Verification of your contact information
8130 ;; From: Contact verification <admin@foo.invalid>
8131 ;; --text follows this line--
8133 ;; please verify that your contact information is still valid:
8134 ;; Charlie Chaplin, C plaza 33, 33333 C town, Chile
8135 ;; --8<---------------cut here---------------end--------------->8---
8137 ;; FIXME: What is the most common term (circular letter, form letter, serial
8138 ;; letter, standard letter) for such kind of letter? See also
8139 ;; <http://en.wikipedia.org/wiki/Form_letter>
8141 ;; FIXME: Maybe extent message-mode's font-lock support to recognize
8142 ;; `message-form-letter-separator', i.e. highlight each message like a single
8145 (defcustom message-form-letter-separator
8146 "\n----------next form letter message follows this line----------\n"
8147 "Separator for `message-send-form-letter'."
8148 ;; :group 'message-form-letter
8149 :group
'message-various
8150 :version
"23.1" ;; No Gnus
8153 (defcustom message-send-form-letter-delay
1
8154 "Delay in seconds when sending a message with `message-send-form-letter'.
8155 Only used when `message-send-form-letter' is called with non-nil
8157 ;; :group 'message-form-letter
8158 :group
'message-various
8159 :version
"23.1" ;; No Gnus
8162 (defun message-send-form-letter (&optional force
)
8163 "Sent all form letter messages from current buffer.
8164 Unless FORCE, prompt before sending.
8166 The messages are separated by `message-form-letter-separator'.
8167 Header and body are separated by `mail-header-separator'."
8169 (let ((sent 0) (skipped 0)
8173 (goto-char (point-min))
8176 end
(if (search-forward message-form-letter-separator nil t
)
8177 (- (point) (length message-form-letter-separator
) -
1)
8181 (buffer-substring-no-properties start end
))
8182 (setq buff
(generate-new-buffer "*mail - form letter*"))
8183 (with-current-buffer buff
8186 (setq to
(message-fetch-field "To"))
8187 (switch-to-buffer buff
)
8189 (sit-for message-send-form-letter-delay
))
8191 (y-or-n-p (format "Send message to `%s'? " to
)))
8193 (setq sent
(1+ sent
))
8194 (message-send-and-exit))
8195 (message (format "Message to `%s' skipped." to
))
8196 (setq skipped
(1+ skipped
)))
8197 (when (buffer-live-p buff
)
8198 (kill-buffer buff
))))
8199 (message "%s message(s) sent, %s skipped." sent skipped
)))
8201 (defun message-replace-header (header new-value
&optional after force
)
8202 "Remove HEADER and insert the NEW-VALUE.
8203 If AFTER, insert after this header. If FORCE, insert new field
8204 even if NEW-VALUE is empty."
8205 ;; Similar to `nnheader-replace-header' but for message buffers.
8208 (message-narrow-to-headers)
8209 (message-remove-header header
))
8210 (when (or force
(> (length new-value
) 0))
8212 (message-position-on-field header after
)
8213 (message-position-on-field header
))
8214 (insert new-value
))))
8216 (defcustom message-recipients-without-full-name
8217 (list "ding@gnus.org"
8219 "emacs-devel@gnu.org"
8220 "emacs-pretest-bug@gnu.org"
8221 "bug-gnu-emacs@gnu.org")
8222 "Mail addresses that have no full name.
8223 Used in `message-simplify-recipients'."
8224 ;; Maybe the addresses could be extracted from
8225 ;; `gnus-parameter-to-list-alist'?
8226 :type
'(choice (const :tag
"None" nil
)
8228 :version
"23.1" ;; No Gnus
8229 :group
'message-headers
)
8231 (defun message-simplify-recipients ()
8233 (dolist (hdr '("Cc" "To"))
8234 (message-replace-header
8238 (if (and message-recipients-without-full-name
8240 (regexp-opt message-recipients-without-full-name
)
8244 (message-make-from (car addrcomp
) (cadr addrcomp
))
8246 (when (message-fetch-field hdr
)
8247 (mail-extract-address-components
8248 (message-fetch-field hdr
) t
))
8251 (when (featurep 'xemacs
)
8252 (require 'messagexmas
)
8253 (message-xmas-redefine))
8257 (run-hooks 'message-load-hook
)
8260 ;; coding: iso-8859-1
8263 ;;; message.el ends here