1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
8 ;; Keiichi Suzuki <kei-suzu@mail.wbs.ne.jp>
9 ;; Tatsuya Ichikawa <t-ichi@po.shiojiri.ne.jp>
10 ;; Katsumi Yamaoka <yamaoka@jpl.org>
11 ;; Kiyokazu SUTO <suto@merry.xmath.ous.ac.jp>
12 ;; Keywords: mail, news, MIME
14 ;; This file is part of GNU Emacs.
16 ;; GNU Emacs is free software; you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation; either version 2, or (at your option)
21 ;; GNU Emacs is distributed in the hope that it will be useful,
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;; GNU General Public License for more details.
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs; see the file COPYING. If not, write to the
28 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
29 ;; Boston, MA 02111-1307, USA.
33 ;; This mode provides mail-sending facilities from within Emacs. It
34 ;; consists mainly of large chunks of code from the sendmail.el,
35 ;; gnus-msg.el and rnewspost.el files.
42 (defvar gnus-message-group-art)
43 (defvar gnus-list-identifiers)) ; gnus-sum is required where necessary
48 (require 'canlock-om))
52 ;; This is apparently necessary even though things are autoloaded.
53 ;; Because we dynamically bind mail-abbrev-mode-regexp, we'd better
54 ;; require mailabbrev here.
55 (if (featurep 'xemacs)
56 (require 'mail-abbrevs)
57 (require 'mailabbrev))
59 (eval-when-compile (require 'static))
61 ;; Avoid byte-compile warnings.
68 (autoload 'customize-save-variable "cus-edit") ;; for Mule 2.
69 (autoload 'sha1 "sha1-el")
70 (autoload 'gnus-find-method-for-group "gnus")
71 (autoload 'nnvirtual-find-group-art "nnvirtual")
72 (autoload 'gnus-group-decoded-name "gnus-group"))
74 (defgroup message '((user-mail-address custom-variable)
75 (user-full-name custom-variable))
76 "Mail and news message composing."
77 :link '(custom-manual "(message)Top")
81 (put 'user-mail-address 'custom-type 'string)
82 (put 'user-full-name 'custom-type 'string)
84 (defgroup message-various nil
85 "Various Message Variables"
86 :link '(custom-manual "(message)Various Message Variables")
89 (defgroup message-buffers nil
91 :link '(custom-manual "(message)Message Buffers")
94 (defgroup message-sending nil
96 :link '(custom-manual "(message)Sending Variables")
99 (defgroup message-interface nil
101 :link '(custom-manual "(message)Interface")
104 (defgroup message-forwarding nil
106 :link '(custom-manual "(message)Forwarding")
107 :group 'message-interface)
109 (defgroup message-insertion nil
111 :link '(custom-manual "(message)Insertion")
114 (defgroup message-headers nil
116 :link '(custom-manual "(message)Message Headers")
119 (defgroup message-news nil
120 "Composing News Messages"
123 (defgroup message-mail nil
124 "Composing Mail Messages"
127 (defgroup message-faces nil
128 "Faces used for message composing."
132 (defgroup message-frames nil
136 (defcustom message-directory "~/Mail/"
137 "*Directory from which all other mail file variables are derived."
138 :group 'message-various
141 (defcustom message-max-buffers 10
142 "*How many buffers to keep before starting to kill them off."
143 :group 'message-buffers
146 (defcustom message-send-rename-function nil
147 "Function called to rename the buffer after sending it."
148 :group 'message-buffers
149 :type '(choice function (const nil)))
151 (defcustom message-fcc-handler-function 'message-output
152 "*A function called to save outgoing articles.
153 This function will be called with the name of the file to store the
154 article in. The default function is `message-output' which saves in Unix
156 :type '(radio (function-item message-output)
157 (function :tag "Other"))
158 :group 'message-sending)
160 (defcustom message-encode-function 'message-maybe-encode
161 "*A function called to encode messages."
162 :group 'message-sending
165 (defcustom message-8bit-encoding-list '(8bit binary)
166 "*8bit encoding type in Content-Transfer-Encoding field."
167 :group 'message-sending
168 :type '(repeat (symbol :tag "Type")))
170 (defcustom message-fcc-externalize-attachments nil
171 "If non-nil, attachments are included as external parts in Fcc copies."
173 :group 'message-sending)
175 (defcustom message-courtesy-message
176 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
177 "*This is inserted at the start of a mailed copy of a posted message.
178 If the string contains the format spec \"%s\", the Newsgroups
179 the article has been posted to will be inserted there.
180 If this variable is nil, no such courtesy message will be added."
181 :group 'message-sending
182 :type '(radio (string :format "%t: %v\n" :size 0) (const nil)))
184 (defcustom message-ignored-bounced-headers
185 "^\\(Received\\|Return-Path\\|Delivered-To\\):"
186 "*Regexp that matches headers to be removed in resent bounced mail."
187 :group 'message-interface
190 (defcustom message-bounce-setup-function 'message-bounce-setup-for-mime-edit
191 "Function to setup a re-sending bounced message."
192 :group 'message-sending
195 ;;; Start of variables adopted from `message-utils.el'.
197 (defcustom message-subject-trailing-was-query 'ask
198 ;; should it default to nil or ask?
199 "*What to do with trailing \"(was: <old subject>)\" in subject lines.
200 If nil, leave the subject unchanged. If it is the symbol `ask', query
201 the user what do do. In this case, the subject is matched against
202 `message-subject-trailing-was-ask-regexp'. If
203 `message-subject-trailing-was-query' is t, always strip the trailing
204 old subject. In this case, `message-subject-trailing-was-regexp' is
206 :type '(choice (const :tag "never" nil)
207 (const :tag "always strip" t)
209 :group 'message-various)
211 (defcustom message-subject-trailing-was-ask-regexp
212 "[ \t]*\\([[(]+[Ww][Aa][Ss][ \t]*.*[\])]+\\)"
213 "*Regexp matching \"(was: <old subject>)\" in the subject line.
215 The function `message-strip-subject-trailing-was' uses this regexp if
216 `message-subject-trailing-was-query' is set to the symbol `ask'. If
217 the variable is t instead of `ask', use
218 `message-subject-trailing-was-regexp' instead.
220 It is okay to create some false positives here, as the user is asked."
221 :group 'message-various
224 (defcustom message-subject-trailing-was-regexp
225 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
226 "*Regexp matching \"(was: <old subject>)\" in the subject line.
228 If `message-subject-trailing-was-query' is set to t, the subject is
229 matched against `message-subject-trailing-was-regexp' in
230 `message-strip-subject-trailing-was'. You should use a regexp creating very
231 few false positives here."
232 :group 'message-various
235 ;; Fixme: Why are all these things autoloaded?
237 ;;; marking inserted text
240 (defcustom message-mark-insert-begin
241 "--8<---------------cut here---------------start------------->8---\n"
242 "How to mark the beginning of some inserted text."
244 :group 'message-various)
247 (defcustom message-mark-insert-end
248 "--8<---------------cut here---------------end--------------->8---\n"
249 "How to mark the end of some inserted text."
251 :group 'message-various)
254 (defcustom message-archive-header
255 "X-No-Archive: Yes\n"
256 "Header to insert when you don't want your article to be archived.
257 Archives \(such as groups.google.com\) respect this header."
259 :group 'message-various)
262 (defcustom message-archive-note
263 "X-No-Archive: Yes - save http://groups.google.com/"
264 "Note to insert why you wouldn't want this posting archived.
265 If nil, don't insert any text in the body."
266 :type '(radio (string :format "%t: %v\n" :size 0)
268 :group 'message-various)
270 ;;; Crossposts and Followups
271 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
272 ;; new suggestions by R. Weikusat <rw at another.de>
274 (defvar message-cross-post-old-target nil
275 "Old target for cross-posts or follow-ups.")
276 (make-variable-buffer-local 'message-cross-post-old-target)
279 (defcustom message-cross-post-default t
280 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
281 If nil, `message-cross-post-followup-to' will only do a followup. Note that
282 you can explicitly override this setting by calling
283 `message-cross-post-followup-to' with a prefix."
285 :group 'message-various)
288 (defcustom message-cross-post-note
289 "Crosspost & Followup-To: "
290 "Note to insert before signature to notify of xpost and follow-up."
292 :group 'message-various)
295 (defcustom message-followup-to-note
297 "Note to insert before signature to notify of follow-up only."
299 :group 'message-various)
302 (defcustom message-cross-post-note-function
303 'message-cross-post-insert-note
304 "Function to use to insert note about Crosspost or Followup-To.
305 The function will be called with four arguments. The function should not only
306 insert a note, but also ensure old notes are deleted. See the documentation
307 for `message-cross-post-insert-note'."
309 :group 'message-various)
311 ;;; End of variables adopted from `message-utils.el'.
314 (defcustom message-from-style 'default
315 "*Specifies how \"From\" headers look.
317 If nil, they contain just the return address like:
319 If `parens', they look like:
320 king@grassland.com (Elvis Parsley)
321 If `angles', they look like:
322 Elvis Parsley <king@grassland.com>
324 Otherwise, most addresses look like `angles', but they look like
325 `parens' if `angles' would need quoting and `parens' would not."
326 :type '(choice (const :tag "simple" nil)
330 :group 'message-headers)
332 (defcustom message-insert-canlock t
333 "Whether to insert a Cancel-Lock header in news postings."
335 :group 'message-headers
338 (defcustom message-syntax-checks
339 (if message-insert-canlock '((sender . disabled)) nil)
340 ;; Guess this one shouldn't be easy to customize...
341 "*Controls what syntax checks should not be performed on outgoing posts.
342 To disable checking of long signatures, for instance, add
343 `(signature . disabled)' to this list.
345 Don't touch this variable unless you really know what you're doing.
347 Checks include `subject-cmsg', `multiple-headers', `sendsys',
348 `message-id', `from', `long-lines', `control-chars', `size',
349 `new-text', `quoting-style', `redirected-followup', `signature',
350 `approved', `sender', `empty', `empty-headers', `message-id', `from',
351 `subject', `shorten-followup-to', `existing-newsgroups',
352 `buffer-file-name', `unchanged', `newsgroups', `reply-to',
353 `continuation-headers', `long-header-lines', `invisible-text' and
356 :type '(repeat sexp)) ; Fixme: improve this
358 (defcustom message-required-headers '((optional . References)
360 "*Headers to be generated or prompted for when sending a message.
361 Also see `message-required-news-headers' and
362 `message-required-mail-headers'."
364 :group 'message-headers
365 :type '(repeat sexp))
367 (defcustom message-draft-headers '(References From)
368 "*Headers to be generated when saving a draft message."
370 :group 'message-headers
371 :type '(repeat sexp))
373 (defcustom message-required-news-headers
374 '(From Newsgroups Subject Date Message-ID
375 (optional . Organization)
376 (optional . User-Agent))
377 "*Headers to be generated or prompted for when posting an article.
378 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
379 Message-ID. Organization, Lines, In-Reply-To, Expires, and
380 User-Agent are optional. If don't you want message to insert some
381 header, remove it from this list."
383 :group 'message-headers
384 :type '(repeat sexp))
386 (defcustom message-required-mail-headers
387 '(From Subject Date (optional . In-Reply-To) Message-ID
388 (optional . User-Agent))
389 "*Headers to be generated or prompted for when mailing a message.
390 It is recommended that From, Date, To, Subject and Message-ID be
391 included. Organization and User-Agent are optional."
393 :group '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
401 (defcustom message-ignored-news-headers
402 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
403 "*Regexp of headers to be removed unconditionally before posting."
405 :group 'message-headers
408 (defcustom message-ignored-mail-headers
409 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
410 "*Regexp of headers to be removed unconditionally before mailing."
412 :group 'message-headers
415 (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:"
416 "*Header lines matching this regexp will be deleted before posting.
417 It's best to delete old Path and Date headers before posting to avoid
419 :group 'message-interface
422 (defcustom message-supersede-setup-function
423 'message-supersede-setup-for-mime-edit
424 "Function to setup a supersede message."
425 :group 'message-sending
428 (defcustom message-subject-re-regexp
429 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)*:[ \t]*\\)*[ \t]*"
430 "*Regexp matching \"Re: \" in the subject line."
431 :group 'message-various
434 ;;; Some sender agents encode the whole subject including leading "Re: ".
435 ;;; And if followup agent does not decode it for some reason (e.g. unknown
436 ;;; charset) and just add a new "Re: " in front of the encoded-word, the
437 ;;; result will contain multiple "Re: "'s.
438 (defcustom message-subject-encoded-re-regexp
442 "[-!#$%&'*+0-9A-Z^_`a-z{|}~]+" ; charset
445 "[Bb]" (regexp-quote "?") ; B encoding
446 "\\(\\(CQk\\|CSA\\|IAk\\|ICA\\)[Jg]\\)*" ; \([ \t][ \t][ \t]\)*
448 "[Uc][km]U6" ; [Rr][Ee]:
450 "\\(C[VX]\\|I[FH]\\)J[Fl]O[g-v]" ; [ \t][Rr][Ee]:
452 "\\(CQl\\|CSB\\|IAl\\|ICB\\)[Sy][RZ]T[o-r]" ; [ \t][ \t][Rr][Ee]:
455 "[Qb]" (regexp-quote "?") ; Q encoding
456 "\\(_\\|=09\\|=20\\)*"
457 "\\([Rr]\\|=[57]2\\)\\([Ee]\\|=[46]5\\)\\(:\\|=3[Aa]\\)"
460 "*Regexp matching \"Re: \" in the subject line.
461 Unlike `message-subject-re-regexp', this regexp matches \"Re: \" within
463 :group 'message-various
466 (defcustom message-use-subject-re t
467 "*If t, remove any (buggy) \"Re: \"'s from the subject of the precursor
468 and add a new \"Re: \". If it is nil, use the subject \"as-is\". If it
469 is the symbol `guess', try to detect \"Re: \" within an encoded-word."
470 :group 'message-various
471 :type '(choice (const :tag "off" nil)
476 (defcustom message-signature-separator "^-- *$"
477 "Regexp matching the signature separator."
479 :group 'message-various)
481 (defcustom message-signature-separator-for-insertion "-- \n"
482 "*Signature separator. This value will be inserted as signature separator
483 when composing message. Default value is \"-- \\n\". Notice: Changing this
484 value may go against RFC-1036 and draft-ietf-usefor-article-05.txt. "
486 :group 'message-insertion)
488 (defcustom message-elide-ellipsis "\n[...]\n\n"
489 "*The string which is inserted for elided text."
491 :group 'message-various)
493 (defcustom message-interactive t
494 "Non-nil means when sending a message wait for and display errors.
495 nil means let mailer mail back a message to report errors."
496 :group 'message-sending
500 (defcustom message-generate-new-buffers 'unique
501 "*Non-nil means create a new message buffer whenever `message-setup' is called.
502 If this is a function, call that function with three parameters: The type,
503 the to address and the group name. (Any of these may be nil.) The function
504 should return the new buffer name."
505 :group 'message-buffers
506 :type '(choice (const :tag "off" nil)
507 (const :tag "unique" unique)
508 (const :tag "unsent" unsent)
511 (defcustom message-kill-buffer-on-exit nil
512 "*Non-nil means that the message buffer will be killed after sending a message."
513 :group 'message-buffers
516 (defcustom message-kill-buffer-query-function 'yes-or-no-p
517 "*Function used to prompt user whether to kill the message buffer. If
518 it is t, the buffer will be killed unconditionally."
519 :type '(radio (function-item yes-or-no-p)
520 (function-item y-or-n-p)
521 (function-item nnheader-Y-or-n-p)
522 (function :tag "Other" t))
523 :group 'message-buffers)
525 (defcustom message-kill-buffer-and-remove-file t
526 "*Non-nil means that the associated file will be removed before
527 removing the message buffer. However, it is treated as nil when the
528 command `message-mimic-kill-buffer' is used."
529 :group 'message-buffers
533 (defvar gnus-local-organization))
534 (defcustom message-user-organization
535 (or (and (boundp 'gnus-local-organization)
536 (stringp gnus-local-organization)
537 gnus-local-organization)
538 (getenv "ORGANIZATION")
540 "*String to be used as an Organization header.
541 If t, use `message-user-organization-file'."
542 :group 'message-headers
543 :type '(choice string
544 (const :tag "consult file" t)))
547 (defcustom message-user-organization-file "/usr/lib/news/organization"
548 "*Local news organization file."
550 :group 'message-headers)
552 (defcustom message-forward-start-separator
553 (concat (mime-make-tag "message" "rfc822") "\n")
554 "*Delimiter inserted before forwarded messages."
555 :group 'message-forwarding
558 (defcustom message-forward-end-separator
559 (concat (mime-make-tag "text" "plain") "\n")
560 "*Delimiter inserted after forwarded messages."
561 :group 'message-forwarding
564 (defcustom message-included-forward-headers
565 "^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:"
566 "*Regexp matching headers to be included in forwarded messages."
567 :group 'message-forwarding
570 (defcustom message-make-forward-subject-function
571 #'message-forward-subject-name-subject
572 "*List of functions called to generate subject headers for forwarded messages.
573 The subject generated by the previous function is passed into each
576 The provided functions are:
578 * `message-forward-subject-author-subject' Source of article (author or
579 newsgroup), in brackets followed by the subject
580 * `message-forward-subject-name-subject' Source of article (name of author
581 or newsgroup), in brackets followed by the subject
582 * `message-forward-subject-fwd' Subject of article with 'Fwd:' prepended
584 :group 'message-forwarding
585 :type '(radio (function-item message-forward-subject-author-subject)
586 (function-item message-forward-subject-fwd)
587 (function-item message-forward-subject-name-subject)
588 (repeat :tag "List of functions" function)))
590 (defcustom message-forward-as-mime t
591 "*Non-nil means forward messages as an inline/rfc822 MIME section.
592 Otherwise, directly inline the old message in the forwarded message."
594 :group 'message-forwarding
597 (defcustom message-forward-show-mml 'best
598 "*Non-nil means show forwarded messages as MML (decoded from MIME).
599 Otherwise, forwarded messages are unchanged.
600 Can also be the symbol `best' to indicate that MML should be
601 used, except when it is a bad idea to use MML. One example where
602 it is a bad idea is when forwarding a signed or encrypted
603 message, because converting MIME to MML would invalidate the
606 :group 'message-forwarding
607 :type '(choice (const :tag "use MML" t)
608 (const :tag "don't use MML " nil)
609 (const :tag "use MML when appropriate" best)))
611 (defcustom message-forward-before-signature t
612 "*Non-nil means put forwarded message before signature, else after."
613 :group 'message-forwarding
616 (defcustom message-wash-forwarded-subjects nil
617 "*Non-nil means try to remove as much cruft as possible from the subject.
618 Done before generating the new subject of a forward."
619 :group 'message-forwarding
622 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From "
623 "*All headers that match this regexp will be deleted when resending a message."
624 :group 'message-interface
627 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
628 "*All headers that match this regexp will be deleted when forwarding a message."
630 :group 'message-forwarding
631 :type '(choice (const :tag "None" nil)
634 (defcustom message-ignored-cited-headers "."
635 "*Delete these headers from the messages you yank."
636 :group 'message-insertion
639 (defcustom message-cite-prefix-regexp
640 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
641 "\\([ \t]*[-_.[:word:]]+>+\\|[ \t]*[]>|}+]\\)+"
642 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
643 (let ((old-table (syntax-table))
644 non-word-constituents)
645 (set-syntax-table text-mode-syntax-table)
646 (setq non-word-constituents
648 (if (string-match "\\w" "-") "" "-")
649 (if (string-match "\\w" "_") "" "_")
650 (if (string-match "\\w" ".") "" ".")))
651 (set-syntax-table old-table)
652 (if (equal non-word-constituents "")
653 "\\([ \t]*\\(\\w\\)+>+\\|[ \t]*[]>|}+]\\)+"
654 (concat "\\([ \t]*\\(\\w\\|["
655 non-word-constituents
656 "]\\)+>+\\|[ \t]*[]>|}+]\\)+"))))
657 "*Regexp matching the longest possible citation prefix on a line."
658 :group 'message-insertion
661 (defcustom message-cancel-message "I am canceling my own article.\n"
662 "Message to be inserted in the cancel message."
663 :group 'message-interface
666 ;; Useful to set in site-init.el
668 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
669 "Function to call to send the current buffer as mail.
670 The headers should be delimited by a line whose contents match the
671 variable `mail-header-separator'.
673 Valid values include `message-send-mail-with-sendmail' (the default),
674 `message-send-mail-with-mh', `message-send-mail-with-qmail',
675 `message-send-mail-with-smtp', `message-smtpmail-send-it',
676 `smtpmail-send-it' and `feedmail-send-it'.
678 See also `send-mail-function'."
679 :type '(radio (function-item message-send-mail-with-sendmail)
680 (function-item message-send-mail-with-mh)
681 (function-item message-send-mail-with-qmail)
682 (function-item message-send-mail-with-smtp)
683 (function-item message-smtpmail-send-it)
684 (function-item smtpmail-send-it)
685 (function-item feedmail-send-it)
686 (function :tag "Other"))
687 :group 'message-sending
688 :group 'message-mail)
690 ;; 1997-09-29 by MORIOKA Tomohiko
691 (defcustom message-send-news-function 'message-send-news-with-gnus
692 "Function to call to send the current buffer as news.
693 The headers should be delimited by a line whose contents match the
694 variable `mail-header-separator'."
695 :group 'message-sending
699 (defcustom message-reply-to-function nil
700 "If non-nil, function that should return a list of headers.
701 This function should pick out addresses from the To, Cc, and From headers
702 and respond with new To and Cc headers."
703 :group 'message-interface
704 :type '(choice function (const nil)))
706 (defcustom message-wide-reply-to-function nil
707 "If non-nil, function that should return a list of headers.
708 This function should pick out addresses from the To, Cc, and From headers
709 and respond with new To and Cc headers."
710 :group 'message-interface
711 :type '(choice function (const nil)))
713 (defcustom message-followup-to-function nil
714 "If non-nil, function that should return a list of headers.
715 This function should pick out addresses from the To, Cc, and From headers
716 and respond with new To and Cc headers."
717 :group 'message-interface
718 :type '(choice function (const nil)))
720 (defcustom message-use-followup-to 'ask
721 "*Specifies what to do with Followup-To header.
722 If nil, always ignore the header. If it is t, use its value, but
723 query before using the \"poster\" value. If it is the symbol `ask',
724 always query the user whether to use the value. If it is the symbol
725 `use', always use the value."
726 :group 'message-interface
727 :type '(choice (const :tag "ignore" nil)
728 (const :tag "use & query" t)
729 (const :tag "maybe" t)
730 (const :tag "always" use)
731 (const :tag "ask" ask)))
733 (defcustom message-use-mail-copies-to 'ask
734 "*Specifies what to do with Mail-Copies-To header.
735 If nil, always ignore the header. If it is t, use its value, but
736 query before using the value other than \"always\" or \"never\".
737 If it is the symbol `ask', always query the user whether to use
738 the value. If it is the symbol `use', always use the value."
739 :group 'message-interface
740 :type '(choice (const :tag "ignore" nil)
741 (const :tag "maybe" t)
742 (const :tag "always" use)
743 (const :tag "ask" ask)))
745 ;;; XXX: 'ask and 'use are not implemented yet.
746 (defcustom message-use-mail-reply-to 'ask
747 "*Specifies what to do with Mail-Reply-To/Reply-To header.
748 If nil, always ignore the header. If it is t or the symbol `use', use
749 its value. If it is the symbol `ask', always query the user whether to
750 use the value. Note that if \"Reply-To\" is marked as \"broken\", its value
752 :group 'message-interface
753 :type '(choice (const :tag "ignore" nil)
754 (const :tag "maybe" t)
755 (const :tag "always" use)
756 (const :tag "ask" ask)))
758 (defcustom message-use-mail-followup-to 'use
759 "*Specifies what to do with Mail-Followup-To header.
760 If nil, always ignore the header. If it is the symbol `ask', always
761 query the user whether to use the value. If it is t or the symbol
762 `use', always use the value."
763 :group 'message-interface
764 :type '(choice (const :tag "ignore" nil)
765 (const :tag "maybe" t)
766 (const :tag "always" use)
767 (const :tag "ask" ask)))
769 (defcustom message-subscribed-address-functions nil
770 "*Specifies functions for determining list subscription.
771 If nil, do not attempt to determine list subscription with functions.
772 If non-nil, this variable contains a list of functions which return
773 regular expressions to match lists. These functions can be used in
774 conjunction with `message-subscribed-regexps' and
775 `message-subscribed-addresses'."
776 :group 'message-interface
777 :type '(repeat sexp))
779 (defcustom message-subscribed-address-file nil
780 "*A file containing addresses the user is subscribed to.
781 If nil, do not look at any files to determine list subscriptions. If
782 non-nil, each line of this file should be a mailing list address."
783 :group 'message-interface
784 :type '(radio (file :format "%t: %v\n" :size 0)
787 (defcustom message-subscribed-addresses nil
788 "*Specifies a list of addresses the user is subscribed to.
789 If nil, do not use any predefined list subscriptions. This list of
790 addresses can be used in conjunction with
791 `message-subscribed-address-functions' and `message-subscribed-regexps'."
792 :group 'message-interface
793 :type '(repeat string))
795 (defcustom message-subscribed-regexps nil
796 "*Specifies a list of addresses the user is subscribed to.
797 If nil, do not use any predefined list subscriptions. This list of
798 regular expressions can be used in conjunction with
799 `message-subscribed-address-functions' and `message-subscribed-addresses'."
800 :group 'message-interface
801 :type '(repeat regexp))
803 (defcustom message-allow-no-recipients 'ask
804 "Specifies what to do when there are no recipients other than Gcc/Fcc.
805 If it is the symbol `always', the posting is allowed. If it is the
806 symbol `never', the posting is not allowed. If it is the symbol
807 `ask', you are prompted."
808 :group 'message-interface
809 :type '(choice (const always)
813 (defcustom message-sendmail-f-is-evil nil
814 "*Non-nil means don't add \"-f username\" to the sendmail command line.
815 Doing so would be even more evil than leaving it out."
816 :group 'message-sending
819 (defcustom message-sendmail-envelope-from nil
820 "*Envelope-from when sending mail with sendmail.
821 If this is nil, use `user-mail-address'. If it is the symbol
822 `header', use the From: header of the message."
823 :type '(choice (string :tag "From name")
824 (const :tag "Use From: header from message" header)
825 (const :tag "Use `user-mail-address'" nil))
826 :group 'message-sending)
828 ;; qmail-related stuff
829 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
830 "Location of the qmail-inject program."
831 :group 'message-sending
834 (defcustom message-qmail-inject-args nil
835 "Arguments passed to qmail-inject programs.
836 This should be a list of strings, one string for each argument. It
837 may also be a function.
839 For e.g., if you wish to set the envelope sender address so that bounces
840 go to the right place or to deal with listserv's usage of that address, you
841 might set this variable to '(\"-f\" \"you@some.where\")."
842 :group 'message-sending
843 :type '(choice (function)
846 (defvar message-cater-to-broken-inn t
847 "Non-nil means Gnus should not fold the `References' header.
848 Folding `References' makes ancient versions of INN create incorrect
852 (defvar gnus-post-method)
853 (defvar gnus-select-method))
854 (defcustom message-post-method
855 (cond ((and (boundp 'gnus-post-method)
856 (listp gnus-post-method)
859 ((boundp 'gnus-select-method)
862 "*Method used to post news.
863 Note that when posting from inside Gnus, for instance, this
864 variable isn't used."
866 :group 'message-sending
867 ;; This should be the `gnus-select-method' widget, but that might
868 ;; create a dependence to `gnus.el'.
871 ;; FIXME: This should be a temporary workaround until someone implements a
872 ;; proper solution. If a crash happens while replying, the auto-save file
873 ;; will *not* have a `References:' header if `message-generate-headers-first'
874 ;; is nil. See: http://article.gmane.org/gmane.emacs.gnus.general/51138
875 (defcustom message-generate-headers-first '(references)
876 "*If non-nil, generate all required headers before composing.
877 The variables `message-required-news-headers' and
878 `message-required-mail-headers' specify which headers to generate.
879 This can also be a list of headers that should be generated before
882 Note that the variable `message-deletable-headers' specifies headers which
883 are to be deleted and then re-generated before sending, so this variable
884 will not have a visible effect for those headers."
885 :group 'message-headers
886 :type '(choice (const :tag "None" nil)
887 (const :tag "References" '(references))
889 (repeat (sexp :tag "Header"))))
891 (defcustom message-setup-hook '(turn-on-mime-edit)
892 "Normal hook, run each time a new outgoing message is initialized.
893 The function `message-setup' runs this hook."
894 :group 'message-various
897 (defcustom message-cancel-hook nil
898 "Hook run when cancelling articles."
899 :group 'message-various
902 (defcustom message-signature-setup-hook nil
903 "Normal hook, run each time a new outgoing message is initialized.
904 It is run after the headers have been inserted and before
905 the signature is inserted."
906 :group 'message-various
909 (defcustom message-bounce-setup-hook nil
910 "Normal hook, run each time a re-sending bounced message is initialized.
911 The function `message-bounce' runs this hook."
912 :group 'message-various
915 (defcustom message-supersede-setup-hook nil
916 "Normal hook, run each time a supersede message is initialized.
917 The function `message-supersede' runs this hook."
918 :group 'message-various
921 (defcustom message-mode-hook nil
922 "Hook run in message mode buffers."
923 :group 'message-various
926 (defcustom message-header-hook '((lambda () (mime-encode-header-in-buffer t)))
927 "Hook run in a message mode buffer narrowed to the headers."
928 :group 'message-various
931 (defcustom message-header-setup-hook nil
932 "Hook called narrowed to the headers when setting up a message buffer."
933 :group 'message-various
936 (defcustom message-minibuffer-local-map
937 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
938 (set-keymap-parent map minibuffer-local-map)
940 "Keymap for `message-read-from-minibuffer'.")
943 (defcustom message-citation-line-function 'message-insert-citation-line
944 "*Function called to insert the \"Whomever writes:\" line.
946 Note that Gnus provides a feature where the reader can click on
947 `writes:' to hide the cited text. If you change this line too much,
948 people who read your message will have to change their Gnus
949 configuration. See the variable `gnus-cite-attribution-suffix'."
951 :group 'message-insertion)
954 (defcustom message-yank-prefix "> "
955 "*Prefix inserted on the lines of yanked messages.
956 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
957 See also `message-yank-cited-prefix'."
959 :group 'message-insertion)
961 (defcustom message-yank-add-new-references t
962 "Non-nil means new IDs will be added to \"References\" field when an
963 article is yanked by the command `message-yank-original' interactively.
964 If it is a symbol `message-id-only', only an ID from \"Message-ID\" field
965 is used, otherwise IDs extracted from \"References\", \"In-Reply-To\" and
966 \"Message-ID\" fields are used."
967 :type '(radio (const :tag "Do not add anything" nil)
968 (const :tag "From Message-Id, References and In-Reply-To fields" t)
969 (const :tag "From only Message-Id field." message-id-only))
970 :group 'message-insertion)
972 (defcustom message-list-references-add-position nil
973 "Integer value means position for adding to \"References\" field when
974 an article is yanked by the command `message-yank-original' interactively."
975 :type '(radio (const :tag "Add to last" nil)
976 (integer :tag "Position from last ID"))
977 :group 'message-insertion)
979 (defcustom message-yank-cited-prefix ">"
980 "*Prefix inserted on cited or empty lines of yanked messages.
981 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
982 See also `message-yank-prefix'."
984 :group 'message-insertion)
986 (defcustom message-indentation-spaces 3
987 "*Number of spaces to insert at the beginning of each cited line.
988 Used by `message-yank-original' via `message-yank-cite'."
989 :group 'message-insertion
993 (defcustom message-cite-function 'message-cite-original
994 "*Function for citing an original message.
995 Predefined functions include `message-cite-original' and
996 `message-cite-original-without-signature'.
997 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
998 :type '(radio (function-item message-cite-original)
999 (function-item message-cite-original-without-signature)
1000 (function-item mu-cite-original)
1001 (function-item sc-cite-original)
1002 (function :tag "Other"))
1003 :group 'message-insertion)
1006 (defcustom message-suspend-font-lock-when-citing nil
1007 "Non-nil means suspend font-lock'ing while citing an original message.
1008 Some lazy demand-driven fontification tools (or Emacs itself) have a
1009 bug that they often miss a buffer to be fontified. It will mostly
1010 occur when Emacs prompts user for any inputs in the minibuffer.
1011 Setting this option to non-nil may help you to avoid unpleasant errors
1012 even if it is an add-hoc expedient."
1014 :group 'message-insertion)
1017 (defcustom message-indent-citation-function 'message-indent-citation
1018 "*Function for modifying a citation just inserted in the mail buffer.
1019 This can also be a list of functions. Each function can find the
1020 citation between (point) and (mark t). And each function should leave
1021 point and mark around the citation text as modified."
1023 :group 'message-insertion)
1026 (defcustom message-signature t
1027 "*String to be inserted at the end of the message buffer.
1028 If t, the `message-signature-file' file will be inserted instead.
1029 If a function, the result from the function will be used instead.
1030 If a form, the result from the form will be used instead."
1032 :group 'message-insertion)
1035 (defcustom message-signature-file "~/.signature"
1036 "*Name of file containing the text inserted at end of message buffer.
1037 Ignored if the named file doesn't exist.
1038 If nil, don't insert a signature."
1039 :type '(choice file (const :tags "None" nil))
1040 :group 'message-insertion)
1043 (defcustom message-signature-insert-empty-line t
1044 "*If non-nil, insert an empty line before the signature separator."
1046 :group 'message-insertion)
1048 (defcustom message-distribution-function nil
1049 "*Function called to return a Distribution header."
1050 :group 'message-news
1051 :group 'message-headers
1052 :type '(choice function (const nil)))
1054 (defcustom message-expires 14
1055 "Number of days before your article expires."
1056 :group 'message-news
1057 :group 'message-headers
1058 :link '(custom-manual "(message)News Headers")
1061 (defcustom message-user-path nil
1062 "If nil, use the NNTP server name in the Path header.
1063 If stringp, use this; if non-nil, use no host name (user name only)."
1064 :group 'message-news
1065 :group 'message-headers
1066 :link '(custom-manual "(message)News Headers")
1067 :type '(choice (const :tag "nntp" nil)
1068 (string :tag "name")
1069 (sexp :tag "none" :format "%t" t)))
1071 (defvar message-reply-buffer nil)
1072 (defvar message-reply-headers nil
1073 "The headers of the current replied article.
1074 It is a vector of the following headers:
1075 \[number subject from date id references chars lines xref extra].")
1076 (defvar message-sent-message-via nil)
1077 (defvar message-checksum nil)
1078 (defvar message-send-actions nil
1079 "A list of actions to be performed upon successful sending of a message.")
1080 (defvar message-exit-actions nil
1081 "A list of actions to be performed upon exiting after sending a message.")
1082 (defvar message-kill-actions nil
1083 "A list of actions to be performed before killing a message buffer.")
1084 (defvar message-postpone-actions nil
1085 "A list of actions to be performed after postponing a message.")
1086 (defvar message-original-frame nil)
1087 (defvar message-parameter-alist nil)
1088 (defvar message-startup-parameter-alist nil)
1090 (define-widget 'message-header-lines 'text
1091 "All header lines must be LFD terminated."
1092 :format "%{%t%}:%n%v"
1093 :valid-regexp "^\\'"
1094 :error "All header lines must be newline terminated")
1096 (defcustom message-default-headers ""
1097 "*A string containing header lines to be inserted in outgoing messages.
1098 It is inserted before you edit the message, so you can edit or delete
1100 :group 'message-headers
1101 :type 'message-header-lines)
1103 (defcustom message-default-mail-headers ""
1104 "*A string of header lines to be inserted in outgoing mails."
1105 :group 'message-headers
1106 :group 'message-mail
1107 :type 'message-header-lines)
1109 (defcustom message-default-news-headers ""
1110 "*A string of header lines to be inserted in outgoing news articles."
1111 :group 'message-headers
1112 :group 'message-news
1113 :type 'message-header-lines)
1115 ;; Note: could use /usr/ucb/mail instead of sendmail;
1116 ;; options -t, and -v if not interactive.
1117 (defcustom message-mailer-swallows-blank-line
1118 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1119 system-configuration)
1120 (file-readable-p "/etc/sendmail.cf")
1121 (let ((buffer (get-buffer-create " *temp*")))
1125 (insert-file-contents "/etc/sendmail.cf")
1126 (goto-char (point-min))
1127 (let ((case-fold-search nil))
1128 (re-search-forward "^OR\\>" nil t)))
1129 (kill-buffer buffer))))
1130 ;; According to RFC822, "The field-name must be composed of printable
1131 ;; ASCII characters (i. e., characters that have decimal values between
1132 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1134 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1135 "*Set this non-nil if the system's mailer runs the header and body together.
1136 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1137 The value should be an expression to test whether the problem will
1139 :group 'message-sending
1142 ;;; XXX: This symbol is overloaded! See below.
1143 (defvar message-user-agent nil
1144 "String of the form of PRODUCT/VERSION. Used for User-Agent header field.")
1146 (static-when (boundp 'MULE)
1147 (require 'reporter));; `define-mail-user-agent' is here.
1150 (define-mail-user-agent 'message-user-agent
1151 'message-mail 'message-send-and-exit
1152 'message-kill-buffer 'message-send-hook)
1154 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
1155 "If non-nil, delete the deletable headers before feeding to mh.")
1157 (defvar message-send-method-alist
1158 '((news message-news-p message-send-via-news)
1159 (mail message-mail-p message-send-via-mail))
1160 "Alist of ways to send outgoing messages.
1161 Each element has the form
1163 \(TYPE PREDICATE FUNCTION)
1165 where TYPE is a symbol that names the method; PREDICATE is a function
1166 called without any parameters to determine whether the message is
1167 a message of type TYPE; and FUNCTION is a function to be called if
1168 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1171 (defcustom message-mail-alias-type 'abbrev
1172 "*What alias expansion type to use in Message buffers.
1173 The default is `abbrev', which uses mailabbrev. nil switches
1176 :link '(custom-manual "(message)Mail Aliases")
1177 :type '(choice (const :tag "Use Mailabbrev" abbrev)
1178 (const :tag "No expansion" nil)))
1180 (defcustom message-auto-save-directory
1181 (file-name-as-directory (nnheader-concat message-directory "drafts"))
1182 "*Directory where Message auto-saves buffers if Gnus isn't running.
1183 If nil, Message won't auto-save."
1184 :group 'message-buffers
1185 :type '(choice directory (const :tag "Don't auto-save" nil)))
1187 (defcustom message-default-charset
1188 (and (featurep 'xemacs) (not (featurep 'mule)) 'iso-8859-1)
1189 "Default charset used in non-MULE XEmacsen."
1194 (defcustom message-dont-reply-to-names
1195 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
1196 "*A regexp specifying addresses to prune when doing wide replies.
1197 A value of nil means exclude your own user name only."
1200 :type '(choice (const :tag "Yourself" nil)
1203 (defvar message-shoot-gnksa-feet nil
1204 "*A list of GNKSA feet you are allowed to shoot.
1205 Gnus gives you all the opportunity you could possibly want for
1206 shooting yourself in the foot. Also, Gnus allows you to shoot the
1207 feet of Good Net-Keeping Seal of Approval. The following are foot
1209 `empty-article' Allow you to post an empty article;
1210 `quoted-text-only' Allow you to post quoted text only;
1211 `multiple-copies' Allow you to post multiple copies;
1212 `cancel-messages' Allow you to cancel or supersede messages from
1213 your other email addresses.")
1215 (defsubst message-gnksa-enable-p (feature)
1216 (or (not (listp message-shoot-gnksa-feet))
1217 (memq feature message-shoot-gnksa-feet)))
1219 (defcustom message-hidden-headers nil
1220 "Regexp of headers to be hidden when composing new messages.
1221 This can also be a list of regexps to match headers. Or a list
1222 starting with `not' and followed by regexps."
1224 :type '(repeat regexp))
1226 ;;; Internal variables.
1227 ;;; Well, not really internal.
1229 (defvar message-mode-syntax-table
1230 (let ((table (copy-syntax-table text-mode-syntax-table)))
1231 (modify-syntax-entry ?% ". " table)
1232 (modify-syntax-entry ?> ". " table)
1233 (modify-syntax-entry ?< ". " table)
1235 "Syntax table used while in Message mode.")
1237 (defface message-header-to-face
1240 (:foreground "green2" :bold t))
1243 (:foreground "MidnightBlue" :bold t))
1245 (:bold t :italic t)))
1246 "Face used for displaying From headers."
1247 :group 'message-faces)
1249 (defface message-header-cc-face
1252 (:foreground "green4" :bold t))
1255 (:foreground "MidnightBlue"))
1258 "Face used for displaying Cc headers."
1259 :group 'message-faces)
1261 (defface message-header-subject-face
1264 (:foreground "green3"))
1267 (:foreground "navy blue" :bold t))
1270 "Face used for displaying subject headers."
1271 :group 'message-faces)
1273 (defface message-header-newsgroups-face
1276 (:foreground "yellow" :bold t :italic t))
1279 (:foreground "blue4" :bold t :italic t))
1281 (:bold t :italic t)))
1282 "Face used for displaying newsgroups headers."
1283 :group 'message-faces)
1285 (defface message-header-other-face
1288 (:foreground "#b00000"))
1291 (:foreground "steel blue"))
1293 (:bold t :italic t)))
1294 "Face used for displaying newsgroups headers."
1295 :group 'message-faces)
1297 (defface message-header-name-face
1300 (:foreground "DarkGreen"))
1303 (:foreground "cornflower blue"))
1306 "Face used for displaying header names."
1307 :group 'message-faces)
1309 (defface message-header-xheader-face
1312 (:foreground "blue"))
1315 (:foreground "blue"))
1318 "Face used for displaying X-Header headers."
1319 :group 'message-faces)
1321 (defface message-separator-face
1324 (:foreground "blue3"))
1327 (:foreground "brown"))
1330 "Face used for displaying the separator."
1331 :group 'message-faces)
1333 (defface message-cited-text-face
1336 (:foreground "red"))
1339 (:foreground "red"))
1342 "Face used for displaying cited text names."
1343 :group 'message-faces)
1345 (defface message-mml-face
1348 (:foreground "ForestGreen"))
1351 (:foreground "ForestGreen"))
1354 "Face used for displaying MML."
1355 :group 'message-faces)
1357 (defun message-font-lock-make-header-matcher (regexp)
1360 (let ((start (point)))
1363 (goto-char (point-min))
1364 (if (re-search-forward
1365 (concat "^" (regexp-quote mail-header-separator) "$")
1367 (setq limit (min limit (match-beginning 0))))
1369 (and (< start limit)
1370 (re-search-forward ,regexp limit t))))))
1371 (if (featurep 'bytecomp)
1375 (defvar message-font-lock-keywords
1376 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1377 `((,(message-font-lock-make-header-matcher
1378 (concat "^\\([Tt]o:\\)" content))
1379 (1 'message-header-name-face)
1380 (2 'message-header-to-face nil t))
1381 (,(message-font-lock-make-header-matcher
1382 (concat "^\\([GBF]?[Cc][Cc]:\\|[Rr]eply-[Tt]o:\\|"
1383 "[Mm]ail-[Cc]opies-[Tt]o:\\|"
1384 "[Mm]ail-[Rr]eply-[Tt]o:\\|"
1385 "[Mm]ail-[Ff]ollowup-[Tt]o:\\)" content))
1386 (1 'message-header-name-face)
1387 (2 'message-header-cc-face nil t))
1388 (,(message-font-lock-make-header-matcher
1389 (concat "^\\([Ss]ubject:\\)" content))
1390 (1 'message-header-name-face)
1391 (2 'message-header-subject-face nil t))
1392 (,(message-font-lock-make-header-matcher
1393 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content))
1394 (1 'message-header-name-face)
1395 (2 'message-header-newsgroups-face nil t))
1396 (,(message-font-lock-make-header-matcher
1397 (concat "^\\([A-Z][^: \n\t]+:\\)" content))
1398 (1 'message-header-name-face)
1399 (2 'message-header-other-face nil t))
1400 (,(message-font-lock-make-header-matcher
1401 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content))
1402 (1 'message-header-name-face)
1403 (2 'message-header-name-face))
1404 ,@(if (and mail-header-separator
1405 (not (equal mail-header-separator "")))
1406 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1407 1 'message-separator-face))
1410 (re-search-forward (concat "^\\("
1411 message-cite-prefix-regexp
1414 (0 'message-cited-text-face))
1415 (,mime-edit-tag-regexp
1416 (0 'message-mml-face))))
1417 "Additional expressions to highlight in Message mode.")
1419 ;; XEmacs does it like this. For Emacs, we have to set the
1420 ;; `font-lock-defaults' buffer-local variable.
1421 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
1423 (defvar message-face-alist
1424 '((bold . bold-region)
1425 (underline . underline-region)
1426 (default . (lambda (b e)
1428 (ununderline-region b e))))
1429 "Alist of mail and news faces for facemenu.
1430 The cdr of each entry is a function for applying the face to a region.")
1432 (defcustom message-send-hook nil
1433 "Hook run before sending messages.
1434 This hook is run quite early when sending."
1435 :group 'message-various
1436 :options '(ispell-message)
1439 (defcustom message-send-mail-hook nil
1440 "Hook run before sending mail messages.
1441 This hook is run very late -- just before the message is sent as
1443 :group 'message-various
1446 (defcustom message-send-news-hook nil
1447 "Hook run before sending news messages.
1448 This hook is run very late -- just before the message is sent as
1450 :group 'message-various
1453 (defcustom message-sent-hook nil
1454 "Hook run after sending messages."
1455 :group 'message-various
1458 (defcustom message-use-multi-frames nil
1459 "Make new frame when sending messages."
1460 :group 'message-frames
1463 (defcustom message-delete-frame-on-exit nil
1464 "Delete frame after sending messages."
1465 :group 'message-frames
1466 :type '(choice (const :tag "off" nil)
1467 (const :tag "always" t)
1468 (const :tag "ask" ask)))
1470 (defvar message-draft-coding-system
1471 nnheader-auto-save-coding-system
1472 "*Coding system to compose mail.
1473 If you'd like to make it possible to share draft files between XEmacs
1474 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1475 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1477 (defcustom message-send-mail-partially-limit 1000000
1478 "The limitation of messages sent as message/partial.
1479 The lower bound of message size in characters, beyond which the message
1480 should be sent in several parts. If it is nil, the size is unlimited."
1482 :group 'message-buffers
1483 :type '(choice (const :tag "unlimited" nil)
1486 (defcustom message-alternative-emails nil
1487 "A regexp to match the alternative email addresses.
1488 The first matched address (not primary one) is used in the From field."
1489 :group 'message-headers
1490 :type '(choice (const :tag "Always use primary" nil)
1493 (defcustom message-hierarchical-addresses nil
1494 "A list of hierarchical mail address definitions.
1496 Inside each entry, the first address is the \"top\" address, and
1497 subsequent addresses are subaddresses; this is used to indicate that
1498 mail sent to the first address will automatically be delivered to the
1499 subaddresses. So if the first address appears in the recipient list
1500 for a message, the subaddresses will be removed (if present) before
1501 the mail is sent. All addresses in this structure should be
1503 :group 'message-headers
1504 :type '(repeat (repeat string)))
1506 (defcustom message-mail-user-agent nil
1507 "Like `mail-user-agent'.
1508 Except if it is nil, use Gnus native MUA; if it is t, use
1510 :type '(radio (const :tag "Gnus native"
1513 (const :tag "`mail-user-agent'"
1516 (function-item :tag "Default Emacs mail"
1518 sendmail-user-agent)
1519 (function-item :tag "Emacs interface to MH"
1522 (function :tag "Other"))
1526 (defcustom message-wide-reply-confirm-recipients nil
1527 "Whether to confirm a wide reply to multiple email recipients.
1528 If this variable is nil, don't ask whether to reply to all recipients.
1529 If this variable is non-nil, pose the question \"Reply to all
1530 recipients?\" before a wide reply to multiple recipients. If the user
1531 answers yes, reply to all recipients as usual. If the user answers
1532 no, only reply back to the author."
1534 :group 'message-headers
1537 (defcustom message-user-fqdn nil
1538 "*Domain part of Messsage-Ids."
1539 :group 'message-headers
1540 :link '(custom-manual "(message)News Headers")
1541 :type '(radio (const :format "%v " nil)
1542 (string :format "FQDN: %v\n" :size 0)))
1544 (defcustom message-use-idna (and (condition-case nil (require 'idna)
1546 (mm-coding-system-p 'utf-8)
1547 (executable-find idna-program)
1549 "Whether to encode non-ASCII in domain names into ASCII according to IDNA."
1550 :group 'message-headers
1551 :type '(choice (const :tag "Ask" ask)
1552 (const :tag "Never" nil)
1553 (const :tag "Always" t)))
1555 ;;; Internal variables.
1557 (defvar message-sending-message "Sending...")
1558 (defvar message-buffer-list nil)
1559 (defvar message-this-is-news nil)
1560 (defvar message-this-is-mail nil)
1561 (defvar message-draft-article nil)
1562 (defvar message-mime-part nil)
1563 (defvar message-posting-charset nil)
1564 (defvar message-inserted-headers nil)
1566 ;; Byte-compiler warning
1568 (defvar gnus-active-hashtb)
1569 (defvar gnus-read-active-file))
1571 ;;; Regexp matching the delimiter of messages in UNIX mail format
1572 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1573 ;;; of rmail.el's rmail-unix-mail-delimiter.
1574 (defvar message-unix-mail-delimiter
1575 (let ((time-zone-regexp
1576 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1577 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1583 ;; Many things can happen to an RFC 822 mailbox before it is put into
1584 ;; a `From' line. The leading phrase can be stripped, e.g.
1585 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1586 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1587 ;; can be removed, e.g.
1588 ;; From: joe@y.z (Joe K
1590 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1593 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1594 ;; The mailbox can be removed or be replaced by white space, e.g.
1595 ;; From: "Joe User"{space}{tab}
1597 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1598 ;; where {space} and {tab} represent the Ascii space and tab characters.
1599 ;; We want to match the results of any of these manglings.
1600 ;; The following regexp rejects names whose first characters are
1601 ;; obviously bogus, but after that anything goes.
1602 "\\([^\0-\b\n-\r\^?].*\\)?"
1604 ;; The time the message was sent.
1605 "\\([^\0-\r \^?]+\\) +" ; day of the week
1606 "\\([^\0-\r \^?]+\\) +" ; month
1607 "\\([0-3]?[0-9]\\) +" ; day of month
1608 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1610 ;; Perhaps a time zone, specified by an abbreviation, or by a
1615 " \\([0-9][0-9]+\\) *"
1617 ;; On some systems the time zone can appear after the year, too.
1621 "\\(remote from .*\\)?"
1624 "Regexp matching the delimiter of messages in UNIX mail format.")
1626 (defvar message-unsent-separator
1627 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1628 "^ *---+ +Returned message +---+ *$\\|"
1629 "^Start of returned message$\\|"
1630 "^ *---+ +Original message +---+ *$\\|"
1631 "^ *--+ +begin message +--+ *$\\|"
1632 "^ *---+ +Original message follows +---+ *$\\|"
1633 "^ *---+ +Undelivered message follows +---+ *$\\|"
1634 "^|? *---+ +Message text follows: +---+ *|?$")
1635 "A regexp that matches the separator before the text of a failed message.")
1637 (defvar message-header-format-alist
1639 (To . message-fill-address)
1640 (Cc . message-fill-address)
1651 (References . message-shorten-references)
1653 "Alist used for formatting headers.")
1655 (defvar message-options nil
1656 "Some saved answers when sending message.")
1658 (defvar message-send-mail-real-function nil
1659 "Internal send mail function.")
1661 (defvar message-bogus-system-names "^localhost\\."
1662 "The regexp of bogus system names.")
1664 (defcustom message-valid-fqdn-regexp
1665 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1667 "\\([a-z][a-z]" ;; two letter country TDLs
1668 "\\|biz\\|com\\|edu\\|gov\\|int\\|mil\\|net\\|org"
1669 "\\|aero\\|coop\\|info\\|name\\|museum"
1670 "\\|arpa\\|pro\\|uucp\\|bitnet\\|bofh" ;; old style?
1672 "Regular expression that matches a valid FQDN."
1673 ;; see also: gnus-button-valid-fqdn-regexp
1674 :group 'message-headers
1678 (autoload 'message-setup-toolbar "messagexmas")
1679 (autoload 'mh-new-draft-name "mh-comp")
1680 (autoload 'mh-send-letter "mh-comp")
1681 (autoload 'gnus-point-at-eol "gnus-util")
1682 (autoload 'gnus-point-at-bol "gnus-util")
1683 (autoload 'gnus-output-to-rmail "gnus-util")
1684 (autoload 'gnus-output-to-mail "gnus-util")
1685 (autoload 'nndraft-request-associate-buffer "nndraft")
1686 (autoload 'nndraft-request-expire-articles "nndraft")
1687 (autoload 'gnus-open-server "gnus-int")
1688 (autoload 'gnus-request-post "gnus-int")
1689 (autoload 'gnus-copy-article-buffer "gnus-msg")
1690 (autoload 'gnus-alive-p "gnus-util")
1691 (autoload 'gnus-server-string "gnus")
1692 (autoload 'gnus-group-name-charset "gnus-group")
1693 (autoload 'gnus-group-name-decode "gnus-group")
1694 (autoload 'gnus-groups-from-server "gnus")
1695 (autoload 'rmail-output "rmailout")
1696 (autoload 'gnus-delay-article "gnus-delay")
1697 (autoload 'gnus-make-local-hook "gnus-util")
1698 (autoload 'mu-cite-original "mu-cite"))
1703 ;;; Utility functions.
1705 (defun message-eval-parameter (parameter)
1707 (if (symbolp parameter)
1708 (if (functionp parameter)
1714 (defsubst message-get-parameter (key &optional alist)
1716 (setq alist message-parameter-alist))
1717 (cdr (assq key alist)))
1719 (defmacro message-get-parameter-with-eval (key &optional alist)
1720 `(message-eval-parameter (message-get-parameter ,key ,alist)))
1722 (defmacro message-y-or-n-p (question show &rest text)
1723 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1724 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1726 (defmacro message-delete-line (&optional n)
1727 "Delete the current line (and the next N lines)."
1728 `(delete-region (progn (beginning-of-line) (point))
1729 (progn (forward-line ,(or n 1)) (point))))
1731 (defun message-mark-active-p ()
1732 "Non-nil means the mark and region are currently active in this buffer."
1735 (defun message-unquote-tokens (elems)
1736 "Remove double quotes (\") from strings in list ELEMS."
1737 (mapcar (lambda (item)
1738 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1739 (setq item (concat (match-string 1 item)
1740 (match-string 2 item))))
1744 (defun message-tokenize-header (header &optional separator)
1745 "Split HEADER into a list of header elements.
1746 SEPARATOR is a string of characters to be used as separators. \",\"
1747 is used by default."
1750 (let ((regexp (format "[%s]+" (or separator ",")))
1755 (set-buffer-multibyte t)
1757 (goto-char (point-min))
1762 (cond ((and (> (point) beg)
1764 (and (looking-at regexp)
1767 (push (buffer-substring beg (point)) elems)
1768 (setq beg (match-end 0)))
1769 ((eq (char-after) ?\")
1770 (setq quoted (not quoted)))
1771 ((and (eq (char-after) ?\()
1774 ((and (eq (char-after) ?\))
1777 (nreverse elems)))))
1779 (defun message-mail-file-mbox-p (file)
1780 "Say whether FILE looks like a Unix mbox file."
1781 (when (and (file-exists-p file)
1782 (file-readable-p file)
1783 (file-regular-p file))
1785 (nnheader-insert-file-contents file)
1786 (goto-char (point-min))
1787 (looking-at message-unix-mail-delimiter))))
1789 (defun message-fetch-field (header &optional not-all)
1790 "The same as `mail-fetch-field', only remove all newlines.
1791 The buffer is expected to be narrowed to just the header of the message;
1792 see `message-narrow-to-headers-or-head'."
1793 (let* ((inhibit-point-motion-hooks t)
1794 (case-fold-search t)
1795 (value (mail-fetch-field header nil (not not-all))))
1797 (while (string-match "\n[\t ]+" value)
1798 (setq value (replace-match " " t t value)))
1799 (set-text-properties 0 (length value) nil value)
1802 (defun message-field-value (header &optional not-all)
1803 "The same as `message-fetch-field', only narrow to the headers first."
1806 (message-narrow-to-headers-or-head)
1807 (message-fetch-field header not-all))))
1809 (defun message-narrow-to-field ()
1810 "Narrow the buffer to the header on the current line."
1816 (if (re-search-forward "^[^ \n\t]" nil t)
1821 (goto-char (point-min)))
1823 (defun message-add-header (&rest headers)
1824 "Add the HEADERS to the message header, skipping those already present."
1827 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1828 (error "Invalid header `%s'" (car headers)))
1829 (setq hclean (match-string 1 (car headers)))
1831 (message-narrow-to-headers)
1832 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1833 (goto-char (point-max))
1834 (if (string-match "\n$" (car headers))
1835 (insert (car headers))
1836 (insert (car headers) ?\n)))))
1837 (setq headers (cdr headers))))
1839 (defmacro message-with-reply-buffer (&rest forms)
1840 "Evaluate FORMS in the reply buffer, if it exists."
1841 `(let ((buffer (message-eval-parameter message-reply-buffer)))
1843 (buffer-name buffer))
1848 (put 'message-with-reply-buffer 'lisp-indent-function 0)
1849 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
1851 (defun message-fetch-reply-field (header)
1852 "Fetch field HEADER from the message we're replying to."
1853 (message-with-reply-buffer
1855 (mail-narrow-to-head)
1856 (message-fetch-field header))))
1858 (defun message-strip-list-identifiers (subject)
1859 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1860 (require 'gnus-sum) ; for gnus-list-identifiers
1861 (let ((regexp (if (stringp gnus-list-identifiers)
1862 gnus-list-identifiers
1863 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1864 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1865 " *\\)\\)+\\(Re: +\\)?\\)") subject)
1866 (concat (substring subject 0 (match-beginning 1))
1867 (or (match-string 3 subject)
1868 (match-string 5 subject))
1873 (defun message-strip-subject-re (subject)
1874 "Remove \"Re:\" from subject lines in string SUBJECT."
1875 (if (string-match message-subject-re-regexp subject)
1876 (substring subject (match-end 0))
1879 ;;; Start of functions adopted from `message-utils.el'.
1881 (defun message-strip-subject-trailing-was (subject)
1882 "Remove trailing \"(Was: <old subject>)\" from SUBJECT lines.
1883 Leading \"Re: \" is not stripped by this function. Use the function
1884 `message-strip-subject-re' for this."
1885 (let* ((query message-subject-trailing-was-query)
1890 message-subject-trailing-was-ask-regexp
1891 message-subject-trailing-was-regexp)
1894 (setq new (substring subject 0 (match-beginning 0))))
1895 (if (or (not found) (eq query nil))
1898 (if (message-y-or-n-p
1899 "Strip `(was: <old subject>)' in subject? " t
1901 "Strip `(was: <old subject>)' in subject "
1902 "and use the new one instead?\n\n"
1903 "Current subject is: \""
1905 "New subject would be: \""
1907 "See the variable `message-subject-trailing-was-query' "
1908 "to get rid of this query."
1913 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
1916 (defun message-change-subject (new-subject)
1917 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
1918 ;; <URL:http://www.landfield.com/usefor/drafts/draft-ietf-usefor-useage--1.02.unpaged>
1921 (read-from-minibuffer "New subject: ")))
1922 (cond ((and (not (or (null new-subject) ; new subject not empty
1923 (zerop (string-width new-subject))
1924 (string-match "^[ \t]*$" new-subject))))
1928 (message-narrow-to-headers)
1929 (message-fetch-field "Subject"))))
1930 (cond ((not old-subject)
1931 (error "No current subject"))
1934 (regexp-quote new-subject)
1936 old-subject)) ; yes, it really is a new subject
1937 ;; delete eventual Re: prefix
1939 (message-strip-subject-re old-subject))
1940 (message-goto-subject)
1941 (message-delete-line)
1942 (insert (concat "Subject: "
1945 old-subject ")\n")))))))))
1948 (defun message-mark-inserted-region (beg end)
1949 "Mark some region in the current article with enclosing tags.
1950 See `message-mark-insert-begin' and `message-mark-insert-end'."
1953 ;; add to the end of the region first, otherwise end would be invalid
1955 (insert message-mark-insert-end)
1957 (insert message-mark-insert-begin)))
1960 (defun message-mark-insert-file (file)
1961 "Insert FILE at point, marking it with enclosing tags.
1962 See `message-mark-insert-begin' and `message-mark-insert-end'."
1963 (interactive "fFile to insert: ")
1964 ;; reverse insertion to get correct result.
1966 (insert message-mark-insert-end)
1968 (insert-file-contents file)
1970 (insert message-mark-insert-begin)))
1973 (defun message-add-archive-header ()
1974 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
1975 The note can be customized using `message-archive-note'. When called with a
1976 prefix argument, ask for a text to insert. If you don't want the note in the
1977 body, set `message-archive-note' to nil."
1979 (if current-prefix-arg
1980 (setq message-archive-note
1981 (read-from-minibuffer "Reason for No-Archive: "
1982 (cons message-archive-note 0))))
1984 (if (message-goto-signature)
1985 (re-search-backward message-signature-separator))
1986 (when message-archive-note
1987 (insert message-archive-note)
1989 (message-add-header message-archive-header)
1990 (message-sort-headers)))
1993 (defun message-cross-post-followup-to-header (target-group)
1994 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
1995 With prefix-argument just set Follow-Up, don't cross-post."
1997 (list ; Completion based on Gnus
1998 (completing-read "Followup To: "
1999 (if (boundp 'gnus-newsrc-alist)
2001 nil nil '("poster" . 0)
2002 (if (boundp 'gnus-group-history)
2003 'gnus-group-history))))
2004 (message-remove-header "Follow[Uu]p-[Tt]o" t)
2005 (message-goto-newsgroups)
2007 ;; if we already did a crosspost before, kill old target
2008 (if (and message-cross-post-old-target
2010 (regexp-quote (concat "," message-cross-post-old-target))
2013 ;; unless (followup is to poster or user explicitly asked not
2014 ;; to cross-post, or target-group is already in Newsgroups)
2015 ;; add target-group to Newsgroups line.
2017 ;; def: cross-post, req:no
2018 (and message-cross-post-default (not current-prefix-arg))
2019 ;; def: no-cross-post, req:yes
2020 (and (not message-cross-post-default) current-prefix-arg))
2021 (not (string-match "poster" target-group))
2022 (not (string-match (regexp-quote target-group)
2023 (message-fetch-field "Newsgroups"))))
2025 (insert (concat "," target-group))))
2026 (end-of-line) ; ensure Followup: comes after Newsgroups:
2027 ;; unless new followup would be identical to Newsgroups line
2028 ;; make a new Followup-To line
2029 (if (not (string-match (concat "^[ \t]*"
2032 (message-fetch-field "Newsgroups")))
2033 (insert (concat "\nFollowup-To: " target-group)))
2034 (setq message-cross-post-old-target target-group))
2037 (defun message-cross-post-insert-note (target-group cross-post in-old
2039 "Insert a in message body note about a set Followup or Crosspost.
2040 If there have been previous notes, delete them. TARGET-GROUP specifies the
2041 group to Followup-To. When CROSS-POST is t, insert note about
2042 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
2043 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
2044 been made to before the user asked for a Crosspost."
2045 ;; start scanning body for previous uses
2046 (message-goto-signature)
2047 (let ((head (re-search-backward
2048 (concat "^" mail-header-separator)
2049 nil t))) ; just search in body
2050 (message-goto-signature)
2051 (while (re-search-backward
2052 (concat "^" (regexp-quote message-cross-post-note) ".*")
2054 (message-delete-line))
2055 (message-goto-signature)
2056 (while (re-search-backward
2057 (concat "^" (regexp-quote message-followup-to-note) ".*")
2059 (message-delete-line))
2061 (if (message-goto-signature)
2062 (re-search-backward message-signature-separator))
2065 (string-match "^[ \t]*poster[ \t]*$" target-group))
2066 (insert (concat message-followup-to-note target-group "\n"))
2067 (insert (concat message-cross-post-note target-group "\n")))))
2070 (defun message-cross-post-followup-to (target-group)
2071 "Crossposts message and set Followup-To to TARGET-GROUP.
2072 With prefix-argument just set Follow-Up, don't cross-post."
2074 (list ; Completion based on Gnus
2075 (completing-read "Followup To: "
2076 (if (boundp 'gnus-newsrc-alist)
2078 nil nil '("poster" . 0)
2079 (if (boundp 'gnus-group-history)
2080 'gnus-group-history))))
2081 (cond ((not (or (null target-group) ; new subject not empty
2082 (zerop (string-width target-group))
2083 (string-match "^[ \t]*$" target-group)))
2085 (let* ((old-groups (message-fetch-field "Newsgroups"))
2086 (in-old (string-match
2087 (regexp-quote target-group)
2088 (or old-groups ""))))
2089 ;; check whether target exactly matches old Newsgroups
2090 (cond ((not old-groups)
2091 (error "No current newsgroup"))
2095 (regexp-quote target-group)
2098 ;; yes, Newsgroups line must change
2099 (message-cross-post-followup-to-header target-group)
2100 ;; insert note whether we do cross-post or followup-to
2101 (funcall message-cross-post-note-function
2103 (if (or (and message-cross-post-default
2104 (not current-prefix-arg))
2105 (and (not message-cross-post-default)
2106 current-prefix-arg)) t)
2107 in-old old-groups))))))))
2109 ;;; Reduce To: to Cc: or Bcc: header
2112 (defun message-reduce-to-to-cc ()
2113 "Replace contents of To: header with contents of Cc: or Bcc: header."
2116 (save-restriction (message-narrow-to-headers)
2117 (message-fetch-field "cc")))
2119 (if (and (not cc-content)
2122 (message-narrow-to-headers)
2123 (message-fetch-field "bcc"))))
2128 (message-delete-line)
2129 (insert (concat "To: " cc-content "\n"))
2131 (message-narrow-to-headers)
2132 (message-remove-header (if bcc
2136 ;;; End of functions adopted from `message-utils.el'.
2138 (defun message-remove-header (header &optional is-regexp first reverse)
2139 "Remove HEADER in the narrowed buffer.
2140 If IS-REGEXP, HEADER is a regular expression.
2141 If FIRST, only remove the first instance of the header.
2142 Return the number of headers removed."
2143 (goto-char (point-min))
2144 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
2146 (case-fold-search t)
2148 (while (and (not (eobp))
2151 (not (looking-at regexp))
2152 (looking-at regexp))
2159 ;; There might be a continuation header, so we have to search
2160 ;; until we find a new non-continuation line.
2163 (if (re-search-forward "^[^ \t]" nil t)
2164 (goto-char (match-beginning 0))
2167 (if (re-search-forward "^[^ \t]" nil t)
2168 (goto-char (match-beginning 0))
2169 (goto-char (point-max)))))
2172 (defun message-remove-first-header (header)
2173 "Remove the first instance of HEADER if there is more than one."
2175 (regexp (concat "^" (regexp-quote header) ":")))
2177 (goto-char (point-min))
2178 (while (re-search-forward regexp nil t)
2181 (message-remove-header header nil t)
2184 (defun message-narrow-to-headers ()
2185 "Narrow the buffer to the head of the message."
2188 (goto-char (point-min))
2189 (if (re-search-forward
2190 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2193 (goto-char (point-min)))
2195 (defun message-narrow-to-head-1 ()
2196 "Like `message-narrow-to-head'. Don't widen."
2198 (goto-char (point-min))
2199 (if (search-forward "\n\n" nil 1)
2202 (goto-char (point-min)))
2204 (defun message-narrow-to-head ()
2205 "Narrow the buffer to the head of the message.
2206 Point is left at the beginning of the narrowed-to region."
2208 (message-narrow-to-head-1))
2210 (defun message-narrow-to-headers-or-head ()
2211 "Narrow the buffer to the head of the message."
2214 (goto-char (point-min))
2217 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2218 (match-beginning 0))
2219 ((search-forward "\n\n" nil t)
2223 (goto-char (point-min)))
2225 (defun message-news-p ()
2226 "Say whether the current buffer contains a news message."
2227 (and (not message-this-is-mail)
2228 (or message-this-is-news
2231 (message-narrow-to-headers)
2232 (and (message-fetch-field "newsgroups")
2233 (not (message-fetch-field "posted-to"))))))))
2235 (defun message-mail-p ()
2236 "Say whether the current buffer contains a mail message."
2237 (and (not message-this-is-news)
2238 (or message-this-is-mail
2241 (message-narrow-to-headers)
2242 (or (message-fetch-field "to")
2243 (message-fetch-field "cc")
2244 (message-fetch-field "bcc")))))))
2246 (defun message-subscribed-p ()
2247 "Say whether we need to insert a MFT header."
2248 (or message-subscribed-regexps
2249 message-subscribed-addresses
2250 message-subscribed-address-file
2251 message-subscribed-address-functions))
2253 (defun message-next-header ()
2254 "Go to the beginning of the next header."
2256 (or (eobp) (forward-char 1))
2257 (not (if (re-search-forward "^[^ \t]" nil t)
2259 (goto-char (point-max)))))
2261 (defun message-sort-headers-1 ()
2262 "Sort the buffer as headers using `message-rank' text props."
2263 (goto-char (point-min))
2266 nil 'message-next-header
2268 (message-next-header)
2272 (or (get-text-property (point) 'message-rank)
2275 (defun message-sort-headers ()
2276 "Sort the headers of the current message according to `message-header-format-alist'."
2280 (let ((max (1+ (length message-header-format-alist)))
2282 (message-narrow-to-headers)
2283 (while (re-search-forward "^[^ \n]+:" nil t)
2285 (match-beginning 0) (1+ (match-beginning 0))
2287 (if (setq rank (length (memq (assq (intern (buffer-substring
2289 (1- (match-end 0))))
2290 message-header-format-alist)
2291 message-header-format-alist)))
2294 (message-sort-headers-1))))
2304 (defvar message-mode-map nil)
2306 (unless message-mode-map
2307 (setq message-mode-map (make-keymap))
2308 (set-keymap-parent message-mode-map text-mode-map)
2309 (define-key message-mode-map "\C-c?" 'describe-mode)
2311 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
2312 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
2313 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
2314 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
2315 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
2316 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2317 ;; (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2318 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-mail-reply-to)
2319 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2320 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2321 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2322 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2323 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2324 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2325 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2326 (define-key message-mode-map "\C-c\C-f\C-i"
2327 'message-insert-or-toggle-importance)
2328 (define-key message-mode-map "\C-c\C-f\C-a"
2329 'message-generate-unsubscribed-mail-followup-to)
2331 ;; modify headers (and insert notes in body)
2332 (define-key message-mode-map "\C-c\C-fs" 'message-change-subject)
2334 (define-key message-mode-map "\C-c\C-fx" 'message-cross-post-followup-to)
2335 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2336 (define-key message-mode-map "\C-c\C-ft" 'message-reduce-to-to-cc)
2337 (define-key message-mode-map "\C-c\C-fa" 'message-add-archive-header)
2338 ;; mark inserted text
2339 (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2340 (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2342 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2343 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2344 (define-key message-mode-map "\C-c\C-fc" 'message-goto-mail-copies-to)
2346 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2347 (define-key message-mode-map "\C-c\C-fw" 'message-insert-wide-reply)
2348 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2349 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2351 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2352 (define-key message-mode-map "\C-c\M-n"
2353 'message-insert-disposition-notification-to)
2355 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2356 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2357 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2358 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2359 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2360 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2361 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2362 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2364 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2365 (define-key message-mode-map "\C-c\C-s" 'message-send)
2366 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2367 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2368 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2370 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2371 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2372 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2373 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2374 ;;(define-key message-mode-map "\M-q" 'message-fill-paragraph)
2375 (define-key message-mode-map [remap split-line] 'message-split-line)
2377 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2378 (define-key message-mode-map "\t" 'message-tab)
2379 (define-key message-mode-map "\M-;" 'comment-region)
2381 (define-key message-mode-map "\C-xk" 'message-mimic-kill-buffer))
2384 message-mode-menu message-mode-map "Message Menu."
2386 ["Yank Original" message-yank-original t]
2387 ["Fill Yanked Message" message-fill-yanked-message t]
2388 ["Insert Signature" message-insert-signature t]
2389 ["Caesar (rot13) Message" message-caesar-buffer-body t]
2390 ["Caesar (rot13) Region" message-caesar-region (message-mark-active-p)]
2391 ["Elide Region" message-elide-region
2392 :active (message-mark-active-p)
2393 ,@(if (featurep 'xemacs) nil
2394 '(:help "Replace text in region with an ellipsis"))]
2395 ["Delete Outside Region" message-delete-not-region
2396 :active (message-mark-active-p)
2397 ,@(if (featurep 'xemacs) nil
2398 '(:help "Delete all quoted text outside region"))]
2399 ["Kill To Signature" message-kill-to-signature t]
2400 ["Newline and Reformat" message-newline-and-reformat t]
2401 ["Rename buffer" message-rename-buffer t]
2402 ["Spellcheck" ispell-message
2403 ,@(if (featurep 'xemacs) '(t)
2404 '(:help "Spellcheck this message"))]
2405 ["Attach file as MIME" mime-edit-insert-file
2406 ,@(if (featurep 'xemacs) '(t)
2407 '(:help "Attach a file at point"))]
2409 ["Insert Region Marked" message-mark-inserted-region
2410 :active (message-mark-active-p)
2411 ,@(if (featurep 'xemacs) nil
2412 '(:help "Mark region with enclosing tags"))]
2413 ["Insert File Marked..." message-mark-insert-file
2414 ,@(if (featurep 'xemacs) '(t)
2415 '(:help "Insert file at point marked with enclosing tags"))]
2417 ["Send Message" message-send-and-exit
2418 ,@(if (featurep 'xemacs) '(t)
2419 '(:help "Send this message"))]
2420 ["Postpone Message" message-dont-send
2421 ,@(if (featurep 'xemacs) '(t)
2422 '(:help "File this draft message and exit"))]
2423 ["Send at Specific Time..." gnus-delay-article
2424 ,@(if (featurep 'xemacs) '(t)
2425 '(:help "Ask, then arrange to send message at that time"))]
2426 ["Kill Message" message-kill-buffer
2427 ,@(if (featurep 'xemacs) '(t)
2428 '(:help "Delete this message without sending"))]))
2431 message-mode-field-menu message-mode-map ""
2433 ["To" message-goto-to t]
2434 ["From" message-goto-from t]
2435 ["Subject" message-goto-subject t]
2436 ["Change subject..." message-change-subject t]
2437 ["Cc" message-goto-cc t]
2438 ["Bcc" message-goto-bcc t]
2439 ["Fcc" message-goto-fcc t]
2440 ["Reply-To" message-goto-reply-to t]
2441 ["Flag As Important" message-insert-importance-high
2442 ,@(if (featurep 'xemacs) '(t)
2443 '(:help "Mark this message as important"))]
2444 ["Flag As Unimportant" message-insert-importance-low
2445 ,@(if (featurep 'xemacs) '(t)
2446 '(:help "Mark this message as unimportant"))]
2448 message-insert-disposition-notification-to
2449 ,@(if (featurep 'xemacs) '(t)
2450 '(:help "Request a receipt notification"))]
2452 ;; (typical) news stuff
2453 ["Summary" message-goto-summary t]
2454 ["Keywords" message-goto-keywords t]
2455 ["Newsgroups" message-goto-newsgroups t]
2456 ["Fetch Newsgroups" message-insert-newsgroups t]
2457 ["Followup-To" message-goto-followup-to t]
2458 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2459 ["Crosspost / Followup-To..." message-cross-post-followup-to t]
2460 ["Distribution" message-goto-distribution t]
2461 ["X-No-Archive:" message-add-archive-header t ]
2463 ;; (typical) mailing-lists stuff
2464 ["Fetch To" message-insert-to
2465 ,@(if (featurep 'xemacs) '(t)
2466 '(:help "Insert a To header that points to the author."))]
2467 ["Fetch To and Cc" message-insert-wide-reply
2468 ,@(if (featurep 'xemacs) '(t)
2470 "Insert To and Cc headers as if you were doing a wide reply."))]
2472 ["Send to list only" message-to-list-only t]
2473 ["Mail-Followup-To" message-goto-mail-followup-to t]
2474 ["Mail-Reply-To" message-goto-mail-reply-to t]
2475 ["Mail-Copies-To" message-goto-mail-copies-to t]
2476 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2477 ,@(if (featurep 'xemacs) '(t)
2478 '(:help "Insert a reasonable `Mail-Followup-To:' header."))]
2479 ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2481 ["Sort Headers" message-sort-headers t]
2482 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t]
2483 ["Goto Body" message-goto-body t]
2484 ["Goto Signature" message-goto-signature t]))
2486 (defvar message-tool-bar-map nil)
2489 (defvar facemenu-add-face-function)
2490 (defvar facemenu-remove-face-function))
2492 ;;; Forbidden properties
2494 ;; We use `after-change-functions' to keep special text properties
2495 ;; that interfer with the normal function of message mode out of the
2498 (defcustom message-strip-special-text-properties t
2499 "Strip special properties from the message buffer.
2501 Emacs has a number of special text properties which can break message
2502 composing in various ways. If this option is set, message will strip
2503 these properties from the message composition buffer. However, some
2504 packages requires these properties to be present in order to work.
2505 If you use one of these packages, turn this option off, and hope the
2506 message composition doesn't break too bad."
2507 :group 'message-various
2510 (defconst message-forbidden-properties
2511 ;; No reason this should be clutter up customize. We make it a
2512 ;; property list (rather than a list of property symbols), to be
2513 ;; directly useful for `remove-text-properties'.
2514 '(field nil read-only nil invisible nil intangible nil
2515 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2516 insert-behind-hooks nil point-entered nil point-left nil)
2517 ;; Other special properties:
2518 ;; category, face, display: probably doesn't do any harm.
2519 ;; fontified: is used by font-lock.
2520 ;; syntax-table, local-map: I dunno.
2521 ;; We need to add XEmacs names to the list.
2522 "Property list of with properties.forbidden in message buffers.
2523 The values of the properties are ignored, only the property names are used.")
2525 (defun message-tamago-not-in-use-p (pos)
2526 "Return t when tamago version 4 is not in use at the cursor position.
2527 Tamago version 4 is a popular input method for writing Japanese text.
2528 It uses the properties `intangible', `invisible', `modification-hooks'
2529 and `read-only' when translating ascii or kana text to kanji text.
2530 These properties are essential to work, so we should never strip them."
2531 (not (and (boundp 'egg-modefull-mode)
2532 (symbol-value 'egg-modefull-mode)
2533 (or (memq (get-text-property pos 'intangible)
2534 '(its-part-1 its-part-2))
2535 (get-text-property pos 'egg-end)
2536 (get-text-property pos 'egg-lang)
2537 (get-text-property pos 'egg-start)))))
2539 (defun message-strip-forbidden-properties (begin end &optional old-length)
2540 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2541 This function is intended to be called from `after-change-functions'.
2542 See also `message-forbidden-properties'."
2543 (when (and message-strip-special-text-properties
2544 (message-tamago-not-in-use-p begin)
2545 ;; Check whether the invisible MIME part is not inserted.
2546 (not (text-property-any begin end 'mime-edit-invisible t)))
2547 (while (not (= begin end))
2548 (when (not (get-text-property begin 'message-hidden))
2549 (remove-text-properties begin (1+ begin)
2550 message-forbidden-properties))
2554 (define-derived-mode message-mode text-mode "Message"
2555 "Major mode for editing mail and news to be sent.
2556 Like Text Mode but with these additional commands:\\<message-mode-map>
2557 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2558 C-c C-d Postpone sending the message C-c C-k Kill the message
2559 C-c C-f move to a header field (and create it if there isn't):
2560 C-c C-f C-t move to To C-c C-f C-s move to Subject
2561 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2562 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2563 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2564 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2565 C-c C-f C-o move to From (\"Originator\")
2566 C-c C-f C-f move to Followup-To
2567 C-c C-f C-m move to Mail-Followup-To
2568 C-c C-f c move to Mail-Copies-To
2569 C-c C-f C-i cycle through Importance values
2570 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2571 C-c C-f x crossposting with FollowUp-To header and note in body
2572 C-c C-f t replace To: header with contents of Cc: or Bcc:
2573 C-c C-f a Insert X-No-Archive: header and a note in the body
2574 C-c C-t `message-insert-to' (add a To header to a news followup)
2575 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2576 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2577 C-c C-b `message-goto-body' (move to beginning of message text).
2578 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2579 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2580 C-c C-y `message-yank-original' (insert current message, if any).
2581 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2582 C-c C-e `message-elide-region' (elide the text between point and mark).
2583 C-c C-v `message-delete-not-region' (remove the text outside the region).
2584 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2585 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2586 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2587 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2588 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2589 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2590 M-RET `message-newline-and-reformat' (break the line and reformat)."
2591 (setq local-abbrev-table text-mode-abbrev-table)
2592 (set (make-local-variable 'message-reply-buffer) nil)
2593 (set (make-local-variable 'message-inserted-headers) nil)
2594 (set (make-local-variable 'message-send-actions) nil)
2595 (set (make-local-variable 'message-exit-actions) nil)
2596 (set (make-local-variable 'message-kill-actions) nil)
2597 (set (make-local-variable 'message-postpone-actions) nil)
2598 (set (make-local-variable 'message-draft-article) nil)
2599 (setq buffer-offer-save t)
2600 (set (make-local-variable 'facemenu-add-face-function)
2602 (let ((face-fun (cdr (assq face message-face-alist))))
2604 (funcall face-fun (point) end)
2605 (error "Face %s not configured for %s mode" face mode-name)))
2607 (set (make-local-variable 'facemenu-remove-face-function) t)
2608 (set (make-local-variable 'message-reply-headers) nil)
2609 (make-local-variable 'message-user-agent)
2610 (make-local-variable 'message-post-method)
2611 (set (make-local-variable 'message-sent-message-via) nil)
2612 (set (make-local-variable 'message-checksum) nil)
2613 (make-local-variable 'message-parameter-alist)
2614 (setq message-parameter-alist
2615 (copy-sequence message-startup-parameter-alist))
2616 (message-setup-fill-variables)
2618 (make-local-variable 'paragraph-separate)
2619 (format "\\(%s\\)\\|\\(%s\\)"
2621 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
2622 ;; Allow using comment commands to add/remove quoting.
2623 (set (make-local-variable 'comment-start) message-yank-prefix)
2624 (if (featurep 'xemacs)
2625 (message-setup-toolbar)
2626 (set (make-local-variable 'font-lock-defaults)
2627 '(message-font-lock-keywords t))
2628 (if (boundp 'tool-bar-map)
2629 (set (make-local-variable 'tool-bar-map) (message-tool-bar-map))))
2630 (easy-menu-add message-mode-menu message-mode-map)
2631 (easy-menu-add message-mode-field-menu message-mode-map)
2632 (gnus-make-local-hook 'after-change-functions)
2633 ;; Mmmm... Forbidden properties...
2634 (add-hook 'after-change-functions 'message-strip-forbidden-properties
2636 ;; Allow mail alias things.
2637 (when (eq message-mail-alias-type 'abbrev)
2638 (if (fboundp 'mail-abbrevs-setup)
2639 (mail-abbrevs-setup)
2640 (if (fboundp 'mail-aliases-setup) ; warning avoidance
2641 (mail-aliases-setup))))
2642 (unless buffer-file-name
2643 (message-set-auto-save-file-name))
2644 (set (make-local-variable 'indent-tabs-mode) nil)) ;No tabs for indentation.
2646 (defun message-setup-fill-variables ()
2647 "Setup message fill variables."
2648 (set (make-local-variable 'fill-paragraph-function)
2649 'message-fill-paragraph)
2650 (make-local-variable 'paragraph-separate)
2651 (make-local-variable 'paragraph-start)
2652 (make-local-variable 'adaptive-fill-regexp)
2653 (unless (boundp 'adaptive-fill-first-line-regexp)
2654 (setq adaptive-fill-first-line-regexp nil))
2655 (make-local-variable 'adaptive-fill-first-line-regexp)
2656 (let ((quote-prefix-regexp
2657 ;; User should change message-cite-prefix-regexp if
2658 ;; message-yank-prefix is set to an abnormal value.
2659 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
2660 (setq paragraph-start
2662 (regexp-quote mail-header-separator) "$\\|"
2663 "[ \t]*$\\|" ; blank lines
2664 "-- $\\|" ; signature delimiter
2665 "---+$\\|" ; delimiters for forwarded messages
2666 page-delimiter "$\\|" ; spoiler warnings
2667 ".*wrote:$\\|" ; attribution lines
2668 quote-prefix-regexp "$")) ; empty lines in quoted text
2669 (setq paragraph-separate paragraph-start)
2670 (setq adaptive-fill-regexp
2671 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
2672 (setq adaptive-fill-first-line-regexp
2673 (concat quote-prefix-regexp "\\|"
2674 adaptive-fill-first-line-regexp)))
2675 (make-local-variable 'auto-fill-inhibit-regexp)
2676 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2677 (setq auto-fill-inhibit-regexp nil)
2678 (make-local-variable 'normal-auto-fill-function)
2679 (setq normal-auto-fill-function 'message-do-auto-fill)
2680 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2681 ;; In that case, ensure that it uses the right function. The real
2682 ;; solution would be not to use `define-derived-mode', and run
2683 ;; `text-mode-hook' ourself at the end of the mode.
2684 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2685 (when auto-fill-function
2686 (setq auto-fill-function normal-auto-fill-function)))
2691 ;;; Message mode commands
2694 ;;; Movement commands
2696 (defun message-goto-to ()
2697 "Move point to the To header."
2699 (message-position-on-field "To"))
2701 (defun message-goto-from ()
2702 "Move point to the From header."
2704 (message-position-on-field "From"))
2706 (defun message-goto-subject ()
2707 "Move point to the Subject header."
2709 (message-position-on-field "Subject"))
2711 (defun message-goto-cc ()
2712 "Move point to the Cc header."
2714 (message-position-on-field "Cc" "To"))
2716 (defun message-goto-bcc ()
2717 "Move point to the Bcc header."
2719 (message-position-on-field "Bcc" "Cc" "To"))
2721 (defun message-goto-fcc ()
2722 "Move point to the Fcc header."
2724 (message-position-on-field "Fcc" "To" "Newsgroups"))
2726 (defun message-goto-reply-to ()
2727 "Move point to the Reply-To header."
2729 (message-position-on-field "Reply-To" "Subject"))
2731 (defun message-goto-mail-reply-to ()
2732 "Move point to the Mail-Reply-To header."
2734 (message-position-on-field "Mail-Reply-To" "Subject"))
2736 (defun message-goto-mail-copies-to ()
2737 "Move point to the Mail-Copies-To header. If the header is newly created,
2738 a string \"never\" is inserted in default."
2740 (unless (message-position-on-field "Mail-Copies-To" "Subject")
2744 (defun message-goto-newsgroups ()
2745 "Move point to the Newsgroups header."
2747 (message-position-on-field "Newsgroups"))
2749 (defun message-goto-distribution ()
2750 "Move point to the Distribution header."
2752 (message-position-on-field "Distribution"))
2754 (defun message-goto-followup-to ()
2755 "Move point to the Followup-To header."
2757 (message-position-on-field "Followup-To" "Newsgroups"))
2759 (defun message-goto-mail-followup-to ()
2760 "Move point to the Mail-Followup-To header. If the header is newly created
2761 and To field contains only one address, the address is inserted in default."
2763 (unless (message-position-on-field "Mail-Followup-To" "Subject")
2764 (let ((start (point))
2767 (message-narrow-to-headers)
2768 (setq addresses (split-string (mail-strip-quoted-names
2769 (or (std11-fetch-field "to") ""))
2771 (when (eq 1 (length addresses))
2773 (insert (car addresses))
2774 (goto-char start))))))
2776 (defun message-goto-keywords ()
2777 "Move point to the Keywords header."
2779 (message-position-on-field "Keywords" "Subject"))
2781 (defun message-goto-summary ()
2782 "Move point to the Summary header."
2784 (message-position-on-field "Summary" "Subject"))
2786 (defun message-goto-body (&optional interactivep)
2787 "Move point to the beginning of the message body."
2788 (interactive (list t))
2789 (when (and interactivep
2790 (looking-at "[ \t]*\n"))
2792 (goto-char (point-min))
2793 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
2794 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
2796 (defun message-goto-eoh ()
2797 "Move point to the end of the headers."
2802 (defun message-goto-signature ()
2803 "Move point to the beginning of the message signature.
2804 If there is no signature in the article, go to the end and
2807 (goto-char (point-min))
2808 (if (re-search-forward message-signature-separator nil t)
2810 (goto-char (point-max))
2813 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc)
2814 "Insert a reasonable MFT header in a post to an unsubscribed list.
2815 When making original posts to a mailing list you are not subscribed to,
2816 you have to type in a MFT header by hand. The contents, usually, are
2817 the addresses of the list and your own address. This function inserts
2818 such a header automatically. It fetches the contents of the To: header
2819 in the current mail buffer, and appends the current `user-mail-address'.
2821 If the optional argument INCLUDE-CC is non-nil, the addresses in the
2822 Cc: header are also put into the MFT."
2827 (message-narrow-to-headers)
2828 (message-remove-header "Mail-Followup-To")
2829 (setq cc (and include-cc (message-fetch-field "Cc")))
2831 (concat (message-fetch-field "To") "," cc)
2832 (message-fetch-field "To"))))
2833 (message-goto-mail-followup-to)
2834 (insert (concat tos ", " user-mail-address))))
2838 (defun message-insert-to (&optional force)
2839 "Insert a To header that points to the author of the article being replied to.
2840 If the original author requested not to be sent mail, don't insert unless the
2841 prefix FORCE is given."
2843 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
2844 (dont (and mct (or (equal (downcase mct) "never")
2845 (equal (downcase mct) "nobody"))))
2846 (to (or (message-fetch-reply-field "mail-reply-to")
2847 (message-fetch-reply-field "reply-to")
2848 (message-fetch-reply-field "from"))))
2853 "Ignoring the user request not to have copies sent via mail"
2854 "Complying with the user request not to have copies sent via mail")))
2855 (when (and force (not to))
2856 (error "No mail address in the article"))
2857 (when (and to (or force (not dont)))
2858 (message-carefully-insert-headers (list (cons 'To to))))))
2860 (defun message-insert-wide-reply ()
2861 "Insert To and Cc headers as if you were doing a wide reply."
2863 (let ((headers (message-with-reply-buffer
2864 (message-get-reply-headers t))))
2865 (message-carefully-insert-headers headers)))
2867 (defun message-carefully-insert-headers (headers)
2868 (dolist (header headers)
2869 (let ((header-name (symbol-name (car header))))
2870 (when (and (message-position-on-field header-name)
2871 (mail-fetch-field header-name)
2872 (not (string-match "\\` *\\'"
2873 (mail-fetch-field header-name))))
2875 (insert (cdr header)))))
2877 (defun message-widen-reply ()
2878 "Widen the reply to include maximum recipients."
2881 (and message-reply-buffer
2882 (buffer-name message-reply-buffer)
2884 (set-buffer message-reply-buffer)
2885 (message-get-reply-headers t)))))
2888 (message-narrow-to-headers)
2889 (dolist (elem follow-to)
2890 (message-remove-header (symbol-name (car elem)))
2891 (goto-char (point-min))
2892 (insert (symbol-name (car elem)) ": "
2893 (cdr elem) "\n"))))))
2895 (defun message-insert-newsgroups ()
2896 "Insert the Newsgroups header from the article being replied to."
2898 (when (and (message-position-on-field "Newsgroups")
2899 (mail-fetch-field "newsgroups")
2900 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
2902 (insert (or (message-fetch-reply-field "newsgroups") "")))
2906 ;;; Various commands
2908 (defun message-delete-not-region (beg end)
2909 "Delete everything in the body of the current message outside of the region."
2914 ;; snarf citation prefix, if appropriate
2915 (unless (eq (point) (progn (beginning-of-line) (point)))
2916 (when (looking-at message-cite-prefix-regexp)
2917 (setq citeprefix (match-string 0))))
2919 (delete-region (point) (if (not (message-goto-signature))
2925 (delete-region beg (progn (message-goto-body)
2929 (insert citeprefix))))
2930 (when (message-goto-signature)
2933 (defun message-kill-to-signature ()
2934 "Deletes all text up to the signature."
2936 (let ((point (point)))
2937 (message-goto-signature)
2940 (kill-region point (point))
2944 (defun message-newline-and-reformat (&optional arg not-break)
2945 "Insert four newlines, and then reformat if inside quoted text.
2946 Prefix arg means justify as well."
2947 (interactive (list (if current-prefix-arg 'full)))
2948 (let (quoted point beg end leading-space bolp)
2949 (setq point (point))
2952 (setq bolp (= beg point))
2953 ;; Find first line of the paragraph.
2955 (while (and (not (eobp))
2956 (not (looking-at message-cite-prefix-regexp))
2957 (looking-at paragraph-start))
2960 (when (looking-at message-cite-prefix-regexp)
2961 (setq quoted (match-string 0))
2962 (goto-char (match-end 0))
2963 (looking-at "[ \t]*")
2964 (setq leading-space (match-string 0)))
2968 (< (- point beg) (length quoted)))
2969 ;; break inside the cite prefix.
2975 (while (and (not (eobp))
2976 (not (looking-at paragraph-separate))
2977 (looking-at message-cite-prefix-regexp)
2978 (equal quoted (match-string 0)))
2979 (goto-char (match-end 0))
2980 (looking-at "[ \t]*")
2981 (if (> (length leading-space) (length (match-string 0)))
2982 (setq leading-space (match-string 0)))
2986 (while (and (if (bobp) nil (forward-line -1) t)
2987 (not (looking-at paragraph-start))
2988 (looking-at message-cite-prefix-regexp)
2989 (equal quoted (match-string 0)))
2991 (goto-char (match-end 0))
2992 (looking-at "[ \t]*")
2993 (if (> (length leading-space) (length (match-string 0)))
2994 (setq leading-space (match-string 0)))))
2995 (while (and (not (eobp))
2996 (not (looking-at paragraph-separate))
2997 (not (looking-at message-cite-prefix-regexp)))
3001 (while (and (if (bobp) nil (forward-line -1) t)
3002 (not (looking-at paragraph-start))
3003 (not (looking-at message-cite-prefix-regexp)))
3004 (setq beg (point))))
3007 (narrow-to-region beg end)
3014 (setq point (point))
3015 ;; (newline 2) doesn't mark both newline's as hard, so call
3016 ;; newline twice. -jas
3019 (delete-region (point) (re-search-forward "[ \t]*"))
3020 (when (and quoted (not bolp))
3021 (insert quoted leading-space)))
3024 (let* ((adaptive-fill-regexp
3025 (regexp-quote (concat quoted leading-space)))
3026 (adaptive-fill-first-line-regexp
3027 adaptive-fill-regexp ))
3028 (fill-paragraph arg))
3029 (fill-paragraph arg))
3030 (if point (goto-char point)))))
3032 (defun message-fill-paragraph (&optional arg)
3033 "Like `fill-paragraph'."
3034 (interactive (list (if current-prefix-arg 'full)))
3035 (if (if (boundp 'filladapt-mode) filladapt-mode)
3037 (message-newline-and-reformat arg t)
3040 ;; Is it better to use `mail-header-end'?
3041 (defun message-point-in-header-p ()
3042 "Return t if point is in the header."
3045 (goto-char (point-min))
3046 (not (re-search-forward
3047 (concat "^" (regexp-quote mail-header-separator) "\n")
3050 (defun message-do-auto-fill ()
3051 "Like `do-auto-fill', but don't fill in message header."
3052 (unless (message-point-in-header-p)
3055 (defun message-insert-signature (&optional force)
3056 "Insert a signature. See documentation for variable `message-signature'."
3057 (interactive (list 0))
3060 ((and (null message-signature)
3063 (goto-char (point-max))
3064 (not (re-search-backward message-signature-separator nil t))))
3065 ((and (null message-signature)
3068 ((functionp message-signature)
3069 (funcall message-signature))
3070 ((listp message-signature)
3071 (eval message-signature))
3072 (t message-signature)))
3074 (cond ((stringp signature)
3076 ((and (eq t signature)
3077 message-signature-file
3078 (file-exists-p message-signature-file))
3081 (goto-char (point-max))
3082 ;; Insert the signature.
3085 (when message-signature-insert-empty-line
3087 (insert "\n" message-signature-separator-for-insertion)
3090 (if (eq signature t)
3091 (insert-file-contents message-signature-file)
3093 (goto-char (point-max))
3094 (or (bolp) (insert "\n")))))
3096 (defun message-insert-importance-high ()
3097 "Insert header to mark message as important."
3101 (message-narrow-to-headers)
3102 (message-remove-header "Importance"))
3104 (insert "Importance: high\n")))
3106 (defun message-insert-importance-low ()
3107 "Insert header to mark message as unimportant."
3111 (message-narrow-to-headers)
3112 (message-remove-header "Importance"))
3114 (insert "Importance: low\n")))
3116 (defun message-insert-or-toggle-importance ()
3117 "Insert a \"Importance: high\" header, or cycle through the header values.
3118 The three allowed values according to RFC 1327 are `high', `normal'
3122 (let ((valid '("high" "normal" "low"))
3126 (message-narrow-to-headers)
3127 (when (setq cur (message-fetch-field "Importance"))
3128 (message-remove-header "Importance")
3129 (setq new (cond ((string= cur "high")
3131 ((string= cur "low")
3136 (insert (format "Importance: %s\n" new)))))
3138 (defun message-insert-disposition-notification-to ()
3139 "Request a disposition notification (return receipt) to this message.
3140 Note that this should not be used in newsgroups."
3144 (message-narrow-to-headers)
3145 (message-remove-header "Disposition-Notification-To"))
3147 (insert (format "Disposition-Notification-To: %s\n"
3148 (or (message-field-value "Reply-to")
3149 (message-field-value "From")
3150 (message-make-from))))))
3152 (defun message-elide-region (b e)
3153 "Elide the text in the region.
3154 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3158 (insert message-elide-ellipsis))
3160 (defvar message-caesar-translation-table nil)
3162 (defun message-caesar-region (b e &optional n)
3163 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3166 (min (point) (or (mark t) (point)))
3167 (max (point) (or (mark t) (point)))
3168 (when current-prefix-arg
3169 (prefix-numeric-value current-prefix-arg))))
3171 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
3172 (unless (or (zerop n) ; no action needed for a rot of 0
3173 (= b e)) ; no region to rotate
3174 ;; We build the table, if necessary.
3175 (when (or (not message-caesar-translation-table)
3176 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
3177 (setq message-caesar-translation-table
3178 (message-make-caesar-translation-table n)))
3179 (translate-region b e message-caesar-translation-table)))
3181 (defun message-make-caesar-translation-table (n)
3182 "Create a rot table with offset N."
3184 (table (make-string 256 0)))
3185 (while (< (incf i) 256)
3188 (substring table 0 ?A)
3189 (substring table (+ ?A n) (+ ?A n (- 26 n)))
3190 (substring table ?A (+ ?A n))
3191 (substring table (+ ?A 26) ?a)
3192 (substring table (+ ?a n) (+ ?a n (- 26 n)))
3193 (substring table ?a (+ ?a n))
3194 (substring table (+ ?a 26) 255))))
3196 (defun message-caesar-buffer-body (&optional rotnum)
3197 "Caesar rotate all letters in the current buffer by 13 places.
3198 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3199 With prefix arg, specifies the number of places to rotate each letter forward.
3200 Mail and USENET news headers are not rotated."
3201 (interactive (if current-prefix-arg
3202 (list (prefix-numeric-value current-prefix-arg))
3206 (when (message-goto-body)
3207 (narrow-to-region (point) (point-max)))
3208 (message-caesar-region (point-min) (point-max) rotnum))))
3210 (defun message-pipe-buffer-body (program)
3211 "Pipe the message body in the current buffer through PROGRAM."
3214 (when (message-goto-body)
3215 (narrow-to-region (point) (point-max)))
3216 (shell-command-on-region
3217 (point-min) (point-max) program nil t))))
3219 (defun message-rename-buffer (&optional enter-string)
3220 "Rename the *message* buffer to \"*message* RECIPIENT\".
3221 If the function is run with a prefix, it will ask for a new buffer
3222 name, rather than giving an automatic name."
3223 (interactive "Pbuffer name: ")
3226 (goto-char (point-min))
3227 (narrow-to-region (point)
3228 (search-forward mail-header-separator nil 'end))
3230 (if (message-news-p) (message-fetch-field "Newsgroups")
3231 (message-fetch-field "To"))
3234 (if (string-match "," mail-to)
3235 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
3237 (name-default (concat "*message* " mail-trimmed-to))
3238 (name (if enter-string
3239 (read-string "New buffer name: " name-default)
3241 (rename-buffer name t)))))
3243 (defun message-fill-yanked-message (&optional justifyp)
3244 "Fill the paragraphs of a message yanked into this one.
3245 Numeric argument means justify as well."
3248 (goto-char (point-min))
3249 (search-forward (concat "\n" mail-header-separator "\n") nil t)
3250 (let ((fill-prefix message-yank-prefix))
3251 (fill-individual-paragraphs (point) (point-max) justifyp))))
3253 (defun message-indent-citation ()
3254 "Modify text just inserted from a message to be cited.
3255 The inserted text should be the region.
3256 When this function returns, the region is again around the modified text.
3258 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3259 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3260 (let ((start (point)))
3261 ;; Remove unwanted headers.
3262 (when message-ignored-cited-headers
3267 (if (search-forward "\n\n" nil t)
3270 (message-remove-header message-ignored-cited-headers t)
3271 (when (= (point-min) (point-max))
3272 (setq all-removed t))
3273 (goto-char (point-max)))
3277 ;; Delete blank lines at the start of the buffer.
3278 (while (and (point-min)
3281 (message-delete-line))
3282 ;; Delete blank lines at the end of the buffer.
3283 (goto-char (point-max))
3286 (while (and (zerop (forward-line -1))
3288 (message-delete-line))
3289 ;; Do the indentation.
3290 (if (null message-yank-prefix)
3291 (indent-rigidly start (mark t) message-indentation-spaces)
3294 (while (< (point) (mark t))
3295 (if (or (looking-at ">") (looking-at "^$"))
3296 (insert message-yank-cited-prefix)
3297 (insert message-yank-prefix))
3301 (defun message-list-references (refs-list &rest refs-strs)
3302 "Add `Message-ID's which appear in REFS-STRS but not in REFS-LIST,
3304 (let (refs ref id saved-id)
3305 (when (and refs-list
3306 (integerp message-list-references-add-position))
3307 (let ((pos message-list-references-add-position))
3308 (while (and refs-list
3310 (push (pop refs-list) saved-id)
3311 (setq pos (1- pos)))))
3313 (when (setq refs (pop refs-strs))
3314 (setq refs (std11-parse-msg-ids (std11-lexical-analyze refs)))
3316 (when (eq (car (setq ref (pop refs))) 'msg-id)
3317 (setq id (concat "<" (mapconcat 'cdr (cdr ref) "") ">"))
3318 (or (member id refs-list)
3319 (member id saved-id)
3320 (push id refs-list))))))
3322 (push (pop saved-id) refs-list))
3325 (defun message-yank-original (&optional arg)
3326 "Insert the message being replied to, if any.
3327 Puts point before the text and mark after.
3328 Normally indents each nonblank line ARG spaces (default 3). However,
3329 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3331 This function uses `message-cite-function' to do the actual citing.
3333 Just \\[universal-argument] as argument means don't indent, insert no
3334 prefix, and don't delete any headers.
3336 In addition, if `message-yank-add-new-references' is non-nil and this
3337 command is called interactively, new IDs from the yanked article will
3338 be added to the \"References\" field."
3340 (let ((modified (buffer-modified-p)))
3341 (when (let ((buffer (message-eval-parameter message-reply-buffer)))
3343 message-cite-function
3346 (delete-windows-on buffer t)
3347 ; The mark will be set at the end of the article.
3348 (insert-buffer buffer))))
3349 ;; Add new IDs to the References field.
3350 (when (and message-yank-add-new-references
3352 (let ((start (point))
3358 (setq refs (message-list-references
3360 (or (message-make-references)
3362 (message-narrow-to-headers)
3363 (message-fetch-field "References")
3365 (narrow-to-region start end)
3366 (std11-narrow-to-header)
3367 (unless (equal (setq newrefs
3368 (message-list-references
3369 (copy-sequence refs)
3370 (unless (eq message-yank-add-new-references
3372 (or (message-fetch-field "References")
3373 (message-fetch-field "In-Reply-To")))
3374 (message-fetch-field "Message-ID")))
3376 ;; If the References field has been changed, we make it
3377 ;; visible in the header.
3378 (when message-reply-headers
3379 (mail-header-set-message-id message-reply-headers nil)
3380 (mail-header-set-references message-reply-headers nil))
3382 (message-narrow-to-headers)
3383 (if (let ((case-fold-search t))
3384 (re-search-forward "^References:\\([\t ]+.+\n\\)+"
3387 (goto-char (point-max)))
3389 (list (or (assq 'References message-header-format-alist)
3390 '(References . message-fill-references)))
3391 (list (cons 'References (mapconcat 'identity
3392 (nreverse newrefs) " "))))
3393 (backward-delete-char 1))))))
3395 (if (and message-suspend-font-lock-when-citing
3396 (boundp 'font-lock-mode)
3397 (symbol-value 'font-lock-mode))
3402 (funcall message-cite-function))
3404 (funcall message-cite-function)))
3405 (message-exchange-point-and-mark)
3409 (setq message-checksum (message-checksum))))))
3411 (defun message-yank-buffer (buffer)
3412 "Insert BUFFER into the current buffer and quote it."
3413 (interactive "bYank buffer: ")
3414 (let ((message-reply-buffer buffer))
3415 (save-window-excursion
3416 (message-yank-original))))
3418 (defun message-buffers ()
3419 "Return a list of active message buffers."
3422 (dolist (buffer (buffer-list t))
3424 (when (and (eq major-mode 'message-mode)
3425 (null message-sent-message-via))
3426 (push (buffer-name buffer) buffers))))
3427 (nreverse buffers)))
3429 (defun message-cite-original-without-signature ()
3430 "Cite function in the standard Message manner."
3431 (let ((start (point))
3434 (when message-indent-citation-function
3435 (if (listp message-indent-citation-function)
3436 message-indent-citation-function
3437 (list message-indent-citation-function))))
3438 (message-reply-headers (or message-reply-headers
3439 (make-mail-header))))
3440 (mail-header-set-from message-reply-headers
3444 (if (search-forward "\n\n" nil t)
3447 (or (message-fetch-field "from")
3452 (when (re-search-backward message-signature-separator start t)
3453 ;; Also peel off any blank lines before the signature.
3455 (while (looking-at "^[ \t]*$")
3458 (delete-region (point) end)
3459 (unless (search-backward "\n\n" start t)
3460 ;; Insert a blank line if it is peeled off.
3464 (funcall (pop functions)))
3465 (when message-citation-line-function
3468 (funcall message-citation-line-function))))
3470 (eval-when-compile (defvar mail-citation-hook)) ;Compiler directive
3471 (defun message-cite-original ()
3472 "Cite function in the standard Message manner."
3473 (if (and (boundp 'mail-citation-hook)
3475 (run-hooks 'mail-citation-hook)
3476 (let ((start (point))
3479 (when message-indent-citation-function
3480 (if (listp message-indent-citation-function)
3481 message-indent-citation-function
3482 (list message-indent-citation-function))))
3483 (message-reply-headers (or message-reply-headers
3484 (make-mail-header))))
3485 (mail-header-set-from message-reply-headers
3489 (if (search-forward "\n\n" nil t)
3492 (or (message-fetch-field "from")
3496 (funcall (pop functions)))
3497 (when message-citation-line-function
3500 (funcall message-citation-line-function)))))
3502 (defun message-insert-citation-line ()
3503 "Insert a simple citation line."
3504 (when message-reply-headers
3505 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
3507 (defun message-position-on-field (header &rest afters)
3508 (let ((case-fold-search t))
3511 (goto-char (point-min))
3514 (concat "^" (regexp-quote mail-header-separator) "$"))
3515 (match-beginning 0)))
3516 (goto-char (point-min))
3517 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
3519 (re-search-forward "^[^ \t]" nil 'move)
3521 (skip-chars-backward "\n")
3524 (not (re-search-forward
3525 (concat "^" (regexp-quote (car afters)) ":")
3529 (re-search-forward "^[^ \t]" nil 'move)
3530 (beginning-of-line))
3531 (insert header ": \n")
3535 (defun message-remove-signature ()
3536 "Remove the signature from the text between point and mark.
3537 The text will also be indented the normal way."
3539 (let ((start (point))
3541 (if (not (re-search-forward message-signature-separator (mark t) t))
3542 ;; No signature here, so we just indent the cited text.
3543 (message-indent-citation)
3544 ;; Find the last non-empty line.
3546 (while (looking-at "[ \t]*$")
3549 (setq mark (set-marker (make-marker) (point)))
3551 (message-indent-citation)
3552 ;; Enable undoing the deletion.
3554 (delete-region mark (mark t))
3555 (set-marker mark nil)))))
3560 ;;; Sending messages
3563 ;; Avoid byte-compile warning.
3564 (defvar message-encoding-buffer nil)
3565 (defvar message-edit-buffer nil)
3566 (defvar message-mime-mode nil)
3568 (defun message-send-and-exit (&optional arg)
3569 "Send message like `message-send', then, if no errors, exit from mail buffer."
3571 (let ((buf (current-buffer))
3572 (actions message-exit-actions)
3573 (frame (selected-frame))
3574 (org-frame message-original-frame))
3575 (when (and (message-send arg)
3577 (if message-kill-buffer-on-exit
3580 (when (eq buf (current-buffer))
3581 (message-bury buf)))
3582 (message-do-actions actions)
3583 (message-delete-frame frame org-frame)
3586 (defun message-dont-send ()
3587 "Don't send the message you have been editing.
3588 Instead, just auto-save the buffer and then bury it."
3590 (set-buffer-modified-p t)
3592 (let ((actions message-postpone-actions)
3593 (frame (selected-frame))
3594 (org-frame message-original-frame))
3595 (message-bury (current-buffer))
3596 (message-do-actions actions)
3597 (message-delete-frame frame org-frame)))
3599 (defun message-kill-buffer ()
3600 "Kill the current buffer."
3602 (when (or (not (buffer-modified-p))
3603 (eq t message-kill-buffer-query-function)
3604 (funcall message-kill-buffer-query-function
3605 "The buffer modified; kill anyway? "))
3606 (let ((actions message-kill-actions)
3607 (draft-article message-draft-article)
3608 (auto-save-file-name buffer-auto-save-file-name)
3609 (file-name buffer-file-name)
3610 (modified (buffer-modified-p))
3611 (frame (selected-frame))
3612 (org-frame message-original-frame))
3613 (setq buffer-file-name nil)
3614 (kill-buffer (current-buffer))
3615 (when (and message-kill-buffer-and-remove-file
3616 (or (and auto-save-file-name
3617 (file-exists-p auto-save-file-name))
3619 (file-exists-p file-name)))
3620 (yes-or-no-p (format "Remove the backup file%s? "
3621 (if modified " too" ""))))
3623 (delete-file auto-save-file-name))
3624 (let ((message-draft-article draft-article))
3625 (message-disassociate-draft)))
3626 (message-do-actions actions)
3627 (message-delete-frame frame org-frame)))
3630 (defun message-mimic-kill-buffer ()
3631 "Kill the current buffer with query. This is an imitation for
3632 `kill-buffer', but it will delete a message frame."
3634 (let ((bufname (read-buffer (format "Kill buffer: (default %s) "
3636 message-kill-buffer-and-remove-file)
3637 (when (or (not bufname)
3638 (string-equal bufname "")
3639 (string-equal bufname (buffer-name)))
3640 (message-kill-buffer))))
3642 (defun message-delete-frame (frame org-frame)
3643 "Delete frame for editing message."
3644 (when (and (or (static-if (featurep 'xemacs)
3645 (device-on-window-system-p)
3647 (>= emacs-major-version 20))
3648 (or (and (eq message-delete-frame-on-exit t)
3649 (select-frame frame)
3650 (or (eq frame org-frame)
3652 (y-or-n-p "Delete this frame?")
3654 (and (eq message-delete-frame-on-exit 'ask)
3655 (select-frame frame)
3657 (y-or-n-p "Delete this frame?")
3659 (delete-frame frame)))
3661 (defun message-bury (buffer)
3662 "Bury this mail BUFFER."
3663 (let ((newbuf (other-buffer buffer)))
3664 (bury-buffer buffer)
3665 (if (and (fboundp 'frame-parameters)
3666 (cdr (assq 'dedicated (frame-parameters)))
3667 (not (null (delq (selected-frame) (visible-frame-list)))))
3668 (delete-frame (selected-frame))
3669 (switch-to-buffer newbuf))))
3671 (defun message-send (&optional arg)
3672 "Send the message in the current buffer.
3673 If `message-interactive' is non-nil, wait for success indication or
3674 error messages, and inform user.
3675 Otherwise any failure is reported in a message back to the user from
3677 The usage of ARG is defined by the instance that called Message.
3678 It should typically alter the sending method in some way or other."
3681 (when (or (buffer-modified-p)
3682 (message-check-element 'unchanged)
3683 (y-or-n-p "No changes in the buffer; really send? "))
3684 ;; Make it possible to undo the coming changes.
3686 (let ((inhibit-read-only t))
3687 (put-text-property (point-min) (point-max) 'read-only nil))
3688 (run-hooks 'message-send-hook)
3689 (message-fix-before-sending)
3690 (message message-sending-message)
3691 (let ((message-encoding-buffer
3692 (message-generate-new-buffer-clone-locals " message encoding"))
3693 (message-edit-buffer (current-buffer))
3694 (message-mime-mode mime-edit-mode-flag)
3695 (alist message-send-method-alist)
3697 elem sent dont-barf-on-no-method
3698 (message-options message-options))
3701 (message-options-set-recipient)
3703 (set-buffer message-encoding-buffer)
3705 ;; ;; Avoid copying text props (except hard newlines).
3706 ;; T-gnus change: copy all text props from the editing buffer
3707 ;; into the encoding buffer.
3708 (insert-buffer-substring message-edit-buffer)
3709 (funcall message-encode-function)
3711 (setq elem (pop alist)))
3712 (when (funcall (cadr elem))
3714 (or (not (memq (car elem)
3715 message-sent-message-via))
3716 (message-fetch-field "supersedes")
3717 (if (or (message-gnksa-enable-p 'multiple-copies)
3718 (not (eq (car elem) 'news)))
3721 "Already sent message via %s; resend? "
3723 (error "Denied posting -- multiple copies")))
3724 (setq success (funcall (caddr elem) arg)))
3730 (let ((fcc (message-fetch-field "Fcc"))
3731 (gcc (message-fetch-field "Gcc")))
3734 (eq message-allow-no-recipients 'always)
3735 (and (not (eq message-allow-no-recipients 'never))
3736 (setq dont-barf-on-no-method
3738 (format "No receiver, perform %s anyway? "
3739 (cond ((and fcc gcc) "Fcc and Gcc")
3742 (error "No methods specified to send by"))
3743 (when (or dont-barf-on-no-method
3747 (run-hooks 'message-sent-hook))
3748 (message "Sending...done")
3749 ;; Mark the buffer as unmodified and delete auto-save.
3750 (set-buffer-modified-p nil)
3751 (delete-auto-save-file-if-necessary t)
3752 (message-disassociate-draft)
3753 ;; Delete other mail buffers and stuff.
3754 (message-do-send-housekeeping)
3755 (message-do-actions message-send-actions)
3758 (kill-buffer message-encoding-buffer)))))
3760 (defun message-send-via-mail (arg)
3761 "Send the current message via mail."
3762 (message-send-mail arg))
3764 (defun message-send-via-news (arg)
3765 "Send the current message via news."
3766 (message-send-news arg))
3768 (defmacro message-check (type &rest forms)
3769 "Eval FORMS if TYPE is to be checked."
3770 `(or (message-check-element ,type)
3774 (put 'message-check 'lisp-indent-function 1)
3775 (put 'message-check 'edebug-form-spec '(form body))
3777 ;; Advise the function `invisible-region'.
3778 (let (current-load-list)
3780 `(defadvice invisible-region (around add-mime-edit-invisible (start end)
3782 "Advised by T-gnus Message.
3783 Add the text property `mime-edit-invisible' to an invisible text when
3784 the buffer's major mode is `message-mode'. The added property will be
3785 used to distinguish whether the invisible text is a MIME part or not."
3786 ,(if (featurep 'xemacs)
3787 '(if (eq ?\n (char-after start))
3788 (setq start (1+ start)))
3789 '(if (eq ?\n (char-after (1- end)))
3790 (setq end (1- end))))
3791 (setq ad-return-value
3792 (if (eq 'message-mode major-mode)
3793 (add-text-properties start end
3794 '(invisible t mime-edit-invisible t))
3795 (put-text-property start end 'invisible t))))))
3797 (defun message-text-with-property (prop)
3798 "Return a list of all points where the text has PROP."
3800 (point (point-min)))
3802 (while (< point (point-max))
3803 (when (get-text-property point prop)
3804 (push point points))
3808 (defun message-fix-before-sending ()
3809 "Do various things to make the message nice before sending it."
3810 ;; Make sure there's a newline at the end of the message.
3812 (goto-char (point-max))
3815 ;; Make the hidden headers visible.
3816 (let ((points (message-text-with-property 'message-hidden)))
3818 (goto-char (car points))
3819 (dolist (point points)
3820 (add-text-properties point (1+ point)
3821 '(invisible nil intangible nil)))))
3822 ;; Make invisible text visible except for mime parts which may be
3823 ;; inserted by the MIME-Edit.
3824 ;; It doesn't seem as if this is useful, since the invisible property
3825 ;; is clobbered by an after-change hook anyhow.
3826 (message-check 'invisible-text
3827 ;; FIXME T-gnus: It should also detect invisible overlays.
3830 mime-from mime-to hidden-start)
3831 (while (setq from (text-property-any to (point-max) 'invisible t))
3832 (setq to (or (text-property-not-all from (point-max) 'invisible t)
3835 (while (setq mime-from (text-property-any mime-to to
3836 'mime-edit-invisible t))
3837 (when (> mime-from mime-to)
3838 (setq hidden-start (or hidden-start mime-to))
3839 (add-text-properties mime-to mime-from
3840 '(invisible nil face highlight
3841 font-lock-face highlight)))
3842 (setq mime-to (or (text-property-not-all mime-from to
3843 'mime-edit-invisible t)
3845 (when (< mime-to to)
3846 (setq hidden-start (or hidden-start mime-to))
3847 (add-text-properties mime-to to
3848 '(invisible nil face highlight
3849 font-lock-face highlight))))
3851 (goto-char hidden-start)
3852 (set-window-start (selected-window) (gnus-point-at-bol))
3853 (unless (yes-or-no-p
3854 "Invisible text found and made visible; continue sending? ")
3855 (error "Invisible text found and made visible")))))
3856 ;; The following check is needless to T-gnus since T-gnus determines
3857 ;; a MIME charset forcibly (even if it cannot be determined properly,
3858 ;; the value of the `default-mime-charset-for-write' variable is used).
3859 ;; (message-check 'illegible-text
3860 ;; (let ((mm-7bit-chars "\x20-\x7f\r\n\t\x7\x8\xb\xc\x1f\x1b")
3862 ;; (message-goto-body)
3863 ;; (skip-chars-forward mm-7bit-chars)
3864 ;; (while (not (eobp))
3865 ;; (when (let ((char (char-after)))
3866 ;; (or (< (mm-char-int char) 128)
3867 ;; (and (mm-multibyte-p)
3868 ;; (> (length (mm-find-mime-charset-region
3869 ;; (point) (point-max)))
3871 ;; (message-overlay-put (message-make-overlay (point) (1+ (point)))
3872 ;; 'face 'highlight)
3875 ;; (skip-chars-forward mm-7bit-chars))
3878 ;; (gnus-multiple-choice
3879 ;; "Non-printable characters found. Continue sending?"
3880 ;; '((?d "Remove non-printable characters and send")
3881 ;; (?r "Replace non-printable characters with dots and send")
3882 ;; (?i "Ignore non-printable characters and send")
3883 ;; (?e "Continue editing"))))
3884 ;; (if (eq choice ?e)
3885 ;; (error "Non-printable characters"))
3886 ;; (message-goto-body)
3887 ;; (skip-chars-forward mm-7bit-chars)
3888 ;; (while (not (eobp))
3889 ;; (when (let ((char (char-after)))
3890 ;; (or (< (mm-char-int char) 128)
3891 ;; (and (mm-multibyte-p)
3892 ;; ;; Fixme: Wrong for Emacs 22 and for things
3893 ;; ;; like undecable utf-8. Should at least
3894 ;; ;; use find-coding-systems-region.
3895 ;; (memq (char-charset char)
3896 ;; '(eight-bit-control eight-bit-graphic
3898 ;; (if (eq choice ?i)
3899 ;; (message-kill-all-overlays)
3901 ;; (when (eq choice ?r)
3904 ;; (skip-chars-forward mm-7bit-chars)))))
3907 (defun message-add-action (action &rest types)
3908 "Add ACTION to be performed when doing an exit of type TYPES."
3910 (add-to-list (intern (format "message-%s-actions" (pop types)))
3913 (defun message-delete-action (action &rest types)
3914 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
3917 (set (setq var (intern (format "message-%s-actions" (pop types))))
3918 (delq action (symbol-value var))))))
3920 (defun message-do-actions (actions)
3921 "Perform all actions in ACTIONS."
3922 ;; Now perform actions on successful sending.
3926 ;; A simple function.
3927 ((functionp (car actions))
3928 (funcall (car actions)))
3929 ;; Something to be evaled.
3931 (eval (car actions)))))
3934 (defsubst message-maybe-split-and-send-mail ()
3935 "Split a message if necessary, and send it via mail.
3936 Returns nil if sending succeeded, returns any string if sending failed.
3937 This sub function is for exclusive use of `message-send-mail'."
3938 (let ((mime-edit-split-ignored-field-regexp
3939 mime-edit-split-ignored-field-regexp)
3940 (case-fold-search t)
3942 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
3943 (setq mime-edit-split-ignored-field-regexp
3944 (concat (substring mime-edit-split-ignored-field-regexp
3945 0 (match-beginning 0))
3946 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
3947 "_so_don't_rape_it!"
3948 (substring mime-edit-split-ignored-field-regexp
3952 (catch 'message-sending-mail-failure
3953 (mime-edit-maybe-split-and-send
3958 (std11-narrow-to-header mail-header-separator)
3959 (goto-char (point-min))
3960 (when (re-search-forward "^Message-ID:" nil t)
3961 (delete-region (match-end 0) (std11-field-end))
3962 (insert " " (message-make-message-id))))
3964 (funcall (or message-send-mail-real-function
3965 message-send-mail-function))
3967 (throw 'message-sending-mail-failure err))))))
3971 (funcall (or message-send-mail-real-function
3972 message-send-mail-function))
3976 (if (eq 'error (car failure))
3978 (prin1-to-string failure)))))
3980 (defun message-send-mail-partially ()
3981 "Send mail as message/partial."
3982 ;; replace the header delimiter with a blank line
3983 (goto-char (point-min))
3985 (concat "^" (regexp-quote mail-header-separator) "\n"))
3986 (replace-match "\n")
3987 (run-hooks 'message-send-mail-hook)
3988 (let ((p (goto-char (point-min)))
3989 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
3990 (curbuf (current-buffer))
3991 (id (message-make-message-id)) (n 1)
3992 plist total header required-mail-headers)
3994 (if (< (point-max) (+ p message-send-mail-partially-limit))
3995 (goto-char (point-max))
3996 (goto-char (+ p message-send-mail-partially-limit))
3998 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
4001 (setq total (length plist))
4002 (push (point-max) plist)
4003 (setq plist (nreverse plist))
4006 (setq p (pop plist))
4009 (copy-to-buffer tembuf p (car plist))
4011 (goto-char (point-min))
4014 (goto-char (point-min))
4015 (narrow-to-region (point) (point))
4018 (setq header (buffer-substring (point-min) (point)))
4019 (goto-char (point-min))
4020 (narrow-to-region (point) (point))
4022 (message-remove-header "Mime-Version")
4023 (message-remove-header "Content-Type")
4024 (message-remove-header "Content-Transfer-Encoding")
4025 (message-remove-header "Message-ID")
4026 (message-remove-header "Lines")
4027 (goto-char (point-max))
4028 (insert "Mime-Version: 1.0\n")
4029 (setq header (buffer-string)))
4030 (goto-char (point-max))
4031 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
4034 (let ((mail-header-separator ""))
4035 (when (memq 'Message-ID message-required-mail-headers)
4036 (insert "Message-ID: " (message-make-message-id) "\n"))
4037 (when (memq 'Lines message-required-mail-headers)
4038 (insert "Lines: " (message-make-lines) "\n"))
4039 (message-goto-subject)
4041 (insert (format " (%d/%d)" n total))
4043 (mm-with-unibyte-current-buffer
4044 (funcall (or message-send-mail-real-function
4045 message-send-mail-function))))
4047 (setq p (pop plist))
4049 (kill-buffer tembuf))))
4051 (defun message-send-mail (&optional arg)
4052 (require 'mail-utils)
4053 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
4054 (case-fold-search nil)
4055 (news (message-news-p))
4056 (message-this-is-mail t)
4057 (headers message-required-mail-headers)
4060 (message-narrow-to-headers)
4061 ;; Generate the Mail-Followup-To header if the header is not there...
4062 (if (and (message-subscribed-p)
4063 (not (mail-fetch-field "mail-followup-to")))
4066 (cons "Mail-Followup-To" (message-make-mail-followup-to))
4067 message-required-mail-headers))
4068 ;; otherwise, delete the MFT header if the field is empty
4069 (when (equal "" (mail-fetch-field "mail-followup-to"))
4070 (message-remove-header "^Mail-Followup-To:")))
4071 ;; Insert some headers.
4072 (let ((message-deletable-headers
4073 (if news nil message-deletable-headers)))
4074 (message-generate-headers headers))
4075 ;; Let the user do all of the above.
4076 (run-hooks 'message-header-hook))
4077 (if (not (message-check-mail-syntax))
4085 ;; ;; Avoid copying text props (except hard newlines).
4086 ;; T-gnus change: copy all text props from the editing buffer
4087 ;; into the encoding buffer.
4088 (insert-buffer-substring message-encoding-buffer)
4089 ;; Remove some headers.
4091 (message-narrow-to-headers)
4092 ;; We Semi-gnus people have no use for it.
4093 ;; ;; We (re)generate the Lines header.
4094 ;; (when (memq 'Lines message-required-mail-headers)
4095 ;; (message-generate-headers '(Lines)))
4096 (message-remove-header message-ignored-mail-headers t))
4097 (goto-char (point-max))
4098 ;; require one newline at the end.
4099 (or (= (preceding-char) ?\n)
4101 (message-cleanup-headers)
4102 ;; FIXME: we're inserting the courtesy copy after encoding.
4103 ;; This is wrong if the courtesy copy string contains
4104 ;; non-ASCII characters. -- jh
4107 (message-narrow-to-headers)
4109 (or (message-fetch-field "cc")
4110 (message-fetch-field "bcc")
4111 (message-fetch-field "to"))
4112 (let ((content-type (mime-read-Content-Type)))
4117 (eq 'text (cdr (assq 'type content-type)))
4118 (eq 'plain (cdr (assq 'subtype content-type)))))
4121 (mime-read-Content-Transfer-Encoding)))))))
4122 (message-insert-courtesy-copy))
4123 (setq failure (message-maybe-split-and-send-mail)))
4124 (kill-buffer tembuf))
4125 (set-buffer message-edit-buffer)
4128 (message "Couldn't send message via mail: %s" failure)
4130 (push 'mail message-sent-message-via)))))
4132 (defun message-send-mail-with-sendmail ()
4133 "Send off the prepared buffer with sendmail."
4134 (let ((errbuf (if message-interactive
4135 (message-generate-new-buffer-clone-locals
4138 resend-to-addresses delimline)
4141 (let ((case-fold-search t))
4143 (message-narrow-to-headers)
4144 (setq resend-to-addresses (message-fetch-field "resent-to")))
4145 ;; Change header-delimiter to be what sendmail expects.
4146 (goto-char (point-min))
4148 (concat "^" (regexp-quote mail-header-separator) "\n"))
4149 (replace-match "\n")
4151 (setq delimline (point-marker))
4152 (run-hooks 'message-send-mail-hook)
4153 ;; Insert an extra newline if we need it to work around
4154 ;; Sun's bug that swallows newlines.
4155 (goto-char (1+ delimline))
4156 (when (eval message-mailer-swallows-blank-line)
4158 (when message-interactive
4162 (let* ((default-directory "/")
4163 (cpr (as-binary-process
4165 'call-process-region
4167 (list (point-min) (point-max)
4168 (if (boundp 'sendmail-program)
4170 "/usr/lib/sendmail")
4171 nil errbuf nil "-oi")
4172 ;; Always specify who from,
4173 ;; since some systems have broken sendmails.
4174 ;; But some systems are more broken with -f, so
4175 ;; we'll let users override this.
4176 (if (null message-sendmail-f-is-evil)
4177 (list "-f" (message-sendmail-envelope-from)))
4178 ;; These mean "report errors by mail"
4179 ;; and "deliver in background".
4180 (if (null message-interactive) '("-oem" "-odb"))
4181 ;; Get the addresses from the message
4182 ;; unless this is a resend.
4183 ;; We must not do that for a resend
4184 ;; because we would find the original addresses.
4185 ;; For a resend, include the specific addresses.
4186 (if resend-to-addresses
4187 (list resend-to-addresses)
4189 (unless (or (null cpr) (and (numberp cpr) (zerop cpr)))
4190 (error "Sending...failed with exit value %d" cpr)))
4191 (when message-interactive
4194 (goto-char (point-min))
4195 (while (re-search-forward "\n\n* *" nil t)
4196 (replace-match "; "))
4197 (if (not (zerop (buffer-size)))
4198 (error "Sending...failed to %s"
4199 (buffer-string))))))
4200 (when (bufferp errbuf)
4201 (kill-buffer errbuf)))))
4203 (defun message-send-mail-with-qmail ()
4204 "Pass the prepared message buffer to qmail-inject.
4205 Refer to the documentation for the variable `message-send-mail-function'
4206 to find out how to use this."
4207 ;; replace the header delimiter with a blank line
4208 (goto-char (point-min))
4210 (concat "^" (regexp-quote mail-header-separator) "\n"))
4211 (replace-match "\n")
4213 (run-hooks 'message-send-mail-hook)
4218 'call-process-region 1 (point-max) message-qmail-inject-program
4220 ;; qmail-inject's default behaviour is to look for addresses on the
4221 ;; command line; if there're none, it scans the headers.
4222 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4224 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4225 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4226 ;; message from stdin.
4228 ;; qmail also has the advantage of not having been raped by
4229 ;; various vendors, so we don't have to allow for that, either --
4230 ;; compare this with message-send-mail-with-sendmail and weep
4231 ;; for sendmail's lost innocence.
4233 ;; all this is way cool coz it lets us keep the arguments entirely
4234 ;; free for -inject-arguments -- a big win for the user and for us
4235 ;; since we don't have to play that double-guessing game and the user
4236 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4237 (if (functionp message-qmail-inject-args)
4238 (funcall message-qmail-inject-args)
4239 message-qmail-inject-args)))
4240 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4241 ;; we have to look at the retval instead
4243 (100 (error "qmail-inject reported permanent failure"))
4244 (111 (error "qmail-inject reported transient failure"))
4245 ;; should never happen
4246 (t (error "qmail-inject reported unknown failure"))))
4248 (defun message-send-mail-with-mh ()
4249 "Send the prepared message buffer with mh."
4250 (let ((mh-previous-window-config nil)
4251 (name (mh-new-draft-name)))
4252 (setq buffer-file-name name)
4253 ;; MH wants to generate these headers itself.
4254 (when message-mh-deletable-headers
4255 (let ((headers message-mh-deletable-headers))
4257 (goto-char (point-min))
4258 (and (re-search-forward
4259 (concat "^" (symbol-name (car headers)) ": *") nil t)
4260 (message-delete-line))
4262 (run-hooks 'message-send-mail-hook)
4263 ;; Pass it on to mh.
4266 (defun message-send-mail-with-smtp ()
4267 "Send off the prepared buffer with SMTP."
4268 (require 'smtp) ; XXX
4269 (let ((case-fold-search t)
4272 (message-narrow-to-headers)
4274 ;; XXX: Should be replaced by better one.
4275 (smtp-deduce-address-list (current-buffer)
4276 (point-min) (point-max)))
4277 ;; Remove BCC lines.
4278 (message-remove-header "bcc"))
4279 ;; replace the header delimiter with a blank line.
4280 (goto-char (point-min))
4282 (concat "^" (regexp-quote mail-header-separator) "\n"))
4283 (replace-match "\n")
4285 (run-hooks 'message-send-mail-hook)
4287 (smtp-send-buffer user-mail-address recipients (current-buffer))
4288 (error "Sending failed; no recipients"))))
4290 (defsubst message-maybe-split-and-send-news (method)
4291 "Split a message if necessary, and send it via news.
4292 Returns nil if sending succeeded, returns t if sending failed.
4293 This sub function is for exclusive use of `message-send-news'."
4294 (let ((mime-edit-split-ignored-field-regexp
4295 mime-edit-split-ignored-field-regexp)
4296 (case-fold-search t))
4297 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
4298 (setq mime-edit-split-ignored-field-regexp
4299 (concat (substring mime-edit-split-ignored-field-regexp
4300 0 (match-beginning 0))
4301 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
4302 "_so_don't_rape_it!"
4303 (substring mime-edit-split-ignored-field-regexp
4306 (catch 'message-sending-news-failure
4307 (mime-edit-maybe-split-and-send
4312 (std11-narrow-to-header mail-header-separator)
4313 (goto-char (point-min))
4314 (when (re-search-forward "^Message-ID:" nil t)
4315 (delete-region (match-end 0) (std11-field-end))
4316 (insert " " (message-make-message-id))))
4317 (unless (funcall message-send-news-function method)
4318 (throw 'message-sending-news-failure t)))))
4320 (not (funcall message-send-news-function method)))))
4322 (defun message-smtpmail-send-it ()
4323 "Send the prepared message buffer with `smtpmail-send-it'.
4324 This only differs from `smtpmail-send-it' that this command evaluates
4325 `message-send-mail-hook' just before sending a message. It is useful
4326 if your ISP requires the POP-before-SMTP authentication. See the
4327 documentation for the function `mail-source-touch-pop'."
4328 (run-hooks 'message-send-mail-hook)
4331 (defun message-canlock-generate ()
4332 "Return a string that is non-trivial to guess.
4333 Do not use this for anything important, it is cryptographically weak."
4334 (let (sha1-maximum-internal-length)
4335 (sha1 (concat (message-unique-id)
4336 (format "%x%x%x" (random) (random t) (random))
4337 (prin1-to-string (recent-keys))
4338 (prin1-to-string (garbage-collect))))))
4340 (defun message-canlock-password ()
4341 "The password used by message for cancel locks.
4342 This is the value of `canlock-password', if that option is non-nil.
4343 Otherwise, generate and save a value for `canlock-password' first."
4344 (unless canlock-password
4345 (customize-save-variable 'canlock-password (message-canlock-generate))
4346 (setq canlock-password-for-verify canlock-password))
4349 (defun message-insert-canlock ()
4350 (when message-insert-canlock
4351 (message-canlock-password)
4352 (canlock-insert-header)))
4354 (defun message-send-news (&optional arg)
4355 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4356 (case-fold-search nil)
4357 (method (if (functionp message-post-method)
4358 (funcall message-post-method arg)
4359 message-post-method))
4360 (newsgroups-field (save-restriction
4361 (message-narrow-to-headers-or-head)
4362 (message-fetch-field "Newsgroups")))
4363 (followup-field (save-restriction
4364 (message-narrow-to-headers-or-head)
4365 (message-fetch-field "Followup-To")))
4366 ;; BUG: We really need to get the charset for each name in the
4367 ;; Newsgroups and Followup-To lines to allow crossposting
4368 ;; between group namess with incompatible character sets.
4369 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4370 (group-field-charset
4371 (gnus-group-name-charset method newsgroups-field))
4372 (followup-field-charset
4373 (gnus-group-name-charset method (or followup-field "")))
4374 (mime-field-encoding-method-alist
4375 (append (when group-field-charset
4376 (list (cons "Newsgroups" group-field-charset)))
4377 (when followup-field-charset
4378 (list (cons "Followup-To" followup-field-charset)))
4379 mime-field-encoding-method-alist))
4380 (message-syntax-checks
4382 (listp message-syntax-checks))
4383 (cons '(existing-newsgroups . disabled)
4384 message-syntax-checks)
4385 message-syntax-checks))
4386 (message-this-is-news t)
4389 (message-narrow-to-headers)
4390 ;; Insert some headers.
4391 (message-generate-headers message-required-news-headers)
4392 (message-insert-canlock)
4393 ;; Let the user do all of the above.
4394 (run-hooks 'message-header-hook))
4395 ;; Note: This check will be disabled by the ".*" default value for
4396 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4397 (when (and group-field-charset
4398 (listp message-syntax-checks))
4399 (setq message-syntax-checks
4400 (cons '(valid-newsgroups . disabled)
4401 message-syntax-checks)))
4402 (message-cleanup-headers)
4403 (if (not (let ((message-post-method method))
4404 (message-check-news-syntax)))
4409 (buffer-disable-undo)
4411 (insert-buffer-substring message-encoding-buffer)
4412 ;; Remove some headers.
4414 (message-narrow-to-headers)
4415 ;; We Semi-gnus people have no use for it.
4416 ;; ;; We (re)generate the Lines header.
4417 ;; (when (memq 'Lines message-required-mail-headers)
4418 ;; (message-generate-headers '(Lines)))
4419 ;; Remove some headers.
4420 (message-remove-header message-ignored-news-headers t))
4421 (goto-char (point-max))
4422 ;; require one newline at the end.
4423 (or (= (preceding-char) ?\n)
4425 (setq result (message-maybe-split-and-send-news method)))
4426 (kill-buffer tembuf))
4427 (set-buffer message-edit-buffer)
4430 (message "Couldn't send message via news: %s"
4431 (nnheader-get-report (car method)))
4433 (push 'news message-sent-message-via)))))
4435 ;; 1997-09-29 by MORIOKA Tomohiko
4436 (defun message-send-news-with-gnus (method)
4437 (let ((case-fold-search t))
4438 ;; Remove the delimiter.
4439 (goto-char (point-min))
4441 (concat "^" (regexp-quote mail-header-separator) "\n"))
4442 (replace-match "\n")
4444 (run-hooks 'message-send-news-hook)
4445 (gnus-open-server method)
4446 (message "Sending news via %s..." (gnus-server-string method))
4447 (gnus-request-post method)
4451 ;;; Header generation & syntax checking.
4454 (defun message-check-element (type)
4455 "Return non-nil if this TYPE is not to be checked."
4456 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
4458 (let ((able (assq type message-syntax-checks)))
4460 (eq (cdr able) 'disabled)))))
4462 (defun message-check-news-syntax ()
4463 "Check the syntax of the message."
4468 ;; We narrow to the headers and check them first.
4471 (message-narrow-to-headers)
4472 (message-check-news-header-syntax)))
4475 (set-buffer message-edit-buffer)
4476 (message-check-news-body-syntax))))))
4478 (defun message-check-news-header-syntax ()
4480 ;; Check Newsgroups header.
4481 (message-check 'newsgroups
4482 (let ((group (message-fetch-field "newsgroups")))
4485 (not (string-match "\\`[ \t]*\\'" group)))
4488 "The newsgroups field is empty or missing. Posting is denied.")))))
4489 ;; Check the Subject header.
4490 (message-check 'subject
4491 (let* ((case-fold-search t)
4492 (subject (message-fetch-field "subject")))
4495 (not (string-match "\\`[ \t]*\\'" subject)))
4498 "The subject field is empty or missing. Posting is denied.")))))
4499 ;; Check for commands in Subject.
4500 (message-check 'subject-cmsg
4501 (if (string-match "^cmsg " (message-fetch-field "subject"))
4503 "The control code \"cmsg\" is in the subject. Really post? ")
4505 ;; Check long header lines.
4506 (message-check 'long-header-lines
4507 (let ((start (point))
4511 (while (and (not found)
4512 (re-search-forward "^\\([^ \t:]+\\): " nil t))
4513 (if (> (- (point) (match-beginning 0)) 998)
4515 length (- (point) (match-beginning 0)))
4516 (setq header (match-string-no-properties 1)))
4517 (setq start (match-beginning 0))
4520 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
4523 ;; Check for multiple identical headers.
4524 (message-check 'multiple-headers
4526 (while (and (not found)
4527 (re-search-forward "^[^ \t:]+: " nil t))
4529 (or (re-search-forward
4534 (match-beginning 0) (- (match-end 0) 2))))
4539 (y-or-n-p (format "Multiple %s headers. Really post? " found))
4541 ;; Check for Version and Sendsys.
4542 (message-check 'sendsys
4543 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
4545 (format "The article contains a %s command. Really post? "
4546 (buffer-substring (match-beginning 0)
4547 (1- (match-end 0)))))
4549 ;; See whether we can shorten Followup-To.
4550 (message-check 'shorten-followup-to
4551 (let ((newsgroups (message-fetch-field "newsgroups"))
4552 (followup-to (message-fetch-field "followup-to"))
4554 (when (and newsgroups
4555 (string-match "," newsgroups)
4560 (setq to (completing-read
4561 "Followups to (default: no Followup-To header) "
4564 (message-tokenize-header
4566 (goto-char (point-min))
4567 (insert "Followup-To: " to "\n"))
4569 ;; Check "Shoot me".
4570 (message-check 'shoot
4571 (if (re-search-forward
4572 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t)
4573 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
4575 ;; Check for Approved.
4576 (message-check 'approved
4577 (if (re-search-forward "^Approved:" nil t)
4578 (y-or-n-p "The article contains an Approved header. Really post? ")
4580 ;; Check the Message-ID header.
4581 (message-check 'message-id
4582 (let* ((case-fold-search t)
4583 (message-id (message-fetch-field "message-id" t)))
4584 (or (not message-id)
4585 ;; Is there an @ in the ID?
4586 (and (string-match "@" message-id)
4587 ;; Is there a dot in the ID?
4588 (string-match "@[^.]*\\." message-id)
4589 ;; Does the ID end with a dot?
4590 (not (string-match "\\.>" message-id)))
4592 (format "The Message-ID looks strange: \"%s\". Really post? "
4594 ;; Check the Newsgroups & Followup-To headers.
4595 (message-check 'existing-newsgroups
4596 (let* ((case-fold-search t)
4597 (newsgroups (message-fetch-field "newsgroups"))
4598 (followup-to (message-fetch-field "followup-to"))
4599 (groups (message-tokenize-header
4601 (concat newsgroups "," followup-to)
4603 (post-method (if (functionp message-post-method)
4604 (funcall message-post-method)
4605 message-post-method))
4606 ;; KLUDGE to handle nnvirtual groups. Doing this right
4607 ;; would probably involve a new nnoo function.
4608 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
4609 (method (if (and (consp post-method)
4610 (eq (car post-method) 'nnvirtual)
4611 gnus-message-group-art)
4612 (let ((group (car (nnvirtual-find-group-art
4613 (car gnus-message-group-art)
4614 (cdr gnus-message-group-art)))))
4615 (gnus-find-method-for-group group))
4619 (gnus-group-name-decode
4620 (gnus-group-real-name n)
4621 (gnus-group-name-charset method n)))
4622 (gnus-groups-from-server method)))
4625 (when (and (not (equal (car groups) "poster"))
4626 (not (member (car groups) known-groups))
4627 (not (member (car groups) errors)))
4628 (push (car groups) errors))
4631 ;; Gnus is not running.
4632 ((or (not (and (boundp 'gnus-active-hashtb)
4633 gnus-active-hashtb))
4634 (not (boundp 'gnus-read-active-file)))
4636 ;; We don't have all the group names.
4637 ((and (or (not gnus-read-active-file)
4638 (eq gnus-read-active-file 'some))
4642 "Really use %s possibly unknown group%s: %s? "
4643 (if (= (length errors) 1) "this" "these")
4644 (if (= (length errors) 1) "" "s")
4645 (mapconcat 'identity errors ", "))))
4646 ;; There were no errors.
4649 ;; There are unknown groups.
4653 "Really post to %s unknown group%s: %s? "
4654 (if (= (length errors) 1) "this" "these")
4655 (if (= (length errors) 1) "" "s")
4656 (mapconcat 'identity errors ", ")))))))
4657 ;; Check continuation headers.
4658 (message-check 'continuation-headers
4659 (goto-char (point-min))
4660 (let ((do-posting t))
4661 (while (re-search-forward "^[^ \t\n][^:\n]*$" nil t)
4662 (if (y-or-n-p "Fix continuation lines? ")
4664 (goto-char (match-beginning 0))
4666 (unless (y-or-n-p "Send anyway? ")
4667 (setq do-posting nil))))
4669 ;; Check the Newsgroups & Followup-To headers for syntax errors.
4670 (message-check 'valid-newsgroups
4671 (let ((case-fold-search t)
4672 (headers '("Newsgroups" "Followup-To"))
4674 (while (and headers (not error))
4675 (when (setq header (mail-fetch-field (car headers)))
4679 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
4684 (not (string-match "\\.\\'\\|\\.\\." g)))
4685 (message-tokenize-header header ","))))
4692 (format "The %s header looks odd: \"%s\". Really post? "
4693 (car headers) header)))))
4694 (message-check 'repeated-newsgroups
4695 (let ((case-fold-search t)
4696 (headers '("Newsgroups" "Followup-To"))
4697 header error groups group)
4700 (when (setq header (mail-fetch-field (pop headers)))
4701 (setq groups (message-tokenize-header header ","))
4702 (while (setq group (pop groups))
4703 (when (member group groups)
4709 (format "Group %s is repeated in headers. Really post? " error)))))
4710 ;; Check the From header.
4711 (message-check 'from
4712 (let* ((case-fold-search t)
4713 (from (message-fetch-field "from"))
4717 (message "There is no From line. Posting is denied.")
4719 ((or (not (string-match
4721 (setq ad (nth 1 (std11-extract-address-components
4722 from))))) ;larsi@ifi
4723 (string-match "\\.\\." ad) ;larsi@ifi..uio
4724 (string-match "@\\." ad) ;larsi@.ifi.uio
4725 (string-match "\\.$" ad) ;larsi@ifi.uio.
4726 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4727 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
4729 "Denied posting -- the From looks strange: \"%s\"." from)
4731 ((let ((addresses (rfc822-addresses from)))
4732 (while (and addresses
4733 (not (eq (string-to-char (car addresses)) ?\()))
4734 (setq addresses (cdr addresses)))
4737 "Denied posting -- bad From address: \"%s\"." from)
4740 ;; Check the Reply-To header.
4741 (message-check 'reply-to
4742 (let* ((case-fold-search t)
4743 (reply-to (message-fetch-field "reply-to"))
4748 ((string-match "," reply-to)
4750 (format "Multiple Reply-To addresses: \"%s\". Really post? "
4752 ((or (not (string-match
4754 (setq ad (nth 1 (std11-extract-address-components
4755 reply-to))))) ;larsi@ifi
4756 (string-match "\\.\\." ad) ;larsi@ifi..uio
4757 (string-match "@\\." ad) ;larsi@.ifi.uio
4758 (string-match "\\.$" ad) ;larsi@ifi.uio.
4759 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4760 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
4763 "The Reply-To looks strange: \"%s\". Really post? "
4767 (defun message-check-news-body-syntax ()
4769 ;; Check for long lines.
4770 (message-check 'long-lines
4771 (goto-char (point-min))
4773 (concat "^" (regexp-quote mail-header-separator) "$"))
4777 mime-edit-tag-regexp)
4780 (< (- (point) p) 80)))
4781 (zerop (forward-line 1))))
4785 "You have lines longer than 79 characters. Really post? ")))
4786 ;; Check whether the article is empty.
4787 (message-check 'empty
4788 (goto-char (point-min))
4790 (concat "^" (regexp-quote mail-header-separator) "$"))
4793 (goto-char (point-max))
4794 (re-search-backward message-signature-separator nil t)
4796 (or (re-search-backward "[^ \n\t]" b t)
4797 (if (message-gnksa-enable-p 'empty-article)
4798 (y-or-n-p "Empty article. Really post? ")
4799 (message "Denied posting -- Empty article.")
4801 ;; Check for control characters.
4802 (message-check 'control-chars
4803 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
4805 "The article contains control characters. Really post? ")
4807 ;; Check 8bit characters.
4808 (message-check '8bit
4809 (message-check-8bit))
4810 ;; Check excessive size.
4811 (message-check 'size
4812 (if (> (buffer-size) 60000)
4814 (format "The article is %d octets long. Really post? "
4817 ;; Check whether any new text has been added.
4818 (message-check 'new-text
4820 (not message-checksum)
4821 (not (eq (message-checksum) message-checksum))
4822 (if (message-gnksa-enable-p 'quoted-text-only)
4824 "It looks like no new text has been added. Really post? ")
4825 (message "Denied posting -- no new text has been added.")
4827 ;; Check the length of the signature.
4828 (message-check 'signature
4829 (goto-char (point-max))
4830 (if (> (count-lines (point) (point-max)) 5)
4833 "Your .sig is %d lines; it should be max 4. Really post? "
4834 (1- (count-lines (point) (point-max)))))
4836 ;; Ensure that text follows last quoted portion.
4837 (message-check 'quoting-style
4838 (goto-char (point-max))
4839 (let ((no-problem t))
4840 (when (search-backward-regexp "^>[^\n]*\n" nil t)
4841 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
4844 (if (message-gnksa-enable-p 'quoted-text-only)
4845 (y-or-n-p "Your text should follow quoted text. Really post? ")
4847 (goto-char (point-min))
4849 (concat "^" (regexp-quote mail-header-separator) "$"))
4850 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
4851 (y-or-n-p "Your text should follow quoted text. Really post? ")
4852 (message "Denied posting -- only quoted text.")
4855 (defun message-check-mail-syntax ()
4856 "Check the syntax of the message."
4861 ;; We narrow to the headers and check them first.
4864 (message-narrow-to-headers)
4865 (message-check-mail-header-syntax)))
4868 (set-buffer message-edit-buffer)
4869 (message-check-mail-body-syntax))))))
4871 (defun message-check-mail-header-syntax ()
4874 (defun message-check-mail-body-syntax ()
4876 ;; Check 8bit characters.
4877 (message-check '8bit
4878 (message-check-8bit)
4881 (defun message-check-8bit ()
4882 "Check the article contains 8bit characters."
4884 (set-buffer message-encoding-buffer)
4885 (message-narrow-to-headers)
4886 (let* ((case-fold-search t)
4887 (field-value (message-fetch-field "content-transfer-encoding")))
4888 (if (and field-value
4889 (member (downcase field-value) message-8bit-encoding-list))
4892 (set-buffer (get-buffer-create " message syntax"))
4894 (goto-char (point-min))
4895 (set-buffer-multibyte nil)
4896 (insert-buffer-substring message-encoding-buffer)
4897 (goto-char (point-min))
4898 (if (re-search-forward "[^\x00-\x7f]" nil t)
4900 "The article contains 8bit characters. Really post? ")
4903 (defun message-checksum ()
4904 "Return a \"checksum\" for the current buffer."
4907 (goto-char (point-min))
4909 (concat "^" (regexp-quote mail-header-separator) "$"))
4911 (when (not (looking-at "[ \t\n]"))
4912 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
4917 (defun message-do-fcc ()
4918 "Process Fcc headers in the current buffer."
4919 (let ((case-fold-search t)
4920 (coding-system-for-write 'raw-text)
4921 (output-coding-system 'raw-text)
4923 (mml-externalize-attachments message-fcc-externalize-attachments))
4926 (message-narrow-to-headers)
4927 (setq file (message-fetch-field "fcc" t)))
4929 (set-buffer (get-buffer-create " *message temp*"))
4931 (insert-buffer-substring message-encoding-buffer)
4933 (message-narrow-to-headers)
4934 (while (setq file (message-fetch-field "fcc"))
4936 (message-remove-header "fcc" nil t)))
4937 (goto-char (point-min))
4938 (when (re-search-forward
4939 (concat "^" (regexp-quote mail-header-separator) "$")
4941 (replace-match "" t t))
4942 ;; Process FCC operations.
4944 (setq file (pop list))
4945 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
4946 ;; Pipe the article to the program in question.
4947 (call-process-region (point-min) (point-max) shell-file-name
4948 nil nil nil shell-command-switch
4949 (match-string 1 file))
4950 ;; Save the article.
4951 (setq file (expand-file-name file))
4952 (unless (file-exists-p (file-name-directory file))
4953 (make-directory (file-name-directory file) t))
4954 (if (and message-fcc-handler-function
4955 (not (eq message-fcc-handler-function 'rmail-output)))
4956 (funcall message-fcc-handler-function file)
4957 (if (and (file-readable-p file) (mail-file-babyl-p file))
4958 (rmail-output file 1 nil t)
4959 (let ((mail-use-rfc822 t))
4960 (rmail-output file 1 t t))))))
4961 (kill-buffer (current-buffer))))))
4963 (defun message-output (filename)
4964 "Append this article to Unix/babyl mail file FILENAME."
4965 (if (and (file-readable-p filename)
4966 (mail-file-babyl-p filename))
4967 (gnus-output-to-rmail filename t)
4968 (gnus-output-to-mail filename t)))
4970 (defun message-cleanup-headers ()
4971 "Do various automatic cleanups of the headers."
4972 ;; Remove empty lines in the header.
4974 (message-narrow-to-headers)
4975 ;; Remove blank lines.
4976 (while (re-search-forward "^[ \t]*\n" nil t)
4977 (replace-match "" t t))
4979 ;; Correct Newsgroups and Followup-To headers: Change sequence of
4980 ;; spaces to comma and eliminate spaces around commas. Eliminate
4981 ;; embedded line breaks.
4982 (goto-char (point-min))
4983 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
4987 (if (re-search-forward "^[^ \t]" nil t)
4991 (goto-char (point-min))
4992 (while (re-search-forward "\n[ \t]+" nil t)
4993 (replace-match " " t t)) ;No line breaks (too confusing)
4994 (goto-char (point-min))
4995 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
4996 (replace-match "," t t))
4997 (goto-char (point-min))
4998 ;; Remove trailing commas.
4999 (when (re-search-forward ",+$" nil t)
5000 (replace-match "" t t))))))
5002 (defun message-make-date (&optional now)
5003 "Make a valid data header.
5004 If NOW, use that time instead."
5005 (let* ((now (or now (current-time)))
5006 (zone (nth 8 (decode-time now)))
5010 (setq zone (- zone)))
5012 ;; The day name of the %a spec is locale-specific. Pfff.
5013 (format "%s, " (capitalize (car (rassoc (nth 6 (decode-time now))
5014 parse-time-weekdays))))
5015 (format-time-string "%d" now)
5016 ;; The month name of the %b spec is locale-specific. Pfff.
5018 (capitalize (car (rassoc (nth 4 (decode-time now))
5019 parse-time-months))))
5020 (format-time-string "%Y %H:%M:%S " now)
5021 ;; We do all of this because XEmacs doesn't have the %z spec.
5022 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
5024 (defun message-make-followup-subject (subject)
5025 "Make a followup Subject."
5027 ((and (eq message-use-subject-re 'guess)
5028 (string-match message-subject-encoded-re-regexp subject))
5030 (message-use-subject-re
5031 (concat "Re: " (message-strip-subject-re subject)))
5034 (defun message-make-message-id ()
5035 "Make a unique Message-ID."
5036 (concat "<" (message-unique-id)
5037 (let ((psubject (save-excursion (message-fetch-field "subject")))
5039 (save-excursion (message-fetch-field "supersedes"))))
5041 (and message-reply-headers
5042 (mail-header-references message-reply-headers)
5043 (mail-header-subject message-reply-headers)
5046 (message-strip-subject-re
5047 (mail-header-subject message-reply-headers))
5048 (message-strip-subject-re psubject))))
5050 (string-match "_-_@" psupersedes)))
5052 "@" (message-make-fqdn) ">"))
5054 (defvar message-unique-id-char nil)
5056 ;; If you ever change this function, make sure the new version
5057 ;; cannot generate IDs that the old version could.
5058 ;; You might for example insert a "." somewhere (not next to another dot
5059 ;; or string boundary), or modify the "fsf" string.
5060 (defun message-unique-id ()
5061 ;; Don't use microseconds from (current-time), they may be unsupported.
5062 ;; Instead we use this randomly inited counter.
5063 (setq message-unique-id-char
5064 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
5065 ;; (current-time) returns 16-bit ints,
5066 ;; and 2^16*25 just fits into 4 digits i base 36.
5068 (let ((tm (current-time)))
5070 (if (memq system-type '(ms-dos emx vax-vms))
5071 (let ((user (downcase (user-login-name))))
5072 (while (string-match "[^a-z0-9_]" user)
5073 (aset user (match-beginning 0) ?_))
5075 (message-number-base36 (user-uid) -1))
5076 (message-number-base36 (+ (car tm)
5077 (lsh (% message-unique-id-char 25) 16)) 4)
5078 (message-number-base36 (+ (nth 1 tm)
5079 (lsh (/ message-unique-id-char 25) 16)) 4)
5080 ;; Append a given name, because while the generated ID is unique
5081 ;; to this newsreader, other newsreaders might otherwise generate
5082 ;; the same ID via another algorithm.
5085 (defun message-number-base36 (num len)
5090 (concat (message-number-base36 (/ num 36) (1- len))
5091 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
5094 (defun message-make-organization ()
5095 "Make an Organization header."
5096 (let* ((organization
5097 (when message-user-organization
5098 (if (functionp message-user-organization)
5099 (funcall message-user-organization)
5100 message-user-organization))))
5102 (set-buffer-multibyte t)
5103 (cond ((stringp organization)
5104 (insert organization))
5105 ((and (eq t organization)
5106 message-user-organization-file
5107 (file-exists-p message-user-organization-file))
5108 (insert-file-contents message-user-organization-file)))
5109 (goto-char (point-min))
5110 (while (re-search-forward "[\t\n]+" nil t)
5111 (replace-match "" t t))
5112 (unless (zerop (buffer-size))
5115 (defun message-make-lines ()
5116 "Count the number of lines and return numeric string."
5121 (int-to-string (count-lines (point) (point-max))))))
5123 (defun message-make-references ()
5124 "Return the References header for this message."
5125 (when message-reply-headers
5126 (let ((message-id (mail-header-message-id message-reply-headers))
5127 (references (mail-header-references message-reply-headers))
5129 (if (or references message-id)
5130 (concat (or references "") (and references " ")
5134 (defun message-make-in-reply-to ()
5135 "Return the In-Reply-To header for this message."
5136 (when message-reply-headers
5137 (let ((from (mail-header-from message-reply-headers))
5138 (date (mail-header-date message-reply-headers))
5139 (msg-id (mail-header-message-id message-reply-headers)))
5141 (let ((name (std11-extract-address-components from)))
5142 (concat msg-id (if msg-id " (")
5146 (if (or (not date) (string= date ""))
5147 "(unknown date)" date)
5148 "\"" (if msg-id ")")))))))
5150 (defun message-make-distribution ()
5151 "Make a Distribution header."
5152 (let ((orig-distribution (message-fetch-reply-field "distribution")))
5153 (cond ((functionp message-distribution-function)
5154 (funcall message-distribution-function))
5155 (t orig-distribution))))
5157 (defun message-make-expires ()
5158 "Return an Expires header based on `message-expires'."
5159 (let ((current (current-time))
5160 (future (* 1.0 message-expires 60 60 24)))
5161 ;; Add the future to current.
5162 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
5163 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
5164 (message-make-date current)))
5166 (defun message-make-path ()
5168 (let ((login-name (user-login-name)))
5169 (cond ((null message-user-path)
5170 (concat (system-name) "!" login-name))
5171 ((stringp message-user-path)
5172 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
5173 (concat message-user-path "!" login-name))
5176 (defun message-make-from ()
5177 "Make a From header."
5178 (let* ((style message-from-style)
5179 (login (message-make-address))
5181 (or (and (boundp 'user-full-name)
5184 (when (string= fullname "&")
5185 (setq fullname (user-login-name)))
5187 (set-buffer-multibyte t)
5190 (equal fullname ""))
5192 ((or (eq style 'angles)
5193 (and (not (eq style 'parens))
5194 ;; Use angles if no quoting is needed, or if parens would
5195 ;; need quoting too.
5196 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
5197 (let ((tmp (concat fullname nil)))
5198 (while (string-match "([^()]*)" tmp)
5199 (aset tmp (match-beginning 0) ?-)
5200 (aset tmp (1- (match-end 0)) ?-))
5201 (string-match "[\\()]" tmp)))))
5203 (goto-char (point-min))
5204 ;; Look for a character that cannot appear unquoted
5205 ;; according to RFC 822.
5206 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
5207 ;; Quote fullname, escaping specials.
5208 (goto-char (point-min))
5210 (while (re-search-forward "[\"\\]" nil 1)
5211 (replace-match "\\\\\\&" t))
5213 (insert " <" login ">"))
5214 (t ; 'parens or default
5216 (let ((fullname-start (point)))
5218 (goto-char fullname-start)
5219 ;; RFC 822 says \ and nonmatching parentheses
5220 ;; must be escaped in comments.
5221 ;; Escape every instance of ()\ ...
5222 (while (re-search-forward "[()\\]" nil 1)
5223 (replace-match "\\\\\\&" t))
5224 ;; ... then undo escaping of matching parentheses,
5225 ;; including matching nested parentheses.
5226 (goto-char fullname-start)
5227 (while (re-search-forward
5228 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
5230 (replace-match "\\1(\\3)" t)
5231 (goto-char fullname-start)))
5235 (defun message-make-sender ()
5236 "Return the \"real\" user address.
5237 This function tries to ignore all user modifications, and
5238 give as trustworthy answer as possible."
5239 (concat (user-login-name) "@" (system-name)))
5241 (defun message-make-address ()
5242 "Make the address of the user."
5243 (or (message-user-mail-address)
5244 (concat (user-login-name) "@" (message-make-domain))))
5246 (defun message-user-mail-address ()
5247 "Return the pertinent part of `user-mail-address'."
5248 (when (and user-mail-address
5249 (string-match "@.*\\." user-mail-address))
5250 (if (string-match " " user-mail-address)
5251 (nth 1 (std11-extract-address-components user-mail-address))
5252 user-mail-address)))
5254 (defun message-sendmail-envelope-from ()
5255 "Return the envelope from."
5256 (cond ((eq message-sendmail-envelope-from 'header)
5257 (nth 1 (std11-extract-address-components
5258 (message-fetch-field "from"))))
5259 ((stringp message-sendmail-envelope-from)
5260 message-sendmail-envelope-from)
5262 (message-make-address))))
5264 (defun message-make-fqdn ()
5265 "Return user's fully qualified domain name."
5266 (let* ((system-name (system-name))
5267 (user-mail (message-user-mail-address))
5270 (string-match "@\\(.*\\)\\'" user-mail))
5271 (match-string 1 user-mail)))
5272 (case-fold-search t))
5274 ((and message-user-fqdn
5275 (stringp message-user-fqdn)
5276 (string-match message-valid-fqdn-regexp message-user-fqdn)
5277 (not (string-match message-bogus-system-names message-user-fqdn)))
5279 ;; `message-user-fqdn' seems to be valid
5280 ((and (string-match message-valid-fqdn-regexp system-name)
5281 (not (string-match message-bogus-system-names system-name)))
5282 ;; `system-name' returned the right result.
5284 ;; Try `mail-host-address'.
5285 ((and (boundp 'mail-host-address)
5286 (stringp mail-host-address)
5287 (string-match message-valid-fqdn-regexp mail-host-address)
5288 (not (string-match message-bogus-system-names mail-host-address)))
5290 ;; We try `user-mail-address' as a backup.
5292 (stringp user-domain)
5293 (string-match message-valid-fqdn-regexp user-domain)
5294 (not (string-match message-bogus-system-names user-domain)))
5296 ;; Default to this bogus thing.
5299 ".i-did-not-set--mail-host-address--so-tickle-me")))))
5301 (defun message-make-host-name ()
5302 "Return the name of the host."
5303 (let ((fqdn (message-make-fqdn)))
5304 (string-match "^[^.]+\\." fqdn)
5305 (substring fqdn 0 (1- (match-end 0)))))
5307 (defun message-make-domain ()
5308 "Return the domain name."
5309 (or mail-host-address
5310 (message-make-fqdn)))
5312 (defun message-to-list-only ()
5313 "Send a message to the list only.
5314 Remove all addresses but the list address from To and Cc headers."
5316 (let ((listaddr (message-make-mail-followup-to t)))
5319 (message-remove-header "to")
5320 (message-remove-header "cc")
5321 (message-position-on-field "To" "X-Draft-From")
5322 (insert listaddr)))))
5324 (defun message-make-mail-followup-to (&optional only-show-subscribed)
5325 "Return the Mail-Followup-To header.
5326 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5327 subscribed address (and not the additional To and Cc header contents)."
5328 (let* ((case-fold-search t)
5329 (to (message-fetch-field "To"))
5330 (cc (message-fetch-field "cc"))
5331 (msg-recipients (concat to (and to cc ", ") cc))
5333 (mapcar 'mail-strip-quoted-names
5334 (message-tokenize-header msg-recipients)))
5336 (if message-subscribed-address-file
5337 (let (begin end item re)
5340 (insert-file-contents message-subscribed-address-file)
5342 (setq begin (point))
5345 (if (bolp) (setq end (1- end)))
5346 (setq item (regexp-quote (buffer-substring begin end)))
5347 (if re (setq re (concat re "\\|" item))
5348 (setq re (concat "\\`\\(" item))))
5349 (and re (list (concat re "\\)\\'"))))))))
5350 (mft-regexps (apply 'append message-subscribed-regexps
5351 (mapcar 'regexp-quote
5352 message-subscribed-addresses)
5355 message-subscribed-address-functions))))
5357 (let ((subscribed-lists nil)
5359 (loop for recipient in recipients
5360 when (loop for regexp in mft-regexps
5361 when (string-match regexp recipient) return t)
5364 (if only-show-subscribed
5366 msg-recipients))))))
5368 ;; Dummy to avoid byte-compile warning.
5369 (defvar mule-version)
5370 (defvar emacs-beta-version)
5371 (defvar xemacs-codename)
5372 (defvar gnus-inviolable-extended-version)
5374 (defun message-make-user-agent ()
5375 "Return user-agent info if the value `message-user-agent' is non-nil. If the
5376 \"User-Agent\" field has already exist, remove it."
5377 (when message-user-agent
5379 (goto-char (point-min))
5380 (let ((case-fold-search t))
5381 (when (re-search-forward "^User-Agent:[\t ]*" nil t)
5382 (delete-region (match-beginning 0) (1+ (std11-field-end)))))))
5385 (defun message-idna-inside-rhs-p ()
5386 "Return t iff point is inside a RHS (heuristically).
5387 Only works properly if header contains mailbox-list or address-list.
5388 I.e., calling it on a Subject: header is useless."
5390 (narrow-to-region (save-excursion (or (re-search-backward "^[^ \t]" nil t)
5392 (save-excursion (or (re-search-forward "^[^ \t]" nil t)
5394 (if (re-search-backward "[\\\n\r\t ]"
5395 (save-excursion (search-backward "@" nil t)) t)
5396 ;; whitespace between @ and point
5398 (let ((dquote 1) (paren 1))
5399 (while (save-excursion (re-search-backward "[^\\]\"" nil t dquote))
5401 (while (save-excursion (re-search-backward "[^\\]\(" nil t paren))
5403 (and (= (% dquote 2) 1) (= (% paren 2) 1))))))
5405 (autoload 'idna-to-ascii "idna")
5407 (defun message-idna-to-ascii-rhs-1 (header)
5408 "Interactively potentially IDNA encode domain names in HEADER."
5409 (let (rhs ace start startpos endpos ovl)
5410 (goto-char (point-min))
5411 (while (re-search-forward (concat "^" header) nil t)
5412 (while (re-search-forward "@\\([^ \t\r\n>,]+\\)"
5414 (re-search-forward "^[^ \t]" nil t))
5417 (setq rhs (match-string-no-properties 1)
5418 startpos (match-beginning 1)
5419 endpos (match-end 1))
5420 (when (save-match-data
5421 (and (message-idna-inside-rhs-p)
5422 (setq ace (idna-to-ascii rhs))
5423 (not (string= rhs ace))
5424 (if (eq message-use-idna 'ask)
5427 (setq ovl (message-make-overlay startpos
5429 (message-overlay-put ovl 'face 'highlight)
5431 (format "Replace with `%s'? " ace)))
5433 (message-delete-overlay ovl))
5435 (replace-match (concat "@" ace)))))))
5437 (defun message-idna-to-ascii-rhs ()
5438 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
5439 See `message-idna-encode'."
5441 (when message-use-idna
5444 (message-narrow-to-head)
5445 (message-idna-to-ascii-rhs-1 "From")
5446 (message-idna-to-ascii-rhs-1 "To")
5447 (message-idna-to-ascii-rhs-1 "Cc")))))
5449 (defun message-generate-headers (headers)
5450 "Prepare article HEADERS.
5451 Headers already prepared in the buffer are not modified."
5452 (setq headers (append headers message-required-headers))
5454 (message-narrow-to-headers)
5455 (let* ((Date (message-make-date))
5456 (Message-ID (message-make-message-id))
5457 (Organization (message-make-organization))
5458 (From (message-make-from))
5459 (Path (message-make-path))
5462 (In-Reply-To (message-make-in-reply-to))
5463 (References (message-make-references))
5465 (Distribution (message-make-distribution))
5466 (Lines (message-make-lines))
5467 (User-Agent (message-make-user-agent))
5468 (Expires (message-make-expires))
5469 (case-fold-search t)
5471 header value elem header-string)
5472 ;; First we remove any old generated headers.
5473 (let ((headers message-deletable-headers))
5474 (unless (buffer-modified-p)
5475 (setq headers (delq 'Message-ID (copy-sequence headers))))
5477 (goto-char (point-min))
5478 (and (re-search-forward
5479 (concat "^" (symbol-name (car headers)) ": *") nil t)
5480 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
5481 (message-delete-line))
5483 ;; Go through all the required headers and see if they are in the
5484 ;; articles already. If they are not, or are empty, they are
5485 ;; inserted automatically - except for Subject, Newsgroups and
5488 (goto-char (point-min))
5489 (setq elem (pop headers))
5491 (if (eq (car elem) 'optional)
5492 (setq header (cdr elem)
5494 (setq header (car elem)))
5496 (setq header-string (if (stringp header)
5498 (symbol-name header)))
5499 (when (or (not (re-search-forward
5501 (regexp-quote (downcase header-string))
5505 ;; The header was found. We insert a space after the
5506 ;; colon, if there is none.
5507 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
5508 ;; Find out whether the header is empty.
5509 (looking-at "[ \t]*\n[^ \t]")))
5510 ;; So we find out what value we should insert.
5514 (eq (car elem) 'optional)
5515 (not (member header-string message-inserted-headers)))
5516 ;; This is an optional header. If the cdr of this
5517 ;; is something that is nil, then we do not insert
5519 (setq header (cdr elem))
5520 (or (and (functionp (cdr elem))
5521 (funcall (cdr elem)))
5522 (and (boundp (cdr elem))
5523 (symbol-value (cdr elem)))))
5525 ;; The element is a cons. Either the cdr is a
5526 ;; string to be inserted verbatim, or it is a
5527 ;; function, and we insert the value returned from
5529 (or (and (stringp (cdr elem))
5531 (and (functionp (cdr elem))
5532 (funcall (cdr elem)))))
5533 ((and (boundp header)
5534 (symbol-value header))
5535 ;; The element is a symbol. We insert the value
5536 ;; of this symbol, if any.
5537 (symbol-value header))
5538 ((not (message-check-element header))
5539 ;; We couldn't generate a value for this header,
5540 ;; so we just ask the user.
5541 (read-from-minibuffer
5542 (format "Empty header for %s; enter value: " header)))))
5543 ;; Finally insert the header.
5545 (not (equal value "")))
5549 ;; This header didn't exist, so we insert it.
5550 (goto-char (point-max))
5552 (cdr (assq header message-header-format-alist))))
5554 (funcall formatter header value)
5555 (insert header-string ": " value))
5556 ;; We check whether the value was ended by a
5557 ;; newline. If now, we insert one.
5561 ;; The value of this header was empty, so we clear
5562 ;; totally and insert the new value.
5563 (delete-region (point) (gnus-point-at-eol))
5564 ;; If the header is optional, and the header was
5565 ;; empty, we can't insert it anyway.
5567 (push header-string message-inserted-headers)
5571 ;; Add the deletable property to the headers that require it.
5572 (and (memq header message-deletable-headers)
5573 (progn (beginning-of-line) (looking-at "[^:]+: "))
5574 (add-text-properties
5575 (point) (match-end 0)
5576 '(message-deletable t face italic) (current-buffer)))))))
5577 ;; Insert new Sender if the From is strange.
5578 (let ((from (message-fetch-field "from"))
5579 (sender (message-fetch-field "sender"))
5580 (secure-sender (message-make-sender)))
5582 (not (message-check-element 'sender))
5585 (cadr (std11-extract-address-components from)))
5586 (downcase secure-sender)))
5591 (cadr (std11-extract-address-components sender)))
5592 (downcase secure-sender)))))
5593 (goto-char (point-min))
5594 ;; Rename any old Sender headers to Original-Sender.
5595 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
5597 (insert "Original-")
5598 (beginning-of-line))
5599 (when (or (message-news-p)
5600 (string-match "@.+\\.." secure-sender))
5601 (insert "Sender: " secure-sender "\n"))))
5603 (message-idna-to-ascii-rhs))))
5605 (defun message-insert-courtesy-copy ()
5606 "Insert a courtesy message in mail copies of combined messages."
5610 (message-narrow-to-headers)
5611 (when (setq newsgroups (message-fetch-field "newsgroups"))
5612 (goto-char (point-max))
5613 (insert "Posted-To: " newsgroups "\n")))
5615 (when message-courtesy-message
5617 ((string-match "%s" message-courtesy-message)
5618 (insert (format message-courtesy-message newsgroups)))
5620 (insert message-courtesy-message)))))))
5623 ;;; Setting up a message buffer
5626 (defun message-fill-address (header value)
5628 (narrow-to-region (point) (point))
5629 (insert (capitalize (symbol-name header))
5631 (if (consp value) (car value) value)
5633 (narrow-to-region (point-min) (1- (point-max)))
5635 (goto-char (point-min))
5637 (skip-chars-forward "^,\"" (point-max))
5638 (if (or (eq (char-after) ?,)
5641 (if (and (> (current-column) 78)
5645 (looking-at "[ \t]*")
5646 (replace-match "\n " t t)))
5647 (setq last (1+ (point))))
5648 (setq quoted (not quoted)))
5651 (goto-char (point-max))
5655 (defun message-fill-references (header value)
5656 (insert (capitalize (symbol-name header))
5658 (std11-fill-msg-id-list-string
5659 (if (consp value) (car value) value))
5662 (defun message-split-line ()
5663 "Split current line, moving portion beyond point vertically down.
5664 If the current line has `message-yank-prefix', insert it on the new line."
5667 (split-line message-yank-prefix) ;; Emacs 21.3.50+ supports arg.
5672 (defun message-fill-header (header value)
5673 (let ((begin (point))
5676 (insert (capitalize (symbol-name header))
5678 (if (consp value) (car value) value)
5681 (narrow-to-region begin (point))
5682 (fill-region-as-paragraph begin (point))
5683 ;; Tapdance around looong Message-IDs.
5685 (when (looking-at "[ \t]*$")
5686 (message-delete-line))
5688 (re-search-forward ":" nil t)
5689 (when (looking-at "\n[ \t]+")
5690 (replace-match " " t t))
5691 (goto-char (point-max)))))
5693 (defun message-shorten-1 (list cut surplus)
5694 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
5695 (setcdr (nthcdr (- cut 2) list)
5696 (nthcdr (+ (- cut 2) surplus 1) list)))
5698 (defun message-shorten-references (header references)
5699 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
5700 If folding is disallowed, also check that the REFERENCES are less
5701 than 988 characters long, and if they are not, trim them until they are."
5708 (goto-char (point-min))
5709 ;; Cons a list of valid references.
5710 (while (re-search-forward "<[^>]+>" nil t)
5711 (push (match-string 0) refs))
5712 (setq refs (nreverse refs)
5713 count (length refs)))
5715 ;; If the list has more than MAXCOUNT elements, trim it by
5716 ;; removing the CUTth element and the required number of
5717 ;; elements that follow.
5718 (when (> count maxcount)
5719 (let ((surplus (- count maxcount)))
5720 (message-shorten-1 refs cut surplus)
5721 (decf count surplus)))
5723 ;; If folding is disallowed, make sure the total length (including
5724 ;; the spaces between) will be less than MAXSIZE characters.
5726 ;; Only disallow folding for News messages. At this point the headers
5727 ;; have not been generated, thus we use message-this-is-news directly.
5728 (when (and message-this-is-news message-cater-to-broken-inn)
5730 (totalsize (+ (apply #'+ (mapcar #'length refs))
5733 (ptr (nthcdr (1- cut) refs)))
5734 ;; Decide how many elements to cut off...
5735 (while (> totalsize maxsize)
5736 (decf totalsize (1+ (length (car ptr))))
5738 (setq ptr (cdr ptr)))
5741 (message-shorten-1 refs cut surplus))))
5743 ;; Finally, collect the references back into a string and insert
5744 ;; it into the buffer.
5745 (let ((refstring (mapconcat #'identity refs " ")))
5746 (if (and message-this-is-news message-cater-to-broken-inn)
5747 (insert (capitalize (symbol-name header)) ": "
5749 (message-fill-header header refstring)))))
5751 (defun message-position-point ()
5752 "Move point to where the user probably wants to find it."
5753 (message-narrow-to-headers)
5755 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
5756 (search-backward ":" )
5759 (if (eq (char-after) ? )
5763 (goto-char (point-max))
5766 (unless (looking-at "$")
5770 (defcustom message-beginning-of-line t
5771 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
5772 goes to beginning of header values."
5773 :group 'message-buffers
5776 (defun message-beginning-of-line (&optional n)
5777 "Move point to beginning of header value or to beginning of line.
5778 The prefix argument N is passed directly to `beginning-of-line'.
5780 This command is identical to `beginning-of-line' if point is
5781 outside the message header or if the option `message-beginning-of-line'
5784 If point is in the message header and on a (non-continued) header
5785 line, move point to the beginning of the header value. If point
5786 is already there, move point to beginning of line. Therefore,
5787 repeated calls will toggle point between beginning of field and
5790 (let ((zrs 'zmacs-region-stays))
5791 (when (and (interactive-p) (boundp zrs))
5793 (if (and message-beginning-of-line
5794 (message-point-in-header-p))
5795 (let* ((here (point))
5796 (bol (progn (beginning-of-line n) (point)))
5797 (eol (gnus-point-at-eol))
5798 (eoh (re-search-forward ": *" eol t)))
5799 (if (or (not eoh) (equal here eoh))
5802 (beginning-of-line n)))
5804 (defun message-buffer-name (type &optional to group)
5805 "Return a new (unique) buffer name based on TYPE and TO."
5807 ;; Generate a new buffer name The Message Way.
5808 ((eq message-generate-new-buffers 'unique)
5809 (generate-new-buffer-name
5813 (or (car (std11-extract-address-components to))
5816 (if (and group (not (string= group ""))) (concat " on " group) "")
5818 ;; Check whether `message-generate-new-buffers' is a function,
5819 ;; and if so, call it.
5820 ((functionp message-generate-new-buffers)
5821 (funcall message-generate-new-buffers type to group))
5822 ((eq message-generate-new-buffers 'unsent)
5823 (generate-new-buffer-name
5824 (concat "*unsent " type
5827 (or (car (std11-extract-address-components to))
5830 (if (and group (not (string= group ""))) (concat " on " group) "")
5832 ;; Use standard name.
5834 (format "*%s message*" type))))
5836 (defmacro message-pop-to-buffer-1 (buffer)
5838 (let (special-display-buffer-names
5839 special-display-regexps
5840 same-window-buffer-names
5841 same-window-regexps)
5842 (pop-to-buffer ,buffer))
5843 (pop-to-buffer ,buffer)))
5845 (defun message-pop-to-buffer (name)
5846 "Pop to buffer NAME, and warn if it already exists and is modified."
5847 (let ((buffer (get-buffer name))
5848 (pop-up-frames (and (or (static-if (featurep 'xemacs)
5849 (device-on-window-system-p)
5851 (>= emacs-major-version 20))
5852 message-use-multi-frames)))
5854 (buffer-name buffer))
5856 (message-pop-to-buffer-1 buffer)
5857 (when (and (buffer-modified-p)
5859 "Message already being composed; erase? ")))
5860 (error "Message being composed")))
5861 (message-pop-to-buffer-1 name))
5865 (set (make-local-variable 'message-original-frame) (selected-frame)))))
5867 (defun message-do-send-housekeeping ()
5868 "Kill old message buffers."
5869 ;; We might have sent this buffer already. Delete it from the
5871 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
5872 (while (and message-max-buffers
5874 (>= (length message-buffer-list) message-max-buffers))
5875 ;; Kill the oldest buffer -- unless it has been changed.
5876 (let ((buffer (pop message-buffer-list)))
5877 (when (and (buffer-name buffer)
5878 (not (buffer-modified-p buffer)))
5879 (kill-buffer buffer))))
5880 ;; Rename the buffer.
5881 (if message-send-rename-function
5882 (funcall message-send-rename-function)
5883 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
5885 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
5887 (let ((name (match-string 2 (buffer-name)))
5889 (if (not (or (null name)
5890 (string-equal name "mail")
5891 (string-equal name "posting")))
5892 (setq name (concat "*sent " name "*"))
5893 (message-narrow-to-headers)
5894 (setq to (message-fetch-field "to"))
5895 (setq group (message-fetch-field "newsgroups"))
5899 (to (concat "*sent mail to "
5900 (or (car (std11-extract-address-components to))
5902 ((and group (not (string= group "")))
5903 (concat "*sent posting on " group "*"))
5904 (t "*sent mail*"))))
5905 (unless (string-equal name (buffer-name))
5906 (rename-buffer name t)))))
5907 ;; Push the current buffer onto the list.
5908 (when message-max-buffers
5909 (setq message-buffer-list
5910 (nconc message-buffer-list (list (current-buffer))))))
5912 (defun message-mail-user-agent ()
5914 ((not message-mail-user-agent) nil)
5915 ((eq message-mail-user-agent t) mail-user-agent)
5916 (t message-mail-user-agent))))
5917 (if (memq mua '(message-user-agent gnus-user-agent))
5921 (defun message-setup (headers &optional replybuffer actions switch-function)
5922 (let ((mua (message-mail-user-agent))
5923 subject to field yank-action)
5924 (if (not (and message-this-is-mail mua))
5925 (message-setup-1 headers replybuffer actions)
5927 (setq yank-action (list 'insert-buffer replybuffer)))
5928 (setq headers (copy-sequence headers))
5929 (setq field (assq 'Subject headers))
5931 (setq subject (cdr field))
5932 (setq headers (delq field headers)))
5933 (setq field (assq 'To headers))
5935 (setq to (cdr field))
5936 (setq headers (delq field headers)))
5937 (let ((mail-user-agent mua))
5938 (compose-mail to subject
5939 (mapcar (lambda (item)
5941 (format "%s" (car item))
5944 nil switch-function yank-action actions)))))
5946 (defun message-headers-to-generate (headers included-headers excluded-headers)
5947 "Return a list that includes all headers from HEADERS.
5948 If INCLUDED-HEADERS is a list, just include those headers. If if is
5949 t, include all headers. In any case, headers from EXCLUDED-HEADERS
5953 (dolist (header headers)
5954 (setq header-name (cond
5955 ((and (consp header)
5956 (eq (car header) 'optional))
5957 ;; On the form (optional . Header)
5960 ;; On the form (Header . function)
5965 (when (and (not (memq header-name excluded-headers))
5966 (or (eq included-headers t)
5967 (memq header-name included-headers)))
5968 (push header result)))
5971 (defun message-setup-1 (headers &optional replybuffer actions)
5972 (dolist (action actions)
5974 (add-to-list 'message-send-actions
5975 `(apply ',(car action) ',(cdr action)))))
5976 (setq message-reply-buffer
5977 (or (message-get-parameter 'reply-buffer)
5979 (goto-char (point-min))
5980 ;; Insert all the headers.
5983 (alist message-header-format-alist))
5985 (unless (assq (caar h) message-header-format-alist)
5986 (push (list (caar h)) alist))
5990 (delete-region (point) (progn (forward-line -1) (point)))
5991 (when message-default-headers
5992 (insert message-default-headers)
5993 (or (bolp) (insert ?\n)))
5997 (insert mail-header-separator "\n")
6001 (when (message-news-p)
6002 (when message-default-news-headers
6003 (insert message-default-news-headers)
6004 (or (bolp) (insert ?\n)))
6005 (when message-generate-headers-first
6006 (message-generate-headers
6007 (message-headers-to-generate
6008 (append message-required-news-headers
6009 message-required-headers)
6010 message-generate-headers-first
6011 '(Lines Subject)))))
6012 (when (message-mail-p)
6013 (when message-default-mail-headers
6014 (insert message-default-mail-headers)
6015 (or (bolp) (insert ?\n)))
6017 (message-narrow-to-headers)
6018 (if (and replybuffer
6019 message-alternative-emails)
6020 (message-use-alternative-email-as-from)))
6021 (when message-generate-headers-first
6022 (message-generate-headers
6023 (message-headers-to-generate
6024 (append message-required-mail-headers
6025 message-required-headers)
6026 message-generate-headers-first
6027 '(Lines Subject)))))
6028 (run-hooks 'message-signature-setup-hook)
6029 (message-insert-signature)
6031 (message-narrow-to-headers)
6032 (run-hooks 'message-header-setup-hook))
6033 (set-buffer-modified-p nil)
6034 (setq buffer-undo-list nil)
6035 (run-hooks 'message-setup-hook)
6036 (message-position-point)
6039 (defun message-set-auto-save-file-name ()
6040 "Associate the message buffer with a file in the drafts directory."
6041 (when message-auto-save-directory
6042 (unless (file-directory-p
6043 (directory-file-name message-auto-save-directory))
6044 (make-directory message-auto-save-directory t))
6046 (setq message-draft-article
6047 (nndraft-request-associate-buffer "drafts"))
6048 (setq buffer-file-name (expand-file-name
6049 (if (memq system-type
6050 '(ms-dos ms-windows windows-nt
6051 cygwin cygwin32 win32 w32
6055 message-auto-save-directory))
6056 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
6057 (clear-visited-file-modtime)
6058 (static-if (boundp 'MULE)
6059 (set-file-coding-system message-draft-coding-system)
6060 (setq buffer-file-coding-system message-draft-coding-system))))
6062 (defun message-disassociate-draft ()
6063 "Disassociate the message buffer from the drafts directory."
6064 (when message-draft-article
6065 (nndraft-request-expire-articles
6066 (list message-draft-article) "drafts" nil t)))
6068 (defun message-insert-headers ()
6069 "Generate the headers for the article."
6073 (message-narrow-to-headers)
6074 (when (message-news-p)
6075 (message-generate-headers
6078 (copy-sequence message-required-news-headers)))))
6079 (when (message-mail-p)
6080 (message-generate-headers
6083 (copy-sequence message-required-mail-headers))))))))
6088 ;;; Commands for interfacing with message
6092 (defun message-mail (&optional to subject
6093 other-headers continue switch-function
6094 yank-action send-actions)
6095 "Start editing a mail message to be sent.
6096 OTHER-HEADERS is an alist of header/value pairs."
6098 (let ((message-this-is-mail t) replybuffer)
6099 (unless (message-mail-user-agent)
6100 (message-pop-to-buffer (message-buffer-name "mail" to)))
6101 ;; FIXME: message-mail should do something if YANK-ACTION is not
6103 (and (consp yank-action) (eq (car yank-action) 'insert-buffer)
6104 (setq replybuffer (nth 1 yank-action)))
6107 `((To . ,(or to "")) (Subject . ,(or subject "")))
6108 (when other-headers other-headers))
6109 replybuffer send-actions)
6110 ;; FIXME: Should return nil if failure.
6114 (defun message-news (&optional newsgroups subject)
6115 "Start editing a news article to be sent."
6117 (let ((message-this-is-news t))
6118 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
6119 (message-setup `((Newsgroups . ,(or newsgroups ""))
6120 (Subject . ,(or subject ""))))))
6122 (defun message-get-reply-headers (wide &optional to-address address-headers)
6123 (let (follow-to mct never-mct to cc author mft recipients)
6124 ;; Find all relevant headers we need.
6125 (let ((mrt (when message-use-mail-reply-to
6126 (message-fetch-field "mail-reply-to")))
6127 (reply-to (message-fetch-field "reply-to")))
6128 (setq to (message-fetch-field "to")
6129 cc (message-fetch-field "cc")
6130 mct (when message-use-mail-copies-to
6131 (message-fetch-field "mail-copies-to"))
6134 (message-fetch-field "from")
6136 mft (when (and (not (or to-address mrt reply-to))
6137 message-use-mail-followup-to)
6138 (message-fetch-field "mail-followup-to"))))
6141 ;; Handle special values of Mail-Copies-To.
6143 (cond ((or (equal (downcase mct) "never")
6144 (equal (downcase mct) "nobody"))
6145 (when (or (not (eq message-use-mail-copies-to 'ask))
6147 (concat "Obey Mail-Copies-To: never? ") t "\
6148 You should normally obey the Mail-Copies-To: header.
6150 `Mail-Copies-To: " mct "'
6151 directs you not to send your response to the author."))
6154 ((or (equal (downcase mct) "always")
6155 (equal (downcase mct) "poster"))
6156 (if (or (not (eq message-use-mail-copies-to 'ask))
6158 (concat "Obey Mail-Copies-To: always? ") t "\
6159 You should normally obey the Mail-Copies-To: header.
6161 `Mail-Copies-To: " mct "'
6162 sends a copy of your response to the author."))
6165 ((and (eq message-use-mail-copies-to 'ask)
6166 (not (message-y-or-n-p
6167 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
6168 You should normally obey the Mail-Copies-To: header.
6170 `Mail-Copies-To: " mct "'
6171 sends a copy of your response to " (if (string-match "," mct)
6172 "the specified addresses"
6173 "that address") ".")))
6176 ;; Build (textual) list of new recipient addresses.
6179 (setq recipients (concat ", " author)))
6181 (dolist (header address-headers)
6182 (let ((value (message-fetch-field header)))
6184 (setq recipients (concat recipients ", " value))))))
6186 (string-match "[^ \t,]" mft)
6187 (or (not (eq message-use-mail-followup-to 'ask))
6188 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
6189 You should normally obey the Mail-Followup-To: header. In this
6190 article, it has the value of
6194 which directs your response to " (if (string-match "," mft)
6195 "the specified addresses"
6196 "that address only") ".
6198 Most commonly, Mail-Followup-To is used by a mailing list poster to
6199 express that responses should be sent to just the list, and not the
6202 If a message is posted to several mailing lists, Mail-Followup-To may
6203 also be used to direct the following discussion to one list only,
6204 because discussions that are spread over several lists tend to be
6205 fragmented and very difficult to follow.
6207 Also, some source/announcement lists are not intended for discussion;
6208 responses here are directed to other addresses.")))
6209 (setq recipients (concat ", " mft)))
6211 (setq recipients (concat ", " to-address))
6212 ;; If the author explicitly asked for a copy, we don't deny it to them.
6213 (if mct (setq recipients (concat recipients ", " mct))))
6215 (setq recipients (if never-mct "" (concat ", " author)))
6216 (if to (setq recipients (concat recipients ", " to)))
6217 (if cc (setq recipients (concat recipients ", " cc)))
6218 (if mct (setq recipients (concat recipients ", " mct)))))
6219 (if (>= (length recipients) 2)
6220 ;; Strip the leading ", ".
6221 (setq recipients (substring recipients 2)))
6222 ;; Squeeze whitespace.
6223 (while (string-match "[ \t][ \t]+" recipients)
6224 (setq recipients (replace-match " " t t recipients)))
6225 ;; Remove addresses that match `rmail-dont-reply-to-names'.
6226 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
6227 (setq recipients (rmail-dont-reply-to recipients)))
6228 ;; Perhaps "Mail-Copies-To: never" removed the only address?
6229 (if (string-equal recipients "")
6230 (setq recipients author))
6231 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
6235 (cons (downcase (mail-strip-quoted-names addr)) addr))
6236 (message-tokenize-header recipients)))
6237 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
6238 (let ((s recipients))
6240 (setq recipients (delq (assoc (car (pop s)) s) recipients))))
6242 ;; Remove hierarchical lists that are contained within each other,
6243 ;; if message-hierarchical-addresses is defined.
6244 (when message-hierarchical-addresses
6245 (let ((plain-addrs (mapcar 'car recipients))
6248 (setq subaddrs (assoc (car plain-addrs)
6249 message-hierarchical-addresses)
6250 plain-addrs (cdr plain-addrs))
6252 (setq subaddrs (cdr subaddrs))
6254 (setq recip (assoc (car subaddrs) recipients)
6255 subaddrs (cdr subaddrs))
6257 (setq recipients (delq recip recipients))))))))
6259 ;; Build the header alist. Allow the user to be asked whether
6260 ;; or not to reply to all recipients in a wide reply.
6261 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
6262 (when (and recipients
6263 (or (not message-wide-reply-confirm-recipients)
6264 (y-or-n-p "Reply to all recipients? ")))
6265 (setq recipients (mapconcat
6266 (lambda (addr) (cdr addr)) recipients ", "))
6267 (if (string-match "^ +" recipients)
6268 (setq recipients (substring recipients (match-end 0))))
6269 (push (cons 'Cc recipients) follow-to)))
6273 (defun message-reply (&optional to-address wide)
6274 "Start editing a reply to the article in the current buffer."
6276 (require 'gnus-sum) ; for gnus-list-identifiers
6277 (let ((cur (current-buffer))
6279 references message-id follow-to
6280 (inhibit-point-motion-hooks t)
6281 (message-this-is-mail t)
6282 gnus-warning in-reply-to)
6284 (message-narrow-to-head-1)
6285 ;; Allow customizations to have their say.
6287 ;; This is a regular reply.
6288 (when (functionp message-reply-to-function)
6290 (setq follow-to (funcall message-reply-to-function))))
6291 ;; This is a followup.
6292 (when (functionp message-wide-reply-to-function)
6295 (funcall message-wide-reply-to-function)))))
6296 (setq message-id (message-fetch-field "message-id" t)
6297 references (message-fetch-field "references")
6298 date (message-fetch-field "date")
6299 from (message-fetch-field "from")
6300 subject (or (message-fetch-field "subject") "none"))
6301 (when gnus-list-identifiers
6302 (setq subject (message-strip-list-identifiers subject)))
6303 (setq subject (message-make-followup-subject subject))
6304 (when message-subject-trailing-was-query
6305 (setq subject (message-strip-subject-trailing-was subject)))
6307 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6308 (string-match "<[^>]+>" gnus-warning))
6309 (setq message-id (match-string 0 gnus-warning)))
6312 (setq follow-to (message-get-reply-headers wide to-address)))
6314 ;; Get the references from "In-Reply-To" field if there were
6315 ;; no references and "In-Reply-To" field looks promising.
6317 (when (and (setq in-reply-to (message-fetch-field "in-reply-to"))
6318 (string-match "<[^>]+>" in-reply-to))
6319 (setq references (match-string 0 in-reply-to)))))
6321 (unless (message-mail-user-agent)
6322 (message-pop-to-buffer
6323 (message-buffer-name
6324 (if wide "wide reply" "reply") from
6325 (if wide to-address nil))))
6327 (setq message-reply-headers
6328 (make-full-mail-header-from-decoded-header
6329 0 subject from date message-id references 0 0 ""))
6332 `((Subject . ,subject)
6337 (defun message-wide-reply (&optional to-address)
6338 "Make a \"wide\" reply to the message in the current buffer."
6340 (message-reply to-address t))
6343 (defun message-followup (&optional to-newsgroups)
6344 "Follow up to the message in the current buffer.
6345 If TO-NEWSGROUPS, use that as the new Newsgroups line."
6347 (require 'gnus-sum) ; for gnus-list-identifiers
6348 (let ((cur (current-buffer))
6349 from subject date reply-to mrt mct mft
6350 references message-id follow-to
6351 (inhibit-point-motion-hooks t)
6352 (message-this-is-news t)
6353 followup-to distribution newsgroups gnus-warning posted-to)
6355 (message-narrow-to-head)
6356 (when (functionp message-followup-to-function)
6358 (funcall message-followup-to-function)))
6359 (setq from (message-fetch-field "from")
6360 date (message-fetch-field "date")
6361 subject (or (message-fetch-field "subject") "none")
6362 references (message-fetch-field "references")
6363 message-id (message-fetch-field "message-id" t)
6364 followup-to (message-fetch-field "followup-to")
6365 newsgroups (message-fetch-field "newsgroups")
6366 posted-to (message-fetch-field "posted-to")
6367 reply-to (message-fetch-field "reply-to")
6368 mrt (when message-use-mail-reply-to
6369 (message-fetch-field "mail-reply-to"))
6370 distribution (message-fetch-field "distribution")
6371 mct (when message-use-mail-copies-to
6372 (message-fetch-field "mail-copies-to"))
6373 mft (when message-use-mail-followup-to
6374 (message-fetch-field "mail-followup-to")))
6375 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6376 (string-match "<[^>]+>" gnus-warning))
6377 (setq message-id (match-string 0 gnus-warning)))
6378 ;; Remove bogus distribution.
6379 (when (and (stringp distribution)
6380 (let ((case-fold-search t))
6381 (string-match "world" distribution)))
6382 (setq distribution nil))
6383 (if gnus-list-identifiers
6384 (setq subject (message-strip-list-identifiers subject)))
6385 (setq subject (message-make-followup-subject subject))
6386 (when message-subject-trailing-was-query
6387 (setq subject (message-strip-subject-trailing-was subject)))
6390 ;; Handle special values of Mail-Copies-To.
6393 ((and (or (equal (downcase mct) "never")
6394 (equal (downcase mct) "nobody")))
6396 ((and (or (equal (downcase mct) "always")
6397 (equal (downcase mct) "poster")))
6398 (if (or (not (eq message-use-mail-copies-to 'ask))
6400 (concat "Obey Mail-Copies-To: always? ") t "\
6401 You should normally obey the Mail-Copies-To: header.
6403 `Mail-Copies-To: " mct "'
6404 sends a copy of your response to the author."))
6405 (setq mct (or mrt reply-to from))
6407 ((and (eq message-use-mail-copies-to 'ask)
6410 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
6411 You should normally obey the Mail-Copies-To: header.
6413 `Mail-Copies-To: " mct "'
6414 sends a copy of your response to " (if (string-match "," mct)
6415 "the specified addresses"
6416 "that address") ".")))
6421 (to-newsgroups (setq follow-to (list (cons 'Newsgroups to-newsgroups))))
6422 ;; Handle Followup-To.
6425 ((equal (downcase followup-to) "poster")
6426 (if (or (and followup-to (eq message-use-followup-to 'use))
6427 (message-y-or-n-p "Obey Followup-To: poster? " t "\
6428 You should normally obey the Followup-To: header.
6430 `Followup-To: poster'
6431 sends your response via e-mail instead of news.
6433 A typical situation where `Followup-To: poster' is used is when the author
6434 does not read the newsgroup, so he wouldn't see any replies sent to it."))
6435 (setq message-this-is-news nil
6437 follow-to (list (cons 'To (or mrt reply-to from ""))))
6438 (setq follow-to (list (cons 'Newsgroups newsgroups)))))
6440 (if (or (equal followup-to newsgroups)
6441 (not (and followup-to (eq message-use-followup-to 'ask)))
6443 (concat "Obey Followup-To: " followup-to "? ") t "\
6444 You should normally obey the Followup-To: header.
6446 `Followup-To: " followup-to "'
6447 directs your response to " (if (string-match "," followup-to)
6448 "the specified newsgroups"
6449 "that newsgroup only") ".
6451 If a message is posted to several newsgroups, Followup-To is often
6452 used to direct the following discussion to one newsgroup only,
6453 because discussions that are spread over several newsgroup tend to
6454 be fragmented and very difficult to follow.
6456 Also, some source/announcement newsgroups are not intended for discussion;
6457 responses here are directed to other newsgroups."))
6458 (setq follow-to (list (cons 'Newsgroups followup-to)))
6459 (setq follow-to (list (cons 'Newsgroups newsgroups)))))))
6460 ;; Handle Mail-Followup-To, followup via e-mail.
6462 (or (not (eq message-use-mail-followup-to 'ask))
6464 (concat "Obey Mail-Followup-To: " mft "? ") t "\
6465 You should normally obey the Mail-Followup-To: header.
6467 `Mail-Followup-To: " mft "'
6468 directs your response to " (if (string-match "," mft)
6469 "the specified addresses"
6470 "that address only") " instead of news.
6472 A typical situation where Mail-Followup-To is used is when the author thinks
6473 that further discussion should take place only in "
6474 (if (string-match "," mft)
6475 "the specified mailing lists"
6476 "that mailing list") ".")))
6477 (setq message-this-is-news nil
6479 follow-to (list (cons 'To mft))))
6480 (posted-to (setq follow-to (list (cons 'Newsgroups posted-to))))
6482 (setq follow-to (list (cons 'Newsgroups newsgroups))))))
6484 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
6486 (setq message-reply-headers
6487 (make-full-mail-header-from-decoded-header
6488 0 subject from date message-id references 0 0 ""))
6491 `((Subject . ,subject)
6493 ,@(and mct (list (cons 'Cc mct)))
6494 ,@(and distribution (list (cons 'Distribution distribution))))
6497 (defun message-is-yours-p ()
6498 "Non-nil means current article is yours.
6499 If you have added 'cancel-messages to 'message-shoot-gnksa-feet', all articles
6500 are yours except those that have Cancel-Lock header not belonging to you.
6501 Instead of shooting GNKSA feet, you should modify 'message-alternative-emails'
6502 regexp to match all of yours addresses."
6503 ;; Canlock-logic as suggested by Per Abrahamsen
6504 ;; <abraham@dina.kvl.dk>
6506 ;; IF article has cancel-lock THEN
6507 ;; IF we can verify it THEN
6510 ;; error: cancellock: article is not yours
6512 ;; Use old rules, comparing sender...
6515 (message-narrow-to-head-1)
6516 (if (message-fetch-field "Cancel-Lock")
6517 (if (null (canlock-verify))
6519 (error "Failed to verify Cancel-lock: This article is not yours"))
6522 (message-gnksa-enable-p 'cancel-messages)
6523 (and (setq sender (message-fetch-field "sender"))
6524 (string-equal (downcase sender)
6525 (downcase (message-make-sender))))
6526 ;; Email address in From field equals to our address
6527 (and (setq from (message-fetch-field "from"))
6529 (downcase (cadr (std11-extract-address-components from)))
6530 (downcase (cadr (std11-extract-address-components
6531 (message-make-from))))))
6532 ;; Email address in From field matches
6533 ;; 'message-alternative-emails' regexp
6535 message-alternative-emails
6537 message-alternative-emails
6538 (cadr (std11-extract-address-components from))))))))))
6541 (defun message-cancel-news (&optional arg)
6542 "Cancel an article you posted.
6543 If ARG, allow editing of the cancellation message."
6545 (unless (message-news-p)
6546 (error "This is not a news article; canceling is impossible"))
6547 (let (from newsgroups message-id distribution buf)
6549 ;; Get header info from original article.
6551 (message-narrow-to-head-1)
6552 (setq from (message-fetch-field "from")
6553 newsgroups (message-fetch-field "newsgroups")
6554 message-id (message-fetch-field "message-id" t)
6555 distribution (message-fetch-field "distribution")))
6556 ;; Make sure that this article was written by the user.
6557 (unless (message-is-yours-p)
6558 (error "This article is not yours"))
6559 (when (yes-or-no-p "Do you really want to cancel this article? ")
6560 ;; Make control message.
6563 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
6565 (insert "Newsgroups: " newsgroups "\n"
6567 "Subject: cmsg cancel " message-id "\n"
6568 "Control: cancel " message-id "\n"
6570 (concat "Distribution: " distribution "\n")
6572 mail-header-separator "\n"
6573 message-cancel-message)
6574 (run-hooks 'message-cancel-hook)
6576 (message "Canceling your article...")
6577 (if (let ((message-syntax-checks
6578 'dont-check-for-anything-just-trust-me)
6579 (message-encoding-buffer (current-buffer))
6580 (message-edit-buffer (current-buffer)))
6581 (message-send-news))
6582 (message "Canceling your article...done"))
6583 (kill-buffer buf))))))
6585 (defun message-supersede-setup-for-mime-edit ()
6586 (set (make-local-variable 'message-setup-hook) nil)
6590 (defun message-supersede ()
6591 "Start composing a message to supersede the current message.
6592 This is done simply by taking the old article and adding a Supersedes
6593 header line with the old Message-ID."
6595 (let ((cur (current-buffer)))
6596 ;; Check whether the user owns the article that is to be superseded.
6597 (unless (message-is-yours-p)
6598 (error "This article is not yours"))
6599 ;; Get a normal message buffer.
6600 (message-pop-to-buffer (message-buffer-name "supersede"))
6601 (insert-buffer-substring cur)
6602 (message-narrow-to-head-1)
6603 ;; Remove unwanted headers.
6604 (when message-ignored-supersedes-headers
6605 (message-remove-header message-ignored-supersedes-headers t))
6606 (goto-char (point-min))
6607 (if (not (re-search-forward "^Message-ID: " nil t))
6608 (error "No Message-ID in this article")
6609 (replace-match "Supersedes: " t t))
6610 (goto-char (point-max))
6611 (insert mail-header-separator)
6613 (when message-supersede-setup-function
6614 (funcall message-supersede-setup-function))
6615 (run-hooks 'message-supersede-setup-hook)
6616 (goto-char (point-min))
6617 (search-forward (concat "\n" mail-header-separator "\n") nil t)))
6620 (defun message-recover ()
6621 "Reread contents of current buffer from its last auto-save file."
6623 (let ((file-name (make-auto-save-file-name)))
6624 (cond ((save-window-excursion
6625 (if (not (eq system-type 'vax-vms))
6626 (with-output-to-temp-buffer "*Directory*"
6627 (with-current-buffer standard-output
6628 (fundamental-mode)) ; for Emacs 20.4+
6629 (buffer-disable-undo standard-output)
6630 (let ((default-directory "/"))
6632 "ls" nil standard-output nil "-l" file-name))))
6633 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
6634 (let ((buffer-read-only nil))
6636 (insert-file-contents file-name nil)))
6637 (t (error "message-recover cancelled")))))
6639 ;;; Washing Subject:
6641 (defun message-wash-subject (subject)
6642 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
6643 Previous forwarders, replyers, etc. may add it."
6646 (goto-char (point-min))
6647 ;; strip Re/Fwd stuff off the beginning
6648 (while (re-search-forward
6649 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
6652 ;; and gnus-style forwards [foo@bar.com] subject
6653 (goto-char (point-min))
6654 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
6658 (goto-char (point-max))
6659 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
6662 ;; and finally, any whitespace that was left-over
6663 (goto-char (point-min))
6664 (while (re-search-forward "^[ \t]+" nil t)
6666 (goto-char (point-max))
6667 (while (re-search-backward "[ \t]+$" nil t)
6672 ;;; Forwarding messages.
6674 (defvar message-forward-decoded-p nil
6675 "Non-nil means the original message is decoded.")
6677 (defun message-forward-subject-name-subject (subject)
6678 "Generate a SUBJECT for a forwarded message.
6679 The form is: [Source] Subject, where if the original message was mail,
6680 Source is the name of the sender, and if the original message was
6681 news, Source is the list of newsgroups is was posted to."
6683 (let ((group (message-fetch-field "newsgroups"))
6686 (gnus-group-decoded-name group)
6687 (or (and (setq from (message-fetch-field "from"))
6688 (car (std11-extract-address-components
6689 (nnheader-decode-from from))))
6693 (defun message-forward-subject-author-subject (subject)
6694 "Generate a SUBJECT for a forwarded message.
6695 The form is: [Source] Subject, where if the original message was mail,
6696 Source is the sender, and if the original message was news, Source is
6697 the list of newsgroups is was posted to."
6699 (let ((group (message-fetch-field "newsgroups"))
6702 (gnus-group-decoded-name group)
6703 (if (setq from (message-fetch-field "from"))
6704 (nnheader-decode-from from)
6708 (defun message-forward-subject-fwd (subject)
6709 "Generate a SUBJECT for a forwarded message.
6710 The form is: Fwd: Subject, where Subject is the original subject of
6712 (if (string-match "^Fwd: " subject)
6714 (concat "Fwd: " subject)))
6716 (defun message-make-forward-subject ()
6717 "Return a Subject header suitable for the message in the current buffer."
6720 (message-narrow-to-head-1)
6721 (let ((funcs message-make-forward-subject-function)
6722 (subject (message-fetch-field "Subject")))
6725 (if message-forward-decoded-p
6727 (nnheader-decode-subject subject))
6729 (if message-wash-forwarded-subjects
6730 (setq subject (message-wash-subject subject)))
6731 ;; Make sure funcs is a list.
6734 (setq funcs (list funcs)))
6735 ;; Apply funcs in order, passing subject generated by previous
6736 ;; func to the next one.
6738 (when (functionp (car funcs))
6739 (setq subject (funcall (car funcs) subject)))
6740 (setq funcs (cdr funcs)))
6744 (defun message-forward (&optional news)
6745 "Forward the current message via mail.
6746 Optional NEWS will use news to forward instead of mail."
6748 (let ((cur (current-buffer))
6749 (subject (message-make-forward-subject)))
6751 (message-news nil subject)
6752 (message-mail nil subject))
6753 (message-forward-make-body cur)))
6755 (defun message-forward-make-body-plain (forward-buffer)
6757 "\n-------------------- Start of forwarded message --------------------\n")
6758 (let ((b (point)) e)
6761 (mm-disable-multibyte)
6763 (with-current-buffer forward-buffer
6764 (mm-with-unibyte-current-buffer (buffer-string))))
6765 (mm-enable-multibyte)
6767 (goto-char (point-min))
6768 (when (looking-at "From ")
6769 (replace-match "X-From-Line: "))
6773 "\n-------------------- End of forwarded message --------------------\n")
6774 (when (and (not current-prefix-arg)
6775 message-forward-ignored-headers)
6777 (narrow-to-region b e)
6779 (narrow-to-region (point)
6780 (or (search-forward "\n\n" nil t) (point)))
6781 (message-remove-header message-forward-ignored-headers t)))))
6783 (defun message-forward-make-body-mime (forward-buffer)
6784 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
6785 (let ((b (point)) e)
6787 (narrow-to-region (point) (point))
6788 (mml-insert-buffer forward-buffer)
6789 (goto-char (point-min))
6790 (when (looking-at "From ")
6791 (replace-match "X-From-Line: "))
6792 (goto-char (point-max)))
6794 (insert "<#/part>\n")))
6796 (defun message-forward-make-body-mml (forward-buffer)
6797 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
6798 (let ((b (point)) e)
6799 (if (not message-forward-decoded-p)
6802 (mm-disable-multibyte)
6804 (with-current-buffer forward-buffer
6805 (mm-with-unibyte-current-buffer (buffer-string))))
6806 (mm-enable-multibyte)
6808 (goto-char (point-min))
6809 (when (looking-at "From ")
6810 (replace-match "X-From-Line: "))
6813 (narrow-to-region (point) (point))
6814 (mml-insert-buffer forward-buffer)
6815 (goto-char (point-min))
6816 (when (looking-at "From ")
6817 (replace-match "X-From-Line: "))
6818 (goto-char (point-max))))
6820 (insert "<#/mml>\n")
6821 (when (and (not current-prefix-arg)
6822 message-forward-ignored-headers)
6824 (narrow-to-region b e)
6826 (narrow-to-region (point)
6827 (or (search-forward "\n\n" nil t) (point)))
6828 (message-remove-header message-forward-ignored-headers t)))))
6830 (defun message-forward-make-body-digest-plain (forward-buffer)
6832 "\n-------------------- Start of forwarded message --------------------\n")
6833 (let ((b (point)) e)
6834 (mml-insert-buffer forward-buffer)
6837 "\n-------------------- End of forwarded message --------------------\n")))
6839 (defun message-forward-make-body-digest-mime (forward-buffer)
6840 (insert "\n<#multipart type=digest>\n")
6841 (let ((b (point)) e)
6842 (insert-buffer-substring forward-buffer)
6844 (insert "<#/multipart>\n")
6846 (narrow-to-region b e)
6848 (narrow-to-region (point)
6849 (or (search-forward "\n\n" nil t) (point)))
6850 (delete-region (point-min) (point-max)))))
6852 (defun message-forward-make-body-digest (forward-buffer)
6853 (if message-forward-as-mime
6854 (message-forward-make-body-digest-mime forward-buffer)
6855 (message-forward-make-body-digest-plain forward-buffer)))
6858 (defun message-forward-make-body (forward-buffer)
6859 ;; Put point where we want it before inserting the forwarded
6861 ;; Note that this function definition for T-gnus is totally different
6862 ;; from the original Gnus."
6863 (if message-forward-before-signature
6865 (goto-char (point-max)))
6866 ;; Make sure we're at the start of the line.
6869 ;; Narrow to the area we are to insert.
6870 (narrow-to-region (point) (point))
6871 ;; Insert the separators and the forwarded buffer.
6872 (insert message-forward-start-separator)
6873 (let ((art-beg (point)))
6874 (insert-buffer-substring forward-buffer)
6875 (goto-char (point-max))
6876 (insert message-forward-end-separator)
6877 (set-text-properties (point-min) (point-max) nil)
6878 ;; Remove all unwanted headers.
6880 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
6883 (goto-char (point-min))
6884 (message-remove-header message-included-forward-headers t nil t)
6886 (message-position-point)))
6889 (defun message-forward-rmail-make-body (forward-buffer)
6890 (save-window-excursion
6891 (set-buffer forward-buffer)
6892 ;; Rmail doesn't have rmail-msg-restore-non-pruned-header in Emacs
6893 ;; 20. FIXIT, or we drop support for rmail in Emacs 20.
6894 (if (rmail-msg-is-pruned)
6895 (rmail-msg-restore-non-pruned-header)))
6896 (message-forward-make-body forward-buffer))
6898 (eval-when-compile (defvar rmail-enable-mime-composing))
6900 ;; Fixme: Should have defcustom.
6902 (defun message-insinuate-rmail ()
6903 "Let RMAIL use message to forward."
6905 (setq rmail-enable-mime-composing t)
6906 (setq rmail-insert-mime-forwarded-message-function
6907 'message-forward-rmail-make-body))
6910 (defun message-resend (address)
6911 "Resend the current article to ADDRESS."
6913 (list (message-read-from-minibuffer "Resend message to: ")))
6914 (message "Resending message to %s..." address)
6916 (let ((cur (current-buffer))
6918 ;; We first set up a normal mail buffer.
6919 (unless (message-mail-user-agent)
6920 (set-buffer (get-buffer-create " *message resend*"))
6922 (let ((message-this-is-mail t)
6924 (message-setup `((To . ,address))))
6925 ;; Insert our usual headers.
6926 (message-generate-headers '(From Date To Message-ID))
6927 (message-narrow-to-headers)
6928 ;; Remove X-Draft-From header etc.
6929 (message-remove-header message-ignored-mail-headers t)
6930 ;; Rename them all to "Resent-*".
6931 (goto-char (point-min))
6932 (while (re-search-forward "^[A-Za-z]" nil t)
6937 (delete-region (point) (point-max))
6939 ;; Insert the message to be resent.
6940 (insert-buffer-substring cur)
6941 (goto-char (point-min))
6942 (search-forward "\n\n")
6945 (narrow-to-region beg (point))
6946 (message-remove-header message-ignored-resent-headers t)
6947 (goto-char (point-max)))
6948 (insert mail-header-separator)
6949 ;; Rename all old ("Also-")Resent headers.
6950 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
6953 ;; Quote any "From " lines at the beginning.
6955 (when (looking-at "From ")
6956 (replace-match "X-From-Line: "))
6958 (let ((message-encoding-buffer (current-buffer))
6959 (message-edit-buffer (current-buffer))
6960 message-required-mail-headers)
6961 (message-send-mail))
6962 (kill-buffer (current-buffer)))
6963 (message "Resending message to %s...done" address)))
6965 (defun message-bounce-setup-for-mime-edit ()
6966 (set (make-local-variable 'message-setup-hook) nil)
6970 (defun message-bounce ()
6971 "Re-mail the current message.
6972 This only makes sense if the current message is a bounce message that
6973 contains some mail you have written which has been bounced back to
6976 (let ((cur (current-buffer))
6977 mime-boundary boundary)
6978 (message-pop-to-buffer (message-buffer-name "bounce"))
6979 (insert-buffer-substring cur)
6981 (message-narrow-to-head)
6982 (if (and (message-fetch-field "MIME-Version")
6983 (setq mime-boundary (message-fetch-field "Content-Type")))
6984 (if (string-match "boundary=\"\\([^\"]+\\)\"" mime-boundary)
6985 (setq mime-boundary (concat (regexp-quote
6986 (match-string 1 mime-boundary))
6987 " *\nContent-Type: message/rfc822"))
6988 (setq mime-boundary nil)))
6990 (goto-char (point-min))
6991 (re-search-forward "\n\n+" nil t)
6992 (setq boundary (point))
6993 ;; We remove everything before the bounced mail.
6994 (if (or (and mime-boundary
6995 (re-search-forward mime-boundary nil t)
6997 (re-search-forward message-unsent-separator nil t)
6999 (search-forward "\n\n" nil 'move)
7000 (re-search-backward "^Return-Path:.*\n" boundary t)))
7003 (delete-region (point-min)
7004 (if (re-search-forward "^[^ \n\t]+:" nil t)
7007 (when (re-search-backward "^.?From .*\n" nil t)
7008 (delete-region (match-beginning 0) (match-end 0))))
7010 (message-narrow-to-head-1)
7011 (message-remove-header message-ignored-bounced-headers t)
7012 (goto-char (point-max))
7013 (insert mail-header-separator))
7014 (when message-bounce-setup-function
7015 (funcall message-bounce-setup-function))
7016 (run-hooks 'message-bounce-setup-hook)
7017 (message-position-point)))
7020 ;;; Interactive entry points for new message buffers.
7024 (defun message-mail-other-window (&optional to subject)
7025 "Like `message-mail' command, but display mail buffer in another window."
7027 (unless (message-mail-user-agent)
7028 (let ((pop-up-windows t)
7029 (special-display-buffer-names nil)
7030 (special-display-regexps nil)
7031 (same-window-buffer-names nil)
7032 (same-window-regexps nil))
7033 (message-pop-to-buffer (message-buffer-name "mail" to))))
7034 (let ((message-this-is-mail t))
7035 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7036 nil nil 'switch-to-buffer-other-window)))
7039 (defun message-mail-other-frame (&optional to subject)
7040 "Like `message-mail' command, but display mail buffer in another frame."
7042 (unless (message-mail-user-agent)
7043 (let ((pop-up-frames t)
7044 (special-display-buffer-names nil)
7045 (special-display-regexps nil)
7046 (same-window-buffer-names nil)
7047 (same-window-regexps nil))
7048 (message-pop-to-buffer (message-buffer-name "mail" to))))
7049 (let ((message-this-is-mail t))
7050 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7051 nil nil 'switch-to-buffer-other-frame)))
7054 (defun message-news-other-window (&optional newsgroups subject)
7055 "Start editing a news article to be sent."
7057 (let ((pop-up-windows t)
7058 (special-display-buffer-names nil)
7059 (special-display-regexps nil)
7060 (same-window-buffer-names nil)
7061 (same-window-regexps nil))
7062 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
7063 (let ((message-this-is-news t))
7064 (message-setup `((Newsgroups . ,(or newsgroups ""))
7065 (Subject . ,(or subject ""))))))
7068 (defun message-news-other-frame (&optional newsgroups subject)
7069 "Start editing a news article to be sent."
7071 (let ((pop-up-frames t)
7072 (special-display-buffer-names nil)
7073 (special-display-regexps nil)
7074 (same-window-buffer-names nil)
7075 (same-window-regexps nil))
7076 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
7077 (let ((message-this-is-news t))
7078 (message-setup `((Newsgroups . ,(or newsgroups ""))
7079 (Subject . ,(or subject ""))))))
7083 ;; This code should be moved to underline.el (from which it is stolen).
7086 (defun bold-region (start end)
7087 "Bold all nonblank characters in the region.
7088 Works by overstriking characters.
7089 Called from program, takes two arguments START and END
7090 which specify the range to operate on."
7093 (let ((end1 (make-marker)))
7094 (move-marker end1 (max start end))
7095 (goto-char (min start end))
7096 (while (< (point) end1)
7097 (or (looking-at "[_\^@- ]")
7098 (insert (char-after) "\b"))
7099 (forward-char 1)))))
7102 (defun unbold-region (start end)
7103 "Remove all boldness (overstruck characters) in the region.
7104 Called from program, takes two arguments START and END
7105 which specify the range to operate on."
7108 (let ((end1 (make-marker)))
7109 (move-marker end1 (max start end))
7110 (goto-char (min start end))
7111 (while (re-search-forward "\b" end1 t)
7112 (if (eq (char-after) (char-after (- (point) 2)))
7113 (delete-char -2))))))
7115 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
7116 (defalias 'message-make-overlay 'make-overlay)
7117 (defalias 'message-delete-overlay 'delete-overlay)
7118 (defalias 'message-overlay-put 'overlay-put)
7119 (defun message-kill-all-overlays ()
7120 (if (featurep 'xemacs)
7121 (map-extents (lambda (extent ignore) (delete-extent extent)))
7122 (mapcar #'delete-overlay (overlays-in (point-min) (point-max)))))
7124 ;; Support for toolbar
7126 (defvar tool-bar-map)
7127 (defvar tool-bar-mode))
7129 (defun message-tool-bar-local-item-from-menu (command icon in-map &optional from-map &rest props)
7130 ;; We need to make tool bar entries in local keymaps with
7131 ;; `tool-bar-local-item-from-menu' in Emacs > 21.3
7132 (if (fboundp 'tool-bar-local-item-from-menu)
7133 ;; This is for Emacs 21.3
7134 (tool-bar-local-item-from-menu command icon in-map from-map props)
7135 (tool-bar-add-item-from-menu command icon from-map props)))
7137 (defun message-tool-bar-map ()
7138 (or message-tool-bar-map
7139 (setq message-tool-bar-map
7141 (condition-case nil (require 'tool-bar) (error nil))
7142 (fboundp 'tool-bar-add-item-from-menu)
7144 (let ((tool-bar-map (copy-keymap tool-bar-map))
7145 (load-path (mm-image-load-path)))
7146 ;; Zap some items which aren't so relevant and take
7148 (dolist (key '(print-buffer kill-buffer save-buffer
7149 write-file dired open-file))
7150 (define-key tool-bar-map (vector key) nil))
7151 (message-tool-bar-local-item-from-menu
7152 'message-send-and-exit "mail_send" tool-bar-map message-mode-map)
7153 (message-tool-bar-local-item-from-menu
7154 'message-kill-buffer "close" tool-bar-map message-mode-map)
7155 (message-tool-bar-local-item-from-menu
7156 'message-dont-send "cancel" tool-bar-map message-mode-map)
7157 ;; (message-tool-bar-local-item-from-menu
7158 ;; 'mime-edit-insert-file "attach"
7159 ;; tool-bar-map mime-edit-mode-map)
7160 (message-tool-bar-local-item-from-menu
7161 'ispell-message "spell" tool-bar-map message-mode-map)
7162 ;; (message-tool-bar-local-item-from-menu
7163 ;; 'mime-edit-preview-message "preview"
7164 ;; tool-bar-map mime-edit-mode-map)
7165 (message-tool-bar-local-item-from-menu
7166 'message-insert-importance-high "important"
7167 tool-bar-map message-mode-map)
7168 (message-tool-bar-local-item-from-menu
7169 'message-insert-importance-low "unimportant"
7170 tool-bar-map message-mode-map)
7171 (message-tool-bar-local-item-from-menu
7172 'message-insert-disposition-notification-to "receipt"
7173 tool-bar-map message-mode-map)
7176 ;;; Group name completion.
7178 (defcustom message-newgroups-header-regexp
7179 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
7180 "Regexp that match headers that lists groups."
7184 (defcustom message-completion-alist
7185 (list (cons message-newgroups-header-regexp 'message-expand-group)
7186 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name)
7187 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
7188 . message-expand-name)
7189 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
7190 . message-expand-name))
7191 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
7193 :type '(alist :key-type regexp :value-type function))
7195 (defcustom message-expand-name-function
7196 (if (fboundp 'bbdb-complete-name)
7198 (if (fboundp 'lsdb-complete-name)
7201 "*A function called to expand addresses in field body."
7205 (defcustom message-tab-body-function nil
7206 "*Function to execute when `message-tab' (TAB) is executed in the body.
7207 If nil, the function bound in `text-mode-map' or `global-map' is executed."
7211 (defun message-tab ()
7212 "Complete names according to `message-completion-alist'.
7213 Execute function specified by `message-tab-body-function' when not in
7216 (let ((alist message-completion-alist))
7218 (let ((mail-abbrev-mode-regexp (caar alist)))
7219 (not (mail-abbrev-in-expansion-header-p))))
7220 (setq alist (cdr alist)))
7221 (funcall (or (cdar alist) message-tab-body-function
7222 (lookup-key text-mode-map "\t")
7223 (lookup-key global-map "\t")
7224 'indent-relative))))
7226 (defun message-expand-group ()
7227 "Expand the group name under point."
7228 (let* ((b (save-excursion
7233 (skip-chars-forward "^:")
7236 (skip-chars-backward "^, \t\n") (point))))
7237 (completion-ignore-case t)
7238 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
7240 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
7241 (completions (all-completions string hashtb))
7243 (delete-region b (point))
7245 ((= (length completions) 1)
7246 (if (string= (car completions) string)
7249 (message "Only matching group"))
7250 (insert (car completions))))
7251 ((and (setq comp (try-completion string hashtb))
7252 (not (string= comp string)))
7257 (message "No matching groups")
7258 (save-selected-window
7259 (pop-to-buffer "*Completions*")
7260 (buffer-disable-undo)
7261 (let ((buffer-read-only nil))
7263 (let ((standard-output (current-buffer)))
7264 (display-completion-list (sort completions 'string<)))
7265 (goto-char (point-min))
7266 (delete-region (point) (progn (forward-line 3) (point))))))))))
7268 (defun message-expand-name ()
7269 (funcall message-expand-name-function))
7273 (defun message-talkative-question (ask question show &rest text)
7274 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
7275 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
7276 The following arguments may contain lists of values."
7278 (setq text (message-flatten-list text)))
7279 (save-window-excursion
7281 (with-output-to-temp-buffer " *MESSAGE information message*"
7282 (set-buffer " *MESSAGE information message*")
7283 (fundamental-mode) ; for Emacs 20.4+
7284 (mapcar 'princ text)
7285 (goto-char (point-min))))
7286 (funcall ask question))
7287 (funcall ask question)))
7289 (defun message-flatten-list (list)
7290 "Return a new, flat list that contains all elements of LIST.
7292 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
7295 (apply 'append (mapcar 'message-flatten-list list)))
7299 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
7300 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
7301 Then clone the local variables and values from the old buffer to the
7302 new one, cloning only the locals having a substring matching the
7304 (let ((oldbuf (current-buffer)))
7306 (set-buffer (generate-new-buffer name))
7307 (message-clone-locals oldbuf varstr)
7310 (defun message-clone-locals (buffer &optional varstr)
7311 "Clone the local variables from BUFFER to the current buffer."
7312 (let ((locals (save-excursion
7314 (buffer-local-variables)))
7316 "^\\(gnus\\|nn\\|message\\|user-\\(mail-address\\|full-name\\)\\)"))
7319 (when (and (consp local)
7321 (string-match regexp (symbol-name (car local)))
7323 (string-match varstr (symbol-name (car local)))))
7325 (set (make-local-variable (car local))
7329 ;;; @ for MIME Edit mode
7332 (defun message-maybe-encode ()
7333 (when message-mime-mode
7334 ;; Inherit the buffer local variable `mime-edit-pgp-processing'.
7335 (let ((pgp-processing (with-current-buffer message-edit-buffer
7336 mime-edit-pgp-processing)))
7337 (setq mime-edit-pgp-processing pgp-processing))
7338 (run-hooks 'mime-edit-translate-hook)
7339 (if (catch 'mime-edit-error
7341 (mime-edit-pgp-enclose-buffer)
7342 (mime-edit-translate-body)))
7343 (error "Translation error!"))
7344 (run-hooks 'mime-edit-exit-hook)))
7346 (defun message-mime-insert-article (&optional full-headers)
7348 (let ((message-cite-function 'mime-edit-inserted-message-filter)
7349 (message-reply-buffer
7350 (message-get-parameter-with-eval 'original-buffer))
7352 (message-yank-original nil)
7354 (narrow-to-region (goto-char start)
7355 (if (search-forward "\n\n" nil t)
7358 (goto-char (point-min))
7359 (let ((message-included-forward-headers
7360 (if full-headers "" message-included-forward-headers)))
7361 (message-remove-header message-included-forward-headers t nil t))
7364 (set-alist 'mime-edit-message-inserter-alist
7365 'message-mode (function message-mime-insert-article))
7371 (defvar message-inhibit-body-encoding t)
7373 (defun message-encode-message-body ()
7374 (unless message-inhibit-body-encoding
7375 (let ((mail-parse-charset (or mail-parse-charset
7376 message-default-charset))
7377 (case-fold-search t)
7378 lines content-type-p)
7381 (narrow-to-region (point) (point-max))
7382 (let ((new (mml-generate-mime)))
7384 (delete-region (point-min) (point-max))
7386 (goto-char (point-min))
7387 (if (eq (aref new 0) ?\n)
7389 (search-forward "\n\n")
7390 (setq lines (buffer-substring (point-min) (1- (point))))
7391 (delete-region (point-min) (point))))))
7393 (message-narrow-to-headers-or-head)
7394 (message-remove-header "Mime-Version")
7395 (goto-char (point-max))
7396 (insert "MIME-Version: 1.0\n")
7399 (setq content-type-p
7401 (re-search-backward "^Content-Type:" nil t))))
7403 (message-narrow-to-headers-or-head)
7404 (message-remove-first-header "Content-Type")
7405 (message-remove-first-header "Content-Transfer-Encoding"))
7406 ;; We always make sure that the message has a Content-Type
7407 ;; header. This is because some broken MTAs and MUAs get
7408 ;; awfully confused when confronted with a message with a
7409 ;; MIME-Version header and without a Content-Type header. For
7410 ;; instance, Solaris' /usr/bin/mail.
7411 (unless content-type-p
7412 (goto-char (point-min))
7413 ;; For unknown reason, MIME-Version doesn't exist.
7414 (when (re-search-forward "^MIME-Version:" nil t)
7416 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
7418 (defun message-read-from-minibuffer (prompt &optional initial-contents)
7419 "Read from the minibuffer while providing abbrev expansion."
7420 (if (fboundp 'mail-abbrevs-setup)
7421 (let ((mail-abbrev-mode-regexp "")
7422 (minibuffer-setup-hook 'mail-abbrevs-setup)
7423 (minibuffer-local-map message-minibuffer-local-map))
7424 (read-from-minibuffer prompt initial-contents))
7425 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
7426 (minibuffer-local-map message-minibuffer-local-map))
7427 (read-string prompt initial-contents))))
7429 (defun message-use-alternative-email-as-from ()
7430 (require 'mail-utils)
7431 (let* ((fields '("To" "Cc"))
7434 (mail-strip-quoted-names
7435 (mapconcat 'message-fetch-reply-field fields ","))
7439 (if (string-match message-alternative-emails (car emails))
7440 (setq email (car emails)
7443 (unless (or (not email) (equal email user-mail-address))
7444 (goto-char (point-max))
7445 (insert "From: " email "\n"))))
7447 (defun message-options-get (symbol)
7448 (cdr (assq symbol message-options)))
7450 (defun message-options-set (symbol value)
7451 (let ((the-cons (assq symbol message-options)))
7454 (setcdr the-cons value)
7455 (setq message-options (delq the-cons message-options)))
7457 (push (cons symbol value) message-options))))
7460 (defun message-options-set-recipient ()
7462 (message-narrow-to-headers-or-head)
7463 (message-options-set 'message-sender
7464 (mail-strip-quoted-names
7465 (message-fetch-field "from")))
7466 (message-options-set 'message-recipients
7467 (mail-strip-quoted-names
7468 (let ((to (message-fetch-field "to"))
7469 (cc (message-fetch-field "cc"))
7470 (bcc (message-fetch-field "bcc")))
7473 (if (and to cc) ", ")
7475 (if (and (or to cc) bcc) ", ")
7478 (defun message-hide-headers ()
7479 "Hide headers based on the `message-hidden-headers' variable."
7480 (let ((regexps (if (stringp message-hidden-headers)
7481 (list message-hidden-headers)
7482 message-hidden-headers))
7483 (inhibit-point-motion-hooks t)
7484 (after-change-functions nil))
7488 (message-narrow-to-headers)
7489 (goto-char (point-min))
7491 (if (not (message-hide-header-p regexps))
7492 (message-next-header)
7493 (let ((begin (point)))
7494 (message-next-header)
7495 (add-text-properties
7497 '(invisible t message-hidden t))))))))))
7499 (defun message-hide-header-p (regexps)
7502 (when (eq (car regexps) 'not)
7505 (dolist (regexp regexps)
7506 (setq result (or result (looking-at regexp))))
7511 (when (featurep 'xemacs)
7512 (require 'messagexmas)
7513 (message-xmas-redefine))
7517 (run-hooks 'message-load-hook)
7520 ;; coding: iso-8859-1
7523 ;;; message.el ends here