1 ;;; message.el --- composing mail and news messages
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005 Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;; Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
9 ;; Keiichi Suzuki <kei-suzu@mail.wbs.ne.jp>
10 ;; Tatsuya Ichikawa <t-ichi@po.shiojiri.ne.jp>
11 ;; Katsumi Yamaoka <yamaoka@jpl.org>
12 ;; Kiyokazu SUTO <suto@merry.xmath.ous.ac.jp>
13 ;; Keywords: mail, news, MIME
15 ;; This file is part of GNU Emacs.
17 ;; GNU Emacs is free software; you can redistribute it and/or modify
18 ;; it under the terms of the GNU General Public License as published by
19 ;; the Free Software Foundation; either version 2, or (at your option)
22 ;; GNU Emacs is distributed in the hope that it will be useful,
23 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 ;; GNU General Public License for more details.
27 ;; You should have received a copy of the GNU General Public License
28 ;; along with GNU Emacs; see the file COPYING. If not, write to the
29 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
30 ;; Boston, MA 02110-1301, USA.
34 ;; This mode provides mail-sending facilities from within Emacs. It
35 ;; consists mainly of large chunks of code from the sendmail.el,
36 ;; gnus-msg.el and rnewspost.el files.
43 (defvar gnus-message-group-art)
44 (defvar gnus-list-identifiers) ; gnus-sum is required where necessary
49 ;; This is apparently necessary even though things are autoloaded.
50 ;; Because we dynamically bind mail-abbrev-mode-regexp, we'd better
51 ;; require mailabbrev here.
52 (if (featurep 'xemacs)
53 (require 'mail-abbrevs)
54 (require 'mailabbrev))
56 (eval-when-compile (require 'static))
58 ;; Avoid byte-compile warnings.
65 (defgroup message '((user-mail-address custom-variable)
66 (user-full-name custom-variable))
67 "Mail and news message composing."
68 :link '(custom-manual "(message)Top")
72 (put 'user-mail-address 'custom-type 'string)
73 (put 'user-full-name 'custom-type 'string)
75 (defgroup message-various nil
76 "Various Message Variables."
77 :link '(custom-manual "(message)Various Message Variables")
80 (defgroup message-buffers nil
82 :link '(custom-manual "(message)Message Buffers")
85 (defgroup message-sending nil
87 :link '(custom-manual "(message)Sending Variables")
90 (defgroup message-interface nil
92 :link '(custom-manual "(message)Interface")
95 (defgroup message-forwarding nil
97 :link '(custom-manual "(message)Forwarding")
98 :group 'message-interface)
100 (defgroup message-insertion nil
102 :link '(custom-manual "(message)Insertion")
105 (defgroup message-headers nil
107 :link '(custom-manual "(message)Message Headers")
110 (defgroup message-news nil
111 "Composing News Messages."
114 (defgroup message-mail nil
115 "Composing Mail Messages."
118 (defgroup message-faces nil
119 "Faces used for message composing."
123 (defgroup message-frames nil
127 (defcustom message-directory "~/Mail/"
128 "*Directory from which all other mail file variables are derived."
129 :group 'message-various
132 (defcustom message-max-buffers 10
133 "*How many buffers to keep before starting to kill them off."
134 :group 'message-buffers
137 (defcustom message-send-rename-function nil
138 "Function called to rename the buffer after sending it."
139 :group 'message-buffers
140 :type '(choice function (const nil)))
142 (defcustom message-fcc-handler-function 'message-output
143 "*A function called to save outgoing articles.
144 This function will be called with the name of the file to store the
145 article in. The default function is `message-output' which saves in Unix
147 :type '(radio (function-item message-output)
148 (function :tag "Other"))
149 :group 'message-sending)
151 (defcustom message-encode-function 'message-maybe-encode
152 "*A function called to encode messages."
153 :group 'message-sending
156 (defcustom message-8bit-encoding-list '(8bit binary)
157 "*8bit encoding type in Content-Transfer-Encoding field."
158 :group 'message-sending
159 :type '(repeat (symbol :tag "Type")))
161 (defcustom message-fcc-externalize-attachments nil
162 "If non-nil, attachments are included as external parts in Fcc copies."
165 :group 'message-sending)
167 (defcustom message-courtesy-message
168 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
169 "*This is inserted at the start of a mailed copy of a posted message.
170 If the string contains the format spec \"%s\", the Newsgroups
171 the article has been posted to will be inserted there.
172 If this variable is nil, no such courtesy message will be added."
173 :group 'message-sending
174 :type '(radio string (const nil)))
176 (defcustom message-ignored-bounced-headers
177 "^\\(Received\\|Return-Path\\|Delivered-To\\):"
178 "*Regexp that matches headers to be removed in resent bounced mail."
179 :group 'message-interface
182 (defcustom message-bounce-setup-function 'message-bounce-setup-for-mime-edit
183 "Function to setup a re-sending bounced message."
184 :group 'message-sending
187 ;;; Start of variables adopted from `message-utils.el'.
189 (defcustom message-subject-trailing-was-query 'ask
190 "*What to do with trailing \"(was: <old subject>)\" in subject lines.
191 If nil, leave the subject unchanged. If it is the symbol `ask', query
192 the user what do do. In this case, the subject is matched against
193 `message-subject-trailing-was-ask-regexp'. If
194 `message-subject-trailing-was-query' is t, always strip the trailing
195 old subject. In this case, `message-subject-trailing-was-regexp' is
198 :type '(choice (const :tag "never" nil)
199 (const :tag "always strip" t)
201 :link '(custom-manual "(message)Message Headers")
202 :group 'message-various)
204 (defcustom message-subject-trailing-was-ask-regexp
205 "[ \t]*\\([[(]+[Ww][Aa][Ss][ \t]*.*[\])]+\\)"
206 "*Regexp matching \"(was: <old subject>)\" in the subject line.
208 The function `message-strip-subject-trailing-was' uses this regexp if
209 `message-subject-trailing-was-query' is set to the symbol `ask'. If
210 the variable is t instead of `ask', use
211 `message-subject-trailing-was-regexp' instead.
213 It is okay to create some false positives here, as the user is asked."
215 :group 'message-various
216 :link '(custom-manual "(message)Message Headers")
219 (defcustom message-subject-trailing-was-regexp
220 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
221 "*Regexp matching \"(was: <old subject>)\" in the subject line.
223 If `message-subject-trailing-was-query' is set to t, the subject is
224 matched against `message-subject-trailing-was-regexp' in
225 `message-strip-subject-trailing-was'. You should use a regexp creating very
226 few false positives here."
228 :group 'message-various
229 :link '(custom-manual "(message)Message Headers")
232 ;;; marking inserted text
234 (defcustom message-mark-insert-begin
235 "--8<---------------cut here---------------start------------->8---\n"
236 "How to mark the beginning of some inserted text."
239 :link '(custom-manual "(message)Insertion Variables")
240 :group 'message-various)
242 (defcustom message-mark-insert-end
243 "--8<---------------cut here---------------end--------------->8---\n"
244 "How to mark the end of some inserted text."
247 :link '(custom-manual "(message)Insertion Variables")
248 :group 'message-various)
250 (defcustom message-archive-header "X-No-Archive: Yes\n"
251 "Header to insert when you don't want your article to be archived.
252 Archives \(such as groups.google.com\) respect this header."
255 :link '(custom-manual "(message)Header Commands")
256 :group 'message-various)
258 (defcustom message-archive-note
259 "X-No-Archive: Yes - save http://groups.google.com/"
260 "Note to insert why you wouldn't want this posting archived.
261 If nil, don't insert any text in the body."
263 :type '(radio string (const nil))
264 :link '(custom-manual "(message)Header Commands")
265 :group 'message-various)
267 ;;; Crossposts and Followups
268 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
269 ;; new suggestions by R. Weikusat <rw at another.de>
271 (defvar message-cross-post-old-target nil
272 "Old target for cross-posts or follow-ups.")
273 (make-variable-buffer-local 'message-cross-post-old-target)
275 (defcustom message-cross-post-default t
276 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
277 If nil, `message-cross-post-followup-to' will only do a followup. Note that
278 you can explicitly override this setting by calling
279 `message-cross-post-followup-to' with a prefix."
282 :group 'message-various)
284 (defcustom message-cross-post-note "Crosspost & Followup-To: "
285 "Note to insert before signature to notify of xpost and follow-up."
288 :group 'message-various)
290 (defcustom message-followup-to-note "Followup-To: "
291 "Note to insert before signature to notify of follow-up only."
294 :group 'message-various)
296 (defcustom message-cross-post-note-function 'message-cross-post-insert-note
297 "Function to use to insert note about Crosspost or Followup-To.
298 The function will be called with four arguments. The function should not only
299 insert a note, but also ensure old notes are deleted. See the documentation
300 for `message-cross-post-insert-note'."
303 :group 'message-various)
305 ;;; End of variables adopted from `message-utils.el'.
308 (defcustom message-from-style 'default
309 "*Specifies how \"From\" headers look.
311 If nil, they contain just the return address like:
313 If `parens', they look like:
314 king@grassland.com (Elvis Parsley)
315 If `angles', they look like:
316 Elvis Parsley <king@grassland.com>
318 Otherwise, most addresses look like `angles', but they look like
319 `parens' if `angles' would need quoting and `parens' would not."
320 :type '(choice (const :tag "simple" nil)
324 :group 'message-headers)
326 (defcustom message-insert-canlock t
327 "Whether to insert a Cancel-Lock header in news postings."
329 :group 'message-headers
332 (defcustom message-syntax-checks
333 (if message-insert-canlock '((sender . disabled)) nil)
334 ;; Guess this one shouldn't be easy to customize...
335 "*Controls what syntax checks should not be performed on outgoing posts.
336 To disable checking of long signatures, for instance, add
337 `(signature . disabled)' to this list.
339 Don't touch this variable unless you really know what you're doing.
341 Checks include `subject-cmsg', `multiple-headers', `sendsys',
342 `message-id', `from', `long-lines', `control-chars', `size',
343 `new-text', `quoting-style', `redirected-followup', `signature',
344 `approved', `sender', `empty', `empty-headers', `message-id', `from',
345 `subject', `shorten-followup-to', `existing-newsgroups',
346 `buffer-file-name', `unchanged', `newsgroups', `reply-to',
347 `continuation-headers', `long-header-lines', `invisible-text' and
350 :type '(repeat sexp)) ; Fixme: improve this
352 (defcustom message-required-headers '((optional . References)
354 "*Headers to be generated or prompted for when sending a message.
355 Also see `message-required-news-headers' and
356 `message-required-mail-headers'."
359 :group 'message-headers
360 :link '(custom-manual "(message)Message Headers")
361 :type '(repeat sexp))
363 (defcustom message-draft-headers '(References From)
364 "*Headers to be generated when saving a draft message."
367 :group 'message-headers
368 :link '(custom-manual "(message)Message Headers")
369 :type '(repeat sexp))
371 (defcustom message-required-news-headers
372 '(From Newsgroups Subject Date Message-ID
373 (optional . Organization)
374 (optional . User-Agent))
375 "*Headers to be generated or prompted for when posting an article.
376 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
377 Message-ID. Organization, Lines, In-Reply-To, Expires, and
378 User-Agent are optional. If don't you want message to insert some
379 header, remove it from this list."
381 :group 'message-headers
382 :link '(custom-manual "(message)Message Headers")
383 :type '(repeat sexp))
385 (defcustom message-required-mail-headers
386 '(From Subject Date (optional . In-Reply-To) Message-ID
387 (optional . User-Agent))
388 "*Headers to be generated or prompted for when mailing a message.
389 It is recommended that From, Date, To, Subject and Message-ID be
390 included. Organization and User-Agent are optional."
392 :group 'message-headers
393 :link '(custom-manual "(message)Message Headers")
394 :type '(repeat sexp))
396 (defcustom message-deletable-headers '(Message-ID Date Lines)
397 "Headers to be deleted if they already exist and were generated by message previously."
398 :group 'message-headers
399 :link '(custom-manual "(message)Message Headers")
402 (defcustom message-ignored-news-headers
403 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
404 "*Regexp of headers to be removed unconditionally before posting."
406 :group 'message-headers
407 :link '(custom-manual "(message)Message Headers")
408 :type '(repeat :value-to-internal (lambda (widget value)
409 (custom-split-regexp-maybe value))
410 :match (lambda (widget value)
412 (widget-editable-list-match widget value)))
415 (defcustom message-ignored-mail-headers
416 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
417 "*Regexp of headers to be removed unconditionally before mailing."
419 :group 'message-headers
420 :link '(custom-manual "(message)Mail Headers")
423 (defcustom message-ignored-supersedes-headers "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|^X-Trace:\\|^X-Complaints-To:\\|Return-Path:\\|^Supersedes:\\|^NNTP-Posting-Date:\\|^X-Trace:\\|^X-Complaints-To:\\|^Cancel-Lock:\\|^Cancel-Key:\\|^X-Hashcash:\\|^X-Payment:\\|^Approved:"
424 "*Header lines matching this regexp will be deleted before posting.
425 It's best to delete old Path and Date headers before posting to avoid
427 :group 'message-interface
428 :link '(custom-manual "(message)Superseding")
429 :type '(repeat :value-to-internal (lambda (widget value)
430 (custom-split-regexp-maybe value))
431 :match (lambda (widget value)
433 (widget-editable-list-match widget value)))
436 (defcustom message-supersede-setup-function
437 'message-supersede-setup-for-mime-edit
438 "Function to setup a supersede message."
439 :group 'message-sending
442 (defcustom message-subject-re-regexp
443 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)*:[ \t]*\\)*[ \t]*"
444 "*Regexp matching \"Re: \" in the subject line."
445 :group 'message-various
446 :link '(custom-manual "(message)Message Headers")
449 ;;; Some sender agents encode the whole subject including leading "Re: ".
450 ;;; And if followup agent does not decode it for some reason (e.g. unknown
451 ;;; charset) and just add a new "Re: " in front of the encoded-word, the
452 ;;; result will contain multiple "Re: "'s.
453 (defcustom message-subject-encoded-re-regexp
457 "[-!#$%&'*+0-9A-Z^_`a-z{|}~]+" ; charset
460 "[Bb]" (regexp-quote "?") ; B encoding
461 "\\(\\(CQk\\|CSA\\|IAk\\|ICA\\)[Jg]\\)*" ; \([ \t][ \t][ \t]\)*
463 "[Uc][km]U6" ; [Rr][Ee]:
465 "\\(C[VX]\\|I[FH]\\)J[Fl]O[g-v]" ; [ \t][Rr][Ee]:
467 "\\(CQl\\|CSB\\|IAl\\|ICB\\)[Sy][RZ]T[o-r]" ; [ \t][ \t][Rr][Ee]:
470 "[Qb]" (regexp-quote "?") ; Q encoding
471 "\\(_\\|=09\\|=20\\)*"
472 "\\([Rr]\\|=[57]2\\)\\([Ee]\\|=[46]5\\)\\(:\\|=3[Aa]\\)"
475 "*Regexp matching \"Re: \" in the subject line.
476 Unlike `message-subject-re-regexp', this regexp matches \"Re: \" within
478 :group 'message-various
479 :link '(custom-manual "(message)Message Headers")
482 (defcustom message-use-subject-re t
483 "*If t, remove any (buggy) \"Re: \"'s from the subject of the precursor
484 and add a new \"Re: \". If it is nil, use the subject \"as-is\". If it
485 is the symbol `guess', try to detect \"Re: \" within an encoded-word."
486 :group 'message-various
487 :type '(choice (const :tag "off" nil)
492 (defcustom message-signature-separator "^-- *$"
493 "Regexp matching the signature separator."
495 :link '(custom-manual "(message)Various Message Variables")
496 :group 'message-various)
498 (defcustom message-signature-separator-for-insertion "-- \n"
499 "*Signature separator. This value will be inserted as signature separator
500 when composing message. Default value is \"-- \\n\". Notice: Changing this
501 value may go against RFC-1036 and draft-ietf-usefor-article-05.txt. "
503 :group 'message-insertion)
505 (defcustom message-elide-ellipsis "\n[...]\n\n"
506 "*The string which is inserted for elided text."
508 :link '(custom-manual "(message)Insertion Variables")
509 :group 'message-various)
511 (defcustom message-interactive t
512 "Non-nil means when sending a message wait for and display errors.
513 nil means let mailer mail back a message to report errors."
514 :group 'message-sending
516 :link '(custom-manual "(message)Sending Variables")
519 (defcustom message-generate-new-buffers 'unique
520 "*Non-nil means create a new message buffer whenever `message-setup' is called.
521 If this is a function, call that function with three parameters: The type,
522 the to address and the group name. (Any of these may be nil.) The function
523 should return the new buffer name."
524 :group 'message-buffers
525 :link '(custom-manual "(message)Message Buffers")
526 :type '(choice (const :tag "off" nil)
527 (const :tag "unique" unique)
528 (const :tag "unsent" unsent)
531 (defcustom message-kill-buffer-on-exit nil
532 "*Non-nil means that the message buffer will be killed after sending a message."
533 :group 'message-buffers
534 :link '(custom-manual "(message)Message Buffers")
537 (defcustom message-kill-buffer-query-function 'yes-or-no-p
538 "*Function used to prompt user whether to kill the message buffer.
539 If it is t, the buffer will be killed unconditionally."
540 :type '(radio (function-item yes-or-no-p)
541 (function-item y-or-n-p)
542 (function-item nnheader-Y-or-n-p)
543 (function :tag "Other" t))
544 :group 'message-buffers)
546 (defcustom message-kill-buffer-and-remove-file t
547 "*Non-nil means that the associated file will be removed before
548 removing the message buffer. However, it is treated as nil when the
549 command `message-mimic-kill-buffer' is used."
550 :group 'message-buffers
553 (defcustom message-kill-buffer-query t
554 "*Non-nil means that killing a modified message buffer has to be confirmed.
555 This is used by `message-kill-buffer'."
556 :version "23.0" ;; No Gnus
557 :group 'message-buffers
561 (defvar gnus-local-organization))
562 (defcustom message-user-organization
563 (or (and (boundp 'gnus-local-organization)
564 (stringp gnus-local-organization)
565 gnus-local-organization)
566 (getenv "ORGANIZATION")
568 "*String to be used as an Organization header.
569 If t, use `message-user-organization-file'."
570 :group 'message-headers
571 :type '(choice string
572 (const :tag "consult file" t)))
575 (defcustom message-user-organization-file "/usr/lib/news/organization"
576 "*Local news organization file."
578 :link '(custom-manual "(message)News Headers")
579 :group 'message-headers)
581 (defcustom message-forward-start-separator
582 (concat (mime-make-tag "message" "rfc822") "\n")
583 "*Delimiter inserted before forwarded messages."
584 :group 'message-forwarding
587 (defcustom message-forward-end-separator
588 (concat (mime-make-tag "text" "plain") "\n")
589 "*Delimiter inserted after forwarded messages."
590 :group 'message-forwarding
593 (defcustom message-included-forward-headers
594 "^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:"
595 "*Regexp matching headers to be included in forwarded messages."
596 :group 'message-forwarding
599 (defcustom message-make-forward-subject-function
600 #'message-forward-subject-name-subject
601 "*List of functions called to generate subject headers for forwarded messages.
602 The subject generated by the previous function is passed into each
605 The provided functions are:
607 * `message-forward-subject-author-subject' Source of article (author or
608 newsgroup), in brackets followed by the subject
609 * `message-forward-subject-name-subject' Source of article (name of author
610 or newsgroup), in brackets followed by the subject
611 * `message-forward-subject-fwd' Subject of article with 'Fwd:' prepended
613 :group 'message-forwarding
614 :link '(custom-manual "(message)Forwarding")
615 :type '(radio (function-item message-forward-subject-author-subject)
616 (function-item message-forward-subject-fwd)
617 (function-item message-forward-subject-name-subject)
618 (repeat :tag "List of functions" function)))
620 (defcustom message-forward-as-mime t
621 "*Non-nil means forward messages as an inline/rfc822 MIME section.
622 Otherwise, directly inline the old message in the forwarded message."
624 :group 'message-forwarding
625 :link '(custom-manual "(message)Forwarding")
628 (defcustom message-forward-show-mml 'best
629 "*Non-nil means show forwarded messages as MML (decoded from MIME).
630 Otherwise, forwarded messages are unchanged.
631 Can also be the symbol `best' to indicate that MML should be
632 used, except when it is a bad idea to use MML. One example where
633 it is a bad idea is when forwarding a signed or encrypted
634 message, because converting MIME to MML would invalidate the
637 :group 'message-forwarding
638 :type '(choice (const :tag "use MML" t)
639 (const :tag "don't use MML " nil)
640 (const :tag "use MML when appropriate" best)))
642 (defcustom message-forward-before-signature t
643 "*Non-nil means put forwarded message before signature, else after."
644 :group 'message-forwarding
647 (defcustom message-wash-forwarded-subjects nil
648 "*Non-nil means try to remove as much cruft as possible from the subject.
649 Done before generating the new subject of a forward."
650 :group 'message-forwarding
651 :link '(custom-manual "(message)Forwarding")
654 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From "
655 "*All headers that match this regexp will be deleted when resending a message."
656 :group 'message-interface
657 :link '(custom-manual "(message)Resending")
658 :type '(repeat :value-to-internal (lambda (widget value)
659 (custom-split-regexp-maybe value))
660 :match (lambda (widget value)
662 (widget-editable-list-match widget value)))
665 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
666 "*All headers that match this regexp will be deleted when forwarding a message."
668 :group 'message-forwarding
669 :type '(repeat :value-to-internal (lambda (widget value)
670 (custom-split-regexp-maybe value))
671 :match (lambda (widget value)
673 (widget-editable-list-match widget value)))
676 (defcustom message-ignored-cited-headers "."
677 "*Delete these headers from the messages you yank."
678 :group 'message-insertion
679 :link '(custom-manual "(message)Insertion Variables")
682 (defcustom message-cite-prefix-regexp
683 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
684 "\\([ \t]*[-_.[:word:]]+>+\\|[ \t]*[]>|}+]\\)+"
685 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
686 (let (non-word-constituents)
687 (with-syntax-table text-mode-syntax-table
688 (setq non-word-constituents
690 (if (string-match "\\w" "-") "" "-")
691 (if (string-match "\\w" "_") "" "_")
692 (if (string-match "\\w" ".") "" "."))))
693 (if (equal non-word-constituents "")
694 "\\([ \t]*\\(\\w\\)+>+\\|[ \t]*[]>|}+]\\)+"
695 (concat "\\([ \t]*\\(\\w\\|["
696 non-word-constituents
697 "]\\)+>+\\|[ \t]*[]>|}+]\\)+"))))
698 "*Regexp matching the longest possible citation prefix on a line."
700 :group 'message-insertion
701 :link '(custom-manual "(message)Insertion Variables")
704 (defcustom message-cancel-message "I am canceling my own article.\n"
705 "Message to be inserted in the cancel message."
706 :group 'message-interface
707 :link '(custom-manual "(message)Canceling News")
710 ;; Useful to set in site-init.el
712 (defcustom message-send-mail-function
713 (let ((program (if (boundp 'sendmail-program)
718 (string-match "/" program) ;; Skip path
719 (file-executable-p program))
720 'message-send-mail-with-sendmail)
722 (executable-find program))
723 'message-send-mail-with-sendmail)
726 "Function to call to send the current buffer as mail.
727 The headers should be delimited by a line whose contents match the
728 variable `mail-header-separator'.
730 Valid values include `message-send-mail-with-sendmail' (the default),
731 `message-send-mail-with-mh', `message-send-mail-with-qmail',
732 `message-send-mail-with-smtp', `message-smtpmail-send-it',
733 `smtpmail-send-it' and `feedmail-send-it'.
735 See also `send-mail-function'."
736 :type '(radio (function-item message-send-mail-with-sendmail)
737 (function-item message-send-mail-with-mh)
738 (function-item message-send-mail-with-qmail)
739 (function-item message-send-mail-with-smtp)
740 (function-item message-smtpmail-send-it)
741 (function-item smtpmail-send-it)
742 (function-item feedmail-send-it)
743 (function :tag "Other"))
744 :group 'message-sending
745 :link '(custom-manual "(message)Mail Variables")
746 :group 'message-mail)
748 ;; 1997-09-29 by MORIOKA Tomohiko
749 (defcustom message-send-news-function 'message-send-news-with-gnus
750 "Function to call to send the current buffer as news.
751 The headers should be delimited by a line whose contents match the
752 variable `mail-header-separator'."
753 :group 'message-sending
755 :link '(custom-manual "(message)News Variables")
758 (defcustom message-reply-to-function nil
759 "If non-nil, function that should return a list of headers.
760 This function should pick out addresses from the To, Cc, and From headers
761 and respond with new To and Cc headers."
762 :group 'message-interface
763 :link '(custom-manual "(message)Reply")
764 :type '(choice function (const nil)))
766 (defcustom message-wide-reply-to-function nil
767 "If non-nil, function that should return a list of headers.
768 This function should pick out addresses from the To, Cc, and From headers
769 and respond with new To and Cc headers."
770 :group 'message-interface
771 :link '(custom-manual "(message)Wide Reply")
772 :type '(choice function (const nil)))
774 (defcustom message-followup-to-function nil
775 "If non-nil, function that should return a list of headers.
776 This function should pick out addresses from the To, Cc, and From headers
777 and respond with new To and Cc headers."
778 :group 'message-interface
779 :link '(custom-manual "(message)Followup")
780 :type '(choice function (const nil)))
782 (defcustom message-extra-wide-headers nil
783 "If non-nil, a list of additional address headers.
784 These are used when composing a wide reply."
785 :group 'message-sending
786 :type '(repeat string))
788 (defcustom message-use-followup-to 'ask
789 "*Specifies what to do with Followup-To header.
790 If nil, always ignore the header. If it is t, use its value, but
791 query before using the \"poster\" value. If it is the symbol `ask',
792 always query the user whether to use the value. If it is the symbol
793 `use', always use the value."
794 :group 'message-interface
795 :link '(custom-manual "(message)Followup")
796 :type '(choice (const :tag "ignore" nil)
797 (const :tag "use & query" t)
798 (const :tag "maybe" t)
799 (const :tag "always" use)
800 (const :tag "ask" ask)))
802 (defcustom message-use-mail-copies-to 'ask
803 "*Specifies what to do with Mail-Copies-To header.
804 If nil, always ignore the header. If it is t, use its value, but
805 query before using the value other than \"always\" or \"never\".
806 If it is the symbol `ask', always query the user whether to use
807 the value. If it is the symbol `use', always use the value."
808 :group 'message-interface
809 :link '(custom-manual "(message)Mailing Lists")
810 :type '(choice (const :tag "ignore" nil)
811 (const :tag "maybe" t)
812 (const :tag "always" use)
813 (const :tag "ask" ask)))
815 ;;; XXX: 'ask and 'use are not implemented yet.
816 (defcustom message-use-mail-reply-to 'ask
817 "*Specifies what to do with Mail-Reply-To/Reply-To header.
818 If nil, always ignore the header. If it is t or the symbol `use', use
819 its value. If it is the symbol `ask', always query the user whether to
820 use the value. Note that if \"Reply-To\" is marked as \"broken\", its value
822 :group 'message-interface
823 :type '(choice (const :tag "ignore" nil)
824 (const :tag "maybe" t)
825 (const :tag "always" use)
826 (const :tag "ask" ask)))
828 (defcustom message-use-mail-followup-to 'use
829 "*Specifies what to do with Mail-Followup-To header.
830 If nil, always ignore the header. If it is the symbol `ask', always
831 query the user whether to use the value. If it is t or the symbol
832 `use', always use the value."
834 :group 'message-interface
835 :type '(choice (const :tag "ignore" nil)
836 (const :tag "maybe" t)
837 (const :tag "always" use)
838 (const :tag "ask" ask)))
840 (defcustom message-subscribed-address-functions nil
841 "*Specifies functions for determining list subscription.
842 If nil, do not attempt to determine list subscription with functions.
843 If non-nil, this variable contains a list of functions which return
844 regular expressions to match lists. These functions can be used in
845 conjunction with `message-subscribed-regexps' and
846 `message-subscribed-addresses'."
848 :group 'message-interface
849 :link '(custom-manual "(message)Mailing Lists")
850 :type '(repeat sexp))
852 (defcustom message-subscribed-address-file nil
853 "*A file containing addresses the user is subscribed to.
854 If nil, do not look at any files to determine list subscriptions. If
855 non-nil, each line of this file should be a mailing list address."
857 :group 'message-interface
858 :link '(custom-manual "(message)Mailing Lists")
859 :type '(radio file (const nil)))
861 (defcustom message-subscribed-addresses nil
862 "*Specifies a list of addresses the user is subscribed to.
863 If nil, do not use any predefined list subscriptions. This list of
864 addresses can be used in conjunction with
865 `message-subscribed-address-functions' and `message-subscribed-regexps'."
867 :group 'message-interface
868 :link '(custom-manual "(message)Mailing Lists")
869 :type '(repeat string))
871 (defcustom message-subscribed-regexps nil
872 "*Specifies a list of addresses the user is subscribed to.
873 If nil, do not use any predefined list subscriptions. This list of
874 regular expressions can be used in conjunction with
875 `message-subscribed-address-functions' and `message-subscribed-addresses'."
877 :group 'message-interface
878 :link '(custom-manual "(message)Mailing Lists")
879 :type '(repeat regexp))
881 (defcustom message-allow-no-recipients 'ask
882 "Specifies what to do when there are no recipients other than Gcc/Fcc.
883 If it is the symbol `always', the posting is allowed. If it is the
884 symbol `never', the posting is not allowed. If it is the symbol
885 `ask', you are prompted."
887 :group 'message-interface
888 :link '(custom-manual "(message)Message Headers")
889 :type '(choice (const always)
893 (defcustom message-sendmail-f-is-evil nil
894 "*Non-nil means don't add \"-f username\" to the sendmail command line.
895 Doing so would be even more evil than leaving it out."
896 :group 'message-sending
897 :link '(custom-manual "(message)Mail Variables")
900 (defcustom message-sendmail-envelope-from nil
901 "*Envelope-from when sending mail with sendmail.
902 If this is nil, use `user-mail-address'. If it is the symbol
903 `header', use the From: header of the message."
905 :type '(choice (string :tag "From name")
906 (const :tag "Use From: header from message" header)
907 (const :tag "Use `user-mail-address'" nil))
908 :link '(custom-manual "(message)Mail Variables")
909 :group 'message-sending)
911 ;; qmail-related stuff
912 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
913 "Location of the qmail-inject program."
914 :group 'message-sending
915 :link '(custom-manual "(message)Mail Variables")
918 (defcustom message-qmail-inject-args nil
919 "Arguments passed to qmail-inject programs.
920 This should be a list of strings, one string for each argument. It
921 may also be a function.
923 For e.g., if you wish to set the envelope sender address so that bounces
924 go to the right place or to deal with listserv's usage of that address, you
925 might set this variable to '(\"-f\" \"you@some.where\")."
926 :group 'message-sending
927 :link '(custom-manual "(message)Mail Variables")
928 :type '(choice (function)
932 (defvar gnus-post-method)
933 (defvar gnus-select-method))
934 (defcustom message-post-method
935 (cond ((and (boundp 'gnus-post-method)
936 (listp gnus-post-method)
939 ((boundp 'gnus-select-method)
942 "*Method used to post news.
943 Note that when posting from inside Gnus, for instance, this
944 variable isn't used."
946 :group 'message-sending
947 ;; This should be the `gnus-select-method' widget, but that might
948 ;; create a dependence to `gnus.el'.
951 ;; FIXME: This should be a temporary workaround until someone implements a
952 ;; proper solution. If a crash happens while replying, the auto-save file
953 ;; will *not* have a `References:' header if `message-generate-headers-first'
954 ;; is nil. See: http://article.gmane.org/gmane.emacs.gnus.general/51138
955 (defcustom message-generate-headers-first '(references)
956 "Which headers should be generated before starting to compose a message.
957 If t, generate all required headers. This can also be a list of headers to
958 generate. The variables `message-required-news-headers' and
959 `message-required-mail-headers' specify which headers to generate.
961 Note that the variable `message-deletable-headers' specifies headers which
962 are to be deleted and then re-generated before sending, so this variable
963 will not have a visible effect for those headers."
964 :group 'message-headers
965 :link '(custom-manual "(message)Message Headers")
966 :type '(choice (const :tag "None" nil)
967 (const :tag "References" '(references))
969 (repeat (sexp :tag "Header"))))
971 (defcustom message-setup-hook '(turn-on-mime-edit)
972 "Normal hook, run each time a new outgoing message is initialized.
973 The function `message-setup' runs this hook."
974 :group 'message-various
975 :link '(custom-manual "(message)Various Message Variables")
978 (defcustom message-cancel-hook nil
979 "Hook run when cancelling articles."
980 :group 'message-various
981 :link '(custom-manual "(message)Various Message Variables")
984 (defcustom message-signature-setup-hook nil
985 "Normal hook, run each time a new outgoing message is initialized.
986 It is run after the headers have been inserted and before
987 the signature is inserted."
988 :group 'message-various
989 :link '(custom-manual "(message)Various Message Variables")
992 (defcustom message-bounce-setup-hook nil
993 "Normal hook, run each time a re-sending bounced message is initialized.
994 The function `message-bounce' runs this hook."
995 :group 'message-various
998 (defcustom message-supersede-setup-hook nil
999 "Normal hook, run each time a supersede message is initialized.
1000 The function `message-supersede' runs this hook."
1001 :group 'message-various
1004 (defcustom message-mode-hook nil
1005 "Hook run in message mode buffers."
1006 :group 'message-various
1009 (defcustom message-header-hook '((lambda () (mime-encode-header-in-buffer t)))
1010 "Hook run in a message mode buffer narrowed to the headers."
1011 :group 'message-various
1014 (defcustom message-header-setup-hook nil
1015 "Hook called narrowed to the headers when setting up a message buffer."
1016 :group 'message-various
1017 :link '(custom-manual "(message)Various Message Variables")
1020 (defcustom message-minibuffer-local-map
1021 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
1022 (set-keymap-parent map minibuffer-local-map)
1024 "Keymap for `message-read-from-minibuffer'."
1026 :group 'message-various)
1029 (defcustom message-citation-line-function 'message-insert-citation-line
1030 "*Function called to insert the \"Whomever writes:\" line.
1032 Note that Gnus provides a feature where the reader can click on
1033 `writes:' to hide the cited text. If you change this line too much,
1034 people who read your message will have to change their Gnus
1035 configuration. See the variable `gnus-cite-attribution-suffix'."
1037 :link '(custom-manual "(message)Insertion Variables")
1038 :group 'message-insertion)
1041 (defcustom message-yank-prefix "> "
1042 "*Prefix inserted on the lines of yanked messages.
1043 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1044 See also `message-yank-cited-prefix' and `message-yank-empty-prefix'."
1046 :link '(custom-manual "(message)Insertion Variables")
1047 :group 'message-insertion)
1049 (defcustom message-yank-cited-prefix ">"
1050 "*Prefix inserted on cited lines of yanked messages.
1051 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1052 See also `message-yank-prefix' and `message-yank-empty-prefix'."
1055 :link '(custom-manual "(message)Insertion Variables")
1056 :group 'message-insertion)
1058 (defcustom message-yank-empty-prefix ">"
1059 "*Prefix inserted on empty lines of yanked messages.
1060 See also `message-yank-prefix' and `message-yank-cited-prefix'."
1063 :link '(custom-manual "(message)Insertion Variables")
1064 :group 'message-insertion)
1066 (defcustom message-indentation-spaces 3
1067 "*Number of spaces to insert at the beginning of each cited line.
1068 Used by `message-yank-original' via `message-yank-cite'."
1069 :group 'message-insertion
1070 :link '(custom-manual "(message)Insertion Variables")
1074 (defcustom message-cite-function 'message-cite-original
1075 "*Function for citing an original message.
1076 Predefined functions include `message-cite-original' and
1077 `message-cite-original-without-signature'.
1078 Note that these functions use `mail-citation-hook' if that is non-nil."
1079 :type '(radio (function-item message-cite-original)
1080 (function-item message-cite-original-without-signature)
1081 (function-item mu-cite-original)
1082 (function-item sc-cite-original)
1083 (function :tag "Other"))
1084 :link '(custom-manual "(message)Insertion Variables")
1085 :group 'message-insertion)
1088 (defcustom message-indent-citation-function 'message-indent-citation
1089 "*Function for modifying a citation just inserted in the mail buffer.
1090 This can also be a list of functions. Each function can find the
1091 citation between (point) and (mark t). And each function should leave
1092 point and mark around the citation text as modified."
1094 :link '(custom-manual "(message)Insertion Variables")
1095 :group 'message-insertion)
1098 (defcustom message-suspend-font-lock-when-citing nil
1099 "Non-nil means suspend font-lock'ing while citing an original message.
1100 Some lazy demand-driven fontification tools (or Emacs itself) have a
1101 bug that they often miss a buffer to be fontified. It will mostly
1102 occur when Emacs prompts user for any inputs in the minibuffer.
1103 Setting this option to non-nil may help you to avoid unpleasant errors
1104 even if it is an add-hoc expedient."
1106 :group 'message-insertion)
1108 (defcustom message-yank-add-new-references t
1109 "Non-nil means new IDs will be added to \"References\" field when an
1110 article is yanked by the command `message-yank-original' interactively.
1111 If it is a symbol `message-id-only', only an ID from \"Message-ID\" field
1112 is used, otherwise IDs extracted from \"References\", \"In-Reply-To\" and
1113 \"Message-ID\" fields are used."
1115 (const :tag "Do not add anything" nil)
1116 (const :tag "From Message-Id, References and In-Reply-To fields" t)
1117 (const :tag "From only Message-Id field." message-id-only))
1118 :group 'message-insertion)
1120 (defcustom message-list-references-add-position nil
1121 "Integer value means position for adding to \"References\" field when
1122 an article is yanked by the command `message-yank-original' interactively."
1123 :type '(radio (const :tag "Add to last" nil)
1124 (integer :tag "Position from last ID"))
1125 :group 'message-insertion)
1128 (defcustom message-signature t
1129 "*String to be inserted at the end of the message buffer.
1130 If t, the `message-signature-file' file will be inserted instead.
1131 If a function, the result from the function will be used instead.
1132 If a form, the result from the form will be used instead."
1134 :link '(custom-manual "(message)Insertion Variables")
1135 :group 'message-insertion)
1138 (defcustom message-signature-file "~/.signature"
1139 "*Name of file containing the text inserted at end of message buffer.
1140 Ignored if the named file doesn't exist.
1141 If nil, don't insert a signature."
1142 :type '(choice file (const :tags "None" nil))
1143 :link '(custom-manual "(message)Insertion Variables")
1144 :group 'message-insertion)
1147 (defcustom message-signature-insert-empty-line t
1148 "*If non-nil, insert an empty line before the signature separator."
1151 :link '(custom-manual "(message)Insertion Variables")
1152 :group 'message-insertion)
1154 (defcustom message-distribution-function nil
1155 "*Function called to return a Distribution header."
1156 :group 'message-news
1157 :group 'message-headers
1158 :link '(custom-manual "(message)News Headers")
1159 :type '(choice function (const nil)))
1161 (defcustom message-expires 14
1162 "Number of days before your article expires."
1163 :group 'message-news
1164 :group 'message-headers
1165 :link '(custom-manual "(message)News Headers")
1168 (defcustom message-user-path nil
1169 "If nil, use the NNTP server name in the Path header.
1170 If stringp, use this; if non-nil, use no host name (user name only)."
1171 :group 'message-news
1172 :group 'message-headers
1173 :link '(custom-manual "(message)News Headers")
1174 :type '(choice (const :tag "nntp" nil)
1175 (string :tag "name")
1176 (sexp :tag "none" :format "%t" t)))
1178 (defvar message-reply-buffer nil)
1179 (defvar message-reply-headers nil
1180 "The headers of the current replied article.
1181 It is a vector of the following headers:
1182 \[number subject from date id references chars lines xref extra].")
1183 (defvar message-sent-message-via nil)
1184 (defvar message-checksum nil)
1185 (defvar message-send-actions nil
1186 "A list of actions to be performed upon successful sending of a message.")
1187 (defvar message-exit-actions nil
1188 "A list of actions to be performed upon exiting after sending a message.")
1189 (defvar message-kill-actions nil
1190 "A list of actions to be performed before killing a message buffer.")
1191 (defvar message-postpone-actions nil
1192 "A list of actions to be performed after postponing a message.")
1193 (defvar message-original-frame nil)
1194 (defvar message-parameter-alist nil)
1195 (defvar message-startup-parameter-alist nil)
1197 (define-widget 'message-header-lines 'text
1198 "All header lines must be LFD terminated."
1199 :format "%{%t%}:%n%v"
1200 :valid-regexp "^\\'"
1201 :error "All header lines must be newline terminated")
1203 (defcustom message-default-headers ""
1204 "*A string containing header lines to be inserted in outgoing messages.
1205 It is inserted before you edit the message, so you can edit or delete
1207 :group 'message-headers
1208 :link '(custom-manual "(message)Message Headers")
1209 :type 'message-header-lines)
1211 (defcustom message-default-mail-headers ""
1212 "*A string of header lines to be inserted in outgoing mails."
1213 :group 'message-headers
1214 :group 'message-mail
1215 :link '(custom-manual "(message)Mail Headers")
1216 :type 'message-header-lines)
1218 (defcustom message-default-news-headers ""
1219 "*A string of header lines to be inserted in outgoing news articles."
1220 :group 'message-headers
1221 :group 'message-news
1222 :link '(custom-manual "(message)News Headers")
1223 :type 'message-header-lines)
1225 ;; Note: could use /usr/ucb/mail instead of sendmail;
1226 ;; options -t, and -v if not interactive.
1227 (defcustom message-mailer-swallows-blank-line
1228 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1229 system-configuration)
1230 (file-readable-p "/etc/sendmail.cf")
1231 (let ((buffer (get-buffer-create " *temp*")))
1235 (insert-file-contents "/etc/sendmail.cf")
1236 (goto-char (point-min))
1237 (let ((case-fold-search nil))
1238 (re-search-forward "^OR\\>" nil t)))
1239 (kill-buffer buffer))))
1240 ;; According to RFC822, "The field-name must be composed of printable
1241 ;; ASCII characters (i. e., characters that have decimal values between
1242 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1244 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1245 "*Set this non-nil if the system's mailer runs the header and body together.
1246 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1247 The value should be an expression to test whether the problem will
1249 :group 'message-sending
1250 :link '(custom-manual "(message)Mail Variables")
1253 ;;; XXX: This symbol is overloaded! See below.
1254 (defvar message-user-agent nil
1255 "String of the form of PRODUCT/VERSION. Used for User-Agent header field.")
1258 (define-mail-user-agent 'message-user-agent
1259 'message-mail 'message-send-and-exit
1260 'message-kill-buffer 'message-send-hook)
1262 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
1263 "If non-nil, delete the deletable headers before feeding to mh.")
1265 (defvar message-send-method-alist
1266 '((news message-news-p message-send-via-news)
1267 (mail message-mail-p message-send-via-mail))
1268 "Alist of ways to send outgoing messages.
1269 Each element has the form
1271 \(TYPE PREDICATE FUNCTION)
1273 where TYPE is a symbol that names the method; PREDICATE is a function
1274 called without any parameters to determine whether the message is
1275 a message of type TYPE; and FUNCTION is a function to be called if
1276 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1279 (defcustom message-mail-alias-type 'abbrev
1280 "*What alias expansion type to use in Message buffers.
1281 The default is `abbrev', which uses mailabbrev. nil switches
1284 :link '(custom-manual "(message)Mail Aliases")
1285 :type '(choice (const :tag "Use Mailabbrev" abbrev)
1286 (const :tag "No expansion" nil)))
1288 (defcustom message-auto-save-directory
1289 (file-name-as-directory (nnheader-concat message-directory "drafts"))
1290 "*Directory where Message auto-saves buffers if Gnus isn't running.
1291 If nil, Message won't auto-save."
1292 :group 'message-buffers
1293 :link '(custom-manual "(message)Various Message Variables")
1294 :type '(choice directory (const :tag "Don't auto-save" nil)))
1296 (defcustom message-default-charset
1297 (and (featurep 'xemacs) (not (featurep 'mule)) 'iso-8859-1)
1298 "Default charset used in non-MULE XEmacsen."
1301 :link '(custom-manual "(message)Various Message Variables")
1304 (defcustom message-dont-reply-to-names
1305 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
1306 "*A regexp specifying addresses to prune when doing wide replies.
1307 A value of nil means exclude your own user name only."
1310 :link '(custom-manual "(message)Wide Reply")
1311 :type '(choice (const :tag "Yourself" nil)
1314 (defvar message-shoot-gnksa-feet nil
1315 "*A list of GNKSA feet you are allowed to shoot.
1316 Gnus gives you all the opportunity you could possibly want for
1317 shooting yourself in the foot. Also, Gnus allows you to shoot the
1318 feet of Good Net-Keeping Seal of Approval. The following are foot
1320 `empty-article' Allow you to post an empty article;
1321 `quoted-text-only' Allow you to post quoted text only;
1322 `multiple-copies' Allow you to post multiple copies;
1323 `cancel-messages' Allow you to cancel or supersede messages from
1324 your other email addresses.")
1326 (defsubst message-gnksa-enable-p (feature)
1327 (or (not (listp message-shoot-gnksa-feet))
1328 (memq feature message-shoot-gnksa-feet)))
1330 (defcustom message-hidden-headers "^References:"
1331 "Regexp of headers to be hidden when composing new messages.
1332 This can also be a list of regexps to match headers. Or a list
1333 starting with `not' and followed by regexps."
1336 :link '(custom-manual "(message)Message Headers")
1338 :format "%{%t%}: %[Value Type%] %v"
1339 (regexp :menu-tag "regexp" :format "regexp\n%t: %v")
1340 (repeat :menu-tag "(regexp ...)" :format "(regexp ...)\n%v%i"
1341 (regexp :format "%t: %v"))
1342 (cons :menu-tag "(not regexp ...)" :format "(not regexp ...)\n%v"
1344 (repeat :format "%v%i"
1345 (regexp :format "%t: %v")))))
1347 (defcustom message-cite-articles-with-x-no-archive t
1348 "If non-nil, cite text from articles that has X-No-Archive set."
1352 ;;; Internal variables.
1353 ;;; Well, not really internal.
1355 (defvar message-mode-syntax-table
1356 (let ((table (copy-syntax-table text-mode-syntax-table)))
1357 (modify-syntax-entry ?% ". " table)
1358 (modify-syntax-entry ?> ". " table)
1359 (modify-syntax-entry ?< ". " table)
1361 "Syntax table used while in Message mode.")
1363 (defface message-header-to
1366 (:foreground "green2" :bold t))
1369 (:foreground "MidnightBlue" :bold t))
1371 (:bold t :italic t)))
1372 "Face used for displaying From headers."
1373 :group 'message-faces)
1374 ;; backward-compatibility alias
1375 (put 'message-header-to-face 'face-alias 'message-header-to)
1377 (defface message-header-cc
1380 (:foreground "green4" :bold t))
1383 (:foreground "MidnightBlue"))
1386 "Face used for displaying Cc headers."
1387 :group 'message-faces)
1388 ;; backward-compatibility alias
1389 (put 'message-header-cc-face 'face-alias 'message-header-cc)
1391 (defface message-header-subject
1394 (:foreground "green3"))
1397 (:foreground "navy blue" :bold t))
1400 "Face used for displaying subject headers."
1401 :group 'message-faces)
1402 ;; backward-compatibility alias
1403 (put 'message-header-subject-face 'face-alias 'message-header-subject)
1405 (defface message-header-newsgroups
1408 (:foreground "yellow" :bold t :italic t))
1411 (:foreground "blue4" :bold t :italic t))
1413 (:bold t :italic t)))
1414 "Face used for displaying newsgroups headers."
1415 :group 'message-faces)
1416 ;; backward-compatibility alias
1417 (put 'message-header-newsgroups-face 'face-alias 'message-header-newsgroups)
1419 (defface message-header-other
1422 (:foreground "#b00000"))
1425 (:foreground "steel blue"))
1427 (:bold t :italic t)))
1428 "Face used for displaying newsgroups headers."
1429 :group 'message-faces)
1430 ;; backward-compatibility alias
1431 (put 'message-header-other-face 'face-alias 'message-header-other)
1433 (defface message-header-name
1436 (:foreground "DarkGreen"))
1439 (:foreground "cornflower blue"))
1442 "Face used for displaying header names."
1443 :group 'message-faces)
1444 ;; backward-compatibility alias
1445 (put 'message-header-name-face 'face-alias 'message-header-name)
1447 (defface message-header-xheader
1450 (:foreground "blue"))
1453 (:foreground "blue"))
1456 "Face used for displaying X-Header headers."
1457 :group 'message-faces)
1458 ;; backward-compatibility alias
1459 (put 'message-header-xheader-face 'face-alias 'message-header-xheader)
1461 (defface message-separator
1464 (:foreground "blue3"))
1467 (:foreground "brown"))
1470 "Face used for displaying the separator."
1471 :group 'message-faces)
1472 ;; backward-compatibility alias
1473 (put 'message-separator-face 'face-alias 'message-separator)
1475 (defface message-cited-text
1478 (:foreground "red"))
1481 (:foreground "red"))
1484 "Face used for displaying cited text names."
1485 :group 'message-faces)
1486 ;; backward-compatibility alias
1487 (put 'message-cited-text-face 'face-alias 'message-cited-text)
1489 (defface message-mml
1492 (:foreground "ForestGreen"))
1495 (:foreground "ForestGreen"))
1498 "Face used for displaying MML."
1499 :group 'message-faces)
1500 ;; backward-compatibility alias
1501 (put 'message-mml-face 'face-alias 'message-mml)
1503 (defun message-font-lock-make-header-matcher (regexp)
1506 (let ((start (point)))
1509 (goto-char (point-min))
1510 (if (re-search-forward
1511 (concat "^" (regexp-quote mail-header-separator) "$")
1513 (setq limit (min limit (match-beginning 0))))
1515 (and (< start limit)
1516 (re-search-forward ,regexp limit t))))))
1517 (if (featurep 'bytecomp)
1521 (defvar message-font-lock-keywords
1522 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1523 `((,(message-font-lock-make-header-matcher
1524 (concat "^\\([Tt]o:\\)" content))
1525 (1 'message-header-name)
1526 (2 'message-header-to nil t))
1527 (,(message-font-lock-make-header-matcher
1528 (concat "^\\([GBF]?[Cc][Cc]:\\|[Rr]eply-[Tt]o:\\|"
1529 "[Mm]ail-[Cc]opies-[Tt]o:\\|"
1530 "[Mm]ail-[Rr]eply-[Tt]o:\\|"
1531 "[Mm]ail-[Ff]ollowup-[Tt]o:\\)" content))
1532 (1 'message-header-name)
1533 (2 'message-header-cc nil t))
1534 (,(message-font-lock-make-header-matcher
1535 (concat "^\\([Ss]ubject:\\)" content))
1536 (1 'message-header-name)
1537 (2 'message-header-subject nil t))
1538 (,(message-font-lock-make-header-matcher
1539 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content))
1540 (1 'message-header-name)
1541 (2 'message-header-newsgroups nil t))
1542 (,(message-font-lock-make-header-matcher
1543 (concat "^\\([A-Z][^: \n\t]+:\\)" content))
1544 (1 'message-header-name)
1545 (2 'message-header-other nil t))
1546 (,(message-font-lock-make-header-matcher
1547 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content))
1548 (1 'message-header-name)
1549 (2 'message-header-name))
1550 ,@(if (and mail-header-separator
1551 (not (equal mail-header-separator "")))
1552 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1553 1 'message-separator))
1556 (re-search-forward (concat "^\\("
1557 message-cite-prefix-regexp
1560 (0 'message-cited-text))
1561 (,mime-edit-tag-regexp
1563 "Additional expressions to highlight in Message mode.")
1565 ;; XEmacs does it like this. For Emacs, we have to set the
1566 ;; `font-lock-defaults' buffer-local variable.
1567 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
1569 (defvar message-face-alist
1570 '((bold . bold-region)
1571 (underline . underline-region)
1572 (default . (lambda (b e)
1574 (ununderline-region b e))))
1575 "Alist of mail and news faces for facemenu.
1576 The cdr of each entry is a function for applying the face to a region.")
1578 (defcustom message-send-hook nil
1579 "Hook run before sending messages.
1580 This hook is run quite early when sending."
1581 :group 'message-various
1582 :options '(ispell-message)
1583 :link '(custom-manual "(message)Various Message Variables")
1586 (defcustom message-send-mail-hook nil
1587 "Hook run before sending mail messages.
1588 This hook is run very late -- just before the message is sent as
1590 :group 'message-various
1591 :link '(custom-manual "(message)Various Message Variables")
1594 (defcustom message-send-news-hook nil
1595 "Hook run before sending news messages.
1596 This hook is run very late -- just before the message is sent as
1598 :group 'message-various
1599 :link '(custom-manual "(message)Various Message Variables")
1602 (defcustom message-sent-hook nil
1603 "Hook run after sending messages."
1604 :group 'message-various
1607 (defcustom message-use-multi-frames nil
1608 "Make new frame when sending messages."
1609 :group 'message-frames
1612 (defcustom message-delete-frame-on-exit nil
1613 "Delete frame after sending messages."
1614 :group 'message-frames
1615 :type '(choice (const :tag "off" nil)
1616 (const :tag "always" t)
1617 (const :tag "ask" ask)))
1619 (defvar message-draft-coding-system
1620 nnheader-auto-save-coding-system
1621 "*Coding system to compose mail.
1622 If you'd like to make it possible to share draft files between XEmacs
1623 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1624 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1626 (defcustom message-send-mail-partially-limit 1000000
1627 "The limitation of messages sent as message/partial.
1628 The lower bound of message size in characters, beyond which the message
1629 should be sent in several parts. If it is nil, the size is unlimited."
1631 :group 'message-buffers
1632 :link '(custom-manual "(message)Mail Variables")
1633 :type '(choice (const :tag "unlimited" nil)
1636 (defcustom message-alternative-emails nil
1637 "*Regexp matching alternative email addresses.
1638 The first address in the To, Cc or From headers of the original
1639 article matching this variable is used as the From field of
1642 This variable has precedence over posting styles and anything that runs
1643 off `message-setup-hook'."
1644 :group 'message-headers
1645 :link '(custom-manual "(message)Message Headers")
1646 :type '(choice (const :tag "Always use primary" nil)
1649 (defcustom message-hierarchical-addresses nil
1650 "A list of hierarchical mail address definitions.
1652 Inside each entry, the first address is the \"top\" address, and
1653 subsequent addresses are subaddresses; this is used to indicate that
1654 mail sent to the first address will automatically be delivered to the
1655 subaddresses. So if the first address appears in the recipient list
1656 for a message, the subaddresses will be removed (if present) before
1657 the mail is sent. All addresses in this structure should be
1660 :group 'message-headers
1661 :type '(repeat (repeat string)))
1663 (defcustom message-mail-user-agent nil
1664 "Like `mail-user-agent'.
1665 Except if it is nil, use Gnus native MUA; if it is t, use
1668 :type '(radio (const :tag "Gnus native"
1671 (const :tag "`mail-user-agent'"
1674 (function-item :tag "Default Emacs mail"
1676 sendmail-user-agent)
1677 (function-item :tag "Emacs interface to MH"
1680 (function :tag "Other"))
1684 (defcustom message-wide-reply-confirm-recipients nil
1685 "Whether to confirm a wide reply to multiple email recipients.
1686 If this variable is nil, don't ask whether to reply to all recipients.
1687 If this variable is non-nil, pose the question \"Reply to all
1688 recipients?\" before a wide reply to multiple recipients. If the user
1689 answers yes, reply to all recipients as usual. If the user answers
1690 no, only reply back to the author."
1692 :group 'message-headers
1693 :link '(custom-manual "(message)Wide Reply")
1696 (defcustom message-user-fqdn nil
1697 "*Domain part of Message-Ids."
1699 :group 'message-headers
1700 :link '(custom-manual "(message)News Headers")
1701 :type '(radio (const :format "%v " nil)
1702 (string :format "FQDN: %v")))
1704 (defcustom message-use-idna (and (condition-case nil (require 'idna)
1706 (mm-coding-system-p 'utf-8)
1707 (executable-find idna-program)
1709 "Whether to encode non-ASCII in domain names into ASCII according to IDNA."
1711 :group 'message-headers
1712 :link '(custom-manual "(message)IDNA")
1713 :type '(choice (const :tag "Ask" ask)
1714 (const :tag "Never" nil)
1715 (const :tag "Always" t)))
1717 (defcustom message-generate-hashcash nil
1718 "*Whether to generate X-Hashcash: headers.
1719 You must have the \"hashcash\" binary installed, see `hashcash-path'."
1720 :group 'message-headers
1721 :link '(custom-manual "(message)Mail Headers")
1724 ;;; Internal variables.
1726 (defvar message-sending-message "Sending...")
1727 (defvar message-buffer-list nil)
1728 (defvar message-this-is-news nil)
1729 (defvar message-this-is-mail nil)
1730 (defvar message-draft-article nil)
1731 (defvar message-mime-part nil)
1732 (defvar message-posting-charset nil)
1733 (defvar message-inserted-headers nil)
1735 ;; Byte-compiler warning
1737 (defvar gnus-active-hashtb)
1738 (defvar gnus-read-active-file))
1740 ;;; Regexp matching the delimiter of messages in UNIX mail format
1741 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1742 ;;; of rmail.el's rmail-unix-mail-delimiter.
1743 (defvar message-unix-mail-delimiter
1744 (let ((time-zone-regexp
1745 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1746 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1752 ;; Many things can happen to an RFC 822 mailbox before it is put into
1753 ;; a `From' line. The leading phrase can be stripped, e.g.
1754 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1755 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1756 ;; can be removed, e.g.
1757 ;; From: joe@y.z (Joe K
1759 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1762 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1763 ;; The mailbox can be removed or be replaced by white space, e.g.
1764 ;; From: "Joe User"{space}{tab}
1766 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1767 ;; where {space} and {tab} represent the Ascii space and tab characters.
1768 ;; We want to match the results of any of these manglings.
1769 ;; The following regexp rejects names whose first characters are
1770 ;; obviously bogus, but after that anything goes.
1771 "\\([^\0-\b\n-\r\^?].*\\)?"
1773 ;; The time the message was sent.
1774 "\\([^\0-\r \^?]+\\) +" ; day of the week
1775 "\\([^\0-\r \^?]+\\) +" ; month
1776 "\\([0-3]?[0-9]\\) +" ; day of month
1777 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1779 ;; Perhaps a time zone, specified by an abbreviation, or by a
1784 " \\([0-9][0-9]+\\) *"
1786 ;; On some systems the time zone can appear after the year, too.
1790 "\\(remote from .*\\)?"
1793 "Regexp matching the delimiter of messages in UNIX mail format.")
1795 (defvar message-unsent-separator
1796 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1797 "^ *---+ +Returned message +---+ *$\\|"
1798 "^Start of returned message$\\|"
1799 "^ *---+ +Original message +---+ *$\\|"
1800 "^ *--+ +begin message +--+ *$\\|"
1801 "^ *---+ +Original message follows +---+ *$\\|"
1802 "^ *---+ +Undelivered message follows +---+ *$\\|"
1803 "^|? *---+ +Message text follows: +---+ *|?$")
1804 "A regexp that matches the separator before the text of a failed message.")
1806 (defvar message-field-fillers
1807 '((To message-fill-field-address)
1808 (Cc message-fill-field-address)
1809 (From message-fill-field-address))
1810 "Alist of header names/filler functions.")
1812 (defvar message-header-format-alist
1827 (References . message-shorten-references)
1829 "Alist used for formatting headers.")
1831 (defvar message-options nil
1832 "Some saved answers when sending message.")
1834 (defvar message-send-mail-real-function nil
1835 "Internal send mail function.")
1837 (defvar message-bogus-system-names "^localhost\\."
1838 "The regexp of bogus system names.")
1840 (defcustom message-valid-fqdn-regexp
1841 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1843 "\\([a-z][a-z]" ;; two letter country TDLs
1844 "\\|biz\\|com\\|edu\\|gov\\|int\\|mil\\|net\\|org"
1845 "\\|aero\\|coop\\|info\\|name\\|museum"
1846 "\\|arpa\\|pro\\|uucp\\|bitnet\\|bofh" ;; old style?
1848 "Regular expression that matches a valid FQDN."
1849 ;; see also: gnus-button-valid-fqdn-regexp
1851 :group 'message-headers
1855 (autoload 'gnus-alive-p "gnus-util")
1856 (autoload 'gnus-delay-article "gnus-delay")
1857 (autoload 'gnus-extract-address-components "gnus-util")
1858 (autoload 'gnus-find-method-for-group "gnus")
1859 (autoload 'gnus-group-decoded-name "gnus-group")
1860 (autoload 'gnus-group-name-charset "gnus-group")
1861 (autoload 'gnus-group-name-decode "gnus-group")
1862 (autoload 'gnus-groups-from-server "gnus")
1863 (autoload 'gnus-make-local-hook "gnus-util")
1864 (autoload 'gnus-open-server "gnus-int")
1865 (autoload 'gnus-output-to-mail "gnus-util")
1866 (autoload 'gnus-output-to-rmail "gnus-util")
1867 (autoload 'gnus-request-post "gnus-int")
1868 (autoload 'gnus-server-string "gnus")
1869 (autoload 'idna-to-ascii "idna")
1870 (autoload 'message-setup-toolbar "messagexmas")
1871 (autoload 'mh-new-draft-name "mh-comp")
1872 (autoload 'mh-send-letter "mh-comp")
1873 (autoload 'mu-cite-original "mu-cite")
1874 (autoload 'nndraft-request-associate-buffer "nndraft")
1875 (autoload 'nndraft-request-expire-articles "nndraft")
1876 (autoload 'nnvirtual-find-group-art "nnvirtual")
1877 (autoload 'rmail-dont-reply-to "mail-utils")
1878 (autoload 'rmail-msg-is-pruned "rmail")
1879 (autoload 'rmail-msg-restore-non-pruned-header "rmail")
1880 (autoload 'rmail-output "rmailout"))
1885 ;;; Utility functions.
1887 (defun message-eval-parameter (parameter)
1889 (if (symbolp parameter)
1890 (if (functionp parameter)
1896 (defsubst message-get-parameter (key &optional alist)
1898 (setq alist message-parameter-alist))
1899 (cdr (assq key alist)))
1901 (defmacro message-get-parameter-with-eval (key &optional alist)
1902 `(message-eval-parameter (message-get-parameter ,key ,alist)))
1904 (defmacro message-y-or-n-p (question show &rest text)
1905 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1906 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1908 (defmacro message-delete-line (&optional n)
1909 "Delete the current line (and the next N lines)."
1910 `(delete-region (progn (beginning-of-line) (point))
1911 (progn (forward-line ,(or n 1)) (point))))
1913 (defun message-mark-active-p ()
1914 "Non-nil means the mark and region are currently active in this buffer."
1917 (defun message-unquote-tokens (elems)
1918 "Remove double quotes (\") from strings in list ELEMS."
1919 (mapcar (lambda (item)
1920 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1921 (setq item (concat (match-string 1 item)
1922 (match-string 2 item))))
1926 (defun message-tokenize-header (header &optional separator)
1927 "Split HEADER into a list of header elements.
1928 SEPARATOR is a string of characters to be used as separators. \",\"
1929 is used by default."
1932 (let ((regexp (format "[%s]+" (or separator ",")))
1934 beg quoted elems paren)
1936 (set-buffer-multibyte t)
1937 (setq beg (point-min))
1939 (goto-char (point-min))
1944 (cond ((and (> (point) beg)
1946 (and (looking-at regexp)
1949 (push (buffer-substring beg (point)) elems)
1950 (setq beg (match-end 0)))
1951 ((eq (char-after) ?\")
1952 (setq quoted (not quoted)))
1953 ((and (eq (char-after) ?\()
1956 ((and (eq (char-after) ?\))
1959 (nreverse elems)))))
1961 (defun message-mail-file-mbox-p (file)
1962 "Say whether FILE looks like a Unix mbox file."
1963 (when (and (file-exists-p file)
1964 (file-readable-p file)
1965 (file-regular-p file))
1967 (nnheader-insert-file-contents file)
1968 (goto-char (point-min))
1969 (looking-at message-unix-mail-delimiter))))
1971 (defun message-fetch-field (header &optional not-all)
1972 "The same as `mail-fetch-field', only remove all newlines.
1973 The buffer is expected to be narrowed to just the header of the message;
1974 see `message-narrow-to-headers-or-head'."
1975 (let* ((inhibit-point-motion-hooks t)
1976 (value (mail-fetch-field header nil (not not-all))))
1978 (while (string-match "\n[\t ]+" value)
1979 (setq value (replace-match " " t t value)))
1982 (defun message-field-value (header &optional not-all)
1983 "The same as `message-fetch-field', only narrow to the headers first."
1986 (message-narrow-to-headers-or-head)
1987 (message-fetch-field header not-all))))
1989 (defun message-narrow-to-field ()
1990 "Narrow the buffer to the header on the current line."
1992 (while (looking-at "[ \t]")
1998 (if (re-search-forward "^[^ \n\t]" nil t)
2001 (goto-char (point-min)))
2003 (defun message-add-header (&rest headers)
2004 "Add the HEADERS to the message header, skipping those already present."
2007 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
2008 (error "Invalid header `%s'" (car headers)))
2009 (setq hclean (match-string 1 (car headers)))
2011 (message-narrow-to-headers)
2012 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
2013 (goto-char (point-max))
2014 (if (string-match "\n$" (car headers))
2015 (insert (car headers))
2016 (insert (car headers) ?\n)))))
2017 (setq headers (cdr headers))))
2019 (defmacro message-with-reply-buffer (&rest forms)
2020 "Evaluate FORMS in the reply buffer, if it exists."
2021 `(let ((buffer (message-eval-parameter message-reply-buffer)))
2023 (buffer-name buffer))
2028 (put 'message-with-reply-buffer 'lisp-indent-function 0)
2029 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
2031 (defun message-fetch-reply-field (header)
2032 "Fetch field HEADER from the message we're replying to."
2033 (message-with-reply-buffer
2035 (mail-narrow-to-head)
2036 (message-fetch-field header))))
2038 (defun message-strip-list-identifiers (subject)
2039 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
2040 (require 'gnus-sum) ; for gnus-list-identifiers
2041 (let ((regexp (if (stringp gnus-list-identifiers)
2042 gnus-list-identifiers
2043 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
2044 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
2045 " *\\)\\)+\\(Re: +\\)?\\)") subject)
2046 (concat (substring subject 0 (match-beginning 1))
2047 (or (match-string 3 subject)
2048 (match-string 5 subject))
2053 (defun message-strip-subject-re (subject)
2054 "Remove \"Re:\" from subject lines in string SUBJECT."
2055 (if (string-match message-subject-re-regexp subject)
2056 (substring subject (match-end 0))
2059 ;;; Start of functions adopted from `message-utils.el'.
2061 (defun message-strip-subject-trailing-was (subject)
2062 "Remove trailing \"(was: <old subject>)\" from SUBJECT lines.
2063 Leading \"Re: \" is not stripped by this function. Use the function
2064 `message-strip-subject-re' for this."
2065 (let* ((query message-subject-trailing-was-query)
2070 message-subject-trailing-was-ask-regexp
2071 message-subject-trailing-was-regexp)
2074 (setq new (substring subject 0 (match-beginning 0))))
2075 (if (or (not found) (eq query nil))
2078 (if (message-y-or-n-p
2079 "Strip `(was: <old subject>)' in subject? " t
2081 "Strip `(was: <old subject>)' in subject "
2082 "and use the new one instead?\n\n"
2083 "Current subject is: \""
2085 "New subject would be: \""
2087 "See the variable `message-subject-trailing-was-query' "
2088 "to get rid of this query."
2093 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
2096 (defun message-change-subject (new-subject)
2097 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
2098 ;; <URL:http://www.landfield.com/usefor/drafts/draft-ietf-usefor-useage--1.02.unpaged>
2101 (read-from-minibuffer "New subject: ")))
2102 (cond ((and (not (or (null new-subject) ; new subject not empty
2103 (zerop (string-width new-subject))
2104 (string-match "^[ \t]*$" new-subject))))
2108 (message-narrow-to-headers)
2109 (message-fetch-field "Subject"))))
2110 (cond ((not old-subject)
2111 (error "No current subject"))
2114 (regexp-quote new-subject)
2116 old-subject)) ; yes, it really is a new subject
2117 ;; delete eventual Re: prefix
2119 (message-strip-subject-re old-subject))
2120 (message-goto-subject)
2121 (message-delete-line)
2122 (insert (concat "Subject: "
2125 old-subject ")\n")))))))))
2128 (defun message-mark-inserted-region (beg end)
2129 "Mark some region in the current article with enclosing tags.
2130 See `message-mark-insert-begin' and `message-mark-insert-end'."
2133 ;; add to the end of the region first, otherwise end would be invalid
2135 (insert message-mark-insert-end)
2137 (insert message-mark-insert-begin)))
2140 (defun message-mark-insert-file (file)
2141 "Insert FILE at point, marking it with enclosing tags.
2142 See `message-mark-insert-begin' and `message-mark-insert-end'."
2143 (interactive "fFile to insert: ")
2144 ;; reverse insertion to get correct result.
2146 (insert message-mark-insert-end)
2148 (insert-file-contents file)
2150 (insert message-mark-insert-begin)))
2153 (defun message-add-archive-header ()
2154 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
2155 The note can be customized using `message-archive-note'. When called with a
2156 prefix argument, ask for a text to insert. If you don't want the note in the
2157 body, set `message-archive-note' to nil."
2159 (if current-prefix-arg
2160 (setq message-archive-note
2161 (read-from-minibuffer "Reason for No-Archive: "
2162 (cons message-archive-note 0))))
2164 (if (message-goto-signature)
2165 (re-search-backward message-signature-separator))
2166 (when message-archive-note
2167 (insert message-archive-note)
2169 (message-add-header message-archive-header)
2170 (message-sort-headers)))
2173 (defun message-cross-post-followup-to-header (target-group)
2174 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
2175 With prefix-argument just set Follow-Up, don't cross-post."
2177 (list ; Completion based on Gnus
2178 (completing-read "Followup To: "
2179 (if (boundp 'gnus-newsrc-alist)
2181 nil nil '("poster" . 0)
2182 (if (boundp 'gnus-group-history)
2183 'gnus-group-history))))
2184 (message-remove-header "Follow[Uu]p-[Tt]o" t)
2185 (message-goto-newsgroups)
2187 ;; if we already did a crosspost before, kill old target
2188 (if (and message-cross-post-old-target
2190 (regexp-quote (concat "," message-cross-post-old-target))
2193 ;; unless (followup is to poster or user explicitly asked not
2194 ;; to cross-post, or target-group is already in Newsgroups)
2195 ;; add target-group to Newsgroups line.
2197 ;; def: cross-post, req:no
2198 (and message-cross-post-default (not current-prefix-arg))
2199 ;; def: no-cross-post, req:yes
2200 (and (not message-cross-post-default) current-prefix-arg))
2201 (not (string-match "poster" target-group))
2202 (not (string-match (regexp-quote target-group)
2203 (message-fetch-field "Newsgroups"))))
2205 (insert (concat "," target-group))))
2206 (end-of-line) ; ensure Followup: comes after Newsgroups:
2207 ;; unless new followup would be identical to Newsgroups line
2208 ;; make a new Followup-To line
2209 (if (not (string-match (concat "^[ \t]*"
2212 (message-fetch-field "Newsgroups")))
2213 (insert (concat "\nFollowup-To: " target-group)))
2214 (setq message-cross-post-old-target target-group))
2217 (defun message-cross-post-insert-note (target-group cross-post in-old
2219 "Insert a in message body note about a set Followup or Crosspost.
2220 If there have been previous notes, delete them. TARGET-GROUP specifies the
2221 group to Followup-To. When CROSS-POST is t, insert note about
2222 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
2223 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
2224 been made to before the user asked for a Crosspost."
2225 ;; start scanning body for previous uses
2226 (message-goto-signature)
2227 (let ((head (re-search-backward
2228 (concat "^" mail-header-separator)
2229 nil t))) ; just search in body
2230 (message-goto-signature)
2231 (while (re-search-backward
2232 (concat "^" (regexp-quote message-cross-post-note) ".*")
2234 (message-delete-line))
2235 (message-goto-signature)
2236 (while (re-search-backward
2237 (concat "^" (regexp-quote message-followup-to-note) ".*")
2239 (message-delete-line))
2241 (if (message-goto-signature)
2242 (re-search-backward message-signature-separator))
2245 (string-match "^[ \t]*poster[ \t]*$" target-group))
2246 (insert (concat message-followup-to-note target-group "\n"))
2247 (insert (concat message-cross-post-note target-group "\n")))))
2250 (defun message-cross-post-followup-to (target-group)
2251 "Crossposts message and set Followup-To to TARGET-GROUP.
2252 With prefix-argument just set Follow-Up, don't cross-post."
2254 (list ; Completion based on Gnus
2255 (completing-read "Followup To: "
2256 (if (boundp 'gnus-newsrc-alist)
2258 nil nil '("poster" . 0)
2259 (if (boundp 'gnus-group-history)
2260 'gnus-group-history))))
2261 (cond ((not (or (null target-group) ; new subject not empty
2262 (zerop (string-width target-group))
2263 (string-match "^[ \t]*$" target-group)))
2265 (let* ((old-groups (message-fetch-field "Newsgroups"))
2266 (in-old (string-match
2267 (regexp-quote target-group)
2268 (or old-groups ""))))
2269 ;; check whether target exactly matches old Newsgroups
2270 (cond ((not old-groups)
2271 (error "No current newsgroup"))
2275 (regexp-quote target-group)
2278 ;; yes, Newsgroups line must change
2279 (message-cross-post-followup-to-header target-group)
2280 ;; insert note whether we do cross-post or followup-to
2281 (funcall message-cross-post-note-function
2283 (if (or (and message-cross-post-default
2284 (not current-prefix-arg))
2285 (and (not message-cross-post-default)
2286 current-prefix-arg)) t)
2287 in-old old-groups))))))))
2289 ;;; Reduce To: to Cc: or Bcc: header
2292 (defun message-reduce-to-to-cc ()
2293 "Replace contents of To: header with contents of Cc: or Bcc: header."
2296 (save-restriction (message-narrow-to-headers)
2297 (message-fetch-field "cc")))
2299 (if (and (not cc-content)
2302 (message-narrow-to-headers)
2303 (message-fetch-field "bcc"))))
2308 (message-delete-line)
2309 (insert (concat "To: " cc-content "\n"))
2311 (message-narrow-to-headers)
2312 (message-remove-header (if bcc
2316 ;;; End of functions adopted from `message-utils.el'.
2318 (defun message-remove-header (header &optional is-regexp first reverse)
2319 "Remove HEADER in the narrowed buffer.
2320 If IS-REGEXP, HEADER is a regular expression.
2321 If FIRST, only remove the first instance of the header.
2322 Return the number of headers removed."
2323 (goto-char (point-min))
2324 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
2326 (case-fold-search t)
2328 (while (and (not (eobp))
2331 (not (looking-at regexp))
2332 (looking-at regexp))
2339 ;; There might be a continuation header, so we have to search
2340 ;; until we find a new non-continuation line.
2343 (if (re-search-forward "^[^ \t]" nil t)
2344 (goto-char (match-beginning 0))
2347 (if (re-search-forward "^[^ \t]" nil t)
2348 (goto-char (match-beginning 0))
2349 (goto-char (point-max)))))
2352 (defun message-remove-first-header (header)
2353 "Remove the first instance of HEADER if there is more than one."
2355 (regexp (concat "^" (regexp-quote header) ":")))
2357 (goto-char (point-min))
2358 (while (re-search-forward regexp nil t)
2361 (message-remove-header header nil t)
2364 (defun message-narrow-to-headers ()
2365 "Narrow the buffer to the head of the message."
2368 (goto-char (point-min))
2369 (if (re-search-forward
2370 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2373 (goto-char (point-min)))
2375 (defun message-narrow-to-head-1 ()
2376 "Like `message-narrow-to-head'. Don't widen."
2378 (goto-char (point-min))
2379 (if (search-forward "\n\n" nil 1)
2382 (goto-char (point-min)))
2384 (defun message-narrow-to-head ()
2385 "Narrow the buffer to the head of the message.
2386 Point is left at the beginning of the narrowed-to region."
2388 (message-narrow-to-head-1))
2390 (defun message-narrow-to-headers-or-head ()
2391 "Narrow the buffer to the head of the message."
2394 (goto-char (point-min))
2397 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2398 (match-beginning 0))
2399 ((search-forward "\n\n" nil t)
2403 (goto-char (point-min)))
2405 (defun message-news-p ()
2406 "Say whether the current buffer contains a news message."
2407 (and (not message-this-is-mail)
2408 (or message-this-is-news
2411 (message-narrow-to-headers)
2412 (and (message-fetch-field "newsgroups")
2413 (not (message-fetch-field "posted-to"))))))))
2415 (defun message-mail-p ()
2416 "Say whether the current buffer contains a mail message."
2417 (and (not message-this-is-news)
2418 (or message-this-is-mail
2421 (message-narrow-to-headers)
2422 (or (message-fetch-field "to")
2423 (message-fetch-field "cc")
2424 (message-fetch-field "bcc")))))))
2426 (defun message-subscribed-p ()
2427 "Say whether we need to insert a MFT header."
2428 (or message-subscribed-regexps
2429 message-subscribed-addresses
2430 message-subscribed-address-file
2431 message-subscribed-address-functions))
2433 (defun message-next-header ()
2434 "Go to the beginning of the next header."
2436 (or (eobp) (forward-char 1))
2437 (not (if (re-search-forward "^[^ \t]" nil t)
2439 (goto-char (point-max)))))
2441 (defun message-sort-headers-1 ()
2442 "Sort the buffer as headers using `message-rank' text props."
2443 (goto-char (point-min))
2446 nil 'message-next-header
2448 (message-next-header)
2452 (or (get-text-property (point) 'message-rank)
2455 (defun message-sort-headers ()
2456 "Sort the headers of the current message according to `message-header-format-alist'."
2460 (let ((max (1+ (length message-header-format-alist)))
2462 (message-narrow-to-headers)
2463 (while (re-search-forward "^[^ \n]+:" nil t)
2465 (match-beginning 0) (1+ (match-beginning 0))
2467 (if (setq rank (length (memq (assq (intern (buffer-substring
2469 (1- (match-end 0))))
2470 message-header-format-alist)
2471 message-header-format-alist)))
2474 (message-sort-headers-1))))
2476 (defun message-kill-address ()
2477 "Kill the address under point."
2479 (let ((start (point)))
2480 (message-skip-to-next-address)
2481 (kill-region start (point))))
2491 (defvar message-mode-map nil)
2493 (unless message-mode-map
2494 (setq message-mode-map (make-keymap))
2495 (set-keymap-parent message-mode-map text-mode-map)
2496 (define-key message-mode-map "\C-c?" 'describe-mode)
2498 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
2499 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
2500 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
2501 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
2502 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
2503 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2504 ;; (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2505 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-mail-reply-to)
2506 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2507 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2508 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2509 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2510 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2511 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2512 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2513 (define-key message-mode-map "\C-c\C-f\C-i"
2514 'message-insert-or-toggle-importance)
2515 (define-key message-mode-map "\C-c\C-f\C-a"
2516 'message-generate-unsubscribed-mail-followup-to)
2518 ;; modify headers (and insert notes in body)
2519 (define-key message-mode-map "\C-c\C-fs" 'message-change-subject)
2521 (define-key message-mode-map "\C-c\C-fx" 'message-cross-post-followup-to)
2522 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2523 (define-key message-mode-map "\C-c\C-ft" 'message-reduce-to-to-cc)
2524 (define-key message-mode-map "\C-c\C-fa" 'message-add-archive-header)
2525 ;; mark inserted text
2526 (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2527 (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2529 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2530 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2531 (define-key message-mode-map "\C-c\C-fc" 'message-goto-mail-copies-to)
2533 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2534 (define-key message-mode-map "\C-c\C-fw" 'message-insert-wide-reply)
2535 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2536 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2538 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2539 (define-key message-mode-map "\C-c\M-n"
2540 'message-insert-disposition-notification-to)
2542 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2543 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2544 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2545 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2546 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2547 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2548 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2549 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2551 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2552 (define-key message-mode-map "\C-c\C-s" 'message-send)
2553 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2554 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2555 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2557 (define-key message-mode-map "\C-c\M-k" 'message-kill-address)
2558 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2559 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2560 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2561 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2562 (define-key message-mode-map [remap split-line] 'message-split-line)
2564 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2565 (define-key message-mode-map "\t" 'message-tab)
2566 (define-key message-mode-map "\M-;" 'comment-region)
2568 (define-key message-mode-map "\C-xk" 'message-mimic-kill-buffer))
2571 message-mode-menu message-mode-map "Message Menu."
2573 ["Yank Original" message-yank-original t]
2574 ["Fill Yanked Message" message-fill-yanked-message t]
2575 ["Insert Signature" message-insert-signature t]
2576 ["Caesar (rot13) Message" message-caesar-buffer-body t]
2577 ["Caesar (rot13) Region" message-caesar-region (message-mark-active-p)]
2578 ["Elide Region" message-elide-region
2579 :active (message-mark-active-p)
2580 ,@(if (featurep 'xemacs) nil
2581 '(:help "Replace text in region with an ellipsis"))]
2582 ["Delete Outside Region" message-delete-not-region
2583 :active (message-mark-active-p)
2584 ,@(if (featurep 'xemacs) nil
2585 '(:help "Delete all quoted text outside region"))]
2586 ["Kill To Signature" message-kill-to-signature t]
2587 ["Newline and Reformat" message-newline-and-reformat t]
2588 ["Rename buffer" message-rename-buffer t]
2589 ["Spellcheck" ispell-message
2590 ,@(if (featurep 'xemacs) '(t)
2591 '(:help "Spellcheck this message"))]
2592 ["Attach file as MIME" mime-edit-insert-file
2593 ,@(if (featurep 'xemacs) '(t)
2594 '(:help "Attach a file at point"))]
2596 ["Insert Region Marked" message-mark-inserted-region
2597 :active (message-mark-active-p)
2598 ,@(if (featurep 'xemacs) nil
2599 '(:help "Mark region with enclosing tags"))]
2600 ["Insert File Marked..." message-mark-insert-file
2601 ,@(if (featurep 'xemacs) '(t)
2602 '(:help "Insert file at point marked with enclosing tags"))]
2604 ["Send Message" message-send-and-exit
2605 ,@(if (featurep 'xemacs) '(t)
2606 '(:help "Send this message"))]
2607 ["Postpone Message" message-dont-send
2608 ,@(if (featurep 'xemacs) '(t)
2609 '(:help "File this draft message and exit"))]
2610 ["Send at Specific Time..." gnus-delay-article
2611 ,@(if (featurep 'xemacs) '(t)
2612 '(:help "Ask, then arrange to send message at that time"))]
2613 ["Kill Message" message-kill-buffer
2614 ,@(if (featurep 'xemacs) '(t)
2615 '(:help "Delete this message without sending"))]))
2618 message-mode-field-menu message-mode-map ""
2620 ["To" message-goto-to t]
2621 ["From" message-goto-from t]
2622 ["Subject" message-goto-subject t]
2623 ["Change subject..." message-change-subject t]
2624 ["Cc" message-goto-cc t]
2625 ["Bcc" message-goto-bcc t]
2626 ["Fcc" message-goto-fcc t]
2627 ["Reply-To" message-goto-reply-to t]
2628 ["Flag As Important" message-insert-importance-high
2629 ,@(if (featurep 'xemacs) '(t)
2630 '(:help "Mark this message as important"))]
2631 ["Flag As Unimportant" message-insert-importance-low
2632 ,@(if (featurep 'xemacs) '(t)
2633 '(:help "Mark this message as unimportant"))]
2635 message-insert-disposition-notification-to
2636 ,@(if (featurep 'xemacs) '(t)
2637 '(:help "Request a receipt notification"))]
2639 ;; (typical) news stuff
2640 ["Summary" message-goto-summary t]
2641 ["Keywords" message-goto-keywords t]
2642 ["Newsgroups" message-goto-newsgroups t]
2643 ["Fetch Newsgroups" message-insert-newsgroups t]
2644 ["Followup-To" message-goto-followup-to t]
2645 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2646 ["Crosspost / Followup-To..." message-cross-post-followup-to t]
2647 ["Distribution" message-goto-distribution t]
2648 ["X-No-Archive:" message-add-archive-header t ]
2650 ;; (typical) mailing-lists stuff
2651 ["Fetch To" message-insert-to
2652 ,@(if (featurep 'xemacs) '(t)
2653 '(:help "Insert a To header that points to the author."))]
2654 ["Fetch To and Cc" message-insert-wide-reply
2655 ,@(if (featurep 'xemacs) '(t)
2657 "Insert To and Cc headers as if you were doing a wide reply."))]
2659 ["Send to list only" message-to-list-only t]
2660 ["Mail-Followup-To" message-goto-mail-followup-to t]
2661 ["Mail-Reply-To" message-goto-mail-reply-to t]
2662 ["Mail-Copies-To" message-goto-mail-copies-to t]
2663 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2664 ,@(if (featurep 'xemacs) '(t)
2665 '(:help "Insert a reasonable `Mail-Followup-To:' header."))]
2666 ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2668 ["Sort Headers" message-sort-headers t]
2669 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t]
2670 ["Goto Body" message-goto-body t]
2671 ["Goto Signature" message-goto-signature t]))
2673 (defvar message-tool-bar-map nil)
2676 (defvar facemenu-add-face-function)
2677 (defvar facemenu-remove-face-function))
2679 ;;; Forbidden properties
2681 ;; We use `after-change-functions' to keep special text properties
2682 ;; that interfer with the normal function of message mode out of the
2685 (defcustom message-strip-special-text-properties t
2686 "Strip special properties from the message buffer.
2688 Emacs has a number of special text properties which can break message
2689 composing in various ways. If this option is set, message will strip
2690 these properties from the message composition buffer. However, some
2691 packages requires these properties to be present in order to work.
2692 If you use one of these packages, turn this option off, and hope the
2693 message composition doesn't break too bad."
2695 :group 'message-various
2696 :link '(custom-manual "(message)Various Message Variables")
2699 (defconst message-forbidden-properties
2700 ;; No reason this should be clutter up customize. We make it a
2701 ;; property list (rather than a list of property symbols), to be
2702 ;; directly useful for `remove-text-properties'.
2703 '(field nil read-only nil invisible nil intangible nil
2704 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2705 insert-behind-hooks nil point-entered nil point-left nil)
2706 ;; Other special properties:
2707 ;; category, face, display: probably doesn't do any harm.
2708 ;; fontified: is used by font-lock.
2709 ;; syntax-table, local-map: I dunno.
2710 ;; We need to add XEmacs names to the list.
2711 "Property list of with properties forbidden in message buffers.
2712 The values of the properties are ignored, only the property names are used.")
2714 (defun message-tamago-not-in-use-p (pos)
2715 "Return t when tamago version 4 is not in use at the cursor position.
2716 Tamago version 4 is a popular input method for writing Japanese text.
2717 It uses the properties `intangible', `invisible', `modification-hooks'
2718 and `read-only' when translating ascii or kana text to kanji text.
2719 These properties are essential to work, so we should never strip them."
2720 (not (and (boundp 'egg-modefull-mode)
2721 (symbol-value 'egg-modefull-mode)
2722 (or (memq (get-text-property pos 'intangible)
2723 '(its-part-1 its-part-2))
2724 (get-text-property pos 'egg-end)
2725 (get-text-property pos 'egg-lang)
2726 (get-text-property pos 'egg-start)))))
2728 (defun message-strip-forbidden-properties (begin end &optional old-length)
2729 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2730 This function is intended to be called from `after-change-functions'.
2731 See also `message-forbidden-properties'."
2732 (when (and message-strip-special-text-properties
2733 (message-tamago-not-in-use-p begin)
2734 ;; Check whether the invisible MIME part is not inserted.
2735 (not (text-property-any begin end 'mime-edit-invisible t)))
2736 (let ((buffer-read-only nil)
2737 (inhibit-read-only t))
2738 (remove-text-properties begin end message-forbidden-properties))))
2741 (define-derived-mode message-mode text-mode "Message"
2742 "Major mode for editing mail and news to be sent.
2743 Like Text Mode but with these additional commands:\\<message-mode-map>
2744 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2745 C-c C-d Postpone sending the message C-c C-k Kill the message
2746 C-c C-f move to a header field (and create it if there isn't):
2747 C-c C-f C-t move to To C-c C-f C-s move to Subject
2748 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2749 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2750 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2751 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2752 C-c C-f C-o move to From (\"Originator\")
2753 C-c C-f C-f move to Followup-To
2754 C-c C-f C-m move to Mail-Followup-To
2755 C-c C-f c move to Mail-Copies-To
2756 C-c C-f C-i cycle through Importance values
2757 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2758 C-c C-f x crossposting with FollowUp-To header and note in body
2759 C-c C-f t replace To: header with contents of Cc: or Bcc:
2760 C-c C-f a Insert X-No-Archive: header and a note in the body
2761 C-c C-t `message-insert-to' (add a To header to a news followup)
2762 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2763 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2764 C-c C-b `message-goto-body' (move to beginning of message text).
2765 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2766 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2767 C-c C-y `message-yank-original' (insert current message, if any).
2768 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2769 C-c C-e `message-elide-region' (elide the text between point and mark).
2770 C-c C-v `message-delete-not-region' (remove the text outside the region).
2771 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2772 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2773 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2774 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2775 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2776 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2777 M-RET `message-newline-and-reformat' (break the line and reformat)."
2778 (setq local-abbrev-table text-mode-abbrev-table)
2779 (set (make-local-variable 'message-reply-buffer) nil)
2780 (set (make-local-variable 'message-inserted-headers) nil)
2781 (set (make-local-variable 'message-send-actions) nil)
2782 (set (make-local-variable 'message-exit-actions) nil)
2783 (set (make-local-variable 'message-kill-actions) nil)
2784 (set (make-local-variable 'message-postpone-actions) nil)
2785 (set (make-local-variable 'message-draft-article) nil)
2786 (setq buffer-offer-save t)
2787 (set (make-local-variable 'facemenu-add-face-function)
2789 (let ((face-fun (cdr (assq face message-face-alist))))
2791 (funcall face-fun (point) end)
2792 (error "Face %s not configured for %s mode" face mode-name)))
2794 (set (make-local-variable 'facemenu-remove-face-function) t)
2795 (set (make-local-variable 'message-reply-headers) nil)
2796 (make-local-variable 'message-user-agent)
2797 (make-local-variable 'message-post-method)
2798 (set (make-local-variable 'message-sent-message-via) nil)
2799 (set (make-local-variable 'message-checksum) nil)
2800 (make-local-variable 'message-parameter-alist)
2801 (setq message-parameter-alist
2802 (copy-sequence message-startup-parameter-alist))
2803 (message-setup-fill-variables)
2804 ;; Allow using comment commands to add/remove quoting.
2805 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2806 (when message-yank-prefix
2807 (set (make-local-variable 'comment-start) message-yank-prefix)
2808 (set (make-local-variable 'comment-start-skip)
2809 (concat "^" (regexp-quote message-yank-prefix) "[ \t]*")))
2810 (if (featurep 'xemacs)
2811 (message-setup-toolbar)
2812 (set (make-local-variable 'font-lock-defaults)
2813 '(message-font-lock-keywords t))
2814 (if (boundp 'tool-bar-map)
2815 (set (make-local-variable 'tool-bar-map) (message-tool-bar-map))))
2816 (easy-menu-add message-mode-menu message-mode-map)
2817 (easy-menu-add message-mode-field-menu message-mode-map)
2818 (gnus-make-local-hook 'after-change-functions)
2819 ;; Mmmm... Forbidden properties...
2820 (add-hook 'after-change-functions 'message-strip-forbidden-properties
2822 ;; Allow mail alias things.
2823 (when (eq message-mail-alias-type 'abbrev)
2824 (if (fboundp 'mail-abbrevs-setup)
2825 (mail-abbrevs-setup)
2826 (if (fboundp 'mail-aliases-setup) ; warning avoidance
2827 (mail-aliases-setup))))
2828 (unless buffer-file-name
2829 (message-set-auto-save-file-name))
2830 (set (make-local-variable 'indent-tabs-mode) nil)) ;No tabs for indentation.
2832 (defun message-setup-fill-variables ()
2833 "Setup message fill variables."
2834 (set (make-local-variable 'fill-paragraph-function)
2835 'message-fill-paragraph)
2836 (make-local-variable 'paragraph-separate)
2837 (make-local-variable 'paragraph-start)
2838 (make-local-variable 'adaptive-fill-regexp)
2839 (unless (boundp 'adaptive-fill-first-line-regexp)
2840 (setq adaptive-fill-first-line-regexp nil))
2841 (make-local-variable 'adaptive-fill-first-line-regexp)
2842 (let ((quote-prefix-regexp
2843 ;; User should change message-cite-prefix-regexp if
2844 ;; message-yank-prefix is set to an abnormal value.
2845 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
2846 (setq paragraph-start
2848 (regexp-quote mail-header-separator) "$\\|"
2849 "[ \t]*$\\|" ; blank lines
2850 "-- $\\|" ; signature delimiter
2851 "---+$\\|" ; delimiters for forwarded messages
2852 page-delimiter "$\\|" ; spoiler warnings
2853 ".*wrote:$\\|" ; attribution lines
2854 quote-prefix-regexp "$\\|" ; empty lines in quoted text
2855 mime-edit-tag-regexp)) ; MIME-Edit tags
2856 (setq paragraph-separate paragraph-start)
2857 (setq adaptive-fill-regexp
2858 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
2859 (setq adaptive-fill-first-line-regexp
2860 (concat quote-prefix-regexp "\\|"
2861 adaptive-fill-first-line-regexp)))
2862 (make-local-variable 'auto-fill-inhibit-regexp)
2863 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2864 (setq auto-fill-inhibit-regexp nil)
2865 (make-local-variable 'normal-auto-fill-function)
2866 (setq normal-auto-fill-function 'message-do-auto-fill)
2867 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2868 ;; In that case, ensure that it uses the right function. The real
2869 ;; solution would be not to use `define-derived-mode', and run
2870 ;; `text-mode-hook' ourself at the end of the mode.
2871 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2872 (when auto-fill-function
2873 (setq auto-fill-function normal-auto-fill-function)))
2878 ;;; Message mode commands
2881 ;;; Movement commands
2883 (defun message-goto-to ()
2884 "Move point to the To header."
2886 (message-position-on-field "To"))
2888 (defun message-goto-from ()
2889 "Move point to the From header."
2891 (message-position-on-field "From"))
2893 (defun message-goto-subject ()
2894 "Move point to the Subject header."
2896 (message-position-on-field "Subject"))
2898 (defun message-goto-cc ()
2899 "Move point to the Cc header."
2901 (message-position-on-field "Cc" "To"))
2903 (defun message-goto-bcc ()
2904 "Move point to the Bcc header."
2906 (message-position-on-field "Bcc" "Cc" "To"))
2908 (defun message-goto-fcc ()
2909 "Move point to the Fcc header."
2911 (message-position-on-field "Fcc" "To" "Newsgroups"))
2913 (defun message-goto-reply-to ()
2914 "Move point to the Reply-To header."
2916 (message-position-on-field "Reply-To" "Subject"))
2918 (defun message-goto-mail-reply-to ()
2919 "Move point to the Mail-Reply-To header."
2921 (message-position-on-field "Mail-Reply-To" "Subject"))
2923 (defun message-goto-mail-copies-to ()
2924 "Move point to the Mail-Copies-To header. If the header is newly created,
2925 a string \"never\" is inserted in default."
2927 (unless (message-position-on-field "Mail-Copies-To" "Subject")
2931 (defun message-goto-newsgroups ()
2932 "Move point to the Newsgroups header."
2934 (message-position-on-field "Newsgroups"))
2936 (defun message-goto-distribution ()
2937 "Move point to the Distribution header."
2939 (message-position-on-field "Distribution"))
2941 (defun message-goto-followup-to ()
2942 "Move point to the Followup-To header."
2944 (message-position-on-field "Followup-To" "Newsgroups"))
2946 (defun message-goto-mail-followup-to ()
2947 "Move point to the Mail-Followup-To header.
2948 If the header is newly created and To field contains only one address,
2949 the address is inserted by default."
2951 (unless (message-position-on-field "Mail-Followup-To" "To")
2952 (let ((start (point))
2955 (message-narrow-to-headers)
2956 (setq addresses (split-string (mail-strip-quoted-names
2957 (or (std11-fetch-field "to") ""))
2959 (when (eq 1 (length addresses))
2961 (insert (car addresses))
2962 (goto-char start))))))
2964 (defun message-goto-keywords ()
2965 "Move point to the Keywords header."
2967 (message-position-on-field "Keywords" "Subject"))
2969 (defun message-goto-summary ()
2970 "Move point to the Summary header."
2972 (message-position-on-field "Summary" "Subject"))
2974 (defun message-goto-body (&optional interactivep)
2975 "Move point to the beginning of the message body."
2976 (interactive (list t))
2977 (when (and interactivep
2978 (looking-at "[ \t]*\n"))
2980 (goto-char (point-min))
2981 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
2982 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
2984 (defun message-goto-eoh ()
2985 "Move point to the end of the headers."
2990 (defun message-goto-signature ()
2991 "Move point to the beginning of the message signature.
2992 If there is no signature in the article, go to the end and
2995 (goto-char (point-min))
2996 (if (re-search-forward message-signature-separator nil t)
2998 (goto-char (point-max))
3001 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc)
3002 "Insert a reasonable MFT header in a post to an unsubscribed list.
3003 When making original posts to a mailing list you are not subscribed to,
3004 you have to type in a MFT header by hand. The contents, usually, are
3005 the addresses of the list and your own address. This function inserts
3006 such a header automatically. It fetches the contents of the To: header
3007 in the current mail buffer, and appends the current `user-mail-address'.
3009 If the optional argument INCLUDE-CC is non-nil, the addresses in the
3010 Cc: header are also put into the MFT."
3015 (message-narrow-to-headers)
3016 (message-remove-header "Mail-Followup-To")
3017 (setq cc (and include-cc (message-fetch-field "Cc")))
3019 (concat (message-fetch-field "To") "," cc)
3020 (message-fetch-field "To"))))
3021 (message-goto-mail-followup-to)
3022 (insert (concat tos ", " user-mail-address))))
3026 (defun message-insert-to (&optional force)
3027 "Insert a To header that points to the author of the article being replied to.
3028 If the original author requested not to be sent mail, don't insert unless the
3029 prefix FORCE is given."
3031 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
3032 (dont (and mct (or (equal (downcase mct) "never")
3033 (equal (downcase mct) "nobody"))))
3034 (to (or (message-fetch-reply-field "mail-reply-to")
3035 (message-fetch-reply-field "reply-to")
3036 (message-fetch-reply-field "from"))))
3040 "Ignoring the user request not to have copies sent via mail"
3041 "Complying with the user request not to have copies sent via mail")))
3042 (when (and force (not to))
3043 (error "No mail address in the article"))
3044 (when (and to (or force (not dont)))
3045 (message-carefully-insert-headers (list (cons 'To to))))))
3047 (defun message-insert-wide-reply ()
3048 "Insert To and Cc headers as if you were doing a wide reply."
3050 (let ((headers (message-with-reply-buffer
3051 (message-get-reply-headers t))))
3052 (message-carefully-insert-headers headers)))
3054 (defcustom message-header-synonyms
3056 "List of lists of header synonyms.
3057 E.g., if this list contains a member list with elements `Cc' and `To',
3058 then `message-carefully-insert-headers' will not insert a `To' header
3059 when the message is already `Cc'ed to the recipient."
3061 :group 'message-headers
3062 :link '(custom-manual "(message)Message Headers")
3063 :type '(repeat sexp))
3065 (defun message-carefully-insert-headers (headers)
3066 "Insert the HEADERS, an alist, into the message buffer.
3067 Does not insert the headers when they are already present there
3068 or in the synonym headers, defined by `message-header-synonyms'."
3069 ;; FIXME: Should compare only the address and not the full name. Comparison
3070 ;; should be done case-folded (and with `string=' rather than
3072 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
3073 (dolist (header headers)
3074 (let* ((header-name (symbol-name (car header)))
3075 (new-header (cdr header))
3076 (synonyms (loop for synonym in message-header-synonyms
3077 when (memq (car header) synonym) return synonym))
3079 (loop for synonym in synonyms
3080 for old-header = (mail-fetch-field (symbol-name synonym))
3081 when (and old-header (string-match new-header old-header))
3084 (message "already have `%s' in `%s'" new-header old-header)
3085 (when (and (message-position-on-field header-name)
3086 (setq old-header (mail-fetch-field header-name))
3087 (not (string-match "\\` *\\'" old-header)))
3089 (insert new-header)))))
3091 (defun message-widen-reply ()
3092 "Widen the reply to include maximum recipients."
3095 (and message-reply-buffer
3096 (buffer-name message-reply-buffer)
3098 (set-buffer message-reply-buffer)
3099 (message-get-reply-headers t)))))
3102 (message-narrow-to-headers)
3103 (dolist (elem follow-to)
3104 (message-remove-header (symbol-name (car elem)))
3105 (goto-char (point-min))
3106 (insert (symbol-name (car elem)) ": "
3107 (cdr elem) "\n"))))))
3109 (defun message-insert-newsgroups ()
3110 "Insert the Newsgroups header from the article being replied to."
3112 (when (and (message-position-on-field "Newsgroups")
3113 (mail-fetch-field "newsgroups")
3114 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
3116 (insert (or (message-fetch-reply-field "newsgroups") "")))
3120 ;;; Various commands
3122 (defun message-delete-not-region (beg end)
3123 "Delete everything in the body of the current message outside of the region."
3128 ;; snarf citation prefix, if appropriate
3129 (unless (eq (point) (progn (beginning-of-line) (point)))
3130 (when (looking-at message-cite-prefix-regexp)
3131 (setq citeprefix (match-string 0))))
3133 (delete-region (point) (if (not (message-goto-signature))
3139 (delete-region beg (progn (message-goto-body)
3143 (insert citeprefix))))
3144 (when (message-goto-signature)
3147 (defun message-kill-to-signature (&optional arg)
3148 "Kill all text up to the signature.
3149 If a numberic argument or prefix arg is given, leave that number
3150 of lines before the signature intact."
3154 (let ((point (point)))
3155 (narrow-to-region point (point-max))
3156 (message-goto-signature)
3158 (if (and arg (numberp arg))
3159 (forward-line (- -1 arg))
3161 (unless (= point (point))
3162 (kill-region point (point))
3166 (defun message-newline-and-reformat (&optional arg not-break)
3167 "Insert four newlines, and then reformat if inside quoted text.
3168 Prefix arg means justify as well."
3169 (interactive (list (if current-prefix-arg 'full)))
3170 (let (quoted point beg end leading-space bolp fill-paragraph-function)
3171 (setq point (point))
3174 (setq bolp (= beg point))
3175 ;; Find first line of the paragraph.
3177 (while (and (not (eobp))
3178 (not (looking-at message-cite-prefix-regexp))
3179 (looking-at paragraph-start))
3182 (when (looking-at message-cite-prefix-regexp)
3183 (setq quoted (match-string 0))
3184 (goto-char (match-end 0))
3185 (looking-at "[ \t]*")
3186 (setq leading-space (match-string 0)))
3190 (< (- point beg) (length quoted)))
3191 ;; break inside the cite prefix.
3197 (while (and (not (eobp))
3198 (not (looking-at paragraph-separate))
3199 (looking-at message-cite-prefix-regexp)
3200 (equal quoted (match-string 0)))
3201 (goto-char (match-end 0))
3202 (looking-at "[ \t]*")
3203 (if (> (length leading-space) (length (match-string 0)))
3204 (setq leading-space (match-string 0)))
3208 (while (and (if (bobp) nil (forward-line -1) t)
3209 (not (looking-at paragraph-start))
3210 (looking-at message-cite-prefix-regexp)
3211 (equal quoted (match-string 0)))
3213 (goto-char (match-end 0))
3214 (looking-at "[ \t]*")
3215 (if (> (length leading-space) (length (match-string 0)))
3216 (setq leading-space (match-string 0)))))
3217 (while (and (not (eobp))
3218 (not (looking-at paragraph-separate))
3219 (not (looking-at message-cite-prefix-regexp)))
3223 (while (and (if (bobp) nil (forward-line -1) t)
3224 (not (looking-at paragraph-start))
3225 (not (looking-at message-cite-prefix-regexp)))
3226 (setq beg (point))))
3229 (narrow-to-region beg end)
3236 (setq point (point))
3237 ;; (newline 2) doesn't mark both newline's as hard, so call
3238 ;; newline twice. -jas
3241 (delete-region (point) (re-search-forward "[ \t]*"))
3242 (when (and quoted (not bolp))
3243 (insert quoted leading-space)))
3246 (let* ((adaptive-fill-regexp
3247 (regexp-quote (concat quoted leading-space)))
3248 (adaptive-fill-first-line-regexp
3249 adaptive-fill-regexp ))
3250 (fill-paragraph arg))
3251 (fill-paragraph arg))
3252 (if point (goto-char point)))))
3254 (defun message-fill-paragraph (&optional arg)
3255 "Message specific function to fill a paragraph.
3256 This function is used as the value of `fill-paragraph-function' in
3257 Message buffers and is not meant to be called directly."
3258 (interactive (list (if current-prefix-arg 'full)))
3259 (if (if (boundp 'filladapt-mode) filladapt-mode)
3261 (if (message-point-in-header-p)
3262 (message-fill-field)
3263 (message-newline-and-reformat arg t))
3266 ;; Is it better to use `mail-header-end'?
3267 (defun message-point-in-header-p ()
3268 "Return t if point is in the header."
3271 (goto-char (point-min))
3272 (not (re-search-forward
3273 (concat "^" (regexp-quote mail-header-separator) "\n")
3276 (defun message-do-auto-fill ()
3277 "Like `do-auto-fill', but don't fill in message header."
3278 (unless (message-point-in-header-p)
3281 (defun message-insert-signature (&optional force)
3282 "Insert a signature. See documentation for variable `message-signature'."
3283 (interactive (list 0))
3286 ((and (null message-signature)
3289 (goto-char (point-max))
3290 (not (re-search-backward message-signature-separator nil t))))
3291 ((and (null message-signature)
3294 ((functionp message-signature)
3295 (funcall message-signature))
3296 ((listp message-signature)
3297 (eval message-signature))
3298 (t message-signature)))
3300 (cond ((stringp signature)
3302 ((and (eq t signature)
3303 message-signature-file
3304 (file-exists-p message-signature-file))
3307 (goto-char (point-max))
3308 ;; Insert the signature.
3311 (when message-signature-insert-empty-line
3313 (insert "\n" message-signature-separator-for-insertion)
3316 (if (eq signature t)
3317 (insert-file-contents message-signature-file)
3319 (goto-char (point-max))
3320 (or (bolp) (insert "\n")))))
3322 (defun message-insert-importance-high ()
3323 "Insert header to mark message as important."
3327 (message-narrow-to-headers)
3328 (message-remove-header "Importance"))
3330 (insert "Importance: high\n")))
3332 (defun message-insert-importance-low ()
3333 "Insert header to mark message as unimportant."
3337 (message-narrow-to-headers)
3338 (message-remove-header "Importance"))
3340 (insert "Importance: low\n")))
3342 (defun message-insert-or-toggle-importance ()
3343 "Insert a \"Importance: high\" header, or cycle through the header values.
3344 The three allowed values according to RFC 1327 are `high', `normal'
3348 (let ((valid '("high" "normal" "low"))
3352 (message-narrow-to-headers)
3353 (when (setq cur (message-fetch-field "Importance"))
3354 (message-remove-header "Importance")
3355 (setq new (cond ((string= cur "high")
3357 ((string= cur "low")
3362 (insert (format "Importance: %s\n" new)))))
3364 (defun message-insert-disposition-notification-to ()
3365 "Request a disposition notification (return receipt) to this message.
3366 Note that this should not be used in newsgroups."
3370 (message-narrow-to-headers)
3371 (message-remove-header "Disposition-Notification-To"))
3373 (insert (format "Disposition-Notification-To: %s\n"
3374 (or (message-field-value "Reply-to")
3375 (message-field-value "From")
3376 (message-make-from))))))
3378 (defun message-elide-region (b e)
3379 "Elide the text in the region.
3380 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3384 (insert message-elide-ellipsis))
3386 (defvar message-caesar-translation-table nil)
3388 (defun message-caesar-region (b e &optional n)
3389 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3392 (min (point) (or (mark t) (point)))
3393 (max (point) (or (mark t) (point)))
3394 (when current-prefix-arg
3395 (prefix-numeric-value current-prefix-arg))))
3397 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
3398 (unless (or (zerop n) ; no action needed for a rot of 0
3399 (= b e)) ; no region to rotate
3400 ;; We build the table, if necessary.
3401 (when (or (not message-caesar-translation-table)
3402 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
3403 (setq message-caesar-translation-table
3404 (message-make-caesar-translation-table n)))
3405 (translate-region b e message-caesar-translation-table)))
3407 (defun message-make-caesar-translation-table (n)
3408 "Create a rot table with offset N."
3410 (table (make-string 256 0)))
3411 (while (< (incf i) 256)
3414 (substring table 0 ?A)
3415 (substring table (+ ?A n) (+ ?A n (- 26 n)))
3416 (substring table ?A (+ ?A n))
3417 (substring table (+ ?A 26) ?a)
3418 (substring table (+ ?a n) (+ ?a n (- 26 n)))
3419 (substring table ?a (+ ?a n))
3420 (substring table (+ ?a 26) 255))))
3422 (defun message-caesar-buffer-body (&optional rotnum)
3423 "Caesar rotate all letters in the current buffer by 13 places.
3424 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3425 With prefix arg, specifies the number of places to rotate each letter forward.
3426 Mail and USENET news headers are not rotated."
3427 (interactive (if current-prefix-arg
3428 (list (prefix-numeric-value current-prefix-arg))
3432 (when (message-goto-body)
3433 (narrow-to-region (point) (point-max)))
3434 (message-caesar-region (point-min) (point-max) rotnum))))
3436 (defun message-pipe-buffer-body (program)
3437 "Pipe the message body in the current buffer through PROGRAM."
3440 (when (message-goto-body)
3441 (narrow-to-region (point) (point-max)))
3442 (shell-command-on-region
3443 (point-min) (point-max) program nil t))))
3445 (defun message-rename-buffer (&optional enter-string)
3446 "Rename the *message* buffer to \"*message* RECIPIENT\".
3447 If the function is run with a prefix, it will ask for a new buffer
3448 name, rather than giving an automatic name."
3449 (interactive "Pbuffer name: ")
3452 (goto-char (point-min))
3453 (narrow-to-region (point)
3454 (search-forward mail-header-separator nil 'end))
3456 (if (message-news-p) (message-fetch-field "Newsgroups")
3457 (message-fetch-field "To"))
3460 (if (string-match "," mail-to)
3461 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
3463 (name-default (concat "*message* " mail-trimmed-to))
3464 (name (if enter-string
3465 (read-string "New buffer name: " name-default)
3467 (rename-buffer name t)))))
3469 (defun message-fill-yanked-message (&optional justifyp)
3470 "Fill the paragraphs of a message yanked into this one.
3471 Numeric argument means justify as well."
3474 (goto-char (point-min))
3475 (search-forward (concat "\n" mail-header-separator "\n") nil t)
3476 (let ((fill-prefix message-yank-prefix))
3477 (fill-individual-paragraphs (point) (point-max) justifyp))))
3479 (defun message-indent-citation ()
3480 "Modify text just inserted from a message to be cited.
3481 The inserted text should be the region.
3482 When this function returns, the region is again around the modified text.
3484 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3485 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3486 (let ((start (point)))
3487 ;; Remove unwanted headers.
3488 (when message-ignored-cited-headers
3493 (if (search-forward "\n\n" nil t)
3496 (message-remove-header message-ignored-cited-headers t)
3497 (when (= (point-min) (point-max))
3498 (setq all-removed t))
3499 (goto-char (point-max)))
3503 ;; Delete blank lines at the start of the buffer.
3504 (while (and (point-min)
3507 (message-delete-line))
3508 ;; Delete blank lines at the end of the buffer.
3509 (goto-char (point-max))
3512 (while (and (zerop (forward-line -1))
3514 (message-delete-line))
3515 ;; Do the indentation.
3516 (if (null message-yank-prefix)
3517 (indent-rigidly start (mark t) message-indentation-spaces)
3520 (while (< (point) (mark t))
3521 (cond ((looking-at ">")
3522 (insert message-yank-cited-prefix))
3524 (insert message-yank-empty-prefix))
3526 (insert message-yank-prefix)))
3530 (defun message-list-references (refs-list &rest refs-strs)
3531 "Add `Message-ID's which appear in REFS-STRS but not in REFS-LIST,
3533 (let (refs ref id saved-id)
3534 (when (and refs-list
3535 (integerp message-list-references-add-position))
3536 (let ((pos message-list-references-add-position))
3537 (while (and refs-list
3539 (push (pop refs-list) saved-id)
3540 (setq pos (1- pos)))))
3542 (when (setq refs (pop refs-strs))
3543 (setq refs (std11-parse-msg-ids (std11-lexical-analyze refs)))
3545 (when (eq (car (setq ref (pop refs))) 'msg-id)
3546 (setq id (concat "<" (mapconcat 'cdr (cdr ref) "") ">"))
3547 (or (member id refs-list)
3548 (member id saved-id)
3549 (push id refs-list))))))
3551 (push (pop saved-id) refs-list))
3554 (defun message-yank-original (&optional arg)
3555 "Insert the message being replied to, if any.
3556 Puts point before the text and mark after.
3557 Normally indents each nonblank line ARG spaces (default 3). However,
3558 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3560 This function uses `message-cite-function' to do the actual citing.
3562 Just \\[universal-argument] as argument means don't indent, insert no
3563 prefix, and don't delete any headers.
3565 In addition, if `message-yank-add-new-references' is non-nil and this
3566 command is called interactively, new IDs from the yanked article will
3567 be added to the \"References\" field."
3569 (let ((modified (buffer-modified-p)))
3570 (when (let ((buffer (message-eval-parameter message-reply-buffer)))
3572 message-cite-function
3575 (delete-windows-on buffer t)
3576 ; Set the mark at the end of the yanked message.
3577 (push-mark (save-excursion
3578 (insert-buffer-substring buffer)
3580 ;; Add new IDs to the References field.
3581 (when (and message-yank-add-new-references
3583 (let ((start (point))
3589 (setq refs (message-list-references
3591 (or (message-make-references)
3593 (message-narrow-to-headers)
3594 (message-fetch-field "References")
3596 (narrow-to-region start end)
3597 (std11-narrow-to-header)
3598 (unless (equal (setq newrefs
3599 (message-list-references
3600 (copy-sequence refs)
3601 (unless (eq message-yank-add-new-references
3603 (or (message-fetch-field "References")
3604 (message-fetch-field "In-Reply-To")))
3605 (message-fetch-field "Message-ID")))
3607 ;; If the References field has been changed, we make it
3608 ;; visible in the header.
3609 (when message-reply-headers
3610 (mail-header-set-message-id message-reply-headers nil)
3611 (mail-header-set-references message-reply-headers nil))
3613 (message-narrow-to-headers)
3614 (if (let ((case-fold-search t))
3615 (re-search-forward "^References:\\([\t ]+.+\n\\)+"
3618 (goto-char (point-max)))
3620 (list (or (assq 'References message-header-format-alist)
3621 '(References . message-fill-references)))
3622 (list (cons 'References
3623 (mapconcat 'identity
3624 (nreverse newrefs) " ")))))))))
3626 (if (and message-suspend-font-lock-when-citing
3627 (boundp 'font-lock-mode)
3628 (symbol-value 'font-lock-mode))
3633 (funcall message-cite-function))
3635 (funcall message-cite-function)))
3636 (message-exchange-point-and-mark)
3640 (setq message-checksum (message-checksum))))))
3642 (defun message-yank-buffer (buffer)
3643 "Insert BUFFER into the current buffer and quote it."
3644 (interactive "bYank buffer: ")
3645 (let ((message-reply-buffer (get-buffer buffer)))
3646 (save-window-excursion
3647 (message-yank-original))))
3649 (defun message-buffers ()
3650 "Return a list of active message buffers."
3653 (dolist (buffer (buffer-list t))
3655 (when (and (eq major-mode 'message-mode)
3656 (null message-sent-message-via))
3657 (push (buffer-name buffer) buffers))))
3658 (nreverse buffers)))
3660 (eval-when-compile (defvar mail-citation-hook)) ; Compiler directive
3662 (defun message-cite-original-1 (strip-signature)
3663 "Cite an original message.
3664 If STRIP-SIGNATURE is non-nil, strips off the signature from the
3667 This function uses `mail-citation-hook' if that is non-nil."
3668 (if (and (boundp 'mail-citation-hook)
3670 (run-hooks 'mail-citation-hook)
3671 (let ((start (point))
3675 (when message-indent-citation-function
3676 (if (listp message-indent-citation-function)
3677 message-indent-citation-function
3678 (list message-indent-citation-function))))
3679 (message-reply-headers (or message-reply-headers
3680 (make-mail-header))))
3682 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
3685 (mail-header-set-from message-reply-headers
3686 (or (message-fetch-field "from")
3688 (setq x-no-archive (message-fetch-field "x-no-archive")))
3690 (mapc 'funcall functions)
3691 (when strip-signature
3695 (when (re-search-backward message-signature-separator start t)
3696 ;; Also peel off any blank lines before the signature.
3698 (while (looking-at "^[ \t]*$")
3701 (delete-region (point) end)
3702 (unless (search-backward "\n\n" start t)
3703 ;; Insert a blank line if it is peeled off.
3705 (when message-citation-line-function
3708 (funcall message-citation-line-function))
3709 (when (and x-no-archive
3710 (not message-cite-articles-with-x-no-archive)
3711 (string-match "yes" x-no-archive))
3713 (delete-region (point) (mark t))
3714 (insert "> [Quoted text removed due to X-No-Archive]\n")
3715 (forward-line -1)))))
3717 (defun message-cite-original ()
3718 "Cite function in the standard Message manner."
3719 (message-cite-original-1 nil))
3721 (defun message-cite-original-without-signature ()
3722 "Cite function in the standard Message manner.
3723 This function strips off the signature from the original message."
3724 (message-cite-original-1 t))
3726 (defun message-insert-citation-line ()
3727 "Insert a simple citation line."
3728 (when message-reply-headers
3729 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
3731 (defun message-position-on-field (header &rest afters)
3732 (let ((case-fold-search t))
3735 (goto-char (point-min))
3738 (concat "^" (regexp-quote mail-header-separator) "$"))
3739 (match-beginning 0)))
3740 (goto-char (point-min))
3741 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
3743 (re-search-forward "^[^ \t]" nil 'move)
3745 (skip-chars-backward "\n")
3748 (not (re-search-forward
3749 (concat "^" (regexp-quote (car afters)) ":")
3753 (re-search-forward "^[^ \t]" nil 'move)
3754 (beginning-of-line))
3755 (insert header ": \n")
3759 (defun message-remove-signature ()
3760 "Remove the signature from the text between point and mark.
3761 The text will also be indented the normal way."
3763 (let ((start (point))
3765 (if (not (re-search-forward message-signature-separator (mark t) t))
3766 ;; No signature here, so we just indent the cited text.
3767 (message-indent-citation)
3768 ;; Find the last non-empty line.
3770 (while (looking-at "[ \t]*$")
3773 (setq mark (set-marker (make-marker) (point)))
3775 (message-indent-citation)
3776 ;; Enable undoing the deletion.
3778 (delete-region mark (mark t))
3779 (set-marker mark nil)))))
3784 ;;; Sending messages
3787 ;; Avoid byte-compile warning.
3788 (defvar message-encoding-buffer nil)
3789 (defvar message-edit-buffer nil)
3790 (defvar message-mime-mode nil)
3792 (defun message-send-and-exit (&optional arg)
3793 "Send message like `message-send', then, if no errors, exit from mail buffer."
3795 (let ((buf (current-buffer))
3796 (actions message-exit-actions)
3797 (frame (selected-frame))
3798 (org-frame message-original-frame))
3799 (when (and (message-send arg)
3801 (if message-kill-buffer-on-exit
3804 (when (eq buf (current-buffer))
3805 (message-bury buf)))
3806 (message-do-actions actions)
3807 (message-delete-frame frame org-frame)
3810 (defun message-dont-send ()
3811 "Don't send the message you have been editing.
3812 Instead, just auto-save the buffer and then bury it."
3814 (set-buffer-modified-p t)
3816 (let ((actions message-postpone-actions)
3817 (frame (selected-frame))
3818 (org-frame message-original-frame))
3819 (message-bury (current-buffer))
3820 (message-do-actions actions)
3821 (message-delete-frame frame org-frame)))
3823 (defun message-kill-buffer ()
3824 "Kill the current buffer."
3826 (when (or (not (buffer-modified-p))
3827 (not message-kill-buffer-query)
3828 (eq t message-kill-buffer-query-function)
3829 (funcall message-kill-buffer-query-function
3830 "The buffer modified; kill anyway? "))
3831 (let ((actions message-kill-actions)
3832 (draft-article message-draft-article)
3833 (auto-save-file-name buffer-auto-save-file-name)
3834 (file-name buffer-file-name)
3835 (modified (buffer-modified-p))
3836 (frame (selected-frame))
3837 (org-frame message-original-frame))
3838 (setq buffer-file-name nil)
3839 (kill-buffer (current-buffer))
3840 (when (and message-kill-buffer-and-remove-file
3841 (or (and auto-save-file-name
3842 (file-exists-p auto-save-file-name))
3844 (file-exists-p file-name)))
3846 ;; If the message buffer has lived in a dedicated window,
3847 ;; `kill-buffer' has killed the frame. Thus the
3848 ;; `yes-or-no-p' may show up in a lowered frame. Make sure
3849 ;; that the user can see the question by raising the
3852 (yes-or-no-p (format "Remove the backup file%s? "
3853 (if modified " too" "")))))
3855 (delete-file auto-save-file-name))
3856 (let ((message-draft-article draft-article))
3857 (message-disassociate-draft)))
3858 (message-do-actions actions)
3859 (message-delete-frame frame org-frame)))
3862 (defun message-mimic-kill-buffer ()
3863 "Kill the current buffer with query. This is an imitation for
3864 `kill-buffer', but it will delete a message frame."
3866 (let ((bufname (read-buffer (format "Kill buffer: (default %s) "
3868 message-kill-buffer-and-remove-file)
3869 (when (or (not bufname)
3870 (string-equal bufname "")
3871 (string-equal bufname (buffer-name)))
3872 (message-kill-buffer))))
3874 (defun message-delete-frame (frame org-frame)
3875 "Delete frame for editing message."
3876 (when (and (static-if (featurep 'xemacs)
3877 (device-on-window-system-p)
3879 (or (and (eq message-delete-frame-on-exit t)
3880 (select-frame frame)
3881 (or (eq frame org-frame)
3883 (y-or-n-p "Delete this frame?")
3885 (and (eq message-delete-frame-on-exit 'ask)
3886 (select-frame frame)
3888 (y-or-n-p "Delete this frame?")
3890 (delete-frame frame)))
3892 (defun message-bury (buffer)
3893 "Bury this mail BUFFER."
3894 (let ((newbuf (other-buffer buffer)))
3895 (bury-buffer buffer)
3896 (if (and (window-dedicated-p (selected-window))
3897 (not (null (delq (selected-frame) (visible-frame-list)))))
3898 (delete-frame (selected-frame))
3899 (switch-to-buffer newbuf))))
3901 (defun message-send (&optional arg)
3902 "Send the message in the current buffer.
3903 If `message-interactive' is non-nil, wait for success indication or
3904 error messages, and inform user.
3905 Otherwise any failure is reported in a message back to the user from
3907 The usage of ARG is defined by the instance that called Message.
3908 It should typically alter the sending method in some way or other."
3911 (when (or (buffer-modified-p)
3912 (message-check-element 'unchanged)
3913 (y-or-n-p "No changes in the buffer; really send? "))
3914 ;; Make it possible to undo the coming changes.
3916 (let ((inhibit-read-only t))
3917 (put-text-property (point-min) (point-max) 'read-only nil))
3918 (run-hooks 'message-send-hook)
3919 (message-fix-before-sending)
3920 (message message-sending-message)
3921 (let ((message-encoding-buffer
3922 (message-generate-new-buffer-clone-locals " message encoding"))
3923 (message-edit-buffer (current-buffer))
3924 (message-mime-mode mime-edit-mode-flag)
3925 (alist message-send-method-alist)
3927 elem sent dont-barf-on-no-method
3928 (message-options message-options))
3931 (message-options-set-recipient)
3933 (set-buffer message-encoding-buffer)
3935 ;; ;; Avoid copying text props (except hard newlines).
3936 ;; T-gnus change: copy all text props from the editing buffer
3937 ;; into the encoding buffer.
3938 (insert-buffer-substring message-edit-buffer)
3939 (funcall message-encode-function)
3941 (setq elem (pop alist)))
3942 (when (funcall (cadr elem))
3944 (or (not (memq (car elem)
3945 message-sent-message-via))
3946 (message-fetch-field "supersedes")
3947 (if (or (message-gnksa-enable-p 'multiple-copies)
3948 (not (eq (car elem) 'news)))
3951 "Already sent message via %s; resend? "
3953 (error "Denied posting -- multiple copies")))
3954 (setq success (funcall (caddr elem) arg)))
3960 (let ((fcc (message-fetch-field "Fcc"))
3961 (gcc (message-fetch-field "Gcc")))
3964 (eq message-allow-no-recipients 'always)
3965 (and (not (eq message-allow-no-recipients 'never))
3966 (setq dont-barf-on-no-method
3968 (format "No receiver, perform %s anyway? "
3969 (cond ((and fcc gcc) "Fcc and Gcc")
3972 (error "No methods specified to send by"))
3973 (when (or dont-barf-on-no-method
3977 (run-hooks 'message-sent-hook))
3978 (message "Sending...done")
3979 ;; Mark the buffer as unmodified and delete auto-save.
3980 (set-buffer-modified-p nil)
3981 (delete-auto-save-file-if-necessary t)
3982 (message-disassociate-draft)
3983 ;; Delete other mail buffers and stuff.
3984 (message-do-send-housekeeping)
3985 (message-do-actions message-send-actions)
3988 (kill-buffer message-encoding-buffer)))))
3990 (defun message-send-via-mail (arg)
3991 "Send the current message via mail."
3992 (message-send-mail arg))
3994 (defun message-send-via-news (arg)
3995 "Send the current message via news."
3996 (message-send-news arg))
3998 (defmacro message-check (type &rest forms)
3999 "Eval FORMS if TYPE is to be checked."
4000 `(or (message-check-element ,type)
4004 (put 'message-check 'lisp-indent-function 1)
4005 (put 'message-check 'edebug-form-spec '(form body))
4007 ;; Advise the function `invisible-region'.
4008 (unless noninteractive
4009 (let (current-load-list)
4011 `(defadvice invisible-region (around add-mime-edit-invisible (start end)
4013 "Advised by T-gnus Message.
4014 Add the text property `mime-edit-invisible' to an invisible text when
4015 the buffer's major mode is `message-mode'. The added property will be
4016 used to distinguish whether the invisible text is a MIME part or not."
4017 ,(if (featurep 'xemacs)
4018 '(if (eq ?\n (char-after start))
4019 (setq start (1+ start)))
4020 '(if (eq ?\n (char-after (1- end)))
4021 (setq end (1- end))))
4022 (setq ad-return-value
4023 (if (eq 'message-mode major-mode)
4024 (add-text-properties start end
4025 '(invisible t mime-edit-invisible t))
4026 (put-text-property start end 'invisible t)))))))
4028 (defun message-text-with-property (prop &optional start end reverse)
4029 "Return a list of start and end positions where the text has PROP.
4030 START and END bound the search, they default to `point-min' and
4031 `point-max' respectively. If REVERSE is non-nil, find text which does
4034 (setq start (point-min)))
4036 (setq end (point-max)))
4040 (setq start (text-property-any start end prop nil)))
4041 (setq next (next-single-property-change start prop nil end))
4042 (push (cons start (or next end)) regions)
4045 (or (get-text-property start prop)
4046 (and (setq start (next-single-property-change
4047 start prop nil end))
4048 (get-text-property start prop))))
4049 (setq next (text-property-any start end prop nil))
4050 (push (cons start (or next end)) regions)
4052 (nreverse regions)))
4054 (defun message-fix-before-sending ()
4055 "Do various things to make the message nice before sending it."
4056 ;; Make sure there's a newline at the end of the message.
4058 (goto-char (point-max))
4061 ;; Make the hidden headers visible.
4063 ;; Sort headers before sending the message.
4064 (message-sort-headers)
4065 ;; Make invisible text visible except for mime parts which may be
4066 ;; inserted by the MIME-Edit.
4067 ;; It doesn't seem as if this is useful, since the invisible property
4068 ;; is clobbered by an after-change hook anyhow.
4069 (message-check 'invisible-text
4070 ;; FIXME T-gnus: It should also detect invisible overlays.
4073 mime-from mime-to hidden-start)
4074 (while (setq from (text-property-any to (point-max) 'invisible t))
4075 (setq to (or (text-property-not-all from (point-max) 'invisible t)
4078 (while (setq mime-from (text-property-any mime-to to
4079 'mime-edit-invisible t))
4080 (when (> mime-from mime-to)
4081 (setq hidden-start (or hidden-start mime-to))
4082 (add-text-properties mime-to mime-from
4083 '(invisible nil face highlight
4084 font-lock-face highlight)))
4085 (setq mime-to (or (text-property-not-all mime-from to
4086 'mime-edit-invisible t)
4088 (when (< mime-to to)
4089 (setq hidden-start (or hidden-start mime-to))
4090 (add-text-properties mime-to to
4091 '(invisible nil face highlight
4092 font-lock-face highlight))))
4094 (goto-char hidden-start)
4095 (set-window-start (selected-window) (point-at-bol))
4096 (unless (yes-or-no-p
4097 "Invisible text found and made visible; continue sending? ")
4098 (error "Invisible text found and made visible")))))
4099 ;; The following check is needless to T-gnus since T-gnus determines
4100 ;; a MIME charset forcibly (even if it cannot be determined properly,
4101 ;; the value of the `default-mime-charset-for-write' variable is used).
4102 ;; (message-check 'illegible-text
4103 ;; (let (found choice)
4104 ;; (message-goto-body)
4105 ;; (skip-chars-forward mm-7bit-chars)
4106 ;; (while (not (eobp))
4107 ;; (when (let ((char (char-after)))
4108 ;; (or (< (mm-char-int char) 128)
4109 ;; (and (mm-multibyte-p)
4110 ;; (memq (char-charset char)
4111 ;; '(eight-bit-control eight-bit-graphic
4113 ;; (not (get-text-property
4114 ;; (point) 'untranslated-utf-8)))))
4115 ;; (message-overlay-put (message-make-overlay (point) (1+ (point)))
4116 ;; 'face 'highlight)
4119 ;; (skip-chars-forward mm-7bit-chars))
4122 ;; (gnus-multiple-choice
4123 ;; "Non-printable characters found. Continue sending?"
4124 ;; '((?d "Remove non-printable characters and send")
4125 ;; (?r "Replace non-printable characters with dots and send")
4126 ;; (?i "Ignore non-printable characters and send")
4127 ;; (?e "Continue editing"))))
4128 ;; (if (eq choice ?e)
4129 ;; (error "Non-printable characters"))
4130 ;; (message-goto-body)
4131 ;; (skip-chars-forward mm-7bit-chars)
4132 ;; (while (not (eobp))
4133 ;; (when (let ((char (char-after)))
4134 ;; (or (< (mm-char-int char) 128)
4135 ;; (and (mm-multibyte-p)
4136 ;; ;; Fixme: Wrong for Emacs 22 and for things
4137 ;; ;; like undecable utf-8. Should at least
4138 ;; ;; use find-coding-systems-region.
4139 ;; (memq (char-charset char)
4140 ;; '(eight-bit-control eight-bit-graphic
4142 ;; (not (get-text-property
4143 ;; (point) 'untranslated-utf-8)))))
4144 ;; (if (eq choice ?i)
4145 ;; (message-kill-all-overlays)
4147 ;; (when (eq choice ?r)
4150 ;; (skip-chars-forward mm-7bit-chars)))))
4153 (defun message-add-action (action &rest types)
4154 "Add ACTION to be performed when doing an exit of type TYPES."
4156 (add-to-list (intern (format "message-%s-actions" (pop types)))
4159 (defun message-delete-action (action &rest types)
4160 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
4163 (set (setq var (intern (format "message-%s-actions" (pop types))))
4164 (delq action (symbol-value var))))))
4166 (defun message-do-actions (actions)
4167 "Perform all actions in ACTIONS."
4168 ;; Now perform actions on successful sending.
4169 (dolist (action actions)
4172 ;; A simple function.
4175 ;; Something to be evaled.
4179 (defsubst message-maybe-split-and-send-mail ()
4180 "Split a message if necessary, and send it via mail.
4181 Returns nil if sending succeeded, returns any string if sending failed.
4182 This sub function is for exclusive use of `message-send-mail'."
4183 (let ((mime-edit-split-ignored-field-regexp
4184 mime-edit-split-ignored-field-regexp)
4185 (case-fold-search t)
4187 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
4188 (setq mime-edit-split-ignored-field-regexp
4189 (concat (substring mime-edit-split-ignored-field-regexp
4190 0 (match-beginning 0))
4191 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
4192 "_so_don't_rape_it!"
4193 (substring mime-edit-split-ignored-field-regexp
4197 (catch 'message-sending-mail-failure
4198 (mime-edit-maybe-split-and-send
4203 (std11-narrow-to-header mail-header-separator)
4204 (goto-char (point-min))
4205 (when (re-search-forward "^Message-ID:" nil t)
4206 (delete-region (match-end 0) (std11-field-end))
4207 (insert " " (message-make-message-id))))
4209 (funcall (or message-send-mail-real-function
4210 message-send-mail-function))
4212 (throw 'message-sending-mail-failure err))))))
4216 (funcall (or message-send-mail-real-function
4217 message-send-mail-function))
4221 (if (eq 'error (car failure))
4223 (prin1-to-string failure)))))
4225 (defun message-send-mail-partially ()
4226 "Send mail as message/partial."
4227 ;; replace the header delimiter with a blank line
4228 (goto-char (point-min))
4230 (concat "^" (regexp-quote mail-header-separator) "\n"))
4231 (replace-match "\n")
4232 (run-hooks 'message-send-mail-hook)
4233 (let ((p (goto-char (point-min)))
4234 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
4235 (curbuf (current-buffer))
4236 (id (message-make-message-id)) (n 1)
4237 plist total header required-mail-headers)
4239 (if (< (point-max) (+ p message-send-mail-partially-limit))
4240 (goto-char (point-max))
4241 (goto-char (+ p message-send-mail-partially-limit))
4243 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
4246 (setq total (length plist))
4247 (push (point-max) plist)
4248 (setq plist (nreverse plist))
4251 (setq p (pop plist))
4254 (copy-to-buffer tembuf p (car plist))
4256 (goto-char (point-min))
4259 (goto-char (point-min))
4260 (narrow-to-region (point) (point))
4263 (setq header (buffer-substring (point-min) (point)))
4264 (goto-char (point-min))
4265 (narrow-to-region (point) (point))
4267 (message-remove-header "Mime-Version")
4268 (message-remove-header "Content-Type")
4269 (message-remove-header "Content-Transfer-Encoding")
4270 (message-remove-header "Message-ID")
4271 (message-remove-header "Lines")
4272 (goto-char (point-max))
4273 (insert "Mime-Version: 1.0\n")
4274 (setq header (buffer-string)))
4275 (goto-char (point-max))
4276 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
4279 (let ((mail-header-separator ""))
4280 (when (memq 'Message-ID message-required-mail-headers)
4281 (insert "Message-ID: " (message-make-message-id) "\n"))
4282 (when (memq 'Lines message-required-mail-headers)
4283 (insert "Lines: " (message-make-lines) "\n"))
4284 (message-goto-subject)
4286 (insert (format " (%d/%d)" n total))
4288 (mm-with-unibyte-current-buffer
4289 (funcall (or message-send-mail-real-function
4290 message-send-mail-function))))
4292 (setq p (pop plist))
4294 (kill-buffer tembuf))))
4296 (defun message-send-mail (&optional arg)
4297 (require 'mail-utils)
4298 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
4299 (case-fold-search nil)
4300 (news (message-news-p))
4301 (message-this-is-mail t)
4302 (headers message-required-mail-headers)
4304 (when message-generate-hashcash
4305 (message "Generating hashcash...")
4306 ;; Wait for calculations already started to finish...
4307 (hashcash-wait-async)
4308 ;; ...and do calculations not already done. mail-add-payment
4309 ;; will leave existing X-Hashcash headers alone.
4311 (message "Generating hashcash...done"))
4313 (message-narrow-to-headers)
4314 ;; Generate the Mail-Followup-To header if the header is not there...
4315 (if (and (message-subscribed-p)
4316 (not (mail-fetch-field "mail-followup-to")))
4319 (cons "Mail-Followup-To" (message-make-mail-followup-to))
4320 message-required-mail-headers))
4321 ;; otherwise, delete the MFT header if the field is empty
4322 (when (equal "" (mail-fetch-field "mail-followup-to"))
4323 (message-remove-header "^Mail-Followup-To:")))
4324 ;; Insert some headers.
4325 (let ((message-deletable-headers
4326 (if news nil message-deletable-headers)))
4327 (message-generate-headers headers))
4328 ;; Let the user do all of the above.
4329 (run-hooks 'message-header-hook))
4330 (if (not (message-check-mail-syntax))
4338 ;; ;; Avoid copying text props (except hard newlines).
4339 ;; T-gnus change: copy all text props from the editing buffer
4340 ;; into the encoding buffer.
4341 (insert-buffer-substring message-encoding-buffer)
4342 ;; Remove some headers.
4344 (message-narrow-to-headers)
4345 ;; We Semi-gnus people have no use for it.
4346 ;; ;; We (re)generate the Lines header.
4347 ;; (when (memq 'Lines message-required-mail-headers)
4348 ;; (message-generate-headers '(Lines)))
4349 (message-remove-header message-ignored-mail-headers t))
4350 (goto-char (point-max))
4351 ;; require one newline at the end.
4352 (or (= (preceding-char) ?\n)
4354 (message-cleanup-headers)
4355 ;; FIXME: we're inserting the courtesy copy after encoding.
4356 ;; This is wrong if the courtesy copy string contains
4357 ;; non-ASCII characters. -- jh
4360 (message-narrow-to-headers)
4362 (or (message-fetch-field "cc")
4363 (message-fetch-field "bcc")
4364 (message-fetch-field "to"))
4365 (let ((content-type (mime-read-Content-Type)))
4370 (eq 'text (cdr (assq 'type content-type)))
4371 (eq 'plain (cdr (assq 'subtype content-type)))))
4374 (mime-read-Content-Transfer-Encoding)))))))
4375 (message-insert-courtesy-copy))
4376 (setq failure (message-maybe-split-and-send-mail)))
4377 (kill-buffer tembuf))
4378 (set-buffer message-edit-buffer)
4381 (message "Couldn't send message via mail: %s" failure)
4383 (push 'mail message-sent-message-via)))))
4385 (defun message-send-mail-with-sendmail ()
4386 "Send off the prepared buffer with sendmail."
4387 (let ((errbuf (if message-interactive
4388 (message-generate-new-buffer-clone-locals
4391 resend-to-addresses delimline)
4394 (let ((case-fold-search t))
4396 (message-narrow-to-headers)
4397 (setq resend-to-addresses (message-fetch-field "resent-to")))
4398 ;; Change header-delimiter to be what sendmail expects.
4399 (goto-char (point-min))
4401 (concat "^" (regexp-quote mail-header-separator) "\n"))
4402 (replace-match "\n")
4404 (setq delimline (point-marker))
4405 (run-hooks 'message-send-mail-hook)
4406 ;; Insert an extra newline if we need it to work around
4407 ;; Sun's bug that swallows newlines.
4408 (goto-char (1+ delimline))
4409 (when (eval message-mailer-swallows-blank-line)
4411 (when message-interactive
4412 (with-current-buffer errbuf
4414 (let* ((default-directory "/")
4415 (cpr (as-binary-process
4417 'call-process-region
4419 (list (point-min) (point-max)
4420 (if (boundp 'sendmail-program)
4422 "/usr/lib/sendmail")
4423 nil errbuf nil "-oi")
4424 ;; Always specify who from,
4425 ;; since some systems have broken sendmails.
4426 ;; But some systems are more broken with -f, so
4427 ;; we'll let users override this.
4428 (if (null message-sendmail-f-is-evil)
4429 (list "-f" (message-sendmail-envelope-from)))
4430 ;; These mean "report errors by mail"
4431 ;; and "deliver in background".
4432 (if (null message-interactive) '("-oem" "-odb"))
4433 ;; Get the addresses from the message
4434 ;; unless this is a resend.
4435 ;; We must not do that for a resend
4436 ;; because we would find the original addresses.
4437 ;; For a resend, include the specific addresses.
4438 (if resend-to-addresses
4439 (list resend-to-addresses)
4441 (unless (or (null cpr) (and (numberp cpr) (zerop cpr)))
4442 (error "Sending...failed with exit value %d" cpr)))
4443 (when message-interactive
4446 (goto-char (point-min))
4447 (while (re-search-forward "\n+ *" nil t)
4448 (replace-match "; "))
4449 (if (not (zerop (buffer-size)))
4450 (error "Sending...failed to %s"
4451 (buffer-string))))))
4452 (when (bufferp errbuf)
4453 (kill-buffer errbuf)))))
4455 (defun message-send-mail-with-qmail ()
4456 "Pass the prepared message buffer to qmail-inject.
4457 Refer to the documentation for the variable `message-send-mail-function'
4458 to find out how to use this."
4459 ;; replace the header delimiter with a blank line
4460 (goto-char (point-min))
4462 (concat "^" (regexp-quote mail-header-separator) "\n"))
4463 (replace-match "\n")
4465 (run-hooks 'message-send-mail-hook)
4470 'call-process-region (point-min) (point-max)
4471 message-qmail-inject-program nil nil nil
4472 ;; qmail-inject's default behaviour is to look for addresses on the
4473 ;; command line; if there're none, it scans the headers.
4474 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4476 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4477 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4478 ;; message from stdin.
4480 ;; qmail also has the advantage of not having been raped by
4481 ;; various vendors, so we don't have to allow for that, either --
4482 ;; compare this with message-send-mail-with-sendmail and weep
4483 ;; for sendmail's lost innocence.
4485 ;; all this is way cool coz it lets us keep the arguments entirely
4486 ;; free for -inject-arguments -- a big win for the user and for us
4487 ;; since we don't have to play that double-guessing game and the user
4488 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4489 (if (functionp message-qmail-inject-args)
4490 (funcall message-qmail-inject-args)
4491 message-qmail-inject-args)))
4492 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4493 ;; we have to look at the retval instead
4495 (100 (error "qmail-inject reported permanent failure"))
4496 (111 (error "qmail-inject reported transient failure"))
4497 ;; should never happen
4498 (t (error "qmail-inject reported unknown failure"))))
4500 (defun message-send-mail-with-mh ()
4501 "Send the prepared message buffer with mh."
4502 (let ((mh-previous-window-config nil)
4503 (name (mh-new-draft-name)))
4504 (setq buffer-file-name name)
4505 ;; MH wants to generate these headers itself.
4506 (when message-mh-deletable-headers
4507 (let ((headers message-mh-deletable-headers))
4509 (goto-char (point-min))
4510 (and (re-search-forward
4511 (concat "^" (symbol-name (car headers)) ": *") nil t)
4512 (message-delete-line))
4514 (run-hooks 'message-send-mail-hook)
4515 ;; Pass it on to mh.
4518 (defun message-send-mail-with-smtp ()
4519 "Send off the prepared buffer with SMTP."
4520 (require 'smtp) ; XXX
4521 (let ((case-fold-search t)
4524 (message-narrow-to-headers)
4526 ;; XXX: Should be replaced by better one.
4527 (smtp-deduce-address-list (current-buffer)
4528 (point-min) (point-max)))
4529 ;; Remove BCC lines.
4530 (message-remove-header "bcc"))
4531 ;; replace the header delimiter with a blank line.
4532 (goto-char (point-min))
4534 (concat "^" (regexp-quote mail-header-separator) "\n"))
4535 (replace-match "\n")
4537 (run-hooks 'message-send-mail-hook)
4539 (smtp-send-buffer user-mail-address recipients (current-buffer))
4540 (error "Sending failed; no recipients"))))
4542 (defsubst message-maybe-split-and-send-news (method)
4543 "Split a message if necessary, and send it via news.
4544 Returns nil if sending succeeded, returns t if sending failed.
4545 This sub function is for exclusive use of `message-send-news'."
4546 (let ((mime-edit-split-ignored-field-regexp
4547 mime-edit-split-ignored-field-regexp)
4548 (case-fold-search t))
4549 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
4550 (setq mime-edit-split-ignored-field-regexp
4551 (concat (substring mime-edit-split-ignored-field-regexp
4552 0 (match-beginning 0))
4553 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
4554 "_so_don't_rape_it!"
4555 (substring mime-edit-split-ignored-field-regexp
4558 (catch 'message-sending-news-failure
4559 (mime-edit-maybe-split-and-send
4564 (std11-narrow-to-header mail-header-separator)
4565 (goto-char (point-min))
4566 (when (re-search-forward "^Message-ID:" nil t)
4567 (delete-region (match-end 0) (std11-field-end))
4568 (insert " " (message-make-message-id))))
4569 (unless (funcall message-send-news-function method)
4570 (throw 'message-sending-news-failure t)))))
4572 (not (funcall message-send-news-function method)))))
4574 (defun message-smtpmail-send-it ()
4575 "Send the prepared message buffer with `smtpmail-send-it'.
4576 This only differs from `smtpmail-send-it' that this command evaluates
4577 `message-send-mail-hook' just before sending a message. It is useful
4578 if your ISP requires the POP-before-SMTP authentication. See the Gnus
4579 manual for details."
4580 (run-hooks 'message-send-mail-hook)
4583 (defun message-canlock-generate ()
4584 "Return a string that is non-trivial to guess.
4585 Do not use this for anything important, it is cryptographically weak."
4587 (let (sha1-maximum-internal-length)
4588 (sha1 (concat (message-unique-id)
4589 (format "%x%x%x" (random) (random t) (random))
4590 (prin1-to-string (recent-keys))
4591 (prin1-to-string (garbage-collect))))))
4593 (defun message-canlock-password ()
4594 "The password used by message for cancel locks.
4595 This is the value of `canlock-password', if that option is non-nil.
4596 Otherwise, generate and save a value for `canlock-password' first."
4597 (unless canlock-password
4598 (customize-save-variable 'canlock-password (message-canlock-generate))
4599 (setq canlock-password-for-verify canlock-password))
4602 (defun message-insert-canlock ()
4603 (when message-insert-canlock
4604 (message-canlock-password)
4605 (canlock-insert-header)))
4607 (defun message-send-news (&optional arg)
4608 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4609 (case-fold-search nil)
4610 (method (if (functionp message-post-method)
4611 (funcall message-post-method arg)
4612 message-post-method))
4613 (newsgroups-field (save-restriction
4614 (message-narrow-to-headers-or-head)
4615 (message-fetch-field "Newsgroups")))
4616 (followup-field (save-restriction
4617 (message-narrow-to-headers-or-head)
4618 (message-fetch-field "Followup-To")))
4619 ;; BUG: We really need to get the charset for each name in the
4620 ;; Newsgroups and Followup-To lines to allow crossposting
4621 ;; between group namess with incompatible character sets.
4622 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4623 (group-field-charset
4624 (gnus-group-name-charset method newsgroups-field))
4625 (followup-field-charset
4626 (gnus-group-name-charset method (or followup-field "")))
4627 (mime-field-encoding-method-alist
4628 (append (when group-field-charset
4629 (list (cons "Newsgroups" group-field-charset)))
4630 (when followup-field-charset
4631 (list (cons "Followup-To" followup-field-charset)))
4632 mime-field-encoding-method-alist))
4633 (message-syntax-checks
4635 (listp message-syntax-checks))
4636 (cons '(existing-newsgroups . disabled)
4637 message-syntax-checks)
4638 message-syntax-checks))
4639 (message-this-is-news t)
4642 (message-narrow-to-headers)
4643 ;; Insert some headers.
4644 (message-generate-headers message-required-news-headers)
4645 (message-insert-canlock)
4646 ;; Let the user do all of the above.
4647 (run-hooks 'message-header-hook))
4648 ;; Note: This check will be disabled by the ".*" default value for
4649 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4650 (when (and group-field-charset
4651 (listp message-syntax-checks))
4652 (setq message-syntax-checks
4653 (cons '(valid-newsgroups . disabled)
4654 message-syntax-checks)))
4655 (message-cleanup-headers)
4656 (if (not (let ((message-post-method method))
4657 (message-check-news-syntax)))
4662 (buffer-disable-undo)
4664 (insert-buffer-substring message-encoding-buffer)
4665 ;; Remove some headers.
4667 (message-narrow-to-headers)
4668 ;; We Semi-gnus people have no use for it.
4669 ;; ;; We (re)generate the Lines header.
4670 ;; (when (memq 'Lines message-required-mail-headers)
4671 ;; (message-generate-headers '(Lines)))
4672 ;; Remove some headers.
4673 (message-remove-header message-ignored-news-headers t))
4674 (goto-char (point-max))
4675 ;; require one newline at the end.
4676 (or (= (preceding-char) ?\n)
4678 (setq result (message-maybe-split-and-send-news method)))
4679 (kill-buffer tembuf))
4680 (set-buffer message-edit-buffer)
4683 (message "Couldn't send message via news: %s"
4684 (nnheader-get-report (car method)))
4686 (push 'news message-sent-message-via)))))
4688 ;; 1997-09-29 by MORIOKA Tomohiko
4689 (defun message-send-news-with-gnus (method)
4690 (let ((case-fold-search t))
4691 ;; Remove the delimiter.
4692 (goto-char (point-min))
4694 (concat "^" (regexp-quote mail-header-separator) "\n"))
4695 (replace-match "\n")
4697 (run-hooks 'message-send-news-hook)
4698 (gnus-open-server method)
4699 (message "Sending news via %s..." (gnus-server-string method))
4700 (gnus-request-post method)
4704 ;;; Header generation & syntax checking.
4707 (defun message-check-element (type)
4708 "Return non-nil if this TYPE is not to be checked."
4709 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
4711 (let ((able (assq type message-syntax-checks)))
4713 (eq (cdr able) 'disabled)))))
4715 (defun message-check-news-syntax ()
4716 "Check the syntax of the message."
4721 ;; We narrow to the headers and check them first.
4724 (message-narrow-to-headers)
4725 (message-check-news-header-syntax)))
4728 (set-buffer message-edit-buffer)
4729 (message-check-news-body-syntax))))))
4731 (defun message-check-news-header-syntax ()
4733 ;; Check Newsgroups header.
4734 (message-check 'newsgroups
4735 (let ((group (message-fetch-field "newsgroups")))
4738 (not (string-match "\\`[ \t]*\\'" group)))
4741 "The newsgroups field is empty or missing. Posting is denied.")))))
4742 ;; Check the Subject header.
4743 (message-check 'subject
4744 (let* ((case-fold-search t)
4745 (subject (message-fetch-field "subject")))
4748 (not (string-match "\\`[ \t]*\\'" subject)))
4751 "The subject field is empty or missing. Posting is denied.")))))
4752 ;; Check for commands in Subject.
4753 (message-check 'subject-cmsg
4754 (if (string-match "^cmsg " (message-fetch-field "subject"))
4756 "The control code \"cmsg\" is in the subject. Really post? ")
4758 ;; Check long header lines.
4759 (message-check 'long-header-lines
4760 (let ((start (point))
4764 (while (and (not found)
4765 (re-search-forward "^\\([^ \t:]+\\): " nil t))
4766 (if (> (- (point) (match-beginning 0)) 998)
4768 length (- (point) (match-beginning 0)))
4769 (setq header (match-string-no-properties 1)))
4770 (setq start (match-beginning 0))
4773 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
4776 ;; Check for multiple identical headers.
4777 (message-check 'multiple-headers
4779 (while (and (not found)
4780 (re-search-forward "^[^ \t:]+: " nil t))
4782 (or (re-search-forward
4787 (match-beginning 0) (- (match-end 0) 2))))
4792 (y-or-n-p (format "Multiple %s headers. Really post? " found))
4794 ;; Check for Version and Sendsys.
4795 (message-check 'sendsys
4796 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
4798 (format "The article contains a %s command. Really post? "
4799 (buffer-substring (match-beginning 0)
4800 (1- (match-end 0)))))
4802 ;; See whether we can shorten Followup-To.
4803 (message-check 'shorten-followup-to
4804 (let ((newsgroups (message-fetch-field "newsgroups"))
4805 (followup-to (message-fetch-field "followup-to"))
4807 (when (and newsgroups
4808 (string-match "," newsgroups)
4813 (setq to (completing-read
4814 "Followups to (default no Followup-To header): "
4817 (message-tokenize-header
4819 (goto-char (point-min))
4820 (insert "Followup-To: " to "\n"))
4822 ;; Check "Shoot me".
4823 (message-check 'shoot
4824 (if (re-search-forward
4825 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t)
4826 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
4828 ;; Check for Approved.
4829 (message-check 'approved
4830 (if (re-search-forward "^Approved:" nil t)
4831 (y-or-n-p "The article contains an Approved header. Really post? ")
4833 ;; Check the Message-ID header.
4834 (message-check 'message-id
4835 (let* ((case-fold-search t)
4836 (message-id (message-fetch-field "message-id" t)))
4837 (or (not message-id)
4838 ;; Is there an @ in the ID?
4839 (and (string-match "@" message-id)
4840 ;; Is there a dot in the ID?
4841 (string-match "@[^.]*\\." message-id)
4842 ;; Does the ID end with a dot?
4843 (not (string-match "\\.>" message-id)))
4845 (format "The Message-ID looks strange: \"%s\". Really post? "
4847 ;; Check the Newsgroups & Followup-To headers.
4848 (message-check 'existing-newsgroups
4849 (let* ((case-fold-search t)
4850 (newsgroups (message-fetch-field "newsgroups"))
4851 (followup-to (message-fetch-field "followup-to"))
4852 (groups (message-tokenize-header
4854 (concat newsgroups "," followup-to)
4856 (post-method (if (functionp message-post-method)
4857 (funcall message-post-method)
4858 message-post-method))
4859 ;; KLUDGE to handle nnvirtual groups. Doing this right
4860 ;; would probably involve a new nnoo function.
4861 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
4862 (method (if (and (consp post-method)
4863 (eq (car post-method) 'nnvirtual)
4864 gnus-message-group-art)
4865 (let ((group (car (nnvirtual-find-group-art
4866 (car gnus-message-group-art)
4867 (cdr gnus-message-group-art)))))
4868 (gnus-find-method-for-group group))
4872 (gnus-group-name-decode
4873 (gnus-group-real-name n)
4874 (gnus-group-name-charset method n)))
4875 (gnus-groups-from-server method)))
4878 (when (and (not (equal (car groups) "poster"))
4879 (not (member (car groups) known-groups))
4880 (not (member (car groups) errors)))
4881 (push (car groups) errors))
4884 ;; Gnus is not running.
4885 ((or (not (and (boundp 'gnus-active-hashtb)
4886 gnus-active-hashtb))
4887 (not (boundp 'gnus-read-active-file)))
4889 ;; We don't have all the group names.
4890 ((and (or (not gnus-read-active-file)
4891 (eq gnus-read-active-file 'some))
4895 "Really use %s possibly unknown group%s: %s? "
4896 (if (= (length errors) 1) "this" "these")
4897 (if (= (length errors) 1) "" "s")
4898 (mapconcat 'identity errors ", "))))
4899 ;; There were no errors.
4902 ;; There are unknown groups.
4906 "Really post to %s unknown group%s: %s? "
4907 (if (= (length errors) 1) "this" "these")
4908 (if (= (length errors) 1) "" "s")
4909 (mapconcat 'identity errors ", ")))))))
4910 ;; Check continuation headers.
4911 (message-check 'continuation-headers
4912 (goto-char (point-min))
4913 (let ((do-posting t))
4914 (while (re-search-forward "^[^ \t\n][^:\n]*$" nil t)
4915 (if (y-or-n-p "Fix continuation lines? ")
4917 (goto-char (match-beginning 0))
4919 (unless (y-or-n-p "Send anyway? ")
4920 (setq do-posting nil))))
4922 ;; Check the Newsgroups & Followup-To headers for syntax errors.
4923 (message-check 'valid-newsgroups
4924 (let ((case-fold-search t)
4925 (headers '("Newsgroups" "Followup-To"))
4927 (while (and headers (not error))
4928 (when (setq header (mail-fetch-field (car headers)))
4932 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
4937 (not (string-match "\\.\\'\\|\\.\\." g)))
4938 (message-tokenize-header header ","))))
4945 (format "The %s header looks odd: \"%s\". Really post? "
4946 (car headers) header)))))
4947 (message-check 'repeated-newsgroups
4948 (let ((case-fold-search t)
4949 (headers '("Newsgroups" "Followup-To"))
4950 header error groups group)
4953 (when (setq header (mail-fetch-field (pop headers)))
4954 (setq groups (message-tokenize-header header ","))
4955 (while (setq group (pop groups))
4956 (when (member group groups)
4962 (format "Group %s is repeated in headers. Really post? " error)))))
4963 ;; Check the From header.
4964 (message-check 'from
4965 (let* ((case-fold-search t)
4966 (from (message-fetch-field "from"))
4970 (message "There is no From line. Posting is denied.")
4972 ((or (not (string-match
4974 (setq ad (nth 1 (std11-extract-address-components
4975 from))))) ;larsi@ifi
4976 (string-match "\\.\\." ad) ;larsi@ifi..uio
4977 (string-match "@\\." ad) ;larsi@.ifi.uio
4978 (string-match "\\.$" ad) ;larsi@ifi.uio.
4979 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4980 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
4982 "Denied posting -- the From looks strange: \"%s\"." from)
4984 ((let ((addresses (rfc822-addresses from)))
4985 (while (and addresses
4986 (not (eq (string-to-char (car addresses)) ?\()))
4987 (setq addresses (cdr addresses)))
4990 "Denied posting -- bad From address: \"%s\"." from)
4993 ;; Check the Reply-To header.
4994 (message-check 'reply-to
4995 (let* ((case-fold-search t)
4996 (reply-to (message-fetch-field "reply-to"))
5001 ((string-match "," reply-to)
5003 (format "Multiple Reply-To addresses: \"%s\". Really post? "
5005 ((or (not (string-match
5007 (setq ad (nth 1 (std11-extract-address-components
5008 reply-to))))) ;larsi@ifi
5009 (string-match "\\.\\." ad) ;larsi@ifi..uio
5010 (string-match "@\\." ad) ;larsi@.ifi.uio
5011 (string-match "\\.$" ad) ;larsi@ifi.uio.
5012 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
5013 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
5016 "The Reply-To looks strange: \"%s\". Really post? "
5020 (defun message-check-news-body-syntax ()
5022 ;; Check for long lines.
5023 (message-check 'long-lines
5024 (goto-char (point-min))
5026 (concat "^" (regexp-quote mail-header-separator) "$"))
5030 mime-edit-tag-regexp)
5033 (< (- (point) p) 80)))
5034 (zerop (forward-line 1))))
5038 "You have lines longer than 79 characters. Really post? ")))
5039 ;; Check whether the article is empty.
5040 (message-check 'empty
5041 (goto-char (point-min))
5043 (concat "^" (regexp-quote mail-header-separator) "$"))
5046 (goto-char (point-max))
5047 (re-search-backward message-signature-separator nil t)
5049 (or (re-search-backward "[^ \n\t]" b t)
5050 (if (message-gnksa-enable-p 'empty-article)
5051 (y-or-n-p "Empty article. Really post? ")
5052 (message "Denied posting -- Empty article.")
5054 ;; Check for control characters.
5055 (message-check 'control-chars
5056 (if (re-search-forward
5057 (string-as-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
5060 "The article contains control characters. Really post? ")
5062 ;; Check 8bit characters.
5063 (message-check '8bit
5064 (message-check-8bit))
5065 ;; Check excessive size.
5066 (message-check 'size
5067 (if (> (buffer-size) 60000)
5069 (format "The article is %d octets long. Really post? "
5072 ;; Check whether any new text has been added.
5073 (message-check 'new-text
5075 (not message-checksum)
5076 (not (eq (message-checksum) message-checksum))
5077 (if (message-gnksa-enable-p 'quoted-text-only)
5079 "It looks like no new text has been added. Really post? ")
5080 (message "Denied posting -- no new text has been added.")
5082 ;; Check the length of the signature.
5083 (message-check 'signature
5084 (goto-char (point-max))
5085 (if (> (count-lines (point) (point-max)) 5)
5088 "Your .sig is %d lines; it should be max 4. Really post? "
5089 (1- (count-lines (point) (point-max)))))
5091 ;; Ensure that text follows last quoted portion.
5092 (message-check 'quoting-style
5093 (goto-char (point-max))
5094 (let ((no-problem t))
5095 (when (search-backward-regexp "^>[^\n]*\n" nil t)
5096 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
5099 (if (message-gnksa-enable-p 'quoted-text-only)
5100 (y-or-n-p "Your text should follow quoted text. Really post? ")
5102 (goto-char (point-min))
5104 (concat "^" (regexp-quote mail-header-separator) "$"))
5105 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
5106 (y-or-n-p "Your text should follow quoted text. Really post? ")
5107 (message "Denied posting -- only quoted text.")
5110 (defun message-check-mail-syntax ()
5111 "Check the syntax of the message."
5116 ;; We narrow to the headers and check them first.
5119 (message-narrow-to-headers)
5120 (message-check-mail-header-syntax)))
5123 (set-buffer message-edit-buffer)
5124 (message-check-mail-body-syntax))))))
5126 (defun message-check-mail-header-syntax ()
5129 (defun message-check-mail-body-syntax ()
5131 ;; Check 8bit characters.
5132 (message-check '8bit
5133 (message-check-8bit)
5136 (defun message-check-8bit ()
5137 "Check the article contains 8bit characters."
5139 (set-buffer message-encoding-buffer)
5140 (message-narrow-to-headers)
5141 (let* ((case-fold-search t)
5142 (field-value (message-fetch-field "content-transfer-encoding")))
5143 (if (and field-value
5144 (member (downcase field-value) message-8bit-encoding-list))
5147 (set-buffer (get-buffer-create " message syntax"))
5149 (goto-char (point-min))
5150 (set-buffer-multibyte nil)
5151 (insert-buffer-substring message-encoding-buffer)
5152 (goto-char (point-min))
5153 (if (re-search-forward "[^\x00-\x7f]" nil t)
5155 "The article contains 8bit characters. Really post? ")
5158 (defun message-checksum ()
5159 "Return a \"checksum\" for the current buffer."
5162 (goto-char (point-min))
5164 (concat "^" (regexp-quote mail-header-separator) "$"))
5166 (when (not (looking-at "[ \t\n]"))
5167 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
5172 (defun message-do-fcc ()
5173 "Process Fcc headers in the current buffer."
5174 (let ((case-fold-search t)
5175 (coding-system-for-write 'raw-text)
5177 (mml-externalize-attachments message-fcc-externalize-attachments))
5180 (message-narrow-to-headers)
5181 (setq file (message-fetch-field "fcc" t)))
5183 (set-buffer (get-buffer-create " *message temp*"))
5185 (insert-buffer-substring message-encoding-buffer)
5187 (message-narrow-to-headers)
5188 (while (setq file (message-fetch-field "fcc"))
5190 (message-remove-header "fcc" nil t)))
5191 (goto-char (point-min))
5192 (when (re-search-forward
5193 (concat "^" (regexp-quote mail-header-separator) "$")
5195 (replace-match "" t t))
5196 ;; Process FCC operations.
5198 (setq file (pop list))
5199 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
5200 ;; Pipe the article to the program in question.
5201 (call-process-region (point-min) (point-max) shell-file-name
5202 nil nil nil shell-command-switch
5203 (match-string 1 file))
5204 ;; Save the article.
5205 (setq file (expand-file-name file))
5206 (unless (file-exists-p (file-name-directory file))
5207 (make-directory (file-name-directory file) t))
5208 (if (and message-fcc-handler-function
5209 (not (eq message-fcc-handler-function 'rmail-output)))
5210 (funcall message-fcc-handler-function file)
5211 (if (and (file-readable-p file) (mail-file-babyl-p file))
5212 (rmail-output file 1 nil t)
5213 (let ((mail-use-rfc822 t))
5214 (rmail-output file 1 t t))))))
5215 (kill-buffer (current-buffer))))))
5217 (defun message-output (filename)
5218 "Append this article to Unix/babyl mail file FILENAME."
5219 (if (and (file-readable-p filename)
5220 (mail-file-babyl-p filename))
5221 (gnus-output-to-rmail filename t)
5222 (gnus-output-to-mail filename t)))
5224 (defun message-cleanup-headers ()
5225 "Do various automatic cleanups of the headers."
5226 ;; Remove empty lines in the header.
5228 (message-narrow-to-headers)
5229 ;; Remove blank lines.
5230 (while (re-search-forward "^[ \t]*\n" nil t)
5231 (replace-match "" t t))
5233 ;; Correct Newsgroups and Followup-To headers: Change sequence of
5234 ;; spaces to comma and eliminate spaces around commas. Eliminate
5235 ;; embedded line breaks.
5236 (goto-char (point-min))
5237 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
5241 (if (re-search-forward "^[^ \t]" nil t)
5245 (goto-char (point-min))
5246 (while (re-search-forward "\n[ \t]+" nil t)
5247 (replace-match " " t t)) ;No line breaks (too confusing)
5248 (goto-char (point-min))
5249 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
5250 (replace-match "," t t))
5251 (goto-char (point-min))
5252 ;; Remove trailing commas.
5253 (when (re-search-forward ",+$" nil t)
5254 (replace-match "" t t))))))
5256 (defun message-make-date (&optional now)
5257 "Make a valid data header.
5258 If NOW, use that time instead."
5259 (let ((system-time-locale "C"))
5260 (format-time-string "%a, %d %b %Y %T %z" now)))
5262 (defun message-make-followup-subject (subject)
5263 "Make a followup Subject."
5265 ((and (eq message-use-subject-re 'guess)
5266 (string-match message-subject-encoded-re-regexp subject))
5268 (message-use-subject-re
5269 (concat "Re: " (message-strip-subject-re subject)))
5272 (defun message-make-message-id ()
5273 "Make a unique Message-ID."
5274 (concat "<" (message-unique-id)
5275 (let ((psubject (save-excursion (message-fetch-field "subject")))
5277 (save-excursion (message-fetch-field "supersedes"))))
5279 (and message-reply-headers
5280 (mail-header-references message-reply-headers)
5281 (mail-header-subject message-reply-headers)
5284 (message-strip-subject-re
5285 (mail-header-subject message-reply-headers))
5286 (message-strip-subject-re psubject))))
5288 (string-match "_-_@" psupersedes)))
5290 "@" (message-make-fqdn) ">"))
5292 (defvar message-unique-id-char nil)
5294 ;; If you ever change this function, make sure the new version
5295 ;; cannot generate IDs that the old version could.
5296 ;; You might for example insert a "." somewhere (not next to another dot
5297 ;; or string boundary), or modify the "fsf" string.
5298 (defun message-unique-id ()
5299 ;; Don't use microseconds from (current-time), they may be unsupported.
5300 ;; Instead we use this randomly inited counter.
5301 (setq message-unique-id-char
5302 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
5303 ;; (current-time) returns 16-bit ints,
5304 ;; and 2^16*25 just fits into 4 digits i base 36.
5306 (let ((tm (current-time)))
5308 (if (memq system-type '(ms-dos emx vax-vms))
5309 (let ((user (downcase (user-login-name))))
5310 (while (string-match "[^a-z0-9_]" user)
5311 (aset user (match-beginning 0) ?_))
5313 (message-number-base36 (user-uid) -1))
5314 (message-number-base36 (+ (car tm)
5315 (lsh (% message-unique-id-char 25) 16)) 4)
5316 (message-number-base36 (+ (nth 1 tm)
5317 (lsh (/ message-unique-id-char 25) 16)) 4)
5318 ;; Append a given name, because while the generated ID is unique
5319 ;; to this newsreader, other newsreaders might otherwise generate
5320 ;; the same ID via another algorithm.
5323 (defun message-number-base36 (num len)
5328 (concat (message-number-base36 (/ num 36) (1- len))
5329 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
5332 (defun message-make-organization ()
5333 "Make an Organization header."
5334 (let* ((organization
5335 (when message-user-organization
5336 (if (functionp message-user-organization)
5337 (funcall message-user-organization)
5338 message-user-organization))))
5340 (set-buffer-multibyte t)
5341 (cond ((stringp organization)
5342 (insert organization))
5343 ((and (eq t organization)
5344 message-user-organization-file
5345 (file-exists-p message-user-organization-file))
5346 (insert-file-contents message-user-organization-file)))
5347 (goto-char (point-min))
5348 (while (re-search-forward "[\t\n]+" nil t)
5349 (replace-match "" t t))
5350 (unless (zerop (buffer-size))
5353 (defun message-make-lines ()
5354 "Count the number of lines and return numeric string."
5359 (int-to-string (count-lines (point) (point-max))))))
5361 (defun message-make-references ()
5362 "Return the References header for this message."
5363 (when message-reply-headers
5364 (let ((message-id (mail-header-message-id message-reply-headers))
5365 (references (mail-header-references message-reply-headers))
5367 (if (or references message-id)
5368 (concat (or references "") (and references " ")
5372 (defun message-make-in-reply-to ()
5373 "Return the In-Reply-To header for this message."
5374 (when message-reply-headers
5375 (let ((from (mail-header-from message-reply-headers))
5376 (date (mail-header-date message-reply-headers))
5377 (msg-id (mail-header-message-id message-reply-headers)))
5379 (let ((name (std11-extract-address-components from)))
5380 (concat msg-id (if msg-id " (")
5384 (if (or (not date) (string= date ""))
5385 "(unknown date)" date)
5386 "\"" (if msg-id ")")))))))
5388 (defun message-make-distribution ()
5389 "Make a Distribution header."
5390 (let ((orig-distribution (message-fetch-reply-field "distribution")))
5391 (cond ((functionp message-distribution-function)
5392 (funcall message-distribution-function))
5393 (t orig-distribution))))
5395 (defun message-make-expires ()
5396 "Return an Expires header based on `message-expires'."
5397 (let ((current (current-time))
5398 (future (* 1.0 message-expires 60 60 24)))
5399 ;; Add the future to current.
5400 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
5401 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
5402 (message-make-date current)))
5404 (defun message-make-path ()
5406 (let ((login-name (user-login-name)))
5407 (cond ((null message-user-path)
5408 (concat (system-name) "!" login-name))
5409 ((stringp message-user-path)
5410 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
5411 (concat message-user-path "!" login-name))
5414 (defun message-make-from ()
5415 "Make a From header."
5416 (let* ((style message-from-style)
5417 (login (message-make-address))
5419 (or (and (boundp 'user-full-name)
5422 (when (string= fullname "&")
5423 (setq fullname (user-login-name)))
5425 (set-buffer-multibyte t)
5428 (equal fullname ""))
5430 ((or (eq style 'angles)
5431 (and (not (eq style 'parens))
5432 ;; Use angles if no quoting is needed, or if parens would
5433 ;; need quoting too.
5434 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
5435 (let ((tmp (concat fullname nil)))
5436 (while (string-match "([^()]*)" tmp)
5437 (aset tmp (match-beginning 0) ?-)
5438 (aset tmp (1- (match-end 0)) ?-))
5439 (string-match "[\\()]" tmp)))))
5441 (goto-char (point-min))
5442 ;; Look for a character that cannot appear unquoted
5443 ;; according to RFC 822.
5444 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
5445 ;; Quote fullname, escaping specials.
5446 (goto-char (point-min))
5448 (while (re-search-forward "[\"\\]" nil 1)
5449 (replace-match "\\\\\\&" t))
5451 (insert " <" login ">"))
5452 (t ; 'parens or default
5454 (let ((fullname-start (point)))
5456 (goto-char fullname-start)
5457 ;; RFC 822 says \ and nonmatching parentheses
5458 ;; must be escaped in comments.
5459 ;; Escape every instance of ()\ ...
5460 (while (re-search-forward "[()\\]" nil 1)
5461 (replace-match "\\\\\\&" t))
5462 ;; ... then undo escaping of matching parentheses,
5463 ;; including matching nested parentheses.
5464 (goto-char fullname-start)
5465 (while (re-search-forward
5466 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
5468 (replace-match "\\1(\\3)" t)
5469 (goto-char fullname-start)))
5473 (defun message-make-sender ()
5474 "Return the \"real\" user address.
5475 This function tries to ignore all user modifications, and
5476 give as trustworthy answer as possible."
5477 (concat (user-login-name) "@" (system-name)))
5479 (defun message-make-address ()
5480 "Make the address of the user."
5481 (or (message-user-mail-address)
5482 (concat (user-login-name) "@" (message-make-domain))))
5484 (defun message-user-mail-address ()
5485 "Return the pertinent part of `user-mail-address'."
5486 (when (and user-mail-address
5487 (string-match "@.*\\." user-mail-address))
5488 (if (string-match " " user-mail-address)
5489 (nth 1 (std11-extract-address-components user-mail-address))
5490 user-mail-address)))
5492 (defun message-sendmail-envelope-from ()
5493 "Return the envelope from."
5494 (cond ((eq message-sendmail-envelope-from 'header)
5495 (nth 1 (std11-extract-address-components
5496 (message-fetch-field "from"))))
5497 ((stringp message-sendmail-envelope-from)
5498 message-sendmail-envelope-from)
5500 (message-make-address))))
5502 (defun message-make-fqdn ()
5503 "Return user's fully qualified domain name."
5504 (let* ((system-name (system-name))
5505 (user-mail (message-user-mail-address))
5508 (string-match "@\\(.*\\)\\'" user-mail))
5509 (match-string 1 user-mail)))
5510 (case-fold-search t))
5512 ((and message-user-fqdn
5513 (stringp message-user-fqdn)
5514 (string-match message-valid-fqdn-regexp message-user-fqdn)
5515 (not (string-match message-bogus-system-names message-user-fqdn)))
5517 ;; `message-user-fqdn' seems to be valid
5518 ((and (string-match message-valid-fqdn-regexp system-name)
5519 (not (string-match message-bogus-system-names system-name)))
5520 ;; `system-name' returned the right result.
5522 ;; Try `mail-host-address'.
5523 ((and (boundp 'mail-host-address)
5524 (stringp mail-host-address)
5525 (string-match message-valid-fqdn-regexp mail-host-address)
5526 (not (string-match message-bogus-system-names mail-host-address)))
5528 ;; We try `user-mail-address' as a backup.
5530 (stringp user-domain)
5531 (string-match message-valid-fqdn-regexp user-domain)
5532 (not (string-match message-bogus-system-names user-domain)))
5534 ;; Default to this bogus thing.
5537 ".i-did-not-set--mail-host-address--so-tickle-me")))))
5539 (defun message-make-host-name ()
5540 "Return the name of the host."
5541 (let ((fqdn (message-make-fqdn)))
5542 (string-match "^[^.]+\\." fqdn)
5543 (substring fqdn 0 (1- (match-end 0)))))
5545 (defun message-make-domain ()
5546 "Return the domain name."
5547 (or mail-host-address
5548 (message-make-fqdn)))
5550 (defun message-to-list-only ()
5551 "Send a message to the list only.
5552 Remove all addresses but the list address from To and Cc headers."
5554 (let ((listaddr (message-make-mail-followup-to t)))
5557 (message-remove-header "to")
5558 (message-remove-header "cc")
5559 (message-position-on-field "To" "X-Draft-From")
5560 (insert listaddr)))))
5562 (defun message-make-mail-followup-to (&optional only-show-subscribed)
5563 "Return the Mail-Followup-To header.
5564 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5565 subscribed address (and not the additional To and Cc header contents)."
5566 (let* ((case-fold-search t)
5567 (to (message-fetch-field "To"))
5568 (cc (message-fetch-field "cc"))
5569 (msg-recipients (concat to (and to cc ", ") cc))
5571 (mapcar 'mail-strip-quoted-names
5572 (message-tokenize-header msg-recipients)))
5574 (if message-subscribed-address-file
5575 (let (begin end item re)
5578 (insert-file-contents message-subscribed-address-file)
5580 (setq begin (point))
5583 (if (bolp) (setq end (1- end)))
5584 (setq item (regexp-quote (buffer-substring begin end)))
5585 (if re (setq re (concat re "\\|" item))
5586 (setq re (concat "\\`\\(" item))))
5587 (and re (list (concat re "\\)\\'"))))))))
5588 (mft-regexps (apply 'append message-subscribed-regexps
5589 (mapcar 'regexp-quote
5590 message-subscribed-addresses)
5593 message-subscribed-address-functions))))
5595 (let ((subscribed-lists nil)
5597 (loop for recipient in recipients
5598 when (loop for regexp in mft-regexps
5599 when (string-match regexp recipient) return t)
5602 (if only-show-subscribed
5604 msg-recipients))))))
5606 ;; Dummy to avoid byte-compile warning.
5607 (defvar mule-version)
5608 (defvar emacs-beta-version)
5609 (defvar xemacs-codename)
5610 (defvar gnus-inviolable-extended-version)
5612 (defun message-make-user-agent ()
5613 "Return user-agent info if the value `message-user-agent' is non-nil. If the
5614 \"User-Agent\" field has already exist, remove it."
5615 (when message-user-agent
5617 (goto-char (point-min))
5618 (let ((case-fold-search t))
5619 (when (re-search-forward "^User-Agent:[\t ]*" nil t)
5620 (delete-region (match-beginning 0) (1+ (std11-field-end)))))))
5623 (defun message-idna-to-ascii-rhs-1 (header)
5624 "Interactively potentially IDNA encode domain names in HEADER."
5625 (let ((field (message-fetch-field header))
5628 (dolist (address (mail-header-parse-addresses field))
5629 (setq address (car address)
5630 rhs (downcase (or (cadr (split-string address "@")) ""))
5631 ace (downcase (idna-to-ascii rhs)))
5632 (when (and (not (equal rhs ace))
5633 (or (not (eq message-use-idna 'ask))
5634 (y-or-n-p (format "Replace %s with %s? " rhs ace))))
5635 (goto-char (point-min))
5636 (while (re-search-forward (concat "^" header ":") nil t)
5637 (message-narrow-to-field)
5638 (while (search-forward (concat "@" rhs) nil t)
5639 (replace-match (concat "@" ace) t t))
5640 (goto-char (point-max))
5643 (defun message-idna-to-ascii-rhs ()
5644 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
5645 See `message-idna-encode'."
5647 (when message-use-idna
5650 (message-narrow-to-head)
5651 (message-idna-to-ascii-rhs-1 "From")
5652 (message-idna-to-ascii-rhs-1 "To")
5653 (message-idna-to-ascii-rhs-1 "Reply-To")
5654 (message-idna-to-ascii-rhs-1 "Cc")))))
5656 (defun message-generate-headers (headers)
5657 "Prepare article HEADERS.
5658 Headers already prepared in the buffer are not modified."
5659 (setq headers (append headers message-required-headers))
5661 (message-narrow-to-headers)
5662 (let* ((Date (message-make-date))
5663 (Message-ID (message-make-message-id))
5664 (Organization (message-make-organization))
5665 (From (message-make-from))
5666 (Path (message-make-path))
5669 (In-Reply-To (message-make-in-reply-to))
5670 (References (message-make-references))
5672 (Distribution (message-make-distribution))
5673 (Lines (message-make-lines))
5674 (User-Agent (message-make-user-agent))
5675 (Expires (message-make-expires))
5676 (case-fold-search t)
5678 header value elem header-string)
5679 ;; First we remove any old generated headers.
5680 (let ((headers message-deletable-headers))
5681 (unless (buffer-modified-p)
5682 (setq headers (delq 'Message-ID (copy-sequence headers))))
5684 (goto-char (point-min))
5685 (and (re-search-forward
5686 (concat "^" (symbol-name (car headers)) ": *") nil t)
5687 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
5688 (message-delete-line))
5690 ;; Go through all the required headers and see if they are in the
5691 ;; articles already. If they are not, or are empty, they are
5692 ;; inserted automatically - except for Subject, Newsgroups and
5695 (goto-char (point-min))
5696 (setq elem (pop headers))
5698 (if (eq (car elem) 'optional)
5699 (setq header (cdr elem)
5701 (setq header (car elem)))
5703 (setq header-string (if (stringp header)
5705 (symbol-name header)))
5706 (when (or (not (re-search-forward
5708 (regexp-quote (downcase header-string))
5712 ;; The header was found. We insert a space after the
5713 ;; colon, if there is none.
5714 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
5715 ;; Find out whether the header is empty.
5716 (looking-at "[ \t]*\n[^ \t]")))
5717 ;; So we find out what value we should insert.
5721 (eq (car elem) 'optional)
5722 (not (member header-string message-inserted-headers)))
5723 ;; This is an optional header. If the cdr of this
5724 ;; is something that is nil, then we do not insert
5726 (setq header (cdr elem))
5727 (or (and (functionp (cdr elem))
5728 (funcall (cdr elem)))
5729 (and (boundp (cdr elem))
5730 (symbol-value (cdr elem)))))
5732 ;; The element is a cons. Either the cdr is a
5733 ;; string to be inserted verbatim, or it is a
5734 ;; function, and we insert the value returned from
5736 (or (and (stringp (cdr elem))
5738 (and (functionp (cdr elem))
5739 (funcall (cdr elem)))))
5740 ((and (boundp header)
5741 (symbol-value header))
5742 ;; The element is a symbol. We insert the value
5743 ;; of this symbol, if any.
5744 (symbol-value header))
5745 ((not (message-check-element header))
5746 ;; We couldn't generate a value for this header,
5747 ;; so we just ask the user.
5748 (read-from-minibuffer
5749 (format "Empty header for %s; enter value: " header)))))
5750 ;; Finally insert the header.
5752 (not (equal value "")))
5756 ;; This header didn't exist, so we insert it.
5757 (goto-char (point-max))
5759 (cdr (assq header message-header-format-alist))))
5761 (funcall formatter header value)
5762 (insert header-string ": " value))
5763 (goto-char (message-fill-field))
5764 ;; We check whether the value was ended by a
5765 ;; newline. If not, we insert one.
5769 ;; The value of this header was empty, so we clear
5770 ;; totally and insert the new value.
5771 (delete-region (point) (point-at-eol))
5772 ;; If the header is optional, and the header was
5773 ;; empty, we can't insert it anyway.
5775 (push header-string message-inserted-headers)
5777 (message-fill-field)))
5778 ;; Add the deletable property to the headers that require it.
5779 (and (memq header message-deletable-headers)
5780 (progn (beginning-of-line) (looking-at "[^:]+: "))
5781 (add-text-properties
5782 (point) (match-end 0)
5783 '(message-deletable t face italic) (current-buffer)))))))
5784 ;; Insert new Sender if the From is strange.
5785 (let ((from (message-fetch-field "from"))
5786 (sender (message-fetch-field "sender"))
5787 (secure-sender (message-make-sender)))
5789 (not (message-check-element 'sender))
5792 (cadr (std11-extract-address-components from)))
5793 (downcase secure-sender)))
5798 (cadr (std11-extract-address-components sender)))
5799 (downcase secure-sender)))))
5800 (goto-char (point-min))
5801 ;; Rename any old Sender headers to Original-Sender.
5802 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
5804 (insert "Original-")
5805 (beginning-of-line))
5806 (when (or (message-news-p)
5807 (string-match "@.+\\.." secure-sender))
5808 (insert "Sender: " secure-sender "\n"))))
5810 (message-idna-to-ascii-rhs))))
5812 (defun message-insert-courtesy-copy ()
5813 "Insert a courtesy message in mail copies of combined messages."
5817 (message-narrow-to-headers)
5818 (when (setq newsgroups (message-fetch-field "newsgroups"))
5819 (goto-char (point-max))
5820 (insert "Posted-To: " newsgroups "\n")))
5822 (when message-courtesy-message
5824 ((string-match "%s" message-courtesy-message)
5825 (insert (format message-courtesy-message newsgroups)))
5827 (insert message-courtesy-message)))))))
5830 ;;; Setting up a message buffer
5833 (defun message-skip-to-next-address ()
5834 (let ((end (save-excursion
5835 (message-next-header)
5838 (when (looking-at ",")
5840 (while (and (not (= (point) end))
5841 (or (not (eq char ?,))
5843 (skip-chars-forward "^,\"" (point-max))
5844 (when (eq (setq char (following-char)) ?\")
5845 (setq quoted (not quoted)))
5846 (unless (= (point) end)
5848 (skip-chars-forward " \t\n")))
5850 (defun message-fill-address (header value)
5851 (insert (capitalize (symbol-name header))
5853 (if (consp value) (car value) value)
5855 (message-fill-field-address))
5857 (defun message-fill-references (header value)
5858 (insert (capitalize (symbol-name header))
5860 (std11-fill-msg-id-list-string
5861 (if (consp value) (car value) value))))
5863 (defun message-split-line ()
5864 "Split current line, moving portion beyond point vertically down.
5865 If the current line has `message-yank-prefix', insert it on the new line."
5868 (split-line message-yank-prefix) ;; Emacs 22.1+ supports arg.
5872 (defun message-insert-header (header value)
5873 (insert (capitalize (symbol-name header))
5875 (if (consp value) (car value) value)))
5877 (defun message-field-name ()
5879 (goto-char (point-min))
5880 (when (looking-at "\\([^:]+\\):")
5881 (intern (capitalize (match-string 1))))))
5883 (defun message-fill-field ()
5886 (message-narrow-to-field)
5887 (let ((field-name (message-field-name)))
5888 (funcall (or (cadr (assq field-name message-field-fillers))
5889 'message-fill-field-general)))
5892 (defun message-fill-field-address ()
5894 (message-skip-to-next-address)
5896 (if (and (> (current-column) 78)
5902 (setq last (1+ (point))))
5903 (setq last (1+ (point)))))))
5905 (defun message-fill-field-general ()
5906 (let ((begin (point))
5909 (while (and (search-forward "\n" nil t)
5911 (replace-match " " t t))
5912 (fill-region-as-paragraph begin (point-max))
5913 ;; Tapdance around looong Message-IDs.
5915 (when (looking-at "[ \t]*$")
5916 (message-delete-line))
5918 (search-forward ":" nil t)
5919 (when (looking-at "\n[ \t]+")
5920 (replace-match " " t t))
5921 (goto-char (point-max))))
5923 (defun message-shorten-1 (list cut surplus)
5924 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
5925 (setcdr (nthcdr (- cut 2) list)
5926 (nthcdr (+ (- cut 2) surplus 1) list)))
5928 (defun message-shorten-references (header references)
5929 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
5930 When sending via news, also check that the REFERENCES are less
5931 than 988 characters long, and if they are not, trim them until
5939 (goto-char (point-min))
5940 ;; Cons a list of valid references.
5941 (while (re-search-forward "<[^>]+>" nil t)
5942 (push (match-string 0) refs))
5943 (setq refs (nreverse refs)
5944 count (length refs)))
5946 ;; If the list has more than MAXCOUNT elements, trim it by
5947 ;; removing the CUTth element and the required number of
5948 ;; elements that follow.
5949 (when (> count maxcount)
5950 (let ((surplus (- count maxcount)))
5951 (message-shorten-1 refs cut surplus)
5952 (decf count surplus)))
5954 ;; When sending via news, make sure the total folded length will
5955 ;; be less than 998 characters. This is to cater to broken INN
5956 ;; 2.3 which counts the total number of characters in a header
5957 ;; rather than the physical line length of each line, as it should.
5959 ;; This hack should be removed when it's believed than INN 2.3 is
5960 ;; no longer widely used.
5962 ;; At this point the headers have not been generated, thus we use
5963 ;; message-this-is-news directly.
5964 (when message-this-is-news
5967 (message-insert-header
5968 header (mapconcat #'identity refs " "))
5970 (message-shorten-1 refs cut 1)))
5971 ;; Finally, collect the references back into a string and insert
5972 ;; it into the buffer.
5973 (message-insert-header header (mapconcat #'identity refs " "))))
5975 (defun message-position-point ()
5976 "Move point to where the user probably wants to find it."
5977 (message-narrow-to-headers)
5979 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
5980 (search-backward ":" )
5983 (if (eq (char-after) ? )
5987 (goto-char (point-max))
5990 (unless (looking-at "$")
5994 (defcustom message-beginning-of-line t
5995 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
5996 goes to beginning of header values."
5998 :group 'message-buffers
5999 :link '(custom-manual "(message)Movement")
6002 (defun message-beginning-of-line (&optional n)
6003 "Move point to beginning of header value or to beginning of line.
6004 The prefix argument N is passed directly to `beginning-of-line'.
6006 This command is identical to `beginning-of-line' if point is
6007 outside the message header or if the option `message-beginning-of-line'
6010 If point is in the message header and on a (non-continued) header
6011 line, move point to the beginning of the header value or the beginning of line,
6012 whichever is closer. If point is already at beginning of line, move point to
6013 beginning of header value. Therefore, repeated calls will toggle point
6014 between beginning of field and beginning of line."
6016 (let ((zrs 'zmacs-region-stays))
6017 (when (and (interactive-p) (boundp zrs))
6019 (if (and message-beginning-of-line
6020 (message-point-in-header-p))
6021 (let* ((here (point))
6022 (bol (progn (beginning-of-line n) (point)))
6023 (eol (point-at-eol))
6024 (eoh (re-search-forward ": *" eol t)))
6026 (if (and eoh (or (< eoh here) (= bol here)))
6028 (beginning-of-line n)))
6030 (defun message-buffer-name (type &optional to group)
6031 "Return a new (unique) buffer name based on TYPE and TO."
6033 ;; Generate a new buffer name The Message Way.
6034 ((eq message-generate-new-buffers 'unique)
6035 (generate-new-buffer-name
6039 (or (car (std11-extract-address-components to))
6042 (if (and group (not (string= group ""))) (concat " on " group) "")
6044 ;; Check whether `message-generate-new-buffers' is a function,
6045 ;; and if so, call it.
6046 ((functionp message-generate-new-buffers)
6047 (funcall message-generate-new-buffers type to group))
6048 ((eq message-generate-new-buffers 'unsent)
6049 (generate-new-buffer-name
6050 (concat "*unsent " type
6053 (or (car (std11-extract-address-components to))
6056 (if (and group (not (string= group ""))) (concat " on " group) "")
6058 ;; Use standard name.
6060 (format "*%s message*" type))))
6062 (defmacro message-pop-to-buffer-1 (buffer)
6064 (let (special-display-buffer-names
6065 special-display-regexps
6066 same-window-buffer-names
6067 same-window-regexps)
6068 (pop-to-buffer ,buffer))
6069 (pop-to-buffer ,buffer)))
6071 (defun message-pop-to-buffer (name)
6072 "Pop to buffer NAME, and warn if it already exists and is modified."
6073 (let ((buffer (get-buffer name))
6074 (pop-up-frames (and (static-if (featurep 'xemacs)
6075 (device-on-window-system-p)
6077 message-use-multi-frames)))
6079 (buffer-name buffer))
6081 (message-pop-to-buffer-1 buffer)
6082 (when (and (buffer-modified-p)
6084 "Message already being composed; erase? ")))
6085 (error "Message being composed")))
6086 (message-pop-to-buffer-1 name))
6090 (set (make-local-variable 'message-original-frame) (selected-frame)))))
6092 (defun message-do-send-housekeeping ()
6093 "Kill old message buffers."
6094 ;; We might have sent this buffer already. Delete it from the
6096 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
6097 (while (and message-max-buffers
6099 (>= (length message-buffer-list) message-max-buffers))
6100 ;; Kill the oldest buffer -- unless it has been changed.
6101 (let ((buffer (pop message-buffer-list)))
6102 (when (and (buffer-name buffer)
6103 (not (buffer-modified-p buffer)))
6104 (kill-buffer buffer))))
6105 ;; Rename the buffer.
6106 (if message-send-rename-function
6107 (funcall message-send-rename-function)
6108 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
6110 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
6112 (let ((name (match-string 2 (buffer-name)))
6114 (if (not (or (null name)
6115 (string-equal name "mail")
6116 (string-equal name "posting")))
6117 (setq name (concat "*sent " name "*"))
6118 (message-narrow-to-headers)
6119 (setq to (message-fetch-field "to"))
6120 (setq group (message-fetch-field "newsgroups"))
6124 (to (concat "*sent mail to "
6125 (or (car (std11-extract-address-components to))
6127 ((and group (not (string= group "")))
6128 (concat "*sent posting on " group "*"))
6129 (t "*sent mail*"))))
6130 (unless (string-equal name (buffer-name))
6131 (rename-buffer name t)))))
6132 ;; Push the current buffer onto the list.
6133 (when message-max-buffers
6134 (setq message-buffer-list
6135 (nconc message-buffer-list (list (current-buffer))))))
6137 (defun message-mail-user-agent ()
6139 ((not message-mail-user-agent) nil)
6140 ((eq message-mail-user-agent t) mail-user-agent)
6141 (t message-mail-user-agent))))
6142 (if (memq mua '(message-user-agent gnus-user-agent))
6146 (defun message-setup (headers &optional replybuffer actions switch-function)
6147 (let ((mua (message-mail-user-agent))
6148 subject to field yank-action)
6149 (if (not (and message-this-is-mail mua))
6150 (message-setup-1 headers replybuffer actions)
6152 (setq yank-action (list 'insert-buffer replybuffer)))
6153 (setq headers (copy-sequence headers))
6154 (setq field (assq 'Subject headers))
6156 (setq subject (cdr field))
6157 (setq headers (delq field headers)))
6158 (setq field (assq 'To headers))
6160 (setq to (cdr field))
6161 (setq headers (delq field headers)))
6162 (let ((mail-user-agent mua))
6163 (compose-mail to subject
6164 (mapcar (lambda (item)
6166 (format "%s" (car item))
6169 nil switch-function yank-action actions)))))
6171 (defun message-headers-to-generate (headers included-headers excluded-headers)
6172 "Return a list that includes all headers from HEADERS.
6173 If INCLUDED-HEADERS is a list, just include those headers. If if is
6174 t, include all headers. In any case, headers from EXCLUDED-HEADERS
6178 (dolist (header headers)
6179 (setq header-name (cond
6180 ((and (consp header)
6181 (eq (car header) 'optional))
6182 ;; On the form (optional . Header)
6185 ;; On the form (Header . function)
6190 (when (and (not (memq header-name excluded-headers))
6191 (or (eq included-headers t)
6192 (memq header-name included-headers)))
6193 (push header result)))
6196 (defun message-setup-1 (headers &optional replybuffer actions)
6197 (dolist (action actions)
6199 (add-to-list 'message-send-actions
6200 `(apply ',(car action) ',(cdr action)))))
6201 (setq message-reply-buffer
6202 (or (message-get-parameter 'reply-buffer)
6204 (goto-char (point-min))
6205 ;; Insert all the headers.
6208 (alist message-header-format-alist))
6210 (unless (assq (caar h) message-header-format-alist)
6211 (push (list (caar h)) alist))
6215 (delete-region (point) (progn (forward-line -1) (point)))
6216 (when message-default-headers
6217 (insert message-default-headers)
6218 (or (bolp) (insert ?\n)))
6219 (insert mail-header-separator "\n")
6221 (when (message-news-p)
6222 (when message-default-news-headers
6223 (insert message-default-news-headers)
6224 (or (bolp) (insert ?\n)))
6225 (when message-generate-headers-first
6226 (message-generate-headers
6227 (message-headers-to-generate
6228 (append message-required-news-headers
6229 message-required-headers)
6230 message-generate-headers-first
6231 '(Lines Subject)))))
6232 (when (message-mail-p)
6233 (when message-default-mail-headers
6234 (insert message-default-mail-headers)
6235 (or (bolp) (insert ?\n)))
6236 (when message-generate-headers-first
6237 (message-generate-headers
6238 (message-headers-to-generate
6239 (append message-required-mail-headers
6240 message-required-headers)
6241 message-generate-headers-first
6242 '(Lines Subject)))))
6243 (run-hooks 'message-signature-setup-hook)
6244 (message-insert-signature)
6246 (message-narrow-to-headers)
6247 (run-hooks 'message-header-setup-hook))
6248 (set-buffer-modified-p nil)
6249 (setq buffer-undo-list nil)
6250 (when message-generate-hashcash
6251 ;; Generate hashcash headers for recipients already known
6252 (mail-add-payment-async))
6253 (run-hooks 'message-setup-hook)
6254 ;; Do this last to give it precedence over posting styles, etc.
6255 (when (message-mail-p)
6257 (message-narrow-to-headers)
6258 (if message-alternative-emails
6259 (message-use-alternative-email-as-from))))
6260 (message-position-point)
6263 (defun message-set-auto-save-file-name ()
6264 "Associate the message buffer with a file in the drafts directory."
6265 (when message-auto-save-directory
6266 (unless (file-directory-p
6267 (directory-file-name message-auto-save-directory))
6268 (make-directory message-auto-save-directory t))
6270 (setq message-draft-article
6271 (nndraft-request-associate-buffer "drafts"))
6272 (setq buffer-file-name (expand-file-name
6273 (if (memq system-type
6274 '(ms-dos ms-windows windows-nt
6275 cygwin cygwin32 win32 w32
6279 message-auto-save-directory))
6280 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
6281 (clear-visited-file-modtime)
6282 (setq buffer-file-coding-system message-draft-coding-system)))
6284 (defun message-disassociate-draft ()
6285 "Disassociate the message buffer from the drafts directory."
6286 (when message-draft-article
6287 (nndraft-request-expire-articles
6288 (list message-draft-article) "drafts" nil t)))
6290 (defun message-insert-headers ()
6291 "Generate the headers for the article."
6295 (message-narrow-to-headers)
6296 (when (message-news-p)
6297 (message-generate-headers
6300 (copy-sequence message-required-news-headers)))))
6301 (when (message-mail-p)
6302 (message-generate-headers
6305 (copy-sequence message-required-mail-headers))))))))
6310 ;;; Commands for interfacing with message
6314 (defun message-mail (&optional to subject
6315 other-headers continue switch-function
6316 yank-action send-actions)
6317 "Start editing a mail message to be sent.
6318 OTHER-HEADERS is an alist of header/value pairs."
6320 (let ((message-this-is-mail t) replybuffer)
6321 (unless (message-mail-user-agent)
6322 (message-pop-to-buffer (message-buffer-name "mail" to)))
6323 ;; FIXME: message-mail should do something if YANK-ACTION is not
6325 (and (consp yank-action) (eq (car yank-action) 'insert-buffer)
6326 (setq replybuffer (nth 1 yank-action)))
6329 `((To . ,(or to "")) (Subject . ,(or subject "")))
6330 (when other-headers other-headers))
6331 replybuffer send-actions)
6332 ;; FIXME: Should return nil if failure.
6336 (defun message-news (&optional newsgroups subject)
6337 "Start editing a news article to be sent."
6339 (let ((message-this-is-news t))
6340 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
6341 (message-setup `((Newsgroups . ,(or newsgroups ""))
6342 (Subject . ,(or subject ""))))))
6344 (defun message-get-reply-headers (wide &optional to-address address-headers)
6345 (let (follow-to mct never-mct to cc author mft recipients extra)
6346 ;; Find all relevant headers we need.
6348 (message-narrow-to-headers-or-head)
6349 (let ((mrt (when message-use-mail-reply-to
6350 (message-fetch-field "mail-reply-to")))
6351 (reply-to (message-fetch-field "reply-to")))
6352 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
6353 ;; message-header-synonyms.
6354 (setq to (or (message-fetch-field "to")
6355 (and (loop for synonym in message-header-synonyms
6356 when (memq 'Original-To synonym)
6358 (message-fetch-field "original-to")))
6359 cc (message-fetch-field "cc")
6360 extra (when message-extra-wide-headers
6361 (mapconcat 'identity
6362 (mapcar 'message-fetch-field
6363 message-extra-wide-headers)
6365 mct (when message-use-mail-copies-to
6366 (message-fetch-field "mail-copies-to"))
6369 (message-fetch-field "from")
6371 mft (when (and (not (or to-address mrt reply-to))
6372 message-use-mail-followup-to)
6373 (message-fetch-field "mail-followup-to")))))
6376 ;; Handle special values of Mail-Copies-To.
6378 (cond ((or (equal (downcase mct) "never")
6379 (equal (downcase mct) "nobody"))
6380 (when (or (not (eq message-use-mail-copies-to 'ask))
6382 (concat "Obey Mail-Copies-To: never? ") t "\
6383 You should normally obey the Mail-Copies-To: header.
6385 `Mail-Copies-To: " mct "'
6386 directs you not to send your response to the author."))
6389 ((or (equal (downcase mct) "always")
6390 (equal (downcase mct) "poster"))
6391 (if (or (not (eq message-use-mail-copies-to 'ask))
6393 (concat "Obey Mail-Copies-To: always? ") t "\
6394 You should normally obey the Mail-Copies-To: header.
6396 `Mail-Copies-To: " mct "'
6397 sends a copy of your response to the author."))
6400 ((and (eq message-use-mail-copies-to 'ask)
6401 (not (message-y-or-n-p
6402 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
6403 You should normally obey the Mail-Copies-To: header.
6405 `Mail-Copies-To: " mct "'
6406 sends a copy of your response to " (if (string-match "," mct)
6407 "the specified addresses"
6408 "that address") ".")))
6411 ;; Build (textual) list of new recipient addresses.
6414 (setq recipients (concat ", " author)))
6416 (dolist (header address-headers)
6417 (let ((value (message-fetch-field header)))
6419 (setq recipients (concat recipients ", " value))))))
6421 (string-match "[^ \t,]" mft)
6422 (or (not (eq message-use-mail-followup-to 'ask))
6423 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
6424 You should normally obey the Mail-Followup-To: header. In this
6425 article, it has the value of
6429 which directs your response to " (if (string-match "," mft)
6430 "the specified addresses"
6431 "that address only") ".
6433 Most commonly, Mail-Followup-To is used by a mailing list poster to
6434 express that responses should be sent to just the list, and not the
6437 If a message is posted to several mailing lists, Mail-Followup-To may
6438 also be used to direct the following discussion to one list only,
6439 because discussions that are spread over several lists tend to be
6440 fragmented and very difficult to follow.
6442 Also, some source/announcement lists are not intended for discussion;
6443 responses here are directed to other addresses.
6445 You may customize the variable `message-use-mail-followup-to', if you
6446 want to get rid of this query permanently.")))
6447 (setq recipients (concat ", " mft)))
6449 (setq recipients (concat ", " to-address))
6450 ;; If the author explicitly asked for a copy, we don't deny it to them.
6451 (if mct (setq recipients (concat recipients ", " mct))))
6453 (setq recipients (if never-mct "" (concat ", " author)))
6454 (if to (setq recipients (concat recipients ", " to)))
6455 (if cc (setq recipients (concat recipients ", " cc)))
6456 (if extra (setq recipients (concat recipients ", " extra)))
6457 (if mct (setq recipients (concat recipients ", " mct)))))
6458 (if (>= (length recipients) 2)
6459 ;; Strip the leading ", ".
6460 (setq recipients (substring recipients 2)))
6461 ;; Squeeze whitespace.
6462 (while (string-match "[ \t][ \t]+" recipients)
6463 (setq recipients (replace-match " " t t recipients)))
6464 ;; Remove addresses that match `rmail-dont-reply-to-names'.
6465 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
6466 (setq recipients (rmail-dont-reply-to recipients)))
6467 ;; Perhaps "Mail-Copies-To: never" removed the only address?
6468 (if (string-equal recipients "")
6469 (setq recipients author))
6470 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
6474 (cons (downcase (mail-strip-quoted-names addr)) addr))
6475 (message-tokenize-header recipients)))
6476 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
6477 (let ((s recipients))
6479 (setq recipients (delq (assoc (car (pop s)) s) recipients))))
6481 ;; Remove hierarchical lists that are contained within each other,
6482 ;; if message-hierarchical-addresses is defined.
6483 (when message-hierarchical-addresses
6484 (let ((plain-addrs (mapcar 'car recipients))
6487 (setq subaddrs (assoc (car plain-addrs)
6488 message-hierarchical-addresses)
6489 plain-addrs (cdr plain-addrs))
6491 (setq subaddrs (cdr subaddrs))
6493 (setq recip (assoc (car subaddrs) recipients)
6494 subaddrs (cdr subaddrs))
6496 (setq recipients (delq recip recipients))))))))
6498 ;; Build the header alist. Allow the user to be asked whether
6499 ;; or not to reply to all recipients in a wide reply.
6500 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
6501 (when (and recipients
6502 (or (not message-wide-reply-confirm-recipients)
6503 (y-or-n-p "Reply to all recipients? ")))
6504 (setq recipients (mapconcat
6505 (lambda (addr) (cdr addr)) recipients ", "))
6506 (if (string-match "^ +" recipients)
6507 (setq recipients (substring recipients (match-end 0))))
6508 (push (cons 'Cc recipients) follow-to)))
6512 (defun message-reply (&optional to-address wide)
6513 "Start editing a reply to the article in the current buffer."
6515 (require 'gnus-sum) ; for gnus-list-identifiers
6516 (let ((cur (current-buffer))
6518 references message-id follow-to
6519 (inhibit-point-motion-hooks t)
6520 (message-this-is-mail t)
6521 gnus-warning in-reply-to)
6523 (message-narrow-to-head-1)
6524 ;; Allow customizations to have their say.
6526 ;; This is a regular reply.
6527 (when (functionp message-reply-to-function)
6529 (setq follow-to (funcall message-reply-to-function))))
6530 ;; This is a followup.
6531 (when (functionp message-wide-reply-to-function)
6534 (funcall message-wide-reply-to-function)))))
6535 (setq message-id (message-fetch-field "message-id" t)
6536 references (message-fetch-field "references")
6537 date (message-fetch-field "date")
6538 from (message-fetch-field "from")
6539 subject (or (message-fetch-field "subject") "none"))
6540 (when gnus-list-identifiers
6541 (setq subject (message-strip-list-identifiers subject)))
6542 (setq subject (message-make-followup-subject subject))
6543 (when message-subject-trailing-was-query
6544 (setq subject (message-strip-subject-trailing-was subject)))
6546 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6547 (string-match "<[^>]+>" gnus-warning))
6548 (setq message-id (match-string 0 gnus-warning)))
6551 (setq follow-to (message-get-reply-headers wide to-address)))
6553 ;; Get the references from "In-Reply-To" field if there were
6554 ;; no references and "In-Reply-To" field looks promising.
6556 (when (and (setq in-reply-to (message-fetch-field "in-reply-to"))
6557 (string-match "<[^>]+>" in-reply-to))
6558 (setq references (match-string 0 in-reply-to)))))
6560 (unless (message-mail-user-agent)
6561 (message-pop-to-buffer
6562 (message-buffer-name
6563 (if wide "wide reply" "reply") from
6564 (if wide to-address nil))))
6566 (setq message-reply-headers
6567 (make-full-mail-header-from-decoded-header
6568 0 subject from date message-id references 0 0 ""))
6571 `((Subject . ,subject)
6576 (defun message-wide-reply (&optional to-address)
6577 "Make a \"wide\" reply to the message in the current buffer."
6579 (message-reply to-address t))
6582 (defun message-followup (&optional to-newsgroups)
6583 "Follow up to the message in the current buffer.
6584 If TO-NEWSGROUPS, use that as the new Newsgroups line."
6586 (require 'gnus-sum) ; for gnus-list-identifiers
6587 (let ((cur (current-buffer))
6588 from subject date reply-to mrt mct mft
6589 references message-id follow-to
6590 (inhibit-point-motion-hooks t)
6591 (message-this-is-news t)
6592 followup-to distribution newsgroups gnus-warning posted-to)
6594 (message-narrow-to-head)
6595 (when (functionp message-followup-to-function)
6597 (funcall message-followup-to-function)))
6598 (setq from (message-fetch-field "from")
6599 date (message-fetch-field "date")
6600 subject (or (message-fetch-field "subject") "none")
6601 references (message-fetch-field "references")
6602 message-id (message-fetch-field "message-id" t)
6603 followup-to (message-fetch-field "followup-to")
6604 newsgroups (message-fetch-field "newsgroups")
6605 posted-to (message-fetch-field "posted-to")
6606 reply-to (message-fetch-field "reply-to")
6607 mrt (when message-use-mail-reply-to
6608 (message-fetch-field "mail-reply-to"))
6609 distribution (message-fetch-field "distribution")
6610 mct (when message-use-mail-copies-to
6611 (message-fetch-field "mail-copies-to"))
6612 mft (when message-use-mail-followup-to
6613 (message-fetch-field "mail-followup-to")))
6614 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6615 (string-match "<[^>]+>" gnus-warning))
6616 (setq message-id (match-string 0 gnus-warning)))
6617 ;; Remove bogus distribution.
6618 (when (and (stringp distribution)
6619 (let ((case-fold-search t))
6620 (string-match "world" distribution)))
6621 (setq distribution nil))
6622 (if gnus-list-identifiers
6623 (setq subject (message-strip-list-identifiers subject)))
6624 (setq subject (message-make-followup-subject subject))
6625 (when message-subject-trailing-was-query
6626 (setq subject (message-strip-subject-trailing-was subject)))
6629 ;; Handle special values of Mail-Copies-To.
6632 ((and (or (equal (downcase mct) "never")
6633 (equal (downcase mct) "nobody")))
6635 ((and (or (equal (downcase mct) "always")
6636 (equal (downcase mct) "poster")))
6637 (if (or (not (eq message-use-mail-copies-to 'ask))
6639 (concat "Obey Mail-Copies-To: always? ") t "\
6640 You should normally obey the Mail-Copies-To: header.
6642 `Mail-Copies-To: " mct "'
6643 sends a copy of your response to the author."))
6644 (setq mct (or mrt reply-to from))
6646 ((and (eq message-use-mail-copies-to 'ask)
6649 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
6650 You should normally obey the Mail-Copies-To: header.
6652 `Mail-Copies-To: " mct "'
6653 sends a copy of your response to " (if (string-match "," mct)
6654 "the specified addresses"
6655 "that address") ".")))
6660 (to-newsgroups (setq follow-to (list (cons 'Newsgroups to-newsgroups))))
6661 ;; Handle Followup-To.
6664 ((equal (downcase followup-to) "poster")
6665 (if (or (and followup-to (eq message-use-followup-to 'use))
6666 (message-y-or-n-p "Obey Followup-To: poster? " t "\
6667 You should normally obey the Followup-To: header.
6669 `Followup-To: poster'
6670 sends your response via e-mail instead of news.
6672 A typical situation where `Followup-To: poster' is used is when the poster
6673 does not read the newsgroup, so he wouldn't see any replies sent to it.
6675 You may customize the variable `message-use-followup-to', if you
6676 want to get rid of this query permanently."))
6677 (setq message-this-is-news nil
6679 follow-to (list (cons 'To (or mrt reply-to from ""))))
6680 (setq follow-to (list (cons 'Newsgroups newsgroups)))))
6682 (if (or (equal followup-to newsgroups)
6683 (not (and followup-to (eq message-use-followup-to 'ask)))
6685 (concat "Obey Followup-To: " followup-to "? ") t "\
6686 You should normally obey the Followup-To: header.
6688 `Followup-To: " followup-to "'
6689 directs your response to " (if (string-match "," followup-to)
6690 "the specified newsgroups"
6691 "that newsgroup only") ".
6693 If a message is posted to several newsgroups, Followup-To is often
6694 used to direct the following discussion to one newsgroup only,
6695 because discussions that are spread over several newsgroup tend to
6696 be fragmented and very difficult to follow.
6698 Also, some source/announcement newsgroups are not intended for discussion;
6699 responses here are directed to other newsgroups.
6701 You may customize the variable `message-use-followup-to', if you
6702 want to get rid of this query permanently."))
6703 (setq follow-to (list (cons 'Newsgroups followup-to)))
6704 (setq follow-to (list (cons 'Newsgroups newsgroups)))))))
6705 ;; Handle Mail-Followup-To, followup via e-mail.
6707 (or (not (eq message-use-mail-followup-to 'ask))
6709 (concat "Obey Mail-Followup-To: " mft "? ") t "\
6710 You should normally obey the Mail-Followup-To: header.
6712 `Mail-Followup-To: " mft "'
6713 directs your response to " (if (string-match "," mft)
6714 "the specified addresses"
6715 "that address only") " instead of news.
6717 A typical situation where Mail-Followup-To is used is when the author thinks
6718 that further discussion should take place only in "
6719 (if (string-match "," mft)
6720 "the specified mailing lists"
6721 "that mailing list") ".")))
6722 (setq message-this-is-news nil
6724 follow-to (list (cons 'To mft))))
6725 (posted-to (setq follow-to (list (cons 'Newsgroups posted-to))))
6727 (setq follow-to (list (cons 'Newsgroups newsgroups))))))
6729 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
6731 (setq message-reply-headers
6732 (make-full-mail-header-from-decoded-header
6733 0 subject from date message-id references 0 0 ""))
6736 `((Subject . ,subject)
6738 ,@(and mct (list (cons 'Cc mct)))
6739 ,@(and distribution (list (cons 'Distribution distribution))))
6742 (defun message-is-yours-p ()
6743 "Non-nil means current article is yours.
6744 If you have added 'cancel-messages to `message-shoot-gnksa-feet', all articles
6745 are yours except those that have Cancel-Lock header not belonging to you.
6746 Instead of shooting GNKSA feet, you should modify `message-alternative-emails'
6747 regexp to match all of yours addresses."
6748 ;; Canlock-logic as suggested by Per Abrahamsen
6749 ;; <abraham@dina.kvl.dk>
6751 ;; IF article has cancel-lock THEN
6752 ;; IF we can verify it THEN
6755 ;; error: cancellock: article is not yours
6757 ;; Use old rules, comparing sender...
6760 (message-narrow-to-head-1)
6761 (if (message-fetch-field "Cancel-Lock")
6762 (if (null (canlock-verify))
6764 (error "Failed to verify Cancel-lock: This article is not yours"))
6767 (message-gnksa-enable-p 'cancel-messages)
6768 (and (setq sender (message-fetch-field "sender"))
6769 (string-equal (downcase sender)
6770 (downcase (message-make-sender))))
6771 ;; Email address in From field equals to our address
6772 (and (setq from (message-fetch-field "from"))
6774 (downcase (cadr (std11-extract-address-components from)))
6775 (downcase (cadr (std11-extract-address-components
6776 (message-make-from))))))
6777 ;; Email address in From field matches
6778 ;; 'message-alternative-emails' regexp
6780 message-alternative-emails
6782 message-alternative-emails
6783 (cadr (std11-extract-address-components from))))))))))
6786 (defun message-cancel-news (&optional arg)
6787 "Cancel an article you posted.
6788 If ARG, allow editing of the cancellation message."
6790 (unless (message-news-p)
6791 (error "This is not a news article; canceling is impossible"))
6792 (let (from newsgroups message-id distribution buf)
6794 ;; Get header info from original article.
6796 (message-narrow-to-head-1)
6797 (setq from (message-fetch-field "from")
6798 newsgroups (message-fetch-field "newsgroups")
6799 message-id (message-fetch-field "message-id" t)
6800 distribution (message-fetch-field "distribution")))
6801 ;; Make sure that this article was written by the user.
6802 (unless (message-is-yours-p)
6803 (error "This article is not yours"))
6804 (when (yes-or-no-p "Do you really want to cancel this article? ")
6805 ;; Make control message.
6808 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
6810 (insert "Newsgroups: " newsgroups "\n"
6812 "Subject: cmsg cancel " message-id "\n"
6813 "Control: cancel " message-id "\n"
6815 (concat "Distribution: " distribution "\n")
6817 mail-header-separator "\n"
6818 message-cancel-message)
6819 (run-hooks 'message-cancel-hook)
6821 (message "Canceling your article...")
6822 (if (let ((message-syntax-checks
6823 'dont-check-for-anything-just-trust-me)
6824 (message-encoding-buffer (current-buffer))
6825 (message-edit-buffer (current-buffer)))
6826 (message-send-news))
6827 (message "Canceling your article...done"))
6828 (kill-buffer buf))))))
6830 (defun message-supersede-setup-for-mime-edit ()
6831 (set (make-local-variable 'message-setup-hook) nil)
6835 (defun message-supersede ()
6836 "Start composing a message to supersede the current message.
6837 This is done simply by taking the old article and adding a Supersedes
6838 header line with the old Message-ID."
6840 (let ((cur (current-buffer)))
6841 ;; Check whether the user owns the article that is to be superseded.
6842 (unless (message-is-yours-p)
6843 (error "This article is not yours"))
6844 ;; Get a normal message buffer.
6845 (message-pop-to-buffer (message-buffer-name "supersede"))
6846 (insert-buffer-substring cur)
6847 (message-narrow-to-head-1)
6848 ;; Remove unwanted headers.
6849 (when message-ignored-supersedes-headers
6850 (message-remove-header message-ignored-supersedes-headers t))
6851 (goto-char (point-min))
6852 (if (not (re-search-forward "^Message-ID: " nil t))
6853 (error "No Message-ID in this article")
6854 (replace-match "Supersedes: " t t))
6855 (goto-char (point-max))
6856 (insert mail-header-separator)
6858 (when message-supersede-setup-function
6859 (funcall message-supersede-setup-function))
6860 (run-hooks 'message-supersede-setup-hook)
6861 (goto-char (point-min))
6862 (search-forward (concat "\n" mail-header-separator "\n") nil t)))
6865 (defun message-recover ()
6866 "Reread contents of current buffer from its last auto-save file."
6868 (let ((file-name (make-auto-save-file-name)))
6869 (cond ((save-window-excursion
6870 (if (not (eq system-type 'vax-vms))
6871 (with-output-to-temp-buffer "*Directory*"
6872 (with-current-buffer standard-output
6873 (fundamental-mode)) ; for Emacs 20.4+
6874 (buffer-disable-undo standard-output)
6875 (let ((default-directory "/"))
6877 "ls" nil standard-output nil "-l" file-name))))
6878 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
6879 (let ((buffer-read-only nil))
6881 (insert-file-contents file-name nil)))
6882 (t (error "message-recover cancelled")))))
6884 ;;; Washing Subject:
6886 (defun message-wash-subject (subject)
6887 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
6888 Previous forwarders, replyers, etc. may add it."
6891 (goto-char (point-min))
6892 ;; strip Re/Fwd stuff off the beginning
6893 (while (re-search-forward
6894 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
6897 ;; and gnus-style forwards [foo@bar.com] subject
6898 (goto-char (point-min))
6899 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
6903 (goto-char (point-max))
6904 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
6907 ;; and finally, any whitespace that was left-over
6908 (goto-char (point-min))
6909 (while (re-search-forward "^[ \t]+" nil t)
6911 (goto-char (point-max))
6912 (while (re-search-backward "[ \t]+$" nil t)
6917 ;;; Forwarding messages.
6919 (defvar message-forward-decoded-p nil
6920 "Non-nil means the original message is decoded.")
6922 (defun message-forward-subject-name-subject (subject)
6923 "Generate a SUBJECT for a forwarded message.
6924 The form is: [Source] Subject, where if the original message was mail,
6925 Source is the name of the sender, and if the original message was
6926 news, Source is the list of newsgroups is was posted to."
6928 (let ((group (message-fetch-field "newsgroups"))
6931 (gnus-group-decoded-name group)
6932 (or (and (setq from (message-fetch-field "from"))
6933 (car (std11-extract-address-components
6934 (nnheader-decode-from from))))
6938 (defun message-forward-subject-author-subject (subject)
6939 "Generate a SUBJECT for a forwarded message.
6940 The form is: [Source] Subject, where if the original message was mail,
6941 Source is the sender, and if the original message was news, Source is
6942 the list of newsgroups is was posted to."
6944 (let ((group (message-fetch-field "newsgroups"))
6947 (gnus-group-decoded-name group)
6948 (if (setq from (message-fetch-field "from"))
6949 (nnheader-decode-from from)
6953 (defun message-forward-subject-fwd (subject)
6954 "Generate a SUBJECT for a forwarded message.
6955 The form is: Fwd: Subject, where Subject is the original subject of
6957 (if (string-match "^Fwd: " subject)
6959 (concat "Fwd: " subject)))
6961 (defun message-make-forward-subject ()
6962 "Return a Subject header suitable for the message in the current buffer."
6965 (message-narrow-to-head-1)
6966 (let ((funcs message-make-forward-subject-function)
6967 (subject (message-fetch-field "Subject")))
6970 (if message-forward-decoded-p
6972 (nnheader-decode-subject subject))
6974 (when message-wash-forwarded-subjects
6975 (setq subject (message-wash-subject subject)))
6976 ;; Make sure funcs is a list.
6979 (setq funcs (list funcs)))
6980 ;; Apply funcs in order, passing subject generated by previous
6981 ;; func to the next one.
6982 (dolist (func funcs)
6983 (when (functionp func)
6984 (setq subject (funcall func subject))))
6988 (defun message-forward (&optional news)
6989 "Forward the current message via mail.
6990 Optional NEWS will use news to forward instead of mail."
6992 (let ((cur (current-buffer))
6993 (subject (message-make-forward-subject)))
6995 (message-news nil subject)
6996 (message-mail nil subject))
6997 (message-forward-make-body cur)))
6999 (defun message-forward-make-body-plain (forward-buffer)
7001 "\n-------------------- Start of forwarded message --------------------\n")
7002 (let ((b (point)) e)
7005 (mm-disable-multibyte)
7007 (with-current-buffer forward-buffer
7008 (mm-with-unibyte-current-buffer (buffer-string))))
7009 (mm-enable-multibyte)
7011 (goto-char (point-min))
7012 (when (looking-at "From ")
7013 (replace-match "X-From-Line: "))
7017 "\n-------------------- End of forwarded message --------------------\n")
7018 (when message-forward-ignored-headers
7020 (narrow-to-region b e)
7022 (narrow-to-region (point)
7023 (or (search-forward "\n\n" nil t) (point)))
7024 (message-remove-header message-forward-ignored-headers t)))))
7026 (defun message-forward-make-body-mime (forward-buffer)
7027 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
7028 (let ((b (point)) e)
7030 (narrow-to-region (point) (point))
7031 (mml-insert-buffer forward-buffer)
7032 (goto-char (point-min))
7033 (when (looking-at "From ")
7034 (replace-match "X-From-Line: "))
7035 (goto-char (point-max)))
7037 (insert "<#/part>\n")))
7039 (defun message-forward-make-body-mml (forward-buffer)
7040 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
7041 (let ((b (point)) e)
7042 (if (not message-forward-decoded-p)
7045 (mm-disable-multibyte)
7047 (with-current-buffer forward-buffer
7048 (mm-with-unibyte-current-buffer (buffer-string))))
7049 (mm-enable-multibyte)
7051 (goto-char (point-min))
7052 (when (looking-at "From ")
7053 (replace-match "X-From-Line: "))
7056 (narrow-to-region (point) (point))
7057 (mml-insert-buffer forward-buffer)
7058 (goto-char (point-min))
7059 (when (looking-at "From ")
7060 (replace-match "X-From-Line: "))
7061 (goto-char (point-max))))
7063 (insert "<#/mml>\n")
7064 (when (and (not message-forward-decoded-p)
7065 message-forward-ignored-headers)
7067 (narrow-to-region b e)
7069 (narrow-to-region (point)
7070 (or (search-forward "\n\n" nil t) (point)))
7071 (message-remove-header message-forward-ignored-headers t)))))
7073 (defun message-forward-make-body-digest-plain (forward-buffer)
7075 "\n-------------------- Start of forwarded message --------------------\n")
7076 (let ((b (point)) e)
7077 (mml-insert-buffer forward-buffer)
7080 "\n-------------------- End of forwarded message --------------------\n")))
7082 (defun message-forward-make-body-digest-mime (forward-buffer)
7083 (insert "\n<#multipart type=digest>\n")
7084 (let ((b (point)) e)
7085 (insert-buffer-substring forward-buffer)
7087 (insert "<#/multipart>\n")
7089 (narrow-to-region b e)
7091 (narrow-to-region (point)
7092 (or (search-forward "\n\n" nil t) (point)))
7093 (delete-region (point-min) (point-max)))))
7095 (defun message-forward-make-body-digest (forward-buffer)
7096 (if message-forward-as-mime
7097 (message-forward-make-body-digest-mime forward-buffer)
7098 (message-forward-make-body-digest-plain forward-buffer)))
7101 (defun message-forward-make-body (forward-buffer)
7102 ;; Put point where we want it before inserting the forwarded
7104 ;; Note that this function definition for T-gnus is totally different
7105 ;; from the original Gnus."
7106 (if message-forward-before-signature
7108 (goto-char (point-max)))
7109 ;; Make sure we're at the start of the line.
7112 ;; Narrow to the area we are to insert.
7113 (narrow-to-region (point) (point))
7114 ;; Insert the separators and the forwarded buffer.
7115 (insert message-forward-start-separator)
7116 (let ((art-beg (point)))
7117 (insert-buffer-substring forward-buffer)
7118 (goto-char (point-max))
7119 (insert message-forward-end-separator)
7120 (set-text-properties (point-min) (point-max) nil)
7121 ;; Remove all unwanted headers.
7123 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
7126 (goto-char (point-min))
7127 (message-remove-header message-included-forward-headers t nil t)
7129 (message-position-point)))
7132 (defun message-forward-rmail-make-body (forward-buffer)
7133 (save-window-excursion
7134 (set-buffer forward-buffer)
7135 (if (rmail-msg-is-pruned)
7136 (rmail-msg-restore-non-pruned-header)))
7137 (message-forward-make-body forward-buffer))
7139 (eval-when-compile (defvar rmail-enable-mime-composing))
7141 ;; Fixme: Should have defcustom.
7143 (defun message-insinuate-rmail ()
7144 "Let RMAIL use message to forward."
7146 (setq rmail-enable-mime-composing t)
7147 (setq rmail-insert-mime-forwarded-message-function
7148 'message-forward-rmail-make-body))
7151 (defun message-resend (address)
7152 "Resend the current article to ADDRESS."
7154 (list (message-read-from-minibuffer "Resend message to: ")))
7155 (message "Resending message to %s..." address)
7157 (let ((cur (current-buffer))
7159 ;; We first set up a normal mail buffer.
7160 (unless (message-mail-user-agent)
7161 (set-buffer (get-buffer-create " *message resend*"))
7163 (let ((message-this-is-mail t)
7165 (message-setup `((To . ,address))))
7166 ;; Insert our usual headers.
7167 (message-generate-headers '(From Date To Message-ID))
7168 (message-narrow-to-headers)
7169 ;; Remove X-Draft-From header etc.
7170 (message-remove-header message-ignored-mail-headers t)
7171 ;; Rename them all to "Resent-*".
7172 (goto-char (point-min))
7173 (while (re-search-forward "^[A-Za-z]" nil t)
7178 (delete-region (point) (point-max))
7180 ;; Insert the message to be resent.
7181 (insert-buffer-substring cur)
7182 (goto-char (point-min))
7183 (search-forward "\n\n")
7186 (narrow-to-region beg (point))
7187 (message-remove-header message-ignored-resent-headers t)
7188 (goto-char (point-max)))
7189 (insert mail-header-separator)
7190 ;; Rename all old ("Also-")Resent headers.
7191 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
7194 ;; Quote any "From " lines at the beginning.
7196 (when (looking-at "From ")
7197 (replace-match "X-From-Line: "))
7199 (let ((message-encoding-buffer (current-buffer))
7200 (message-edit-buffer (current-buffer))
7201 message-required-mail-headers)
7202 (message-send-mail))
7203 (kill-buffer (current-buffer)))
7204 (message "Resending message to %s...done" address)))
7206 (defun message-bounce-setup-for-mime-edit ()
7207 (set (make-local-variable 'message-setup-hook) nil)
7211 (defun message-bounce ()
7212 "Re-mail the current message.
7213 This only makes sense if the current message is a bounce message that
7214 contains some mail you have written which has been bounced back to
7217 (let ((cur (current-buffer))
7218 mime-boundary boundary)
7219 (message-pop-to-buffer (message-buffer-name "bounce"))
7220 (insert-buffer-substring cur)
7222 (message-narrow-to-head)
7223 (if (and (message-fetch-field "MIME-Version")
7224 (setq mime-boundary (message-fetch-field "Content-Type")))
7225 (if (string-match "boundary=\"\\([^\"]+\\)\"" mime-boundary)
7226 (setq mime-boundary (concat (regexp-quote
7227 (match-string 1 mime-boundary))
7228 " *\nContent-Type: message/rfc822"))
7229 (setq mime-boundary nil)))
7231 (goto-char (point-min))
7232 (re-search-forward "\n\n+" nil t)
7233 (setq boundary (point))
7234 ;; We remove everything before the bounced mail.
7235 (if (or (and mime-boundary
7236 (re-search-forward mime-boundary nil t)
7238 (re-search-forward message-unsent-separator nil t)
7240 (search-forward "\n\n" nil 'move)
7241 (re-search-backward "^Return-Path:.*\n" boundary t)))
7244 (delete-region (point-min)
7245 (if (re-search-forward "^[^ \n\t]+:" nil t)
7248 (when (re-search-backward "^.?From .*\n" nil t)
7249 (delete-region (match-beginning 0) (match-end 0))))
7251 (message-narrow-to-head-1)
7252 (message-remove-header message-ignored-bounced-headers t)
7253 (goto-char (point-max))
7254 (insert mail-header-separator))
7255 (when message-bounce-setup-function
7256 (funcall message-bounce-setup-function))
7257 (run-hooks 'message-bounce-setup-hook)
7258 (message-position-point)))
7261 ;;; Interactive entry points for new message buffers.
7265 (defun message-mail-other-window (&optional to subject)
7266 "Like `message-mail' command, but display mail buffer in another window."
7268 (unless (message-mail-user-agent)
7269 (let ((pop-up-windows t)
7270 (special-display-buffer-names nil)
7271 (special-display-regexps nil)
7272 (same-window-buffer-names nil)
7273 (same-window-regexps nil))
7274 (message-pop-to-buffer (message-buffer-name "mail" to))))
7275 (let ((message-this-is-mail t))
7276 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7277 nil nil 'switch-to-buffer-other-window)))
7280 (defun message-mail-other-frame (&optional to subject)
7281 "Like `message-mail' command, but display mail buffer in another frame."
7283 (unless (message-mail-user-agent)
7284 (let ((pop-up-frames t)
7285 (special-display-buffer-names nil)
7286 (special-display-regexps nil)
7287 (same-window-buffer-names nil)
7288 (same-window-regexps nil))
7289 (message-pop-to-buffer (message-buffer-name "mail" to))))
7290 (let ((message-this-is-mail t))
7291 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7292 nil nil 'switch-to-buffer-other-frame)))
7295 (defun message-news-other-window (&optional newsgroups subject)
7296 "Start editing a news article to be sent."
7298 (let ((pop-up-windows t)
7299 (special-display-buffer-names nil)
7300 (special-display-regexps nil)
7301 (same-window-buffer-names nil)
7302 (same-window-regexps nil))
7303 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
7304 (let ((message-this-is-news t))
7305 (message-setup `((Newsgroups . ,(or newsgroups ""))
7306 (Subject . ,(or subject ""))))))
7309 (defun message-news-other-frame (&optional newsgroups subject)
7310 "Start editing a news article to be sent."
7312 (let ((pop-up-frames t)
7313 (special-display-buffer-names nil)
7314 (special-display-regexps nil)
7315 (same-window-buffer-names nil)
7316 (same-window-regexps nil))
7317 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
7318 (let ((message-this-is-news t))
7319 (message-setup `((Newsgroups . ,(or newsgroups ""))
7320 (Subject . ,(or subject ""))))))
7324 ;; This code should be moved to underline.el (from which it is stolen).
7327 (defun bold-region (start end)
7328 "Bold all nonblank characters in the region.
7329 Works by overstriking characters.
7330 Called from program, takes two arguments START and END
7331 which specify the range to operate on."
7334 (let ((end1 (make-marker)))
7335 (move-marker end1 (max start end))
7336 (goto-char (min start end))
7337 (while (< (point) end1)
7338 (or (looking-at "[_\^@- ]")
7339 (insert (char-after) "\b"))
7340 (forward-char 1)))))
7343 (defun unbold-region (start end)
7344 "Remove all boldness (overstruck characters) in the region.
7345 Called from program, takes two arguments START and END
7346 which specify the range to operate on."
7349 (let ((end1 (make-marker)))
7350 (move-marker end1 (max start end))
7351 (goto-char (min start end))
7352 (while (search-forward "\b" end1 t)
7353 (if (eq (char-after) (char-after (- (point) 2)))
7354 (delete-char -2))))))
7356 (defun message-exchange-point-and-mark ()
7357 "Exchange point and mark, but don't activate region if it was inactive."
7359 (message-mark-active-p)
7360 (exchange-point-and-mark))
7361 (setq mark-active nil)))
7363 (defalias 'message-make-overlay 'make-overlay)
7364 (defalias 'message-delete-overlay 'delete-overlay)
7365 (defalias 'message-overlay-put 'overlay-put)
7366 (defun message-kill-all-overlays ()
7367 (if (featurep 'xemacs)
7368 (map-extents (lambda (extent ignore) (delete-extent extent)))
7369 (mapcar #'delete-overlay (overlays-in (point-min) (point-max)))))
7371 ;; Support for toolbar
7373 (defvar tool-bar-map)
7374 (defvar tool-bar-mode))
7376 (defun message-tool-bar-local-item-from-menu (command icon in-map &optional from-map &rest props)
7377 ;; We need to make tool bar entries in local keymaps with
7378 ;; `tool-bar-local-item-from-menu' in Emacs > 21.3
7379 (if (fboundp 'tool-bar-local-item-from-menu)
7380 ;; This is for Emacs 21.3
7381 (tool-bar-local-item-from-menu command icon in-map from-map props)
7382 (tool-bar-add-item-from-menu command icon from-map props)))
7384 (defun message-tool-bar-map ()
7385 (or message-tool-bar-map
7386 (setq message-tool-bar-map
7388 (condition-case nil (require 'tool-bar) (error nil))
7389 (fboundp 'tool-bar-add-item-from-menu)
7391 (let ((tool-bar-map (copy-keymap tool-bar-map))
7392 (load-path (mm-image-load-path)))
7393 ;; Zap some items which aren't so relevant and take
7395 (dolist (key '(print-buffer kill-buffer save-buffer
7396 write-file dired open-file))
7397 (define-key tool-bar-map (vector key) nil))
7398 (message-tool-bar-local-item-from-menu
7399 'message-send-and-exit "mail_send" tool-bar-map message-mode-map)
7400 (message-tool-bar-local-item-from-menu
7401 'message-kill-buffer "close" tool-bar-map message-mode-map)
7402 (message-tool-bar-local-item-from-menu
7403 'message-dont-send "cancel" tool-bar-map message-mode-map)
7404 ;; (message-tool-bar-local-item-from-menu
7405 ;; 'mime-edit-insert-file "attach"
7406 ;; tool-bar-map mime-edit-mode-map)
7407 (message-tool-bar-local-item-from-menu
7408 'ispell-message "spell" tool-bar-map message-mode-map)
7409 ;; (message-tool-bar-local-item-from-menu
7410 ;; 'mime-edit-preview-message "preview"
7411 ;; tool-bar-map mime-edit-mode-map)
7412 (message-tool-bar-local-item-from-menu
7413 'message-insert-importance-high "important"
7414 tool-bar-map message-mode-map)
7415 (message-tool-bar-local-item-from-menu
7416 'message-insert-importance-low "unimportant"
7417 tool-bar-map message-mode-map)
7418 (message-tool-bar-local-item-from-menu
7419 'message-insert-disposition-notification-to "receipt"
7420 tool-bar-map message-mode-map)
7423 ;;; Group name completion.
7425 (defcustom message-newgroups-header-regexp
7426 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
7427 "Regexp that match headers that lists groups."
7431 (defcustom message-completion-alist
7432 (list (cons message-newgroups-header-regexp 'message-expand-group)
7433 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name)
7434 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
7435 . message-expand-name)
7436 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
7437 . message-expand-name))
7438 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
7441 :type '(alist :key-type regexp :value-type function))
7443 (defcustom message-expand-name-databases
7444 (list 'bbdb 'eudc 'lsdb)
7445 "List of databases to try for name completion (`message-expand-name').
7446 Each element is a symbol and can be `bbdb', `eudc' or `lsdb'."
7448 :type '(set (const bbdb) (const eudc) (const lsdb)))
7450 (defcustom message-expand-name-function
7451 (cond ((and (boundp 'eudc-protocol)
7453 'eudc-expand-inline)
7454 ((fboundp 'bbdb-complete-name)
7455 'bbdb-complete-name)
7456 ((fboundp 'lsdb-complete-name)
7457 'lsdb-complete-name)
7459 "*A function called to expand addresses in field body.
7460 This variable is semi-obsolete, set it as nil and use
7461 `message-expand-name-databases' instead."
7463 :type '(radio (const :format "Invalidate it: %v\n" nil)
7464 (function-item :format "eudc: %v\n" eudc-expand-inline)
7465 (function-item :format "bbdb: %v\n" bbdb-complete-name)
7466 (function-item :format "lsdb: %v\n" lsdb-complete-name)
7467 (function :value expand-abbrev)))
7469 (defcustom message-tab-body-function nil
7470 "*Function to execute when `message-tab' (TAB) is executed in the body.
7471 If nil, the function bound in `text-mode-map' or `global-map' is executed."
7474 :link '(custom-manual "(message)Various Commands")
7475 :type '(choice (const nil)
7478 (defun message-tab ()
7479 "Complete names according to `message-completion-alist'.
7480 Execute function specified by `message-tab-body-function' when not in
7483 (let ((alist message-completion-alist))
7485 (let ((mail-abbrev-mode-regexp (caar alist)))
7486 (not (mail-abbrev-in-expansion-header-p))))
7487 (setq alist (cdr alist)))
7488 (funcall (or (cdar alist) message-tab-body-function
7489 (lookup-key text-mode-map "\t")
7490 (lookup-key global-map "\t")
7491 'indent-relative))))
7493 (defun message-expand-group ()
7494 "Expand the group name under point."
7495 (let* ((b (save-excursion
7500 (skip-chars-forward "^:")
7503 (skip-chars-backward "^, \t\n") (point))))
7504 (completion-ignore-case t)
7505 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
7507 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
7508 (completions (all-completions string hashtb))
7510 (delete-region b (point))
7512 ((= (length completions) 1)
7513 (if (string= (car completions) string)
7516 (message "Only matching group"))
7517 (insert (car completions))))
7518 ((and (setq comp (try-completion string hashtb))
7519 (not (string= comp string)))
7524 (message "No matching groups")
7525 (save-selected-window
7526 (pop-to-buffer "*Completions*")
7527 (buffer-disable-undo)
7528 (let ((buffer-read-only nil))
7530 (let ((standard-output (current-buffer)))
7531 (display-completion-list (sort completions 'string<)))
7532 (goto-char (point-min))
7533 (delete-region (point) (progn (forward-line 3) (point))))))))))
7535 (defun message-expand-name ()
7536 (cond (message-expand-name-function
7537 (funcall message-expand-name-function))
7538 ((and (memq 'eudc message-expand-name-databases)
7539 (boundp 'eudc-protocol)
7541 (eudc-expand-inline))
7542 ((and (memq 'bbdb message-expand-name-databases)
7543 (fboundp 'bbdb-complete-name))
7544 (bbdb-complete-name))
7545 ((and (memq 'lsdb message-expand-name-databases)
7546 (fboundp 'lsdb-complete-name))
7547 (lsdb-complete-name))
7548 (t 'expand-abbrev)))
7552 (defun message-talkative-question (ask question show &rest text)
7553 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
7554 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
7555 The following arguments may contain lists of values."
7557 (setq text (message-flatten-list text)))
7558 (save-window-excursion
7560 (with-output-to-temp-buffer " *MESSAGE information message*"
7561 (set-buffer " *MESSAGE information message*")
7562 (fundamental-mode) ; for Emacs 20.4+
7563 (mapcar 'princ text)
7564 (goto-char (point-min))))
7565 (funcall ask question))
7566 (funcall ask question)))
7568 (defun message-flatten-list (list)
7569 "Return a new, flat list that contains all elements of LIST.
7571 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
7574 (apply 'append (mapcar 'message-flatten-list list)))
7578 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
7579 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
7580 Then clone the local variables and values from the old buffer to the
7581 new one, cloning only the locals having a substring matching the
7583 (let ((oldbuf (current-buffer)))
7585 (set-buffer (generate-new-buffer name))
7586 (message-clone-locals oldbuf varstr)
7589 (defun message-clone-locals (buffer &optional varstr)
7590 "Clone the local variables from BUFFER to the current buffer."
7591 (let ((locals (save-excursion
7593 (buffer-local-variables)))
7594 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address\\|^user-full-name"))
7597 (when (and (consp local)
7599 (string-match regexp (symbol-name (car local)))
7601 (string-match varstr (symbol-name (car local)))))
7603 (set (make-local-variable (car local))
7607 ;;; @ for MIME Edit mode
7610 (defun message-maybe-encode ()
7611 (when message-mime-mode
7612 ;; Inherit the buffer local variable `mime-edit-pgp-processing'.
7613 (let ((pgp-processing (with-current-buffer message-edit-buffer
7614 mime-edit-pgp-processing)))
7615 (setq mime-edit-pgp-processing pgp-processing))
7616 (run-hooks 'mime-edit-translate-hook)
7617 (if (catch 'mime-edit-error
7619 (mime-edit-pgp-enclose-buffer)
7620 (mime-edit-translate-body)))
7621 (error "Translation error!"))
7622 (run-hooks 'mime-edit-exit-hook)))
7624 (defun message-mime-insert-article (&optional full-headers)
7626 (let ((message-cite-function 'mime-edit-inserted-message-filter)
7627 (message-reply-buffer
7628 (message-get-parameter-with-eval 'original-buffer))
7630 (message-yank-original nil)
7632 (narrow-to-region (goto-char start)
7633 (if (search-forward "\n\n" nil t)
7636 (goto-char (point-min))
7637 (let ((message-included-forward-headers
7638 (if full-headers "" message-included-forward-headers)))
7639 (message-remove-header message-included-forward-headers t nil t))
7642 (set-alist 'mime-edit-message-inserter-alist
7643 'message-mode (function message-mime-insert-article))
7649 (defvar message-inhibit-body-encoding t)
7651 (defun message-encode-message-body ()
7652 (unless message-inhibit-body-encoding
7653 (let ((mail-parse-charset (or mail-parse-charset
7654 message-default-charset))
7655 (case-fold-search t)
7656 lines content-type-p)
7659 (narrow-to-region (point) (point-max))
7660 (let ((new (mml-generate-mime)))
7662 (delete-region (point-min) (point-max))
7664 (goto-char (point-min))
7665 (if (eq (aref new 0) ?\n)
7667 (search-forward "\n\n")
7668 (setq lines (buffer-substring (point-min) (1- (point))))
7669 (delete-region (point-min) (point))))))
7671 (message-narrow-to-headers-or-head)
7672 (message-remove-header "Mime-Version")
7673 (goto-char (point-max))
7674 (insert "MIME-Version: 1.0\n")
7677 (setq content-type-p
7679 (re-search-backward "^Content-Type:" nil t))))
7681 (message-narrow-to-headers-or-head)
7682 (message-remove-first-header "Content-Type")
7683 (message-remove-first-header "Content-Transfer-Encoding"))
7684 ;; We always make sure that the message has a Content-Type
7685 ;; header. This is because some broken MTAs and MUAs get
7686 ;; awfully confused when confronted with a message with a
7687 ;; MIME-Version header and without a Content-Type header. For
7688 ;; instance, Solaris' /usr/bin/mail.
7689 (unless content-type-p
7690 (goto-char (point-min))
7691 ;; For unknown reason, MIME-Version doesn't exist.
7692 (when (re-search-forward "^MIME-Version:" nil t)
7694 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
7696 (defun message-read-from-minibuffer (prompt &optional initial-contents)
7697 "Read from the minibuffer while providing abbrev expansion."
7698 (if (fboundp 'mail-abbrevs-setup)
7699 (let ((mail-abbrev-mode-regexp "")
7700 (minibuffer-setup-hook 'mail-abbrevs-setup)
7701 (minibuffer-local-map message-minibuffer-local-map))
7702 (read-from-minibuffer prompt initial-contents))
7703 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
7704 (minibuffer-local-map message-minibuffer-local-map))
7705 (read-string prompt initial-contents))))
7707 (defun message-use-alternative-email-as-from ()
7708 "Set From field of the outgoing message to the first matching
7709 address in `message-alternative-emails', looking at To, Cc and
7710 From headers in the original article."
7711 (require 'mail-utils)
7712 (let* ((fields '("To" "Cc" "From"))
7715 (mail-strip-quoted-names
7716 (mapconcat 'message-fetch-reply-field fields ","))
7720 (if (string-match message-alternative-emails (car emails))
7721 (setq email (car emails)
7724 (unless (or (not email) (equal email user-mail-address))
7725 (message-remove-header "From")
7726 (goto-char (point-max))
7727 (insert "From: " (let ((user-mail-address email)) (message-make-from))
7730 (defun message-options-get (symbol)
7731 (cdr (assq symbol message-options)))
7733 (defun message-options-set (symbol value)
7734 (let ((the-cons (assq symbol message-options)))
7737 (setcdr the-cons value)
7738 (setq message-options (delq the-cons message-options)))
7740 (push (cons symbol value) message-options))))
7743 (defun message-options-set-recipient ()
7745 (message-narrow-to-headers-or-head)
7746 (message-options-set 'message-sender
7747 (mail-strip-quoted-names
7748 (message-fetch-field "from")))
7749 (message-options-set 'message-recipients
7750 (mail-strip-quoted-names
7751 (let ((to (message-fetch-field "to"))
7752 (cc (message-fetch-field "cc"))
7753 (bcc (message-fetch-field "bcc")))
7756 (if (and to cc) ", ")
7758 (if (and (or to cc) bcc) ", ")
7761 (defun message-hide-headers ()
7762 "Hide headers based on the `message-hidden-headers' variable."
7763 (let ((regexps (if (stringp message-hidden-headers)
7764 (list message-hidden-headers)
7765 message-hidden-headers))
7766 (inhibit-point-motion-hooks t)
7767 (after-change-functions nil)
7772 (message-narrow-to-headers)
7773 (goto-char (point-min))
7775 (if (not (message-hide-header-p regexps))
7776 (message-next-header)
7777 (let ((begin (point))
7779 (message-next-header)
7780 (setq header (buffer-substring begin (point))
7781 header-len (- (point) begin))
7782 (delete-region begin (point))
7783 (goto-char (1+ end-of-headers))
7785 (setq end-of-headers
7786 (+ end-of-headers header-len))))))))
7787 (narrow-to-region (1+ end-of-headers) (point-max))))
7789 (defun message-hide-header-p (regexps)
7792 (when (eq (car regexps) 'not)
7795 (dolist (regexp regexps)
7796 (setq result (or result (looking-at regexp))))
7801 (when (featurep 'xemacs)
7802 (require 'messagexmas)
7803 (message-xmas-redefine))
7807 (run-hooks 'message-load-hook)
7810 ;; coding: iso-8859-1
7813 ;;; message.el ends here