1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
8 ;; Keiichi Suzuki <kei-suzu@mail.wbs.ne.jp>
9 ;; Tatsuya Ichikawa <t-ichi@po.shiojiri.ne.jp>
10 ;; Katsumi Yamaoka <yamaoka@jpl.org>
11 ;; Kiyokazu SUTO <suto@merry.xmath.ous.ac.jp>
12 ;; Keywords: mail, news, MIME
14 ;; This file is part of GNU Emacs.
16 ;; GNU Emacs is free software; you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation; either version 2, or (at your option)
21 ;; GNU Emacs is distributed in the hope that it will be useful,
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;; GNU General Public License for more details.
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs; see the file COPYING. If not, write to the
28 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
29 ;; Boston, MA 02111-1307, USA.
33 ;; This mode provides mail-sending facilities from within Emacs. It
34 ;; consists mainly of large chunks of code from the sendmail.el,
35 ;; gnus-msg.el and rnewspost.el files.
42 (defvar gnus-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-cross-post-old-target nil
267 "Old target for cross-posts or follow-ups.")
268 (make-variable-buffer-local 'message-cross-post-old-target)
271 (defcustom message-cross-post-default t
272 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
273 If nil, `message-cross-post-followup-to' will only do a followup. Note that
274 you can explicitly override this setting by calling
275 `message-cross-post-followup-to' with a prefix."
277 :group 'message-various)
280 (defcustom message-cross-post-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-followup-to-note
289 "Note to insert before signature to notify of follow-up only."
291 :group 'message-various)
294 (defcustom message-cross-post-note-function
295 'message-cross-post-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-cross-post-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',
345 'continuation-headers', and `long-header-lines'."
347 :type '(repeat sexp)) ; Fixme: improve this
349 (defcustom message-required-headers '((optional . References) From)
350 "*Headers to be generated or prompted for when sending a message.
351 Also see `message-required-news-headers' and
352 `message-required-mail-headers'."
354 :group 'message-headers
355 :type '(repeat sexp))
357 (defcustom message-draft-headers '(References From)
358 "*Headers to be generated when saving a draft message."
360 :group 'message-headers
361 :type '(repeat sexp))
363 (defcustom message-required-news-headers
364 '(From Newsgroups Subject Date Message-ID
365 (optional . Organization)
366 (optional . User-Agent))
367 "*Headers to be generated or prompted for when posting an article.
368 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
369 Message-ID. Organization, Lines, In-Reply-To, Expires, and
370 User-Agent are optional. If don't you want message to insert some
371 header, remove it from this list."
373 :group 'message-headers
374 :type '(repeat sexp))
376 (defcustom message-required-mail-headers
377 '(From Subject Date (optional . In-Reply-To) Message-ID
378 (optional . User-Agent))
379 "*Headers to be generated or prompted for when mailing a message.
380 It is recommended that From, Date, To, Subject and Message-ID be
381 included. Organization and User-Agent are optional."
383 :group 'message-headers
384 :type '(repeat sexp))
386 (defcustom message-deletable-headers '(Message-ID Date Lines)
387 "Headers to be deleted if they already exist and were generated by message previously."
388 :group 'message-headers
391 (defcustom message-ignored-news-headers
392 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
393 "*Regexp of headers to be removed unconditionally before posting."
395 :group 'message-headers
398 (defcustom message-ignored-mail-headers
399 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
400 "*Regexp of headers to be removed unconditionally before mailing."
402 :group 'message-headers
405 (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:"
406 "*Header lines matching this regexp will be deleted before posting.
407 It's best to delete old Path and Date headers before posting to avoid
409 :group 'message-interface
412 (defcustom message-supersede-setup-function
413 'message-supersede-setup-for-mime-edit
414 "Function to setup a supersede message."
415 :group 'message-sending
418 (defcustom message-subject-re-regexp
419 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)*:[ \t]*\\)*[ \t]*"
420 "*Regexp matching \"Re: \" in the subject line."
421 :group 'message-various
424 ;;; Some sender agents encode the whole subject including leading "Re: ".
425 ;;; And if followup agent does not decode it for some reason (e.g. unknown
426 ;;; charset) and just add a new "Re: " in front of the encoded-word, the
427 ;;; result will contain multiple "Re: "'s.
428 (defcustom message-subject-encoded-re-regexp
432 "[-!#$%&'*+0-9A-Z^_`a-z{|}~]+" ; charset
435 "[Bb]" (regexp-quote "?") ; B encoding
436 "\\(\\(CQk\\|CSA\\|IAk\\|ICA\\)[Jg]\\)*" ; \([ \t][ \t][ \t]\)*
438 "[Uc][km]U6" ; [Rr][Ee]:
440 "\\(C[VX]\\|I[FH]\\)J[Fl]O[g-v]" ; [ \t][Rr][Ee]:
442 "\\(CQl\\|CSB\\|IAl\\|ICB\\)[Sy][RZ]T[o-r]" ; [ \t][ \t][Rr][Ee]:
445 "[Qb]" (regexp-quote "?") ; Q encoding
446 "\\(_\\|=09\\|=20\\)*"
447 "\\([Rr]\\|=[57]2\\)\\([Ee]\\|=[46]5\\)\\(:\\|=3[Aa]\\)"
450 "*Regexp matching \"Re: \" in the subject line.
451 Unlike `message-subject-re-regexp', this regexp matches \"Re: \" within
453 :group 'message-various
456 (defcustom message-use-subject-re t
457 "*If t, remove any (buggy) \"Re: \"'s from the subject of the precursor
458 and add a new \"Re: \". If it is nil, use the subject \"as-is\". If it
459 is the symbol `guess', try to detect \"Re: \" within an encoded-word."
460 :group 'message-various
461 :type '(choice (const :tag "off" nil)
466 (defcustom message-signature-separator "^-- *$"
467 "Regexp matching the signature separator."
469 :group 'message-various)
471 (defcustom message-signature-separator-for-insertion "-- \n"
472 "*Signature separator. This value will be inserted as signature separator
473 when composing message. Default value is \"-- \\n\". Notice: Changing this
474 value may go against RFC-1036 and draft-ietf-usefor-article-05.txt. "
476 :group 'message-insertion)
478 (defcustom message-elide-ellipsis "\n[...]\n\n"
479 "*The string which is inserted for elided text."
481 :group 'message-various)
483 (defcustom message-interactive t
484 "Non-nil means when sending a message wait for and display errors.
485 nil means let mailer mail back a message to report errors."
486 :group 'message-sending
490 (defcustom message-generate-new-buffers 'unique
491 "*Non-nil means create a new message buffer whenever `message-setup' is called.
492 If this is a function, call that function with three parameters: The type,
493 the to address and the group name. (Any of these may be nil.) The function
494 should return the new buffer name."
495 :group 'message-buffers
496 :type '(choice (const :tag "off" nil)
497 (const :tag "unique" unique)
498 (const :tag "unsent" unsent)
501 (defcustom message-kill-buffer-on-exit nil
502 "*Non-nil means that the message buffer will be killed after sending a message."
503 :group 'message-buffers
506 (defcustom message-kill-buffer-query-function 'yes-or-no-p
507 "*Function used to prompt user whether to kill the message buffer. If
508 it is t, the buffer will be killed unconditionally."
509 :type '(radio (function-item yes-or-no-p)
510 (function-item y-or-n-p)
511 (function-item nnheader-Y-or-n-p)
512 (function :tag "Other" t))
513 :group 'message-buffers)
515 (defcustom message-kill-buffer-and-remove-file t
516 "*Non-nil means that the associated file will be removed before
517 removing the message buffer. However, it is treated as nil when the
518 command `message-mimic-kill-buffer' is used."
519 :group 'message-buffers
523 (defvar gnus-local-organization))
524 (defcustom message-user-organization
525 (or (and (boundp 'gnus-local-organization)
526 (stringp gnus-local-organization)
527 gnus-local-organization)
528 (getenv "ORGANIZATION")
530 "*String to be used as an Organization header.
531 If t, use `message-user-organization-file'."
532 :group 'message-headers
533 :type '(choice string
534 (const :tag "consult file" t)))
537 (defcustom message-user-organization-file "/usr/lib/news/organization"
538 "*Local news organization file."
540 :group 'message-headers)
542 (defcustom message-forward-start-separator
543 (concat (mime-make-tag "message" "rfc822") "\n")
544 "*Delimiter inserted before forwarded messages."
545 :group 'message-forwarding
548 (defcustom message-forward-end-separator
549 (concat (mime-make-tag "text" "plain") "\n")
550 "*Delimiter inserted after forwarded messages."
551 :group 'message-forwarding
554 (defcustom message-included-forward-headers
555 "^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:"
556 "*Regexp matching headers to be included in forwarded messages."
557 :group 'message-forwarding
560 (defcustom message-make-forward-subject-function
561 'message-forward-subject-author-subject
562 "*List of functions called to generate subject headers for forwarded messages.
563 The subject generated by the previous function is passed into each
566 The provided functions are:
568 * `message-forward-subject-author-subject' (Source of article (author or
569 newsgroup)), in brackets followed by the subject
570 * `message-forward-subject-fwd' (Subject of article with 'Fwd:' prepended
572 :group 'message-forwarding
573 :type '(radio (function-item message-forward-subject-author-subject)
574 (function-item message-forward-subject-fwd)
575 (repeat :tag "List of functions" function)))
577 (defcustom message-forward-as-mime t
578 "*If non-nil, forward messages as an inline/rfc822 MIME section. Otherwise, directly inline the old message in the forwarded message."
580 :group 'message-forwarding
583 (defcustom message-forward-show-mml t
584 "*If non-nil, forward messages are shown as mml. Otherwise, forward messages are unchanged."
586 :group 'message-forwarding
589 (defcustom message-forward-before-signature t
590 "*If non-nil, put forwarded message before signature, else after."
591 :group 'message-forwarding
594 (defcustom message-wash-forwarded-subjects nil
595 "*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."
596 :group 'message-forwarding
599 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From "
600 "*All headers that match this regexp will be deleted when resending a message."
601 :group 'message-interface
604 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
605 "*All headers that match this regexp will be deleted when forwarding a message."
607 :group 'message-forwarding
608 :type '(choice (const :tag "None" nil)
611 (defcustom message-ignored-cited-headers "."
612 "*Delete these headers from the messages you yank."
613 :group 'message-insertion
616 (defcustom message-cite-prefix-regexp
617 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
618 "\\([ \t]*[-_.[:word:]]+>+\\|[ \t]*[]>|}+]\\)+"
619 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
620 (let ((old-table (syntax-table))
621 non-word-constituents)
622 (set-syntax-table text-mode-syntax-table)
623 (setq non-word-constituents
625 (if (string-match "\\w" "-") "" "-")
626 (if (string-match "\\w" "_") "" "_")
627 (if (string-match "\\w" ".") "" ".")))
628 (set-syntax-table old-table)
629 (if (equal non-word-constituents "")
630 "\\([ \t]*\\(\\w\\)+>+\\|[ \t]*[]>|}+]\\)+"
631 (concat "\\([ \t]*\\(\\w\\|["
632 non-word-constituents
633 "]\\)+>+\\|[ \t]*[]>|}+]\\)+"))))
634 "*Regexp matching the longest possible citation prefix on a line."
635 :group 'message-insertion
638 (defcustom message-cancel-message "I am canceling my own article.\n"
639 "Message to be inserted in the cancel message."
640 :group 'message-interface
643 ;; Useful to set in site-init.el
645 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
646 "Function to call to send the current buffer as mail.
647 The headers should be delimited by a line whose contents match the
648 variable `mail-header-separator'.
650 Valid values include `message-send-mail-with-sendmail' (the default),
651 `message-send-mail-with-mh', `message-send-mail-with-qmail',
652 `message-send-mail-with-smtp', `message-smtpmail-send-it',
653 `smtpmail-send-it' and `feedmail-send-it'.
655 See also `send-mail-function'."
656 :type '(radio (function-item message-send-mail-with-sendmail)
657 (function-item message-send-mail-with-mh)
658 (function-item message-send-mail-with-qmail)
659 (function-item message-send-mail-with-smtp)
660 (function-item message-smtpmail-send-it)
661 (function-item smtpmail-send-it)
662 (function-item feedmail-send-it)
663 (function :tag "Other"))
664 :group 'message-sending
665 :group 'message-mail)
667 ;; 1997-09-29 by MORIOKA Tomohiko
668 (defcustom message-send-news-function 'message-send-news-with-gnus
669 "Function to call to send the current buffer as news.
670 The headers should be delimited by a line whose contents match the
671 variable `mail-header-separator'."
672 :group 'message-sending
676 (defcustom message-reply-to-function nil
677 "If non-nil, function that should return a list of headers.
678 This function should pick out addresses from the To, Cc, and From headers
679 and respond with new To and Cc headers."
680 :group 'message-interface
681 :type '(choice function (const nil)))
683 (defcustom message-wide-reply-to-function nil
684 "If non-nil, function that should return a list of headers.
685 This function should pick out addresses from the To, Cc, and From headers
686 and respond with new To and Cc headers."
687 :group 'message-interface
688 :type '(choice function (const nil)))
690 (defcustom message-followup-to-function nil
691 "If non-nil, function that should return a list of headers.
692 This function should pick out addresses from the To, Cc, and From headers
693 and respond with new To and Cc headers."
694 :group 'message-interface
695 :type '(choice function (const nil)))
697 (defcustom message-use-followup-to 'ask
698 "*Specifies what to do with Followup-To header.
699 If nil, always ignore the header. If it is t, use its value, but
700 query before using the \"poster\" value. If it is the symbol `ask',
701 always query the user whether to use the value. If it is the symbol
702 `use', always use the value."
703 :group 'message-interface
704 :type '(choice (const :tag "ignore" nil)
705 (const :tag "use & query" t)
706 (const :tag "maybe" t)
707 (const :tag "always" use)
708 (const :tag "ask" ask)))
710 (defcustom message-use-mail-copies-to 'ask
711 "*Specifies what to do with Mail-Copies-To header.
712 If nil, always ignore the header. If it is t, use its value, but
713 query before using the value other than \"always\" or \"never\".
714 If it is the symbol `ask', always query the user whether to use
715 the value. If it is the symbol `use', always use the 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 ;;; XXX: 'ask and 'use are not implemented yet.
723 (defcustom message-use-mail-reply-to 'ask
724 "*Specifies what to do with Mail-Reply-To/Reply-To header.
725 If nil, always ignore the header. If it is t or the symbol `use', use
726 its value. If it is the symbol `ask', always query the user whether to
727 use the value. Note that if \"Reply-To\" is marked as \"broken\", its value
729 :group 'message-interface
730 :type '(choice (const :tag "ignore" nil)
731 (const :tag "maybe" t)
732 (const :tag "always" use)
733 (const :tag "ask" ask)))
735 (defcustom message-use-mail-followup-to 'use
736 "*Specifies what to do with Mail-Followup-To header.
737 If nil, always ignore the header. If it is the symbol `ask', always
738 query the user whether to use the value. If it is t or the symbol
739 `use', always use the value."
740 :group 'message-interface
741 :type '(choice (const :tag "ignore" nil)
742 (const :tag "maybe" t)
743 (const :tag "always" use)
744 (const :tag "ask" ask)))
746 (defcustom message-subscribed-address-functions nil
747 "*Specifies functions for determining list subscription.
748 If nil, do not attempt to determine list subscribtion with functions.
749 If non-nil, this variable contains a list of functions which return
750 regular expressions to match lists. These functions can be used in
751 conjunction with `message-subscribed-regexps' and
752 `message-subscribed-addresses'."
753 :group 'message-interface
754 :type '(repeat sexp))
756 (defcustom message-subscribed-address-file nil
757 "*A file containing addresses the user is subscribed to.
758 If nil, do not look at any files to determine list subscriptions. If
759 non-nil, each line of this file should be a mailing list address."
760 :group 'message-interface
763 (defcustom message-subscribed-addresses nil
764 "*Specifies a list of addresses the user is subscribed to.
765 If nil, do not use any predefined list subscriptions. This list of
766 addresses can be used in conjuction with
767 `message-subscribed-address-functions' and `message-subscribed-regexps'."
768 :group 'message-interface
769 :type '(repeat string))
771 (defcustom message-subscribed-regexps nil
772 "*Specifies a list of addresses the user is subscribed to.
773 If nil, do not use any predefined list subscriptions. This list of
774 regular expressions can be used in conjuction with
775 `message-subscribed-address-functions' and `message-subscribed-addresses'."
776 :group 'message-interface
777 :type '(repeat regexp))
779 (defcustom message-allow-no-recipients 'ask
780 "Specifies what to do when there are no recipients other than Gcc/Fcc.
781 If it is the symbol `always', the posting is allowed. If it is the
782 symbol `never', the posting is not allowed. If it is the symbol
783 `ask', you are prompted."
784 :group 'message-interface
785 :type '(choice (const always)
789 (defcustom message-sendmail-f-is-evil nil
790 "*Non-nil means don't add \"-f username\" to the sendmail command line.
791 Doing so would be even more evil than leaving it out."
792 :group 'message-sending
795 ;; qmail-related stuff
796 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
797 "Location of the qmail-inject program."
798 :group 'message-sending
801 (defcustom message-qmail-inject-args nil
802 "Arguments passed to qmail-inject programs.
803 This should be a list of strings, one string for each argument. It
804 may also be a function.
806 For e.g., if you wish to set the envelope sender address so that bounces
807 go to the right place or to deal with listserv's usage of that address, you
808 might set this variable to '(\"-f\" \"you@some.where\")."
809 :group 'message-sending
810 :type '(choice (function)
813 (defvar message-cater-to-broken-inn t
814 "Non-nil means Gnus should not fold the `References' header.
815 Folding `References' makes ancient versions of INN create incorrect
819 (defvar gnus-post-method)
820 (defvar gnus-select-method))
821 (defcustom message-post-method
822 (cond ((and (boundp 'gnus-post-method)
823 (listp gnus-post-method)
826 ((boundp 'gnus-select-method)
829 "*Method used to post news.
830 Note that when posting from inside Gnus, for instance, this
831 variable isn't used."
833 :group 'message-sending
834 ;; This should be the `gnus-select-method' widget, but that might
835 ;; create a dependence to `gnus.el'.
838 (defcustom message-generate-headers-first nil
839 "*If non-nil, generate all required headers before composing.
840 The variables `message-required-news-headers' and
841 `message-required-mail-headers' specify which headers to generate.
842 This can also be a list of headers that should be generated before
845 Note that the variable `message-deletable-headers' specifies headers which
846 are to be deleted and then re-generated before sending, so this variable
847 will not have a visible effect for those headers."
848 :group 'message-headers
849 :type '(choice (const :tag "None" nil)
851 (repeat (sexp :tag "Header"))))
853 (defcustom message-setup-hook '(turn-on-mime-edit)
854 "Normal hook, run each time a new outgoing message is initialized.
855 The function `message-setup' runs this hook."
856 :group 'message-various
859 (defcustom message-cancel-hook nil
860 "Hook run when cancelling articles."
861 :group 'message-various
864 (defcustom message-signature-setup-hook nil
865 "Normal hook, run each time a new outgoing message is initialized.
866 It is run after the headers have been inserted and before
867 the signature is inserted."
868 :group 'message-various
871 (defcustom message-bounce-setup-hook nil
872 "Normal hook, run each time a re-sending bounced message is initialized.
873 The function `message-bounce' runs this hook."
874 :group 'message-various
877 (defcustom message-supersede-setup-hook nil
878 "Normal hook, run each time a supersede message is initialized.
879 The function `message-supersede' runs this hook."
880 :group 'message-various
883 (defcustom message-mode-hook nil
884 "Hook run in message mode buffers."
885 :group 'message-various
888 (defcustom message-header-hook '((lambda () (mime-encode-header-in-buffer t)))
889 "Hook run in a message mode buffer narrowed to the headers."
890 :group 'message-various
893 (defcustom message-header-setup-hook nil
894 "Hook called narrowed to the headers when setting up a message buffer."
895 :group 'message-various
898 (defcustom message-minibuffer-local-map
899 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
900 (set-keymap-parent map minibuffer-local-map)
902 "Keymap for `message-read-from-minibuffer'.")
905 (defcustom message-citation-line-function 'message-insert-citation-line
906 "*Function called to insert the \"Whomever writes:\" line.
908 Note that Gnus provides a feature where the reader can click on
909 `writes:' to hide the cited text. If you change this line too much,
910 people who read your message will have to change their Gnus
911 configuration. See the variable `gnus-cite-attribution-suffix'."
913 :group 'message-insertion)
916 (defcustom message-yank-prefix "> "
917 "*Prefix inserted on the lines of yanked messages.
918 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
919 See also `message-yank-cited-prefix'."
921 :group 'message-insertion)
923 (defcustom message-yank-add-new-references t
924 "Non-nil means new IDs will be added to \"References\" field when an
925 article is yanked by the command `message-yank-original' interactively.
926 If it is a symbol `message-id-only', only an ID from \"Message-ID\" field
927 is used, otherwise IDs extracted from \"References\", \"In-Reply-To\" and
928 \"Message-ID\" fields are used."
929 :type '(radio (const :tag "Do not add anything" nil)
930 (const :tag "From Message-Id, References and In-Reply-To fields" t)
931 (const :tag "From only Message-Id field." message-id-only))
932 :group 'message-insertion)
934 (defcustom message-list-references-add-position nil
935 "Integer value means position for adding to \"References\" field when
936 an article is yanked by the command `message-yank-original' interactively."
937 :type '(radio (const :tag "Add to last" nil)
938 (integer :tag "Position from last ID"))
939 :group 'message-insertion)
941 (defcustom message-yank-cited-prefix ">"
942 "*Prefix inserted on cited or empty lines of yanked messages.
943 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
944 See also `message-yank-prefix'."
946 :group 'message-insertion)
948 (defcustom message-indentation-spaces 3
949 "*Number of spaces to insert at the beginning of each cited line.
950 Used by `message-yank-original' via `message-yank-cite'."
951 :group 'message-insertion
955 (defcustom message-cite-function 'message-cite-original
956 "*Function for citing an original message.
957 Predefined functions include `message-cite-original' and
958 `message-cite-original-without-signature'.
959 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
960 :type '(radio (function-item message-cite-original)
961 (function-item message-cite-original-without-signature)
962 (function-item mu-cite-original)
963 (function-item sc-cite-original)
964 (function :tag "Other"))
965 :group 'message-insertion)
968 (defcustom message-suspend-font-lock-when-citing nil
969 "Non-nil means suspend font-lock'ing while citing an original message.
970 Some lazy demand-driven fontification tools (or Emacs itself) have a
971 bug that they often miss a buffer to be fontified. It will mostly
972 occur when Emacs prompts user for any inputs in the minibuffer.
973 Setting this option to non-nil may help you to avoid unpleasant errors
974 even if it is an add-hoc expedient."
976 :group 'message-insertion)
979 (defcustom message-indent-citation-function 'message-indent-citation
980 "*Function for modifying a citation just inserted in the mail buffer.
981 This can also be a list of functions. Each function can find the
982 citation between (point) and (mark t). And each function should leave
983 point and mark around the citation text as modified."
985 :group 'message-insertion)
988 (defcustom message-signature t
989 "*String to be inserted at the end of the message buffer.
990 If t, the `message-signature-file' file will be inserted instead.
991 If a function, the result from the function will be used instead.
992 If a form, the result from the form will be used instead."
994 :group 'message-insertion)
997 (defcustom message-signature-file "~/.signature"
998 "*Name of file containing the text inserted at end of message buffer.
999 Ignored if the named file doesn't exist.
1000 If nil, don't insert a signature."
1001 :type '(choice file (const :tags "None" nil))
1002 :group 'message-insertion)
1005 (defcustom message-signature-insert-empty-line t
1006 "*If non-nil, insert an empty line before the signature separator."
1008 :group 'message-insertion)
1010 (defcustom message-distribution-function nil
1011 "*Function called to return a Distribution header."
1012 :group 'message-news
1013 :group 'message-headers
1014 :type '(choice function (const nil)))
1016 (defcustom message-expires 14
1017 "Number of days before your article expires."
1018 :group 'message-news
1019 :group 'message-headers
1020 :link '(custom-manual "(message)News Headers")
1023 (defcustom message-user-path nil
1024 "If nil, use the NNTP server name in the Path header.
1025 If stringp, use this; if non-nil, use no host name (user name only)."
1026 :group 'message-news
1027 :group 'message-headers
1028 :link '(custom-manual "(message)News Headers")
1029 :type '(choice (const :tag "nntp" nil)
1030 (string :tag "name")
1031 (sexp :tag "none" :format "%t" t)))
1033 (defvar message-reply-buffer nil)
1034 (defvar message-reply-headers nil
1035 "The headers of the current replied article.
1036 It is a vector of the following headers:
1037 \[number subject from date id references chars lines xref extra].")
1038 (defvar message-sent-message-via nil)
1039 (defvar message-checksum nil)
1040 (defvar message-send-actions nil
1041 "A list of actions to be performed upon successful sending of a message.")
1042 (defvar message-exit-actions nil
1043 "A list of actions to be performed upon exiting after sending a message.")
1044 (defvar message-kill-actions nil
1045 "A list of actions to be performed before killing a message buffer.")
1046 (defvar message-postpone-actions nil
1047 "A list of actions to be performed after postponing a message.")
1048 (defvar message-original-frame nil)
1049 (defvar message-parameter-alist nil)
1050 (defvar message-startup-parameter-alist nil)
1052 (define-widget 'message-header-lines 'text
1053 "All header lines must be LFD terminated."
1054 :format "%{%t%}:%n%v"
1055 :valid-regexp "^\\'"
1056 :error "All header lines must be newline terminated")
1058 (defcustom message-default-headers ""
1059 "*A string containing header lines to be inserted in outgoing messages.
1060 It is inserted before you edit the message, so you can edit or delete
1062 :group 'message-headers
1063 :type 'message-header-lines)
1065 (defcustom message-default-mail-headers ""
1066 "*A string of header lines to be inserted in outgoing mails."
1067 :group 'message-headers
1068 :group 'message-mail
1069 :type 'message-header-lines)
1071 (defcustom message-default-news-headers ""
1072 "*A string of header lines to be inserted in outgoing news articles."
1073 :group 'message-headers
1074 :group 'message-news
1075 :type 'message-header-lines)
1077 ;; Note: could use /usr/ucb/mail instead of sendmail;
1078 ;; options -t, and -v if not interactive.
1079 (defcustom message-mailer-swallows-blank-line
1080 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1081 system-configuration)
1082 (file-readable-p "/etc/sendmail.cf")
1083 (let ((buffer (get-buffer-create " *temp*")))
1087 (insert-file-contents "/etc/sendmail.cf")
1088 (goto-char (point-min))
1089 (let ((case-fold-search nil))
1090 (re-search-forward "^OR\\>" nil t)))
1091 (kill-buffer buffer))))
1092 ;; According to RFC822, "The field-name must be composed of printable
1093 ;; ASCII characters (i. e., characters that have decimal values between
1094 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1096 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1097 "*Set this non-nil if the system's mailer runs the header and body together.
1098 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1099 The value should be an expression to test whether the problem will
1101 :group 'message-sending
1104 ;;; XXX: This symbol is overloaded! See below.
1105 (defvar message-user-agent nil
1106 "String of the form of PRODUCT/VERSION. Used for User-Agent header field.")
1108 (static-when (boundp 'MULE)
1109 (require 'reporter));; `define-mail-user-agent' is here.
1112 (define-mail-user-agent 'message-user-agent
1113 'message-mail 'message-send-and-exit
1114 'message-kill-buffer 'message-send-hook)
1116 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
1117 "If non-nil, delete the deletable headers before feeding to mh.")
1119 (defvar message-send-method-alist
1120 '((news message-news-p message-send-via-news)
1121 (mail message-mail-p message-send-via-mail))
1122 "Alist of ways to send outgoing messages.
1123 Each element has the form
1125 \(TYPE PREDICATE FUNCTION)
1127 where TYPE is a symbol that names the method; PREDICATE is a function
1128 called without any parameters to determine whether the message is
1129 a message of type TYPE; and FUNCTION is a function to be called if
1130 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1133 (defcustom message-mail-alias-type 'abbrev
1134 "*What alias expansion type to use in Message buffers.
1135 The default is `abbrev', which uses mailabbrev. nil switches
1138 :link '(custom-manual "(message)Mail Aliases")
1139 :type '(choice (const :tag "Use Mailabbrev" abbrev)
1140 (const :tag "No expansion" nil)))
1142 (defcustom message-auto-save-directory
1143 (file-name-as-directory (nnheader-concat message-directory "drafts"))
1144 "*Directory where Message auto-saves buffers if Gnus isn't running.
1145 If nil, Message won't auto-save."
1146 :group 'message-buffers
1147 :type '(choice directory (const :tag "Don't auto-save" nil)))
1149 (defcustom message-default-charset
1150 (and (featurep 'xemacs) (not (featurep 'mule)) 'iso-8859-1)
1151 "Default charset used in non-MULE XEmacsen."
1156 (defcustom message-dont-reply-to-names
1157 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
1158 "*A regexp specifying addresses to prune when doing wide replies.
1159 A value of nil means exclude your own user name only."
1162 :type '(choice (const :tag "Yourself" nil)
1165 (defvar message-shoot-gnksa-feet nil
1166 "*A list of GNKSA feet you are allowed to shoot.
1167 Gnus gives you all the opportunity you could possibly want for
1168 shooting yourself in the foot. Also, Gnus allows you to shoot the
1169 feet of Good Net-Keeping Seal of Approval. The following are foot
1171 `empty-article' Allow you to post an empty article;
1172 `quoted-text-only' Allow you to post quoted text only;
1173 `multiple-copies' Allow you to post multiple copies;
1174 `cancel-messages' Allow you to cancel or supersede messages from
1175 your other email addresses.")
1177 (defsubst message-gnksa-enable-p (feature)
1178 (or (not (listp message-shoot-gnksa-feet))
1179 (memq feature message-shoot-gnksa-feet)))
1181 ;;; Internal variables.
1182 ;;; Well, not really internal.
1184 (defvar message-mode-syntax-table
1185 (let ((table (copy-syntax-table text-mode-syntax-table)))
1186 (modify-syntax-entry ?% ". " table)
1187 (modify-syntax-entry ?> ". " table)
1188 (modify-syntax-entry ?< ". " table)
1190 "Syntax table used while in Message mode.")
1192 (defface message-header-to-face
1195 (:foreground "green2" :bold t))
1198 (:foreground "MidnightBlue" :bold t))
1200 (:bold t :italic t)))
1201 "Face used for displaying From headers."
1202 :group 'message-faces)
1204 (defface message-header-cc-face
1207 (:foreground "green4" :bold t))
1210 (:foreground "MidnightBlue"))
1213 "Face used for displaying Cc headers."
1214 :group 'message-faces)
1216 (defface message-header-subject-face
1219 (:foreground "green3"))
1222 (:foreground "navy blue" :bold t))
1225 "Face used for displaying subject headers."
1226 :group 'message-faces)
1228 (defface message-header-newsgroups-face
1231 (:foreground "yellow" :bold t :italic t))
1234 (:foreground "blue4" :bold t :italic t))
1236 (:bold t :italic t)))
1237 "Face used for displaying newsgroups headers."
1238 :group 'message-faces)
1240 (defface message-header-other-face
1243 (:foreground "#b00000"))
1246 (:foreground "steel blue"))
1248 (:bold t :italic t)))
1249 "Face used for displaying newsgroups headers."
1250 :group 'message-faces)
1252 (defface message-header-name-face
1255 (:foreground "DarkGreen"))
1258 (:foreground "cornflower blue"))
1261 "Face used for displaying header names."
1262 :group 'message-faces)
1264 (defface message-header-xheader-face
1267 (:foreground "blue"))
1270 (:foreground "blue"))
1273 "Face used for displaying X-Header headers."
1274 :group 'message-faces)
1276 (defface message-separator-face
1279 (:foreground "blue3"))
1282 (:foreground "brown"))
1285 "Face used for displaying the separator."
1286 :group 'message-faces)
1288 (defface message-cited-text-face
1291 (:foreground "red"))
1294 (:foreground "red"))
1297 "Face used for displaying cited text names."
1298 :group 'message-faces)
1300 (defface message-mml-face
1303 (:foreground "ForestGreen"))
1306 (:foreground "ForestGreen"))
1309 "Face used for displaying MML."
1310 :group 'message-faces)
1312 (defun message-font-lock-make-header-matcher (regexp)
1315 (let ((start (point)))
1318 (goto-char (point-min))
1319 (if (re-search-forward
1320 (concat "^" (regexp-quote mail-header-separator) "$")
1322 (setq limit (min limit (match-beginning 0))))
1324 (and (< start limit)
1325 (re-search-forward ,regexp limit t))))))
1326 (if (featurep 'bytecomp)
1330 (defvar message-font-lock-keywords
1331 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1332 `((,(message-font-lock-make-header-matcher
1333 (concat "^\\([Tt]o:\\)" content))
1334 (1 'message-header-name-face)
1335 (2 'message-header-to-face nil t))
1336 (,(message-font-lock-make-header-matcher
1337 (concat "^\\([GBF]?[Cc][Cc]:\\|[Rr]eply-[Tt]o:\\|"
1338 "[Mm]ail-[Cc]opies-[Tt]o:\\|"
1339 "[Mm]ail-[Rr]eply-[Tt]o:\\|"
1340 "[Mm]ail-[Ff]ollowup-[Tt]o:\\)" content))
1341 (1 'message-header-name-face)
1342 (2 'message-header-cc-face nil t))
1343 (,(message-font-lock-make-header-matcher
1344 (concat "^\\([Ss]ubject:\\)" content))
1345 (1 'message-header-name-face)
1346 (2 'message-header-subject-face nil t))
1347 (,(message-font-lock-make-header-matcher
1348 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content))
1349 (1 'message-header-name-face)
1350 (2 'message-header-newsgroups-face nil t))
1351 (,(message-font-lock-make-header-matcher
1352 (concat "^\\([A-Z][^: \n\t]+:\\)" content))
1353 (1 'message-header-name-face)
1354 (2 'message-header-other-face nil t))
1355 (,(message-font-lock-make-header-matcher
1356 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content))
1357 (1 'message-header-name-face)
1358 (2 'message-header-name-face))
1359 ,@(if (and mail-header-separator
1360 (not (equal mail-header-separator "")))
1361 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1362 1 'message-separator-face))
1365 (re-search-forward (concat "^\\("
1366 message-cite-prefix-regexp
1369 (0 'message-cited-text-face))
1370 (,mime-edit-tag-regexp
1371 (0 'message-mml-face))))
1372 "Additional expressions to highlight in Message mode.")
1374 ;; XEmacs does it like this. For Emacs, we have to set the
1375 ;; `font-lock-defaults' buffer-local variable.
1376 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
1378 (defvar message-face-alist
1379 '((bold . bold-region)
1380 (underline . underline-region)
1381 (default . (lambda (b e)
1383 (ununderline-region b e))))
1384 "Alist of mail and news faces for facemenu.
1385 The cdr of each entry is a function for applying the face to a region.")
1387 (defcustom message-send-hook nil
1388 "Hook run before sending messages.
1389 This hook is run quite early when sending."
1390 :group 'message-various
1391 :options '(ispell-message)
1394 (defcustom message-send-mail-hook nil
1395 "Hook run before sending mail messages.
1396 This hook is run very late -- just before the message is sent as
1398 :group 'message-various
1401 (defcustom message-send-news-hook nil
1402 "Hook run before sending news messages.
1403 This hook is run very late -- just before the message is sent as
1405 :group 'message-various
1408 (defcustom message-sent-hook nil
1409 "Hook run after sending messages."
1410 :group 'message-various
1413 (defcustom message-use-multi-frames nil
1414 "Make new frame when sending messages."
1415 :group 'message-frames
1418 (defcustom message-delete-frame-on-exit nil
1419 "Delete frame after sending messages."
1420 :group 'message-frames
1421 :type '(choice (const :tag "off" nil)
1422 (const :tag "always" t)
1423 (const :tag "ask" ask)))
1425 (defvar message-draft-coding-system
1426 nnheader-auto-save-coding-system
1427 "*Coding system to compose mail.
1428 If you'd like to make it possible to share draft files between XEmacs
1429 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1430 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1432 (defcustom message-send-mail-partially-limit 1000000
1433 "The limitation of messages sent as message/partial.
1434 The lower bound of message size in characters, beyond which the message
1435 should be sent in several parts. If it is nil, the size is unlimited."
1437 :group 'message-buffers
1438 :type '(choice (const :tag "unlimited" nil)
1441 (defcustom message-alternative-emails nil
1442 "A regexp to match the alternative email addresses.
1443 The first matched address (not primary one) is used in the From field."
1444 :group 'message-headers
1445 :type '(choice (const :tag "Always use primary" nil)
1448 (defcustom message-hierarchical-addresses nil
1449 "A list of hierarchical mail address definitions.
1451 Inside each entry, the first address is the \"top\" address, and
1452 subsequent addresses are subaddresses; this is used to indicate that
1453 mail sent to the first address will automatically be delivered to the
1454 subaddresses. So if the first address appears in the recipient list
1455 for a message, the subaddresses will be removed (if present) before
1456 the mail is sent. All addresses in this structure should be
1458 :group 'message-headers
1459 :type '(repeat (repeat string)))
1461 (defcustom message-mail-user-agent nil
1462 "Like `mail-user-agent'.
1463 Except if it is nil, use Gnus native MUA; if it is t, use
1465 :type '(radio (const :tag "Gnus native"
1468 (const :tag "`mail-user-agent'"
1471 (function-item :tag "Default Emacs mail"
1473 sendmail-user-agent)
1474 (function-item :tag "Emacs interface to MH"
1477 (function :tag "Other"))
1481 (defcustom message-wide-reply-confirm-recipients nil
1482 "Whether to confirm a wide reply to multiple email recipients.
1483 If this variable is nil, don't ask whether to reply to all recipients.
1484 If this variable is non-nil, pose the question \"Reply to all
1485 recipients?\" before a wide reply to multiple recipients. If the user
1486 answers yes, reply to all recipients as usual. If the user answers
1487 no, only reply back to the author."
1489 :group 'message-headers
1492 ;;; Internal variables.
1494 (defvar message-sending-message "Sending...")
1495 (defvar message-buffer-list nil)
1496 (defvar message-this-is-news nil)
1497 (defvar message-this-is-mail nil)
1498 (defvar message-draft-article nil)
1499 (defvar message-mime-part nil)
1500 (defvar message-posting-charset nil)
1502 ;; Byte-compiler warning
1504 (defvar gnus-active-hashtb)
1505 (defvar gnus-read-active-file))
1507 ;;; Regexp matching the delimiter of messages in UNIX mail format
1508 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1509 ;;; of rmail.el's rmail-unix-mail-delimiter.
1510 (defvar message-unix-mail-delimiter
1511 (let ((time-zone-regexp
1512 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1513 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1519 ;; Many things can happen to an RFC 822 mailbox before it is put into
1520 ;; a `From' line. The leading phrase can be stripped, e.g.
1521 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1522 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1523 ;; can be removed, e.g.
1524 ;; From: joe@y.z (Joe K
1526 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1529 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1530 ;; The mailbox can be removed or be replaced by white space, e.g.
1531 ;; From: "Joe User"{space}{tab}
1533 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1534 ;; where {space} and {tab} represent the Ascii space and tab characters.
1535 ;; We want to match the results of any of these manglings.
1536 ;; The following regexp rejects names whose first characters are
1537 ;; obviously bogus, but after that anything goes.
1538 "\\([^\0-\b\n-\r\^?].*\\)? "
1540 ;; The time the message was sent.
1541 "\\([^\0-\r \^?]+\\) +" ; day of the week
1542 "\\([^\0-\r \^?]+\\) +" ; month
1543 "\\([0-3]?[0-9]\\) +" ; day of month
1544 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1546 ;; Perhaps a time zone, specified by an abbreviation, or by a
1551 " \\([0-9][0-9]+\\) *"
1553 ;; On some systems the time zone can appear after the year, too.
1557 "\\(remote from .*\\)?"
1560 "Regexp matching the delimiter of messages in UNIX mail format.")
1562 (defvar message-unsent-separator
1563 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1564 "^ *---+ +Returned message +---+ *$\\|"
1565 "^Start of returned message$\\|"
1566 "^ *---+ +Original message +---+ *$\\|"
1567 "^ *--+ +begin message +--+ *$\\|"
1568 "^ *---+ +Original message follows +---+ *$\\|"
1569 "^ *---+ +Undelivered message follows +---+ *$\\|"
1570 "^|? *---+ +Message text follows: +---+ *|?$")
1571 "A regexp that matches the separator before the text of a failed message.")
1573 (defvar message-header-format-alist
1575 (To . message-fill-address)
1576 (Cc . message-fill-address)
1587 (References . message-shorten-references)
1589 "Alist used for formatting headers.")
1591 (defvar message-options nil
1592 "Some saved answers when sending message.")
1594 (defvar message-send-mail-real-function nil
1595 "Internal send mail function.")
1597 (defvar message-bogus-system-names "^localhost\\."
1598 "The regexp of bogus system names.")
1601 (autoload 'message-setup-toolbar "messagexmas")
1602 (autoload 'mh-new-draft-name "mh-comp")
1603 (autoload 'mh-send-letter "mh-comp")
1604 (autoload 'gnus-point-at-eol "gnus-util")
1605 (autoload 'gnus-point-at-bol "gnus-util")
1606 (autoload 'gnus-output-to-rmail "gnus-util")
1607 (autoload 'gnus-output-to-mail "gnus-util")
1608 (autoload 'nndraft-request-associate-buffer "nndraft")
1609 (autoload 'nndraft-request-expire-articles "nndraft")
1610 (autoload 'gnus-open-server "gnus-int")
1611 (autoload 'gnus-request-post "gnus-int")
1612 (autoload 'gnus-copy-article-buffer "gnus-msg")
1613 (autoload 'gnus-alive-p "gnus-util")
1614 (autoload 'gnus-server-string "gnus")
1615 (autoload 'gnus-group-name-charset "gnus-group")
1616 (autoload 'gnus-group-name-decode "gnus-group")
1617 (autoload 'gnus-groups-from-server "gnus")
1618 (autoload 'rmail-output "rmailout")
1619 (autoload 'gnus-delay-article "gnus-delay")
1620 (autoload 'mu-cite-original "mu-cite"))
1625 ;;; Utility functions.
1627 (defun message-eval-parameter (parameter)
1629 (if (symbolp parameter)
1630 (if (functionp parameter)
1636 (defsubst message-get-parameter (key &optional alist)
1638 (setq alist message-parameter-alist))
1639 (cdr (assq key alist)))
1641 (defmacro message-get-parameter-with-eval (key &optional alist)
1642 `(message-eval-parameter (message-get-parameter ,key ,alist)))
1644 (defmacro message-y-or-n-p (question show &rest text)
1645 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1646 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1648 (defmacro message-delete-line (&optional n)
1649 "Delete the current line (and the next N lines)."
1650 `(delete-region (progn (beginning-of-line) (point))
1651 (progn (forward-line ,(or n 1)) (point))))
1653 (defun message-mark-active-p ()
1654 "Non-nil means the mark and region are currently active in this buffer."
1657 (defun message-unquote-tokens (elems)
1658 "Remove double quotes (\") from strings in list ELEMS."
1659 (mapcar (lambda (item)
1660 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1661 (setq item (concat (match-string 1 item)
1662 (match-string 2 item))))
1666 (defun message-tokenize-header (header &optional separator)
1667 "Split HEADER into a list of header elements.
1668 SEPARATOR is a string of characters to be used as separators. \",\"
1669 is used by default."
1672 (let ((regexp (format "[%s]+" (or separator ",")))
1677 (message-set-work-buffer)
1679 (goto-char (point-min))
1684 (cond ((and (> (point) beg)
1686 (and (looking-at regexp)
1689 (push (buffer-substring beg (point)) elems)
1690 (setq beg (match-end 0)))
1691 ((eq (char-after) ?\")
1692 (setq quoted (not quoted)))
1693 ((and (eq (char-after) ?\()
1696 ((and (eq (char-after) ?\))
1699 (nreverse elems)))))
1701 (defun message-mail-file-mbox-p (file)
1702 "Say whether FILE looks like a Unix mbox file."
1703 (when (and (file-exists-p file)
1704 (file-readable-p file)
1705 (file-regular-p file))
1707 (nnheader-insert-file-contents file)
1708 (goto-char (point-min))
1709 (looking-at message-unix-mail-delimiter))))
1711 (defun message-fetch-field (header &optional not-all)
1712 "The same as `mail-fetch-field', only remove all newlines."
1713 (let* ((inhibit-point-motion-hooks t)
1714 (case-fold-search t)
1715 (value (mail-fetch-field header nil (not not-all))))
1717 (while (string-match "\n[\t ]+" value)
1718 (setq value (replace-match " " t t value)))
1719 (set-text-properties 0 (length value) nil value)
1722 (defun message-narrow-to-field ()
1723 "Narrow the buffer to the header on the current line."
1729 (if (re-search-forward "^[^ \n\t]" nil t)
1734 (goto-char (point-min)))
1736 (defun message-add-header (&rest headers)
1737 "Add the HEADERS to the message header, skipping those already present."
1740 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1741 (error "Invalid header `%s'" (car headers)))
1742 (setq hclean (match-string 1 (car headers)))
1744 (message-narrow-to-headers)
1745 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1746 (goto-char (point-max))
1747 (if (string-match "\n$" (car headers))
1748 (insert (car headers))
1749 (insert (car headers) ?\n)))))
1750 (setq headers (cdr headers))))
1752 (defmacro message-with-reply-buffer (&rest forms)
1753 "Evaluate FORMS in the reply buffer, if it exists."
1754 `(let ((buffer (message-eval-parameter message-reply-buffer)))
1756 (buffer-name buffer))
1761 (put 'message-with-reply-buffer 'lisp-indent-function 0)
1762 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
1764 (defun message-fetch-reply-field (header)
1765 "Fetch field HEADER from the message we're replying to."
1766 (message-with-reply-buffer
1768 (mail-narrow-to-head)
1769 (message-fetch-field header))))
1771 (defun message-set-work-buffer ()
1772 (if (get-buffer " *message work*")
1774 (set-buffer " *message work*")
1776 (set-buffer (get-buffer-create " *message work*"))
1777 (kill-all-local-variables)))
1779 (defun message-functionp (form)
1780 "Return non-nil if FORM is funcallable."
1781 (or (and (symbolp form) (fboundp form))
1782 (and (listp form) (eq (car form) 'lambda))
1783 (byte-code-function-p form)))
1785 (defun message-strip-list-identifiers (subject)
1786 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1787 (require 'gnus-sum) ; for gnus-list-identifiers
1788 (let ((regexp (if (stringp gnus-list-identifiers)
1789 gnus-list-identifiers
1790 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1791 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1792 " *\\)\\)+\\(Re: +\\)?\\)") subject)
1793 (concat (substring subject 0 (match-beginning 1))
1794 (or (match-string 3 subject)
1795 (match-string 5 subject))
1800 (defun message-strip-subject-re (subject)
1801 "Remove \"Re:\" from subject lines in string SUBJECT."
1802 (if (string-match message-subject-re-regexp subject)
1803 (substring subject (match-end 0))
1806 ;;; Start of functions adopted from `message-utils.el'.
1808 (defun message-strip-subject-trailing-was (subject)
1809 "Remove trailing \"(Was: <old subject>)\" from SUBJECT lines.
1810 Leading \"Re: \" is not stripped by this function. Use the function
1811 `message-strip-subject-re' for this."
1812 (let* ((query message-subject-trailing-was-query)
1817 message-subject-trailing-was-ask-regexp
1818 message-subject-trailing-was-regexp)
1821 (setq new (substring subject 0 (match-beginning 0))))
1822 (if (or (not found) (eq query nil))
1825 (if (message-y-or-n-p
1826 "Strip `(was: <old subject>)' in subject? " t
1828 "Strip `(was: <old subject>)' in subject "
1829 "and use the new one instead?\n\n"
1830 "Current subject is: \""
1832 "New subject would be: \""
1834 "See the variable `message-subject-trailing-was-query' "
1835 "to get rid of this query."
1840 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
1843 (defun message-change-subject (new-subject)
1844 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
1847 (read-from-minibuffer "New subject: ")))
1848 (cond ((and (not (or (null new-subject) ; new subject not empty
1849 (zerop (string-width new-subject))
1850 (string-match "^[ \t]*$" new-subject))))
1852 (let ((old-subject (message-fetch-field "Subject")))
1853 (cond ((not old-subject)
1854 (error "No current subject"))
1857 (regexp-quote new-subject)
1859 old-subject)) ; yes, it really is a new subject
1860 ;; delete eventual Re: prefix
1862 (message-strip-subject-re old-subject))
1863 (message-goto-subject)
1864 (message-delete-line)
1865 (insert (concat "Subject: "
1868 old-subject ")\n")))))))))
1871 (defun message-mark-inserted-region (beg end)
1872 "Mark some region in the current article with enclosing tags.
1873 See `message-mark-insert-begin' and `message-mark-insert-end'."
1876 ; add to the end of the region first, otherwise end would be invalid
1878 (insert message-mark-insert-end)
1880 (insert message-mark-insert-begin)))
1883 (defun message-mark-insert-file (file)
1884 "Insert FILE at point, marking it with enclosing tags.
1885 See `message-mark-insert-begin' and `message-mark-insert-end'."
1886 (interactive "fFile to insert: ")
1887 ;; reverse insertion to get correct result.
1889 (insert message-mark-insert-end)
1891 (insert-file-contents file)
1893 (insert message-mark-insert-begin)))
1896 (defun message-add-archive-header ()
1897 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
1898 The note can be customized using `message-archive-note'. When called with a
1899 prefix argument, ask for a text to insert. If you don't want the note in the
1900 body, set `message-archive-note' to nil."
1902 (if current-prefix-arg
1903 (setq message-archive-note
1904 (read-from-minibuffer "Reason for No-Archive: "
1905 (cons message-archive-note 0))))
1907 (if (message-goto-signature)
1908 (re-search-backward message-signature-separator))
1909 (when message-archive-note
1910 (insert message-archive-note)
1912 (message-add-header message-archive-header)
1913 (message-sort-headers)))
1916 (defun message-cross-post-followup-to-header (target-group)
1917 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
1918 With prefix-argument just set Follow-Up, don't cross-post."
1920 (list ; Completion based on Gnus
1921 (completing-read "Followup To: "
1922 (if (boundp 'gnus-newsrc-alist)
1924 nil nil '("poster" . 0)
1925 (if (boundp 'gnus-group-history)
1926 'gnus-group-history))))
1927 (message-remove-header "Follow[Uu]p-[Tt]o" t)
1928 (message-goto-newsgroups)
1930 ;; if we already did a crosspost before, kill old target
1931 (if (and message-cross-post-old-target
1933 (regexp-quote (concat "," message-cross-post-old-target))
1936 ;; unless (followup is to poster or user explicitly asked not
1937 ;; to cross-post, or target-group is already in Newsgroups)
1938 ;; add target-group to Newsgroups line.
1940 ;; def: cross-post, req:no
1941 (and message-cross-post-default (not current-prefix-arg))
1942 ;; def: no-cross-post, req:yes
1943 (and (not message-cross-post-default) current-prefix-arg))
1944 (not (string-match "poster" target-group))
1945 (not (string-match (regexp-quote target-group)
1946 (message-fetch-field "Newsgroups"))))
1948 (insert-string (concat "," target-group))))
1949 (end-of-line) ; ensure Followup: comes after Newsgroups:
1950 ;; unless new followup would be identical to Newsgroups line
1951 ;; make a new Followup-To line
1952 (if (not (string-match (concat "^[ \t]*"
1955 (message-fetch-field "Newsgroups")))
1956 (insert (concat "\nFollowup-To: " target-group)))
1957 (setq message-cross-post-old-target target-group))
1960 (defun message-cross-post-insert-note (target-group cross-post in-old
1962 "Insert a in message body note about a set Followup or Crosspost.
1963 If there have been previous notes, delete them. TARGET-GROUP specifies the
1964 group to Followup-To. When CROSS-POST is t, insert note about
1965 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
1966 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
1967 been made to before the user asked for a Crosspost."
1968 ;; start scanning body for previous uses
1969 (message-goto-signature)
1970 (let ((head (re-search-backward
1971 (concat "^" mail-header-separator)
1972 nil t))) ; just search in body
1973 (message-goto-signature)
1974 (while (re-search-backward
1975 (concat "^" (regexp-quote message-cross-post-note) ".*")
1977 (message-delete-line))
1978 (message-goto-signature)
1979 (while (re-search-backward
1980 (concat "^" (regexp-quote message-followup-to-note) ".*")
1982 (message-delete-line))
1984 (if (message-goto-signature)
1985 (re-search-backward message-signature-separator))
1988 (string-match "^[ \t]*poster[ \t]*$" target-group))
1989 (insert (concat message-followup-to-note target-group "\n"))
1990 (insert (concat message-cross-post-note target-group "\n")))))
1993 (defun message-cross-post-followup-to (target-group)
1994 "Crossposts message and set Followup-To to TARGET-GROUP.
1995 With prefix-argument just set Follow-Up, don't cross-post."
1997 (list ; Completion based on Gnus
1998 (completing-read "Followup To: "
1999 (if (boundp 'gnus-newsrc-alist)
2001 nil nil '("poster" . 0)
2002 (if (boundp 'gnus-group-history)
2003 'gnus-group-history))))
2004 (cond ((not (or (null target-group) ; new subject not empty
2005 (zerop (string-width target-group))
2006 (string-match "^[ \t]*$" target-group)))
2008 (let* ((old-groups (message-fetch-field "Newsgroups"))
2009 (in-old (string-match
2010 (regexp-quote target-group)
2011 (or old-groups ""))))
2012 ;; check whether target exactly matches old Newsgroups
2013 (cond ((not old-groups)
2014 (error "No current newsgroup"))
2018 (regexp-quote target-group)
2021 ;; yes, Newsgroups line must change
2022 (message-cross-post-followup-to-header target-group)
2023 ;; insert note whether we do cross-post or followup-to
2024 (funcall message-cross-post-note-function
2026 (if (or (and message-cross-post-default
2027 (not current-prefix-arg))
2028 (and (not message-cross-post-default)
2029 current-prefix-arg)) t)
2030 in-old old-groups))))))))
2032 ;;; Reduce To: to Cc: or Bcc: header
2035 (defun message-reduce-to-to-cc ()
2036 "Replace contents of To: header with contents of Cc: or Bcc: header."
2038 (let ((cc-content (message-fetch-field "cc"))
2040 (if (and (not cc-content)
2041 (setq cc-content (message-fetch-field "bcc")))
2046 (message-delete-line)
2047 (insert (concat "To: " cc-content "\n"))
2048 (message-remove-header (if bcc
2052 ;;; End of functions adopted from `message-utils.el'.
2054 (defun message-remove-header (header &optional is-regexp first reverse)
2055 "Remove HEADER in the narrowed buffer.
2056 If IS-REGEXP, HEADER is a regular expression.
2057 If FIRST, only remove the first instance of the header.
2058 Return the number of headers removed."
2059 (goto-char (point-min))
2060 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
2062 (case-fold-search t)
2064 (while (and (not (eobp))
2067 (not (looking-at regexp))
2068 (looking-at regexp))
2075 ;; There might be a continuation header, so we have to search
2076 ;; until we find a new non-continuation line.
2079 (if (re-search-forward "^[^ \t]" nil t)
2080 (goto-char (match-beginning 0))
2083 (if (re-search-forward "^[^ \t]" nil t)
2084 (goto-char (match-beginning 0))
2085 (goto-char (point-max)))))
2088 (defun message-remove-first-header (header)
2089 "Remove the first instance of HEADER if there is more than one."
2091 (regexp (concat "^" (regexp-quote header) ":")))
2093 (goto-char (point-min))
2094 (while (re-search-forward regexp nil t)
2097 (message-remove-header header nil t)
2100 (defun message-narrow-to-headers ()
2101 "Narrow the buffer to the head of the message."
2104 (goto-char (point-min))
2105 (if (re-search-forward
2106 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2109 (goto-char (point-min)))
2111 (defun message-narrow-to-head-1 ()
2112 "Like `message-narrow-to-head'. Don't widen."
2114 (goto-char (point-min))
2115 (if (search-forward "\n\n" nil 1)
2118 (goto-char (point-min)))
2120 (defun message-narrow-to-head ()
2121 "Narrow the buffer to the head of the message.
2122 Point is left at the beginning of the narrowed-to region."
2124 (message-narrow-to-head-1))
2126 (defun message-narrow-to-headers-or-head ()
2127 "Narrow the buffer to the head of the message."
2130 (goto-char (point-min))
2133 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2134 (match-beginning 0))
2135 ((search-forward "\n\n" nil t)
2139 (goto-char (point-min)))
2141 (defun message-news-p ()
2142 "Say whether the current buffer contains a news message."
2143 (and (not message-this-is-mail)
2144 (or message-this-is-news
2147 (message-narrow-to-headers)
2148 (and (message-fetch-field "newsgroups")
2149 (not (message-fetch-field "posted-to"))))))))
2151 (defun message-mail-p ()
2152 "Say whether the current buffer contains a mail message."
2153 (and (not message-this-is-news)
2154 (or message-this-is-mail
2157 (message-narrow-to-headers)
2158 (or (message-fetch-field "to")
2159 (message-fetch-field "cc")
2160 (message-fetch-field "bcc")))))))
2162 (defun message-subscribed-p ()
2163 "Say whether we need to insert a MFT header."
2164 (or message-subscribed-regexps
2165 message-subscribed-addresses
2166 message-subscribed-address-file
2167 message-subscribed-address-functions))
2169 (defun message-next-header ()
2170 "Go to the beginning of the next header."
2172 (or (eobp) (forward-char 1))
2173 (not (if (re-search-forward "^[^ \t]" nil t)
2175 (goto-char (point-max)))))
2177 (defun message-sort-headers-1 ()
2178 "Sort the buffer as headers using `message-rank' text props."
2179 (goto-char (point-min))
2182 nil 'message-next-header
2184 (message-next-header)
2188 (or (get-text-property (point) 'message-rank)
2191 (defun message-sort-headers ()
2192 "Sort the headers of the current message according to `message-header-format-alist'."
2196 (let ((max (1+ (length message-header-format-alist)))
2198 (message-narrow-to-headers)
2199 (while (re-search-forward "^[^ \n]+:" nil t)
2201 (match-beginning 0) (1+ (match-beginning 0))
2203 (if (setq rank (length (memq (assq (intern (buffer-substring
2205 (1- (match-end 0))))
2206 message-header-format-alist)
2207 message-header-format-alist)))
2210 (message-sort-headers-1))))
2220 (defvar message-mode-map nil)
2222 (unless message-mode-map
2223 (setq message-mode-map (make-keymap))
2224 (set-keymap-parent message-mode-map text-mode-map)
2225 (define-key message-mode-map "\C-c?" 'describe-mode)
2227 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
2228 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
2229 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
2230 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
2231 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
2232 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2233 ;; (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2234 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-mail-reply-to)
2235 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2236 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2237 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2238 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2239 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2240 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2241 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2242 (define-key message-mode-map "\C-c\C-f\C-i"
2243 'message-insert-or-toggle-importance)
2244 (define-key message-mode-map "\C-c\C-f\C-a"
2245 'message-generate-unsubscribed-mail-followup-to)
2247 ;; modify headers (and insert notes in body)
2248 (define-key message-mode-map "\C-c\C-fs" 'message-change-subject)
2250 (define-key message-mode-map "\C-c\C-fx" 'message-cross-post-followup-to)
2251 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2252 (define-key message-mode-map "\C-c\C-ft" 'message-reduce-to-to-cc)
2253 (define-key message-mode-map "\C-c\C-fa" 'message-add-archive-header)
2254 ;; mark inserted text
2255 (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2256 (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2258 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2259 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2260 (define-key message-mode-map "\C-c\C-fc" 'message-goto-mail-copies-to)
2262 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2263 (define-key message-mode-map "\C-c\C-fw" 'message-insert-wide-reply)
2264 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2265 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2267 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2268 (define-key message-mode-map "\C-c\M-n"
2269 'message-insert-disposition-notification-to)
2271 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2272 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2273 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2274 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2275 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2276 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2277 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2278 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2280 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2281 (define-key message-mode-map "\C-c\C-s" 'message-send)
2282 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2283 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2284 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2286 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2287 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2288 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2289 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2290 ;;(define-key message-mode-map "\M-q" 'message-fill-paragraph)
2292 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2293 (define-key message-mode-map "\t" 'message-tab)
2294 (define-key message-mode-map "\M-;" 'comment-region)
2296 (define-key message-mode-map "\C-xk" 'message-mimic-kill-buffer))
2299 message-mode-menu message-mode-map "Message Menu."
2301 ["Yank Original" message-yank-original t]
2302 ["Fill Yanked Message" message-fill-yanked-message t]
2303 ["Insert Signature" message-insert-signature t]
2304 ["Caesar (rot13) Message" message-caesar-buffer-body t]
2305 ["Caesar (rot13) Region" message-caesar-region (message-mark-active-p)]
2306 ["Elide Region" message-elide-region
2307 :active (message-mark-active-p)
2308 ,@(if (featurep 'xemacs) nil
2309 '(:help "Replace text in region with an ellipsis"))]
2310 ["Delete Outside Region" message-delete-not-region
2311 :active (message-mark-active-p)
2312 ,@(if (featurep 'xemacs) nil
2313 '(:help "Delete all quoted text outside region"))]
2314 ["Kill To Signature" message-kill-to-signature t]
2315 ["Newline and Reformat" message-newline-and-reformat t]
2316 ["Rename buffer" message-rename-buffer t]
2317 ["Spellcheck" ispell-message
2318 ,@(if (featurep 'xemacs) '(t)
2319 '(:help "Spellcheck this message"))]
2320 ["Attach file as MIME" mime-edit-insert-file
2321 ,@(if (featurep 'xemacs) '(t)
2322 '(:help "Attach a file at point"))]
2324 ["Insert Region Marked" message-mark-inserted-region
2325 :active (message-mark-active-p)
2326 ,@(if (featurep 'xemacs) nil
2327 '(:help "Mark region with enclosing tags"))]
2328 ["Insert File Marked..." message-mark-insert-file
2329 ,@(if (featurep 'xemacs) '(t)
2330 '(:help "Insert file at point marked with enclosing tags"))]
2332 ["Send Message" message-send-and-exit
2333 ,@(if (featurep 'xemacs) '(t)
2334 '(:help "Send this message"))]
2335 ["Postpone Message" message-dont-send
2336 ,@(if (featurep 'xemacs) '(t)
2337 '(:help "File this draft message and exit"))]
2338 ["Send at Specific Time..." gnus-delay-article
2339 ,@(if (featurep 'xemacs) '(t)
2340 '(:help "Ask, then arrange to send message at that time"))]
2341 ["Kill Message" message-kill-buffer
2342 ,@(if (featurep 'xemacs) '(t)
2343 '(:help "Delete this message without sending"))]))
2346 message-mode-field-menu message-mode-map ""
2348 ["Fetch To" message-insert-to t]
2349 ["Fetch Newsgroups" message-insert-newsgroups t]
2351 ["To" message-goto-to t]
2352 ["From" message-goto-from t]
2353 ["Subject" message-goto-subject t]
2354 ["Change subject..." message-change-subject t]
2355 ["Cc" message-goto-cc t]
2356 ["Bcc" message-goto-bcc t]
2357 ["Fcc" message-goto-fcc t]
2358 ["Reply-To" message-goto-reply-to t]
2359 ["Flag As Important" message-insert-importance-high
2360 ,@(if (featurep 'xemacs) '(t)
2361 '(:help "Mark this message as important"))]
2362 ["Flag As Unimportant" message-insert-importance-low
2363 ,@(if (featurep 'xemacs) '(t)
2364 '(:help "Mark this message as unimportant"))]
2366 message-insert-disposition-notification-to
2367 ,@(if (featurep 'xemacs) '(t)
2368 '(:help "Request a receipt notification"))]
2370 ;; (typical) news stuff
2371 ["Summary" message-goto-summary t]
2372 ["Keywords" message-goto-keywords t]
2373 ["Newsgroups" message-goto-newsgroups t]
2374 ["Followup-To" message-goto-followup-to t]
2375 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2376 ["Crosspost / Followup-To..." message-cross-post-followup-to t]
2377 ["Distribution" message-goto-distribution t]
2378 ["X-No-Archive:" message-add-archive-header t ]
2380 ;; (typical) mailing-lists stuff
2381 ["Send to list only" message-to-list-only t]
2382 ["Mail-Followup-To" message-goto-mail-followup-to t]
2383 ["Mail-Reply-To" message-goto-mail-reply-to t]
2384 ["Mail-Copies-To" message-goto-mail-copies-to t]
2385 ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2387 ["Sort Headers" message-sort-headers t]
2388 ["Goto Body" message-goto-body t]
2389 ["Goto Signature" message-goto-signature t]))
2391 (defvar message-tool-bar-map nil)
2394 (defvar facemenu-add-face-function)
2395 (defvar facemenu-remove-face-function))
2397 ;;; Forbidden properties
2399 ;; We use `after-change-functions' to keep special text properties
2400 ;; that interfer with the normal function of message mode out of the
2403 (defcustom message-strip-special-text-properties t
2404 "Strip special properties from the message buffer.
2406 Emacs has a number of special text properties which can break message
2407 composing in various ways. If this option is set, message will strip
2408 these properties from the message composition buffer. However, some
2409 packages requires these properties to be present in order to work.
2410 If you use one of these packages, turn this option off, and hope the
2411 message composition doesn't break too bad."
2412 :group 'message-various
2415 (defconst message-forbidden-properties
2416 ;; No reason this should be clutter up customize. We make it a
2417 ;; property list (rather than a list of property symbols), to be
2418 ;; directly useful for `remove-text-properties'.
2419 '(field nil read-only nil intangible nil invisible nil
2420 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2421 insert-behind-hooks nil point-entered nil point-left nil)
2422 ;; Other special properties:
2423 ;; category, face, display: probably doesn't do any harm.
2424 ;; fontified: is used by font-lock.
2425 ;; syntax-table, local-map: I dunno.
2426 ;; We need to add XEmacs names to the list.
2427 "Property list of with properties.forbidden in message buffers.
2428 The values of the properties are ignored, only the property names are used.")
2430 (defun message-tamago-not-in-use-p (pos)
2431 "Return t when tamago version 4 is not in use at the cursor position.
2432 Tamago version 4 is a popular input method for writing Japanese text.
2433 It uses the properties `intangible', `invisible', `modification-hooks'
2434 and `read-only' when translating ascii or kana text to kanji text.
2435 These properties are essential to work, so we should never strip them."
2436 (not (and (boundp 'egg-modefull-mode)
2437 (symbol-value 'egg-modefull-mode)
2438 (or (memq (get-text-property pos 'intangible)
2439 '(its-part-1 its-part-2))
2440 (get-text-property pos 'egg-end)
2441 (get-text-property pos 'egg-lang)
2442 (get-text-property pos 'egg-start)))))
2444 (defun message-strip-forbidden-properties (begin end &optional old-length)
2445 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2446 This function is intended to be called from `after-change-functions'.
2447 See also `message-forbidden-properties'."
2448 (when (and message-strip-special-text-properties
2449 (message-tamago-not-in-use-p begin)
2450 ;; Check whether the invisible MIME part is not inserted.
2451 (not (text-property-any begin end 'mime-edit-invisible t)))
2452 (remove-text-properties begin end message-forbidden-properties)))
2455 (define-derived-mode message-mode text-mode "Message"
2456 "Major mode for editing mail and news to be sent.
2457 Like Text Mode but with these additional commands:\\<message-mode-map>
2458 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2459 C-c C-d Postpone sending the message C-c C-k Kill the message
2460 C-c C-f move to a header field (and create it if there isn't):
2461 C-c C-f C-t move to To C-c C-f C-s move to Subject
2462 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2463 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2464 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2465 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2466 C-c C-f C-o move to From (\"Originator\")
2467 C-c C-f C-f move to Followup-To
2468 C-c C-f C-m move to Mail-Followup-To
2469 C-c C-f c move to Mail-Copies-To
2470 C-c C-f C-i cycle through Importance values
2471 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2472 C-c C-f x crossposting with FollowUp-To header and note in body
2473 C-c C-f t replace To: header with contents of Cc: or Bcc:
2474 C-c C-f a Insert X-No-Archive: header and a note in the body
2475 C-c C-t `message-insert-to' (add a To header to a news followup)
2476 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2477 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2478 C-c C-b `message-goto-body' (move to beginning of message text).
2479 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2480 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2481 C-c C-y `message-yank-original' (insert current message, if any).
2482 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2483 C-c C-e `message-elide-region' (elide the text between point and mark).
2484 C-c C-v `message-delete-not-region' (remove the text outside the region).
2485 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2486 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2487 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2488 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2489 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2490 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2491 M-RET `message-newline-and-reformat' (break the line and reformat)."
2492 (setq local-abbrev-table text-mode-abbrev-table)
2493 (set (make-local-variable 'message-reply-buffer) nil)
2494 (make-local-variable 'message-send-actions)
2495 (make-local-variable 'message-exit-actions)
2496 (make-local-variable 'message-kill-actions)
2497 (make-local-variable 'message-postpone-actions)
2498 (make-local-variable 'message-draft-article)
2499 (setq buffer-offer-save t)
2500 (set (make-local-variable 'facemenu-add-face-function)
2502 (let ((face-fun (cdr (assq face message-face-alist))))
2504 (funcall face-fun (point) end)
2505 (error "Face %s not configured for %s mode" face mode-name)))
2507 (set (make-local-variable 'facemenu-remove-face-function) t)
2508 (set (make-local-variable 'message-reply-headers) nil)
2509 (make-local-variable 'message-user-agent)
2510 (make-local-variable 'message-post-method)
2511 (set (make-local-variable 'message-sent-message-via) nil)
2512 (set (make-local-variable 'message-checksum) nil)
2513 (make-local-variable 'message-parameter-alist)
2514 (setq message-parameter-alist
2515 (copy-sequence message-startup-parameter-alist))
2516 (message-setup-fill-variables)
2517 ;; Allow using comment commands to add/remove quoting.
2518 (set (make-local-variable 'comment-start) message-yank-prefix)
2519 (if (featurep 'xemacs)
2520 (message-setup-toolbar)
2521 (set (make-local-variable 'font-lock-defaults)
2522 '(message-font-lock-keywords t))
2523 (if (boundp 'tool-bar-map)
2524 (set (make-local-variable 'tool-bar-map) (message-tool-bar-map))))
2525 (easy-menu-add message-mode-menu message-mode-map)
2526 (easy-menu-add message-mode-field-menu message-mode-map)
2527 ;; make-local-hook is harmless though obsolete in Emacs 21.
2528 ;; Emacs 20 and XEmacs need make-local-hook.
2529 (make-local-hook 'after-change-functions)
2530 ;; Mmmm... Forbidden properties...
2531 (add-hook 'after-change-functions 'message-strip-forbidden-properties
2533 ;; Allow mail alias things.
2534 (when (eq message-mail-alias-type 'abbrev)
2535 (if (fboundp 'mail-abbrevs-setup)
2536 (mail-abbrevs-setup)
2537 (mail-aliases-setup)))
2538 (unless buffer-file-name
2539 (message-set-auto-save-file-name))
2540 (set (make-local-variable 'indent-tabs-mode) nil)) ;No tabs for indentation.
2542 (defun message-setup-fill-variables ()
2543 "Setup message fill variables."
2544 (set (make-local-variable 'fill-paragraph-function)
2545 'message-fill-paragraph)
2546 (make-local-variable 'paragraph-separate)
2547 (make-local-variable 'paragraph-start)
2548 (make-local-variable 'adaptive-fill-regexp)
2549 (unless (boundp 'adaptive-fill-first-line-regexp)
2550 (setq adaptive-fill-first-line-regexp nil))
2551 (make-local-variable 'adaptive-fill-first-line-regexp)
2552 (let ((quote-prefix-regexp
2553 ;; User should change message-cite-prefix-regexp if
2554 ;; message-yank-prefix is set to an abnormal value.
2555 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
2556 (setq paragraph-start
2558 (regexp-quote mail-header-separator) "$\\|"
2559 "[ \t]*$\\|" ; blank lines
2560 "-- $\\|" ; signature delimiter
2561 "---+$\\|" ; delimiters for forwarded messages
2562 page-delimiter "$\\|" ; spoiler warnings
2563 ".*wrote:$\\|" ; attribution lines
2564 quote-prefix-regexp "$")) ; empty lines in quoted text
2565 (setq paragraph-separate paragraph-start)
2566 (setq adaptive-fill-regexp
2567 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
2568 (setq adaptive-fill-first-line-regexp
2569 (concat quote-prefix-regexp "\\|"
2570 adaptive-fill-first-line-regexp)))
2571 (make-local-variable 'auto-fill-inhibit-regexp)
2572 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2573 (setq auto-fill-inhibit-regexp nil)
2574 (make-local-variable 'normal-auto-fill-function)
2575 (setq normal-auto-fill-function 'message-do-auto-fill)
2576 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2577 ;; In that case, ensure that it uses the right function. The real
2578 ;; solution would be not to use `define-derived-mode', and run
2579 ;; `text-mode-hook' ourself at the end of the mode.
2580 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2581 (when auto-fill-function
2582 (setq auto-fill-function normal-auto-fill-function)))
2587 ;;; Message mode commands
2590 ;;; Movement commands
2592 (defun message-goto-to ()
2593 "Move point to the To header."
2595 (message-position-on-field "To"))
2597 (defun message-goto-from ()
2598 "Move point to the From header."
2600 (message-position-on-field "From"))
2602 (defun message-goto-subject ()
2603 "Move point to the Subject header."
2605 (message-position-on-field "Subject"))
2607 (defun message-goto-cc ()
2608 "Move point to the Cc header."
2610 (message-position-on-field "Cc" "To"))
2612 (defun message-goto-bcc ()
2613 "Move point to the Bcc header."
2615 (message-position-on-field "Bcc" "Cc" "To"))
2617 (defun message-goto-fcc ()
2618 "Move point to the Fcc header."
2620 (message-position-on-field "Fcc" "To" "Newsgroups"))
2622 (defun message-goto-reply-to ()
2623 "Move point to the Reply-To header."
2625 (message-position-on-field "Reply-To" "Subject"))
2627 (defun message-goto-mail-reply-to ()
2628 "Move point to the Mail-Reply-To header."
2630 (message-position-on-field "Mail-Reply-To" "Subject"))
2632 (defun message-goto-mail-copies-to ()
2633 "Move point to the Mail-Copies-To header. If the header is newly created,
2634 a string \"never\" is inserted in default."
2636 (unless (message-position-on-field "Mail-Copies-To" "Subject")
2640 (defun message-goto-newsgroups ()
2641 "Move point to the Newsgroups header."
2643 (message-position-on-field "Newsgroups"))
2645 (defun message-goto-distribution ()
2646 "Move point to the Distribution header."
2648 (message-position-on-field "Distribution"))
2650 (defun message-goto-followup-to ()
2651 "Move point to the Followup-To header."
2653 (message-position-on-field "Followup-To" "Newsgroups"))
2655 (defun message-goto-mail-followup-to ()
2656 "Move point to the Mail-Followup-To header. If the header is newly created
2657 and To field contains only one address, the address is inserted in default."
2659 (unless (message-position-on-field "Mail-Followup-To" "Subject")
2660 (let ((start (point))
2663 (message-narrow-to-headers)
2664 (setq addresses (split-string (mail-strip-quoted-names
2665 (or (std11-fetch-field "to") ""))
2667 (when (eq 1 (length addresses))
2669 (insert (car addresses))
2670 (goto-char start))))))
2672 (defun message-goto-keywords ()
2673 "Move point to the Keywords header."
2675 (message-position-on-field "Keywords" "Subject"))
2677 (defun message-goto-summary ()
2678 "Move point to the Summary header."
2680 (message-position-on-field "Summary" "Subject"))
2682 (defun message-goto-body (&optional interactivep)
2683 "Move point to the beginning of the message body."
2684 (interactive (list t))
2685 (when (and interactivep
2686 (looking-at "[ \t]*\n"))
2688 (goto-char (point-min))
2689 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
2690 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
2692 (defun message-goto-eoh ()
2693 "Move point to the end of the headers."
2698 (defun message-goto-signature ()
2699 "Move point to the beginning of the message signature.
2700 If there is no signature in the article, go to the end and
2703 (goto-char (point-min))
2704 (if (re-search-forward message-signature-separator nil t)
2706 (goto-char (point-max))
2709 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc)
2710 "Insert a reasonable MFT header in a post to an unsubscribed list.
2711 When making original posts to a mailing list you are not subscribed to,
2712 you have to type in a MFT header by hand. The contents, usually, are
2713 the addresses of the list and your own address. This function inserts
2714 such a header automatically. It fetches the contents of the To: header
2715 in the current mail buffer, and appends the current `user-mail-address'.
2717 If the optional argument INCLUDE-CC is non-nil, the addresses in the
2718 Cc: header are also put into the MFT."
2721 (message-remove-header "Mail-Followup-To")
2722 (let* ((cc (and include-cc (message-fetch-field "Cc")))
2724 (concat (message-fetch-field "To") "," cc)
2725 (message-fetch-field "To"))))
2726 (message-goto-mail-followup-to)
2727 (insert (concat tos ", " user-mail-address))))
2731 (defun message-insert-to (&optional force)
2732 "Insert a To header that points to the author of the article being replied to.
2733 If the original author requested not to be sent mail, the function signals
2735 With the prefix argument FORCE, insert the header anyway."
2737 (let ((co (message-fetch-reply-field "mail-copies-to")))
2738 (when (and (null force)
2740 (or (equal (downcase co) "never")
2741 (equal (downcase co) "nobody")))
2742 (error "The user has requested not to have copies sent via mail")))
2743 (message-carefully-insert-headers
2745 (or (message-fetch-reply-field "mail-reply-to")
2746 (message-fetch-reply-field "reply-to")
2747 (message-fetch-reply-field "from")
2750 (defun message-insert-wide-reply ()
2751 "Insert To and Cc headers as if you were doing a wide reply."
2753 (let ((headers (message-with-reply-buffer
2754 (message-get-reply-headers t))))
2755 (message-carefully-insert-headers headers)))
2757 (defun message-carefully-insert-headers (headers)
2758 (dolist (header headers)
2759 (let ((header-name (symbol-name (car header))))
2760 (when (and (message-position-on-field header-name)
2761 (mail-fetch-field header-name)
2762 (not (string-match "\\` *\\'"
2763 (mail-fetch-field header-name))))
2765 (insert (cdr header)))))
2767 (defun message-widen-reply ()
2768 "Widen the reply to include maximum recipients."
2771 (and message-reply-buffer
2772 (buffer-name message-reply-buffer)
2774 (set-buffer message-reply-buffer)
2775 (message-get-reply-headers t)))))
2778 (message-narrow-to-headers)
2779 (dolist (elem follow-to)
2780 (message-remove-header (symbol-name (car elem)))
2781 (goto-char (point-min))
2782 (insert (symbol-name (car elem)) ": "
2783 (cdr elem) "\n"))))))
2785 (defun message-insert-newsgroups ()
2786 "Insert the Newsgroups header from the article being replied to."
2788 (when (and (message-position-on-field "Newsgroups")
2789 (mail-fetch-field "newsgroups")
2790 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
2792 (insert (or (message-fetch-reply-field "newsgroups") "")))
2796 ;;; Various commands
2798 (defun message-delete-not-region (beg end)
2799 "Delete everything in the body of the current message outside of the region."
2804 ;; snarf citation prefix, if appropriate
2805 (unless (eq (point) (progn (beginning-of-line) (point)))
2806 (when (looking-at message-cite-prefix-regexp)
2807 (setq citeprefix (match-string 0))))
2809 (delete-region (point) (if (not (message-goto-signature))
2815 (delete-region beg (progn (message-goto-body)
2819 (insert citeprefix))))
2820 (when (message-goto-signature)
2823 (defun message-kill-to-signature ()
2824 "Deletes all text up to the signature."
2826 (let ((point (point)))
2827 (message-goto-signature)
2830 (kill-region point (point))
2834 (defun message-newline-and-reformat (&optional arg not-break)
2835 "Insert four newlines, and then reformat if inside quoted text.
2836 Prefix arg means justify as well."
2837 (interactive (list (if current-prefix-arg 'full)))
2838 (let (quoted point beg end leading-space bolp)
2839 (setq point (point))
2842 (setq bolp (= beg point))
2843 ;; Find first line of the paragraph.
2845 (while (and (not (eobp))
2846 (not (looking-at message-cite-prefix-regexp))
2847 (looking-at paragraph-start))
2850 (when (looking-at message-cite-prefix-regexp)
2851 (setq quoted (match-string 0))
2852 (goto-char (match-end 0))
2853 (looking-at "[ \t]*")
2854 (setq leading-space (match-string 0)))
2858 (< (- point beg) (length quoted)))
2859 ;; break inside the cite prefix.
2865 (while (and (not (eobp))
2866 (not (looking-at paragraph-separate))
2867 (looking-at message-cite-prefix-regexp)
2868 (equal quoted (match-string 0)))
2869 (goto-char (match-end 0))
2870 (looking-at "[ \t]*")
2871 (if (> (length leading-space) (length (match-string 0)))
2872 (setq leading-space (match-string 0)))
2876 (while (and (if (bobp) nil (forward-line -1) t)
2877 (not (looking-at paragraph-start))
2878 (looking-at message-cite-prefix-regexp)
2879 (equal quoted (match-string 0)))
2881 (goto-char (match-end 0))
2882 (looking-at "[ \t]*")
2883 (if (> (length leading-space) (length (match-string 0)))
2884 (setq leading-space (match-string 0)))))
2885 (while (and (not (eobp))
2886 (not (looking-at paragraph-separate))
2887 (not (looking-at message-cite-prefix-regexp)))
2891 (while (and (if (bobp) nil (forward-line -1) t)
2892 (not (looking-at paragraph-start))
2893 (not (looking-at message-cite-prefix-regexp)))
2894 (setq beg (point))))
2897 (narrow-to-region beg end)
2904 (setq point (point))
2905 ;; (newline 2) doesn't mark both newline's as hard, so call
2906 ;; newline twice. -jas
2909 (delete-region (point) (re-search-forward "[ \t]*"))
2910 (when (and quoted (not bolp))
2911 (insert quoted leading-space)))
2913 (let* ((adaptive-fill-regexp
2914 (regexp-quote (concat quoted leading-space)))
2915 (adaptive-fill-first-line-regexp
2916 adaptive-fill-regexp ))
2917 (fill-paragraph arg))
2918 (fill-paragraph arg))
2919 (if point (goto-char point)))))
2921 (defun message-fill-paragraph (&optional arg)
2922 "Like `fill-paragraph'."
2923 (interactive (list (if current-prefix-arg 'full)))
2924 (if (and (boundp 'filladapt-mode) filladapt-mode)
2926 (message-newline-and-reformat arg t)
2929 ;; Is it better to use `mail-header-end'?
2930 (defun message-point-in-header-p ()
2931 "Return t if point is in the header."
2934 (goto-char (point-min))
2935 (not (re-search-forward
2936 (concat "^" (regexp-quote mail-header-separator) "\n")
2939 (defun message-do-auto-fill ()
2940 "Like `do-auto-fill', but don't fill in message header."
2941 (unless (message-point-in-header-p)
2944 (defun message-insert-signature (&optional force)
2945 "Insert a signature. See documentation for variable `message-signature'."
2946 (interactive (list 0))
2949 ((and (null message-signature)
2952 (goto-char (point-max))
2953 (not (re-search-backward message-signature-separator nil t))))
2954 ((and (null message-signature)
2957 ((message-functionp message-signature)
2958 (funcall message-signature))
2959 ((listp message-signature)
2960 (eval message-signature))
2961 (t message-signature)))
2963 (cond ((stringp signature)
2965 ((and (eq t signature)
2966 message-signature-file
2967 (file-exists-p message-signature-file))
2970 (goto-char (point-max))
2971 ;; Insert the signature.
2974 (when message-signature-insert-empty-line
2976 (insert "\n" message-signature-separator-for-insertion)
2979 (if (eq signature t)
2980 (insert-file-contents message-signature-file)
2982 (goto-char (point-max))
2983 (or (bolp) (insert "\n")))))
2985 (defun message-insert-importance-high ()
2986 "Insert header to mark message as important."
2989 (message-remove-header "Importance")
2991 (insert "Importance: high\n")))
2993 (defun message-insert-importance-low ()
2994 "Insert header to mark message as unimportant."
2997 (message-remove-header "Importance")
2999 (insert "Importance: low\n")))
3001 (defun message-insert-or-toggle-importance ()
3002 "Insert a \"Importance: high\" header, or cycle through the header values.
3003 The three allowed values according to RFC 1327 are `high', `normal'
3007 (let ((valid '("high" "normal" "low"))
3010 (when (setq cur (message-fetch-field "Importance"))
3011 (message-remove-header "Importance")
3012 (setq new (cond ((string= cur "high")
3014 ((string= cur "low")
3019 (insert (format "Importance: %s\n" new)))))
3021 (defun message-insert-disposition-notification-to ()
3022 "Request a disposition notification (return receipt) to this message.
3023 Note that this should not be used in newsgroups."
3026 (message-remove-header "Disposition-Notification-To")
3028 (insert (format "Disposition-Notification-To: %s\n"
3029 (or (message-fetch-field "From") (message-make-from))))))
3031 (defun message-elide-region (b e)
3032 "Elide the text in the region.
3033 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3037 (insert message-elide-ellipsis))
3039 (defvar message-caesar-translation-table nil)
3041 (defun message-caesar-region (b e &optional n)
3042 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3045 (min (point) (or (mark t) (point)))
3046 (max (point) (or (mark t) (point)))
3047 (when current-prefix-arg
3048 (prefix-numeric-value current-prefix-arg))))
3050 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
3051 (unless (or (zerop n) ; no action needed for a rot of 0
3052 (= b e)) ; no region to rotate
3053 ;; We build the table, if necessary.
3054 (when (or (not message-caesar-translation-table)
3055 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
3056 (setq message-caesar-translation-table
3057 (message-make-caesar-translation-table n)))
3058 (translate-region b e message-caesar-translation-table)))
3060 (defun message-make-caesar-translation-table (n)
3061 "Create a rot table with offset N."
3063 (table (make-string 256 0)))
3064 (while (< (incf i) 256)
3067 (substring table 0 ?A)
3068 (substring table (+ ?A n) (+ ?A n (- 26 n)))
3069 (substring table ?A (+ ?A n))
3070 (substring table (+ ?A 26) ?a)
3071 (substring table (+ ?a n) (+ ?a n (- 26 n)))
3072 (substring table ?a (+ ?a n))
3073 (substring table (+ ?a 26) 255))))
3075 (defun message-caesar-buffer-body (&optional rotnum)
3076 "Caesar rotate all letters in the current buffer by 13 places.
3077 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3078 With prefix arg, specifies the number of places to rotate each letter forward.
3079 Mail and USENET news headers are not rotated."
3080 (interactive (if current-prefix-arg
3081 (list (prefix-numeric-value current-prefix-arg))
3085 (when (message-goto-body)
3086 (narrow-to-region (point) (point-max)))
3087 (message-caesar-region (point-min) (point-max) rotnum))))
3089 (defun message-pipe-buffer-body (program)
3090 "Pipe the message body in the current buffer through PROGRAM."
3093 (when (message-goto-body)
3094 (narrow-to-region (point) (point-max)))
3095 (shell-command-on-region
3096 (point-min) (point-max) program nil t))))
3098 (defun message-rename-buffer (&optional enter-string)
3099 "Rename the *message* buffer to \"*message* RECIPIENT\".
3100 If the function is run with a prefix, it will ask for a new buffer
3101 name, rather than giving an automatic name."
3102 (interactive "Pbuffer name: ")
3105 (goto-char (point-min))
3106 (narrow-to-region (point)
3107 (search-forward mail-header-separator nil 'end))
3109 (if (message-news-p) (message-fetch-field "Newsgroups")
3110 (message-fetch-field "To"))
3113 (if (string-match "," mail-to)
3114 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
3116 (name-default (concat "*message* " mail-trimmed-to))
3117 (name (if enter-string
3118 (read-string "New buffer name: " name-default)
3120 (rename-buffer name t)))))
3122 (defun message-fill-yanked-message (&optional justifyp)
3123 "Fill the paragraphs of a message yanked into this one.
3124 Numeric argument means justify as well."
3127 (goto-char (point-min))
3128 (search-forward (concat "\n" mail-header-separator "\n") nil t)
3129 (let ((fill-prefix message-yank-prefix))
3130 (fill-individual-paragraphs (point) (point-max) justifyp))))
3132 (defun message-indent-citation ()
3133 "Modify text just inserted from a message to be cited.
3134 The inserted text should be the region.
3135 When this function returns, the region is again around the modified text.
3137 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3138 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3139 (let ((start (point)))
3140 ;; Remove unwanted headers.
3141 (when message-ignored-cited-headers
3146 (if (search-forward "\n\n" nil t)
3149 (message-remove-header message-ignored-cited-headers t)
3150 (when (= (point-min) (point-max))
3151 (setq all-removed t))
3152 (goto-char (point-max)))
3156 ;; Delete blank lines at the start of the buffer.
3157 (while (and (point-min)
3160 (message-delete-line))
3161 ;; Delete blank lines at the end of the buffer.
3162 (goto-char (point-max))
3165 (while (and (zerop (forward-line -1))
3167 (message-delete-line))
3168 ;; Do the indentation.
3169 (if (null message-yank-prefix)
3170 (indent-rigidly start (mark t) message-indentation-spaces)
3173 (while (< (point) (mark t))
3174 (if (or (looking-at ">") (looking-at "^$"))
3175 (insert message-yank-cited-prefix)
3176 (insert message-yank-prefix))
3180 (defun message-list-references (refs-list &rest refs-strs)
3181 "Add `Message-ID's which appear in REFS-STRS but not in REFS-LIST,
3183 (let (refs ref id saved-id)
3184 (when (and refs-list
3185 (integerp message-list-references-add-position))
3186 (let ((pos message-list-references-add-position))
3187 (while (and refs-list
3189 (push (pop refs-list) saved-id)
3190 (setq pos (1- pos)))))
3192 (when (setq refs (pop refs-strs))
3193 (setq refs (std11-parse-msg-ids (std11-lexical-analyze refs)))
3195 (when (eq (car (setq ref (pop refs))) 'msg-id)
3196 (setq id (concat "<" (mapconcat 'cdr (cdr ref) "") ">"))
3197 (or (member id refs-list)
3198 (member id saved-id)
3199 (push id refs-list))))))
3201 (push (pop saved-id) refs-list))
3204 (defvar gnus-article-copy)
3205 (defun message-yank-original (&optional arg)
3206 "Insert the message being replied to, if any.
3207 Puts point before the text and mark after.
3208 Normally indents each nonblank line ARG spaces (default 3). However,
3209 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3211 This function uses `message-cite-function' to do the actual citing.
3213 Just \\[universal-argument] as argument means don't indent, insert no
3214 prefix, and don't delete any headers.
3216 In addition, if `message-yank-add-new-references' is non-nil and this
3217 command is called interactively, new IDs from the yanked article will
3218 be added to \"References\" field.
3219 \(See also `message-yank-add-new-references'.)"
3221 (let ((modified (buffer-modified-p))
3222 (buffer (message-eval-parameter message-reply-buffer))
3225 message-cite-function)
3226 (delete-windows-on buffer t)
3227 (insert-buffer buffer) ; mark will be set at the end of article.
3231 ;; Add new IDs to References field.
3232 (when (and message-yank-add-new-references (interactive-p))
3235 (message-narrow-to-headers)
3236 (setq refs (message-list-references
3238 (message-fetch-field "References")))
3240 (narrow-to-region start end)
3241 (std11-narrow-to-header)
3242 (when (setq refs (message-list-references
3244 (unless (eq message-yank-add-new-references
3246 (or (message-fetch-field "References")
3247 (message-fetch-field "In-Reply-To")))
3248 (message-fetch-field "Message-ID")))
3250 (message-narrow-to-headers)
3251 (goto-char (point-min))
3252 (let ((case-fold-search t))
3253 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
3255 (goto-char (point-max))))
3257 (list (or (assq 'References message-header-format-alist)
3258 '(References . message-fill-references)))
3259 (list (cons 'References
3260 (mapconcat 'identity (nreverse refs) " "))))
3261 (backward-delete-char 1)))))
3264 (if (and message-suspend-font-lock-when-citing
3265 (boundp 'font-lock-mode)
3266 (symbol-value 'font-lock-mode))
3271 (funcall message-cite-function))
3273 (funcall message-cite-function)))
3274 (message-exchange-point-and-mark)
3278 (setq message-checksum (message-checksum))))))
3280 (defun message-yank-buffer (buffer)
3281 "Insert BUFFER into the current buffer and quote it."
3282 (interactive "bYank buffer: ")
3283 (let ((message-reply-buffer buffer))
3284 (save-window-excursion
3285 (message-yank-original))))
3287 (defun message-buffers ()
3288 "Return a list of active message buffers."
3291 (dolist (buffer (buffer-list t))
3293 (when (and (eq major-mode 'message-mode)
3294 (null message-sent-message-via))
3295 (push (buffer-name buffer) buffers))))
3296 (nreverse buffers)))
3298 (defun message-cite-original-without-signature ()
3299 "Cite function in the standard Message manner."
3300 (let ((start (point))
3303 (when message-indent-citation-function
3304 (if (listp message-indent-citation-function)
3305 message-indent-citation-function
3306 (list message-indent-citation-function))))
3307 (message-reply-headers (or message-reply-headers
3308 (make-mail-header))))
3309 (mail-header-set-from message-reply-headers
3313 (if (search-forward "\n\n" nil t)
3316 (or (message-fetch-field "from")
3321 (when (re-search-backward message-signature-separator start t)
3322 ;; Also peel off any blank lines before the signature.
3324 (while (looking-at "^[ \t]*$")
3327 (delete-region (point) end)
3328 (unless (search-backward "\n\n" start t)
3329 ;; Insert a blank line if it is peeled off.
3333 (funcall (pop functions)))
3334 (when message-citation-line-function
3337 (funcall message-citation-line-function))))
3339 (eval-when-compile (defvar mail-citation-hook)) ;Compiler directive
3340 (defun message-cite-original ()
3341 "Cite function in the standard Message manner."
3342 (if (and (boundp 'mail-citation-hook)
3344 (run-hooks 'mail-citation-hook)
3345 (let ((start (point))
3348 (when message-indent-citation-function
3349 (if (listp message-indent-citation-function)
3350 message-indent-citation-function
3351 (list message-indent-citation-function))))
3352 (message-reply-headers (or message-reply-headers
3353 (make-mail-header))))
3354 (mail-header-set-from message-reply-headers
3358 (if (search-forward "\n\n" nil t)
3361 (or (message-fetch-field "from")
3365 (funcall (pop functions)))
3366 (when message-citation-line-function
3369 (funcall message-citation-line-function)))))
3371 (defun message-insert-citation-line ()
3372 "Insert a simple citation line."
3373 (when message-reply-headers
3374 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
3376 (defun message-position-on-field (header &rest afters)
3377 (let ((case-fold-search t))
3380 (goto-char (point-min))
3383 (concat "^" (regexp-quote mail-header-separator) "$"))
3384 (match-beginning 0)))
3385 (goto-char (point-min))
3386 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
3388 (re-search-forward "^[^ \t]" nil 'move)
3390 (skip-chars-backward "\n")
3393 (not (re-search-forward
3394 (concat "^" (regexp-quote (car afters)) ":")
3398 (re-search-forward "^[^ \t]" nil 'move)
3399 (beginning-of-line))
3400 (insert header ": \n")
3404 (defun message-remove-signature ()
3405 "Remove the signature from the text between point and mark.
3406 The text will also be indented the normal way."
3408 (let ((start (point))
3410 (if (not (re-search-forward message-signature-separator (mark t) t))
3411 ;; No signature here, so we just indent the cited text.
3412 (message-indent-citation)
3413 ;; Find the last non-empty line.
3415 (while (looking-at "[ \t]*$")
3418 (setq mark (set-marker (make-marker) (point)))
3420 (message-indent-citation)
3421 ;; Enable undoing the deletion.
3423 (delete-region mark (mark t))
3424 (set-marker mark nil)))))
3429 ;;; Sending messages
3432 ;; Avoid byte-compile warning.
3433 (defvar message-encoding-buffer nil)
3434 (defvar message-edit-buffer nil)
3435 (defvar message-mime-mode nil)
3437 (defun message-send-and-exit (&optional arg)
3438 "Send message like `message-send', then, if no errors, exit from mail buffer."
3440 (let ((buf (current-buffer))
3441 (actions message-exit-actions)
3442 (frame (selected-frame))
3443 (org-frame message-original-frame))
3444 (when (and (message-send arg)
3446 (if message-kill-buffer-on-exit
3449 (when (eq buf (current-buffer))
3450 (message-bury buf)))
3451 (message-do-actions actions)
3452 (message-delete-frame frame org-frame)
3455 (defun message-dont-send ()
3456 "Don't send the message you have been editing.
3457 Instead, just auto-save the buffer and then bury it."
3459 (set-buffer-modified-p t)
3461 (let ((actions message-postpone-actions)
3462 (frame (selected-frame))
3463 (org-frame message-original-frame))
3464 (message-bury (current-buffer))
3465 (message-do-actions actions)
3466 (message-delete-frame frame org-frame)))
3468 (defun message-kill-buffer ()
3469 "Kill the current buffer."
3471 (when (or (not (buffer-modified-p))
3472 (eq t message-kill-buffer-query-function)
3473 (funcall message-kill-buffer-query-function
3474 "The buffer modified; kill anyway? "))
3475 (let ((actions message-kill-actions)
3476 (draft-article message-draft-article)
3477 (auto-save-file-name buffer-auto-save-file-name)
3478 (file-name buffer-file-name)
3479 (modified (buffer-modified-p))
3480 (frame (selected-frame))
3481 (org-frame message-original-frame))
3482 (setq buffer-file-name nil)
3483 (kill-buffer (current-buffer))
3484 (when (and message-kill-buffer-and-remove-file
3485 (or (and auto-save-file-name
3486 (file-exists-p auto-save-file-name))
3488 (file-exists-p file-name)))
3489 (yes-or-no-p (format "Remove the backup file%s? "
3490 (if modified " too" ""))))
3492 (delete-file auto-save-file-name))
3493 (let ((message-draft-article draft-article))
3494 (message-disassociate-draft)))
3495 (message-do-actions actions)
3496 (message-delete-frame frame org-frame)))
3499 (defun message-mimic-kill-buffer ()
3500 "Kill the current buffer with query. This is an imitation for
3501 `kill-buffer', but it will delete a message frame."
3503 (let ((bufname (read-buffer (format "Kill buffer: (default %s) "
3505 message-kill-buffer-and-remove-file)
3506 (when (or (not bufname)
3507 (string-equal bufname "")
3508 (string-equal bufname (buffer-name)))
3509 (message-kill-buffer))))
3511 (defun message-delete-frame (frame org-frame)
3512 "Delete frame for editing message."
3513 (when (and (or (static-if (featurep 'xemacs)
3514 (device-on-window-system-p)
3516 (>= emacs-major-version 20))
3517 (or (and (eq message-delete-frame-on-exit t)
3518 (select-frame frame)
3519 (or (eq frame org-frame)
3521 (y-or-n-p "Delete this frame?")
3523 (and (eq message-delete-frame-on-exit 'ask)
3524 (select-frame frame)
3526 (y-or-n-p "Delete this frame?")
3528 (delete-frame frame)))
3530 (defun message-bury (buffer)
3531 "Bury this mail BUFFER."
3532 (let ((newbuf (other-buffer buffer)))
3533 (bury-buffer buffer)
3534 (if (and (fboundp 'frame-parameters)
3535 (cdr (assq 'dedicated (frame-parameters)))
3536 (not (null (delq (selected-frame) (visible-frame-list)))))
3537 (delete-frame (selected-frame))
3538 (switch-to-buffer newbuf))))
3540 (defun message-send (&optional arg)
3541 "Send the message in the current buffer.
3542 If `message-interactive' is non-nil, wait for success indication or
3543 error messages, and inform user.
3544 Otherwise any failure is reported in a message back to the user from
3546 The usage of ARG is defined by the instance that called Message.
3547 It should typically alter the sending method in some way or other."
3550 (when (or (buffer-modified-p)
3551 (message-check-element 'unchanged)
3552 (y-or-n-p "No changes in the buffer; really send? "))
3553 ;; Make it possible to undo the coming changes.
3555 (let ((inhibit-read-only t))
3556 (put-text-property (point-min) (point-max) 'read-only nil))
3557 (run-hooks 'message-send-hook)
3558 (message-fix-before-sending)
3559 (message message-sending-message)
3560 (let ((message-encoding-buffer
3561 (message-generate-new-buffer-clone-locals " message encoding"))
3562 (message-edit-buffer (current-buffer))
3563 (message-mime-mode mime-edit-mode-flag)
3564 (alist message-send-method-alist)
3566 elem sent dont-barf-on-no-method
3567 (message-options message-options))
3570 (message-options-set-recipient)
3572 (set-buffer message-encoding-buffer)
3574 ;; ;; Avoid copying text props (except hard newlines).
3575 ;; T-gnus change: copy all text props from the editing buffer
3576 ;; into the encoding buffer.
3577 (insert-buffer-substring message-edit-buffer)
3578 (funcall message-encode-function)
3580 (setq elem (pop alist)))
3581 (when (funcall (cadr elem))
3583 (or (not (memq (car elem)
3584 message-sent-message-via))
3585 (not (message-fetch-field "supersedes"))
3586 (if (or (message-gnksa-enable-p 'multiple-copies)
3587 (not (eq (car elem) 'news)))
3590 "Already sent message via %s; resend? "
3592 (error "Denied posting -- multiple copies")))
3593 (setq success (funcall (caddr elem) arg)))
3599 (let ((fcc (message-fetch-field "Fcc"))
3600 (gcc (message-fetch-field "Gcc")))
3603 (eq message-allow-no-recipients 'always)
3604 (and (not (eq message-allow-no-recipients 'never))
3605 (setq dont-barf-on-no-method
3607 (format "No receiver, perform %s anyway? "
3608 (cond ((and fcc gcc) "Fcc and Gcc")
3611 (error "No methods specified to send by"))
3612 (when (or dont-barf-on-no-method
3616 (run-hooks 'message-sent-hook))
3617 (message "Sending...done")
3618 ;; Mark the buffer as unmodified and delete auto-save.
3619 (set-buffer-modified-p nil)
3620 (delete-auto-save-file-if-necessary t)
3621 (message-disassociate-draft)
3622 ;; Delete other mail buffers and stuff.
3623 (message-do-send-housekeeping)
3624 (message-do-actions message-send-actions)
3627 (kill-buffer message-encoding-buffer)))))
3629 (defun message-send-via-mail (arg)
3630 "Send the current message via mail."
3631 (message-send-mail arg))
3633 (defun message-send-via-news (arg)
3634 "Send the current message via news."
3635 (message-send-news arg))
3637 (defmacro message-check (type &rest forms)
3638 "Eval FORMS if TYPE is to be checked."
3639 `(or (message-check-element ,type)
3643 (put 'message-check 'lisp-indent-function 1)
3644 (put 'message-check 'edebug-form-spec '(form body))
3646 ;; Advise the function `invisible-region'.
3647 (let (current-load-list)
3649 `(defadvice invisible-region (around add-mime-edit-invisible (start end)
3651 "Advised by T-gnus Message.
3652 Add the text property `mime-edit-invisible' to an invisible text when
3653 the buffer's major mode is `message-mode'. The added property will be
3654 used to distinguish whether the invisible text is a MIME part or not."
3655 ,(if (featurep 'xemacs)
3656 '(if (eq ?\n (char-after start))
3657 (setq start (1+ start)))
3658 '(if (eq ?\n (char-after (1- end)))
3659 (setq end (1- end))))
3660 (setq ad-return-value
3661 (if (eq 'message-mode major-mode)
3662 (add-text-properties start end
3663 '(invisible t mime-edit-invisible t))
3664 (put-text-property start end 'invisible t))))))
3666 (defun message-text-with-property (prop)
3667 "Return a list of all points where the text has PROP."
3669 (point (point-min)))
3671 (while (< point (point-max))
3672 (when (get-text-property point prop)
3673 (push point points))
3677 (defun message-fix-before-sending ()
3678 "Do various things to make the message nice before sending it."
3679 ;; Make sure there's a newline at the end of the message.
3681 (goto-char (point-max))
3684 ;; Delete all invisible text except for the mime parts which might
3685 ;; be inserted by the MIME-Edit.
3686 (message-check 'invisible-text
3689 mime-from mime-to hidden-start)
3690 (while (setq from (text-property-any to (point-max) 'invisible t))
3691 (setq to (or (text-property-not-all from (point-max) 'invisible t)
3694 (while (setq mime-from (text-property-any mime-to to
3695 'mime-edit-invisible t))
3696 (when (> mime-from mime-to)
3697 (setq hidden-start (or hidden-start mime-to))
3698 (put-text-property mime-to mime-from 'invisible nil))
3699 (setq mime-to (or (text-property-not-all mime-from to
3700 'mime-edit-invisible t)
3702 (when (< mime-to to)
3703 (setq hidden-start (or hidden-start mime-to))
3704 (put-text-property mime-to to 'invisible nil)))
3706 (goto-char hidden-start)
3707 (set-window-start (selected-window) (gnus-point-at-bol))
3708 (unless (yes-or-no-p
3709 "Invisible text found and made visible; continue posting? ")
3710 (error "Invisible text found and made visible")))))
3711 (message-check 'illegible-text
3712 (let ((mm-7bit-chars "\x20-\x7f\r\n\t\x7\x8\xb\xc\x1f\x1b")
3715 (skip-chars-forward mm-7bit-chars)
3717 (when (let ((char (char-after)))
3718 (or (< (mm-char-int char) 128)
3719 (and (mm-multibyte-p)
3720 (memq (char-charset char)
3721 '(eight-bit-control eight-bit-graphic
3723 (add-text-properties (point) (1+ (point)) '(highlight t))
3726 (skip-chars-forward mm-7bit-chars))
3729 (gnus-multiple-choice
3730 "Illegible text found. Continue posting? "
3731 '((?d "Remove and continue posting")
3732 (?r "Replace with dots and continue posting")
3733 (?i "Ignore and continue posting")
3734 (?e "Continue editing"))))
3736 (error "Illegible text found"))
3738 (skip-chars-forward mm-7bit-chars)
3740 (when (let ((char (char-after)))
3741 (or (< (mm-char-int char) 128)
3742 (and (mm-multibyte-p)
3743 (memq (char-charset char)
3744 '(eight-bit-control eight-bit-graphic
3747 (remove-text-properties (point) (1+ (point)) '(highlight t))
3752 (skip-chars-forward mm-7bit-chars))))))
3754 (defun message-add-action (action &rest types)
3755 "Add ACTION to be performed when doing an exit of type TYPES."
3757 (add-to-list (intern (format "message-%s-actions" (pop types)))
3760 (defun message-delete-action (action &rest types)
3761 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
3764 (set (setq var (intern (format "message-%s-actions" (pop types))))
3765 (delq action (symbol-value var))))))
3767 (defun message-do-actions (actions)
3768 "Perform all actions in ACTIONS."
3769 ;; Now perform actions on successful sending.
3773 ;; A simple function.
3774 ((message-functionp (car actions))
3775 (funcall (car actions)))
3776 ;; Something to be evaled.
3778 (eval (car actions)))))
3781 (defsubst message-maybe-split-and-send-mail ()
3782 "Split a message if necessary, and send it via mail.
3783 Returns nil if sending succeeded, returns any string if sending failed.
3784 This sub function is for exclusive use of `message-send-mail'."
3785 (let ((mime-edit-split-ignored-field-regexp
3786 mime-edit-split-ignored-field-regexp)
3787 (case-fold-search t)
3789 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
3790 (setq mime-edit-split-ignored-field-regexp
3791 (concat (substring mime-edit-split-ignored-field-regexp
3792 0 (match-beginning 0))
3793 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
3794 "_so_don't_rape_it!"
3795 (substring mime-edit-split-ignored-field-regexp
3799 (catch 'message-sending-mail-failure
3800 (mime-edit-maybe-split-and-send
3805 (std11-narrow-to-header mail-header-separator)
3806 (goto-char (point-min))
3807 (when (re-search-forward "^Message-ID:" nil t)
3808 (delete-region (match-end 0) (std11-field-end))
3809 (insert " " (message-make-message-id))))
3811 (funcall (or message-send-mail-real-function
3812 message-send-mail-function))
3814 (throw 'message-sending-mail-failure err))))))
3818 (funcall (or message-send-mail-real-function
3819 message-send-mail-function))
3823 (if (eq 'error (car failure))
3825 (prin1-to-string failure)))))
3827 (defun message-send-mail-partially ()
3828 "Send mail as message/partial."
3829 ;; replace the header delimiter with a blank line
3830 (goto-char (point-min))
3832 (concat "^" (regexp-quote mail-header-separator) "\n"))
3833 (replace-match "\n")
3834 (run-hooks 'message-send-mail-hook)
3835 (let ((p (goto-char (point-min)))
3836 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
3837 (curbuf (current-buffer))
3838 (id (message-make-message-id)) (n 1)
3839 plist total header required-mail-headers)
3841 (if (< (point-max) (+ p message-send-mail-partially-limit))
3842 (goto-char (point-max))
3843 (goto-char (+ p message-send-mail-partially-limit))
3845 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
3848 (setq total (length plist))
3849 (push (point-max) plist)
3850 (setq plist (nreverse plist))
3853 (setq p (pop plist))
3856 (copy-to-buffer tembuf p (car plist))
3858 (goto-char (point-min))
3861 (goto-char (point-min))
3862 (narrow-to-region (point) (point))
3865 (setq header (buffer-substring (point-min) (point)))
3866 (goto-char (point-min))
3867 (narrow-to-region (point) (point))
3869 (message-remove-header "Mime-Version")
3870 (message-remove-header "Content-Type")
3871 (message-remove-header "Content-Transfer-Encoding")
3872 (message-remove-header "Message-ID")
3873 (message-remove-header "Lines")
3874 (goto-char (point-max))
3875 (insert "Mime-Version: 1.0\n")
3876 (setq header (buffer-substring (point-min) (point-max))))
3877 (goto-char (point-max))
3878 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
3881 (let ((mail-header-separator ""))
3882 (when (memq 'Message-ID message-required-mail-headers)
3883 (insert "Message-ID: " (message-make-message-id) "\n"))
3884 (when (memq 'Lines message-required-mail-headers)
3885 (insert "Lines: " (message-make-lines) "\n"))
3886 (message-goto-subject)
3888 (insert (format " (%d/%d)" n total))
3890 (mm-with-unibyte-current-buffer
3891 (funcall (or message-send-mail-real-function
3892 message-send-mail-function))))
3894 (setq p (pop plist))
3896 (kill-buffer tembuf))))
3898 (defun message-send-mail (&optional arg)
3899 (require 'mail-utils)
3900 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
3901 (case-fold-search nil)
3902 (news (message-news-p))
3903 (message-this-is-mail t)
3904 (headers message-required-mail-headers)
3907 (message-narrow-to-headers)
3908 ;; Generate the Mail-Followup-To header if the header is not there...
3909 (if (and (message-subscribed-p)
3910 (not (mail-fetch-field "mail-followup-to")))
3913 (cons "Mail-Followup-To" (message-make-mail-followup-to))
3914 message-required-mail-headers))
3915 ;; otherwise, delete the MFT header if the field is empty
3916 (when (equal "" (mail-fetch-field "mail-followup-to"))
3917 (message-remove-header "^Mail-Followup-To:")))
3918 ;; Insert some headers.
3919 (let ((message-deletable-headers
3920 (if news nil message-deletable-headers)))
3921 (message-generate-headers headers))
3922 ;; Let the user do all of the above.
3923 (run-hooks 'message-header-hook))
3924 (if (not (message-check-mail-syntax))
3932 ;; ;; Avoid copying text props (except hard newlines).
3933 ;; T-gnus change: copy all text props from the editing buffer
3934 ;; into the encoding buffer.
3935 (insert-buffer-substring message-encoding-buffer)
3936 ;; Remove some headers.
3938 (message-narrow-to-headers)
3939 ;; We Semi-gnus people have no use for it.
3940 ;; ;; We (re)generate the Lines header.
3941 ;; (when (memq 'Lines message-required-mail-headers)
3942 ;; (message-generate-headers '(Lines)))
3943 (message-remove-header message-ignored-mail-headers t))
3944 (goto-char (point-max))
3945 ;; require one newline at the end.
3946 (or (= (preceding-char) ?\n)
3948 (message-cleanup-headers)
3951 (message-narrow-to-headers)
3953 (or (message-fetch-field "cc")
3954 (message-fetch-field "to"))
3955 (let ((ct (mime-read-Content-Type)))
3957 (and (eq 'text (cdr (assq 'type ct)))
3958 (eq 'plain (cdr (assq 'subtype ct))))))))
3959 (message-insert-courtesy-copy))
3960 (setq failure (message-maybe-split-and-send-mail)))
3961 (kill-buffer tembuf))
3962 (set-buffer message-edit-buffer)
3965 (message "Couldn't send message via mail: %s" failure)
3967 (push 'mail message-sent-message-via)))))
3969 (defun message-send-mail-with-sendmail ()
3970 "Send off the prepared buffer with sendmail."
3971 (let ((errbuf (if message-interactive
3972 (message-generate-new-buffer-clone-locals
3975 resend-to-addresses delimline)
3978 (let ((case-fold-search t))
3980 (message-narrow-to-headers)
3981 (setq resend-to-addresses (message-fetch-field "resent-to")))
3982 ;; Change header-delimiter to be what sendmail expects.
3983 (goto-char (point-min))
3985 (concat "^" (regexp-quote mail-header-separator) "\n"))
3986 (replace-match "\n")
3988 (setq delimline (point-marker))
3989 (run-hooks 'message-send-mail-hook)
3990 ;; Insert an extra newline if we need it to work around
3991 ;; Sun's bug that swallows newlines.
3992 (goto-char (1+ delimline))
3993 (when (eval message-mailer-swallows-blank-line)
3995 (when message-interactive
3999 (let* ((default-directory "/")
4000 (cpr (as-binary-process
4002 'call-process-region
4004 (list (point-min) (point-max)
4005 (if (boundp 'sendmail-program)
4007 "/usr/lib/sendmail")
4008 nil errbuf nil "-oi")
4009 ;; Always specify who from,
4010 ;; since some systems have broken sendmails.
4011 ;; But some systems are more broken with -f, so
4012 ;; we'll let users override this.
4013 (if (null message-sendmail-f-is-evil)
4014 (list "-f" (message-make-address)))
4015 ;; These mean "report errors by mail"
4016 ;; and "deliver in background".
4017 (if (null message-interactive) '("-oem" "-odb"))
4018 ;; Get the addresses from the message
4019 ;; unless this is a resend.
4020 ;; We must not do that for a resend
4021 ;; because we would find the original addresses.
4022 ;; For a resend, include the specific addresses.
4023 (if resend-to-addresses
4024 (list resend-to-addresses)
4026 (unless (or (null cpr) (zerop cpr))
4027 (error "Sending...failed with exit value %d" cpr)))
4028 (when message-interactive
4031 (goto-char (point-min))
4032 (while (re-search-forward "\n\n* *" nil t)
4033 (replace-match "; "))
4034 (if (not (zerop (buffer-size)))
4035 (error "Sending...failed to %s"
4036 (buffer-substring (point-min) (point-max)))))))
4037 (when (bufferp errbuf)
4038 (kill-buffer errbuf)))))
4040 (defun message-send-mail-with-qmail ()
4041 "Pass the prepared message buffer to qmail-inject.
4042 Refer to the documentation for the variable `message-send-mail-function'
4043 to find out how to use this."
4044 ;; replace the header delimiter with a blank line
4045 (goto-char (point-min))
4047 (concat "^" (regexp-quote mail-header-separator) "\n"))
4048 (replace-match "\n")
4050 (run-hooks 'message-send-mail-hook)
4055 'call-process-region 1 (point-max) message-qmail-inject-program
4057 ;; qmail-inject's default behaviour is to look for addresses on the
4058 ;; command line; if there're none, it scans the headers.
4059 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4061 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4062 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4063 ;; message from stdin.
4065 ;; qmail also has the advantage of not having been raped by
4066 ;; various vendors, so we don't have to allow for that, either --
4067 ;; compare this with message-send-mail-with-sendmail and weep
4068 ;; for sendmail's lost innocence.
4070 ;; all this is way cool coz it lets us keep the arguments entirely
4071 ;; free for -inject-arguments -- a big win for the user and for us
4072 ;; since we don't have to play that double-guessing game and the user
4073 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4074 (if (functionp message-qmail-inject-args)
4075 (funcall message-qmail-inject-args)
4076 message-qmail-inject-args)))
4077 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4078 ;; we have to look at the retval instead
4080 (100 (error "qmail-inject reported permanent failure"))
4081 (111 (error "qmail-inject reported transient failure"))
4082 ;; should never happen
4083 (t (error "qmail-inject reported unknown failure"))))
4085 (defun message-send-mail-with-mh ()
4086 "Send the prepared message buffer with mh."
4087 (let ((mh-previous-window-config nil)
4088 (name (mh-new-draft-name)))
4089 (setq buffer-file-name name)
4090 ;; MH wants to generate these headers itself.
4091 (when message-mh-deletable-headers
4092 (let ((headers message-mh-deletable-headers))
4094 (goto-char (point-min))
4095 (and (re-search-forward
4096 (concat "^" (symbol-name (car headers)) ": *") nil t)
4097 (message-delete-line))
4099 (run-hooks 'message-send-mail-hook)
4100 ;; Pass it on to mh.
4103 (defun message-send-mail-with-smtp ()
4104 "Send off the prepared buffer with SMTP."
4105 (require 'smtp) ; XXX
4106 (let ((case-fold-search t)
4109 (message-narrow-to-headers)
4111 ;; XXX: Should be replaced by better one.
4112 (smtp-deduce-address-list (current-buffer)
4113 (point-min) (point-max)))
4114 ;; Remove BCC lines.
4115 (message-remove-header "bcc"))
4116 ;; replace the header delimiter with a blank line.
4117 (goto-char (point-min))
4119 (concat "^" (regexp-quote mail-header-separator) "\n"))
4120 (replace-match "\n")
4122 (run-hooks 'message-send-mail-hook)
4124 (smtp-send-buffer user-mail-address recipients (current-buffer))
4125 (error "Sending failed; no recipients"))))
4127 (defsubst message-maybe-split-and-send-news (method)
4128 "Split a message if necessary, and send it via news.
4129 Returns nil if sending succeeded, returns t if sending failed.
4130 This sub function is for exclusive use of `message-send-news'."
4131 (let ((mime-edit-split-ignored-field-regexp
4132 mime-edit-split-ignored-field-regexp)
4133 (case-fold-search t))
4134 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
4135 (setq mime-edit-split-ignored-field-regexp
4136 (concat (substring mime-edit-split-ignored-field-regexp
4137 0 (match-beginning 0))
4138 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
4139 "_so_don't_rape_it!"
4140 (substring mime-edit-split-ignored-field-regexp
4143 (catch 'message-sending-news-failure
4144 (mime-edit-maybe-split-and-send
4149 (std11-narrow-to-header mail-header-separator)
4150 (goto-char (point-min))
4151 (when (re-search-forward "^Message-ID:" nil t)
4152 (delete-region (match-end 0) (std11-field-end))
4153 (insert " " (message-make-message-id))))
4154 (unless (funcall message-send-news-function method)
4155 (throw 'message-sending-news-failure t)))))
4157 (not (funcall message-send-news-function method)))))
4159 (defun message-smtpmail-send-it ()
4160 "Send the prepared message buffer with `smtpmail-send-it'.
4161 This only differs from `smtpmail-send-it' that this command evaluates
4162 `message-send-mail-hook' just before sending a message. It is useful
4163 if your ISP requires the POP-before-SMTP authentication. See the
4164 documentation for the function `mail-source-touch-pop'."
4165 (run-hooks 'message-send-mail-hook)
4168 (defun message-canlock-generate ()
4169 "Return a string that is non-trival to guess.
4170 Do not use this for anything important, it is cryptographically weak."
4171 (let (sha1-maximum-internal-length)
4172 (sha1 (concat (message-unique-id)
4173 (format "%x%x%x" (random) (random t) (random))
4174 (prin1-to-string (recent-keys))
4175 (prin1-to-string (garbage-collect))))))
4177 (defun message-canlock-password ()
4178 "The password used by message for cancel locks.
4179 This is the value of `canlock-password', if that option is non-nil.
4180 Otherwise, generate and save a value for `canlock-password' first."
4181 (unless canlock-password
4182 (customize-save-variable 'canlock-password (message-canlock-generate))
4183 (setq canlock-password-for-verify canlock-password))
4186 (defun message-insert-canlock ()
4187 (when message-insert-canlock
4188 (message-canlock-password)
4189 (canlock-insert-header)))
4191 (defun message-send-news (&optional arg)
4192 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4193 (case-fold-search nil)
4194 (method (if (message-functionp message-post-method)
4195 (funcall message-post-method arg)
4196 message-post-method))
4197 (newsgroups-field (save-restriction
4198 (message-narrow-to-headers-or-head)
4199 (message-fetch-field "Newsgroups")))
4200 (followup-field (save-restriction
4201 (message-narrow-to-headers-or-head)
4202 (message-fetch-field "Followup-To")))
4203 ;; BUG: We really need to get the charset for each name in the
4204 ;; Newsgroups and Followup-To lines to allow crossposting
4205 ;; between group namess with incompatible character sets.
4206 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4207 (group-field-charset
4208 (gnus-group-name-charset method newsgroups-field))
4209 (followup-field-charset
4210 (gnus-group-name-charset method (or followup-field "")))
4211 (mime-field-encoding-method-alist
4212 (append (when group-field-charset
4213 (list (cons "Newsgroups" group-field-charset)))
4214 (when followup-field-charset
4215 (list (cons "Followup-To" followup-field-charset)))
4216 mime-field-encoding-method-alist))
4217 (message-syntax-checks
4219 (listp message-syntax-checks))
4220 (cons '(existing-newsgroups . disabled)
4221 message-syntax-checks)
4222 message-syntax-checks))
4223 (message-this-is-news t)
4226 (message-narrow-to-headers)
4227 ;; Insert some headers.
4228 (message-generate-headers message-required-news-headers)
4229 (message-insert-canlock)
4230 ;; Let the user do all of the above.
4231 (run-hooks 'message-header-hook))
4232 ;; Note: This check will be disabled by the ".*" default value for
4233 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4234 (when (and group-field-charset
4235 (listp message-syntax-checks))
4236 (setq message-syntax-checks
4237 (cons '(valid-newsgroups . disabled)
4238 message-syntax-checks)))
4239 (message-cleanup-headers)
4240 (if (not (let ((message-post-method method))
4241 (message-check-news-syntax)))
4246 (buffer-disable-undo)
4248 (insert-buffer-substring message-encoding-buffer)
4249 ;; Remove some headers.
4251 (message-narrow-to-headers)
4252 ;; We Semi-gnus people have no use for it.
4253 ;; ;; We (re)generate the Lines header.
4254 ;; (when (memq 'Lines message-required-mail-headers)
4255 ;; (message-generate-headers '(Lines)))
4256 ;; Remove some headers.
4257 (message-remove-header message-ignored-news-headers t))
4258 (goto-char (point-max))
4259 ;; require one newline at the end.
4260 (or (= (preceding-char) ?\n)
4262 (setq result (message-maybe-split-and-send-news method)))
4263 (kill-buffer tembuf))
4264 (set-buffer message-edit-buffer)
4267 (message "Couldn't send message via news: %s"
4268 (nnheader-get-report (car method)))
4270 (push 'news message-sent-message-via)))))
4272 ;; 1997-09-29 by MORIOKA Tomohiko
4273 (defun message-send-news-with-gnus (method)
4274 (let ((case-fold-search t))
4275 ;; Remove the delimiter.
4276 (goto-char (point-min))
4278 (concat "^" (regexp-quote mail-header-separator) "\n"))
4279 (replace-match "\n")
4281 (run-hooks 'message-send-news-hook)
4282 (gnus-open-server method)
4283 (message "Sending news via %s..." (gnus-server-string method))
4284 (gnus-request-post method)
4288 ;;; Header generation & syntax checking.
4291 (defun message-check-element (type)
4292 "Return non-nil if this TYPE is not to be checked."
4293 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
4295 (let ((able (assq type message-syntax-checks)))
4297 (eq (cdr able) 'disabled)))))
4299 (defun message-check-news-syntax ()
4300 "Check the syntax of the message."
4305 ;; We narrow to the headers and check them first.
4308 (message-narrow-to-headers)
4309 (message-check-news-header-syntax)))
4312 (set-buffer message-edit-buffer)
4313 (message-check-news-body-syntax))))))
4315 (defun message-check-news-header-syntax ()
4317 ;; Check Newsgroups header.
4318 (message-check 'newsgroups
4319 (let ((group (message-fetch-field "newsgroups")))
4322 (not (string-match "\\`[ \t]*\\'" group)))
4325 "The newsgroups field is empty or missing. Posting is denied.")))))
4326 ;; Check the Subject header.
4327 (message-check 'subject
4328 (let* ((case-fold-search t)
4329 (subject (message-fetch-field "subject")))
4332 (not (string-match "\\`[ \t]*\\'" subject)))
4335 "The subject field is empty or missing. Posting is denied.")))))
4336 ;; Check for commands in Subject.
4337 (message-check 'subject-cmsg
4338 (if (string-match "^cmsg " (message-fetch-field "subject"))
4340 "The control code \"cmsg\" is in the subject. Really post? ")
4342 ;; Check long header lines.
4343 (message-check 'long-header-lines
4344 (let ((start (point))
4348 (while (and (not found)
4349 (re-search-forward "^\\([^ \t:]+\\): " nil t))
4350 (if (> (- (point) (match-beginning 0)) 998)
4352 length (- (point) (match-beginning 0)))
4353 (setq header (match-string-no-properties 1)))
4354 (setq start (match-beginning 0))
4357 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
4360 ;; Check for multiple identical headers.
4361 (message-check 'multiple-headers
4363 (while (and (not found)
4364 (re-search-forward "^[^ \t:]+: " nil t))
4366 (or (re-search-forward
4371 (match-beginning 0) (- (match-end 0) 2))))
4376 (y-or-n-p (format "Multiple %s headers. Really post? " found))
4378 ;; Check for Version and Sendsys.
4379 (message-check 'sendsys
4380 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
4382 (format "The article contains a %s command. Really post? "
4383 (buffer-substring (match-beginning 0)
4384 (1- (match-end 0)))))
4386 ;; See whether we can shorten Followup-To.
4387 (message-check 'shorten-followup-to
4388 (let ((newsgroups (message-fetch-field "newsgroups"))
4389 (followup-to (message-fetch-field "followup-to"))
4391 (when (and newsgroups
4392 (string-match "," newsgroups)
4397 (setq to (completing-read
4398 "Followups to (default: no Followup-To header) "
4399 (mapcar (lambda (g) (list g))
4401 (message-tokenize-header
4403 (goto-char (point-min))
4404 (insert "Followup-To: " to "\n"))
4406 ;; Check "Shoot me".
4407 (message-check 'shoot
4408 (if (re-search-forward
4409 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
4410 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
4412 ;; Check for Approved.
4413 (message-check 'approved
4414 (if (re-search-forward "^Approved:" nil t)
4415 (y-or-n-p "The article contains an Approved header. Really post? ")
4417 ;; Check the Message-ID header.
4418 (message-check 'message-id
4419 (let* ((case-fold-search t)
4420 (message-id (message-fetch-field "message-id" t)))
4421 (or (not message-id)
4422 ;; Is there an @ in the ID?
4423 (and (string-match "@" message-id)
4424 ;; Is there a dot in the ID?
4425 (string-match "@[^.]*\\." message-id)
4426 ;; Does the ID end with a dot?
4427 (not (string-match "\\.>" message-id)))
4429 (format "The Message-ID looks strange: \"%s\". Really post? "
4431 ;; Check the Newsgroups & Followup-To headers.
4432 (message-check 'existing-newsgroups
4433 (let* ((case-fold-search t)
4434 (newsgroups (message-fetch-field "newsgroups"))
4435 (followup-to (message-fetch-field "followup-to"))
4436 (groups (message-tokenize-header
4438 (concat newsgroups "," followup-to)
4440 (post-method (if (message-functionp message-post-method)
4441 (funcall message-post-method)
4442 message-post-method))
4443 ;; KLUDGE to handle nnvirtual groups. Doing this right
4444 ;; would probably involve a new nnoo function.
4445 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
4446 (method (if (and (consp post-method)
4447 (eq (car post-method) 'nnvirtual)
4448 gnus-message-group-art)
4449 (let ((group (car (nnvirtual-find-group-art
4450 (car gnus-message-group-art)
4451 (cdr gnus-message-group-art)))))
4452 (gnus-find-method-for-group group))
4456 (gnus-group-name-decode
4457 (gnus-group-real-name n)
4458 (gnus-group-name-charset method n)))
4459 (gnus-groups-from-server method)))
4462 (unless (or (equal (car groups) "poster")
4463 (member (car groups) known-groups))
4464 (push (car groups) errors))
4467 ;; Gnus is not running.
4468 ((or (not (and (boundp 'gnus-active-hashtb)
4469 gnus-active-hashtb))
4470 (not (boundp 'gnus-read-active-file)))
4472 ;; We don't have all the group names.
4473 ((and (or (not gnus-read-active-file)
4474 (eq gnus-read-active-file 'some))
4478 "Really post to %s possibly unknown group%s: %s? "
4479 (if (= (length errors) 1) "this" "these")
4480 (if (= (length errors) 1) "" "s")
4481 (mapconcat 'identity errors ", "))))
4482 ;; There were no errors.
4485 ;; There are unknown groups.
4489 "Really post to %s unknown group%s: %s? "
4490 (if (= (length errors) 1) "this" "these")
4491 (if (= (length errors) 1) "" "s")
4492 (mapconcat 'identity errors ", ")))))))
4493 ;; Check continuation headers.
4494 (message-check 'continuation-headers
4495 (goto-char (point-min))
4496 (let ((do-posting t))
4497 (while (re-search-forward "^[^ \t\n][^:\n]*$" nil t)
4498 (if (y-or-n-p "Fix continuation lines? ")
4500 (goto-char (match-beginning 0))
4502 (unless (y-or-n-p "Send anyway? ")
4503 (setq do-posting nil))))
4505 ;; Check the Newsgroups & Followup-To headers for syntax errors.
4506 (message-check 'valid-newsgroups
4507 (let ((case-fold-search t)
4508 (headers '("Newsgroups" "Followup-To"))
4510 (while (and headers (not error))
4511 (when (setq header (mail-fetch-field (car headers)))
4515 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
4520 (not (string-match "\\.\\'\\|\\.\\." g)))
4521 (message-tokenize-header header ","))))
4528 (format "The %s header looks odd: \"%s\". Really post? "
4529 (car headers) header)))))
4530 (message-check 'repeated-newsgroups
4531 (let ((case-fold-search t)
4532 (headers '("Newsgroups" "Followup-To"))
4533 header error groups group)
4536 (when (setq header (mail-fetch-field (pop headers)))
4537 (setq groups (message-tokenize-header header ","))
4538 (while (setq group (pop groups))
4539 (when (member group groups)
4545 (format "Group %s is repeated in headers. Really post? " error)))))
4546 ;; Check the From header.
4547 (message-check 'from
4548 (let* ((case-fold-search t)
4549 (from (message-fetch-field "from"))
4553 (message "There is no From line. Posting is denied.")
4555 ((or (not (string-match
4557 (setq ad (nth 1 (mail-extract-address-components
4558 from))))) ;larsi@ifi
4559 (string-match "\\.\\." ad) ;larsi@ifi..uio
4560 (string-match "@\\." ad) ;larsi@.ifi.uio
4561 (string-match "\\.$" ad) ;larsi@ifi.uio.
4562 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4563 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
4565 "Denied posting -- the From looks strange: \"%s\"." from)
4567 ((let ((addresses (rfc822-addresses from)))
4568 (while (and addresses
4569 (not (eq (string-to-char (car addresses)) ?\()))
4570 (setq addresses (cdr addresses)))
4573 "Denied posting -- bad From address: \"%s\"." from)
4576 ;; Check the Reply-To header.
4577 (message-check 'reply-to
4578 (let* ((case-fold-search t)
4579 (reply-to (message-fetch-field "reply-to"))
4584 ((string-match "," reply-to)
4586 (format "Multiple Reply-To addresses: \"%s\". Really post? "
4588 ((or (not (string-match
4590 (setq ad (nth 1 (mail-extract-address-components
4591 reply-to))))) ;larsi@ifi
4592 (string-match "\\.\\." ad) ;larsi@ifi..uio
4593 (string-match "@\\." ad) ;larsi@.ifi.uio
4594 (string-match "\\.$" ad) ;larsi@ifi.uio.
4595 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4596 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
4599 "The Reply-To looks strange: \"%s\". Really post? "
4603 (defun message-check-news-body-syntax ()
4605 ;; Check for long lines.
4606 (message-check 'long-lines
4607 (goto-char (point-min))
4609 (concat "^" (regexp-quote mail-header-separator) "$"))
4613 mime-edit-tag-regexp)
4616 (< (- (point) p) 80)))
4617 (zerop (forward-line 1))))
4621 "You have lines longer than 79 characters. Really post? ")))
4622 ;; Check whether the article is empty.
4623 (message-check 'empty
4624 (goto-char (point-min))
4626 (concat "^" (regexp-quote mail-header-separator) "$"))
4629 (goto-char (point-max))
4630 (re-search-backward message-signature-separator nil t)
4632 (or (re-search-backward "[^ \n\t]" b t)
4633 (if (message-gnksa-enable-p 'empty-article)
4634 (y-or-n-p "Empty article. Really post? ")
4635 (message "Denied posting -- Empty article.")
4637 ;; Check for control characters.
4638 (message-check 'control-chars
4639 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
4641 "The article contains control characters. Really post? ")
4643 ;; Check 8bit characters.
4644 (message-check '8bit
4645 (message-check-8bit))
4646 ;; Check excessive size.
4647 (message-check 'size
4648 (if (> (buffer-size) 60000)
4650 (format "The article is %d octets long. Really post? "
4653 ;; Check whether any new text has been added.
4654 (message-check 'new-text
4656 (not message-checksum)
4657 (not (eq (message-checksum) message-checksum))
4658 (if (message-gnksa-enable-p 'quoted-text-only)
4660 "It looks like no new text has been added. Really post? ")
4661 (message "Denied posting -- no new text has been added.")
4663 ;; Check the length of the signature.
4664 (message-check 'signature
4665 (goto-char (point-max))
4666 (if (> (count-lines (point) (point-max)) 5)
4669 "Your .sig is %d lines; it should be max 4. Really post? "
4670 (1- (count-lines (point) (point-max)))))
4672 ;; Ensure that text follows last quoted portion.
4673 (message-check 'quoting-style
4674 (goto-char (point-max))
4675 (let ((no-problem t))
4676 (when (search-backward-regexp "^>[^\n]*\n" nil t)
4677 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
4680 (if (message-gnksa-enable-p 'quoted-text-only)
4681 (y-or-n-p "Your text should follow quoted text. Really post? ")
4683 (goto-char (point-min))
4685 (concat "^" (regexp-quote mail-header-separator) "$"))
4686 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
4687 (y-or-n-p "Your text should follow quoted text. Really post? ")
4688 (message "Denied posting -- only quoted text.")
4691 (defun message-check-mail-syntax ()
4692 "Check the syntax of the message."
4697 ;; We narrow to the headers and check them first.
4700 (message-narrow-to-headers)
4701 (message-check-mail-header-syntax)))
4704 (set-buffer message-edit-buffer)
4705 (message-check-mail-body-syntax))))))
4707 (defun message-check-mail-header-syntax ()
4710 (defun message-check-mail-body-syntax ()
4712 ;; Check 8bit characters.
4713 (message-check '8bit
4714 (message-check-8bit)
4717 (defun message-check-8bit ()
4718 "Check the article contains 8bit characters."
4720 (set-buffer message-encoding-buffer)
4721 (message-narrow-to-headers)
4722 (let* ((case-fold-search t)
4723 (field-value (message-fetch-field "content-transfer-encoding")))
4724 (if (and field-value
4725 (member (downcase field-value) message-8bit-encoding-list))
4728 (set-buffer (get-buffer-create " message syntax"))
4730 (goto-char (point-min))
4731 (set-buffer-multibyte nil)
4732 (insert-buffer-substring message-encoding-buffer)
4733 (goto-char (point-min))
4734 (if (re-search-forward "[^\x00-\x7f]" nil t)
4736 "The article contains 8bit characters. Really post? ")
4739 (defun message-checksum ()
4740 "Return a \"checksum\" for the current buffer."
4743 (goto-char (point-min))
4745 (concat "^" (regexp-quote mail-header-separator) "$"))
4747 (when (not (looking-at "[ \t\n]"))
4748 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
4753 (defun message-do-fcc ()
4754 "Process Fcc headers in the current buffer."
4755 (let ((case-fold-search t)
4756 (coding-system-for-write 'raw-text)
4757 (output-coding-system 'raw-text)
4759 (mml-externalize-attachments message-fcc-externalize-attachments))
4762 (message-narrow-to-headers)
4763 (setq file (message-fetch-field "fcc" t)))
4765 (set-buffer (get-buffer-create " *message temp*"))
4767 (insert-buffer-substring message-encoding-buffer)
4769 (message-narrow-to-headers)
4770 (while (setq file (message-fetch-field "fcc"))
4772 (message-remove-header "fcc" nil t)))
4773 (goto-char (point-min))
4774 (when (re-search-forward
4775 (concat "^" (regexp-quote mail-header-separator) "$")
4777 (replace-match "" t t))
4778 ;; Process FCC operations.
4780 (setq file (pop list))
4781 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
4782 ;; Pipe the article to the program in question.
4783 (call-process-region (point-min) (point-max) shell-file-name
4784 nil nil nil shell-command-switch
4785 (match-string 1 file))
4786 ;; Save the article.
4787 (setq file (expand-file-name file))
4788 (unless (file-exists-p (file-name-directory file))
4789 (make-directory (file-name-directory file) t))
4790 (if (and message-fcc-handler-function
4791 (not (eq message-fcc-handler-function 'rmail-output)))
4792 (funcall message-fcc-handler-function file)
4793 (if (and (file-readable-p file) (mail-file-babyl-p file))
4794 (rmail-output file 1 nil t)
4795 (let ((mail-use-rfc822 t))
4796 (rmail-output file 1 t t))))))
4797 (kill-buffer (current-buffer))))))
4799 (defun message-output (filename)
4800 "Append this article to Unix/babyl mail file FILENAME."
4801 (if (and (file-readable-p filename)
4802 (mail-file-babyl-p filename))
4803 (gnus-output-to-rmail filename t)
4804 (gnus-output-to-mail filename t)))
4806 (defun message-cleanup-headers ()
4807 "Do various automatic cleanups of the headers."
4808 ;; Remove empty lines in the header.
4810 (message-narrow-to-headers)
4811 ;; Remove blank lines.
4812 (while (re-search-forward "^[ \t]*\n" nil t)
4813 (replace-match "" t t))
4815 ;; Correct Newsgroups and Followup-To headers: Change sequence of
4816 ;; spaces to comma and eliminate spaces around commas. Eliminate
4817 ;; embedded line breaks.
4818 (goto-char (point-min))
4819 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
4823 (if (re-search-forward "^[^ \t]" nil t)
4827 (goto-char (point-min))
4828 (while (re-search-forward "\n[ \t]+" nil t)
4829 (replace-match " " t t)) ;No line breaks (too confusing)
4830 (goto-char (point-min))
4831 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
4832 (replace-match "," t t))
4833 (goto-char (point-min))
4834 ;; Remove trailing commas.
4835 (when (re-search-forward ",+$" nil t)
4836 (replace-match "" t t))))))
4838 (defun message-make-date (&optional now)
4839 "Make a valid data header.
4840 If NOW, use that time instead."
4841 (let* ((now (or now (current-time)))
4842 (zone (nth 8 (decode-time now)))
4846 (setq zone (- zone)))
4848 ;; The day name of the %a spec is locale-specific. Pfff.
4849 (format "%s, " (capitalize (car (rassoc (nth 6 (decode-time now))
4850 parse-time-weekdays))))
4851 (format-time-string "%d" now)
4852 ;; The month name of the %b spec is locale-specific. Pfff.
4854 (capitalize (car (rassoc (nth 4 (decode-time now))
4855 parse-time-months))))
4856 (format-time-string "%Y %H:%M:%S " now)
4857 ;; We do all of this because XEmacs doesn't have the %z spec.
4858 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
4860 (defun message-make-followup-subject (subject)
4861 "Make a followup Subject."
4863 ((and (eq message-use-subject-re 'guess)
4864 (string-match message-subject-encoded-re-regexp subject))
4866 (message-use-subject-re
4867 (concat "Re: " (message-strip-subject-re subject)))
4870 (defun message-make-message-id ()
4871 "Make a unique Message-ID."
4872 (concat "<" (message-unique-id)
4873 (let ((psubject (save-excursion (message-fetch-field "subject")))
4875 (save-excursion (message-fetch-field "supersedes"))))
4877 (and message-reply-headers
4878 (mail-header-references message-reply-headers)
4879 (mail-header-subject message-reply-headers)
4882 (message-strip-subject-re
4883 (mail-header-subject message-reply-headers))
4884 (message-strip-subject-re psubject))))
4886 (string-match "_-_@" psupersedes)))
4888 "@" (message-make-fqdn) ">"))
4890 (defvar message-unique-id-char nil)
4892 ;; If you ever change this function, make sure the new version
4893 ;; cannot generate IDs that the old version could.
4894 ;; You might for example insert a "." somewhere (not next to another dot
4895 ;; or string boundary), or modify the "fsf" string.
4896 (defun message-unique-id ()
4897 ;; Don't use microseconds from (current-time), they may be unsupported.
4898 ;; Instead we use this randomly inited counter.
4899 (setq message-unique-id-char
4900 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
4901 ;; (current-time) returns 16-bit ints,
4902 ;; and 2^16*25 just fits into 4 digits i base 36.
4904 (let ((tm (current-time)))
4906 (if (memq system-type '(ms-dos emx vax-vms))
4907 (let ((user (downcase (user-login-name))))
4908 (while (string-match "[^a-z0-9_]" user)
4909 (aset user (match-beginning 0) ?_))
4911 (message-number-base36 (user-uid) -1))
4912 (message-number-base36 (+ (car tm)
4913 (lsh (% message-unique-id-char 25) 16)) 4)
4914 (message-number-base36 (+ (nth 1 tm)
4915 (lsh (/ message-unique-id-char 25) 16)) 4)
4916 ;; Append the newsreader name, because while the generated
4917 ;; ID is unique to this newsreader, other newsreaders might
4918 ;; otherwise generate the same ID via another algorithm.
4921 (defun message-number-base36 (num len)
4926 (concat (message-number-base36 (/ num 36) (1- len))
4927 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
4930 (defun message-make-organization ()
4931 "Make an Organization header."
4932 (let* ((organization
4933 (when message-user-organization
4934 (if (message-functionp message-user-organization)
4935 (funcall message-user-organization)
4936 message-user-organization))))
4938 (message-set-work-buffer)
4939 (cond ((stringp organization)
4940 (insert organization))
4941 ((and (eq t organization)
4942 message-user-organization-file
4943 (file-exists-p message-user-organization-file))
4944 (insert-file-contents message-user-organization-file)))
4945 (goto-char (point-min))
4946 (while (re-search-forward "[\t\n]+" nil t)
4947 (replace-match "" t t))
4948 (unless (zerop (buffer-size))
4951 (defun message-make-lines ()
4952 "Count the number of lines and return numeric string."
4957 (int-to-string (count-lines (point) (point-max))))))
4959 (defun message-make-references ()
4960 "Return the References header for this message."
4961 (when message-reply-headers
4962 (let ((message-id (mail-header-message-id message-reply-headers))
4963 (references (mail-header-references message-reply-headers))
4965 (if (or references message-id)
4966 (concat (or references "") (and references " ")
4970 (defun message-make-in-reply-to ()
4971 "Return the In-Reply-To header for this message."
4972 (when message-reply-headers
4973 (let ((from (mail-header-from message-reply-headers))
4974 (date (mail-header-date message-reply-headers))
4975 (msg-id (mail-header-message-id message-reply-headers)))
4979 (let ((pair (std11-extract-address-components from)))
4981 (or (car pair) (cadr pair))
4983 (if (or (not date) (string= date ""))
4984 "(unknown date)" date)
4987 (defun message-make-distribution ()
4988 "Make a Distribution header."
4989 (let ((orig-distribution (message-fetch-reply-field "distribution")))
4990 (cond ((message-functionp message-distribution-function)
4991 (funcall message-distribution-function))
4992 (t orig-distribution))))
4994 (defun message-make-expires ()
4995 "Return an Expires header based on `message-expires'."
4996 (let ((current (current-time))
4997 (future (* 1.0 message-expires 60 60 24)))
4998 ;; Add the future to current.
4999 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
5000 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
5001 (message-make-date current)))
5003 (defun message-make-path ()
5005 (let ((login-name (user-login-name)))
5006 (cond ((null message-user-path)
5007 (concat (system-name) "!" login-name))
5008 ((stringp message-user-path)
5009 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
5010 (concat message-user-path "!" login-name))
5013 (defun message-make-from ()
5014 "Make a From header."
5015 (let* ((style message-from-style)
5016 (login (message-make-address))
5018 (or (and (boundp 'user-full-name)
5021 (when (string= fullname "&")
5022 (setq fullname (user-login-name)))
5024 (message-set-work-buffer)
5027 (equal fullname ""))
5029 ((or (eq style 'angles)
5030 (and (not (eq style 'parens))
5031 ;; Use angles if no quoting is needed, or if parens would
5032 ;; need quoting too.
5033 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
5034 (let ((tmp (concat fullname nil)))
5035 (while (string-match "([^()]*)" tmp)
5036 (aset tmp (match-beginning 0) ?-)
5037 (aset tmp (1- (match-end 0)) ?-))
5038 (string-match "[\\()]" tmp)))))
5040 (insert " <" login ">"))
5041 (t ; 'parens or default
5043 (let ((fullname-start (point)))
5045 (goto-char fullname-start)
5046 ;; RFC 822 says \ and nonmatching parentheses
5047 ;; must be escaped in comments.
5048 ;; Escape every instance of ()\ ...
5049 (while (re-search-forward "[()\\]" nil 1)
5050 (replace-match "\\\\\\&" t))
5051 ;; ... then undo escaping of matching parentheses,
5052 ;; including matching nested parentheses.
5053 (goto-char fullname-start)
5054 (while (re-search-forward
5055 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
5057 (replace-match "\\1(\\3)" t)
5058 (goto-char fullname-start)))
5062 (defun message-make-sender ()
5063 "Return the \"real\" user address.
5064 This function tries to ignore all user modifications, and
5065 give as trustworthy answer as possible."
5066 (concat (user-login-name) "@" (system-name)))
5068 (defun message-make-address ()
5069 "Make the address of the user."
5070 (or (message-user-mail-address)
5071 (concat (user-login-name) "@" (message-make-domain))))
5073 (defun message-user-mail-address ()
5074 "Return the pertinent part of `user-mail-address'."
5075 (when user-mail-address
5076 (if (string-match " " user-mail-address)
5077 (nth 1 (std11-extract-address-components user-mail-address))
5078 user-mail-address)))
5080 (defun message-make-fqdn ()
5081 "Return user's fully qualified domain name."
5082 (let ((system-name (system-name))
5083 (user-mail (message-user-mail-address)))
5085 ((and (string-match "[^.]\\.[^.]" system-name)
5086 (not (string-match message-bogus-system-names system-name)))
5087 ;; `system-name' returned the right result.
5089 ;; Try `mail-host-address'.
5090 ((and (boundp 'mail-host-address)
5091 (stringp mail-host-address)
5092 (string-match "\\." mail-host-address))
5094 ;; We try `user-mail-address' as a backup.
5096 (string-match "\\." user-mail)
5097 (string-match "@\\(.*\\)\\'" user-mail))
5098 (match-string 1 user-mail))
5099 ;; Default to this bogus thing.
5101 (concat system-name ".i-did-not-set--mail-host-address--so-tickle-me")))))
5103 (defun message-make-host-name ()
5104 "Return the name of the host."
5105 (let ((fqdn (message-make-fqdn)))
5106 (string-match "^[^.]+\\." fqdn)
5107 (substring fqdn 0 (1- (match-end 0)))))
5109 (defun message-make-domain ()
5110 "Return the domain name."
5111 (or mail-host-address
5112 (message-make-fqdn)))
5114 (defun message-to-list-only ()
5115 "Send a message to the list only.
5116 Remove all addresses but the list address from To and Cc headers."
5118 (let ((listaddr (message-make-mail-followup-to t)))
5121 (message-remove-header "to")
5122 (message-remove-header "cc")
5123 (message-position-on-field "To" "X-Draft-From")
5124 (insert listaddr)))))
5126 (defun message-make-mail-followup-to (&optional only-show-subscribed)
5127 "Return the Mail-Followup-To header.
5128 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5129 subscribed address (and not the additional To and Cc header contents)."
5130 (let* ((case-fold-search t)
5131 (to (message-fetch-field "To"))
5132 (cc (message-fetch-field "cc"))
5133 (msg-recipients (concat to (and to cc ", ") cc))
5135 (mapcar 'mail-strip-quoted-names
5136 (message-tokenize-header msg-recipients)))
5138 (if message-subscribed-address-file
5139 (let (begin end item re)
5142 (insert-file-contents message-subscribed-address-file)
5144 (setq begin (point))
5147 (if (bolp) (setq end (1- end)))
5148 (setq item (regexp-quote (buffer-substring begin end)))
5149 (if re (setq re (concat re "\\|" item))
5150 (setq re (concat "\\`\\(" item))))
5151 (and re (list (concat re "\\)\\'"))))))))
5152 (mft-regexps (apply 'append message-subscribed-regexps
5153 (mapcar 'regexp-quote
5154 message-subscribed-addresses)
5157 message-subscribed-address-functions))))
5159 (let ((subscribed-lists nil)
5161 (loop for recipient in recipients
5162 when (loop for regexp in mft-regexps
5163 when (string-match regexp recipient) return t)
5166 (if only-show-subscribed
5168 msg-recipients))))))
5170 ;; Dummy to avoid byte-compile warning.
5171 (defvar mule-version)
5172 (defvar emacs-beta-version)
5173 (defvar xemacs-codename)
5174 (defvar gnus-inviolable-extended-version)
5176 (defun message-make-user-agent ()
5177 "Return user-agent info if the value `message-user-agent' is non-nil. If the
5178 \"User-Agent\" field has already exist, it's value will be added in the return
5180 (when message-user-agent
5182 (goto-char (point-min))
5183 (let ((case-fold-search t)
5184 user-agent start p end)
5185 (if (re-search-forward
5186 (concat "^User-Agent:[\t ]*\\("
5187 (regexp-quote gnus-product-name)
5188 "/[0-9.]+\\([ \t\r\n]*([^)]+)\\)*\\)?[\t ]*")
5191 (setq start (match-beginning 0)
5193 end (std11-field-end)
5194 user-agent (buffer-substring-no-properties p end))
5195 (delete-region start (1+ end))
5196 (concat message-user-agent " " user-agent))
5197 message-user-agent)))))
5199 (defun message-generate-headers (headers)
5200 "Prepare article HEADERS.
5201 Headers already prepared in the buffer are not modified."
5202 (setq headers (append headers message-required-headers))
5204 (message-narrow-to-headers)
5205 (let* ((Date (message-make-date))
5206 (Message-ID (message-make-message-id))
5207 (Organization (message-make-organization))
5208 (From (message-make-from))
5209 (Path (message-make-path))
5212 (In-Reply-To (message-make-in-reply-to))
5213 (References (message-make-references))
5215 (Distribution (message-make-distribution))
5216 (Lines (message-make-lines))
5217 (User-Agent (message-make-user-agent))
5218 (Expires (message-make-expires))
5219 (case-fold-search t)
5222 ;; First we remove any old generated headers.
5223 (let ((headers message-deletable-headers))
5224 (unless (buffer-modified-p)
5225 (setq headers (delq 'Message-ID (copy-sequence headers))))
5227 (goto-char (point-min))
5228 (and (re-search-forward
5229 (concat "^" (symbol-name (car headers)) ": *") nil t)
5230 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
5231 (message-delete-line))
5233 ;; Go through all the required headers and see if they are in the
5234 ;; articles already. If they are not, or are empty, they are
5235 ;; inserted automatically - except for Subject, Newsgroups and
5238 (goto-char (point-min))
5239 (setq elem (pop headers))
5241 (if (eq (car elem) 'optional)
5242 (setq header (cdr elem)
5244 (setq header (car elem)))
5246 (when (or (not (re-search-forward
5250 (if (stringp header)
5252 (symbol-name header))))
5256 ;; The header was found. We insert a space after the
5257 ;; colon, if there is none.
5258 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
5259 ;; Find out whether the header is empty.
5260 (looking-at "[ \t]*\n[^ \t]")))
5261 ;; So we find out what value we should insert.
5265 (eq (car elem) 'optional))
5266 ;; This is an optional header. If the cdr of this
5267 ;; is something that is nil, then we do not insert
5269 (setq header (cdr elem))
5270 (or (and (message-functionp (cdr elem))
5271 (funcall (cdr elem)))
5272 (and (boundp (cdr elem))
5273 (symbol-value (cdr elem)))))
5275 ;; The element is a cons. Either the cdr is a
5276 ;; string to be inserted verbatim, or it is a
5277 ;; function, and we insert the value returned from
5279 (or (and (stringp (cdr elem))
5281 (and (message-functionp (cdr elem))
5282 (funcall (cdr elem)))))
5283 ((and (boundp header)
5284 (symbol-value header))
5285 ;; The element is a symbol. We insert the value
5286 ;; of this symbol, if any.
5287 (symbol-value header))
5288 ((not (message-check-element header))
5289 ;; We couldn't generate a value for this header,
5290 ;; so we just ask the user.
5291 (read-from-minibuffer
5292 (format "Empty header for %s; enter value: " header)))))
5293 ;; Finally insert the header.
5295 (not (equal value "")))
5299 ;; This header didn't exist, so we insert it.
5300 (goto-char (point-max))
5302 (cdr (assq header message-header-format-alist))))
5304 (funcall formatter header value)
5305 (insert (if (stringp header)
5306 header (symbol-name header))
5308 ;; We check whether the value was ended by a
5309 ;; newline. If now, we insert one.
5313 ;; The value of this header was empty, so we clear
5314 ;; totally and insert the new value.
5315 (delete-region (point) (gnus-point-at-eol))
5316 ;; If the header is optional, and the header was
5317 ;; empty, we can't insert it anyway.
5322 ;; Add the deletable property to the headers that require it.
5323 (and (memq header message-deletable-headers)
5324 (progn (beginning-of-line) (looking-at "[^:]+: "))
5325 (add-text-properties
5326 (point) (match-end 0)
5327 '(message-deletable t face italic) (current-buffer)))))))
5328 ;; Insert new Sender if the From is strange.
5329 (let ((from (message-fetch-field "from"))
5330 (sender (message-fetch-field "sender"))
5331 (secure-sender (message-make-sender)))
5333 (not (message-check-element 'sender))
5336 (cadr (std11-extract-address-components from)))
5337 (downcase secure-sender)))
5342 (cadr (std11-extract-address-components sender)))
5343 (downcase secure-sender)))))
5344 (goto-char (point-min))
5345 ;; Rename any old Sender headers to Original-Sender.
5346 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
5348 (insert "Original-")
5349 (beginning-of-line))
5350 (when (or (message-news-p)
5351 (string-match "@.+\\.." secure-sender))
5352 (insert "Sender: " secure-sender "\n")))))))
5354 (defun message-insert-courtesy-copy ()
5355 "Insert a courtesy message in mail copies of combined messages."
5359 (message-narrow-to-headers)
5360 (when (setq newsgroups (message-fetch-field "newsgroups"))
5361 (goto-char (point-max))
5362 (insert "Posted-To: " newsgroups "\n")))
5364 (when message-courtesy-message
5366 ((string-match "%s" message-courtesy-message)
5367 (insert (format message-courtesy-message newsgroups)))
5369 (insert message-courtesy-message)))))))
5372 ;;; Setting up a message buffer
5375 (defun message-fill-address (header value)
5377 (narrow-to-region (point) (point))
5378 (insert (capitalize (symbol-name header))
5380 (if (consp value) (car value) value)
5382 (narrow-to-region (point-min) (1- (point-max)))
5384 (goto-char (point-min))
5386 (skip-chars-forward "^,\"" (point-max))
5387 (if (or (eq (char-after) ?,)
5390 (if (and (> (current-column) 78)
5394 (looking-at "[ \t]*")
5395 (replace-match "\n " t t)))
5396 (setq last (1+ (point))))
5397 (setq quoted (not quoted)))
5400 (goto-char (point-max))
5404 (defun message-fill-references (header value)
5405 (insert (capitalize (symbol-name header))
5407 (std11-fill-msg-id-list-string
5408 (if (consp value) (car value) value))
5411 (defun message-fill-header (header value)
5412 (let ((begin (point))
5415 (insert (capitalize (symbol-name header))
5417 (if (consp value) (car value) value)
5420 (narrow-to-region begin (point))
5421 (fill-region-as-paragraph begin (point))
5422 ;; Tapdance around looong Message-IDs.
5424 (when (looking-at "[ \t]*$")
5425 (message-delete-line))
5427 (re-search-forward ":" nil t)
5428 (when (looking-at "\n[ \t]+")
5429 (replace-match " " t t))
5430 (goto-char (point-max)))))
5432 (defun message-shorten-1 (list cut surplus)
5433 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
5434 (setcdr (nthcdr (- cut 2) list)
5435 (nthcdr (+ (- cut 2) surplus 1) list)))
5437 (defun message-shorten-references (header references)
5438 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
5439 If folding is disallowed, also check that the REFERENCES are less
5440 than 988 characters long, and if they are not, trim them until they are."
5447 (goto-char (point-min))
5448 ;; Cons a list of valid references.
5449 (while (re-search-forward "<[^>]+>" nil t)
5450 (push (match-string 0) refs))
5451 (setq refs (nreverse refs)
5452 count (length refs)))
5454 ;; If the list has more than MAXCOUNT elements, trim it by
5455 ;; removing the CUTth element and the required number of
5456 ;; elements that follow.
5457 (when (> count maxcount)
5458 (let ((surplus (- count maxcount)))
5459 (message-shorten-1 refs cut surplus)
5460 (decf count surplus)))
5462 ;; If folding is disallowed, make sure the total length (including
5463 ;; the spaces between) will be less than MAXSIZE characters.
5465 ;; Only disallow folding for News messages. At this point the headers
5466 ;; have not been generated, thus we use message-this-is-news directly.
5467 (when (and message-this-is-news message-cater-to-broken-inn)
5469 (totalsize (+ (apply #'+ (mapcar #'length refs))
5472 (ptr (nthcdr (1- cut) refs)))
5473 ;; Decide how many elements to cut off...
5474 (while (> totalsize maxsize)
5475 (decf totalsize (1+ (length (car ptr))))
5477 (setq ptr (cdr ptr)))
5480 (message-shorten-1 refs cut surplus))))
5482 ;; Finally, collect the references back into a string and insert
5483 ;; it into the buffer.
5484 (let ((refstring (mapconcat #'identity refs " ")))
5485 (if (and message-this-is-news message-cater-to-broken-inn)
5486 (insert (capitalize (symbol-name header)) ": "
5488 (message-fill-header header refstring)))))
5490 (defun message-position-point ()
5491 "Move point to where the user probably wants to find it."
5492 (message-narrow-to-headers)
5494 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
5495 (search-backward ":" )
5498 (if (eq (char-after) ? )
5502 (goto-char (point-max))
5505 (unless (looking-at "$")
5509 (defcustom message-beginning-of-line t
5510 "Whether C-a goes to beginning of header values."
5511 :group 'message-buffers
5514 (defun message-beginning-of-line (&optional n)
5515 "Move point to beginning of header value or to beginning of line."
5517 (let ((zrs 'zmacs-region-stays))
5518 (when (and (interactive-p) (boundp zrs))
5520 (if (and message-beginning-of-line
5521 (message-point-in-header-p))
5522 (let* ((here (point))
5523 (bol (progn (beginning-of-line n) (point)))
5524 (eol (gnus-point-at-eol))
5525 (eoh (re-search-forward ": *" eol t)))
5526 (if (or (not eoh) (equal here eoh))
5529 (beginning-of-line n)))
5531 (defun message-buffer-name (type &optional to group)
5532 "Return a new (unique) buffer name based on TYPE and TO."
5534 ;; Generate a new buffer name The Message Way.
5535 ((eq message-generate-new-buffers 'unique)
5536 (generate-new-buffer-name
5540 (or (car (std11-extract-address-components to))
5543 (if (and group (not (string= group ""))) (concat " on " group) "")
5545 ;; Check whether `message-generate-new-buffers' is a function,
5546 ;; and if so, call it.
5547 ((message-functionp message-generate-new-buffers)
5548 (funcall message-generate-new-buffers type to group))
5549 ((eq message-generate-new-buffers 'unsent)
5550 (generate-new-buffer-name
5551 (concat "*unsent " type
5554 (or (car (mail-extract-address-components to))
5557 (if (and group (not (string= group ""))) (concat " on " group) "")
5559 ;; Use standard name.
5561 (format "*%s message*" type))))
5563 (defmacro message-pop-to-buffer-1 (buffer)
5565 (let (special-display-buffer-names
5566 special-display-regexps
5567 same-window-buffer-names
5568 same-window-regexps)
5569 (pop-to-buffer ,buffer))
5570 (pop-to-buffer ,buffer)))
5572 (defun message-pop-to-buffer (name)
5573 "Pop to buffer NAME, and warn if it already exists and is modified."
5574 (let ((buffer (get-buffer name))
5575 (pop-up-frames (and (or (static-if (featurep 'xemacs)
5576 (device-on-window-system-p)
5578 (>= emacs-major-version 20))
5579 message-use-multi-frames)))
5581 (buffer-name buffer))
5583 (message-pop-to-buffer-1 buffer)
5584 (when (and (buffer-modified-p)
5586 "Message already being composed; erase? ")))
5587 (error "Message being composed")))
5588 (message-pop-to-buffer-1 name))
5592 (set (make-local-variable 'message-original-frame) (selected-frame)))))
5594 (defun message-do-send-housekeeping ()
5595 "Kill old message buffers."
5596 ;; We might have sent this buffer already. Delete it from the
5598 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
5599 (while (and message-max-buffers
5601 (>= (length message-buffer-list) message-max-buffers))
5602 ;; Kill the oldest buffer -- unless it has been changed.
5603 (let ((buffer (pop message-buffer-list)))
5604 (when (and (buffer-name buffer)
5605 (not (buffer-modified-p buffer)))
5606 (kill-buffer buffer))))
5607 ;; Rename the buffer.
5608 (if message-send-rename-function
5609 (funcall message-send-rename-function)
5610 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
5612 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
5614 (let ((name (match-string 2 (buffer-name)))
5616 (if (not (or (null name)
5617 (string-equal name "mail")
5618 (string-equal name "posting")))
5619 (setq name (concat "*sent " name "*"))
5620 (message-narrow-to-headers)
5621 (setq to (message-fetch-field "to"))
5622 (setq group (message-fetch-field "newsgroups"))
5626 (to (concat "*sent mail to "
5627 (or (car (mail-extract-address-components to))
5629 ((and group (not (string= group "")))
5630 (concat "*sent posting on " group "*"))
5631 (t "*sent mail*"))))
5632 (unless (string-equal name (buffer-name))
5633 (rename-buffer name t)))))
5634 ;; Push the current buffer onto the list.
5635 (when message-max-buffers
5636 (setq message-buffer-list
5637 (nconc message-buffer-list (list (current-buffer))))))
5639 (defun message-mail-user-agent ()
5641 ((not message-mail-user-agent) nil)
5642 ((eq message-mail-user-agent t) mail-user-agent)
5643 (t message-mail-user-agent))))
5644 (if (memq mua '(message-user-agent gnus-user-agent))
5648 (defun message-setup (headers &optional replybuffer actions switch-function)
5649 (let ((mua (message-mail-user-agent))
5650 subject to field yank-action)
5651 (if (not (and message-this-is-mail mua))
5652 (message-setup-1 headers replybuffer actions)
5654 (setq yank-action (list 'insert-buffer replybuffer)))
5655 (setq headers (copy-sequence headers))
5656 (setq field (assq 'Subject headers))
5658 (setq subject (cdr field))
5659 (setq headers (delq field headers)))
5660 (setq field (assq 'To headers))
5662 (setq to (cdr field))
5663 (setq headers (delq field headers)))
5664 (let ((mail-user-agent mua))
5665 (compose-mail to subject
5666 (mapcar (lambda (item)
5668 (format "%s" (car item))
5671 nil switch-function yank-action actions)))))
5673 (defun message-headers-to-generate (headers included-headers excluded-headers)
5674 "Return a list that includes all headers from HEADERS.
5675 If INCLUDED-HEADERS is a list, just include those headers. If if is
5676 t, include all headers. In any case, headers from EXCLUDED-HEADERS
5680 (dolist (header headers)
5681 (setq header-name (cond
5682 ((and (consp header)
5683 (eq (car header) 'optional))
5684 ;; On the form (optional . Header)
5687 ;; On the form (Header . function)
5692 (when (and (not (memq header-name excluded-headers))
5693 (or (eq included-headers t)
5694 (memq header-name included-headers)))
5695 (push header result)))
5698 (defun message-setup-1 (headers &optional replybuffer actions)
5699 (dolist (action actions)
5701 (add-to-list 'message-send-actions
5702 `(apply ',(car action) ',(cdr action)))))
5703 (setq message-reply-buffer
5704 (or (message-get-parameter 'reply-buffer)
5706 (goto-char (point-min))
5707 ;; Insert all the headers.
5710 (alist message-header-format-alist))
5712 (unless (assq (caar h) message-header-format-alist)
5713 (push (list (caar h)) alist))
5717 (delete-region (point) (progn (forward-line -1) (point)))
5718 (when message-default-headers
5719 (insert message-default-headers)
5720 (or (bolp) (insert ?\n)))
5724 (insert mail-header-separator "\n")
5728 (when (message-news-p)
5729 (when message-default-news-headers
5730 (insert message-default-news-headers)
5731 (or (bolp) (insert ?\n)))
5732 (when message-generate-headers-first
5733 (message-generate-headers
5734 (message-headers-to-generate
5735 (append message-required-news-headers
5736 message-required-headers)
5737 message-generate-headers-first
5738 '(Lines Subject)))))
5739 (when (message-mail-p)
5740 (when message-default-mail-headers
5741 (insert message-default-mail-headers)
5742 (or (bolp) (insert ?\n)))
5743 (when message-generate-headers-first
5744 (message-generate-headers
5745 (message-headers-to-generate
5746 (append message-required-mail-headers
5747 message-required-headers)
5748 message-generate-headers-first
5749 '(Lines Subject)))))
5750 (run-hooks 'message-signature-setup-hook)
5751 (message-insert-signature)
5753 (message-narrow-to-headers)
5754 (if (and replybuffer
5755 message-alternative-emails)
5756 (message-use-alternative-email-as-from))
5757 (run-hooks 'message-header-setup-hook))
5758 (set-buffer-modified-p nil)
5759 (setq buffer-undo-list nil)
5760 (run-hooks 'message-setup-hook)
5761 (message-position-point)
5764 (defun message-set-auto-save-file-name ()
5765 "Associate the message buffer with a file in the drafts directory."
5766 (when message-auto-save-directory
5767 (unless (file-directory-p
5768 (directory-file-name message-auto-save-directory))
5769 (make-directory message-auto-save-directory t))
5771 (setq message-draft-article
5772 (nndraft-request-associate-buffer "drafts"))
5773 (setq buffer-file-name (expand-file-name
5774 (if (memq system-type
5775 '(ms-dos ms-windows windows-nt
5776 cygwin cygwin32 win32 w32
5780 message-auto-save-directory))
5781 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
5782 (clear-visited-file-modtime)
5783 (static-if (boundp 'MULE)
5784 (set-file-coding-system message-draft-coding-system)
5785 (setq buffer-file-coding-system message-draft-coding-system))))
5787 (defun message-disassociate-draft ()
5788 "Disassociate the message buffer from the drafts directory."
5789 (when message-draft-article
5790 (nndraft-request-expire-articles
5791 (list message-draft-article) "drafts" nil t)))
5793 (defun message-insert-headers ()
5794 "Generate the headers for the article."
5798 (message-narrow-to-headers)
5799 (when (message-news-p)
5800 (message-generate-headers
5803 (copy-sequence message-required-news-headers)))))
5804 (when (message-mail-p)
5805 (message-generate-headers
5808 (copy-sequence message-required-mail-headers))))))))
5813 ;;; Commands for interfacing with message
5817 (defun message-mail (&optional to subject
5818 other-headers continue switch-function
5819 yank-action send-actions)
5820 "Start editing a mail message to be sent.
5821 OTHER-HEADERS is an alist of header/value pairs."
5823 (let ((message-this-is-mail t) replybuffer)
5824 (unless (message-mail-user-agent)
5825 (message-pop-to-buffer (message-buffer-name "mail" to)))
5826 ;; FIXME: message-mail should do something if YANK-ACTION is not
5828 (and (consp yank-action) (eq (car yank-action) 'insert-buffer)
5829 (setq replybuffer (nth 1 yank-action)))
5832 `((To . ,(or to "")) (Subject . ,(or subject "")))
5833 (when other-headers other-headers))
5834 replybuffer send-actions)
5835 ;; FIXME: Should return nil if failure.
5839 (defun message-news (&optional newsgroups subject)
5840 "Start editing a news article to be sent."
5842 (let ((message-this-is-news t))
5843 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
5844 (message-setup `((Newsgroups . ,(or newsgroups ""))
5845 (Subject . ,(or subject ""))))))
5847 (defun message-get-reply-headers (wide &optional to-address address-headers)
5848 (let (follow-to mct never-mct to cc author mft recipients)
5849 ;; Find all relevant headers we need.
5850 (let ((mrt (when message-use-mail-reply-to
5851 (message-fetch-field "mail-reply-to")))
5852 (reply-to (message-fetch-field "reply-to")))
5853 (setq to (message-fetch-field "to")
5854 cc (message-fetch-field "cc")
5855 mct (when message-use-mail-copies-to
5856 (message-fetch-field "mail-copies-to"))
5859 (message-fetch-field "from")
5861 mft (when (and (not (or to-address mrt reply-to))
5862 message-use-mail-followup-to)
5863 (message-fetch-field "mail-followup-to"))))
5866 ;; Handle special values of Mail-Copies-To.
5868 (cond ((or (equal (downcase mct) "never")
5869 (equal (downcase mct) "nobody"))
5870 (when (or (not (eq message-use-mail-copies-to 'ask))
5872 (concat "Obey Mail-Copies-To: never? ") t "\
5873 You should normally obey the Mail-Copies-To: header.
5875 `Mail-Copies-To: " mct "'
5876 directs you not to send your response to the author."))
5879 ((or (equal (downcase mct) "always")
5880 (equal (downcase mct) "poster"))
5881 (if (or (not (eq message-use-mail-copies-to 'ask))
5883 (concat "Obey Mail-Copies-To: always? ") t "\
5884 You should normally obey the Mail-Copies-To: header.
5886 `Mail-Copies-To: " mct "'
5887 sends a copy of your response to the author."))
5890 ((and (eq message-use-mail-copies-to 'ask)
5891 (not (message-y-or-n-p
5892 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
5893 You should normally obey the Mail-Copies-To: header.
5895 `Mail-Copies-To: " mct "'
5896 sends a copy of your response to " (if (string-match "," mct)
5897 "the specified addresses"
5898 "that address") ".")))
5901 ;; Build (textual) list of new recipient addresses.
5904 (setq recipients (concat ", " author)))
5906 (dolist (header address-headers)
5907 (let ((value (message-fetch-field header)))
5909 (setq recipients (concat recipients ", " value))))))
5911 (string-match "[^ \t,]" mft)
5912 (or (not (eq message-use-mail-followup-to 'ask))
5913 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
5914 You should normally obey the Mail-Followup-To: header. In this
5915 article, it has the value of
5919 which directs your response to " (if (string-match "," mft)
5920 "the specified addresses"
5921 "that address only") ".
5923 Most commonly, Mail-Followup-To is used by a mailing list poster to
5924 express that responses should be sent to just the list, and not the
5927 If a message is posted to several mailing lists, Mail-Followup-To may
5928 also be used to direct the following discussion to one list only,
5929 because discussions that are spread over several lists tend to be
5930 fragmented and very difficult to follow.
5932 Also, some source/announcement lists are not intended for discussion;
5933 responses here are directed to other addresses.")))
5934 (setq recipients (concat ", " mft)))
5936 (setq recipients (concat ", " to-address))
5937 ;; If the author explicitly asked for a copy, we don't deny it to them.
5938 (if mct (setq recipients (concat recipients ", " mct))))
5940 (setq recipients (if never-mct "" (concat ", " author)))
5941 (if to (setq recipients (concat recipients ", " to)))
5942 (if cc (setq recipients (concat recipients ", " cc)))
5943 (if mct (setq recipients (concat recipients ", " mct)))))
5944 (if (>= (length recipients) 2)
5945 ;; Strip the leading ", ".
5946 (setq recipients (substring recipients 2)))
5947 ;; Squeeze whitespace.
5948 (while (string-match "[ \t][ \t]+" recipients)
5949 (setq recipients (replace-match " " t t recipients)))
5950 ;; Remove addresses that match `rmail-dont-reply-to-names'.
5951 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
5952 (setq recipients (rmail-dont-reply-to recipients)))
5953 ;; Perhaps "Mail-Copies-To: never" removed the only address?
5954 (if (string-equal recipients "")
5955 (setq recipients author))
5956 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
5960 (cons (downcase (mail-strip-quoted-names addr)) addr))
5961 (message-tokenize-header recipients)))
5962 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
5963 (let ((s recipients))
5965 (setq recipients (delq (assoc (car (pop s)) s) recipients))))
5967 ;; Remove hierarchical lists that are contained within each other,
5968 ;; if message-hierarchical-addresses is defined.
5969 (when message-hierarchical-addresses
5970 (let ((plain-addrs (mapcar 'car recipients))
5973 (setq subaddrs (assoc (car plain-addrs)
5974 message-hierarchical-addresses)
5975 plain-addrs (cdr plain-addrs))
5977 (setq subaddrs (cdr subaddrs))
5979 (setq recip (assoc (car subaddrs) recipients)
5980 subaddrs (cdr subaddrs))
5982 (setq recipients (delq recip recipients))))))))
5984 ;; Build the header alist. Allow the user to be asked whether
5985 ;; or not to reply to all recipients in a wide reply.
5986 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
5987 (when (and recipients
5988 (or (not message-wide-reply-confirm-recipients)
5989 (y-or-n-p "Reply to all recipients? ")))
5990 (setq recipients (mapconcat
5991 (lambda (addr) (cdr addr)) recipients ", "))
5992 (if (string-match "^ +" recipients)
5993 (setq recipients (substring recipients (match-end 0))))
5994 (push (cons 'Cc recipients) follow-to)))
5998 (defun message-reply (&optional to-address wide)
5999 "Start editing a reply to the article in the current buffer."
6001 (require 'gnus-sum) ; for gnus-list-identifiers
6002 (let ((cur (current-buffer))
6004 references message-id follow-to
6005 (inhibit-point-motion-hooks t)
6006 (message-this-is-mail t)
6007 gnus-warning in-reply-to)
6009 (message-narrow-to-head-1)
6010 ;; Allow customizations to have their say.
6012 ;; This is a regular reply.
6013 (when (message-functionp message-reply-to-function)
6015 (setq follow-to (funcall message-reply-to-function))))
6016 ;; This is a followup.
6017 (when (message-functionp message-wide-reply-to-function)
6020 (funcall message-wide-reply-to-function)))))
6021 (setq message-id (message-fetch-field "message-id" t)
6022 references (message-fetch-field "references")
6023 date (message-fetch-field "date")
6024 from (message-fetch-field "from")
6025 subject (or (message-fetch-field "subject") "none"))
6026 (when gnus-list-identifiers
6027 (setq subject (message-strip-list-identifiers subject)))
6028 (setq subject (message-make-followup-subject subject))
6029 (when message-subject-trailing-was-query
6030 (setq subject (message-strip-subject-trailing-was subject)))
6032 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6033 (string-match "<[^>]+>" gnus-warning))
6034 (setq message-id (match-string 0 gnus-warning)))
6037 (setq follow-to (message-get-reply-headers wide to-address)))
6039 ;; Get the references from "In-Reply-To" field if there were
6040 ;; no references and "In-Reply-To" field looks promising.
6042 (when (and (setq in-reply-to (message-fetch-field "in-reply-to"))
6043 (string-match "<[^>]+>" in-reply-to))
6044 (setq references (match-string 0 in-reply-to)))))
6046 (unless (message-mail-user-agent)
6047 (message-pop-to-buffer
6048 (message-buffer-name
6049 (if wide "wide reply" "reply") from
6050 (if wide to-address nil))))
6052 (setq message-reply-headers
6053 (make-full-mail-header-from-decoded-header
6054 0 subject from date message-id references 0 0 ""))
6057 `((Subject . ,subject)
6062 (defun message-wide-reply (&optional to-address)
6063 "Make a \"wide\" reply to the message in the current buffer."
6065 (message-reply to-address t))
6068 (defun message-followup (&optional to-newsgroups)
6069 "Follow up to the message in the current buffer.
6070 If TO-NEWSGROUPS, use that as the new Newsgroups line."
6072 (require 'gnus-sum) ; for gnus-list-identifiers
6073 (let ((cur (current-buffer))
6074 from subject date reply-to mrt mct mft
6075 references message-id follow-to
6076 (inhibit-point-motion-hooks t)
6077 (message-this-is-news t)
6078 followup-to distribution newsgroups gnus-warning posted-to)
6080 (message-narrow-to-head)
6081 (when (message-functionp message-followup-to-function)
6083 (funcall message-followup-to-function)))
6084 (setq from (message-fetch-field "from")
6085 date (message-fetch-field "date")
6086 subject (or (message-fetch-field "subject") "none")
6087 references (message-fetch-field "references")
6088 message-id (message-fetch-field "message-id" t)
6089 followup-to (message-fetch-field "followup-to")
6090 newsgroups (message-fetch-field "newsgroups")
6091 posted-to (message-fetch-field "posted-to")
6092 reply-to (message-fetch-field "reply-to")
6093 mrt (when message-use-mail-reply-to
6094 (message-fetch-field "mail-reply-to"))
6095 distribution (message-fetch-field "distribution")
6096 mct (when message-use-mail-copies-to
6097 (message-fetch-field "mail-copies-to"))
6098 mft (when message-use-mail-followup-to
6099 (message-fetch-field "mail-followup-to")))
6100 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6101 (string-match "<[^>]+>" gnus-warning))
6102 (setq message-id (match-string 0 gnus-warning)))
6103 ;; Remove bogus distribution.
6104 (when (and (stringp distribution)
6105 (let ((case-fold-search t))
6106 (string-match "world" distribution)))
6107 (setq distribution nil))
6108 (if gnus-list-identifiers
6109 (setq subject (message-strip-list-identifiers subject)))
6110 (setq subject (message-make-followup-subject subject))
6111 (when message-subject-trailing-was-query
6112 (setq subject (message-strip-subject-trailing-was subject)))
6115 ;; Handle special values of Mail-Copies-To.
6118 ((and (or (equal (downcase mct) "never")
6119 (equal (downcase mct) "nobody")))
6121 ((and (or (equal (downcase mct) "always")
6122 (equal (downcase mct) "poster")))
6123 (if (or (not (eq message-use-mail-copies-to 'ask))
6125 (concat "Obey Mail-Copies-To: always? ") t "\
6126 You should normally obey the Mail-Copies-To: header.
6128 `Mail-Copies-To: " mct "'
6129 sends a copy of your response to the author."))
6130 (setq mct (or mrt reply-to from))
6132 ((and (eq message-use-mail-copies-to 'ask)
6135 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
6136 You should normally obey the Mail-Copies-To: header.
6138 `Mail-Copies-To: " mct "'
6139 sends a copy of your response to " (if (string-match "," mct)
6140 "the specified addresses"
6141 "that address") ".")))
6146 (to-newsgroups (setq follow-to (list (cons 'Newsgroups to-newsgroups))))
6147 ;; Handle Followup-To.
6150 ((equal (downcase followup-to) "poster")
6151 (if (or (and followup-to (eq message-use-followup-to 'use))
6152 (message-y-or-n-p "Obey Followup-To: poster? " t "\
6153 You should normally obey the Followup-To: header.
6155 `Followup-To: poster'
6156 sends your response via e-mail instead of news.
6158 A typical situation where `Followup-To: poster' is used is when the author
6159 does not read the newsgroup, so he wouldn't see any replies sent to it."))
6160 (setq message-this-is-news nil
6162 follow-to (list (cons 'To (or mrt reply-to from ""))))
6163 (setq follow-to (list (cons 'Newsgroups newsgroups)))))
6165 (if (or (equal followup-to newsgroups)
6166 (not (and followup-to (eq message-use-followup-to 'ask)))
6168 (concat "Obey Followup-To: " followup-to "? ") t "\
6169 You should normally obey the Followup-To: header.
6171 `Followup-To: " followup-to "'
6172 directs your response to " (if (string-match "," followup-to)
6173 "the specified newsgroups"
6174 "that newsgroup only") ".
6176 If a message is posted to several newsgroups, Followup-To is often
6177 used to direct the following discussion to one newsgroup only,
6178 because discussions that are spread over several newsgroup tend to
6179 be fragmented and very difficult to follow.
6181 Also, some source/announcement newsgroups are not intended for discussion;
6182 responses here are directed to other newsgroups."))
6183 (setq follow-to (list (cons 'Newsgroups followup-to)))
6184 (setq follow-to (list (cons 'Newsgroups newsgroups)))))))
6185 ;; Handle Mail-Followup-To, followup via e-mail.
6187 (or (not (eq message-use-mail-followup-to 'ask))
6189 (concat "Obey Mail-Followup-To: " mft "? ") t "\
6190 You should normally obey the Mail-Followup-To: header.
6192 `Mail-Followup-To: " mft "'
6193 directs your response to " (if (string-match "," mft)
6194 "the specified addresses"
6195 "that address only") " instead of news.
6197 A typical situation where Mail-Followup-To is used is when the author thinks
6198 that further discussion should take place only in "
6199 (if (string-match "," mft)
6200 "the specified mailing lists"
6201 "that mailing list") ".")))
6202 (setq message-this-is-news nil
6204 follow-to (list (cons 'To mft))))
6205 (posted-to (setq follow-to (list (cons 'Newsgroups posted-to))))
6207 (setq follow-to (list (cons 'Newsgroups newsgroups))))))
6209 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
6211 (setq message-reply-headers
6212 (make-full-mail-header-from-decoded-header
6213 0 subject from date message-id references 0 0 ""))
6216 `((Subject . ,subject)
6218 ,@(and mct (list (cons 'Cc mct)))
6219 ,@(and distribution (list (cons 'Distribution distribution))))
6223 (defun message-cancel-news (&optional arg)
6224 "Cancel an article you posted.
6225 If ARG, allow editing of the cancellation message."
6227 (unless (message-news-p)
6228 (error "This is not a news article; canceling is impossible"))
6229 (let (from newsgroups message-id distribution buf sender)
6231 ;; Get header info from original article.
6233 (message-narrow-to-head-1)
6234 (setq from (message-fetch-field "from")
6235 sender (message-fetch-field "sender")
6236 newsgroups (message-fetch-field "newsgroups")
6237 message-id (message-fetch-field "message-id" t)
6238 distribution (message-fetch-field "distribution")))
6239 ;; Make sure that this article was written by the user.
6241 ;; Canlock-logic as suggested by Per Abrahamsen
6242 ;; <abraham@dina.kvl.dk>
6244 ;; IF article has cancel-lock THEN
6245 ;; IF we can verify it THEN
6248 ;; error: cancellock: article is not yours
6250 ;; Use old rules, comparing sender...
6251 (if (message-fetch-field "Cancel-Lock")
6252 (if (null (canlock-verify))
6254 (error "Failed to verify Cancel-lock: This article is not yours"))
6256 (message-gnksa-enable-p 'cancel-messages)
6260 (downcase (message-make-sender))))
6262 (downcase (cadr (std11-extract-address-components from)))
6263 (downcase (cadr (std11-extract-address-components
6264 (message-make-from))))))
6265 (error "This article is not yours"))
6266 (when (yes-or-no-p "Do you really want to cancel this article? ")
6267 ;; Make control message.
6270 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
6272 (insert "Newsgroups: " newsgroups "\n"
6274 "Subject: cmsg cancel " message-id "\n"
6275 "Control: cancel " message-id "\n"
6277 (concat "Distribution: " distribution "\n")
6279 mail-header-separator "\n"
6280 message-cancel-message)
6281 (run-hooks 'message-cancel-hook)
6283 (message "Canceling your article...")
6284 (if (let ((message-syntax-checks
6285 'dont-check-for-anything-just-trust-me)
6286 (message-encoding-buffer (current-buffer))
6287 (message-edit-buffer (current-buffer)))
6288 (message-send-news))
6289 (message "Canceling your article...done"))
6290 (kill-buffer buf))))))
6292 (defun message-supersede-setup-for-mime-edit ()
6293 (set (make-local-variable 'message-setup-hook) nil)
6297 (defun message-supersede ()
6298 "Start composing a message to supersede the current message.
6299 This is done simply by taking the old article and adding a Supersedes
6300 header line with the old Message-ID."
6302 (let ((cur (current-buffer))
6303 (sender (message-fetch-field "sender"))
6304 (from (message-fetch-field "from")))
6305 ;; Check whether the user owns the article that is to be superseded.
6307 ;; Canlock-logic as suggested by Per Abrahamsen
6308 ;; <abraham@dina.kvl.dk>
6310 ;; IF article has cancel-lock THEN
6311 ;; IF we can verify it THEN
6314 ;; error: cancellock: article is not yours
6316 ;; Use old rules, comparing sender...
6317 (if (message-fetch-field "Cancel-Lock")
6318 (if (null (canlock-verify))
6320 (error "Failed to verify Cancel-lock: This article is not yours"))
6322 (message-gnksa-enable-p 'cancel-messages)
6326 (downcase (message-make-sender))))
6328 (downcase (cadr (std11-extract-address-components from)))
6329 (downcase (cadr (std11-extract-address-components
6330 (message-make-from))))))
6331 (error "This article is not yours"))
6332 ;; Get a normal message buffer.
6333 (message-pop-to-buffer (message-buffer-name "supersede"))
6334 (insert-buffer-substring cur)
6335 (message-narrow-to-head-1)
6336 ;; Remove unwanted headers.
6337 (when message-ignored-supersedes-headers
6338 (message-remove-header message-ignored-supersedes-headers t))
6339 (goto-char (point-min))
6340 (if (not (re-search-forward "^Message-ID: " nil t))
6341 (error "No Message-ID in this article")
6342 (replace-match "Supersedes: " t t))
6343 (goto-char (point-max))
6344 (insert mail-header-separator)
6346 (when message-supersede-setup-function
6347 (funcall message-supersede-setup-function))
6348 (run-hooks 'message-supersede-setup-hook)
6349 (goto-char (point-min))
6350 (search-forward (concat "\n" mail-header-separator "\n") nil t)))
6353 (defun message-recover ()
6354 "Reread contents of current buffer from its last auto-save file."
6356 (let ((file-name (make-auto-save-file-name)))
6357 (cond ((save-window-excursion
6358 (if (not (eq system-type 'vax-vms))
6359 (with-output-to-temp-buffer "*Directory*"
6360 (with-current-buffer standard-output
6361 (fundamental-mode)) ; for Emacs 20.4+
6362 (buffer-disable-undo standard-output)
6363 (let ((default-directory "/"))
6365 "ls" nil standard-output nil "-l" file-name))))
6366 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
6367 (let ((buffer-read-only nil))
6369 (insert-file-contents file-name nil)))
6370 (t (error "message-recover cancelled")))))
6372 ;;; Washing Subject:
6374 (defun message-wash-subject (subject)
6375 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
6376 Previous forwarders, replyers, etc. may add it."
6379 (goto-char (point-min))
6380 ;; strip Re/Fwd stuff off the beginning
6381 (while (re-search-forward
6382 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
6385 ;; and gnus-style forwards [foo@bar.com] subject
6386 (goto-char (point-min))
6387 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
6391 (goto-char (point-max))
6392 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
6395 ;; and finally, any whitespace that was left-over
6396 (goto-char (point-min))
6397 (while (re-search-forward "^[ \t]+" nil t)
6399 (goto-char (point-max))
6400 (while (re-search-backward "[ \t]+$" nil t)
6405 ;;; Forwarding messages.
6407 (defvar message-forward-decoded-p nil
6408 "Non-nil means the original message is decoded.")
6410 (defun message-forward-subject-author-subject (subject)
6411 "Generate a SUBJECT for a forwarded message.
6412 The form is: [Source] Subject, where if the original message was mail,
6413 Source is the sender, and if the original message was news, Source is
6414 the list of newsgroups is was posted to."
6416 (let ((prefix (message-fetch-field "newsgroups")))
6418 (and (setq prefix (message-fetch-field "from"))
6419 (nnheader-decode-from prefix))
6423 (defun message-forward-subject-fwd (subject)
6424 "Generate a SUBJECT for a forwarded message.
6425 The form is: Fwd: Subject, where Subject is the original subject of
6427 (concat "Fwd: " subject))
6429 (defun message-make-forward-subject ()
6430 "Return a Subject header suitable for the message in the current buffer."
6433 (message-narrow-to-head-1)
6434 (let ((funcs message-make-forward-subject-function)
6435 (subject (message-fetch-field "Subject")))
6438 (if message-forward-decoded-p
6440 (nnheader-decode-subject subject))
6442 (if message-wash-forwarded-subjects
6443 (setq subject (message-wash-subject subject)))
6444 ;; Make sure funcs is a list.
6447 (setq funcs (list funcs)))
6448 ;; Apply funcs in order, passing subject generated by previous
6449 ;; func to the next one.
6451 (when (message-functionp (car funcs))
6452 (setq subject (funcall (car funcs) subject)))
6453 (setq funcs (cdr funcs)))
6457 (defun message-forward (&optional news)
6458 "Forward the current message via mail.
6459 Optional NEWS will use news to forward instead of mail."
6461 (let ((cur (current-buffer))
6462 (subject (message-make-forward-subject)))
6464 (message-news nil subject)
6465 (message-mail nil subject))
6466 (message-forward-make-body cur)))
6469 (defun message-forward-make-body (forward-buffer)
6470 ;; Put point where we want it before inserting the forwarded
6472 ;; Note that this function definition for T-gnus is totally different
6473 ;; from the original Gnus."
6474 (if message-forward-before-signature
6476 (goto-char (point-max)))
6477 ;; Make sure we're at the start of the line.
6480 ;; Narrow to the area we are to insert.
6481 (narrow-to-region (point) (point))
6482 ;; Insert the separators and the forwarded buffer.
6483 (insert message-forward-start-separator)
6484 (let ((art-beg (point)))
6485 (insert-buffer-substring forward-buffer)
6486 (goto-char (point-max))
6487 (insert message-forward-end-separator)
6488 (set-text-properties (point-min) (point-max) nil)
6489 ;; Remove all unwanted headers.
6491 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
6494 (goto-char (point-min))
6495 (message-remove-header message-included-forward-headers t nil t)
6497 (message-position-point)))
6500 (defun message-forward-rmail-make-body (forward-buffer)
6501 (save-window-excursion
6502 (set-buffer forward-buffer)
6503 ;; Rmail doesn't have rmail-msg-restore-non-pruned-header in Emacs
6504 ;; 20. FIXIT, or we drop support for rmail in Emacs 20.
6505 (if (rmail-msg-is-pruned)
6506 (rmail-msg-restore-non-pruned-header)))
6507 (message-forward-make-body forward-buffer))
6510 (defun message-insinuate-rmail ()
6511 "Let RMAIL uses message to forward."
6513 (setq rmail-enable-mime-composing t)
6514 (setq rmail-insert-mime-forwarded-message-function
6515 'message-forward-rmail-make-body))
6518 (defun message-resend (address)
6519 "Resend the current article to ADDRESS."
6521 (list (message-read-from-minibuffer "Resend message to: ")))
6522 (message "Resending message to %s..." address)
6524 (let ((cur (current-buffer))
6526 ;; We first set up a normal mail buffer.
6527 (unless (message-mail-user-agent)
6528 (set-buffer (get-buffer-create " *message resend*"))
6530 (let ((message-this-is-mail t)
6531 ;; avoid to turn-on-mime-edit
6533 (message-setup `((To . ,address)))))
6534 ;; Insert our usual headers.
6535 (message-generate-headers '(From Date To))
6536 (message-narrow-to-headers)
6537 ;; Rename them all to "Resent-*".
6538 (while (re-search-forward "^[A-Za-z]" nil t)
6543 (delete-region (point) (point-max))
6545 ;; Insert the message to be resent.
6546 (insert-buffer-substring cur)
6547 (goto-char (point-min))
6548 (search-forward "\n\n")
6551 (narrow-to-region beg (point))
6552 (message-remove-header message-ignored-resent-headers t)
6553 (goto-char (point-max)))
6554 (insert mail-header-separator)
6555 ;; Rename all old ("Also-")Resent headers.
6556 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
6559 ;; Quote any "From " lines at the beginning.
6561 (when (looking-at "From ")
6562 (replace-match "X-From-Line: "))
6564 (let ((message-encoding-buffer (current-buffer))
6565 (message-edit-buffer (current-buffer))
6566 message-required-mail-headers)
6567 (message-send-mail))
6568 (kill-buffer (current-buffer)))
6569 (message "Resending message to %s...done" address)))
6571 (defun message-bounce-setup-for-mime-edit ()
6572 (set (make-local-variable 'message-setup-hook) nil)
6576 (defun message-bounce ()
6577 "Re-mail the current message.
6578 This only makes sense if the current message is a bounce message that
6579 contains some mail you have written which has been bounced back to
6582 (let ((cur (current-buffer))
6584 (message-pop-to-buffer (message-buffer-name "bounce"))
6585 (insert-buffer-substring cur)
6587 (message-narrow-to-head)
6588 (if (and (message-fetch-field "MIME-Version")
6589 (setq boundary (message-fetch-field "Content-Type")))
6590 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary)
6591 (setq boundary (concat (match-string 1 boundary) " *\n"
6592 "Content-Type: message/rfc822"))
6593 (setq boundary nil)))
6595 (goto-char (point-min))
6596 (search-forward "\n\n" nil t)
6597 (if (or (and boundary
6598 (re-search-forward boundary nil t)
6600 (and (re-search-forward message-unsent-separator nil t)
6602 (re-search-forward "^Return-Path:.*\n" nil t))
6603 ;; We remove everything before the bounced mail.
6606 (if (re-search-forward "^[^ \n\t]+:" nil t)
6609 (when (re-search-backward "^.?From .*\n" nil t)
6610 (delete-region (match-beginning 0) (match-end 0))))
6612 (message-narrow-to-head-1)
6613 (message-remove-header message-ignored-bounced-headers t)
6614 (goto-char (point-max))
6615 (insert mail-header-separator))
6616 (when message-bounce-setup-function
6617 (funcall message-bounce-setup-function))
6618 (run-hooks 'message-bounce-setup-hook)
6619 (message-position-point)))
6622 ;;; Interactive entry points for new message buffers.
6626 (defun message-mail-other-window (&optional to subject)
6627 "Like `message-mail' command, but display mail buffer in another window."
6629 (unless (message-mail-user-agent)
6630 (let ((pop-up-windows t)
6631 (special-display-buffer-names nil)
6632 (special-display-regexps nil)
6633 (same-window-buffer-names nil)
6634 (same-window-regexps nil))
6635 (message-pop-to-buffer (message-buffer-name "mail" to))))
6636 (let ((message-this-is-mail t))
6637 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
6638 nil nil 'switch-to-buffer-other-window)))
6641 (defun message-mail-other-frame (&optional to subject)
6642 "Like `message-mail' command, but display mail buffer in another frame."
6644 (unless (message-mail-user-agent)
6645 (let ((pop-up-frames t)
6646 (special-display-buffer-names nil)
6647 (special-display-regexps nil)
6648 (same-window-buffer-names nil)
6649 (same-window-regexps nil))
6650 (message-pop-to-buffer (message-buffer-name "mail" to))))
6651 (let ((message-this-is-mail t))
6652 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
6653 nil nil 'switch-to-buffer-other-frame)))
6656 (defun message-news-other-window (&optional newsgroups subject)
6657 "Start editing a news article to be sent."
6659 (let ((pop-up-windows t)
6660 (special-display-buffer-names nil)
6661 (special-display-regexps nil)
6662 (same-window-buffer-names nil)
6663 (same-window-regexps nil))
6664 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
6665 (let ((message-this-is-news t))
6666 (message-setup `((Newsgroups . ,(or newsgroups ""))
6667 (Subject . ,(or subject ""))))))
6670 (defun message-news-other-frame (&optional newsgroups subject)
6671 "Start editing a news article to be sent."
6673 (let ((pop-up-frames t)
6674 (special-display-buffer-names nil)
6675 (special-display-regexps nil)
6676 (same-window-buffer-names nil)
6677 (same-window-regexps nil))
6678 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
6679 (let ((message-this-is-news t))
6680 (message-setup `((Newsgroups . ,(or newsgroups ""))
6681 (Subject . ,(or subject ""))))))
6685 ;; This code should be moved to underline.el (from which it is stolen).
6688 (defun bold-region (start end)
6689 "Bold all nonblank characters in the region.
6690 Works by overstriking characters.
6691 Called from program, takes two arguments START and END
6692 which specify the range to operate on."
6695 (let ((end1 (make-marker)))
6696 (move-marker end1 (max start end))
6697 (goto-char (min start end))
6698 (while (< (point) end1)
6699 (or (looking-at "[_\^@- ]")
6700 (insert (char-after) "\b"))
6701 (forward-char 1)))))
6704 (defun unbold-region (start end)
6705 "Remove all boldness (overstruck characters) in the region.
6706 Called from program, takes two arguments START and END
6707 which specify the range to operate on."
6710 (let ((end1 (make-marker)))
6711 (move-marker end1 (max start end))
6712 (goto-char (min start end))
6713 (while (re-search-forward "\b" end1 t)
6714 (if (eq (char-after) (char-after (- (point) 2)))
6715 (delete-char -2))))))
6717 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
6719 ;; Support for toolbar
6721 (defvar tool-bar-map)
6722 (defvar tool-bar-mode))
6724 (defun message-tool-bar-local-item-from-menu (command icon in-map &optional from-map &rest props)
6725 ;; We need to make tool bar entries in local keymaps with
6726 ;; `tool-bar-local-item-from-menu' in Emacs > 21.3
6727 (if (fboundp 'tool-bar-local-item-from-menu)
6728 ;; This is for Emacs 21.3
6729 (tool-bar-local-item-from-menu command icon in-map from-map props)
6730 (tool-bar-add-item-from-menu command icon from-map props)))
6732 (defun message-tool-bar-map ()
6733 (or message-tool-bar-map
6734 (setq message-tool-bar-map
6736 (condition-case nil (require 'tool-bar) (error nil))
6737 (fboundp 'tool-bar-add-item-from-menu)
6739 (let ((tool-bar-map (copy-keymap tool-bar-map))
6740 (load-path (mm-image-load-path)))
6741 ;; Zap some items which aren't so relevant and take
6743 (dolist (key '(print-buffer kill-buffer save-buffer
6744 write-file dired open-file))
6745 (define-key tool-bar-map (vector key) nil))
6746 (message-tool-bar-local-item-from-menu
6747 'message-send-and-exit "mail_send" tool-bar-map message-mode-map)
6748 (message-tool-bar-local-item-from-menu
6749 'message-kill-buffer "close" tool-bar-map message-mode-map)
6750 (message-tool-bar-local-item-from-menu
6751 'message-dont-send "cancel" tool-bar-map message-mode-map)
6752 ;; (message-tool-bar-local-item-from-menu
6753 ;; 'mime-edit-insert-file "attach"
6754 ;; tool-bar-map mime-edit-mode-map)
6755 (message-tool-bar-local-item-from-menu
6756 'ispell-message "spell" tool-bar-map message-mode-map)
6757 ;; (message-tool-bar-local-item-from-menu
6758 ;; 'mime-edit-preview-message "preview"
6759 ;; tool-bar-map mime-edit-mode-map)
6760 (message-tool-bar-local-item-from-menu
6761 'message-insert-importance-high "important"
6762 tool-bar-map message-mode-map)
6763 (message-tool-bar-local-item-from-menu
6764 'message-insert-importance-low "unimportant"
6765 tool-bar-map message-mode-map)
6766 (message-tool-bar-local-item-from-menu
6767 'message-insert-disposition-notification-to "receipt"
6768 tool-bar-map message-mode-map)
6771 ;;; Group name completion.
6773 (defcustom message-newgroups-header-regexp
6774 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
6775 "Regexp that match headers that lists groups."
6779 (defcustom message-completion-alist
6780 (list (cons message-newgroups-header-regexp 'message-expand-group)
6781 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name)
6782 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
6783 . message-expand-name)
6784 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
6785 . message-expand-name))
6786 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
6788 :type '(alist :key-type regexp :value-type function))
6790 (defcustom message-expand-name-function
6791 (if (fboundp 'bbdb-complete-name)
6793 (if (fboundp 'lsdb-complete-name)
6796 "*A function called to expand addresses in field body."
6800 (defcustom message-tab-body-function nil
6801 "*Function to execute when `message-tab' (TAB) is executed in the body.
6802 If nil, the function bound in `text-mode-map' or `global-map' is executed."
6806 (defun message-tab ()
6807 "Complete names according to `message-completion-alist'.
6808 Execute function specified by `message-tab-body-function' when not in
6811 (let ((alist message-completion-alist))
6813 (let ((mail-abbrev-mode-regexp (caar alist)))
6814 (not (mail-abbrev-in-expansion-header-p))))
6815 (setq alist (cdr alist)))
6816 (funcall (or (cdar alist) message-tab-body-function
6817 (lookup-key text-mode-map "\t")
6818 (lookup-key global-map "\t")
6819 'indent-relative))))
6821 (defun message-expand-group ()
6822 "Expand the group name under point."
6823 (let* ((b (save-excursion
6828 (skip-chars-forward "^:")
6831 (skip-chars-backward "^, \t\n") (point))))
6832 (completion-ignore-case t)
6833 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
6835 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
6836 (completions (all-completions string hashtb))
6838 (delete-region b (point))
6840 ((= (length completions) 1)
6841 (if (string= (car completions) string)
6844 (message "Only matching group"))
6845 (insert (car completions))))
6846 ((and (setq comp (try-completion string hashtb))
6847 (not (string= comp string)))
6852 (message "No matching groups")
6853 (save-selected-window
6854 (pop-to-buffer "*Completions*")
6855 (buffer-disable-undo)
6856 (let ((buffer-read-only nil))
6858 (let ((standard-output (current-buffer)))
6859 (display-completion-list (sort completions 'string<)))
6860 (goto-char (point-min))
6861 (delete-region (point) (progn (forward-line 3) (point))))))))))
6863 (defun message-expand-name ()
6864 (funcall message-expand-name-function))
6868 (defun message-talkative-question (ask question show &rest text)
6869 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
6870 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
6871 The following arguments may contain lists of values."
6873 (setq text (message-flatten-list text)))
6874 (save-window-excursion
6876 (with-output-to-temp-buffer " *MESSAGE information message*"
6877 (set-buffer " *MESSAGE information message*")
6878 (fundamental-mode) ; for Emacs 20.4+
6879 (mapcar 'princ text)
6880 (goto-char (point-min))))
6881 (funcall ask question))
6882 (funcall ask question)))
6884 (defun message-flatten-list (list)
6885 "Return a new, flat list that contains all elements of LIST.
6887 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
6890 (apply 'append (mapcar 'message-flatten-list list)))
6894 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
6895 "Create and return a buffer with name based on NAME using `generate-new-buffer.'
6896 Then clone the local variables and values from the old buffer to the
6897 new one, cloning only the locals having a substring matching the
6899 (let ((oldbuf (current-buffer)))
6901 (set-buffer (generate-new-buffer name))
6902 (message-clone-locals oldbuf varstr)
6905 (defun message-clone-locals (buffer &optional varstr)
6906 "Clone the local variables from BUFFER to the current buffer."
6907 (let ((locals (save-excursion
6909 (buffer-local-variables)))
6911 "^\\(gnus\\|nn\\|message\\|user-\\(mail-address\\|full-name\\)\\)"))
6914 (when (and (consp local)
6916 (string-match regexp (symbol-name (car local)))
6918 (string-match varstr (symbol-name (car local)))))
6920 (set (make-local-variable (car local))
6925 ;;; @ for MIME Edit mode
6928 (defun message-maybe-encode ()
6929 (when message-mime-mode
6930 ;; Inherit the buffer local variable `mime-edit-pgp-processing'.
6931 (let ((pgp-processing (with-current-buffer message-edit-buffer
6932 mime-edit-pgp-processing)))
6933 (setq mime-edit-pgp-processing pgp-processing))
6934 (run-hooks 'mime-edit-translate-hook)
6935 (if (catch 'mime-edit-error
6937 (mime-edit-pgp-enclose-buffer)
6938 (mime-edit-translate-body)))
6939 (error "Translation error!"))
6940 (run-hooks 'mime-edit-exit-hook)))
6942 (defun message-mime-insert-article (&optional full-headers)
6944 (let ((message-cite-function 'mime-edit-inserted-message-filter)
6945 (message-reply-buffer
6946 (message-get-parameter-with-eval 'original-buffer))
6948 (message-yank-original nil)
6950 (narrow-to-region (goto-char start)
6951 (if (search-forward "\n\n" nil t)
6954 (goto-char (point-min))
6955 (let ((message-included-forward-headers
6956 (if full-headers "" message-included-forward-headers)))
6957 (message-remove-header message-included-forward-headers t nil t))
6960 (set-alist 'mime-edit-message-inserter-alist
6961 'message-mode (function message-mime-insert-article))
6963 ;;; Miscellaneous functions
6965 ;; stolen (and renamed) from nnheader.el
6966 (static-if (fboundp 'subst-char-in-string)
6967 (defsubst message-replace-chars-in-string (string from to)
6968 (subst-char-in-string from to string))
6969 (defun message-replace-chars-in-string (string from to)
6970 "Replace characters in STRING from FROM to TO."
6971 (let ((string (substring string 0)) ;Copy string.
6972 (len (length string))
6974 ;; Replace all occurrences of FROM with TO.
6976 (when (= (aref string idx) from)
6977 (aset string idx to))
6978 (setq idx (1+ idx)))
6985 (defvar message-inhibit-body-encoding t)
6987 (defun message-encode-message-body ()
6988 (unless message-inhibit-body-encoding
6989 (let ((mail-parse-charset (or mail-parse-charset
6990 message-default-charset))
6991 (case-fold-search t)
6992 lines content-type-p)
6995 (narrow-to-region (point) (point-max))
6996 (let ((new (mml-generate-mime)))
6998 (delete-region (point-min) (point-max))
7000 (goto-char (point-min))
7001 (if (eq (aref new 0) ?\n)
7003 (search-forward "\n\n")
7004 (setq lines (buffer-substring (point-min) (1- (point))))
7005 (delete-region (point-min) (point))))))
7007 (message-narrow-to-headers-or-head)
7008 (message-remove-header "Mime-Version")
7009 (goto-char (point-max))
7010 (insert "MIME-Version: 1.0\n")
7013 (setq content-type-p
7015 (re-search-backward "^Content-Type:" nil t))))
7017 (message-narrow-to-headers-or-head)
7018 (message-remove-first-header "Content-Type")
7019 (message-remove-first-header "Content-Transfer-Encoding"))
7020 ;; We always make sure that the message has a Content-Type
7021 ;; header. This is because some broken MTAs and MUAs get
7022 ;; awfully confused when confronted with a message with a
7023 ;; MIME-Version header and without a Content-Type header. For
7024 ;; instance, Solaris' /usr/bin/mail.
7025 (unless content-type-p
7026 (goto-char (point-min))
7027 ;; For unknown reason, MIME-Version doesn't exist.
7028 (when (re-search-forward "^MIME-Version:" nil t)
7030 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
7032 (defun message-read-from-minibuffer (prompt &optional initial-contents)
7033 "Read from the minibuffer while providing abbrev expansion."
7034 (if (fboundp 'mail-abbrevs-setup)
7035 (let ((mail-abbrev-mode-regexp "")
7036 (minibuffer-setup-hook 'mail-abbrevs-setup)
7037 (minibuffer-local-map message-minibuffer-local-map))
7038 (read-from-minibuffer prompt initial-contents))
7039 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
7040 (minibuffer-local-map message-minibuffer-local-map))
7041 (read-string prompt initial-contents))))
7043 (defun message-use-alternative-email-as-from ()
7044 (require 'mail-utils)
7045 (let* ((fields '("To" "Cc"))
7048 (mail-strip-quoted-names
7049 (mapconcat 'message-fetch-reply-field fields ","))
7053 (if (string-match message-alternative-emails (car emails))
7054 (setq email (car emails)
7057 (unless (or (not email) (equal email user-mail-address))
7058 (goto-char (point-max))
7059 (insert "From: " email "\n"))))
7061 (defun message-options-get (symbol)
7062 (cdr (assq symbol message-options)))
7064 (defun message-options-set (symbol value)
7065 (let ((the-cons (assq symbol message-options)))
7068 (setcdr the-cons value)
7069 (setq message-options (delq the-cons message-options)))
7071 (push (cons symbol value) message-options))))
7074 (defun message-options-set-recipient ()
7076 (message-narrow-to-headers-or-head)
7077 (message-options-set 'message-sender
7078 (mail-strip-quoted-names
7079 (message-fetch-field "from")))
7080 (message-options-set 'message-recipients
7081 (mail-strip-quoted-names
7082 (let ((to (message-fetch-field "to"))
7083 (cc (message-fetch-field "cc"))
7084 (bcc (message-fetch-field "bcc")))
7087 (if (and to cc) ", ")
7089 (if (and (or to cc) bcc) ", ")
7092 (when (featurep 'xemacs)
7093 (require 'messagexmas)
7094 (message-xmas-redefine))
7098 (run-hooks 'message-load-hook)
7101 ;; coding: iso-8859-1
7104 ;;; message.el ends here