1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
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-list-identifiers)) ; gnus-sum is required where necessary
47 (require 'canlock-om))
51 ;; This is apparently necessary even though things are autoloaded.
52 ;; Because we dynamically bind mail-abbrev-mode-regexp, we'd better
53 ;; require mailabbrev here.
54 (if (featurep 'xemacs)
55 (require 'mail-abbrevs)
56 (require 'mailabbrev))
58 (eval-when-compile (require 'static))
60 ;; Avoid byte-compile warnings.
67 (autoload 'sha1 "sha1-el")
68 (autoload 'customize-save-variable "cus-edit"));; for Mule 2.
70 (defgroup message '((user-mail-address custom-variable)
71 (user-full-name custom-variable))
72 "Mail and news message composing."
73 :link '(custom-manual "(message)Top")
77 (put 'user-mail-address 'custom-type 'string)
78 (put 'user-full-name 'custom-type 'string)
80 (defgroup message-various nil
81 "Various Message Variables"
82 :link '(custom-manual "(message)Various Message Variables")
85 (defgroup message-buffers nil
87 :link '(custom-manual "(message)Message Buffers")
90 (defgroup message-sending nil
92 :link '(custom-manual "(message)Sending Variables")
95 (defgroup message-interface nil
97 :link '(custom-manual "(message)Interface")
100 (defgroup message-forwarding nil
102 :link '(custom-manual "(message)Forwarding")
103 :group 'message-interface)
105 (defgroup message-insertion nil
107 :link '(custom-manual "(message)Insertion")
110 (defgroup message-headers nil
112 :link '(custom-manual "(message)Message Headers")
115 (defgroup message-news nil
116 "Composing News Messages"
119 (defgroup message-mail nil
120 "Composing Mail Messages"
123 (defgroup message-faces nil
124 "Faces used for message composing."
128 (defgroup message-frames nil
132 (defcustom message-directory "~/Mail/"
133 "*Directory from which all other mail file variables are derived."
134 :group 'message-various
137 (defcustom message-max-buffers 10
138 "*How many buffers to keep before starting to kill them off."
139 :group 'message-buffers
142 (defcustom message-send-rename-function nil
143 "Function called to rename the buffer after sending it."
144 :group 'message-buffers
145 :type '(choice function (const nil)))
147 (defcustom message-fcc-handler-function 'message-output
148 "*A function called to save outgoing articles.
149 This function will be called with the name of the file to store the
150 article in. The default function is `message-output' which saves in Unix
152 :type '(radio (function-item message-output)
153 (function :tag "Other"))
154 :group 'message-sending)
156 (defcustom message-encode-function 'message-maybe-encode
157 "*A function called to encode messages."
158 :group 'message-sending
161 (defcustom message-8bit-encoding-list '(8bit binary)
162 "*8bit encoding type in Content-Transfer-Encoding field."
163 :group 'message-sending
164 :type '(repeat (symbol :tag "Type")))
166 (defcustom message-fcc-externalize-attachments nil
167 "If non-nil, attachments are included as external parts in Fcc copies."
169 :group 'message-sending)
171 (defcustom message-courtesy-message
172 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
173 "*This is inserted at the start of a mailed copy of a posted message.
174 If the string contains the format spec \"%s\", the Newsgroups
175 the article has been posted to will be inserted there.
176 If this variable is nil, no such courtesy message will be added."
177 :group 'message-sending
180 (defcustom message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):"
181 "*Regexp that matches headers to be removed in resent bounced mail."
182 :group 'message-interface
185 (defcustom message-bounce-setup-function 'message-bounce-setup-for-mime-edit
186 "Function to setup a re-sending bounced message."
187 :group 'message-sending
190 ;;; Start of variables adopted from `message-utils.el'.
192 (defcustom message-subject-trailing-was-query 'ask
193 ;; should it default to nil or ask?
194 "*What to do with trailing \"(was: <old subject>)\" in subject lines.
195 If nil, leave the subject unchanged. If it is the symbol `ask', query
196 the user what do do. In this case, the subject is matched against
197 `message-subject-trailing-was-ask-regexp'. If
198 `message-subject-trailing-was-query' is t, always strip the trailing
199 old subject. In this case, `message-subject-trailing-was-regexp' is
201 :type '(choice (const :tag "never" nil)
202 (const :tag "always strip" t)
204 :group 'message-various)
206 (defcustom message-subject-trailing-was-ask-regexp
207 "[ \t]*\\([[(]+[Ww][Aa][Ss][ \t]*.*[\])]+\\)"
208 "*Regexp matching \"(was: <old subject>)\" in the subject line.
210 The function `message-strip-subject-trailing-was' uses this regexp if
211 `message-subject-trailing-was-query' is set to the symbol `ask'. If
212 the variable is t instead of `ask', use
213 `message-subject-trailing-was-regexp' instead.
215 It is okay to create some false positives here, as the user is asked."
216 :group 'message-various
219 (defcustom message-subject-trailing-was-regexp
220 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
221 "*Regexp matching \"(was: <old subject>)\" in the subject line.
223 If `message-subject-trailing-was-query' is set to t, the subject is
224 matched against `message-subject-trailing-was-regexp' in
225 `message-strip-subject-trailing-was'. You should use a regexp creating very
226 few false positives here."
227 :group 'message-various
230 ;;; marking inserted text
233 (defcustom message-mark-insert-begin
234 "--8<---------------cut here---------------start------------->8---\n"
235 "How to mark the beginning of some inserted text."
237 :group 'message-various)
240 (defcustom message-mark-insert-end
241 "--8<---------------cut here---------------end--------------->8---\n"
242 "How to mark the end of some inserted text."
244 :group 'message-various)
247 (defcustom message-archive-header
248 "X-No-Archive: Yes\n"
249 "Header to insert when you don't want your article to be archived.
250 Archives \(such as groups.googgle.com\) respect this header."
252 :group 'message-various)
255 (defcustom message-archive-note
256 "X-No-Archive: Yes - save http://groups.google.com/"
257 "Note to insert why you wouldn't want this posting archived.
258 If nil, don't insert any text in the body."
260 :group 'message-various)
262 ;;; Crossposts and Followups
263 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
264 ;; new suggestions by R. Weikusat <rw at another.de>
266 (defvar message-xpost-old-target nil
267 "Old target for cross-posts or follow-ups.")
268 (make-variable-buffer-local 'message-xpost-old-target)
271 (defcustom message-xpost-default t
272 "When non-nil `message-xpost-fup2' will normally perform a crosspost.
273 If nil, `message-xpost-fup2' will only do a followup. Note that you
274 can explicitly override this setting by calling `message-xpost-fup2'
277 :group 'message-various)
280 (defcustom message-xpost-note
281 "Crosspost & Followup-To: "
282 "Note to insert before signature to notify of xpost and follow-up."
284 :group 'message-various)
287 (defcustom message-fup2-note
289 "Note to insert before signature to notify of follow-up only."
291 :group 'message-various)
294 (defcustom message-xpost-note-function
295 'message-xpost-insert-note
296 "Function to use to insert note about Crosspost or Followup-To.
297 The function will be called with four arguments. The function should not only
298 insert a note, but also ensure old notes are deleted. See the documentation
299 for `message-xpost-insert-note'. "
301 :group 'message-various)
303 ;;; End of variables adopted from `message-utils.el'.
306 (defcustom message-from-style 'default
307 "*Specifies how \"From\" headers look.
309 If nil, they contain just the return address like:
311 If `parens', they look like:
312 king@grassland.com (Elvis Parsley)
313 If `angles', they look like:
314 Elvis Parsley <king@grassland.com>
316 Otherwise, most addresses look like `angles', but they look like
317 `parens' if `angles' would need quoting and `parens' would not."
318 :type '(choice (const :tag "simple" nil)
322 :group 'message-headers)
324 (defcustom message-insert-canlock t
325 "Whether to insert a Cancel-Lock header in news postings."
327 :group 'message-headers
330 (defcustom message-syntax-checks
331 (if message-insert-canlock '((sender . disabled)) nil)
332 ;; Guess this one shouldn't be easy to customize...
333 "*Controls what syntax checks should not be performed on outgoing posts.
334 To disable checking of long signatures, for instance, add
335 `(signature . disabled)' to this list.
337 Don't touch this variable unless you really know what you're doing.
339 Checks include `subject-cmsg', `multiple-headers', `sendsys',
340 `message-id', `from', `long-lines', `control-chars', `size',
341 `new-text', `quoting-style', `redirected-followup', `signature',
342 `approved', `sender', `empty', `empty-headers', `message-id', `from',
343 `subject', `shorten-followup-to', `existing-newsgroups',
344 `buffer-file-name', `unchanged', `newsgroups', `reply-to'."
346 :type '(repeat sexp)) ; Fixme: improve this
348 (defcustom message-required-news-headers
349 '(From Newsgroups Subject Date Message-ID
350 (optional . Organization)
351 (optional . References)
352 (optional . User-Agent))
353 "*Headers to be generated or prompted for when posting an article.
354 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
355 Message-ID. Organization, Lines, In-Reply-To, Expires, and
356 User-Agent are optional. If don't you want message to insert some
357 header, remove it from this list."
359 :group 'message-headers
360 :type '(repeat sexp))
362 (defcustom message-required-mail-headers
363 '(From Subject Date (optional . In-Reply-To) Message-ID
364 (optional . User-Agent)
365 (optional . References))
366 "*Headers to be generated or prompted for when mailing a message.
367 It is recommended that From, Date, To, Subject and Message-ID be
368 included. Organization and User-Agent are optional."
370 :group 'message-headers
371 :type '(repeat sexp))
373 (defcustom message-deletable-headers '(Message-ID Date Lines)
374 "Headers to be deleted if they already exist and were generated by message previously."
375 :group 'message-headers
378 (defcustom message-ignored-news-headers
379 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
380 "*Regexp of headers to be removed unconditionally before posting."
382 :group 'message-headers
385 (defcustom message-ignored-mail-headers
386 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
387 "*Regexp of headers to be removed unconditionally before mailing."
389 :group 'message-headers
392 (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:"
393 "*Header lines matching this regexp will be deleted before posting.
394 It's best to delete old Path and Date headers before posting to avoid
396 :group 'message-interface
399 (defcustom message-supersede-setup-function
400 'message-supersede-setup-for-mime-edit
401 "Function to setup a supersede message."
402 :group 'message-sending
405 (defcustom message-subject-re-regexp
406 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)*:[ \t]*\\)*[ \t]*"
407 "*Regexp matching \"Re: \" in the subject line."
408 :group 'message-various
411 ;;; Some sender agents encode the whole subject including leading "Re: ".
412 ;;; And if followup agent does not decode it for some reason (e.g. unknown
413 ;;; charset) and just add a new "Re: " in front of the encoded-word, the
414 ;;; result will contain multiple "Re: "'s.
415 (defcustom message-subject-encoded-re-regexp
419 "[-!#$%&'*+0-9A-Z^_`a-z{|}~]+" ; charset
422 "[Bb]" (regexp-quote "?") ; B encoding
423 "\\(\\(CQk\\|CSA\\|IAk\\|ICA\\)[Jg]\\)*" ; \([ \t][ \t][ \t]\)*
425 "[Uc][km]U6" ; [Rr][Ee]:
427 "\\(C[VX]\\|I[FH]\\)J[Fl]O[g-v]" ; [ \t][Rr][Ee]:
429 "\\(CQl\\|CSB\\|IAl\\|ICB\\)[Sy][RZ]T[o-r]" ; [ \t][ \t][Rr][Ee]:
432 "[Qb]" (regexp-quote "?") ; Q encoding
433 "\\(_\\|=09\\|=20\\)*"
434 "\\([Rr]\\|=[57]2\\)\\([Ee]\\|=[46]5\\)\\(:\\|=3[Aa]\\)"
437 "*Regexp matching \"Re: \" in the subject line.
438 Unlike `message-subject-re-regexp', this regexp matches \"Re: \" within
440 :group 'message-various
443 (defcustom message-use-subject-re t
444 "*If t, remove any (buggy) \"Re: \"'s from the subject of the precursor
445 and add a new \"Re: \". If it is nil, use the subject \"as-is\". If it
446 is the symbol `guess', try to detect \"Re: \" within an encoded-word."
447 :group 'message-various
448 :type '(choice (const :tag "off" nil)
453 (defcustom message-signature-separator "^-- *$"
454 "Regexp matching the signature separator."
456 :group 'message-various)
458 (defcustom message-signature-separator-for-insertion "-- \n"
459 "*Signature separator. This value will be inserted as signature separator
460 when composing message. Default value is \"-- \\n\". Notice: Changing this
461 value may go against RFC-1036 and draft-ietf-usefor-article-05.txt. "
463 :group 'message-insertion)
465 (defcustom message-elide-ellipsis "\n[...]\n\n"
466 "*The string which is inserted for elided text."
468 :group 'message-various)
470 (defcustom message-interactive t
471 "Non-nil means when sending a message wait for and display errors.
472 nil means let mailer mail back a message to report errors."
473 :group 'message-sending
477 (defcustom message-generate-new-buffers 'unique
478 "*Non-nil means create a new message buffer whenever `message-setup' is called.
479 If this is a function, call that function with three parameters: The type,
480 the to address and the group name. (Any of these may be nil.) The function
481 should return the new buffer name."
482 :group 'message-buffers
483 :type '(choice (const :tag "off" nil)
484 (const :tag "unique" unique)
485 (const :tag "unsent" unsent)
488 (defcustom message-kill-buffer-on-exit nil
489 "*Non-nil means that the message buffer will be killed after sending a message."
490 :group 'message-buffers
493 (defcustom message-kill-buffer-query-function 'yes-or-no-p
494 "*Function used to prompt user whether to kill the message buffer. If
495 it is t, the buffer will be killed unconditionally."
496 :type '(radio (function-item yes-or-no-p)
497 (function-item y-or-n-p)
498 (function-item nnheader-Y-or-n-p)
499 (function :tag "Other" t))
500 :group 'message-buffers)
502 (defcustom message-kill-buffer-and-remove-file t
503 "*Non-nil means that the associated file will be removed before
504 removing the message buffer. However, it is treated as nil when the
505 command `message-mimic-kill-buffer' is used."
506 :group 'message-buffers
510 (defvar gnus-local-organization))
511 (defcustom message-user-organization
512 (or (and (boundp 'gnus-local-organization)
513 (stringp gnus-local-organization)
514 gnus-local-organization)
515 (getenv "ORGANIZATION")
517 "*String to be used as an Organization header.
518 If t, use `message-user-organization-file'."
519 :group 'message-headers
520 :type '(choice string
521 (const :tag "consult file" t)))
524 (defcustom message-user-organization-file "/usr/lib/news/organization"
525 "*Local news organization file."
527 :group 'message-headers)
529 (defcustom message-forward-start-separator
530 (concat (mime-make-tag "message" "rfc822") "\n")
531 "*Delimiter inserted before forwarded messages."
532 :group 'message-forwarding
535 (defcustom message-forward-end-separator
536 (concat (mime-make-tag "text" "plain") "\n")
537 "*Delimiter inserted after forwarded messages."
538 :group 'message-forwarding
541 (defcustom message-included-forward-headers
542 "^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:"
543 "*Regexp matching headers to be included in forwarded messages."
544 :group 'message-forwarding
547 (defcustom message-make-forward-subject-function
548 'message-forward-subject-author-subject
549 "*List of functions called to generate subject headers for forwarded messages.
550 The subject generated by the previous function is passed into each
553 The provided functions are:
555 * `message-forward-subject-author-subject' (Source of article (author or
556 newsgroup)), in brackets followed by the subject
557 * `message-forward-subject-fwd' (Subject of article with 'Fwd:' prepended
559 :group 'message-forwarding
560 :type '(radio (function-item message-forward-subject-author-subject)
561 (function-item message-forward-subject-fwd)
562 (repeat :tag "List of functions" function)))
564 (defcustom message-forward-as-mime t
565 "*If non-nil, forward messages as an inline/rfc822 MIME section. Otherwise, directly inline the old message in the forwarded message."
567 :group 'message-forwarding
570 (defcustom message-forward-show-mml t
571 "*If non-nil, forward messages are shown as mml. Otherwise, forward messages are unchanged."
573 :group 'message-forwarding
576 (defcustom message-forward-before-signature t
577 "*If non-nil, put forwarded message before signature, else after."
578 :group 'message-forwarding
581 (defcustom message-wash-forwarded-subjects nil
582 "*If non-nil, try to remove as much old cruft as possible from the subject of messages before generating the new subject of a forward."
583 :group 'message-forwarding
586 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From "
587 "*All headers that match this regexp will be deleted when resending a message."
588 :group 'message-interface
591 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
592 "*All headers that match this regexp will be deleted when forwarding a message."
594 :group 'message-forwarding
595 :type '(choice (const :tag "None" nil)
598 (defcustom message-ignored-cited-headers "."
599 "*Delete these headers from the messages you yank."
600 :group 'message-insertion
603 (defcustom message-cite-prefix-regexp
604 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
605 "\\([ \t]*[-_.[:word:]]+>+\\|[ \t]*[]>|}+]\\)+"
606 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
607 (let ((old-table (syntax-table))
608 non-word-constituents)
609 (set-syntax-table text-mode-syntax-table)
610 (setq non-word-constituents
612 (if (string-match "\\w" "-") "" "-")
613 (if (string-match "\\w" "_") "" "_")
614 (if (string-match "\\w" ".") "" ".")))
615 (set-syntax-table old-table)
616 (if (equal non-word-constituents "")
617 "\\([ \t]*\\(\\w\\)+>+\\|[ \t]*[]>|}+]\\)+"
618 (concat "\\([ \t]*\\(\\w\\|["
619 non-word-constituents
620 "]\\)+>+\\|[ \t]*[]>|}+]\\)+"))))
621 "*Regexp matching the longest possible citation prefix on a line."
622 :group 'message-insertion
625 (defcustom message-cancel-message "I am canceling my own article.\n"
626 "Message to be inserted in the cancel message."
627 :group 'message-interface
630 ;; Useful to set in site-init.el
632 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
633 "Function to call to send the current buffer as mail.
634 The headers should be delimited by a line whose contents match the
635 variable `mail-header-separator'.
637 Valid values include `message-send-mail-with-sendmail' (the default),
638 `message-send-mail-with-mh', `message-send-mail-with-qmail',
639 `message-send-mail-with-smtp', `message-smtpmail-send-it',
640 `smtpmail-send-it' and `feedmail-send-it'.
642 See also `send-mail-function'."
643 :type '(radio (function-item message-send-mail-with-sendmail)
644 (function-item message-send-mail-with-mh)
645 (function-item message-send-mail-with-qmail)
646 (function-item message-send-mail-with-smtp)
647 (function-item message-smtpmail-send-it)
648 (function-item smtpmail-send-it)
649 (function-item feedmail-send-it)
650 (function :tag "Other"))
651 :group 'message-sending
652 :group 'message-mail)
654 ;; 1997-09-29 by MORIOKA Tomohiko
655 (defcustom message-send-news-function 'message-send-news-with-gnus
656 "Function to call to send the current buffer as news.
657 The headers should be delimited by a line whose contents match the
658 variable `mail-header-separator'."
659 :group 'message-sending
663 (defcustom message-reply-to-function nil
664 "If non-nil, function that should return a list of headers.
665 This function should pick out addresses from the To, Cc, and From headers
666 and respond with new To and Cc headers."
667 :group 'message-interface
668 :type '(choice function (const nil)))
670 (defcustom message-wide-reply-to-function nil
671 "If non-nil, function that should return a list of headers.
672 This function should pick out addresses from the To, Cc, and From headers
673 and respond with new To and Cc headers."
674 :group 'message-interface
675 :type '(choice function (const nil)))
677 (defcustom message-followup-to-function nil
678 "If non-nil, function that should return a list of headers.
679 This function should pick out addresses from the To, Cc, and From headers
680 and respond with new To and Cc headers."
681 :group 'message-interface
682 :type '(choice function (const nil)))
684 (defcustom message-use-followup-to 'ask
685 "*Specifies what to do with Followup-To header.
686 If nil, always ignore the header. If it is t, use its value, but
687 query before using the \"poster\" value. If it is the symbol `ask',
688 always query the user whether to use the value. If it is the symbol
689 `use', always use the value."
690 :group 'message-interface
691 :type '(choice (const :tag "ignore" nil)
692 (const :tag "use & query" t)
693 (const :tag "maybe" t)
694 (const :tag "always" use)
695 (const :tag "ask" ask)))
697 (defcustom message-use-mail-copies-to 'ask
698 "*Specifies what to do with Mail-Copies-To header.
699 If nil, always ignore the header. If it is t, use its value, but
700 query before using the value other than \"always\" or \"never\".
701 If it is the symbol `ask', always query the user whether to use
702 the value. If it is the symbol `use', always use the value."
703 :group 'message-interface
704 :type '(choice (const :tag "ignore" nil)
705 (const :tag "maybe" t)
706 (const :tag "always" use)
707 (const :tag "ask" ask)))
709 ;;; XXX: 'ask and 'use are not implemented yet.
710 (defcustom message-use-mail-reply-to 'ask
711 "*Specifies what to do with Mail-Reply-To/Reply-To header.
712 If nil, always ignore the header. If it is t or the symbol `use', use
713 its value. If it is the symbol `ask', always query the user whether to
714 use the value. Note that if \"Reply-To\" is marked as \"broken\", its value
716 :group 'message-interface
717 :type '(choice (const :tag "ignore" nil)
718 (const :tag "maybe" t)
719 (const :tag "always" use)
720 (const :tag "ask" ask)))
722 (defcustom message-use-mail-followup-to 'use
723 "*Specifies what to do with Mail-Followup-To header.
724 If nil, always ignore the header. If it is the symbol `ask', always
725 query the user whether to use the value. If it is t or the symbol
726 `use', always use the value."
727 :group 'message-interface
728 :type '(choice (const :tag "ignore" nil)
729 (const :tag "maybe" t)
730 (const :tag "always" use)
731 (const :tag "ask" ask)))
733 (defcustom message-subscribed-address-functions nil
734 "*Specifies functions for determining list subscription.
735 If nil, do not attempt to determine list subscribtion with functions.
736 If non-nil, this variable contains a list of functions which return
737 regular expressions to match lists. These functions can be used in
738 conjunction with `message-subscribed-regexps' and
739 `message-subscribed-addresses'."
740 :group 'message-interface
741 :type '(repeat sexp))
743 (defcustom message-subscribed-address-file nil
744 "*A file containing addresses the user is subscribed to.
745 If nil, do not look at any files to determine list subscriptions. If
746 non-nil, each line of this file should be a mailing list address."
747 :group 'message-interface
750 (defcustom message-subscribed-addresses nil
751 "*Specifies a list of addresses the user is subscribed to.
752 If nil, do not use any predefined list subscriptions. This list of
753 addresses can be used in conjuction with
754 `message-subscribed-address-functions' and `message-subscribed-regexps'."
755 :group 'message-interface
756 :type '(repeat string))
758 (defcustom message-subscribed-regexps nil
759 "*Specifies a list of addresses the user is subscribed to.
760 If nil, do not use any predefined list subscriptions. This list of
761 regular expressions can be used in conjuction with
762 `message-subscribed-address-functions' and `message-subscribed-addresses'."
763 :group 'message-interface
764 :type '(repeat regexp))
766 (defcustom message-allow-no-recipients 'ask
767 "Specifies what to do when there are no recipients other than Gcc/Fcc.
768 If it is the symbol `always', the posting is allowed. If it is the
769 symbol `never', the posting is not allowed. If it is the symbol
770 `ask', you are prompted."
771 :group 'message-interface
772 :type '(choice (const always)
776 (defcustom message-sendmail-f-is-evil nil
777 "*Non-nil means don't add \"-f username\" to the sendmail command line.
778 Doing so would be even more evil than leaving it out."
779 :group 'message-sending
782 ;; qmail-related stuff
783 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
784 "Location of the qmail-inject program."
785 :group 'message-sending
788 (defcustom message-qmail-inject-args nil
789 "Arguments passed to qmail-inject programs.
790 This should be a list of strings, one string for each argument. It
791 may also be a function.
793 For e.g., if you wish to set the envelope sender address so that bounces
794 go to the right place or to deal with listserv's usage of that address, you
795 might set this variable to '(\"-f\" \"you@some.where\")."
796 :group 'message-sending
797 :type '(choice (function)
800 (defvar message-cater-to-broken-inn t
801 "Non-nil means Gnus should not fold the `References' header.
802 Folding `References' makes ancient versions of INN create incorrect
806 (defvar gnus-post-method)
807 (defvar gnus-select-method))
808 (defcustom message-post-method
809 (cond ((and (boundp 'gnus-post-method)
810 (listp gnus-post-method)
813 ((boundp 'gnus-select-method)
816 "*Method used to post news.
817 Note that when posting from inside Gnus, for instance, this
818 variable isn't used."
820 :group 'message-sending
821 ;; This should be the `gnus-select-method' widget, but that might
822 ;; create a dependence to `gnus.el'.
825 (defcustom message-generate-headers-first nil
826 "*If non-nil, generate all required headers before composing.
827 The variables `message-required-news-headers' and
828 `message-required-mail-headers' specify which headers to generate.
830 Note that the variable `message-deletable-headers' specifies headers which
831 are to be deleted and then re-generated before sending, so this variable
832 will not have a visible effect for those headers."
833 :group 'message-headers
836 (defcustom message-setup-hook '(turn-on-mime-edit)
837 "Normal hook, run each time a new outgoing message is initialized.
838 The function `message-setup' runs this hook."
839 :group 'message-various
842 (defcustom message-cancel-hook nil
843 "Hook run when cancelling articles."
844 :group 'message-various
847 (defcustom message-signature-setup-hook nil
848 "Normal hook, run each time a new outgoing message is initialized.
849 It is run after the headers have been inserted and before
850 the signature is inserted."
851 :group 'message-various
854 (defcustom message-bounce-setup-hook nil
855 "Normal hook, run each time a re-sending bounced message is initialized.
856 The function `message-bounce' runs this hook."
857 :group 'message-various
860 (defcustom message-supersede-setup-hook nil
861 "Normal hook, run each time a supersede message is initialized.
862 The function `message-supersede' runs this hook."
863 :group 'message-various
866 (defcustom message-mode-hook nil
867 "Hook run in message mode buffers."
868 :group 'message-various
871 (defcustom message-header-hook '((lambda () (mime-encode-header-in-buffer t)))
872 "Hook run in a message mode buffer narrowed to the headers."
873 :group 'message-various
876 (defcustom message-header-setup-hook nil
877 "Hook called narrowed to the headers when setting up a message buffer."
878 :group 'message-various
881 (defcustom message-minibuffer-local-map
882 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
883 (set-keymap-parent map minibuffer-local-map)
885 "Keymap for `message-read-from-minibuffer'.")
888 (defcustom message-citation-line-function 'message-insert-citation-line
889 "*Function called to insert the \"Whomever writes:\" line.
891 Note that Gnus provides a feature where the reader can click on
892 `writes:' to hide the cited text. If you change this line too much,
893 people who read your message will have to change their Gnus
894 configuration. See the variable `gnus-cite-attribution-suffix'."
896 :group 'message-insertion)
899 (defcustom message-yank-prefix "> "
900 "*Prefix inserted on the lines of yanked messages.
901 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
902 See also `message-yank-cited-prefix'."
904 :group 'message-insertion)
906 (defcustom message-yank-add-new-references t
907 "Non-nil means new IDs will be added to \"References\" field when an
908 article is yanked by the command `message-yank-original' interactively.
909 If it is a symbol `message-id-only', only an ID from \"Message-ID\" field
910 is used, otherwise IDs extracted from \"References\", \"In-Reply-To\" and
911 \"Message-ID\" fields are used."
912 :type '(radio (const :tag "Do not add anything" nil)
913 (const :tag "From Message-Id, References and In-Reply-To fields" t)
914 (const :tag "From only Message-Id field." message-id-only))
915 :group 'message-insertion)
917 (defcustom message-list-references-add-position nil
918 "Integer value means position for adding to \"References\" field when
919 an article is yanked by the command `message-yank-original' interactively."
920 :type '(radio (const :tag "Add to last" nil)
921 (integer :tag "Position from last ID"))
922 :group 'message-insertion)
924 (defcustom message-yank-cited-prefix ">"
925 "*Prefix inserted on cited or empty lines of yanked messages.
926 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
927 See also `message-yank-prefix'."
929 :group 'message-insertion)
931 (defcustom message-indentation-spaces 3
932 "*Number of spaces to insert at the beginning of each cited line.
933 Used by `message-yank-original' via `message-yank-cite'."
934 :group 'message-insertion
938 (defcustom message-cite-function 'message-cite-original
939 "*Function for citing an original message.
940 Predefined functions include `message-cite-original' and
941 `message-cite-original-without-signature'.
942 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
943 :type '(radio (function-item message-cite-original)
944 (function-item message-cite-original-without-signature)
945 (function-item mu-cite-original)
946 (function-item sc-cite-original)
947 (function :tag "Other"))
948 :group 'message-insertion)
951 (defcustom message-suspend-font-lock-when-citing nil
952 "Non-nil means suspend font-lock'ing while citing an original message.
953 Some lazy demand-driven fontification tools (or Emacs itself) have a
954 bug that they often miss a buffer to be fontified. It will mostly
955 occur when Emacs prompts user for any inputs in the minibuffer.
956 Setting this option to non-nil may help you to avoid unpleasant errors
957 even if it is an add-hoc expedient."
959 :group 'message-insertion)
962 (defcustom message-indent-citation-function 'message-indent-citation
963 "*Function for modifying a citation just inserted in the mail buffer.
964 This can also be a list of functions. Each function can find the
965 citation between (point) and (mark t). And each function should leave
966 point and mark around the citation text as modified."
968 :group 'message-insertion)
971 (defcustom message-signature t
972 "*String to be inserted at the end of the message buffer.
973 If t, the `message-signature-file' file will be inserted instead.
974 If a function, the result from the function will be used instead.
975 If a form, the result from the form will be used instead."
977 :group 'message-insertion)
980 (defcustom message-signature-file "~/.signature"
981 "*Name of file containing the text inserted at end of message buffer.
982 Ignored if the named file doesn't exist.
983 If nil, don't insert a signature."
984 :type '(choice file (const :tags "None" nil))
985 :group 'message-insertion)
987 (defcustom message-distribution-function nil
988 "*Function called to return a Distribution header."
990 :group 'message-headers
991 :type '(choice function (const nil)))
993 (defcustom message-expires 14
994 "Number of days before your article expires."
996 :group 'message-headers
997 :link '(custom-manual "(message)News Headers")
1000 (defcustom message-user-path nil
1001 "If nil, use the NNTP server name in the Path header.
1002 If stringp, use this; if non-nil, use no host name (user name only)."
1003 :group 'message-news
1004 :group 'message-headers
1005 :link '(custom-manual "(message)News Headers")
1006 :type '(choice (const :tag "nntp" nil)
1007 (string :tag "name")
1008 (sexp :tag "none" :format "%t" t)))
1010 (defvar message-reply-buffer nil)
1011 (defvar message-reply-headers nil
1012 "The headers of the current replied article.
1013 It is a vector of the following headers:
1014 \[number subject from date id references chars lines xref extra].")
1015 (defvar message-sent-message-via nil)
1016 (defvar message-checksum nil)
1017 (defvar message-send-actions nil
1018 "A list of actions to be performed upon successful sending of a message.")
1019 (defvar message-exit-actions nil
1020 "A list of actions to be performed upon exiting after sending a message.")
1021 (defvar message-kill-actions nil
1022 "A list of actions to be performed before killing a message buffer.")
1023 (defvar message-postpone-actions nil
1024 "A list of actions to be performed after postponing a message.")
1025 (defvar message-original-frame nil)
1026 (defvar message-parameter-alist nil)
1027 (defvar message-startup-parameter-alist nil)
1029 (define-widget 'message-header-lines 'text
1030 "All header lines must be LFD terminated."
1031 :format "%{%t%}:%n%v"
1032 :valid-regexp "^\\'"
1033 :error "All header lines must be newline terminated")
1035 (defcustom message-default-headers ""
1036 "*A string containing header lines to be inserted in outgoing messages.
1037 It is inserted before you edit the message, so you can edit or delete
1039 :group 'message-headers
1040 :type 'message-header-lines)
1042 (defcustom message-default-mail-headers ""
1043 "*A string of header lines to be inserted in outgoing mails."
1044 :group 'message-headers
1045 :group 'message-mail
1046 :type 'message-header-lines)
1048 (defcustom message-default-news-headers ""
1049 "*A string of header lines to be inserted in outgoing news articles."
1050 :group 'message-headers
1051 :group 'message-news
1052 :type 'message-header-lines)
1054 ;; Note: could use /usr/ucb/mail instead of sendmail;
1055 ;; options -t, and -v if not interactive.
1056 (defcustom message-mailer-swallows-blank-line
1057 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1058 system-configuration)
1059 (file-readable-p "/etc/sendmail.cf")
1060 (let ((buffer (get-buffer-create " *temp*")))
1064 (insert-file-contents "/etc/sendmail.cf")
1065 (goto-char (point-min))
1066 (let ((case-fold-search nil))
1067 (re-search-forward "^OR\\>" nil t)))
1068 (kill-buffer buffer))))
1069 ;; According to RFC822, "The field-name must be composed of printable
1070 ;; ASCII characters (i. e., characters that have decimal values between
1071 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1073 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1074 "*Set this non-nil if the system's mailer runs the header and body together.
1075 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1076 The value should be an expression to test whether the problem will
1078 :group 'message-sending
1081 ;;; XXX: This symbol is overloaded! See below.
1082 (defvar message-user-agent nil
1083 "String of the form of PRODUCT/VERSION. Used for User-Agent header field.")
1085 (static-when (boundp 'MULE)
1086 (require 'reporter));; `define-mail-user-agent' is here.
1089 (define-mail-user-agent 'message-user-agent
1090 'message-mail 'message-send-and-exit
1091 'message-kill-buffer 'message-send-hook)
1093 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
1094 "If non-nil, delete the deletable headers before feeding to mh.")
1096 (defvar message-send-method-alist
1097 '((news message-news-p message-send-via-news)
1098 (mail message-mail-p message-send-via-mail))
1099 "Alist of ways to send outgoing messages.
1100 Each element has the form
1102 \(TYPE PREDICATE FUNCTION)
1104 where TYPE is a symbol that names the method; PREDICATE is a function
1105 called without any parameters to determine whether the message is
1106 a message of type TYPE; and FUNCTION is a function to be called if
1107 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1110 (defcustom message-mail-alias-type 'abbrev
1111 "*What alias expansion type to use in Message buffers.
1112 The default is `abbrev', which uses mailabbrev. nil switches
1115 :link '(custom-manual "(message)Mail Aliases")
1116 :type '(choice (const :tag "Use Mailabbrev" abbrev)
1117 (const :tag "No expansion" nil)))
1119 (defcustom message-auto-save-directory
1120 (file-name-as-directory (nnheader-concat message-directory "drafts"))
1121 "*Directory where Message auto-saves buffers if Gnus isn't running.
1122 If nil, Message won't auto-save."
1123 :group 'message-buffers
1124 :type '(choice directory (const :tag "Don't auto-save" nil)))
1126 (defcustom message-default-charset
1127 (and (featurep 'xemacs) (not (featurep 'mule)) 'iso-8859-1)
1128 "Default charset used in non-MULE XEmacsen."
1133 (defcustom message-dont-reply-to-names
1134 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
1135 "*A regexp specifying addresses to prune when doing wide replies.
1136 A value of nil means exclude your own user name only."
1139 :type '(choice (const :tag "Yourself" nil)
1142 (defvar message-shoot-gnksa-feet nil
1143 "*A list of GNKSA feet you are allowed to shoot.
1144 Gnus gives you all the opportunity you could possibly want for
1145 shooting yourself in the foot. Also, Gnus allows you to shoot the
1146 feet of Good Net-Keeping Seal of Approval. The following are foot
1148 `empty-article' Allow you to post an empty article;
1149 `quoted-text-only' Allow you to post quoted text only;
1150 `multiple-copies' Allow you to post multiple copies;
1151 `cancel-messages' Allow you to cancel or supersede messages from
1152 your other email addresses.")
1154 (defsubst message-gnksa-enable-p (feature)
1155 (or (not (listp message-shoot-gnksa-feet))
1156 (memq feature message-shoot-gnksa-feet)))
1158 ;;; Internal variables.
1159 ;;; Well, not really internal.
1161 (defvar message-mode-syntax-table
1162 (let ((table (copy-syntax-table text-mode-syntax-table)))
1163 (modify-syntax-entry ?% ". " table)
1164 (modify-syntax-entry ?> ". " table)
1165 (modify-syntax-entry ?< ". " table)
1167 "Syntax table used while in Message mode.")
1169 (defface message-header-to-face
1172 (:foreground "green2" :bold t))
1175 (:foreground "MidnightBlue" :bold t))
1177 (:bold t :italic t)))
1178 "Face used for displaying From headers."
1179 :group 'message-faces)
1181 (defface message-header-cc-face
1184 (:foreground "green4" :bold t))
1187 (:foreground "MidnightBlue"))
1190 "Face used for displaying Cc headers."
1191 :group 'message-faces)
1193 (defface message-header-subject-face
1196 (:foreground "green3"))
1199 (:foreground "navy blue" :bold t))
1202 "Face used for displaying subject headers."
1203 :group 'message-faces)
1205 (defface message-header-newsgroups-face
1208 (:foreground "yellow" :bold t :italic t))
1211 (:foreground "blue4" :bold t :italic t))
1213 (:bold t :italic t)))
1214 "Face used for displaying newsgroups headers."
1215 :group 'message-faces)
1217 (defface message-header-other-face
1220 (:foreground "#b00000"))
1223 (:foreground "steel blue"))
1225 (:bold t :italic t)))
1226 "Face used for displaying newsgroups headers."
1227 :group 'message-faces)
1229 (defface message-header-name-face
1232 (:foreground "DarkGreen"))
1235 (:foreground "cornflower blue"))
1238 "Face used for displaying header names."
1239 :group 'message-faces)
1241 (defface message-header-xheader-face
1244 (:foreground "blue"))
1247 (:foreground "blue"))
1250 "Face used for displaying X-Header headers."
1251 :group 'message-faces)
1253 (defface message-separator-face
1256 (:foreground "blue3"))
1259 (:foreground "brown"))
1262 "Face used for displaying the separator."
1263 :group 'message-faces)
1265 (defface message-cited-text-face
1268 (:foreground "red"))
1271 (:foreground "red"))
1274 "Face used for displaying cited text names."
1275 :group 'message-faces)
1277 (defface message-mml-face
1280 (:foreground "ForestGreen"))
1283 (:foreground "ForestGreen"))
1286 "Face used for displaying MML."
1287 :group 'message-faces)
1289 (defun message-font-lock-make-header-matcher (regexp)
1292 (let ((start (point)))
1295 (goto-char (point-min))
1296 (if (re-search-forward
1297 (concat "^" (regexp-quote mail-header-separator) "$")
1299 (setq limit (min limit (match-beginning 0))))
1301 (and (< start limit)
1302 (re-search-forward ,regexp limit t))))))
1303 (if (featurep 'bytecomp)
1307 (defvar message-font-lock-keywords
1308 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1309 `((,(message-font-lock-make-header-matcher
1310 (concat "^\\([Tt]o:\\)" content))
1311 (1 'message-header-name-face)
1312 (2 'message-header-to-face nil t))
1313 (,(message-font-lock-make-header-matcher
1314 (concat "^\\([GBF]?[Cc][Cc]:\\|[Rr]eply-[Tt]o:\\|"
1315 "[Mm]ail-[Cc]opies-[Tt]o:\\|"
1316 "[Mm]ail-[Rr]eply-[Tt]o:\\|"
1317 "[Mm]ail-[Ff]ollowup-[Tt]o:\\)" content))
1318 (1 'message-header-name-face)
1319 (2 'message-header-cc-face nil t))
1320 (,(message-font-lock-make-header-matcher
1321 (concat "^\\([Ss]ubject:\\)" content))
1322 (1 'message-header-name-face)
1323 (2 'message-header-subject-face nil t))
1324 (,(message-font-lock-make-header-matcher
1325 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content))
1326 (1 'message-header-name-face)
1327 (2 'message-header-newsgroups-face nil t))
1328 (,(message-font-lock-make-header-matcher
1329 (concat "^\\([A-Z][^: \n\t]+:\\)" content))
1330 (1 'message-header-name-face)
1331 (2 'message-header-other-face nil t))
1332 (,(message-font-lock-make-header-matcher
1333 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content))
1334 (1 'message-header-name-face)
1335 (2 'message-header-name-face))
1336 ,@(if (and mail-header-separator
1337 (not (equal mail-header-separator "")))
1338 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1339 1 'message-separator-face))
1342 (re-search-forward (concat "^\\("
1343 message-cite-prefix-regexp
1346 (0 'message-cited-text-face))
1347 (,mime-edit-tag-regexp
1348 (0 'message-mml-face))))
1349 "Additional expressions to highlight in Message mode.")
1351 ;; XEmacs does it like this. For Emacs, we have to set the
1352 ;; `font-lock-defaults' buffer-local variable.
1353 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
1355 (defvar message-face-alist
1356 '((bold . bold-region)
1357 (underline . underline-region)
1358 (default . (lambda (b e)
1360 (ununderline-region b e))))
1361 "Alist of mail and news faces for facemenu.
1362 The cdr of each entry is a function for applying the face to a region.")
1364 (defcustom message-send-hook nil
1365 "Hook run before sending messages."
1366 :group 'message-various
1367 :options '(ispell-message)
1370 (defcustom message-send-mail-hook nil
1371 "Hook run before sending mail messages."
1372 :group 'message-various
1375 (defcustom message-send-news-hook nil
1376 "Hook run before sending news messages."
1377 :group 'message-various
1380 (defcustom message-sent-hook nil
1381 "Hook run after sending messages."
1382 :group 'message-various
1385 (defcustom message-use-multi-frames nil
1386 "Make new frame when sending messages."
1387 :group 'message-frames
1390 (defcustom message-delete-frame-on-exit nil
1391 "Delete frame after sending messages."
1392 :group 'message-frames
1393 :type '(choice (const :tag "off" nil)
1394 (const :tag "always" t)
1395 (const :tag "ask" ask)))
1397 (defvar message-draft-coding-system
1398 nnheader-auto-save-coding-system
1399 "*Coding system to compose mail.
1400 If you'd like to make it possible to share draft files between XEmacs
1401 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1402 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1404 (defcustom message-send-mail-partially-limit 1000000
1405 "The limitation of messages sent as message/partial.
1406 The lower bound of message size in characters, beyond which the message
1407 should be sent in several parts. If it is nil, the size is unlimited."
1409 :group 'message-buffers
1410 :type '(choice (const :tag "unlimited" nil)
1413 (defcustom message-alternative-emails nil
1414 "A regexp to match the alternative email addresses.
1415 The first matched address (not primary one) is used in the From field."
1416 :group 'message-headers
1417 :type '(choice (const :tag "Always use primary" nil)
1420 (defcustom message-hierarchical-addresses nil
1421 "A list of hierarchical mail address definitions.
1423 Inside each entry, the first address is the \"top\" address, and
1424 subsequent addresses are subaddresses; this is used to indicate that
1425 mail sent to the first address will automatically be delivered to the
1426 subaddresses. So if the first address appears in the recipient list
1427 for a message, the subaddresses will be removed (if present) before
1428 the mail is sent. All addresses in this structure should be
1430 :group 'message-headers
1431 :type '(repeat (repeat string)))
1433 (defcustom message-mail-user-agent nil
1434 "Like `mail-user-agent'.
1435 Except if it is nil, use Gnus native MUA; if it is t, use
1437 :type '(radio (const :tag "Gnus native"
1440 (const :tag "`mail-user-agent'"
1443 (function-item :tag "Default Emacs mail"
1445 sendmail-user-agent)
1446 (function-item :tag "Emacs interface to MH"
1449 (function :tag "Other"))
1453 (defcustom message-wide-reply-confirm-recipients nil
1454 "Whether to confirm a wide reply to multiple email recipients.
1455 If this variable is nil, don't ask whether to reply to all recipients.
1456 If this variable is non-nil, pose the question \"Reply to all
1457 recipients?\" before a wide reply to multiple recipients. If the user
1458 answers yes, reply to all recipients as usual. If the user answers
1459 no, only reply back to the author."
1461 :group 'message-headers
1464 ;;; Internal variables.
1466 (defvar message-sending-message "Sending...")
1467 (defvar message-buffer-list nil)
1468 (defvar message-this-is-news nil)
1469 (defvar message-this-is-mail nil)
1470 (defvar message-draft-article nil)
1471 (defvar message-mime-part nil)
1472 (defvar message-posting-charset nil)
1474 ;; Byte-compiler warning
1476 (defvar gnus-active-hashtb)
1477 (defvar gnus-read-active-file))
1479 ;;; Regexp matching the delimiter of messages in UNIX mail format
1480 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1481 ;;; of rmail.el's rmail-unix-mail-delimiter.
1482 (defvar message-unix-mail-delimiter
1483 (let ((time-zone-regexp
1484 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1485 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1491 ;; Many things can happen to an RFC 822 mailbox before it is put into
1492 ;; a `From' line. The leading phrase can be stripped, e.g.
1493 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1494 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1495 ;; can be removed, e.g.
1496 ;; From: joe@y.z (Joe K
1498 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1501 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1502 ;; The mailbox can be removed or be replaced by white space, e.g.
1503 ;; From: "Joe User"{space}{tab}
1505 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1506 ;; where {space} and {tab} represent the Ascii space and tab characters.
1507 ;; We want to match the results of any of these manglings.
1508 ;; The following regexp rejects names whose first characters are
1509 ;; obviously bogus, but after that anything goes.
1510 "\\([^\0-\b\n-\r\^?].*\\)? "
1512 ;; The time the message was sent.
1513 "\\([^\0-\r \^?]+\\) +" ; day of the week
1514 "\\([^\0-\r \^?]+\\) +" ; month
1515 "\\([0-3]?[0-9]\\) +" ; day of month
1516 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1518 ;; Perhaps a time zone, specified by an abbreviation, or by a
1523 " \\([0-9][0-9]+\\) *"
1525 ;; On some systems the time zone can appear after the year, too.
1529 "\\(remote from .*\\)?"
1532 "Regexp matching the delimiter of messages in UNIX mail format.")
1534 (defvar message-unsent-separator
1535 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1536 "^ *---+ +Returned message +---+ *$\\|"
1537 "^Start of returned message$\\|"
1538 "^ *---+ +Original message +---+ *$\\|"
1539 "^ *--+ +begin message +--+ *$\\|"
1540 "^ *---+ +Original message follows +---+ *$\\|"
1541 "^ *---+ +Undelivered message follows +---+ *$\\|"
1542 "^|? *---+ +Message text follows: +---+ *|?$")
1543 "A regexp that matches the separator before the text of a failed message.")
1545 (defvar message-header-format-alist
1547 (To . message-fill-address)
1548 (Cc . message-fill-address)
1559 (References . message-shorten-references)
1561 "Alist used for formatting headers.")
1563 (defvar message-options nil
1564 "Some saved answers when sending message.")
1566 (defvar message-send-mail-real-function nil
1567 "Internal send mail function.")
1569 (defvar message-bogus-system-names "^localhost\\."
1570 "The regexp of bogus system names.")
1573 (autoload 'message-setup-toolbar "messagexmas")
1574 (autoload 'mh-new-draft-name "mh-comp")
1575 (autoload 'mh-send-letter "mh-comp")
1576 (autoload 'gnus-point-at-eol "gnus-util")
1577 (autoload 'gnus-point-at-bol "gnus-util")
1578 (autoload 'gnus-output-to-rmail "gnus-util")
1579 (autoload 'gnus-output-to-mail "gnus-util")
1580 (autoload 'nndraft-request-associate-buffer "nndraft")
1581 (autoload 'nndraft-request-expire-articles "nndraft")
1582 (autoload 'gnus-open-server "gnus-int")
1583 (autoload 'gnus-request-post "gnus-int")
1584 (autoload 'gnus-copy-article-buffer "gnus-msg")
1585 (autoload 'gnus-alive-p "gnus-util")
1586 (autoload 'gnus-server-string "gnus")
1587 (autoload 'gnus-group-name-charset "gnus-group")
1588 (autoload 'gnus-group-name-decode "gnus-group")
1589 (autoload 'gnus-groups-from-server "gnus")
1590 (autoload 'rmail-output "rmailout")
1591 (autoload 'gnus-delay-article "gnus-delay")
1592 (autoload 'mu-cite-original "mu-cite"))
1597 ;;; Utility functions.
1599 (defun message-eval-parameter (parameter)
1601 (if (symbolp parameter)
1602 (if (functionp parameter)
1608 (defsubst message-get-parameter (key &optional alist)
1610 (setq alist message-parameter-alist))
1611 (cdr (assq key alist)))
1613 (defmacro message-get-parameter-with-eval (key &optional alist)
1614 `(message-eval-parameter (message-get-parameter ,key ,alist)))
1616 (defmacro message-y-or-n-p (question show &rest text)
1617 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1618 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1620 (defmacro message-delete-line (&optional n)
1621 "Delete the current line (and the next N lines)."
1622 `(delete-region (progn (beginning-of-line) (point))
1623 (progn (forward-line ,(or n 1)) (point))))
1625 (defun message-unquote-tokens (elems)
1626 "Remove double quotes (\") from strings in list ELEMS."
1627 (mapcar (lambda (item)
1628 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1629 (setq item (concat (match-string 1 item)
1630 (match-string 2 item))))
1634 (defun message-tokenize-header (header &optional separator)
1635 "Split HEADER into a list of header elements.
1636 SEPARATOR is a string of characters to be used as separators. \",\"
1637 is used by default."
1640 (let ((regexp (format "[%s]+" (or separator ",")))
1645 (message-set-work-buffer)
1647 (goto-char (point-min))
1652 (cond ((and (> (point) beg)
1654 (and (looking-at regexp)
1657 (push (buffer-substring beg (point)) elems)
1658 (setq beg (match-end 0)))
1659 ((eq (char-after) ?\")
1660 (setq quoted (not quoted)))
1661 ((and (eq (char-after) ?\()
1664 ((and (eq (char-after) ?\))
1667 (nreverse elems)))))
1669 (defun message-mail-file-mbox-p (file)
1670 "Say whether FILE looks like a Unix mbox file."
1671 (when (and (file-exists-p file)
1672 (file-readable-p file)
1673 (file-regular-p file))
1675 (nnheader-insert-file-contents file)
1676 (goto-char (point-min))
1677 (looking-at message-unix-mail-delimiter))))
1679 (defun message-fetch-field (header &optional not-all)
1680 "The same as `mail-fetch-field', only remove all newlines."
1681 (let* ((inhibit-point-motion-hooks t)
1682 (case-fold-search t)
1683 (value (mail-fetch-field header nil (not not-all))))
1685 (while (string-match "\n[\t ]+" value)
1686 (setq value (replace-match " " t t value)))
1687 (set-text-properties 0 (length value) nil value)
1690 (defun message-narrow-to-field ()
1691 "Narrow the buffer to the header on the current line."
1697 (if (re-search-forward "^[^ \n\t]" nil t)
1702 (goto-char (point-min)))
1704 (defun message-add-header (&rest headers)
1705 "Add the HEADERS to the message header, skipping those already present."
1708 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1709 (error "Invalid header `%s'" (car headers)))
1710 (setq hclean (match-string 1 (car headers)))
1712 (message-narrow-to-headers)
1713 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1714 (goto-char (point-max))
1715 (if (string-match "\n$" (car headers))
1716 (insert (car headers))
1717 (insert (car headers) ?\n)))))
1718 (setq headers (cdr headers))))
1720 (defmacro message-with-reply-buffer (&rest forms)
1721 "Evaluate FORMS in the reply buffer, if it exists."
1722 `(let ((buffer (message-eval-parameter message-reply-buffer)))
1724 (buffer-name buffer))
1729 (put 'message-with-reply-buffer 'lisp-indent-function 0)
1730 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
1732 (defun message-fetch-reply-field (header)
1733 "Fetch field HEADER from the message we're replying to."
1734 (message-with-reply-buffer
1735 (message-fetch-field header)))
1737 (defun message-set-work-buffer ()
1738 (if (get-buffer " *message work*")
1740 (set-buffer " *message work*")
1742 (set-buffer (get-buffer-create " *message work*"))
1743 (kill-all-local-variables)))
1745 (defun message-functionp (form)
1746 "Return non-nil if FORM is funcallable."
1747 (or (and (symbolp form) (fboundp form))
1748 (and (listp form) (eq (car form) 'lambda))
1749 (byte-code-function-p form)))
1751 (defun message-strip-list-identifiers (subject)
1752 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1753 (require 'gnus-sum) ; for gnus-list-identifiers
1754 (let ((regexp (if (stringp gnus-list-identifiers)
1755 gnus-list-identifiers
1756 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1757 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1758 " *\\)\\)+\\(Re: +\\)?\\)") subject)
1759 (concat (substring subject 0 (match-beginning 1))
1760 (or (match-string 3 subject)
1761 (match-string 5 subject))
1766 (defun message-strip-subject-re (subject)
1767 "Remove \"Re:\" from subject lines in string SUBJECT."
1768 (if (string-match message-subject-re-regexp subject)
1769 (substring subject (match-end 0))
1772 ;;; Start of functions adopted from `message-utils.el'.
1774 (defun message-strip-subject-trailing-was (subject)
1775 "Remove trailing \"(Was: <old subject>)\" from subject lines.
1776 Leading \"Re: \" is not stripped by this function. Use the function
1777 `message-strip-subject-re' for this."
1778 (let* ((query message-subject-trailing-was-query)
1783 message-subject-trailing-was-ask-regexp
1784 message-subject-trailing-was-regexp)
1787 (setq new (substring subject 0 (match-beginning 0))))
1788 (if (or (not found) (eq query nil))
1791 (if (message-y-or-n-p
1792 "Strip `(was: <old subject>)' in subject? " t
1794 "Strip `(was: <old subject>)' in subject "
1795 "and use the new one instead?\n\n"
1796 "Current subject is: \""
1798 "New subject would be: \""
1800 "See the variable `message-subject-trailing-was-query' "
1801 "to get rid of this query."
1806 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
1809 (defun message-change-subject (new-subject)
1810 "Ask for new Subject: header, append (was: <Old Subject>)."
1813 (read-from-minibuffer "New subject: ")))
1814 (cond ((and (not (or (null new-subject) ; new subject not empty
1815 (zerop (string-width new-subject))
1816 (string-match "^[ \t]*$" new-subject))))
1818 (let ((old-subject (message-fetch-field "Subject")))
1819 (cond ((not old-subject)
1820 (error "No current subject."))
1823 (regexp-quote new-subject)
1825 old-subject)) ; yes, it really is a new subject
1826 ;; delete eventual Re: prefix
1828 (message-strip-subject-re old-subject))
1829 (message-goto-subject)
1830 (message-delete-line)
1831 (insert (concat "Subject: "
1834 old-subject ")\n")))))))))
1837 (defun message-mark-inserted-region (beg end)
1838 "Mark some region in the current article with enclosing tags.
1839 See `message-mark-insert-begin' and `message-mark-insert-end'."
1842 ; add to the end of the region first, otherwise end would be invalid
1844 (insert message-mark-insert-end)
1846 (insert message-mark-insert-begin)))
1849 (defun message-mark-insert-file (file)
1850 "Inserts FILE at point, marking it with enclosing tags.
1851 See `message-mark-insert-begin' and `message-mark-insert-end'."
1852 (interactive "fFile to insert: ")
1853 ;; reverse insertion to get correct result.
1855 (insert message-mark-insert-end)
1857 (insert-file-contents file)
1859 (insert message-mark-insert-begin)))
1862 (defun message-add-archive-header ()
1863 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
1864 The note can be customized using `message-archive-note'. When called with a
1865 prefix argument, ask for a text to insert. If you don't want the note in the
1866 body, set `message-archive-note' to nil."
1868 (if current-prefix-arg
1869 (setq message-archive-note
1870 (read-from-minibuffer "Reason for No-Archive: "
1871 (cons message-archive-note 0))))
1873 (if (message-goto-signature)
1874 (re-search-backward message-signature-separator))
1875 (when message-archive-note
1876 (insert message-archive-note)
1878 (message-add-header message-archive-header)
1879 (message-sort-headers)))
1882 (defun message-xpost-fup2-header (target-group)
1883 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
1884 With prefix-argument just set Follow-Up, don't cross-post."
1886 (list ; Completion based on Gnus
1887 (completing-read "Followup To: "
1888 (if (boundp 'gnus-newsrc-alist)
1890 nil nil '("poster" . 0)
1891 (if (boundp 'gnus-group-history)
1892 'gnus-group-history))))
1893 (message-remove-header "Follow[Uu]p-[Tt]o" t)
1894 (message-goto-newsgroups)
1896 ;; if we already did a crosspost before, kill old target
1897 (if (and message-xpost-old-target
1899 (regexp-quote (concat "," message-xpost-old-target))
1902 ;; unless (followup is to poster or user explicitly asked not
1903 ;; to cross-post, or target-group is already in Newsgroups)
1904 ;; add target-group to Newsgroups line.
1906 ;; def: xpost, req:no
1907 (and message-xpost-default (not current-prefix-arg))
1908 ;; def: no-xpost, req:yes
1909 (and (not message-xpost-default) current-prefix-arg))
1910 (not (string-match "poster" target-group))
1911 (not (string-match (regexp-quote target-group)
1912 (message-fetch-field "Newsgroups"))))
1914 (insert-string (concat "," target-group))))
1915 (end-of-line) ; ensure Followup: comes after Newsgroups:
1916 ;; unless new followup would be identical to Newsgroups line
1917 ;; make a new Followup-To line
1918 (if (not (string-match (concat "^[ \t]*"
1921 (message-fetch-field "Newsgroups")))
1922 (insert (concat "\nFollowup-To: " target-group)))
1923 (setq message-xpost-old-target target-group))
1926 (defun message-xpost-insert-note (target-group xpost in-old old-groups)
1927 "Insert a in message body note about a set Followup or Crosspost.
1928 If there have been previous notes, delete them. TARGET-GROUP specifies the
1929 group to Followup-To. When XPOST is t, insert note about
1930 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
1931 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
1932 been made to before the user asked for a Crosspost."
1933 ;; start scanning body for previous uses
1934 (message-goto-signature)
1935 (let ((head (re-search-backward
1936 (concat "^" mail-header-separator)
1937 nil t))) ; just search in body
1938 (message-goto-signature)
1939 (while (re-search-backward
1940 (concat "^" (regexp-quote message-xpost-note) ".*")
1942 (message-delete-line))
1943 (message-goto-signature)
1944 (while (re-search-backward
1945 (concat "^" (regexp-quote message-fup2-note) ".*")
1947 (message-delete-line))
1949 (if (message-goto-signature)
1950 (re-search-backward message-signature-separator))
1953 (string-match "^[ \t]*poster[ \t]*$" target-group))
1954 (insert (concat message-fup2-note target-group "\n"))
1955 (insert (concat message-xpost-note target-group "\n")))))
1958 (defun message-xpost-fup2 (target-group)
1959 "Crossposts message and sets Followup-To to TARGET-GROUP.
1960 With prefix-argument just set Follow-Up, don't cross-post."
1962 (list ; Completion based on Gnus
1963 (completing-read "Followup To: "
1964 (if (boundp 'gnus-newsrc-alist)
1966 nil nil '("poster" . 0)
1967 (if (boundp 'gnus-group-history)
1968 'gnus-group-history))))
1969 (cond ((not (or (null target-group) ; new subject not empty
1970 (zerop (string-width target-group))
1971 (string-match "^[ \t]*$" target-group)))
1973 (let* ((old-groups (message-fetch-field "Newsgroups"))
1974 (in-old (string-match
1975 (regexp-quote target-group)
1976 (or old-groups ""))))
1977 ;; check whether target exactly matches old Newsgroups
1978 (cond ((not old-groups)
1979 (error "No current newsgroup."))
1983 (regexp-quote target-group)
1986 ;; yes, Newsgroups line must change
1987 (message-xpost-fup2-header target-group)
1988 ;; insert note whether we do xpost or fup2
1989 (funcall message-xpost-note-function
1991 (if (or (and message-xpost-default
1992 (not current-prefix-arg))
1993 (and (not message-xpost-default)
1994 current-prefix-arg)) t)
1995 in-old old-groups))))))))
1997 ;;; Reduce To: to Cc: or Bcc: header
2000 (defun message-reduce-to-to-cc ()
2001 "Replace contents of To: header with contents of Cc: or Bcc: header."
2003 (let ((cc-content (message-fetch-field "cc"))
2005 (if (and (not cc-content)
2006 (setq cc-content (message-fetch-field "bcc")))
2011 (message-delete-line)
2012 (insert (concat "To: " cc-content "\n"))
2013 (message-remove-header (if bcc
2017 ;;; End of functions adopted from `message-utils.el'.
2019 (defun message-remove-header (header &optional is-regexp first reverse)
2020 "Remove HEADER in the narrowed buffer.
2021 If IS-REGEXP, HEADER is a regular expression.
2022 If FIRST, only remove the first instance of the header.
2023 Return the number of headers removed."
2024 (goto-char (point-min))
2025 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
2027 (case-fold-search t)
2029 (while (and (not (eobp))
2032 (not (looking-at regexp))
2033 (looking-at regexp))
2040 ;; There might be a continuation header, so we have to search
2041 ;; until we find a new non-continuation line.
2044 (if (re-search-forward "^[^ \t]" nil t)
2045 (goto-char (match-beginning 0))
2048 (if (re-search-forward "^[^ \t]" nil t)
2049 (goto-char (match-beginning 0))
2050 (goto-char (point-max)))))
2053 (defun message-remove-first-header (header)
2054 "Remove the first instance of HEADER if there is more than one."
2056 (regexp (concat "^" (regexp-quote header) ":")))
2058 (goto-char (point-min))
2059 (while (re-search-forward regexp nil t)
2062 (message-remove-header header nil t)
2065 (defun message-narrow-to-headers ()
2066 "Narrow the buffer to the head of the message."
2069 (goto-char (point-min))
2070 (if (re-search-forward
2071 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2074 (goto-char (point-min)))
2076 (defun message-narrow-to-head-1 ()
2077 "Like `message-narrow-to-head'. Don't widen."
2079 (goto-char (point-min))
2080 (if (search-forward "\n\n" nil 1)
2083 (goto-char (point-min)))
2085 (defun message-narrow-to-head ()
2086 "Narrow the buffer to the head of the message.
2087 Point is left at the beginning of the narrowed-to region."
2089 (message-narrow-to-head-1))
2091 (defun message-narrow-to-headers-or-head ()
2092 "Narrow the buffer to the head of the message."
2095 (goto-char (point-min))
2098 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2099 (match-beginning 0))
2100 ((search-forward "\n\n" nil t)
2104 (goto-char (point-min)))
2106 (defun message-news-p ()
2107 "Say whether the current buffer contains a news message."
2108 (and (not message-this-is-mail)
2109 (or message-this-is-news
2112 (message-narrow-to-headers)
2113 (and (message-fetch-field "newsgroups")
2114 (not (message-fetch-field "posted-to"))))))))
2116 (defun message-mail-p ()
2117 "Say whether the current buffer contains a mail message."
2118 (and (not message-this-is-news)
2119 (or message-this-is-mail
2122 (message-narrow-to-headers)
2123 (or (message-fetch-field "to")
2124 (message-fetch-field "cc")
2125 (message-fetch-field "bcc")))))))
2127 (defun message-next-header ()
2128 "Go to the beginning of the next header."
2130 (or (eobp) (forward-char 1))
2131 (not (if (re-search-forward "^[^ \t]" nil t)
2133 (goto-char (point-max)))))
2135 (defun message-sort-headers-1 ()
2136 "Sort the buffer as headers using `message-rank' text props."
2137 (goto-char (point-min))
2140 nil 'message-next-header
2142 (message-next-header)
2146 (or (get-text-property (point) 'message-rank)
2149 (defun message-sort-headers ()
2150 "Sort the headers of the current message according to `message-header-format-alist'."
2154 (let ((max (1+ (length message-header-format-alist)))
2156 (message-narrow-to-headers)
2157 (while (re-search-forward "^[^ \n]+:" nil t)
2159 (match-beginning 0) (1+ (match-beginning 0))
2161 (if (setq rank (length (memq (assq (intern (buffer-substring
2163 (1- (match-end 0))))
2164 message-header-format-alist)
2165 message-header-format-alist)))
2168 (message-sort-headers-1))))
2178 (defvar message-mode-map nil)
2180 (unless message-mode-map
2181 (setq message-mode-map (make-keymap))
2182 (set-keymap-parent message-mode-map text-mode-map)
2183 (define-key message-mode-map "\C-c?" 'describe-mode)
2185 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
2186 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
2187 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
2188 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
2189 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
2190 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2191 ;; (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2192 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-mail-reply-to)
2193 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2194 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2195 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2196 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2197 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2198 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2199 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2200 (define-key message-mode-map "\C-c\C-f\C-i" 'message-insert-or-toggle-importance)
2201 (define-key message-mode-map "\C-c\C-f\C-a" 'message-gen-unsubscribed-mft)
2203 ;; modify headers (and insert notes in body)
2204 (define-key message-mode-map "\C-c\C-fs" 'message-change-subject)
2206 (define-key message-mode-map "\C-c\C-fx" 'message-xpost-fup2)
2207 ;; prefix+message-xpost-fup2 = same w/o xpost
2208 (define-key message-mode-map "\C-c\C-ft" 'message-reduce-to-to-cc)
2209 (define-key message-mode-map "\C-c\C-fa" 'message-add-archive-header)
2210 ;; mark inserted text
2211 (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2212 (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2214 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2215 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2216 (define-key message-mode-map "\C-c\C-fc" 'message-goto-mail-copies-to)
2218 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2219 (define-key message-mode-map "\C-c\C-p" 'message-insert-wide-reply)
2220 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2221 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2223 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2224 (define-key message-mode-map "\C-c\M-n" 'message-insert-disposition-notification-to)
2226 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2227 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2228 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2229 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2230 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2231 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2232 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2233 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2235 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2236 (define-key message-mode-map "\C-c\C-s" 'message-send)
2237 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2238 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2239 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2241 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2242 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2243 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2244 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2245 ;;(define-key message-mode-map "\M-q" 'message-fill-paragraph)
2247 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2248 (define-key message-mode-map "\t" 'message-tab)
2249 (define-key message-mode-map "\M-;" 'comment-region)
2251 (define-key message-mode-map "\C-xk" 'message-mimic-kill-buffer))
2254 message-mode-menu message-mode-map "Message Menu."
2256 ["Sort Headers" message-sort-headers t]
2257 ["Yank Original" message-yank-original t]
2258 ["Fill Yanked Message" message-fill-yanked-message t]
2259 ["Insert Signature" message-insert-signature t]
2260 ["Caesar (rot13) Message" message-caesar-buffer-body t]
2261 ["Caesar (rot13) Region" message-caesar-region (mark t)]
2262 ["Elide Region" message-elide-region (mark t)]
2263 ["Delete Outside Region" message-delete-not-region (mark t)]
2264 ["Kill To Signature" message-kill-to-signature t]
2265 ["Newline and Reformat" message-newline-and-reformat t]
2266 ["Rename buffer" message-rename-buffer t]
2267 ["Flag As Important" message-insert-importance-high
2268 ,@(if (featurep 'xemacs) '(t)
2269 '(:help "Mark this message as important"))]
2270 ["Flag As Unimportant" message-insert-importance-low
2271 ,@(if (featurep 'xemacs) '(t)
2272 '(:help "Mark this message as unimportant"))]
2274 message-insert-disposition-notification-to
2275 ,@(if (featurep 'xemacs) '(t)
2276 '(:help "Request a Disposition Notification of this article"))]
2277 ["Spellcheck" ispell-message
2278 ,@(if (featurep 'xemacs) '(t)
2279 '(:help "Spellcheck this message"))]
2280 ["Attach file as MIME" mime-edit-insert-file
2281 ,@(if (featurep 'xemacs) '(t)
2282 '(:help "Attach a file at point"))]
2284 ["Insert Region Marked" message-mark-inserted-region
2285 ,@(if (featurep 'xemacs) '(t)
2286 '(:help "Mark region with enclosing tags"))]
2287 ["Insert File Marked..." message-mark-insert-file
2288 ,@(if (featurep 'xemacs) '(t)
2289 '(:help "Insert file at point marked with enclosing tags"))]
2291 ["Send Message" message-send-and-exit
2292 ,@(if (featurep 'xemacs) '(t)
2293 '(:help "Send this message"))]
2294 ["Postpone Message" message-dont-send
2295 ,@(if (featurep 'xemacs) '(t)
2296 '(:help "File this draft message and exit"))]
2297 ["Send at Specific Time..." gnus-delay-article
2298 ,@(if (featurep 'xemacs) '(t)
2299 '(:help "Ask, then arrange to send message at that time"))]
2300 ["Kill Message" message-kill-buffer
2301 ,@(if (featurep 'xemacs) '(t)
2302 '(:help "Delete this message without sending"))]))
2305 message-mode-field-menu message-mode-map ""
2307 ["Fetch To" message-insert-to t]
2308 ["Fetch Newsgroups" message-insert-newsgroups t]
2310 ["To" message-goto-to t]
2311 ["From" message-goto-from t]
2312 ["Subject" message-goto-subject t]
2313 ["Change subject..." message-change-subject t]
2314 ["Cc" message-goto-cc t]
2315 ["Bcc" message-goto-bcc t]
2316 ["Fcc" message-goto-fcc t]
2317 ["Reply-To" message-goto-reply-to t]
2319 ;; (typical) news stuff
2320 ["Summary" message-goto-summary t]
2321 ["Keywords" message-goto-keywords t]
2322 ["Newsgroups" message-goto-newsgroups t]
2323 ["Followup-To" message-goto-followup-to t]
2324 ;; ["Followup-To (with note in body)" message-xpost-fup2 t]
2325 ["Crosspost / Followup-To..." message-xpost-fup2 t]
2326 ["Distribution" message-goto-distribution t]
2327 ["X-No-Archive:" message-add-archive-header t ]
2329 ;; (typical) mailing-lists stuff
2330 ["Send to list only" message-to-list-only t]
2331 ["Mail-Followup-To" message-goto-mail-followup-to t]
2332 ["Mail-Reply-To" message-goto-mail-reply-to t]
2333 ["Mail-Copies-To" message-goto-mail-copies-to t]
2334 ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2336 ["Body" message-goto-body t]
2337 ["Signature" message-goto-signature t]))
2339 (defvar message-tool-bar-map nil)
2342 (defvar facemenu-add-face-function)
2343 (defvar facemenu-remove-face-function))
2345 ;;; Forbidden properties
2347 ;; We use `after-change-functions' to keep special text properties
2348 ;; that interfer with the normal function of message mode out of the
2351 (defcustom message-strip-special-text-properties t
2352 "Strip special properties from the message buffer.
2354 Emacs has a number of special text properties which can break message
2355 composing in various ways. If this option is set, message will strip
2356 these properties from the message composition buffer. However, some
2357 packages requires these properties to be present in order to work.
2358 If you use one of these packages, turn this option off, and hope the
2359 message composition doesn't break too bad."
2360 :group 'message-various
2363 (defconst message-forbidden-properties
2364 ;; No reason this should be clutter up customize. We make it a
2365 ;; property list (rather than a list of property symbols), to be
2366 ;; directly useful for `remove-text-properties'.
2367 '(field nil read-only nil intangible nil invisible nil
2368 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2369 insert-behind-hooks nil point-entered nil point-left nil)
2370 ;; Other special properties:
2371 ;; category, face, display: probably doesn't do any harm.
2372 ;; fontified: is used by font-lock.
2373 ;; syntax-table, local-map: I dunno.
2374 ;; We need to add XEmacs names to the list.
2375 "Property list of with properties.forbidden in message buffers.
2376 The values of the properties are ignored, only the property names are used.")
2378 (defun message-tamago-not-in-use-p (pos)
2379 "Return t when tamago version 4 is not in use at the cursor position.
2380 Tamago version 4 is a popular input method for writing Japanese text.
2381 It uses the properties `intangible', `invisible', `modification-hooks'
2382 and `read-only' when translating ascii or kana text to kanji text.
2383 These properties are essential to work, so we should never strip them."
2384 (not (and (boundp 'egg-modefull-mode)
2385 (symbol-value 'egg-modefull-mode)
2386 (or (memq (get-text-property pos 'intangible)
2387 '(its-part-1 its-part-2))
2388 (get-text-property pos 'egg-end)
2389 (get-text-property pos 'egg-lang)
2390 (get-text-property pos 'egg-start)))))
2392 (defun message-strip-forbidden-properties (begin end &optional old-length)
2393 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2394 This function is intended to be called from `after-change-functions'.
2395 See also `message-forbidden-properties'."
2396 (when (and message-strip-special-text-properties
2397 (message-tamago-not-in-use-p begin)
2398 ;; Check whether the invisible MIME part is not inserted.
2399 (not (text-property-any begin end 'mime-edit-invisible t)))
2400 (remove-text-properties begin end message-forbidden-properties)))
2403 (define-derived-mode message-mode text-mode "Message"
2404 "Major mode for editing mail and news to be sent.
2405 Like Text Mode but with these additional commands:\\<message-mode-map>
2406 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2407 C-c C-d Postpone sending the message C-c C-k Kill the message
2408 C-c C-f move to a header field (and create it if there isn't):
2409 C-c C-f C-t move to To C-c C-f C-s move to Subject
2410 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2411 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2412 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2413 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2414 C-c C-f C-o move to From (\"Originator\")
2415 C-c C-f C-f move to Followup-To
2416 C-c C-f C-m move to Mail-Followup-To
2417 C-c C-f c move to Mail-Copies-To
2418 C-c C-f C-i cycle through Importance values
2419 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2420 C-c C-f x crossposting with FollowUp-To header and note in body
2421 C-c C-f t replace To: header with contents of Cc: or Bcc:
2422 C-c C-f a Insert X-No-Archive: header and a note in the body
2423 C-c C-t `message-insert-to' (add a To header to a news followup)
2424 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2425 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2426 C-c C-b `message-goto-body' (move to beginning of message text).
2427 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2428 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2429 C-c C-y `message-yank-original' (insert current message, if any).
2430 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2431 C-c C-e `message-elide-region' (elide the text between point and mark).
2432 C-c C-v `message-delete-not-region' (remove the text outside the region).
2433 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2434 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2435 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2436 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2437 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2438 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2439 M-RET `message-newline-and-reformat' (break the line and reformat)."
2440 (setq local-abbrev-table text-mode-abbrev-table)
2441 (set (make-local-variable 'message-reply-buffer) nil)
2442 (make-local-variable 'message-send-actions)
2443 (make-local-variable 'message-exit-actions)
2444 (make-local-variable 'message-kill-actions)
2445 (make-local-variable 'message-postpone-actions)
2446 (make-local-variable 'message-draft-article)
2447 (setq buffer-offer-save t)
2448 (set (make-local-variable 'facemenu-add-face-function)
2450 (let ((face-fun (cdr (assq face message-face-alist))))
2452 (funcall face-fun (point) end)
2453 (error "Face %s not configured for %s mode" face mode-name)))
2455 (set (make-local-variable 'facemenu-remove-face-function) t)
2456 (set (make-local-variable 'message-reply-headers) nil)
2457 (make-local-variable 'message-user-agent)
2458 (make-local-variable 'message-post-method)
2459 (set (make-local-variable 'message-sent-message-via) nil)
2460 (set (make-local-variable 'message-checksum) nil)
2461 (make-local-variable 'message-parameter-alist)
2462 (setq message-parameter-alist
2463 (copy-sequence message-startup-parameter-alist))
2464 (message-setup-fill-variables)
2465 ;; Allow using comment commands to add/remove quoting.
2466 (set (make-local-variable 'comment-start) message-yank-prefix)
2467 (if (featurep 'xemacs)
2468 (message-setup-toolbar)
2469 (set (make-local-variable 'font-lock-defaults)
2470 '(message-font-lock-keywords t))
2471 (if (boundp 'tool-bar-map)
2472 (set (make-local-variable 'tool-bar-map) (message-tool-bar-map))))
2473 (easy-menu-add message-mode-menu message-mode-map)
2474 (easy-menu-add message-mode-field-menu message-mode-map)
2475 ;; make-local-hook is harmless though obsolete in Emacs 21.
2476 ;; Emacs 20 and XEmacs need make-local-hook.
2477 (make-local-hook 'after-change-functions)
2478 ;; Mmmm... Forbidden properties...
2479 (add-hook 'after-change-functions 'message-strip-forbidden-properties
2481 ;; Allow mail alias things.
2482 (when (eq message-mail-alias-type 'abbrev)
2483 (if (fboundp 'mail-abbrevs-setup)
2484 (mail-abbrevs-setup)
2485 (mail-aliases-setup)))
2486 (unless buffer-file-name
2487 (message-set-auto-save-file-name))
2488 (set (make-local-variable 'indent-tabs-mode) nil)) ;No tabs for indentation.
2490 (defun message-setup-fill-variables ()
2491 "Setup message fill variables."
2492 (set (make-local-variable 'fill-paragraph-function)
2493 'message-fill-paragraph)
2494 (make-local-variable 'paragraph-separate)
2495 (make-local-variable 'paragraph-start)
2496 (make-local-variable 'adaptive-fill-regexp)
2497 (unless (boundp 'adaptive-fill-first-line-regexp)
2498 (setq adaptive-fill-first-line-regexp nil))
2499 (make-local-variable 'adaptive-fill-first-line-regexp)
2500 (let ((quote-prefix-regexp
2501 ;; User should change message-cite-prefix-regexp if
2502 ;; message-yank-prefix is set to an abnormal value.
2503 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
2504 (setq paragraph-start
2506 (regexp-quote mail-header-separator) "$\\|"
2507 "[ \t]*$\\|" ; blank lines
2508 "-- $\\|" ; signature delimiter
2509 "---+$\\|" ; delimiters for forwarded messages
2510 page-delimiter "$\\|" ; spoiler warnings
2511 ".*wrote:$\\|" ; attribution lines
2512 quote-prefix-regexp "$")) ; empty lines in quoted text
2513 (setq paragraph-separate paragraph-start)
2514 (setq adaptive-fill-regexp
2515 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
2516 (setq adaptive-fill-first-line-regexp
2517 (concat quote-prefix-regexp "\\|"
2518 adaptive-fill-first-line-regexp)))
2519 (make-local-variable 'auto-fill-inhibit-regexp)
2520 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2521 (setq auto-fill-inhibit-regexp nil)
2522 (make-local-variable 'normal-auto-fill-function)
2523 (setq normal-auto-fill-function 'message-do-auto-fill)
2524 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2525 ;; In that case, ensure that it uses the right function. The real
2526 ;; solution would be not to use `define-derived-mode', and run
2527 ;; `text-mode-hook' ourself at the end of the mode.
2528 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2529 (when auto-fill-function
2530 (setq auto-fill-function normal-auto-fill-function)))
2535 ;;; Message mode commands
2538 ;;; Movement commands
2540 (defun message-goto-to ()
2541 "Move point to the To header."
2543 (message-position-on-field "To"))
2545 (defun message-goto-from ()
2546 "Move point to the From header."
2548 (message-position-on-field "From"))
2550 (defun message-goto-subject ()
2551 "Move point to the Subject header."
2553 (message-position-on-field "Subject"))
2555 (defun message-goto-cc ()
2556 "Move point to the Cc header."
2558 (message-position-on-field "Cc" "To"))
2560 (defun message-goto-bcc ()
2561 "Move point to the Bcc header."
2563 (message-position-on-field "Bcc" "Cc" "To"))
2565 (defun message-goto-fcc ()
2566 "Move point to the Fcc header."
2568 (message-position-on-field "Fcc" "To" "Newsgroups"))
2570 (defun message-goto-reply-to ()
2571 "Move point to the Reply-To header."
2573 (message-position-on-field "Reply-To" "Subject"))
2575 (defun message-goto-mail-reply-to ()
2576 "Move point to the Mail-Reply-To header."
2578 (message-position-on-field "Mail-Reply-To" "Subject"))
2580 (defun message-goto-mail-copies-to ()
2581 "Move point to the Mail-Copies-To header. If the header is newly created,
2582 a string \"never\" is inserted in default."
2584 (unless (message-position-on-field "Mail-Copies-To" "Subject")
2588 (defun message-goto-newsgroups ()
2589 "Move point to the Newsgroups header."
2591 (message-position-on-field "Newsgroups"))
2593 (defun message-goto-distribution ()
2594 "Move point to the Distribution header."
2596 (message-position-on-field "Distribution"))
2598 (defun message-goto-followup-to ()
2599 "Move point to the Followup-To header."
2601 (message-position-on-field "Followup-To" "Newsgroups"))
2603 (defun message-goto-mail-followup-to ()
2604 "Move point to the Mail-Followup-To header. If the header is newly created
2605 and To field contains only one address, the address is inserted in default."
2607 (unless (message-position-on-field "Mail-Followup-To" "Subject")
2608 (let ((start (point))
2611 (message-narrow-to-headers)
2612 (setq addresses (split-string (mail-strip-quoted-names
2613 (or (std11-fetch-field "to") ""))
2615 (when (eq 1 (length addresses))
2617 (insert (car addresses))
2618 (goto-char start))))))
2620 (defun message-goto-keywords ()
2621 "Move point to the Keywords header."
2623 (message-position-on-field "Keywords" "Subject"))
2625 (defun message-goto-summary ()
2626 "Move point to the Summary header."
2628 (message-position-on-field "Summary" "Subject"))
2630 (defun message-goto-body (&optional interactivep)
2631 "Move point to the beginning of the message body."
2632 (interactive (list t))
2633 (when (and interactivep
2634 (looking-at "[ \t]*\n"))
2636 (goto-char (point-min))
2637 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
2638 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
2640 (defun message-goto-eoh ()
2641 "Move point to the end of the headers."
2646 (defun message-goto-signature ()
2647 "Move point to the beginning of the message signature.
2648 If there is no signature in the article, go to the end and
2651 (goto-char (point-min))
2652 (if (re-search-forward message-signature-separator nil t)
2654 (goto-char (point-max))
2657 (defun message-gen-unsubscribed-mft (&optional include-cc)
2658 "Insert a reasonable MFT header in a post to an unsubscribed list.
2659 When making original posts to a mailing list you are not subscribed to,
2660 you have to type in a MFT header by hand. The contents, usually, are
2661 the addresses of the list and your own address. This function inserts
2662 such a header automatically. It fetches the contents of the To: header
2663 in the current mail buffer, and appends the current user-mail-address.
2665 If the optional argument `include-cc' is non-nil, the addresses in the
2666 Cc: header are also put into the MFT."
2669 (message-remove-header "Mail-Followup-To")
2670 (let* ((cc (and include-cc (message-fetch-field "Cc")))
2672 (concat (message-fetch-field "To") "," cc)
2673 (message-fetch-field "To"))))
2674 (message-goto-mail-followup-to)
2675 (insert (concat tos ", " user-mail-address))))
2679 (defun message-insert-to (&optional force)
2680 "Insert a To header that points to the author of the article being replied to.
2681 If the original author requested not to be sent mail, the function signals
2683 With the prefix argument FORCE, insert the header anyway."
2685 (let ((co (message-fetch-reply-field "mail-copies-to")))
2686 (when (and (null force)
2688 (or (equal (downcase co) "never")
2689 (equal (downcase co) "nobody")))
2690 (error "The user has requested not to have copies sent via mail")))
2691 (message-carefully-insert-headers
2693 (or (message-fetch-reply-field "mail-reply-to")
2694 (message-fetch-reply-field "reply-to")
2695 (message-fetch-reply-field "from")
2698 (defun message-insert-wide-reply ()
2699 "Insert To and Cc headers as if you were doing a wide reply."
2701 (let ((headers (message-with-reply-buffer
2702 (message-get-reply-headers t))))
2703 (message-carefully-insert-headers headers)))
2705 (defun message-carefully-insert-headers (headers)
2706 (dolist (header headers)
2707 (let ((header-name (symbol-name (car header))))
2708 (when (and (message-position-on-field header-name)
2709 (mail-fetch-field header-name)
2710 (not (string-match "\\` *\\'"
2711 (mail-fetch-field header-name))))
2713 (insert (cdr header)))))
2715 (defun message-widen-reply ()
2716 "Widen the reply to include maximum recipients."
2719 (and message-reply-buffer
2720 (buffer-name message-reply-buffer)
2722 (set-buffer message-reply-buffer)
2723 (message-get-reply-headers t)))))
2726 (message-narrow-to-headers)
2727 (dolist (elem follow-to)
2728 (message-remove-header (symbol-name (car elem)))
2729 (goto-char (point-min))
2730 (insert (symbol-name (car elem)) ": "
2731 (cdr elem) "\n"))))))
2733 (defun message-insert-newsgroups ()
2734 "Insert the Newsgroups header from the article being replied to."
2736 (when (and (message-position-on-field "Newsgroups")
2737 (mail-fetch-field "newsgroups")
2738 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
2740 (insert (or (message-fetch-reply-field "newsgroups") "")))
2744 ;;; Various commands
2746 (defun message-delete-not-region (beg end)
2747 "Delete everything in the body of the current message outside of the region."
2752 ;; snarf citation prefix, if appropriate
2753 (unless (eq (point) (progn (beginning-of-line) (point)))
2754 (when (looking-at message-cite-prefix-regexp)
2755 (setq citeprefix (match-string 0))))
2757 (delete-region (point) (if (not (message-goto-signature))
2763 (delete-region beg (progn (message-goto-body)
2767 (insert citeprefix))))
2768 (when (message-goto-signature)
2771 (defun message-kill-to-signature ()
2772 "Deletes all text up to the signature."
2774 (let ((point (point)))
2775 (message-goto-signature)
2778 (kill-region point (point))
2782 (defun message-newline-and-reformat (&optional arg not-break)
2783 "Insert four newlines, and then reformat if inside quoted text.
2784 Prefix arg means justify as well."
2785 (interactive (list (if current-prefix-arg 'full)))
2786 (let (quoted point beg end leading-space bolp)
2787 (setq point (point))
2790 (setq bolp (= beg point))
2791 ;; Find first line of the paragraph.
2793 (while (and (not (eobp))
2794 (not (looking-at message-cite-prefix-regexp))
2795 (looking-at paragraph-start))
2798 (when (looking-at message-cite-prefix-regexp)
2799 (setq quoted (match-string 0))
2800 (goto-char (match-end 0))
2801 (looking-at "[ \t]*")
2802 (setq leading-space (match-string 0)))
2806 (< (- point beg) (length quoted)))
2807 ;; break inside the cite prefix.
2813 (while (and (not (eobp))
2814 (not (looking-at paragraph-separate))
2815 (looking-at message-cite-prefix-regexp)
2816 (equal quoted (match-string 0)))
2817 (goto-char (match-end 0))
2818 (looking-at "[ \t]*")
2819 (if (> (length leading-space) (length (match-string 0)))
2820 (setq leading-space (match-string 0)))
2824 (while (and (if (bobp) nil (forward-line -1) t)
2825 (not (looking-at paragraph-start))
2826 (looking-at message-cite-prefix-regexp)
2827 (equal quoted (match-string 0)))
2829 (goto-char (match-end 0))
2830 (looking-at "[ \t]*")
2831 (if (> (length leading-space) (length (match-string 0)))
2832 (setq leading-space (match-string 0)))))
2833 (while (and (not (eobp))
2834 (not (looking-at paragraph-separate))
2835 (not (looking-at message-cite-prefix-regexp)))
2839 (while (and (if (bobp) nil (forward-line -1) t)
2840 (not (looking-at paragraph-start))
2841 (not (looking-at message-cite-prefix-regexp)))
2842 (setq beg (point))))
2845 (narrow-to-region beg end)
2852 (setq point (point))
2853 ;; (newline 2) doesn't mark both newline's as hard, so call
2854 ;; newline twice. -jas
2857 (delete-region (point) (re-search-forward "[ \t]*"))
2858 (when (and quoted (not bolp))
2859 (insert quoted leading-space)))
2861 (let* ((adaptive-fill-regexp
2862 (regexp-quote (concat quoted leading-space)))
2863 (adaptive-fill-first-line-regexp
2864 adaptive-fill-regexp ))
2865 (fill-paragraph arg))
2866 (fill-paragraph arg))
2867 (if point (goto-char point)))))
2869 (defun message-fill-paragraph (&optional arg)
2870 "Like `fill-paragraph'."
2871 (interactive (list (if current-prefix-arg 'full)))
2872 (if (and (boundp 'filladapt-mode) filladapt-mode)
2874 (message-newline-and-reformat arg t)
2877 ;; Is it better to use `mail-header-end'?
2878 (defun message-point-in-header-p ()
2879 "Return t if point is in the header."
2882 (goto-char (point-min))
2883 (not (re-search-forward
2884 (concat "^" (regexp-quote mail-header-separator) "\n")
2887 (defun message-do-auto-fill ()
2888 "Like `do-auto-fill', but don't fill in message header."
2889 (unless (message-point-in-header-p)
2892 (defun message-insert-signature (&optional force)
2893 "Insert a signature. See documentation for variable `message-signature'."
2894 (interactive (list 0))
2897 ((and (null message-signature)
2900 (goto-char (point-max))
2901 (not (re-search-backward message-signature-separator nil t))))
2902 ((and (null message-signature)
2905 ((message-functionp message-signature)
2906 (funcall message-signature))
2907 ((listp message-signature)
2908 (eval message-signature))
2909 (t message-signature)))
2911 (cond ((stringp signature)
2913 ((and (eq t signature)
2914 message-signature-file
2915 (file-exists-p message-signature-file))
2918 (goto-char (point-max))
2919 ;; Insert the signature.
2922 (insert "\n" message-signature-separator-for-insertion)
2925 (if (eq signature t)
2926 (insert-file-contents message-signature-file)
2928 (goto-char (point-max))
2929 (or (bolp) (insert "\n")))))
2931 (defun message-insert-importance-high ()
2932 "Insert header to mark message as important."
2935 (message-remove-header "Importance")
2937 (insert "Importance: high\n")))
2939 (defun message-insert-importance-low ()
2940 "Insert header to mark message as unimportant."
2943 (message-remove-header "Importance")
2945 (insert "Importance: low\n")))
2947 (defun message-insert-or-toggle-importance ()
2948 "Insert a \"Importance: high\" header, or cycle through the header values.
2949 The three allowed values according to RFC 1327 are `high', `normal'
2953 (let ((valid '("high" "normal" "low"))
2956 (when (setq cur (message-fetch-field "Importance"))
2957 (message-remove-header "Importance")
2958 (setq new (cond ((string= cur "high")
2960 ((string= cur "low")
2965 (insert (format "Importance: %s\n" new)))))
2967 (defun message-insert-disposition-notification-to ()
2968 "Request a disposition notification (return receipt) to this message.
2969 Note that this should not be used in newsgroups."
2972 (message-remove-header "Disposition-Notification-To")
2974 (insert (format "Disposition-Notification-To: %s\n"
2975 (or (message-fetch-field "From") (message-make-from))))))
2977 (defun message-elide-region (b e)
2978 "Elide the text in the region.
2979 An ellipsis (from `message-elide-ellipsis') will be inserted where the
2983 (insert message-elide-ellipsis))
2985 (defvar message-caesar-translation-table nil)
2987 (defun message-caesar-region (b e &optional n)
2988 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
2991 (min (point) (or (mark t) (point)))
2992 (max (point) (or (mark t) (point)))
2993 (when current-prefix-arg
2994 (prefix-numeric-value current-prefix-arg))))
2996 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
2997 (unless (or (zerop n) ; no action needed for a rot of 0
2998 (= b e)) ; no region to rotate
2999 ;; We build the table, if necessary.
3000 (when (or (not message-caesar-translation-table)
3001 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
3002 (setq message-caesar-translation-table
3003 (message-make-caesar-translation-table n)))
3004 (translate-region b e message-caesar-translation-table)))
3006 (defun message-make-caesar-translation-table (n)
3007 "Create a rot table with offset N."
3009 (table (make-string 256 0)))
3010 (while (< (incf i) 256)
3013 (substring table 0 ?A)
3014 (substring table (+ ?A n) (+ ?A n (- 26 n)))
3015 (substring table ?A (+ ?A n))
3016 (substring table (+ ?A 26) ?a)
3017 (substring table (+ ?a n) (+ ?a n (- 26 n)))
3018 (substring table ?a (+ ?a n))
3019 (substring table (+ ?a 26) 255))))
3021 (defun message-caesar-buffer-body (&optional rotnum)
3022 "Caesar rotate all letters in the current buffer by 13 places.
3023 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3024 With prefix arg, specifies the number of places to rotate each letter forward.
3025 Mail and USENET news headers are not rotated."
3026 (interactive (if current-prefix-arg
3027 (list (prefix-numeric-value current-prefix-arg))
3031 (when (message-goto-body)
3032 (narrow-to-region (point) (point-max)))
3033 (message-caesar-region (point-min) (point-max) rotnum))))
3035 (defun message-pipe-buffer-body (program)
3036 "Pipe the message body in the current buffer through PROGRAM."
3039 (when (message-goto-body)
3040 (narrow-to-region (point) (point-max)))
3041 (shell-command-on-region
3042 (point-min) (point-max) program nil t))))
3044 (defun message-rename-buffer (&optional enter-string)
3045 "Rename the *message* buffer to \"*message* RECIPIENT\".
3046 If the function is run with a prefix, it will ask for a new buffer
3047 name, rather than giving an automatic name."
3048 (interactive "Pbuffer name: ")
3051 (goto-char (point-min))
3052 (narrow-to-region (point)
3053 (search-forward mail-header-separator nil 'end))
3055 (if (message-news-p) (message-fetch-field "Newsgroups")
3056 (message-fetch-field "To"))
3059 (if (string-match "," mail-to)
3060 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
3062 (name-default (concat "*message* " mail-trimmed-to))
3063 (name (if enter-string
3064 (read-string "New buffer name: " name-default)
3066 (rename-buffer name t)))))
3068 (defun message-fill-yanked-message (&optional justifyp)
3069 "Fill the paragraphs of a message yanked into this one.
3070 Numeric argument means justify as well."
3073 (goto-char (point-min))
3074 (search-forward (concat "\n" mail-header-separator "\n") nil t)
3075 (let ((fill-prefix message-yank-prefix))
3076 (fill-individual-paragraphs (point) (point-max) justifyp))))
3078 (defun message-indent-citation ()
3079 "Modify text just inserted from a message to be cited.
3080 The inserted text should be the region.
3081 When this function returns, the region is again around the modified text.
3083 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3084 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3085 (let ((start (point)))
3086 ;; Remove unwanted headers.
3087 (when message-ignored-cited-headers
3092 (if (search-forward "\n\n" nil t)
3095 (message-remove-header message-ignored-cited-headers t)
3096 (when (= (point-min) (point-max))
3097 (setq all-removed t))
3098 (goto-char (point-max)))
3102 ;; Delete blank lines at the start of the buffer.
3103 (while (and (point-min)
3106 (message-delete-line))
3107 ;; Delete blank lines at the end of the buffer.
3108 (goto-char (point-max))
3111 (while (and (zerop (forward-line -1))
3113 (message-delete-line))
3114 ;; Do the indentation.
3115 (if (null message-yank-prefix)
3116 (indent-rigidly start (mark t) message-indentation-spaces)
3119 (while (< (point) (mark t))
3120 (if (or (looking-at ">") (looking-at "^$"))
3121 (insert message-yank-cited-prefix)
3122 (insert message-yank-prefix))
3126 (defun message-list-references (refs-list &rest refs-strs)
3127 "Add `Message-ID's which appear in REFS-STRS but not in REFS-LIST,
3129 (let (refs ref id saved-id)
3130 (when (and refs-list
3131 (integerp message-list-references-add-position))
3132 (let ((pos message-list-references-add-position))
3133 (while (and refs-list
3135 (push (pop refs-list) saved-id)
3136 (setq pos (1- pos)))))
3138 (when (setq refs (pop refs-strs))
3139 (setq refs (std11-parse-msg-ids (std11-lexical-analyze refs)))
3141 (when (eq (car (setq ref (pop refs))) 'msg-id)
3142 (setq id (concat "<" (mapconcat 'cdr (cdr ref) "") ">"))
3143 (or (member id refs-list)
3144 (member id saved-id)
3145 (push id refs-list))))))
3147 (push (pop saved-id) refs-list))
3150 (defvar gnus-article-copy)
3151 (defun message-yank-original (&optional arg)
3152 "Insert the message being replied to, if any.
3153 Puts point before the text and mark after.
3154 Normally indents each nonblank line ARG spaces (default 3). However,
3155 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3157 This function uses `message-cite-function' to do the actual citing.
3159 Just \\[universal-argument] as argument means don't indent, insert no
3160 prefix, and don't delete any headers.
3162 In addition, if `message-yank-add-new-references' is non-nil and this
3163 command is called interactively, new IDs from the yanked article will
3164 be added to \"References\" field.
3165 \(See also `message-yank-add-new-references'.)"
3167 (let ((modified (buffer-modified-p))
3168 (buffer (message-eval-parameter message-reply-buffer))
3171 message-cite-function)
3172 (delete-windows-on buffer t)
3173 (insert-buffer buffer) ; mark will be set at the end of article.
3177 ;; Add new IDs to References field.
3178 (when (and message-yank-add-new-references (interactive-p))
3181 (message-narrow-to-headers)
3182 (setq refs (message-list-references
3184 (message-fetch-field "References")))
3186 (narrow-to-region start end)
3187 (std11-narrow-to-header)
3188 (when (setq refs (message-list-references
3190 (unless (eq message-yank-add-new-references
3192 (or (message-fetch-field "References")
3193 (message-fetch-field "In-Reply-To")))
3194 (message-fetch-field "Message-ID")))
3196 (message-narrow-to-headers)
3197 (goto-char (point-min))
3198 (let ((case-fold-search t))
3199 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
3201 (goto-char (point-max))))
3203 (list (or (assq 'References message-header-format-alist)
3204 '(References . message-fill-references)))
3205 (list (cons 'References
3206 (mapconcat 'identity (nreverse refs) " "))))
3207 (backward-delete-char 1)))))
3210 (if (and message-suspend-font-lock-when-citing
3211 (boundp 'font-lock-mode)
3212 (symbol-value 'font-lock-mode))
3217 (funcall message-cite-function))
3219 (funcall message-cite-function)))
3220 (message-exchange-point-and-mark)
3224 (setq message-checksum (message-checksum))))))
3226 (defun message-yank-buffer (buffer)
3227 "Insert BUFFER into the current buffer and quote it."
3228 (interactive "bYank buffer: ")
3229 (let ((message-reply-buffer buffer))
3230 (save-window-excursion
3231 (message-yank-original))))
3233 (defun message-buffers ()
3234 "Return a list of active message buffers."
3237 (dolist (buffer (buffer-list t))
3239 (when (and (eq major-mode 'message-mode)
3240 (null message-sent-message-via))
3241 (push (buffer-name buffer) buffers))))
3242 (nreverse buffers)))
3244 (defun message-cite-original-without-signature ()
3245 "Cite function in the standard Message manner."
3246 (let ((start (point))
3249 (when message-indent-citation-function
3250 (if (listp message-indent-citation-function)
3251 message-indent-citation-function
3252 (list message-indent-citation-function))))
3253 (message-reply-headers (or message-reply-headers
3254 (make-mail-header))))
3255 (mail-header-set-from message-reply-headers
3259 (if (search-forward "\n\n" nil t)
3262 (or (message-fetch-field "from")
3267 (when (re-search-backward message-signature-separator start t)
3268 ;; Also peel off any blank lines before the signature.
3270 (while (looking-at "^[ \t]*$")
3273 (delete-region (point) end)
3274 (unless (search-backward "\n\n" start t)
3275 ;; Insert a blank line if it is peeled off.
3279 (funcall (pop functions)))
3280 (when message-citation-line-function
3283 (funcall message-citation-line-function))))
3285 (eval-when-compile (defvar mail-citation-hook)) ;Compiler directive
3286 (defun message-cite-original ()
3287 "Cite function in the standard Message manner."
3288 (if (and (boundp 'mail-citation-hook)
3290 (run-hooks 'mail-citation-hook)
3291 (let ((start (point))
3294 (when message-indent-citation-function
3295 (if (listp message-indent-citation-function)
3296 message-indent-citation-function
3297 (list message-indent-citation-function))))
3298 (message-reply-headers (or message-reply-headers
3299 (make-mail-header))))
3300 (mail-header-set-from message-reply-headers
3304 (if (search-forward "\n\n" nil t)
3307 (or (message-fetch-field "from")
3311 (funcall (pop functions)))
3312 (when message-citation-line-function
3315 (funcall message-citation-line-function)))))
3317 (defun message-insert-citation-line ()
3318 "Insert a simple citation line."
3319 (when message-reply-headers
3320 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
3322 (defun message-position-on-field (header &rest afters)
3323 (let ((case-fold-search t))
3326 (goto-char (point-min))
3329 (concat "^" (regexp-quote mail-header-separator) "$"))
3330 (match-beginning 0)))
3331 (goto-char (point-min))
3332 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
3334 (re-search-forward "^[^ \t]" nil 'move)
3336 (skip-chars-backward "\n")
3339 (not (re-search-forward
3340 (concat "^" (regexp-quote (car afters)) ":")
3344 (re-search-forward "^[^ \t]" nil 'move)
3345 (beginning-of-line))
3346 (insert header ": \n")
3350 (defun message-remove-signature ()
3351 "Remove the signature from the text between point and mark.
3352 The text will also be indented the normal way."
3354 (let ((start (point))
3356 (if (not (re-search-forward message-signature-separator (mark t) t))
3357 ;; No signature here, so we just indent the cited text.
3358 (message-indent-citation)
3359 ;; Find the last non-empty line.
3361 (while (looking-at "[ \t]*$")
3364 (setq mark (set-marker (make-marker) (point)))
3366 (message-indent-citation)
3367 ;; Enable undoing the deletion.
3369 (delete-region mark (mark t))
3370 (set-marker mark nil)))))
3375 ;;; Sending messages
3378 ;; Avoid byte-compile warning.
3379 (defvar message-encoding-buffer nil)
3380 (defvar message-edit-buffer nil)
3381 (defvar message-mime-mode nil)
3383 (defun message-send-and-exit (&optional arg)
3384 "Send message like `message-send', then, if no errors, exit from mail buffer."
3386 (let ((buf (current-buffer))
3387 (actions message-exit-actions)
3388 (frame (selected-frame))
3389 (org-frame message-original-frame))
3390 (when (and (message-send arg)
3392 (if message-kill-buffer-on-exit
3395 (when (eq buf (current-buffer))
3396 (message-bury buf)))
3397 (message-do-actions actions)
3398 (message-delete-frame frame org-frame)
3401 (defun message-dont-send ()
3402 "Don't send the message you have been editing.
3403 Instead, just auto-save the buffer and then bury it."
3405 (set-buffer-modified-p t)
3407 (let ((actions message-postpone-actions)
3408 (frame (selected-frame))
3409 (org-frame message-original-frame))
3410 (message-bury (current-buffer))
3411 (message-do-actions actions)
3412 (message-delete-frame frame org-frame)))
3414 (defun message-kill-buffer ()
3415 "Kill the current buffer."
3417 (when (or (not (buffer-modified-p))
3418 (eq t message-kill-buffer-query-function)
3419 (funcall message-kill-buffer-query-function
3420 "The buffer modified; kill anyway? "))
3421 (let ((actions message-kill-actions)
3422 (draft-article message-draft-article)
3423 (auto-save-file-name buffer-auto-save-file-name)
3424 (file-name buffer-file-name)
3425 (modified (buffer-modified-p))
3426 (frame (selected-frame))
3427 (org-frame message-original-frame))
3428 (setq buffer-file-name nil)
3429 (kill-buffer (current-buffer))
3430 (when (and message-kill-buffer-and-remove-file
3431 (or (and auto-save-file-name
3432 (file-exists-p auto-save-file-name))
3434 (file-exists-p file-name)))
3435 (yes-or-no-p (format "Remove the backup file%s? "
3436 (if modified " too" ""))))
3438 (delete-file auto-save-file-name))
3439 (let ((message-draft-article draft-article))
3440 (message-disassociate-draft)))
3441 (message-do-actions actions)
3442 (message-delete-frame frame org-frame)))
3445 (defun message-mimic-kill-buffer ()
3446 "Kill the current buffer with query. This is an imitation for
3447 `kill-buffer', but it will delete a message frame."
3449 (let ((bufname (read-buffer (format "Kill buffer: (default %s) "
3451 message-kill-buffer-and-remove-file)
3452 (when (or (not bufname)
3453 (string-equal bufname "")
3454 (string-equal bufname (buffer-name)))
3455 (message-kill-buffer))))
3457 (defun message-delete-frame (frame org-frame)
3458 "Delete frame for editing message."
3459 (when (and (or (static-if (featurep 'xemacs)
3460 (device-on-window-system-p)
3462 (>= emacs-major-version 20))
3463 (or (and (eq message-delete-frame-on-exit t)
3464 (select-frame frame)
3465 (or (eq frame org-frame)
3467 (y-or-n-p "Delete this frame?")
3469 (and (eq message-delete-frame-on-exit 'ask)
3470 (select-frame frame)
3472 (y-or-n-p "Delete this frame?")
3474 (delete-frame frame)))
3476 (defun message-bury (buffer)
3477 "Bury this mail BUFFER."
3478 (let ((newbuf (other-buffer buffer)))
3479 (bury-buffer buffer)
3480 (if (and (fboundp 'frame-parameters)
3481 (cdr (assq 'dedicated (frame-parameters)))
3482 (not (null (delq (selected-frame) (visible-frame-list)))))
3483 (delete-frame (selected-frame))
3484 (switch-to-buffer newbuf))))
3486 (defun message-send (&optional arg)
3487 "Send the message in the current buffer.
3488 If `message-interactive' is non-nil, wait for success indication or
3489 error messages, and inform user.
3490 Otherwise any failure is reported in a message back to the user from
3492 The usage of ARG is defined by the instance that called Message.
3493 It should typically alter the sending method in some way or other."
3496 (when (or (buffer-modified-p)
3497 (message-check-element 'unchanged)
3498 (y-or-n-p "No changes in the buffer; really send? "))
3499 ;; Make it possible to undo the coming changes.
3501 (let ((inhibit-read-only t))
3502 (put-text-property (point-min) (point-max) 'read-only nil))
3503 (run-hooks 'message-send-hook)
3504 (message-fix-before-sending)
3505 (message message-sending-message)
3506 (let ((message-encoding-buffer
3507 (message-generate-new-buffer-clone-locals " message encoding"))
3508 (message-edit-buffer (current-buffer))
3509 (message-mime-mode mime-edit-mode-flag)
3510 (alist message-send-method-alist)
3512 elem sent dont-barf-on-no-method
3513 (message-options message-options))
3516 (message-options-set-recipient)
3518 (set-buffer message-encoding-buffer)
3520 ;; ;; Avoid copying text props (except hard newlines).
3521 ;; T-gnus change: copy all text props from the editing buffer
3522 ;; into the encoding buffer.
3523 (insert-buffer-substring message-edit-buffer)
3524 (funcall message-encode-function)
3526 (setq elem (pop alist)))
3527 (when (funcall (cadr elem))
3529 (or (not (memq (car elem)
3530 message-sent-message-via))
3531 (if (or (message-gnksa-enable-p 'multiple-copies)
3532 (not (eq (car elem) 'news)))
3535 "Already sent message via %s; resend? "
3537 (error "Denied posting -- multiple copies")))
3538 (setq success (funcall (caddr elem) arg)))
3544 (let ((fcc (message-fetch-field "Fcc"))
3545 (gcc (message-fetch-field "Gcc")))
3548 (eq message-allow-no-recipients 'always)
3549 (and (not (eq message-allow-no-recipients 'never))
3550 (setq dont-barf-on-no-method
3552 (format "No receiver, perform %s anyway? "
3553 (cond ((and fcc gcc) "Fcc and Gcc")
3556 (error "No methods specified to send by"))
3557 (when (or dont-barf-on-no-method
3561 (run-hooks 'message-sent-hook))
3562 (message "Sending...done")
3563 ;; Mark the buffer as unmodified and delete auto-save.
3564 (set-buffer-modified-p nil)
3565 (delete-auto-save-file-if-necessary t)
3566 (message-disassociate-draft)
3567 ;; Delete other mail buffers and stuff.
3568 (message-do-send-housekeeping)
3569 (message-do-actions message-send-actions)
3572 (kill-buffer message-encoding-buffer)))))
3574 (defun message-send-via-mail (arg)
3575 "Send the current message via mail."
3576 (message-send-mail arg))
3578 (defun message-send-via-news (arg)
3579 "Send the current message via news."
3580 (message-send-news arg))
3582 (defmacro message-check (type &rest forms)
3583 "Eval FORMS if TYPE is to be checked."
3584 `(or (message-check-element ,type)
3588 (put 'message-check 'lisp-indent-function 1)
3589 (put 'message-check 'edebug-form-spec '(form body))
3591 ;; Advise the function `invisible-region'.
3592 (let (current-load-list)
3594 `(defadvice invisible-region (around add-mime-edit-invisible (start end)
3596 "Advised by T-gnus Message.
3597 Add the text property `mime-edit-invisible' to an invisible text when
3598 the buffer's major mode is `message-mode'. The added property will be
3599 used to distinguish whether the invisible text is a MIME part or not."
3600 ,(if (featurep 'xemacs)
3601 '(if (eq ?\n (char-after start))
3602 (setq start (1+ start)))
3603 '(if (eq ?\n (char-after (1- end)))
3604 (setq end (1- end))))
3605 (setq ad-return-value
3606 (if (eq 'message-mode major-mode)
3607 (add-text-properties start end
3608 '(invisible t mime-edit-invisible t))
3609 (put-text-property start end 'invisible t))))))
3611 (defun message-text-with-property (prop)
3612 "Return a list of all points where the text has PROP."
3614 (point (point-min)))
3616 (while (< point (point-max))
3617 (when (get-text-property point prop)
3618 (push point points))
3622 (defun message-fix-before-sending ()
3623 "Do various things to make the message nice before sending it."
3624 ;; Make sure there's a newline at the end of the message.
3626 (goto-char (point-max))
3629 ;; Delete all invisible text except for the mime parts which might
3630 ;; be inserted by the MIME-Edit.
3631 (message-check 'invisible-text
3634 mime-from mime-to hidden-start)
3635 (while (setq from (text-property-any to (point-max) 'invisible t))
3636 (setq to (or (text-property-not-all from (point-max) 'invisible t)
3639 (while (setq mime-from (text-property-any mime-to to
3640 'mime-edit-invisible t))
3641 (when (> mime-from mime-to)
3642 (setq hidden-start (or hidden-start mime-to))
3643 (put-text-property mime-to mime-from 'invisible nil))
3644 (setq mime-to (or (text-property-not-all mime-from to
3645 'mime-edit-invisible t)
3647 (when (< mime-to to)
3648 (setq hidden-start (or hidden-start mime-to))
3649 (put-text-property mime-to to 'invisible nil)))
3651 (goto-char hidden-start)
3652 (set-window-start (selected-window) (gnus-point-at-bol))
3653 (unless (yes-or-no-p
3654 "Invisible text found and made visible; continue posting? ")
3655 (error "Invisible text found and made visible")))))
3656 (message-check 'illegible-text
3657 (let ((mm-7bit-chars "\x20-\x7f\r\n\t\x7\x8\xb\xc\x1f\x1b")
3660 (skip-chars-forward mm-7bit-chars)
3662 (when (let ((char (char-after)))
3663 (or (< (mm-char-int char) 128)
3664 (and (mm-multibyte-p)
3665 (memq (char-charset char)
3666 '(eight-bit-control eight-bit-graphic
3668 (add-text-properties (point) (1+ (point)) '(highlight t))
3671 (skip-chars-forward mm-7bit-chars))
3674 (gnus-multiple-choice
3675 "Illegible text found. Continue posting? "
3676 '((?d "Remove and continue posting")
3677 (?r "Replace with dots and continue posting")
3678 (?i "Ignore and continue posting")
3679 (?e "Continue editing"))))
3681 (error "Illegible text found"))
3683 (skip-chars-forward mm-7bit-chars)
3685 (when (let ((char (char-after)))
3686 (or (< (mm-char-int char) 128)
3687 (and (mm-multibyte-p)
3688 (memq (char-charset char)
3689 '(eight-bit-control eight-bit-graphic
3692 (remove-text-properties (point) (1+ (point)) '(highlight t))
3697 (skip-chars-forward mm-7bit-chars))))))
3699 (defun message-add-action (action &rest types)
3700 "Add ACTION to be performed when doing an exit of type TYPES."
3702 (add-to-list (intern (format "message-%s-actions" (pop types)))
3705 (defun message-delete-action (action &rest types)
3706 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
3709 (set (setq var (intern (format "message-%s-actions" (pop types))))
3710 (delq action (symbol-value var))))))
3712 (defun message-do-actions (actions)
3713 "Perform all actions in ACTIONS."
3714 ;; Now perform actions on successful sending.
3718 ;; A simple function.
3719 ((message-functionp (car actions))
3720 (funcall (car actions)))
3721 ;; Something to be evaled.
3723 (eval (car actions)))))
3726 (defsubst message-maybe-split-and-send-mail ()
3727 "Split a message if necessary, and send it via mail.
3728 Returns nil if sending succeeded, returns any string if sending failed.
3729 This sub function is for exclusive use of `message-send-mail'."
3730 (let ((mime-edit-split-ignored-field-regexp
3731 mime-edit-split-ignored-field-regexp)
3732 (case-fold-search t)
3734 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
3735 (setq mime-edit-split-ignored-field-regexp
3736 (concat (substring mime-edit-split-ignored-field-regexp
3737 0 (match-beginning 0))
3738 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
3739 "_so_don't_rape_it!"
3740 (substring mime-edit-split-ignored-field-regexp
3744 (catch 'message-sending-mail-failure
3745 (mime-edit-maybe-split-and-send
3750 (std11-narrow-to-header mail-header-separator)
3751 (goto-char (point-min))
3752 (when (re-search-forward "^Message-ID:" nil t)
3753 (delete-region (match-end 0) (std11-field-end))
3754 (insert " " (message-make-message-id))))
3756 (funcall (or message-send-mail-real-function
3757 message-send-mail-function))
3759 (throw 'message-sending-mail-failure err))))))
3763 (funcall (or message-send-mail-real-function
3764 message-send-mail-function))
3768 (if (eq 'error (car failure))
3770 (prin1-to-string failure)))))
3772 (defun message-send-mail-partially ()
3773 "Send mail as message/partial."
3774 ;; replace the header delimiter with a blank line
3775 (goto-char (point-min))
3777 (concat "^" (regexp-quote mail-header-separator) "\n"))
3778 (replace-match "\n")
3779 (run-hooks 'message-send-mail-hook)
3780 (let ((p (goto-char (point-min)))
3781 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
3782 (curbuf (current-buffer))
3783 (id (message-make-message-id)) (n 1)
3784 plist total header required-mail-headers)
3786 (if (< (point-max) (+ p message-send-mail-partially-limit))
3787 (goto-char (point-max))
3788 (goto-char (+ p message-send-mail-partially-limit))
3790 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
3793 (setq total (length plist))
3794 (push (point-max) plist)
3795 (setq plist (nreverse plist))
3798 (setq p (pop plist))
3801 (copy-to-buffer tembuf p (car plist))
3803 (goto-char (point-min))
3806 (goto-char (point-min))
3807 (narrow-to-region (point) (point))
3810 (setq header (buffer-substring (point-min) (point)))
3811 (goto-char (point-min))
3812 (narrow-to-region (point) (point))
3814 (message-remove-header "Mime-Version")
3815 (message-remove-header "Content-Type")
3816 (message-remove-header "Content-Transfer-Encoding")
3817 (message-remove-header "Message-ID")
3818 (message-remove-header "Lines")
3819 (goto-char (point-max))
3820 (insert "Mime-Version: 1.0\n")
3821 (setq header (buffer-substring (point-min) (point-max))))
3822 (goto-char (point-max))
3823 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
3826 (let ((mail-header-separator ""))
3827 (when (memq 'Message-ID message-required-mail-headers)
3828 (insert "Message-ID: " (message-make-message-id) "\n"))
3829 (when (memq 'Lines message-required-mail-headers)
3830 (insert "Lines: " (message-make-lines) "\n"))
3831 (message-goto-subject)
3833 (insert (format " (%d/%d)" n total))
3835 (mm-with-unibyte-current-buffer
3836 (funcall (or message-send-mail-real-function
3837 message-send-mail-function))))
3839 (setq p (pop plist))
3841 (kill-buffer tembuf))))
3843 (defun message-send-mail (&optional arg)
3844 (require 'mail-utils)
3845 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
3846 (case-fold-search nil)
3847 (news (message-news-p))
3848 (message-this-is-mail t)
3849 (headers message-required-mail-headers)
3852 (message-narrow-to-headers)
3853 ;; Generate the Mail-Followup-To header if the header is not there...
3854 (if (and (or message-subscribed-regexps
3855 message-subscribed-addresses
3856 message-subscribed-address-file
3857 message-subscribed-address-functions)
3858 (not (mail-fetch-field "mail-followup-to")))
3861 (cons "Mail-Followup-To" (message-make-mft))
3862 message-required-mail-headers))
3863 ;; otherwise, delete the MFT header if the field is empty
3864 (when (equal "" (mail-fetch-field "mail-followup-to"))
3865 (message-remove-header "^Mail-Followup-To:")))
3866 ;; Insert some headers.
3867 (let ((message-deletable-headers
3868 (if news nil message-deletable-headers)))
3869 (message-generate-headers headers))
3870 ;; Let the user do all of the above.
3871 (run-hooks 'message-header-hook))
3872 (if (not (message-check-mail-syntax))
3880 ;; ;; Avoid copying text props (except hard newlines).
3881 ;; T-gnus change: copy all text props from the editing buffer
3882 ;; into the encoding buffer.
3883 (insert-buffer-substring message-encoding-buffer)
3884 ;; Remove some headers.
3886 (message-narrow-to-headers)
3887 ;; We Semi-gnus people have no use for it.
3888 ;; ;; We (re)generate the Lines header.
3889 ;; (when (memq 'Lines message-required-mail-headers)
3890 ;; (message-generate-headers '(Lines)))
3891 (message-remove-header message-ignored-mail-headers t))
3892 (goto-char (point-max))
3893 ;; require one newline at the end.
3894 (or (= (preceding-char) ?\n)
3898 (message-narrow-to-headers)
3900 (or (message-fetch-field "cc")
3901 (message-fetch-field "to"))
3902 (let ((ct (mime-read-Content-Type)))
3904 (and (eq 'text (cdr (assq 'type ct)))
3905 (eq 'plain (cdr (assq 'subtype ct))))))))
3906 (message-insert-courtesy-copy))
3907 (setq failure (message-maybe-split-and-send-mail)))
3908 (kill-buffer tembuf))
3909 (set-buffer message-edit-buffer)
3912 (message "Couldn't send message via mail: %s" failure)
3914 (push 'mail message-sent-message-via)))))
3916 (defun message-send-mail-with-sendmail ()
3917 "Send off the prepared buffer with sendmail."
3918 (let ((errbuf (if message-interactive
3919 (message-generate-new-buffer-clone-locals
3922 resend-to-addresses delimline)
3925 (let ((case-fold-search t))
3927 (message-narrow-to-headers)
3928 (setq resend-to-addresses (message-fetch-field "resent-to")))
3929 ;; Change header-delimiter to be what sendmail expects.
3930 (goto-char (point-min))
3932 (concat "^" (regexp-quote mail-header-separator) "\n"))
3933 (replace-match "\n")
3935 (setq delimline (point-marker))
3936 (run-hooks 'message-send-mail-hook)
3937 ;; Insert an extra newline if we need it to work around
3938 ;; Sun's bug that swallows newlines.
3939 (goto-char (1+ delimline))
3940 (when (eval message-mailer-swallows-blank-line)
3942 (when message-interactive
3946 (let* ((default-directory "/")
3947 (cpr (as-binary-process
3949 'call-process-region
3951 (list (point-min) (point-max)
3952 (if (boundp 'sendmail-program)
3954 "/usr/lib/sendmail")
3955 nil errbuf nil "-oi")
3956 ;; Always specify who from,
3957 ;; since some systems have broken sendmails.
3958 ;; But some systems are more broken with -f, so
3959 ;; we'll let users override this.
3960 (if (null message-sendmail-f-is-evil)
3961 (list "-f" (message-make-address)))
3962 ;; These mean "report errors by mail"
3963 ;; and "deliver in background".
3964 (if (null message-interactive) '("-oem" "-odb"))
3965 ;; Get the addresses from the message
3966 ;; unless this is a resend.
3967 ;; We must not do that for a resend
3968 ;; because we would find the original addresses.
3969 ;; For a resend, include the specific addresses.
3970 (if resend-to-addresses
3971 (list resend-to-addresses)
3973 (unless (or (null cpr) (zerop cpr))
3974 (error "Sending...failed with exit value %d" cpr)))
3975 (when message-interactive
3978 (goto-char (point-min))
3979 (while (re-search-forward "\n\n* *" nil t)
3980 (replace-match "; "))
3981 (if (not (zerop (buffer-size)))
3982 (error "Sending...failed to %s"
3983 (buffer-substring (point-min) (point-max)))))))
3984 (when (bufferp errbuf)
3985 (kill-buffer errbuf)))))
3987 (defun message-send-mail-with-qmail ()
3988 "Pass the prepared message buffer to qmail-inject.
3989 Refer to the documentation for the variable `message-send-mail-function'
3990 to find out how to use this."
3991 ;; replace the header delimiter with a blank line
3992 (goto-char (point-min))
3994 (concat "^" (regexp-quote mail-header-separator) "\n"))
3995 (replace-match "\n")
3997 (run-hooks 'message-send-mail-hook)
4002 'call-process-region 1 (point-max) message-qmail-inject-program
4004 ;; qmail-inject's default behaviour is to look for addresses on the
4005 ;; command line; if there're none, it scans the headers.
4006 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4008 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4009 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4010 ;; message from stdin.
4012 ;; qmail also has the advantage of not having been raped by
4013 ;; various vendors, so we don't have to allow for that, either --
4014 ;; compare this with message-send-mail-with-sendmail and weep
4015 ;; for sendmail's lost innocence.
4017 ;; all this is way cool coz it lets us keep the arguments entirely
4018 ;; free for -inject-arguments -- a big win for the user and for us
4019 ;; since we don't have to play that double-guessing game and the user
4020 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4021 (if (functionp message-qmail-inject-args)
4022 (funcall message-qmail-inject-args)
4023 message-qmail-inject-args)))
4024 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4025 ;; we have to look at the retval instead
4027 (100 (error "qmail-inject reported permanent failure"))
4028 (111 (error "qmail-inject reported transient failure"))
4029 ;; should never happen
4030 (t (error "qmail-inject reported unknown failure"))))
4032 (defun message-send-mail-with-mh ()
4033 "Send the prepared message buffer with mh."
4034 (let ((mh-previous-window-config nil)
4035 (name (mh-new-draft-name)))
4036 (setq buffer-file-name name)
4037 ;; MH wants to generate these headers itself.
4038 (when message-mh-deletable-headers
4039 (let ((headers message-mh-deletable-headers))
4041 (goto-char (point-min))
4042 (and (re-search-forward
4043 (concat "^" (symbol-name (car headers)) ": *") nil t)
4044 (message-delete-line))
4046 (run-hooks 'message-send-mail-hook)
4047 ;; Pass it on to mh.
4050 (defun message-send-mail-with-smtp ()
4051 "Send off the prepared buffer with SMTP."
4052 (require 'smtp) ; XXX
4053 (let ((case-fold-search t)
4056 (message-narrow-to-headers)
4058 ;; XXX: Should be replaced by better one.
4059 (smtp-deduce-address-list (current-buffer)
4060 (point-min) (point-max)))
4061 ;; Remove BCC lines.
4062 (message-remove-header "bcc"))
4063 ;; replace the header delimiter with a blank line.
4064 (goto-char (point-min))
4066 (concat "^" (regexp-quote mail-header-separator) "\n"))
4067 (replace-match "\n")
4069 (run-hooks 'message-send-mail-hook)
4071 (smtp-send-buffer user-mail-address recipients (current-buffer))
4072 (error "Sending failed; no recipients"))))
4074 (defsubst message-maybe-split-and-send-news (method)
4075 "Split a message if necessary, and send it via news.
4076 Returns nil if sending succeeded, returns t if sending failed.
4077 This sub function is for exclusive use of `message-send-news'."
4078 (let ((mime-edit-split-ignored-field-regexp
4079 mime-edit-split-ignored-field-regexp)
4080 (case-fold-search t))
4081 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
4082 (setq mime-edit-split-ignored-field-regexp
4083 (concat (substring mime-edit-split-ignored-field-regexp
4084 0 (match-beginning 0))
4085 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
4086 "_so_don't_rape_it!"
4087 (substring mime-edit-split-ignored-field-regexp
4090 (catch 'message-sending-news-failure
4091 (mime-edit-maybe-split-and-send
4096 (std11-narrow-to-header mail-header-separator)
4097 (goto-char (point-min))
4098 (when (re-search-forward "^Message-ID:" nil t)
4099 (delete-region (match-end 0) (std11-field-end))
4100 (insert " " (message-make-message-id))))
4101 (unless (funcall message-send-news-function method)
4102 (throw 'message-sending-news-failure t)))))
4104 (not (funcall message-send-news-function method)))))
4106 (defun message-smtpmail-send-it ()
4107 "Send the prepared message buffer with `smtpmail-send-it'.
4108 This only differs from `smtpmail-send-it' that this command evaluates
4109 `message-send-mail-hook' just before sending a message. It is useful
4110 if your ISP requires the POP-before-SMTP authentication. See the
4111 documentation for the function `mail-source-touch-pop'."
4112 (run-hooks 'message-send-mail-hook)
4115 (defun message-canlock-generate ()
4116 "Return a string that is non-trival to guess.
4117 Do not use this for anything important, it is cryptographically weak."
4118 (let (sha1-maximum-internal-length)
4119 (sha1 (concat (message-unique-id)
4120 (format "%x%x%x" (random) (random t) (random))
4121 (prin1-to-string (recent-keys))
4122 (prin1-to-string (garbage-collect))))))
4124 (defun message-canlock-password ()
4125 "The password used by message for cancel locks.
4126 This is the value of `canlock-password', if that option is non-nil.
4127 Otherwise, generate and save a value for `canlock-password' first."
4128 (unless canlock-password
4129 (customize-save-variable 'canlock-password (message-canlock-generate))
4130 (setq canlock-password-for-verify canlock-password))
4133 (defun message-insert-canlock ()
4134 (when message-insert-canlock
4135 (message-canlock-password)
4136 (canlock-insert-header)))
4138 (defun message-send-news (&optional arg)
4139 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4140 (case-fold-search nil)
4141 (method (if (message-functionp message-post-method)
4142 (funcall message-post-method arg)
4143 message-post-method))
4144 (newsgroups-field (save-restriction
4145 (message-narrow-to-headers-or-head)
4146 (message-fetch-field "Newsgroups")))
4147 (followup-field (save-restriction
4148 (message-narrow-to-headers-or-head)
4149 (message-fetch-field "Followup-To")))
4150 ;; BUG: We really need to get the charset for each name in the
4151 ;; Newsgroups and Followup-To lines to allow crossposting
4152 ;; between group namess with incompatible character sets.
4153 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4154 (group-field-charset
4155 (gnus-group-name-charset method newsgroups-field))
4156 (followup-field-charset
4157 (gnus-group-name-charset method (or followup-field "")))
4158 (mime-field-encoding-method-alist
4159 (append (when group-field-charset
4160 (list (cons "Newsgroups" group-field-charset)))
4161 (when followup-field-charset
4162 (list (cons "Followup-To" followup-field-charset)))
4163 mime-field-encoding-method-alist))
4164 (message-syntax-checks
4166 (listp message-syntax-checks))
4167 (cons '(existing-newsgroups . disabled)
4168 message-syntax-checks)
4169 message-syntax-checks))
4170 (message-this-is-news t)
4173 (message-narrow-to-headers)
4174 ;; Insert some headers.
4175 (message-generate-headers message-required-news-headers)
4176 (message-insert-canlock)
4177 ;; Let the user do all of the above.
4178 (run-hooks 'message-header-hook))
4179 ;; Note: This check will be disabled by the ".*" default value for
4180 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4181 (when (and group-field-charset
4182 (listp message-syntax-checks))
4183 (setq message-syntax-checks
4184 (cons '(valid-newsgroups . disabled)
4185 message-syntax-checks)))
4186 (message-cleanup-headers)
4187 (if (not (let ((message-post-method method))
4188 (message-check-news-syntax)))
4193 (buffer-disable-undo)
4195 (insert-buffer-substring message-encoding-buffer)
4196 ;; Remove some headers.
4198 (message-narrow-to-headers)
4199 ;; We Semi-gnus people have no use for it.
4200 ;; ;; We (re)generate the Lines header.
4201 ;; (when (memq 'Lines message-required-mail-headers)
4202 ;; (message-generate-headers '(Lines)))
4203 ;; Remove some headers.
4204 (message-remove-header message-ignored-news-headers t))
4205 (goto-char (point-max))
4206 ;; require one newline at the end.
4207 (or (= (preceding-char) ?\n)
4209 (setq result (message-maybe-split-and-send-news method)))
4210 (kill-buffer tembuf))
4211 (set-buffer message-edit-buffer)
4214 (message "Couldn't send message via news: %s"
4215 (nnheader-get-report (car method)))
4217 (push 'news message-sent-message-via)))))
4219 ;; 1997-09-29 by MORIOKA Tomohiko
4220 (defun message-send-news-with-gnus (method)
4221 (let ((case-fold-search t))
4222 ;; Remove the delimiter.
4223 (goto-char (point-min))
4225 (concat "^" (regexp-quote mail-header-separator) "\n"))
4226 (replace-match "\n")
4228 (run-hooks 'message-send-news-hook)
4229 (gnus-open-server method)
4230 (message "Sending news via %s..." (gnus-server-string method))
4231 (gnus-request-post method)
4235 ;;; Header generation & syntax checking.
4238 (defun message-check-element (type)
4239 "Return non-nil if this TYPE is not to be checked."
4240 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
4242 (let ((able (assq type message-syntax-checks)))
4244 (eq (cdr able) 'disabled)))))
4246 (defun message-check-news-syntax ()
4247 "Check the syntax of the message."
4252 ;; We narrow to the headers and check them first.
4255 (message-narrow-to-headers)
4256 (message-check-news-header-syntax)))
4259 (set-buffer message-edit-buffer)
4260 (message-check-news-body-syntax))))))
4262 (defun message-check-news-header-syntax ()
4264 ;; Check Newsgroups header.
4265 (message-check 'newsgroups
4266 (let ((group (message-fetch-field "newsgroups")))
4269 (not (string-match "\\`[ \t]*\\'" group)))
4272 "The newsgroups field is empty or missing. Posting is denied.")))))
4273 ;; Check the Subject header.
4274 (message-check 'subject
4275 (let* ((case-fold-search t)
4276 (subject (message-fetch-field "subject")))
4279 (not (string-match "\\`[ \t]*\\'" subject)))
4282 "The subject field is empty or missing. Posting is denied.")))))
4283 ;; Check for commands in Subject.
4284 (message-check 'subject-cmsg
4285 (if (string-match "^cmsg " (message-fetch-field "subject"))
4287 "The control code \"cmsg\" is in the subject. Really post? ")
4289 ;; Check for multiple identical headers.
4290 (message-check 'multiple-headers
4292 (while (and (not found)
4293 (re-search-forward "^[^ \t:]+: " nil t))
4295 (or (re-search-forward
4300 (match-beginning 0) (- (match-end 0) 2))))
4305 (y-or-n-p (format "Multiple %s headers. Really post? " found))
4307 ;; Check for Version and Sendsys.
4308 (message-check 'sendsys
4309 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
4311 (format "The article contains a %s command. Really post? "
4312 (buffer-substring (match-beginning 0)
4313 (1- (match-end 0)))))
4315 ;; See whether we can shorten Followup-To.
4316 (message-check 'shorten-followup-to
4317 (let ((newsgroups (message-fetch-field "newsgroups"))
4318 (followup-to (message-fetch-field "followup-to"))
4320 (when (and newsgroups
4321 (string-match "," newsgroups)
4326 (setq to (completing-read
4327 "Followups to (default: no Followup-To header) "
4328 (mapcar (lambda (g) (list g))
4330 (message-tokenize-header
4332 (goto-char (point-min))
4333 (insert "Followup-To: " to "\n"))
4335 ;; Check "Shoot me".
4336 (message-check 'shoot
4337 (if (re-search-forward
4338 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
4339 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
4341 ;; Check for Approved.
4342 (message-check 'approved
4343 (if (re-search-forward "^Approved:" nil t)
4344 (y-or-n-p "The article contains an Approved header. Really post? ")
4346 ;; Check the Message-ID header.
4347 (message-check 'message-id
4348 (let* ((case-fold-search t)
4349 (message-id (message-fetch-field "message-id" t)))
4350 (or (not message-id)
4351 ;; Is there an @ in the ID?
4352 (and (string-match "@" message-id)
4353 ;; Is there a dot in the ID?
4354 (string-match "@[^.]*\\." message-id)
4355 ;; Does the ID end with a dot?
4356 (not (string-match "\\.>" message-id)))
4358 (format "The Message-ID looks strange: \"%s\". Really post? "
4360 ;; Check the Newsgroups & Followup-To headers.
4361 (message-check 'existing-newsgroups
4362 (let* ((case-fold-search t)
4363 (newsgroups (message-fetch-field "newsgroups"))
4364 (followup-to (message-fetch-field "followup-to"))
4365 (groups (message-tokenize-header
4367 (concat newsgroups "," followup-to)
4369 (post-method (if (message-functionp message-post-method)
4370 (funcall message-post-method)
4371 message-post-method))
4372 ;; KLUDGE to handle nnvirtual groups. Doing this right
4373 ;; would probably involve a new nnoo function.
4374 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
4375 (method (if (and (consp post-method)
4376 (eq (car post-method) 'nnvirtual)
4377 gnus-message-group-art)
4378 (let ((group (car (nnvirtual-find-group-art
4379 (car gnus-message-group-art)
4380 (cdr gnus-message-group-art)))))
4381 (gnus-find-method-for-group group))
4385 (gnus-group-name-decode
4386 (gnus-group-real-name n)
4387 (gnus-group-name-charset method n)))
4388 (gnus-groups-from-server method)))
4391 (unless (or (equal (car groups) "poster")
4392 (member (car groups) known-groups))
4393 (push (car groups) errors))
4396 ;; Gnus is not running.
4397 ((or (not (and (boundp 'gnus-active-hashtb)
4398 gnus-active-hashtb))
4399 (not (boundp 'gnus-read-active-file)))
4401 ;; We don't have all the group names.
4402 ((and (or (not gnus-read-active-file)
4403 (eq gnus-read-active-file 'some))
4407 "Really post to %s possibly unknown group%s: %s? "
4408 (if (= (length errors) 1) "this" "these")
4409 (if (= (length errors) 1) "" "s")
4410 (mapconcat 'identity errors ", "))))
4411 ;; There were no errors.
4414 ;; There are unknown groups.
4418 "Really post to %s unknown group%s: %s? "
4419 (if (= (length errors) 1) "this" "these")
4420 (if (= (length errors) 1) "" "s")
4421 (mapconcat 'identity errors ", ")))))))
4422 ;; Check the Newsgroups & Followup-To headers for syntax errors.
4423 (message-check 'valid-newsgroups
4424 (let ((case-fold-search t)
4425 (headers '("Newsgroups" "Followup-To"))
4427 (while (and headers (not error))
4428 (when (setq header (mail-fetch-field (car headers)))
4432 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
4437 (not (string-match "\\.\\'\\|\\.\\." g)))
4438 (message-tokenize-header header ","))))
4445 (format "The %s header looks odd: \"%s\". Really post? "
4446 (car headers) header)))))
4447 (message-check 'repeated-newsgroups
4448 (let ((case-fold-search t)
4449 (headers '("Newsgroups" "Followup-To"))
4450 header error groups group)
4453 (when (setq header (mail-fetch-field (pop headers)))
4454 (setq groups (message-tokenize-header header ","))
4455 (while (setq group (pop groups))
4456 (when (member group groups)
4462 (format "Group %s is repeated in headers. Really post? " error)))))
4463 ;; Check the From header.
4464 (message-check 'from
4465 (let* ((case-fold-search t)
4466 (from (message-fetch-field "from"))
4470 (message "There is no From line. Posting is denied.")
4472 ((or (not (string-match
4474 (setq ad (nth 1 (mail-extract-address-components
4475 from))))) ;larsi@ifi
4476 (string-match "\\.\\." ad) ;larsi@ifi..uio
4477 (string-match "@\\." ad) ;larsi@.ifi.uio
4478 (string-match "\\.$" ad) ;larsi@ifi.uio.
4479 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4480 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
4482 "Denied posting -- the From looks strange: \"%s\"." from)
4484 ((let ((addresses (rfc822-addresses from)))
4485 (while (and addresses
4486 (not (eq (string-to-char (car addresses)) ?\()))
4487 (setq addresses (cdr addresses)))
4490 "Denied posting -- bad From address: \"%s\"." from)
4493 ;; Check the Reply-To header.
4494 (message-check 'reply-to
4495 (let* ((case-fold-search t)
4496 (reply-to (message-fetch-field "reply-to"))
4501 ((string-match "," reply-to)
4503 (format "Multiple Reply-To addresses: \"%s\". Really post? "
4505 ((or (not (string-match
4507 (setq ad (nth 1 (mail-extract-address-components
4508 reply-to))))) ;larsi@ifi
4509 (string-match "\\.\\." ad) ;larsi@ifi..uio
4510 (string-match "@\\." ad) ;larsi@.ifi.uio
4511 (string-match "\\.$" ad) ;larsi@ifi.uio.
4512 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4513 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
4516 "The Reply-To looks strange: \"%s\". Really post? "
4520 (defun message-check-news-body-syntax ()
4522 ;; Check for long lines.
4523 (message-check 'long-lines
4524 (goto-char (point-min))
4526 (concat "^" (regexp-quote mail-header-separator) "$"))
4530 mime-edit-tag-regexp)
4533 (< (- (point) p) 80)))
4534 (zerop (forward-line 1))))
4538 "You have lines longer than 79 characters. Really post? ")))
4539 ;; Check whether the article is empty.
4540 (message-check 'empty
4541 (goto-char (point-min))
4543 (concat "^" (regexp-quote mail-header-separator) "$"))
4546 (goto-char (point-max))
4547 (re-search-backward message-signature-separator nil t)
4549 (or (re-search-backward "[^ \n\t]" b t)
4550 (if (message-gnksa-enable-p 'empty-article)
4551 (y-or-n-p "Empty article. Really post? ")
4552 (message "Denied posting -- Empty article.")
4554 ;; Check for control characters.
4555 (message-check 'control-chars
4556 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
4558 "The article contains control characters. Really post? ")
4560 ;; Check 8bit characters.
4561 (message-check '8bit
4562 (message-check-8bit))
4563 ;; Check excessive size.
4564 (message-check 'size
4565 (if (> (buffer-size) 60000)
4567 (format "The article is %d octets long. Really post? "
4570 ;; Check whether any new text has been added.
4571 (message-check 'new-text
4573 (not message-checksum)
4574 (not (eq (message-checksum) message-checksum))
4575 (if (message-gnksa-enable-p 'quoted-text-only)
4577 "It looks like no new text has been added. Really post? ")
4578 (message "Denied posting -- no new text has been added.")
4580 ;; Check the length of the signature.
4581 (message-check 'signature
4582 (goto-char (point-max))
4583 (if (> (count-lines (point) (point-max)) 5)
4586 "Your .sig is %d lines; it should be max 4. Really post? "
4587 (1- (count-lines (point) (point-max)))))
4589 ;; Ensure that text follows last quoted portion.
4590 (message-check 'quoting-style
4591 (goto-char (point-max))
4592 (let ((no-problem t))
4593 (when (search-backward-regexp "^>[^\n]*\n" nil t)
4594 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
4597 (if (message-gnksa-enable-p 'quoted-text-only)
4598 (y-or-n-p "Your text should follow quoted text. Really post? ")
4600 (goto-char (point-min))
4602 (concat "^" (regexp-quote mail-header-separator) "$"))
4603 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
4604 (y-or-n-p "Your text should follow quoted text. Really post? ")
4605 (message "Denied posting -- only quoted text.")
4608 (defun message-check-mail-syntax ()
4609 "Check the syntax of the message."
4614 ;; We narrow to the headers and check them first.
4617 (message-narrow-to-headers)
4618 (message-check-mail-header-syntax)))
4621 (set-buffer message-edit-buffer)
4622 (message-check-mail-body-syntax))))))
4624 (defun message-check-mail-header-syntax ()
4627 (defun message-check-mail-body-syntax ()
4629 ;; Check 8bit characters.
4630 (message-check '8bit
4631 (message-check-8bit)
4634 (defun message-check-8bit ()
4635 "Check the article contains 8bit characters."
4637 (set-buffer message-encoding-buffer)
4638 (message-narrow-to-headers)
4639 (let* ((case-fold-search t)
4640 (field-value (message-fetch-field "content-transfer-encoding")))
4641 (if (and field-value
4642 (member (downcase field-value) message-8bit-encoding-list))
4645 (set-buffer (get-buffer-create " message syntax"))
4647 (goto-char (point-min))
4648 (set-buffer-multibyte nil)
4649 (insert-buffer-substring message-encoding-buffer)
4650 (goto-char (point-min))
4651 (if (re-search-forward "[^\x00-\x7f]" nil t)
4653 "The article contains 8bit characters. Really post? ")
4656 (defun message-checksum ()
4657 "Return a \"checksum\" for the current buffer."
4660 (goto-char (point-min))
4662 (concat "^" (regexp-quote mail-header-separator) "$"))
4664 (when (not (looking-at "[ \t\n]"))
4665 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
4670 (defun message-do-fcc ()
4671 "Process Fcc headers in the current buffer."
4672 (let ((case-fold-search t)
4673 (coding-system-for-write 'raw-text)
4674 (output-coding-system 'raw-text)
4676 (mml-externalize-attachments message-fcc-externalize-attachments))
4679 (message-narrow-to-headers)
4680 (setq file (message-fetch-field "fcc" t)))
4682 (set-buffer (get-buffer-create " *message temp*"))
4684 (insert-buffer-substring message-encoding-buffer)
4686 (message-narrow-to-headers)
4687 (while (setq file (message-fetch-field "fcc"))
4689 (message-remove-header "fcc" nil t)))
4690 (goto-char (point-min))
4691 (when (re-search-forward
4692 (concat "^" (regexp-quote mail-header-separator) "$")
4694 (replace-match "" t t))
4695 ;; Process FCC operations.
4697 (setq file (pop list))
4698 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
4699 ;; Pipe the article to the program in question.
4700 (call-process-region (point-min) (point-max) shell-file-name
4701 nil nil nil shell-command-switch
4702 (match-string 1 file))
4703 ;; Save the article.
4704 (setq file (expand-file-name file))
4705 (unless (file-exists-p (file-name-directory file))
4706 (make-directory (file-name-directory file) t))
4707 (if (and message-fcc-handler-function
4708 (not (eq message-fcc-handler-function 'rmail-output)))
4709 (funcall message-fcc-handler-function file)
4710 (if (and (file-readable-p file) (mail-file-babyl-p file))
4711 (rmail-output file 1 nil t)
4712 (let ((mail-use-rfc822 t))
4713 (rmail-output file 1 t t))))))
4714 (kill-buffer (current-buffer))))))
4716 (defun message-output (filename)
4717 "Append this article to Unix/babyl mail file FILENAME."
4718 (if (and (file-readable-p filename)
4719 (mail-file-babyl-p filename))
4720 (gnus-output-to-rmail filename t)
4721 (gnus-output-to-mail filename t)))
4723 (defun message-cleanup-headers ()
4724 "Do various automatic cleanups of the headers."
4725 ;; Remove empty lines in the header.
4727 (message-narrow-to-headers)
4728 ;; Remove blank lines.
4729 (while (re-search-forward "^[ \t]*\n" nil t)
4730 (replace-match "" t t))
4732 ;; Correct Newsgroups and Followup-To headers: Change sequence of
4733 ;; spaces to comma and eliminate spaces around commas. Eliminate
4734 ;; embedded line breaks.
4735 (goto-char (point-min))
4736 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
4740 (if (re-search-forward "^[^ \t]" nil t)
4744 (goto-char (point-min))
4745 (while (re-search-forward "\n[ \t]+" nil t)
4746 (replace-match " " t t)) ;No line breaks (too confusing)
4747 (goto-char (point-min))
4748 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
4749 (replace-match "," t t))
4750 (goto-char (point-min))
4751 ;; Remove trailing commas.
4752 (when (re-search-forward ",+$" nil t)
4753 (replace-match "" t t))))))
4755 (defun message-make-date (&optional now)
4756 "Make a valid data header.
4757 If NOW, use that time instead."
4758 (let* ((now (or now (current-time)))
4759 (zone (nth 8 (decode-time now)))
4763 (setq zone (- zone)))
4765 ;; The day name of the %a spec is locale-specific. Pfff.
4766 (format "%s, " (capitalize (car (rassoc (nth 6 (decode-time now))
4767 parse-time-weekdays))))
4768 (format-time-string "%d" now)
4769 ;; The month name of the %b spec is locale-specific. Pfff.
4771 (capitalize (car (rassoc (nth 4 (decode-time now))
4772 parse-time-months))))
4773 (format-time-string "%Y %H:%M:%S " now)
4774 ;; We do all of this because XEmacs doesn't have the %z spec.
4775 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
4777 (defun message-make-followup-subject (subject)
4778 "Make a followup Subject."
4780 ((and (eq message-use-subject-re 'guess)
4781 (string-match message-subject-encoded-re-regexp subject))
4783 (message-use-subject-re
4784 (concat "Re: " (message-strip-subject-re subject)))
4787 (defun message-make-message-id ()
4788 "Make a unique Message-ID."
4789 (concat "<" (message-unique-id)
4790 (let ((psubject (save-excursion (message-fetch-field "subject")))
4792 (save-excursion (message-fetch-field "supersedes"))))
4794 (and message-reply-headers
4795 (mail-header-references message-reply-headers)
4796 (mail-header-subject message-reply-headers)
4799 (message-strip-subject-re
4800 (mail-header-subject message-reply-headers))
4801 (message-strip-subject-re psubject))))
4803 (string-match "_-_@" psupersedes)))
4805 "@" (message-make-fqdn) ">"))
4807 (defvar message-unique-id-char nil)
4809 ;; If you ever change this function, make sure the new version
4810 ;; cannot generate IDs that the old version could.
4811 ;; You might for example insert a "." somewhere (not next to another dot
4812 ;; or string boundary), or modify the "fsf" string.
4813 (defun message-unique-id ()
4814 ;; Don't use microseconds from (current-time), they may be unsupported.
4815 ;; Instead we use this randomly inited counter.
4816 (setq message-unique-id-char
4817 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
4818 ;; (current-time) returns 16-bit ints,
4819 ;; and 2^16*25 just fits into 4 digits i base 36.
4821 (let ((tm (current-time)))
4823 (if (memq system-type '(ms-dos emx vax-vms))
4824 (let ((user (downcase (user-login-name))))
4825 (while (string-match "[^a-z0-9_]" user)
4826 (aset user (match-beginning 0) ?_))
4828 (message-number-base36 (user-uid) -1))
4829 (message-number-base36 (+ (car tm)
4830 (lsh (% message-unique-id-char 25) 16)) 4)
4831 (message-number-base36 (+ (nth 1 tm)
4832 (lsh (/ message-unique-id-char 25) 16)) 4)
4833 ;; Append the newsreader name, because while the generated
4834 ;; ID is unique to this newsreader, other newsreaders might
4835 ;; otherwise generate the same ID via another algorithm.
4838 (defun message-number-base36 (num len)
4843 (concat (message-number-base36 (/ num 36) (1- len))
4844 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
4847 (defun message-make-organization ()
4848 "Make an Organization header."
4849 (let* ((organization
4850 (when message-user-organization
4851 (if (message-functionp message-user-organization)
4852 (funcall message-user-organization)
4853 message-user-organization))))
4855 (message-set-work-buffer)
4856 (cond ((stringp organization)
4857 (insert organization))
4858 ((and (eq t organization)
4859 message-user-organization-file
4860 (file-exists-p message-user-organization-file))
4861 (insert-file-contents message-user-organization-file)))
4862 (goto-char (point-min))
4863 (while (re-search-forward "[\t\n]+" nil t)
4864 (replace-match "" t t))
4865 (unless (zerop (buffer-size))
4868 (defun message-make-lines ()
4869 "Count the number of lines and return numeric string."
4874 (int-to-string (count-lines (point) (point-max))))))
4876 (defun message-make-references ()
4877 "Return the References header for this message."
4878 (when message-reply-headers
4879 (let ((message-id (mail-header-message-id message-reply-headers))
4880 (references (mail-header-references message-reply-headers))
4882 (if (or references message-id)
4883 (concat (or references "") (and references " ")
4887 (defun message-make-in-reply-to ()
4888 "Return the In-Reply-To header for this message."
4889 (when message-reply-headers
4890 (let ((from (mail-header-from message-reply-headers))
4891 (date (mail-header-date message-reply-headers))
4892 (msg-id (mail-header-message-id message-reply-headers)))
4896 (let ((pair (std11-extract-address-components from)))
4898 (or (car pair) (cadr pair))
4900 (if (or (not date) (string= date ""))
4901 "(unknown date)" date)
4904 (defun message-make-distribution ()
4905 "Make a Distribution header."
4906 (let ((orig-distribution (message-fetch-reply-field "distribution")))
4907 (cond ((message-functionp message-distribution-function)
4908 (funcall message-distribution-function))
4909 (t orig-distribution))))
4911 (defun message-make-expires ()
4912 "Return an Expires header based on `message-expires'."
4913 (let ((current (current-time))
4914 (future (* 1.0 message-expires 60 60 24)))
4915 ;; Add the future to current.
4916 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
4917 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
4918 (message-make-date current)))
4920 (defun message-make-path ()
4922 (let ((login-name (user-login-name)))
4923 (cond ((null message-user-path)
4924 (concat (system-name) "!" login-name))
4925 ((stringp message-user-path)
4926 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
4927 (concat message-user-path "!" login-name))
4930 (defun message-make-from ()
4931 "Make a From header."
4932 (let* ((style message-from-style)
4933 (login (message-make-address))
4935 (or (and (boundp 'user-full-name)
4938 (when (string= fullname "&")
4939 (setq fullname (user-login-name)))
4941 (message-set-work-buffer)
4944 (equal fullname ""))
4946 ((or (eq style 'angles)
4947 (and (not (eq style 'parens))
4948 ;; Use angles if no quoting is needed, or if parens would
4949 ;; need quoting too.
4950 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
4951 (let ((tmp (concat fullname nil)))
4952 (while (string-match "([^()]*)" tmp)
4953 (aset tmp (match-beginning 0) ?-)
4954 (aset tmp (1- (match-end 0)) ?-))
4955 (string-match "[\\()]" tmp)))))
4957 (insert " <" login ">"))
4958 (t ; 'parens or default
4960 (let ((fullname-start (point)))
4962 (goto-char fullname-start)
4963 ;; RFC 822 says \ and nonmatching parentheses
4964 ;; must be escaped in comments.
4965 ;; Escape every instance of ()\ ...
4966 (while (re-search-forward "[()\\]" nil 1)
4967 (replace-match "\\\\\\&" t))
4968 ;; ... then undo escaping of matching parentheses,
4969 ;; including matching nested parentheses.
4970 (goto-char fullname-start)
4971 (while (re-search-forward
4972 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
4974 (replace-match "\\1(\\3)" t)
4975 (goto-char fullname-start)))
4979 (defun message-make-sender ()
4980 "Return the \"real\" user address.
4981 This function tries to ignore all user modifications, and
4982 give as trustworthy answer as possible."
4983 (concat (user-login-name) "@" (system-name)))
4985 (defun message-make-address ()
4986 "Make the address of the user."
4987 (or (message-user-mail-address)
4988 (concat (user-login-name) "@" (message-make-domain))))
4990 (defun message-user-mail-address ()
4991 "Return the pertinent part of `user-mail-address'."
4992 (when user-mail-address
4993 (if (string-match " " user-mail-address)
4994 (nth 1 (std11-extract-address-components user-mail-address))
4995 user-mail-address)))
4997 (defun message-make-fqdn ()
4998 "Return user's fully qualified domain name."
4999 (let ((system-name (system-name))
5000 (user-mail (message-user-mail-address)))
5002 ((and (string-match "[^.]\\.[^.]" system-name)
5003 (not (string-match message-bogus-system-names system-name)))
5004 ;; `system-name' returned the right result.
5006 ;; Try `mail-host-address'.
5007 ((and (boundp 'mail-host-address)
5008 (stringp mail-host-address)
5009 (string-match "\\." mail-host-address))
5011 ;; We try `user-mail-address' as a backup.
5013 (string-match "\\." user-mail)
5014 (string-match "@\\(.*\\)\\'" user-mail))
5015 (match-string 1 user-mail))
5016 ;; Default to this bogus thing.
5018 (concat system-name ".i-did-not-set--mail-host-address--so-tickle-me")))))
5020 (defun message-make-host-name ()
5021 "Return the name of the host."
5022 (let ((fqdn (message-make-fqdn)))
5023 (string-match "^[^.]+\\." fqdn)
5024 (substring fqdn 0 (1- (match-end 0)))))
5026 (defun message-make-domain ()
5027 "Return the domain name."
5028 (or mail-host-address
5029 (message-make-fqdn)))
5031 (defun message-to-list-only ()
5032 "Send a message to the list only.
5033 Remove all addresses but the list address from To and Cc headers."
5035 (let ((listaddr (message-make-mft t)))
5038 (message-remove-header "to")
5039 (message-remove-header "cc")
5040 (message-position-on-field "To" "X-Draft-From")
5041 (insert listaddr)))))
5043 (defun message-make-mft (&optional only-show-subscribed)
5044 "Return the Mail-Followup-To header. If passed the optional
5045 argument `only-show-subscribed' only return the subscribed address (and
5046 not the additional To and Cc header contents)."
5047 (let* ((case-fold-search t)
5048 (to (message-fetch-field "To"))
5049 (cc (message-fetch-field "cc"))
5050 (msg-recipients (concat to (and to cc ", ") cc))
5052 (mapcar 'mail-strip-quoted-names
5053 (message-tokenize-header msg-recipients)))
5055 (if message-subscribed-address-file
5056 (let (begin end item re)
5059 (insert-file-contents message-subscribed-address-file)
5061 (setq begin (point))
5064 (if (bolp) (setq end (1- end)))
5065 (setq item (regexp-quote (buffer-substring begin end)))
5066 (if re (setq re (concat re "\\|" item))
5067 (setq re (concat "\\`\\(" item))))
5068 (and re (list (concat re "\\)\\'"))))))))
5069 (mft-regexps (apply 'append message-subscribed-regexps
5070 (mapcar 'regexp-quote
5071 message-subscribed-addresses)
5074 message-subscribed-address-functions))))
5076 (let ((subscribed-lists nil)
5078 (loop for recipient in recipients
5079 when (loop for regexp in mft-regexps
5080 when (string-match regexp recipient) return t)
5083 (if only-show-subscribed
5085 msg-recipients))))))
5087 ;; Dummy to avoid byte-compile warning.
5088 (defvar mule-version)
5089 (defvar emacs-beta-version)
5090 (defvar xemacs-codename)
5091 (defvar gnus-inviolable-extended-version)
5093 (defun message-make-user-agent ()
5094 "Return user-agent info if the value `message-user-agent' is non-nil. If the
5095 \"User-Agent\" field has already exist, it's value will be added in the return
5097 (when message-user-agent
5099 (goto-char (point-min))
5100 (let ((case-fold-search t)
5101 user-agent start p end)
5102 (if (re-search-forward
5103 (concat "^User-Agent:[\t ]*\\("
5104 (regexp-quote gnus-product-name)
5105 "/[0-9.]+\\([ \t\r\n]*([^)]+)\\)*\\)?[\t ]*")
5108 (setq start (match-beginning 0)
5110 end (std11-field-end)
5111 user-agent (buffer-substring-no-properties p end))
5112 (delete-region start (1+ end))
5113 (concat message-user-agent " " user-agent))
5114 message-user-agent)))))
5116 (defun message-generate-headers (headers)
5117 "Prepare article HEADERS.
5118 Headers already prepared in the buffer are not modified."
5120 (message-narrow-to-headers)
5121 (let* ((Date (message-make-date))
5122 (Message-ID (message-make-message-id))
5123 (Organization (message-make-organization))
5124 (From (message-make-from))
5125 (Path (message-make-path))
5128 (In-Reply-To (message-make-in-reply-to))
5129 (References (message-make-references))
5131 (Distribution (message-make-distribution))
5132 (Lines (message-make-lines))
5133 (User-Agent (message-make-user-agent))
5134 (Expires (message-make-expires))
5135 (case-fold-search t)
5137 ;; First we remove any old generated headers.
5138 (let ((headers message-deletable-headers))
5139 (unless (buffer-modified-p)
5140 (setq headers (delq 'Message-ID (copy-sequence headers))))
5142 (goto-char (point-min))
5143 (and (re-search-forward
5144 (concat "^" (symbol-name (car headers)) ": *") nil t)
5145 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
5146 (message-delete-line))
5148 ;; Go through all the required headers and see if they are in the
5149 ;; articles already. If they are not, or are empty, they are
5150 ;; inserted automatically - except for Subject, Newsgroups and
5153 (goto-char (point-min))
5154 (setq elem (pop headers))
5156 (if (eq (car elem) 'optional)
5157 (setq header (cdr elem))
5158 (setq header (car elem)))
5160 (when (or (not (re-search-forward
5164 (if (stringp header)
5166 (symbol-name header))))
5170 ;; The header was found. We insert a space after the
5171 ;; colon, if there is none.
5172 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
5173 ;; Find out whether the header is empty...
5174 (looking-at "[ \t]*\n[^ \t]")))
5175 ;; So we find out what value we should insert.
5178 ((and (consp elem) (eq (car elem) 'optional))
5179 ;; This is an optional header. If the cdr of this
5180 ;; is something that is nil, then we do not insert
5182 (setq header (cdr elem))
5183 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
5184 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
5186 ;; The element is a cons. Either the cdr is a
5187 ;; string to be inserted verbatim, or it is a
5188 ;; function, and we insert the value returned from
5190 (or (and (stringp (cdr elem)) (cdr elem))
5191 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
5192 ((and (boundp header) (symbol-value header))
5193 ;; The element is a symbol. We insert the value
5194 ;; of this symbol, if any.
5195 (symbol-value header))
5196 ((not (message-check-element header))
5197 ;; We couldn't generate a value for this header,
5198 ;; so we just ask the user.
5199 (read-from-minibuffer
5200 (format "Empty header for %s; enter value: " header)))))
5201 ;; Finally insert the header.
5203 (not (equal value "")))
5207 ;; This header didn't exist, so we insert it.
5208 (goto-char (point-max))
5209 (insert (if (stringp header) header (symbol-name header))
5211 ;; We check whether the value was ended by a
5212 ;; newline. If now, we insert one.
5216 ;; The value of this header was empty, so we clear
5217 ;; totally and insert the new value.
5218 (delete-region (point) (gnus-point-at-eol))
5222 ;; Add the deletable property to the headers that require it.
5223 (and (memq header message-deletable-headers)
5224 (progn (beginning-of-line) (looking-at "[^:]+: "))
5225 (add-text-properties
5226 (point) (match-end 0)
5227 '(message-deletable t face italic) (current-buffer)))))))
5228 ;; Insert new Sender if the From is strange.
5229 (let ((from (message-fetch-field "from"))
5230 (sender (message-fetch-field "sender"))
5231 (secure-sender (message-make-sender)))
5233 (not (message-check-element 'sender))
5236 (cadr (std11-extract-address-components from)))
5237 (downcase secure-sender)))
5242 (cadr (std11-extract-address-components sender)))
5243 (downcase secure-sender)))))
5244 (goto-char (point-min))
5245 ;; Rename any old Sender headers to Original-Sender.
5246 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
5248 (insert "Original-")
5249 (beginning-of-line))
5250 (when (or (message-news-p)
5251 (string-match "@.+\\.." secure-sender))
5252 (insert "Sender: " secure-sender "\n")))))))
5254 (defun message-insert-courtesy-copy ()
5255 "Insert a courtesy message in mail copies of combined messages."
5259 (message-narrow-to-headers)
5260 (when (setq newsgroups (message-fetch-field "newsgroups"))
5261 (goto-char (point-max))
5262 (insert "Posted-To: " newsgroups "\n")))
5264 (when message-courtesy-message
5266 ((string-match "%s" message-courtesy-message)
5267 (insert (format message-courtesy-message newsgroups)))
5269 (insert message-courtesy-message)))))))
5272 ;;; Setting up a message buffer
5275 (defun message-fill-address (header value)
5277 (narrow-to-region (point) (point))
5278 (insert (capitalize (symbol-name header))
5280 (if (consp value) (car value) value)
5282 (narrow-to-region (point-min) (1- (point-max)))
5284 (goto-char (point-min))
5286 (skip-chars-forward "^,\"" (point-max))
5287 (if (or (eq (char-after) ?,)
5290 (if (and (> (current-column) 78)
5294 (looking-at "[ \t]*")
5295 (replace-match "\n " t t)))
5296 (setq last (1+ (point))))
5297 (setq quoted (not quoted)))
5300 (goto-char (point-max))
5304 (defun message-fill-references (header value)
5305 (insert (capitalize (symbol-name header))
5307 (std11-fill-msg-id-list-string
5308 (if (consp value) (car value) value))
5311 (defun message-fill-header (header value)
5312 (let ((begin (point))
5315 (insert (capitalize (symbol-name header))
5317 (if (consp value) (car value) value)
5320 (narrow-to-region begin (point))
5321 (fill-region-as-paragraph begin (point))
5322 ;; Tapdance around looong Message-IDs.
5324 (when (looking-at "[ \t]*$")
5325 (message-delete-line))
5327 (re-search-forward ":" nil t)
5328 (when (looking-at "\n[ \t]+")
5329 (replace-match " " t t))
5330 (goto-char (point-max)))))
5332 (defun message-shorten-1 (list cut surplus)
5333 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
5334 (setcdr (nthcdr (- cut 2) list)
5335 (nthcdr (+ (- cut 2) surplus 1) list)))
5337 (defun message-shorten-references (header references)
5338 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
5339 If folding is disallowed, also check that the REFERENCES are less
5340 than 988 characters long, and if they are not, trim them until they are."
5347 (goto-char (point-min))
5348 ;; Cons a list of valid references.
5349 (while (re-search-forward "<[^>]+>" nil t)
5350 (push (match-string 0) refs))
5351 (setq refs (nreverse refs)
5352 count (length refs)))
5354 ;; If the list has more than MAXCOUNT elements, trim it by
5355 ;; removing the CUTth element and the required number of
5356 ;; elements that follow.
5357 (when (> count maxcount)
5358 (let ((surplus (- count maxcount)))
5359 (message-shorten-1 refs cut surplus)
5360 (decf count surplus)))
5362 ;; If folding is disallowed, make sure the total length (including
5363 ;; the spaces between) will be less than MAXSIZE characters.
5365 ;; Only disallow folding for News messages. At this point the headers
5366 ;; have not been generated, thus we use message-this-is-news directly.
5367 (when (and message-this-is-news message-cater-to-broken-inn)
5369 (totalsize (+ (apply #'+ (mapcar #'length refs))
5372 (ptr (nthcdr (1- cut) refs)))
5373 ;; Decide how many elements to cut off...
5374 (while (> totalsize maxsize)
5375 (decf totalsize (1+ (length (car ptr))))
5377 (setq ptr (cdr ptr)))
5380 (message-shorten-1 refs cut surplus))))
5382 ;; Finally, collect the references back into a string and insert
5383 ;; it into the buffer.
5384 (let ((refstring (mapconcat #'identity refs " ")))
5385 (if (and message-this-is-news message-cater-to-broken-inn)
5386 (insert (capitalize (symbol-name header)) ": "
5388 (message-fill-header header refstring)))))
5390 (defun message-position-point ()
5391 "Move point to where the user probably wants to find it."
5392 (message-narrow-to-headers)
5394 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
5395 (search-backward ":" )
5398 (if (eq (char-after) ? )
5402 (goto-char (point-max))
5405 (unless (looking-at "$")
5409 (defcustom message-beginning-of-line t
5410 "Whether C-a goes to beginning of header values."
5411 :group 'message-buffers
5414 (defun message-beginning-of-line (&optional n)
5415 "Move point to beginning of header value or to beginning of line."
5417 (let ((zrs 'zmacs-region-stays))
5418 (when (and (interactive-p) (boundp zrs))
5420 (if (and message-beginning-of-line
5421 (message-point-in-header-p))
5422 (let* ((here (point))
5423 (bol (progn (beginning-of-line n) (point)))
5424 (eol (gnus-point-at-eol))
5425 (eoh (re-search-forward ": *" eol t)))
5426 (if (or (not eoh) (equal here eoh))
5429 (beginning-of-line n)))
5431 (defun message-buffer-name (type &optional to group)
5432 "Return a new (unique) buffer name based on TYPE and TO."
5434 ;; Generate a new buffer name The Message Way.
5435 ((eq message-generate-new-buffers 'unique)
5436 (generate-new-buffer-name
5440 (or (car (std11-extract-address-components to))
5443 (if (and group (not (string= group ""))) (concat " on " group) "")
5445 ;; Check whether `message-generate-new-buffers' is a function,
5446 ;; and if so, call it.
5447 ((message-functionp message-generate-new-buffers)
5448 (funcall message-generate-new-buffers type to group))
5449 ((eq message-generate-new-buffers 'unsent)
5450 (generate-new-buffer-name
5451 (concat "*unsent " type
5454 (or (car (mail-extract-address-components to))
5457 (if (and group (not (string= group ""))) (concat " on " group) "")
5459 ;; Use standard name.
5461 (format "*%s message*" type))))
5463 (defmacro message-pop-to-buffer-1 (buffer)
5465 (let (special-display-buffer-names
5466 special-display-regexps
5467 same-window-buffer-names
5468 same-window-regexps)
5469 (pop-to-buffer ,buffer))
5470 (pop-to-buffer ,buffer)))
5472 (defun message-pop-to-buffer (name)
5473 "Pop to buffer NAME, and warn if it already exists and is modified."
5474 (let ((buffer (get-buffer name))
5475 (pop-up-frames (and (or (static-if (featurep 'xemacs)
5476 (device-on-window-system-p)
5478 (>= emacs-major-version 20))
5479 message-use-multi-frames)))
5481 (buffer-name buffer))
5483 (message-pop-to-buffer-1 buffer)
5484 (when (and (buffer-modified-p)
5486 "Message already being composed; erase? ")))
5487 (error "Message being composed")))
5488 (message-pop-to-buffer-1 name))
5492 (set (make-local-variable 'message-original-frame) (selected-frame)))))
5494 (defun message-do-send-housekeeping ()
5495 "Kill old message buffers."
5496 ;; We might have sent this buffer already. Delete it from the
5498 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
5499 (while (and message-max-buffers
5501 (>= (length message-buffer-list) message-max-buffers))
5502 ;; Kill the oldest buffer -- unless it has been changed.
5503 (let ((buffer (pop message-buffer-list)))
5504 (when (and (buffer-name buffer)
5505 (not (buffer-modified-p buffer)))
5506 (kill-buffer buffer))))
5507 ;; Rename the buffer.
5508 (if message-send-rename-function
5509 (funcall message-send-rename-function)
5510 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
5512 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
5514 (let ((name (match-string 2 (buffer-name)))
5516 (if (not (or (null name)
5517 (string-equal name "mail")
5518 (string-equal name "posting")))
5519 (setq name (concat "*sent " name "*"))
5520 (message-narrow-to-headers)
5521 (setq to (message-fetch-field "to"))
5522 (setq group (message-fetch-field "newsgroups"))
5526 (to (concat "*sent mail to "
5527 (or (car (mail-extract-address-components to))
5529 ((and group (not (string= group "")))
5530 (concat "*sent posting on " group "*"))
5531 (t "*sent mail*"))))
5532 (unless (string-equal name (buffer-name))
5533 (rename-buffer name t)))))
5534 ;; Push the current buffer onto the list.
5535 (when message-max-buffers
5536 (setq message-buffer-list
5537 (nconc message-buffer-list (list (current-buffer))))))
5539 (defun message-mail-user-agent ()
5541 ((not message-mail-user-agent) nil)
5542 ((eq message-mail-user-agent t) mail-user-agent)
5543 (t message-mail-user-agent))))
5544 (if (memq mua '(message-user-agent gnus-user-agent))
5548 (defun message-setup (headers &optional replybuffer actions switch-function)
5549 (let ((mua (message-mail-user-agent))
5550 subject to field yank-action)
5551 (if (not (and message-this-is-mail mua))
5552 (message-setup-1 headers replybuffer actions)
5554 (setq yank-action (list 'insert-buffer replybuffer)))
5555 (setq headers (copy-sequence headers))
5556 (setq field (assq 'Subject headers))
5558 (setq subject (cdr field))
5559 (setq headers (delq field headers)))
5560 (setq field (assq 'To headers))
5562 (setq to (cdr field))
5563 (setq headers (delq field headers)))
5564 (let ((mail-user-agent mua))
5565 (compose-mail to subject
5566 (mapcar (lambda (item)
5568 (format "%s" (car item))
5571 nil switch-function yank-action actions)))))
5573 (defun message-setup-1 (headers &optional replybuffer actions)
5574 (dolist (action actions)
5576 (add-to-list 'message-send-actions
5577 `(apply ',(car action) ',(cdr action)))))
5578 (setq message-reply-buffer
5579 (or (message-get-parameter 'reply-buffer)
5581 (goto-char (point-min))
5582 ;; Insert all the headers.
5585 (alist message-header-format-alist))
5587 (unless (assq (caar h) message-header-format-alist)
5588 (push (list (caar h)) alist))
5592 (delete-region (point) (progn (forward-line -1) (point)))
5593 (when message-default-headers
5594 (insert message-default-headers)
5595 (or (bolp) (insert ?\n)))
5599 (insert mail-header-separator "\n")
5603 (when (message-news-p)
5604 (when message-default-news-headers
5605 (insert message-default-news-headers)
5606 (or (bolp) (insert ?\n)))
5607 (when message-generate-headers-first
5608 (message-generate-headers
5611 (copy-sequence message-required-news-headers))))))
5612 (when (message-mail-p)
5613 (when message-default-mail-headers
5614 (insert message-default-mail-headers)
5615 (or (bolp) (insert ?\n)))
5616 (when message-generate-headers-first
5617 (message-generate-headers
5620 (copy-sequence message-required-mail-headers))))))
5621 (run-hooks 'message-signature-setup-hook)
5622 (message-insert-signature)
5624 (message-narrow-to-headers)
5625 (if message-alternative-emails
5626 (message-use-alternative-email-as-from))
5627 (run-hooks 'message-header-setup-hook))
5628 (set-buffer-modified-p nil)
5629 (setq buffer-undo-list nil)
5630 (run-hooks 'message-setup-hook)
5631 (message-position-point)
5634 (defun message-set-auto-save-file-name ()
5635 "Associate the message buffer with a file in the drafts directory."
5636 (when message-auto-save-directory
5637 (unless (file-directory-p
5638 (directory-file-name message-auto-save-directory))
5639 (make-directory message-auto-save-directory t))
5641 (setq message-draft-article
5642 (nndraft-request-associate-buffer "drafts"))
5643 (setq buffer-file-name (expand-file-name
5644 (if (memq system-type
5645 '(ms-dos ms-windows windows-nt
5646 cygwin cygwin32 win32 w32
5650 message-auto-save-directory))
5651 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
5652 (clear-visited-file-modtime)
5653 (static-if (boundp 'MULE)
5654 (set-file-coding-system message-draft-coding-system)
5655 (setq buffer-file-coding-system message-draft-coding-system))))
5657 (defun message-disassociate-draft ()
5658 "Disassociate the message buffer from the drafts directory."
5659 (when message-draft-article
5660 (nndraft-request-expire-articles
5661 (list message-draft-article) "drafts" nil t)))
5663 (defun message-insert-headers ()
5664 "Generate the headers for the article."
5668 (message-narrow-to-headers)
5669 (when (message-news-p)
5670 (message-generate-headers
5673 (copy-sequence message-required-news-headers)))))
5674 (when (message-mail-p)
5675 (message-generate-headers
5678 (copy-sequence message-required-mail-headers))))))))
5683 ;;; Commands for interfacing with message
5687 (defun message-mail (&optional to subject
5688 other-headers continue switch-function
5689 yank-action send-actions)
5690 "Start editing a mail message to be sent.
5691 OTHER-HEADERS is an alist of header/value pairs."
5693 (let ((message-this-is-mail t) replybuffer)
5694 (unless (message-mail-user-agent)
5695 (message-pop-to-buffer (message-buffer-name "mail" to)))
5696 ;; FIXME: message-mail should do something if YANK-ACTION is not
5698 (and (consp yank-action) (eq (car yank-action) 'insert-buffer)
5699 (setq replybuffer (nth 1 yank-action)))
5702 `((To . ,(or to "")) (Subject . ,(or subject "")))
5703 (when other-headers other-headers))
5704 replybuffer send-actions)
5705 ;; FIXME: Should return nil if failure.
5709 (defun message-news (&optional newsgroups subject)
5710 "Start editing a news article to be sent."
5712 (let ((message-this-is-news t))
5713 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
5714 (message-setup `((Newsgroups . ,(or newsgroups ""))
5715 (Subject . ,(or subject ""))))))
5717 (defun message-get-reply-headers (wide &optional to-address address-headers)
5718 (let (follow-to mct never-mct to cc author mft recipients)
5719 ;; Find all relevant headers we need.
5720 (let ((mrt (when message-use-mail-reply-to
5721 (message-fetch-field "mail-reply-to")))
5722 (reply-to (message-fetch-field "reply-to")))
5723 (setq to (message-fetch-field "to")
5724 cc (message-fetch-field "cc")
5725 mct (when message-use-mail-copies-to
5726 (message-fetch-field "mail-copies-to"))
5729 (message-fetch-field "from")
5731 mft (when (and (not (or to-address mrt reply-to))
5732 message-use-mail-followup-to)
5733 (message-fetch-field "mail-followup-to"))))
5736 ;; Handle special values of Mail-Copies-To.
5738 (cond ((or (equal (downcase mct) "never")
5739 (equal (downcase mct) "nobody"))
5740 (when (or (not (eq message-use-mail-copies-to 'ask))
5742 (concat "Obey Mail-Copies-To: never? ") t "\
5743 You should normally obey the Mail-Copies-To: header.
5745 `Mail-Copies-To: " mct "'
5746 directs you not to send your response to the author."))
5749 ((or (equal (downcase mct) "always")
5750 (equal (downcase mct) "poster"))
5751 (if (or (not (eq message-use-mail-copies-to 'ask))
5753 (concat "Obey Mail-Copies-To: always? ") t "\
5754 You should normally obey the Mail-Copies-To: header.
5756 `Mail-Copies-To: " mct "'
5757 sends a copy of your response to the author."))
5760 ((and (eq message-use-mail-copies-to 'ask)
5761 (not (message-y-or-n-p
5762 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
5763 You should normally obey the Mail-Copies-To: header.
5765 `Mail-Copies-To: " mct "'
5766 sends a copy of your response to " (if (string-match "," mct)
5767 "the specified addresses"
5768 "that address") ".")))
5771 ;; Build (textual) list of new recipient addresses.
5774 (setq recipients (concat ", " author)))
5776 (dolist (header address-headers)
5777 (let ((value (message-fetch-field header)))
5779 (setq recipients (concat recipients ", " value))))))
5781 (string-match "[^ \t,]" mft)
5782 (or (not (eq message-use-mail-followup-to 'ask))
5783 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
5784 You should normally obey the Mail-Followup-To: header. In this
5785 article, it has the value of
5789 which directs your response to " (if (string-match "," mft)
5790 "the specified addresses"
5791 "that address only") ".
5793 Most commonly, Mail-Followup-To is used by a mailing list poster to
5794 express that responses should be sent to just the list, and not the
5797 If a message is posted to several mailing lists, Mail-Followup-To may
5798 also be used to direct the following discussion to one list only,
5799 because discussions that are spread over several lists tend to be
5800 fragmented and very difficult to follow.
5802 Also, some source/announcement lists are not intended for discussion;
5803 responses here are directed to other addresses.")))
5804 (setq recipients (concat ", " mft)))
5806 (setq recipients (concat ", " to-address))
5807 ;; If the author explicitly asked for a copy, we don't deny it to them.
5808 (if mct (setq recipients (concat recipients ", " mct))))
5810 (setq recipients (if never-mct "" (concat ", " author)))
5811 (if to (setq recipients (concat recipients ", " to)))
5812 (if cc (setq recipients (concat recipients ", " cc)))
5813 (if mct (setq recipients (concat recipients ", " mct)))))
5814 (if (>= (length recipients) 2)
5815 ;; Strip the leading ", ".
5816 (setq recipients (substring recipients 2)))
5817 ;; Squeeze whitespace.
5818 (while (string-match "[ \t][ \t]+" recipients)
5819 (setq recipients (replace-match " " t t recipients)))
5820 ;; Remove addresses that match `rmail-dont-reply-to-names'.
5821 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
5822 (setq recipients (rmail-dont-reply-to recipients)))
5823 ;; Perhaps "Mail-Copies-To: never" removed the only address?
5824 (if (string-equal recipients "")
5825 (setq recipients author))
5826 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
5830 (cons (downcase (mail-strip-quoted-names addr)) addr))
5831 (message-tokenize-header recipients)))
5832 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
5833 (let ((s recipients))
5835 (setq recipients (delq (assoc (car (pop s)) s) recipients))))
5837 ;; Remove hierarchical lists that are contained within each other,
5838 ;; if message-hierarchical-addresses is defined.
5839 (when message-hierarchical-addresses
5840 (let ((plain-addrs (mapcar 'car recipients))
5843 (setq subaddrs (assoc (car plain-addrs)
5844 message-hierarchical-addresses)
5845 plain-addrs (cdr plain-addrs))
5847 (setq subaddrs (cdr subaddrs))
5849 (setq recip (assoc (car subaddrs) recipients)
5850 subaddrs (cdr subaddrs))
5852 (setq recipients (delq recip recipients))))))))
5854 ;; Build the header alist. Allow the user to be asked whether
5855 ;; or not to reply to all recipients in a wide reply.
5856 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
5857 (when (and recipients
5858 (or (not message-wide-reply-confirm-recipients)
5859 (y-or-n-p "Reply to all recipients? ")))
5860 (setq recipients (mapconcat
5861 (lambda (addr) (cdr addr)) recipients ", "))
5862 (if (string-match "^ +" recipients)
5863 (setq recipients (substring recipients (match-end 0))))
5864 (push (cons 'Cc recipients) follow-to)))
5868 (defun message-reply (&optional to-address wide)
5869 "Start editing a reply to the article in the current buffer."
5871 (require 'gnus-sum) ; for gnus-list-identifiers
5872 (let ((cur (current-buffer))
5874 references message-id follow-to
5875 (inhibit-point-motion-hooks t)
5876 (message-this-is-mail t)
5877 gnus-warning in-reply-to)
5879 (message-narrow-to-head-1)
5880 ;; Allow customizations to have their say.
5882 ;; This is a regular reply.
5883 (when (message-functionp message-reply-to-function)
5885 (setq follow-to (funcall message-reply-to-function))))
5886 ;; This is a followup.
5887 (when (message-functionp message-wide-reply-to-function)
5890 (funcall message-wide-reply-to-function)))))
5891 (setq message-id (message-fetch-field "message-id" t)
5892 references (message-fetch-field "references")
5893 date (message-fetch-field "date")
5894 from (message-fetch-field "from")
5895 subject (or (message-fetch-field "subject") "none"))
5896 (when gnus-list-identifiers
5897 (setq subject (message-strip-list-identifiers subject)))
5898 (setq subject (message-make-followup-subject subject))
5899 (when message-subject-trailing-was-query
5900 (setq subject (message-strip-subject-trailing-was subject)))
5902 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
5903 (string-match "<[^>]+>" gnus-warning))
5904 (setq message-id (match-string 0 gnus-warning)))
5907 (setq follow-to (message-get-reply-headers wide to-address)))
5909 ;; Get the references from "In-Reply-To" field if there were
5910 ;; no references and "In-Reply-To" field looks promising.
5912 (when (and (setq in-reply-to (message-fetch-field "in-reply-to"))
5913 (string-match "<[^>]+>" in-reply-to))
5914 (setq references (match-string 0 in-reply-to)))))
5916 (unless (message-mail-user-agent)
5917 (message-pop-to-buffer
5918 (message-buffer-name
5919 (if wide "wide reply" "reply") from
5920 (if wide to-address nil))))
5922 (setq message-reply-headers
5923 (make-full-mail-header-from-decoded-header
5924 0 subject from date message-id references 0 0 ""))
5927 `((Subject . ,subject)
5932 (defun message-wide-reply (&optional to-address)
5933 "Make a \"wide\" reply to the message in the current buffer."
5935 (message-reply to-address t))
5938 (defun message-followup (&optional to-newsgroups)
5939 "Follow up to the message in the current buffer.
5940 If TO-NEWSGROUPS, use that as the new Newsgroups line."
5942 (require 'gnus-sum) ; for gnus-list-identifiers
5943 (let ((cur (current-buffer))
5944 from subject date reply-to mrt mct mft
5945 references message-id follow-to
5946 (inhibit-point-motion-hooks t)
5947 (message-this-is-news t)
5948 followup-to distribution newsgroups gnus-warning posted-to)
5950 (message-narrow-to-head)
5951 (when (message-functionp message-followup-to-function)
5953 (funcall message-followup-to-function)))
5954 (setq from (message-fetch-field "from")
5955 date (message-fetch-field "date")
5956 subject (or (message-fetch-field "subject") "none")
5957 references (message-fetch-field "references")
5958 message-id (message-fetch-field "message-id" t)
5959 followup-to (message-fetch-field "followup-to")
5960 newsgroups (message-fetch-field "newsgroups")
5961 posted-to (message-fetch-field "posted-to")
5962 reply-to (message-fetch-field "reply-to")
5963 mrt (when message-use-mail-reply-to
5964 (message-fetch-field "mail-reply-to"))
5965 distribution (message-fetch-field "distribution")
5966 mct (when message-use-mail-copies-to
5967 (message-fetch-field "mail-copies-to"))
5968 mft (when message-use-mail-followup-to
5969 (message-fetch-field "mail-followup-to")))
5970 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
5971 (string-match "<[^>]+>" gnus-warning))
5972 (setq message-id (match-string 0 gnus-warning)))
5973 ;; Remove bogus distribution.
5974 (when (and (stringp distribution)
5975 (let ((case-fold-search t))
5976 (string-match "world" distribution)))
5977 (setq distribution nil))
5978 (if gnus-list-identifiers
5979 (setq subject (message-strip-list-identifiers subject)))
5980 (setq subject (message-make-followup-subject subject))
5981 (when message-subject-trailing-was-query
5982 (setq subject (message-strip-subject-trailing-was subject)))
5985 ;; Handle special values of Mail-Copies-To.
5988 ((and (or (equal (downcase mct) "never")
5989 (equal (downcase mct) "nobody")))
5991 ((and (or (equal (downcase mct) "always")
5992 (equal (downcase mct) "poster")))
5993 (if (or (not (eq message-use-mail-copies-to 'ask))
5995 (concat "Obey Mail-Copies-To: always? ") t "\
5996 You should normally obey the Mail-Copies-To: header.
5998 `Mail-Copies-To: " mct "'
5999 sends a copy of your response to the author."))
6000 (setq mct (or mrt reply-to from))
6002 ((and (eq message-use-mail-copies-to 'ask)
6005 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
6006 You should normally obey the Mail-Copies-To: header.
6008 `Mail-Copies-To: " mct "'
6009 sends a copy of your response to " (if (string-match "," mct)
6010 "the specified addresses"
6011 "that address") ".")))
6016 (to-newsgroups (setq follow-to (list (cons 'Newsgroups to-newsgroups))))
6017 ;; Handle Followup-To.
6020 ((equal (downcase followup-to) "poster")
6021 (if (or (and followup-to (eq message-use-followup-to 'use))
6022 (message-y-or-n-p "Obey Followup-To: poster? " t "\
6023 You should normally obey the Followup-To: header.
6025 `Followup-To: poster'
6026 sends your response via e-mail instead of news.
6028 A typical situation where `Followup-To: poster' is used is when the author
6029 does not read the newsgroup, so he wouldn't see any replies sent to it."))
6030 (setq message-this-is-news nil
6032 follow-to (list (cons 'To (or mrt reply-to from ""))))
6033 (setq follow-to (list (cons 'Newsgroups newsgroups)))))
6035 (if (or (equal followup-to newsgroups)
6036 (not (and followup-to (eq message-use-followup-to 'ask)))
6038 (concat "Obey Followup-To: " followup-to "? ") t "\
6039 You should normally obey the Followup-To: header.
6041 `Followup-To: " followup-to "'
6042 directs your response to " (if (string-match "," followup-to)
6043 "the specified newsgroups"
6044 "that newsgroup only") ".
6046 If a message is posted to several newsgroups, Followup-To is often
6047 used to direct the following discussion to one newsgroup only,
6048 because discussions that are spread over several newsgroup tend to
6049 be fragmented and very difficult to follow.
6051 Also, some source/announcement newsgroups are not intended for discussion;
6052 responses here are directed to other newsgroups."))
6053 (setq follow-to (list (cons 'Newsgroups followup-to)))
6054 (setq follow-to (list (cons 'Newsgroups newsgroups)))))))
6055 ;; Handle Mail-Followup-To, followup via e-mail.
6057 (or (not (eq message-use-mail-followup-to 'ask))
6059 (concat "Obey Mail-Followup-To: " mft "? ") t "\
6060 You should normally obey the Mail-Followup-To: header.
6062 `Mail-Followup-To: " mft "'
6063 directs your response to " (if (string-match "," mft)
6064 "the specified addresses"
6065 "that address only") " instead of news.
6067 A typical situation where Mail-Followup-To is used is when the author thinks
6068 that further discussion should take place only in "
6069 (if (string-match "," mft)
6070 "the specified mailing lists"
6071 "that mailing list") ".")))
6072 (setq message-this-is-news nil
6074 follow-to (list (cons 'To mft))))
6075 (posted-to (setq follow-to (list (cons 'Newsgroups posted-to))))
6077 (setq follow-to (list (cons 'Newsgroups newsgroups))))))
6079 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
6081 (setq message-reply-headers
6082 (make-full-mail-header-from-decoded-header
6083 0 subject from date message-id references 0 0 ""))
6086 `((Subject . ,subject)
6088 ,@(and mct (list (cons 'Cc mct)))
6089 ,@(and distribution (list (cons 'Distribution distribution)))
6093 (defun message-cancel-news (&optional arg)
6094 "Cancel an article you posted.
6095 If ARG, allow editing of the cancellation message."
6097 (unless (message-news-p)
6098 (error "This is not a news article; canceling is impossible"))
6099 (let (from newsgroups message-id distribution buf sender)
6101 ;; Get header info from original article.
6103 (message-narrow-to-head-1)
6104 (setq from (message-fetch-field "from")
6105 sender (message-fetch-field "sender")
6106 newsgroups (message-fetch-field "newsgroups")
6107 message-id (message-fetch-field "message-id" t)
6108 distribution (message-fetch-field "distribution")))
6109 ;; Make sure that this article was written by the user.
6111 ;; Canlock-logic as suggested by Per Abrahamsen
6112 ;; <abraham@dina.kvl.dk>
6114 ;; IF article has cancel-lock THEN
6115 ;; IF we can verify it THEN
6118 ;; error: cancellock: article is not yours
6120 ;; Use old rules, comparing sender...
6121 (if (message-fetch-field "Cancel-Lock")
6122 (if (null (canlock-verify))
6124 (error "Failed to verify Cancel-lock: This article is not yours"))
6126 (message-gnksa-enable-p 'cancel-messages)
6130 (downcase (message-make-sender))))
6132 (downcase (cadr (std11-extract-address-components from)))
6133 (downcase (cadr (std11-extract-address-components
6134 (message-make-from))))))
6135 (error "This article is not yours"))
6136 (when (yes-or-no-p "Do you really want to cancel this article? ")
6137 ;; Make control message.
6140 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
6142 (insert "Newsgroups: " newsgroups "\n"
6144 "Subject: cmsg cancel " message-id "\n"
6145 "Control: cancel " message-id "\n"
6147 (concat "Distribution: " distribution "\n")
6149 mail-header-separator "\n"
6150 message-cancel-message)
6151 (run-hooks 'message-cancel-hook)
6153 (message "Canceling your article...")
6154 (if (let ((message-syntax-checks
6155 'dont-check-for-anything-just-trust-me)
6156 (message-encoding-buffer (current-buffer))
6157 (message-edit-buffer (current-buffer)))
6158 (message-send-news))
6159 (message "Canceling your article...done"))
6160 (kill-buffer buf))))))
6162 (defun message-supersede-setup-for-mime-edit ()
6163 (set (make-local-variable 'message-setup-hook) nil)
6167 (defun message-supersede ()
6168 "Start composing a message to supersede the current message.
6169 This is done simply by taking the old article and adding a Supersedes
6170 header line with the old Message-ID."
6172 (let ((cur (current-buffer))
6173 (sender (message-fetch-field "sender"))
6174 (from (message-fetch-field "from")))
6175 ;; Check whether the user owns the article that is to be superseded.
6177 ;; Canlock-logic as suggested by Per Abrahamsen
6178 ;; <abraham@dina.kvl.dk>
6180 ;; IF article has cancel-lock THEN
6181 ;; IF we can verify it THEN
6184 ;; error: cancellock: article is not yours
6186 ;; Use old rules, comparing sender...
6187 (if (message-fetch-field "Cancel-Lock")
6188 (if (null (canlock-verify))
6190 (error "Failed to verify Cancel-lock: This article is not yours"))
6192 (message-gnksa-enable-p 'cancel-messages)
6196 (downcase (message-make-sender))))
6198 (downcase (cadr (std11-extract-address-components from)))
6199 (downcase (cadr (std11-extract-address-components
6200 (message-make-from))))))
6201 (error "This article is not yours"))
6202 ;; Get a normal message buffer.
6203 (message-pop-to-buffer (message-buffer-name "supersede"))
6204 (insert-buffer-substring cur)
6205 (message-narrow-to-head-1)
6206 ;; Remove unwanted headers.
6207 (when message-ignored-supersedes-headers
6208 (message-remove-header message-ignored-supersedes-headers t))
6209 (goto-char (point-min))
6210 (if (not (re-search-forward "^Message-ID: " nil t))
6211 (error "No Message-ID in this article")
6212 (replace-match "Supersedes: " t t))
6213 (goto-char (point-max))
6214 (insert mail-header-separator)
6216 (when message-supersede-setup-function
6217 (funcall message-supersede-setup-function))
6218 (run-hooks 'message-supersede-setup-hook)
6219 (goto-char (point-min))
6220 (search-forward (concat "\n" mail-header-separator "\n") nil t)))
6223 (defun message-recover ()
6224 "Reread contents of current buffer from its last auto-save file."
6226 (let ((file-name (make-auto-save-file-name)))
6227 (cond ((save-window-excursion
6228 (if (not (eq system-type 'vax-vms))
6229 (with-output-to-temp-buffer "*Directory*"
6230 (with-current-buffer standard-output
6231 (fundamental-mode)) ; for Emacs 20.4+
6232 (buffer-disable-undo standard-output)
6233 (let ((default-directory "/"))
6235 "ls" nil standard-output nil "-l" file-name))))
6236 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
6237 (let ((buffer-read-only nil))
6239 (insert-file-contents file-name nil)))
6240 (t (error "message-recover cancelled")))))
6242 ;;; Washing Subject:
6244 (defun message-wash-subject (subject)
6245 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
6246 Previous forwarders, replyers, etc. may add it."
6249 (goto-char (point-min))
6250 ;; strip Re/Fwd stuff off the beginning
6251 (while (re-search-forward
6252 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
6255 ;; and gnus-style forwards [foo@bar.com] subject
6256 (goto-char (point-min))
6257 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
6261 (goto-char (point-max))
6262 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
6265 ;; and finally, any whitespace that was left-over
6266 (goto-char (point-min))
6267 (while (re-search-forward "^[ \t]+" nil t)
6269 (goto-char (point-max))
6270 (while (re-search-backward "[ \t]+$" nil t)
6275 ;;; Forwarding messages.
6277 (defvar message-forward-decoded-p nil
6278 "Non-nil means the original message is decoded.")
6280 (defun message-forward-subject-author-subject (subject)
6281 "Generate a SUBJECT for a forwarded message.
6282 The form is: [Source] Subject, where if the original message was mail,
6283 Source is the sender, and if the original message was news, Source is
6284 the list of newsgroups is was posted to."
6286 (let ((prefix (message-fetch-field "newsgroups")))
6288 (and (setq prefix (message-fetch-field "from"))
6289 (nnheader-decode-from prefix))
6293 (defun message-forward-subject-fwd (subject)
6294 "Generate a SUBJECT for a forwarded message.
6295 The form is: Fwd: Subject, where Subject is the original subject of
6297 (concat "Fwd: " subject))
6299 (defun message-make-forward-subject ()
6300 "Return a Subject header suitable for the message in the current buffer."
6303 (message-narrow-to-head-1)
6304 (let ((funcs message-make-forward-subject-function)
6305 (subject (message-fetch-field "Subject")))
6308 (if message-forward-decoded-p
6310 (nnheader-decode-subject subject))
6312 (if message-wash-forwarded-subjects
6313 (setq subject (message-wash-subject subject)))
6314 ;; Make sure funcs is a list.
6317 (setq funcs (list funcs)))
6318 ;; Apply funcs in order, passing subject generated by previous
6319 ;; func to the next one.
6321 (when (message-functionp (car funcs))
6322 (setq subject (funcall (car funcs) subject)))
6323 (setq funcs (cdr funcs)))
6327 (defun message-forward (&optional news)
6328 "Forward the current message via mail.
6329 Optional NEWS will use news to forward instead of mail."
6331 (let ((cur (current-buffer))
6332 (subject (message-make-forward-subject)))
6334 (message-news nil subject)
6335 (message-mail nil subject))
6336 (message-forward-make-body cur)))
6339 (defun message-forward-make-body (forward-buffer)
6340 ;; Put point where we want it before inserting the forwarded
6342 ;; Note that this function definition for T-gnus is totally different
6343 ;; from the original Gnus."
6344 (if message-forward-before-signature
6346 (goto-char (point-max)))
6347 ;; Make sure we're at the start of the line.
6350 ;; Narrow to the area we are to insert.
6351 (narrow-to-region (point) (point))
6352 ;; Insert the separators and the forwarded buffer.
6353 (insert message-forward-start-separator)
6354 (let ((art-beg (point)))
6355 (insert-buffer-substring forward-buffer)
6356 (goto-char (point-max))
6357 (insert message-forward-end-separator)
6358 (set-text-properties (point-min) (point-max) nil)
6359 ;; Remove all unwanted headers.
6361 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
6364 (goto-char (point-min))
6365 (message-remove-header message-included-forward-headers t nil t)
6367 (message-position-point)))
6370 (defun message-forward-rmail-make-body (forward-buffer)
6371 (save-window-excursion
6372 (set-buffer forward-buffer)
6373 ;; Rmail doesn't have rmail-msg-restore-non-pruned-header in Emacs
6374 ;; 20. FIXIT, or we drop support for rmail in Emacs 20.
6375 (if (rmail-msg-is-pruned)
6376 (rmail-msg-restore-non-pruned-header)))
6377 (message-forward-make-body forward-buffer))
6380 (defun message-insinuate-rmail ()
6381 "Let RMAIL uses message to forward."
6383 (setq rmail-enable-mime-composing t)
6384 (setq rmail-insert-mime-forwarded-message-function
6385 'message-forward-rmail-make-body))
6388 (defun message-resend (address)
6389 "Resend the current article to ADDRESS."
6391 (list (message-read-from-minibuffer "Resend message to: ")))
6392 (message "Resending message to %s..." address)
6394 (let ((cur (current-buffer))
6396 ;; We first set up a normal mail buffer.
6397 (unless (message-mail-user-agent)
6398 (set-buffer (get-buffer-create " *message resend*"))
6400 (let ((message-this-is-mail t)
6401 ;; avoid to turn-on-mime-edit
6403 (message-setup `((To . ,address)))))
6404 ;; Insert our usual headers.
6405 (message-generate-headers '(From Date To))
6406 (message-narrow-to-headers)
6407 ;; Rename them all to "Resent-*".
6408 (while (re-search-forward "^[A-Za-z]" nil t)
6413 (delete-region (point) (point-max))
6415 ;; Insert the message to be resent.
6416 (insert-buffer-substring cur)
6417 (goto-char (point-min))
6418 (search-forward "\n\n")
6421 (narrow-to-region beg (point))
6422 (message-remove-header message-ignored-resent-headers t)
6423 (goto-char (point-max)))
6424 (insert mail-header-separator)
6425 ;; Rename all old ("Also-")Resent headers.
6426 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
6429 ;; Quote any "From " lines at the beginning.
6431 (when (looking-at "From ")
6432 (replace-match "X-From-Line: "))
6434 (let ((message-encoding-buffer (current-buffer))
6435 (message-edit-buffer (current-buffer))
6436 message-required-mail-headers)
6437 (message-send-mail))
6438 (kill-buffer (current-buffer)))
6439 (message "Resending message to %s...done" address)))
6441 (defun message-bounce-setup-for-mime-edit ()
6442 (set (make-local-variable 'message-setup-hook) nil)
6446 (defun message-bounce ()
6447 "Re-mail the current message.
6448 This only makes sense if the current message is a bounce message that
6449 contains some mail you have written which has been bounced back to
6452 (let ((cur (current-buffer))
6454 (message-pop-to-buffer (message-buffer-name "bounce"))
6455 (insert-buffer-substring cur)
6457 (message-narrow-to-head)
6458 (if (and (message-fetch-field "MIME-Version")
6459 (setq boundary (message-fetch-field "Content-Type")))
6460 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary)
6461 (setq boundary (concat (match-string 1 boundary) " *\n"
6462 "Content-Type: message/rfc822"))
6463 (setq boundary nil)))
6465 (goto-char (point-min))
6466 (search-forward "\n\n" nil t)
6467 (if (or (and boundary
6468 (re-search-forward boundary nil t)
6470 (and (re-search-forward message-unsent-separator nil t)
6472 (re-search-forward "^Return-Path:.*\n" nil t))
6473 ;; We remove everything before the bounced mail.
6476 (if (re-search-forward "^[^ \n\t]+:" nil t)
6479 (when (re-search-backward "^.?From .*\n" nil t)
6480 (delete-region (match-beginning 0) (match-end 0))))
6482 (message-narrow-to-head-1)
6483 (message-remove-header message-ignored-bounced-headers t)
6484 (goto-char (point-max))
6485 (insert mail-header-separator))
6486 (when message-bounce-setup-function
6487 (funcall message-bounce-setup-function))
6488 (run-hooks 'message-bounce-setup-hook)
6489 (message-position-point)))
6492 ;;; Interactive entry points for new message buffers.
6496 (defun message-mail-other-window (&optional to subject)
6497 "Like `message-mail' command, but display mail buffer in another window."
6499 (unless (message-mail-user-agent)
6500 (let ((pop-up-windows t)
6501 (special-display-buffer-names nil)
6502 (special-display-regexps nil)
6503 (same-window-buffer-names nil)
6504 (same-window-regexps nil))
6505 (message-pop-to-buffer (message-buffer-name "mail" to))))
6506 (let ((message-this-is-mail t))
6507 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
6508 nil nil 'switch-to-buffer-other-window)))
6511 (defun message-mail-other-frame (&optional to subject)
6512 "Like `message-mail' command, but display mail buffer in another frame."
6514 (unless (message-mail-user-agent)
6515 (let ((pop-up-frames t)
6516 (special-display-buffer-names nil)
6517 (special-display-regexps nil)
6518 (same-window-buffer-names nil)
6519 (same-window-regexps nil))
6520 (message-pop-to-buffer (message-buffer-name "mail" to))))
6521 (let ((message-this-is-mail t))
6522 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
6523 nil nil 'switch-to-buffer-other-frame)))
6526 (defun message-news-other-window (&optional newsgroups subject)
6527 "Start editing a news article to be sent."
6529 (let ((pop-up-windows t)
6530 (special-display-buffer-names nil)
6531 (special-display-regexps nil)
6532 (same-window-buffer-names nil)
6533 (same-window-regexps nil))
6534 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
6535 (let ((message-this-is-news t))
6536 (message-setup `((Newsgroups . ,(or newsgroups ""))
6537 (Subject . ,(or subject ""))))))
6540 (defun message-news-other-frame (&optional newsgroups subject)
6541 "Start editing a news article to be sent."
6543 (let ((pop-up-frames t)
6544 (special-display-buffer-names nil)
6545 (special-display-regexps nil)
6546 (same-window-buffer-names nil)
6547 (same-window-regexps nil))
6548 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
6549 (let ((message-this-is-news t))
6550 (message-setup `((Newsgroups . ,(or newsgroups ""))
6551 (Subject . ,(or subject ""))))))
6555 ;; This code should be moved to underline.el (from which it is stolen).
6558 (defun bold-region (start end)
6559 "Bold all nonblank characters in the region.
6560 Works by overstriking characters.
6561 Called from program, takes two arguments START and END
6562 which specify the range to operate on."
6565 (let ((end1 (make-marker)))
6566 (move-marker end1 (max start end))
6567 (goto-char (min start end))
6568 (while (< (point) end1)
6569 (or (looking-at "[_\^@- ]")
6570 (insert (char-after) "\b"))
6571 (forward-char 1)))))
6574 (defun unbold-region (start end)
6575 "Remove all boldness (overstruck characters) in the region.
6576 Called from program, takes two arguments START and END
6577 which specify the range to operate on."
6580 (let ((end1 (make-marker)))
6581 (move-marker end1 (max start end))
6582 (goto-char (min start end))
6583 (while (re-search-forward "\b" end1 t)
6584 (if (eq (char-after) (char-after (- (point) 2)))
6585 (delete-char -2))))))
6587 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
6589 ;; Support for toolbar
6591 (defvar tool-bar-map)
6592 (defvar tool-bar-mode))
6594 (defun message-tool-bar-local-item-from-menu (command icon in-map &optional from-map &rest props)
6595 ;; We need to make tool bar entries in local keymaps with
6596 ;; `tool-bar-local-item-from-menu' in Emacs > 21.3
6597 (if (fboundp 'tool-bar-local-item-from-menu)
6598 ;; This is for Emacs 21.3
6599 (tool-bar-local-item-from-menu command icon in-map from-map props)
6600 (tool-bar-add-item-from-menu command icon from-map props)))
6602 (defun message-tool-bar-map ()
6603 (or message-tool-bar-map
6604 (setq message-tool-bar-map
6606 (condition-case nil (require 'tool-bar) (error nil))
6607 (fboundp 'tool-bar-add-item-from-menu)
6609 (let ((tool-bar-map (copy-keymap tool-bar-map))
6610 (load-path (mm-image-load-path)))
6611 ;; Zap some items which aren't so relevant and take
6613 (dolist (key '(print-buffer kill-buffer save-buffer
6614 write-file dired open-file))
6615 (define-key tool-bar-map (vector key) nil))
6616 (message-tool-bar-local-item-from-menu
6617 'message-send-and-exit "mail_send" tool-bar-map message-mode-map)
6618 (message-tool-bar-local-item-from-menu
6619 'message-kill-buffer "close" tool-bar-map message-mode-map)
6620 (message-tool-bar-local-item-from-menu
6621 'message-dont-send "cancel" tool-bar-map message-mode-map)
6622 (message-tool-bar-local-item-from-menu
6623 'mime-edit-insert-file "attach" tool-bar-map message-mode-map)
6624 (message-tool-bar-local-item-from-menu
6625 'ispell-message "spell" tool-bar-map message-mode-map)
6626 (message-tool-bar-local-item-from-menu
6627 'message-insert-importance-high "important"
6628 tool-bar-map message-mode-map)
6629 (message-tool-bar-local-item-from-menu
6630 'message-insert-importance-low "unimportant"
6631 tool-bar-map message-mode-map)
6632 (message-tool-bar-local-item-from-menu
6633 'message-insert-disposition-notification-to "receipt"
6634 tool-bar-map message-mode-map)
6637 ;;; Group name completion.
6639 (defcustom message-newgroups-header-regexp
6640 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
6641 "Regexp that match headers that lists groups."
6645 (defcustom message-completion-alist
6646 (list (cons message-newgroups-header-regexp 'message-expand-group)
6647 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name)
6648 '("^\\(Reply-To\\|From\\|Disposition-Notification-To\\|Return-Receipt-To\\):"
6649 . message-expand-name))
6650 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
6652 :type '(alist :key-type regexp :value-type function))
6654 (defcustom message-expand-name-function
6655 (if (fboundp 'bbdb-complete-name)
6657 (if (fboundp 'lsdb-complete-name)
6660 "*A function called to expand addresses in field body."
6664 (defcustom message-tab-body-function nil
6665 "*Function to execute when `message-tab' (TAB) is executed in the body.
6666 If nil, the function bound in `text-mode-map' or `global-map' is executed."
6670 (defun message-tab ()
6671 "Complete names according to `message-completion-alist'.
6672 Execute function specified by `message-tab-body-function' when not in
6675 (let ((alist message-completion-alist))
6677 (let ((mail-abbrev-mode-regexp (caar alist)))
6678 (not (mail-abbrev-in-expansion-header-p))))
6679 (setq alist (cdr alist)))
6680 (funcall (or (cdar alist) message-tab-body-function
6681 (lookup-key text-mode-map "\t")
6682 (lookup-key global-map "\t")
6683 'indent-relative))))
6685 (defun message-expand-group ()
6686 "Expand the group name under point."
6687 (let* ((b (save-excursion
6692 (skip-chars-forward "^:")
6695 (skip-chars-backward "^, \t\n") (point))))
6696 (completion-ignore-case t)
6697 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
6699 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
6700 (completions (all-completions string hashtb))
6702 (delete-region b (point))
6704 ((= (length completions) 1)
6705 (if (string= (car completions) string)
6708 (message "Only matching group"))
6709 (insert (car completions))))
6710 ((and (setq comp (try-completion string hashtb))
6711 (not (string= comp string)))
6716 (message "No matching groups")
6717 (save-selected-window
6718 (pop-to-buffer "*Completions*")
6719 (buffer-disable-undo)
6720 (let ((buffer-read-only nil))
6722 (let ((standard-output (current-buffer)))
6723 (display-completion-list (sort completions 'string<)))
6724 (goto-char (point-min))
6725 (delete-region (point) (progn (forward-line 3) (point))))))))))
6727 (defun message-expand-name ()
6728 (funcall message-expand-name-function))
6732 (defun message-talkative-question (ask question show &rest text)
6733 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
6734 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
6735 The following arguments may contain lists of values."
6737 (setq text (message-flatten-list text)))
6738 (save-window-excursion
6740 (with-output-to-temp-buffer " *MESSAGE information message*"
6741 (set-buffer " *MESSAGE information message*")
6742 (fundamental-mode) ; for Emacs 20.4+
6743 (mapcar 'princ text)
6744 (goto-char (point-min))))
6745 (funcall ask question))
6746 (funcall ask question)))
6748 (defun message-flatten-list (list)
6749 "Return a new, flat list that contains all elements of LIST.
6751 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
6754 (apply 'append (mapcar 'message-flatten-list list)))
6758 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
6759 "Create and return a buffer with name based on NAME using `generate-new-buffer.'
6760 Then clone the local variables and values from the old buffer to the
6761 new one, cloning only the locals having a substring matching the
6763 (let ((oldbuf (current-buffer)))
6765 (set-buffer (generate-new-buffer name))
6766 (message-clone-locals oldbuf varstr)
6769 (defun message-clone-locals (buffer &optional varstr)
6770 "Clone the local variables from BUFFER to the current buffer."
6771 (let ((locals (save-excursion
6773 (buffer-local-variables)))
6775 "^\\(gnus\\|nn\\|message\\|user-\\(mail-address\\|full-name\\)\\)"))
6778 (when (and (consp local)
6780 (string-match regexp (symbol-name (car local)))
6782 (string-match varstr (symbol-name (car local)))))
6784 (set (make-local-variable (car local))
6789 ;;; @ for MIME Edit mode
6792 (defun message-maybe-encode ()
6793 (when message-mime-mode
6794 ;; Inherit the buffer local variable `mime-edit-pgp-processing'.
6795 (let ((pgp-processing (with-current-buffer message-edit-buffer
6796 mime-edit-pgp-processing)))
6797 (setq mime-edit-pgp-processing pgp-processing))
6798 (run-hooks 'mime-edit-translate-hook)
6799 (if (catch 'mime-edit-error
6801 (mime-edit-pgp-enclose-buffer)
6802 (mime-edit-translate-body)))
6803 (error "Translation error!"))
6804 (run-hooks 'mime-edit-exit-hook)))
6806 (defun message-mime-insert-article (&optional full-headers)
6808 (let ((message-cite-function 'mime-edit-inserted-message-filter)
6809 (message-reply-buffer
6810 (message-get-parameter-with-eval 'original-buffer))
6812 (message-yank-original nil)
6814 (narrow-to-region (goto-char start)
6815 (if (search-forward "\n\n" nil t)
6818 (goto-char (point-min))
6819 (let ((message-included-forward-headers
6820 (if full-headers "" message-included-forward-headers)))
6821 (message-remove-header message-included-forward-headers t nil t))
6824 (set-alist 'mime-edit-message-inserter-alist
6825 'message-mode (function message-mime-insert-article))
6827 ;;; Miscellaneous functions
6829 ;; stolen (and renamed) from nnheader.el
6830 (static-if (fboundp 'subst-char-in-string)
6831 (defsubst message-replace-chars-in-string (string from to)
6832 (subst-char-in-string from to string))
6833 (defun message-replace-chars-in-string (string from to)
6834 "Replace characters in STRING from FROM to TO."
6835 (let ((string (substring string 0)) ;Copy string.
6836 (len (length string))
6838 ;; Replace all occurrences of FROM with TO.
6840 (when (= (aref string idx) from)
6841 (aset string idx to))
6842 (setq idx (1+ idx)))
6849 (defvar message-inhibit-body-encoding t)
6851 (defun message-encode-message-body ()
6852 (unless message-inhibit-body-encoding
6853 (let ((mail-parse-charset (or mail-parse-charset
6854 message-default-charset))
6855 (case-fold-search t)
6856 lines content-type-p)
6859 (narrow-to-region (point) (point-max))
6860 (let ((new (mml-generate-mime)))
6862 (delete-region (point-min) (point-max))
6864 (goto-char (point-min))
6865 (if (eq (aref new 0) ?\n)
6867 (search-forward "\n\n")
6868 (setq lines (buffer-substring (point-min) (1- (point))))
6869 (delete-region (point-min) (point))))))
6871 (message-narrow-to-headers-or-head)
6872 (message-remove-header "Mime-Version")
6873 (goto-char (point-max))
6874 (insert "MIME-Version: 1.0\n")
6877 (setq content-type-p
6879 (re-search-backward "^Content-Type:" nil t))))
6881 (message-narrow-to-headers-or-head)
6882 (message-remove-first-header "Content-Type")
6883 (message-remove-first-header "Content-Transfer-Encoding"))
6884 ;; We always make sure that the message has a Content-Type
6885 ;; header. This is because some broken MTAs and MUAs get
6886 ;; awfully confused when confronted with a message with a
6887 ;; MIME-Version header and without a Content-Type header. For
6888 ;; instance, Solaris' /usr/bin/mail.
6889 (unless content-type-p
6890 (goto-char (point-min))
6891 ;; For unknown reason, MIME-Version doesn't exist.
6892 (when (re-search-forward "^MIME-Version:" nil t)
6894 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
6896 (defun message-read-from-minibuffer (prompt &optional initial-contents)
6897 "Read from the minibuffer while providing abbrev expansion."
6898 (if (fboundp 'mail-abbrevs-setup)
6899 (let ((mail-abbrev-mode-regexp "")
6900 (minibuffer-setup-hook 'mail-abbrevs-setup)
6901 (minibuffer-local-map message-minibuffer-local-map))
6902 (read-from-minibuffer prompt initial-contents))
6903 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
6904 (minibuffer-local-map message-minibuffer-local-map))
6905 (read-string prompt initial-contents))))
6907 (defun message-use-alternative-email-as-from ()
6908 (require 'mail-utils)
6909 (let* ((fields '("To" "Cc"))
6912 (mail-strip-quoted-names
6913 (mapconcat 'message-fetch-reply-field fields ","))
6917 (if (string-match message-alternative-emails (car emails))
6918 (setq email (car emails)
6921 (unless (or (not email) (equal email user-mail-address))
6922 (goto-char (point-max))
6923 (insert "From: " email "\n"))))
6925 (defun message-options-get (symbol)
6926 (cdr (assq symbol message-options)))
6928 (defun message-options-set (symbol value)
6929 (let ((the-cons (assq symbol message-options)))
6932 (setcdr the-cons value)
6933 (setq message-options (delq the-cons message-options)))
6935 (push (cons symbol value) message-options))))
6938 (defun message-options-set-recipient ()
6940 (message-narrow-to-headers-or-head)
6941 (message-options-set 'message-sender
6942 (mail-strip-quoted-names
6943 (message-fetch-field "from")))
6944 (message-options-set 'message-recipients
6945 (mail-strip-quoted-names
6946 (let ((to (message-fetch-field "to"))
6947 (cc (message-fetch-field "cc"))
6948 (bcc (message-fetch-field "bcc")))
6951 (if (and to cc) ", ")
6953 (if (and (or to cc) bcc) ", ")
6956 (when (featurep 'xemacs)
6957 (require 'messagexmas)
6958 (message-xmas-redefine))
6962 (run-hooks 'message-load-hook)
6965 ;; coding: iso-8859-1
6968 ;;; message.el ends here