1 ;;; message.el --- composing mail and news messages
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006 Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: mail, news
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
28 ;; This mode provides mail-sending facilities from within Emacs. It
29 ;; consists mainly of large chunks of code from the sendmail.el,
30 ;; gnus-msg.el and rnewspost.el files.
36 (defvar gnus-message-group-art
)
37 (defvar gnus-list-identifiers
)) ; gnus-sum is required where necessary
41 ;; This is apparently necessary even though things are autoloaded.
42 ;; Because we dynamically bind mail-abbrev-mode-regexp, we'd better
43 ;; require mailabbrev here.
44 (if (featurep 'xemacs
)
45 (require 'mail-abbrevs
)
46 (require 'mailabbrev
))
51 (autoload 'gnus-find-method-for-group
"gnus")
52 (autoload 'nnvirtual-find-group-art
"nnvirtual")
53 (autoload 'gnus-group-decoded-name
"gnus-group"))
55 (defgroup message
'((user-mail-address custom-variable
)
56 (user-full-name custom-variable
))
57 "Mail and news message composing."
58 :link
'(custom-manual "(message)Top")
62 (put 'user-mail-address
'custom-type
'string
)
63 (put 'user-full-name
'custom-type
'string
)
65 (defgroup message-various nil
66 "Various Message Variables."
67 :link
'(custom-manual "(message)Various Message Variables")
70 (defgroup message-buffers nil
72 :link
'(custom-manual "(message)Message Buffers")
75 (defgroup message-sending nil
77 :link
'(custom-manual "(message)Sending Variables")
80 (defgroup message-interface nil
82 :link
'(custom-manual "(message)Interface")
85 (defgroup message-forwarding nil
87 :link
'(custom-manual "(message)Forwarding")
88 :group
'message-interface
)
90 (defgroup message-insertion nil
92 :link
'(custom-manual "(message)Insertion")
95 (defgroup message-headers nil
97 :link
'(custom-manual "(message)Message Headers")
100 (defgroup message-news nil
101 "Composing News Messages."
104 (defgroup message-mail nil
105 "Composing Mail Messages."
108 (defgroup message-faces nil
109 "Faces used for message composing."
113 (defcustom message-directory
"~/Mail/"
114 "*Directory from which all other mail file variables are derived."
115 :group
'message-various
118 (defcustom message-max-buffers
10
119 "*How many buffers to keep before starting to kill them off."
120 :group
'message-buffers
123 (defcustom message-send-rename-function nil
124 "Function called to rename the buffer after sending it."
125 :group
'message-buffers
126 :type
'(choice function
(const nil
)))
128 (defcustom message-fcc-handler-function
'message-output
129 "*A function called to save outgoing articles.
130 This function will be called with the name of the file to store the
131 article in. The default function is `message-output' which saves in Unix
133 :type
'(radio (function-item message-output
)
134 (function :tag
"Other"))
135 :group
'message-sending
)
137 (defcustom message-fcc-externalize-attachments nil
138 "If non-nil, attachments are included as external parts in Fcc copies."
141 :group
'message-sending
)
143 (defcustom message-courtesy-message
144 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
145 "*This is inserted at the start of a mailed copy of a posted message.
146 If the string contains the format spec \"%s\", the Newsgroups
147 the article has been posted to will be inserted there.
148 If this variable is nil, no such courtesy message will be added."
149 :group
'message-sending
150 :type
'(radio string
(const nil
)))
152 (defcustom message-ignored-bounced-headers
153 "^\\(Received\\|Return-Path\\|Delivered-To\\):"
154 "*Regexp that matches headers to be removed in resent bounced mail."
155 :group
'message-interface
159 (defcustom message-from-style
'default
160 "*Specifies how \"From\" headers look.
162 If nil, they contain just the return address like:
164 If `parens', they look like:
165 king@grassland.com (Elvis Parsley)
166 If `angles', they look like:
167 Elvis Parsley <king@grassland.com>
169 Otherwise, most addresses look like `angles', but they look like
170 `parens' if `angles' would need quoting and `parens' would not."
171 :type
'(choice (const :tag
"simple" nil
)
175 :group
'message-headers
)
177 (defcustom message-insert-canlock t
178 "Whether to insert a Cancel-Lock header in news postings."
180 :group
'message-headers
183 (defcustom message-syntax-checks
184 (if message-insert-canlock
'((sender . disabled
)) nil
)
185 ;; Guess this one shouldn't be easy to customize...
186 "*Controls what syntax checks should not be performed on outgoing posts.
187 To disable checking of long signatures, for instance, add
188 `(signature . disabled)' to this list.
190 Don't touch this variable unless you really know what you're doing.
192 Checks include `subject-cmsg', `multiple-headers', `sendsys',
193 `message-id', `from', `long-lines', `control-chars', `size',
194 `new-text', `quoting-style', `redirected-followup', `signature',
195 `approved', `sender', `empty', `empty-headers', `message-id', `from',
196 `subject', `shorten-followup-to', `existing-newsgroups',
197 `buffer-file-name', `unchanged', `newsgroups', `reply-to',
198 `continuation-headers', `long-header-lines', `invisible-text' and
201 :type
'(repeat sexp
)) ; Fixme: improve this
203 (defcustom message-required-headers
'((optional . References
)
205 "*Headers to be generated or prompted for when sending a message.
206 Also see `message-required-news-headers' and
207 `message-required-mail-headers'."
210 :group
'message-headers
211 :link
'(custom-manual "(message)Message Headers")
212 :type
'(repeat sexp
))
214 (defcustom message-draft-headers
'(References From
)
215 "*Headers to be generated when saving a draft message."
218 :group
'message-headers
219 :link
'(custom-manual "(message)Message Headers")
220 :type
'(repeat sexp
))
222 (defcustom message-required-news-headers
223 '(From Newsgroups Subject Date Message-ID
224 (optional . Organization
)
225 (optional . User-Agent
))
226 "*Headers to be generated or prompted for when posting an article.
227 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
228 Message-ID. Organization, Lines, In-Reply-To, Expires, and
229 User-Agent are optional. If don't you want message to insert some
230 header, remove it from this list."
232 :group
'message-headers
233 :link
'(custom-manual "(message)Message Headers")
234 :type
'(repeat sexp
))
236 (defcustom message-required-mail-headers
237 '(From Subject Date
(optional . In-Reply-To
) Message-ID
238 (optional . User-Agent
))
239 "*Headers to be generated or prompted for when mailing a message.
240 It is recommended that From, Date, To, Subject and Message-ID be
241 included. Organization and User-Agent are optional."
243 :group
'message-headers
244 :link
'(custom-manual "(message)Message Headers")
245 :type
'(repeat sexp
))
247 (defcustom message-deletable-headers
'(Message-ID Date Lines
)
248 "Headers to be deleted if they already exist and were generated by message previously."
249 :group
'message-headers
250 :link
'(custom-manual "(message)Message Headers")
253 (defcustom message-ignored-news-headers
254 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
255 "*Regexp of headers to be removed unconditionally before posting."
257 :group
'message-headers
258 :link
'(custom-manual "(message)Message Headers")
259 :type
'(repeat :value-to-internal
(lambda (widget value
)
260 (custom-split-regexp-maybe value
))
261 :match
(lambda (widget value
)
263 (widget-editable-list-match widget value
)))
266 (defcustom message-ignored-mail-headers
267 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
268 "*Regexp of headers to be removed unconditionally before mailing."
270 :group
'message-headers
271 :link
'(custom-manual "(message)Mail Headers")
274 (defcustom message-ignored-supersedes-headers
"^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|^X-Trace:\\|^X-Complaints-To:\\|Return-Path:\\|^Supersedes:\\|^NNTP-Posting-Date:\\|^X-Trace:\\|^X-Complaints-To:\\|^Cancel-Lock:\\|^Cancel-Key:\\|^X-Hashcash:\\|^X-Payment:"
275 "*Header lines matching this regexp will be deleted before posting.
276 It's best to delete old Path and Date headers before posting to avoid
278 :group
'message-interface
279 :link
'(custom-manual "(message)Superseding")
280 :type
'(repeat :value-to-internal
(lambda (widget value
)
281 (custom-split-regexp-maybe value
))
282 :match
(lambda (widget value
)
284 (widget-editable-list-match widget value
)))
287 (defcustom message-subject-re-regexp
288 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)*:[ \t]*\\)*[ \t]*"
289 "*Regexp matching \"Re: \" in the subject line."
290 :group
'message-various
291 :link
'(custom-manual "(message)Message Headers")
294 ;;; Start of variables adopted from `message-utils.el'.
296 (defcustom message-subject-trailing-was-query
'ask
297 "*What to do with trailing \"(was: <old subject>)\" in subject lines.
298 If nil, leave the subject unchanged. If it is the symbol `ask', query
299 the user what do do. In this case, the subject is matched against
300 `message-subject-trailing-was-ask-regexp'. If
301 `message-subject-trailing-was-query' is t, always strip the trailing
302 old subject. In this case, `message-subject-trailing-was-regexp' is
305 :type
'(choice (const :tag
"never" nil
)
306 (const :tag
"always strip" t
)
308 :link
'(custom-manual "(message)Message Headers")
309 :group
'message-various
)
311 (defcustom message-subject-trailing-was-ask-regexp
312 "[ \t]*\\([[(]+[Ww][Aa][Ss][ \t]*.*[\])]+\\)"
313 "*Regexp matching \"(was: <old subject>)\" in the subject line.
315 The function `message-strip-subject-trailing-was' uses this regexp if
316 `message-subject-trailing-was-query' is set to the symbol `ask'. If
317 the variable is t instead of `ask', use
318 `message-subject-trailing-was-regexp' instead.
320 It is okay to create some false positives here, as the user is asked."
322 :group
'message-various
323 :link
'(custom-manual "(message)Message Headers")
326 (defcustom message-subject-trailing-was-regexp
327 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
328 "*Regexp matching \"(was: <old subject>)\" in the subject line.
330 If `message-subject-trailing-was-query' is set to t, the subject is
331 matched against `message-subject-trailing-was-regexp' in
332 `message-strip-subject-trailing-was'. You should use a regexp creating very
333 few false positives here."
335 :group
'message-various
336 :link
'(custom-manual "(message)Message Headers")
339 ;;; marking inserted text
341 (defcustom message-mark-insert-begin
342 "--8<---------------cut here---------------start------------->8---\n"
343 "How to mark the beginning of some inserted text."
346 :link
'(custom-manual "(message)Insertion Variables")
347 :group
'message-various
)
349 (defcustom message-mark-insert-end
350 "--8<---------------cut here---------------end--------------->8---\n"
351 "How to mark the end of some inserted text."
354 :link
'(custom-manual "(message)Insertion Variables")
355 :group
'message-various
)
357 (defcustom message-archive-header
"X-No-Archive: Yes\n"
358 "Header to insert when you don't want your article to be archived.
359 Archives \(such as groups.google.com\) respect this header."
362 :link
'(custom-manual "(message)Header Commands")
363 :group
'message-various
)
365 (defcustom message-archive-note
366 "X-No-Archive: Yes - save http://groups.google.com/"
367 "Note to insert why you wouldn't want this posting archived.
368 If nil, don't insert any text in the body."
370 :type
'(radio string
(const nil
))
371 :link
'(custom-manual "(message)Header Commands")
372 :group
'message-various
)
374 ;;; Crossposts and Followups
375 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
376 ;; new suggestions by R. Weikusat <rw at another.de>
378 (defvar message-cross-post-old-target nil
379 "Old target for cross-posts or follow-ups.")
380 (make-variable-buffer-local 'message-cross-post-old-target
)
382 (defcustom message-cross-post-default t
383 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
384 If nil, `message-cross-post-followup-to' will only do a followup. Note that
385 you can explicitly override this setting by calling
386 `message-cross-post-followup-to' with a prefix."
389 :group
'message-various
)
391 (defcustom message-cross-post-note
"Crosspost & Followup-To: "
392 "Note to insert before signature to notify of cross-post and follow-up."
395 :group
'message-various
)
397 (defcustom message-followup-to-note
"Followup-To: "
398 "Note to insert before signature to notify of follow-up only."
401 :group
'message-various
)
403 (defcustom message-cross-post-note-function
'message-cross-post-insert-note
404 "Function to use to insert note about Crosspost or Followup-To.
405 The function will be called with four arguments. The function should not only
406 insert a note, but also ensure old notes are deleted. See the documentation
407 for `message-cross-post-insert-note'."
410 :group
'message-various
)
412 ;;; End of variables adopted from `message-utils.el'.
415 (defcustom message-signature-separator
"^-- *$"
416 "Regexp matching the signature separator."
418 :link
'(custom-manual "(message)Various Message Variables")
419 :group
'message-various
)
421 (defcustom message-elide-ellipsis
"\n[...]\n\n"
422 "*The string which is inserted for elided text."
424 :link
'(custom-manual "(message)Various Commands")
425 :group
'message-various
)
427 (defcustom message-interactive t
428 "Non-nil means when sending a message wait for and display errors.
429 nil means let mailer mail back a message to report errors."
430 :group
'message-sending
432 :link
'(custom-manual "(message)Sending Variables")
435 (defcustom message-generate-new-buffers
'unique
436 "*Non-nil means create a new message buffer whenever `message-setup' is called.
437 If this is a function, call that function with three parameters: The type,
438 the to address and the group name. (Any of these may be nil.) The function
439 should return the new buffer name."
440 :group
'message-buffers
441 :link
'(custom-manual "(message)Message Buffers")
442 :type
'(choice (const :tag
"off" nil
)
443 (const :tag
"unique" unique
)
444 (const :tag
"unsent" unsent
)
447 (defcustom message-kill-buffer-on-exit nil
448 "*Non-nil means that the message buffer will be killed after sending a message."
449 :group
'message-buffers
450 :link
'(custom-manual "(message)Message Buffers")
454 (defvar gnus-local-organization
))
455 (defcustom message-user-organization
456 (or (and (boundp 'gnus-local-organization
)
457 (stringp gnus-local-organization
)
458 gnus-local-organization
)
459 (getenv "ORGANIZATION")
461 "*String to be used as an Organization header.
462 If t, use `message-user-organization-file'."
463 :group
'message-headers
464 :type
'(choice string
465 (const :tag
"consult file" t
)))
468 (defcustom message-user-organization-file
"/usr/lib/news/organization"
469 "*Local news organization file."
471 :link
'(custom-manual "(message)News Headers")
472 :group
'message-headers
)
474 (defcustom message-make-forward-subject-function
475 #'message-forward-subject-name-subject
476 "*List of functions called to generate subject headers for forwarded messages.
477 The subject generated by the previous function is passed into each
480 The provided functions are:
482 * `message-forward-subject-author-subject' Source of article (author or
483 newsgroup), in brackets followed by the subject
484 * `message-forward-subject-name-subject' Source of article (name of author
485 or newsgroup), in brackets followed by the subject
486 * `message-forward-subject-fwd' Subject of article with 'Fwd:' prepended
488 :group
'message-forwarding
489 :link
'(custom-manual "(message)Forwarding")
490 :type
'(radio (function-item message-forward-subject-author-subject
)
491 (function-item message-forward-subject-fwd
)
492 (function-item message-forward-subject-name-subject
)
493 (repeat :tag
"List of functions" function
)))
495 (defcustom message-forward-as-mime t
496 "*Non-nil means forward messages as an inline/rfc822 MIME section.
497 Otherwise, directly inline the old message in the forwarded message."
499 :group
'message-forwarding
500 :link
'(custom-manual "(message)Forwarding")
503 (defcustom message-forward-show-mml
'best
504 "*Non-nil means show forwarded messages as MML (decoded from MIME).
505 Otherwise, forwarded messages are unchanged.
506 Can also be the symbol `best' to indicate that MML should be
507 used, except when it is a bad idea to use MML. One example where
508 it is a bad idea is when forwarding a signed or encrypted
509 message, because converting MIME to MML would invalidate the
512 :group
'message-forwarding
513 :type
'(choice (const :tag
"use MML" t
)
514 (const :tag
"don't use MML " nil
)
515 (const :tag
"use MML when appropriate" best
)))
517 (defcustom message-forward-before-signature t
518 "*Non-nil means put forwarded message before signature, else after."
519 :group
'message-forwarding
522 (defcustom message-wash-forwarded-subjects nil
523 "*Non-nil means try to remove as much cruft as possible from the subject.
524 Done before generating the new subject of a forward."
525 :group
'message-forwarding
526 :link
'(custom-manual "(message)Forwarding")
529 (defcustom message-ignored-resent-headers
"^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From "
530 "*All headers that match this regexp will be deleted when resending a message."
531 :group
'message-interface
532 :link
'(custom-manual "(message)Resending")
533 :type
'(repeat :value-to-internal
(lambda (widget value
)
534 (custom-split-regexp-maybe value
))
535 :match
(lambda (widget value
)
537 (widget-editable-list-match widget value
)))
540 (defcustom message-forward-ignored-headers
"^Content-Transfer-Encoding:\\|^X-Gnus"
541 "*All headers that match this regexp will be deleted when forwarding a message."
543 :group
'message-forwarding
544 :type
'(repeat :value-to-internal
(lambda (widget value
)
545 (custom-split-regexp-maybe value
))
546 :match
(lambda (widget value
)
548 (widget-editable-list-match widget value
)))
551 (defcustom message-ignored-cited-headers
"."
552 "*Delete these headers from the messages you yank."
553 :group
'message-insertion
554 :link
'(custom-manual "(message)Insertion Variables")
557 (defcustom message-cite-prefix-regexp
558 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
559 "\\([ \t]*[-_.[:word:]]+>+\\|[ \t]*[]>|}+]\\)+"
560 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
561 (let ((old-table (syntax-table))
562 non-word-constituents
)
563 (set-syntax-table text-mode-syntax-table
)
564 (setq non-word-constituents
566 (if (string-match "\\w" "-") "" "-")
567 (if (string-match "\\w" "_") "" "_")
568 (if (string-match "\\w" ".") "" ".")))
569 (set-syntax-table old-table
)
570 (if (equal non-word-constituents
"")
571 "\\([ \t]*\\(\\w\\)+>+\\|[ \t]*[]>|}+]\\)+"
572 (concat "\\([ \t]*\\(\\w\\|["
573 non-word-constituents
574 "]\\)+>+\\|[ \t]*[]>|}+]\\)+"))))
575 "*Regexp matching the longest possible citation prefix on a line."
577 :group
'message-insertion
578 :link
'(custom-manual "(message)Insertion Variables")
581 (defcustom message-cancel-message
"I am canceling my own article.\n"
582 "Message to be inserted in the cancel message."
583 :group
'message-interface
584 :link
'(custom-manual "(message)Canceling News")
587 ;; Useful to set in site-init.el
589 (defcustom message-send-mail-function
'message-send-mail-with-sendmail
590 "Function to call to send the current buffer as mail.
591 The headers should be delimited by a line whose contents match the
592 variable `mail-header-separator'.
594 Valid values include `message-send-mail-with-sendmail' (the default),
595 `message-send-mail-with-mh', `message-send-mail-with-qmail',
596 `message-smtpmail-send-it', `smtpmail-send-it' and `feedmail-send-it'.
598 See also `send-mail-function'."
599 :type
'(radio (function-item message-send-mail-with-sendmail
)
600 (function-item message-send-mail-with-mh
)
601 (function-item message-send-mail-with-qmail
)
602 (function-item message-smtpmail-send-it
)
603 (function-item smtpmail-send-it
)
604 (function-item feedmail-send-it
)
605 (function :tag
"Other"))
606 :group
'message-sending
607 :link
'(custom-manual "(message)Mail Variables")
608 :group
'message-mail
)
610 (defcustom message-send-news-function
'message-send-news
611 "Function to call to send the current buffer as news.
612 The headers should be delimited by a line whose contents match the
613 variable `mail-header-separator'."
614 :group
'message-sending
616 :link
'(custom-manual "(message)News Variables")
619 (defcustom message-reply-to-function nil
620 "If non-nil, function that should return a list of headers.
621 This function should pick out addresses from the To, Cc, and From headers
622 and respond with new To and Cc headers."
623 :group
'message-interface
624 :link
'(custom-manual "(message)Reply")
625 :type
'(choice function
(const nil
)))
627 (defcustom message-wide-reply-to-function nil
628 "If non-nil, function that should return a list of headers.
629 This function should pick out addresses from the To, Cc, and From headers
630 and respond with new To and Cc headers."
631 :group
'message-interface
632 :link
'(custom-manual "(message)Wide Reply")
633 :type
'(choice function
(const nil
)))
635 (defcustom message-followup-to-function nil
636 "If non-nil, function that should return a list of headers.
637 This function should pick out addresses from the To, Cc, and From headers
638 and respond with new To and Cc headers."
639 :group
'message-interface
640 :link
'(custom-manual "(message)Followup")
641 :type
'(choice function
(const nil
)))
643 (defcustom message-use-followup-to
'ask
644 "*Specifies what to do with Followup-To header.
645 If nil, always ignore the header. If it is t, use its value, but
646 query before using the \"poster\" value. If it is the symbol `ask',
647 always query the user whether to use the value. If it is the symbol
648 `use', always use the value."
649 :group
'message-interface
650 :link
'(custom-manual "(message)Followup")
651 :type
'(choice (const :tag
"ignore" nil
)
652 (const :tag
"use & query" t
)
656 (defcustom message-use-mail-followup-to
'use
657 "*Specifies what to do with Mail-Followup-To header.
658 If nil, always ignore the header. If it is the symbol `ask', always
659 query the user whether to use the value. If it is the symbol `use',
660 always use the value."
662 :group
'message-interface
663 :link
'(custom-manual "(message)Mailing Lists")
664 :type
'(choice (const :tag
"ignore" nil
)
668 (defcustom message-subscribed-address-functions nil
669 "*Specifies functions for determining list subscription.
670 If nil, do not attempt to determine list subscription with functions.
671 If non-nil, this variable contains a list of functions which return
672 regular expressions to match lists. These functions can be used in
673 conjunction with `message-subscribed-regexps' and
674 `message-subscribed-addresses'."
676 :group
'message-interface
677 :link
'(custom-manual "(message)Mailing Lists")
678 :type
'(repeat sexp
))
680 (defcustom message-subscribed-address-file nil
681 "*A file containing addresses the user is subscribed to.
682 If nil, do not look at any files to determine list subscriptions. If
683 non-nil, each line of this file should be a mailing list address."
685 :group
'message-interface
686 :link
'(custom-manual "(message)Mailing Lists")
687 :type
'(radio file
(const nil
)))
689 (defcustom message-subscribed-addresses nil
690 "*Specifies a list of addresses the user is subscribed to.
691 If nil, do not use any predefined list subscriptions. This list of
692 addresses can be used in conjunction with
693 `message-subscribed-address-functions' and `message-subscribed-regexps'."
695 :group
'message-interface
696 :link
'(custom-manual "(message)Mailing Lists")
697 :type
'(repeat string
))
699 (defcustom message-subscribed-regexps nil
700 "*Specifies a list of addresses the user is subscribed to.
701 If nil, do not use any predefined list subscriptions. This list of
702 regular expressions can be used in conjunction with
703 `message-subscribed-address-functions' and `message-subscribed-addresses'."
705 :group
'message-interface
706 :link
'(custom-manual "(message)Mailing Lists")
707 :type
'(repeat regexp
))
709 (defcustom message-allow-no-recipients
'ask
710 "Specifies what to do when there are no recipients other than Gcc/Fcc.
711 If it is the symbol `always', the posting is allowed. If it is the
712 symbol `never', the posting is not allowed. If it is the symbol
713 `ask', you are prompted."
715 :group
'message-interface
716 :link
'(custom-manual "(message)Message Headers")
717 :type
'(choice (const always
)
721 (defcustom message-sendmail-f-is-evil nil
722 "*Non-nil means don't add \"-f username\" to the sendmail command line.
723 Doing so would be even more evil than leaving it out."
724 :group
'message-sending
725 :link
'(custom-manual "(message)Mail Variables")
728 (defcustom message-sendmail-envelope-from nil
729 "*Envelope-from when sending mail with sendmail.
730 If this is nil, use `user-mail-address'. If it is the symbol
731 `header', use the From: header of the message."
733 :type
'(choice (string :tag
"From name")
734 (const :tag
"Use From: header from message" header
)
735 (const :tag
"Use `user-mail-address'" nil
))
736 :link
'(custom-manual "(message)Mail Variables")
737 :group
'message-sending
)
739 ;; qmail-related stuff
740 (defcustom message-qmail-inject-program
"/var/qmail/bin/qmail-inject"
741 "Location of the qmail-inject program."
742 :group
'message-sending
743 :link
'(custom-manual "(message)Mail Variables")
746 (defcustom message-qmail-inject-args nil
747 "Arguments passed to qmail-inject programs.
748 This should be a list of strings, one string for each argument. It
749 may also be a function.
751 For e.g., if you wish to set the envelope sender address so that bounces
752 go to the right place or to deal with listserv's usage of that address, you
753 might set this variable to '(\"-f\" \"you@some.where\")."
754 :group
'message-sending
755 :link
'(custom-manual "(message)Mail Variables")
756 :type
'(choice (function)
759 (defvar message-cater-to-broken-inn t
760 "Non-nil means Gnus should not fold the `References' header.
761 Folding `References' makes ancient versions of INN create incorrect
765 (defvar gnus-post-method
)
766 (defvar gnus-select-method
))
767 (defcustom message-post-method
768 (cond ((and (boundp 'gnus-post-method
)
769 (listp gnus-post-method
)
772 ((boundp 'gnus-select-method
)
775 "*Method used to post news.
776 Note that when posting from inside Gnus, for instance, this
777 variable isn't used."
779 :group
'message-sending
780 ;; This should be the `gnus-select-method' widget, but that might
781 ;; create a dependence to `gnus.el'.
784 ;; FIXME: This should be a temporary workaround until someone implements a
785 ;; proper solution. If a crash happens while replying, the auto-save file
786 ;; will *not* have a `References:' header if `message-generate-headers-first'
787 ;; is nil. See: http://article.gmane.org/gmane.emacs.gnus.general/51138
788 (defcustom message-generate-headers-first
'(references)
789 "Which headers should be generated before starting to compose a message.
790 If t, generate all required headers. This can also be a list of headers to
791 generate. The variables `message-required-news-headers' and
792 `message-required-mail-headers' specify which headers to generate.
794 Note that the variable `message-deletable-headers' specifies headers which
795 are to be deleted and then re-generated before sending, so this variable
796 will not have a visible effect for those headers."
797 :group
'message-headers
798 :link
'(custom-manual "(message)Message Headers")
799 :type
'(choice (const :tag
"None" nil
)
800 (const :tag
"References" '(references))
802 (repeat (sexp :tag
"Header"))))
804 (defcustom message-setup-hook nil
805 "Normal hook, run each time a new outgoing message is initialized.
806 The function `message-setup' runs this hook."
807 :group
'message-various
808 :link
'(custom-manual "(message)Various Message Variables")
811 (defcustom message-cancel-hook nil
812 "Hook run when cancelling articles."
813 :group
'message-various
814 :link
'(custom-manual "(message)Various Message Variables")
817 (defcustom message-signature-setup-hook nil
818 "Normal hook, run each time a new outgoing message is initialized.
819 It is run after the headers have been inserted and before
820 the signature is inserted."
821 :group
'message-various
822 :link
'(custom-manual "(message)Various Message Variables")
825 (defcustom message-mode-hook nil
826 "Hook run in message mode buffers."
827 :group
'message-various
830 (defcustom message-header-hook nil
831 "Hook run in a message mode buffer narrowed to the headers."
832 :group
'message-various
835 (defcustom message-header-setup-hook nil
836 "Hook called narrowed to the headers when setting up a message buffer."
837 :group
'message-various
838 :link
'(custom-manual "(message)Various Message Variables")
841 (defcustom message-minibuffer-local-map
842 (let ((map (make-sparse-keymap 'message-minibuffer-local-map
)))
843 (set-keymap-parent map minibuffer-local-map
)
845 "Keymap for `message-read-from-minibuffer'."
847 :group
'message-various
)
850 (defcustom message-citation-line-function
'message-insert-citation-line
851 "*Function called to insert the \"Whomever writes:\" line.
853 Note that Gnus provides a feature where the reader can click on
854 `writes:' to hide the cited text. If you change this line too much,
855 people who read your message will have to change their Gnus
856 configuration. See the variable `gnus-cite-attribution-suffix'."
858 :link
'(custom-manual "(message)Insertion Variables")
859 :group
'message-insertion
)
862 (defcustom message-yank-prefix
"> "
863 "*Prefix inserted on the lines of yanked messages.
864 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
865 See also `message-yank-cited-prefix'."
867 :link
'(custom-manual "(message)Insertion Variables")
868 :group
'message-insertion
)
870 (defcustom message-yank-cited-prefix
">"
871 "*Prefix inserted on cited or empty lines of yanked messages.
872 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
873 See also `message-yank-prefix'."
876 :link
'(custom-manual "(message)Insertion Variables")
877 :group
'message-insertion
)
879 (defcustom message-indentation-spaces
3
880 "*Number of spaces to insert at the beginning of each cited line.
881 Used by `message-yank-original' via `message-yank-cite'."
882 :group
'message-insertion
883 :link
'(custom-manual "(message)Insertion Variables")
887 (defcustom message-cite-function
'message-cite-original
888 "*Function for citing an original message.
889 Predefined functions include `message-cite-original' and
890 `message-cite-original-without-signature'.
891 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
892 :type
'(radio (function-item message-cite-original
)
893 (function-item message-cite-original-without-signature
)
894 (function-item sc-cite-original
)
895 (function :tag
"Other"))
896 :link
'(custom-manual "(message)Insertion Variables")
897 :group
'message-insertion
)
900 (defcustom message-indent-citation-function
'message-indent-citation
901 "*Function for modifying a citation just inserted in the mail buffer.
902 This can also be a list of functions. Each function can find the
903 citation between (point) and (mark t). And each function should leave
904 point and mark around the citation text as modified."
906 :link
'(custom-manual "(message)Insertion Variables")
907 :group
'message-insertion
)
910 (defcustom message-signature t
911 "*String to be inserted at the end of the message buffer.
912 If t, the `message-signature-file' file will be inserted instead.
913 If a function, the result from the function will be used instead.
914 If a form, the result from the form will be used instead."
916 :link
'(custom-manual "(message)Insertion Variables")
917 :group
'message-insertion
)
920 (defcustom message-signature-file
"~/.signature"
921 "*Name of file containing the text inserted at end of message buffer.
922 Ignored if the named file doesn't exist.
923 If nil, don't insert a signature."
924 :type
'(choice file
(const :tags
"None" nil
))
925 :link
'(custom-manual "(message)Insertion Variables")
926 :group
'message-insertion
)
929 (defcustom message-signature-insert-empty-line t
930 "*If non-nil, insert an empty line before the signature separator."
933 :link
'(custom-manual "(message)Insertion Variables")
934 :group
'message-insertion
)
936 (defcustom message-distribution-function nil
937 "*Function called to return a Distribution header."
939 :group
'message-headers
940 :link
'(custom-manual "(message)News Headers")
941 :type
'(choice function
(const nil
)))
943 (defcustom message-expires
14
944 "Number of days before your article expires."
946 :group
'message-headers
947 :link
'(custom-manual "(message)News Headers")
950 (defcustom message-user-path nil
951 "If nil, use the NNTP server name in the Path header.
952 If stringp, use this; if non-nil, use no host name (user name only)."
954 :group
'message-headers
955 :link
'(custom-manual "(message)News Headers")
956 :type
'(choice (const :tag
"nntp" nil
)
958 (sexp :tag
"none" :format
"%t" t
)))
960 (defvar message-reply-buffer nil
)
961 (defvar message-reply-headers nil
962 "The headers of the current replied article.
963 It is a vector of the following headers:
964 \[number subject from date id references chars lines xref extra].")
965 (defvar message-newsreader nil
)
966 (defvar message-mailer nil
)
967 (defvar message-sent-message-via nil
)
968 (defvar message-checksum nil
)
969 (defvar message-send-actions nil
970 "A list of actions to be performed upon successful sending of a message.")
971 (defvar message-exit-actions nil
972 "A list of actions to be performed upon exiting after sending a message.")
973 (defvar message-kill-actions nil
974 "A list of actions to be performed before killing a message buffer.")
975 (defvar message-postpone-actions nil
976 "A list of actions to be performed after postponing a message.")
978 (define-widget 'message-header-lines
'text
979 "All header lines must be LFD terminated."
980 :format
"%{%t%}:%n%v"
982 :error
"All header lines must be newline terminated")
984 (defcustom message-default-headers
""
985 "*A string containing header lines to be inserted in outgoing messages.
986 It is inserted before you edit the message, so you can edit or delete
988 :group
'message-headers
989 :link
'(custom-manual "(message)Message Headers")
990 :type
'message-header-lines
)
992 (defcustom message-default-mail-headers
""
993 "*A string of header lines to be inserted in outgoing mails."
994 :group
'message-headers
996 :link
'(custom-manual "(message)Mail Headers")
997 :type
'message-header-lines
)
999 (defcustom message-default-news-headers
""
1000 "*A string of header lines to be inserted in outgoing news articles."
1001 :group
'message-headers
1002 :group
'message-news
1003 :link
'(custom-manual "(message)News Headers")
1004 :type
'message-header-lines
)
1006 ;; Note: could use /usr/ucb/mail instead of sendmail;
1007 ;; options -t, and -v if not interactive.
1008 (defcustom message-mailer-swallows-blank-line
1009 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1010 system-configuration
)
1011 (file-readable-p "/etc/sendmail.cf")
1012 (let ((buffer (get-buffer-create " *temp*")))
1016 (insert-file-contents "/etc/sendmail.cf")
1017 (goto-char (point-min))
1018 (let ((case-fold-search nil
))
1019 (re-search-forward "^OR\\>" nil t
)))
1020 (kill-buffer buffer
))))
1021 ;; According to RFC822, "The field-name must be composed of printable
1022 ;; ASCII characters (i. e., characters that have decimal values between
1023 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1025 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1026 "*Set this non-nil if the system's mailer runs the header and body together.
1027 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1028 The value should be an expression to test whether the problem will
1030 :group
'message-sending
1031 :link
'(custom-manual "(message)Mail Variables")
1035 (define-mail-user-agent 'message-user-agent
1036 'message-mail
'message-send-and-exit
1037 'message-kill-buffer
'message-send-hook
)
1039 (defvar message-mh-deletable-headers
'(Message-ID Date Lines Sender
)
1040 "If non-nil, delete the deletable headers before feeding to mh.")
1042 (defvar message-send-method-alist
1043 '((news message-news-p message-send-via-news
)
1044 (mail message-mail-p message-send-via-mail
))
1045 "Alist of ways to send outgoing messages.
1046 Each element has the form
1048 \(TYPE PREDICATE FUNCTION)
1050 where TYPE is a symbol that names the method; PREDICATE is a function
1051 called without any parameters to determine whether the message is
1052 a message of type TYPE; and FUNCTION is a function to be called if
1053 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1056 (defcustom message-mail-alias-type
'abbrev
1057 "*What alias expansion type to use in Message buffers.
1058 The default is `abbrev', which uses mailabbrev. nil switches
1061 :link
'(custom-manual "(message)Mail Aliases")
1062 :type
'(choice (const :tag
"Use Mailabbrev" abbrev
)
1063 (const :tag
"No expansion" nil
)))
1065 (defcustom message-auto-save-directory
1066 (file-name-as-directory (nnheader-concat message-directory
"drafts"))
1067 "*Directory where Message auto-saves buffers if Gnus isn't running.
1068 If nil, Message won't auto-save."
1069 :group
'message-buffers
1070 :link
'(custom-manual "(message)Various Message Variables")
1071 :type
'(choice directory
(const :tag
"Don't auto-save" nil
)))
1073 (defcustom message-default-charset
1074 (and (not (mm-multibyte-p)) 'iso-8859-1
)
1075 "Default charset used in non-MULE Emacsen.
1076 If nil, you might be asked to input the charset."
1079 :link
'(custom-manual "(message)Various Message Variables")
1082 (defcustom message-dont-reply-to-names
1083 (and (boundp 'rmail-dont-reply-to-names
) rmail-dont-reply-to-names
)
1084 "*A regexp specifying addresses to prune when doing wide replies.
1085 A value of nil means exclude your own user name only."
1088 :link
'(custom-manual "(message)Wide Reply")
1089 :type
'(choice (const :tag
"Yourself" nil
)
1092 (defvar message-shoot-gnksa-feet nil
1093 "*A list of GNKSA feet you are allowed to shoot.
1094 Gnus gives you all the opportunity you could possibly want for
1095 shooting yourself in the foot. Also, Gnus allows you to shoot the
1096 feet of Good Net-Keeping Seal of Approval. The following are foot
1098 `empty-article' Allow you to post an empty article;
1099 `quoted-text-only' Allow you to post quoted text only;
1100 `multiple-copies' Allow you to post multiple copies;
1101 `cancel-messages' Allow you to cancel or supersede messages from
1102 your other email addresses.")
1104 (defsubst message-gnksa-enable-p
(feature)
1105 (or (not (listp message-shoot-gnksa-feet
))
1106 (memq feature message-shoot-gnksa-feet
)))
1108 (defcustom message-hidden-headers nil
1109 "Regexp of headers to be hidden when composing new messages.
1110 This can also be a list of regexps to match headers. Or a list
1111 starting with `not' and followed by regexps."
1114 :link
'(custom-manual "(message)Message Headers")
1115 :type
'(repeat regexp
))
1117 ;;; Internal variables.
1118 ;;; Well, not really internal.
1120 (defvar message-mode-syntax-table
1121 (let ((table (copy-syntax-table text-mode-syntax-table
)))
1122 (modify-syntax-entry ?%
". " table
)
1123 (modify-syntax-entry ?
> ". " table
)
1124 (modify-syntax-entry ?
< ". " table
)
1126 "Syntax table used while in Message mode.")
1128 (defface message-header-to
1131 (:foreground
"green2" :bold t
))
1134 (:foreground
"MidnightBlue" :bold t
))
1136 (:bold t
:italic t
)))
1137 "Face used for displaying From headers."
1138 :group
'message-faces
)
1139 ;; backward-compatibility alias
1140 (put 'message-header-to-face
'face-alias
'message-header-to
)
1142 (defface message-header-cc
1145 (:foreground
"green4" :bold t
))
1148 (:foreground
"MidnightBlue"))
1151 "Face used for displaying Cc headers."
1152 :group
'message-faces
)
1153 ;; backward-compatibility alias
1154 (put 'message-header-cc-face
'face-alias
'message-header-cc
)
1156 (defface message-header-subject
1159 (:foreground
"green3"))
1162 (:foreground
"navy blue" :bold t
))
1165 "Face used for displaying subject headers."
1166 :group
'message-faces
)
1167 ;; backward-compatibility alias
1168 (put 'message-header-subject-face
'face-alias
'message-header-subject
)
1170 (defface message-header-newsgroups
1173 (:foreground
"yellow" :bold t
:italic t
))
1176 (:foreground
"blue4" :bold t
:italic t
))
1178 (:bold t
:italic t
)))
1179 "Face used for displaying newsgroups headers."
1180 :group
'message-faces
)
1181 ;; backward-compatibility alias
1182 (put 'message-header-newsgroups-face
'face-alias
'message-header-newsgroups
)
1184 (defface message-header-other
1187 (:foreground
"#b00000"))
1190 (:foreground
"steel blue"))
1192 (:bold t
:italic t
)))
1193 "Face used for displaying newsgroups headers."
1194 :group
'message-faces
)
1195 ;; backward-compatibility alias
1196 (put 'message-header-other-face
'face-alias
'message-header-other
)
1198 (defface message-header-name
1201 (:foreground
"DarkGreen"))
1204 (:foreground
"cornflower blue"))
1207 "Face used for displaying header names."
1208 :group
'message-faces
)
1209 ;; backward-compatibility alias
1210 (put 'message-header-name-face
'face-alias
'message-header-name
)
1212 (defface message-header-xheader
1215 (:foreground
"blue"))
1218 (:foreground
"blue"))
1221 "Face used for displaying X-Header headers."
1222 :group
'message-faces
)
1223 ;; backward-compatibility alias
1224 (put 'message-header-xheader-face
'face-alias
'message-header-xheader
)
1226 (defface message-separator
1229 (:foreground
"blue3"))
1232 (:foreground
"brown"))
1235 "Face used for displaying the separator."
1236 :group
'message-faces
)
1237 ;; backward-compatibility alias
1238 (put 'message-separator-face
'face-alias
'message-separator
)
1240 (defface message-cited-text
1243 (:foreground
"red"))
1246 (:foreground
"red"))
1249 "Face used for displaying cited text names."
1250 :group
'message-faces
)
1251 ;; backward-compatibility alias
1252 (put 'message-cited-text-face
'face-alias
'message-cited-text
)
1254 (defface message-mml
1257 (:foreground
"ForestGreen"))
1260 (:foreground
"ForestGreen"))
1263 "Face used for displaying MML."
1264 :group
'message-faces
)
1265 ;; backward-compatibility alias
1266 (put 'message-mml-face
'face-alias
'message-mml
)
1268 (defun message-font-lock-make-header-matcher (regexp)
1271 (let ((start (point)))
1274 (goto-char (point-min))
1275 (if (re-search-forward
1276 (concat "^" (regexp-quote mail-header-separator
) "$")
1278 (setq limit
(min limit
(match-beginning 0))))
1280 (and (< start limit
)
1281 (re-search-forward ,regexp limit t
))))))
1282 (if (featurep 'bytecomp
)
1286 (defvar message-font-lock-keywords
1287 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1288 `((,(message-font-lock-make-header-matcher
1289 (concat "^\\([Tt]o:\\)" content
))
1290 (1 'message-header-name
)
1291 (2 'message-header-to nil t
))
1292 (,(message-font-lock-make-header-matcher
1293 (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content
))
1294 (1 'message-header-name
)
1295 (2 'message-header-cc nil t
))
1296 (,(message-font-lock-make-header-matcher
1297 (concat "^\\([Ss]ubject:\\)" content
))
1298 (1 'message-header-name
)
1299 (2 'message-header-subject nil t
))
1300 (,(message-font-lock-make-header-matcher
1301 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content
))
1302 (1 'message-header-name
)
1303 (2 'message-header-newsgroups nil t
))
1304 (,(message-font-lock-make-header-matcher
1305 (concat "^\\([A-Z][^: \n\t]+:\\)" content
))
1306 (1 'message-header-name
)
1307 (2 'message-header-other nil t
))
1308 (,(message-font-lock-make-header-matcher
1309 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content
))
1310 (1 'message-header-name
)
1311 (2 'message-header-name
))
1312 ,@(if (and mail-header-separator
1313 (not (equal mail-header-separator
"")))
1314 `((,(concat "^\\(" (regexp-quote mail-header-separator
) "\\)$")
1315 1 'message-separator
))
1318 (re-search-forward (concat "^\\("
1319 message-cite-prefix-regexp
1322 (0 'message-cited-text
))
1323 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1325 "Additional expressions to highlight in Message mode.")
1328 ;; XEmacs does it like this. For Emacs, we have to set the
1329 ;; `font-lock-defaults' buffer-local variable.
1330 (put 'message-mode
'font-lock-defaults
'(message-font-lock-keywords t
))
1332 (defvar message-face-alist
1333 '((bold . bold-region
)
1334 (underline . underline-region
)
1335 (default .
(lambda (b e
)
1337 (ununderline-region b e
))))
1338 "Alist of mail and news faces for facemenu.
1339 The cdr of each entry is a function for applying the face to a region.")
1341 (defcustom message-send-hook nil
1342 "Hook run before sending messages.
1343 This hook is run quite early when sending."
1344 :group
'message-various
1345 :options
'(ispell-message)
1346 :link
'(custom-manual "(message)Various Message Variables")
1349 (defcustom message-send-mail-hook nil
1350 "Hook run before sending mail messages.
1351 This hook is run very late -- just before the message is sent as
1353 :group
'message-various
1354 :link
'(custom-manual "(message)Various Message Variables")
1357 (defcustom message-send-news-hook nil
1358 "Hook run before sending news messages.
1359 This hook is run very late -- just before the message is sent as
1361 :group
'message-various
1362 :link
'(custom-manual "(message)Various Message Variables")
1365 (defcustom message-sent-hook nil
1366 "Hook run after sending messages."
1367 :group
'message-various
1370 (defvar message-send-coding-system
'binary
1371 "Coding system to encode outgoing mail.")
1373 (defvar message-draft-coding-system
1374 mm-auto-save-coding-system
1375 "*Coding system to compose mail.
1376 If you'd like to make it possible to share draft files between XEmacs
1377 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1378 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1380 (defcustom message-send-mail-partially-limit
1000000
1381 "The limitation of messages sent as message/partial.
1382 The lower bound of message size in characters, beyond which the message
1383 should be sent in several parts. If it is nil, the size is unlimited."
1385 :group
'message-buffers
1386 :link
'(custom-manual "(message)Mail Variables")
1387 :type
'(choice (const :tag
"unlimited" nil
)
1390 (defcustom message-alternative-emails nil
1391 "*Regexp matching alternative email addresses.
1392 The first address in the To, Cc or From headers of the original
1393 article matching this variable is used as the From field of
1396 This variable has precedence over posting styles and anything that runs
1397 off `message-setup-hook'."
1398 :group
'message-headers
1399 :link
'(custom-manual "(message)Message Headers")
1400 :type
'(choice (const :tag
"Always use primary" nil
)
1403 (defcustom message-hierarchical-addresses nil
1404 "A list of hierarchical mail address definitions.
1406 Inside each entry, the first address is the \"top\" address, and
1407 subsequent addresses are subaddresses; this is used to indicate that
1408 mail sent to the first address will automatically be delivered to the
1409 subaddresses. So if the first address appears in the recipient list
1410 for a message, the subaddresses will be removed (if present) before
1411 the mail is sent. All addresses in this structure should be
1414 :group
'message-headers
1415 :type
'(repeat (repeat string
)))
1417 (defcustom message-mail-user-agent nil
1418 "Like `mail-user-agent'.
1419 Except if it is nil, use Gnus native MUA; if it is t, use
1422 :type
'(radio (const :tag
"Gnus native"
1425 (const :tag
"`mail-user-agent'"
1428 (function-item :tag
"Default Emacs mail"
1430 sendmail-user-agent
)
1431 (function-item :tag
"Emacs interface to MH"
1434 (function :tag
"Other"))
1438 (defcustom message-wide-reply-confirm-recipients nil
1439 "Whether to confirm a wide reply to multiple email recipients.
1440 If this variable is nil, don't ask whether to reply to all recipients.
1441 If this variable is non-nil, pose the question \"Reply to all
1442 recipients?\" before a wide reply to multiple recipients. If the user
1443 answers yes, reply to all recipients as usual. If the user answers
1444 no, only reply back to the author."
1446 :group
'message-headers
1447 :link
'(custom-manual "(message)Wide Reply")
1450 (defcustom message-user-fqdn nil
1451 "*Domain part of Message-Ids."
1453 :group
'message-headers
1454 :link
'(custom-manual "(message)News Headers")
1455 :type
'(radio (const :format
"%v " nil
)
1456 (string :format
"FQDN: %v")))
1458 (defcustom message-use-idna
(and (condition-case nil
(require 'idna
)
1460 (mm-coding-system-p 'utf-8
)
1461 (executable-find idna-program
)
1462 (string= (idna-to-ascii "räksmörgås")
1463 "xn--rksmrgs-5wao1o")
1465 "Whether to encode non-ASCII in domain names into ASCII according to IDNA.
1466 GNU Libidn, and in particular the elisp package \"idna.el\" and
1467 the external program \"idn\", must be installed for this
1468 functionality to work."
1470 :group
'message-headers
1471 :link
'(custom-manual "(message)IDNA")
1472 :type
'(choice (const :tag
"Ask" ask
)
1473 (const :tag
"Never" nil
)
1474 (const :tag
"Always" t
)))
1476 ;;; Internal variables.
1478 (defvar message-sending-message
"Sending...")
1479 (defvar message-buffer-list nil
)
1480 (defvar message-this-is-news nil
)
1481 (defvar message-this-is-mail nil
)
1482 (defvar message-draft-article nil
)
1483 (defvar message-mime-part nil
)
1484 (defvar message-posting-charset nil
)
1485 (defvar message-inserted-headers nil
)
1487 ;; Byte-compiler warning
1489 (defvar gnus-active-hashtb
)
1490 (defvar gnus-read-active-file
))
1492 ;;; Regexp matching the delimiter of messages in UNIX mail format
1493 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1494 ;;; of rmail.el's rmail-unix-mail-delimiter.
1495 (defvar message-unix-mail-delimiter
1496 (let ((time-zone-regexp
1497 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1498 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1504 ;; Many things can happen to an RFC 822 mailbox before it is put into
1505 ;; a `From' line. The leading phrase can be stripped, e.g.
1506 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1507 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1508 ;; can be removed, e.g.
1509 ;; From: joe@y.z (Joe K
1511 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1514 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1515 ;; The mailbox can be removed or be replaced by white space, e.g.
1516 ;; From: "Joe User"{space}{tab}
1518 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1519 ;; where {space} and {tab} represent the Ascii space and tab characters.
1520 ;; We want to match the results of any of these manglings.
1521 ;; The following regexp rejects names whose first characters are
1522 ;; obviously bogus, but after that anything goes.
1523 "\\([^\0-\b\n-\r\^?].*\\)?"
1525 ;; The time the message was sent.
1526 "\\([^\0-\r \^?]+\\) +" ; day of the week
1527 "\\([^\0-\r \^?]+\\) +" ; month
1528 "\\([0-3]?[0-9]\\) +" ; day of month
1529 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1531 ;; Perhaps a time zone, specified by an abbreviation, or by a
1536 " \\([0-9][0-9]+\\) *"
1538 ;; On some systems the time zone can appear after the year, too.
1542 "\\(remote from .*\\)?"
1545 "Regexp matching the delimiter of messages in UNIX mail format.")
1547 (defvar message-unsent-separator
1548 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1549 "^ *---+ +Returned message +---+ *$\\|"
1550 "^Start of returned message$\\|"
1551 "^ *---+ +Original message +---+ *$\\|"
1552 "^ *--+ +begin message +--+ *$\\|"
1553 "^ *---+ +Original message follows +---+ *$\\|"
1554 "^ *---+ +Undelivered message follows +---+ *$\\|"
1555 "^|? *---+ +Message text follows: +---+ *|?$")
1556 "A regexp that matches the separator before the text of a failed message.")
1558 (defvar message-header-format-alist
1560 (To . message-fill-address
)
1561 (Cc . message-fill-address
)
1572 (References . message-shorten-references
)
1574 "Alist used for formatting headers.")
1576 (defvar message-options nil
1577 "Some saved answers when sending message.")
1579 (defvar message-send-mail-real-function nil
1580 "Internal send mail function.")
1582 (defvar message-bogus-system-names
"^localhost\\."
1583 "The regexp of bogus system names.")
1585 (defcustom message-valid-fqdn-regexp
1586 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1588 "\\([a-z][a-z]" ;; two letter country TDLs
1589 "\\|biz\\|com\\|edu\\|gov\\|int\\|mil\\|net\\|org"
1590 "\\|aero\\|coop\\|info\\|name\\|museum"
1591 "\\|arpa\\|pro\\|uucp\\|bitnet\\|bofh" ;; old style?
1593 "Regular expression that matches a valid FQDN."
1594 ;; see also: gnus-button-valid-fqdn-regexp
1596 :group
'message-headers
1600 (autoload 'idna-to-ascii
"idna")
1601 (autoload 'message-setup-toolbar
"messagexmas")
1602 (autoload 'mh-new-draft-name
"mh-comp")
1603 (autoload 'mh-send-letter
"mh-comp")
1604 (autoload 'gnus-point-at-eol
"gnus-util")
1605 (autoload 'gnus-point-at-bol
"gnus-util")
1606 (autoload 'gnus-output-to-rmail
"gnus-util")
1607 (autoload 'gnus-output-to-mail
"gnus-util")
1608 (autoload 'nndraft-request-associate-buffer
"nndraft")
1609 (autoload 'nndraft-request-expire-articles
"nndraft")
1610 (autoload 'gnus-open-server
"gnus-int")
1611 (autoload 'gnus-request-post
"gnus-int")
1612 (autoload 'gnus-alive-p
"gnus-util")
1613 (autoload 'gnus-server-string
"gnus")
1614 (autoload 'gnus-group-name-charset
"gnus-group")
1615 (autoload 'gnus-group-name-decode
"gnus-group")
1616 (autoload 'gnus-groups-from-server
"gnus")
1617 (autoload 'rmail-output
"rmailout")
1618 (autoload 'gnus-delay-article
"gnus-delay")
1619 (autoload 'gnus-make-local-hook
"gnus-util")
1620 (autoload 'gnus-extract-address-components
"gnus-util"))
1625 ;;; Utility functions.
1628 (defmacro message-y-or-n-p
(question show
&rest text
)
1629 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1630 `(message-talkative-question 'y-or-n-p
,question
,show
,@text
))
1632 (defmacro message-delete-line
(&optional n
)
1633 "Delete the current line (and the next N lines)."
1634 `(delete-region (progn (beginning-of-line) (point))
1635 (progn (forward-line ,(or n
1)) (point))))
1637 (defun message-mark-active-p ()
1638 "Non-nil means the mark and region are currently active in this buffer."
1641 (defun message-unquote-tokens (elems)
1642 "Remove double quotes (\") from strings in list ELEMS."
1643 (mapcar (lambda (item)
1644 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item
)
1645 (setq item
(concat (match-string 1 item
)
1646 (match-string 2 item
))))
1650 (defun message-tokenize-header (header &optional separator
)
1651 "Split HEADER into a list of header elements.
1652 SEPARATOR is a string of characters to be used as separators. \",\"
1653 is used by default."
1656 (let ((regexp (format "[%s]+" (or separator
",")))
1658 beg quoted elems paren
)
1660 (mm-enable-multibyte)
1661 (setq beg
(point-min))
1663 (goto-char (point-min))
1668 (cond ((and (> (point) beg
)
1670 (and (looking-at regexp
)
1673 (push (buffer-substring beg
(point)) elems
)
1674 (setq beg
(match-end 0)))
1675 ((eq (char-after) ?
\")
1676 (setq quoted
(not quoted
)))
1677 ((and (eq (char-after) ?\
()
1680 ((and (eq (char-after) ?\
))
1683 (nreverse elems
)))))
1685 (defun message-mail-file-mbox-p (file)
1686 "Say whether FILE looks like a Unix mbox file."
1687 (when (and (file-exists-p file
)
1688 (file-readable-p file
)
1689 (file-regular-p file
))
1691 (nnheader-insert-file-contents file
)
1692 (goto-char (point-min))
1693 (looking-at message-unix-mail-delimiter
))))
1695 (defun message-fetch-field (header &optional not-all
)
1696 "The same as `mail-fetch-field', only remove all newlines.
1697 The buffer is expected to be narrowed to just the header of the message;
1698 see `message-narrow-to-headers-or-head'."
1699 (let* ((inhibit-point-motion-hooks t
)
1700 (case-fold-search t
)
1701 (value (mail-fetch-field header nil
(not not-all
))))
1703 (while (string-match "\n[\t ]+" value
)
1704 (setq value
(replace-match " " t t value
)))
1705 (set-text-properties 0 (length value
) nil value
)
1708 (defun message-field-value (header &optional not-all
)
1709 "The same as `message-fetch-field', only narrow to the headers first."
1712 (message-narrow-to-headers-or-head)
1713 (message-fetch-field header not-all
))))
1715 (defun message-narrow-to-field ()
1716 "Narrow the buffer to the header on the current line."
1722 (if (re-search-forward "^[^ \n\t]" nil t
)
1727 (goto-char (point-min)))
1729 (defun message-add-header (&rest headers
)
1730 "Add the HEADERS to the message header, skipping those already present."
1733 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers
))
1734 (error "Invalid header `%s'" (car headers
)))
1735 (setq hclean
(match-string 1 (car headers
)))
1737 (message-narrow-to-headers)
1738 (unless (re-search-forward (concat "^" (regexp-quote hclean
) ":") nil t
)
1739 (goto-char (point-max))
1740 (if (string-match "\n$" (car headers
))
1741 (insert (car headers
))
1742 (insert (car headers
) ?
\n)))))
1743 (setq headers
(cdr headers
))))
1745 (defmacro message-with-reply-buffer
(&rest forms
)
1746 "Evaluate FORMS in the reply buffer, if it exists."
1747 `(when (and message-reply-buffer
1748 (buffer-name message-reply-buffer
))
1750 (set-buffer message-reply-buffer
)
1753 (put 'message-with-reply-buffer
'lisp-indent-function
0)
1754 (put 'message-with-reply-buffer
'edebug-form-spec
'(body))
1756 (defun message-fetch-reply-field (header)
1757 "Fetch field HEADER from the message we're replying to."
1758 (message-with-reply-buffer
1760 (mail-narrow-to-head)
1761 (message-fetch-field header
))))
1763 (defun message-strip-list-identifiers (subject)
1764 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1765 (require 'gnus-sum
) ; for gnus-list-identifiers
1766 (let ((regexp (if (stringp gnus-list-identifiers
)
1767 gnus-list-identifiers
1768 (mapconcat 'identity gnus-list-identifiers
" *\\|"))))
1769 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1770 " *\\)\\)+\\(Re: +\\)?\\)") subject
)
1771 (concat (substring subject
0 (match-beginning 1))
1772 (or (match-string 3 subject
)
1773 (match-string 5 subject
))
1778 (defun message-strip-subject-re (subject)
1779 "Remove \"Re:\" from subject lines in string SUBJECT."
1780 (if (string-match message-subject-re-regexp subject
)
1781 (substring subject
(match-end 0))
1784 ;;; Start of functions adopted from `message-utils.el'.
1786 (defun message-strip-subject-trailing-was (subject)
1787 "Remove trailing \"(was: <old subject>)\" from SUBJECT lines.
1788 Leading \"Re: \" is not stripped by this function. Use the function
1789 `message-strip-subject-re' for this."
1790 (let* ((query message-subject-trailing-was-query
)
1795 message-subject-trailing-was-ask-regexp
1796 message-subject-trailing-was-regexp
)
1799 (setq new
(substring subject
0 (match-beginning 0))))
1800 (if (or (not found
) (eq query nil
))
1803 (if (message-y-or-n-p
1804 "Strip `(was: <old subject>)' in subject? " t
1806 "Strip `(was: <old subject>)' in subject "
1807 "and use the new one instead?\n\n"
1808 "Current subject is: \""
1810 "New subject would be: \""
1812 "See the variable `message-subject-trailing-was-query' "
1813 "to get rid of this query."
1818 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
1820 (defun message-change-subject (new-subject)
1821 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
1822 ;; <URL:http://www.landfield.com/usefor/drafts/draft-ietf-usefor-useage--1.02.unpaged>
1825 (read-from-minibuffer "New subject: ")))
1826 (cond ((and (not (or (null new-subject
) ; new subject not empty
1827 (zerop (string-width new-subject
))
1828 (string-match "^[ \t]*$" new-subject
))))
1832 (message-narrow-to-headers)
1833 (message-fetch-field "Subject"))))
1834 (cond ((not old-subject
)
1835 (error "No current subject"))
1838 (regexp-quote new-subject
)
1840 old-subject
)) ; yes, it really is a new subject
1841 ;; delete eventual Re: prefix
1843 (message-strip-subject-re old-subject
))
1844 (message-goto-subject)
1845 (message-delete-line)
1846 (insert (concat "Subject: "
1849 old-subject
")\n")))))))))
1851 (defun message-mark-inserted-region (beg end
)
1852 "Mark some region in the current article with enclosing tags.
1853 See `message-mark-insert-begin' and `message-mark-insert-end'."
1856 ;; add to the end of the region first, otherwise end would be invalid
1858 (insert message-mark-insert-end
)
1860 (insert message-mark-insert-begin
)))
1862 (defun message-mark-insert-file (file)
1863 "Insert FILE at point, marking it with enclosing tags.
1864 See `message-mark-insert-begin' and `message-mark-insert-end'."
1865 (interactive "fFile to insert: ")
1866 ;; reverse insertion to get correct result.
1868 (insert message-mark-insert-end
)
1870 (insert-file-contents file
)
1872 (insert message-mark-insert-begin
)))
1874 (defun message-add-archive-header ()
1875 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
1876 The note can be customized using `message-archive-note'. When called with a
1877 prefix argument, ask for a text to insert. If you don't want the note in the
1878 body, set `message-archive-note' to nil."
1880 (if current-prefix-arg
1881 (setq message-archive-note
1882 (read-from-minibuffer "Reason for No-Archive: "
1883 (cons message-archive-note
0))))
1885 (if (message-goto-signature)
1886 (re-search-backward message-signature-separator
))
1887 (when message-archive-note
1888 (insert message-archive-note
)
1890 (message-add-header message-archive-header
)
1891 (message-sort-headers)))
1893 (defun message-cross-post-followup-to-header (target-group)
1894 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
1895 With prefix-argument just set Follow-Up, don't cross-post."
1897 (list ; Completion based on Gnus
1898 (completing-read "Followup To: "
1899 (if (boundp 'gnus-newsrc-alist
)
1901 nil nil
'("poster" .
0)
1902 (if (boundp 'gnus-group-history
)
1903 'gnus-group-history
))))
1904 (message-remove-header "Follow[Uu]p-[Tt]o" t
)
1905 (message-goto-newsgroups)
1907 ;; if we already did a crosspost before, kill old target
1908 (if (and message-cross-post-old-target
1910 (regexp-quote (concat "," message-cross-post-old-target
))
1913 ;; unless (followup is to poster or user explicitly asked not
1914 ;; to cross-post, or target-group is already in Newsgroups)
1915 ;; add target-group to Newsgroups line.
1917 ;; def: cross-post, req:no
1918 (and message-cross-post-default
(not current-prefix-arg
))
1919 ;; def: no-cross-post, req:yes
1920 (and (not message-cross-post-default
) current-prefix-arg
))
1921 (not (string-match "poster" target-group
))
1922 (not (string-match (regexp-quote target-group
)
1923 (message-fetch-field "Newsgroups"))))
1925 (insert (concat "," target-group
))))
1926 (end-of-line) ; ensure Followup: comes after Newsgroups:
1927 ;; unless new followup would be identical to Newsgroups line
1928 ;; make a new Followup-To line
1929 (if (not (string-match (concat "^[ \t]*"
1932 (message-fetch-field "Newsgroups")))
1933 (insert (concat "\nFollowup-To: " target-group
)))
1934 (setq message-cross-post-old-target target-group
))
1936 (defun message-cross-post-insert-note (target-group cross-post in-old
1938 "Insert a in message body note about a set Followup or Crosspost.
1939 If there have been previous notes, delete them. TARGET-GROUP specifies the
1940 group to Followup-To. When CROSS-POST is t, insert note about
1941 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
1942 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
1943 been made to before the user asked for a Crosspost."
1944 ;; start scanning body for previous uses
1945 (message-goto-signature)
1946 (let ((head (re-search-backward
1947 (concat "^" mail-header-separator
)
1948 nil t
))) ; just search in body
1949 (message-goto-signature)
1950 (while (re-search-backward
1951 (concat "^" (regexp-quote message-cross-post-note
) ".*")
1953 (message-delete-line))
1954 (message-goto-signature)
1955 (while (re-search-backward
1956 (concat "^" (regexp-quote message-followup-to-note
) ".*")
1958 (message-delete-line))
1960 (if (message-goto-signature)
1961 (re-search-backward message-signature-separator
))
1964 (string-match "^[ \t]*poster[ \t]*$" target-group
))
1965 (insert (concat message-followup-to-note target-group
"\n"))
1966 (insert (concat message-cross-post-note target-group
"\n")))))
1968 (defun message-cross-post-followup-to (target-group)
1969 "Crossposts message and set Followup-To to TARGET-GROUP.
1970 With prefix-argument just set Follow-Up, don't cross-post."
1972 (list ; Completion based on Gnus
1973 (completing-read "Followup To: "
1974 (if (boundp 'gnus-newsrc-alist
)
1976 nil nil
'("poster" .
0)
1977 (if (boundp 'gnus-group-history
)
1978 'gnus-group-history
))))
1979 (cond ((not (or (null target-group
) ; new subject not empty
1980 (zerop (string-width target-group
))
1981 (string-match "^[ \t]*$" target-group
)))
1983 (let* ((old-groups (message-fetch-field "Newsgroups"))
1984 (in-old (string-match
1985 (regexp-quote target-group
)
1986 (or old-groups
""))))
1987 ;; check whether target exactly matches old Newsgroups
1988 (cond ((not old-groups
)
1989 (error "No current newsgroup"))
1993 (regexp-quote target-group
)
1996 ;; yes, Newsgroups line must change
1997 (message-cross-post-followup-to-header target-group
)
1998 ;; insert note whether we do cross-post or followup-to
1999 (funcall message-cross-post-note-function
2001 (if (or (and message-cross-post-default
2002 (not current-prefix-arg
))
2003 (and (not message-cross-post-default
)
2004 current-prefix-arg
)) t
)
2005 in-old old-groups
))))))))
2007 ;;; Reduce To: to Cc: or Bcc: header
2009 (defun message-reduce-to-to-cc ()
2010 "Replace contents of To: header with contents of Cc: or Bcc: header."
2013 (save-restriction (message-narrow-to-headers)
2014 (message-fetch-field "cc")))
2016 (if (and (not cc-content
)
2019 (message-narrow-to-headers)
2020 (message-fetch-field "bcc"))))
2025 (message-delete-line)
2026 (insert (concat "To: " cc-content
"\n"))
2028 (message-narrow-to-headers)
2029 (message-remove-header (if bcc
2033 ;;; End of functions adopted from `message-utils.el'.
2035 (defun message-remove-header (header &optional is-regexp first reverse
)
2036 "Remove HEADER in the narrowed buffer.
2037 If IS-REGEXP, HEADER is a regular expression.
2038 If FIRST, only remove the first instance of the header.
2039 Return the number of headers removed."
2040 (goto-char (point-min))
2041 (let ((regexp (if is-regexp header
(concat "^" (regexp-quote header
) ":")))
2043 (case-fold-search t
)
2045 (while (and (not (eobp))
2048 (not (looking-at regexp
))
2049 (looking-at regexp
))
2056 ;; There might be a continuation header, so we have to search
2057 ;; until we find a new non-continuation line.
2060 (if (re-search-forward "^[^ \t]" nil t
)
2061 (goto-char (match-beginning 0))
2064 (if (re-search-forward "^[^ \t]" nil t
)
2065 (goto-char (match-beginning 0))
2066 (goto-char (point-max)))))
2069 (defun message-remove-first-header (header)
2070 "Remove the first instance of HEADER if there is more than one."
2072 (regexp (concat "^" (regexp-quote header
) ":")))
2074 (goto-char (point-min))
2075 (while (re-search-forward regexp nil t
)
2078 (message-remove-header header nil t
)
2081 (defun message-narrow-to-headers ()
2082 "Narrow the buffer to the head of the message."
2085 (goto-char (point-min))
2086 (if (re-search-forward
2087 (concat "^" (regexp-quote mail-header-separator
) "\n") nil t
)
2090 (goto-char (point-min)))
2092 (defun message-narrow-to-head-1 ()
2093 "Like `message-narrow-to-head'. Don't widen."
2095 (goto-char (point-min))
2096 (if (search-forward "\n\n" nil
1)
2099 (goto-char (point-min)))
2101 (defun message-narrow-to-head ()
2102 "Narrow the buffer to the head of the message.
2103 Point is left at the beginning of the narrowed-to region."
2105 (message-narrow-to-head-1))
2107 (defun message-narrow-to-headers-or-head ()
2108 "Narrow the buffer to the head of the message."
2111 (goto-char (point-min))
2114 (concat "^" (regexp-quote mail-header-separator
) "\n") nil t
)
2115 (match-beginning 0))
2116 ((search-forward "\n\n" nil t
)
2120 (goto-char (point-min)))
2122 (defun message-news-p ()
2123 "Say whether the current buffer contains a news message."
2124 (and (not message-this-is-mail
)
2125 (or message-this-is-news
2128 (message-narrow-to-headers)
2129 (and (message-fetch-field "newsgroups")
2130 (not (message-fetch-field "posted-to"))))))))
2132 (defun message-mail-p ()
2133 "Say whether the current buffer contains a mail message."
2134 (and (not message-this-is-news
)
2135 (or message-this-is-mail
2138 (message-narrow-to-headers)
2139 (or (message-fetch-field "to")
2140 (message-fetch-field "cc")
2141 (message-fetch-field "bcc")))))))
2143 (defun message-subscribed-p ()
2144 "Say whether we need to insert a MFT header."
2145 (or message-subscribed-regexps
2146 message-subscribed-addresses
2147 message-subscribed-address-file
2148 message-subscribed-address-functions
))
2150 (defun message-next-header ()
2151 "Go to the beginning of the next header."
2153 (or (eobp) (forward-char 1))
2154 (not (if (re-search-forward "^[^ \t]" nil t
)
2156 (goto-char (point-max)))))
2158 (defun message-sort-headers-1 ()
2159 "Sort the buffer as headers using `message-rank' text props."
2160 (goto-char (point-min))
2163 nil
'message-next-header
2165 (message-next-header)
2169 (or (get-text-property (point) 'message-rank
)
2172 (defun message-sort-headers ()
2173 "Sort the headers of the current message according to `message-header-format-alist'."
2177 (let ((max (1+ (length message-header-format-alist
)))
2179 (message-narrow-to-headers)
2180 (while (re-search-forward "^[^ \n]+:" nil t
)
2182 (match-beginning 0) (1+ (match-beginning 0))
2184 (if (setq rank
(length (memq (assq (intern (buffer-substring
2186 (1- (match-end 0))))
2187 message-header-format-alist
)
2188 message-header-format-alist
)))
2191 (message-sort-headers-1))))
2193 (defun message-info (&optional arg
)
2194 "Display the Message manual.
2196 Prefixed with one \\[universal-argument], display the Emacs MIME manual.
2197 Prefixed with two \\[universal-argument]'s, display the PGG manual."
2199 (cond ((eq arg
16) (Info-goto-node "(pgg)Top"))
2200 ((eq arg
4) (Info-goto-node "(emacs-mime)Top"))
2201 (t (Info-goto-node "(message)Top"))))
2211 (defvar message-mode-map nil
)
2213 (unless message-mode-map
2214 (setq message-mode-map
(make-keymap))
2215 (set-keymap-parent message-mode-map text-mode-map
)
2216 (define-key message-mode-map
"\C-c?" 'describe-mode
)
2218 (define-key message-mode-map
"\C-c\C-f\C-t" 'message-goto-to
)
2219 (define-key message-mode-map
"\C-c\C-f\C-o" 'message-goto-from
)
2220 (define-key message-mode-map
"\C-c\C-f\C-b" 'message-goto-bcc
)
2221 (define-key message-mode-map
"\C-c\C-f\C-w" 'message-goto-fcc
)
2222 (define-key message-mode-map
"\C-c\C-f\C-c" 'message-goto-cc
)
2223 (define-key message-mode-map
"\C-c\C-f\C-s" 'message-goto-subject
)
2224 (define-key message-mode-map
"\C-c\C-f\C-r" 'message-goto-reply-to
)
2225 (define-key message-mode-map
"\C-c\C-f\C-n" 'message-goto-newsgroups
)
2226 (define-key message-mode-map
"\C-c\C-f\C-d" 'message-goto-distribution
)
2227 (define-key message-mode-map
"\C-c\C-f\C-f" 'message-goto-followup-to
)
2228 (define-key message-mode-map
"\C-c\C-f\C-m" 'message-goto-mail-followup-to
)
2229 (define-key message-mode-map
"\C-c\C-f\C-k" 'message-goto-keywords
)
2230 (define-key message-mode-map
"\C-c\C-f\C-u" 'message-goto-summary
)
2231 (define-key message-mode-map
"\C-c\C-f\C-i"
2232 'message-insert-or-toggle-importance
)
2233 (define-key message-mode-map
"\C-c\C-f\C-a"
2234 'message-generate-unsubscribed-mail-followup-to
)
2236 ;; modify headers (and insert notes in body)
2237 (define-key message-mode-map
"\C-c\C-fs" 'message-change-subject
)
2239 (define-key message-mode-map
"\C-c\C-fx" 'message-cross-post-followup-to
)
2240 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2241 (define-key message-mode-map
"\C-c\C-ft" 'message-reduce-to-to-cc
)
2242 (define-key message-mode-map
"\C-c\C-fa" 'message-add-archive-header
)
2243 ;; mark inserted text
2244 (define-key message-mode-map
"\C-c\M-m" 'message-mark-inserted-region
)
2245 (define-key message-mode-map
"\C-c\M-f" 'message-mark-insert-file
)
2247 (define-key message-mode-map
"\C-c\C-b" 'message-goto-body
)
2248 (define-key message-mode-map
"\C-c\C-i" 'message-goto-signature
)
2250 (define-key message-mode-map
"\C-c\C-t" 'message-insert-to
)
2251 (define-key message-mode-map
"\C-c\C-fw" 'message-insert-wide-reply
)
2252 (define-key message-mode-map
"\C-c\C-n" 'message-insert-newsgroups
)
2253 (define-key message-mode-map
"\C-c\C-l" 'message-to-list-only
)
2255 (define-key message-mode-map
"\C-c\C-u" 'message-insert-or-toggle-importance
)
2256 (define-key message-mode-map
"\C-c\M-n"
2257 'message-insert-disposition-notification-to
)
2259 (define-key message-mode-map
"\C-c\C-y" 'message-yank-original
)
2260 (define-key message-mode-map
"\C-c\M-\C-y" 'message-yank-buffer
)
2261 (define-key message-mode-map
"\C-c\C-q" 'message-fill-yanked-message
)
2262 (define-key message-mode-map
"\C-c\C-w" 'message-insert-signature
)
2263 (define-key message-mode-map
"\C-c\M-h" 'message-insert-headers
)
2264 (define-key message-mode-map
"\C-c\C-r" 'message-caesar-buffer-body
)
2265 (define-key message-mode-map
"\C-c\C-o" 'message-sort-headers
)
2266 (define-key message-mode-map
"\C-c\M-r" 'message-rename-buffer
)
2268 (define-key message-mode-map
"\C-c\C-c" 'message-send-and-exit
)
2269 (define-key message-mode-map
"\C-c\C-s" 'message-send
)
2270 (define-key message-mode-map
"\C-c\C-k" 'message-kill-buffer
)
2271 (define-key message-mode-map
"\C-c\C-d" 'message-dont-send
)
2272 (define-key message-mode-map
"\C-c\n" 'gnus-delay-article
)
2274 (define-key message-mode-map
"\C-c\C-e" 'message-elide-region
)
2275 (define-key message-mode-map
"\C-c\C-v" 'message-delete-not-region
)
2276 (define-key message-mode-map
"\C-c\C-z" 'message-kill-to-signature
)
2277 (define-key message-mode-map
"\M-\r" 'message-newline-and-reformat
)
2278 ;;(define-key message-mode-map "\M-q" 'message-fill-paragraph)
2279 (define-key message-mode-map
[remap split-line
] 'message-split-line
)
2281 (define-key message-mode-map
"\C-c\C-a" 'mml-attach-file
)
2283 (define-key message-mode-map
"\C-a" 'message-beginning-of-line
)
2284 (define-key message-mode-map
"\t" 'message-tab
)
2285 (define-key message-mode-map
"\M-;" 'comment-region
))
2288 message-mode-menu message-mode-map
"Message Menu."
2290 ["Yank Original" message-yank-original message-reply-buffer
]
2291 ["Fill Yanked Message" message-fill-yanked-message t
]
2292 ["Insert Signature" message-insert-signature t
]
2293 ["Caesar (rot13) Message" message-caesar-buffer-body t
]
2294 ["Caesar (rot13) Region" message-caesar-region
(message-mark-active-p)]
2295 ["Elide Region" message-elide-region
2296 :active
(message-mark-active-p)
2297 ,@(if (featurep 'xemacs
) nil
2298 '(:help
"Replace text in region with an ellipsis"))]
2299 ["Delete Outside Region" message-delete-not-region
2300 :active
(message-mark-active-p)
2301 ,@(if (featurep 'xemacs
) nil
2302 '(:help
"Delete all quoted text outside region"))]
2303 ["Kill To Signature" message-kill-to-signature t
]
2304 ["Newline and Reformat" message-newline-and-reformat t
]
2305 ["Rename buffer" message-rename-buffer t
]
2306 ["Spellcheck" ispell-message
2307 ,@(if (featurep 'xemacs
) '(t)
2308 '(:help
"Spellcheck this message"))]
2310 ["Insert Region Marked" message-mark-inserted-region
2311 :active
(message-mark-active-p)
2312 ,@(if (featurep 'xemacs
) nil
2313 '(:help
"Mark region with enclosing tags"))]
2314 ["Insert File Marked..." message-mark-insert-file
2315 ,@(if (featurep 'xemacs
) '(t)
2316 '(:help
"Insert file at point marked with enclosing tags"))]
2318 ["Send Message" message-send-and-exit
2319 ,@(if (featurep 'xemacs
) '(t)
2320 '(:help
"Send this message"))]
2321 ["Postpone Message" message-dont-send
2322 ,@(if (featurep 'xemacs
) '(t)
2323 '(:help
"File this draft message and exit"))]
2324 ["Send at Specific Time..." gnus-delay-article
2325 ,@(if (featurep 'xemacs
) '(t)
2326 '(:help
"Ask, then arrange to send message at that time"))]
2327 ["Kill Message" message-kill-buffer
2328 ,@(if (featurep 'xemacs
) '(t)
2329 '(:help
"Delete this message without sending"))]
2331 ["Message manual" message-info
2332 ,@(if (featurep 'xemacs
) '(t)
2333 '(:help
"Display the Message manual"))]))
2336 message-mode-field-menu message-mode-map
""
2338 ["To" message-goto-to t
]
2339 ["From" message-goto-from t
]
2340 ["Subject" message-goto-subject t
]
2341 ["Change subject..." message-change-subject t
]
2342 ["Cc" message-goto-cc t
]
2343 ["Bcc" message-goto-bcc t
]
2344 ["Fcc" message-goto-fcc t
]
2345 ["Reply-To" message-goto-reply-to t
]
2346 ["Flag As Important" message-insert-importance-high
2347 ,@(if (featurep 'xemacs
) '(t)
2348 '(:help
"Mark this message as important"))]
2349 ["Flag As Unimportant" message-insert-importance-low
2350 ,@(if (featurep 'xemacs
) '(t)
2351 '(:help
"Mark this message as unimportant"))]
2353 message-insert-disposition-notification-to
2354 ,@(if (featurep 'xemacs
) '(t)
2355 '(:help
"Request a receipt notification"))]
2357 ;; (typical) news stuff
2358 ["Summary" message-goto-summary t
]
2359 ["Keywords" message-goto-keywords t
]
2360 ["Newsgroups" message-goto-newsgroups t
]
2361 ["Fetch Newsgroups" message-insert-newsgroups t
]
2362 ["Followup-To" message-goto-followup-to t
]
2363 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2364 ["Crosspost / Followup-To..." message-cross-post-followup-to t
]
2365 ["Distribution" message-goto-distribution t
]
2366 ["X-No-Archive:" message-add-archive-header t
]
2368 ;; (typical) mailing-lists stuff
2369 ["Fetch To" message-insert-to
2370 ,@(if (featurep 'xemacs
) '(t)
2371 '(:help
"Insert a To header that points to the author."))]
2372 ["Fetch To and Cc" message-insert-wide-reply
2373 ,@(if (featurep 'xemacs
) '(t)
2375 "Insert To and Cc headers as if you were doing a wide reply."))]
2377 ["Send to list only" message-to-list-only t
]
2378 ["Mail-Followup-To" message-goto-mail-followup-to t
]
2379 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2380 ,@(if (featurep 'xemacs
) '(t)
2381 '(:help
"Insert a reasonable `Mail-Followup-To:' header."))]
2382 ["Reduce To: to Cc:" message-reduce-to-to-cc t
]
2384 ["Sort Headers" message-sort-headers t
]
2385 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t
]
2386 ["Goto Body" message-goto-body t
]
2387 ["Goto Signature" message-goto-signature t
]))
2389 (defvar message-tool-bar-map nil
)
2392 (defvar facemenu-add-face-function
)
2393 (defvar facemenu-remove-face-function
))
2395 ;;; Forbidden properties
2397 ;; We use `after-change-functions' to keep special text properties
2398 ;; that interfer with the normal function of message mode out of the
2401 (defcustom message-strip-special-text-properties t
2402 "Strip special properties from the message buffer.
2404 Emacs has a number of special text properties which can break message
2405 composing in various ways. If this option is set, message will strip
2406 these properties from the message composition buffer. However, some
2407 packages requires these properties to be present in order to work.
2408 If you use one of these packages, turn this option off, and hope the
2409 message composition doesn't break too bad."
2411 :group
'message-various
2412 :link
'(custom-manual "(message)Various Message Variables")
2415 (defconst message-forbidden-properties
2416 ;; No reason this should be clutter up customize. We make it a
2417 ;; property list (rather than a list of property symbols), to be
2418 ;; directly useful for `remove-text-properties'.
2419 '(field nil read-only nil invisible nil intangible nil
2420 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2421 insert-behind-hooks nil point-entered nil point-left nil
)
2422 ;; Other special properties:
2423 ;; category, face, display: probably doesn't do any harm.
2424 ;; fontified: is used by font-lock.
2425 ;; syntax-table, local-map: I dunno.
2426 ;; We need to add XEmacs names to the list.
2427 "Property list of with properties forbidden in message buffers.
2428 The values of the properties are ignored, only the property names are used.")
2430 (defun message-tamago-not-in-use-p (pos)
2431 "Return t when tamago version 4 is not in use at the cursor position.
2432 Tamago version 4 is a popular input method for writing Japanese text.
2433 It uses the properties `intangible', `invisible', `modification-hooks'
2434 and `read-only' when translating ascii or kana text to kanji text.
2435 These properties are essential to work, so we should never strip them."
2436 (not (and (boundp 'egg-modefull-mode
)
2437 (symbol-value 'egg-modefull-mode
)
2438 (or (memq (get-text-property pos
'intangible
)
2439 '(its-part-1 its-part-2
))
2440 (get-text-property pos
'egg-end
)
2441 (get-text-property pos
'egg-lang
)
2442 (get-text-property pos
'egg-start
)))))
2444 (defun message-strip-forbidden-properties (begin end
&optional old-length
)
2445 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2446 This function is intended to be called from `after-change-functions'.
2447 See also `message-forbidden-properties'."
2448 (when (and message-strip-special-text-properties
2449 (message-tamago-not-in-use-p begin
))
2450 (let ((buffer-read-only nil
)
2451 (inhibit-read-only t
))
2452 (while (not (= begin end
))
2453 (when (not (get-text-property begin
'message-hidden
))
2454 (remove-text-properties begin
(1+ begin
)
2455 message-forbidden-properties
))
2459 (define-derived-mode message-mode text-mode
"Message"
2460 "Major mode for editing mail and news to be sent.
2461 Like Text Mode but with these additional commands:\\<message-mode-map>
2462 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2463 C-c C-d Postpone sending the message C-c C-k Kill the message
2464 C-c C-f move to a header field (and create it if there isn't):
2465 C-c C-f C-t move to To C-c C-f C-s move to Subject
2466 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2467 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2468 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2469 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2470 C-c C-f C-o move to From (\"Originator\")
2471 C-c C-f C-f move to Followup-To
2472 C-c C-f C-m move to Mail-Followup-To
2473 C-c C-f C-i cycle through Importance values
2474 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2475 C-c C-f x crossposting with FollowUp-To header and note in body
2476 C-c C-f t replace To: header with contents of Cc: or Bcc:
2477 C-c C-f a Insert X-No-Archive: header and a note in the body
2478 C-c C-t `message-insert-to' (add a To header to a news followup)
2479 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2480 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2481 C-c C-b `message-goto-body' (move to beginning of message text).
2482 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2483 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2484 C-c C-y `message-yank-original' (insert current message, if any).
2485 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2486 C-c C-e `message-elide-region' (elide the text between point and mark).
2487 C-c C-v `message-delete-not-region' (remove the text outside the region).
2488 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2489 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2490 C-c C-a `mml-attach-file' (attach a file as MIME).
2491 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2492 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2493 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2494 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2495 M-RET `message-newline-and-reformat' (break the line and reformat)."
2496 (setq local-abbrev-table text-mode-abbrev-table
)
2497 (set (make-local-variable 'message-reply-buffer
) nil
)
2498 (set (make-local-variable 'message-inserted-headers
) nil
)
2499 (set (make-local-variable 'message-send-actions
) nil
)
2500 (set (make-local-variable 'message-exit-actions
) nil
)
2501 (set (make-local-variable 'message-kill-actions
) nil
)
2502 (set (make-local-variable 'message-postpone-actions
) nil
)
2503 (set (make-local-variable 'message-draft-article
) nil
)
2504 (setq buffer-offer-save t
)
2505 (set (make-local-variable 'facemenu-add-face-function
)
2507 (let ((face-fun (cdr (assq face message-face-alist
))))
2509 (funcall face-fun
(point) end
)
2510 (error "Face %s not configured for %s mode" face mode-name
)))
2512 (set (make-local-variable 'facemenu-remove-face-function
) t
)
2513 (set (make-local-variable 'message-reply-headers
) nil
)
2514 (make-local-variable 'message-newsreader
)
2515 (make-local-variable 'message-mailer
)
2516 (make-local-variable 'message-post-method
)
2517 (set (make-local-variable 'message-sent-message-via
) nil
)
2518 (set (make-local-variable 'message-checksum
) nil
)
2519 (set (make-local-variable 'message-mime-part
) 0)
2520 (message-setup-fill-variables)
2521 ;; Allow using comment commands to add/remove quoting.
2522 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2523 (when message-yank-prefix
2524 (set (make-local-variable 'comment-start
) message-yank-prefix
)
2525 (set (make-local-variable 'comment-start-skip
)
2526 (concat "^" (regexp-quote message-yank-prefix
) "[ \t]*")))
2527 (if (featurep 'xemacs
)
2528 (message-setup-toolbar)
2529 (set (make-local-variable 'font-lock-defaults
)
2530 '(message-font-lock-keywords t
))
2531 (if (boundp 'tool-bar-map
)
2532 (set (make-local-variable 'tool-bar-map
) (message-tool-bar-map))))
2533 (easy-menu-add message-mode-menu message-mode-map
)
2534 (easy-menu-add message-mode-field-menu message-mode-map
)
2535 (gnus-make-local-hook 'after-change-functions
)
2536 ;; Mmmm... Forbidden properties...
2537 (add-hook 'after-change-functions
'message-strip-forbidden-properties
2539 ;; Allow mail alias things.
2540 (when (eq message-mail-alias-type
'abbrev
)
2541 (if (fboundp 'mail-abbrevs-setup
)
2542 (mail-abbrevs-setup)
2543 (if (fboundp 'mail-aliases-setup
) ; warning avoidance
2544 (mail-aliases-setup))))
2545 (unless buffer-file-name
2546 (message-set-auto-save-file-name))
2547 (unless (buffer-base-buffer)
2548 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2549 ;; multibyte is not necessary at all. -- zsh
2550 (mm-enable-multibyte))
2551 (set (make-local-variable 'indent-tabs-mode
) nil
) ;No tabs for indentation.
2554 (defun message-setup-fill-variables ()
2555 "Setup message fill variables."
2556 (set (make-local-variable 'fill-paragraph-function
)
2557 'message-fill-paragraph
)
2558 (make-local-variable 'paragraph-separate
)
2559 (make-local-variable 'paragraph-start
)
2560 (make-local-variable 'adaptive-fill-regexp
)
2561 (unless (boundp 'adaptive-fill-first-line-regexp
)
2562 (setq adaptive-fill-first-line-regexp nil
))
2563 (make-local-variable 'adaptive-fill-first-line-regexp
)
2564 (let ((quote-prefix-regexp
2565 ;; User should change message-cite-prefix-regexp if
2566 ;; message-yank-prefix is set to an abnormal value.
2567 (concat "\\(" message-cite-prefix-regexp
"\\)[ \t]*")))
2568 (setq paragraph-start
2570 (regexp-quote mail-header-separator
) "$\\|"
2571 "[ \t]*$\\|" ; blank lines
2572 "-- $\\|" ; signature delimiter
2573 "---+$\\|" ; delimiters for forwarded messages
2574 page-delimiter
"$\\|" ; spoiler warnings
2575 ".*wrote:$\\|" ; attribution lines
2576 quote-prefix-regexp
"$\\|" ; empty lines in quoted text
2578 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
2579 (setq paragraph-separate paragraph-start
)
2580 (setq adaptive-fill-regexp
2581 (concat quote-prefix-regexp
"\\|" adaptive-fill-regexp
))
2582 (setq adaptive-fill-first-line-regexp
2583 (concat quote-prefix-regexp
"\\|"
2584 adaptive-fill-first-line-regexp
)))
2585 (make-local-variable 'auto-fill-inhibit-regexp
)
2586 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2587 (setq auto-fill-inhibit-regexp nil
)
2588 (make-local-variable 'normal-auto-fill-function
)
2589 (setq normal-auto-fill-function
'message-do-auto-fill
)
2590 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2591 ;; In that case, ensure that it uses the right function. The real
2592 ;; solution would be not to use `define-derived-mode', and run
2593 ;; `text-mode-hook' ourself at the end of the mode.
2594 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2595 (when auto-fill-function
2596 (setq auto-fill-function normal-auto-fill-function
)))
2601 ;;; Message mode commands
2604 ;;; Movement commands
2606 (defun message-goto-to ()
2607 "Move point to the To header."
2609 (message-position-on-field "To"))
2611 (defun message-goto-from ()
2612 "Move point to the From header."
2614 (message-position-on-field "From"))
2616 (defun message-goto-subject ()
2617 "Move point to the Subject header."
2619 (message-position-on-field "Subject"))
2621 (defun message-goto-cc ()
2622 "Move point to the Cc header."
2624 (message-position-on-field "Cc" "To"))
2626 (defun message-goto-bcc ()
2627 "Move point to the Bcc header."
2629 (message-position-on-field "Bcc" "Cc" "To"))
2631 (defun message-goto-fcc ()
2632 "Move point to the Fcc header."
2634 (message-position-on-field "Fcc" "To" "Newsgroups"))
2636 (defun message-goto-reply-to ()
2637 "Move point to the Reply-To header."
2639 (message-position-on-field "Reply-To" "Subject"))
2641 (defun message-goto-newsgroups ()
2642 "Move point to the Newsgroups header."
2644 (message-position-on-field "Newsgroups"))
2646 (defun message-goto-distribution ()
2647 "Move point to the Distribution header."
2649 (message-position-on-field "Distribution"))
2651 (defun message-goto-followup-to ()
2652 "Move point to the Followup-To header."
2654 (message-position-on-field "Followup-To" "Newsgroups"))
2656 (defun message-goto-mail-followup-to ()
2657 "Move point to the Mail-Followup-To header."
2659 (message-position-on-field "Mail-Followup-To" "To"))
2661 (defun message-goto-keywords ()
2662 "Move point to the Keywords header."
2664 (message-position-on-field "Keywords" "Subject"))
2666 (defun message-goto-summary ()
2667 "Move point to the Summary header."
2669 (message-position-on-field "Summary" "Subject"))
2671 (defun message-goto-body (&optional interactivep
)
2672 "Move point to the beginning of the message body."
2673 (interactive (list t
))
2674 (when (and interactivep
2675 (looking-at "[ \t]*\n"))
2677 (goto-char (point-min))
2678 (or (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
2679 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t
)))
2681 (defun message-goto-eoh ()
2682 "Move point to the end of the headers."
2687 (defun message-goto-signature ()
2688 "Move point to the beginning of the message signature.
2689 If there is no signature in the article, go to the end and
2692 (goto-char (point-min))
2693 (if (re-search-forward message-signature-separator nil t
)
2695 (goto-char (point-max))
2698 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc
)
2699 "Insert a reasonable MFT header in a post to an unsubscribed list.
2700 When making original posts to a mailing list you are not subscribed to,
2701 you have to type in a MFT header by hand. The contents, usually, are
2702 the addresses of the list and your own address. This function inserts
2703 such a header automatically. It fetches the contents of the To: header
2704 in the current mail buffer, and appends the current `user-mail-address'.
2706 If the optional argument INCLUDE-CC is non-nil, the addresses in the
2707 Cc: header are also put into the MFT."
2712 (message-narrow-to-headers)
2713 (message-remove-header "Mail-Followup-To")
2714 (setq cc
(and include-cc
(message-fetch-field "Cc")))
2716 (concat (message-fetch-field "To") "," cc
)
2717 (message-fetch-field "To"))))
2718 (message-goto-mail-followup-to)
2719 (insert (concat tos
", " user-mail-address
))))
2723 (defun message-insert-to (&optional force
)
2724 "Insert a To header that points to the author of the article being replied to.
2725 If the original author requested not to be sent mail, don't insert unless the
2726 prefix FORCE is given."
2728 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
2729 (dont (and mct
(or (equal (downcase mct
) "never")
2730 (equal (downcase mct
) "nobody"))))
2731 (to (or (message-fetch-reply-field "mail-reply-to")
2732 (message-fetch-reply-field "reply-to")
2733 (message-fetch-reply-field "from"))))
2737 "Ignoring the user request not to have copies sent via mail"
2738 "Complying with the user request not to have copies sent via mail")))
2739 (when (and force
(not to
))
2740 (error "No mail address in the article"))
2741 (when (and to
(or force
(not dont
)))
2742 (message-carefully-insert-headers (list (cons 'To to
))))))
2744 (defun message-insert-wide-reply ()
2745 "Insert To and Cc headers as if you were doing a wide reply."
2747 (let ((headers (message-with-reply-buffer
2748 (message-get-reply-headers t
))))
2749 (message-carefully-insert-headers headers
)))
2751 (defcustom message-header-synonyms
2753 "List of lists of header synonyms.
2754 E.g., if this list contains a member list with elements `Cc' and `To',
2755 then `message-carefully-insert-headers' will not insert a `To' header
2756 when the message is already `Cc'ed to the recipient."
2758 :group
'message-headers
2759 :link
'(custom-manual "(message)Message Headers")
2760 :type
'(repeat sexp
))
2762 (defun message-carefully-insert-headers (headers)
2763 "Insert the HEADERS, an alist, into the message buffer.
2764 Does not insert the headers when they are already present there
2765 or in the synonym headers, defined by `message-header-synonyms'."
2766 ;; FIXME: Should compare only the address and not the full name. Comparison
2767 ;; should be done case-folded (and with `string=' rather than
2769 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
2770 (dolist (header headers
)
2771 (let* ((header-name (symbol-name (car header
)))
2772 (new-header (cdr header
))
2773 (synonyms (loop for synonym in message-header-synonyms
2774 when
(memq (car header
) synonym
) return synonym
))
2776 (loop for synonym in synonyms
2777 for old-header
= (mail-fetch-field (symbol-name synonym
))
2778 when
(and old-header
(string-match new-header old-header
))
2781 (message "already have `%s' in `%s'" new-header old-header
)
2782 (when (and (message-position-on-field header-name
)
2783 (setq old-header
(mail-fetch-field header-name
))
2784 (not (string-match "\\` *\\'" old-header
)))
2786 (insert new-header
)))))
2788 (defun message-widen-reply ()
2789 "Widen the reply to include maximum recipients."
2792 (and message-reply-buffer
2793 (buffer-name message-reply-buffer
)
2795 (set-buffer message-reply-buffer
)
2796 (message-get-reply-headers t
)))))
2799 (message-narrow-to-headers)
2800 (dolist (elem follow-to
)
2801 (message-remove-header (symbol-name (car elem
)))
2802 (goto-char (point-min))
2803 (insert (symbol-name (car elem
)) ": "
2804 (cdr elem
) "\n"))))))
2806 (defun message-insert-newsgroups ()
2807 "Insert the Newsgroups header from the article being replied to."
2809 (when (and (message-position-on-field "Newsgroups")
2810 (mail-fetch-field "newsgroups")
2811 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
2813 (insert (or (message-fetch-reply-field "newsgroups") "")))
2817 ;;; Various commands
2819 (defun message-delete-not-region (beg end
)
2820 "Delete everything in the body of the current message outside of the region."
2825 ;; snarf citation prefix, if appropriate
2826 (unless (eq (point) (progn (beginning-of-line) (point)))
2827 (when (looking-at message-cite-prefix-regexp
)
2828 (setq citeprefix
(match-string 0))))
2830 (delete-region (point) (if (not (message-goto-signature))
2836 (delete-region beg
(progn (message-goto-body)
2840 (insert citeprefix
))))
2841 (when (message-goto-signature)
2844 (defun message-kill-to-signature ()
2845 "Deletes all text up to the signature."
2847 (let ((point (point)))
2848 (message-goto-signature)
2851 (kill-region point
(point))
2855 (defun message-newline-and-reformat (&optional arg not-break
)
2856 "Insert four newlines, and then reformat if inside quoted text.
2857 Prefix arg means justify as well."
2858 (interactive (list (if current-prefix-arg
'full
)))
2859 (let (quoted point beg end leading-space bolp
)
2860 (setq point
(point))
2863 (setq bolp
(= beg point
))
2864 ;; Find first line of the paragraph.
2866 (while (and (not (eobp))
2867 (not (looking-at message-cite-prefix-regexp
))
2868 (looking-at paragraph-start
))
2871 (when (looking-at message-cite-prefix-regexp
)
2872 (setq quoted
(match-string 0))
2873 (goto-char (match-end 0))
2874 (looking-at "[ \t]*")
2875 (setq leading-space
(match-string 0)))
2879 (< (- point beg
) (length quoted
)))
2880 ;; break inside the cite prefix.
2886 (while (and (not (eobp))
2887 (not (looking-at paragraph-separate
))
2888 (looking-at message-cite-prefix-regexp
)
2889 (equal quoted
(match-string 0)))
2890 (goto-char (match-end 0))
2891 (looking-at "[ \t]*")
2892 (if (> (length leading-space
) (length (match-string 0)))
2893 (setq leading-space
(match-string 0)))
2897 (while (and (if (bobp) nil
(forward-line -
1) t
)
2898 (not (looking-at paragraph-start
))
2899 (looking-at message-cite-prefix-regexp
)
2900 (equal quoted
(match-string 0)))
2902 (goto-char (match-end 0))
2903 (looking-at "[ \t]*")
2904 (if (> (length leading-space
) (length (match-string 0)))
2905 (setq leading-space
(match-string 0)))))
2906 (while (and (not (eobp))
2907 (not (looking-at paragraph-separate
))
2908 (not (looking-at message-cite-prefix-regexp
)))
2912 (while (and (if (bobp) nil
(forward-line -
1) t
)
2913 (not (looking-at paragraph-start
))
2914 (not (looking-at message-cite-prefix-regexp
)))
2915 (setq beg
(point))))
2918 (narrow-to-region beg end
)
2925 (setq point
(point))
2926 ;; (newline 2) doesn't mark both newline's as hard, so call
2927 ;; newline twice. -jas
2930 (delete-region (point) (re-search-forward "[ \t]*"))
2931 (when (and quoted
(not bolp
))
2932 (insert quoted leading-space
)))
2935 (let* ((adaptive-fill-regexp
2936 (regexp-quote (concat quoted leading-space
)))
2937 (adaptive-fill-first-line-regexp
2938 adaptive-fill-regexp
))
2939 (fill-paragraph arg
))
2940 (fill-paragraph arg
))
2941 (if point
(goto-char point
)))))
2943 (defun message-fill-paragraph (&optional arg
)
2944 "Like `fill-paragraph'."
2945 (interactive (list (if current-prefix-arg
'full
)))
2946 (if (if (boundp 'filladapt-mode
) filladapt-mode
)
2948 (message-newline-and-reformat arg t
)
2951 ;; Is it better to use `mail-header-end'?
2952 (defun message-point-in-header-p ()
2953 "Return t if point is in the header."
2956 (goto-char (point-min))
2957 (not (re-search-forward
2958 (concat "^" (regexp-quote mail-header-separator
) "\n")
2961 (defun message-do-auto-fill ()
2962 "Like `do-auto-fill', but don't fill in message header."
2963 (unless (message-point-in-header-p)
2966 (defun message-insert-signature (&optional force
)
2967 "Insert a signature. See documentation for variable `message-signature'."
2968 (interactive (list 0))
2971 ((and (null message-signature
)
2974 (goto-char (point-max))
2975 (not (re-search-backward message-signature-separator nil t
))))
2976 ((and (null message-signature
)
2979 ((functionp message-signature
)
2980 (funcall message-signature
))
2981 ((listp message-signature
)
2982 (eval message-signature
))
2983 (t message-signature
)))
2985 (cond ((stringp signature
)
2987 ((and (eq t signature
)
2988 message-signature-file
2989 (file-exists-p message-signature-file
))
2992 (goto-char (point-max))
2993 ;; Insert the signature.
2996 (when message-signature-insert-empty-line
2999 (if (eq signature t
)
3000 (insert-file-contents message-signature-file
)
3002 (goto-char (point-max))
3003 (or (bolp) (insert "\n")))))
3005 (defun message-insert-importance-high ()
3006 "Insert header to mark message as important."
3010 (message-narrow-to-headers)
3011 (message-remove-header "Importance"))
3013 (insert "Importance: high\n")))
3015 (defun message-insert-importance-low ()
3016 "Insert header to mark message as unimportant."
3020 (message-narrow-to-headers)
3021 (message-remove-header "Importance"))
3023 (insert "Importance: low\n")))
3025 (defun message-insert-or-toggle-importance ()
3026 "Insert a \"Importance: high\" header, or cycle through the header values.
3027 The three allowed values according to RFC 1327 are `high', `normal'
3031 (let ((valid '("high" "normal" "low"))
3035 (message-narrow-to-headers)
3036 (when (setq cur
(message-fetch-field "Importance"))
3037 (message-remove-header "Importance")
3038 (setq new
(cond ((string= cur
"high")
3040 ((string= cur
"low")
3045 (insert (format "Importance: %s\n" new
)))))
3047 (defun message-insert-disposition-notification-to ()
3048 "Request a disposition notification (return receipt) to this message.
3049 Note that this should not be used in newsgroups."
3053 (message-narrow-to-headers)
3054 (message-remove-header "Disposition-Notification-To"))
3056 (insert (format "Disposition-Notification-To: %s\n"
3057 (or (message-field-value "Reply-to")
3058 (message-field-value "From")
3059 (message-make-from))))))
3061 (defun message-elide-region (b e
)
3062 "Elide the text in the region.
3063 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3067 (insert message-elide-ellipsis
))
3069 (defvar message-caesar-translation-table nil
)
3071 (defun message-caesar-region (b e
&optional n
)
3072 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3075 (min (point) (or (mark t
) (point)))
3076 (max (point) (or (mark t
) (point)))
3077 (when current-prefix-arg
3078 (prefix-numeric-value current-prefix-arg
))))
3080 (setq n
(if (numberp n
) (mod n
26) 13)) ;canonize N
3081 (unless (or (zerop n
) ; no action needed for a rot of 0
3082 (= b e
)) ; no region to rotate
3083 ;; We build the table, if necessary.
3084 (when (or (not message-caesar-translation-table
)
3085 (/= (aref message-caesar-translation-table ?a
) (+ ?a n
)))
3086 (setq message-caesar-translation-table
3087 (message-make-caesar-translation-table n
)))
3088 (translate-region b e message-caesar-translation-table
)))
3090 (defun message-make-caesar-translation-table (n)
3091 "Create a rot table with offset N."
3093 (table (make-string 256 0)))
3094 (while (< (incf i
) 256)
3097 (substring table
0 ?A
)
3098 (substring table
(+ ?A n
) (+ ?A n
(- 26 n
)))
3099 (substring table ?A
(+ ?A n
))
3100 (substring table
(+ ?A
26) ?a
)
3101 (substring table
(+ ?a n
) (+ ?a n
(- 26 n
)))
3102 (substring table ?a
(+ ?a n
))
3103 (substring table
(+ ?a
26) 255))))
3105 (defun message-caesar-buffer-body (&optional rotnum
)
3106 "Caesar rotate all letters in the current buffer by 13 places.
3107 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3108 With prefix arg, specifies the number of places to rotate each letter forward.
3109 Mail and USENET news headers are not rotated."
3110 (interactive (if current-prefix-arg
3111 (list (prefix-numeric-value current-prefix-arg
))
3115 (when (message-goto-body)
3116 (narrow-to-region (point) (point-max)))
3117 (message-caesar-region (point-min) (point-max) rotnum
))))
3119 (defun message-pipe-buffer-body (program)
3120 "Pipe the message body in the current buffer through PROGRAM."
3123 (when (message-goto-body)
3124 (narrow-to-region (point) (point-max)))
3125 (shell-command-on-region
3126 (point-min) (point-max) program nil t
))))
3128 (defun message-rename-buffer (&optional enter-string
)
3129 "Rename the *message* buffer to \"*message* RECIPIENT\".
3130 If the function is run with a prefix, it will ask for a new buffer
3131 name, rather than giving an automatic name."
3132 (interactive "Pbuffer name: ")
3135 (goto-char (point-min))
3136 (narrow-to-region (point)
3137 (search-forward mail-header-separator nil
'end
))
3139 (if (message-news-p) (message-fetch-field "Newsgroups")
3140 (message-fetch-field "To"))
3143 (if (string-match "," mail-to
)
3144 (concat (substring mail-to
0 (match-beginning 0)) ", ...")
3146 (name-default (concat "*message* " mail-trimmed-to
))
3147 (name (if enter-string
3148 (read-string "New buffer name: " name-default
)
3150 (rename-buffer name t
)))))
3152 (defun message-fill-yanked-message (&optional justifyp
)
3153 "Fill the paragraphs of a message yanked into this one.
3154 Numeric argument means justify as well."
3157 (goto-char (point-min))
3158 (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
3159 (let ((fill-prefix message-yank-prefix
))
3160 (fill-individual-paragraphs (point) (point-max) justifyp
))))
3162 (defun message-indent-citation ()
3163 "Modify text just inserted from a message to be cited.
3164 The inserted text should be the region.
3165 When this function returns, the region is again around the modified text.
3167 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3168 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3169 (let ((start (point)))
3170 ;; Remove unwanted headers.
3171 (when message-ignored-cited-headers
3176 (if (search-forward "\n\n" nil t
)
3179 (message-remove-header message-ignored-cited-headers t
)
3180 (when (= (point-min) (point-max))
3181 (setq all-removed t
))
3182 (goto-char (point-max)))
3186 ;; Delete blank lines at the start of the buffer.
3187 (while (and (point-min)
3190 (message-delete-line))
3191 ;; Delete blank lines at the end of the buffer.
3192 (goto-char (point-max))
3195 (while (and (zerop (forward-line -
1))
3197 (message-delete-line))
3198 ;; Do the indentation.
3199 (if (null message-yank-prefix
)
3200 (indent-rigidly start
(mark t
) message-indentation-spaces
)
3203 (while (< (point) (mark t
))
3204 (if (or (looking-at ">") (looking-at "^$"))
3205 (insert message-yank-cited-prefix
)
3206 (insert message-yank-prefix
))
3210 (defun message-yank-original (&optional arg
)
3211 "Insert the message being replied to, if any.
3212 Puts point before the text and mark after.
3213 Normally indents each nonblank line ARG spaces (default 3). However,
3214 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3216 This function uses `message-cite-function' to do the actual citing.
3218 Just \\[universal-argument] as argument means don't indent, insert no
3219 prefix, and don't delete any headers."
3221 (let ((modified (buffer-modified-p)))
3222 (when (and message-reply-buffer
3223 message-cite-function
)
3224 (delete-windows-on message-reply-buffer t
)
3225 (push-mark (save-excursion
3226 (insert-buffer-substring message-reply-buffer
)
3229 (funcall message-cite-function
))
3230 (message-exchange-point-and-mark)
3234 (setq message-checksum
(message-checksum))))))
3236 (defun message-yank-buffer (buffer)
3237 "Insert BUFFER into the current buffer and quote it."
3238 (interactive "bYank buffer: ")
3239 (let ((message-reply-buffer (get-buffer buffer
)))
3240 (save-window-excursion
3241 (message-yank-original))))
3243 (defun message-buffers ()
3244 "Return a list of active message buffers."
3247 (dolist (buffer (buffer-list t
))
3249 (when (and (eq major-mode
'message-mode
)
3250 (null message-sent-message-via
))
3251 (push (buffer-name buffer
) buffers
))))
3252 (nreverse buffers
)))
3254 (defun message-cite-original-without-signature ()
3255 "Cite function in the standard Message manner."
3256 (let* ((start (point))
3259 (when message-indent-citation-function
3260 (if (listp message-indent-citation-function
)
3261 message-indent-citation-function
3262 (list message-indent-citation-function
))))
3263 ;; This function may be called by `gnus-summary-yank-message' and
3264 ;; may insert a different article from the original. So, we will
3265 ;; modify the value of `message-reply-headers' with that article.
3266 (message-reply-headers
3268 (narrow-to-region start end
)
3269 (message-narrow-to-head-1)
3271 (or (message-fetch-field "subject") "none")
3272 (message-fetch-field "from")
3273 (message-fetch-field "date")
3274 (message-fetch-field "message-id" t
)
3275 (message-fetch-field "references")
3277 (mml-quote-region start end
)
3281 (when (re-search-backward message-signature-separator start t
)
3282 ;; Also peel off any blank lines before the signature.
3284 (while (looking-at "^[ \t]*$")
3287 (delete-region (point) end
)
3288 (unless (search-backward "\n\n" start t
)
3289 ;; Insert a blank line if it is peeled off.
3293 (funcall (pop functions
)))
3294 (when message-citation-line-function
3297 (funcall message-citation-line-function
))))
3299 (eval-when-compile (defvar mail-citation-hook
)) ;Compiler directive
3300 (defun message-cite-original ()
3301 "Cite function in the standard Message manner."
3302 (if (and (boundp 'mail-citation-hook
)
3304 (run-hooks 'mail-citation-hook
)
3305 (let* ((start (point))
3308 (when message-indent-citation-function
3309 (if (listp message-indent-citation-function
)
3310 message-indent-citation-function
3311 (list message-indent-citation-function
))))
3312 ;; This function may be called by `gnus-summary-yank-message' and
3313 ;; may insert a different article from the original. So, we will
3314 ;; modify the value of `message-reply-headers' with that article.
3315 (message-reply-headers
3317 (narrow-to-region start end
)
3318 (message-narrow-to-head-1)
3320 (or (message-fetch-field "subject") "none")
3321 (message-fetch-field "from")
3322 (message-fetch-field "date")
3323 (message-fetch-field "message-id" t
)
3324 (message-fetch-field "references")
3326 (mml-quote-region start end
)
3329 (funcall (pop functions
)))
3330 (when message-citation-line-function
3333 (funcall message-citation-line-function
)))))
3335 (defun message-insert-citation-line ()
3336 "Insert a simple citation line."
3337 (when message-reply-headers
3338 (insert (mail-header-from message-reply-headers
) " writes:")
3342 (defun message-position-on-field (header &rest afters
)
3343 (let ((case-fold-search t
))
3346 (goto-char (point-min))
3349 (concat "^" (regexp-quote mail-header-separator
) "$"))
3350 (match-beginning 0)))
3351 (goto-char (point-min))
3352 (if (re-search-forward (concat "^" (regexp-quote header
) ":") nil t
)
3354 (re-search-forward "^[^ \t]" nil
'move
)
3356 (skip-chars-backward "\n")
3359 (not (re-search-forward
3360 (concat "^" (regexp-quote (car afters
)) ":")
3364 (re-search-forward "^[^ \t]" nil
'move
)
3365 (beginning-of-line))
3366 (insert header
": \n")
3370 (defun message-remove-signature ()
3371 "Remove the signature from the text between point and mark.
3372 The text will also be indented the normal way."
3374 (let ((start (point))
3376 (if (not (re-search-forward message-signature-separator
(mark t
) t
))
3377 ;; No signature here, so we just indent the cited text.
3378 (message-indent-citation)
3379 ;; Find the last non-empty line.
3381 (while (looking-at "[ \t]*$")
3384 (setq mark
(set-marker (make-marker) (point)))
3386 (message-indent-citation)
3387 ;; Enable undoing the deletion.
3389 (delete-region mark
(mark t
))
3390 (set-marker mark nil
)))))
3395 ;;; Sending messages
3398 (defun message-send-and-exit (&optional arg
)
3399 "Send message like `message-send', then, if no errors, exit from mail buffer."
3401 (let ((buf (current-buffer))
3402 (actions message-exit-actions
))
3403 (when (and (message-send arg
)
3405 (if message-kill-buffer-on-exit
3408 (when (eq buf
(current-buffer))
3409 (message-bury buf
)))
3410 (message-do-actions actions
)
3413 (defun message-dont-send ()
3414 "Don't send the message you have been editing.
3415 Instead, just auto-save the buffer and then bury it."
3417 (set-buffer-modified-p t
)
3419 (let ((actions message-postpone-actions
))
3420 (message-bury (current-buffer))
3421 (message-do-actions actions
)))
3423 (defun message-kill-buffer ()
3424 "Kill the current buffer."
3426 (when (or (not (buffer-modified-p))
3427 (yes-or-no-p "Message modified; kill anyway? "))
3428 (let ((actions message-kill-actions
)
3429 (draft-article message-draft-article
)
3430 (auto-save-file-name buffer-auto-save-file-name
)
3431 (file-name buffer-file-name
)
3432 (modified (buffer-modified-p)))
3433 (setq buffer-file-name nil
)
3434 (kill-buffer (current-buffer))
3435 (when (and (or (and auto-save-file-name
3436 (file-exists-p auto-save-file-name
))
3438 (file-exists-p file-name
)))
3440 ;; If the message buffer has lived in a dedicated window,
3441 ;; `kill-buffer' has killed the frame. Thus the
3442 ;; `yes-or-no-p' may show up in a lowered frame. Make sure
3443 ;; that the user can see the question by raising the
3446 (yes-or-no-p (format "Remove the backup file%s? "
3447 (if modified
" too" "")))))
3449 (delete-file auto-save-file-name
))
3450 (let ((message-draft-article draft-article
))
3451 (message-disassociate-draft)))
3452 (message-do-actions actions
))))
3454 (defun message-bury (buffer)
3455 "Bury this mail BUFFER."
3456 (let ((newbuf (other-buffer buffer
)))
3457 (bury-buffer buffer
)
3458 (if (and (window-dedicated-p (selected-window))
3459 (not (null (delq (selected-frame) (visible-frame-list)))))
3460 (delete-frame (selected-frame))
3461 (switch-to-buffer newbuf
))))
3463 (defun message-send (&optional arg
)
3464 "Send the message in the current buffer.
3465 If `message-interactive' is non-nil, wait for success indication or
3466 error messages, and inform user.
3467 Otherwise any failure is reported in a message back to the user from
3469 The usage of ARG is defined by the instance that called Message.
3470 It should typically alter the sending method in some way or other."
3472 ;; Make it possible to undo the coming changes.
3474 (let ((inhibit-read-only t
))
3475 (put-text-property (point-min) (point-max) 'read-only nil
))
3476 (message-fix-before-sending)
3477 (run-hooks 'message-send-hook
)
3478 (message message-sending-message
)
3479 (let ((alist message-send-method-alist
)
3481 elem sent dont-barf-on-no-method
3482 (message-options message-options
))
3483 (message-options-set-recipient)
3485 (setq elem
(pop alist
)))
3486 (when (funcall (cadr elem
))
3487 (when (and (or (not (memq (car elem
)
3488 message-sent-message-via
))
3489 (message-fetch-field "supersedes")
3490 (if (or (message-gnksa-enable-p 'multiple-copies
)
3491 (not (eq (car elem
) 'news
)))
3494 "Already sent message via %s; resend? "
3496 (error "Denied posting -- multiple copies")))
3497 (setq success
(funcall (caddr elem
) arg
)))
3501 (let ((fcc (message-fetch-field "Fcc"))
3502 (gcc (message-fetch-field "Gcc")))
3504 (or (eq message-allow-no-recipients
'always
)
3505 (and (not (eq message-allow-no-recipients
'never
))
3506 (setq dont-barf-on-no-method
3508 (format "No receiver, perform %s anyway? "
3509 (cond ((and fcc gcc
) "Fcc and Gcc")
3512 (error "No methods specified to send by"))
3513 (when (or dont-barf-on-no-method
3517 (run-hooks 'message-sent-hook
))
3518 (message "Sending...done")
3519 ;; Mark the buffer as unmodified and delete auto-save.
3520 (set-buffer-modified-p nil
)
3521 (delete-auto-save-file-if-necessary t
)
3522 (message-disassociate-draft)
3523 ;; Delete other mail buffers and stuff.
3524 (message-do-send-housekeeping)
3525 (message-do-actions message-send-actions
)
3529 (defun message-send-via-mail (arg)
3530 "Send the current message via mail."
3531 (message-send-mail arg
))
3533 (defun message-send-via-news (arg)
3534 "Send the current message via news."
3535 (funcall message-send-news-function arg
))
3537 (defmacro message-check
(type &rest forms
)
3538 "Eval FORMS if TYPE is to be checked."
3539 `(or (message-check-element ,type
)
3543 (put 'message-check
'lisp-indent-function
1)
3544 (put 'message-check
'edebug-form-spec
'(form body
))
3546 (defun message-text-with-property (prop)
3547 "Return a list of all points where the text has PROP."
3549 (point (point-min)))
3551 (while (< point
(point-max))
3552 (when (get-text-property point prop
)
3553 (push point points
))
3557 (defun message-fix-before-sending ()
3558 "Do various things to make the message nice before sending it."
3559 ;; Make sure there's a newline at the end of the message.
3560 (goto-char (point-max))
3563 ;; Make the hidden headers visible.
3564 (let ((points (message-text-with-property 'message-hidden
)))
3566 (goto-char (car points
))
3567 (dolist (point points
)
3568 (add-text-properties point
(1+ point
)
3569 '(invisible nil intangible nil
)))))
3570 ;; Make invisible text visible.
3571 ;; It doesn't seem as if this is useful, since the invisible property
3572 ;; is clobbered by an after-change hook anyhow.
3573 (message-check 'invisible-text
3574 (let ((points (message-text-with-property 'invisible
)))
3576 (goto-char (car points
))
3577 (dolist (point points
)
3578 (put-text-property point
(1+ point
) 'invisible nil
)
3579 (message-overlay-put (message-make-overlay point
(1+ point
))
3581 (unless (yes-or-no-p
3582 "Invisible text found and made visible; continue sending? ")
3583 (error "Invisible text found and made visible")))))
3584 (message-check 'illegible-text
3587 (skip-chars-forward mm-7bit-chars
)
3589 (when (let ((char (char-after)))
3590 (or (< (mm-char-int char
) 128)
3591 (and (mm-multibyte-p)
3592 (memq (char-charset char
)
3593 '(eight-bit-control eight-bit-graphic
3595 (not (get-text-property
3596 (point) 'untranslated-utf-8
)))))
3597 (message-overlay-put (message-make-overlay (point) (1+ (point)))
3601 (skip-chars-forward mm-7bit-chars
))
3604 (gnus-multiple-choice
3605 "Non-printable characters found. Continue sending?"
3606 '((?d
"Remove non-printable characters and send")
3607 (?r
"Replace non-printable characters with dots and send")
3608 (?i
"Ignore non-printable characters and send")
3609 (?e
"Continue editing"))))
3611 (error "Non-printable characters"))
3613 (skip-chars-forward mm-7bit-chars
)
3615 (when (let ((char (char-after)))
3616 (or (< (mm-char-int char
) 128)
3617 (and (mm-multibyte-p)
3618 ;; FIXME: Wrong for Emacs 23 (unicode) and for
3619 ;; things like undecable utf-8. Should at least
3620 ;; use find-coding-systems-region.
3621 (memq (char-charset char
)
3622 '(eight-bit-control eight-bit-graphic
3624 (not (get-text-property
3625 (point) 'untranslated-utf-8
)))))
3627 (message-kill-all-overlays)
3629 (when (eq choice ?r
)
3632 (skip-chars-forward mm-7bit-chars
))))))
3634 (defun message-add-action (action &rest types
)
3635 "Add ACTION to be performed when doing an exit of type TYPES."
3637 (add-to-list (intern (format "message-%s-actions" (pop types
)))
3640 (defun message-delete-action (action &rest types
)
3641 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
3644 (set (setq var
(intern (format "message-%s-actions" (pop types
))))
3645 (delq action
(symbol-value var
))))))
3647 (defun message-do-actions (actions)
3648 "Perform all actions in ACTIONS."
3649 ;; Now perform actions on successful sending.
3653 ;; A simple function.
3654 ((functionp (car actions
))
3655 (funcall (car actions
)))
3656 ;; Something to be evaled.
3658 (eval (car actions
)))))
3661 (defun message-send-mail-partially ()
3662 "Send mail as message/partial."
3663 ;; replace the header delimiter with a blank line
3664 (goto-char (point-min))
3666 (concat "^" (regexp-quote mail-header-separator
) "\n"))
3667 (replace-match "\n")
3668 (run-hooks 'message-send-mail-hook
)
3669 (let ((p (goto-char (point-min)))
3670 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
3671 (curbuf (current-buffer))
3672 (id (message-make-message-id)) (n 1)
3673 plist total header required-mail-headers
)
3675 (if (< (point-max) (+ p message-send-mail-partially-limit
))
3676 (goto-char (point-max))
3677 (goto-char (+ p message-send-mail-partially-limit
))
3679 (if (<= (point) p
) (forward-line 1))) ;; In case of bad message.
3682 (setq total
(length plist
))
3683 (push (point-max) plist
)
3684 (setq plist
(nreverse plist
))
3687 (setq p
(pop plist
))
3690 (copy-to-buffer tembuf p
(car plist
))
3692 (goto-char (point-min))
3695 (goto-char (point-min))
3696 (narrow-to-region (point) (point))
3699 (setq header
(buffer-substring (point-min) (point)))
3700 (goto-char (point-min))
3701 (narrow-to-region (point) (point))
3703 (message-remove-header "Mime-Version")
3704 (message-remove-header "Content-Type")
3705 (message-remove-header "Content-Transfer-Encoding")
3706 (message-remove-header "Message-ID")
3707 (message-remove-header "Lines")
3708 (goto-char (point-max))
3709 (insert "Mime-Version: 1.0\n")
3710 (setq header
(buffer-string)))
3711 (goto-char (point-max))
3712 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
3715 (let ((mail-header-separator ""))
3716 (when (memq 'Message-ID message-required-mail-headers
)
3717 (insert "Message-ID: " (message-make-message-id) "\n"))
3718 (when (memq 'Lines message-required-mail-headers
)
3719 (insert "Lines: " (message-make-lines) "\n"))
3720 (message-goto-subject)
3722 (insert (format " (%d/%d)" n total
))
3724 (mm-with-unibyte-current-buffer
3725 (funcall (or message-send-mail-real-function
3726 message-send-mail-function
))))
3728 (setq p
(pop plist
))
3730 (kill-buffer tembuf
))))
3732 (defun message-send-mail (&optional arg
)
3733 (require 'mail-utils
)
3734 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
3735 (case-fold-search nil
)
3736 (news (message-news-p))
3737 (mailbuf (current-buffer))
3738 (message-this-is-mail t
)
3739 (message-posting-charset
3740 (if (fboundp 'gnus-setup-posting-charset
)
3741 (gnus-setup-posting-charset nil
)
3742 message-posting-charset
))
3743 (headers message-required-mail-headers
))
3745 (message-narrow-to-headers)
3746 ;; Generate the Mail-Followup-To header if the header is not there...
3747 (if (and (message-subscribed-p)
3748 (not (mail-fetch-field "mail-followup-to")))
3751 (cons "Mail-Followup-To" (message-make-mail-followup-to))
3752 message-required-mail-headers
))
3753 ;; otherwise, delete the MFT header if the field is empty
3754 (when (equal "" (mail-fetch-field "mail-followup-to"))
3755 (message-remove-header "^Mail-Followup-To:")))
3756 ;; Insert some headers.
3757 (let ((message-deletable-headers
3758 (if news nil message-deletable-headers
)))
3759 (message-generate-headers headers
))
3760 ;; Let the user do all of the above.
3761 (run-hooks 'message-header-hook
))
3766 ;; Avoid copying text props (except hard newlines).
3767 (insert (with-current-buffer mailbuf
3768 (mml-buffer-substring-no-properties-except-hard-newlines
3769 (point-min) (point-max))))
3770 ;; Remove some headers.
3771 (message-encode-message-body)
3773 (message-narrow-to-headers)
3774 ;; We (re)generate the Lines header.
3775 (when (memq 'Lines message-required-mail-headers
)
3776 (message-generate-headers '(Lines)))
3777 ;; Remove some headers.
3778 (message-remove-header message-ignored-mail-headers t
)
3779 (let ((mail-parse-charset message-default-charset
))
3780 (mail-encode-encoded-word-buffer)))
3781 (goto-char (point-max))
3782 ;; require one newline at the end.
3783 (or (= (preceding-char) ?
\n)
3785 (message-cleanup-headers)
3786 ;; FIXME: we're inserting the courtesy copy after encoding.
3787 ;; This is wrong if the courtesy copy string contains
3788 ;; non-ASCII characters. -- jh
3791 (message-narrow-to-headers)
3793 (or (message-fetch-field "cc")
3794 (message-fetch-field "bcc")
3795 (message-fetch-field "to"))
3796 (let ((content-type (message-fetch-field
3801 (string= "text/plain"
3803 (mail-header-parse-content-type
3807 (message-fetch-field
3808 "content-transfer-encoding")))))))
3809 (message-insert-courtesy-copy))
3810 (if (or (not message-send-mail-partially-limit
)
3811 (< (buffer-size) message-send-mail-partially-limit
)
3812 (not (message-y-or-n-p
3813 "The message size is too large, split? "
3817 (/ (buffer-size) 1000) "KB, is too large.
3819 Some mail gateways (MTA's) bounce large messages. To avoid the
3820 problem, answer `y', and the message will be split into several
3821 smaller pieces, the size of each is about "
3822 (/ message-send-mail-partially-limit
1000)
3826 However, some mail readers (MUA's) can't read split messages, i.e.,
3827 mails in message/partially format. Answer `n', and the message will be
3830 The size limit is controlled by `message-send-mail-partially-limit'.
3831 If you always want Gnus to send messages in one piece, set
3832 `message-send-mail-partially-limit' to nil.
3834 (mm-with-unibyte-current-buffer
3835 (message "Sending via mail...")
3836 (funcall (or message-send-mail-real-function
3837 message-send-mail-function
)))
3838 (message-send-mail-partially)))
3839 (kill-buffer tembuf
))
3840 (set-buffer mailbuf
)
3841 (push 'mail message-sent-message-via
)))
3843 (defun message-send-mail-with-sendmail ()
3844 "Send off the prepared buffer with sendmail."
3845 (let ((errbuf (if message-interactive
3846 (message-generate-new-buffer-clone-locals
3849 resend-to-addresses delimline
)
3852 (let ((case-fold-search t
))
3854 (message-narrow-to-headers)
3855 (setq resend-to-addresses
(message-fetch-field "resent-to")))
3856 ;; Change header-delimiter to be what sendmail expects.
3857 (goto-char (point-min))
3859 (concat "^" (regexp-quote mail-header-separator
) "\n"))
3860 (replace-match "\n")
3862 (setq delimline
(point-marker))
3863 (run-hooks 'message-send-mail-hook
)
3864 ;; Insert an extra newline if we need it to work around
3865 ;; Sun's bug that swallows newlines.
3866 (goto-char (1+ delimline
))
3867 (when (eval message-mailer-swallows-blank-line
)
3869 (when message-interactive
3873 (let* ((default-directory "/")
3874 (coding-system-for-write message-send-coding-system
)
3876 'call-process-region
3878 (list (point-min) (point-max)
3879 (if (boundp 'sendmail-program
)
3881 "/usr/lib/sendmail")
3882 nil errbuf nil
"-oi")
3883 ;; Always specify who from,
3884 ;; since some systems have broken sendmails.
3885 ;; But some systems are more broken with -f, so
3886 ;; we'll let users override this.
3887 (if (null message-sendmail-f-is-evil
)
3888 (list "-f" (message-sendmail-envelope-from)))
3889 ;; These mean "report errors by mail"
3890 ;; and "deliver in background".
3891 (if (null message-interactive
) '("-oem" "-odb"))
3892 ;; Get the addresses from the message
3893 ;; unless this is a resend.
3894 ;; We must not do that for a resend
3895 ;; because we would find the original addresses.
3896 ;; For a resend, include the specific addresses.
3897 (if resend-to-addresses
3898 (list resend-to-addresses
)
3900 (unless (or (null cpr
) (and (numberp cpr
) (zerop cpr
)))
3901 (error "Sending...failed with exit value %d" cpr
)))
3902 (when message-interactive
3905 (goto-char (point-min))
3906 (while (re-search-forward "\n\n* *" nil t
)
3907 (replace-match "; "))
3908 (if (not (zerop (buffer-size)))
3909 (error "Sending...failed to %s"
3910 (buffer-string))))))
3911 (when (bufferp errbuf
)
3912 (kill-buffer errbuf
)))))
3914 (defun message-send-mail-with-qmail ()
3915 "Pass the prepared message buffer to qmail-inject.
3916 Refer to the documentation for the variable `message-send-mail-function'
3917 to find out how to use this."
3918 ;; replace the header delimiter with a blank line
3919 (goto-char (point-min))
3921 (concat "^" (regexp-quote mail-header-separator
) "\n"))
3922 (replace-match "\n")
3923 (run-hooks 'message-send-mail-hook
)
3926 (let ((coding-system-for-write message-send-coding-system
))
3928 'call-process-region
(point-min) (point-max)
3929 message-qmail-inject-program nil nil nil
3930 ;; qmail-inject's default behaviour is to look for addresses on the
3931 ;; command line; if there're none, it scans the headers.
3932 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
3934 ;; in general, ALL of qmail-inject's defaults are perfect for simply
3935 ;; reading a formatted (i. e., at least a To: or Resent-To header)
3936 ;; message from stdin.
3938 ;; qmail also has the advantage of not having been raped by
3939 ;; various vendors, so we don't have to allow for that, either --
3940 ;; compare this with message-send-mail-with-sendmail and weep
3941 ;; for sendmail's lost innocence.
3943 ;; all this is way cool coz it lets us keep the arguments entirely
3944 ;; free for -inject-arguments -- a big win for the user and for us
3945 ;; since we don't have to play that double-guessing game and the user
3946 ;; gets full control (no gestapo'ish -f's, for instance). --sj
3947 (if (functionp message-qmail-inject-args
)
3948 (funcall message-qmail-inject-args
)
3949 message-qmail-inject-args
)))
3950 ;; qmail-inject doesn't say anything on it's stdout/stderr,
3951 ;; we have to look at the retval instead
3953 (100 (error "qmail-inject reported permanent failure"))
3954 (111 (error "qmail-inject reported transient failure"))
3955 ;; should never happen
3956 (t (error "qmail-inject reported unknown failure"))))
3958 (defun message-send-mail-with-mh ()
3959 "Send the prepared message buffer with mh."
3960 (let ((mh-previous-window-config nil
)
3961 (name (mh-new-draft-name)))
3962 (setq buffer-file-name name
)
3963 ;; MH wants to generate these headers itself.
3964 (when message-mh-deletable-headers
3965 (let ((headers message-mh-deletable-headers
))
3967 (goto-char (point-min))
3968 (and (re-search-forward
3969 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
3970 (message-delete-line))
3972 (run-hooks 'message-send-mail-hook
)
3973 ;; Pass it on to mh.
3976 (defun message-smtpmail-send-it ()
3977 "Send the prepared message buffer with `smtpmail-send-it'.
3978 This only differs from `smtpmail-send-it' that this command evaluates
3979 `message-send-mail-hook' just before sending a message. It is useful
3980 if your ISP requires the POP-before-SMTP authentication. See the Gnus
3981 manual for details."
3982 (run-hooks 'message-send-mail-hook
)
3985 (defun message-canlock-generate ()
3986 "Return a string that is non-trivial to guess.
3987 Do not use this for anything important, it is cryptographically weak."
3989 (let (sha1-maximum-internal-length)
3990 (sha1 (concat (message-unique-id)
3991 (format "%x%x%x" (random) (random t
) (random))
3992 (prin1-to-string (recent-keys))
3993 (prin1-to-string (garbage-collect))))))
3995 (defun message-canlock-password ()
3996 "The password used by message for cancel locks.
3997 This is the value of `canlock-password', if that option is non-nil.
3998 Otherwise, generate and save a value for `canlock-password' first."
3999 (unless canlock-password
4000 (customize-save-variable 'canlock-password
(message-canlock-generate))
4001 (setq canlock-password-for-verify canlock-password
))
4004 (defun message-insert-canlock ()
4005 (when message-insert-canlock
4006 (message-canlock-password)
4007 (canlock-insert-header)))
4009 (defun message-send-news (&optional arg
)
4010 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4011 (case-fold-search nil
)
4012 (method (if (functionp message-post-method
)
4013 (funcall message-post-method arg
)
4014 message-post-method
))
4015 (newsgroups-field (save-restriction
4016 (message-narrow-to-headers-or-head)
4017 (message-fetch-field "Newsgroups")))
4018 (followup-field (save-restriction
4019 (message-narrow-to-headers-or-head)
4020 (message-fetch-field "Followup-To")))
4021 ;; BUG: We really need to get the charset for each name in the
4022 ;; Newsgroups and Followup-To lines to allow crossposting
4023 ;; between group namess with incompatible character sets.
4024 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4025 (group-field-charset
4026 (gnus-group-name-charset method newsgroups-field
))
4027 (followup-field-charset
4028 (gnus-group-name-charset method
(or followup-field
"")))
4029 (rfc2047-header-encoding-alist
4030 (append (when group-field-charset
4031 (list (cons "Newsgroups" group-field-charset
)))
4032 (when followup-field-charset
4033 (list (cons "Followup-To" followup-field-charset
)))
4034 rfc2047-header-encoding-alist
))
4035 (messbuf (current-buffer))
4036 (message-syntax-checks
4038 (listp message-syntax-checks
))
4039 (cons '(existing-newsgroups . disabled
)
4040 message-syntax-checks
)
4041 message-syntax-checks
))
4042 (message-this-is-news t
)
4043 (message-posting-charset
4044 (gnus-setup-posting-charset newsgroups-field
))
4046 (if (not (message-check-news-body-syntax))
4049 (message-narrow-to-headers)
4050 ;; Insert some headers.
4051 (message-generate-headers message-required-news-headers
)
4052 (message-insert-canlock)
4053 ;; Let the user do all of the above.
4054 (run-hooks 'message-header-hook
))
4055 ;; Note: This check will be disabled by the ".*" default value for
4056 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4057 (when (and group-field-charset
4058 (listp message-syntax-checks
))
4059 (setq message-syntax-checks
4060 (cons '(valid-newsgroups . disabled
)
4061 message-syntax-checks
)))
4062 (message-cleanup-headers)
4063 (if (not (let ((message-post-method method
))
4064 (message-check-news-syntax)))
4069 (buffer-disable-undo)
4071 ;; Avoid copying text props (except hard newlines).
4073 (with-current-buffer messbuf
4074 (mml-buffer-substring-no-properties-except-hard-newlines
4075 (point-min) (point-max))))
4076 (message-encode-message-body)
4077 ;; Remove some headers.
4079 (message-narrow-to-headers)
4080 ;; We (re)generate the Lines header.
4081 (when (memq 'Lines message-required-mail-headers
)
4082 (message-generate-headers '(Lines)))
4083 ;; Remove some headers.
4084 (message-remove-header message-ignored-news-headers t
)
4085 (let ((mail-parse-charset message-default-charset
))
4086 (mail-encode-encoded-word-buffer)))
4087 (goto-char (point-max))
4088 ;; require one newline at the end.
4089 (or (= (preceding-char) ?
\n)
4091 (let ((case-fold-search t
))
4092 ;; Remove the delimiter.
4093 (goto-char (point-min))
4095 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4096 (replace-match "\n")
4098 (run-hooks 'message-send-news-hook
)
4099 (gnus-open-server method
)
4100 (message "Sending news via %s..." (gnus-server-string method
))
4101 (setq result
(let ((mail-header-separator ""))
4102 (gnus-request-post method
))))
4103 (kill-buffer tembuf
))
4104 (set-buffer messbuf
)
4106 (push 'news message-sent-message-via
)
4107 (message "Couldn't send message via news: %s"
4108 (nnheader-get-report (car method
)))
4112 ;;; Header generation & syntax checking.
4115 (defun message-check-element (type)
4116 "Return non-nil if this TYPE is not to be checked."
4117 (if (eq message-syntax-checks
'dont-check-for-anything-just-trust-me
)
4119 (let ((able (assq type message-syntax-checks
)))
4121 (eq (cdr able
) 'disabled
)))))
4123 (defun message-check-news-syntax ()
4124 "Check the syntax of the message."
4128 ;; We narrow to the headers and check them first.
4131 (message-narrow-to-headers)
4132 (message-check-news-header-syntax))))))
4134 (defun message-check-news-header-syntax ()
4136 ;; Check Newsgroups header.
4137 (message-check 'newsgroups
4138 (let ((group (message-fetch-field "newsgroups")))
4141 (not (string-match "\\`[ \t]*\\'" group
)))
4144 "The newsgroups field is empty or missing. Posting is denied.")))))
4145 ;; Check the Subject header.
4146 (message-check 'subject
4147 (let* ((case-fold-search t
)
4148 (subject (message-fetch-field "subject")))
4151 (not (string-match "\\`[ \t]*\\'" subject
)))
4154 "The subject field is empty or missing. Posting is denied.")))))
4155 ;; Check for commands in Subject.
4156 (message-check 'subject-cmsg
4157 (if (string-match "^cmsg " (message-fetch-field "subject"))
4159 "The control code \"cmsg\" is in the subject. Really post? ")
4161 ;; Check long header lines.
4162 (message-check 'long-header-lines
4163 (let ((start (point))
4167 (while (and (not found
)
4168 (re-search-forward "^\\([^ \t:]+\\): " nil t
))
4169 (if (> (- (point) (match-beginning 0)) 998)
4171 length
(- (point) (match-beginning 0)))
4172 (setq header
(match-string-no-properties 1)))
4173 (setq start
(match-beginning 0))
4176 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
4179 ;; Check for multiple identical headers.
4180 (message-check 'multiple-headers
4182 (while (and (not found
)
4183 (re-search-forward "^[^ \t:]+: " nil t
))
4185 (or (re-search-forward
4190 (match-beginning 0) (- (match-end 0) 2))))
4195 (y-or-n-p (format "Multiple %s headers. Really post? " found
))
4197 ;; Check for Version and Sendsys.
4198 (message-check 'sendsys
4199 (if (re-search-forward "^Sendsys:\\|^Version:" nil t
)
4201 (format "The article contains a %s command. Really post? "
4202 (buffer-substring (match-beginning 0)
4203 (1- (match-end 0)))))
4205 ;; See whether we can shorten Followup-To.
4206 (message-check 'shorten-followup-to
4207 (let ((newsgroups (message-fetch-field "newsgroups"))
4208 (followup-to (message-fetch-field "followup-to"))
4210 (when (and newsgroups
4211 (string-match "," newsgroups
)
4216 (setq to
(completing-read
4217 "Followups to (default no Followup-To header): "
4220 (message-tokenize-header
4222 (goto-char (point-min))
4223 (insert "Followup-To: " to
"\n"))
4225 ;; Check "Shoot me".
4226 (message-check 'shoot
4227 (if (re-search-forward
4228 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t
)
4229 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
4231 ;; Check for Approved.
4232 (message-check 'approved
4233 (if (re-search-forward "^Approved:" nil t
)
4234 (y-or-n-p "The article contains an Approved header. Really post? ")
4236 ;; Check the Message-ID header.
4237 (message-check 'message-id
4238 (let* ((case-fold-search t
)
4239 (message-id (message-fetch-field "message-id" t
)))
4240 (or (not message-id
)
4241 ;; Is there an @ in the ID?
4242 (and (string-match "@" message-id
)
4243 ;; Is there a dot in the ID?
4244 (string-match "@[^.]*\\." message-id
)
4245 ;; Does the ID end with a dot?
4246 (not (string-match "\\.>" message-id
)))
4248 (format "The Message-ID looks strange: \"%s\". Really post? "
4250 ;; Check the Newsgroups & Followup-To headers.
4251 (message-check 'existing-newsgroups
4252 (let* ((case-fold-search t
)
4253 (newsgroups (message-fetch-field "newsgroups"))
4254 (followup-to (message-fetch-field "followup-to"))
4255 (groups (message-tokenize-header
4257 (concat newsgroups
"," followup-to
)
4259 (post-method (if (functionp message-post-method
)
4260 (funcall message-post-method
)
4261 message-post-method
))
4262 ;; KLUDGE to handle nnvirtual groups. Doing this right
4263 ;; would probably involve a new nnoo function.
4264 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
4265 (method (if (and (consp post-method
)
4266 (eq (car post-method
) 'nnvirtual
)
4267 gnus-message-group-art
)
4268 (let ((group (car (nnvirtual-find-group-art
4269 (car gnus-message-group-art
)
4270 (cdr gnus-message-group-art
)))))
4271 (gnus-find-method-for-group group
))
4275 (gnus-group-name-decode
4276 (gnus-group-real-name n
)
4277 (gnus-group-name-charset method n
)))
4278 (gnus-groups-from-server method
)))
4281 (when (and (not (equal (car groups
) "poster"))
4282 (not (member (car groups
) known-groups
))
4283 (not (member (car groups
) errors
)))
4284 (push (car groups
) errors
))
4287 ;; Gnus is not running.
4288 ((or (not (and (boundp 'gnus-active-hashtb
)
4289 gnus-active-hashtb
))
4290 (not (boundp 'gnus-read-active-file
)))
4292 ;; We don't have all the group names.
4293 ((and (or (not gnus-read-active-file
)
4294 (eq gnus-read-active-file
'some
))
4298 "Really use %s possibly unknown group%s: %s? "
4299 (if (= (length errors
) 1) "this" "these")
4300 (if (= (length errors
) 1) "" "s")
4301 (mapconcat 'identity errors
", "))))
4302 ;; There were no errors.
4305 ;; There are unknown groups.
4309 "Really post to %s unknown group%s: %s? "
4310 (if (= (length errors
) 1) "this" "these")
4311 (if (= (length errors
) 1) "" "s")
4312 (mapconcat 'identity errors
", ")))))))
4313 ;; Check continuation headers.
4314 (message-check 'continuation-headers
4315 (goto-char (point-min))
4316 (let ((do-posting t
))
4317 (while (re-search-forward "^[^ \t\n][^:\n]*$" nil t
)
4318 (if (y-or-n-p "Fix continuation lines? ")
4320 (goto-char (match-beginning 0))
4322 (unless (y-or-n-p "Send anyway? ")
4323 (setq do-posting nil
))))
4325 ;; Check the Newsgroups & Followup-To headers for syntax errors.
4326 (message-check 'valid-newsgroups
4327 (let ((case-fold-search t
)
4328 (headers '("Newsgroups" "Followup-To"))
4330 (while (and headers
(not error
))
4331 (when (setq header
(mail-fetch-field (car headers
)))
4335 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
4340 (not (string-match "\\.\\'\\|\\.\\." g
)))
4341 (message-tokenize-header header
","))))
4348 (format "The %s header looks odd: \"%s\". Really post? "
4349 (car headers
) header
)))))
4350 (message-check 'repeated-newsgroups
4351 (let ((case-fold-search t
)
4352 (headers '("Newsgroups" "Followup-To"))
4353 header error groups group
)
4356 (when (setq header
(mail-fetch-field (pop headers
)))
4357 (setq groups
(message-tokenize-header header
","))
4358 (while (setq group
(pop groups
))
4359 (when (member group groups
)
4365 (format "Group %s is repeated in headers. Really post? " error
)))))
4366 ;; Check the From header.
4367 (message-check 'from
4368 (let* ((case-fold-search t
)
4369 (from (message-fetch-field "from"))
4373 (message "There is no From line. Posting is denied.")
4375 ((or (not (string-match
4377 (setq ad
(nth 1 (mail-extract-address-components
4378 from
))))) ;larsi@ifi
4379 (string-match "\\.\\." ad
) ;larsi@ifi..uio
4380 (string-match "@\\." ad
) ;larsi@.ifi.uio
4381 (string-match "\\.$" ad
) ;larsi@ifi.uio.
4382 (not (string-match "^[^@]+@[^@]+$" ad
)) ;larsi.ifi.uio
4383 (string-match "(.*).*(.*)" from
)) ;(lars) (lars)
4385 "Denied posting -- the From looks strange: \"%s\"." from
)
4387 ((let ((addresses (rfc822-addresses from
)))
4388 (while (and addresses
4389 (not (eq (string-to-char (car addresses
)) ?\
()))
4390 (setq addresses
(cdr addresses
)))
4393 "Denied posting -- bad From address: \"%s\"." from
)
4396 ;; Check the Reply-To header.
4397 (message-check 'reply-to
4398 (let* ((case-fold-search t
)
4399 (reply-to (message-fetch-field "reply-to"))
4404 ((string-match "," reply-to
)
4406 (format "Multiple Reply-To addresses: \"%s\". Really post? "
4408 ((or (not (string-match
4410 (setq ad
(nth 1 (mail-extract-address-components
4411 reply-to
))))) ;larsi@ifi
4412 (string-match "\\.\\." ad
) ;larsi@ifi..uio
4413 (string-match "@\\." ad
) ;larsi@.ifi.uio
4414 (string-match "\\.$" ad
) ;larsi@ifi.uio.
4415 (not (string-match "^[^@]+@[^@]+$" ad
)) ;larsi.ifi.uio
4416 (string-match "(.*).*(.*)" reply-to
)) ;(lars) (lars)
4419 "The Reply-To looks strange: \"%s\". Really post? "
4423 (defun message-check-news-body-syntax ()
4425 ;; Check for long lines.
4426 (message-check 'long-lines
4427 (goto-char (point-min))
4429 (concat "^" (regexp-quote mail-header-separator
) "$"))
4433 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
4436 (< (- (point) p
) 80)))
4437 (zerop (forward-line 1))))
4441 "You have lines longer than 79 characters. Really post? ")))
4442 ;; Check whether the article is empty.
4443 (message-check 'empty
4444 (goto-char (point-min))
4446 (concat "^" (regexp-quote mail-header-separator
) "$"))
4449 (goto-char (point-max))
4450 (re-search-backward message-signature-separator nil t
)
4452 (or (re-search-backward "[^ \n\t]" b t
)
4453 (if (message-gnksa-enable-p 'empty-article
)
4454 (y-or-n-p "Empty article. Really post? ")
4455 (message "Denied posting -- Empty article.")
4457 ;; Check for control characters.
4458 (message-check 'control-chars
4459 (if (re-search-forward
4460 (mm-string-as-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
4463 "The article contains control characters. Really post? ")
4465 ;; Check excessive size.
4466 (message-check 'size
4467 (if (> (buffer-size) 60000)
4469 (format "The article is %d octets long. Really post? "
4472 ;; Check whether any new text has been added.
4473 (message-check 'new-text
4475 (not message-checksum
)
4476 (not (eq (message-checksum) message-checksum
))
4477 (if (message-gnksa-enable-p 'quoted-text-only
)
4479 "It looks like no new text has been added. Really post? ")
4480 (message "Denied posting -- no new text has been added.")
4482 ;; Check the length of the signature.
4483 (message-check 'signature
4484 (goto-char (point-max))
4485 (if (> (count-lines (point) (point-max)) 5)
4488 "Your .sig is %d lines; it should be max 4. Really post? "
4489 (1- (count-lines (point) (point-max)))))
4491 ;; Ensure that text follows last quoted portion.
4492 (message-check 'quoting-style
4493 (goto-char (point-max))
4494 (let ((no-problem t
))
4495 (when (search-backward-regexp "^>[^\n]*\n" nil t
)
4496 (setq no-problem
(search-forward-regexp "^[ \t]*[^>\n]" nil t
)))
4499 (if (message-gnksa-enable-p 'quoted-text-only
)
4500 (y-or-n-p "Your text should follow quoted text. Really post? ")
4502 (goto-char (point-min))
4504 (concat "^" (regexp-quote mail-header-separator
) "$"))
4505 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t
)
4506 (y-or-n-p "Your text should follow quoted text. Really post? ")
4507 (message "Denied posting -- only quoted text.")
4510 (defun message-checksum ()
4511 "Return a \"checksum\" for the current buffer."
4514 (goto-char (point-min))
4516 (concat "^" (regexp-quote mail-header-separator
) "$"))
4518 (when (not (looking-at "[ \t\n]"))
4519 (setq sum
(logxor (ash sum
1) (if (natnump sum
) 0 1)
4524 (defun message-do-fcc ()
4525 "Process Fcc headers in the current buffer."
4526 (let ((case-fold-search t
)
4527 (buf (current-buffer))
4529 (mml-externalize-attachments message-fcc-externalize-attachments
))
4532 (message-narrow-to-headers)
4533 (setq file
(message-fetch-field "fcc" t
)))
4535 (set-buffer (get-buffer-create " *message temp*"))
4537 (insert-buffer-substring buf
)
4538 (message-encode-message-body)
4540 (message-narrow-to-headers)
4541 (while (setq file
(message-fetch-field "fcc" t
))
4543 (message-remove-header "fcc" nil t
))
4544 (let ((mail-parse-charset message-default-charset
)
4545 (rfc2047-header-encoding-alist
4546 (cons '("Newsgroups" . default
)
4547 rfc2047-header-encoding-alist
)))
4548 (mail-encode-encoded-word-buffer)))
4549 (goto-char (point-min))
4550 (when (re-search-forward
4551 (concat "^" (regexp-quote mail-header-separator
) "$")
4553 (replace-match "" t t
))
4554 ;; Process FCC operations.
4556 (setq file
(pop list
))
4557 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file
)
4558 ;; Pipe the article to the program in question.
4559 (call-process-region (point-min) (point-max) shell-file-name
4560 nil nil nil shell-command-switch
4561 (match-string 1 file
))
4562 ;; Save the article.
4563 (setq file
(expand-file-name file
))
4564 (unless (file-exists-p (file-name-directory file
))
4565 (make-directory (file-name-directory file
) t
))
4566 (if (and message-fcc-handler-function
4567 (not (eq message-fcc-handler-function
'rmail-output
)))
4568 (funcall message-fcc-handler-function file
)
4569 (if (and (file-readable-p file
) (mail-file-babyl-p file
))
4570 (rmail-output file
1 nil t
)
4571 (let ((mail-use-rfc822 t
))
4572 (rmail-output file
1 t t
))))))
4573 (kill-buffer (current-buffer))))))
4575 (defun message-output (filename)
4576 "Append this article to Unix/babyl mail file FILENAME."
4577 (if (and (file-readable-p filename
)
4578 (mail-file-babyl-p filename
))
4579 (gnus-output-to-rmail filename t
)
4580 (gnus-output-to-mail filename t
)))
4582 (defun message-cleanup-headers ()
4583 "Do various automatic cleanups of the headers."
4584 ;; Remove empty lines in the header.
4586 (message-narrow-to-headers)
4587 ;; Remove blank lines.
4588 (while (re-search-forward "^[ \t]*\n" nil t
)
4589 (replace-match "" t t
))
4591 ;; Correct Newsgroups and Followup-To headers: Change sequence of
4592 ;; spaces to comma and eliminate spaces around commas. Eliminate
4593 ;; embedded line breaks.
4594 (goto-char (point-min))
4595 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t
)
4599 (if (re-search-forward "^[^ \t]" nil t
)
4603 (goto-char (point-min))
4604 (while (re-search-forward "\n[ \t]+" nil t
)
4605 (replace-match " " t t
)) ;No line breaks (too confusing)
4606 (goto-char (point-min))
4607 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t
)
4608 (replace-match "," t t
))
4609 (goto-char (point-min))
4610 ;; Remove trailing commas.
4611 (when (re-search-forward ",+$" nil t
)
4612 (replace-match "" t t
))))))
4614 (eval-when-compile (require 'parse-time
))
4615 (defun message-make-date (&optional now
)
4616 "Make a valid data header.
4617 If NOW, use that time instead."
4618 (require 'parse-time
)
4619 (let* ((now (or now
(current-time)))
4620 (zone (nth 8 (decode-time now
)))
4624 (setq zone
(- zone
)))
4626 ;; The day name of the %a spec is locale-specific. Pfff.
4627 (format "%s, " (capitalize (car (rassoc (nth 6 (decode-time now
))
4628 parse-time-weekdays
))))
4629 (format-time-string "%d" now
)
4630 ;; The month name of the %b spec is locale-specific. Pfff.
4632 (capitalize (car (rassoc (nth 4 (decode-time now
))
4633 parse-time-months
))))
4634 (format-time-string "%Y %H:%M:%S " now
)
4635 ;; We do all of this because XEmacs doesn't have the %z spec.
4636 (format "%s%02d%02d" sign
(/ zone
3600) (/ (% zone
3600) 60)))))
4638 (defun message-make-message-id ()
4639 "Make a unique Message-ID."
4640 (concat "<" (message-unique-id)
4641 (let ((psubject (save-excursion (message-fetch-field "subject")))
4643 (save-excursion (message-fetch-field "supersedes"))))
4645 (and message-reply-headers
4646 (mail-header-references message-reply-headers
)
4647 (mail-header-subject message-reply-headers
)
4650 (message-strip-subject-re
4651 (mail-header-subject message-reply-headers
))
4652 (message-strip-subject-re psubject
))))
4654 (string-match "_-_@" psupersedes
)))
4656 "@" (message-make-fqdn) ">"))
4658 (defvar message-unique-id-char nil
)
4660 ;; If you ever change this function, make sure the new version
4661 ;; cannot generate IDs that the old version could.
4662 ;; You might for example insert a "." somewhere (not next to another dot
4663 ;; or string boundary), or modify the "fsf" string.
4664 (defun message-unique-id ()
4665 ;; Don't use microseconds from (current-time), they may be unsupported.
4666 ;; Instead we use this randomly inited counter.
4667 (setq message-unique-id-char
4668 (%
(1+ (or message-unique-id-char
(logand (random t
) (1- (lsh 1 20)))))
4669 ;; (current-time) returns 16-bit ints,
4670 ;; and 2^16*25 just fits into 4 digits i base 36.
4672 (let ((tm (current-time)))
4674 (if (memq system-type
'(ms-dos emx vax-vms
))
4675 (let ((user (downcase (user-login-name))))
4676 (while (string-match "[^a-z0-9_]" user
)
4677 (aset user
(match-beginning 0) ?_
))
4679 (message-number-base36 (user-uid) -
1))
4680 (message-number-base36 (+ (car tm
)
4681 (lsh (% message-unique-id-char
25) 16)) 4)
4682 (message-number-base36 (+ (nth 1 tm
)
4683 (lsh (/ message-unique-id-char
25) 16)) 4)
4684 ;; Append a given name, because while the generated ID is unique
4685 ;; to this newsreader, other newsreaders might otherwise generate
4686 ;; the same ID via another algorithm.
4689 (defun message-number-base36 (num len
)
4694 (concat (message-number-base36 (/ num
36) (1- len
))
4695 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
4698 (defun message-make-organization ()
4699 "Make an Organization header."
4700 (let* ((organization
4701 (when message-user-organization
4702 (if (functionp message-user-organization
)
4703 (funcall message-user-organization
)
4704 message-user-organization
))))
4706 (mm-enable-multibyte)
4707 (cond ((stringp organization
)
4708 (insert organization
))
4709 ((and (eq t organization
)
4710 message-user-organization-file
4711 (file-exists-p message-user-organization-file
))
4712 (insert-file-contents message-user-organization-file
)))
4713 (goto-char (point-min))
4714 (while (re-search-forward "[\t\n]+" nil t
)
4715 (replace-match "" t t
))
4716 (unless (zerop (buffer-size))
4719 (defun message-make-lines ()
4720 "Count the number of lines and return numeric string."
4725 (int-to-string (count-lines (point) (point-max))))))
4727 (defun message-make-references ()
4728 "Return the References header for this message."
4729 (when message-reply-headers
4730 (let ((message-id (mail-header-message-id message-reply-headers
))
4731 (references (mail-header-references message-reply-headers
))
4733 (if (or references message-id
)
4734 (concat (or references
"") (and references
" ")
4738 (defun message-make-in-reply-to ()
4739 "Return the In-Reply-To header for this message."
4740 (when message-reply-headers
4741 (let ((from (mail-header-from message-reply-headers
))
4742 (date (mail-header-date message-reply-headers
))
4743 (msg-id (mail-header-message-id message-reply-headers
)))
4745 (let ((name (mail-extract-address-components from
)))
4746 (concat msg-id
(if msg-id
" (")
4750 (if (or (not date
) (string= date
""))
4751 "(unknown date)" date
)
4752 "\"" (if msg-id
")")))))))
4754 (defun message-make-distribution ()
4755 "Make a Distribution header."
4756 (let ((orig-distribution (message-fetch-reply-field "distribution")))
4757 (cond ((functionp message-distribution-function
)
4758 (funcall message-distribution-function
))
4759 (t orig-distribution
))))
4761 (defun message-make-expires ()
4762 "Return an Expires header based on `message-expires'."
4763 (let ((current (current-time))
4764 (future (* 1.0 message-expires
60 60 24)))
4765 ;; Add the future to current.
4766 (setcar current
(+ (car current
) (round (/ future
(expt 2 16)))))
4767 (setcar (cdr current
) (+ (nth 1 current
) (%
(round future
) (expt 2 16))))
4768 (message-make-date current
)))
4770 (defun message-make-path ()
4772 (let ((login-name (user-login-name)))
4773 (cond ((null message-user-path
)
4774 (concat (system-name) "!" login-name
))
4775 ((stringp message-user-path
)
4776 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
4777 (concat message-user-path
"!" login-name
))
4780 (defun message-make-from ()
4781 "Make a From header."
4782 (let* ((style message-from-style
)
4783 (login (message-make-address))
4785 (or (and (boundp 'user-full-name
)
4788 (when (string= fullname
"&")
4789 (setq fullname
(user-login-name)))
4791 (mm-enable-multibyte)
4794 (equal fullname
""))
4796 ((or (eq style
'angles
)
4797 (and (not (eq style
'parens
))
4798 ;; Use angles if no quoting is needed, or if parens would
4799 ;; need quoting too.
4800 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname
))
4801 (let ((tmp (concat fullname nil
)))
4802 (while (string-match "([^()]*)" tmp
)
4803 (aset tmp
(match-beginning 0) ?-
)
4804 (aset tmp
(1- (match-end 0)) ?-
))
4805 (string-match "[\\()]" tmp
)))))
4807 (goto-char (point-min))
4808 ;; Look for a character that cannot appear unquoted
4809 ;; according to RFC 822.
4810 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil
1)
4811 ;; Quote fullname, escaping specials.
4812 (goto-char (point-min))
4814 (while (re-search-forward "[\"\\]" nil
1)
4815 (replace-match "\\\\\\&" t
))
4817 (insert " <" login
">"))
4818 (t ; 'parens or default
4820 (let ((fullname-start (point)))
4822 (goto-char fullname-start
)
4823 ;; RFC 822 says \ and nonmatching parentheses
4824 ;; must be escaped in comments.
4825 ;; Escape every instance of ()\ ...
4826 (while (re-search-forward "[()\\]" nil
1)
4827 (replace-match "\\\\\\&" t
))
4828 ;; ... then undo escaping of matching parentheses,
4829 ;; including matching nested parentheses.
4830 (goto-char fullname-start
)
4831 (while (re-search-forward
4832 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
4834 (replace-match "\\1(\\3)" t
)
4835 (goto-char fullname-start
)))
4839 (defun message-make-sender ()
4840 "Return the \"real\" user address.
4841 This function tries to ignore all user modifications, and
4842 give as trustworthy answer as possible."
4843 (concat (user-login-name) "@" (system-name)))
4845 (defun message-make-address ()
4846 "Make the address of the user."
4847 (or (message-user-mail-address)
4848 (concat (user-login-name) "@" (message-make-domain))))
4850 (defun message-user-mail-address ()
4851 "Return the pertinent part of `user-mail-address'."
4852 (when (and user-mail-address
4853 (string-match "@.*\\." user-mail-address
))
4854 (if (string-match " " user-mail-address
)
4855 (nth 1 (mail-extract-address-components user-mail-address
))
4856 user-mail-address
)))
4858 (defun message-sendmail-envelope-from ()
4859 "Return the envelope from."
4860 (cond ((eq message-sendmail-envelope-from
'header
)
4861 (nth 1 (mail-extract-address-components
4862 (message-fetch-field "from"))))
4863 ((stringp message-sendmail-envelope-from
)
4864 message-sendmail-envelope-from
)
4866 (message-make-address))))
4868 (defun message-make-fqdn ()
4869 "Return user's fully qualified domain name."
4870 (let* ((system-name (system-name))
4871 (user-mail (message-user-mail-address))
4874 (string-match "@\\(.*\\)\\'" user-mail
))
4875 (match-string 1 user-mail
)))
4876 (case-fold-search t
))
4878 ((and message-user-fqdn
4879 (stringp message-user-fqdn
)
4880 (string-match message-valid-fqdn-regexp message-user-fqdn
)
4881 (not (string-match message-bogus-system-names message-user-fqdn
)))
4883 ;; `message-user-fqdn' seems to be valid
4884 ((and (string-match message-valid-fqdn-regexp system-name
)
4885 (not (string-match message-bogus-system-names system-name
)))
4886 ;; `system-name' returned the right result.
4888 ;; Try `mail-host-address'.
4889 ((and (boundp 'mail-host-address
)
4890 (stringp mail-host-address
)
4891 (string-match message-valid-fqdn-regexp mail-host-address
)
4892 (not (string-match message-bogus-system-names mail-host-address
)))
4894 ;; We try `user-mail-address' as a backup.
4896 (stringp user-domain
)
4897 (string-match message-valid-fqdn-regexp user-domain
)
4898 (not (string-match message-bogus-system-names user-domain
)))
4900 ;; Default to this bogus thing.
4903 ".i-did-not-set--mail-host-address--so-tickle-me")))))
4905 (defun message-make-host-name ()
4906 "Return the name of the host."
4907 (let ((fqdn (message-make-fqdn)))
4908 (string-match "^[^.]+\\." fqdn
)
4909 (substring fqdn
0 (1- (match-end 0)))))
4911 (defun message-make-domain ()
4912 "Return the domain name."
4913 (or mail-host-address
4914 (message-make-fqdn)))
4916 (defun message-to-list-only ()
4917 "Send a message to the list only.
4918 Remove all addresses but the list address from To and Cc headers."
4920 (let ((listaddr (message-make-mail-followup-to t
)))
4923 (message-remove-header "to")
4924 (message-remove-header "cc")
4925 (message-position-on-field "To" "X-Draft-From")
4926 (insert listaddr
)))))
4928 (defun message-make-mail-followup-to (&optional only-show-subscribed
)
4929 "Return the Mail-Followup-To header.
4930 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
4931 subscribed address (and not the additional To and Cc header contents)."
4932 (let* ((case-fold-search t
)
4933 (to (message-fetch-field "To"))
4934 (cc (message-fetch-field "cc"))
4935 (msg-recipients (concat to
(and to cc
", ") cc
))
4937 (mapcar 'mail-strip-quoted-names
4938 (message-tokenize-header msg-recipients
)))
4940 (if message-subscribed-address-file
4941 (let (begin end item re
)
4944 (insert-file-contents message-subscribed-address-file
)
4946 (setq begin
(point))
4949 (if (bolp) (setq end
(1- end
)))
4950 (setq item
(regexp-quote (buffer-substring begin end
)))
4951 (if re
(setq re
(concat re
"\\|" item
))
4952 (setq re
(concat "\\`\\(" item
))))
4953 (and re
(list (concat re
"\\)\\'"))))))))
4954 (mft-regexps (apply 'append message-subscribed-regexps
4955 (mapcar 'regexp-quote
4956 message-subscribed-addresses
)
4959 message-subscribed-address-functions
))))
4961 (let ((subscribed-lists nil
)
4963 (loop for recipient in recipients
4964 when
(loop for regexp in mft-regexps
4965 when
(string-match regexp recipient
) return t
)
4968 (if only-show-subscribed
4970 msg-recipients
))))))
4972 (defun message-idna-to-ascii-rhs-1 (header)
4973 "Interactively potentially IDNA encode domain names in HEADER."
4974 (let ((field (message-fetch-field header
))
4978 (mm-delete-duplicates
4979 (mapcar (lambda (rhs) (or (cadr (split-string rhs
"@")) ""))
4982 'car
(mail-header-parse-addresses field
))))))
4983 (setq ace
(downcase (idna-to-ascii rhs
)))
4984 (when (and (not (equal rhs ace
))
4985 (or (not (eq message-use-idna
'ask
))
4986 (y-or-n-p (format "Replace %s with %s in %s:? "
4988 (goto-char (point-min))
4989 (while (re-search-forward (concat "^" header
":") nil t
)
4990 (message-narrow-to-field)
4991 (while (search-forward (concat "@" rhs
) nil t
)
4992 (replace-match (concat "@" ace
) t t
))
4993 (goto-char (point-max))
4996 (defun message-idna-to-ascii-rhs ()
4997 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
4998 See `message-idna-encode'."
5000 (when message-use-idna
5003 (message-narrow-to-head)
5004 (message-idna-to-ascii-rhs-1 "From")
5005 (message-idna-to-ascii-rhs-1 "To")
5006 (message-idna-to-ascii-rhs-1 "Reply-To")
5007 (message-idna-to-ascii-rhs-1 "Mail-Reply-To")
5008 (message-idna-to-ascii-rhs-1 "Mail-Followup-To")
5009 (message-idna-to-ascii-rhs-1 "Cc")))))
5011 (defun message-generate-headers (headers)
5012 "Prepare article HEADERS.
5013 Headers already prepared in the buffer are not modified."
5014 (setq headers
(append headers message-required-headers
))
5016 (message-narrow-to-headers)
5017 (let* ((Date (message-make-date))
5018 (Message-ID (message-make-message-id))
5019 (Organization (message-make-organization))
5020 (From (message-make-from))
5021 (Path (message-make-path))
5024 (In-Reply-To (message-make-in-reply-to))
5025 (References (message-make-references))
5027 (Distribution (message-make-distribution))
5028 (Lines (message-make-lines))
5029 (User-Agent message-newsreader
)
5030 (Expires (message-make-expires))
5031 (case-fold-search t
)
5033 header value elem header-string
)
5034 ;; First we remove any old generated headers.
5035 (let ((headers message-deletable-headers
))
5036 (unless (buffer-modified-p)
5037 (setq headers
(delq 'Message-ID
(copy-sequence headers
))))
5039 (goto-char (point-min))
5040 (and (re-search-forward
5041 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
5042 (get-text-property (1+ (match-beginning 0)) 'message-deletable
)
5043 (message-delete-line))
5045 ;; Go through all the required headers and see if they are in the
5046 ;; articles already. If they are not, or are empty, they are
5047 ;; inserted automatically - except for Subject, Newsgroups and
5050 (goto-char (point-min))
5051 (setq elem
(pop headers
))
5053 (if (eq (car elem
) 'optional
)
5054 (setq header
(cdr elem
)
5056 (setq header
(car elem
)))
5058 (setq header-string
(if (stringp header
)
5060 (symbol-name header
)))
5061 (when (or (not (re-search-forward
5063 (regexp-quote (downcase header-string
))
5067 ;; The header was found. We insert a space after the
5068 ;; colon, if there is none.
5069 (if (/= (char-after) ?
) (insert " ") (forward-char 1))
5070 ;; Find out whether the header is empty.
5071 (looking-at "[ \t]*\n[^ \t]")))
5072 ;; So we find out what value we should insert.
5076 (eq (car elem
) 'optional
)
5077 (not (member header-string message-inserted-headers
)))
5078 ;; This is an optional header. If the cdr of this
5079 ;; is something that is nil, then we do not insert
5081 (setq header
(cdr elem
))
5082 (or (and (functionp (cdr elem
))
5083 (funcall (cdr elem
)))
5084 (and (boundp (cdr elem
))
5085 (symbol-value (cdr elem
)))))
5087 ;; The element is a cons. Either the cdr is a
5088 ;; string to be inserted verbatim, or it is a
5089 ;; function, and we insert the value returned from
5091 (or (and (stringp (cdr elem
))
5093 (and (functionp (cdr elem
))
5094 (funcall (cdr elem
)))))
5095 ((and (boundp header
)
5096 (symbol-value header
))
5097 ;; The element is a symbol. We insert the value
5098 ;; of this symbol, if any.
5099 (symbol-value header
))
5100 ((not (message-check-element
5101 (intern (downcase (symbol-name header
)))))
5102 ;; We couldn't generate a value for this header,
5103 ;; so we just ask the user.
5104 (read-from-minibuffer
5105 (format "Empty header for %s; enter value: " header
)))))
5106 ;; Finally insert the header.
5108 (not (equal value
"")))
5112 ;; This header didn't exist, so we insert it.
5113 (goto-char (point-max))
5115 (cdr (assq header message-header-format-alist
))))
5117 (funcall formatter header value
)
5118 (insert header-string
": " value
))
5119 ;; We check whether the value was ended by a
5120 ;; newline. If now, we insert one.
5124 ;; The value of this header was empty, so we clear
5125 ;; totally and insert the new value.
5126 (delete-region (point) (gnus-point-at-eol))
5127 ;; If the header is optional, and the header was
5128 ;; empty, we con't insert it anyway.
5130 (push header-string message-inserted-headers
)
5132 ;; Add the deletable property to the headers that require it.
5133 (and (memq header message-deletable-headers
)
5134 (progn (beginning-of-line) (looking-at "[^:]+: "))
5135 (add-text-properties
5136 (point) (match-end 0)
5137 '(message-deletable t face italic
) (current-buffer)))))))
5138 ;; Insert new Sender if the From is strange.
5139 (let ((from (message-fetch-field "from"))
5140 (sender (message-fetch-field "sender"))
5141 (secure-sender (message-make-sender)))
5143 (not (message-check-element 'sender
))
5146 (cadr (mail-extract-address-components from
)))
5147 (downcase secure-sender
)))
5152 (cadr (mail-extract-address-components sender
)))
5153 (downcase secure-sender
)))))
5154 (goto-char (point-min))
5155 ;; Rename any old Sender headers to Original-Sender.
5156 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t
)
5158 (insert "Original-")
5159 (beginning-of-line))
5160 (when (or (message-news-p)
5161 (string-match "@.+\\.." secure-sender
))
5162 (insert "Sender: " secure-sender
"\n"))))
5164 (message-idna-to-ascii-rhs))))
5166 (defun message-insert-courtesy-copy ()
5167 "Insert a courtesy message in mail copies of combined messages."
5171 (message-narrow-to-headers)
5172 (when (setq newsgroups
(message-fetch-field "newsgroups"))
5173 (goto-char (point-max))
5174 (insert "Posted-To: " newsgroups
"\n")))
5176 (when message-courtesy-message
5178 ((string-match "%s" message-courtesy-message
)
5179 (insert (format message-courtesy-message newsgroups
)))
5181 (insert message-courtesy-message
)))))))
5184 ;;; Setting up a message buffer
5187 (defun message-fill-address (header value
)
5189 (narrow-to-region (point) (point))
5190 (insert (capitalize (symbol-name header
))
5192 (if (consp value
) (car value
) value
)
5194 (narrow-to-region (point-min) (1- (point-max)))
5196 (goto-char (point-min))
5198 (skip-chars-forward "^,\"" (point-max))
5199 (if (or (eq (char-after) ?
,)
5202 (if (and (> (current-column) 78)
5208 (setq last
(1+ (point))))
5209 (setq last
(1+ (point)))))
5210 (setq quoted
(not quoted
)))
5213 (goto-char (point-max))
5217 (defun message-split-line ()
5218 "Split current line, moving portion beyond point vertically down.
5219 If the current line has `message-yank-prefix', insert it on the new line."
5222 (split-line message-yank-prefix
) ;; Emacs 22.1+ supports arg.
5226 (defun message-fill-header (header value
)
5227 (let ((begin (point))
5230 (insert (capitalize (symbol-name header
))
5232 (if (consp value
) (car value
) value
)
5235 (narrow-to-region begin
(point))
5236 (fill-region-as-paragraph begin
(point))
5237 ;; Tapdance around looong Message-IDs.
5239 (when (looking-at "[ \t]*$")
5240 (message-delete-line))
5242 (re-search-forward ":" nil t
)
5243 (when (looking-at "\n[ \t]+")
5244 (replace-match " " t t
))
5245 (goto-char (point-max)))))
5247 (defun message-shorten-1 (list cut surplus
)
5248 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
5249 (setcdr (nthcdr (- cut
2) list
)
5250 (nthcdr (+ (- cut
2) surplus
1) list
)))
5252 (defun message-shorten-references (header references
)
5253 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
5254 If folding is disallowed, also check that the REFERENCES are less
5255 than 988 characters long, and if they are not, trim them until they are."
5262 (goto-char (point-min))
5263 ;; Cons a list of valid references.
5264 (while (re-search-forward "<[^>]+>" nil t
)
5265 (push (match-string 0) refs
))
5266 (setq refs
(nreverse refs
)
5267 count
(length refs
)))
5269 ;; If the list has more than MAXCOUNT elements, trim it by
5270 ;; removing the CUTth element and the required number of
5271 ;; elements that follow.
5272 (when (> count maxcount
)
5273 (let ((surplus (- count maxcount
)))
5274 (message-shorten-1 refs cut surplus
)
5275 (decf count surplus
)))
5277 ;; If folding is disallowed, make sure the total length (including
5278 ;; the spaces between) will be less than MAXSIZE characters.
5280 ;; Only disallow folding for News messages. At this point the headers
5281 ;; have not been generated, thus we use message-this-is-news directly.
5282 (when (and message-this-is-news message-cater-to-broken-inn
)
5284 (totalsize (+ (apply #'+ (mapcar #'length refs
))
5287 (ptr (nthcdr (1- cut
) refs
)))
5288 ;; Decide how many elements to cut off...
5289 (while (> totalsize maxsize
)
5290 (decf totalsize
(1+ (length (car ptr
))))
5292 (setq ptr
(cdr ptr
)))
5295 (message-shorten-1 refs cut surplus
))))
5297 ;; Finally, collect the references back into a string and insert
5298 ;; it into the buffer.
5299 (let ((refstring (mapconcat #'identity refs
" ")))
5300 (if (and message-this-is-news message-cater-to-broken-inn
)
5301 (insert (capitalize (symbol-name header
)) ": "
5303 (message-fill-header header refstring
)))))
5305 (defun message-position-point ()
5306 "Move point to where the user probably wants to find it."
5307 (message-narrow-to-headers)
5309 ((re-search-forward "^[^:]+:[ \t]*$" nil t
)
5310 (search-backward ":" )
5313 (if (eq (char-after) ?
)
5317 (goto-char (point-max))
5320 (unless (looking-at "$")
5324 (defcustom message-beginning-of-line t
5325 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
5326 goes to beginning of header values."
5328 :group
'message-buffers
5329 :link
'(custom-manual "(message)Movement")
5332 (defun message-beginning-of-line (&optional n
)
5333 "Move point to beginning of header value or to beginning of line.
5334 The prefix argument N is passed directly to `beginning-of-line'.
5336 This command is identical to `beginning-of-line' if point is
5337 outside the message header or if the option `message-beginning-of-line'
5340 If point is in the message header and on a (non-continued) header
5341 line, move point to the beginning of the header value or the beginning of line,
5342 whichever is closer. If point is already at beginning of line, move point to
5343 beginning of header value. Therefore, repeated calls will toggle point
5344 between beginning of field and beginning of line."
5346 (let ((zrs 'zmacs-region-stays
))
5347 (when (and (interactive-p) (boundp zrs
))
5349 (if (and message-beginning-of-line
5350 (message-point-in-header-p))
5351 (let* ((here (point))
5352 (bol (progn (beginning-of-line n
) (point)))
5353 (eol (gnus-point-at-eol))
5354 (eoh (re-search-forward ": *" eol t
)))
5356 (if (and eoh
(or (< eoh here
) (= bol here
)))
5358 (beginning-of-line n
)))
5360 (defun message-buffer-name (type &optional to group
)
5361 "Return a new (unique) buffer name based on TYPE and TO."
5363 ;; Generate a new buffer name The Message Way.
5364 ((eq message-generate-new-buffers
'unique
)
5365 (generate-new-buffer-name
5369 (or (car (mail-extract-address-components to
))
5372 (if (and group
(not (string= group
""))) (concat " on " group
) "")
5374 ;; Check whether `message-generate-new-buffers' is a function,
5375 ;; and if so, call it.
5376 ((functionp message-generate-new-buffers
)
5377 (funcall message-generate-new-buffers type to group
))
5378 ((eq message-generate-new-buffers
'unsent
)
5379 (generate-new-buffer-name
5380 (concat "*unsent " type
5383 (or (car (mail-extract-address-components to
))
5386 (if (and group
(not (string= group
""))) (concat " on " group
) "")
5388 ;; Use standard name.
5390 (format "*%s message*" type
))))
5392 (defun message-pop-to-buffer (name)
5393 "Pop to buffer NAME, and warn if it already exists and is modified."
5394 (let ((buffer (get-buffer name
)))
5396 (buffer-name buffer
))
5398 (set-buffer (pop-to-buffer buffer
))
5399 (when (and (buffer-modified-p)
5401 "Message already being composed; erase? ")))
5402 (error "Message being composed")))
5403 (set-buffer (pop-to-buffer name
)))
5407 (defun message-do-send-housekeeping ()
5408 "Kill old message buffers."
5409 ;; We might have sent this buffer already. Delete it from the
5411 (setq message-buffer-list
(delq (current-buffer) message-buffer-list
))
5412 (while (and message-max-buffers
5414 (>= (length message-buffer-list
) message-max-buffers
))
5415 ;; Kill the oldest buffer -- unless it has been changed.
5416 (let ((buffer (pop message-buffer-list
)))
5417 (when (and (buffer-name buffer
)
5418 (not (buffer-modified-p buffer
)))
5419 (kill-buffer buffer
))))
5420 ;; Rename the buffer.
5421 (if message-send-rename-function
5422 (funcall message-send-rename-function
)
5423 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
5425 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
5427 (let ((name (match-string 2 (buffer-name)))
5429 (if (not (or (null name
)
5430 (string-equal name
"mail")
5431 (string-equal name
"posting")))
5432 (setq name
(concat "*sent " name
"*"))
5433 (message-narrow-to-headers)
5434 (setq to
(message-fetch-field "to"))
5435 (setq group
(message-fetch-field "newsgroups"))
5439 (to (concat "*sent mail to "
5440 (or (car (mail-extract-address-components to
))
5442 ((and group
(not (string= group
"")))
5443 (concat "*sent posting on " group
"*"))
5444 (t "*sent mail*"))))
5445 (unless (string-equal name
(buffer-name))
5446 (rename-buffer name t
)))))
5447 ;; Push the current buffer onto the list.
5448 (when message-max-buffers
5449 (setq message-buffer-list
5450 (nconc message-buffer-list
(list (current-buffer))))))
5452 (defun message-mail-user-agent ()
5454 ((not message-mail-user-agent
) nil
)
5455 ((eq message-mail-user-agent t
) mail-user-agent
)
5456 (t message-mail-user-agent
))))
5457 (if (memq mua
'(message-user-agent gnus-user-agent
))
5461 (defun message-setup (headers &optional replybuffer actions switch-function
)
5462 (let ((mua (message-mail-user-agent))
5463 subject to field yank-action
)
5464 (if (not (and message-this-is-mail mua
))
5465 (message-setup-1 headers replybuffer actions
)
5467 (setq yank-action
(list 'insert-buffer replybuffer
)))
5468 (setq headers
(copy-sequence headers
))
5469 (setq field
(assq 'Subject headers
))
5471 (setq subject
(cdr field
))
5472 (setq headers
(delq field headers
)))
5473 (setq field
(assq 'To headers
))
5475 (setq to
(cdr field
))
5476 (setq headers
(delq field headers
)))
5477 (let ((mail-user-agent mua
))
5478 (compose-mail to subject
5479 (mapcar (lambda (item)
5481 (format "%s" (car item
))
5484 nil switch-function yank-action actions
)))))
5486 (defun message-headers-to-generate (headers included-headers excluded-headers
)
5487 "Return a list that includes all headers from HEADERS.
5488 If INCLUDED-HEADERS is a list, just include those headers. If if is
5489 t, include all headers. In any case, headers from EXCLUDED-HEADERS
5493 (dolist (header headers
)
5494 (setq header-name
(cond
5495 ((and (consp header
)
5496 (eq (car header
) 'optional
))
5497 ;; On the form (optional . Header)
5500 ;; On the form (Header . function)
5505 (when (and (not (memq header-name excluded-headers
))
5506 (or (eq included-headers t
)
5507 (memq header-name included-headers
)))
5508 (push header result
)))
5511 (defun message-setup-1 (headers &optional replybuffer actions
)
5512 (dolist (action actions
)
5514 (add-to-list 'message-send-actions
5515 `(apply ',(car action
) ',(cdr action
)))))
5516 (setq message-reply-buffer replybuffer
)
5517 (goto-char (point-min))
5518 ;; Insert all the headers.
5521 (alist message-header-format-alist
))
5523 (unless (assq (caar h
) message-header-format-alist
)
5524 (push (list (caar h
)) alist
))
5528 (delete-region (point) (progn (forward-line -
1) (point)))
5529 (when message-default-headers
5530 (insert message-default-headers
)
5531 (or (bolp) (insert ?
\n)))
5535 (insert mail-header-separator
"\n")
5539 (when (message-news-p)
5540 (when message-default-news-headers
5541 (insert message-default-news-headers
)
5542 (or (bolp) (insert ?
\n)))
5543 (when message-generate-headers-first
5544 (message-generate-headers
5545 (message-headers-to-generate
5546 (append message-required-news-headers
5547 message-required-headers
)
5548 message-generate-headers-first
5549 '(Lines Subject
)))))
5550 (when (message-mail-p)
5551 (when message-default-mail-headers
5552 (insert message-default-mail-headers
)
5553 (or (bolp) (insert ?
\n)))
5554 (when message-generate-headers-first
5555 (message-generate-headers
5556 (message-headers-to-generate
5557 (append message-required-mail-headers
5558 message-required-headers
)
5559 message-generate-headers-first
5560 '(Lines Subject
)))))
5561 (run-hooks 'message-signature-setup-hook
)
5562 (message-insert-signature)
5564 (message-narrow-to-headers)
5565 (run-hooks 'message-header-setup-hook
))
5566 (set-buffer-modified-p nil
)
5567 (setq buffer-undo-list nil
)
5568 (run-hooks 'message-setup-hook
)
5569 ;; Do this last to give it precedence over posting styles, etc.
5570 (when (message-mail-p)
5572 (message-narrow-to-headers)
5573 (if message-alternative-emails
5574 (message-use-alternative-email-as-from))))
5575 (message-position-point)
5578 (defun message-set-auto-save-file-name ()
5579 "Associate the message buffer with a file in the drafts directory."
5580 (when message-auto-save-directory
5581 (unless (file-directory-p
5582 (directory-file-name message-auto-save-directory
))
5583 (make-directory message-auto-save-directory t
))
5585 (setq message-draft-article
5586 (nndraft-request-associate-buffer "drafts"))
5587 (setq buffer-file-name
(expand-file-name
5588 (if (memq system-type
5589 '(ms-dos ms-windows windows-nt
5590 cygwin cygwin32 win32 w32
5594 message-auto-save-directory
))
5595 (setq buffer-auto-save-file-name
(make-auto-save-file-name)))
5596 (clear-visited-file-modtime)
5597 (setq buffer-file-coding-system message-draft-coding-system
)))
5599 (defun message-disassociate-draft ()
5600 "Disassociate the message buffer from the drafts directory."
5601 (when message-draft-article
5602 (nndraft-request-expire-articles
5603 (list message-draft-article
) "drafts" nil t
)))
5605 (defun message-insert-headers ()
5606 "Generate the headers for the article."
5610 (message-narrow-to-headers)
5611 (when (message-news-p)
5612 (message-generate-headers
5615 (copy-sequence message-required-news-headers
)))))
5616 (when (message-mail-p)
5617 (message-generate-headers
5620 (copy-sequence message-required-mail-headers
))))))))
5625 ;;; Commands for interfacing with message
5629 (defun message-mail (&optional to subject
5630 other-headers continue switch-function
5631 yank-action send-actions
)
5632 "Start editing a mail message to be sent.
5633 OTHER-HEADERS is an alist of header/value pairs."
5635 (let ((message-this-is-mail t
) replybuffer
)
5636 (unless (message-mail-user-agent)
5637 (message-pop-to-buffer (message-buffer-name "mail" to
)))
5638 ;; FIXME: message-mail should do something if YANK-ACTION is not
5640 (and (consp yank-action
) (eq (car yank-action
) 'insert-buffer
)
5641 (setq replybuffer
(nth 1 yank-action
)))
5644 `((To .
,(or to
"")) (Subject .
,(or subject
"")))
5645 (when other-headers other-headers
))
5646 replybuffer send-actions
)
5647 ;; FIXME: Should return nil if failure.
5651 (defun message-news (&optional newsgroups subject
)
5652 "Start editing a news article to be sent."
5654 (let ((message-this-is-news t
))
5655 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
))
5656 (message-setup `((Newsgroups .
,(or newsgroups
""))
5657 (Subject .
,(or subject
""))))))
5659 (defun message-get-reply-headers (wide &optional to-address address-headers
)
5660 (let (follow-to mct never-mct to cc author mft recipients
)
5661 ;; Find all relevant headers we need.
5663 (message-narrow-to-headers-or-head)
5664 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
5665 ;; message-header-synonyms.
5666 (setq to
(or (message-fetch-field "to")
5667 (and (loop for synonym in message-header-synonyms
5668 when
(memq 'Original-To synonym
)
5670 (message-fetch-field "original-to")))
5671 cc
(message-fetch-field "cc")
5672 mct
(message-fetch-field "mail-copies-to")
5673 author
(or (message-fetch-field "mail-reply-to")
5674 (message-fetch-field "reply-to")
5675 (message-fetch-field "from")
5677 mft
(and message-use-mail-followup-to
5678 (message-fetch-field "mail-followup-to"))))
5680 ;; Handle special values of Mail-Copies-To.
5682 (cond ((or (equal (downcase mct
) "never")
5683 (equal (downcase mct
) "nobody"))
5686 ((or (equal (downcase mct
) "always")
5687 (equal (downcase mct
) "poster"))
5688 (setq mct author
))))
5691 ;; Build (textual) list of new recipient addresses.
5694 (setq recipients
(concat ", " author
)))
5696 (dolist (header address-headers
)
5697 (let ((value (message-fetch-field header
)))
5699 (setq recipients
(concat recipients
", " value
))))))
5701 (string-match "[^ \t,]" mft
)
5702 (or (not (eq message-use-mail-followup-to
'ask
))
5703 (message-y-or-n-p "Obey Mail-Followup-To? " t
"\
5704 You should normally obey the Mail-Followup-To: header. In this
5705 article, it has the value of
5709 which directs your response to " (if (string-match "," mft
)
5710 "the specified addresses"
5711 "that address only") ".
5713 Most commonly, Mail-Followup-To is used by a mailing list poster to
5714 express that responses should be sent to just the list, and not the
5717 If a message is posted to several mailing lists, Mail-Followup-To may
5718 also be used to direct the following discussion to one list only,
5719 because discussions that are spread over several lists tend to be
5720 fragmented and very difficult to follow.
5722 Also, some source/announcement lists are not intended for discussion;
5723 responses here are directed to other addresses.
5725 You may customize the variable `message-use-mail-followup-to', if you
5726 want to get rid of this query permanently.")))
5727 (setq recipients
(concat ", " mft
)))
5729 (setq recipients
(concat ", " to-address
))
5730 ;; If the author explicitly asked for a copy, we don't deny it to them.
5731 (if mct
(setq recipients
(concat recipients
", " mct
))))
5733 (setq recipients
(if never-mct
"" (concat ", " author
)))
5734 (if to
(setq recipients
(concat recipients
", " to
)))
5735 (if cc
(setq recipients
(concat recipients
", " cc
)))
5736 (if mct
(setq recipients
(concat recipients
", " mct
)))))
5737 (if (>= (length recipients
) 2)
5738 ;; Strip the leading ", ".
5739 (setq recipients
(substring recipients
2)))
5740 ;; Squeeze whitespace.
5741 (while (string-match "[ \t][ \t]+" recipients
)
5742 (setq recipients
(replace-match " " t t recipients
)))
5743 ;; Remove addresses that match `rmail-dont-reply-to-names'.
5744 (let ((rmail-dont-reply-to-names message-dont-reply-to-names
))
5745 (setq recipients
(rmail-dont-reply-to recipients
)))
5746 ;; Perhaps "Mail-Copies-To: never" removed the only address?
5747 (if (string-equal recipients
"")
5748 (setq recipients author
))
5749 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
5753 (cons (downcase (mail-strip-quoted-names addr
)) addr
))
5754 (message-tokenize-header recipients
)))
5755 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
5756 (let ((s recipients
))
5758 (setq recipients
(delq (assoc (car (pop s
)) s
) recipients
))))
5760 ;; Remove hierarchical lists that are contained within each other,
5761 ;; if message-hierarchical-addresses is defined.
5762 (when message-hierarchical-addresses
5763 (let ((plain-addrs (mapcar 'car recipients
))
5766 (setq subaddrs
(assoc (car plain-addrs
)
5767 message-hierarchical-addresses
)
5768 plain-addrs
(cdr plain-addrs
))
5770 (setq subaddrs
(cdr subaddrs
))
5772 (setq recip
(assoc (car subaddrs
) recipients
)
5773 subaddrs
(cdr subaddrs
))
5775 (setq recipients
(delq recip recipients
))))))))
5777 ;; Build the header alist. Allow the user to be asked whether
5778 ;; or not to reply to all recipients in a wide reply.
5779 (setq follow-to
(list (cons 'To
(cdr (pop recipients
)))))
5780 (when (and recipients
5781 (or (not message-wide-reply-confirm-recipients
)
5782 (y-or-n-p "Reply to all recipients? ")))
5783 (setq recipients
(mapconcat
5784 (lambda (addr) (cdr addr
)) recipients
", "))
5785 (if (string-match "^ +" recipients
)
5786 (setq recipients
(substring recipients
(match-end 0))))
5787 (push (cons 'Cc recipients
) follow-to
)))
5791 (defun message-reply (&optional to-address wide
)
5792 "Start editing a reply to the article in the current buffer."
5794 (require 'gnus-sum
) ; for gnus-list-identifiers
5795 (let ((cur (current-buffer))
5796 from subject date reply-to to cc
5797 references message-id follow-to
5798 (inhibit-point-motion-hooks t
)
5799 (message-this-is-mail t
)
5802 (message-narrow-to-head-1)
5803 ;; Allow customizations to have their say.
5805 ;; This is a regular reply.
5806 (when (functionp message-reply-to-function
)
5808 (setq follow-to
(funcall message-reply-to-function
))))
5809 ;; This is a followup.
5810 (when (functionp message-wide-reply-to-function
)
5813 (funcall message-wide-reply-to-function
)))))
5814 (setq message-id
(message-fetch-field "message-id" t
)
5815 references
(message-fetch-field "references")
5816 date
(message-fetch-field "date")
5817 from
(message-fetch-field "from")
5818 subject
(or (message-fetch-field "subject") "none"))
5819 (when gnus-list-identifiers
5820 (setq subject
(message-strip-list-identifiers subject
)))
5821 (setq subject
(concat "Re: " (message-strip-subject-re subject
)))
5822 (when message-subject-trailing-was-query
5823 (setq subject
(message-strip-subject-trailing-was subject
)))
5825 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
5826 (string-match "<[^>]+>" gnus-warning
))
5827 (setq message-id
(match-string 0 gnus-warning
)))
5830 (setq follow-to
(message-get-reply-headers wide to-address
))))
5832 (unless (message-mail-user-agent)
5833 (message-pop-to-buffer
5834 (message-buffer-name
5835 (if wide
"wide reply" "reply") from
5836 (if wide to-address nil
))))
5838 (setq message-reply-headers
5839 (vector 0 subject from date message-id references
0 0 ""))
5842 `((Subject .
,subject
)
5847 (defun message-wide-reply (&optional to-address
)
5848 "Make a \"wide\" reply to the message in the current buffer."
5850 (message-reply to-address t
))
5853 (defun message-followup (&optional to-newsgroups
)
5854 "Follow up to the message in the current buffer.
5855 If TO-NEWSGROUPS, use that as the new Newsgroups line."
5857 (require 'gnus-sum
) ; for gnus-list-identifiers
5858 (let ((cur (current-buffer))
5859 from subject date reply-to mrt mct
5860 references message-id follow-to
5861 (inhibit-point-motion-hooks t
)
5862 (message-this-is-news t
)
5863 followup-to distribution newsgroups gnus-warning posted-to
)
5866 (goto-char (point-min))
5867 (if (search-forward "\n\n" nil t
)
5870 (when (functionp message-followup-to-function
)
5872 (funcall message-followup-to-function
)))
5873 (setq from
(message-fetch-field "from")
5874 date
(message-fetch-field "date")
5875 subject
(or (message-fetch-field "subject") "none")
5876 references
(message-fetch-field "references")
5877 message-id
(message-fetch-field "message-id" t
)
5878 followup-to
(message-fetch-field "followup-to")
5879 newsgroups
(message-fetch-field "newsgroups")
5880 posted-to
(message-fetch-field "posted-to")
5881 reply-to
(message-fetch-field "reply-to")
5882 mrt
(message-fetch-field "mail-reply-to")
5883 distribution
(message-fetch-field "distribution")
5884 mct
(message-fetch-field "mail-copies-to"))
5885 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
5886 (string-match "<[^>]+>" gnus-warning
))
5887 (setq message-id
(match-string 0 gnus-warning
)))
5888 ;; Remove bogus distribution.
5889 (when (and (stringp distribution
)
5890 (let ((case-fold-search t
))
5891 (string-match "world" distribution
)))
5892 (setq distribution nil
))
5893 (if gnus-list-identifiers
5894 (setq subject
(message-strip-list-identifiers subject
)))
5895 (setq subject
(concat "Re: " (message-strip-subject-re subject
)))
5896 (when message-subject-trailing-was-query
5897 (setq subject
(message-strip-subject-trailing-was subject
)))
5900 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups
))
5902 (setq message-reply-headers
5903 (vector 0 subject from date message-id references
0 0 ""))
5906 `((Subject .
,subject
)
5909 (list (cons 'Newsgroups to-newsgroups
)))
5910 (follow-to follow-to
)
5911 ((and followup-to message-use-followup-to
)
5914 ((equal (downcase followup-to
) "poster")
5915 (if (or (eq message-use-followup-to
'use
)
5916 (message-y-or-n-p "Obey Followup-To: poster? " t
"\
5917 You should normally obey the Followup-To: header.
5919 `Followup-To: poster' sends your response via e-mail instead of news.
5921 A typical situation where `Followup-To: poster' is used is when the poster
5922 does not read the newsgroup, so he wouldn't see any replies sent to it.
5924 You may customize the variable `message-use-followup-to', if you
5925 want to get rid of this query permanently."))
5927 (setq message-this-is-news nil
)
5928 (cons 'To
(or mrt reply-to from
"")))
5929 (cons 'Newsgroups newsgroups
)))
5931 (if (or (equal followup-to newsgroups
)
5932 (not (eq message-use-followup-to
'ask
))
5934 (concat "Obey Followup-To: " followup-to
"? ") t
"\
5935 You should normally obey the Followup-To: header.
5937 `Followup-To: " followup-to
"'
5938 directs your response to " (if (string-match "," followup-to
)
5939 "the specified newsgroups"
5940 "that newsgroup only") ".
5942 If a message is posted to several newsgroups, Followup-To is often
5943 used to direct the following discussion to one newsgroup only,
5944 because discussions that are spread over several newsgroup tend to
5945 be fragmented and very difficult to follow.
5947 Also, some source/announcement newsgroups are not intended for discussion;
5948 responses here are directed to other newsgroups.
5950 You may customize the variable `message-use-followup-to', if you
5951 want to get rid of this query permanently."))
5952 (cons 'Newsgroups followup-to
)
5953 (cons 'Newsgroups newsgroups
))))))
5955 `((Newsgroups .
,posted-to
)))
5957 `((Newsgroups .
,newsgroups
))))
5958 ,@(and distribution
(list (cons 'Distribution distribution
)))
5960 (not (or (equal (downcase mct
) "never")
5961 (equal (downcase mct
) "nobody"))))
5962 (list (cons 'Cc
(if (or (equal (downcase mct
) "always")
5963 (equal (downcase mct
) "poster"))
5964 (or mrt reply-to from
"")
5969 (defun message-is-yours-p ()
5970 "Non-nil means current article is yours.
5971 If you have added 'cancel-messages to `message-shoot-gnksa-feet', all articles
5972 are yours except those that have Cancel-Lock header not belonging to you.
5973 Instead of shooting GNKSA feet, you should modify `message-alternative-emails'
5974 regexp to match all of yours addresses."
5975 ;; Canlock-logic as suggested by Per Abrahamsen
5976 ;; <abraham@dina.kvl.dk>
5978 ;; IF article has cancel-lock THEN
5979 ;; IF we can verify it THEN
5982 ;; error: cancellock: article is not yours
5984 ;; Use old rules, comparing sender...
5987 (message-narrow-to-head-1)
5988 (if (message-fetch-field "Cancel-Lock")
5989 (if (null (canlock-verify))
5991 (error "Failed to verify Cancel-lock: This article is not yours"))
5994 (message-gnksa-enable-p 'cancel-messages
)
5995 (and (setq sender
(message-fetch-field "sender"))
5996 (string-equal (downcase sender
)
5997 (downcase (message-make-sender))))
5998 ;; Email address in From field equals to our address
5999 (and (setq from
(message-fetch-field "from"))
6001 (downcase (cadr (mail-extract-address-components from
)))
6002 (downcase (cadr (mail-extract-address-components
6003 (message-make-from))))))
6004 ;; Email address in From field matches
6005 ;; 'message-alternative-emails' regexp
6007 message-alternative-emails
6009 message-alternative-emails
6010 (cadr (mail-extract-address-components from
))))))))))
6013 (defun message-cancel-news (&optional arg
)
6014 "Cancel an article you posted.
6015 If ARG, allow editing of the cancellation message."
6017 (unless (message-news-p)
6018 (error "This is not a news article; canceling is impossible"))
6019 (let (from newsgroups message-id distribution buf
)
6021 ;; Get header info from original article.
6023 (message-narrow-to-head-1)
6024 (setq from
(message-fetch-field "from")
6025 newsgroups
(message-fetch-field "newsgroups")
6026 message-id
(message-fetch-field "message-id" t
)
6027 distribution
(message-fetch-field "distribution")))
6028 ;; Make sure that this article was written by the user.
6029 (unless (message-is-yours-p)
6030 (error "This article is not yours"))
6031 (when (yes-or-no-p "Do you really want to cancel this article? ")
6032 ;; Make control message.
6035 (setq buf
(set-buffer (get-buffer-create " *message cancel*"))))
6037 (insert "Newsgroups: " newsgroups
"\n"
6039 "Subject: cmsg cancel " message-id
"\n"
6040 "Control: cancel " message-id
"\n"
6042 (concat "Distribution: " distribution
"\n")
6044 mail-header-separator
"\n"
6045 message-cancel-message
)
6046 (run-hooks 'message-cancel-hook
)
6048 (message "Canceling your article...")
6049 (if (let ((message-syntax-checks
6050 'dont-check-for-anything-just-trust-me
))
6051 (funcall message-send-news-function
))
6052 (message "Canceling your article...done"))
6053 (kill-buffer buf
))))))
6056 (defun message-supersede ()
6057 "Start composing a message to supersede the current message.
6058 This is done simply by taking the old article and adding a Supersedes
6059 header line with the old Message-ID."
6061 (let ((cur (current-buffer)))
6062 ;; Check whether the user owns the article that is to be superseded.
6063 (unless (message-is-yours-p)
6064 (error "This article is not yours"))
6065 ;; Get a normal message buffer.
6066 (message-pop-to-buffer (message-buffer-name "supersede"))
6067 (insert-buffer-substring cur
)
6069 (message-narrow-to-head-1)
6070 ;; Remove unwanted headers.
6071 (when message-ignored-supersedes-headers
6072 (message-remove-header message-ignored-supersedes-headers t
))
6073 (goto-char (point-min))
6074 (if (not (re-search-forward "^Message-ID: " nil t
))
6075 (error "No Message-ID in this article")
6076 (replace-match "Supersedes: " t t
))
6077 (goto-char (point-max))
6078 (insert mail-header-separator
)
6083 (defun message-recover ()
6084 "Reread contents of current buffer from its last auto-save file."
6086 (let ((file-name (make-auto-save-file-name)))
6087 (cond ((save-window-excursion
6088 (if (not (eq system-type
'vax-vms
))
6089 (with-output-to-temp-buffer "*Directory*"
6090 (with-current-buffer standard-output
6091 (fundamental-mode)) ; for Emacs 20.4+
6092 (buffer-disable-undo standard-output
)
6093 (let ((default-directory "/"))
6095 "ls" nil standard-output nil
"-l" file-name
))))
6096 (yes-or-no-p (format "Recover auto save file %s? " file-name
)))
6097 (let ((buffer-read-only nil
))
6099 (insert-file-contents file-name nil
)))
6100 (t (error "message-recover cancelled")))))
6102 ;;; Washing Subject:
6104 (defun message-wash-subject (subject)
6105 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
6106 Previous forwarders, replyers, etc. may add it."
6109 (goto-char (point-min))
6110 ;; strip Re/Fwd stuff off the beginning
6111 (while (re-search-forward
6112 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t
)
6115 ;; and gnus-style forwards [foo@bar.com] subject
6116 (goto-char (point-min))
6117 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t
)
6121 (goto-char (point-max))
6122 (while (re-search-backward "([Ff][Ww][Dd])" nil t
)
6125 ;; and finally, any whitespace that was left-over
6126 (goto-char (point-min))
6127 (while (re-search-forward "^[ \t]+" nil t
)
6129 (goto-char (point-max))
6130 (while (re-search-backward "[ \t]+$" nil t
)
6135 ;;; Forwarding messages.
6137 (defvar message-forward-decoded-p nil
6138 "Non-nil means the original message is decoded.")
6140 (defun message-forward-subject-name-subject (subject)
6141 "Generate a SUBJECT for a forwarded message.
6142 The form is: [Source] Subject, where if the original message was mail,
6143 Source is the name of the sender, and if the original message was
6144 news, Source is the list of newsgroups is was posted to."
6145 (let* ((group (message-fetch-field "newsgroups"))
6146 (from (message-fetch-field "from"))
6149 (gnus-group-decoded-name group
)
6150 (or (and from
(car (gnus-extract-address-components from
)))
6153 (if message-forward-decoded-p
6155 (mail-decode-encoded-word-string prefix
))
6158 (defun message-forward-subject-author-subject (subject)
6159 "Generate a SUBJECT for a forwarded message.
6160 The form is: [Source] Subject, where if the original message was mail,
6161 Source is the sender, and if the original message was news, Source is
6162 the list of newsgroups is was posted to."
6163 (let* ((group (message-fetch-field "newsgroups"))
6166 (gnus-group-decoded-name group
)
6167 (or (message-fetch-field "from")
6170 (if message-forward-decoded-p
6172 (mail-decode-encoded-word-string prefix
))
6175 (defun message-forward-subject-fwd (subject)
6176 "Generate a SUBJECT for a forwarded message.
6177 The form is: Fwd: Subject, where Subject is the original subject of
6179 (if (string-match "^Fwd: " subject
)
6181 (concat "Fwd: " subject
)))
6183 (defun message-make-forward-subject ()
6184 "Return a Subject header suitable for the message in the current buffer."
6187 (message-narrow-to-head-1)
6188 (let ((funcs message-make-forward-subject-function
)
6189 (subject (message-fetch-field "Subject")))
6192 (if message-forward-decoded-p
6194 (mail-decode-encoded-word-string subject
))
6196 (if message-wash-forwarded-subjects
6197 (setq subject
(message-wash-subject subject
)))
6198 ;; Make sure funcs is a list.
6201 (setq funcs
(list funcs
)))
6202 ;; Apply funcs in order, passing subject generated by previous
6203 ;; func to the next one.
6205 (when (functionp (car funcs
))
6206 (setq subject
(funcall (car funcs
) subject
)))
6207 (setq funcs
(cdr funcs
)))
6211 (defvar gnus-article-decoded-p
))
6215 (defun message-forward (&optional news digest
)
6216 "Forward the current message via mail.
6217 Optional NEWS will use news to forward instead of mail.
6218 Optional DIGEST will use digest to forward."
6220 (let* ((cur (current-buffer))
6221 (message-forward-decoded-p
6222 (if (local-variable-p 'gnus-article-decoded-p
(current-buffer))
6223 gnus-article-decoded-p
;; In an article buffer.
6224 message-forward-decoded-p
))
6225 (subject (message-make-forward-subject)))
6227 (message-news nil subject
)
6228 (message-mail nil subject
))
6229 (message-forward-make-body cur digest
)))
6231 (defun message-forward-make-body-plain (forward-buffer)
6233 "\n-------------------- Start of forwarded message --------------------\n")
6234 (let ((b (point)) e
)
6237 (mm-disable-multibyte)
6239 (with-current-buffer forward-buffer
6240 (mm-with-unibyte-current-buffer (buffer-string))))
6241 (mm-enable-multibyte)
6243 (goto-char (point-min))
6244 (when (looking-at "From ")
6245 (replace-match "X-From-Line: "))
6249 "\n-------------------- End of forwarded message --------------------\n")
6250 (when message-forward-ignored-headers
6252 (narrow-to-region b e
)
6254 (narrow-to-region (point)
6255 (or (search-forward "\n\n" nil t
) (point)))
6256 (message-remove-header message-forward-ignored-headers t
)))))
6258 (defun message-forward-make-body-mime (forward-buffer)
6259 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
6260 (let ((b (point)) e
)
6262 (narrow-to-region (point) (point))
6263 (mml-insert-buffer forward-buffer
)
6264 (goto-char (point-min))
6265 (when (looking-at "From ")
6266 (replace-match "X-From-Line: "))
6267 (goto-char (point-max)))
6269 (insert "<#/part>\n")))
6271 (defun message-forward-make-body-mml (forward-buffer)
6272 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
6273 (let ((b (point)) e
)
6274 (if (not message-forward-decoded-p
)
6277 (mm-disable-multibyte)
6279 (with-current-buffer forward-buffer
6280 (mm-with-unibyte-current-buffer (buffer-string))))
6281 (mm-enable-multibyte)
6283 (goto-char (point-min))
6284 (when (looking-at "From ")
6285 (replace-match "X-From-Line: "))
6288 (narrow-to-region (point) (point))
6289 (mml-insert-buffer forward-buffer
)
6290 (goto-char (point-min))
6291 (when (looking-at "From ")
6292 (replace-match "X-From-Line: "))
6293 (goto-char (point-max))))
6295 (insert "<#/mml>\n")
6296 (when (and (not message-forward-decoded-p
)
6297 message-forward-ignored-headers
)
6299 (narrow-to-region b e
)
6301 (narrow-to-region (point)
6302 (or (search-forward "\n\n" nil t
) (point)))
6303 (message-remove-header message-forward-ignored-headers t
)))))
6305 (defun message-forward-make-body-digest-plain (forward-buffer)
6307 "\n-------------------- Start of forwarded message --------------------\n")
6308 (let ((b (point)) e
)
6309 (mml-insert-buffer forward-buffer
)
6312 "\n-------------------- End of forwarded message --------------------\n")))
6314 (defun message-forward-make-body-digest-mime (forward-buffer)
6315 (insert "\n<#multipart type=digest>\n")
6316 (let ((b (point)) e
)
6317 (insert-buffer-substring forward-buffer
)
6319 (insert "<#/multipart>\n")
6321 (narrow-to-region b e
)
6323 (narrow-to-region (point)
6324 (or (search-forward "\n\n" nil t
) (point)))
6325 (delete-region (point-min) (point-max)))))
6327 (defun message-forward-make-body-digest (forward-buffer)
6328 (if message-forward-as-mime
6329 (message-forward-make-body-digest-mime forward-buffer
)
6330 (message-forward-make-body-digest-plain forward-buffer
)))
6333 (defun message-forward-make-body (forward-buffer &optional digest
)
6334 ;; Put point where we want it before inserting the forwarded
6336 (if message-forward-before-signature
6338 (goto-char (point-max)))
6340 (message-forward-make-body-digest forward-buffer
)
6341 (if message-forward-as-mime
6342 (if (and message-forward-show-mml
6343 (not (and (eq message-forward-show-mml
'best
)
6344 (with-current-buffer forward-buffer
6345 (goto-char (point-min))
6347 "Content-Type: *multipart/\\(signed\\|encrypted\\)"
6349 (message-forward-make-body-mml forward-buffer
)
6350 (message-forward-make-body-mime forward-buffer
))
6351 (message-forward-make-body-plain forward-buffer
)))
6352 (message-position-point))
6355 (defun message-forward-rmail-make-body (forward-buffer)
6356 (save-window-excursion
6357 (set-buffer forward-buffer
)
6358 ;; Rmail doesn't have rmail-msg-restore-non-pruned-header in Emacs
6359 ;; 20. FIXIT, or we drop support for rmail in Emacs 20.
6360 (if (rmail-msg-is-pruned)
6361 (rmail-msg-restore-non-pruned-header)))
6362 (message-forward-make-body forward-buffer
))
6364 (eval-when-compile (defvar rmail-enable-mime-composing
))
6366 ;; Fixme: Should have defcustom.
6368 (defun message-insinuate-rmail ()
6369 "Let RMAIL use message to forward."
6371 (setq rmail-enable-mime-composing t
)
6372 (setq rmail-insert-mime-forwarded-message-function
6373 'message-forward-rmail-make-body
))
6376 (defun message-resend (address)
6377 "Resend the current article to ADDRESS."
6379 (list (message-read-from-minibuffer "Resend message to: ")))
6380 (message "Resending message to %s..." address
)
6382 (let ((cur (current-buffer))
6384 ;; We first set up a normal mail buffer.
6385 (unless (message-mail-user-agent)
6386 (set-buffer (get-buffer-create " *message resend*"))
6388 (let ((message-this-is-mail t
)
6390 (message-setup `((To .
,address
))))
6391 ;; Insert our usual headers.
6392 (message-generate-headers '(From Date To Message-ID
))
6393 (message-narrow-to-headers)
6394 ;; Remove X-Draft-From header etc.
6395 (message-remove-header message-ignored-mail-headers t
)
6396 ;; Rename them all to "Resent-*".
6397 (goto-char (point-min))
6398 (while (re-search-forward "^[A-Za-z]" nil t
)
6403 (delete-region (point) (point-max))
6405 ;; Insert the message to be resent.
6406 (insert-buffer-substring cur
)
6407 (goto-char (point-min))
6408 (search-forward "\n\n")
6411 (narrow-to-region beg
(point))
6412 (message-remove-header message-ignored-resent-headers t
)
6413 (goto-char (point-max)))
6414 (insert mail-header-separator
)
6415 ;; Rename all old ("Also-")Resent headers.
6416 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t
)
6419 ;; Quote any "From " lines at the beginning.
6421 (when (looking-at "From ")
6422 (replace-match "X-From-Line: "))
6424 (let ((message-inhibit-body-encoding t
)
6425 message-required-mail-headers
6426 rfc2047-encode-encoded-words
)
6427 (message-send-mail))
6428 (kill-buffer (current-buffer)))
6429 (message "Resending message to %s...done" address
)))
6432 (defun message-bounce ()
6433 "Re-mail the current message.
6434 This only makes sense if the current message is a bounce message that
6435 contains some mail you have written which has been bounced back to
6438 (let ((handles (mm-dissect-buffer t
))
6440 (message-pop-to-buffer (message-buffer-name "bounce"))
6441 (if (stringp (car handles
))
6442 ;; This is a MIME bounce.
6443 (mm-insert-part (car (last handles
)))
6444 ;; This is a non-MIME bounce, so we try to remove things
6446 (mm-insert-part handles
)
6448 (goto-char (point-min))
6449 (re-search-forward "\n\n+" nil t
)
6450 (setq boundary
(point))
6451 ;; We remove everything before the bounced mail.
6452 (if (or (re-search-forward message-unsent-separator nil t
)
6454 (search-forward "\n\n" nil
'move
)
6455 (re-search-backward "^Return-Path:.*\n" boundary t
)))
6458 (delete-region (point-min)
6459 (if (re-search-forward "^[^ \n\t]+:" nil t
)
6462 (goto-char boundary
)
6463 (when (re-search-backward "^.?From .*\n" nil t
)
6464 (delete-region (match-beginning 0) (match-end 0)))))
6465 (mm-enable-multibyte)
6467 (message-narrow-to-head-1)
6468 (message-remove-header message-ignored-bounced-headers t
)
6469 (goto-char (point-max))
6470 (insert mail-header-separator
))
6471 (message-position-point)))
6474 ;;; Interactive entry points for new message buffers.
6478 (defun message-mail-other-window (&optional to subject
)
6479 "Like `message-mail' command, but display mail buffer in another window."
6481 (unless (message-mail-user-agent)
6482 (let ((pop-up-windows t
)
6483 (special-display-buffer-names nil
)
6484 (special-display-regexps nil
)
6485 (same-window-buffer-names nil
)
6486 (same-window-regexps nil
))
6487 (message-pop-to-buffer (message-buffer-name "mail" to
))))
6488 (let ((message-this-is-mail t
))
6489 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
"")))
6490 nil nil
'switch-to-buffer-other-window
)))
6493 (defun message-mail-other-frame (&optional to subject
)
6494 "Like `message-mail' command, but display mail buffer in another frame."
6496 (unless (message-mail-user-agent)
6497 (let ((pop-up-frames t
)
6498 (special-display-buffer-names nil
)
6499 (special-display-regexps nil
)
6500 (same-window-buffer-names nil
)
6501 (same-window-regexps nil
))
6502 (message-pop-to-buffer (message-buffer-name "mail" to
))))
6503 (let ((message-this-is-mail t
))
6504 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
"")))
6505 nil nil
'switch-to-buffer-other-frame
)))
6508 (defun message-news-other-window (&optional newsgroups subject
)
6509 "Start editing a news article to be sent."
6511 (let ((pop-up-windows t
)
6512 (special-display-buffer-names nil
)
6513 (special-display-regexps nil
)
6514 (same-window-buffer-names nil
)
6515 (same-window-regexps nil
))
6516 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
)))
6517 (let ((message-this-is-news t
))
6518 (message-setup `((Newsgroups .
,(or newsgroups
""))
6519 (Subject .
,(or subject
""))))))
6522 (defun message-news-other-frame (&optional newsgroups subject
)
6523 "Start editing a news article to be sent."
6525 (let ((pop-up-frames t
)
6526 (special-display-buffer-names nil
)
6527 (special-display-regexps nil
)
6528 (same-window-buffer-names nil
)
6529 (same-window-regexps nil
))
6530 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
)))
6531 (let ((message-this-is-news t
))
6532 (message-setup `((Newsgroups .
,(or newsgroups
""))
6533 (Subject .
,(or subject
""))))))
6537 ;; This code should be moved to underline.el (from which it is stolen).
6540 (defun bold-region (start end
)
6541 "Bold all nonblank characters in the region.
6542 Works by overstriking characters.
6543 Called from program, takes two arguments START and END
6544 which specify the range to operate on."
6547 (let ((end1 (make-marker)))
6548 (move-marker end1
(max start end
))
6549 (goto-char (min start end
))
6550 (while (< (point) end1
)
6551 (or (looking-at "[_\^@- ]")
6552 (insert (char-after) "\b"))
6553 (forward-char 1)))))
6556 (defun unbold-region (start end
)
6557 "Remove all boldness (overstruck characters) in the region.
6558 Called from program, takes two arguments START and END
6559 which specify the range to operate on."
6562 (let ((end1 (make-marker)))
6563 (move-marker end1
(max start end
))
6564 (goto-char (min start end
))
6565 (while (re-search-forward "\b" end1 t
)
6566 (if (eq (char-after) (char-after (- (point) 2)))
6567 (delete-char -
2))))))
6569 (defun message-exchange-point-and-mark ()
6570 "Exchange point and mark, but don't activate region if it was inactive."
6572 (message-mark-active-p)
6573 (exchange-point-and-mark))
6574 (setq mark-active nil
)))
6576 (defalias 'message-make-overlay
'make-overlay
)
6577 (defalias 'message-delete-overlay
'delete-overlay
)
6578 (defalias 'message-overlay-put
'overlay-put
)
6579 (defun message-kill-all-overlays ()
6580 (if (featurep 'xemacs
)
6581 (map-extents (lambda (extent ignore
) (delete-extent extent
)))
6582 (mapcar #'delete-overlay
(overlays-in (point-min) (point-max)))))
6584 ;; Support for toolbar
6586 (defvar tool-bar-map
)
6587 (defvar tool-bar-mode
))
6589 (defun message-tool-bar-local-item-from-menu (command icon in-map
&optional from-map
&rest props
)
6590 ;; We need to make tool bar entries in local keymaps with
6591 ;; `tool-bar-local-item-from-menu' in Emacs >= 22
6592 (if (fboundp 'tool-bar-local-item-from-menu
)
6593 (tool-bar-local-item-from-menu command icon in-map from-map props
)
6594 (tool-bar-add-item-from-menu command icon from-map props
)))
6596 (defun message-tool-bar-map ()
6597 (or message-tool-bar-map
6598 (setq message-tool-bar-map
6600 (condition-case nil
(require 'tool-bar
) (error nil
))
6601 (fboundp 'tool-bar-add-item-from-menu
)
6603 (let ((tool-bar-map (copy-keymap tool-bar-map
))
6604 (load-path (mm-image-load-path)))
6605 ;; Zap some items which aren't so relevant and take
6607 (dolist (key '(print-buffer kill-buffer save-buffer
6608 write-file dired open-file
))
6609 (define-key tool-bar-map
(vector key
) nil
))
6610 (message-tool-bar-local-item-from-menu
6611 'message-send-and-exit
"mail/send" tool-bar-map message-mode-map
)
6612 (message-tool-bar-local-item-from-menu
6613 'message-kill-buffer
"close" tool-bar-map message-mode-map
)
6614 (message-tool-bar-local-item-from-menu
6615 'message-dont-send
"cancel" tool-bar-map message-mode-map
)
6616 (message-tool-bar-local-item-from-menu
6617 'mml-attach-file
"attach" tool-bar-map mml-mode-map
)
6618 (message-tool-bar-local-item-from-menu
6619 'ispell-message
"spell" tool-bar-map message-mode-map
)
6620 (message-tool-bar-local-item-from-menu
6621 'mml-preview
"preview"
6622 tool-bar-map mml-mode-map
)
6623 (message-tool-bar-local-item-from-menu
6624 'message-insert-importance-high
"important"
6625 tool-bar-map message-mode-map
)
6626 (message-tool-bar-local-item-from-menu
6627 'message-insert-importance-low
"unimportant"
6628 tool-bar-map message-mode-map
)
6629 (message-tool-bar-local-item-from-menu
6630 'message-insert-disposition-notification-to
"receipt"
6631 tool-bar-map message-mode-map
)
6634 ;;; Group name completion.
6636 (defcustom message-newgroups-header-regexp
6637 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
6638 "Regexp that match headers that lists groups."
6642 (defcustom message-completion-alist
6643 (list (cons message-newgroups-header-regexp
'message-expand-group
)
6644 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name
)
6645 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
6646 . message-expand-name
)
6647 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
6648 . message-expand-name
))
6649 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
6652 :type
'(alist :key-type regexp
:value-type function
))
6654 (defcustom message-tab-body-function nil
6655 "*Function to execute when `message-tab' (TAB) is executed in the body.
6656 If nil, the function bound in `text-mode-map' or `global-map' is executed."
6659 :link
'(custom-manual "(message)Various Commands")
6660 :type
'(choice (const nil
)
6663 (defun message-tab ()
6664 "Complete names according to `message-completion-alist'.
6665 Execute function specified by `message-tab-body-function' when not in
6668 (let ((alist message-completion-alist
))
6670 (let ((mail-abbrev-mode-regexp (caar alist
)))
6671 (not (mail-abbrev-in-expansion-header-p))))
6672 (setq alist
(cdr alist
)))
6673 (funcall (or (cdar alist
) message-tab-body-function
6674 (lookup-key text-mode-map
"\t")
6675 (lookup-key global-map
"\t")
6676 'indent-relative
))))
6681 (let ((standard-output (current-buffer)))
6682 (eval '(display-completion-list nil
"")))
6683 (defalias 'message-display-completion-list
'display-completion-list
))
6684 (error ;; Don't use `wrong-number-of-arguments' here because of XEmacs.
6685 (defun message-display-completion-list (completions &optional ignore
)
6686 "Display the list of completions, COMPLETIONS, using `standard-output'."
6687 (display-completion-list completions
)))))
6689 (defun message-expand-group ()
6690 "Expand the group name under point."
6691 (let* ((b (save-excursion
6696 (skip-chars-forward "^:")
6699 (skip-chars-backward "^, \t\n") (point))))
6700 (completion-ignore-case t
)
6701 (string (buffer-substring b
(progn (skip-chars-forward "^,\t\n ")
6703 (hashtb (and (boundp 'gnus-active-hashtb
) gnus-active-hashtb
))
6704 (completions (all-completions string hashtb
))
6706 (delete-region b
(point))
6708 ((= (length completions
) 1)
6709 (if (string= (car completions
) string
)
6712 (message "Only matching group"))
6713 (insert (car completions
))))
6714 ((and (setq comp
(try-completion string hashtb
))
6715 (not (string= comp string
)))
6720 (message "No matching groups")
6721 (save-selected-window
6722 (pop-to-buffer "*Completions*")
6723 (buffer-disable-undo)
6724 (let ((buffer-read-only nil
))
6726 (let ((standard-output (current-buffer)))
6727 (message-display-completion-list (sort completions
'string
<)
6729 (setq buffer-read-only nil
)
6730 (goto-char (point-min))
6731 (delete-region (point) (progn (forward-line 3) (point))))))))))
6733 (defun message-expand-name ()
6734 (if (fboundp 'bbdb-complete-name
)
6735 (bbdb-complete-name)
6740 (defun message-talkative-question (ask question show
&rest text
)
6741 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
6742 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
6743 The following arguments may contain lists of values."
6745 (setq text
(message-flatten-list text
)))
6746 (save-window-excursion
6748 (with-output-to-temp-buffer " *MESSAGE information message*"
6749 (set-buffer " *MESSAGE information message*")
6750 (fundamental-mode) ; for Emacs 20.4+
6751 (mapcar 'princ text
)
6752 (goto-char (point-min))))
6753 (funcall ask question
))
6754 (funcall ask question
)))
6756 (defun message-flatten-list (list)
6757 "Return a new, flat list that contains all elements of LIST.
6759 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
6762 (apply 'append
(mapcar 'message-flatten-list list
)))
6766 (defun message-generate-new-buffer-clone-locals (name &optional varstr
)
6767 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
6768 Then clone the local variables and values from the old buffer to the
6769 new one, cloning only the locals having a substring matching the
6771 (let ((oldbuf (current-buffer)))
6773 (set-buffer (generate-new-buffer name
))
6774 (message-clone-locals oldbuf varstr
)
6777 (defun message-clone-locals (buffer &optional varstr
)
6778 "Clone the local variables from BUFFER to the current buffer."
6779 (let ((locals (save-excursion
6781 (buffer-local-variables)))
6782 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address"))
6785 (when (and (consp local
)
6787 (string-match regexp
(symbol-name (car local
)))
6789 (string-match varstr
(symbol-name (car local
)))))
6791 (set (make-local-variable (car local
))
6799 (defvar message-inhibit-body-encoding nil
)
6801 (defun message-encode-message-body ()
6802 (unless message-inhibit-body-encoding
6803 (let ((mail-parse-charset (or mail-parse-charset
6804 message-default-charset
))
6805 (case-fold-search t
)
6806 lines content-type-p
)
6809 (narrow-to-region (point) (point-max))
6810 (let ((new (mml-generate-mime)))
6812 (delete-region (point-min) (point-max))
6814 (goto-char (point-min))
6815 (if (eq (aref new
0) ?
\n)
6817 (search-forward "\n\n")
6818 (setq lines
(buffer-substring (point-min) (1- (point))))
6819 (delete-region (point-min) (point))))))
6821 (message-narrow-to-headers-or-head)
6822 (message-remove-header "Mime-Version")
6823 (goto-char (point-max))
6824 (insert "MIME-Version: 1.0\n")
6827 (setq content-type-p
6829 (re-search-backward "^Content-Type:" nil t
))))
6831 (message-narrow-to-headers-or-head)
6832 (message-remove-first-header "Content-Type")
6833 (message-remove-first-header "Content-Transfer-Encoding"))
6834 ;; We always make sure that the message has a Content-Type
6835 ;; header. This is because some broken MTAs and MUAs get
6836 ;; awfully confused when confronted with a message with a
6837 ;; MIME-Version header and without a Content-Type header. For
6838 ;; instance, Solaris' /usr/bin/mail.
6839 (unless content-type-p
6840 (goto-char (point-min))
6841 ;; For unknown reason, MIME-Version doesn't exist.
6842 (when (re-search-forward "^MIME-Version:" nil t
)
6844 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
6846 (defun message-read-from-minibuffer (prompt &optional initial-contents
)
6847 "Read from the minibuffer while providing abbrev expansion."
6848 (if (fboundp 'mail-abbrevs-setup
)
6849 (let ((mail-abbrev-mode-regexp "")
6850 (minibuffer-setup-hook 'mail-abbrevs-setup
)
6851 (minibuffer-local-map message-minibuffer-local-map
))
6852 (read-from-minibuffer prompt initial-contents
))
6853 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook
)
6854 (minibuffer-local-map message-minibuffer-local-map
))
6855 (read-string prompt initial-contents
))))
6857 (defun message-use-alternative-email-as-from ()
6858 "Set From field of the outgoing message to the first matching
6859 address in `message-alternative-emails', looking at To, Cc and
6860 From headers in the original article."
6861 (require 'mail-utils
)
6862 (let* ((fields '("To" "Cc"))
6865 (mail-strip-quoted-names
6866 (mapconcat 'message-fetch-reply-field fields
","))
6870 (if (string-match message-alternative-emails
(car emails
))
6871 (setq email
(car emails
)
6874 (unless (or (not email
) (equal email user-mail-address
))
6875 (message-remove-header "From")
6876 (goto-char (point-max))
6877 (insert "From: " email
"\n"))))
6879 (defun message-options-get (symbol)
6880 (cdr (assq symbol message-options
)))
6882 (defun message-options-set (symbol value
)
6883 (let ((the-cons (assq symbol message-options
)))
6886 (setcdr the-cons value
)
6887 (setq message-options
(delq the-cons message-options
)))
6889 (push (cons symbol value
) message-options
))))
6892 (defun message-options-set-recipient ()
6894 (message-narrow-to-headers-or-head)
6895 (message-options-set 'message-sender
6896 (mail-strip-quoted-names
6897 (message-fetch-field "from")))
6898 (message-options-set 'message-recipients
6899 (mail-strip-quoted-names
6900 (let ((to (message-fetch-field "to"))
6901 (cc (message-fetch-field "cc"))
6902 (bcc (message-fetch-field "bcc")))
6905 (if (and to cc
) ", ")
6907 (if (and (or to cc
) bcc
) ", ")
6910 (defun message-hide-headers ()
6911 "Hide headers based on the `message-hidden-headers' variable."
6912 (let ((regexps (if (stringp message-hidden-headers
)
6913 (list message-hidden-headers
)
6914 message-hidden-headers
))
6915 (inhibit-point-motion-hooks t
)
6916 (after-change-functions nil
))
6920 (message-narrow-to-headers)
6921 (goto-char (point-min))
6923 (if (not (message-hide-header-p regexps
))
6924 (message-next-header)
6925 (let ((begin (point)))
6926 (message-next-header)
6927 (add-text-properties
6929 '(invisible t message-hidden t
))))))))))
6931 (defun message-hide-header-p (regexps)
6934 (when (eq (car regexps
) 'not
)
6937 (dolist (regexp regexps
)
6938 (setq result
(or result
(looking-at regexp
))))
6943 (when (featurep 'xemacs
)
6944 (require 'messagexmas
)
6945 (message-xmas-redefine))
6949 (run-hooks 'message-load-hook
)
6952 ;; coding: iso-8859-1
6955 ;; arch-tag: 94b32cac-4504-4b6c-8181-030ebf380ee0
6956 ;;; message.el ends here