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 (defcustom message-sendmail-envelope-from nil
796 "*Envelope-from when sending mail with sendmail.
797 If this is nil, use `user-mail-address'. If it is the symbol
798 `header', use the From: header of the message."
799 :type '(choice (string :tag "From name")
800 (const :tag "Use From: header from message" header)
801 (const :tag "Use `user-mail-address'" nil))
802 :group 'message-sending)
804 ;; qmail-related stuff
805 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
806 "Location of the qmail-inject program."
807 :group 'message-sending
810 (defcustom message-qmail-inject-args nil
811 "Arguments passed to qmail-inject programs.
812 This should be a list of strings, one string for each argument. It
813 may also be a function.
815 For e.g., if you wish to set the envelope sender address so that bounces
816 go to the right place or to deal with listserv's usage of that address, you
817 might set this variable to '(\"-f\" \"you@some.where\")."
818 :group 'message-sending
819 :type '(choice (function)
822 (defvar message-cater-to-broken-inn t
823 "Non-nil means Gnus should not fold the `References' header.
824 Folding `References' makes ancient versions of INN create incorrect
828 (defvar gnus-post-method)
829 (defvar gnus-select-method))
830 (defcustom message-post-method
831 (cond ((and (boundp 'gnus-post-method)
832 (listp gnus-post-method)
835 ((boundp 'gnus-select-method)
838 "*Method used to post news.
839 Note that when posting from inside Gnus, for instance, this
840 variable isn't used."
842 :group 'message-sending
843 ;; This should be the `gnus-select-method' widget, but that might
844 ;; create a dependence to `gnus.el'.
847 (defcustom message-generate-headers-first nil
848 "*If non-nil, generate all required headers before composing.
849 The variables `message-required-news-headers' and
850 `message-required-mail-headers' specify which headers to generate.
851 This can also be a list of headers that should be generated before
854 Note that the variable `message-deletable-headers' specifies headers which
855 are to be deleted and then re-generated before sending, so this variable
856 will not have a visible effect for those headers."
857 :group 'message-headers
858 :type '(choice (const :tag "None" nil)
860 (repeat (sexp :tag "Header"))))
862 (defcustom message-setup-hook '(turn-on-mime-edit)
863 "Normal hook, run each time a new outgoing message is initialized.
864 The function `message-setup' runs this hook."
865 :group 'message-various
868 (defcustom message-cancel-hook nil
869 "Hook run when cancelling articles."
870 :group 'message-various
873 (defcustom message-signature-setup-hook nil
874 "Normal hook, run each time a new outgoing message is initialized.
875 It is run after the headers have been inserted and before
876 the signature is inserted."
877 :group 'message-various
880 (defcustom message-bounce-setup-hook nil
881 "Normal hook, run each time a re-sending bounced message is initialized.
882 The function `message-bounce' runs this hook."
883 :group 'message-various
886 (defcustom message-supersede-setup-hook nil
887 "Normal hook, run each time a supersede message is initialized.
888 The function `message-supersede' runs this hook."
889 :group 'message-various
892 (defcustom message-mode-hook nil
893 "Hook run in message mode buffers."
894 :group 'message-various
897 (defcustom message-header-hook '((lambda () (mime-encode-header-in-buffer t)))
898 "Hook run in a message mode buffer narrowed to the headers."
899 :group 'message-various
902 (defcustom message-header-setup-hook nil
903 "Hook called narrowed to the headers when setting up a message buffer."
904 :group 'message-various
907 (defcustom message-minibuffer-local-map
908 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
909 (set-keymap-parent map minibuffer-local-map)
911 "Keymap for `message-read-from-minibuffer'.")
914 (defcustom message-citation-line-function 'message-insert-citation-line
915 "*Function called to insert the \"Whomever writes:\" line.
917 Note that Gnus provides a feature where the reader can click on
918 `writes:' to hide the cited text. If you change this line too much,
919 people who read your message will have to change their Gnus
920 configuration. See the variable `gnus-cite-attribution-suffix'."
922 :group 'message-insertion)
925 (defcustom message-yank-prefix "> "
926 "*Prefix inserted on the lines of yanked messages.
927 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
928 See also `message-yank-cited-prefix'."
930 :group 'message-insertion)
932 (defcustom message-yank-add-new-references t
933 "Non-nil means new IDs will be added to \"References\" field when an
934 article is yanked by the command `message-yank-original' interactively.
935 If it is a symbol `message-id-only', only an ID from \"Message-ID\" field
936 is used, otherwise IDs extracted from \"References\", \"In-Reply-To\" and
937 \"Message-ID\" fields are used."
938 :type '(radio (const :tag "Do not add anything" nil)
939 (const :tag "From Message-Id, References and In-Reply-To fields" t)
940 (const :tag "From only Message-Id field." message-id-only))
941 :group 'message-insertion)
943 (defcustom message-list-references-add-position nil
944 "Integer value means position for adding to \"References\" field when
945 an article is yanked by the command `message-yank-original' interactively."
946 :type '(radio (const :tag "Add to last" nil)
947 (integer :tag "Position from last ID"))
948 :group 'message-insertion)
950 (defcustom message-yank-cited-prefix ">"
951 "*Prefix inserted on cited or empty lines of yanked messages.
952 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
953 See also `message-yank-prefix'."
955 :group 'message-insertion)
957 (defcustom message-indentation-spaces 3
958 "*Number of spaces to insert at the beginning of each cited line.
959 Used by `message-yank-original' via `message-yank-cite'."
960 :group 'message-insertion
964 (defcustom message-cite-function 'message-cite-original
965 "*Function for citing an original message.
966 Predefined functions include `message-cite-original' and
967 `message-cite-original-without-signature'.
968 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
969 :type '(radio (function-item message-cite-original)
970 (function-item message-cite-original-without-signature)
971 (function-item mu-cite-original)
972 (function-item sc-cite-original)
973 (function :tag "Other"))
974 :group 'message-insertion)
977 (defcustom message-suspend-font-lock-when-citing nil
978 "Non-nil means suspend font-lock'ing while citing an original message.
979 Some lazy demand-driven fontification tools (or Emacs itself) have a
980 bug that they often miss a buffer to be fontified. It will mostly
981 occur when Emacs prompts user for any inputs in the minibuffer.
982 Setting this option to non-nil may help you to avoid unpleasant errors
983 even if it is an add-hoc expedient."
985 :group 'message-insertion)
988 (defcustom message-indent-citation-function 'message-indent-citation
989 "*Function for modifying a citation just inserted in the mail buffer.
990 This can also be a list of functions. Each function can find the
991 citation between (point) and (mark t). And each function should leave
992 point and mark around the citation text as modified."
994 :group 'message-insertion)
997 (defcustom message-signature t
998 "*String to be inserted at the end of the message buffer.
999 If t, the `message-signature-file' file will be inserted instead.
1000 If a function, the result from the function will be used instead.
1001 If a form, the result from the form will be used instead."
1003 :group 'message-insertion)
1006 (defcustom message-signature-file "~/.signature"
1007 "*Name of file containing the text inserted at end of message buffer.
1008 Ignored if the named file doesn't exist.
1009 If nil, don't insert a signature."
1010 :type '(choice file (const :tags "None" nil))
1011 :group 'message-insertion)
1014 (defcustom message-signature-insert-empty-line t
1015 "*If non-nil, insert an empty line before the signature separator."
1017 :group 'message-insertion)
1019 (defcustom message-distribution-function nil
1020 "*Function called to return a Distribution header."
1021 :group 'message-news
1022 :group 'message-headers
1023 :type '(choice function (const nil)))
1025 (defcustom message-expires 14
1026 "Number of days before your article expires."
1027 :group 'message-news
1028 :group 'message-headers
1029 :link '(custom-manual "(message)News Headers")
1032 (defcustom message-user-path nil
1033 "If nil, use the NNTP server name in the Path header.
1034 If stringp, use this; if non-nil, use no host name (user name only)."
1035 :group 'message-news
1036 :group 'message-headers
1037 :link '(custom-manual "(message)News Headers")
1038 :type '(choice (const :tag "nntp" nil)
1039 (string :tag "name")
1040 (sexp :tag "none" :format "%t" t)))
1042 (defvar message-reply-buffer nil)
1043 (defvar message-reply-headers nil
1044 "The headers of the current replied article.
1045 It is a vector of the following headers:
1046 \[number subject from date id references chars lines xref extra].")
1047 (defvar message-sent-message-via nil)
1048 (defvar message-checksum nil)
1049 (defvar message-send-actions nil
1050 "A list of actions to be performed upon successful sending of a message.")
1051 (defvar message-exit-actions nil
1052 "A list of actions to be performed upon exiting after sending a message.")
1053 (defvar message-kill-actions nil
1054 "A list of actions to be performed before killing a message buffer.")
1055 (defvar message-postpone-actions nil
1056 "A list of actions to be performed after postponing a message.")
1057 (defvar message-original-frame nil)
1058 (defvar message-parameter-alist nil)
1059 (defvar message-startup-parameter-alist nil)
1061 (define-widget 'message-header-lines 'text
1062 "All header lines must be LFD terminated."
1063 :format "%{%t%}:%n%v"
1064 :valid-regexp "^\\'"
1065 :error "All header lines must be newline terminated")
1067 (defcustom message-default-headers ""
1068 "*A string containing header lines to be inserted in outgoing messages.
1069 It is inserted before you edit the message, so you can edit or delete
1071 :group 'message-headers
1072 :type 'message-header-lines)
1074 (defcustom message-default-mail-headers ""
1075 "*A string of header lines to be inserted in outgoing mails."
1076 :group 'message-headers
1077 :group 'message-mail
1078 :type 'message-header-lines)
1080 (defcustom message-default-news-headers ""
1081 "*A string of header lines to be inserted in outgoing news articles."
1082 :group 'message-headers
1083 :group 'message-news
1084 :type 'message-header-lines)
1086 ;; Note: could use /usr/ucb/mail instead of sendmail;
1087 ;; options -t, and -v if not interactive.
1088 (defcustom message-mailer-swallows-blank-line
1089 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1090 system-configuration)
1091 (file-readable-p "/etc/sendmail.cf")
1092 (let ((buffer (get-buffer-create " *temp*")))
1096 (insert-file-contents "/etc/sendmail.cf")
1097 (goto-char (point-min))
1098 (let ((case-fold-search nil))
1099 (re-search-forward "^OR\\>" nil t)))
1100 (kill-buffer buffer))))
1101 ;; According to RFC822, "The field-name must be composed of printable
1102 ;; ASCII characters (i. e., characters that have decimal values between
1103 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1105 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1106 "*Set this non-nil if the system's mailer runs the header and body together.
1107 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1108 The value should be an expression to test whether the problem will
1110 :group 'message-sending
1113 ;;; XXX: This symbol is overloaded! See below.
1114 (defvar message-user-agent nil
1115 "String of the form of PRODUCT/VERSION. Used for User-Agent header field.")
1117 (static-when (boundp 'MULE)
1118 (require 'reporter));; `define-mail-user-agent' is here.
1121 (define-mail-user-agent 'message-user-agent
1122 'message-mail 'message-send-and-exit
1123 'message-kill-buffer 'message-send-hook)
1125 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
1126 "If non-nil, delete the deletable headers before feeding to mh.")
1128 (defvar message-send-method-alist
1129 '((news message-news-p message-send-via-news)
1130 (mail message-mail-p message-send-via-mail))
1131 "Alist of ways to send outgoing messages.
1132 Each element has the form
1134 \(TYPE PREDICATE FUNCTION)
1136 where TYPE is a symbol that names the method; PREDICATE is a function
1137 called without any parameters to determine whether the message is
1138 a message of type TYPE; and FUNCTION is a function to be called if
1139 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1142 (defcustom message-mail-alias-type 'abbrev
1143 "*What alias expansion type to use in Message buffers.
1144 The default is `abbrev', which uses mailabbrev. nil switches
1147 :link '(custom-manual "(message)Mail Aliases")
1148 :type '(choice (const :tag "Use Mailabbrev" abbrev)
1149 (const :tag "No expansion" nil)))
1151 (defcustom message-auto-save-directory
1152 (file-name-as-directory (nnheader-concat message-directory "drafts"))
1153 "*Directory where Message auto-saves buffers if Gnus isn't running.
1154 If nil, Message won't auto-save."
1155 :group 'message-buffers
1156 :type '(choice directory (const :tag "Don't auto-save" nil)))
1158 (defcustom message-default-charset
1159 (and (featurep 'xemacs) (not (featurep 'mule)) 'iso-8859-1)
1160 "Default charset used in non-MULE XEmacsen."
1165 (defcustom message-dont-reply-to-names
1166 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
1167 "*A regexp specifying addresses to prune when doing wide replies.
1168 A value of nil means exclude your own user name only."
1171 :type '(choice (const :tag "Yourself" nil)
1174 (defvar message-shoot-gnksa-feet nil
1175 "*A list of GNKSA feet you are allowed to shoot.
1176 Gnus gives you all the opportunity you could possibly want for
1177 shooting yourself in the foot. Also, Gnus allows you to shoot the
1178 feet of Good Net-Keeping Seal of Approval. The following are foot
1180 `empty-article' Allow you to post an empty article;
1181 `quoted-text-only' Allow you to post quoted text only;
1182 `multiple-copies' Allow you to post multiple copies;
1183 `cancel-messages' Allow you to cancel or supersede messages from
1184 your other email addresses.")
1186 (defsubst message-gnksa-enable-p (feature)
1187 (or (not (listp message-shoot-gnksa-feet))
1188 (memq feature message-shoot-gnksa-feet)))
1190 ;;; Internal variables.
1191 ;;; Well, not really internal.
1193 (defvar message-mode-syntax-table
1194 (let ((table (copy-syntax-table text-mode-syntax-table)))
1195 (modify-syntax-entry ?% ". " table)
1196 (modify-syntax-entry ?> ". " table)
1197 (modify-syntax-entry ?< ". " table)
1199 "Syntax table used while in Message mode.")
1201 (defface message-header-to-face
1204 (:foreground "green2" :bold t))
1207 (:foreground "MidnightBlue" :bold t))
1209 (:bold t :italic t)))
1210 "Face used for displaying From headers."
1211 :group 'message-faces)
1213 (defface message-header-cc-face
1216 (:foreground "green4" :bold t))
1219 (:foreground "MidnightBlue"))
1222 "Face used for displaying Cc headers."
1223 :group 'message-faces)
1225 (defface message-header-subject-face
1228 (:foreground "green3"))
1231 (:foreground "navy blue" :bold t))
1234 "Face used for displaying subject headers."
1235 :group 'message-faces)
1237 (defface message-header-newsgroups-face
1240 (:foreground "yellow" :bold t :italic t))
1243 (:foreground "blue4" :bold t :italic t))
1245 (:bold t :italic t)))
1246 "Face used for displaying newsgroups headers."
1247 :group 'message-faces)
1249 (defface message-header-other-face
1252 (:foreground "#b00000"))
1255 (:foreground "steel blue"))
1257 (:bold t :italic t)))
1258 "Face used for displaying newsgroups headers."
1259 :group 'message-faces)
1261 (defface message-header-name-face
1264 (:foreground "DarkGreen"))
1267 (:foreground "cornflower blue"))
1270 "Face used for displaying header names."
1271 :group 'message-faces)
1273 (defface message-header-xheader-face
1276 (:foreground "blue"))
1279 (:foreground "blue"))
1282 "Face used for displaying X-Header headers."
1283 :group 'message-faces)
1285 (defface message-separator-face
1288 (:foreground "blue3"))
1291 (:foreground "brown"))
1294 "Face used for displaying the separator."
1295 :group 'message-faces)
1297 (defface message-cited-text-face
1300 (:foreground "red"))
1303 (:foreground "red"))
1306 "Face used for displaying cited text names."
1307 :group 'message-faces)
1309 (defface message-mml-face
1312 (:foreground "ForestGreen"))
1315 (:foreground "ForestGreen"))
1318 "Face used for displaying MML."
1319 :group 'message-faces)
1321 (defun message-font-lock-make-header-matcher (regexp)
1324 (let ((start (point)))
1327 (goto-char (point-min))
1328 (if (re-search-forward
1329 (concat "^" (regexp-quote mail-header-separator) "$")
1331 (setq limit (min limit (match-beginning 0))))
1333 (and (< start limit)
1334 (re-search-forward ,regexp limit t))))))
1335 (if (featurep 'bytecomp)
1339 (defvar message-font-lock-keywords
1340 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1341 `((,(message-font-lock-make-header-matcher
1342 (concat "^\\([Tt]o:\\)" content))
1343 (1 'message-header-name-face)
1344 (2 'message-header-to-face nil t))
1345 (,(message-font-lock-make-header-matcher
1346 (concat "^\\([GBF]?[Cc][Cc]:\\|[Rr]eply-[Tt]o:\\|"
1347 "[Mm]ail-[Cc]opies-[Tt]o:\\|"
1348 "[Mm]ail-[Rr]eply-[Tt]o:\\|"
1349 "[Mm]ail-[Ff]ollowup-[Tt]o:\\)" content))
1350 (1 'message-header-name-face)
1351 (2 'message-header-cc-face nil t))
1352 (,(message-font-lock-make-header-matcher
1353 (concat "^\\([Ss]ubject:\\)" content))
1354 (1 'message-header-name-face)
1355 (2 'message-header-subject-face nil t))
1356 (,(message-font-lock-make-header-matcher
1357 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content))
1358 (1 'message-header-name-face)
1359 (2 'message-header-newsgroups-face nil t))
1360 (,(message-font-lock-make-header-matcher
1361 (concat "^\\([A-Z][^: \n\t]+:\\)" content))
1362 (1 'message-header-name-face)
1363 (2 'message-header-other-face nil t))
1364 (,(message-font-lock-make-header-matcher
1365 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content))
1366 (1 'message-header-name-face)
1367 (2 'message-header-name-face))
1368 ,@(if (and mail-header-separator
1369 (not (equal mail-header-separator "")))
1370 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1371 1 'message-separator-face))
1374 (re-search-forward (concat "^\\("
1375 message-cite-prefix-regexp
1378 (0 'message-cited-text-face))
1379 (,mime-edit-tag-regexp
1380 (0 'message-mml-face))))
1381 "Additional expressions to highlight in Message mode.")
1383 ;; XEmacs does it like this. For Emacs, we have to set the
1384 ;; `font-lock-defaults' buffer-local variable.
1385 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
1387 (defvar message-face-alist
1388 '((bold . bold-region)
1389 (underline . underline-region)
1390 (default . (lambda (b e)
1392 (ununderline-region b e))))
1393 "Alist of mail and news faces for facemenu.
1394 The cdr of each entry is a function for applying the face to a region.")
1396 (defcustom message-send-hook nil
1397 "Hook run before sending messages.
1398 This hook is run quite early when sending."
1399 :group 'message-various
1400 :options '(ispell-message)
1403 (defcustom message-send-mail-hook nil
1404 "Hook run before sending mail messages.
1405 This hook is run very late -- just before the message is sent as
1407 :group 'message-various
1410 (defcustom message-send-news-hook nil
1411 "Hook run before sending news messages.
1412 This hook is run very late -- just before the message is sent as
1414 :group 'message-various
1417 (defcustom message-sent-hook nil
1418 "Hook run after sending messages."
1419 :group 'message-various
1422 (defcustom message-use-multi-frames nil
1423 "Make new frame when sending messages."
1424 :group 'message-frames
1427 (defcustom message-delete-frame-on-exit nil
1428 "Delete frame after sending messages."
1429 :group 'message-frames
1430 :type '(choice (const :tag "off" nil)
1431 (const :tag "always" t)
1432 (const :tag "ask" ask)))
1434 (defvar message-draft-coding-system
1435 nnheader-auto-save-coding-system
1436 "*Coding system to compose mail.
1437 If you'd like to make it possible to share draft files between XEmacs
1438 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1439 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1441 (defcustom message-send-mail-partially-limit 1000000
1442 "The limitation of messages sent as message/partial.
1443 The lower bound of message size in characters, beyond which the message
1444 should be sent in several parts. If it is nil, the size is unlimited."
1446 :group 'message-buffers
1447 :type '(choice (const :tag "unlimited" nil)
1450 (defcustom message-alternative-emails nil
1451 "A regexp to match the alternative email addresses.
1452 The first matched address (not primary one) is used in the From field."
1453 :group 'message-headers
1454 :type '(choice (const :tag "Always use primary" nil)
1457 (defcustom message-hierarchical-addresses nil
1458 "A list of hierarchical mail address definitions.
1460 Inside each entry, the first address is the \"top\" address, and
1461 subsequent addresses are subaddresses; this is used to indicate that
1462 mail sent to the first address will automatically be delivered to the
1463 subaddresses. So if the first address appears in the recipient list
1464 for a message, the subaddresses will be removed (if present) before
1465 the mail is sent. All addresses in this structure should be
1467 :group 'message-headers
1468 :type '(repeat (repeat string)))
1470 (defcustom message-mail-user-agent nil
1471 "Like `mail-user-agent'.
1472 Except if it is nil, use Gnus native MUA; if it is t, use
1474 :type '(radio (const :tag "Gnus native"
1477 (const :tag "`mail-user-agent'"
1480 (function-item :tag "Default Emacs mail"
1482 sendmail-user-agent)
1483 (function-item :tag "Emacs interface to MH"
1486 (function :tag "Other"))
1490 (defcustom message-wide-reply-confirm-recipients nil
1491 "Whether to confirm a wide reply to multiple email recipients.
1492 If this variable is nil, don't ask whether to reply to all recipients.
1493 If this variable is non-nil, pose the question \"Reply to all
1494 recipients?\" before a wide reply to multiple recipients. If the user
1495 answers yes, reply to all recipients as usual. If the user answers
1496 no, only reply back to the author."
1498 :group 'message-headers
1501 (defcustom message-user-fqdn nil
1502 "*Domain part of Messsage-Ids."
1503 :group 'message-headers
1504 :link '(custom-manual "(message)News Headers")
1507 ;;; Internal variables.
1509 (defvar message-sending-message "Sending...")
1510 (defvar message-buffer-list nil)
1511 (defvar message-this-is-news nil)
1512 (defvar message-this-is-mail nil)
1513 (defvar message-draft-article nil)
1514 (defvar message-mime-part nil)
1515 (defvar message-posting-charset nil)
1517 ;; Byte-compiler warning
1519 (defvar gnus-active-hashtb)
1520 (defvar gnus-read-active-file))
1522 ;;; Regexp matching the delimiter of messages in UNIX mail format
1523 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1524 ;;; of rmail.el's rmail-unix-mail-delimiter.
1525 (defvar message-unix-mail-delimiter
1526 (let ((time-zone-regexp
1527 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1528 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1534 ;; Many things can happen to an RFC 822 mailbox before it is put into
1535 ;; a `From' line. The leading phrase can be stripped, e.g.
1536 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1537 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1538 ;; can be removed, e.g.
1539 ;; From: joe@y.z (Joe K
1541 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1544 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1545 ;; The mailbox can be removed or be replaced by white space, e.g.
1546 ;; From: "Joe User"{space}{tab}
1548 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1549 ;; where {space} and {tab} represent the Ascii space and tab characters.
1550 ;; We want to match the results of any of these manglings.
1551 ;; The following regexp rejects names whose first characters are
1552 ;; obviously bogus, but after that anything goes.
1553 "\\([^\0-\b\n-\r\^?].*\\)?"
1555 ;; The time the message was sent.
1556 "\\([^\0-\r \^?]+\\) +" ; day of the week
1557 "\\([^\0-\r \^?]+\\) +" ; month
1558 "\\([0-3]?[0-9]\\) +" ; day of month
1559 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1561 ;; Perhaps a time zone, specified by an abbreviation, or by a
1566 " \\([0-9][0-9]+\\) *"
1568 ;; On some systems the time zone can appear after the year, too.
1572 "\\(remote from .*\\)?"
1575 "Regexp matching the delimiter of messages in UNIX mail format.")
1577 (defvar message-unsent-separator
1578 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1579 "^ *---+ +Returned message +---+ *$\\|"
1580 "^Start of returned message$\\|"
1581 "^ *---+ +Original message +---+ *$\\|"
1582 "^ *--+ +begin message +--+ *$\\|"
1583 "^ *---+ +Original message follows +---+ *$\\|"
1584 "^ *---+ +Undelivered message follows +---+ *$\\|"
1585 "^|? *---+ +Message text follows: +---+ *|?$")
1586 "A regexp that matches the separator before the text of a failed message.")
1588 (defvar message-header-format-alist
1590 (To . message-fill-address)
1591 (Cc . message-fill-address)
1602 (References . message-shorten-references)
1604 "Alist used for formatting headers.")
1606 (defvar message-options nil
1607 "Some saved answers when sending message.")
1609 (defvar message-send-mail-real-function nil
1610 "Internal send mail function.")
1612 (defvar message-bogus-system-names "^localhost\\."
1613 "The regexp of bogus system names.")
1615 (defcustom message-valid-fqdn-regexp
1616 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1618 "\\([a-z][a-z]" ;; two letter country TDLs
1619 "\\|biz\\|com\\|edu\\|gov\\|int\\|mil\\|net\\|org"
1620 "\\|aero\\|coop\\|info\\|name\\|museum"
1621 "\\|arpa\\|pro\\|uucp\\|bitnet\\|bofh" ;; old style?
1623 "Regular expression that matches a valid FQDN."
1624 ;; see also: gnus-button-valid-fqdn-regexp
1625 :group 'message-headers
1629 (autoload 'message-setup-toolbar "messagexmas")
1630 (autoload 'mh-new-draft-name "mh-comp")
1631 (autoload 'mh-send-letter "mh-comp")
1632 (autoload 'gnus-point-at-eol "gnus-util")
1633 (autoload 'gnus-point-at-bol "gnus-util")
1634 (autoload 'gnus-output-to-rmail "gnus-util")
1635 (autoload 'gnus-output-to-mail "gnus-util")
1636 (autoload 'nndraft-request-associate-buffer "nndraft")
1637 (autoload 'nndraft-request-expire-articles "nndraft")
1638 (autoload 'gnus-open-server "gnus-int")
1639 (autoload 'gnus-request-post "gnus-int")
1640 (autoload 'gnus-copy-article-buffer "gnus-msg")
1641 (autoload 'gnus-alive-p "gnus-util")
1642 (autoload 'gnus-server-string "gnus")
1643 (autoload 'gnus-group-name-charset "gnus-group")
1644 (autoload 'gnus-group-name-decode "gnus-group")
1645 (autoload 'gnus-groups-from-server "gnus")
1646 (autoload 'rmail-output "rmailout")
1647 (autoload 'gnus-delay-article "gnus-delay")
1648 (autoload 'mu-cite-original "mu-cite"))
1653 ;;; Utility functions.
1655 (defun message-eval-parameter (parameter)
1657 (if (symbolp parameter)
1658 (if (functionp parameter)
1664 (defsubst message-get-parameter (key &optional alist)
1666 (setq alist message-parameter-alist))
1667 (cdr (assq key alist)))
1669 (defmacro message-get-parameter-with-eval (key &optional alist)
1670 `(message-eval-parameter (message-get-parameter ,key ,alist)))
1672 (defmacro message-y-or-n-p (question show &rest text)
1673 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1674 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1676 (defmacro message-delete-line (&optional n)
1677 "Delete the current line (and the next N lines)."
1678 `(delete-region (progn (beginning-of-line) (point))
1679 (progn (forward-line ,(or n 1)) (point))))
1681 (defun message-mark-active-p ()
1682 "Non-nil means the mark and region are currently active in this buffer."
1685 (defun message-unquote-tokens (elems)
1686 "Remove double quotes (\") from strings in list ELEMS."
1687 (mapcar (lambda (item)
1688 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1689 (setq item (concat (match-string 1 item)
1690 (match-string 2 item))))
1694 (defun message-tokenize-header (header &optional separator)
1695 "Split HEADER into a list of header elements.
1696 SEPARATOR is a string of characters to be used as separators. \",\"
1697 is used by default."
1700 (let ((regexp (format "[%s]+" (or separator ",")))
1705 (message-set-work-buffer)
1707 (goto-char (point-min))
1712 (cond ((and (> (point) beg)
1714 (and (looking-at regexp)
1717 (push (buffer-substring beg (point)) elems)
1718 (setq beg (match-end 0)))
1719 ((eq (char-after) ?\")
1720 (setq quoted (not quoted)))
1721 ((and (eq (char-after) ?\()
1724 ((and (eq (char-after) ?\))
1727 (nreverse elems)))))
1729 (defun message-mail-file-mbox-p (file)
1730 "Say whether FILE looks like a Unix mbox file."
1731 (when (and (file-exists-p file)
1732 (file-readable-p file)
1733 (file-regular-p file))
1735 (nnheader-insert-file-contents file)
1736 (goto-char (point-min))
1737 (looking-at message-unix-mail-delimiter))))
1739 (defun message-fetch-field (header &optional not-all)
1740 "The same as `mail-fetch-field', only remove all newlines."
1741 (let* ((inhibit-point-motion-hooks t)
1742 (case-fold-search t)
1743 (value (mail-fetch-field header nil (not not-all))))
1745 (while (string-match "\n[\t ]+" value)
1746 (setq value (replace-match " " t t value)))
1747 (set-text-properties 0 (length value) nil value)
1750 (defun message-narrow-to-field ()
1751 "Narrow the buffer to the header on the current line."
1757 (if (re-search-forward "^[^ \n\t]" nil t)
1762 (goto-char (point-min)))
1764 (defun message-add-header (&rest headers)
1765 "Add the HEADERS to the message header, skipping those already present."
1768 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1769 (error "Invalid header `%s'" (car headers)))
1770 (setq hclean (match-string 1 (car headers)))
1772 (message-narrow-to-headers)
1773 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1774 (goto-char (point-max))
1775 (if (string-match "\n$" (car headers))
1776 (insert (car headers))
1777 (insert (car headers) ?\n)))))
1778 (setq headers (cdr headers))))
1780 (defmacro message-with-reply-buffer (&rest forms)
1781 "Evaluate FORMS in the reply buffer, if it exists."
1782 `(let ((buffer (message-eval-parameter message-reply-buffer)))
1784 (buffer-name buffer))
1789 (put 'message-with-reply-buffer 'lisp-indent-function 0)
1790 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
1792 (defun message-fetch-reply-field (header)
1793 "Fetch field HEADER from the message we're replying to."
1794 (message-with-reply-buffer
1796 (mail-narrow-to-head)
1797 (message-fetch-field header))))
1799 (defun message-set-work-buffer ()
1800 (if (get-buffer " *message work*")
1802 (set-buffer " *message work*")
1804 (set-buffer (get-buffer-create " *message work*"))
1805 (kill-all-local-variables)))
1807 (defun message-functionp (form)
1808 "Return non-nil if FORM is funcallable."
1809 (or (and (symbolp form) (fboundp form))
1810 (and (listp form) (eq (car form) 'lambda))
1811 (byte-code-function-p form)))
1813 (defun message-strip-list-identifiers (subject)
1814 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1815 (require 'gnus-sum) ; for gnus-list-identifiers
1816 (let ((regexp (if (stringp gnus-list-identifiers)
1817 gnus-list-identifiers
1818 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1819 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1820 " *\\)\\)+\\(Re: +\\)?\\)") subject)
1821 (concat (substring subject 0 (match-beginning 1))
1822 (or (match-string 3 subject)
1823 (match-string 5 subject))
1828 (defun message-strip-subject-re (subject)
1829 "Remove \"Re:\" from subject lines in string SUBJECT."
1830 (if (string-match message-subject-re-regexp subject)
1831 (substring subject (match-end 0))
1834 ;;; Start of functions adopted from `message-utils.el'.
1836 (defun message-strip-subject-trailing-was (subject)
1837 "Remove trailing \"(Was: <old subject>)\" from SUBJECT lines.
1838 Leading \"Re: \" is not stripped by this function. Use the function
1839 `message-strip-subject-re' for this."
1840 (let* ((query message-subject-trailing-was-query)
1845 message-subject-trailing-was-ask-regexp
1846 message-subject-trailing-was-regexp)
1849 (setq new (substring subject 0 (match-beginning 0))))
1850 (if (or (not found) (eq query nil))
1853 (if (message-y-or-n-p
1854 "Strip `(was: <old subject>)' in subject? " t
1856 "Strip `(was: <old subject>)' in subject "
1857 "and use the new one instead?\n\n"
1858 "Current subject is: \""
1860 "New subject would be: \""
1862 "See the variable `message-subject-trailing-was-query' "
1863 "to get rid of this query."
1868 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
1871 (defun message-change-subject (new-subject)
1872 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
1875 (read-from-minibuffer "New subject: ")))
1876 (cond ((and (not (or (null new-subject) ; new subject not empty
1877 (zerop (string-width new-subject))
1878 (string-match "^[ \t]*$" new-subject))))
1880 (let ((old-subject (message-fetch-field "Subject")))
1881 (cond ((not old-subject)
1882 (error "No current subject"))
1885 (regexp-quote new-subject)
1887 old-subject)) ; yes, it really is a new subject
1888 ;; delete eventual Re: prefix
1890 (message-strip-subject-re old-subject))
1891 (message-goto-subject)
1892 (message-delete-line)
1893 (insert (concat "Subject: "
1896 old-subject ")\n")))))))))
1899 (defun message-mark-inserted-region (beg end)
1900 "Mark some region in the current article with enclosing tags.
1901 See `message-mark-insert-begin' and `message-mark-insert-end'."
1904 ; add to the end of the region first, otherwise end would be invalid
1906 (insert message-mark-insert-end)
1908 (insert message-mark-insert-begin)))
1911 (defun message-mark-insert-file (file)
1912 "Insert FILE at point, marking it with enclosing tags.
1913 See `message-mark-insert-begin' and `message-mark-insert-end'."
1914 (interactive "fFile to insert: ")
1915 ;; reverse insertion to get correct result.
1917 (insert message-mark-insert-end)
1919 (insert-file-contents file)
1921 (insert message-mark-insert-begin)))
1924 (defun message-add-archive-header ()
1925 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
1926 The note can be customized using `message-archive-note'. When called with a
1927 prefix argument, ask for a text to insert. If you don't want the note in the
1928 body, set `message-archive-note' to nil."
1930 (if current-prefix-arg
1931 (setq message-archive-note
1932 (read-from-minibuffer "Reason for No-Archive: "
1933 (cons message-archive-note 0))))
1935 (if (message-goto-signature)
1936 (re-search-backward message-signature-separator))
1937 (when message-archive-note
1938 (insert message-archive-note)
1940 (message-add-header message-archive-header)
1941 (message-sort-headers)))
1944 (defun message-cross-post-followup-to-header (target-group)
1945 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
1946 With prefix-argument just set Follow-Up, don't cross-post."
1948 (list ; Completion based on Gnus
1949 (completing-read "Followup To: "
1950 (if (boundp 'gnus-newsrc-alist)
1952 nil nil '("poster" . 0)
1953 (if (boundp 'gnus-group-history)
1954 'gnus-group-history))))
1955 (message-remove-header "Follow[Uu]p-[Tt]o" t)
1956 (message-goto-newsgroups)
1958 ;; if we already did a crosspost before, kill old target
1959 (if (and message-cross-post-old-target
1961 (regexp-quote (concat "," message-cross-post-old-target))
1964 ;; unless (followup is to poster or user explicitly asked not
1965 ;; to cross-post, or target-group is already in Newsgroups)
1966 ;; add target-group to Newsgroups line.
1968 ;; def: cross-post, req:no
1969 (and message-cross-post-default (not current-prefix-arg))
1970 ;; def: no-cross-post, req:yes
1971 (and (not message-cross-post-default) current-prefix-arg))
1972 (not (string-match "poster" target-group))
1973 (not (string-match (regexp-quote target-group)
1974 (message-fetch-field "Newsgroups"))))
1976 (insert (concat "," target-group))))
1977 (end-of-line) ; ensure Followup: comes after Newsgroups:
1978 ;; unless new followup would be identical to Newsgroups line
1979 ;; make a new Followup-To line
1980 (if (not (string-match (concat "^[ \t]*"
1983 (message-fetch-field "Newsgroups")))
1984 (insert (concat "\nFollowup-To: " target-group)))
1985 (setq message-cross-post-old-target target-group))
1988 (defun message-cross-post-insert-note (target-group cross-post in-old
1990 "Insert a in message body note about a set Followup or Crosspost.
1991 If there have been previous notes, delete them. TARGET-GROUP specifies the
1992 group to Followup-To. When CROSS-POST is t, insert note about
1993 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
1994 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
1995 been made to before the user asked for a Crosspost."
1996 ;; start scanning body for previous uses
1997 (message-goto-signature)
1998 (let ((head (re-search-backward
1999 (concat "^" mail-header-separator)
2000 nil t))) ; just search in body
2001 (message-goto-signature)
2002 (while (re-search-backward
2003 (concat "^" (regexp-quote message-cross-post-note) ".*")
2005 (message-delete-line))
2006 (message-goto-signature)
2007 (while (re-search-backward
2008 (concat "^" (regexp-quote message-followup-to-note) ".*")
2010 (message-delete-line))
2012 (if (message-goto-signature)
2013 (re-search-backward message-signature-separator))
2016 (string-match "^[ \t]*poster[ \t]*$" target-group))
2017 (insert (concat message-followup-to-note target-group "\n"))
2018 (insert (concat message-cross-post-note target-group "\n")))))
2021 (defun message-cross-post-followup-to (target-group)
2022 "Crossposts message and set Followup-To to TARGET-GROUP.
2023 With prefix-argument just set Follow-Up, don't cross-post."
2025 (list ; Completion based on Gnus
2026 (completing-read "Followup To: "
2027 (if (boundp 'gnus-newsrc-alist)
2029 nil nil '("poster" . 0)
2030 (if (boundp 'gnus-group-history)
2031 'gnus-group-history))))
2032 (cond ((not (or (null target-group) ; new subject not empty
2033 (zerop (string-width target-group))
2034 (string-match "^[ \t]*$" target-group)))
2036 (let* ((old-groups (message-fetch-field "Newsgroups"))
2037 (in-old (string-match
2038 (regexp-quote target-group)
2039 (or old-groups ""))))
2040 ;; check whether target exactly matches old Newsgroups
2041 (cond ((not old-groups)
2042 (error "No current newsgroup"))
2046 (regexp-quote target-group)
2049 ;; yes, Newsgroups line must change
2050 (message-cross-post-followup-to-header target-group)
2051 ;; insert note whether we do cross-post or followup-to
2052 (funcall message-cross-post-note-function
2054 (if (or (and message-cross-post-default
2055 (not current-prefix-arg))
2056 (and (not message-cross-post-default)
2057 current-prefix-arg)) t)
2058 in-old old-groups))))))))
2060 ;;; Reduce To: to Cc: or Bcc: header
2063 (defun message-reduce-to-to-cc ()
2064 "Replace contents of To: header with contents of Cc: or Bcc: header."
2066 (let ((cc-content (message-fetch-field "cc"))
2068 (if (and (not cc-content)
2069 (setq cc-content (message-fetch-field "bcc")))
2074 (message-delete-line)
2075 (insert (concat "To: " cc-content "\n"))
2076 (message-remove-header (if bcc
2080 ;;; End of functions adopted from `message-utils.el'.
2082 (defun message-remove-header (header &optional is-regexp first reverse)
2083 "Remove HEADER in the narrowed buffer.
2084 If IS-REGEXP, HEADER is a regular expression.
2085 If FIRST, only remove the first instance of the header.
2086 Return the number of headers removed."
2087 (goto-char (point-min))
2088 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
2090 (case-fold-search t)
2092 (while (and (not (eobp))
2095 (not (looking-at regexp))
2096 (looking-at regexp))
2103 ;; There might be a continuation header, so we have to search
2104 ;; until we find a new non-continuation line.
2107 (if (re-search-forward "^[^ \t]" nil t)
2108 (goto-char (match-beginning 0))
2111 (if (re-search-forward "^[^ \t]" nil t)
2112 (goto-char (match-beginning 0))
2113 (goto-char (point-max)))))
2116 (defun message-remove-first-header (header)
2117 "Remove the first instance of HEADER if there is more than one."
2119 (regexp (concat "^" (regexp-quote header) ":")))
2121 (goto-char (point-min))
2122 (while (re-search-forward regexp nil t)
2125 (message-remove-header header nil t)
2128 (defun message-narrow-to-headers ()
2129 "Narrow the buffer to the head of the message."
2132 (goto-char (point-min))
2133 (if (re-search-forward
2134 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2137 (goto-char (point-min)))
2139 (defun message-narrow-to-head-1 ()
2140 "Like `message-narrow-to-head'. Don't widen."
2142 (goto-char (point-min))
2143 (if (search-forward "\n\n" nil 1)
2146 (goto-char (point-min)))
2148 (defun message-narrow-to-head ()
2149 "Narrow the buffer to the head of the message.
2150 Point is left at the beginning of the narrowed-to region."
2152 (message-narrow-to-head-1))
2154 (defun message-narrow-to-headers-or-head ()
2155 "Narrow the buffer to the head of the message."
2158 (goto-char (point-min))
2161 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2162 (match-beginning 0))
2163 ((search-forward "\n\n" nil t)
2167 (goto-char (point-min)))
2169 (defun message-news-p ()
2170 "Say whether the current buffer contains a news message."
2171 (and (not message-this-is-mail)
2172 (or message-this-is-news
2175 (message-narrow-to-headers)
2176 (and (message-fetch-field "newsgroups")
2177 (not (message-fetch-field "posted-to"))))))))
2179 (defun message-mail-p ()
2180 "Say whether the current buffer contains a mail message."
2181 (and (not message-this-is-news)
2182 (or message-this-is-mail
2185 (message-narrow-to-headers)
2186 (or (message-fetch-field "to")
2187 (message-fetch-field "cc")
2188 (message-fetch-field "bcc")))))))
2190 (defun message-subscribed-p ()
2191 "Say whether we need to insert a MFT header."
2192 (or message-subscribed-regexps
2193 message-subscribed-addresses
2194 message-subscribed-address-file
2195 message-subscribed-address-functions))
2197 (defun message-next-header ()
2198 "Go to the beginning of the next header."
2200 (or (eobp) (forward-char 1))
2201 (not (if (re-search-forward "^[^ \t]" nil t)
2203 (goto-char (point-max)))))
2205 (defun message-sort-headers-1 ()
2206 "Sort the buffer as headers using `message-rank' text props."
2207 (goto-char (point-min))
2210 nil 'message-next-header
2212 (message-next-header)
2216 (or (get-text-property (point) 'message-rank)
2219 (defun message-sort-headers ()
2220 "Sort the headers of the current message according to `message-header-format-alist'."
2224 (let ((max (1+ (length message-header-format-alist)))
2226 (message-narrow-to-headers)
2227 (while (re-search-forward "^[^ \n]+:" nil t)
2229 (match-beginning 0) (1+ (match-beginning 0))
2231 (if (setq rank (length (memq (assq (intern (buffer-substring
2233 (1- (match-end 0))))
2234 message-header-format-alist)
2235 message-header-format-alist)))
2238 (message-sort-headers-1))))
2248 (defvar message-mode-map nil)
2250 (unless message-mode-map
2251 (setq message-mode-map (make-keymap))
2252 (set-keymap-parent message-mode-map text-mode-map)
2253 (define-key message-mode-map "\C-c?" 'describe-mode)
2255 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
2256 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
2257 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
2258 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
2259 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
2260 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2261 ;; (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2262 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-mail-reply-to)
2263 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2264 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2265 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2266 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2267 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2268 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2269 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2270 (define-key message-mode-map "\C-c\C-f\C-i"
2271 'message-insert-or-toggle-importance)
2272 (define-key message-mode-map "\C-c\C-f\C-a"
2273 'message-generate-unsubscribed-mail-followup-to)
2275 ;; modify headers (and insert notes in body)
2276 (define-key message-mode-map "\C-c\C-fs" 'message-change-subject)
2278 (define-key message-mode-map "\C-c\C-fx" 'message-cross-post-followup-to)
2279 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2280 (define-key message-mode-map "\C-c\C-ft" 'message-reduce-to-to-cc)
2281 (define-key message-mode-map "\C-c\C-fa" 'message-add-archive-header)
2282 ;; mark inserted text
2283 (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2284 (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2286 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2287 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2288 (define-key message-mode-map "\C-c\C-fc" 'message-goto-mail-copies-to)
2290 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2291 (define-key message-mode-map "\C-c\C-fw" 'message-insert-wide-reply)
2292 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2293 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2295 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2296 (define-key message-mode-map "\C-c\M-n"
2297 'message-insert-disposition-notification-to)
2299 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2300 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2301 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2302 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2303 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2304 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2305 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2306 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2308 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2309 (define-key message-mode-map "\C-c\C-s" 'message-send)
2310 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2311 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2312 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2314 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2315 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2316 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2317 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2318 ;;(define-key message-mode-map "\M-q" 'message-fill-paragraph)
2320 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2321 (define-key message-mode-map "\t" 'message-tab)
2322 (define-key message-mode-map "\M-;" 'comment-region)
2324 (define-key message-mode-map "\C-xk" 'message-mimic-kill-buffer))
2327 message-mode-menu message-mode-map "Message Menu."
2329 ["Yank Original" message-yank-original t]
2330 ["Fill Yanked Message" message-fill-yanked-message t]
2331 ["Insert Signature" message-insert-signature t]
2332 ["Caesar (rot13) Message" message-caesar-buffer-body t]
2333 ["Caesar (rot13) Region" message-caesar-region (message-mark-active-p)]
2334 ["Elide Region" message-elide-region
2335 :active (message-mark-active-p)
2336 ,@(if (featurep 'xemacs) nil
2337 '(:help "Replace text in region with an ellipsis"))]
2338 ["Delete Outside Region" message-delete-not-region
2339 :active (message-mark-active-p)
2340 ,@(if (featurep 'xemacs) nil
2341 '(:help "Delete all quoted text outside region"))]
2342 ["Kill To Signature" message-kill-to-signature t]
2343 ["Newline and Reformat" message-newline-and-reformat t]
2344 ["Rename buffer" message-rename-buffer t]
2345 ["Spellcheck" ispell-message
2346 ,@(if (featurep 'xemacs) '(t)
2347 '(:help "Spellcheck this message"))]
2348 ["Attach file as MIME" mime-edit-insert-file
2349 ,@(if (featurep 'xemacs) '(t)
2350 '(:help "Attach a file at point"))]
2352 ["Insert Region Marked" message-mark-inserted-region
2353 :active (message-mark-active-p)
2354 ,@(if (featurep 'xemacs) nil
2355 '(:help "Mark region with enclosing tags"))]
2356 ["Insert File Marked..." message-mark-insert-file
2357 ,@(if (featurep 'xemacs) '(t)
2358 '(:help "Insert file at point marked with enclosing tags"))]
2360 ["Send Message" message-send-and-exit
2361 ,@(if (featurep 'xemacs) '(t)
2362 '(:help "Send this message"))]
2363 ["Postpone Message" message-dont-send
2364 ,@(if (featurep 'xemacs) '(t)
2365 '(:help "File this draft message and exit"))]
2366 ["Send at Specific Time..." gnus-delay-article
2367 ,@(if (featurep 'xemacs) '(t)
2368 '(:help "Ask, then arrange to send message at that time"))]
2369 ["Kill Message" message-kill-buffer
2370 ,@(if (featurep 'xemacs) '(t)
2371 '(:help "Delete this message without sending"))]))
2374 message-mode-field-menu message-mode-map ""
2376 ["Fetch To" message-insert-to t]
2377 ["Fetch Newsgroups" message-insert-newsgroups t]
2379 ["To" message-goto-to t]
2380 ["From" message-goto-from t]
2381 ["Subject" message-goto-subject t]
2382 ["Change subject..." message-change-subject t]
2383 ["Cc" message-goto-cc t]
2384 ["Bcc" message-goto-bcc t]
2385 ["Fcc" message-goto-fcc t]
2386 ["Reply-To" message-goto-reply-to t]
2387 ["Flag As Important" message-insert-importance-high
2388 ,@(if (featurep 'xemacs) '(t)
2389 '(:help "Mark this message as important"))]
2390 ["Flag As Unimportant" message-insert-importance-low
2391 ,@(if (featurep 'xemacs) '(t)
2392 '(:help "Mark this message as unimportant"))]
2394 message-insert-disposition-notification-to
2395 ,@(if (featurep 'xemacs) '(t)
2396 '(:help "Request a receipt notification"))]
2398 ;; (typical) news stuff
2399 ["Summary" message-goto-summary t]
2400 ["Keywords" message-goto-keywords t]
2401 ["Newsgroups" message-goto-newsgroups t]
2402 ["Followup-To" message-goto-followup-to t]
2403 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2404 ["Crosspost / Followup-To..." message-cross-post-followup-to t]
2405 ["Distribution" message-goto-distribution t]
2406 ["X-No-Archive:" message-add-archive-header t ]
2408 ;; (typical) mailing-lists stuff
2409 ["Send to list only" message-to-list-only t]
2410 ["Mail-Followup-To" message-goto-mail-followup-to t]
2411 ["Mail-Reply-To" message-goto-mail-reply-to t]
2412 ["Mail-Copies-To" message-goto-mail-copies-to t]
2413 ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2415 ["Sort Headers" message-sort-headers t]
2416 ["Goto Body" message-goto-body t]
2417 ["Goto Signature" message-goto-signature t]))
2419 (defvar message-tool-bar-map nil)
2422 (defvar facemenu-add-face-function)
2423 (defvar facemenu-remove-face-function))
2425 ;;; Forbidden properties
2427 ;; We use `after-change-functions' to keep special text properties
2428 ;; that interfer with the normal function of message mode out of the
2431 (defcustom message-strip-special-text-properties t
2432 "Strip special properties from the message buffer.
2434 Emacs has a number of special text properties which can break message
2435 composing in various ways. If this option is set, message will strip
2436 these properties from the message composition buffer. However, some
2437 packages requires these properties to be present in order to work.
2438 If you use one of these packages, turn this option off, and hope the
2439 message composition doesn't break too bad."
2440 :group 'message-various
2443 (defconst message-forbidden-properties
2444 ;; No reason this should be clutter up customize. We make it a
2445 ;; property list (rather than a list of property symbols), to be
2446 ;; directly useful for `remove-text-properties'.
2447 '(field nil read-only nil intangible nil invisible nil
2448 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2449 insert-behind-hooks nil point-entered nil point-left nil)
2450 ;; Other special properties:
2451 ;; category, face, display: probably doesn't do any harm.
2452 ;; fontified: is used by font-lock.
2453 ;; syntax-table, local-map: I dunno.
2454 ;; We need to add XEmacs names to the list.
2455 "Property list of with properties.forbidden in message buffers.
2456 The values of the properties are ignored, only the property names are used.")
2458 (defun message-tamago-not-in-use-p (pos)
2459 "Return t when tamago version 4 is not in use at the cursor position.
2460 Tamago version 4 is a popular input method for writing Japanese text.
2461 It uses the properties `intangible', `invisible', `modification-hooks'
2462 and `read-only' when translating ascii or kana text to kanji text.
2463 These properties are essential to work, so we should never strip them."
2464 (not (and (boundp 'egg-modefull-mode)
2465 (symbol-value 'egg-modefull-mode)
2466 (or (memq (get-text-property pos 'intangible)
2467 '(its-part-1 its-part-2))
2468 (get-text-property pos 'egg-end)
2469 (get-text-property pos 'egg-lang)
2470 (get-text-property pos 'egg-start)))))
2472 (defun message-strip-forbidden-properties (begin end &optional old-length)
2473 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2474 This function is intended to be called from `after-change-functions'.
2475 See also `message-forbidden-properties'."
2476 (when (and message-strip-special-text-properties
2477 (message-tamago-not-in-use-p begin)
2478 ;; Check whether the invisible MIME part is not inserted.
2479 (not (text-property-any begin end 'mime-edit-invisible t)))
2480 (remove-text-properties begin end message-forbidden-properties)))
2483 (define-derived-mode message-mode text-mode "Message"
2484 "Major mode for editing mail and news to be sent.
2485 Like Text Mode but with these additional commands:\\<message-mode-map>
2486 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2487 C-c C-d Postpone sending the message C-c C-k Kill the message
2488 C-c C-f move to a header field (and create it if there isn't):
2489 C-c C-f C-t move to To C-c C-f C-s move to Subject
2490 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2491 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2492 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2493 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2494 C-c C-f C-o move to From (\"Originator\")
2495 C-c C-f C-f move to Followup-To
2496 C-c C-f C-m move to Mail-Followup-To
2497 C-c C-f c move to Mail-Copies-To
2498 C-c C-f C-i cycle through Importance values
2499 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2500 C-c C-f x crossposting with FollowUp-To header and note in body
2501 C-c C-f t replace To: header with contents of Cc: or Bcc:
2502 C-c C-f a Insert X-No-Archive: header and a note in the body
2503 C-c C-t `message-insert-to' (add a To header to a news followup)
2504 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2505 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2506 C-c C-b `message-goto-body' (move to beginning of message text).
2507 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2508 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2509 C-c C-y `message-yank-original' (insert current message, if any).
2510 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2511 C-c C-e `message-elide-region' (elide the text between point and mark).
2512 C-c C-v `message-delete-not-region' (remove the text outside the region).
2513 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2514 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2515 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2516 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2517 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2518 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2519 M-RET `message-newline-and-reformat' (break the line and reformat)."
2520 (setq local-abbrev-table text-mode-abbrev-table)
2521 (set (make-local-variable 'message-reply-buffer) nil)
2522 (make-local-variable 'message-send-actions)
2523 (make-local-variable 'message-exit-actions)
2524 (make-local-variable 'message-kill-actions)
2525 (make-local-variable 'message-postpone-actions)
2526 (make-local-variable 'message-draft-article)
2527 (setq buffer-offer-save t)
2528 (set (make-local-variable 'facemenu-add-face-function)
2530 (let ((face-fun (cdr (assq face message-face-alist))))
2532 (funcall face-fun (point) end)
2533 (error "Face %s not configured for %s mode" face mode-name)))
2535 (set (make-local-variable 'facemenu-remove-face-function) t)
2536 (set (make-local-variable 'message-reply-headers) nil)
2537 (make-local-variable 'message-user-agent)
2538 (make-local-variable 'message-post-method)
2539 (set (make-local-variable 'message-sent-message-via) nil)
2540 (set (make-local-variable 'message-checksum) nil)
2541 (make-local-variable 'message-parameter-alist)
2542 (setq message-parameter-alist
2543 (copy-sequence message-startup-parameter-alist))
2544 (message-setup-fill-variables)
2546 (make-local-variable 'paragraph-separate)
2547 (format "\\(%s\\)\\|\\(%s\\)"
2549 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
2550 ;; Allow using comment commands to add/remove quoting.
2551 (set (make-local-variable 'comment-start) message-yank-prefix)
2552 (if (featurep 'xemacs)
2553 (message-setup-toolbar)
2554 (set (make-local-variable 'font-lock-defaults)
2555 '(message-font-lock-keywords t))
2556 (if (boundp 'tool-bar-map)
2557 (set (make-local-variable 'tool-bar-map) (message-tool-bar-map))))
2558 (easy-menu-add message-mode-menu message-mode-map)
2559 (easy-menu-add message-mode-field-menu message-mode-map)
2560 ;; make-local-hook is harmless though obsolete in Emacs 21.
2561 ;; Emacs 20 and XEmacs need make-local-hook.
2562 (make-local-hook 'after-change-functions)
2563 ;; Mmmm... Forbidden properties...
2564 (add-hook 'after-change-functions 'message-strip-forbidden-properties
2566 ;; Allow mail alias things.
2567 (when (eq message-mail-alias-type 'abbrev)
2568 (if (fboundp 'mail-abbrevs-setup)
2569 (mail-abbrevs-setup)
2570 (mail-aliases-setup)))
2571 (unless buffer-file-name
2572 (message-set-auto-save-file-name))
2573 (set (make-local-variable 'indent-tabs-mode) nil)) ;No tabs for indentation.
2575 (defun message-setup-fill-variables ()
2576 "Setup message fill variables."
2577 (set (make-local-variable 'fill-paragraph-function)
2578 'message-fill-paragraph)
2579 (make-local-variable 'paragraph-separate)
2580 (make-local-variable 'paragraph-start)
2581 (make-local-variable 'adaptive-fill-regexp)
2582 (unless (boundp 'adaptive-fill-first-line-regexp)
2583 (setq adaptive-fill-first-line-regexp nil))
2584 (make-local-variable 'adaptive-fill-first-line-regexp)
2585 (let ((quote-prefix-regexp
2586 ;; User should change message-cite-prefix-regexp if
2587 ;; message-yank-prefix is set to an abnormal value.
2588 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
2589 (setq paragraph-start
2591 (regexp-quote mail-header-separator) "$\\|"
2592 "[ \t]*$\\|" ; blank lines
2593 "-- $\\|" ; signature delimiter
2594 "---+$\\|" ; delimiters for forwarded messages
2595 page-delimiter "$\\|" ; spoiler warnings
2596 ".*wrote:$\\|" ; attribution lines
2597 quote-prefix-regexp "$")) ; empty lines in quoted text
2598 (setq paragraph-separate paragraph-start)
2599 (setq adaptive-fill-regexp
2600 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
2601 (setq adaptive-fill-first-line-regexp
2602 (concat quote-prefix-regexp "\\|"
2603 adaptive-fill-first-line-regexp)))
2604 (make-local-variable 'auto-fill-inhibit-regexp)
2605 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2606 (setq auto-fill-inhibit-regexp nil)
2607 (make-local-variable 'normal-auto-fill-function)
2608 (setq normal-auto-fill-function 'message-do-auto-fill)
2609 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2610 ;; In that case, ensure that it uses the right function. The real
2611 ;; solution would be not to use `define-derived-mode', and run
2612 ;; `text-mode-hook' ourself at the end of the mode.
2613 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2614 (when auto-fill-function
2615 (setq auto-fill-function normal-auto-fill-function)))
2620 ;;; Message mode commands
2623 ;;; Movement commands
2625 (defun message-goto-to ()
2626 "Move point to the To header."
2628 (message-position-on-field "To"))
2630 (defun message-goto-from ()
2631 "Move point to the From header."
2633 (message-position-on-field "From"))
2635 (defun message-goto-subject ()
2636 "Move point to the Subject header."
2638 (message-position-on-field "Subject"))
2640 (defun message-goto-cc ()
2641 "Move point to the Cc header."
2643 (message-position-on-field "Cc" "To"))
2645 (defun message-goto-bcc ()
2646 "Move point to the Bcc header."
2648 (message-position-on-field "Bcc" "Cc" "To"))
2650 (defun message-goto-fcc ()
2651 "Move point to the Fcc header."
2653 (message-position-on-field "Fcc" "To" "Newsgroups"))
2655 (defun message-goto-reply-to ()
2656 "Move point to the Reply-To header."
2658 (message-position-on-field "Reply-To" "Subject"))
2660 (defun message-goto-mail-reply-to ()
2661 "Move point to the Mail-Reply-To header."
2663 (message-position-on-field "Mail-Reply-To" "Subject"))
2665 (defun message-goto-mail-copies-to ()
2666 "Move point to the Mail-Copies-To header. If the header is newly created,
2667 a string \"never\" is inserted in default."
2669 (unless (message-position-on-field "Mail-Copies-To" "Subject")
2673 (defun message-goto-newsgroups ()
2674 "Move point to the Newsgroups header."
2676 (message-position-on-field "Newsgroups"))
2678 (defun message-goto-distribution ()
2679 "Move point to the Distribution header."
2681 (message-position-on-field "Distribution"))
2683 (defun message-goto-followup-to ()
2684 "Move point to the Followup-To header."
2686 (message-position-on-field "Followup-To" "Newsgroups"))
2688 (defun message-goto-mail-followup-to ()
2689 "Move point to the Mail-Followup-To header. If the header is newly created
2690 and To field contains only one address, the address is inserted in default."
2692 (unless (message-position-on-field "Mail-Followup-To" "Subject")
2693 (let ((start (point))
2696 (message-narrow-to-headers)
2697 (setq addresses (split-string (mail-strip-quoted-names
2698 (or (std11-fetch-field "to") ""))
2700 (when (eq 1 (length addresses))
2702 (insert (car addresses))
2703 (goto-char start))))))
2705 (defun message-goto-keywords ()
2706 "Move point to the Keywords header."
2708 (message-position-on-field "Keywords" "Subject"))
2710 (defun message-goto-summary ()
2711 "Move point to the Summary header."
2713 (message-position-on-field "Summary" "Subject"))
2715 (defun message-goto-body (&optional interactivep)
2716 "Move point to the beginning of the message body."
2717 (interactive (list t))
2718 (when (and interactivep
2719 (looking-at "[ \t]*\n"))
2721 (goto-char (point-min))
2722 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
2723 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
2725 (defun message-goto-eoh ()
2726 "Move point to the end of the headers."
2731 (defun message-goto-signature ()
2732 "Move point to the beginning of the message signature.
2733 If there is no signature in the article, go to the end and
2736 (goto-char (point-min))
2737 (if (re-search-forward message-signature-separator nil t)
2739 (goto-char (point-max))
2742 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc)
2743 "Insert a reasonable MFT header in a post to an unsubscribed list.
2744 When making original posts to a mailing list you are not subscribed to,
2745 you have to type in a MFT header by hand. The contents, usually, are
2746 the addresses of the list and your own address. This function inserts
2747 such a header automatically. It fetches the contents of the To: header
2748 in the current mail buffer, and appends the current `user-mail-address'.
2750 If the optional argument INCLUDE-CC is non-nil, the addresses in the
2751 Cc: header are also put into the MFT."
2754 (message-remove-header "Mail-Followup-To")
2755 (let* ((cc (and include-cc (message-fetch-field "Cc")))
2757 (concat (message-fetch-field "To") "," cc)
2758 (message-fetch-field "To"))))
2759 (message-goto-mail-followup-to)
2760 (insert (concat tos ", " user-mail-address))))
2764 (defun message-insert-to (&optional force)
2765 "Insert a To header that points to the author of the article being replied to.
2766 If the original author requested not to be sent mail, the function signals
2768 With the prefix argument FORCE, insert the header anyway."
2770 (let ((co (message-fetch-reply-field "mail-copies-to")))
2771 (when (and (null force)
2773 (or (equal (downcase co) "never")
2774 (equal (downcase co) "nobody")))
2775 (error "The user has requested not to have copies sent via mail")))
2776 (message-carefully-insert-headers
2778 (or (message-fetch-reply-field "mail-reply-to")
2779 (message-fetch-reply-field "reply-to")
2780 (message-fetch-reply-field "from")
2783 (defun message-insert-wide-reply ()
2784 "Insert To and Cc headers as if you were doing a wide reply."
2786 (let ((headers (message-with-reply-buffer
2787 (message-get-reply-headers t))))
2788 (message-carefully-insert-headers headers)))
2790 (defun message-carefully-insert-headers (headers)
2791 (dolist (header headers)
2792 (let ((header-name (symbol-name (car header))))
2793 (when (and (message-position-on-field header-name)
2794 (mail-fetch-field header-name)
2795 (not (string-match "\\` *\\'"
2796 (mail-fetch-field header-name))))
2798 (insert (cdr header)))))
2800 (defun message-widen-reply ()
2801 "Widen the reply to include maximum recipients."
2804 (and message-reply-buffer
2805 (buffer-name message-reply-buffer)
2807 (set-buffer message-reply-buffer)
2808 (message-get-reply-headers t)))))
2811 (message-narrow-to-headers)
2812 (dolist (elem follow-to)
2813 (message-remove-header (symbol-name (car elem)))
2814 (goto-char (point-min))
2815 (insert (symbol-name (car elem)) ": "
2816 (cdr elem) "\n"))))))
2818 (defun message-insert-newsgroups ()
2819 "Insert the Newsgroups header from the article being replied to."
2821 (when (and (message-position-on-field "Newsgroups")
2822 (mail-fetch-field "newsgroups")
2823 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
2825 (insert (or (message-fetch-reply-field "newsgroups") "")))
2829 ;;; Various commands
2831 (defun message-delete-not-region (beg end)
2832 "Delete everything in the body of the current message outside of the region."
2837 ;; snarf citation prefix, if appropriate
2838 (unless (eq (point) (progn (beginning-of-line) (point)))
2839 (when (looking-at message-cite-prefix-regexp)
2840 (setq citeprefix (match-string 0))))
2842 (delete-region (point) (if (not (message-goto-signature))
2848 (delete-region beg (progn (message-goto-body)
2852 (insert citeprefix))))
2853 (when (message-goto-signature)
2856 (defun message-kill-to-signature ()
2857 "Deletes all text up to the signature."
2859 (let ((point (point)))
2860 (message-goto-signature)
2863 (kill-region point (point))
2867 (defun message-newline-and-reformat (&optional arg not-break)
2868 "Insert four newlines, and then reformat if inside quoted text.
2869 Prefix arg means justify as well."
2870 (interactive (list (if current-prefix-arg 'full)))
2871 (let (quoted point beg end leading-space bolp)
2872 (setq point (point))
2875 (setq bolp (= beg point))
2876 ;; Find first line of the paragraph.
2878 (while (and (not (eobp))
2879 (not (looking-at message-cite-prefix-regexp))
2880 (looking-at paragraph-start))
2883 (when (looking-at message-cite-prefix-regexp)
2884 (setq quoted (match-string 0))
2885 (goto-char (match-end 0))
2886 (looking-at "[ \t]*")
2887 (setq leading-space (match-string 0)))
2891 (< (- point beg) (length quoted)))
2892 ;; break inside the cite prefix.
2898 (while (and (not (eobp))
2899 (not (looking-at paragraph-separate))
2900 (looking-at message-cite-prefix-regexp)
2901 (equal quoted (match-string 0)))
2902 (goto-char (match-end 0))
2903 (looking-at "[ \t]*")
2904 (if (> (length leading-space) (length (match-string 0)))
2905 (setq leading-space (match-string 0)))
2909 (while (and (if (bobp) nil (forward-line -1) t)
2910 (not (looking-at paragraph-start))
2911 (looking-at message-cite-prefix-regexp)
2912 (equal quoted (match-string 0)))
2914 (goto-char (match-end 0))
2915 (looking-at "[ \t]*")
2916 (if (> (length leading-space) (length (match-string 0)))
2917 (setq leading-space (match-string 0)))))
2918 (while (and (not (eobp))
2919 (not (looking-at paragraph-separate))
2920 (not (looking-at message-cite-prefix-regexp)))
2924 (while (and (if (bobp) nil (forward-line -1) t)
2925 (not (looking-at paragraph-start))
2926 (not (looking-at message-cite-prefix-regexp)))
2927 (setq beg (point))))
2930 (narrow-to-region beg end)
2937 (setq point (point))
2938 ;; (newline 2) doesn't mark both newline's as hard, so call
2939 ;; newline twice. -jas
2942 (delete-region (point) (re-search-forward "[ \t]*"))
2943 (when (and quoted (not bolp))
2944 (insert quoted leading-space)))
2946 (let* ((adaptive-fill-regexp
2947 (regexp-quote (concat quoted leading-space)))
2948 (adaptive-fill-first-line-regexp
2949 adaptive-fill-regexp ))
2950 (fill-paragraph arg))
2951 (fill-paragraph arg))
2952 (if point (goto-char point)))))
2954 (defun message-fill-paragraph (&optional arg)
2955 "Like `fill-paragraph'."
2956 (interactive (list (if current-prefix-arg 'full)))
2957 (if (and (boundp 'filladapt-mode) filladapt-mode)
2959 (message-newline-and-reformat arg t)
2962 ;; Is it better to use `mail-header-end'?
2963 (defun message-point-in-header-p ()
2964 "Return t if point is in the header."
2967 (goto-char (point-min))
2968 (not (re-search-forward
2969 (concat "^" (regexp-quote mail-header-separator) "\n")
2972 (defun message-do-auto-fill ()
2973 "Like `do-auto-fill', but don't fill in message header."
2974 (unless (message-point-in-header-p)
2977 (defun message-insert-signature (&optional force)
2978 "Insert a signature. See documentation for variable `message-signature'."
2979 (interactive (list 0))
2982 ((and (null message-signature)
2985 (goto-char (point-max))
2986 (not (re-search-backward message-signature-separator nil t))))
2987 ((and (null message-signature)
2990 ((message-functionp message-signature)
2991 (funcall message-signature))
2992 ((listp message-signature)
2993 (eval message-signature))
2994 (t message-signature)))
2996 (cond ((stringp signature)
2998 ((and (eq t signature)
2999 message-signature-file
3000 (file-exists-p message-signature-file))
3003 (goto-char (point-max))
3004 ;; Insert the signature.
3007 (when message-signature-insert-empty-line
3009 (insert "\n" message-signature-separator-for-insertion)
3012 (if (eq signature t)
3013 (insert-file-contents message-signature-file)
3015 (goto-char (point-max))
3016 (or (bolp) (insert "\n")))))
3018 (defun message-insert-importance-high ()
3019 "Insert header to mark message as important."
3022 (message-remove-header "Importance")
3024 (insert "Importance: high\n")))
3026 (defun message-insert-importance-low ()
3027 "Insert header to mark message as unimportant."
3030 (message-remove-header "Importance")
3032 (insert "Importance: low\n")))
3034 (defun message-insert-or-toggle-importance ()
3035 "Insert a \"Importance: high\" header, or cycle through the header values.
3036 The three allowed values according to RFC 1327 are `high', `normal'
3040 (let ((valid '("high" "normal" "low"))
3043 (when (setq cur (message-fetch-field "Importance"))
3044 (message-remove-header "Importance")
3045 (setq new (cond ((string= cur "high")
3047 ((string= cur "low")
3052 (insert (format "Importance: %s\n" new)))))
3054 (defun message-insert-disposition-notification-to ()
3055 "Request a disposition notification (return receipt) to this message.
3056 Note that this should not be used in newsgroups."
3059 (message-remove-header "Disposition-Notification-To")
3061 (insert (format "Disposition-Notification-To: %s\n"
3062 (or (message-fetch-field "From") (message-make-from))))))
3064 (defun message-elide-region (b e)
3065 "Elide the text in the region.
3066 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3070 (insert message-elide-ellipsis))
3072 (defvar message-caesar-translation-table nil)
3074 (defun message-caesar-region (b e &optional n)
3075 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3078 (min (point) (or (mark t) (point)))
3079 (max (point) (or (mark t) (point)))
3080 (when current-prefix-arg
3081 (prefix-numeric-value current-prefix-arg))))
3083 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
3084 (unless (or (zerop n) ; no action needed for a rot of 0
3085 (= b e)) ; no region to rotate
3086 ;; We build the table, if necessary.
3087 (when (or (not message-caesar-translation-table)
3088 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
3089 (setq message-caesar-translation-table
3090 (message-make-caesar-translation-table n)))
3091 (translate-region b e message-caesar-translation-table)))
3093 (defun message-make-caesar-translation-table (n)
3094 "Create a rot table with offset N."
3096 (table (make-string 256 0)))
3097 (while (< (incf i) 256)
3100 (substring table 0 ?A)
3101 (substring table (+ ?A n) (+ ?A n (- 26 n)))
3102 (substring table ?A (+ ?A n))
3103 (substring table (+ ?A 26) ?a)
3104 (substring table (+ ?a n) (+ ?a n (- 26 n)))
3105 (substring table ?a (+ ?a n))
3106 (substring table (+ ?a 26) 255))))
3108 (defun message-caesar-buffer-body (&optional rotnum)
3109 "Caesar rotate all letters in the current buffer by 13 places.
3110 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3111 With prefix arg, specifies the number of places to rotate each letter forward.
3112 Mail and USENET news headers are not rotated."
3113 (interactive (if current-prefix-arg
3114 (list (prefix-numeric-value current-prefix-arg))
3118 (when (message-goto-body)
3119 (narrow-to-region (point) (point-max)))
3120 (message-caesar-region (point-min) (point-max) rotnum))))
3122 (defun message-pipe-buffer-body (program)
3123 "Pipe the message body in the current buffer through PROGRAM."
3126 (when (message-goto-body)
3127 (narrow-to-region (point) (point-max)))
3128 (shell-command-on-region
3129 (point-min) (point-max) program nil t))))
3131 (defun message-rename-buffer (&optional enter-string)
3132 "Rename the *message* buffer to \"*message* RECIPIENT\".
3133 If the function is run with a prefix, it will ask for a new buffer
3134 name, rather than giving an automatic name."
3135 (interactive "Pbuffer name: ")
3138 (goto-char (point-min))
3139 (narrow-to-region (point)
3140 (search-forward mail-header-separator nil 'end))
3142 (if (message-news-p) (message-fetch-field "Newsgroups")
3143 (message-fetch-field "To"))
3146 (if (string-match "," mail-to)
3147 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
3149 (name-default (concat "*message* " mail-trimmed-to))
3150 (name (if enter-string
3151 (read-string "New buffer name: " name-default)
3153 (rename-buffer name t)))))
3155 (defun message-fill-yanked-message (&optional justifyp)
3156 "Fill the paragraphs of a message yanked into this one.
3157 Numeric argument means justify as well."
3160 (goto-char (point-min))
3161 (search-forward (concat "\n" mail-header-separator "\n") nil t)
3162 (let ((fill-prefix message-yank-prefix))
3163 (fill-individual-paragraphs (point) (point-max) justifyp))))
3165 (defun message-indent-citation ()
3166 "Modify text just inserted from a message to be cited.
3167 The inserted text should be the region.
3168 When this function returns, the region is again around the modified text.
3170 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3171 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3172 (let ((start (point)))
3173 ;; Remove unwanted headers.
3174 (when message-ignored-cited-headers
3179 (if (search-forward "\n\n" nil t)
3182 (message-remove-header message-ignored-cited-headers t)
3183 (when (= (point-min) (point-max))
3184 (setq all-removed t))
3185 (goto-char (point-max)))
3189 ;; Delete blank lines at the start of the buffer.
3190 (while (and (point-min)
3193 (message-delete-line))
3194 ;; Delete blank lines at the end of the buffer.
3195 (goto-char (point-max))
3198 (while (and (zerop (forward-line -1))
3200 (message-delete-line))
3201 ;; Do the indentation.
3202 (if (null message-yank-prefix)
3203 (indent-rigidly start (mark t) message-indentation-spaces)
3206 (while (< (point) (mark t))
3207 (if (or (looking-at ">") (looking-at "^$"))
3208 (insert message-yank-cited-prefix)
3209 (insert message-yank-prefix))
3213 (defun message-list-references (refs-list &rest refs-strs)
3214 "Add `Message-ID's which appear in REFS-STRS but not in REFS-LIST,
3216 (let (refs ref id saved-id)
3217 (when (and refs-list
3218 (integerp message-list-references-add-position))
3219 (let ((pos message-list-references-add-position))
3220 (while (and refs-list
3222 (push (pop refs-list) saved-id)
3223 (setq pos (1- pos)))))
3225 (when (setq refs (pop refs-strs))
3226 (setq refs (std11-parse-msg-ids (std11-lexical-analyze refs)))
3228 (when (eq (car (setq ref (pop refs))) 'msg-id)
3229 (setq id (concat "<" (mapconcat 'cdr (cdr ref) "") ">"))
3230 (or (member id refs-list)
3231 (member id saved-id)
3232 (push id refs-list))))))
3234 (push (pop saved-id) refs-list))
3237 (defun message-yank-original (&optional arg)
3238 "Insert the message being replied to, if any.
3239 Puts point before the text and mark after.
3240 Normally indents each nonblank line ARG spaces (default 3). However,
3241 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3243 This function uses `message-cite-function' to do the actual citing.
3245 Just \\[universal-argument] as argument means don't indent, insert no
3246 prefix, and don't delete any headers.
3248 In addition, if `message-yank-add-new-references' is non-nil and this
3249 command is called interactively, new IDs from the yanked article will
3250 be added to the \"References\" field."
3252 (let ((modified (buffer-modified-p)))
3253 (when (let ((buffer (message-eval-parameter message-reply-buffer)))
3255 message-cite-function
3258 (delete-windows-on buffer t)
3259 ; The mark will be set at the end of the article.
3260 (insert-buffer buffer))))
3261 ;; Add new IDs to the References field.
3262 (when (and message-yank-add-new-references
3264 (let ((start (point))
3270 (setq refs (message-list-references
3272 (or (message-make-references)
3274 (message-narrow-to-headers)
3275 (message-fetch-field "References")
3277 (narrow-to-region start end)
3278 (std11-narrow-to-header)
3279 (unless (equal (setq newrefs
3280 (message-list-references
3281 (copy-sequence refs)
3282 (unless (eq message-yank-add-new-references
3284 (or (message-fetch-field "References")
3285 (message-fetch-field "In-Reply-To")))
3286 (message-fetch-field "Message-ID")))
3288 ;; If the References field has been changed, we make it
3289 ;; visible in the header.
3290 (mail-header-set-message-id message-reply-headers nil)
3291 (mail-header-set-references message-reply-headers nil)
3293 (message-narrow-to-headers)
3294 (if (let ((case-fold-search t))
3295 (re-search-forward "^References:\\([\t ]+.+\n\\)+"
3298 (goto-char (point-max)))
3300 (list (or (assq 'References message-header-format-alist)
3301 '(References . message-fill-references)))
3302 (list (cons 'References (mapconcat 'identity
3303 (nreverse newrefs) " "))))
3304 (backward-delete-char 1))))))
3306 (if (and message-suspend-font-lock-when-citing
3307 (boundp 'font-lock-mode)
3308 (symbol-value 'font-lock-mode))
3313 (funcall message-cite-function))
3315 (funcall message-cite-function)))
3316 (message-exchange-point-and-mark)
3320 (setq message-checksum (message-checksum))))))
3322 (defun message-yank-buffer (buffer)
3323 "Insert BUFFER into the current buffer and quote it."
3324 (interactive "bYank buffer: ")
3325 (let ((message-reply-buffer buffer))
3326 (save-window-excursion
3327 (message-yank-original))))
3329 (defun message-buffers ()
3330 "Return a list of active message buffers."
3333 (dolist (buffer (buffer-list t))
3335 (when (and (eq major-mode 'message-mode)
3336 (null message-sent-message-via))
3337 (push (buffer-name buffer) buffers))))
3338 (nreverse buffers)))
3340 (defun message-cite-original-without-signature ()
3341 "Cite function in the standard Message manner."
3342 (let ((start (point))
3345 (when message-indent-citation-function
3346 (if (listp message-indent-citation-function)
3347 message-indent-citation-function
3348 (list message-indent-citation-function))))
3349 (message-reply-headers (or message-reply-headers
3350 (make-mail-header))))
3351 (mail-header-set-from message-reply-headers
3355 (if (search-forward "\n\n" nil t)
3358 (or (message-fetch-field "from")
3363 (when (re-search-backward message-signature-separator start t)
3364 ;; Also peel off any blank lines before the signature.
3366 (while (looking-at "^[ \t]*$")
3369 (delete-region (point) end)
3370 (unless (search-backward "\n\n" start t)
3371 ;; Insert a blank line if it is peeled off.
3375 (funcall (pop functions)))
3376 (when message-citation-line-function
3379 (funcall message-citation-line-function))))
3381 (eval-when-compile (defvar mail-citation-hook)) ;Compiler directive
3382 (defun message-cite-original ()
3383 "Cite function in the standard Message manner."
3384 (if (and (boundp 'mail-citation-hook)
3386 (run-hooks 'mail-citation-hook)
3387 (let ((start (point))
3390 (when message-indent-citation-function
3391 (if (listp message-indent-citation-function)
3392 message-indent-citation-function
3393 (list message-indent-citation-function))))
3394 (message-reply-headers (or message-reply-headers
3395 (make-mail-header))))
3396 (mail-header-set-from message-reply-headers
3400 (if (search-forward "\n\n" nil t)
3403 (or (message-fetch-field "from")
3407 (funcall (pop functions)))
3408 (when message-citation-line-function
3411 (funcall message-citation-line-function)))))
3413 (defun message-insert-citation-line ()
3414 "Insert a simple citation line."
3415 (when message-reply-headers
3416 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
3418 (defun message-position-on-field (header &rest afters)
3419 (let ((case-fold-search t))
3422 (goto-char (point-min))
3425 (concat "^" (regexp-quote mail-header-separator) "$"))
3426 (match-beginning 0)))
3427 (goto-char (point-min))
3428 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
3430 (re-search-forward "^[^ \t]" nil 'move)
3432 (skip-chars-backward "\n")
3435 (not (re-search-forward
3436 (concat "^" (regexp-quote (car afters)) ":")
3440 (re-search-forward "^[^ \t]" nil 'move)
3441 (beginning-of-line))
3442 (insert header ": \n")
3446 (defun message-remove-signature ()
3447 "Remove the signature from the text between point and mark.
3448 The text will also be indented the normal way."
3450 (let ((start (point))
3452 (if (not (re-search-forward message-signature-separator (mark t) t))
3453 ;; No signature here, so we just indent the cited text.
3454 (message-indent-citation)
3455 ;; Find the last non-empty line.
3457 (while (looking-at "[ \t]*$")
3460 (setq mark (set-marker (make-marker) (point)))
3462 (message-indent-citation)
3463 ;; Enable undoing the deletion.
3465 (delete-region mark (mark t))
3466 (set-marker mark nil)))))
3471 ;;; Sending messages
3474 ;; Avoid byte-compile warning.
3475 (defvar message-encoding-buffer nil)
3476 (defvar message-edit-buffer nil)
3477 (defvar message-mime-mode nil)
3479 (defun message-send-and-exit (&optional arg)
3480 "Send message like `message-send', then, if no errors, exit from mail buffer."
3482 (let ((buf (current-buffer))
3483 (actions message-exit-actions)
3484 (frame (selected-frame))
3485 (org-frame message-original-frame))
3486 (when (and (message-send arg)
3488 (if message-kill-buffer-on-exit
3491 (when (eq buf (current-buffer))
3492 (message-bury buf)))
3493 (message-do-actions actions)
3494 (message-delete-frame frame org-frame)
3497 (defun message-dont-send ()
3498 "Don't send the message you have been editing.
3499 Instead, just auto-save the buffer and then bury it."
3501 (set-buffer-modified-p t)
3503 (let ((actions message-postpone-actions)
3504 (frame (selected-frame))
3505 (org-frame message-original-frame))
3506 (message-bury (current-buffer))
3507 (message-do-actions actions)
3508 (message-delete-frame frame org-frame)))
3510 (defun message-kill-buffer ()
3511 "Kill the current buffer."
3513 (when (or (not (buffer-modified-p))
3514 (eq t message-kill-buffer-query-function)
3515 (funcall message-kill-buffer-query-function
3516 "The buffer modified; kill anyway? "))
3517 (let ((actions message-kill-actions)
3518 (draft-article message-draft-article)
3519 (auto-save-file-name buffer-auto-save-file-name)
3520 (file-name buffer-file-name)
3521 (modified (buffer-modified-p))
3522 (frame (selected-frame))
3523 (org-frame message-original-frame))
3524 (setq buffer-file-name nil)
3525 (kill-buffer (current-buffer))
3526 (when (and message-kill-buffer-and-remove-file
3527 (or (and auto-save-file-name
3528 (file-exists-p auto-save-file-name))
3530 (file-exists-p file-name)))
3531 (yes-or-no-p (format "Remove the backup file%s? "
3532 (if modified " too" ""))))
3534 (delete-file auto-save-file-name))
3535 (let ((message-draft-article draft-article))
3536 (message-disassociate-draft)))
3537 (message-do-actions actions)
3538 (message-delete-frame frame org-frame)))
3541 (defun message-mimic-kill-buffer ()
3542 "Kill the current buffer with query. This is an imitation for
3543 `kill-buffer', but it will delete a message frame."
3545 (let ((bufname (read-buffer (format "Kill buffer: (default %s) "
3547 message-kill-buffer-and-remove-file)
3548 (when (or (not bufname)
3549 (string-equal bufname "")
3550 (string-equal bufname (buffer-name)))
3551 (message-kill-buffer))))
3553 (defun message-delete-frame (frame org-frame)
3554 "Delete frame for editing message."
3555 (when (and (or (static-if (featurep 'xemacs)
3556 (device-on-window-system-p)
3558 (>= emacs-major-version 20))
3559 (or (and (eq message-delete-frame-on-exit t)
3560 (select-frame frame)
3561 (or (eq frame org-frame)
3563 (y-or-n-p "Delete this frame?")
3565 (and (eq message-delete-frame-on-exit 'ask)
3566 (select-frame frame)
3568 (y-or-n-p "Delete this frame?")
3570 (delete-frame frame)))
3572 (defun message-bury (buffer)
3573 "Bury this mail BUFFER."
3574 (let ((newbuf (other-buffer buffer)))
3575 (bury-buffer buffer)
3576 (if (and (fboundp 'frame-parameters)
3577 (cdr (assq 'dedicated (frame-parameters)))
3578 (not (null (delq (selected-frame) (visible-frame-list)))))
3579 (delete-frame (selected-frame))
3580 (switch-to-buffer newbuf))))
3582 (defun message-send (&optional arg)
3583 "Send the message in the current buffer.
3584 If `message-interactive' is non-nil, wait for success indication or
3585 error messages, and inform user.
3586 Otherwise any failure is reported in a message back to the user from
3588 The usage of ARG is defined by the instance that called Message.
3589 It should typically alter the sending method in some way or other."
3592 (when (or (buffer-modified-p)
3593 (message-check-element 'unchanged)
3594 (y-or-n-p "No changes in the buffer; really send? "))
3595 ;; Make it possible to undo the coming changes.
3597 (let ((inhibit-read-only t))
3598 (put-text-property (point-min) (point-max) 'read-only nil))
3599 (run-hooks 'message-send-hook)
3600 (message-fix-before-sending)
3601 (message message-sending-message)
3602 (let ((message-encoding-buffer
3603 (message-generate-new-buffer-clone-locals " message encoding"))
3604 (message-edit-buffer (current-buffer))
3605 (message-mime-mode mime-edit-mode-flag)
3606 (alist message-send-method-alist)
3608 elem sent dont-barf-on-no-method
3609 (message-options message-options))
3612 (message-options-set-recipient)
3614 (set-buffer message-encoding-buffer)
3616 ;; ;; Avoid copying text props (except hard newlines).
3617 ;; T-gnus change: copy all text props from the editing buffer
3618 ;; into the encoding buffer.
3619 (insert-buffer-substring message-edit-buffer)
3620 (funcall message-encode-function)
3622 (setq elem (pop alist)))
3623 (when (funcall (cadr elem))
3625 (or (not (memq (car elem)
3626 message-sent-message-via))
3627 (not (message-fetch-field "supersedes"))
3628 (if (or (message-gnksa-enable-p 'multiple-copies)
3629 (not (eq (car elem) 'news)))
3632 "Already sent message via %s; resend? "
3634 (error "Denied posting -- multiple copies")))
3635 (setq success (funcall (caddr elem) arg)))
3641 (let ((fcc (message-fetch-field "Fcc"))
3642 (gcc (message-fetch-field "Gcc")))
3645 (eq message-allow-no-recipients 'always)
3646 (and (not (eq message-allow-no-recipients 'never))
3647 (setq dont-barf-on-no-method
3649 (format "No receiver, perform %s anyway? "
3650 (cond ((and fcc gcc) "Fcc and Gcc")
3653 (error "No methods specified to send by"))
3654 (when (or dont-barf-on-no-method
3658 (run-hooks 'message-sent-hook))
3659 (message "Sending...done")
3660 ;; Mark the buffer as unmodified and delete auto-save.
3661 (set-buffer-modified-p nil)
3662 (delete-auto-save-file-if-necessary t)
3663 (message-disassociate-draft)
3664 ;; Delete other mail buffers and stuff.
3665 (message-do-send-housekeeping)
3666 (message-do-actions message-send-actions)
3669 (kill-buffer message-encoding-buffer)))))
3671 (defun message-send-via-mail (arg)
3672 "Send the current message via mail."
3673 (message-send-mail arg))
3675 (defun message-send-via-news (arg)
3676 "Send the current message via news."
3677 (message-send-news arg))
3679 (defmacro message-check (type &rest forms)
3680 "Eval FORMS if TYPE is to be checked."
3681 `(or (message-check-element ,type)
3685 (put 'message-check 'lisp-indent-function 1)
3686 (put 'message-check 'edebug-form-spec '(form body))
3688 ;; Advise the function `invisible-region'.
3689 (let (current-load-list)
3691 `(defadvice invisible-region (around add-mime-edit-invisible (start end)
3693 "Advised by T-gnus Message.
3694 Add the text property `mime-edit-invisible' to an invisible text when
3695 the buffer's major mode is `message-mode'. The added property will be
3696 used to distinguish whether the invisible text is a MIME part or not."
3697 ,(if (featurep 'xemacs)
3698 '(if (eq ?\n (char-after start))
3699 (setq start (1+ start)))
3700 '(if (eq ?\n (char-after (1- end)))
3701 (setq end (1- end))))
3702 (setq ad-return-value
3703 (if (eq 'message-mode major-mode)
3704 (add-text-properties start end
3705 '(invisible t mime-edit-invisible t))
3706 (put-text-property start end 'invisible t))))))
3708 (defun message-text-with-property (prop)
3709 "Return a list of all points where the text has PROP."
3711 (point (point-min)))
3713 (while (< point (point-max))
3714 (when (get-text-property point prop)
3715 (push point points))
3719 (defun message-fix-before-sending ()
3720 "Do various things to make the message nice before sending it."
3721 ;; Make sure there's a newline at the end of the message.
3723 (goto-char (point-max))
3726 ;; Delete all invisible text except for the mime parts which might
3727 ;; be inserted by the MIME-Edit.
3728 (message-check 'invisible-text
3731 mime-from mime-to hidden-start)
3732 (while (setq from (text-property-any to (point-max) 'invisible t))
3733 (setq to (or (text-property-not-all from (point-max) 'invisible t)
3736 (while (setq mime-from (text-property-any mime-to to
3737 'mime-edit-invisible t))
3738 (when (> mime-from mime-to)
3739 (setq hidden-start (or hidden-start mime-to))
3740 (add-text-properties mime-to mime-from
3741 '(invisible nil face highlight
3742 font-lock-face highlight)))
3743 (setq mime-to (or (text-property-not-all mime-from to
3744 'mime-edit-invisible t)
3746 (when (< mime-to to)
3747 (setq hidden-start (or hidden-start mime-to))
3748 (add-text-properties mime-to to
3749 '(invisible nil face highlight
3750 font-lock-face highlight))))
3752 (goto-char hidden-start)
3753 (set-window-start (selected-window) (gnus-point-at-bol))
3754 (unless (yes-or-no-p
3755 "Invisible text found and made visible; continue posting? ")
3756 (error "Invisible text found and made visible")))))
3757 (message-check 'illegible-text
3758 (let ((mm-7bit-chars "\x20-\x7f\r\n\t\x7\x8\xb\xc\x1f\x1b")
3761 (skip-chars-forward mm-7bit-chars)
3763 (when (let ((char (char-after)))
3764 (or (< (mm-char-int char) 128)
3765 (and (mm-multibyte-p)
3766 (memq (char-charset char)
3767 '(eight-bit-control eight-bit-graphic
3769 (add-text-properties (point) (1+ (point))
3770 '(font-lock-face highlight face highlight))
3773 (skip-chars-forward mm-7bit-chars))
3776 (gnus-multiple-choice
3777 "Illegible text found. Continue posting?"
3778 '((?d "Remove and continue posting")
3779 (?r "Replace with dots and continue posting")
3780 (?i "Ignore and continue posting")
3781 (?e "Continue editing"))))
3783 (error "Illegible text found"))
3785 (skip-chars-forward mm-7bit-chars)
3787 (when (let ((char (char-after)))
3788 (or (< (mm-char-int char) 128)
3789 (and (mm-multibyte-p)
3790 (memq (char-charset char)
3791 '(eight-bit-control eight-bit-graphic
3794 (remove-text-properties (point) (1+ (point))
3795 '(font-lock-face highlight face highlight))
3797 (when (eq choice ?r)
3800 (skip-chars-forward mm-7bit-chars))))))
3802 (defun message-add-action (action &rest types)
3803 "Add ACTION to be performed when doing an exit of type TYPES."
3805 (add-to-list (intern (format "message-%s-actions" (pop types)))
3808 (defun message-delete-action (action &rest types)
3809 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
3812 (set (setq var (intern (format "message-%s-actions" (pop types))))
3813 (delq action (symbol-value var))))))
3815 (defun message-do-actions (actions)
3816 "Perform all actions in ACTIONS."
3817 ;; Now perform actions on successful sending.
3821 ;; A simple function.
3822 ((message-functionp (car actions))
3823 (funcall (car actions)))
3824 ;; Something to be evaled.
3826 (eval (car actions)))))
3829 (defsubst message-maybe-split-and-send-mail ()
3830 "Split a message if necessary, and send it via mail.
3831 Returns nil if sending succeeded, returns any string if sending failed.
3832 This sub function is for exclusive use of `message-send-mail'."
3833 (let ((mime-edit-split-ignored-field-regexp
3834 mime-edit-split-ignored-field-regexp)
3835 (case-fold-search t)
3837 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
3838 (setq mime-edit-split-ignored-field-regexp
3839 (concat (substring mime-edit-split-ignored-field-regexp
3840 0 (match-beginning 0))
3841 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
3842 "_so_don't_rape_it!"
3843 (substring mime-edit-split-ignored-field-regexp
3847 (catch 'message-sending-mail-failure
3848 (mime-edit-maybe-split-and-send
3853 (std11-narrow-to-header mail-header-separator)
3854 (goto-char (point-min))
3855 (when (re-search-forward "^Message-ID:" nil t)
3856 (delete-region (match-end 0) (std11-field-end))
3857 (insert " " (message-make-message-id))))
3859 (funcall (or message-send-mail-real-function
3860 message-send-mail-function))
3862 (throw 'message-sending-mail-failure err))))))
3866 (funcall (or message-send-mail-real-function
3867 message-send-mail-function))
3871 (if (eq 'error (car failure))
3873 (prin1-to-string failure)))))
3875 (defun message-send-mail-partially ()
3876 "Send mail as message/partial."
3877 ;; replace the header delimiter with a blank line
3878 (goto-char (point-min))
3880 (concat "^" (regexp-quote mail-header-separator) "\n"))
3881 (replace-match "\n")
3882 (run-hooks 'message-send-mail-hook)
3883 (let ((p (goto-char (point-min)))
3884 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
3885 (curbuf (current-buffer))
3886 (id (message-make-message-id)) (n 1)
3887 plist total header required-mail-headers)
3889 (if (< (point-max) (+ p message-send-mail-partially-limit))
3890 (goto-char (point-max))
3891 (goto-char (+ p message-send-mail-partially-limit))
3893 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
3896 (setq total (length plist))
3897 (push (point-max) plist)
3898 (setq plist (nreverse plist))
3901 (setq p (pop plist))
3904 (copy-to-buffer tembuf p (car plist))
3906 (goto-char (point-min))
3909 (goto-char (point-min))
3910 (narrow-to-region (point) (point))
3913 (setq header (buffer-substring (point-min) (point)))
3914 (goto-char (point-min))
3915 (narrow-to-region (point) (point))
3917 (message-remove-header "Mime-Version")
3918 (message-remove-header "Content-Type")
3919 (message-remove-header "Content-Transfer-Encoding")
3920 (message-remove-header "Message-ID")
3921 (message-remove-header "Lines")
3922 (goto-char (point-max))
3923 (insert "Mime-Version: 1.0\n")
3924 (setq header (buffer-string)))
3925 (goto-char (point-max))
3926 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
3929 (let ((mail-header-separator ""))
3930 (when (memq 'Message-ID message-required-mail-headers)
3931 (insert "Message-ID: " (message-make-message-id) "\n"))
3932 (when (memq 'Lines message-required-mail-headers)
3933 (insert "Lines: " (message-make-lines) "\n"))
3934 (message-goto-subject)
3936 (insert (format " (%d/%d)" n total))
3938 (mm-with-unibyte-current-buffer
3939 (funcall (or message-send-mail-real-function
3940 message-send-mail-function))))
3942 (setq p (pop plist))
3944 (kill-buffer tembuf))))
3946 (defun message-send-mail (&optional arg)
3947 (require 'mail-utils)
3948 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
3949 (case-fold-search nil)
3950 (news (message-news-p))
3951 (message-this-is-mail t)
3952 (headers message-required-mail-headers)
3955 (message-narrow-to-headers)
3956 ;; Generate the Mail-Followup-To header if the header is not there...
3957 (if (and (message-subscribed-p)
3958 (not (mail-fetch-field "mail-followup-to")))
3961 (cons "Mail-Followup-To" (message-make-mail-followup-to))
3962 message-required-mail-headers))
3963 ;; otherwise, delete the MFT header if the field is empty
3964 (when (equal "" (mail-fetch-field "mail-followup-to"))
3965 (message-remove-header "^Mail-Followup-To:")))
3966 ;; Insert some headers.
3967 (let ((message-deletable-headers
3968 (if news nil message-deletable-headers)))
3969 (message-generate-headers headers))
3970 ;; Let the user do all of the above.
3971 (run-hooks 'message-header-hook))
3972 (if (not (message-check-mail-syntax))
3980 ;; ;; Avoid copying text props (except hard newlines).
3981 ;; T-gnus change: copy all text props from the editing buffer
3982 ;; into the encoding buffer.
3983 (insert-buffer-substring message-encoding-buffer)
3984 ;; Remove some headers.
3986 (message-narrow-to-headers)
3987 ;; We Semi-gnus people have no use for it.
3988 ;; ;; We (re)generate the Lines header.
3989 ;; (when (memq 'Lines message-required-mail-headers)
3990 ;; (message-generate-headers '(Lines)))
3991 (message-remove-header message-ignored-mail-headers t))
3992 (goto-char (point-max))
3993 ;; require one newline at the end.
3994 (or (= (preceding-char) ?\n)
3996 (message-cleanup-headers)
3999 (message-narrow-to-headers)
4001 (or (message-fetch-field "cc")
4002 (message-fetch-field "bcc")
4003 (message-fetch-field "to"))
4004 (let ((ct (mime-read-Content-Type)))
4006 (and (eq 'text (cdr (assq 'type ct)))
4007 (eq 'plain (cdr (assq 'subtype ct))))))))
4008 (message-insert-courtesy-copy))
4009 (setq failure (message-maybe-split-and-send-mail)))
4010 (kill-buffer tembuf))
4011 (set-buffer message-edit-buffer)
4014 (message "Couldn't send message via mail: %s" failure)
4016 (push 'mail message-sent-message-via)))))
4018 (defun message-send-mail-with-sendmail ()
4019 "Send off the prepared buffer with sendmail."
4020 (let ((errbuf (if message-interactive
4021 (message-generate-new-buffer-clone-locals
4024 resend-to-addresses delimline)
4027 (let ((case-fold-search t))
4029 (message-narrow-to-headers)
4030 (setq resend-to-addresses (message-fetch-field "resent-to")))
4031 ;; Change header-delimiter to be what sendmail expects.
4032 (goto-char (point-min))
4034 (concat "^" (regexp-quote mail-header-separator) "\n"))
4035 (replace-match "\n")
4037 (setq delimline (point-marker))
4038 (run-hooks 'message-send-mail-hook)
4039 ;; Insert an extra newline if we need it to work around
4040 ;; Sun's bug that swallows newlines.
4041 (goto-char (1+ delimline))
4042 (when (eval message-mailer-swallows-blank-line)
4044 (when message-interactive
4048 (let* ((default-directory "/")
4049 (cpr (as-binary-process
4051 'call-process-region
4053 (list (point-min) (point-max)
4054 (if (boundp 'sendmail-program)
4056 "/usr/lib/sendmail")
4057 nil errbuf nil "-oi")
4058 ;; Always specify who from,
4059 ;; since some systems have broken sendmails.
4060 ;; But some systems are more broken with -f, so
4061 ;; we'll let users override this.
4062 (if (null message-sendmail-f-is-evil)
4063 (list "-f" (message-sendmail-envelope-from)))
4064 ;; These mean "report errors by mail"
4065 ;; and "deliver in background".
4066 (if (null message-interactive) '("-oem" "-odb"))
4067 ;; Get the addresses from the message
4068 ;; unless this is a resend.
4069 ;; We must not do that for a resend
4070 ;; because we would find the original addresses.
4071 ;; For a resend, include the specific addresses.
4072 (if resend-to-addresses
4073 (list resend-to-addresses)
4075 (unless (or (null cpr) (zerop cpr))
4076 (error "Sending...failed with exit value %d" cpr)))
4077 (when message-interactive
4080 (goto-char (point-min))
4081 (while (re-search-forward "\n\n* *" nil t)
4082 (replace-match "; "))
4083 (if (not (zerop (buffer-size)))
4084 (error "Sending...failed to %s"
4085 (buffer-string))))))
4086 (when (bufferp errbuf)
4087 (kill-buffer errbuf)))))
4089 (defun message-send-mail-with-qmail ()
4090 "Pass the prepared message buffer to qmail-inject.
4091 Refer to the documentation for the variable `message-send-mail-function'
4092 to find out how to use this."
4093 ;; replace the header delimiter with a blank line
4094 (goto-char (point-min))
4096 (concat "^" (regexp-quote mail-header-separator) "\n"))
4097 (replace-match "\n")
4099 (run-hooks 'message-send-mail-hook)
4104 'call-process-region 1 (point-max) message-qmail-inject-program
4106 ;; qmail-inject's default behaviour is to look for addresses on the
4107 ;; command line; if there're none, it scans the headers.
4108 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4110 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4111 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4112 ;; message from stdin.
4114 ;; qmail also has the advantage of not having been raped by
4115 ;; various vendors, so we don't have to allow for that, either --
4116 ;; compare this with message-send-mail-with-sendmail and weep
4117 ;; for sendmail's lost innocence.
4119 ;; all this is way cool coz it lets us keep the arguments entirely
4120 ;; free for -inject-arguments -- a big win for the user and for us
4121 ;; since we don't have to play that double-guessing game and the user
4122 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4123 (if (functionp message-qmail-inject-args)
4124 (funcall message-qmail-inject-args)
4125 message-qmail-inject-args)))
4126 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4127 ;; we have to look at the retval instead
4129 (100 (error "qmail-inject reported permanent failure"))
4130 (111 (error "qmail-inject reported transient failure"))
4131 ;; should never happen
4132 (t (error "qmail-inject reported unknown failure"))))
4134 (defun message-send-mail-with-mh ()
4135 "Send the prepared message buffer with mh."
4136 (let ((mh-previous-window-config nil)
4137 (name (mh-new-draft-name)))
4138 (setq buffer-file-name name)
4139 ;; MH wants to generate these headers itself.
4140 (when message-mh-deletable-headers
4141 (let ((headers message-mh-deletable-headers))
4143 (goto-char (point-min))
4144 (and (re-search-forward
4145 (concat "^" (symbol-name (car headers)) ": *") nil t)
4146 (message-delete-line))
4148 (run-hooks 'message-send-mail-hook)
4149 ;; Pass it on to mh.
4152 (defun message-send-mail-with-smtp ()
4153 "Send off the prepared buffer with SMTP."
4154 (require 'smtp) ; XXX
4155 (let ((case-fold-search t)
4158 (message-narrow-to-headers)
4160 ;; XXX: Should be replaced by better one.
4161 (smtp-deduce-address-list (current-buffer)
4162 (point-min) (point-max)))
4163 ;; Remove BCC lines.
4164 (message-remove-header "bcc"))
4165 ;; replace the header delimiter with a blank line.
4166 (goto-char (point-min))
4168 (concat "^" (regexp-quote mail-header-separator) "\n"))
4169 (replace-match "\n")
4171 (run-hooks 'message-send-mail-hook)
4173 (smtp-send-buffer user-mail-address recipients (current-buffer))
4174 (error "Sending failed; no recipients"))))
4176 (defsubst message-maybe-split-and-send-news (method)
4177 "Split a message if necessary, and send it via news.
4178 Returns nil if sending succeeded, returns t if sending failed.
4179 This sub function is for exclusive use of `message-send-news'."
4180 (let ((mime-edit-split-ignored-field-regexp
4181 mime-edit-split-ignored-field-regexp)
4182 (case-fold-search t))
4183 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
4184 (setq mime-edit-split-ignored-field-regexp
4185 (concat (substring mime-edit-split-ignored-field-regexp
4186 0 (match-beginning 0))
4187 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
4188 "_so_don't_rape_it!"
4189 (substring mime-edit-split-ignored-field-regexp
4192 (catch 'message-sending-news-failure
4193 (mime-edit-maybe-split-and-send
4198 (std11-narrow-to-header mail-header-separator)
4199 (goto-char (point-min))
4200 (when (re-search-forward "^Message-ID:" nil t)
4201 (delete-region (match-end 0) (std11-field-end))
4202 (insert " " (message-make-message-id))))
4203 (unless (funcall message-send-news-function method)
4204 (throw 'message-sending-news-failure t)))))
4206 (not (funcall message-send-news-function method)))))
4208 (defun message-smtpmail-send-it ()
4209 "Send the prepared message buffer with `smtpmail-send-it'.
4210 This only differs from `smtpmail-send-it' that this command evaluates
4211 `message-send-mail-hook' just before sending a message. It is useful
4212 if your ISP requires the POP-before-SMTP authentication. See the
4213 documentation for the function `mail-source-touch-pop'."
4214 (run-hooks 'message-send-mail-hook)
4217 (defun message-canlock-generate ()
4218 "Return a string that is non-trival to guess.
4219 Do not use this for anything important, it is cryptographically weak."
4220 (let (sha1-maximum-internal-length)
4221 (sha1 (concat (message-unique-id)
4222 (format "%x%x%x" (random) (random t) (random))
4223 (prin1-to-string (recent-keys))
4224 (prin1-to-string (garbage-collect))))))
4226 (defun message-canlock-password ()
4227 "The password used by message for cancel locks.
4228 This is the value of `canlock-password', if that option is non-nil.
4229 Otherwise, generate and save a value for `canlock-password' first."
4230 (unless canlock-password
4231 (customize-save-variable 'canlock-password (message-canlock-generate))
4232 (setq canlock-password-for-verify canlock-password))
4235 (defun message-insert-canlock ()
4236 (when message-insert-canlock
4237 (message-canlock-password)
4238 (canlock-insert-header)))
4240 (defun message-send-news (&optional arg)
4241 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4242 (case-fold-search nil)
4243 (method (if (message-functionp message-post-method)
4244 (funcall message-post-method arg)
4245 message-post-method))
4246 (newsgroups-field (save-restriction
4247 (message-narrow-to-headers-or-head)
4248 (message-fetch-field "Newsgroups")))
4249 (followup-field (save-restriction
4250 (message-narrow-to-headers-or-head)
4251 (message-fetch-field "Followup-To")))
4252 ;; BUG: We really need to get the charset for each name in the
4253 ;; Newsgroups and Followup-To lines to allow crossposting
4254 ;; between group namess with incompatible character sets.
4255 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4256 (group-field-charset
4257 (gnus-group-name-charset method newsgroups-field))
4258 (followup-field-charset
4259 (gnus-group-name-charset method (or followup-field "")))
4260 (mime-field-encoding-method-alist
4261 (append (when group-field-charset
4262 (list (cons "Newsgroups" group-field-charset)))
4263 (when followup-field-charset
4264 (list (cons "Followup-To" followup-field-charset)))
4265 mime-field-encoding-method-alist))
4266 (message-syntax-checks
4268 (listp message-syntax-checks))
4269 (cons '(existing-newsgroups . disabled)
4270 message-syntax-checks)
4271 message-syntax-checks))
4272 (message-this-is-news t)
4275 (message-narrow-to-headers)
4276 ;; Insert some headers.
4277 (message-generate-headers message-required-news-headers)
4278 (message-insert-canlock)
4279 ;; Let the user do all of the above.
4280 (run-hooks 'message-header-hook))
4281 ;; Note: This check will be disabled by the ".*" default value for
4282 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4283 (when (and group-field-charset
4284 (listp message-syntax-checks))
4285 (setq message-syntax-checks
4286 (cons '(valid-newsgroups . disabled)
4287 message-syntax-checks)))
4288 (message-cleanup-headers)
4289 (if (not (let ((message-post-method method))
4290 (message-check-news-syntax)))
4295 (buffer-disable-undo)
4297 (insert-buffer-substring message-encoding-buffer)
4298 ;; Remove some headers.
4300 (message-narrow-to-headers)
4301 ;; We Semi-gnus people have no use for it.
4302 ;; ;; We (re)generate the Lines header.
4303 ;; (when (memq 'Lines message-required-mail-headers)
4304 ;; (message-generate-headers '(Lines)))
4305 ;; Remove some headers.
4306 (message-remove-header message-ignored-news-headers t))
4307 (goto-char (point-max))
4308 ;; require one newline at the end.
4309 (or (= (preceding-char) ?\n)
4311 (setq result (message-maybe-split-and-send-news method)))
4312 (kill-buffer tembuf))
4313 (set-buffer message-edit-buffer)
4316 (message "Couldn't send message via news: %s"
4317 (nnheader-get-report (car method)))
4319 (push 'news message-sent-message-via)))))
4321 ;; 1997-09-29 by MORIOKA Tomohiko
4322 (defun message-send-news-with-gnus (method)
4323 (let ((case-fold-search t))
4324 ;; Remove the delimiter.
4325 (goto-char (point-min))
4327 (concat "^" (regexp-quote mail-header-separator) "\n"))
4328 (replace-match "\n")
4330 (run-hooks 'message-send-news-hook)
4331 (gnus-open-server method)
4332 (message "Sending news via %s..." (gnus-server-string method))
4333 (gnus-request-post method)
4337 ;;; Header generation & syntax checking.
4340 (defun message-check-element (type)
4341 "Return non-nil if this TYPE is not to be checked."
4342 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
4344 (let ((able (assq type message-syntax-checks)))
4346 (eq (cdr able) 'disabled)))))
4348 (defun message-check-news-syntax ()
4349 "Check the syntax of the message."
4354 ;; We narrow to the headers and check them first.
4357 (message-narrow-to-headers)
4358 (message-check-news-header-syntax)))
4361 (set-buffer message-edit-buffer)
4362 (message-check-news-body-syntax))))))
4364 (defun message-check-news-header-syntax ()
4366 ;; Check Newsgroups header.
4367 (message-check 'newsgroups
4368 (let ((group (message-fetch-field "newsgroups")))
4371 (not (string-match "\\`[ \t]*\\'" group)))
4374 "The newsgroups field is empty or missing. Posting is denied.")))))
4375 ;; Check the Subject header.
4376 (message-check 'subject
4377 (let* ((case-fold-search t)
4378 (subject (message-fetch-field "subject")))
4381 (not (string-match "\\`[ \t]*\\'" subject)))
4384 "The subject field is empty or missing. Posting is denied.")))))
4385 ;; Check for commands in Subject.
4386 (message-check 'subject-cmsg
4387 (if (string-match "^cmsg " (message-fetch-field "subject"))
4389 "The control code \"cmsg\" is in the subject. Really post? ")
4391 ;; Check long header lines.
4392 (message-check 'long-header-lines
4393 (let ((start (point))
4397 (while (and (not found)
4398 (re-search-forward "^\\([^ \t:]+\\): " nil t))
4399 (if (> (- (point) (match-beginning 0)) 998)
4401 length (- (point) (match-beginning 0)))
4402 (setq header (match-string-no-properties 1)))
4403 (setq start (match-beginning 0))
4406 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
4409 ;; Check for multiple identical headers.
4410 (message-check 'multiple-headers
4412 (while (and (not found)
4413 (re-search-forward "^[^ \t:]+: " nil t))
4415 (or (re-search-forward
4420 (match-beginning 0) (- (match-end 0) 2))))
4425 (y-or-n-p (format "Multiple %s headers. Really post? " found))
4427 ;; Check for Version and Sendsys.
4428 (message-check 'sendsys
4429 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
4431 (format "The article contains a %s command. Really post? "
4432 (buffer-substring (match-beginning 0)
4433 (1- (match-end 0)))))
4435 ;; See whether we can shorten Followup-To.
4436 (message-check 'shorten-followup-to
4437 (let ((newsgroups (message-fetch-field "newsgroups"))
4438 (followup-to (message-fetch-field "followup-to"))
4440 (when (and newsgroups
4441 (string-match "," newsgroups)
4446 (setq to (completing-read
4447 "Followups to (default: no Followup-To header) "
4448 (mapcar (lambda (g) (list g))
4450 (message-tokenize-header
4452 (goto-char (point-min))
4453 (insert "Followup-To: " to "\n"))
4455 ;; Check "Shoot me".
4456 (message-check 'shoot
4457 (if (re-search-forward
4458 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
4459 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
4461 ;; Check for Approved.
4462 (message-check 'approved
4463 (if (re-search-forward "^Approved:" nil t)
4464 (y-or-n-p "The article contains an Approved header. Really post? ")
4466 ;; Check the Message-ID header.
4467 (message-check 'message-id
4468 (let* ((case-fold-search t)
4469 (message-id (message-fetch-field "message-id" t)))
4470 (or (not message-id)
4471 ;; Is there an @ in the ID?
4472 (and (string-match "@" message-id)
4473 ;; Is there a dot in the ID?
4474 (string-match "@[^.]*\\." message-id)
4475 ;; Does the ID end with a dot?
4476 (not (string-match "\\.>" message-id)))
4478 (format "The Message-ID looks strange: \"%s\". Really post? "
4480 ;; Check the Newsgroups & Followup-To headers.
4481 (message-check 'existing-newsgroups
4482 (let* ((case-fold-search t)
4483 (newsgroups (message-fetch-field "newsgroups"))
4484 (followup-to (message-fetch-field "followup-to"))
4485 (groups (message-tokenize-header
4487 (concat newsgroups "," followup-to)
4489 (post-method (if (message-functionp message-post-method)
4490 (funcall message-post-method)
4491 message-post-method))
4492 ;; KLUDGE to handle nnvirtual groups. Doing this right
4493 ;; would probably involve a new nnoo function.
4494 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
4495 (method (if (and (consp post-method)
4496 (eq (car post-method) 'nnvirtual)
4497 gnus-message-group-art)
4498 (let ((group (car (nnvirtual-find-group-art
4499 (car gnus-message-group-art)
4500 (cdr gnus-message-group-art)))))
4501 (gnus-find-method-for-group group))
4505 (gnus-group-name-decode
4506 (gnus-group-real-name n)
4507 (gnus-group-name-charset method n)))
4508 (gnus-groups-from-server method)))
4511 (when (and (not (equal (car groups) "poster"))
4512 (not (member (car groups) known-groups))
4513 (not (member (car groups) errors)))
4514 (push (car groups) errors))
4517 ;; Gnus is not running.
4518 ((or (not (and (boundp 'gnus-active-hashtb)
4519 gnus-active-hashtb))
4520 (not (boundp 'gnus-read-active-file)))
4522 ;; We don't have all the group names.
4523 ((and (or (not gnus-read-active-file)
4524 (eq gnus-read-active-file 'some))
4528 "Really post to %s possibly unknown group%s: %s? "
4529 (if (= (length errors) 1) "this" "these")
4530 (if (= (length errors) 1) "" "s")
4531 (mapconcat 'identity errors ", "))))
4532 ;; There were no errors.
4535 ;; There are unknown groups.
4539 "Really post to %s unknown group%s: %s? "
4540 (if (= (length errors) 1) "this" "these")
4541 (if (= (length errors) 1) "" "s")
4542 (mapconcat 'identity errors ", ")))))))
4543 ;; Check continuation headers.
4544 (message-check 'continuation-headers
4545 (goto-char (point-min))
4546 (let ((do-posting t))
4547 (while (re-search-forward "^[^ \t\n][^:\n]*$" nil t)
4548 (if (y-or-n-p "Fix continuation lines? ")
4550 (goto-char (match-beginning 0))
4552 (unless (y-or-n-p "Send anyway? ")
4553 (setq do-posting nil))))
4555 ;; Check the Newsgroups & Followup-To headers for syntax errors.
4556 (message-check 'valid-newsgroups
4557 (let ((case-fold-search t)
4558 (headers '("Newsgroups" "Followup-To"))
4560 (while (and headers (not error))
4561 (when (setq header (mail-fetch-field (car headers)))
4565 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
4570 (not (string-match "\\.\\'\\|\\.\\." g)))
4571 (message-tokenize-header header ","))))
4578 (format "The %s header looks odd: \"%s\". Really post? "
4579 (car headers) header)))))
4580 (message-check 'repeated-newsgroups
4581 (let ((case-fold-search t)
4582 (headers '("Newsgroups" "Followup-To"))
4583 header error groups group)
4586 (when (setq header (mail-fetch-field (pop headers)))
4587 (setq groups (message-tokenize-header header ","))
4588 (while (setq group (pop groups))
4589 (when (member group groups)
4595 (format "Group %s is repeated in headers. Really post? " error)))))
4596 ;; Check the From header.
4597 (message-check 'from
4598 (let* ((case-fold-search t)
4599 (from (message-fetch-field "from"))
4603 (message "There is no From line. Posting is denied.")
4605 ((or (not (string-match
4607 (setq ad (nth 1 (mail-extract-address-components
4608 from))))) ;larsi@ifi
4609 (string-match "\\.\\." ad) ;larsi@ifi..uio
4610 (string-match "@\\." ad) ;larsi@.ifi.uio
4611 (string-match "\\.$" ad) ;larsi@ifi.uio.
4612 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4613 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
4615 "Denied posting -- the From looks strange: \"%s\"." from)
4617 ((let ((addresses (rfc822-addresses from)))
4618 (while (and addresses
4619 (not (eq (string-to-char (car addresses)) ?\()))
4620 (setq addresses (cdr addresses)))
4623 "Denied posting -- bad From address: \"%s\"." from)
4626 ;; Check the Reply-To header.
4627 (message-check 'reply-to
4628 (let* ((case-fold-search t)
4629 (reply-to (message-fetch-field "reply-to"))
4634 ((string-match "," reply-to)
4636 (format "Multiple Reply-To addresses: \"%s\". Really post? "
4638 ((or (not (string-match
4640 (setq ad (nth 1 (mail-extract-address-components
4641 reply-to))))) ;larsi@ifi
4642 (string-match "\\.\\." ad) ;larsi@ifi..uio
4643 (string-match "@\\." ad) ;larsi@.ifi.uio
4644 (string-match "\\.$" ad) ;larsi@ifi.uio.
4645 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4646 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
4649 "The Reply-To looks strange: \"%s\". Really post? "
4653 (defun message-check-news-body-syntax ()
4655 ;; Check for long lines.
4656 (message-check 'long-lines
4657 (goto-char (point-min))
4659 (concat "^" (regexp-quote mail-header-separator) "$"))
4663 mime-edit-tag-regexp)
4666 (< (- (point) p) 80)))
4667 (zerop (forward-line 1))))
4671 "You have lines longer than 79 characters. Really post? ")))
4672 ;; Check whether the article is empty.
4673 (message-check 'empty
4674 (goto-char (point-min))
4676 (concat "^" (regexp-quote mail-header-separator) "$"))
4679 (goto-char (point-max))
4680 (re-search-backward message-signature-separator nil t)
4682 (or (re-search-backward "[^ \n\t]" b t)
4683 (if (message-gnksa-enable-p 'empty-article)
4684 (y-or-n-p "Empty article. Really post? ")
4685 (message "Denied posting -- Empty article.")
4687 ;; Check for control characters.
4688 (message-check 'control-chars
4689 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
4691 "The article contains control characters. Really post? ")
4693 ;; Check 8bit characters.
4694 (message-check '8bit
4695 (message-check-8bit))
4696 ;; Check excessive size.
4697 (message-check 'size
4698 (if (> (buffer-size) 60000)
4700 (format "The article is %d octets long. Really post? "
4703 ;; Check whether any new text has been added.
4704 (message-check 'new-text
4706 (not message-checksum)
4707 (not (eq (message-checksum) message-checksum))
4708 (if (message-gnksa-enable-p 'quoted-text-only)
4710 "It looks like no new text has been added. Really post? ")
4711 (message "Denied posting -- no new text has been added.")
4713 ;; Check the length of the signature.
4714 (message-check 'signature
4715 (goto-char (point-max))
4716 (if (> (count-lines (point) (point-max)) 5)
4719 "Your .sig is %d lines; it should be max 4. Really post? "
4720 (1- (count-lines (point) (point-max)))))
4722 ;; Ensure that text follows last quoted portion.
4723 (message-check 'quoting-style
4724 (goto-char (point-max))
4725 (let ((no-problem t))
4726 (when (search-backward-regexp "^>[^\n]*\n" nil t)
4727 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
4730 (if (message-gnksa-enable-p 'quoted-text-only)
4731 (y-or-n-p "Your text should follow quoted text. Really post? ")
4733 (goto-char (point-min))
4735 (concat "^" (regexp-quote mail-header-separator) "$"))
4736 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
4737 (y-or-n-p "Your text should follow quoted text. Really post? ")
4738 (message "Denied posting -- only quoted text.")
4741 (defun message-check-mail-syntax ()
4742 "Check the syntax of the message."
4747 ;; We narrow to the headers and check them first.
4750 (message-narrow-to-headers)
4751 (message-check-mail-header-syntax)))
4754 (set-buffer message-edit-buffer)
4755 (message-check-mail-body-syntax))))))
4757 (defun message-check-mail-header-syntax ()
4760 (defun message-check-mail-body-syntax ()
4762 ;; Check 8bit characters.
4763 (message-check '8bit
4764 (message-check-8bit)
4767 (defun message-check-8bit ()
4768 "Check the article contains 8bit characters."
4770 (set-buffer message-encoding-buffer)
4771 (message-narrow-to-headers)
4772 (let* ((case-fold-search t)
4773 (field-value (message-fetch-field "content-transfer-encoding")))
4774 (if (and field-value
4775 (member (downcase field-value) message-8bit-encoding-list))
4778 (set-buffer (get-buffer-create " message syntax"))
4780 (goto-char (point-min))
4781 (set-buffer-multibyte nil)
4782 (insert-buffer-substring message-encoding-buffer)
4783 (goto-char (point-min))
4784 (if (re-search-forward "[^\x00-\x7f]" nil t)
4786 "The article contains 8bit characters. Really post? ")
4789 (defun message-checksum ()
4790 "Return a \"checksum\" for the current buffer."
4793 (goto-char (point-min))
4795 (concat "^" (regexp-quote mail-header-separator) "$"))
4797 (when (not (looking-at "[ \t\n]"))
4798 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
4803 (defun message-do-fcc ()
4804 "Process Fcc headers in the current buffer."
4805 (let ((case-fold-search t)
4806 (coding-system-for-write 'raw-text)
4807 (output-coding-system 'raw-text)
4809 (mml-externalize-attachments message-fcc-externalize-attachments))
4812 (message-narrow-to-headers)
4813 (setq file (message-fetch-field "fcc" t)))
4815 (set-buffer (get-buffer-create " *message temp*"))
4817 (insert-buffer-substring message-encoding-buffer)
4819 (message-narrow-to-headers)
4820 (while (setq file (message-fetch-field "fcc"))
4822 (message-remove-header "fcc" nil t)))
4823 (goto-char (point-min))
4824 (when (re-search-forward
4825 (concat "^" (regexp-quote mail-header-separator) "$")
4827 (replace-match "" t t))
4828 ;; Process FCC operations.
4830 (setq file (pop list))
4831 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
4832 ;; Pipe the article to the program in question.
4833 (call-process-region (point-min) (point-max) shell-file-name
4834 nil nil nil shell-command-switch
4835 (match-string 1 file))
4836 ;; Save the article.
4837 (setq file (expand-file-name file))
4838 (unless (file-exists-p (file-name-directory file))
4839 (make-directory (file-name-directory file) t))
4840 (if (and message-fcc-handler-function
4841 (not (eq message-fcc-handler-function 'rmail-output)))
4842 (funcall message-fcc-handler-function file)
4843 (if (and (file-readable-p file) (mail-file-babyl-p file))
4844 (rmail-output file 1 nil t)
4845 (let ((mail-use-rfc822 t))
4846 (rmail-output file 1 t t))))))
4847 (kill-buffer (current-buffer))))))
4849 (defun message-output (filename)
4850 "Append this article to Unix/babyl mail file FILENAME."
4851 (if (and (file-readable-p filename)
4852 (mail-file-babyl-p filename))
4853 (gnus-output-to-rmail filename t)
4854 (gnus-output-to-mail filename t)))
4856 (defun message-cleanup-headers ()
4857 "Do various automatic cleanups of the headers."
4858 ;; Remove empty lines in the header.
4860 (message-narrow-to-headers)
4861 ;; Remove blank lines.
4862 (while (re-search-forward "^[ \t]*\n" nil t)
4863 (replace-match "" t t))
4865 ;; Correct Newsgroups and Followup-To headers: Change sequence of
4866 ;; spaces to comma and eliminate spaces around commas. Eliminate
4867 ;; embedded line breaks.
4868 (goto-char (point-min))
4869 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
4873 (if (re-search-forward "^[^ \t]" nil t)
4877 (goto-char (point-min))
4878 (while (re-search-forward "\n[ \t]+" nil t)
4879 (replace-match " " t t)) ;No line breaks (too confusing)
4880 (goto-char (point-min))
4881 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
4882 (replace-match "," t t))
4883 (goto-char (point-min))
4884 ;; Remove trailing commas.
4885 (when (re-search-forward ",+$" nil t)
4886 (replace-match "" t t))))))
4888 (defun message-make-date (&optional now)
4889 "Make a valid data header.
4890 If NOW, use that time instead."
4891 (let* ((now (or now (current-time)))
4892 (zone (nth 8 (decode-time now)))
4896 (setq zone (- zone)))
4898 ;; The day name of the %a spec is locale-specific. Pfff.
4899 (format "%s, " (capitalize (car (rassoc (nth 6 (decode-time now))
4900 parse-time-weekdays))))
4901 (format-time-string "%d" now)
4902 ;; The month name of the %b spec is locale-specific. Pfff.
4904 (capitalize (car (rassoc (nth 4 (decode-time now))
4905 parse-time-months))))
4906 (format-time-string "%Y %H:%M:%S " now)
4907 ;; We do all of this because XEmacs doesn't have the %z spec.
4908 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
4910 (defun message-make-followup-subject (subject)
4911 "Make a followup Subject."
4913 ((and (eq message-use-subject-re 'guess)
4914 (string-match message-subject-encoded-re-regexp subject))
4916 (message-use-subject-re
4917 (concat "Re: " (message-strip-subject-re subject)))
4920 (defun message-make-message-id ()
4921 "Make a unique Message-ID."
4922 (concat "<" (message-unique-id)
4923 (let ((psubject (save-excursion (message-fetch-field "subject")))
4925 (save-excursion (message-fetch-field "supersedes"))))
4927 (and message-reply-headers
4928 (mail-header-references message-reply-headers)
4929 (mail-header-subject message-reply-headers)
4932 (message-strip-subject-re
4933 (mail-header-subject message-reply-headers))
4934 (message-strip-subject-re psubject))))
4936 (string-match "_-_@" psupersedes)))
4938 "@" (message-make-fqdn) ">"))
4940 (defvar message-unique-id-char nil)
4942 ;; If you ever change this function, make sure the new version
4943 ;; cannot generate IDs that the old version could.
4944 ;; You might for example insert a "." somewhere (not next to another dot
4945 ;; or string boundary), or modify the "fsf" string.
4946 (defun message-unique-id ()
4947 ;; Don't use microseconds from (current-time), they may be unsupported.
4948 ;; Instead we use this randomly inited counter.
4949 (setq message-unique-id-char
4950 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
4951 ;; (current-time) returns 16-bit ints,
4952 ;; and 2^16*25 just fits into 4 digits i base 36.
4954 (let ((tm (current-time)))
4956 (if (memq system-type '(ms-dos emx vax-vms))
4957 (let ((user (downcase (user-login-name))))
4958 (while (string-match "[^a-z0-9_]" user)
4959 (aset user (match-beginning 0) ?_))
4961 (message-number-base36 (user-uid) -1))
4962 (message-number-base36 (+ (car tm)
4963 (lsh (% message-unique-id-char 25) 16)) 4)
4964 (message-number-base36 (+ (nth 1 tm)
4965 (lsh (/ message-unique-id-char 25) 16)) 4)
4966 ;; Append the newsreader name, because while the generated
4967 ;; ID is unique to this newsreader, other newsreaders might
4968 ;; otherwise generate the same ID via another algorithm.
4971 (defun message-number-base36 (num len)
4976 (concat (message-number-base36 (/ num 36) (1- len))
4977 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
4980 (defun message-make-organization ()
4981 "Make an Organization header."
4982 (let* ((organization
4983 (when message-user-organization
4984 (if (message-functionp message-user-organization)
4985 (funcall message-user-organization)
4986 message-user-organization))))
4988 (message-set-work-buffer)
4989 (cond ((stringp organization)
4990 (insert organization))
4991 ((and (eq t organization)
4992 message-user-organization-file
4993 (file-exists-p message-user-organization-file))
4994 (insert-file-contents message-user-organization-file)))
4995 (goto-char (point-min))
4996 (while (re-search-forward "[\t\n]+" nil t)
4997 (replace-match "" t t))
4998 (unless (zerop (buffer-size))
5001 (defun message-make-lines ()
5002 "Count the number of lines and return numeric string."
5007 (int-to-string (count-lines (point) (point-max))))))
5009 (defun message-make-references ()
5010 "Return the References header for this message."
5011 (when message-reply-headers
5012 (let ((message-id (mail-header-message-id message-reply-headers))
5013 (references (mail-header-references message-reply-headers))
5015 (if (or references message-id)
5016 (concat (or references "") (and references " ")
5020 (defun message-make-in-reply-to ()
5021 "Return the In-Reply-To header for this message."
5022 (when message-reply-headers
5023 (let ((from (mail-header-from message-reply-headers))
5024 (date (mail-header-date message-reply-headers))
5025 (msg-id (mail-header-message-id message-reply-headers)))
5029 (let ((pair (std11-extract-address-components from)))
5031 (or (car pair) (cadr pair))
5033 (if (or (not date) (string= date ""))
5034 "(unknown date)" date)
5037 (defun message-make-distribution ()
5038 "Make a Distribution header."
5039 (let ((orig-distribution (message-fetch-reply-field "distribution")))
5040 (cond ((message-functionp message-distribution-function)
5041 (funcall message-distribution-function))
5042 (t orig-distribution))))
5044 (defun message-make-expires ()
5045 "Return an Expires header based on `message-expires'."
5046 (let ((current (current-time))
5047 (future (* 1.0 message-expires 60 60 24)))
5048 ;; Add the future to current.
5049 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
5050 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
5051 (message-make-date current)))
5053 (defun message-make-path ()
5055 (let ((login-name (user-login-name)))
5056 (cond ((null message-user-path)
5057 (concat (system-name) "!" login-name))
5058 ((stringp message-user-path)
5059 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
5060 (concat message-user-path "!" login-name))
5063 (defun message-make-from ()
5064 "Make a From header."
5065 (let* ((style message-from-style)
5066 (login (message-make-address))
5068 (or (and (boundp 'user-full-name)
5071 (when (string= fullname "&")
5072 (setq fullname (user-login-name)))
5074 (message-set-work-buffer)
5077 (equal fullname ""))
5079 ((or (eq style 'angles)
5080 (and (not (eq style 'parens))
5081 ;; Use angles if no quoting is needed, or if parens would
5082 ;; need quoting too.
5083 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
5084 (let ((tmp (concat fullname nil)))
5085 (while (string-match "([^()]*)" tmp)
5086 (aset tmp (match-beginning 0) ?-)
5087 (aset tmp (1- (match-end 0)) ?-))
5088 (string-match "[\\()]" tmp)))))
5090 (insert " <" login ">"))
5091 (t ; 'parens or default
5093 (let ((fullname-start (point)))
5095 (goto-char fullname-start)
5096 ;; RFC 822 says \ and nonmatching parentheses
5097 ;; must be escaped in comments.
5098 ;; Escape every instance of ()\ ...
5099 (while (re-search-forward "[()\\]" nil 1)
5100 (replace-match "\\\\\\&" t))
5101 ;; ... then undo escaping of matching parentheses,
5102 ;; including matching nested parentheses.
5103 (goto-char fullname-start)
5104 (while (re-search-forward
5105 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
5107 (replace-match "\\1(\\3)" t)
5108 (goto-char fullname-start)))
5112 (defun message-make-sender ()
5113 "Return the \"real\" user address.
5114 This function tries to ignore all user modifications, and
5115 give as trustworthy answer as possible."
5116 (concat (user-login-name) "@" (system-name)))
5118 (defun message-make-address ()
5119 "Make the address of the user."
5120 (or (message-user-mail-address)
5121 (concat (user-login-name) "@" (message-make-domain))))
5123 (defun message-user-mail-address ()
5124 "Return the pertinent part of `user-mail-address'."
5125 (when (and user-mail-address
5126 (string-match "@.*\\." user-mail-address))
5127 (if (string-match " " user-mail-address)
5128 (nth 1 (std11-extract-address-components user-mail-address))
5129 user-mail-address)))
5131 (defun message-sendmail-envelope-from ()
5132 "Return the envelope from."
5133 (cond ((eq message-sendmail-envelope-from 'header)
5134 (nth 1 (mail-extract-address-components
5135 (message-fetch-field "from"))))
5136 ((stringp message-sendmail-envelope-from)
5137 message-sendmail-envelope-from)
5139 (message-make-address))))
5141 (defun message-make-fqdn ()
5142 "Return user's fully qualified domain name."
5143 (let* ((system-name (system-name))
5144 (user-mail (message-user-mail-address))
5147 (string-match "@\\(.*\\)\\'" user-mail))
5148 (match-string 1 user-mail))))
5150 ((and message-user-fqdn
5151 (stringp message-user-fqdn)
5152 (string-match message-valid-fqdn-regexp message-user-fqdn)
5153 (not (string-match message-bogus-system-names message-user-fqdn)))
5155 ;; `message-user-fqdn' seems to be valid
5156 ((and (string-match message-valid-fqdn-regexp system-name)
5157 (not (string-match message-bogus-system-names system-name)))
5158 ;; `system-name' returned the right result.
5160 ;; Try `mail-host-address'.
5161 ((and (boundp 'mail-host-address)
5162 (stringp mail-host-address)
5163 (string-match message-valid-fqdn-regexp mail-host-address)
5164 (not (string-match message-bogus-system-names mail-host-address)))
5166 ;; We try `user-mail-address' as a backup.
5168 (stringp user-domain)
5169 (string-match message-valid-fqdn-regexp user-domain)
5170 (not (string-match message-bogus-system-names user-domain)))
5172 ;; Default to this bogus thing.
5174 (concat system-name ".i-did-not-set--mail-host-address--so-tickle-me")))))
5176 (defun message-make-host-name ()
5177 "Return the name of the host."
5178 (let ((fqdn (message-make-fqdn)))
5179 (string-match "^[^.]+\\." fqdn)
5180 (substring fqdn 0 (1- (match-end 0)))))
5182 (defun message-make-domain ()
5183 "Return the domain name."
5184 (or mail-host-address
5185 (message-make-fqdn)))
5187 (defun message-to-list-only ()
5188 "Send a message to the list only.
5189 Remove all addresses but the list address from To and Cc headers."
5191 (let ((listaddr (message-make-mail-followup-to t)))
5194 (message-remove-header "to")
5195 (message-remove-header "cc")
5196 (message-position-on-field "To" "X-Draft-From")
5197 (insert listaddr)))))
5199 (defun message-make-mail-followup-to (&optional only-show-subscribed)
5200 "Return the Mail-Followup-To header.
5201 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5202 subscribed address (and not the additional To and Cc header contents)."
5203 (let* ((case-fold-search t)
5204 (to (message-fetch-field "To"))
5205 (cc (message-fetch-field "cc"))
5206 (msg-recipients (concat to (and to cc ", ") cc))
5208 (mapcar 'mail-strip-quoted-names
5209 (message-tokenize-header msg-recipients)))
5211 (if message-subscribed-address-file
5212 (let (begin end item re)
5215 (insert-file-contents message-subscribed-address-file)
5217 (setq begin (point))
5220 (if (bolp) (setq end (1- end)))
5221 (setq item (regexp-quote (buffer-substring begin end)))
5222 (if re (setq re (concat re "\\|" item))
5223 (setq re (concat "\\`\\(" item))))
5224 (and re (list (concat re "\\)\\'"))))))))
5225 (mft-regexps (apply 'append message-subscribed-regexps
5226 (mapcar 'regexp-quote
5227 message-subscribed-addresses)
5230 message-subscribed-address-functions))))
5232 (let ((subscribed-lists nil)
5234 (loop for recipient in recipients
5235 when (loop for regexp in mft-regexps
5236 when (string-match regexp recipient) return t)
5239 (if only-show-subscribed
5241 msg-recipients))))))
5243 ;; Dummy to avoid byte-compile warning.
5244 (defvar mule-version)
5245 (defvar emacs-beta-version)
5246 (defvar xemacs-codename)
5247 (defvar gnus-inviolable-extended-version)
5249 (defun message-make-user-agent ()
5250 "Return user-agent info if the value `message-user-agent' is non-nil. If the
5251 \"User-Agent\" field has already exist, it's value will be added in the return
5253 (when message-user-agent
5255 (goto-char (point-min))
5256 (let ((case-fold-search t)
5257 user-agent start p end)
5258 (if (re-search-forward
5259 (concat "^User-Agent:[\t ]*\\("
5260 (regexp-quote gnus-product-name)
5261 "/[0-9.]+\\([ \t\r\n]*([^)]+)\\)*\\)?[\t ]*")
5264 (setq start (match-beginning 0)
5266 end (std11-field-end)
5267 user-agent (buffer-substring-no-properties p end))
5268 (delete-region start (1+ end))
5269 (concat message-user-agent " " user-agent))
5270 message-user-agent)))))
5272 (defun message-generate-headers (headers)
5273 "Prepare article HEADERS.
5274 Headers already prepared in the buffer are not modified."
5275 (setq headers (append headers message-required-headers))
5277 (message-narrow-to-headers)
5278 (let* ((Date (message-make-date))
5279 (Message-ID (message-make-message-id))
5280 (Organization (message-make-organization))
5281 (From (message-make-from))
5282 (Path (message-make-path))
5285 (In-Reply-To (message-make-in-reply-to))
5286 (References (message-make-references))
5288 (Distribution (message-make-distribution))
5289 (Lines (message-make-lines))
5290 (User-Agent (message-make-user-agent))
5291 (Expires (message-make-expires))
5292 (case-fold-search t)
5295 ;; First we remove any old generated headers.
5296 (let ((headers message-deletable-headers))
5297 (unless (buffer-modified-p)
5298 (setq headers (delq 'Message-ID (copy-sequence headers))))
5300 (goto-char (point-min))
5301 (and (re-search-forward
5302 (concat "^" (symbol-name (car headers)) ": *") nil t)
5303 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
5304 (message-delete-line))
5306 ;; Go through all the required headers and see if they are in the
5307 ;; articles already. If they are not, or are empty, they are
5308 ;; inserted automatically - except for Subject, Newsgroups and
5311 (goto-char (point-min))
5312 (setq elem (pop headers))
5314 (if (eq (car elem) 'optional)
5315 (setq header (cdr elem)
5317 (setq header (car elem)))
5319 (when (or (not (re-search-forward
5323 (if (stringp header)
5325 (symbol-name header))))
5329 ;; The header was found. We insert a space after the
5330 ;; colon, if there is none.
5331 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
5332 ;; Find out whether the header is empty.
5333 (looking-at "[ \t]*\n[^ \t]")))
5334 ;; So we find out what value we should insert.
5338 (eq (car elem) 'optional))
5339 ;; This is an optional header. If the cdr of this
5340 ;; is something that is nil, then we do not insert
5342 (setq header (cdr elem))
5343 (or (and (message-functionp (cdr elem))
5344 (funcall (cdr elem)))
5345 (and (boundp (cdr elem))
5346 (symbol-value (cdr elem)))))
5348 ;; The element is a cons. Either the cdr is a
5349 ;; string to be inserted verbatim, or it is a
5350 ;; function, and we insert the value returned from
5352 (or (and (stringp (cdr elem))
5354 (and (message-functionp (cdr elem))
5355 (funcall (cdr elem)))))
5356 ((and (boundp header)
5357 (symbol-value header))
5358 ;; The element is a symbol. We insert the value
5359 ;; of this symbol, if any.
5360 (symbol-value header))
5361 ((not (message-check-element header))
5362 ;; We couldn't generate a value for this header,
5363 ;; so we just ask the user.
5364 (read-from-minibuffer
5365 (format "Empty header for %s; enter value: " header)))))
5366 ;; Finally insert the header.
5368 (not (equal value "")))
5372 ;; This header didn't exist, so we insert it.
5373 (goto-char (point-max))
5375 (cdr (assq header message-header-format-alist))))
5377 (funcall formatter header value)
5378 (insert (if (stringp header)
5379 header (symbol-name header))
5381 ;; We check whether the value was ended by a
5382 ;; newline. If now, we insert one.
5386 ;; The value of this header was empty, so we clear
5387 ;; totally and insert the new value.
5388 (delete-region (point) (gnus-point-at-eol))
5389 ;; If the header is optional, and the header was
5390 ;; empty, we can't insert it anyway.
5395 ;; Add the deletable property to the headers that require it.
5396 (and (memq header message-deletable-headers)
5397 (progn (beginning-of-line) (looking-at "[^:]+: "))
5398 (add-text-properties
5399 (point) (match-end 0)
5400 '(message-deletable t face italic) (current-buffer)))))))
5401 ;; Insert new Sender if the From is strange.
5402 (let ((from (message-fetch-field "from"))
5403 (sender (message-fetch-field "sender"))
5404 (secure-sender (message-make-sender)))
5406 (not (message-check-element 'sender))
5409 (cadr (std11-extract-address-components from)))
5410 (downcase secure-sender)))
5415 (cadr (std11-extract-address-components sender)))
5416 (downcase secure-sender)))))
5417 (goto-char (point-min))
5418 ;; Rename any old Sender headers to Original-Sender.
5419 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
5421 (insert "Original-")
5422 (beginning-of-line))
5423 (when (or (message-news-p)
5424 (string-match "@.+\\.." secure-sender))
5425 (insert "Sender: " secure-sender "\n")))))))
5427 (defun message-insert-courtesy-copy ()
5428 "Insert a courtesy message in mail copies of combined messages."
5432 (message-narrow-to-headers)
5433 (when (setq newsgroups (message-fetch-field "newsgroups"))
5434 (goto-char (point-max))
5435 (insert "Posted-To: " newsgroups "\n")))
5437 (when message-courtesy-message
5439 ((string-match "%s" message-courtesy-message)
5440 (insert (format message-courtesy-message newsgroups)))
5442 (insert message-courtesy-message)))))))
5445 ;;; Setting up a message buffer
5448 (defun message-fill-address (header value)
5450 (narrow-to-region (point) (point))
5451 (insert (capitalize (symbol-name header))
5453 (if (consp value) (car value) value)
5455 (narrow-to-region (point-min) (1- (point-max)))
5457 (goto-char (point-min))
5459 (skip-chars-forward "^,\"" (point-max))
5460 (if (or (eq (char-after) ?,)
5463 (if (and (> (current-column) 78)
5467 (looking-at "[ \t]*")
5468 (replace-match "\n " t t)))
5469 (setq last (1+ (point))))
5470 (setq quoted (not quoted)))
5473 (goto-char (point-max))
5477 (defun message-fill-references (header value)
5478 (insert (capitalize (symbol-name header))
5480 (std11-fill-msg-id-list-string
5481 (if (consp value) (car value) value))
5484 (defun message-fill-header (header value)
5485 (let ((begin (point))
5488 (insert (capitalize (symbol-name header))
5490 (if (consp value) (car value) value)
5493 (narrow-to-region begin (point))
5494 (fill-region-as-paragraph begin (point))
5495 ;; Tapdance around looong Message-IDs.
5497 (when (looking-at "[ \t]*$")
5498 (message-delete-line))
5500 (re-search-forward ":" nil t)
5501 (when (looking-at "\n[ \t]+")
5502 (replace-match " " t t))
5503 (goto-char (point-max)))))
5505 (defun message-shorten-1 (list cut surplus)
5506 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
5507 (setcdr (nthcdr (- cut 2) list)
5508 (nthcdr (+ (- cut 2) surplus 1) list)))
5510 (defun message-shorten-references (header references)
5511 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
5512 If folding is disallowed, also check that the REFERENCES are less
5513 than 988 characters long, and if they are not, trim them until they are."
5520 (goto-char (point-min))
5521 ;; Cons a list of valid references.
5522 (while (re-search-forward "<[^>]+>" nil t)
5523 (push (match-string 0) refs))
5524 (setq refs (nreverse refs)
5525 count (length refs)))
5527 ;; If the list has more than MAXCOUNT elements, trim it by
5528 ;; removing the CUTth element and the required number of
5529 ;; elements that follow.
5530 (when (> count maxcount)
5531 (let ((surplus (- count maxcount)))
5532 (message-shorten-1 refs cut surplus)
5533 (decf count surplus)))
5535 ;; If folding is disallowed, make sure the total length (including
5536 ;; the spaces between) will be less than MAXSIZE characters.
5538 ;; Only disallow folding for News messages. At this point the headers
5539 ;; have not been generated, thus we use message-this-is-news directly.
5540 (when (and message-this-is-news message-cater-to-broken-inn)
5542 (totalsize (+ (apply #'+ (mapcar #'length refs))
5545 (ptr (nthcdr (1- cut) refs)))
5546 ;; Decide how many elements to cut off...
5547 (while (> totalsize maxsize)
5548 (decf totalsize (1+ (length (car ptr))))
5550 (setq ptr (cdr ptr)))
5553 (message-shorten-1 refs cut surplus))))
5555 ;; Finally, collect the references back into a string and insert
5556 ;; it into the buffer.
5557 (let ((refstring (mapconcat #'identity refs " ")))
5558 (if (and message-this-is-news message-cater-to-broken-inn)
5559 (insert (capitalize (symbol-name header)) ": "
5561 (message-fill-header header refstring)))))
5563 (defun message-position-point ()
5564 "Move point to where the user probably wants to find it."
5565 (message-narrow-to-headers)
5567 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
5568 (search-backward ":" )
5571 (if (eq (char-after) ? )
5575 (goto-char (point-max))
5578 (unless (looking-at "$")
5582 (defcustom message-beginning-of-line t
5583 "Whether C-a goes to beginning of header values."
5584 :group 'message-buffers
5587 (defun message-beginning-of-line (&optional n)
5588 "Move point to beginning of header value or to beginning of line."
5590 (let ((zrs 'zmacs-region-stays))
5591 (when (and (interactive-p) (boundp zrs))
5593 (if (and message-beginning-of-line
5594 (message-point-in-header-p))
5595 (let* ((here (point))
5596 (bol (progn (beginning-of-line n) (point)))
5597 (eol (gnus-point-at-eol))
5598 (eoh (re-search-forward ": *" eol t)))
5599 (if (or (not eoh) (equal here eoh))
5602 (beginning-of-line n)))
5604 (defun message-buffer-name (type &optional to group)
5605 "Return a new (unique) buffer name based on TYPE and TO."
5607 ;; Generate a new buffer name The Message Way.
5608 ((eq message-generate-new-buffers 'unique)
5609 (generate-new-buffer-name
5613 (or (car (std11-extract-address-components to))
5616 (if (and group (not (string= group ""))) (concat " on " group) "")
5618 ;; Check whether `message-generate-new-buffers' is a function,
5619 ;; and if so, call it.
5620 ((message-functionp message-generate-new-buffers)
5621 (funcall message-generate-new-buffers type to group))
5622 ((eq message-generate-new-buffers 'unsent)
5623 (generate-new-buffer-name
5624 (concat "*unsent " type
5627 (or (car (mail-extract-address-components to))
5630 (if (and group (not (string= group ""))) (concat " on " group) "")
5632 ;; Use standard name.
5634 (format "*%s message*" type))))
5636 (defmacro message-pop-to-buffer-1 (buffer)
5638 (let (special-display-buffer-names
5639 special-display-regexps
5640 same-window-buffer-names
5641 same-window-regexps)
5642 (pop-to-buffer ,buffer))
5643 (pop-to-buffer ,buffer)))
5645 (defun message-pop-to-buffer (name)
5646 "Pop to buffer NAME, and warn if it already exists and is modified."
5647 (let ((buffer (get-buffer name))
5648 (pop-up-frames (and (or (static-if (featurep 'xemacs)
5649 (device-on-window-system-p)
5651 (>= emacs-major-version 20))
5652 message-use-multi-frames)))
5654 (buffer-name buffer))
5656 (message-pop-to-buffer-1 buffer)
5657 (when (and (buffer-modified-p)
5659 "Message already being composed; erase? ")))
5660 (error "Message being composed")))
5661 (message-pop-to-buffer-1 name))
5665 (set (make-local-variable 'message-original-frame) (selected-frame)))))
5667 (defun message-do-send-housekeeping ()
5668 "Kill old message buffers."
5669 ;; We might have sent this buffer already. Delete it from the
5671 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
5672 (while (and message-max-buffers
5674 (>= (length message-buffer-list) message-max-buffers))
5675 ;; Kill the oldest buffer -- unless it has been changed.
5676 (let ((buffer (pop message-buffer-list)))
5677 (when (and (buffer-name buffer)
5678 (not (buffer-modified-p buffer)))
5679 (kill-buffer buffer))))
5680 ;; Rename the buffer.
5681 (if message-send-rename-function
5682 (funcall message-send-rename-function)
5683 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
5685 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
5687 (let ((name (match-string 2 (buffer-name)))
5689 (if (not (or (null name)
5690 (string-equal name "mail")
5691 (string-equal name "posting")))
5692 (setq name (concat "*sent " name "*"))
5693 (message-narrow-to-headers)
5694 (setq to (message-fetch-field "to"))
5695 (setq group (message-fetch-field "newsgroups"))
5699 (to (concat "*sent mail to "
5700 (or (car (mail-extract-address-components to))
5702 ((and group (not (string= group "")))
5703 (concat "*sent posting on " group "*"))
5704 (t "*sent mail*"))))
5705 (unless (string-equal name (buffer-name))
5706 (rename-buffer name t)))))
5707 ;; Push the current buffer onto the list.
5708 (when message-max-buffers
5709 (setq message-buffer-list
5710 (nconc message-buffer-list (list (current-buffer))))))
5712 (defun message-mail-user-agent ()
5714 ((not message-mail-user-agent) nil)
5715 ((eq message-mail-user-agent t) mail-user-agent)
5716 (t message-mail-user-agent))))
5717 (if (memq mua '(message-user-agent gnus-user-agent))
5721 (defun message-setup (headers &optional replybuffer actions switch-function)
5722 (let ((mua (message-mail-user-agent))
5723 subject to field yank-action)
5724 (if (not (and message-this-is-mail mua))
5725 (message-setup-1 headers replybuffer actions)
5727 (setq yank-action (list 'insert-buffer replybuffer)))
5728 (setq headers (copy-sequence headers))
5729 (setq field (assq 'Subject headers))
5731 (setq subject (cdr field))
5732 (setq headers (delq field headers)))
5733 (setq field (assq 'To headers))
5735 (setq to (cdr field))
5736 (setq headers (delq field headers)))
5737 (let ((mail-user-agent mua))
5738 (compose-mail to subject
5739 (mapcar (lambda (item)
5741 (format "%s" (car item))
5744 nil switch-function yank-action actions)))))
5746 (defun message-headers-to-generate (headers included-headers excluded-headers)
5747 "Return a list that includes all headers from HEADERS.
5748 If INCLUDED-HEADERS is a list, just include those headers. If if is
5749 t, include all headers. In any case, headers from EXCLUDED-HEADERS
5753 (dolist (header headers)
5754 (setq header-name (cond
5755 ((and (consp header)
5756 (eq (car header) 'optional))
5757 ;; On the form (optional . Header)
5760 ;; On the form (Header . function)
5765 (when (and (not (memq header-name excluded-headers))
5766 (or (eq included-headers t)
5767 (memq header-name included-headers)))
5768 (push header result)))
5771 (defun message-setup-1 (headers &optional replybuffer actions)
5772 (dolist (action actions)
5774 (add-to-list 'message-send-actions
5775 `(apply ',(car action) ',(cdr action)))))
5776 (setq message-reply-buffer
5777 (or (message-get-parameter 'reply-buffer)
5779 (goto-char (point-min))
5780 ;; Insert all the headers.
5783 (alist message-header-format-alist))
5785 (unless (assq (caar h) message-header-format-alist)
5786 (push (list (caar h)) alist))
5790 (delete-region (point) (progn (forward-line -1) (point)))
5791 (when message-default-headers
5792 (insert message-default-headers)
5793 (or (bolp) (insert ?\n)))
5797 (insert mail-header-separator "\n")
5801 (when (message-news-p)
5802 (when message-default-news-headers
5803 (insert message-default-news-headers)
5804 (or (bolp) (insert ?\n)))
5805 (when message-generate-headers-first
5806 (message-generate-headers
5807 (message-headers-to-generate
5808 (append message-required-news-headers
5809 message-required-headers)
5810 message-generate-headers-first
5811 '(Lines Subject)))))
5812 (when (message-mail-p)
5813 (when message-default-mail-headers
5814 (insert message-default-mail-headers)
5815 (or (bolp) (insert ?\n)))
5816 (when message-generate-headers-first
5817 (message-generate-headers
5818 (message-headers-to-generate
5819 (append message-required-mail-headers
5820 message-required-headers)
5821 message-generate-headers-first
5822 '(Lines Subject)))))
5823 (run-hooks 'message-signature-setup-hook)
5824 (message-insert-signature)
5826 (message-narrow-to-headers)
5827 (if (and replybuffer
5828 message-alternative-emails)
5829 (message-use-alternative-email-as-from))
5830 (run-hooks 'message-header-setup-hook))
5831 (set-buffer-modified-p nil)
5832 (setq buffer-undo-list nil)
5833 (run-hooks 'message-setup-hook)
5834 (message-position-point)
5837 (defun message-set-auto-save-file-name ()
5838 "Associate the message buffer with a file in the drafts directory."
5839 (when message-auto-save-directory
5840 (unless (file-directory-p
5841 (directory-file-name message-auto-save-directory))
5842 (make-directory message-auto-save-directory t))
5844 (setq message-draft-article
5845 (nndraft-request-associate-buffer "drafts"))
5846 (setq buffer-file-name (expand-file-name
5847 (if (memq system-type
5848 '(ms-dos ms-windows windows-nt
5849 cygwin cygwin32 win32 w32
5853 message-auto-save-directory))
5854 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
5855 (clear-visited-file-modtime)
5856 (static-if (boundp 'MULE)
5857 (set-file-coding-system message-draft-coding-system)
5858 (setq buffer-file-coding-system message-draft-coding-system))))
5860 (defun message-disassociate-draft ()
5861 "Disassociate the message buffer from the drafts directory."
5862 (when message-draft-article
5863 (nndraft-request-expire-articles
5864 (list message-draft-article) "drafts" nil t)))
5866 (defun message-insert-headers ()
5867 "Generate the headers for the article."
5871 (message-narrow-to-headers)
5872 (when (message-news-p)
5873 (message-generate-headers
5876 (copy-sequence message-required-news-headers)))))
5877 (when (message-mail-p)
5878 (message-generate-headers
5881 (copy-sequence message-required-mail-headers))))))))
5886 ;;; Commands for interfacing with message
5890 (defun message-mail (&optional to subject
5891 other-headers continue switch-function
5892 yank-action send-actions)
5893 "Start editing a mail message to be sent.
5894 OTHER-HEADERS is an alist of header/value pairs."
5896 (let ((message-this-is-mail t) replybuffer)
5897 (unless (message-mail-user-agent)
5898 (message-pop-to-buffer (message-buffer-name "mail" to)))
5899 ;; FIXME: message-mail should do something if YANK-ACTION is not
5901 (and (consp yank-action) (eq (car yank-action) 'insert-buffer)
5902 (setq replybuffer (nth 1 yank-action)))
5905 `((To . ,(or to "")) (Subject . ,(or subject "")))
5906 (when other-headers other-headers))
5907 replybuffer send-actions)
5908 ;; FIXME: Should return nil if failure.
5912 (defun message-news (&optional newsgroups subject)
5913 "Start editing a news article to be sent."
5915 (let ((message-this-is-news t))
5916 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
5917 (message-setup `((Newsgroups . ,(or newsgroups ""))
5918 (Subject . ,(or subject ""))))))
5920 (defun message-get-reply-headers (wide &optional to-address address-headers)
5921 (let (follow-to mct never-mct to cc author mft recipients)
5922 ;; Find all relevant headers we need.
5923 (let ((mrt (when message-use-mail-reply-to
5924 (message-fetch-field "mail-reply-to")))
5925 (reply-to (message-fetch-field "reply-to")))
5926 (setq to (message-fetch-field "to")
5927 cc (message-fetch-field "cc")
5928 mct (when message-use-mail-copies-to
5929 (message-fetch-field "mail-copies-to"))
5932 (message-fetch-field "from")
5934 mft (when (and (not (or to-address mrt reply-to))
5935 message-use-mail-followup-to)
5936 (message-fetch-field "mail-followup-to"))))
5939 ;; Handle special values of Mail-Copies-To.
5941 (cond ((or (equal (downcase mct) "never")
5942 (equal (downcase mct) "nobody"))
5943 (when (or (not (eq message-use-mail-copies-to 'ask))
5945 (concat "Obey Mail-Copies-To: never? ") t "\
5946 You should normally obey the Mail-Copies-To: header.
5948 `Mail-Copies-To: " mct "'
5949 directs you not to send your response to the author."))
5952 ((or (equal (downcase mct) "always")
5953 (equal (downcase mct) "poster"))
5954 (if (or (not (eq message-use-mail-copies-to 'ask))
5956 (concat "Obey Mail-Copies-To: always? ") t "\
5957 You should normally obey the Mail-Copies-To: header.
5959 `Mail-Copies-To: " mct "'
5960 sends a copy of your response to the author."))
5963 ((and (eq message-use-mail-copies-to 'ask)
5964 (not (message-y-or-n-p
5965 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
5966 You should normally obey the Mail-Copies-To: header.
5968 `Mail-Copies-To: " mct "'
5969 sends a copy of your response to " (if (string-match "," mct)
5970 "the specified addresses"
5971 "that address") ".")))
5974 ;; Build (textual) list of new recipient addresses.
5977 (setq recipients (concat ", " author)))
5979 (dolist (header address-headers)
5980 (let ((value (message-fetch-field header)))
5982 (setq recipients (concat recipients ", " value))))))
5984 (string-match "[^ \t,]" mft)
5985 (or (not (eq message-use-mail-followup-to 'ask))
5986 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
5987 You should normally obey the Mail-Followup-To: header. In this
5988 article, it has the value of
5992 which directs your response to " (if (string-match "," mft)
5993 "the specified addresses"
5994 "that address only") ".
5996 Most commonly, Mail-Followup-To is used by a mailing list poster to
5997 express that responses should be sent to just the list, and not the
6000 If a message is posted to several mailing lists, Mail-Followup-To may
6001 also be used to direct the following discussion to one list only,
6002 because discussions that are spread over several lists tend to be
6003 fragmented and very difficult to follow.
6005 Also, some source/announcement lists are not intended for discussion;
6006 responses here are directed to other addresses.")))
6007 (setq recipients (concat ", " mft)))
6009 (setq recipients (concat ", " to-address))
6010 ;; If the author explicitly asked for a copy, we don't deny it to them.
6011 (if mct (setq recipients (concat recipients ", " mct))))
6013 (setq recipients (if never-mct "" (concat ", " author)))
6014 (if to (setq recipients (concat recipients ", " to)))
6015 (if cc (setq recipients (concat recipients ", " cc)))
6016 (if mct (setq recipients (concat recipients ", " mct)))))
6017 (if (>= (length recipients) 2)
6018 ;; Strip the leading ", ".
6019 (setq recipients (substring recipients 2)))
6020 ;; Squeeze whitespace.
6021 (while (string-match "[ \t][ \t]+" recipients)
6022 (setq recipients (replace-match " " t t recipients)))
6023 ;; Remove addresses that match `rmail-dont-reply-to-names'.
6024 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
6025 (setq recipients (rmail-dont-reply-to recipients)))
6026 ;; Perhaps "Mail-Copies-To: never" removed the only address?
6027 (if (string-equal recipients "")
6028 (setq recipients author))
6029 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
6033 (cons (downcase (mail-strip-quoted-names addr)) addr))
6034 (message-tokenize-header recipients)))
6035 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
6036 (let ((s recipients))
6038 (setq recipients (delq (assoc (car (pop s)) s) recipients))))
6040 ;; Remove hierarchical lists that are contained within each other,
6041 ;; if message-hierarchical-addresses is defined.
6042 (when message-hierarchical-addresses
6043 (let ((plain-addrs (mapcar 'car recipients))
6046 (setq subaddrs (assoc (car plain-addrs)
6047 message-hierarchical-addresses)
6048 plain-addrs (cdr plain-addrs))
6050 (setq subaddrs (cdr subaddrs))
6052 (setq recip (assoc (car subaddrs) recipients)
6053 subaddrs (cdr subaddrs))
6055 (setq recipients (delq recip recipients))))))))
6057 ;; Build the header alist. Allow the user to be asked whether
6058 ;; or not to reply to all recipients in a wide reply.
6059 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
6060 (when (and recipients
6061 (or (not message-wide-reply-confirm-recipients)
6062 (y-or-n-p "Reply to all recipients? ")))
6063 (setq recipients (mapconcat
6064 (lambda (addr) (cdr addr)) recipients ", "))
6065 (if (string-match "^ +" recipients)
6066 (setq recipients (substring recipients (match-end 0))))
6067 (push (cons 'Cc recipients) follow-to)))
6071 (defun message-reply (&optional to-address wide)
6072 "Start editing a reply to the article in the current buffer."
6074 (require 'gnus-sum) ; for gnus-list-identifiers
6075 (let ((cur (current-buffer))
6077 references message-id follow-to
6078 (inhibit-point-motion-hooks t)
6079 (message-this-is-mail t)
6080 gnus-warning in-reply-to)
6082 (message-narrow-to-head-1)
6083 ;; Allow customizations to have their say.
6085 ;; This is a regular reply.
6086 (when (message-functionp message-reply-to-function)
6088 (setq follow-to (funcall message-reply-to-function))))
6089 ;; This is a followup.
6090 (when (message-functionp message-wide-reply-to-function)
6093 (funcall message-wide-reply-to-function)))))
6094 (setq message-id (message-fetch-field "message-id" t)
6095 references (message-fetch-field "references")
6096 date (message-fetch-field "date")
6097 from (message-fetch-field "from")
6098 subject (or (message-fetch-field "subject") "none"))
6099 (when gnus-list-identifiers
6100 (setq subject (message-strip-list-identifiers subject)))
6101 (setq subject (message-make-followup-subject subject))
6102 (when message-subject-trailing-was-query
6103 (setq subject (message-strip-subject-trailing-was subject)))
6105 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6106 (string-match "<[^>]+>" gnus-warning))
6107 (setq message-id (match-string 0 gnus-warning)))
6110 (setq follow-to (message-get-reply-headers wide to-address)))
6112 ;; Get the references from "In-Reply-To" field if there were
6113 ;; no references and "In-Reply-To" field looks promising.
6115 (when (and (setq in-reply-to (message-fetch-field "in-reply-to"))
6116 (string-match "<[^>]+>" in-reply-to))
6117 (setq references (match-string 0 in-reply-to)))))
6119 (unless (message-mail-user-agent)
6120 (message-pop-to-buffer
6121 (message-buffer-name
6122 (if wide "wide reply" "reply") from
6123 (if wide to-address nil))))
6125 (setq message-reply-headers
6126 (make-full-mail-header-from-decoded-header
6127 0 subject from date message-id references 0 0 ""))
6130 `((Subject . ,subject)
6135 (defun message-wide-reply (&optional to-address)
6136 "Make a \"wide\" reply to the message in the current buffer."
6138 (message-reply to-address t))
6141 (defun message-followup (&optional to-newsgroups)
6142 "Follow up to the message in the current buffer.
6143 If TO-NEWSGROUPS, use that as the new Newsgroups line."
6145 (require 'gnus-sum) ; for gnus-list-identifiers
6146 (let ((cur (current-buffer))
6147 from subject date reply-to mrt mct mft
6148 references message-id follow-to
6149 (inhibit-point-motion-hooks t)
6150 (message-this-is-news t)
6151 followup-to distribution newsgroups gnus-warning posted-to)
6153 (message-narrow-to-head)
6154 (when (message-functionp message-followup-to-function)
6156 (funcall message-followup-to-function)))
6157 (setq from (message-fetch-field "from")
6158 date (message-fetch-field "date")
6159 subject (or (message-fetch-field "subject") "none")
6160 references (message-fetch-field "references")
6161 message-id (message-fetch-field "message-id" t)
6162 followup-to (message-fetch-field "followup-to")
6163 newsgroups (message-fetch-field "newsgroups")
6164 posted-to (message-fetch-field "posted-to")
6165 reply-to (message-fetch-field "reply-to")
6166 mrt (when message-use-mail-reply-to
6167 (message-fetch-field "mail-reply-to"))
6168 distribution (message-fetch-field "distribution")
6169 mct (when message-use-mail-copies-to
6170 (message-fetch-field "mail-copies-to"))
6171 mft (when message-use-mail-followup-to
6172 (message-fetch-field "mail-followup-to")))
6173 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6174 (string-match "<[^>]+>" gnus-warning))
6175 (setq message-id (match-string 0 gnus-warning)))
6176 ;; Remove bogus distribution.
6177 (when (and (stringp distribution)
6178 (let ((case-fold-search t))
6179 (string-match "world" distribution)))
6180 (setq distribution nil))
6181 (if gnus-list-identifiers
6182 (setq subject (message-strip-list-identifiers subject)))
6183 (setq subject (message-make-followup-subject subject))
6184 (when message-subject-trailing-was-query
6185 (setq subject (message-strip-subject-trailing-was subject)))
6188 ;; Handle special values of Mail-Copies-To.
6191 ((and (or (equal (downcase mct) "never")
6192 (equal (downcase mct) "nobody")))
6194 ((and (or (equal (downcase mct) "always")
6195 (equal (downcase mct) "poster")))
6196 (if (or (not (eq message-use-mail-copies-to 'ask))
6198 (concat "Obey Mail-Copies-To: always? ") t "\
6199 You should normally obey the Mail-Copies-To: header.
6201 `Mail-Copies-To: " mct "'
6202 sends a copy of your response to the author."))
6203 (setq mct (or mrt reply-to from))
6205 ((and (eq message-use-mail-copies-to 'ask)
6208 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
6209 You should normally obey the Mail-Copies-To: header.
6211 `Mail-Copies-To: " mct "'
6212 sends a copy of your response to " (if (string-match "," mct)
6213 "the specified addresses"
6214 "that address") ".")))
6219 (to-newsgroups (setq follow-to (list (cons 'Newsgroups to-newsgroups))))
6220 ;; Handle Followup-To.
6223 ((equal (downcase followup-to) "poster")
6224 (if (or (and followup-to (eq message-use-followup-to 'use))
6225 (message-y-or-n-p "Obey Followup-To: poster? " t "\
6226 You should normally obey the Followup-To: header.
6228 `Followup-To: poster'
6229 sends your response via e-mail instead of news.
6231 A typical situation where `Followup-To: poster' is used is when the author
6232 does not read the newsgroup, so he wouldn't see any replies sent to it."))
6233 (setq message-this-is-news nil
6235 follow-to (list (cons 'To (or mrt reply-to from ""))))
6236 (setq follow-to (list (cons 'Newsgroups newsgroups)))))
6238 (if (or (equal followup-to newsgroups)
6239 (not (and followup-to (eq message-use-followup-to 'ask)))
6241 (concat "Obey Followup-To: " followup-to "? ") t "\
6242 You should normally obey the Followup-To: header.
6244 `Followup-To: " followup-to "'
6245 directs your response to " (if (string-match "," followup-to)
6246 "the specified newsgroups"
6247 "that newsgroup only") ".
6249 If a message is posted to several newsgroups, Followup-To is often
6250 used to direct the following discussion to one newsgroup only,
6251 because discussions that are spread over several newsgroup tend to
6252 be fragmented and very difficult to follow.
6254 Also, some source/announcement newsgroups are not intended for discussion;
6255 responses here are directed to other newsgroups."))
6256 (setq follow-to (list (cons 'Newsgroups followup-to)))
6257 (setq follow-to (list (cons 'Newsgroups newsgroups)))))))
6258 ;; Handle Mail-Followup-To, followup via e-mail.
6260 (or (not (eq message-use-mail-followup-to 'ask))
6262 (concat "Obey Mail-Followup-To: " mft "? ") t "\
6263 You should normally obey the Mail-Followup-To: header.
6265 `Mail-Followup-To: " mft "'
6266 directs your response to " (if (string-match "," mft)
6267 "the specified addresses"
6268 "that address only") " instead of news.
6270 A typical situation where Mail-Followup-To is used is when the author thinks
6271 that further discussion should take place only in "
6272 (if (string-match "," mft)
6273 "the specified mailing lists"
6274 "that mailing list") ".")))
6275 (setq message-this-is-news nil
6277 follow-to (list (cons 'To mft))))
6278 (posted-to (setq follow-to (list (cons 'Newsgroups posted-to))))
6280 (setq follow-to (list (cons 'Newsgroups newsgroups))))))
6282 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
6284 (setq message-reply-headers
6285 (make-full-mail-header-from-decoded-header
6286 0 subject from date message-id references 0 0 ""))
6289 `((Subject . ,subject)
6291 ,@(and mct (list (cons 'Cc mct)))
6292 ,@(and distribution (list (cons 'Distribution distribution))))
6296 (defun message-cancel-news (&optional arg)
6297 "Cancel an article you posted.
6298 If ARG, allow editing of the cancellation message."
6300 (unless (message-news-p)
6301 (error "This is not a news article; canceling is impossible"))
6302 (let (from newsgroups message-id distribution buf sender)
6304 ;; Get header info from original article.
6306 (message-narrow-to-head-1)
6307 (setq from (message-fetch-field "from")
6308 sender (message-fetch-field "sender")
6309 newsgroups (message-fetch-field "newsgroups")
6310 message-id (message-fetch-field "message-id" t)
6311 distribution (message-fetch-field "distribution")))
6312 ;; Make sure that this article was written by the user.
6314 ;; Canlock-logic as suggested by Per Abrahamsen
6315 ;; <abraham@dina.kvl.dk>
6317 ;; IF article has cancel-lock THEN
6318 ;; IF we can verify it THEN
6321 ;; error: cancellock: article is not yours
6323 ;; Use old rules, comparing sender...
6324 (if (message-fetch-field "Cancel-Lock")
6325 (if (null (canlock-verify))
6327 (error "Failed to verify Cancel-lock: This article is not yours"))
6329 (message-gnksa-enable-p 'cancel-messages)
6333 (downcase (message-make-sender))))
6335 (downcase (cadr (std11-extract-address-components from)))
6336 (downcase (cadr (std11-extract-address-components
6337 (message-make-from))))))
6338 (error "This article is not yours"))
6339 (when (yes-or-no-p "Do you really want to cancel this article? ")
6340 ;; Make control message.
6343 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
6345 (insert "Newsgroups: " newsgroups "\n"
6347 "Subject: cmsg cancel " message-id "\n"
6348 "Control: cancel " message-id "\n"
6350 (concat "Distribution: " distribution "\n")
6352 mail-header-separator "\n"
6353 message-cancel-message)
6354 (run-hooks 'message-cancel-hook)
6356 (message "Canceling your article...")
6357 (if (let ((message-syntax-checks
6358 'dont-check-for-anything-just-trust-me)
6359 (message-encoding-buffer (current-buffer))
6360 (message-edit-buffer (current-buffer)))
6361 (message-send-news))
6362 (message "Canceling your article...done"))
6363 (kill-buffer buf))))))
6365 (defun message-supersede-setup-for-mime-edit ()
6366 (set (make-local-variable 'message-setup-hook) nil)
6370 (defun message-supersede ()
6371 "Start composing a message to supersede the current message.
6372 This is done simply by taking the old article and adding a Supersedes
6373 header line with the old Message-ID."
6375 (let ((cur (current-buffer))
6376 (sender (message-fetch-field "sender"))
6377 (from (message-fetch-field "from")))
6378 ;; Check whether the user owns the article that is to be superseded.
6380 ;; Canlock-logic as suggested by Per Abrahamsen
6381 ;; <abraham@dina.kvl.dk>
6383 ;; IF article has cancel-lock THEN
6384 ;; IF we can verify it THEN
6387 ;; error: cancellock: article is not yours
6389 ;; Use old rules, comparing sender...
6390 (if (message-fetch-field "Cancel-Lock")
6391 (if (null (canlock-verify))
6393 (error "Failed to verify Cancel-lock: This article is not yours"))
6395 (message-gnksa-enable-p 'cancel-messages)
6399 (downcase (message-make-sender))))
6401 (downcase (cadr (std11-extract-address-components from)))
6402 (downcase (cadr (std11-extract-address-components
6403 (message-make-from))))))
6404 (error "This article is not yours"))
6405 ;; Get a normal message buffer.
6406 (message-pop-to-buffer (message-buffer-name "supersede"))
6407 (insert-buffer-substring cur)
6408 (message-narrow-to-head-1)
6409 ;; Remove unwanted headers.
6410 (when message-ignored-supersedes-headers
6411 (message-remove-header message-ignored-supersedes-headers t))
6412 (goto-char (point-min))
6413 (if (not (re-search-forward "^Message-ID: " nil t))
6414 (error "No Message-ID in this article")
6415 (replace-match "Supersedes: " t t))
6416 (goto-char (point-max))
6417 (insert mail-header-separator)
6419 (when message-supersede-setup-function
6420 (funcall message-supersede-setup-function))
6421 (run-hooks 'message-supersede-setup-hook)
6422 (goto-char (point-min))
6423 (search-forward (concat "\n" mail-header-separator "\n") nil t)))
6426 (defun message-recover ()
6427 "Reread contents of current buffer from its last auto-save file."
6429 (let ((file-name (make-auto-save-file-name)))
6430 (cond ((save-window-excursion
6431 (if (not (eq system-type 'vax-vms))
6432 (with-output-to-temp-buffer "*Directory*"
6433 (with-current-buffer standard-output
6434 (fundamental-mode)) ; for Emacs 20.4+
6435 (buffer-disable-undo standard-output)
6436 (let ((default-directory "/"))
6438 "ls" nil standard-output nil "-l" file-name))))
6439 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
6440 (let ((buffer-read-only nil))
6442 (insert-file-contents file-name nil)))
6443 (t (error "message-recover cancelled")))))
6445 ;;; Washing Subject:
6447 (defun message-wash-subject (subject)
6448 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
6449 Previous forwarders, replyers, etc. may add it."
6452 (goto-char (point-min))
6453 ;; strip Re/Fwd stuff off the beginning
6454 (while (re-search-forward
6455 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
6458 ;; and gnus-style forwards [foo@bar.com] subject
6459 (goto-char (point-min))
6460 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
6464 (goto-char (point-max))
6465 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
6468 ;; and finally, any whitespace that was left-over
6469 (goto-char (point-min))
6470 (while (re-search-forward "^[ \t]+" nil t)
6472 (goto-char (point-max))
6473 (while (re-search-backward "[ \t]+$" nil t)
6478 ;;; Forwarding messages.
6480 (defvar message-forward-decoded-p nil
6481 "Non-nil means the original message is decoded.")
6483 (defun message-forward-subject-author-subject (subject)
6484 "Generate a SUBJECT for a forwarded message.
6485 The form is: [Source] Subject, where if the original message was mail,
6486 Source is the sender, and if the original message was news, Source is
6487 the list of newsgroups is was posted to."
6489 (let ((prefix (message-fetch-field "newsgroups")))
6491 (and (setq prefix (message-fetch-field "from"))
6492 (nnheader-decode-from prefix))
6496 (defun message-forward-subject-fwd (subject)
6497 "Generate a SUBJECT for a forwarded message.
6498 The form is: Fwd: Subject, where Subject is the original subject of
6500 (concat "Fwd: " subject))
6502 (defun message-make-forward-subject ()
6503 "Return a Subject header suitable for the message in the current buffer."
6506 (message-narrow-to-head-1)
6507 (let ((funcs message-make-forward-subject-function)
6508 (subject (message-fetch-field "Subject")))
6511 (if message-forward-decoded-p
6513 (nnheader-decode-subject subject))
6515 (if message-wash-forwarded-subjects
6516 (setq subject (message-wash-subject subject)))
6517 ;; Make sure funcs is a list.
6520 (setq funcs (list funcs)))
6521 ;; Apply funcs in order, passing subject generated by previous
6522 ;; func to the next one.
6524 (when (message-functionp (car funcs))
6525 (setq subject (funcall (car funcs) subject)))
6526 (setq funcs (cdr funcs)))
6530 (defun message-forward (&optional news)
6531 "Forward the current message via mail.
6532 Optional NEWS will use news to forward instead of mail."
6534 (let ((cur (current-buffer))
6535 (subject (message-make-forward-subject)))
6537 (message-news nil subject)
6538 (message-mail nil subject))
6539 (message-forward-make-body cur)))
6542 (defun message-forward-make-body (forward-buffer)
6543 ;; Put point where we want it before inserting the forwarded
6545 ;; Note that this function definition for T-gnus is totally different
6546 ;; from the original Gnus."
6547 (if message-forward-before-signature
6549 (goto-char (point-max)))
6550 ;; Make sure we're at the start of the line.
6553 ;; Narrow to the area we are to insert.
6554 (narrow-to-region (point) (point))
6555 ;; Insert the separators and the forwarded buffer.
6556 (insert message-forward-start-separator)
6557 (let ((art-beg (point)))
6558 (insert-buffer-substring forward-buffer)
6559 (goto-char (point-max))
6560 (insert message-forward-end-separator)
6561 (set-text-properties (point-min) (point-max) nil)
6562 ;; Remove all unwanted headers.
6564 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
6567 (goto-char (point-min))
6568 (message-remove-header message-included-forward-headers t nil t)
6570 (message-position-point)))
6573 (defun message-forward-rmail-make-body (forward-buffer)
6574 (save-window-excursion
6575 (set-buffer forward-buffer)
6576 ;; Rmail doesn't have rmail-msg-restore-non-pruned-header in Emacs
6577 ;; 20. FIXIT, or we drop support for rmail in Emacs 20.
6578 (if (rmail-msg-is-pruned)
6579 (rmail-msg-restore-non-pruned-header)))
6580 (message-forward-make-body forward-buffer))
6583 (defun message-insinuate-rmail ()
6584 "Let RMAIL uses message to forward."
6586 (setq rmail-enable-mime-composing t)
6587 (setq rmail-insert-mime-forwarded-message-function
6588 'message-forward-rmail-make-body))
6591 (defun message-resend (address)
6592 "Resend the current article to ADDRESS."
6594 (list (message-read-from-minibuffer "Resend message to: ")))
6595 (message "Resending message to %s..." address)
6597 (let ((cur (current-buffer))
6599 ;; We first set up a normal mail buffer.
6600 (unless (message-mail-user-agent)
6601 (set-buffer (get-buffer-create " *message resend*"))
6603 (let ((message-this-is-mail t)
6605 (message-setup `((To . ,address))))
6606 ;; Insert our usual headers.
6607 (message-generate-headers '(From Date To))
6608 (message-narrow-to-headers)
6609 ;; Remove X-Draft-From header etc.
6610 (message-remove-header message-ignored-mail-headers t)
6611 ;; Rename them all to "Resent-*".
6612 (goto-char (point-min))
6613 (while (re-search-forward "^[A-Za-z]" nil t)
6618 (delete-region (point) (point-max))
6620 ;; Insert the message to be resent.
6621 (insert-buffer-substring cur)
6622 (goto-char (point-min))
6623 (search-forward "\n\n")
6626 (narrow-to-region beg (point))
6627 (message-remove-header message-ignored-resent-headers t)
6628 (goto-char (point-max)))
6629 (insert mail-header-separator)
6630 ;; Rename all old ("Also-")Resent headers.
6631 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
6634 ;; Quote any "From " lines at the beginning.
6636 (when (looking-at "From ")
6637 (replace-match "X-From-Line: "))
6639 (let ((message-encoding-buffer (current-buffer))
6640 (message-edit-buffer (current-buffer))
6641 message-required-mail-headers)
6642 (message-send-mail))
6643 (kill-buffer (current-buffer)))
6644 (message "Resending message to %s...done" address)))
6646 (defun message-bounce-setup-for-mime-edit ()
6647 (set (make-local-variable 'message-setup-hook) nil)
6651 (defun message-bounce ()
6652 "Re-mail the current message.
6653 This only makes sense if the current message is a bounce message that
6654 contains some mail you have written which has been bounced back to
6657 (let ((cur (current-buffer))
6659 (message-pop-to-buffer (message-buffer-name "bounce"))
6660 (insert-buffer-substring cur)
6662 (message-narrow-to-head)
6663 (if (and (message-fetch-field "MIME-Version")
6664 (setq boundary (message-fetch-field "Content-Type")))
6665 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary)
6666 (setq boundary (concat (match-string 1 boundary) " *\n"
6667 "Content-Type: message/rfc822"))
6668 (setq boundary nil)))
6670 (goto-char (point-min))
6671 (search-forward "\n\n" nil t)
6672 (if (or (and boundary
6673 (re-search-forward boundary nil t)
6675 (and (re-search-forward message-unsent-separator nil t)
6677 (re-search-forward "^Return-Path:.*\n" nil t))
6678 ;; We remove everything before the bounced mail.
6681 (if (re-search-forward "^[^ \n\t]+:" nil t)
6684 (when (re-search-backward "^.?From .*\n" nil t)
6685 (delete-region (match-beginning 0) (match-end 0))))
6687 (message-narrow-to-head-1)
6688 (message-remove-header message-ignored-bounced-headers t)
6689 (goto-char (point-max))
6690 (insert mail-header-separator))
6691 (when message-bounce-setup-function
6692 (funcall message-bounce-setup-function))
6693 (run-hooks 'message-bounce-setup-hook)
6694 (message-position-point)))
6697 ;;; Interactive entry points for new message buffers.
6701 (defun message-mail-other-window (&optional to subject)
6702 "Like `message-mail' command, but display mail buffer in another window."
6704 (unless (message-mail-user-agent)
6705 (let ((pop-up-windows t)
6706 (special-display-buffer-names nil)
6707 (special-display-regexps nil)
6708 (same-window-buffer-names nil)
6709 (same-window-regexps nil))
6710 (message-pop-to-buffer (message-buffer-name "mail" to))))
6711 (let ((message-this-is-mail t))
6712 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
6713 nil nil 'switch-to-buffer-other-window)))
6716 (defun message-mail-other-frame (&optional to subject)
6717 "Like `message-mail' command, but display mail buffer in another frame."
6719 (unless (message-mail-user-agent)
6720 (let ((pop-up-frames t)
6721 (special-display-buffer-names nil)
6722 (special-display-regexps nil)
6723 (same-window-buffer-names nil)
6724 (same-window-regexps nil))
6725 (message-pop-to-buffer (message-buffer-name "mail" to))))
6726 (let ((message-this-is-mail t))
6727 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
6728 nil nil 'switch-to-buffer-other-frame)))
6731 (defun message-news-other-window (&optional newsgroups subject)
6732 "Start editing a news article to be sent."
6734 (let ((pop-up-windows t)
6735 (special-display-buffer-names nil)
6736 (special-display-regexps nil)
6737 (same-window-buffer-names nil)
6738 (same-window-regexps nil))
6739 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
6740 (let ((message-this-is-news t))
6741 (message-setup `((Newsgroups . ,(or newsgroups ""))
6742 (Subject . ,(or subject ""))))))
6745 (defun message-news-other-frame (&optional newsgroups subject)
6746 "Start editing a news article to be sent."
6748 (let ((pop-up-frames t)
6749 (special-display-buffer-names nil)
6750 (special-display-regexps nil)
6751 (same-window-buffer-names nil)
6752 (same-window-regexps nil))
6753 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
6754 (let ((message-this-is-news t))
6755 (message-setup `((Newsgroups . ,(or newsgroups ""))
6756 (Subject . ,(or subject ""))))))
6760 ;; This code should be moved to underline.el (from which it is stolen).
6763 (defun bold-region (start end)
6764 "Bold all nonblank characters in the region.
6765 Works by overstriking characters.
6766 Called from program, takes two arguments START and END
6767 which specify the range to operate on."
6770 (let ((end1 (make-marker)))
6771 (move-marker end1 (max start end))
6772 (goto-char (min start end))
6773 (while (< (point) end1)
6774 (or (looking-at "[_\^@- ]")
6775 (insert (char-after) "\b"))
6776 (forward-char 1)))))
6779 (defun unbold-region (start end)
6780 "Remove all boldness (overstruck characters) in the region.
6781 Called from program, takes two arguments START and END
6782 which specify the range to operate on."
6785 (let ((end1 (make-marker)))
6786 (move-marker end1 (max start end))
6787 (goto-char (min start end))
6788 (while (re-search-forward "\b" end1 t)
6789 (if (eq (char-after) (char-after (- (point) 2)))
6790 (delete-char -2))))))
6792 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
6794 ;; Support for toolbar
6796 (defvar tool-bar-map)
6797 (defvar tool-bar-mode))
6799 (defun message-tool-bar-local-item-from-menu (command icon in-map &optional from-map &rest props)
6800 ;; We need to make tool bar entries in local keymaps with
6801 ;; `tool-bar-local-item-from-menu' in Emacs > 21.3
6802 (if (fboundp 'tool-bar-local-item-from-menu)
6803 ;; This is for Emacs 21.3
6804 (tool-bar-local-item-from-menu command icon in-map from-map props)
6805 (tool-bar-add-item-from-menu command icon from-map props)))
6807 (defun message-tool-bar-map ()
6808 (or message-tool-bar-map
6809 (setq message-tool-bar-map
6811 (condition-case nil (require 'tool-bar) (error nil))
6812 (fboundp 'tool-bar-add-item-from-menu)
6814 (let ((tool-bar-map (copy-keymap tool-bar-map))
6815 (load-path (mm-image-load-path)))
6816 ;; Zap some items which aren't so relevant and take
6818 (dolist (key '(print-buffer kill-buffer save-buffer
6819 write-file dired open-file))
6820 (define-key tool-bar-map (vector key) nil))
6821 (message-tool-bar-local-item-from-menu
6822 'message-send-and-exit "mail_send" tool-bar-map message-mode-map)
6823 (message-tool-bar-local-item-from-menu
6824 'message-kill-buffer "close" tool-bar-map message-mode-map)
6825 (message-tool-bar-local-item-from-menu
6826 'message-dont-send "cancel" tool-bar-map message-mode-map)
6827 ;; (message-tool-bar-local-item-from-menu
6828 ;; 'mime-edit-insert-file "attach"
6829 ;; tool-bar-map mime-edit-mode-map)
6830 (message-tool-bar-local-item-from-menu
6831 'ispell-message "spell" tool-bar-map message-mode-map)
6832 ;; (message-tool-bar-local-item-from-menu
6833 ;; 'mime-edit-preview-message "preview"
6834 ;; tool-bar-map mime-edit-mode-map)
6835 (message-tool-bar-local-item-from-menu
6836 'message-insert-importance-high "important"
6837 tool-bar-map message-mode-map)
6838 (message-tool-bar-local-item-from-menu
6839 'message-insert-importance-low "unimportant"
6840 tool-bar-map message-mode-map)
6841 (message-tool-bar-local-item-from-menu
6842 'message-insert-disposition-notification-to "receipt"
6843 tool-bar-map message-mode-map)
6846 ;;; Group name completion.
6848 (defcustom message-newgroups-header-regexp
6849 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
6850 "Regexp that match headers that lists groups."
6854 (defcustom message-completion-alist
6855 (list (cons message-newgroups-header-regexp 'message-expand-group)
6856 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name)
6857 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
6858 . message-expand-name)
6859 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
6860 . message-expand-name))
6861 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
6863 :type '(alist :key-type regexp :value-type function))
6865 (defcustom message-expand-name-function
6866 (if (fboundp 'bbdb-complete-name)
6868 (if (fboundp 'lsdb-complete-name)
6871 "*A function called to expand addresses in field body."
6875 (defcustom message-tab-body-function nil
6876 "*Function to execute when `message-tab' (TAB) is executed in the body.
6877 If nil, the function bound in `text-mode-map' or `global-map' is executed."
6881 (defun message-tab ()
6882 "Complete names according to `message-completion-alist'.
6883 Execute function specified by `message-tab-body-function' when not in
6886 (let ((alist message-completion-alist))
6888 (let ((mail-abbrev-mode-regexp (caar alist)))
6889 (not (mail-abbrev-in-expansion-header-p))))
6890 (setq alist (cdr alist)))
6891 (funcall (or (cdar alist) message-tab-body-function
6892 (lookup-key text-mode-map "\t")
6893 (lookup-key global-map "\t")
6894 'indent-relative))))
6896 (defun message-expand-group ()
6897 "Expand the group name under point."
6898 (let* ((b (save-excursion
6903 (skip-chars-forward "^:")
6906 (skip-chars-backward "^, \t\n") (point))))
6907 (completion-ignore-case t)
6908 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
6910 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
6911 (completions (all-completions string hashtb))
6913 (delete-region b (point))
6915 ((= (length completions) 1)
6916 (if (string= (car completions) string)
6919 (message "Only matching group"))
6920 (insert (car completions))))
6921 ((and (setq comp (try-completion string hashtb))
6922 (not (string= comp string)))
6927 (message "No matching groups")
6928 (save-selected-window
6929 (pop-to-buffer "*Completions*")
6930 (buffer-disable-undo)
6931 (let ((buffer-read-only nil))
6933 (let ((standard-output (current-buffer)))
6934 (display-completion-list (sort completions 'string<)))
6935 (goto-char (point-min))
6936 (delete-region (point) (progn (forward-line 3) (point))))))))))
6938 (defun message-expand-name ()
6939 (funcall message-expand-name-function))
6943 (defun message-talkative-question (ask question show &rest text)
6944 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
6945 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
6946 The following arguments may contain lists of values."
6948 (setq text (message-flatten-list text)))
6949 (save-window-excursion
6951 (with-output-to-temp-buffer " *MESSAGE information message*"
6952 (set-buffer " *MESSAGE information message*")
6953 (fundamental-mode) ; for Emacs 20.4+
6954 (mapcar 'princ text)
6955 (goto-char (point-min))))
6956 (funcall ask question))
6957 (funcall ask question)))
6959 (defun message-flatten-list (list)
6960 "Return a new, flat list that contains all elements of LIST.
6962 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
6965 (apply 'append (mapcar 'message-flatten-list list)))
6969 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
6970 "Create and return a buffer with name based on NAME using `generate-new-buffer.'
6971 Then clone the local variables and values from the old buffer to the
6972 new one, cloning only the locals having a substring matching the
6974 (let ((oldbuf (current-buffer)))
6976 (set-buffer (generate-new-buffer name))
6977 (message-clone-locals oldbuf varstr)
6980 (defun message-clone-locals (buffer &optional varstr)
6981 "Clone the local variables from BUFFER to the current buffer."
6982 (let ((locals (save-excursion
6984 (buffer-local-variables)))
6986 "^\\(gnus\\|nn\\|message\\|user-\\(mail-address\\|full-name\\)\\)"))
6989 (when (and (consp local)
6991 (string-match regexp (symbol-name (car local)))
6993 (string-match varstr (symbol-name (car local)))))
6995 (set (make-local-variable (car local))
7000 ;;; @ for MIME Edit mode
7003 (defun message-maybe-encode ()
7004 (when message-mime-mode
7005 ;; Inherit the buffer local variable `mime-edit-pgp-processing'.
7006 (let ((pgp-processing (with-current-buffer message-edit-buffer
7007 mime-edit-pgp-processing)))
7008 (setq mime-edit-pgp-processing pgp-processing))
7009 (run-hooks 'mime-edit-translate-hook)
7010 (if (catch 'mime-edit-error
7012 (mime-edit-pgp-enclose-buffer)
7013 (mime-edit-translate-body)))
7014 (error "Translation error!"))
7015 (run-hooks 'mime-edit-exit-hook)))
7017 (defun message-mime-insert-article (&optional full-headers)
7019 (let ((message-cite-function 'mime-edit-inserted-message-filter)
7020 (message-reply-buffer
7021 (message-get-parameter-with-eval 'original-buffer))
7023 (message-yank-original nil)
7025 (narrow-to-region (goto-char start)
7026 (if (search-forward "\n\n" nil t)
7029 (goto-char (point-min))
7030 (let ((message-included-forward-headers
7031 (if full-headers "" message-included-forward-headers)))
7032 (message-remove-header message-included-forward-headers t nil t))
7035 (set-alist 'mime-edit-message-inserter-alist
7036 'message-mode (function message-mime-insert-article))
7038 ;;; Miscellaneous functions
7040 ;; stolen (and renamed) from nnheader.el
7041 (static-if (fboundp 'subst-char-in-string)
7042 (defsubst message-replace-chars-in-string (string from to)
7043 (subst-char-in-string from to string))
7044 (defun message-replace-chars-in-string (string from to)
7045 "Replace characters in STRING from FROM to TO."
7046 (let ((string (substring string 0)) ;Copy string.
7047 (len (length string))
7049 ;; Replace all occurrences of FROM with TO.
7051 (when (= (aref string idx) from)
7052 (aset string idx to))
7053 (setq idx (1+ idx)))
7060 (defvar message-inhibit-body-encoding t)
7062 (defun message-encode-message-body ()
7063 (unless message-inhibit-body-encoding
7064 (let ((mail-parse-charset (or mail-parse-charset
7065 message-default-charset))
7066 (case-fold-search t)
7067 lines content-type-p)
7070 (narrow-to-region (point) (point-max))
7071 (let ((new (mml-generate-mime)))
7073 (delete-region (point-min) (point-max))
7075 (goto-char (point-min))
7076 (if (eq (aref new 0) ?\n)
7078 (search-forward "\n\n")
7079 (setq lines (buffer-substring (point-min) (1- (point))))
7080 (delete-region (point-min) (point))))))
7082 (message-narrow-to-headers-or-head)
7083 (message-remove-header "Mime-Version")
7084 (goto-char (point-max))
7085 (insert "MIME-Version: 1.0\n")
7088 (setq content-type-p
7090 (re-search-backward "^Content-Type:" nil t))))
7092 (message-narrow-to-headers-or-head)
7093 (message-remove-first-header "Content-Type")
7094 (message-remove-first-header "Content-Transfer-Encoding"))
7095 ;; We always make sure that the message has a Content-Type
7096 ;; header. This is because some broken MTAs and MUAs get
7097 ;; awfully confused when confronted with a message with a
7098 ;; MIME-Version header and without a Content-Type header. For
7099 ;; instance, Solaris' /usr/bin/mail.
7100 (unless content-type-p
7101 (goto-char (point-min))
7102 ;; For unknown reason, MIME-Version doesn't exist.
7103 (when (re-search-forward "^MIME-Version:" nil t)
7105 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
7107 (defun message-read-from-minibuffer (prompt &optional initial-contents)
7108 "Read from the minibuffer while providing abbrev expansion."
7109 (if (fboundp 'mail-abbrevs-setup)
7110 (let ((mail-abbrev-mode-regexp "")
7111 (minibuffer-setup-hook 'mail-abbrevs-setup)
7112 (minibuffer-local-map message-minibuffer-local-map))
7113 (read-from-minibuffer prompt initial-contents))
7114 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
7115 (minibuffer-local-map message-minibuffer-local-map))
7116 (read-string prompt initial-contents))))
7118 (defun message-use-alternative-email-as-from ()
7119 (require 'mail-utils)
7120 (let* ((fields '("To" "Cc"))
7123 (mail-strip-quoted-names
7124 (mapconcat 'message-fetch-reply-field fields ","))
7128 (if (string-match message-alternative-emails (car emails))
7129 (setq email (car emails)
7132 (unless (or (not email) (equal email user-mail-address))
7133 (goto-char (point-max))
7134 (insert "From: " email "\n"))))
7136 (defun message-options-get (symbol)
7137 (cdr (assq symbol message-options)))
7139 (defun message-options-set (symbol value)
7140 (let ((the-cons (assq symbol message-options)))
7143 (setcdr the-cons value)
7144 (setq message-options (delq the-cons message-options)))
7146 (push (cons symbol value) message-options))))
7149 (defun message-options-set-recipient ()
7151 (message-narrow-to-headers-or-head)
7152 (message-options-set 'message-sender
7153 (mail-strip-quoted-names
7154 (message-fetch-field "from")))
7155 (message-options-set 'message-recipients
7156 (mail-strip-quoted-names
7157 (let ((to (message-fetch-field "to"))
7158 (cc (message-fetch-field "cc"))
7159 (bcc (message-fetch-field "bcc")))
7162 (if (and to cc) ", ")
7164 (if (and (or to cc) bcc) ", ")
7167 (when (featurep 'xemacs)
7168 (require 'messagexmas)
7169 (message-xmas-redefine))
7173 (run-hooks 'message-load-hook)
7176 ;; coding: iso-8859-1
7179 ;;; message.el ends here