1 ;;; message.el --- composing mail and news messages
3 ;; Copyright (C) 1996-2011 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: mail, news
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;; This mode provides mail-sending facilities from within Emacs. It
26 ;; consists mainly of large chunks of code from the sendmail.el,
27 ;; gnus-msg.el and rnewspost.el files.
31 ;; For Emacs <22.2 and XEmacs.
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 t
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 (defcustom message-user-organization
510 (or (getenv "ORGANIZATION") t
)
511 "String to be used as an Organization header.
512 If t, use `message-user-organization-file'."
513 :group
'message-headers
514 :type
'(choice string
515 (const :tag
"consult file" t
)))
517 (defcustom message-user-organization-file
519 (dolist (f (list "/etc/organization"
520 "/etc/news/organization"
521 "/usr/lib/news/organization"))
522 (when (file-readable-p f
)
525 "*Local news organization file."
527 :link
'(custom-manual "(message)News Headers")
528 :group
'message-headers
)
530 (defcustom message-make-forward-subject-function
531 #'message-forward-subject-name-subject
532 "*List of functions called to generate subject headers for forwarded messages.
533 The subject generated by the previous function is passed into each
536 The provided functions are:
538 * `message-forward-subject-author-subject' Source of article (author or
539 newsgroup), in brackets followed by the subject
540 * `message-forward-subject-name-subject' Source of article (name of author
541 or newsgroup), in brackets followed by the subject
542 * `message-forward-subject-fwd' Subject of article with 'Fwd:' prepended
544 :group
'message-forwarding
545 :link
'(custom-manual "(message)Forwarding")
546 :type
'(radio (function-item message-forward-subject-author-subject
)
547 (function-item message-forward-subject-fwd
)
548 (function-item message-forward-subject-name-subject
)
549 (repeat :tag
"List of functions" function
)))
551 (defcustom message-forward-as-mime t
552 "*Non-nil means forward messages as an inline/rfc822 MIME section.
553 Otherwise, directly inline the old message in the forwarded message."
555 :group
'message-forwarding
556 :link
'(custom-manual "(message)Forwarding")
559 (defcustom message-forward-show-mml
'best
560 "*Non-nil means show forwarded messages as MML (decoded from MIME).
561 Otherwise, forwarded messages are unchanged.
562 Can also be the symbol `best' to indicate that MML should be
563 used, except when it is a bad idea to use MML. One example where
564 it is a bad idea is when forwarding a signed or encrypted
565 message, because converting MIME to MML would invalidate the
568 :group
'message-forwarding
569 :type
'(choice (const :tag
"use MML" t
)
570 (const :tag
"don't use MML " nil
)
571 (const :tag
"use MML when appropriate" best
)))
573 (defcustom message-forward-before-signature t
574 "*Non-nil means put forwarded message before signature, else after."
575 :group
'message-forwarding
578 (defcustom message-wash-forwarded-subjects nil
579 "*Non-nil means try to remove as much cruft as possible from the subject.
580 Done before generating the new subject of a forward."
581 :group
'message-forwarding
582 :link
'(custom-manual "(message)Forwarding")
585 (defcustom message-ignored-resent-headers
586 ;; `Delivered-To' needs to be removed because some mailers use it to
587 ;; detect loops, so if you resend a message to an address that ultimately
588 ;; comes back to you (e.g. a mailing-list to which you subscribe, in which
589 ;; case you may be removed from the list on the grounds that mail to you
590 ;; bounced with a "mailing loop" error).
591 "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From \\|^Delivered-To:"
592 "*All headers that match this regexp will be deleted when resending a message."
593 :group
'message-interface
594 :link
'(custom-manual "(message)Resending")
595 :type
'(repeat :value-to-internal
(lambda (widget value
)
596 (custom-split-regexp-maybe value
))
597 :match
(lambda (widget value
)
599 (widget-editable-list-match widget value
)))
602 (defcustom message-forward-ignored-headers
"^Content-Transfer-Encoding:\\|^X-Gnus"
603 "*All headers that match this regexp will be deleted when forwarding a message."
605 :group
'message-forwarding
606 :type
'(repeat :value-to-internal
(lambda (widget value
)
607 (custom-split-regexp-maybe value
))
608 :match
(lambda (widget value
)
610 (widget-editable-list-match widget value
)))
613 (defcustom message-ignored-cited-headers
"."
614 "*Delete these headers from the messages you yank."
615 :group
'message-insertion
616 :link
'(custom-manual "(message)Insertion Variables")
619 (defcustom message-cite-prefix-regexp mail-citation-prefix-regexp
620 "*Regexp matching the longest possible citation prefix on a line."
622 :group
'message-insertion
623 :link
'(custom-manual "(message)Insertion Variables")
625 :set
(lambda (symbol value
)
627 (custom-set-default symbol value
)
628 (if (boundp 'gnus-message-cite-prefix-regexp
)
629 (setq gnus-message-cite-prefix-regexp
630 (concat "^\\(?:" value
"\\)"))))))
632 (defcustom message-cancel-message
"I am canceling my own article.\n"
633 "Message to be inserted in the cancel message."
634 :group
'message-interface
635 :link
'(custom-manual "(message)Canceling News")
638 (defun message-send-mail-function ()
639 "Return suitable value for the variable `message-send-mail-function'."
640 (cond ((and (require 'sendmail
)
641 (boundp 'sendmail-program
)
643 (executable-find sendmail-program
))
644 'message-send-mail-with-sendmail
)
645 ((and (locate-library "smtpmail")
646 (boundp 'smtpmail-default-smtp-server
)
647 smtpmail-default-smtp-server
)
648 'message-smtpmail-send-it
)
649 ((locate-library "mailclient")
650 'message-send-mail-with-mailclient
)
652 (error "Don't know how to send mail. Please customize `message-send-mail-function'"))))
654 ;; Useful to set in site-init.el
655 (defcustom message-send-mail-function
656 (cond ((eq send-mail-function
'smtpmail-send-it
) 'message-smtpmail-send-it
)
657 ((eq send-mail-function
'feedmail-send-it
) 'feedmail-send-it
)
658 ((eq send-mail-function
'mailclient-send-it
)
659 'message-send-mail-with-mailclient
)
660 (t (message-send-mail-function)))
661 "Function to call to send the current buffer as mail.
662 The headers should be delimited by a line whose contents match the
663 variable `mail-header-separator'.
665 Valid values include `message-send-mail-with-sendmail'
666 `message-send-mail-with-mh', `message-send-mail-with-qmail',
667 `message-smtpmail-send-it', `smtpmail-send-it',
668 `feedmail-send-it' and `message-send-mail-with-mailclient'. The
669 default is system dependent and determined by the function
670 `message-send-mail-function'.
672 See also `send-mail-function'."
673 :type
'(radio (function-item message-send-mail-with-sendmail
)
674 (function-item message-send-mail-with-mh
)
675 (function-item message-send-mail-with-qmail
)
676 (function-item message-smtpmail-send-it
)
677 (function-item smtpmail-send-it
)
678 (function-item feedmail-send-it
)
679 (function-item message-send-mail-with-mailclient
680 :tag
"Use Mailclient package")
681 (function :tag
"Other"))
682 :group
'message-sending
684 :initialize
'custom-initialize-default
685 :link
'(custom-manual "(message)Mail Variables")
686 :group
'message-mail
)
688 (defcustom message-send-news-function
'message-send-news
689 "Function to call to send the current buffer as news.
690 The headers should be delimited by a line whose contents match the
691 variable `mail-header-separator'."
692 :group
'message-sending
694 :link
'(custom-manual "(message)News Variables")
697 (defcustom message-reply-to-function nil
698 "If non-nil, function that should return a list of headers.
699 This function should pick out addresses from the To, Cc, and From headers
700 and respond with new To and Cc headers."
701 :group
'message-interface
702 :link
'(custom-manual "(message)Reply")
703 :type
'(choice function
(const nil
)))
705 (defcustom message-wide-reply-to-function nil
706 "If non-nil, function that should return a list of headers.
707 This function should pick out addresses from the To, Cc, and From headers
708 and respond with new To and Cc headers."
709 :group
'message-interface
710 :link
'(custom-manual "(message)Wide Reply")
711 :type
'(choice function
(const nil
)))
713 (defcustom message-followup-to-function nil
714 "If non-nil, function that should return a list of headers.
715 This function should pick out addresses from the To, Cc, and From headers
716 and respond with new To and Cc headers."
717 :group
'message-interface
718 :link
'(custom-manual "(message)Followup")
719 :type
'(choice function
(const nil
)))
721 (defcustom message-extra-wide-headers nil
722 "If non-nil, a list of additional address headers.
723 These are used when composing a wide reply."
724 :group
'message-sending
725 :type
'(repeat string
))
727 (defcustom message-use-followup-to
'ask
728 "*Specifies what to do with Followup-To header.
729 If nil, always ignore the header. If it is t, use its value, but
730 query before using the \"poster\" value. If it is the symbol `ask',
731 always query the user whether to use the value. If it is the symbol
732 `use', always use the value."
733 :group
'message-interface
734 :link
'(custom-manual "(message)Followup")
735 :type
'(choice (const :tag
"ignore" nil
)
736 (const :tag
"use & query" t
)
740 (defcustom message-use-mail-followup-to
'use
741 "*Specifies what to do with Mail-Followup-To header.
742 If nil, always ignore the header. If it is the symbol `ask', always
743 query the user whether to use the value. If it is the symbol `use',
744 always use the value."
746 :group
'message-interface
747 :link
'(custom-manual "(message)Mailing Lists")
748 :type
'(choice (const :tag
"ignore" nil
)
752 (defcustom message-subscribed-address-functions nil
753 "*Specifies functions for determining list subscription.
754 If nil, do not attempt to determine list subscription with functions.
755 If non-nil, this variable contains a list of functions which return
756 regular expressions to match lists. These functions can be used in
757 conjunction with `message-subscribed-regexps' and
758 `message-subscribed-addresses'."
760 :group
'message-interface
761 :link
'(custom-manual "(message)Mailing Lists")
762 :type
'(repeat sexp
))
764 (defcustom message-subscribed-address-file nil
765 "*A file containing addresses the user is subscribed to.
766 If nil, do not look at any files to determine list subscriptions. If
767 non-nil, each line of this file should be a mailing list address."
769 :group
'message-interface
770 :link
'(custom-manual "(message)Mailing Lists")
771 :type
'(radio file
(const nil
)))
773 (defcustom message-subscribed-addresses nil
774 "*Specifies a list of addresses the user is subscribed to.
775 If nil, do not use any predefined list subscriptions. This list of
776 addresses can be used in conjunction with
777 `message-subscribed-address-functions' and `message-subscribed-regexps'."
779 :group
'message-interface
780 :link
'(custom-manual "(message)Mailing Lists")
781 :type
'(repeat string
))
783 (defcustom message-subscribed-regexps nil
784 "*Specifies a list of addresses the user is subscribed to.
785 If nil, do not use any predefined list subscriptions. This list of
786 regular expressions can be used in conjunction with
787 `message-subscribed-address-functions' and `message-subscribed-addresses'."
789 :group
'message-interface
790 :link
'(custom-manual "(message)Mailing Lists")
791 :type
'(repeat regexp
))
793 (defcustom message-allow-no-recipients
'ask
794 "Specifies what to do when there are no recipients other than Gcc/Fcc.
795 If it is the symbol `always', the posting is allowed. If it is the
796 symbol `never', the posting is not allowed. If it is the symbol
797 `ask', you are prompted."
799 :group
'message-interface
800 :link
'(custom-manual "(message)Message Headers")
801 :type
'(choice (const always
)
805 (defcustom message-sendmail-f-is-evil nil
806 "*Non-nil means don't add \"-f username\" to the sendmail command line.
807 Doing so would be even more evil than leaving it out."
808 :group
'message-sending
809 :link
'(custom-manual "(message)Mail Variables")
812 (defcustom message-sendmail-envelope-from
813 ;; `mail-envelope-from' is unavailable unless sendmail.el is loaded.
814 (if (boundp 'mail-envelope-from
) mail-envelope-from
)
815 "*Envelope-from when sending mail with sendmail.
816 If this is nil, use `user-mail-address'. If it is the symbol
817 `header', use the From: header of the message."
819 :type
'(choice (string :tag
"From name")
820 (const :tag
"Use From: header from message" header
)
821 (const :tag
"Use `user-mail-address'" nil
))
822 :link
'(custom-manual "(message)Mail Variables")
823 :group
'message-sending
)
825 (defcustom message-sendmail-extra-arguments nil
826 "Additional arguments to `sendmail-program'."
827 ;; E.g. '("-a" "account") for msmtp
828 :version
"23.1" ;; No Gnus
829 :type
'(repeat string
)
830 ;; :link '(custom-manual "(message)Mail Variables")
831 :group
'message-sending
)
833 ;; qmail-related stuff
834 (defcustom message-qmail-inject-program
"/var/qmail/bin/qmail-inject"
835 "Location of the qmail-inject program."
836 :group
'message-sending
837 :link
'(custom-manual "(message)Mail Variables")
840 (defcustom message-qmail-inject-args nil
841 "Arguments passed to qmail-inject programs.
842 This should be a list of strings, one string for each argument.
843 It may also be a function.
845 For e.g., if you wish to set the envelope sender address so that bounces
846 go to the right place or to deal with listserv's usage of that address, you
847 might set this variable to '(\"-f\" \"you@some.where\")."
848 :group
'message-sending
849 :link
'(custom-manual "(message)Mail Variables")
850 :type
'(choice (function)
853 (defvar gnus-post-method
)
854 (defvar gnus-select-method
)
855 (defcustom message-post-method
856 (cond ((and (boundp 'gnus-post-method
)
857 (listp gnus-post-method
)
860 ((boundp 'gnus-select-method
)
863 "*Method used to post news.
864 Note that when posting from inside Gnus, for instance, this
865 variable isn't used."
867 :group
'message-sending
868 ;; This should be the `gnus-select-method' widget, but that might
869 ;; create a dependence to `gnus.el'.
872 ;; FIXME: This should be a temporary workaround until someone implements a
873 ;; proper solution. If a crash happens while replying, the auto-save file
874 ;; will *not* have a `References:' header if `message-generate-headers-first'
875 ;; is nil. See: http://article.gmane.org/gmane.emacs.gnus.general/51138
876 (defcustom message-generate-headers-first
'(references)
877 "Which headers should be generated before starting to compose a message.
878 If t, generate all required headers. This can also be a list of headers to
879 generate. The variables `message-required-news-headers' and
880 `message-required-mail-headers' specify which headers to generate.
882 Note that the variable `message-deletable-headers' specifies headers which
883 are to be deleted and then re-generated before sending, so this variable
884 will not have a visible effect for those headers."
885 :group
'message-headers
886 :link
'(custom-manual "(message)Message Headers")
887 :type
'(choice (const :tag
"None" nil
)
888 (const :tag
"References" '(references))
890 (repeat (sexp :tag
"Header"))))
892 (defcustom message-fill-column
72
893 "Column beyond which automatic line-wrapping should happen.
894 Local value for message buffers. If non-nil, also turn on
895 auto-fill in message buffers."
896 :group
'message-various
897 ;; :link '(custom-manual "(message)Message Headers")
898 :type
'(choice (const :tag
"Don't turn on auto fill" nil
)
901 (defcustom message-setup-hook nil
902 "Normal hook, run each time a new outgoing message is initialized.
903 The function `message-setup' runs this hook."
904 :group
'message-various
905 :link
'(custom-manual "(message)Various Message Variables")
908 (defcustom message-cancel-hook nil
909 "Hook run when cancelling articles."
910 :group
'message-various
911 :link
'(custom-manual "(message)Various Message Variables")
914 (defcustom message-signature-setup-hook nil
915 "Normal hook, run each time a new outgoing message is initialized.
916 It is run after the headers have been inserted and before
917 the signature is inserted."
918 :group
'message-various
919 :link
'(custom-manual "(message)Various Message Variables")
922 (defcustom message-mode-hook nil
923 "Hook run in message mode buffers."
924 :group
'message-various
927 (defcustom message-header-hook nil
928 "Hook run in a message mode buffer narrowed to the headers."
929 :group
'message-various
932 (defcustom message-header-setup-hook nil
933 "Hook called narrowed to the headers when setting up a message buffer."
934 :group
'message-various
935 :link
'(custom-manual "(message)Various Message Variables")
938 (defcustom message-minibuffer-local-map
939 (let ((map (make-sparse-keymap 'message-minibuffer-local-map
)))
940 (set-keymap-parent map minibuffer-local-map
)
942 "Keymap for `message-read-from-minibuffer'."
944 :group
'message-various
)
946 (defcustom message-citation-line-function
'message-insert-citation-line
947 "*Function called to insert the \"Whomever writes:\" line.
949 Predefined functions include `message-insert-citation-line' and
950 `message-insert-formatted-citation-line' (see the variable
951 `message-citation-line-format').
953 Note that Gnus provides a feature where the reader can click on
954 `writes:' to hide the cited text. If you change this line too much,
955 people who read your message will have to change their Gnus
956 configuration. See the variable `gnus-cite-attribution-suffix'."
958 (function-item :tag
"plain" message-insert-citation-line
)
959 (function-item :tag
"formatted" message-insert-formatted-citation-line
)
960 (function :tag
"Other"))
961 :link
'(custom-manual "(message)Insertion Variables")
962 :group
'message-insertion
)
964 (defcustom message-citation-line-format
"On %a, %b %d %Y, %N wrote:\n"
965 "Format of the \"Whomever writes:\" line.
967 The string is formatted using `format-spec'. The following
968 constructs are replaced:
970 %f The full From, e.g. \"John Doe <john.doe@example.invalid>\".
971 %n The mail address, e.g. \"john.doe@example.invalid\".
972 %N The real name if present, e.g.: \"John Doe\", else fall
973 back to the mail address.
974 %F The first name if present, e.g.: \"John\".
975 %L The last name if present, e.g.: \"Doe\".
977 All other format specifiers are passed to `format-time-string'
978 which is called using the date from the article your replying to.
979 Extracting the first (%F) and last name (%L) is done
980 heuristically, so you should always check it yourself.
982 Please also read the note in the documentation of
983 `message-citation-line-function'."
984 :type
'(choice (const :tag
"Plain" "%f writes:")
985 (const :tag
"Include date" "On %a, %b %d %Y, %n wrote:")
987 :link
'(custom-manual "(message)Insertion Variables")
988 :version
"23.1" ;; No Gnus
989 :group
'message-insertion
)
991 (defcustom message-yank-prefix mail-yank-prefix
992 "*Prefix inserted on the lines of yanked messages.
993 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
994 See also `message-yank-cited-prefix' and `message-yank-empty-prefix'."
997 :link
'(custom-manual "(message)Insertion Variables")
998 :group
'message-insertion
)
1000 (defcustom message-yank-cited-prefix
">"
1001 "*Prefix inserted on cited lines of yanked messages.
1002 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1003 See also `message-yank-prefix' and `message-yank-empty-prefix'."
1006 :link
'(custom-manual "(message)Insertion Variables")
1007 :group
'message-insertion
)
1009 (defcustom message-yank-empty-prefix
">"
1010 "*Prefix inserted on empty lines of yanked messages.
1011 See also `message-yank-prefix' and `message-yank-cited-prefix'."
1014 :link
'(custom-manual "(message)Insertion Variables")
1015 :group
'message-insertion
)
1017 (defcustom message-indentation-spaces mail-indentation-spaces
1018 "*Number of spaces to insert at the beginning of each cited line.
1019 Used by `message-yank-original' via `message-yank-cite'."
1021 :group
'message-insertion
1022 :link
'(custom-manual "(message)Insertion Variables")
1025 (defcustom message-cite-function
'message-cite-original-without-signature
1026 "*Function for citing an original message.
1027 Predefined functions include `message-cite-original' and
1028 `message-cite-original-without-signature'.
1029 Note that these functions use `mail-citation-hook' if that is non-nil."
1030 :type
'(radio (function-item message-cite-original
)
1031 (function-item message-cite-original-without-signature
)
1032 (function-item sc-cite-original
)
1033 (function :tag
"Other"))
1034 :link
'(custom-manual "(message)Insertion Variables")
1035 :version
"22.3" ;; Gnus 5.10.12 (changed default)
1036 :group
'message-insertion
)
1038 (defcustom message-indent-citation-function
'message-indent-citation
1039 "*Function for modifying a citation just inserted in the mail buffer.
1040 This can also be a list of functions. Each function can find the
1041 citation between (point) and (mark t). And each function should leave
1042 point and mark around the citation text as modified."
1044 :link
'(custom-manual "(message)Insertion Variables")
1045 :group
'message-insertion
)
1047 (defcustom message-signature mail-signature
1048 "*String to be inserted at the end of the message buffer.
1049 If t, the `message-signature-file' file will be inserted instead.
1050 If a function, the result from the function will be used instead.
1051 If a form, the result from the form will be used instead."
1054 :link
'(custom-manual "(message)Insertion Variables")
1055 :group
'message-insertion
)
1057 (defcustom message-signature-file mail-signature-file
1058 "*Name of file containing the text inserted at end of message buffer.
1059 Ignored if the named file doesn't exist.
1060 If nil, don't insert a signature.
1061 If a path is specified, the value of `message-signature-directory' is ignored,
1064 :type
'(choice file
(const :tags
"None" nil
))
1065 :link
'(custom-manual "(message)Insertion Variables")
1066 :group
'message-insertion
)
1068 (defcustom message-signature-directory nil
1069 "*Name of directory containing signature files.
1070 Comes in handy if you have many such files, handled via posting styles for
1072 If nil, `message-signature-file' is expected to specify the directory if
1074 :type
'(choice string
(const :tags
"None" nil
))
1075 :link
'(custom-manual "(message)Insertion Variables")
1076 :group
'message-insertion
)
1078 (defcustom message-signature-insert-empty-line t
1079 "*If non-nil, insert an empty line before the signature separator."
1082 :link
'(custom-manual "(message)Insertion Variables")
1083 :group
'message-insertion
)
1085 (defcustom message-distribution-function nil
1086 "*Function called to return a Distribution header."
1087 :group
'message-news
1088 :group
'message-headers
1089 :link
'(custom-manual "(message)News Headers")
1090 :type
'(choice function
(const nil
)))
1092 (defcustom message-expires
14
1093 "Number of days before your article expires."
1094 :group
'message-news
1095 :group
'message-headers
1096 :link
'(custom-manual "(message)News Headers")
1099 (defcustom message-user-path nil
1100 "If nil, use the NNTP server name in the Path header.
1101 If stringp, use this; if non-nil, use no host name (user name only)."
1102 :group
'message-news
1103 :group
'message-headers
1104 :link
'(custom-manual "(message)News Headers")
1105 :type
'(choice (const :tag
"nntp" nil
)
1106 (string :tag
"name")
1107 (sexp :tag
"none" :format
"%t" t
)))
1109 ;; This can be the name of a buffer, or a cons cell (FUNCTION . ARGS)
1110 ;; for yanking the original buffer.
1111 (defvar message-reply-buffer nil
)
1112 (defvar message-reply-headers nil
1113 "The headers of the current replied article.
1114 It is a vector of the following headers:
1115 \[number subject from date id references chars lines xref extra].")
1116 (defvar message-newsreader nil
)
1117 (defvar message-mailer nil
)
1118 (defvar message-sent-message-via nil
)
1119 (defvar message-checksum nil
)
1120 (defvar message-send-actions nil
1121 "A list of actions to be performed upon successful sending of a message.")
1122 (defvar message-return-action nil
1123 "Action to return to the caller after sending or postphoning a message.")
1124 (defvar message-exit-actions nil
1125 "A list of actions to be performed upon exiting after sending a message.")
1126 (defvar message-kill-actions nil
1127 "A list of actions to be performed before killing a message buffer.")
1128 (defvar message-postpone-actions nil
1129 "A list of actions to be performed after postponing a message.")
1131 (define-widget 'message-header-lines
'text
1132 "All header lines must be LFD terminated."
1133 :format
"%{%t%}:%n%v"
1134 :valid-regexp
"^\\'"
1135 :error
"All header lines must be newline terminated")
1137 (defcustom message-default-headers
""
1138 "Header lines to be inserted in outgoing messages.
1139 This can be set to a string containing or a function returning
1140 header lines to be inserted before you edit the message, so you
1141 can edit or delete these lines. If set to a function, it is
1142 called and its result is inserted."
1144 :group
'message-headers
1145 :link
'(custom-manual "(message)Message Headers")
1147 (message-header-lines :tag
"String")
1148 (function :tag
"Function")))
1150 (defcustom message-default-mail-headers
1151 ;; Ease the transition from mail-mode to message-mode. See bugs#4431, 5555.
1152 (concat (if (and (boundp 'mail-default-reply-to
)
1153 (stringp mail-default-reply-to
))
1154 (format "Reply-to: %s\n" mail-default-reply-to
))
1155 (if (and (boundp 'mail-self-blind
)
1157 (format "BCC: %s\n" user-mail-address
))
1158 (if (and (boundp 'mail-archive-file-name
)
1159 (stringp mail-archive-file-name
))
1160 (format "FCC: %s\n" mail-archive-file-name
))
1161 ;; Use the value of `mail-default-headers' if available.
1162 ;; Note: as for XEmacs 21.4 and 21.5, it is unavailable
1163 ;; unless sendmail.el is loaded.
1164 (if (boundp 'mail-default-headers
)
1165 mail-default-headers
))
1166 "*A string of header lines to be inserted in outgoing mails."
1168 :group
'message-headers
1169 :group
'message-mail
1170 :link
'(custom-manual "(message)Mail Headers")
1171 :type
'message-header-lines
)
1173 (defcustom message-default-news-headers
""
1174 "*A string of header lines to be inserted in outgoing news articles."
1175 :group
'message-headers
1176 :group
'message-news
1177 :link
'(custom-manual "(message)News Headers")
1178 :type
'message-header-lines
)
1180 ;; Note: could use /usr/ucb/mail instead of sendmail;
1181 ;; options -t, and -v if not interactive.
1182 (defcustom message-mailer-swallows-blank-line
1183 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1184 system-configuration
)
1185 (file-readable-p "/etc/sendmail.cf")
1187 (insert-file-contents "/etc/sendmail.cf")
1188 (goto-char (point-min))
1189 (let ((case-fold-search nil
))
1190 (re-search-forward "^OR\\>" nil t
))))
1191 ;; According to RFC822, "The field-name must be composed of printable
1192 ;; ASCII characters (i. e., characters that have decimal values between
1193 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1195 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1196 "*Set this non-nil if the system's mailer runs the header and body together.
1197 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1198 The value should be an expression to test whether the problem will
1200 :group
'message-sending
1201 :link
'(custom-manual "(message)Mail Variables")
1205 (define-mail-user-agent 'message-user-agent
1206 'message-mail
'message-send-and-exit
1207 'message-kill-buffer
'message-send-hook
)
1209 (defvar message-mh-deletable-headers
'(Message-ID Date Lines Sender
)
1210 "If non-nil, delete the deletable headers before feeding to mh.")
1212 (defvar message-send-method-alist
1213 '((news message-news-p message-send-via-news
)
1214 (mail message-mail-p message-send-via-mail
))
1215 "Alist of ways to send outgoing messages.
1216 Each element has the form
1218 \(TYPE PREDICATE FUNCTION)
1220 where TYPE is a symbol that names the method; PREDICATE is a function
1221 called without any parameters to determine whether the message is
1222 a message of type TYPE; and FUNCTION is a function to be called if
1223 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1226 (defcustom message-mail-alias-type
'abbrev
1227 "*What alias expansion type to use in Message buffers.
1228 The default is `abbrev', which uses mailabbrev. `ecomplete' uses
1229 an electric completion mode. nil switches mail aliases off.
1230 This can also be a list of values."
1232 :link
'(custom-manual "(message)Mail Aliases")
1233 :type
'(choice (const :tag
"Use Mailabbrev" abbrev
)
1234 (const :tag
"Use ecomplete" ecomplete
)
1235 (const :tag
"No expansion" nil
)))
1237 (defcustom message-self-insert-commands
'(self-insert-command)
1238 "List of `self-insert-command's used to trigger ecomplete.
1239 When one of those commands is invoked to enter a character in To or Cc
1240 header, ecomplete will suggest the candidates of recipients (see also
1241 `message-mail-alias-type'). If you use some tool to enter non-ASCII
1242 text and it replaces `self-insert-command' with the other command, e.g.
1243 `egg-self-insert-command', you may want to add it to this list."
1244 :group
'message-various
1245 :type
'(repeat function
))
1247 (defcustom message-auto-save-directory
1248 (file-name-as-directory (expand-file-name "drafts" message-directory
))
1249 "*Directory where Message auto-saves buffers if Gnus isn't running.
1250 If nil, Message won't auto-save."
1251 :group
'message-buffers
1252 :link
'(custom-manual "(message)Various Message Variables")
1253 :type
'(choice directory
(const :tag
"Don't auto-save" nil
)))
1255 (defcustom message-default-charset
1256 (and (not (mm-multibyte-p)) 'iso-8859-1
)
1257 "Default charset used in non-MULE Emacsen.
1258 If nil, you might be asked to input the charset."
1261 :link
'(custom-manual "(message)Various Message Variables")
1264 (defcustom message-dont-reply-to-names
1265 (and (boundp 'rmail-dont-reply-to-names
) rmail-dont-reply-to-names
)
1266 "*Addresses to prune when doing wide replies.
1267 This can be a regexp or a list of regexps. Also, a value of nil means
1268 exclude your own user name only."
1271 :link
'(custom-manual "(message)Wide Reply")
1272 :type
'(choice (const :tag
"Yourself" nil
)
1274 (repeat :tag
"Regexp List" regexp
)))
1276 (defsubst message-dont-reply-to-names
()
1277 (gmm-regexp-concat message-dont-reply-to-names
))
1279 (defvar message-shoot-gnksa-feet nil
1280 "*A list of GNKSA feet you are allowed to shoot.
1281 Gnus gives you all the opportunity you could possibly want for
1282 shooting yourself in the foot. Also, Gnus allows you to shoot the
1283 feet of Good Net-Keeping Seal of Approval. The following are foot
1285 `empty-article' Allow you to post an empty article;
1286 `quoted-text-only' Allow you to post quoted text only;
1287 `multiple-copies' Allow you to post multiple copies;
1288 `cancel-messages' Allow you to cancel or supersede messages from
1289 your other email addresses.")
1291 (defsubst message-gnksa-enable-p
(feature)
1292 (or (not (listp message-shoot-gnksa-feet
))
1293 (memq feature message-shoot-gnksa-feet
)))
1295 (defcustom message-hidden-headers
'("^References:" "^Face:" "^X-Face:"
1297 "Regexp of headers to be hidden when composing new messages.
1298 This can also be a list of regexps to match headers. Or a list
1299 starting with `not' and followed by regexps."
1302 :link
'(custom-manual "(message)Message Headers")
1304 :format
"%{%t%}: %[Value Type%] %v"
1305 (regexp :menu-tag
"regexp" :format
"regexp\n%t: %v")
1306 (repeat :menu-tag
"(regexp ...)" :format
"(regexp ...)\n%v%i"
1307 (regexp :format
"%t: %v"))
1308 (cons :menu-tag
"(not regexp ...)" :format
"(not regexp ...)\n%v"
1310 (repeat :format
"%v%i"
1311 (regexp :format
"%t: %v")))))
1313 (defcustom message-cite-articles-with-x-no-archive t
1314 "If non-nil, cite text from articles that has X-No-Archive set."
1318 ;;; Internal variables.
1319 ;;; Well, not really internal.
1321 (defvar message-mode-syntax-table
1322 (let ((table (copy-syntax-table text-mode-syntax-table
)))
1323 (modify-syntax-entry ?%
". " table
)
1324 (modify-syntax-entry ?
> ". " table
)
1325 (modify-syntax-entry ?
< ". " table
)
1327 "Syntax table used while in Message mode.")
1329 (defface message-header-to
1332 (:foreground
"DarkOliveGreen1" :bold t
))
1335 (:foreground
"MidnightBlue" :bold t
))
1337 (:bold t
:italic t
)))
1338 "Face used for displaying From headers."
1339 :group
'message-faces
)
1340 ;; backward-compatibility alias
1341 (put 'message-header-to-face
'face-alias
'message-header-to
)
1342 (put 'message-header-to-face
'obsolete-face
"22.1")
1344 (defface message-header-cc
1347 (:foreground
"chartreuse1" :bold t
))
1350 (:foreground
"MidnightBlue"))
1353 "Face used for displaying Cc headers."
1354 :group
'message-faces
)
1355 ;; backward-compatibility alias
1356 (put 'message-header-cc-face
'face-alias
'message-header-cc
)
1357 (put 'message-header-cc-face
'obsolete-face
"22.1")
1359 (defface message-header-subject
1362 (:foreground
"OliveDrab1"))
1365 (:foreground
"navy blue" :bold t
))
1368 "Face used for displaying subject headers."
1369 :group
'message-faces
)
1370 ;; backward-compatibility alias
1371 (put 'message-header-subject-face
'face-alias
'message-header-subject
)
1372 (put 'message-header-subject-face
'obsolete-face
"22.1")
1374 (defface message-header-newsgroups
1377 (:foreground
"yellow" :bold t
:italic t
))
1380 (:foreground
"blue4" :bold t
:italic t
))
1382 (:bold t
:italic t
)))
1383 "Face used for displaying newsgroups headers."
1384 :group
'message-faces
)
1385 ;; backward-compatibility alias
1386 (put 'message-header-newsgroups-face
'face-alias
'message-header-newsgroups
)
1387 (put 'message-header-newsgroups-face
'obsolete-face
"22.1")
1389 (defface message-header-other
1392 (:foreground
"VioletRed1"))
1395 (:foreground
"steel blue"))
1397 (:bold t
:italic t
)))
1398 "Face used for displaying newsgroups headers."
1399 :group
'message-faces
)
1400 ;; backward-compatibility alias
1401 (put 'message-header-other-face
'face-alias
'message-header-other
)
1402 (put 'message-header-other-face
'obsolete-face
"22.1")
1404 (defface message-header-name
1407 (:foreground
"green"))
1410 (:foreground
"cornflower blue"))
1413 "Face used for displaying header names."
1414 :group
'message-faces
)
1415 ;; backward-compatibility alias
1416 (put 'message-header-name-face
'face-alias
'message-header-name
)
1417 (put 'message-header-name-face
'obsolete-face
"22.1")
1419 (defface message-header-xheader
1422 (:foreground
"DeepSkyBlue1"))
1425 (:foreground
"blue"))
1428 "Face used for displaying X-Header headers."
1429 :group
'message-faces
)
1430 ;; backward-compatibility alias
1431 (put 'message-header-xheader-face
'face-alias
'message-header-xheader
)
1432 (put 'message-header-xheader-face
'obsolete-face
"22.1")
1434 (defface message-separator
1437 (:foreground
"LightSkyBlue1"))
1440 (:foreground
"brown"))
1443 "Face used for displaying the separator."
1444 :group
'message-faces
)
1445 ;; backward-compatibility alias
1446 (put 'message-separator-face
'face-alias
'message-separator
)
1447 (put 'message-separator-face
'obsolete-face
"22.1")
1449 (defface message-cited-text
1452 (:foreground
"LightPink1"))
1455 (:foreground
"red"))
1458 "Face used for displaying cited text names."
1459 :group
'message-faces
)
1460 ;; backward-compatibility alias
1461 (put 'message-cited-text-face
'face-alias
'message-cited-text
)
1462 (put 'message-cited-text-face
'obsolete-face
"22.1")
1464 (defface message-mml
1467 (:foreground
"MediumSpringGreen"))
1470 (:foreground
"ForestGreen"))
1473 "Face used for displaying MML."
1474 :group
'message-faces
)
1475 ;; backward-compatibility alias
1476 (put 'message-mml-face
'face-alias
'message-mml
)
1477 (put 'message-mml-face
'obsolete-face
"22.1")
1479 (defun message-font-lock-make-header-matcher (regexp)
1482 (let ((start (point)))
1485 (goto-char (point-min))
1486 (if (re-search-forward
1487 (concat "^" (regexp-quote mail-header-separator
) "$")
1489 (setq limit
(min limit
(match-beginning 0))))
1491 (and (< start limit
)
1492 (re-search-forward ,regexp limit t
))))))
1493 (if (featurep 'bytecomp
)
1497 (defvar message-font-lock-keywords
1498 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1499 `((,(message-font-lock-make-header-matcher
1500 (concat "^\\([Tt]o:\\)" content
))
1501 (1 'message-header-name
)
1502 (2 'message-header-to nil t
))
1503 (,(message-font-lock-make-header-matcher
1504 (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content
))
1505 (1 'message-header-name
)
1506 (2 'message-header-cc nil t
))
1507 (,(message-font-lock-make-header-matcher
1508 (concat "^\\([Ss]ubject:\\)" content
))
1509 (1 'message-header-name
)
1510 (2 'message-header-subject nil t
))
1511 (,(message-font-lock-make-header-matcher
1512 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content
))
1513 (1 'message-header-name
)
1514 (2 'message-header-newsgroups nil t
))
1515 (,(message-font-lock-make-header-matcher
1516 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content
))
1517 (1 'message-header-name
)
1518 (2 'message-header-xheader
))
1519 (,(message-font-lock-make-header-matcher
1520 (concat "^\\([A-Z][^: \n\t]+:\\)" content
))
1521 (1 'message-header-name
)
1522 (2 'message-header-other nil t
))
1523 ,@(if (and mail-header-separator
1524 (not (equal mail-header-separator
"")))
1525 `((,(concat "^\\(" (regexp-quote mail-header-separator
) "\\)$")
1526 1 'message-separator
))
1529 (re-search-forward (concat "^\\("
1530 message-cite-prefix-regexp
1533 (0 'message-cited-text
))
1534 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1536 "Additional expressions to highlight in Message mode.")
1539 ;; XEmacs does it like this. For Emacs, we have to set the
1540 ;; `font-lock-defaults' buffer-local variable.
1541 (put 'message-mode
'font-lock-defaults
'(message-font-lock-keywords t
))
1543 (defvar message-face-alist
1544 '((bold . message-bold-region
)
1545 (underline . underline-region
)
1546 (default .
(lambda (b e
)
1547 (message-unbold-region b e
)
1548 (ununderline-region b e
))))
1549 "Alist of mail and news faces for facemenu.
1550 The cdr of each entry is a function for applying the face to a region.")
1552 (defcustom message-send-hook nil
1553 "Hook run before sending messages.
1554 This hook is run quite early when sending."
1555 :group
'message-various
1556 :options
'(ispell-message)
1557 :link
'(custom-manual "(message)Various Message Variables")
1560 (defcustom message-send-mail-hook nil
1561 "Hook run before sending mail messages.
1562 This hook is run very late -- just before the message is sent as
1564 :group
'message-various
1565 :link
'(custom-manual "(message)Various Message Variables")
1568 (defcustom message-send-news-hook nil
1569 "Hook run before sending news messages.
1570 This hook is run very late -- just before the message is sent as
1572 :group
'message-various
1573 :link
'(custom-manual "(message)Various Message Variables")
1576 (defcustom message-sent-hook nil
1577 "Hook run after sending messages."
1578 :group
'message-various
1581 (defvar message-send-coding-system
'binary
1582 "Coding system to encode outgoing mail.")
1584 (defvar message-draft-coding-system
1585 mm-auto-save-coding-system
1586 "*Coding system to compose mail.
1587 If you'd like to make it possible to share draft files between XEmacs
1588 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1589 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1591 (defcustom message-send-mail-partially-limit nil
1592 "The limitation of messages sent as message/partial.
1593 The lower bound of message size in characters, beyond which the message
1594 should be sent in several parts. If it is nil, the size is unlimited."
1596 :group
'message-buffers
1597 :link
'(custom-manual "(message)Mail Variables")
1598 :type
'(choice (const :tag
"unlimited" nil
)
1601 (defcustom message-alternative-emails nil
1602 "*Regexp matching alternative email addresses.
1603 The first address in the To, Cc or From headers of the original
1604 article matching this variable is used as the From field of
1607 This variable has precedence over posting styles and anything that runs
1608 off `message-setup-hook'."
1609 :group
'message-headers
1610 :link
'(custom-manual "(message)Message Headers")
1611 :type
'(choice (const :tag
"Always use primary" nil
)
1614 (defcustom message-hierarchical-addresses nil
1615 "A list of hierarchical mail address definitions.
1617 Inside each entry, the first address is the \"top\" address, and
1618 subsequent addresses are subaddresses; this is used to indicate that
1619 mail sent to the first address will automatically be delivered to the
1620 subaddresses. So if the first address appears in the recipient list
1621 for a message, the subaddresses will be removed (if present) before
1622 the mail is sent. All addresses in this structure should be
1625 :group
'message-headers
1626 :type
'(repeat (repeat string
)))
1628 (defcustom message-mail-user-agent nil
1629 "Like `mail-user-agent'.
1630 Except if it is nil, use Gnus native MUA; if it is t, use
1633 :type
'(radio (const :tag
"Gnus native"
1636 (const :tag
"`mail-user-agent'"
1639 (function-item :tag
"Default Emacs mail"
1641 sendmail-user-agent
)
1642 (function-item :tag
"Emacs interface to MH"
1645 (function :tag
"Other"))
1649 (defcustom message-wide-reply-confirm-recipients nil
1650 "Whether to confirm a wide reply to multiple email recipients.
1651 If this variable is nil, don't ask whether to reply to all recipients.
1652 If this variable is non-nil, pose the question \"Reply to all
1653 recipients?\" before a wide reply to multiple recipients. If the user
1654 answers yes, reply to all recipients as usual. If the user answers
1655 no, only reply back to the author."
1657 :group
'message-headers
1658 :link
'(custom-manual "(message)Wide Reply")
1661 (defcustom message-user-fqdn nil
1662 "*Domain part of Message-Ids."
1664 :group
'message-headers
1665 :link
'(custom-manual "(message)News Headers")
1666 :type
'(radio (const :format
"%v " nil
)
1667 (string :format
"FQDN: %v")))
1669 (defcustom message-use-idna
(and (condition-case nil
(require 'idna
)
1671 (mm-coding-system-p 'utf-8
)
1672 (executable-find idna-program
)
1673 (string= (idna-to-ascii "räksmörgås")
1674 "xn--rksmrgs-5wao1o")
1676 "Whether to encode non-ASCII in domain names into ASCII according to IDNA.
1677 GNU Libidn, and in particular the elisp package \"idna.el\" and
1678 the external program \"idn\", must be installed for this
1679 functionality to work."
1681 :group
'message-headers
1682 :link
'(custom-manual "(message)IDNA")
1683 :type
'(choice (const :tag
"Ask" ask
)
1684 (const :tag
"Never" nil
)
1685 (const :tag
"Always" t
)))
1687 (defcustom message-generate-hashcash
(if (executable-find "hashcash") 'opportunistic
)
1688 "*Whether to generate X-Hashcash: headers.
1689 If t, always generate hashcash headers. If `opportunistic',
1690 only generate hashcash headers if it can be done without the user
1691 waiting (i.e., only asynchronously).
1693 You must have the \"hashcash\" binary installed, see `hashcash-path'."
1695 :group
'message-headers
1696 :link
'(custom-manual "(message)Mail Headers")
1697 :type
'(choice (const :tag
"Always" t
)
1698 (const :tag
"Never" nil
)
1699 (const :tag
"Opportunistic" opportunistic
)))
1701 ;;; Internal variables.
1703 (defvar message-sending-message
"Sending...")
1704 (defvar message-buffer-list nil
)
1705 (defvar message-this-is-news nil
)
1706 (defvar message-this-is-mail nil
)
1707 (defvar message-draft-article nil
)
1708 (defvar message-mime-part nil
)
1709 (defvar message-posting-charset nil
)
1710 (defvar message-inserted-headers nil
)
1711 (defvar message-inhibit-ecomplete nil
)
1713 ;; Byte-compiler warning
1714 (defvar gnus-active-hashtb
)
1715 (defvar gnus-read-active-file
)
1717 ;;; Regexp matching the delimiter of messages in UNIX mail format
1718 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1719 ;;; of rmail.el's rmail-unix-mail-delimiter.
1720 (defvar message-unix-mail-delimiter
1721 (let ((time-zone-regexp
1722 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1723 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1729 ;; Many things can happen to an RFC 822 mailbox before it is put into
1730 ;; a `From' line. The leading phrase can be stripped, e.g.
1731 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1732 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1733 ;; can be removed, e.g.
1734 ;; From: joe@y.z (Joe K
1736 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1739 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1740 ;; The mailbox can be removed or be replaced by white space, e.g.
1741 ;; From: "Joe User"{space}{tab}
1743 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1744 ;; where {space} and {tab} represent the Ascii space and tab characters.
1745 ;; We want to match the results of any of these manglings.
1746 ;; The following regexp rejects names whose first characters are
1747 ;; obviously bogus, but after that anything goes.
1748 "\\([^\0-\b\n-\r\^?].*\\)?"
1750 ;; The time the message was sent.
1751 "\\([^\0-\r \^?]+\\) +" ; day of the week
1752 "\\([^\0-\r \^?]+\\) +" ; month
1753 "\\([0-3]?[0-9]\\) +" ; day of month
1754 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1756 ;; Perhaps a time zone, specified by an abbreviation, or by a
1761 " \\([0-9][0-9]+\\) *"
1763 ;; On some systems the time zone can appear after the year, too.
1767 "\\(remote from .*\\)?"
1770 "Regexp matching the delimiter of messages in UNIX mail format.")
1772 (defvar message-unsent-separator
1773 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1774 "^ *---+ +Returned message +---+ *$\\|"
1775 "^Start of returned message$\\|"
1776 "^ *---+ +Original message +---+ *$\\|"
1777 "^ *--+ +begin message +--+ *$\\|"
1778 "^ *---+ +Original message follows +---+ *$\\|"
1779 "^ *---+ +Undelivered message follows +---+ *$\\|"
1780 "^------ This is a copy of the message, including all the headers. ------ *$\\|"
1781 "^|? *---+ +Message text follows: +---+ *|?$")
1782 "A regexp that matches the separator before the text of a failed message.")
1784 (defvar message-field-fillers
1785 '((To message-fill-field-address
)
1786 (Cc message-fill-field-address
)
1787 (From message-fill-field-address
))
1788 "Alist of header names/filler functions.")
1790 (defvar message-header-format-alist
1805 (References . message-shorten-references
)
1807 "Alist used for formatting headers.")
1809 (defvar message-options nil
1810 "Some saved answers when sending message.")
1812 (defvar message-send-mail-real-function nil
1813 "Internal send mail function.")
1815 (defvar message-bogus-system-names
"^localhost\\.\\|\\.local$"
1816 "The regexp of bogus system names.")
1818 (defcustom message-valid-fqdn-regexp
1819 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1821 "\\([a-z][a-z]\\|" ;; two letter country TDLs
1822 "aero\\|arpa\\|bitnet\\|biz\\|bofh\\|"
1823 "cat\\|com\\|coop\\|edu\\|gov\\|"
1824 "info\\|int\\|jobs\\|"
1825 "mil\\|mobi\\|museum\\|name\\|net\\|"
1826 "org\\|pro\\|travel\\|uucp\\)")
1827 ;; http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains
1828 ;; http://en.wikipedia.org/wiki/GTLD
1829 ;; `in the process of being approved': .asia .post .tel .sex
1830 ;; "dead" nato bitnet uucp
1831 "Regular expression that matches a valid FQDN."
1832 ;; see also: gnus-button-valid-fqdn-regexp
1834 :group
'message-headers
1837 (autoload 'gnus-alive-p
"gnus-util")
1838 (autoload 'gnus-delay-article
"gnus-delay")
1839 (autoload 'gnus-extract-address-components
"gnus-util")
1840 (autoload 'gnus-find-method-for-group
"gnus")
1841 (autoload 'gnus-group-decoded-name
"gnus-group")
1842 (autoload 'gnus-group-name-charset
"gnus-group")
1843 (autoload 'gnus-group-name-decode
"gnus-group")
1844 (autoload 'gnus-groups-from-server
"gnus")
1845 (autoload 'gnus-make-local-hook
"gnus-util")
1846 (autoload 'gnus-open-server
"gnus-int")
1847 (autoload 'gnus-output-to-mail
"gnus-util")
1848 (autoload 'gnus-output-to-rmail
"gnus-util")
1849 (autoload 'gnus-request-post
"gnus-int")
1850 (autoload 'gnus-select-frame-set-input-focus
"gnus-util")
1851 (autoload 'gnus-server-string
"gnus")
1852 (autoload 'idna-to-ascii
"idna")
1853 (autoload 'message-setup-toolbar
"messagexmas")
1854 (autoload 'mh-new-draft-name
"mh-comp")
1855 (autoload 'mh-send-letter
"mh-comp")
1856 (autoload 'nndraft-request-associate-buffer
"nndraft")
1857 (autoload 'nndraft-request-expire-articles
"nndraft")
1858 (autoload 'nnvirtual-find-group-art
"nnvirtual")
1859 (autoload 'rmail-dont-reply-to
"mail-utils")
1860 (autoload 'rmail-msg-is-pruned
"rmail")
1861 (autoload 'rmail-output
"rmailout")
1866 ;;; Utility functions.
1869 (defmacro message-y-or-n-p
(question show
&rest text
)
1870 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1871 `(message-talkative-question 'y-or-n-p
,question
,show
,@text
))
1873 (defmacro message-delete-line
(&optional n
)
1874 "Delete the current line (and the next N lines)."
1875 `(delete-region (progn (beginning-of-line) (point))
1876 (progn (forward-line ,(or n
1)) (point))))
1878 (defun message-mark-active-p ()
1879 "Non-nil means the mark and region are currently active in this buffer."
1882 (defun message-unquote-tokens (elems)
1883 "Remove double quotes (\") from strings in list ELEMS."
1884 (mapcar (lambda (item)
1885 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item
)
1886 (setq item
(concat (match-string 1 item
)
1887 (match-string 2 item
))))
1891 (defun message-tokenize-header (header &optional separator
)
1892 "Split HEADER into a list of header elements.
1893 SEPARATOR is a string of characters to be used as separators. \",\"
1894 is used by default."
1897 (let ((regexp (format "[%s]+" (or separator
",")))
1899 beg quoted elems paren
)
1901 (mm-enable-multibyte)
1902 (setq beg
(point-min))
1904 (goto-char (point-min))
1909 (cond ((and (> (point) beg
)
1911 (and (looking-at regexp
)
1914 (push (buffer-substring beg
(point)) elems
)
1915 (setq beg
(match-end 0)))
1916 ((eq (char-after) ?
\")
1917 (setq quoted
(not quoted
)))
1918 ((and (eq (char-after) ?\
()
1921 ((and (eq (char-after) ?\
))
1924 (nreverse elems
)))))
1926 (autoload 'nnheader-insert-file-contents
"nnheader")
1928 (defun message-mail-file-mbox-p (file)
1929 "Say whether FILE looks like a Unix mbox file."
1930 (when (and (file-exists-p file
)
1931 (file-readable-p file
)
1932 (file-regular-p file
))
1934 (nnheader-insert-file-contents file
)
1935 (goto-char (point-min))
1936 (looking-at message-unix-mail-delimiter
))))
1938 (defun message-fetch-field (header &optional not-all
)
1939 "The same as `mail-fetch-field', only remove all newlines.
1940 The buffer is expected to be narrowed to just the header of the message;
1941 see `message-narrow-to-headers-or-head'."
1942 (let* ((inhibit-point-motion-hooks t
)
1943 (value (mail-fetch-field header nil
(not not-all
))))
1945 (while (string-match "\n[\t ]+" value
)
1946 (setq value
(replace-match " " t t value
)))
1949 (defun message-field-value (header &optional not-all
)
1950 "The same as `message-fetch-field', only narrow to the headers first."
1953 (message-narrow-to-headers-or-head)
1954 (message-fetch-field header not-all
))))
1956 (defun message-narrow-to-field ()
1957 "Narrow the buffer to the header on the current line."
1959 (while (looking-at "[ \t]")
1965 (if (re-search-forward "^[^ \n\t]" nil t
)
1968 (goto-char (point-min)))
1970 (defun message-add-header (&rest headers
)
1971 "Add the HEADERS to the message header, skipping those already present."
1974 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers
))
1975 (error "Invalid header `%s'" (car headers
)))
1976 (setq hclean
(match-string 1 (car headers
)))
1978 (message-narrow-to-headers)
1979 (unless (re-search-forward (concat "^" (regexp-quote hclean
) ":") nil t
)
1980 (goto-char (point-max))
1981 (if (string-match "\n$" (car headers
))
1982 (insert (car headers
))
1983 (insert (car headers
) ?
\n)))))
1984 (setq headers
(cdr headers
))))
1986 (defmacro message-with-reply-buffer
(&rest forms
)
1987 "Evaluate FORMS in the reply buffer, if it exists."
1988 `(when (and (bufferp message-reply-buffer
)
1989 (buffer-name message-reply-buffer
))
1990 (with-current-buffer message-reply-buffer
1993 (put 'message-with-reply-buffer
'lisp-indent-function
0)
1994 (put 'message-with-reply-buffer
'edebug-form-spec
'(body))
1996 (defun message-fetch-reply-field (header)
1997 "Fetch field HEADER from the message we're replying to."
1998 (message-with-reply-buffer
2000 (mail-narrow-to-head)
2001 (message-fetch-field header
))))
2003 (defun message-strip-list-identifiers (subject)
2004 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
2005 (require 'gnus-sum
) ; for gnus-list-identifiers
2006 (let ((regexp (if (stringp gnus-list-identifiers
)
2007 gnus-list-identifiers
2008 (mapconcat 'identity gnus-list-identifiers
" *\\|"))))
2009 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
2010 " *\\)\\)+\\(Re: +\\)?\\)") subject
)
2011 (concat (substring subject
0 (match-beginning 1))
2012 (or (match-string 3 subject
)
2013 (match-string 5 subject
))
2018 (defun message-strip-subject-re (subject)
2019 "Remove \"Re:\" from subject lines in string SUBJECT."
2020 (if (string-match message-subject-re-regexp subject
)
2021 (substring subject
(match-end 0))
2024 (defcustom message-replacement-char
"."
2025 "Replacement character used instead of unprintable or not decodable chars."
2026 :group
'message-various
2027 :version
"22.1" ;; Gnus 5.10.9
2028 :type
'(choice string
2032 ;; FIXME: We also should call `message-strip-subject-encoded-words'
2033 ;; when forwarding. Probably in `message-make-forward-subject' and
2034 ;; `message-forward-make-body'.
2036 (defun message-strip-subject-encoded-words (subject)
2037 "Fix non-decodable words in SUBJECT."
2038 ;; Cf. `gnus-simplify-subject-fully'.
2039 (let* ((case-fold-search t
)
2040 (replacement-chars (format "[%s%s%s]"
2041 message-replacement-char
2042 message-replacement-char
2043 message-replacement-char
))
2044 (enc-word-re "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?\\([^?]+\\)\\(\\?=\\)")
2049 (goto-char (point-min))
2050 (when (re-search-forward enc-word-re nil t
)
2051 (setq cs-string
(match-string 1)))))
2052 cs-coding q-or-b word-beg word-end
)
2053 (if (or (not have-marker
) ;; No encoded word found...
2054 ;; ... or double encoding was correct:
2055 (and (stringp cs-string
)
2056 (setq cs-string
(downcase cs-string
))
2057 (mm-coding-system-p (intern cs-string
))
2061 Decoded Subject \"%s\"
2062 contains a valid encoded word. Decode again? "
2064 (setq cs-coding
(intern cs-string
))))))
2068 (goto-char (point-min))
2069 (while (re-search-forward enc-word-re nil t
)
2070 (setq cs-string
(downcase (match-string 1))
2071 q-or-b
(match-string 2)
2072 word-beg
(match-beginning 0)
2073 word-end
(match-end 0))
2075 (if (mm-coding-system-p (intern cs-string
))
2076 (setq cs-coding
(intern cs-string
))
2078 ;; No double encoded subject? => bogus charset.
2081 (mm-read-coding-system
2083 Decoded Subject \"%s\"
2084 contains an encoded word. The charset `%s' is unknown or invalid.
2085 Hit RET to replace non-decodable characters with \"%s\" or enter replacement
2087 subject cs-string message-replacement-char
)))
2089 (replace-match (concat "=?" (symbol-name cs-coding
)
2092 (goto-char word-beg
)
2093 (re-search-forward "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?" word-end t
)
2096 (if (string-match "\\`Q\\'" q-or-b
)
2099 (message "Replacing non-decodable characters with \"%s\"."
2100 message-replacement-char
)
2101 (while (re-search-forward "\\(=[A-F0-9][A-F0-9]\\)+"
2103 (replace-match message-replacement-char
)))
2105 (message "Replacing non-decodable characters with \"%s\"."
2107 (re-search-forward "[^?]+" word-end t
)
2108 (replace-match replacement-chars
))
2109 (re-search-forward "\\?=")
2110 (replace-match "")))))
2111 (rfc2047-decode-region (point-min) (point-max))
2114 ;;; Start of functions adopted from `message-utils.el'.
2116 (defun message-strip-subject-trailing-was (subject)
2117 "Remove trailing \"(was: <old subject>)\" from SUBJECT lines.
2118 Leading \"Re: \" is not stripped by this function. Use the function
2119 `message-strip-subject-re' for this."
2120 (let* ((query message-subject-trailing-was-query
)
2125 message-subject-trailing-was-ask-regexp
2126 message-subject-trailing-was-regexp
)
2129 (setq new
(substring subject
0 (match-beginning 0))))
2130 (if (or (not found
) (eq query nil
))
2133 (if (message-y-or-n-p
2134 "Strip `(was: <old subject>)' in subject? " t
2136 "Strip `(was: <old subject>)' in subject "
2137 "and use the new one instead?\n\n"
2138 "Current subject is: \""
2140 "New subject would be: \""
2142 "See the variable `message-subject-trailing-was-query' "
2143 "to get rid of this query."
2148 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
2150 (defun message-change-subject (new-subject)
2151 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
2154 (read-from-minibuffer "New subject: ")))
2155 (cond ((and (not (or (null new-subject
) ; new subject not empty
2156 (zerop (string-width new-subject
))
2157 (string-match "^[ \t]*$" new-subject
))))
2161 (message-narrow-to-headers)
2162 (message-fetch-field "Subject"))))
2163 (cond ((not old-subject
)
2164 (error "No current subject"))
2167 (regexp-quote new-subject
)
2169 old-subject
)) ; yes, it really is a new subject
2170 ;; delete eventual Re: prefix
2172 (message-strip-subject-re old-subject
))
2173 (message-goto-subject)
2174 (message-delete-line)
2175 (insert (concat "Subject: "
2178 old-subject
")\n")))))))))
2180 (defun message-mark-inserted-region (beg end
&optional verbatim
)
2181 "Mark some region in the current article with enclosing tags.
2182 See `message-mark-insert-begin' and `message-mark-insert-end'.
2183 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2184 (interactive "r\nP")
2186 ;; add to the end of the region first, otherwise end would be invalid
2188 (insert (if verbatim
"#v-\n" message-mark-insert-end
))
2190 (insert (if verbatim
"#v+\n" message-mark-insert-begin
))))
2192 (defun message-mark-insert-file (file &optional verbatim
)
2193 "Insert FILE at point, marking it with enclosing tags.
2194 See `message-mark-insert-begin' and `message-mark-insert-end'.
2195 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2196 (interactive "fFile to insert: \nP")
2197 ;; reverse insertion to get correct result.
2199 (insert (if verbatim
"#v-\n" message-mark-insert-end
))
2201 (insert-file-contents file
)
2203 (insert (if verbatim
"#v+\n" message-mark-insert-begin
))))
2205 (defun message-add-archive-header ()
2206 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
2207 The note can be customized using `message-archive-note'. When called with a
2208 prefix argument, ask for a text to insert. If you don't want the note in the
2209 body, set `message-archive-note' to nil."
2211 (if current-prefix-arg
2212 (setq message-archive-note
2213 (read-from-minibuffer "Reason for No-Archive: "
2214 (cons message-archive-note
0))))
2216 (if (message-goto-signature)
2217 (re-search-backward message-signature-separator
))
2218 (when message-archive-note
2219 (insert message-archive-note
)
2221 (message-add-header message-archive-header
)
2222 (message-sort-headers)))
2224 (defun message-cross-post-followup-to-header (target-group)
2225 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
2226 With prefix-argument just set Follow-Up, don't cross-post."
2228 (list ; Completion based on Gnus
2229 (completing-read "Followup To: "
2230 (if (boundp 'gnus-newsrc-alist
)
2232 nil nil
'("poster" .
0)
2233 (if (boundp 'gnus-group-history
)
2234 'gnus-group-history
))))
2235 (message-remove-header "Follow[Uu]p-[Tt]o" t
)
2236 (message-goto-newsgroups)
2238 ;; if we already did a crosspost before, kill old target
2239 (if (and message-cross-post-old-target
2241 (regexp-quote (concat "," message-cross-post-old-target
))
2244 ;; unless (followup is to poster or user explicitly asked not
2245 ;; to cross-post, or target-group is already in Newsgroups)
2246 ;; add target-group to Newsgroups line.
2248 ;; def: cross-post, req:no
2249 (and message-cross-post-default
(not current-prefix-arg
))
2250 ;; def: no-cross-post, req:yes
2251 (and (not message-cross-post-default
) current-prefix-arg
))
2252 (not (string-match "poster" target-group
))
2253 (not (string-match (regexp-quote target-group
)
2254 (message-fetch-field "Newsgroups"))))
2256 (insert (concat "," target-group
))))
2257 (end-of-line) ; ensure Followup: comes after Newsgroups:
2258 ;; unless new followup would be identical to Newsgroups line
2259 ;; make a new Followup-To line
2260 (if (not (string-match (concat "^[ \t]*"
2263 (message-fetch-field "Newsgroups")))
2264 (insert (concat "\nFollowup-To: " target-group
)))
2265 (setq message-cross-post-old-target target-group
))
2267 (defun message-cross-post-insert-note (target-group cross-post in-old
2269 "Insert a in message body note about a set Followup or Crosspost.
2270 If there have been previous notes, delete them. TARGET-GROUP specifies the
2271 group to Followup-To. When CROSS-POST is t, insert note about
2272 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
2273 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
2274 been made to before the user asked for a Crosspost."
2275 ;; start scanning body for previous uses
2276 (message-goto-signature)
2277 (let ((head (re-search-backward
2278 (concat "^" mail-header-separator
)
2279 nil t
))) ; just search in body
2280 (message-goto-signature)
2281 (while (re-search-backward
2282 (concat "^" (regexp-quote message-cross-post-note
) ".*")
2284 (message-delete-line))
2285 (message-goto-signature)
2286 (while (re-search-backward
2287 (concat "^" (regexp-quote message-followup-to-note
) ".*")
2289 (message-delete-line))
2291 (if (message-goto-signature)
2292 (re-search-backward message-signature-separator
))
2295 (string-match "^[ \t]*poster[ \t]*$" target-group
))
2296 (insert (concat message-followup-to-note target-group
"\n"))
2297 (insert (concat message-cross-post-note target-group
"\n")))))
2299 (defun message-cross-post-followup-to (target-group)
2300 "Crossposts message and set Followup-To to TARGET-GROUP.
2301 With prefix-argument just set Follow-Up, don't cross-post."
2303 (list ; Completion based on Gnus
2304 (completing-read "Followup To: "
2305 (if (boundp 'gnus-newsrc-alist
)
2307 nil nil
'("poster" .
0)
2308 (if (boundp 'gnus-group-history
)
2309 'gnus-group-history
))))
2310 (cond ((not (or (null target-group
) ; new subject not empty
2311 (zerop (string-width target-group
))
2312 (string-match "^[ \t]*$" target-group
)))
2314 (let* ((old-groups (message-fetch-field "Newsgroups"))
2315 (in-old (string-match
2316 (regexp-quote target-group
)
2317 (or old-groups
""))))
2318 ;; check whether target exactly matches old Newsgroups
2319 (cond ((not old-groups
)
2320 (error "No current newsgroup"))
2324 (regexp-quote target-group
)
2327 ;; yes, Newsgroups line must change
2328 (message-cross-post-followup-to-header target-group
)
2329 ;; insert note whether we do cross-post or followup-to
2330 (funcall message-cross-post-note-function
2332 (if (or (and message-cross-post-default
2333 (not current-prefix-arg
))
2334 (and (not message-cross-post-default
)
2335 current-prefix-arg
)) t
)
2336 in-old old-groups
))))))))
2338 ;;; Reduce To: to Cc: or Bcc: header
2340 (defun message-reduce-to-to-cc ()
2341 "Replace contents of To: header with contents of Cc: or Bcc: header."
2344 (save-restriction (message-narrow-to-headers)
2345 (message-fetch-field "cc")))
2347 (if (and (not cc-content
)
2350 (message-narrow-to-headers)
2351 (message-fetch-field "bcc"))))
2356 (message-delete-line)
2357 (insert (concat "To: " cc-content
"\n"))
2359 (message-narrow-to-headers)
2360 (message-remove-header (if bcc
2364 ;;; End of functions adopted from `message-utils.el'.
2366 (defun message-remove-header (header &optional is-regexp first reverse
)
2367 "Remove HEADER in the narrowed buffer.
2368 If IS-REGEXP, HEADER is a regular expression.
2369 If FIRST, only remove the first instance of the header.
2370 Return the number of headers removed."
2371 (goto-char (point-min))
2372 (let ((regexp (if is-regexp header
(concat "^" (regexp-quote header
) ":")))
2374 (case-fold-search t
)
2376 (while (and (not (eobp))
2379 (not (looking-at regexp
))
2380 (looking-at regexp
))
2387 ;; There might be a continuation header, so we have to search
2388 ;; until we find a new non-continuation line.
2391 (if (re-search-forward "^[^ \t]" nil t
)
2392 (goto-char (match-beginning 0))
2395 (if (re-search-forward "^[^ \t]" nil t
)
2396 (goto-char (match-beginning 0))
2397 (goto-char (point-max)))))
2400 (defun message-remove-first-header (header)
2401 "Remove the first instance of HEADER if there is more than one."
2403 (regexp (concat "^" (regexp-quote header
) ":")))
2405 (goto-char (point-min))
2406 (while (re-search-forward regexp nil t
)
2409 (message-remove-header header nil t
)
2412 (defun message-narrow-to-headers ()
2413 "Narrow the buffer to the head of the message."
2416 (goto-char (point-min))
2417 (if (re-search-forward
2418 (concat "^" (regexp-quote mail-header-separator
) "\n") nil t
)
2421 (goto-char (point-min)))
2423 (defun message-narrow-to-head-1 ()
2424 "Like `message-narrow-to-head'. Don't widen."
2426 (goto-char (point-min))
2427 (if (search-forward "\n\n" nil
1)
2430 (goto-char (point-min)))
2432 ;; FIXME: clarify diffference: message-narrow-to-head,
2433 ;; message-narrow-to-headers-or-head, message-narrow-to-headers
2434 (defun message-narrow-to-head ()
2435 "Narrow the buffer to the head of the message.
2436 Point is left at the beginning of the narrowed-to region."
2438 (message-narrow-to-head-1))
2440 (defun message-narrow-to-headers-or-head ()
2441 "Narrow the buffer to the head of the message."
2444 (goto-char (point-min))
2445 (if (re-search-forward (concat "\\(\n\\)\n\\|^\\("
2446 (regexp-quote mail-header-separator
)
2449 (or (match-end 1) (match-beginning 2))
2451 (goto-char (point-min)))
2453 (defun message-news-p ()
2454 "Say whether the current buffer contains a news message."
2455 (and (not message-this-is-mail
)
2456 (or message-this-is-news
2459 (message-narrow-to-headers)
2460 (and (message-fetch-field "newsgroups")
2461 (not (message-fetch-field "posted-to"))))))))
2463 (defun message-mail-p ()
2464 "Say whether the current buffer contains a mail message."
2465 (and (not message-this-is-news
)
2466 (or message-this-is-mail
2469 (message-narrow-to-headers)
2470 (or (message-fetch-field "to")
2471 (message-fetch-field "cc")
2472 (message-fetch-field "bcc")))))))
2474 (defun message-subscribed-p ()
2475 "Say whether we need to insert a MFT header."
2476 (or message-subscribed-regexps
2477 message-subscribed-addresses
2478 message-subscribed-address-file
2479 message-subscribed-address-functions
))
2481 (defun message-next-header ()
2482 "Go to the beginning of the next header."
2484 (or (eobp) (forward-char 1))
2485 (not (if (re-search-forward "^[^ \t]" nil t
)
2487 (goto-char (point-max)))))
2489 (defun message-sort-headers-1 ()
2490 "Sort the buffer as headers using `message-rank' text props."
2491 (goto-char (point-min))
2494 nil
'message-next-header
2496 (message-next-header)
2500 (or (get-text-property (point) 'message-rank
)
2503 (defun message-sort-headers ()
2504 "Sort the headers of the current message according to `message-header-format-alist'."
2508 (let ((max (1+ (length message-header-format-alist
)))
2510 (message-narrow-to-headers)
2511 (while (re-search-forward "^[^ \n]+:" nil t
)
2513 (match-beginning 0) (1+ (match-beginning 0))
2515 (if (setq rank
(length (memq (assq (intern (buffer-substring
2517 (1- (match-end 0))))
2518 message-header-format-alist
)
2519 message-header-format-alist
)))
2522 (message-sort-headers-1))))
2524 (defun message-kill-address ()
2525 "Kill the address under point."
2527 (let ((start (point)))
2528 (message-skip-to-next-address)
2529 (kill-region start
(point))))
2532 (autoload 'Info-goto-node
"info")
2533 (defvar mml2015-use
)
2535 (defun message-info (&optional arg
)
2536 "Display the Message manual.
2538 Prefixed with one \\[universal-argument], display the Emacs MIME
2539 manual. With two \\[universal-argument]'s, display the EasyPG or
2540 PGG manual, depending on the value of `mml2015-use'."
2542 ;; Don't use `info' because support for `(filename)nodename' is not
2543 ;; available in XEmacs < 21.5.12.
2544 (Info-goto-node (format "(%s)Top"
2548 ((eq arg
4) 'emacs-mime
)
2549 ;; `booleanp' only available in Emacs 22+
2550 ((and (not (memq arg
'(nil t
)))
2564 (defvar message-mode-map nil
)
2566 (unless message-mode-map
2567 (setq message-mode-map
(make-keymap))
2568 (set-keymap-parent message-mode-map text-mode-map
)
2569 (define-key message-mode-map
"\C-c?" 'describe-mode
)
2571 (define-key message-mode-map
"\C-c\C-f\C-t" 'message-goto-to
)
2572 (define-key message-mode-map
"\C-c\C-f\C-o" 'message-goto-from
)
2573 (define-key message-mode-map
"\C-c\C-f\C-b" 'message-goto-bcc
)
2574 (define-key message-mode-map
"\C-c\C-f\C-w" 'message-goto-fcc
)
2575 (define-key message-mode-map
"\C-c\C-f\C-c" 'message-goto-cc
)
2576 (define-key message-mode-map
"\C-c\C-f\C-s" 'message-goto-subject
)
2577 (define-key message-mode-map
"\C-c\C-f\C-r" 'message-goto-reply-to
)
2578 (define-key message-mode-map
"\C-c\C-f\C-n" 'message-goto-newsgroups
)
2579 (define-key message-mode-map
"\C-c\C-f\C-d" 'message-goto-distribution
)
2580 (define-key message-mode-map
"\C-c\C-f\C-f" 'message-goto-followup-to
)
2581 (define-key message-mode-map
"\C-c\C-f\C-m" 'message-goto-mail-followup-to
)
2582 (define-key message-mode-map
"\C-c\C-f\C-k" 'message-goto-keywords
)
2583 (define-key message-mode-map
"\C-c\C-f\C-u" 'message-goto-summary
)
2584 (define-key message-mode-map
"\C-c\C-f\C-i"
2585 'message-insert-or-toggle-importance
)
2586 (define-key message-mode-map
"\C-c\C-f\C-a"
2587 'message-generate-unsubscribed-mail-followup-to
)
2589 ;; modify headers (and insert notes in body)
2590 (define-key message-mode-map
"\C-c\C-fs" 'message-change-subject
)
2592 (define-key message-mode-map
"\C-c\C-fx" 'message-cross-post-followup-to
)
2593 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2594 (define-key message-mode-map
"\C-c\C-ft" 'message-reduce-to-to-cc
)
2595 (define-key message-mode-map
"\C-c\C-fa" 'message-add-archive-header
)
2596 ;; mark inserted text
2597 (define-key message-mode-map
"\C-c\M-m" 'message-mark-inserted-region
)
2598 (define-key message-mode-map
"\C-c\M-f" 'message-mark-insert-file
)
2600 (define-key message-mode-map
"\C-c\C-b" 'message-goto-body
)
2601 (define-key message-mode-map
"\C-c\C-i" 'message-goto-signature
)
2603 (define-key message-mode-map
"\C-c\C-t" 'message-insert-to
)
2604 (define-key message-mode-map
"\C-c\C-fw" 'message-insert-wide-reply
)
2605 (define-key message-mode-map
"\C-c\C-n" 'message-insert-newsgroups
)
2606 (define-key message-mode-map
"\C-c\C-l" 'message-to-list-only
)
2607 (define-key message-mode-map
"\C-c\C-f\C-e" 'message-insert-expires
)
2609 (define-key message-mode-map
"\C-c\C-u" 'message-insert-or-toggle-importance
)
2610 (define-key message-mode-map
"\C-c\M-n"
2611 'message-insert-disposition-notification-to
)
2613 (define-key message-mode-map
"\C-c\C-y" 'message-yank-original
)
2614 (define-key message-mode-map
"\C-c\M-\C-y" 'message-yank-buffer
)
2615 (define-key message-mode-map
"\C-c\C-q" 'message-fill-yanked-message
)
2616 (define-key message-mode-map
"\C-c\C-w" 'message-insert-signature
)
2617 (define-key message-mode-map
"\C-c\M-h" 'message-insert-headers
)
2618 (define-key message-mode-map
"\C-c\C-r" 'message-caesar-buffer-body
)
2619 (define-key message-mode-map
"\C-c\C-o" 'message-sort-headers
)
2620 (define-key message-mode-map
"\C-c\M-r" 'message-rename-buffer
)
2622 (define-key message-mode-map
"\C-c\C-c" 'message-send-and-exit
)
2623 (define-key message-mode-map
"\C-c\C-s" 'message-send
)
2624 (define-key message-mode-map
"\C-c\C-k" 'message-kill-buffer
)
2625 (define-key message-mode-map
"\C-c\C-d" 'message-dont-send
)
2626 (define-key message-mode-map
"\C-c\n" 'gnus-delay-article
)
2628 (define-key message-mode-map
"\C-c\M-k" 'message-kill-address
)
2629 (define-key message-mode-map
"\C-c\C-e" 'message-elide-region
)
2630 (define-key message-mode-map
"\C-c\C-v" 'message-delete-not-region
)
2631 (define-key message-mode-map
"\C-c\C-z" 'message-kill-to-signature
)
2632 (define-key message-mode-map
"\M-\r" 'message-newline-and-reformat
)
2633 (define-key message-mode-map
[remap split-line
] 'message-split-line
)
2635 (define-key message-mode-map
"\C-c\C-a" 'mml-attach-file
)
2637 (define-key message-mode-map
"\C-a" 'message-beginning-of-line
)
2638 (define-key message-mode-map
"\t" 'message-tab
)
2640 (define-key message-mode-map
"\M-n" 'message-display-abbrev
))
2643 message-mode-menu message-mode-map
"Message Menu."
2645 ["Yank Original" message-yank-original message-reply-buffer
]
2646 ["Fill Yanked Message" message-fill-yanked-message t
]
2647 ["Insert Signature" message-insert-signature t
]
2648 ["Caesar (rot13) Message" message-caesar-buffer-body t
]
2649 ["Caesar (rot13) Region" message-caesar-region
(message-mark-active-p)]
2650 ["Elide Region" message-elide-region
2651 :active
(message-mark-active-p)
2652 ,@(if (featurep 'xemacs
) nil
2653 '(:help
"Replace text in region with an ellipsis"))]
2654 ["Delete Outside Region" message-delete-not-region
2655 :active
(message-mark-active-p)
2656 ,@(if (featurep 'xemacs
) nil
2657 '(:help
"Delete all quoted text outside region"))]
2658 ["Kill To Signature" message-kill-to-signature t
]
2659 ["Newline and Reformat" message-newline-and-reformat t
]
2660 ["Rename buffer" message-rename-buffer t
]
2661 ["Spellcheck" ispell-message
2662 ,@(if (featurep 'xemacs
) '(t)
2663 '(:help
"Spellcheck this message"))]
2665 ["Insert Region Marked" message-mark-inserted-region
2666 :active
(message-mark-active-p)
2667 ,@(if (featurep 'xemacs
) nil
2668 '(:help
"Mark region with enclosing tags"))]
2669 ["Insert File Marked..." message-mark-insert-file
2670 ,@(if (featurep 'xemacs
) '(t)
2671 '(:help
"Insert file at point marked with enclosing tags"))]
2673 ["Send Message" message-send-and-exit
2674 ,@(if (featurep 'xemacs
) '(t)
2675 '(:help
"Send this message"))]
2676 ["Postpone Message" message-dont-send
2677 ,@(if (featurep 'xemacs
) '(t)
2678 '(:help
"File this draft message and exit"))]
2679 ["Send at Specific Time..." gnus-delay-article
2680 ,@(if (featurep 'xemacs
) '(t)
2681 '(:help
"Ask, then arrange to send message at that time"))]
2682 ["Kill Message" message-kill-buffer
2683 ,@(if (featurep 'xemacs
) '(t)
2684 '(:help
"Delete this message without sending"))]
2686 ["Message manual" message-info
2687 ,@(if (featurep 'xemacs
) '(t)
2688 '(:help
"Display the Message manual"))]))
2691 message-mode-field-menu message-mode-map
""
2693 ["To" message-goto-to t
]
2694 ["From" message-goto-from t
]
2695 ["Subject" message-goto-subject t
]
2696 ["Change subject..." message-change-subject t
]
2697 ["Cc" message-goto-cc t
]
2698 ["Bcc" message-goto-bcc t
]
2699 ["Fcc" message-goto-fcc t
]
2700 ["Reply-To" message-goto-reply-to t
]
2701 ["Flag As Important" message-insert-importance-high
2702 ,@(if (featurep 'xemacs
) '(t)
2703 '(:help
"Mark this message as important"))]
2704 ["Flag As Unimportant" message-insert-importance-low
2705 ,@(if (featurep 'xemacs
) '(t)
2706 '(:help
"Mark this message as unimportant"))]
2708 message-insert-disposition-notification-to
2709 ,@(if (featurep 'xemacs
) '(t)
2710 '(:help
"Request a receipt notification"))]
2712 ;; (typical) news stuff
2713 ["Summary" message-goto-summary t
]
2714 ["Keywords" message-goto-keywords t
]
2715 ["Newsgroups" message-goto-newsgroups t
]
2716 ["Fetch Newsgroups" message-insert-newsgroups t
]
2717 ["Followup-To" message-goto-followup-to t
]
2718 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2719 ["Crosspost / Followup-To..." message-cross-post-followup-to t
]
2720 ["Distribution" message-goto-distribution t
]
2721 ["Expires" message-insert-expires t
]
2722 ["X-No-Archive" message-add-archive-header t
]
2724 ;; (typical) mailing-lists stuff
2725 ["Fetch To" message-insert-to
2726 ,@(if (featurep 'xemacs
) '(t)
2727 '(:help
"Insert a To header that points to the author."))]
2728 ["Fetch To and Cc" message-insert-wide-reply
2729 ,@(if (featurep 'xemacs
) '(t)
2731 "Insert To and Cc headers as if you were doing a wide reply."))]
2733 ["Send to list only" message-to-list-only t
]
2734 ["Mail-Followup-To" message-goto-mail-followup-to t
]
2735 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2736 ,@(if (featurep 'xemacs
) '(t)
2737 '(:help
"Insert a reasonable `Mail-Followup-To:' header."))]
2738 ["Reduce To: to Cc:" message-reduce-to-to-cc t
]
2740 ["Sort Headers" message-sort-headers t
]
2741 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t
]
2742 ;; We hide `message-hidden-headers' by narrowing the buffer.
2743 ["Show Hidden Headers" widen t
]
2744 ["Goto Body" message-goto-body t
]
2745 ["Goto Signature" message-goto-signature t
]))
2747 (defvar message-tool-bar-map nil
)
2749 (defvar facemenu-add-face-function
)
2750 (defvar facemenu-remove-face-function
)
2752 ;;; Forbidden properties
2754 ;; We use `after-change-functions' to keep special text properties
2755 ;; that interfere with the normal function of message mode out of the
2758 (defcustom message-strip-special-text-properties t
2759 "Strip special properties from the message buffer.
2761 Emacs has a number of special text properties which can break message
2762 composing in various ways. If this option is set, message will strip
2763 these properties from the message composition buffer. However, some
2764 packages requires these properties to be present in order to work.
2765 If you use one of these packages, turn this option off, and hope the
2766 message composition doesn't break too bad."
2768 :group
'message-various
2769 :link
'(custom-manual "(message)Various Message Variables")
2772 (defconst message-forbidden-properties
2773 ;; No reason this should be clutter up customize. We make it a
2774 ;; property list (rather than a list of property symbols), to be
2775 ;; directly useful for `remove-text-properties'.
2776 '(field nil read-only nil invisible nil intangible nil
2777 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2778 insert-behind-hooks nil point-entered nil point-left nil
)
2779 ;; Other special properties:
2780 ;; category, face, display: probably doesn't do any harm.
2781 ;; fontified: is used by font-lock.
2782 ;; syntax-table, local-map: I dunno.
2783 ;; We need to add XEmacs names to the list.
2784 "Property list of with properties forbidden in message buffers.
2785 The values of the properties are ignored, only the property names are used.")
2787 (defun message-tamago-not-in-use-p (pos)
2788 "Return t when tamago version 4 is not in use at the cursor position.
2789 Tamago version 4 is a popular input method for writing Japanese text.
2790 It uses the properties `intangible', `invisible', `modification-hooks'
2791 and `read-only' when translating ascii or kana text to kanji text.
2792 These properties are essential to work, so we should never strip them."
2793 (not (and (boundp 'egg-modefull-mode
)
2794 (symbol-value 'egg-modefull-mode
)
2795 (or (memq (get-text-property pos
'intangible
)
2796 '(its-part-1 its-part-2
))
2797 (get-text-property pos
'egg-end
)
2798 (get-text-property pos
'egg-lang
)
2799 (get-text-property pos
'egg-start
)))))
2801 (defsubst message-mail-alias-type-p
(type)
2802 (if (atom message-mail-alias-type
)
2803 (eq message-mail-alias-type type
)
2804 (memq type message-mail-alias-type
)))
2806 (defun message-strip-forbidden-properties (begin end
&optional old-length
)
2807 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2808 This function is intended to be called from `after-change-functions'.
2809 See also `message-forbidden-properties'."
2810 (when (and (message-mail-alias-type-p 'ecomplete
)
2811 (memq this-command message-self-insert-commands
))
2812 (message-display-abbrev))
2813 (when (and message-strip-special-text-properties
2814 (message-tamago-not-in-use-p begin
))
2815 (let ((buffer-read-only nil
)
2816 (inhibit-read-only t
))
2817 (remove-text-properties begin end message-forbidden-properties
))))
2819 (autoload 'ecomplete-setup
"ecomplete") ;; for Emacs <23.
2822 (define-derived-mode message-mode text-mode
"Message"
2823 "Major mode for editing mail and news to be sent.
2824 Like Text Mode but with these additional commands:\\<message-mode-map>
2825 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2826 C-c C-d Postpone sending the message C-c C-k Kill the message
2827 C-c C-f move to a header field (and create it if there isn't):
2828 C-c C-f C-t move to To C-c C-f C-s move to Subject
2829 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2830 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2831 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2832 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2833 C-c C-f C-o move to From (\"Originator\")
2834 C-c C-f C-f move to Followup-To
2835 C-c C-f C-m move to Mail-Followup-To
2836 C-c C-f C-e move to Expires
2837 C-c C-f C-i cycle through Importance values
2838 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2839 C-c C-f x crossposting with FollowUp-To header and note in body
2840 C-c C-f t replace To: header with contents of Cc: or Bcc:
2841 C-c C-f a Insert X-No-Archive: header and a note in the body
2842 C-c C-t `message-insert-to' (add a To header to a news followup)
2843 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2844 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2845 C-c C-b `message-goto-body' (move to beginning of message text).
2846 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2847 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2848 C-c C-y `message-yank-original' (insert current message, if any).
2849 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2850 C-c C-e `message-elide-region' (elide the text between point and mark).
2851 C-c C-v `message-delete-not-region' (remove the text outside the region).
2852 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2853 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2854 C-c C-a `mml-attach-file' (attach a file as MIME).
2855 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2856 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2857 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2858 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2859 M-RET `message-newline-and-reformat' (break the line and reformat)."
2860 (setq local-abbrev-table text-mode-abbrev-table
)
2861 (set (make-local-variable 'message-reply-buffer
) nil
)
2862 (set (make-local-variable 'message-inserted-headers
) nil
)
2863 (set (make-local-variable 'message-send-actions
) nil
)
2864 (set (make-local-variable 'message-return-action
) nil
)
2865 (set (make-local-variable 'message-exit-actions
) nil
)
2866 (set (make-local-variable 'message-kill-actions
) nil
)
2867 (set (make-local-variable 'message-postpone-actions
) nil
)
2868 (set (make-local-variable 'message-draft-article
) nil
)
2869 (setq buffer-offer-save t
)
2870 (set (make-local-variable 'facemenu-add-face-function
)
2872 (let ((face-fun (cdr (assq face message-face-alist
))))
2874 (funcall face-fun
(point) end
)
2875 (error "Face %s not configured for %s mode" face mode-name
)))
2877 (set (make-local-variable 'facemenu-remove-face-function
) t
)
2878 (set (make-local-variable 'message-reply-headers
) nil
)
2879 (make-local-variable 'message-newsreader
)
2880 (make-local-variable 'message-mailer
)
2881 (make-local-variable 'message-post-method
)
2882 (set (make-local-variable 'message-sent-message-via
) nil
)
2883 (set (make-local-variable 'message-checksum
) nil
)
2884 (set (make-local-variable 'message-mime-part
) 0)
2885 (message-setup-fill-variables)
2886 (when message-fill-column
2887 (setq fill-column message-fill-column
)
2888 (turn-on-auto-fill))
2889 ;; Allow using comment commands to add/remove quoting.
2890 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2891 (when message-yank-prefix
2892 (set (make-local-variable 'comment-start
) message-yank-prefix
)
2893 (set (make-local-variable 'comment-start-skip
)
2894 (concat "^" (regexp-quote message-yank-prefix
) "[ \t]*")))
2895 (if (featurep 'xemacs
)
2896 (message-setup-toolbar)
2897 (set (make-local-variable 'font-lock-defaults
)
2898 '(message-font-lock-keywords t
))
2899 (if (boundp 'tool-bar-map
)
2900 (set (make-local-variable 'tool-bar-map
) (message-make-tool-bar))))
2901 (easy-menu-add message-mode-menu message-mode-map
)
2902 (easy-menu-add message-mode-field-menu message-mode-map
)
2903 (gnus-make-local-hook 'after-change-functions
)
2904 ;; Mmmm... Forbidden properties...
2905 (add-hook 'after-change-functions
'message-strip-forbidden-properties
2907 ;; Allow mail alias things.
2909 ((message-mail-alias-type-p 'abbrev
)
2910 (if (fboundp 'mail-abbrevs-setup
)
2911 (mail-abbrevs-setup)
2912 (if (fboundp 'mail-aliases-setup
) ; warning avoidance
2913 (mail-aliases-setup))))
2914 ((message-mail-alias-type-p 'ecomplete
)
2916 (add-hook 'completion-at-point-functions
'message-completion-function nil t
)
2917 (unless buffer-file-name
2918 (message-set-auto-save-file-name))
2919 (unless (buffer-base-buffer)
2920 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2921 ;; multibyte is not necessary at all. -- zsh
2922 (mm-enable-multibyte))
2923 (set (make-local-variable 'indent-tabs-mode
) nil
) ;No tabs for indentation.
2926 (defun message-setup-fill-variables ()
2927 "Setup message fill variables."
2928 (set (make-local-variable 'fill-paragraph-function
)
2929 'message-fill-paragraph
)
2930 (make-local-variable 'paragraph-separate
)
2931 (make-local-variable 'paragraph-start
)
2932 (make-local-variable 'adaptive-fill-regexp
)
2933 (unless (boundp 'adaptive-fill-first-line-regexp
)
2934 (setq adaptive-fill-first-line-regexp nil
))
2935 (make-local-variable 'adaptive-fill-first-line-regexp
)
2936 (let ((quote-prefix-regexp
2937 ;; User should change message-cite-prefix-regexp if
2938 ;; message-yank-prefix is set to an abnormal value.
2939 (concat "\\(" message-cite-prefix-regexp
"\\)[ \t]*")))
2940 (setq paragraph-start
2942 (regexp-quote mail-header-separator
) "$\\|"
2943 "[ \t]*$\\|" ; blank lines
2944 "-- $\\|" ; signature delimiter
2945 "---+$\\|" ; delimiters for forwarded messages
2946 page-delimiter
"$\\|" ; spoiler warnings
2947 ".*wrote:$\\|" ; attribution lines
2948 quote-prefix-regexp
"$\\|" ; empty lines in quoted text
2950 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
2951 (setq paragraph-separate paragraph-start
)
2952 (setq adaptive-fill-regexp
2953 (concat quote-prefix-regexp
"\\|" adaptive-fill-regexp
))
2954 (setq adaptive-fill-first-line-regexp
2955 (concat quote-prefix-regexp
"\\|"
2956 adaptive-fill-first-line-regexp
)))
2957 (make-local-variable 'auto-fill-inhibit-regexp
)
2958 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2959 (setq auto-fill-inhibit-regexp nil
)
2960 (make-local-variable 'normal-auto-fill-function
)
2961 (setq normal-auto-fill-function
'message-do-auto-fill
)
2962 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2963 ;; In that case, ensure that it uses the right function. The real
2964 ;; solution would be not to use `define-derived-mode', and run
2965 ;; `text-mode-hook' ourself at the end of the mode.
2966 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2967 ;; This kludge is unneeded in Emacs>=21 since define-derived-mode is
2968 ;; now careful to run parent hooks after the body. --Stef
2969 (when auto-fill-function
2970 (setq auto-fill-function normal-auto-fill-function
)))
2975 ;;; Message mode commands
2978 ;;; Movement commands
2980 (defun message-goto-to ()
2981 "Move point to the To header."
2983 (message-position-on-field "To"))
2985 (defun message-goto-from ()
2986 "Move point to the From header."
2988 (message-position-on-field "From"))
2990 (defun message-goto-subject ()
2991 "Move point to the Subject header."
2993 (message-position-on-field "Subject"))
2995 (defun message-goto-cc ()
2996 "Move point to the Cc header."
2998 (message-position-on-field "Cc" "To"))
3000 (defun message-goto-bcc ()
3001 "Move point to the Bcc header."
3003 (message-position-on-field "Bcc" "Cc" "To"))
3005 (defun message-goto-fcc ()
3006 "Move point to the Fcc header."
3008 (message-position-on-field "Fcc" "To" "Newsgroups"))
3010 (defun message-goto-reply-to ()
3011 "Move point to the Reply-To header."
3013 (message-position-on-field "Reply-To" "Subject"))
3015 (defun message-goto-newsgroups ()
3016 "Move point to the Newsgroups header."
3018 (message-position-on-field "Newsgroups"))
3020 (defun message-goto-distribution ()
3021 "Move point to the Distribution header."
3023 (message-position-on-field "Distribution"))
3025 (defun message-goto-followup-to ()
3026 "Move point to the Followup-To header."
3028 (message-position-on-field "Followup-To" "Newsgroups"))
3030 (defun message-goto-mail-followup-to ()
3031 "Move point to the Mail-Followup-To header."
3033 (message-position-on-field "Mail-Followup-To" "To"))
3035 (defun message-goto-keywords ()
3036 "Move point to the Keywords header."
3038 (message-position-on-field "Keywords" "Subject"))
3040 (defun message-goto-summary ()
3041 "Move point to the Summary header."
3043 (message-position-on-field "Summary" "Subject"))
3046 (defmacro message-called-interactively-p
(kind)
3049 (eval '(called-interactively-p 'any
))
3051 `(called-interactively-p ,kind
))
3053 (wrong-number-of-arguments '(called-interactively-p))
3055 (void-function '(interactive-p)))))
3057 (defun message-goto-body ()
3058 "Move point to the beginning of the message body."
3060 (when (and (message-called-interactively-p 'any
)
3061 (looking-at "[ \t]*\n"))
3063 (goto-char (point-min))
3064 (or (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
3065 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t
)))
3067 (defun message-in-body-p ()
3068 "Return t if point is in the message body."
3069 (let ((body (save-excursion (message-goto-body))))
3072 (defun message-goto-eoh ()
3073 "Move point to the end of the headers."
3078 (defun message-goto-signature ()
3079 "Move point to the beginning of the message signature.
3080 If there is no signature in the article, go to the end and
3083 (goto-char (point-min))
3084 (if (re-search-forward message-signature-separator nil t
)
3086 (goto-char (point-max))
3089 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc
)
3090 "Insert a reasonable MFT header in a post to an unsubscribed list.
3091 When making original posts to a mailing list you are not subscribed to,
3092 you have to type in a MFT header by hand. The contents, usually, are
3093 the addresses of the list and your own address. This function inserts
3094 such a header automatically. It fetches the contents of the To: header
3095 in the current mail buffer, and appends the current `user-mail-address'.
3097 If the optional argument INCLUDE-CC is non-nil, the addresses in the
3098 Cc: header are also put into the MFT."
3103 (message-narrow-to-headers)
3104 (message-remove-header "Mail-Followup-To")
3105 (setq cc
(and include-cc
(message-fetch-field "Cc")))
3107 (concat (message-fetch-field "To") "," cc
)
3108 (message-fetch-field "To"))))
3109 (message-goto-mail-followup-to)
3110 (insert (concat tos
", " user-mail-address
))))
3114 (defun message-insert-to (&optional force
)
3115 "Insert a To header that points to the author of the article being replied to.
3116 If the original author requested not to be sent mail, don't insert unless the
3117 prefix FORCE is given."
3119 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
3120 (dont (and mct
(or (equal (downcase mct
) "never")
3121 (equal (downcase mct
) "nobody"))))
3122 (to (or (message-fetch-reply-field "mail-reply-to")
3123 (message-fetch-reply-field "reply-to")
3124 (message-fetch-reply-field "from"))))
3128 "Ignoring the user request not to have copies sent via mail"
3129 "Complying with the user request not to have copies sent via mail")))
3130 (when (and force
(not to
))
3131 (error "No mail address in the article"))
3132 (when (and to
(or force
(not dont
)))
3133 (message-carefully-insert-headers (list (cons 'To to
))))))
3135 (defun message-insert-wide-reply ()
3136 "Insert To and Cc headers as if you were doing a wide reply."
3138 (let ((headers (message-with-reply-buffer
3139 (message-get-reply-headers t
))))
3140 (message-carefully-insert-headers headers
)))
3142 (defcustom message-header-synonyms
3145 "List of lists of header synonyms.
3146 E.g., if this list contains a member list with elements `Cc' and `To',
3147 then `message-carefully-insert-headers' will not insert a `To' header
3148 when the message is already `Cc'ed to the recipient."
3150 :group
'message-headers
3151 :link
'(custom-manual "(message)Message Headers")
3152 :type
'(repeat sexp
))
3154 (defun message-carefully-insert-headers (headers)
3155 "Insert the HEADERS, an alist, into the message buffer.
3156 Does not insert the headers when they are already present there
3157 or in the synonym headers, defined by `message-header-synonyms'."
3158 ;; FIXME: Should compare only the address and not the full name. Comparison
3159 ;; should be done case-folded (and with `string=' rather than
3161 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
3162 (dolist (header headers
)
3163 (let* ((header-name (symbol-name (car header
)))
3164 (new-header (cdr header
))
3165 (synonyms (loop for synonym in message-header-synonyms
3166 when
(memq (car header
) synonym
) return synonym
))
3168 (loop for synonym in synonyms
3169 for old-header
= (mail-fetch-field (symbol-name synonym
))
3170 when
(and old-header
(string-match new-header old-header
))
3173 (message "already have `%s' in `%s'" new-header old-header
)
3174 (when (and (message-position-on-field header-name
)
3175 (setq old-header
(mail-fetch-field header-name
))
3176 (not (string-match "\\` *\\'" old-header
)))
3178 (insert new-header
)))))
3180 (defun message-widen-reply ()
3181 "Widen the reply to include maximum recipients."
3184 (and (bufferp message-reply-buffer
)
3185 (buffer-name message-reply-buffer
)
3186 (with-current-buffer message-reply-buffer
3187 (message-get-reply-headers t
)))))
3190 (message-narrow-to-headers)
3191 (dolist (elem follow-to
)
3192 (message-remove-header (symbol-name (car elem
)))
3193 (goto-char (point-min))
3194 (insert (symbol-name (car elem
)) ": "
3195 (cdr elem
) "\n"))))))
3197 (defun message-insert-newsgroups ()
3198 "Insert the Newsgroups header from the article being replied to."
3200 (when (and (message-position-on-field "Newsgroups")
3201 (mail-fetch-field "newsgroups")
3202 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
3204 (insert (or (message-fetch-reply-field "newsgroups") "")))
3208 ;;; Various commands
3210 (defun message-delete-not-region (beg end
)
3211 "Delete everything in the body of the current message outside of the region."
3216 ;; snarf citation prefix, if appropriate
3217 (unless (eq (point) (progn (beginning-of-line) (point)))
3218 (when (looking-at message-cite-prefix-regexp
)
3219 (setq citeprefix
(match-string 0))))
3221 (delete-region (point) (if (not (message-goto-signature))
3227 (delete-region beg
(progn (message-goto-body)
3231 (insert citeprefix
))))
3232 (when (message-goto-signature)
3235 (defun message-kill-to-signature (&optional arg
)
3236 "Kill all text up to the signature.
3237 If a numeric argument or prefix arg is given, leave that number
3238 of lines before the signature intact."
3242 (let ((point (point)))
3243 (narrow-to-region point
(point-max))
3244 (message-goto-signature)
3246 (if (and arg
(numberp arg
))
3247 (forward-line (- -
1 arg
))
3249 (unless (= point
(point))
3250 (kill-region point
(point))
3254 (defun message-newline-and-reformat (&optional arg not-break
)
3255 "Insert four newlines, and then reformat if inside quoted text.
3256 Prefix arg means justify as well."
3257 (interactive (list (if current-prefix-arg
'full
)))
3258 (let (quoted point beg end leading-space bolp fill-paragraph-function
)
3259 (setq point
(point))
3262 (setq bolp
(= beg point
))
3263 ;; Find first line of the paragraph.
3265 (while (and (not (eobp))
3266 (not (looking-at message-cite-prefix-regexp
))
3267 (looking-at paragraph-start
))
3270 (when (looking-at message-cite-prefix-regexp
)
3271 (setq quoted
(match-string 0))
3272 (goto-char (match-end 0))
3273 (looking-at "[ \t]*")
3274 (setq leading-space
(match-string 0)))
3278 (< (- point beg
) (length quoted
)))
3279 ;; break inside the cite prefix.
3285 (while (and (not (eobp))
3286 (not (looking-at paragraph-separate
))
3287 (looking-at message-cite-prefix-regexp
)
3288 (equal quoted
(match-string 0)))
3289 (goto-char (match-end 0))
3290 (looking-at "[ \t]*")
3291 (if (> (length leading-space
) (length (match-string 0)))
3292 (setq leading-space
(match-string 0)))
3296 (while (and (if (bobp) nil
(forward-line -
1) t
)
3297 (not (looking-at paragraph-start
))
3298 (looking-at message-cite-prefix-regexp
)
3299 (equal quoted
(match-string 0)))
3301 (goto-char (match-end 0))
3302 (looking-at "[ \t]*")
3303 (if (> (length leading-space
) (length (match-string 0)))
3304 (setq leading-space
(match-string 0)))))
3305 (while (and (not (eobp))
3306 (not (looking-at paragraph-separate
))
3307 (not (looking-at message-cite-prefix-regexp
)))
3311 (while (and (if (bobp) nil
(forward-line -
1) t
)
3312 (not (looking-at paragraph-start
))
3313 (not (looking-at message-cite-prefix-regexp
)))
3314 (setq beg
(point))))
3317 (narrow-to-region beg end
)
3324 (setq point
(point))
3325 ;; (newline 2) doesn't mark both newline's as hard, so call
3326 ;; newline twice. -jas
3329 (delete-region (point) (re-search-forward "[ \t]*"))
3330 (when (and quoted
(not bolp
))
3331 (insert quoted leading-space
)))
3334 (let* ((adaptive-fill-regexp
3335 (regexp-quote (concat quoted leading-space
)))
3336 (adaptive-fill-first-line-regexp
3337 adaptive-fill-regexp
))
3338 (fill-paragraph arg
))
3339 (fill-paragraph arg
))
3340 (if point
(goto-char point
)))))
3342 (defun message-fill-paragraph (&optional arg
)
3343 "Message specific function to fill a paragraph.
3344 This function is used as the value of `fill-paragraph-function' in
3345 Message buffers and is not meant to be called directly."
3346 (interactive (list (if current-prefix-arg
'full
)))
3347 (if (if (boundp 'filladapt-mode
) filladapt-mode
)
3349 (if (message-point-in-header-p)
3350 (message-fill-field)
3351 (message-newline-and-reformat arg t
))
3354 (defun message-point-in-header-p ()
3355 "Return t if point is in the header."
3357 (not (re-search-backward
3358 (concat "^" (regexp-quote mail-header-separator
) "\n") nil t
))))
3360 (defun message-do-auto-fill ()
3361 "Like `do-auto-fill', but don't fill in message header."
3362 (unless (message-point-in-header-p)
3365 (defun message-insert-signature (&optional force
)
3366 "Insert a signature. See documentation for variable `message-signature'."
3367 (interactive (list 0))
3370 ((and (null message-signature
)
3373 (goto-char (point-max))
3374 (not (re-search-backward message-signature-separator nil t
))))
3375 ((and (null message-signature
)
3378 ((functionp message-signature
)
3379 (funcall message-signature
))
3380 ((listp message-signature
)
3381 (eval message-signature
))
3382 (t message-signature
)))
3385 (cond ((stringp signature
)
3387 ((and (eq t signature
) message-signature-file
)
3388 (setq signature-file
3389 (if (and message-signature-directory
3390 ;; don't actually use the signature directory
3391 ;; if message-signature-file contains a path.
3392 (not (file-name-directory
3393 message-signature-file
)))
3394 (expand-file-name message-signature-file
3395 message-signature-directory
)
3396 message-signature-file
))
3397 (file-exists-p signature-file
))))
3399 (goto-char (point-max))
3400 ;; Insert the signature.
3403 (when message-signature-insert-empty-line
3406 (if (eq signature t
)
3407 (insert-file-contents signature-file
)
3409 (goto-char (point-max))
3410 (or (bolp) (insert "\n")))))
3412 (defun message-insert-importance-high ()
3413 "Insert header to mark message as important."
3417 (message-narrow-to-headers)
3418 (message-remove-header "Importance"))
3420 (insert "Importance: high\n")))
3422 (defun message-insert-importance-low ()
3423 "Insert header to mark message as unimportant."
3427 (message-narrow-to-headers)
3428 (message-remove-header "Importance"))
3430 (insert "Importance: low\n")))
3432 (defun message-insert-or-toggle-importance ()
3433 "Insert a \"Importance: high\" header, or cycle through the header values.
3434 The three allowed values according to RFC 1327 are `high', `normal'
3441 (message-narrow-to-headers)
3442 (when (setq cur
(message-fetch-field "Importance"))
3443 (message-remove-header "Importance")
3444 (setq new
(cond ((string= cur
"high")
3446 ((string= cur
"low")
3451 (insert (format "Importance: %s\n" new
)))))
3453 (defun message-insert-disposition-notification-to ()
3454 "Request a disposition notification (return receipt) to this message.
3455 Note that this should not be used in newsgroups."
3459 (message-narrow-to-headers)
3460 (message-remove-header "Disposition-Notification-To"))
3462 (insert (format "Disposition-Notification-To: %s\n"
3463 (or (message-field-value "Reply-to")
3464 (message-field-value "From")
3465 (message-make-from))))))
3467 (defun message-elide-region (b e
)
3468 "Elide the text in the region.
3469 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3473 (insert message-elide-ellipsis
))
3475 (defvar message-caesar-translation-table nil
)
3477 (defun message-caesar-region (b e
&optional n
)
3478 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3481 (min (point) (or (mark t
) (point)))
3482 (max (point) (or (mark t
) (point)))
3483 (when current-prefix-arg
3484 (prefix-numeric-value current-prefix-arg
))))
3486 (setq n
(if (numberp n
) (mod n
26) 13)) ;canonize N
3487 (unless (or (zerop n
) ; no action needed for a rot of 0
3488 (= b e
)) ; no region to rotate
3489 ;; We build the table, if necessary.
3490 (when (or (not message-caesar-translation-table
)
3491 (/= (aref message-caesar-translation-table ?a
) (+ ?a n
)))
3492 (setq message-caesar-translation-table
3493 (message-make-caesar-translation-table n
)))
3494 (translate-region b e message-caesar-translation-table
)))
3496 (defun message-make-caesar-translation-table (n)
3497 "Create a rot table with offset N."
3499 (table (make-string 256 0)))
3500 (while (< (incf i
) 256)
3503 (substring table
0 ?A
)
3504 (substring table
(+ ?A n
) (+ ?A n
(- 26 n
)))
3505 (substring table ?A
(+ ?A n
))
3506 (substring table
(+ ?A
26) ?a
)
3507 (substring table
(+ ?a n
) (+ ?a n
(- 26 n
)))
3508 (substring table ?a
(+ ?a n
))
3509 (substring table
(+ ?a
26) 255))))
3511 (defun message-caesar-buffer-body (&optional rotnum wide
)
3512 "Caesar rotate all letters in the current buffer by 13 places.
3513 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3514 With prefix arg, specifies the number of places to rotate each letter forward.
3515 Mail and USENET news headers are not rotated unless WIDE is non-nil."
3516 (interactive (if current-prefix-arg
3517 (list (prefix-numeric-value current-prefix-arg
))
3521 (when (and (not wide
) (message-goto-body))
3522 (narrow-to-region (point) (point-max)))
3523 (message-caesar-region (point-min) (point-max) rotnum
))))
3525 (defun message-pipe-buffer-body (program)
3526 "Pipe the message body in the current buffer through PROGRAM."
3529 (when (message-goto-body)
3530 (narrow-to-region (point) (point-max)))
3531 (shell-command-on-region
3532 (point-min) (point-max) program nil t
))))
3534 (defun message-rename-buffer (&optional enter-string
)
3535 "Rename the *message* buffer to \"*message* RECIPIENT\".
3536 If the function is run with a prefix, it will ask for a new buffer
3537 name, rather than giving an automatic name."
3538 (interactive "Pbuffer name: ")
3541 (goto-char (point-min))
3542 (narrow-to-region (point)
3543 (search-forward mail-header-separator nil
'end
))
3545 (if (message-news-p) (message-fetch-field "Newsgroups")
3546 (message-fetch-field "To"))
3549 (if (string-match "," mail-to
)
3550 (concat (substring mail-to
0 (match-beginning 0)) ", ...")
3552 (name-default (concat "*message* " mail-trimmed-to
))
3553 (name (if enter-string
3554 (read-string "New buffer name: " name-default
)
3556 (rename-buffer name t
)))))
3558 (defun message-fill-yanked-message (&optional justifyp
)
3559 "Fill the paragraphs of a message yanked into this one.
3560 Numeric argument means justify as well."
3563 (goto-char (point-min))
3564 (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
3565 (let ((fill-prefix message-yank-prefix
))
3566 (fill-individual-paragraphs (point) (point-max) justifyp
))))
3568 (defun message-indent-citation (&optional start end yank-only
)
3569 "Modify text just inserted from a message to be cited.
3570 The inserted text should be the region.
3571 When this function returns, the region is again around the modified text.
3573 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3574 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3575 (unless start
(setq start
(point)))
3577 ;; Remove unwanted headers.
3578 (when message-ignored-cited-headers
3583 (if (search-forward "\n\n" nil t
)
3586 (message-remove-header message-ignored-cited-headers t
)
3587 (when (= (point-min) (point-max))
3588 (setq all-removed t
))
3589 (goto-char (point-max)))
3593 ;; Delete blank lines at the start of the buffer.
3594 (while (and (point-min)
3597 (message-delete-line))
3598 ;; Delete blank lines at the end of the buffer.
3599 (goto-char (point-max))
3602 (while (and (zerop (forward-line -
1))
3604 (message-delete-line)))
3605 ;; Do the indentation.
3606 (if (null message-yank-prefix
)
3607 (indent-rigidly start
(or end
(mark t
)) message-indentation-spaces
)
3610 (while (< (point) (or end
(mark t
)))
3611 (cond ((looking-at ">")
3612 (insert message-yank-cited-prefix
))
3614 (insert message-yank-empty-prefix
))
3616 (insert message-yank-prefix
)))
3620 (defun message-remove-blank-cited-lines (&optional remove
)
3621 "Remove cited lines containing only blanks.
3622 If REMOVE is non-nil, remove newlines, too.
3624 To use this automatically, you may add this function to
3625 `gnus-message-setup-hook'."
3630 (when (boundp 'message-yank-cited-prefix
)
3631 (concat message-yank-cited-prefix
"\\|"))
3635 (gnus-message 8 "removing `%s'" citexp
)
3638 (while (re-search-forward citexp nil t
)
3639 (replace-match (if remove
"" "\n"))))))
3641 (defvar message-cite-reply-above nil
3642 "If non-nil, start own text above the quote.
3644 Note: Top posting is bad netiquette. Don't use it unless you
3645 really must. You probably want to set variable only for specific
3646 groups, e.g. using `gnus-posting-styles':
3648 (eval (set (make-local-variable 'message-cite-reply-above) t))
3650 This variable has no effect in news postings.")
3652 (defun message-yank-original (&optional arg
)
3653 "Insert the message being replied to, if any.
3654 Puts point before the text and mark after.
3655 Normally indents each nonblank line ARG spaces (default 3). However,
3656 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3658 This function uses `message-cite-function' to do the actual citing.
3660 Just \\[universal-argument] as argument means don't indent, insert no
3661 prefix, and don't delete any headers."
3663 (let ((modified (buffer-modified-p))
3665 (when (and message-reply-buffer
3666 message-cite-function
)
3667 (when message-cite-reply-above
3668 (if (and (not (message-news-p))
3669 (or (eq message-cite-reply-above
'is-evil
)
3671 Top posting is bad netiquette. Please don't top post unless you really must.
3672 Really top post? ")))
3675 (buffer-substring (message-goto-body)
3677 (delete-region (message-goto-body) (point-max)))
3678 (set (make-local-variable 'message-cite-reply-above
) nil
)))
3679 (if (bufferp message-reply-buffer
)
3680 (delete-windows-on message-reply-buffer t
))
3681 (push-mark (save-excursion
3683 ((bufferp message-reply-buffer
)
3684 (insert-buffer-substring message-reply-buffer
))
3685 ((and (consp message-reply-buffer
)
3686 (functionp (car message-reply-buffer
)))
3687 (apply (car message-reply-buffer
)
3688 (cdr message-reply-buffer
))))
3693 (funcall message-cite-function
)
3694 (unless (eq (char-before (mark t
)) ?
\n)
3696 (goto-char (mark t
))
3697 (insert-before-markers ?
\n)
3699 (when message-cite-reply-above
3702 (insert (if (bolp) "\n" "\n\n"))
3703 (message-goto-body))
3704 ;; Add a `message-setup-very-last-hook' here?
3705 ;; Add `gnus-article-highlight-citation' here?
3707 (setq message-checksum
(message-checksum))))))
3709 (defun message-yank-buffer (buffer)
3710 "Insert BUFFER into the current buffer and quote it."
3711 (interactive "bYank buffer: ")
3712 (let ((message-reply-buffer (get-buffer buffer
)))
3713 (save-window-excursion
3714 (message-yank-original))))
3716 (defun message-buffers ()
3717 "Return a list of active message buffers."
3719 (save-current-buffer
3720 (dolist (buffer (buffer-list t
))
3722 (when (and (eq major-mode
'message-mode
)
3723 (null message-sent-message-via
))
3724 (push (buffer-name buffer
) buffers
))))
3725 (nreverse buffers
)))
3727 (defun message-cite-original-1 (strip-signature)
3728 "Cite an original message.
3729 If STRIP-SIGNATURE is non-nil, strips off the signature from the
3732 This function uses `mail-citation-hook' if that is non-nil."
3733 (if (and (boundp 'mail-citation-hook
)
3735 (run-hooks 'mail-citation-hook
)
3736 (let* ((start (point))
3740 (when message-indent-citation-function
3741 (if (listp message-indent-citation-function
)
3742 message-indent-citation-function
3743 (list message-indent-citation-function
))))
3744 ;; This function may be called by `gnus-summary-yank-message' and
3745 ;; may insert a different article from the original. So, we will
3746 ;; modify the value of `message-reply-headers' with that article.
3747 (message-reply-headers
3749 (narrow-to-region start end
)
3750 (message-narrow-to-head-1)
3751 (setq x-no-archive
(message-fetch-field "x-no-archive"))
3753 (or (message-fetch-field "subject") "none")
3754 (or (message-fetch-field "from") "nobody")
3755 (message-fetch-field "date")
3756 (message-fetch-field "message-id" t
)
3757 (message-fetch-field "references")
3759 (mml-quote-region start end
)
3760 (when strip-signature
3764 (when (re-search-backward message-signature-separator start t
)
3765 ;; Also peel off any blank lines before the signature.
3767 (while (looking-at "^[ \t]*$")
3770 (delete-region (point) end
)
3771 (unless (search-backward "\n\n" start t
)
3772 ;; Insert a blank line if it is peeled off.
3775 (mapc 'funcall functions
)
3776 (when message-citation-line-function
3779 (funcall message-citation-line-function
))
3780 (when (and x-no-archive
3781 (not message-cite-articles-with-x-no-archive
)
3782 (string-match "yes" x-no-archive
))
3784 (delete-region (point) (mark t
))
3785 (insert "> [Quoted text removed due to X-No-Archive]\n")
3787 (forward-line -
1)))))
3789 (defun message-cite-original ()
3790 "Cite function in the standard Message manner."
3791 (message-cite-original-1 nil
))
3793 (defvar gnus-extract-address-components
)
3795 (autoload 'format-spec
"format-spec")
3797 (defun message-insert-formatted-citation-line (&optional from date
)
3798 "Function that inserts a formatted citation line.
3800 See `message-citation-line-format'."
3801 ;; The optional args are for testing/debugging. They will disappear later.
3803 ;; (with-temp-buffer
3804 ;; (message-insert-formatted-citation-line
3805 ;; "John Doe <john.doe@example.invalid>"
3808 (when (or message-reply-headers
(and from date
))
3810 (setq from
(mail-header-from message-reply-headers
)))
3811 (let* ((data (condition-case ()
3812 (funcall (if (boundp gnus-extract-address-components
)
3813 gnus-extract-address-components
3814 'mail-extract-address-components
)
3820 (net (car (cdr data
)))
3821 (name-or-net (or (car data
)
3822 (car (cdr data
)) from
))
3826 ;; We need Gnus functionality if the user wants date or time from
3827 ;; the original article:
3828 (when (string-match "%[^fnNFL]" message-citation-line-format
)
3829 (autoload 'gnus-date-get-time
"gnus-util")
3830 (gnus-date-get-time (mail-header-date message-reply-headers
)))))
3833 (when (stringp name
)
3834 ;; Guess first name and last name:
3835 (cond ((string-match
3836 "\\`\\(\\w\\|[-.]\\)+ \\(\\w\\|[-.]\\)+\\'" name
)
3837 (setq fname
(nth 0 (split-string name
"[ \t]+"))
3838 lname
(nth 1 (split-string name
"[ \t]+"))))
3840 "\\`\\(\\w\\|[-.]\\)+, \\(\\w\\|[-.]\\)+\\'" name
)
3841 (setq fname
(nth 1 (split-string name
"[ \t,]+"))
3842 lname
(nth 0 (split-string name
"[ \t,]+"))))
3844 "\\`\\(\\w\\|[-.]\\)+\\'" name
)
3847 ;; The following letters are not used in `format-time-string':
3848 (push ?E lst
) (push "<E>" lst
)
3849 (push ?F lst
) (push fname lst
)
3850 ;; We might want to use "" instead of "<X>" later.
3851 (push ?J lst
) (push "<J>" lst
)
3852 (push ?K lst
) (push "<K>" lst
)
3853 (push ?L lst
) (push lname lst
)
3854 (push ?N lst
) (push name-or-net lst
)
3855 (push ?O lst
) (push "<O>" lst
)
3856 (push ?P lst
) (push "<P>" lst
)
3857 (push ?Q lst
) (push "<Q>" lst
)
3858 (push ?f lst
) (push from lst
)
3859 (push ?i lst
) (push "<i>" lst
)
3860 (push ?n lst
) (push net lst
)
3861 (push ?o lst
) (push "<o>" lst
)
3862 (push ?q lst
) (push "<q>" lst
)
3863 (push ?t lst
) (push "<t>" lst
)
3864 (push ?v lst
) (push "<v>" lst
)
3865 ;; Delegate the rest to `format-time-string':
3867 (when (and (not (memq i lst
))
3872 (push (condition-case nil
3873 (format-time-string (format "%%%c" i
) replydate
)
3874 (error (format ">%c<" i
)))
3878 (spec (apply 'format-spec-make flist
)))
3879 (insert (format-spec message-citation-line-format spec
)))
3882 (defun message-cite-original-without-signature ()
3883 "Cite function in the standard Message manner.
3884 This function strips off the signature from the original message."
3885 (message-cite-original-1 t
))
3887 (defun message-insert-citation-line ()
3888 "Insert a simple citation line."
3889 (when message-reply-headers
3890 (insert (mail-header-from message-reply-headers
) " writes:")
3894 (defun message-position-on-field (header &rest afters
)
3895 (let ((case-fold-search t
))
3898 (goto-char (point-min))
3901 (concat "^" (regexp-quote mail-header-separator
) "$"))
3902 (match-beginning 0)))
3903 (goto-char (point-min))
3904 (if (re-search-forward (concat "^" (regexp-quote header
) ":") nil t
)
3906 (re-search-forward "^[^ \t]" nil
'move
)
3908 (skip-chars-backward "\n")
3911 (not (re-search-forward
3912 (concat "^" (regexp-quote (car afters
)) ":")
3916 (re-search-forward "^[^ \t]" nil
'move
)
3917 (beginning-of-line))
3918 (insert header
": \n")
3922 (defun message-remove-signature ()
3923 "Remove the signature from the text between point and mark.
3924 The text will also be indented the normal way."
3926 (let ((start (point))
3928 (if (not (re-search-forward message-signature-separator
(mark t
) t
))
3929 ;; No signature here, so we just indent the cited text.
3930 (message-indent-citation)
3931 ;; Find the last non-empty line.
3933 (while (looking-at "[ \t]*$")
3936 (setq mark
(set-marker (make-marker) (point)))
3938 (message-indent-citation)
3939 ;; Enable undoing the deletion.
3941 (delete-region mark
(mark t
))
3942 (set-marker mark nil
)))))
3947 ;;; Sending messages
3950 (defun message-send-and-exit (&optional arg
)
3951 "Send message like `message-send', then, if no errors, exit from mail buffer."
3953 (let ((buf (current-buffer))
3954 (actions message-exit-actions
))
3955 (when (and (message-send arg
)
3958 (if message-kill-buffer-on-exit
3960 (message-do-actions actions
)
3963 (defun message-dont-send ()
3964 "Don't send the message you have been editing.
3965 Instead, just auto-save the buffer and then bury it."
3967 (set-buffer-modified-p t
)
3969 (let ((actions message-postpone-actions
))
3970 (message-bury (current-buffer))
3971 (message-do-actions actions
)))
3973 (defun message-kill-buffer ()
3974 "Kill the current buffer."
3976 (when (or (not (buffer-modified-p))
3977 (not message-kill-buffer-query
)
3978 (yes-or-no-p "Message modified; kill anyway? "))
3979 (let ((actions message-kill-actions
)
3980 (draft-article message-draft-article
)
3981 (auto-save-file-name buffer-auto-save-file-name
)
3982 (file-name buffer-file-name
)
3983 (modified (buffer-modified-p)))
3984 (setq buffer-file-name nil
)
3985 (kill-buffer (current-buffer))
3986 (when (and (or (and auto-save-file-name
3987 (file-exists-p auto-save-file-name
))
3989 (file-exists-p file-name
)))
3991 ;; If the message buffer has lived in a dedicated window,
3992 ;; `kill-buffer' has killed the frame. Thus the
3993 ;; `yes-or-no-p' may show up in a lowered frame. Make sure
3994 ;; that the user can see the question by raising the
3997 (yes-or-no-p (format "Remove the backup file%s? "
3998 (if modified
" too" "")))))
4000 (delete-file auto-save-file-name
))
4001 (let ((message-draft-article draft-article
))
4002 (message-disassociate-draft)))
4003 (message-do-actions actions
))))
4005 (defun message-bury (buffer)
4006 "Bury this mail BUFFER."
4007 (let ((newbuf (other-buffer buffer
)))
4008 (bury-buffer buffer
)
4009 (if message-return-action
4010 (apply (car message-return-action
) (cdr message-return-action
))
4011 (switch-to-buffer newbuf
))))
4013 (defun message-send (&optional arg
)
4014 "Send the message in the current buffer.
4015 If `message-interactive' is non-nil, wait for success indication or
4016 error messages, and inform user.
4017 Otherwise any failure is reported in a message back to the user from
4019 The usage of ARG is defined by the instance that called Message.
4020 It should typically alter the sending method in some way or other."
4022 ;; Make it possible to undo the coming changes.
4024 (let ((inhibit-read-only t
))
4025 (put-text-property (point-min) (point-max) 'read-only nil
))
4026 (message-fix-before-sending)
4027 (run-hooks 'message-send-hook
)
4028 (when message-confirm-send
4029 (or (y-or-n-p "Send message? ")
4031 (message message-sending-message
)
4032 (let ((alist message-send-method-alist
)
4034 elem sent dont-barf-on-no-method
4035 (message-options message-options
))
4036 (message-options-set-recipient)
4038 (setq elem
(pop alist
)))
4039 (when (funcall (cadr elem
))
4040 (when (and (or (not (memq (car elem
)
4041 message-sent-message-via
))
4042 (message-fetch-field "supersedes")
4043 (if (or (message-gnksa-enable-p 'multiple-copies
)
4044 (not (eq (car elem
) 'news
)))
4047 "Already sent message via %s; resend? "
4049 (error "Denied posting -- multiple copies")))
4050 (setq success
(funcall (caddr elem
) arg
)))
4054 (let ((fcc (message-fetch-field "Fcc"))
4055 (gcc (message-fetch-field "Gcc")))
4057 (or (eq message-allow-no-recipients
'always
)
4058 (and (not (eq message-allow-no-recipients
'never
))
4059 (setq dont-barf-on-no-method
4061 (format "No receiver, perform %s anyway? "
4062 (cond ((and fcc gcc
) "Fcc and Gcc")
4065 (error "No methods specified to send by"))
4066 (when (or dont-barf-on-no-method
4070 (run-hooks 'message-sent-hook
))
4071 (message "Sending...done")
4072 ;; Do ecomplete address snarfing.
4073 (when (and (message-mail-alias-type-p 'ecomplete
)
4074 (not message-inhibit-ecomplete
))
4075 (message-put-addresses-in-ecomplete))
4076 ;; Mark the buffer as unmodified and delete auto-save.
4077 (set-buffer-modified-p nil
)
4078 (delete-auto-save-file-if-necessary t
)
4079 (message-disassociate-draft)
4080 ;; Delete other mail buffers and stuff.
4081 (message-do-send-housekeeping)
4082 (message-do-actions message-send-actions
)
4086 (defun message-send-via-mail (arg)
4087 "Send the current message via mail."
4088 (message-send-mail arg
))
4090 (defun message-send-via-news (arg)
4091 "Send the current message via news."
4092 (funcall message-send-news-function arg
))
4094 (defmacro message-check
(type &rest forms
)
4095 "Eval FORMS if TYPE is to be checked."
4096 `(or (message-check-element ,type
)
4100 (put 'message-check
'lisp-indent-function
1)
4101 (put 'message-check
'edebug-form-spec
'(form body
))
4103 (defun message-text-with-property (prop &optional start end reverse
)
4104 "Return a list of start and end positions where the text has PROP.
4105 START and END bound the search, they default to `point-min' and
4106 `point-max' respectively. If REVERSE is non-nil, find text which does
4109 (setq start
(point-min)))
4111 (setq end
(point-max)))
4115 (setq start
(text-property-any start end prop nil
)))
4116 (setq next
(next-single-property-change start prop nil end
))
4117 (push (cons start
(or next end
)) regions
)
4120 (or (get-text-property start prop
)
4121 (and (setq start
(next-single-property-change
4122 start prop nil end
))
4123 (get-text-property start prop
))))
4124 (setq next
(text-property-any start end prop nil
))
4125 (push (cons start
(or next end
)) regions
)
4127 (nreverse regions
)))
4129 (defcustom message-bogus-addresses
4130 '("noreply" "nospam" "invalid" "@@" "[^[:ascii:]].*@" "[ \t]")
4131 "List of regexps of potentially bogus mail addresses.
4132 See `message-check-recipients' how to setup checking.
4134 This list should make it possible to catch typos or warn about
4135 spam-trap addresses. It doesn't aim to verify strict RFC
4137 :version
"23.1" ;; No Gnus
4138 :group
'message-headers
4140 (const :tag
"None" nil
)
4146 (const :tag
"duplicate @" "@@")
4147 (const :tag
"non-ascii local part" "[^[:ascii:]].*@")
4148 ;; Already caught by `message-valid-fqdn-regexp'
4149 ;; (const :tag "`_' in domain part" "@.*_")
4150 (const :tag
"whitespace" "[ \t]"))
4155 (defun message-fix-before-sending ()
4156 "Do various things to make the message nice before sending it."
4157 ;; Make sure there's a newline at the end of the message.
4158 (goto-char (point-max))
4161 ;; Make the hidden headers visible.
4163 ;; Sort headers before sending the message.
4164 (message-sort-headers)
4165 ;; Make invisible text visible.
4166 ;; It doesn't seem as if this is useful, since the invisible property
4167 ;; is clobbered by an after-change hook anyhow.
4168 (message-check 'invisible-text
4169 (let ((regions (message-text-with-property 'invisible
))
4173 (setq from
(caar regions
)
4175 regions
(cdr regions
))
4176 (put-text-property from to
'invisible nil
)
4177 (message-overlay-put (message-make-overlay from to
)
4179 (unless (yes-or-no-p
4180 "Invisible text found and made visible; continue sending? ")
4181 (error "Invisible text found and made visible")))))
4182 (message-check 'illegible-text
4183 (let (char found choice
)
4186 (skip-chars-forward mm-7bit-chars
)
4187 (when (get-text-property (point) 'no-illegible-text
)
4188 ;; There is a signed or encrypted raw message part
4189 ;; that is considered to be safe.
4190 (goto-char (or (next-single-property-change
4191 (point) 'no-illegible-text
)
4193 (setq char
(char-after)))
4194 (when (or (< (mm-char-int char
) 128)
4195 (and (mm-multibyte-p)
4196 (memq (char-charset char
)
4197 '(eight-bit-control eight-bit-graphic
4198 ;; Emacs 23, Bug#1770:
4201 (not (get-text-property
4202 (point) 'untranslated-utf-8
))))
4203 (message-overlay-put (message-make-overlay (point) (1+ (point)))
4209 (gnus-multiple-choice
4210 "Non-printable characters found. Continue sending?"
4211 `((?d
"Remove non-printable characters and send")
4213 "Replace non-printable characters with \"%s\" and send"
4214 message-replacement-char
))
4215 (?s
"Send as is without removing anything")
4216 (?e
"Continue editing"))))
4218 (error "Non-printable characters"))
4220 (skip-chars-forward mm-7bit-chars
)
4222 (when (let ((char (char-after)))
4223 (or (< (mm-char-int char
) 128)
4224 (and (mm-multibyte-p)
4225 ;; FIXME: Wrong for Emacs 23 (unicode) and for
4226 ;; things like undecodable utf-8 (in Emacs 21?).
4227 ;; Should at least use find-coding-systems-region.
4229 (memq (char-charset char
)
4230 '(eight-bit-control eight-bit-graphic
4231 ;; Emacs 23, Bug#1770:
4234 (not (get-text-property
4235 (point) 'untranslated-utf-8
)))))
4237 (message-kill-all-overlays)
4239 (when (eq choice ?r
)
4240 (insert message-replacement-char
))))
4242 (skip-chars-forward mm-7bit-chars
)))))
4243 (message-check 'bogus-recipient
4244 ;; Warn before sending a mail to an invalid address.
4245 (message-check-recipients)))
4247 (defun message-bogus-recipient-p (recipients)
4248 "Check if a mail address in RECIPIENTS looks bogus.
4250 RECIPIENTS is a mail header. Return a list of potentially bogus
4251 addresses. If none is found, return nil.
4253 An address might be bogus if the domain part is not fully
4254 qualified, see `message-valid-fqdn-regexp', or if there's a
4255 matching entry in `message-bogus-addresses'."
4256 ;; FIXME: How about "foo@subdomain", when the MTA adds ".domain.tld"?
4258 (mapc (lambda (address)
4259 (setq address
(or (cadr address
) ""))
4261 (or (string= "" address
)
4264 (not (string-match "@" address
))
4267 message-valid-fqdn-regexp
"\\)\\'") address
)))
4268 (and message-bogus-addresses
4270 (if (listp message-bogus-addresses
)
4271 (mapconcat 'identity
4272 message-bogus-addresses
4274 message-bogus-addresses
)))
4275 (string-match re address
))))
4276 (push address found
)))
4278 (mail-extract-address-components recipients t
))
4281 (defun message-check-recipients ()
4282 "Warn before composing or sending a mail to an invalid address.
4284 This function could be useful in `message-setup-hook'."
4287 (message-narrow-to-headers)
4288 (dolist (hdr '("To" "Cc" "Bcc"))
4289 (let ((addr (message-fetch-field hdr
)))
4290 (when (stringp addr
)
4291 (dolist (bog (message-bogus-recipient-p addr
))
4295 "Address `%s'%s might be bogus. Continue? "
4297 ;; If the encoded version of the email address
4298 ;; is different from the unencoded version,
4299 ;; then we likely have invisible characters or
4300 ;; the like. Display the encoded version,
4302 (let ((encoded (rfc2047-encode-string bog
)))
4303 (if (string= encoded bog
)
4305 (format " (%s)" encoded
))))))
4306 (error "Bogus address"))))))))
4308 (custom-add-option 'message-setup-hook
'message-check-recipients
)
4310 (defun message-add-action (action &rest types
)
4311 "Add ACTION to be performed when doing an exit of type TYPES."
4313 (add-to-list (intern (format "message-%s-actions" (pop types
)))
4316 (defun message-delete-action (action &rest types
)
4317 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
4320 (set (setq var
(intern (format "message-%s-actions" (pop types
))))
4321 (delq action
(symbol-value var
))))))
4323 (defun message-do-actions (actions)
4324 "Perform all actions in ACTIONS."
4325 ;; Now perform actions on successful sending.
4326 (dolist (action actions
)
4329 ;; A simple function.
4332 ;; Something to be evaled.
4336 (defun message-send-mail-partially ()
4337 "Send mail as message/partial."
4338 ;; replace the header delimiter with a blank line
4339 (goto-char (point-min))
4341 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4342 (replace-match "\n")
4343 (run-hooks 'message-send-mail-hook
)
4344 (let ((p (goto-char (point-min)))
4345 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
4346 (curbuf (current-buffer))
4347 (id (message-make-message-id)) (n 1)
4348 required-mail-headers
;FIXME: Unused, right? --Stef
4351 (if (< (point-max) (+ p message-send-mail-partially-limit
))
4352 (goto-char (point-max))
4353 (goto-char (+ p message-send-mail-partially-limit
))
4355 (if (<= (point) p
) (forward-line 1))) ;; In case of bad message.
4358 (setq total
(length plist
))
4359 (push (point-max) plist
)
4360 (setq plist
(nreverse plist
))
4363 (setq p
(pop plist
))
4366 (copy-to-buffer tembuf p
(car plist
))
4368 (goto-char (point-min))
4371 (goto-char (point-min))
4372 (narrow-to-region (point) (point))
4375 (setq header
(buffer-substring (point-min) (point)))
4376 (goto-char (point-min))
4377 (narrow-to-region (point) (point))
4379 (message-remove-header "Mime-Version")
4380 (message-remove-header "Content-Type")
4381 (message-remove-header "Content-Transfer-Encoding")
4382 (message-remove-header "Message-ID")
4383 (message-remove-header "Lines")
4384 (goto-char (point-max))
4385 (insert "Mime-Version: 1.0\n")
4386 (setq header
(buffer-string)))
4387 (goto-char (point-max))
4388 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
4391 (let ((mail-header-separator ""))
4392 (when (memq 'Message-ID message-required-mail-headers
)
4393 (insert "Message-ID: " (message-make-message-id) "\n"))
4394 (when (memq 'Lines message-required-mail-headers
)
4395 (insert "Lines: " (message-make-lines) "\n"))
4396 (message-goto-subject)
4398 (insert (format " (%d/%d)" n total
))
4400 (funcall (or message-send-mail-real-function
4401 message-send-mail-function
)))
4403 (setq p
(pop plist
))
4405 (kill-buffer tembuf
))))
4407 (declare-function hashcash-wait-async
"hashcash" (&optional buffer
))
4409 (defun message-send-mail (&optional arg
)
4410 (require 'mail-utils
)
4411 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
4412 (case-fold-search nil
)
4413 (news (message-news-p))
4414 (mailbuf (current-buffer))
4415 (message-this-is-mail t
)
4416 ;; gnus-setup-posting-charset is autoloaded in mml.el (FIXME
4417 ;; maybe it should not be), which this file requires. Hence
4418 ;; the fboundp test is always true. Loading it from gnus-msg
4419 ;; loads many Gnus files (Bug#5642). If
4420 ;; gnus-group-posting-charset-alist hasn't been customized,
4421 ;; this is just going to return nil anyway. FIXME it would
4422 ;; be good to improve this further, because even if g-g-p-c-a
4423 ;; has been customized, that is likely to just be for news.
4424 ;; Eg either move the definition from gnus-msg, or separate out
4425 ;; the mail and news parts.
4426 (message-posting-charset
4427 (if (and (fboundp 'gnus-setup-posting-charset
)
4428 (boundp 'gnus-group-posting-charset-alist
))
4429 (gnus-setup-posting-charset nil
)
4430 message-posting-charset
))
4431 (headers message-required-mail-headers
))
4432 (when (and message-generate-hashcash
4433 (not (eq message-generate-hashcash
'opportunistic
)))
4434 (message "Generating hashcash...")
4436 ;; Wait for calculations already started to finish...
4437 (hashcash-wait-async)
4438 ;; ...and do calculations not already done. mail-add-payment
4439 ;; will leave existing X-Hashcash headers alone.
4441 (message "Generating hashcash...done"))
4443 (message-narrow-to-headers)
4444 ;; Generate the Mail-Followup-To header if the header is not there...
4445 (if (and (message-subscribed-p)
4446 (not (mail-fetch-field "mail-followup-to")))
4449 (cons "Mail-Followup-To" (message-make-mail-followup-to))
4450 message-required-mail-headers
))
4451 ;; otherwise, delete the MFT header if the field is empty
4452 (when (equal "" (mail-fetch-field "mail-followup-to"))
4453 (message-remove-header "^Mail-Followup-To:")))
4454 ;; Insert some headers.
4455 (let ((message-deletable-headers
4456 (if news nil message-deletable-headers
)))
4457 (message-generate-headers headers
))
4458 ;; Check continuation headers.
4459 (message-check 'continuation-headers
4460 (goto-char (point-min))
4461 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t
)
4462 (goto-char (match-beginning 0))
4463 (if (y-or-n-p "Fix continuation lines? ")
4466 (unless (y-or-n-p "Send anyway? ")
4467 (error "Failed to send the message")))))
4468 ;; Let the user do all of the above.
4469 (run-hooks 'message-header-hook
))
4471 (with-current-buffer tembuf
4473 ;; Avoid copying text props (except hard newlines).
4474 (insert (with-current-buffer mailbuf
4475 (mml-buffer-substring-no-properties-except-hard-newlines
4476 (point-min) (point-max))))
4477 ;; Remove some headers.
4478 (message-encode-message-body)
4480 (message-narrow-to-headers)
4481 ;; We (re)generate the Lines header.
4482 (when (memq 'Lines message-required-mail-headers
)
4483 (message-generate-headers '(Lines)))
4484 ;; Remove some headers.
4485 (message-remove-header message-ignored-mail-headers t
)
4486 (let ((mail-parse-charset message-default-charset
))
4487 (mail-encode-encoded-word-buffer)))
4488 (goto-char (point-max))
4489 ;; require one newline at the end.
4490 (or (= (preceding-char) ?
\n)
4492 (message-cleanup-headers)
4493 ;; FIXME: we're inserting the courtesy copy after encoding.
4494 ;; This is wrong if the courtesy copy string contains
4495 ;; non-ASCII characters. -- jh
4498 (message-narrow-to-headers)
4500 (not (message-fetch-field "List-Post"))
4501 (not (message-fetch-field "List-ID"))
4502 (or (message-fetch-field "cc")
4503 (message-fetch-field "bcc")
4504 (message-fetch-field "to"))
4505 (let ((content-type (message-fetch-field
4510 (string= "text/plain"
4512 (mail-header-parse-content-type
4516 (message-fetch-field
4517 "content-transfer-encoding")))))))
4518 (message-insert-courtesy-copy
4519 (with-current-buffer mailbuf
4520 message-courtesy-message
)))
4521 ;; Let's make sure we encoded all the body.
4522 (assert (save-excursion
4523 (goto-char (point-min))
4524 (not (re-search-forward "[^\000-\377]" nil t
))))
4525 (mm-disable-multibyte)
4526 (if (or (not message-send-mail-partially-limit
)
4527 (< (buffer-size) message-send-mail-partially-limit
)
4528 (not (message-y-or-n-p
4529 "The message size is too large, split? "
4533 (/ (buffer-size) 1000) "KB, is too large.
4535 Some mail gateways (MTA's) bounce large messages. To avoid the
4536 problem, answer `y', and the message will be split into several
4537 smaller pieces, the size of each is about "
4538 (/ message-send-mail-partially-limit
1000)
4542 However, some mail readers (MUA's) can't read split messages, i.e.,
4543 mails in message/partially format. Answer `n', and the message will be
4546 The size limit is controlled by `message-send-mail-partially-limit'.
4547 If you always want Gnus to send messages in one piece, set
4548 `message-send-mail-partially-limit' to nil.
4551 (message "Sending via mail...")
4552 (funcall (or message-send-mail-real-function
4553 message-send-mail-function
)))
4554 (message-send-mail-partially)))
4555 (kill-buffer tembuf
))
4556 (set-buffer mailbuf
)
4557 (push 'mail message-sent-message-via
)))
4559 (defun message-send-mail-with-sendmail ()
4560 "Send off the prepared buffer with sendmail."
4562 (let ((errbuf (if message-interactive
4563 (message-generate-new-buffer-clone-locals
4566 resend-to-addresses delimline
)
4569 (let ((case-fold-search t
))
4571 (message-narrow-to-headers)
4572 (setq resend-to-addresses
(message-fetch-field "resent-to")))
4573 ;; Change header-delimiter to be what sendmail expects.
4574 (goto-char (point-min))
4576 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4577 (replace-match "\n")
4579 (setq delimline
(point-marker))
4580 (run-hooks 'message-send-mail-hook
)
4581 ;; Insert an extra newline if we need it to work around
4582 ;; Sun's bug that swallows newlines.
4583 (goto-char (1+ delimline
))
4584 (when (eval message-mailer-swallows-blank-line
)
4586 (when message-interactive
4587 (with-current-buffer errbuf
4589 (let* ((default-directory "/")
4590 (coding-system-for-write message-send-coding-system
)
4592 'call-process-region
4594 (list (point-min) (point-max)
4595 (cond ((boundp 'sendmail-program
)
4597 ((file-exists-p "/usr/sbin/sendmail")
4598 "/usr/sbin/sendmail")
4599 ((file-exists-p "/usr/lib/sendmail")
4600 "/usr/lib/sendmail")
4601 ((file-exists-p "/usr/ucblib/sendmail")
4602 "/usr/ucblib/sendmail")
4604 nil errbuf nil
"-oi")
4605 message-sendmail-extra-arguments
4606 ;; Always specify who from,
4607 ;; since some systems have broken sendmails.
4608 ;; But some systems are more broken with -f, so
4609 ;; we'll let users override this.
4610 (and (null message-sendmail-f-is-evil
)
4611 (list "-f" (message-sendmail-envelope-from)))
4612 ;; These mean "report errors by mail"
4613 ;; and "deliver in background".
4614 (if (null message-interactive
) '("-oem" "-odb"))
4615 ;; Get the addresses from the message
4616 ;; unless this is a resend.
4617 ;; We must not do that for a resend
4618 ;; because we would find the original addresses.
4619 ;; For a resend, include the specific addresses.
4620 (if resend-to-addresses
4621 (list resend-to-addresses
)
4623 (unless (or (null cpr
) (and (numberp cpr
) (zerop cpr
)))
4624 (if errbuf
(pop-to-buffer errbuf
))
4625 (error "Sending...failed with exit value %d" cpr
)))
4626 (when message-interactive
4627 (with-current-buffer errbuf
4628 (goto-char (point-min))
4629 (while (re-search-forward "\n+ *" nil t
)
4630 (replace-match "; "))
4631 (if (not (zerop (buffer-size)))
4632 (error "Sending...failed to %s"
4633 (buffer-string))))))
4634 (when (bufferp errbuf
)
4635 (kill-buffer errbuf
)))))
4637 (defun message-send-mail-with-qmail ()
4638 "Pass the prepared message buffer to qmail-inject.
4639 Refer to the documentation for the variable `message-send-mail-function'
4640 to find out how to use this."
4641 ;; replace the header delimiter with a blank line
4642 (goto-char (point-min))
4644 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4645 (replace-match "\n")
4646 (run-hooks 'message-send-mail-hook
)
4649 (let ((coding-system-for-write message-send-coding-system
))
4651 'call-process-region
(point-min) (point-max)
4652 message-qmail-inject-program nil nil nil
4653 ;; qmail-inject's default behavior is to look for addresses on the
4654 ;; command line; if there're none, it scans the headers.
4655 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4657 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4658 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4659 ;; message from stdin.
4661 ;; qmail also has the advantage of not having been raped by
4662 ;; various vendors, so we don't have to allow for that, either --
4663 ;; compare this with message-send-mail-with-sendmail and weep
4664 ;; for sendmail's lost innocence.
4666 ;; all this is way cool coz it lets us keep the arguments entirely
4667 ;; free for -inject-arguments -- a big win for the user and for us
4668 ;; since we don't have to play that double-guessing game and the user
4669 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4670 (if (functionp message-qmail-inject-args
)
4671 (funcall message-qmail-inject-args
)
4672 message-qmail-inject-args
)))
4673 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4674 ;; we have to look at the retval instead
4676 (100 (error "qmail-inject reported permanent failure"))
4677 (111 (error "qmail-inject reported transient failure"))
4678 ;; should never happen
4679 (t (error "qmail-inject reported unknown failure"))))
4681 (defvar mh-previous-window-config
)
4683 (defun message-send-mail-with-mh ()
4684 "Send the prepared message buffer with mh."
4685 (let ((mh-previous-window-config nil
)
4686 (name (mh-new-draft-name)))
4687 (setq buffer-file-name name
)
4688 ;; MH wants to generate these headers itself.
4689 (when message-mh-deletable-headers
4690 (let ((headers message-mh-deletable-headers
))
4692 (goto-char (point-min))
4693 (and (re-search-forward
4694 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
4695 (message-delete-line))
4697 (run-hooks 'message-send-mail-hook
)
4698 ;; Pass it on to mh.
4701 (defun message-smtpmail-send-it ()
4702 "Send the prepared message buffer with `smtpmail-send-it'.
4703 The only difference from `smtpmail-send-it' is that this command
4704 evaluates `message-send-mail-hook' just before sending a message.
4705 It is useful if your ISP requires the POP-before-SMTP
4706 authentication. See the Gnus manual for details."
4707 (run-hooks 'message-send-mail-hook
)
4710 (defun message-send-mail-with-mailclient ()
4711 "Send the prepared message buffer with `mailclient-send-it'.
4712 The only difference from `mailclient-send-it' is that this
4713 command evaluates `message-send-mail-hook' just before sending a message."
4714 (run-hooks 'message-send-mail-hook
)
4715 (mailclient-send-it))
4717 (defun message-canlock-generate ()
4718 "Return a string that is non-trivial to guess.
4719 Do not use this for anything important, it is cryptographically weak."
4721 (let (sha1-maximum-internal-length)
4722 (sha1 (concat (message-unique-id)
4723 (format "%x%x%x" (random) (random t
) (random))
4724 (prin1-to-string (recent-keys))
4725 (prin1-to-string (garbage-collect))))))
4727 (defvar canlock-password
)
4728 (defvar canlock-password-for-verify
)
4730 (defun message-canlock-password ()
4731 "The password used by message for cancel locks.
4732 This is the value of `canlock-password', if that option is non-nil.
4733 Otherwise, generate and save a value for `canlock-password' first."
4735 (unless canlock-password
4736 (customize-save-variable 'canlock-password
(message-canlock-generate))
4737 (setq canlock-password-for-verify canlock-password
))
4740 (defun message-insert-canlock ()
4741 (when message-insert-canlock
4742 (message-canlock-password)
4743 (canlock-insert-header)))
4745 (autoload 'nnheader-get-report
"nnheader")
4747 (declare-function gnus-setup-posting-charset
"gnus-msg" (group))
4749 (defun message-send-news (&optional arg
)
4751 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4752 (case-fold-search nil
)
4753 (method (if (functionp message-post-method
)
4754 (funcall message-post-method arg
)
4755 message-post-method
))
4756 (newsgroups-field (save-restriction
4757 (message-narrow-to-headers-or-head)
4758 (message-fetch-field "Newsgroups")))
4759 (followup-field (save-restriction
4760 (message-narrow-to-headers-or-head)
4761 (message-fetch-field "Followup-To")))
4762 ;; BUG: We really need to get the charset for each name in the
4763 ;; Newsgroups and Followup-To lines to allow crossposting
4764 ;; between group namess with incompatible character sets.
4765 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4766 (group-field-charset
4767 (gnus-group-name-charset method newsgroups-field
))
4768 (followup-field-charset
4769 (gnus-group-name-charset method
(or followup-field
"")))
4770 (rfc2047-header-encoding-alist
4771 (append (when group-field-charset
4772 (list (cons "Newsgroups" group-field-charset
)))
4773 (when followup-field-charset
4774 (list (cons "Followup-To" followup-field-charset
)))
4775 rfc2047-header-encoding-alist
))
4776 (messbuf (current-buffer))
4777 (message-syntax-checks
4779 (listp message-syntax-checks
))
4780 (cons '(existing-newsgroups . disabled
)
4781 message-syntax-checks
)
4782 message-syntax-checks
))
4783 (message-this-is-news t
)
4784 (message-posting-charset
4785 (gnus-setup-posting-charset newsgroups-field
))
4787 (if (not (message-check-news-body-syntax))
4790 (message-narrow-to-headers)
4791 ;; Insert some headers.
4792 (message-generate-headers message-required-news-headers
)
4793 (message-insert-canlock)
4794 ;; Let the user do all of the above.
4795 (run-hooks 'message-header-hook
))
4796 ;; Note: This check will be disabled by the ".*" default value for
4797 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4798 (when (and group-field-charset
4799 (listp message-syntax-checks
))
4800 (setq message-syntax-checks
4801 (cons '(valid-newsgroups . disabled
)
4802 message-syntax-checks
)))
4803 (message-cleanup-headers)
4804 (if (not (let ((message-post-method method
))
4805 (message-check-news-syntax)))
4808 (with-current-buffer tembuf
4809 (buffer-disable-undo)
4811 ;; Avoid copying text props (except hard newlines).
4813 (with-current-buffer messbuf
4814 (mml-buffer-substring-no-properties-except-hard-newlines
4815 (point-min) (point-max))))
4816 (message-encode-message-body)
4817 ;; Remove some headers.
4819 (message-narrow-to-headers)
4820 ;; We (re)generate the Lines header.
4821 (when (memq 'Lines message-required-mail-headers
)
4822 (message-generate-headers '(Lines)))
4823 ;; Remove some headers.
4824 (message-remove-header message-ignored-news-headers t
)
4825 (let ((mail-parse-charset message-default-charset
))
4826 (mail-encode-encoded-word-buffer)))
4827 (goto-char (point-max))
4828 ;; require one newline at the end.
4829 (or (= (preceding-char) ?
\n)
4831 (let ((case-fold-search t
))
4832 ;; Remove the delimiter.
4833 (goto-char (point-min))
4835 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4836 (replace-match "\n")
4838 (run-hooks 'message-send-news-hook
)
4839 (gnus-open-server method
)
4840 (message "Sending news via %s..." (gnus-server-string method
))
4841 (setq result
(let ((mail-header-separator ""))
4842 (gnus-request-post method
))))
4843 (kill-buffer tembuf
))
4844 (set-buffer messbuf
)
4846 (push 'news message-sent-message-via
)
4847 (message "Couldn't send message via news: %s"
4848 (nnheader-get-report (car method
)))
4852 ;;; Header generation & syntax checking.
4855 (defun message-check-element (type)
4856 "Return non-nil if this TYPE is not to be checked."
4857 (if (eq message-syntax-checks
'dont-check-for-anything-just-trust-me
)
4859 (let ((able (assq type message-syntax-checks
)))
4861 (eq (cdr able
) 'disabled
)))))
4863 (defun message-check-news-syntax ()
4864 "Check the syntax of the message."
4868 ;; We narrow to the headers and check them first.
4871 (message-narrow-to-headers)
4872 (message-check-news-header-syntax))))))
4874 (defun message-check-news-header-syntax ()
4876 ;; Check Newsgroups header.
4877 (message-check 'newsgroups
4878 (let ((group (message-fetch-field "newsgroups")))
4881 (not (string-match "\\`[ \t]*\\'" group
)))
4884 "The newsgroups field is empty or missing. Posting is denied.")))))
4885 ;; Check the Subject header.
4886 (message-check 'subject
4887 (let* ((case-fold-search t
)
4888 (subject (message-fetch-field "subject")))
4891 (not (string-match "\\`[ \t]*\\'" subject
)))
4894 "The subject field is empty or missing. Posting is denied.")))))
4895 ;; Check for commands in Subject.
4896 (message-check 'subject-cmsg
4897 (if (string-match "^cmsg " (message-fetch-field "subject"))
4899 "The control code \"cmsg\" is in the subject. Really post? ")
4901 ;; Check long header lines.
4902 (message-check 'long-header-lines
4906 (while (and (not found
)
4907 (re-search-forward "^\\([^ \t:]+\\): " nil t
))
4908 (if (> (- (point) (match-beginning 0)) 998)
4910 length
(- (point) (match-beginning 0)))
4911 (setq header
(match-string-no-properties 1)))
4914 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
4917 ;; Check for multiple identical headers.
4918 (message-check 'multiple-headers
4920 (while (and (not found
)
4921 (re-search-forward "^[^ \t:]+: " nil t
))
4923 (or (re-search-forward
4928 (match-beginning 0) (- (match-end 0) 2))))
4933 (y-or-n-p (format "Multiple %s headers. Really post? " found
))
4935 ;; Check for Version and Sendsys.
4936 (message-check 'sendsys
4937 (if (re-search-forward "^Sendsys:\\|^Version:" nil t
)
4939 (format "The article contains a %s command. Really post? "
4940 (buffer-substring (match-beginning 0)
4941 (1- (match-end 0)))))
4943 ;; See whether we can shorten Followup-To.
4944 (message-check 'shorten-followup-to
4945 (let ((newsgroups (message-fetch-field "newsgroups"))
4946 (followup-to (message-fetch-field "followup-to"))
4948 (when (and newsgroups
4949 (string-match "," newsgroups
)
4954 (setq to
(completing-read
4955 "Followups to (default no Followup-To header): "
4958 (message-tokenize-header
4960 (goto-char (point-min))
4961 (insert "Followup-To: " to
"\n"))
4963 ;; Check "Shoot me".
4964 (message-check 'shoot
4965 (if (re-search-forward
4966 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t
)
4967 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
4969 ;; Check for Approved.
4970 (message-check 'approved
4971 (if (re-search-forward "^Approved:" nil t
)
4972 (y-or-n-p "The article contains an Approved header. Really post? ")
4974 ;; Check the Message-ID header.
4975 (message-check 'message-id
4976 (let* ((case-fold-search t
)
4977 (message-id (message-fetch-field "message-id" t
)))
4978 (or (not message-id
)
4979 ;; Is there an @ in the ID?
4980 (and (string-match "@" message-id
)
4981 ;; Is there a dot in the ID?
4982 (string-match "@[^.]*\\." message-id
)
4983 ;; Does the ID end with a dot?
4984 (not (string-match "\\.>" message-id
)))
4986 (format "The Message-ID looks strange: \"%s\". Really post? "
4988 ;; Check the Newsgroups & Followup-To headers.
4989 (message-check 'existing-newsgroups
4990 (let* ((case-fold-search t
)
4991 (newsgroups (message-fetch-field "newsgroups"))
4992 (followup-to (message-fetch-field "followup-to"))
4993 (groups (message-tokenize-header
4995 (concat newsgroups
"," followup-to
)
4997 (post-method (if (functionp message-post-method
)
4998 (funcall message-post-method
)
4999 message-post-method
))
5000 ;; KLUDGE to handle nnvirtual groups. Doing this right
5001 ;; would probably involve a new nnoo function.
5002 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
5003 (method (if (and (consp post-method
)
5004 (eq (car post-method
) 'nnvirtual
)
5005 gnus-message-group-art
)
5006 (let ((group (car (nnvirtual-find-group-art
5007 (car gnus-message-group-art
)
5008 (cdr gnus-message-group-art
)))))
5009 (gnus-find-method-for-group group
))
5013 (gnus-group-name-decode
5014 (gnus-group-real-name n
)
5015 (gnus-group-name-charset method n
)))
5016 (gnus-groups-from-server method
)))
5019 (when (and (not (equal (car groups
) "poster"))
5020 (not (member (car groups
) known-groups
))
5021 (not (member (car groups
) errors
)))
5022 (push (car groups
) errors
))
5025 ;; Gnus is not running.
5026 ((or (not (and (boundp 'gnus-active-hashtb
)
5027 gnus-active-hashtb
))
5028 (not (boundp 'gnus-read-active-file
)))
5030 ;; We don't have all the group names.
5031 ((and (or (not gnus-read-active-file
)
5032 (eq gnus-read-active-file
'some
))
5036 "Really use %s possibly unknown group%s: %s? "
5037 (if (= (length errors
) 1) "this" "these")
5038 (if (= (length errors
) 1) "" "s")
5039 (mapconcat 'identity errors
", "))))
5040 ;; There were no errors.
5043 ;; There are unknown groups.
5047 "Really post to %s unknown group%s: %s? "
5048 (if (= (length errors
) 1) "this" "these")
5049 (if (= (length errors
) 1) "" "s")
5050 (mapconcat 'identity errors
", ")))))))
5051 ;; Check continuation headers.
5052 (message-check 'continuation-headers
5053 (goto-char (point-min))
5054 (let ((do-posting t
))
5055 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t
)
5056 (goto-char (match-beginning 0))
5057 (if (y-or-n-p "Fix continuation lines? ")
5060 (unless (y-or-n-p "Send anyway? ")
5061 (setq do-posting nil
))))
5063 ;; Check the Newsgroups & Followup-To headers for syntax errors.
5064 (message-check 'valid-newsgroups
5065 (let ((case-fold-search t
)
5066 (headers '("Newsgroups" "Followup-To"))
5068 (while (and headers
(not error
))
5069 (when (setq header
(mail-fetch-field (car headers
)))
5073 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
5078 (not (string-match "\\.\\'\\|\\.\\." g
)))
5079 (message-tokenize-header header
","))))
5086 (format "The %s header looks odd: \"%s\". Really post? "
5087 (car headers
) header
)))))
5088 (message-check 'repeated-newsgroups
5089 (let ((case-fold-search t
)
5090 (headers '("Newsgroups" "Followup-To"))
5091 header error groups group
)
5094 (when (setq header
(mail-fetch-field (pop headers
)))
5095 (setq groups
(message-tokenize-header header
","))
5096 (while (setq group
(pop groups
))
5097 (when (member group groups
)
5103 (format "Group %s is repeated in headers. Really post? " error
)))))
5104 ;; Check the From header.
5105 (message-check 'from
5106 (let* ((case-fold-search t
)
5107 (from (message-fetch-field "from"))
5111 (message "There is no From line. Posting is denied.")
5113 ((or (not (string-match
5115 (setq ad
(nth 1 (mail-extract-address-components
5116 from
))))) ;larsi@ifi
5117 (string-match "\\.\\." ad
) ;larsi@ifi..uio
5118 (string-match "@\\." ad
) ;larsi@.ifi.uio
5119 (string-match "\\.$" ad
) ;larsi@ifi.uio.
5120 (not (string-match "^[^@]+@[^@]+$" ad
)) ;larsi.ifi.uio
5121 (string-match "(.*).*(.*)" from
)) ;(lars) (lars)
5123 "Denied posting -- the From looks strange: \"%s\"." from
)
5125 ((let ((addresses (rfc822-addresses from
)))
5126 ;; `rfc822-addresses' returns a string if parsing fails.
5127 (while (and (consp addresses
)
5128 (not (eq (string-to-char (car addresses
)) ?\
()))
5129 (setq addresses
(cdr addresses
)))
5132 "Denied posting -- bad From address: \"%s\"." from
)
5135 ;; Check the Reply-To header.
5136 (message-check 'reply-to
5137 (let* ((case-fold-search t
)
5138 (reply-to (message-fetch-field "reply-to"))
5143 ((string-match "," reply-to
)
5145 (format "Multiple Reply-To addresses: \"%s\". Really post? "
5147 ((or (not (string-match
5149 (setq ad
(nth 1 (mail-extract-address-components
5150 reply-to
))))) ;larsi@ifi
5151 (string-match "\\.\\." ad
) ;larsi@ifi..uio
5152 (string-match "@\\." ad
) ;larsi@.ifi.uio
5153 (string-match "\\.$" ad
) ;larsi@ifi.uio.
5154 (not (string-match "^[^@]+@[^@]+$" ad
)) ;larsi.ifi.uio
5155 (string-match "(.*).*(.*)" reply-to
)) ;(lars) (lars)
5158 "The Reply-To looks strange: \"%s\". Really post? "
5162 (defun message-check-news-body-syntax ()
5164 ;; Check for long lines.
5165 (message-check 'long-lines
5166 (goto-char (point-min))
5168 (concat "^" (regexp-quote mail-header-separator
) "$"))
5172 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
5175 (< (- (point) p
) 80)))
5176 (zerop (forward-line 1))))
5180 "You have lines longer than 79 characters. Really post? ")))
5181 ;; Check whether the article is empty.
5182 (message-check 'empty
5183 (goto-char (point-min))
5185 (concat "^" (regexp-quote mail-header-separator
) "$"))
5188 (goto-char (point-max))
5189 (re-search-backward message-signature-separator nil t
)
5191 (or (re-search-backward "[^ \n\t]" b t
)
5192 (if (message-gnksa-enable-p 'empty-article
)
5193 (y-or-n-p "Empty article. Really post? ")
5194 (message "Denied posting -- Empty article.")
5196 ;; Check for control characters.
5197 (message-check 'control-chars
5198 (if (re-search-forward
5199 (mm-string-to-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
5202 "The article contains control characters. Really post? ")
5204 ;; Check excessive size.
5205 (message-check 'size
5206 (if (> (buffer-size) 60000)
5208 (format "The article is %d octets long. Really post? "
5211 ;; Check whether any new text has been added.
5212 (message-check 'new-text
5214 (not message-checksum
)
5215 (not (eq (message-checksum) message-checksum
))
5216 (if (message-gnksa-enable-p 'quoted-text-only
)
5218 "It looks like no new text has been added. Really post? ")
5219 (message "Denied posting -- no new text has been added.")
5221 ;; Check the length of the signature.
5222 (message-check 'signature
5223 (let (sig-start sig-end
)
5224 (goto-char (point-max))
5225 (if (not (re-search-backward message-signature-separator nil t
))
5227 (setq sig-start
(1+ (point-at-eol)))
5229 (if (re-search-forward
5230 "<#/?\\(multipart\\|part\\|external\\|mml\\)" nil t
)
5231 (- (point-at-bol) 1)
5233 (if (>= (count-lines sig-start sig-end
) 5)
5234 (if (message-gnksa-enable-p 'signature
)
5236 (format "Signature is excessively long (%d lines). Really post? "
5237 (count-lines sig-start sig-end
)))
5238 (message "Denied posting -- Excessive signature.")
5241 ;; Ensure that text follows last quoted portion.
5242 (message-check 'quoting-style
5243 (goto-char (point-max))
5244 (let ((no-problem t
))
5245 (when (search-backward-regexp "^>[^\n]*\n" nil t
)
5246 (setq no-problem
(search-forward-regexp "^[ \t]*[^>\n]" nil t
)))
5249 (if (message-gnksa-enable-p 'quoted-text-only
)
5250 (y-or-n-p "Your text should follow quoted text. Really post? ")
5252 (goto-char (point-min))
5254 (concat "^" (regexp-quote mail-header-separator
) "$"))
5255 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t
)
5256 (y-or-n-p "Your text should follow quoted text. Really post? ")
5257 (message "Denied posting -- only quoted text.")
5260 (defun message-checksum ()
5261 "Return a \"checksum\" for the current buffer."
5264 (goto-char (point-min))
5266 (concat "^" (regexp-quote mail-header-separator
) "$"))
5268 (when (not (looking-at "[ \t\n]"))
5269 (setq sum
(logxor (ash sum
1) (if (natnump sum
) 0 1)
5274 (defun message-do-fcc ()
5275 "Process Fcc headers in the current buffer."
5276 (let ((case-fold-search t
)
5277 (buf (current-buffer))
5279 (mml-externalize-attachments message-fcc-externalize-attachments
))
5282 (message-narrow-to-headers)
5283 (setq file
(message-fetch-field "fcc" t
)))
5285 (set-buffer (get-buffer-create " *message temp*"))
5287 (insert-buffer-substring buf
)
5288 (message-encode-message-body)
5290 (message-narrow-to-headers)
5291 (while (setq file
(message-fetch-field "fcc" t
))
5293 (message-remove-header "fcc" nil t
))
5294 (let ((mail-parse-charset message-default-charset
)
5295 (rfc2047-header-encoding-alist
5296 (cons '("Newsgroups" . default
)
5297 rfc2047-header-encoding-alist
)))
5298 (mail-encode-encoded-word-buffer)))
5299 (goto-char (point-min))
5300 (when (re-search-forward
5301 (concat "^" (regexp-quote mail-header-separator
) "$")
5303 (replace-match "" t t
))
5304 ;; Process FCC operations.
5306 (setq file
(pop list
))
5307 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file
)
5308 ;; Pipe the article to the program in question.
5309 (call-process-region (point-min) (point-max) shell-file-name
5310 nil nil nil shell-command-switch
5311 (match-string 1 file
))
5312 ;; Save the article.
5313 (setq file
(expand-file-name file
))
5314 (unless (file-exists-p (file-name-directory file
))
5315 (make-directory (file-name-directory file
) t
))
5316 (if (and message-fcc-handler-function
5317 (not (eq message-fcc-handler-function
'rmail-output
)))
5318 (funcall message-fcc-handler-function file
)
5319 ;; FIXME this option, rmail-output (also used if
5320 ;; message-fcc-handler-function is nil) is not
5321 ;; documented anywhere AFAICS. It should work in Emacs
5322 ;; 23; I suspect it does not work in Emacs 22.
5323 ;; FIXME I don't see the need for the two different cases here.
5324 ;; mail-use-rfc822 makes no difference (in Emacs 23),and
5325 ;; the third argument just controls \"Wrote file\" message.
5326 (if (and (file-readable-p file
) (mail-file-babyl-p file
))
5327 (rmail-output file
1 nil t
)
5328 (let ((mail-use-rfc822 t
))
5329 (rmail-output file
1 t t
))))))
5330 (kill-buffer (current-buffer))))))
5332 (defun message-output (filename)
5333 "Append this article to Unix/babyl mail file FILENAME."
5334 (if (or (and (file-readable-p filename
)
5335 (mail-file-babyl-p filename
))
5336 ;; gnus-output-to-mail does the wrong thing with live, mbox
5337 ;; Rmail buffers in Emacs 23.
5338 ;; http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=597255
5339 (let ((buff (find-buffer-visiting filename
)))
5340 (and buff
(with-current-buffer buff
5341 (eq major-mode
'rmail-mode
)))))
5342 (gnus-output-to-rmail filename t
)
5343 (gnus-output-to-mail filename t
)))
5345 (defun message-cleanup-headers ()
5346 "Do various automatic cleanups of the headers."
5347 ;; Remove empty lines in the header.
5349 (message-narrow-to-headers)
5350 ;; Remove blank lines.
5351 (while (re-search-forward "^[ \t]*\n" nil t
)
5352 (replace-match "" t t
))
5354 ;; Correct Newsgroups and Followup-To headers: Change sequence of
5355 ;; spaces to comma and eliminate spaces around commas. Eliminate
5356 ;; embedded line breaks.
5357 (goto-char (point-min))
5358 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t
)
5362 (if (re-search-forward "^[^ \t]" nil t
)
5366 (goto-char (point-min))
5367 (while (re-search-forward "\n[ \t]+" nil t
)
5368 (replace-match " " t t
)) ;No line breaks (too confusing)
5369 (goto-char (point-min))
5370 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t
)
5371 (replace-match "," t t
))
5372 (goto-char (point-min))
5373 ;; Remove trailing commas.
5374 (when (re-search-forward ",+$" nil t
)
5375 (replace-match "" t t
))))))
5377 (defun message-make-date (&optional now
)
5378 "Make a valid data header.
5379 If NOW, use that time instead."
5380 (let ((system-time-locale "C"))
5381 (format-time-string "%a, %d %b %Y %T %z" now
)))
5383 (defun message-insert-expires (days)
5384 "Insert the Expires header. Expiry in DAYS days."
5385 (interactive "NExpire article in how many days? ")
5387 (message-position-on-field "Expires" "X-Draft-From")
5388 (insert (message-make-expires-date days
))))
5390 (defun message-make-expires-date (days)
5391 "Make date string for the Expires header. Expiry in DAYS days.
5393 In posting styles use `(\"Expires\" (make-expires-date 30))'."
5394 (let* ((cur (decode-time (current-time)))
5395 (nday (+ days
(nth 3 cur
))))
5396 (setf (nth 3 cur
) nday
)
5397 (message-make-date (apply 'encode-time cur
))))
5399 (defun message-make-message-id ()
5400 "Make a unique Message-ID."
5401 (concat "<" (message-unique-id)
5402 (let ((psubject (save-excursion (message-fetch-field "subject")))
5404 (save-excursion (message-fetch-field "supersedes"))))
5406 (and message-reply-headers
5407 (mail-header-references message-reply-headers
)
5408 (mail-header-subject message-reply-headers
)
5411 (message-strip-subject-re
5412 (mail-header-subject message-reply-headers
))
5413 (message-strip-subject-re psubject
))))
5415 (string-match "_-_@" psupersedes
)))
5417 "@" (message-make-fqdn) ">"))
5419 (defvar message-unique-id-char nil
)
5421 ;; If you ever change this function, make sure the new version
5422 ;; cannot generate IDs that the old version could.
5423 ;; You might for example insert a "." somewhere (not next to another dot
5424 ;; or string boundary), or modify the "fsf" string.
5425 (defun message-unique-id ()
5426 ;; Don't use microseconds from (current-time), they may be unsupported.
5427 ;; Instead we use this randomly inited counter.
5428 (setq message-unique-id-char
5429 (%
(1+ (or message-unique-id-char
(logand (random t
) (1- (lsh 1 20)))))
5430 ;; (current-time) returns 16-bit ints,
5431 ;; and 2^16*25 just fits into 4 digits i base 36.
5433 (let ((tm (current-time)))
5435 (if (or (eq system-type
'ms-dos
)
5436 ;; message-number-base36 doesn't handle bigints.
5437 (floatp (user-uid)))
5438 (let ((user (downcase (user-login-name))))
5439 (while (string-match "[^a-z0-9_]" user
)
5440 (aset user
(match-beginning 0) ?_
))
5442 (message-number-base36 (user-uid) -
1))
5443 (message-number-base36 (+ (car tm
)
5444 (lsh (% message-unique-id-char
25) 16)) 4)
5445 (message-number-base36 (+ (nth 1 tm
)
5446 (lsh (/ message-unique-id-char
25) 16)) 4)
5447 ;; Append a given name, because while the generated ID is unique
5448 ;; to this newsreader, other newsreaders might otherwise generate
5449 ;; the same ID via another algorithm.
5452 (defun message-number-base36 (num len
)
5457 (concat (message-number-base36 (/ num
36) (1- len
))
5458 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
5461 (defun message-make-organization ()
5462 "Make an Organization header."
5463 (let* ((organization
5464 (when message-user-organization
5465 (if (functionp message-user-organization
)
5466 (funcall message-user-organization
)
5467 message-user-organization
))))
5469 (mm-enable-multibyte)
5470 (cond ((stringp organization
)
5471 (insert organization
))
5472 ((and (eq t organization
)
5473 message-user-organization-file
5474 (file-exists-p message-user-organization-file
))
5475 (insert-file-contents message-user-organization-file
)))
5476 (goto-char (point-min))
5477 (while (re-search-forward "[\t\n]+" nil t
)
5478 (replace-match "" t t
))
5479 (unless (zerop (buffer-size))
5482 (defun message-make-lines ()
5483 "Count the number of lines and return numeric string."
5488 (int-to-string (count-lines (point) (point-max))))))
5490 (defun message-make-references ()
5491 "Return the References header for this message."
5492 (when message-reply-headers
5493 (let ((message-id (mail-header-id message-reply-headers
))
5494 (references (mail-header-references message-reply-headers
)))
5495 (if (or references message-id
)
5496 (concat (or references
"") (and references
" ")
5500 (defun message-make-in-reply-to ()
5501 "Return the In-Reply-To header for this message."
5502 (when message-reply-headers
5503 (let ((from (mail-header-from message-reply-headers
))
5504 (date (mail-header-date message-reply-headers
))
5505 (msg-id (mail-header-id message-reply-headers
)))
5507 (let ((name (mail-extract-address-components from
)))
5509 msg-id
(if msg-id
" (")
5511 (if (string-match "[^\000-\177]" (car name
))
5512 ;; Quote a string containing non-ASCII characters.
5513 ;; It will make the RFC2047 encoder cause an error
5514 ;; if there are special characters.
5515 (mm-with-multibyte-buffer
5517 (goto-char (point-min))
5518 (while (search-forward "\"" nil t
)
5521 (zerop (%
(skip-chars-backward "\\\\") 2))
5522 (goto-char (match-beginning 0)))
5525 ;; Those quotes will be removed by the RFC2047 encoder.
5526 (concat "\"" (buffer-string) "\""))
5530 (if (or (not date
) (string= date
""))
5531 "(unknown date)" date
)
5532 "\"" (if msg-id
")")))))))
5534 (defun message-make-distribution ()
5535 "Make a Distribution header."
5536 (let ((orig-distribution (message-fetch-reply-field "distribution")))
5537 (cond ((functionp message-distribution-function
)
5538 (funcall message-distribution-function
))
5539 (t orig-distribution
))))
5541 (defun message-make-expires ()
5542 "Return an Expires header based on `message-expires'."
5543 (let ((current (current-time))
5544 (future (* 1.0 message-expires
60 60 24)))
5545 ;; Add the future to current.
5546 (setcar current
(+ (car current
) (round (/ future
(expt 2 16)))))
5547 (setcar (cdr current
) (+ (nth 1 current
) (%
(round future
) (expt 2 16))))
5548 (message-make-date current
)))
5550 (defun message-make-path ()
5552 (let ((login-name (user-login-name)))
5553 (cond ((null message-user-path
)
5554 (concat (system-name) "!" login-name
))
5555 ((stringp message-user-path
)
5556 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
5557 (concat message-user-path
"!" login-name
))
5560 (defun message-make-from (&optional name address
)
5561 "Make a From header."
5562 (let* ((style message-from-style
)
5563 (login (or address
(message-make-address)))
5565 (and (boundp 'user-full-name
)
5568 (when (string= fullname
"&")
5569 (setq fullname
(user-login-name)))
5571 (mm-enable-multibyte)
5574 (equal fullname
""))
5576 ((or (eq style
'angles
)
5577 (and (not (eq style
'parens
))
5578 ;; Use angles if no quoting is needed, or if parens would
5579 ;; need quoting too.
5580 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname
))
5581 (let ((tmp (concat fullname nil
)))
5582 (while (string-match "([^()]*)" tmp
)
5583 (aset tmp
(match-beginning 0) ?-
)
5584 (aset tmp
(1- (match-end 0)) ?-
))
5585 (string-match "[\\()]" tmp
)))))
5587 (goto-char (point-min))
5588 ;; Look for a character that cannot appear unquoted
5589 ;; according to RFC 822.
5590 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil
1)
5591 ;; Quote fullname, escaping specials.
5592 (goto-char (point-min))
5594 (while (re-search-forward "[\"\\]" nil
1)
5595 (replace-match "\\\\\\&" t
))
5597 (insert " <" login
">"))
5598 (t ; 'parens or default
5600 (let ((fullname-start (point)))
5602 (goto-char fullname-start
)
5603 ;; RFC 822 says \ and nonmatching parentheses
5604 ;; must be escaped in comments.
5605 ;; Escape every instance of ()\ ...
5606 (while (re-search-forward "[()\\]" nil
1)
5607 (replace-match "\\\\\\&" t
))
5608 ;; ... then undo escaping of matching parentheses,
5609 ;; including matching nested parentheses.
5610 (goto-char fullname-start
)
5611 (while (re-search-forward
5612 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
5614 (replace-match "\\1(\\3)" t
)
5615 (goto-char fullname-start
)))
5619 (defun message-make-sender ()
5620 "Return the \"real\" user address.
5621 This function tries to ignore all user modifications, and
5622 give as trustworthy answer as possible."
5623 (concat (user-login-name) "@" (system-name)))
5625 (defun message-make-address ()
5626 "Make the address of the user."
5627 (or (message-user-mail-address)
5628 (concat (user-login-name) "@" (message-make-domain))))
5630 (defun message-user-mail-address ()
5631 "Return the pertinent part of `user-mail-address'."
5632 (when (and user-mail-address
5633 (string-match "@.*\\." user-mail-address
))
5634 (if (string-match " " user-mail-address
)
5635 (nth 1 (mail-extract-address-components user-mail-address
))
5636 user-mail-address
)))
5638 (defun message-sendmail-envelope-from ()
5639 "Return the envelope from."
5640 (cond ((eq message-sendmail-envelope-from
'header
)
5641 (nth 1 (mail-extract-address-components
5642 (message-fetch-field "from"))))
5643 ((stringp message-sendmail-envelope-from
)
5644 message-sendmail-envelope-from
)
5646 (message-make-address))))
5648 (defun message-make-fqdn ()
5649 "Return user's fully qualified domain name."
5650 (let* ((system-name (system-name))
5651 (user-mail (message-user-mail-address))
5654 (string-match "@\\(.*\\)\\'" user-mail
))
5655 (match-string 1 user-mail
)))
5656 (case-fold-search t
))
5658 ((and message-user-fqdn
5659 (stringp message-user-fqdn
)
5660 (string-match message-valid-fqdn-regexp message-user-fqdn
)
5661 (not (string-match message-bogus-system-names message-user-fqdn
)))
5662 ;; `message-user-fqdn' seems to be valid
5664 ((and (string-match message-valid-fqdn-regexp system-name
)
5665 (not (string-match message-bogus-system-names system-name
)))
5666 ;; `system-name' returned the right result.
5668 ;; Try `mail-host-address'.
5669 ((and (boundp 'mail-host-address
)
5670 (stringp mail-host-address
)
5671 (string-match message-valid-fqdn-regexp mail-host-address
)
5672 (not (string-match message-bogus-system-names mail-host-address
)))
5674 ;; We try `user-mail-address' as a backup.
5676 (stringp user-domain
)
5677 (string-match message-valid-fqdn-regexp user-domain
)
5678 (not (string-match message-bogus-system-names user-domain
)))
5680 ;; Default to this bogus thing.
5683 ".i-did-not-set--mail-host-address--so-tickle-me")))))
5685 (defun message-make-host-name ()
5686 "Return the name of the host."
5687 (let ((fqdn (message-make-fqdn)))
5688 (string-match "^[^.]+\\." fqdn
)
5689 (substring fqdn
0 (1- (match-end 0)))))
5691 (defun message-make-domain ()
5692 "Return the domain name."
5693 (or mail-host-address
5694 (message-make-fqdn)))
5696 (defun message-to-list-only ()
5697 "Send a message to the list only.
5698 Remove all addresses but the list address from To and Cc headers."
5700 (let ((listaddr (message-make-mail-followup-to t
)))
5703 (message-remove-header "to")
5704 (message-remove-header "cc")
5705 (message-position-on-field "To" "X-Draft-From")
5706 (insert listaddr
)))))
5708 (defun message-make-mail-followup-to (&optional only-show-subscribed
)
5709 "Return the Mail-Followup-To header.
5710 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5711 subscribed address (and not the additional To and Cc header contents)."
5712 (let* ((case-fold-search t
)
5713 (to (message-fetch-field "To"))
5714 (cc (message-fetch-field "cc"))
5715 (msg-recipients (concat to
(and to cc
", ") cc
))
5717 (mapcar 'mail-strip-quoted-names
5718 (message-tokenize-header msg-recipients
)))
5720 (if message-subscribed-address-file
5721 (let (begin end item re
)
5724 (insert-file-contents message-subscribed-address-file
)
5726 (setq begin
(point))
5729 (if (bolp) (setq end
(1- end
)))
5730 (setq item
(regexp-quote (buffer-substring begin end
)))
5731 (if re
(setq re
(concat re
"\\|" item
))
5732 (setq re
(concat "\\`\\(" item
))))
5733 (and re
(list (concat re
"\\)\\'"))))))))
5734 (mft-regexps (apply 'append message-subscribed-regexps
5735 (mapcar 'regexp-quote
5736 message-subscribed-addresses
)
5739 message-subscribed-address-functions
))))
5742 (loop for recipient in recipients
5743 when
(loop for regexp in mft-regexps
5744 when
(string-match regexp recipient
) return t
)
5747 (if only-show-subscribed
5749 msg-recipients
))))))
5751 (defun message-idna-to-ascii-rhs-1 (header)
5752 "Interactively potentially IDNA encode domain names in HEADER."
5753 (let ((field (message-fetch-field header
))
5757 (mm-delete-duplicates
5758 (mapcar (lambda (rhs) (or (cadr (split-string rhs
"@")) ""))
5764 (mail-extract-address-components field t
))))))
5765 ;; Note that `rhs' will be "" if the address does not have
5766 ;; the domain part, i.e., if it is a local user's address.
5767 (setq ace
(if (string-match "\\`[[:ascii:]]*\\'" rhs
)
5769 (downcase (idna-to-ascii rhs
))))
5770 (when (and (not (equal rhs ace
))
5771 (or (not (eq message-use-idna
'ask
))
5772 (y-or-n-p (format "Replace %s with %s in %s:? "
5774 (goto-char (point-min))
5775 (while (re-search-forward (concat "^" header
":") nil t
)
5776 (message-narrow-to-field)
5777 (while (search-forward (concat "@" rhs
) nil t
)
5778 (replace-match (concat "@" ace
) t t
))
5779 (goto-char (point-max))
5782 (defun message-idna-to-ascii-rhs ()
5783 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
5784 See `message-idna-encode'."
5786 (when message-use-idna
5789 ;; `message-narrow-to-head' that recognizes only the first empty
5790 ;; line as the message header separator used to be used here.
5791 ;; However, since there is the "--text follows this line--" line
5792 ;; normally, it failed in narrowing to the headers and potentially
5793 ;; caused the IDNA encoding on lines that look like headers in
5794 ;; the message body.
5795 (message-narrow-to-headers-or-head)
5796 (message-idna-to-ascii-rhs-1 "From")
5797 (message-idna-to-ascii-rhs-1 "To")
5798 (message-idna-to-ascii-rhs-1 "Reply-To")
5799 (message-idna-to-ascii-rhs-1 "Mail-Reply-To")
5800 (message-idna-to-ascii-rhs-1 "Mail-Followup-To")
5801 (message-idna-to-ascii-rhs-1 "Cc")))))
5805 (defvar Organization
)
5810 (defvar In-Reply-To
)
5813 (defvar Distribution
)
5818 (defun message-generate-headers (headers)
5819 "Prepare article HEADERS.
5820 Headers already prepared in the buffer are not modified."
5821 (setq headers
(append headers message-required-headers
))
5823 (message-narrow-to-headers)
5824 (let* ((Date (message-make-date))
5825 (Message-ID (message-make-message-id))
5826 (Organization (message-make-organization))
5827 (From (message-make-from))
5828 (Path (message-make-path))
5831 (In-Reply-To (message-make-in-reply-to))
5832 (References (message-make-references))
5834 (Distribution (message-make-distribution))
5835 (Lines (message-make-lines))
5836 (User-Agent message-newsreader
)
5837 (Expires (message-make-expires))
5838 (case-fold-search t
)
5840 header value elem header-string
)
5841 ;; First we remove any old generated headers.
5842 (let ((headers message-deletable-headers
))
5843 (unless (buffer-modified-p)
5844 (setq headers
(delq 'Message-ID
(copy-sequence headers
))))
5846 (goto-char (point-min))
5847 (and (re-search-forward
5848 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
5849 (get-text-property (1+ (match-beginning 0)) 'message-deletable
)
5850 (message-delete-line))
5852 ;; Go through all the required headers and see if they are in the
5853 ;; articles already. If they are not, or are empty, they are
5854 ;; inserted automatically - except for Subject, Newsgroups and
5857 (goto-char (point-min))
5858 (setq elem
(pop headers
))
5860 (if (eq (car elem
) 'optional
)
5861 (setq header
(cdr elem
)
5863 (setq header
(car elem
)))
5865 (setq header-string
(if (stringp header
)
5867 (symbol-name header
)))
5868 (when (or (not (re-search-forward
5870 (regexp-quote (downcase header-string
))
5874 ;; The header was found. We insert a space after the
5875 ;; colon, if there is none.
5876 (if (/= (char-after) ?
) (insert " ") (forward-char 1))
5877 ;; Find out whether the header is empty.
5878 (looking-at "[ \t]*\n[^ \t]")))
5879 ;; So we find out what value we should insert.
5883 (eq (car elem
) 'optional
)
5884 (not (member header-string message-inserted-headers
)))
5885 ;; This is an optional header. If the cdr of this
5886 ;; is something that is nil, then we do not insert
5888 (setq header
(cdr elem
))
5889 (or (and (functionp (cdr elem
))
5890 (funcall (cdr elem
)))
5891 (and (boundp (cdr elem
))
5892 (symbol-value (cdr elem
)))))
5894 ;; The element is a cons. Either the cdr is a
5895 ;; string to be inserted verbatim, or it is a
5896 ;; function, and we insert the value returned from
5898 (or (and (stringp (cdr elem
))
5900 (and (functionp (cdr elem
))
5901 (funcall (cdr elem
)))))
5902 ((and (boundp header
)
5903 (symbol-value header
))
5904 ;; The element is a symbol. We insert the value
5905 ;; of this symbol, if any.
5906 (symbol-value header
))
5907 ((not (message-check-element
5908 (intern (downcase (symbol-name header
)))))
5909 ;; We couldn't generate a value for this header,
5910 ;; so we just ask the user.
5911 (read-from-minibuffer
5912 (format "Empty header for %s; enter value: " header
)))))
5913 ;; Finally insert the header.
5915 (not (equal value
"")))
5919 ;; This header didn't exist, so we insert it.
5920 (goto-char (point-max))
5922 (cdr (assq header message-header-format-alist
))))
5924 (funcall formatter header value
)
5925 (insert header-string
": " value
))
5926 (push header-string message-inserted-headers
)
5927 (goto-char (message-fill-field))
5928 ;; We check whether the value was ended by a
5929 ;; newline. If not, we insert one.
5933 ;; The value of this header was empty, so we clear
5934 ;; totally and insert the new value.
5935 (delete-region (point) (point-at-eol))
5936 ;; If the header is optional, and the header was
5937 ;; empty, we can't insert it anyway.
5939 (push header-string message-inserted-headers
)
5941 (message-fill-field)))
5942 ;; Add the deletable property to the headers that require it.
5943 (and (memq header message-deletable-headers
)
5944 (progn (beginning-of-line) (looking-at "[^:]+: "))
5945 (add-text-properties
5946 (point) (match-end 0)
5947 '(message-deletable t face italic
) (current-buffer)))))))
5948 ;; Insert new Sender if the From is strange.
5949 (let ((from (message-fetch-field "from"))
5950 (sender (message-fetch-field "sender"))
5951 (secure-sender (message-make-sender)))
5953 (not (message-check-element 'sender
))
5956 (cadr (mail-extract-address-components from
)))
5957 (downcase secure-sender
)))
5962 (cadr (mail-extract-address-components sender
)))
5963 (downcase secure-sender
)))))
5964 (goto-char (point-min))
5965 ;; Rename any old Sender headers to Original-Sender.
5966 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t
)
5968 (insert "Original-")
5969 (beginning-of-line))
5970 (when (or (message-news-p)
5971 (string-match "@.+\\.." secure-sender
))
5972 (insert "Sender: " secure-sender
"\n"))))
5974 (message-idna-to-ascii-rhs))))
5976 (defun message-insert-courtesy-copy (message)
5977 "Insert a courtesy message in mail copies of combined messages."
5981 (message-narrow-to-headers)
5982 (when (setq newsgroups
(message-fetch-field "newsgroups"))
5983 (goto-char (point-max))
5984 (insert "Posted-To: " newsgroups
"\n")))
5988 ((string-match "%s" message
)
5989 (insert (format message newsgroups
)))
5991 (insert message
)))))))
5994 ;;; Setting up a message buffer
5997 (defun message-skip-to-next-address ()
5998 (let ((end (save-excursion
5999 (message-next-header)
6002 (when (looking-at ",")
6004 (while (and (not (= (point) end
))
6005 (or (not (eq char ?
,))
6007 (skip-chars-forward "^,\"" (point-max))
6008 (when (eq (setq char
(following-char)) ?
\")
6009 (setq quoted
(not quoted
)))
6010 (unless (= (point) end
)
6012 (skip-chars-forward " \t\n")))
6014 (defun message-fill-address (header value
)
6015 (insert (capitalize (symbol-name header
))
6017 (if (consp value
) (car value
) value
)
6019 (message-fill-field-address))
6021 (defun message-split-line ()
6022 "Split current line, moving portion beyond point vertically down.
6023 If the current line has `message-yank-prefix', insert it on the new line."
6026 (split-line message-yank-prefix
) ;; Emacs 22.1+ supports arg.
6030 (defun message-insert-header (header value
)
6031 (insert (capitalize (symbol-name header
))
6033 (if (consp value
) (car value
) value
)))
6035 (defun message-field-name ()
6037 (goto-char (point-min))
6038 (when (looking-at "\\([^:]+\\):")
6039 (intern (capitalize (match-string 1))))))
6041 (defun message-fill-field ()
6044 (message-narrow-to-field)
6045 (let ((field-name (message-field-name)))
6046 (funcall (or (cadr (assq field-name message-field-fillers
))
6047 'message-fill-field-general
)))
6050 (defun message-fill-field-address ()
6052 (message-skip-to-next-address)
6054 (if (and (> (current-column) 78)
6060 (setq last
(1+ (point))))
6061 (setq last
(1+ (point)))))))
6063 (defun message-fill-field-general ()
6064 (let ((begin (point))
6067 (while (and (search-forward "\n" nil t
)
6069 (replace-match " " t t
))
6070 (fill-region-as-paragraph begin
(point-max))
6071 ;; Tapdance around looong Message-IDs.
6073 (when (looking-at "[ \t]*$")
6074 (message-delete-line))
6076 (search-forward ":" nil t
)
6077 (when (looking-at "\n[ \t]+")
6078 (replace-match " " t t
))
6079 (goto-char (point-max))))
6081 (defun message-shorten-1 (list cut surplus
)
6082 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
6083 (setcdr (nthcdr (- cut
2) list
)
6084 (nthcdr (+ (- cut
2) surplus
1) list
)))
6086 (defun message-shorten-references (header references
)
6087 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
6088 When sending via news, also check that the REFERENCES are less
6089 than 988 characters long, and if they are not, trim them until
6091 ;; 21 is the number suggested by USEAGE.
6098 (goto-char (point-min))
6099 ;; Cons a list of valid references. GNKSA says we must not include MIDs
6100 ;; with whitespace or missing brackets (7.a "Does not propagate broken
6101 ;; Message-IDs in original References").
6102 (while (re-search-forward "<[^ <]+@[^ <]+>" nil t
)
6103 (push (match-string 0) refs
))
6104 (setq refs
(nreverse refs
)
6105 count
(length refs
)))
6107 ;; If the list has more than MAXCOUNT elements, trim it by
6108 ;; removing the CUTth element and the required number of
6109 ;; elements that follow.
6110 (when (> count maxcount
)
6111 (let ((surplus (- count maxcount
)))
6112 (message-shorten-1 refs cut surplus
)
6113 (decf count surplus
)))
6115 ;; When sending via news, make sure the total folded length will
6116 ;; be less than 998 characters. This is to cater to broken INN
6117 ;; 2.3 which counts the total number of characters in a header
6118 ;; rather than the physical line length of each line, as it should.
6120 ;; This hack should be removed when it's believed than INN 2.3 is
6121 ;; no longer widely used.
6123 ;; At this point the headers have not been generated, thus we use
6124 ;; message-this-is-news directly.
6125 (when message-this-is-news
6128 (message-insert-header
6129 header
(mapconcat #'identity refs
" "))
6131 (message-shorten-1 refs cut
1)))
6132 ;; Finally, collect the references back into a string and insert
6133 ;; it into the buffer.
6134 (message-insert-header header
(mapconcat #'identity refs
" "))))
6136 (defun message-position-point ()
6137 "Move point to where the user probably wants to find it."
6138 (message-narrow-to-headers)
6140 ((re-search-forward "^[^:]+:[ \t]*$" nil t
)
6141 (search-backward ":" )
6144 (if (eq (char-after) ?
)
6148 (goto-char (point-max))
6151 (unless (looking-at "$")
6155 (defcustom message-beginning-of-line t
6156 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
6157 goes to beginning of header values."
6159 :group
'message-buffers
6160 :link
'(custom-manual "(message)Movement")
6163 (defun message-beginning-of-line (&optional n
)
6164 "Move point to beginning of header value or to beginning of line.
6165 The prefix argument N is passed directly to `beginning-of-line'.
6167 This command is identical to `beginning-of-line' if point is
6168 outside the message header or if the option `message-beginning-of-line'
6171 If point is in the message header and on a (non-continued) header
6172 line, move point to the beginning of the header value or the beginning of line,
6173 whichever is closer. If point is already at beginning of line, move point to
6174 beginning of header value. Therefore, repeated calls will toggle point
6175 between beginning of field and beginning of line."
6177 (let ((zrs 'zmacs-region-stays
))
6178 (when (and (featurep 'xemacs
) (interactive-p) (boundp zrs
))
6180 (if (and message-beginning-of-line
6181 (message-point-in-header-p))
6182 (let* ((here (point))
6183 (bol (progn (beginning-of-line n
) (point)))
6184 (eol (point-at-eol))
6185 (eoh (re-search-forward ": *" eol t
)))
6187 (if (and eoh
(or (< eoh here
) (= bol here
)))
6189 (beginning-of-line n
)))
6191 (defun message-buffer-name (type &optional to group
)
6192 "Return a new (unique) buffer name based on TYPE and TO."
6194 ;; Generate a new buffer name The Message Way.
6195 ((memq message-generate-new-buffers
'(unique t
))
6196 (generate-new-buffer-name
6200 (or (car (mail-extract-address-components to
))
6203 (if (and group
(not (string= group
""))) (concat " on " group
) "")
6205 ;; Check whether `message-generate-new-buffers' is a function,
6206 ;; and if so, call it.
6207 ((functionp message-generate-new-buffers
)
6208 (funcall message-generate-new-buffers type to group
))
6209 ((eq message-generate-new-buffers
'unsent
)
6210 (generate-new-buffer-name
6211 (concat "*unsent " type
6214 (or (car (mail-extract-address-components to
))
6217 (if (and group
(not (string= group
""))) (concat " on " group
) "")
6219 ;; Search for the existing message buffer with the specified name.
6221 (let* ((new (if (eq message-generate-new-buffers
'standard
)
6222 (generate-new-buffer-name (concat "*" type
" message*"))
6223 (let ((message-generate-new-buffers 'unique
))
6224 (message-buffer-name type to group
))))
6225 (regexp (concat "\\`"
6227 (if (string-match "<[0-9]+>\\'" new
)
6228 (substring new
0 (match-beginning 0))
6230 "\\(?:<\\([0-9]+\\)>\\)?\\'"))
6231 (case-fold-search nil
))
6238 (when (and (string-match regexp
(setq b
(buffer-name b
)))
6239 (eq (with-current-buffer b major-mode
)
6241 (cons (string-to-number (or (match-string 1 b
) "1"))
6244 'car-less-than-car
)))
6247 (defun message-pop-to-buffer (name &optional switch-function
)
6248 "Pop to buffer NAME, and warn if it already exists and is modified."
6249 (let ((buffer (get-buffer name
)))
6251 (buffer-name buffer
))
6252 (let ((window (get-buffer-window buffer
0)))
6254 ;; Raise the frame already displaying the message buffer.
6256 (gnus-select-frame-set-input-focus (window-frame window
))
6257 (select-window window
))
6258 (funcall (or switch-function
'pop-to-buffer
) buffer
)
6259 (set-buffer buffer
))
6260 (when (and (buffer-modified-p)
6263 "Message already being composed; erase? ")
6265 (error "Message being composed")))
6266 (funcall (or switch-function
'pop-to-buffer
) name
)
6271 (defun message-do-send-housekeeping ()
6272 "Kill old message buffers."
6273 ;; We might have sent this buffer already. Delete it from the
6275 (setq message-buffer-list
(delq (current-buffer) message-buffer-list
))
6276 (while (and message-max-buffers
6278 (>= (length message-buffer-list
) message-max-buffers
))
6279 ;; Kill the oldest buffer -- unless it has been changed.
6280 (let ((buffer (pop message-buffer-list
)))
6281 (when (and (buffer-name buffer
)
6282 (not (buffer-modified-p buffer
)))
6283 (kill-buffer buffer
))))
6284 ;; Rename the buffer.
6285 (if message-send-rename-function
6286 (funcall message-send-rename-function
)
6287 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
6289 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
6291 (let ((name (match-string 2 (buffer-name)))
6293 (if (not (or (null name
)
6294 (string-equal name
"mail")
6295 (string-equal name
"posting")))
6296 (setq name
(concat "*sent " name
"*"))
6297 (message-narrow-to-headers)
6298 (setq to
(message-fetch-field "to"))
6299 (setq group
(message-fetch-field "newsgroups"))
6303 (to (concat "*sent mail to "
6304 (or (car (mail-extract-address-components to
))
6306 ((and group
(not (string= group
"")))
6307 (concat "*sent posting on " group
"*"))
6308 (t "*sent mail*"))))
6309 (unless (string-equal name
(buffer-name))
6310 (rename-buffer name t
)))))
6311 ;; Push the current buffer onto the list.
6312 (when message-max-buffers
6313 (setq message-buffer-list
6314 (nconc message-buffer-list
(list (current-buffer))))))
6316 (defun message-mail-user-agent ()
6318 ((not message-mail-user-agent
) nil
)
6319 ((eq message-mail-user-agent t
) mail-user-agent
)
6320 (t message-mail-user-agent
))))
6321 (if (memq mua
'(message-user-agent gnus-user-agent
))
6325 ;; YANK-ACTION, if non-nil, can be a buffer or a yank action of the
6326 ;; form (FUNCTION . ARGS).
6327 (defun message-setup (headers &optional yank-action actions
6328 continue switch-function return-action
)
6329 (let ((mua (message-mail-user-agent))
6331 (if (not (and message-this-is-mail mua
))
6332 (message-setup-1 headers yank-action actions return-action
)
6333 (setq headers
(copy-sequence headers
))
6334 (setq field
(assq 'Subject headers
))
6336 (setq subject
(cdr field
))
6337 (setq headers
(delq field headers
)))
6338 (setq field
(assq 'To headers
))
6340 (setq to
(cdr field
))
6341 (setq headers
(delq field headers
)))
6342 (let ((mail-user-agent mua
))
6343 (compose-mail to subject
6344 (mapcar (lambda (item)
6346 (format "%s" (car item
))
6349 continue switch-function
6350 (if (bufferp yank-action
)
6351 (list 'insert-buffer yank-action
)
6355 (defun message-headers-to-generate (headers included-headers excluded-headers
)
6356 "Return a list that includes all headers from HEADERS.
6357 If INCLUDED-HEADERS is a list, just include those headers. If it is
6358 t, include all headers. In any case, headers from EXCLUDED-HEADERS
6362 (dolist (header headers
)
6363 (setq header-name
(cond
6364 ((and (consp header
)
6365 (eq (car header
) 'optional
))
6366 ;; On the form (optional . Header)
6369 ;; On the form (Header . function)
6374 (when (and (not (memq header-name excluded-headers
))
6375 (or (eq included-headers t
)
6376 (memq header-name included-headers
)))
6377 (push header result
)))
6380 (defun message-setup-1 (headers &optional yank-action actions return-action
)
6381 (dolist (action actions
)
6383 (add-to-list 'message-send-actions
6384 `(apply ',(car action
) ',(cdr action
)))))
6385 (setq message-return-action return-action
)
6386 (setq message-reply-buffer
6387 (if (and (consp yank-action
)
6388 (eq (car yank-action
) 'insert-buffer
))
6391 (goto-char (point-min))
6392 ;; Insert all the headers.
6395 (alist message-header-format-alist
))
6397 (unless (assq (caar h
) message-header-format-alist
)
6398 (push (list (caar h
)) alist
))
6402 (delete-region (point) (progn (forward-line -
1) (point)))
6403 (when message-default-headers
6405 (if (functionp message-default-headers
)
6406 (funcall message-default-headers
)
6407 message-default-headers
))
6408 (or (bolp) (insert ?
\n)))
6409 (insert mail-header-separator
"\n")
6411 (when (message-news-p)
6412 (when message-default-news-headers
6413 (insert message-default-news-headers
)
6414 (or (bolp) (insert ?
\n)))
6415 (when message-generate-headers-first
6416 (message-generate-headers
6417 (message-headers-to-generate
6418 (append message-required-news-headers
6419 message-required-headers
)
6420 message-generate-headers-first
6421 '(Lines Subject
)))))
6422 (when (message-mail-p)
6423 (when message-default-mail-headers
6424 (insert message-default-mail-headers
)
6425 (or (bolp) (insert ?
\n)))
6426 (when message-generate-headers-first
6427 (message-generate-headers
6428 (message-headers-to-generate
6429 (append message-required-mail-headers
6430 message-required-headers
)
6431 message-generate-headers-first
6432 '(Lines Subject
)))))
6433 (run-hooks 'message-signature-setup-hook
)
6434 (message-insert-signature)
6436 (message-narrow-to-headers)
6437 (run-hooks 'message-header-setup-hook
))
6438 (setq buffer-undo-list nil
)
6439 (when message-generate-hashcash
6440 ;; Generate hashcash headers for recipients already known
6441 (mail-add-payment-async))
6442 ;; Gnus posting styles are applied via buffer-local `message-setup-hook'
6444 (run-hooks 'message-setup-hook
)
6445 ;; Do this last to give it precedence over posting styles, etc.
6446 (when (message-mail-p)
6448 (message-narrow-to-headers)
6449 (if message-alternative-emails
6450 (message-use-alternative-email-as-from))))
6451 (message-position-point)
6452 ;; Allow correct handling of `message-checksum' in `message-yank-original':
6453 (set-buffer-modified-p nil
)
6456 (defun message-set-auto-save-file-name ()
6457 "Associate the message buffer with a file in the drafts directory."
6458 (when message-auto-save-directory
6459 (unless (file-directory-p
6460 (directory-file-name message-auto-save-directory
))
6461 (make-directory message-auto-save-directory t
))
6463 (setq message-draft-article
6464 (nndraft-request-associate-buffer "drafts"))
6466 ;; If Gnus were alive, draft messages would be saved in the drafts folder.
6467 ;; But Gnus is not alive, so arrange to save the draft message in a
6468 ;; regular file in message-auto-save-directory. Append a unique
6469 ;; time-based suffix to the filename to allow multiple drafts to be saved
6470 ;; simultaneously without overwriting each other (which mimics the
6471 ;; functionality of the Gnus drafts folder).
6472 (setq buffer-file-name
(expand-file-name
6474 (if (memq system-type
6475 '(ms-dos windows-nt cygwin
))
6478 (format-time-string "-%Y%m%d-%H%M%S"))
6479 message-auto-save-directory
))
6480 (setq buffer-auto-save-file-name
(make-auto-save-file-name)))
6481 (clear-visited-file-modtime)
6482 (setq buffer-file-coding-system message-draft-coding-system
)))
6484 (defun message-disassociate-draft ()
6485 "Disassociate the message buffer from the drafts directory."
6486 (when message-draft-article
6487 (nndraft-request-expire-articles
6488 (list message-draft-article
) "drafts" nil t
)))
6490 (defun message-insert-headers ()
6491 "Generate the headers for the article."
6495 (message-narrow-to-headers)
6496 (when (message-news-p)
6497 (message-generate-headers
6500 (copy-sequence message-required-news-headers
)))))
6501 (when (message-mail-p)
6502 (message-generate-headers
6505 (copy-sequence message-required-mail-headers
))))))))
6510 ;;; Commands for interfacing with message
6514 (defun message-mail (&optional to subject other-headers continue
6515 switch-function yank-action send-actions
6516 return-action
&rest ignored
)
6517 "Start editing a mail message to be sent.
6518 OTHER-HEADERS is an alist of header/value pairs. CONTINUE says whether
6519 to continue editing a message already being composed. SWITCH-FUNCTION
6520 is a function used to switch to and display the mail buffer."
6522 (let ((message-this-is-mail t
))
6523 (unless (message-mail-user-agent)
6524 (message-pop-to-buffer
6525 ;; Search for the existing message buffer if `continue' is non-nil.
6526 (let ((message-generate-new-buffers
6527 (when (or (not continue
)
6528 (eq message-generate-new-buffers
'standard
)
6529 (functionp message-generate-new-buffers
))
6530 message-generate-new-buffers
)))
6531 (message-buffer-name "mail" to
))
6535 `((To .
,(or to
"")) (Subject .
,(or subject
"")))
6536 ;; C-h f compose-mail says that headers should be specified as
6537 ;; (string . value); however all the rest of message expects
6538 ;; headers to be symbols, not strings (eg message-header-format-alist).
6539 ;; http://lists.gnu.org/archive/html/emacs-devel/2011-01/msg00337.html
6540 ;; We need to convert any string input, eg from rmail-start-mail.
6541 (dolist (h other-headers other-headers
)
6542 (if (stringp (car h
)) (setcar h
(intern (capitalize (car h
)))))))
6543 yank-action send-actions continue switch-function
6545 ;; FIXME: Should return nil if failure.
6549 (defun message-news (&optional newsgroups subject
)
6550 "Start editing a news article to be sent."
6552 (let ((message-this-is-news t
))
6553 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
))
6554 (message-setup `((Newsgroups .
,(or newsgroups
""))
6555 (Subject .
,(or subject
""))))))
6557 (defun message-alter-recipients-discard-bogus-full-name (addrcell)
6558 "Discard mail address in full names.
6559 When the full name in reply headers contains the mail
6560 address (e.g. \"foo@bar <foo@bar>\"), discard full name.
6561 ADDRCELL is a cons cell where the car is the mail address and the
6562 cdr is the complete address (full name and mail address)."
6563 (if (string-match (concat (regexp-quote (car addrcell
)) ".*"
6564 (regexp-quote (car addrcell
)))
6566 (cons (car addrcell
) (car addrcell
))
6569 (defcustom message-alter-recipients-function nil
6570 "Function called to allow alteration of reply header structures.
6571 It is called in `message-get-reply-headers' for each recipient.
6572 The function is called with one parameter, a cons cell ..."
6573 :type
'(choice (const :tag
"None" nil
)
6574 (const :tag
"Discard bogus full name"
6575 message-alter-recipients-discard-bogus-full-name
)
6577 :version
"23.1" ;; No Gnus
6578 :group
'message-headers
)
6580 (defun message-get-reply-headers (wide &optional to-address address-headers
)
6581 (let (follow-to mct never-mct to cc author mft recipients extra
)
6582 ;; Find all relevant headers we need.
6584 (message-narrow-to-headers-or-head)
6585 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
6586 ;; message-header-synonyms.
6587 (setq to
(or (message-fetch-field "to")
6588 (and (loop for synonym in message-header-synonyms
6589 when
(memq 'Original-To synonym
)
6591 (message-fetch-field "original-to")))
6592 cc
(message-fetch-field "cc")
6593 extra
(when message-extra-wide-headers
6594 (mapconcat 'identity
6595 (mapcar 'message-fetch-field
6596 message-extra-wide-headers
)
6598 mct
(message-fetch-field "mail-copies-to")
6599 author
(or (message-fetch-field "mail-reply-to")
6600 (message-fetch-field "reply-to")
6601 (message-fetch-field "from")
6603 mft
(and message-use-mail-followup-to
6604 (message-fetch-field "mail-followup-to"))))
6606 ;; Handle special values of Mail-Copies-To.
6608 (cond ((or (equal (downcase mct
) "never")
6609 (equal (downcase mct
) "nobody"))
6612 ((or (equal (downcase mct
) "always")
6613 (equal (downcase mct
) "poster"))
6614 (setq mct author
))))
6617 ;; Build (textual) list of new recipient addresses.
6620 (setq recipients
(concat ", " to-address
))
6621 ;; If the author explicitly asked for a copy, we don't deny it to them.
6622 (if mct
(setq recipients
(concat recipients
", " mct
))))
6624 (setq recipients
(concat ", " author
)))
6626 (dolist (header address-headers
)
6627 (let ((value (message-fetch-field header
)))
6629 (setq recipients
(concat recipients
", " value
))))))
6631 (string-match "[^ \t,]" mft
)
6632 (or (not (eq message-use-mail-followup-to
'ask
))
6633 (message-y-or-n-p "Obey Mail-Followup-To? " t
"\
6634 You should normally obey the Mail-Followup-To: header. In this
6635 article, it has the value of
6639 which directs your response to " (if (string-match "," mft
)
6640 "the specified addresses"
6641 "that address only") ".
6643 Most commonly, Mail-Followup-To is used by a mailing list poster to
6644 express that responses should be sent to just the list, and not the
6647 If a message is posted to several mailing lists, Mail-Followup-To may
6648 also be used to direct the following discussion to one list only,
6649 because discussions that are spread over several lists tend to be
6650 fragmented and very difficult to follow.
6652 Also, some source/announcement lists are not intended for discussion;
6653 responses here are directed to other addresses.
6655 You may customize the variable `message-use-mail-followup-to', if you
6656 want to get rid of this query permanently.")))
6657 (setq recipients
(concat ", " mft
)))
6659 (setq recipients
(if never-mct
"" (concat ", " author
)))
6660 (if to
(setq recipients
(concat recipients
", " to
)))
6661 (if cc
(setq recipients
(concat recipients
", " cc
)))
6662 (if extra
(setq recipients
(concat recipients
", " extra
)))
6663 (if mct
(setq recipients
(concat recipients
", " mct
)))))
6664 (if (>= (length recipients
) 2)
6665 ;; Strip the leading ", ".
6666 (setq recipients
(substring recipients
2)))
6667 ;; Squeeze whitespace.
6668 (while (string-match "[ \t][ \t]+" recipients
)
6669 (setq recipients
(replace-match " " t t recipients
)))
6670 ;; Remove addresses that match `rmail-dont-reply-to-names'.
6671 (let ((rmail-dont-reply-to-names (message-dont-reply-to-names)))
6672 (setq recipients
(rmail-dont-reply-to recipients
)))
6673 ;; Perhaps "Mail-Copies-To: never" removed the only address?
6674 (if (string-equal recipients
"")
6675 (setq recipients author
))
6676 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
6680 (if message-alter-recipients-function
6681 (funcall message-alter-recipients-function
6682 (cons (downcase (mail-strip-quoted-names addr
))
6684 (cons (downcase (mail-strip-quoted-names addr
)) addr
)))
6685 (message-tokenize-header recipients
)))
6686 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
6687 (let ((s recipients
))
6689 (setq recipients
(delq (assoc (car (pop s
)) s
) recipients
))))
6691 ;; Remove hierarchical lists that are contained within each other,
6692 ;; if message-hierarchical-addresses is defined.
6693 (when message-hierarchical-addresses
6694 (let ((plain-addrs (mapcar 'car recipients
))
6697 (setq subaddrs
(assoc (car plain-addrs
)
6698 message-hierarchical-addresses
)
6699 plain-addrs
(cdr plain-addrs
))
6701 (setq subaddrs
(cdr subaddrs
))
6703 (setq recip
(assoc (car subaddrs
) recipients
)
6704 subaddrs
(cdr subaddrs
))
6706 (setq recipients
(delq recip recipients
))))))))
6708 (setq recipients
(message-prune-recipients recipients
))
6710 ;; Build the header alist. Allow the user to be asked whether
6711 ;; or not to reply to all recipients in a wide reply.
6712 (setq follow-to
(list (cons 'To
(cdr (pop recipients
)))))
6713 (when (and recipients
6714 (or (not message-wide-reply-confirm-recipients
)
6715 (y-or-n-p "Reply to all recipients? ")))
6716 (setq recipients
(mapconcat
6717 (lambda (addr) (cdr addr
)) recipients
", "))
6718 (if (string-match "^ +" recipients
)
6719 (setq recipients
(substring recipients
(match-end 0))))
6720 (push (cons 'Cc recipients
) follow-to
)))
6723 (defun message-prune-recipients (recipients)
6724 (dolist (rule message-prune-recipient-rules
)
6725 (let ((match (car rule
))
6728 (dolist (recipient recipients
)
6729 (setq address
(car recipient
))
6730 (when (string-match match address
)
6731 (setq dup-match
(replace-match (cadr rule
) nil nil address
))
6732 (dolist (recipient recipients
)
6733 ;; Don't delete the address that triggered this.
6734 (when (and (not (eq address
(car recipient
)))
6735 (string-match dup-match
(car recipient
)))
6736 (setq recipients
(delq recipient recipients
))))))))
6739 (defcustom message-simplify-subject-functions
6740 '(message-strip-list-identifiers
6741 message-strip-subject-re
6742 message-strip-subject-trailing-was
6743 message-strip-subject-encoded-words
)
6744 "List of functions taking a string argument that simplify subjects.
6745 The functions are applied when replying to a message.
6747 Useful functions to put in this list include:
6748 `message-strip-list-identifiers', `message-strip-subject-re',
6749 `message-strip-subject-trailing-was', and
6750 `message-strip-subject-encoded-words'."
6751 :version
"22.1" ;; Gnus 5.10.9
6752 :group
'message-various
6753 :type
'(repeat function
))
6755 (defun message-simplify-subject (subject &optional functions
)
6756 "Return simplified SUBJECT."
6759 (setq functions message-simplify-subject-functions
))
6760 (when (and (memq 'message-strip-list-identifiers functions
)
6761 gnus-list-identifiers
)
6762 (setq subject
(message-strip-list-identifiers subject
)))
6763 (when (memq 'message-strip-subject-re functions
)
6764 (setq subject
(concat "Re: " (message-strip-subject-re subject
))))
6765 (when (and (memq 'message-strip-subject-trailing-was functions
)
6766 message-subject-trailing-was-query
)
6767 (setq subject
(message-strip-subject-trailing-was subject
)))
6768 (when (memq 'message-strip-subject-encoded-words functions
)
6769 (setq subject
(message-strip-subject-encoded-words subject
)))
6773 (defun message-reply (&optional to-address wide
)
6774 "Start editing a reply to the article in the current buffer."
6776 (require 'gnus-sum
) ; for gnus-list-identifiers
6777 (let ((cur (current-buffer))
6779 reply-to to cc
;FIXME: These 3 seem to be unused? --Stef
6780 references message-id follow-to
6781 (inhibit-point-motion-hooks t
)
6782 (message-this-is-mail t
)
6785 (message-narrow-to-head-1)
6786 ;; Allow customizations to have their say.
6788 ;; This is a regular reply.
6789 (when (functionp message-reply-to-function
)
6791 (setq follow-to
(funcall message-reply-to-function
))))
6792 ;; This is a followup.
6793 (when (functionp message-wide-reply-to-function
)
6796 (funcall message-wide-reply-to-function
)))))
6797 (setq message-id
(message-fetch-field "message-id" t
)
6798 references
(message-fetch-field "references")
6799 date
(message-fetch-field "date")
6800 from
(or (message-fetch-field "from") "nobody")
6801 subject
(or (message-fetch-field "subject") "none"))
6803 ;; Strip list identifiers, "Re: ", and "was:"
6804 (setq subject
(message-simplify-subject subject
))
6806 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
6807 (string-match "<[^>]+>" gnus-warning
))
6808 (setq message-id
(match-string 0 gnus-warning
)))
6811 (setq follow-to
(message-get-reply-headers wide to-address
))))
6813 (unless (message-mail-user-agent)
6814 (message-pop-to-buffer
6815 (message-buffer-name
6816 (if wide
"wide reply" "reply") from
6817 (if wide to-address nil
))))
6819 (setq message-reply-headers
6820 (vector 0 subject from date message-id references
0 0 ""))
6823 `((Subject .
,subject
)
6828 (defun message-wide-reply (&optional to-address
)
6829 "Make a \"wide\" reply to the message in the current buffer."
6831 (message-reply to-address t
))
6834 (defun message-followup (&optional to-newsgroups
)
6835 "Follow up to the message in the current buffer.
6836 If TO-NEWSGROUPS, use that as the new Newsgroups line."
6838 (require 'gnus-sum
) ; for gnus-list-identifiers
6839 (let ((cur (current-buffer))
6840 from subject date reply-to mrt mct
6841 references message-id follow-to
6842 (inhibit-point-motion-hooks t
)
6843 (message-this-is-news t
)
6844 followup-to distribution newsgroups gnus-warning posted-to
)
6847 (goto-char (point-min))
6848 (if (search-forward "\n\n" nil t
)
6851 (when (functionp message-followup-to-function
)
6853 (funcall message-followup-to-function
)))
6854 (setq from
(message-fetch-field "from")
6855 date
(message-fetch-field "date")
6856 subject
(or (message-fetch-field "subject") "none")
6857 references
(message-fetch-field "references")
6858 message-id
(message-fetch-field "message-id" t
)
6859 followup-to
(message-fetch-field "followup-to")
6860 newsgroups
(message-fetch-field "newsgroups")
6861 posted-to
(message-fetch-field "posted-to")
6862 reply-to
(message-fetch-field "reply-to")
6863 mrt
(message-fetch-field "mail-reply-to")
6864 distribution
(message-fetch-field "distribution")
6865 mct
(message-fetch-field "mail-copies-to"))
6866 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
6867 (string-match "<[^>]+>" gnus-warning
))
6868 (setq message-id
(match-string 0 gnus-warning
)))
6869 ;; Remove bogus distribution.
6870 (when (and (stringp distribution
)
6871 (let ((case-fold-search t
))
6872 (string-match "world" distribution
)))
6873 (setq distribution nil
))
6874 ;; Strip list identifiers, "Re: ", and "was:"
6875 (setq subject
(message-simplify-subject subject
))
6878 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups
))
6880 (setq message-reply-headers
6881 (vector 0 subject from date message-id references
0 0 ""))
6884 `((Subject .
,subject
)
6887 (list (cons 'Newsgroups to-newsgroups
)))
6888 (follow-to follow-to
)
6889 ((and followup-to message-use-followup-to
)
6892 ((equal (downcase followup-to
) "poster")
6893 (if (or (eq message-use-followup-to
'use
)
6894 (message-y-or-n-p "Obey Followup-To: poster? " t
"\
6895 You should normally obey the Followup-To: header.
6897 `Followup-To: poster' sends your response via e-mail instead of news.
6899 A typical situation where `Followup-To: poster' is used is when the poster
6900 does not read the newsgroup, so he wouldn't see any replies sent to it.
6902 You may customize the variable `message-use-followup-to', if you
6903 want to get rid of this query permanently."))
6905 (setq message-this-is-news nil
)
6906 (cons 'To
(or mrt reply-to from
"")))
6907 (cons 'Newsgroups newsgroups
)))
6909 (if (or (equal followup-to newsgroups
)
6910 (not (eq message-use-followup-to
'ask
))
6912 (concat "Obey Followup-To: " followup-to
"? ") t
"\
6913 You should normally obey the Followup-To: header.
6915 `Followup-To: " followup-to
"'
6916 directs your response to " (if (string-match "," followup-to
)
6917 "the specified newsgroups"
6918 "that newsgroup only") ".
6920 If a message is posted to several newsgroups, Followup-To is often
6921 used to direct the following discussion to one newsgroup only,
6922 because discussions that are spread over several newsgroup tend to
6923 be fragmented and very difficult to follow.
6925 Also, some source/announcement newsgroups are not intended for discussion;
6926 responses here are directed to other newsgroups.
6928 You may customize the variable `message-use-followup-to', if you
6929 want to get rid of this query permanently."))
6930 (cons 'Newsgroups followup-to
)
6931 (cons 'Newsgroups newsgroups
))))))
6933 `((Newsgroups .
,posted-to
)))
6935 `((Newsgroups .
,newsgroups
))))
6936 ,@(and distribution
(list (cons 'Distribution distribution
)))
6938 (not (or (equal (downcase mct
) "never")
6939 (equal (downcase mct
) "nobody"))))
6940 (list (cons 'Cc
(if (or (equal (downcase mct
) "always")
6941 (equal (downcase mct
) "poster"))
6942 (or mrt reply-to from
"")
6947 (defun message-is-yours-p ()
6948 "Non-nil means current article is yours.
6949 If you have added 'cancel-messages to `message-shoot-gnksa-feet', all articles
6950 are yours except those that have Cancel-Lock header not belonging to you.
6951 Instead of shooting GNKSA feet, you should modify `message-alternative-emails'
6952 regexp to match all of yours addresses."
6953 ;; Canlock-logic as suggested by Per Abrahamsen
6954 ;; <abraham@dina.kvl.dk>
6956 ;; IF article has cancel-lock THEN
6957 ;; IF we can verify it THEN
6960 ;; error: cancellock: article is not yours
6962 ;; Use old rules, comparing sender...
6965 (message-narrow-to-head-1)
6966 (if (message-fetch-field "Cancel-Lock")
6967 (if (null (canlock-verify))
6969 (error "Failed to verify Cancel-lock: This article is not yours"))
6972 (message-gnksa-enable-p 'cancel-messages
)
6973 (and (setq sender
(message-fetch-field "sender"))
6974 (string-equal (downcase sender
)
6975 (downcase (message-make-sender))))
6976 ;; Email address in From field equals to our address
6977 (and (setq from
(message-fetch-field "from"))
6979 (downcase (car (mail-header-parse-address from
)))
6980 (downcase (car (mail-header-parse-address
6981 (message-make-from))))))
6982 ;; Email address in From field matches
6983 ;; 'message-alternative-emails' regexp
6985 message-alternative-emails
6987 message-alternative-emails
6988 (car (mail-header-parse-address from
))))))))))
6991 (defun message-cancel-news (&optional arg
)
6992 "Cancel an article you posted.
6993 If ARG, allow editing of the cancellation message."
6995 (unless (message-news-p)
6996 (error "This is not a news article; canceling is impossible"))
6997 (let (from newsgroups message-id distribution buf
)
6999 ;; Get header info from original article.
7001 (message-narrow-to-head-1)
7002 (setq from
(message-fetch-field "from")
7003 newsgroups
(message-fetch-field "newsgroups")
7004 message-id
(message-fetch-field "message-id" t
)
7005 distribution
(message-fetch-field "distribution")))
7006 ;; Make sure that this article was written by the user.
7007 (unless (message-is-yours-p)
7008 (error "This article is not yours"))
7009 (when (yes-or-no-p "Do you really want to cancel this article? ")
7010 ;; Make control message.
7013 (setq buf
(set-buffer (get-buffer-create " *message cancel*"))))
7015 (insert "Newsgroups: " newsgroups
"\n"
7017 "Subject: cmsg cancel " message-id
"\n"
7018 "Control: cancel " message-id
"\n"
7020 (concat "Distribution: " distribution
"\n")
7022 mail-header-separator
"\n"
7023 message-cancel-message
)
7024 (run-hooks 'message-cancel-hook
)
7026 (message "Canceling your article...")
7027 (if (let ((message-syntax-checks
7028 'dont-check-for-anything-just-trust-me
))
7029 (funcall message-send-news-function
))
7030 (message "Canceling your article...done"))
7031 (kill-buffer buf
))))))
7034 (defun message-supersede ()
7035 "Start composing a message to supersede the current message.
7036 This is done simply by taking the old article and adding a Supersedes
7037 header line with the old Message-ID."
7039 (let ((cur (current-buffer)))
7040 ;; Check whether the user owns the article that is to be superseded.
7041 (unless (message-is-yours-p)
7042 (error "This article is not yours"))
7043 ;; Get a normal message buffer.
7044 (message-pop-to-buffer (message-buffer-name "supersede"))
7045 (insert-buffer-substring cur
)
7047 (message-narrow-to-head-1)
7048 ;; Remove unwanted headers.
7049 (when message-ignored-supersedes-headers
7050 (message-remove-header message-ignored-supersedes-headers t
))
7051 (goto-char (point-min))
7052 (if (not (re-search-forward "^Message-ID: " nil t
))
7053 (error "No Message-ID in this article")
7054 (replace-match "Supersedes: " t t
))
7055 (goto-char (point-max))
7056 (insert mail-header-separator
)
7061 (defun message-recover ()
7062 "Reread contents of current buffer from its last auto-save file."
7064 (let ((file-name (make-auto-save-file-name)))
7065 (cond ((save-window-excursion
7066 (with-output-to-temp-buffer "*Directory*"
7067 (with-current-buffer standard-output
7068 (fundamental-mode)) ; for Emacs 20.4+
7069 (buffer-disable-undo standard-output
)
7070 (let ((default-directory "/"))
7072 "ls" nil standard-output nil
"-l" file-name
)))
7073 (yes-or-no-p (format "Recover auto save file %s? " file-name
)))
7074 (let ((buffer-read-only nil
))
7076 (insert-file-contents file-name nil
)))
7077 (t (error "message-recover cancelled")))))
7079 ;;; Washing Subject:
7081 (defun message-wash-subject (subject)
7082 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
7083 Previous forwarders, replyers, etc. may add it."
7086 (goto-char (point-min))
7087 ;; strip Re/Fwd stuff off the beginning
7088 (while (re-search-forward
7089 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t
)
7092 ;; and gnus-style forwards [foo@bar.com] subject
7093 (goto-char (point-min))
7094 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t
)
7098 (goto-char (point-max))
7099 (while (re-search-backward "([Ff][Ww][Dd])" nil t
)
7102 ;; and finally, any whitespace that was left-over
7103 (goto-char (point-min))
7104 (while (re-search-forward "^[ \t]+" nil t
)
7106 (goto-char (point-max))
7107 (while (re-search-backward "[ \t]+$" nil t
)
7112 ;;; Forwarding messages.
7114 (defvar message-forward-decoded-p nil
7115 "Non-nil means the original message is decoded.")
7117 (defun message-forward-subject-name-subject (subject)
7118 "Generate a SUBJECT for a forwarded message.
7119 The form is: [Source] Subject, where if the original message was mail,
7120 Source is the name of the sender, and if the original message was
7121 news, Source is the list of newsgroups is was posted to."
7122 (let* ((group (message-fetch-field "newsgroups"))
7123 (from (message-fetch-field "from"))
7126 (gnus-group-decoded-name group
)
7128 (car (gnus-extract-address-components from
))
7129 (cadr (gnus-extract-address-components from
))))
7132 (if message-forward-decoded-p
7134 (mail-decode-encoded-word-string prefix
))
7137 (defun message-forward-subject-author-subject (subject)
7138 "Generate a SUBJECT for a forwarded message.
7139 The form is: [Source] Subject, where if the original message was mail,
7140 Source is the sender, and if the original message was news, Source is
7141 the list of newsgroups is was posted to."
7142 (let* ((group (message-fetch-field "newsgroups"))
7145 (gnus-group-decoded-name group
)
7146 (or (message-fetch-field "from")
7149 (if message-forward-decoded-p
7151 (mail-decode-encoded-word-string prefix
))
7154 (defun message-forward-subject-fwd (subject)
7155 "Generate a SUBJECT for a forwarded message.
7156 The form is: Fwd: Subject, where Subject is the original subject of
7158 (if (string-match "^Fwd: " subject
)
7160 (concat "Fwd: " subject
)))
7162 (defun message-make-forward-subject ()
7163 "Return a Subject header suitable for the message in the current buffer."
7166 (message-narrow-to-head-1)
7167 (let ((funcs message-make-forward-subject-function
)
7168 (subject (message-fetch-field "Subject")))
7171 (if message-forward-decoded-p
7173 (mail-decode-encoded-word-string subject
))
7175 (when message-wash-forwarded-subjects
7176 (setq subject
(message-wash-subject subject
)))
7177 ;; Make sure funcs is a list.
7180 (setq funcs
(list funcs
)))
7181 ;; Apply funcs in order, passing subject generated by previous
7182 ;; func to the next one.
7183 (dolist (func funcs
)
7184 (when (functionp func
)
7185 (setq subject
(funcall func subject
))))
7188 (defvar gnus-article-decoded-p
)
7192 (defun message-forward (&optional news digest
)
7193 "Forward the current message via mail.
7194 Optional NEWS will use news to forward instead of mail.
7195 Optional DIGEST will use digest to forward."
7197 (let* ((cur (current-buffer))
7198 (message-forward-decoded-p
7199 (if (local-variable-p 'gnus-article-decoded-p
(current-buffer))
7200 gnus-article-decoded-p
;; In an article buffer.
7201 message-forward-decoded-p
))
7202 (subject (message-make-forward-subject)))
7204 (message-news nil subject
)
7205 (message-mail nil subject
))
7206 (message-forward-make-body cur digest
)))
7208 (defun message-forward-make-body-plain (forward-buffer)
7210 "\n-------------------- Start of forwarded message --------------------\n")
7212 (contents (with-current-buffer forward-buffer
(buffer-string)))
7214 (unless (featurep 'xemacs
)
7215 (unless (mm-multibyte-string-p contents
)
7216 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7217 to the multibyte buffer \"%s\""
7218 (if (bufferp forward-buffer
)
7219 (buffer-name forward-buffer
)
7222 (insert (mm-with-multibyte-buffer
7225 (goto-char (point-min))
7226 (when (looking-at "From ")
7227 (replace-match "X-From-Line: "))
7229 (unless (bolp) (insert "\n"))
7232 "-------------------- End of forwarded message --------------------\n")
7233 (message-remove-ignored-headers b e
)))
7235 (defun message-remove-ignored-headers (b e
)
7236 (when message-forward-ignored-headers
7238 (narrow-to-region b e
)
7240 (narrow-to-region (point)
7241 (or (search-forward "\n\n" nil t
) (point)))
7242 (let ((ignored (if (stringp message-forward-ignored-headers
)
7243 (list message-forward-ignored-headers
)
7244 message-forward-ignored-headers
)))
7245 (dolist (elem ignored
)
7246 (message-remove-header elem t
))))))
7248 (defun message-forward-make-body-mime (forward-buffer)
7250 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
7252 (narrow-to-region (point) (point))
7253 (mml-insert-buffer forward-buffer
)
7254 (goto-char (point-min))
7255 (when (looking-at "From ")
7256 (replace-match "X-From-Line: "))
7257 (goto-char (point-max)))
7258 (insert "<#/part>\n")
7259 ;; Consider there is no illegible text.
7260 (add-text-properties
7262 `(no-illegible-text t rear-nonsticky t start-open t
))))
7264 (defun message-forward-make-body-mml (forward-buffer)
7265 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
7266 (let ((b (point)) e
)
7267 (if (not message-forward-decoded-p
)
7268 (let ((contents (with-current-buffer forward-buffer
(buffer-string))))
7269 (unless (featurep 'xemacs
)
7270 (unless (mm-multibyte-string-p contents
)
7271 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7272 to the multibyte buffer \"%s\""
7273 (if (bufferp forward-buffer
)
7274 (buffer-name forward-buffer
)
7277 (insert (mm-with-multibyte-buffer
7280 (goto-char (point-min))
7281 (when (looking-at "From ")
7282 (replace-match "X-From-Line: "))
7285 (narrow-to-region (point) (point))
7286 (mml-insert-buffer forward-buffer
)
7287 (goto-char (point-min))
7288 (when (looking-at "From ")
7289 (replace-match "X-From-Line: "))
7290 (goto-char (point-max))))
7292 (insert "<#/mml>\n")
7293 (when (and (not message-forward-decoded-p
)
7294 message-forward-ignored-headers
)
7295 (message-remove-ignored-headers b e
))))
7297 (defun message-forward-make-body-digest-plain (forward-buffer)
7299 "\n-------------------- Start of forwarded message --------------------\n")
7300 (let ((b (point)) e
) ;FIXME: Not used, right? --Stef
7301 (mml-insert-buffer forward-buffer
)
7304 "\n-------------------- End of forwarded message --------------------\n")))
7306 (defun message-forward-make-body-digest-mime (forward-buffer)
7307 (insert "\n<#multipart type=digest>\n")
7308 (let ((b (point)) e
)
7309 (insert-buffer-substring forward-buffer
)
7311 (insert "<#/multipart>\n")
7313 (narrow-to-region b e
)
7315 (narrow-to-region (point)
7316 (or (search-forward "\n\n" nil t
) (point)))
7317 (delete-region (point-min) (point-max)))))
7319 (defun message-forward-make-body-digest (forward-buffer)
7320 (if message-forward-as-mime
7321 (message-forward-make-body-digest-mime forward-buffer
)
7322 (message-forward-make-body-digest-plain forward-buffer
)))
7324 (autoload 'mm-uu-dissect-text-parts
"mm-uu")
7325 (autoload 'mm-uu-dissect
"mm-uu")
7327 (defun message-signed-or-encrypted-p (&optional dont-emulate-mime handles
)
7328 "Say whether the current buffer contains signed or encrypted message.
7329 If DONT-EMULATE-MIME is nil, this function does the MIME emulation on
7330 messages that don't conform to PGP/MIME described in RFC2015. HANDLES
7331 is for the internal use."
7333 (let ((mm-decrypt-option 'never
)
7334 (mm-verify-option 'never
))
7335 (if (setq handles
(mm-dissect-buffer nil t
))
7336 (unless dont-emulate-mime
7337 (mm-uu-dissect-text-parts handles
))
7338 (unless dont-emulate-mime
7339 (setq handles
(mm-uu-dissect))))))
7340 ;; Check text/plain message in which there is a signed or encrypted
7341 ;; body that has been encoded by B or Q.
7342 (unless (or handles dont-emulate-mime
)
7343 (let ((cur (current-buffer))
7344 (mm-decrypt-option 'never
)
7345 (mm-verify-option 'never
))
7347 (insert-buffer-substring cur
)
7348 (when (setq handles
(mm-dissect-buffer t t
))
7350 (bufferp (car handles
))
7351 (mm-destroy-parts handles
))
7352 (equal (mm-handle-media-type handles
) "text/plain"))
7354 (mm-decode-content-transfer-encoding
7355 (mm-handle-encoding handles
))
7356 (setq handles
(mm-uu-dissect)))
7357 (setq handles nil
))))))
7361 (dolist (handle (if (stringp (car handles
))
7362 (if (member (car handles
)
7363 '("multipart/signed"
7364 "multipart/encrypted"))
7368 (if (stringp (car handle
))
7369 (when (message-signed-or-encrypted-p dont-emulate-mime handle
)
7371 (when (and (bufferp (car handle
))
7372 (equal (mm-handle-media-type handle
)
7374 (with-current-buffer (mm-handle-buffer handle
)
7375 (when (message-signed-or-encrypted-p dont-emulate-mime
)
7376 (throw 'found t
)))))))
7377 (mm-destroy-parts handles
))))
7380 (defun message-forward-make-body (forward-buffer &optional digest
)
7381 ;; Put point where we want it before inserting the forwarded
7383 (if message-forward-before-signature
7385 (goto-char (point-max)))
7387 (message-forward-make-body-digest forward-buffer
)
7388 (if message-forward-as-mime
7389 (if (and message-forward-show-mml
7390 (not (and (eq message-forward-show-mml
'best
)
7391 ;; Use the raw form in the body if it contains
7392 ;; signed or encrypted message so as not to be
7393 ;; destroyed by re-encoding.
7394 (with-current-buffer forward-buffer
7396 (message-signed-or-encrypted-p)
7398 (message-forward-make-body-mml forward-buffer
)
7399 (message-forward-make-body-mime forward-buffer
))
7400 (message-forward-make-body-plain forward-buffer
)))
7401 (message-position-point))
7403 (declare-function rmail-toggle-header
"rmail" (&optional arg
))
7406 (defun message-forward-rmail-make-body (forward-buffer)
7407 (save-window-excursion
7408 (set-buffer forward-buffer
)
7409 (if (rmail-msg-is-pruned)
7410 (if (fboundp 'rmail-msg-restore-non-pruned-header
)
7411 (rmail-msg-restore-non-pruned-header) ; Emacs 22
7412 (rmail-toggle-header 0)))) ; Emacs 23
7413 (message-forward-make-body forward-buffer
))
7415 ;; Fixme: Should have defcustom.
7417 (defun message-insinuate-rmail ()
7418 "Let RMAIL use message to forward."
7420 (setq rmail-enable-mime-composing t
)
7421 (setq rmail-insert-mime-forwarded-message-function
7422 'message-forward-rmail-make-body
))
7424 (defvar message-inhibit-body-encoding nil
)
7427 (defun message-resend (address)
7428 "Resend the current article to ADDRESS."
7430 (list (message-read-from-minibuffer "Resend message to: ")))
7431 (message "Resending message to %s..." address
)
7433 (let ((cur (current-buffer))
7435 ;; We first set up a normal mail buffer.
7436 (unless (message-mail-user-agent)
7437 (set-buffer (get-buffer-create " *message resend*"))
7439 (let ((message-this-is-mail t
)
7440 message-generate-hashcash
7442 (message-setup `((To .
,address
))))
7443 ;; Insert our usual headers.
7444 (message-generate-headers '(From Date To Message-ID
))
7445 (message-narrow-to-headers)
7446 ;; Remove X-Draft-From header etc.
7447 (message-remove-header message-ignored-mail-headers t
)
7448 ;; Rename them all to "Resent-*".
7449 (goto-char (point-min))
7450 (while (re-search-forward "^[A-Za-z]" nil t
)
7455 (delete-region (point) (point-max))
7457 ;; Insert the message to be resent.
7458 (insert-buffer-substring cur
)
7459 (goto-char (point-min))
7460 (search-forward "\n\n")
7463 (narrow-to-region beg
(point))
7464 (message-remove-header message-ignored-resent-headers t
)
7465 (goto-char (point-max)))
7466 (insert mail-header-separator
)
7467 ;; Rename all old ("Also-")Resent headers.
7468 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t
)
7471 ;; Quote any "From " lines at the beginning.
7473 (when (looking-at "From ")
7474 (replace-match "X-From-Line: "))
7476 (let ((message-inhibit-body-encoding
7477 ;; Don't do any further encoding if it looks like the
7478 ;; message has already been encoded.
7479 (let ((case-fold-search t
))
7480 (re-search-forward "^mime-version:" nil t
)))
7481 (message-inhibit-ecomplete t
)
7482 message-required-mail-headers
7483 message-generate-hashcash
7484 rfc2047-encode-encoded-words
)
7485 (message-send-mail))
7486 (kill-buffer (current-buffer)))
7487 (message "Resending message to %s...done" address
)))
7490 (defun message-bounce ()
7491 "Re-mail the current message.
7492 This only makes sense if the current message is a bounce message that
7493 contains some mail you have written which has been bounced back to
7496 (let ((handles (mm-dissect-buffer t
))
7498 (message-pop-to-buffer (message-buffer-name "bounce"))
7499 (if (stringp (car handles
))
7500 ;; This is a MIME bounce.
7501 (mm-insert-part (car (last handles
)))
7502 ;; This is a non-MIME bounce, so we try to remove things
7504 (mm-insert-part handles
)
7506 (goto-char (point-min))
7507 (re-search-forward "\n\n+" nil t
)
7508 (setq boundary
(point))
7509 ;; We remove everything before the bounced mail.
7510 (if (or (re-search-forward message-unsent-separator nil t
)
7512 (search-forward "\n\n" nil
'move
)
7513 (re-search-backward "^Return-Path:.*\n" boundary t
)))
7516 (delete-region (point-min)
7517 (if (re-search-forward "^[^ \n\t]+:" nil t
)
7520 (goto-char boundary
)
7521 (when (re-search-backward "^.?From .*\n" nil t
)
7522 (delete-region (match-beginning 0) (match-end 0)))))
7525 (message-narrow-to-head-1)
7526 (message-remove-header message-ignored-bounced-headers t
)
7527 (goto-char (point-max))
7528 (insert mail-header-separator
))
7529 (message-position-point)))
7532 ;;; Interactive entry points for new message buffers.
7536 (defun message-mail-other-window (&optional to subject
)
7537 "Like `message-mail' command, but display mail buffer in another window."
7539 (unless (message-mail-user-agent)
7540 (let ((pop-up-windows t
)
7541 (special-display-buffer-names nil
)
7542 (special-display-regexps nil
)
7543 (same-window-buffer-names nil
)
7544 (same-window-regexps nil
))
7545 (message-pop-to-buffer (message-buffer-name "mail" to
))))
7546 (let ((message-this-is-mail t
))
7547 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
"")))
7548 nil nil nil
'switch-to-buffer-other-window
)))
7551 (defun message-mail-other-frame (&optional to subject
)
7552 "Like `message-mail' command, but display mail buffer in another frame."
7554 (unless (message-mail-user-agent)
7555 (let ((pop-up-frames t
)
7556 (special-display-buffer-names nil
)
7557 (special-display-regexps nil
)
7558 (same-window-buffer-names nil
)
7559 (same-window-regexps nil
))
7560 (message-pop-to-buffer (message-buffer-name "mail" to
))))
7561 (let ((message-this-is-mail t
))
7562 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
"")))
7563 nil nil nil
'switch-to-buffer-other-frame
)))
7566 (defun message-news-other-window (&optional newsgroups subject
)
7567 "Start editing a news article to be sent."
7569 (let ((pop-up-windows t
)
7570 (special-display-buffer-names nil
)
7571 (special-display-regexps nil
)
7572 (same-window-buffer-names nil
)
7573 (same-window-regexps nil
))
7574 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
)))
7575 (let ((message-this-is-news t
))
7576 (message-setup `((Newsgroups .
,(or newsgroups
""))
7577 (Subject .
,(or subject
""))))))
7580 (defun message-news-other-frame (&optional newsgroups subject
)
7581 "Start editing a news article to be sent."
7583 (let ((pop-up-frames t
)
7584 (special-display-buffer-names nil
)
7585 (special-display-regexps nil
)
7586 (same-window-buffer-names nil
)
7587 (same-window-regexps nil
))
7588 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
)))
7589 (let ((message-this-is-news t
))
7590 (message-setup `((Newsgroups .
,(or newsgroups
""))
7591 (Subject .
,(or subject
""))))))
7595 ;; This code should be moved to underline.el (from which it is stolen).
7598 (defun message-bold-region (start end
)
7599 "Bold all nonblank characters in the region.
7600 Works by overstriking characters.
7601 Called from program, takes two arguments START and END
7602 which specify the range to operate on."
7605 (let ((end1 (make-marker)))
7606 (move-marker end1
(max start end
))
7607 (goto-char (min start end
))
7608 (while (< (point) end1
)
7609 (or (looking-at "[_\^@- ]")
7610 (insert (char-after) "\b"))
7611 (forward-char 1)))))
7614 (defun message-unbold-region (start end
)
7615 "Remove all boldness (overstruck characters) in the region.
7616 Called from program, takes two arguments START and END
7617 which specify the range to operate on."
7620 (let ((end1 (make-marker)))
7621 (move-marker end1
(max start end
))
7622 (goto-char (min start end
))
7623 (while (search-forward "\b" end1 t
)
7624 (if (eq (char-after) (char-after (- (point) 2)))
7625 (delete-char -
2))))))
7627 (defun message-exchange-point-and-mark ()
7628 "Exchange point and mark, but don't activate region if it was inactive."
7629 (goto-char (prog1 (mark t
)
7630 (set-marker (mark-marker) (point)))))
7632 (defalias 'message-make-overlay
'make-overlay
)
7633 (defalias 'message-delete-overlay
'delete-overlay
)
7634 (defalias 'message-overlay-put
'overlay-put
)
7635 (defun message-kill-all-overlays ()
7636 (if (featurep 'xemacs
)
7637 (map-extents (lambda (extent ignore
) (delete-extent extent
)))
7638 (mapcar #'delete-overlay
(overlays-in (point-min) (point-max)))))
7640 ;; Support for toolbar
7641 (defvar tool-bar-mode
)
7643 ;; Note: The :set function in the `message-tool-bar*' variables will only
7644 ;; affect _new_ message buffers. We might add a function that walks thru all
7645 ;; message-mode buffers and force the update.
7646 (defun message-tool-bar-update (&optional symbol value
)
7647 "Update message mode toolbar.
7648 Setter function for custom variables."
7649 (setq-default message-tool-bar-map nil
)
7651 ;; When used as ":set" function:
7652 (set-default symbol value
)))
7654 (defcustom message-tool-bar
(if (eq gmm-tool-bar-style
'gnome
)
7655 'message-tool-bar-gnome
7656 'message-tool-bar-retro
)
7657 "Specifies the message mode tool bar.
7659 It can be either a list or a symbol refering to a list. See
7660 `gmm-tool-bar-from-list' for the format of the list. The
7661 default key map is `message-mode-map'.
7663 Pre-defined symbols include `message-tool-bar-gnome' and
7664 `message-tool-bar-retro'."
7665 :type
'(repeat gmm-tool-bar-list-item
)
7666 :type
'(choice (const :tag
"GNOME style" message-tool-bar-gnome
)
7667 (const :tag
"Retro look" message-tool-bar-retro
)
7668 (repeat :tag
"User defined list" gmm-tool-bar-item
)
7670 :version
"23.1" ;; No Gnus
7671 :initialize
'custom-initialize-default
7672 :set
'message-tool-bar-update
7675 (defcustom message-tool-bar-gnome
7676 '((ispell-message "spell" nil
7678 :visible
(or (not (boundp 'flyspell-mode
))
7679 (not flyspell-mode
)))
7680 (flyspell-buffer "spell" t
7682 :visible
(and (boundp 'flyspell-mode
)
7684 :help
"Flyspell whole buffer")
7685 (message-send-and-exit "mail/send" t
:label
"Send")
7686 (message-dont-send "mail/save-draft")
7687 (mml-attach-file "attach" mml-mode-map
:vert-only t
)
7688 (mml-preview "mail/preview" mml-mode-map
)
7689 (mml-secure-message-sign-encrypt "lock" mml-mode-map
:visible nil
)
7690 (message-insert-importance-high "important" nil
:visible nil
)
7691 (message-insert-importance-low "unimportant" nil
:visible nil
)
7692 (message-insert-disposition-notification-to "receipt" nil
:visible nil
))
7693 "List of items for the message tool bar (GNOME style).
7695 See `gmm-tool-bar-from-list' for details on the format of the list."
7696 :type
'(repeat gmm-tool-bar-item
)
7697 :version
"23.1" ;; No Gnus
7698 :initialize
'custom-initialize-default
7699 :set
'message-tool-bar-update
7702 (defcustom message-tool-bar-retro
7703 '(;; Old Emacs 21 icon for consistency.
7704 (message-send-and-exit "gnus/mail-send")
7705 (message-kill-buffer "close")
7706 (message-dont-send "cancel")
7707 (mml-attach-file "attach" mml-mode-map
)
7708 (ispell-message "spell")
7709 (mml-preview "preview" mml-mode-map
)
7710 (message-insert-importance-high "gnus/important")
7711 (message-insert-importance-low "gnus/unimportant")
7712 (message-insert-disposition-notification-to "gnus/receipt"))
7713 "List of items for the message tool bar (retro style).
7715 See `gmm-tool-bar-from-list' for details on the format of the list."
7716 :type
'(repeat gmm-tool-bar-item
)
7717 :version
"23.1" ;; No Gnus
7718 :initialize
'custom-initialize-default
7719 :set
'message-tool-bar-update
7722 (defcustom message-tool-bar-zap-list
7723 '(new-file open-file dired kill-buffer write-file
7724 print-buffer customize help
)
7725 "List of icon items from the global tool bar.
7726 These items are not displayed on the message mode tool bar.
7728 See `gmm-tool-bar-from-list' for the format of the list."
7729 :type
'gmm-tool-bar-zap-list
7730 :version
"23.1" ;; No Gnus
7731 :initialize
'custom-initialize-default
7732 :set
'message-tool-bar-update
7735 (defvar image-load-path
)
7737 (defun message-make-tool-bar (&optional force
)
7738 "Make a message mode tool bar from `message-tool-bar-list'.
7739 When FORCE, rebuild the tool bar."
7740 (when (and (not (featurep 'xemacs
))
7741 (boundp 'tool-bar-mode
)
7743 (or (not message-tool-bar-map
) force
))
7744 (setq message-tool-bar-map
7746 (gmm-image-load-path-for-library "message"
7747 "mail/save-draft.xpm"
7749 (image-load-path (cons (car load-path
)
7750 (when (boundp 'image-load-path
)
7752 (gmm-tool-bar-from-list message-tool-bar
7753 message-tool-bar-zap-list
7754 'message-mode-map
))))
7755 message-tool-bar-map
)
7757 ;;; Group name completion.
7759 (defcustom message-newgroups-header-regexp
7760 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
7761 "Regexp that match headers that lists groups."
7765 (defcustom message-completion-alist
7766 (list (cons message-newgroups-header-regexp
'message-expand-group
)
7767 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name
)
7768 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
7769 . message-expand-name
)
7770 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
7771 . message-expand-name
))
7772 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
7775 :type
'(alist :key-type regexp
:value-type function
))
7777 (defcustom message-expand-name-databases
7779 "List of databases to try for name completion (`message-expand-name').
7780 Each element is a symbol and can be `bbdb' or `eudc'."
7782 :type
'(set (const bbdb
) (const eudc
)))
7784 (defcustom message-tab-body-function nil
7785 "*Function to execute when `message-tab' (TAB) is executed in the body.
7786 If nil, the function bound in `text-mode-map' or `global-map' is executed."
7789 :link
'(custom-manual "(message)Various Commands")
7790 :type
'(choice (const nil
)
7793 (declare-function mail-abbrev-in-expansion-header-p
"mailabbrev" ())
7795 (defun message-tab ()
7796 "Complete names according to `message-completion-alist'.
7797 Execute function specified by `message-tab-body-function' when not in
7801 ((if (and (boundp 'completion-fail-discreetly
)
7802 (fboundp 'completion-at-point
))
7803 (let ((completion-fail-discreetly t
)) (completion-at-point))
7804 (funcall (or (message-completion-function) #'ignore
)))
7805 ;; Completion was performed; nothing else to do.
7807 (message-tab-body-function (funcall message-tab-body-function
))
7808 (t (funcall (or (lookup-key text-mode-map
"\t")
7809 (lookup-key global-map
"\t")
7810 'indent-relative
)))))
7812 (defvar mail-abbrev-mode-regexp
)
7814 (defun message-completion-function ()
7815 (let ((alist message-completion-alist
))
7817 (let ((mail-abbrev-mode-regexp (caar alist
)))
7818 (not (mail-abbrev-in-expansion-header-p))))
7819 (setq alist
(cdr alist
)))
7825 (let ((standard-output (current-buffer)))
7826 (eval '(display-completion-list nil
"")))
7827 (defalias 'message-display-completion-list
'display-completion-list
))
7828 (error ;; Don't use `wrong-number-of-arguments' here because of XEmacs.
7829 (defun message-display-completion-list (completions &optional ignore
)
7830 "Display the list of completions, COMPLETIONS, using `standard-output'."
7831 (display-completion-list completions
)))))
7833 (defun message-expand-group ()
7834 "Expand the group name under point."
7835 (let* ((b (save-excursion
7840 (skip-chars-forward "^:")
7843 (skip-chars-backward "^, \t\n") (point))))
7844 (completion-ignore-case t
)
7845 (e (progn (skip-chars-forward "^,\t\n ") (point)))
7846 (hashtb (and (boundp 'gnus-active-hashtb
) gnus-active-hashtb
)))
7847 (message-completion-in-region e b hashtb
)))
7849 (defalias 'message-completion-in-region
7850 (if (fboundp 'completion-in-region
)
7851 'completion-in-region
7852 (lambda (e b hashtb
)
7853 (let* ((string (buffer-substring b e
))
7854 (completions (all-completions string hashtb
))
7856 (delete-region b
(point))
7858 ((= (length completions
) 1)
7859 (if (string= (car completions
) string
)
7862 (message "Only matching group"))
7863 (insert (car completions
))))
7864 ((and (setq comp
(try-completion string hashtb
))
7865 (not (string= comp string
)))
7870 (message "No matching groups")
7871 (save-selected-window
7872 (pop-to-buffer "*Completions*")
7873 (buffer-disable-undo)
7874 (let ((buffer-read-only nil
))
7876 (let ((standard-output (current-buffer)))
7877 (message-display-completion-list (sort completions
'string
<)
7879 (setq buffer-read-only nil
)
7880 (goto-char (point-min))
7881 (delete-region (point)
7882 (progn (forward-line 3) (point))))))))))))
7884 (defun message-expand-name ()
7885 (cond ((and (memq 'eudc message-expand-name-databases
)
7886 (boundp 'eudc-protocol
)
7888 (eudc-expand-inline))
7889 ((and (memq 'bbdb message-expand-name-databases
)
7890 (fboundp 'bbdb-complete-name
))
7891 (let ((starttick (buffer-modified-tick)))
7892 (or (bbdb-complete-name)
7893 ;; Apparently, bbdb-complete-name can return nil even when
7894 ;; completion took place. So let's double check the buffer was
7896 (/= starttick
(buffer-modified-tick)))))
7902 (defun message-talkative-question (ask question show
&rest text
)
7903 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
7904 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
7905 The following arguments may contain lists of values."
7907 (setq text
(message-flatten-list text
)))
7908 (save-window-excursion
7909 (with-output-to-temp-buffer " *MESSAGE information message*"
7910 (with-current-buffer " *MESSAGE information message*"
7911 (fundamental-mode) ; for Emacs 20.4+
7913 (goto-char (point-min))))
7914 (funcall ask question
))
7915 (funcall ask question
)))
7917 (defun message-flatten-list (list)
7918 "Return a new, flat list that contains all elements of LIST.
7920 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
7923 (apply 'append
(mapcar 'message-flatten-list list
)))
7927 (defun message-generate-new-buffer-clone-locals (name &optional varstr
)
7928 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
7929 Then clone the local variables and values from the old buffer to the
7930 new one, cloning only the locals having a substring matching the
7932 (let ((oldbuf (current-buffer)))
7933 (with-current-buffer (generate-new-buffer name
)
7934 (message-clone-locals oldbuf varstr
)
7937 (defun message-clone-locals (buffer &optional varstr
)
7938 "Clone the local variables from BUFFER to the current buffer."
7939 (let ((locals (with-current-buffer buffer
(buffer-local-variables)))
7940 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address"))
7943 (when (and (consp local
)
7945 (string-match regexp
(symbol-name (car local
)))
7947 (string-match varstr
(symbol-name (car local
)))))
7949 (set (make-local-variable (car local
))
7957 (defun message-encode-message-body ()
7958 (unless message-inhibit-body-encoding
7959 (let ((mail-parse-charset (or mail-parse-charset
7960 message-default-charset
))
7961 (case-fold-search t
)
7962 lines content-type-p
)
7965 (narrow-to-region (point) (point-max))
7966 (let ((new (mml-generate-mime)))
7968 (delete-region (point-min) (point-max))
7970 (goto-char (point-min))
7971 (if (eq (aref new
0) ?
\n)
7973 (search-forward "\n\n")
7974 (setq lines
(buffer-substring (point-min) (1- (point))))
7975 (delete-region (point-min) (point))))))
7977 (message-narrow-to-headers-or-head)
7978 (message-remove-header "Mime-Version")
7979 (goto-char (point-max))
7980 (insert "MIME-Version: 1.0\n")
7983 (setq content-type-p
7985 (re-search-backward "^Content-Type:" nil t
))))
7987 (message-narrow-to-headers-or-head)
7988 (message-remove-first-header "Content-Type")
7989 (message-remove-first-header "Content-Transfer-Encoding"))
7990 ;; We always make sure that the message has a Content-Type
7991 ;; header. This is because some broken MTAs and MUAs get
7992 ;; awfully confused when confronted with a message with a
7993 ;; MIME-Version header and without a Content-Type header. For
7994 ;; instance, Solaris' /usr/bin/mail.
7995 (unless content-type-p
7996 (goto-char (point-min))
7997 ;; For unknown reason, MIME-Version doesn't exist.
7998 (when (re-search-forward "^MIME-Version:" nil t
)
8000 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
8002 (defun message-read-from-minibuffer (prompt &optional initial-contents
)
8003 "Read from the minibuffer while providing abbrev expansion."
8004 (if (fboundp 'mail-abbrevs-setup
)
8005 (let ((mail-abbrev-mode-regexp "")
8006 (minibuffer-setup-hook 'mail-abbrevs-setup
)
8007 (minibuffer-local-map message-minibuffer-local-map
))
8008 (read-from-minibuffer prompt initial-contents
))
8009 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook
)
8010 (minibuffer-local-map message-minibuffer-local-map
))
8011 (read-string prompt initial-contents
))))
8013 (defun message-use-alternative-email-as-from ()
8014 "Set From field of the outgoing message to the first matching
8015 address in `message-alternative-emails', looking at To, Cc and
8016 From headers in the original article."
8017 (require 'mail-utils
)
8018 (let* ((fields '("To" "Cc" "From"))
8021 (mail-strip-quoted-names
8022 (mapconcat 'message-fetch-reply-field fields
","))
8026 (if (string-match message-alternative-emails
(car emails
))
8027 (setq email
(car emails
)
8030 (unless (or (not email
) (equal email user-mail-address
))
8031 (message-remove-header "From")
8032 (goto-char (point-max))
8033 (insert "From: " (let ((user-mail-address email
)) (message-make-from))
8036 (defun message-options-get (symbol)
8037 (cdr (assq symbol message-options
)))
8039 (defun message-options-set (symbol value
)
8040 (let ((the-cons (assq symbol message-options
)))
8043 (setcdr the-cons value
)
8044 (setq message-options
(delq the-cons message-options
)))
8046 (push (cons symbol value
) message-options
))))
8049 (defun message-options-set-recipient ()
8051 (message-narrow-to-headers-or-head)
8052 (message-options-set 'message-sender
8053 (mail-strip-quoted-names
8054 (message-fetch-field "from")))
8055 (message-options-set 'message-recipients
8056 (mail-strip-quoted-names
8057 (let ((to (message-fetch-field "to"))
8058 (cc (message-fetch-field "cc"))
8059 (bcc (message-fetch-field "bcc")))
8062 (if (and to cc
) ", ")
8064 (if (and (or to cc
) bcc
) ", ")
8067 (defun message-hide-headers ()
8068 "Hide headers based on the `message-hidden-headers' variable."
8069 (let ((regexps (if (stringp message-hidden-headers
)
8070 (list message-hidden-headers
)
8071 message-hidden-headers
))
8072 (inhibit-point-motion-hooks t
)
8073 (after-change-functions nil
)
8074 (end-of-headers (point-min)))
8078 (message-narrow-to-headers)
8079 (goto-char (point-min))
8081 (if (not (message-hide-header-p regexps
))
8082 (message-next-header)
8083 (let ((begin (point))
8085 (message-next-header)
8086 (setq header
(buffer-substring begin
(point))
8087 header-len
(- (point) begin
))
8088 (delete-region begin
(point))
8089 (goto-char end-of-headers
)
8091 (setq end-of-headers
8092 (+ end-of-headers header-len
))))))))
8093 (narrow-to-region end-of-headers
(point-max))))
8095 (defun message-hide-header-p (regexps)
8098 (when (eq (car regexps
) 'not
)
8101 (dolist (regexp regexps
)
8102 (setq result
(or result
(looking-at regexp
))))
8107 (declare-function ecomplete-add-item
"ecomplete" (type key text
))
8108 (declare-function ecomplete-save
"ecomplete" ())
8110 (defun message-put-addresses-in-ecomplete ()
8111 (require 'ecomplete
)
8112 (dolist (header '("to" "cc" "from" "reply-to"))
8113 (let ((value (message-field-value header
)))
8114 (dolist (string (mail-header-parse-addresses value
'raw
))
8116 (gnus-replace-in-string
8117 (gnus-replace-in-string string
"^ +\\| +$" "") "\n" ""))
8118 (ecomplete-add-item 'mail
(car (mail-header-parse-address string
))
8122 (autoload 'ecomplete-display-matches
"ecomplete")
8124 (defun message-display-abbrev (&optional choose
)
8125 "Display the next possible abbrev for the text before point."
8126 (interactive (list t
))
8127 (when (and (memq (char-after (point-at-bol)) '(?C ?T ?
\t ?
))
8128 (message-point-in-header-p)
8131 (while (and (memq (char-after) '(?
\t ?
))
8132 (zerop (forward-line -
1))))
8133 (looking-at "To:\\|Cc:")))
8134 (let* ((end (point))
8135 (start (save-excursion
8136 (and (re-search-backward "[\n\t ]" nil t
)
8138 (word (when start
(buffer-substring start end
)))
8139 (match (when (and word
8140 (not (zerop (length word
))))
8141 (ecomplete-display-matches 'mail word choose
))))
8142 (when (and choose match
)
8143 (delete-region start end
)
8146 ;; To send pre-formatted letters like the example below, you can use
8147 ;; `message-send-form-letter':
8148 ;; --8<---------------cut here---------------start------------->8---
8149 ;; To: alice@invalid.invalid
8150 ;; Subject: Verification of your contact information
8151 ;; From: Contact verification <admin@foo.invalid>
8152 ;; --text follows this line--
8154 ;; please verify that your contact information is still valid:
8155 ;; Alice A, A avenue 11, 1111 A town, Austria
8156 ;; ----------next form letter message follows this line----------
8157 ;; To: bob@invalid.invalid
8158 ;; Subject: Verification of your contact information
8159 ;; From: Contact verification <admin@foo.invalid>
8160 ;; --text follows this line--
8162 ;; please verify that your contact information is still valid:
8163 ;; Bob, B street 22, 22222 Be town, Belgium
8164 ;; ----------next form letter message follows this line----------
8165 ;; To: charlie@invalid.invalid
8166 ;; Subject: Verification of your contact information
8167 ;; From: Contact verification <admin@foo.invalid>
8168 ;; --text follows this line--
8170 ;; please verify that your contact information is still valid:
8171 ;; Charlie Chaplin, C plaza 33, 33333 C town, Chile
8172 ;; --8<---------------cut here---------------end--------------->8---
8174 ;; FIXME: What is the most common term (circular letter, form letter, serial
8175 ;; letter, standard letter) for such kind of letter? See also
8176 ;; <http://en.wikipedia.org/wiki/Form_letter>
8178 ;; FIXME: Maybe extent message-mode's font-lock support to recognize
8179 ;; `message-form-letter-separator', i.e. highlight each message like a single
8182 (defcustom message-form-letter-separator
8183 "\n----------next form letter message follows this line----------\n"
8184 "Separator for `message-send-form-letter'."
8185 ;; :group 'message-form-letter
8186 :group
'message-various
8187 :version
"23.1" ;; No Gnus
8190 (defcustom message-send-form-letter-delay
1
8191 "Delay in seconds when sending a message with `message-send-form-letter'.
8192 Only used when `message-send-form-letter' is called with non-nil
8194 ;; :group 'message-form-letter
8195 :group
'message-various
8196 :version
"23.1" ;; No Gnus
8199 (defun message-send-form-letter (&optional force
)
8200 "Sent all form letter messages from current buffer.
8201 Unless FORCE, prompt before sending.
8203 The messages are separated by `message-form-letter-separator'.
8204 Header and body are separated by `mail-header-separator'."
8206 (let ((sent 0) (skipped 0)
8210 (goto-char (point-min))
8213 end
(if (search-forward message-form-letter-separator nil t
)
8214 (- (point) (length message-form-letter-separator
) -
1)
8218 (buffer-substring-no-properties start end
))
8219 (setq buff
(generate-new-buffer "*mail - form letter*"))
8220 (with-current-buffer buff
8223 (setq to
(message-fetch-field "To"))
8224 (switch-to-buffer buff
)
8226 (sit-for message-send-form-letter-delay
))
8228 (y-or-n-p (format "Send message to `%s'? " to
)))
8230 (setq sent
(1+ sent
))
8231 (message-send-and-exit))
8232 (message (format "Message to `%s' skipped." to
))
8233 (setq skipped
(1+ skipped
)))
8234 (when (buffer-live-p buff
)
8235 (kill-buffer buff
))))
8236 (message "%s message(s) sent, %s skipped." sent skipped
)))
8238 (defun message-replace-header (header new-value
&optional after force
)
8239 "Remove HEADER and insert the NEW-VALUE.
8240 If AFTER, insert after this header. If FORCE, insert new field
8241 even if NEW-VALUE is empty."
8242 ;; Similar to `nnheader-replace-header' but for message buffers.
8245 (message-narrow-to-headers)
8246 (message-remove-header header
))
8247 (when (or force
(> (length new-value
) 0))
8249 (message-position-on-field header after
)
8250 (message-position-on-field header
))
8251 (insert new-value
))))
8253 (defcustom message-recipients-without-full-name
8254 (list "ding@gnus.org"
8256 "emacs-devel@gnu.org"
8257 "emacs-pretest-bug@gnu.org"
8258 "bug-gnu-emacs@gnu.org")
8259 "Mail addresses that have no full name.
8260 Used in `message-simplify-recipients'."
8261 ;; Maybe the addresses could be extracted from
8262 ;; `gnus-parameter-to-list-alist'?
8263 :type
'(choice (const :tag
"None" nil
)
8265 :version
"23.1" ;; No Gnus
8266 :group
'message-headers
)
8268 (defun message-simplify-recipients ()
8270 (dolist (hdr '("Cc" "To"))
8271 (message-replace-header
8275 (if (and message-recipients-without-full-name
8277 (regexp-opt message-recipients-without-full-name
)
8281 (message-make-from (car addrcomp
) (cadr addrcomp
))
8283 (when (message-fetch-field hdr
)
8284 (mail-extract-address-components
8285 (message-fetch-field hdr
) t
))
8288 (when (featurep 'xemacs
)
8289 (require 'messagexmas
)
8290 (message-xmas-redefine))
8294 (run-hooks 'message-load-hook
)
8297 ;; coding: iso-8859-1
8300 ;;; message.el ends here