1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
8 ;; Keiichi Suzuki <kei-suzu@mail.wbs.ne.jp>
9 ;; Tatsuya Ichikawa <t-ichi@po.shiojiri.ne.jp>
10 ;; Katsumi Yamaoka <yamaoka@jpl.org>
11 ;; Kiyokazu SUTO <suto@merry.xmath.ous.ac.jp>
12 ;; Keywords: mail, news, MIME
14 ;; This file is part of GNU Emacs.
16 ;; GNU Emacs is free software; you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation; either version 2, or (at your option)
21 ;; GNU Emacs is distributed in the hope that it will be useful,
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;; GNU General Public License for more details.
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs; see the file COPYING. If not, write to the
28 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
29 ;; Boston, MA 02111-1307, USA.
33 ;; This mode provides mail-sending facilities from within Emacs. It
34 ;; consists mainly of large chunks of code from the sendmail.el,
35 ;; gnus-msg.el and rnewspost.el files.
42 (defvar gnus-message-group-art)
43 (defvar gnus-list-identifiers)) ; gnus-sum is required where necessary
47 ;; This is apparently necessary even though things are autoloaded.
48 ;; Because we dynamically bind mail-abbrev-mode-regexp, we'd better
49 ;; require mailabbrev here.
50 (if (featurep 'xemacs)
51 (require 'mail-abbrevs)
52 (require 'mailabbrev))
54 (eval-when-compile (require 'static))
56 ;; Avoid byte-compile warnings.
63 (autoload 'customize-save-variable "cus-edit") ;; for Mule 2.
64 (autoload 'sha1 "sha1-el")
65 (autoload 'gnus-find-method-for-group "gnus")
66 (autoload 'nnvirtual-find-group-art "nnvirtual")
67 (autoload 'gnus-group-decoded-name "gnus-group"))
69 (defgroup message '((user-mail-address custom-variable)
70 (user-full-name custom-variable))
71 "Mail and news message composing."
72 :link '(custom-manual "(message)Top")
76 (put 'user-mail-address 'custom-type 'string)
77 (put 'user-full-name 'custom-type 'string)
79 (defgroup message-various nil
80 "Various Message Variables"
81 :link '(custom-manual "(message)Various Message Variables")
84 (defgroup message-buffers nil
86 :link '(custom-manual "(message)Message Buffers")
89 (defgroup message-sending nil
91 :link '(custom-manual "(message)Sending Variables")
94 (defgroup message-interface nil
96 :link '(custom-manual "(message)Interface")
99 (defgroup message-forwarding nil
101 :link '(custom-manual "(message)Forwarding")
102 :group 'message-interface)
104 (defgroup message-insertion nil
106 :link '(custom-manual "(message)Insertion")
109 (defgroup message-headers nil
111 :link '(custom-manual "(message)Message Headers")
114 (defgroup message-news nil
115 "Composing News Messages"
118 (defgroup message-mail nil
119 "Composing Mail Messages"
122 (defgroup message-faces nil
123 "Faces used for message composing."
127 (defgroup message-frames nil
131 (defcustom message-directory "~/Mail/"
132 "*Directory from which all other mail file variables are derived."
133 :group 'message-various
136 (defcustom message-max-buffers 10
137 "*How many buffers to keep before starting to kill them off."
138 :group 'message-buffers
141 (defcustom message-send-rename-function nil
142 "Function called to rename the buffer after sending it."
143 :group 'message-buffers
144 :type '(choice function (const nil)))
146 (defcustom message-fcc-handler-function 'message-output
147 "*A function called to save outgoing articles.
148 This function will be called with the name of the file to store the
149 article in. The default function is `message-output' which saves in Unix
151 :type '(radio (function-item message-output)
152 (function :tag "Other"))
153 :group 'message-sending)
155 (defcustom message-encode-function 'message-maybe-encode
156 "*A function called to encode messages."
157 :group 'message-sending
160 (defcustom message-8bit-encoding-list '(8bit binary)
161 "*8bit encoding type in Content-Transfer-Encoding field."
162 :group 'message-sending
163 :type '(repeat (symbol :tag "Type")))
165 (defcustom message-fcc-externalize-attachments nil
166 "If non-nil, attachments are included as external parts in Fcc copies."
168 :group 'message-sending)
170 (defcustom message-courtesy-message
171 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
172 "*This is inserted at the start of a mailed copy of a posted message.
173 If the string contains the format spec \"%s\", the Newsgroups
174 the article has been posted to will be inserted there.
175 If this variable is nil, no such courtesy message will be added."
176 :group 'message-sending
177 :type '(radio (string :format "%t: %v\n" :size 0) (const nil)))
179 (defcustom message-ignored-bounced-headers
180 "^\\(Received\\|Return-Path\\|Delivered-To\\):"
181 "*Regexp that matches headers to be removed in resent bounced mail."
182 :group 'message-interface
185 (defcustom message-bounce-setup-function 'message-bounce-setup-for-mime-edit
186 "Function to setup a re-sending bounced message."
187 :group 'message-sending
190 ;;; Start of variables adopted from `message-utils.el'.
192 (defcustom message-subject-trailing-was-query 'ask
193 "*What to do with trailing \"(was: <old subject>)\" in subject lines.
194 If nil, leave the subject unchanged. If it is the symbol `ask', query
195 the user what do do. In this case, the subject is matched against
196 `message-subject-trailing-was-ask-regexp'. If
197 `message-subject-trailing-was-query' is t, always strip the trailing
198 old subject. In this case, `message-subject-trailing-was-regexp' is
200 :type '(choice (const :tag "never" nil)
201 (const :tag "always strip" t)
203 :link '(custom-manual "(message)Message Headers")
204 :group 'message-various)
206 (defcustom message-subject-trailing-was-ask-regexp
207 "[ \t]*\\([[(]+[Ww][Aa][Ss][ \t]*.*[\])]+\\)"
208 "*Regexp matching \"(was: <old subject>)\" in the subject line.
210 The function `message-strip-subject-trailing-was' uses this regexp if
211 `message-subject-trailing-was-query' is set to the symbol `ask'. If
212 the variable is t instead of `ask', use
213 `message-subject-trailing-was-regexp' instead.
215 It is okay to create some false positives here, as the user is asked."
216 :group 'message-various
217 :link '(custom-manual "(message)Message Headers")
220 (defcustom message-subject-trailing-was-regexp
221 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
222 "*Regexp matching \"(was: <old subject>)\" in the subject line.
224 If `message-subject-trailing-was-query' is set to t, the subject is
225 matched against `message-subject-trailing-was-regexp' in
226 `message-strip-subject-trailing-was'. You should use a regexp creating very
227 few false positives here."
228 :group 'message-various
229 :link '(custom-manual "(message)Message Headers")
232 ;; Fixme: Why are all these things autoloaded?
234 ;;; marking inserted text
237 (defcustom message-mark-insert-begin
238 "--8<---------------cut here---------------start------------->8---\n"
239 "How to mark the beginning of some inserted text."
241 :link '(custom-manual "(message)Insertion Variables")
242 :group 'message-various)
245 (defcustom message-mark-insert-end
246 "--8<---------------cut here---------------end--------------->8---\n"
247 "How to mark the end of some inserted text."
249 :link '(custom-manual "(message)Insertion Variables")
250 :group 'message-various)
253 (defcustom message-archive-header
254 "X-No-Archive: Yes\n"
255 "Header to insert when you don't want your article to be archived.
256 Archives \(such as groups.google.com\) respect this header."
258 :link '(custom-manual "(message)Header Commands")
259 :group 'message-various)
262 (defcustom message-archive-note
263 "X-No-Archive: Yes - save http://groups.google.com/"
264 "Note to insert why you wouldn't want this posting archived.
265 If nil, don't insert any text in the body."
266 :type '(radio (string :format "%t: %v\n" :size 0)
268 :link '(custom-manual "(message)Header Commands")
269 :group 'message-various)
271 ;;; Crossposts and Followups
272 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
273 ;; new suggestions by R. Weikusat <rw at another.de>
275 (defvar message-cross-post-old-target nil
276 "Old target for cross-posts or follow-ups.")
277 (make-variable-buffer-local 'message-cross-post-old-target)
280 (defcustom message-cross-post-default t
281 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
282 If nil, `message-cross-post-followup-to' will only do a followup. Note that
283 you can explicitly override this setting by calling
284 `message-cross-post-followup-to' with a prefix."
286 :group 'message-various)
289 (defcustom message-cross-post-note
290 "Crosspost & Followup-To: "
291 "Note to insert before signature to notify of xpost and follow-up."
293 :group 'message-various)
296 (defcustom message-followup-to-note
298 "Note to insert before signature to notify of follow-up only."
300 :group 'message-various)
303 (defcustom message-cross-post-note-function
304 'message-cross-post-insert-note
305 "Function to use to insert note about Crosspost or Followup-To.
306 The function will be called with four arguments. The function should not only
307 insert a note, but also ensure old notes are deleted. See the documentation
308 for `message-cross-post-insert-note'."
310 :group 'message-various)
312 ;;; End of variables adopted from `message-utils.el'.
315 (defcustom message-from-style 'default
316 "*Specifies how \"From\" headers look.
318 If nil, they contain just the return address like:
320 If `parens', they look like:
321 king@grassland.com (Elvis Parsley)
322 If `angles', they look like:
323 Elvis Parsley <king@grassland.com>
325 Otherwise, most addresses look like `angles', but they look like
326 `parens' if `angles' would need quoting and `parens' would not."
327 :type '(choice (const :tag "simple" nil)
331 :group 'message-headers)
333 (defcustom message-insert-canlock t
334 "Whether to insert a Cancel-Lock header in news postings."
336 :group 'message-headers
339 (defcustom message-syntax-checks
340 (if message-insert-canlock '((sender . disabled)) nil)
341 ;; Guess this one shouldn't be easy to customize...
342 "*Controls what syntax checks should not be performed on outgoing posts.
343 To disable checking of long signatures, for instance, add
344 `(signature . disabled)' to this list.
346 Don't touch this variable unless you really know what you're doing.
348 Checks include `subject-cmsg', `multiple-headers', `sendsys',
349 `message-id', `from', `long-lines', `control-chars', `size',
350 `new-text', `quoting-style', `redirected-followup', `signature',
351 `approved', `sender', `empty', `empty-headers', `message-id', `from',
352 `subject', `shorten-followup-to', `existing-newsgroups',
353 `buffer-file-name', `unchanged', `newsgroups', `reply-to',
354 `continuation-headers', `long-header-lines', `invisible-text' and
357 :type '(repeat sexp)) ; Fixme: improve this
359 (defcustom message-required-headers '((optional . References)
361 "*Headers to be generated or prompted for when sending a message.
362 Also see `message-required-news-headers' and
363 `message-required-mail-headers'."
365 :group 'message-headers
366 :link '(custom-manual "(message)Message Headers")
367 :type '(repeat sexp))
369 (defcustom message-draft-headers '(References From)
370 "*Headers to be generated when saving a draft message."
372 :group 'message-headers
373 :link '(custom-manual "(message)Message Headers")
374 :type '(repeat sexp))
376 (defcustom message-required-news-headers
377 '(From Newsgroups Subject Date Message-ID
378 (optional . Organization)
379 (optional . User-Agent))
380 "*Headers to be generated or prompted for when posting an article.
381 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
382 Message-ID. Organization, Lines, In-Reply-To, Expires, and
383 User-Agent are optional. If don't you want message to insert some
384 header, remove it from this list."
386 :group 'message-headers
387 :link '(custom-manual "(message)Message Headers")
388 :type '(repeat sexp))
390 (defcustom message-required-mail-headers
391 '(From Subject Date (optional . In-Reply-To) Message-ID
392 (optional . User-Agent))
393 "*Headers to be generated or prompted for when mailing a message.
394 It is recommended that From, Date, To, Subject and Message-ID be
395 included. Organization and User-Agent are optional."
397 :group 'message-headers
398 :link '(custom-manual "(message)Message Headers")
399 :type '(repeat sexp))
401 (defcustom message-deletable-headers '(Message-ID Date Lines)
402 "Headers to be deleted if they already exist and were generated by message previously."
403 :group 'message-headers
404 :link '(custom-manual "(message)Message Headers")
407 (defcustom message-ignored-news-headers
408 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
409 "*Regexp of headers to be removed unconditionally before posting."
411 :group 'message-headers
412 :link '(custom-manual "(message)Message Headers")
415 (defcustom message-ignored-mail-headers
416 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
417 "*Regexp of headers to be removed unconditionally before mailing."
419 :group 'message-headers
420 :link '(custom-manual "(message)Mail Headers")
423 (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:"
424 "*Header lines matching this regexp will be deleted before posting.
425 It's best to delete old Path and Date headers before posting to avoid
427 :group 'message-interface
428 :link '(custom-manual "(message)Superseding")
431 (defcustom message-supersede-setup-function
432 'message-supersede-setup-for-mime-edit
433 "Function to setup a supersede message."
434 :group 'message-sending
437 (defcustom message-subject-re-regexp
438 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)*:[ \t]*\\)*[ \t]*"
439 "*Regexp matching \"Re: \" in the subject line."
440 :group 'message-various
441 :link '(custom-manual "(message)Message Headers")
444 ;;; Some sender agents encode the whole subject including leading "Re: ".
445 ;;; And if followup agent does not decode it for some reason (e.g. unknown
446 ;;; charset) and just add a new "Re: " in front of the encoded-word, the
447 ;;; result will contain multiple "Re: "'s.
448 (defcustom message-subject-encoded-re-regexp
452 "[-!#$%&'*+0-9A-Z^_`a-z{|}~]+" ; charset
455 "[Bb]" (regexp-quote "?") ; B encoding
456 "\\(\\(CQk\\|CSA\\|IAk\\|ICA\\)[Jg]\\)*" ; \([ \t][ \t][ \t]\)*
458 "[Uc][km]U6" ; [Rr][Ee]:
460 "\\(C[VX]\\|I[FH]\\)J[Fl]O[g-v]" ; [ \t][Rr][Ee]:
462 "\\(CQl\\|CSB\\|IAl\\|ICB\\)[Sy][RZ]T[o-r]" ; [ \t][ \t][Rr][Ee]:
465 "[Qb]" (regexp-quote "?") ; Q encoding
466 "\\(_\\|=09\\|=20\\)*"
467 "\\([Rr]\\|=[57]2\\)\\([Ee]\\|=[46]5\\)\\(:\\|=3[Aa]\\)"
470 "*Regexp matching \"Re: \" in the subject line.
471 Unlike `message-subject-re-regexp', this regexp matches \"Re: \" within
473 :group 'message-various
474 :link '(custom-manual "(message)Message Headers")
477 (defcustom message-use-subject-re t
478 "*If t, remove any (buggy) \"Re: \"'s from the subject of the precursor
479 and add a new \"Re: \". If it is nil, use the subject \"as-is\". If it
480 is the symbol `guess', try to detect \"Re: \" within an encoded-word."
481 :group 'message-various
482 :type '(choice (const :tag "off" nil)
487 (defcustom message-signature-separator "^-- *$"
488 "Regexp matching the signature separator."
490 :link '(custom-manual "(message)Various Message Variables")
491 :group 'message-various)
493 (defcustom message-signature-separator-for-insertion "-- \n"
494 "*Signature separator. This value will be inserted as signature separator
495 when composing message. Default value is \"-- \\n\". Notice: Changing this
496 value may go against RFC-1036 and draft-ietf-usefor-article-05.txt. "
498 :group 'message-insertion)
500 (defcustom message-elide-ellipsis "\n[...]\n\n"
501 "*The string which is inserted for elided text."
503 :link '(custom-manual "(message)Insertion Variables")
504 :group 'message-various)
506 (defcustom message-interactive t
507 "Non-nil means when sending a message wait for and display errors.
508 nil means let mailer mail back a message to report errors."
509 :group 'message-sending
511 :link '(custom-manual "(message)Sending Variables")
514 (defcustom message-generate-new-buffers 'unique
515 "*Non-nil means create a new message buffer whenever `message-setup' is called.
516 If this is a function, call that function with three parameters: The type,
517 the to address and the group name. (Any of these may be nil.) The function
518 should return the new buffer name."
519 :group 'message-buffers
520 :link '(custom-manual "(message)Message Buffers")
521 :type '(choice (const :tag "off" nil)
522 (const :tag "unique" unique)
523 (const :tag "unsent" unsent)
526 (defcustom message-kill-buffer-on-exit nil
527 "*Non-nil means that the message buffer will be killed after sending a message."
528 :group 'message-buffers
529 :link '(custom-manual "(message)Message Buffers")
532 (defcustom message-kill-buffer-query-function 'yes-or-no-p
533 "*Function used to prompt user whether to kill the message buffer. If
534 it is t, the buffer will be killed unconditionally."
535 :type '(radio (function-item yes-or-no-p)
536 (function-item y-or-n-p)
537 (function-item nnheader-Y-or-n-p)
538 (function :tag "Other" t))
539 :group 'message-buffers)
541 (defcustom message-kill-buffer-and-remove-file t
542 "*Non-nil means that the associated file will be removed before
543 removing the message buffer. However, it is treated as nil when the
544 command `message-mimic-kill-buffer' is used."
545 :group 'message-buffers
549 (defvar gnus-local-organization))
550 (defcustom message-user-organization
551 (or (and (boundp 'gnus-local-organization)
552 (stringp gnus-local-organization)
553 gnus-local-organization)
554 (getenv "ORGANIZATION")
556 "*String to be used as an Organization header.
557 If t, use `message-user-organization-file'."
558 :group 'message-headers
559 :type '(choice string
560 (const :tag "consult file" t)))
563 (defcustom message-user-organization-file "/usr/lib/news/organization"
564 "*Local news organization file."
566 :link '(custom-manual "(message)News Headers")
567 :group 'message-headers)
569 (defcustom message-forward-start-separator
570 (concat (mime-make-tag "message" "rfc822") "\n")
571 "*Delimiter inserted before forwarded messages."
572 :group 'message-forwarding
575 (defcustom message-forward-end-separator
576 (concat (mime-make-tag "text" "plain") "\n")
577 "*Delimiter inserted after forwarded messages."
578 :group 'message-forwarding
581 (defcustom message-included-forward-headers
582 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^\\(Mail-\\)?Followup-To:\\|^\\(Mail-\\)?Reply-To:\\|^Mail-Copies-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-\\|^Message-ID:\\|^References:\\|^Content-\\|^MIME-Version:"
583 "*Regexp matching headers to be included in forwarded messages."
584 :group 'message-forwarding
587 (defcustom message-make-forward-subject-function
588 #'message-forward-subject-name-subject
589 "*List of functions called to generate subject headers for forwarded messages.
590 The subject generated by the previous function is passed into each
593 The provided functions are:
595 * `message-forward-subject-author-subject' Source of article (author or
596 newsgroup), in brackets followed by the subject
597 * `message-forward-subject-name-subject' Source of article (name of author
598 or newsgroup), in brackets followed by the subject
599 * `message-forward-subject-fwd' Subject of article with 'Fwd:' prepended
601 :group 'message-forwarding
602 :link '(custom-manual "(message)Forwarding")
603 :type '(radio (function-item message-forward-subject-author-subject)
604 (function-item message-forward-subject-fwd)
605 (function-item message-forward-subject-name-subject)
606 (repeat :tag "List of functions" function)))
608 (defcustom message-forward-as-mime t
609 "*Non-nil means forward messages as an inline/rfc822 MIME section.
610 Otherwise, directly inline the old message in the forwarded message."
612 :group 'message-forwarding
613 :link '(custom-manual "(message)Forwarding")
616 (defcustom message-forward-show-mml 'best
617 "*Non-nil means show forwarded messages as MML (decoded from MIME).
618 Otherwise, forwarded messages are unchanged.
619 Can also be the symbol `best' to indicate that MML should be
620 used, except when it is a bad idea to use MML. One example where
621 it is a bad idea is when forwarding a signed or encrypted
622 message, because converting MIME to MML would invalidate the
625 :group 'message-forwarding
626 :type '(choice (const :tag "use MML" t)
627 (const :tag "don't use MML " nil)
628 (const :tag "use MML when appropriate" best)))
630 (defcustom message-forward-before-signature t
631 "*Non-nil means put forwarded message before signature, else after."
632 :group 'message-forwarding
635 (defcustom message-wash-forwarded-subjects nil
636 "*Non-nil means try to remove as much cruft as possible from the subject.
637 Done before generating the new subject of a forward."
638 :group 'message-forwarding
639 :link '(custom-manual "(message)Forwarding")
642 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From "
643 "*All headers that match this regexp will be deleted when resending a message."
644 :group 'message-interface
645 :link '(custom-manual "(message)Resending")
648 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
649 "*All headers that match this regexp will be deleted when forwarding a message."
651 :group 'message-forwarding
652 :type '(choice (const :tag "None" nil)
655 (defcustom message-ignored-cited-headers "."
656 "*Delete these headers from the messages you yank."
657 :group 'message-insertion
658 :link '(custom-manual "(message)Insertion Variables")
661 (defcustom message-cite-prefix-regexp
662 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
663 "\\([ \t]*[-_.[:word:]]+>+\\|[ \t]*[]>|}+]\\)+"
664 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
665 (let ((old-table (syntax-table))
666 non-word-constituents)
667 (set-syntax-table text-mode-syntax-table)
668 (setq non-word-constituents
670 (if (string-match "\\w" "-") "" "-")
671 (if (string-match "\\w" "_") "" "_")
672 (if (string-match "\\w" ".") "" ".")))
673 (set-syntax-table old-table)
674 (if (equal non-word-constituents "")
675 "\\([ \t]*\\(\\w\\)+>+\\|[ \t]*[]>|}+]\\)+"
676 (concat "\\([ \t]*\\(\\w\\|["
677 non-word-constituents
678 "]\\)+>+\\|[ \t]*[]>|}+]\\)+"))))
679 "*Regexp matching the longest possible citation prefix on a line."
680 :group 'message-insertion
681 :link '(custom-manual "(message)Insertion Variables")
684 (defcustom message-cancel-message "I am canceling my own article.\n"
685 "Message to be inserted in the cancel message."
686 :group 'message-interface
687 :link '(custom-manual "(message)Canceling News")
690 ;; Useful to set in site-init.el
692 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
693 "Function to call to send the current buffer as mail.
694 The headers should be delimited by a line whose contents match the
695 variable `mail-header-separator'.
697 Valid values include `message-send-mail-with-sendmail' (the default),
698 `message-send-mail-with-mh', `message-send-mail-with-qmail',
699 `message-send-mail-with-smtp', `message-smtpmail-send-it',
700 `smtpmail-send-it' and `feedmail-send-it'.
702 See also `send-mail-function'."
703 :type '(radio (function-item message-send-mail-with-sendmail)
704 (function-item message-send-mail-with-mh)
705 (function-item message-send-mail-with-qmail)
706 (function-item message-send-mail-with-smtp)
707 (function-item message-smtpmail-send-it)
708 (function-item smtpmail-send-it)
709 (function-item feedmail-send-it)
710 (function :tag "Other"))
711 :group 'message-sending
712 :link '(custom-manual "(message)Mail Variables")
713 :group 'message-mail)
715 ;; 1997-09-29 by MORIOKA Tomohiko
716 (defcustom message-send-news-function 'message-send-news-with-gnus
717 "Function to call to send the current buffer as news.
718 The headers should be delimited by a line whose contents match the
719 variable `mail-header-separator'."
720 :group 'message-sending
722 :link '(custom-manual "(message)News Variables")
725 (defcustom message-reply-to-function nil
726 "If non-nil, function that should return a list of headers.
727 This function should pick out addresses from the To, Cc, and From headers
728 and respond with new To and Cc headers."
729 :group 'message-interface
730 :link '(custom-manual "(message)Reply")
731 :type '(choice function (const nil)))
733 (defcustom message-wide-reply-to-function nil
734 "If non-nil, function that should return a list of headers.
735 This function should pick out addresses from the To, Cc, and From headers
736 and respond with new To and Cc headers."
737 :group 'message-interface
738 :link '(custom-manual "(message)Wide Reply")
739 :type '(choice function (const nil)))
741 (defcustom message-followup-to-function nil
742 "If non-nil, function that should return a list of headers.
743 This function should pick out addresses from the To, Cc, and From headers
744 and respond with new To and Cc headers."
745 :group 'message-interface
746 :link '(custom-manual "(message)Followup")
747 :type '(choice function (const nil)))
749 (defcustom message-use-followup-to 'ask
750 "*Specifies what to do with Followup-To header.
751 If nil, always ignore the header. If it is t, use its value, but
752 query before using the \"poster\" value. If it is the symbol `ask',
753 always query the user whether to use the value. If it is the symbol
754 `use', always use the value."
755 :group 'message-interface
756 :link '(custom-manual "(message)Followup")
757 :type '(choice (const :tag "ignore" nil)
758 (const :tag "use & query" t)
759 (const :tag "maybe" t)
760 (const :tag "always" use)
761 (const :tag "ask" ask)))
763 (defcustom message-use-mail-copies-to 'ask
764 "*Specifies what to do with Mail-Copies-To header.
765 If nil, always ignore the header. If it is t, use its value, but
766 query before using the value other than \"always\" or \"never\".
767 If it is the symbol `ask', always query the user whether to use
768 the value. If it is the symbol `use', always use the value."
769 :group 'message-interface
770 :link '(custom-manual "(message)Mailing Lists")
771 :type '(choice (const :tag "ignore" nil)
772 (const :tag "maybe" t)
773 (const :tag "always" use)
774 (const :tag "ask" ask)))
776 ;;; XXX: 'ask and 'use are not implemented yet.
777 (defcustom message-use-mail-reply-to 'ask
778 "*Specifies what to do with Mail-Reply-To/Reply-To header.
779 If nil, always ignore the header. If it is t or the symbol `use', use
780 its value. If it is the symbol `ask', always query the user whether to
781 use the value. Note that if \"Reply-To\" is marked as \"broken\", its value
783 :group 'message-interface
784 :type '(choice (const :tag "ignore" nil)
785 (const :tag "maybe" t)
786 (const :tag "always" use)
787 (const :tag "ask" ask)))
789 (defcustom message-use-mail-followup-to 'use
790 "*Specifies what to do with Mail-Followup-To header.
791 If nil, always ignore the header. If it is the symbol `ask', always
792 query the user whether to use the value. If it is t or the symbol
793 `use', always use the value."
794 :group 'message-interface
795 :type '(choice (const :tag "ignore" nil)
796 (const :tag "maybe" t)
797 (const :tag "always" use)
798 (const :tag "ask" ask)))
800 (defcustom message-subscribed-address-functions nil
801 "*Specifies functions for determining list subscription.
802 If nil, do not attempt to determine list subscription with functions.
803 If non-nil, this variable contains a list of functions which return
804 regular expressions to match lists. These functions can be used in
805 conjunction with `message-subscribed-regexps' and
806 `message-subscribed-addresses'."
807 :group 'message-interface
808 :link '(custom-manual "(message)Mailing Lists")
809 :type '(repeat sexp))
811 (defcustom message-subscribed-address-file nil
812 "*A file containing addresses the user is subscribed to.
813 If nil, do not look at any files to determine list subscriptions. If
814 non-nil, each line of this file should be a mailing list address."
815 :group 'message-interface
816 :link '(custom-manual "(message)Mailing Lists")
817 :type '(radio (file :format "%t: %v\n" :size 0)
820 (defcustom message-subscribed-addresses nil
821 "*Specifies a list of addresses the user is subscribed to.
822 If nil, do not use any predefined list subscriptions. This list of
823 addresses can be used in conjunction with
824 `message-subscribed-address-functions' and `message-subscribed-regexps'."
825 :group 'message-interface
826 :link '(custom-manual "(message)Mailing Lists")
827 :type '(repeat string))
829 (defcustom message-subscribed-regexps nil
830 "*Specifies a list of addresses the user is subscribed to.
831 If nil, do not use any predefined list subscriptions. This list of
832 regular expressions can be used in conjunction with
833 `message-subscribed-address-functions' and `message-subscribed-addresses'."
834 :group 'message-interface
835 :link '(custom-manual "(message)Mailing Lists")
836 :type '(repeat regexp))
838 (defcustom message-allow-no-recipients 'ask
839 "Specifies what to do when there are no recipients other than Gcc/Fcc.
840 If it is the symbol `always', the posting is allowed. If it is the
841 symbol `never', the posting is not allowed. If it is the symbol
842 `ask', you are prompted."
843 :group 'message-interface
844 :link '(custom-manual "(message)Message Headers")
845 :type '(choice (const always)
849 (defcustom message-sendmail-f-is-evil nil
850 "*Non-nil means don't add \"-f username\" to the sendmail command line.
851 Doing so would be even more evil than leaving it out."
852 :group 'message-sending
853 :link '(custom-manual "(message)Mail Variables")
856 (defcustom message-sendmail-envelope-from nil
857 "*Envelope-from when sending mail with sendmail.
858 If this is nil, use `user-mail-address'. If it is the symbol
859 `header', use the From: header of the message."
860 :type '(choice (string :tag "From name")
861 (const :tag "Use From: header from message" header)
862 (const :tag "Use `user-mail-address'" nil))
863 :link '(custom-manual "(message)Mail Variables")
864 :group 'message-sending)
866 ;; qmail-related stuff
867 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
868 "Location of the qmail-inject program."
869 :group 'message-sending
870 :link '(custom-manual "(message)Mail Variables")
873 (defcustom message-qmail-inject-args nil
874 "Arguments passed to qmail-inject programs.
875 This should be a list of strings, one string for each argument. It
876 may also be a function.
878 For e.g., if you wish to set the envelope sender address so that bounces
879 go to the right place or to deal with listserv's usage of that address, you
880 might set this variable to '(\"-f\" \"you@some.where\")."
881 :group 'message-sending
882 :link '(custom-manual "(message)Mail Variables")
883 :type '(choice (function)
886 (defvar message-cater-to-broken-inn t
887 "Non-nil means Gnus should not fold the `References' header.
888 Folding `References' makes ancient versions of INN create incorrect
892 (defvar gnus-post-method)
893 (defvar gnus-select-method))
894 (defcustom message-post-method
895 (cond ((and (boundp 'gnus-post-method)
896 (listp gnus-post-method)
899 ((boundp 'gnus-select-method)
902 "*Method used to post news.
903 Note that when posting from inside Gnus, for instance, this
904 variable isn't used."
906 :group 'message-sending
907 ;; This should be the `gnus-select-method' widget, but that might
908 ;; create a dependence to `gnus.el'.
911 ;; FIXME: This should be a temporary workaround until someone implements a
912 ;; proper solution. If a crash happens while replying, the auto-save file
913 ;; will *not* have a `References:' header if `message-generate-headers-first'
914 ;; is nil. See: http://article.gmane.org/gmane.emacs.gnus.general/51138
915 (defcustom message-generate-headers-first '(references)
916 "Which headers should be generated before starting to compose a message.
917 If `t', generate all required headers. This can also be a list of headers to
918 generate. The variables `message-required-news-headers' and
919 `message-required-mail-headers' specify which headers to generate.
921 Note that the variable `message-deletable-headers' specifies headers which
922 are to be deleted and then re-generated before sending, so this variable
923 will not have a visible effect for those headers."
924 :group 'message-headers
925 :link '(custom-manual "(message)Message Headers")
926 :type '(choice (const :tag "None" nil)
927 (const :tag "References" '(references))
929 (repeat (sexp :tag "Header"))))
931 (defcustom message-setup-hook '(turn-on-mime-edit)
932 "Normal hook, run each time a new outgoing message is initialized.
933 The function `message-setup' runs this hook."
934 :group 'message-various
935 :link '(custom-manual "(message)Various Message Variables")
938 (defcustom message-cancel-hook nil
939 "Hook run when cancelling articles."
940 :group 'message-various
941 :link '(custom-manual "(message)Various Message Variables")
944 (defcustom message-signature-setup-hook nil
945 "Normal hook, run each time a new outgoing message is initialized.
946 It is run after the headers have been inserted and before
947 the signature is inserted."
948 :group 'message-various
949 :link '(custom-manual "(message)Various Message Variables")
952 (defcustom message-bounce-setup-hook nil
953 "Normal hook, run each time a re-sending bounced message is initialized.
954 The function `message-bounce' runs this hook."
955 :group 'message-various
958 (defcustom message-supersede-setup-hook nil
959 "Normal hook, run each time a supersede message is initialized.
960 The function `message-supersede' runs this hook."
961 :group 'message-various
964 (defcustom message-mode-hook nil
965 "Hook run in message mode buffers."
966 :group 'message-various
969 (defcustom message-header-hook '((lambda () (mime-encode-header-in-buffer t)))
970 "Hook run in a message mode buffer narrowed to the headers."
971 :group 'message-various
974 (defcustom message-header-setup-hook nil
975 "Hook called narrowed to the headers when setting up a message buffer."
976 :group 'message-various
977 :link '(custom-manual "(message)Various Message Variables")
980 (defcustom message-minibuffer-local-map
981 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
982 (set-keymap-parent map minibuffer-local-map)
984 "Keymap for `message-read-from-minibuffer'.")
987 (defcustom message-citation-line-function 'message-insert-citation-line
988 "*Function called to insert the \"Whomever writes:\" line.
990 Note that Gnus provides a feature where the reader can click on
991 `writes:' to hide the cited text. If you change this line too much,
992 people who read your message will have to change their Gnus
993 configuration. See the variable `gnus-cite-attribution-suffix'."
995 :link '(custom-manual "(message)Insertion Variables")
996 :group 'message-insertion)
999 (defcustom message-yank-prefix "> "
1000 "*Prefix inserted on the lines of yanked messages.
1001 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1002 See also `message-yank-cited-prefix'."
1004 :link '(custom-manual "(message)Insertion Variables")
1005 :group 'message-insertion)
1007 (defcustom message-yank-add-new-references t
1008 "Non-nil means new IDs will be added to \"References\" field when an
1009 article is yanked by the command `message-yank-original' interactively.
1010 If it is a symbol `message-id-only', only an ID from \"Message-ID\" field
1011 is used, otherwise IDs extracted from \"References\", \"In-Reply-To\" and
1012 \"Message-ID\" fields are used."
1013 :type '(radio (const :tag "Do not add anything" nil)
1014 (const :tag "From Message-Id, References and In-Reply-To fields" t)
1015 (const :tag "From only Message-Id field." message-id-only))
1016 :group 'message-insertion)
1018 (defcustom message-list-references-add-position nil
1019 "Integer value means position for adding to \"References\" field when
1020 an article is yanked by the command `message-yank-original' interactively."
1021 :type '(radio (const :tag "Add to last" nil)
1022 (integer :tag "Position from last ID"))
1023 :group 'message-insertion)
1025 (defcustom message-yank-cited-prefix ">"
1026 "*Prefix inserted on cited or empty lines of yanked messages.
1027 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1028 See also `message-yank-prefix'."
1030 :link '(custom-manual "(message)Insertion Variables")
1031 :group 'message-insertion)
1033 (defcustom message-indentation-spaces 3
1034 "*Number of spaces to insert at the beginning of each cited line.
1035 Used by `message-yank-original' via `message-yank-cite'."
1036 :group 'message-insertion
1037 :link '(custom-manual "(message)Insertion Variables")
1041 (defcustom message-cite-function 'message-cite-original
1042 "*Function for citing an original message.
1043 Predefined functions include `message-cite-original' and
1044 `message-cite-original-without-signature'.
1045 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
1046 :type '(radio (function-item message-cite-original)
1047 (function-item message-cite-original-without-signature)
1048 (function-item mu-cite-original)
1049 (function-item sc-cite-original)
1050 (function :tag "Other"))
1051 :link '(custom-manual "(message)Insertion Variables")
1052 :group 'message-insertion)
1055 (defcustom message-suspend-font-lock-when-citing nil
1056 "Non-nil means suspend font-lock'ing while citing an original message.
1057 Some lazy demand-driven fontification tools (or Emacs itself) have a
1058 bug that they often miss a buffer to be fontified. It will mostly
1059 occur when Emacs prompts user for any inputs in the minibuffer.
1060 Setting this option to non-nil may help you to avoid unpleasant errors
1061 even if it is an add-hoc expedient."
1063 :group 'message-insertion)
1066 (defcustom message-indent-citation-function 'message-indent-citation
1067 "*Function for modifying a citation just inserted in the mail buffer.
1068 This can also be a list of functions. Each function can find the
1069 citation between (point) and (mark t). And each function should leave
1070 point and mark around the citation text as modified."
1072 :link '(custom-manual "(message)Insertion Variables")
1073 :group 'message-insertion)
1076 (defcustom message-signature t
1077 "*String to be inserted at the end of the message buffer.
1078 If t, the `message-signature-file' file will be inserted instead.
1079 If a function, the result from the function will be used instead.
1080 If a form, the result from the form will be used instead."
1082 :link '(custom-manual "(message)Insertion Variables")
1083 :group 'message-insertion)
1086 (defcustom message-signature-file "~/.signature"
1087 "*Name of file containing the text inserted at end of message buffer.
1088 Ignored if the named file doesn't exist.
1089 If nil, don't insert a signature."
1090 :type '(choice file (const :tags "None" nil))
1091 :link '(custom-manual "(message)Insertion Variables")
1092 :group 'message-insertion)
1095 (defcustom message-signature-insert-empty-line t
1096 "*If non-nil, insert an empty line before the signature separator."
1098 :link '(custom-manual "(message)Insertion Variables")
1099 :group 'message-insertion)
1101 (defcustom message-distribution-function nil
1102 "*Function called to return a Distribution header."
1103 :group 'message-news
1104 :group 'message-headers
1105 :link '(custom-manual "(message)News Headers")
1106 :type '(choice function (const nil)))
1108 (defcustom message-expires 14
1109 "Number of days before your article expires."
1110 :group 'message-news
1111 :group 'message-headers
1112 :link '(custom-manual "(message)News Headers")
1115 (defcustom message-user-path nil
1116 "If nil, use the NNTP server name in the Path header.
1117 If stringp, use this; if non-nil, use no host name (user name only)."
1118 :group 'message-news
1119 :group 'message-headers
1120 :link '(custom-manual "(message)News Headers")
1121 :type '(choice (const :tag "nntp" nil)
1122 (string :tag "name")
1123 (sexp :tag "none" :format "%t" t)))
1125 (defvar message-reply-buffer nil)
1126 (defvar message-reply-headers nil
1127 "The headers of the current replied article.
1128 It is a vector of the following headers:
1129 \[number subject from date id references chars lines xref extra].")
1130 (defvar message-sent-message-via nil)
1131 (defvar message-checksum nil)
1132 (defvar message-send-actions nil
1133 "A list of actions to be performed upon successful sending of a message.")
1134 (defvar message-exit-actions nil
1135 "A list of actions to be performed upon exiting after sending a message.")
1136 (defvar message-kill-actions nil
1137 "A list of actions to be performed before killing a message buffer.")
1138 (defvar message-postpone-actions nil
1139 "A list of actions to be performed after postponing a message.")
1140 (defvar message-original-frame nil)
1141 (defvar message-parameter-alist nil)
1142 (defvar message-startup-parameter-alist nil)
1144 (define-widget 'message-header-lines 'text
1145 "All header lines must be LFD terminated."
1146 :format "%{%t%}:%n%v"
1147 :valid-regexp "^\\'"
1148 :error "All header lines must be newline terminated")
1150 (defcustom message-default-headers ""
1151 "*A string containing header lines to be inserted in outgoing messages.
1152 It is inserted before you edit the message, so you can edit or delete
1154 :group 'message-headers
1155 :link '(custom-manual "(message)Message Headers")
1156 :type 'message-header-lines)
1158 (defcustom message-default-mail-headers ""
1159 "*A string of header lines to be inserted in outgoing mails."
1160 :group 'message-headers
1161 :group 'message-mail
1162 :link '(custom-manual "(message)Mail Headers")
1163 :type 'message-header-lines)
1165 (defcustom message-default-news-headers ""
1166 "*A string of header lines to be inserted in outgoing news articles."
1167 :group 'message-headers
1168 :group 'message-news
1169 :link '(custom-manual "(message)News Headers")
1170 :type 'message-header-lines)
1172 ;; Note: could use /usr/ucb/mail instead of sendmail;
1173 ;; options -t, and -v if not interactive.
1174 (defcustom message-mailer-swallows-blank-line
1175 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1176 system-configuration)
1177 (file-readable-p "/etc/sendmail.cf")
1178 (let ((buffer (get-buffer-create " *temp*")))
1182 (insert-file-contents "/etc/sendmail.cf")
1183 (goto-char (point-min))
1184 (let ((case-fold-search nil))
1185 (re-search-forward "^OR\\>" nil t)))
1186 (kill-buffer buffer))))
1187 ;; According to RFC822, "The field-name must be composed of printable
1188 ;; ASCII characters (i. e., characters that have decimal values between
1189 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1191 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1192 "*Set this non-nil if the system's mailer runs the header and body together.
1193 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1194 The value should be an expression to test whether the problem will
1196 :group 'message-sending
1197 :link '(custom-manual "(message)Mail Variables")
1200 ;;; XXX: This symbol is overloaded! See below.
1201 (defvar message-user-agent nil
1202 "String of the form of PRODUCT/VERSION. Used for User-Agent header field.")
1205 (define-mail-user-agent 'message-user-agent
1206 'message-mail 'message-send-and-exit
1207 'message-kill-buffer 'message-send-hook)
1209 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
1210 "If non-nil, delete the deletable headers before feeding to mh.")
1212 (defvar message-send-method-alist
1213 '((news message-news-p message-send-via-news)
1214 (mail message-mail-p message-send-via-mail))
1215 "Alist of ways to send outgoing messages.
1216 Each element has the form
1218 \(TYPE PREDICATE FUNCTION)
1220 where TYPE is a symbol that names the method; PREDICATE is a function
1221 called without any parameters to determine whether the message is
1222 a message of type TYPE; and FUNCTION is a function to be called if
1223 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1226 (defcustom message-mail-alias-type 'abbrev
1227 "*What alias expansion type to use in Message buffers.
1228 The default is `abbrev', which uses mailabbrev. nil switches
1231 :link '(custom-manual "(message)Mail Aliases")
1232 :type '(choice (const :tag "Use Mailabbrev" abbrev)
1233 (const :tag "No expansion" nil)))
1235 (defcustom message-auto-save-directory
1236 (file-name-as-directory (nnheader-concat message-directory "drafts"))
1237 "*Directory where Message auto-saves buffers if Gnus isn't running.
1238 If nil, Message won't auto-save."
1239 :group 'message-buffers
1240 :link '(custom-manual "(message)Various Message Variables")
1241 :type '(choice directory (const :tag "Don't auto-save" nil)))
1243 (defcustom message-default-charset
1244 (and (featurep 'xemacs) (not (featurep 'mule)) 'iso-8859-1)
1245 "Default charset used in non-MULE XEmacsen."
1248 :link '(custom-manual "(message)Various Message Variables")
1251 (defcustom message-dont-reply-to-names
1252 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
1253 "*A regexp specifying addresses to prune when doing wide replies.
1254 A value of nil means exclude your own user name only."
1257 :link '(custom-manual "(message)Wide Reply")
1258 :type '(choice (const :tag "Yourself" nil)
1261 (defvar message-shoot-gnksa-feet nil
1262 "*A list of GNKSA feet you are allowed to shoot.
1263 Gnus gives you all the opportunity you could possibly want for
1264 shooting yourself in the foot. Also, Gnus allows you to shoot the
1265 feet of Good Net-Keeping Seal of Approval. The following are foot
1267 `empty-article' Allow you to post an empty article;
1268 `quoted-text-only' Allow you to post quoted text only;
1269 `multiple-copies' Allow you to post multiple copies;
1270 `cancel-messages' Allow you to cancel or supersede messages from
1271 your other email addresses.")
1273 (defsubst message-gnksa-enable-p (feature)
1274 (or (not (listp message-shoot-gnksa-feet))
1275 (memq feature message-shoot-gnksa-feet)))
1277 (defcustom message-hidden-headers nil
1278 "Regexp of headers to be hidden when composing new messages.
1279 This can also be a list of regexps to match headers. Or a list
1280 starting with `not' and followed by regexps."
1282 :link '(custom-manual "(message)Message Headers")
1283 :type '(repeat regexp))
1285 ;;; Internal variables.
1286 ;;; Well, not really internal.
1288 (defvar message-mode-syntax-table
1289 (let ((table (copy-syntax-table text-mode-syntax-table)))
1290 (modify-syntax-entry ?% ". " table)
1291 (modify-syntax-entry ?> ". " table)
1292 (modify-syntax-entry ?< ". " table)
1294 "Syntax table used while in Message mode.")
1296 (defface message-header-to-face
1299 (:foreground "green2" :bold t))
1302 (:foreground "MidnightBlue" :bold t))
1304 (:bold t :italic t)))
1305 "Face used for displaying From headers."
1306 :group 'message-faces)
1308 (defface message-header-cc-face
1311 (:foreground "green4" :bold t))
1314 (:foreground "MidnightBlue"))
1317 "Face used for displaying Cc headers."
1318 :group 'message-faces)
1320 (defface message-header-subject-face
1323 (:foreground "green3"))
1326 (:foreground "navy blue" :bold t))
1329 "Face used for displaying subject headers."
1330 :group 'message-faces)
1332 (defface message-header-newsgroups-face
1335 (:foreground "yellow" :bold t :italic t))
1338 (:foreground "blue4" :bold t :italic t))
1340 (:bold t :italic t)))
1341 "Face used for displaying newsgroups headers."
1342 :group 'message-faces)
1344 (defface message-header-other-face
1347 (:foreground "#b00000"))
1350 (:foreground "steel blue"))
1352 (:bold t :italic t)))
1353 "Face used for displaying newsgroups headers."
1354 :group 'message-faces)
1356 (defface message-header-name-face
1359 (:foreground "DarkGreen"))
1362 (:foreground "cornflower blue"))
1365 "Face used for displaying header names."
1366 :group 'message-faces)
1368 (defface message-header-xheader-face
1371 (:foreground "blue"))
1374 (:foreground "blue"))
1377 "Face used for displaying X-Header headers."
1378 :group 'message-faces)
1380 (defface message-separator-face
1383 (:foreground "blue3"))
1386 (:foreground "brown"))
1389 "Face used for displaying the separator."
1390 :group 'message-faces)
1392 (defface message-cited-text-face
1395 (:foreground "red"))
1398 (:foreground "red"))
1401 "Face used for displaying cited text names."
1402 :group 'message-faces)
1404 (defface message-mml-face
1407 (:foreground "ForestGreen"))
1410 (:foreground "ForestGreen"))
1413 "Face used for displaying MML."
1414 :group 'message-faces)
1416 (defun message-font-lock-make-header-matcher (regexp)
1419 (let ((start (point)))
1422 (goto-char (point-min))
1423 (if (re-search-forward
1424 (concat "^" (regexp-quote mail-header-separator) "$")
1426 (setq limit (min limit (match-beginning 0))))
1428 (and (< start limit)
1429 (re-search-forward ,regexp limit t))))))
1430 (if (featurep 'bytecomp)
1434 (defvar message-font-lock-keywords
1435 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1436 `((,(message-font-lock-make-header-matcher
1437 (concat "^\\([Tt]o:\\)" content))
1438 (1 'message-header-name-face)
1439 (2 'message-header-to-face nil t))
1440 (,(message-font-lock-make-header-matcher
1441 (concat "^\\([GBF]?[Cc][Cc]:\\|[Rr]eply-[Tt]o:\\|"
1442 "[Mm]ail-[Cc]opies-[Tt]o:\\|"
1443 "[Mm]ail-[Rr]eply-[Tt]o:\\|"
1444 "[Mm]ail-[Ff]ollowup-[Tt]o:\\)" content))
1445 (1 'message-header-name-face)
1446 (2 'message-header-cc-face nil t))
1447 (,(message-font-lock-make-header-matcher
1448 (concat "^\\([Ss]ubject:\\)" content))
1449 (1 'message-header-name-face)
1450 (2 'message-header-subject-face nil t))
1451 (,(message-font-lock-make-header-matcher
1452 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content))
1453 (1 'message-header-name-face)
1454 (2 'message-header-newsgroups-face nil t))
1455 (,(message-font-lock-make-header-matcher
1456 (concat "^\\([A-Z][^: \n\t]+:\\)" content))
1457 (1 'message-header-name-face)
1458 (2 'message-header-other-face nil t))
1459 (,(message-font-lock-make-header-matcher
1460 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content))
1461 (1 'message-header-name-face)
1462 (2 'message-header-name-face))
1463 ,@(if (and mail-header-separator
1464 (not (equal mail-header-separator "")))
1465 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1466 1 'message-separator-face))
1469 (re-search-forward (concat "^\\("
1470 message-cite-prefix-regexp
1473 (0 'message-cited-text-face))
1474 (,mime-edit-tag-regexp
1475 (0 'message-mml-face))))
1476 "Additional expressions to highlight in Message mode.")
1478 ;; XEmacs does it like this. For Emacs, we have to set the
1479 ;; `font-lock-defaults' buffer-local variable.
1480 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
1482 (defvar message-face-alist
1483 '((bold . bold-region)
1484 (underline . underline-region)
1485 (default . (lambda (b e)
1487 (ununderline-region b e))))
1488 "Alist of mail and news faces for facemenu.
1489 The cdr of each entry is a function for applying the face to a region.")
1491 (defcustom message-send-hook nil
1492 "Hook run before sending messages.
1493 This hook is run quite early when sending."
1494 :group 'message-various
1495 :options '(ispell-message)
1496 :link '(custom-manual "(message)Various Message Variables")
1499 (defcustom message-send-mail-hook nil
1500 "Hook run before sending mail messages.
1501 This hook is run very late -- just before the message is sent as
1503 :group 'message-various
1504 :link '(custom-manual "(message)Various Message Variables")
1507 (defcustom message-send-news-hook nil
1508 "Hook run before sending news messages.
1509 This hook is run very late -- just before the message is sent as
1511 :group 'message-various
1512 :link '(custom-manual "(message)Various Message Variables")
1515 (defcustom message-sent-hook nil
1516 "Hook run after sending messages."
1517 :group 'message-various
1520 (defcustom message-use-multi-frames nil
1521 "Make new frame when sending messages."
1522 :group 'message-frames
1525 (defcustom message-delete-frame-on-exit nil
1526 "Delete frame after sending messages."
1527 :group 'message-frames
1528 :type '(choice (const :tag "off" nil)
1529 (const :tag "always" t)
1530 (const :tag "ask" ask)))
1532 (defvar message-draft-coding-system
1533 nnheader-auto-save-coding-system
1534 "*Coding system to compose mail.
1535 If you'd like to make it possible to share draft files between XEmacs
1536 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1537 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1539 (defcustom message-send-mail-partially-limit 1000000
1540 "The limitation of messages sent as message/partial.
1541 The lower bound of message size in characters, beyond which the message
1542 should be sent in several parts. If it is nil, the size is unlimited."
1544 :group 'message-buffers
1545 :link '(custom-manual "(message)Mail Variables")
1546 :type '(choice (const :tag "unlimited" nil)
1549 (defcustom message-alternative-emails nil
1550 "A regexp to match the alternative email addresses.
1551 The first matched address (not primary one) is used in the From field."
1552 :group 'message-headers
1553 :link '(custom-manual "(message)Message Headers")
1554 :type '(choice (const :tag "Always use primary" nil)
1557 (defcustom message-hierarchical-addresses nil
1558 "A list of hierarchical mail address definitions.
1560 Inside each entry, the first address is the \"top\" address, and
1561 subsequent addresses are subaddresses; this is used to indicate that
1562 mail sent to the first address will automatically be delivered to the
1563 subaddresses. So if the first address appears in the recipient list
1564 for a message, the subaddresses will be removed (if present) before
1565 the mail is sent. All addresses in this structure should be
1567 :group 'message-headers
1568 :type '(repeat (repeat string)))
1570 (defcustom message-mail-user-agent nil
1571 "Like `mail-user-agent'.
1572 Except if it is nil, use Gnus native MUA; if it is t, use
1574 :type '(radio (const :tag "Gnus native"
1577 (const :tag "`mail-user-agent'"
1580 (function-item :tag "Default Emacs mail"
1582 sendmail-user-agent)
1583 (function-item :tag "Emacs interface to MH"
1586 (function :tag "Other"))
1590 (defcustom message-wide-reply-confirm-recipients nil
1591 "Whether to confirm a wide reply to multiple email recipients.
1592 If this variable is nil, don't ask whether to reply to all recipients.
1593 If this variable is non-nil, pose the question \"Reply to all
1594 recipients?\" before a wide reply to multiple recipients. If the user
1595 answers yes, reply to all recipients as usual. If the user answers
1596 no, only reply back to the author."
1598 :group 'message-headers
1599 :link '(custom-manual "(message)Wide Reply")
1602 (defcustom message-user-fqdn nil
1603 "*Domain part of Messsage-Ids."
1604 :group 'message-headers
1605 :link '(custom-manual "(message)News Headers")
1606 :type '(radio (const :format "%v " nil)
1607 (string :format "FQDN: %v\n" :size 0)))
1609 (defcustom message-use-idna (and (condition-case nil (require 'idna)
1611 (mm-coding-system-p 'utf-8)
1612 (executable-find idna-program)
1614 "Whether to encode non-ASCII in domain names into ASCII according to IDNA."
1615 :group 'message-headers
1616 :link '(custom-manual "(message)IDNA")
1617 :type '(choice (const :tag "Ask" ask)
1618 (const :tag "Never" nil)
1619 (const :tag "Always" t)))
1621 ;;; Internal variables.
1623 (defvar message-sending-message "Sending...")
1624 (defvar message-buffer-list nil)
1625 (defvar message-this-is-news nil)
1626 (defvar message-this-is-mail nil)
1627 (defvar message-draft-article nil)
1628 (defvar message-mime-part nil)
1629 (defvar message-posting-charset nil)
1630 (defvar message-inserted-headers nil)
1632 ;; Byte-compiler warning
1634 (defvar gnus-active-hashtb)
1635 (defvar gnus-read-active-file))
1637 ;;; Regexp matching the delimiter of messages in UNIX mail format
1638 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1639 ;;; of rmail.el's rmail-unix-mail-delimiter.
1640 (defvar message-unix-mail-delimiter
1641 (let ((time-zone-regexp
1642 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1643 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1649 ;; Many things can happen to an RFC 822 mailbox before it is put into
1650 ;; a `From' line. The leading phrase can be stripped, e.g.
1651 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1652 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1653 ;; can be removed, e.g.
1654 ;; From: joe@y.z (Joe K
1656 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1659 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1660 ;; The mailbox can be removed or be replaced by white space, e.g.
1661 ;; From: "Joe User"{space}{tab}
1663 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1664 ;; where {space} and {tab} represent the Ascii space and tab characters.
1665 ;; We want to match the results of any of these manglings.
1666 ;; The following regexp rejects names whose first characters are
1667 ;; obviously bogus, but after that anything goes.
1668 "\\([^\0-\b\n-\r\^?].*\\)?"
1670 ;; The time the message was sent.
1671 "\\([^\0-\r \^?]+\\) +" ; day of the week
1672 "\\([^\0-\r \^?]+\\) +" ; month
1673 "\\([0-3]?[0-9]\\) +" ; day of month
1674 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1676 ;; Perhaps a time zone, specified by an abbreviation, or by a
1681 " \\([0-9][0-9]+\\) *"
1683 ;; On some systems the time zone can appear after the year, too.
1687 "\\(remote from .*\\)?"
1690 "Regexp matching the delimiter of messages in UNIX mail format.")
1692 (defvar message-unsent-separator
1693 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1694 "^ *---+ +Returned message +---+ *$\\|"
1695 "^Start of returned message$\\|"
1696 "^ *---+ +Original message +---+ *$\\|"
1697 "^ *--+ +begin message +--+ *$\\|"
1698 "^ *---+ +Original message follows +---+ *$\\|"
1699 "^ *---+ +Undelivered message follows +---+ *$\\|"
1700 "^|? *---+ +Message text follows: +---+ *|?$")
1701 "A regexp that matches the separator before the text of a failed message.")
1703 (defvar message-header-format-alist
1705 (To . message-fill-address)
1706 (Cc . message-fill-address)
1717 (References . message-shorten-references)
1719 "Alist used for formatting headers.")
1721 (defvar message-options nil
1722 "Some saved answers when sending message.")
1724 (defvar message-send-mail-real-function nil
1725 "Internal send mail function.")
1727 (defvar message-bogus-system-names "^localhost\\."
1728 "The regexp of bogus system names.")
1730 (defcustom message-valid-fqdn-regexp
1731 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1733 "\\([a-z][a-z]" ;; two letter country TDLs
1734 "\\|biz\\|com\\|edu\\|gov\\|int\\|mil\\|net\\|org"
1735 "\\|aero\\|coop\\|info\\|name\\|museum"
1736 "\\|arpa\\|pro\\|uucp\\|bitnet\\|bofh" ;; old style?
1738 "Regular expression that matches a valid FQDN."
1739 ;; see also: gnus-button-valid-fqdn-regexp
1740 :group 'message-headers
1744 (autoload 'message-setup-toolbar "messagexmas")
1745 (autoload 'mh-new-draft-name "mh-comp")
1746 (autoload 'mh-send-letter "mh-comp")
1747 (autoload 'gnus-output-to-rmail "gnus-util")
1748 (autoload 'gnus-output-to-mail "gnus-util")
1749 (autoload 'nndraft-request-associate-buffer "nndraft")
1750 (autoload 'nndraft-request-expire-articles "nndraft")
1751 (autoload 'gnus-open-server "gnus-int")
1752 (autoload 'gnus-request-post "gnus-int")
1753 (autoload 'gnus-copy-article-buffer "gnus-msg")
1754 (autoload 'gnus-alive-p "gnus-util")
1755 (autoload 'gnus-server-string "gnus")
1756 (autoload 'gnus-group-name-charset "gnus-group")
1757 (autoload 'gnus-group-name-decode "gnus-group")
1758 (autoload 'gnus-groups-from-server "gnus")
1759 (autoload 'rmail-output "rmailout")
1760 (autoload 'gnus-delay-article "gnus-delay")
1761 (autoload 'gnus-make-local-hook "gnus-util")
1762 (autoload 'gnus-extract-address-components "gnus-util"))
1765 (autoload 'mu-cite-original "mu-cite"))
1770 ;;; Utility functions.
1772 (defun message-eval-parameter (parameter)
1774 (if (symbolp parameter)
1775 (if (functionp parameter)
1781 (defsubst message-get-parameter (key &optional alist)
1783 (setq alist message-parameter-alist))
1784 (cdr (assq key alist)))
1786 (defmacro message-get-parameter-with-eval (key &optional alist)
1787 `(message-eval-parameter (message-get-parameter ,key ,alist)))
1789 (defmacro message-y-or-n-p (question show &rest text)
1790 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1791 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1793 (defmacro message-delete-line (&optional n)
1794 "Delete the current line (and the next N lines)."
1795 `(delete-region (progn (beginning-of-line) (point))
1796 (progn (forward-line ,(or n 1)) (point))))
1798 (defun message-mark-active-p ()
1799 "Non-nil means the mark and region are currently active in this buffer."
1802 (defun message-unquote-tokens (elems)
1803 "Remove double quotes (\") from strings in list ELEMS."
1804 (mapcar (lambda (item)
1805 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1806 (setq item (concat (match-string 1 item)
1807 (match-string 2 item))))
1811 (defun message-tokenize-header (header &optional separator)
1812 "Split HEADER into a list of header elements.
1813 SEPARATOR is a string of characters to be used as separators. \",\"
1814 is used by default."
1817 (let ((regexp (format "[%s]+" (or separator ",")))
1822 (set-buffer-multibyte t)
1824 (goto-char (point-min))
1829 (cond ((and (> (point) beg)
1831 (and (looking-at regexp)
1834 (push (buffer-substring beg (point)) elems)
1835 (setq beg (match-end 0)))
1836 ((eq (char-after) ?\")
1837 (setq quoted (not quoted)))
1838 ((and (eq (char-after) ?\()
1841 ((and (eq (char-after) ?\))
1844 (nreverse elems)))))
1846 (defun message-mail-file-mbox-p (file)
1847 "Say whether FILE looks like a Unix mbox file."
1848 (when (and (file-exists-p file)
1849 (file-readable-p file)
1850 (file-regular-p file))
1852 (nnheader-insert-file-contents file)
1853 (goto-char (point-min))
1854 (looking-at message-unix-mail-delimiter))))
1856 (defun message-fetch-field (header &optional not-all)
1857 "The same as `mail-fetch-field', only remove all newlines.
1858 The buffer is expected to be narrowed to just the header of the message;
1859 see `message-narrow-to-headers-or-head'."
1860 (let* ((inhibit-point-motion-hooks t)
1861 (case-fold-search t)
1862 (value (mail-fetch-field header nil (not not-all))))
1864 (while (string-match "\n[\t ]+" value)
1865 (setq value (replace-match " " t t value)))
1866 (set-text-properties 0 (length value) nil value)
1869 (defun message-field-value (header &optional not-all)
1870 "The same as `message-fetch-field', only narrow to the headers first."
1873 (message-narrow-to-headers-or-head)
1874 (message-fetch-field header not-all))))
1876 (defun message-narrow-to-field ()
1877 "Narrow the buffer to the header on the current line."
1883 (if (re-search-forward "^[^ \n\t]" nil t)
1888 (goto-char (point-min)))
1890 (defun message-add-header (&rest headers)
1891 "Add the HEADERS to the message header, skipping those already present."
1894 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1895 (error "Invalid header `%s'" (car headers)))
1896 (setq hclean (match-string 1 (car headers)))
1898 (message-narrow-to-headers)
1899 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1900 (goto-char (point-max))
1901 (if (string-match "\n$" (car headers))
1902 (insert (car headers))
1903 (insert (car headers) ?\n)))))
1904 (setq headers (cdr headers))))
1906 (defmacro message-with-reply-buffer (&rest forms)
1907 "Evaluate FORMS in the reply buffer, if it exists."
1908 `(let ((buffer (message-eval-parameter message-reply-buffer)))
1910 (buffer-name buffer))
1915 (put 'message-with-reply-buffer 'lisp-indent-function 0)
1916 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
1918 (defun message-fetch-reply-field (header)
1919 "Fetch field HEADER from the message we're replying to."
1920 (message-with-reply-buffer
1922 (mail-narrow-to-head)
1923 (message-fetch-field header))))
1925 (defun message-strip-list-identifiers (subject)
1926 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1927 (require 'gnus-sum) ; for gnus-list-identifiers
1928 (let ((regexp (if (stringp gnus-list-identifiers)
1929 gnus-list-identifiers
1930 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1931 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1932 " *\\)\\)+\\(Re: +\\)?\\)") subject)
1933 (concat (substring subject 0 (match-beginning 1))
1934 (or (match-string 3 subject)
1935 (match-string 5 subject))
1940 (defun message-strip-subject-re (subject)
1941 "Remove \"Re:\" from subject lines in string SUBJECT."
1942 (if (string-match message-subject-re-regexp subject)
1943 (substring subject (match-end 0))
1946 ;;; Start of functions adopted from `message-utils.el'.
1948 (defun message-strip-subject-trailing-was (subject)
1949 "Remove trailing \"(Was: <old subject>)\" from SUBJECT lines.
1950 Leading \"Re: \" is not stripped by this function. Use the function
1951 `message-strip-subject-re' for this."
1952 (let* ((query message-subject-trailing-was-query)
1957 message-subject-trailing-was-ask-regexp
1958 message-subject-trailing-was-regexp)
1961 (setq new (substring subject 0 (match-beginning 0))))
1962 (if (or (not found) (eq query nil))
1965 (if (message-y-or-n-p
1966 "Strip `(was: <old subject>)' in subject? " t
1968 "Strip `(was: <old subject>)' in subject "
1969 "and use the new one instead?\n\n"
1970 "Current subject is: \""
1972 "New subject would be: \""
1974 "See the variable `message-subject-trailing-was-query' "
1975 "to get rid of this query."
1980 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
1983 (defun message-change-subject (new-subject)
1984 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
1985 ;; <URL:http://www.landfield.com/usefor/drafts/draft-ietf-usefor-useage--1.02.unpaged>
1988 (read-from-minibuffer "New subject: ")))
1989 (cond ((and (not (or (null new-subject) ; new subject not empty
1990 (zerop (string-width new-subject))
1991 (string-match "^[ \t]*$" new-subject))))
1995 (message-narrow-to-headers)
1996 (message-fetch-field "Subject"))))
1997 (cond ((not old-subject)
1998 (error "No current subject"))
2001 (regexp-quote new-subject)
2003 old-subject)) ; yes, it really is a new subject
2004 ;; delete eventual Re: prefix
2006 (message-strip-subject-re old-subject))
2007 (message-goto-subject)
2008 (message-delete-line)
2009 (insert (concat "Subject: "
2012 old-subject ")\n")))))))))
2015 (defun message-mark-inserted-region (beg end)
2016 "Mark some region in the current article with enclosing tags.
2017 See `message-mark-insert-begin' and `message-mark-insert-end'."
2020 ;; add to the end of the region first, otherwise end would be invalid
2022 (insert message-mark-insert-end)
2024 (insert message-mark-insert-begin)))
2027 (defun message-mark-insert-file (file)
2028 "Insert FILE at point, marking it with enclosing tags.
2029 See `message-mark-insert-begin' and `message-mark-insert-end'."
2030 (interactive "fFile to insert: ")
2031 ;; reverse insertion to get correct result.
2033 (insert message-mark-insert-end)
2035 (insert-file-contents file)
2037 (insert message-mark-insert-begin)))
2040 (defun message-add-archive-header ()
2041 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
2042 The note can be customized using `message-archive-note'. When called with a
2043 prefix argument, ask for a text to insert. If you don't want the note in the
2044 body, set `message-archive-note' to nil."
2046 (if current-prefix-arg
2047 (setq message-archive-note
2048 (read-from-minibuffer "Reason for No-Archive: "
2049 (cons message-archive-note 0))))
2051 (if (message-goto-signature)
2052 (re-search-backward message-signature-separator))
2053 (when message-archive-note
2054 (insert message-archive-note)
2056 (message-add-header message-archive-header)
2057 (message-sort-headers)))
2060 (defun message-cross-post-followup-to-header (target-group)
2061 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
2062 With prefix-argument just set Follow-Up, don't cross-post."
2064 (list ; Completion based on Gnus
2065 (completing-read "Followup To: "
2066 (if (boundp 'gnus-newsrc-alist)
2068 nil nil '("poster" . 0)
2069 (if (boundp 'gnus-group-history)
2070 'gnus-group-history))))
2071 (message-remove-header "Follow[Uu]p-[Tt]o" t)
2072 (message-goto-newsgroups)
2074 ;; if we already did a crosspost before, kill old target
2075 (if (and message-cross-post-old-target
2077 (regexp-quote (concat "," message-cross-post-old-target))
2080 ;; unless (followup is to poster or user explicitly asked not
2081 ;; to cross-post, or target-group is already in Newsgroups)
2082 ;; add target-group to Newsgroups line.
2084 ;; def: cross-post, req:no
2085 (and message-cross-post-default (not current-prefix-arg))
2086 ;; def: no-cross-post, req:yes
2087 (and (not message-cross-post-default) current-prefix-arg))
2088 (not (string-match "poster" target-group))
2089 (not (string-match (regexp-quote target-group)
2090 (message-fetch-field "Newsgroups"))))
2092 (insert (concat "," target-group))))
2093 (end-of-line) ; ensure Followup: comes after Newsgroups:
2094 ;; unless new followup would be identical to Newsgroups line
2095 ;; make a new Followup-To line
2096 (if (not (string-match (concat "^[ \t]*"
2099 (message-fetch-field "Newsgroups")))
2100 (insert (concat "\nFollowup-To: " target-group)))
2101 (setq message-cross-post-old-target target-group))
2104 (defun message-cross-post-insert-note (target-group cross-post in-old
2106 "Insert a in message body note about a set Followup or Crosspost.
2107 If there have been previous notes, delete them. TARGET-GROUP specifies the
2108 group to Followup-To. When CROSS-POST is t, insert note about
2109 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
2110 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
2111 been made to before the user asked for a Crosspost."
2112 ;; start scanning body for previous uses
2113 (message-goto-signature)
2114 (let ((head (re-search-backward
2115 (concat "^" mail-header-separator)
2116 nil t))) ; just search in body
2117 (message-goto-signature)
2118 (while (re-search-backward
2119 (concat "^" (regexp-quote message-cross-post-note) ".*")
2121 (message-delete-line))
2122 (message-goto-signature)
2123 (while (re-search-backward
2124 (concat "^" (regexp-quote message-followup-to-note) ".*")
2126 (message-delete-line))
2128 (if (message-goto-signature)
2129 (re-search-backward message-signature-separator))
2132 (string-match "^[ \t]*poster[ \t]*$" target-group))
2133 (insert (concat message-followup-to-note target-group "\n"))
2134 (insert (concat message-cross-post-note target-group "\n")))))
2137 (defun message-cross-post-followup-to (target-group)
2138 "Crossposts message and set Followup-To to TARGET-GROUP.
2139 With prefix-argument just set Follow-Up, don't cross-post."
2141 (list ; Completion based on Gnus
2142 (completing-read "Followup To: "
2143 (if (boundp 'gnus-newsrc-alist)
2145 nil nil '("poster" . 0)
2146 (if (boundp 'gnus-group-history)
2147 'gnus-group-history))))
2148 (cond ((not (or (null target-group) ; new subject not empty
2149 (zerop (string-width target-group))
2150 (string-match "^[ \t]*$" target-group)))
2152 (let* ((old-groups (message-fetch-field "Newsgroups"))
2153 (in-old (string-match
2154 (regexp-quote target-group)
2155 (or old-groups ""))))
2156 ;; check whether target exactly matches old Newsgroups
2157 (cond ((not old-groups)
2158 (error "No current newsgroup"))
2162 (regexp-quote target-group)
2165 ;; yes, Newsgroups line must change
2166 (message-cross-post-followup-to-header target-group)
2167 ;; insert note whether we do cross-post or followup-to
2168 (funcall message-cross-post-note-function
2170 (if (or (and message-cross-post-default
2171 (not current-prefix-arg))
2172 (and (not message-cross-post-default)
2173 current-prefix-arg)) t)
2174 in-old old-groups))))))))
2176 ;;; Reduce To: to Cc: or Bcc: header
2179 (defun message-reduce-to-to-cc ()
2180 "Replace contents of To: header with contents of Cc: or Bcc: header."
2183 (save-restriction (message-narrow-to-headers)
2184 (message-fetch-field "cc")))
2186 (if (and (not cc-content)
2189 (message-narrow-to-headers)
2190 (message-fetch-field "bcc"))))
2195 (message-delete-line)
2196 (insert (concat "To: " cc-content "\n"))
2198 (message-narrow-to-headers)
2199 (message-remove-header (if bcc
2203 ;;; End of functions adopted from `message-utils.el'.
2205 (defun message-remove-header (header &optional is-regexp first reverse)
2206 "Remove HEADER in the narrowed buffer.
2207 If IS-REGEXP, HEADER is a regular expression.
2208 If FIRST, only remove the first instance of the header.
2209 Return the number of headers removed."
2210 (goto-char (point-min))
2211 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
2213 (case-fold-search t)
2215 (while (and (not (eobp))
2218 (not (looking-at regexp))
2219 (looking-at regexp))
2226 ;; There might be a continuation header, so we have to search
2227 ;; until we find a new non-continuation line.
2230 (if (re-search-forward "^[^ \t]" nil t)
2231 (goto-char (match-beginning 0))
2234 (if (re-search-forward "^[^ \t]" nil t)
2235 (goto-char (match-beginning 0))
2236 (goto-char (point-max)))))
2239 (defun message-remove-first-header (header)
2240 "Remove the first instance of HEADER if there is more than one."
2242 (regexp (concat "^" (regexp-quote header) ":")))
2244 (goto-char (point-min))
2245 (while (re-search-forward regexp nil t)
2248 (message-remove-header header nil t)
2251 (defun message-narrow-to-headers ()
2252 "Narrow the buffer to the head of the message."
2255 (goto-char (point-min))
2256 (if (re-search-forward
2257 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2260 (goto-char (point-min)))
2262 (defun message-narrow-to-head-1 ()
2263 "Like `message-narrow-to-head'. Don't widen."
2265 (goto-char (point-min))
2266 (if (search-forward "\n\n" nil 1)
2269 (goto-char (point-min)))
2271 (defun message-narrow-to-head ()
2272 "Narrow the buffer to the head of the message.
2273 Point is left at the beginning of the narrowed-to region."
2275 (message-narrow-to-head-1))
2277 (defun message-narrow-to-headers-or-head ()
2278 "Narrow the buffer to the head of the message."
2281 (goto-char (point-min))
2284 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2285 (match-beginning 0))
2286 ((search-forward "\n\n" nil t)
2290 (goto-char (point-min)))
2292 (defun message-news-p ()
2293 "Say whether the current buffer contains a news message."
2294 (and (not message-this-is-mail)
2295 (or message-this-is-news
2298 (message-narrow-to-headers)
2299 (and (message-fetch-field "newsgroups")
2300 (not (message-fetch-field "posted-to"))))))))
2302 (defun message-mail-p ()
2303 "Say whether the current buffer contains a mail message."
2304 (and (not message-this-is-news)
2305 (or message-this-is-mail
2308 (message-narrow-to-headers)
2309 (or (message-fetch-field "to")
2310 (message-fetch-field "cc")
2311 (message-fetch-field "bcc")))))))
2313 (defun message-subscribed-p ()
2314 "Say whether we need to insert a MFT header."
2315 (or message-subscribed-regexps
2316 message-subscribed-addresses
2317 message-subscribed-address-file
2318 message-subscribed-address-functions))
2320 (defun message-next-header ()
2321 "Go to the beginning of the next header."
2323 (or (eobp) (forward-char 1))
2324 (not (if (re-search-forward "^[^ \t]" nil t)
2326 (goto-char (point-max)))))
2328 (defun message-sort-headers-1 ()
2329 "Sort the buffer as headers using `message-rank' text props."
2330 (goto-char (point-min))
2333 nil 'message-next-header
2335 (message-next-header)
2339 (or (get-text-property (point) 'message-rank)
2342 (defun message-sort-headers ()
2343 "Sort the headers of the current message according to `message-header-format-alist'."
2347 (let ((max (1+ (length message-header-format-alist)))
2349 (message-narrow-to-headers)
2350 (while (re-search-forward "^[^ \n]+:" nil t)
2352 (match-beginning 0) (1+ (match-beginning 0))
2354 (if (setq rank (length (memq (assq (intern (buffer-substring
2356 (1- (match-end 0))))
2357 message-header-format-alist)
2358 message-header-format-alist)))
2361 (message-sort-headers-1))))
2371 (defvar message-mode-map nil)
2373 (unless message-mode-map
2374 (setq message-mode-map (make-keymap))
2375 (set-keymap-parent message-mode-map text-mode-map)
2376 (define-key message-mode-map "\C-c?" 'describe-mode)
2378 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
2379 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
2380 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
2381 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
2382 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
2383 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2384 ;; (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2385 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-mail-reply-to)
2386 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2387 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2388 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2389 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2390 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2391 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2392 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2393 (define-key message-mode-map "\C-c\C-f\C-i"
2394 'message-insert-or-toggle-importance)
2395 (define-key message-mode-map "\C-c\C-f\C-a"
2396 'message-generate-unsubscribed-mail-followup-to)
2398 ;; modify headers (and insert notes in body)
2399 (define-key message-mode-map "\C-c\C-fs" 'message-change-subject)
2401 (define-key message-mode-map "\C-c\C-fx" 'message-cross-post-followup-to)
2402 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2403 (define-key message-mode-map "\C-c\C-ft" 'message-reduce-to-to-cc)
2404 (define-key message-mode-map "\C-c\C-fa" 'message-add-archive-header)
2405 ;; mark inserted text
2406 (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2407 (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2409 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2410 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2411 (define-key message-mode-map "\C-c\C-fc" 'message-goto-mail-copies-to)
2413 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2414 (define-key message-mode-map "\C-c\C-fw" 'message-insert-wide-reply)
2415 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2416 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2418 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2419 (define-key message-mode-map "\C-c\M-n"
2420 'message-insert-disposition-notification-to)
2422 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2423 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2424 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2425 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2426 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2427 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2428 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2429 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2431 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2432 (define-key message-mode-map "\C-c\C-s" 'message-send)
2433 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2434 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2435 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2437 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2438 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2439 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2440 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2441 ;;(define-key message-mode-map "\M-q" 'message-fill-paragraph)
2442 (define-key message-mode-map [remap split-line] 'message-split-line)
2444 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2445 (define-key message-mode-map "\t" 'message-tab)
2446 (define-key message-mode-map "\M-;" 'comment-region)
2448 (define-key message-mode-map "\C-xk" 'message-mimic-kill-buffer))
2451 message-mode-menu message-mode-map "Message Menu."
2453 ["Yank Original" message-yank-original t]
2454 ["Fill Yanked Message" message-fill-yanked-message t]
2455 ["Insert Signature" message-insert-signature t]
2456 ["Caesar (rot13) Message" message-caesar-buffer-body t]
2457 ["Caesar (rot13) Region" message-caesar-region (message-mark-active-p)]
2458 ["Elide Region" message-elide-region
2459 :active (message-mark-active-p)
2460 ,@(if (featurep 'xemacs) nil
2461 '(:help "Replace text in region with an ellipsis"))]
2462 ["Delete Outside Region" message-delete-not-region
2463 :active (message-mark-active-p)
2464 ,@(if (featurep 'xemacs) nil
2465 '(:help "Delete all quoted text outside region"))]
2466 ["Kill To Signature" message-kill-to-signature t]
2467 ["Newline and Reformat" message-newline-and-reformat t]
2468 ["Rename buffer" message-rename-buffer t]
2469 ["Spellcheck" ispell-message
2470 ,@(if (featurep 'xemacs) '(t)
2471 '(:help "Spellcheck this message"))]
2472 ["Attach file as MIME" mime-edit-insert-file
2473 ,@(if (featurep 'xemacs) '(t)
2474 '(:help "Attach a file at point"))]
2476 ["Insert Region Marked" message-mark-inserted-region
2477 :active (message-mark-active-p)
2478 ,@(if (featurep 'xemacs) nil
2479 '(:help "Mark region with enclosing tags"))]
2480 ["Insert File Marked..." message-mark-insert-file
2481 ,@(if (featurep 'xemacs) '(t)
2482 '(:help "Insert file at point marked with enclosing tags"))]
2484 ["Send Message" message-send-and-exit
2485 ,@(if (featurep 'xemacs) '(t)
2486 '(:help "Send this message"))]
2487 ["Postpone Message" message-dont-send
2488 ,@(if (featurep 'xemacs) '(t)
2489 '(:help "File this draft message and exit"))]
2490 ["Send at Specific Time..." gnus-delay-article
2491 ,@(if (featurep 'xemacs) '(t)
2492 '(:help "Ask, then arrange to send message at that time"))]
2493 ["Kill Message" message-kill-buffer
2494 ,@(if (featurep 'xemacs) '(t)
2495 '(:help "Delete this message without sending"))]))
2498 message-mode-field-menu message-mode-map ""
2500 ["To" message-goto-to t]
2501 ["From" message-goto-from t]
2502 ["Subject" message-goto-subject t]
2503 ["Change subject..." message-change-subject t]
2504 ["Cc" message-goto-cc t]
2505 ["Bcc" message-goto-bcc t]
2506 ["Fcc" message-goto-fcc t]
2507 ["Reply-To" message-goto-reply-to t]
2508 ["Flag As Important" message-insert-importance-high
2509 ,@(if (featurep 'xemacs) '(t)
2510 '(:help "Mark this message as important"))]
2511 ["Flag As Unimportant" message-insert-importance-low
2512 ,@(if (featurep 'xemacs) '(t)
2513 '(:help "Mark this message as unimportant"))]
2515 message-insert-disposition-notification-to
2516 ,@(if (featurep 'xemacs) '(t)
2517 '(:help "Request a receipt notification"))]
2519 ;; (typical) news stuff
2520 ["Summary" message-goto-summary t]
2521 ["Keywords" message-goto-keywords t]
2522 ["Newsgroups" message-goto-newsgroups t]
2523 ["Fetch Newsgroups" message-insert-newsgroups t]
2524 ["Followup-To" message-goto-followup-to t]
2525 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2526 ["Crosspost / Followup-To..." message-cross-post-followup-to t]
2527 ["Distribution" message-goto-distribution t]
2528 ["X-No-Archive:" message-add-archive-header t ]
2530 ;; (typical) mailing-lists stuff
2531 ["Fetch To" message-insert-to
2532 ,@(if (featurep 'xemacs) '(t)
2533 '(:help "Insert a To header that points to the author."))]
2534 ["Fetch To and Cc" message-insert-wide-reply
2535 ,@(if (featurep 'xemacs) '(t)
2537 "Insert To and Cc headers as if you were doing a wide reply."))]
2539 ["Send to list only" message-to-list-only t]
2540 ["Mail-Followup-To" message-goto-mail-followup-to t]
2541 ["Mail-Reply-To" message-goto-mail-reply-to t]
2542 ["Mail-Copies-To" message-goto-mail-copies-to t]
2543 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2544 ,@(if (featurep 'xemacs) '(t)
2545 '(:help "Insert a reasonable `Mail-Followup-To:' header."))]
2546 ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2548 ["Sort Headers" message-sort-headers t]
2549 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t]
2550 ["Goto Body" message-goto-body t]
2551 ["Goto Signature" message-goto-signature t]))
2553 (defvar message-tool-bar-map nil)
2556 (defvar facemenu-add-face-function)
2557 (defvar facemenu-remove-face-function))
2559 ;;; Forbidden properties
2561 ;; We use `after-change-functions' to keep special text properties
2562 ;; that interfer with the normal function of message mode out of the
2565 (defcustom message-strip-special-text-properties t
2566 "Strip special properties from the message buffer.
2568 Emacs has a number of special text properties which can break message
2569 composing in various ways. If this option is set, message will strip
2570 these properties from the message composition buffer. However, some
2571 packages requires these properties to be present in order to work.
2572 If you use one of these packages, turn this option off, and hope the
2573 message composition doesn't break too bad."
2574 :group 'message-various
2575 :link '(custom-manual "(message)Various Message Variables")
2578 (defconst message-forbidden-properties
2579 ;; No reason this should be clutter up customize. We make it a
2580 ;; property list (rather than a list of property symbols), to be
2581 ;; directly useful for `remove-text-properties'.
2582 '(field nil read-only nil invisible nil intangible nil
2583 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2584 insert-behind-hooks nil point-entered nil point-left nil)
2585 ;; Other special properties:
2586 ;; category, face, display: probably doesn't do any harm.
2587 ;; fontified: is used by font-lock.
2588 ;; syntax-table, local-map: I dunno.
2589 ;; We need to add XEmacs names to the list.
2590 "Property list of with properties.forbidden in message buffers.
2591 The values of the properties are ignored, only the property names are used.")
2593 (defun message-tamago-not-in-use-p (pos)
2594 "Return t when tamago version 4 is not in use at the cursor position.
2595 Tamago version 4 is a popular input method for writing Japanese text.
2596 It uses the properties `intangible', `invisible', `modification-hooks'
2597 and `read-only' when translating ascii or kana text to kanji text.
2598 These properties are essential to work, so we should never strip them."
2599 (not (and (boundp 'egg-modefull-mode)
2600 (symbol-value 'egg-modefull-mode)
2601 (or (memq (get-text-property pos 'intangible)
2602 '(its-part-1 its-part-2))
2603 (get-text-property pos 'egg-end)
2604 (get-text-property pos 'egg-lang)
2605 (get-text-property pos 'egg-start)))))
2607 (defun message-strip-forbidden-properties (begin end &optional old-length)
2608 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2609 This function is intended to be called from `after-change-functions'.
2610 See also `message-forbidden-properties'."
2611 (when (and message-strip-special-text-properties
2612 (message-tamago-not-in-use-p begin)
2613 ;; Check whether the invisible MIME part is not inserted.
2614 (not (text-property-any begin end 'mime-edit-invisible t)))
2615 (while (not (= begin end))
2616 (when (not (get-text-property begin 'message-hidden))
2617 (remove-text-properties begin (1+ begin)
2618 message-forbidden-properties))
2622 (define-derived-mode message-mode text-mode "Message"
2623 "Major mode for editing mail and news to be sent.
2624 Like Text Mode but with these additional commands:\\<message-mode-map>
2625 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2626 C-c C-d Postpone sending the message C-c C-k Kill the message
2627 C-c C-f move to a header field (and create it if there isn't):
2628 C-c C-f C-t move to To C-c C-f C-s move to Subject
2629 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2630 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2631 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2632 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2633 C-c C-f C-o move to From (\"Originator\")
2634 C-c C-f C-f move to Followup-To
2635 C-c C-f C-m move to Mail-Followup-To
2636 C-c C-f c move to Mail-Copies-To
2637 C-c C-f C-i cycle through Importance values
2638 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2639 C-c C-f x crossposting with FollowUp-To header and note in body
2640 C-c C-f t replace To: header with contents of Cc: or Bcc:
2641 C-c C-f a Insert X-No-Archive: header and a note in the body
2642 C-c C-t `message-insert-to' (add a To header to a news followup)
2643 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2644 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2645 C-c C-b `message-goto-body' (move to beginning of message text).
2646 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2647 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2648 C-c C-y `message-yank-original' (insert current message, if any).
2649 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2650 C-c C-e `message-elide-region' (elide the text between point and mark).
2651 C-c C-v `message-delete-not-region' (remove the text outside the region).
2652 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2653 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2654 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2655 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2656 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2657 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2658 M-RET `message-newline-and-reformat' (break the line and reformat)."
2659 (setq local-abbrev-table text-mode-abbrev-table)
2660 (set (make-local-variable 'message-reply-buffer) nil)
2661 (set (make-local-variable 'message-inserted-headers) nil)
2662 (set (make-local-variable 'message-send-actions) nil)
2663 (set (make-local-variable 'message-exit-actions) nil)
2664 (set (make-local-variable 'message-kill-actions) nil)
2665 (set (make-local-variable 'message-postpone-actions) nil)
2666 (set (make-local-variable 'message-draft-article) nil)
2667 (setq buffer-offer-save t)
2668 (set (make-local-variable 'facemenu-add-face-function)
2670 (let ((face-fun (cdr (assq face message-face-alist))))
2672 (funcall face-fun (point) end)
2673 (error "Face %s not configured for %s mode" face mode-name)))
2675 (set (make-local-variable 'facemenu-remove-face-function) t)
2676 (set (make-local-variable 'message-reply-headers) nil)
2677 (make-local-variable 'message-user-agent)
2678 (make-local-variable 'message-post-method)
2679 (set (make-local-variable 'message-sent-message-via) nil)
2680 (set (make-local-variable 'message-checksum) nil)
2681 (make-local-variable 'message-parameter-alist)
2682 (setq message-parameter-alist
2683 (copy-sequence message-startup-parameter-alist))
2684 (message-setup-fill-variables)
2686 (make-local-variable 'paragraph-separate)
2687 (format "\\(%s\\)\\|\\(%s\\)"
2689 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
2690 ;; Allow using comment commands to add/remove quoting.
2691 (set (make-local-variable 'comment-start) message-yank-prefix)
2692 (if (featurep 'xemacs)
2693 (message-setup-toolbar)
2694 (set (make-local-variable 'font-lock-defaults)
2695 '(message-font-lock-keywords t))
2696 (if (boundp 'tool-bar-map)
2697 (set (make-local-variable 'tool-bar-map) (message-tool-bar-map))))
2698 (easy-menu-add message-mode-menu message-mode-map)
2699 (easy-menu-add message-mode-field-menu message-mode-map)
2700 (gnus-make-local-hook 'after-change-functions)
2701 ;; Mmmm... Forbidden properties...
2702 (add-hook 'after-change-functions 'message-strip-forbidden-properties
2704 ;; Allow mail alias things.
2705 (when (eq message-mail-alias-type 'abbrev)
2706 (if (fboundp 'mail-abbrevs-setup)
2707 (mail-abbrevs-setup)
2708 (if (fboundp 'mail-aliases-setup) ; warning avoidance
2709 (mail-aliases-setup))))
2710 (unless buffer-file-name
2711 (message-set-auto-save-file-name))
2712 (set (make-local-variable 'indent-tabs-mode) nil)) ;No tabs for indentation.
2714 (defun message-setup-fill-variables ()
2715 "Setup message fill variables."
2716 (set (make-local-variable 'fill-paragraph-function)
2717 'message-fill-paragraph)
2718 (make-local-variable 'paragraph-separate)
2719 (make-local-variable 'paragraph-start)
2720 (make-local-variable 'adaptive-fill-regexp)
2721 (unless (boundp 'adaptive-fill-first-line-regexp)
2722 (setq adaptive-fill-first-line-regexp nil))
2723 (make-local-variable 'adaptive-fill-first-line-regexp)
2724 (let ((quote-prefix-regexp
2725 ;; User should change message-cite-prefix-regexp if
2726 ;; message-yank-prefix is set to an abnormal value.
2727 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
2728 (setq paragraph-start
2730 (regexp-quote mail-header-separator) "$\\|"
2731 "[ \t]*$\\|" ; blank lines
2732 "-- $\\|" ; signature delimiter
2733 "---+$\\|" ; delimiters for forwarded messages
2734 page-delimiter "$\\|" ; spoiler warnings
2735 ".*wrote:$\\|" ; attribution lines
2736 quote-prefix-regexp "$")) ; empty lines in quoted text
2737 (setq paragraph-separate paragraph-start)
2738 (setq adaptive-fill-regexp
2739 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
2740 (setq adaptive-fill-first-line-regexp
2741 (concat quote-prefix-regexp "\\|"
2742 adaptive-fill-first-line-regexp)))
2743 (make-local-variable 'auto-fill-inhibit-regexp)
2744 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2745 (setq auto-fill-inhibit-regexp nil)
2746 (make-local-variable 'normal-auto-fill-function)
2747 (setq normal-auto-fill-function 'message-do-auto-fill)
2748 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2749 ;; In that case, ensure that it uses the right function. The real
2750 ;; solution would be not to use `define-derived-mode', and run
2751 ;; `text-mode-hook' ourself at the end of the mode.
2752 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2753 (when auto-fill-function
2754 (setq auto-fill-function normal-auto-fill-function)))
2759 ;;; Message mode commands
2762 ;;; Movement commands
2764 (defun message-goto-to ()
2765 "Move point to the To header."
2767 (message-position-on-field "To"))
2769 (defun message-goto-from ()
2770 "Move point to the From header."
2772 (message-position-on-field "From"))
2774 (defun message-goto-subject ()
2775 "Move point to the Subject header."
2777 (message-position-on-field "Subject"))
2779 (defun message-goto-cc ()
2780 "Move point to the Cc header."
2782 (message-position-on-field "Cc" "To"))
2784 (defun message-goto-bcc ()
2785 "Move point to the Bcc header."
2787 (message-position-on-field "Bcc" "Cc" "To"))
2789 (defun message-goto-fcc ()
2790 "Move point to the Fcc header."
2792 (message-position-on-field "Fcc" "To" "Newsgroups"))
2794 (defun message-goto-reply-to ()
2795 "Move point to the Reply-To header."
2797 (message-position-on-field "Reply-To" "Subject"))
2799 (defun message-goto-mail-reply-to ()
2800 "Move point to the Mail-Reply-To header."
2802 (message-position-on-field "Mail-Reply-To" "Subject"))
2804 (defun message-goto-mail-copies-to ()
2805 "Move point to the Mail-Copies-To header. If the header is newly created,
2806 a string \"never\" is inserted in default."
2808 (unless (message-position-on-field "Mail-Copies-To" "Subject")
2812 (defun message-goto-newsgroups ()
2813 "Move point to the Newsgroups header."
2815 (message-position-on-field "Newsgroups"))
2817 (defun message-goto-distribution ()
2818 "Move point to the Distribution header."
2820 (message-position-on-field "Distribution"))
2822 (defun message-goto-followup-to ()
2823 "Move point to the Followup-To header."
2825 (message-position-on-field "Followup-To" "Newsgroups"))
2827 (defun message-goto-mail-followup-to ()
2828 "Move point to the Mail-Followup-To header. If the header is newly created
2829 and To field contains only one address, the address is inserted in default."
2831 (unless (message-position-on-field "Mail-Followup-To" "Subject")
2832 (let ((start (point))
2835 (message-narrow-to-headers)
2836 (setq addresses (split-string (mail-strip-quoted-names
2837 (or (std11-fetch-field "to") ""))
2839 (when (eq 1 (length addresses))
2841 (insert (car addresses))
2842 (goto-char start))))))
2844 (defun message-goto-keywords ()
2845 "Move point to the Keywords header."
2847 (message-position-on-field "Keywords" "Subject"))
2849 (defun message-goto-summary ()
2850 "Move point to the Summary header."
2852 (message-position-on-field "Summary" "Subject"))
2854 (defun message-goto-body (&optional interactivep)
2855 "Move point to the beginning of the message body."
2856 (interactive (list t))
2857 (when (and interactivep
2858 (looking-at "[ \t]*\n"))
2860 (goto-char (point-min))
2861 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
2862 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
2864 (defun message-goto-eoh ()
2865 "Move point to the end of the headers."
2870 (defun message-goto-signature ()
2871 "Move point to the beginning of the message signature.
2872 If there is no signature in the article, go to the end and
2875 (goto-char (point-min))
2876 (if (re-search-forward message-signature-separator nil t)
2878 (goto-char (point-max))
2881 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc)
2882 "Insert a reasonable MFT header in a post to an unsubscribed list.
2883 When making original posts to a mailing list you are not subscribed to,
2884 you have to type in a MFT header by hand. The contents, usually, are
2885 the addresses of the list and your own address. This function inserts
2886 such a header automatically. It fetches the contents of the To: header
2887 in the current mail buffer, and appends the current `user-mail-address'.
2889 If the optional argument INCLUDE-CC is non-nil, the addresses in the
2890 Cc: header are also put into the MFT."
2895 (message-narrow-to-headers)
2896 (message-remove-header "Mail-Followup-To")
2897 (setq cc (and include-cc (message-fetch-field "Cc")))
2899 (concat (message-fetch-field "To") "," cc)
2900 (message-fetch-field "To"))))
2901 (message-goto-mail-followup-to)
2902 (insert (concat tos ", " user-mail-address))))
2906 (defun message-insert-to (&optional force)
2907 "Insert a To header that points to the author of the article being replied to.
2908 If the original author requested not to be sent mail, don't insert unless the
2909 prefix FORCE is given."
2911 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
2912 (dont (and mct (or (equal (downcase mct) "never")
2913 (equal (downcase mct) "nobody"))))
2914 (to (or (message-fetch-reply-field "mail-reply-to")
2915 (message-fetch-reply-field "reply-to")
2916 (message-fetch-reply-field "from"))))
2920 "Ignoring the user request not to have copies sent via mail"
2921 "Complying with the user request not to have copies sent via mail")))
2922 (when (and force (not to))
2923 (error "No mail address in the article"))
2924 (when (and to (or force (not dont)))
2925 (message-carefully-insert-headers (list (cons 'To to))))))
2927 (defun message-insert-wide-reply ()
2928 "Insert To and Cc headers as if you were doing a wide reply."
2930 (let ((headers (message-with-reply-buffer
2931 (message-get-reply-headers t))))
2932 (message-carefully-insert-headers headers)))
2934 (defcustom message-header-synonyms
2936 "List of lists of header synonyms.
2937 E.g., if this list contains a member list with elements `Cc' and `To',
2938 then `message-carefully-insert-headers' will not insert a `To' header
2939 when the message is already `Cc'ed to the recipient."
2940 :group 'message-headers
2941 :link '(custom-manual "(message)Message Headers")
2942 :type '(repeat sexp))
2944 (defun message-carefully-insert-headers (headers)
2945 "Insert the HEADERS, an alist, into the message buffer.
2946 Does not insert the headers when they are already present there
2947 or in the synonym headers, defined by `message-header-synonyms'."
2948 ;; FIXME: Should compare only the address and not the full name. Comparison
2949 ;; should be done case-folded (and with `string=' rather than
2951 (dolist (header headers)
2952 (let* ((header-name (symbol-name (car header)))
2953 (new-header (cdr header))
2954 (synonyms (loop for synonym in message-header-synonyms
2955 when (memq (car header) synonym) return synonym))
2957 (loop for synonym in synonyms
2958 for old-header = (mail-fetch-field (symbol-name synonym))
2959 when (and old-header (string-match new-header old-header))
2962 (message "already have `%s' in `%s'" new-header old-header)
2963 (when (and (message-position-on-field header-name)
2964 (setq old-header (mail-fetch-field header-name))
2965 (not (string-match "\\` *\\'" old-header)))
2967 (insert new-header)))))
2969 (defun message-widen-reply ()
2970 "Widen the reply to include maximum recipients."
2973 (and message-reply-buffer
2974 (buffer-name message-reply-buffer)
2976 (set-buffer message-reply-buffer)
2977 (message-get-reply-headers t)))))
2980 (message-narrow-to-headers)
2981 (dolist (elem follow-to)
2982 (message-remove-header (symbol-name (car elem)))
2983 (goto-char (point-min))
2984 (insert (symbol-name (car elem)) ": "
2985 (cdr elem) "\n"))))))
2987 (defun message-insert-newsgroups ()
2988 "Insert the Newsgroups header from the article being replied to."
2990 (when (and (message-position-on-field "Newsgroups")
2991 (mail-fetch-field "newsgroups")
2992 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
2994 (insert (or (message-fetch-reply-field "newsgroups") "")))
2998 ;;; Various commands
3000 (defun message-delete-not-region (beg end)
3001 "Delete everything in the body of the current message outside of the region."
3006 ;; snarf citation prefix, if appropriate
3007 (unless (eq (point) (progn (beginning-of-line) (point)))
3008 (when (looking-at message-cite-prefix-regexp)
3009 (setq citeprefix (match-string 0))))
3011 (delete-region (point) (if (not (message-goto-signature))
3017 (delete-region beg (progn (message-goto-body)
3021 (insert citeprefix))))
3022 (when (message-goto-signature)
3025 (defun message-kill-to-signature ()
3026 "Deletes all text up to the signature."
3028 (let ((point (point)))
3029 (message-goto-signature)
3032 (kill-region point (point))
3036 (defun message-newline-and-reformat (&optional arg not-break)
3037 "Insert four newlines, and then reformat if inside quoted text.
3038 Prefix arg means justify as well."
3039 (interactive (list (if current-prefix-arg 'full)))
3040 (let (quoted point beg end leading-space bolp)
3041 (setq point (point))
3044 (setq bolp (= beg point))
3045 ;; Find first line of the paragraph.
3047 (while (and (not (eobp))
3048 (not (looking-at message-cite-prefix-regexp))
3049 (looking-at paragraph-start))
3052 (when (looking-at message-cite-prefix-regexp)
3053 (setq quoted (match-string 0))
3054 (goto-char (match-end 0))
3055 (looking-at "[ \t]*")
3056 (setq leading-space (match-string 0)))
3060 (< (- point beg) (length quoted)))
3061 ;; break inside the cite prefix.
3067 (while (and (not (eobp))
3068 (not (looking-at paragraph-separate))
3069 (looking-at message-cite-prefix-regexp)
3070 (equal quoted (match-string 0)))
3071 (goto-char (match-end 0))
3072 (looking-at "[ \t]*")
3073 (if (> (length leading-space) (length (match-string 0)))
3074 (setq leading-space (match-string 0)))
3078 (while (and (if (bobp) nil (forward-line -1) t)
3079 (not (looking-at paragraph-start))
3080 (looking-at message-cite-prefix-regexp)
3081 (equal quoted (match-string 0)))
3083 (goto-char (match-end 0))
3084 (looking-at "[ \t]*")
3085 (if (> (length leading-space) (length (match-string 0)))
3086 (setq leading-space (match-string 0)))))
3087 (while (and (not (eobp))
3088 (not (looking-at paragraph-separate))
3089 (not (looking-at message-cite-prefix-regexp)))
3093 (while (and (if (bobp) nil (forward-line -1) t)
3094 (not (looking-at paragraph-start))
3095 (not (looking-at message-cite-prefix-regexp)))
3096 (setq beg (point))))
3099 (narrow-to-region beg end)
3106 (setq point (point))
3107 ;; (newline 2) doesn't mark both newline's as hard, so call
3108 ;; newline twice. -jas
3111 (delete-region (point) (re-search-forward "[ \t]*"))
3112 (when (and quoted (not bolp))
3113 (insert quoted leading-space)))
3116 (let* ((adaptive-fill-regexp
3117 (regexp-quote (concat quoted leading-space)))
3118 (adaptive-fill-first-line-regexp
3119 adaptive-fill-regexp ))
3120 (fill-paragraph arg))
3121 (fill-paragraph arg))
3122 (if point (goto-char point)))))
3124 (defun message-fill-paragraph (&optional arg)
3125 "Like `fill-paragraph'."
3126 (interactive (list (if current-prefix-arg 'full)))
3127 (if (if (boundp 'filladapt-mode) filladapt-mode)
3129 (message-newline-and-reformat arg t)
3132 ;; Is it better to use `mail-header-end'?
3133 (defun message-point-in-header-p ()
3134 "Return t if point is in the header."
3137 (goto-char (point-min))
3138 (not (re-search-forward
3139 (concat "^" (regexp-quote mail-header-separator) "\n")
3142 (defun message-do-auto-fill ()
3143 "Like `do-auto-fill', but don't fill in message header."
3144 (unless (message-point-in-header-p)
3147 (defun message-insert-signature (&optional force)
3148 "Insert a signature. See documentation for variable `message-signature'."
3149 (interactive (list 0))
3152 ((and (null message-signature)
3155 (goto-char (point-max))
3156 (not (re-search-backward message-signature-separator nil t))))
3157 ((and (null message-signature)
3160 ((functionp message-signature)
3161 (funcall message-signature))
3162 ((listp message-signature)
3163 (eval message-signature))
3164 (t message-signature)))
3166 (cond ((stringp signature)
3168 ((and (eq t signature)
3169 message-signature-file
3170 (file-exists-p message-signature-file))
3173 (goto-char (point-max))
3174 ;; Insert the signature.
3177 (when message-signature-insert-empty-line
3179 (insert "\n" message-signature-separator-for-insertion)
3182 (if (eq signature t)
3183 (insert-file-contents message-signature-file)
3185 (goto-char (point-max))
3186 (or (bolp) (insert "\n")))))
3188 (defun message-insert-importance-high ()
3189 "Insert header to mark message as important."
3193 (message-narrow-to-headers)
3194 (message-remove-header "Importance"))
3196 (insert "Importance: high\n")))
3198 (defun message-insert-importance-low ()
3199 "Insert header to mark message as unimportant."
3203 (message-narrow-to-headers)
3204 (message-remove-header "Importance"))
3206 (insert "Importance: low\n")))
3208 (defun message-insert-or-toggle-importance ()
3209 "Insert a \"Importance: high\" header, or cycle through the header values.
3210 The three allowed values according to RFC 1327 are `high', `normal'
3214 (let ((valid '("high" "normal" "low"))
3218 (message-narrow-to-headers)
3219 (when (setq cur (message-fetch-field "Importance"))
3220 (message-remove-header "Importance")
3221 (setq new (cond ((string= cur "high")
3223 ((string= cur "low")
3228 (insert (format "Importance: %s\n" new)))))
3230 (defun message-insert-disposition-notification-to ()
3231 "Request a disposition notification (return receipt) to this message.
3232 Note that this should not be used in newsgroups."
3236 (message-narrow-to-headers)
3237 (message-remove-header "Disposition-Notification-To"))
3239 (insert (format "Disposition-Notification-To: %s\n"
3240 (or (message-field-value "Reply-to")
3241 (message-field-value "From")
3242 (message-make-from))))))
3244 (defun message-elide-region (b e)
3245 "Elide the text in the region.
3246 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3250 (insert message-elide-ellipsis))
3252 (defvar message-caesar-translation-table nil)
3254 (defun message-caesar-region (b e &optional n)
3255 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3258 (min (point) (or (mark t) (point)))
3259 (max (point) (or (mark t) (point)))
3260 (when current-prefix-arg
3261 (prefix-numeric-value current-prefix-arg))))
3263 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
3264 (unless (or (zerop n) ; no action needed for a rot of 0
3265 (= b e)) ; no region to rotate
3266 ;; We build the table, if necessary.
3267 (when (or (not message-caesar-translation-table)
3268 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
3269 (setq message-caesar-translation-table
3270 (message-make-caesar-translation-table n)))
3271 (translate-region b e message-caesar-translation-table)))
3273 (defun message-make-caesar-translation-table (n)
3274 "Create a rot table with offset N."
3276 (table (make-string 256 0)))
3277 (while (< (incf i) 256)
3280 (substring table 0 ?A)
3281 (substring table (+ ?A n) (+ ?A n (- 26 n)))
3282 (substring table ?A (+ ?A n))
3283 (substring table (+ ?A 26) ?a)
3284 (substring table (+ ?a n) (+ ?a n (- 26 n)))
3285 (substring table ?a (+ ?a n))
3286 (substring table (+ ?a 26) 255))))
3288 (defun message-caesar-buffer-body (&optional rotnum)
3289 "Caesar rotate all letters in the current buffer by 13 places.
3290 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3291 With prefix arg, specifies the number of places to rotate each letter forward.
3292 Mail and USENET news headers are not rotated."
3293 (interactive (if current-prefix-arg
3294 (list (prefix-numeric-value current-prefix-arg))
3298 (when (message-goto-body)
3299 (narrow-to-region (point) (point-max)))
3300 (message-caesar-region (point-min) (point-max) rotnum))))
3302 (defun message-pipe-buffer-body (program)
3303 "Pipe the message body in the current buffer through PROGRAM."
3306 (when (message-goto-body)
3307 (narrow-to-region (point) (point-max)))
3308 (shell-command-on-region
3309 (point-min) (point-max) program nil t))))
3311 (defun message-rename-buffer (&optional enter-string)
3312 "Rename the *message* buffer to \"*message* RECIPIENT\".
3313 If the function is run with a prefix, it will ask for a new buffer
3314 name, rather than giving an automatic name."
3315 (interactive "Pbuffer name: ")
3318 (goto-char (point-min))
3319 (narrow-to-region (point)
3320 (search-forward mail-header-separator nil 'end))
3322 (if (message-news-p) (message-fetch-field "Newsgroups")
3323 (message-fetch-field "To"))
3326 (if (string-match "," mail-to)
3327 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
3329 (name-default (concat "*message* " mail-trimmed-to))
3330 (name (if enter-string
3331 (read-string "New buffer name: " name-default)
3333 (rename-buffer name t)))))
3335 (defun message-fill-yanked-message (&optional justifyp)
3336 "Fill the paragraphs of a message yanked into this one.
3337 Numeric argument means justify as well."
3340 (goto-char (point-min))
3341 (search-forward (concat "\n" mail-header-separator "\n") nil t)
3342 (let ((fill-prefix message-yank-prefix))
3343 (fill-individual-paragraphs (point) (point-max) justifyp))))
3345 (defun message-indent-citation ()
3346 "Modify text just inserted from a message to be cited.
3347 The inserted text should be the region.
3348 When this function returns, the region is again around the modified text.
3350 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3351 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3352 (let ((start (point)))
3353 ;; Remove unwanted headers.
3354 (when message-ignored-cited-headers
3359 (if (search-forward "\n\n" nil t)
3362 (message-remove-header message-ignored-cited-headers t)
3363 (when (= (point-min) (point-max))
3364 (setq all-removed t))
3365 (goto-char (point-max)))
3369 ;; Delete blank lines at the start of the buffer.
3370 (while (and (point-min)
3373 (message-delete-line))
3374 ;; Delete blank lines at the end of the buffer.
3375 (goto-char (point-max))
3378 (while (and (zerop (forward-line -1))
3380 (message-delete-line))
3381 ;; Do the indentation.
3382 (if (null message-yank-prefix)
3383 (indent-rigidly start (mark t) message-indentation-spaces)
3386 (while (< (point) (mark t))
3387 (if (or (looking-at ">") (looking-at "^$"))
3388 (insert message-yank-cited-prefix)
3389 (insert message-yank-prefix))
3393 (defun message-list-references (refs-list &rest refs-strs)
3394 "Add `Message-ID's which appear in REFS-STRS but not in REFS-LIST,
3396 (let (refs ref id saved-id)
3397 (when (and refs-list
3398 (integerp message-list-references-add-position))
3399 (let ((pos message-list-references-add-position))
3400 (while (and refs-list
3402 (push (pop refs-list) saved-id)
3403 (setq pos (1- pos)))))
3405 (when (setq refs (pop refs-strs))
3406 (setq refs (std11-parse-msg-ids (std11-lexical-analyze refs)))
3408 (when (eq (car (setq ref (pop refs))) 'msg-id)
3409 (setq id (concat "<" (mapconcat 'cdr (cdr ref) "") ">"))
3410 (or (member id refs-list)
3411 (member id saved-id)
3412 (push id refs-list))))))
3414 (push (pop saved-id) refs-list))
3417 (defun message-yank-original (&optional arg)
3418 "Insert the message being replied to, if any.
3419 Puts point before the text and mark after.
3420 Normally indents each nonblank line ARG spaces (default 3). However,
3421 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3423 This function uses `message-cite-function' to do the actual citing.
3425 Just \\[universal-argument] as argument means don't indent, insert no
3426 prefix, and don't delete any headers.
3428 In addition, if `message-yank-add-new-references' is non-nil and this
3429 command is called interactively, new IDs from the yanked article will
3430 be added to the \"References\" field."
3432 (let ((modified (buffer-modified-p)))
3433 (when (let ((buffer (message-eval-parameter message-reply-buffer)))
3435 message-cite-function
3438 (delete-windows-on buffer t)
3439 ; The mark will be set at the end of the article.
3440 (insert-buffer buffer))))
3441 ;; Add new IDs to the References field.
3442 (when (and message-yank-add-new-references
3444 (let ((start (point))
3450 (setq refs (message-list-references
3452 (or (message-make-references)
3454 (message-narrow-to-headers)
3455 (message-fetch-field "References")
3457 (narrow-to-region start end)
3458 (std11-narrow-to-header)
3459 (unless (equal (setq newrefs
3460 (message-list-references
3461 (copy-sequence refs)
3462 (unless (eq message-yank-add-new-references
3464 (or (message-fetch-field "References")
3465 (message-fetch-field "In-Reply-To")))
3466 (message-fetch-field "Message-ID")))
3468 ;; If the References field has been changed, we make it
3469 ;; visible in the header.
3470 (when message-reply-headers
3471 (mail-header-set-message-id message-reply-headers nil)
3472 (mail-header-set-references message-reply-headers nil))
3474 (message-narrow-to-headers)
3475 (if (let ((case-fold-search t))
3476 (re-search-forward "^References:\\([\t ]+.+\n\\)+"
3479 (goto-char (point-max)))
3481 (list (or (assq 'References message-header-format-alist)
3482 '(References . message-fill-references)))
3483 (list (cons 'References (mapconcat 'identity
3484 (nreverse newrefs) " "))))
3485 (backward-delete-char 1))))))
3487 (if (and message-suspend-font-lock-when-citing
3488 (boundp 'font-lock-mode)
3489 (symbol-value 'font-lock-mode))
3494 (funcall message-cite-function))
3496 (funcall message-cite-function)))
3497 (message-exchange-point-and-mark)
3501 (setq message-checksum (message-checksum))))))
3503 (defun message-yank-buffer (buffer)
3504 "Insert BUFFER into the current buffer and quote it."
3505 (interactive "bYank buffer: ")
3506 (let ((message-reply-buffer (get-buffer buffer)))
3507 (save-window-excursion
3508 (message-yank-original))))
3510 (defun message-buffers ()
3511 "Return a list of active message buffers."
3514 (dolist (buffer (buffer-list t))
3516 (when (and (eq major-mode 'message-mode)
3517 (null message-sent-message-via))
3518 (push (buffer-name buffer) buffers))))
3519 (nreverse buffers)))
3521 (defun message-cite-original-without-signature ()
3522 "Cite function in the standard Message manner."
3523 (let ((start (point))
3526 (when message-indent-citation-function
3527 (if (listp message-indent-citation-function)
3528 message-indent-citation-function
3529 (list message-indent-citation-function))))
3530 (message-reply-headers (or message-reply-headers
3531 (make-mail-header))))
3532 (mail-header-set-from message-reply-headers
3536 (if (search-forward "\n\n" nil t)
3539 (or (message-fetch-field "from")
3544 (when (re-search-backward message-signature-separator start t)
3545 ;; Also peel off any blank lines before the signature.
3547 (while (looking-at "^[ \t]*$")
3550 (delete-region (point) end)
3551 (unless (search-backward "\n\n" start t)
3552 ;; Insert a blank line if it is peeled off.
3556 (funcall (pop functions)))
3557 (when message-citation-line-function
3560 (funcall message-citation-line-function))))
3562 (eval-when-compile (defvar mail-citation-hook)) ;Compiler directive
3563 (defun message-cite-original ()
3564 "Cite function in the standard Message manner."
3565 (if (and (boundp 'mail-citation-hook)
3567 (run-hooks 'mail-citation-hook)
3568 (let ((start (point))
3571 (when message-indent-citation-function
3572 (if (listp message-indent-citation-function)
3573 message-indent-citation-function
3574 (list message-indent-citation-function))))
3575 (message-reply-headers (or message-reply-headers
3576 (make-mail-header))))
3577 (mail-header-set-from message-reply-headers
3581 (if (search-forward "\n\n" nil t)
3584 (or (message-fetch-field "from")
3588 (funcall (pop functions)))
3589 (when message-citation-line-function
3592 (funcall message-citation-line-function)))))
3594 (defun message-insert-citation-line ()
3595 "Insert a simple citation line."
3596 (when message-reply-headers
3597 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
3599 (defun message-position-on-field (header &rest afters)
3600 (let ((case-fold-search t))
3603 (goto-char (point-min))
3606 (concat "^" (regexp-quote mail-header-separator) "$"))
3607 (match-beginning 0)))
3608 (goto-char (point-min))
3609 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
3611 (re-search-forward "^[^ \t]" nil 'move)
3613 (skip-chars-backward "\n")
3616 (not (re-search-forward
3617 (concat "^" (regexp-quote (car afters)) ":")
3621 (re-search-forward "^[^ \t]" nil 'move)
3622 (beginning-of-line))
3623 (insert header ": \n")
3627 (defun message-remove-signature ()
3628 "Remove the signature from the text between point and mark.
3629 The text will also be indented the normal way."
3631 (let ((start (point))
3633 (if (not (re-search-forward message-signature-separator (mark t) t))
3634 ;; No signature here, so we just indent the cited text.
3635 (message-indent-citation)
3636 ;; Find the last non-empty line.
3638 (while (looking-at "[ \t]*$")
3641 (setq mark (set-marker (make-marker) (point)))
3643 (message-indent-citation)
3644 ;; Enable undoing the deletion.
3646 (delete-region mark (mark t))
3647 (set-marker mark nil)))))
3652 ;;; Sending messages
3655 ;; Avoid byte-compile warning.
3656 (defvar message-encoding-buffer nil)
3657 (defvar message-edit-buffer nil)
3658 (defvar message-mime-mode nil)
3660 (defun message-send-and-exit (&optional arg)
3661 "Send message like `message-send', then, if no errors, exit from mail buffer."
3663 (let ((buf (current-buffer))
3664 (actions message-exit-actions)
3665 (frame (selected-frame))
3666 (org-frame message-original-frame))
3667 (when (and (message-send arg)
3669 (if message-kill-buffer-on-exit
3672 (when (eq buf (current-buffer))
3673 (message-bury buf)))
3674 (message-do-actions actions)
3675 (message-delete-frame frame org-frame)
3678 (defun message-dont-send ()
3679 "Don't send the message you have been editing.
3680 Instead, just auto-save the buffer and then bury it."
3682 (set-buffer-modified-p t)
3684 (let ((actions message-postpone-actions)
3685 (frame (selected-frame))
3686 (org-frame message-original-frame))
3687 (message-bury (current-buffer))
3688 (message-do-actions actions)
3689 (message-delete-frame frame org-frame)))
3691 (defun message-kill-buffer ()
3692 "Kill the current buffer."
3694 (when (or (not (buffer-modified-p))
3695 (eq t message-kill-buffer-query-function)
3696 (funcall message-kill-buffer-query-function
3697 "The buffer modified; kill anyway? "))
3698 (let ((actions message-kill-actions)
3699 (draft-article message-draft-article)
3700 (auto-save-file-name buffer-auto-save-file-name)
3701 (file-name buffer-file-name)
3702 (modified (buffer-modified-p))
3703 (frame (selected-frame))
3704 (org-frame message-original-frame))
3705 (setq buffer-file-name nil)
3706 (kill-buffer (current-buffer))
3707 (when (and message-kill-buffer-and-remove-file
3708 (or (and auto-save-file-name
3709 (file-exists-p auto-save-file-name))
3711 (file-exists-p file-name)))
3712 (yes-or-no-p (format "Remove the backup file%s? "
3713 (if modified " too" ""))))
3715 (delete-file auto-save-file-name))
3716 (let ((message-draft-article draft-article))
3717 (message-disassociate-draft)))
3718 (message-do-actions actions)
3719 (message-delete-frame frame org-frame)))
3722 (defun message-mimic-kill-buffer ()
3723 "Kill the current buffer with query. This is an imitation for
3724 `kill-buffer', but it will delete a message frame."
3726 (let ((bufname (read-buffer (format "Kill buffer: (default %s) "
3728 message-kill-buffer-and-remove-file)
3729 (when (or (not bufname)
3730 (string-equal bufname "")
3731 (string-equal bufname (buffer-name)))
3732 (message-kill-buffer))))
3734 (defun message-delete-frame (frame org-frame)
3735 "Delete frame for editing message."
3736 (when (and (static-if (featurep 'xemacs)
3737 (device-on-window-system-p)
3739 (or (and (eq message-delete-frame-on-exit t)
3740 (select-frame frame)
3741 (or (eq frame org-frame)
3743 (y-or-n-p "Delete this frame?")
3745 (and (eq message-delete-frame-on-exit 'ask)
3746 (select-frame frame)
3748 (y-or-n-p "Delete this frame?")
3750 (delete-frame frame)))
3752 (defun message-bury (buffer)
3753 "Bury this mail BUFFER."
3754 (let ((newbuf (other-buffer buffer)))
3755 (bury-buffer buffer)
3756 (if (and (fboundp 'frame-parameters)
3757 (cdr (assq 'dedicated (frame-parameters)))
3758 (not (null (delq (selected-frame) (visible-frame-list)))))
3759 (delete-frame (selected-frame))
3760 (switch-to-buffer newbuf))))
3762 (defun message-send (&optional arg)
3763 "Send the message in the current buffer.
3764 If `message-interactive' is non-nil, wait for success indication or
3765 error messages, and inform user.
3766 Otherwise any failure is reported in a message back to the user from
3768 The usage of ARG is defined by the instance that called Message.
3769 It should typically alter the sending method in some way or other."
3772 (when (or (buffer-modified-p)
3773 (message-check-element 'unchanged)
3774 (y-or-n-p "No changes in the buffer; really send? "))
3775 ;; Make it possible to undo the coming changes.
3777 (let ((inhibit-read-only t))
3778 (put-text-property (point-min) (point-max) 'read-only nil))
3779 (run-hooks 'message-send-hook)
3780 (message-fix-before-sending)
3781 (message message-sending-message)
3782 (let ((message-encoding-buffer
3783 (message-generate-new-buffer-clone-locals " message encoding"))
3784 (message-edit-buffer (current-buffer))
3785 (message-mime-mode mime-edit-mode-flag)
3786 (alist message-send-method-alist)
3788 elem sent dont-barf-on-no-method
3789 (message-options message-options))
3792 (message-options-set-recipient)
3794 (set-buffer message-encoding-buffer)
3796 ;; ;; Avoid copying text props (except hard newlines).
3797 ;; T-gnus change: copy all text props from the editing buffer
3798 ;; into the encoding buffer.
3799 (insert-buffer-substring message-edit-buffer)
3800 (funcall message-encode-function)
3802 (setq elem (pop alist)))
3803 (when (funcall (cadr elem))
3805 (or (not (memq (car elem)
3806 message-sent-message-via))
3807 (message-fetch-field "supersedes")
3808 (if (or (message-gnksa-enable-p 'multiple-copies)
3809 (not (eq (car elem) 'news)))
3812 "Already sent message via %s; resend? "
3814 (error "Denied posting -- multiple copies")))
3815 (setq success (funcall (caddr elem) arg)))
3821 (let ((fcc (message-fetch-field "Fcc"))
3822 (gcc (message-fetch-field "Gcc")))
3825 (eq message-allow-no-recipients 'always)
3826 (and (not (eq message-allow-no-recipients 'never))
3827 (setq dont-barf-on-no-method
3829 (format "No receiver, perform %s anyway? "
3830 (cond ((and fcc gcc) "Fcc and Gcc")
3833 (error "No methods specified to send by"))
3834 (when (or dont-barf-on-no-method
3838 (run-hooks 'message-sent-hook))
3839 (message "Sending...done")
3840 ;; Mark the buffer as unmodified and delete auto-save.
3841 (set-buffer-modified-p nil)
3842 (delete-auto-save-file-if-necessary t)
3843 (message-disassociate-draft)
3844 ;; Delete other mail buffers and stuff.
3845 (message-do-send-housekeeping)
3846 (message-do-actions message-send-actions)
3849 (kill-buffer message-encoding-buffer)))))
3851 (defun message-send-via-mail (arg)
3852 "Send the current message via mail."
3853 (message-send-mail arg))
3855 (defun message-send-via-news (arg)
3856 "Send the current message via news."
3857 (message-send-news arg))
3859 (defmacro message-check (type &rest forms)
3860 "Eval FORMS if TYPE is to be checked."
3861 `(or (message-check-element ,type)
3865 (put 'message-check 'lisp-indent-function 1)
3866 (put 'message-check 'edebug-form-spec '(form body))
3868 ;; Advise the function `invisible-region'.
3869 (let (current-load-list)
3871 `(defadvice invisible-region (around add-mime-edit-invisible (start end)
3873 "Advised by T-gnus Message.
3874 Add the text property `mime-edit-invisible' to an invisible text when
3875 the buffer's major mode is `message-mode'. The added property will be
3876 used to distinguish whether the invisible text is a MIME part or not."
3877 ,(if (featurep 'xemacs)
3878 '(if (eq ?\n (char-after start))
3879 (setq start (1+ start)))
3880 '(if (eq ?\n (char-after (1- end)))
3881 (setq end (1- end))))
3882 (setq ad-return-value
3883 (if (eq 'message-mode major-mode)
3884 (add-text-properties start end
3885 '(invisible t mime-edit-invisible t))
3886 (put-text-property start end 'invisible t))))))
3888 (defun message-text-with-property (prop)
3889 "Return a list of all points where the text has PROP."
3891 (point (point-min)))
3893 (while (< point (point-max))
3894 (when (get-text-property point prop)
3895 (push point points))
3899 (defun message-fix-before-sending ()
3900 "Do various things to make the message nice before sending it."
3901 ;; Make sure there's a newline at the end of the message.
3903 (goto-char (point-max))
3906 ;; Make the hidden headers visible.
3907 (let ((points (message-text-with-property 'message-hidden)))
3909 (goto-char (car points))
3910 (dolist (point points)
3911 (add-text-properties point (1+ point)
3912 '(invisible nil intangible nil)))))
3913 ;; Make invisible text visible except for mime parts which may be
3914 ;; inserted by the MIME-Edit.
3915 ;; It doesn't seem as if this is useful, since the invisible property
3916 ;; is clobbered by an after-change hook anyhow.
3917 (message-check 'invisible-text
3918 ;; FIXME T-gnus: It should also detect invisible overlays.
3921 mime-from mime-to hidden-start)
3922 (while (setq from (text-property-any to (point-max) 'invisible t))
3923 (setq to (or (text-property-not-all from (point-max) 'invisible t)
3926 (while (setq mime-from (text-property-any mime-to to
3927 'mime-edit-invisible t))
3928 (when (> mime-from mime-to)
3929 (setq hidden-start (or hidden-start mime-to))
3930 (add-text-properties mime-to mime-from
3931 '(invisible nil face highlight
3932 font-lock-face highlight)))
3933 (setq mime-to (or (text-property-not-all mime-from to
3934 'mime-edit-invisible t)
3936 (when (< mime-to to)
3937 (setq hidden-start (or hidden-start mime-to))
3938 (add-text-properties mime-to to
3939 '(invisible nil face highlight
3940 font-lock-face highlight))))
3942 (goto-char hidden-start)
3943 (set-window-start (selected-window) (point-at-bol))
3944 (unless (yes-or-no-p
3945 "Invisible text found and made visible; continue sending? ")
3946 (error "Invisible text found and made visible")))))
3947 ;; The following check is needless to T-gnus since T-gnus determines
3948 ;; a MIME charset forcibly (even if it cannot be determined properly,
3949 ;; the value of the `default-mime-charset-for-write' variable is used).
3950 ;; (message-check 'illegible-text
3951 ;; (let (found choice)
3952 ;; (message-goto-body)
3953 ;; (skip-chars-forward mm-7bit-chars)
3954 ;; (while (not (eobp))
3955 ;; (when (let ((char (char-after)))
3956 ;; (or (< (mm-char-int char) 128)
3957 ;; (and (mm-multibyte-p)
3958 ;; (memq (char-charset char)
3959 ;; '(eight-bit-control eight-bit-graphic
3961 ;; (not (get-text-property
3962 ;; (point) 'untranslated-utf-8)))))
3963 ;; (message-overlay-put (message-make-overlay (point) (1+ (point)))
3964 ;; 'face 'highlight)
3967 ;; (skip-chars-forward mm-7bit-chars))
3970 ;; (gnus-multiple-choice
3971 ;; "Non-printable characters found. Continue sending?"
3972 ;; '((?d "Remove non-printable characters and send")
3973 ;; (?r "Replace non-printable characters with dots and send")
3974 ;; (?i "Ignore non-printable characters and send")
3975 ;; (?e "Continue editing"))))
3976 ;; (if (eq choice ?e)
3977 ;; (error "Non-printable characters"))
3978 ;; (message-goto-body)
3979 ;; (skip-chars-forward mm-7bit-chars)
3980 ;; (while (not (eobp))
3981 ;; (when (let ((char (char-after)))
3982 ;; (or (< (mm-char-int char) 128)
3983 ;; (and (mm-multibyte-p)
3984 ;; ;; Fixme: Wrong for Emacs 22 and for things
3985 ;; ;; like undecable utf-8. Should at least
3986 ;; ;; use find-coding-systems-region.
3987 ;; (memq (char-charset char)
3988 ;; '(eight-bit-control eight-bit-graphic
3990 ;; (not (get-text-property
3991 ;; (point) 'untranslated-utf-8)))))
3992 ;; (if (eq choice ?i)
3993 ;; (message-kill-all-overlays)
3995 ;; (when (eq choice ?r)
3998 ;; (skip-chars-forward mm-7bit-chars)))))
4001 (defun message-add-action (action &rest types)
4002 "Add ACTION to be performed when doing an exit of type TYPES."
4004 (add-to-list (intern (format "message-%s-actions" (pop types)))
4007 (defun message-delete-action (action &rest types)
4008 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
4011 (set (setq var (intern (format "message-%s-actions" (pop types))))
4012 (delq action (symbol-value var))))))
4014 (defun message-do-actions (actions)
4015 "Perform all actions in ACTIONS."
4016 ;; Now perform actions on successful sending.
4020 ;; A simple function.
4021 ((functionp (car actions))
4022 (funcall (car actions)))
4023 ;; Something to be evaled.
4025 (eval (car actions)))))
4028 (defsubst message-maybe-split-and-send-mail ()
4029 "Split a message if necessary, and send it via mail.
4030 Returns nil if sending succeeded, returns any string if sending failed.
4031 This sub function is for exclusive use of `message-send-mail'."
4032 (let ((mime-edit-split-ignored-field-regexp
4033 mime-edit-split-ignored-field-regexp)
4034 (case-fold-search t)
4036 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
4037 (setq mime-edit-split-ignored-field-regexp
4038 (concat (substring mime-edit-split-ignored-field-regexp
4039 0 (match-beginning 0))
4040 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
4041 "_so_don't_rape_it!"
4042 (substring mime-edit-split-ignored-field-regexp
4046 (catch 'message-sending-mail-failure
4047 (mime-edit-maybe-split-and-send
4052 (std11-narrow-to-header mail-header-separator)
4053 (goto-char (point-min))
4054 (when (re-search-forward "^Message-ID:" nil t)
4055 (delete-region (match-end 0) (std11-field-end))
4056 (insert " " (message-make-message-id))))
4058 (funcall (or message-send-mail-real-function
4059 message-send-mail-function))
4061 (throw 'message-sending-mail-failure err))))))
4065 (funcall (or message-send-mail-real-function
4066 message-send-mail-function))
4070 (if (eq 'error (car failure))
4072 (prin1-to-string failure)))))
4074 (defun message-send-mail-partially ()
4075 "Send mail as message/partial."
4076 ;; replace the header delimiter with a blank line
4077 (goto-char (point-min))
4079 (concat "^" (regexp-quote mail-header-separator) "\n"))
4080 (replace-match "\n")
4081 (run-hooks 'message-send-mail-hook)
4082 (let ((p (goto-char (point-min)))
4083 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
4084 (curbuf (current-buffer))
4085 (id (message-make-message-id)) (n 1)
4086 plist total header required-mail-headers)
4088 (if (< (point-max) (+ p message-send-mail-partially-limit))
4089 (goto-char (point-max))
4090 (goto-char (+ p message-send-mail-partially-limit))
4092 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
4095 (setq total (length plist))
4096 (push (point-max) plist)
4097 (setq plist (nreverse plist))
4100 (setq p (pop plist))
4103 (copy-to-buffer tembuf p (car plist))
4105 (goto-char (point-min))
4108 (goto-char (point-min))
4109 (narrow-to-region (point) (point))
4112 (setq header (buffer-substring (point-min) (point)))
4113 (goto-char (point-min))
4114 (narrow-to-region (point) (point))
4116 (message-remove-header "Mime-Version")
4117 (message-remove-header "Content-Type")
4118 (message-remove-header "Content-Transfer-Encoding")
4119 (message-remove-header "Message-ID")
4120 (message-remove-header "Lines")
4121 (goto-char (point-max))
4122 (insert "Mime-Version: 1.0\n")
4123 (setq header (buffer-string)))
4124 (goto-char (point-max))
4125 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
4128 (let ((mail-header-separator ""))
4129 (when (memq 'Message-ID message-required-mail-headers)
4130 (insert "Message-ID: " (message-make-message-id) "\n"))
4131 (when (memq 'Lines message-required-mail-headers)
4132 (insert "Lines: " (message-make-lines) "\n"))
4133 (message-goto-subject)
4135 (insert (format " (%d/%d)" n total))
4137 (mm-with-unibyte-current-buffer
4138 (funcall (or message-send-mail-real-function
4139 message-send-mail-function))))
4141 (setq p (pop plist))
4143 (kill-buffer tembuf))))
4145 (defun message-send-mail (&optional arg)
4146 (require 'mail-utils)
4147 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
4148 (case-fold-search nil)
4149 (news (message-news-p))
4150 (message-this-is-mail t)
4151 (headers message-required-mail-headers)
4154 (message-narrow-to-headers)
4155 ;; Generate the Mail-Followup-To header if the header is not there...
4156 (if (and (message-subscribed-p)
4157 (not (mail-fetch-field "mail-followup-to")))
4160 (cons "Mail-Followup-To" (message-make-mail-followup-to))
4161 message-required-mail-headers))
4162 ;; otherwise, delete the MFT header if the field is empty
4163 (when (equal "" (mail-fetch-field "mail-followup-to"))
4164 (message-remove-header "^Mail-Followup-To:")))
4165 ;; Insert some headers.
4166 (let ((message-deletable-headers
4167 (if news nil message-deletable-headers)))
4168 (message-generate-headers headers))
4169 ;; Let the user do all of the above.
4170 (run-hooks 'message-header-hook))
4171 (if (not (message-check-mail-syntax))
4179 ;; ;; Avoid copying text props (except hard newlines).
4180 ;; T-gnus change: copy all text props from the editing buffer
4181 ;; into the encoding buffer.
4182 (insert-buffer-substring message-encoding-buffer)
4183 ;; Remove some headers.
4185 (message-narrow-to-headers)
4186 ;; We Semi-gnus people have no use for it.
4187 ;; ;; We (re)generate the Lines header.
4188 ;; (when (memq 'Lines message-required-mail-headers)
4189 ;; (message-generate-headers '(Lines)))
4190 (message-remove-header message-ignored-mail-headers t))
4191 (goto-char (point-max))
4192 ;; require one newline at the end.
4193 (or (= (preceding-char) ?\n)
4195 (message-cleanup-headers)
4196 ;; FIXME: we're inserting the courtesy copy after encoding.
4197 ;; This is wrong if the courtesy copy string contains
4198 ;; non-ASCII characters. -- jh
4201 (message-narrow-to-headers)
4203 (or (message-fetch-field "cc")
4204 (message-fetch-field "bcc")
4205 (message-fetch-field "to"))
4206 (let ((content-type (mime-read-Content-Type)))
4211 (eq 'text (cdr (assq 'type content-type)))
4212 (eq 'plain (cdr (assq 'subtype content-type)))))
4215 (mime-read-Content-Transfer-Encoding)))))))
4216 (message-insert-courtesy-copy))
4217 (setq failure (message-maybe-split-and-send-mail)))
4218 (kill-buffer tembuf))
4219 (set-buffer message-edit-buffer)
4222 (message "Couldn't send message via mail: %s" failure)
4224 (push 'mail message-sent-message-via)))))
4226 (defun message-send-mail-with-sendmail ()
4227 "Send off the prepared buffer with sendmail."
4228 (let ((errbuf (if message-interactive
4229 (message-generate-new-buffer-clone-locals
4232 resend-to-addresses delimline)
4235 (let ((case-fold-search t))
4237 (message-narrow-to-headers)
4238 (setq resend-to-addresses (message-fetch-field "resent-to")))
4239 ;; Change header-delimiter to be what sendmail expects.
4240 (goto-char (point-min))
4242 (concat "^" (regexp-quote mail-header-separator) "\n"))
4243 (replace-match "\n")
4245 (setq delimline (point-marker))
4246 (run-hooks 'message-send-mail-hook)
4247 ;; Insert an extra newline if we need it to work around
4248 ;; Sun's bug that swallows newlines.
4249 (goto-char (1+ delimline))
4250 (when (eval message-mailer-swallows-blank-line)
4252 (when message-interactive
4256 (let* ((default-directory "/")
4257 (cpr (as-binary-process
4259 'call-process-region
4261 (list (point-min) (point-max)
4262 (if (boundp 'sendmail-program)
4264 "/usr/lib/sendmail")
4265 nil errbuf nil "-oi")
4266 ;; Always specify who from,
4267 ;; since some systems have broken sendmails.
4268 ;; But some systems are more broken with -f, so
4269 ;; we'll let users override this.
4270 (if (null message-sendmail-f-is-evil)
4271 (list "-f" (message-sendmail-envelope-from)))
4272 ;; These mean "report errors by mail"
4273 ;; and "deliver in background".
4274 (if (null message-interactive) '("-oem" "-odb"))
4275 ;; Get the addresses from the message
4276 ;; unless this is a resend.
4277 ;; We must not do that for a resend
4278 ;; because we would find the original addresses.
4279 ;; For a resend, include the specific addresses.
4280 (if resend-to-addresses
4281 (list resend-to-addresses)
4283 (unless (or (null cpr) (and (numberp cpr) (zerop cpr)))
4284 (error "Sending...failed with exit value %d" cpr)))
4285 (when message-interactive
4288 (goto-char (point-min))
4289 (while (re-search-forward "\n\n* *" nil t)
4290 (replace-match "; "))
4291 (if (not (zerop (buffer-size)))
4292 (error "Sending...failed to %s"
4293 (buffer-string))))))
4294 (when (bufferp errbuf)
4295 (kill-buffer errbuf)))))
4297 (defun message-send-mail-with-qmail ()
4298 "Pass the prepared message buffer to qmail-inject.
4299 Refer to the documentation for the variable `message-send-mail-function'
4300 to find out how to use this."
4301 ;; replace the header delimiter with a blank line
4302 (goto-char (point-min))
4304 (concat "^" (regexp-quote mail-header-separator) "\n"))
4305 (replace-match "\n")
4307 (run-hooks 'message-send-mail-hook)
4312 'call-process-region 1 (point-max) message-qmail-inject-program
4314 ;; qmail-inject's default behaviour is to look for addresses on the
4315 ;; command line; if there're none, it scans the headers.
4316 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4318 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4319 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4320 ;; message from stdin.
4322 ;; qmail also has the advantage of not having been raped by
4323 ;; various vendors, so we don't have to allow for that, either --
4324 ;; compare this with message-send-mail-with-sendmail and weep
4325 ;; for sendmail's lost innocence.
4327 ;; all this is way cool coz it lets us keep the arguments entirely
4328 ;; free for -inject-arguments -- a big win for the user and for us
4329 ;; since we don't have to play that double-guessing game and the user
4330 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4331 (if (functionp message-qmail-inject-args)
4332 (funcall message-qmail-inject-args)
4333 message-qmail-inject-args)))
4334 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4335 ;; we have to look at the retval instead
4337 (100 (error "qmail-inject reported permanent failure"))
4338 (111 (error "qmail-inject reported transient failure"))
4339 ;; should never happen
4340 (t (error "qmail-inject reported unknown failure"))))
4342 (defun message-send-mail-with-mh ()
4343 "Send the prepared message buffer with mh."
4344 (let ((mh-previous-window-config nil)
4345 (name (mh-new-draft-name)))
4346 (setq buffer-file-name name)
4347 ;; MH wants to generate these headers itself.
4348 (when message-mh-deletable-headers
4349 (let ((headers message-mh-deletable-headers))
4351 (goto-char (point-min))
4352 (and (re-search-forward
4353 (concat "^" (symbol-name (car headers)) ": *") nil t)
4354 (message-delete-line))
4356 (run-hooks 'message-send-mail-hook)
4357 ;; Pass it on to mh.
4360 (defun message-send-mail-with-smtp ()
4361 "Send off the prepared buffer with SMTP."
4362 (require 'smtp) ; XXX
4363 (let ((case-fold-search t)
4366 (message-narrow-to-headers)
4368 ;; XXX: Should be replaced by better one.
4369 (smtp-deduce-address-list (current-buffer)
4370 (point-min) (point-max)))
4371 ;; Remove BCC lines.
4372 (message-remove-header "bcc"))
4373 ;; replace the header delimiter with a blank line.
4374 (goto-char (point-min))
4376 (concat "^" (regexp-quote mail-header-separator) "\n"))
4377 (replace-match "\n")
4379 (run-hooks 'message-send-mail-hook)
4381 (smtp-send-buffer user-mail-address recipients (current-buffer))
4382 (error "Sending failed; no recipients"))))
4384 (defsubst message-maybe-split-and-send-news (method)
4385 "Split a message if necessary, and send it via news.
4386 Returns nil if sending succeeded, returns t if sending failed.
4387 This sub function is for exclusive use of `message-send-news'."
4388 (let ((mime-edit-split-ignored-field-regexp
4389 mime-edit-split-ignored-field-regexp)
4390 (case-fold-search t))
4391 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
4392 (setq mime-edit-split-ignored-field-regexp
4393 (concat (substring mime-edit-split-ignored-field-regexp
4394 0 (match-beginning 0))
4395 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
4396 "_so_don't_rape_it!"
4397 (substring mime-edit-split-ignored-field-regexp
4400 (catch 'message-sending-news-failure
4401 (mime-edit-maybe-split-and-send
4406 (std11-narrow-to-header mail-header-separator)
4407 (goto-char (point-min))
4408 (when (re-search-forward "^Message-ID:" nil t)
4409 (delete-region (match-end 0) (std11-field-end))
4410 (insert " " (message-make-message-id))))
4411 (unless (funcall message-send-news-function method)
4412 (throw 'message-sending-news-failure t)))))
4414 (not (funcall message-send-news-function method)))))
4416 (defun message-smtpmail-send-it ()
4417 "Send the prepared message buffer with `smtpmail-send-it'.
4418 This only differs from `smtpmail-send-it' that this command evaluates
4419 `message-send-mail-hook' just before sending a message. It is useful
4420 if your ISP requires the POP-before-SMTP authentication. See the
4421 documentation for the function `mail-source-touch-pop'."
4422 (run-hooks 'message-send-mail-hook)
4425 (defun message-canlock-generate ()
4426 "Return a string that is non-trivial to guess.
4427 Do not use this for anything important, it is cryptographically weak."
4428 (let (sha1-maximum-internal-length)
4429 (sha1 (concat (message-unique-id)
4430 (format "%x%x%x" (random) (random t) (random))
4431 (prin1-to-string (recent-keys))
4432 (prin1-to-string (garbage-collect))))))
4434 (defun message-canlock-password ()
4435 "The password used by message for cancel locks.
4436 This is the value of `canlock-password', if that option is non-nil.
4437 Otherwise, generate and save a value for `canlock-password' first."
4438 (unless canlock-password
4439 (customize-save-variable 'canlock-password (message-canlock-generate))
4440 (setq canlock-password-for-verify canlock-password))
4443 (defun message-insert-canlock ()
4444 (when message-insert-canlock
4445 (message-canlock-password)
4446 (canlock-insert-header)))
4448 (defun message-send-news (&optional arg)
4449 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4450 (case-fold-search nil)
4451 (method (if (functionp message-post-method)
4452 (funcall message-post-method arg)
4453 message-post-method))
4454 (newsgroups-field (save-restriction
4455 (message-narrow-to-headers-or-head)
4456 (message-fetch-field "Newsgroups")))
4457 (followup-field (save-restriction
4458 (message-narrow-to-headers-or-head)
4459 (message-fetch-field "Followup-To")))
4460 ;; BUG: We really need to get the charset for each name in the
4461 ;; Newsgroups and Followup-To lines to allow crossposting
4462 ;; between group namess with incompatible character sets.
4463 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4464 (group-field-charset
4465 (gnus-group-name-charset method newsgroups-field))
4466 (followup-field-charset
4467 (gnus-group-name-charset method (or followup-field "")))
4468 (mime-field-encoding-method-alist
4469 (append (when group-field-charset
4470 (list (cons "Newsgroups" group-field-charset)))
4471 (when followup-field-charset
4472 (list (cons "Followup-To" followup-field-charset)))
4473 mime-field-encoding-method-alist))
4474 (message-syntax-checks
4476 (listp message-syntax-checks))
4477 (cons '(existing-newsgroups . disabled)
4478 message-syntax-checks)
4479 message-syntax-checks))
4480 (message-this-is-news t)
4483 (message-narrow-to-headers)
4484 ;; Insert some headers.
4485 (message-generate-headers message-required-news-headers)
4486 (message-insert-canlock)
4487 ;; Let the user do all of the above.
4488 (run-hooks 'message-header-hook))
4489 ;; Note: This check will be disabled by the ".*" default value for
4490 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4491 (when (and group-field-charset
4492 (listp message-syntax-checks))
4493 (setq message-syntax-checks
4494 (cons '(valid-newsgroups . disabled)
4495 message-syntax-checks)))
4496 (message-cleanup-headers)
4497 (if (not (let ((message-post-method method))
4498 (message-check-news-syntax)))
4503 (buffer-disable-undo)
4505 (insert-buffer-substring message-encoding-buffer)
4506 ;; Remove some headers.
4508 (message-narrow-to-headers)
4509 ;; We Semi-gnus people have no use for it.
4510 ;; ;; We (re)generate the Lines header.
4511 ;; (when (memq 'Lines message-required-mail-headers)
4512 ;; (message-generate-headers '(Lines)))
4513 ;; Remove some headers.
4514 (message-remove-header message-ignored-news-headers t))
4515 (goto-char (point-max))
4516 ;; require one newline at the end.
4517 (or (= (preceding-char) ?\n)
4519 (setq result (message-maybe-split-and-send-news method)))
4520 (kill-buffer tembuf))
4521 (set-buffer message-edit-buffer)
4524 (message "Couldn't send message via news: %s"
4525 (nnheader-get-report (car method)))
4527 (push 'news message-sent-message-via)))))
4529 ;; 1997-09-29 by MORIOKA Tomohiko
4530 (defun message-send-news-with-gnus (method)
4531 (let ((case-fold-search t))
4532 ;; Remove the delimiter.
4533 (goto-char (point-min))
4535 (concat "^" (regexp-quote mail-header-separator) "\n"))
4536 (replace-match "\n")
4538 (run-hooks 'message-send-news-hook)
4539 (gnus-open-server method)
4540 (message "Sending news via %s..." (gnus-server-string method))
4541 (gnus-request-post method)
4545 ;;; Header generation & syntax checking.
4548 (defun message-check-element (type)
4549 "Return non-nil if this TYPE is not to be checked."
4550 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
4552 (let ((able (assq type message-syntax-checks)))
4554 (eq (cdr able) 'disabled)))))
4556 (defun message-check-news-syntax ()
4557 "Check the syntax of the message."
4562 ;; We narrow to the headers and check them first.
4565 (message-narrow-to-headers)
4566 (message-check-news-header-syntax)))
4569 (set-buffer message-edit-buffer)
4570 (message-check-news-body-syntax))))))
4572 (defun message-check-news-header-syntax ()
4574 ;; Check Newsgroups header.
4575 (message-check 'newsgroups
4576 (let ((group (message-fetch-field "newsgroups")))
4579 (not (string-match "\\`[ \t]*\\'" group)))
4582 "The newsgroups field is empty or missing. Posting is denied.")))))
4583 ;; Check the Subject header.
4584 (message-check 'subject
4585 (let* ((case-fold-search t)
4586 (subject (message-fetch-field "subject")))
4589 (not (string-match "\\`[ \t]*\\'" subject)))
4592 "The subject field is empty or missing. Posting is denied.")))))
4593 ;; Check for commands in Subject.
4594 (message-check 'subject-cmsg
4595 (if (string-match "^cmsg " (message-fetch-field "subject"))
4597 "The control code \"cmsg\" is in the subject. Really post? ")
4599 ;; Check long header lines.
4600 (message-check 'long-header-lines
4601 (let ((start (point))
4605 (while (and (not found)
4606 (re-search-forward "^\\([^ \t:]+\\): " nil t))
4607 (if (> (- (point) (match-beginning 0)) 998)
4609 length (- (point) (match-beginning 0)))
4610 (setq header (match-string-no-properties 1)))
4611 (setq start (match-beginning 0))
4614 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
4617 ;; Check for multiple identical headers.
4618 (message-check 'multiple-headers
4620 (while (and (not found)
4621 (re-search-forward "^[^ \t:]+: " nil t))
4623 (or (re-search-forward
4628 (match-beginning 0) (- (match-end 0) 2))))
4633 (y-or-n-p (format "Multiple %s headers. Really post? " found))
4635 ;; Check for Version and Sendsys.
4636 (message-check 'sendsys
4637 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
4639 (format "The article contains a %s command. Really post? "
4640 (buffer-substring (match-beginning 0)
4641 (1- (match-end 0)))))
4643 ;; See whether we can shorten Followup-To.
4644 (message-check 'shorten-followup-to
4645 (let ((newsgroups (message-fetch-field "newsgroups"))
4646 (followup-to (message-fetch-field "followup-to"))
4648 (when (and newsgroups
4649 (string-match "," newsgroups)
4654 (setq to (completing-read
4655 "Followups to (default: no Followup-To header) "
4658 (message-tokenize-header
4660 (goto-char (point-min))
4661 (insert "Followup-To: " to "\n"))
4663 ;; Check "Shoot me".
4664 (message-check 'shoot
4665 (if (re-search-forward
4666 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t)
4667 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
4669 ;; Check for Approved.
4670 (message-check 'approved
4671 (if (re-search-forward "^Approved:" nil t)
4672 (y-or-n-p "The article contains an Approved header. Really post? ")
4674 ;; Check the Message-ID header.
4675 (message-check 'message-id
4676 (let* ((case-fold-search t)
4677 (message-id (message-fetch-field "message-id" t)))
4678 (or (not message-id)
4679 ;; Is there an @ in the ID?
4680 (and (string-match "@" message-id)
4681 ;; Is there a dot in the ID?
4682 (string-match "@[^.]*\\." message-id)
4683 ;; Does the ID end with a dot?
4684 (not (string-match "\\.>" message-id)))
4686 (format "The Message-ID looks strange: \"%s\". Really post? "
4688 ;; Check the Newsgroups & Followup-To headers.
4689 (message-check 'existing-newsgroups
4690 (let* ((case-fold-search t)
4691 (newsgroups (message-fetch-field "newsgroups"))
4692 (followup-to (message-fetch-field "followup-to"))
4693 (groups (message-tokenize-header
4695 (concat newsgroups "," followup-to)
4697 (post-method (if (functionp message-post-method)
4698 (funcall message-post-method)
4699 message-post-method))
4700 ;; KLUDGE to handle nnvirtual groups. Doing this right
4701 ;; would probably involve a new nnoo function.
4702 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
4703 (method (if (and (consp post-method)
4704 (eq (car post-method) 'nnvirtual)
4705 gnus-message-group-art)
4706 (let ((group (car (nnvirtual-find-group-art
4707 (car gnus-message-group-art)
4708 (cdr gnus-message-group-art)))))
4709 (gnus-find-method-for-group group))
4713 (gnus-group-name-decode
4714 (gnus-group-real-name n)
4715 (gnus-group-name-charset method n)))
4716 (gnus-groups-from-server method)))
4719 (when (and (not (equal (car groups) "poster"))
4720 (not (member (car groups) known-groups))
4721 (not (member (car groups) errors)))
4722 (push (car groups) errors))
4725 ;; Gnus is not running.
4726 ((or (not (and (boundp 'gnus-active-hashtb)
4727 gnus-active-hashtb))
4728 (not (boundp 'gnus-read-active-file)))
4730 ;; We don't have all the group names.
4731 ((and (or (not gnus-read-active-file)
4732 (eq gnus-read-active-file 'some))
4736 "Really use %s possibly unknown group%s: %s? "
4737 (if (= (length errors) 1) "this" "these")
4738 (if (= (length errors) 1) "" "s")
4739 (mapconcat 'identity errors ", "))))
4740 ;; There were no errors.
4743 ;; There are unknown groups.
4747 "Really post to %s unknown group%s: %s? "
4748 (if (= (length errors) 1) "this" "these")
4749 (if (= (length errors) 1) "" "s")
4750 (mapconcat 'identity errors ", ")))))))
4751 ;; Check continuation headers.
4752 (message-check 'continuation-headers
4753 (goto-char (point-min))
4754 (let ((do-posting t))
4755 (while (re-search-forward "^[^ \t\n][^:\n]*$" nil t)
4756 (if (y-or-n-p "Fix continuation lines? ")
4758 (goto-char (match-beginning 0))
4760 (unless (y-or-n-p "Send anyway? ")
4761 (setq do-posting nil))))
4763 ;; Check the Newsgroups & Followup-To headers for syntax errors.
4764 (message-check 'valid-newsgroups
4765 (let ((case-fold-search t)
4766 (headers '("Newsgroups" "Followup-To"))
4768 (while (and headers (not error))
4769 (when (setq header (mail-fetch-field (car headers)))
4773 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
4778 (not (string-match "\\.\\'\\|\\.\\." g)))
4779 (message-tokenize-header header ","))))
4786 (format "The %s header looks odd: \"%s\". Really post? "
4787 (car headers) header)))))
4788 (message-check 'repeated-newsgroups
4789 (let ((case-fold-search t)
4790 (headers '("Newsgroups" "Followup-To"))
4791 header error groups group)
4794 (when (setq header (mail-fetch-field (pop headers)))
4795 (setq groups (message-tokenize-header header ","))
4796 (while (setq group (pop groups))
4797 (when (member group groups)
4803 (format "Group %s is repeated in headers. Really post? " error)))))
4804 ;; Check the From header.
4805 (message-check 'from
4806 (let* ((case-fold-search t)
4807 (from (message-fetch-field "from"))
4811 (message "There is no From line. Posting is denied.")
4813 ((or (not (string-match
4815 (setq ad (nth 1 (std11-extract-address-components
4816 from))))) ;larsi@ifi
4817 (string-match "\\.\\." ad) ;larsi@ifi..uio
4818 (string-match "@\\." ad) ;larsi@.ifi.uio
4819 (string-match "\\.$" ad) ;larsi@ifi.uio.
4820 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4821 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
4823 "Denied posting -- the From looks strange: \"%s\"." from)
4825 ((let ((addresses (rfc822-addresses from)))
4826 (while (and addresses
4827 (not (eq (string-to-char (car addresses)) ?\()))
4828 (setq addresses (cdr addresses)))
4831 "Denied posting -- bad From address: \"%s\"." from)
4834 ;; Check the Reply-To header.
4835 (message-check 'reply-to
4836 (let* ((case-fold-search t)
4837 (reply-to (message-fetch-field "reply-to"))
4842 ((string-match "," reply-to)
4844 (format "Multiple Reply-To addresses: \"%s\". Really post? "
4846 ((or (not (string-match
4848 (setq ad (nth 1 (std11-extract-address-components
4849 reply-to))))) ;larsi@ifi
4850 (string-match "\\.\\." ad) ;larsi@ifi..uio
4851 (string-match "@\\." ad) ;larsi@.ifi.uio
4852 (string-match "\\.$" ad) ;larsi@ifi.uio.
4853 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4854 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
4857 "The Reply-To looks strange: \"%s\". Really post? "
4861 (defun message-check-news-body-syntax ()
4863 ;; Check for long lines.
4864 (message-check 'long-lines
4865 (goto-char (point-min))
4867 (concat "^" (regexp-quote mail-header-separator) "$"))
4871 mime-edit-tag-regexp)
4874 (< (- (point) p) 80)))
4875 (zerop (forward-line 1))))
4879 "You have lines longer than 79 characters. Really post? ")))
4880 ;; Check whether the article is empty.
4881 (message-check 'empty
4882 (goto-char (point-min))
4884 (concat "^" (regexp-quote mail-header-separator) "$"))
4887 (goto-char (point-max))
4888 (re-search-backward message-signature-separator nil t)
4890 (or (re-search-backward "[^ \n\t]" b t)
4891 (if (message-gnksa-enable-p 'empty-article)
4892 (y-or-n-p "Empty article. Really post? ")
4893 (message "Denied posting -- Empty article.")
4895 ;; Check for control characters.
4896 (message-check 'control-chars
4897 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
4899 "The article contains control characters. Really post? ")
4901 ;; Check 8bit characters.
4902 (message-check '8bit
4903 (message-check-8bit))
4904 ;; Check excessive size.
4905 (message-check 'size
4906 (if (> (buffer-size) 60000)
4908 (format "The article is %d octets long. Really post? "
4911 ;; Check whether any new text has been added.
4912 (message-check 'new-text
4914 (not message-checksum)
4915 (not (eq (message-checksum) message-checksum))
4916 (if (message-gnksa-enable-p 'quoted-text-only)
4918 "It looks like no new text has been added. Really post? ")
4919 (message "Denied posting -- no new text has been added.")
4921 ;; Check the length of the signature.
4922 (message-check 'signature
4923 (goto-char (point-max))
4924 (if (> (count-lines (point) (point-max)) 5)
4927 "Your .sig is %d lines; it should be max 4. Really post? "
4928 (1- (count-lines (point) (point-max)))))
4930 ;; Ensure that text follows last quoted portion.
4931 (message-check 'quoting-style
4932 (goto-char (point-max))
4933 (let ((no-problem t))
4934 (when (search-backward-regexp "^>[^\n]*\n" nil t)
4935 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
4938 (if (message-gnksa-enable-p 'quoted-text-only)
4939 (y-or-n-p "Your text should follow quoted text. Really post? ")
4941 (goto-char (point-min))
4943 (concat "^" (regexp-quote mail-header-separator) "$"))
4944 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
4945 (y-or-n-p "Your text should follow quoted text. Really post? ")
4946 (message "Denied posting -- only quoted text.")
4949 (defun message-check-mail-syntax ()
4950 "Check the syntax of the message."
4955 ;; We narrow to the headers and check them first.
4958 (message-narrow-to-headers)
4959 (message-check-mail-header-syntax)))
4962 (set-buffer message-edit-buffer)
4963 (message-check-mail-body-syntax))))))
4965 (defun message-check-mail-header-syntax ()
4968 (defun message-check-mail-body-syntax ()
4970 ;; Check 8bit characters.
4971 (message-check '8bit
4972 (message-check-8bit)
4975 (defun message-check-8bit ()
4976 "Check the article contains 8bit characters."
4978 (set-buffer message-encoding-buffer)
4979 (message-narrow-to-headers)
4980 (let* ((case-fold-search t)
4981 (field-value (message-fetch-field "content-transfer-encoding")))
4982 (if (and field-value
4983 (member (downcase field-value) message-8bit-encoding-list))
4986 (set-buffer (get-buffer-create " message syntax"))
4988 (goto-char (point-min))
4989 (set-buffer-multibyte nil)
4990 (insert-buffer-substring message-encoding-buffer)
4991 (goto-char (point-min))
4992 (if (re-search-forward "[^\x00-\x7f]" nil t)
4994 "The article contains 8bit characters. Really post? ")
4997 (defun message-checksum ()
4998 "Return a \"checksum\" for the current buffer."
5001 (goto-char (point-min))
5003 (concat "^" (regexp-quote mail-header-separator) "$"))
5005 (when (not (looking-at "[ \t\n]"))
5006 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
5011 (defun message-do-fcc ()
5012 "Process Fcc headers in the current buffer."
5013 (let ((case-fold-search t)
5014 (coding-system-for-write 'raw-text)
5016 (mml-externalize-attachments message-fcc-externalize-attachments))
5019 (message-narrow-to-headers)
5020 (setq file (message-fetch-field "fcc" t)))
5022 (set-buffer (get-buffer-create " *message temp*"))
5024 (insert-buffer-substring message-encoding-buffer)
5026 (message-narrow-to-headers)
5027 (while (setq file (message-fetch-field "fcc"))
5029 (message-remove-header "fcc" nil t)))
5030 (goto-char (point-min))
5031 (when (re-search-forward
5032 (concat "^" (regexp-quote mail-header-separator) "$")
5034 (replace-match "" t t))
5035 ;; Process FCC operations.
5037 (setq file (pop list))
5038 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
5039 ;; Pipe the article to the program in question.
5040 (call-process-region (point-min) (point-max) shell-file-name
5041 nil nil nil shell-command-switch
5042 (match-string 1 file))
5043 ;; Save the article.
5044 (setq file (expand-file-name file))
5045 (unless (file-exists-p (file-name-directory file))
5046 (make-directory (file-name-directory file) t))
5047 (if (and message-fcc-handler-function
5048 (not (eq message-fcc-handler-function 'rmail-output)))
5049 (funcall message-fcc-handler-function file)
5050 (if (and (file-readable-p file) (mail-file-babyl-p file))
5051 (rmail-output file 1 nil t)
5052 (let ((mail-use-rfc822 t))
5053 (rmail-output file 1 t t))))))
5054 (kill-buffer (current-buffer))))))
5056 (defun message-output (filename)
5057 "Append this article to Unix/babyl mail file FILENAME."
5058 (if (and (file-readable-p filename)
5059 (mail-file-babyl-p filename))
5060 (gnus-output-to-rmail filename t)
5061 (gnus-output-to-mail filename t)))
5063 (defun message-cleanup-headers ()
5064 "Do various automatic cleanups of the headers."
5065 ;; Remove empty lines in the header.
5067 (message-narrow-to-headers)
5068 ;; Remove blank lines.
5069 (while (re-search-forward "^[ \t]*\n" nil t)
5070 (replace-match "" t t))
5072 ;; Correct Newsgroups and Followup-To headers: Change sequence of
5073 ;; spaces to comma and eliminate spaces around commas. Eliminate
5074 ;; embedded line breaks.
5075 (goto-char (point-min))
5076 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
5080 (if (re-search-forward "^[^ \t]" nil t)
5084 (goto-char (point-min))
5085 (while (re-search-forward "\n[ \t]+" nil t)
5086 (replace-match " " t t)) ;No line breaks (too confusing)
5087 (goto-char (point-min))
5088 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
5089 (replace-match "," t t))
5090 (goto-char (point-min))
5091 ;; Remove trailing commas.
5092 (when (re-search-forward ",+$" nil t)
5093 (replace-match "" t t))))))
5095 (defun message-make-date (&optional now)
5096 "Make a valid data header.
5097 If NOW, use that time instead."
5098 (let* ((now (or now (current-time)))
5099 (zone (nth 8 (decode-time now)))
5103 (setq zone (- zone)))
5105 ;; The day name of the %a spec is locale-specific. Pfff.
5106 (format "%s, " (capitalize (car (rassoc (nth 6 (decode-time now))
5107 parse-time-weekdays))))
5108 (format-time-string "%d" now)
5109 ;; The month name of the %b spec is locale-specific. Pfff.
5111 (capitalize (car (rassoc (nth 4 (decode-time now))
5112 parse-time-months))))
5113 (format-time-string "%Y %H:%M:%S " now)
5114 ;; We do all of this because XEmacs doesn't have the %z spec.
5115 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
5117 (defun message-make-followup-subject (subject)
5118 "Make a followup Subject."
5120 ((and (eq message-use-subject-re 'guess)
5121 (string-match message-subject-encoded-re-regexp subject))
5123 (message-use-subject-re
5124 (concat "Re: " (message-strip-subject-re subject)))
5127 (defun message-make-message-id ()
5128 "Make a unique Message-ID."
5129 (concat "<" (message-unique-id)
5130 (let ((psubject (save-excursion (message-fetch-field "subject")))
5132 (save-excursion (message-fetch-field "supersedes"))))
5134 (and message-reply-headers
5135 (mail-header-references message-reply-headers)
5136 (mail-header-subject message-reply-headers)
5139 (message-strip-subject-re
5140 (mail-header-subject message-reply-headers))
5141 (message-strip-subject-re psubject))))
5143 (string-match "_-_@" psupersedes)))
5145 "@" (message-make-fqdn) ">"))
5147 (defvar message-unique-id-char nil)
5149 ;; If you ever change this function, make sure the new version
5150 ;; cannot generate IDs that the old version could.
5151 ;; You might for example insert a "." somewhere (not next to another dot
5152 ;; or string boundary), or modify the "fsf" string.
5153 (defun message-unique-id ()
5154 ;; Don't use microseconds from (current-time), they may be unsupported.
5155 ;; Instead we use this randomly inited counter.
5156 (setq message-unique-id-char
5157 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
5158 ;; (current-time) returns 16-bit ints,
5159 ;; and 2^16*25 just fits into 4 digits i base 36.
5161 (let ((tm (current-time)))
5163 (if (memq system-type '(ms-dos emx vax-vms))
5164 (let ((user (downcase (user-login-name))))
5165 (while (string-match "[^a-z0-9_]" user)
5166 (aset user (match-beginning 0) ?_))
5168 (message-number-base36 (user-uid) -1))
5169 (message-number-base36 (+ (car tm)
5170 (lsh (% message-unique-id-char 25) 16)) 4)
5171 (message-number-base36 (+ (nth 1 tm)
5172 (lsh (/ message-unique-id-char 25) 16)) 4)
5173 ;; Append a given name, because while the generated ID is unique
5174 ;; to this newsreader, other newsreaders might otherwise generate
5175 ;; the same ID via another algorithm.
5178 (defun message-number-base36 (num len)
5183 (concat (message-number-base36 (/ num 36) (1- len))
5184 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
5187 (defun message-make-organization ()
5188 "Make an Organization header."
5189 (let* ((organization
5190 (when message-user-organization
5191 (if (functionp message-user-organization)
5192 (funcall message-user-organization)
5193 message-user-organization))))
5195 (set-buffer-multibyte t)
5196 (cond ((stringp organization)
5197 (insert organization))
5198 ((and (eq t organization)
5199 message-user-organization-file
5200 (file-exists-p message-user-organization-file))
5201 (insert-file-contents message-user-organization-file)))
5202 (goto-char (point-min))
5203 (while (re-search-forward "[\t\n]+" nil t)
5204 (replace-match "" t t))
5205 (unless (zerop (buffer-size))
5208 (defun message-make-lines ()
5209 "Count the number of lines and return numeric string."
5214 (int-to-string (count-lines (point) (point-max))))))
5216 (defun message-make-references ()
5217 "Return the References header for this message."
5218 (when message-reply-headers
5219 (let ((message-id (mail-header-message-id message-reply-headers))
5220 (references (mail-header-references message-reply-headers))
5222 (if (or references message-id)
5223 (concat (or references "") (and references " ")
5227 (defun message-make-in-reply-to ()
5228 "Return the In-Reply-To header for this message."
5229 (when message-reply-headers
5230 (let ((from (mail-header-from message-reply-headers))
5231 (date (mail-header-date message-reply-headers))
5232 (msg-id (mail-header-message-id message-reply-headers)))
5234 (let ((name (std11-extract-address-components from)))
5235 (concat msg-id (if msg-id " (")
5239 (if (or (not date) (string= date ""))
5240 "(unknown date)" date)
5241 "\"" (if msg-id ")")))))))
5243 (defun message-make-distribution ()
5244 "Make a Distribution header."
5245 (let ((orig-distribution (message-fetch-reply-field "distribution")))
5246 (cond ((functionp message-distribution-function)
5247 (funcall message-distribution-function))
5248 (t orig-distribution))))
5250 (defun message-make-expires ()
5251 "Return an Expires header based on `message-expires'."
5252 (let ((current (current-time))
5253 (future (* 1.0 message-expires 60 60 24)))
5254 ;; Add the future to current.
5255 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
5256 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
5257 (message-make-date current)))
5259 (defun message-make-path ()
5261 (let ((login-name (user-login-name)))
5262 (cond ((null message-user-path)
5263 (concat (system-name) "!" login-name))
5264 ((stringp message-user-path)
5265 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
5266 (concat message-user-path "!" login-name))
5269 (defun message-make-from ()
5270 "Make a From header."
5271 (let* ((style message-from-style)
5272 (login (message-make-address))
5274 (or (and (boundp 'user-full-name)
5277 (when (string= fullname "&")
5278 (setq fullname (user-login-name)))
5280 (set-buffer-multibyte t)
5283 (equal fullname ""))
5285 ((or (eq style 'angles)
5286 (and (not (eq style 'parens))
5287 ;; Use angles if no quoting is needed, or if parens would
5288 ;; need quoting too.
5289 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
5290 (let ((tmp (concat fullname nil)))
5291 (while (string-match "([^()]*)" tmp)
5292 (aset tmp (match-beginning 0) ?-)
5293 (aset tmp (1- (match-end 0)) ?-))
5294 (string-match "[\\()]" tmp)))))
5296 (goto-char (point-min))
5297 ;; Look for a character that cannot appear unquoted
5298 ;; according to RFC 822.
5299 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
5300 ;; Quote fullname, escaping specials.
5301 (goto-char (point-min))
5303 (while (re-search-forward "[\"\\]" nil 1)
5304 (replace-match "\\\\\\&" t))
5306 (insert " <" login ">"))
5307 (t ; 'parens or default
5309 (let ((fullname-start (point)))
5311 (goto-char fullname-start)
5312 ;; RFC 822 says \ and nonmatching parentheses
5313 ;; must be escaped in comments.
5314 ;; Escape every instance of ()\ ...
5315 (while (re-search-forward "[()\\]" nil 1)
5316 (replace-match "\\\\\\&" t))
5317 ;; ... then undo escaping of matching parentheses,
5318 ;; including matching nested parentheses.
5319 (goto-char fullname-start)
5320 (while (re-search-forward
5321 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
5323 (replace-match "\\1(\\3)" t)
5324 (goto-char fullname-start)))
5328 (defun message-make-sender ()
5329 "Return the \"real\" user address.
5330 This function tries to ignore all user modifications, and
5331 give as trustworthy answer as possible."
5332 (concat (user-login-name) "@" (system-name)))
5334 (defun message-make-address ()
5335 "Make the address of the user."
5336 (or (message-user-mail-address)
5337 (concat (user-login-name) "@" (message-make-domain))))
5339 (defun message-user-mail-address ()
5340 "Return the pertinent part of `user-mail-address'."
5341 (when (and user-mail-address
5342 (string-match "@.*\\." user-mail-address))
5343 (if (string-match " " user-mail-address)
5344 (nth 1 (std11-extract-address-components user-mail-address))
5345 user-mail-address)))
5347 (defun message-sendmail-envelope-from ()
5348 "Return the envelope from."
5349 (cond ((eq message-sendmail-envelope-from 'header)
5350 (nth 1 (std11-extract-address-components
5351 (message-fetch-field "from"))))
5352 ((stringp message-sendmail-envelope-from)
5353 message-sendmail-envelope-from)
5355 (message-make-address))))
5357 (defun message-make-fqdn ()
5358 "Return user's fully qualified domain name."
5359 (let* ((system-name (system-name))
5360 (user-mail (message-user-mail-address))
5363 (string-match "@\\(.*\\)\\'" user-mail))
5364 (match-string 1 user-mail)))
5365 (case-fold-search t))
5367 ((and message-user-fqdn
5368 (stringp message-user-fqdn)
5369 (string-match message-valid-fqdn-regexp message-user-fqdn)
5370 (not (string-match message-bogus-system-names message-user-fqdn)))
5372 ;; `message-user-fqdn' seems to be valid
5373 ((and (string-match message-valid-fqdn-regexp system-name)
5374 (not (string-match message-bogus-system-names system-name)))
5375 ;; `system-name' returned the right result.
5377 ;; Try `mail-host-address'.
5378 ((and (boundp 'mail-host-address)
5379 (stringp mail-host-address)
5380 (string-match message-valid-fqdn-regexp mail-host-address)
5381 (not (string-match message-bogus-system-names mail-host-address)))
5383 ;; We try `user-mail-address' as a backup.
5385 (stringp user-domain)
5386 (string-match message-valid-fqdn-regexp user-domain)
5387 (not (string-match message-bogus-system-names user-domain)))
5389 ;; Default to this bogus thing.
5392 ".i-did-not-set--mail-host-address--so-tickle-me")))))
5394 (defun message-make-host-name ()
5395 "Return the name of the host."
5396 (let ((fqdn (message-make-fqdn)))
5397 (string-match "^[^.]+\\." fqdn)
5398 (substring fqdn 0 (1- (match-end 0)))))
5400 (defun message-make-domain ()
5401 "Return the domain name."
5402 (or mail-host-address
5403 (message-make-fqdn)))
5405 (defun message-to-list-only ()
5406 "Send a message to the list only.
5407 Remove all addresses but the list address from To and Cc headers."
5409 (let ((listaddr (message-make-mail-followup-to t)))
5412 (message-remove-header "to")
5413 (message-remove-header "cc")
5414 (message-position-on-field "To" "X-Draft-From")
5415 (insert listaddr)))))
5417 (defun message-make-mail-followup-to (&optional only-show-subscribed)
5418 "Return the Mail-Followup-To header.
5419 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5420 subscribed address (and not the additional To and Cc header contents)."
5421 (let* ((case-fold-search t)
5422 (to (message-fetch-field "To"))
5423 (cc (message-fetch-field "cc"))
5424 (msg-recipients (concat to (and to cc ", ") cc))
5426 (mapcar 'mail-strip-quoted-names
5427 (message-tokenize-header msg-recipients)))
5429 (if message-subscribed-address-file
5430 (let (begin end item re)
5433 (insert-file-contents message-subscribed-address-file)
5435 (setq begin (point))
5438 (if (bolp) (setq end (1- end)))
5439 (setq item (regexp-quote (buffer-substring begin end)))
5440 (if re (setq re (concat re "\\|" item))
5441 (setq re (concat "\\`\\(" item))))
5442 (and re (list (concat re "\\)\\'"))))))))
5443 (mft-regexps (apply 'append message-subscribed-regexps
5444 (mapcar 'regexp-quote
5445 message-subscribed-addresses)
5448 message-subscribed-address-functions))))
5450 (let ((subscribed-lists nil)
5452 (loop for recipient in recipients
5453 when (loop for regexp in mft-regexps
5454 when (string-match regexp recipient) return t)
5457 (if only-show-subscribed
5459 msg-recipients))))))
5461 ;; Dummy to avoid byte-compile warning.
5462 (defvar mule-version)
5463 (defvar emacs-beta-version)
5464 (defvar xemacs-codename)
5465 (defvar gnus-inviolable-extended-version)
5467 (defun message-make-user-agent ()
5468 "Return user-agent info if the value `message-user-agent' is non-nil. If the
5469 \"User-Agent\" field has already exist, remove it."
5470 (when message-user-agent
5472 (goto-char (point-min))
5473 (let ((case-fold-search t))
5474 (when (re-search-forward "^User-Agent:[\t ]*" nil t)
5475 (delete-region (match-beginning 0) (1+ (std11-field-end)))))))
5478 (defun message-idna-inside-rhs-p ()
5479 "Return t iff point is inside a RHS (heuristically).
5480 Only works properly if header contains mailbox-list or address-list.
5481 I.e., calling it on a Subject: header is useless."
5483 (narrow-to-region (save-excursion (or (re-search-backward "^[^ \t]" nil t)
5485 (save-excursion (or (re-search-forward "^[^ \t]" nil t)
5487 (if (re-search-backward "[\\\n\r\t ]"
5488 (save-excursion (search-backward "@" nil t)) t)
5489 ;; whitespace between @ and point
5491 (let ((dquote 1) (paren 1))
5492 (while (save-excursion (re-search-backward "[^\\]\"" nil t dquote))
5494 (while (save-excursion (re-search-backward "[^\\]\(" nil t paren))
5496 (and (= (% dquote 2) 1) (= (% paren 2) 1))))))
5498 (autoload 'idna-to-ascii "idna")
5500 (defun message-idna-to-ascii-rhs-1 (header)
5501 "Interactively potentially IDNA encode domain names in HEADER."
5502 (let (rhs ace start startpos endpos ovl)
5503 (goto-char (point-min))
5504 (while (re-search-forward (concat "^" header) nil t)
5505 (while (re-search-forward "@\\([^ \t\r\n>,]+\\)"
5507 (re-search-forward "^[^ \t]" nil t))
5510 (setq rhs (match-string-no-properties 1)
5511 startpos (match-beginning 1)
5512 endpos (match-end 1))
5513 (when (save-match-data
5514 (and (message-idna-inside-rhs-p)
5515 (setq ace (idna-to-ascii rhs))
5516 (not (string= rhs ace))
5517 (if (eq message-use-idna 'ask)
5520 (setq ovl (message-make-overlay startpos
5522 (message-overlay-put ovl 'face 'highlight)
5524 (format "Replace with `%s'? " ace)))
5526 (message-delete-overlay ovl))
5528 (replace-match (concat "@" ace)))))))
5530 (defun message-idna-to-ascii-rhs ()
5531 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
5532 See `message-idna-encode'."
5534 (when message-use-idna
5537 (message-narrow-to-head)
5538 (message-idna-to-ascii-rhs-1 "From")
5539 (message-idna-to-ascii-rhs-1 "To")
5540 (message-idna-to-ascii-rhs-1 "Cc")))))
5542 (defun message-generate-headers (headers)
5543 "Prepare article HEADERS.
5544 Headers already prepared in the buffer are not modified."
5545 (setq headers (append headers message-required-headers))
5547 (message-narrow-to-headers)
5548 (let* ((Date (message-make-date))
5549 (Message-ID (message-make-message-id))
5550 (Organization (message-make-organization))
5551 (From (message-make-from))
5552 (Path (message-make-path))
5555 (In-Reply-To (message-make-in-reply-to))
5556 (References (message-make-references))
5558 (Distribution (message-make-distribution))
5559 (Lines (message-make-lines))
5560 (User-Agent (message-make-user-agent))
5561 (Expires (message-make-expires))
5562 (case-fold-search t)
5564 header value elem header-string)
5565 ;; First we remove any old generated headers.
5566 (let ((headers message-deletable-headers))
5567 (unless (buffer-modified-p)
5568 (setq headers (delq 'Message-ID (copy-sequence headers))))
5570 (goto-char (point-min))
5571 (and (re-search-forward
5572 (concat "^" (symbol-name (car headers)) ": *") nil t)
5573 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
5574 (message-delete-line))
5576 ;; Go through all the required headers and see if they are in the
5577 ;; articles already. If they are not, or are empty, they are
5578 ;; inserted automatically - except for Subject, Newsgroups and
5581 (goto-char (point-min))
5582 (setq elem (pop headers))
5584 (if (eq (car elem) 'optional)
5585 (setq header (cdr elem)
5587 (setq header (car elem)))
5589 (setq header-string (if (stringp header)
5591 (symbol-name header)))
5592 (when (or (not (re-search-forward
5594 (regexp-quote (downcase header-string))
5598 ;; The header was found. We insert a space after the
5599 ;; colon, if there is none.
5600 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
5601 ;; Find out whether the header is empty.
5602 (looking-at "[ \t]*\n[^ \t]")))
5603 ;; So we find out what value we should insert.
5607 (eq (car elem) 'optional)
5608 (not (member header-string message-inserted-headers)))
5609 ;; This is an optional header. If the cdr of this
5610 ;; is something that is nil, then we do not insert
5612 (setq header (cdr elem))
5613 (or (and (functionp (cdr elem))
5614 (funcall (cdr elem)))
5615 (and (boundp (cdr elem))
5616 (symbol-value (cdr elem)))))
5618 ;; The element is a cons. Either the cdr is a
5619 ;; string to be inserted verbatim, or it is a
5620 ;; function, and we insert the value returned from
5622 (or (and (stringp (cdr elem))
5624 (and (functionp (cdr elem))
5625 (funcall (cdr elem)))))
5626 ((and (boundp header)
5627 (symbol-value header))
5628 ;; The element is a symbol. We insert the value
5629 ;; of this symbol, if any.
5630 (symbol-value header))
5631 ((not (message-check-element header))
5632 ;; We couldn't generate a value for this header,
5633 ;; so we just ask the user.
5634 (read-from-minibuffer
5635 (format "Empty header for %s; enter value: " header)))))
5636 ;; Finally insert the header.
5638 (not (equal value "")))
5642 ;; This header didn't exist, so we insert it.
5643 (goto-char (point-max))
5645 (cdr (assq header message-header-format-alist))))
5647 (funcall formatter header value)
5648 (insert header-string ": " value))
5649 ;; We check whether the value was ended by a
5650 ;; newline. If now, we insert one.
5654 ;; The value of this header was empty, so we clear
5655 ;; totally and insert the new value.
5656 (delete-region (point) (point-at-eol))
5657 ;; If the header is optional, and the header was
5658 ;; empty, we can't insert it anyway.
5660 (push header-string message-inserted-headers)
5664 ;; Add the deletable property to the headers that require it.
5665 (and (memq header message-deletable-headers)
5666 (progn (beginning-of-line) (looking-at "[^:]+: "))
5667 (add-text-properties
5668 (point) (match-end 0)
5669 '(message-deletable t face italic) (current-buffer)))))))
5670 ;; Insert new Sender if the From is strange.
5671 (let ((from (message-fetch-field "from"))
5672 (sender (message-fetch-field "sender"))
5673 (secure-sender (message-make-sender)))
5675 (not (message-check-element 'sender))
5678 (cadr (std11-extract-address-components from)))
5679 (downcase secure-sender)))
5684 (cadr (std11-extract-address-components sender)))
5685 (downcase secure-sender)))))
5686 (goto-char (point-min))
5687 ;; Rename any old Sender headers to Original-Sender.
5688 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
5690 (insert "Original-")
5691 (beginning-of-line))
5692 (when (or (message-news-p)
5693 (string-match "@.+\\.." secure-sender))
5694 (insert "Sender: " secure-sender "\n"))))
5696 (message-idna-to-ascii-rhs))))
5698 (defun message-insert-courtesy-copy ()
5699 "Insert a courtesy message in mail copies of combined messages."
5703 (message-narrow-to-headers)
5704 (when (setq newsgroups (message-fetch-field "newsgroups"))
5705 (goto-char (point-max))
5706 (insert "Posted-To: " newsgroups "\n")))
5708 (when message-courtesy-message
5710 ((string-match "%s" message-courtesy-message)
5711 (insert (format message-courtesy-message newsgroups)))
5713 (insert message-courtesy-message)))))))
5716 ;;; Setting up a message buffer
5719 (defun message-fill-address (header value)
5721 (narrow-to-region (point) (point))
5722 (insert (capitalize (symbol-name header))
5724 (if (consp value) (car value) value)
5726 (narrow-to-region (point-min) (1- (point-max)))
5728 (goto-char (point-min))
5730 (skip-chars-forward "^,\"" (point-max))
5731 (if (or (eq (char-after) ?,)
5734 (if (and (> (current-column) 78)
5738 (looking-at "[ \t]*")
5739 (replace-match "\n " t t)))
5740 (setq last (1+ (point))))
5741 (setq quoted (not quoted)))
5744 (goto-char (point-max))
5748 (defun message-fill-references (header value)
5749 (insert (capitalize (symbol-name header))
5751 (std11-fill-msg-id-list-string
5752 (if (consp value) (car value) value))
5755 (defun message-split-line ()
5756 "Split current line, moving portion beyond point vertically down.
5757 If the current line has `message-yank-prefix', insert it on the new line."
5760 (split-line message-yank-prefix) ;; Emacs 21.3.50+ supports arg.
5764 (defun message-fill-header (header value)
5765 (let ((begin (point))
5768 (insert (capitalize (symbol-name header))
5770 (if (consp value) (car value) value)
5773 (narrow-to-region begin (point))
5774 (fill-region-as-paragraph begin (point))
5775 ;; Tapdance around looong Message-IDs.
5777 (when (looking-at "[ \t]*$")
5778 (message-delete-line))
5780 (re-search-forward ":" nil t)
5781 (when (looking-at "\n[ \t]+")
5782 (replace-match " " t t))
5783 (goto-char (point-max)))))
5785 (defun message-shorten-1 (list cut surplus)
5786 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
5787 (setcdr (nthcdr (- cut 2) list)
5788 (nthcdr (+ (- cut 2) surplus 1) list)))
5790 (defun message-shorten-references (header references)
5791 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
5792 If folding is disallowed, also check that the REFERENCES are less
5793 than 988 characters long, and if they are not, trim them until they are."
5800 (goto-char (point-min))
5801 ;; Cons a list of valid references.
5802 (while (re-search-forward "<[^>]+>" nil t)
5803 (push (match-string 0) refs))
5804 (setq refs (nreverse refs)
5805 count (length refs)))
5807 ;; If the list has more than MAXCOUNT elements, trim it by
5808 ;; removing the CUTth element and the required number of
5809 ;; elements that follow.
5810 (when (> count maxcount)
5811 (let ((surplus (- count maxcount)))
5812 (message-shorten-1 refs cut surplus)
5813 (decf count surplus)))
5815 ;; If folding is disallowed, make sure the total length (including
5816 ;; the spaces between) will be less than MAXSIZE characters.
5818 ;; Only disallow folding for News messages. At this point the headers
5819 ;; have not been generated, thus we use message-this-is-news directly.
5820 (when (and message-this-is-news message-cater-to-broken-inn)
5822 (totalsize (+ (apply #'+ (mapcar #'length refs))
5825 (ptr (nthcdr (1- cut) refs)))
5826 ;; Decide how many elements to cut off...
5827 (while (> totalsize maxsize)
5828 (decf totalsize (1+ (length (car ptr))))
5830 (setq ptr (cdr ptr)))
5833 (message-shorten-1 refs cut surplus))))
5835 ;; Finally, collect the references back into a string and insert
5836 ;; it into the buffer.
5837 (let ((refstring (mapconcat #'identity refs " ")))
5838 (if (and message-this-is-news message-cater-to-broken-inn)
5839 (insert (capitalize (symbol-name header)) ": "
5841 (message-fill-header header refstring)))))
5843 (defun message-position-point ()
5844 "Move point to where the user probably wants to find it."
5845 (message-narrow-to-headers)
5847 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
5848 (search-backward ":" )
5851 (if (eq (char-after) ? )
5855 (goto-char (point-max))
5858 (unless (looking-at "$")
5862 (defcustom message-beginning-of-line t
5863 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
5864 goes to beginning of header values."
5865 :group 'message-buffers
5866 :link '(custom-manual "(message)Movement")
5869 (defun message-beginning-of-line (&optional n)
5870 "Move point to beginning of header value or to beginning of line.
5871 The prefix argument N is passed directly to `beginning-of-line'.
5873 This command is identical to `beginning-of-line' if point is
5874 outside the message header or if the option `message-beginning-of-line'
5877 If point is in the message header and on a (non-continued) header
5878 line, move point to the beginning of the header value. If point
5879 is already there, move point to beginning of line. Therefore,
5880 repeated calls will toggle point between beginning of field and
5883 (let ((zrs 'zmacs-region-stays))
5884 (when (and (interactive-p) (boundp zrs))
5886 (if (and message-beginning-of-line
5887 (message-point-in-header-p))
5888 (let* ((here (point))
5889 (bol (progn (beginning-of-line n) (point)))
5890 (eol (point-at-eol))
5891 (eoh (re-search-forward ": *" eol t)))
5892 (if (or (not eoh) (equal here eoh))
5895 (beginning-of-line n)))
5897 (defun message-buffer-name (type &optional to group)
5898 "Return a new (unique) buffer name based on TYPE and TO."
5900 ;; Generate a new buffer name The Message Way.
5901 ((eq message-generate-new-buffers 'unique)
5902 (generate-new-buffer-name
5906 (or (car (std11-extract-address-components to))
5909 (if (and group (not (string= group ""))) (concat " on " group) "")
5911 ;; Check whether `message-generate-new-buffers' is a function,
5912 ;; and if so, call it.
5913 ((functionp message-generate-new-buffers)
5914 (funcall message-generate-new-buffers type to group))
5915 ((eq message-generate-new-buffers 'unsent)
5916 (generate-new-buffer-name
5917 (concat "*unsent " type
5920 (or (car (std11-extract-address-components to))
5923 (if (and group (not (string= group ""))) (concat " on " group) "")
5925 ;; Use standard name.
5927 (format "*%s message*" type))))
5929 (defmacro message-pop-to-buffer-1 (buffer)
5931 (let (special-display-buffer-names
5932 special-display-regexps
5933 same-window-buffer-names
5934 same-window-regexps)
5935 (pop-to-buffer ,buffer))
5936 (pop-to-buffer ,buffer)))
5938 (defun message-pop-to-buffer (name)
5939 "Pop to buffer NAME, and warn if it already exists and is modified."
5940 (let ((buffer (get-buffer name))
5941 (pop-up-frames (and (static-if (featurep 'xemacs)
5942 (device-on-window-system-p)
5944 message-use-multi-frames)))
5946 (buffer-name buffer))
5948 (message-pop-to-buffer-1 buffer)
5949 (when (and (buffer-modified-p)
5951 "Message already being composed; erase? ")))
5952 (error "Message being composed")))
5953 (message-pop-to-buffer-1 name))
5957 (set (make-local-variable 'message-original-frame) (selected-frame)))))
5959 (defun message-do-send-housekeeping ()
5960 "Kill old message buffers."
5961 ;; We might have sent this buffer already. Delete it from the
5963 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
5964 (while (and message-max-buffers
5966 (>= (length message-buffer-list) message-max-buffers))
5967 ;; Kill the oldest buffer -- unless it has been changed.
5968 (let ((buffer (pop message-buffer-list)))
5969 (when (and (buffer-name buffer)
5970 (not (buffer-modified-p buffer)))
5971 (kill-buffer buffer))))
5972 ;; Rename the buffer.
5973 (if message-send-rename-function
5974 (funcall message-send-rename-function)
5975 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
5977 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
5979 (let ((name (match-string 2 (buffer-name)))
5981 (if (not (or (null name)
5982 (string-equal name "mail")
5983 (string-equal name "posting")))
5984 (setq name (concat "*sent " name "*"))
5985 (message-narrow-to-headers)
5986 (setq to (message-fetch-field "to"))
5987 (setq group (message-fetch-field "newsgroups"))
5991 (to (concat "*sent mail to "
5992 (or (car (std11-extract-address-components to))
5994 ((and group (not (string= group "")))
5995 (concat "*sent posting on " group "*"))
5996 (t "*sent mail*"))))
5997 (unless (string-equal name (buffer-name))
5998 (rename-buffer name t)))))
5999 ;; Push the current buffer onto the list.
6000 (when message-max-buffers
6001 (setq message-buffer-list
6002 (nconc message-buffer-list (list (current-buffer))))))
6004 (defun message-mail-user-agent ()
6006 ((not message-mail-user-agent) nil)
6007 ((eq message-mail-user-agent t) mail-user-agent)
6008 (t message-mail-user-agent))))
6009 (if (memq mua '(message-user-agent gnus-user-agent))
6013 (defun message-setup (headers &optional replybuffer actions switch-function)
6014 (let ((mua (message-mail-user-agent))
6015 subject to field yank-action)
6016 (if (not (and message-this-is-mail mua))
6017 (message-setup-1 headers replybuffer actions)
6019 (setq yank-action (list 'insert-buffer replybuffer)))
6020 (setq headers (copy-sequence headers))
6021 (setq field (assq 'Subject headers))
6023 (setq subject (cdr field))
6024 (setq headers (delq field headers)))
6025 (setq field (assq 'To headers))
6027 (setq to (cdr field))
6028 (setq headers (delq field headers)))
6029 (let ((mail-user-agent mua))
6030 (compose-mail to subject
6031 (mapcar (lambda (item)
6033 (format "%s" (car item))
6036 nil switch-function yank-action actions)))))
6038 (defun message-headers-to-generate (headers included-headers excluded-headers)
6039 "Return a list that includes all headers from HEADERS.
6040 If INCLUDED-HEADERS is a list, just include those headers. If if is
6041 t, include all headers. In any case, headers from EXCLUDED-HEADERS
6045 (dolist (header headers)
6046 (setq header-name (cond
6047 ((and (consp header)
6048 (eq (car header) 'optional))
6049 ;; On the form (optional . Header)
6052 ;; On the form (Header . function)
6057 (when (and (not (memq header-name excluded-headers))
6058 (or (eq included-headers t)
6059 (memq header-name included-headers)))
6060 (push header result)))
6063 (defun message-setup-1 (headers &optional replybuffer actions)
6064 (dolist (action actions)
6066 (add-to-list 'message-send-actions
6067 `(apply ',(car action) ',(cdr action)))))
6068 (setq message-reply-buffer
6069 (or (message-get-parameter 'reply-buffer)
6071 (goto-char (point-min))
6072 ;; Insert all the headers.
6075 (alist message-header-format-alist))
6077 (unless (assq (caar h) message-header-format-alist)
6078 (push (list (caar h)) alist))
6082 (delete-region (point) (progn (forward-line -1) (point)))
6083 (when message-default-headers
6084 (insert message-default-headers)
6085 (or (bolp) (insert ?\n)))
6089 (insert mail-header-separator "\n")
6093 (when (message-news-p)
6094 (when message-default-news-headers
6095 (insert message-default-news-headers)
6096 (or (bolp) (insert ?\n)))
6097 (when message-generate-headers-first
6098 (message-generate-headers
6099 (message-headers-to-generate
6100 (append message-required-news-headers
6101 message-required-headers)
6102 message-generate-headers-first
6103 '(Lines Subject)))))
6104 (when (message-mail-p)
6105 (when message-default-mail-headers
6106 (insert message-default-mail-headers)
6107 (or (bolp) (insert ?\n)))
6109 (message-narrow-to-headers)
6110 (if (and replybuffer
6111 message-alternative-emails)
6112 (message-use-alternative-email-as-from)))
6113 (when message-generate-headers-first
6114 (message-generate-headers
6115 (message-headers-to-generate
6116 (append message-required-mail-headers
6117 message-required-headers)
6118 message-generate-headers-first
6119 '(Lines Subject)))))
6120 (run-hooks 'message-signature-setup-hook)
6121 (message-insert-signature)
6123 (message-narrow-to-headers)
6124 (run-hooks 'message-header-setup-hook))
6125 (set-buffer-modified-p nil)
6126 (setq buffer-undo-list nil)
6127 (run-hooks 'message-setup-hook)
6128 (message-position-point)
6131 (defun message-set-auto-save-file-name ()
6132 "Associate the message buffer with a file in the drafts directory."
6133 (when message-auto-save-directory
6134 (unless (file-directory-p
6135 (directory-file-name message-auto-save-directory))
6136 (make-directory message-auto-save-directory t))
6138 (setq message-draft-article
6139 (nndraft-request-associate-buffer "drafts"))
6140 (setq buffer-file-name (expand-file-name
6141 (if (memq system-type
6142 '(ms-dos ms-windows windows-nt
6143 cygwin cygwin32 win32 w32
6147 message-auto-save-directory))
6148 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
6149 (clear-visited-file-modtime)
6150 (setq buffer-file-coding-system message-draft-coding-system)))
6152 (defun message-disassociate-draft ()
6153 "Disassociate the message buffer from the drafts directory."
6154 (when message-draft-article
6155 (nndraft-request-expire-articles
6156 (list message-draft-article) "drafts" nil t)))
6158 (defun message-insert-headers ()
6159 "Generate the headers for the article."
6163 (message-narrow-to-headers)
6164 (when (message-news-p)
6165 (message-generate-headers
6168 (copy-sequence message-required-news-headers)))))
6169 (when (message-mail-p)
6170 (message-generate-headers
6173 (copy-sequence message-required-mail-headers))))))))
6178 ;;; Commands for interfacing with message
6182 (defun message-mail (&optional to subject
6183 other-headers continue switch-function
6184 yank-action send-actions)
6185 "Start editing a mail message to be sent.
6186 OTHER-HEADERS is an alist of header/value pairs."
6188 (let ((message-this-is-mail t) replybuffer)
6189 (unless (message-mail-user-agent)
6190 (message-pop-to-buffer (message-buffer-name "mail" to)))
6191 ;; FIXME: message-mail should do something if YANK-ACTION is not
6193 (and (consp yank-action) (eq (car yank-action) 'insert-buffer)
6194 (setq replybuffer (nth 1 yank-action)))
6197 `((To . ,(or to "")) (Subject . ,(or subject "")))
6198 (when other-headers other-headers))
6199 replybuffer send-actions)
6200 ;; FIXME: Should return nil if failure.
6204 (defun message-news (&optional newsgroups subject)
6205 "Start editing a news article to be sent."
6207 (let ((message-this-is-news t))
6208 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
6209 (message-setup `((Newsgroups . ,(or newsgroups ""))
6210 (Subject . ,(or subject ""))))))
6212 (defun message-get-reply-headers (wide &optional to-address address-headers)
6213 (let (follow-to mct never-mct to cc author mft recipients)
6214 ;; Find all relevant headers we need.
6216 (message-narrow-to-headers-or-head)
6217 (let ((mrt (when message-use-mail-reply-to
6218 (message-fetch-field "mail-reply-to")))
6219 (reply-to (message-fetch-field "reply-to")))
6220 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
6221 ;; message-header-synonyms.
6222 (setq to (or (message-fetch-field "to")
6223 (and (loop for synonym in message-header-synonyms
6224 when (memq 'Original-To synonym)
6226 (message-fetch-field "original-to")))
6227 cc (message-fetch-field "cc")
6228 mct (when message-use-mail-copies-to
6229 (message-fetch-field "mail-copies-to"))
6232 (message-fetch-field "from")
6234 mft (when (and (not (or to-address mrt reply-to))
6235 message-use-mail-followup-to)
6236 (message-fetch-field "mail-followup-to")))))
6239 ;; Handle special values of Mail-Copies-To.
6241 (cond ((or (equal (downcase mct) "never")
6242 (equal (downcase mct) "nobody"))
6243 (when (or (not (eq message-use-mail-copies-to 'ask))
6245 (concat "Obey Mail-Copies-To: never? ") t "\
6246 You should normally obey the Mail-Copies-To: header.
6248 `Mail-Copies-To: " mct "'
6249 directs you not to send your response to the author."))
6252 ((or (equal (downcase mct) "always")
6253 (equal (downcase mct) "poster"))
6254 (if (or (not (eq message-use-mail-copies-to 'ask))
6256 (concat "Obey Mail-Copies-To: always? ") t "\
6257 You should normally obey the Mail-Copies-To: header.
6259 `Mail-Copies-To: " mct "'
6260 sends a copy of your response to the author."))
6263 ((and (eq message-use-mail-copies-to 'ask)
6264 (not (message-y-or-n-p
6265 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
6266 You should normally obey the Mail-Copies-To: header.
6268 `Mail-Copies-To: " mct "'
6269 sends a copy of your response to " (if (string-match "," mct)
6270 "the specified addresses"
6271 "that address") ".")))
6274 ;; Build (textual) list of new recipient addresses.
6277 (setq recipients (concat ", " author)))
6279 (dolist (header address-headers)
6280 (let ((value (message-fetch-field header)))
6282 (setq recipients (concat recipients ", " value))))))
6284 (string-match "[^ \t,]" mft)
6285 (or (not (eq message-use-mail-followup-to 'ask))
6286 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
6287 You should normally obey the Mail-Followup-To: header. In this
6288 article, it has the value of
6292 which directs your response to " (if (string-match "," mft)
6293 "the specified addresses"
6294 "that address only") ".
6296 Most commonly, Mail-Followup-To is used by a mailing list poster to
6297 express that responses should be sent to just the list, and not the
6300 If a message is posted to several mailing lists, Mail-Followup-To may
6301 also be used to direct the following discussion to one list only,
6302 because discussions that are spread over several lists tend to be
6303 fragmented and very difficult to follow.
6305 Also, some source/announcement lists are not intended for discussion;
6306 responses here are directed to other addresses.")))
6307 (setq recipients (concat ", " mft)))
6309 (setq recipients (concat ", " to-address))
6310 ;; If the author explicitly asked for a copy, we don't deny it to them.
6311 (if mct (setq recipients (concat recipients ", " mct))))
6313 (setq recipients (if never-mct "" (concat ", " author)))
6314 (if to (setq recipients (concat recipients ", " to)))
6315 (if cc (setq recipients (concat recipients ", " cc)))
6316 (if mct (setq recipients (concat recipients ", " mct)))))
6317 (if (>= (length recipients) 2)
6318 ;; Strip the leading ", ".
6319 (setq recipients (substring recipients 2)))
6320 ;; Squeeze whitespace.
6321 (while (string-match "[ \t][ \t]+" recipients)
6322 (setq recipients (replace-match " " t t recipients)))
6323 ;; Remove addresses that match `rmail-dont-reply-to-names'.
6324 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
6325 (setq recipients (rmail-dont-reply-to recipients)))
6326 ;; Perhaps "Mail-Copies-To: never" removed the only address?
6327 (if (string-equal recipients "")
6328 (setq recipients author))
6329 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
6333 (cons (downcase (mail-strip-quoted-names addr)) addr))
6334 (message-tokenize-header recipients)))
6335 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
6336 (let ((s recipients))
6338 (setq recipients (delq (assoc (car (pop s)) s) recipients))))
6340 ;; Remove hierarchical lists that are contained within each other,
6341 ;; if message-hierarchical-addresses is defined.
6342 (when message-hierarchical-addresses
6343 (let ((plain-addrs (mapcar 'car recipients))
6346 (setq subaddrs (assoc (car plain-addrs)
6347 message-hierarchical-addresses)
6348 plain-addrs (cdr plain-addrs))
6350 (setq subaddrs (cdr subaddrs))
6352 (setq recip (assoc (car subaddrs) recipients)
6353 subaddrs (cdr subaddrs))
6355 (setq recipients (delq recip recipients))))))))
6357 ;; Build the header alist. Allow the user to be asked whether
6358 ;; or not to reply to all recipients in a wide reply.
6359 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
6360 (when (and recipients
6361 (or (not message-wide-reply-confirm-recipients)
6362 (y-or-n-p "Reply to all recipients? ")))
6363 (setq recipients (mapconcat
6364 (lambda (addr) (cdr addr)) recipients ", "))
6365 (if (string-match "^ +" recipients)
6366 (setq recipients (substring recipients (match-end 0))))
6367 (push (cons 'Cc recipients) follow-to)))
6371 (defun message-reply (&optional to-address wide)
6372 "Start editing a reply to the article in the current buffer."
6374 (require 'gnus-sum) ; for gnus-list-identifiers
6375 (let ((cur (current-buffer))
6377 references message-id follow-to
6378 (inhibit-point-motion-hooks t)
6379 (message-this-is-mail t)
6380 gnus-warning in-reply-to)
6382 (message-narrow-to-head-1)
6383 ;; Allow customizations to have their say.
6385 ;; This is a regular reply.
6386 (when (functionp message-reply-to-function)
6388 (setq follow-to (funcall message-reply-to-function))))
6389 ;; This is a followup.
6390 (when (functionp message-wide-reply-to-function)
6393 (funcall message-wide-reply-to-function)))))
6394 (setq message-id (message-fetch-field "message-id" t)
6395 references (message-fetch-field "references")
6396 date (message-fetch-field "date")
6397 from (message-fetch-field "from")
6398 subject (or (message-fetch-field "subject") "none"))
6399 (when gnus-list-identifiers
6400 (setq subject (message-strip-list-identifiers subject)))
6401 (setq subject (message-make-followup-subject subject))
6402 (when message-subject-trailing-was-query
6403 (setq subject (message-strip-subject-trailing-was subject)))
6405 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6406 (string-match "<[^>]+>" gnus-warning))
6407 (setq message-id (match-string 0 gnus-warning)))
6410 (setq follow-to (message-get-reply-headers wide to-address)))
6412 ;; Get the references from "In-Reply-To" field if there were
6413 ;; no references and "In-Reply-To" field looks promising.
6415 (when (and (setq in-reply-to (message-fetch-field "in-reply-to"))
6416 (string-match "<[^>]+>" in-reply-to))
6417 (setq references (match-string 0 in-reply-to)))))
6419 (unless (message-mail-user-agent)
6420 (message-pop-to-buffer
6421 (message-buffer-name
6422 (if wide "wide reply" "reply") from
6423 (if wide to-address nil))))
6425 (setq message-reply-headers
6426 (make-full-mail-header-from-decoded-header
6427 0 subject from date message-id references 0 0 ""))
6430 `((Subject . ,subject)
6435 (defun message-wide-reply (&optional to-address)
6436 "Make a \"wide\" reply to the message in the current buffer."
6438 (message-reply to-address t))
6441 (defun message-followup (&optional to-newsgroups)
6442 "Follow up to the message in the current buffer.
6443 If TO-NEWSGROUPS, use that as the new Newsgroups line."
6445 (require 'gnus-sum) ; for gnus-list-identifiers
6446 (let ((cur (current-buffer))
6447 from subject date reply-to mrt mct mft
6448 references message-id follow-to
6449 (inhibit-point-motion-hooks t)
6450 (message-this-is-news t)
6451 followup-to distribution newsgroups gnus-warning posted-to)
6453 (message-narrow-to-head)
6454 (when (functionp message-followup-to-function)
6456 (funcall message-followup-to-function)))
6457 (setq from (message-fetch-field "from")
6458 date (message-fetch-field "date")
6459 subject (or (message-fetch-field "subject") "none")
6460 references (message-fetch-field "references")
6461 message-id (message-fetch-field "message-id" t)
6462 followup-to (message-fetch-field "followup-to")
6463 newsgroups (message-fetch-field "newsgroups")
6464 posted-to (message-fetch-field "posted-to")
6465 reply-to (message-fetch-field "reply-to")
6466 mrt (when message-use-mail-reply-to
6467 (message-fetch-field "mail-reply-to"))
6468 distribution (message-fetch-field "distribution")
6469 mct (when message-use-mail-copies-to
6470 (message-fetch-field "mail-copies-to"))
6471 mft (when message-use-mail-followup-to
6472 (message-fetch-field "mail-followup-to")))
6473 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6474 (string-match "<[^>]+>" gnus-warning))
6475 (setq message-id (match-string 0 gnus-warning)))
6476 ;; Remove bogus distribution.
6477 (when (and (stringp distribution)
6478 (let ((case-fold-search t))
6479 (string-match "world" distribution)))
6480 (setq distribution nil))
6481 (if gnus-list-identifiers
6482 (setq subject (message-strip-list-identifiers subject)))
6483 (setq subject (message-make-followup-subject subject))
6484 (when message-subject-trailing-was-query
6485 (setq subject (message-strip-subject-trailing-was subject)))
6488 ;; Handle special values of Mail-Copies-To.
6491 ((and (or (equal (downcase mct) "never")
6492 (equal (downcase mct) "nobody")))
6494 ((and (or (equal (downcase mct) "always")
6495 (equal (downcase mct) "poster")))
6496 (if (or (not (eq message-use-mail-copies-to 'ask))
6498 (concat "Obey Mail-Copies-To: always? ") t "\
6499 You should normally obey the Mail-Copies-To: header.
6501 `Mail-Copies-To: " mct "'
6502 sends a copy of your response to the author."))
6503 (setq mct (or mrt reply-to from))
6505 ((and (eq message-use-mail-copies-to 'ask)
6508 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
6509 You should normally obey the Mail-Copies-To: header.
6511 `Mail-Copies-To: " mct "'
6512 sends a copy of your response to " (if (string-match "," mct)
6513 "the specified addresses"
6514 "that address") ".")))
6519 (to-newsgroups (setq follow-to (list (cons 'Newsgroups to-newsgroups))))
6520 ;; Handle Followup-To.
6523 ((equal (downcase followup-to) "poster")
6524 (if (or (and followup-to (eq message-use-followup-to 'use))
6525 (message-y-or-n-p "Obey Followup-To: poster? " t "\
6526 You should normally obey the Followup-To: header.
6528 `Followup-To: poster'
6529 sends your response via e-mail instead of news.
6531 A typical situation where `Followup-To: poster' is used is when the author
6532 does not read the newsgroup, so he wouldn't see any replies sent to it."))
6533 (setq message-this-is-news nil
6535 follow-to (list (cons 'To (or mrt reply-to from ""))))
6536 (setq follow-to (list (cons 'Newsgroups newsgroups)))))
6538 (if (or (equal followup-to newsgroups)
6539 (not (and followup-to (eq message-use-followup-to 'ask)))
6541 (concat "Obey Followup-To: " followup-to "? ") t "\
6542 You should normally obey the Followup-To: header.
6544 `Followup-To: " followup-to "'
6545 directs your response to " (if (string-match "," followup-to)
6546 "the specified newsgroups"
6547 "that newsgroup only") ".
6549 If a message is posted to several newsgroups, Followup-To is often
6550 used to direct the following discussion to one newsgroup only,
6551 because discussions that are spread over several newsgroup tend to
6552 be fragmented and very difficult to follow.
6554 Also, some source/announcement newsgroups are not intended for discussion;
6555 responses here are directed to other newsgroups."))
6556 (setq follow-to (list (cons 'Newsgroups followup-to)))
6557 (setq follow-to (list (cons 'Newsgroups newsgroups)))))))
6558 ;; Handle Mail-Followup-To, followup via e-mail.
6560 (or (not (eq message-use-mail-followup-to 'ask))
6562 (concat "Obey Mail-Followup-To: " mft "? ") t "\
6563 You should normally obey the Mail-Followup-To: header.
6565 `Mail-Followup-To: " mft "'
6566 directs your response to " (if (string-match "," mft)
6567 "the specified addresses"
6568 "that address only") " instead of news.
6570 A typical situation where Mail-Followup-To is used is when the author thinks
6571 that further discussion should take place only in "
6572 (if (string-match "," mft)
6573 "the specified mailing lists"
6574 "that mailing list") ".")))
6575 (setq message-this-is-news nil
6577 follow-to (list (cons 'To mft))))
6578 (posted-to (setq follow-to (list (cons 'Newsgroups posted-to))))
6580 (setq follow-to (list (cons 'Newsgroups newsgroups))))))
6582 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
6584 (setq message-reply-headers
6585 (make-full-mail-header-from-decoded-header
6586 0 subject from date message-id references 0 0 ""))
6589 `((Subject . ,subject)
6591 ,@(and mct (list (cons 'Cc mct)))
6592 ,@(and distribution (list (cons 'Distribution distribution))))
6595 (defun message-is-yours-p ()
6596 "Non-nil means current article is yours.
6597 If you have added 'cancel-messages to 'message-shoot-gnksa-feet', all articles
6598 are yours except those that have Cancel-Lock header not belonging to you.
6599 Instead of shooting GNKSA feet, you should modify 'message-alternative-emails'
6600 regexp to match all of yours addresses."
6601 ;; Canlock-logic as suggested by Per Abrahamsen
6602 ;; <abraham@dina.kvl.dk>
6604 ;; IF article has cancel-lock THEN
6605 ;; IF we can verify it THEN
6608 ;; error: cancellock: article is not yours
6610 ;; Use old rules, comparing sender...
6613 (message-narrow-to-head-1)
6614 (if (message-fetch-field "Cancel-Lock")
6615 (if (null (canlock-verify))
6617 (error "Failed to verify Cancel-lock: This article is not yours"))
6620 (message-gnksa-enable-p 'cancel-messages)
6621 (and (setq sender (message-fetch-field "sender"))
6622 (string-equal (downcase sender)
6623 (downcase (message-make-sender))))
6624 ;; Email address in From field equals to our address
6625 (and (setq from (message-fetch-field "from"))
6627 (downcase (cadr (std11-extract-address-components from)))
6628 (downcase (cadr (std11-extract-address-components
6629 (message-make-from))))))
6630 ;; Email address in From field matches
6631 ;; 'message-alternative-emails' regexp
6633 message-alternative-emails
6635 message-alternative-emails
6636 (cadr (std11-extract-address-components from))))))))))
6639 (defun message-cancel-news (&optional arg)
6640 "Cancel an article you posted.
6641 If ARG, allow editing of the cancellation message."
6643 (unless (message-news-p)
6644 (error "This is not a news article; canceling is impossible"))
6645 (let (from newsgroups message-id distribution buf)
6647 ;; Get header info from original article.
6649 (message-narrow-to-head-1)
6650 (setq from (message-fetch-field "from")
6651 newsgroups (message-fetch-field "newsgroups")
6652 message-id (message-fetch-field "message-id" t)
6653 distribution (message-fetch-field "distribution")))
6654 ;; Make sure that this article was written by the user.
6655 (unless (message-is-yours-p)
6656 (error "This article is not yours"))
6657 (when (yes-or-no-p "Do you really want to cancel this article? ")
6658 ;; Make control message.
6661 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
6663 (insert "Newsgroups: " newsgroups "\n"
6665 "Subject: cmsg cancel " message-id "\n"
6666 "Control: cancel " message-id "\n"
6668 (concat "Distribution: " distribution "\n")
6670 mail-header-separator "\n"
6671 message-cancel-message)
6672 (run-hooks 'message-cancel-hook)
6674 (message "Canceling your article...")
6675 (if (let ((message-syntax-checks
6676 'dont-check-for-anything-just-trust-me)
6677 (message-encoding-buffer (current-buffer))
6678 (message-edit-buffer (current-buffer)))
6679 (message-send-news))
6680 (message "Canceling your article...done"))
6681 (kill-buffer buf))))))
6683 (defun message-supersede-setup-for-mime-edit ()
6684 (set (make-local-variable 'message-setup-hook) nil)
6688 (defun message-supersede ()
6689 "Start composing a message to supersede the current message.
6690 This is done simply by taking the old article and adding a Supersedes
6691 header line with the old Message-ID."
6693 (let ((cur (current-buffer)))
6694 ;; Check whether the user owns the article that is to be superseded.
6695 (unless (message-is-yours-p)
6696 (error "This article is not yours"))
6697 ;; Get a normal message buffer.
6698 (message-pop-to-buffer (message-buffer-name "supersede"))
6699 (insert-buffer-substring cur)
6700 (message-narrow-to-head-1)
6701 ;; Remove unwanted headers.
6702 (when message-ignored-supersedes-headers
6703 (message-remove-header message-ignored-supersedes-headers t))
6704 (goto-char (point-min))
6705 (if (not (re-search-forward "^Message-ID: " nil t))
6706 (error "No Message-ID in this article")
6707 (replace-match "Supersedes: " t t))
6708 (goto-char (point-max))
6709 (insert mail-header-separator)
6711 (when message-supersede-setup-function
6712 (funcall message-supersede-setup-function))
6713 (run-hooks 'message-supersede-setup-hook)
6714 (goto-char (point-min))
6715 (search-forward (concat "\n" mail-header-separator "\n") nil t)))
6718 (defun message-recover ()
6719 "Reread contents of current buffer from its last auto-save file."
6721 (let ((file-name (make-auto-save-file-name)))
6722 (cond ((save-window-excursion
6723 (if (not (eq system-type 'vax-vms))
6724 (with-output-to-temp-buffer "*Directory*"
6725 (with-current-buffer standard-output
6726 (fundamental-mode)) ; for Emacs 20.4+
6727 (buffer-disable-undo standard-output)
6728 (let ((default-directory "/"))
6730 "ls" nil standard-output nil "-l" file-name))))
6731 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
6732 (let ((buffer-read-only nil))
6734 (insert-file-contents file-name nil)))
6735 (t (error "message-recover cancelled")))))
6737 ;;; Washing Subject:
6739 (defun message-wash-subject (subject)
6740 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
6741 Previous forwarders, replyers, etc. may add it."
6744 (goto-char (point-min))
6745 ;; strip Re/Fwd stuff off the beginning
6746 (while (re-search-forward
6747 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
6750 ;; and gnus-style forwards [foo@bar.com] subject
6751 (goto-char (point-min))
6752 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
6756 (goto-char (point-max))
6757 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
6760 ;; and finally, any whitespace that was left-over
6761 (goto-char (point-min))
6762 (while (re-search-forward "^[ \t]+" nil t)
6764 (goto-char (point-max))
6765 (while (re-search-backward "[ \t]+$" nil t)
6770 ;;; Forwarding messages.
6772 (defvar message-forward-decoded-p nil
6773 "Non-nil means the original message is decoded.")
6775 (defun message-forward-subject-name-subject (subject)
6776 "Generate a SUBJECT for a forwarded message.
6777 The form is: [Source] Subject, where if the original message was mail,
6778 Source is the name of the sender, and if the original message was
6779 news, Source is the list of newsgroups is was posted to."
6781 (let ((group (message-fetch-field "newsgroups"))
6784 (gnus-group-decoded-name group)
6785 (or (and (setq from (message-fetch-field "from"))
6786 (car (std11-extract-address-components
6787 (nnheader-decode-from from))))
6791 (defun message-forward-subject-author-subject (subject)
6792 "Generate a SUBJECT for a forwarded message.
6793 The form is: [Source] Subject, where if the original message was mail,
6794 Source is the sender, and if the original message was news, Source is
6795 the list of newsgroups is was posted to."
6797 (let ((group (message-fetch-field "newsgroups"))
6800 (gnus-group-decoded-name group)
6801 (if (setq from (message-fetch-field "from"))
6802 (nnheader-decode-from from)
6806 (defun message-forward-subject-fwd (subject)
6807 "Generate a SUBJECT for a forwarded message.
6808 The form is: Fwd: Subject, where Subject is the original subject of
6810 (if (string-match "^Fwd: " subject)
6812 (concat "Fwd: " subject)))
6814 (defun message-make-forward-subject ()
6815 "Return a Subject header suitable for the message in the current buffer."
6818 (message-narrow-to-head-1)
6819 (let ((funcs message-make-forward-subject-function)
6820 (subject (message-fetch-field "Subject")))
6823 (if message-forward-decoded-p
6825 (nnheader-decode-subject subject))
6827 (if message-wash-forwarded-subjects
6828 (setq subject (message-wash-subject subject)))
6829 ;; Make sure funcs is a list.
6832 (setq funcs (list funcs)))
6833 ;; Apply funcs in order, passing subject generated by previous
6834 ;; func to the next one.
6836 (when (functionp (car funcs))
6837 (setq subject (funcall (car funcs) subject)))
6838 (setq funcs (cdr funcs)))
6842 (defun message-forward (&optional news)
6843 "Forward the current message via mail.
6844 Optional NEWS will use news to forward instead of mail."
6846 (let ((cur (current-buffer))
6847 (subject (message-make-forward-subject)))
6849 (message-news nil subject)
6850 (message-mail nil subject))
6851 (message-forward-make-body cur)))
6853 (defun message-forward-make-body-plain (forward-buffer)
6855 "\n-------------------- Start of forwarded message --------------------\n")
6856 (let ((b (point)) e)
6859 (mm-disable-multibyte)
6861 (with-current-buffer forward-buffer
6862 (mm-with-unibyte-current-buffer (buffer-string))))
6863 (mm-enable-multibyte)
6865 (goto-char (point-min))
6866 (when (looking-at "From ")
6867 (replace-match "X-From-Line: "))
6871 "\n-------------------- End of forwarded message --------------------\n")
6872 (when (and (not current-prefix-arg)
6873 message-forward-ignored-headers)
6875 (narrow-to-region b e)
6877 (narrow-to-region (point)
6878 (or (search-forward "\n\n" nil t) (point)))
6879 (message-remove-header message-forward-ignored-headers t)))))
6881 (defun message-forward-make-body-mime (forward-buffer)
6882 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
6883 (let ((b (point)) e)
6885 (narrow-to-region (point) (point))
6886 (mml-insert-buffer forward-buffer)
6887 (goto-char (point-min))
6888 (when (looking-at "From ")
6889 (replace-match "X-From-Line: "))
6890 (goto-char (point-max)))
6892 (insert "<#/part>\n")))
6894 (defun message-forward-make-body-mml (forward-buffer)
6895 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
6896 (let ((b (point)) e)
6897 (if (not message-forward-decoded-p)
6900 (mm-disable-multibyte)
6902 (with-current-buffer forward-buffer
6903 (mm-with-unibyte-current-buffer (buffer-string))))
6904 (mm-enable-multibyte)
6906 (goto-char (point-min))
6907 (when (looking-at "From ")
6908 (replace-match "X-From-Line: "))
6911 (narrow-to-region (point) (point))
6912 (mml-insert-buffer forward-buffer)
6913 (goto-char (point-min))
6914 (when (looking-at "From ")
6915 (replace-match "X-From-Line: "))
6916 (goto-char (point-max))))
6918 (insert "<#/mml>\n")
6919 (when (and (not current-prefix-arg)
6920 message-forward-ignored-headers)
6922 (narrow-to-region b e)
6924 (narrow-to-region (point)
6925 (or (search-forward "\n\n" nil t) (point)))
6926 (message-remove-header message-forward-ignored-headers t)))))
6928 (defun message-forward-make-body-digest-plain (forward-buffer)
6930 "\n-------------------- Start of forwarded message --------------------\n")
6931 (let ((b (point)) e)
6932 (mml-insert-buffer forward-buffer)
6935 "\n-------------------- End of forwarded message --------------------\n")))
6937 (defun message-forward-make-body-digest-mime (forward-buffer)
6938 (insert "\n<#multipart type=digest>\n")
6939 (let ((b (point)) e)
6940 (insert-buffer-substring forward-buffer)
6942 (insert "<#/multipart>\n")
6944 (narrow-to-region b e)
6946 (narrow-to-region (point)
6947 (or (search-forward "\n\n" nil t) (point)))
6948 (delete-region (point-min) (point-max)))))
6950 (defun message-forward-make-body-digest (forward-buffer)
6951 (if message-forward-as-mime
6952 (message-forward-make-body-digest-mime forward-buffer)
6953 (message-forward-make-body-digest-plain forward-buffer)))
6956 (defun message-forward-make-body (forward-buffer)
6957 ;; Put point where we want it before inserting the forwarded
6959 ;; Note that this function definition for T-gnus is totally different
6960 ;; from the original Gnus."
6961 (if message-forward-before-signature
6963 (goto-char (point-max)))
6964 ;; Make sure we're at the start of the line.
6967 ;; Narrow to the area we are to insert.
6968 (narrow-to-region (point) (point))
6969 ;; Insert the separators and the forwarded buffer.
6970 (insert message-forward-start-separator)
6971 (let ((art-beg (point)))
6972 (insert-buffer-substring forward-buffer)
6973 (goto-char (point-max))
6974 (insert message-forward-end-separator)
6975 (set-text-properties (point-min) (point-max) nil)
6976 ;; Remove all unwanted headers.
6978 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
6981 (goto-char (point-min))
6982 (message-remove-header message-included-forward-headers t nil t)
6984 (message-position-point)))
6987 (defun message-forward-rmail-make-body (forward-buffer)
6988 (save-window-excursion
6989 (set-buffer forward-buffer)
6990 ;; Rmail doesn't have rmail-msg-restore-non-pruned-header in Emacs
6991 ;; 20. FIXIT, or we drop support for rmail in Emacs 20.
6992 (if (rmail-msg-is-pruned)
6993 (rmail-msg-restore-non-pruned-header)))
6994 (message-forward-make-body forward-buffer))
6996 (eval-when-compile (defvar rmail-enable-mime-composing))
6998 ;; Fixme: Should have defcustom.
7000 (defun message-insinuate-rmail ()
7001 "Let RMAIL use message to forward."
7003 (setq rmail-enable-mime-composing t)
7004 (setq rmail-insert-mime-forwarded-message-function
7005 'message-forward-rmail-make-body))
7008 (defun message-resend (address)
7009 "Resend the current article to ADDRESS."
7011 (list (message-read-from-minibuffer "Resend message to: ")))
7012 (message "Resending message to %s..." address)
7014 (let ((cur (current-buffer))
7016 ;; We first set up a normal mail buffer.
7017 (unless (message-mail-user-agent)
7018 (set-buffer (get-buffer-create " *message resend*"))
7020 (let ((message-this-is-mail t)
7022 (message-setup `((To . ,address))))
7023 ;; Insert our usual headers.
7024 (message-generate-headers '(From Date To Message-ID))
7025 (message-narrow-to-headers)
7026 ;; Remove X-Draft-From header etc.
7027 (message-remove-header message-ignored-mail-headers t)
7028 ;; Rename them all to "Resent-*".
7029 (goto-char (point-min))
7030 (while (re-search-forward "^[A-Za-z]" nil t)
7035 (delete-region (point) (point-max))
7037 ;; Insert the message to be resent.
7038 (insert-buffer-substring cur)
7039 (goto-char (point-min))
7040 (search-forward "\n\n")
7043 (narrow-to-region beg (point))
7044 (message-remove-header message-ignored-resent-headers t)
7045 (goto-char (point-max)))
7046 (insert mail-header-separator)
7047 ;; Rename all old ("Also-")Resent headers.
7048 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
7051 ;; Quote any "From " lines at the beginning.
7053 (when (looking-at "From ")
7054 (replace-match "X-From-Line: "))
7056 (let ((message-encoding-buffer (current-buffer))
7057 (message-edit-buffer (current-buffer))
7058 message-required-mail-headers)
7059 (message-send-mail))
7060 (kill-buffer (current-buffer)))
7061 (message "Resending message to %s...done" address)))
7063 (defun message-bounce-setup-for-mime-edit ()
7064 (set (make-local-variable 'message-setup-hook) nil)
7068 (defun message-bounce ()
7069 "Re-mail the current message.
7070 This only makes sense if the current message is a bounce message that
7071 contains some mail you have written which has been bounced back to
7074 (let ((cur (current-buffer))
7075 mime-boundary boundary)
7076 (message-pop-to-buffer (message-buffer-name "bounce"))
7077 (insert-buffer-substring cur)
7079 (message-narrow-to-head)
7080 (if (and (message-fetch-field "MIME-Version")
7081 (setq mime-boundary (message-fetch-field "Content-Type")))
7082 (if (string-match "boundary=\"\\([^\"]+\\)\"" mime-boundary)
7083 (setq mime-boundary (concat (regexp-quote
7084 (match-string 1 mime-boundary))
7085 " *\nContent-Type: message/rfc822"))
7086 (setq mime-boundary nil)))
7088 (goto-char (point-min))
7089 (re-search-forward "\n\n+" nil t)
7090 (setq boundary (point))
7091 ;; We remove everything before the bounced mail.
7092 (if (or (and mime-boundary
7093 (re-search-forward mime-boundary nil t)
7095 (re-search-forward message-unsent-separator nil t)
7097 (search-forward "\n\n" nil 'move)
7098 (re-search-backward "^Return-Path:.*\n" boundary t)))
7101 (delete-region (point-min)
7102 (if (re-search-forward "^[^ \n\t]+:" nil t)
7105 (when (re-search-backward "^.?From .*\n" nil t)
7106 (delete-region (match-beginning 0) (match-end 0))))
7108 (message-narrow-to-head-1)
7109 (message-remove-header message-ignored-bounced-headers t)
7110 (goto-char (point-max))
7111 (insert mail-header-separator))
7112 (when message-bounce-setup-function
7113 (funcall message-bounce-setup-function))
7114 (run-hooks 'message-bounce-setup-hook)
7115 (message-position-point)))
7118 ;;; Interactive entry points for new message buffers.
7122 (defun message-mail-other-window (&optional to subject)
7123 "Like `message-mail' command, but display mail buffer in another window."
7125 (unless (message-mail-user-agent)
7126 (let ((pop-up-windows t)
7127 (special-display-buffer-names nil)
7128 (special-display-regexps nil)
7129 (same-window-buffer-names nil)
7130 (same-window-regexps nil))
7131 (message-pop-to-buffer (message-buffer-name "mail" to))))
7132 (let ((message-this-is-mail t))
7133 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7134 nil nil 'switch-to-buffer-other-window)))
7137 (defun message-mail-other-frame (&optional to subject)
7138 "Like `message-mail' command, but display mail buffer in another frame."
7140 (unless (message-mail-user-agent)
7141 (let ((pop-up-frames t)
7142 (special-display-buffer-names nil)
7143 (special-display-regexps nil)
7144 (same-window-buffer-names nil)
7145 (same-window-regexps nil))
7146 (message-pop-to-buffer (message-buffer-name "mail" to))))
7147 (let ((message-this-is-mail t))
7148 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7149 nil nil 'switch-to-buffer-other-frame)))
7152 (defun message-news-other-window (&optional newsgroups subject)
7153 "Start editing a news article to be sent."
7155 (let ((pop-up-windows t)
7156 (special-display-buffer-names nil)
7157 (special-display-regexps nil)
7158 (same-window-buffer-names nil)
7159 (same-window-regexps nil))
7160 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
7161 (let ((message-this-is-news t))
7162 (message-setup `((Newsgroups . ,(or newsgroups ""))
7163 (Subject . ,(or subject ""))))))
7166 (defun message-news-other-frame (&optional newsgroups subject)
7167 "Start editing a news article to be sent."
7169 (let ((pop-up-frames t)
7170 (special-display-buffer-names nil)
7171 (special-display-regexps nil)
7172 (same-window-buffer-names nil)
7173 (same-window-regexps nil))
7174 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
7175 (let ((message-this-is-news t))
7176 (message-setup `((Newsgroups . ,(or newsgroups ""))
7177 (Subject . ,(or subject ""))))))
7181 ;; This code should be moved to underline.el (from which it is stolen).
7184 (defun bold-region (start end)
7185 "Bold all nonblank characters in the region.
7186 Works by overstriking characters.
7187 Called from program, takes two arguments START and END
7188 which specify the range to operate on."
7191 (let ((end1 (make-marker)))
7192 (move-marker end1 (max start end))
7193 (goto-char (min start end))
7194 (while (< (point) end1)
7195 (or (looking-at "[_\^@- ]")
7196 (insert (char-after) "\b"))
7197 (forward-char 1)))))
7200 (defun unbold-region (start end)
7201 "Remove all boldness (overstruck characters) in the region.
7202 Called from program, takes two arguments START and END
7203 which specify the range to operate on."
7206 (let ((end1 (make-marker)))
7207 (move-marker end1 (max start end))
7208 (goto-char (min start end))
7209 (while (re-search-forward "\b" end1 t)
7210 (if (eq (char-after) (char-after (- (point) 2)))
7211 (delete-char -2))))))
7213 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
7214 (defalias 'message-make-overlay 'make-overlay)
7215 (defalias 'message-delete-overlay 'delete-overlay)
7216 (defalias 'message-overlay-put 'overlay-put)
7217 (defun message-kill-all-overlays ()
7218 (if (featurep 'xemacs)
7219 (map-extents (lambda (extent ignore) (delete-extent extent)))
7220 (mapcar #'delete-overlay (overlays-in (point-min) (point-max)))))
7222 ;; Support for toolbar
7224 (defvar tool-bar-map)
7225 (defvar tool-bar-mode))
7227 (defun message-tool-bar-local-item-from-menu (command icon in-map &optional from-map &rest props)
7228 ;; We need to make tool bar entries in local keymaps with
7229 ;; `tool-bar-local-item-from-menu' in Emacs > 21.3
7230 (if (fboundp 'tool-bar-local-item-from-menu)
7231 ;; This is for Emacs 21.3
7232 (tool-bar-local-item-from-menu command icon in-map from-map props)
7233 (tool-bar-add-item-from-menu command icon from-map props)))
7235 (defun message-tool-bar-map ()
7236 (or message-tool-bar-map
7237 (setq message-tool-bar-map
7239 (condition-case nil (require 'tool-bar) (error nil))
7240 (fboundp 'tool-bar-add-item-from-menu)
7242 (let ((tool-bar-map (copy-keymap tool-bar-map))
7243 (load-path (mm-image-load-path)))
7244 ;; Zap some items which aren't so relevant and take
7246 (dolist (key '(print-buffer kill-buffer save-buffer
7247 write-file dired open-file))
7248 (define-key tool-bar-map (vector key) nil))
7249 (message-tool-bar-local-item-from-menu
7250 'message-send-and-exit "mail_send" tool-bar-map message-mode-map)
7251 (message-tool-bar-local-item-from-menu
7252 'message-kill-buffer "close" tool-bar-map message-mode-map)
7253 (message-tool-bar-local-item-from-menu
7254 'message-dont-send "cancel" tool-bar-map message-mode-map)
7255 ;; (message-tool-bar-local-item-from-menu
7256 ;; 'mime-edit-insert-file "attach"
7257 ;; tool-bar-map mime-edit-mode-map)
7258 (message-tool-bar-local-item-from-menu
7259 'ispell-message "spell" tool-bar-map message-mode-map)
7260 ;; (message-tool-bar-local-item-from-menu
7261 ;; 'mime-edit-preview-message "preview"
7262 ;; tool-bar-map mime-edit-mode-map)
7263 (message-tool-bar-local-item-from-menu
7264 'message-insert-importance-high "important"
7265 tool-bar-map message-mode-map)
7266 (message-tool-bar-local-item-from-menu
7267 'message-insert-importance-low "unimportant"
7268 tool-bar-map message-mode-map)
7269 (message-tool-bar-local-item-from-menu
7270 'message-insert-disposition-notification-to "receipt"
7271 tool-bar-map message-mode-map)
7274 ;;; Group name completion.
7276 (defcustom message-newgroups-header-regexp
7277 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
7278 "Regexp that match headers that lists groups."
7282 (defcustom message-completion-alist
7283 (list (cons message-newgroups-header-regexp 'message-expand-group)
7284 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name)
7285 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
7286 . message-expand-name)
7287 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
7288 . message-expand-name))
7289 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
7291 :type '(alist :key-type regexp :value-type function))
7293 (defcustom message-expand-name-function
7294 (if (fboundp 'bbdb-complete-name)
7296 (if (fboundp 'lsdb-complete-name)
7299 "*A function called to expand addresses in field body."
7303 (defcustom message-tab-body-function nil
7304 "*Function to execute when `message-tab' (TAB) is executed in the body.
7305 If nil, the function bound in `text-mode-map' or `global-map' is executed."
7307 :link '(custom-manual "(message)Various Commands")
7310 (defun message-tab ()
7311 "Complete names according to `message-completion-alist'.
7312 Execute function specified by `message-tab-body-function' when not in
7315 (let ((alist message-completion-alist))
7317 (let ((mail-abbrev-mode-regexp (caar alist)))
7318 (not (mail-abbrev-in-expansion-header-p))))
7319 (setq alist (cdr alist)))
7320 (funcall (or (cdar alist) message-tab-body-function
7321 (lookup-key text-mode-map "\t")
7322 (lookup-key global-map "\t")
7323 'indent-relative))))
7325 (defun message-expand-group ()
7326 "Expand the group name under point."
7327 (let* ((b (save-excursion
7332 (skip-chars-forward "^:")
7335 (skip-chars-backward "^, \t\n") (point))))
7336 (completion-ignore-case t)
7337 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
7339 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
7340 (completions (all-completions string hashtb))
7342 (delete-region b (point))
7344 ((= (length completions) 1)
7345 (if (string= (car completions) string)
7348 (message "Only matching group"))
7349 (insert (car completions))))
7350 ((and (setq comp (try-completion string hashtb))
7351 (not (string= comp string)))
7356 (message "No matching groups")
7357 (save-selected-window
7358 (pop-to-buffer "*Completions*")
7359 (buffer-disable-undo)
7360 (let ((buffer-read-only nil))
7362 (let ((standard-output (current-buffer)))
7363 (display-completion-list (sort completions 'string<)))
7364 (goto-char (point-min))
7365 (delete-region (point) (progn (forward-line 3) (point))))))))))
7367 (defun message-expand-name ()
7368 (funcall message-expand-name-function))
7372 (defun message-talkative-question (ask question show &rest text)
7373 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
7374 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
7375 The following arguments may contain lists of values."
7377 (setq text (message-flatten-list text)))
7378 (save-window-excursion
7380 (with-output-to-temp-buffer " *MESSAGE information message*"
7381 (set-buffer " *MESSAGE information message*")
7382 (fundamental-mode) ; for Emacs 20.4+
7383 (mapcar 'princ text)
7384 (goto-char (point-min))))
7385 (funcall ask question))
7386 (funcall ask question)))
7388 (defun message-flatten-list (list)
7389 "Return a new, flat list that contains all elements of LIST.
7391 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
7394 (apply 'append (mapcar 'message-flatten-list list)))
7398 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
7399 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
7400 Then clone the local variables and values from the old buffer to the
7401 new one, cloning only the locals having a substring matching the
7403 (let ((oldbuf (current-buffer)))
7405 (set-buffer (generate-new-buffer name))
7406 (message-clone-locals oldbuf varstr)
7409 (defun message-clone-locals (buffer &optional varstr)
7410 "Clone the local variables from BUFFER to the current buffer."
7411 (let ((locals (save-excursion
7413 (buffer-local-variables)))
7415 "^\\(gnus\\|nn\\|message\\|user-\\(mail-address\\|full-name\\)\\)"))
7418 (when (and (consp local)
7420 (string-match regexp (symbol-name (car local)))
7422 (string-match varstr (symbol-name (car local)))))
7424 (set (make-local-variable (car local))
7428 ;;; @ for MIME Edit mode
7431 (defun message-maybe-encode ()
7432 (when message-mime-mode
7433 ;; Inherit the buffer local variable `mime-edit-pgp-processing'.
7434 (let ((pgp-processing (with-current-buffer message-edit-buffer
7435 mime-edit-pgp-processing)))
7436 (setq mime-edit-pgp-processing pgp-processing))
7437 (run-hooks 'mime-edit-translate-hook)
7438 (if (catch 'mime-edit-error
7440 (mime-edit-pgp-enclose-buffer)
7441 (mime-edit-translate-body)))
7442 (error "Translation error!"))
7443 (run-hooks 'mime-edit-exit-hook)))
7445 (defun message-mime-insert-article (&optional full-headers)
7447 (let ((message-cite-function 'mime-edit-inserted-message-filter)
7448 (message-reply-buffer
7449 (message-get-parameter-with-eval 'original-buffer))
7451 (message-yank-original nil)
7453 (narrow-to-region (goto-char start)
7454 (if (search-forward "\n\n" nil t)
7457 (goto-char (point-min))
7458 (let ((message-included-forward-headers
7459 (if full-headers "" message-included-forward-headers)))
7460 (message-remove-header message-included-forward-headers t nil t))
7463 (set-alist 'mime-edit-message-inserter-alist
7464 'message-mode (function message-mime-insert-article))
7470 (defvar message-inhibit-body-encoding t)
7472 (defun message-encode-message-body ()
7473 (unless message-inhibit-body-encoding
7474 (let ((mail-parse-charset (or mail-parse-charset
7475 message-default-charset))
7476 (case-fold-search t)
7477 lines content-type-p)
7480 (narrow-to-region (point) (point-max))
7481 (let ((new (mml-generate-mime)))
7483 (delete-region (point-min) (point-max))
7485 (goto-char (point-min))
7486 (if (eq (aref new 0) ?\n)
7488 (search-forward "\n\n")
7489 (setq lines (buffer-substring (point-min) (1- (point))))
7490 (delete-region (point-min) (point))))))
7492 (message-narrow-to-headers-or-head)
7493 (message-remove-header "Mime-Version")
7494 (goto-char (point-max))
7495 (insert "MIME-Version: 1.0\n")
7498 (setq content-type-p
7500 (re-search-backward "^Content-Type:" nil t))))
7502 (message-narrow-to-headers-or-head)
7503 (message-remove-first-header "Content-Type")
7504 (message-remove-first-header "Content-Transfer-Encoding"))
7505 ;; We always make sure that the message has a Content-Type
7506 ;; header. This is because some broken MTAs and MUAs get
7507 ;; awfully confused when confronted with a message with a
7508 ;; MIME-Version header and without a Content-Type header. For
7509 ;; instance, Solaris' /usr/bin/mail.
7510 (unless content-type-p
7511 (goto-char (point-min))
7512 ;; For unknown reason, MIME-Version doesn't exist.
7513 (when (re-search-forward "^MIME-Version:" nil t)
7515 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
7517 (defun message-read-from-minibuffer (prompt &optional initial-contents)
7518 "Read from the minibuffer while providing abbrev expansion."
7519 (if (fboundp 'mail-abbrevs-setup)
7520 (let ((mail-abbrev-mode-regexp "")
7521 (minibuffer-setup-hook 'mail-abbrevs-setup)
7522 (minibuffer-local-map message-minibuffer-local-map))
7523 (read-from-minibuffer prompt initial-contents))
7524 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
7525 (minibuffer-local-map message-minibuffer-local-map))
7526 (read-string prompt initial-contents))))
7528 (defun message-use-alternative-email-as-from ()
7529 (require 'mail-utils)
7530 (let* ((fields '("To" "Cc"))
7533 (mail-strip-quoted-names
7534 (mapconcat 'message-fetch-reply-field fields ","))
7538 (if (string-match message-alternative-emails (car emails))
7539 (setq email (car emails)
7542 (unless (or (not email) (equal email user-mail-address))
7543 (goto-char (point-max))
7544 (insert "From: " email "\n"))))
7546 (defun message-options-get (symbol)
7547 (cdr (assq symbol message-options)))
7549 (defun message-options-set (symbol value)
7550 (let ((the-cons (assq symbol message-options)))
7553 (setcdr the-cons value)
7554 (setq message-options (delq the-cons message-options)))
7556 (push (cons symbol value) message-options))))
7559 (defun message-options-set-recipient ()
7561 (message-narrow-to-headers-or-head)
7562 (message-options-set 'message-sender
7563 (mail-strip-quoted-names
7564 (message-fetch-field "from")))
7565 (message-options-set 'message-recipients
7566 (mail-strip-quoted-names
7567 (let ((to (message-fetch-field "to"))
7568 (cc (message-fetch-field "cc"))
7569 (bcc (message-fetch-field "bcc")))
7572 (if (and to cc) ", ")
7574 (if (and (or to cc) bcc) ", ")
7577 (defun message-hide-headers ()
7578 "Hide headers based on the `message-hidden-headers' variable."
7579 (let ((regexps (if (stringp message-hidden-headers)
7580 (list message-hidden-headers)
7581 message-hidden-headers))
7582 (inhibit-point-motion-hooks t)
7583 (after-change-functions nil))
7587 (message-narrow-to-headers)
7588 (goto-char (point-min))
7590 (if (not (message-hide-header-p regexps))
7591 (message-next-header)
7592 (let ((begin (point)))
7593 (message-next-header)
7594 (add-text-properties
7596 '(invisible t message-hidden t))))))))))
7598 (defun message-hide-header-p (regexps)
7601 (when (eq (car regexps) 'not)
7604 (dolist (regexp regexps)
7605 (setq result (or result (looking-at regexp))))
7610 (when (featurep 'xemacs)
7611 (require 'messagexmas)
7612 (message-xmas-redefine))
7616 (run-hooks 'message-load-hook)
7619 ;; coding: iso-8859-1
7622 ;;; message.el ends here