1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: mail, news
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; This mode provides mail-sending facilities from within Emacs. It
28 ;; consists mainly of large chunks of code from the sendmail.el,
29 ;; gnus-msg.el and rnewspost.el files.
35 (defvar gnus-message-group-art
)
36 (defvar gnus-list-identifiers
)) ; gnus-sum is required where necessary
40 ;; This is apparently necessary even though things are autoloaded.
41 ;; Because we dynamically bind mail-abbrev-mode-regexp, we'd better
42 ;; require mailabbrev here.
43 (if (featurep 'xemacs
)
44 (require 'mail-abbrevs
)
45 (require 'mailabbrev
))
50 (autoload 'gnus-find-method-for-group
"gnus")
51 (autoload 'nnvirtual-find-group-art
"nnvirtual")
52 (autoload 'gnus-group-decoded-name
"gnus-group"))
54 (defgroup message
'((user-mail-address custom-variable
)
55 (user-full-name custom-variable
))
56 "Mail and news message composing."
57 :link
'(custom-manual "(message)Top")
61 (put 'user-mail-address
'custom-type
'string
)
62 (put 'user-full-name
'custom-type
'string
)
64 (defgroup message-various nil
65 "Various Message Variables"
66 :link
'(custom-manual "(message)Various Message Variables")
69 (defgroup message-buffers nil
71 :link
'(custom-manual "(message)Message Buffers")
74 (defgroup message-sending nil
76 :link
'(custom-manual "(message)Sending Variables")
79 (defgroup message-interface nil
81 :link
'(custom-manual "(message)Interface")
84 (defgroup message-forwarding nil
86 :link
'(custom-manual "(message)Forwarding")
87 :group
'message-interface
)
89 (defgroup message-insertion nil
91 :link
'(custom-manual "(message)Insertion")
94 (defgroup message-headers nil
96 :link
'(custom-manual "(message)Message Headers")
99 (defgroup message-news nil
100 "Composing News Messages"
103 (defgroup message-mail nil
104 "Composing Mail Messages"
107 (defgroup message-faces nil
108 "Faces used for message composing."
112 (defcustom message-directory
"~/Mail/"
113 "*Directory from which all other mail file variables are derived."
114 :group
'message-various
117 (defcustom message-max-buffers
10
118 "*How many buffers to keep before starting to kill them off."
119 :group
'message-buffers
122 (defcustom message-send-rename-function nil
123 "Function called to rename the buffer after sending it."
124 :group
'message-buffers
125 :type
'(choice function
(const nil
)))
127 (defcustom message-fcc-handler-function
'message-output
128 "*A function called to save outgoing articles.
129 This function will be called with the name of the file to store the
130 article in. The default function is `message-output' which saves in Unix
132 :type
'(radio (function-item message-output
)
133 (function :tag
"Other"))
134 :group
'message-sending
)
136 (defcustom message-fcc-externalize-attachments nil
137 "If non-nil, attachments are included as external parts in Fcc copies."
140 :group
'message-sending
)
142 (defcustom message-courtesy-message
143 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
144 "*This is inserted at the start of a mailed copy of a posted message.
145 If the string contains the format spec \"%s\", the Newsgroups
146 the article has been posted to will be inserted there.
147 If this variable is nil, no such courtesy message will be added."
148 :group
'message-sending
149 :type
'(radio string
(const nil
)))
151 (defcustom message-ignored-bounced-headers
152 "^\\(Received\\|Return-Path\\|Delivered-To\\):"
153 "*Regexp that matches headers to be removed in resent bounced mail."
154 :group
'message-interface
158 (defcustom message-from-style
'default
159 "*Specifies how \"From\" headers look.
161 If nil, they contain just the return address like:
163 If `parens', they look like:
164 king@grassland.com (Elvis Parsley)
165 If `angles', they look like:
166 Elvis Parsley <king@grassland.com>
168 Otherwise, most addresses look like `angles', but they look like
169 `parens' if `angles' would need quoting and `parens' would not."
170 :type
'(choice (const :tag
"simple" nil
)
174 :group
'message-headers
)
176 (defcustom message-insert-canlock t
177 "Whether to insert a Cancel-Lock header in news postings."
179 :group
'message-headers
182 (defcustom message-syntax-checks
183 (if message-insert-canlock
'((sender . disabled
)) nil
)
184 ;; Guess this one shouldn't be easy to customize...
185 "*Controls what syntax checks should not be performed on outgoing posts.
186 To disable checking of long signatures, for instance, add
187 `(signature . disabled)' to this list.
189 Don't touch this variable unless you really know what you're doing.
191 Checks include `subject-cmsg', `multiple-headers', `sendsys',
192 `message-id', `from', `long-lines', `control-chars', `size',
193 `new-text', `quoting-style', `redirected-followup', `signature',
194 `approved', `sender', `empty', `empty-headers', `message-id', `from',
195 `subject', `shorten-followup-to', `existing-newsgroups',
196 `buffer-file-name', `unchanged', `newsgroups', `reply-to',
197 `continuation-headers', `long-header-lines', `invisible-text' and
200 :type
'(repeat sexp
)) ; Fixme: improve this
202 (defcustom message-required-headers
'((optional . References
)
204 "*Headers to be generated or prompted for when sending a message.
205 Also see `message-required-news-headers' and
206 `message-required-mail-headers'."
209 :group
'message-headers
210 :link
'(custom-manual "(message)Message Headers")
211 :type
'(repeat sexp
))
213 (defcustom message-draft-headers
'(References From
)
214 "*Headers to be generated when saving a draft message."
217 :group
'message-headers
218 :link
'(custom-manual "(message)Message Headers")
219 :type
'(repeat sexp
))
221 (defcustom message-required-news-headers
222 '(From Newsgroups Subject Date Message-ID
223 (optional . Organization
)
224 (optional . User-Agent
))
225 "*Headers to be generated or prompted for when posting an article.
226 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
227 Message-ID. Organization, Lines, In-Reply-To, Expires, and
228 User-Agent are optional. If don't you want message to insert some
229 header, remove it from this list."
231 :group
'message-headers
232 :link
'(custom-manual "(message)Message Headers")
233 :type
'(repeat sexp
))
235 (defcustom message-required-mail-headers
236 '(From Subject Date
(optional . In-Reply-To
) Message-ID
237 (optional . User-Agent
))
238 "*Headers to be generated or prompted for when mailing a message.
239 It is recommended that From, Date, To, Subject and Message-ID be
240 included. Organization and User-Agent are optional."
242 :group
'message-headers
243 :link
'(custom-manual "(message)Message Headers")
244 :type
'(repeat sexp
))
246 (defcustom message-deletable-headers
'(Message-ID Date Lines
)
247 "Headers to be deleted if they already exist and were generated by message previously."
248 :group
'message-headers
249 :link
'(custom-manual "(message)Message Headers")
252 (defcustom message-ignored-news-headers
253 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
254 "*Regexp of headers to be removed unconditionally before posting."
256 :group
'message-headers
257 :link
'(custom-manual "(message)Message Headers")
258 :type
'(repeat :value-to-internal
(lambda (widget value
)
259 (custom-split-regexp-maybe value
))
260 :match
(lambda (widget value
)
262 (widget-editable-list-match widget value
)))
265 (defcustom message-ignored-mail-headers
266 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
267 "*Regexp of headers to be removed unconditionally before mailing."
269 :group
'message-headers
270 :link
'(custom-manual "(message)Mail Headers")
273 (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:"
274 "*Header lines matching this regexp will be deleted before posting.
275 It's best to delete old Path and Date headers before posting to avoid
277 :group
'message-interface
278 :link
'(custom-manual "(message)Superseding")
279 :type
'(repeat :value-to-internal
(lambda (widget value
)
280 (custom-split-regexp-maybe value
))
281 :match
(lambda (widget value
)
283 (widget-editable-list-match widget value
)))
286 (defcustom message-subject-re-regexp
287 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)*:[ \t]*\\)*[ \t]*"
288 "*Regexp matching \"Re: \" in the subject line."
289 :group
'message-various
290 :link
'(custom-manual "(message)Message Headers")
293 ;;; Start of variables adopted from `message-utils.el'.
295 (defcustom message-subject-trailing-was-query
'ask
296 "*What to do with trailing \"(was: <old subject>)\" in subject lines.
297 If nil, leave the subject unchanged. If it is the symbol `ask', query
298 the user what do do. In this case, the subject is matched against
299 `message-subject-trailing-was-ask-regexp'. If
300 `message-subject-trailing-was-query' is t, always strip the trailing
301 old subject. In this case, `message-subject-trailing-was-regexp' is
304 :type
'(choice (const :tag
"never" nil
)
305 (const :tag
"always strip" t
)
307 :link
'(custom-manual "(message)Message Headers")
308 :group
'message-various
)
310 (defcustom message-subject-trailing-was-ask-regexp
311 "[ \t]*\\([[(]+[Ww][Aa][Ss][ \t]*.*[\])]+\\)"
312 "*Regexp matching \"(was: <old subject>)\" in the subject line.
314 The function `message-strip-subject-trailing-was' uses this regexp if
315 `message-subject-trailing-was-query' is set to the symbol `ask'. If
316 the variable is t instead of `ask', use
317 `message-subject-trailing-was-regexp' instead.
319 It is okay to create some false positives here, as the user is asked."
321 :group
'message-various
322 :link
'(custom-manual "(message)Message Headers")
325 (defcustom message-subject-trailing-was-regexp
326 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
327 "*Regexp matching \"(was: <old subject>)\" in the subject line.
329 If `message-subject-trailing-was-query' is set to t, the subject is
330 matched against `message-subject-trailing-was-regexp' in
331 `message-strip-subject-trailing-was'. You should use a regexp creating very
332 few false positives here."
334 :group
'message-various
335 :link
'(custom-manual "(message)Message Headers")
338 ;; Fixme: Why are all these things autoloaded?
340 ;;; marking inserted text
343 (defcustom message-mark-insert-begin
344 "--8<---------------cut here---------------start------------->8---\n"
345 "How to mark the beginning of some inserted text."
348 :link
'(custom-manual "(message)Insertion Variables")
349 :group
'message-various
)
352 (defcustom message-mark-insert-end
353 "--8<---------------cut here---------------end--------------->8---\n"
354 "How to mark the end of some inserted text."
357 :link
'(custom-manual "(message)Insertion Variables")
358 :group
'message-various
)
361 (defcustom message-archive-header
362 "X-No-Archive: Yes\n"
363 "Header to insert when you don't want your article to be archived.
364 Archives \(such as groups.google.com\) respect this header."
367 :link
'(custom-manual "(message)Header Commands")
368 :group
'message-various
)
371 (defcustom message-archive-note
372 "X-No-Archive: Yes - save http://groups.google.com/"
373 "Note to insert why you wouldn't want this posting archived.
374 If nil, don't insert any text in the body."
376 :type
'(radio string
(const nil
))
377 :link
'(custom-manual "(message)Header Commands")
378 :group
'message-various
)
380 ;;; Crossposts and Followups
381 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
382 ;; new suggestions by R. Weikusat <rw at another.de>
384 (defvar message-cross-post-old-target nil
385 "Old target for cross-posts or follow-ups.")
386 (make-variable-buffer-local 'message-cross-post-old-target
)
389 (defcustom message-cross-post-default t
390 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
391 If nil, `message-cross-post-followup-to' will only do a followup. Note that
392 you can explicitly override this setting by calling
393 `message-cross-post-followup-to' with a prefix."
396 :group
'message-various
)
399 (defcustom message-cross-post-note
400 "Crosspost & Followup-To: "
401 "Note to insert before signature to notify of cross-post and follow-up."
404 :group
'message-various
)
407 (defcustom message-followup-to-note
409 "Note to insert before signature to notify of follow-up only."
412 :group
'message-various
)
415 (defcustom message-cross-post-note-function
416 'message-cross-post-insert-note
417 "Function to use to insert note about Crosspost or Followup-To.
418 The function will be called with four arguments. The function should not only
419 insert a note, but also ensure old notes are deleted. See the documentation
420 for `message-cross-post-insert-note'."
423 :group
'message-various
)
425 ;;; End of variables adopted from `message-utils.el'.
428 (defcustom message-signature-separator
"^-- *$"
429 "Regexp matching the signature separator."
431 :link
'(custom-manual "(message)Various Message Variables")
432 :group
'message-various
)
434 (defcustom message-elide-ellipsis
"\n[...]\n\n"
435 "*The string which is inserted for elided text."
437 :link
'(custom-manual "(message)Various Commands")
438 :group
'message-various
)
440 (defcustom message-interactive t
441 "Non-nil means when sending a message wait for and display errors.
442 nil means let mailer mail back a message to report errors."
443 :group
'message-sending
445 :link
'(custom-manual "(message)Sending Variables")
448 (defcustom message-generate-new-buffers
'unique
449 "*Non-nil means create a new message buffer whenever `message-setup' is called.
450 If this is a function, call that function with three parameters: The type,
451 the to address and the group name. (Any of these may be nil.) The function
452 should return the new buffer name."
453 :group
'message-buffers
454 :link
'(custom-manual "(message)Message Buffers")
455 :type
'(choice (const :tag
"off" nil
)
456 (const :tag
"unique" unique
)
457 (const :tag
"unsent" unsent
)
460 (defcustom message-kill-buffer-on-exit nil
461 "*Non-nil means that the message buffer will be killed after sending a message."
462 :group
'message-buffers
463 :link
'(custom-manual "(message)Message Buffers")
467 (defvar gnus-local-organization
))
468 (defcustom message-user-organization
469 (or (and (boundp 'gnus-local-organization
)
470 (stringp gnus-local-organization
)
471 gnus-local-organization
)
472 (getenv "ORGANIZATION")
474 "*String to be used as an Organization header.
475 If t, use `message-user-organization-file'."
476 :group
'message-headers
477 :type
'(choice string
478 (const :tag
"consult file" t
)))
481 (defcustom message-user-organization-file
"/usr/lib/news/organization"
482 "*Local news organization file."
484 :link
'(custom-manual "(message)News Headers")
485 :group
'message-headers
)
487 (defcustom message-make-forward-subject-function
488 #'message-forward-subject-name-subject
489 "*List of functions called to generate subject headers for forwarded messages.
490 The subject generated by the previous function is passed into each
493 The provided functions are:
495 * `message-forward-subject-author-subject' Source of article (author or
496 newsgroup), in brackets followed by the subject
497 * `message-forward-subject-name-subject' Source of article (name of author
498 or newsgroup), in brackets followed by the subject
499 * `message-forward-subject-fwd' Subject of article with 'Fwd:' prepended
501 :group
'message-forwarding
502 :link
'(custom-manual "(message)Forwarding")
503 :type
'(radio (function-item message-forward-subject-author-subject
)
504 (function-item message-forward-subject-fwd
)
505 (function-item message-forward-subject-name-subject
)
506 (repeat :tag
"List of functions" function
)))
508 (defcustom message-forward-as-mime t
509 "*Non-nil means forward messages as an inline/rfc822 MIME section.
510 Otherwise, directly inline the old message in the forwarded message."
512 :group
'message-forwarding
513 :link
'(custom-manual "(message)Forwarding")
516 (defcustom message-forward-show-mml
'best
517 "*Non-nil means show forwarded messages as MML (decoded from MIME).
518 Otherwise, forwarded messages are unchanged.
519 Can also be the symbol `best' to indicate that MML should be
520 used, except when it is a bad idea to use MML. One example where
521 it is a bad idea is when forwarding a signed or encrypted
522 message, because converting MIME to MML would invalidate the
525 :group
'message-forwarding
526 :type
'(choice (const :tag
"use MML" t
)
527 (const :tag
"don't use MML " nil
)
528 (const :tag
"use MML when appropriate" best
)))
530 (defcustom message-forward-before-signature t
531 "*Non-nil means put forwarded message before signature, else after."
532 :group
'message-forwarding
535 (defcustom message-wash-forwarded-subjects nil
536 "*Non-nil means try to remove as much cruft as possible from the subject.
537 Done before generating the new subject of a forward."
538 :group
'message-forwarding
539 :link
'(custom-manual "(message)Forwarding")
542 (defcustom message-ignored-resent-headers
"^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From "
543 "*All headers that match this regexp will be deleted when resending a message."
544 :group
'message-interface
545 :link
'(custom-manual "(message)Resending")
546 :type
'(repeat :value-to-internal
(lambda (widget value
)
547 (custom-split-regexp-maybe value
))
548 :match
(lambda (widget value
)
550 (widget-editable-list-match widget value
)))
553 (defcustom message-forward-ignored-headers
"^Content-Transfer-Encoding:\\|^X-Gnus"
554 "*All headers that match this regexp will be deleted when forwarding a message."
556 :group
'message-forwarding
557 :type
'(repeat :value-to-internal
(lambda (widget value
)
558 (custom-split-regexp-maybe value
))
559 :match
(lambda (widget value
)
561 (widget-editable-list-match widget value
)))
564 (defcustom message-ignored-cited-headers
"."
565 "*Delete these headers from the messages you yank."
566 :group
'message-insertion
567 :link
'(custom-manual "(message)Insertion Variables")
570 (defcustom message-cite-prefix-regexp
571 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
572 "\\([ \t]*[-_.[:word:]]+>+\\|[ \t]*[]>|}+]\\)+"
573 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
574 (let ((old-table (syntax-table))
575 non-word-constituents
)
576 (set-syntax-table text-mode-syntax-table
)
577 (setq non-word-constituents
579 (if (string-match "\\w" "-") "" "-")
580 (if (string-match "\\w" "_") "" "_")
581 (if (string-match "\\w" ".") "" ".")))
582 (set-syntax-table old-table
)
583 (if (equal non-word-constituents
"")
584 "\\([ \t]*\\(\\w\\)+>+\\|[ \t]*[]>|}+]\\)+"
585 (concat "\\([ \t]*\\(\\w\\|["
586 non-word-constituents
587 "]\\)+>+\\|[ \t]*[]>|}+]\\)+"))))
588 "*Regexp matching the longest possible citation prefix on a line."
590 :group
'message-insertion
591 :link
'(custom-manual "(message)Insertion Variables")
594 (defcustom message-cancel-message
"I am canceling my own article.\n"
595 "Message to be inserted in the cancel message."
596 :group
'message-interface
597 :link
'(custom-manual "(message)Canceling News")
600 ;; Useful to set in site-init.el
602 (defcustom message-send-mail-function
'message-send-mail-with-sendmail
603 "Function to call to send the current buffer as mail.
604 The headers should be delimited by a line whose contents match the
605 variable `mail-header-separator'.
607 Valid values include `message-send-mail-with-sendmail' (the default),
608 `message-send-mail-with-mh', `message-send-mail-with-qmail',
609 `message-smtpmail-send-it', `smtpmail-send-it' and `feedmail-send-it'.
611 See also `send-mail-function'."
612 :type
'(radio (function-item message-send-mail-with-sendmail
)
613 (function-item message-send-mail-with-mh
)
614 (function-item message-send-mail-with-qmail
)
615 (function-item message-smtpmail-send-it
)
616 (function-item smtpmail-send-it
)
617 (function-item feedmail-send-it
)
618 (function :tag
"Other"))
619 :group
'message-sending
620 :link
'(custom-manual "(message)Mail Variables")
621 :group
'message-mail
)
623 (defcustom message-send-news-function
'message-send-news
624 "Function to call to send the current buffer as news.
625 The headers should be delimited by a line whose contents match the
626 variable `mail-header-separator'."
627 :group
'message-sending
629 :link
'(custom-manual "(message)News Variables")
632 (defcustom message-reply-to-function nil
633 "If non-nil, function that should return a list of headers.
634 This function should pick out addresses from the To, Cc, and From headers
635 and respond with new To and Cc headers."
636 :group
'message-interface
637 :link
'(custom-manual "(message)Reply")
638 :type
'(choice function
(const nil
)))
640 (defcustom message-wide-reply-to-function nil
641 "If non-nil, function that should return a list of headers.
642 This function should pick out addresses from the To, Cc, and From headers
643 and respond with new To and Cc headers."
644 :group
'message-interface
645 :link
'(custom-manual "(message)Wide Reply")
646 :type
'(choice function
(const nil
)))
648 (defcustom message-followup-to-function nil
649 "If non-nil, function that should return a list of headers.
650 This function should pick out addresses from the To, Cc, and From headers
651 and respond with new To and Cc headers."
652 :group
'message-interface
653 :link
'(custom-manual "(message)Followup")
654 :type
'(choice function
(const nil
)))
656 (defcustom message-use-followup-to
'ask
657 "*Specifies what to do with Followup-To header.
658 If nil, always ignore the header. If it is t, use its value, but
659 query before using the \"poster\" value. If it is the symbol `ask',
660 always query the user whether to use the value. If it is the symbol
661 `use', always use the value."
662 :group
'message-interface
663 :link
'(custom-manual "(message)Followup")
664 :type
'(choice (const :tag
"ignore" nil
)
665 (const :tag
"use & query" t
)
669 (defcustom message-use-mail-followup-to
'use
670 "*Specifies what to do with Mail-Followup-To header.
671 If nil, always ignore the header. If it is the symbol `ask', always
672 query the user whether to use the value. If it is the symbol `use',
673 always use the value."
675 :group
'message-interface
676 :link
'(custom-manual "(message)Mailing Lists")
677 :type
'(choice (const :tag
"ignore" nil
)
681 (defcustom message-subscribed-address-functions nil
682 "*Specifies functions for determining list subscription.
683 If nil, do not attempt to determine list subscription with functions.
684 If non-nil, this variable contains a list of functions which return
685 regular expressions to match lists. These functions can be used in
686 conjunction with `message-subscribed-regexps' and
687 `message-subscribed-addresses'."
689 :group
'message-interface
690 :link
'(custom-manual "(message)Mailing Lists")
691 :type
'(repeat sexp
))
693 (defcustom message-subscribed-address-file nil
694 "*A file containing addresses the user is subscribed to.
695 If nil, do not look at any files to determine list subscriptions. If
696 non-nil, each line of this file should be a mailing list address."
698 :group
'message-interface
699 :link
'(custom-manual "(message)Mailing Lists")
700 :type
'(radio file
(const nil
)))
702 (defcustom message-subscribed-addresses nil
703 "*Specifies a list of addresses the user is subscribed to.
704 If nil, do not use any predefined list subscriptions. This list of
705 addresses can be used in conjunction with
706 `message-subscribed-address-functions' and `message-subscribed-regexps'."
708 :group
'message-interface
709 :link
'(custom-manual "(message)Mailing Lists")
710 :type
'(repeat string
))
712 (defcustom message-subscribed-regexps nil
713 "*Specifies a list of addresses the user is subscribed to.
714 If nil, do not use any predefined list subscriptions. This list of
715 regular expressions can be used in conjunction with
716 `message-subscribed-address-functions' and `message-subscribed-addresses'."
718 :group
'message-interface
719 :link
'(custom-manual "(message)Mailing Lists")
720 :type
'(repeat regexp
))
722 (defcustom message-allow-no-recipients
'ask
723 "Specifies what to do when there are no recipients other than Gcc/Fcc.
724 If it is the symbol `always', the posting is allowed. If it is the
725 symbol `never', the posting is not allowed. If it is the symbol
726 `ask', you are prompted."
728 :group
'message-interface
729 :link
'(custom-manual "(message)Message Headers")
730 :type
'(choice (const always
)
734 (defcustom message-sendmail-f-is-evil nil
735 "*Non-nil means don't add \"-f username\" to the sendmail command line.
736 Doing so would be even more evil than leaving it out."
737 :group
'message-sending
738 :link
'(custom-manual "(message)Mail Variables")
741 (defcustom message-sendmail-envelope-from nil
742 "*Envelope-from when sending mail with sendmail.
743 If this is nil, use `user-mail-address'. If it is the symbol
744 `header', use the From: header of the message."
746 :type
'(choice (string :tag
"From name")
747 (const :tag
"Use From: header from message" header
)
748 (const :tag
"Use `user-mail-address'" nil
))
749 :link
'(custom-manual "(message)Mail Variables")
750 :group
'message-sending
)
752 ;; qmail-related stuff
753 (defcustom message-qmail-inject-program
"/var/qmail/bin/qmail-inject"
754 "Location of the qmail-inject program."
755 :group
'message-sending
756 :link
'(custom-manual "(message)Mail Variables")
759 (defcustom message-qmail-inject-args nil
760 "Arguments passed to qmail-inject programs.
761 This should be a list of strings, one string for each argument. It
762 may also be a function.
764 For e.g., if you wish to set the envelope sender address so that bounces
765 go to the right place or to deal with listserv's usage of that address, you
766 might set this variable to '(\"-f\" \"you@some.where\")."
767 :group
'message-sending
768 :link
'(custom-manual "(message)Mail Variables")
769 :type
'(choice (function)
772 (defvar message-cater-to-broken-inn t
773 "Non-nil means Gnus should not fold the `References' header.
774 Folding `References' makes ancient versions of INN create incorrect
778 (defvar gnus-post-method
)
779 (defvar gnus-select-method
))
780 (defcustom message-post-method
781 (cond ((and (boundp 'gnus-post-method
)
782 (listp gnus-post-method
)
785 ((boundp 'gnus-select-method
)
788 "*Method used to post news.
789 Note that when posting from inside Gnus, for instance, this
790 variable isn't used."
792 :group
'message-sending
793 ;; This should be the `gnus-select-method' widget, but that might
794 ;; create a dependence to `gnus.el'.
797 ;; FIXME: This should be a temporary workaround until someone implements a
798 ;; proper solution. If a crash happens while replying, the auto-save file
799 ;; will *not* have a `References:' header if `message-generate-headers-first'
800 ;; is nil. See: http://article.gmane.org/gmane.emacs.gnus.general/51138
801 (defcustom message-generate-headers-first
'(references)
802 "Which headers should be generated before starting to compose a message.
803 If t, generate all required headers. This can also be a list of headers to
804 generate. The variables `message-required-news-headers' and
805 `message-required-mail-headers' specify which headers to generate.
807 Note that the variable `message-deletable-headers' specifies headers which
808 are to be deleted and then re-generated before sending, so this variable
809 will not have a visible effect for those headers."
810 :group
'message-headers
811 :link
'(custom-manual "(message)Message Headers")
812 :type
'(choice (const :tag
"None" nil
)
813 (const :tag
"References" '(references))
815 (repeat (sexp :tag
"Header"))))
817 (defcustom message-setup-hook nil
818 "Normal hook, run each time a new outgoing message is initialized.
819 The function `message-setup' runs this hook."
820 :group
'message-various
821 :link
'(custom-manual "(message)Various Message Variables")
824 (defcustom message-cancel-hook nil
825 "Hook run when cancelling articles."
826 :group
'message-various
827 :link
'(custom-manual "(message)Various Message Variables")
830 (defcustom message-signature-setup-hook nil
831 "Normal hook, run each time a new outgoing message is initialized.
832 It is run after the headers have been inserted and before
833 the signature is inserted."
834 :group
'message-various
835 :link
'(custom-manual "(message)Various Message Variables")
838 (defcustom message-mode-hook nil
839 "Hook run in message mode buffers."
840 :group
'message-various
843 (defcustom message-header-hook nil
844 "Hook run in a message mode buffer narrowed to the headers."
845 :group
'message-various
848 (defcustom message-header-setup-hook nil
849 "Hook called narrowed to the headers when setting up a message buffer."
850 :group
'message-various
851 :link
'(custom-manual "(message)Various Message Variables")
854 (defcustom message-minibuffer-local-map
855 (let ((map (make-sparse-keymap 'message-minibuffer-local-map
)))
856 (set-keymap-parent map minibuffer-local-map
)
858 "Keymap for `message-read-from-minibuffer'."
862 (defcustom message-citation-line-function
'message-insert-citation-line
863 "*Function called to insert the \"Whomever writes:\" line.
865 Note that Gnus provides a feature where the reader can click on
866 `writes:' to hide the cited text. If you change this line too much,
867 people who read your message will have to change their Gnus
868 configuration. See the variable `gnus-cite-attribution-suffix'."
870 :link
'(custom-manual "(message)Insertion Variables")
871 :group
'message-insertion
)
874 (defcustom message-yank-prefix
"> "
875 "*Prefix inserted on the lines of yanked messages.
876 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
877 See also `message-yank-cited-prefix'."
879 :link
'(custom-manual "(message)Insertion Variables")
880 :group
'message-insertion
)
882 (defcustom message-yank-cited-prefix
">"
883 "*Prefix inserted on cited or empty lines of yanked messages.
884 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
885 See also `message-yank-prefix'."
888 :link
'(custom-manual "(message)Insertion Variables")
889 :group
'message-insertion
)
891 (defcustom message-indentation-spaces
3
892 "*Number of spaces to insert at the beginning of each cited line.
893 Used by `message-yank-original' via `message-yank-cite'."
894 :group
'message-insertion
895 :link
'(custom-manual "(message)Insertion Variables")
899 (defcustom message-cite-function
'message-cite-original
900 "*Function for citing an original message.
901 Predefined functions include `message-cite-original' and
902 `message-cite-original-without-signature'.
903 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
904 :type
'(radio (function-item message-cite-original
)
905 (function-item message-cite-original-without-signature
)
906 (function-item sc-cite-original
)
907 (function :tag
"Other"))
908 :link
'(custom-manual "(message)Insertion Variables")
909 :group
'message-insertion
)
912 (defcustom message-indent-citation-function
'message-indent-citation
913 "*Function for modifying a citation just inserted in the mail buffer.
914 This can also be a list of functions. Each function can find the
915 citation between (point) and (mark t). And each function should leave
916 point and mark around the citation text as modified."
918 :link
'(custom-manual "(message)Insertion Variables")
919 :group
'message-insertion
)
922 (defcustom message-signature t
923 "*String to be inserted at the end of the message buffer.
924 If t, the `message-signature-file' file will be inserted instead.
925 If a function, the result from the function will be used instead.
926 If a form, the result from the form will be used instead."
928 :link
'(custom-manual "(message)Insertion Variables")
929 :group
'message-insertion
)
932 (defcustom message-signature-file
"~/.signature"
933 "*Name of file containing the text inserted at end of message buffer.
934 Ignored if the named file doesn't exist.
935 If nil, don't insert a signature."
936 :type
'(choice file
(const :tags
"None" nil
))
937 :link
'(custom-manual "(message)Insertion Variables")
938 :group
'message-insertion
)
941 (defcustom message-signature-insert-empty-line t
942 "*If non-nil, insert an empty line before the signature separator."
945 :link
'(custom-manual "(message)Insertion Variables")
946 :group
'message-insertion
)
948 (defcustom message-distribution-function nil
949 "*Function called to return a Distribution header."
951 :group
'message-headers
952 :link
'(custom-manual "(message)News Headers")
953 :type
'(choice function
(const nil
)))
955 (defcustom message-expires
14
956 "Number of days before your article expires."
958 :group
'message-headers
959 :link
'(custom-manual "(message)News Headers")
962 (defcustom message-user-path nil
963 "If nil, use the NNTP server name in the Path header.
964 If stringp, use this; if non-nil, use no host name (user name only)."
966 :group
'message-headers
967 :link
'(custom-manual "(message)News Headers")
968 :type
'(choice (const :tag
"nntp" nil
)
970 (sexp :tag
"none" :format
"%t" t
)))
972 (defvar message-reply-buffer nil
)
973 (defvar message-reply-headers nil
974 "The headers of the current replied article.
975 It is a vector of the following headers:
976 \[number subject from date id references chars lines xref extra].")
977 (defvar message-newsreader nil
)
978 (defvar message-mailer nil
)
979 (defvar message-sent-message-via nil
)
980 (defvar message-checksum nil
)
981 (defvar message-send-actions nil
982 "A list of actions to be performed upon successful sending of a message.")
983 (defvar message-exit-actions nil
984 "A list of actions to be performed upon exiting after sending a message.")
985 (defvar message-kill-actions nil
986 "A list of actions to be performed before killing a message buffer.")
987 (defvar message-postpone-actions nil
988 "A list of actions to be performed after postponing a message.")
990 (define-widget 'message-header-lines
'text
991 "All header lines must be LFD terminated."
992 :format
"%{%t%}:%n%v"
994 :error
"All header lines must be newline terminated")
996 (defcustom message-default-headers
""
997 "*A string containing header lines to be inserted in outgoing messages.
998 It is inserted before you edit the message, so you can edit or delete
1000 :group
'message-headers
1001 :link
'(custom-manual "(message)Message Headers")
1002 :type
'message-header-lines
)
1004 (defcustom message-default-mail-headers
""
1005 "*A string of header lines to be inserted in outgoing mails."
1006 :group
'message-headers
1007 :group
'message-mail
1008 :link
'(custom-manual "(message)Mail Headers")
1009 :type
'message-header-lines
)
1011 (defcustom message-default-news-headers
""
1012 "*A string of header lines to be inserted in outgoing news articles."
1013 :group
'message-headers
1014 :group
'message-news
1015 :link
'(custom-manual "(message)News Headers")
1016 :type
'message-header-lines
)
1018 ;; Note: could use /usr/ucb/mail instead of sendmail;
1019 ;; options -t, and -v if not interactive.
1020 (defcustom message-mailer-swallows-blank-line
1021 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1022 system-configuration
)
1023 (file-readable-p "/etc/sendmail.cf")
1024 (let ((buffer (get-buffer-create " *temp*")))
1028 (insert-file-contents "/etc/sendmail.cf")
1029 (goto-char (point-min))
1030 (let ((case-fold-search nil
))
1031 (re-search-forward "^OR\\>" nil t
)))
1032 (kill-buffer buffer
))))
1033 ;; According to RFC822, "The field-name must be composed of printable
1034 ;; ASCII characters (i. e., characters that have decimal values between
1035 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1037 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1038 "*Set this non-nil if the system's mailer runs the header and body together.
1039 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1040 The value should be an expression to test whether the problem will
1042 :group
'message-sending
1043 :link
'(custom-manual "(message)Mail Variables")
1047 (define-mail-user-agent 'message-user-agent
1048 'message-mail
'message-send-and-exit
1049 'message-kill-buffer
'message-send-hook
)
1051 (defvar message-mh-deletable-headers
'(Message-ID Date Lines Sender
)
1052 "If non-nil, delete the deletable headers before feeding to mh.")
1054 (defvar message-send-method-alist
1055 '((news message-news-p message-send-via-news
)
1056 (mail message-mail-p message-send-via-mail
))
1057 "Alist of ways to send outgoing messages.
1058 Each element has the form
1060 \(TYPE PREDICATE FUNCTION)
1062 where TYPE is a symbol that names the method; PREDICATE is a function
1063 called without any parameters to determine whether the message is
1064 a message of type TYPE; and FUNCTION is a function to be called if
1065 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1068 (defcustom message-mail-alias-type
'abbrev
1069 "*What alias expansion type to use in Message buffers.
1070 The default is `abbrev', which uses mailabbrev. nil switches
1073 :link
'(custom-manual "(message)Mail Aliases")
1074 :type
'(choice (const :tag
"Use Mailabbrev" abbrev
)
1075 (const :tag
"No expansion" nil
)))
1077 (defcustom message-auto-save-directory
1078 (file-name-as-directory (nnheader-concat message-directory
"drafts"))
1079 "*Directory where Message auto-saves buffers if Gnus isn't running.
1080 If nil, Message won't auto-save."
1081 :group
'message-buffers
1082 :link
'(custom-manual "(message)Various Message Variables")
1083 :type
'(choice directory
(const :tag
"Don't auto-save" nil
)))
1085 (defcustom message-default-charset
1086 (and (not (mm-multibyte-p)) 'iso-8859-1
)
1087 "Default charset used in non-MULE Emacsen.
1088 If nil, you might be asked to input the charset."
1091 :link
'(custom-manual "(message)Various Message Variables")
1094 (defcustom message-dont-reply-to-names
1095 (and (boundp 'rmail-dont-reply-to-names
) rmail-dont-reply-to-names
)
1096 "*A regexp specifying addresses to prune when doing wide replies.
1097 A value of nil means exclude your own user name only."
1100 :link
'(custom-manual "(message)Wide Reply")
1101 :type
'(choice (const :tag
"Yourself" nil
)
1104 (defvar message-shoot-gnksa-feet nil
1105 "*A list of GNKSA feet you are allowed to shoot.
1106 Gnus gives you all the opportunity you could possibly want for
1107 shooting yourself in the foot. Also, Gnus allows you to shoot the
1108 feet of Good Net-Keeping Seal of Approval. The following are foot
1110 `empty-article' Allow you to post an empty article;
1111 `quoted-text-only' Allow you to post quoted text only;
1112 `multiple-copies' Allow you to post multiple copies;
1113 `cancel-messages' Allow you to cancel or supersede messages from
1114 your other email addresses.")
1116 (defsubst message-gnksa-enable-p
(feature)
1117 (or (not (listp message-shoot-gnksa-feet
))
1118 (memq feature message-shoot-gnksa-feet
)))
1120 (defcustom message-hidden-headers nil
1121 "Regexp of headers to be hidden when composing new messages.
1122 This can also be a list of regexps to match headers. Or a list
1123 starting with `not' and followed by regexps."
1126 :link
'(custom-manual "(message)Message Headers")
1127 :type
'(repeat regexp
))
1129 ;;; Internal variables.
1130 ;;; Well, not really internal.
1132 (defvar message-mode-syntax-table
1133 (let ((table (copy-syntax-table text-mode-syntax-table
)))
1134 (modify-syntax-entry ?%
". " table
)
1135 (modify-syntax-entry ?
> ". " table
)
1136 (modify-syntax-entry ?
< ". " table
)
1138 "Syntax table used while in Message mode.")
1140 (defface message-header-to-face
1143 (:foreground
"green2" :bold t
))
1146 (:foreground
"MidnightBlue" :bold t
))
1148 (:bold t
:italic t
)))
1149 "Face used for displaying From headers."
1150 :group
'message-faces
)
1152 (defface message-header-cc-face
1155 (:foreground
"green4" :bold t
))
1158 (:foreground
"MidnightBlue"))
1161 "Face used for displaying Cc headers."
1162 :group
'message-faces
)
1164 (defface message-header-subject-face
1167 (:foreground
"green3"))
1170 (:foreground
"navy blue" :bold t
))
1173 "Face used for displaying subject headers."
1174 :group
'message-faces
)
1176 (defface message-header-newsgroups-face
1179 (:foreground
"yellow" :bold t
:italic t
))
1182 (:foreground
"blue4" :bold t
:italic t
))
1184 (:bold t
:italic t
)))
1185 "Face used for displaying newsgroups headers."
1186 :group
'message-faces
)
1188 (defface message-header-other-face
1191 (:foreground
"#b00000"))
1194 (:foreground
"steel blue"))
1196 (:bold t
:italic t
)))
1197 "Face used for displaying newsgroups headers."
1198 :group
'message-faces
)
1200 (defface message-header-name-face
1203 (:foreground
"DarkGreen"))
1206 (:foreground
"cornflower blue"))
1209 "Face used for displaying header names."
1210 :group
'message-faces
)
1212 (defface message-header-xheader-face
1215 (:foreground
"blue"))
1218 (:foreground
"blue"))
1221 "Face used for displaying X-Header headers."
1222 :group
'message-faces
)
1224 (defface message-separator-face
1227 (:foreground
"blue3"))
1230 (:foreground
"brown"))
1233 "Face used for displaying the separator."
1234 :group
'message-faces
)
1236 (defface message-cited-text-face
1239 (:foreground
"red"))
1242 (:foreground
"red"))
1245 "Face used for displaying cited text names."
1246 :group
'message-faces
)
1248 (defface message-mml-face
1251 (:foreground
"ForestGreen"))
1254 (:foreground
"ForestGreen"))
1257 "Face used for displaying MML."
1258 :group
'message-faces
)
1260 (defun message-font-lock-make-header-matcher (regexp)
1263 (let ((start (point)))
1266 (goto-char (point-min))
1267 (if (re-search-forward
1268 (concat "^" (regexp-quote mail-header-separator
) "$")
1270 (setq limit
(min limit
(match-beginning 0))))
1272 (and (< start limit
)
1273 (re-search-forward ,regexp limit t
))))))
1274 (if (featurep 'bytecomp
)
1278 (defvar message-font-lock-keywords
1279 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1280 `((,(message-font-lock-make-header-matcher
1281 (concat "^\\([Tt]o:\\)" content
))
1282 (1 'message-header-name-face
)
1283 (2 'message-header-to-face nil t
))
1284 (,(message-font-lock-make-header-matcher
1285 (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content
))
1286 (1 'message-header-name-face
)
1287 (2 'message-header-cc-face nil t
))
1288 (,(message-font-lock-make-header-matcher
1289 (concat "^\\([Ss]ubject:\\)" content
))
1290 (1 'message-header-name-face
)
1291 (2 'message-header-subject-face nil t
))
1292 (,(message-font-lock-make-header-matcher
1293 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content
))
1294 (1 'message-header-name-face
)
1295 (2 'message-header-newsgroups-face nil t
))
1296 (,(message-font-lock-make-header-matcher
1297 (concat "^\\([A-Z][^: \n\t]+:\\)" content
))
1298 (1 'message-header-name-face
)
1299 (2 'message-header-other-face nil t
))
1300 (,(message-font-lock-make-header-matcher
1301 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content
))
1302 (1 'message-header-name-face
)
1303 (2 'message-header-name-face
))
1304 ,@(if (and mail-header-separator
1305 (not (equal mail-header-separator
"")))
1306 `((,(concat "^\\(" (regexp-quote mail-header-separator
) "\\)$")
1307 1 'message-separator-face
))
1310 (re-search-forward (concat "^\\("
1311 message-cite-prefix-regexp
1314 (0 'message-cited-text-face
))
1315 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1316 (0 'message-mml-face
))))
1317 "Additional expressions to highlight in Message mode.")
1320 ;; XEmacs does it like this. For Emacs, we have to set the
1321 ;; `font-lock-defaults' buffer-local variable.
1322 (put 'message-mode
'font-lock-defaults
'(message-font-lock-keywords t
))
1324 (defvar message-face-alist
1325 '((bold . bold-region
)
1326 (underline . underline-region
)
1327 (default .
(lambda (b e
)
1329 (ununderline-region b e
))))
1330 "Alist of mail and news faces for facemenu.
1331 The cdr of each entry is a function for applying the face to a region.")
1333 (defcustom message-send-hook nil
1334 "Hook run before sending messages.
1335 This hook is run quite early when sending."
1336 :group
'message-various
1337 :options
'(ispell-message)
1338 :link
'(custom-manual "(message)Various Message Variables")
1341 (defcustom message-send-mail-hook nil
1342 "Hook run before sending mail messages.
1343 This hook is run very late -- just before the message is sent as
1345 :group
'message-various
1346 :link
'(custom-manual "(message)Various Message Variables")
1349 (defcustom message-send-news-hook nil
1350 "Hook run before sending news 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-sent-hook nil
1358 "Hook run after sending messages."
1359 :group
'message-various
1362 (defvar message-send-coding-system
'binary
1363 "Coding system to encode outgoing mail.")
1365 (defvar message-draft-coding-system
1366 mm-auto-save-coding-system
1367 "*Coding system to compose mail.
1368 If you'd like to make it possible to share draft files between XEmacs
1369 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1370 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1372 (defcustom message-send-mail-partially-limit
1000000
1373 "The limitation of messages sent as message/partial.
1374 The lower bound of message size in characters, beyond which the message
1375 should be sent in several parts. If it is nil, the size is unlimited."
1377 :group
'message-buffers
1378 :link
'(custom-manual "(message)Mail Variables")
1379 :type
'(choice (const :tag
"unlimited" nil
)
1382 (defcustom message-alternative-emails nil
1383 "A regexp to match the alternative email addresses.
1384 The first matched address (not primary one) is used in the From field."
1385 :group
'message-headers
1386 :link
'(custom-manual "(message)Message Headers")
1387 :type
'(choice (const :tag
"Always use primary" nil
)
1390 (defcustom message-hierarchical-addresses nil
1391 "A list of hierarchical mail address definitions.
1393 Inside each entry, the first address is the \"top\" address, and
1394 subsequent addresses are subaddresses; this is used to indicate that
1395 mail sent to the first address will automatically be delivered to the
1396 subaddresses. So if the first address appears in the recipient list
1397 for a message, the subaddresses will be removed (if present) before
1398 the mail is sent. All addresses in this structure should be
1401 :group
'message-headers
1402 :type
'(repeat (repeat string
)))
1404 (defcustom message-mail-user-agent nil
1405 "Like `mail-user-agent'.
1406 Except if it is nil, use Gnus native MUA; if it is t, use
1409 :type
'(radio (const :tag
"Gnus native"
1412 (const :tag
"`mail-user-agent'"
1415 (function-item :tag
"Default Emacs mail"
1417 sendmail-user-agent
)
1418 (function-item :tag
"Emacs interface to MH"
1421 (function :tag
"Other"))
1425 (defcustom message-wide-reply-confirm-recipients nil
1426 "Whether to confirm a wide reply to multiple email recipients.
1427 If this variable is nil, don't ask whether to reply to all recipients.
1428 If this variable is non-nil, pose the question \"Reply to all
1429 recipients?\" before a wide reply to multiple recipients. If the user
1430 answers yes, reply to all recipients as usual. If the user answers
1431 no, only reply back to the author."
1433 :group
'message-headers
1434 :link
'(custom-manual "(message)Wide Reply")
1437 (defcustom message-user-fqdn nil
1438 "*Domain part of Messsage-Ids."
1440 :group
'message-headers
1441 :link
'(custom-manual "(message)News Headers")
1442 :type
'(radio (const :format
"%v " nil
)
1443 (string :format
"FQDN: %v")))
1445 (defcustom message-use-idna
(and (condition-case nil
(require 'idna
)
1447 (mm-coding-system-p 'utf-8
)
1448 (executable-find idna-program
)
1450 "Whether to encode non-ASCII in domain names into ASCII according to IDNA."
1452 :group
'message-headers
1453 :link
'(custom-manual "(message)IDNA")
1454 :type
'(choice (const :tag
"Ask" ask
)
1455 (const :tag
"Never" nil
)
1456 (const :tag
"Always" t
)))
1458 ;;; Internal variables.
1460 (defvar message-sending-message
"Sending...")
1461 (defvar message-buffer-list nil
)
1462 (defvar message-this-is-news nil
)
1463 (defvar message-this-is-mail nil
)
1464 (defvar message-draft-article nil
)
1465 (defvar message-mime-part nil
)
1466 (defvar message-posting-charset nil
)
1467 (defvar message-inserted-headers nil
)
1469 ;; Byte-compiler warning
1471 (defvar gnus-active-hashtb
)
1472 (defvar gnus-read-active-file
))
1474 ;;; Regexp matching the delimiter of messages in UNIX mail format
1475 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1476 ;;; of rmail.el's rmail-unix-mail-delimiter.
1477 (defvar message-unix-mail-delimiter
1478 (let ((time-zone-regexp
1479 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1480 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1486 ;; Many things can happen to an RFC 822 mailbox before it is put into
1487 ;; a `From' line. The leading phrase can be stripped, e.g.
1488 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1489 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1490 ;; can be removed, e.g.
1491 ;; From: joe@y.z (Joe K
1493 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1496 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1497 ;; The mailbox can be removed or be replaced by white space, e.g.
1498 ;; From: "Joe User"{space}{tab}
1500 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1501 ;; where {space} and {tab} represent the Ascii space and tab characters.
1502 ;; We want to match the results of any of these manglings.
1503 ;; The following regexp rejects names whose first characters are
1504 ;; obviously bogus, but after that anything goes.
1505 "\\([^\0-\b\n-\r\^?].*\\)?"
1507 ;; The time the message was sent.
1508 "\\([^\0-\r \^?]+\\) +" ; day of the week
1509 "\\([^\0-\r \^?]+\\) +" ; month
1510 "\\([0-3]?[0-9]\\) +" ; day of month
1511 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1513 ;; Perhaps a time zone, specified by an abbreviation, or by a
1518 " \\([0-9][0-9]+\\) *"
1520 ;; On some systems the time zone can appear after the year, too.
1524 "\\(remote from .*\\)?"
1527 "Regexp matching the delimiter of messages in UNIX mail format.")
1529 (defvar message-unsent-separator
1530 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1531 "^ *---+ +Returned message +---+ *$\\|"
1532 "^Start of returned message$\\|"
1533 "^ *---+ +Original message +---+ *$\\|"
1534 "^ *--+ +begin message +--+ *$\\|"
1535 "^ *---+ +Original message follows +---+ *$\\|"
1536 "^ *---+ +Undelivered message follows +---+ *$\\|"
1537 "^|? *---+ +Message text follows: +---+ *|?$")
1538 "A regexp that matches the separator before the text of a failed message.")
1540 (defvar message-header-format-alist
1542 (To . message-fill-address
)
1543 (Cc . message-fill-address
)
1554 (References . message-shorten-references
)
1556 "Alist used for formatting headers.")
1558 (defvar message-options nil
1559 "Some saved answers when sending message.")
1561 (defvar message-send-mail-real-function nil
1562 "Internal send mail function.")
1564 (defvar message-bogus-system-names
"^localhost\\."
1565 "The regexp of bogus system names.")
1567 (defcustom message-valid-fqdn-regexp
1568 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1570 "\\([a-z][a-z]" ;; two letter country TDLs
1571 "\\|biz\\|com\\|edu\\|gov\\|int\\|mil\\|net\\|org"
1572 "\\|aero\\|coop\\|info\\|name\\|museum"
1573 "\\|arpa\\|pro\\|uucp\\|bitnet\\|bofh" ;; old style?
1575 "Regular expression that matches a valid FQDN."
1576 ;; see also: gnus-button-valid-fqdn-regexp
1578 :group
'message-headers
1582 (autoload 'idna-to-ascii
"idna")
1583 (autoload 'message-setup-toolbar
"messagexmas")
1584 (autoload 'mh-new-draft-name
"mh-comp")
1585 (autoload 'mh-send-letter
"mh-comp")
1586 (autoload 'gnus-point-at-eol
"gnus-util")
1587 (autoload 'gnus-point-at-bol
"gnus-util")
1588 (autoload 'gnus-output-to-rmail
"gnus-util")
1589 (autoload 'gnus-output-to-mail
"gnus-util")
1590 (autoload 'nndraft-request-associate-buffer
"nndraft")
1591 (autoload 'nndraft-request-expire-articles
"nndraft")
1592 (autoload 'gnus-open-server
"gnus-int")
1593 (autoload 'gnus-request-post
"gnus-int")
1594 (autoload 'gnus-alive-p
"gnus-util")
1595 (autoload 'gnus-server-string
"gnus")
1596 (autoload 'gnus-group-name-charset
"gnus-group")
1597 (autoload 'gnus-group-name-decode
"gnus-group")
1598 (autoload 'gnus-groups-from-server
"gnus")
1599 (autoload 'rmail-output
"rmailout")
1600 (autoload 'gnus-delay-article
"gnus-delay")
1601 (autoload 'gnus-make-local-hook
"gnus-util")
1602 (autoload 'gnus-extract-address-components
"gnus-util"))
1607 ;;; Utility functions.
1610 (defmacro message-y-or-n-p
(question show
&rest text
)
1611 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1612 `(message-talkative-question 'y-or-n-p
,question
,show
,@text
))
1614 (defmacro message-delete-line
(&optional n
)
1615 "Delete the current line (and the next N lines)."
1616 `(delete-region (progn (beginning-of-line) (point))
1617 (progn (forward-line ,(or n
1)) (point))))
1619 (defun message-mark-active-p ()
1620 "Non-nil means the mark and region are currently active in this buffer."
1623 (defun message-unquote-tokens (elems)
1624 "Remove double quotes (\") from strings in list ELEMS."
1625 (mapcar (lambda (item)
1626 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item
)
1627 (setq item
(concat (match-string 1 item
)
1628 (match-string 2 item
))))
1632 (defun message-tokenize-header (header &optional separator
)
1633 "Split HEADER into a list of header elements.
1634 SEPARATOR is a string of characters to be used as separators. \",\"
1635 is used by default."
1638 (let ((regexp (format "[%s]+" (or separator
",")))
1640 beg quoted elems paren
)
1642 (mm-enable-multibyte)
1643 (setq beg
(point-min))
1645 (goto-char (point-min))
1650 (cond ((and (> (point) beg
)
1652 (and (looking-at regexp
)
1655 (push (buffer-substring beg
(point)) elems
)
1656 (setq beg
(match-end 0)))
1657 ((eq (char-after) ?
\")
1658 (setq quoted
(not quoted
)))
1659 ((and (eq (char-after) ?\
()
1662 ((and (eq (char-after) ?\
))
1665 (nreverse elems
)))))
1667 (defun message-mail-file-mbox-p (file)
1668 "Say whether FILE looks like a Unix mbox file."
1669 (when (and (file-exists-p file
)
1670 (file-readable-p file
)
1671 (file-regular-p file
))
1673 (nnheader-insert-file-contents file
)
1674 (goto-char (point-min))
1675 (looking-at message-unix-mail-delimiter
))))
1677 (defun message-fetch-field (header &optional not-all
)
1678 "The same as `mail-fetch-field', only remove all newlines.
1679 The buffer is expected to be narrowed to just the header of the message;
1680 see `message-narrow-to-headers-or-head'."
1681 (let* ((inhibit-point-motion-hooks t
)
1682 (case-fold-search t
)
1683 (value (mail-fetch-field header nil
(not not-all
))))
1685 (while (string-match "\n[\t ]+" value
)
1686 (setq value
(replace-match " " t t value
)))
1687 (set-text-properties 0 (length value
) nil value
)
1690 (defun message-field-value (header &optional not-all
)
1691 "The same as `message-fetch-field', only narrow to the headers first."
1694 (message-narrow-to-headers-or-head)
1695 (message-fetch-field header not-all
))))
1697 (defun message-narrow-to-field ()
1698 "Narrow the buffer to the header on the current line."
1704 (if (re-search-forward "^[^ \n\t]" nil t
)
1709 (goto-char (point-min)))
1711 (defun message-add-header (&rest headers
)
1712 "Add the HEADERS to the message header, skipping those already present."
1715 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers
))
1716 (error "Invalid header `%s'" (car headers
)))
1717 (setq hclean
(match-string 1 (car headers
)))
1719 (message-narrow-to-headers)
1720 (unless (re-search-forward (concat "^" (regexp-quote hclean
) ":") nil t
)
1721 (goto-char (point-max))
1722 (if (string-match "\n$" (car headers
))
1723 (insert (car headers
))
1724 (insert (car headers
) ?
\n)))))
1725 (setq headers
(cdr headers
))))
1727 (defmacro message-with-reply-buffer
(&rest forms
)
1728 "Evaluate FORMS in the reply buffer, if it exists."
1729 `(when (and message-reply-buffer
1730 (buffer-name message-reply-buffer
))
1732 (set-buffer message-reply-buffer
)
1735 (put 'message-with-reply-buffer
'lisp-indent-function
0)
1736 (put 'message-with-reply-buffer
'edebug-form-spec
'(body))
1738 (defun message-fetch-reply-field (header)
1739 "Fetch field HEADER from the message we're replying to."
1740 (message-with-reply-buffer
1742 (mail-narrow-to-head)
1743 (message-fetch-field header
))))
1745 (defun message-strip-list-identifiers (subject)
1746 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1747 (require 'gnus-sum
) ; for gnus-list-identifiers
1748 (let ((regexp (if (stringp gnus-list-identifiers
)
1749 gnus-list-identifiers
1750 (mapconcat 'identity gnus-list-identifiers
" *\\|"))))
1751 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1752 " *\\)\\)+\\(Re: +\\)?\\)") subject
)
1753 (concat (substring subject
0 (match-beginning 1))
1754 (or (match-string 3 subject
)
1755 (match-string 5 subject
))
1760 (defun message-strip-subject-re (subject)
1761 "Remove \"Re:\" from subject lines in string SUBJECT."
1762 (if (string-match message-subject-re-regexp subject
)
1763 (substring subject
(match-end 0))
1766 ;;; Start of functions adopted from `message-utils.el'.
1768 (defun message-strip-subject-trailing-was (subject)
1769 "Remove trailing \"(Was: <old subject>)\" from SUBJECT lines.
1770 Leading \"Re: \" is not stripped by this function. Use the function
1771 `message-strip-subject-re' for this."
1772 (let* ((query message-subject-trailing-was-query
)
1777 message-subject-trailing-was-ask-regexp
1778 message-subject-trailing-was-regexp
)
1781 (setq new
(substring subject
0 (match-beginning 0))))
1782 (if (or (not found
) (eq query nil
))
1785 (if (message-y-or-n-p
1786 "Strip `(was: <old subject>)' in subject? " t
1788 "Strip `(was: <old subject>)' in subject "
1789 "and use the new one instead?\n\n"
1790 "Current subject is: \""
1792 "New subject would be: \""
1794 "See the variable `message-subject-trailing-was-query' "
1795 "to get rid of this query."
1800 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
1803 (defun message-change-subject (new-subject)
1804 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
1805 ;; <URL:http://www.landfield.com/usefor/drafts/draft-ietf-usefor-useage--1.02.unpaged>
1808 (read-from-minibuffer "New subject: ")))
1809 (cond ((and (not (or (null new-subject
) ; new subject not empty
1810 (zerop (string-width new-subject
))
1811 (string-match "^[ \t]*$" new-subject
))))
1815 (message-narrow-to-headers)
1816 (message-fetch-field "Subject"))))
1817 (cond ((not old-subject
)
1818 (error "No current subject"))
1821 (regexp-quote new-subject
)
1823 old-subject
)) ; yes, it really is a new subject
1824 ;; delete eventual Re: prefix
1826 (message-strip-subject-re old-subject
))
1827 (message-goto-subject)
1828 (message-delete-line)
1829 (insert (concat "Subject: "
1832 old-subject
")\n")))))))))
1835 (defun message-mark-inserted-region (beg end
)
1836 "Mark some region in the current article with enclosing tags.
1837 See `message-mark-insert-begin' and `message-mark-insert-end'."
1840 ;; add to the end of the region first, otherwise end would be invalid
1842 (insert message-mark-insert-end
)
1844 (insert message-mark-insert-begin
)))
1847 (defun message-mark-insert-file (file)
1848 "Insert FILE at point, marking it with enclosing tags.
1849 See `message-mark-insert-begin' and `message-mark-insert-end'."
1850 (interactive "fFile to insert: ")
1851 ;; reverse insertion to get correct result.
1853 (insert message-mark-insert-end
)
1855 (insert-file-contents file
)
1857 (insert message-mark-insert-begin
)))
1860 (defun message-add-archive-header ()
1861 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
1862 The note can be customized using `message-archive-note'. When called with a
1863 prefix argument, ask for a text to insert. If you don't want the note in the
1864 body, set `message-archive-note' to nil."
1866 (if current-prefix-arg
1867 (setq message-archive-note
1868 (read-from-minibuffer "Reason for No-Archive: "
1869 (cons message-archive-note
0))))
1871 (if (message-goto-signature)
1872 (re-search-backward message-signature-separator
))
1873 (when message-archive-note
1874 (insert message-archive-note
)
1876 (message-add-header message-archive-header
)
1877 (message-sort-headers)))
1880 (defun message-cross-post-followup-to-header (target-group)
1881 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
1882 With prefix-argument just set Follow-Up, don't cross-post."
1884 (list ; Completion based on Gnus
1885 (completing-read "Followup To: "
1886 (if (boundp 'gnus-newsrc-alist
)
1888 nil nil
'("poster" .
0)
1889 (if (boundp 'gnus-group-history
)
1890 'gnus-group-history
))))
1891 (message-remove-header "Follow[Uu]p-[Tt]o" t
)
1892 (message-goto-newsgroups)
1894 ;; if we already did a crosspost before, kill old target
1895 (if (and message-cross-post-old-target
1897 (regexp-quote (concat "," message-cross-post-old-target
))
1900 ;; unless (followup is to poster or user explicitly asked not
1901 ;; to cross-post, or target-group is already in Newsgroups)
1902 ;; add target-group to Newsgroups line.
1904 ;; def: cross-post, req:no
1905 (and message-cross-post-default
(not current-prefix-arg
))
1906 ;; def: no-cross-post, req:yes
1907 (and (not message-cross-post-default
) current-prefix-arg
))
1908 (not (string-match "poster" target-group
))
1909 (not (string-match (regexp-quote target-group
)
1910 (message-fetch-field "Newsgroups"))))
1912 (insert (concat "," target-group
))))
1913 (end-of-line) ; ensure Followup: comes after Newsgroups:
1914 ;; unless new followup would be identical to Newsgroups line
1915 ;; make a new Followup-To line
1916 (if (not (string-match (concat "^[ \t]*"
1919 (message-fetch-field "Newsgroups")))
1920 (insert (concat "\nFollowup-To: " target-group
)))
1921 (setq message-cross-post-old-target target-group
))
1924 (defun message-cross-post-insert-note (target-group cross-post in-old
1926 "Insert a in message body note about a set Followup or Crosspost.
1927 If there have been previous notes, delete them. TARGET-GROUP specifies the
1928 group to Followup-To. When CROSS-POST is t, insert note about
1929 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
1930 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
1931 been made to before the user asked for a Crosspost."
1932 ;; start scanning body for previous uses
1933 (message-goto-signature)
1934 (let ((head (re-search-backward
1935 (concat "^" mail-header-separator
)
1936 nil t
))) ; just search in body
1937 (message-goto-signature)
1938 (while (re-search-backward
1939 (concat "^" (regexp-quote message-cross-post-note
) ".*")
1941 (message-delete-line))
1942 (message-goto-signature)
1943 (while (re-search-backward
1944 (concat "^" (regexp-quote message-followup-to-note
) ".*")
1946 (message-delete-line))
1948 (if (message-goto-signature)
1949 (re-search-backward message-signature-separator
))
1952 (string-match "^[ \t]*poster[ \t]*$" target-group
))
1953 (insert (concat message-followup-to-note target-group
"\n"))
1954 (insert (concat message-cross-post-note target-group
"\n")))))
1957 (defun message-cross-post-followup-to (target-group)
1958 "Crossposts message and set Followup-To to TARGET-GROUP.
1959 With prefix-argument just set Follow-Up, don't cross-post."
1961 (list ; Completion based on Gnus
1962 (completing-read "Followup To: "
1963 (if (boundp 'gnus-newsrc-alist
)
1965 nil nil
'("poster" .
0)
1966 (if (boundp 'gnus-group-history
)
1967 'gnus-group-history
))))
1968 (cond ((not (or (null target-group
) ; new subject not empty
1969 (zerop (string-width target-group
))
1970 (string-match "^[ \t]*$" target-group
)))
1972 (let* ((old-groups (message-fetch-field "Newsgroups"))
1973 (in-old (string-match
1974 (regexp-quote target-group
)
1975 (or old-groups
""))))
1976 ;; check whether target exactly matches old Newsgroups
1977 (cond ((not old-groups
)
1978 (error "No current newsgroup"))
1982 (regexp-quote target-group
)
1985 ;; yes, Newsgroups line must change
1986 (message-cross-post-followup-to-header target-group
)
1987 ;; insert note whether we do cross-post or followup-to
1988 (funcall message-cross-post-note-function
1990 (if (or (and message-cross-post-default
1991 (not current-prefix-arg
))
1992 (and (not message-cross-post-default
)
1993 current-prefix-arg
)) t
)
1994 in-old old-groups
))))))))
1996 ;;; Reduce To: to Cc: or Bcc: header
1999 (defun message-reduce-to-to-cc ()
2000 "Replace contents of To: header with contents of Cc: or Bcc: header."
2003 (save-restriction (message-narrow-to-headers)
2004 (message-fetch-field "cc")))
2006 (if (and (not cc-content
)
2009 (message-narrow-to-headers)
2010 (message-fetch-field "bcc"))))
2015 (message-delete-line)
2016 (insert (concat "To: " cc-content
"\n"))
2018 (message-narrow-to-headers)
2019 (message-remove-header (if bcc
2023 ;;; End of functions adopted from `message-utils.el'.
2025 (defun message-remove-header (header &optional is-regexp first reverse
)
2026 "Remove HEADER in the narrowed buffer.
2027 If IS-REGEXP, HEADER is a regular expression.
2028 If FIRST, only remove the first instance of the header.
2029 Return the number of headers removed."
2030 (goto-char (point-min))
2031 (let ((regexp (if is-regexp header
(concat "^" (regexp-quote header
) ":")))
2033 (case-fold-search t
)
2035 (while (and (not (eobp))
2038 (not (looking-at regexp
))
2039 (looking-at regexp
))
2046 ;; There might be a continuation header, so we have to search
2047 ;; until we find a new non-continuation line.
2050 (if (re-search-forward "^[^ \t]" nil t
)
2051 (goto-char (match-beginning 0))
2054 (if (re-search-forward "^[^ \t]" nil t
)
2055 (goto-char (match-beginning 0))
2056 (goto-char (point-max)))))
2059 (defun message-remove-first-header (header)
2060 "Remove the first instance of HEADER if there is more than one."
2062 (regexp (concat "^" (regexp-quote header
) ":")))
2064 (goto-char (point-min))
2065 (while (re-search-forward regexp nil t
)
2068 (message-remove-header header nil t
)
2071 (defun message-narrow-to-headers ()
2072 "Narrow the buffer to the head of the message."
2075 (goto-char (point-min))
2076 (if (re-search-forward
2077 (concat "^" (regexp-quote mail-header-separator
) "\n") nil t
)
2080 (goto-char (point-min)))
2082 (defun message-narrow-to-head-1 ()
2083 "Like `message-narrow-to-head'. Don't widen."
2085 (goto-char (point-min))
2086 (if (search-forward "\n\n" nil
1)
2089 (goto-char (point-min)))
2091 (defun message-narrow-to-head ()
2092 "Narrow the buffer to the head of the message.
2093 Point is left at the beginning of the narrowed-to region."
2095 (message-narrow-to-head-1))
2097 (defun message-narrow-to-headers-or-head ()
2098 "Narrow the buffer to the head of the message."
2101 (goto-char (point-min))
2104 (concat "^" (regexp-quote mail-header-separator
) "\n") nil t
)
2105 (match-beginning 0))
2106 ((search-forward "\n\n" nil t
)
2110 (goto-char (point-min)))
2112 (defun message-news-p ()
2113 "Say whether the current buffer contains a news message."
2114 (and (not message-this-is-mail
)
2115 (or message-this-is-news
2118 (message-narrow-to-headers)
2119 (and (message-fetch-field "newsgroups")
2120 (not (message-fetch-field "posted-to"))))))))
2122 (defun message-mail-p ()
2123 "Say whether the current buffer contains a mail message."
2124 (and (not message-this-is-news
)
2125 (or message-this-is-mail
2128 (message-narrow-to-headers)
2129 (or (message-fetch-field "to")
2130 (message-fetch-field "cc")
2131 (message-fetch-field "bcc")))))))
2133 (defun message-subscribed-p ()
2134 "Say whether we need to insert a MFT header."
2135 (or message-subscribed-regexps
2136 message-subscribed-addresses
2137 message-subscribed-address-file
2138 message-subscribed-address-functions
))
2140 (defun message-next-header ()
2141 "Go to the beginning of the next header."
2143 (or (eobp) (forward-char 1))
2144 (not (if (re-search-forward "^[^ \t]" nil t
)
2146 (goto-char (point-max)))))
2148 (defun message-sort-headers-1 ()
2149 "Sort the buffer as headers using `message-rank' text props."
2150 (goto-char (point-min))
2153 nil
'message-next-header
2155 (message-next-header)
2159 (or (get-text-property (point) 'message-rank
)
2162 (defun message-sort-headers ()
2163 "Sort the headers of the current message according to `message-header-format-alist'."
2167 (let ((max (1+ (length message-header-format-alist
)))
2169 (message-narrow-to-headers)
2170 (while (re-search-forward "^[^ \n]+:" nil t
)
2172 (match-beginning 0) (1+ (match-beginning 0))
2174 (if (setq rank
(length (memq (assq (intern (buffer-substring
2176 (1- (match-end 0))))
2177 message-header-format-alist
)
2178 message-header-format-alist
)))
2181 (message-sort-headers-1))))
2192 (defvar message-mode-map nil
)
2194 (unless message-mode-map
2195 (setq message-mode-map
(make-keymap))
2196 (set-keymap-parent message-mode-map text-mode-map
)
2197 (define-key message-mode-map
"\C-c?" 'describe-mode
)
2199 (define-key message-mode-map
"\C-c\C-f\C-t" 'message-goto-to
)
2200 (define-key message-mode-map
"\C-c\C-f\C-o" 'message-goto-from
)
2201 (define-key message-mode-map
"\C-c\C-f\C-b" 'message-goto-bcc
)
2202 (define-key message-mode-map
"\C-c\C-f\C-w" 'message-goto-fcc
)
2203 (define-key message-mode-map
"\C-c\C-f\C-c" 'message-goto-cc
)
2204 (define-key message-mode-map
"\C-c\C-f\C-s" 'message-goto-subject
)
2205 (define-key message-mode-map
"\C-c\C-f\C-r" 'message-goto-reply-to
)
2206 (define-key message-mode-map
"\C-c\C-f\C-n" 'message-goto-newsgroups
)
2207 (define-key message-mode-map
"\C-c\C-f\C-d" 'message-goto-distribution
)
2208 (define-key message-mode-map
"\C-c\C-f\C-f" 'message-goto-followup-to
)
2209 (define-key message-mode-map
"\C-c\C-f\C-m" 'message-goto-mail-followup-to
)
2210 (define-key message-mode-map
"\C-c\C-f\C-k" 'message-goto-keywords
)
2211 (define-key message-mode-map
"\C-c\C-f\C-u" 'message-goto-summary
)
2212 (define-key message-mode-map
"\C-c\C-f\C-i"
2213 'message-insert-or-toggle-importance
)
2214 (define-key message-mode-map
"\C-c\C-f\C-a"
2215 'message-generate-unsubscribed-mail-followup-to
)
2217 ;; modify headers (and insert notes in body)
2218 (define-key message-mode-map
"\C-c\C-fs" 'message-change-subject
)
2220 (define-key message-mode-map
"\C-c\C-fx" 'message-cross-post-followup-to
)
2221 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2222 (define-key message-mode-map
"\C-c\C-ft" 'message-reduce-to-to-cc
)
2223 (define-key message-mode-map
"\C-c\C-fa" 'message-add-archive-header
)
2224 ;; mark inserted text
2225 (define-key message-mode-map
"\C-c\M-m" 'message-mark-inserted-region
)
2226 (define-key message-mode-map
"\C-c\M-f" 'message-mark-insert-file
)
2228 (define-key message-mode-map
"\C-c\C-b" 'message-goto-body
)
2229 (define-key message-mode-map
"\C-c\C-i" 'message-goto-signature
)
2231 (define-key message-mode-map
"\C-c\C-t" 'message-insert-to
)
2232 (define-key message-mode-map
"\C-c\C-fw" 'message-insert-wide-reply
)
2233 (define-key message-mode-map
"\C-c\C-n" 'message-insert-newsgroups
)
2234 (define-key message-mode-map
"\C-c\C-l" 'message-to-list-only
)
2236 (define-key message-mode-map
"\C-c\C-u" 'message-insert-or-toggle-importance
)
2237 (define-key message-mode-map
"\C-c\M-n"
2238 'message-insert-disposition-notification-to
)
2240 (define-key message-mode-map
"\C-c\C-y" 'message-yank-original
)
2241 (define-key message-mode-map
"\C-c\M-\C-y" 'message-yank-buffer
)
2242 (define-key message-mode-map
"\C-c\C-q" 'message-fill-yanked-message
)
2243 (define-key message-mode-map
"\C-c\C-w" 'message-insert-signature
)
2244 (define-key message-mode-map
"\C-c\M-h" 'message-insert-headers
)
2245 (define-key message-mode-map
"\C-c\C-r" 'message-caesar-buffer-body
)
2246 (define-key message-mode-map
"\C-c\C-o" 'message-sort-headers
)
2247 (define-key message-mode-map
"\C-c\M-r" 'message-rename-buffer
)
2249 (define-key message-mode-map
"\C-c\C-c" 'message-send-and-exit
)
2250 (define-key message-mode-map
"\C-c\C-s" 'message-send
)
2251 (define-key message-mode-map
"\C-c\C-k" 'message-kill-buffer
)
2252 (define-key message-mode-map
"\C-c\C-d" 'message-dont-send
)
2253 (define-key message-mode-map
"\C-c\n" 'gnus-delay-article
)
2255 (define-key message-mode-map
"\C-c\C-e" 'message-elide-region
)
2256 (define-key message-mode-map
"\C-c\C-v" 'message-delete-not-region
)
2257 (define-key message-mode-map
"\C-c\C-z" 'message-kill-to-signature
)
2258 (define-key message-mode-map
"\M-\r" 'message-newline-and-reformat
)
2259 ;;(define-key message-mode-map "\M-q" 'message-fill-paragraph)
2260 (define-key message-mode-map
[remap split-line
] 'message-split-line
)
2262 (define-key message-mode-map
"\C-c\C-a" 'mml-attach-file
)
2264 (define-key message-mode-map
"\C-a" 'message-beginning-of-line
)
2265 (define-key message-mode-map
"\t" 'message-tab
)
2266 (define-key message-mode-map
"\M-;" 'comment-region
))
2269 message-mode-menu message-mode-map
"Message Menu."
2271 ["Yank Original" message-yank-original message-reply-buffer
]
2272 ["Fill Yanked Message" message-fill-yanked-message t
]
2273 ["Insert Signature" message-insert-signature t
]
2274 ["Caesar (rot13) Message" message-caesar-buffer-body t
]
2275 ["Caesar (rot13) Region" message-caesar-region
(message-mark-active-p)]
2276 ["Elide Region" message-elide-region
2277 :active
(message-mark-active-p)
2278 ,@(if (featurep 'xemacs
) nil
2279 '(:help
"Replace text in region with an ellipsis"))]
2280 ["Delete Outside Region" message-delete-not-region
2281 :active
(message-mark-active-p)
2282 ,@(if (featurep 'xemacs
) nil
2283 '(:help
"Delete all quoted text outside region"))]
2284 ["Kill To Signature" message-kill-to-signature t
]
2285 ["Newline and Reformat" message-newline-and-reformat t
]
2286 ["Rename buffer" message-rename-buffer t
]
2287 ["Spellcheck" ispell-message
2288 ,@(if (featurep 'xemacs
) '(t)
2289 '(:help
"Spellcheck this message"))]
2291 ["Insert Region Marked" message-mark-inserted-region
2292 :active
(message-mark-active-p)
2293 ,@(if (featurep 'xemacs
) nil
2294 '(:help
"Mark region with enclosing tags"))]
2295 ["Insert File Marked..." message-mark-insert-file
2296 ,@(if (featurep 'xemacs
) '(t)
2297 '(:help
"Insert file at point marked with enclosing tags"))]
2299 ["Send Message" message-send-and-exit
2300 ,@(if (featurep 'xemacs
) '(t)
2301 '(:help
"Send this message"))]
2302 ["Postpone Message" message-dont-send
2303 ,@(if (featurep 'xemacs
) '(t)
2304 '(:help
"File this draft message and exit"))]
2305 ["Send at Specific Time..." gnus-delay-article
2306 ,@(if (featurep 'xemacs
) '(t)
2307 '(:help
"Ask, then arrange to send message at that time"))]
2308 ["Kill Message" message-kill-buffer
2309 ,@(if (featurep 'xemacs
) '(t)
2310 '(:help
"Delete this message without sending"))]))
2313 message-mode-field-menu message-mode-map
""
2315 ["To" message-goto-to t
]
2316 ["From" message-goto-from t
]
2317 ["Subject" message-goto-subject t
]
2318 ["Change subject..." message-change-subject t
]
2319 ["Cc" message-goto-cc t
]
2320 ["Bcc" message-goto-bcc t
]
2321 ["Fcc" message-goto-fcc t
]
2322 ["Reply-To" message-goto-reply-to t
]
2323 ["Flag As Important" message-insert-importance-high
2324 ,@(if (featurep 'xemacs
) '(t)
2325 '(:help
"Mark this message as important"))]
2326 ["Flag As Unimportant" message-insert-importance-low
2327 ,@(if (featurep 'xemacs
) '(t)
2328 '(:help
"Mark this message as unimportant"))]
2330 message-insert-disposition-notification-to
2331 ,@(if (featurep 'xemacs
) '(t)
2332 '(:help
"Request a receipt notification"))]
2334 ;; (typical) news stuff
2335 ["Summary" message-goto-summary t
]
2336 ["Keywords" message-goto-keywords t
]
2337 ["Newsgroups" message-goto-newsgroups t
]
2338 ["Fetch Newsgroups" message-insert-newsgroups t
]
2339 ["Followup-To" message-goto-followup-to t
]
2340 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2341 ["Crosspost / Followup-To..." message-cross-post-followup-to t
]
2342 ["Distribution" message-goto-distribution t
]
2343 ["X-No-Archive:" message-add-archive-header t
]
2345 ;; (typical) mailing-lists stuff
2346 ["Fetch To" message-insert-to
2347 ,@(if (featurep 'xemacs
) '(t)
2348 '(:help
"Insert a To header that points to the author."))]
2349 ["Fetch To and Cc" message-insert-wide-reply
2350 ,@(if (featurep 'xemacs
) '(t)
2352 "Insert To and Cc headers as if you were doing a wide reply."))]
2354 ["Send to list only" message-to-list-only t
]
2355 ["Mail-Followup-To" message-goto-mail-followup-to t
]
2356 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2357 ,@(if (featurep 'xemacs
) '(t)
2358 '(:help
"Insert a reasonable `Mail-Followup-To:' header."))]
2359 ["Reduce To: to Cc:" message-reduce-to-to-cc t
]
2361 ["Sort Headers" message-sort-headers t
]
2362 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t
]
2363 ["Goto Body" message-goto-body t
]
2364 ["Goto Signature" message-goto-signature t
]))
2366 (defvar message-tool-bar-map nil
)
2369 (defvar facemenu-add-face-function
)
2370 (defvar facemenu-remove-face-function
))
2372 ;;; Forbidden properties
2374 ;; We use `after-change-functions' to keep special text properties
2375 ;; that interfer with the normal function of message mode out of the
2378 (defcustom message-strip-special-text-properties t
2379 "Strip special properties from the message buffer.
2381 Emacs has a number of special text properties which can break message
2382 composing in various ways. If this option is set, message will strip
2383 these properties from the message composition buffer. However, some
2384 packages requires these properties to be present in order to work.
2385 If you use one of these packages, turn this option off, and hope the
2386 message composition doesn't break too bad."
2388 :group
'message-various
2389 :link
'(custom-manual "(message)Various Message Variables")
2392 (defconst message-forbidden-properties
2393 ;; No reason this should be clutter up customize. We make it a
2394 ;; property list (rather than a list of property symbols), to be
2395 ;; directly useful for `remove-text-properties'.
2396 '(field nil read-only nil invisible nil intangible nil
2397 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2398 insert-behind-hooks nil point-entered nil point-left nil
)
2399 ;; Other special properties:
2400 ;; category, face, display: probably doesn't do any harm.
2401 ;; fontified: is used by font-lock.
2402 ;; syntax-table, local-map: I dunno.
2403 ;; We need to add XEmacs names to the list.
2404 "Property list of with properties forbidden in message buffers.
2405 The values of the properties are ignored, only the property names are used.")
2407 (defun message-tamago-not-in-use-p (pos)
2408 "Return t when tamago version 4 is not in use at the cursor position.
2409 Tamago version 4 is a popular input method for writing Japanese text.
2410 It uses the properties `intangible', `invisible', `modification-hooks'
2411 and `read-only' when translating ascii or kana text to kanji text.
2412 These properties are essential to work, so we should never strip them."
2413 (not (and (boundp 'egg-modefull-mode
)
2414 (symbol-value 'egg-modefull-mode
)
2415 (or (memq (get-text-property pos
'intangible
)
2416 '(its-part-1 its-part-2
))
2417 (get-text-property pos
'egg-end
)
2418 (get-text-property pos
'egg-lang
)
2419 (get-text-property pos
'egg-start
)))))
2421 (defun message-strip-forbidden-properties (begin end
&optional old-length
)
2422 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2423 This function is intended to be called from `after-change-functions'.
2424 See also `message-forbidden-properties'."
2425 (when (and message-strip-special-text-properties
2426 (message-tamago-not-in-use-p begin
))
2427 (let ((buffer-read-only nil
)
2428 (inhibit-read-only t
))
2429 (while (not (= begin end
))
2430 (when (not (get-text-property begin
'message-hidden
))
2431 (remove-text-properties begin
(1+ begin
)
2432 message-forbidden-properties
))
2436 (define-derived-mode message-mode text-mode
"Message"
2437 "Major mode for editing mail and news to be sent.
2438 Like Text Mode but with these additional commands:\\<message-mode-map>
2439 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2440 C-c C-d Postpone sending the message C-c C-k Kill the message
2441 C-c C-f move to a header field (and create it if there isn't):
2442 C-c C-f C-t move to To C-c C-f C-s move to Subject
2443 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2444 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2445 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2446 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2447 C-c C-f C-o move to From (\"Originator\")
2448 C-c C-f C-f move to Followup-To
2449 C-c C-f C-m move to Mail-Followup-To
2450 C-c C-f C-i cycle through Importance values
2451 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2452 C-c C-f x crossposting with FollowUp-To header and note in body
2453 C-c C-f t replace To: header with contents of Cc: or Bcc:
2454 C-c C-f a Insert X-No-Archive: header and a note in the body
2455 C-c C-t `message-insert-to' (add a To header to a news followup)
2456 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2457 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2458 C-c C-b `message-goto-body' (move to beginning of message text).
2459 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2460 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2461 C-c C-y `message-yank-original' (insert current message, if any).
2462 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2463 C-c C-e `message-elide-region' (elide the text between point and mark).
2464 C-c C-v `message-delete-not-region' (remove the text outside the region).
2465 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2466 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2467 C-c C-a `mml-attach-file' (attach a file as MIME).
2468 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2469 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2470 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2471 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2472 M-RET `message-newline-and-reformat' (break the line and reformat)."
2473 (setq local-abbrev-table text-mode-abbrev-table
)
2474 (set (make-local-variable 'message-reply-buffer
) nil
)
2475 (set (make-local-variable 'message-inserted-headers
) nil
)
2476 (set (make-local-variable 'message-send-actions
) nil
)
2477 (set (make-local-variable 'message-exit-actions
) nil
)
2478 (set (make-local-variable 'message-kill-actions
) nil
)
2479 (set (make-local-variable 'message-postpone-actions
) nil
)
2480 (set (make-local-variable 'message-draft-article
) nil
)
2481 (setq buffer-offer-save t
)
2482 (set (make-local-variable 'facemenu-add-face-function
)
2484 (let ((face-fun (cdr (assq face message-face-alist
))))
2486 (funcall face-fun
(point) end
)
2487 (error "Face %s not configured for %s mode" face mode-name
)))
2489 (set (make-local-variable 'facemenu-remove-face-function
) t
)
2490 (set (make-local-variable 'message-reply-headers
) nil
)
2491 (make-local-variable 'message-newsreader
)
2492 (make-local-variable 'message-mailer
)
2493 (make-local-variable 'message-post-method
)
2494 (set (make-local-variable 'message-sent-message-via
) nil
)
2495 (set (make-local-variable 'message-checksum
) nil
)
2496 (set (make-local-variable 'message-mime-part
) 0)
2497 (message-setup-fill-variables)
2498 ;; Allow using comment commands to add/remove quoting.
2499 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2500 (when message-yank-prefix
2501 (set (make-local-variable 'comment-start
) message-yank-prefix
)
2502 (set (make-local-variable 'comment-start-skip
)
2503 (concat "^" (regexp-quote message-yank-prefix
) "[ \t]*")))
2504 (if (featurep 'xemacs
)
2505 (message-setup-toolbar)
2506 (set (make-local-variable 'font-lock-defaults
)
2507 '(message-font-lock-keywords t
))
2508 (if (boundp 'tool-bar-map
)
2509 (set (make-local-variable 'tool-bar-map
) (message-tool-bar-map))))
2510 (easy-menu-add message-mode-menu message-mode-map
)
2511 (easy-menu-add message-mode-field-menu message-mode-map
)
2512 (gnus-make-local-hook 'after-change-functions
)
2513 ;; Mmmm... Forbidden properties...
2514 (add-hook 'after-change-functions
'message-strip-forbidden-properties
2516 ;; Allow mail alias things.
2517 (when (eq message-mail-alias-type
'abbrev
)
2518 (if (fboundp 'mail-abbrevs-setup
)
2519 (mail-abbrevs-setup)
2520 (if (fboundp 'mail-aliases-setup
) ; warning avoidance
2521 (mail-aliases-setup))))
2522 (unless buffer-file-name
2523 (message-set-auto-save-file-name))
2524 (unless (buffer-base-buffer)
2525 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2526 ;; multibyte is not necessary at all. -- zsh
2527 (mm-enable-multibyte))
2528 (set (make-local-variable 'indent-tabs-mode
) nil
) ;No tabs for indentation.
2531 (defun message-setup-fill-variables ()
2532 "Setup message fill variables."
2533 (set (make-local-variable 'fill-paragraph-function
)
2534 'message-fill-paragraph
)
2535 (make-local-variable 'paragraph-separate
)
2536 (make-local-variable 'paragraph-start
)
2537 (make-local-variable 'adaptive-fill-regexp
)
2538 (unless (boundp 'adaptive-fill-first-line-regexp
)
2539 (setq adaptive-fill-first-line-regexp nil
))
2540 (make-local-variable 'adaptive-fill-first-line-regexp
)
2541 (let ((quote-prefix-regexp
2542 ;; User should change message-cite-prefix-regexp if
2543 ;; message-yank-prefix is set to an abnormal value.
2544 (concat "\\(" message-cite-prefix-regexp
"\\)[ \t]*")))
2545 (setq paragraph-start
2547 (regexp-quote mail-header-separator
) "$\\|"
2548 "[ \t]*$\\|" ; blank lines
2549 "-- $\\|" ; signature delimiter
2550 "---+$\\|" ; delimiters for forwarded messages
2551 page-delimiter
"$\\|" ; spoiler warnings
2552 ".*wrote:$\\|" ; attribution lines
2553 quote-prefix-regexp
"$\\|" ; empty lines in quoted text
2555 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
2556 (setq paragraph-separate paragraph-start
)
2557 (setq adaptive-fill-regexp
2558 (concat quote-prefix-regexp
"\\|" adaptive-fill-regexp
))
2559 (setq adaptive-fill-first-line-regexp
2560 (concat quote-prefix-regexp
"\\|"
2561 adaptive-fill-first-line-regexp
)))
2562 (make-local-variable 'auto-fill-inhibit-regexp
)
2563 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2564 (setq auto-fill-inhibit-regexp nil
)
2565 (make-local-variable 'normal-auto-fill-function
)
2566 (setq normal-auto-fill-function
'message-do-auto-fill
)
2567 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2568 ;; In that case, ensure that it uses the right function. The real
2569 ;; solution would be not to use `define-derived-mode', and run
2570 ;; `text-mode-hook' ourself at the end of the mode.
2571 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2572 (when auto-fill-function
2573 (setq auto-fill-function normal-auto-fill-function
)))
2578 ;;; Message mode commands
2581 ;;; Movement commands
2583 (defun message-goto-to ()
2584 "Move point to the To header."
2586 (message-position-on-field "To"))
2588 (defun message-goto-from ()
2589 "Move point to the From header."
2591 (message-position-on-field "From"))
2593 (defun message-goto-subject ()
2594 "Move point to the Subject header."
2596 (message-position-on-field "Subject"))
2598 (defun message-goto-cc ()
2599 "Move point to the Cc header."
2601 (message-position-on-field "Cc" "To"))
2603 (defun message-goto-bcc ()
2604 "Move point to the Bcc header."
2606 (message-position-on-field "Bcc" "Cc" "To"))
2608 (defun message-goto-fcc ()
2609 "Move point to the Fcc header."
2611 (message-position-on-field "Fcc" "To" "Newsgroups"))
2613 (defun message-goto-reply-to ()
2614 "Move point to the Reply-To header."
2616 (message-position-on-field "Reply-To" "Subject"))
2618 (defun message-goto-newsgroups ()
2619 "Move point to the Newsgroups header."
2621 (message-position-on-field "Newsgroups"))
2623 (defun message-goto-distribution ()
2624 "Move point to the Distribution header."
2626 (message-position-on-field "Distribution"))
2628 (defun message-goto-followup-to ()
2629 "Move point to the Followup-To header."
2631 (message-position-on-field "Followup-To" "Newsgroups"))
2633 (defun message-goto-mail-followup-to ()
2634 "Move point to the Mail-Followup-To header."
2636 (message-position-on-field "Mail-Followup-To" "To"))
2638 (defun message-goto-keywords ()
2639 "Move point to the Keywords header."
2641 (message-position-on-field "Keywords" "Subject"))
2643 (defun message-goto-summary ()
2644 "Move point to the Summary header."
2646 (message-position-on-field "Summary" "Subject"))
2648 (defun message-goto-body (&optional interactivep
)
2649 "Move point to the beginning of the message body."
2650 (interactive (list t
))
2651 (when (and interactivep
2652 (looking-at "[ \t]*\n"))
2654 (goto-char (point-min))
2655 (or (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
2656 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t
)))
2658 (defun message-goto-eoh ()
2659 "Move point to the end of the headers."
2664 (defun message-goto-signature ()
2665 "Move point to the beginning of the message signature.
2666 If there is no signature in the article, go to the end and
2669 (goto-char (point-min))
2670 (if (re-search-forward message-signature-separator nil t
)
2672 (goto-char (point-max))
2675 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc
)
2676 "Insert a reasonable MFT header in a post to an unsubscribed list.
2677 When making original posts to a mailing list you are not subscribed to,
2678 you have to type in a MFT header by hand. The contents, usually, are
2679 the addresses of the list and your own address. This function inserts
2680 such a header automatically. It fetches the contents of the To: header
2681 in the current mail buffer, and appends the current `user-mail-address'.
2683 If the optional argument INCLUDE-CC is non-nil, the addresses in the
2684 Cc: header are also put into the MFT."
2689 (message-narrow-to-headers)
2690 (message-remove-header "Mail-Followup-To")
2691 (setq cc
(and include-cc
(message-fetch-field "Cc")))
2693 (concat (message-fetch-field "To") "," cc
)
2694 (message-fetch-field "To"))))
2695 (message-goto-mail-followup-to)
2696 (insert (concat tos
", " user-mail-address
))))
2700 (defun message-insert-to (&optional force
)
2701 "Insert a To header that points to the author of the article being replied to.
2702 If the original author requested not to be sent mail, don't insert unless the
2703 prefix FORCE is given."
2705 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
2706 (dont (and mct
(or (equal (downcase mct
) "never")
2707 (equal (downcase mct
) "nobody"))))
2708 (to (or (message-fetch-reply-field "mail-reply-to")
2709 (message-fetch-reply-field "reply-to")
2710 (message-fetch-reply-field "from"))))
2714 "Ignoring the user request not to have copies sent via mail"
2715 "Complying with the user request not to have copies sent via mail")))
2716 (when (and force
(not to
))
2717 (error "No mail address in the article"))
2718 (when (and to
(or force
(not dont
)))
2719 (message-carefully-insert-headers (list (cons 'To to
))))))
2721 (defun message-insert-wide-reply ()
2722 "Insert To and Cc headers as if you were doing a wide reply."
2724 (let ((headers (message-with-reply-buffer
2725 (message-get-reply-headers t
))))
2726 (message-carefully-insert-headers headers
)))
2728 (defcustom message-header-synonyms
2730 "List of lists of header synonyms.
2731 E.g., if this list contains a member list with elements `Cc' and `To',
2732 then `message-carefully-insert-headers' will not insert a `To' header
2733 when the message is already `Cc'ed to the recipient."
2735 :group
'message-headers
2736 :link
'(custom-manual "(message)Message Headers")
2737 :type
'(repeat sexp
))
2739 (defun message-carefully-insert-headers (headers)
2740 "Insert the HEADERS, an alist, into the message buffer.
2741 Does not insert the headers when they are already present there
2742 or in the synonym headers, defined by `message-header-synonyms'."
2743 ;; FIXME: Should compare only the address and not the full name. Comparison
2744 ;; should be done case-folded (and with `string=' rather than
2746 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
2747 (dolist (header headers
)
2748 (let* ((header-name (symbol-name (car header
)))
2749 (new-header (cdr header
))
2750 (synonyms (loop for synonym in message-header-synonyms
2751 when
(memq (car header
) synonym
) return synonym
))
2753 (loop for synonym in synonyms
2754 for old-header
= (mail-fetch-field (symbol-name synonym
))
2755 when
(and old-header
(string-match new-header old-header
))
2758 (message "already have `%s' in `%s'" new-header old-header
)
2759 (when (and (message-position-on-field header-name
)
2760 (setq old-header
(mail-fetch-field header-name
))
2761 (not (string-match "\\` *\\'" old-header
)))
2763 (insert new-header
)))))
2765 (defun message-widen-reply ()
2766 "Widen the reply to include maximum recipients."
2769 (and message-reply-buffer
2770 (buffer-name message-reply-buffer
)
2772 (set-buffer message-reply-buffer
)
2773 (message-get-reply-headers t
)))))
2776 (message-narrow-to-headers)
2777 (dolist (elem follow-to
)
2778 (message-remove-header (symbol-name (car elem
)))
2779 (goto-char (point-min))
2780 (insert (symbol-name (car elem
)) ": "
2781 (cdr elem
) "\n"))))))
2783 (defun message-insert-newsgroups ()
2784 "Insert the Newsgroups header from the article being replied to."
2786 (when (and (message-position-on-field "Newsgroups")
2787 (mail-fetch-field "newsgroups")
2788 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
2790 (insert (or (message-fetch-reply-field "newsgroups") "")))
2794 ;;; Various commands
2796 (defun message-delete-not-region (beg end
)
2797 "Delete everything in the body of the current message outside of the region."
2802 ;; snarf citation prefix, if appropriate
2803 (unless (eq (point) (progn (beginning-of-line) (point)))
2804 (when (looking-at message-cite-prefix-regexp
)
2805 (setq citeprefix
(match-string 0))))
2807 (delete-region (point) (if (not (message-goto-signature))
2813 (delete-region beg
(progn (message-goto-body)
2817 (insert citeprefix
))))
2818 (when (message-goto-signature)
2821 (defun message-kill-to-signature ()
2822 "Deletes all text up to the signature."
2824 (let ((point (point)))
2825 (message-goto-signature)
2828 (kill-region point
(point))
2832 (defun message-newline-and-reformat (&optional arg not-break
)
2833 "Insert four newlines, and then reformat if inside quoted text.
2834 Prefix arg means justify as well."
2835 (interactive (list (if current-prefix-arg
'full
)))
2836 (let (quoted point beg end leading-space bolp
)
2837 (setq point
(point))
2840 (setq bolp
(= beg point
))
2841 ;; Find first line of the paragraph.
2843 (while (and (not (eobp))
2844 (not (looking-at message-cite-prefix-regexp
))
2845 (looking-at paragraph-start
))
2848 (when (looking-at message-cite-prefix-regexp
)
2849 (setq quoted
(match-string 0))
2850 (goto-char (match-end 0))
2851 (looking-at "[ \t]*")
2852 (setq leading-space
(match-string 0)))
2856 (< (- point beg
) (length quoted
)))
2857 ;; break inside the cite prefix.
2863 (while (and (not (eobp))
2864 (not (looking-at paragraph-separate
))
2865 (looking-at message-cite-prefix-regexp
)
2866 (equal quoted
(match-string 0)))
2867 (goto-char (match-end 0))
2868 (looking-at "[ \t]*")
2869 (if (> (length leading-space
) (length (match-string 0)))
2870 (setq leading-space
(match-string 0)))
2874 (while (and (if (bobp) nil
(forward-line -
1) t
)
2875 (not (looking-at paragraph-start
))
2876 (looking-at message-cite-prefix-regexp
)
2877 (equal quoted
(match-string 0)))
2879 (goto-char (match-end 0))
2880 (looking-at "[ \t]*")
2881 (if (> (length leading-space
) (length (match-string 0)))
2882 (setq leading-space
(match-string 0)))))
2883 (while (and (not (eobp))
2884 (not (looking-at paragraph-separate
))
2885 (not (looking-at message-cite-prefix-regexp
)))
2889 (while (and (if (bobp) nil
(forward-line -
1) t
)
2890 (not (looking-at paragraph-start
))
2891 (not (looking-at message-cite-prefix-regexp
)))
2892 (setq beg
(point))))
2895 (narrow-to-region beg end
)
2902 (setq point
(point))
2903 ;; (newline 2) doesn't mark both newline's as hard, so call
2904 ;; newline twice. -jas
2907 (delete-region (point) (re-search-forward "[ \t]*"))
2908 (when (and quoted
(not bolp
))
2909 (insert quoted leading-space
)))
2912 (let* ((adaptive-fill-regexp
2913 (regexp-quote (concat quoted leading-space
)))
2914 (adaptive-fill-first-line-regexp
2915 adaptive-fill-regexp
))
2916 (fill-paragraph arg
))
2917 (fill-paragraph arg
))
2918 (if point
(goto-char point
)))))
2920 (defun message-fill-paragraph (&optional arg
)
2921 "Like `fill-paragraph'."
2922 (interactive (list (if current-prefix-arg
'full
)))
2923 (if (if (boundp 'filladapt-mode
) filladapt-mode
)
2925 (message-newline-and-reformat arg t
)
2928 ;; Is it better to use `mail-header-end'?
2929 (defun message-point-in-header-p ()
2930 "Return t if point is in the header."
2933 (goto-char (point-min))
2934 (not (re-search-forward
2935 (concat "^" (regexp-quote mail-header-separator
) "\n")
2938 (defun message-do-auto-fill ()
2939 "Like `do-auto-fill', but don't fill in message header."
2940 (unless (message-point-in-header-p)
2943 (defun message-insert-signature (&optional force
)
2944 "Insert a signature. See documentation for variable `message-signature'."
2945 (interactive (list 0))
2948 ((and (null message-signature
)
2951 (goto-char (point-max))
2952 (not (re-search-backward message-signature-separator nil t
))))
2953 ((and (null message-signature
)
2956 ((functionp message-signature
)
2957 (funcall message-signature
))
2958 ((listp message-signature
)
2959 (eval message-signature
))
2960 (t message-signature
)))
2962 (cond ((stringp signature
)
2964 ((and (eq t signature
)
2965 message-signature-file
2966 (file-exists-p message-signature-file
))
2969 (goto-char (point-max))
2970 ;; Insert the signature.
2973 (when message-signature-insert-empty-line
2976 (if (eq signature t
)
2977 (insert-file-contents message-signature-file
)
2979 (goto-char (point-max))
2980 (or (bolp) (insert "\n")))))
2982 (defun message-insert-importance-high ()
2983 "Insert header to mark message as important."
2987 (message-narrow-to-headers)
2988 (message-remove-header "Importance"))
2990 (insert "Importance: high\n")))
2992 (defun message-insert-importance-low ()
2993 "Insert header to mark message as unimportant."
2997 (message-narrow-to-headers)
2998 (message-remove-header "Importance"))
3000 (insert "Importance: low\n")))
3002 (defun message-insert-or-toggle-importance ()
3003 "Insert a \"Importance: high\" header, or cycle through the header values.
3004 The three allowed values according to RFC 1327 are `high', `normal'
3008 (let ((valid '("high" "normal" "low"))
3012 (message-narrow-to-headers)
3013 (when (setq cur
(message-fetch-field "Importance"))
3014 (message-remove-header "Importance")
3015 (setq new
(cond ((string= cur
"high")
3017 ((string= cur
"low")
3022 (insert (format "Importance: %s\n" new
)))))
3024 (defun message-insert-disposition-notification-to ()
3025 "Request a disposition notification (return receipt) to this message.
3026 Note that this should not be used in newsgroups."
3030 (message-narrow-to-headers)
3031 (message-remove-header "Disposition-Notification-To"))
3033 (insert (format "Disposition-Notification-To: %s\n"
3034 (or (message-field-value "Reply-to")
3035 (message-field-value "From")
3036 (message-make-from))))))
3038 (defun message-elide-region (b e
)
3039 "Elide the text in the region.
3040 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3044 (insert message-elide-ellipsis
))
3046 (defvar message-caesar-translation-table nil
)
3048 (defun message-caesar-region (b e
&optional n
)
3049 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3052 (min (point) (or (mark t
) (point)))
3053 (max (point) (or (mark t
) (point)))
3054 (when current-prefix-arg
3055 (prefix-numeric-value current-prefix-arg
))))
3057 (setq n
(if (numberp n
) (mod n
26) 13)) ;canonize N
3058 (unless (or (zerop n
) ; no action needed for a rot of 0
3059 (= b e
)) ; no region to rotate
3060 ;; We build the table, if necessary.
3061 (when (or (not message-caesar-translation-table
)
3062 (/= (aref message-caesar-translation-table ?a
) (+ ?a n
)))
3063 (setq message-caesar-translation-table
3064 (message-make-caesar-translation-table n
)))
3065 (translate-region b e message-caesar-translation-table
)))
3067 (defun message-make-caesar-translation-table (n)
3068 "Create a rot table with offset N."
3070 (table (make-string 256 0)))
3071 (while (< (incf i
) 256)
3074 (substring table
0 ?A
)
3075 (substring table
(+ ?A n
) (+ ?A n
(- 26 n
)))
3076 (substring table ?A
(+ ?A n
))
3077 (substring table
(+ ?A
26) ?a
)
3078 (substring table
(+ ?a n
) (+ ?a n
(- 26 n
)))
3079 (substring table ?a
(+ ?a n
))
3080 (substring table
(+ ?a
26) 255))))
3082 (defun message-caesar-buffer-body (&optional rotnum
)
3083 "Caesar rotate all letters in the current buffer by 13 places.
3084 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3085 With prefix arg, specifies the number of places to rotate each letter forward.
3086 Mail and USENET news headers are not rotated."
3087 (interactive (if current-prefix-arg
3088 (list (prefix-numeric-value current-prefix-arg
))
3092 (when (message-goto-body)
3093 (narrow-to-region (point) (point-max)))
3094 (message-caesar-region (point-min) (point-max) rotnum
))))
3096 (defun message-pipe-buffer-body (program)
3097 "Pipe the message body in the current buffer through PROGRAM."
3100 (when (message-goto-body)
3101 (narrow-to-region (point) (point-max)))
3102 (shell-command-on-region
3103 (point-min) (point-max) program nil t
))))
3105 (defun message-rename-buffer (&optional enter-string
)
3106 "Rename the *message* buffer to \"*message* RECIPIENT\".
3107 If the function is run with a prefix, it will ask for a new buffer
3108 name, rather than giving an automatic name."
3109 (interactive "Pbuffer name: ")
3112 (goto-char (point-min))
3113 (narrow-to-region (point)
3114 (search-forward mail-header-separator nil
'end
))
3116 (if (message-news-p) (message-fetch-field "Newsgroups")
3117 (message-fetch-field "To"))
3120 (if (string-match "," mail-to
)
3121 (concat (substring mail-to
0 (match-beginning 0)) ", ...")
3123 (name-default (concat "*message* " mail-trimmed-to
))
3124 (name (if enter-string
3125 (read-string "New buffer name: " name-default
)
3127 (rename-buffer name t
)))))
3129 (defun message-fill-yanked-message (&optional justifyp
)
3130 "Fill the paragraphs of a message yanked into this one.
3131 Numeric argument means justify as well."
3134 (goto-char (point-min))
3135 (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
3136 (let ((fill-prefix message-yank-prefix
))
3137 (fill-individual-paragraphs (point) (point-max) justifyp
))))
3139 (defun message-indent-citation ()
3140 "Modify text just inserted from a message to be cited.
3141 The inserted text should be the region.
3142 When this function returns, the region is again around the modified text.
3144 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3145 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3146 (let ((start (point)))
3147 ;; Remove unwanted headers.
3148 (when message-ignored-cited-headers
3153 (if (search-forward "\n\n" nil t
)
3156 (message-remove-header message-ignored-cited-headers t
)
3157 (when (= (point-min) (point-max))
3158 (setq all-removed t
))
3159 (goto-char (point-max)))
3163 ;; Delete blank lines at the start of the buffer.
3164 (while (and (point-min)
3167 (message-delete-line))
3168 ;; Delete blank lines at the end of the buffer.
3169 (goto-char (point-max))
3172 (while (and (zerop (forward-line -
1))
3174 (message-delete-line))
3175 ;; Do the indentation.
3176 (if (null message-yank-prefix
)
3177 (indent-rigidly start
(mark t
) message-indentation-spaces
)
3180 (while (< (point) (mark t
))
3181 (if (or (looking-at ">") (looking-at "^$"))
3182 (insert message-yank-cited-prefix
)
3183 (insert message-yank-prefix
))
3187 (defun message-yank-original (&optional arg
)
3188 "Insert the message being replied to, if any.
3189 Puts point before the text and mark after.
3190 Normally indents each nonblank line ARG spaces (default 3). However,
3191 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3193 This function uses `message-cite-function' to do the actual citing.
3195 Just \\[universal-argument] as argument means don't indent, insert no
3196 prefix, and don't delete any headers."
3198 (let ((modified (buffer-modified-p)))
3199 (when (and message-reply-buffer
3200 message-cite-function
)
3201 (delete-windows-on message-reply-buffer t
)
3202 (insert-buffer message-reply-buffer
)
3204 (funcall message-cite-function
))
3205 (message-exchange-point-and-mark)
3209 (setq message-checksum
(message-checksum))))))
3211 (defun message-yank-buffer (buffer)
3212 "Insert BUFFER into the current buffer and quote it."
3213 (interactive "bYank buffer: ")
3214 (let ((message-reply-buffer (get-buffer buffer
)))
3215 (save-window-excursion
3216 (message-yank-original))))
3218 (defun message-buffers ()
3219 "Return a list of active message buffers."
3222 (dolist (buffer (buffer-list t
))
3224 (when (and (eq major-mode
'message-mode
)
3225 (null message-sent-message-via
))
3226 (push (buffer-name buffer
) buffers
))))
3227 (nreverse buffers
)))
3229 (defun message-cite-original-without-signature ()
3230 "Cite function in the standard Message manner."
3231 (let* ((start (point))
3234 (when message-indent-citation-function
3235 (if (listp message-indent-citation-function
)
3236 message-indent-citation-function
3237 (list message-indent-citation-function
))))
3238 ;; This function may be called by `gnus-summary-yank-message' and
3239 ;; may insert a different article from the original. So, we will
3240 ;; modify the value of `message-reply-headers' with that article.
3241 (message-reply-headers
3243 (narrow-to-region start end
)
3244 (message-narrow-to-head-1)
3246 (or (message-fetch-field "subject") "none")
3247 (message-fetch-field "from")
3248 (message-fetch-field "date")
3249 (message-fetch-field "message-id" t
)
3250 (message-fetch-field "references")
3252 (mml-quote-region start end
)
3256 (when (re-search-backward message-signature-separator start t
)
3257 ;; Also peel off any blank lines before the signature.
3259 (while (looking-at "^[ \t]*$")
3262 (delete-region (point) end
)
3263 (unless (search-backward "\n\n" start t
)
3264 ;; Insert a blank line if it is peeled off.
3268 (funcall (pop functions
)))
3269 (when message-citation-line-function
3272 (funcall message-citation-line-function
))))
3274 (eval-when-compile (defvar mail-citation-hook
)) ;Compiler directive
3275 (defun message-cite-original ()
3276 "Cite function in the standard Message manner."
3277 (if (and (boundp 'mail-citation-hook
)
3279 (run-hooks 'mail-citation-hook
)
3280 (let* ((start (point))
3283 (when message-indent-citation-function
3284 (if (listp message-indent-citation-function
)
3285 message-indent-citation-function
3286 (list message-indent-citation-function
))))
3287 ;; This function may be called by `gnus-summary-yank-message' and
3288 ;; may insert a different article from the original. So, we will
3289 ;; modify the value of `message-reply-headers' with that article.
3290 (message-reply-headers
3292 (narrow-to-region start end
)
3293 (message-narrow-to-head-1)
3295 (or (message-fetch-field "subject") "none")
3296 (message-fetch-field "from")
3297 (message-fetch-field "date")
3298 (message-fetch-field "message-id" t
)
3299 (message-fetch-field "references")
3301 (mml-quote-region start end
)
3304 (funcall (pop functions
)))
3305 (when message-citation-line-function
3308 (funcall message-citation-line-function
)))))
3310 (defun message-insert-citation-line ()
3311 "Insert a simple citation line."
3312 (when message-reply-headers
3313 (insert (mail-header-from message-reply-headers
) " writes:\n\n")))
3315 (defun message-position-on-field (header &rest afters
)
3316 (let ((case-fold-search t
))
3319 (goto-char (point-min))
3322 (concat "^" (regexp-quote mail-header-separator
) "$"))
3323 (match-beginning 0)))
3324 (goto-char (point-min))
3325 (if (re-search-forward (concat "^" (regexp-quote header
) ":") nil t
)
3327 (re-search-forward "^[^ \t]" nil
'move
)
3329 (skip-chars-backward "\n")
3332 (not (re-search-forward
3333 (concat "^" (regexp-quote (car afters
)) ":")
3337 (re-search-forward "^[^ \t]" nil
'move
)
3338 (beginning-of-line))
3339 (insert header
": \n")
3343 (defun message-remove-signature ()
3344 "Remove the signature from the text between point and mark.
3345 The text will also be indented the normal way."
3347 (let ((start (point))
3349 (if (not (re-search-forward message-signature-separator
(mark t
) t
))
3350 ;; No signature here, so we just indent the cited text.
3351 (message-indent-citation)
3352 ;; Find the last non-empty line.
3354 (while (looking-at "[ \t]*$")
3357 (setq mark
(set-marker (make-marker) (point)))
3359 (message-indent-citation)
3360 ;; Enable undoing the deletion.
3362 (delete-region mark
(mark t
))
3363 (set-marker mark nil
)))))
3368 ;;; Sending messages
3371 (defun message-send-and-exit (&optional arg
)
3372 "Send message like `message-send', then, if no errors, exit from mail buffer."
3374 (let ((buf (current-buffer))
3375 (actions message-exit-actions
))
3376 (when (and (message-send arg
)
3378 (if message-kill-buffer-on-exit
3381 (when (eq buf
(current-buffer))
3382 (message-bury buf
)))
3383 (message-do-actions actions
)
3386 (defun message-dont-send ()
3387 "Don't send the message you have been editing.
3388 Instead, just auto-save the buffer and then bury it."
3390 (set-buffer-modified-p t
)
3392 (let ((actions message-postpone-actions
))
3393 (message-bury (current-buffer))
3394 (message-do-actions actions
)))
3396 (defun message-kill-buffer ()
3397 "Kill the current buffer."
3399 (when (or (not (buffer-modified-p))
3400 (yes-or-no-p "Message modified; kill anyway? "))
3401 (let ((actions message-kill-actions
)
3402 (draft-article message-draft-article
)
3403 (auto-save-file-name buffer-auto-save-file-name
)
3404 (file-name buffer-file-name
)
3405 (modified (buffer-modified-p)))
3406 (setq buffer-file-name nil
)
3407 (kill-buffer (current-buffer))
3408 (when (and (or (and auto-save-file-name
3409 (file-exists-p auto-save-file-name
))
3411 (file-exists-p file-name
)))
3412 (yes-or-no-p (format "Remove the backup file%s? "
3413 (if modified
" too" ""))))
3415 (delete-file auto-save-file-name
))
3416 (let ((message-draft-article draft-article
))
3417 (message-disassociate-draft)))
3418 (message-do-actions actions
))))
3420 (defun message-bury (buffer)
3421 "Bury this mail BUFFER."
3422 (let ((newbuf (other-buffer buffer
)))
3423 (bury-buffer buffer
)
3424 (if (and (fboundp 'frame-parameters
)
3425 (cdr (assq 'dedicated
(frame-parameters)))
3426 (not (null (delq (selected-frame) (visible-frame-list)))))
3427 (delete-frame (selected-frame))
3428 (switch-to-buffer newbuf
))))
3430 (defun message-send (&optional arg
)
3431 "Send the message in the current buffer.
3432 If `message-interactive' is non-nil, wait for success indication or
3433 error messages, and inform user.
3434 Otherwise any failure is reported in a message back to the user from
3436 The usage of ARG is defined by the instance that called Message.
3437 It should typically alter the sending method in some way or other."
3439 ;; Make it possible to undo the coming changes.
3441 (let ((inhibit-read-only t
))
3442 (put-text-property (point-min) (point-max) 'read-only nil
))
3443 (message-fix-before-sending)
3444 (run-hooks 'message-send-hook
)
3445 (message message-sending-message
)
3446 (let ((alist message-send-method-alist
)
3448 elem sent dont-barf-on-no-method
3449 (message-options message-options
))
3450 (message-options-set-recipient)
3452 (setq elem
(pop alist
)))
3453 (when (funcall (cadr elem
))
3454 (when (and (or (not (memq (car elem
)
3455 message-sent-message-via
))
3456 (message-fetch-field "supersedes")
3457 (if (or (message-gnksa-enable-p 'multiple-copies
)
3458 (not (eq (car elem
) 'news
)))
3461 "Already sent message via %s; resend? "
3463 (error "Denied posting -- multiple copies")))
3464 (setq success
(funcall (caddr elem
) arg
)))
3468 (let ((fcc (message-fetch-field "Fcc"))
3469 (gcc (message-fetch-field "Gcc")))
3471 (or (eq message-allow-no-recipients
'always
)
3472 (and (not (eq message-allow-no-recipients
'never
))
3473 (setq dont-barf-on-no-method
3475 (format "No receiver, perform %s anyway? "
3476 (cond ((and fcc gcc
) "Fcc and Gcc")
3479 (error "No methods specified to send by"))
3480 (when (or dont-barf-on-no-method
3484 (run-hooks 'message-sent-hook
))
3485 (message "Sending...done")
3486 ;; Mark the buffer as unmodified and delete auto-save.
3487 (set-buffer-modified-p nil
)
3488 (delete-auto-save-file-if-necessary t
)
3489 (message-disassociate-draft)
3490 ;; Delete other mail buffers and stuff.
3491 (message-do-send-housekeeping)
3492 (message-do-actions message-send-actions
)
3496 (defun message-send-via-mail (arg)
3497 "Send the current message via mail."
3498 (message-send-mail arg
))
3500 (defun message-send-via-news (arg)
3501 "Send the current message via news."
3502 (funcall message-send-news-function arg
))
3504 (defmacro message-check
(type &rest forms
)
3505 "Eval FORMS if TYPE is to be checked."
3506 `(or (message-check-element ,type
)
3510 (put 'message-check
'lisp-indent-function
1)
3511 (put 'message-check
'edebug-form-spec
'(form body
))
3513 (defun message-text-with-property (prop)
3514 "Return a list of all points where the text has PROP."
3516 (point (point-min)))
3518 (while (< point
(point-max))
3519 (when (get-text-property point prop
)
3520 (push point points
))
3524 (defun message-fix-before-sending ()
3525 "Do various things to make the message nice before sending it."
3526 ;; Make sure there's a newline at the end of the message.
3527 (goto-char (point-max))
3530 ;; Make the hidden headers visible.
3531 (let ((points (message-text-with-property 'message-hidden
)))
3533 (goto-char (car points
))
3534 (dolist (point points
)
3535 (add-text-properties point
(1+ point
)
3536 '(invisible nil intangible nil
)))))
3537 ;; Make invisible text visible.
3538 ;; It doesn't seem as if this is useful, since the invisible property
3539 ;; is clobbered by an after-change hook anyhow.
3540 (message-check 'invisible-text
3541 (let ((points (message-text-with-property 'invisible
)))
3543 (goto-char (car points
))
3544 (dolist (point points
)
3545 (put-text-property point
(1+ point
) 'invisible nil
)
3546 (message-overlay-put (message-make-overlay point
(1+ point
))
3548 (unless (yes-or-no-p
3549 "Invisible text found and made visible; continue sending? ")
3550 (error "Invisible text found and made visible")))))
3551 (message-check 'illegible-text
3554 (skip-chars-forward mm-7bit-chars
)
3556 (when (let ((char (char-after)))
3557 (or (< (mm-char-int char
) 128)
3558 (and (mm-multibyte-p)
3559 (memq (char-charset char
)
3560 '(eight-bit-control eight-bit-graphic
3562 (not (get-text-property
3563 (point) 'untranslated-utf-8
)))))
3564 (message-overlay-put (message-make-overlay (point) (1+ (point)))
3568 (skip-chars-forward mm-7bit-chars
))
3571 (gnus-multiple-choice
3572 "Non-printable characters found. Continue sending?"
3573 '((?d
"Remove non-printable characters and send")
3574 (?r
"Replace non-printable characters with dots and send")
3575 (?i
"Ignore non-printable characters and send")
3576 (?e
"Continue editing"))))
3578 (error "Non-printable characters"))
3580 (skip-chars-forward mm-7bit-chars
)
3582 (when (let ((char (char-after)))
3583 (or (< (mm-char-int char
) 128)
3584 (and (mm-multibyte-p)
3585 ;; Fixme: Wrong for Emacs 22 and for things
3586 ;; like undecable utf-8. Should at least
3587 ;; use find-coding-systems-region.
3588 (memq (char-charset char
)
3589 '(eight-bit-control eight-bit-graphic
3591 (not (get-text-property
3592 (point) 'untranslated-utf-8
)))))
3594 (message-kill-all-overlays)
3596 (when (eq choice ?r
)
3599 (skip-chars-forward mm-7bit-chars
))))))
3601 (defun message-add-action (action &rest types
)
3602 "Add ACTION to be performed when doing an exit of type TYPES."
3604 (add-to-list (intern (format "message-%s-actions" (pop types
)))
3607 (defun message-delete-action (action &rest types
)
3608 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
3611 (set (setq var
(intern (format "message-%s-actions" (pop types
))))
3612 (delq action
(symbol-value var
))))))
3614 (defun message-do-actions (actions)
3615 "Perform all actions in ACTIONS."
3616 ;; Now perform actions on successful sending.
3620 ;; A simple function.
3621 ((functionp (car actions
))
3622 (funcall (car actions
)))
3623 ;; Something to be evaled.
3625 (eval (car actions
)))))
3628 (defun message-send-mail-partially ()
3629 "Send mail as message/partial."
3630 ;; replace the header delimiter with a blank line
3631 (goto-char (point-min))
3633 (concat "^" (regexp-quote mail-header-separator
) "\n"))
3634 (replace-match "\n")
3635 (run-hooks 'message-send-mail-hook
)
3636 (let ((p (goto-char (point-min)))
3637 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
3638 (curbuf (current-buffer))
3639 (id (message-make-message-id)) (n 1)
3640 plist total header required-mail-headers
)
3642 (if (< (point-max) (+ p message-send-mail-partially-limit
))
3643 (goto-char (point-max))
3644 (goto-char (+ p message-send-mail-partially-limit
))
3646 (if (<= (point) p
) (forward-line 1))) ;; In case of bad message.
3649 (setq total
(length plist
))
3650 (push (point-max) plist
)
3651 (setq plist
(nreverse plist
))
3654 (setq p
(pop plist
))
3657 (copy-to-buffer tembuf p
(car plist
))
3659 (goto-char (point-min))
3662 (goto-char (point-min))
3663 (narrow-to-region (point) (point))
3666 (setq header
(buffer-substring (point-min) (point)))
3667 (goto-char (point-min))
3668 (narrow-to-region (point) (point))
3670 (message-remove-header "Mime-Version")
3671 (message-remove-header "Content-Type")
3672 (message-remove-header "Content-Transfer-Encoding")
3673 (message-remove-header "Message-ID")
3674 (message-remove-header "Lines")
3675 (goto-char (point-max))
3676 (insert "Mime-Version: 1.0\n")
3677 (setq header
(buffer-string)))
3678 (goto-char (point-max))
3679 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
3682 (let ((mail-header-separator ""))
3683 (when (memq 'Message-ID message-required-mail-headers
)
3684 (insert "Message-ID: " (message-make-message-id) "\n"))
3685 (when (memq 'Lines message-required-mail-headers
)
3686 (insert "Lines: " (message-make-lines) "\n"))
3687 (message-goto-subject)
3689 (insert (format " (%d/%d)" n total
))
3691 (mm-with-unibyte-current-buffer
3692 (funcall (or message-send-mail-real-function
3693 message-send-mail-function
))))
3695 (setq p
(pop plist
))
3697 (kill-buffer tembuf
))))
3699 (defun message-send-mail (&optional arg
)
3700 (require 'mail-utils
)
3701 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
3702 (case-fold-search nil
)
3703 (news (message-news-p))
3704 (mailbuf (current-buffer))
3705 (message-this-is-mail t
)
3706 (message-posting-charset
3707 (if (fboundp 'gnus-setup-posting-charset
)
3708 (gnus-setup-posting-charset nil
)
3709 message-posting-charset
))
3710 (headers message-required-mail-headers
))
3712 (message-narrow-to-headers)
3713 ;; Generate the Mail-Followup-To header if the header is not there...
3714 (if (and (message-subscribed-p)
3715 (not (mail-fetch-field "mail-followup-to")))
3718 (cons "Mail-Followup-To" (message-make-mail-followup-to))
3719 message-required-mail-headers
))
3720 ;; otherwise, delete the MFT header if the field is empty
3721 (when (equal "" (mail-fetch-field "mail-followup-to"))
3722 (message-remove-header "^Mail-Followup-To:")))
3723 ;; Insert some headers.
3724 (let ((message-deletable-headers
3725 (if news nil message-deletable-headers
)))
3726 (message-generate-headers headers
))
3727 ;; Let the user do all of the above.
3728 (run-hooks 'message-header-hook
))
3733 ;; Avoid copying text props (except hard newlines).
3734 (insert (with-current-buffer mailbuf
3735 (mml-buffer-substring-no-properties-except-hard-newlines
3736 (point-min) (point-max))))
3737 ;; Remove some headers.
3738 (message-encode-message-body)
3740 (message-narrow-to-headers)
3741 ;; We (re)generate the Lines header.
3742 (when (memq 'Lines message-required-mail-headers
)
3743 (message-generate-headers '(Lines)))
3744 ;; Remove some headers.
3745 (message-remove-header message-ignored-mail-headers t
)
3746 (let ((mail-parse-charset message-default-charset
))
3747 (mail-encode-encoded-word-buffer)))
3748 (goto-char (point-max))
3749 ;; require one newline at the end.
3750 (or (= (preceding-char) ?
\n)
3752 (message-cleanup-headers)
3753 ;; FIXME: we're inserting the courtesy copy after encoding.
3754 ;; This is wrong if the courtesy copy string contains
3755 ;; non-ASCII characters. -- jh
3758 (message-narrow-to-headers)
3760 (or (message-fetch-field "cc")
3761 (message-fetch-field "bcc")
3762 (message-fetch-field "to"))
3763 (let ((content-type (message-fetch-field
3768 (string= "text/plain"
3770 (mail-header-parse-content-type
3774 (message-fetch-field
3775 "content-transfer-encoding")))))))
3776 (message-insert-courtesy-copy))
3777 (if (or (not message-send-mail-partially-limit
)
3778 (< (buffer-size) message-send-mail-partially-limit
)
3779 (not (message-y-or-n-p
3780 "The message size is too large, split? "
3784 (/ (buffer-size) 1000) "KB, is too large.
3786 Some mail gateways (MTA's) bounce large messages. To avoid the
3787 problem, answer `y', and the message will be split into several
3788 smaller pieces, the size of each is about "
3789 (/ message-send-mail-partially-limit
1000)
3793 However, some mail readers (MUA's) can't read split messages, i.e.,
3794 mails in message/partially format. Answer `n', and the message will be
3797 The size limit is controlled by `message-send-mail-partially-limit'.
3798 If you always want Gnus to send messages in one piece, set
3799 `message-send-mail-partially-limit' to nil.
3801 (mm-with-unibyte-current-buffer
3802 (message "Sending via mail...")
3803 (funcall (or message-send-mail-real-function
3804 message-send-mail-function
)))
3805 (message-send-mail-partially)))
3806 (kill-buffer tembuf
))
3807 (set-buffer mailbuf
)
3808 (push 'mail message-sent-message-via
)))
3810 (defun message-send-mail-with-sendmail ()
3811 "Send off the prepared buffer with sendmail."
3812 (let ((errbuf (if message-interactive
3813 (message-generate-new-buffer-clone-locals
3816 resend-to-addresses delimline
)
3819 (let ((case-fold-search t
))
3821 (message-narrow-to-headers)
3822 (setq resend-to-addresses
(message-fetch-field "resent-to")))
3823 ;; Change header-delimiter to be what sendmail expects.
3824 (goto-char (point-min))
3826 (concat "^" (regexp-quote mail-header-separator
) "\n"))
3827 (replace-match "\n")
3829 (setq delimline
(point-marker))
3830 (run-hooks 'message-send-mail-hook
)
3831 ;; Insert an extra newline if we need it to work around
3832 ;; Sun's bug that swallows newlines.
3833 (goto-char (1+ delimline
))
3834 (when (eval message-mailer-swallows-blank-line
)
3836 (when message-interactive
3840 (let* ((default-directory "/")
3841 (coding-system-for-write message-send-coding-system
)
3843 'call-process-region
3845 (list (point-min) (point-max)
3846 (if (boundp 'sendmail-program
)
3848 "/usr/lib/sendmail")
3849 nil errbuf nil
"-oi")
3850 ;; Always specify who from,
3851 ;; since some systems have broken sendmails.
3852 ;; But some systems are more broken with -f, so
3853 ;; we'll let users override this.
3854 (if (null message-sendmail-f-is-evil
)
3855 (list "-f" (message-sendmail-envelope-from)))
3856 ;; These mean "report errors by mail"
3857 ;; and "deliver in background".
3858 (if (null message-interactive
) '("-oem" "-odb"))
3859 ;; Get the addresses from the message
3860 ;; unless this is a resend.
3861 ;; We must not do that for a resend
3862 ;; because we would find the original addresses.
3863 ;; For a resend, include the specific addresses.
3864 (if resend-to-addresses
3865 (list resend-to-addresses
)
3867 (unless (or (null cpr
) (and (numberp cpr
) (zerop cpr
)))
3868 (error "Sending...failed with exit value %d" cpr
)))
3869 (when message-interactive
3872 (goto-char (point-min))
3873 (while (re-search-forward "\n\n* *" nil t
)
3874 (replace-match "; "))
3875 (if (not (zerop (buffer-size)))
3876 (error "Sending...failed to %s"
3877 (buffer-string))))))
3878 (when (bufferp errbuf
)
3879 (kill-buffer errbuf
)))))
3881 (defun message-send-mail-with-qmail ()
3882 "Pass the prepared message buffer to qmail-inject.
3883 Refer to the documentation for the variable `message-send-mail-function'
3884 to find out how to use this."
3885 ;; replace the header delimiter with a blank line
3886 (goto-char (point-min))
3888 (concat "^" (regexp-quote mail-header-separator
) "\n"))
3889 (replace-match "\n")
3890 (run-hooks 'message-send-mail-hook
)
3893 (let ((coding-system-for-write message-send-coding-system
))
3895 'call-process-region
(point-min) (point-max)
3896 message-qmail-inject-program nil nil nil
3897 ;; qmail-inject's default behaviour is to look for addresses on the
3898 ;; command line; if there're none, it scans the headers.
3899 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
3901 ;; in general, ALL of qmail-inject's defaults are perfect for simply
3902 ;; reading a formatted (i. e., at least a To: or Resent-To header)
3903 ;; message from stdin.
3905 ;; qmail also has the advantage of not having been raped by
3906 ;; various vendors, so we don't have to allow for that, either --
3907 ;; compare this with message-send-mail-with-sendmail and weep
3908 ;; for sendmail's lost innocence.
3910 ;; all this is way cool coz it lets us keep the arguments entirely
3911 ;; free for -inject-arguments -- a big win for the user and for us
3912 ;; since we don't have to play that double-guessing game and the user
3913 ;; gets full control (no gestapo'ish -f's, for instance). --sj
3914 (if (functionp message-qmail-inject-args
)
3915 (funcall message-qmail-inject-args
)
3916 message-qmail-inject-args
)))
3917 ;; qmail-inject doesn't say anything on it's stdout/stderr,
3918 ;; we have to look at the retval instead
3920 (100 (error "qmail-inject reported permanent failure"))
3921 (111 (error "qmail-inject reported transient failure"))
3922 ;; should never happen
3923 (t (error "qmail-inject reported unknown failure"))))
3925 (defun message-send-mail-with-mh ()
3926 "Send the prepared message buffer with mh."
3927 (let ((mh-previous-window-config nil
)
3928 (name (mh-new-draft-name)))
3929 (setq buffer-file-name name
)
3930 ;; MH wants to generate these headers itself.
3931 (when message-mh-deletable-headers
3932 (let ((headers message-mh-deletable-headers
))
3934 (goto-char (point-min))
3935 (and (re-search-forward
3936 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
3937 (message-delete-line))
3939 (run-hooks 'message-send-mail-hook
)
3940 ;; Pass it on to mh.
3943 (defun message-smtpmail-send-it ()
3944 "Send the prepared message buffer with `smtpmail-send-it'.
3945 This only differs from `smtpmail-send-it' that this command evaluates
3946 `message-send-mail-hook' just before sending a message. It is useful
3947 if your ISP requires the POP-before-SMTP authentication. See the Gnus
3948 manual for details."
3949 (run-hooks 'message-send-mail-hook
)
3952 (defun message-canlock-generate ()
3953 "Return a string that is non-trivial to guess.
3954 Do not use this for anything important, it is cryptographically weak."
3956 (let (sha1-maximum-internal-length)
3957 (sha1 (concat (message-unique-id)
3958 (format "%x%x%x" (random) (random t
) (random))
3959 (prin1-to-string (recent-keys))
3960 (prin1-to-string (garbage-collect))))))
3962 (defun message-canlock-password ()
3963 "The password used by message for cancel locks.
3964 This is the value of `canlock-password', if that option is non-nil.
3965 Otherwise, generate and save a value for `canlock-password' first."
3966 (unless canlock-password
3967 (customize-save-variable 'canlock-password
(message-canlock-generate))
3968 (setq canlock-password-for-verify canlock-password
))
3971 (defun message-insert-canlock ()
3972 (when message-insert-canlock
3973 (message-canlock-password)
3974 (canlock-insert-header)))
3976 (defun message-send-news (&optional arg
)
3977 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
3978 (case-fold-search nil
)
3979 (method (if (functionp message-post-method
)
3980 (funcall message-post-method arg
)
3981 message-post-method
))
3982 (newsgroups-field (save-restriction
3983 (message-narrow-to-headers-or-head)
3984 (message-fetch-field "Newsgroups")))
3985 (followup-field (save-restriction
3986 (message-narrow-to-headers-or-head)
3987 (message-fetch-field "Followup-To")))
3988 ;; BUG: We really need to get the charset for each name in the
3989 ;; Newsgroups and Followup-To lines to allow crossposting
3990 ;; between group namess with incompatible character sets.
3991 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
3992 (group-field-charset
3993 (gnus-group-name-charset method newsgroups-field
))
3994 (followup-field-charset
3995 (gnus-group-name-charset method
(or followup-field
"")))
3996 (rfc2047-header-encoding-alist
3997 (append (when group-field-charset
3998 (list (cons "Newsgroups" group-field-charset
)))
3999 (when followup-field-charset
4000 (list (cons "Followup-To" followup-field-charset
)))
4001 rfc2047-header-encoding-alist
))
4002 (messbuf (current-buffer))
4003 (message-syntax-checks
4005 (listp message-syntax-checks
))
4006 (cons '(existing-newsgroups . disabled
)
4007 message-syntax-checks
)
4008 message-syntax-checks
))
4009 (message-this-is-news t
)
4010 (message-posting-charset
4011 (gnus-setup-posting-charset newsgroups-field
))
4013 (if (not (message-check-news-body-syntax))
4016 (message-narrow-to-headers)
4017 ;; Insert some headers.
4018 (message-generate-headers message-required-news-headers
)
4019 (message-insert-canlock)
4020 ;; Let the user do all of the above.
4021 (run-hooks 'message-header-hook
))
4022 ;; Note: This check will be disabled by the ".*" default value for
4023 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4024 (when (and group-field-charset
4025 (listp message-syntax-checks
))
4026 (setq message-syntax-checks
4027 (cons '(valid-newsgroups . disabled
)
4028 message-syntax-checks
)))
4029 (message-cleanup-headers)
4030 (if (not (let ((message-post-method method
))
4031 (message-check-news-syntax)))
4036 (buffer-disable-undo)
4038 ;; Avoid copying text props (except hard newlines).
4040 (with-current-buffer messbuf
4041 (mml-buffer-substring-no-properties-except-hard-newlines
4042 (point-min) (point-max))))
4043 (message-encode-message-body)
4044 ;; Remove some headers.
4046 (message-narrow-to-headers)
4047 ;; We (re)generate the Lines header.
4048 (when (memq 'Lines message-required-mail-headers
)
4049 (message-generate-headers '(Lines)))
4050 ;; Remove some headers.
4051 (message-remove-header message-ignored-news-headers t
)
4052 (let ((mail-parse-charset message-default-charset
))
4053 (mail-encode-encoded-word-buffer)))
4054 (goto-char (point-max))
4055 ;; require one newline at the end.
4056 (or (= (preceding-char) ?
\n)
4058 (let ((case-fold-search t
))
4059 ;; Remove the delimiter.
4060 (goto-char (point-min))
4062 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4063 (replace-match "\n")
4065 (run-hooks 'message-send-news-hook
)
4066 (gnus-open-server method
)
4067 (message "Sending news via %s..." (gnus-server-string method
))
4068 (setq result
(let ((mail-header-separator ""))
4069 (gnus-request-post method
))))
4070 (kill-buffer tembuf
))
4071 (set-buffer messbuf
)
4073 (push 'news message-sent-message-via
)
4074 (message "Couldn't send message via news: %s"
4075 (nnheader-get-report (car method
)))
4079 ;;; Header generation & syntax checking.
4082 (defun message-check-element (type)
4083 "Return non-nil if this TYPE is not to be checked."
4084 (if (eq message-syntax-checks
'dont-check-for-anything-just-trust-me
)
4086 (let ((able (assq type message-syntax-checks
)))
4088 (eq (cdr able
) 'disabled
)))))
4090 (defun message-check-news-syntax ()
4091 "Check the syntax of the message."
4095 ;; We narrow to the headers and check them first.
4098 (message-narrow-to-headers)
4099 (message-check-news-header-syntax))))))
4101 (defun message-check-news-header-syntax ()
4103 ;; Check Newsgroups header.
4104 (message-check 'newsgroups
4105 (let ((group (message-fetch-field "newsgroups")))
4108 (not (string-match "\\`[ \t]*\\'" group
)))
4111 "The newsgroups field is empty or missing. Posting is denied.")))))
4112 ;; Check the Subject header.
4113 (message-check 'subject
4114 (let* ((case-fold-search t
)
4115 (subject (message-fetch-field "subject")))
4118 (not (string-match "\\`[ \t]*\\'" subject
)))
4121 "The subject field is empty or missing. Posting is denied.")))))
4122 ;; Check for commands in Subject.
4123 (message-check 'subject-cmsg
4124 (if (string-match "^cmsg " (message-fetch-field "subject"))
4126 "The control code \"cmsg\" is in the subject. Really post? ")
4128 ;; Check long header lines.
4129 (message-check 'long-header-lines
4130 (let ((start (point))
4134 (while (and (not found
)
4135 (re-search-forward "^\\([^ \t:]+\\): " nil t
))
4136 (if (> (- (point) (match-beginning 0)) 998)
4138 length
(- (point) (match-beginning 0)))
4139 (setq header
(match-string-no-properties 1)))
4140 (setq start
(match-beginning 0))
4143 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
4146 ;; Check for multiple identical headers.
4147 (message-check 'multiple-headers
4149 (while (and (not found
)
4150 (re-search-forward "^[^ \t:]+: " nil t
))
4152 (or (re-search-forward
4157 (match-beginning 0) (- (match-end 0) 2))))
4162 (y-or-n-p (format "Multiple %s headers. Really post? " found
))
4164 ;; Check for Version and Sendsys.
4165 (message-check 'sendsys
4166 (if (re-search-forward "^Sendsys:\\|^Version:" nil t
)
4168 (format "The article contains a %s command. Really post? "
4169 (buffer-substring (match-beginning 0)
4170 (1- (match-end 0)))))
4172 ;; See whether we can shorten Followup-To.
4173 (message-check 'shorten-followup-to
4174 (let ((newsgroups (message-fetch-field "newsgroups"))
4175 (followup-to (message-fetch-field "followup-to"))
4177 (when (and newsgroups
4178 (string-match "," newsgroups
)
4183 (setq to
(completing-read
4184 "Followups to (default: no Followup-To header) "
4187 (message-tokenize-header
4189 (goto-char (point-min))
4190 (insert "Followup-To: " to
"\n"))
4192 ;; Check "Shoot me".
4193 (message-check 'shoot
4194 (if (re-search-forward
4195 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t
)
4196 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
4198 ;; Check for Approved.
4199 (message-check 'approved
4200 (if (re-search-forward "^Approved:" nil t
)
4201 (y-or-n-p "The article contains an Approved header. Really post? ")
4203 ;; Check the Message-ID header.
4204 (message-check 'message-id
4205 (let* ((case-fold-search t
)
4206 (message-id (message-fetch-field "message-id" t
)))
4207 (or (not message-id
)
4208 ;; Is there an @ in the ID?
4209 (and (string-match "@" message-id
)
4210 ;; Is there a dot in the ID?
4211 (string-match "@[^.]*\\." message-id
)
4212 ;; Does the ID end with a dot?
4213 (not (string-match "\\.>" message-id
)))
4215 (format "The Message-ID looks strange: \"%s\". Really post? "
4217 ;; Check the Newsgroups & Followup-To headers.
4218 (message-check 'existing-newsgroups
4219 (let* ((case-fold-search t
)
4220 (newsgroups (message-fetch-field "newsgroups"))
4221 (followup-to (message-fetch-field "followup-to"))
4222 (groups (message-tokenize-header
4224 (concat newsgroups
"," followup-to
)
4226 (post-method (if (functionp message-post-method
)
4227 (funcall message-post-method
)
4228 message-post-method
))
4229 ;; KLUDGE to handle nnvirtual groups. Doing this right
4230 ;; would probably involve a new nnoo function.
4231 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
4232 (method (if (and (consp post-method
)
4233 (eq (car post-method
) 'nnvirtual
)
4234 gnus-message-group-art
)
4235 (let ((group (car (nnvirtual-find-group-art
4236 (car gnus-message-group-art
)
4237 (cdr gnus-message-group-art
)))))
4238 (gnus-find-method-for-group group
))
4242 (gnus-group-name-decode
4243 (gnus-group-real-name n
)
4244 (gnus-group-name-charset method n
)))
4245 (gnus-groups-from-server method
)))
4248 (when (and (not (equal (car groups
) "poster"))
4249 (not (member (car groups
) known-groups
))
4250 (not (member (car groups
) errors
)))
4251 (push (car groups
) errors
))
4254 ;; Gnus is not running.
4255 ((or (not (and (boundp 'gnus-active-hashtb
)
4256 gnus-active-hashtb
))
4257 (not (boundp 'gnus-read-active-file
)))
4259 ;; We don't have all the group names.
4260 ((and (or (not gnus-read-active-file
)
4261 (eq gnus-read-active-file
'some
))
4265 "Really use %s possibly unknown group%s: %s? "
4266 (if (= (length errors
) 1) "this" "these")
4267 (if (= (length errors
) 1) "" "s")
4268 (mapconcat 'identity errors
", "))))
4269 ;; There were no errors.
4272 ;; There are unknown groups.
4276 "Really post to %s unknown group%s: %s? "
4277 (if (= (length errors
) 1) "this" "these")
4278 (if (= (length errors
) 1) "" "s")
4279 (mapconcat 'identity errors
", ")))))))
4280 ;; Check continuation headers.
4281 (message-check 'continuation-headers
4282 (goto-char (point-min))
4283 (let ((do-posting t
))
4284 (while (re-search-forward "^[^ \t\n][^:\n]*$" nil t
)
4285 (if (y-or-n-p "Fix continuation lines? ")
4287 (goto-char (match-beginning 0))
4289 (unless (y-or-n-p "Send anyway? ")
4290 (setq do-posting nil
))))
4292 ;; Check the Newsgroups & Followup-To headers for syntax errors.
4293 (message-check 'valid-newsgroups
4294 (let ((case-fold-search t
)
4295 (headers '("Newsgroups" "Followup-To"))
4297 (while (and headers
(not error
))
4298 (when (setq header
(mail-fetch-field (car headers
)))
4302 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
4307 (not (string-match "\\.\\'\\|\\.\\." g
)))
4308 (message-tokenize-header header
","))))
4315 (format "The %s header looks odd: \"%s\". Really post? "
4316 (car headers
) header
)))))
4317 (message-check 'repeated-newsgroups
4318 (let ((case-fold-search t
)
4319 (headers '("Newsgroups" "Followup-To"))
4320 header error groups group
)
4323 (when (setq header
(mail-fetch-field (pop headers
)))
4324 (setq groups
(message-tokenize-header header
","))
4325 (while (setq group
(pop groups
))
4326 (when (member group groups
)
4332 (format "Group %s is repeated in headers. Really post? " error
)))))
4333 ;; Check the From header.
4334 (message-check 'from
4335 (let* ((case-fold-search t
)
4336 (from (message-fetch-field "from"))
4340 (message "There is no From line. Posting is denied.")
4342 ((or (not (string-match
4344 (setq ad
(nth 1 (mail-extract-address-components
4345 from
))))) ;larsi@ifi
4346 (string-match "\\.\\." ad
) ;larsi@ifi..uio
4347 (string-match "@\\." ad
) ;larsi@.ifi.uio
4348 (string-match "\\.$" ad
) ;larsi@ifi.uio.
4349 (not (string-match "^[^@]+@[^@]+$" ad
)) ;larsi.ifi.uio
4350 (string-match "(.*).*(.*)" from
)) ;(lars) (lars)
4352 "Denied posting -- the From looks strange: \"%s\"." from
)
4354 ((let ((addresses (rfc822-addresses from
)))
4355 (while (and addresses
4356 (not (eq (string-to-char (car addresses
)) ?\
()))
4357 (setq addresses
(cdr addresses
)))
4360 "Denied posting -- bad From address: \"%s\"." from
)
4363 ;; Check the Reply-To header.
4364 (message-check 'reply-to
4365 (let* ((case-fold-search t
)
4366 (reply-to (message-fetch-field "reply-to"))
4371 ((string-match "," reply-to
)
4373 (format "Multiple Reply-To addresses: \"%s\". Really post? "
4375 ((or (not (string-match
4377 (setq ad
(nth 1 (mail-extract-address-components
4378 reply-to
))))) ;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 "(.*).*(.*)" reply-to
)) ;(lars) (lars)
4386 "The Reply-To looks strange: \"%s\". Really post? "
4390 (defun message-check-news-body-syntax ()
4392 ;; Check for long lines.
4393 (message-check 'long-lines
4394 (goto-char (point-min))
4396 (concat "^" (regexp-quote mail-header-separator
) "$"))
4400 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
4403 (< (- (point) p
) 80)))
4404 (zerop (forward-line 1))))
4408 "You have lines longer than 79 characters. Really post? ")))
4409 ;; Check whether the article is empty.
4410 (message-check 'empty
4411 (goto-char (point-min))
4413 (concat "^" (regexp-quote mail-header-separator
) "$"))
4416 (goto-char (point-max))
4417 (re-search-backward message-signature-separator nil t
)
4419 (or (re-search-backward "[^ \n\t]" b t
)
4420 (if (message-gnksa-enable-p 'empty-article
)
4421 (y-or-n-p "Empty article. Really post? ")
4422 (message "Denied posting -- Empty article.")
4424 ;; Check for control characters.
4425 (message-check 'control-chars
4426 (if (re-search-forward
4427 (mm-string-as-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
4430 "The article contains control characters. Really post? ")
4432 ;; Check excessive size.
4433 (message-check 'size
4434 (if (> (buffer-size) 60000)
4436 (format "The article is %d octets long. Really post? "
4439 ;; Check whether any new text has been added.
4440 (message-check 'new-text
4442 (not message-checksum
)
4443 (not (eq (message-checksum) message-checksum
))
4444 (if (message-gnksa-enable-p 'quoted-text-only
)
4446 "It looks like no new text has been added. Really post? ")
4447 (message "Denied posting -- no new text has been added.")
4449 ;; Check the length of the signature.
4450 (message-check 'signature
4451 (goto-char (point-max))
4452 (if (> (count-lines (point) (point-max)) 5)
4455 "Your .sig is %d lines; it should be max 4. Really post? "
4456 (1- (count-lines (point) (point-max)))))
4458 ;; Ensure that text follows last quoted portion.
4459 (message-check 'quoting-style
4460 (goto-char (point-max))
4461 (let ((no-problem t
))
4462 (when (search-backward-regexp "^>[^\n]*\n" nil t
)
4463 (setq no-problem
(search-forward-regexp "^[ \t]*[^>\n]" nil t
)))
4466 (if (message-gnksa-enable-p 'quoted-text-only
)
4467 (y-or-n-p "Your text should follow quoted text. Really post? ")
4469 (goto-char (point-min))
4471 (concat "^" (regexp-quote mail-header-separator
) "$"))
4472 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t
)
4473 (y-or-n-p "Your text should follow quoted text. Really post? ")
4474 (message "Denied posting -- only quoted text.")
4477 (defun message-checksum ()
4478 "Return a \"checksum\" for the current buffer."
4481 (goto-char (point-min))
4483 (concat "^" (regexp-quote mail-header-separator
) "$"))
4485 (when (not (looking-at "[ \t\n]"))
4486 (setq sum
(logxor (ash sum
1) (if (natnump sum
) 0 1)
4491 (defun message-do-fcc ()
4492 "Process Fcc headers in the current buffer."
4493 (let ((case-fold-search t
)
4494 (buf (current-buffer))
4496 (mml-externalize-attachments message-fcc-externalize-attachments
))
4499 (message-narrow-to-headers)
4500 (setq file
(message-fetch-field "fcc" t
)))
4502 (set-buffer (get-buffer-create " *message temp*"))
4504 (insert-buffer-substring buf
)
4505 (message-encode-message-body)
4507 (message-narrow-to-headers)
4508 (while (setq file
(message-fetch-field "fcc" t
))
4510 (message-remove-header "fcc" nil t
))
4511 (let ((mail-parse-charset message-default-charset
)
4512 (rfc2047-header-encoding-alist
4513 (cons '("Newsgroups" . default
)
4514 rfc2047-header-encoding-alist
)))
4515 (mail-encode-encoded-word-buffer)))
4516 (goto-char (point-min))
4517 (when (re-search-forward
4518 (concat "^" (regexp-quote mail-header-separator
) "$")
4520 (replace-match "" t t
))
4521 ;; Process FCC operations.
4523 (setq file
(pop list
))
4524 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file
)
4525 ;; Pipe the article to the program in question.
4526 (call-process-region (point-min) (point-max) shell-file-name
4527 nil nil nil shell-command-switch
4528 (match-string 1 file
))
4529 ;; Save the article.
4530 (setq file
(expand-file-name file
))
4531 (unless (file-exists-p (file-name-directory file
))
4532 (make-directory (file-name-directory file
) t
))
4533 (if (and message-fcc-handler-function
4534 (not (eq message-fcc-handler-function
'rmail-output
)))
4535 (funcall message-fcc-handler-function file
)
4536 (if (and (file-readable-p file
) (mail-file-babyl-p file
))
4537 (rmail-output file
1 nil t
)
4538 (let ((mail-use-rfc822 t
))
4539 (rmail-output file
1 t t
))))))
4540 (kill-buffer (current-buffer))))))
4542 (defun message-output (filename)
4543 "Append this article to Unix/babyl mail file FILENAME."
4544 (if (and (file-readable-p filename
)
4545 (mail-file-babyl-p filename
))
4546 (gnus-output-to-rmail filename t
)
4547 (gnus-output-to-mail filename t
)))
4549 (defun message-cleanup-headers ()
4550 "Do various automatic cleanups of the headers."
4551 ;; Remove empty lines in the header.
4553 (message-narrow-to-headers)
4554 ;; Remove blank lines.
4555 (while (re-search-forward "^[ \t]*\n" nil t
)
4556 (replace-match "" t t
))
4558 ;; Correct Newsgroups and Followup-To headers: Change sequence of
4559 ;; spaces to comma and eliminate spaces around commas. Eliminate
4560 ;; embedded line breaks.
4561 (goto-char (point-min))
4562 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t
)
4566 (if (re-search-forward "^[^ \t]" nil t
)
4570 (goto-char (point-min))
4571 (while (re-search-forward "\n[ \t]+" nil t
)
4572 (replace-match " " t t
)) ;No line breaks (too confusing)
4573 (goto-char (point-min))
4574 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t
)
4575 (replace-match "," t t
))
4576 (goto-char (point-min))
4577 ;; Remove trailing commas.
4578 (when (re-search-forward ",+$" nil t
)
4579 (replace-match "" t t
))))))
4581 (defun message-make-date (&optional now
)
4582 "Make a valid data header.
4583 If NOW, use that time instead."
4584 (let* ((now (or now
(current-time)))
4585 (zone (nth 8 (decode-time now
)))
4589 (setq zone
(- zone
)))
4591 ;; The day name of the %a spec is locale-specific. Pfff.
4592 (format "%s, " (capitalize (car (rassoc (nth 6 (decode-time now
))
4593 parse-time-weekdays
))))
4594 (format-time-string "%d" now
)
4595 ;; The month name of the %b spec is locale-specific. Pfff.
4597 (capitalize (car (rassoc (nth 4 (decode-time now
))
4598 parse-time-months
))))
4599 (format-time-string "%Y %H:%M:%S " now
)
4600 ;; We do all of this because XEmacs doesn't have the %z spec.
4601 (format "%s%02d%02d" sign
(/ zone
3600) (/ (% zone
3600) 60)))))
4603 (defun message-make-message-id ()
4604 "Make a unique Message-ID."
4605 (concat "<" (message-unique-id)
4606 (let ((psubject (save-excursion (message-fetch-field "subject")))
4608 (save-excursion (message-fetch-field "supersedes"))))
4610 (and message-reply-headers
4611 (mail-header-references message-reply-headers
)
4612 (mail-header-subject message-reply-headers
)
4615 (message-strip-subject-re
4616 (mail-header-subject message-reply-headers
))
4617 (message-strip-subject-re psubject
))))
4619 (string-match "_-_@" psupersedes
)))
4621 "@" (message-make-fqdn) ">"))
4623 (defvar message-unique-id-char nil
)
4625 ;; If you ever change this function, make sure the new version
4626 ;; cannot generate IDs that the old version could.
4627 ;; You might for example insert a "." somewhere (not next to another dot
4628 ;; or string boundary), or modify the "fsf" string.
4629 (defun message-unique-id ()
4630 ;; Don't use microseconds from (current-time), they may be unsupported.
4631 ;; Instead we use this randomly inited counter.
4632 (setq message-unique-id-char
4633 (%
(1+ (or message-unique-id-char
(logand (random t
) (1- (lsh 1 20)))))
4634 ;; (current-time) returns 16-bit ints,
4635 ;; and 2^16*25 just fits into 4 digits i base 36.
4637 (let ((tm (current-time)))
4639 (if (memq system-type
'(ms-dos emx vax-vms
))
4640 (let ((user (downcase (user-login-name))))
4641 (while (string-match "[^a-z0-9_]" user
)
4642 (aset user
(match-beginning 0) ?_
))
4644 (message-number-base36 (user-uid) -
1))
4645 (message-number-base36 (+ (car tm
)
4646 (lsh (% message-unique-id-char
25) 16)) 4)
4647 (message-number-base36 (+ (nth 1 tm
)
4648 (lsh (/ message-unique-id-char
25) 16)) 4)
4649 ;; Append a given name, because while the generated ID is unique
4650 ;; to this newsreader, other newsreaders might otherwise generate
4651 ;; the same ID via another algorithm.
4654 (defun message-number-base36 (num len
)
4659 (concat (message-number-base36 (/ num
36) (1- len
))
4660 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
4663 (defun message-make-organization ()
4664 "Make an Organization header."
4665 (let* ((organization
4666 (when message-user-organization
4667 (if (functionp message-user-organization
)
4668 (funcall message-user-organization
)
4669 message-user-organization
))))
4671 (mm-enable-multibyte)
4672 (cond ((stringp organization
)
4673 (insert organization
))
4674 ((and (eq t organization
)
4675 message-user-organization-file
4676 (file-exists-p message-user-organization-file
))
4677 (insert-file-contents message-user-organization-file
)))
4678 (goto-char (point-min))
4679 (while (re-search-forward "[\t\n]+" nil t
)
4680 (replace-match "" t t
))
4681 (unless (zerop (buffer-size))
4684 (defun message-make-lines ()
4685 "Count the number of lines and return numeric string."
4690 (int-to-string (count-lines (point) (point-max))))))
4692 (defun message-make-references ()
4693 "Return the References header for this message."
4694 (when message-reply-headers
4695 (let ((message-id (mail-header-message-id message-reply-headers
))
4696 (references (mail-header-references message-reply-headers
))
4698 (if (or references message-id
)
4699 (concat (or references
"") (and references
" ")
4703 (defun message-make-in-reply-to ()
4704 "Return the In-Reply-To header for this message."
4705 (when message-reply-headers
4706 (let ((from (mail-header-from message-reply-headers
))
4707 (date (mail-header-date message-reply-headers
))
4708 (msg-id (mail-header-message-id message-reply-headers
)))
4710 (let ((name (mail-extract-address-components from
)))
4711 (concat msg-id
(if msg-id
" (")
4715 (if (or (not date
) (string= date
""))
4716 "(unknown date)" date
)
4717 "\"" (if msg-id
")")))))))
4719 (defun message-make-distribution ()
4720 "Make a Distribution header."
4721 (let ((orig-distribution (message-fetch-reply-field "distribution")))
4722 (cond ((functionp message-distribution-function
)
4723 (funcall message-distribution-function
))
4724 (t orig-distribution
))))
4726 (defun message-make-expires ()
4727 "Return an Expires header based on `message-expires'."
4728 (let ((current (current-time))
4729 (future (* 1.0 message-expires
60 60 24)))
4730 ;; Add the future to current.
4731 (setcar current
(+ (car current
) (round (/ future
(expt 2 16)))))
4732 (setcar (cdr current
) (+ (nth 1 current
) (%
(round future
) (expt 2 16))))
4733 (message-make-date current
)))
4735 (defun message-make-path ()
4737 (let ((login-name (user-login-name)))
4738 (cond ((null message-user-path
)
4739 (concat (system-name) "!" login-name
))
4740 ((stringp message-user-path
)
4741 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
4742 (concat message-user-path
"!" login-name
))
4745 (defun message-make-from ()
4746 "Make a From header."
4747 (let* ((style message-from-style
)
4748 (login (message-make-address))
4750 (or (and (boundp 'user-full-name
)
4753 (when (string= fullname
"&")
4754 (setq fullname
(user-login-name)))
4756 (mm-enable-multibyte)
4759 (equal fullname
""))
4761 ((or (eq style
'angles
)
4762 (and (not (eq style
'parens
))
4763 ;; Use angles if no quoting is needed, or if parens would
4764 ;; need quoting too.
4765 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname
))
4766 (let ((tmp (concat fullname nil
)))
4767 (while (string-match "([^()]*)" tmp
)
4768 (aset tmp
(match-beginning 0) ?-
)
4769 (aset tmp
(1- (match-end 0)) ?-
))
4770 (string-match "[\\()]" tmp
)))))
4772 (goto-char (point-min))
4773 ;; Look for a character that cannot appear unquoted
4774 ;; according to RFC 822.
4775 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil
1)
4776 ;; Quote fullname, escaping specials.
4777 (goto-char (point-min))
4779 (while (re-search-forward "[\"\\]" nil
1)
4780 (replace-match "\\\\\\&" t
))
4782 (insert " <" login
">"))
4783 (t ; 'parens or default
4785 (let ((fullname-start (point)))
4787 (goto-char fullname-start
)
4788 ;; RFC 822 says \ and nonmatching parentheses
4789 ;; must be escaped in comments.
4790 ;; Escape every instance of ()\ ...
4791 (while (re-search-forward "[()\\]" nil
1)
4792 (replace-match "\\\\\\&" t
))
4793 ;; ... then undo escaping of matching parentheses,
4794 ;; including matching nested parentheses.
4795 (goto-char fullname-start
)
4796 (while (re-search-forward
4797 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
4799 (replace-match "\\1(\\3)" t
)
4800 (goto-char fullname-start
)))
4804 (defun message-make-sender ()
4805 "Return the \"real\" user address.
4806 This function tries to ignore all user modifications, and
4807 give as trustworthy answer as possible."
4808 (concat (user-login-name) "@" (system-name)))
4810 (defun message-make-address ()
4811 "Make the address of the user."
4812 (or (message-user-mail-address)
4813 (concat (user-login-name) "@" (message-make-domain))))
4815 (defun message-user-mail-address ()
4816 "Return the pertinent part of `user-mail-address'."
4817 (when (and user-mail-address
4818 (string-match "@.*\\." user-mail-address
))
4819 (if (string-match " " user-mail-address
)
4820 (nth 1 (mail-extract-address-components user-mail-address
))
4821 user-mail-address
)))
4823 (defun message-sendmail-envelope-from ()
4824 "Return the envelope from."
4825 (cond ((eq message-sendmail-envelope-from
'header
)
4826 (nth 1 (mail-extract-address-components
4827 (message-fetch-field "from"))))
4828 ((stringp message-sendmail-envelope-from
)
4829 message-sendmail-envelope-from
)
4831 (message-make-address))))
4833 (defun message-make-fqdn ()
4834 "Return user's fully qualified domain name."
4835 (let* ((system-name (system-name))
4836 (user-mail (message-user-mail-address))
4839 (string-match "@\\(.*\\)\\'" user-mail
))
4840 (match-string 1 user-mail
)))
4841 (case-fold-search t
))
4843 ((and message-user-fqdn
4844 (stringp message-user-fqdn
)
4845 (string-match message-valid-fqdn-regexp message-user-fqdn
)
4846 (not (string-match message-bogus-system-names message-user-fqdn
)))
4848 ;; `message-user-fqdn' seems to be valid
4849 ((and (string-match message-valid-fqdn-regexp system-name
)
4850 (not (string-match message-bogus-system-names system-name
)))
4851 ;; `system-name' returned the right result.
4853 ;; Try `mail-host-address'.
4854 ((and (boundp 'mail-host-address
)
4855 (stringp mail-host-address
)
4856 (string-match message-valid-fqdn-regexp mail-host-address
)
4857 (not (string-match message-bogus-system-names mail-host-address
)))
4859 ;; We try `user-mail-address' as a backup.
4861 (stringp user-domain
)
4862 (string-match message-valid-fqdn-regexp user-domain
)
4863 (not (string-match message-bogus-system-names user-domain
)))
4865 ;; Default to this bogus thing.
4868 ".i-did-not-set--mail-host-address--so-tickle-me")))))
4870 (defun message-make-host-name ()
4871 "Return the name of the host."
4872 (let ((fqdn (message-make-fqdn)))
4873 (string-match "^[^.]+\\." fqdn
)
4874 (substring fqdn
0 (1- (match-end 0)))))
4876 (defun message-make-domain ()
4877 "Return the domain name."
4878 (or mail-host-address
4879 (message-make-fqdn)))
4881 (defun message-to-list-only ()
4882 "Send a message to the list only.
4883 Remove all addresses but the list address from To and Cc headers."
4885 (let ((listaddr (message-make-mail-followup-to t
)))
4888 (message-remove-header "to")
4889 (message-remove-header "cc")
4890 (message-position-on-field "To" "X-Draft-From")
4891 (insert listaddr
)))))
4893 (defun message-make-mail-followup-to (&optional only-show-subscribed
)
4894 "Return the Mail-Followup-To header.
4895 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
4896 subscribed address (and not the additional To and Cc header contents)."
4897 (let* ((case-fold-search t
)
4898 (to (message-fetch-field "To"))
4899 (cc (message-fetch-field "cc"))
4900 (msg-recipients (concat to
(and to cc
", ") cc
))
4902 (mapcar 'mail-strip-quoted-names
4903 (message-tokenize-header msg-recipients
)))
4905 (if message-subscribed-address-file
4906 (let (begin end item re
)
4909 (insert-file-contents message-subscribed-address-file
)
4911 (setq begin
(point))
4914 (if (bolp) (setq end
(1- end
)))
4915 (setq item
(regexp-quote (buffer-substring begin end
)))
4916 (if re
(setq re
(concat re
"\\|" item
))
4917 (setq re
(concat "\\`\\(" item
))))
4918 (and re
(list (concat re
"\\)\\'"))))))))
4919 (mft-regexps (apply 'append message-subscribed-regexps
4920 (mapcar 'regexp-quote
4921 message-subscribed-addresses
)
4924 message-subscribed-address-functions
))))
4926 (let ((subscribed-lists nil
)
4928 (loop for recipient in recipients
4929 when
(loop for regexp in mft-regexps
4930 when
(string-match regexp recipient
) return t
)
4933 (if only-show-subscribed
4935 msg-recipients
))))))
4937 (defun message-idna-to-ascii-rhs-1 (header)
4938 "Interactively potentially IDNA encode domain names in HEADER."
4939 (let ((field (message-fetch-field header
))
4942 (dolist (address (mail-header-parse-addresses field
))
4943 (setq address
(car address
)
4944 rhs
(downcase (or (cadr (split-string address
"@")) ""))
4945 ace
(downcase (idna-to-ascii rhs
)))
4946 (when (and (not (equal rhs ace
))
4947 (or (not (eq message-use-idna
'ask
))
4948 (y-or-n-p (format "Replace %s with %s? " rhs ace
))))
4949 (goto-char (point-min))
4950 (while (re-search-forward (concat "^" header
":") nil t
)
4951 (message-narrow-to-field)
4952 (while (search-forward (concat "@" rhs
) nil t
)
4953 (replace-match (concat "@" ace
) t t
))
4954 (goto-char (point-max))
4957 (defun message-idna-to-ascii-rhs ()
4958 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
4959 See `message-idna-encode'."
4961 (when message-use-idna
4964 (message-narrow-to-head)
4965 (message-idna-to-ascii-rhs-1 "From")
4966 (message-idna-to-ascii-rhs-1 "To")
4967 (message-idna-to-ascii-rhs-1 "Cc")))))
4969 (defun message-generate-headers (headers)
4970 "Prepare article HEADERS.
4971 Headers already prepared in the buffer are not modified."
4972 (setq headers
(append headers message-required-headers
))
4974 (message-narrow-to-headers)
4975 (let* ((Date (message-make-date))
4976 (Message-ID (message-make-message-id))
4977 (Organization (message-make-organization))
4978 (From (message-make-from))
4979 (Path (message-make-path))
4982 (In-Reply-To (message-make-in-reply-to))
4983 (References (message-make-references))
4985 (Distribution (message-make-distribution))
4986 (Lines (message-make-lines))
4987 (User-Agent message-newsreader
)
4988 (Expires (message-make-expires))
4989 (case-fold-search t
)
4991 header value elem header-string
)
4992 ;; First we remove any old generated headers.
4993 (let ((headers message-deletable-headers
))
4994 (unless (buffer-modified-p)
4995 (setq headers
(delq 'Message-ID
(copy-sequence headers
))))
4997 (goto-char (point-min))
4998 (and (re-search-forward
4999 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
5000 (get-text-property (1+ (match-beginning 0)) 'message-deletable
)
5001 (message-delete-line))
5003 ;; Go through all the required headers and see if they are in the
5004 ;; articles already. If they are not, or are empty, they are
5005 ;; inserted automatically - except for Subject, Newsgroups and
5008 (goto-char (point-min))
5009 (setq elem
(pop headers
))
5011 (if (eq (car elem
) 'optional
)
5012 (setq header
(cdr elem
)
5014 (setq header
(car elem
)))
5016 (setq header-string
(if (stringp header
)
5018 (symbol-name header
)))
5019 (when (or (not (re-search-forward
5021 (regexp-quote (downcase header-string
))
5025 ;; The header was found. We insert a space after the
5026 ;; colon, if there is none.
5027 (if (/= (char-after) ?
) (insert " ") (forward-char 1))
5028 ;; Find out whether the header is empty.
5029 (looking-at "[ \t]*\n[^ \t]")))
5030 ;; So we find out what value we should insert.
5034 (eq (car elem
) 'optional
)
5035 (not (member header-string message-inserted-headers
)))
5036 ;; This is an optional header. If the cdr of this
5037 ;; is something that is nil, then we do not insert
5039 (setq header
(cdr elem
))
5040 (or (and (functionp (cdr elem
))
5041 (funcall (cdr elem
)))
5042 (and (boundp (cdr elem
))
5043 (symbol-value (cdr elem
)))))
5045 ;; The element is a cons. Either the cdr is a
5046 ;; string to be inserted verbatim, or it is a
5047 ;; function, and we insert the value returned from
5049 (or (and (stringp (cdr elem
))
5051 (and (functionp (cdr elem
))
5052 (funcall (cdr elem
)))))
5053 ((and (boundp header
)
5054 (symbol-value header
))
5055 ;; The element is a symbol. We insert the value
5056 ;; of this symbol, if any.
5057 (symbol-value header
))
5058 ((not (message-check-element header
))
5059 ;; We couldn't generate a value for this header,
5060 ;; so we just ask the user.
5061 (read-from-minibuffer
5062 (format "Empty header for %s; enter value: " header
)))))
5063 ;; Finally insert the header.
5065 (not (equal value
"")))
5069 ;; This header didn't exist, so we insert it.
5070 (goto-char (point-max))
5072 (cdr (assq header message-header-format-alist
))))
5074 (funcall formatter header value
)
5075 (insert header-string
": " value
))
5076 ;; We check whether the value was ended by a
5077 ;; newline. If now, we insert one.
5081 ;; The value of this header was empty, so we clear
5082 ;; totally and insert the new value.
5083 (delete-region (point) (gnus-point-at-eol))
5084 ;; If the header is optional, and the header was
5085 ;; empty, we con't insert it anyway.
5087 (push header-string message-inserted-headers
)
5089 ;; Add the deletable property to the headers that require it.
5090 (and (memq header message-deletable-headers
)
5091 (progn (beginning-of-line) (looking-at "[^:]+: "))
5092 (add-text-properties
5093 (point) (match-end 0)
5094 '(message-deletable t face italic
) (current-buffer)))))))
5095 ;; Insert new Sender if the From is strange.
5096 (let ((from (message-fetch-field "from"))
5097 (sender (message-fetch-field "sender"))
5098 (secure-sender (message-make-sender)))
5100 (not (message-check-element 'sender
))
5103 (cadr (mail-extract-address-components from
)))
5104 (downcase secure-sender
)))
5109 (cadr (mail-extract-address-components sender
)))
5110 (downcase secure-sender
)))))
5111 (goto-char (point-min))
5112 ;; Rename any old Sender headers to Original-Sender.
5113 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t
)
5115 (insert "Original-")
5116 (beginning-of-line))
5117 (when (or (message-news-p)
5118 (string-match "@.+\\.." secure-sender
))
5119 (insert "Sender: " secure-sender
"\n"))))
5121 (message-idna-to-ascii-rhs))))
5123 (defun message-insert-courtesy-copy ()
5124 "Insert a courtesy message in mail copies of combined messages."
5128 (message-narrow-to-headers)
5129 (when (setq newsgroups
(message-fetch-field "newsgroups"))
5130 (goto-char (point-max))
5131 (insert "Posted-To: " newsgroups
"\n")))
5133 (when message-courtesy-message
5135 ((string-match "%s" message-courtesy-message
)
5136 (insert (format message-courtesy-message newsgroups
)))
5138 (insert message-courtesy-message
)))))))
5141 ;;; Setting up a message buffer
5144 (defun message-fill-address (header value
)
5146 (narrow-to-region (point) (point))
5147 (insert (capitalize (symbol-name header
))
5149 (if (consp value
) (car value
) value
)
5151 (narrow-to-region (point-min) (1- (point-max)))
5153 (goto-char (point-min))
5155 (skip-chars-forward "^,\"" (point-max))
5156 (if (or (eq (char-after) ?
,)
5159 (if (and (> (current-column) 78)
5165 (setq last
(1+ (point))))
5166 (setq last
(1+ (point)))))
5167 (setq quoted
(not quoted
)))
5170 (goto-char (point-max))
5174 (defun message-split-line ()
5175 "Split current line, moving portion beyond point vertically down.
5176 If the current line has `message-yank-prefix', insert it on the new line."
5179 (split-line message-yank-prefix
) ;; Emacs 22.1+ supports arg.
5183 (defun message-fill-header (header value
)
5184 (let ((begin (point))
5187 (insert (capitalize (symbol-name header
))
5189 (if (consp value
) (car value
) value
)
5192 (narrow-to-region begin
(point))
5193 (fill-region-as-paragraph begin
(point))
5194 ;; Tapdance around looong Message-IDs.
5196 (when (looking-at "[ \t]*$")
5197 (message-delete-line))
5199 (re-search-forward ":" nil t
)
5200 (when (looking-at "\n[ \t]+")
5201 (replace-match " " t t
))
5202 (goto-char (point-max)))))
5204 (defun message-shorten-1 (list cut surplus
)
5205 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
5206 (setcdr (nthcdr (- cut
2) list
)
5207 (nthcdr (+ (- cut
2) surplus
1) list
)))
5209 (defun message-shorten-references (header references
)
5210 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
5211 If folding is disallowed, also check that the REFERENCES are less
5212 than 988 characters long, and if they are not, trim them until they are."
5219 (goto-char (point-min))
5220 ;; Cons a list of valid references.
5221 (while (re-search-forward "<[^>]+>" nil t
)
5222 (push (match-string 0) refs
))
5223 (setq refs
(nreverse refs
)
5224 count
(length refs
)))
5226 ;; If the list has more than MAXCOUNT elements, trim it by
5227 ;; removing the CUTth element and the required number of
5228 ;; elements that follow.
5229 (when (> count maxcount
)
5230 (let ((surplus (- count maxcount
)))
5231 (message-shorten-1 refs cut surplus
)
5232 (decf count surplus
)))
5234 ;; If folding is disallowed, make sure the total length (including
5235 ;; the spaces between) will be less than MAXSIZE characters.
5237 ;; Only disallow folding for News messages. At this point the headers
5238 ;; have not been generated, thus we use message-this-is-news directly.
5239 (when (and message-this-is-news message-cater-to-broken-inn
)
5241 (totalsize (+ (apply #'+ (mapcar #'length refs
))
5244 (ptr (nthcdr (1- cut
) refs
)))
5245 ;; Decide how many elements to cut off...
5246 (while (> totalsize maxsize
)
5247 (decf totalsize
(1+ (length (car ptr
))))
5249 (setq ptr
(cdr ptr
)))
5252 (message-shorten-1 refs cut surplus
))))
5254 ;; Finally, collect the references back into a string and insert
5255 ;; it into the buffer.
5256 (let ((refstring (mapconcat #'identity refs
" ")))
5257 (if (and message-this-is-news message-cater-to-broken-inn
)
5258 (insert (capitalize (symbol-name header
)) ": "
5260 (message-fill-header header refstring
)))))
5262 (defun message-position-point ()
5263 "Move point to where the user probably wants to find it."
5264 (message-narrow-to-headers)
5266 ((re-search-forward "^[^:]+:[ \t]*$" nil t
)
5267 (search-backward ":" )
5270 (if (eq (char-after) ?
)
5274 (goto-char (point-max))
5277 (unless (looking-at "$")
5281 (defcustom message-beginning-of-line t
5282 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
5283 goes to beginning of header values."
5285 :group
'message-buffers
5286 :link
'(custom-manual "(message)Movement")
5289 (defun message-beginning-of-line (&optional n
)
5290 "Move point to beginning of header value or to beginning of line.
5291 The prefix argument N is passed directly to `beginning-of-line'.
5293 This command is identical to `beginning-of-line' if point is
5294 outside the message header or if the option `message-beginning-of-line'
5297 If point is in the message header and on a (non-continued) header
5298 line, move point to the beginning of the header value or the beginning of line,
5299 whichever is closer. If point is already at beginning of line, move point to
5300 beginning of header value. Therefore, repeated calls will toggle point
5301 between beginning of field and beginning of line."
5303 (let ((zrs 'zmacs-region-stays
))
5304 (when (and (interactive-p) (boundp zrs
))
5306 (if (and message-beginning-of-line
5307 (message-point-in-header-p))
5308 (let* ((here (point))
5309 (bol (progn (beginning-of-line n
) (point)))
5310 (eol (gnus-point-at-eol))
5311 (eoh (re-search-forward ": *" eol t
)))
5313 (if (and eoh
(or (< eoh here
) (= bol here
)))
5315 (beginning-of-line n
)))
5317 (defun message-buffer-name (type &optional to group
)
5318 "Return a new (unique) buffer name based on TYPE and TO."
5320 ;; Generate a new buffer name The Message Way.
5321 ((eq message-generate-new-buffers
'unique
)
5322 (generate-new-buffer-name
5326 (or (car (mail-extract-address-components to
))
5329 (if (and group
(not (string= group
""))) (concat " on " group
) "")
5331 ;; Check whether `message-generate-new-buffers' is a function,
5332 ;; and if so, call it.
5333 ((functionp message-generate-new-buffers
)
5334 (funcall message-generate-new-buffers type to group
))
5335 ((eq message-generate-new-buffers
'unsent
)
5336 (generate-new-buffer-name
5337 (concat "*unsent " type
5340 (or (car (mail-extract-address-components to
))
5343 (if (and group
(not (string= group
""))) (concat " on " group
) "")
5345 ;; Use standard name.
5347 (format "*%s message*" type
))))
5349 (defun message-pop-to-buffer (name)
5350 "Pop to buffer NAME, and warn if it already exists and is modified."
5351 (let ((buffer (get-buffer name
)))
5353 (buffer-name buffer
))
5355 (set-buffer (pop-to-buffer buffer
))
5356 (when (and (buffer-modified-p)
5358 "Message already being composed; erase? ")))
5359 (error "Message being composed")))
5360 (set-buffer (pop-to-buffer name
)))
5364 (defun message-do-send-housekeeping ()
5365 "Kill old message buffers."
5366 ;; We might have sent this buffer already. Delete it from the
5368 (setq message-buffer-list
(delq (current-buffer) message-buffer-list
))
5369 (while (and message-max-buffers
5371 (>= (length message-buffer-list
) message-max-buffers
))
5372 ;; Kill the oldest buffer -- unless it has been changed.
5373 (let ((buffer (pop message-buffer-list
)))
5374 (when (and (buffer-name buffer
)
5375 (not (buffer-modified-p buffer
)))
5376 (kill-buffer buffer
))))
5377 ;; Rename the buffer.
5378 (if message-send-rename-function
5379 (funcall message-send-rename-function
)
5380 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
5382 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
5384 (let ((name (match-string 2 (buffer-name)))
5386 (if (not (or (null name
)
5387 (string-equal name
"mail")
5388 (string-equal name
"posting")))
5389 (setq name
(concat "*sent " name
"*"))
5390 (message-narrow-to-headers)
5391 (setq to
(message-fetch-field "to"))
5392 (setq group
(message-fetch-field "newsgroups"))
5396 (to (concat "*sent mail to "
5397 (or (car (mail-extract-address-components to
))
5399 ((and group
(not (string= group
"")))
5400 (concat "*sent posting on " group
"*"))
5401 (t "*sent mail*"))))
5402 (unless (string-equal name
(buffer-name))
5403 (rename-buffer name t
)))))
5404 ;; Push the current buffer onto the list.
5405 (when message-max-buffers
5406 (setq message-buffer-list
5407 (nconc message-buffer-list
(list (current-buffer))))))
5409 (defun message-mail-user-agent ()
5411 ((not message-mail-user-agent
) nil
)
5412 ((eq message-mail-user-agent t
) mail-user-agent
)
5413 (t message-mail-user-agent
))))
5414 (if (memq mua
'(message-user-agent gnus-user-agent
))
5418 (defun message-setup (headers &optional replybuffer actions switch-function
)
5419 (let ((mua (message-mail-user-agent))
5420 subject to field yank-action
)
5421 (if (not (and message-this-is-mail mua
))
5422 (message-setup-1 headers replybuffer actions
)
5424 (setq yank-action
(list 'insert-buffer replybuffer
)))
5425 (setq headers
(copy-sequence headers
))
5426 (setq field
(assq 'Subject headers
))
5428 (setq subject
(cdr field
))
5429 (setq headers
(delq field headers
)))
5430 (setq field
(assq 'To headers
))
5432 (setq to
(cdr field
))
5433 (setq headers
(delq field headers
)))
5434 (let ((mail-user-agent mua
))
5435 (compose-mail to subject
5436 (mapcar (lambda (item)
5438 (format "%s" (car item
))
5441 nil switch-function yank-action actions
)))))
5443 (defun message-headers-to-generate (headers included-headers excluded-headers
)
5444 "Return a list that includes all headers from HEADERS.
5445 If INCLUDED-HEADERS is a list, just include those headers. If if is
5446 t, include all headers. In any case, headers from EXCLUDED-HEADERS
5450 (dolist (header headers
)
5451 (setq header-name
(cond
5452 ((and (consp header
)
5453 (eq (car header
) 'optional
))
5454 ;; On the form (optional . Header)
5457 ;; On the form (Header . function)
5462 (when (and (not (memq header-name excluded-headers
))
5463 (or (eq included-headers t
)
5464 (memq header-name included-headers
)))
5465 (push header result
)))
5468 (defun message-setup-1 (headers &optional replybuffer actions
)
5469 (dolist (action actions
)
5471 (add-to-list 'message-send-actions
5472 `(apply ',(car action
) ',(cdr action
)))))
5473 (setq message-reply-buffer replybuffer
)
5474 (goto-char (point-min))
5475 ;; Insert all the headers.
5478 (alist message-header-format-alist
))
5480 (unless (assq (caar h
) message-header-format-alist
)
5481 (push (list (caar h
)) alist
))
5485 (delete-region (point) (progn (forward-line -
1) (point)))
5486 (when message-default-headers
5487 (insert message-default-headers
)
5488 (or (bolp) (insert ?
\n)))
5492 (insert mail-header-separator
"\n")
5496 (when (message-news-p)
5497 (when message-default-news-headers
5498 (insert message-default-news-headers
)
5499 (or (bolp) (insert ?
\n)))
5500 (when message-generate-headers-first
5501 (message-generate-headers
5502 (message-headers-to-generate
5503 (append message-required-news-headers
5504 message-required-headers
)
5505 message-generate-headers-first
5506 '(Lines Subject
)))))
5507 (when (message-mail-p)
5508 (when message-default-mail-headers
5509 (insert message-default-mail-headers
)
5510 (or (bolp) (insert ?
\n)))
5512 (message-narrow-to-headers)
5513 (if message-alternative-emails
5514 (message-use-alternative-email-as-from)))
5515 (when message-generate-headers-first
5516 (message-generate-headers
5517 (message-headers-to-generate
5518 (append message-required-mail-headers
5519 message-required-headers
)
5520 message-generate-headers-first
5521 '(Lines Subject
)))))
5522 (run-hooks 'message-signature-setup-hook
)
5523 (message-insert-signature)
5525 (message-narrow-to-headers)
5526 (run-hooks 'message-header-setup-hook
))
5527 (set-buffer-modified-p nil
)
5528 (setq buffer-undo-list nil
)
5529 (run-hooks 'message-setup-hook
)
5530 (message-position-point)
5533 (defun message-set-auto-save-file-name ()
5534 "Associate the message buffer with a file in the drafts directory."
5535 (when message-auto-save-directory
5536 (unless (file-directory-p
5537 (directory-file-name message-auto-save-directory
))
5538 (make-directory message-auto-save-directory t
))
5540 (setq message-draft-article
5541 (nndraft-request-associate-buffer "drafts"))
5542 (setq buffer-file-name
(expand-file-name
5543 (if (memq system-type
5544 '(ms-dos ms-windows windows-nt
5545 cygwin cygwin32 win32 w32
5549 message-auto-save-directory
))
5550 (setq buffer-auto-save-file-name
(make-auto-save-file-name)))
5551 (clear-visited-file-modtime)
5552 (setq buffer-file-coding-system message-draft-coding-system
)))
5554 (defun message-disassociate-draft ()
5555 "Disassociate the message buffer from the drafts directory."
5556 (when message-draft-article
5557 (nndraft-request-expire-articles
5558 (list message-draft-article
) "drafts" nil t
)))
5560 (defun message-insert-headers ()
5561 "Generate the headers for the article."
5565 (message-narrow-to-headers)
5566 (when (message-news-p)
5567 (message-generate-headers
5570 (copy-sequence message-required-news-headers
)))))
5571 (when (message-mail-p)
5572 (message-generate-headers
5575 (copy-sequence message-required-mail-headers
))))))))
5580 ;;; Commands for interfacing with message
5584 (defun message-mail (&optional to subject
5585 other-headers continue switch-function
5586 yank-action send-actions
)
5587 "Start editing a mail message to be sent.
5588 OTHER-HEADERS is an alist of header/value pairs."
5590 (let ((message-this-is-mail t
) replybuffer
)
5591 (unless (message-mail-user-agent)
5592 (message-pop-to-buffer (message-buffer-name "mail" to
)))
5593 ;; FIXME: message-mail should do something if YANK-ACTION is not
5595 (and (consp yank-action
) (eq (car yank-action
) 'insert-buffer
)
5596 (setq replybuffer
(nth 1 yank-action
)))
5599 `((To .
,(or to
"")) (Subject .
,(or subject
"")))
5600 (when other-headers other-headers
))
5601 replybuffer send-actions
)
5602 ;; FIXME: Should return nil if failure.
5606 (defun message-news (&optional newsgroups subject
)
5607 "Start editing a news article to be sent."
5609 (let ((message-this-is-news t
))
5610 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
))
5611 (message-setup `((Newsgroups .
,(or newsgroups
""))
5612 (Subject .
,(or subject
""))))))
5614 (defun message-get-reply-headers (wide &optional to-address address-headers
)
5615 (let (follow-to mct never-mct to cc author mft recipients
)
5616 ;; Find all relevant headers we need.
5618 (message-narrow-to-headers-or-head)
5619 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
5620 ;; message-header-synonyms.
5621 (setq to
(or (message-fetch-field "to")
5622 (and (loop for synonym in message-header-synonyms
5623 when
(memq 'Original-To synonym
)
5625 (message-fetch-field "original-to")))
5626 cc
(message-fetch-field "cc")
5627 mct
(message-fetch-field "mail-copies-to")
5628 author
(or (message-fetch-field "mail-reply-to")
5629 (message-fetch-field "reply-to")
5630 (message-fetch-field "from")
5632 mft
(and message-use-mail-followup-to
5633 (message-fetch-field "mail-followup-to"))))
5635 ;; Handle special values of Mail-Copies-To.
5637 (cond ((or (equal (downcase mct
) "never")
5638 (equal (downcase mct
) "nobody"))
5641 ((or (equal (downcase mct
) "always")
5642 (equal (downcase mct
) "poster"))
5643 (setq mct author
))))
5646 ;; Build (textual) list of new recipient addresses.
5649 (setq recipients
(concat ", " author
)))
5651 (dolist (header address-headers
)
5652 (let ((value (message-fetch-field header
)))
5654 (setq recipients
(concat recipients
", " value
))))))
5656 (string-match "[^ \t,]" mft
)
5657 (or (not (eq message-use-mail-followup-to
'ask
))
5658 (message-y-or-n-p "Obey Mail-Followup-To? " t
"\
5659 You should normally obey the Mail-Followup-To: header. In this
5660 article, it has the value of
5664 which directs your response to " (if (string-match "," mft
)
5665 "the specified addresses"
5666 "that address only") ".
5668 Most commonly, Mail-Followup-To is used by a mailing list poster to
5669 express that responses should be sent to just the list, and not the
5672 If a message is posted to several mailing lists, Mail-Followup-To may
5673 also be used to direct the following discussion to one list only,
5674 because discussions that are spread over several lists tend to be
5675 fragmented and very difficult to follow.
5677 Also, some source/announcement lists are not intended for discussion;
5678 responses here are directed to other addresses.")))
5679 (setq recipients
(concat ", " mft
)))
5681 (setq recipients
(concat ", " to-address
))
5682 ;; If the author explicitly asked for a copy, we don't deny it to them.
5683 (if mct
(setq recipients
(concat recipients
", " mct
))))
5685 (setq recipients
(if never-mct
"" (concat ", " author
)))
5686 (if to
(setq recipients
(concat recipients
", " to
)))
5687 (if cc
(setq recipients
(concat recipients
", " cc
)))
5688 (if mct
(setq recipients
(concat recipients
", " mct
)))))
5689 (if (>= (length recipients
) 2)
5690 ;; Strip the leading ", ".
5691 (setq recipients
(substring recipients
2)))
5692 ;; Squeeze whitespace.
5693 (while (string-match "[ \t][ \t]+" recipients
)
5694 (setq recipients
(replace-match " " t t recipients
)))
5695 ;; Remove addresses that match `rmail-dont-reply-to-names'.
5696 (let ((rmail-dont-reply-to-names message-dont-reply-to-names
))
5697 (setq recipients
(rmail-dont-reply-to recipients
)))
5698 ;; Perhaps "Mail-Copies-To: never" removed the only address?
5699 (if (string-equal recipients
"")
5700 (setq recipients author
))
5701 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
5705 (cons (downcase (mail-strip-quoted-names addr
)) addr
))
5706 (message-tokenize-header recipients
)))
5707 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
5708 (let ((s recipients
))
5710 (setq recipients
(delq (assoc (car (pop s
)) s
) recipients
))))
5712 ;; Remove hierarchical lists that are contained within each other,
5713 ;; if message-hierarchical-addresses is defined.
5714 (when message-hierarchical-addresses
5715 (let ((plain-addrs (mapcar 'car recipients
))
5718 (setq subaddrs
(assoc (car plain-addrs
)
5719 message-hierarchical-addresses
)
5720 plain-addrs
(cdr plain-addrs
))
5722 (setq subaddrs
(cdr subaddrs
))
5724 (setq recip
(assoc (car subaddrs
) recipients
)
5725 subaddrs
(cdr subaddrs
))
5727 (setq recipients
(delq recip recipients
))))))))
5729 ;; Build the header alist. Allow the user to be asked whether
5730 ;; or not to reply to all recipients in a wide reply.
5731 (setq follow-to
(list (cons 'To
(cdr (pop recipients
)))))
5732 (when (and recipients
5733 (or (not message-wide-reply-confirm-recipients
)
5734 (y-or-n-p "Reply to all recipients? ")))
5735 (setq recipients
(mapconcat
5736 (lambda (addr) (cdr addr
)) recipients
", "))
5737 (if (string-match "^ +" recipients
)
5738 (setq recipients
(substring recipients
(match-end 0))))
5739 (push (cons 'Cc recipients
) follow-to
)))
5743 (defun message-reply (&optional to-address wide
)
5744 "Start editing a reply to the article in the current buffer."
5746 (require 'gnus-sum
) ; for gnus-list-identifiers
5747 (let ((cur (current-buffer))
5748 from subject date reply-to to cc
5749 references message-id follow-to
5750 (inhibit-point-motion-hooks t
)
5751 (message-this-is-mail t
)
5754 (message-narrow-to-head-1)
5755 ;; Allow customizations to have their say.
5757 ;; This is a regular reply.
5758 (when (functionp message-reply-to-function
)
5760 (setq follow-to
(funcall message-reply-to-function
))))
5761 ;; This is a followup.
5762 (when (functionp message-wide-reply-to-function
)
5765 (funcall message-wide-reply-to-function
)))))
5766 (setq message-id
(message-fetch-field "message-id" t
)
5767 references
(message-fetch-field "references")
5768 date
(message-fetch-field "date")
5769 from
(message-fetch-field "from")
5770 subject
(or (message-fetch-field "subject") "none"))
5771 (when gnus-list-identifiers
5772 (setq subject
(message-strip-list-identifiers subject
)))
5773 (setq subject
(concat "Re: " (message-strip-subject-re subject
)))
5774 (when message-subject-trailing-was-query
5775 (setq subject
(message-strip-subject-trailing-was subject
)))
5777 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
5778 (string-match "<[^>]+>" gnus-warning
))
5779 (setq message-id
(match-string 0 gnus-warning
)))
5782 (setq follow-to
(message-get-reply-headers wide to-address
))))
5784 (unless (message-mail-user-agent)
5785 (message-pop-to-buffer
5786 (message-buffer-name
5787 (if wide
"wide reply" "reply") from
5788 (if wide to-address nil
))))
5790 (setq message-reply-headers
5791 (vector 0 subject from date message-id references
0 0 ""))
5794 `((Subject .
,subject
)
5799 (defun message-wide-reply (&optional to-address
)
5800 "Make a \"wide\" reply to the message in the current buffer."
5802 (message-reply to-address t
))
5805 (defun message-followup (&optional to-newsgroups
)
5806 "Follow up to the message in the current buffer.
5807 If TO-NEWSGROUPS, use that as the new Newsgroups line."
5809 (require 'gnus-sum
) ; for gnus-list-identifiers
5810 (let ((cur (current-buffer))
5811 from subject date reply-to mrt mct
5812 references message-id follow-to
5813 (inhibit-point-motion-hooks t
)
5814 (message-this-is-news t
)
5815 followup-to distribution newsgroups gnus-warning posted-to
)
5818 (goto-char (point-min))
5819 (if (search-forward "\n\n" nil t
)
5822 (when (functionp message-followup-to-function
)
5824 (funcall message-followup-to-function
)))
5825 (setq from
(message-fetch-field "from")
5826 date
(message-fetch-field "date")
5827 subject
(or (message-fetch-field "subject") "none")
5828 references
(message-fetch-field "references")
5829 message-id
(message-fetch-field "message-id" t
)
5830 followup-to
(message-fetch-field "followup-to")
5831 newsgroups
(message-fetch-field "newsgroups")
5832 posted-to
(message-fetch-field "posted-to")
5833 reply-to
(message-fetch-field "reply-to")
5834 mrt
(message-fetch-field "mail-reply-to")
5835 distribution
(message-fetch-field "distribution")
5836 mct
(message-fetch-field "mail-copies-to"))
5837 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
5838 (string-match "<[^>]+>" gnus-warning
))
5839 (setq message-id
(match-string 0 gnus-warning
)))
5840 ;; Remove bogus distribution.
5841 (when (and (stringp distribution
)
5842 (let ((case-fold-search t
))
5843 (string-match "world" distribution
)))
5844 (setq distribution nil
))
5845 (if gnus-list-identifiers
5846 (setq subject
(message-strip-list-identifiers subject
)))
5847 (setq subject
(concat "Re: " (message-strip-subject-re subject
)))
5848 (when message-subject-trailing-was-query
5849 (setq subject
(message-strip-subject-trailing-was subject
)))
5852 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups
))
5854 (setq message-reply-headers
5855 (vector 0 subject from date message-id references
0 0 ""))
5858 `((Subject .
,subject
)
5861 (list (cons 'Newsgroups to-newsgroups
)))
5862 (follow-to follow-to
)
5863 ((and followup-to message-use-followup-to
)
5866 ((equal (downcase followup-to
) "poster")
5867 (if (or (eq message-use-followup-to
'use
)
5868 (message-y-or-n-p "Obey Followup-To: poster? " t
"\
5869 You should normally obey the Followup-To: header.
5871 `Followup-To: poster' sends your response via e-mail instead of news.
5873 A typical situation where `Followup-To: poster' is used is when the poster
5874 does not read the newsgroup, so he wouldn't see any replies sent to it."))
5876 (setq message-this-is-news nil
)
5877 (cons 'To
(or mrt reply-to from
"")))
5878 (cons 'Newsgroups newsgroups
)))
5880 (if (or (equal followup-to newsgroups
)
5881 (not (eq message-use-followup-to
'ask
))
5883 (concat "Obey Followup-To: " followup-to
"? ") t
"\
5884 You should normally obey the Followup-To: header.
5886 `Followup-To: " followup-to
"'
5887 directs your response to " (if (string-match "," followup-to
)
5888 "the specified newsgroups"
5889 "that newsgroup only") ".
5891 If a message is posted to several newsgroups, Followup-To is often
5892 used to direct the following discussion to one newsgroup only,
5893 because discussions that are spread over several newsgroup tend to
5894 be fragmented and very difficult to follow.
5896 Also, some source/announcement newsgroups are not intended for discussion;
5897 responses here are directed to other newsgroups."))
5898 (cons 'Newsgroups followup-to
)
5899 (cons 'Newsgroups newsgroups
))))))
5901 `((Newsgroups .
,posted-to
)))
5903 `((Newsgroups .
,newsgroups
))))
5904 ,@(and distribution
(list (cons 'Distribution distribution
)))
5906 (not (or (equal (downcase mct
) "never")
5907 (equal (downcase mct
) "nobody"))))
5908 (list (cons 'Cc
(if (or (equal (downcase mct
) "always")
5909 (equal (downcase mct
) "poster"))
5910 (or mrt reply-to from
"")
5915 (defun message-is-yours-p ()
5916 "Non-nil means current article is yours.
5917 If you have added 'cancel-messages to 'message-shoot-gnksa-feet', all articles
5918 are yours except those that have Cancel-Lock header not belonging to you.
5919 Instead of shooting GNKSA feet, you should modify 'message-alternative-emails'
5920 regexp to match all of yours addresses."
5921 ;; Canlock-logic as suggested by Per Abrahamsen
5922 ;; <abraham@dina.kvl.dk>
5924 ;; IF article has cancel-lock THEN
5925 ;; IF we can verify it THEN
5928 ;; error: cancellock: article is not yours
5930 ;; Use old rules, comparing sender...
5933 (message-narrow-to-head-1)
5934 (if (message-fetch-field "Cancel-Lock")
5935 (if (null (canlock-verify))
5937 (error "Failed to verify Cancel-lock: This article is not yours"))
5940 (message-gnksa-enable-p 'cancel-messages
)
5941 (and (setq sender
(message-fetch-field "sender"))
5942 (string-equal (downcase sender
)
5943 (downcase (message-make-sender))))
5944 ;; Email address in From field equals to our address
5945 (and (setq from
(message-fetch-field "from"))
5947 (downcase (cadr (mail-extract-address-components from
)))
5948 (downcase (cadr (mail-extract-address-components
5949 (message-make-from))))))
5950 ;; Email address in From field matches
5951 ;; 'message-alternative-emails' regexp
5953 message-alternative-emails
5955 message-alternative-emails
5956 (cadr (mail-extract-address-components from
))))))))))
5959 (defun message-cancel-news (&optional arg
)
5960 "Cancel an article you posted.
5961 If ARG, allow editing of the cancellation message."
5963 (unless (message-news-p)
5964 (error "This is not a news article; canceling is impossible"))
5965 (let (from newsgroups message-id distribution buf
)
5967 ;; Get header info from original article.
5969 (message-narrow-to-head-1)
5970 (setq from
(message-fetch-field "from")
5971 newsgroups
(message-fetch-field "newsgroups")
5972 message-id
(message-fetch-field "message-id" t
)
5973 distribution
(message-fetch-field "distribution")))
5974 ;; Make sure that this article was written by the user.
5975 (unless (message-is-yours-p)
5976 (error "This article is not yours"))
5977 (when (yes-or-no-p "Do you really want to cancel this article? ")
5978 ;; Make control message.
5981 (setq buf
(set-buffer (get-buffer-create " *message cancel*"))))
5983 (insert "Newsgroups: " newsgroups
"\n"
5985 "Subject: cmsg cancel " message-id
"\n"
5986 "Control: cancel " message-id
"\n"
5988 (concat "Distribution: " distribution
"\n")
5990 mail-header-separator
"\n"
5991 message-cancel-message
)
5992 (run-hooks 'message-cancel-hook
)
5994 (message "Canceling your article...")
5995 (if (let ((message-syntax-checks
5996 'dont-check-for-anything-just-trust-me
))
5997 (funcall message-send-news-function
))
5998 (message "Canceling your article...done"))
5999 (kill-buffer buf
))))))
6002 (defun message-supersede ()
6003 "Start composing a message to supersede the current message.
6004 This is done simply by taking the old article and adding a Supersedes
6005 header line with the old Message-ID."
6007 (let ((cur (current-buffer)))
6008 ;; Check whether the user owns the article that is to be superseded.
6009 (unless (message-is-yours-p)
6010 (error "This article is not yours"))
6011 ;; Get a normal message buffer.
6012 (message-pop-to-buffer (message-buffer-name "supersede"))
6013 (insert-buffer-substring cur
)
6015 (message-narrow-to-head-1)
6016 ;; Remove unwanted headers.
6017 (when message-ignored-supersedes-headers
6018 (message-remove-header message-ignored-supersedes-headers t
))
6019 (goto-char (point-min))
6020 (if (not (re-search-forward "^Message-ID: " nil t
))
6021 (error "No Message-ID in this article")
6022 (replace-match "Supersedes: " t t
))
6023 (goto-char (point-max))
6024 (insert mail-header-separator
)
6029 (defun message-recover ()
6030 "Reread contents of current buffer from its last auto-save file."
6032 (let ((file-name (make-auto-save-file-name)))
6033 (cond ((save-window-excursion
6034 (if (not (eq system-type
'vax-vms
))
6035 (with-output-to-temp-buffer "*Directory*"
6036 (with-current-buffer standard-output
6037 (fundamental-mode)) ; for Emacs 20.4+
6038 (buffer-disable-undo standard-output
)
6039 (let ((default-directory "/"))
6041 "ls" nil standard-output nil
"-l" file-name
))))
6042 (yes-or-no-p (format "Recover auto save file %s? " file-name
)))
6043 (let ((buffer-read-only nil
))
6045 (insert-file-contents file-name nil
)))
6046 (t (error "message-recover cancelled")))))
6048 ;;; Washing Subject:
6050 (defun message-wash-subject (subject)
6051 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
6052 Previous forwarders, replyers, etc. may add it."
6055 (goto-char (point-min))
6056 ;; strip Re/Fwd stuff off the beginning
6057 (while (re-search-forward
6058 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t
)
6061 ;; and gnus-style forwards [foo@bar.com] subject
6062 (goto-char (point-min))
6063 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t
)
6067 (goto-char (point-max))
6068 (while (re-search-backward "([Ff][Ww][Dd])" nil t
)
6071 ;; and finally, any whitespace that was left-over
6072 (goto-char (point-min))
6073 (while (re-search-forward "^[ \t]+" nil t
)
6075 (goto-char (point-max))
6076 (while (re-search-backward "[ \t]+$" nil t
)
6081 ;;; Forwarding messages.
6083 (defvar message-forward-decoded-p nil
6084 "Non-nil means the original message is decoded.")
6086 (defun message-forward-subject-name-subject (subject)
6087 "Generate a SUBJECT for a forwarded message.
6088 The form is: [Source] Subject, where if the original message was mail,
6089 Source is the name of the sender, and if the original message was
6090 news, Source is the list of newsgroups is was posted to."
6091 (let* ((group (message-fetch-field "newsgroups"))
6092 (from (message-fetch-field "from"))
6095 (gnus-group-decoded-name group
)
6096 (or (and from
(car (gnus-extract-address-components from
)))
6099 (if message-forward-decoded-p
6101 (mail-decode-encoded-word-string prefix
))
6104 (defun message-forward-subject-author-subject (subject)
6105 "Generate a SUBJECT for a forwarded message.
6106 The form is: [Source] Subject, where if the original message was mail,
6107 Source is the sender, and if the original message was news, Source is
6108 the list of newsgroups is was posted to."
6109 (let* ((group (message-fetch-field "newsgroups"))
6112 (gnus-group-decoded-name group
)
6113 (or (message-fetch-field "from")
6116 (if message-forward-decoded-p
6118 (mail-decode-encoded-word-string prefix
))
6121 (defun message-forward-subject-fwd (subject)
6122 "Generate a SUBJECT for a forwarded message.
6123 The form is: Fwd: Subject, where Subject is the original subject of
6125 (if (string-match "^Fwd: " subject
)
6127 (concat "Fwd: " subject
)))
6129 (defun message-make-forward-subject ()
6130 "Return a Subject header suitable for the message in the current buffer."
6133 (message-narrow-to-head-1)
6134 (let ((funcs message-make-forward-subject-function
)
6135 (subject (message-fetch-field "Subject")))
6138 (if message-forward-decoded-p
6140 (mail-decode-encoded-word-string subject
))
6142 (if message-wash-forwarded-subjects
6143 (setq subject
(message-wash-subject subject
)))
6144 ;; Make sure funcs is a list.
6147 (setq funcs
(list funcs
)))
6148 ;; Apply funcs in order, passing subject generated by previous
6149 ;; func to the next one.
6151 (when (functionp (car funcs
))
6152 (setq subject
(funcall (car funcs
) subject
)))
6153 (setq funcs
(cdr funcs
)))
6157 (defvar gnus-article-decoded-p
))
6161 (defun message-forward (&optional news digest
)
6162 "Forward the current message via mail.
6163 Optional NEWS will use news to forward instead of mail.
6164 Optional DIGEST will use digest to forward."
6166 (let* ((cur (current-buffer))
6167 (message-forward-decoded-p
6168 (if (local-variable-p 'gnus-article-decoded-p
(current-buffer))
6169 gnus-article-decoded-p
;; In an article buffer.
6170 message-forward-decoded-p
))
6171 (subject (message-make-forward-subject)))
6173 (message-news nil subject
)
6174 (message-mail nil subject
))
6175 (message-forward-make-body cur digest
)))
6177 (defun message-forward-make-body-plain (forward-buffer)
6179 "\n-------------------- Start of forwarded message --------------------\n")
6180 (let ((b (point)) e
)
6183 (mm-disable-multibyte)
6185 (with-current-buffer forward-buffer
6186 (mm-with-unibyte-current-buffer (buffer-string))))
6187 (mm-enable-multibyte)
6189 (goto-char (point-min))
6190 (when (looking-at "From ")
6191 (replace-match "X-From-Line: "))
6195 "\n-------------------- End of forwarded message --------------------\n")
6196 (when message-forward-ignored-headers
6198 (narrow-to-region b e
)
6200 (narrow-to-region (point)
6201 (or (search-forward "\n\n" nil t
) (point)))
6202 (message-remove-header message-forward-ignored-headers t
)))))
6204 (defun message-forward-make-body-mime (forward-buffer)
6205 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
6206 (let ((b (point)) e
)
6208 (narrow-to-region (point) (point))
6209 (mml-insert-buffer forward-buffer
)
6210 (goto-char (point-min))
6211 (when (looking-at "From ")
6212 (replace-match "X-From-Line: "))
6213 (goto-char (point-max)))
6215 (insert "<#/part>\n")))
6217 (defun message-forward-make-body-mml (forward-buffer)
6218 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
6219 (let ((b (point)) e
)
6220 (if (not message-forward-decoded-p
)
6223 (mm-disable-multibyte)
6225 (with-current-buffer forward-buffer
6226 (mm-with-unibyte-current-buffer (buffer-string))))
6227 (mm-enable-multibyte)
6229 (goto-char (point-min))
6230 (when (looking-at "From ")
6231 (replace-match "X-From-Line: "))
6234 (narrow-to-region (point) (point))
6235 (mml-insert-buffer forward-buffer
)
6236 (goto-char (point-min))
6237 (when (looking-at "From ")
6238 (replace-match "X-From-Line: "))
6239 (goto-char (point-max))))
6241 (insert "<#/mml>\n")
6242 (when (and (not message-forward-decoded-p
)
6243 message-forward-ignored-headers
)
6245 (narrow-to-region b e
)
6247 (narrow-to-region (point)
6248 (or (search-forward "\n\n" nil t
) (point)))
6249 (message-remove-header message-forward-ignored-headers t
)))))
6251 (defun message-forward-make-body-digest-plain (forward-buffer)
6253 "\n-------------------- Start of forwarded message --------------------\n")
6254 (let ((b (point)) e
)
6255 (mml-insert-buffer forward-buffer
)
6258 "\n-------------------- End of forwarded message --------------------\n")))
6260 (defun message-forward-make-body-digest-mime (forward-buffer)
6261 (insert "\n<#multipart type=digest>\n")
6262 (let ((b (point)) e
)
6263 (insert-buffer-substring forward-buffer
)
6265 (insert "<#/multipart>\n")
6267 (narrow-to-region b e
)
6269 (narrow-to-region (point)
6270 (or (search-forward "\n\n" nil t
) (point)))
6271 (delete-region (point-min) (point-max)))))
6273 (defun message-forward-make-body-digest (forward-buffer)
6274 (if message-forward-as-mime
6275 (message-forward-make-body-digest-mime forward-buffer
)
6276 (message-forward-make-body-digest-plain forward-buffer
)))
6279 (defun message-forward-make-body (forward-buffer &optional digest
)
6280 ;; Put point where we want it before inserting the forwarded
6282 (if message-forward-before-signature
6284 (goto-char (point-max)))
6286 (message-forward-make-body-digest forward-buffer
)
6287 (if message-forward-as-mime
6288 (if (and message-forward-show-mml
6289 (not (and (eq message-forward-show-mml
'best
)
6290 (with-current-buffer forward-buffer
6291 (goto-char (point-min))
6293 "Content-Type: *multipart/\\(signed\\|encrypted\\)"
6295 (message-forward-make-body-mml forward-buffer
)
6296 (message-forward-make-body-mime forward-buffer
))
6297 (message-forward-make-body-plain forward-buffer
)))
6298 (message-position-point))
6301 (defun message-forward-rmail-make-body (forward-buffer)
6302 (save-window-excursion
6303 (set-buffer forward-buffer
)
6304 ;; Rmail doesn't have rmail-msg-restore-non-pruned-header in Emacs
6305 ;; 20. FIXIT, or we drop support for rmail in Emacs 20.
6306 (if (rmail-msg-is-pruned)
6307 (rmail-msg-restore-non-pruned-header)))
6308 (message-forward-make-body forward-buffer
))
6310 (eval-when-compile (defvar rmail-enable-mime-composing
))
6312 ;; Fixme: Should have defcustom.
6314 (defun message-insinuate-rmail ()
6315 "Let RMAIL use message to forward."
6317 (setq rmail-enable-mime-composing t
)
6318 (setq rmail-insert-mime-forwarded-message-function
6319 'message-forward-rmail-make-body
))
6322 (defun message-resend (address)
6323 "Resend the current article to ADDRESS."
6325 (list (message-read-from-minibuffer "Resend message to: ")))
6326 (message "Resending message to %s..." address
)
6328 (let ((cur (current-buffer))
6330 ;; We first set up a normal mail buffer.
6331 (unless (message-mail-user-agent)
6332 (set-buffer (get-buffer-create " *message resend*"))
6334 (let ((message-this-is-mail t
)
6336 (message-setup `((To .
,address
))))
6337 ;; Insert our usual headers.
6338 (message-generate-headers '(From Date To Message-ID
))
6339 (message-narrow-to-headers)
6340 ;; Remove X-Draft-From header etc.
6341 (message-remove-header message-ignored-mail-headers t
)
6342 ;; Rename them all to "Resent-*".
6343 (goto-char (point-min))
6344 (while (re-search-forward "^[A-Za-z]" nil t
)
6349 (delete-region (point) (point-max))
6351 ;; Insert the message to be resent.
6352 (insert-buffer-substring cur
)
6353 (goto-char (point-min))
6354 (search-forward "\n\n")
6357 (narrow-to-region beg
(point))
6358 (message-remove-header message-ignored-resent-headers t
)
6359 (goto-char (point-max)))
6360 (insert mail-header-separator
)
6361 ;; Rename all old ("Also-")Resent headers.
6362 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t
)
6365 ;; Quote any "From " lines at the beginning.
6367 (when (looking-at "From ")
6368 (replace-match "X-From-Line: "))
6370 (let ((message-inhibit-body-encoding t
)
6371 message-required-mail-headers
)
6372 (message-send-mail))
6373 (kill-buffer (current-buffer)))
6374 (message "Resending message to %s...done" address
)))
6377 (defun message-bounce ()
6378 "Re-mail the current message.
6379 This only makes sense if the current message is a bounce message that
6380 contains some mail you have written which has been bounced back to
6383 (let ((handles (mm-dissect-buffer t
))
6385 (message-pop-to-buffer (message-buffer-name "bounce"))
6386 (if (stringp (car handles
))
6387 ;; This is a MIME bounce.
6388 (mm-insert-part (car (last handles
)))
6389 ;; This is a non-MIME bounce, so we try to remove things
6391 (mm-insert-part handles
)
6393 (goto-char (point-min))
6394 (re-search-forward "\n\n+" nil t
)
6395 (setq boundary
(point))
6396 ;; We remove everything before the bounced mail.
6397 (if (or (re-search-forward message-unsent-separator nil t
)
6399 (search-forward "\n\n" nil
'move
)
6400 (re-search-backward "^Return-Path:.*\n" boundary t
)))
6403 (delete-region (point-min)
6404 (if (re-search-forward "^[^ \n\t]+:" nil t
)
6407 (goto-char boundary
)
6408 (when (re-search-backward "^.?From .*\n" nil t
)
6409 (delete-region (match-beginning 0) (match-end 0)))))
6410 (mm-enable-multibyte)
6412 (message-narrow-to-head-1)
6413 (message-remove-header message-ignored-bounced-headers t
)
6414 (goto-char (point-max))
6415 (insert mail-header-separator
))
6416 (message-position-point)))
6419 ;;; Interactive entry points for new message buffers.
6423 (defun message-mail-other-window (&optional to subject
)
6424 "Like `message-mail' command, but display mail buffer in another window."
6426 (unless (message-mail-user-agent)
6427 (let ((pop-up-windows t
)
6428 (special-display-buffer-names nil
)
6429 (special-display-regexps nil
)
6430 (same-window-buffer-names nil
)
6431 (same-window-regexps nil
))
6432 (message-pop-to-buffer (message-buffer-name "mail" to
))))
6433 (let ((message-this-is-mail t
))
6434 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
"")))
6435 nil nil
'switch-to-buffer-other-window
)))
6438 (defun message-mail-other-frame (&optional to subject
)
6439 "Like `message-mail' command, but display mail buffer in another frame."
6441 (unless (message-mail-user-agent)
6442 (let ((pop-up-frames t
)
6443 (special-display-buffer-names nil
)
6444 (special-display-regexps nil
)
6445 (same-window-buffer-names nil
)
6446 (same-window-regexps nil
))
6447 (message-pop-to-buffer (message-buffer-name "mail" to
))))
6448 (let ((message-this-is-mail t
))
6449 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
"")))
6450 nil nil
'switch-to-buffer-other-frame
)))
6453 (defun message-news-other-window (&optional newsgroups subject
)
6454 "Start editing a news article to be sent."
6456 (let ((pop-up-windows t
)
6457 (special-display-buffer-names nil
)
6458 (special-display-regexps nil
)
6459 (same-window-buffer-names nil
)
6460 (same-window-regexps nil
))
6461 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
)))
6462 (let ((message-this-is-news t
))
6463 (message-setup `((Newsgroups .
,(or newsgroups
""))
6464 (Subject .
,(or subject
""))))))
6467 (defun message-news-other-frame (&optional newsgroups subject
)
6468 "Start editing a news article to be sent."
6470 (let ((pop-up-frames t
)
6471 (special-display-buffer-names nil
)
6472 (special-display-regexps nil
)
6473 (same-window-buffer-names nil
)
6474 (same-window-regexps nil
))
6475 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
)))
6476 (let ((message-this-is-news t
))
6477 (message-setup `((Newsgroups .
,(or newsgroups
""))
6478 (Subject .
,(or subject
""))))))
6482 ;; This code should be moved to underline.el (from which it is stolen).
6485 (defun bold-region (start end
)
6486 "Bold all nonblank characters in the region.
6487 Works by overstriking characters.
6488 Called from program, takes two arguments START and END
6489 which specify the range to operate on."
6492 (let ((end1 (make-marker)))
6493 (move-marker end1
(max start end
))
6494 (goto-char (min start end
))
6495 (while (< (point) end1
)
6496 (or (looking-at "[_\^@- ]")
6497 (insert (char-after) "\b"))
6498 (forward-char 1)))))
6501 (defun unbold-region (start end
)
6502 "Remove all boldness (overstruck characters) in the region.
6503 Called from program, takes two arguments START and END
6504 which specify the range to operate on."
6507 (let ((end1 (make-marker)))
6508 (move-marker end1
(max start end
))
6509 (goto-char (min start end
))
6510 (while (re-search-forward "\b" end1 t
)
6511 (if (eq (char-after) (char-after (- (point) 2)))
6512 (delete-char -
2))))))
6514 (defun message-exchange-point-and-mark ()
6515 "Exchange point and mark, but don't activate region if it was inactive."
6517 (message-mark-active-p)
6518 (exchange-point-and-mark))
6519 (setq mark-active nil
)))
6521 (defalias 'message-make-overlay
'make-overlay
)
6522 (defalias 'message-delete-overlay
'delete-overlay
)
6523 (defalias 'message-overlay-put
'overlay-put
)
6524 (defun message-kill-all-overlays ()
6525 (if (featurep 'xemacs
)
6526 (map-extents (lambda (extent ignore
) (delete-extent extent
)))
6527 (mapcar #'delete-overlay
(overlays-in (point-min) (point-max)))))
6529 ;; Support for toolbar
6531 (defvar tool-bar-map
)
6532 (defvar tool-bar-mode
))
6534 (defun message-tool-bar-local-item-from-menu (command icon in-map
&optional from-map
&rest props
)
6535 ;; We need to make tool bar entries in local keymaps with
6536 ;; `tool-bar-local-item-from-menu' in Emacs > 21.3
6537 (if (fboundp 'tool-bar-local-item-from-menu
)
6538 ;; This is for Emacs 21.3
6539 (tool-bar-local-item-from-menu command icon in-map from-map props
)
6540 (tool-bar-add-item-from-menu command icon from-map props
)))
6542 (defun message-tool-bar-map ()
6543 (or message-tool-bar-map
6544 (setq message-tool-bar-map
6546 (condition-case nil
(require 'tool-bar
) (error nil
))
6547 (fboundp 'tool-bar-add-item-from-menu
)
6549 (let ((tool-bar-map (copy-keymap tool-bar-map
))
6550 (load-path (mm-image-load-path)))
6551 ;; Zap some items which aren't so relevant and take
6553 (dolist (key '(print-buffer kill-buffer save-buffer
6554 write-file dired open-file
))
6555 (define-key tool-bar-map
(vector key
) nil
))
6556 (message-tool-bar-local-item-from-menu
6557 'message-send-and-exit
"mail_send" tool-bar-map message-mode-map
)
6558 (message-tool-bar-local-item-from-menu
6559 'message-kill-buffer
"close" tool-bar-map message-mode-map
)
6560 (message-tool-bar-local-item-from-menu
6561 'message-dont-send
"cancel" tool-bar-map message-mode-map
)
6562 (message-tool-bar-local-item-from-menu
6563 'mml-attach-file
"attach" tool-bar-map mml-mode-map
)
6564 (message-tool-bar-local-item-from-menu
6565 'ispell-message
"spell" tool-bar-map message-mode-map
)
6566 (message-tool-bar-local-item-from-menu
6567 'mml-preview
"preview"
6568 tool-bar-map mml-mode-map
)
6569 (message-tool-bar-local-item-from-menu
6570 'message-insert-importance-high
"important"
6571 tool-bar-map message-mode-map
)
6572 (message-tool-bar-local-item-from-menu
6573 'message-insert-importance-low
"unimportant"
6574 tool-bar-map message-mode-map
)
6575 (message-tool-bar-local-item-from-menu
6576 'message-insert-disposition-notification-to
"receipt"
6577 tool-bar-map message-mode-map
)
6580 ;;; Group name completion.
6582 (defcustom message-newgroups-header-regexp
6583 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
6584 "Regexp that match headers that lists groups."
6588 (defcustom message-completion-alist
6589 (list (cons message-newgroups-header-regexp
'message-expand-group
)
6590 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name
)
6591 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
6592 . message-expand-name
)
6593 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
6594 . message-expand-name
))
6595 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
6598 :type
'(alist :key-type regexp
:value-type function
))
6600 (defcustom message-tab-body-function nil
6601 "*Function to execute when `message-tab' (TAB) is executed in the body.
6602 If nil, the function bound in `text-mode-map' or `global-map' is executed."
6605 :link
'(custom-manual "(message)Various Commands")
6608 (defun message-tab ()
6609 "Complete names according to `message-completion-alist'.
6610 Execute function specified by `message-tab-body-function' when not in
6613 (let ((alist message-completion-alist
))
6615 (let ((mail-abbrev-mode-regexp (caar alist
)))
6616 (not (mail-abbrev-in-expansion-header-p))))
6617 (setq alist
(cdr alist
)))
6618 (funcall (or (cdar alist
) message-tab-body-function
6619 (lookup-key text-mode-map
"\t")
6620 (lookup-key global-map
"\t")
6621 'indent-relative
))))
6623 (defun message-expand-group ()
6624 "Expand the group name under point."
6625 (let* ((b (save-excursion
6630 (skip-chars-forward "^:")
6633 (skip-chars-backward "^, \t\n") (point))))
6634 (completion-ignore-case t
)
6635 (string (buffer-substring b
(progn (skip-chars-forward "^,\t\n ")
6637 (hashtb (and (boundp 'gnus-active-hashtb
) gnus-active-hashtb
))
6638 (completions (all-completions string hashtb
))
6640 (delete-region b
(point))
6642 ((= (length completions
) 1)
6643 (if (string= (car completions
) string
)
6646 (message "Only matching group"))
6647 (insert (car completions
))))
6648 ((and (setq comp
(try-completion string hashtb
))
6649 (not (string= comp string
)))
6654 (message "No matching groups")
6655 (save-selected-window
6656 (pop-to-buffer "*Completions*")
6657 (buffer-disable-undo)
6658 (let ((buffer-read-only nil
))
6660 (let ((standard-output (current-buffer)))
6661 (display-completion-list (sort completions
'string
<)))
6662 (goto-char (point-min))
6663 (delete-region (point) (progn (forward-line 3) (point))))))))))
6665 (defun message-expand-name ()
6666 (if (fboundp 'bbdb-complete-name
)
6667 (bbdb-complete-name)
6672 (defun message-talkative-question (ask question show
&rest text
)
6673 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
6674 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
6675 The following arguments may contain lists of values."
6677 (setq text
(message-flatten-list text
)))
6678 (save-window-excursion
6680 (with-output-to-temp-buffer " *MESSAGE information message*"
6681 (set-buffer " *MESSAGE information message*")
6682 (fundamental-mode) ; for Emacs 20.4+
6683 (mapcar 'princ text
)
6684 (goto-char (point-min))))
6685 (funcall ask question
))
6686 (funcall ask question
)))
6688 (defun message-flatten-list (list)
6689 "Return a new, flat list that contains all elements of LIST.
6691 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
6694 (apply 'append
(mapcar 'message-flatten-list list
)))
6698 (defun message-generate-new-buffer-clone-locals (name &optional varstr
)
6699 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
6700 Then clone the local variables and values from the old buffer to the
6701 new one, cloning only the locals having a substring matching the
6703 (let ((oldbuf (current-buffer)))
6705 (set-buffer (generate-new-buffer name
))
6706 (message-clone-locals oldbuf varstr
)
6709 (defun message-clone-locals (buffer &optional varstr
)
6710 "Clone the local variables from BUFFER to the current buffer."
6711 (let ((locals (save-excursion
6713 (buffer-local-variables)))
6714 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address"))
6717 (when (and (consp local
)
6719 (string-match regexp
(symbol-name (car local
)))
6721 (string-match varstr
(symbol-name (car local
)))))
6723 (set (make-local-variable (car local
))
6731 (defvar message-inhibit-body-encoding nil
)
6733 (defun message-encode-message-body ()
6734 (unless message-inhibit-body-encoding
6735 (let ((mail-parse-charset (or mail-parse-charset
6736 message-default-charset
))
6737 (case-fold-search t
)
6738 lines content-type-p
)
6741 (narrow-to-region (point) (point-max))
6742 (let ((new (mml-generate-mime)))
6744 (delete-region (point-min) (point-max))
6746 (goto-char (point-min))
6747 (if (eq (aref new
0) ?
\n)
6749 (search-forward "\n\n")
6750 (setq lines
(buffer-substring (point-min) (1- (point))))
6751 (delete-region (point-min) (point))))))
6753 (message-narrow-to-headers-or-head)
6754 (message-remove-header "Mime-Version")
6755 (goto-char (point-max))
6756 (insert "MIME-Version: 1.0\n")
6759 (setq content-type-p
6761 (re-search-backward "^Content-Type:" nil t
))))
6763 (message-narrow-to-headers-or-head)
6764 (message-remove-first-header "Content-Type")
6765 (message-remove-first-header "Content-Transfer-Encoding"))
6766 ;; We always make sure that the message has a Content-Type
6767 ;; header. This is because some broken MTAs and MUAs get
6768 ;; awfully confused when confronted with a message with a
6769 ;; MIME-Version header and without a Content-Type header. For
6770 ;; instance, Solaris' /usr/bin/mail.
6771 (unless content-type-p
6772 (goto-char (point-min))
6773 ;; For unknown reason, MIME-Version doesn't exist.
6774 (when (re-search-forward "^MIME-Version:" nil t
)
6776 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
6778 (defun message-read-from-minibuffer (prompt &optional initial-contents
)
6779 "Read from the minibuffer while providing abbrev expansion."
6780 (if (fboundp 'mail-abbrevs-setup
)
6781 (let ((mail-abbrev-mode-regexp "")
6782 (minibuffer-setup-hook 'mail-abbrevs-setup
)
6783 (minibuffer-local-map message-minibuffer-local-map
))
6784 (read-from-minibuffer prompt initial-contents
))
6785 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook
)
6786 (minibuffer-local-map message-minibuffer-local-map
))
6787 (read-string prompt initial-contents
))))
6789 (defun message-use-alternative-email-as-from ()
6790 (require 'mail-utils
)
6791 (let* ((fields '("To" "Cc"))
6794 (mail-strip-quoted-names
6795 (mapconcat 'message-fetch-reply-field fields
","))
6799 (if (string-match message-alternative-emails
(car emails
))
6800 (setq email
(car emails
)
6803 (unless (or (not email
) (equal email user-mail-address
))
6804 (goto-char (point-max))
6805 (insert "From: " email
"\n"))))
6807 (defun message-options-get (symbol)
6808 (cdr (assq symbol message-options
)))
6810 (defun message-options-set (symbol value
)
6811 (let ((the-cons (assq symbol message-options
)))
6814 (setcdr the-cons value
)
6815 (setq message-options
(delq the-cons message-options
)))
6817 (push (cons symbol value
) message-options
))))
6820 (defun message-options-set-recipient ()
6822 (message-narrow-to-headers-or-head)
6823 (message-options-set 'message-sender
6824 (mail-strip-quoted-names
6825 (message-fetch-field "from")))
6826 (message-options-set 'message-recipients
6827 (mail-strip-quoted-names
6828 (let ((to (message-fetch-field "to"))
6829 (cc (message-fetch-field "cc"))
6830 (bcc (message-fetch-field "bcc")))
6833 (if (and to cc
) ", ")
6835 (if (and (or to cc
) bcc
) ", ")
6838 (defun message-hide-headers ()
6839 "Hide headers based on the `message-hidden-headers' variable."
6840 (let ((regexps (if (stringp message-hidden-headers
)
6841 (list message-hidden-headers
)
6842 message-hidden-headers
))
6843 (inhibit-point-motion-hooks t
)
6844 (after-change-functions nil
))
6848 (message-narrow-to-headers)
6849 (goto-char (point-min))
6851 (if (not (message-hide-header-p regexps
))
6852 (message-next-header)
6853 (let ((begin (point)))
6854 (message-next-header)
6855 (add-text-properties
6857 '(invisible t message-hidden t
))))))))))
6859 (defun message-hide-header-p (regexps)
6862 (when (eq (car regexps
) 'not
)
6865 (dolist (regexp regexps
)
6866 (setq result
(or result
(looking-at regexp
))))
6871 (when (featurep 'xemacs
)
6872 (require 'messagexmas
)
6873 (message-xmas-redefine))
6877 (run-hooks 'message-load-hook
)
6880 ;; coding: iso-8859-1
6883 ;; arch-tag: 94b32cac-4504-4b6c-8181-030ebf380ee0
6884 ;;; message.el ends here