1 ;;; message.el --- composing mail and news messages
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006 Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: mail, news
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
28 ;; This mode provides mail-sending facilities from within Emacs. It
29 ;; consists mainly of large chunks of code from the sendmail.el,
30 ;; gnus-msg.el and rnewspost.el files.
36 (defvar gnus-message-group-art
)
37 (defvar gnus-list-identifiers
)) ; gnus-sum is required where necessary
42 ;; This is apparently necessary even though things are autoloaded.
43 ;; Because we dynamically bind mail-abbrev-mode-regexp, we'd better
44 ;; require mailabbrev here.
45 (if (featurep 'xemacs
)
46 (require 'mail-abbrevs
)
47 (require 'mailabbrev
))
52 (autoload 'gnus-find-method-for-group
"gnus")
53 (autoload 'nnvirtual-find-group-art
"nnvirtual")
54 (autoload 'gnus-group-decoded-name
"gnus-group"))
56 (defgroup message
'((user-mail-address custom-variable
)
57 (user-full-name custom-variable
))
58 "Mail and news message composing."
59 :link
'(custom-manual "(message)Top")
63 (put 'user-mail-address
'custom-type
'string
)
64 (put 'user-full-name
'custom-type
'string
)
66 (defgroup message-various nil
67 "Various Message Variables."
68 :link
'(custom-manual "(message)Various Message Variables")
71 (defgroup message-buffers nil
73 :link
'(custom-manual "(message)Message Buffers")
76 (defgroup message-sending nil
78 :link
'(custom-manual "(message)Sending Variables")
81 (defgroup message-interface nil
83 :link
'(custom-manual "(message)Interface")
86 (defgroup message-forwarding nil
88 :link
'(custom-manual "(message)Forwarding")
89 :group
'message-interface
)
91 (defgroup message-insertion nil
93 :link
'(custom-manual "(message)Insertion")
96 (defgroup message-headers nil
98 :link
'(custom-manual "(message)Message Headers")
101 (defgroup message-news nil
102 "Composing News Messages."
105 (defgroup message-mail nil
106 "Composing Mail Messages."
109 (defgroup message-faces nil
110 "Faces used for message composing."
114 (defcustom message-directory
"~/Mail/"
115 "*Directory from which all other mail file variables are derived."
116 :group
'message-various
119 (defcustom message-max-buffers
10
120 "*How many buffers to keep before starting to kill them off."
121 :group
'message-buffers
124 (defcustom message-send-rename-function nil
125 "Function called to rename the buffer after sending it."
126 :group
'message-buffers
127 :type
'(choice function
(const nil
)))
129 (defcustom message-fcc-handler-function
'message-output
130 "*A function called to save outgoing articles.
131 This function will be called with the name of the file to store the
132 article in. The default function is `message-output' which saves in Unix
134 :type
'(radio (function-item message-output
)
135 (function :tag
"Other"))
136 :group
'message-sending
)
138 (defcustom message-fcc-externalize-attachments nil
139 "If non-nil, attachments are included as external parts in Fcc copies."
142 :group
'message-sending
)
144 (defcustom message-courtesy-message
145 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
146 "*This is inserted at the start of a mailed copy of a posted message.
147 If the string contains the format spec \"%s\", the Newsgroups
148 the article has been posted to will be inserted there.
149 If this variable is nil, no such courtesy message will be added."
150 :group
'message-sending
151 :type
'(radio string
(const nil
)))
153 (defcustom message-ignored-bounced-headers
154 "^\\(Received\\|Return-Path\\|Delivered-To\\):"
155 "*Regexp that matches headers to be removed in resent bounced mail."
156 :group
'message-interface
160 (defcustom message-from-style
'default
161 "*Specifies how \"From\" headers look.
163 If nil, they contain just the return address like:
165 If `parens', they look like:
166 king@grassland.com (Elvis Parsley)
167 If `angles', they look like:
168 Elvis Parsley <king@grassland.com>
170 Otherwise, most addresses look like `angles', but they look like
171 `parens' if `angles' would need quoting and `parens' would not."
172 :type
'(choice (const :tag
"simple" nil
)
176 :group
'message-headers
)
178 (defcustom message-insert-canlock t
179 "Whether to insert a Cancel-Lock header in news postings."
181 :group
'message-headers
184 (defcustom message-syntax-checks
185 (if message-insert-canlock
'((sender . disabled
)) nil
)
186 ;; Guess this one shouldn't be easy to customize...
187 "*Controls what syntax checks should not be performed on outgoing posts.
188 To disable checking of long signatures, for instance, add
189 `(signature . disabled)' to this list.
191 Don't touch this variable unless you really know what you're doing.
193 Checks include `approved', `continuation-headers', `control-chars',
194 `empty', `existing-newsgroups', `from', `illegible-text',
195 `invisible-text', `long-header-lines', `long-lines', `message-id',
196 `multiple-headers', `new-text', `newsgroups', `quoting-style',
197 `repeated-newsgroups', `reply-to', `sender', `sendsys', `shoot',
198 `shorten-followup-to', `signature', `size', `subject', `subject-cmsg'
199 and `valid-newsgroups'."
201 :type
'(repeat sexp
)) ; Fixme: improve this
203 (defcustom message-required-headers
'((optional . References
)
205 "*Headers to be generated or prompted for when sending a message.
206 Also see `message-required-news-headers' and
207 `message-required-mail-headers'."
210 :group
'message-headers
211 :link
'(custom-manual "(message)Message Headers")
212 :type
'(repeat sexp
))
214 (defcustom message-draft-headers
'(References From
)
215 "*Headers to be generated when saving a draft message."
218 :group
'message-headers
219 :link
'(custom-manual "(message)Message Headers")
220 :type
'(repeat sexp
))
222 (defcustom message-required-news-headers
223 '(From Newsgroups Subject Date Message-ID
224 (optional . Organization
)
225 (optional . User-Agent
))
226 "*Headers to be generated or prompted for when posting an article.
227 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
228 Message-ID. Organization, Lines, In-Reply-To, Expires, and
229 User-Agent are optional. If don't you want message to insert some
230 header, remove it from this list."
232 :group
'message-headers
233 :link
'(custom-manual "(message)Message Headers")
234 :type
'(repeat sexp
))
236 (defcustom message-required-mail-headers
237 '(From Subject Date
(optional . In-Reply-To
) Message-ID
238 (optional . User-Agent
))
239 "*Headers to be generated or prompted for when mailing a message.
240 It is recommended that From, Date, To, Subject and Message-ID be
241 included. Organization and User-Agent are optional."
243 :group
'message-headers
244 :link
'(custom-manual "(message)Message Headers")
245 :type
'(repeat sexp
))
247 (defcustom message-deletable-headers
'(Message-ID Date Lines
)
248 "Headers to be deleted if they already exist and were generated by message previously."
249 :group
'message-headers
250 :link
'(custom-manual "(message)Message Headers")
253 (defcustom message-ignored-news-headers
254 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
255 "*Regexp of headers to be removed unconditionally before posting."
257 :group
'message-headers
258 :link
'(custom-manual "(message)Message Headers")
259 :type
'(repeat :value-to-internal
(lambda (widget value
)
260 (custom-split-regexp-maybe value
))
261 :match
(lambda (widget value
)
263 (widget-editable-list-match widget value
)))
266 (defcustom message-ignored-mail-headers
267 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
268 "*Regexp of headers to be removed unconditionally before mailing."
270 :group
'message-headers
271 :link
'(custom-manual "(message)Mail Headers")
274 (defcustom message-ignored-supersedes-headers
"^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|^X-Trace:\\|^X-Complaints-To:\\|Return-Path:\\|^Supersedes:\\|^NNTP-Posting-Date:\\|^X-Trace:\\|^X-Complaints-To:\\|^Cancel-Lock:\\|^Cancel-Key:\\|^X-Hashcash:\\|^X-Payment:"
275 "*Header lines matching this regexp will be deleted before posting.
276 It's best to delete old Path and Date headers before posting to avoid
278 :group
'message-interface
279 :link
'(custom-manual "(message)Superseding")
280 :type
'(repeat :value-to-internal
(lambda (widget value
)
281 (custom-split-regexp-maybe value
))
282 :match
(lambda (widget value
)
284 (widget-editable-list-match widget value
)))
287 (defcustom message-subject-re-regexp
288 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)*:[ \t]*\\)*[ \t]*"
289 "*Regexp matching \"Re: \" in the subject line."
290 :group
'message-various
291 :link
'(custom-manual "(message)Message Headers")
294 ;;; Start of variables adopted from `message-utils.el'.
296 (defcustom message-subject-trailing-was-query
'ask
297 "*What to do with trailing \"(was: <old subject>)\" in subject lines.
298 If nil, leave the subject unchanged. If it is the symbol `ask', query
299 the user what do do. In this case, the subject is matched against
300 `message-subject-trailing-was-ask-regexp'. If
301 `message-subject-trailing-was-query' is t, always strip the trailing
302 old subject. In this case, `message-subject-trailing-was-regexp' is
305 :type
'(choice (const :tag
"never" nil
)
306 (const :tag
"always strip" t
)
308 :link
'(custom-manual "(message)Message Headers")
309 :group
'message-various
)
311 (defcustom message-subject-trailing-was-ask-regexp
312 "[ \t]*\\([[(]+[Ww][Aa][Ss][ \t]*.*[\])]+\\)"
313 "*Regexp matching \"(was: <old subject>)\" in the subject line.
315 The function `message-strip-subject-trailing-was' uses this regexp if
316 `message-subject-trailing-was-query' is set to the symbol `ask'. If
317 the variable is t instead of `ask', use
318 `message-subject-trailing-was-regexp' instead.
320 It is okay to create some false positives here, as the user is asked."
322 :group
'message-various
323 :link
'(custom-manual "(message)Message Headers")
326 (defcustom message-subject-trailing-was-regexp
327 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
328 "*Regexp matching \"(was: <old subject>)\" in the subject line.
330 If `message-subject-trailing-was-query' is set to t, the subject is
331 matched against `message-subject-trailing-was-regexp' in
332 `message-strip-subject-trailing-was'. You should use a regexp creating very
333 few false positives here."
335 :group
'message-various
336 :link
'(custom-manual "(message)Message Headers")
339 ;;; marking inserted text
341 (defcustom message-mark-insert-begin
342 "--8<---------------cut here---------------start------------->8---\n"
343 "How to mark the beginning of some inserted text."
346 :link
'(custom-manual "(message)Insertion Variables")
347 :group
'message-various
)
349 (defcustom message-mark-insert-end
350 "--8<---------------cut here---------------end--------------->8---\n"
351 "How to mark the end of some inserted text."
354 :link
'(custom-manual "(message)Insertion Variables")
355 :group
'message-various
)
357 (defcustom message-archive-header
"X-No-Archive: Yes\n"
358 "Header to insert when you don't want your article to be archived.
359 Archives \(such as groups.google.com\) respect this header."
362 :link
'(custom-manual "(message)Header Commands")
363 :group
'message-various
)
365 (defcustom message-archive-note
366 "X-No-Archive: Yes - save http://groups.google.com/"
367 "Note to insert why you wouldn't want this posting archived.
368 If nil, don't insert any text in the body."
370 :type
'(radio string
(const nil
))
371 :link
'(custom-manual "(message)Header Commands")
372 :group
'message-various
)
374 ;;; Crossposts and Followups
375 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
376 ;; new suggestions by R. Weikusat <rw at another.de>
378 (defvar message-cross-post-old-target nil
379 "Old target for cross-posts or follow-ups.")
380 (make-variable-buffer-local 'message-cross-post-old-target
)
382 (defcustom message-cross-post-default t
383 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
384 If nil, `message-cross-post-followup-to' will only do a followup. Note that
385 you can explicitly override this setting by calling
386 `message-cross-post-followup-to' with a prefix."
389 :group
'message-various
)
391 (defcustom message-cross-post-note
"Crosspost & Followup-To: "
392 "Note to insert before signature to notify of cross-post and follow-up."
395 :group
'message-various
)
397 (defcustom message-followup-to-note
"Followup-To: "
398 "Note to insert before signature to notify of follow-up only."
401 :group
'message-various
)
403 (defcustom message-cross-post-note-function
'message-cross-post-insert-note
404 "Function to use to insert note about Crosspost or Followup-To.
405 The function will be called with four arguments. The function should not only
406 insert a note, but also ensure old notes are deleted. See the documentation
407 for `message-cross-post-insert-note'."
410 :group
'message-various
)
412 ;;; End of variables adopted from `message-utils.el'.
415 (defcustom message-signature-separator
"^-- *$"
416 "Regexp matching the signature separator."
418 :link
'(custom-manual "(message)Various Message Variables")
419 :group
'message-various
)
421 (defcustom message-elide-ellipsis
"\n[...]\n\n"
422 "*The string which is inserted for elided text."
424 :link
'(custom-manual "(message)Various Commands")
425 :group
'message-various
)
427 (defcustom message-interactive t
428 "Non-nil means when sending a message wait for and display errors.
429 nil means let mailer mail back a message to report errors."
430 :group
'message-sending
432 :link
'(custom-manual "(message)Sending Variables")
435 (defcustom message-generate-new-buffers
'unique
436 "*Non-nil means create a new message buffer whenever `message-setup' is called.
437 If this is a function, call that function with three parameters: The type,
438 the to address and the group name. (Any of these may be nil.) The function
439 should return the new buffer name."
440 :group
'message-buffers
441 :link
'(custom-manual "(message)Message Buffers")
442 :type
'(choice (const :tag
"off" nil
)
443 (const :tag
"unique" unique
)
444 (const :tag
"unsent" unsent
)
447 (defcustom message-kill-buffer-on-exit nil
448 "*Non-nil means that the message buffer will be killed after sending a message."
449 :group
'message-buffers
450 :link
'(custom-manual "(message)Message Buffers")
454 (defvar gnus-local-organization
))
455 (defcustom message-user-organization
456 (or (and (boundp 'gnus-local-organization
)
457 (stringp gnus-local-organization
)
458 gnus-local-organization
)
459 (getenv "ORGANIZATION")
461 "*String to be used as an Organization header.
462 If t, use `message-user-organization-file'."
463 :group
'message-headers
464 :type
'(choice string
465 (const :tag
"consult file" t
)))
468 (defcustom message-user-organization-file
"/usr/lib/news/organization"
469 "*Local news organization file."
471 :link
'(custom-manual "(message)News Headers")
472 :group
'message-headers
)
474 (defcustom message-make-forward-subject-function
475 #'message-forward-subject-name-subject
476 "*List of functions called to generate subject headers for forwarded messages.
477 The subject generated by the previous function is passed into each
480 The provided functions are:
482 * `message-forward-subject-author-subject' Source of article (author or
483 newsgroup), in brackets followed by the subject
484 * `message-forward-subject-name-subject' Source of article (name of author
485 or newsgroup), in brackets followed by the subject
486 * `message-forward-subject-fwd' Subject of article with 'Fwd:' prepended
488 :group
'message-forwarding
489 :link
'(custom-manual "(message)Forwarding")
490 :type
'(radio (function-item message-forward-subject-author-subject
)
491 (function-item message-forward-subject-fwd
)
492 (function-item message-forward-subject-name-subject
)
493 (repeat :tag
"List of functions" function
)))
495 (defcustom message-forward-as-mime t
496 "*Non-nil means forward messages as an inline/rfc822 MIME section.
497 Otherwise, directly inline the old message in the forwarded message."
499 :group
'message-forwarding
500 :link
'(custom-manual "(message)Forwarding")
503 (defcustom message-forward-show-mml
'best
504 "*Non-nil means show forwarded messages as MML (decoded from MIME).
505 Otherwise, forwarded messages are unchanged.
506 Can also be the symbol `best' to indicate that MML should be
507 used, except when it is a bad idea to use MML. One example where
508 it is a bad idea is when forwarding a signed or encrypted
509 message, because converting MIME to MML would invalidate the
512 :group
'message-forwarding
513 :type
'(choice (const :tag
"use MML" t
)
514 (const :tag
"don't use MML " nil
)
515 (const :tag
"use MML when appropriate" best
)))
517 (defcustom message-forward-before-signature t
518 "*Non-nil means put forwarded message before signature, else after."
519 :group
'message-forwarding
522 (defcustom message-wash-forwarded-subjects nil
523 "*Non-nil means try to remove as much cruft as possible from the subject.
524 Done before generating the new subject of a forward."
525 :group
'message-forwarding
526 :link
'(custom-manual "(message)Forwarding")
529 (defcustom message-ignored-resent-headers
"^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From "
530 "*All headers that match this regexp will be deleted when resending a message."
531 :group
'message-interface
532 :link
'(custom-manual "(message)Resending")
533 :type
'(repeat :value-to-internal
(lambda (widget value
)
534 (custom-split-regexp-maybe value
))
535 :match
(lambda (widget value
)
537 (widget-editable-list-match widget value
)))
540 (defcustom message-forward-ignored-headers
"^Content-Transfer-Encoding:\\|^X-Gnus"
541 "*All headers that match this regexp will be deleted when forwarding a message."
543 :group
'message-forwarding
544 :type
'(repeat :value-to-internal
(lambda (widget value
)
545 (custom-split-regexp-maybe value
))
546 :match
(lambda (widget value
)
548 (widget-editable-list-match widget value
)))
551 (defcustom message-ignored-cited-headers
"."
552 "*Delete these headers from the messages you yank."
553 :group
'message-insertion
554 :link
'(custom-manual "(message)Insertion Variables")
557 (defcustom message-cite-prefix-regexp
558 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
559 "\\([ \t]*[-_.[:word:]]+>+\\|[ \t]*[]>|}+]\\)+"
560 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
561 (let ((old-table (syntax-table))
562 non-word-constituents
)
563 (set-syntax-table text-mode-syntax-table
)
564 (setq non-word-constituents
566 (if (string-match "\\w" "-") "" "-")
567 (if (string-match "\\w" "_") "" "_")
568 (if (string-match "\\w" ".") "" ".")))
569 (set-syntax-table old-table
)
570 (if (equal non-word-constituents
"")
571 "\\([ \t]*\\(\\w\\)+>+\\|[ \t]*[]>|}+]\\)+"
572 (concat "\\([ \t]*\\(\\w\\|["
573 non-word-constituents
574 "]\\)+>+\\|[ \t]*[]>|}+]\\)+"))))
575 "*Regexp matching the longest possible citation prefix on a line."
577 :group
'message-insertion
578 :link
'(custom-manual "(message)Insertion Variables")
581 (defcustom message-cancel-message
"I am canceling my own article.\n"
582 "Message to be inserted in the cancel message."
583 :group
'message-interface
584 :link
'(custom-manual "(message)Canceling News")
587 ;; Useful to set in site-init.el
589 (defcustom message-send-mail-function
'message-send-mail-with-sendmail
590 "Function to call to send the current buffer as mail.
591 The headers should be delimited by a line whose contents match the
592 variable `mail-header-separator'.
594 Valid values include `message-send-mail-with-sendmail' (the default),
595 `message-send-mail-with-mh', `message-send-mail-with-qmail',
596 `message-smtpmail-send-it', `smtpmail-send-it' and `feedmail-send-it'.
598 See also `send-mail-function'."
599 :type
'(radio (function-item message-send-mail-with-sendmail
)
600 (function-item message-send-mail-with-mh
)
601 (function-item message-send-mail-with-qmail
)
602 (function-item message-smtpmail-send-it
)
603 (function-item smtpmail-send-it
)
604 (function-item feedmail-send-it
)
605 (function :tag
"Other"))
606 :group
'message-sending
607 :link
'(custom-manual "(message)Mail Variables")
608 :group
'message-mail
)
610 (defcustom message-send-news-function
'message-send-news
611 "Function to call to send the current buffer as news.
612 The headers should be delimited by a line whose contents match the
613 variable `mail-header-separator'."
614 :group
'message-sending
616 :link
'(custom-manual "(message)News Variables")
619 (defcustom message-reply-to-function nil
620 "If non-nil, function that should return a list of headers.
621 This function should pick out addresses from the To, Cc, and From headers
622 and respond with new To and Cc headers."
623 :group
'message-interface
624 :link
'(custom-manual "(message)Reply")
625 :type
'(choice function
(const nil
)))
627 (defcustom message-wide-reply-to-function nil
628 "If non-nil, function that should return a list of headers.
629 This function should pick out addresses from the To, Cc, and From headers
630 and respond with new To and Cc headers."
631 :group
'message-interface
632 :link
'(custom-manual "(message)Wide Reply")
633 :type
'(choice function
(const nil
)))
635 (defcustom message-followup-to-function nil
636 "If non-nil, function that should return a list of headers.
637 This function should pick out addresses from the To, Cc, and From headers
638 and respond with new To and Cc headers."
639 :group
'message-interface
640 :link
'(custom-manual "(message)Followup")
641 :type
'(choice function
(const nil
)))
643 (defcustom message-use-followup-to
'ask
644 "*Specifies what to do with Followup-To header.
645 If nil, always ignore the header. If it is t, use its value, but
646 query before using the \"poster\" value. If it is the symbol `ask',
647 always query the user whether to use the value. If it is the symbol
648 `use', always use the value."
649 :group
'message-interface
650 :link
'(custom-manual "(message)Followup")
651 :type
'(choice (const :tag
"ignore" nil
)
652 (const :tag
"use & query" t
)
656 (defcustom message-use-mail-followup-to
'use
657 "*Specifies what to do with Mail-Followup-To header.
658 If nil, always ignore the header. If it is the symbol `ask', always
659 query the user whether to use the value. If it is the symbol `use',
660 always use the value."
662 :group
'message-interface
663 :link
'(custom-manual "(message)Mailing Lists")
664 :type
'(choice (const :tag
"ignore" nil
)
668 (defcustom message-subscribed-address-functions nil
669 "*Specifies functions for determining list subscription.
670 If nil, do not attempt to determine list subscription with functions.
671 If non-nil, this variable contains a list of functions which return
672 regular expressions to match lists. These functions can be used in
673 conjunction with `message-subscribed-regexps' and
674 `message-subscribed-addresses'."
676 :group
'message-interface
677 :link
'(custom-manual "(message)Mailing Lists")
678 :type
'(repeat sexp
))
680 (defcustom message-subscribed-address-file nil
681 "*A file containing addresses the user is subscribed to.
682 If nil, do not look at any files to determine list subscriptions. If
683 non-nil, each line of this file should be a mailing list address."
685 :group
'message-interface
686 :link
'(custom-manual "(message)Mailing Lists")
687 :type
'(radio file
(const nil
)))
689 (defcustom message-subscribed-addresses nil
690 "*Specifies a list of addresses the user is subscribed to.
691 If nil, do not use any predefined list subscriptions. This list of
692 addresses can be used in conjunction with
693 `message-subscribed-address-functions' and `message-subscribed-regexps'."
695 :group
'message-interface
696 :link
'(custom-manual "(message)Mailing Lists")
697 :type
'(repeat string
))
699 (defcustom message-subscribed-regexps nil
700 "*Specifies a list of addresses the user is subscribed to.
701 If nil, do not use any predefined list subscriptions. This list of
702 regular expressions can be used in conjunction with
703 `message-subscribed-address-functions' and `message-subscribed-addresses'."
705 :group
'message-interface
706 :link
'(custom-manual "(message)Mailing Lists")
707 :type
'(repeat regexp
))
709 (defcustom message-allow-no-recipients
'ask
710 "Specifies what to do when there are no recipients other than Gcc/Fcc.
711 If it is the symbol `always', the posting is allowed. If it is the
712 symbol `never', the posting is not allowed. If it is the symbol
713 `ask', you are prompted."
715 :group
'message-interface
716 :link
'(custom-manual "(message)Message Headers")
717 :type
'(choice (const always
)
721 (defcustom message-sendmail-f-is-evil nil
722 "*Non-nil means don't add \"-f username\" to the sendmail command line.
723 Doing so would be even more evil than leaving it out."
724 :group
'message-sending
725 :link
'(custom-manual "(message)Mail Variables")
728 (defcustom message-sendmail-envelope-from nil
729 "*Envelope-from when sending mail with sendmail.
730 If this is nil, use `user-mail-address'. If it is the symbol
731 `header', use the From: header of the message."
733 :type
'(choice (string :tag
"From name")
734 (const :tag
"Use From: header from message" header
)
735 (const :tag
"Use `user-mail-address'" nil
))
736 :link
'(custom-manual "(message)Mail Variables")
737 :group
'message-sending
)
739 ;; qmail-related stuff
740 (defcustom message-qmail-inject-program
"/var/qmail/bin/qmail-inject"
741 "Location of the qmail-inject program."
742 :group
'message-sending
743 :link
'(custom-manual "(message)Mail Variables")
746 (defcustom message-qmail-inject-args nil
747 "Arguments passed to qmail-inject programs.
748 This should be a list of strings, one string for each argument. It
749 may also be a function.
751 For e.g., if you wish to set the envelope sender address so that bounces
752 go to the right place or to deal with listserv's usage of that address, you
753 might set this variable to '(\"-f\" \"you@some.where\")."
754 :group
'message-sending
755 :link
'(custom-manual "(message)Mail Variables")
756 :type
'(choice (function)
759 (defvar message-cater-to-broken-inn t
760 "Non-nil means Gnus should not fold the `References' header.
761 Folding `References' makes ancient versions of INN create incorrect
765 (defvar gnus-post-method
)
766 (defvar gnus-select-method
))
767 (defcustom message-post-method
768 (cond ((and (boundp 'gnus-post-method
)
769 (listp gnus-post-method
)
772 ((boundp 'gnus-select-method
)
775 "*Method used to post news.
776 Note that when posting from inside Gnus, for instance, this
777 variable isn't used."
779 :group
'message-sending
780 ;; This should be the `gnus-select-method' widget, but that might
781 ;; create a dependence to `gnus.el'.
784 ;; FIXME: This should be a temporary workaround until someone implements a
785 ;; proper solution. If a crash happens while replying, the auto-save file
786 ;; will *not* have a `References:' header if `message-generate-headers-first'
787 ;; is nil. See: http://article.gmane.org/gmane.emacs.gnus.general/51138
788 (defcustom message-generate-headers-first
'(references)
789 "Which headers should be generated before starting to compose a message.
790 If t, generate all required headers. This can also be a list of headers to
791 generate. The variables `message-required-news-headers' and
792 `message-required-mail-headers' specify which headers to generate.
794 Note that the variable `message-deletable-headers' specifies headers which
795 are to be deleted and then re-generated before sending, so this variable
796 will not have a visible effect for those headers."
797 :group
'message-headers
798 :link
'(custom-manual "(message)Message Headers")
799 :type
'(choice (const :tag
"None" nil
)
800 (const :tag
"References" '(references))
802 (repeat (sexp :tag
"Header"))))
804 (defcustom message-setup-hook nil
805 "Normal hook, run each time a new outgoing message is initialized.
806 The function `message-setup' runs this hook."
807 :group
'message-various
808 :link
'(custom-manual "(message)Various Message Variables")
811 (defcustom message-cancel-hook nil
812 "Hook run when cancelling articles."
813 :group
'message-various
814 :link
'(custom-manual "(message)Various Message Variables")
817 (defcustom message-signature-setup-hook nil
818 "Normal hook, run each time a new outgoing message is initialized.
819 It is run after the headers have been inserted and before
820 the signature is inserted."
821 :group
'message-various
822 :link
'(custom-manual "(message)Various Message Variables")
825 (defcustom message-mode-hook nil
826 "Hook run in message mode buffers."
827 :group
'message-various
830 (defcustom message-header-hook nil
831 "Hook run in a message mode buffer narrowed to the headers."
832 :group
'message-various
835 (defcustom message-header-setup-hook nil
836 "Hook called narrowed to the headers when setting up a message buffer."
837 :group
'message-various
838 :link
'(custom-manual "(message)Various Message Variables")
841 (defcustom message-minibuffer-local-map
842 (let ((map (make-sparse-keymap 'message-minibuffer-local-map
)))
843 (set-keymap-parent map minibuffer-local-map
)
845 "Keymap for `message-read-from-minibuffer'."
847 :group
'message-various
)
850 (defcustom message-citation-line-function
'message-insert-citation-line
851 "*Function called to insert the \"Whomever writes:\" line.
853 Note that Gnus provides a feature where the reader can click on
854 `writes:' to hide the cited text. If you change this line too much,
855 people who read your message will have to change their Gnus
856 configuration. See the variable `gnus-cite-attribution-suffix'."
858 :link
'(custom-manual "(message)Insertion Variables")
859 :group
'message-insertion
)
862 (defcustom message-yank-prefix
"> "
863 "*Prefix inserted on the lines of yanked messages.
864 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
865 See also `message-yank-cited-prefix'."
867 :link
'(custom-manual "(message)Insertion Variables")
868 :group
'message-insertion
)
870 (defcustom message-yank-cited-prefix
">"
871 "*Prefix inserted on cited or empty lines of yanked messages.
872 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
873 See also `message-yank-prefix'."
876 :link
'(custom-manual "(message)Insertion Variables")
877 :group
'message-insertion
)
879 (defcustom message-indentation-spaces
3
880 "*Number of spaces to insert at the beginning of each cited line.
881 Used by `message-yank-original' via `message-yank-cite'."
882 :group
'message-insertion
883 :link
'(custom-manual "(message)Insertion Variables")
887 (defcustom message-cite-function
'message-cite-original
888 "*Function for citing an original message.
889 Predefined functions include `message-cite-original' and
890 `message-cite-original-without-signature'.
891 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
892 :type
'(radio (function-item message-cite-original
)
893 (function-item message-cite-original-without-signature
)
894 (function-item sc-cite-original
)
895 (function :tag
"Other"))
896 :link
'(custom-manual "(message)Insertion Variables")
897 :group
'message-insertion
)
900 (defcustom message-indent-citation-function
'message-indent-citation
901 "*Function for modifying a citation just inserted in the mail buffer.
902 This can also be a list of functions. Each function can find the
903 citation between (point) and (mark t). And each function should leave
904 point and mark around the citation text as modified."
906 :link
'(custom-manual "(message)Insertion Variables")
907 :group
'message-insertion
)
910 (defcustom message-signature t
911 "*String to be inserted at the end of the message buffer.
912 If t, the `message-signature-file' file will be inserted instead.
913 If a function, the result from the function will be used instead.
914 If a form, the result from the form will be used instead."
916 :link
'(custom-manual "(message)Insertion Variables")
917 :group
'message-insertion
)
920 (defcustom message-signature-file
"~/.signature"
921 "*Name of file containing the text inserted at end of message buffer.
922 Ignored if the named file doesn't exist.
923 If nil, don't insert a signature."
924 :type
'(choice file
(const :tags
"None" nil
))
925 :link
'(custom-manual "(message)Insertion Variables")
926 :group
'message-insertion
)
929 (defcustom message-signature-insert-empty-line t
930 "*If non-nil, insert an empty line before the signature separator."
933 :link
'(custom-manual "(message)Insertion Variables")
934 :group
'message-insertion
)
936 (defcustom message-distribution-function nil
937 "*Function called to return a Distribution header."
939 :group
'message-headers
940 :link
'(custom-manual "(message)News Headers")
941 :type
'(choice function
(const nil
)))
943 (defcustom message-expires
14
944 "Number of days before your article expires."
946 :group
'message-headers
947 :link
'(custom-manual "(message)News Headers")
950 (defcustom message-user-path nil
951 "If nil, use the NNTP server name in the Path header.
952 If stringp, use this; if non-nil, use no host name (user name only)."
954 :group
'message-headers
955 :link
'(custom-manual "(message)News Headers")
956 :type
'(choice (const :tag
"nntp" nil
)
958 (sexp :tag
"none" :format
"%t" t
)))
960 (defvar message-reply-buffer nil
)
961 (defvar message-reply-headers nil
962 "The headers of the current replied article.
963 It is a vector of the following headers:
964 \[number subject from date id references chars lines xref extra].")
965 (defvar message-newsreader nil
)
966 (defvar message-mailer nil
)
967 (defvar message-sent-message-via nil
)
968 (defvar message-checksum nil
)
969 (defvar message-send-actions nil
970 "A list of actions to be performed upon successful sending of a message.")
971 (defvar message-exit-actions nil
972 "A list of actions to be performed upon exiting after sending a message.")
973 (defvar message-kill-actions nil
974 "A list of actions to be performed before killing a message buffer.")
975 (defvar message-postpone-actions nil
976 "A list of actions to be performed after postponing a message.")
978 (define-widget 'message-header-lines
'text
979 "All header lines must be LFD terminated."
980 :format
"%{%t%}:%n%v"
982 :error
"All header lines must be newline terminated")
984 (defcustom message-default-headers
""
985 "*A string containing header lines to be inserted in outgoing messages.
986 It is inserted before you edit the message, so you can edit or delete
988 :group
'message-headers
989 :link
'(custom-manual "(message)Message Headers")
990 :type
'message-header-lines
)
992 (defcustom message-default-mail-headers
""
993 "*A string of header lines to be inserted in outgoing mails."
994 :group
'message-headers
996 :link
'(custom-manual "(message)Mail Headers")
997 :type
'message-header-lines
)
999 (defcustom message-default-news-headers
""
1000 "*A string of header lines to be inserted in outgoing news articles."
1001 :group
'message-headers
1002 :group
'message-news
1003 :link
'(custom-manual "(message)News Headers")
1004 :type
'message-header-lines
)
1006 ;; Note: could use /usr/ucb/mail instead of sendmail;
1007 ;; options -t, and -v if not interactive.
1008 (defcustom message-mailer-swallows-blank-line
1009 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1010 system-configuration
)
1011 (file-readable-p "/etc/sendmail.cf")
1012 (let ((buffer (get-buffer-create " *temp*")))
1016 (insert-file-contents "/etc/sendmail.cf")
1017 (goto-char (point-min))
1018 (let ((case-fold-search nil
))
1019 (re-search-forward "^OR\\>" nil t
)))
1020 (kill-buffer buffer
))))
1021 ;; According to RFC822, "The field-name must be composed of printable
1022 ;; ASCII characters (i. e., characters that have decimal values between
1023 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1025 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1026 "*Set this non-nil if the system's mailer runs the header and body together.
1027 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1028 The value should be an expression to test whether the problem will
1030 :group
'message-sending
1031 :link
'(custom-manual "(message)Mail Variables")
1035 (define-mail-user-agent 'message-user-agent
1036 'message-mail
'message-send-and-exit
1037 'message-kill-buffer
'message-send-hook
)
1039 (defvar message-mh-deletable-headers
'(Message-ID Date Lines Sender
)
1040 "If non-nil, delete the deletable headers before feeding to mh.")
1042 (defvar message-send-method-alist
1043 '((news message-news-p message-send-via-news
)
1044 (mail message-mail-p message-send-via-mail
))
1045 "Alist of ways to send outgoing messages.
1046 Each element has the form
1048 \(TYPE PREDICATE FUNCTION)
1050 where TYPE is a symbol that names the method; PREDICATE is a function
1051 called without any parameters to determine whether the message is
1052 a message of type TYPE; and FUNCTION is a function to be called if
1053 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1056 (defcustom message-mail-alias-type
'abbrev
1057 "*What alias expansion type to use in Message buffers.
1058 The default is `abbrev', which uses mailabbrev. nil switches
1061 :link
'(custom-manual "(message)Mail Aliases")
1062 :type
'(choice (const :tag
"Use Mailabbrev" abbrev
)
1063 (const :tag
"No expansion" nil
)))
1065 (defcustom message-auto-save-directory
1066 (file-name-as-directory (nnheader-concat message-directory
"drafts"))
1067 "*Directory where Message auto-saves buffers if Gnus isn't running.
1068 If nil, Message won't auto-save."
1069 :group
'message-buffers
1070 :link
'(custom-manual "(message)Various Message Variables")
1071 :type
'(choice directory
(const :tag
"Don't auto-save" nil
)))
1073 (defcustom message-default-charset
1074 (and (not (mm-multibyte-p)) 'iso-8859-1
)
1075 "Default charset used in non-MULE Emacsen.
1076 If nil, you might be asked to input the charset."
1079 :link
'(custom-manual "(message)Various Message Variables")
1082 (defcustom message-dont-reply-to-names
1083 (and (boundp 'rmail-dont-reply-to-names
) rmail-dont-reply-to-names
)
1084 "*A regexp specifying addresses to prune when doing wide replies.
1085 A value of nil means exclude your own user name only."
1088 :link
'(custom-manual "(message)Wide Reply")
1089 :type
'(choice (const :tag
"Yourself" nil
)
1092 (defvar message-shoot-gnksa-feet nil
1093 "*A list of GNKSA feet you are allowed to shoot.
1094 Gnus gives you all the opportunity you could possibly want for
1095 shooting yourself in the foot. Also, Gnus allows you to shoot the
1096 feet of Good Net-Keeping Seal of Approval. The following are foot
1098 `empty-article' Allow you to post an empty article;
1099 `quoted-text-only' Allow you to post quoted text only;
1100 `multiple-copies' Allow you to post multiple copies;
1101 `cancel-messages' Allow you to cancel or supersede messages from
1102 your other email addresses.")
1104 (defsubst message-gnksa-enable-p
(feature)
1105 (or (not (listp message-shoot-gnksa-feet
))
1106 (memq feature message-shoot-gnksa-feet
)))
1108 (defcustom message-hidden-headers nil
1109 "Regexp of headers to be hidden when composing new messages.
1110 This can also be a list of regexps to match headers. Or a list
1111 starting with `not' and followed by regexps."
1114 :link
'(custom-manual "(message)Message Headers")
1115 :type
'(repeat regexp
))
1117 ;;; Internal variables.
1118 ;;; Well, not really internal.
1120 (defvar message-mode-syntax-table
1121 (let ((table (copy-syntax-table text-mode-syntax-table
)))
1122 (modify-syntax-entry ?%
". " table
)
1123 (modify-syntax-entry ?
> ". " table
)
1124 (modify-syntax-entry ?
< ". " table
)
1126 "Syntax table used while in Message mode.")
1128 (defface message-header-to
1131 (:foreground
"green2" :bold t
))
1134 (:foreground
"MidnightBlue" :bold t
))
1136 (:bold t
:italic t
)))
1137 "Face used for displaying From headers."
1138 :group
'message-faces
)
1139 ;; backward-compatibility alias
1140 (put 'message-header-to-face
'face-alias
'message-header-to
)
1142 (defface message-header-cc
1145 (:foreground
"green4" :bold t
))
1148 (:foreground
"MidnightBlue"))
1151 "Face used for displaying Cc headers."
1152 :group
'message-faces
)
1153 ;; backward-compatibility alias
1154 (put 'message-header-cc-face
'face-alias
'message-header-cc
)
1156 (defface message-header-subject
1159 (:foreground
"green3"))
1162 (:foreground
"navy blue" :bold t
))
1165 "Face used for displaying subject headers."
1166 :group
'message-faces
)
1167 ;; backward-compatibility alias
1168 (put 'message-header-subject-face
'face-alias
'message-header-subject
)
1170 (defface message-header-newsgroups
1173 (:foreground
"yellow" :bold t
:italic t
))
1176 (:foreground
"blue4" :bold t
:italic t
))
1178 (:bold t
:italic t
)))
1179 "Face used for displaying newsgroups headers."
1180 :group
'message-faces
)
1181 ;; backward-compatibility alias
1182 (put 'message-header-newsgroups-face
'face-alias
'message-header-newsgroups
)
1184 (defface message-header-other
1187 (:foreground
"#b00000"))
1190 (:foreground
"steel blue"))
1192 (:bold t
:italic t
)))
1193 "Face used for displaying newsgroups headers."
1194 :group
'message-faces
)
1195 ;; backward-compatibility alias
1196 (put 'message-header-other-face
'face-alias
'message-header-other
)
1198 (defface message-header-name
1201 (:foreground
"DarkGreen"))
1204 (:foreground
"cornflower blue"))
1207 "Face used for displaying header names."
1208 :group
'message-faces
)
1209 ;; backward-compatibility alias
1210 (put 'message-header-name-face
'face-alias
'message-header-name
)
1212 (defface message-header-xheader
1215 (:foreground
"blue"))
1218 (:foreground
"blue"))
1221 "Face used for displaying X-Header headers."
1222 :group
'message-faces
)
1223 ;; backward-compatibility alias
1224 (put 'message-header-xheader-face
'face-alias
'message-header-xheader
)
1226 (defface message-separator
1229 (:foreground
"blue3"))
1232 (:foreground
"brown"))
1235 "Face used for displaying the separator."
1236 :group
'message-faces
)
1237 ;; backward-compatibility alias
1238 (put 'message-separator-face
'face-alias
'message-separator
)
1240 (defface message-cited-text
1243 (:foreground
"red"))
1246 (:foreground
"red"))
1249 "Face used for displaying cited text names."
1250 :group
'message-faces
)
1251 ;; backward-compatibility alias
1252 (put 'message-cited-text-face
'face-alias
'message-cited-text
)
1254 (defface message-mml
1257 (:foreground
"ForestGreen"))
1260 (:foreground
"ForestGreen"))
1263 "Face used for displaying MML."
1264 :group
'message-faces
)
1265 ;; backward-compatibility alias
1266 (put 'message-mml-face
'face-alias
'message-mml
)
1268 (defun message-font-lock-make-header-matcher (regexp)
1271 (let ((start (point)))
1274 (goto-char (point-min))
1275 (if (re-search-forward
1276 (concat "^" (regexp-quote mail-header-separator
) "$")
1278 (setq limit
(min limit
(match-beginning 0))))
1280 (and (< start limit
)
1281 (re-search-forward ,regexp limit t
))))))
1282 (if (featurep 'bytecomp
)
1286 (defvar message-font-lock-keywords
1287 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1288 `((,(message-font-lock-make-header-matcher
1289 (concat "^\\([Tt]o:\\)" content
))
1290 (1 'message-header-name
)
1291 (2 'message-header-to nil t
))
1292 (,(message-font-lock-make-header-matcher
1293 (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content
))
1294 (1 'message-header-name
)
1295 (2 'message-header-cc nil t
))
1296 (,(message-font-lock-make-header-matcher
1297 (concat "^\\([Ss]ubject:\\)" content
))
1298 (1 'message-header-name
)
1299 (2 'message-header-subject nil t
))
1300 (,(message-font-lock-make-header-matcher
1301 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content
))
1302 (1 'message-header-name
)
1303 (2 'message-header-newsgroups nil t
))
1304 (,(message-font-lock-make-header-matcher
1305 (concat "^\\([A-Z][^: \n\t]+:\\)" content
))
1306 (1 'message-header-name
)
1307 (2 'message-header-other nil t
))
1308 (,(message-font-lock-make-header-matcher
1309 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content
))
1310 (1 'message-header-name
)
1311 (2 'message-header-name
))
1312 ,@(if (and mail-header-separator
1313 (not (equal mail-header-separator
"")))
1314 `((,(concat "^\\(" (regexp-quote mail-header-separator
) "\\)$")
1315 1 'message-separator
))
1318 (re-search-forward (concat "^\\("
1319 message-cite-prefix-regexp
1322 (0 'message-cited-text
))
1323 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1325 "Additional expressions to highlight in Message mode.")
1328 ;; XEmacs does it like this. For Emacs, we have to set the
1329 ;; `font-lock-defaults' buffer-local variable.
1330 (put 'message-mode
'font-lock-defaults
'(message-font-lock-keywords t
))
1332 (defvar message-face-alist
1333 '((bold . bold-region
)
1334 (underline . underline-region
)
1335 (default .
(lambda (b e
)
1337 (ununderline-region b e
))))
1338 "Alist of mail and news faces for facemenu.
1339 The cdr of each entry is a function for applying the face to a region.")
1341 (defcustom message-send-hook nil
1342 "Hook run before sending messages.
1343 This hook is run quite early when sending."
1344 :group
'message-various
1345 :options
'(ispell-message)
1346 :link
'(custom-manual "(message)Various Message Variables")
1349 (defcustom message-send-mail-hook nil
1350 "Hook run before sending mail messages.
1351 This hook is run very late -- just before the message is sent as
1353 :group
'message-various
1354 :link
'(custom-manual "(message)Various Message Variables")
1357 (defcustom message-send-news-hook nil
1358 "Hook run before sending news messages.
1359 This hook is run very late -- just before the message is sent as
1361 :group
'message-various
1362 :link
'(custom-manual "(message)Various Message Variables")
1365 (defcustom message-sent-hook nil
1366 "Hook run after sending messages."
1367 :group
'message-various
1370 (defvar message-send-coding-system
'binary
1371 "Coding system to encode outgoing mail.")
1373 (defvar message-draft-coding-system
1374 mm-auto-save-coding-system
1375 "*Coding system to compose mail.
1376 If you'd like to make it possible to share draft files between XEmacs
1377 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1378 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1380 (defcustom message-send-mail-partially-limit
1000000
1381 "The limitation of messages sent as message/partial.
1382 The lower bound of message size in characters, beyond which the message
1383 should be sent in several parts. If it is nil, the size is unlimited."
1385 :group
'message-buffers
1386 :link
'(custom-manual "(message)Mail Variables")
1387 :type
'(choice (const :tag
"unlimited" nil
)
1390 (defcustom message-alternative-emails nil
1391 "*Regexp matching alternative email addresses.
1392 The first address in the To, Cc or From headers of the original
1393 article matching this variable is used as the From field of
1396 This variable has precedence over posting styles and anything that runs
1397 off `message-setup-hook'."
1398 :group
'message-headers
1399 :link
'(custom-manual "(message)Message Headers")
1400 :type
'(choice (const :tag
"Always use primary" nil
)
1403 (defcustom message-hierarchical-addresses nil
1404 "A list of hierarchical mail address definitions.
1406 Inside each entry, the first address is the \"top\" address, and
1407 subsequent addresses are subaddresses; this is used to indicate that
1408 mail sent to the first address will automatically be delivered to the
1409 subaddresses. So if the first address appears in the recipient list
1410 for a message, the subaddresses will be removed (if present) before
1411 the mail is sent. All addresses in this structure should be
1414 :group
'message-headers
1415 :type
'(repeat (repeat string
)))
1417 (defcustom message-mail-user-agent nil
1418 "Like `mail-user-agent'.
1419 Except if it is nil, use Gnus native MUA; if it is t, use
1422 :type
'(radio (const :tag
"Gnus native"
1425 (const :tag
"`mail-user-agent'"
1428 (function-item :tag
"Default Emacs mail"
1430 sendmail-user-agent
)
1431 (function-item :tag
"Emacs interface to MH"
1434 (function :tag
"Other"))
1438 (defcustom message-wide-reply-confirm-recipients nil
1439 "Whether to confirm a wide reply to multiple email recipients.
1440 If this variable is nil, don't ask whether to reply to all recipients.
1441 If this variable is non-nil, pose the question \"Reply to all
1442 recipients?\" before a wide reply to multiple recipients. If the user
1443 answers yes, reply to all recipients as usual. If the user answers
1444 no, only reply back to the author."
1446 :group
'message-headers
1447 :link
'(custom-manual "(message)Wide Reply")
1450 (defcustom message-user-fqdn nil
1451 "*Domain part of Message-Ids."
1453 :group
'message-headers
1454 :link
'(custom-manual "(message)News Headers")
1455 :type
'(radio (const :format
"%v " nil
)
1456 (string :format
"FQDN: %v")))
1458 (defcustom message-use-idna
(and (condition-case nil
(require 'idna
)
1460 (mm-coding-system-p 'utf-8
)
1461 (executable-find idna-program
)
1462 (string= (idna-to-ascii "räksmörgås")
1463 "xn--rksmrgs-5wao1o")
1465 "Whether to encode non-ASCII in domain names into ASCII according to IDNA.
1466 GNU Libidn, and in particular the elisp package \"idna.el\" and
1467 the external program \"idn\", must be installed for this
1468 functionality to work."
1470 :group
'message-headers
1471 :link
'(custom-manual "(message)IDNA")
1472 :type
'(choice (const :tag
"Ask" ask
)
1473 (const :tag
"Never" nil
)
1474 (const :tag
"Always" t
)))
1476 ;;; Internal variables.
1478 (defvar message-sending-message
"Sending...")
1479 (defvar message-buffer-list nil
)
1480 (defvar message-this-is-news nil
)
1481 (defvar message-this-is-mail nil
)
1482 (defvar message-draft-article nil
)
1483 (defvar message-mime-part nil
)
1484 (defvar message-posting-charset nil
)
1485 (defvar message-inserted-headers nil
)
1487 ;; Byte-compiler warning
1489 (defvar gnus-active-hashtb
)
1490 (defvar gnus-read-active-file
))
1492 ;;; Regexp matching the delimiter of messages in UNIX mail format
1493 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1494 ;;; of rmail.el's rmail-unix-mail-delimiter.
1495 (defvar message-unix-mail-delimiter
1496 (let ((time-zone-regexp
1497 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1498 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1504 ;; Many things can happen to an RFC 822 mailbox before it is put into
1505 ;; a `From' line. The leading phrase can be stripped, e.g.
1506 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1507 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1508 ;; can be removed, e.g.
1509 ;; From: joe@y.z (Joe K
1511 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1514 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1515 ;; The mailbox can be removed or be replaced by white space, e.g.
1516 ;; From: "Joe User"{space}{tab}
1518 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1519 ;; where {space} and {tab} represent the Ascii space and tab characters.
1520 ;; We want to match the results of any of these manglings.
1521 ;; The following regexp rejects names whose first characters are
1522 ;; obviously bogus, but after that anything goes.
1523 "\\([^\0-\b\n-\r\^?].*\\)?"
1525 ;; The time the message was sent.
1526 "\\([^\0-\r \^?]+\\) +" ; day of the week
1527 "\\([^\0-\r \^?]+\\) +" ; month
1528 "\\([0-3]?[0-9]\\) +" ; day of month
1529 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1531 ;; Perhaps a time zone, specified by an abbreviation, or by a
1536 " \\([0-9][0-9]+\\) *"
1538 ;; On some systems the time zone can appear after the year, too.
1542 "\\(remote from .*\\)?"
1545 "Regexp matching the delimiter of messages in UNIX mail format.")
1547 (defvar message-unsent-separator
1548 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1549 "^ *---+ +Returned message +---+ *$\\|"
1550 "^Start of returned message$\\|"
1551 "^ *---+ +Original message +---+ *$\\|"
1552 "^ *--+ +begin message +--+ *$\\|"
1553 "^ *---+ +Original message follows +---+ *$\\|"
1554 "^ *---+ +Undelivered message follows +---+ *$\\|"
1555 "^|? *---+ +Message text follows: +---+ *|?$")
1556 "A regexp that matches the separator before the text of a failed message.")
1558 (defvar message-header-format-alist
1560 (To . message-fill-address
)
1561 (Cc . message-fill-address
)
1572 (References . message-shorten-references
)
1574 "Alist used for formatting headers.")
1576 (defvar message-options nil
1577 "Some saved answers when sending message.")
1579 (defvar message-send-mail-real-function nil
1580 "Internal send mail function.")
1582 (defvar message-bogus-system-names
"^localhost\\.\\|\\.local$"
1583 "The regexp of bogus system names.")
1585 (defcustom message-valid-fqdn-regexp
1586 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1588 "\\([a-z][a-z]\\|" ;; two letter country TDLs
1589 "aero\\|arpa\\|bitnet\\|biz\\|bofh\\|"
1590 "cat\\|com\\|coop\\|edu\\|gov\\|"
1591 "info\\|int\\|jobs\\|"
1592 "mil\\|mobi\\|museum\\|name\\|net\\|"
1593 "org\\|pro\\|travel\\|uucp\\)")
1594 ;; http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains
1595 ;; http://en.wikipedia.org/wiki/GTLD
1596 ;; `in the process of being approved': .asia .post .tel .sex
1597 ;; "dead" nato bitnet uucp
1598 "Regular expression that matches a valid FQDN."
1599 ;; see also: gnus-button-valid-fqdn-regexp
1601 :group
'message-headers
1605 (autoload 'idna-to-ascii
"idna")
1606 (autoload 'message-setup-toolbar
"messagexmas")
1607 (autoload 'mh-new-draft-name
"mh-comp")
1608 (autoload 'mh-send-letter
"mh-comp")
1609 (autoload 'gnus-point-at-eol
"gnus-util")
1610 (autoload 'gnus-point-at-bol
"gnus-util")
1611 (autoload 'gnus-output-to-rmail
"gnus-util")
1612 (autoload 'gnus-output-to-mail
"gnus-util")
1613 (autoload 'nndraft-request-associate-buffer
"nndraft")
1614 (autoload 'nndraft-request-expire-articles
"nndraft")
1615 (autoload 'gnus-open-server
"gnus-int")
1616 (autoload 'gnus-request-post
"gnus-int")
1617 (autoload 'gnus-alive-p
"gnus-util")
1618 (autoload 'gnus-server-string
"gnus")
1619 (autoload 'gnus-group-name-charset
"gnus-group")
1620 (autoload 'gnus-group-name-decode
"gnus-group")
1621 (autoload 'gnus-groups-from-server
"gnus")
1622 (autoload 'rmail-output
"rmailout")
1623 (autoload 'gnus-delay-article
"gnus-delay")
1624 (autoload 'gnus-make-local-hook
"gnus-util")
1625 (autoload 'gnus-extract-address-components
"gnus-util"))
1630 ;;; Utility functions.
1633 (defmacro message-y-or-n-p
(question show
&rest text
)
1634 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1635 `(message-talkative-question 'y-or-n-p
,question
,show
,@text
))
1637 (defmacro message-delete-line
(&optional n
)
1638 "Delete the current line (and the next N lines)."
1639 `(delete-region (progn (beginning-of-line) (point))
1640 (progn (forward-line ,(or n
1)) (point))))
1642 (defun message-mark-active-p ()
1643 "Non-nil means the mark and region are currently active in this buffer."
1646 (defun message-unquote-tokens (elems)
1647 "Remove double quotes (\") from strings in list ELEMS."
1648 (mapcar (lambda (item)
1649 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item
)
1650 (setq item
(concat (match-string 1 item
)
1651 (match-string 2 item
))))
1655 (defun message-tokenize-header (header &optional separator
)
1656 "Split HEADER into a list of header elements.
1657 SEPARATOR is a string of characters to be used as separators. \",\"
1658 is used by default."
1661 (let ((regexp (format "[%s]+" (or separator
",")))
1663 beg quoted elems paren
)
1665 (mm-enable-multibyte)
1666 (setq beg
(point-min))
1668 (goto-char (point-min))
1673 (cond ((and (> (point) beg
)
1675 (and (looking-at regexp
)
1678 (push (buffer-substring beg
(point)) elems
)
1679 (setq beg
(match-end 0)))
1680 ((eq (char-after) ?
\")
1681 (setq quoted
(not quoted
)))
1682 ((and (eq (char-after) ?\
()
1685 ((and (eq (char-after) ?\
))
1688 (nreverse elems
)))))
1690 (defun message-mail-file-mbox-p (file)
1691 "Say whether FILE looks like a Unix mbox file."
1692 (when (and (file-exists-p file
)
1693 (file-readable-p file
)
1694 (file-regular-p file
))
1696 (nnheader-insert-file-contents file
)
1697 (goto-char (point-min))
1698 (looking-at message-unix-mail-delimiter
))))
1700 (defun message-fetch-field (header &optional not-all
)
1701 "The same as `mail-fetch-field', only remove all newlines.
1702 The buffer is expected to be narrowed to just the header of the message;
1703 see `message-narrow-to-headers-or-head'."
1704 (let* ((inhibit-point-motion-hooks t
)
1705 (case-fold-search t
)
1706 (value (mail-fetch-field header nil
(not not-all
))))
1708 (while (string-match "\n[\t ]+" value
)
1709 (setq value
(replace-match " " t t value
)))
1710 (set-text-properties 0 (length value
) nil value
)
1713 (defun message-field-value (header &optional not-all
)
1714 "The same as `message-fetch-field', only narrow to the headers first."
1717 (message-narrow-to-headers-or-head)
1718 (message-fetch-field header not-all
))))
1720 (defun message-narrow-to-field ()
1721 "Narrow the buffer to the header on the current line."
1727 (if (re-search-forward "^[^ \n\t]" nil t
)
1732 (goto-char (point-min)))
1734 (defun message-add-header (&rest headers
)
1735 "Add the HEADERS to the message header, skipping those already present."
1738 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers
))
1739 (error "Invalid header `%s'" (car headers
)))
1740 (setq hclean
(match-string 1 (car headers
)))
1742 (message-narrow-to-headers)
1743 (unless (re-search-forward (concat "^" (regexp-quote hclean
) ":") nil t
)
1744 (goto-char (point-max))
1745 (if (string-match "\n$" (car headers
))
1746 (insert (car headers
))
1747 (insert (car headers
) ?
\n)))))
1748 (setq headers
(cdr headers
))))
1750 (defmacro message-with-reply-buffer
(&rest forms
)
1751 "Evaluate FORMS in the reply buffer, if it exists."
1752 `(when (and message-reply-buffer
1753 (buffer-name message-reply-buffer
))
1755 (set-buffer message-reply-buffer
)
1758 (put 'message-with-reply-buffer
'lisp-indent-function
0)
1759 (put 'message-with-reply-buffer
'edebug-form-spec
'(body))
1761 (defun message-fetch-reply-field (header)
1762 "Fetch field HEADER from the message we're replying to."
1763 (message-with-reply-buffer
1765 (mail-narrow-to-head)
1766 (message-fetch-field header
))))
1768 (defun message-strip-list-identifiers (subject)
1769 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1770 (require 'gnus-sum
) ; for gnus-list-identifiers
1771 (let ((regexp (if (stringp gnus-list-identifiers
)
1772 gnus-list-identifiers
1773 (mapconcat 'identity gnus-list-identifiers
" *\\|"))))
1774 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1775 " *\\)\\)+\\(Re: +\\)?\\)") subject
)
1776 (concat (substring subject
0 (match-beginning 1))
1777 (or (match-string 3 subject
)
1778 (match-string 5 subject
))
1783 (defun message-strip-subject-re (subject)
1784 "Remove \"Re:\" from subject lines in string SUBJECT."
1785 (if (string-match message-subject-re-regexp subject
)
1786 (substring subject
(match-end 0))
1789 (defcustom message-replacement-char
"."
1790 "Replacement character used instead of unprintable or not decodable chars."
1791 :group
'message-various
1792 :version
"22.1" ;; Gnus 5.10.9
1793 :type
'(choice string
1797 ;; FIXME: We also should call `message-strip-subject-encoded-words'
1798 ;; when forwarding. Probably in `message-make-forward-subject' and
1799 ;; `message-forward-make-body'.
1801 (defun message-strip-subject-encoded-words (subject)
1802 "Fix non-decodable words in SUBJECT."
1803 ;; Cf. `gnus-simplify-subject-fully'.
1804 (let* ((case-fold-search t
)
1805 (replacement-chars (format "[%s%s%s]"
1806 message-replacement-char
1807 message-replacement-char
1808 message-replacement-char
))
1809 (enc-word-re "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?\\([^?]+\\)\\(\\?=\\)")
1814 (goto-char (point-min))
1815 (when (re-search-forward enc-word-re nil t
)
1816 (setq cs-string
(match-string 1)))))
1817 cs-coding q-or-b word-beg word-end
)
1818 (if (or (not have-marker
) ;; No encoded word found...
1819 ;; ... or double encoding was correct:
1820 (and (stringp cs-string
)
1821 (setq cs-string
(downcase cs-string
))
1822 (mm-coding-system-p (intern cs-string
))
1826 Decoded Subject \"%s\"
1827 contains a valid encoded word. Decode again? "
1829 (setq cs-coding
(intern cs-string
))))))
1833 (goto-char (point-min))
1834 (while (re-search-forward enc-word-re nil t
)
1835 (setq cs-string
(downcase (match-string 1))
1836 q-or-b
(match-string 2)
1837 word-beg
(match-beginning 0)
1838 word-end
(match-end 0))
1840 (if (mm-coding-system-p (intern cs-string
))
1841 (setq cs-coding
(intern cs-string
))
1843 ;; No double encoded subject? => bogus charset.
1846 (mm-read-coding-system
1848 Decoded Subject \"%s\"
1849 contains an encoded word. The charset `%s' is unknown or invalid.
1850 Hit RET to replace non-decodable characters with \"%s\" or enter replacement
1852 subject cs-string message-replacement-char
)))
1854 (replace-match (concat "=?" (symbol-name cs-coding
)
1857 (goto-char word-beg
)
1858 (re-search-forward "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?" word-end t
)
1861 (if (string-match "\\`Q\\'" q-or-b
)
1864 (message "Replacing non-decodable characters with \"%s\"."
1865 message-replacement-char
)
1866 (while (re-search-forward "\\(=[A-F0-9][A-F0-9]\\)+"
1868 (replace-match message-replacement-char
)))
1870 (message "Replacing non-decodable characters with \"%s\"."
1872 (re-search-forward "[^?]+" word-end t
)
1873 (replace-match replacement-chars
))
1874 (re-search-forward "\\?=")
1875 (replace-match "")))))
1876 (rfc2047-decode-region (point-min) (point-max))
1879 ;;; Start of functions adopted from `message-utils.el'.
1881 (defun message-strip-subject-trailing-was (subject)
1882 "Remove trailing \"(was: <old subject>)\" from SUBJECT lines.
1883 Leading \"Re: \" is not stripped by this function. Use the function
1884 `message-strip-subject-re' for this."
1885 (let* ((query message-subject-trailing-was-query
)
1890 message-subject-trailing-was-ask-regexp
1891 message-subject-trailing-was-regexp
)
1894 (setq new
(substring subject
0 (match-beginning 0))))
1895 (if (or (not found
) (eq query nil
))
1898 (if (message-y-or-n-p
1899 "Strip `(was: <old subject>)' in subject? " t
1901 "Strip `(was: <old subject>)' in subject "
1902 "and use the new one instead?\n\n"
1903 "Current subject is: \""
1905 "New subject would be: \""
1907 "See the variable `message-subject-trailing-was-query' "
1908 "to get rid of this query."
1913 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
1915 (defun message-change-subject (new-subject)
1916 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
1917 ;; <URL:http://www.landfield.com/usefor/drafts/draft-ietf-usefor-useage--1.02.unpaged>
1920 (read-from-minibuffer "New subject: ")))
1921 (cond ((and (not (or (null new-subject
) ; new subject not empty
1922 (zerop (string-width new-subject
))
1923 (string-match "^[ \t]*$" new-subject
))))
1927 (message-narrow-to-headers)
1928 (message-fetch-field "Subject"))))
1929 (cond ((not old-subject
)
1930 (error "No current subject"))
1933 (regexp-quote new-subject
)
1935 old-subject
)) ; yes, it really is a new subject
1936 ;; delete eventual Re: prefix
1938 (message-strip-subject-re old-subject
))
1939 (message-goto-subject)
1940 (message-delete-line)
1941 (insert (concat "Subject: "
1944 old-subject
")\n")))))))))
1946 (defun message-mark-inserted-region (beg end
)
1947 "Mark some region in the current article with enclosing tags.
1948 See `message-mark-insert-begin' and `message-mark-insert-end'."
1951 ;; add to the end of the region first, otherwise end would be invalid
1953 (insert message-mark-insert-end
)
1955 (insert message-mark-insert-begin
)))
1957 (defun message-mark-insert-file (file)
1958 "Insert FILE at point, marking it with enclosing tags.
1959 See `message-mark-insert-begin' and `message-mark-insert-end'."
1960 (interactive "fFile to insert: ")
1961 ;; reverse insertion to get correct result.
1963 (insert message-mark-insert-end
)
1965 (insert-file-contents file
)
1967 (insert message-mark-insert-begin
)))
1969 (defun message-add-archive-header ()
1970 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
1971 The note can be customized using `message-archive-note'. When called with a
1972 prefix argument, ask for a text to insert. If you don't want the note in the
1973 body, set `message-archive-note' to nil."
1975 (if current-prefix-arg
1976 (setq message-archive-note
1977 (read-from-minibuffer "Reason for No-Archive: "
1978 (cons message-archive-note
0))))
1980 (if (message-goto-signature)
1981 (re-search-backward message-signature-separator
))
1982 (when message-archive-note
1983 (insert message-archive-note
)
1985 (message-add-header message-archive-header
)
1986 (message-sort-headers)))
1988 (defun message-cross-post-followup-to-header (target-group)
1989 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
1990 With prefix-argument just set Follow-Up, don't cross-post."
1992 (list ; Completion based on Gnus
1993 (completing-read "Followup To: "
1994 (if (boundp 'gnus-newsrc-alist
)
1996 nil nil
'("poster" .
0)
1997 (if (boundp 'gnus-group-history
)
1998 'gnus-group-history
))))
1999 (message-remove-header "Follow[Uu]p-[Tt]o" t
)
2000 (message-goto-newsgroups)
2002 ;; if we already did a crosspost before, kill old target
2003 (if (and message-cross-post-old-target
2005 (regexp-quote (concat "," message-cross-post-old-target
))
2008 ;; unless (followup is to poster or user explicitly asked not
2009 ;; to cross-post, or target-group is already in Newsgroups)
2010 ;; add target-group to Newsgroups line.
2012 ;; def: cross-post, req:no
2013 (and message-cross-post-default
(not current-prefix-arg
))
2014 ;; def: no-cross-post, req:yes
2015 (and (not message-cross-post-default
) current-prefix-arg
))
2016 (not (string-match "poster" target-group
))
2017 (not (string-match (regexp-quote target-group
)
2018 (message-fetch-field "Newsgroups"))))
2020 (insert (concat "," target-group
))))
2021 (end-of-line) ; ensure Followup: comes after Newsgroups:
2022 ;; unless new followup would be identical to Newsgroups line
2023 ;; make a new Followup-To line
2024 (if (not (string-match (concat "^[ \t]*"
2027 (message-fetch-field "Newsgroups")))
2028 (insert (concat "\nFollowup-To: " target-group
)))
2029 (setq message-cross-post-old-target target-group
))
2031 (defun message-cross-post-insert-note (target-group cross-post in-old
2033 "Insert a in message body note about a set Followup or Crosspost.
2034 If there have been previous notes, delete them. TARGET-GROUP specifies the
2035 group to Followup-To. When CROSS-POST is t, insert note about
2036 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
2037 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
2038 been made to before the user asked for a Crosspost."
2039 ;; start scanning body for previous uses
2040 (message-goto-signature)
2041 (let ((head (re-search-backward
2042 (concat "^" mail-header-separator
)
2043 nil t
))) ; just search in body
2044 (message-goto-signature)
2045 (while (re-search-backward
2046 (concat "^" (regexp-quote message-cross-post-note
) ".*")
2048 (message-delete-line))
2049 (message-goto-signature)
2050 (while (re-search-backward
2051 (concat "^" (regexp-quote message-followup-to-note
) ".*")
2053 (message-delete-line))
2055 (if (message-goto-signature)
2056 (re-search-backward message-signature-separator
))
2059 (string-match "^[ \t]*poster[ \t]*$" target-group
))
2060 (insert (concat message-followup-to-note target-group
"\n"))
2061 (insert (concat message-cross-post-note target-group
"\n")))))
2063 (defun message-cross-post-followup-to (target-group)
2064 "Crossposts message and set Followup-To to TARGET-GROUP.
2065 With prefix-argument just set Follow-Up, don't cross-post."
2067 (list ; Completion based on Gnus
2068 (completing-read "Followup To: "
2069 (if (boundp 'gnus-newsrc-alist
)
2071 nil nil
'("poster" .
0)
2072 (if (boundp 'gnus-group-history
)
2073 'gnus-group-history
))))
2074 (cond ((not (or (null target-group
) ; new subject not empty
2075 (zerop (string-width target-group
))
2076 (string-match "^[ \t]*$" target-group
)))
2078 (let* ((old-groups (message-fetch-field "Newsgroups"))
2079 (in-old (string-match
2080 (regexp-quote target-group
)
2081 (or old-groups
""))))
2082 ;; check whether target exactly matches old Newsgroups
2083 (cond ((not old-groups
)
2084 (error "No current newsgroup"))
2088 (regexp-quote target-group
)
2091 ;; yes, Newsgroups line must change
2092 (message-cross-post-followup-to-header target-group
)
2093 ;; insert note whether we do cross-post or followup-to
2094 (funcall message-cross-post-note-function
2096 (if (or (and message-cross-post-default
2097 (not current-prefix-arg
))
2098 (and (not message-cross-post-default
)
2099 current-prefix-arg
)) t
)
2100 in-old old-groups
))))))))
2102 ;;; Reduce To: to Cc: or Bcc: header
2104 (defun message-reduce-to-to-cc ()
2105 "Replace contents of To: header with contents of Cc: or Bcc: header."
2108 (save-restriction (message-narrow-to-headers)
2109 (message-fetch-field "cc")))
2111 (if (and (not cc-content
)
2114 (message-narrow-to-headers)
2115 (message-fetch-field "bcc"))))
2120 (message-delete-line)
2121 (insert (concat "To: " cc-content
"\n"))
2123 (message-narrow-to-headers)
2124 (message-remove-header (if bcc
2128 ;;; End of functions adopted from `message-utils.el'.
2130 (defun message-remove-header (header &optional is-regexp first reverse
)
2131 "Remove HEADER in the narrowed buffer.
2132 If IS-REGEXP, HEADER is a regular expression.
2133 If FIRST, only remove the first instance of the header.
2134 Return the number of headers removed."
2135 (goto-char (point-min))
2136 (let ((regexp (if is-regexp header
(concat "^" (regexp-quote header
) ":")))
2138 (case-fold-search t
)
2140 (while (and (not (eobp))
2143 (not (looking-at regexp
))
2144 (looking-at regexp
))
2151 ;; There might be a continuation header, so we have to search
2152 ;; until we find a new non-continuation line.
2155 (if (re-search-forward "^[^ \t]" nil t
)
2156 (goto-char (match-beginning 0))
2159 (if (re-search-forward "^[^ \t]" nil t
)
2160 (goto-char (match-beginning 0))
2161 (goto-char (point-max)))))
2164 (defun message-remove-first-header (header)
2165 "Remove the first instance of HEADER if there is more than one."
2167 (regexp (concat "^" (regexp-quote header
) ":")))
2169 (goto-char (point-min))
2170 (while (re-search-forward regexp nil t
)
2173 (message-remove-header header nil t
)
2176 (defun message-narrow-to-headers ()
2177 "Narrow the buffer to the head of the message."
2180 (goto-char (point-min))
2181 (if (re-search-forward
2182 (concat "^" (regexp-quote mail-header-separator
) "\n") nil t
)
2185 (goto-char (point-min)))
2187 (defun message-narrow-to-head-1 ()
2188 "Like `message-narrow-to-head'. Don't widen."
2190 (goto-char (point-min))
2191 (if (search-forward "\n\n" nil
1)
2194 (goto-char (point-min)))
2196 (defun message-narrow-to-head ()
2197 "Narrow the buffer to the head of the message.
2198 Point is left at the beginning of the narrowed-to region."
2200 (message-narrow-to-head-1))
2202 (defun message-narrow-to-headers-or-head ()
2203 "Narrow the buffer to the head of the message."
2206 (goto-char (point-min))
2209 (concat "^" (regexp-quote mail-header-separator
) "\n") nil t
)
2210 (match-beginning 0))
2211 ((search-forward "\n\n" nil t
)
2215 (goto-char (point-min)))
2217 (defun message-news-p ()
2218 "Say whether the current buffer contains a news message."
2219 (and (not message-this-is-mail
)
2220 (or message-this-is-news
2223 (message-narrow-to-headers)
2224 (and (message-fetch-field "newsgroups")
2225 (not (message-fetch-field "posted-to"))))))))
2227 (defun message-mail-p ()
2228 "Say whether the current buffer contains a mail message."
2229 (and (not message-this-is-news
)
2230 (or message-this-is-mail
2233 (message-narrow-to-headers)
2234 (or (message-fetch-field "to")
2235 (message-fetch-field "cc")
2236 (message-fetch-field "bcc")))))))
2238 (defun message-subscribed-p ()
2239 "Say whether we need to insert a MFT header."
2240 (or message-subscribed-regexps
2241 message-subscribed-addresses
2242 message-subscribed-address-file
2243 message-subscribed-address-functions
))
2245 (defun message-next-header ()
2246 "Go to the beginning of the next header."
2248 (or (eobp) (forward-char 1))
2249 (not (if (re-search-forward "^[^ \t]" nil t
)
2251 (goto-char (point-max)))))
2253 (defun message-sort-headers-1 ()
2254 "Sort the buffer as headers using `message-rank' text props."
2255 (goto-char (point-min))
2258 nil
'message-next-header
2260 (message-next-header)
2264 (or (get-text-property (point) 'message-rank
)
2267 (defun message-sort-headers ()
2268 "Sort the headers of the current message according to `message-header-format-alist'."
2272 (let ((max (1+ (length message-header-format-alist
)))
2274 (message-narrow-to-headers)
2275 (while (re-search-forward "^[^ \n]+:" nil t
)
2277 (match-beginning 0) (1+ (match-beginning 0))
2279 (if (setq rank
(length (memq (assq (intern (buffer-substring
2281 (1- (match-end 0))))
2282 message-header-format-alist
)
2283 message-header-format-alist
)))
2286 (message-sort-headers-1))))
2288 (defun message-info (&optional arg
)
2289 "Display the Message manual.
2291 Prefixed with one \\[universal-argument], display the Emacs MIME manual.
2292 Prefixed with two \\[universal-argument]'s, display the PGG manual."
2294 (cond ((eq arg
16) (Info-goto-node "(pgg)Top"))
2295 ((eq arg
4) (Info-goto-node "(emacs-mime)Top"))
2296 (t (Info-goto-node "(message)Top"))))
2306 (defvar message-mode-map nil
)
2308 (unless message-mode-map
2309 (setq message-mode-map
(make-keymap))
2310 (set-keymap-parent message-mode-map text-mode-map
)
2311 (define-key message-mode-map
"\C-c?" 'describe-mode
)
2313 (define-key message-mode-map
"\C-c\C-f\C-t" 'message-goto-to
)
2314 (define-key message-mode-map
"\C-c\C-f\C-o" 'message-goto-from
)
2315 (define-key message-mode-map
"\C-c\C-f\C-b" 'message-goto-bcc
)
2316 (define-key message-mode-map
"\C-c\C-f\C-w" 'message-goto-fcc
)
2317 (define-key message-mode-map
"\C-c\C-f\C-c" 'message-goto-cc
)
2318 (define-key message-mode-map
"\C-c\C-f\C-s" 'message-goto-subject
)
2319 (define-key message-mode-map
"\C-c\C-f\C-r" 'message-goto-reply-to
)
2320 (define-key message-mode-map
"\C-c\C-f\C-n" 'message-goto-newsgroups
)
2321 (define-key message-mode-map
"\C-c\C-f\C-d" 'message-goto-distribution
)
2322 (define-key message-mode-map
"\C-c\C-f\C-f" 'message-goto-followup-to
)
2323 (define-key message-mode-map
"\C-c\C-f\C-m" 'message-goto-mail-followup-to
)
2324 (define-key message-mode-map
"\C-c\C-f\C-k" 'message-goto-keywords
)
2325 (define-key message-mode-map
"\C-c\C-f\C-u" 'message-goto-summary
)
2326 (define-key message-mode-map
"\C-c\C-f\C-i"
2327 'message-insert-or-toggle-importance
)
2328 (define-key message-mode-map
"\C-c\C-f\C-a"
2329 'message-generate-unsubscribed-mail-followup-to
)
2331 ;; modify headers (and insert notes in body)
2332 (define-key message-mode-map
"\C-c\C-fs" 'message-change-subject
)
2334 (define-key message-mode-map
"\C-c\C-fx" 'message-cross-post-followup-to
)
2335 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2336 (define-key message-mode-map
"\C-c\C-ft" 'message-reduce-to-to-cc
)
2337 (define-key message-mode-map
"\C-c\C-fa" 'message-add-archive-header
)
2338 ;; mark inserted text
2339 (define-key message-mode-map
"\C-c\M-m" 'message-mark-inserted-region
)
2340 (define-key message-mode-map
"\C-c\M-f" 'message-mark-insert-file
)
2342 (define-key message-mode-map
"\C-c\C-b" 'message-goto-body
)
2343 (define-key message-mode-map
"\C-c\C-i" 'message-goto-signature
)
2345 (define-key message-mode-map
"\C-c\C-t" 'message-insert-to
)
2346 (define-key message-mode-map
"\C-c\C-fw" 'message-insert-wide-reply
)
2347 (define-key message-mode-map
"\C-c\C-n" 'message-insert-newsgroups
)
2348 (define-key message-mode-map
"\C-c\C-l" 'message-to-list-only
)
2350 (define-key message-mode-map
"\C-c\C-u" 'message-insert-or-toggle-importance
)
2351 (define-key message-mode-map
"\C-c\M-n"
2352 'message-insert-disposition-notification-to
)
2354 (define-key message-mode-map
"\C-c\C-y" 'message-yank-original
)
2355 (define-key message-mode-map
"\C-c\M-\C-y" 'message-yank-buffer
)
2356 (define-key message-mode-map
"\C-c\C-q" 'message-fill-yanked-message
)
2357 (define-key message-mode-map
"\C-c\C-w" 'message-insert-signature
)
2358 (define-key message-mode-map
"\C-c\M-h" 'message-insert-headers
)
2359 (define-key message-mode-map
"\C-c\C-r" 'message-caesar-buffer-body
)
2360 (define-key message-mode-map
"\C-c\C-o" 'message-sort-headers
)
2361 (define-key message-mode-map
"\C-c\M-r" 'message-rename-buffer
)
2363 (define-key message-mode-map
"\C-c\C-c" 'message-send-and-exit
)
2364 (define-key message-mode-map
"\C-c\C-s" 'message-send
)
2365 (define-key message-mode-map
"\C-c\C-k" 'message-kill-buffer
)
2366 (define-key message-mode-map
"\C-c\C-d" 'message-dont-send
)
2367 (define-key message-mode-map
"\C-c\n" 'gnus-delay-article
)
2369 (define-key message-mode-map
"\C-c\C-e" 'message-elide-region
)
2370 (define-key message-mode-map
"\C-c\C-v" 'message-delete-not-region
)
2371 (define-key message-mode-map
"\C-c\C-z" 'message-kill-to-signature
)
2372 (define-key message-mode-map
"\M-\r" 'message-newline-and-reformat
)
2373 ;;(define-key message-mode-map "\M-q" 'message-fill-paragraph)
2374 (define-key message-mode-map
[remap split-line
] 'message-split-line
)
2376 (define-key message-mode-map
"\C-c\C-a" 'mml-attach-file
)
2378 (define-key message-mode-map
"\C-a" 'message-beginning-of-line
)
2379 (define-key message-mode-map
"\t" 'message-tab
)
2380 (define-key message-mode-map
"\M-;" 'comment-region
))
2383 message-mode-menu message-mode-map
"Message Menu."
2385 ["Yank Original" message-yank-original message-reply-buffer
]
2386 ["Fill Yanked Message" message-fill-yanked-message t
]
2387 ["Insert Signature" message-insert-signature t
]
2388 ["Caesar (rot13) Message" message-caesar-buffer-body t
]
2389 ["Caesar (rot13) Region" message-caesar-region
(message-mark-active-p)]
2390 ["Elide Region" message-elide-region
2391 :active
(message-mark-active-p)
2392 ,@(if (featurep 'xemacs
) nil
2393 '(:help
"Replace text in region with an ellipsis"))]
2394 ["Delete Outside Region" message-delete-not-region
2395 :active
(message-mark-active-p)
2396 ,@(if (featurep 'xemacs
) nil
2397 '(:help
"Delete all quoted text outside region"))]
2398 ["Kill To Signature" message-kill-to-signature t
]
2399 ["Newline and Reformat" message-newline-and-reformat t
]
2400 ["Rename buffer" message-rename-buffer t
]
2401 ["Spellcheck" ispell-message
2402 ,@(if (featurep 'xemacs
) '(t)
2403 '(:help
"Spellcheck this message"))]
2405 ["Insert Region Marked" message-mark-inserted-region
2406 :active
(message-mark-active-p)
2407 ,@(if (featurep 'xemacs
) nil
2408 '(:help
"Mark region with enclosing tags"))]
2409 ["Insert File Marked..." message-mark-insert-file
2410 ,@(if (featurep 'xemacs
) '(t)
2411 '(:help
"Insert file at point marked with enclosing tags"))]
2413 ["Send Message" message-send-and-exit
2414 ,@(if (featurep 'xemacs
) '(t)
2415 '(:help
"Send this message"))]
2416 ["Postpone Message" message-dont-send
2417 ,@(if (featurep 'xemacs
) '(t)
2418 '(:help
"File this draft message and exit"))]
2419 ["Send at Specific Time..." gnus-delay-article
2420 ,@(if (featurep 'xemacs
) '(t)
2421 '(:help
"Ask, then arrange to send message at that time"))]
2422 ["Kill Message" message-kill-buffer
2423 ,@(if (featurep 'xemacs
) '(t)
2424 '(:help
"Delete this message without sending"))]
2426 ["Message manual" message-info
2427 ,@(if (featurep 'xemacs
) '(t)
2428 '(:help
"Display the Message manual"))]))
2431 message-mode-field-menu message-mode-map
""
2433 ["To" message-goto-to t
]
2434 ["From" message-goto-from t
]
2435 ["Subject" message-goto-subject t
]
2436 ["Change subject..." message-change-subject t
]
2437 ["Cc" message-goto-cc t
]
2438 ["Bcc" message-goto-bcc t
]
2439 ["Fcc" message-goto-fcc t
]
2440 ["Reply-To" message-goto-reply-to t
]
2441 ["Flag As Important" message-insert-importance-high
2442 ,@(if (featurep 'xemacs
) '(t)
2443 '(:help
"Mark this message as important"))]
2444 ["Flag As Unimportant" message-insert-importance-low
2445 ,@(if (featurep 'xemacs
) '(t)
2446 '(:help
"Mark this message as unimportant"))]
2448 message-insert-disposition-notification-to
2449 ,@(if (featurep 'xemacs
) '(t)
2450 '(:help
"Request a receipt notification"))]
2452 ;; (typical) news stuff
2453 ["Summary" message-goto-summary t
]
2454 ["Keywords" message-goto-keywords t
]
2455 ["Newsgroups" message-goto-newsgroups t
]
2456 ["Fetch Newsgroups" message-insert-newsgroups t
]
2457 ["Followup-To" message-goto-followup-to t
]
2458 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2459 ["Crosspost / Followup-To..." message-cross-post-followup-to t
]
2460 ["Distribution" message-goto-distribution t
]
2461 ["X-No-Archive:" message-add-archive-header t
]
2463 ;; (typical) mailing-lists stuff
2464 ["Fetch To" message-insert-to
2465 ,@(if (featurep 'xemacs
) '(t)
2466 '(:help
"Insert a To header that points to the author."))]
2467 ["Fetch To and Cc" message-insert-wide-reply
2468 ,@(if (featurep 'xemacs
) '(t)
2470 "Insert To and Cc headers as if you were doing a wide reply."))]
2472 ["Send to list only" message-to-list-only t
]
2473 ["Mail-Followup-To" message-goto-mail-followup-to t
]
2474 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2475 ,@(if (featurep 'xemacs
) '(t)
2476 '(:help
"Insert a reasonable `Mail-Followup-To:' header."))]
2477 ["Reduce To: to Cc:" message-reduce-to-to-cc t
]
2479 ["Sort Headers" message-sort-headers t
]
2480 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t
]
2481 ["Goto Body" message-goto-body t
]
2482 ["Goto Signature" message-goto-signature t
]))
2484 (defvar message-tool-bar-map nil
)
2487 (defvar facemenu-add-face-function
)
2488 (defvar facemenu-remove-face-function
))
2490 ;;; Forbidden properties
2492 ;; We use `after-change-functions' to keep special text properties
2493 ;; that interfer with the normal function of message mode out of the
2496 (defcustom message-strip-special-text-properties t
2497 "Strip special properties from the message buffer.
2499 Emacs has a number of special text properties which can break message
2500 composing in various ways. If this option is set, message will strip
2501 these properties from the message composition buffer. However, some
2502 packages requires these properties to be present in order to work.
2503 If you use one of these packages, turn this option off, and hope the
2504 message composition doesn't break too bad."
2506 :group
'message-various
2507 :link
'(custom-manual "(message)Various Message Variables")
2510 (defconst message-forbidden-properties
2511 ;; No reason this should be clutter up customize. We make it a
2512 ;; property list (rather than a list of property symbols), to be
2513 ;; directly useful for `remove-text-properties'.
2514 '(field nil read-only nil invisible nil intangible nil
2515 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2516 insert-behind-hooks nil point-entered nil point-left nil
)
2517 ;; Other special properties:
2518 ;; category, face, display: probably doesn't do any harm.
2519 ;; fontified: is used by font-lock.
2520 ;; syntax-table, local-map: I dunno.
2521 ;; We need to add XEmacs names to the list.
2522 "Property list of with properties forbidden in message buffers.
2523 The values of the properties are ignored, only the property names are used.")
2525 (defun message-tamago-not-in-use-p (pos)
2526 "Return t when tamago version 4 is not in use at the cursor position.
2527 Tamago version 4 is a popular input method for writing Japanese text.
2528 It uses the properties `intangible', `invisible', `modification-hooks'
2529 and `read-only' when translating ascii or kana text to kanji text.
2530 These properties are essential to work, so we should never strip them."
2531 (not (and (boundp 'egg-modefull-mode
)
2532 (symbol-value 'egg-modefull-mode
)
2533 (or (memq (get-text-property pos
'intangible
)
2534 '(its-part-1 its-part-2
))
2535 (get-text-property pos
'egg-end
)
2536 (get-text-property pos
'egg-lang
)
2537 (get-text-property pos
'egg-start
)))))
2539 (defun message-strip-forbidden-properties (begin end
&optional old-length
)
2540 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2541 This function is intended to be called from `after-change-functions'.
2542 See also `message-forbidden-properties'."
2543 (when (and message-strip-special-text-properties
2544 (message-tamago-not-in-use-p begin
))
2545 (let ((buffer-read-only nil
)
2546 (inhibit-read-only t
))
2547 (while (not (= begin end
))
2548 (when (not (get-text-property begin
'message-hidden
))
2549 (remove-text-properties begin
(1+ begin
)
2550 message-forbidden-properties
))
2554 (define-derived-mode message-mode text-mode
"Message"
2555 "Major mode for editing mail and news to be sent.
2556 Like Text Mode but with these additional commands:\\<message-mode-map>
2557 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2558 C-c C-d Postpone sending the message C-c C-k Kill the message
2559 C-c C-f move to a header field (and create it if there isn't):
2560 C-c C-f C-t move to To C-c C-f C-s move to Subject
2561 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2562 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2563 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2564 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2565 C-c C-f C-o move to From (\"Originator\")
2566 C-c C-f C-f move to Followup-To
2567 C-c C-f C-m move to Mail-Followup-To
2568 C-c C-f C-i cycle through Importance values
2569 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2570 C-c C-f x crossposting with FollowUp-To header and note in body
2571 C-c C-f t replace To: header with contents of Cc: or Bcc:
2572 C-c C-f a Insert X-No-Archive: header and a note in the body
2573 C-c C-t `message-insert-to' (add a To header to a news followup)
2574 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2575 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2576 C-c C-b `message-goto-body' (move to beginning of message text).
2577 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2578 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2579 C-c C-y `message-yank-original' (insert current message, if any).
2580 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2581 C-c C-e `message-elide-region' (elide the text between point and mark).
2582 C-c C-v `message-delete-not-region' (remove the text outside the region).
2583 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2584 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2585 C-c C-a `mml-attach-file' (attach a file as MIME).
2586 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2587 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2588 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2589 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2590 M-RET `message-newline-and-reformat' (break the line and reformat)."
2591 (setq local-abbrev-table text-mode-abbrev-table
)
2592 (set (make-local-variable 'message-reply-buffer
) nil
)
2593 (set (make-local-variable 'message-inserted-headers
) nil
)
2594 (set (make-local-variable 'message-send-actions
) nil
)
2595 (set (make-local-variable 'message-exit-actions
) nil
)
2596 (set (make-local-variable 'message-kill-actions
) nil
)
2597 (set (make-local-variable 'message-postpone-actions
) nil
)
2598 (set (make-local-variable 'message-draft-article
) nil
)
2599 (setq buffer-offer-save t
)
2600 (set (make-local-variable 'facemenu-add-face-function
)
2602 (let ((face-fun (cdr (assq face message-face-alist
))))
2604 (funcall face-fun
(point) end
)
2605 (error "Face %s not configured for %s mode" face mode-name
)))
2607 (set (make-local-variable 'facemenu-remove-face-function
) t
)
2608 (set (make-local-variable 'message-reply-headers
) nil
)
2609 (make-local-variable 'message-newsreader
)
2610 (make-local-variable 'message-mailer
)
2611 (make-local-variable 'message-post-method
)
2612 (set (make-local-variable 'message-sent-message-via
) nil
)
2613 (set (make-local-variable 'message-checksum
) nil
)
2614 (set (make-local-variable 'message-mime-part
) 0)
2615 (message-setup-fill-variables)
2616 ;; Allow using comment commands to add/remove quoting.
2617 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2618 (when message-yank-prefix
2619 (set (make-local-variable 'comment-start
) message-yank-prefix
)
2620 (set (make-local-variable 'comment-start-skip
)
2621 (concat "^" (regexp-quote message-yank-prefix
) "[ \t]*")))
2622 (if (featurep 'xemacs
)
2623 (message-setup-toolbar)
2624 (set (make-local-variable 'font-lock-defaults
)
2625 '(message-font-lock-keywords t
))
2626 (if (boundp 'tool-bar-map
)
2627 (set (make-local-variable 'tool-bar-map
) (message-make-tool-bar))))
2628 (easy-menu-add message-mode-menu message-mode-map
)
2629 (easy-menu-add message-mode-field-menu message-mode-map
)
2630 (gnus-make-local-hook 'after-change-functions
)
2631 ;; Mmmm... Forbidden properties...
2632 (add-hook 'after-change-functions
'message-strip-forbidden-properties
2634 ;; Allow mail alias things.
2635 (when (eq message-mail-alias-type
'abbrev
)
2636 (if (fboundp 'mail-abbrevs-setup
)
2637 (mail-abbrevs-setup)
2638 (if (fboundp 'mail-aliases-setup
) ; warning avoidance
2639 (mail-aliases-setup))))
2640 (unless buffer-file-name
2641 (message-set-auto-save-file-name))
2642 (unless (buffer-base-buffer)
2643 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2644 ;; multibyte is not necessary at all. -- zsh
2645 (mm-enable-multibyte))
2646 (set (make-local-variable 'indent-tabs-mode
) nil
) ;No tabs for indentation.
2649 (defun message-setup-fill-variables ()
2650 "Setup message fill variables."
2651 (set (make-local-variable 'fill-paragraph-function
)
2652 'message-fill-paragraph
)
2653 (make-local-variable 'paragraph-separate
)
2654 (make-local-variable 'paragraph-start
)
2655 (make-local-variable 'adaptive-fill-regexp
)
2656 (unless (boundp 'adaptive-fill-first-line-regexp
)
2657 (setq adaptive-fill-first-line-regexp nil
))
2658 (make-local-variable 'adaptive-fill-first-line-regexp
)
2659 (let ((quote-prefix-regexp
2660 ;; User should change message-cite-prefix-regexp if
2661 ;; message-yank-prefix is set to an abnormal value.
2662 (concat "\\(" message-cite-prefix-regexp
"\\)[ \t]*")))
2663 (setq paragraph-start
2665 (regexp-quote mail-header-separator
) "$\\|"
2666 "[ \t]*$\\|" ; blank lines
2667 "-- $\\|" ; signature delimiter
2668 "---+$\\|" ; delimiters for forwarded messages
2669 page-delimiter
"$\\|" ; spoiler warnings
2670 ".*wrote:$\\|" ; attribution lines
2671 quote-prefix-regexp
"$\\|" ; empty lines in quoted text
2673 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
2674 (setq paragraph-separate paragraph-start
)
2675 (setq adaptive-fill-regexp
2676 (concat quote-prefix-regexp
"\\|" adaptive-fill-regexp
))
2677 (setq adaptive-fill-first-line-regexp
2678 (concat quote-prefix-regexp
"\\|"
2679 adaptive-fill-first-line-regexp
)))
2680 (make-local-variable 'auto-fill-inhibit-regexp
)
2681 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2682 (setq auto-fill-inhibit-regexp nil
)
2683 (make-local-variable 'normal-auto-fill-function
)
2684 (setq normal-auto-fill-function
'message-do-auto-fill
)
2685 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2686 ;; In that case, ensure that it uses the right function. The real
2687 ;; solution would be not to use `define-derived-mode', and run
2688 ;; `text-mode-hook' ourself at the end of the mode.
2689 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2690 (when auto-fill-function
2691 (setq auto-fill-function normal-auto-fill-function
)))
2696 ;;; Message mode commands
2699 ;;; Movement commands
2701 (defun message-goto-to ()
2702 "Move point to the To header."
2704 (message-position-on-field "To"))
2706 (defun message-goto-from ()
2707 "Move point to the From header."
2709 (message-position-on-field "From"))
2711 (defun message-goto-subject ()
2712 "Move point to the Subject header."
2714 (message-position-on-field "Subject"))
2716 (defun message-goto-cc ()
2717 "Move point to the Cc header."
2719 (message-position-on-field "Cc" "To"))
2721 (defun message-goto-bcc ()
2722 "Move point to the Bcc header."
2724 (message-position-on-field "Bcc" "Cc" "To"))
2726 (defun message-goto-fcc ()
2727 "Move point to the Fcc header."
2729 (message-position-on-field "Fcc" "To" "Newsgroups"))
2731 (defun message-goto-reply-to ()
2732 "Move point to the Reply-To header."
2734 (message-position-on-field "Reply-To" "Subject"))
2736 (defun message-goto-newsgroups ()
2737 "Move point to the Newsgroups header."
2739 (message-position-on-field "Newsgroups"))
2741 (defun message-goto-distribution ()
2742 "Move point to the Distribution header."
2744 (message-position-on-field "Distribution"))
2746 (defun message-goto-followup-to ()
2747 "Move point to the Followup-To header."
2749 (message-position-on-field "Followup-To" "Newsgroups"))
2751 (defun message-goto-mail-followup-to ()
2752 "Move point to the Mail-Followup-To header."
2754 (message-position-on-field "Mail-Followup-To" "To"))
2756 (defun message-goto-keywords ()
2757 "Move point to the Keywords header."
2759 (message-position-on-field "Keywords" "Subject"))
2761 (defun message-goto-summary ()
2762 "Move point to the Summary header."
2764 (message-position-on-field "Summary" "Subject"))
2766 (defun message-goto-body (&optional interactivep
)
2767 "Move point to the beginning of the message body."
2768 (interactive (list t
))
2769 (when (and interactivep
2770 (looking-at "[ \t]*\n"))
2772 (goto-char (point-min))
2773 (or (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
2774 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t
)))
2776 (defun message-in-body-p ()
2777 "Return t if point is in the message body."
2778 (let ((body (save-excursion (message-goto-body) (point))))
2781 (defun message-goto-eoh ()
2782 "Move point to the end of the headers."
2787 (defun message-goto-signature ()
2788 "Move point to the beginning of the message signature.
2789 If there is no signature in the article, go to the end and
2792 (goto-char (point-min))
2793 (if (re-search-forward message-signature-separator nil t
)
2795 (goto-char (point-max))
2798 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc
)
2799 "Insert a reasonable MFT header in a post to an unsubscribed list.
2800 When making original posts to a mailing list you are not subscribed to,
2801 you have to type in a MFT header by hand. The contents, usually, are
2802 the addresses of the list and your own address. This function inserts
2803 such a header automatically. It fetches the contents of the To: header
2804 in the current mail buffer, and appends the current `user-mail-address'.
2806 If the optional argument INCLUDE-CC is non-nil, the addresses in the
2807 Cc: header are also put into the MFT."
2812 (message-narrow-to-headers)
2813 (message-remove-header "Mail-Followup-To")
2814 (setq cc
(and include-cc
(message-fetch-field "Cc")))
2816 (concat (message-fetch-field "To") "," cc
)
2817 (message-fetch-field "To"))))
2818 (message-goto-mail-followup-to)
2819 (insert (concat tos
", " user-mail-address
))))
2823 (defun message-insert-to (&optional force
)
2824 "Insert a To header that points to the author of the article being replied to.
2825 If the original author requested not to be sent mail, don't insert unless the
2826 prefix FORCE is given."
2828 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
2829 (dont (and mct
(or (equal (downcase mct
) "never")
2830 (equal (downcase mct
) "nobody"))))
2831 (to (or (message-fetch-reply-field "mail-reply-to")
2832 (message-fetch-reply-field "reply-to")
2833 (message-fetch-reply-field "from"))))
2837 "Ignoring the user request not to have copies sent via mail"
2838 "Complying with the user request not to have copies sent via mail")))
2839 (when (and force
(not to
))
2840 (error "No mail address in the article"))
2841 (when (and to
(or force
(not dont
)))
2842 (message-carefully-insert-headers (list (cons 'To to
))))))
2844 (defun message-insert-wide-reply ()
2845 "Insert To and Cc headers as if you were doing a wide reply."
2847 (let ((headers (message-with-reply-buffer
2848 (message-get-reply-headers t
))))
2849 (message-carefully-insert-headers headers
)))
2851 (defcustom message-header-synonyms
2854 "List of lists of header synonyms.
2855 E.g., if this list contains a member list with elements `Cc' and `To',
2856 then `message-carefully-insert-headers' will not insert a `To' header
2857 when the message is already `Cc'ed to the recipient."
2859 :group
'message-headers
2860 :link
'(custom-manual "(message)Message Headers")
2861 :type
'(repeat sexp
))
2863 (defun message-carefully-insert-headers (headers)
2864 "Insert the HEADERS, an alist, into the message buffer.
2865 Does not insert the headers when they are already present there
2866 or in the synonym headers, defined by `message-header-synonyms'."
2867 ;; FIXME: Should compare only the address and not the full name. Comparison
2868 ;; should be done case-folded (and with `string=' rather than
2870 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
2871 (dolist (header headers
)
2872 (let* ((header-name (symbol-name (car header
)))
2873 (new-header (cdr header
))
2874 (synonyms (loop for synonym in message-header-synonyms
2875 when
(memq (car header
) synonym
) return synonym
))
2877 (loop for synonym in synonyms
2878 for old-header
= (mail-fetch-field (symbol-name synonym
))
2879 when
(and old-header
(string-match new-header old-header
))
2882 (message "already have `%s' in `%s'" new-header old-header
)
2883 (when (and (message-position-on-field header-name
)
2884 (setq old-header
(mail-fetch-field header-name
))
2885 (not (string-match "\\` *\\'" old-header
)))
2887 (insert new-header
)))))
2889 (defun message-widen-reply ()
2890 "Widen the reply to include maximum recipients."
2893 (and message-reply-buffer
2894 (buffer-name message-reply-buffer
)
2896 (set-buffer message-reply-buffer
)
2897 (message-get-reply-headers t
)))))
2900 (message-narrow-to-headers)
2901 (dolist (elem follow-to
)
2902 (message-remove-header (symbol-name (car elem
)))
2903 (goto-char (point-min))
2904 (insert (symbol-name (car elem
)) ": "
2905 (cdr elem
) "\n"))))))
2907 (defun message-insert-newsgroups ()
2908 "Insert the Newsgroups header from the article being replied to."
2910 (when (and (message-position-on-field "Newsgroups")
2911 (mail-fetch-field "newsgroups")
2912 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
2914 (insert (or (message-fetch-reply-field "newsgroups") "")))
2918 ;;; Various commands
2920 (defun message-delete-not-region (beg end
)
2921 "Delete everything in the body of the current message outside of the region."
2926 ;; snarf citation prefix, if appropriate
2927 (unless (eq (point) (progn (beginning-of-line) (point)))
2928 (when (looking-at message-cite-prefix-regexp
)
2929 (setq citeprefix
(match-string 0))))
2931 (delete-region (point) (if (not (message-goto-signature))
2937 (delete-region beg
(progn (message-goto-body)
2941 (insert citeprefix
))))
2942 (when (message-goto-signature)
2945 (defun message-kill-to-signature ()
2946 "Deletes all text up to the signature."
2948 (let ((point (point)))
2949 (message-goto-signature)
2952 (kill-region point
(point))
2956 (defun message-newline-and-reformat (&optional arg not-break
)
2957 "Insert four newlines, and then reformat if inside quoted text.
2958 Prefix arg means justify as well."
2959 (interactive (list (if current-prefix-arg
'full
)))
2960 (let (quoted point beg end leading-space bolp
)
2961 (setq point
(point))
2964 (setq bolp
(= beg point
))
2965 ;; Find first line of the paragraph.
2967 (while (and (not (eobp))
2968 (not (looking-at message-cite-prefix-regexp
))
2969 (looking-at paragraph-start
))
2972 (when (looking-at message-cite-prefix-regexp
)
2973 (setq quoted
(match-string 0))
2974 (goto-char (match-end 0))
2975 (looking-at "[ \t]*")
2976 (setq leading-space
(match-string 0)))
2980 (< (- point beg
) (length quoted
)))
2981 ;; break inside the cite prefix.
2987 (while (and (not (eobp))
2988 (not (looking-at paragraph-separate
))
2989 (looking-at message-cite-prefix-regexp
)
2990 (equal quoted
(match-string 0)))
2991 (goto-char (match-end 0))
2992 (looking-at "[ \t]*")
2993 (if (> (length leading-space
) (length (match-string 0)))
2994 (setq leading-space
(match-string 0)))
2998 (while (and (if (bobp) nil
(forward-line -
1) t
)
2999 (not (looking-at paragraph-start
))
3000 (looking-at message-cite-prefix-regexp
)
3001 (equal quoted
(match-string 0)))
3003 (goto-char (match-end 0))
3004 (looking-at "[ \t]*")
3005 (if (> (length leading-space
) (length (match-string 0)))
3006 (setq leading-space
(match-string 0)))))
3007 (while (and (not (eobp))
3008 (not (looking-at paragraph-separate
))
3009 (not (looking-at message-cite-prefix-regexp
)))
3013 (while (and (if (bobp) nil
(forward-line -
1) t
)
3014 (not (looking-at paragraph-start
))
3015 (not (looking-at message-cite-prefix-regexp
)))
3016 (setq beg
(point))))
3019 (narrow-to-region beg end
)
3026 (setq point
(point))
3027 ;; (newline 2) doesn't mark both newline's as hard, so call
3028 ;; newline twice. -jas
3031 (delete-region (point) (re-search-forward "[ \t]*"))
3032 (when (and quoted
(not bolp
))
3033 (insert quoted leading-space
)))
3036 (let* ((adaptive-fill-regexp
3037 (regexp-quote (concat quoted leading-space
)))
3038 (adaptive-fill-first-line-regexp
3039 adaptive-fill-regexp
))
3040 (fill-paragraph arg
))
3041 (fill-paragraph arg
))
3042 (if point
(goto-char point
)))))
3044 (defun message-fill-paragraph (&optional arg
)
3045 "Like `fill-paragraph'."
3046 (interactive (list (if current-prefix-arg
'full
)))
3047 (if (if (boundp 'filladapt-mode
) filladapt-mode
)
3049 (message-newline-and-reformat arg t
)
3052 ;; Is it better to use `mail-header-end'?
3053 (defun message-point-in-header-p ()
3054 "Return t if point is in the header."
3057 (goto-char (point-min))
3058 (not (re-search-forward
3059 (concat "^" (regexp-quote mail-header-separator
) "\n")
3062 (defun message-do-auto-fill ()
3063 "Like `do-auto-fill', but don't fill in message header."
3064 (unless (message-point-in-header-p)
3067 (defun message-insert-signature (&optional force
)
3068 "Insert a signature. See documentation for variable `message-signature'."
3069 (interactive (list 0))
3072 ((and (null message-signature
)
3075 (goto-char (point-max))
3076 (not (re-search-backward message-signature-separator nil t
))))
3077 ((and (null message-signature
)
3080 ((functionp message-signature
)
3081 (funcall message-signature
))
3082 ((listp message-signature
)
3083 (eval message-signature
))
3084 (t message-signature
)))
3086 (cond ((stringp signature
)
3088 ((and (eq t signature
)
3089 message-signature-file
3090 (file-exists-p message-signature-file
))
3093 (goto-char (point-max))
3094 ;; Insert the signature.
3097 (when message-signature-insert-empty-line
3100 (if (eq signature t
)
3101 (insert-file-contents message-signature-file
)
3103 (goto-char (point-max))
3104 (or (bolp) (insert "\n")))))
3106 (defun message-insert-importance-high ()
3107 "Insert header to mark message as important."
3111 (message-narrow-to-headers)
3112 (message-remove-header "Importance"))
3114 (insert "Importance: high\n")))
3116 (defun message-insert-importance-low ()
3117 "Insert header to mark message as unimportant."
3121 (message-narrow-to-headers)
3122 (message-remove-header "Importance"))
3124 (insert "Importance: low\n")))
3126 (defun message-insert-or-toggle-importance ()
3127 "Insert a \"Importance: high\" header, or cycle through the header values.
3128 The three allowed values according to RFC 1327 are `high', `normal'
3132 (let ((valid '("high" "normal" "low"))
3136 (message-narrow-to-headers)
3137 (when (setq cur
(message-fetch-field "Importance"))
3138 (message-remove-header "Importance")
3139 (setq new
(cond ((string= cur
"high")
3141 ((string= cur
"low")
3146 (insert (format "Importance: %s\n" new
)))))
3148 (defun message-insert-disposition-notification-to ()
3149 "Request a disposition notification (return receipt) to this message.
3150 Note that this should not be used in newsgroups."
3154 (message-narrow-to-headers)
3155 (message-remove-header "Disposition-Notification-To"))
3157 (insert (format "Disposition-Notification-To: %s\n"
3158 (or (message-field-value "Reply-to")
3159 (message-field-value "From")
3160 (message-make-from))))))
3162 (defun message-elide-region (b e
)
3163 "Elide the text in the region.
3164 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3168 (insert message-elide-ellipsis
))
3170 (defvar message-caesar-translation-table nil
)
3172 (defun message-caesar-region (b e
&optional n
)
3173 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3176 (min (point) (or (mark t
) (point)))
3177 (max (point) (or (mark t
) (point)))
3178 (when current-prefix-arg
3179 (prefix-numeric-value current-prefix-arg
))))
3181 (setq n
(if (numberp n
) (mod n
26) 13)) ;canonize N
3182 (unless (or (zerop n
) ; no action needed for a rot of 0
3183 (= b e
)) ; no region to rotate
3184 ;; We build the table, if necessary.
3185 (when (or (not message-caesar-translation-table
)
3186 (/= (aref message-caesar-translation-table ?a
) (+ ?a n
)))
3187 (setq message-caesar-translation-table
3188 (message-make-caesar-translation-table n
)))
3189 (translate-region b e message-caesar-translation-table
)))
3191 (defun message-make-caesar-translation-table (n)
3192 "Create a rot table with offset N."
3194 (table (make-string 256 0)))
3195 (while (< (incf i
) 256)
3198 (substring table
0 ?A
)
3199 (substring table
(+ ?A n
) (+ ?A n
(- 26 n
)))
3200 (substring table ?A
(+ ?A n
))
3201 (substring table
(+ ?A
26) ?a
)
3202 (substring table
(+ ?a n
) (+ ?a n
(- 26 n
)))
3203 (substring table ?a
(+ ?a n
))
3204 (substring table
(+ ?a
26) 255))))
3206 (defun message-caesar-buffer-body (&optional rotnum
)
3207 "Caesar rotate all letters in the current buffer by 13 places.
3208 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3209 With prefix arg, specifies the number of places to rotate each letter forward.
3210 Mail and USENET news headers are not rotated."
3211 (interactive (if current-prefix-arg
3212 (list (prefix-numeric-value current-prefix-arg
))
3216 (when (message-goto-body)
3217 (narrow-to-region (point) (point-max)))
3218 (message-caesar-region (point-min) (point-max) rotnum
))))
3220 (defun message-pipe-buffer-body (program)
3221 "Pipe the message body in the current buffer through PROGRAM."
3224 (when (message-goto-body)
3225 (narrow-to-region (point) (point-max)))
3226 (shell-command-on-region
3227 (point-min) (point-max) program nil t
))))
3229 (defun message-rename-buffer (&optional enter-string
)
3230 "Rename the *message* buffer to \"*message* RECIPIENT\".
3231 If the function is run with a prefix, it will ask for a new buffer
3232 name, rather than giving an automatic name."
3233 (interactive "Pbuffer name: ")
3236 (goto-char (point-min))
3237 (narrow-to-region (point)
3238 (search-forward mail-header-separator nil
'end
))
3240 (if (message-news-p) (message-fetch-field "Newsgroups")
3241 (message-fetch-field "To"))
3244 (if (string-match "," mail-to
)
3245 (concat (substring mail-to
0 (match-beginning 0)) ", ...")
3247 (name-default (concat "*message* " mail-trimmed-to
))
3248 (name (if enter-string
3249 (read-string "New buffer name: " name-default
)
3251 (rename-buffer name t
)))))
3253 (defun message-fill-yanked-message (&optional justifyp
)
3254 "Fill the paragraphs of a message yanked into this one.
3255 Numeric argument means justify as well."
3258 (goto-char (point-min))
3259 (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
3260 (let ((fill-prefix message-yank-prefix
))
3261 (fill-individual-paragraphs (point) (point-max) justifyp
))))
3263 (defun message-indent-citation ()
3264 "Modify text just inserted from a message to be cited.
3265 The inserted text should be the region.
3266 When this function returns, the region is again around the modified text.
3268 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3269 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3270 (let ((start (point)))
3271 ;; Remove unwanted headers.
3272 (when message-ignored-cited-headers
3277 (if (search-forward "\n\n" nil t
)
3280 (message-remove-header message-ignored-cited-headers t
)
3281 (when (= (point-min) (point-max))
3282 (setq all-removed t
))
3283 (goto-char (point-max)))
3287 ;; Delete blank lines at the start of the buffer.
3288 (while (and (point-min)
3291 (message-delete-line))
3292 ;; Delete blank lines at the end of the buffer.
3293 (goto-char (point-max))
3296 (while (and (zerop (forward-line -
1))
3298 (message-delete-line))
3299 ;; Do the indentation.
3300 (if (null message-yank-prefix
)
3301 (indent-rigidly start
(mark t
) message-indentation-spaces
)
3304 (while (< (point) (mark t
))
3305 (if (or (looking-at ">") (looking-at "^$"))
3306 (insert message-yank-cited-prefix
)
3307 (insert message-yank-prefix
))
3311 (defun message-yank-original (&optional arg
)
3312 "Insert the message being replied to, if any.
3313 Puts point before the text and mark after.
3314 Normally indents each nonblank line ARG spaces (default 3). However,
3315 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3317 This function uses `message-cite-function' to do the actual citing.
3319 Just \\[universal-argument] as argument means don't indent, insert no
3320 prefix, and don't delete any headers."
3322 (let ((modified (buffer-modified-p)))
3323 (when (and message-reply-buffer
3324 message-cite-function
)
3325 (delete-windows-on message-reply-buffer t
)
3326 (push-mark (save-excursion
3327 (insert-buffer-substring message-reply-buffer
)
3330 (funcall message-cite-function
))
3331 (message-exchange-point-and-mark)
3335 (setq message-checksum
(message-checksum))))))
3337 (defun message-yank-buffer (buffer)
3338 "Insert BUFFER into the current buffer and quote it."
3339 (interactive "bYank buffer: ")
3340 (let ((message-reply-buffer (get-buffer buffer
)))
3341 (save-window-excursion
3342 (message-yank-original))))
3344 (defun message-buffers ()
3345 "Return a list of active message buffers."
3348 (dolist (buffer (buffer-list t
))
3350 (when (and (eq major-mode
'message-mode
)
3351 (null message-sent-message-via
))
3352 (push (buffer-name buffer
) buffers
))))
3353 (nreverse buffers
)))
3355 (defun message-cite-original-without-signature ()
3356 "Cite function in the standard Message manner."
3357 (let* ((start (point))
3360 (when message-indent-citation-function
3361 (if (listp message-indent-citation-function
)
3362 message-indent-citation-function
3363 (list message-indent-citation-function
))))
3364 ;; This function may be called by `gnus-summary-yank-message' and
3365 ;; may insert a different article from the original. So, we will
3366 ;; modify the value of `message-reply-headers' with that article.
3367 (message-reply-headers
3369 (narrow-to-region start end
)
3370 (message-narrow-to-head-1)
3372 (or (message-fetch-field "subject") "none")
3373 (or (message-fetch-field "from") "nobody")
3374 (message-fetch-field "date")
3375 (message-fetch-field "message-id" t
)
3376 (message-fetch-field "references")
3378 (mml-quote-region start end
)
3382 (when (re-search-backward message-signature-separator start t
)
3383 ;; Also peel off any blank lines before the signature.
3385 (while (looking-at "^[ \t]*$")
3388 (delete-region (point) end
)
3389 (unless (search-backward "\n\n" start t
)
3390 ;; Insert a blank line if it is peeled off.
3394 (funcall (pop functions
)))
3395 (when message-citation-line-function
3398 (funcall message-citation-line-function
))))
3400 (eval-when-compile (defvar mail-citation-hook
)) ;Compiler directive
3401 (defun message-cite-original ()
3402 "Cite function in the standard Message manner."
3403 (if (and (boundp 'mail-citation-hook
)
3405 (run-hooks 'mail-citation-hook
)
3406 (let* ((start (point))
3409 (when message-indent-citation-function
3410 (if (listp message-indent-citation-function
)
3411 message-indent-citation-function
3412 (list message-indent-citation-function
))))
3413 ;; This function may be called by `gnus-summary-yank-message' and
3414 ;; may insert a different article from the original. So, we will
3415 ;; modify the value of `message-reply-headers' with that article.
3416 (message-reply-headers
3418 (narrow-to-region start end
)
3419 (message-narrow-to-head-1)
3421 (or (message-fetch-field "subject") "none")
3422 (or (message-fetch-field "from") "nobody")
3423 (message-fetch-field "date")
3424 (message-fetch-field "message-id" t
)
3425 (message-fetch-field "references")
3427 (mml-quote-region start end
)
3430 (funcall (pop functions
)))
3431 (when message-citation-line-function
3434 (funcall message-citation-line-function
)))))
3436 (defun message-insert-citation-line ()
3437 "Insert a simple citation line."
3438 (when message-reply-headers
3439 (insert (mail-header-from message-reply-headers
) " writes:")
3443 (defun message-position-on-field (header &rest afters
)
3444 (let ((case-fold-search t
))
3447 (goto-char (point-min))
3450 (concat "^" (regexp-quote mail-header-separator
) "$"))
3451 (match-beginning 0)))
3452 (goto-char (point-min))
3453 (if (re-search-forward (concat "^" (regexp-quote header
) ":") nil t
)
3455 (re-search-forward "^[^ \t]" nil
'move
)
3457 (skip-chars-backward "\n")
3460 (not (re-search-forward
3461 (concat "^" (regexp-quote (car afters
)) ":")
3465 (re-search-forward "^[^ \t]" nil
'move
)
3466 (beginning-of-line))
3467 (insert header
": \n")
3471 (defun message-remove-signature ()
3472 "Remove the signature from the text between point and mark.
3473 The text will also be indented the normal way."
3475 (let ((start (point))
3477 (if (not (re-search-forward message-signature-separator
(mark t
) t
))
3478 ;; No signature here, so we just indent the cited text.
3479 (message-indent-citation)
3480 ;; Find the last non-empty line.
3482 (while (looking-at "[ \t]*$")
3485 (setq mark
(set-marker (make-marker) (point)))
3487 (message-indent-citation)
3488 ;; Enable undoing the deletion.
3490 (delete-region mark
(mark t
))
3491 (set-marker mark nil
)))))
3496 ;;; Sending messages
3499 (defun message-send-and-exit (&optional arg
)
3500 "Send message like `message-send', then, if no errors, exit from mail buffer."
3502 (let ((buf (current-buffer))
3503 (actions message-exit-actions
))
3504 (when (and (message-send arg
)
3506 (if message-kill-buffer-on-exit
3509 (when (eq buf
(current-buffer))
3510 (message-bury buf
)))
3511 (message-do-actions actions
)
3514 (defun message-dont-send ()
3515 "Don't send the message you have been editing.
3516 Instead, just auto-save the buffer and then bury it."
3518 (set-buffer-modified-p t
)
3520 (let ((actions message-postpone-actions
))
3521 (message-bury (current-buffer))
3522 (message-do-actions actions
)))
3524 (defun message-kill-buffer ()
3525 "Kill the current buffer."
3527 (when (or (not (buffer-modified-p))
3528 (yes-or-no-p "Message modified; kill anyway? "))
3529 (let ((actions message-kill-actions
)
3530 (draft-article message-draft-article
)
3531 (auto-save-file-name buffer-auto-save-file-name
)
3532 (file-name buffer-file-name
)
3533 (modified (buffer-modified-p)))
3534 (setq buffer-file-name nil
)
3535 (kill-buffer (current-buffer))
3536 (when (and (or (and auto-save-file-name
3537 (file-exists-p auto-save-file-name
))
3539 (file-exists-p file-name
)))
3541 ;; If the message buffer has lived in a dedicated window,
3542 ;; `kill-buffer' has killed the frame. Thus the
3543 ;; `yes-or-no-p' may show up in a lowered frame. Make sure
3544 ;; that the user can see the question by raising the
3547 (yes-or-no-p (format "Remove the backup file%s? "
3548 (if modified
" too" "")))))
3550 (delete-file auto-save-file-name
))
3551 (let ((message-draft-article draft-article
))
3552 (message-disassociate-draft)))
3553 (message-do-actions actions
))))
3555 (defun message-bury (buffer)
3556 "Bury this mail BUFFER."
3557 (let ((newbuf (other-buffer buffer
)))
3558 (bury-buffer buffer
)
3559 (if (and (window-dedicated-p (selected-window))
3560 (not (null (delq (selected-frame) (visible-frame-list)))))
3561 (delete-frame (selected-frame))
3562 (switch-to-buffer newbuf
))))
3564 (defun message-send (&optional arg
)
3565 "Send the message in the current buffer.
3566 If `message-interactive' is non-nil, wait for success indication or
3567 error messages, and inform user.
3568 Otherwise any failure is reported in a message back to the user from
3570 The usage of ARG is defined by the instance that called Message.
3571 It should typically alter the sending method in some way or other."
3573 ;; Make it possible to undo the coming changes.
3575 (let ((inhibit-read-only t
))
3576 (put-text-property (point-min) (point-max) 'read-only nil
))
3577 (message-fix-before-sending)
3578 (run-hooks 'message-send-hook
)
3579 (message message-sending-message
)
3580 (let ((alist message-send-method-alist
)
3582 elem sent dont-barf-on-no-method
3583 (message-options message-options
))
3584 (message-options-set-recipient)
3586 (setq elem
(pop alist
)))
3587 (when (funcall (cadr elem
))
3588 (when (and (or (not (memq (car elem
)
3589 message-sent-message-via
))
3590 (message-fetch-field "supersedes")
3591 (if (or (message-gnksa-enable-p 'multiple-copies
)
3592 (not (eq (car elem
) 'news
)))
3595 "Already sent message via %s; resend? "
3597 (error "Denied posting -- multiple copies")))
3598 (setq success
(funcall (caddr elem
) arg
)))
3602 (let ((fcc (message-fetch-field "Fcc"))
3603 (gcc (message-fetch-field "Gcc")))
3605 (or (eq message-allow-no-recipients
'always
)
3606 (and (not (eq message-allow-no-recipients
'never
))
3607 (setq dont-barf-on-no-method
3609 (format "No receiver, perform %s anyway? "
3610 (cond ((and fcc gcc
) "Fcc and Gcc")
3613 (error "No methods specified to send by"))
3614 (when (or dont-barf-on-no-method
3618 (run-hooks 'message-sent-hook
))
3619 (message "Sending...done")
3620 ;; Mark the buffer as unmodified and delete auto-save.
3621 (set-buffer-modified-p nil
)
3622 (delete-auto-save-file-if-necessary t
)
3623 (message-disassociate-draft)
3624 ;; Delete other mail buffers and stuff.
3625 (message-do-send-housekeeping)
3626 (message-do-actions message-send-actions
)
3630 (defun message-send-via-mail (arg)
3631 "Send the current message via mail."
3632 (message-send-mail arg
))
3634 (defun message-send-via-news (arg)
3635 "Send the current message via news."
3636 (funcall message-send-news-function arg
))
3638 (defmacro message-check
(type &rest forms
)
3639 "Eval FORMS if TYPE is to be checked."
3640 `(or (message-check-element ,type
)
3644 (put 'message-check
'lisp-indent-function
1)
3645 (put 'message-check
'edebug-form-spec
'(form body
))
3647 (defun message-text-with-property (prop)
3648 "Return a list of all points where the text has PROP."
3650 (point (point-min)))
3652 (while (< point
(point-max))
3653 (when (get-text-property point prop
)
3654 (push point points
))
3658 (defun message-fix-before-sending ()
3659 "Do various things to make the message nice before sending it."
3660 ;; Make sure there's a newline at the end of the message.
3661 (goto-char (point-max))
3664 ;; Make the hidden headers visible.
3665 (let ((points (message-text-with-property 'message-hidden
)))
3667 (goto-char (car points
))
3668 (dolist (point points
)
3669 (add-text-properties point
(1+ point
)
3670 '(invisible nil intangible nil
)))))
3671 ;; Make invisible text visible.
3672 ;; It doesn't seem as if this is useful, since the invisible property
3673 ;; is clobbered by an after-change hook anyhow.
3674 (message-check 'invisible-text
3675 (let ((points (message-text-with-property 'invisible
)))
3677 (goto-char (car points
))
3678 (dolist (point points
)
3679 (put-text-property point
(1+ point
) 'invisible nil
)
3680 (message-overlay-put (message-make-overlay point
(1+ point
))
3682 (unless (yes-or-no-p
3683 "Invisible text found and made visible; continue sending? ")
3684 (error "Invisible text found and made visible")))))
3685 (message-check 'illegible-text
3688 (skip-chars-forward mm-7bit-chars
)
3690 (when (let ((char (char-after)))
3691 (or (< (mm-char-int char
) 128)
3692 (and (mm-multibyte-p)
3693 (memq (char-charset char
)
3694 '(eight-bit-control eight-bit-graphic
3696 (not (get-text-property
3697 (point) 'untranslated-utf-8
)))))
3698 (message-overlay-put (message-make-overlay (point) (1+ (point)))
3702 (skip-chars-forward mm-7bit-chars
))
3705 (gnus-multiple-choice
3706 "Non-printable characters found. Continue sending?"
3707 `((?d
"Remove non-printable characters and send")
3709 "Replace non-printable characters with \"%s\" and send"
3710 message-replacement-char
))
3711 (?i
"Ignore non-printable characters and send")
3712 (?e
"Continue editing"))))
3714 (error "Non-printable characters"))
3716 (skip-chars-forward mm-7bit-chars
)
3718 (when (let ((char (char-after)))
3719 (or (< (mm-char-int char
) 128)
3720 (and (mm-multibyte-p)
3721 ;; FIXME: Wrong for Emacs 23 (unicode) and for
3722 ;; things like undecable utf-8. Should at least
3723 ;; use find-coding-systems-region.
3724 (memq (char-charset char
)
3725 '(eight-bit-control eight-bit-graphic
3727 (not (get-text-property
3728 (point) 'untranslated-utf-8
)))))
3730 (message-kill-all-overlays)
3732 (when (eq choice ?r
)
3733 (insert message-replacement-char
))))
3735 (skip-chars-forward mm-7bit-chars
))))))
3737 (defun message-add-action (action &rest types
)
3738 "Add ACTION to be performed when doing an exit of type TYPES."
3740 (add-to-list (intern (format "message-%s-actions" (pop types
)))
3743 (defun message-delete-action (action &rest types
)
3744 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
3747 (set (setq var
(intern (format "message-%s-actions" (pop types
))))
3748 (delq action
(symbol-value var
))))))
3750 (defun message-do-actions (actions)
3751 "Perform all actions in ACTIONS."
3752 ;; Now perform actions on successful sending.
3756 ;; A simple function.
3757 ((functionp (car actions
))
3758 (funcall (car actions
)))
3759 ;; Something to be evaled.
3761 (eval (car actions
)))))
3764 (defun message-send-mail-partially ()
3765 "Send mail as message/partial."
3766 ;; replace the header delimiter with a blank line
3767 (goto-char (point-min))
3769 (concat "^" (regexp-quote mail-header-separator
) "\n"))
3770 (replace-match "\n")
3771 (run-hooks 'message-send-mail-hook
)
3772 (let ((p (goto-char (point-min)))
3773 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
3774 (curbuf (current-buffer))
3775 (id (message-make-message-id)) (n 1)
3776 plist total header required-mail-headers
)
3778 (if (< (point-max) (+ p message-send-mail-partially-limit
))
3779 (goto-char (point-max))
3780 (goto-char (+ p message-send-mail-partially-limit
))
3782 (if (<= (point) p
) (forward-line 1))) ;; In case of bad message.
3785 (setq total
(length plist
))
3786 (push (point-max) plist
)
3787 (setq plist
(nreverse plist
))
3790 (setq p
(pop plist
))
3793 (copy-to-buffer tembuf p
(car plist
))
3795 (goto-char (point-min))
3798 (goto-char (point-min))
3799 (narrow-to-region (point) (point))
3802 (setq header
(buffer-substring (point-min) (point)))
3803 (goto-char (point-min))
3804 (narrow-to-region (point) (point))
3806 (message-remove-header "Mime-Version")
3807 (message-remove-header "Content-Type")
3808 (message-remove-header "Content-Transfer-Encoding")
3809 (message-remove-header "Message-ID")
3810 (message-remove-header "Lines")
3811 (goto-char (point-max))
3812 (insert "Mime-Version: 1.0\n")
3813 (setq header
(buffer-string)))
3814 (goto-char (point-max))
3815 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
3818 (let ((mail-header-separator ""))
3819 (when (memq 'Message-ID message-required-mail-headers
)
3820 (insert "Message-ID: " (message-make-message-id) "\n"))
3821 (when (memq 'Lines message-required-mail-headers
)
3822 (insert "Lines: " (message-make-lines) "\n"))
3823 (message-goto-subject)
3825 (insert (format " (%d/%d)" n total
))
3827 (mm-with-unibyte-current-buffer
3828 (funcall (or message-send-mail-real-function
3829 message-send-mail-function
))))
3831 (setq p
(pop plist
))
3833 (kill-buffer tembuf
))))
3835 (defun message-send-mail (&optional arg
)
3836 (require 'mail-utils
)
3837 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
3838 (case-fold-search nil
)
3839 (news (message-news-p))
3840 (mailbuf (current-buffer))
3841 (message-this-is-mail t
)
3842 (message-posting-charset
3843 (if (fboundp 'gnus-setup-posting-charset
)
3844 (gnus-setup-posting-charset nil
)
3845 message-posting-charset
))
3846 (headers message-required-mail-headers
))
3848 (message-narrow-to-headers)
3849 ;; Generate the Mail-Followup-To header if the header is not there...
3850 (if (and (message-subscribed-p)
3851 (not (mail-fetch-field "mail-followup-to")))
3854 (cons "Mail-Followup-To" (message-make-mail-followup-to))
3855 message-required-mail-headers
))
3856 ;; otherwise, delete the MFT header if the field is empty
3857 (when (equal "" (mail-fetch-field "mail-followup-to"))
3858 (message-remove-header "^Mail-Followup-To:")))
3859 ;; Insert some headers.
3860 (let ((message-deletable-headers
3861 (if news nil message-deletable-headers
)))
3862 (message-generate-headers headers
))
3863 ;; Check continuation headers.
3864 (message-check 'continuation-headers
3865 (goto-char (point-min))
3866 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t
)
3867 (goto-char (match-beginning 0))
3868 (if (y-or-n-p "Fix continuation lines? ")
3871 (unless (y-or-n-p "Send anyway? ")
3872 (error "Failed to send the message")))))
3873 ;; Let the user do all of the above.
3874 (run-hooks 'message-header-hook
))
3879 ;; Avoid copying text props (except hard newlines).
3880 (insert (with-current-buffer mailbuf
3881 (mml-buffer-substring-no-properties-except-hard-newlines
3882 (point-min) (point-max))))
3883 ;; Remove some headers.
3884 (message-encode-message-body)
3886 (message-narrow-to-headers)
3887 ;; We (re)generate the Lines header.
3888 (when (memq 'Lines message-required-mail-headers
)
3889 (message-generate-headers '(Lines)))
3890 ;; Remove some headers.
3891 (message-remove-header message-ignored-mail-headers t
)
3892 (let ((mail-parse-charset message-default-charset
))
3893 (mail-encode-encoded-word-buffer)))
3894 (goto-char (point-max))
3895 ;; require one newline at the end.
3896 (or (= (preceding-char) ?
\n)
3898 (message-cleanup-headers)
3899 ;; FIXME: we're inserting the courtesy copy after encoding.
3900 ;; This is wrong if the courtesy copy string contains
3901 ;; non-ASCII characters. -- jh
3904 (message-narrow-to-headers)
3906 (or (message-fetch-field "cc")
3907 (message-fetch-field "bcc")
3908 (message-fetch-field "to"))
3909 (let ((content-type (message-fetch-field
3914 (string= "text/plain"
3916 (mail-header-parse-content-type
3920 (message-fetch-field
3921 "content-transfer-encoding")))))))
3922 (message-insert-courtesy-copy))
3923 (if (or (not message-send-mail-partially-limit
)
3924 (< (buffer-size) message-send-mail-partially-limit
)
3925 (not (message-y-or-n-p
3926 "The message size is too large, split? "
3930 (/ (buffer-size) 1000) "KB, is too large.
3932 Some mail gateways (MTA's) bounce large messages. To avoid the
3933 problem, answer `y', and the message will be split into several
3934 smaller pieces, the size of each is about "
3935 (/ message-send-mail-partially-limit
1000)
3939 However, some mail readers (MUA's) can't read split messages, i.e.,
3940 mails in message/partially format. Answer `n', and the message will be
3943 The size limit is controlled by `message-send-mail-partially-limit'.
3944 If you always want Gnus to send messages in one piece, set
3945 `message-send-mail-partially-limit' to nil.
3947 (mm-with-unibyte-current-buffer
3948 (message "Sending via mail...")
3949 (funcall (or message-send-mail-real-function
3950 message-send-mail-function
)))
3951 (message-send-mail-partially)))
3952 (kill-buffer tembuf
))
3953 (set-buffer mailbuf
)
3954 (push 'mail message-sent-message-via
)))
3956 (defun message-send-mail-with-sendmail ()
3957 "Send off the prepared buffer with sendmail."
3958 (let ((errbuf (if message-interactive
3959 (message-generate-new-buffer-clone-locals
3962 resend-to-addresses delimline
)
3965 (let ((case-fold-search t
))
3967 (message-narrow-to-headers)
3968 (setq resend-to-addresses
(message-fetch-field "resent-to")))
3969 ;; Change header-delimiter to be what sendmail expects.
3970 (goto-char (point-min))
3972 (concat "^" (regexp-quote mail-header-separator
) "\n"))
3973 (replace-match "\n")
3975 (setq delimline
(point-marker))
3976 (run-hooks 'message-send-mail-hook
)
3977 ;; Insert an extra newline if we need it to work around
3978 ;; Sun's bug that swallows newlines.
3979 (goto-char (1+ delimline
))
3980 (when (eval message-mailer-swallows-blank-line
)
3982 (when message-interactive
3986 (let* ((default-directory "/")
3987 (coding-system-for-write message-send-coding-system
)
3989 'call-process-region
3991 (list (point-min) (point-max)
3992 (cond ((boundp 'sendmail-program
)
3994 ((file-exists-p "/usr/sbin/sendmail")
3995 "/usr/sbin/sendmail")
3996 ((file-exists-p "/usr/lib/sendmail")
3997 "/usr/lib/sendmail")
3998 ((file-exists-p "/usr/ucblib/sendmail")
3999 "/usr/ucblib/sendmail")
4001 nil errbuf nil
"-oi")
4002 ;; Always specify who from,
4003 ;; since some systems have broken sendmails.
4004 ;; But some systems are more broken with -f, so
4005 ;; we'll let users override this.
4006 (if (null message-sendmail-f-is-evil
)
4007 (list "-f" (message-sendmail-envelope-from)))
4008 ;; These mean "report errors by mail"
4009 ;; and "deliver in background".
4010 (if (null message-interactive
) '("-oem" "-odb"))
4011 ;; Get the addresses from the message
4012 ;; unless this is a resend.
4013 ;; We must not do that for a resend
4014 ;; because we would find the original addresses.
4015 ;; For a resend, include the specific addresses.
4016 (if resend-to-addresses
4017 (list resend-to-addresses
)
4019 (unless (or (null cpr
) (and (numberp cpr
) (zerop cpr
)))
4020 (error "Sending...failed with exit value %d" cpr
)))
4021 (when message-interactive
4024 (goto-char (point-min))
4025 (while (re-search-forward "\n\n* *" nil t
)
4026 (replace-match "; "))
4027 (if (not (zerop (buffer-size)))
4028 (error "Sending...failed to %s"
4029 (buffer-string))))))
4030 (when (bufferp errbuf
)
4031 (kill-buffer errbuf
)))))
4033 (defun message-send-mail-with-qmail ()
4034 "Pass the prepared message buffer to qmail-inject.
4035 Refer to the documentation for the variable `message-send-mail-function'
4036 to find out how to use this."
4037 ;; replace the header delimiter with a blank line
4038 (goto-char (point-min))
4040 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4041 (replace-match "\n")
4042 (run-hooks 'message-send-mail-hook
)
4045 (let ((coding-system-for-write message-send-coding-system
))
4047 'call-process-region
(point-min) (point-max)
4048 message-qmail-inject-program nil nil nil
4049 ;; qmail-inject's default behaviour is to look for addresses on the
4050 ;; command line; if there're none, it scans the headers.
4051 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4053 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4054 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4055 ;; message from stdin.
4057 ;; qmail also has the advantage of not having been raped by
4058 ;; various vendors, so we don't have to allow for that, either --
4059 ;; compare this with message-send-mail-with-sendmail and weep
4060 ;; for sendmail's lost innocence.
4062 ;; all this is way cool coz it lets us keep the arguments entirely
4063 ;; free for -inject-arguments -- a big win for the user and for us
4064 ;; since we don't have to play that double-guessing game and the user
4065 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4066 (if (functionp message-qmail-inject-args
)
4067 (funcall message-qmail-inject-args
)
4068 message-qmail-inject-args
)))
4069 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4070 ;; we have to look at the retval instead
4072 (100 (error "qmail-inject reported permanent failure"))
4073 (111 (error "qmail-inject reported transient failure"))
4074 ;; should never happen
4075 (t (error "qmail-inject reported unknown failure"))))
4077 (defun message-send-mail-with-mh ()
4078 "Send the prepared message buffer with mh."
4079 (let ((mh-previous-window-config nil
)
4080 (name (mh-new-draft-name)))
4081 (setq buffer-file-name name
)
4082 ;; MH wants to generate these headers itself.
4083 (when message-mh-deletable-headers
4084 (let ((headers message-mh-deletable-headers
))
4086 (goto-char (point-min))
4087 (and (re-search-forward
4088 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
4089 (message-delete-line))
4091 (run-hooks 'message-send-mail-hook
)
4092 ;; Pass it on to mh.
4095 (defun message-smtpmail-send-it ()
4096 "Send the prepared message buffer with `smtpmail-send-it'.
4097 This only differs from `smtpmail-send-it' that this command evaluates
4098 `message-send-mail-hook' just before sending a message. It is useful
4099 if your ISP requires the POP-before-SMTP authentication. See the Gnus
4100 manual for details."
4101 (run-hooks 'message-send-mail-hook
)
4104 (defun message-canlock-generate ()
4105 "Return a string that is non-trivial to guess.
4106 Do not use this for anything important, it is cryptographically weak."
4108 (let (sha1-maximum-internal-length)
4109 (sha1 (concat (message-unique-id)
4110 (format "%x%x%x" (random) (random t
) (random))
4111 (prin1-to-string (recent-keys))
4112 (prin1-to-string (garbage-collect))))))
4114 (defun message-canlock-password ()
4115 "The password used by message for cancel locks.
4116 This is the value of `canlock-password', if that option is non-nil.
4117 Otherwise, generate and save a value for `canlock-password' first."
4118 (unless canlock-password
4119 (customize-save-variable 'canlock-password
(message-canlock-generate))
4120 (setq canlock-password-for-verify canlock-password
))
4123 (defun message-insert-canlock ()
4124 (when message-insert-canlock
4125 (message-canlock-password)
4126 (canlock-insert-header)))
4128 (defun message-send-news (&optional arg
)
4129 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4130 (case-fold-search nil
)
4131 (method (if (functionp message-post-method
)
4132 (funcall message-post-method arg
)
4133 message-post-method
))
4134 (newsgroups-field (save-restriction
4135 (message-narrow-to-headers-or-head)
4136 (message-fetch-field "Newsgroups")))
4137 (followup-field (save-restriction
4138 (message-narrow-to-headers-or-head)
4139 (message-fetch-field "Followup-To")))
4140 ;; BUG: We really need to get the charset for each name in the
4141 ;; Newsgroups and Followup-To lines to allow crossposting
4142 ;; between group namess with incompatible character sets.
4143 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4144 (group-field-charset
4145 (gnus-group-name-charset method newsgroups-field
))
4146 (followup-field-charset
4147 (gnus-group-name-charset method
(or followup-field
"")))
4148 (rfc2047-header-encoding-alist
4149 (append (when group-field-charset
4150 (list (cons "Newsgroups" group-field-charset
)))
4151 (when followup-field-charset
4152 (list (cons "Followup-To" followup-field-charset
)))
4153 rfc2047-header-encoding-alist
))
4154 (messbuf (current-buffer))
4155 (message-syntax-checks
4157 (listp message-syntax-checks
))
4158 (cons '(existing-newsgroups . disabled
)
4159 message-syntax-checks
)
4160 message-syntax-checks
))
4161 (message-this-is-news t
)
4162 (message-posting-charset
4163 (gnus-setup-posting-charset newsgroups-field
))
4165 (if (not (message-check-news-body-syntax))
4168 (message-narrow-to-headers)
4169 ;; Insert some headers.
4170 (message-generate-headers message-required-news-headers
)
4171 (message-insert-canlock)
4172 ;; Let the user do all of the above.
4173 (run-hooks 'message-header-hook
))
4174 ;; Note: This check will be disabled by the ".*" default value for
4175 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4176 (when (and group-field-charset
4177 (listp message-syntax-checks
))
4178 (setq message-syntax-checks
4179 (cons '(valid-newsgroups . disabled
)
4180 message-syntax-checks
)))
4181 (message-cleanup-headers)
4182 (if (not (let ((message-post-method method
))
4183 (message-check-news-syntax)))
4188 (buffer-disable-undo)
4190 ;; Avoid copying text props (except hard newlines).
4192 (with-current-buffer messbuf
4193 (mml-buffer-substring-no-properties-except-hard-newlines
4194 (point-min) (point-max))))
4195 (message-encode-message-body)
4196 ;; Remove some headers.
4198 (message-narrow-to-headers)
4199 ;; We (re)generate the Lines header.
4200 (when (memq 'Lines message-required-mail-headers
)
4201 (message-generate-headers '(Lines)))
4202 ;; Remove some headers.
4203 (message-remove-header message-ignored-news-headers t
)
4204 (let ((mail-parse-charset message-default-charset
))
4205 (mail-encode-encoded-word-buffer)))
4206 (goto-char (point-max))
4207 ;; require one newline at the end.
4208 (or (= (preceding-char) ?
\n)
4210 (let ((case-fold-search t
))
4211 ;; Remove the delimiter.
4212 (goto-char (point-min))
4214 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4215 (replace-match "\n")
4217 (run-hooks 'message-send-news-hook
)
4218 (gnus-open-server method
)
4219 (message "Sending news via %s..." (gnus-server-string method
))
4220 (setq result
(let ((mail-header-separator ""))
4221 (gnus-request-post method
))))
4222 (kill-buffer tembuf
))
4223 (set-buffer messbuf
)
4225 (push 'news message-sent-message-via
)
4226 (message "Couldn't send message via news: %s"
4227 (nnheader-get-report (car method
)))
4231 ;;; Header generation & syntax checking.
4234 (defun message-check-element (type)
4235 "Return non-nil if this TYPE is not to be checked."
4236 (if (eq message-syntax-checks
'dont-check-for-anything-just-trust-me
)
4238 (let ((able (assq type message-syntax-checks
)))
4240 (eq (cdr able
) 'disabled
)))))
4242 (defun message-check-news-syntax ()
4243 "Check the syntax of the message."
4247 ;; We narrow to the headers and check them first.
4250 (message-narrow-to-headers)
4251 (message-check-news-header-syntax))))))
4253 (defun message-check-news-header-syntax ()
4255 ;; Check Newsgroups header.
4256 (message-check 'newsgroups
4257 (let ((group (message-fetch-field "newsgroups")))
4260 (not (string-match "\\`[ \t]*\\'" group
)))
4263 "The newsgroups field is empty or missing. Posting is denied.")))))
4264 ;; Check the Subject header.
4265 (message-check 'subject
4266 (let* ((case-fold-search t
)
4267 (subject (message-fetch-field "subject")))
4270 (not (string-match "\\`[ \t]*\\'" subject
)))
4273 "The subject field is empty or missing. Posting is denied.")))))
4274 ;; Check for commands in Subject.
4275 (message-check 'subject-cmsg
4276 (if (string-match "^cmsg " (message-fetch-field "subject"))
4278 "The control code \"cmsg\" is in the subject. Really post? ")
4280 ;; Check long header lines.
4281 (message-check 'long-header-lines
4282 (let ((start (point))
4286 (while (and (not found
)
4287 (re-search-forward "^\\([^ \t:]+\\): " nil t
))
4288 (if (> (- (point) (match-beginning 0)) 998)
4290 length
(- (point) (match-beginning 0)))
4291 (setq header
(match-string-no-properties 1)))
4292 (setq start
(match-beginning 0))
4295 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
4298 ;; Check for multiple identical headers.
4299 (message-check 'multiple-headers
4301 (while (and (not found
)
4302 (re-search-forward "^[^ \t:]+: " nil t
))
4304 (or (re-search-forward
4309 (match-beginning 0) (- (match-end 0) 2))))
4314 (y-or-n-p (format "Multiple %s headers. Really post? " found
))
4316 ;; Check for Version and Sendsys.
4317 (message-check 'sendsys
4318 (if (re-search-forward "^Sendsys:\\|^Version:" nil t
)
4320 (format "The article contains a %s command. Really post? "
4321 (buffer-substring (match-beginning 0)
4322 (1- (match-end 0)))))
4324 ;; See whether we can shorten Followup-To.
4325 (message-check 'shorten-followup-to
4326 (let ((newsgroups (message-fetch-field "newsgroups"))
4327 (followup-to (message-fetch-field "followup-to"))
4329 (when (and newsgroups
4330 (string-match "," newsgroups
)
4335 (setq to
(completing-read
4336 "Followups to (default no Followup-To header): "
4339 (message-tokenize-header
4341 (goto-char (point-min))
4342 (insert "Followup-To: " to
"\n"))
4344 ;; Check "Shoot me".
4345 (message-check 'shoot
4346 (if (re-search-forward
4347 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t
)
4348 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
4350 ;; Check for Approved.
4351 (message-check 'approved
4352 (if (re-search-forward "^Approved:" nil t
)
4353 (y-or-n-p "The article contains an Approved header. Really post? ")
4355 ;; Check the Message-ID header.
4356 (message-check 'message-id
4357 (let* ((case-fold-search t
)
4358 (message-id (message-fetch-field "message-id" t
)))
4359 (or (not message-id
)
4360 ;; Is there an @ in the ID?
4361 (and (string-match "@" message-id
)
4362 ;; Is there a dot in the ID?
4363 (string-match "@[^.]*\\." message-id
)
4364 ;; Does the ID end with a dot?
4365 (not (string-match "\\.>" message-id
)))
4367 (format "The Message-ID looks strange: \"%s\". Really post? "
4369 ;; Check the Newsgroups & Followup-To headers.
4370 (message-check 'existing-newsgroups
4371 (let* ((case-fold-search t
)
4372 (newsgroups (message-fetch-field "newsgroups"))
4373 (followup-to (message-fetch-field "followup-to"))
4374 (groups (message-tokenize-header
4376 (concat newsgroups
"," followup-to
)
4378 (post-method (if (functionp message-post-method
)
4379 (funcall message-post-method
)
4380 message-post-method
))
4381 ;; KLUDGE to handle nnvirtual groups. Doing this right
4382 ;; would probably involve a new nnoo function.
4383 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
4384 (method (if (and (consp post-method
)
4385 (eq (car post-method
) 'nnvirtual
)
4386 gnus-message-group-art
)
4387 (let ((group (car (nnvirtual-find-group-art
4388 (car gnus-message-group-art
)
4389 (cdr gnus-message-group-art
)))))
4390 (gnus-find-method-for-group group
))
4394 (gnus-group-name-decode
4395 (gnus-group-real-name n
)
4396 (gnus-group-name-charset method n
)))
4397 (gnus-groups-from-server method
)))
4400 (when (and (not (equal (car groups
) "poster"))
4401 (not (member (car groups
) known-groups
))
4402 (not (member (car groups
) errors
)))
4403 (push (car groups
) errors
))
4406 ;; Gnus is not running.
4407 ((or (not (and (boundp 'gnus-active-hashtb
)
4408 gnus-active-hashtb
))
4409 (not (boundp 'gnus-read-active-file
)))
4411 ;; We don't have all the group names.
4412 ((and (or (not gnus-read-active-file
)
4413 (eq gnus-read-active-file
'some
))
4417 "Really use %s possibly unknown group%s: %s? "
4418 (if (= (length errors
) 1) "this" "these")
4419 (if (= (length errors
) 1) "" "s")
4420 (mapconcat 'identity errors
", "))))
4421 ;; There were no errors.
4424 ;; There are unknown groups.
4428 "Really post to %s unknown group%s: %s? "
4429 (if (= (length errors
) 1) "this" "these")
4430 (if (= (length errors
) 1) "" "s")
4431 (mapconcat 'identity errors
", ")))))))
4432 ;; Check continuation headers.
4433 (message-check 'continuation-headers
4434 (goto-char (point-min))
4435 (let ((do-posting t
))
4436 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t
)
4437 (goto-char (match-beginning 0))
4438 (if (y-or-n-p "Fix continuation lines? ")
4441 (unless (y-or-n-p "Send anyway? ")
4442 (setq do-posting nil
))))
4444 ;; Check the Newsgroups & Followup-To headers for syntax errors.
4445 (message-check 'valid-newsgroups
4446 (let ((case-fold-search t
)
4447 (headers '("Newsgroups" "Followup-To"))
4449 (while (and headers
(not error
))
4450 (when (setq header
(mail-fetch-field (car headers
)))
4454 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
4459 (not (string-match "\\.\\'\\|\\.\\." g
)))
4460 (message-tokenize-header header
","))))
4467 (format "The %s header looks odd: \"%s\". Really post? "
4468 (car headers
) header
)))))
4469 (message-check 'repeated-newsgroups
4470 (let ((case-fold-search t
)
4471 (headers '("Newsgroups" "Followup-To"))
4472 header error groups group
)
4475 (when (setq header
(mail-fetch-field (pop headers
)))
4476 (setq groups
(message-tokenize-header header
","))
4477 (while (setq group
(pop groups
))
4478 (when (member group groups
)
4484 (format "Group %s is repeated in headers. Really post? " error
)))))
4485 ;; Check the From header.
4486 (message-check 'from
4487 (let* ((case-fold-search t
)
4488 (from (message-fetch-field "from"))
4492 (message "There is no From line. Posting is denied.")
4494 ((or (not (string-match
4496 (setq ad
(nth 1 (mail-extract-address-components
4497 from
))))) ;larsi@ifi
4498 (string-match "\\.\\." ad
) ;larsi@ifi..uio
4499 (string-match "@\\." ad
) ;larsi@.ifi.uio
4500 (string-match "\\.$" ad
) ;larsi@ifi.uio.
4501 (not (string-match "^[^@]+@[^@]+$" ad
)) ;larsi.ifi.uio
4502 (string-match "(.*).*(.*)" from
)) ;(lars) (lars)
4504 "Denied posting -- the From looks strange: \"%s\"." from
)
4506 ((let ((addresses (rfc822-addresses from
)))
4507 (while (and addresses
4508 (not (eq (string-to-char (car addresses
)) ?\
()))
4509 (setq addresses
(cdr addresses
)))
4512 "Denied posting -- bad From address: \"%s\"." from
)
4515 ;; Check the Reply-To header.
4516 (message-check 'reply-to
4517 (let* ((case-fold-search t
)
4518 (reply-to (message-fetch-field "reply-to"))
4523 ((string-match "," reply-to
)
4525 (format "Multiple Reply-To addresses: \"%s\". Really post? "
4527 ((or (not (string-match
4529 (setq ad
(nth 1 (mail-extract-address-components
4530 reply-to
))))) ;larsi@ifi
4531 (string-match "\\.\\." ad
) ;larsi@ifi..uio
4532 (string-match "@\\." ad
) ;larsi@.ifi.uio
4533 (string-match "\\.$" ad
) ;larsi@ifi.uio.
4534 (not (string-match "^[^@]+@[^@]+$" ad
)) ;larsi.ifi.uio
4535 (string-match "(.*).*(.*)" reply-to
)) ;(lars) (lars)
4538 "The Reply-To looks strange: \"%s\". Really post? "
4542 (defun message-check-news-body-syntax ()
4544 ;; Check for long lines.
4545 (message-check 'long-lines
4546 (goto-char (point-min))
4548 (concat "^" (regexp-quote mail-header-separator
) "$"))
4552 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
4555 (< (- (point) p
) 80)))
4556 (zerop (forward-line 1))))
4560 "You have lines longer than 79 characters. Really post? ")))
4561 ;; Check whether the article is empty.
4562 (message-check 'empty
4563 (goto-char (point-min))
4565 (concat "^" (regexp-quote mail-header-separator
) "$"))
4568 (goto-char (point-max))
4569 (re-search-backward message-signature-separator nil t
)
4571 (or (re-search-backward "[^ \n\t]" b t
)
4572 (if (message-gnksa-enable-p 'empty-article
)
4573 (y-or-n-p "Empty article. Really post? ")
4574 (message "Denied posting -- Empty article.")
4576 ;; Check for control characters.
4577 (message-check 'control-chars
4578 (if (re-search-forward
4579 (mm-string-as-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
4582 "The article contains control characters. Really post? ")
4584 ;; Check excessive size.
4585 (message-check 'size
4586 (if (> (buffer-size) 60000)
4588 (format "The article is %d octets long. Really post? "
4591 ;; Check whether any new text has been added.
4592 (message-check 'new-text
4594 (not message-checksum
)
4595 (not (eq (message-checksum) message-checksum
))
4596 (if (message-gnksa-enable-p 'quoted-text-only
)
4598 "It looks like no new text has been added. Really post? ")
4599 (message "Denied posting -- no new text has been added.")
4601 ;; Check the length of the signature.
4602 (message-check 'signature
4603 (goto-char (point-max))
4604 (if (> (count-lines (point) (point-max)) 5)
4607 "Your .sig is %d lines; it should be max 4. Really post? "
4608 (1- (count-lines (point) (point-max)))))
4610 ;; Ensure that text follows last quoted portion.
4611 (message-check 'quoting-style
4612 (goto-char (point-max))
4613 (let ((no-problem t
))
4614 (when (search-backward-regexp "^>[^\n]*\n" nil t
)
4615 (setq no-problem
(search-forward-regexp "^[ \t]*[^>\n]" nil t
)))
4618 (if (message-gnksa-enable-p 'quoted-text-only
)
4619 (y-or-n-p "Your text should follow quoted text. Really post? ")
4621 (goto-char (point-min))
4623 (concat "^" (regexp-quote mail-header-separator
) "$"))
4624 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t
)
4625 (y-or-n-p "Your text should follow quoted text. Really post? ")
4626 (message "Denied posting -- only quoted text.")
4629 (defun message-checksum ()
4630 "Return a \"checksum\" for the current buffer."
4633 (goto-char (point-min))
4635 (concat "^" (regexp-quote mail-header-separator
) "$"))
4637 (when (not (looking-at "[ \t\n]"))
4638 (setq sum
(logxor (ash sum
1) (if (natnump sum
) 0 1)
4643 (defun message-do-fcc ()
4644 "Process Fcc headers in the current buffer."
4645 (let ((case-fold-search t
)
4646 (buf (current-buffer))
4648 (mml-externalize-attachments message-fcc-externalize-attachments
))
4651 (message-narrow-to-headers)
4652 (setq file
(message-fetch-field "fcc" t
)))
4654 (set-buffer (get-buffer-create " *message temp*"))
4656 (insert-buffer-substring buf
)
4657 (message-encode-message-body)
4659 (message-narrow-to-headers)
4660 (while (setq file
(message-fetch-field "fcc" t
))
4662 (message-remove-header "fcc" nil t
))
4663 (let ((mail-parse-charset message-default-charset
)
4664 (rfc2047-header-encoding-alist
4665 (cons '("Newsgroups" . default
)
4666 rfc2047-header-encoding-alist
)))
4667 (mail-encode-encoded-word-buffer)))
4668 (goto-char (point-min))
4669 (when (re-search-forward
4670 (concat "^" (regexp-quote mail-header-separator
) "$")
4672 (replace-match "" t t
))
4673 ;; Process FCC operations.
4675 (setq file
(pop list
))
4676 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file
)
4677 ;; Pipe the article to the program in question.
4678 (call-process-region (point-min) (point-max) shell-file-name
4679 nil nil nil shell-command-switch
4680 (match-string 1 file
))
4681 ;; Save the article.
4682 (setq file
(expand-file-name file
))
4683 (unless (file-exists-p (file-name-directory file
))
4684 (make-directory (file-name-directory file
) t
))
4685 (if (and message-fcc-handler-function
4686 (not (eq message-fcc-handler-function
'rmail-output
)))
4687 (funcall message-fcc-handler-function file
)
4688 (if (and (file-readable-p file
) (mail-file-babyl-p file
))
4689 (rmail-output file
1 nil t
)
4690 (let ((mail-use-rfc822 t
))
4691 (rmail-output file
1 t t
))))))
4692 (kill-buffer (current-buffer))))))
4694 (defun message-output (filename)
4695 "Append this article to Unix/babyl mail file FILENAME."
4696 (if (and (file-readable-p filename
)
4697 (mail-file-babyl-p filename
))
4698 (gnus-output-to-rmail filename t
)
4699 (gnus-output-to-mail filename t
)))
4701 (defun message-cleanup-headers ()
4702 "Do various automatic cleanups of the headers."
4703 ;; Remove empty lines in the header.
4705 (message-narrow-to-headers)
4706 ;; Remove blank lines.
4707 (while (re-search-forward "^[ \t]*\n" nil t
)
4708 (replace-match "" t t
))
4710 ;; Correct Newsgroups and Followup-To headers: Change sequence of
4711 ;; spaces to comma and eliminate spaces around commas. Eliminate
4712 ;; embedded line breaks.
4713 (goto-char (point-min))
4714 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t
)
4718 (if (re-search-forward "^[^ \t]" nil t
)
4722 (goto-char (point-min))
4723 (while (re-search-forward "\n[ \t]+" nil t
)
4724 (replace-match " " t t
)) ;No line breaks (too confusing)
4725 (goto-char (point-min))
4726 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t
)
4727 (replace-match "," t t
))
4728 (goto-char (point-min))
4729 ;; Remove trailing commas.
4730 (when (re-search-forward ",+$" nil t
)
4731 (replace-match "" t t
))))))
4733 (eval-when-compile (require 'parse-time
))
4734 (defun message-make-date (&optional now
)
4735 "Make a valid data header.
4736 If NOW, use that time instead."
4737 (require 'parse-time
)
4738 (let* ((now (or now
(current-time)))
4739 (zone (nth 8 (decode-time now
)))
4743 (setq zone
(- zone
)))
4745 ;; The day name of the %a spec is locale-specific. Pfff.
4746 (format "%s, " (capitalize (car (rassoc (nth 6 (decode-time now
))
4747 parse-time-weekdays
))))
4748 (format-time-string "%d" now
)
4749 ;; The month name of the %b spec is locale-specific. Pfff.
4751 (capitalize (car (rassoc (nth 4 (decode-time now
))
4752 parse-time-months
))))
4753 (format-time-string "%Y %H:%M:%S " now
)
4754 ;; We do all of this because XEmacs doesn't have the %z spec.
4755 (format "%s%02d%02d" sign
(/ zone
3600) (/ (% zone
3600) 60)))))
4757 (defun message-make-message-id ()
4758 "Make a unique Message-ID."
4759 (concat "<" (message-unique-id)
4760 (let ((psubject (save-excursion (message-fetch-field "subject")))
4762 (save-excursion (message-fetch-field "supersedes"))))
4764 (and message-reply-headers
4765 (mail-header-references message-reply-headers
)
4766 (mail-header-subject message-reply-headers
)
4769 (message-strip-subject-re
4770 (mail-header-subject message-reply-headers
))
4771 (message-strip-subject-re psubject
))))
4773 (string-match "_-_@" psupersedes
)))
4775 "@" (message-make-fqdn) ">"))
4777 (defvar message-unique-id-char nil
)
4779 ;; If you ever change this function, make sure the new version
4780 ;; cannot generate IDs that the old version could.
4781 ;; You might for example insert a "." somewhere (not next to another dot
4782 ;; or string boundary), or modify the "fsf" string.
4783 (defun message-unique-id ()
4784 ;; Don't use microseconds from (current-time), they may be unsupported.
4785 ;; Instead we use this randomly inited counter.
4786 (setq message-unique-id-char
4787 (%
(1+ (or message-unique-id-char
(logand (random t
) (1- (lsh 1 20)))))
4788 ;; (current-time) returns 16-bit ints,
4789 ;; and 2^16*25 just fits into 4 digits i base 36.
4791 (let ((tm (current-time)))
4793 (if (or (memq system-type
'(ms-dos emx vax-vms
))
4794 ;; message-number-base36 doesn't handle bigints.
4795 (floatp (user-uid)))
4796 (let ((user (downcase (user-login-name))))
4797 (while (string-match "[^a-z0-9_]" user
)
4798 (aset user
(match-beginning 0) ?_
))
4800 (message-number-base36 (user-uid) -
1))
4801 (message-number-base36 (+ (car tm
)
4802 (lsh (% message-unique-id-char
25) 16)) 4)
4803 (message-number-base36 (+ (nth 1 tm
)
4804 (lsh (/ message-unique-id-char
25) 16)) 4)
4805 ;; Append a given name, because while the generated ID is unique
4806 ;; to this newsreader, other newsreaders might otherwise generate
4807 ;; the same ID via another algorithm.
4810 (defun message-number-base36 (num len
)
4815 (concat (message-number-base36 (/ num
36) (1- len
))
4816 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
4819 (defun message-make-organization ()
4820 "Make an Organization header."
4821 (let* ((organization
4822 (when message-user-organization
4823 (if (functionp message-user-organization
)
4824 (funcall message-user-organization
)
4825 message-user-organization
))))
4827 (mm-enable-multibyte)
4828 (cond ((stringp organization
)
4829 (insert organization
))
4830 ((and (eq t organization
)
4831 message-user-organization-file
4832 (file-exists-p message-user-organization-file
))
4833 (insert-file-contents message-user-organization-file
)))
4834 (goto-char (point-min))
4835 (while (re-search-forward "[\t\n]+" nil t
)
4836 (replace-match "" t t
))
4837 (unless (zerop (buffer-size))
4840 (defun message-make-lines ()
4841 "Count the number of lines and return numeric string."
4846 (int-to-string (count-lines (point) (point-max))))))
4848 (defun message-make-references ()
4849 "Return the References header for this message."
4850 (when message-reply-headers
4851 (let ((message-id (mail-header-message-id message-reply-headers
))
4852 (references (mail-header-references message-reply-headers
))
4854 (if (or references message-id
)
4855 (concat (or references
"") (and references
" ")
4859 (defun message-make-in-reply-to ()
4860 "Return the In-Reply-To header for this message."
4861 (when message-reply-headers
4862 (let ((from (mail-header-from message-reply-headers
))
4863 (date (mail-header-date message-reply-headers
))
4864 (msg-id (mail-header-message-id message-reply-headers
)))
4866 (let ((name (mail-extract-address-components from
)))
4867 (concat msg-id
(if msg-id
" (")
4871 (if (or (not date
) (string= date
""))
4872 "(unknown date)" date
)
4873 "\"" (if msg-id
")")))))))
4875 (defun message-make-distribution ()
4876 "Make a Distribution header."
4877 (let ((orig-distribution (message-fetch-reply-field "distribution")))
4878 (cond ((functionp message-distribution-function
)
4879 (funcall message-distribution-function
))
4880 (t orig-distribution
))))
4882 (defun message-make-expires ()
4883 "Return an Expires header based on `message-expires'."
4884 (let ((current (current-time))
4885 (future (* 1.0 message-expires
60 60 24)))
4886 ;; Add the future to current.
4887 (setcar current
(+ (car current
) (round (/ future
(expt 2 16)))))
4888 (setcar (cdr current
) (+ (nth 1 current
) (%
(round future
) (expt 2 16))))
4889 (message-make-date current
)))
4891 (defun message-make-path ()
4893 (let ((login-name (user-login-name)))
4894 (cond ((null message-user-path
)
4895 (concat (system-name) "!" login-name
))
4896 ((stringp message-user-path
)
4897 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
4898 (concat message-user-path
"!" login-name
))
4901 (defun message-make-from ()
4902 "Make a From header."
4903 (let* ((style message-from-style
)
4904 (login (message-make-address))
4906 (or (and (boundp 'user-full-name
)
4909 (when (string= fullname
"&")
4910 (setq fullname
(user-login-name)))
4912 (mm-enable-multibyte)
4915 (equal fullname
""))
4917 ((or (eq style
'angles
)
4918 (and (not (eq style
'parens
))
4919 ;; Use angles if no quoting is needed, or if parens would
4920 ;; need quoting too.
4921 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname
))
4922 (let ((tmp (concat fullname nil
)))
4923 (while (string-match "([^()]*)" tmp
)
4924 (aset tmp
(match-beginning 0) ?-
)
4925 (aset tmp
(1- (match-end 0)) ?-
))
4926 (string-match "[\\()]" tmp
)))))
4928 (goto-char (point-min))
4929 ;; Look for a character that cannot appear unquoted
4930 ;; according to RFC 822.
4931 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil
1)
4932 ;; Quote fullname, escaping specials.
4933 (goto-char (point-min))
4935 (while (re-search-forward "[\"\\]" nil
1)
4936 (replace-match "\\\\\\&" t
))
4938 (insert " <" login
">"))
4939 (t ; 'parens or default
4941 (let ((fullname-start (point)))
4943 (goto-char fullname-start
)
4944 ;; RFC 822 says \ and nonmatching parentheses
4945 ;; must be escaped in comments.
4946 ;; Escape every instance of ()\ ...
4947 (while (re-search-forward "[()\\]" nil
1)
4948 (replace-match "\\\\\\&" t
))
4949 ;; ... then undo escaping of matching parentheses,
4950 ;; including matching nested parentheses.
4951 (goto-char fullname-start
)
4952 (while (re-search-forward
4953 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
4955 (replace-match "\\1(\\3)" t
)
4956 (goto-char fullname-start
)))
4960 (defun message-make-sender ()
4961 "Return the \"real\" user address.
4962 This function tries to ignore all user modifications, and
4963 give as trustworthy answer as possible."
4964 (concat (user-login-name) "@" (system-name)))
4966 (defun message-make-address ()
4967 "Make the address of the user."
4968 (or (message-user-mail-address)
4969 (concat (user-login-name) "@" (message-make-domain))))
4971 (defun message-user-mail-address ()
4972 "Return the pertinent part of `user-mail-address'."
4973 (when (and user-mail-address
4974 (string-match "@.*\\." user-mail-address
))
4975 (if (string-match " " user-mail-address
)
4976 (nth 1 (mail-extract-address-components user-mail-address
))
4977 user-mail-address
)))
4979 (defun message-sendmail-envelope-from ()
4980 "Return the envelope from."
4981 (cond ((eq message-sendmail-envelope-from
'header
)
4982 (nth 1 (mail-extract-address-components
4983 (message-fetch-field "from"))))
4984 ((stringp message-sendmail-envelope-from
)
4985 message-sendmail-envelope-from
)
4987 (message-make-address))))
4989 (defun message-make-fqdn ()
4990 "Return user's fully qualified domain name."
4991 (let* ((system-name (system-name))
4992 (user-mail (message-user-mail-address))
4995 (string-match "@\\(.*\\)\\'" user-mail
))
4996 (match-string 1 user-mail
)))
4997 (case-fold-search t
))
4999 ((and message-user-fqdn
5000 (stringp message-user-fqdn
)
5001 (string-match message-valid-fqdn-regexp message-user-fqdn
)
5002 (not (string-match message-bogus-system-names message-user-fqdn
)))
5003 ;; `message-user-fqdn' seems to be valid
5005 ((and (string-match message-valid-fqdn-regexp system-name
)
5006 (not (string-match message-bogus-system-names system-name
)))
5007 ;; `system-name' returned the right result.
5009 ;; Try `mail-host-address'.
5010 ((and (boundp 'mail-host-address
)
5011 (stringp mail-host-address
)
5012 (string-match message-valid-fqdn-regexp mail-host-address
)
5013 (not (string-match message-bogus-system-names mail-host-address
)))
5015 ;; We try `user-mail-address' as a backup.
5017 (stringp user-domain
)
5018 (string-match message-valid-fqdn-regexp user-domain
)
5019 (not (string-match message-bogus-system-names user-domain
)))
5021 ;; Default to this bogus thing.
5024 ".i-did-not-set--mail-host-address--so-tickle-me")))))
5026 (defun message-make-host-name ()
5027 "Return the name of the host."
5028 (let ((fqdn (message-make-fqdn)))
5029 (string-match "^[^.]+\\." fqdn
)
5030 (substring fqdn
0 (1- (match-end 0)))))
5032 (defun message-make-domain ()
5033 "Return the domain name."
5034 (or mail-host-address
5035 (message-make-fqdn)))
5037 (defun message-to-list-only ()
5038 "Send a message to the list only.
5039 Remove all addresses but the list address from To and Cc headers."
5041 (let ((listaddr (message-make-mail-followup-to t
)))
5044 (message-remove-header "to")
5045 (message-remove-header "cc")
5046 (message-position-on-field "To" "X-Draft-From")
5047 (insert listaddr
)))))
5049 (defun message-make-mail-followup-to (&optional only-show-subscribed
)
5050 "Return the Mail-Followup-To header.
5051 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5052 subscribed address (and not the additional To and Cc header contents)."
5053 (let* ((case-fold-search t
)
5054 (to (message-fetch-field "To"))
5055 (cc (message-fetch-field "cc"))
5056 (msg-recipients (concat to
(and to cc
", ") cc
))
5058 (mapcar 'mail-strip-quoted-names
5059 (message-tokenize-header msg-recipients
)))
5061 (if message-subscribed-address-file
5062 (let (begin end item re
)
5065 (insert-file-contents message-subscribed-address-file
)
5067 (setq begin
(point))
5070 (if (bolp) (setq end
(1- end
)))
5071 (setq item
(regexp-quote (buffer-substring begin end
)))
5072 (if re
(setq re
(concat re
"\\|" item
))
5073 (setq re
(concat "\\`\\(" item
))))
5074 (and re
(list (concat re
"\\)\\'"))))))))
5075 (mft-regexps (apply 'append message-subscribed-regexps
5076 (mapcar 'regexp-quote
5077 message-subscribed-addresses
)
5080 message-subscribed-address-functions
))))
5082 (let ((subscribed-lists nil
)
5084 (loop for recipient in recipients
5085 when
(loop for regexp in mft-regexps
5086 when
(string-match regexp recipient
) return t
)
5089 (if only-show-subscribed
5091 msg-recipients
))))))
5093 (defun message-idna-to-ascii-rhs-1 (header)
5094 "Interactively potentially IDNA encode domain names in HEADER."
5095 (let ((field (message-fetch-field header
))
5099 (mm-delete-duplicates
5100 (mapcar (lambda (rhs) (or (cadr (split-string rhs
"@")) ""))
5103 'car
(mail-header-parse-addresses field
))))))
5104 (setq ace
(downcase (idna-to-ascii rhs
)))
5105 (when (and (not (equal rhs ace
))
5106 (or (not (eq message-use-idna
'ask
))
5107 (y-or-n-p (format "Replace %s with %s in %s:? "
5109 (goto-char (point-min))
5110 (while (re-search-forward (concat "^" header
":") nil t
)
5111 (message-narrow-to-field)
5112 (while (search-forward (concat "@" rhs
) nil t
)
5113 (replace-match (concat "@" ace
) t t
))
5114 (goto-char (point-max))
5117 (defun message-idna-to-ascii-rhs ()
5118 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
5119 See `message-idna-encode'."
5121 (when message-use-idna
5124 (message-narrow-to-head)
5125 (message-idna-to-ascii-rhs-1 "From")
5126 (message-idna-to-ascii-rhs-1 "To")
5127 (message-idna-to-ascii-rhs-1 "Reply-To")
5128 (message-idna-to-ascii-rhs-1 "Mail-Reply-To")
5129 (message-idna-to-ascii-rhs-1 "Mail-Followup-To")
5130 (message-idna-to-ascii-rhs-1 "Cc")))))
5132 (defun message-generate-headers (headers)
5133 "Prepare article HEADERS.
5134 Headers already prepared in the buffer are not modified."
5135 (setq headers
(append headers message-required-headers
))
5137 (message-narrow-to-headers)
5138 (let* ((Date (message-make-date))
5139 (Message-ID (message-make-message-id))
5140 (Organization (message-make-organization))
5141 (From (message-make-from))
5142 (Path (message-make-path))
5145 (In-Reply-To (message-make-in-reply-to))
5146 (References (message-make-references))
5148 (Distribution (message-make-distribution))
5149 (Lines (message-make-lines))
5150 (User-Agent message-newsreader
)
5151 (Expires (message-make-expires))
5152 (case-fold-search t
)
5154 header value elem header-string
)
5155 ;; First we remove any old generated headers.
5156 (let ((headers message-deletable-headers
))
5157 (unless (buffer-modified-p)
5158 (setq headers
(delq 'Message-ID
(copy-sequence headers
))))
5160 (goto-char (point-min))
5161 (and (re-search-forward
5162 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
5163 (get-text-property (1+ (match-beginning 0)) 'message-deletable
)
5164 (message-delete-line))
5166 ;; Go through all the required headers and see if they are in the
5167 ;; articles already. If they are not, or are empty, they are
5168 ;; inserted automatically - except for Subject, Newsgroups and
5171 (goto-char (point-min))
5172 (setq elem
(pop headers
))
5174 (if (eq (car elem
) 'optional
)
5175 (setq header
(cdr elem
)
5177 (setq header
(car elem
)))
5179 (setq header-string
(if (stringp header
)
5181 (symbol-name header
)))
5182 (when (or (not (re-search-forward
5184 (regexp-quote (downcase header-string
))
5188 ;; The header was found. We insert a space after the
5189 ;; colon, if there is none.
5190 (if (/= (char-after) ?
) (insert " ") (forward-char 1))
5191 ;; Find out whether the header is empty.
5192 (looking-at "[ \t]*\n[^ \t]")))
5193 ;; So we find out what value we should insert.
5197 (eq (car elem
) 'optional
)
5198 (not (member header-string message-inserted-headers
)))
5199 ;; This is an optional header. If the cdr of this
5200 ;; is something that is nil, then we do not insert
5202 (setq header
(cdr elem
))
5203 (or (and (functionp (cdr elem
))
5204 (funcall (cdr elem
)))
5205 (and (boundp (cdr elem
))
5206 (symbol-value (cdr elem
)))))
5208 ;; The element is a cons. Either the cdr is a
5209 ;; string to be inserted verbatim, or it is a
5210 ;; function, and we insert the value returned from
5212 (or (and (stringp (cdr elem
))
5214 (and (functionp (cdr elem
))
5215 (funcall (cdr elem
)))))
5216 ((and (boundp header
)
5217 (symbol-value header
))
5218 ;; The element is a symbol. We insert the value
5219 ;; of this symbol, if any.
5220 (symbol-value header
))
5221 ((not (message-check-element
5222 (intern (downcase (symbol-name header
)))))
5223 ;; We couldn't generate a value for this header,
5224 ;; so we just ask the user.
5225 (read-from-minibuffer
5226 (format "Empty header for %s; enter value: " header
)))))
5227 ;; Finally insert the header.
5229 (not (equal value
"")))
5233 ;; This header didn't exist, so we insert it.
5234 (goto-char (point-max))
5236 (cdr (assq header message-header-format-alist
))))
5238 (funcall formatter header value
)
5239 (insert header-string
": " value
))
5240 ;; We check whether the value was ended by a
5241 ;; newline. If now, we insert one.
5245 ;; The value of this header was empty, so we clear
5246 ;; totally and insert the new value.
5247 (delete-region (point) (gnus-point-at-eol))
5248 ;; If the header is optional, and the header was
5249 ;; empty, we con't insert it anyway.
5251 (push header-string message-inserted-headers
)
5253 ;; Add the deletable property to the headers that require it.
5254 (and (memq header message-deletable-headers
)
5255 (progn (beginning-of-line) (looking-at "[^:]+: "))
5256 (add-text-properties
5257 (point) (match-end 0)
5258 '(message-deletable t face italic
) (current-buffer)))))))
5259 ;; Insert new Sender if the From is strange.
5260 (let ((from (message-fetch-field "from"))
5261 (sender (message-fetch-field "sender"))
5262 (secure-sender (message-make-sender)))
5264 (not (message-check-element 'sender
))
5267 (cadr (mail-extract-address-components from
)))
5268 (downcase secure-sender
)))
5273 (cadr (mail-extract-address-components sender
)))
5274 (downcase secure-sender
)))))
5275 (goto-char (point-min))
5276 ;; Rename any old Sender headers to Original-Sender.
5277 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t
)
5279 (insert "Original-")
5280 (beginning-of-line))
5281 (when (or (message-news-p)
5282 (string-match "@.+\\.." secure-sender
))
5283 (insert "Sender: " secure-sender
"\n"))))
5285 (message-idna-to-ascii-rhs))))
5287 (defun message-insert-courtesy-copy ()
5288 "Insert a courtesy message in mail copies of combined messages."
5292 (message-narrow-to-headers)
5293 (when (setq newsgroups
(message-fetch-field "newsgroups"))
5294 (goto-char (point-max))
5295 (insert "Posted-To: " newsgroups
"\n")))
5297 (when message-courtesy-message
5299 ((string-match "%s" message-courtesy-message
)
5300 (insert (format message-courtesy-message newsgroups
)))
5302 (insert message-courtesy-message
)))))))
5305 ;;; Setting up a message buffer
5308 (defun message-fill-address (header value
)
5310 (narrow-to-region (point) (point))
5311 (insert (capitalize (symbol-name header
))
5313 (if (consp value
) (car value
) value
)
5315 (narrow-to-region (point-min) (1- (point-max)))
5317 (goto-char (point-min))
5319 (skip-chars-forward "^,\"" (point-max))
5320 (if (or (eq (char-after) ?
,)
5323 (if (and (> (current-column) 78)
5329 (setq last
(1+ (point))))
5330 (setq last
(1+ (point)))))
5331 (setq quoted
(not quoted
)))
5334 (goto-char (point-max))
5338 (defun message-split-line ()
5339 "Split current line, moving portion beyond point vertically down.
5340 If the current line has `message-yank-prefix', insert it on the new line."
5343 (split-line message-yank-prefix
) ;; Emacs 22.1+ supports arg.
5347 (defun message-fill-header (header value
)
5348 (let ((begin (point))
5351 (insert (capitalize (symbol-name header
))
5353 (if (consp value
) (car value
) value
)
5356 (narrow-to-region begin
(point))
5357 (fill-region-as-paragraph begin
(point))
5358 ;; Tapdance around looong Message-IDs.
5360 (when (looking-at "[ \t]*$")
5361 (message-delete-line))
5363 (re-search-forward ":" nil t
)
5364 (when (looking-at "\n[ \t]+")
5365 (replace-match " " t t
))
5366 (goto-char (point-max)))))
5368 (defun message-shorten-1 (list cut surplus
)
5369 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
5370 (setcdr (nthcdr (- cut
2) list
)
5371 (nthcdr (+ (- cut
2) surplus
1) list
)))
5373 (defun message-shorten-references (header references
)
5374 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
5375 If folding is disallowed, also check that the REFERENCES are less
5376 than 988 characters long, and if they are not, trim them until they are."
5383 (goto-char (point-min))
5384 ;; Cons a list of valid references.
5385 (while (re-search-forward "<[^>]+>" nil t
)
5386 (push (match-string 0) refs
))
5387 (setq refs
(nreverse refs
)
5388 count
(length refs
)))
5390 ;; If the list has more than MAXCOUNT elements, trim it by
5391 ;; removing the CUTth element and the required number of
5392 ;; elements that follow.
5393 (when (> count maxcount
)
5394 (let ((surplus (- count maxcount
)))
5395 (message-shorten-1 refs cut surplus
)
5396 (decf count surplus
)))
5398 ;; If folding is disallowed, make sure the total length (including
5399 ;; the spaces between) will be less than MAXSIZE characters.
5401 ;; Only disallow folding for News messages. At this point the headers
5402 ;; have not been generated, thus we use message-this-is-news directly.
5403 (when (and message-this-is-news message-cater-to-broken-inn
)
5405 (totalsize (+ (apply #'+ (mapcar #'length refs
))
5408 (ptr (nthcdr (1- cut
) refs
)))
5409 ;; Decide how many elements to cut off...
5410 (while (> totalsize maxsize
)
5411 (decf totalsize
(1+ (length (car ptr
))))
5413 (setq ptr
(cdr ptr
)))
5416 (message-shorten-1 refs cut surplus
))))
5418 ;; Finally, collect the references back into a string and insert
5419 ;; it into the buffer.
5420 (let ((refstring (mapconcat #'identity refs
" ")))
5421 (if (and message-this-is-news message-cater-to-broken-inn
)
5422 (insert (capitalize (symbol-name header
)) ": "
5424 (message-fill-header header refstring
)))))
5426 (defun message-position-point ()
5427 "Move point to where the user probably wants to find it."
5428 (message-narrow-to-headers)
5430 ((re-search-forward "^[^:]+:[ \t]*$" nil t
)
5431 (search-backward ":" )
5434 (if (eq (char-after) ?
)
5438 (goto-char (point-max))
5441 (unless (looking-at "$")
5445 (defcustom message-beginning-of-line t
5446 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
5447 goes to beginning of header values."
5449 :group
'message-buffers
5450 :link
'(custom-manual "(message)Movement")
5453 (defun message-beginning-of-line (&optional n
)
5454 "Move point to beginning of header value or to beginning of line.
5455 The prefix argument N is passed directly to `beginning-of-line'.
5457 This command is identical to `beginning-of-line' if point is
5458 outside the message header or if the option `message-beginning-of-line'
5461 If point is in the message header and on a (non-continued) header
5462 line, move point to the beginning of the header value or the beginning of line,
5463 whichever is closer. If point is already at beginning of line, move point to
5464 beginning of header value. Therefore, repeated calls will toggle point
5465 between beginning of field and beginning of line."
5467 (let ((zrs 'zmacs-region-stays
))
5468 (when (and (interactive-p) (boundp zrs
))
5470 (if (and message-beginning-of-line
5471 (message-point-in-header-p))
5472 (let* ((here (point))
5473 (bol (progn (beginning-of-line n
) (point)))
5474 (eol (gnus-point-at-eol))
5475 (eoh (re-search-forward ": *" eol t
)))
5477 (if (and eoh
(or (< eoh here
) (= bol here
)))
5479 (beginning-of-line n
)))
5481 (defun message-buffer-name (type &optional to group
)
5482 "Return a new (unique) buffer name based on TYPE and TO."
5484 ;; Generate a new buffer name The Message Way.
5485 ((eq message-generate-new-buffers
'unique
)
5486 (generate-new-buffer-name
5490 (or (car (mail-extract-address-components to
))
5493 (if (and group
(not (string= group
""))) (concat " on " group
) "")
5495 ;; Check whether `message-generate-new-buffers' is a function,
5496 ;; and if so, call it.
5497 ((functionp message-generate-new-buffers
)
5498 (funcall message-generate-new-buffers type to group
))
5499 ((eq message-generate-new-buffers
'unsent
)
5500 (generate-new-buffer-name
5501 (concat "*unsent " type
5504 (or (car (mail-extract-address-components to
))
5507 (if (and group
(not (string= group
""))) (concat " on " group
) "")
5509 ;; Use standard name.
5511 (format "*%s message*" type
))))
5513 (defun message-pop-to-buffer (name)
5514 "Pop to buffer NAME, and warn if it already exists and is modified."
5515 (let ((buffer (get-buffer name
)))
5517 (buffer-name buffer
))
5519 (set-buffer (pop-to-buffer buffer
))
5520 (when (and (buffer-modified-p)
5522 "Message already being composed; erase? ")))
5523 (error "Message being composed")))
5524 (set-buffer (pop-to-buffer name
)))
5528 (defun message-do-send-housekeeping ()
5529 "Kill old message buffers."
5530 ;; We might have sent this buffer already. Delete it from the
5532 (setq message-buffer-list
(delq (current-buffer) message-buffer-list
))
5533 (while (and message-max-buffers
5535 (>= (length message-buffer-list
) message-max-buffers
))
5536 ;; Kill the oldest buffer -- unless it has been changed.
5537 (let ((buffer (pop message-buffer-list
)))
5538 (when (and (buffer-name buffer
)
5539 (not (buffer-modified-p buffer
)))
5540 (kill-buffer buffer
))))
5541 ;; Rename the buffer.
5542 (if message-send-rename-function
5543 (funcall message-send-rename-function
)
5544 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
5546 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
5548 (let ((name (match-string 2 (buffer-name)))
5550 (if (not (or (null name
)
5551 (string-equal name
"mail")
5552 (string-equal name
"posting")))
5553 (setq name
(concat "*sent " name
"*"))
5554 (message-narrow-to-headers)
5555 (setq to
(message-fetch-field "to"))
5556 (setq group
(message-fetch-field "newsgroups"))
5560 (to (concat "*sent mail to "
5561 (or (car (mail-extract-address-components to
))
5563 ((and group
(not (string= group
"")))
5564 (concat "*sent posting on " group
"*"))
5565 (t "*sent mail*"))))
5566 (unless (string-equal name
(buffer-name))
5567 (rename-buffer name t
)))))
5568 ;; Push the current buffer onto the list.
5569 (when message-max-buffers
5570 (setq message-buffer-list
5571 (nconc message-buffer-list
(list (current-buffer))))))
5573 (defun message-mail-user-agent ()
5575 ((not message-mail-user-agent
) nil
)
5576 ((eq message-mail-user-agent t
) mail-user-agent
)
5577 (t message-mail-user-agent
))))
5578 (if (memq mua
'(message-user-agent gnus-user-agent
))
5582 (defun message-setup (headers &optional replybuffer actions switch-function
)
5583 (let ((mua (message-mail-user-agent))
5584 subject to field yank-action
)
5585 (if (not (and message-this-is-mail mua
))
5586 (message-setup-1 headers replybuffer actions
)
5588 (setq yank-action
(list 'insert-buffer replybuffer
)))
5589 (setq headers
(copy-sequence headers
))
5590 (setq field
(assq 'Subject headers
))
5592 (setq subject
(cdr field
))
5593 (setq headers
(delq field headers
)))
5594 (setq field
(assq 'To headers
))
5596 (setq to
(cdr field
))
5597 (setq headers
(delq field headers
)))
5598 (let ((mail-user-agent mua
))
5599 (compose-mail to subject
5600 (mapcar (lambda (item)
5602 (format "%s" (car item
))
5605 nil switch-function yank-action actions
)))))
5607 (defun message-headers-to-generate (headers included-headers excluded-headers
)
5608 "Return a list that includes all headers from HEADERS.
5609 If INCLUDED-HEADERS is a list, just include those headers. If it is
5610 t, include all headers. In any case, headers from EXCLUDED-HEADERS
5614 (dolist (header headers
)
5615 (setq header-name
(cond
5616 ((and (consp header
)
5617 (eq (car header
) 'optional
))
5618 ;; On the form (optional . Header)
5621 ;; On the form (Header . function)
5626 (when (and (not (memq header-name excluded-headers
))
5627 (or (eq included-headers t
)
5628 (memq header-name included-headers
)))
5629 (push header result
)))
5632 (defun message-setup-1 (headers &optional replybuffer actions
)
5633 (dolist (action actions
)
5635 (add-to-list 'message-send-actions
5636 `(apply ',(car action
) ',(cdr action
)))))
5637 (setq message-reply-buffer replybuffer
)
5638 (goto-char (point-min))
5639 ;; Insert all the headers.
5642 (alist message-header-format-alist
))
5644 (unless (assq (caar h
) message-header-format-alist
)
5645 (push (list (caar h
)) alist
))
5649 (delete-region (point) (progn (forward-line -
1) (point)))
5650 (when message-default-headers
5651 (insert message-default-headers
)
5652 (or (bolp) (insert ?
\n)))
5656 (insert mail-header-separator
"\n")
5660 (when (message-news-p)
5661 (when message-default-news-headers
5662 (insert message-default-news-headers
)
5663 (or (bolp) (insert ?
\n)))
5664 (when message-generate-headers-first
5665 (message-generate-headers
5666 (message-headers-to-generate
5667 (append message-required-news-headers
5668 message-required-headers
)
5669 message-generate-headers-first
5670 '(Lines Subject
)))))
5671 (when (message-mail-p)
5672 (when message-default-mail-headers
5673 (insert message-default-mail-headers
)
5674 (or (bolp) (insert ?
\n)))
5675 (when message-generate-headers-first
5676 (message-generate-headers
5677 (message-headers-to-generate
5678 (append message-required-mail-headers
5679 message-required-headers
)
5680 message-generate-headers-first
5681 '(Lines Subject
)))))
5682 (run-hooks 'message-signature-setup-hook
)
5683 (message-insert-signature)
5685 (message-narrow-to-headers)
5686 (run-hooks 'message-header-setup-hook
))
5687 (set-buffer-modified-p nil
)
5688 (setq buffer-undo-list nil
)
5689 (run-hooks 'message-setup-hook
)
5690 ;; Do this last to give it precedence over posting styles, etc.
5691 (when (message-mail-p)
5693 (message-narrow-to-headers)
5694 (if message-alternative-emails
5695 (message-use-alternative-email-as-from))))
5696 (message-position-point)
5699 (defun message-set-auto-save-file-name ()
5700 "Associate the message buffer with a file in the drafts directory."
5701 (when message-auto-save-directory
5702 (unless (file-directory-p
5703 (directory-file-name message-auto-save-directory
))
5704 (make-directory message-auto-save-directory t
))
5706 (setq message-draft-article
5707 (nndraft-request-associate-buffer "drafts"))
5708 (setq buffer-file-name
(expand-file-name
5709 (if (memq system-type
5710 '(ms-dos ms-windows windows-nt
5711 cygwin cygwin32 win32 w32
5715 message-auto-save-directory
))
5716 (setq buffer-auto-save-file-name
(make-auto-save-file-name)))
5717 (clear-visited-file-modtime)
5718 (setq buffer-file-coding-system message-draft-coding-system
)))
5720 (defun message-disassociate-draft ()
5721 "Disassociate the message buffer from the drafts directory."
5722 (when message-draft-article
5723 (nndraft-request-expire-articles
5724 (list message-draft-article
) "drafts" nil t
)))
5726 (defun message-insert-headers ()
5727 "Generate the headers for the article."
5731 (message-narrow-to-headers)
5732 (when (message-news-p)
5733 (message-generate-headers
5736 (copy-sequence message-required-news-headers
)))))
5737 (when (message-mail-p)
5738 (message-generate-headers
5741 (copy-sequence message-required-mail-headers
))))))))
5746 ;;; Commands for interfacing with message
5750 (defun message-mail (&optional to subject
5751 other-headers continue switch-function
5752 yank-action send-actions
)
5753 "Start editing a mail message to be sent.
5754 OTHER-HEADERS is an alist of header/value pairs."
5756 (let ((message-this-is-mail t
) replybuffer
)
5757 (unless (message-mail-user-agent)
5758 (message-pop-to-buffer (message-buffer-name "mail" to
)))
5759 ;; FIXME: message-mail should do something if YANK-ACTION is not
5761 (and (consp yank-action
) (eq (car yank-action
) 'insert-buffer
)
5762 (setq replybuffer
(nth 1 yank-action
)))
5765 `((To .
,(or to
"")) (Subject .
,(or subject
"")))
5766 (when other-headers other-headers
))
5767 replybuffer send-actions
)
5768 ;; FIXME: Should return nil if failure.
5772 (defun message-news (&optional newsgroups subject
)
5773 "Start editing a news article to be sent."
5775 (let ((message-this-is-news t
))
5776 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
))
5777 (message-setup `((Newsgroups .
,(or newsgroups
""))
5778 (Subject .
,(or subject
""))))))
5780 (defun message-get-reply-headers (wide &optional to-address address-headers
)
5781 (let (follow-to mct never-mct to cc author mft recipients
)
5782 ;; Find all relevant headers we need.
5784 (message-narrow-to-headers-or-head)
5785 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
5786 ;; message-header-synonyms.
5787 (setq to
(or (message-fetch-field "to")
5788 (and (loop for synonym in message-header-synonyms
5789 when
(memq 'Original-To synonym
)
5791 (message-fetch-field "original-to")))
5792 cc
(message-fetch-field "cc")
5793 mct
(message-fetch-field "mail-copies-to")
5794 author
(or (message-fetch-field "mail-reply-to")
5795 (message-fetch-field "reply-to")
5796 (message-fetch-field "from")
5798 mft
(and message-use-mail-followup-to
5799 (message-fetch-field "mail-followup-to"))))
5801 ;; Handle special values of Mail-Copies-To.
5803 (cond ((or (equal (downcase mct
) "never")
5804 (equal (downcase mct
) "nobody"))
5807 ((or (equal (downcase mct
) "always")
5808 (equal (downcase mct
) "poster"))
5809 (setq mct author
))))
5812 ;; Build (textual) list of new recipient addresses.
5815 (setq recipients
(concat ", " author
)))
5817 (dolist (header address-headers
)
5818 (let ((value (message-fetch-field header
)))
5820 (setq recipients
(concat recipients
", " value
))))))
5822 (string-match "[^ \t,]" mft
)
5823 (or (not (eq message-use-mail-followup-to
'ask
))
5824 (message-y-or-n-p "Obey Mail-Followup-To? " t
"\
5825 You should normally obey the Mail-Followup-To: header. In this
5826 article, it has the value of
5830 which directs your response to " (if (string-match "," mft
)
5831 "the specified addresses"
5832 "that address only") ".
5834 Most commonly, Mail-Followup-To is used by a mailing list poster to
5835 express that responses should be sent to just the list, and not the
5838 If a message is posted to several mailing lists, Mail-Followup-To may
5839 also be used to direct the following discussion to one list only,
5840 because discussions that are spread over several lists tend to be
5841 fragmented and very difficult to follow.
5843 Also, some source/announcement lists are not intended for discussion;
5844 responses here are directed to other addresses.
5846 You may customize the variable `message-use-mail-followup-to', if you
5847 want to get rid of this query permanently.")))
5848 (setq recipients
(concat ", " mft
)))
5850 (setq recipients
(concat ", " to-address
))
5851 ;; If the author explicitly asked for a copy, we don't deny it to them.
5852 (if mct
(setq recipients
(concat recipients
", " mct
))))
5854 (setq recipients
(if never-mct
"" (concat ", " author
)))
5855 (if to
(setq recipients
(concat recipients
", " to
)))
5856 (if cc
(setq recipients
(concat recipients
", " cc
)))
5857 (if mct
(setq recipients
(concat recipients
", " mct
)))))
5858 (if (>= (length recipients
) 2)
5859 ;; Strip the leading ", ".
5860 (setq recipients
(substring recipients
2)))
5861 ;; Squeeze whitespace.
5862 (while (string-match "[ \t][ \t]+" recipients
)
5863 (setq recipients
(replace-match " " t t recipients
)))
5864 ;; Remove addresses that match `rmail-dont-reply-to-names'.
5865 (let ((rmail-dont-reply-to-names message-dont-reply-to-names
))
5866 (setq recipients
(rmail-dont-reply-to recipients
)))
5867 ;; Perhaps "Mail-Copies-To: never" removed the only address?
5868 (if (string-equal recipients
"")
5869 (setq recipients author
))
5870 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
5874 (cons (downcase (mail-strip-quoted-names addr
)) addr
))
5875 (message-tokenize-header recipients
)))
5876 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
5877 (let ((s recipients
))
5879 (setq recipients
(delq (assoc (car (pop s
)) s
) recipients
))))
5881 ;; Remove hierarchical lists that are contained within each other,
5882 ;; if message-hierarchical-addresses is defined.
5883 (when message-hierarchical-addresses
5884 (let ((plain-addrs (mapcar 'car recipients
))
5887 (setq subaddrs
(assoc (car plain-addrs
)
5888 message-hierarchical-addresses
)
5889 plain-addrs
(cdr plain-addrs
))
5891 (setq subaddrs
(cdr subaddrs
))
5893 (setq recip
(assoc (car subaddrs
) recipients
)
5894 subaddrs
(cdr subaddrs
))
5896 (setq recipients
(delq recip recipients
))))))))
5898 ;; Build the header alist. Allow the user to be asked whether
5899 ;; or not to reply to all recipients in a wide reply.
5900 (setq follow-to
(list (cons 'To
(cdr (pop recipients
)))))
5901 (when (and recipients
5902 (or (not message-wide-reply-confirm-recipients
)
5903 (y-or-n-p "Reply to all recipients? ")))
5904 (setq recipients
(mapconcat
5905 (lambda (addr) (cdr addr
)) recipients
", "))
5906 (if (string-match "^ +" recipients
)
5907 (setq recipients
(substring recipients
(match-end 0))))
5908 (push (cons 'Cc recipients
) follow-to
)))
5911 (defcustom message-simplify-subject-functions
5912 '(message-strip-list-identifiers
5913 message-strip-subject-re
5914 message-strip-subject-trailing-was
5915 message-strip-subject-encoded-words
)
5916 "List of functions taking a string argument that simplify subjects.
5917 The functions are applied when replying to a message.
5919 Useful functions to put in this list include:
5920 `message-strip-list-identifiers', `message-strip-subject-re',
5921 `message-strip-subject-trailing-was', and
5922 `message-strip-subject-encoded-words'."
5923 :version
"22.1" ;; Gnus 5.10.9
5924 :group
'message-various
5925 :type
'(repeat function
))
5927 (defun message-simplify-subject (subject &optional functions
)
5928 "Return simplified SUBJECT."
5931 (setq functions message-simplify-subject-functions
))
5932 (when (and (memq 'message-strip-list-identifiers functions
)
5933 gnus-list-identifiers
)
5934 (setq subject
(message-strip-list-identifiers subject
)))
5935 (when (memq 'message-strip-subject-re functions
)
5936 (setq subject
(concat "Re: " (message-strip-subject-re subject
))))
5937 (when (and (memq 'message-strip-subject-trailing-was functions
)
5938 message-subject-trailing-was-query
)
5939 (setq subject
(message-strip-subject-trailing-was subject
)))
5940 (when (memq 'message-strip-subject-encoded-words functions
)
5941 (setq subject
(message-strip-subject-encoded-words subject
)))
5945 (defun message-reply (&optional to-address wide
)
5946 "Start editing a reply to the article in the current buffer."
5948 (require 'gnus-sum
) ; for gnus-list-identifiers
5949 (let ((cur (current-buffer))
5950 from subject date reply-to to cc
5951 references message-id follow-to
5952 (inhibit-point-motion-hooks t
)
5953 (message-this-is-mail t
)
5956 (message-narrow-to-head-1)
5957 ;; Allow customizations to have their say.
5959 ;; This is a regular reply.
5960 (when (functionp message-reply-to-function
)
5962 (setq follow-to
(funcall message-reply-to-function
))))
5963 ;; This is a followup.
5964 (when (functionp message-wide-reply-to-function
)
5967 (funcall message-wide-reply-to-function
)))))
5968 (setq message-id
(message-fetch-field "message-id" t
)
5969 references
(message-fetch-field "references")
5970 date
(message-fetch-field "date")
5971 from
(or (message-fetch-field "from") "nobody")
5972 subject
(or (message-fetch-field "subject") "none"))
5974 ;; Strip list identifiers, "Re: ", and "was:"
5975 (setq subject
(message-simplify-subject subject
))
5977 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
5978 (string-match "<[^>]+>" gnus-warning
))
5979 (setq message-id
(match-string 0 gnus-warning
)))
5982 (setq follow-to
(message-get-reply-headers wide to-address
))))
5984 (unless (message-mail-user-agent)
5985 (message-pop-to-buffer
5986 (message-buffer-name
5987 (if wide
"wide reply" "reply") from
5988 (if wide to-address nil
))))
5990 (setq message-reply-headers
5991 (vector 0 subject from date message-id references
0 0 ""))
5994 `((Subject .
,subject
)
5999 (defun message-wide-reply (&optional to-address
)
6000 "Make a \"wide\" reply to the message in the current buffer."
6002 (message-reply to-address t
))
6005 (defun message-followup (&optional to-newsgroups
)
6006 "Follow up to the message in the current buffer.
6007 If TO-NEWSGROUPS, use that as the new Newsgroups line."
6009 (require 'gnus-sum
) ; for gnus-list-identifiers
6010 (let ((cur (current-buffer))
6011 from subject date reply-to mrt mct
6012 references message-id follow-to
6013 (inhibit-point-motion-hooks t
)
6014 (message-this-is-news t
)
6015 followup-to distribution newsgroups gnus-warning posted-to
)
6018 (goto-char (point-min))
6019 (if (search-forward "\n\n" nil t
)
6022 (when (functionp message-followup-to-function
)
6024 (funcall message-followup-to-function
)))
6025 (setq from
(message-fetch-field "from")
6026 date
(message-fetch-field "date")
6027 subject
(or (message-fetch-field "subject") "none")
6028 references
(message-fetch-field "references")
6029 message-id
(message-fetch-field "message-id" t
)
6030 followup-to
(message-fetch-field "followup-to")
6031 newsgroups
(message-fetch-field "newsgroups")
6032 posted-to
(message-fetch-field "posted-to")
6033 reply-to
(message-fetch-field "reply-to")
6034 mrt
(message-fetch-field "mail-reply-to")
6035 distribution
(message-fetch-field "distribution")
6036 mct
(message-fetch-field "mail-copies-to"))
6037 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
6038 (string-match "<[^>]+>" gnus-warning
))
6039 (setq message-id
(match-string 0 gnus-warning
)))
6040 ;; Remove bogus distribution.
6041 (when (and (stringp distribution
)
6042 (let ((case-fold-search t
))
6043 (string-match "world" distribution
)))
6044 (setq distribution nil
))
6045 ;; Strip list identifiers, "Re: ", and "was:"
6046 (setq subject
(message-simplify-subject subject
))
6049 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups
))
6051 (setq message-reply-headers
6052 (vector 0 subject from date message-id references
0 0 ""))
6055 `((Subject .
,subject
)
6058 (list (cons 'Newsgroups to-newsgroups
)))
6059 (follow-to follow-to
)
6060 ((and followup-to message-use-followup-to
)
6063 ((equal (downcase followup-to
) "poster")
6064 (if (or (eq message-use-followup-to
'use
)
6065 (message-y-or-n-p "Obey Followup-To: poster? " t
"\
6066 You should normally obey the Followup-To: header.
6068 `Followup-To: poster' sends your response via e-mail instead of news.
6070 A typical situation where `Followup-To: poster' is used is when the poster
6071 does not read the newsgroup, so he wouldn't see any replies sent to it.
6073 You may customize the variable `message-use-followup-to', if you
6074 want to get rid of this query permanently."))
6076 (setq message-this-is-news nil
)
6077 (cons 'To
(or mrt reply-to from
"")))
6078 (cons 'Newsgroups newsgroups
)))
6080 (if (or (equal followup-to newsgroups
)
6081 (not (eq message-use-followup-to
'ask
))
6083 (concat "Obey Followup-To: " followup-to
"? ") t
"\
6084 You should normally obey the Followup-To: header.
6086 `Followup-To: " followup-to
"'
6087 directs your response to " (if (string-match "," followup-to
)
6088 "the specified newsgroups"
6089 "that newsgroup only") ".
6091 If a message is posted to several newsgroups, Followup-To is often
6092 used to direct the following discussion to one newsgroup only,
6093 because discussions that are spread over several newsgroup tend to
6094 be fragmented and very difficult to follow.
6096 Also, some source/announcement newsgroups are not intended for discussion;
6097 responses here are directed to other newsgroups.
6099 You may customize the variable `message-use-followup-to', if you
6100 want to get rid of this query permanently."))
6101 (cons 'Newsgroups followup-to
)
6102 (cons 'Newsgroups newsgroups
))))))
6104 `((Newsgroups .
,posted-to
)))
6106 `((Newsgroups .
,newsgroups
))))
6107 ,@(and distribution
(list (cons 'Distribution distribution
)))
6109 (not (or (equal (downcase mct
) "never")
6110 (equal (downcase mct
) "nobody"))))
6111 (list (cons 'Cc
(if (or (equal (downcase mct
) "always")
6112 (equal (downcase mct
) "poster"))
6113 (or mrt reply-to from
"")
6118 (defun message-is-yours-p ()
6119 "Non-nil means current article is yours.
6120 If you have added 'cancel-messages to `message-shoot-gnksa-feet', all articles
6121 are yours except those that have Cancel-Lock header not belonging to you.
6122 Instead of shooting GNKSA feet, you should modify `message-alternative-emails'
6123 regexp to match all of yours addresses."
6124 ;; Canlock-logic as suggested by Per Abrahamsen
6125 ;; <abraham@dina.kvl.dk>
6127 ;; IF article has cancel-lock THEN
6128 ;; IF we can verify it THEN
6131 ;; error: cancellock: article is not yours
6133 ;; Use old rules, comparing sender...
6136 (message-narrow-to-head-1)
6137 (if (message-fetch-field "Cancel-Lock")
6138 (if (null (canlock-verify))
6140 (error "Failed to verify Cancel-lock: This article is not yours"))
6143 (message-gnksa-enable-p 'cancel-messages
)
6144 (and (setq sender
(message-fetch-field "sender"))
6145 (string-equal (downcase sender
)
6146 (downcase (message-make-sender))))
6147 ;; Email address in From field equals to our address
6148 (and (setq from
(message-fetch-field "from"))
6150 (downcase (cadr (mail-extract-address-components from
)))
6151 (downcase (cadr (mail-extract-address-components
6152 (message-make-from))))))
6153 ;; Email address in From field matches
6154 ;; 'message-alternative-emails' regexp
6156 message-alternative-emails
6158 message-alternative-emails
6159 (cadr (mail-extract-address-components from
))))))))))
6162 (defun message-cancel-news (&optional arg
)
6163 "Cancel an article you posted.
6164 If ARG, allow editing of the cancellation message."
6166 (unless (message-news-p)
6167 (error "This is not a news article; canceling is impossible"))
6168 (let (from newsgroups message-id distribution buf
)
6170 ;; Get header info from original article.
6172 (message-narrow-to-head-1)
6173 (setq from
(message-fetch-field "from")
6174 newsgroups
(message-fetch-field "newsgroups")
6175 message-id
(message-fetch-field "message-id" t
)
6176 distribution
(message-fetch-field "distribution")))
6177 ;; Make sure that this article was written by the user.
6178 (unless (message-is-yours-p)
6179 (error "This article is not yours"))
6180 (when (yes-or-no-p "Do you really want to cancel this article? ")
6181 ;; Make control message.
6184 (setq buf
(set-buffer (get-buffer-create " *message cancel*"))))
6186 (insert "Newsgroups: " newsgroups
"\n"
6188 "Subject: cmsg cancel " message-id
"\n"
6189 "Control: cancel " message-id
"\n"
6191 (concat "Distribution: " distribution
"\n")
6193 mail-header-separator
"\n"
6194 message-cancel-message
)
6195 (run-hooks 'message-cancel-hook
)
6197 (message "Canceling your article...")
6198 (if (let ((message-syntax-checks
6199 'dont-check-for-anything-just-trust-me
))
6200 (funcall message-send-news-function
))
6201 (message "Canceling your article...done"))
6202 (kill-buffer buf
))))))
6205 (defun message-supersede ()
6206 "Start composing a message to supersede the current message.
6207 This is done simply by taking the old article and adding a Supersedes
6208 header line with the old Message-ID."
6210 (let ((cur (current-buffer)))
6211 ;; Check whether the user owns the article that is to be superseded.
6212 (unless (message-is-yours-p)
6213 (error "This article is not yours"))
6214 ;; Get a normal message buffer.
6215 (message-pop-to-buffer (message-buffer-name "supersede"))
6216 (insert-buffer-substring cur
)
6218 (message-narrow-to-head-1)
6219 ;; Remove unwanted headers.
6220 (when message-ignored-supersedes-headers
6221 (message-remove-header message-ignored-supersedes-headers t
))
6222 (goto-char (point-min))
6223 (if (not (re-search-forward "^Message-ID: " nil t
))
6224 (error "No Message-ID in this article")
6225 (replace-match "Supersedes: " t t
))
6226 (goto-char (point-max))
6227 (insert mail-header-separator
)
6232 (defun message-recover ()
6233 "Reread contents of current buffer from its last auto-save file."
6235 (let ((file-name (make-auto-save-file-name)))
6236 (cond ((save-window-excursion
6237 (if (not (eq system-type
'vax-vms
))
6238 (with-output-to-temp-buffer "*Directory*"
6239 (with-current-buffer standard-output
6240 (fundamental-mode)) ; for Emacs 20.4+
6241 (buffer-disable-undo standard-output
)
6242 (let ((default-directory "/"))
6244 "ls" nil standard-output nil
"-l" file-name
))))
6245 (yes-or-no-p (format "Recover auto save file %s? " file-name
)))
6246 (let ((buffer-read-only nil
))
6248 (insert-file-contents file-name nil
)))
6249 (t (error "message-recover cancelled")))))
6251 ;;; Washing Subject:
6253 (defun message-wash-subject (subject)
6254 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
6255 Previous forwarders, replyers, etc. may add it."
6258 (goto-char (point-min))
6259 ;; strip Re/Fwd stuff off the beginning
6260 (while (re-search-forward
6261 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t
)
6264 ;; and gnus-style forwards [foo@bar.com] subject
6265 (goto-char (point-min))
6266 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t
)
6270 (goto-char (point-max))
6271 (while (re-search-backward "([Ff][Ww][Dd])" nil t
)
6274 ;; and finally, any whitespace that was left-over
6275 (goto-char (point-min))
6276 (while (re-search-forward "^[ \t]+" nil t
)
6278 (goto-char (point-max))
6279 (while (re-search-backward "[ \t]+$" nil t
)
6284 ;;; Forwarding messages.
6286 (defvar message-forward-decoded-p nil
6287 "Non-nil means the original message is decoded.")
6289 (defun message-forward-subject-name-subject (subject)
6290 "Generate a SUBJECT for a forwarded message.
6291 The form is: [Source] Subject, where if the original message was mail,
6292 Source is the name of the sender, and if the original message was
6293 news, Source is the list of newsgroups is was posted to."
6294 (let* ((group (message-fetch-field "newsgroups"))
6295 (from (message-fetch-field "from"))
6298 (gnus-group-decoded-name group
)
6299 (or (and from
(car (gnus-extract-address-components from
)))
6302 (if message-forward-decoded-p
6304 (mail-decode-encoded-word-string prefix
))
6307 (defun message-forward-subject-author-subject (subject)
6308 "Generate a SUBJECT for a forwarded message.
6309 The form is: [Source] Subject, where if the original message was mail,
6310 Source is the sender, and if the original message was news, Source is
6311 the list of newsgroups is was posted to."
6312 (let* ((group (message-fetch-field "newsgroups"))
6315 (gnus-group-decoded-name group
)
6316 (or (message-fetch-field "from")
6319 (if message-forward-decoded-p
6321 (mail-decode-encoded-word-string prefix
))
6324 (defun message-forward-subject-fwd (subject)
6325 "Generate a SUBJECT for a forwarded message.
6326 The form is: Fwd: Subject, where Subject is the original subject of
6328 (if (string-match "^Fwd: " subject
)
6330 (concat "Fwd: " subject
)))
6332 (defun message-make-forward-subject ()
6333 "Return a Subject header suitable for the message in the current buffer."
6336 (message-narrow-to-head-1)
6337 (let ((funcs message-make-forward-subject-function
)
6338 (subject (message-fetch-field "Subject")))
6341 (if message-forward-decoded-p
6343 (mail-decode-encoded-word-string subject
))
6345 (if message-wash-forwarded-subjects
6346 (setq subject
(message-wash-subject subject
)))
6347 ;; Make sure funcs is a list.
6350 (setq funcs
(list funcs
)))
6351 ;; Apply funcs in order, passing subject generated by previous
6352 ;; func to the next one.
6354 (when (functionp (car funcs
))
6355 (setq subject
(funcall (car funcs
) subject
)))
6356 (setq funcs
(cdr funcs
)))
6360 (defvar gnus-article-decoded-p
))
6364 (defun message-forward (&optional news digest
)
6365 "Forward the current message via mail.
6366 Optional NEWS will use news to forward instead of mail.
6367 Optional DIGEST will use digest to forward."
6369 (let* ((cur (current-buffer))
6370 (message-forward-decoded-p
6371 (if (local-variable-p 'gnus-article-decoded-p
(current-buffer))
6372 gnus-article-decoded-p
;; In an article buffer.
6373 message-forward-decoded-p
))
6374 (subject (message-make-forward-subject)))
6376 (message-news nil subject
)
6377 (message-mail nil subject
))
6378 (message-forward-make-body cur digest
)))
6380 (defun message-forward-make-body-plain (forward-buffer)
6382 "\n-------------------- Start of forwarded message --------------------\n")
6383 (let ((b (point)) e
)
6386 (mm-disable-multibyte)
6388 (with-current-buffer forward-buffer
6389 (mm-with-unibyte-current-buffer (buffer-string))))
6390 (mm-enable-multibyte)
6392 (goto-char (point-min))
6393 (when (looking-at "From ")
6394 (replace-match "X-From-Line: "))
6398 "\n-------------------- End of forwarded message --------------------\n")
6399 (when message-forward-ignored-headers
6401 (narrow-to-region b e
)
6403 (narrow-to-region (point)
6404 (or (search-forward "\n\n" nil t
) (point)))
6405 (message-remove-header message-forward-ignored-headers t
)))))
6407 (defun message-forward-make-body-mime (forward-buffer)
6408 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
6409 (let ((b (point)) e
)
6411 (narrow-to-region (point) (point))
6412 (mml-insert-buffer forward-buffer
)
6413 (goto-char (point-min))
6414 (when (looking-at "From ")
6415 (replace-match "X-From-Line: "))
6416 (goto-char (point-max)))
6418 (insert "<#/part>\n")))
6420 (defun message-forward-make-body-mml (forward-buffer)
6421 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
6422 (let ((b (point)) e
)
6423 (if (not message-forward-decoded-p
)
6426 (mm-disable-multibyte)
6428 (with-current-buffer forward-buffer
6429 (mm-with-unibyte-current-buffer (buffer-string))))
6430 (mm-enable-multibyte)
6432 (goto-char (point-min))
6433 (when (looking-at "From ")
6434 (replace-match "X-From-Line: "))
6437 (narrow-to-region (point) (point))
6438 (mml-insert-buffer forward-buffer
)
6439 (goto-char (point-min))
6440 (when (looking-at "From ")
6441 (replace-match "X-From-Line: "))
6442 (goto-char (point-max))))
6444 (insert "<#/mml>\n")
6445 (when (and (not message-forward-decoded-p
)
6446 message-forward-ignored-headers
)
6448 (narrow-to-region b e
)
6450 (narrow-to-region (point)
6451 (or (search-forward "\n\n" nil t
) (point)))
6452 (message-remove-header message-forward-ignored-headers t
)))))
6454 (defun message-forward-make-body-digest-plain (forward-buffer)
6456 "\n-------------------- Start of forwarded message --------------------\n")
6457 (let ((b (point)) e
)
6458 (mml-insert-buffer forward-buffer
)
6461 "\n-------------------- End of forwarded message --------------------\n")))
6463 (defun message-forward-make-body-digest-mime (forward-buffer)
6464 (insert "\n<#multipart type=digest>\n")
6465 (let ((b (point)) e
)
6466 (insert-buffer-substring forward-buffer
)
6468 (insert "<#/multipart>\n")
6470 (narrow-to-region b e
)
6472 (narrow-to-region (point)
6473 (or (search-forward "\n\n" nil t
) (point)))
6474 (delete-region (point-min) (point-max)))))
6476 (defun message-forward-make-body-digest (forward-buffer)
6477 (if message-forward-as-mime
6478 (message-forward-make-body-digest-mime forward-buffer
)
6479 (message-forward-make-body-digest-plain forward-buffer
)))
6482 (defun message-forward-make-body (forward-buffer &optional digest
)
6483 ;; Put point where we want it before inserting the forwarded
6485 (if message-forward-before-signature
6487 (goto-char (point-max)))
6489 (message-forward-make-body-digest forward-buffer
)
6490 (if message-forward-as-mime
6491 (if (and message-forward-show-mml
6492 (not (and (eq message-forward-show-mml
'best
)
6493 (with-current-buffer forward-buffer
6494 (goto-char (point-min))
6496 "Content-Type: *multipart/\\(signed\\|encrypted\\)"
6498 (message-forward-make-body-mml forward-buffer
)
6499 (message-forward-make-body-mime forward-buffer
))
6500 (message-forward-make-body-plain forward-buffer
)))
6501 (message-position-point))
6504 (defun message-forward-rmail-make-body (forward-buffer)
6505 (save-window-excursion
6506 (set-buffer forward-buffer
)
6507 ;; Rmail doesn't have rmail-msg-restore-non-pruned-header in Emacs
6508 ;; 20. FIXIT, or we drop support for rmail in Emacs 20.
6509 (if (rmail-msg-is-pruned)
6510 (rmail-msg-restore-non-pruned-header)))
6511 (message-forward-make-body forward-buffer
))
6513 (eval-when-compile (defvar rmail-enable-mime-composing
))
6515 ;; Fixme: Should have defcustom.
6517 (defun message-insinuate-rmail ()
6518 "Let RMAIL use message to forward."
6520 (setq rmail-enable-mime-composing t
)
6521 (setq rmail-insert-mime-forwarded-message-function
6522 'message-forward-rmail-make-body
))
6525 (defun message-resend (address)
6526 "Resend the current article to ADDRESS."
6528 (list (message-read-from-minibuffer "Resend message to: ")))
6529 (message "Resending message to %s..." address
)
6531 (let ((cur (current-buffer))
6533 ;; We first set up a normal mail buffer.
6534 (unless (message-mail-user-agent)
6535 (set-buffer (get-buffer-create " *message resend*"))
6537 (let ((message-this-is-mail t
)
6539 (message-setup `((To .
,address
))))
6540 ;; Insert our usual headers.
6541 (message-generate-headers '(From Date To Message-ID
))
6542 (message-narrow-to-headers)
6543 ;; Remove X-Draft-From header etc.
6544 (message-remove-header message-ignored-mail-headers t
)
6545 ;; Rename them all to "Resent-*".
6546 (goto-char (point-min))
6547 (while (re-search-forward "^[A-Za-z]" nil t
)
6552 (delete-region (point) (point-max))
6554 ;; Insert the message to be resent.
6555 (insert-buffer-substring cur
)
6556 (goto-char (point-min))
6557 (search-forward "\n\n")
6560 (narrow-to-region beg
(point))
6561 (message-remove-header message-ignored-resent-headers t
)
6562 (goto-char (point-max)))
6563 (insert mail-header-separator
)
6564 ;; Rename all old ("Also-")Resent headers.
6565 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t
)
6568 ;; Quote any "From " lines at the beginning.
6570 (when (looking-at "From ")
6571 (replace-match "X-From-Line: "))
6573 (let ((message-inhibit-body-encoding t
)
6574 message-required-mail-headers
6575 rfc2047-encode-encoded-words
)
6576 (message-send-mail))
6577 (kill-buffer (current-buffer)))
6578 (message "Resending message to %s...done" address
)))
6581 (defun message-bounce ()
6582 "Re-mail the current message.
6583 This only makes sense if the current message is a bounce message that
6584 contains some mail you have written which has been bounced back to
6587 (let ((handles (mm-dissect-buffer t
))
6589 (message-pop-to-buffer (message-buffer-name "bounce"))
6590 (if (stringp (car handles
))
6591 ;; This is a MIME bounce.
6592 (mm-insert-part (car (last handles
)))
6593 ;; This is a non-MIME bounce, so we try to remove things
6595 (mm-insert-part handles
)
6597 (goto-char (point-min))
6598 (re-search-forward "\n\n+" nil t
)
6599 (setq boundary
(point))
6600 ;; We remove everything before the bounced mail.
6601 (if (or (re-search-forward message-unsent-separator nil t
)
6603 (search-forward "\n\n" nil
'move
)
6604 (re-search-backward "^Return-Path:.*\n" boundary t
)))
6607 (delete-region (point-min)
6608 (if (re-search-forward "^[^ \n\t]+:" nil t
)
6611 (goto-char boundary
)
6612 (when (re-search-backward "^.?From .*\n" nil t
)
6613 (delete-region (match-beginning 0) (match-end 0)))))
6614 (mm-enable-multibyte)
6616 (message-narrow-to-head-1)
6617 (message-remove-header message-ignored-bounced-headers t
)
6618 (goto-char (point-max))
6619 (insert mail-header-separator
))
6620 (message-position-point)))
6623 ;;; Interactive entry points for new message buffers.
6627 (defun message-mail-other-window (&optional to subject
)
6628 "Like `message-mail' command, but display mail buffer in another window."
6630 (unless (message-mail-user-agent)
6631 (let ((pop-up-windows t
)
6632 (special-display-buffer-names nil
)
6633 (special-display-regexps nil
)
6634 (same-window-buffer-names nil
)
6635 (same-window-regexps nil
))
6636 (message-pop-to-buffer (message-buffer-name "mail" to
))))
6637 (let ((message-this-is-mail t
))
6638 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
"")))
6639 nil nil
'switch-to-buffer-other-window
)))
6642 (defun message-mail-other-frame (&optional to subject
)
6643 "Like `message-mail' command, but display mail buffer in another frame."
6645 (unless (message-mail-user-agent)
6646 (let ((pop-up-frames t
)
6647 (special-display-buffer-names nil
)
6648 (special-display-regexps nil
)
6649 (same-window-buffer-names nil
)
6650 (same-window-regexps nil
))
6651 (message-pop-to-buffer (message-buffer-name "mail" to
))))
6652 (let ((message-this-is-mail t
))
6653 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
"")))
6654 nil nil
'switch-to-buffer-other-frame
)))
6657 (defun message-news-other-window (&optional newsgroups subject
)
6658 "Start editing a news article to be sent."
6660 (let ((pop-up-windows t
)
6661 (special-display-buffer-names nil
)
6662 (special-display-regexps nil
)
6663 (same-window-buffer-names nil
)
6664 (same-window-regexps nil
))
6665 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
)))
6666 (let ((message-this-is-news t
))
6667 (message-setup `((Newsgroups .
,(or newsgroups
""))
6668 (Subject .
,(or subject
""))))))
6671 (defun message-news-other-frame (&optional newsgroups subject
)
6672 "Start editing a news article to be sent."
6674 (let ((pop-up-frames t
)
6675 (special-display-buffer-names nil
)
6676 (special-display-regexps nil
)
6677 (same-window-buffer-names nil
)
6678 (same-window-regexps nil
))
6679 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
)))
6680 (let ((message-this-is-news t
))
6681 (message-setup `((Newsgroups .
,(or newsgroups
""))
6682 (Subject .
,(or subject
""))))))
6686 ;; This code should be moved to underline.el (from which it is stolen).
6689 (defun bold-region (start end
)
6690 "Bold all nonblank characters in the region.
6691 Works by overstriking characters.
6692 Called from program, takes two arguments START and END
6693 which specify the range to operate on."
6696 (let ((end1 (make-marker)))
6697 (move-marker end1
(max start end
))
6698 (goto-char (min start end
))
6699 (while (< (point) end1
)
6700 (or (looking-at "[_\^@- ]")
6701 (insert (char-after) "\b"))
6702 (forward-char 1)))))
6705 (defun unbold-region (start end
)
6706 "Remove all boldness (overstruck characters) in the region.
6707 Called from program, takes two arguments START and END
6708 which specify the range to operate on."
6711 (let ((end1 (make-marker)))
6712 (move-marker end1
(max start end
))
6713 (goto-char (min start end
))
6714 (while (re-search-forward "\b" end1 t
)
6715 (if (eq (char-after) (char-after (- (point) 2)))
6716 (delete-char -
2))))))
6718 (defun message-exchange-point-and-mark ()
6719 "Exchange point and mark, but don't activate region if it was inactive."
6721 (message-mark-active-p)
6722 (exchange-point-and-mark))
6723 (setq mark-active nil
)))
6725 (defalias 'message-make-overlay
'make-overlay
)
6726 (defalias 'message-delete-overlay
'delete-overlay
)
6727 (defalias 'message-overlay-put
'overlay-put
)
6728 (defun message-kill-all-overlays ()
6729 (if (featurep 'xemacs
)
6730 (map-extents (lambda (extent ignore
) (delete-extent extent
)))
6731 (mapcar #'delete-overlay
(overlays-in (point-min) (point-max)))))
6733 ;; Support for toolbar
6735 (defvar tool-bar-mode
))
6737 ;; Note: The :set function in the `message-tool-bar*' variables will only
6738 ;; affect _new_ message buffers. We might add a function that walks thru all
6739 ;; message-mode buffers and force the update.
6740 (defun message-tool-bar-update (&optional symbol value
)
6741 "Update message mode toolbar.
6742 Setter function for custom variables."
6743 (setq-default message-tool-bar-map nil
)
6745 ;; When used as ":set" function:
6746 (set-default symbol value
)))
6748 (defcustom message-tool-bar
(if (eq gmm-tool-bar-style
'gnome
)
6749 'message-tool-bar-gnome
6750 'message-tool-bar-retro
)
6751 "Specifies the message mode tool bar.
6753 It can be either a list or a symbol refering to a list. See
6754 `gmm-tool-bar-from-list' for the format of the list. The
6755 default key map is `message-mode-map'.
6757 Pre-defined symbols include `message-tool-bar-gnome' and
6758 `message-tool-bar-retro'."
6759 :type
'(repeat gmm-tool-bar-list-item
)
6760 :type
'(choice (const :tag
"GNOME style" message-tool-bar-gnome
)
6761 (const :tag
"Retro look" message-tool-bar-retro
)
6762 (repeat :tag
"User defined list" gmm-tool-bar-item
)
6764 :version
"22.1" ;; Gnus 5.10.9
6765 :initialize
'custom-initialize-default
6766 :set
'message-tool-bar-update
6769 (defcustom message-tool-bar-gnome
6770 '((ispell-message "spell" nil
6771 :visible
(or (not (boundp 'flyspell-mode
))
6772 (not flyspell-mode
)))
6773 (flyspell-buffer "spell" t
6774 :visible
(and (boundp 'flyspell-mode
)
6776 :help
"Flyspell whole buffer")
6777 (gmm-ignore "separator")
6778 (message-send-and-exit "mail/send")
6779 (message-dont-send "mail/save-draft")
6780 (message-kill-buffer "close") ;; stock_cancel
6781 (mml-attach-file "attach" mml-mode-map
)
6782 (mml-preview "mail/preview" mml-mode-map
)
6783 ;; (mml-secure-message-sign-encrypt "lock" mml-mode-map :visible nil)
6784 (message-insert-importance-high "important" nil
:visible nil
)
6785 (message-insert-importance-low "unimportant" nil
:visible nil
)
6786 (message-insert-disposition-notification-to "receipt" nil
:visible nil
)
6787 (gmm-customize-mode "preferences" t
:help
"Edit mode preferences")
6788 (message-info "help" t
:help
"Message manual"))
6789 "List of items for the message tool bar (GNOME style).
6791 See `gmm-tool-bar-from-list' for details on the format of the list."
6792 :type
'(repeat gmm-tool-bar-item
)
6793 :version
"22.1" ;; Gnus 5.10.9
6794 :initialize
'custom-initialize-default
6795 :set
'message-tool-bar-update
6798 (defcustom message-tool-bar-retro
6799 '(;; Old Emacs 21 icon for consistency.
6800 (message-send-and-exit "gnus/mail_send")
6801 (message-kill-buffer "close")
6802 (message-dont-send "cancel")
6803 (mml-attach-file "attach" mml-mode-map
)
6804 (ispell-message "spell")
6805 (mml-preview "preview" mml-mode-map
)
6806 (message-insert-importance-high "gnus/important")
6807 (message-insert-importance-low "gnus/unimportant")
6808 (message-insert-disposition-notification-to "gnus/receipt"))
6809 "List of items for the message tool bar (retro style).
6811 See `gmm-tool-bar-from-list' for details on the format of the list."
6812 :type
'(repeat gmm-tool-bar-item
)
6813 :version
"22.1" ;; Gnus 5.10.9
6814 :initialize
'custom-initialize-default
6815 :set
'message-tool-bar-update
6818 (defcustom message-tool-bar-zap-list
6819 '(new-file open-file dired kill-buffer write-file
6820 print-buffer customize help
)
6821 "List of icon items from the global tool bar.
6822 These items are not displayed on the message mode tool bar.
6824 See `gmm-tool-bar-from-list' for the format of the list."
6825 :type
'gmm-tool-bar-zap-list
6826 :version
"22.1" ;; Gnus 5.10.9
6827 :initialize
'custom-initialize-default
6828 :set
'message-tool-bar-update
6831 (defvar image-load-path
)
6833 (defun message-make-tool-bar (&optional force
)
6834 "Make a message mode tool bar from `message-tool-bar-list'.
6835 When FORCE, rebuild the tool bar."
6836 (when (and (not (featurep 'xemacs
))
6837 (boundp 'tool-bar-mode
)
6839 (or (not message-tool-bar-map
) force
))
6840 (setq message-tool-bar-map
6842 (gmm-image-load-path-for-library "message"
6843 "mail/save-draft.xpm"
6845 (image-load-path (cons (car load-path
)
6846 (when (boundp 'image-load-path
)
6848 (gmm-tool-bar-from-list message-tool-bar
6849 message-tool-bar-zap-list
6850 'message-mode-map
))))
6851 message-tool-bar-map
)
6853 ;;; Group name completion.
6855 (defcustom message-newgroups-header-regexp
6856 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
6857 "Regexp that match headers that lists groups."
6861 (defcustom message-completion-alist
6862 (list (cons message-newgroups-header-regexp
'message-expand-group
)
6863 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name
)
6864 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
6865 . message-expand-name
)
6866 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
6867 . message-expand-name
))
6868 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
6871 :type
'(alist :key-type regexp
:value-type function
))
6873 (defcustom message-tab-body-function nil
6874 "*Function to execute when `message-tab' (TAB) is executed in the body.
6875 If nil, the function bound in `text-mode-map' or `global-map' is executed."
6878 :link
'(custom-manual "(message)Various Commands")
6879 :type
'(choice (const nil
)
6882 (defun message-tab ()
6883 "Complete names according to `message-completion-alist'.
6884 Execute function specified by `message-tab-body-function' when not in
6887 (let ((alist message-completion-alist
))
6889 (let ((mail-abbrev-mode-regexp (caar alist
)))
6890 (not (mail-abbrev-in-expansion-header-p))))
6891 (setq alist
(cdr alist
)))
6892 (funcall (or (cdar alist
) message-tab-body-function
6893 (lookup-key text-mode-map
"\t")
6894 (lookup-key global-map
"\t")
6895 'indent-relative
))))
6900 (let ((standard-output (current-buffer)))
6901 (eval '(display-completion-list nil
"")))
6902 (defalias 'message-display-completion-list
'display-completion-list
))
6903 (error ;; Don't use `wrong-number-of-arguments' here because of XEmacs.
6904 (defun message-display-completion-list (completions &optional ignore
)
6905 "Display the list of completions, COMPLETIONS, using `standard-output'."
6906 (display-completion-list completions
)))))
6908 (defun message-expand-group ()
6909 "Expand the group name under point."
6910 (let* ((b (save-excursion
6915 (skip-chars-forward "^:")
6918 (skip-chars-backward "^, \t\n") (point))))
6919 (completion-ignore-case t
)
6920 (string (buffer-substring b
(progn (skip-chars-forward "^,\t\n ")
6922 (hashtb (and (boundp 'gnus-active-hashtb
) gnus-active-hashtb
))
6923 (completions (all-completions string hashtb
))
6925 (delete-region b
(point))
6927 ((= (length completions
) 1)
6928 (if (string= (car completions
) string
)
6931 (message "Only matching group"))
6932 (insert (car completions
))))
6933 ((and (setq comp
(try-completion string hashtb
))
6934 (not (string= comp string
)))
6939 (message "No matching groups")
6940 (save-selected-window
6941 (pop-to-buffer "*Completions*")
6942 (buffer-disable-undo)
6943 (let ((buffer-read-only nil
))
6945 (let ((standard-output (current-buffer)))
6946 (message-display-completion-list (sort completions
'string
<)
6948 (setq buffer-read-only nil
)
6949 (goto-char (point-min))
6950 (delete-region (point) (progn (forward-line 3) (point))))))))))
6952 (defun message-expand-name ()
6953 (if (fboundp 'bbdb-complete-name
)
6954 (bbdb-complete-name)
6959 (defun message-talkative-question (ask question show
&rest text
)
6960 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
6961 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
6962 The following arguments may contain lists of values."
6964 (setq text
(message-flatten-list text
)))
6965 (save-window-excursion
6967 (with-output-to-temp-buffer " *MESSAGE information message*"
6968 (set-buffer " *MESSAGE information message*")
6969 (fundamental-mode) ; for Emacs 20.4+
6970 (mapcar 'princ text
)
6971 (goto-char (point-min))))
6972 (funcall ask question
))
6973 (funcall ask question
)))
6975 (defun message-flatten-list (list)
6976 "Return a new, flat list that contains all elements of LIST.
6978 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
6981 (apply 'append
(mapcar 'message-flatten-list list
)))
6985 (defun message-generate-new-buffer-clone-locals (name &optional varstr
)
6986 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
6987 Then clone the local variables and values from the old buffer to the
6988 new one, cloning only the locals having a substring matching the
6990 (let ((oldbuf (current-buffer)))
6992 (set-buffer (generate-new-buffer name
))
6993 (message-clone-locals oldbuf varstr
)
6996 (defun message-clone-locals (buffer &optional varstr
)
6997 "Clone the local variables from BUFFER to the current buffer."
6998 (let ((locals (save-excursion
7000 (buffer-local-variables)))
7001 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address"))
7004 (when (and (consp local
)
7006 (string-match regexp
(symbol-name (car local
)))
7008 (string-match varstr
(symbol-name (car local
)))))
7010 (set (make-local-variable (car local
))
7018 (defvar message-inhibit-body-encoding nil
)
7020 (defun message-encode-message-body ()
7021 (unless message-inhibit-body-encoding
7022 (let ((mail-parse-charset (or mail-parse-charset
7023 message-default-charset
))
7024 (case-fold-search t
)
7025 lines content-type-p
)
7028 (narrow-to-region (point) (point-max))
7029 (let ((new (mml-generate-mime)))
7031 (delete-region (point-min) (point-max))
7033 (goto-char (point-min))
7034 (if (eq (aref new
0) ?
\n)
7036 (search-forward "\n\n")
7037 (setq lines
(buffer-substring (point-min) (1- (point))))
7038 (delete-region (point-min) (point))))))
7040 (message-narrow-to-headers-or-head)
7041 (message-remove-header "Mime-Version")
7042 (goto-char (point-max))
7043 (insert "MIME-Version: 1.0\n")
7046 (setq content-type-p
7048 (re-search-backward "^Content-Type:" nil t
))))
7050 (message-narrow-to-headers-or-head)
7051 (message-remove-first-header "Content-Type")
7052 (message-remove-first-header "Content-Transfer-Encoding"))
7053 ;; We always make sure that the message has a Content-Type
7054 ;; header. This is because some broken MTAs and MUAs get
7055 ;; awfully confused when confronted with a message with a
7056 ;; MIME-Version header and without a Content-Type header. For
7057 ;; instance, Solaris' /usr/bin/mail.
7058 (unless content-type-p
7059 (goto-char (point-min))
7060 ;; For unknown reason, MIME-Version doesn't exist.
7061 (when (re-search-forward "^MIME-Version:" nil t
)
7063 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
7065 (defun message-read-from-minibuffer (prompt &optional initial-contents
)
7066 "Read from the minibuffer while providing abbrev expansion."
7067 (if (fboundp 'mail-abbrevs-setup
)
7068 (let ((mail-abbrev-mode-regexp "")
7069 (minibuffer-setup-hook 'mail-abbrevs-setup
)
7070 (minibuffer-local-map message-minibuffer-local-map
))
7071 (read-from-minibuffer prompt initial-contents
))
7072 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook
)
7073 (minibuffer-local-map message-minibuffer-local-map
))
7074 (read-string prompt initial-contents
))))
7076 (defun message-use-alternative-email-as-from ()
7077 "Set From field of the outgoing message to the first matching
7078 address in `message-alternative-emails', looking at To, Cc and
7079 From headers in the original article."
7080 (require 'mail-utils
)
7081 (let* ((fields '("To" "Cc"))
7084 (mail-strip-quoted-names
7085 (mapconcat 'message-fetch-reply-field fields
","))
7089 (if (string-match message-alternative-emails
(car emails
))
7090 (setq email
(car emails
)
7093 (unless (or (not email
) (equal email user-mail-address
))
7094 (message-remove-header "From")
7095 (goto-char (point-max))
7096 (insert "From: " email
"\n"))))
7098 (defun message-options-get (symbol)
7099 (cdr (assq symbol message-options
)))
7101 (defun message-options-set (symbol value
)
7102 (let ((the-cons (assq symbol message-options
)))
7105 (setcdr the-cons value
)
7106 (setq message-options
(delq the-cons message-options
)))
7108 (push (cons symbol value
) message-options
))))
7111 (defun message-options-set-recipient ()
7113 (message-narrow-to-headers-or-head)
7114 (message-options-set 'message-sender
7115 (mail-strip-quoted-names
7116 (message-fetch-field "from")))
7117 (message-options-set 'message-recipients
7118 (mail-strip-quoted-names
7119 (let ((to (message-fetch-field "to"))
7120 (cc (message-fetch-field "cc"))
7121 (bcc (message-fetch-field "bcc")))
7124 (if (and to cc
) ", ")
7126 (if (and (or to cc
) bcc
) ", ")
7129 (defun message-hide-headers ()
7130 "Hide headers based on the `message-hidden-headers' variable."
7131 (let ((regexps (if (stringp message-hidden-headers
)
7132 (list message-hidden-headers
)
7133 message-hidden-headers
))
7134 (inhibit-point-motion-hooks t
)
7135 (after-change-functions nil
))
7139 (message-narrow-to-headers)
7140 (goto-char (point-min))
7142 (if (not (message-hide-header-p regexps
))
7143 (message-next-header)
7144 (let ((begin (point)))
7145 (message-next-header)
7146 (add-text-properties
7148 '(invisible t message-hidden t
))))))))))
7150 (defun message-hide-header-p (regexps)
7153 (when (eq (car regexps
) 'not
)
7156 (dolist (regexp regexps
)
7157 (setq result
(or result
(looking-at regexp
))))
7162 (when (featurep 'xemacs
)
7163 (require 'messagexmas
)
7164 (message-xmas-redefine))
7168 (run-hooks 'message-load-hook
)
7171 ;; coding: iso-8859-1
7174 ;; arch-tag: 94b32cac-4504-4b6c-8181-030ebf380ee0
7175 ;;; message.el ends here