1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; 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
48 ;; This is apparently necessary even though things are autoloaded.
49 ;; Because we dynamically bind mail-abbrev-mode-regexp, we'd better
50 ;; require mailabbrev here.
51 (if (featurep 'xemacs)
52 (require 'mail-abbrevs)
53 (require 'mailabbrev))
55 (eval-when-compile (require 'static))
57 ;; Avoid byte-compile warnings.
64 (defgroup message '((user-mail-address custom-variable)
65 (user-full-name custom-variable))
66 "Mail and news message composing."
67 :link '(custom-manual "(message)Top")
71 (put 'user-mail-address 'custom-type 'string)
72 (put 'user-full-name 'custom-type 'string)
74 (defgroup message-various nil
75 "Various Message Variables"
76 :link '(custom-manual "(message)Various Message Variables")
79 (defgroup message-buffers nil
81 :link '(custom-manual "(message)Message Buffers")
84 (defgroup message-sending nil
86 :link '(custom-manual "(message)Sending Variables")
89 (defgroup message-interface nil
91 :link '(custom-manual "(message)Interface")
94 (defgroup message-forwarding nil
96 :link '(custom-manual "(message)Forwarding")
97 :group 'message-interface)
99 (defgroup message-insertion nil
101 :link '(custom-manual "(message)Insertion")
104 (defgroup message-headers nil
106 :link '(custom-manual "(message)Message Headers")
109 (defgroup message-news nil
110 "Composing News Messages"
113 (defgroup message-mail nil
114 "Composing Mail Messages"
117 (defgroup message-faces nil
118 "Faces used for message composing."
122 (defgroup message-frames nil
126 (defcustom message-directory "~/Mail/"
127 "*Directory from which all other mail file variables are derived."
128 :group 'message-various
131 (defcustom message-max-buffers 10
132 "*How many buffers to keep before starting to kill them off."
133 :group 'message-buffers
136 (defcustom message-send-rename-function nil
137 "Function called to rename the buffer after sending it."
138 :group 'message-buffers
139 :type '(choice function (const nil)))
141 (defcustom message-fcc-handler-function 'message-output
142 "*A function called to save outgoing articles.
143 This function will be called with the name of the file to store the
144 article in. The default function is `message-output' which saves in Unix
146 :type '(radio (function-item message-output)
147 (function :tag "Other"))
148 :group 'message-sending)
150 (defcustom message-encode-function 'message-maybe-encode
151 "*A function called to encode messages."
152 :group 'message-sending
155 (defcustom message-8bit-encoding-list '(8bit binary)
156 "*8bit encoding type in Content-Transfer-Encoding field."
157 :group 'message-sending
158 :type '(repeat (symbol :tag "Type")))
160 (defcustom message-fcc-externalize-attachments nil
161 "If non-nil, attachments are included as external parts in Fcc copies."
164 :group 'message-sending)
166 (defcustom message-courtesy-message
167 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
168 "*This is inserted at the start of a mailed copy of a posted message.
169 If the string contains the format spec \"%s\", the Newsgroups
170 the article has been posted to will be inserted there.
171 If this variable is nil, no such courtesy message will be added."
172 :group 'message-sending
173 :type '(radio string (const nil)))
175 (defcustom message-ignored-bounced-headers
176 "^\\(Received\\|Return-Path\\|Delivered-To\\):"
177 "*Regexp that matches headers to be removed in resent bounced mail."
178 :group 'message-interface
181 (defcustom message-bounce-setup-function 'message-bounce-setup-for-mime-edit
182 "Function to setup a re-sending bounced message."
183 :group 'message-sending
186 ;;; Start of variables adopted from `message-utils.el'.
188 (defcustom message-subject-trailing-was-query 'ask
189 "*What to do with trailing \"(was: <old subject>)\" in subject lines.
190 If nil, leave the subject unchanged. If it is the symbol `ask', query
191 the user what do do. In this case, the subject is matched against
192 `message-subject-trailing-was-ask-regexp'. If
193 `message-subject-trailing-was-query' is t, always strip the trailing
194 old subject. In this case, `message-subject-trailing-was-regexp' is
197 :type '(choice (const :tag "never" nil)
198 (const :tag "always strip" t)
200 :link '(custom-manual "(message)Message Headers")
201 :group 'message-various)
203 (defcustom message-subject-trailing-was-ask-regexp
204 "[ \t]*\\([[(]+[Ww][Aa][Ss][ \t]*.*[\])]+\\)"
205 "*Regexp matching \"(was: <old subject>)\" in the subject line.
207 The function `message-strip-subject-trailing-was' uses this regexp if
208 `message-subject-trailing-was-query' is set to the symbol `ask'. If
209 the variable is t instead of `ask', use
210 `message-subject-trailing-was-regexp' instead.
212 It is okay to create some false positives here, as the user is asked."
214 :group 'message-various
215 :link '(custom-manual "(message)Message Headers")
218 (defcustom message-subject-trailing-was-regexp
219 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
220 "*Regexp matching \"(was: <old subject>)\" in the subject line.
222 If `message-subject-trailing-was-query' is set to t, the subject is
223 matched against `message-subject-trailing-was-regexp' in
224 `message-strip-subject-trailing-was'. You should use a regexp creating very
225 few false positives here."
227 :group 'message-various
228 :link '(custom-manual "(message)Message Headers")
231 ;; Fixme: Why are all these things autoloaded?
233 ;;; marking inserted text
236 (defcustom message-mark-insert-begin
237 "--8<---------------cut here---------------start------------->8---\n"
238 "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."
250 :link '(custom-manual "(message)Insertion Variables")
251 :group 'message-various)
254 (defcustom message-archive-header
255 "X-No-Archive: Yes\n"
256 "Header to insert when you don't want your article to be archived.
257 Archives \(such as groups.google.com\) respect this header."
260 :link '(custom-manual "(message)Header Commands")
261 :group 'message-various)
264 (defcustom message-archive-note
265 "X-No-Archive: Yes - save http://groups.google.com/"
266 "Note to insert why you wouldn't want this posting archived.
267 If nil, don't insert any text in the body."
269 :type '(radio string (const nil))
270 :link '(custom-manual "(message)Header Commands")
271 :group 'message-various)
273 ;;; Crossposts and Followups
274 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
275 ;; new suggestions by R. Weikusat <rw at another.de>
277 (defvar message-cross-post-old-target nil
278 "Old target for cross-posts or follow-ups.")
279 (make-variable-buffer-local 'message-cross-post-old-target)
282 (defcustom message-cross-post-default t
283 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
284 If nil, `message-cross-post-followup-to' will only do a followup. Note that
285 you can explicitly override this setting by calling
286 `message-cross-post-followup-to' with a prefix."
289 :group 'message-various)
292 (defcustom message-cross-post-note
293 "Crosspost & Followup-To: "
294 "Note to insert before signature to notify of xpost and follow-up."
297 :group 'message-various)
300 (defcustom message-followup-to-note
302 "Note to insert before signature to notify of follow-up only."
305 :group 'message-various)
308 (defcustom message-cross-post-note-function
309 'message-cross-post-insert-note
310 "Function to use to insert note about Crosspost or Followup-To.
311 The function will be called with four arguments. The function should not only
312 insert a note, but also ensure old notes are deleted. See the documentation
313 for `message-cross-post-insert-note'."
316 :group 'message-various)
318 ;;; End of variables adopted from `message-utils.el'.
321 (defcustom message-from-style 'default
322 "*Specifies how \"From\" headers look.
324 If nil, they contain just the return address like:
326 If `parens', they look like:
327 king@grassland.com (Elvis Parsley)
328 If `angles', they look like:
329 Elvis Parsley <king@grassland.com>
331 Otherwise, most addresses look like `angles', but they look like
332 `parens' if `angles' would need quoting and `parens' would not."
333 :type '(choice (const :tag "simple" nil)
337 :group 'message-headers)
339 (defcustom message-insert-canlock t
340 "Whether to insert a Cancel-Lock header in news postings."
342 :group 'message-headers
345 (defcustom message-syntax-checks
346 (if message-insert-canlock '((sender . disabled)) nil)
347 ;; Guess this one shouldn't be easy to customize...
348 "*Controls what syntax checks should not be performed on outgoing posts.
349 To disable checking of long signatures, for instance, add
350 `(signature . disabled)' to this list.
352 Don't touch this variable unless you really know what you're doing.
354 Checks include `subject-cmsg', `multiple-headers', `sendsys',
355 `message-id', `from', `long-lines', `control-chars', `size',
356 `new-text', `quoting-style', `redirected-followup', `signature',
357 `approved', `sender', `empty', `empty-headers', `message-id', `from',
358 `subject', `shorten-followup-to', `existing-newsgroups',
359 `buffer-file-name', `unchanged', `newsgroups', `reply-to',
360 `continuation-headers', `long-header-lines', `invisible-text' and
363 :type '(repeat sexp)) ; Fixme: improve this
365 (defcustom message-required-headers '((optional . References)
367 "*Headers to be generated or prompted for when sending a message.
368 Also see `message-required-news-headers' and
369 `message-required-mail-headers'."
372 :group 'message-headers
373 :link '(custom-manual "(message)Message Headers")
374 :type '(repeat sexp))
376 (defcustom message-draft-headers '(References From)
377 "*Headers to be generated when saving a draft message."
380 :group 'message-headers
381 :link '(custom-manual "(message)Message Headers")
382 :type '(repeat sexp))
384 (defcustom message-required-news-headers
385 '(From Newsgroups Subject Date Message-ID
386 (optional . Organization)
387 (optional . User-Agent))
388 "*Headers to be generated or prompted for when posting an article.
389 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
390 Message-ID. Organization, Lines, In-Reply-To, Expires, and
391 User-Agent are optional. If don't you want message to insert some
392 header, remove it from this list."
394 :group 'message-headers
395 :link '(custom-manual "(message)Message Headers")
396 :type '(repeat sexp))
398 (defcustom message-required-mail-headers
399 '(From Subject Date (optional . In-Reply-To) Message-ID
400 (optional . User-Agent))
401 "*Headers to be generated or prompted for when mailing a message.
402 It is recommended that From, Date, To, Subject and Message-ID be
403 included. Organization and User-Agent are optional."
405 :group 'message-headers
406 :link '(custom-manual "(message)Message Headers")
407 :type '(repeat sexp))
409 (defcustom message-deletable-headers '(Message-ID Date Lines)
410 "Headers to be deleted if they already exist and were generated by message previously."
411 :group 'message-headers
412 :link '(custom-manual "(message)Message Headers")
415 (defcustom message-ignored-news-headers
416 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
417 "*Regexp of headers to be removed unconditionally before posting."
419 :group 'message-headers
420 :link '(custom-manual "(message)Message Headers")
421 :type '(repeat :value-to-internal (lambda (widget value)
422 (custom-split-regexp-maybe value))
423 :match (lambda (widget value)
425 (widget-editable-list-match widget value)))
428 (defcustom message-ignored-mail-headers
429 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
430 "*Regexp of headers to be removed unconditionally before mailing."
432 :group 'message-headers
433 :link '(custom-manual "(message)Mail Headers")
436 (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:\\|^Approved:"
437 "*Header lines matching this regexp will be deleted before posting.
438 It's best to delete old Path and Date headers before posting to avoid
440 :group 'message-interface
441 :link '(custom-manual "(message)Superseding")
442 :type '(repeat :value-to-internal (lambda (widget value)
443 (custom-split-regexp-maybe value))
444 :match (lambda (widget value)
446 (widget-editable-list-match widget value)))
449 (defcustom message-supersede-setup-function
450 'message-supersede-setup-for-mime-edit
451 "Function to setup a supersede message."
452 :group 'message-sending
455 (defcustom message-subject-re-regexp
456 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)*:[ \t]*\\)*[ \t]*"
457 "*Regexp matching \"Re: \" in the subject line."
458 :group 'message-various
459 :link '(custom-manual "(message)Message Headers")
462 ;;; Some sender agents encode the whole subject including leading "Re: ".
463 ;;; And if followup agent does not decode it for some reason (e.g. unknown
464 ;;; charset) and just add a new "Re: " in front of the encoded-word, the
465 ;;; result will contain multiple "Re: "'s.
466 (defcustom message-subject-encoded-re-regexp
470 "[-!#$%&'*+0-9A-Z^_`a-z{|}~]+" ; charset
473 "[Bb]" (regexp-quote "?") ; B encoding
474 "\\(\\(CQk\\|CSA\\|IAk\\|ICA\\)[Jg]\\)*" ; \([ \t][ \t][ \t]\)*
476 "[Uc][km]U6" ; [Rr][Ee]:
478 "\\(C[VX]\\|I[FH]\\)J[Fl]O[g-v]" ; [ \t][Rr][Ee]:
480 "\\(CQl\\|CSB\\|IAl\\|ICB\\)[Sy][RZ]T[o-r]" ; [ \t][ \t][Rr][Ee]:
483 "[Qb]" (regexp-quote "?") ; Q encoding
484 "\\(_\\|=09\\|=20\\)*"
485 "\\([Rr]\\|=[57]2\\)\\([Ee]\\|=[46]5\\)\\(:\\|=3[Aa]\\)"
488 "*Regexp matching \"Re: \" in the subject line.
489 Unlike `message-subject-re-regexp', this regexp matches \"Re: \" within
491 :group 'message-various
492 :link '(custom-manual "(message)Message Headers")
495 (defcustom message-use-subject-re t
496 "*If t, remove any (buggy) \"Re: \"'s from the subject of the precursor
497 and add a new \"Re: \". If it is nil, use the subject \"as-is\". If it
498 is the symbol `guess', try to detect \"Re: \" within an encoded-word."
499 :group 'message-various
500 :type '(choice (const :tag "off" nil)
505 (defcustom message-signature-separator "^-- *$"
506 "Regexp matching the signature separator."
508 :link '(custom-manual "(message)Various Message Variables")
509 :group 'message-various)
511 (defcustom message-signature-separator-for-insertion "-- \n"
512 "*Signature separator. This value will be inserted as signature separator
513 when composing message. Default value is \"-- \\n\". Notice: Changing this
514 value may go against RFC-1036 and draft-ietf-usefor-article-05.txt. "
516 :group 'message-insertion)
518 (defcustom message-elide-ellipsis "\n[...]\n\n"
519 "*The string which is inserted for elided text."
521 :link '(custom-manual "(message)Insertion Variables")
522 :group 'message-various)
524 (defcustom message-interactive t
525 "Non-nil means when sending a message wait for and display errors.
526 nil means let mailer mail back a message to report errors."
527 :group 'message-sending
529 :link '(custom-manual "(message)Sending Variables")
532 (defcustom message-generate-new-buffers 'unique
533 "*Non-nil means create a new message buffer whenever `message-setup' is called.
534 If this is a function, call that function with three parameters: The type,
535 the to address and the group name. (Any of these may be nil.) The function
536 should return the new buffer name."
537 :group 'message-buffers
538 :link '(custom-manual "(message)Message Buffers")
539 :type '(choice (const :tag "off" nil)
540 (const :tag "unique" unique)
541 (const :tag "unsent" unsent)
544 (defcustom message-kill-buffer-on-exit nil
545 "*Non-nil means that the message buffer will be killed after sending a message."
546 :group 'message-buffers
547 :link '(custom-manual "(message)Message Buffers")
550 (defcustom message-kill-buffer-query-function 'yes-or-no-p
551 "*Function used to prompt user whether to kill the message buffer. If
552 it is t, the buffer will be killed unconditionally."
553 :type '(radio (function-item yes-or-no-p)
554 (function-item y-or-n-p)
555 (function-item nnheader-Y-or-n-p)
556 (function :tag "Other" t))
557 :group 'message-buffers)
559 (defcustom message-kill-buffer-and-remove-file t
560 "*Non-nil means that the associated file will be removed before
561 removing the message buffer. However, it is treated as nil when the
562 command `message-mimic-kill-buffer' is used."
563 :group 'message-buffers
567 (defvar gnus-local-organization))
568 (defcustom message-user-organization
569 (or (and (boundp 'gnus-local-organization)
570 (stringp gnus-local-organization)
571 gnus-local-organization)
572 (getenv "ORGANIZATION")
574 "*String to be used as an Organization header.
575 If t, use `message-user-organization-file'."
576 :group 'message-headers
577 :type '(choice string
578 (const :tag "consult file" t)))
581 (defcustom message-user-organization-file "/usr/lib/news/organization"
582 "*Local news organization file."
584 :link '(custom-manual "(message)News Headers")
585 :group 'message-headers)
587 (defcustom message-forward-start-separator
588 (concat (mime-make-tag "message" "rfc822") "\n")
589 "*Delimiter inserted before forwarded messages."
590 :group 'message-forwarding
593 (defcustom message-forward-end-separator
594 (concat (mime-make-tag "text" "plain") "\n")
595 "*Delimiter inserted after forwarded messages."
596 :group 'message-forwarding
599 (defcustom message-included-forward-headers
600 "^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:"
601 "*Regexp matching headers to be included in forwarded messages."
602 :group 'message-forwarding
605 (defcustom message-make-forward-subject-function
606 #'message-forward-subject-name-subject
607 "*List of functions called to generate subject headers for forwarded messages.
608 The subject generated by the previous function is passed into each
611 The provided functions are:
613 * `message-forward-subject-author-subject' Source of article (author or
614 newsgroup), in brackets followed by the subject
615 * `message-forward-subject-name-subject' Source of article (name of author
616 or newsgroup), in brackets followed by the subject
617 * `message-forward-subject-fwd' Subject of article with 'Fwd:' prepended
619 :group 'message-forwarding
620 :link '(custom-manual "(message)Forwarding")
621 :type '(radio (function-item message-forward-subject-author-subject)
622 (function-item message-forward-subject-fwd)
623 (function-item message-forward-subject-name-subject)
624 (repeat :tag "List of functions" function)))
626 (defcustom message-forward-as-mime t
627 "*Non-nil means forward messages as an inline/rfc822 MIME section.
628 Otherwise, directly inline the old message in the forwarded message."
630 :group 'message-forwarding
631 :link '(custom-manual "(message)Forwarding")
634 (defcustom message-forward-show-mml 'best
635 "*Non-nil means show forwarded messages as MML (decoded from MIME).
636 Otherwise, forwarded messages are unchanged.
637 Can also be the symbol `best' to indicate that MML should be
638 used, except when it is a bad idea to use MML. One example where
639 it is a bad idea is when forwarding a signed or encrypted
640 message, because converting MIME to MML would invalidate the
643 :group 'message-forwarding
644 :type '(choice (const :tag "use MML" t)
645 (const :tag "don't use MML " nil)
646 (const :tag "use MML when appropriate" best)))
648 (defcustom message-forward-before-signature t
649 "*Non-nil means put forwarded message before signature, else after."
650 :group 'message-forwarding
653 (defcustom message-wash-forwarded-subjects nil
654 "*Non-nil means try to remove as much cruft as possible from the subject.
655 Done before generating the new subject of a forward."
656 :group 'message-forwarding
657 :link '(custom-manual "(message)Forwarding")
660 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From "
661 "*All headers that match this regexp will be deleted when resending a message."
662 :group 'message-interface
663 :link '(custom-manual "(message)Resending")
664 :type '(repeat :value-to-internal (lambda (widget value)
665 (custom-split-regexp-maybe value))
666 :match (lambda (widget value)
668 (widget-editable-list-match widget value)))
671 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
672 "*All headers that match this regexp will be deleted when forwarding a message."
674 :group 'message-forwarding
675 :type '(repeat :value-to-internal (lambda (widget value)
676 (custom-split-regexp-maybe value))
677 :match (lambda (widget value)
679 (widget-editable-list-match widget value)))
682 (defcustom message-ignored-cited-headers "."
683 "*Delete these headers from the messages you yank."
684 :group 'message-insertion
685 :link '(custom-manual "(message)Insertion Variables")
688 (defcustom message-cite-prefix-regexp
689 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
690 "\\([ \t]*[-_.[:word:]]+>+\\|[ \t]*[]>|}+]\\)+"
691 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
692 (let (non-word-constituents)
693 (with-syntax-table text-mode-syntax-table
694 (setq non-word-constituents
696 (if (string-match "\\w" "-") "" "-")
697 (if (string-match "\\w" "_") "" "_")
698 (if (string-match "\\w" ".") "" "."))))
699 (if (equal non-word-constituents "")
700 "\\([ \t]*\\(\\w\\)+>+\\|[ \t]*[]>|}+]\\)+"
701 (concat "\\([ \t]*\\(\\w\\|["
702 non-word-constituents
703 "]\\)+>+\\|[ \t]*[]>|}+]\\)+"))))
704 "*Regexp matching the longest possible citation prefix on a line."
706 :group 'message-insertion
707 :link '(custom-manual "(message)Insertion Variables")
710 (defcustom message-cancel-message "I am canceling my own article.\n"
711 "Message to be inserted in the cancel message."
712 :group 'message-interface
713 :link '(custom-manual "(message)Canceling News")
716 ;; Useful to set in site-init.el
718 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
719 "Function to call to send the current buffer as mail.
720 The headers should be delimited by a line whose contents match the
721 variable `mail-header-separator'.
723 Valid values include `message-send-mail-with-sendmail' (the default),
724 `message-send-mail-with-mh', `message-send-mail-with-qmail',
725 `message-send-mail-with-smtp', `message-smtpmail-send-it',
726 `smtpmail-send-it' and `feedmail-send-it'.
728 See also `send-mail-function'."
729 :type '(radio (function-item message-send-mail-with-sendmail)
730 (function-item message-send-mail-with-mh)
731 (function-item message-send-mail-with-qmail)
732 (function-item message-send-mail-with-smtp)
733 (function-item message-smtpmail-send-it)
734 (function-item smtpmail-send-it)
735 (function-item feedmail-send-it)
736 (function :tag "Other"))
737 :group 'message-sending
738 :link '(custom-manual "(message)Mail Variables")
739 :group 'message-mail)
741 ;; 1997-09-29 by MORIOKA Tomohiko
742 (defcustom message-send-news-function 'message-send-news-with-gnus
743 "Function to call to send the current buffer as news.
744 The headers should be delimited by a line whose contents match the
745 variable `mail-header-separator'."
746 :group 'message-sending
748 :link '(custom-manual "(message)News Variables")
751 (defcustom message-reply-to-function nil
752 "If non-nil, function that should return a list of headers.
753 This function should pick out addresses from the To, Cc, and From headers
754 and respond with new To and Cc headers."
755 :group 'message-interface
756 :link '(custom-manual "(message)Reply")
757 :type '(choice function (const nil)))
759 (defcustom message-wide-reply-to-function nil
760 "If non-nil, function that should return a list of headers.
761 This function should pick out addresses from the To, Cc, and From headers
762 and respond with new To and Cc headers."
763 :group 'message-interface
764 :link '(custom-manual "(message)Wide Reply")
765 :type '(choice function (const nil)))
767 (defcustom message-followup-to-function nil
768 "If non-nil, function that should return a list of headers.
769 This function should pick out addresses from the To, Cc, and From headers
770 and respond with new To and Cc headers."
771 :group 'message-interface
772 :link '(custom-manual "(message)Followup")
773 :type '(choice function (const nil)))
775 (defcustom message-extra-wide-headers nil
776 "If non-nil, a list of additional address headers.
777 These are used when composing a wide reply."
778 :group 'message-sending
779 :type '(repeat string))
781 (defcustom message-use-followup-to 'ask
782 "*Specifies what to do with Followup-To header.
783 If nil, always ignore the header. If it is t, use its value, but
784 query before using the \"poster\" value. If it is the symbol `ask',
785 always query the user whether to use the value. If it is the symbol
786 `use', always use the value."
787 :group 'message-interface
788 :link '(custom-manual "(message)Followup")
789 :type '(choice (const :tag "ignore" nil)
790 (const :tag "use & query" t)
791 (const :tag "maybe" t)
792 (const :tag "always" use)
793 (const :tag "ask" ask)))
795 (defcustom message-use-mail-copies-to 'ask
796 "*Specifies what to do with Mail-Copies-To header.
797 If nil, always ignore the header. If it is t, use its value, but
798 query before using the value other than \"always\" or \"never\".
799 If it is the symbol `ask', always query the user whether to use
800 the value. If it is the symbol `use', always use the value."
801 :group 'message-interface
802 :link '(custom-manual "(message)Mailing Lists")
803 :type '(choice (const :tag "ignore" nil)
804 (const :tag "maybe" t)
805 (const :tag "always" use)
806 (const :tag "ask" ask)))
808 ;;; XXX: 'ask and 'use are not implemented yet.
809 (defcustom message-use-mail-reply-to 'ask
810 "*Specifies what to do with Mail-Reply-To/Reply-To header.
811 If nil, always ignore the header. If it is t or the symbol `use', use
812 its value. If it is the symbol `ask', always query the user whether to
813 use the value. Note that if \"Reply-To\" is marked as \"broken\", its value
815 :group 'message-interface
816 :type '(choice (const :tag "ignore" nil)
817 (const :tag "maybe" t)
818 (const :tag "always" use)
819 (const :tag "ask" ask)))
821 (defcustom message-use-mail-followup-to 'use
822 "*Specifies what to do with Mail-Followup-To header.
823 If nil, always ignore the header. If it is the symbol `ask', always
824 query the user whether to use the value. If it is t or the symbol
825 `use', always use the value."
827 :group 'message-interface
828 :type '(choice (const :tag "ignore" nil)
829 (const :tag "maybe" t)
830 (const :tag "always" use)
831 (const :tag "ask" ask)))
833 (defcustom message-subscribed-address-functions nil
834 "*Specifies functions for determining list subscription.
835 If nil, do not attempt to determine list subscription with functions.
836 If non-nil, this variable contains a list of functions which return
837 regular expressions to match lists. These functions can be used in
838 conjunction with `message-subscribed-regexps' and
839 `message-subscribed-addresses'."
841 :group 'message-interface
842 :link '(custom-manual "(message)Mailing Lists")
843 :type '(repeat sexp))
845 (defcustom message-subscribed-address-file nil
846 "*A file containing addresses the user is subscribed to.
847 If nil, do not look at any files to determine list subscriptions. If
848 non-nil, each line of this file should be a mailing list address."
850 :group 'message-interface
851 :link '(custom-manual "(message)Mailing Lists")
852 :type '(radio file (const nil)))
854 (defcustom message-subscribed-addresses nil
855 "*Specifies a list of addresses the user is subscribed to.
856 If nil, do not use any predefined list subscriptions. This list of
857 addresses can be used in conjunction with
858 `message-subscribed-address-functions' and `message-subscribed-regexps'."
860 :group 'message-interface
861 :link '(custom-manual "(message)Mailing Lists")
862 :type '(repeat string))
864 (defcustom message-subscribed-regexps nil
865 "*Specifies a list of addresses the user is subscribed to.
866 If nil, do not use any predefined list subscriptions. This list of
867 regular expressions can be used in conjunction with
868 `message-subscribed-address-functions' and `message-subscribed-addresses'."
870 :group 'message-interface
871 :link '(custom-manual "(message)Mailing Lists")
872 :type '(repeat regexp))
874 (defcustom message-allow-no-recipients 'ask
875 "Specifies what to do when there are no recipients other than Gcc/Fcc.
876 If it is the symbol `always', the posting is allowed. If it is the
877 symbol `never', the posting is not allowed. If it is the symbol
878 `ask', you are prompted."
880 :group 'message-interface
881 :link '(custom-manual "(message)Message Headers")
882 :type '(choice (const always)
886 (defcustom message-sendmail-f-is-evil nil
887 "*Non-nil means don't add \"-f username\" to the sendmail command line.
888 Doing so would be even more evil than leaving it out."
889 :group 'message-sending
890 :link '(custom-manual "(message)Mail Variables")
893 (defcustom message-sendmail-envelope-from nil
894 "*Envelope-from when sending mail with sendmail.
895 If this is nil, use `user-mail-address'. If it is the symbol
896 `header', use the From: header of the message."
898 :type '(choice (string :tag "From name")
899 (const :tag "Use From: header from message" header)
900 (const :tag "Use `user-mail-address'" nil))
901 :link '(custom-manual "(message)Mail Variables")
902 :group 'message-sending)
904 ;; qmail-related stuff
905 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
906 "Location of the qmail-inject program."
907 :group 'message-sending
908 :link '(custom-manual "(message)Mail Variables")
911 (defcustom message-qmail-inject-args nil
912 "Arguments passed to qmail-inject programs.
913 This should be a list of strings, one string for each argument. It
914 may also be a function.
916 For e.g., if you wish to set the envelope sender address so that bounces
917 go to the right place or to deal with listserv's usage of that address, you
918 might set this variable to '(\"-f\" \"you@some.where\")."
919 :group 'message-sending
920 :link '(custom-manual "(message)Mail Variables")
921 :type '(choice (function)
925 (defvar gnus-post-method)
926 (defvar gnus-select-method))
927 (defcustom message-post-method
928 (cond ((and (boundp 'gnus-post-method)
929 (listp gnus-post-method)
932 ((boundp 'gnus-select-method)
935 "*Method used to post news.
936 Note that when posting from inside Gnus, for instance, this
937 variable isn't used."
939 :group 'message-sending
940 ;; This should be the `gnus-select-method' widget, but that might
941 ;; create a dependence to `gnus.el'.
944 ;; FIXME: This should be a temporary workaround until someone implements a
945 ;; proper solution. If a crash happens while replying, the auto-save file
946 ;; will *not* have a `References:' header if `message-generate-headers-first'
947 ;; is nil. See: http://article.gmane.org/gmane.emacs.gnus.general/51138
948 (defcustom message-generate-headers-first '(references)
949 "Which headers should be generated before starting to compose a message.
950 If t, generate all required headers. This can also be a list of headers to
951 generate. The variables `message-required-news-headers' and
952 `message-required-mail-headers' specify which headers to generate.
954 Note that the variable `message-deletable-headers' specifies headers which
955 are to be deleted and then re-generated before sending, so this variable
956 will not have a visible effect for those headers."
957 :group 'message-headers
958 :link '(custom-manual "(message)Message Headers")
959 :type '(choice (const :tag "None" nil)
960 (const :tag "References" '(references))
962 (repeat (sexp :tag "Header"))))
964 (defcustom message-setup-hook '(turn-on-mime-edit)
965 "Normal hook, run each time a new outgoing message is initialized.
966 The function `message-setup' runs this hook."
967 :group 'message-various
968 :link '(custom-manual "(message)Various Message Variables")
971 (defcustom message-cancel-hook nil
972 "Hook run when cancelling articles."
973 :group 'message-various
974 :link '(custom-manual "(message)Various Message Variables")
977 (defcustom message-signature-setup-hook nil
978 "Normal hook, run each time a new outgoing message is initialized.
979 It is run after the headers have been inserted and before
980 the signature is inserted."
981 :group 'message-various
982 :link '(custom-manual "(message)Various Message Variables")
985 (defcustom message-bounce-setup-hook nil
986 "Normal hook, run each time a re-sending bounced message is initialized.
987 The function `message-bounce' runs this hook."
988 :group 'message-various
991 (defcustom message-supersede-setup-hook nil
992 "Normal hook, run each time a supersede message is initialized.
993 The function `message-supersede' runs this hook."
994 :group 'message-various
997 (defcustom message-mode-hook nil
998 "Hook run in message mode buffers."
999 :group 'message-various
1002 (defcustom message-header-hook '((lambda () (mime-encode-header-in-buffer t)))
1003 "Hook run in a message mode buffer narrowed to the headers."
1004 :group 'message-various
1007 (defcustom message-header-setup-hook nil
1008 "Hook called narrowed to the headers when setting up a message buffer."
1009 :group 'message-various
1010 :link '(custom-manual "(message)Various Message Variables")
1013 (defcustom message-minibuffer-local-map
1014 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
1015 (set-keymap-parent map minibuffer-local-map)
1017 "Keymap for `message-read-from-minibuffer'."
1021 (defcustom message-citation-line-function 'message-insert-citation-line
1022 "*Function called to insert the \"Whomever writes:\" line.
1024 Note that Gnus provides a feature where the reader can click on
1025 `writes:' to hide the cited text. If you change this line too much,
1026 people who read your message will have to change their Gnus
1027 configuration. See the variable `gnus-cite-attribution-suffix'."
1029 :link '(custom-manual "(message)Insertion Variables")
1030 :group 'message-insertion)
1033 (defcustom message-yank-prefix "> "
1034 "*Prefix inserted on the lines of yanked messages.
1035 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1036 See also `message-yank-cited-prefix'."
1038 :link '(custom-manual "(message)Insertion Variables")
1039 :group 'message-insertion)
1041 (defcustom message-yank-add-new-references t
1042 "Non-nil means new IDs will be added to \"References\" field when an
1043 article is yanked by the command `message-yank-original' interactively.
1044 If it is a symbol `message-id-only', only an ID from \"Message-ID\" field
1045 is used, otherwise IDs extracted from \"References\", \"In-Reply-To\" and
1046 \"Message-ID\" fields are used."
1047 :type '(radio (const :tag "Do not add anything" nil)
1048 (const :tag "From Message-Id, References and In-Reply-To fields" t)
1049 (const :tag "From only Message-Id field." message-id-only))
1050 :group 'message-insertion)
1052 (defcustom message-list-references-add-position nil
1053 "Integer value means position for adding to \"References\" field when
1054 an article is yanked by the command `message-yank-original' interactively."
1055 :type '(radio (const :tag "Add to last" nil)
1056 (integer :tag "Position from last ID"))
1057 :group 'message-insertion)
1059 (defcustom message-yank-cited-prefix ">"
1060 "*Prefix inserted on cited or empty lines of yanked messages.
1061 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1062 See also `message-yank-prefix'."
1065 :link '(custom-manual "(message)Insertion Variables")
1066 :group 'message-insertion)
1068 (defcustom message-indentation-spaces 3
1069 "*Number of spaces to insert at the beginning of each cited line.
1070 Used by `message-yank-original' via `message-yank-cite'."
1071 :group 'message-insertion
1072 :link '(custom-manual "(message)Insertion Variables")
1076 (defcustom message-cite-function 'message-cite-original
1077 "*Function for citing an original message.
1078 Predefined functions include `message-cite-original' and
1079 `message-cite-original-without-signature'.
1080 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
1081 :type '(radio (function-item message-cite-original)
1082 (function-item message-cite-original-without-signature)
1083 (function-item mu-cite-original)
1084 (function-item sc-cite-original)
1085 (function :tag "Other"))
1086 :link '(custom-manual "(message)Insertion Variables")
1087 :group 'message-insertion)
1090 (defcustom message-suspend-font-lock-when-citing nil
1091 "Non-nil means suspend font-lock'ing while citing an original message.
1092 Some lazy demand-driven fontification tools (or Emacs itself) have a
1093 bug that they often miss a buffer to be fontified. It will mostly
1094 occur when Emacs prompts user for any inputs in the minibuffer.
1095 Setting this option to non-nil may help you to avoid unpleasant errors
1096 even if it is an add-hoc expedient."
1098 :group 'message-insertion)
1101 (defcustom message-indent-citation-function 'message-indent-citation
1102 "*Function for modifying a citation just inserted in the mail buffer.
1103 This can also be a list of functions. Each function can find the
1104 citation between (point) and (mark t). And each function should leave
1105 point and mark around the citation text as modified."
1107 :link '(custom-manual "(message)Insertion Variables")
1108 :group 'message-insertion)
1111 (defcustom message-signature t
1112 "*String to be inserted at the end of the message buffer.
1113 If t, the `message-signature-file' file will be inserted instead.
1114 If a function, the result from the function will be used instead.
1115 If a form, the result from the form will be used instead."
1117 :link '(custom-manual "(message)Insertion Variables")
1118 :group 'message-insertion)
1121 (defcustom message-signature-file "~/.signature"
1122 "*Name of file containing the text inserted at end of message buffer.
1123 Ignored if the named file doesn't exist.
1124 If nil, don't insert a signature."
1125 :type '(choice file (const :tags "None" nil))
1126 :link '(custom-manual "(message)Insertion Variables")
1127 :group 'message-insertion)
1130 (defcustom message-signature-insert-empty-line t
1131 "*If non-nil, insert an empty line before the signature separator."
1134 :link '(custom-manual "(message)Insertion Variables")
1135 :group 'message-insertion)
1137 (defcustom message-distribution-function nil
1138 "*Function called to return a Distribution header."
1139 :group 'message-news
1140 :group 'message-headers
1141 :link '(custom-manual "(message)News Headers")
1142 :type '(choice function (const nil)))
1144 (defcustom message-expires 14
1145 "Number of days before your article expires."
1146 :group 'message-news
1147 :group 'message-headers
1148 :link '(custom-manual "(message)News Headers")
1151 (defcustom message-user-path nil
1152 "If nil, use the NNTP server name in the Path header.
1153 If stringp, use this; if non-nil, use no host name (user name only)."
1154 :group 'message-news
1155 :group 'message-headers
1156 :link '(custom-manual "(message)News Headers")
1157 :type '(choice (const :tag "nntp" nil)
1158 (string :tag "name")
1159 (sexp :tag "none" :format "%t" t)))
1161 (defvar message-reply-buffer nil)
1162 (defvar message-reply-headers nil
1163 "The headers of the current replied article.
1164 It is a vector of the following headers:
1165 \[number subject from date id references chars lines xref extra].")
1166 (defvar message-sent-message-via nil)
1167 (defvar message-checksum nil)
1168 (defvar message-send-actions nil
1169 "A list of actions to be performed upon successful sending of a message.")
1170 (defvar message-exit-actions nil
1171 "A list of actions to be performed upon exiting after sending a message.")
1172 (defvar message-kill-actions nil
1173 "A list of actions to be performed before killing a message buffer.")
1174 (defvar message-postpone-actions nil
1175 "A list of actions to be performed after postponing a message.")
1176 (defvar message-original-frame nil)
1177 (defvar message-parameter-alist nil)
1178 (defvar message-startup-parameter-alist nil)
1180 (define-widget 'message-header-lines 'text
1181 "All header lines must be LFD terminated."
1182 :format "%{%t%}:%n%v"
1183 :valid-regexp "^\\'"
1184 :error "All header lines must be newline terminated")
1186 (defcustom message-default-headers ""
1187 "*A string containing header lines to be inserted in outgoing messages.
1188 It is inserted before you edit the message, so you can edit or delete
1190 :group 'message-headers
1191 :link '(custom-manual "(message)Message Headers")
1192 :type 'message-header-lines)
1194 (defcustom message-default-mail-headers ""
1195 "*A string of header lines to be inserted in outgoing mails."
1196 :group 'message-headers
1197 :group 'message-mail
1198 :link '(custom-manual "(message)Mail Headers")
1199 :type 'message-header-lines)
1201 (defcustom message-default-news-headers ""
1202 "*A string of header lines to be inserted in outgoing news articles."
1203 :group 'message-headers
1204 :group 'message-news
1205 :link '(custom-manual "(message)News Headers")
1206 :type 'message-header-lines)
1208 ;; Note: could use /usr/ucb/mail instead of sendmail;
1209 ;; options -t, and -v if not interactive.
1210 (defcustom message-mailer-swallows-blank-line
1211 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1212 system-configuration)
1213 (file-readable-p "/etc/sendmail.cf")
1214 (let ((buffer (get-buffer-create " *temp*")))
1218 (insert-file-contents "/etc/sendmail.cf")
1219 (goto-char (point-min))
1220 (let ((case-fold-search nil))
1221 (re-search-forward "^OR\\>" nil t)))
1222 (kill-buffer buffer))))
1223 ;; According to RFC822, "The field-name must be composed of printable
1224 ;; ASCII characters (i. e., characters that have decimal values between
1225 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1227 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1228 "*Set this non-nil if the system's mailer runs the header and body together.
1229 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1230 The value should be an expression to test whether the problem will
1232 :group 'message-sending
1233 :link '(custom-manual "(message)Mail Variables")
1236 ;;; XXX: This symbol is overloaded! See below.
1237 (defvar message-user-agent nil
1238 "String of the form of PRODUCT/VERSION. Used for User-Agent header field.")
1241 (define-mail-user-agent 'message-user-agent
1242 'message-mail 'message-send-and-exit
1243 'message-kill-buffer 'message-send-hook)
1245 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
1246 "If non-nil, delete the deletable headers before feeding to mh.")
1248 (defvar message-send-method-alist
1249 '((news message-news-p message-send-via-news)
1250 (mail message-mail-p message-send-via-mail))
1251 "Alist of ways to send outgoing messages.
1252 Each element has the form
1254 \(TYPE PREDICATE FUNCTION)
1256 where TYPE is a symbol that names the method; PREDICATE is a function
1257 called without any parameters to determine whether the message is
1258 a message of type TYPE; and FUNCTION is a function to be called if
1259 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1262 (defcustom message-mail-alias-type 'abbrev
1263 "*What alias expansion type to use in Message buffers.
1264 The default is `abbrev', which uses mailabbrev. nil switches
1267 :link '(custom-manual "(message)Mail Aliases")
1268 :type '(choice (const :tag "Use Mailabbrev" abbrev)
1269 (const :tag "No expansion" nil)))
1271 (defcustom message-auto-save-directory
1272 (file-name-as-directory (nnheader-concat message-directory "drafts"))
1273 "*Directory where Message auto-saves buffers if Gnus isn't running.
1274 If nil, Message won't auto-save."
1275 :group 'message-buffers
1276 :link '(custom-manual "(message)Various Message Variables")
1277 :type '(choice directory (const :tag "Don't auto-save" nil)))
1279 (defcustom message-default-charset
1280 (and (featurep 'xemacs) (not (featurep 'mule)) 'iso-8859-1)
1281 "Default charset used in non-MULE XEmacsen."
1284 :link '(custom-manual "(message)Various Message Variables")
1287 (defcustom message-dont-reply-to-names
1288 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
1289 "*A regexp specifying addresses to prune when doing wide replies.
1290 A value of nil means exclude your own user name only."
1293 :link '(custom-manual "(message)Wide Reply")
1294 :type '(choice (const :tag "Yourself" nil)
1297 (defvar message-shoot-gnksa-feet nil
1298 "*A list of GNKSA feet you are allowed to shoot.
1299 Gnus gives you all the opportunity you could possibly want for
1300 shooting yourself in the foot. Also, Gnus allows you to shoot the
1301 feet of Good Net-Keeping Seal of Approval. The following are foot
1303 `empty-article' Allow you to post an empty article;
1304 `quoted-text-only' Allow you to post quoted text only;
1305 `multiple-copies' Allow you to post multiple copies;
1306 `cancel-messages' Allow you to cancel or supersede messages from
1307 your other email addresses.")
1309 (defsubst message-gnksa-enable-p (feature)
1310 (or (not (listp message-shoot-gnksa-feet))
1311 (memq feature message-shoot-gnksa-feet)))
1313 (defcustom message-hidden-headers "^References:"
1314 "Regexp of headers to be hidden when composing new messages.
1315 This can also be a list of regexps to match headers. Or a list
1316 starting with `not' and followed by regexps."
1319 :link '(custom-manual "(message)Message Headers")
1321 :format "%{%t%}: %[Value Type%] %v"
1322 (regexp :menu-tag "regexp" :format "regexp\n%t: %v")
1323 (repeat :menu-tag "(regexp ...)" :format "(regexp ...)\n%v%i"
1324 (regexp :format "%t: %v"))
1325 (cons :menu-tag "(not regexp ...)" :format "(not regexp ...)\n%v"
1327 (repeat :format "%v%i"
1328 (regexp :format "%t: %v")))))
1330 (defcustom message-cite-articles-with-x-no-archive t
1331 "If non-nil, cite text from articles that has X-No-Archive set."
1335 ;;; Internal variables.
1336 ;;; Well, not really internal.
1338 (defvar message-mode-syntax-table
1339 (let ((table (copy-syntax-table text-mode-syntax-table)))
1340 (modify-syntax-entry ?% ". " table)
1341 (modify-syntax-entry ?> ". " table)
1342 (modify-syntax-entry ?< ". " table)
1344 "Syntax table used while in Message mode.")
1346 (defface message-header-to-face
1349 (:foreground "green2" :bold t))
1352 (:foreground "MidnightBlue" :bold t))
1354 (:bold t :italic t)))
1355 "Face used for displaying From headers."
1356 :group 'message-faces)
1358 (defface message-header-cc-face
1361 (:foreground "green4" :bold t))
1364 (:foreground "MidnightBlue"))
1367 "Face used for displaying Cc headers."
1368 :group 'message-faces)
1370 (defface message-header-subject-face
1373 (:foreground "green3"))
1376 (:foreground "navy blue" :bold t))
1379 "Face used for displaying subject headers."
1380 :group 'message-faces)
1382 (defface message-header-newsgroups-face
1385 (:foreground "yellow" :bold t :italic t))
1388 (:foreground "blue4" :bold t :italic t))
1390 (:bold t :italic t)))
1391 "Face used for displaying newsgroups headers."
1392 :group 'message-faces)
1394 (defface message-header-other-face
1397 (:foreground "#b00000"))
1400 (:foreground "steel blue"))
1402 (:bold t :italic t)))
1403 "Face used for displaying newsgroups headers."
1404 :group 'message-faces)
1406 (defface message-header-name-face
1409 (:foreground "DarkGreen"))
1412 (:foreground "cornflower blue"))
1415 "Face used for displaying header names."
1416 :group 'message-faces)
1418 (defface message-header-xheader-face
1421 (:foreground "blue"))
1424 (:foreground "blue"))
1427 "Face used for displaying X-Header headers."
1428 :group 'message-faces)
1430 (defface message-separator-face
1433 (:foreground "blue3"))
1436 (:foreground "brown"))
1439 "Face used for displaying the separator."
1440 :group 'message-faces)
1442 (defface message-cited-text-face
1445 (:foreground "red"))
1448 (:foreground "red"))
1451 "Face used for displaying cited text names."
1452 :group 'message-faces)
1454 (defface message-mml-face
1457 (:foreground "ForestGreen"))
1460 (:foreground "ForestGreen"))
1463 "Face used for displaying MML."
1464 :group 'message-faces)
1466 (defun message-font-lock-make-header-matcher (regexp)
1469 (let ((start (point)))
1472 (goto-char (point-min))
1473 (if (re-search-forward
1474 (concat "^" (regexp-quote mail-header-separator) "$")
1476 (setq limit (min limit (match-beginning 0))))
1478 (and (< start limit)
1479 (re-search-forward ,regexp limit t))))))
1480 (if (featurep 'bytecomp)
1484 (defvar message-font-lock-keywords
1485 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1486 `((,(message-font-lock-make-header-matcher
1487 (concat "^\\([Tt]o:\\)" content))
1488 (1 'message-header-name-face)
1489 (2 'message-header-to-face nil t))
1490 (,(message-font-lock-make-header-matcher
1491 (concat "^\\([GBF]?[Cc][Cc]:\\|[Rr]eply-[Tt]o:\\|"
1492 "[Mm]ail-[Cc]opies-[Tt]o:\\|"
1493 "[Mm]ail-[Rr]eply-[Tt]o:\\|"
1494 "[Mm]ail-[Ff]ollowup-[Tt]o:\\)" content))
1495 (1 'message-header-name-face)
1496 (2 'message-header-cc-face nil t))
1497 (,(message-font-lock-make-header-matcher
1498 (concat "^\\([Ss]ubject:\\)" content))
1499 (1 'message-header-name-face)
1500 (2 'message-header-subject-face nil t))
1501 (,(message-font-lock-make-header-matcher
1502 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content))
1503 (1 'message-header-name-face)
1504 (2 'message-header-newsgroups-face nil t))
1505 (,(message-font-lock-make-header-matcher
1506 (concat "^\\([A-Z][^: \n\t]+:\\)" content))
1507 (1 'message-header-name-face)
1508 (2 'message-header-other-face nil t))
1509 (,(message-font-lock-make-header-matcher
1510 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content))
1511 (1 'message-header-name-face)
1512 (2 'message-header-name-face))
1513 ,@(if (and mail-header-separator
1514 (not (equal mail-header-separator "")))
1515 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1516 1 'message-separator-face))
1519 (re-search-forward (concat "^\\("
1520 message-cite-prefix-regexp
1523 (0 'message-cited-text-face))
1524 (,mime-edit-tag-regexp
1525 (0 'message-mml-face))))
1526 "Additional expressions to highlight in Message mode.")
1528 ;; XEmacs does it like this. For Emacs, we have to set the
1529 ;; `font-lock-defaults' buffer-local variable.
1530 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
1532 (defvar message-face-alist
1533 '((bold . bold-region)
1534 (underline . underline-region)
1535 (default . (lambda (b e)
1537 (ununderline-region b e))))
1538 "Alist of mail and news faces for facemenu.
1539 The cdr of each entry is a function for applying the face to a region.")
1541 (defcustom message-send-hook nil
1542 "Hook run before sending messages.
1543 This hook is run quite early when sending."
1544 :group 'message-various
1545 :options '(ispell-message)
1546 :link '(custom-manual "(message)Various Message Variables")
1549 (defcustom message-send-mail-hook nil
1550 "Hook run before sending mail messages.
1551 This hook is run very late -- just before the message is sent as
1553 :group 'message-various
1554 :link '(custom-manual "(message)Various Message Variables")
1557 (defcustom message-send-news-hook nil
1558 "Hook run before sending news messages.
1559 This hook is run very late -- just before the message is sent as
1561 :group 'message-various
1562 :link '(custom-manual "(message)Various Message Variables")
1565 (defcustom message-sent-hook nil
1566 "Hook run after sending messages."
1567 :group 'message-various
1570 (defcustom message-use-multi-frames nil
1571 "Make new frame when sending messages."
1572 :group 'message-frames
1575 (defcustom message-delete-frame-on-exit nil
1576 "Delete frame after sending messages."
1577 :group 'message-frames
1578 :type '(choice (const :tag "off" nil)
1579 (const :tag "always" t)
1580 (const :tag "ask" ask)))
1582 (defvar message-draft-coding-system
1583 nnheader-auto-save-coding-system
1584 "*Coding system to compose mail.
1585 If you'd like to make it possible to share draft files between XEmacs
1586 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1587 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1589 (defcustom message-send-mail-partially-limit 1000000
1590 "The limitation of messages sent as message/partial.
1591 The lower bound of message size in characters, beyond which the message
1592 should be sent in several parts. If it is nil, the size is unlimited."
1594 :group 'message-buffers
1595 :link '(custom-manual "(message)Mail Variables")
1596 :type '(choice (const :tag "unlimited" nil)
1599 (defcustom message-alternative-emails nil
1600 "A regexp to match the alternative email addresses.
1601 The first matched address (not primary one) is used in the From field."
1602 :group 'message-headers
1603 :link '(custom-manual "(message)Message Headers")
1604 :type '(choice (const :tag "Always use primary" nil)
1607 (defcustom message-hierarchical-addresses nil
1608 "A list of hierarchical mail address definitions.
1610 Inside each entry, the first address is the \"top\" address, and
1611 subsequent addresses are subaddresses; this is used to indicate that
1612 mail sent to the first address will automatically be delivered to the
1613 subaddresses. So if the first address appears in the recipient list
1614 for a message, the subaddresses will be removed (if present) before
1615 the mail is sent. All addresses in this structure should be
1618 :group 'message-headers
1619 :type '(repeat (repeat string)))
1621 (defcustom message-mail-user-agent nil
1622 "Like `mail-user-agent'.
1623 Except if it is nil, use Gnus native MUA; if it is t, use
1626 :type '(radio (const :tag "Gnus native"
1629 (const :tag "`mail-user-agent'"
1632 (function-item :tag "Default Emacs mail"
1634 sendmail-user-agent)
1635 (function-item :tag "Emacs interface to MH"
1638 (function :tag "Other"))
1642 (defcustom message-wide-reply-confirm-recipients nil
1643 "Whether to confirm a wide reply to multiple email recipients.
1644 If this variable is nil, don't ask whether to reply to all recipients.
1645 If this variable is non-nil, pose the question \"Reply to all
1646 recipients?\" before a wide reply to multiple recipients. If the user
1647 answers yes, reply to all recipients as usual. If the user answers
1648 no, only reply back to the author."
1650 :group 'message-headers
1651 :link '(custom-manual "(message)Wide Reply")
1654 (defcustom message-user-fqdn nil
1655 "*Domain part of Messsage-Ids."
1657 :group 'message-headers
1658 :link '(custom-manual "(message)News Headers")
1659 :type '(radio (const :format "%v " nil)
1660 (string :format "FQDN: %v")))
1662 (defcustom message-use-idna (and (condition-case nil (require 'idna)
1664 (mm-coding-system-p 'utf-8)
1665 (executable-find idna-program)
1667 "Whether to encode non-ASCII in domain names into ASCII according to IDNA."
1669 :group 'message-headers
1670 :link '(custom-manual "(message)IDNA")
1671 :type '(choice (const :tag "Ask" ask)
1672 (const :tag "Never" nil)
1673 (const :tag "Always" t)))
1675 (defcustom message-generate-hashcash nil
1676 "*Whether to generate X-Hashcash: headers.
1677 You must have the \"hashcash\" binary installed, see `hashcash-path'."
1678 :group 'message-headers
1679 :link '(custom-manual "(message)Mail Headers")
1682 ;;; Internal variables.
1684 (defvar message-sending-message "Sending...")
1685 (defvar message-buffer-list nil)
1686 (defvar message-this-is-news nil)
1687 (defvar message-this-is-mail nil)
1688 (defvar message-draft-article nil)
1689 (defvar message-mime-part nil)
1690 (defvar message-posting-charset nil)
1691 (defvar message-inserted-headers nil)
1693 ;; Byte-compiler warning
1695 (defvar gnus-active-hashtb)
1696 (defvar gnus-read-active-file))
1698 ;;; Regexp matching the delimiter of messages in UNIX mail format
1699 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1700 ;;; of rmail.el's rmail-unix-mail-delimiter.
1701 (defvar message-unix-mail-delimiter
1702 (let ((time-zone-regexp
1703 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1704 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1710 ;; Many things can happen to an RFC 822 mailbox before it is put into
1711 ;; a `From' line. The leading phrase can be stripped, e.g.
1712 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1713 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1714 ;; can be removed, e.g.
1715 ;; From: joe@y.z (Joe K
1717 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1720 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1721 ;; The mailbox can be removed or be replaced by white space, e.g.
1722 ;; From: "Joe User"{space}{tab}
1724 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1725 ;; where {space} and {tab} represent the Ascii space and tab characters.
1726 ;; We want to match the results of any of these manglings.
1727 ;; The following regexp rejects names whose first characters are
1728 ;; obviously bogus, but after that anything goes.
1729 "\\([^\0-\b\n-\r\^?].*\\)?"
1731 ;; The time the message was sent.
1732 "\\([^\0-\r \^?]+\\) +" ; day of the week
1733 "\\([^\0-\r \^?]+\\) +" ; month
1734 "\\([0-3]?[0-9]\\) +" ; day of month
1735 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1737 ;; Perhaps a time zone, specified by an abbreviation, or by a
1742 " \\([0-9][0-9]+\\) *"
1744 ;; On some systems the time zone can appear after the year, too.
1748 "\\(remote from .*\\)?"
1751 "Regexp matching the delimiter of messages in UNIX mail format.")
1753 (defvar message-unsent-separator
1754 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1755 "^ *---+ +Returned message +---+ *$\\|"
1756 "^Start of returned message$\\|"
1757 "^ *---+ +Original message +---+ *$\\|"
1758 "^ *--+ +begin message +--+ *$\\|"
1759 "^ *---+ +Original message follows +---+ *$\\|"
1760 "^ *---+ +Undelivered message follows +---+ *$\\|"
1761 "^|? *---+ +Message text follows: +---+ *|?$")
1762 "A regexp that matches the separator before the text of a failed message.")
1764 (defvar message-field-fillers
1765 '((To message-fill-field-address)
1766 (Cc message-fill-field-address)
1767 (From message-fill-field-address))
1768 "Alist of header names/filler functions.")
1770 (defvar message-header-format-alist
1785 (References . message-shorten-references)
1787 "Alist used for formatting headers.")
1789 (defvar message-options nil
1790 "Some saved answers when sending message.")
1792 (defvar message-send-mail-real-function nil
1793 "Internal send mail function.")
1795 (defvar message-bogus-system-names "^localhost\\."
1796 "The regexp of bogus system names.")
1798 (defcustom message-valid-fqdn-regexp
1799 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1801 "\\([a-z][a-z]" ;; two letter country TDLs
1802 "\\|biz\\|com\\|edu\\|gov\\|int\\|mil\\|net\\|org"
1803 "\\|aero\\|coop\\|info\\|name\\|museum"
1804 "\\|arpa\\|pro\\|uucp\\|bitnet\\|bofh" ;; old style?
1806 "Regular expression that matches a valid FQDN."
1807 ;; see also: gnus-button-valid-fqdn-regexp
1809 :group 'message-headers
1813 (autoload 'gnus-alive-p "gnus-util")
1814 (autoload 'gnus-delay-article "gnus-delay")
1815 (autoload 'gnus-extract-address-components "gnus-util")
1816 (autoload 'gnus-find-method-for-group "gnus")
1817 (autoload 'gnus-group-decoded-name "gnus-group")
1818 (autoload 'gnus-group-name-charset "gnus-group")
1819 (autoload 'gnus-group-name-decode "gnus-group")
1820 (autoload 'gnus-groups-from-server "gnus")
1821 (autoload 'gnus-make-local-hook "gnus-util")
1822 (autoload 'gnus-open-server "gnus-int")
1823 (autoload 'gnus-output-to-mail "gnus-util")
1824 (autoload 'gnus-output-to-rmail "gnus-util")
1825 (autoload 'gnus-request-post "gnus-int")
1826 (autoload 'gnus-server-string "gnus")
1827 (autoload 'idna-to-ascii "idna")
1828 (autoload 'message-setup-toolbar "messagexmas")
1829 (autoload 'mh-new-draft-name "mh-comp")
1830 (autoload 'mh-send-letter "mh-comp")
1831 (autoload 'mu-cite-original "mu-cite")
1832 (autoload 'nndraft-request-associate-buffer "nndraft")
1833 (autoload 'nndraft-request-expire-articles "nndraft")
1834 (autoload 'nnvirtual-find-group-art "nnvirtual")
1835 (autoload 'rmail-dont-reply-to "mail-utils")
1836 (autoload 'rmail-msg-is-pruned "rmail")
1837 (autoload 'rmail-msg-restore-non-pruned-header "rmail")
1838 (autoload 'rmail-output "rmailout"))
1843 ;;; Utility functions.
1845 (defun message-eval-parameter (parameter)
1847 (if (symbolp parameter)
1848 (if (functionp parameter)
1854 (defsubst message-get-parameter (key &optional alist)
1856 (setq alist message-parameter-alist))
1857 (cdr (assq key alist)))
1859 (defmacro message-get-parameter-with-eval (key &optional alist)
1860 `(message-eval-parameter (message-get-parameter ,key ,alist)))
1862 (defmacro message-y-or-n-p (question show &rest text)
1863 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1864 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1866 (defmacro message-delete-line (&optional n)
1867 "Delete the current line (and the next N lines)."
1868 `(delete-region (progn (beginning-of-line) (point))
1869 (progn (forward-line ,(or n 1)) (point))))
1871 (defun message-mark-active-p ()
1872 "Non-nil means the mark and region are currently active in this buffer."
1875 (defun message-unquote-tokens (elems)
1876 "Remove double quotes (\") from strings in list ELEMS."
1877 (mapcar (lambda (item)
1878 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1879 (setq item (concat (match-string 1 item)
1880 (match-string 2 item))))
1884 (defun message-tokenize-header (header &optional separator)
1885 "Split HEADER into a list of header elements.
1886 SEPARATOR is a string of characters to be used as separators. \",\"
1887 is used by default."
1890 (let ((regexp (format "[%s]+" (or separator ",")))
1892 beg quoted elems paren)
1894 (set-buffer-multibyte t)
1895 (setq beg (point-min))
1897 (goto-char (point-min))
1902 (cond ((and (> (point) beg)
1904 (and (looking-at regexp)
1907 (push (buffer-substring beg (point)) elems)
1908 (setq beg (match-end 0)))
1909 ((eq (char-after) ?\")
1910 (setq quoted (not quoted)))
1911 ((and (eq (char-after) ?\()
1914 ((and (eq (char-after) ?\))
1917 (nreverse elems)))))
1919 (defun message-mail-file-mbox-p (file)
1920 "Say whether FILE looks like a Unix mbox file."
1921 (when (and (file-exists-p file)
1922 (file-readable-p file)
1923 (file-regular-p file))
1925 (nnheader-insert-file-contents file)
1926 (goto-char (point-min))
1927 (looking-at message-unix-mail-delimiter))))
1929 (defun message-fetch-field (header &optional not-all)
1930 "The same as `mail-fetch-field', only remove all newlines.
1931 The buffer is expected to be narrowed to just the header of the message;
1932 see `message-narrow-to-headers-or-head'."
1933 (let* ((inhibit-point-motion-hooks t)
1934 (value (mail-fetch-field header nil (not not-all))))
1936 (while (string-match "\n[\t ]+" value)
1937 (setq value (replace-match " " t t value)))
1940 (defun message-field-value (header &optional not-all)
1941 "The same as `message-fetch-field', only narrow to the headers first."
1944 (message-narrow-to-headers-or-head)
1945 (message-fetch-field header not-all))))
1947 (defun message-narrow-to-field ()
1948 "Narrow the buffer to the header on the current line."
1950 (while (looking-at "[ \t]")
1956 (if (re-search-forward "^[^ \n\t]" nil t)
1959 (goto-char (point-min)))
1961 (defun message-add-header (&rest headers)
1962 "Add the HEADERS to the message header, skipping those already present."
1965 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1966 (error "Invalid header `%s'" (car headers)))
1967 (setq hclean (match-string 1 (car headers)))
1969 (message-narrow-to-headers)
1970 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1971 (goto-char (point-max))
1972 (if (string-match "\n$" (car headers))
1973 (insert (car headers))
1974 (insert (car headers) ?\n)))))
1975 (setq headers (cdr headers))))
1977 (defmacro message-with-reply-buffer (&rest forms)
1978 "Evaluate FORMS in the reply buffer, if it exists."
1979 `(let ((buffer (message-eval-parameter message-reply-buffer)))
1981 (buffer-name buffer))
1986 (put 'message-with-reply-buffer 'lisp-indent-function 0)
1987 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
1989 (defun message-fetch-reply-field (header)
1990 "Fetch field HEADER from the message we're replying to."
1991 (message-with-reply-buffer
1993 (mail-narrow-to-head)
1994 (message-fetch-field header))))
1996 (defun message-strip-list-identifiers (subject)
1997 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1998 (require 'gnus-sum) ; for gnus-list-identifiers
1999 (let ((regexp (if (stringp gnus-list-identifiers)
2000 gnus-list-identifiers
2001 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
2002 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
2003 " *\\)\\)+\\(Re: +\\)?\\)") subject)
2004 (concat (substring subject 0 (match-beginning 1))
2005 (or (match-string 3 subject)
2006 (match-string 5 subject))
2011 (defun message-strip-subject-re (subject)
2012 "Remove \"Re:\" from subject lines in string SUBJECT."
2013 (if (string-match message-subject-re-regexp subject)
2014 (substring subject (match-end 0))
2017 ;;; Start of functions adopted from `message-utils.el'.
2019 (defun message-strip-subject-trailing-was (subject)
2020 "Remove trailing \"(Was: <old subject>)\" from SUBJECT lines.
2021 Leading \"Re: \" is not stripped by this function. Use the function
2022 `message-strip-subject-re' for this."
2023 (let* ((query message-subject-trailing-was-query)
2028 message-subject-trailing-was-ask-regexp
2029 message-subject-trailing-was-regexp)
2032 (setq new (substring subject 0 (match-beginning 0))))
2033 (if (or (not found) (eq query nil))
2036 (if (message-y-or-n-p
2037 "Strip `(was: <old subject>)' in subject? " t
2039 "Strip `(was: <old subject>)' in subject "
2040 "and use the new one instead?\n\n"
2041 "Current subject is: \""
2043 "New subject would be: \""
2045 "See the variable `message-subject-trailing-was-query' "
2046 "to get rid of this query."
2051 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
2054 (defun message-change-subject (new-subject)
2055 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
2056 ;; <URL:http://www.landfield.com/usefor/drafts/draft-ietf-usefor-useage--1.02.unpaged>
2059 (read-from-minibuffer "New subject: ")))
2060 (cond ((and (not (or (null new-subject) ; new subject not empty
2061 (zerop (string-width new-subject))
2062 (string-match "^[ \t]*$" new-subject))))
2066 (message-narrow-to-headers)
2067 (message-fetch-field "Subject"))))
2068 (cond ((not old-subject)
2069 (error "No current subject"))
2072 (regexp-quote new-subject)
2074 old-subject)) ; yes, it really is a new subject
2075 ;; delete eventual Re: prefix
2077 (message-strip-subject-re old-subject))
2078 (message-goto-subject)
2079 (message-delete-line)
2080 (insert (concat "Subject: "
2083 old-subject ")\n")))))))))
2086 (defun message-mark-inserted-region (beg end)
2087 "Mark some region in the current article with enclosing tags.
2088 See `message-mark-insert-begin' and `message-mark-insert-end'."
2091 ;; add to the end of the region first, otherwise end would be invalid
2093 (insert message-mark-insert-end)
2095 (insert message-mark-insert-begin)))
2098 (defun message-mark-insert-file (file)
2099 "Insert FILE at point, marking it with enclosing tags.
2100 See `message-mark-insert-begin' and `message-mark-insert-end'."
2101 (interactive "fFile to insert: ")
2102 ;; reverse insertion to get correct result.
2104 (insert message-mark-insert-end)
2106 (insert-file-contents file)
2108 (insert message-mark-insert-begin)))
2111 (defun message-add-archive-header ()
2112 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
2113 The note can be customized using `message-archive-note'. When called with a
2114 prefix argument, ask for a text to insert. If you don't want the note in the
2115 body, set `message-archive-note' to nil."
2117 (if current-prefix-arg
2118 (setq message-archive-note
2119 (read-from-minibuffer "Reason for No-Archive: "
2120 (cons message-archive-note 0))))
2122 (if (message-goto-signature)
2123 (re-search-backward message-signature-separator))
2124 (when message-archive-note
2125 (insert message-archive-note)
2127 (message-add-header message-archive-header)
2128 (message-sort-headers)))
2131 (defun message-cross-post-followup-to-header (target-group)
2132 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
2133 With prefix-argument just set Follow-Up, don't cross-post."
2135 (list ; Completion based on Gnus
2136 (completing-read "Followup To: "
2137 (if (boundp 'gnus-newsrc-alist)
2139 nil nil '("poster" . 0)
2140 (if (boundp 'gnus-group-history)
2141 'gnus-group-history))))
2142 (message-remove-header "Follow[Uu]p-[Tt]o" t)
2143 (message-goto-newsgroups)
2145 ;; if we already did a crosspost before, kill old target
2146 (if (and message-cross-post-old-target
2148 (regexp-quote (concat "," message-cross-post-old-target))
2151 ;; unless (followup is to poster or user explicitly asked not
2152 ;; to cross-post, or target-group is already in Newsgroups)
2153 ;; add target-group to Newsgroups line.
2155 ;; def: cross-post, req:no
2156 (and message-cross-post-default (not current-prefix-arg))
2157 ;; def: no-cross-post, req:yes
2158 (and (not message-cross-post-default) current-prefix-arg))
2159 (not (string-match "poster" target-group))
2160 (not (string-match (regexp-quote target-group)
2161 (message-fetch-field "Newsgroups"))))
2163 (insert (concat "," target-group))))
2164 (end-of-line) ; ensure Followup: comes after Newsgroups:
2165 ;; unless new followup would be identical to Newsgroups line
2166 ;; make a new Followup-To line
2167 (if (not (string-match (concat "^[ \t]*"
2170 (message-fetch-field "Newsgroups")))
2171 (insert (concat "\nFollowup-To: " target-group)))
2172 (setq message-cross-post-old-target target-group))
2175 (defun message-cross-post-insert-note (target-group cross-post in-old
2177 "Insert a in message body note about a set Followup or Crosspost.
2178 If there have been previous notes, delete them. TARGET-GROUP specifies the
2179 group to Followup-To. When CROSS-POST is t, insert note about
2180 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
2181 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
2182 been made to before the user asked for a Crosspost."
2183 ;; start scanning body for previous uses
2184 (message-goto-signature)
2185 (let ((head (re-search-backward
2186 (concat "^" mail-header-separator)
2187 nil t))) ; just search in body
2188 (message-goto-signature)
2189 (while (re-search-backward
2190 (concat "^" (regexp-quote message-cross-post-note) ".*")
2192 (message-delete-line))
2193 (message-goto-signature)
2194 (while (re-search-backward
2195 (concat "^" (regexp-quote message-followup-to-note) ".*")
2197 (message-delete-line))
2199 (if (message-goto-signature)
2200 (re-search-backward message-signature-separator))
2203 (string-match "^[ \t]*poster[ \t]*$" target-group))
2204 (insert (concat message-followup-to-note target-group "\n"))
2205 (insert (concat message-cross-post-note target-group "\n")))))
2208 (defun message-cross-post-followup-to (target-group)
2209 "Crossposts message and set Followup-To to TARGET-GROUP.
2210 With prefix-argument just set Follow-Up, don't cross-post."
2212 (list ; Completion based on Gnus
2213 (completing-read "Followup To: "
2214 (if (boundp 'gnus-newsrc-alist)
2216 nil nil '("poster" . 0)
2217 (if (boundp 'gnus-group-history)
2218 'gnus-group-history))))
2219 (cond ((not (or (null target-group) ; new subject not empty
2220 (zerop (string-width target-group))
2221 (string-match "^[ \t]*$" target-group)))
2223 (let* ((old-groups (message-fetch-field "Newsgroups"))
2224 (in-old (string-match
2225 (regexp-quote target-group)
2226 (or old-groups ""))))
2227 ;; check whether target exactly matches old Newsgroups
2228 (cond ((not old-groups)
2229 (error "No current newsgroup"))
2233 (regexp-quote target-group)
2236 ;; yes, Newsgroups line must change
2237 (message-cross-post-followup-to-header target-group)
2238 ;; insert note whether we do cross-post or followup-to
2239 (funcall message-cross-post-note-function
2241 (if (or (and message-cross-post-default
2242 (not current-prefix-arg))
2243 (and (not message-cross-post-default)
2244 current-prefix-arg)) t)
2245 in-old old-groups))))))))
2247 ;;; Reduce To: to Cc: or Bcc: header
2250 (defun message-reduce-to-to-cc ()
2251 "Replace contents of To: header with contents of Cc: or Bcc: header."
2254 (save-restriction (message-narrow-to-headers)
2255 (message-fetch-field "cc")))
2257 (if (and (not cc-content)
2260 (message-narrow-to-headers)
2261 (message-fetch-field "bcc"))))
2266 (message-delete-line)
2267 (insert (concat "To: " cc-content "\n"))
2269 (message-narrow-to-headers)
2270 (message-remove-header (if bcc
2274 ;;; End of functions adopted from `message-utils.el'.
2276 (defun message-remove-header (header &optional is-regexp first reverse)
2277 "Remove HEADER in the narrowed buffer.
2278 If IS-REGEXP, HEADER is a regular expression.
2279 If FIRST, only remove the first instance of the header.
2280 Return the number of headers removed."
2281 (goto-char (point-min))
2282 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
2284 (case-fold-search t)
2286 (while (and (not (eobp))
2289 (not (looking-at regexp))
2290 (looking-at regexp))
2297 ;; There might be a continuation header, so we have to search
2298 ;; until we find a new non-continuation line.
2301 (if (re-search-forward "^[^ \t]" nil t)
2302 (goto-char (match-beginning 0))
2305 (if (re-search-forward "^[^ \t]" nil t)
2306 (goto-char (match-beginning 0))
2307 (goto-char (point-max)))))
2310 (defun message-remove-first-header (header)
2311 "Remove the first instance of HEADER if there is more than one."
2313 (regexp (concat "^" (regexp-quote header) ":")))
2315 (goto-char (point-min))
2316 (while (re-search-forward regexp nil t)
2319 (message-remove-header header nil t)
2322 (defun message-narrow-to-headers ()
2323 "Narrow the buffer to the head of the message."
2326 (goto-char (point-min))
2327 (if (re-search-forward
2328 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2331 (goto-char (point-min)))
2333 (defun message-narrow-to-head-1 ()
2334 "Like `message-narrow-to-head'. Don't widen."
2336 (goto-char (point-min))
2337 (if (search-forward "\n\n" nil 1)
2340 (goto-char (point-min)))
2342 (defun message-narrow-to-head ()
2343 "Narrow the buffer to the head of the message.
2344 Point is left at the beginning of the narrowed-to region."
2346 (message-narrow-to-head-1))
2348 (defun message-narrow-to-headers-or-head ()
2349 "Narrow the buffer to the head of the message."
2352 (goto-char (point-min))
2355 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2356 (match-beginning 0))
2357 ((search-forward "\n\n" nil t)
2361 (goto-char (point-min)))
2363 (defun message-news-p ()
2364 "Say whether the current buffer contains a news message."
2365 (and (not message-this-is-mail)
2366 (or message-this-is-news
2369 (message-narrow-to-headers)
2370 (and (message-fetch-field "newsgroups")
2371 (not (message-fetch-field "posted-to"))))))))
2373 (defun message-mail-p ()
2374 "Say whether the current buffer contains a mail message."
2375 (and (not message-this-is-news)
2376 (or message-this-is-mail
2379 (message-narrow-to-headers)
2380 (or (message-fetch-field "to")
2381 (message-fetch-field "cc")
2382 (message-fetch-field "bcc")))))))
2384 (defun message-subscribed-p ()
2385 "Say whether we need to insert a MFT header."
2386 (or message-subscribed-regexps
2387 message-subscribed-addresses
2388 message-subscribed-address-file
2389 message-subscribed-address-functions))
2391 (defun message-next-header ()
2392 "Go to the beginning of the next header."
2394 (or (eobp) (forward-char 1))
2395 (not (if (re-search-forward "^[^ \t]" nil t)
2397 (goto-char (point-max)))))
2399 (defun message-sort-headers-1 ()
2400 "Sort the buffer as headers using `message-rank' text props."
2401 (goto-char (point-min))
2404 nil 'message-next-header
2406 (message-next-header)
2410 (or (get-text-property (point) 'message-rank)
2413 (defun message-sort-headers ()
2414 "Sort the headers of the current message according to `message-header-format-alist'."
2418 (let ((max (1+ (length message-header-format-alist)))
2420 (message-narrow-to-headers)
2421 (while (re-search-forward "^[^ \n]+:" nil t)
2423 (match-beginning 0) (1+ (match-beginning 0))
2425 (if (setq rank (length (memq (assq (intern (buffer-substring
2427 (1- (match-end 0))))
2428 message-header-format-alist)
2429 message-header-format-alist)))
2432 (message-sort-headers-1))))
2434 (defun message-kill-address ()
2435 "Kill the address under point."
2437 (let ((start (point)))
2438 (message-skip-to-next-address)
2439 (kill-region start (point))))
2449 (defvar message-mode-map nil)
2451 (unless message-mode-map
2452 (setq message-mode-map (make-keymap))
2453 (set-keymap-parent message-mode-map text-mode-map)
2454 (define-key message-mode-map "\C-c?" 'describe-mode)
2456 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
2457 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
2458 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
2459 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
2460 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
2461 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2462 ;; (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2463 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-mail-reply-to)
2464 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2465 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2466 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2467 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2468 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2469 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2470 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2471 (define-key message-mode-map "\C-c\C-f\C-i"
2472 'message-insert-or-toggle-importance)
2473 (define-key message-mode-map "\C-c\C-f\C-a"
2474 'message-generate-unsubscribed-mail-followup-to)
2476 ;; modify headers (and insert notes in body)
2477 (define-key message-mode-map "\C-c\C-fs" 'message-change-subject)
2479 (define-key message-mode-map "\C-c\C-fx" 'message-cross-post-followup-to)
2480 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2481 (define-key message-mode-map "\C-c\C-ft" 'message-reduce-to-to-cc)
2482 (define-key message-mode-map "\C-c\C-fa" 'message-add-archive-header)
2483 ;; mark inserted text
2484 (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2485 (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2487 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2488 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2489 (define-key message-mode-map "\C-c\C-fc" 'message-goto-mail-copies-to)
2491 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2492 (define-key message-mode-map "\C-c\C-fw" 'message-insert-wide-reply)
2493 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2494 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2496 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2497 (define-key message-mode-map "\C-c\M-n"
2498 'message-insert-disposition-notification-to)
2500 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2501 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2502 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2503 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2504 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2505 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2506 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2507 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2509 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2510 (define-key message-mode-map "\C-c\C-s" 'message-send)
2511 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2512 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2513 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2515 (define-key message-mode-map "\C-c\M-k" 'message-kill-address)
2516 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2517 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2518 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2519 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2520 (define-key message-mode-map [remap split-line] 'message-split-line)
2522 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2523 (define-key message-mode-map "\t" 'message-tab)
2524 (define-key message-mode-map "\M-;" 'comment-region)
2526 (define-key message-mode-map "\C-xk" 'message-mimic-kill-buffer))
2529 message-mode-menu message-mode-map "Message Menu."
2531 ["Yank Original" message-yank-original t]
2532 ["Fill Yanked Message" message-fill-yanked-message t]
2533 ["Insert Signature" message-insert-signature t]
2534 ["Caesar (rot13) Message" message-caesar-buffer-body t]
2535 ["Caesar (rot13) Region" message-caesar-region (message-mark-active-p)]
2536 ["Elide Region" message-elide-region
2537 :active (message-mark-active-p)
2538 ,@(if (featurep 'xemacs) nil
2539 '(:help "Replace text in region with an ellipsis"))]
2540 ["Delete Outside Region" message-delete-not-region
2541 :active (message-mark-active-p)
2542 ,@(if (featurep 'xemacs) nil
2543 '(:help "Delete all quoted text outside region"))]
2544 ["Kill To Signature" message-kill-to-signature t]
2545 ["Newline and Reformat" message-newline-and-reformat t]
2546 ["Rename buffer" message-rename-buffer t]
2547 ["Spellcheck" ispell-message
2548 ,@(if (featurep 'xemacs) '(t)
2549 '(:help "Spellcheck this message"))]
2550 ["Attach file as MIME" mime-edit-insert-file
2551 ,@(if (featurep 'xemacs) '(t)
2552 '(:help "Attach a file at point"))]
2554 ["Insert Region Marked" message-mark-inserted-region
2555 :active (message-mark-active-p)
2556 ,@(if (featurep 'xemacs) nil
2557 '(:help "Mark region with enclosing tags"))]
2558 ["Insert File Marked..." message-mark-insert-file
2559 ,@(if (featurep 'xemacs) '(t)
2560 '(:help "Insert file at point marked with enclosing tags"))]
2562 ["Send Message" message-send-and-exit
2563 ,@(if (featurep 'xemacs) '(t)
2564 '(:help "Send this message"))]
2565 ["Postpone Message" message-dont-send
2566 ,@(if (featurep 'xemacs) '(t)
2567 '(:help "File this draft message and exit"))]
2568 ["Send at Specific Time..." gnus-delay-article
2569 ,@(if (featurep 'xemacs) '(t)
2570 '(:help "Ask, then arrange to send message at that time"))]
2571 ["Kill Message" message-kill-buffer
2572 ,@(if (featurep 'xemacs) '(t)
2573 '(:help "Delete this message without sending"))]))
2576 message-mode-field-menu message-mode-map ""
2578 ["To" message-goto-to t]
2579 ["From" message-goto-from t]
2580 ["Subject" message-goto-subject t]
2581 ["Change subject..." message-change-subject t]
2582 ["Cc" message-goto-cc t]
2583 ["Bcc" message-goto-bcc t]
2584 ["Fcc" message-goto-fcc t]
2585 ["Reply-To" message-goto-reply-to t]
2586 ["Flag As Important" message-insert-importance-high
2587 ,@(if (featurep 'xemacs) '(t)
2588 '(:help "Mark this message as important"))]
2589 ["Flag As Unimportant" message-insert-importance-low
2590 ,@(if (featurep 'xemacs) '(t)
2591 '(:help "Mark this message as unimportant"))]
2593 message-insert-disposition-notification-to
2594 ,@(if (featurep 'xemacs) '(t)
2595 '(:help "Request a receipt notification"))]
2597 ;; (typical) news stuff
2598 ["Summary" message-goto-summary t]
2599 ["Keywords" message-goto-keywords t]
2600 ["Newsgroups" message-goto-newsgroups t]
2601 ["Fetch Newsgroups" message-insert-newsgroups t]
2602 ["Followup-To" message-goto-followup-to t]
2603 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2604 ["Crosspost / Followup-To..." message-cross-post-followup-to t]
2605 ["Distribution" message-goto-distribution t]
2606 ["X-No-Archive:" message-add-archive-header t ]
2608 ;; (typical) mailing-lists stuff
2609 ["Fetch To" message-insert-to
2610 ,@(if (featurep 'xemacs) '(t)
2611 '(:help "Insert a To header that points to the author."))]
2612 ["Fetch To and Cc" message-insert-wide-reply
2613 ,@(if (featurep 'xemacs) '(t)
2615 "Insert To and Cc headers as if you were doing a wide reply."))]
2617 ["Send to list only" message-to-list-only t]
2618 ["Mail-Followup-To" message-goto-mail-followup-to t]
2619 ["Mail-Reply-To" message-goto-mail-reply-to t]
2620 ["Mail-Copies-To" message-goto-mail-copies-to t]
2621 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2622 ,@(if (featurep 'xemacs) '(t)
2623 '(:help "Insert a reasonable `Mail-Followup-To:' header."))]
2624 ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2626 ["Sort Headers" message-sort-headers t]
2627 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t]
2628 ["Goto Body" message-goto-body t]
2629 ["Goto Signature" message-goto-signature t]))
2631 (defvar message-tool-bar-map nil)
2634 (defvar facemenu-add-face-function)
2635 (defvar facemenu-remove-face-function))
2637 ;;; Forbidden properties
2639 ;; We use `after-change-functions' to keep special text properties
2640 ;; that interfer with the normal function of message mode out of the
2643 (defcustom message-strip-special-text-properties t
2644 "Strip special properties from the message buffer.
2646 Emacs has a number of special text properties which can break message
2647 composing in various ways. If this option is set, message will strip
2648 these properties from the message composition buffer. However, some
2649 packages requires these properties to be present in order to work.
2650 If you use one of these packages, turn this option off, and hope the
2651 message composition doesn't break too bad."
2653 :group 'message-various
2654 :link '(custom-manual "(message)Various Message Variables")
2657 (defconst message-forbidden-properties
2658 ;; No reason this should be clutter up customize. We make it a
2659 ;; property list (rather than a list of property symbols), to be
2660 ;; directly useful for `remove-text-properties'.
2661 '(field nil read-only nil invisible nil intangible nil
2662 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2663 insert-behind-hooks nil point-entered nil point-left nil)
2664 ;; Other special properties:
2665 ;; category, face, display: probably doesn't do any harm.
2666 ;; fontified: is used by font-lock.
2667 ;; syntax-table, local-map: I dunno.
2668 ;; We need to add XEmacs names to the list.
2669 "Property list of with properties forbidden in message buffers.
2670 The values of the properties are ignored, only the property names are used.")
2672 (defun message-tamago-not-in-use-p (pos)
2673 "Return t when tamago version 4 is not in use at the cursor position.
2674 Tamago version 4 is a popular input method for writing Japanese text.
2675 It uses the properties `intangible', `invisible', `modification-hooks'
2676 and `read-only' when translating ascii or kana text to kanji text.
2677 These properties are essential to work, so we should never strip them."
2678 (not (and (boundp 'egg-modefull-mode)
2679 (symbol-value 'egg-modefull-mode)
2680 (or (memq (get-text-property pos 'intangible)
2681 '(its-part-1 its-part-2))
2682 (get-text-property pos 'egg-end)
2683 (get-text-property pos 'egg-lang)
2684 (get-text-property pos 'egg-start)))))
2686 (defun message-strip-forbidden-properties (begin end &optional old-length)
2687 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2688 This function is intended to be called from `after-change-functions'.
2689 See also `message-forbidden-properties'."
2690 (when (and message-strip-special-text-properties
2691 (message-tamago-not-in-use-p begin)
2692 ;; Check whether the invisible MIME part is not inserted.
2693 (not (text-property-any begin end 'mime-edit-invisible t)))
2694 (let ((buffer-read-only nil)
2695 (inhibit-read-only t))
2696 (remove-text-properties begin end message-forbidden-properties))))
2699 (define-derived-mode message-mode text-mode "Message"
2700 "Major mode for editing mail and news to be sent.
2701 Like Text Mode but with these additional commands:\\<message-mode-map>
2702 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2703 C-c C-d Postpone sending the message C-c C-k Kill the message
2704 C-c C-f move to a header field (and create it if there isn't):
2705 C-c C-f C-t move to To C-c C-f C-s move to Subject
2706 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2707 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2708 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2709 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2710 C-c C-f C-o move to From (\"Originator\")
2711 C-c C-f C-f move to Followup-To
2712 C-c C-f C-m move to Mail-Followup-To
2713 C-c C-f c move to Mail-Copies-To
2714 C-c C-f C-i cycle through Importance values
2715 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2716 C-c C-f x crossposting with FollowUp-To header and note in body
2717 C-c C-f t replace To: header with contents of Cc: or Bcc:
2718 C-c C-f a Insert X-No-Archive: header and a note in the body
2719 C-c C-t `message-insert-to' (add a To header to a news followup)
2720 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2721 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2722 C-c C-b `message-goto-body' (move to beginning of message text).
2723 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2724 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2725 C-c C-y `message-yank-original' (insert current message, if any).
2726 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2727 C-c C-e `message-elide-region' (elide the text between point and mark).
2728 C-c C-v `message-delete-not-region' (remove the text outside the region).
2729 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2730 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2731 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2732 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2733 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2734 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2735 M-RET `message-newline-and-reformat' (break the line and reformat)."
2736 (setq local-abbrev-table text-mode-abbrev-table)
2737 (set (make-local-variable 'message-reply-buffer) nil)
2738 (set (make-local-variable 'message-inserted-headers) nil)
2739 (set (make-local-variable 'message-send-actions) nil)
2740 (set (make-local-variable 'message-exit-actions) nil)
2741 (set (make-local-variable 'message-kill-actions) nil)
2742 (set (make-local-variable 'message-postpone-actions) nil)
2743 (set (make-local-variable 'message-draft-article) nil)
2744 (setq buffer-offer-save t)
2745 (set (make-local-variable 'facemenu-add-face-function)
2747 (let ((face-fun (cdr (assq face message-face-alist))))
2749 (funcall face-fun (point) end)
2750 (error "Face %s not configured for %s mode" face mode-name)))
2752 (set (make-local-variable 'facemenu-remove-face-function) t)
2753 (set (make-local-variable 'message-reply-headers) nil)
2754 (make-local-variable 'message-user-agent)
2755 (make-local-variable 'message-post-method)
2756 (set (make-local-variable 'message-sent-message-via) nil)
2757 (set (make-local-variable 'message-checksum) nil)
2758 (make-local-variable 'message-parameter-alist)
2759 (setq message-parameter-alist
2760 (copy-sequence message-startup-parameter-alist))
2761 (message-setup-fill-variables)
2762 ;; Allow using comment commands to add/remove quoting.
2763 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2764 (when message-yank-prefix
2765 (set (make-local-variable 'comment-start) message-yank-prefix)
2766 (set (make-local-variable 'comment-start-skip)
2767 (concat "^" (regexp-quote message-yank-prefix) "[ \t]*")))
2768 (if (featurep 'xemacs)
2769 (message-setup-toolbar)
2770 (set (make-local-variable 'font-lock-defaults)
2771 '(message-font-lock-keywords t))
2772 (if (boundp 'tool-bar-map)
2773 (set (make-local-variable 'tool-bar-map) (message-tool-bar-map))))
2774 (easy-menu-add message-mode-menu message-mode-map)
2775 (easy-menu-add message-mode-field-menu message-mode-map)
2776 (gnus-make-local-hook 'after-change-functions)
2777 ;; Mmmm... Forbidden properties...
2778 (add-hook 'after-change-functions 'message-strip-forbidden-properties
2780 ;; Allow mail alias things.
2781 (when (eq message-mail-alias-type 'abbrev)
2782 (if (fboundp 'mail-abbrevs-setup)
2783 (mail-abbrevs-setup)
2784 (if (fboundp 'mail-aliases-setup) ; warning avoidance
2785 (mail-aliases-setup))))
2786 (unless buffer-file-name
2787 (message-set-auto-save-file-name))
2788 (set (make-local-variable 'indent-tabs-mode) nil)) ;No tabs for indentation.
2790 (defun message-setup-fill-variables ()
2791 "Setup message fill variables."
2792 (set (make-local-variable 'fill-paragraph-function)
2793 'message-fill-paragraph)
2794 (make-local-variable 'paragraph-separate)
2795 (make-local-variable 'paragraph-start)
2796 (make-local-variable 'adaptive-fill-regexp)
2797 (unless (boundp 'adaptive-fill-first-line-regexp)
2798 (setq adaptive-fill-first-line-regexp nil))
2799 (make-local-variable 'adaptive-fill-first-line-regexp)
2800 (let ((quote-prefix-regexp
2801 ;; User should change message-cite-prefix-regexp if
2802 ;; message-yank-prefix is set to an abnormal value.
2803 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
2804 (setq paragraph-start
2806 (regexp-quote mail-header-separator) "$\\|"
2807 "[ \t]*$\\|" ; blank lines
2808 "-- $\\|" ; signature delimiter
2809 "---+$\\|" ; delimiters for forwarded messages
2810 page-delimiter "$\\|" ; spoiler warnings
2811 ".*wrote:$\\|" ; attribution lines
2812 quote-prefix-regexp "$\\|" ; empty lines in quoted text
2813 mime-edit-tag-regexp)) ; MIME-Edit tags
2814 (setq paragraph-separate paragraph-start)
2815 (setq adaptive-fill-regexp
2816 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
2817 (setq adaptive-fill-first-line-regexp
2818 (concat quote-prefix-regexp "\\|"
2819 adaptive-fill-first-line-regexp)))
2820 (make-local-variable 'auto-fill-inhibit-regexp)
2821 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2822 (setq auto-fill-inhibit-regexp nil)
2823 (make-local-variable 'normal-auto-fill-function)
2824 (setq normal-auto-fill-function 'message-do-auto-fill)
2825 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2826 ;; In that case, ensure that it uses the right function. The real
2827 ;; solution would be not to use `define-derived-mode', and run
2828 ;; `text-mode-hook' ourself at the end of the mode.
2829 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2830 (when auto-fill-function
2831 (setq auto-fill-function normal-auto-fill-function)))
2836 ;;; Message mode commands
2839 ;;; Movement commands
2841 (defun message-goto-to ()
2842 "Move point to the To header."
2844 (message-position-on-field "To"))
2846 (defun message-goto-from ()
2847 "Move point to the From header."
2849 (message-position-on-field "From"))
2851 (defun message-goto-subject ()
2852 "Move point to the Subject header."
2854 (message-position-on-field "Subject"))
2856 (defun message-goto-cc ()
2857 "Move point to the Cc header."
2859 (message-position-on-field "Cc" "To"))
2861 (defun message-goto-bcc ()
2862 "Move point to the Bcc header."
2864 (message-position-on-field "Bcc" "Cc" "To"))
2866 (defun message-goto-fcc ()
2867 "Move point to the Fcc header."
2869 (message-position-on-field "Fcc" "To" "Newsgroups"))
2871 (defun message-goto-reply-to ()
2872 "Move point to the Reply-To header."
2874 (message-position-on-field "Reply-To" "Subject"))
2876 (defun message-goto-mail-reply-to ()
2877 "Move point to the Mail-Reply-To header."
2879 (message-position-on-field "Mail-Reply-To" "Subject"))
2881 (defun message-goto-mail-copies-to ()
2882 "Move point to the Mail-Copies-To header. If the header is newly created,
2883 a string \"never\" is inserted in default."
2885 (unless (message-position-on-field "Mail-Copies-To" "Subject")
2889 (defun message-goto-newsgroups ()
2890 "Move point to the Newsgroups header."
2892 (message-position-on-field "Newsgroups"))
2894 (defun message-goto-distribution ()
2895 "Move point to the Distribution header."
2897 (message-position-on-field "Distribution"))
2899 (defun message-goto-followup-to ()
2900 "Move point to the Followup-To header."
2902 (message-position-on-field "Followup-To" "Newsgroups"))
2904 (defun message-goto-mail-followup-to ()
2905 "Move point to the Mail-Followup-To header.
2906 If the header is newly created and To field contains only one address,
2907 the address is inserted by default."
2909 (unless (message-position-on-field "Mail-Followup-To" "To")
2910 (let ((start (point))
2913 (message-narrow-to-headers)
2914 (setq addresses (split-string (mail-strip-quoted-names
2915 (or (std11-fetch-field "to") ""))
2917 (when (eq 1 (length addresses))
2919 (insert (car addresses))
2920 (goto-char start))))))
2922 (defun message-goto-keywords ()
2923 "Move point to the Keywords header."
2925 (message-position-on-field "Keywords" "Subject"))
2927 (defun message-goto-summary ()
2928 "Move point to the Summary header."
2930 (message-position-on-field "Summary" "Subject"))
2932 (defun message-goto-body (&optional interactivep)
2933 "Move point to the beginning of the message body."
2934 (interactive (list t))
2935 (when (and interactivep
2936 (looking-at "[ \t]*\n"))
2938 (goto-char (point-min))
2939 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
2940 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
2942 (defun message-goto-eoh ()
2943 "Move point to the end of the headers."
2948 (defun message-goto-signature ()
2949 "Move point to the beginning of the message signature.
2950 If there is no signature in the article, go to the end and
2953 (goto-char (point-min))
2954 (if (re-search-forward message-signature-separator nil t)
2956 (goto-char (point-max))
2959 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc)
2960 "Insert a reasonable MFT header in a post to an unsubscribed list.
2961 When making original posts to a mailing list you are not subscribed to,
2962 you have to type in a MFT header by hand. The contents, usually, are
2963 the addresses of the list and your own address. This function inserts
2964 such a header automatically. It fetches the contents of the To: header
2965 in the current mail buffer, and appends the current `user-mail-address'.
2967 If the optional argument INCLUDE-CC is non-nil, the addresses in the
2968 Cc: header are also put into the MFT."
2973 (message-narrow-to-headers)
2974 (message-remove-header "Mail-Followup-To")
2975 (setq cc (and include-cc (message-fetch-field "Cc")))
2977 (concat (message-fetch-field "To") "," cc)
2978 (message-fetch-field "To"))))
2979 (message-goto-mail-followup-to)
2980 (insert (concat tos ", " user-mail-address))))
2984 (defun message-insert-to (&optional force)
2985 "Insert a To header that points to the author of the article being replied to.
2986 If the original author requested not to be sent mail, don't insert unless the
2987 prefix FORCE is given."
2989 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
2990 (dont (and mct (or (equal (downcase mct) "never")
2991 (equal (downcase mct) "nobody"))))
2992 (to (or (message-fetch-reply-field "mail-reply-to")
2993 (message-fetch-reply-field "reply-to")
2994 (message-fetch-reply-field "from"))))
2998 "Ignoring the user request not to have copies sent via mail"
2999 "Complying with the user request not to have copies sent via mail")))
3000 (when (and force (not to))
3001 (error "No mail address in the article"))
3002 (when (and to (or force (not dont)))
3003 (message-carefully-insert-headers (list (cons 'To to))))))
3005 (defun message-insert-wide-reply ()
3006 "Insert To and Cc headers as if you were doing a wide reply."
3008 (let ((headers (message-with-reply-buffer
3009 (message-get-reply-headers t))))
3010 (message-carefully-insert-headers headers)))
3012 (defcustom message-header-synonyms
3014 "List of lists of header synonyms.
3015 E.g., if this list contains a member list with elements `Cc' and `To',
3016 then `message-carefully-insert-headers' will not insert a `To' header
3017 when the message is already `Cc'ed to the recipient."
3019 :group 'message-headers
3020 :link '(custom-manual "(message)Message Headers")
3021 :type '(repeat sexp))
3023 (defun message-carefully-insert-headers (headers)
3024 "Insert the HEADERS, an alist, into the message buffer.
3025 Does not insert the headers when they are already present there
3026 or in the synonym headers, defined by `message-header-synonyms'."
3027 ;; FIXME: Should compare only the address and not the full name. Comparison
3028 ;; should be done case-folded (and with `string=' rather than
3030 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
3031 (dolist (header headers)
3032 (let* ((header-name (symbol-name (car header)))
3033 (new-header (cdr header))
3034 (synonyms (loop for synonym in message-header-synonyms
3035 when (memq (car header) synonym) return synonym))
3037 (loop for synonym in synonyms
3038 for old-header = (mail-fetch-field (symbol-name synonym))
3039 when (and old-header (string-match new-header old-header))
3042 (message "already have `%s' in `%s'" new-header old-header)
3043 (when (and (message-position-on-field header-name)
3044 (setq old-header (mail-fetch-field header-name))
3045 (not (string-match "\\` *\\'" old-header)))
3047 (insert new-header)))))
3049 (defun message-widen-reply ()
3050 "Widen the reply to include maximum recipients."
3053 (and message-reply-buffer
3054 (buffer-name message-reply-buffer)
3056 (set-buffer message-reply-buffer)
3057 (message-get-reply-headers t)))))
3060 (message-narrow-to-headers)
3061 (dolist (elem follow-to)
3062 (message-remove-header (symbol-name (car elem)))
3063 (goto-char (point-min))
3064 (insert (symbol-name (car elem)) ": "
3065 (cdr elem) "\n"))))))
3067 (defun message-insert-newsgroups ()
3068 "Insert the Newsgroups header from the article being replied to."
3070 (when (and (message-position-on-field "Newsgroups")
3071 (mail-fetch-field "newsgroups")
3072 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
3074 (insert (or (message-fetch-reply-field "newsgroups") "")))
3078 ;;; Various commands
3080 (defun message-delete-not-region (beg end)
3081 "Delete everything in the body of the current message outside of the region."
3086 ;; snarf citation prefix, if appropriate
3087 (unless (eq (point) (progn (beginning-of-line) (point)))
3088 (when (looking-at message-cite-prefix-regexp)
3089 (setq citeprefix (match-string 0))))
3091 (delete-region (point) (if (not (message-goto-signature))
3097 (delete-region beg (progn (message-goto-body)
3101 (insert citeprefix))))
3102 (when (message-goto-signature)
3105 (defun message-kill-to-signature (&optional arg)
3106 "Kill all text up to the signature.
3107 If a numberic argument or prefix arg is given, leave that number
3108 of lines before the signature intact."
3112 (let ((point (point)))
3113 (narrow-to-region point (point-max))
3114 (message-goto-signature)
3116 (if (and arg (numberp arg))
3117 (forward-line (- -1 arg))
3119 (unless (= point (point))
3120 (kill-region point (point))
3123 (defun message-newline-and-reformat (&optional arg not-break)
3124 "Insert four newlines, and then reformat if inside quoted text.
3125 Prefix arg means justify as well."
3126 (interactive (list (if current-prefix-arg 'full)))
3127 (let (quoted point beg end leading-space bolp)
3128 (setq point (point))
3131 (setq bolp (= beg point))
3132 ;; Find first line of the paragraph.
3134 (while (and (not (eobp))
3135 (not (looking-at message-cite-prefix-regexp))
3136 (looking-at paragraph-start))
3139 (when (looking-at message-cite-prefix-regexp)
3140 (setq quoted (match-string 0))
3141 (goto-char (match-end 0))
3142 (looking-at "[ \t]*")
3143 (setq leading-space (match-string 0)))
3147 (< (- point beg) (length quoted)))
3148 ;; break inside the cite prefix.
3154 (while (and (not (eobp))
3155 (not (looking-at paragraph-separate))
3156 (looking-at message-cite-prefix-regexp)
3157 (equal quoted (match-string 0)))
3158 (goto-char (match-end 0))
3159 (looking-at "[ \t]*")
3160 (if (> (length leading-space) (length (match-string 0)))
3161 (setq leading-space (match-string 0)))
3165 (while (and (if (bobp) nil (forward-line -1) t)
3166 (not (looking-at paragraph-start))
3167 (looking-at message-cite-prefix-regexp)
3168 (equal quoted (match-string 0)))
3170 (goto-char (match-end 0))
3171 (looking-at "[ \t]*")
3172 (if (> (length leading-space) (length (match-string 0)))
3173 (setq leading-space (match-string 0)))))
3174 (while (and (not (eobp))
3175 (not (looking-at paragraph-separate))
3176 (not (looking-at message-cite-prefix-regexp)))
3180 (while (and (if (bobp) nil (forward-line -1) t)
3181 (not (looking-at paragraph-start))
3182 (not (looking-at message-cite-prefix-regexp)))
3183 (setq beg (point))))
3186 (narrow-to-region beg end)
3193 (setq point (point))
3194 ;; (newline 2) doesn't mark both newline's as hard, so call
3195 ;; newline twice. -jas
3198 (delete-region (point) (re-search-forward "[ \t]*"))
3199 (when (and quoted (not bolp))
3200 (insert quoted leading-space)))
3203 (let* ((adaptive-fill-regexp
3204 (regexp-quote (concat quoted leading-space)))
3205 (adaptive-fill-first-line-regexp
3206 adaptive-fill-regexp ))
3207 (fill-paragraph arg))
3208 (fill-paragraph arg))
3209 (if point (goto-char point)))))
3211 (defun message-fill-paragraph (&optional arg)
3212 "Like `fill-paragraph'."
3213 (interactive (list (if current-prefix-arg 'full)))
3214 (if (if (boundp 'filladapt-mode) filladapt-mode)
3216 (if (message-point-in-header-p)
3217 (message-fill-field)
3218 (message-newline-and-reformat arg t))
3221 ;; Is it better to use `mail-header-end'?
3222 (defun message-point-in-header-p ()
3223 "Return t if point is in the header."
3226 (goto-char (point-min))
3227 (not (re-search-forward
3228 (concat "^" (regexp-quote mail-header-separator) "\n")
3231 (defun message-do-auto-fill ()
3232 "Like `do-auto-fill', but don't fill in message header."
3233 (unless (message-point-in-header-p)
3236 (defun message-insert-signature (&optional force)
3237 "Insert a signature. See documentation for variable `message-signature'."
3238 (interactive (list 0))
3241 ((and (null message-signature)
3244 (goto-char (point-max))
3245 (not (re-search-backward message-signature-separator nil t))))
3246 ((and (null message-signature)
3249 ((functionp message-signature)
3250 (funcall message-signature))
3251 ((listp message-signature)
3252 (eval message-signature))
3253 (t message-signature)))
3255 (cond ((stringp signature)
3257 ((and (eq t signature)
3258 message-signature-file
3259 (file-exists-p message-signature-file))
3262 (goto-char (point-max))
3263 ;; Insert the signature.
3266 (when message-signature-insert-empty-line
3268 (insert "\n" message-signature-separator-for-insertion)
3271 (if (eq signature t)
3272 (insert-file-contents message-signature-file)
3274 (goto-char (point-max))
3275 (or (bolp) (insert "\n")))))
3277 (defun message-insert-importance-high ()
3278 "Insert header to mark message as important."
3282 (message-narrow-to-headers)
3283 (message-remove-header "Importance"))
3285 (insert "Importance: high\n")))
3287 (defun message-insert-importance-low ()
3288 "Insert header to mark message as unimportant."
3292 (message-narrow-to-headers)
3293 (message-remove-header "Importance"))
3295 (insert "Importance: low\n")))
3297 (defun message-insert-or-toggle-importance ()
3298 "Insert a \"Importance: high\" header, or cycle through the header values.
3299 The three allowed values according to RFC 1327 are `high', `normal'
3303 (let ((valid '("high" "normal" "low"))
3307 (message-narrow-to-headers)
3308 (when (setq cur (message-fetch-field "Importance"))
3309 (message-remove-header "Importance")
3310 (setq new (cond ((string= cur "high")
3312 ((string= cur "low")
3317 (insert (format "Importance: %s\n" new)))))
3319 (defun message-insert-disposition-notification-to ()
3320 "Request a disposition notification (return receipt) to this message.
3321 Note that this should not be used in newsgroups."
3325 (message-narrow-to-headers)
3326 (message-remove-header "Disposition-Notification-To"))
3328 (insert (format "Disposition-Notification-To: %s\n"
3329 (or (message-field-value "Reply-to")
3330 (message-field-value "From")
3331 (message-make-from))))))
3333 (defun message-elide-region (b e)
3334 "Elide the text in the region.
3335 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3339 (insert message-elide-ellipsis))
3341 (defvar message-caesar-translation-table nil)
3343 (defun message-caesar-region (b e &optional n)
3344 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3347 (min (point) (or (mark t) (point)))
3348 (max (point) (or (mark t) (point)))
3349 (when current-prefix-arg
3350 (prefix-numeric-value current-prefix-arg))))
3352 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
3353 (unless (or (zerop n) ; no action needed for a rot of 0
3354 (= b e)) ; no region to rotate
3355 ;; We build the table, if necessary.
3356 (when (or (not message-caesar-translation-table)
3357 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
3358 (setq message-caesar-translation-table
3359 (message-make-caesar-translation-table n)))
3360 (translate-region b e message-caesar-translation-table)))
3362 (defun message-make-caesar-translation-table (n)
3363 "Create a rot table with offset N."
3365 (table (make-string 256 0)))
3366 (while (< (incf i) 256)
3369 (substring table 0 ?A)
3370 (substring table (+ ?A n) (+ ?A n (- 26 n)))
3371 (substring table ?A (+ ?A n))
3372 (substring table (+ ?A 26) ?a)
3373 (substring table (+ ?a n) (+ ?a n (- 26 n)))
3374 (substring table ?a (+ ?a n))
3375 (substring table (+ ?a 26) 255))))
3377 (defun message-caesar-buffer-body (&optional rotnum)
3378 "Caesar rotate all letters in the current buffer by 13 places.
3379 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3380 With prefix arg, specifies the number of places to rotate each letter forward.
3381 Mail and USENET news headers are not rotated."
3382 (interactive (if current-prefix-arg
3383 (list (prefix-numeric-value current-prefix-arg))
3387 (when (message-goto-body)
3388 (narrow-to-region (point) (point-max)))
3389 (message-caesar-region (point-min) (point-max) rotnum))))
3391 (defun message-pipe-buffer-body (program)
3392 "Pipe the message body in the current buffer through PROGRAM."
3395 (when (message-goto-body)
3396 (narrow-to-region (point) (point-max)))
3397 (shell-command-on-region
3398 (point-min) (point-max) program nil t))))
3400 (defun message-rename-buffer (&optional enter-string)
3401 "Rename the *message* buffer to \"*message* RECIPIENT\".
3402 If the function is run with a prefix, it will ask for a new buffer
3403 name, rather than giving an automatic name."
3404 (interactive "Pbuffer name: ")
3407 (goto-char (point-min))
3408 (narrow-to-region (point)
3409 (search-forward mail-header-separator nil 'end))
3411 (if (message-news-p) (message-fetch-field "Newsgroups")
3412 (message-fetch-field "To"))
3415 (if (string-match "," mail-to)
3416 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
3418 (name-default (concat "*message* " mail-trimmed-to))
3419 (name (if enter-string
3420 (read-string "New buffer name: " name-default)
3422 (rename-buffer name t)))))
3424 (defun message-fill-yanked-message (&optional justifyp)
3425 "Fill the paragraphs of a message yanked into this one.
3426 Numeric argument means justify as well."
3429 (goto-char (point-min))
3430 (search-forward (concat "\n" mail-header-separator "\n") nil t)
3431 (let ((fill-prefix message-yank-prefix))
3432 (fill-individual-paragraphs (point) (point-max) justifyp))))
3434 (defun message-indent-citation ()
3435 "Modify text just inserted from a message to be cited.
3436 The inserted text should be the region.
3437 When this function returns, the region is again around the modified text.
3439 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3440 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3441 (let ((start (point)))
3442 ;; Remove unwanted headers.
3443 (when message-ignored-cited-headers
3448 (if (search-forward "\n\n" nil t)
3451 (message-remove-header message-ignored-cited-headers t)
3452 (when (= (point-min) (point-max))
3453 (setq all-removed t))
3454 (goto-char (point-max)))
3458 ;; Delete blank lines at the start of the buffer.
3459 (while (and (point-min)
3462 (message-delete-line))
3463 ;; Delete blank lines at the end of the buffer.
3464 (goto-char (point-max))
3467 (while (and (zerop (forward-line -1))
3469 (message-delete-line))
3470 ;; Do the indentation.
3471 (if (null message-yank-prefix)
3472 (indent-rigidly start (mark t) message-indentation-spaces)
3475 (while (< (point) (mark t))
3476 (if (or (looking-at ">") (looking-at "^$"))
3477 (insert message-yank-cited-prefix)
3478 (insert message-yank-prefix))
3482 (defun message-list-references (refs-list &rest refs-strs)
3483 "Add `Message-ID's which appear in REFS-STRS but not in REFS-LIST,
3485 (let (refs ref id saved-id)
3486 (when (and refs-list
3487 (integerp message-list-references-add-position))
3488 (let ((pos message-list-references-add-position))
3489 (while (and refs-list
3491 (push (pop refs-list) saved-id)
3492 (setq pos (1- pos)))))
3494 (when (setq refs (pop refs-strs))
3495 (setq refs (std11-parse-msg-ids (std11-lexical-analyze refs)))
3497 (when (eq (car (setq ref (pop refs))) 'msg-id)
3498 (setq id (concat "<" (mapconcat 'cdr (cdr ref) "") ">"))
3499 (or (member id refs-list)
3500 (member id saved-id)
3501 (push id refs-list))))))
3503 (push (pop saved-id) refs-list))
3506 (defun message-yank-original (&optional arg)
3507 "Insert the message being replied to, if any.
3508 Puts point before the text and mark after.
3509 Normally indents each nonblank line ARG spaces (default 3). However,
3510 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3512 This function uses `message-cite-function' to do the actual citing.
3514 Just \\[universal-argument] as argument means don't indent, insert no
3515 prefix, and don't delete any headers.
3517 In addition, if `message-yank-add-new-references' is non-nil and this
3518 command is called interactively, new IDs from the yanked article will
3519 be added to the \"References\" field."
3521 (let ((modified (buffer-modified-p)))
3522 (when (let ((buffer (message-eval-parameter message-reply-buffer)))
3524 message-cite-function
3527 (delete-windows-on buffer t)
3528 ; The mark will be set at the end of the article.
3529 (insert-buffer buffer))))
3530 ;; Add new IDs to the References field.
3531 (when (and message-yank-add-new-references
3533 (let ((start (point))
3539 (setq refs (message-list-references
3541 (or (message-make-references)
3543 (message-narrow-to-headers)
3544 (message-fetch-field "References")
3546 (narrow-to-region start end)
3547 (std11-narrow-to-header)
3548 (unless (equal (setq newrefs
3549 (message-list-references
3550 (copy-sequence refs)
3551 (unless (eq message-yank-add-new-references
3553 (or (message-fetch-field "References")
3554 (message-fetch-field "In-Reply-To")))
3555 (message-fetch-field "Message-ID")))
3557 ;; If the References field has been changed, we make it
3558 ;; visible in the header.
3559 (when message-reply-headers
3560 (mail-header-set-message-id message-reply-headers nil)
3561 (mail-header-set-references message-reply-headers nil))
3563 (message-narrow-to-headers)
3564 (if (let ((case-fold-search t))
3565 (re-search-forward "^References:\\([\t ]+.+\n\\)+"
3568 (goto-char (point-max)))
3570 (list (or (assq 'References message-header-format-alist)
3571 '(References . message-fill-references)))
3572 (list (cons 'References (mapconcat 'identity
3573 (nreverse newrefs) " "))))
3574 (backward-delete-char 1))))))
3576 (if (and message-suspend-font-lock-when-citing
3577 (boundp 'font-lock-mode)
3578 (symbol-value 'font-lock-mode))
3583 (funcall message-cite-function))
3585 (funcall message-cite-function)))
3586 (message-exchange-point-and-mark)
3590 (setq message-checksum (message-checksum))))))
3592 (defun message-yank-buffer (buffer)
3593 "Insert BUFFER into the current buffer and quote it."
3594 (interactive "bYank buffer: ")
3595 (let ((message-reply-buffer (get-buffer buffer)))
3596 (save-window-excursion
3597 (message-yank-original))))
3599 (defun message-buffers ()
3600 "Return a list of active message buffers."
3603 (dolist (buffer (buffer-list t))
3605 (when (and (eq major-mode 'message-mode)
3606 (null message-sent-message-via))
3607 (push (buffer-name buffer) buffers))))
3608 (nreverse buffers)))
3610 (defun message-cite-original-without-signature ()
3611 "Cite function in the standard Message manner."
3612 (let ((start (point))
3615 (when message-indent-citation-function
3616 (if (listp message-indent-citation-function)
3617 message-indent-citation-function
3618 (list message-indent-citation-function))))
3619 (message-reply-headers (or message-reply-headers
3620 (make-mail-header))))
3621 (mail-header-set-from message-reply-headers
3625 (if (search-forward "\n\n" nil t)
3628 (or (message-fetch-field "from")
3633 (when (re-search-backward message-signature-separator start t)
3634 ;; Also peel off any blank lines before the signature.
3636 (while (looking-at "^[ \t]*$")
3639 (delete-region (point) end)
3640 (unless (search-backward "\n\n" start t)
3641 ;; Insert a blank line if it is peeled off.
3644 (mapc 'funcall functions)
3645 (when message-citation-line-function
3648 (funcall message-citation-line-function))))
3650 (eval-when-compile (defvar mail-citation-hook)) ;Compiler directive
3651 (defun message-cite-original ()
3652 "Cite function in the standard Message manner."
3653 (if (and (boundp 'mail-citation-hook)
3655 (run-hooks 'mail-citation-hook)
3656 (let ((start (point))
3660 (when message-indent-citation-function
3661 (if (listp message-indent-citation-function)
3662 message-indent-citation-function
3663 (list message-indent-citation-function))))
3664 (message-reply-headers (or message-reply-headers
3665 (make-mail-header))))
3667 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
3670 (mail-header-set-from message-reply-headers
3671 (or (message-fetch-field "from")
3673 (setq x-no-archive (message-fetch-field "x-no-archive")))
3675 (mapc 'funcall functions)
3676 (when message-citation-line-function
3679 (funcall message-citation-line-function))
3680 (when (and x-no-archive
3681 (not message-cite-articles-with-x-no-archive)
3682 (string-match "yes" x-no-archive))
3684 (delete-region (point) (mark t))
3685 (insert "> [Quoted text removed due to X-No-Archive]\n")
3686 (forward-line -1)))))
3688 (defun message-insert-citation-line ()
3689 "Insert a simple citation line."
3690 (when message-reply-headers
3691 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
3693 (defun message-position-on-field (header &rest afters)
3694 (let ((case-fold-search t))
3697 (goto-char (point-min))
3700 (concat "^" (regexp-quote mail-header-separator) "$"))
3701 (match-beginning 0)))
3702 (goto-char (point-min))
3703 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
3705 (re-search-forward "^[^ \t]" nil 'move)
3707 (skip-chars-backward "\n")
3710 (not (re-search-forward
3711 (concat "^" (regexp-quote (car afters)) ":")
3715 (re-search-forward "^[^ \t]" nil 'move)
3716 (beginning-of-line))
3717 (insert header ": \n")
3721 (defun message-remove-signature ()
3722 "Remove the signature from the text between point and mark.
3723 The text will also be indented the normal way."
3725 (let ((start (point))
3727 (if (not (re-search-forward message-signature-separator (mark t) t))
3728 ;; No signature here, so we just indent the cited text.
3729 (message-indent-citation)
3730 ;; Find the last non-empty line.
3732 (while (looking-at "[ \t]*$")
3735 (setq mark (set-marker (make-marker) (point)))
3737 (message-indent-citation)
3738 ;; Enable undoing the deletion.
3740 (delete-region mark (mark t))
3741 (set-marker mark nil)))))
3746 ;;; Sending messages
3749 ;; Avoid byte-compile warning.
3750 (defvar message-encoding-buffer nil)
3751 (defvar message-edit-buffer nil)
3752 (defvar message-mime-mode nil)
3754 (defun message-send-and-exit (&optional arg)
3755 "Send message like `message-send', then, if no errors, exit from mail buffer."
3757 (let ((buf (current-buffer))
3758 (actions message-exit-actions)
3759 (frame (selected-frame))
3760 (org-frame message-original-frame))
3761 (when (and (message-send arg)
3763 (if message-kill-buffer-on-exit
3766 (when (eq buf (current-buffer))
3767 (message-bury buf)))
3768 (message-do-actions actions)
3769 (message-delete-frame frame org-frame)
3772 (defun message-dont-send ()
3773 "Don't send the message you have been editing.
3774 Instead, just auto-save the buffer and then bury it."
3776 (set-buffer-modified-p t)
3778 (let ((actions message-postpone-actions)
3779 (frame (selected-frame))
3780 (org-frame message-original-frame))
3781 (message-bury (current-buffer))
3782 (message-do-actions actions)
3783 (message-delete-frame frame org-frame)))
3785 (defun message-kill-buffer ()
3786 "Kill the current buffer."
3788 (when (or (not (buffer-modified-p))
3789 (eq t message-kill-buffer-query-function)
3790 (funcall message-kill-buffer-query-function
3791 "The buffer modified; kill anyway? "))
3792 (let ((actions message-kill-actions)
3793 (draft-article message-draft-article)
3794 (auto-save-file-name buffer-auto-save-file-name)
3795 (file-name buffer-file-name)
3796 (modified (buffer-modified-p))
3797 (frame (selected-frame))
3798 (org-frame message-original-frame))
3799 (setq buffer-file-name nil)
3800 (kill-buffer (current-buffer))
3801 (when (and message-kill-buffer-and-remove-file
3802 (or (and auto-save-file-name
3803 (file-exists-p auto-save-file-name))
3805 (file-exists-p file-name)))
3807 ;; If the message buffer has lived in a dedicated window,
3808 ;; `kill-buffer' has killed the frame. Thus the
3809 ;; `yes-or-no-p' may show up in a lowered frame. Make sure
3810 ;; that the user can see the question by raising the
3813 (yes-or-no-p (format "Remove the backup file%s? "
3814 (if modified " too" "")))))
3816 (delete-file auto-save-file-name))
3817 (let ((message-draft-article draft-article))
3818 (message-disassociate-draft)))
3819 (message-do-actions actions)
3820 (message-delete-frame frame org-frame)))
3823 (defun message-mimic-kill-buffer ()
3824 "Kill the current buffer with query. This is an imitation for
3825 `kill-buffer', but it will delete a message frame."
3827 (let ((bufname (read-buffer (format "Kill buffer: (default %s) "
3829 message-kill-buffer-and-remove-file)
3830 (when (or (not bufname)
3831 (string-equal bufname "")
3832 (string-equal bufname (buffer-name)))
3833 (message-kill-buffer))))
3835 (defun message-delete-frame (frame org-frame)
3836 "Delete frame for editing message."
3837 (when (and (static-if (featurep 'xemacs)
3838 (device-on-window-system-p)
3840 (or (and (eq message-delete-frame-on-exit t)
3841 (select-frame frame)
3842 (or (eq frame org-frame)
3844 (y-or-n-p "Delete this frame?")
3846 (and (eq message-delete-frame-on-exit 'ask)
3847 (select-frame frame)
3849 (y-or-n-p "Delete this frame?")
3851 (delete-frame frame)))
3853 (defun message-bury (buffer)
3854 "Bury this mail BUFFER."
3855 (let ((newbuf (other-buffer buffer)))
3856 (bury-buffer buffer)
3857 (if (and (window-dedicated-p (selected-window))
3858 (not (null (delq (selected-frame) (visible-frame-list)))))
3859 (delete-frame (selected-frame))
3860 (switch-to-buffer newbuf))))
3862 (defun message-send (&optional arg)
3863 "Send the message in the current buffer.
3864 If `message-interactive' is non-nil, wait for success indication or
3865 error messages, and inform user.
3866 Otherwise any failure is reported in a message back to the user from
3868 The usage of ARG is defined by the instance that called Message.
3869 It should typically alter the sending method in some way or other."
3872 (when (or (buffer-modified-p)
3873 (message-check-element 'unchanged)
3874 (y-or-n-p "No changes in the buffer; really send? "))
3875 ;; Make it possible to undo the coming changes.
3877 (let ((inhibit-read-only t))
3878 (put-text-property (point-min) (point-max) 'read-only nil))
3879 (run-hooks 'message-send-hook)
3880 (message-fix-before-sending)
3881 (message message-sending-message)
3882 (let ((message-encoding-buffer
3883 (message-generate-new-buffer-clone-locals " message encoding"))
3884 (message-edit-buffer (current-buffer))
3885 (message-mime-mode mime-edit-mode-flag)
3886 (alist message-send-method-alist)
3888 elem sent dont-barf-on-no-method
3889 (message-options message-options))
3892 (message-options-set-recipient)
3894 (set-buffer message-encoding-buffer)
3896 ;; ;; Avoid copying text props (except hard newlines).
3897 ;; T-gnus change: copy all text props from the editing buffer
3898 ;; into the encoding buffer.
3899 (insert-buffer-substring message-edit-buffer)
3900 (funcall message-encode-function)
3902 (setq elem (pop alist)))
3903 (when (funcall (cadr elem))
3905 (or (not (memq (car elem)
3906 message-sent-message-via))
3907 (message-fetch-field "supersedes")
3908 (if (or (message-gnksa-enable-p 'multiple-copies)
3909 (not (eq (car elem) 'news)))
3912 "Already sent message via %s; resend? "
3914 (error "Denied posting -- multiple copies")))
3915 (setq success (funcall (caddr elem) arg)))
3921 (let ((fcc (message-fetch-field "Fcc"))
3922 (gcc (message-fetch-field "Gcc")))
3925 (eq message-allow-no-recipients 'always)
3926 (and (not (eq message-allow-no-recipients 'never))
3927 (setq dont-barf-on-no-method
3929 (format "No receiver, perform %s anyway? "
3930 (cond ((and fcc gcc) "Fcc and Gcc")
3933 (error "No methods specified to send by"))
3934 (when (or dont-barf-on-no-method
3938 (run-hooks 'message-sent-hook))
3939 (message "Sending...done")
3940 ;; Mark the buffer as unmodified and delete auto-save.
3941 (set-buffer-modified-p nil)
3942 (delete-auto-save-file-if-necessary t)
3943 (message-disassociate-draft)
3944 ;; Delete other mail buffers and stuff.
3945 (message-do-send-housekeeping)
3946 (message-do-actions message-send-actions)
3949 (kill-buffer message-encoding-buffer)))))
3951 (defun message-send-via-mail (arg)
3952 "Send the current message via mail."
3953 (message-send-mail arg))
3955 (defun message-send-via-news (arg)
3956 "Send the current message via news."
3957 (message-send-news arg))
3959 (defmacro message-check (type &rest forms)
3960 "Eval FORMS if TYPE is to be checked."
3961 `(or (message-check-element ,type)
3965 (put 'message-check 'lisp-indent-function 1)
3966 (put 'message-check 'edebug-form-spec '(form body))
3968 ;; Advise the function `invisible-region'.
3969 (unless noninteractive
3970 (let (current-load-list)
3972 `(defadvice invisible-region (around add-mime-edit-invisible (start end)
3974 "Advised by T-gnus Message.
3975 Add the text property `mime-edit-invisible' to an invisible text when
3976 the buffer's major mode is `message-mode'. The added property will be
3977 used to distinguish whether the invisible text is a MIME part or not."
3978 ,(if (featurep 'xemacs)
3979 '(if (eq ?\n (char-after start))
3980 (setq start (1+ start)))
3981 '(if (eq ?\n (char-after (1- end)))
3982 (setq end (1- end))))
3983 (setq ad-return-value
3984 (if (eq 'message-mode major-mode)
3985 (add-text-properties start end
3986 '(invisible t mime-edit-invisible t))
3987 (put-text-property start end 'invisible t)))))))
3989 (defun message-text-with-property (prop &optional start end reverse)
3990 "Return a list of start and end positions where the text has PROP.
3991 START and END bound the search, they default to `point-min' and
3992 `point-max' respectively. If REVERSE is non-nil, find text which does
3995 (setq start (point-min)))
3997 (setq end (point-max)))
4001 (setq start (text-property-any start end prop nil)))
4002 (setq next (next-single-property-change start prop nil end))
4003 (push (cons start (or next end)) regions)
4006 (or (get-text-property start prop)
4007 (and (setq start (next-single-property-change
4008 start prop nil end))
4009 (get-text-property start prop))))
4010 (setq next (text-property-any start end prop nil))
4011 (push (cons start (or next end)) regions)
4013 (nreverse regions)))
4015 (defun message-fix-before-sending ()
4016 "Do various things to make the message nice before sending it."
4017 ;; Make sure there's a newline at the end of the message.
4019 (goto-char (point-max))
4022 ;; Make the hidden headers visible.
4024 ;; Sort headers before sending the message.
4025 (message-sort-headers)
4026 ;; Make invisible text visible except for mime parts which may be
4027 ;; inserted by the MIME-Edit.
4028 ;; It doesn't seem as if this is useful, since the invisible property
4029 ;; is clobbered by an after-change hook anyhow.
4030 (message-check 'invisible-text
4031 ;; FIXME T-gnus: It should also detect invisible overlays.
4034 mime-from mime-to hidden-start)
4035 (while (setq from (text-property-any to (point-max) 'invisible t))
4036 (setq to (or (text-property-not-all from (point-max) 'invisible t)
4039 (while (setq mime-from (text-property-any mime-to to
4040 'mime-edit-invisible t))
4041 (when (> mime-from mime-to)
4042 (setq hidden-start (or hidden-start mime-to))
4043 (add-text-properties mime-to mime-from
4044 '(invisible nil face highlight
4045 font-lock-face highlight)))
4046 (setq mime-to (or (text-property-not-all mime-from to
4047 'mime-edit-invisible t)
4049 (when (< mime-to to)
4050 (setq hidden-start (or hidden-start mime-to))
4051 (add-text-properties mime-to to
4052 '(invisible nil face highlight
4053 font-lock-face highlight))))
4055 (goto-char hidden-start)
4056 (set-window-start (selected-window) (point-at-bol))
4057 (unless (yes-or-no-p
4058 "Invisible text found and made visible; continue sending? ")
4059 (error "Invisible text found and made visible")))))
4060 ;; The following check is needless to T-gnus since T-gnus determines
4061 ;; a MIME charset forcibly (even if it cannot be determined properly,
4062 ;; the value of the `default-mime-charset-for-write' variable is used).
4063 ;; (message-check 'illegible-text
4064 ;; (let (found choice)
4065 ;; (message-goto-body)
4066 ;; (skip-chars-forward mm-7bit-chars)
4067 ;; (while (not (eobp))
4068 ;; (when (let ((char (char-after)))
4069 ;; (or (< (mm-char-int char) 128)
4070 ;; (and (mm-multibyte-p)
4071 ;; (memq (char-charset char)
4072 ;; '(eight-bit-control eight-bit-graphic
4074 ;; (not (get-text-property
4075 ;; (point) 'untranslated-utf-8)))))
4076 ;; (message-overlay-put (message-make-overlay (point) (1+ (point)))
4077 ;; 'face 'highlight)
4080 ;; (skip-chars-forward mm-7bit-chars))
4083 ;; (gnus-multiple-choice
4084 ;; "Non-printable characters found. Continue sending?"
4085 ;; '((?d "Remove non-printable characters and send")
4086 ;; (?r "Replace non-printable characters with dots and send")
4087 ;; (?i "Ignore non-printable characters and send")
4088 ;; (?e "Continue editing"))))
4089 ;; (if (eq choice ?e)
4090 ;; (error "Non-printable characters"))
4091 ;; (message-goto-body)
4092 ;; (skip-chars-forward mm-7bit-chars)
4093 ;; (while (not (eobp))
4094 ;; (when (let ((char (char-after)))
4095 ;; (or (< (mm-char-int char) 128)
4096 ;; (and (mm-multibyte-p)
4097 ;; ;; Fixme: Wrong for Emacs 22 and for things
4098 ;; ;; like undecable utf-8. Should at least
4099 ;; ;; use find-coding-systems-region.
4100 ;; (memq (char-charset char)
4101 ;; '(eight-bit-control eight-bit-graphic
4103 ;; (not (get-text-property
4104 ;; (point) 'untranslated-utf-8)))))
4105 ;; (if (eq choice ?i)
4106 ;; (message-kill-all-overlays)
4108 ;; (when (eq choice ?r)
4111 ;; (skip-chars-forward mm-7bit-chars)))))
4114 (defun message-add-action (action &rest types)
4115 "Add ACTION to be performed when doing an exit of type TYPES."
4117 (add-to-list (intern (format "message-%s-actions" (pop types)))
4120 (defun message-delete-action (action &rest types)
4121 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
4124 (set (setq var (intern (format "message-%s-actions" (pop types))))
4125 (delq action (symbol-value var))))))
4127 (defun message-do-actions (actions)
4128 "Perform all actions in ACTIONS."
4129 ;; Now perform actions on successful sending.
4130 (dolist (action actions)
4133 ;; A simple function.
4136 ;; Something to be evaled.
4140 (defsubst message-maybe-split-and-send-mail ()
4141 "Split a message if necessary, and send it via mail.
4142 Returns nil if sending succeeded, returns any string if sending failed.
4143 This sub function is for exclusive use of `message-send-mail'."
4144 (let ((mime-edit-split-ignored-field-regexp
4145 mime-edit-split-ignored-field-regexp)
4146 (case-fold-search t)
4148 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
4149 (setq mime-edit-split-ignored-field-regexp
4150 (concat (substring mime-edit-split-ignored-field-regexp
4151 0 (match-beginning 0))
4152 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
4153 "_so_don't_rape_it!"
4154 (substring mime-edit-split-ignored-field-regexp
4158 (catch 'message-sending-mail-failure
4159 (mime-edit-maybe-split-and-send
4164 (std11-narrow-to-header mail-header-separator)
4165 (goto-char (point-min))
4166 (when (re-search-forward "^Message-ID:" nil t)
4167 (delete-region (match-end 0) (std11-field-end))
4168 (insert " " (message-make-message-id))))
4170 (funcall (or message-send-mail-real-function
4171 message-send-mail-function))
4173 (throw 'message-sending-mail-failure err))))))
4177 (funcall (or message-send-mail-real-function
4178 message-send-mail-function))
4182 (if (eq 'error (car failure))
4184 (prin1-to-string failure)))))
4186 (defun message-send-mail-partially ()
4187 "Send mail as message/partial."
4188 ;; replace the header delimiter with a blank line
4189 (goto-char (point-min))
4191 (concat "^" (regexp-quote mail-header-separator) "\n"))
4192 (replace-match "\n")
4193 (run-hooks 'message-send-mail-hook)
4194 (let ((p (goto-char (point-min)))
4195 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
4196 (curbuf (current-buffer))
4197 (id (message-make-message-id)) (n 1)
4198 plist total header required-mail-headers)
4200 (if (< (point-max) (+ p message-send-mail-partially-limit))
4201 (goto-char (point-max))
4202 (goto-char (+ p message-send-mail-partially-limit))
4204 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
4207 (setq total (length plist))
4208 (push (point-max) plist)
4209 (setq plist (nreverse plist))
4212 (setq p (pop plist))
4215 (copy-to-buffer tembuf p (car plist))
4217 (goto-char (point-min))
4220 (goto-char (point-min))
4221 (narrow-to-region (point) (point))
4224 (setq header (buffer-substring (point-min) (point)))
4225 (goto-char (point-min))
4226 (narrow-to-region (point) (point))
4228 (message-remove-header "Mime-Version")
4229 (message-remove-header "Content-Type")
4230 (message-remove-header "Content-Transfer-Encoding")
4231 (message-remove-header "Message-ID")
4232 (message-remove-header "Lines")
4233 (goto-char (point-max))
4234 (insert "Mime-Version: 1.0\n")
4235 (setq header (buffer-string)))
4236 (goto-char (point-max))
4237 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
4240 (let ((mail-header-separator ""))
4241 (when (memq 'Message-ID message-required-mail-headers)
4242 (insert "Message-ID: " (message-make-message-id) "\n"))
4243 (when (memq 'Lines message-required-mail-headers)
4244 (insert "Lines: " (message-make-lines) "\n"))
4245 (message-goto-subject)
4247 (insert (format " (%d/%d)" n total))
4249 (mm-with-unibyte-current-buffer
4250 (funcall (or message-send-mail-real-function
4251 message-send-mail-function))))
4253 (setq p (pop plist))
4255 (kill-buffer tembuf))))
4257 (defun message-send-mail (&optional arg)
4258 (require 'mail-utils)
4259 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
4260 (case-fold-search nil)
4261 (news (message-news-p))
4262 (message-this-is-mail t)
4263 (headers message-required-mail-headers)
4265 (when message-generate-hashcash
4266 (message "Generating hashcash...")
4267 ;; Wait for calculations already started to finish...
4268 (hashcash-wait-async)
4269 ;; ...and do calculations not already done. mail-add-payment
4270 ;; will leave existing X-Hashcash headers alone.
4272 (message "Generating hashcash...done"))
4274 (message-narrow-to-headers)
4275 ;; Generate the Mail-Followup-To header if the header is not there...
4276 (if (and (message-subscribed-p)
4277 (not (mail-fetch-field "mail-followup-to")))
4280 (cons "Mail-Followup-To" (message-make-mail-followup-to))
4281 message-required-mail-headers))
4282 ;; otherwise, delete the MFT header if the field is empty
4283 (when (equal "" (mail-fetch-field "mail-followup-to"))
4284 (message-remove-header "^Mail-Followup-To:")))
4285 ;; Insert some headers.
4286 (let ((message-deletable-headers
4287 (if news nil message-deletable-headers)))
4288 (message-generate-headers headers))
4289 ;; Let the user do all of the above.
4290 (run-hooks 'message-header-hook))
4291 (if (not (message-check-mail-syntax))
4299 ;; ;; Avoid copying text props (except hard newlines).
4300 ;; T-gnus change: copy all text props from the editing buffer
4301 ;; into the encoding buffer.
4302 (insert-buffer-substring message-encoding-buffer)
4303 ;; Remove some headers.
4305 (message-narrow-to-headers)
4306 ;; We Semi-gnus people have no use for it.
4307 ;; ;; We (re)generate the Lines header.
4308 ;; (when (memq 'Lines message-required-mail-headers)
4309 ;; (message-generate-headers '(Lines)))
4310 (message-remove-header message-ignored-mail-headers t))
4311 (goto-char (point-max))
4312 ;; require one newline at the end.
4313 (or (= (preceding-char) ?\n)
4315 (message-cleanup-headers)
4316 ;; FIXME: we're inserting the courtesy copy after encoding.
4317 ;; This is wrong if the courtesy copy string contains
4318 ;; non-ASCII characters. -- jh
4321 (message-narrow-to-headers)
4323 (or (message-fetch-field "cc")
4324 (message-fetch-field "bcc")
4325 (message-fetch-field "to"))
4326 (let ((content-type (mime-read-Content-Type)))
4331 (eq 'text (cdr (assq 'type content-type)))
4332 (eq 'plain (cdr (assq 'subtype content-type)))))
4335 (mime-read-Content-Transfer-Encoding)))))))
4336 (message-insert-courtesy-copy))
4337 (setq failure (message-maybe-split-and-send-mail)))
4338 (kill-buffer tembuf))
4339 (set-buffer message-edit-buffer)
4342 (message "Couldn't send message via mail: %s" failure)
4344 (push 'mail message-sent-message-via)))))
4346 (defun message-send-mail-with-sendmail ()
4347 "Send off the prepared buffer with sendmail."
4348 (let ((errbuf (if message-interactive
4349 (message-generate-new-buffer-clone-locals
4352 resend-to-addresses delimline)
4355 (let ((case-fold-search t))
4357 (message-narrow-to-headers)
4358 (setq resend-to-addresses (message-fetch-field "resent-to")))
4359 ;; Change header-delimiter to be what sendmail expects.
4360 (goto-char (point-min))
4362 (concat "^" (regexp-quote mail-header-separator) "\n"))
4363 (replace-match "\n")
4365 (setq delimline (point-marker))
4366 (run-hooks 'message-send-mail-hook)
4367 ;; Insert an extra newline if we need it to work around
4368 ;; Sun's bug that swallows newlines.
4369 (goto-char (1+ delimline))
4370 (when (eval message-mailer-swallows-blank-line)
4372 (when message-interactive
4373 (with-current-buffer errbuf
4375 (let* ((default-directory "/")
4376 (cpr (as-binary-process
4378 'call-process-region
4380 (list (point-min) (point-max)
4381 (if (boundp 'sendmail-program)
4383 "/usr/lib/sendmail")
4384 nil errbuf nil "-oi")
4385 ;; Always specify who from,
4386 ;; since some systems have broken sendmails.
4387 ;; But some systems are more broken with -f, so
4388 ;; we'll let users override this.
4389 (if (null message-sendmail-f-is-evil)
4390 (list "-f" (message-sendmail-envelope-from)))
4391 ;; These mean "report errors by mail"
4392 ;; and "deliver in background".
4393 (if (null message-interactive) '("-oem" "-odb"))
4394 ;; Get the addresses from the message
4395 ;; unless this is a resend.
4396 ;; We must not do that for a resend
4397 ;; because we would find the original addresses.
4398 ;; For a resend, include the specific addresses.
4399 (if resend-to-addresses
4400 (list resend-to-addresses)
4402 (unless (or (null cpr) (and (numberp cpr) (zerop cpr)))
4403 (error "Sending...failed with exit value %d" cpr)))
4404 (when message-interactive
4407 (goto-char (point-min))
4408 (while (re-search-forward "\n+ *" nil t)
4409 (replace-match "; "))
4410 (if (not (zerop (buffer-size)))
4411 (error "Sending...failed to %s"
4412 (buffer-string))))))
4413 (when (bufferp errbuf)
4414 (kill-buffer errbuf)))))
4416 (defun message-send-mail-with-qmail ()
4417 "Pass the prepared message buffer to qmail-inject.
4418 Refer to the documentation for the variable `message-send-mail-function'
4419 to find out how to use this."
4420 ;; replace the header delimiter with a blank line
4421 (goto-char (point-min))
4423 (concat "^" (regexp-quote mail-header-separator) "\n"))
4424 (replace-match "\n")
4426 (run-hooks 'message-send-mail-hook)
4431 'call-process-region (point-min) (point-max)
4432 message-qmail-inject-program nil nil nil
4433 ;; qmail-inject's default behaviour is to look for addresses on the
4434 ;; command line; if there're none, it scans the headers.
4435 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4437 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4438 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4439 ;; message from stdin.
4441 ;; qmail also has the advantage of not having been raped by
4442 ;; various vendors, so we don't have to allow for that, either --
4443 ;; compare this with message-send-mail-with-sendmail and weep
4444 ;; for sendmail's lost innocence.
4446 ;; all this is way cool coz it lets us keep the arguments entirely
4447 ;; free for -inject-arguments -- a big win for the user and for us
4448 ;; since we don't have to play that double-guessing game and the user
4449 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4450 (if (functionp message-qmail-inject-args)
4451 (funcall message-qmail-inject-args)
4452 message-qmail-inject-args)))
4453 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4454 ;; we have to look at the retval instead
4456 (100 (error "qmail-inject reported permanent failure"))
4457 (111 (error "qmail-inject reported transient failure"))
4458 ;; should never happen
4459 (t (error "qmail-inject reported unknown failure"))))
4461 (defun message-send-mail-with-mh ()
4462 "Send the prepared message buffer with mh."
4463 (let ((mh-previous-window-config nil)
4464 (name (mh-new-draft-name)))
4465 (setq buffer-file-name name)
4466 ;; MH wants to generate these headers itself.
4467 (when message-mh-deletable-headers
4468 (let ((headers message-mh-deletable-headers))
4470 (goto-char (point-min))
4471 (and (re-search-forward
4472 (concat "^" (symbol-name (car headers)) ": *") nil t)
4473 (message-delete-line))
4475 (run-hooks 'message-send-mail-hook)
4476 ;; Pass it on to mh.
4479 (defun message-send-mail-with-smtp ()
4480 "Send off the prepared buffer with SMTP."
4481 (require 'smtp) ; XXX
4482 (let ((case-fold-search t)
4485 (message-narrow-to-headers)
4487 ;; XXX: Should be replaced by better one.
4488 (smtp-deduce-address-list (current-buffer)
4489 (point-min) (point-max)))
4490 ;; Remove BCC lines.
4491 (message-remove-header "bcc"))
4492 ;; replace the header delimiter with a blank line.
4493 (goto-char (point-min))
4495 (concat "^" (regexp-quote mail-header-separator) "\n"))
4496 (replace-match "\n")
4498 (run-hooks 'message-send-mail-hook)
4500 (smtp-send-buffer user-mail-address recipients (current-buffer))
4501 (error "Sending failed; no recipients"))))
4503 (defsubst message-maybe-split-and-send-news (method)
4504 "Split a message if necessary, and send it via news.
4505 Returns nil if sending succeeded, returns t if sending failed.
4506 This sub function is for exclusive use of `message-send-news'."
4507 (let ((mime-edit-split-ignored-field-regexp
4508 mime-edit-split-ignored-field-regexp)
4509 (case-fold-search t))
4510 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
4511 (setq mime-edit-split-ignored-field-regexp
4512 (concat (substring mime-edit-split-ignored-field-regexp
4513 0 (match-beginning 0))
4514 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
4515 "_so_don't_rape_it!"
4516 (substring mime-edit-split-ignored-field-regexp
4519 (catch 'message-sending-news-failure
4520 (mime-edit-maybe-split-and-send
4525 (std11-narrow-to-header mail-header-separator)
4526 (goto-char (point-min))
4527 (when (re-search-forward "^Message-ID:" nil t)
4528 (delete-region (match-end 0) (std11-field-end))
4529 (insert " " (message-make-message-id))))
4530 (unless (funcall message-send-news-function method)
4531 (throw 'message-sending-news-failure t)))))
4533 (not (funcall message-send-news-function method)))))
4535 (defun message-smtpmail-send-it ()
4536 "Send the prepared message buffer with `smtpmail-send-it'.
4537 This only differs from `smtpmail-send-it' that this command evaluates
4538 `message-send-mail-hook' just before sending a message. It is useful
4539 if your ISP requires the POP-before-SMTP authentication. See the Gnus
4540 manual for details."
4541 (run-hooks 'message-send-mail-hook)
4544 (defun message-canlock-generate ()
4545 "Return a string that is non-trivial to guess.
4546 Do not use this for anything important, it is cryptographically weak."
4548 (let (sha1-maximum-internal-length)
4549 (sha1 (concat (message-unique-id)
4550 (format "%x%x%x" (random) (random t) (random))
4551 (prin1-to-string (recent-keys))
4552 (prin1-to-string (garbage-collect))))))
4554 (defun message-canlock-password ()
4555 "The password used by message for cancel locks.
4556 This is the value of `canlock-password', if that option is non-nil.
4557 Otherwise, generate and save a value for `canlock-password' first."
4558 (unless canlock-password
4559 (customize-save-variable 'canlock-password (message-canlock-generate))
4560 (setq canlock-password-for-verify canlock-password))
4563 (defun message-insert-canlock ()
4564 (when message-insert-canlock
4565 (message-canlock-password)
4566 (canlock-insert-header)))
4568 (defun message-send-news (&optional arg)
4569 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4570 (case-fold-search nil)
4571 (method (if (functionp message-post-method)
4572 (funcall message-post-method arg)
4573 message-post-method))
4574 (newsgroups-field (save-restriction
4575 (message-narrow-to-headers-or-head)
4576 (message-fetch-field "Newsgroups")))
4577 (followup-field (save-restriction
4578 (message-narrow-to-headers-or-head)
4579 (message-fetch-field "Followup-To")))
4580 ;; BUG: We really need to get the charset for each name in the
4581 ;; Newsgroups and Followup-To lines to allow crossposting
4582 ;; between group namess with incompatible character sets.
4583 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4584 (group-field-charset
4585 (gnus-group-name-charset method newsgroups-field))
4586 (followup-field-charset
4587 (gnus-group-name-charset method (or followup-field "")))
4588 (mime-field-encoding-method-alist
4589 (append (when group-field-charset
4590 (list (cons "Newsgroups" group-field-charset)))
4591 (when followup-field-charset
4592 (list (cons "Followup-To" followup-field-charset)))
4593 mime-field-encoding-method-alist))
4594 (message-syntax-checks
4596 (listp message-syntax-checks))
4597 (cons '(existing-newsgroups . disabled)
4598 message-syntax-checks)
4599 message-syntax-checks))
4600 (message-this-is-news t)
4603 (message-narrow-to-headers)
4604 ;; Insert some headers.
4605 (message-generate-headers message-required-news-headers)
4606 (message-insert-canlock)
4607 ;; Let the user do all of the above.
4608 (run-hooks 'message-header-hook))
4609 ;; Note: This check will be disabled by the ".*" default value for
4610 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4611 (when (and group-field-charset
4612 (listp message-syntax-checks))
4613 (setq message-syntax-checks
4614 (cons '(valid-newsgroups . disabled)
4615 message-syntax-checks)))
4616 (message-cleanup-headers)
4617 (if (not (let ((message-post-method method))
4618 (message-check-news-syntax)))
4623 (buffer-disable-undo)
4625 (insert-buffer-substring message-encoding-buffer)
4626 ;; Remove some headers.
4628 (message-narrow-to-headers)
4629 ;; We Semi-gnus people have no use for it.
4630 ;; ;; We (re)generate the Lines header.
4631 ;; (when (memq 'Lines message-required-mail-headers)
4632 ;; (message-generate-headers '(Lines)))
4633 ;; Remove some headers.
4634 (message-remove-header message-ignored-news-headers t))
4635 (goto-char (point-max))
4636 ;; require one newline at the end.
4637 (or (= (preceding-char) ?\n)
4639 (setq result (message-maybe-split-and-send-news method)))
4640 (kill-buffer tembuf))
4641 (set-buffer message-edit-buffer)
4644 (message "Couldn't send message via news: %s"
4645 (nnheader-get-report (car method)))
4647 (push 'news message-sent-message-via)))))
4649 ;; 1997-09-29 by MORIOKA Tomohiko
4650 (defun message-send-news-with-gnus (method)
4651 (let ((case-fold-search t))
4652 ;; Remove the delimiter.
4653 (goto-char (point-min))
4655 (concat "^" (regexp-quote mail-header-separator) "\n"))
4656 (replace-match "\n")
4658 (run-hooks 'message-send-news-hook)
4659 (gnus-open-server method)
4660 (message "Sending news via %s..." (gnus-server-string method))
4661 (gnus-request-post method)
4665 ;;; Header generation & syntax checking.
4668 (defun message-check-element (type)
4669 "Return non-nil if this TYPE is not to be checked."
4670 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
4672 (let ((able (assq type message-syntax-checks)))
4674 (eq (cdr able) 'disabled)))))
4676 (defun message-check-news-syntax ()
4677 "Check the syntax of the message."
4682 ;; We narrow to the headers and check them first.
4685 (message-narrow-to-headers)
4686 (message-check-news-header-syntax)))
4689 (set-buffer message-edit-buffer)
4690 (message-check-news-body-syntax))))))
4692 (defun message-check-news-header-syntax ()
4694 ;; Check Newsgroups header.
4695 (message-check 'newsgroups
4696 (let ((group (message-fetch-field "newsgroups")))
4699 (not (string-match "\\`[ \t]*\\'" group)))
4702 "The newsgroups field is empty or missing. Posting is denied.")))))
4703 ;; Check the Subject header.
4704 (message-check 'subject
4705 (let* ((case-fold-search t)
4706 (subject (message-fetch-field "subject")))
4709 (not (string-match "\\`[ \t]*\\'" subject)))
4712 "The subject field is empty or missing. Posting is denied.")))))
4713 ;; Check for commands in Subject.
4714 (message-check 'subject-cmsg
4715 (if (string-match "^cmsg " (message-fetch-field "subject"))
4717 "The control code \"cmsg\" is in the subject. Really post? ")
4719 ;; Check long header lines.
4720 (message-check 'long-header-lines
4721 (let ((start (point))
4725 (while (and (not found)
4726 (re-search-forward "^\\([^ \t:]+\\): " nil t))
4727 (if (> (- (point) (match-beginning 0)) 998)
4729 length (- (point) (match-beginning 0)))
4730 (setq header (match-string-no-properties 1)))
4731 (setq start (match-beginning 0))
4734 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
4737 ;; Check for multiple identical headers.
4738 (message-check 'multiple-headers
4740 (while (and (not found)
4741 (re-search-forward "^[^ \t:]+: " nil t))
4743 (or (re-search-forward
4748 (match-beginning 0) (- (match-end 0) 2))))
4753 (y-or-n-p (format "Multiple %s headers. Really post? " found))
4755 ;; Check for Version and Sendsys.
4756 (message-check 'sendsys
4757 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
4759 (format "The article contains a %s command. Really post? "
4760 (buffer-substring (match-beginning 0)
4761 (1- (match-end 0)))))
4763 ;; See whether we can shorten Followup-To.
4764 (message-check 'shorten-followup-to
4765 (let ((newsgroups (message-fetch-field "newsgroups"))
4766 (followup-to (message-fetch-field "followup-to"))
4768 (when (and newsgroups
4769 (string-match "," newsgroups)
4774 (setq to (completing-read
4775 "Followups to (default: no Followup-To header) "
4778 (message-tokenize-header
4780 (goto-char (point-min))
4781 (insert "Followup-To: " to "\n"))
4783 ;; Check "Shoot me".
4784 (message-check 'shoot
4785 (if (re-search-forward
4786 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t)
4787 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
4789 ;; Check for Approved.
4790 (message-check 'approved
4791 (if (re-search-forward "^Approved:" nil t)
4792 (y-or-n-p "The article contains an Approved header. Really post? ")
4794 ;; Check the Message-ID header.
4795 (message-check 'message-id
4796 (let* ((case-fold-search t)
4797 (message-id (message-fetch-field "message-id" t)))
4798 (or (not message-id)
4799 ;; Is there an @ in the ID?
4800 (and (string-match "@" message-id)
4801 ;; Is there a dot in the ID?
4802 (string-match "@[^.]*\\." message-id)
4803 ;; Does the ID end with a dot?
4804 (not (string-match "\\.>" message-id)))
4806 (format "The Message-ID looks strange: \"%s\". Really post? "
4808 ;; Check the Newsgroups & Followup-To headers.
4809 (message-check 'existing-newsgroups
4810 (let* ((case-fold-search t)
4811 (newsgroups (message-fetch-field "newsgroups"))
4812 (followup-to (message-fetch-field "followup-to"))
4813 (groups (message-tokenize-header
4815 (concat newsgroups "," followup-to)
4817 (post-method (if (functionp message-post-method)
4818 (funcall message-post-method)
4819 message-post-method))
4820 ;; KLUDGE to handle nnvirtual groups. Doing this right
4821 ;; would probably involve a new nnoo function.
4822 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
4823 (method (if (and (consp post-method)
4824 (eq (car post-method) 'nnvirtual)
4825 gnus-message-group-art)
4826 (let ((group (car (nnvirtual-find-group-art
4827 (car gnus-message-group-art)
4828 (cdr gnus-message-group-art)))))
4829 (gnus-find-method-for-group group))
4833 (gnus-group-name-decode
4834 (gnus-group-real-name n)
4835 (gnus-group-name-charset method n)))
4836 (gnus-groups-from-server method)))
4839 (when (and (not (equal (car groups) "poster"))
4840 (not (member (car groups) known-groups))
4841 (not (member (car groups) errors)))
4842 (push (car groups) errors))
4845 ;; Gnus is not running.
4846 ((or (not (and (boundp 'gnus-active-hashtb)
4847 gnus-active-hashtb))
4848 (not (boundp 'gnus-read-active-file)))
4850 ;; We don't have all the group names.
4851 ((and (or (not gnus-read-active-file)
4852 (eq gnus-read-active-file 'some))
4856 "Really use %s possibly unknown group%s: %s? "
4857 (if (= (length errors) 1) "this" "these")
4858 (if (= (length errors) 1) "" "s")
4859 (mapconcat 'identity errors ", "))))
4860 ;; There were no errors.
4863 ;; There are unknown groups.
4867 "Really post to %s unknown group%s: %s? "
4868 (if (= (length errors) 1) "this" "these")
4869 (if (= (length errors) 1) "" "s")
4870 (mapconcat 'identity errors ", ")))))))
4871 ;; Check continuation headers.
4872 (message-check 'continuation-headers
4873 (goto-char (point-min))
4874 (let ((do-posting t))
4875 (while (re-search-forward "^[^ \t\n][^:\n]*$" nil t)
4876 (if (y-or-n-p "Fix continuation lines? ")
4878 (goto-char (match-beginning 0))
4880 (unless (y-or-n-p "Send anyway? ")
4881 (setq do-posting nil))))
4883 ;; Check the Newsgroups & Followup-To headers for syntax errors.
4884 (message-check 'valid-newsgroups
4885 (let ((case-fold-search t)
4886 (headers '("Newsgroups" "Followup-To"))
4888 (while (and headers (not error))
4889 (when (setq header (mail-fetch-field (car headers)))
4893 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
4898 (not (string-match "\\.\\'\\|\\.\\." g)))
4899 (message-tokenize-header header ","))))
4906 (format "The %s header looks odd: \"%s\". Really post? "
4907 (car headers) header)))))
4908 (message-check 'repeated-newsgroups
4909 (let ((case-fold-search t)
4910 (headers '("Newsgroups" "Followup-To"))
4911 header error groups group)
4914 (when (setq header (mail-fetch-field (pop headers)))
4915 (setq groups (message-tokenize-header header ","))
4916 (while (setq group (pop groups))
4917 (when (member group groups)
4923 (format "Group %s is repeated in headers. Really post? " error)))))
4924 ;; Check the From header.
4925 (message-check 'from
4926 (let* ((case-fold-search t)
4927 (from (message-fetch-field "from"))
4931 (message "There is no From line. Posting is denied.")
4933 ((or (not (string-match
4935 (setq ad (nth 1 (std11-extract-address-components
4936 from))))) ;larsi@ifi
4937 (string-match "\\.\\." ad) ;larsi@ifi..uio
4938 (string-match "@\\." ad) ;larsi@.ifi.uio
4939 (string-match "\\.$" ad) ;larsi@ifi.uio.
4940 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4941 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
4943 "Denied posting -- the From looks strange: \"%s\"." from)
4945 ((let ((addresses (rfc822-addresses from)))
4946 (while (and addresses
4947 (not (eq (string-to-char (car addresses)) ?\()))
4948 (setq addresses (cdr addresses)))
4951 "Denied posting -- bad From address: \"%s\"." from)
4954 ;; Check the Reply-To header.
4955 (message-check 'reply-to
4956 (let* ((case-fold-search t)
4957 (reply-to (message-fetch-field "reply-to"))
4962 ((string-match "," reply-to)
4964 (format "Multiple Reply-To addresses: \"%s\". Really post? "
4966 ((or (not (string-match
4968 (setq ad (nth 1 (std11-extract-address-components
4969 reply-to))))) ;larsi@ifi
4970 (string-match "\\.\\." ad) ;larsi@ifi..uio
4971 (string-match "@\\." ad) ;larsi@.ifi.uio
4972 (string-match "\\.$" ad) ;larsi@ifi.uio.
4973 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4974 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
4977 "The Reply-To looks strange: \"%s\". Really post? "
4981 (defun message-check-news-body-syntax ()
4983 ;; Check for long lines.
4984 (message-check 'long-lines
4985 (goto-char (point-min))
4987 (concat "^" (regexp-quote mail-header-separator) "$"))
4991 mime-edit-tag-regexp)
4994 (< (- (point) p) 80)))
4995 (zerop (forward-line 1))))
4999 "You have lines longer than 79 characters. Really post? ")))
5000 ;; Check whether the article is empty.
5001 (message-check 'empty
5002 (goto-char (point-min))
5004 (concat "^" (regexp-quote mail-header-separator) "$"))
5007 (goto-char (point-max))
5008 (re-search-backward message-signature-separator nil t)
5010 (or (re-search-backward "[^ \n\t]" b t)
5011 (if (message-gnksa-enable-p 'empty-article)
5012 (y-or-n-p "Empty article. Really post? ")
5013 (message "Denied posting -- Empty article.")
5015 ;; Check for control characters.
5016 (message-check 'control-chars
5017 (if (re-search-forward
5018 (string-as-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
5021 "The article contains control characters. Really post? ")
5023 ;; Check 8bit characters.
5024 (message-check '8bit
5025 (message-check-8bit))
5026 ;; Check excessive size.
5027 (message-check 'size
5028 (if (> (buffer-size) 60000)
5030 (format "The article is %d octets long. Really post? "
5033 ;; Check whether any new text has been added.
5034 (message-check 'new-text
5036 (not message-checksum)
5037 (not (eq (message-checksum) message-checksum))
5038 (if (message-gnksa-enable-p 'quoted-text-only)
5040 "It looks like no new text has been added. Really post? ")
5041 (message "Denied posting -- no new text has been added.")
5043 ;; Check the length of the signature.
5044 (message-check 'signature
5045 (goto-char (point-max))
5046 (if (> (count-lines (point) (point-max)) 5)
5049 "Your .sig is %d lines; it should be max 4. Really post? "
5050 (1- (count-lines (point) (point-max)))))
5052 ;; Ensure that text follows last quoted portion.
5053 (message-check 'quoting-style
5054 (goto-char (point-max))
5055 (let ((no-problem t))
5056 (when (search-backward-regexp "^>[^\n]*\n" nil t)
5057 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
5060 (if (message-gnksa-enable-p 'quoted-text-only)
5061 (y-or-n-p "Your text should follow quoted text. Really post? ")
5063 (goto-char (point-min))
5065 (concat "^" (regexp-quote mail-header-separator) "$"))
5066 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
5067 (y-or-n-p "Your text should follow quoted text. Really post? ")
5068 (message "Denied posting -- only quoted text.")
5071 (defun message-check-mail-syntax ()
5072 "Check the syntax of the message."
5077 ;; We narrow to the headers and check them first.
5080 (message-narrow-to-headers)
5081 (message-check-mail-header-syntax)))
5084 (set-buffer message-edit-buffer)
5085 (message-check-mail-body-syntax))))))
5087 (defun message-check-mail-header-syntax ()
5090 (defun message-check-mail-body-syntax ()
5092 ;; Check 8bit characters.
5093 (message-check '8bit
5094 (message-check-8bit)
5097 (defun message-check-8bit ()
5098 "Check the article contains 8bit characters."
5100 (set-buffer message-encoding-buffer)
5101 (message-narrow-to-headers)
5102 (let* ((case-fold-search t)
5103 (field-value (message-fetch-field "content-transfer-encoding")))
5104 (if (and field-value
5105 (member (downcase field-value) message-8bit-encoding-list))
5108 (set-buffer (get-buffer-create " message syntax"))
5110 (goto-char (point-min))
5111 (set-buffer-multibyte nil)
5112 (insert-buffer-substring message-encoding-buffer)
5113 (goto-char (point-min))
5114 (if (re-search-forward "[^\x00-\x7f]" nil t)
5116 "The article contains 8bit characters. Really post? ")
5119 (defun message-checksum ()
5120 "Return a \"checksum\" for the current buffer."
5123 (goto-char (point-min))
5125 (concat "^" (regexp-quote mail-header-separator) "$"))
5127 (when (not (looking-at "[ \t\n]"))
5128 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
5133 (defun message-do-fcc ()
5134 "Process Fcc headers in the current buffer."
5135 (let ((case-fold-search t)
5136 (coding-system-for-write 'raw-text)
5138 (mml-externalize-attachments message-fcc-externalize-attachments))
5141 (message-narrow-to-headers)
5142 (setq file (message-fetch-field "fcc" t)))
5144 (set-buffer (get-buffer-create " *message temp*"))
5146 (insert-buffer-substring message-encoding-buffer)
5148 (message-narrow-to-headers)
5149 (while (setq file (message-fetch-field "fcc"))
5151 (message-remove-header "fcc" nil t)))
5152 (goto-char (point-min))
5153 (when (re-search-forward
5154 (concat "^" (regexp-quote mail-header-separator) "$")
5156 (replace-match "" t t))
5157 ;; Process FCC operations.
5159 (setq file (pop list))
5160 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
5161 ;; Pipe the article to the program in question.
5162 (call-process-region (point-min) (point-max) shell-file-name
5163 nil nil nil shell-command-switch
5164 (match-string 1 file))
5165 ;; Save the article.
5166 (setq file (expand-file-name file))
5167 (unless (file-exists-p (file-name-directory file))
5168 (make-directory (file-name-directory file) t))
5169 (if (and message-fcc-handler-function
5170 (not (eq message-fcc-handler-function 'rmail-output)))
5171 (funcall message-fcc-handler-function file)
5172 (if (and (file-readable-p file) (mail-file-babyl-p file))
5173 (rmail-output file 1 nil t)
5174 (let ((mail-use-rfc822 t))
5175 (rmail-output file 1 t t))))))
5176 (kill-buffer (current-buffer))))))
5178 (defun message-output (filename)
5179 "Append this article to Unix/babyl mail file FILENAME."
5180 (if (and (file-readable-p filename)
5181 (mail-file-babyl-p filename))
5182 (gnus-output-to-rmail filename t)
5183 (gnus-output-to-mail filename t)))
5185 (defun message-cleanup-headers ()
5186 "Do various automatic cleanups of the headers."
5187 ;; Remove empty lines in the header.
5189 (message-narrow-to-headers)
5190 ;; Remove blank lines.
5191 (while (re-search-forward "^[ \t]*\n" nil t)
5192 (replace-match "" t t))
5194 ;; Correct Newsgroups and Followup-To headers: Change sequence of
5195 ;; spaces to comma and eliminate spaces around commas. Eliminate
5196 ;; embedded line breaks.
5197 (goto-char (point-min))
5198 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
5202 (if (re-search-forward "^[^ \t]" nil t)
5206 (goto-char (point-min))
5207 (while (re-search-forward "\n[ \t]+" nil t)
5208 (replace-match " " t t)) ;No line breaks (too confusing)
5209 (goto-char (point-min))
5210 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
5211 (replace-match "," t t))
5212 (goto-char (point-min))
5213 ;; Remove trailing commas.
5214 (when (re-search-forward ",+$" nil t)
5215 (replace-match "" t t))))))
5217 (defun message-make-date (&optional now)
5218 "Make a valid data header.
5219 If NOW, use that time instead."
5220 (let ((system-time-locale "C"))
5221 (format-time-string "%a, %d %b %Y %T %z" now)))
5223 (defun message-make-followup-subject (subject)
5224 "Make a followup Subject."
5226 ((and (eq message-use-subject-re 'guess)
5227 (string-match message-subject-encoded-re-regexp subject))
5229 (message-use-subject-re
5230 (concat "Re: " (message-strip-subject-re subject)))
5233 (defun message-make-message-id ()
5234 "Make a unique Message-ID."
5235 (concat "<" (message-unique-id)
5236 (let ((psubject (save-excursion (message-fetch-field "subject")))
5238 (save-excursion (message-fetch-field "supersedes"))))
5240 (and message-reply-headers
5241 (mail-header-references message-reply-headers)
5242 (mail-header-subject message-reply-headers)
5245 (message-strip-subject-re
5246 (mail-header-subject message-reply-headers))
5247 (message-strip-subject-re psubject))))
5249 (string-match "_-_@" psupersedes)))
5251 "@" (message-make-fqdn) ">"))
5253 (defvar message-unique-id-char nil)
5255 ;; If you ever change this function, make sure the new version
5256 ;; cannot generate IDs that the old version could.
5257 ;; You might for example insert a "." somewhere (not next to another dot
5258 ;; or string boundary), or modify the "fsf" string.
5259 (defun message-unique-id ()
5260 ;; Don't use microseconds from (current-time), they may be unsupported.
5261 ;; Instead we use this randomly inited counter.
5262 (setq message-unique-id-char
5263 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
5264 ;; (current-time) returns 16-bit ints,
5265 ;; and 2^16*25 just fits into 4 digits i base 36.
5267 (let ((tm (current-time)))
5269 (if (memq system-type '(ms-dos emx vax-vms))
5270 (let ((user (downcase (user-login-name))))
5271 (while (string-match "[^a-z0-9_]" user)
5272 (aset user (match-beginning 0) ?_))
5274 (message-number-base36 (user-uid) -1))
5275 (message-number-base36 (+ (car tm)
5276 (lsh (% message-unique-id-char 25) 16)) 4)
5277 (message-number-base36 (+ (nth 1 tm)
5278 (lsh (/ message-unique-id-char 25) 16)) 4)
5279 ;; Append a given name, because while the generated ID is unique
5280 ;; to this newsreader, other newsreaders might otherwise generate
5281 ;; the same ID via another algorithm.
5284 (defun message-number-base36 (num len)
5289 (concat (message-number-base36 (/ num 36) (1- len))
5290 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
5293 (defun message-make-organization ()
5294 "Make an Organization header."
5295 (let* ((organization
5296 (when message-user-organization
5297 (if (functionp message-user-organization)
5298 (funcall message-user-organization)
5299 message-user-organization))))
5301 (set-buffer-multibyte t)
5302 (cond ((stringp organization)
5303 (insert organization))
5304 ((and (eq t organization)
5305 message-user-organization-file
5306 (file-exists-p message-user-organization-file))
5307 (insert-file-contents message-user-organization-file)))
5308 (goto-char (point-min))
5309 (while (re-search-forward "[\t\n]+" nil t)
5310 (replace-match "" t t))
5311 (unless (zerop (buffer-size))
5314 (defun message-make-lines ()
5315 "Count the number of lines and return numeric string."
5320 (int-to-string (count-lines (point) (point-max))))))
5322 (defun message-make-references ()
5323 "Return the References header for this message."
5324 (when message-reply-headers
5325 (let ((message-id (mail-header-message-id message-reply-headers))
5326 (references (mail-header-references message-reply-headers))
5328 (if (or references message-id)
5329 (concat (or references "") (and references " ")
5333 (defun message-make-in-reply-to ()
5334 "Return the In-Reply-To header for this message."
5335 (when message-reply-headers
5336 (let ((from (mail-header-from message-reply-headers))
5337 (date (mail-header-date message-reply-headers))
5338 (msg-id (mail-header-message-id message-reply-headers)))
5340 (let ((name (std11-extract-address-components from)))
5341 (concat msg-id (if msg-id " (")
5345 (if (or (not date) (string= date ""))
5346 "(unknown date)" date)
5347 "\"" (if msg-id ")")))))))
5349 (defun message-make-distribution ()
5350 "Make a Distribution header."
5351 (let ((orig-distribution (message-fetch-reply-field "distribution")))
5352 (cond ((functionp message-distribution-function)
5353 (funcall message-distribution-function))
5354 (t orig-distribution))))
5356 (defun message-make-expires ()
5357 "Return an Expires header based on `message-expires'."
5358 (let ((current (current-time))
5359 (future (* 1.0 message-expires 60 60 24)))
5360 ;; Add the future to current.
5361 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
5362 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
5363 (message-make-date current)))
5365 (defun message-make-path ()
5367 (let ((login-name (user-login-name)))
5368 (cond ((null message-user-path)
5369 (concat (system-name) "!" login-name))
5370 ((stringp message-user-path)
5371 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
5372 (concat message-user-path "!" login-name))
5375 (defun message-make-from ()
5376 "Make a From header."
5377 (let* ((style message-from-style)
5378 (login (message-make-address))
5380 (or (and (boundp 'user-full-name)
5383 (when (string= fullname "&")
5384 (setq fullname (user-login-name)))
5386 (set-buffer-multibyte t)
5389 (equal fullname ""))
5391 ((or (eq style 'angles)
5392 (and (not (eq style 'parens))
5393 ;; Use angles if no quoting is needed, or if parens would
5394 ;; need quoting too.
5395 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
5396 (let ((tmp (concat fullname nil)))
5397 (while (string-match "([^()]*)" tmp)
5398 (aset tmp (match-beginning 0) ?-)
5399 (aset tmp (1- (match-end 0)) ?-))
5400 (string-match "[\\()]" tmp)))))
5402 (goto-char (point-min))
5403 ;; Look for a character that cannot appear unquoted
5404 ;; according to RFC 822.
5405 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
5406 ;; Quote fullname, escaping specials.
5407 (goto-char (point-min))
5409 (while (re-search-forward "[\"\\]" nil 1)
5410 (replace-match "\\\\\\&" t))
5412 (insert " <" login ">"))
5413 (t ; 'parens or default
5415 (let ((fullname-start (point)))
5417 (goto-char fullname-start)
5418 ;; RFC 822 says \ and nonmatching parentheses
5419 ;; must be escaped in comments.
5420 ;; Escape every instance of ()\ ...
5421 (while (re-search-forward "[()\\]" nil 1)
5422 (replace-match "\\\\\\&" t))
5423 ;; ... then undo escaping of matching parentheses,
5424 ;; including matching nested parentheses.
5425 (goto-char fullname-start)
5426 (while (re-search-forward
5427 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
5429 (replace-match "\\1(\\3)" t)
5430 (goto-char fullname-start)))
5434 (defun message-make-sender ()
5435 "Return the \"real\" user address.
5436 This function tries to ignore all user modifications, and
5437 give as trustworthy answer as possible."
5438 (concat (user-login-name) "@" (system-name)))
5440 (defun message-make-address ()
5441 "Make the address of the user."
5442 (or (message-user-mail-address)
5443 (concat (user-login-name) "@" (message-make-domain))))
5445 (defun message-user-mail-address ()
5446 "Return the pertinent part of `user-mail-address'."
5447 (when (and user-mail-address
5448 (string-match "@.*\\." user-mail-address))
5449 (if (string-match " " user-mail-address)
5450 (nth 1 (std11-extract-address-components user-mail-address))
5451 user-mail-address)))
5453 (defun message-sendmail-envelope-from ()
5454 "Return the envelope from."
5455 (cond ((eq message-sendmail-envelope-from 'header)
5456 (nth 1 (std11-extract-address-components
5457 (message-fetch-field "from"))))
5458 ((stringp message-sendmail-envelope-from)
5459 message-sendmail-envelope-from)
5461 (message-make-address))))
5463 (defun message-make-fqdn ()
5464 "Return user's fully qualified domain name."
5465 (let* ((system-name (system-name))
5466 (user-mail (message-user-mail-address))
5469 (string-match "@\\(.*\\)\\'" user-mail))
5470 (match-string 1 user-mail)))
5471 (case-fold-search t))
5473 ((and message-user-fqdn
5474 (stringp message-user-fqdn)
5475 (string-match message-valid-fqdn-regexp message-user-fqdn)
5476 (not (string-match message-bogus-system-names message-user-fqdn)))
5478 ;; `message-user-fqdn' seems to be valid
5479 ((and (string-match message-valid-fqdn-regexp system-name)
5480 (not (string-match message-bogus-system-names system-name)))
5481 ;; `system-name' returned the right result.
5483 ;; Try `mail-host-address'.
5484 ((and (boundp 'mail-host-address)
5485 (stringp mail-host-address)
5486 (string-match message-valid-fqdn-regexp mail-host-address)
5487 (not (string-match message-bogus-system-names mail-host-address)))
5489 ;; We try `user-mail-address' as a backup.
5491 (stringp user-domain)
5492 (string-match message-valid-fqdn-regexp user-domain)
5493 (not (string-match message-bogus-system-names user-domain)))
5495 ;; Default to this bogus thing.
5498 ".i-did-not-set--mail-host-address--so-tickle-me")))))
5500 (defun message-make-host-name ()
5501 "Return the name of the host."
5502 (let ((fqdn (message-make-fqdn)))
5503 (string-match "^[^.]+\\." fqdn)
5504 (substring fqdn 0 (1- (match-end 0)))))
5506 (defun message-make-domain ()
5507 "Return the domain name."
5508 (or mail-host-address
5509 (message-make-fqdn)))
5511 (defun message-to-list-only ()
5512 "Send a message to the list only.
5513 Remove all addresses but the list address from To and Cc headers."
5515 (let ((listaddr (message-make-mail-followup-to t)))
5518 (message-remove-header "to")
5519 (message-remove-header "cc")
5520 (message-position-on-field "To" "X-Draft-From")
5521 (insert listaddr)))))
5523 (defun message-make-mail-followup-to (&optional only-show-subscribed)
5524 "Return the Mail-Followup-To header.
5525 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5526 subscribed address (and not the additional To and Cc header contents)."
5527 (let* ((case-fold-search t)
5528 (to (message-fetch-field "To"))
5529 (cc (message-fetch-field "cc"))
5530 (msg-recipients (concat to (and to cc ", ") cc))
5532 (mapcar 'mail-strip-quoted-names
5533 (message-tokenize-header msg-recipients)))
5535 (if message-subscribed-address-file
5536 (let (begin end item re)
5539 (insert-file-contents message-subscribed-address-file)
5541 (setq begin (point))
5544 (if (bolp) (setq end (1- end)))
5545 (setq item (regexp-quote (buffer-substring begin end)))
5546 (if re (setq re (concat re "\\|" item))
5547 (setq re (concat "\\`\\(" item))))
5548 (and re (list (concat re "\\)\\'"))))))))
5549 (mft-regexps (apply 'append message-subscribed-regexps
5550 (mapcar 'regexp-quote
5551 message-subscribed-addresses)
5554 message-subscribed-address-functions))))
5556 (let ((subscribed-lists nil)
5558 (loop for recipient in recipients
5559 when (loop for regexp in mft-regexps
5560 when (string-match regexp recipient) return t)
5563 (if only-show-subscribed
5565 msg-recipients))))))
5567 ;; Dummy to avoid byte-compile warning.
5568 (defvar mule-version)
5569 (defvar emacs-beta-version)
5570 (defvar xemacs-codename)
5571 (defvar gnus-inviolable-extended-version)
5573 (defun message-make-user-agent ()
5574 "Return user-agent info if the value `message-user-agent' is non-nil. If the
5575 \"User-Agent\" field has already exist, remove it."
5576 (when message-user-agent
5578 (goto-char (point-min))
5579 (let ((case-fold-search t))
5580 (when (re-search-forward "^User-Agent:[\t ]*" nil t)
5581 (delete-region (match-beginning 0) (1+ (std11-field-end)))))))
5584 (defun message-idna-to-ascii-rhs-1 (header)
5585 "Interactively potentially IDNA encode domain names in HEADER."
5586 (let ((field (message-fetch-field header))
5589 (dolist (address (mail-header-parse-addresses field))
5590 (setq address (car address)
5591 rhs (downcase (or (cadr (split-string address "@")) ""))
5592 ace (downcase (idna-to-ascii rhs)))
5593 (when (and (not (equal rhs ace))
5594 (or (not (eq message-use-idna 'ask))
5595 (y-or-n-p (format "Replace %s with %s? " rhs ace))))
5596 (goto-char (point-min))
5597 (while (re-search-forward (concat "^" header ":") nil t)
5598 (message-narrow-to-field)
5599 (while (search-forward (concat "@" rhs) nil t)
5600 (replace-match (concat "@" ace) t t))
5601 (goto-char (point-max))
5604 (defun message-idna-to-ascii-rhs ()
5605 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
5606 See `message-idna-encode'."
5608 (when message-use-idna
5611 (message-narrow-to-head)
5612 (message-idna-to-ascii-rhs-1 "From")
5613 (message-idna-to-ascii-rhs-1 "To")
5614 (message-idna-to-ascii-rhs-1 "Reply-To")
5615 (message-idna-to-ascii-rhs-1 "Cc")))))
5617 (defun message-generate-headers (headers)
5618 "Prepare article HEADERS.
5619 Headers already prepared in the buffer are not modified."
5620 (setq headers (append headers message-required-headers))
5622 (message-narrow-to-headers)
5623 (let* ((Date (message-make-date))
5624 (Message-ID (message-make-message-id))
5625 (Organization (message-make-organization))
5626 (From (message-make-from))
5627 (Path (message-make-path))
5630 (In-Reply-To (message-make-in-reply-to))
5631 (References (message-make-references))
5633 (Distribution (message-make-distribution))
5634 (Lines (message-make-lines))
5635 (User-Agent (message-make-user-agent))
5636 (Expires (message-make-expires))
5637 (case-fold-search t)
5639 header value elem header-string)
5640 ;; First we remove any old generated headers.
5641 (let ((headers message-deletable-headers))
5642 (unless (buffer-modified-p)
5643 (setq headers (delq 'Message-ID (copy-sequence headers))))
5645 (goto-char (point-min))
5646 (and (re-search-forward
5647 (concat "^" (symbol-name (car headers)) ": *") nil t)
5648 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
5649 (message-delete-line))
5651 ;; Go through all the required headers and see if they are in the
5652 ;; articles already. If they are not, or are empty, they are
5653 ;; inserted automatically - except for Subject, Newsgroups and
5656 (goto-char (point-min))
5657 (setq elem (pop headers))
5659 (if (eq (car elem) 'optional)
5660 (setq header (cdr elem)
5662 (setq header (car elem)))
5664 (setq header-string (if (stringp header)
5666 (symbol-name header)))
5667 (when (or (not (re-search-forward
5669 (regexp-quote (downcase header-string))
5673 ;; The header was found. We insert a space after the
5674 ;; colon, if there is none.
5675 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
5676 ;; Find out whether the header is empty.
5677 (looking-at "[ \t]*\n[^ \t]")))
5678 ;; So we find out what value we should insert.
5682 (eq (car elem) 'optional)
5683 (not (member header-string message-inserted-headers)))
5684 ;; This is an optional header. If the cdr of this
5685 ;; is something that is nil, then we do not insert
5687 (setq header (cdr elem))
5688 (or (and (functionp (cdr elem))
5689 (funcall (cdr elem)))
5690 (and (boundp (cdr elem))
5691 (symbol-value (cdr elem)))))
5693 ;; The element is a cons. Either the cdr is a
5694 ;; string to be inserted verbatim, or it is a
5695 ;; function, and we insert the value returned from
5697 (or (and (stringp (cdr elem))
5699 (and (functionp (cdr elem))
5700 (funcall (cdr elem)))))
5701 ((and (boundp header)
5702 (symbol-value header))
5703 ;; The element is a symbol. We insert the value
5704 ;; of this symbol, if any.
5705 (symbol-value header))
5706 ((not (message-check-element header))
5707 ;; We couldn't generate a value for this header,
5708 ;; so we just ask the user.
5709 (read-from-minibuffer
5710 (format "Empty header for %s; enter value: " header)))))
5711 ;; Finally insert the header.
5713 (not (equal value "")))
5717 ;; This header didn't exist, so we insert it.
5718 (goto-char (point-max))
5720 (cdr (assq header message-header-format-alist))))
5722 (funcall formatter header value)
5723 (insert header-string ": " value))
5724 (goto-char (message-fill-field))
5725 ;; We check whether the value was ended by a
5726 ;; newline. If not, we insert one.
5730 ;; The value of this header was empty, so we clear
5731 ;; totally and insert the new value.
5732 (delete-region (point) (point-at-eol))
5733 ;; If the header is optional, and the header was
5734 ;; empty, we can't insert it anyway.
5736 (push header-string message-inserted-headers)
5738 (message-fill-field)))
5739 ;; Add the deletable property to the headers that require it.
5740 (and (memq header message-deletable-headers)
5741 (progn (beginning-of-line) (looking-at "[^:]+: "))
5742 (add-text-properties
5743 (point) (match-end 0)
5744 '(message-deletable t face italic) (current-buffer)))))))
5745 ;; Insert new Sender if the From is strange.
5746 (let ((from (message-fetch-field "from"))
5747 (sender (message-fetch-field "sender"))
5748 (secure-sender (message-make-sender)))
5750 (not (message-check-element 'sender))
5753 (cadr (std11-extract-address-components from)))
5754 (downcase secure-sender)))
5759 (cadr (std11-extract-address-components sender)))
5760 (downcase secure-sender)))))
5761 (goto-char (point-min))
5762 ;; Rename any old Sender headers to Original-Sender.
5763 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
5765 (insert "Original-")
5766 (beginning-of-line))
5767 (when (or (message-news-p)
5768 (string-match "@.+\\.." secure-sender))
5769 (insert "Sender: " secure-sender "\n"))))
5771 (message-idna-to-ascii-rhs))))
5773 (defun message-insert-courtesy-copy ()
5774 "Insert a courtesy message in mail copies of combined messages."
5778 (message-narrow-to-headers)
5779 (when (setq newsgroups (message-fetch-field "newsgroups"))
5780 (goto-char (point-max))
5781 (insert "Posted-To: " newsgroups "\n")))
5783 (when message-courtesy-message
5785 ((string-match "%s" message-courtesy-message)
5786 (insert (format message-courtesy-message newsgroups)))
5788 (insert message-courtesy-message)))))))
5791 ;;; Setting up a message buffer
5794 (defun message-skip-to-next-address ()
5795 (let ((end (save-excursion
5796 (message-next-header)
5799 (when (looking-at ",")
5801 (while (and (not (= (point) end))
5802 (or (not (eq char ?,))
5804 (skip-chars-forward "^,\"" (point-max))
5805 (when (eq (setq char (following-char)) ?\")
5806 (setq quoted (not quoted)))
5807 (unless (= (point) end)
5809 (skip-chars-forward " \t\n")))
5811 (defun message-fill-address (header value)
5812 (insert (capitalize (symbol-name header))
5814 (if (consp value) (car value) value)
5816 (message-fill-field-address))
5818 (defun message-fill-references (header value)
5819 (insert (capitalize (symbol-name header))
5821 (std11-fill-msg-id-list-string
5822 (if (consp value) (car value) value))
5825 (defun message-split-line ()
5826 "Split current line, moving portion beyond point vertically down.
5827 If the current line has `message-yank-prefix', insert it on the new line."
5830 (split-line message-yank-prefix) ;; Emacs 21.3.50+ supports arg.
5834 (defun message-insert-header (header value)
5835 (insert (capitalize (symbol-name header))
5837 (if (consp value) (car value) value)))
5839 (defun message-field-name ()
5841 (goto-char (point-min))
5842 (when (looking-at "\\([^:]+\\):")
5843 (intern (capitalize (match-string 1))))))
5845 (defun message-fill-field ()
5848 (message-narrow-to-field)
5849 (let ((field-name (message-field-name)))
5850 (funcall (or (cadr (assq field-name message-field-fillers))
5851 'message-fill-field-general)))
5854 (defun message-fill-field-address ()
5856 (message-skip-to-next-address)
5858 (if (and (> (current-column) 78)
5864 (setq last (1+ (point))))
5865 (setq last (1+ (point)))))))
5867 (defun message-fill-field-general ()
5868 (let ((begin (point))
5871 (while (and (search-forward "\n" nil t)
5873 (replace-match " " t t))
5874 (fill-region-as-paragraph begin (point-max))
5875 ;; Tapdance around looong Message-IDs.
5877 (when (looking-at "[ \t]*$")
5878 (message-delete-line))
5880 (search-forward ":" nil t)
5881 (when (looking-at "\n[ \t]+")
5882 (replace-match " " t t))
5883 (goto-char (point-max))))
5885 (defun message-shorten-1 (list cut surplus)
5886 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
5887 (setcdr (nthcdr (- cut 2) list)
5888 (nthcdr (+ (- cut 2) surplus 1) list)))
5890 (defun message-shorten-references (header references)
5891 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
5892 When sending via news, also check that the REFERENCES are less
5893 than 988 characters long, and if they are not, trim them until
5901 (goto-char (point-min))
5902 ;; Cons a list of valid references.
5903 (while (re-search-forward "<[^>]+>" nil t)
5904 (push (match-string 0) refs))
5905 (setq refs (nreverse refs)
5906 count (length refs)))
5908 ;; If the list has more than MAXCOUNT elements, trim it by
5909 ;; removing the CUTth element and the required number of
5910 ;; elements that follow.
5911 (when (> count maxcount)
5912 (let ((surplus (- count maxcount)))
5913 (message-shorten-1 refs cut surplus)
5914 (decf count surplus)))
5916 ;; When sending via news, make sure the total folded length will
5917 ;; be less than 998 characters. This is to cater to broken INN
5918 ;; 2.3 which counts the total number of characters in a header
5919 ;; rather than the physical line length of each line, as it should.
5921 ;; This hack should be removed when it's believed than INN 2.3 is
5922 ;; no longer widely used.
5924 ;; At this point the headers have not been generated, thus we use
5925 ;; message-this-is-news directly.
5926 (when message-this-is-news
5929 (message-insert-header
5930 header (mapconcat #'identity refs " "))
5932 (message-shorten-1 refs cut 1)))
5933 ;; Finally, collect the references back into a string and insert
5934 ;; it into the buffer.
5935 (message-insert-header header (mapconcat #'identity refs " "))))
5937 (defun message-position-point ()
5938 "Move point to where the user probably wants to find it."
5939 (message-narrow-to-headers)
5941 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
5942 (search-backward ":" )
5945 (if (eq (char-after) ? )
5949 (goto-char (point-max))
5952 (unless (looking-at "$")
5956 (defcustom message-beginning-of-line t
5957 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
5958 goes to beginning of header values."
5960 :group 'message-buffers
5961 :link '(custom-manual "(message)Movement")
5964 (defun message-beginning-of-line (&optional n)
5965 "Move point to beginning of header value or to beginning of line.
5966 The prefix argument N is passed directly to `beginning-of-line'.
5968 This command is identical to `beginning-of-line' if point is
5969 outside the message header or if the option `message-beginning-of-line'
5972 If point is in the message header and on a (non-continued) header
5973 line, move point to the beginning of the header value. If point
5974 is already there, move point to beginning of line. Therefore,
5975 repeated calls will toggle point between beginning of field and
5978 (let ((zrs 'zmacs-region-stays))
5979 (when (and (interactive-p) (boundp zrs))
5981 (if (and message-beginning-of-line
5982 (message-point-in-header-p))
5983 (let* ((here (point))
5984 (bol (progn (beginning-of-line n) (point)))
5985 (eol (point-at-eol))
5986 (eoh (re-search-forward ": *" eol t)))
5987 (if (or (not eoh) (equal here eoh))
5990 (beginning-of-line n)))
5992 (defun message-buffer-name (type &optional to group)
5993 "Return a new (unique) buffer name based on TYPE and TO."
5995 ;; Generate a new buffer name The Message Way.
5996 ((eq message-generate-new-buffers 'unique)
5997 (generate-new-buffer-name
6001 (or (car (std11-extract-address-components to))
6004 (if (and group (not (string= group ""))) (concat " on " group) "")
6006 ;; Check whether `message-generate-new-buffers' is a function,
6007 ;; and if so, call it.
6008 ((functionp message-generate-new-buffers)
6009 (funcall message-generate-new-buffers type to group))
6010 ((eq message-generate-new-buffers 'unsent)
6011 (generate-new-buffer-name
6012 (concat "*unsent " type
6015 (or (car (std11-extract-address-components to))
6018 (if (and group (not (string= group ""))) (concat " on " group) "")
6020 ;; Use standard name.
6022 (format "*%s message*" type))))
6024 (defmacro message-pop-to-buffer-1 (buffer)
6026 (let (special-display-buffer-names
6027 special-display-regexps
6028 same-window-buffer-names
6029 same-window-regexps)
6030 (pop-to-buffer ,buffer))
6031 (pop-to-buffer ,buffer)))
6033 (defun message-pop-to-buffer (name)
6034 "Pop to buffer NAME, and warn if it already exists and is modified."
6035 (let ((buffer (get-buffer name))
6036 (pop-up-frames (and (static-if (featurep 'xemacs)
6037 (device-on-window-system-p)
6039 message-use-multi-frames)))
6041 (buffer-name buffer))
6043 (message-pop-to-buffer-1 buffer)
6044 (when (and (buffer-modified-p)
6046 "Message already being composed; erase? ")))
6047 (error "Message being composed")))
6048 (message-pop-to-buffer-1 name))
6052 (set (make-local-variable 'message-original-frame) (selected-frame)))))
6054 (defun message-do-send-housekeeping ()
6055 "Kill old message buffers."
6056 ;; We might have sent this buffer already. Delete it from the
6058 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
6059 (while (and message-max-buffers
6061 (>= (length message-buffer-list) message-max-buffers))
6062 ;; Kill the oldest buffer -- unless it has been changed.
6063 (let ((buffer (pop message-buffer-list)))
6064 (when (and (buffer-name buffer)
6065 (not (buffer-modified-p buffer)))
6066 (kill-buffer buffer))))
6067 ;; Rename the buffer.
6068 (if message-send-rename-function
6069 (funcall message-send-rename-function)
6070 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
6072 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
6074 (let ((name (match-string 2 (buffer-name)))
6076 (if (not (or (null name)
6077 (string-equal name "mail")
6078 (string-equal name "posting")))
6079 (setq name (concat "*sent " name "*"))
6080 (message-narrow-to-headers)
6081 (setq to (message-fetch-field "to"))
6082 (setq group (message-fetch-field "newsgroups"))
6086 (to (concat "*sent mail to "
6087 (or (car (std11-extract-address-components to))
6089 ((and group (not (string= group "")))
6090 (concat "*sent posting on " group "*"))
6091 (t "*sent mail*"))))
6092 (unless (string-equal name (buffer-name))
6093 (rename-buffer name t)))))
6094 ;; Push the current buffer onto the list.
6095 (when message-max-buffers
6096 (setq message-buffer-list
6097 (nconc message-buffer-list (list (current-buffer))))))
6099 (defun message-mail-user-agent ()
6101 ((not message-mail-user-agent) nil)
6102 ((eq message-mail-user-agent t) mail-user-agent)
6103 (t message-mail-user-agent))))
6104 (if (memq mua '(message-user-agent gnus-user-agent))
6108 (defun message-setup (headers &optional replybuffer actions switch-function)
6109 (let ((mua (message-mail-user-agent))
6110 subject to field yank-action)
6111 (if (not (and message-this-is-mail mua))
6112 (message-setup-1 headers replybuffer actions)
6114 (setq yank-action (list 'insert-buffer replybuffer)))
6115 (setq headers (copy-sequence headers))
6116 (setq field (assq 'Subject headers))
6118 (setq subject (cdr field))
6119 (setq headers (delq field headers)))
6120 (setq field (assq 'To headers))
6122 (setq to (cdr field))
6123 (setq headers (delq field headers)))
6124 (let ((mail-user-agent mua))
6125 (compose-mail to subject
6126 (mapcar (lambda (item)
6128 (format "%s" (car item))
6131 nil switch-function yank-action actions)))))
6133 (defun message-headers-to-generate (headers included-headers excluded-headers)
6134 "Return a list that includes all headers from HEADERS.
6135 If INCLUDED-HEADERS is a list, just include those headers. If if is
6136 t, include all headers. In any case, headers from EXCLUDED-HEADERS
6140 (dolist (header headers)
6141 (setq header-name (cond
6142 ((and (consp header)
6143 (eq (car header) 'optional))
6144 ;; On the form (optional . Header)
6147 ;; On the form (Header . function)
6152 (when (and (not (memq header-name excluded-headers))
6153 (or (eq included-headers t)
6154 (memq header-name included-headers)))
6155 (push header result)))
6158 (defun message-setup-1 (headers &optional replybuffer actions)
6159 (dolist (action actions)
6161 (add-to-list 'message-send-actions
6162 `(apply ',(car action) ',(cdr action)))))
6163 (setq message-reply-buffer
6164 (or (message-get-parameter 'reply-buffer)
6166 (goto-char (point-min))
6167 ;; Insert all the headers.
6170 (alist message-header-format-alist))
6172 (unless (assq (caar h) message-header-format-alist)
6173 (push (list (caar h)) alist))
6177 (delete-region (point) (progn (forward-line -1) (point)))
6178 (when message-default-headers
6179 (insert message-default-headers)
6180 (or (bolp) (insert ?\n)))
6181 (insert mail-header-separator "\n")
6183 (when (message-news-p)
6184 (when message-default-news-headers
6185 (insert message-default-news-headers)
6186 (or (bolp) (insert ?\n)))
6187 (when message-generate-headers-first
6188 (message-generate-headers
6189 (message-headers-to-generate
6190 (append message-required-news-headers
6191 message-required-headers)
6192 message-generate-headers-first
6193 '(Lines Subject)))))
6194 (when (message-mail-p)
6195 (when message-default-mail-headers
6196 (insert message-default-mail-headers)
6197 (or (bolp) (insert ?\n)))
6199 (message-narrow-to-headers)
6200 (if (and replybuffer
6201 message-alternative-emails)
6202 (message-use-alternative-email-as-from)))
6203 (when message-generate-headers-first
6204 (message-generate-headers
6205 (message-headers-to-generate
6206 (append message-required-mail-headers
6207 message-required-headers)
6208 message-generate-headers-first
6209 '(Lines Subject)))))
6210 (run-hooks 'message-signature-setup-hook)
6211 (message-insert-signature)
6213 (message-narrow-to-headers)
6214 (run-hooks 'message-header-setup-hook))
6215 (set-buffer-modified-p nil)
6216 (setq buffer-undo-list nil)
6217 (when message-generate-hashcash
6218 ;; Generate hashcash headers for recipients already known
6219 (mail-add-payment-async))
6220 (run-hooks 'message-setup-hook)
6221 (message-position-point)
6224 (defun message-set-auto-save-file-name ()
6225 "Associate the message buffer with a file in the drafts directory."
6226 (when message-auto-save-directory
6227 (unless (file-directory-p
6228 (directory-file-name message-auto-save-directory))
6229 (make-directory message-auto-save-directory t))
6231 (setq message-draft-article
6232 (nndraft-request-associate-buffer "drafts"))
6233 (setq buffer-file-name (expand-file-name
6234 (if (memq system-type
6235 '(ms-dos ms-windows windows-nt
6236 cygwin cygwin32 win32 w32
6240 message-auto-save-directory))
6241 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
6242 (clear-visited-file-modtime)
6243 (setq buffer-file-coding-system message-draft-coding-system)))
6245 (defun message-disassociate-draft ()
6246 "Disassociate the message buffer from the drafts directory."
6247 (when message-draft-article
6248 (nndraft-request-expire-articles
6249 (list message-draft-article) "drafts" nil t)))
6251 (defun message-insert-headers ()
6252 "Generate the headers for the article."
6256 (message-narrow-to-headers)
6257 (when (message-news-p)
6258 (message-generate-headers
6261 (copy-sequence message-required-news-headers)))))
6262 (when (message-mail-p)
6263 (message-generate-headers
6266 (copy-sequence message-required-mail-headers))))))))
6271 ;;; Commands for interfacing with message
6275 (defun message-mail (&optional to subject
6276 other-headers continue switch-function
6277 yank-action send-actions)
6278 "Start editing a mail message to be sent.
6279 OTHER-HEADERS is an alist of header/value pairs."
6281 (let ((message-this-is-mail t) replybuffer)
6282 (unless (message-mail-user-agent)
6283 (message-pop-to-buffer (message-buffer-name "mail" to)))
6284 ;; FIXME: message-mail should do something if YANK-ACTION is not
6286 (and (consp yank-action) (eq (car yank-action) 'insert-buffer)
6287 (setq replybuffer (nth 1 yank-action)))
6290 `((To . ,(or to "")) (Subject . ,(or subject "")))
6291 (when other-headers other-headers))
6292 replybuffer send-actions)
6293 ;; FIXME: Should return nil if failure.
6297 (defun message-news (&optional newsgroups subject)
6298 "Start editing a news article to be sent."
6300 (let ((message-this-is-news t))
6301 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
6302 (message-setup `((Newsgroups . ,(or newsgroups ""))
6303 (Subject . ,(or subject ""))))))
6305 (defun message-get-reply-headers (wide &optional to-address address-headers)
6306 (let (follow-to mct never-mct to cc author mft recipients extra)
6307 ;; Find all relevant headers we need.
6309 (message-narrow-to-headers-or-head)
6310 (let ((mrt (when message-use-mail-reply-to
6311 (message-fetch-field "mail-reply-to")))
6312 (reply-to (message-fetch-field "reply-to")))
6313 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
6314 ;; message-header-synonyms.
6315 (setq to (or (message-fetch-field "to")
6316 (and (loop for synonym in message-header-synonyms
6317 when (memq 'Original-To synonym)
6319 (message-fetch-field "original-to")))
6320 cc (message-fetch-field "cc")
6321 extra (when message-extra-wide-headers
6322 (mapconcat 'identity
6323 (mapcar 'message-fetch-field
6324 message-extra-wide-headers)
6326 mct (when message-use-mail-copies-to
6327 (message-fetch-field "mail-copies-to"))
6330 (message-fetch-field "from")
6332 mft (when (and (not (or to-address mrt reply-to))
6333 message-use-mail-followup-to)
6334 (message-fetch-field "mail-followup-to")))))
6337 ;; Handle special values of Mail-Copies-To.
6339 (cond ((or (equal (downcase mct) "never")
6340 (equal (downcase mct) "nobody"))
6341 (when (or (not (eq message-use-mail-copies-to 'ask))
6343 (concat "Obey Mail-Copies-To: never? ") t "\
6344 You should normally obey the Mail-Copies-To: header.
6346 `Mail-Copies-To: " mct "'
6347 directs you not to send your response to the author."))
6350 ((or (equal (downcase mct) "always")
6351 (equal (downcase mct) "poster"))
6352 (if (or (not (eq message-use-mail-copies-to 'ask))
6354 (concat "Obey Mail-Copies-To: always? ") t "\
6355 You should normally obey the Mail-Copies-To: header.
6357 `Mail-Copies-To: " mct "'
6358 sends a copy of your response to the author."))
6361 ((and (eq message-use-mail-copies-to 'ask)
6362 (not (message-y-or-n-p
6363 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
6364 You should normally obey the Mail-Copies-To: header.
6366 `Mail-Copies-To: " mct "'
6367 sends a copy of your response to " (if (string-match "," mct)
6368 "the specified addresses"
6369 "that address") ".")))
6372 ;; Build (textual) list of new recipient addresses.
6375 (setq recipients (concat ", " author)))
6377 (dolist (header address-headers)
6378 (let ((value (message-fetch-field header)))
6380 (setq recipients (concat recipients ", " value))))))
6382 (string-match "[^ \t,]" mft)
6383 (or (not (eq message-use-mail-followup-to 'ask))
6384 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
6385 You should normally obey the Mail-Followup-To: header. In this
6386 article, it has the value of
6390 which directs your response to " (if (string-match "," mft)
6391 "the specified addresses"
6392 "that address only") ".
6394 Most commonly, Mail-Followup-To is used by a mailing list poster to
6395 express that responses should be sent to just the list, and not the
6398 If a message is posted to several mailing lists, Mail-Followup-To may
6399 also be used to direct the following discussion to one list only,
6400 because discussions that are spread over several lists tend to be
6401 fragmented and very difficult to follow.
6403 Also, some source/announcement lists are not intended for discussion;
6404 responses here are directed to other addresses.")))
6405 (setq recipients (concat ", " mft)))
6407 (setq recipients (concat ", " to-address))
6408 ;; If the author explicitly asked for a copy, we don't deny it to them.
6409 (if mct (setq recipients (concat recipients ", " mct))))
6411 (setq recipients (if never-mct "" (concat ", " author)))
6412 (if to (setq recipients (concat recipients ", " to)))
6413 (if cc (setq recipients (concat recipients ", " cc)))
6414 (if extra (setq recipients (concat recipients ", " extra)))
6415 (if mct (setq recipients (concat recipients ", " mct)))))
6416 (if (>= (length recipients) 2)
6417 ;; Strip the leading ", ".
6418 (setq recipients (substring recipients 2)))
6419 ;; Squeeze whitespace.
6420 (while (string-match "[ \t][ \t]+" recipients)
6421 (setq recipients (replace-match " " t t recipients)))
6422 ;; Remove addresses that match `rmail-dont-reply-to-names'.
6423 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
6424 (setq recipients (rmail-dont-reply-to recipients)))
6425 ;; Perhaps "Mail-Copies-To: never" removed the only address?
6426 (if (string-equal recipients "")
6427 (setq recipients author))
6428 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
6432 (cons (downcase (mail-strip-quoted-names addr)) addr))
6433 (message-tokenize-header recipients)))
6434 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
6435 (let ((s recipients))
6437 (setq recipients (delq (assoc (car (pop s)) s) recipients))))
6439 ;; Remove hierarchical lists that are contained within each other,
6440 ;; if message-hierarchical-addresses is defined.
6441 (when message-hierarchical-addresses
6442 (let ((plain-addrs (mapcar 'car recipients))
6445 (setq subaddrs (assoc (car plain-addrs)
6446 message-hierarchical-addresses)
6447 plain-addrs (cdr plain-addrs))
6449 (setq subaddrs (cdr subaddrs))
6451 (setq recip (assoc (car subaddrs) recipients)
6452 subaddrs (cdr subaddrs))
6454 (setq recipients (delq recip recipients))))))))
6456 ;; Build the header alist. Allow the user to be asked whether
6457 ;; or not to reply to all recipients in a wide reply.
6458 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
6459 (when (and recipients
6460 (or (not message-wide-reply-confirm-recipients)
6461 (y-or-n-p "Reply to all recipients? ")))
6462 (setq recipients (mapconcat
6463 (lambda (addr) (cdr addr)) recipients ", "))
6464 (if (string-match "^ +" recipients)
6465 (setq recipients (substring recipients (match-end 0))))
6466 (push (cons 'Cc recipients) follow-to)))
6470 (defun message-reply (&optional to-address wide)
6471 "Start editing a reply to the article in the current buffer."
6473 (require 'gnus-sum) ; for gnus-list-identifiers
6474 (let ((cur (current-buffer))
6476 references message-id follow-to
6477 (inhibit-point-motion-hooks t)
6478 (message-this-is-mail t)
6479 gnus-warning in-reply-to)
6481 (message-narrow-to-head-1)
6482 ;; Allow customizations to have their say.
6484 ;; This is a regular reply.
6485 (when (functionp message-reply-to-function)
6487 (setq follow-to (funcall message-reply-to-function))))
6488 ;; This is a followup.
6489 (when (functionp message-wide-reply-to-function)
6492 (funcall message-wide-reply-to-function)))))
6493 (setq message-id (message-fetch-field "message-id" t)
6494 references (message-fetch-field "references")
6495 date (message-fetch-field "date")
6496 from (message-fetch-field "from")
6497 subject (or (message-fetch-field "subject") "none"))
6498 (when gnus-list-identifiers
6499 (setq subject (message-strip-list-identifiers subject)))
6500 (setq subject (message-make-followup-subject subject))
6501 (when message-subject-trailing-was-query
6502 (setq subject (message-strip-subject-trailing-was subject)))
6504 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6505 (string-match "<[^>]+>" gnus-warning))
6506 (setq message-id (match-string 0 gnus-warning)))
6509 (setq follow-to (message-get-reply-headers wide to-address)))
6511 ;; Get the references from "In-Reply-To" field if there were
6512 ;; no references and "In-Reply-To" field looks promising.
6514 (when (and (setq in-reply-to (message-fetch-field "in-reply-to"))
6515 (string-match "<[^>]+>" in-reply-to))
6516 (setq references (match-string 0 in-reply-to)))))
6518 (unless (message-mail-user-agent)
6519 (message-pop-to-buffer
6520 (message-buffer-name
6521 (if wide "wide reply" "reply") from
6522 (if wide to-address nil))))
6524 (setq message-reply-headers
6525 (make-full-mail-header-from-decoded-header
6526 0 subject from date message-id references 0 0 ""))
6529 `((Subject . ,subject)
6534 (defun message-wide-reply (&optional to-address)
6535 "Make a \"wide\" reply to the message in the current buffer."
6537 (message-reply to-address t))
6540 (defun message-followup (&optional to-newsgroups)
6541 "Follow up to the message in the current buffer.
6542 If TO-NEWSGROUPS, use that as the new Newsgroups line."
6544 (require 'gnus-sum) ; for gnus-list-identifiers
6545 (let ((cur (current-buffer))
6546 from subject date reply-to mrt mct mft
6547 references message-id follow-to
6548 (inhibit-point-motion-hooks t)
6549 (message-this-is-news t)
6550 followup-to distribution newsgroups gnus-warning posted-to)
6552 (message-narrow-to-head)
6553 (when (functionp message-followup-to-function)
6555 (funcall message-followup-to-function)))
6556 (setq from (message-fetch-field "from")
6557 date (message-fetch-field "date")
6558 subject (or (message-fetch-field "subject") "none")
6559 references (message-fetch-field "references")
6560 message-id (message-fetch-field "message-id" t)
6561 followup-to (message-fetch-field "followup-to")
6562 newsgroups (message-fetch-field "newsgroups")
6563 posted-to (message-fetch-field "posted-to")
6564 reply-to (message-fetch-field "reply-to")
6565 mrt (when message-use-mail-reply-to
6566 (message-fetch-field "mail-reply-to"))
6567 distribution (message-fetch-field "distribution")
6568 mct (when message-use-mail-copies-to
6569 (message-fetch-field "mail-copies-to"))
6570 mft (when message-use-mail-followup-to
6571 (message-fetch-field "mail-followup-to")))
6572 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6573 (string-match "<[^>]+>" gnus-warning))
6574 (setq message-id (match-string 0 gnus-warning)))
6575 ;; Remove bogus distribution.
6576 (when (and (stringp distribution)
6577 (let ((case-fold-search t))
6578 (string-match "world" distribution)))
6579 (setq distribution nil))
6580 (if gnus-list-identifiers
6581 (setq subject (message-strip-list-identifiers subject)))
6582 (setq subject (message-make-followup-subject subject))
6583 (when message-subject-trailing-was-query
6584 (setq subject (message-strip-subject-trailing-was subject)))
6587 ;; Handle special values of Mail-Copies-To.
6590 ((and (or (equal (downcase mct) "never")
6591 (equal (downcase mct) "nobody")))
6593 ((and (or (equal (downcase mct) "always")
6594 (equal (downcase mct) "poster")))
6595 (if (or (not (eq message-use-mail-copies-to 'ask))
6597 (concat "Obey Mail-Copies-To: always? ") t "\
6598 You should normally obey the Mail-Copies-To: header.
6600 `Mail-Copies-To: " mct "'
6601 sends a copy of your response to the author."))
6602 (setq mct (or mrt reply-to from))
6604 ((and (eq message-use-mail-copies-to 'ask)
6607 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
6608 You should normally obey the Mail-Copies-To: header.
6610 `Mail-Copies-To: " mct "'
6611 sends a copy of your response to " (if (string-match "," mct)
6612 "the specified addresses"
6613 "that address") ".")))
6618 (to-newsgroups (setq follow-to (list (cons 'Newsgroups to-newsgroups))))
6619 ;; Handle Followup-To.
6622 ((equal (downcase followup-to) "poster")
6623 (if (or (and followup-to (eq message-use-followup-to 'use))
6624 (message-y-or-n-p "Obey Followup-To: poster? " t "\
6625 You should normally obey the Followup-To: header.
6627 `Followup-To: poster'
6628 sends your response via e-mail instead of news.
6630 A typical situation where `Followup-To: poster' is used is when the author
6631 does not read the newsgroup, so he wouldn't see any replies sent to it."))
6632 (setq message-this-is-news nil
6634 follow-to (list (cons 'To (or mrt reply-to from ""))))
6635 (setq follow-to (list (cons 'Newsgroups newsgroups)))))
6637 (if (or (equal followup-to newsgroups)
6638 (not (and followup-to (eq message-use-followup-to 'ask)))
6640 (concat "Obey Followup-To: " followup-to "? ") t "\
6641 You should normally obey the Followup-To: header.
6643 `Followup-To: " followup-to "'
6644 directs your response to " (if (string-match "," followup-to)
6645 "the specified newsgroups"
6646 "that newsgroup only") ".
6648 If a message is posted to several newsgroups, Followup-To is often
6649 used to direct the following discussion to one newsgroup only,
6650 because discussions that are spread over several newsgroup tend to
6651 be fragmented and very difficult to follow.
6653 Also, some source/announcement newsgroups are not intended for discussion;
6654 responses here are directed to other newsgroups."))
6655 (setq follow-to (list (cons 'Newsgroups followup-to)))
6656 (setq follow-to (list (cons 'Newsgroups newsgroups)))))))
6657 ;; Handle Mail-Followup-To, followup via e-mail.
6659 (or (not (eq message-use-mail-followup-to 'ask))
6661 (concat "Obey Mail-Followup-To: " mft "? ") t "\
6662 You should normally obey the Mail-Followup-To: header.
6664 `Mail-Followup-To: " mft "'
6665 directs your response to " (if (string-match "," mft)
6666 "the specified addresses"
6667 "that address only") " instead of news.
6669 A typical situation where Mail-Followup-To is used is when the author thinks
6670 that further discussion should take place only in "
6671 (if (string-match "," mft)
6672 "the specified mailing lists"
6673 "that mailing list") ".")))
6674 (setq message-this-is-news nil
6676 follow-to (list (cons 'To mft))))
6677 (posted-to (setq follow-to (list (cons 'Newsgroups posted-to))))
6679 (setq follow-to (list (cons 'Newsgroups newsgroups))))))
6681 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
6683 (setq message-reply-headers
6684 (make-full-mail-header-from-decoded-header
6685 0 subject from date message-id references 0 0 ""))
6688 `((Subject . ,subject)
6690 ,@(and mct (list (cons 'Cc mct)))
6691 ,@(and distribution (list (cons 'Distribution distribution))))
6694 (defun message-is-yours-p ()
6695 "Non-nil means current article is yours.
6696 If you have added 'cancel-messages to 'message-shoot-gnksa-feet', all articles
6697 are yours except those that have Cancel-Lock header not belonging to you.
6698 Instead of shooting GNKSA feet, you should modify 'message-alternative-emails'
6699 regexp to match all of yours addresses."
6700 ;; Canlock-logic as suggested by Per Abrahamsen
6701 ;; <abraham@dina.kvl.dk>
6703 ;; IF article has cancel-lock THEN
6704 ;; IF we can verify it THEN
6707 ;; error: cancellock: article is not yours
6709 ;; Use old rules, comparing sender...
6712 (message-narrow-to-head-1)
6713 (if (message-fetch-field "Cancel-Lock")
6714 (if (null (canlock-verify))
6716 (error "Failed to verify Cancel-lock: This article is not yours"))
6719 (message-gnksa-enable-p 'cancel-messages)
6720 (and (setq sender (message-fetch-field "sender"))
6721 (string-equal (downcase sender)
6722 (downcase (message-make-sender))))
6723 ;; Email address in From field equals to our address
6724 (and (setq from (message-fetch-field "from"))
6726 (downcase (cadr (std11-extract-address-components from)))
6727 (downcase (cadr (std11-extract-address-components
6728 (message-make-from))))))
6729 ;; Email address in From field matches
6730 ;; 'message-alternative-emails' regexp
6732 message-alternative-emails
6734 message-alternative-emails
6735 (cadr (std11-extract-address-components from))))))))))
6738 (defun message-cancel-news (&optional arg)
6739 "Cancel an article you posted.
6740 If ARG, allow editing of the cancellation message."
6742 (unless (message-news-p)
6743 (error "This is not a news article; canceling is impossible"))
6744 (let (from newsgroups message-id distribution buf)
6746 ;; Get header info from original article.
6748 (message-narrow-to-head-1)
6749 (setq from (message-fetch-field "from")
6750 newsgroups (message-fetch-field "newsgroups")
6751 message-id (message-fetch-field "message-id" t)
6752 distribution (message-fetch-field "distribution")))
6753 ;; Make sure that this article was written by the user.
6754 (unless (message-is-yours-p)
6755 (error "This article is not yours"))
6756 (when (yes-or-no-p "Do you really want to cancel this article? ")
6757 ;; Make control message.
6760 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
6762 (insert "Newsgroups: " newsgroups "\n"
6764 "Subject: cmsg cancel " message-id "\n"
6765 "Control: cancel " message-id "\n"
6767 (concat "Distribution: " distribution "\n")
6769 mail-header-separator "\n"
6770 message-cancel-message)
6771 (run-hooks 'message-cancel-hook)
6773 (message "Canceling your article...")
6774 (if (let ((message-syntax-checks
6775 'dont-check-for-anything-just-trust-me)
6776 (message-encoding-buffer (current-buffer))
6777 (message-edit-buffer (current-buffer)))
6778 (message-send-news))
6779 (message "Canceling your article...done"))
6780 (kill-buffer buf))))))
6782 (defun message-supersede-setup-for-mime-edit ()
6783 (set (make-local-variable 'message-setup-hook) nil)
6787 (defun message-supersede ()
6788 "Start composing a message to supersede the current message.
6789 This is done simply by taking the old article and adding a Supersedes
6790 header line with the old Message-ID."
6792 (let ((cur (current-buffer)))
6793 ;; Check whether the user owns the article that is to be superseded.
6794 (unless (message-is-yours-p)
6795 (error "This article is not yours"))
6796 ;; Get a normal message buffer.
6797 (message-pop-to-buffer (message-buffer-name "supersede"))
6798 (insert-buffer-substring cur)
6799 (message-narrow-to-head-1)
6800 ;; Remove unwanted headers.
6801 (when message-ignored-supersedes-headers
6802 (message-remove-header message-ignored-supersedes-headers t))
6803 (goto-char (point-min))
6804 (if (not (re-search-forward "^Message-ID: " nil t))
6805 (error "No Message-ID in this article")
6806 (replace-match "Supersedes: " t t))
6807 (goto-char (point-max))
6808 (insert mail-header-separator)
6810 (when message-supersede-setup-function
6811 (funcall message-supersede-setup-function))
6812 (run-hooks 'message-supersede-setup-hook)
6813 (goto-char (point-min))
6814 (search-forward (concat "\n" mail-header-separator "\n") nil t)))
6817 (defun message-recover ()
6818 "Reread contents of current buffer from its last auto-save file."
6820 (let ((file-name (make-auto-save-file-name)))
6821 (cond ((save-window-excursion
6822 (if (not (eq system-type 'vax-vms))
6823 (with-output-to-temp-buffer "*Directory*"
6824 (with-current-buffer standard-output
6825 (fundamental-mode)) ; for Emacs 20.4+
6826 (buffer-disable-undo standard-output)
6827 (let ((default-directory "/"))
6829 "ls" nil standard-output nil "-l" file-name))))
6830 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
6831 (let ((buffer-read-only nil))
6833 (insert-file-contents file-name nil)))
6834 (t (error "message-recover cancelled")))))
6836 ;;; Washing Subject:
6838 (defun message-wash-subject (subject)
6839 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
6840 Previous forwarders, replyers, etc. may add it."
6843 (goto-char (point-min))
6844 ;; strip Re/Fwd stuff off the beginning
6845 (while (re-search-forward
6846 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
6849 ;; and gnus-style forwards [foo@bar.com] subject
6850 (goto-char (point-min))
6851 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
6855 (goto-char (point-max))
6856 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
6859 ;; and finally, any whitespace that was left-over
6860 (goto-char (point-min))
6861 (while (re-search-forward "^[ \t]+" nil t)
6863 (goto-char (point-max))
6864 (while (re-search-backward "[ \t]+$" nil t)
6869 ;;; Forwarding messages.
6871 (defvar message-forward-decoded-p nil
6872 "Non-nil means the original message is decoded.")
6874 (defun message-forward-subject-name-subject (subject)
6875 "Generate a SUBJECT for a forwarded message.
6876 The form is: [Source] Subject, where if the original message was mail,
6877 Source is the name of the sender, and if the original message was
6878 news, Source is the list of newsgroups is was posted to."
6880 (let ((group (message-fetch-field "newsgroups"))
6883 (gnus-group-decoded-name group)
6884 (or (and (setq from (message-fetch-field "from"))
6885 (car (std11-extract-address-components
6886 (nnheader-decode-from from))))
6890 (defun message-forward-subject-author-subject (subject)
6891 "Generate a SUBJECT for a forwarded message.
6892 The form is: [Source] Subject, where if the original message was mail,
6893 Source is the sender, and if the original message was news, Source is
6894 the list of newsgroups is was posted to."
6896 (let ((group (message-fetch-field "newsgroups"))
6899 (gnus-group-decoded-name group)
6900 (if (setq from (message-fetch-field "from"))
6901 (nnheader-decode-from from)
6905 (defun message-forward-subject-fwd (subject)
6906 "Generate a SUBJECT for a forwarded message.
6907 The form is: Fwd: Subject, where Subject is the original subject of
6909 (if (string-match "^Fwd: " subject)
6911 (concat "Fwd: " subject)))
6913 (defun message-make-forward-subject ()
6914 "Return a Subject header suitable for the message in the current buffer."
6917 (message-narrow-to-head-1)
6918 (let ((funcs message-make-forward-subject-function)
6919 (subject (message-fetch-field "Subject")))
6922 (if message-forward-decoded-p
6924 (nnheader-decode-subject subject))
6926 (when message-wash-forwarded-subjects
6927 (setq subject (message-wash-subject subject)))
6928 ;; Make sure funcs is a list.
6931 (setq funcs (list funcs)))
6932 ;; Apply funcs in order, passing subject generated by previous
6933 ;; func to the next one.
6934 (dolist (func funcs)
6935 (when (functionp func)
6936 (setq subject (funcall func subject))))
6940 (defun message-forward (&optional news)
6941 "Forward the current message via mail.
6942 Optional NEWS will use news to forward instead of mail."
6944 (let ((cur (current-buffer))
6945 (subject (message-make-forward-subject)))
6947 (message-news nil subject)
6948 (message-mail nil subject))
6949 (message-forward-make-body cur)))
6951 (defun message-forward-make-body-plain (forward-buffer)
6953 "\n-------------------- Start of forwarded message --------------------\n")
6954 (let ((b (point)) e)
6957 (mm-disable-multibyte)
6959 (with-current-buffer forward-buffer
6960 (mm-with-unibyte-current-buffer (buffer-string))))
6961 (mm-enable-multibyte)
6963 (goto-char (point-min))
6964 (when (looking-at "From ")
6965 (replace-match "X-From-Line: "))
6969 "\n-------------------- End of forwarded message --------------------\n")
6970 (when message-forward-ignored-headers
6972 (narrow-to-region b e)
6974 (narrow-to-region (point)
6975 (or (search-forward "\n\n" nil t) (point)))
6976 (message-remove-header message-forward-ignored-headers t)))))
6978 (defun message-forward-make-body-mime (forward-buffer)
6979 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
6980 (let ((b (point)) e)
6982 (narrow-to-region (point) (point))
6983 (mml-insert-buffer forward-buffer)
6984 (goto-char (point-min))
6985 (when (looking-at "From ")
6986 (replace-match "X-From-Line: "))
6987 (goto-char (point-max)))
6989 (insert "<#/part>\n")))
6991 (defun message-forward-make-body-mml (forward-buffer)
6992 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
6993 (let ((b (point)) e)
6994 (if (not message-forward-decoded-p)
6997 (mm-disable-multibyte)
6999 (with-current-buffer forward-buffer
7000 (mm-with-unibyte-current-buffer (buffer-string))))
7001 (mm-enable-multibyte)
7003 (goto-char (point-min))
7004 (when (looking-at "From ")
7005 (replace-match "X-From-Line: "))
7008 (narrow-to-region (point) (point))
7009 (mml-insert-buffer forward-buffer)
7010 (goto-char (point-min))
7011 (when (looking-at "From ")
7012 (replace-match "X-From-Line: "))
7013 (goto-char (point-max))))
7015 (insert "<#/mml>\n")
7016 (when (and (not message-forward-decoded-p)
7017 message-forward-ignored-headers)
7019 (narrow-to-region b e)
7021 (narrow-to-region (point)
7022 (or (search-forward "\n\n" nil t) (point)))
7023 (message-remove-header message-forward-ignored-headers t)))))
7025 (defun message-forward-make-body-digest-plain (forward-buffer)
7027 "\n-------------------- Start of forwarded message --------------------\n")
7028 (let ((b (point)) e)
7029 (mml-insert-buffer forward-buffer)
7032 "\n-------------------- End of forwarded message --------------------\n")))
7034 (defun message-forward-make-body-digest-mime (forward-buffer)
7035 (insert "\n<#multipart type=digest>\n")
7036 (let ((b (point)) e)
7037 (insert-buffer-substring forward-buffer)
7039 (insert "<#/multipart>\n")
7041 (narrow-to-region b e)
7043 (narrow-to-region (point)
7044 (or (search-forward "\n\n" nil t) (point)))
7045 (delete-region (point-min) (point-max)))))
7047 (defun message-forward-make-body-digest (forward-buffer)
7048 (if message-forward-as-mime
7049 (message-forward-make-body-digest-mime forward-buffer)
7050 (message-forward-make-body-digest-plain forward-buffer)))
7053 (defun message-forward-make-body (forward-buffer)
7054 ;; Put point where we want it before inserting the forwarded
7056 ;; Note that this function definition for T-gnus is totally different
7057 ;; from the original Gnus."
7058 (if message-forward-before-signature
7060 (goto-char (point-max)))
7061 ;; Make sure we're at the start of the line.
7064 ;; Narrow to the area we are to insert.
7065 (narrow-to-region (point) (point))
7066 ;; Insert the separators and the forwarded buffer.
7067 (insert message-forward-start-separator)
7068 (let ((art-beg (point)))
7069 (insert-buffer-substring forward-buffer)
7070 (goto-char (point-max))
7071 (insert message-forward-end-separator)
7072 (set-text-properties (point-min) (point-max) nil)
7073 ;; Remove all unwanted headers.
7075 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
7078 (goto-char (point-min))
7079 (message-remove-header message-included-forward-headers t nil t)
7081 (message-position-point)))
7084 (defun message-forward-rmail-make-body (forward-buffer)
7085 (save-window-excursion
7086 (set-buffer forward-buffer)
7087 (if (rmail-msg-is-pruned)
7088 (rmail-msg-restore-non-pruned-header)))
7089 (message-forward-make-body forward-buffer))
7091 (eval-when-compile (defvar rmail-enable-mime-composing))
7093 ;; Fixme: Should have defcustom.
7095 (defun message-insinuate-rmail ()
7096 "Let RMAIL use message to forward."
7098 (setq rmail-enable-mime-composing t)
7099 (setq rmail-insert-mime-forwarded-message-function
7100 'message-forward-rmail-make-body))
7103 (defun message-resend (address)
7104 "Resend the current article to ADDRESS."
7106 (list (message-read-from-minibuffer "Resend message to: ")))
7107 (message "Resending message to %s..." address)
7109 (let ((cur (current-buffer))
7111 ;; We first set up a normal mail buffer.
7112 (unless (message-mail-user-agent)
7113 (set-buffer (get-buffer-create " *message resend*"))
7115 (let ((message-this-is-mail t)
7117 (message-setup `((To . ,address))))
7118 ;; Insert our usual headers.
7119 (message-generate-headers '(From Date To Message-ID))
7120 (message-narrow-to-headers)
7121 ;; Remove X-Draft-From header etc.
7122 (message-remove-header message-ignored-mail-headers t)
7123 ;; Rename them all to "Resent-*".
7124 (goto-char (point-min))
7125 (while (re-search-forward "^[A-Za-z]" nil t)
7130 (delete-region (point) (point-max))
7132 ;; Insert the message to be resent.
7133 (insert-buffer-substring cur)
7134 (goto-char (point-min))
7135 (search-forward "\n\n")
7138 (narrow-to-region beg (point))
7139 (message-remove-header message-ignored-resent-headers t)
7140 (goto-char (point-max)))
7141 (insert mail-header-separator)
7142 ;; Rename all old ("Also-")Resent headers.
7143 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
7146 ;; Quote any "From " lines at the beginning.
7148 (when (looking-at "From ")
7149 (replace-match "X-From-Line: "))
7151 (let ((message-encoding-buffer (current-buffer))
7152 (message-edit-buffer (current-buffer))
7153 message-required-mail-headers)
7154 (message-send-mail))
7155 (kill-buffer (current-buffer)))
7156 (message "Resending message to %s...done" address)))
7158 (defun message-bounce-setup-for-mime-edit ()
7159 (set (make-local-variable 'message-setup-hook) nil)
7163 (defun message-bounce ()
7164 "Re-mail the current message.
7165 This only makes sense if the current message is a bounce message that
7166 contains some mail you have written which has been bounced back to
7169 (let ((cur (current-buffer))
7170 mime-boundary boundary)
7171 (message-pop-to-buffer (message-buffer-name "bounce"))
7172 (insert-buffer-substring cur)
7174 (message-narrow-to-head)
7175 (if (and (message-fetch-field "MIME-Version")
7176 (setq mime-boundary (message-fetch-field "Content-Type")))
7177 (if (string-match "boundary=\"\\([^\"]+\\)\"" mime-boundary)
7178 (setq mime-boundary (concat (regexp-quote
7179 (match-string 1 mime-boundary))
7180 " *\nContent-Type: message/rfc822"))
7181 (setq mime-boundary nil)))
7183 (goto-char (point-min))
7184 (re-search-forward "\n\n+" nil t)
7185 (setq boundary (point))
7186 ;; We remove everything before the bounced mail.
7187 (if (or (and mime-boundary
7188 (re-search-forward mime-boundary nil t)
7190 (re-search-forward message-unsent-separator nil t)
7192 (search-forward "\n\n" nil 'move)
7193 (re-search-backward "^Return-Path:.*\n" boundary t)))
7196 (delete-region (point-min)
7197 (if (re-search-forward "^[^ \n\t]+:" nil t)
7200 (when (re-search-backward "^.?From .*\n" nil t)
7201 (delete-region (match-beginning 0) (match-end 0))))
7203 (message-narrow-to-head-1)
7204 (message-remove-header message-ignored-bounced-headers t)
7205 (goto-char (point-max))
7206 (insert mail-header-separator))
7207 (when message-bounce-setup-function
7208 (funcall message-bounce-setup-function))
7209 (run-hooks 'message-bounce-setup-hook)
7210 (message-position-point)))
7213 ;;; Interactive entry points for new message buffers.
7217 (defun message-mail-other-window (&optional to subject)
7218 "Like `message-mail' command, but display mail buffer in another window."
7220 (unless (message-mail-user-agent)
7221 (let ((pop-up-windows t)
7222 (special-display-buffer-names nil)
7223 (special-display-regexps nil)
7224 (same-window-buffer-names nil)
7225 (same-window-regexps nil))
7226 (message-pop-to-buffer (message-buffer-name "mail" to))))
7227 (let ((message-this-is-mail t))
7228 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7229 nil nil 'switch-to-buffer-other-window)))
7232 (defun message-mail-other-frame (&optional to subject)
7233 "Like `message-mail' command, but display mail buffer in another frame."
7235 (unless (message-mail-user-agent)
7236 (let ((pop-up-frames t)
7237 (special-display-buffer-names nil)
7238 (special-display-regexps nil)
7239 (same-window-buffer-names nil)
7240 (same-window-regexps nil))
7241 (message-pop-to-buffer (message-buffer-name "mail" to))))
7242 (let ((message-this-is-mail t))
7243 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7244 nil nil 'switch-to-buffer-other-frame)))
7247 (defun message-news-other-window (&optional newsgroups subject)
7248 "Start editing a news article to be sent."
7250 (let ((pop-up-windows t)
7251 (special-display-buffer-names nil)
7252 (special-display-regexps nil)
7253 (same-window-buffer-names nil)
7254 (same-window-regexps nil))
7255 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
7256 (let ((message-this-is-news t))
7257 (message-setup `((Newsgroups . ,(or newsgroups ""))
7258 (Subject . ,(or subject ""))))))
7261 (defun message-news-other-frame (&optional newsgroups subject)
7262 "Start editing a news article to be sent."
7264 (let ((pop-up-frames t)
7265 (special-display-buffer-names nil)
7266 (special-display-regexps nil)
7267 (same-window-buffer-names nil)
7268 (same-window-regexps nil))
7269 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
7270 (let ((message-this-is-news t))
7271 (message-setup `((Newsgroups . ,(or newsgroups ""))
7272 (Subject . ,(or subject ""))))))
7276 ;; This code should be moved to underline.el (from which it is stolen).
7279 (defun bold-region (start end)
7280 "Bold all nonblank characters in the region.
7281 Works by overstriking characters.
7282 Called from program, takes two arguments START and END
7283 which specify the range to operate on."
7286 (let ((end1 (make-marker)))
7287 (move-marker end1 (max start end))
7288 (goto-char (min start end))
7289 (while (< (point) end1)
7290 (or (looking-at "[_\^@- ]")
7291 (insert (char-after) "\b"))
7292 (forward-char 1)))))
7295 (defun unbold-region (start end)
7296 "Remove all boldness (overstruck characters) in the region.
7297 Called from program, takes two arguments START and END
7298 which specify the range to operate on."
7301 (let ((end1 (make-marker)))
7302 (move-marker end1 (max start end))
7303 (goto-char (min start end))
7304 (while (search-forward "\b" end1 t)
7305 (if (eq (char-after) (char-after (- (point) 2)))
7306 (delete-char -2))))))
7308 (defun message-exchange-point-and-mark ()
7309 "Exchange point and mark, but don't activate region if it was inactive."
7311 (message-mark-active-p)
7312 (exchange-point-and-mark))
7313 (setq mark-active nil)))
7315 (defalias 'message-make-overlay 'make-overlay)
7316 (defalias 'message-delete-overlay 'delete-overlay)
7317 (defalias 'message-overlay-put 'overlay-put)
7318 (defun message-kill-all-overlays ()
7319 (if (featurep 'xemacs)
7320 (map-extents (lambda (extent ignore) (delete-extent extent)))
7321 (mapcar #'delete-overlay (overlays-in (point-min) (point-max)))))
7323 ;; Support for toolbar
7325 (defvar tool-bar-map)
7326 (defvar tool-bar-mode))
7328 (defun message-tool-bar-local-item-from-menu (command icon in-map &optional from-map &rest props)
7329 ;; We need to make tool bar entries in local keymaps with
7330 ;; `tool-bar-local-item-from-menu' in Emacs > 21.3
7331 (if (fboundp 'tool-bar-local-item-from-menu)
7332 ;; This is for Emacs 21.3
7333 (tool-bar-local-item-from-menu command icon in-map from-map props)
7334 (tool-bar-add-item-from-menu command icon from-map props)))
7336 (defun message-tool-bar-map ()
7337 (or message-tool-bar-map
7338 (setq message-tool-bar-map
7340 (condition-case nil (require 'tool-bar) (error nil))
7341 (fboundp 'tool-bar-add-item-from-menu)
7343 (let ((tool-bar-map (copy-keymap tool-bar-map))
7344 (load-path (mm-image-load-path)))
7345 ;; Zap some items which aren't so relevant and take
7347 (dolist (key '(print-buffer kill-buffer save-buffer
7348 write-file dired open-file))
7349 (define-key tool-bar-map (vector key) nil))
7350 (message-tool-bar-local-item-from-menu
7351 'message-send-and-exit "mail_send" tool-bar-map message-mode-map)
7352 (message-tool-bar-local-item-from-menu
7353 'message-kill-buffer "close" tool-bar-map message-mode-map)
7354 (message-tool-bar-local-item-from-menu
7355 'message-dont-send "cancel" tool-bar-map message-mode-map)
7356 ;; (message-tool-bar-local-item-from-menu
7357 ;; 'mime-edit-insert-file "attach"
7358 ;; tool-bar-map mime-edit-mode-map)
7359 (message-tool-bar-local-item-from-menu
7360 'ispell-message "spell" tool-bar-map message-mode-map)
7361 ;; (message-tool-bar-local-item-from-menu
7362 ;; 'mime-edit-preview-message "preview"
7363 ;; tool-bar-map mime-edit-mode-map)
7364 (message-tool-bar-local-item-from-menu
7365 'message-insert-importance-high "important"
7366 tool-bar-map message-mode-map)
7367 (message-tool-bar-local-item-from-menu
7368 'message-insert-importance-low "unimportant"
7369 tool-bar-map message-mode-map)
7370 (message-tool-bar-local-item-from-menu
7371 'message-insert-disposition-notification-to "receipt"
7372 tool-bar-map message-mode-map)
7375 ;;; Group name completion.
7377 (defcustom message-newgroups-header-regexp
7378 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
7379 "Regexp that match headers that lists groups."
7383 (defcustom message-completion-alist
7384 (list (cons message-newgroups-header-regexp 'message-expand-group)
7385 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name)
7386 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
7387 . message-expand-name)
7388 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
7389 . message-expand-name))
7390 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
7393 :type '(alist :key-type regexp :value-type function))
7395 (defcustom message-expand-name-databases
7396 (list 'bbdb 'eudc 'lsdb)
7397 "List of databases to try for name completion (`message-expand-name').
7398 Each element is a symbol and can be `bbdb', `eudc' or `lsdb'."
7400 :type '(set (const bbdb) (const eudc) (const lsdb)))
7402 (defcustom message-expand-name-function
7403 (cond ((and (boundp 'eudc-protocol)
7405 'eudc-expand-inline)
7406 ((fboundp 'bbdb-complete-name)
7407 'bbdb-complete-name)
7408 ((fboundp 'lsdb-complete-name)
7409 'lsdb-complete-name)
7411 "*A function called to expand addresses in field body.
7412 This variable is semi-obsolete, set it as nil and use
7413 `message-expand-name-databases' instead."
7415 :type '(radio (const :format "Invalidate it: %v\n" nil)
7416 (function-item :format "eudc: %v\n" eudc-expand-inline)
7417 (function-item :format "bbdb: %v\n" bbdb-complete-name)
7418 (function-item :format "lsdb: %v\n" lsdb-complete-name)
7419 (function :value expand-abbrev)))
7421 (defcustom message-tab-body-function nil
7422 "*Function to execute when `message-tab' (TAB) is executed in the body.
7423 If nil, the function bound in `text-mode-map' or `global-map' is executed."
7426 :link '(custom-manual "(message)Various Commands")
7429 (defun message-tab ()
7430 "Complete names according to `message-completion-alist'.
7431 Execute function specified by `message-tab-body-function' when not in
7434 (let ((alist message-completion-alist))
7436 (let ((mail-abbrev-mode-regexp (caar alist)))
7437 (not (mail-abbrev-in-expansion-header-p))))
7438 (setq alist (cdr alist)))
7439 (funcall (or (cdar alist) message-tab-body-function
7440 (lookup-key text-mode-map "\t")
7441 (lookup-key global-map "\t")
7442 'indent-relative))))
7444 (defun message-expand-group ()
7445 "Expand the group name under point."
7446 (let* ((b (save-excursion
7451 (skip-chars-forward "^:")
7454 (skip-chars-backward "^, \t\n") (point))))
7455 (completion-ignore-case t)
7456 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
7458 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
7459 (completions (all-completions string hashtb))
7461 (delete-region b (point))
7463 ((= (length completions) 1)
7464 (if (string= (car completions) string)
7467 (message "Only matching group"))
7468 (insert (car completions))))
7469 ((and (setq comp (try-completion string hashtb))
7470 (not (string= comp string)))
7475 (message "No matching groups")
7476 (save-selected-window
7477 (pop-to-buffer "*Completions*")
7478 (buffer-disable-undo)
7479 (let ((buffer-read-only nil))
7481 (let ((standard-output (current-buffer)))
7482 (display-completion-list (sort completions 'string<)))
7483 (goto-char (point-min))
7484 (delete-region (point) (progn (forward-line 3) (point))))))))))
7486 (defun message-expand-name ()
7487 (cond (message-expand-name-function
7488 (funcall message-expand-name-function))
7489 ((and (memq 'eudc message-expand-name-databases)
7490 (boundp 'eudc-protocol)
7492 (eudc-expand-inline))
7493 ((and (memq 'bbdb message-expand-name-databases)
7494 (fboundp 'bbdb-complete-name))
7495 (bbdb-complete-name))
7496 ((and (memq 'lsdb message-expand-name-databases)
7497 (fboundp 'lsdb-complete-name))
7498 (lsdb-complete-name))
7499 (t 'expand-abbrev)))
7503 (defun message-talkative-question (ask question show &rest text)
7504 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
7505 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
7506 The following arguments may contain lists of values."
7508 (setq text (message-flatten-list text)))
7509 (save-window-excursion
7511 (with-output-to-temp-buffer " *MESSAGE information message*"
7512 (set-buffer " *MESSAGE information message*")
7513 (fundamental-mode) ; for Emacs 20.4+
7514 (mapcar 'princ text)
7515 (goto-char (point-min))))
7516 (funcall ask question))
7517 (funcall ask question)))
7519 (defun message-flatten-list (list)
7520 "Return a new, flat list that contains all elements of LIST.
7522 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
7525 (apply 'append (mapcar 'message-flatten-list list)))
7529 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
7530 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
7531 Then clone the local variables and values from the old buffer to the
7532 new one, cloning only the locals having a substring matching the
7534 (let ((oldbuf (current-buffer)))
7536 (set-buffer (generate-new-buffer name))
7537 (message-clone-locals oldbuf varstr)
7540 (defun message-clone-locals (buffer &optional varstr)
7541 "Clone the local variables from BUFFER to the current buffer."
7542 (let ((locals (save-excursion
7544 (buffer-local-variables)))
7545 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address\\|^user-full-name"))
7548 (when (and (consp local)
7550 (string-match regexp (symbol-name (car local)))
7552 (string-match varstr (symbol-name (car local)))))
7554 (set (make-local-variable (car local))
7558 ;;; @ for MIME Edit mode
7561 (defun message-maybe-encode ()
7562 (when message-mime-mode
7563 ;; Inherit the buffer local variable `mime-edit-pgp-processing'.
7564 (let ((pgp-processing (with-current-buffer message-edit-buffer
7565 mime-edit-pgp-processing)))
7566 (setq mime-edit-pgp-processing pgp-processing))
7567 (run-hooks 'mime-edit-translate-hook)
7568 (if (catch 'mime-edit-error
7570 (mime-edit-pgp-enclose-buffer)
7571 (mime-edit-translate-body)))
7572 (error "Translation error!"))
7573 (run-hooks 'mime-edit-exit-hook)))
7575 (defun message-mime-insert-article (&optional full-headers)
7577 (let ((message-cite-function 'mime-edit-inserted-message-filter)
7578 (message-reply-buffer
7579 (message-get-parameter-with-eval 'original-buffer))
7581 (message-yank-original nil)
7583 (narrow-to-region (goto-char start)
7584 (if (search-forward "\n\n" nil t)
7587 (goto-char (point-min))
7588 (let ((message-included-forward-headers
7589 (if full-headers "" message-included-forward-headers)))
7590 (message-remove-header message-included-forward-headers t nil t))
7593 (set-alist 'mime-edit-message-inserter-alist
7594 'message-mode (function message-mime-insert-article))
7600 (defvar message-inhibit-body-encoding t)
7602 (defun message-encode-message-body ()
7603 (unless message-inhibit-body-encoding
7604 (let ((mail-parse-charset (or mail-parse-charset
7605 message-default-charset))
7606 (case-fold-search t)
7607 lines content-type-p)
7610 (narrow-to-region (point) (point-max))
7611 (let ((new (mml-generate-mime)))
7613 (delete-region (point-min) (point-max))
7615 (goto-char (point-min))
7616 (if (eq (aref new 0) ?\n)
7618 (search-forward "\n\n")
7619 (setq lines (buffer-substring (point-min) (1- (point))))
7620 (delete-region (point-min) (point))))))
7622 (message-narrow-to-headers-or-head)
7623 (message-remove-header "Mime-Version")
7624 (goto-char (point-max))
7625 (insert "MIME-Version: 1.0\n")
7628 (setq content-type-p
7630 (re-search-backward "^Content-Type:" nil t))))
7632 (message-narrow-to-headers-or-head)
7633 (message-remove-first-header "Content-Type")
7634 (message-remove-first-header "Content-Transfer-Encoding"))
7635 ;; We always make sure that the message has a Content-Type
7636 ;; header. This is because some broken MTAs and MUAs get
7637 ;; awfully confused when confronted with a message with a
7638 ;; MIME-Version header and without a Content-Type header. For
7639 ;; instance, Solaris' /usr/bin/mail.
7640 (unless content-type-p
7641 (goto-char (point-min))
7642 ;; For unknown reason, MIME-Version doesn't exist.
7643 (when (re-search-forward "^MIME-Version:" nil t)
7645 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
7647 (defun message-read-from-minibuffer (prompt &optional initial-contents)
7648 "Read from the minibuffer while providing abbrev expansion."
7649 (if (fboundp 'mail-abbrevs-setup)
7650 (let ((mail-abbrev-mode-regexp "")
7651 (minibuffer-setup-hook 'mail-abbrevs-setup)
7652 (minibuffer-local-map message-minibuffer-local-map))
7653 (read-from-minibuffer prompt initial-contents))
7654 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
7655 (minibuffer-local-map message-minibuffer-local-map))
7656 (read-string prompt initial-contents))))
7658 (defun message-use-alternative-email-as-from ()
7659 (require 'mail-utils)
7660 (let* ((fields '("To" "Cc" "From"))
7663 (mail-strip-quoted-names
7664 (mapconcat 'message-fetch-reply-field fields ","))
7668 (if (string-match message-alternative-emails (car emails))
7669 (setq email (car emails)
7672 (unless (or (not email) (equal email user-mail-address))
7673 (goto-char (point-max))
7674 (insert "From: " (let ((user-mail-address email)) (message-make-from))
7677 (defun message-options-get (symbol)
7678 (cdr (assq symbol message-options)))
7680 (defun message-options-set (symbol value)
7681 (let ((the-cons (assq symbol message-options)))
7684 (setcdr the-cons value)
7685 (setq message-options (delq the-cons message-options)))
7687 (push (cons symbol value) message-options))))
7690 (defun message-options-set-recipient ()
7692 (message-narrow-to-headers-or-head)
7693 (message-options-set 'message-sender
7694 (mail-strip-quoted-names
7695 (message-fetch-field "from")))
7696 (message-options-set 'message-recipients
7697 (mail-strip-quoted-names
7698 (let ((to (message-fetch-field "to"))
7699 (cc (message-fetch-field "cc"))
7700 (bcc (message-fetch-field "bcc")))
7703 (if (and to cc) ", ")
7705 (if (and (or to cc) bcc) ", ")
7708 (defun message-hide-headers ()
7709 "Hide headers based on the `message-hidden-headers' variable."
7710 (let ((regexps (if (stringp message-hidden-headers)
7711 (list message-hidden-headers)
7712 message-hidden-headers))
7713 (inhibit-point-motion-hooks t)
7714 (after-change-functions nil)
7719 (message-narrow-to-headers)
7720 (goto-char (point-min))
7722 (if (not (message-hide-header-p regexps))
7723 (message-next-header)
7724 (let ((begin (point))
7726 (message-next-header)
7727 (setq header (buffer-substring begin (point))
7728 header-len (- (point) begin))
7729 (delete-region begin (point))
7730 (goto-char (1+ end-of-headers))
7732 (setq end-of-headers
7733 (+ end-of-headers header-len))))))))
7734 (narrow-to-region (1+ end-of-headers) (point-max))))
7736 (defun message-hide-header-p (regexps)
7739 (when (eq (car regexps) 'not)
7742 (dolist (regexp regexps)
7743 (setq result (or result (looking-at regexp))))
7748 (when (featurep 'xemacs)
7749 (require 'messagexmas)
7750 (message-xmas-redefine))
7754 (run-hooks 'message-load-hook)
7757 ;; coding: iso-8859-1
7760 ;;; message.el ends here