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 "*Specifies how \"From\" headers look.
165 If nil, they contain just the return address like:
167 If `parens', they look like:
168 king@grassland.com (Elvis Parsley)
169 If `angles', they look like:
170 Elvis Parsley <king@grassland.com>
172 Otherwise, most addresses look like `angles', but they look like
173 `parens' if `angles' would need quoting and `parens' would not."
175 :type
'(choice (const :tag
"simple" nil
)
179 :group
'message-headers
)
181 (defcustom message-insert-canlock t
182 "Whether to insert a Cancel-Lock header in news postings."
184 :group
'message-headers
187 (defcustom message-syntax-checks
188 (if message-insert-canlock
'((sender . disabled
)) nil
)
189 ;; Guess this one shouldn't be easy to customize...
190 "*Controls what syntax checks should not be performed on outgoing posts.
191 To disable checking of long signatures, for instance, add
192 `(signature . disabled)' to this list.
194 Don't touch this variable unless you really know what you're doing.
196 Checks include `approved', `bogus-recipient', `continuation-headers',
197 `control-chars', `empty', `existing-newsgroups', `from', `illegible-text',
198 `invisible-text', `long-header-lines', `long-lines', `message-id',
199 `multiple-headers', `new-text', `newsgroups', `quoting-style',
200 `repeated-newsgroups', `reply-to', `sender', `sendsys', `shoot',
201 `shorten-followup-to', `signature', `size', `subject', `subject-cmsg'
202 and `valid-newsgroups'."
204 :type
'(repeat sexp
)) ; Fixme: improve this
206 (defcustom message-required-headers
'((optional . References
)
208 "*Headers to be generated or prompted for when sending a message.
209 Also see `message-required-news-headers' and
210 `message-required-mail-headers'."
213 :group
'message-headers
214 :link
'(custom-manual "(message)Message Headers")
215 :type
'(repeat sexp
))
217 (defcustom message-draft-headers
'(References From Date
)
218 "*Headers to be generated when saving a draft message."
221 :group
'message-headers
222 :link
'(custom-manual "(message)Message Headers")
223 :type
'(repeat sexp
))
225 (defcustom message-required-news-headers
226 '(From Newsgroups Subject Date Message-ID
227 (optional . Organization
)
228 (optional . User-Agent
))
229 "*Headers to be generated or prompted for when posting an article.
230 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
231 Message-ID. Organization, Lines, In-Reply-To, Expires, and
232 User-Agent are optional. If you don't want message to insert some
233 header, remove it from this list."
235 :group
'message-headers
236 :link
'(custom-manual "(message)Message Headers")
237 :type
'(repeat sexp
))
239 (defcustom message-required-mail-headers
240 '(From Subject Date
(optional . In-Reply-To
) Message-ID
241 (optional . User-Agent
))
242 "*Headers to be generated or prompted for when mailing a message.
243 It is recommended that From, Date, To, Subject and Message-ID be
244 included. Organization and User-Agent are optional."
246 :group
'message-headers
247 :link
'(custom-manual "(message)Message Headers")
248 :type
'(repeat sexp
))
250 (defcustom message-prune-recipient-rules nil
251 "Rules for how to prune the list of recipients when doing wide replies.
252 This is a list of regexps and regexp matches."
255 :group
'message-headers
256 :link
'(custom-manual "(message)Wide Reply")
257 :type
'(repeat regexp
))
259 (defcustom message-deletable-headers
'(Message-ID Date Lines
)
260 "Headers to be deleted if they already exist and were generated by message previously."
261 :group
'message-headers
262 :link
'(custom-manual "(message)Message Headers")
265 (defcustom message-ignored-news-headers
266 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
267 "*Regexp of headers to be removed unconditionally before posting."
269 :group
'message-headers
270 :link
'(custom-manual "(message)Message Headers")
271 :type
'(repeat :value-to-internal
(lambda (widget value
)
272 (custom-split-regexp-maybe value
))
273 :match
(lambda (widget value
)
275 (widget-editable-list-match widget value
)))
278 (defcustom message-ignored-mail-headers
279 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
280 "*Regexp of headers to be removed unconditionally before mailing."
282 :group
'message-headers
283 :link
'(custom-manual "(message)Mail Headers")
286 (defcustom message-ignored-supersedes-headers
"^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|^X-Trace:\\|^X-ID:\\|^X-Complaints-To:\\|Return-Path:\\|^Supersedes:\\|^NNTP-Posting-Date:\\|^X-Trace:\\|^X-Complaints-To:\\|^Cancel-Lock:\\|^Cancel-Key:\\|^X-Hashcash:\\|^X-Payment:\\|^Approved:\\|^Injection-Date:\\|^Injection-Info:"
287 "*Header lines matching this regexp will be deleted before posting.
288 It's best to delete old Path and Date headers before posting to avoid
290 :group
'message-interface
291 :link
'(custom-manual "(message)Superseding")
292 :type
'(repeat :value-to-internal
(lambda (widget value
)
293 (custom-split-regexp-maybe value
))
294 :match
(lambda (widget value
)
296 (widget-editable-list-match widget value
)))
299 (defcustom message-subject-re-regexp
300 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)*:[ \t]*\\)*[ \t]*"
301 "*Regexp matching \"Re: \" in the subject line."
302 :group
'message-various
303 :link
'(custom-manual "(message)Message Headers")
306 ;;; Start of variables adopted from `message-utils.el'.
308 (defcustom message-subject-trailing-was-query
'ask
309 "*What to do with trailing \"(was: <old subject>)\" in subject lines.
310 If nil, leave the subject unchanged. If it is the symbol `ask', query
311 the user what do do. In this case, the subject is matched against
312 `message-subject-trailing-was-ask-regexp'. If
313 `message-subject-trailing-was-query' is t, always strip the trailing
314 old subject. In this case, `message-subject-trailing-was-regexp' is
317 :type
'(choice (const :tag
"never" nil
)
318 (const :tag
"always strip" t
)
320 :link
'(custom-manual "(message)Message Headers")
321 :group
'message-various
)
323 (defcustom message-subject-trailing-was-ask-regexp
324 "[ \t]*\\([[(]+[Ww][Aa][Ss][ \t]*.*[\])]+\\)"
325 "*Regexp matching \"(was: <old subject>)\" in the subject line.
327 The function `message-strip-subject-trailing-was' uses this regexp if
328 `message-subject-trailing-was-query' is set to the symbol `ask'. If
329 the variable is t instead of `ask', use
330 `message-subject-trailing-was-regexp' instead.
332 It is okay to create some false positives here, as the user is asked."
334 :group
'message-various
335 :link
'(custom-manual "(message)Message Headers")
338 (defcustom message-subject-trailing-was-regexp
339 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
340 "*Regexp matching \"(was: <old subject>)\" in the subject line.
342 If `message-subject-trailing-was-query' is set to t, the subject is
343 matched against `message-subject-trailing-was-regexp' in
344 `message-strip-subject-trailing-was'. You should use a regexp creating very
345 few false positives here."
347 :group
'message-various
348 :link
'(custom-manual "(message)Message Headers")
351 ;;; marking inserted text
353 (defcustom message-mark-insert-begin
354 "--8<---------------cut here---------------start------------->8---\n"
355 "How to mark the beginning of some inserted text."
358 :link
'(custom-manual "(message)Insertion Variables")
359 :group
'message-various
)
361 (defcustom message-mark-insert-end
362 "--8<---------------cut here---------------end--------------->8---\n"
363 "How to mark the end of some inserted text."
366 :link
'(custom-manual "(message)Insertion Variables")
367 :group
'message-various
)
369 (defcustom message-archive-header
"X-No-Archive: Yes\n"
370 "Header to insert when you don't want your article to be archived.
371 Archives \(such as groups.google.com\) respect this header."
374 :link
'(custom-manual "(message)Header Commands")
375 :group
'message-various
)
377 (defcustom message-archive-note
378 "X-No-Archive: Yes - save http://groups.google.com/"
379 "Note to insert why you wouldn't want this posting archived.
380 If nil, don't insert any text in the body."
382 :type
'(radio string
(const nil
))
383 :link
'(custom-manual "(message)Header Commands")
384 :group
'message-various
)
386 ;;; Crossposts and Followups
387 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
388 ;; new suggestions by R. Weikusat <rw at another.de>
390 (defvar message-cross-post-old-target nil
391 "Old target for cross-posts or follow-ups.")
392 (make-variable-buffer-local 'message-cross-post-old-target
)
394 (defcustom message-cross-post-default t
395 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
396 If nil, `message-cross-post-followup-to' will only do a followup. Note that
397 you can explicitly override this setting by calling
398 `message-cross-post-followup-to' with a prefix."
401 :group
'message-various
)
403 (defcustom message-cross-post-note
"Crosspost & Followup-To: "
404 "Note to insert before signature to notify of cross-post and follow-up."
407 :group
'message-various
)
409 (defcustom message-followup-to-note
"Followup-To: "
410 "Note to insert before signature to notify of follow-up only."
413 :group
'message-various
)
415 (defcustom message-cross-post-note-function
'message-cross-post-insert-note
416 "Function to use to insert note about Crosspost or Followup-To.
417 The function will be called with four arguments. The function should not only
418 insert a note, but also ensure old notes are deleted. See the documentation
419 for `message-cross-post-insert-note'."
422 :group
'message-various
)
424 ;;; End of variables adopted from `message-utils.el'.
426 (defcustom message-signature-separator
"^-- $"
427 "Regexp matching the signature separator.
428 This variable is used to strip off the signature from quoted text
429 when `message-cite-function' is
430 `message-cite-original-without-signature'. Most useful values
431 are \"^-- $\" (strict) and \"^-- *$\" (loose; allow missing
433 :type
'(choice (const :tag
"strict" "^-- $")
434 (const :tag
"loose" "^-- *$")
436 :version
"22.3" ;; Gnus 5.10.12 (changed default)
437 :link
'(custom-manual "(message)Various Message Variables")
438 :group
'message-various
)
440 (defcustom message-elide-ellipsis
"\n[...]\n\n"
441 "*The string which is inserted for elided text."
443 :link
'(custom-manual "(message)Various Commands")
444 :group
'message-various
)
446 (defcustom message-interactive mail-interactive
447 "Non-nil means when sending a message wait for and display errors.
448 A value of nil means let mailer mail back a message to report errors."
450 :group
'message-sending
452 :link
'(custom-manual "(message)Sending Variables")
455 (defcustom message-confirm-send nil
456 "When non-nil, ask for confirmation when sending a message."
457 :group
'message-sending
459 :version
"23.1" ;; No Gnus
460 :link
'(custom-manual "(message)Sending Variables")
463 (defcustom message-generate-new-buffers
'unsent
464 "*Say whether to create a new message buffer to compose a message.
465 Valid values include:
468 Generate the buffer name in the Message way (e.g., *mail*, *news*,
469 *mail to whom*, *news on group*, etc.) and continue editing in the
470 existing buffer of that name. If there is no such buffer, it will
474 Create the new buffer with the name generated in the Message way.
477 Similar to `unique' but the buffer name begins with \"*unsent \".
480 Similar to nil but the buffer name is simpler like *mail message*.
483 If this is a function, call that function with three parameters:
484 The type, the To address and the group name (any of these may be nil).
485 The function should return the new buffer name."
487 :group
'message-buffers
488 :link
'(custom-manual "(message)Message Buffers")
489 :type
'(choice (const nil
)
490 (sexp :tag
"unique" :format
"unique\n" :value unique
491 :match
(lambda (widget value
) (memq value
'(unique t
))))
494 (function :format
"\n %{%t%}: %v")))
496 (defcustom message-kill-buffer-on-exit nil
497 "*Non-nil means that the message buffer will be killed after sending a message."
498 :group
'message-buffers
499 :link
'(custom-manual "(message)Message Buffers")
502 (defcustom message-kill-buffer-query t
503 "*Non-nil means that killing a modified message buffer has to be confirmed.
504 This is used by `message-kill-buffer'."
505 :version
"23.1" ;; No Gnus
506 :group
'message-buffers
509 (defvar gnus-local-organization
)
510 (defcustom message-user-organization
511 (or (and (boundp 'gnus-local-organization
)
512 (stringp gnus-local-organization
)
513 gnus-local-organization
)
514 (getenv "ORGANIZATION")
516 "*String to be used as an Organization header.
517 If t, use `message-user-organization-file'."
518 :group
'message-headers
519 :type
'(choice string
520 (const :tag
"consult file" t
)))
522 (defcustom message-user-organization-file
524 (dolist (f (list "/etc/organization"
525 "/etc/news/organization"
526 "/usr/lib/news/organization"))
527 (when (file-readable-p f
)
530 "*Local news organization file."
532 :link
'(custom-manual "(message)News Headers")
533 :group
'message-headers
)
535 (defcustom message-make-forward-subject-function
536 #'message-forward-subject-name-subject
537 "*List of functions called to generate subject headers for forwarded messages.
538 The subject generated by the previous function is passed into each
541 The provided functions are:
543 * `message-forward-subject-author-subject' Source of article (author or
544 newsgroup), in brackets followed by the subject
545 * `message-forward-subject-name-subject' Source of article (name of author
546 or newsgroup), in brackets followed by the subject
547 * `message-forward-subject-fwd' Subject of article with 'Fwd:' prepended
549 :group
'message-forwarding
550 :link
'(custom-manual "(message)Forwarding")
551 :type
'(radio (function-item message-forward-subject-author-subject
)
552 (function-item message-forward-subject-fwd
)
553 (function-item message-forward-subject-name-subject
)
554 (repeat :tag
"List of functions" function
)))
556 (defcustom message-forward-as-mime t
557 "*Non-nil means forward messages as an inline/rfc822 MIME section.
558 Otherwise, directly inline the old message in the forwarded message."
560 :group
'message-forwarding
561 :link
'(custom-manual "(message)Forwarding")
564 (defcustom message-forward-show-mml
'best
565 "*Non-nil means show forwarded messages as MML (decoded from MIME).
566 Otherwise, forwarded messages are unchanged.
567 Can also be the symbol `best' to indicate that MML should be
568 used, except when it is a bad idea to use MML. One example where
569 it is a bad idea is when forwarding a signed or encrypted
570 message, because converting MIME to MML would invalidate the
573 :group
'message-forwarding
574 :type
'(choice (const :tag
"use MML" t
)
575 (const :tag
"don't use MML " nil
)
576 (const :tag
"use MML when appropriate" best
)))
578 (defcustom message-forward-before-signature t
579 "*Non-nil means put forwarded message before signature, else after."
580 :group
'message-forwarding
583 (defcustom message-wash-forwarded-subjects nil
584 "*Non-nil means try to remove as much cruft as possible from the subject.
585 Done before generating the new subject of a forward."
586 :group
'message-forwarding
587 :link
'(custom-manual "(message)Forwarding")
590 (defcustom message-ignored-resent-headers
591 ;; `Delivered-To' needs to be removed because some mailers use it to
592 ;; detect loops, so if you resend a message to an address that ultimately
593 ;; comes back to you (e.g. a mailing-list to which you subscribe, in which
594 ;; case you may be removed from the list on the grounds that mail to you
595 ;; bounced with a "mailing loop" error).
596 "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From \\|^Delivered-To:"
597 "*All headers that match this regexp will be deleted when resending a message."
598 :group
'message-interface
599 :link
'(custom-manual "(message)Resending")
600 :type
'(repeat :value-to-internal
(lambda (widget value
)
601 (custom-split-regexp-maybe value
))
602 :match
(lambda (widget value
)
604 (widget-editable-list-match widget value
)))
607 (defcustom message-forward-ignored-headers
"^Content-Transfer-Encoding:\\|^X-Gnus"
608 "*All headers that match this regexp will be deleted when forwarding a message."
610 :group
'message-forwarding
611 :type
'(repeat :value-to-internal
(lambda (widget value
)
612 (custom-split-regexp-maybe value
))
613 :match
(lambda (widget value
)
615 (widget-editable-list-match widget value
)))
618 (defcustom message-ignored-cited-headers
"."
619 "*Delete these headers from the messages you yank."
620 :group
'message-insertion
621 :link
'(custom-manual "(message)Insertion Variables")
624 (defcustom message-cite-prefix-regexp mail-citation-prefix-regexp
625 "*Regexp matching the longest possible citation prefix on a line."
627 :group
'message-insertion
628 :link
'(custom-manual "(message)Insertion Variables")
630 :set
(lambda (symbol value
)
632 (custom-set-default symbol value
)
633 (if (boundp 'gnus-message-cite-prefix-regexp
)
634 (setq gnus-message-cite-prefix-regexp
635 (concat "^\\(?:" value
"\\)"))))))
637 (defcustom message-cancel-message
"I am canceling my own article.\n"
638 "Message to be inserted in the cancel message."
639 :group
'message-interface
640 :link
'(custom-manual "(message)Canceling News")
643 (defun message-send-mail-function ()
644 "Return suitable value for the variable `message-send-mail-function'."
645 (cond ((and (require 'sendmail
)
646 (boundp 'sendmail-program
)
648 (executable-find sendmail-program
))
649 'message-send-mail-with-sendmail
)
650 ((and (locate-library "smtpmail")
651 (boundp 'smtpmail-default-smtp-server
)
652 smtpmail-default-smtp-server
)
653 'message-smtpmail-send-it
)
654 ((locate-library "mailclient")
655 'message-send-mail-with-mailclient
)
657 (error "Don't know how to send mail. Please customize `message-send-mail-function'"))))
659 ;; Useful to set in site-init.el
660 (defcustom message-send-mail-function
661 (cond ((eq send-mail-function
'smtpmail-send-it
) 'message-smtpmail-send-it
)
662 ((eq send-mail-function
'feedmail-send-it
) 'feedmail-send-it
)
663 ((eq send-mail-function
'mailclient-send-it
)
664 'message-send-mail-with-mailclient
)
665 (t (message-send-mail-function)))
666 "Function to call to send the current buffer as mail.
667 The headers should be delimited by a line whose contents match the
668 variable `mail-header-separator'.
670 Valid values include `message-send-mail-with-sendmail'
671 `message-send-mail-with-mh', `message-send-mail-with-qmail',
672 `message-smtpmail-send-it', `smtpmail-send-it',
673 `feedmail-send-it' and `message-send-mail-with-mailclient'. The
674 default is system dependent and determined by the function
675 `message-send-mail-function'.
677 See also `send-mail-function'."
678 :type
'(radio (function-item message-send-mail-with-sendmail
)
679 (function-item message-send-mail-with-mh
)
680 (function-item message-send-mail-with-qmail
)
681 (function-item message-smtpmail-send-it
)
682 (function-item smtpmail-send-it
)
683 (function-item feedmail-send-it
)
684 (function-item message-send-mail-with-mailclient
685 :tag
"Use Mailclient package")
686 (function :tag
"Other"))
687 :group
'message-sending
689 :initialize
'custom-initialize-default
690 :link
'(custom-manual "(message)Mail Variables")
691 :group
'message-mail
)
693 (defcustom message-send-news-function
'message-send-news
694 "Function to call to send the current buffer as news.
695 The headers should be delimited by a line whose contents match the
696 variable `mail-header-separator'."
697 :group
'message-sending
699 :link
'(custom-manual "(message)News Variables")
702 (defcustom message-reply-to-function nil
703 "If non-nil, function that should return a list of headers.
704 This function should pick out addresses from the To, Cc, and From headers
705 and respond with new To and Cc headers."
706 :group
'message-interface
707 :link
'(custom-manual "(message)Reply")
708 :type
'(choice function
(const nil
)))
710 (defcustom message-wide-reply-to-function nil
711 "If non-nil, function that should return a list of headers.
712 This function should pick out addresses from the To, Cc, and From headers
713 and respond with new To and Cc headers."
714 :group
'message-interface
715 :link
'(custom-manual "(message)Wide Reply")
716 :type
'(choice function
(const nil
)))
718 (defcustom message-followup-to-function nil
719 "If non-nil, function that should return a list of headers.
720 This function should pick out addresses from the To, Cc, and From headers
721 and respond with new To and Cc headers."
722 :group
'message-interface
723 :link
'(custom-manual "(message)Followup")
724 :type
'(choice function
(const nil
)))
726 (defcustom message-extra-wide-headers nil
727 "If non-nil, a list of additional address headers.
728 These are used when composing a wide reply."
729 :group
'message-sending
730 :type
'(repeat string
))
732 (defcustom message-use-followup-to
'ask
733 "*Specifies what to do with Followup-To header.
734 If nil, always ignore the header. If it is t, use its value, but
735 query before using the \"poster\" value. If it is the symbol `ask',
736 always query the user whether to use the value. If it is the symbol
737 `use', always use the value."
738 :group
'message-interface
739 :link
'(custom-manual "(message)Followup")
740 :type
'(choice (const :tag
"ignore" nil
)
741 (const :tag
"use & query" t
)
745 (defcustom message-use-mail-followup-to
'use
746 "*Specifies what to do with Mail-Followup-To header.
747 If nil, always ignore the header. If it is the symbol `ask', always
748 query the user whether to use the value. If it is the symbol `use',
749 always use the value."
751 :group
'message-interface
752 :link
'(custom-manual "(message)Mailing Lists")
753 :type
'(choice (const :tag
"ignore" nil
)
757 (defcustom message-subscribed-address-functions nil
758 "*Specifies functions for determining list subscription.
759 If nil, do not attempt to determine list subscription with functions.
760 If non-nil, this variable contains a list of functions which return
761 regular expressions to match lists. These functions can be used in
762 conjunction with `message-subscribed-regexps' and
763 `message-subscribed-addresses'."
765 :group
'message-interface
766 :link
'(custom-manual "(message)Mailing Lists")
767 :type
'(repeat sexp
))
769 (defcustom message-subscribed-address-file nil
770 "*A file containing addresses the user is subscribed to.
771 If nil, do not look at any files to determine list subscriptions. If
772 non-nil, each line of this file should be a mailing list address."
774 :group
'message-interface
775 :link
'(custom-manual "(message)Mailing Lists")
776 :type
'(radio file
(const nil
)))
778 (defcustom message-subscribed-addresses nil
779 "*Specifies a list of addresses the user is subscribed to.
780 If nil, do not use any predefined list subscriptions. This list of
781 addresses can be used in conjunction with
782 `message-subscribed-address-functions' and `message-subscribed-regexps'."
784 :group
'message-interface
785 :link
'(custom-manual "(message)Mailing Lists")
786 :type
'(repeat string
))
788 (defcustom message-subscribed-regexps nil
789 "*Specifies a list of addresses the user is subscribed to.
790 If nil, do not use any predefined list subscriptions. This list of
791 regular expressions can be used in conjunction with
792 `message-subscribed-address-functions' and `message-subscribed-addresses'."
794 :group
'message-interface
795 :link
'(custom-manual "(message)Mailing Lists")
796 :type
'(repeat regexp
))
798 (defcustom message-allow-no-recipients
'ask
799 "Specifies what to do when there are no recipients other than Gcc/Fcc.
800 If it is the symbol `always', the posting is allowed. If it is the
801 symbol `never', the posting is not allowed. If it is the symbol
802 `ask', you are prompted."
804 :group
'message-interface
805 :link
'(custom-manual "(message)Message Headers")
806 :type
'(choice (const always
)
810 (defcustom message-sendmail-f-is-evil nil
811 "*Non-nil means don't add \"-f username\" to the sendmail command line.
812 Doing so would be even more evil than leaving it out."
813 :group
'message-sending
814 :link
'(custom-manual "(message)Mail Variables")
817 (defcustom message-sendmail-envelope-from
818 ;; `mail-envelope-from' is unavailable unless sendmail.el is loaded.
819 (if (boundp 'mail-envelope-from
) mail-envelope-from
)
820 "*Envelope-from when sending mail with sendmail.
821 If this is nil, use `user-mail-address'. If it is the symbol
822 `header', use the From: header of the message."
824 :type
'(choice (string :tag
"From name")
825 (const :tag
"Use From: header from message" header
)
826 (const :tag
"Use `user-mail-address'" nil
))
827 :link
'(custom-manual "(message)Mail Variables")
828 :group
'message-sending
)
830 (defcustom message-sendmail-extra-arguments nil
831 "Additional arguments to `sendmail-program'."
832 ;; E.g. '("-a" "account") for msmtp
833 :version
"23.1" ;; No Gnus
834 :type
'(repeat string
)
835 ;; :link '(custom-manual "(message)Mail Variables")
836 :group
'message-sending
)
838 ;; qmail-related stuff
839 (defcustom message-qmail-inject-program
"/var/qmail/bin/qmail-inject"
840 "Location of the qmail-inject program."
841 :group
'message-sending
842 :link
'(custom-manual "(message)Mail Variables")
845 (defcustom message-qmail-inject-args nil
846 "Arguments passed to qmail-inject programs.
847 This should be a list of strings, one string for each argument.
848 It may also be a function.
850 For e.g., if you wish to set the envelope sender address so that bounces
851 go to the right place or to deal with listserv's usage of that address, you
852 might set this variable to '(\"-f\" \"you@some.where\")."
853 :group
'message-sending
854 :link
'(custom-manual "(message)Mail Variables")
855 :type
'(choice (function)
858 (defvar gnus-post-method
)
859 (defvar gnus-select-method
)
860 (defcustom message-post-method
861 (cond ((and (boundp 'gnus-post-method
)
862 (listp gnus-post-method
)
865 ((boundp 'gnus-select-method
)
868 "*Method used to post news.
869 Note that when posting from inside Gnus, for instance, this
870 variable isn't used."
872 :group
'message-sending
873 ;; This should be the `gnus-select-method' widget, but that might
874 ;; create a dependence to `gnus.el'.
877 ;; FIXME: This should be a temporary workaround until someone implements a
878 ;; proper solution. If a crash happens while replying, the auto-save file
879 ;; will *not* have a `References:' header if `message-generate-headers-first'
880 ;; is nil. See: http://article.gmane.org/gmane.emacs.gnus.general/51138
881 (defcustom message-generate-headers-first
'(references)
882 "Which headers should be generated before starting to compose a message.
883 If t, generate all required headers. This can also be a list of headers to
884 generate. The variables `message-required-news-headers' and
885 `message-required-mail-headers' specify which headers to generate.
887 Note that the variable `message-deletable-headers' specifies headers which
888 are to be deleted and then re-generated before sending, so this variable
889 will not have a visible effect for those headers."
890 :group
'message-headers
891 :link
'(custom-manual "(message)Message Headers")
892 :type
'(choice (const :tag
"None" nil
)
893 (const :tag
"References" '(references))
895 (repeat (sexp :tag
"Header"))))
897 (defcustom message-fill-column
72
898 "Column beyond which automatic line-wrapping should happen.
899 Local value for message buffers. If non-nil, also turn on
900 auto-fill in message buffers."
901 :group
'message-various
902 ;; :link '(custom-manual "(message)Message Headers")
903 :type
'(choice (const :tag
"Don't turn on auto fill" nil
)
906 (defcustom message-setup-hook nil
907 "Normal hook, run each time a new outgoing message is initialized.
908 The function `message-setup' runs this hook."
909 :group
'message-various
910 :link
'(custom-manual "(message)Various Message Variables")
913 (defcustom message-cancel-hook nil
914 "Hook run when cancelling articles."
915 :group
'message-various
916 :link
'(custom-manual "(message)Various Message Variables")
919 (defcustom message-signature-setup-hook nil
920 "Normal hook, run each time a new outgoing message is initialized.
921 It is run after the headers have been inserted and before
922 the signature is inserted."
923 :group
'message-various
924 :link
'(custom-manual "(message)Various Message Variables")
927 (defcustom message-mode-hook nil
928 "Hook run in message mode buffers."
929 :group
'message-various
932 (defcustom message-header-hook nil
933 "Hook run in a message mode buffer narrowed to the headers."
934 :group
'message-various
937 (defcustom message-header-setup-hook nil
938 "Hook called narrowed to the headers when setting up a message buffer."
939 :group
'message-various
940 :link
'(custom-manual "(message)Various Message Variables")
943 (defcustom message-minibuffer-local-map
944 (let ((map (make-sparse-keymap 'message-minibuffer-local-map
)))
945 (set-keymap-parent map minibuffer-local-map
)
947 "Keymap for `message-read-from-minibuffer'."
949 :group
'message-various
)
951 (defcustom message-citation-line-function
'message-insert-citation-line
952 "*Function called to insert the \"Whomever writes:\" line.
954 Predefined functions include `message-insert-citation-line' and
955 `message-insert-formatted-citation-line' (see the variable
956 `message-citation-line-format').
958 Note that Gnus provides a feature where the reader can click on
959 `writes:' to hide the cited text. If you change this line too much,
960 people who read your message will have to change their Gnus
961 configuration. See the variable `gnus-cite-attribution-suffix'."
963 (function-item :tag
"plain" message-insert-citation-line
)
964 (function-item :tag
"formatted" message-insert-formatted-citation-line
)
965 (function :tag
"Other"))
966 :link
'(custom-manual "(message)Insertion Variables")
967 :group
'message-insertion
)
969 (defcustom message-citation-line-format
"On %a, %b %d %Y, %N wrote:\n"
970 "Format of the \"Whomever writes:\" line.
972 The string is formatted using `format-spec'. The following
973 constructs are replaced:
975 %f The full From, e.g. \"John Doe <john.doe@example.invalid>\".
976 %n The mail address, e.g. \"john.doe@example.invalid\".
977 %N The real name if present, e.g.: \"John Doe\", else fall
978 back to the mail address.
979 %F The first name if present, e.g.: \"John\".
980 %L The last name if present, e.g.: \"Doe\".
982 All other format specifiers are passed to `format-time-string'
983 which is called using the date from the article your replying to.
984 Extracting the first (%F) and last name (%L) is done
985 heuristically, so you should always check it yourself.
987 Please also read the note in the documentation of
988 `message-citation-line-function'."
989 :type
'(choice (const :tag
"Plain" "%f writes:")
990 (const :tag
"Include date" "On %a, %b %d %Y, %n wrote:")
992 :link
'(custom-manual "(message)Insertion Variables")
993 :version
"23.1" ;; No Gnus
994 :group
'message-insertion
)
996 (defcustom message-yank-prefix mail-yank-prefix
997 "*Prefix inserted on the lines of yanked messages.
998 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
999 See also `message-yank-cited-prefix' and `message-yank-empty-prefix'."
1002 :link
'(custom-manual "(message)Insertion Variables")
1003 :group
'message-insertion
)
1005 (defcustom message-yank-cited-prefix
">"
1006 "*Prefix inserted on cited lines of yanked messages.
1007 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1008 See also `message-yank-prefix' and `message-yank-empty-prefix'."
1011 :link
'(custom-manual "(message)Insertion Variables")
1012 :group
'message-insertion
)
1014 (defcustom message-yank-empty-prefix
">"
1015 "*Prefix inserted on empty lines of yanked messages.
1016 See also `message-yank-prefix' and `message-yank-cited-prefix'."
1019 :link
'(custom-manual "(message)Insertion Variables")
1020 :group
'message-insertion
)
1022 (defcustom message-indentation-spaces mail-indentation-spaces
1023 "*Number of spaces to insert at the beginning of each cited line.
1024 Used by `message-yank-original' via `message-yank-cite'."
1026 :group
'message-insertion
1027 :link
'(custom-manual "(message)Insertion Variables")
1030 (defcustom message-cite-function
'message-cite-original-without-signature
1031 "*Function for citing an original message.
1032 Predefined functions include `message-cite-original' and
1033 `message-cite-original-without-signature'.
1034 Note that these functions use `mail-citation-hook' if that is non-nil."
1035 :type
'(radio (function-item message-cite-original
)
1036 (function-item message-cite-original-without-signature
)
1037 (function-item sc-cite-original
)
1038 (function :tag
"Other"))
1039 :link
'(custom-manual "(message)Insertion Variables")
1040 :version
"22.3" ;; Gnus 5.10.12 (changed default)
1041 :group
'message-insertion
)
1043 (defcustom message-indent-citation-function
'message-indent-citation
1044 "*Function for modifying a citation just inserted in the mail buffer.
1045 This can also be a list of functions. Each function can find the
1046 citation between (point) and (mark t). And each function should leave
1047 point and mark around the citation text as modified."
1049 :link
'(custom-manual "(message)Insertion Variables")
1050 :group
'message-insertion
)
1052 (defcustom message-signature mail-signature
1053 "*String to be inserted at the end of the message buffer.
1054 If t, the `message-signature-file' file will be inserted instead.
1055 If a function, the result from the function will be used instead.
1056 If a form, the result from the form will be used instead."
1059 :link
'(custom-manual "(message)Insertion Variables")
1060 :group
'message-insertion
)
1062 (defcustom message-signature-file mail-signature-file
1063 "*Name of file containing the text inserted at end of message buffer.
1064 Ignored if the named file doesn't exist.
1065 If nil, don't insert a signature.
1066 If a path is specified, the value of `message-signature-directory' is ignored,
1069 :type
'(choice file
(const :tags
"None" nil
))
1070 :link
'(custom-manual "(message)Insertion Variables")
1071 :group
'message-insertion
)
1073 (defcustom message-signature-directory nil
1074 "*Name of directory containing signature files.
1075 Comes in handy if you have many such files, handled via posting styles for
1077 If nil, `message-signature-file' is expected to specify the directory if
1079 :type
'(choice string
(const :tags
"None" nil
))
1080 :link
'(custom-manual "(message)Insertion Variables")
1081 :group
'message-insertion
)
1083 (defcustom message-signature-insert-empty-line t
1084 "*If non-nil, insert an empty line before the signature separator."
1087 :link
'(custom-manual "(message)Insertion Variables")
1088 :group
'message-insertion
)
1090 (defcustom message-distribution-function nil
1091 "*Function called to return a Distribution header."
1092 :group
'message-news
1093 :group
'message-headers
1094 :link
'(custom-manual "(message)News Headers")
1095 :type
'(choice function
(const nil
)))
1097 (defcustom message-expires
14
1098 "Number of days before your article expires."
1099 :group
'message-news
1100 :group
'message-headers
1101 :link
'(custom-manual "(message)News Headers")
1104 (defcustom message-user-path nil
1105 "If nil, use the NNTP server name in the Path header.
1106 If stringp, use this; if non-nil, use no host name (user name only)."
1107 :group
'message-news
1108 :group
'message-headers
1109 :link
'(custom-manual "(message)News Headers")
1110 :type
'(choice (const :tag
"nntp" nil
)
1111 (string :tag
"name")
1112 (sexp :tag
"none" :format
"%t" t
)))
1114 ;; This can be the name of a buffer, or a cons cell (FUNCTION . ARGS)
1115 ;; for yanking the original buffer.
1116 (defvar message-reply-buffer nil
)
1117 (defvar message-reply-headers nil
1118 "The headers of the current replied article.
1119 It is a vector of the following headers:
1120 \[number subject from date id references chars lines xref extra].")
1121 (defvar message-newsreader nil
)
1122 (defvar message-mailer nil
)
1123 (defvar message-sent-message-via nil
)
1124 (defvar message-checksum nil
)
1125 (defvar message-send-actions nil
1126 "A list of actions to be performed upon successful sending of a message.")
1127 (defvar message-exit-actions nil
1128 "A list of actions to be performed upon exiting after sending a message.")
1129 (defvar message-kill-actions nil
1130 "A list of actions to be performed before killing a message buffer.")
1131 (defvar message-postpone-actions nil
1132 "A list of actions to be performed after postponing a message.")
1134 (define-widget 'message-header-lines
'text
1135 "All header lines must be LFD terminated."
1136 :format
"%{%t%}:%n%v"
1137 :valid-regexp
"^\\'"
1138 :error
"All header lines must be newline terminated")
1140 (defcustom message-default-headers
""
1141 "*A string containing header lines to be inserted in outgoing messages.
1142 It is inserted before you edit the message, so you can edit or delete
1145 :group
'message-headers
1146 :link
'(custom-manual "(message)Message Headers")
1147 :type
'message-header-lines
)
1149 (defcustom message-default-mail-headers
1150 ;; Ease the transition from mail-mode to message-mode. See bugs#4431, 5555.
1151 (concat (if (and (boundp 'mail-default-reply-to
)
1152 (stringp mail-default-reply-to
))
1153 (format "Reply-to: %s\n" mail-default-reply-to
))
1154 (if (and (boundp 'mail-self-blind
)
1156 (format "BCC: %s\n" user-mail-address
))
1157 (if (and (boundp 'mail-archive-file-name
)
1158 (stringp mail-archive-file-name
))
1159 (format "FCC: %s\n" mail-archive-file-name
))
1160 ;; Use the value of `mail-default-headers' if available.
1161 ;; Note: as for XEmacs 21.4 and 21.5, it is unavailable
1162 ;; unless sendmail.el is loaded.
1163 (if (boundp 'mail-default-headers
)
1164 mail-default-headers
))
1165 "*A string of header lines to be inserted in outgoing mails."
1167 :group
'message-headers
1168 :group
'message-mail
1169 :link
'(custom-manual "(message)Mail Headers")
1170 :type
'message-header-lines
)
1172 (defcustom message-default-news-headers
""
1173 "*A string of header lines to be inserted in outgoing news articles."
1174 :group
'message-headers
1175 :group
'message-news
1176 :link
'(custom-manual "(message)News Headers")
1177 :type
'message-header-lines
)
1179 ;; Note: could use /usr/ucb/mail instead of sendmail;
1180 ;; options -t, and -v if not interactive.
1181 (defcustom message-mailer-swallows-blank-line
1182 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1183 system-configuration
)
1184 (file-readable-p "/etc/sendmail.cf")
1185 (let ((buffer (get-buffer-create " *temp*")))
1187 (with-current-buffer buffer
1188 (insert-file-contents "/etc/sendmail.cf")
1189 (goto-char (point-min))
1190 (let ((case-fold-search nil
))
1191 (re-search-forward "^OR\\>" nil t
)))
1192 (kill-buffer buffer
))))
1193 ;; According to RFC822, "The field-name must be composed of printable
1194 ;; ASCII characters (i. e., characters that have decimal values between
1195 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1197 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1198 "*Set this non-nil if the system's mailer runs the header and body together.
1199 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1200 The value should be an expression to test whether the problem will
1202 :group
'message-sending
1203 :link
'(custom-manual "(message)Mail Variables")
1207 (define-mail-user-agent 'message-user-agent
1208 'message-mail
'message-send-and-exit
1209 'message-kill-buffer
'message-send-hook
)
1211 (defvar message-mh-deletable-headers
'(Message-ID Date Lines Sender
)
1212 "If non-nil, delete the deletable headers before feeding to mh.")
1214 (defvar message-send-method-alist
1215 '((news message-news-p message-send-via-news
)
1216 (mail message-mail-p message-send-via-mail
))
1217 "Alist of ways to send outgoing messages.
1218 Each element has the form
1220 \(TYPE PREDICATE FUNCTION)
1222 where TYPE is a symbol that names the method; PREDICATE is a function
1223 called without any parameters to determine whether the message is
1224 a message of type TYPE; and FUNCTION is a function to be called if
1225 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1228 (defcustom message-mail-alias-type
'abbrev
1229 "*What alias expansion type to use in Message buffers.
1230 The default is `abbrev', which uses mailabbrev. `ecomplete' uses
1231 an electric completion mode. nil switches mail aliases off.
1232 This can also be a list of values."
1234 :link
'(custom-manual "(message)Mail Aliases")
1235 :type
'(choice (const :tag
"Use Mailabbrev" abbrev
)
1236 (const :tag
"Use ecomplete" ecomplete
)
1237 (const :tag
"No expansion" nil
)))
1239 (defcustom message-self-insert-commands
'(self-insert-command)
1240 "List of `self-insert-command's used to trigger ecomplete.
1241 When one of those commands is invoked to enter a character in To or Cc
1242 header, ecomplete will suggest the candidates of recipients (see also
1243 `message-mail-alias-type'). If you use some tool to enter non-ASCII
1244 text and it replaces `self-insert-command' with the other command, e.g.
1245 `egg-self-insert-command', you may want to add it to this list."
1246 :group
'message-various
1247 :type
'(repeat function
))
1249 (defcustom message-auto-save-directory
1250 (file-name-as-directory (expand-file-name "drafts" message-directory
))
1251 "*Directory where Message auto-saves buffers if Gnus isn't running.
1252 If nil, Message won't auto-save."
1253 :group
'message-buffers
1254 :link
'(custom-manual "(message)Various Message Variables")
1255 :type
'(choice directory
(const :tag
"Don't auto-save" nil
)))
1257 (defcustom message-default-charset
1258 (and (not (mm-multibyte-p)) 'iso-8859-1
)
1259 "Default charset used in non-MULE Emacsen.
1260 If nil, you might be asked to input the charset."
1263 :link
'(custom-manual "(message)Various Message Variables")
1266 (defcustom message-dont-reply-to-names
1267 (and (boundp 'rmail-dont-reply-to-names
) rmail-dont-reply-to-names
)
1268 "*Addresses to prune when doing wide replies.
1269 This can be a regexp or a list of regexps. Also, a value of nil means
1270 exclude your own user name only."
1273 :link
'(custom-manual "(message)Wide Reply")
1274 :type
'(choice (const :tag
"Yourself" nil
)
1276 (repeat :tag
"Regexp List" regexp
)))
1278 (defsubst message-dont-reply-to-names
()
1279 (gmm-regexp-concat message-dont-reply-to-names
))
1281 (defvar message-shoot-gnksa-feet nil
1282 "*A list of GNKSA feet you are allowed to shoot.
1283 Gnus gives you all the opportunity you could possibly want for
1284 shooting yourself in the foot. Also, Gnus allows you to shoot the
1285 feet of Good Net-Keeping Seal of Approval. The following are foot
1287 `empty-article' Allow you to post an empty article;
1288 `quoted-text-only' Allow you to post quoted text only;
1289 `multiple-copies' Allow you to post multiple copies;
1290 `cancel-messages' Allow you to cancel or supersede messages from
1291 your other email addresses.")
1293 (defsubst message-gnksa-enable-p
(feature)
1294 (or (not (listp message-shoot-gnksa-feet
))
1295 (memq feature message-shoot-gnksa-feet
)))
1297 (defcustom message-hidden-headers
'("^References:" "^Face:" "^X-Face:"
1299 "Regexp of headers to be hidden when composing new messages.
1300 This can also be a list of regexps to match headers. Or a list
1301 starting with `not' and followed by regexps."
1304 :link
'(custom-manual "(message)Message Headers")
1306 :format
"%{%t%}: %[Value Type%] %v"
1307 (regexp :menu-tag
"regexp" :format
"regexp\n%t: %v")
1308 (repeat :menu-tag
"(regexp ...)" :format
"(regexp ...)\n%v%i"
1309 (regexp :format
"%t: %v"))
1310 (cons :menu-tag
"(not regexp ...)" :format
"(not regexp ...)\n%v"
1312 (repeat :format
"%v%i"
1313 (regexp :format
"%t: %v")))))
1315 (defcustom message-cite-articles-with-x-no-archive t
1316 "If non-nil, cite text from articles that has X-No-Archive set."
1320 ;;; Internal variables.
1321 ;;; Well, not really internal.
1323 (defvar message-mode-syntax-table
1324 (let ((table (copy-syntax-table text-mode-syntax-table
)))
1325 (modify-syntax-entry ?%
". " table
)
1326 (modify-syntax-entry ?
> ". " table
)
1327 (modify-syntax-entry ?
< ". " table
)
1329 "Syntax table used while in Message mode.")
1331 (defface message-header-to
1334 (:foreground
"DarkOliveGreen1" :bold t
))
1337 (:foreground
"MidnightBlue" :bold t
))
1339 (:bold t
:italic t
)))
1340 "Face used for displaying From headers."
1341 :group
'message-faces
)
1342 ;; backward-compatibility alias
1343 (put 'message-header-to-face
'face-alias
'message-header-to
)
1344 (put 'message-header-to-face
'obsolete-face
"22.1")
1346 (defface message-header-cc
1349 (:foreground
"chartreuse1" :bold t
))
1352 (:foreground
"MidnightBlue"))
1355 "Face used for displaying Cc headers."
1356 :group
'message-faces
)
1357 ;; backward-compatibility alias
1358 (put 'message-header-cc-face
'face-alias
'message-header-cc
)
1359 (put 'message-header-cc-face
'obsolete-face
"22.1")
1361 (defface message-header-subject
1364 (:foreground
"OliveDrab1"))
1367 (:foreground
"navy blue" :bold t
))
1370 "Face used for displaying subject headers."
1371 :group
'message-faces
)
1372 ;; backward-compatibility alias
1373 (put 'message-header-subject-face
'face-alias
'message-header-subject
)
1374 (put 'message-header-subject-face
'obsolete-face
"22.1")
1376 (defface message-header-newsgroups
1379 (:foreground
"yellow" :bold t
:italic t
))
1382 (:foreground
"blue4" :bold t
:italic t
))
1384 (:bold t
:italic t
)))
1385 "Face used for displaying newsgroups headers."
1386 :group
'message-faces
)
1387 ;; backward-compatibility alias
1388 (put 'message-header-newsgroups-face
'face-alias
'message-header-newsgroups
)
1389 (put 'message-header-newsgroups-face
'obsolete-face
"22.1")
1391 (defface message-header-other
1394 (:foreground
"VioletRed1"))
1397 (:foreground
"steel blue"))
1399 (:bold t
:italic t
)))
1400 "Face used for displaying newsgroups headers."
1401 :group
'message-faces
)
1402 ;; backward-compatibility alias
1403 (put 'message-header-other-face
'face-alias
'message-header-other
)
1404 (put 'message-header-other-face
'obsolete-face
"22.1")
1406 (defface message-header-name
1409 (:foreground
"green"))
1412 (:foreground
"cornflower blue"))
1415 "Face used for displaying header names."
1416 :group
'message-faces
)
1417 ;; backward-compatibility alias
1418 (put 'message-header-name-face
'face-alias
'message-header-name
)
1419 (put 'message-header-name-face
'obsolete-face
"22.1")
1421 (defface message-header-xheader
1424 (:foreground
"DeepSkyBlue1"))
1427 (:foreground
"blue"))
1430 "Face used for displaying X-Header headers."
1431 :group
'message-faces
)
1432 ;; backward-compatibility alias
1433 (put 'message-header-xheader-face
'face-alias
'message-header-xheader
)
1434 (put 'message-header-xheader-face
'obsolete-face
"22.1")
1436 (defface message-separator
1439 (:foreground
"LightSkyBlue1"))
1442 (:foreground
"brown"))
1445 "Face used for displaying the separator."
1446 :group
'message-faces
)
1447 ;; backward-compatibility alias
1448 (put 'message-separator-face
'face-alias
'message-separator
)
1449 (put 'message-separator-face
'obsolete-face
"22.1")
1451 (defface message-cited-text
1454 (:foreground
"LightPink1"))
1457 (:foreground
"red"))
1460 "Face used for displaying cited text names."
1461 :group
'message-faces
)
1462 ;; backward-compatibility alias
1463 (put 'message-cited-text-face
'face-alias
'message-cited-text
)
1464 (put 'message-cited-text-face
'obsolete-face
"22.1")
1466 (defface message-mml
1469 (:foreground
"MediumSpringGreen"))
1472 (:foreground
"ForestGreen"))
1475 "Face used for displaying MML."
1476 :group
'message-faces
)
1477 ;; backward-compatibility alias
1478 (put 'message-mml-face
'face-alias
'message-mml
)
1479 (put 'message-mml-face
'obsolete-face
"22.1")
1481 (defun message-font-lock-make-header-matcher (regexp)
1484 (let ((start (point)))
1487 (goto-char (point-min))
1488 (if (re-search-forward
1489 (concat "^" (regexp-quote mail-header-separator
) "$")
1491 (setq limit
(min limit
(match-beginning 0))))
1493 (and (< start limit
)
1494 (re-search-forward ,regexp limit t
))))))
1495 (if (featurep 'bytecomp
)
1499 (defvar message-font-lock-keywords
1500 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1501 `((,(message-font-lock-make-header-matcher
1502 (concat "^\\([Tt]o:\\)" content
))
1503 (1 'message-header-name
)
1504 (2 'message-header-to nil t
))
1505 (,(message-font-lock-make-header-matcher
1506 (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content
))
1507 (1 'message-header-name
)
1508 (2 'message-header-cc nil t
))
1509 (,(message-font-lock-make-header-matcher
1510 (concat "^\\([Ss]ubject:\\)" content
))
1511 (1 'message-header-name
)
1512 (2 'message-header-subject nil t
))
1513 (,(message-font-lock-make-header-matcher
1514 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content
))
1515 (1 'message-header-name
)
1516 (2 'message-header-newsgroups nil t
))
1517 (,(message-font-lock-make-header-matcher
1518 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content
))
1519 (1 'message-header-name
)
1520 (2 'message-header-xheader
))
1521 (,(message-font-lock-make-header-matcher
1522 (concat "^\\([A-Z][^: \n\t]+:\\)" content
))
1523 (1 'message-header-name
)
1524 (2 'message-header-other nil t
))
1525 ,@(if (and mail-header-separator
1526 (not (equal mail-header-separator
"")))
1527 `((,(concat "^\\(" (regexp-quote mail-header-separator
) "\\)$")
1528 1 'message-separator
))
1531 (re-search-forward (concat "^\\("
1532 message-cite-prefix-regexp
1535 (0 'message-cited-text
))
1536 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1538 "Additional expressions to highlight in Message mode.")
1541 ;; XEmacs does it like this. For Emacs, we have to set the
1542 ;; `font-lock-defaults' buffer-local variable.
1543 (put 'message-mode
'font-lock-defaults
'(message-font-lock-keywords t
))
1545 (defvar message-face-alist
1546 '((bold . message-bold-region
)
1547 (underline . underline-region
)
1548 (default .
(lambda (b e
)
1549 (message-unbold-region b e
)
1550 (ununderline-region b e
))))
1551 "Alist of mail and news faces for facemenu.
1552 The cdr of each entry is a function for applying the face to a region.")
1554 (defcustom message-send-hook nil
1555 "Hook run before sending messages.
1556 This hook is run quite early when sending."
1557 :group
'message-various
1558 :options
'(ispell-message)
1559 :link
'(custom-manual "(message)Various Message Variables")
1562 (defcustom message-send-mail-hook nil
1563 "Hook run before sending mail messages.
1564 This hook is run very late -- just before the message is sent as
1566 :group
'message-various
1567 :link
'(custom-manual "(message)Various Message Variables")
1570 (defcustom message-send-news-hook nil
1571 "Hook run before sending news messages.
1572 This hook is run very late -- just before the message is sent as
1574 :group
'message-various
1575 :link
'(custom-manual "(message)Various Message Variables")
1578 (defcustom message-sent-hook nil
1579 "Hook run after sending messages."
1580 :group
'message-various
1583 (defvar message-send-coding-system
'binary
1584 "Coding system to encode outgoing mail.")
1586 (defvar message-draft-coding-system
1587 mm-auto-save-coding-system
1588 "*Coding system to compose mail.
1589 If you'd like to make it possible to share draft files between XEmacs
1590 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1591 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1593 (defcustom message-send-mail-partially-limit nil
1594 "The limitation of messages sent as message/partial.
1595 The lower bound of message size in characters, beyond which the message
1596 should be sent in several parts. If it is nil, the size is unlimited."
1598 :group
'message-buffers
1599 :link
'(custom-manual "(message)Mail Variables")
1600 :type
'(choice (const :tag
"unlimited" nil
)
1603 (defcustom message-alternative-emails nil
1604 "*Regexp matching alternative email addresses.
1605 The first address in the To, Cc or From headers of the original
1606 article matching this variable is used as the From field of
1609 This variable has precedence over posting styles and anything that runs
1610 off `message-setup-hook'."
1611 :group
'message-headers
1612 :link
'(custom-manual "(message)Message Headers")
1613 :type
'(choice (const :tag
"Always use primary" nil
)
1616 (defcustom message-hierarchical-addresses nil
1617 "A list of hierarchical mail address definitions.
1619 Inside each entry, the first address is the \"top\" address, and
1620 subsequent addresses are subaddresses; this is used to indicate that
1621 mail sent to the first address will automatically be delivered to the
1622 subaddresses. So if the first address appears in the recipient list
1623 for a message, the subaddresses will be removed (if present) before
1624 the mail is sent. All addresses in this structure should be
1627 :group
'message-headers
1628 :type
'(repeat (repeat string
)))
1630 (defcustom message-mail-user-agent nil
1631 "Like `mail-user-agent'.
1632 Except if it is nil, use Gnus native MUA; if it is t, use
1635 :type
'(radio (const :tag
"Gnus native"
1638 (const :tag
"`mail-user-agent'"
1641 (function-item :tag
"Default Emacs mail"
1643 sendmail-user-agent
)
1644 (function-item :tag
"Emacs interface to MH"
1647 (function :tag
"Other"))
1651 (defcustom message-wide-reply-confirm-recipients nil
1652 "Whether to confirm a wide reply to multiple email recipients.
1653 If this variable is nil, don't ask whether to reply to all recipients.
1654 If this variable is non-nil, pose the question \"Reply to all
1655 recipients?\" before a wide reply to multiple recipients. If the user
1656 answers yes, reply to all recipients as usual. If the user answers
1657 no, only reply back to the author."
1659 :group
'message-headers
1660 :link
'(custom-manual "(message)Wide Reply")
1663 (defcustom message-user-fqdn nil
1664 "*Domain part of Message-Ids."
1666 :group
'message-headers
1667 :link
'(custom-manual "(message)News Headers")
1668 :type
'(radio (const :format
"%v " nil
)
1669 (string :format
"FQDN: %v")))
1671 (defcustom message-use-idna
(and (condition-case nil
(require 'idna
)
1673 (mm-coding-system-p 'utf-8
)
1674 (executable-find idna-program
)
1675 (string= (idna-to-ascii "räksmörgås")
1676 "xn--rksmrgs-5wao1o")
1678 "Whether to encode non-ASCII in domain names into ASCII according to IDNA.
1679 GNU Libidn, and in particular the elisp package \"idna.el\" and
1680 the external program \"idn\", must be installed for this
1681 functionality to work."
1683 :group
'message-headers
1684 :link
'(custom-manual "(message)IDNA")
1685 :type
'(choice (const :tag
"Ask" ask
)
1686 (const :tag
"Never" nil
)
1687 (const :tag
"Always" t
)))
1689 (defcustom message-generate-hashcash
(if (executable-find "hashcash") 'opportunistic
)
1690 "*Whether to generate X-Hashcash: headers.
1691 If t, always generate hashcash headers. If `opportunistic',
1692 only generate hashcash headers if it can be done without the user
1693 waiting (i.e., only asynchronously).
1695 You must have the \"hashcash\" binary installed, see `hashcash-path'."
1697 :group
'message-headers
1698 :link
'(custom-manual "(message)Mail Headers")
1699 :type
'(choice (const :tag
"Always" t
)
1700 (const :tag
"Never" nil
)
1701 (const :tag
"Opportunistic" opportunistic
)))
1703 ;;; Internal variables.
1705 (defvar message-sending-message
"Sending...")
1706 (defvar message-buffer-list nil
)
1707 (defvar message-this-is-news nil
)
1708 (defvar message-this-is-mail nil
)
1709 (defvar message-draft-article nil
)
1710 (defvar message-mime-part nil
)
1711 (defvar message-posting-charset nil
)
1712 (defvar message-inserted-headers nil
)
1713 (defvar message-inhibit-ecomplete nil
)
1715 ;; Byte-compiler warning
1716 (defvar gnus-active-hashtb
)
1717 (defvar gnus-read-active-file
)
1719 ;;; Regexp matching the delimiter of messages in UNIX mail format
1720 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1721 ;;; of rmail.el's rmail-unix-mail-delimiter.
1722 (defvar message-unix-mail-delimiter
1723 (let ((time-zone-regexp
1724 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1725 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1731 ;; Many things can happen to an RFC 822 mailbox before it is put into
1732 ;; a `From' line. The leading phrase can be stripped, e.g.
1733 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1734 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1735 ;; can be removed, e.g.
1736 ;; From: joe@y.z (Joe K
1738 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1741 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1742 ;; The mailbox can be removed or be replaced by white space, e.g.
1743 ;; From: "Joe User"{space}{tab}
1745 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1746 ;; where {space} and {tab} represent the Ascii space and tab characters.
1747 ;; We want to match the results of any of these manglings.
1748 ;; The following regexp rejects names whose first characters are
1749 ;; obviously bogus, but after that anything goes.
1750 "\\([^\0-\b\n-\r\^?].*\\)?"
1752 ;; The time the message was sent.
1753 "\\([^\0-\r \^?]+\\) +" ; day of the week
1754 "\\([^\0-\r \^?]+\\) +" ; month
1755 "\\([0-3]?[0-9]\\) +" ; day of month
1756 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1758 ;; Perhaps a time zone, specified by an abbreviation, or by a
1763 " \\([0-9][0-9]+\\) *"
1765 ;; On some systems the time zone can appear after the year, too.
1769 "\\(remote from .*\\)?"
1772 "Regexp matching the delimiter of messages in UNIX mail format.")
1774 (defvar message-unsent-separator
1775 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1776 "^ *---+ +Returned message +---+ *$\\|"
1777 "^Start of returned message$\\|"
1778 "^ *---+ +Original message +---+ *$\\|"
1779 "^ *--+ +begin message +--+ *$\\|"
1780 "^ *---+ +Original message follows +---+ *$\\|"
1781 "^ *---+ +Undelivered message follows +---+ *$\\|"
1782 "^------ This is a copy of the message, including all the headers. ------ *$\\|"
1783 "^|? *---+ +Message text follows: +---+ *|?$")
1784 "A regexp that matches the separator before the text of a failed message.")
1786 (defvar message-field-fillers
1787 '((To message-fill-field-address
)
1788 (Cc message-fill-field-address
)
1789 (From message-fill-field-address
))
1790 "Alist of header names/filler functions.")
1792 (defvar message-header-format-alist
1807 (References . message-shorten-references
)
1809 "Alist used for formatting headers.")
1811 (defvar message-options nil
1812 "Some saved answers when sending message.")
1814 (defvar message-send-mail-real-function nil
1815 "Internal send mail function.")
1817 (defvar message-bogus-system-names
"^localhost\\.\\|\\.local$"
1818 "The regexp of bogus system names.")
1820 (defcustom message-valid-fqdn-regexp
1821 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1823 "\\([a-z][a-z]\\|" ;; two letter country TDLs
1824 "aero\\|arpa\\|bitnet\\|biz\\|bofh\\|"
1825 "cat\\|com\\|coop\\|edu\\|gov\\|"
1826 "info\\|int\\|jobs\\|"
1827 "mil\\|mobi\\|museum\\|name\\|net\\|"
1828 "org\\|pro\\|travel\\|uucp\\)")
1829 ;; http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains
1830 ;; http://en.wikipedia.org/wiki/GTLD
1831 ;; `in the process of being approved': .asia .post .tel .sex
1832 ;; "dead" nato bitnet uucp
1833 "Regular expression that matches a valid FQDN."
1834 ;; see also: gnus-button-valid-fqdn-regexp
1836 :group
'message-headers
1839 (autoload 'gnus-alive-p
"gnus-util")
1840 (autoload 'gnus-delay-article
"gnus-delay")
1841 (autoload 'gnus-extract-address-components
"gnus-util")
1842 (autoload 'gnus-find-method-for-group
"gnus")
1843 (autoload 'gnus-group-decoded-name
"gnus-group")
1844 (autoload 'gnus-group-name-charset
"gnus-group")
1845 (autoload 'gnus-group-name-decode
"gnus-group")
1846 (autoload 'gnus-groups-from-server
"gnus")
1847 (autoload 'gnus-make-local-hook
"gnus-util")
1848 (autoload 'gnus-open-server
"gnus-int")
1849 (autoload 'gnus-output-to-mail
"gnus-util")
1850 (autoload 'gnus-output-to-rmail
"gnus-util")
1851 (autoload 'gnus-request-post
"gnus-int")
1852 (autoload 'gnus-select-frame-set-input-focus
"gnus-util")
1853 (autoload 'gnus-server-string
"gnus")
1854 (autoload 'idna-to-ascii
"idna")
1855 (autoload 'message-setup-toolbar
"messagexmas")
1856 (autoload 'mh-new-draft-name
"mh-comp")
1857 (autoload 'mh-send-letter
"mh-comp")
1858 (autoload 'nndraft-request-associate-buffer
"nndraft")
1859 (autoload 'nndraft-request-expire-articles
"nndraft")
1860 (autoload 'nnvirtual-find-group-art
"nnvirtual")
1861 (autoload 'rmail-dont-reply-to
"mail-utils")
1862 (autoload 'rmail-msg-is-pruned
"rmail")
1863 (autoload 'rmail-output
"rmailout")
1868 ;;; Utility functions.
1871 (defmacro message-y-or-n-p
(question show
&rest text
)
1872 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1873 `(message-talkative-question 'y-or-n-p
,question
,show
,@text
))
1875 (defmacro message-delete-line
(&optional n
)
1876 "Delete the current line (and the next N lines)."
1877 `(delete-region (progn (beginning-of-line) (point))
1878 (progn (forward-line ,(or n
1)) (point))))
1880 (defun message-mark-active-p ()
1881 "Non-nil means the mark and region are currently active in this buffer."
1884 (defun message-unquote-tokens (elems)
1885 "Remove double quotes (\") from strings in list ELEMS."
1886 (mapcar (lambda (item)
1887 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item
)
1888 (setq item
(concat (match-string 1 item
)
1889 (match-string 2 item
))))
1893 (defun message-tokenize-header (header &optional separator
)
1894 "Split HEADER into a list of header elements.
1895 SEPARATOR is a string of characters to be used as separators. \",\"
1896 is used by default."
1899 (let ((regexp (format "[%s]+" (or separator
",")))
1901 beg quoted elems paren
)
1903 (mm-enable-multibyte)
1904 (setq beg
(point-min))
1906 (goto-char (point-min))
1911 (cond ((and (> (point) beg
)
1913 (and (looking-at regexp
)
1916 (push (buffer-substring beg
(point)) elems
)
1917 (setq beg
(match-end 0)))
1918 ((eq (char-after) ?
\")
1919 (setq quoted
(not quoted
)))
1920 ((and (eq (char-after) ?\
()
1923 ((and (eq (char-after) ?\
))
1926 (nreverse elems
)))))
1928 (autoload 'nnheader-insert-file-contents
"nnheader")
1930 (defun message-mail-file-mbox-p (file)
1931 "Say whether FILE looks like a Unix mbox file."
1932 (when (and (file-exists-p file
)
1933 (file-readable-p file
)
1934 (file-regular-p file
))
1936 (nnheader-insert-file-contents file
)
1937 (goto-char (point-min))
1938 (looking-at message-unix-mail-delimiter
))))
1940 (defun message-fetch-field (header &optional not-all
)
1941 "The same as `mail-fetch-field', only remove all newlines.
1942 The buffer is expected to be narrowed to just the header of the message;
1943 see `message-narrow-to-headers-or-head'."
1944 (let* ((inhibit-point-motion-hooks t
)
1945 (value (mail-fetch-field header nil
(not not-all
))))
1947 (while (string-match "\n[\t ]+" value
)
1948 (setq value
(replace-match " " t t value
)))
1951 (defun message-field-value (header &optional not-all
)
1952 "The same as `message-fetch-field', only narrow to the headers first."
1955 (message-narrow-to-headers-or-head)
1956 (message-fetch-field header not-all
))))
1958 (defun message-narrow-to-field ()
1959 "Narrow the buffer to the header on the current line."
1961 (while (looking-at "[ \t]")
1967 (if (re-search-forward "^[^ \n\t]" nil t
)
1970 (goto-char (point-min)))
1972 (defun message-add-header (&rest headers
)
1973 "Add the HEADERS to the message header, skipping those already present."
1976 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers
))
1977 (error "Invalid header `%s'" (car headers
)))
1978 (setq hclean
(match-string 1 (car headers
)))
1980 (message-narrow-to-headers)
1981 (unless (re-search-forward (concat "^" (regexp-quote hclean
) ":") nil t
)
1982 (goto-char (point-max))
1983 (if (string-match "\n$" (car headers
))
1984 (insert (car headers
))
1985 (insert (car headers
) ?
\n)))))
1986 (setq headers
(cdr headers
))))
1988 (defmacro message-with-reply-buffer
(&rest forms
)
1989 "Evaluate FORMS in the reply buffer, if it exists."
1990 `(when (and (bufferp message-reply-buffer
)
1991 (buffer-name message-reply-buffer
))
1992 (with-current-buffer message-reply-buffer
1995 (put 'message-with-reply-buffer
'lisp-indent-function
0)
1996 (put 'message-with-reply-buffer
'edebug-form-spec
'(body))
1998 (defun message-fetch-reply-field (header)
1999 "Fetch field HEADER from the message we're replying to."
2000 (message-with-reply-buffer
2002 (mail-narrow-to-head)
2003 (message-fetch-field header
))))
2005 (defun message-strip-list-identifiers (subject)
2006 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
2007 (require 'gnus-sum
) ; for gnus-list-identifiers
2008 (let ((regexp (if (stringp gnus-list-identifiers
)
2009 gnus-list-identifiers
2010 (mapconcat 'identity gnus-list-identifiers
" *\\|"))))
2011 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
2012 " *\\)\\)+\\(Re: +\\)?\\)") subject
)
2013 (concat (substring subject
0 (match-beginning 1))
2014 (or (match-string 3 subject
)
2015 (match-string 5 subject
))
2020 (defun message-strip-subject-re (subject)
2021 "Remove \"Re:\" from subject lines in string SUBJECT."
2022 (if (string-match message-subject-re-regexp subject
)
2023 (substring subject
(match-end 0))
2026 (defcustom message-replacement-char
"."
2027 "Replacement character used instead of unprintable or not decodable chars."
2028 :group
'message-various
2029 :version
"22.1" ;; Gnus 5.10.9
2030 :type
'(choice string
2034 ;; FIXME: We also should call `message-strip-subject-encoded-words'
2035 ;; when forwarding. Probably in `message-make-forward-subject' and
2036 ;; `message-forward-make-body'.
2038 (defun message-strip-subject-encoded-words (subject)
2039 "Fix non-decodable words in SUBJECT."
2040 ;; Cf. `gnus-simplify-subject-fully'.
2041 (let* ((case-fold-search t
)
2042 (replacement-chars (format "[%s%s%s]"
2043 message-replacement-char
2044 message-replacement-char
2045 message-replacement-char
))
2046 (enc-word-re "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?\\([^?]+\\)\\(\\?=\\)")
2051 (goto-char (point-min))
2052 (when (re-search-forward enc-word-re nil t
)
2053 (setq cs-string
(match-string 1)))))
2054 cs-coding q-or-b word-beg word-end
)
2055 (if (or (not have-marker
) ;; No encoded word found...
2056 ;; ... or double encoding was correct:
2057 (and (stringp cs-string
)
2058 (setq cs-string
(downcase cs-string
))
2059 (mm-coding-system-p (intern cs-string
))
2063 Decoded Subject \"%s\"
2064 contains a valid encoded word. Decode again? "
2066 (setq cs-coding
(intern cs-string
))))))
2070 (goto-char (point-min))
2071 (while (re-search-forward enc-word-re nil t
)
2072 (setq cs-string
(downcase (match-string 1))
2073 q-or-b
(match-string 2)
2074 word-beg
(match-beginning 0)
2075 word-end
(match-end 0))
2077 (if (mm-coding-system-p (intern cs-string
))
2078 (setq cs-coding
(intern cs-string
))
2080 ;; No double encoded subject? => bogus charset.
2083 (mm-read-coding-system
2085 Decoded Subject \"%s\"
2086 contains an encoded word. The charset `%s' is unknown or invalid.
2087 Hit RET to replace non-decodable characters with \"%s\" or enter replacement
2089 subject cs-string message-replacement-char
)))
2091 (replace-match (concat "=?" (symbol-name cs-coding
)
2094 (goto-char word-beg
)
2095 (re-search-forward "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?" word-end t
)
2098 (if (string-match "\\`Q\\'" q-or-b
)
2101 (message "Replacing non-decodable characters with \"%s\"."
2102 message-replacement-char
)
2103 (while (re-search-forward "\\(=[A-F0-9][A-F0-9]\\)+"
2105 (replace-match message-replacement-char
)))
2107 (message "Replacing non-decodable characters with \"%s\"."
2109 (re-search-forward "[^?]+" word-end t
)
2110 (replace-match replacement-chars
))
2111 (re-search-forward "\\?=")
2112 (replace-match "")))))
2113 (rfc2047-decode-region (point-min) (point-max))
2116 ;;; Start of functions adopted from `message-utils.el'.
2118 (defun message-strip-subject-trailing-was (subject)
2119 "Remove trailing \"(was: <old subject>)\" from SUBJECT lines.
2120 Leading \"Re: \" is not stripped by this function. Use the function
2121 `message-strip-subject-re' for this."
2122 (let* ((query message-subject-trailing-was-query
)
2127 message-subject-trailing-was-ask-regexp
2128 message-subject-trailing-was-regexp
)
2131 (setq new
(substring subject
0 (match-beginning 0))))
2132 (if (or (not found
) (eq query nil
))
2135 (if (message-y-or-n-p
2136 "Strip `(was: <old subject>)' in subject? " t
2138 "Strip `(was: <old subject>)' in subject "
2139 "and use the new one instead?\n\n"
2140 "Current subject is: \""
2142 "New subject would be: \""
2144 "See the variable `message-subject-trailing-was-query' "
2145 "to get rid of this query."
2150 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
2152 (defun message-change-subject (new-subject)
2153 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
2154 ;; <URL:http://www.landfield.com/usefor/drafts/draft-ietf-usefor-useage--1.02.unpaged>
2157 (read-from-minibuffer "New subject: ")))
2158 (cond ((and (not (or (null new-subject
) ; new subject not empty
2159 (zerop (string-width new-subject
))
2160 (string-match "^[ \t]*$" new-subject
))))
2164 (message-narrow-to-headers)
2165 (message-fetch-field "Subject"))))
2166 (cond ((not old-subject
)
2167 (error "No current subject"))
2170 (regexp-quote new-subject
)
2172 old-subject
)) ; yes, it really is a new subject
2173 ;; delete eventual Re: prefix
2175 (message-strip-subject-re old-subject
))
2176 (message-goto-subject)
2177 (message-delete-line)
2178 (insert (concat "Subject: "
2181 old-subject
")\n")))))))))
2183 (defun message-mark-inserted-region (beg end
&optional verbatim
)
2184 "Mark some region in the current article with enclosing tags.
2185 See `message-mark-insert-begin' and `message-mark-insert-end'.
2186 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2187 (interactive "r\nP")
2189 ;; add to the end of the region first, otherwise end would be invalid
2191 (insert (if verbatim
"#v-\n" message-mark-insert-end
))
2193 (insert (if verbatim
"#v+\n" message-mark-insert-begin
))))
2195 (defun message-mark-insert-file (file &optional verbatim
)
2196 "Insert FILE at point, marking it with enclosing tags.
2197 See `message-mark-insert-begin' and `message-mark-insert-end'.
2198 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2199 (interactive "fFile to insert: \nP")
2200 ;; reverse insertion to get correct result.
2202 (insert (if verbatim
"#v-\n" message-mark-insert-end
))
2204 (insert-file-contents file
)
2206 (insert (if verbatim
"#v+\n" message-mark-insert-begin
))))
2208 (defun message-add-archive-header ()
2209 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
2210 The note can be customized using `message-archive-note'. When called with a
2211 prefix argument, ask for a text to insert. If you don't want the note in the
2212 body, set `message-archive-note' to nil."
2214 (if current-prefix-arg
2215 (setq message-archive-note
2216 (read-from-minibuffer "Reason for No-Archive: "
2217 (cons message-archive-note
0))))
2219 (if (message-goto-signature)
2220 (re-search-backward message-signature-separator
))
2221 (when message-archive-note
2222 (insert message-archive-note
)
2224 (message-add-header message-archive-header
)
2225 (message-sort-headers)))
2227 (defun message-cross-post-followup-to-header (target-group)
2228 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
2229 With prefix-argument just set Follow-Up, don't cross-post."
2231 (list ; Completion based on Gnus
2232 (completing-read "Followup To: "
2233 (if (boundp 'gnus-newsrc-alist
)
2235 nil nil
'("poster" .
0)
2236 (if (boundp 'gnus-group-history
)
2237 'gnus-group-history
))))
2238 (message-remove-header "Follow[Uu]p-[Tt]o" t
)
2239 (message-goto-newsgroups)
2241 ;; if we already did a crosspost before, kill old target
2242 (if (and message-cross-post-old-target
2244 (regexp-quote (concat "," message-cross-post-old-target
))
2247 ;; unless (followup is to poster or user explicitly asked not
2248 ;; to cross-post, or target-group is already in Newsgroups)
2249 ;; add target-group to Newsgroups line.
2251 ;; def: cross-post, req:no
2252 (and message-cross-post-default
(not current-prefix-arg
))
2253 ;; def: no-cross-post, req:yes
2254 (and (not message-cross-post-default
) current-prefix-arg
))
2255 (not (string-match "poster" target-group
))
2256 (not (string-match (regexp-quote target-group
)
2257 (message-fetch-field "Newsgroups"))))
2259 (insert (concat "," target-group
))))
2260 (end-of-line) ; ensure Followup: comes after Newsgroups:
2261 ;; unless new followup would be identical to Newsgroups line
2262 ;; make a new Followup-To line
2263 (if (not (string-match (concat "^[ \t]*"
2266 (message-fetch-field "Newsgroups")))
2267 (insert (concat "\nFollowup-To: " target-group
)))
2268 (setq message-cross-post-old-target target-group
))
2270 (defun message-cross-post-insert-note (target-group cross-post in-old
2272 "Insert a in message body note about a set Followup or Crosspost.
2273 If there have been previous notes, delete them. TARGET-GROUP specifies the
2274 group to Followup-To. When CROSS-POST is t, insert note about
2275 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
2276 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
2277 been made to before the user asked for a Crosspost."
2278 ;; start scanning body for previous uses
2279 (message-goto-signature)
2280 (let ((head (re-search-backward
2281 (concat "^" mail-header-separator
)
2282 nil t
))) ; just search in body
2283 (message-goto-signature)
2284 (while (re-search-backward
2285 (concat "^" (regexp-quote message-cross-post-note
) ".*")
2287 (message-delete-line))
2288 (message-goto-signature)
2289 (while (re-search-backward
2290 (concat "^" (regexp-quote message-followup-to-note
) ".*")
2292 (message-delete-line))
2294 (if (message-goto-signature)
2295 (re-search-backward message-signature-separator
))
2298 (string-match "^[ \t]*poster[ \t]*$" target-group
))
2299 (insert (concat message-followup-to-note target-group
"\n"))
2300 (insert (concat message-cross-post-note target-group
"\n")))))
2302 (defun message-cross-post-followup-to (target-group)
2303 "Crossposts message and set Followup-To to TARGET-GROUP.
2304 With prefix-argument just set Follow-Up, don't cross-post."
2306 (list ; Completion based on Gnus
2307 (completing-read "Followup To: "
2308 (if (boundp 'gnus-newsrc-alist
)
2310 nil nil
'("poster" .
0)
2311 (if (boundp 'gnus-group-history
)
2312 'gnus-group-history
))))
2313 (cond ((not (or (null target-group
) ; new subject not empty
2314 (zerop (string-width target-group
))
2315 (string-match "^[ \t]*$" target-group
)))
2317 (let* ((old-groups (message-fetch-field "Newsgroups"))
2318 (in-old (string-match
2319 (regexp-quote target-group
)
2320 (or old-groups
""))))
2321 ;; check whether target exactly matches old Newsgroups
2322 (cond ((not old-groups
)
2323 (error "No current newsgroup"))
2327 (regexp-quote target-group
)
2330 ;; yes, Newsgroups line must change
2331 (message-cross-post-followup-to-header target-group
)
2332 ;; insert note whether we do cross-post or followup-to
2333 (funcall message-cross-post-note-function
2335 (if (or (and message-cross-post-default
2336 (not current-prefix-arg
))
2337 (and (not message-cross-post-default
)
2338 current-prefix-arg
)) t
)
2339 in-old old-groups
))))))))
2341 ;;; Reduce To: to Cc: or Bcc: header
2343 (defun message-reduce-to-to-cc ()
2344 "Replace contents of To: header with contents of Cc: or Bcc: header."
2347 (save-restriction (message-narrow-to-headers)
2348 (message-fetch-field "cc")))
2350 (if (and (not cc-content
)
2353 (message-narrow-to-headers)
2354 (message-fetch-field "bcc"))))
2359 (message-delete-line)
2360 (insert (concat "To: " cc-content
"\n"))
2362 (message-narrow-to-headers)
2363 (message-remove-header (if bcc
2367 ;;; End of functions adopted from `message-utils.el'.
2369 (defun message-remove-header (header &optional is-regexp first reverse
)
2370 "Remove HEADER in the narrowed buffer.
2371 If IS-REGEXP, HEADER is a regular expression.
2372 If FIRST, only remove the first instance of the header.
2373 Return the number of headers removed."
2374 (goto-char (point-min))
2375 (let ((regexp (if is-regexp header
(concat "^" (regexp-quote header
) ":")))
2377 (case-fold-search t
)
2379 (while (and (not (eobp))
2382 (not (looking-at regexp
))
2383 (looking-at regexp
))
2390 ;; There might be a continuation header, so we have to search
2391 ;; until we find a new non-continuation line.
2394 (if (re-search-forward "^[^ \t]" nil t
)
2395 (goto-char (match-beginning 0))
2398 (if (re-search-forward "^[^ \t]" nil t
)
2399 (goto-char (match-beginning 0))
2400 (goto-char (point-max)))))
2403 (defun message-remove-first-header (header)
2404 "Remove the first instance of HEADER if there is more than one."
2406 (regexp (concat "^" (regexp-quote header
) ":")))
2408 (goto-char (point-min))
2409 (while (re-search-forward regexp nil t
)
2412 (message-remove-header header nil t
)
2415 (defun message-narrow-to-headers ()
2416 "Narrow the buffer to the head of the message."
2419 (goto-char (point-min))
2420 (if (re-search-forward
2421 (concat "^" (regexp-quote mail-header-separator
) "\n") nil t
)
2424 (goto-char (point-min)))
2426 (defun message-narrow-to-head-1 ()
2427 "Like `message-narrow-to-head'. Don't widen."
2429 (goto-char (point-min))
2430 (if (search-forward "\n\n" nil
1)
2433 (goto-char (point-min)))
2435 ;; FIXME: clarify diffference: message-narrow-to-head,
2436 ;; message-narrow-to-headers-or-head, message-narrow-to-headers
2437 (defun message-narrow-to-head ()
2438 "Narrow the buffer to the head of the message.
2439 Point is left at the beginning of the narrowed-to region."
2441 (message-narrow-to-head-1))
2443 (defun message-narrow-to-headers-or-head ()
2444 "Narrow the buffer to the head of the message."
2447 (goto-char (point-min))
2448 (if (re-search-forward (concat "\\(\n\\)\n\\|^\\("
2449 (regexp-quote mail-header-separator
)
2452 (or (match-end 1) (match-beginning 2))
2454 (goto-char (point-min)))
2456 (defun message-news-p ()
2457 "Say whether the current buffer contains a news message."
2458 (and (not message-this-is-mail
)
2459 (or message-this-is-news
2462 (message-narrow-to-headers)
2463 (and (message-fetch-field "newsgroups")
2464 (not (message-fetch-field "posted-to"))))))))
2466 (defun message-mail-p ()
2467 "Say whether the current buffer contains a mail message."
2468 (and (not message-this-is-news
)
2469 (or message-this-is-mail
2472 (message-narrow-to-headers)
2473 (or (message-fetch-field "to")
2474 (message-fetch-field "cc")
2475 (message-fetch-field "bcc")))))))
2477 (defun message-subscribed-p ()
2478 "Say whether we need to insert a MFT header."
2479 (or message-subscribed-regexps
2480 message-subscribed-addresses
2481 message-subscribed-address-file
2482 message-subscribed-address-functions
))
2484 (defun message-next-header ()
2485 "Go to the beginning of the next header."
2487 (or (eobp) (forward-char 1))
2488 (not (if (re-search-forward "^[^ \t]" nil t
)
2490 (goto-char (point-max)))))
2492 (defun message-sort-headers-1 ()
2493 "Sort the buffer as headers using `message-rank' text props."
2494 (goto-char (point-min))
2497 nil
'message-next-header
2499 (message-next-header)
2503 (or (get-text-property (point) 'message-rank
)
2506 (defun message-sort-headers ()
2507 "Sort the headers of the current message according to `message-header-format-alist'."
2511 (let ((max (1+ (length message-header-format-alist
)))
2513 (message-narrow-to-headers)
2514 (while (re-search-forward "^[^ \n]+:" nil t
)
2516 (match-beginning 0) (1+ (match-beginning 0))
2518 (if (setq rank
(length (memq (assq (intern (buffer-substring
2520 (1- (match-end 0))))
2521 message-header-format-alist
)
2522 message-header-format-alist
)))
2525 (message-sort-headers-1))))
2527 (defun message-kill-address ()
2528 "Kill the address under point."
2530 (let ((start (point)))
2531 (message-skip-to-next-address)
2532 (kill-region start
(point))))
2535 (autoload 'Info-goto-node
"info")
2536 (defvar mml2015-use
)
2538 (defun message-info (&optional arg
)
2539 "Display the Message manual.
2541 Prefixed with one \\[universal-argument], display the Emacs MIME
2542 manual. With two \\[universal-argument]'s, display the EasyPG or
2543 PGG manual, depending on the value of `mml2015-use'."
2545 ;; Don't use `info' because support for `(filename)nodename' is not
2546 ;; available in XEmacs < 21.5.12.
2547 (Info-goto-node (format "(%s)Top"
2551 ((eq arg
4) 'emacs-mime
)
2552 ;; `booleanp' only available in Emacs 22+
2553 ((and (not (memq arg
'(nil t
)))
2567 (defvar message-mode-map nil
)
2569 (unless message-mode-map
2570 (setq message-mode-map
(make-keymap))
2571 (set-keymap-parent message-mode-map text-mode-map
)
2572 (define-key message-mode-map
"\C-c?" 'describe-mode
)
2574 (define-key message-mode-map
"\C-c\C-f\C-t" 'message-goto-to
)
2575 (define-key message-mode-map
"\C-c\C-f\C-o" 'message-goto-from
)
2576 (define-key message-mode-map
"\C-c\C-f\C-b" 'message-goto-bcc
)
2577 (define-key message-mode-map
"\C-c\C-f\C-w" 'message-goto-fcc
)
2578 (define-key message-mode-map
"\C-c\C-f\C-c" 'message-goto-cc
)
2579 (define-key message-mode-map
"\C-c\C-f\C-s" 'message-goto-subject
)
2580 (define-key message-mode-map
"\C-c\C-f\C-r" 'message-goto-reply-to
)
2581 (define-key message-mode-map
"\C-c\C-f\C-n" 'message-goto-newsgroups
)
2582 (define-key message-mode-map
"\C-c\C-f\C-d" 'message-goto-distribution
)
2583 (define-key message-mode-map
"\C-c\C-f\C-f" 'message-goto-followup-to
)
2584 (define-key message-mode-map
"\C-c\C-f\C-m" 'message-goto-mail-followup-to
)
2585 (define-key message-mode-map
"\C-c\C-f\C-k" 'message-goto-keywords
)
2586 (define-key message-mode-map
"\C-c\C-f\C-u" 'message-goto-summary
)
2587 (define-key message-mode-map
"\C-c\C-f\C-i"
2588 'message-insert-or-toggle-importance
)
2589 (define-key message-mode-map
"\C-c\C-f\C-a"
2590 'message-generate-unsubscribed-mail-followup-to
)
2592 ;; modify headers (and insert notes in body)
2593 (define-key message-mode-map
"\C-c\C-fs" 'message-change-subject
)
2595 (define-key message-mode-map
"\C-c\C-fx" 'message-cross-post-followup-to
)
2596 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2597 (define-key message-mode-map
"\C-c\C-ft" 'message-reduce-to-to-cc
)
2598 (define-key message-mode-map
"\C-c\C-fa" 'message-add-archive-header
)
2599 ;; mark inserted text
2600 (define-key message-mode-map
"\C-c\M-m" 'message-mark-inserted-region
)
2601 (define-key message-mode-map
"\C-c\M-f" 'message-mark-insert-file
)
2603 (define-key message-mode-map
"\C-c\C-b" 'message-goto-body
)
2604 (define-key message-mode-map
"\C-c\C-i" 'message-goto-signature
)
2606 (define-key message-mode-map
"\C-c\C-t" 'message-insert-to
)
2607 (define-key message-mode-map
"\C-c\C-fw" 'message-insert-wide-reply
)
2608 (define-key message-mode-map
"\C-c\C-n" 'message-insert-newsgroups
)
2609 (define-key message-mode-map
"\C-c\C-l" 'message-to-list-only
)
2610 (define-key message-mode-map
"\C-c\C-f\C-e" 'message-insert-expires
)
2612 (define-key message-mode-map
"\C-c\C-u" 'message-insert-or-toggle-importance
)
2613 (define-key message-mode-map
"\C-c\M-n"
2614 'message-insert-disposition-notification-to
)
2616 (define-key message-mode-map
"\C-c\C-y" 'message-yank-original
)
2617 (define-key message-mode-map
"\C-c\M-\C-y" 'message-yank-buffer
)
2618 (define-key message-mode-map
"\C-c\C-q" 'message-fill-yanked-message
)
2619 (define-key message-mode-map
"\C-c\C-w" 'message-insert-signature
)
2620 (define-key message-mode-map
"\C-c\M-h" 'message-insert-headers
)
2621 (define-key message-mode-map
"\C-c\C-r" 'message-caesar-buffer-body
)
2622 (define-key message-mode-map
"\C-c\C-o" 'message-sort-headers
)
2623 (define-key message-mode-map
"\C-c\M-r" 'message-rename-buffer
)
2625 (define-key message-mode-map
"\C-c\C-c" 'message-send-and-exit
)
2626 (define-key message-mode-map
"\C-c\C-s" 'message-send
)
2627 (define-key message-mode-map
"\C-c\C-k" 'message-kill-buffer
)
2628 (define-key message-mode-map
"\C-c\C-d" 'message-dont-send
)
2629 (define-key message-mode-map
"\C-c\n" 'gnus-delay-article
)
2631 (define-key message-mode-map
"\C-c\M-k" 'message-kill-address
)
2632 (define-key message-mode-map
"\C-c\C-e" 'message-elide-region
)
2633 (define-key message-mode-map
"\C-c\C-v" 'message-delete-not-region
)
2634 (define-key message-mode-map
"\C-c\C-z" 'message-kill-to-signature
)
2635 (define-key message-mode-map
"\M-\r" 'message-newline-and-reformat
)
2636 (define-key message-mode-map
[remap split-line
] 'message-split-line
)
2638 (define-key message-mode-map
"\C-c\C-a" 'mml-attach-file
)
2640 (define-key message-mode-map
"\C-a" 'message-beginning-of-line
)
2641 (define-key message-mode-map
"\t" 'message-tab
)
2642 (define-key message-mode-map
"\M-;" 'comment-region
)
2644 (define-key message-mode-map
"\M-n" 'message-display-abbrev
))
2647 message-mode-menu message-mode-map
"Message Menu."
2649 ["Yank Original" message-yank-original message-reply-buffer
]
2650 ["Fill Yanked Message" message-fill-yanked-message t
]
2651 ["Insert Signature" message-insert-signature t
]
2652 ["Caesar (rot13) Message" message-caesar-buffer-body t
]
2653 ["Caesar (rot13) Region" message-caesar-region
(message-mark-active-p)]
2654 ["Elide Region" message-elide-region
2655 :active
(message-mark-active-p)
2656 ,@(if (featurep 'xemacs
) nil
2657 '(:help
"Replace text in region with an ellipsis"))]
2658 ["Delete Outside Region" message-delete-not-region
2659 :active
(message-mark-active-p)
2660 ,@(if (featurep 'xemacs
) nil
2661 '(:help
"Delete all quoted text outside region"))]
2662 ["Kill To Signature" message-kill-to-signature t
]
2663 ["Newline and Reformat" message-newline-and-reformat t
]
2664 ["Rename buffer" message-rename-buffer t
]
2665 ["Spellcheck" ispell-message
2666 ,@(if (featurep 'xemacs
) '(t)
2667 '(:help
"Spellcheck this message"))]
2669 ["Insert Region Marked" message-mark-inserted-region
2670 :active
(message-mark-active-p)
2671 ,@(if (featurep 'xemacs
) nil
2672 '(:help
"Mark region with enclosing tags"))]
2673 ["Insert File Marked..." message-mark-insert-file
2674 ,@(if (featurep 'xemacs
) '(t)
2675 '(:help
"Insert file at point marked with enclosing tags"))]
2677 ["Send Message" message-send-and-exit
2678 ,@(if (featurep 'xemacs
) '(t)
2679 '(:help
"Send this message"))]
2680 ["Postpone Message" message-dont-send
2681 ,@(if (featurep 'xemacs
) '(t)
2682 '(:help
"File this draft message and exit"))]
2683 ["Send at Specific Time..." gnus-delay-article
2684 ,@(if (featurep 'xemacs
) '(t)
2685 '(:help
"Ask, then arrange to send message at that time"))]
2686 ["Kill Message" message-kill-buffer
2687 ,@(if (featurep 'xemacs
) '(t)
2688 '(:help
"Delete this message without sending"))]
2690 ["Message manual" message-info
2691 ,@(if (featurep 'xemacs
) '(t)
2692 '(:help
"Display the Message manual"))]))
2695 message-mode-field-menu message-mode-map
""
2697 ["To" message-goto-to t
]
2698 ["From" message-goto-from t
]
2699 ["Subject" message-goto-subject t
]
2700 ["Change subject..." message-change-subject t
]
2701 ["Cc" message-goto-cc t
]
2702 ["Bcc" message-goto-bcc t
]
2703 ["Fcc" message-goto-fcc t
]
2704 ["Reply-To" message-goto-reply-to t
]
2705 ["Flag As Important" message-insert-importance-high
2706 ,@(if (featurep 'xemacs
) '(t)
2707 '(:help
"Mark this message as important"))]
2708 ["Flag As Unimportant" message-insert-importance-low
2709 ,@(if (featurep 'xemacs
) '(t)
2710 '(:help
"Mark this message as unimportant"))]
2712 message-insert-disposition-notification-to
2713 ,@(if (featurep 'xemacs
) '(t)
2714 '(:help
"Request a receipt notification"))]
2716 ;; (typical) news stuff
2717 ["Summary" message-goto-summary t
]
2718 ["Keywords" message-goto-keywords t
]
2719 ["Newsgroups" message-goto-newsgroups t
]
2720 ["Fetch Newsgroups" message-insert-newsgroups t
]
2721 ["Followup-To" message-goto-followup-to t
]
2722 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2723 ["Crosspost / Followup-To..." message-cross-post-followup-to t
]
2724 ["Distribution" message-goto-distribution t
]
2725 ["Expires" message-insert-expires t
]
2726 ["X-No-Archive" message-add-archive-header t
]
2728 ;; (typical) mailing-lists stuff
2729 ["Fetch To" message-insert-to
2730 ,@(if (featurep 'xemacs
) '(t)
2731 '(:help
"Insert a To header that points to the author."))]
2732 ["Fetch To and Cc" message-insert-wide-reply
2733 ,@(if (featurep 'xemacs
) '(t)
2735 "Insert To and Cc headers as if you were doing a wide reply."))]
2737 ["Send to list only" message-to-list-only t
]
2738 ["Mail-Followup-To" message-goto-mail-followup-to t
]
2739 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2740 ,@(if (featurep 'xemacs
) '(t)
2741 '(:help
"Insert a reasonable `Mail-Followup-To:' header."))]
2742 ["Reduce To: to Cc:" message-reduce-to-to-cc t
]
2744 ["Sort Headers" message-sort-headers t
]
2745 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t
]
2746 ;; We hide `message-hidden-headers' by narrowing the buffer.
2747 ["Show Hidden Headers" widen t
]
2748 ["Goto Body" message-goto-body t
]
2749 ["Goto Signature" message-goto-signature t
]))
2751 (defvar message-tool-bar-map nil
)
2753 (defvar facemenu-add-face-function
)
2754 (defvar facemenu-remove-face-function
)
2756 ;;; Forbidden properties
2758 ;; We use `after-change-functions' to keep special text properties
2759 ;; that interfere with the normal function of message mode out of the
2762 (defcustom message-strip-special-text-properties t
2763 "Strip special properties from the message buffer.
2765 Emacs has a number of special text properties which can break message
2766 composing in various ways. If this option is set, message will strip
2767 these properties from the message composition buffer. However, some
2768 packages requires these properties to be present in order to work.
2769 If you use one of these packages, turn this option off, and hope the
2770 message composition doesn't break too bad."
2772 :group
'message-various
2773 :link
'(custom-manual "(message)Various Message Variables")
2776 (defconst message-forbidden-properties
2777 ;; No reason this should be clutter up customize. We make it a
2778 ;; property list (rather than a list of property symbols), to be
2779 ;; directly useful for `remove-text-properties'.
2780 '(field nil read-only nil invisible nil intangible nil
2781 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2782 insert-behind-hooks nil point-entered nil point-left nil
)
2783 ;; Other special properties:
2784 ;; category, face, display: probably doesn't do any harm.
2785 ;; fontified: is used by font-lock.
2786 ;; syntax-table, local-map: I dunno.
2787 ;; We need to add XEmacs names to the list.
2788 "Property list of with properties forbidden in message buffers.
2789 The values of the properties are ignored, only the property names are used.")
2791 (defun message-tamago-not-in-use-p (pos)
2792 "Return t when tamago version 4 is not in use at the cursor position.
2793 Tamago version 4 is a popular input method for writing Japanese text.
2794 It uses the properties `intangible', `invisible', `modification-hooks'
2795 and `read-only' when translating ascii or kana text to kanji text.
2796 These properties are essential to work, so we should never strip them."
2797 (not (and (boundp 'egg-modefull-mode
)
2798 (symbol-value 'egg-modefull-mode
)
2799 (or (memq (get-text-property pos
'intangible
)
2800 '(its-part-1 its-part-2
))
2801 (get-text-property pos
'egg-end
)
2802 (get-text-property pos
'egg-lang
)
2803 (get-text-property pos
'egg-start
)))))
2805 (defsubst message-mail-alias-type-p
(type)
2806 (if (atom message-mail-alias-type
)
2807 (eq message-mail-alias-type type
)
2808 (memq type message-mail-alias-type
)))
2810 (defun message-strip-forbidden-properties (begin end
&optional old-length
)
2811 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2812 This function is intended to be called from `after-change-functions'.
2813 See also `message-forbidden-properties'."
2814 (when (and (message-mail-alias-type-p 'ecomplete
)
2815 (memq this-command message-self-insert-commands
))
2816 (message-display-abbrev))
2817 (when (and message-strip-special-text-properties
2818 (message-tamago-not-in-use-p begin
))
2819 (let ((buffer-read-only nil
)
2820 (inhibit-read-only t
))
2821 (remove-text-properties begin end message-forbidden-properties
))))
2823 (autoload 'ecomplete-setup
"ecomplete") ;; for Emacs <23.
2826 (define-derived-mode message-mode text-mode
"Message"
2827 "Major mode for editing mail and news to be sent.
2828 Like Text Mode but with these additional commands:\\<message-mode-map>
2829 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2830 C-c C-d Postpone sending the message C-c C-k Kill the message
2831 C-c C-f move to a header field (and create it if there isn't):
2832 C-c C-f C-t move to To C-c C-f C-s move to Subject
2833 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2834 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2835 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2836 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2837 C-c C-f C-o move to From (\"Originator\")
2838 C-c C-f C-f move to Followup-To
2839 C-c C-f C-m move to Mail-Followup-To
2840 C-c C-f C-e move to Expires
2841 C-c C-f C-i cycle through Importance values
2842 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2843 C-c C-f x crossposting with FollowUp-To header and note in body
2844 C-c C-f t replace To: header with contents of Cc: or Bcc:
2845 C-c C-f a Insert X-No-Archive: header and a note in the body
2846 C-c C-t `message-insert-to' (add a To header to a news followup)
2847 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2848 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2849 C-c C-b `message-goto-body' (move to beginning of message text).
2850 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2851 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2852 C-c C-y `message-yank-original' (insert current message, if any).
2853 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2854 C-c C-e `message-elide-region' (elide the text between point and mark).
2855 C-c C-v `message-delete-not-region' (remove the text outside the region).
2856 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2857 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2858 C-c C-a `mml-attach-file' (attach a file as MIME).
2859 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2860 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2861 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2862 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2863 M-RET `message-newline-and-reformat' (break the line and reformat)."
2864 (setq local-abbrev-table text-mode-abbrev-table
)
2865 (set (make-local-variable 'message-reply-buffer
) nil
)
2866 (set (make-local-variable 'message-inserted-headers
) nil
)
2867 (set (make-local-variable 'message-send-actions
) nil
)
2868 (set (make-local-variable 'message-exit-actions
) nil
)
2869 (set (make-local-variable 'message-kill-actions
) nil
)
2870 (set (make-local-variable 'message-postpone-actions
) nil
)
2871 (set (make-local-variable 'message-draft-article
) nil
)
2872 (setq buffer-offer-save t
)
2873 (set (make-local-variable 'facemenu-add-face-function
)
2875 (let ((face-fun (cdr (assq face message-face-alist
))))
2877 (funcall face-fun
(point) end
)
2878 (error "Face %s not configured for %s mode" face mode-name
)))
2880 (set (make-local-variable 'facemenu-remove-face-function
) t
)
2881 (set (make-local-variable 'message-reply-headers
) nil
)
2882 (make-local-variable 'message-newsreader
)
2883 (make-local-variable 'message-mailer
)
2884 (make-local-variable 'message-post-method
)
2885 (set (make-local-variable 'message-sent-message-via
) nil
)
2886 (set (make-local-variable 'message-checksum
) nil
)
2887 (set (make-local-variable 'message-mime-part
) 0)
2888 (message-setup-fill-variables)
2889 (when message-fill-column
2890 (setq fill-column message-fill-column
)
2891 (turn-on-auto-fill))
2892 ;; Allow using comment commands to add/remove quoting.
2893 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2894 (when message-yank-prefix
2895 (set (make-local-variable 'comment-start
) message-yank-prefix
)
2896 (set (make-local-variable 'comment-start-skip
)
2897 (concat "^" (regexp-quote message-yank-prefix
) "[ \t]*")))
2898 (if (featurep 'xemacs
)
2899 (message-setup-toolbar)
2900 (set (make-local-variable 'font-lock-defaults
)
2901 '(message-font-lock-keywords t
))
2902 (if (boundp 'tool-bar-map
)
2903 (set (make-local-variable 'tool-bar-map
) (message-make-tool-bar))))
2904 (easy-menu-add message-mode-menu message-mode-map
)
2905 (easy-menu-add message-mode-field-menu message-mode-map
)
2906 (gnus-make-local-hook 'after-change-functions
)
2907 ;; Mmmm... Forbidden properties...
2908 (add-hook 'after-change-functions
'message-strip-forbidden-properties
2910 ;; Allow mail alias things.
2912 ((message-mail-alias-type-p 'abbrev
)
2913 (if (fboundp 'mail-abbrevs-setup
)
2914 (mail-abbrevs-setup)
2915 (if (fboundp 'mail-aliases-setup
) ; warning avoidance
2916 (mail-aliases-setup))))
2917 ((message-mail-alias-type-p 'ecomplete
)
2919 (unless buffer-file-name
2920 (message-set-auto-save-file-name))
2921 (unless (buffer-base-buffer)
2922 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2923 ;; multibyte is not necessary at all. -- zsh
2924 (mm-enable-multibyte))
2925 (set (make-local-variable 'indent-tabs-mode
) nil
) ;No tabs for indentation.
2928 (defun message-setup-fill-variables ()
2929 "Setup message fill variables."
2930 (set (make-local-variable 'fill-paragraph-function
)
2931 'message-fill-paragraph
)
2932 (make-local-variable 'paragraph-separate
)
2933 (make-local-variable 'paragraph-start
)
2934 (make-local-variable 'adaptive-fill-regexp
)
2935 (unless (boundp 'adaptive-fill-first-line-regexp
)
2936 (setq adaptive-fill-first-line-regexp nil
))
2937 (make-local-variable 'adaptive-fill-first-line-regexp
)
2938 (let ((quote-prefix-regexp
2939 ;; User should change message-cite-prefix-regexp if
2940 ;; message-yank-prefix is set to an abnormal value.
2941 (concat "\\(" message-cite-prefix-regexp
"\\)[ \t]*")))
2942 (setq paragraph-start
2944 (regexp-quote mail-header-separator
) "$\\|"
2945 "[ \t]*$\\|" ; blank lines
2946 "-- $\\|" ; signature delimiter
2947 "---+$\\|" ; delimiters for forwarded messages
2948 page-delimiter
"$\\|" ; spoiler warnings
2949 ".*wrote:$\\|" ; attribution lines
2950 quote-prefix-regexp
"$\\|" ; empty lines in quoted text
2952 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
2953 (setq paragraph-separate paragraph-start
)
2954 (setq adaptive-fill-regexp
2955 (concat quote-prefix-regexp
"\\|" adaptive-fill-regexp
))
2956 (setq adaptive-fill-first-line-regexp
2957 (concat quote-prefix-regexp
"\\|"
2958 adaptive-fill-first-line-regexp
)))
2959 (make-local-variable 'auto-fill-inhibit-regexp
)
2960 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2961 (setq auto-fill-inhibit-regexp nil
)
2962 (make-local-variable 'normal-auto-fill-function
)
2963 (setq normal-auto-fill-function
'message-do-auto-fill
)
2964 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2965 ;; In that case, ensure that it uses the right function. The real
2966 ;; solution would be not to use `define-derived-mode', and run
2967 ;; `text-mode-hook' ourself at the end of the mode.
2968 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2969 ;; This kludge is unneeded in Emacs>=21 since define-derived-mode is
2970 ;; now careful to run parent hooks after the body. --Stef
2971 (when auto-fill-function
2972 (setq auto-fill-function normal-auto-fill-function
)))
2977 ;;; Message mode commands
2980 ;;; Movement commands
2982 (defun message-goto-to ()
2983 "Move point to the To header."
2985 (message-position-on-field "To"))
2987 (defun message-goto-from ()
2988 "Move point to the From header."
2990 (message-position-on-field "From"))
2992 (defun message-goto-subject ()
2993 "Move point to the Subject header."
2995 (message-position-on-field "Subject"))
2997 (defun message-goto-cc ()
2998 "Move point to the Cc header."
3000 (message-position-on-field "Cc" "To"))
3002 (defun message-goto-bcc ()
3003 "Move point to the Bcc header."
3005 (message-position-on-field "Bcc" "Cc" "To"))
3007 (defun message-goto-fcc ()
3008 "Move point to the Fcc header."
3010 (message-position-on-field "Fcc" "To" "Newsgroups"))
3012 (defun message-goto-reply-to ()
3013 "Move point to the Reply-To header."
3015 (message-position-on-field "Reply-To" "Subject"))
3017 (defun message-goto-newsgroups ()
3018 "Move point to the Newsgroups header."
3020 (message-position-on-field "Newsgroups"))
3022 (defun message-goto-distribution ()
3023 "Move point to the Distribution header."
3025 (message-position-on-field "Distribution"))
3027 (defun message-goto-followup-to ()
3028 "Move point to the Followup-To header."
3030 (message-position-on-field "Followup-To" "Newsgroups"))
3032 (defun message-goto-mail-followup-to ()
3033 "Move point to the Mail-Followup-To header."
3035 (message-position-on-field "Mail-Followup-To" "To"))
3037 (defun message-goto-keywords ()
3038 "Move point to the Keywords header."
3040 (message-position-on-field "Keywords" "Subject"))
3042 (defun message-goto-summary ()
3043 "Move point to the Summary header."
3045 (message-position-on-field "Summary" "Subject"))
3047 (defun message-goto-body (&optional interactivep
)
3048 "Move point to the beginning of the message body."
3049 (interactive (list t
))
3050 (when (and interactivep
3051 (looking-at "[ \t]*\n"))
3053 (goto-char (point-min))
3054 (or (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
3055 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t
)))
3057 (defun message-in-body-p ()
3058 "Return t if point is in the message body."
3059 (let ((body (save-excursion (message-goto-body) (point))))
3062 (defun message-goto-eoh ()
3063 "Move point to the end of the headers."
3068 (defun message-goto-signature ()
3069 "Move point to the beginning of the message signature.
3070 If there is no signature in the article, go to the end and
3073 (goto-char (point-min))
3074 (if (re-search-forward message-signature-separator nil t
)
3076 (goto-char (point-max))
3079 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc
)
3080 "Insert a reasonable MFT header in a post to an unsubscribed list.
3081 When making original posts to a mailing list you are not subscribed to,
3082 you have to type in a MFT header by hand. The contents, usually, are
3083 the addresses of the list and your own address. This function inserts
3084 such a header automatically. It fetches the contents of the To: header
3085 in the current mail buffer, and appends the current `user-mail-address'.
3087 If the optional argument INCLUDE-CC is non-nil, the addresses in the
3088 Cc: header are also put into the MFT."
3093 (message-narrow-to-headers)
3094 (message-remove-header "Mail-Followup-To")
3095 (setq cc
(and include-cc
(message-fetch-field "Cc")))
3097 (concat (message-fetch-field "To") "," cc
)
3098 (message-fetch-field "To"))))
3099 (message-goto-mail-followup-to)
3100 (insert (concat tos
", " user-mail-address
))))
3104 (defun message-insert-to (&optional force
)
3105 "Insert a To header that points to the author of the article being replied to.
3106 If the original author requested not to be sent mail, don't insert unless the
3107 prefix FORCE is given."
3109 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
3110 (dont (and mct
(or (equal (downcase mct
) "never")
3111 (equal (downcase mct
) "nobody"))))
3112 (to (or (message-fetch-reply-field "mail-reply-to")
3113 (message-fetch-reply-field "reply-to")
3114 (message-fetch-reply-field "from"))))
3118 "Ignoring the user request not to have copies sent via mail"
3119 "Complying with the user request not to have copies sent via mail")))
3120 (when (and force
(not to
))
3121 (error "No mail address in the article"))
3122 (when (and to
(or force
(not dont
)))
3123 (message-carefully-insert-headers (list (cons 'To to
))))))
3125 (defun message-insert-wide-reply ()
3126 "Insert To and Cc headers as if you were doing a wide reply."
3128 (let ((headers (message-with-reply-buffer
3129 (message-get-reply-headers t
))))
3130 (message-carefully-insert-headers headers
)))
3132 (defcustom message-header-synonyms
3135 "List of lists of header synonyms.
3136 E.g., if this list contains a member list with elements `Cc' and `To',
3137 then `message-carefully-insert-headers' will not insert a `To' header
3138 when the message is already `Cc'ed to the recipient."
3140 :group
'message-headers
3141 :link
'(custom-manual "(message)Message Headers")
3142 :type
'(repeat sexp
))
3144 (defun message-carefully-insert-headers (headers)
3145 "Insert the HEADERS, an alist, into the message buffer.
3146 Does not insert the headers when they are already present there
3147 or in the synonym headers, defined by `message-header-synonyms'."
3148 ;; FIXME: Should compare only the address and not the full name. Comparison
3149 ;; should be done case-folded (and with `string=' rather than
3151 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
3152 (dolist (header headers
)
3153 (let* ((header-name (symbol-name (car header
)))
3154 (new-header (cdr header
))
3155 (synonyms (loop for synonym in message-header-synonyms
3156 when
(memq (car header
) synonym
) return synonym
))
3158 (loop for synonym in synonyms
3159 for old-header
= (mail-fetch-field (symbol-name synonym
))
3160 when
(and old-header
(string-match new-header old-header
))
3163 (message "already have `%s' in `%s'" new-header old-header
)
3164 (when (and (message-position-on-field header-name
)
3165 (setq old-header
(mail-fetch-field header-name
))
3166 (not (string-match "\\` *\\'" old-header
)))
3168 (insert new-header
)))))
3170 (defun message-widen-reply ()
3171 "Widen the reply to include maximum recipients."
3174 (and (bufferp message-reply-buffer
)
3175 (buffer-name message-reply-buffer
)
3176 (with-current-buffer message-reply-buffer
3177 (message-get-reply-headers t
)))))
3180 (message-narrow-to-headers)
3181 (dolist (elem follow-to
)
3182 (message-remove-header (symbol-name (car elem
)))
3183 (goto-char (point-min))
3184 (insert (symbol-name (car elem
)) ": "
3185 (cdr elem
) "\n"))))))
3187 (defun message-insert-newsgroups ()
3188 "Insert the Newsgroups header from the article being replied to."
3190 (when (and (message-position-on-field "Newsgroups")
3191 (mail-fetch-field "newsgroups")
3192 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
3194 (insert (or (message-fetch-reply-field "newsgroups") "")))
3198 ;;; Various commands
3200 (defun message-delete-not-region (beg end
)
3201 "Delete everything in the body of the current message outside of the region."
3206 ;; snarf citation prefix, if appropriate
3207 (unless (eq (point) (progn (beginning-of-line) (point)))
3208 (when (looking-at message-cite-prefix-regexp
)
3209 (setq citeprefix
(match-string 0))))
3211 (delete-region (point) (if (not (message-goto-signature))
3217 (delete-region beg
(progn (message-goto-body)
3221 (insert citeprefix
))))
3222 (when (message-goto-signature)
3225 (defun message-kill-to-signature (&optional arg
)
3226 "Kill all text up to the signature.
3227 If a numeric argument or prefix arg is given, leave that number
3228 of lines before the signature intact."
3232 (let ((point (point)))
3233 (narrow-to-region point
(point-max))
3234 (message-goto-signature)
3236 (if (and arg
(numberp arg
))
3237 (forward-line (- -
1 arg
))
3239 (unless (= point
(point))
3240 (kill-region point
(point))
3244 (defun message-newline-and-reformat (&optional arg not-break
)
3245 "Insert four newlines, and then reformat if inside quoted text.
3246 Prefix arg means justify as well."
3247 (interactive (list (if current-prefix-arg
'full
)))
3248 (let (quoted point beg end leading-space bolp fill-paragraph-function
)
3249 (setq point
(point))
3252 (setq bolp
(= beg point
))
3253 ;; Find first line of the paragraph.
3255 (while (and (not (eobp))
3256 (not (looking-at message-cite-prefix-regexp
))
3257 (looking-at paragraph-start
))
3260 (when (looking-at message-cite-prefix-regexp
)
3261 (setq quoted
(match-string 0))
3262 (goto-char (match-end 0))
3263 (looking-at "[ \t]*")
3264 (setq leading-space
(match-string 0)))
3268 (< (- point beg
) (length quoted
)))
3269 ;; break inside the cite prefix.
3275 (while (and (not (eobp))
3276 (not (looking-at paragraph-separate
))
3277 (looking-at message-cite-prefix-regexp
)
3278 (equal quoted
(match-string 0)))
3279 (goto-char (match-end 0))
3280 (looking-at "[ \t]*")
3281 (if (> (length leading-space
) (length (match-string 0)))
3282 (setq leading-space
(match-string 0)))
3286 (while (and (if (bobp) nil
(forward-line -
1) t
)
3287 (not (looking-at paragraph-start
))
3288 (looking-at message-cite-prefix-regexp
)
3289 (equal quoted
(match-string 0)))
3291 (goto-char (match-end 0))
3292 (looking-at "[ \t]*")
3293 (if (> (length leading-space
) (length (match-string 0)))
3294 (setq leading-space
(match-string 0)))))
3295 (while (and (not (eobp))
3296 (not (looking-at paragraph-separate
))
3297 (not (looking-at message-cite-prefix-regexp
)))
3301 (while (and (if (bobp) nil
(forward-line -
1) t
)
3302 (not (looking-at paragraph-start
))
3303 (not (looking-at message-cite-prefix-regexp
)))
3304 (setq beg
(point))))
3307 (narrow-to-region beg end
)
3314 (setq point
(point))
3315 ;; (newline 2) doesn't mark both newline's as hard, so call
3316 ;; newline twice. -jas
3319 (delete-region (point) (re-search-forward "[ \t]*"))
3320 (when (and quoted
(not bolp
))
3321 (insert quoted leading-space
)))
3324 (let* ((adaptive-fill-regexp
3325 (regexp-quote (concat quoted leading-space
)))
3326 (adaptive-fill-first-line-regexp
3327 adaptive-fill-regexp
))
3328 (fill-paragraph arg
))
3329 (fill-paragraph arg
))
3330 (if point
(goto-char point
)))))
3332 (defun message-fill-paragraph (&optional arg
)
3333 "Message specific function to fill a paragraph.
3334 This function is used as the value of `fill-paragraph-function' in
3335 Message buffers and is not meant to be called directly."
3336 (interactive (list (if current-prefix-arg
'full
)))
3337 (if (if (boundp 'filladapt-mode
) filladapt-mode
)
3339 (if (message-point-in-header-p)
3340 (message-fill-field)
3341 (message-newline-and-reformat arg t
))
3344 (defun message-point-in-header-p ()
3345 "Return t if point is in the header."
3347 (not (re-search-backward
3348 (concat "^" (regexp-quote mail-header-separator
) "\n") nil t
))))
3350 (defun message-do-auto-fill ()
3351 "Like `do-auto-fill', but don't fill in message header."
3352 (unless (message-point-in-header-p)
3355 (defun message-insert-signature (&optional force
)
3356 "Insert a signature. See documentation for variable `message-signature'."
3357 (interactive (list 0))
3360 ((and (null message-signature
)
3363 (goto-char (point-max))
3364 (not (re-search-backward message-signature-separator nil t
))))
3365 ((and (null message-signature
)
3368 ((functionp message-signature
)
3369 (funcall message-signature
))
3370 ((listp message-signature
)
3371 (eval message-signature
))
3372 (t message-signature
)))
3375 (cond ((stringp signature
)
3377 ((and (eq t signature
) message-signature-file
)
3378 (setq signature-file
3379 (if (and message-signature-directory
3380 ;; don't actually use the signature directory
3381 ;; if message-signature-file contains a path.
3382 (not (file-name-directory
3383 message-signature-file
)))
3384 (expand-file-name message-signature-file
3385 message-signature-directory
)
3386 message-signature-file
))
3387 (file-exists-p signature-file
))))
3389 (goto-char (point-max))
3390 ;; Insert the signature.
3393 (when message-signature-insert-empty-line
3396 (if (eq signature t
)
3397 (insert-file-contents signature-file
)
3399 (goto-char (point-max))
3400 (or (bolp) (insert "\n")))))
3402 (defun message-insert-importance-high ()
3403 "Insert header to mark message as important."
3407 (message-narrow-to-headers)
3408 (message-remove-header "Importance"))
3410 (insert "Importance: high\n")))
3412 (defun message-insert-importance-low ()
3413 "Insert header to mark message as unimportant."
3417 (message-narrow-to-headers)
3418 (message-remove-header "Importance"))
3420 (insert "Importance: low\n")))
3422 (defun message-insert-or-toggle-importance ()
3423 "Insert a \"Importance: high\" header, or cycle through the header values.
3424 The three allowed values according to RFC 1327 are `high', `normal'
3431 (message-narrow-to-headers)
3432 (when (setq cur
(message-fetch-field "Importance"))
3433 (message-remove-header "Importance")
3434 (setq new
(cond ((string= cur
"high")
3436 ((string= cur
"low")
3441 (insert (format "Importance: %s\n" new
)))))
3443 (defun message-insert-disposition-notification-to ()
3444 "Request a disposition notification (return receipt) to this message.
3445 Note that this should not be used in newsgroups."
3449 (message-narrow-to-headers)
3450 (message-remove-header "Disposition-Notification-To"))
3452 (insert (format "Disposition-Notification-To: %s\n"
3453 (or (message-field-value "Reply-to")
3454 (message-field-value "From")
3455 (message-make-from))))))
3457 (defun message-elide-region (b e
)
3458 "Elide the text in the region.
3459 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3463 (insert message-elide-ellipsis
))
3465 (defvar message-caesar-translation-table nil
)
3467 (defun message-caesar-region (b e
&optional n
)
3468 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3471 (min (point) (or (mark t
) (point)))
3472 (max (point) (or (mark t
) (point)))
3473 (when current-prefix-arg
3474 (prefix-numeric-value current-prefix-arg
))))
3476 (setq n
(if (numberp n
) (mod n
26) 13)) ;canonize N
3477 (unless (or (zerop n
) ; no action needed for a rot of 0
3478 (= b e
)) ; no region to rotate
3479 ;; We build the table, if necessary.
3480 (when (or (not message-caesar-translation-table
)
3481 (/= (aref message-caesar-translation-table ?a
) (+ ?a n
)))
3482 (setq message-caesar-translation-table
3483 (message-make-caesar-translation-table n
)))
3484 (translate-region b e message-caesar-translation-table
)))
3486 (defun message-make-caesar-translation-table (n)
3487 "Create a rot table with offset N."
3489 (table (make-string 256 0)))
3490 (while (< (incf i
) 256)
3493 (substring table
0 ?A
)
3494 (substring table
(+ ?A n
) (+ ?A n
(- 26 n
)))
3495 (substring table ?A
(+ ?A n
))
3496 (substring table
(+ ?A
26) ?a
)
3497 (substring table
(+ ?a n
) (+ ?a n
(- 26 n
)))
3498 (substring table ?a
(+ ?a n
))
3499 (substring table
(+ ?a
26) 255))))
3501 (defun message-caesar-buffer-body (&optional rotnum wide
)
3502 "Caesar rotate all letters in the current buffer by 13 places.
3503 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3504 With prefix arg, specifies the number of places to rotate each letter forward.
3505 Mail and USENET news headers are not rotated unless WIDE is non-nil."
3506 (interactive (if current-prefix-arg
3507 (list (prefix-numeric-value current-prefix-arg
))
3511 (when (and (not wide
) (message-goto-body))
3512 (narrow-to-region (point) (point-max)))
3513 (message-caesar-region (point-min) (point-max) rotnum
))))
3515 (defun message-pipe-buffer-body (program)
3516 "Pipe the message body in the current buffer through PROGRAM."
3519 (when (message-goto-body)
3520 (narrow-to-region (point) (point-max)))
3521 (shell-command-on-region
3522 (point-min) (point-max) program nil t
))))
3524 (defun message-rename-buffer (&optional enter-string
)
3525 "Rename the *message* buffer to \"*message* RECIPIENT\".
3526 If the function is run with a prefix, it will ask for a new buffer
3527 name, rather than giving an automatic name."
3528 (interactive "Pbuffer name: ")
3531 (goto-char (point-min))
3532 (narrow-to-region (point)
3533 (search-forward mail-header-separator nil
'end
))
3535 (if (message-news-p) (message-fetch-field "Newsgroups")
3536 (message-fetch-field "To"))
3539 (if (string-match "," mail-to
)
3540 (concat (substring mail-to
0 (match-beginning 0)) ", ...")
3542 (name-default (concat "*message* " mail-trimmed-to
))
3543 (name (if enter-string
3544 (read-string "New buffer name: " name-default
)
3546 (rename-buffer name t
)))))
3548 (defun message-fill-yanked-message (&optional justifyp
)
3549 "Fill the paragraphs of a message yanked into this one.
3550 Numeric argument means justify as well."
3553 (goto-char (point-min))
3554 (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
3555 (let ((fill-prefix message-yank-prefix
))
3556 (fill-individual-paragraphs (point) (point-max) justifyp
))))
3558 (defun message-indent-citation (&optional start end yank-only
)
3559 "Modify text just inserted from a message to be cited.
3560 The inserted text should be the region.
3561 When this function returns, the region is again around the modified text.
3563 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3564 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3565 (unless start
(setq start
(point)))
3567 ;; Remove unwanted headers.
3568 (when message-ignored-cited-headers
3573 (if (search-forward "\n\n" nil t
)
3576 (message-remove-header message-ignored-cited-headers t
)
3577 (when (= (point-min) (point-max))
3578 (setq all-removed t
))
3579 (goto-char (point-max)))
3583 ;; Delete blank lines at the start of the buffer.
3584 (while (and (point-min)
3587 (message-delete-line))
3588 ;; Delete blank lines at the end of the buffer.
3589 (goto-char (point-max))
3592 (while (and (zerop (forward-line -
1))
3594 (message-delete-line)))
3595 ;; Do the indentation.
3596 (if (null message-yank-prefix
)
3597 (indent-rigidly start
(or end
(mark t
)) message-indentation-spaces
)
3600 (while (< (point) (or end
(mark t
)))
3601 (cond ((looking-at ">")
3602 (insert message-yank-cited-prefix
))
3604 (insert message-yank-empty-prefix
))
3606 (insert message-yank-prefix
)))
3610 (defun message-remove-blank-cited-lines (&optional remove
)
3611 "Remove cited lines containing only blanks.
3612 If REMOVE is non-nil, remove newlines, too.
3614 To use this automatically, you may add this function to
3615 `gnus-message-setup-hook'."
3620 (when (boundp 'message-yank-cited-prefix
)
3621 (concat message-yank-cited-prefix
"\\|"))
3625 (gnus-message 8 "removing `%s'" citexp
)
3628 (while (re-search-forward citexp nil t
)
3629 (replace-match (if remove
"" "\n"))))))
3631 (defvar message-cite-reply-above nil
3632 "If non-nil, start own text above the quote.
3634 Note: Top posting is bad netiquette. Don't use it unless you
3635 really must. You probably want to set variable only for specific
3636 groups, e.g. using `gnus-posting-styles':
3638 (eval (set (make-local-variable 'message-cite-reply-above) t))
3640 This variable has no effect in news postings.")
3642 (defun message-yank-original (&optional arg
)
3643 "Insert the message being replied to, if any.
3644 Puts point before the text and mark after.
3645 Normally indents each nonblank line ARG spaces (default 3). However,
3646 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3648 This function uses `message-cite-function' to do the actual citing.
3650 Just \\[universal-argument] as argument means don't indent, insert no
3651 prefix, and don't delete any headers."
3653 (let ((modified (buffer-modified-p))
3655 (when (and message-reply-buffer
3656 message-cite-function
)
3657 (when message-cite-reply-above
3658 (if (and (not (message-news-p))
3659 (or (eq message-cite-reply-above
'is-evil
)
3661 Top posting is bad netiquette. Please don't top post unless you really must.
3662 Really top post? ")))
3665 (buffer-substring (message-goto-body)
3667 (delete-region (message-goto-body) (point-max)))
3668 (set (make-local-variable 'message-cite-reply-above
) nil
)))
3669 (if (bufferp message-reply-buffer
)
3670 (delete-windows-on message-reply-buffer t
))
3671 (push-mark (save-excursion
3673 ((bufferp message-reply-buffer
)
3674 (insert-buffer-substring message-reply-buffer
))
3675 ((and (consp message-reply-buffer
)
3676 (functionp (car message-reply-buffer
)))
3677 (apply (car message-reply-buffer
)
3678 (cdr message-reply-buffer
))))
3683 (funcall message-cite-function
)
3684 (unless (eq (char-before (mark t
)) ?
\n)
3686 (goto-char (mark t
))
3687 (insert-before-markers ?
\n)
3689 (when message-cite-reply-above
3692 (insert (if (bolp) "\n" "\n\n"))
3693 (message-goto-body))
3694 ;; Add a `message-setup-very-last-hook' here?
3695 ;; Add `gnus-article-highlight-citation' here?
3697 (setq message-checksum
(message-checksum))))))
3699 (defun message-yank-buffer (buffer)
3700 "Insert BUFFER into the current buffer and quote it."
3701 (interactive "bYank buffer: ")
3702 (let ((message-reply-buffer (get-buffer buffer
)))
3703 (save-window-excursion
3704 (message-yank-original))))
3706 (defun message-buffers ()
3707 "Return a list of active message buffers."
3709 (save-current-buffer
3710 (dolist (buffer (buffer-list t
))
3712 (when (and (eq major-mode
'message-mode
)
3713 (null message-sent-message-via
))
3714 (push (buffer-name buffer
) buffers
))))
3715 (nreverse buffers
)))
3717 (defun message-cite-original-1 (strip-signature)
3718 "Cite an original message.
3719 If STRIP-SIGNATURE is non-nil, strips off the signature from the
3722 This function uses `mail-citation-hook' if that is non-nil."
3723 (if (and (boundp 'mail-citation-hook
)
3725 (run-hooks 'mail-citation-hook
)
3726 (let* ((start (point))
3730 (when message-indent-citation-function
3731 (if (listp message-indent-citation-function
)
3732 message-indent-citation-function
3733 (list message-indent-citation-function
))))
3734 ;; This function may be called by `gnus-summary-yank-message' and
3735 ;; may insert a different article from the original. So, we will
3736 ;; modify the value of `message-reply-headers' with that article.
3737 (message-reply-headers
3739 (narrow-to-region start end
)
3740 (message-narrow-to-head-1)
3741 (setq x-no-archive
(message-fetch-field "x-no-archive"))
3743 (or (message-fetch-field "subject") "none")
3744 (or (message-fetch-field "from") "nobody")
3745 (message-fetch-field "date")
3746 (message-fetch-field "message-id" t
)
3747 (message-fetch-field "references")
3749 (mml-quote-region start end
)
3750 (when strip-signature
3754 (when (re-search-backward message-signature-separator start t
)
3755 ;; Also peel off any blank lines before the signature.
3757 (while (looking-at "^[ \t]*$")
3760 (delete-region (point) end
)
3761 (unless (search-backward "\n\n" start t
)
3762 ;; Insert a blank line if it is peeled off.
3765 (mapc 'funcall functions
)
3766 (when message-citation-line-function
3769 (funcall message-citation-line-function
))
3770 (when (and x-no-archive
3771 (not message-cite-articles-with-x-no-archive
)
3772 (string-match "yes" x-no-archive
))
3774 (delete-region (point) (mark t
))
3775 (insert "> [Quoted text removed due to X-No-Archive]\n")
3777 (forward-line -
1)))))
3779 (defun message-cite-original ()
3780 "Cite function in the standard Message manner."
3781 (message-cite-original-1 nil
))
3783 (defvar gnus-extract-address-components
)
3785 (autoload 'format-spec
"format-spec")
3787 (defun message-insert-formatted-citation-line (&optional from date
)
3788 "Function that inserts a formatted citation line.
3790 See `message-citation-line-format'."
3791 ;; The optional args are for testing/debugging. They will disappear later.
3793 ;; (with-temp-buffer
3794 ;; (message-insert-formatted-citation-line
3795 ;; "John Doe <john.doe@example.invalid>"
3798 (when (or message-reply-headers
(and from date
))
3800 (setq from
(mail-header-from message-reply-headers
)))
3801 (let* ((data (condition-case ()
3802 (funcall (if (boundp gnus-extract-address-components
)
3803 gnus-extract-address-components
3804 'mail-extract-address-components
)
3810 (net (car (cdr data
)))
3811 (name-or-net (or (car data
)
3812 (car (cdr data
)) from
))
3816 ;; We need Gnus functionality if the user wants date or time from
3817 ;; the original article:
3818 (when (string-match "%[^fnNFL]" message-citation-line-format
)
3819 (autoload 'gnus-date-get-time
"gnus-util")
3820 (gnus-date-get-time (mail-header-date message-reply-headers
)))))
3823 (when (stringp name
)
3824 ;; Guess first name and last name:
3825 (cond ((string-match
3826 "\\`\\(\\w\\|[-.]\\)+ \\(\\w\\|[-.]\\)+\\'" name
)
3827 (setq fname
(nth 0 (split-string name
"[ \t]+"))
3828 lname
(nth 1 (split-string name
"[ \t]+"))))
3830 "\\`\\(\\w\\|[-.]\\)+, \\(\\w\\|[-.]\\)+\\'" name
)
3831 (setq fname
(nth 1 (split-string name
"[ \t,]+"))
3832 lname
(nth 0 (split-string name
"[ \t,]+"))))
3834 "\\`\\(\\w\\|[-.]\\)+\\'" name
)
3837 ;; The following letters are not used in `format-time-string':
3838 (push ?E lst
) (push "<E>" lst
)
3839 (push ?F lst
) (push fname lst
)
3840 ;; We might want to use "" instead of "<X>" later.
3841 (push ?J lst
) (push "<J>" lst
)
3842 (push ?K lst
) (push "<K>" lst
)
3843 (push ?L lst
) (push lname lst
)
3844 (push ?N lst
) (push name-or-net lst
)
3845 (push ?O lst
) (push "<O>" lst
)
3846 (push ?P lst
) (push "<P>" lst
)
3847 (push ?Q lst
) (push "<Q>" lst
)
3848 (push ?f lst
) (push from lst
)
3849 (push ?i lst
) (push "<i>" lst
)
3850 (push ?n lst
) (push net lst
)
3851 (push ?o lst
) (push "<o>" lst
)
3852 (push ?q lst
) (push "<q>" lst
)
3853 (push ?t lst
) (push "<t>" lst
)
3854 (push ?v lst
) (push "<v>" lst
)
3855 ;; Delegate the rest to `format-time-string':
3857 (when (and (not (memq i lst
))
3862 (push (condition-case nil
3863 (format-time-string (format "%%%c" i
) replydate
)
3864 (error (format ">%c<" i
)))
3868 (spec (apply 'format-spec-make flist
)))
3869 (insert (format-spec message-citation-line-format spec
)))
3872 (defun message-cite-original-without-signature ()
3873 "Cite function in the standard Message manner.
3874 This function strips off the signature from the original message."
3875 (message-cite-original-1 t
))
3877 (defun message-insert-citation-line ()
3878 "Insert a simple citation line."
3879 (when message-reply-headers
3880 (insert (mail-header-from message-reply-headers
) " writes:")
3884 (defun message-position-on-field (header &rest afters
)
3885 (let ((case-fold-search t
))
3888 (goto-char (point-min))
3891 (concat "^" (regexp-quote mail-header-separator
) "$"))
3892 (match-beginning 0)))
3893 (goto-char (point-min))
3894 (if (re-search-forward (concat "^" (regexp-quote header
) ":") nil t
)
3896 (re-search-forward "^[^ \t]" nil
'move
)
3898 (skip-chars-backward "\n")
3901 (not (re-search-forward
3902 (concat "^" (regexp-quote (car afters
)) ":")
3906 (re-search-forward "^[^ \t]" nil
'move
)
3907 (beginning-of-line))
3908 (insert header
": \n")
3912 (defun message-remove-signature ()
3913 "Remove the signature from the text between point and mark.
3914 The text will also be indented the normal way."
3916 (let ((start (point))
3918 (if (not (re-search-forward message-signature-separator
(mark t
) t
))
3919 ;; No signature here, so we just indent the cited text.
3920 (message-indent-citation)
3921 ;; Find the last non-empty line.
3923 (while (looking-at "[ \t]*$")
3926 (setq mark
(set-marker (make-marker) (point)))
3928 (message-indent-citation)
3929 ;; Enable undoing the deletion.
3931 (delete-region mark
(mark t
))
3932 (set-marker mark nil
)))))
3937 ;;; Sending messages
3940 (defun message-send-and-exit (&optional arg
)
3941 "Send message like `message-send', then, if no errors, exit from mail buffer."
3943 (let ((buf (current-buffer))
3944 (actions message-exit-actions
))
3945 (when (and (message-send arg
)
3947 (if message-kill-buffer-on-exit
3950 (when (eq buf
(current-buffer))
3951 (message-bury buf
)))
3952 (message-do-actions actions
)
3955 (defun message-dont-send ()
3956 "Don't send the message you have been editing.
3957 Instead, just auto-save the buffer and then bury it."
3959 (set-buffer-modified-p t
)
3961 (let ((actions message-postpone-actions
))
3962 (message-bury (current-buffer))
3963 (message-do-actions actions
)))
3965 (defun message-kill-buffer ()
3966 "Kill the current buffer."
3968 (when (or (not (buffer-modified-p))
3969 (not message-kill-buffer-query
)
3970 (yes-or-no-p "Message modified; kill anyway? "))
3971 (let ((actions message-kill-actions
)
3972 (draft-article message-draft-article
)
3973 (auto-save-file-name buffer-auto-save-file-name
)
3974 (file-name buffer-file-name
)
3975 (modified (buffer-modified-p)))
3976 (setq buffer-file-name nil
)
3977 (kill-buffer (current-buffer))
3978 (when (and (or (and auto-save-file-name
3979 (file-exists-p auto-save-file-name
))
3981 (file-exists-p file-name
)))
3983 ;; If the message buffer has lived in a dedicated window,
3984 ;; `kill-buffer' has killed the frame. Thus the
3985 ;; `yes-or-no-p' may show up in a lowered frame. Make sure
3986 ;; that the user can see the question by raising the
3989 (yes-or-no-p (format "Remove the backup file%s? "
3990 (if modified
" too" "")))))
3992 (delete-file auto-save-file-name
))
3993 (let ((message-draft-article draft-article
))
3994 (message-disassociate-draft)))
3995 (message-do-actions actions
))))
3997 (defun message-bury (buffer)
3998 "Bury this mail BUFFER."
3999 (let ((newbuf (other-buffer buffer
)))
4000 (bury-buffer buffer
)
4001 (if (and (window-dedicated-p (selected-window))
4002 (not (null (delq (selected-frame) (visible-frame-list)))))
4003 (delete-frame (selected-frame))
4004 (switch-to-buffer newbuf
))))
4006 (defun message-send (&optional arg
)
4007 "Send the message in the current buffer.
4008 If `message-interactive' is non-nil, wait for success indication or
4009 error messages, and inform user.
4010 Otherwise any failure is reported in a message back to the user from
4012 The usage of ARG is defined by the instance that called Message.
4013 It should typically alter the sending method in some way or other."
4015 ;; Make it possible to undo the coming changes.
4017 (let ((inhibit-read-only t
))
4018 (put-text-property (point-min) (point-max) 'read-only nil
))
4019 (message-fix-before-sending)
4020 (run-hooks 'message-send-hook
)
4021 (when message-confirm-send
4022 (or (y-or-n-p "Send message? ")
4024 (message message-sending-message
)
4025 (let ((alist message-send-method-alist
)
4027 elem sent dont-barf-on-no-method
4028 (message-options message-options
))
4029 (message-options-set-recipient)
4031 (setq elem
(pop alist
)))
4032 (when (funcall (cadr elem
))
4033 (when (and (or (not (memq (car elem
)
4034 message-sent-message-via
))
4035 (message-fetch-field "supersedes")
4036 (if (or (message-gnksa-enable-p 'multiple-copies
)
4037 (not (eq (car elem
) 'news
)))
4040 "Already sent message via %s; resend? "
4042 (error "Denied posting -- multiple copies")))
4043 (setq success
(funcall (caddr elem
) arg
)))
4047 (let ((fcc (message-fetch-field "Fcc"))
4048 (gcc (message-fetch-field "Gcc")))
4050 (or (eq message-allow-no-recipients
'always
)
4051 (and (not (eq message-allow-no-recipients
'never
))
4052 (setq dont-barf-on-no-method
4054 (format "No receiver, perform %s anyway? "
4055 (cond ((and fcc gcc
) "Fcc and Gcc")
4058 (error "No methods specified to send by"))
4059 (when (or dont-barf-on-no-method
4063 (run-hooks 'message-sent-hook
))
4064 (message "Sending...done")
4065 ;; Do ecomplete address snarfing.
4066 (when (and (message-mail-alias-type-p 'ecomplete
)
4067 (not message-inhibit-ecomplete
))
4068 (message-put-addresses-in-ecomplete))
4069 ;; Mark the buffer as unmodified and delete auto-save.
4070 (set-buffer-modified-p nil
)
4071 (delete-auto-save-file-if-necessary t
)
4072 (message-disassociate-draft)
4073 ;; Delete other mail buffers and stuff.
4074 (message-do-send-housekeeping)
4075 (message-do-actions message-send-actions
)
4079 (defun message-send-via-mail (arg)
4080 "Send the current message via mail."
4081 (message-send-mail arg
))
4083 (defun message-send-via-news (arg)
4084 "Send the current message via news."
4085 (funcall message-send-news-function arg
))
4087 (defmacro message-check
(type &rest forms
)
4088 "Eval FORMS if TYPE is to be checked."
4089 `(or (message-check-element ,type
)
4093 (put 'message-check
'lisp-indent-function
1)
4094 (put 'message-check
'edebug-form-spec
'(form body
))
4096 (defun message-text-with-property (prop &optional start end reverse
)
4097 "Return a list of start and end positions where the text has PROP.
4098 START and END bound the search, they default to `point-min' and
4099 `point-max' respectively. If REVERSE is non-nil, find text which does
4102 (setq start
(point-min)))
4104 (setq end
(point-max)))
4108 (setq start
(text-property-any start end prop nil
)))
4109 (setq next
(next-single-property-change start prop nil end
))
4110 (push (cons start
(or next end
)) regions
)
4113 (or (get-text-property start prop
)
4114 (and (setq start
(next-single-property-change
4115 start prop nil end
))
4116 (get-text-property start prop
))))
4117 (setq next
(text-property-any start end prop nil
))
4118 (push (cons start
(or next end
)) regions
)
4120 (nreverse regions
)))
4122 (defcustom message-bogus-addresses
4123 ;; '("noreply" "nospam" "invalid")
4124 '("noreply" "nospam" "invalid" "@@" "[^[:ascii:]].*@" "[ \t]")
4125 "List of regexps of potentially bogus mail addresses.
4126 See `message-check-recipients' how to setup checking.
4128 This list should make it possible to catch typos or warn about
4129 spam-trap addresses. It doesn't aim to verify strict RFC
4131 :version
"23.1" ;; No Gnus
4132 :group
'message-headers
4134 (const :tag
"None" nil
)
4140 (const :tag
"duplicate @" "@@")
4141 (const :tag
"non-ascii local part" "[^[:ascii:]].*@")
4142 ;; Already caught by `message-valid-fqdn-regexp'
4143 ;; (const :tag "`_' in domain part" "@.*_")
4144 (const :tag
"whitespace" "[ \t]"))
4149 (defun message-fix-before-sending ()
4150 "Do various things to make the message nice before sending it."
4151 ;; Make sure there's a newline at the end of the message.
4152 (goto-char (point-max))
4155 ;; Make the hidden headers visible.
4157 ;; Sort headers before sending the message.
4158 (message-sort-headers)
4159 ;; Make invisible text visible.
4160 ;; It doesn't seem as if this is useful, since the invisible property
4161 ;; is clobbered by an after-change hook anyhow.
4162 (message-check 'invisible-text
4163 (let ((regions (message-text-with-property 'invisible
))
4167 (setq from
(caar regions
)
4169 regions
(cdr regions
))
4170 (put-text-property from to
'invisible nil
)
4171 (message-overlay-put (message-make-overlay from to
)
4173 (unless (yes-or-no-p
4174 "Invisible text found and made visible; continue sending? ")
4175 (error "Invisible text found and made visible")))))
4176 (message-check 'illegible-text
4177 (let (char found choice
)
4180 (skip-chars-forward mm-7bit-chars
)
4181 (when (get-text-property (point) 'no-illegible-text
)
4182 ;; There is a signed or encrypted raw message part
4183 ;; that is considered to be safe.
4184 (goto-char (or (next-single-property-change
4185 (point) 'no-illegible-text
)
4187 (setq char
(char-after)))
4188 (when (or (< (mm-char-int char
) 128)
4189 (and (mm-multibyte-p)
4190 (memq (char-charset char
)
4191 '(eight-bit-control eight-bit-graphic
4192 ;; Emacs 23, Bug#1770:
4195 (not (get-text-property
4196 (point) 'untranslated-utf-8
))))
4197 (message-overlay-put (message-make-overlay (point) (1+ (point)))
4203 (gnus-multiple-choice
4204 "Non-printable characters found. Continue sending?"
4205 `((?d
"Remove non-printable characters and send")
4207 "Replace non-printable characters with \"%s\" and send"
4208 message-replacement-char
))
4209 (?i
"Ignore non-printable characters and send")
4210 (?e
"Continue editing"))))
4212 (error "Non-printable characters"))
4214 (skip-chars-forward mm-7bit-chars
)
4216 (when (let ((char (char-after)))
4217 (or (< (mm-char-int char
) 128)
4218 (and (mm-multibyte-p)
4219 ;; FIXME: Wrong for Emacs 23 (unicode) and for
4220 ;; things like undecodable utf-8 (in Emacs 21?).
4221 ;; Should at least use find-coding-systems-region.
4223 (memq (char-charset char
)
4224 '(eight-bit-control eight-bit-graphic
4225 ;; Emacs 23, Bug#1770:
4228 (not (get-text-property
4229 (point) 'untranslated-utf-8
)))))
4231 (message-kill-all-overlays)
4233 (when (eq choice ?r
)
4234 (insert message-replacement-char
))))
4236 (skip-chars-forward mm-7bit-chars
)))))
4237 (message-check 'bogus-recipient
4238 ;; Warn before sending a mail to an invalid address.
4239 (message-check-recipients)))
4241 (defun message-bogus-recipient-p (recipients)
4242 "Check if a mail address in RECIPIENTS looks bogus.
4244 RECIPIENTS is a mail header. Return a list of potentially bogus
4245 addresses. If none is found, return nil.
4247 An address might be bogus if the domain part is not fully
4248 qualified, see `message-valid-fqdn-regexp', or if there's a
4249 matching entry in `message-bogus-addresses'."
4250 ;; FIXME: How about "foo@subdomain", when the MTA adds ".domain.tld"?
4252 (mapc (lambda (address)
4253 (setq address
(cadr address
))
4257 (not (string-match "@" address
))
4260 message-valid-fqdn-regexp
"\\)\\'") address
)))
4261 (and message-bogus-addresses
4263 (if (listp message-bogus-addresses
)
4264 (mapconcat 'identity
4265 message-bogus-addresses
4267 message-bogus-addresses
)))
4268 (string-match re address
))))
4269 (push address found
)))
4271 (mail-extract-address-components recipients t
))
4274 (defun message-check-recipients ()
4275 "Warn before composing or sending a mail to an invalid address.
4277 This function could be useful in `message-setup-hook'."
4280 (message-narrow-to-headers)
4281 (dolist (hdr '("To" "Cc" "Bcc"))
4282 (let ((addr (message-fetch-field hdr
)))
4283 (when (stringp addr
)
4284 (dolist (bog (message-bogus-recipient-p addr
))
4288 "Address `%s' might be bogus. Continue? " bog
)))
4289 (error "Bogus address"))))))))
4291 (custom-add-option 'message-setup-hook
'message-check-recipients
)
4293 (defun message-add-action (action &rest types
)
4294 "Add ACTION to be performed when doing an exit of type TYPES."
4296 (add-to-list (intern (format "message-%s-actions" (pop types
)))
4299 (defun message-delete-action (action &rest types
)
4300 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
4303 (set (setq var
(intern (format "message-%s-actions" (pop types
))))
4304 (delq action
(symbol-value var
))))))
4306 (defun message-do-actions (actions)
4307 "Perform all actions in ACTIONS."
4308 ;; Now perform actions on successful sending.
4309 (dolist (action actions
)
4312 ;; A simple function.
4315 ;; Something to be evaled.
4319 (defun message-send-mail-partially ()
4320 "Send mail as message/partial."
4321 ;; replace the header delimiter with a blank line
4322 (goto-char (point-min))
4324 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4325 (replace-match "\n")
4326 (run-hooks 'message-send-mail-hook
)
4327 (let ((p (goto-char (point-min)))
4328 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
4329 (curbuf (current-buffer))
4330 (id (message-make-message-id)) (n 1)
4331 plist total header required-mail-headers
)
4333 (if (< (point-max) (+ p message-send-mail-partially-limit
))
4334 (goto-char (point-max))
4335 (goto-char (+ p message-send-mail-partially-limit
))
4337 (if (<= (point) p
) (forward-line 1))) ;; In case of bad message.
4340 (setq total
(length plist
))
4341 (push (point-max) plist
)
4342 (setq plist
(nreverse plist
))
4345 (setq p
(pop plist
))
4348 (copy-to-buffer tembuf p
(car plist
))
4350 (goto-char (point-min))
4353 (goto-char (point-min))
4354 (narrow-to-region (point) (point))
4357 (setq header
(buffer-substring (point-min) (point)))
4358 (goto-char (point-min))
4359 (narrow-to-region (point) (point))
4361 (message-remove-header "Mime-Version")
4362 (message-remove-header "Content-Type")
4363 (message-remove-header "Content-Transfer-Encoding")
4364 (message-remove-header "Message-ID")
4365 (message-remove-header "Lines")
4366 (goto-char (point-max))
4367 (insert "Mime-Version: 1.0\n")
4368 (setq header
(buffer-string)))
4369 (goto-char (point-max))
4370 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
4373 (let ((mail-header-separator ""))
4374 (when (memq 'Message-ID message-required-mail-headers
)
4375 (insert "Message-ID: " (message-make-message-id) "\n"))
4376 (when (memq 'Lines message-required-mail-headers
)
4377 (insert "Lines: " (message-make-lines) "\n"))
4378 (message-goto-subject)
4380 (insert (format " (%d/%d)" n total
))
4382 (funcall (or message-send-mail-real-function
4383 message-send-mail-function
)))
4385 (setq p
(pop plist
))
4387 (kill-buffer tembuf
))))
4389 (declare-function hashcash-wait-async
"hashcash" (&optional buffer
))
4391 (defun message-send-mail (&optional arg
)
4392 (require 'mail-utils
)
4393 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
4394 (case-fold-search nil
)
4395 (news (message-news-p))
4396 (mailbuf (current-buffer))
4397 (message-this-is-mail t
)
4398 ;; gnus-setup-posting-charset is autoloaded in mml.el (FIXME
4399 ;; maybe it should not be), which this file requires. Hence
4400 ;; the fboundp test is always true. Loading it from gnus-msg
4401 ;; loads many Gnus files (Bug#5642). If
4402 ;; gnus-group-posting-charset-alist hasn't been customized,
4403 ;; this is just going to return nil anyway. FIXME it would
4404 ;; be good to improve this further, because even if g-g-p-c-a
4405 ;; has been customized, that is likely to just be for news.
4406 ;; Eg either move the definition from gnus-msg, or separate out
4407 ;; the mail and news parts.
4408 (message-posting-charset
4409 (if (and (fboundp 'gnus-setup-posting-charset
)
4410 (boundp 'gnus-group-posting-charset-alist
))
4411 (gnus-setup-posting-charset nil
)
4412 message-posting-charset
))
4413 (headers message-required-mail-headers
))
4414 (when (and message-generate-hashcash
4415 (not (eq message-generate-hashcash
'opportunistic
)))
4416 (message "Generating hashcash...")
4418 ;; Wait for calculations already started to finish...
4419 (hashcash-wait-async)
4420 ;; ...and do calculations not already done. mail-add-payment
4421 ;; will leave existing X-Hashcash headers alone.
4423 (message "Generating hashcash...done"))
4425 (message-narrow-to-headers)
4426 ;; Generate the Mail-Followup-To header if the header is not there...
4427 (if (and (message-subscribed-p)
4428 (not (mail-fetch-field "mail-followup-to")))
4431 (cons "Mail-Followup-To" (message-make-mail-followup-to))
4432 message-required-mail-headers
))
4433 ;; otherwise, delete the MFT header if the field is empty
4434 (when (equal "" (mail-fetch-field "mail-followup-to"))
4435 (message-remove-header "^Mail-Followup-To:")))
4436 ;; Insert some headers.
4437 (let ((message-deletable-headers
4438 (if news nil message-deletable-headers
)))
4439 (message-generate-headers headers
))
4440 ;; Check continuation headers.
4441 (message-check 'continuation-headers
4442 (goto-char (point-min))
4443 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t
)
4444 (goto-char (match-beginning 0))
4445 (if (y-or-n-p "Fix continuation lines? ")
4448 (unless (y-or-n-p "Send anyway? ")
4449 (error "Failed to send the message")))))
4450 ;; Let the user do all of the above.
4451 (run-hooks 'message-header-hook
))
4453 (with-current-buffer tembuf
4455 ;; Avoid copying text props (except hard newlines).
4456 (insert (with-current-buffer mailbuf
4457 (mml-buffer-substring-no-properties-except-hard-newlines
4458 (point-min) (point-max))))
4459 ;; Remove some headers.
4460 (message-encode-message-body)
4462 (message-narrow-to-headers)
4463 ;; We (re)generate the Lines header.
4464 (when (memq 'Lines message-required-mail-headers
)
4465 (message-generate-headers '(Lines)))
4466 ;; Remove some headers.
4467 (message-remove-header message-ignored-mail-headers t
)
4468 (let ((mail-parse-charset message-default-charset
))
4469 (mail-encode-encoded-word-buffer)))
4470 (goto-char (point-max))
4471 ;; require one newline at the end.
4472 (or (= (preceding-char) ?
\n)
4474 (message-cleanup-headers)
4475 ;; FIXME: we're inserting the courtesy copy after encoding.
4476 ;; This is wrong if the courtesy copy string contains
4477 ;; non-ASCII characters. -- jh
4480 (message-narrow-to-headers)
4482 (or (message-fetch-field "cc")
4483 (message-fetch-field "bcc")
4484 (message-fetch-field "to"))
4485 (let ((content-type (message-fetch-field
4490 (string= "text/plain"
4492 (mail-header-parse-content-type
4496 (message-fetch-field
4497 "content-transfer-encoding")))))))
4498 (message-insert-courtesy-copy))
4499 ;; Let's make sure we encoded all the body.
4500 (assert (save-excursion
4501 (goto-char (point-min))
4502 (not (re-search-forward "[^\000-\377]" nil t
))))
4503 (mm-disable-multibyte)
4504 (if (or (not message-send-mail-partially-limit
)
4505 (< (buffer-size) message-send-mail-partially-limit
)
4506 (not (message-y-or-n-p
4507 "The message size is too large, split? "
4511 (/ (buffer-size) 1000) "KB, is too large.
4513 Some mail gateways (MTA's) bounce large messages. To avoid the
4514 problem, answer `y', and the message will be split into several
4515 smaller pieces, the size of each is about "
4516 (/ message-send-mail-partially-limit
1000)
4520 However, some mail readers (MUA's) can't read split messages, i.e.,
4521 mails in message/partially format. Answer `n', and the message will be
4524 The size limit is controlled by `message-send-mail-partially-limit'.
4525 If you always want Gnus to send messages in one piece, set
4526 `message-send-mail-partially-limit' to nil.
4529 (message "Sending via mail...")
4530 (funcall (or message-send-mail-real-function
4531 message-send-mail-function
)))
4532 (message-send-mail-partially)))
4533 (kill-buffer tembuf
))
4534 (set-buffer mailbuf
)
4535 (push 'mail message-sent-message-via
)))
4537 (defun message-send-mail-with-sendmail ()
4538 "Send off the prepared buffer with sendmail."
4540 (let ((errbuf (if message-interactive
4541 (message-generate-new-buffer-clone-locals
4544 resend-to-addresses delimline
)
4547 (let ((case-fold-search t
))
4549 (message-narrow-to-headers)
4550 (setq resend-to-addresses
(message-fetch-field "resent-to")))
4551 ;; Change header-delimiter to be what sendmail expects.
4552 (goto-char (point-min))
4554 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4555 (replace-match "\n")
4557 (setq delimline
(point-marker))
4558 (run-hooks 'message-send-mail-hook
)
4559 ;; Insert an extra newline if we need it to work around
4560 ;; Sun's bug that swallows newlines.
4561 (goto-char (1+ delimline
))
4562 (when (eval message-mailer-swallows-blank-line
)
4564 (when message-interactive
4565 (with-current-buffer errbuf
4567 (let* ((default-directory "/")
4568 (coding-system-for-write message-send-coding-system
)
4570 'call-process-region
4572 (list (point-min) (point-max)
4573 (cond ((boundp 'sendmail-program
)
4575 ((file-exists-p "/usr/sbin/sendmail")
4576 "/usr/sbin/sendmail")
4577 ((file-exists-p "/usr/lib/sendmail")
4578 "/usr/lib/sendmail")
4579 ((file-exists-p "/usr/ucblib/sendmail")
4580 "/usr/ucblib/sendmail")
4582 nil errbuf nil
"-oi")
4583 message-sendmail-extra-arguments
4584 ;; Always specify who from,
4585 ;; since some systems have broken sendmails.
4586 ;; But some systems are more broken with -f, so
4587 ;; we'll let users override this.
4588 (and (null message-sendmail-f-is-evil
)
4589 (list "-f" (message-sendmail-envelope-from)))
4590 ;; These mean "report errors by mail"
4591 ;; and "deliver in background".
4592 (if (null message-interactive
) '("-oem" "-odb"))
4593 ;; Get the addresses from the message
4594 ;; unless this is a resend.
4595 ;; We must not do that for a resend
4596 ;; because we would find the original addresses.
4597 ;; For a resend, include the specific addresses.
4598 (if resend-to-addresses
4599 (list resend-to-addresses
)
4601 (unless (or (null cpr
) (and (numberp cpr
) (zerop cpr
)))
4602 (if errbuf
(pop-to-buffer errbuf
))
4603 (error "Sending...failed with exit value %d" cpr
)))
4604 (when message-interactive
4605 (with-current-buffer errbuf
4606 (goto-char (point-min))
4607 (while (re-search-forward "\n+ *" nil t
)
4608 (replace-match "; "))
4609 (if (not (zerop (buffer-size)))
4610 (error "Sending...failed to %s"
4611 (buffer-string))))))
4612 (when (bufferp errbuf
)
4613 (kill-buffer errbuf
)))))
4615 (defun message-send-mail-with-qmail ()
4616 "Pass the prepared message buffer to qmail-inject.
4617 Refer to the documentation for the variable `message-send-mail-function'
4618 to find out how to use this."
4619 ;; replace the header delimiter with a blank line
4620 (goto-char (point-min))
4622 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4623 (replace-match "\n")
4624 (run-hooks 'message-send-mail-hook
)
4627 (let ((coding-system-for-write message-send-coding-system
))
4629 'call-process-region
(point-min) (point-max)
4630 message-qmail-inject-program nil nil nil
4631 ;; qmail-inject's default behavior is to look for addresses on the
4632 ;; command line; if there're none, it scans the headers.
4633 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4635 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4636 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4637 ;; message from stdin.
4639 ;; qmail also has the advantage of not having been raped by
4640 ;; various vendors, so we don't have to allow for that, either --
4641 ;; compare this with message-send-mail-with-sendmail and weep
4642 ;; for sendmail's lost innocence.
4644 ;; all this is way cool coz it lets us keep the arguments entirely
4645 ;; free for -inject-arguments -- a big win for the user and for us
4646 ;; since we don't have to play that double-guessing game and the user
4647 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4648 (if (functionp message-qmail-inject-args
)
4649 (funcall message-qmail-inject-args
)
4650 message-qmail-inject-args
)))
4651 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4652 ;; we have to look at the retval instead
4654 (100 (error "qmail-inject reported permanent failure"))
4655 (111 (error "qmail-inject reported transient failure"))
4656 ;; should never happen
4657 (t (error "qmail-inject reported unknown failure"))))
4659 (defun message-send-mail-with-mh ()
4660 "Send the prepared message buffer with mh."
4661 (let ((mh-previous-window-config nil
)
4662 (name (mh-new-draft-name)))
4663 (setq buffer-file-name name
)
4664 ;; MH wants to generate these headers itself.
4665 (when message-mh-deletable-headers
4666 (let ((headers message-mh-deletable-headers
))
4668 (goto-char (point-min))
4669 (and (re-search-forward
4670 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
4671 (message-delete-line))
4673 (run-hooks 'message-send-mail-hook
)
4674 ;; Pass it on to mh.
4677 (defun message-smtpmail-send-it ()
4678 "Send the prepared message buffer with `smtpmail-send-it'.
4679 The only difference from `smtpmail-send-it' is that this command
4680 evaluates `message-send-mail-hook' just before sending a message.
4681 It is useful if your ISP requires the POP-before-SMTP
4682 authentication. See the Gnus manual for details."
4683 (run-hooks 'message-send-mail-hook
)
4686 (defun message-send-mail-with-mailclient ()
4687 "Send the prepared message buffer with `mailclient-send-it'.
4688 The only difference from `mailclient-send-it' is that this
4689 command evaluates `message-send-mail-hook' just before sending a message."
4690 (run-hooks 'message-send-mail-hook
)
4691 (mailclient-send-it))
4693 (defun message-canlock-generate ()
4694 "Return a string that is non-trivial to guess.
4695 Do not use this for anything important, it is cryptographically weak."
4697 (let (sha1-maximum-internal-length)
4698 (sha1 (concat (message-unique-id)
4699 (format "%x%x%x" (random) (random t
) (random))
4700 (prin1-to-string (recent-keys))
4701 (prin1-to-string (garbage-collect))))))
4703 (defvar canlock-password
)
4704 (defvar canlock-password-for-verify
)
4706 (defun message-canlock-password ()
4707 "The password used by message for cancel locks.
4708 This is the value of `canlock-password', if that option is non-nil.
4709 Otherwise, generate and save a value for `canlock-password' first."
4711 (unless canlock-password
4712 (customize-save-variable 'canlock-password
(message-canlock-generate))
4713 (setq canlock-password-for-verify canlock-password
))
4716 (defun message-insert-canlock ()
4717 (when message-insert-canlock
4718 (message-canlock-password)
4719 (canlock-insert-header)))
4721 (autoload 'nnheader-get-report
"nnheader")
4723 (declare-function gnus-setup-posting-charset
"gnus-msg" (group))
4725 (defun message-send-news (&optional arg
)
4727 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4728 (case-fold-search nil
)
4729 (method (if (functionp message-post-method
)
4730 (funcall message-post-method arg
)
4731 message-post-method
))
4732 (newsgroups-field (save-restriction
4733 (message-narrow-to-headers-or-head)
4734 (message-fetch-field "Newsgroups")))
4735 (followup-field (save-restriction
4736 (message-narrow-to-headers-or-head)
4737 (message-fetch-field "Followup-To")))
4738 ;; BUG: We really need to get the charset for each name in the
4739 ;; Newsgroups and Followup-To lines to allow crossposting
4740 ;; between group namess with incompatible character sets.
4741 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4742 (group-field-charset
4743 (gnus-group-name-charset method newsgroups-field
))
4744 (followup-field-charset
4745 (gnus-group-name-charset method
(or followup-field
"")))
4746 (rfc2047-header-encoding-alist
4747 (append (when group-field-charset
4748 (list (cons "Newsgroups" group-field-charset
)))
4749 (when followup-field-charset
4750 (list (cons "Followup-To" followup-field-charset
)))
4751 rfc2047-header-encoding-alist
))
4752 (messbuf (current-buffer))
4753 (message-syntax-checks
4755 (listp message-syntax-checks
))
4756 (cons '(existing-newsgroups . disabled
)
4757 message-syntax-checks
)
4758 message-syntax-checks
))
4759 (message-this-is-news t
)
4760 (message-posting-charset
4761 (gnus-setup-posting-charset newsgroups-field
))
4763 (if (not (message-check-news-body-syntax))
4766 (message-narrow-to-headers)
4767 ;; Insert some headers.
4768 (message-generate-headers message-required-news-headers
)
4769 (message-insert-canlock)
4770 ;; Let the user do all of the above.
4771 (run-hooks 'message-header-hook
))
4772 ;; Note: This check will be disabled by the ".*" default value for
4773 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4774 (when (and group-field-charset
4775 (listp message-syntax-checks
))
4776 (setq message-syntax-checks
4777 (cons '(valid-newsgroups . disabled
)
4778 message-syntax-checks
)))
4779 (message-cleanup-headers)
4780 (if (not (let ((message-post-method method
))
4781 (message-check-news-syntax)))
4784 (with-current-buffer tembuf
4785 (buffer-disable-undo)
4787 ;; Avoid copying text props (except hard newlines).
4789 (with-current-buffer messbuf
4790 (mml-buffer-substring-no-properties-except-hard-newlines
4791 (point-min) (point-max))))
4792 (message-encode-message-body)
4793 ;; Remove some headers.
4795 (message-narrow-to-headers)
4796 ;; We (re)generate the Lines header.
4797 (when (memq 'Lines message-required-mail-headers
)
4798 (message-generate-headers '(Lines)))
4799 ;; Remove some headers.
4800 (message-remove-header message-ignored-news-headers t
)
4801 (let ((mail-parse-charset message-default-charset
))
4802 (mail-encode-encoded-word-buffer)))
4803 (goto-char (point-max))
4804 ;; require one newline at the end.
4805 (or (= (preceding-char) ?
\n)
4807 (let ((case-fold-search t
))
4808 ;; Remove the delimiter.
4809 (goto-char (point-min))
4811 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4812 (replace-match "\n")
4814 (run-hooks 'message-send-news-hook
)
4815 (gnus-open-server method
)
4816 (message "Sending news via %s..." (gnus-server-string method
))
4817 (setq result
(let ((mail-header-separator ""))
4818 (gnus-request-post method
))))
4819 (kill-buffer tembuf
))
4820 (set-buffer messbuf
)
4822 (push 'news message-sent-message-via
)
4823 (message "Couldn't send message via news: %s"
4824 (nnheader-get-report (car method
)))
4828 ;;; Header generation & syntax checking.
4831 (defun message-check-element (type)
4832 "Return non-nil if this TYPE is not to be checked."
4833 (if (eq message-syntax-checks
'dont-check-for-anything-just-trust-me
)
4835 (let ((able (assq type message-syntax-checks
)))
4837 (eq (cdr able
) 'disabled
)))))
4839 (defun message-check-news-syntax ()
4840 "Check the syntax of the message."
4844 ;; We narrow to the headers and check them first.
4847 (message-narrow-to-headers)
4848 (message-check-news-header-syntax))))))
4850 (defun message-check-news-header-syntax ()
4852 ;; Check Newsgroups header.
4853 (message-check 'newsgroups
4854 (let ((group (message-fetch-field "newsgroups")))
4857 (not (string-match "\\`[ \t]*\\'" group
)))
4860 "The newsgroups field is empty or missing. Posting is denied.")))))
4861 ;; Check the Subject header.
4862 (message-check 'subject
4863 (let* ((case-fold-search t
)
4864 (subject (message-fetch-field "subject")))
4867 (not (string-match "\\`[ \t]*\\'" subject
)))
4870 "The subject field is empty or missing. Posting is denied.")))))
4871 ;; Check for commands in Subject.
4872 (message-check 'subject-cmsg
4873 (if (string-match "^cmsg " (message-fetch-field "subject"))
4875 "The control code \"cmsg\" is in the subject. Really post? ")
4877 ;; Check long header lines.
4878 (message-check 'long-header-lines
4879 (let ((start (point))
4883 (while (and (not found
)
4884 (re-search-forward "^\\([^ \t:]+\\): " nil t
))
4885 (if (> (- (point) (match-beginning 0)) 998)
4887 length
(- (point) (match-beginning 0)))
4888 (setq header
(match-string-no-properties 1)))
4889 (setq start
(match-beginning 0))
4892 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
4895 ;; Check for multiple identical headers.
4896 (message-check 'multiple-headers
4898 (while (and (not found
)
4899 (re-search-forward "^[^ \t:]+: " nil t
))
4901 (or (re-search-forward
4906 (match-beginning 0) (- (match-end 0) 2))))
4911 (y-or-n-p (format "Multiple %s headers. Really post? " found
))
4913 ;; Check for Version and Sendsys.
4914 (message-check 'sendsys
4915 (if (re-search-forward "^Sendsys:\\|^Version:" nil t
)
4917 (format "The article contains a %s command. Really post? "
4918 (buffer-substring (match-beginning 0)
4919 (1- (match-end 0)))))
4921 ;; See whether we can shorten Followup-To.
4922 (message-check 'shorten-followup-to
4923 (let ((newsgroups (message-fetch-field "newsgroups"))
4924 (followup-to (message-fetch-field "followup-to"))
4926 (when (and newsgroups
4927 (string-match "," newsgroups
)
4932 (setq to
(completing-read
4933 "Followups to (default no Followup-To header): "
4936 (message-tokenize-header
4938 (goto-char (point-min))
4939 (insert "Followup-To: " to
"\n"))
4941 ;; Check "Shoot me".
4942 (message-check 'shoot
4943 (if (re-search-forward
4944 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t
)
4945 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
4947 ;; Check for Approved.
4948 (message-check 'approved
4949 (if (re-search-forward "^Approved:" nil t
)
4950 (y-or-n-p "The article contains an Approved header. Really post? ")
4952 ;; Check the Message-ID header.
4953 (message-check 'message-id
4954 (let* ((case-fold-search t
)
4955 (message-id (message-fetch-field "message-id" t
)))
4956 (or (not message-id
)
4957 ;; Is there an @ in the ID?
4958 (and (string-match "@" message-id
)
4959 ;; Is there a dot in the ID?
4960 (string-match "@[^.]*\\." message-id
)
4961 ;; Does the ID end with a dot?
4962 (not (string-match "\\.>" message-id
)))
4964 (format "The Message-ID looks strange: \"%s\". Really post? "
4966 ;; Check the Newsgroups & Followup-To headers.
4967 (message-check 'existing-newsgroups
4968 (let* ((case-fold-search t
)
4969 (newsgroups (message-fetch-field "newsgroups"))
4970 (followup-to (message-fetch-field "followup-to"))
4971 (groups (message-tokenize-header
4973 (concat newsgroups
"," followup-to
)
4975 (post-method (if (functionp message-post-method
)
4976 (funcall message-post-method
)
4977 message-post-method
))
4978 ;; KLUDGE to handle nnvirtual groups. Doing this right
4979 ;; would probably involve a new nnoo function.
4980 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
4981 (method (if (and (consp post-method
)
4982 (eq (car post-method
) 'nnvirtual
)
4983 gnus-message-group-art
)
4984 (let ((group (car (nnvirtual-find-group-art
4985 (car gnus-message-group-art
)
4986 (cdr gnus-message-group-art
)))))
4987 (gnus-find-method-for-group group
))
4991 (gnus-group-name-decode
4992 (gnus-group-real-name n
)
4993 (gnus-group-name-charset method n
)))
4994 (gnus-groups-from-server method
)))
4997 (when (and (not (equal (car groups
) "poster"))
4998 (not (member (car groups
) known-groups
))
4999 (not (member (car groups
) errors
)))
5000 (push (car groups
) errors
))
5003 ;; Gnus is not running.
5004 ((or (not (and (boundp 'gnus-active-hashtb
)
5005 gnus-active-hashtb
))
5006 (not (boundp 'gnus-read-active-file
)))
5008 ;; We don't have all the group names.
5009 ((and (or (not gnus-read-active-file
)
5010 (eq gnus-read-active-file
'some
))
5014 "Really use %s possibly unknown group%s: %s? "
5015 (if (= (length errors
) 1) "this" "these")
5016 (if (= (length errors
) 1) "" "s")
5017 (mapconcat 'identity errors
", "))))
5018 ;; There were no errors.
5021 ;; There are unknown groups.
5025 "Really post to %s unknown group%s: %s? "
5026 (if (= (length errors
) 1) "this" "these")
5027 (if (= (length errors
) 1) "" "s")
5028 (mapconcat 'identity errors
", ")))))))
5029 ;; Check continuation headers.
5030 (message-check 'continuation-headers
5031 (goto-char (point-min))
5032 (let ((do-posting t
))
5033 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t
)
5034 (goto-char (match-beginning 0))
5035 (if (y-or-n-p "Fix continuation lines? ")
5038 (unless (y-or-n-p "Send anyway? ")
5039 (setq do-posting nil
))))
5041 ;; Check the Newsgroups & Followup-To headers for syntax errors.
5042 (message-check 'valid-newsgroups
5043 (let ((case-fold-search t
)
5044 (headers '("Newsgroups" "Followup-To"))
5046 (while (and headers
(not error
))
5047 (when (setq header
(mail-fetch-field (car headers
)))
5051 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
5056 (not (string-match "\\.\\'\\|\\.\\." g
)))
5057 (message-tokenize-header header
","))))
5064 (format "The %s header looks odd: \"%s\". Really post? "
5065 (car headers
) header
)))))
5066 (message-check 'repeated-newsgroups
5067 (let ((case-fold-search t
)
5068 (headers '("Newsgroups" "Followup-To"))
5069 header error groups group
)
5072 (when (setq header
(mail-fetch-field (pop headers
)))
5073 (setq groups
(message-tokenize-header header
","))
5074 (while (setq group
(pop groups
))
5075 (when (member group groups
)
5081 (format "Group %s is repeated in headers. Really post? " error
)))))
5082 ;; Check the From header.
5083 (message-check 'from
5084 (let* ((case-fold-search t
)
5085 (from (message-fetch-field "from"))
5089 (message "There is no From line. Posting is denied.")
5091 ((or (not (string-match
5093 (setq ad
(nth 1 (mail-extract-address-components
5094 from
))))) ;larsi@ifi
5095 (string-match "\\.\\." ad
) ;larsi@ifi..uio
5096 (string-match "@\\." ad
) ;larsi@.ifi.uio
5097 (string-match "\\.$" ad
) ;larsi@ifi.uio.
5098 (not (string-match "^[^@]+@[^@]+$" ad
)) ;larsi.ifi.uio
5099 (string-match "(.*).*(.*)" from
)) ;(lars) (lars)
5101 "Denied posting -- the From looks strange: \"%s\"." from
)
5103 ((let ((addresses (rfc822-addresses from
)))
5104 ;; `rfc822-addresses' returns a string if parsing fails.
5105 (while (and (consp addresses
)
5106 (not (eq (string-to-char (car addresses
)) ?\
()))
5107 (setq addresses
(cdr addresses
)))
5110 "Denied posting -- bad From address: \"%s\"." from
)
5113 ;; Check the Reply-To header.
5114 (message-check 'reply-to
5115 (let* ((case-fold-search t
)
5116 (reply-to (message-fetch-field "reply-to"))
5121 ((string-match "," reply-to
)
5123 (format "Multiple Reply-To addresses: \"%s\". Really post? "
5125 ((or (not (string-match
5127 (setq ad
(nth 1 (mail-extract-address-components
5128 reply-to
))))) ;larsi@ifi
5129 (string-match "\\.\\." ad
) ;larsi@ifi..uio
5130 (string-match "@\\." ad
) ;larsi@.ifi.uio
5131 (string-match "\\.$" ad
) ;larsi@ifi.uio.
5132 (not (string-match "^[^@]+@[^@]+$" ad
)) ;larsi.ifi.uio
5133 (string-match "(.*).*(.*)" reply-to
)) ;(lars) (lars)
5136 "The Reply-To looks strange: \"%s\". Really post? "
5140 (defun message-check-news-body-syntax ()
5142 ;; Check for long lines.
5143 (message-check 'long-lines
5144 (goto-char (point-min))
5146 (concat "^" (regexp-quote mail-header-separator
) "$"))
5150 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
5153 (< (- (point) p
) 80)))
5154 (zerop (forward-line 1))))
5158 "You have lines longer than 79 characters. Really post? ")))
5159 ;; Check whether the article is empty.
5160 (message-check 'empty
5161 (goto-char (point-min))
5163 (concat "^" (regexp-quote mail-header-separator
) "$"))
5166 (goto-char (point-max))
5167 (re-search-backward message-signature-separator nil t
)
5169 (or (re-search-backward "[^ \n\t]" b t
)
5170 (if (message-gnksa-enable-p 'empty-article
)
5171 (y-or-n-p "Empty article. Really post? ")
5172 (message "Denied posting -- Empty article.")
5174 ;; Check for control characters.
5175 (message-check 'control-chars
5176 (if (re-search-forward
5177 (mm-string-to-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
5180 "The article contains control characters. Really post? ")
5182 ;; Check excessive size.
5183 (message-check 'size
5184 (if (> (buffer-size) 60000)
5186 (format "The article is %d octets long. Really post? "
5189 ;; Check whether any new text has been added.
5190 (message-check 'new-text
5192 (not message-checksum
)
5193 (not (eq (message-checksum) message-checksum
))
5194 (if (message-gnksa-enable-p 'quoted-text-only
)
5196 "It looks like no new text has been added. Really post? ")
5197 (message "Denied posting -- no new text has been added.")
5199 ;; Check the length of the signature.
5200 (message-check 'signature
5201 (let (sig-start sig-end
)
5202 (goto-char (point-max))
5203 (if (not (re-search-backward message-signature-separator nil t
))
5205 (setq sig-start
(1+ (point-at-eol)))
5207 (if (re-search-forward
5208 "<#/?\\(multipart\\|part\\|external\\|mml\\)" nil t
)
5209 (- (point-at-bol) 1)
5211 (if (>= (count-lines sig-start sig-end
) 5)
5212 (if (message-gnksa-enable-p 'signature
)
5214 (format "Signature is excessively long (%d lines). Really post? "
5215 (count-lines sig-start sig-end
)))
5216 (message "Denied posting -- Excessive signature.")
5219 ;; Ensure that text follows last quoted portion.
5220 (message-check 'quoting-style
5221 (goto-char (point-max))
5222 (let ((no-problem t
))
5223 (when (search-backward-regexp "^>[^\n]*\n" nil t
)
5224 (setq no-problem
(search-forward-regexp "^[ \t]*[^>\n]" nil t
)))
5227 (if (message-gnksa-enable-p 'quoted-text-only
)
5228 (y-or-n-p "Your text should follow quoted text. Really post? ")
5230 (goto-char (point-min))
5232 (concat "^" (regexp-quote mail-header-separator
) "$"))
5233 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t
)
5234 (y-or-n-p "Your text should follow quoted text. Really post? ")
5235 (message "Denied posting -- only quoted text.")
5238 (defun message-checksum ()
5239 "Return a \"checksum\" for the current buffer."
5242 (goto-char (point-min))
5244 (concat "^" (regexp-quote mail-header-separator
) "$"))
5246 (when (not (looking-at "[ \t\n]"))
5247 (setq sum
(logxor (ash sum
1) (if (natnump sum
) 0 1)
5252 (defun message-do-fcc ()
5253 "Process Fcc headers in the current buffer."
5254 (let ((case-fold-search t
)
5255 (buf (current-buffer))
5257 (mml-externalize-attachments message-fcc-externalize-attachments
))
5260 (message-narrow-to-headers)
5261 (setq file
(message-fetch-field "fcc" t
)))
5263 (set-buffer (get-buffer-create " *message temp*"))
5265 (insert-buffer-substring buf
)
5266 (message-encode-message-body)
5268 (message-narrow-to-headers)
5269 (while (setq file
(message-fetch-field "fcc" t
))
5271 (message-remove-header "fcc" nil t
))
5272 (let ((mail-parse-charset message-default-charset
)
5273 (rfc2047-header-encoding-alist
5274 (cons '("Newsgroups" . default
)
5275 rfc2047-header-encoding-alist
)))
5276 (mail-encode-encoded-word-buffer)))
5277 (goto-char (point-min))
5278 (when (re-search-forward
5279 (concat "^" (regexp-quote mail-header-separator
) "$")
5281 (replace-match "" t t
))
5282 ;; Process FCC operations.
5284 (setq file
(pop list
))
5285 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file
)
5286 ;; Pipe the article to the program in question.
5287 (call-process-region (point-min) (point-max) shell-file-name
5288 nil nil nil shell-command-switch
5289 (match-string 1 file
))
5290 ;; Save the article.
5291 (setq file
(expand-file-name file
))
5292 (unless (file-exists-p (file-name-directory file
))
5293 (make-directory (file-name-directory file
) t
))
5294 (if (and message-fcc-handler-function
5295 (not (eq message-fcc-handler-function
'rmail-output
)))
5296 (funcall message-fcc-handler-function file
)
5297 ;; FIXME this option, rmail-output (also used if
5298 ;; message-fcc-handler-function is nil) is not
5299 ;; documented anywhere AFAICS. It should work in Emacs
5300 ;; 23; I suspect it does not work in Emacs 22.
5301 ;; FIXME I don't see the need for the two different cases here.
5302 ;; mail-use-rfc822 makes no difference (in Emacs 23),and
5303 ;; the third argument just controls \"Wrote file\" message.
5304 (if (and (file-readable-p file
) (mail-file-babyl-p file
))
5305 (rmail-output file
1 nil t
)
5306 (let ((mail-use-rfc822 t
))
5307 (rmail-output file
1 t t
))))))
5308 (kill-buffer (current-buffer))))))
5310 (defun message-output (filename)
5311 "Append this article to Unix/babyl mail file FILENAME."
5312 (if (or (and (file-readable-p filename
)
5313 (mail-file-babyl-p filename
))
5314 ;; gnus-output-to-mail does the wrong thing with live, mbox
5315 ;; Rmail buffers in Emacs 23.
5316 ;; http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=597255
5317 (let ((buff (find-buffer-visiting filename
)))
5318 (and buff
(with-current-buffer buff
5319 (eq major-mode
'rmail-mode
)))))
5320 (gnus-output-to-rmail filename t
)
5321 (gnus-output-to-mail filename t
)))
5323 (defun message-cleanup-headers ()
5324 "Do various automatic cleanups of the headers."
5325 ;; Remove empty lines in the header.
5327 (message-narrow-to-headers)
5328 ;; Remove blank lines.
5329 (while (re-search-forward "^[ \t]*\n" nil t
)
5330 (replace-match "" t t
))
5332 ;; Correct Newsgroups and Followup-To headers: Change sequence of
5333 ;; spaces to comma and eliminate spaces around commas. Eliminate
5334 ;; embedded line breaks.
5335 (goto-char (point-min))
5336 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t
)
5340 (if (re-search-forward "^[^ \t]" nil t
)
5344 (goto-char (point-min))
5345 (while (re-search-forward "\n[ \t]+" nil t
)
5346 (replace-match " " t t
)) ;No line breaks (too confusing)
5347 (goto-char (point-min))
5348 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t
)
5349 (replace-match "," t t
))
5350 (goto-char (point-min))
5351 ;; Remove trailing commas.
5352 (when (re-search-forward ",+$" nil t
)
5353 (replace-match "" t t
))))))
5355 (defun message-make-date (&optional now
)
5356 "Make a valid data header.
5357 If NOW, use that time instead."
5358 (let ((system-time-locale "C"))
5359 (format-time-string "%a, %d %b %Y %T %z" now
)))
5361 (defun message-insert-expires (days)
5362 "Insert the Expires header. Expiry in DAYS days."
5363 (interactive "NExpire article in how many days? ")
5365 (message-position-on-field "Expires" "X-Draft-From")
5366 (insert (message-make-expires-date days
))))
5368 (defun message-make-expires-date (days)
5369 "Make date string for the Expires header. Expiry in DAYS days.
5371 In posting styles use `(\"Expires\" (make-expires-date 30))'."
5372 (let* ((cur (decode-time (current-time)))
5373 (nday (+ days
(nth 3 cur
))))
5374 (setf (nth 3 cur
) nday
)
5375 (message-make-date (apply 'encode-time cur
))))
5377 (defun message-make-message-id ()
5378 "Make a unique Message-ID."
5379 (concat "<" (message-unique-id)
5380 (let ((psubject (save-excursion (message-fetch-field "subject")))
5382 (save-excursion (message-fetch-field "supersedes"))))
5384 (and message-reply-headers
5385 (mail-header-references message-reply-headers
)
5386 (mail-header-subject message-reply-headers
)
5389 (message-strip-subject-re
5390 (mail-header-subject message-reply-headers
))
5391 (message-strip-subject-re psubject
))))
5393 (string-match "_-_@" psupersedes
)))
5395 "@" (message-make-fqdn) ">"))
5397 (defvar message-unique-id-char nil
)
5399 ;; If you ever change this function, make sure the new version
5400 ;; cannot generate IDs that the old version could.
5401 ;; You might for example insert a "." somewhere (not next to another dot
5402 ;; or string boundary), or modify the "fsf" string.
5403 (defun message-unique-id ()
5404 ;; Don't use microseconds from (current-time), they may be unsupported.
5405 ;; Instead we use this randomly inited counter.
5406 (setq message-unique-id-char
5407 (%
(1+ (or message-unique-id-char
(logand (random t
) (1- (lsh 1 20)))))
5408 ;; (current-time) returns 16-bit ints,
5409 ;; and 2^16*25 just fits into 4 digits i base 36.
5411 (let ((tm (current-time)))
5413 (if (or (eq system-type
'ms-dos
)
5414 ;; message-number-base36 doesn't handle bigints.
5415 (floatp (user-uid)))
5416 (let ((user (downcase (user-login-name))))
5417 (while (string-match "[^a-z0-9_]" user
)
5418 (aset user
(match-beginning 0) ?_
))
5420 (message-number-base36 (user-uid) -
1))
5421 (message-number-base36 (+ (car tm
)
5422 (lsh (% message-unique-id-char
25) 16)) 4)
5423 (message-number-base36 (+ (nth 1 tm
)
5424 (lsh (/ message-unique-id-char
25) 16)) 4)
5425 ;; Append a given name, because while the generated ID is unique
5426 ;; to this newsreader, other newsreaders might otherwise generate
5427 ;; the same ID via another algorithm.
5430 (defun message-number-base36 (num len
)
5435 (concat (message-number-base36 (/ num
36) (1- len
))
5436 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
5439 (defun message-make-organization ()
5440 "Make an Organization header."
5441 (let* ((organization
5442 (when message-user-organization
5443 (if (functionp message-user-organization
)
5444 (funcall message-user-organization
)
5445 message-user-organization
))))
5447 (mm-enable-multibyte)
5448 (cond ((stringp organization
)
5449 (insert organization
))
5450 ((and (eq t organization
)
5451 message-user-organization-file
5452 (file-exists-p message-user-organization-file
))
5453 (insert-file-contents message-user-organization-file
)))
5454 (goto-char (point-min))
5455 (while (re-search-forward "[\t\n]+" nil t
)
5456 (replace-match "" t t
))
5457 (unless (zerop (buffer-size))
5460 (defun message-make-lines ()
5461 "Count the number of lines and return numeric string."
5466 (int-to-string (count-lines (point) (point-max))))))
5468 (defun message-make-references ()
5469 "Return the References header for this message."
5470 (when message-reply-headers
5471 (let ((message-id (mail-header-id message-reply-headers
))
5472 (references (mail-header-references message-reply-headers
)))
5473 (if (or references message-id
)
5474 (concat (or references
"") (and references
" ")
5478 (defun message-make-in-reply-to ()
5479 "Return the In-Reply-To header for this message."
5480 (when message-reply-headers
5481 (let ((from (mail-header-from message-reply-headers
))
5482 (date (mail-header-date message-reply-headers
))
5483 (msg-id (mail-header-id message-reply-headers
)))
5485 (let ((name (mail-extract-address-components from
)))
5487 msg-id
(if msg-id
" (")
5489 (if (string-match "[^\000-\177]" (car name
))
5490 ;; Quote a string containing non-ASCII characters.
5491 ;; It will make the RFC2047 encoder cause an error
5492 ;; if there are special characters.
5493 (mm-with-multibyte-buffer
5495 (goto-char (point-min))
5496 (while (search-forward "\"" nil t
)
5499 (zerop (%
(skip-chars-backward "\\\\") 2))
5500 (goto-char (match-beginning 0)))
5503 ;; Those quotes will be removed by the RFC2047 encoder.
5504 (concat "\"" (buffer-string) "\""))
5508 (if (or (not date
) (string= date
""))
5509 "(unknown date)" date
)
5510 "\"" (if msg-id
")")))))))
5512 (defun message-make-distribution ()
5513 "Make a Distribution header."
5514 (let ((orig-distribution (message-fetch-reply-field "distribution")))
5515 (cond ((functionp message-distribution-function
)
5516 (funcall message-distribution-function
))
5517 (t orig-distribution
))))
5519 (defun message-make-expires ()
5520 "Return an Expires header based on `message-expires'."
5521 (let ((current (current-time))
5522 (future (* 1.0 message-expires
60 60 24)))
5523 ;; Add the future to current.
5524 (setcar current
(+ (car current
) (round (/ future
(expt 2 16)))))
5525 (setcar (cdr current
) (+ (nth 1 current
) (%
(round future
) (expt 2 16))))
5526 (message-make-date current
)))
5528 (defun message-make-path ()
5530 (let ((login-name (user-login-name)))
5531 (cond ((null message-user-path
)
5532 (concat (system-name) "!" login-name
))
5533 ((stringp message-user-path
)
5534 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
5535 (concat message-user-path
"!" login-name
))
5538 (defun message-make-from (&optional name address
)
5539 "Make a From header."
5540 (let* ((style message-from-style
)
5541 (login (or address
(message-make-address)))
5543 (and (boundp 'user-full-name
)
5546 (when (string= fullname
"&")
5547 (setq fullname
(user-login-name)))
5549 (mm-enable-multibyte)
5552 (equal fullname
""))
5554 ((or (eq style
'angles
)
5555 (and (not (eq style
'parens
))
5556 ;; Use angles if no quoting is needed, or if parens would
5557 ;; need quoting too.
5558 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname
))
5559 (let ((tmp (concat fullname nil
)))
5560 (while (string-match "([^()]*)" tmp
)
5561 (aset tmp
(match-beginning 0) ?-
)
5562 (aset tmp
(1- (match-end 0)) ?-
))
5563 (string-match "[\\()]" tmp
)))))
5565 (goto-char (point-min))
5566 ;; Look for a character that cannot appear unquoted
5567 ;; according to RFC 822.
5568 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil
1)
5569 ;; Quote fullname, escaping specials.
5570 (goto-char (point-min))
5572 (while (re-search-forward "[\"\\]" nil
1)
5573 (replace-match "\\\\\\&" t
))
5575 (insert " <" login
">"))
5576 (t ; 'parens or default
5578 (let ((fullname-start (point)))
5580 (goto-char fullname-start
)
5581 ;; RFC 822 says \ and nonmatching parentheses
5582 ;; must be escaped in comments.
5583 ;; Escape every instance of ()\ ...
5584 (while (re-search-forward "[()\\]" nil
1)
5585 (replace-match "\\\\\\&" t
))
5586 ;; ... then undo escaping of matching parentheses,
5587 ;; including matching nested parentheses.
5588 (goto-char fullname-start
)
5589 (while (re-search-forward
5590 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
5592 (replace-match "\\1(\\3)" t
)
5593 (goto-char fullname-start
)))
5597 (defun message-make-sender ()
5598 "Return the \"real\" user address.
5599 This function tries to ignore all user modifications, and
5600 give as trustworthy answer as possible."
5601 (concat (user-login-name) "@" (system-name)))
5603 (defun message-make-address ()
5604 "Make the address of the user."
5605 (or (message-user-mail-address)
5606 (concat (user-login-name) "@" (message-make-domain))))
5608 (defun message-user-mail-address ()
5609 "Return the pertinent part of `user-mail-address'."
5610 (when (and user-mail-address
5611 (string-match "@.*\\." user-mail-address
))
5612 (if (string-match " " user-mail-address
)
5613 (nth 1 (mail-extract-address-components user-mail-address
))
5614 user-mail-address
)))
5616 (defun message-sendmail-envelope-from ()
5617 "Return the envelope from."
5618 (cond ((eq message-sendmail-envelope-from
'header
)
5619 (nth 1 (mail-extract-address-components
5620 (message-fetch-field "from"))))
5621 ((stringp message-sendmail-envelope-from
)
5622 message-sendmail-envelope-from
)
5624 (message-make-address))))
5626 (defun message-make-fqdn ()
5627 "Return user's fully qualified domain name."
5628 (let* ((system-name (system-name))
5629 (user-mail (message-user-mail-address))
5632 (string-match "@\\(.*\\)\\'" user-mail
))
5633 (match-string 1 user-mail
)))
5634 (case-fold-search t
))
5636 ((and message-user-fqdn
5637 (stringp message-user-fqdn
)
5638 (string-match message-valid-fqdn-regexp message-user-fqdn
)
5639 (not (string-match message-bogus-system-names message-user-fqdn
)))
5640 ;; `message-user-fqdn' seems to be valid
5642 ((and (string-match message-valid-fqdn-regexp system-name
)
5643 (not (string-match message-bogus-system-names system-name
)))
5644 ;; `system-name' returned the right result.
5646 ;; Try `mail-host-address'.
5647 ((and (boundp 'mail-host-address
)
5648 (stringp mail-host-address
)
5649 (string-match message-valid-fqdn-regexp mail-host-address
)
5650 (not (string-match message-bogus-system-names mail-host-address
)))
5652 ;; We try `user-mail-address' as a backup.
5654 (stringp user-domain
)
5655 (string-match message-valid-fqdn-regexp user-domain
)
5656 (not (string-match message-bogus-system-names user-domain
)))
5658 ;; Default to this bogus thing.
5661 ".i-did-not-set--mail-host-address--so-tickle-me")))))
5663 (defun message-make-host-name ()
5664 "Return the name of the host."
5665 (let ((fqdn (message-make-fqdn)))
5666 (string-match "^[^.]+\\." fqdn
)
5667 (substring fqdn
0 (1- (match-end 0)))))
5669 (defun message-make-domain ()
5670 "Return the domain name."
5671 (or mail-host-address
5672 (message-make-fqdn)))
5674 (defun message-to-list-only ()
5675 "Send a message to the list only.
5676 Remove all addresses but the list address from To and Cc headers."
5678 (let ((listaddr (message-make-mail-followup-to t
)))
5681 (message-remove-header "to")
5682 (message-remove-header "cc")
5683 (message-position-on-field "To" "X-Draft-From")
5684 (insert listaddr
)))))
5686 (defun message-make-mail-followup-to (&optional only-show-subscribed
)
5687 "Return the Mail-Followup-To header.
5688 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5689 subscribed address (and not the additional To and Cc header contents)."
5690 (let* ((case-fold-search t
)
5691 (to (message-fetch-field "To"))
5692 (cc (message-fetch-field "cc"))
5693 (msg-recipients (concat to
(and to cc
", ") cc
))
5695 (mapcar 'mail-strip-quoted-names
5696 (message-tokenize-header msg-recipients
)))
5698 (if message-subscribed-address-file
5699 (let (begin end item re
)
5702 (insert-file-contents message-subscribed-address-file
)
5704 (setq begin
(point))
5707 (if (bolp) (setq end
(1- end
)))
5708 (setq item
(regexp-quote (buffer-substring begin end
)))
5709 (if re
(setq re
(concat re
"\\|" item
))
5710 (setq re
(concat "\\`\\(" item
))))
5711 (and re
(list (concat re
"\\)\\'"))))))))
5712 (mft-regexps (apply 'append message-subscribed-regexps
5713 (mapcar 'regexp-quote
5714 message-subscribed-addresses
)
5717 message-subscribed-address-functions
))))
5720 (loop for recipient in recipients
5721 when
(loop for regexp in mft-regexps
5722 when
(string-match regexp recipient
) return t
)
5725 (if only-show-subscribed
5727 msg-recipients
))))))
5729 (defun message-idna-to-ascii-rhs-1 (header)
5730 "Interactively potentially IDNA encode domain names in HEADER."
5731 (let ((field (message-fetch-field header
))
5735 (mm-delete-duplicates
5736 (mapcar (lambda (rhs) (or (cadr (split-string rhs
"@")) ""))
5740 (mail-extract-address-components field t
))))))
5741 ;; Note that `rhs' will be "" if the address does not have
5742 ;; the domain part, i.e., if it is a local user's address.
5743 (setq ace
(if (string-match "\\`[[:ascii:]]*\\'" rhs
)
5745 (downcase (idna-to-ascii rhs
))))
5746 (when (and (not (equal rhs ace
))
5747 (or (not (eq message-use-idna
'ask
))
5748 (y-or-n-p (format "Replace %s with %s in %s:? "
5750 (goto-char (point-min))
5751 (while (re-search-forward (concat "^" header
":") nil t
)
5752 (message-narrow-to-field)
5753 (while (search-forward (concat "@" rhs
) nil t
)
5754 (replace-match (concat "@" ace
) t t
))
5755 (goto-char (point-max))
5758 (defun message-idna-to-ascii-rhs ()
5759 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
5760 See `message-idna-encode'."
5762 (when message-use-idna
5765 ;; `message-narrow-to-head' that recognizes only the first empty
5766 ;; line as the message header separator used to be used here.
5767 ;; However, since there is the "--text follows this line--" line
5768 ;; normally, it failed in narrowing to the headers and potentially
5769 ;; caused the IDNA encoding on lines that look like headers in
5770 ;; the message body.
5771 (message-narrow-to-headers-or-head)
5772 (message-idna-to-ascii-rhs-1 "From")
5773 (message-idna-to-ascii-rhs-1 "To")
5774 (message-idna-to-ascii-rhs-1 "Reply-To")
5775 (message-idna-to-ascii-rhs-1 "Mail-Reply-To")
5776 (message-idna-to-ascii-rhs-1 "Mail-Followup-To")
5777 (message-idna-to-ascii-rhs-1 "Cc")))))
5779 (defun message-generate-headers (headers)
5780 "Prepare article HEADERS.
5781 Headers already prepared in the buffer are not modified."
5782 (setq headers
(append headers message-required-headers
))
5784 (message-narrow-to-headers)
5785 (let* ((Date (message-make-date))
5786 (Message-ID (message-make-message-id))
5787 (Organization (message-make-organization))
5788 (From (message-make-from))
5789 (Path (message-make-path))
5792 (In-Reply-To (message-make-in-reply-to))
5793 (References (message-make-references))
5795 (Distribution (message-make-distribution))
5796 (Lines (message-make-lines))
5797 (User-Agent message-newsreader
)
5798 (Expires (message-make-expires))
5799 (case-fold-search t
)
5801 header value elem header-string
)
5802 ;; First we remove any old generated headers.
5803 (let ((headers message-deletable-headers
))
5804 (unless (buffer-modified-p)
5805 (setq headers
(delq 'Message-ID
(copy-sequence headers
))))
5807 (goto-char (point-min))
5808 (and (re-search-forward
5809 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
5810 (get-text-property (1+ (match-beginning 0)) 'message-deletable
)
5811 (message-delete-line))
5813 ;; Go through all the required headers and see if they are in the
5814 ;; articles already. If they are not, or are empty, they are
5815 ;; inserted automatically - except for Subject, Newsgroups and
5818 (goto-char (point-min))
5819 (setq elem
(pop headers
))
5821 (if (eq (car elem
) 'optional
)
5822 (setq header
(cdr elem
)
5824 (setq header
(car elem
)))
5826 (setq header-string
(if (stringp header
)
5828 (symbol-name header
)))
5829 (when (or (not (re-search-forward
5831 (regexp-quote (downcase header-string
))
5835 ;; The header was found. We insert a space after the
5836 ;; colon, if there is none.
5837 (if (/= (char-after) ?
) (insert " ") (forward-char 1))
5838 ;; Find out whether the header is empty.
5839 (looking-at "[ \t]*\n[^ \t]")))
5840 ;; So we find out what value we should insert.
5844 (eq (car elem
) 'optional
)
5845 (not (member header-string message-inserted-headers
)))
5846 ;; This is an optional header. If the cdr of this
5847 ;; is something that is nil, then we do not insert
5849 (setq header
(cdr elem
))
5850 (or (and (functionp (cdr elem
))
5851 (funcall (cdr elem
)))
5852 (and (boundp (cdr elem
))
5853 (symbol-value (cdr elem
)))))
5855 ;; The element is a cons. Either the cdr is a
5856 ;; string to be inserted verbatim, or it is a
5857 ;; function, and we insert the value returned from
5859 (or (and (stringp (cdr elem
))
5861 (and (functionp (cdr elem
))
5862 (funcall (cdr elem
)))))
5863 ((and (boundp header
)
5864 (symbol-value header
))
5865 ;; The element is a symbol. We insert the value
5866 ;; of this symbol, if any.
5867 (symbol-value header
))
5868 ((not (message-check-element
5869 (intern (downcase (symbol-name header
)))))
5870 ;; We couldn't generate a value for this header,
5871 ;; so we just ask the user.
5872 (read-from-minibuffer
5873 (format "Empty header for %s; enter value: " header
)))))
5874 ;; Finally insert the header.
5876 (not (equal value
"")))
5880 ;; This header didn't exist, so we insert it.
5881 (goto-char (point-max))
5883 (cdr (assq header message-header-format-alist
))))
5885 (funcall formatter header value
)
5886 (insert header-string
": " value
))
5887 (push header-string message-inserted-headers
)
5888 (goto-char (message-fill-field))
5889 ;; We check whether the value was ended by a
5890 ;; newline. If not, we insert one.
5894 ;; The value of this header was empty, so we clear
5895 ;; totally and insert the new value.
5896 (delete-region (point) (point-at-eol))
5897 ;; If the header is optional, and the header was
5898 ;; empty, we can't insert it anyway.
5900 (push header-string message-inserted-headers
)
5902 (message-fill-field)))
5903 ;; Add the deletable property to the headers that require it.
5904 (and (memq header message-deletable-headers
)
5905 (progn (beginning-of-line) (looking-at "[^:]+: "))
5906 (add-text-properties
5907 (point) (match-end 0)
5908 '(message-deletable t face italic
) (current-buffer)))))))
5909 ;; Insert new Sender if the From is strange.
5910 (let ((from (message-fetch-field "from"))
5911 (sender (message-fetch-field "sender"))
5912 (secure-sender (message-make-sender)))
5914 (not (message-check-element 'sender
))
5917 (cadr (mail-extract-address-components from
)))
5918 (downcase secure-sender
)))
5923 (cadr (mail-extract-address-components sender
)))
5924 (downcase secure-sender
)))))
5925 (goto-char (point-min))
5926 ;; Rename any old Sender headers to Original-Sender.
5927 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t
)
5929 (insert "Original-")
5930 (beginning-of-line))
5931 (when (or (message-news-p)
5932 (string-match "@.+\\.." secure-sender
))
5933 (insert "Sender: " secure-sender
"\n"))))
5935 (message-idna-to-ascii-rhs))))
5937 (defun message-insert-courtesy-copy ()
5938 "Insert a courtesy message in mail copies of combined messages."
5942 (message-narrow-to-headers)
5943 (when (setq newsgroups
(message-fetch-field "newsgroups"))
5944 (goto-char (point-max))
5945 (insert "Posted-To: " newsgroups
"\n")))
5947 (when message-courtesy-message
5949 ((string-match "%s" message-courtesy-message
)
5950 (insert (format message-courtesy-message newsgroups
)))
5952 (insert message-courtesy-message
)))))))
5955 ;;; Setting up a message buffer
5958 (defun message-skip-to-next-address ()
5959 (let ((end (save-excursion
5960 (message-next-header)
5963 (when (looking-at ",")
5965 (while (and (not (= (point) end
))
5966 (or (not (eq char ?
,))
5968 (skip-chars-forward "^,\"" (point-max))
5969 (when (eq (setq char
(following-char)) ?
\")
5970 (setq quoted
(not quoted
)))
5971 (unless (= (point) end
)
5973 (skip-chars-forward " \t\n")))
5975 (defun message-fill-address (header value
)
5976 (insert (capitalize (symbol-name header
))
5978 (if (consp value
) (car value
) value
)
5980 (message-fill-field-address))
5982 (defun message-split-line ()
5983 "Split current line, moving portion beyond point vertically down.
5984 If the current line has `message-yank-prefix', insert it on the new line."
5987 (split-line message-yank-prefix
) ;; Emacs 22.1+ supports arg.
5991 (defun message-insert-header (header value
)
5992 (insert (capitalize (symbol-name header
))
5994 (if (consp value
) (car value
) value
)))
5996 (defun message-field-name ()
5998 (goto-char (point-min))
5999 (when (looking-at "\\([^:]+\\):")
6000 (intern (capitalize (match-string 1))))))
6002 (defun message-fill-field ()
6005 (message-narrow-to-field)
6006 (let ((field-name (message-field-name)))
6007 (funcall (or (cadr (assq field-name message-field-fillers
))
6008 'message-fill-field-general
)))
6011 (defun message-fill-field-address ()
6013 (message-skip-to-next-address)
6015 (if (and (> (current-column) 78)
6021 (setq last
(1+ (point))))
6022 (setq last
(1+ (point)))))))
6024 (defun message-fill-field-general ()
6025 (let ((begin (point))
6028 (while (and (search-forward "\n" nil t
)
6030 (replace-match " " t t
))
6031 (fill-region-as-paragraph begin
(point-max))
6032 ;; Tapdance around looong Message-IDs.
6034 (when (looking-at "[ \t]*$")
6035 (message-delete-line))
6037 (search-forward ":" nil t
)
6038 (when (looking-at "\n[ \t]+")
6039 (replace-match " " t t
))
6040 (goto-char (point-max))))
6042 (defun message-shorten-1 (list cut surplus
)
6043 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
6044 (setcdr (nthcdr (- cut
2) list
)
6045 (nthcdr (+ (- cut
2) surplus
1) list
)))
6047 (defun message-shorten-references (header references
)
6048 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
6049 When sending via news, also check that the REFERENCES are less
6050 than 988 characters long, and if they are not, trim them until
6052 ;; 21 is the number suggested by USEAGE.
6059 (goto-char (point-min))
6060 ;; Cons a list of valid references. GNKSA says we must not include MIDs
6061 ;; with whitespace or missing brackets (7.a "Does not propagate broken
6062 ;; Message-IDs in original References").
6063 (while (re-search-forward "<[^ <]+@[^ <]+>" nil t
)
6064 (push (match-string 0) refs
))
6065 (setq refs
(nreverse refs
)
6066 count
(length refs
)))
6068 ;; If the list has more than MAXCOUNT elements, trim it by
6069 ;; removing the CUTth element and the required number of
6070 ;; elements that follow.
6071 (when (> count maxcount
)
6072 (let ((surplus (- count maxcount
)))
6073 (message-shorten-1 refs cut surplus
)
6074 (decf count surplus
)))
6076 ;; When sending via news, make sure the total folded length will
6077 ;; be less than 998 characters. This is to cater to broken INN
6078 ;; 2.3 which counts the total number of characters in a header
6079 ;; rather than the physical line length of each line, as it should.
6081 ;; This hack should be removed when it's believed than INN 2.3 is
6082 ;; no longer widely used.
6084 ;; At this point the headers have not been generated, thus we use
6085 ;; message-this-is-news directly.
6086 (when message-this-is-news
6089 (message-insert-header
6090 header
(mapconcat #'identity refs
" "))
6092 (message-shorten-1 refs cut
1)))
6093 ;; Finally, collect the references back into a string and insert
6094 ;; it into the buffer.
6095 (message-insert-header header
(mapconcat #'identity refs
" "))))
6097 (defun message-position-point ()
6098 "Move point to where the user probably wants to find it."
6099 (message-narrow-to-headers)
6101 ((re-search-forward "^[^:]+:[ \t]*$" nil t
)
6102 (search-backward ":" )
6105 (if (eq (char-after) ?
)
6109 (goto-char (point-max))
6112 (unless (looking-at "$")
6116 (defcustom message-beginning-of-line t
6117 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
6118 goes to beginning of header values."
6120 :group
'message-buffers
6121 :link
'(custom-manual "(message)Movement")
6124 (defun message-beginning-of-line (&optional n
)
6125 "Move point to beginning of header value or to beginning of line.
6126 The prefix argument N is passed directly to `beginning-of-line'.
6128 This command is identical to `beginning-of-line' if point is
6129 outside the message header or if the option `message-beginning-of-line'
6132 If point is in the message header and on a (non-continued) header
6133 line, move point to the beginning of the header value or the beginning of line,
6134 whichever is closer. If point is already at beginning of line, move point to
6135 beginning of header value. Therefore, repeated calls will toggle point
6136 between beginning of field and beginning of line."
6138 (let ((zrs 'zmacs-region-stays
))
6139 (when (and (featurep 'xemacs
) (interactive-p) (boundp zrs
))
6141 (if (and message-beginning-of-line
6142 (message-point-in-header-p))
6143 (let* ((here (point))
6144 (bol (progn (beginning-of-line n
) (point)))
6145 (eol (point-at-eol))
6146 (eoh (re-search-forward ": *" eol t
)))
6148 (if (and eoh
(or (< eoh here
) (= bol here
)))
6150 (beginning-of-line n
)))
6152 (defun message-buffer-name (type &optional to group
)
6153 "Return a new (unique) buffer name based on TYPE and TO."
6155 ;; Generate a new buffer name The Message Way.
6156 ((memq message-generate-new-buffers
'(unique t
))
6157 (generate-new-buffer-name
6161 (or (car (mail-extract-address-components to
))
6164 (if (and group
(not (string= group
""))) (concat " on " group
) "")
6166 ;; Check whether `message-generate-new-buffers' is a function,
6167 ;; and if so, call it.
6168 ((functionp message-generate-new-buffers
)
6169 (funcall message-generate-new-buffers type to group
))
6170 ((eq message-generate-new-buffers
'unsent
)
6171 (generate-new-buffer-name
6172 (concat "*unsent " type
6175 (or (car (mail-extract-address-components to
))
6178 (if (and group
(not (string= group
""))) (concat " on " group
) "")
6180 ;; Search for the existing message buffer with the specified name.
6182 (let* ((new (if (eq message-generate-new-buffers
'standard
)
6183 (generate-new-buffer-name (concat "*" type
" message*"))
6184 (let ((message-generate-new-buffers 'unique
))
6185 (message-buffer-name type to group
))))
6186 (regexp (concat "\\`"
6188 (if (string-match "<[0-9]+>\\'" new
)
6189 (substring new
0 (match-beginning 0))
6191 "\\(?:<\\([0-9]+\\)>\\)?\\'"))
6192 (case-fold-search nil
))
6199 (when (and (string-match regexp
(setq b
(buffer-name b
)))
6200 (eq (with-current-buffer b major-mode
)
6202 (cons (string-to-number (or (match-string 1 b
) "1"))
6205 'car-less-than-car
)))
6208 (defun message-pop-to-buffer (name &optional switch-function
)
6209 "Pop to buffer NAME, and warn if it already exists and is modified."
6210 (let ((buffer (get-buffer name
)))
6212 (buffer-name buffer
))
6213 (let ((window (get-buffer-window buffer
0)))
6215 ;; Raise the frame already displaying the message buffer.
6217 (gnus-select-frame-set-input-focus (window-frame window
))
6218 (select-window window
))
6219 (funcall (or switch-function
'pop-to-buffer
) buffer
)
6220 (set-buffer buffer
))
6221 (when (and (buffer-modified-p)
6224 "Message already being composed; erase? ")
6226 (error "Message being composed")))
6227 (funcall (or switch-function
'pop-to-buffer
) name
)
6232 (defun message-do-send-housekeeping ()
6233 "Kill old message buffers."
6234 ;; We might have sent this buffer already. Delete it from the
6236 (setq message-buffer-list
(delq (current-buffer) message-buffer-list
))
6237 (while (and message-max-buffers
6239 (>= (length message-buffer-list
) message-max-buffers
))
6240 ;; Kill the oldest buffer -- unless it has been changed.
6241 (let ((buffer (pop message-buffer-list
)))
6242 (when (and (buffer-name buffer
)
6243 (not (buffer-modified-p buffer
)))
6244 (kill-buffer buffer
))))
6245 ;; Rename the buffer.
6246 (if message-send-rename-function
6247 (funcall message-send-rename-function
)
6248 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
6250 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
6252 (let ((name (match-string 2 (buffer-name)))
6254 (if (not (or (null name
)
6255 (string-equal name
"mail")
6256 (string-equal name
"posting")))
6257 (setq name
(concat "*sent " name
"*"))
6258 (message-narrow-to-headers)
6259 (setq to
(message-fetch-field "to"))
6260 (setq group
(message-fetch-field "newsgroups"))
6264 (to (concat "*sent mail to "
6265 (or (car (mail-extract-address-components to
))
6267 ((and group
(not (string= group
"")))
6268 (concat "*sent posting on " group
"*"))
6269 (t "*sent mail*"))))
6270 (unless (string-equal name
(buffer-name))
6271 (rename-buffer name t
)))))
6272 ;; Push the current buffer onto the list.
6273 (when message-max-buffers
6274 (setq message-buffer-list
6275 (nconc message-buffer-list
(list (current-buffer))))))
6277 (defun message-mail-user-agent ()
6279 ((not message-mail-user-agent
) nil
)
6280 ((eq message-mail-user-agent t
) mail-user-agent
)
6281 (t message-mail-user-agent
))))
6282 (if (memq mua
'(message-user-agent gnus-user-agent
))
6286 ;; YANK-ACTION, if non-nil, can be a buffer or a yank action of the
6287 ;; form (FUNCTION . ARGS).
6288 (defun message-setup (headers &optional yank-action actions
6289 continue switch-function
)
6290 (let ((mua (message-mail-user-agent))
6292 (if (not (and message-this-is-mail mua
))
6293 (message-setup-1 headers yank-action actions
)
6294 (setq headers
(copy-sequence headers
))
6295 (setq field
(assq 'Subject headers
))
6297 (setq subject
(cdr field
))
6298 (setq headers
(delq field headers
)))
6299 (setq field
(assq 'To headers
))
6301 (setq to
(cdr field
))
6302 (setq headers
(delq field headers
)))
6303 (let ((mail-user-agent mua
))
6304 (compose-mail to subject
6305 (mapcar (lambda (item)
6307 (format "%s" (car item
))
6310 continue switch-function
6311 (if (bufferp yank-action
)
6312 (list 'insert-buffer yank-action
)
6316 (defun message-headers-to-generate (headers included-headers excluded-headers
)
6317 "Return a list that includes all headers from HEADERS.
6318 If INCLUDED-HEADERS is a list, just include those headers. If it is
6319 t, include all headers. In any case, headers from EXCLUDED-HEADERS
6323 (dolist (header headers
)
6324 (setq header-name
(cond
6325 ((and (consp header
)
6326 (eq (car header
) 'optional
))
6327 ;; On the form (optional . Header)
6330 ;; On the form (Header . function)
6335 (when (and (not (memq header-name excluded-headers
))
6336 (or (eq included-headers t
)
6337 (memq header-name included-headers
)))
6338 (push header result
)))
6341 (defun message-setup-1 (headers &optional yank-action actions
)
6342 (dolist (action actions
)
6344 (add-to-list 'message-send-actions
6345 `(apply ',(car action
) ',(cdr action
)))))
6346 (setq message-reply-buffer
6347 (if (and (consp yank-action
)
6348 (eq (car yank-action
) 'insert-buffer
))
6351 (goto-char (point-min))
6352 ;; Insert all the headers.
6355 (alist message-header-format-alist
))
6357 (unless (assq (caar h
) message-header-format-alist
)
6358 (push (list (caar h
)) alist
))
6362 (delete-region (point) (progn (forward-line -
1) (point)))
6363 (when message-default-headers
6364 (insert message-default-headers
)
6365 (or (bolp) (insert ?
\n)))
6366 (insert mail-header-separator
"\n")
6368 (when (message-news-p)
6369 (when message-default-news-headers
6370 (insert message-default-news-headers
)
6371 (or (bolp) (insert ?
\n)))
6372 (when message-generate-headers-first
6373 (message-generate-headers
6374 (message-headers-to-generate
6375 (append message-required-news-headers
6376 message-required-headers
)
6377 message-generate-headers-first
6378 '(Lines Subject
)))))
6379 (when (message-mail-p)
6380 (when message-default-mail-headers
6381 (insert message-default-mail-headers
)
6382 (or (bolp) (insert ?
\n)))
6383 (when message-generate-headers-first
6384 (message-generate-headers
6385 (message-headers-to-generate
6386 (append message-required-mail-headers
6387 message-required-headers
)
6388 message-generate-headers-first
6389 '(Lines Subject
)))))
6390 (run-hooks 'message-signature-setup-hook
)
6391 (message-insert-signature)
6393 (message-narrow-to-headers)
6394 (run-hooks 'message-header-setup-hook
))
6395 (setq buffer-undo-list nil
)
6396 (when message-generate-hashcash
6397 ;; Generate hashcash headers for recipients already known
6398 (mail-add-payment-async))
6399 ;; Gnus posting styles are applied via buffer-local `message-setup-hook'
6401 (run-hooks 'message-setup-hook
)
6402 ;; Do this last to give it precedence over posting styles, etc.
6403 (when (message-mail-p)
6405 (message-narrow-to-headers)
6406 (if message-alternative-emails
6407 (message-use-alternative-email-as-from))))
6408 (message-position-point)
6409 ;; Allow correct handling of `message-checksum' in `message-yank-original':
6410 (set-buffer-modified-p nil
)
6413 (defun message-set-auto-save-file-name ()
6414 "Associate the message buffer with a file in the drafts directory."
6415 (when message-auto-save-directory
6416 (unless (file-directory-p
6417 (directory-file-name message-auto-save-directory
))
6418 (make-directory message-auto-save-directory t
))
6420 (setq message-draft-article
6421 (nndraft-request-associate-buffer "drafts"))
6423 ;; If Gnus were alive, draft messages would be saved in the drafts folder.
6424 ;; But Gnus is not alive, so arrange to save the draft message in a
6425 ;; regular file in message-auto-save-directory. Append a unique
6426 ;; time-based suffix to the filename to allow multiple drafts to be saved
6427 ;; simultaneously without overwriting each other (which mimics the
6428 ;; functionality of the Gnus drafts folder).
6429 (setq buffer-file-name
(expand-file-name
6431 (if (memq system-type
6432 '(ms-dos windows-nt cygwin
))
6435 (format-time-string "-%Y%m%d-%H%M%S"))
6436 message-auto-save-directory
))
6437 (setq buffer-auto-save-file-name
(make-auto-save-file-name)))
6438 (clear-visited-file-modtime)
6439 (setq buffer-file-coding-system message-draft-coding-system
)))
6441 (defun message-disassociate-draft ()
6442 "Disassociate the message buffer from the drafts directory."
6443 (when message-draft-article
6444 (nndraft-request-expire-articles
6445 (list message-draft-article
) "drafts" nil t
)))
6447 (defun message-insert-headers ()
6448 "Generate the headers for the article."
6452 (message-narrow-to-headers)
6453 (when (message-news-p)
6454 (message-generate-headers
6457 (copy-sequence message-required-news-headers
)))))
6458 (when (message-mail-p)
6459 (message-generate-headers
6462 (copy-sequence message-required-mail-headers
))))))))
6467 ;;; Commands for interfacing with message
6471 (defun message-mail (&optional to subject
6472 other-headers continue switch-function
6473 yank-action send-actions
)
6474 "Start editing a mail message to be sent.
6475 OTHER-HEADERS is an alist of header/value pairs. CONTINUE says whether
6476 to continue editing a message already being composed. SWITCH-FUNCTION
6477 is a function used to switch to and display the mail buffer."
6479 (let ((message-this-is-mail t
))
6480 (unless (message-mail-user-agent)
6481 (message-pop-to-buffer
6482 ;; Search for the existing message buffer if `continue' is non-nil.
6483 (let ((message-generate-new-buffers
6484 (when (or (not continue
)
6485 (eq message-generate-new-buffers
'standard
)
6486 (functionp message-generate-new-buffers
))
6487 message-generate-new-buffers
)))
6488 (message-buffer-name "mail" to
))
6492 `((To .
,(or to
"")) (Subject .
,(or subject
"")))
6493 (when other-headers other-headers
))
6494 yank-action send-actions continue switch-function
)
6495 ;; FIXME: Should return nil if failure.
6499 (defun message-news (&optional newsgroups subject
)
6500 "Start editing a news article to be sent."
6502 (let ((message-this-is-news t
))
6503 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
))
6504 (message-setup `((Newsgroups .
,(or newsgroups
""))
6505 (Subject .
,(or subject
""))))))
6507 (defun message-alter-recipients-discard-bogus-full-name (addrcell)
6508 "Discard mail address in full names.
6509 When the full name in reply headers contains the mail
6510 address (e.g. \"foo@bar <foo@bar>\"), discard full name.
6511 ADDRCELL is a cons cell where the car is the mail address and the
6512 cdr is the complete address (full name and mail address)."
6513 (if (string-match (concat (regexp-quote (car addrcell
)) ".*"
6514 (regexp-quote (car addrcell
)))
6516 (cons (car addrcell
) (car addrcell
))
6519 (defcustom message-alter-recipients-function nil
6520 "Function called to allow alteration of reply header structures.
6521 It is called in `message-get-reply-headers' for each recipient.
6522 The function is called with one parameter, a cons cell ..."
6523 :type
'(choice (const :tag
"None" nil
)
6524 (const :tag
"Discard bogus full name"
6525 message-alter-recipients-discard-bogus-full-name
)
6527 :version
"23.1" ;; No Gnus
6528 :group
'message-headers
)
6530 (defun message-get-reply-headers (wide &optional to-address address-headers
)
6531 (let (follow-to mct never-mct to cc author mft recipients extra
)
6532 ;; Find all relevant headers we need.
6534 (message-narrow-to-headers-or-head)
6535 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
6536 ;; message-header-synonyms.
6537 (setq to
(or (message-fetch-field "to")
6538 (and (loop for synonym in message-header-synonyms
6539 when
(memq 'Original-To synonym
)
6541 (message-fetch-field "original-to")))
6542 cc
(message-fetch-field "cc")
6543 extra
(when message-extra-wide-headers
6544 (mapconcat 'identity
6545 (mapcar 'message-fetch-field
6546 message-extra-wide-headers
)
6548 mct
(message-fetch-field "mail-copies-to")
6549 author
(or (message-fetch-field "mail-reply-to")
6550 (message-fetch-field "reply-to")
6551 (message-fetch-field "from")
6553 mft
(and message-use-mail-followup-to
6554 (message-fetch-field "mail-followup-to"))))
6556 ;; Handle special values of Mail-Copies-To.
6558 (cond ((or (equal (downcase mct
) "never")
6559 (equal (downcase mct
) "nobody"))
6562 ((or (equal (downcase mct
) "always")
6563 (equal (downcase mct
) "poster"))
6564 (setq mct author
))))
6567 ;; Build (textual) list of new recipient addresses.
6570 (setq recipients
(concat ", " author
)))
6572 (dolist (header address-headers
)
6573 (let ((value (message-fetch-field header
)))
6575 (setq recipients
(concat recipients
", " value
))))))
6577 (string-match "[^ \t,]" mft
)
6578 (or (not (eq message-use-mail-followup-to
'ask
))
6579 (message-y-or-n-p "Obey Mail-Followup-To? " t
"\
6580 You should normally obey the Mail-Followup-To: header. In this
6581 article, it has the value of
6585 which directs your response to " (if (string-match "," mft
)
6586 "the specified addresses"
6587 "that address only") ".
6589 Most commonly, Mail-Followup-To is used by a mailing list poster to
6590 express that responses should be sent to just the list, and not the
6593 If a message is posted to several mailing lists, Mail-Followup-To may
6594 also be used to direct the following discussion to one list only,
6595 because discussions that are spread over several lists tend to be
6596 fragmented and very difficult to follow.
6598 Also, some source/announcement lists are not intended for discussion;
6599 responses here are directed to other addresses.
6601 You may customize the variable `message-use-mail-followup-to', if you
6602 want to get rid of this query permanently.")))
6603 (setq recipients
(concat ", " mft
)))
6605 (setq recipients
(concat ", " to-address
))
6606 ;; If the author explicitly asked for a copy, we don't deny it to them.
6607 (if mct
(setq recipients
(concat recipients
", " mct
))))
6609 (setq recipients
(if never-mct
"" (concat ", " author
)))
6610 (if to
(setq recipients
(concat recipients
", " to
)))
6611 (if cc
(setq recipients
(concat recipients
", " cc
)))
6612 (if extra
(setq recipients
(concat recipients
", " extra
)))
6613 (if mct
(setq recipients
(concat recipients
", " mct
)))))
6614 (if (>= (length recipients
) 2)
6615 ;; Strip the leading ", ".
6616 (setq recipients
(substring recipients
2)))
6617 ;; Squeeze whitespace.
6618 (while (string-match "[ \t][ \t]+" recipients
)
6619 (setq recipients
(replace-match " " t t recipients
)))
6620 ;; Remove addresses that match `rmail-dont-reply-to-names'.
6621 (let ((rmail-dont-reply-to-names (message-dont-reply-to-names)))
6622 (setq recipients
(rmail-dont-reply-to recipients
)))
6623 ;; Perhaps "Mail-Copies-To: never" removed the only address?
6624 (if (string-equal recipients
"")
6625 (setq recipients author
))
6626 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
6630 (if message-alter-recipients-function
6631 (funcall message-alter-recipients-function
6632 (cons (downcase (mail-strip-quoted-names addr
))
6634 (cons (downcase (mail-strip-quoted-names addr
)) addr
)))
6635 (message-tokenize-header recipients
)))
6636 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
6637 (let ((s recipients
))
6639 (setq recipients
(delq (assoc (car (pop s
)) s
) recipients
))))
6641 ;; Remove hierarchical lists that are contained within each other,
6642 ;; if message-hierarchical-addresses is defined.
6643 (when message-hierarchical-addresses
6644 (let ((plain-addrs (mapcar 'car recipients
))
6647 (setq subaddrs
(assoc (car plain-addrs
)
6648 message-hierarchical-addresses
)
6649 plain-addrs
(cdr plain-addrs
))
6651 (setq subaddrs
(cdr subaddrs
))
6653 (setq recip
(assoc (car subaddrs
) recipients
)
6654 subaddrs
(cdr subaddrs
))
6656 (setq recipients
(delq recip recipients
))))))))
6658 (setq recipients
(message-prune-recipients recipients
))
6660 ;; Build the header alist. Allow the user to be asked whether
6661 ;; or not to reply to all recipients in a wide reply.
6662 (setq follow-to
(list (cons 'To
(cdr (pop recipients
)))))
6663 (when (and recipients
6664 (or (not message-wide-reply-confirm-recipients
)
6665 (y-or-n-p "Reply to all recipients? ")))
6666 (setq recipients
(mapconcat
6667 (lambda (addr) (cdr addr
)) recipients
", "))
6668 (if (string-match "^ +" recipients
)
6669 (setq recipients
(substring recipients
(match-end 0))))
6670 (push (cons 'Cc recipients
) follow-to
)))
6673 (defun message-prune-recipients (recipients)
6674 (dolist (rule message-prune-recipient-rules
)
6675 (let ((match (car rule
))
6678 (dolist (recipient recipients
)
6679 (setq address
(car recipient
))
6680 (when (string-match match address
)
6681 (setq dup-match
(replace-match (cadr rule
) nil nil address
))
6682 (dolist (recipient recipients
)
6683 ;; Don't delete the address that triggered this.
6684 (when (and (not (eq address
(car recipient
)))
6685 (string-match dup-match
(car recipient
)))
6686 (setq recipients
(delq recipient recipients
))))))))
6689 (defcustom message-simplify-subject-functions
6690 '(message-strip-list-identifiers
6691 message-strip-subject-re
6692 message-strip-subject-trailing-was
6693 message-strip-subject-encoded-words
)
6694 "List of functions taking a string argument that simplify subjects.
6695 The functions are applied when replying to a message.
6697 Useful functions to put in this list include:
6698 `message-strip-list-identifiers', `message-strip-subject-re',
6699 `message-strip-subject-trailing-was', and
6700 `message-strip-subject-encoded-words'."
6701 :version
"22.1" ;; Gnus 5.10.9
6702 :group
'message-various
6703 :type
'(repeat function
))
6705 (defun message-simplify-subject (subject &optional functions
)
6706 "Return simplified SUBJECT."
6709 (setq functions message-simplify-subject-functions
))
6710 (when (and (memq 'message-strip-list-identifiers functions
)
6711 gnus-list-identifiers
)
6712 (setq subject
(message-strip-list-identifiers subject
)))
6713 (when (memq 'message-strip-subject-re functions
)
6714 (setq subject
(concat "Re: " (message-strip-subject-re subject
))))
6715 (when (and (memq 'message-strip-subject-trailing-was functions
)
6716 message-subject-trailing-was-query
)
6717 (setq subject
(message-strip-subject-trailing-was subject
)))
6718 (when (memq 'message-strip-subject-encoded-words functions
)
6719 (setq subject
(message-strip-subject-encoded-words subject
)))
6723 (defun message-reply (&optional to-address wide
)
6724 "Start editing a reply to the article in the current buffer."
6726 (require 'gnus-sum
) ; for gnus-list-identifiers
6727 (let ((cur (current-buffer))
6728 from subject date reply-to to cc
6729 references message-id follow-to
6730 (inhibit-point-motion-hooks t
)
6731 (message-this-is-mail t
)
6734 (message-narrow-to-head-1)
6735 ;; Allow customizations to have their say.
6737 ;; This is a regular reply.
6738 (when (functionp message-reply-to-function
)
6740 (setq follow-to
(funcall message-reply-to-function
))))
6741 ;; This is a followup.
6742 (when (functionp message-wide-reply-to-function
)
6745 (funcall message-wide-reply-to-function
)))))
6746 (setq message-id
(message-fetch-field "message-id" t
)
6747 references
(message-fetch-field "references")
6748 date
(message-fetch-field "date")
6749 from
(or (message-fetch-field "from") "nobody")
6750 subject
(or (message-fetch-field "subject") "none"))
6752 ;; Strip list identifiers, "Re: ", and "was:"
6753 (setq subject
(message-simplify-subject subject
))
6755 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
6756 (string-match "<[^>]+>" gnus-warning
))
6757 (setq message-id
(match-string 0 gnus-warning
)))
6760 (setq follow-to
(message-get-reply-headers wide to-address
))))
6762 (unless (message-mail-user-agent)
6763 (message-pop-to-buffer
6764 (message-buffer-name
6765 (if wide
"wide reply" "reply") from
6766 (if wide to-address nil
))))
6768 (setq message-reply-headers
6769 (vector 0 subject from date message-id references
0 0 ""))
6772 `((Subject .
,subject
)
6777 (defun message-wide-reply (&optional to-address
)
6778 "Make a \"wide\" reply to the message in the current buffer."
6780 (message-reply to-address t
))
6783 (defun message-followup (&optional to-newsgroups
)
6784 "Follow up to the message in the current buffer.
6785 If TO-NEWSGROUPS, use that as the new Newsgroups line."
6787 (require 'gnus-sum
) ; for gnus-list-identifiers
6788 (let ((cur (current-buffer))
6789 from subject date reply-to mrt mct
6790 references message-id follow-to
6791 (inhibit-point-motion-hooks t
)
6792 (message-this-is-news t
)
6793 followup-to distribution newsgroups gnus-warning posted-to
)
6796 (goto-char (point-min))
6797 (if (search-forward "\n\n" nil t
)
6800 (when (functionp message-followup-to-function
)
6802 (funcall message-followup-to-function
)))
6803 (setq from
(message-fetch-field "from")
6804 date
(message-fetch-field "date")
6805 subject
(or (message-fetch-field "subject") "none")
6806 references
(message-fetch-field "references")
6807 message-id
(message-fetch-field "message-id" t
)
6808 followup-to
(message-fetch-field "followup-to")
6809 newsgroups
(message-fetch-field "newsgroups")
6810 posted-to
(message-fetch-field "posted-to")
6811 reply-to
(message-fetch-field "reply-to")
6812 mrt
(message-fetch-field "mail-reply-to")
6813 distribution
(message-fetch-field "distribution")
6814 mct
(message-fetch-field "mail-copies-to"))
6815 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
6816 (string-match "<[^>]+>" gnus-warning
))
6817 (setq message-id
(match-string 0 gnus-warning
)))
6818 ;; Remove bogus distribution.
6819 (when (and (stringp distribution
)
6820 (let ((case-fold-search t
))
6821 (string-match "world" distribution
)))
6822 (setq distribution nil
))
6823 ;; Strip list identifiers, "Re: ", and "was:"
6824 (setq subject
(message-simplify-subject subject
))
6827 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups
))
6829 (setq message-reply-headers
6830 (vector 0 subject from date message-id references
0 0 ""))
6833 `((Subject .
,subject
)
6836 (list (cons 'Newsgroups to-newsgroups
)))
6837 (follow-to follow-to
)
6838 ((and followup-to message-use-followup-to
)
6841 ((equal (downcase followup-to
) "poster")
6842 (if (or (eq message-use-followup-to
'use
)
6843 (message-y-or-n-p "Obey Followup-To: poster? " t
"\
6844 You should normally obey the Followup-To: header.
6846 `Followup-To: poster' sends your response via e-mail instead of news.
6848 A typical situation where `Followup-To: poster' is used is when the poster
6849 does not read the newsgroup, so he wouldn't see any replies sent to it.
6851 You may customize the variable `message-use-followup-to', if you
6852 want to get rid of this query permanently."))
6854 (setq message-this-is-news nil
)
6855 (cons 'To
(or mrt reply-to from
"")))
6856 (cons 'Newsgroups newsgroups
)))
6858 (if (or (equal followup-to newsgroups
)
6859 (not (eq message-use-followup-to
'ask
))
6861 (concat "Obey Followup-To: " followup-to
"? ") t
"\
6862 You should normally obey the Followup-To: header.
6864 `Followup-To: " followup-to
"'
6865 directs your response to " (if (string-match "," followup-to
)
6866 "the specified newsgroups"
6867 "that newsgroup only") ".
6869 If a message is posted to several newsgroups, Followup-To is often
6870 used to direct the following discussion to one newsgroup only,
6871 because discussions that are spread over several newsgroup tend to
6872 be fragmented and very difficult to follow.
6874 Also, some source/announcement newsgroups are not intended for discussion;
6875 responses here are directed to other newsgroups.
6877 You may customize the variable `message-use-followup-to', if you
6878 want to get rid of this query permanently."))
6879 (cons 'Newsgroups followup-to
)
6880 (cons 'Newsgroups newsgroups
))))))
6882 `((Newsgroups .
,posted-to
)))
6884 `((Newsgroups .
,newsgroups
))))
6885 ,@(and distribution
(list (cons 'Distribution distribution
)))
6887 (not (or (equal (downcase mct
) "never")
6888 (equal (downcase mct
) "nobody"))))
6889 (list (cons 'Cc
(if (or (equal (downcase mct
) "always")
6890 (equal (downcase mct
) "poster"))
6891 (or mrt reply-to from
"")
6896 (defun message-is-yours-p ()
6897 "Non-nil means current article is yours.
6898 If you have added 'cancel-messages to `message-shoot-gnksa-feet', all articles
6899 are yours except those that have Cancel-Lock header not belonging to you.
6900 Instead of shooting GNKSA feet, you should modify `message-alternative-emails'
6901 regexp to match all of yours addresses."
6902 ;; Canlock-logic as suggested by Per Abrahamsen
6903 ;; <abraham@dina.kvl.dk>
6905 ;; IF article has cancel-lock THEN
6906 ;; IF we can verify it THEN
6909 ;; error: cancellock: article is not yours
6911 ;; Use old rules, comparing sender...
6914 (message-narrow-to-head-1)
6915 (if (message-fetch-field "Cancel-Lock")
6916 (if (null (canlock-verify))
6918 (error "Failed to verify Cancel-lock: This article is not yours"))
6921 (message-gnksa-enable-p 'cancel-messages
)
6922 (and (setq sender
(message-fetch-field "sender"))
6923 (string-equal (downcase sender
)
6924 (downcase (message-make-sender))))
6925 ;; Email address in From field equals to our address
6926 (and (setq from
(message-fetch-field "from"))
6928 (downcase (car (mail-header-parse-address from
)))
6929 (downcase (car (mail-header-parse-address
6930 (message-make-from))))))
6931 ;; Email address in From field matches
6932 ;; 'message-alternative-emails' regexp
6934 message-alternative-emails
6936 message-alternative-emails
6937 (car (mail-header-parse-address from
))))))))))
6940 (defun message-cancel-news (&optional arg
)
6941 "Cancel an article you posted.
6942 If ARG, allow editing of the cancellation message."
6944 (unless (message-news-p)
6945 (error "This is not a news article; canceling is impossible"))
6946 (let (from newsgroups message-id distribution buf
)
6948 ;; Get header info from original article.
6950 (message-narrow-to-head-1)
6951 (setq from
(message-fetch-field "from")
6952 newsgroups
(message-fetch-field "newsgroups")
6953 message-id
(message-fetch-field "message-id" t
)
6954 distribution
(message-fetch-field "distribution")))
6955 ;; Make sure that this article was written by the user.
6956 (unless (message-is-yours-p)
6957 (error "This article is not yours"))
6958 (when (yes-or-no-p "Do you really want to cancel this article? ")
6959 ;; Make control message.
6962 (setq buf
(set-buffer (get-buffer-create " *message cancel*"))))
6964 (insert "Newsgroups: " newsgroups
"\n"
6966 "Subject: cmsg cancel " message-id
"\n"
6967 "Control: cancel " message-id
"\n"
6969 (concat "Distribution: " distribution
"\n")
6971 mail-header-separator
"\n"
6972 message-cancel-message
)
6973 (run-hooks 'message-cancel-hook
)
6975 (message "Canceling your article...")
6976 (if (let ((message-syntax-checks
6977 'dont-check-for-anything-just-trust-me
))
6978 (funcall message-send-news-function
))
6979 (message "Canceling your article...done"))
6980 (kill-buffer buf
))))))
6983 (defun message-supersede ()
6984 "Start composing a message to supersede the current message.
6985 This is done simply by taking the old article and adding a Supersedes
6986 header line with the old Message-ID."
6988 (let ((cur (current-buffer)))
6989 ;; Check whether the user owns the article that is to be superseded.
6990 (unless (message-is-yours-p)
6991 (error "This article is not yours"))
6992 ;; Get a normal message buffer.
6993 (message-pop-to-buffer (message-buffer-name "supersede"))
6994 (insert-buffer-substring cur
)
6996 (message-narrow-to-head-1)
6997 ;; Remove unwanted headers.
6998 (when message-ignored-supersedes-headers
6999 (message-remove-header message-ignored-supersedes-headers t
))
7000 (goto-char (point-min))
7001 (if (not (re-search-forward "^Message-ID: " nil t
))
7002 (error "No Message-ID in this article")
7003 (replace-match "Supersedes: " t t
))
7004 (goto-char (point-max))
7005 (insert mail-header-separator
)
7010 (defun message-recover ()
7011 "Reread contents of current buffer from its last auto-save file."
7013 (let ((file-name (make-auto-save-file-name)))
7014 (cond ((save-window-excursion
7015 (with-output-to-temp-buffer "*Directory*"
7016 (with-current-buffer standard-output
7017 (fundamental-mode)) ; for Emacs 20.4+
7018 (buffer-disable-undo standard-output
)
7019 (let ((default-directory "/"))
7021 "ls" nil standard-output nil
"-l" file-name
)))
7022 (yes-or-no-p (format "Recover auto save file %s? " file-name
)))
7023 (let ((buffer-read-only nil
))
7025 (insert-file-contents file-name nil
)))
7026 (t (error "message-recover cancelled")))))
7028 ;;; Washing Subject:
7030 (defun message-wash-subject (subject)
7031 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
7032 Previous forwarders, replyers, etc. may add it."
7035 (goto-char (point-min))
7036 ;; strip Re/Fwd stuff off the beginning
7037 (while (re-search-forward
7038 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t
)
7041 ;; and gnus-style forwards [foo@bar.com] subject
7042 (goto-char (point-min))
7043 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t
)
7047 (goto-char (point-max))
7048 (while (re-search-backward "([Ff][Ww][Dd])" nil t
)
7051 ;; and finally, any whitespace that was left-over
7052 (goto-char (point-min))
7053 (while (re-search-forward "^[ \t]+" nil t
)
7055 (goto-char (point-max))
7056 (while (re-search-backward "[ \t]+$" nil t
)
7061 ;;; Forwarding messages.
7063 (defvar message-forward-decoded-p nil
7064 "Non-nil means the original message is decoded.")
7066 (defun message-forward-subject-name-subject (subject)
7067 "Generate a SUBJECT for a forwarded message.
7068 The form is: [Source] Subject, where if the original message was mail,
7069 Source is the name of the sender, and if the original message was
7070 news, Source is the list of newsgroups is was posted to."
7071 (let* ((group (message-fetch-field "newsgroups"))
7072 (from (message-fetch-field "from"))
7075 (gnus-group-decoded-name group
)
7077 (car (gnus-extract-address-components from
))
7078 (cadr (gnus-extract-address-components from
))))
7081 (if message-forward-decoded-p
7083 (mail-decode-encoded-word-string prefix
))
7086 (defun message-forward-subject-author-subject (subject)
7087 "Generate a SUBJECT for a forwarded message.
7088 The form is: [Source] Subject, where if the original message was mail,
7089 Source is the sender, and if the original message was news, Source is
7090 the list of newsgroups is was posted to."
7091 (let* ((group (message-fetch-field "newsgroups"))
7094 (gnus-group-decoded-name group
)
7095 (or (message-fetch-field "from")
7098 (if message-forward-decoded-p
7100 (mail-decode-encoded-word-string prefix
))
7103 (defun message-forward-subject-fwd (subject)
7104 "Generate a SUBJECT for a forwarded message.
7105 The form is: Fwd: Subject, where Subject is the original subject of
7107 (if (string-match "^Fwd: " subject
)
7109 (concat "Fwd: " subject
)))
7111 (defun message-make-forward-subject ()
7112 "Return a Subject header suitable for the message in the current buffer."
7115 (message-narrow-to-head-1)
7116 (let ((funcs message-make-forward-subject-function
)
7117 (subject (message-fetch-field "Subject")))
7120 (if message-forward-decoded-p
7122 (mail-decode-encoded-word-string subject
))
7124 (when message-wash-forwarded-subjects
7125 (setq subject
(message-wash-subject subject
)))
7126 ;; Make sure funcs is a list.
7129 (setq funcs
(list funcs
)))
7130 ;; Apply funcs in order, passing subject generated by previous
7131 ;; func to the next one.
7132 (dolist (func funcs
)
7133 (when (functionp func
)
7134 (setq subject
(funcall func subject
))))
7137 (defvar gnus-article-decoded-p
)
7141 (defun message-forward (&optional news digest
)
7142 "Forward the current message via mail.
7143 Optional NEWS will use news to forward instead of mail.
7144 Optional DIGEST will use digest to forward."
7146 (let* ((cur (current-buffer))
7147 (message-forward-decoded-p
7148 (if (local-variable-p 'gnus-article-decoded-p
(current-buffer))
7149 gnus-article-decoded-p
;; In an article buffer.
7150 message-forward-decoded-p
))
7151 (subject (message-make-forward-subject)))
7153 (message-news nil subject
)
7154 (message-mail nil subject
))
7155 (message-forward-make-body cur digest
)))
7157 (defun message-forward-make-body-plain (forward-buffer)
7159 "\n-------------------- Start of forwarded message --------------------\n")
7161 (contents (with-current-buffer forward-buffer
(buffer-string)))
7163 (unless (featurep 'xemacs
)
7164 (unless (mm-multibyte-string-p contents
)
7165 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7166 to the multibyte buffer \"%s\""
7167 (if (bufferp forward-buffer
)
7168 (buffer-name forward-buffer
)
7171 (insert (mm-with-multibyte-buffer
7174 (goto-char (point-min))
7175 (when (looking-at "From ")
7176 (replace-match "X-From-Line: "))
7178 (unless (bolp) (insert "\n"))
7181 "-------------------- End of forwarded message --------------------\n")
7182 (message-remove-ignored-headers b e
)))
7184 (defun message-remove-ignored-headers (b e
)
7185 (when message-forward-ignored-headers
7187 (narrow-to-region b e
)
7189 (narrow-to-region (point)
7190 (or (search-forward "\n\n" nil t
) (point)))
7191 (let ((ignored (if (stringp message-forward-ignored-headers
)
7192 (list message-forward-ignored-headers
)
7193 message-forward-ignored-headers
)))
7194 (dolist (elem ignored
)
7195 (message-remove-header elem t
))))))
7197 (defun message-forward-make-body-mime (forward-buffer)
7199 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
7201 (narrow-to-region (point) (point))
7202 (mml-insert-buffer forward-buffer
)
7203 (goto-char (point-min))
7204 (when (looking-at "From ")
7205 (replace-match "X-From-Line: "))
7206 (goto-char (point-max)))
7207 (insert "<#/part>\n")
7208 ;; Consider there is no illegible text.
7209 (add-text-properties
7211 `(no-illegible-text t rear-nonsticky t start-open t
))))
7213 (defun message-forward-make-body-mml (forward-buffer)
7214 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
7215 (let ((b (point)) e
)
7216 (if (not message-forward-decoded-p
)
7217 (let ((contents (with-current-buffer forward-buffer
(buffer-string))))
7218 (unless (featurep 'xemacs
)
7219 (unless (mm-multibyte-string-p contents
)
7220 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7221 to the multibyte buffer \"%s\""
7222 (if (bufferp forward-buffer
)
7223 (buffer-name forward-buffer
)
7226 (insert (mm-with-multibyte-buffer
7229 (goto-char (point-min))
7230 (when (looking-at "From ")
7231 (replace-match "X-From-Line: "))
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))))
7241 (insert "<#/mml>\n")
7242 (when (and (not message-forward-decoded-p
)
7243 message-forward-ignored-headers
)
7244 (message-remove-ignored-headers b e
))))
7246 (defun message-forward-make-body-digest-plain (forward-buffer)
7248 "\n-------------------- Start of forwarded message --------------------\n")
7249 (let ((b (point)) e
)
7250 (mml-insert-buffer forward-buffer
)
7253 "\n-------------------- End of forwarded message --------------------\n")))
7255 (defun message-forward-make-body-digest-mime (forward-buffer)
7256 (insert "\n<#multipart type=digest>\n")
7257 (let ((b (point)) e
)
7258 (insert-buffer-substring forward-buffer
)
7260 (insert "<#/multipart>\n")
7262 (narrow-to-region b e
)
7264 (narrow-to-region (point)
7265 (or (search-forward "\n\n" nil t
) (point)))
7266 (delete-region (point-min) (point-max)))))
7268 (defun message-forward-make-body-digest (forward-buffer)
7269 (if message-forward-as-mime
7270 (message-forward-make-body-digest-mime forward-buffer
)
7271 (message-forward-make-body-digest-plain forward-buffer
)))
7273 (autoload 'mm-uu-dissect-text-parts
"mm-uu")
7274 (autoload 'mm-uu-dissect
"mm-uu")
7276 (defun message-signed-or-encrypted-p (&optional dont-emulate-mime handles
)
7277 "Say whether the current buffer contains signed or encrypted message.
7278 If DONT-EMULATE-MIME is nil, this function does the MIME emulation on
7279 messages that don't conform to PGP/MIME described in RFC2015. HANDLES
7280 is for the internal use."
7282 (let ((mm-decrypt-option 'never
)
7283 (mm-verify-option 'never
))
7284 (if (setq handles
(mm-dissect-buffer nil t
))
7285 (unless dont-emulate-mime
7286 (mm-uu-dissect-text-parts handles
))
7287 (unless dont-emulate-mime
7288 (setq handles
(mm-uu-dissect))))))
7289 ;; Check text/plain message in which there is a signed or encrypted
7290 ;; body that has been encoded by B or Q.
7291 (unless (or handles dont-emulate-mime
)
7292 (let ((cur (current-buffer))
7293 (mm-decrypt-option 'never
)
7294 (mm-verify-option 'never
))
7296 (insert-buffer-substring cur
)
7297 (when (setq handles
(mm-dissect-buffer t t
))
7299 (bufferp (car handles
))
7300 (mm-destroy-parts handles
))
7301 (equal (mm-handle-media-type handles
) "text/plain"))
7303 (mm-decode-content-transfer-encoding
7304 (mm-handle-encoding handles
))
7305 (setq handles
(mm-uu-dissect)))
7306 (setq handles nil
))))))
7310 (dolist (handle (if (stringp (car handles
))
7311 (if (member (car handles
)
7312 '("multipart/signed"
7313 "multipart/encrypted"))
7317 (if (stringp (car handle
))
7318 (when (message-signed-or-encrypted-p dont-emulate-mime handle
)
7320 (when (and (bufferp (car handle
))
7321 (equal (mm-handle-media-type handle
)
7323 (with-current-buffer (mm-handle-buffer handle
)
7324 (when (message-signed-or-encrypted-p dont-emulate-mime
)
7325 (throw 'found t
)))))))
7326 (mm-destroy-parts handles
))))
7329 (defun message-forward-make-body (forward-buffer &optional digest
)
7330 ;; Put point where we want it before inserting the forwarded
7332 (if message-forward-before-signature
7334 (goto-char (point-max)))
7336 (message-forward-make-body-digest forward-buffer
)
7337 (if message-forward-as-mime
7338 (if (and message-forward-show-mml
7339 (not (and (eq message-forward-show-mml
'best
)
7340 ;; Use the raw form in the body if it contains
7341 ;; signed or encrypted message so as not to be
7342 ;; destroyed by re-encoding.
7343 (with-current-buffer forward-buffer
7345 (message-signed-or-encrypted-p)
7347 (message-forward-make-body-mml forward-buffer
)
7348 (message-forward-make-body-mime forward-buffer
))
7349 (message-forward-make-body-plain forward-buffer
)))
7350 (message-position-point))
7352 (declare-function rmail-toggle-header
"rmail" (&optional arg
))
7355 (defun message-forward-rmail-make-body (forward-buffer)
7356 (save-window-excursion
7357 (set-buffer forward-buffer
)
7358 (if (rmail-msg-is-pruned)
7359 (if (fboundp 'rmail-msg-restore-non-pruned-header
)
7360 (rmail-msg-restore-non-pruned-header) ; Emacs 22
7361 (rmail-toggle-header 0)))) ; Emacs 23
7362 (message-forward-make-body forward-buffer
))
7364 ;; Fixme: Should have defcustom.
7366 (defun message-insinuate-rmail ()
7367 "Let RMAIL use message to forward."
7369 (setq rmail-enable-mime-composing t
)
7370 (setq rmail-insert-mime-forwarded-message-function
7371 'message-forward-rmail-make-body
))
7374 (defun message-resend (address)
7375 "Resend the current article to ADDRESS."
7377 (list (message-read-from-minibuffer "Resend message to: ")))
7378 (message "Resending message to %s..." address
)
7380 (let ((cur (current-buffer))
7382 ;; We first set up a normal mail buffer.
7383 (unless (message-mail-user-agent)
7384 (set-buffer (get-buffer-create " *message resend*"))
7386 (let ((message-this-is-mail t
)
7387 message-generate-hashcash
7389 (message-setup `((To .
,address
))))
7390 ;; Insert our usual headers.
7391 (message-generate-headers '(From Date To Message-ID
))
7392 (message-narrow-to-headers)
7393 ;; Remove X-Draft-From header etc.
7394 (message-remove-header message-ignored-mail-headers t
)
7395 ;; Rename them all to "Resent-*".
7396 (goto-char (point-min))
7397 (while (re-search-forward "^[A-Za-z]" nil t
)
7402 (delete-region (point) (point-max))
7404 ;; Insert the message to be resent.
7405 (insert-buffer-substring cur
)
7406 (goto-char (point-min))
7407 (search-forward "\n\n")
7410 (narrow-to-region beg
(point))
7411 (message-remove-header message-ignored-resent-headers t
)
7412 (goto-char (point-max)))
7413 (insert mail-header-separator
)
7414 ;; Rename all old ("Also-")Resent headers.
7415 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t
)
7418 ;; Quote any "From " lines at the beginning.
7420 (when (looking-at "From ")
7421 (replace-match "X-From-Line: "))
7423 (let ((message-inhibit-body-encoding t
)
7424 (message-inhibit-ecomplete t
)
7425 message-required-mail-headers
7426 message-generate-hashcash
7427 rfc2047-encode-encoded-words
)
7428 (message-send-mail))
7429 (kill-buffer (current-buffer)))
7430 (message "Resending message to %s...done" address
)))
7433 (defun message-bounce ()
7434 "Re-mail the current message.
7435 This only makes sense if the current message is a bounce message that
7436 contains some mail you have written which has been bounced back to
7439 (let ((handles (mm-dissect-buffer t
))
7441 (message-pop-to-buffer (message-buffer-name "bounce"))
7442 (if (stringp (car handles
))
7443 ;; This is a MIME bounce.
7444 (mm-insert-part (car (last handles
)))
7445 ;; This is a non-MIME bounce, so we try to remove things
7447 (mm-insert-part handles
)
7449 (goto-char (point-min))
7450 (re-search-forward "\n\n+" nil t
)
7451 (setq boundary
(point))
7452 ;; We remove everything before the bounced mail.
7453 (if (or (re-search-forward message-unsent-separator nil t
)
7455 (search-forward "\n\n" nil
'move
)
7456 (re-search-backward "^Return-Path:.*\n" boundary t
)))
7459 (delete-region (point-min)
7460 (if (re-search-forward "^[^ \n\t]+:" nil t
)
7463 (goto-char boundary
)
7464 (when (re-search-backward "^.?From .*\n" nil t
)
7465 (delete-region (match-beginning 0) (match-end 0)))))
7468 (message-narrow-to-head-1)
7469 (message-remove-header message-ignored-bounced-headers t
)
7470 (goto-char (point-max))
7471 (insert mail-header-separator
))
7472 (message-position-point)))
7475 ;;; Interactive entry points for new message buffers.
7479 (defun message-mail-other-window (&optional to subject
)
7480 "Like `message-mail' command, but display mail buffer in another window."
7482 (unless (message-mail-user-agent)
7483 (let ((pop-up-windows t
)
7484 (special-display-buffer-names nil
)
7485 (special-display-regexps nil
)
7486 (same-window-buffer-names nil
)
7487 (same-window-regexps nil
))
7488 (message-pop-to-buffer (message-buffer-name "mail" to
))))
7489 (let ((message-this-is-mail t
))
7490 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
"")))
7491 nil nil nil
'switch-to-buffer-other-window
)))
7494 (defun message-mail-other-frame (&optional to subject
)
7495 "Like `message-mail' command, but display mail buffer in another frame."
7497 (unless (message-mail-user-agent)
7498 (let ((pop-up-frames t
)
7499 (special-display-buffer-names nil
)
7500 (special-display-regexps nil
)
7501 (same-window-buffer-names nil
)
7502 (same-window-regexps nil
))
7503 (message-pop-to-buffer (message-buffer-name "mail" to
))))
7504 (let ((message-this-is-mail t
))
7505 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
"")))
7506 nil nil nil
'switch-to-buffer-other-frame
)))
7509 (defun message-news-other-window (&optional newsgroups subject
)
7510 "Start editing a news article to be sent."
7512 (let ((pop-up-windows t
)
7513 (special-display-buffer-names nil
)
7514 (special-display-regexps nil
)
7515 (same-window-buffer-names nil
)
7516 (same-window-regexps nil
))
7517 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
)))
7518 (let ((message-this-is-news t
))
7519 (message-setup `((Newsgroups .
,(or newsgroups
""))
7520 (Subject .
,(or subject
""))))))
7523 (defun message-news-other-frame (&optional newsgroups subject
)
7524 "Start editing a news article to be sent."
7526 (let ((pop-up-frames t
)
7527 (special-display-buffer-names nil
)
7528 (special-display-regexps nil
)
7529 (same-window-buffer-names nil
)
7530 (same-window-regexps nil
))
7531 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
)))
7532 (let ((message-this-is-news t
))
7533 (message-setup `((Newsgroups .
,(or newsgroups
""))
7534 (Subject .
,(or subject
""))))))
7538 ;; This code should be moved to underline.el (from which it is stolen).
7541 (defun message-bold-region (start end
)
7542 "Bold all nonblank characters in the region.
7543 Works by overstriking characters.
7544 Called from program, takes two arguments START and END
7545 which specify the range to operate on."
7548 (let ((end1 (make-marker)))
7549 (move-marker end1
(max start end
))
7550 (goto-char (min start end
))
7551 (while (< (point) end1
)
7552 (or (looking-at "[_\^@- ]")
7553 (insert (char-after) "\b"))
7554 (forward-char 1)))))
7557 (defun message-unbold-region (start end
)
7558 "Remove all boldness (overstruck characters) in the region.
7559 Called from program, takes two arguments START and END
7560 which specify the range to operate on."
7563 (let ((end1 (make-marker)))
7564 (move-marker end1
(max start end
))
7565 (goto-char (min start end
))
7566 (while (search-forward "\b" end1 t
)
7567 (if (eq (char-after) (char-after (- (point) 2)))
7568 (delete-char -
2))))))
7570 (defun message-exchange-point-and-mark ()
7571 "Exchange point and mark, but don't activate region if it was inactive."
7572 (goto-char (prog1 (mark t
)
7573 (set-marker (mark-marker) (point)))))
7575 (defalias 'message-make-overlay
'make-overlay
)
7576 (defalias 'message-delete-overlay
'delete-overlay
)
7577 (defalias 'message-overlay-put
'overlay-put
)
7578 (defun message-kill-all-overlays ()
7579 (if (featurep 'xemacs
)
7580 (map-extents (lambda (extent ignore
) (delete-extent extent
)))
7581 (mapcar #'delete-overlay
(overlays-in (point-min) (point-max)))))
7583 ;; Support for toolbar
7584 (defvar tool-bar-mode
)
7586 ;; Note: The :set function in the `message-tool-bar*' variables will only
7587 ;; affect _new_ message buffers. We might add a function that walks thru all
7588 ;; message-mode buffers and force the update.
7589 (defun message-tool-bar-update (&optional symbol value
)
7590 "Update message mode toolbar.
7591 Setter function for custom variables."
7592 (setq-default message-tool-bar-map nil
)
7594 ;; When used as ":set" function:
7595 (set-default symbol value
)))
7597 (defcustom message-tool-bar
(if (eq gmm-tool-bar-style
'gnome
)
7598 'message-tool-bar-gnome
7599 'message-tool-bar-retro
)
7600 "Specifies the message mode tool bar.
7602 It can be either a list or a symbol refering to a list. See
7603 `gmm-tool-bar-from-list' for the format of the list. The
7604 default key map is `message-mode-map'.
7606 Pre-defined symbols include `message-tool-bar-gnome' and
7607 `message-tool-bar-retro'."
7608 :type
'(repeat gmm-tool-bar-list-item
)
7609 :type
'(choice (const :tag
"GNOME style" message-tool-bar-gnome
)
7610 (const :tag
"Retro look" message-tool-bar-retro
)
7611 (repeat :tag
"User defined list" gmm-tool-bar-item
)
7613 :version
"23.1" ;; No Gnus
7614 :initialize
'custom-initialize-default
7615 :set
'message-tool-bar-update
7618 (defcustom message-tool-bar-gnome
7619 '((ispell-message "spell" nil
7620 :visible
(or (not (boundp 'flyspell-mode
))
7621 (not flyspell-mode
)))
7622 (flyspell-buffer "spell" t
7623 :visible
(and (boundp 'flyspell-mode
)
7625 :help
"Flyspell whole buffer")
7626 (gmm-ignore "separator")
7627 (message-send-and-exit "mail/send")
7628 (message-dont-send "mail/save-draft")
7629 (message-kill-buffer "close") ;; stock_cancel
7630 (mml-attach-file "attach" mml-mode-map
)
7631 (mml-preview "mail/preview" mml-mode-map
)
7632 (mml-secure-message-sign-encrypt "lock" mml-mode-map
:visible nil
)
7633 (message-insert-importance-high "important" nil
:visible nil
)
7634 (message-insert-importance-low "unimportant" nil
:visible nil
)
7635 (message-insert-disposition-notification-to "receipt" nil
:visible nil
)
7636 (gmm-customize-mode "preferences" t
:help
"Edit mode preferences")
7637 (message-info "help" t
:help
"Message manual"))
7638 "List of items for the message tool bar (GNOME style).
7640 See `gmm-tool-bar-from-list' for details on the format of the list."
7641 :type
'(repeat gmm-tool-bar-item
)
7642 :version
"23.1" ;; No Gnus
7643 :initialize
'custom-initialize-default
7644 :set
'message-tool-bar-update
7647 (defcustom message-tool-bar-retro
7648 '(;; Old Emacs 21 icon for consistency.
7649 (message-send-and-exit "gnus/mail-send")
7650 (message-kill-buffer "close")
7651 (message-dont-send "cancel")
7652 (mml-attach-file "attach" mml-mode-map
)
7653 (ispell-message "spell")
7654 (mml-preview "preview" mml-mode-map
)
7655 (message-insert-importance-high "gnus/important")
7656 (message-insert-importance-low "gnus/unimportant")
7657 (message-insert-disposition-notification-to "gnus/receipt"))
7658 "List of items for the message tool bar (retro style).
7660 See `gmm-tool-bar-from-list' for details on the format of the list."
7661 :type
'(repeat gmm-tool-bar-item
)
7662 :version
"23.1" ;; No Gnus
7663 :initialize
'custom-initialize-default
7664 :set
'message-tool-bar-update
7667 (defcustom message-tool-bar-zap-list
7668 '(new-file open-file dired kill-buffer write-file
7669 print-buffer customize help
)
7670 "List of icon items from the global tool bar.
7671 These items are not displayed on the message mode tool bar.
7673 See `gmm-tool-bar-from-list' for the format of the list."
7674 :type
'gmm-tool-bar-zap-list
7675 :version
"23.1" ;; No Gnus
7676 :initialize
'custom-initialize-default
7677 :set
'message-tool-bar-update
7680 (defvar image-load-path
)
7682 (defun message-make-tool-bar (&optional force
)
7683 "Make a message mode tool bar from `message-tool-bar-list'.
7684 When FORCE, rebuild the tool bar."
7685 (when (and (not (featurep 'xemacs
))
7686 (boundp 'tool-bar-mode
)
7688 (or (not message-tool-bar-map
) force
))
7689 (setq message-tool-bar-map
7691 (gmm-image-load-path-for-library "message"
7692 "mail/save-draft.xpm"
7694 (image-load-path (cons (car load-path
)
7695 (when (boundp 'image-load-path
)
7697 (gmm-tool-bar-from-list message-tool-bar
7698 message-tool-bar-zap-list
7699 'message-mode-map
))))
7700 message-tool-bar-map
)
7702 ;;; Group name completion.
7704 (defcustom message-newgroups-header-regexp
7705 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
7706 "Regexp that match headers that lists groups."
7710 (defcustom message-completion-alist
7711 (list (cons message-newgroups-header-regexp
'message-expand-group
)
7712 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name
)
7713 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
7714 . message-expand-name
)
7715 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
7716 . message-expand-name
))
7717 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
7720 :type
'(alist :key-type regexp
:value-type function
))
7722 (defcustom message-expand-name-databases
7724 "List of databases to try for name completion (`message-expand-name').
7725 Each element is a symbol and can be `bbdb' or `eudc'."
7727 :type
'(set (const bbdb
) (const eudc
)))
7729 (defcustom message-tab-body-function nil
7730 "*Function to execute when `message-tab' (TAB) is executed in the body.
7731 If nil, the function bound in `text-mode-map' or `global-map' is executed."
7734 :link
'(custom-manual "(message)Various Commands")
7735 :type
'(choice (const nil
)
7738 (declare-function mail-abbrev-in-expansion-header-p
"mailabbrev" ())
7740 (defun message-tab ()
7741 "Complete names according to `message-completion-alist'.
7742 Execute function specified by `message-tab-body-function' when not in
7745 (let ((alist message-completion-alist
))
7747 (let ((mail-abbrev-mode-regexp (caar alist
)))
7748 (not (mail-abbrev-in-expansion-header-p))))
7749 (setq alist
(cdr alist
)))
7750 (funcall (or (cdar alist
) message-tab-body-function
7751 (lookup-key text-mode-map
"\t")
7752 (lookup-key global-map
"\t")
7753 'indent-relative
))))
7758 (let ((standard-output (current-buffer)))
7759 (eval '(display-completion-list nil
"")))
7760 (defalias 'message-display-completion-list
'display-completion-list
))
7761 (error ;; Don't use `wrong-number-of-arguments' here because of XEmacs.
7762 (defun message-display-completion-list (completions &optional ignore
)
7763 "Display the list of completions, COMPLETIONS, using `standard-output'."
7764 (display-completion-list completions
)))))
7766 (defun message-expand-group ()
7767 "Expand the group name under point."
7768 (let* ((b (save-excursion
7773 (skip-chars-forward "^:")
7776 (skip-chars-backward "^, \t\n") (point))))
7777 (completion-ignore-case t
)
7778 (e (progn (skip-chars-forward "^,\t\n ") (point)))
7779 (hashtb (and (boundp 'gnus-active-hashtb
) gnus-active-hashtb
)))
7780 (message-completion-in-region e b hashtb
)))
7782 (defalias 'message-completion-in-region
7783 (if (fboundp 'completion-in-region
)
7784 'completion-in-region
7785 (lambda (e b hashtb
)
7786 (let* ((string (buffer-substring b e
))
7787 (completions (all-completions string hashtb
))
7789 (delete-region b
(point))
7791 ((= (length completions
) 1)
7792 (if (string= (car completions
) string
)
7795 (message "Only matching group"))
7796 (insert (car completions
))))
7797 ((and (setq comp
(try-completion string hashtb
))
7798 (not (string= comp string
)))
7803 (message "No matching groups")
7804 (save-selected-window
7805 (pop-to-buffer "*Completions*")
7806 (buffer-disable-undo)
7807 (let ((buffer-read-only nil
))
7809 (let ((standard-output (current-buffer)))
7810 (message-display-completion-list (sort completions
'string
<)
7812 (setq buffer-read-only nil
)
7813 (goto-char (point-min))
7814 (delete-region (point)
7815 (progn (forward-line 3) (point))))))))))))
7817 (defun message-expand-name ()
7818 (cond ((and (memq 'eudc message-expand-name-databases
)
7819 (boundp 'eudc-protocol
)
7821 (eudc-expand-inline))
7822 ((and (memq 'bbdb message-expand-name-databases
)
7823 (fboundp 'bbdb-complete-name
))
7824 (bbdb-complete-name))
7830 (defun message-talkative-question (ask question show
&rest text
)
7831 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
7832 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
7833 The following arguments may contain lists of values."
7835 (setq text
(message-flatten-list text
)))
7836 (save-window-excursion
7837 (with-output-to-temp-buffer " *MESSAGE information message*"
7838 (with-current-buffer " *MESSAGE information message*"
7839 (fundamental-mode) ; for Emacs 20.4+
7841 (goto-char (point-min))))
7842 (funcall ask question
))
7843 (funcall ask question
)))
7845 (defun message-flatten-list (list)
7846 "Return a new, flat list that contains all elements of LIST.
7848 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
7851 (apply 'append
(mapcar 'message-flatten-list list
)))
7855 (defun message-generate-new-buffer-clone-locals (name &optional varstr
)
7856 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
7857 Then clone the local variables and values from the old buffer to the
7858 new one, cloning only the locals having a substring matching the
7860 (let ((oldbuf (current-buffer)))
7861 (with-current-buffer (generate-new-buffer name
)
7862 (message-clone-locals oldbuf varstr
)
7865 (defun message-clone-locals (buffer &optional varstr
)
7866 "Clone the local variables from BUFFER to the current buffer."
7867 (let ((locals (with-current-buffer buffer
(buffer-local-variables)))
7868 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address"))
7871 (when (and (consp local
)
7873 (string-match regexp
(symbol-name (car local
)))
7875 (string-match varstr
(symbol-name (car local
)))))
7877 (set (make-local-variable (car local
))
7885 (defvar message-inhibit-body-encoding nil
)
7887 (defun message-encode-message-body ()
7888 (unless message-inhibit-body-encoding
7889 (let ((mail-parse-charset (or mail-parse-charset
7890 message-default-charset
))
7891 (case-fold-search t
)
7892 lines content-type-p
)
7895 (narrow-to-region (point) (point-max))
7896 (let ((new (mml-generate-mime)))
7898 (delete-region (point-min) (point-max))
7900 (goto-char (point-min))
7901 (if (eq (aref new
0) ?
\n)
7903 (search-forward "\n\n")
7904 (setq lines
(buffer-substring (point-min) (1- (point))))
7905 (delete-region (point-min) (point))))))
7907 (message-narrow-to-headers-or-head)
7908 (message-remove-header "Mime-Version")
7909 (goto-char (point-max))
7910 (insert "MIME-Version: 1.0\n")
7913 (setq content-type-p
7915 (re-search-backward "^Content-Type:" nil t
))))
7917 (message-narrow-to-headers-or-head)
7918 (message-remove-first-header "Content-Type")
7919 (message-remove-first-header "Content-Transfer-Encoding"))
7920 ;; We always make sure that the message has a Content-Type
7921 ;; header. This is because some broken MTAs and MUAs get
7922 ;; awfully confused when confronted with a message with a
7923 ;; MIME-Version header and without a Content-Type header. For
7924 ;; instance, Solaris' /usr/bin/mail.
7925 (unless content-type-p
7926 (goto-char (point-min))
7927 ;; For unknown reason, MIME-Version doesn't exist.
7928 (when (re-search-forward "^MIME-Version:" nil t
)
7930 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
7932 (defun message-read-from-minibuffer (prompt &optional initial-contents
)
7933 "Read from the minibuffer while providing abbrev expansion."
7934 (if (fboundp 'mail-abbrevs-setup
)
7935 (let ((mail-abbrev-mode-regexp "")
7936 (minibuffer-setup-hook 'mail-abbrevs-setup
)
7937 (minibuffer-local-map message-minibuffer-local-map
))
7938 (read-from-minibuffer prompt initial-contents
))
7939 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook
)
7940 (minibuffer-local-map message-minibuffer-local-map
))
7941 (read-string prompt initial-contents
))))
7943 (defun message-use-alternative-email-as-from ()
7944 "Set From field of the outgoing message to the first matching
7945 address in `message-alternative-emails', looking at To, Cc and
7946 From headers in the original article."
7947 (require 'mail-utils
)
7948 (let* ((fields '("To" "Cc" "From"))
7951 (mail-strip-quoted-names
7952 (mapconcat 'message-fetch-reply-field fields
","))
7956 (if (string-match message-alternative-emails
(car emails
))
7957 (setq email
(car emails
)
7960 (unless (or (not email
) (equal email user-mail-address
))
7961 (message-remove-header "From")
7962 (goto-char (point-max))
7963 (insert "From: " (let ((user-mail-address email
)) (message-make-from))
7966 (defun message-options-get (symbol)
7967 (cdr (assq symbol message-options
)))
7969 (defun message-options-set (symbol value
)
7970 (let ((the-cons (assq symbol message-options
)))
7973 (setcdr the-cons value
)
7974 (setq message-options
(delq the-cons message-options
)))
7976 (push (cons symbol value
) message-options
))))
7979 (defun message-options-set-recipient ()
7981 (message-narrow-to-headers-or-head)
7982 (message-options-set 'message-sender
7983 (mail-strip-quoted-names
7984 (message-fetch-field "from")))
7985 (message-options-set 'message-recipients
7986 (mail-strip-quoted-names
7987 (let ((to (message-fetch-field "to"))
7988 (cc (message-fetch-field "cc"))
7989 (bcc (message-fetch-field "bcc")))
7992 (if (and to cc
) ", ")
7994 (if (and (or to cc
) bcc
) ", ")
7997 (defun message-hide-headers ()
7998 "Hide headers based on the `message-hidden-headers' variable."
7999 (let ((regexps (if (stringp message-hidden-headers
)
8000 (list message-hidden-headers
)
8001 message-hidden-headers
))
8002 (inhibit-point-motion-hooks t
)
8003 (after-change-functions nil
)
8004 (end-of-headers (point-min)))
8008 (message-narrow-to-headers)
8009 (goto-char (point-min))
8011 (if (not (message-hide-header-p regexps
))
8012 (message-next-header)
8013 (let ((begin (point))
8015 (message-next-header)
8016 (setq header
(buffer-substring begin
(point))
8017 header-len
(- (point) begin
))
8018 (delete-region begin
(point))
8019 (goto-char end-of-headers
)
8021 (setq end-of-headers
8022 (+ end-of-headers header-len
))))))))
8023 (narrow-to-region end-of-headers
(point-max))))
8025 (defun message-hide-header-p (regexps)
8028 (when (eq (car regexps
) 'not
)
8031 (dolist (regexp regexps
)
8032 (setq result
(or result
(looking-at regexp
))))
8037 (declare-function ecomplete-add-item
"ecomplete" (type key text
))
8038 (declare-function ecomplete-save
"ecomplete" ())
8040 (defun message-put-addresses-in-ecomplete ()
8041 (require 'ecomplete
)
8042 (dolist (header '("to" "cc" "from" "reply-to"))
8043 (let ((value (message-field-value header
)))
8044 (dolist (string (mail-header-parse-addresses value
'raw
))
8046 (gnus-replace-in-string
8047 (gnus-replace-in-string string
"^ +\\| +$" "") "\n" ""))
8048 (ecomplete-add-item 'mail
(car (mail-header-parse-address string
))
8052 (autoload 'ecomplete-display-matches
"ecomplete")
8054 (defun message-display-abbrev (&optional choose
)
8055 "Display the next possible abbrev for the text before point."
8056 (interactive (list t
))
8057 (when (and (memq (char-after (point-at-bol)) '(?C ?T ?
\t ?
))
8058 (message-point-in-header-p)
8061 (while (and (memq (char-after) '(?
\t ?
))
8062 (zerop (forward-line -
1))))
8063 (looking-at "To:\\|Cc:")))
8064 (let* ((end (point))
8065 (start (save-excursion
8066 (and (re-search-backward "[\n\t ]" nil t
)
8068 (word (when start
(buffer-substring start end
)))
8069 (match (when (and word
8070 (not (zerop (length word
))))
8071 (ecomplete-display-matches 'mail word choose
))))
8072 (when (and choose match
)
8073 (delete-region start end
)
8076 ;; To send pre-formatted letters like the example below, you can use
8077 ;; `message-send-form-letter':
8078 ;; --8<---------------cut here---------------start------------->8---
8079 ;; To: alice@invalid.invalid
8080 ;; Subject: Verification of your contact information
8081 ;; From: Contact verification <admin@foo.invalid>
8082 ;; --text follows this line--
8084 ;; please verify that your contact information is still valid:
8085 ;; Alice A, A avenue 11, 1111 A town, Austria
8086 ;; ----------next form letter message follows this line----------
8087 ;; To: bob@invalid.invalid
8088 ;; Subject: Verification of your contact information
8089 ;; From: Contact verification <admin@foo.invalid>
8090 ;; --text follows this line--
8092 ;; please verify that your contact information is still valid:
8093 ;; Bob, B street 22, 22222 Be town, Belgium
8094 ;; ----------next form letter message follows this line----------
8095 ;; To: charlie@invalid.invalid
8096 ;; Subject: Verification of your contact information
8097 ;; From: Contact verification <admin@foo.invalid>
8098 ;; --text follows this line--
8100 ;; please verify that your contact information is still valid:
8101 ;; Charlie Chaplin, C plaza 33, 33333 C town, Chile
8102 ;; --8<---------------cut here---------------end--------------->8---
8104 ;; FIXME: What is the most common term (circular letter, form letter, serial
8105 ;; letter, standard letter) for such kind of letter? See also
8106 ;; <http://en.wikipedia.org/wiki/Form_letter>
8108 ;; FIXME: Maybe extent message-mode's font-lock support to recognize
8109 ;; `message-form-letter-separator', i.e. highlight each message like a single
8112 (defcustom message-form-letter-separator
8113 "\n----------next form letter message follows this line----------\n"
8114 "Separator for `message-send-form-letter'."
8115 ;; :group 'message-form-letter
8116 :group
'message-various
8117 :version
"23.1" ;; No Gnus
8120 (defcustom message-send-form-letter-delay
1
8121 "Delay in seconds when sending a message with `message-send-form-letter'.
8122 Only used when `message-send-form-letter' is called with non-nil
8124 ;; :group 'message-form-letter
8125 :group
'message-various
8126 :version
"23.1" ;; No Gnus
8129 (defun message-send-form-letter (&optional force
)
8130 "Sent all form letter messages from current buffer.
8131 Unless FORCE, prompt before sending.
8133 The messages are separated by `message-form-letter-separator'.
8134 Header and body are separated by `mail-header-separator'."
8136 (let ((sent 0) (skipped 0)
8140 (goto-char (point-min))
8143 end
(if (search-forward message-form-letter-separator nil t
)
8144 (- (point) (length message-form-letter-separator
) -
1)
8148 (buffer-substring-no-properties start end
))
8149 (setq buff
(generate-new-buffer "*mail - form letter*"))
8150 (with-current-buffer buff
8153 (setq to
(message-fetch-field "To"))
8154 (switch-to-buffer buff
)
8156 (sit-for message-send-form-letter-delay
))
8158 (y-or-n-p (format "Send message to `%s'? " to
)))
8160 (setq sent
(1+ sent
))
8161 (message-send-and-exit))
8162 (message (format "Message to `%s' skipped." to
))
8163 (setq skipped
(1+ skipped
)))
8164 (when (buffer-live-p buff
)
8165 (kill-buffer buff
))))
8166 (message "%s message(s) sent, %s skipped." sent skipped
)))
8168 (defun message-replace-header (header new-value
&optional after force
)
8169 "Remove HEADER and insert the NEW-VALUE.
8170 If AFTER, insert after this header. If FORCE, insert new field
8171 even if NEW-VALUE is empty."
8172 ;; Similar to `nnheader-replace-header' but for message buffers.
8175 (message-narrow-to-headers)
8176 (message-remove-header header
))
8177 (when (or force
(> (length new-value
) 0))
8179 (message-position-on-field header after
)
8180 (message-position-on-field header
))
8181 (insert new-value
))))
8183 (defcustom message-recipients-without-full-name
8184 (list "ding@gnus.org"
8186 "emacs-devel@gnu.org"
8187 "emacs-pretest-bug@gnu.org"
8188 "bug-gnu-emacs@gnu.org")
8189 "Mail addresses that have no full name.
8190 Used in `message-simplify-recipients'."
8191 ;; Maybe the addresses could be extracted from
8192 ;; `gnus-parameter-to-list-alist'?
8193 :type
'(choice (const :tag
"None" nil
)
8195 :version
"23.1" ;; No Gnus
8196 :group
'message-headers
)
8198 (defun message-simplify-recipients ()
8200 (dolist (hdr '("Cc" "To"))
8201 (message-replace-header
8205 (if (and message-recipients-without-full-name
8207 (regexp-opt message-recipients-without-full-name
)
8211 (message-make-from (car addrcomp
) (cadr addrcomp
))
8213 (when (message-fetch-field hdr
)
8214 (mail-extract-address-components
8215 (message-fetch-field hdr
) t
))
8218 (when (featurep 'xemacs
)
8219 (require 'messagexmas
)
8220 (message-xmas-redefine))
8224 (run-hooks 'message-load-hook
)
8227 ;; coding: iso-8859-1
8230 ;;; message.el ends here