1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
8 ;; Keiichi Suzuki <kei-suzu@mail.wbs.ne.jp>
9 ;; Tatsuya Ichikawa <t-ichi@po.shiojiri.ne.jp>
10 ;; Katsumi Yamaoka <yamaoka@jpl.org>
11 ;; Kiyokazu SUTO <suto@merry.xmath.ous.ac.jp>
12 ;; Keywords: mail, news, MIME
14 ;; This file is part of GNU Emacs.
16 ;; GNU Emacs is free software; you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation; either version 2, or (at your option)
21 ;; GNU Emacs is distributed in the hope that it will be useful,
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;; GNU General Public License for more details.
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs; see the file COPYING. If not, write to the
28 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
29 ;; Boston, MA 02111-1307, USA.
33 ;; This mode provides mail-sending facilities from within Emacs. It
34 ;; consists mainly of large chunks of code from the sendmail.el,
35 ;; gnus-msg.el and rnewspost.el files.
42 (defvar gnus-message-group-art)
43 (defvar gnus-list-identifiers)) ; gnus-sum is required where necessary
47 ;; This is apparently necessary even though things are autoloaded.
48 ;; Because we dynamically bind mail-abbrev-mode-regexp, we'd better
49 ;; require mailabbrev here.
50 (if (featurep 'xemacs)
51 (require 'mail-abbrevs)
52 (require 'mailabbrev))
54 (eval-when-compile (require 'static))
56 ;; Avoid byte-compile warnings.
63 (defgroup message '((user-mail-address custom-variable)
64 (user-full-name custom-variable))
65 "Mail and news message composing."
66 :link '(custom-manual "(message)Top")
70 (put 'user-mail-address 'custom-type 'string)
71 (put 'user-full-name 'custom-type 'string)
73 (defgroup message-various nil
74 "Various Message Variables"
75 :link '(custom-manual "(message)Various Message Variables")
78 (defgroup message-buffers nil
80 :link '(custom-manual "(message)Message Buffers")
83 (defgroup message-sending nil
85 :link '(custom-manual "(message)Sending Variables")
88 (defgroup message-interface nil
90 :link '(custom-manual "(message)Interface")
93 (defgroup message-forwarding nil
95 :link '(custom-manual "(message)Forwarding")
96 :group 'message-interface)
98 (defgroup message-insertion nil
100 :link '(custom-manual "(message)Insertion")
103 (defgroup message-headers nil
105 :link '(custom-manual "(message)Message Headers")
108 (defgroup message-news nil
109 "Composing News Messages"
112 (defgroup message-mail nil
113 "Composing Mail Messages"
116 (defgroup message-faces nil
117 "Faces used for message composing."
121 (defgroup message-frames nil
125 (defcustom message-directory "~/Mail/"
126 "*Directory from which all other mail file variables are derived."
127 :group 'message-various
130 (defcustom message-max-buffers 10
131 "*How many buffers to keep before starting to kill them off."
132 :group 'message-buffers
135 (defcustom message-send-rename-function nil
136 "Function called to rename the buffer after sending it."
137 :group 'message-buffers
138 :type '(choice function (const nil)))
140 (defcustom message-fcc-handler-function 'message-output
141 "*A function called to save outgoing articles.
142 This function will be called with the name of the file to store the
143 article in. The default function is `message-output' which saves in Unix
145 :type '(radio (function-item message-output)
146 (function :tag "Other"))
147 :group 'message-sending)
149 (defcustom message-encode-function 'message-maybe-encode
150 "*A function called to encode messages."
151 :group 'message-sending
154 (defcustom message-8bit-encoding-list '(8bit binary)
155 "*8bit encoding type in Content-Transfer-Encoding field."
156 :group 'message-sending
157 :type '(repeat (symbol :tag "Type")))
159 (defcustom message-fcc-externalize-attachments nil
160 "If non-nil, attachments are included as external parts in Fcc copies."
162 :group 'message-sending)
164 (defcustom message-courtesy-message
165 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
166 "*This is inserted at the start of a mailed copy of a posted message.
167 If the string contains the format spec \"%s\", the Newsgroups
168 the article has been posted to will be inserted there.
169 If this variable is nil, no such courtesy message will be added."
170 :group 'message-sending
171 :type '(radio (string :format "%t: %v\n" :size 0) (const nil)))
173 (defcustom message-ignored-bounced-headers
174 "^\\(Received\\|Return-Path\\|Delivered-To\\):"
175 "*Regexp that matches headers to be removed in resent bounced mail."
176 :group 'message-interface
179 (defcustom message-bounce-setup-function 'message-bounce-setup-for-mime-edit
180 "Function to setup a re-sending bounced message."
181 :group 'message-sending
184 ;;; Start of variables adopted from `message-utils.el'.
186 (defcustom message-subject-trailing-was-query 'ask
187 "*What to do with trailing \"(was: <old subject>)\" in subject lines.
188 If nil, leave the subject unchanged. If it is the symbol `ask', query
189 the user what do do. In this case, the subject is matched against
190 `message-subject-trailing-was-ask-regexp'. If
191 `message-subject-trailing-was-query' is t, always strip the trailing
192 old subject. In this case, `message-subject-trailing-was-regexp' is
194 :type '(choice (const :tag "never" nil)
195 (const :tag "always strip" t)
197 :link '(custom-manual "(message)Message Headers")
198 :group 'message-various)
200 (defcustom message-subject-trailing-was-ask-regexp
201 "[ \t]*\\([[(]+[Ww][Aa][Ss][ \t]*.*[\])]+\\)"
202 "*Regexp matching \"(was: <old subject>)\" in the subject line.
204 The function `message-strip-subject-trailing-was' uses this regexp if
205 `message-subject-trailing-was-query' is set to the symbol `ask'. If
206 the variable is t instead of `ask', use
207 `message-subject-trailing-was-regexp' instead.
209 It is okay to create some false positives here, as the user is asked."
210 :group 'message-various
211 :link '(custom-manual "(message)Message Headers")
214 (defcustom message-subject-trailing-was-regexp
215 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
216 "*Regexp matching \"(was: <old subject>)\" in the subject line.
218 If `message-subject-trailing-was-query' is set to t, the subject is
219 matched against `message-subject-trailing-was-regexp' in
220 `message-strip-subject-trailing-was'. You should use a regexp creating very
221 few false positives here."
222 :group 'message-various
223 :link '(custom-manual "(message)Message Headers")
226 ;; Fixme: Why are all these things autoloaded?
228 ;;; marking inserted text
231 (defcustom message-mark-insert-begin
232 "--8<---------------cut here---------------start------------->8---\n"
233 "How to mark the beginning of some inserted text."
235 :link '(custom-manual "(message)Insertion Variables")
236 :group 'message-various)
239 (defcustom message-mark-insert-end
240 "--8<---------------cut here---------------end--------------->8---\n"
241 "How to mark the end of some inserted text."
243 :link '(custom-manual "(message)Insertion Variables")
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.google.com\) respect this header."
252 :link '(custom-manual "(message)Header Commands")
253 :group 'message-various)
256 (defcustom message-archive-note
257 "X-No-Archive: Yes - save http://groups.google.com/"
258 "Note to insert why you wouldn't want this posting archived.
259 If nil, don't insert any text in the body."
260 :type '(radio (string :format "%t: %v\n" :size 0)
262 :link '(custom-manual "(message)Header Commands")
263 :group 'message-various)
265 ;;; Crossposts and Followups
266 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
267 ;; new suggestions by R. Weikusat <rw at another.de>
269 (defvar message-cross-post-old-target nil
270 "Old target for cross-posts or follow-ups.")
271 (make-variable-buffer-local 'message-cross-post-old-target)
274 (defcustom message-cross-post-default t
275 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
276 If nil, `message-cross-post-followup-to' will only do a followup. Note that
277 you can explicitly override this setting by calling
278 `message-cross-post-followup-to' with a prefix."
280 :group 'message-various)
283 (defcustom message-cross-post-note
284 "Crosspost & Followup-To: "
285 "Note to insert before signature to notify of xpost and follow-up."
287 :group 'message-various)
290 (defcustom message-followup-to-note
292 "Note to insert before signature to notify of follow-up only."
294 :group 'message-various)
297 (defcustom message-cross-post-note-function
298 'message-cross-post-insert-note
299 "Function to use to insert note about Crosspost or Followup-To.
300 The function will be called with four arguments. The function should not only
301 insert a note, but also ensure old notes are deleted. See the documentation
302 for `message-cross-post-insert-note'."
304 :group 'message-various)
306 ;;; End of variables adopted from `message-utils.el'.
309 (defcustom message-from-style 'default
310 "*Specifies how \"From\" headers look.
312 If nil, they contain just the return address like:
314 If `parens', they look like:
315 king@grassland.com (Elvis Parsley)
316 If `angles', they look like:
317 Elvis Parsley <king@grassland.com>
319 Otherwise, most addresses look like `angles', but they look like
320 `parens' if `angles' would need quoting and `parens' would not."
321 :type '(choice (const :tag "simple" nil)
325 :group 'message-headers)
327 (defcustom message-insert-canlock t
328 "Whether to insert a Cancel-Lock header in news postings."
330 :group 'message-headers
333 (defcustom message-syntax-checks
334 (if message-insert-canlock '((sender . disabled)) nil)
335 ;; Guess this one shouldn't be easy to customize...
336 "*Controls what syntax checks should not be performed on outgoing posts.
337 To disable checking of long signatures, for instance, add
338 `(signature . disabled)' to this list.
340 Don't touch this variable unless you really know what you're doing.
342 Checks include `subject-cmsg', `multiple-headers', `sendsys',
343 `message-id', `from', `long-lines', `control-chars', `size',
344 `new-text', `quoting-style', `redirected-followup', `signature',
345 `approved', `sender', `empty', `empty-headers', `message-id', `from',
346 `subject', `shorten-followup-to', `existing-newsgroups',
347 `buffer-file-name', `unchanged', `newsgroups', `reply-to',
348 `continuation-headers', `long-header-lines', `invisible-text' and
351 :type '(repeat sexp)) ; Fixme: improve this
353 (defcustom message-required-headers '((optional . References)
355 "*Headers to be generated or prompted for when sending a message.
356 Also see `message-required-news-headers' and
357 `message-required-mail-headers'."
359 :group 'message-headers
360 :link '(custom-manual "(message)Message Headers")
361 :type '(repeat sexp))
363 (defcustom message-draft-headers '(References From)
364 "*Headers to be generated when saving a draft message."
366 :group 'message-headers
367 :link '(custom-manual "(message)Message Headers")
368 :type '(repeat sexp))
370 (defcustom message-required-news-headers
371 '(From Newsgroups Subject Date Message-ID
372 (optional . Organization)
373 (optional . User-Agent))
374 "*Headers to be generated or prompted for when posting an article.
375 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
376 Message-ID. Organization, Lines, In-Reply-To, Expires, and
377 User-Agent are optional. If don't you want message to insert some
378 header, remove it from this list."
380 :group 'message-headers
381 :link '(custom-manual "(message)Message Headers")
382 :type '(repeat sexp))
384 (defcustom message-required-mail-headers
385 '(From Subject Date (optional . In-Reply-To) Message-ID
386 (optional . User-Agent))
387 "*Headers to be generated or prompted for when mailing a message.
388 It is recommended that From, Date, To, Subject and Message-ID be
389 included. Organization and User-Agent are optional."
391 :group 'message-headers
392 :link '(custom-manual "(message)Message Headers")
393 :type '(repeat sexp))
395 (defcustom message-deletable-headers '(Message-ID Date Lines)
396 "Headers to be deleted if they already exist and were generated by message previously."
397 :group 'message-headers
398 :link '(custom-manual "(message)Message Headers")
401 (defcustom message-ignored-news-headers
402 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
403 "*Regexp of headers to be removed unconditionally before posting."
405 :group 'message-headers
406 :link '(custom-manual "(message)Message Headers")
409 (defcustom message-ignored-mail-headers
410 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
411 "*Regexp of headers to be removed unconditionally before mailing."
413 :group 'message-headers
414 :link '(custom-manual "(message)Mail Headers")
417 (defcustom message-ignored-supersedes-headers "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|^X-Trace:\\|^X-Complaints-To:\\|Return-Path:\\|^Supersedes:\\|^NNTP-Posting-Date:\\|^X-Trace:\\|^X-Complaints-To:\\|^Cancel-Lock:\\|^Cancel-Key:\\|^X-Hashcash:\\|^X-Payment:"
418 "*Header lines matching this regexp will be deleted before posting.
419 It's best to delete old Path and Date headers before posting to avoid
421 :group 'message-interface
422 :link '(custom-manual "(message)Superseding")
425 (defcustom message-supersede-setup-function
426 'message-supersede-setup-for-mime-edit
427 "Function to setup a supersede message."
428 :group 'message-sending
431 (defcustom message-subject-re-regexp
432 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)*:[ \t]*\\)*[ \t]*"
433 "*Regexp matching \"Re: \" in the subject line."
434 :group 'message-various
435 :link '(custom-manual "(message)Message Headers")
438 ;;; Some sender agents encode the whole subject including leading "Re: ".
439 ;;; And if followup agent does not decode it for some reason (e.g. unknown
440 ;;; charset) and just add a new "Re: " in front of the encoded-word, the
441 ;;; result will contain multiple "Re: "'s.
442 (defcustom message-subject-encoded-re-regexp
446 "[-!#$%&'*+0-9A-Z^_`a-z{|}~]+" ; charset
449 "[Bb]" (regexp-quote "?") ; B encoding
450 "\\(\\(CQk\\|CSA\\|IAk\\|ICA\\)[Jg]\\)*" ; \([ \t][ \t][ \t]\)*
452 "[Uc][km]U6" ; [Rr][Ee]:
454 "\\(C[VX]\\|I[FH]\\)J[Fl]O[g-v]" ; [ \t][Rr][Ee]:
456 "\\(CQl\\|CSB\\|IAl\\|ICB\\)[Sy][RZ]T[o-r]" ; [ \t][ \t][Rr][Ee]:
459 "[Qb]" (regexp-quote "?") ; Q encoding
460 "\\(_\\|=09\\|=20\\)*"
461 "\\([Rr]\\|=[57]2\\)\\([Ee]\\|=[46]5\\)\\(:\\|=3[Aa]\\)"
464 "*Regexp matching \"Re: \" in the subject line.
465 Unlike `message-subject-re-regexp', this regexp matches \"Re: \" within
467 :group 'message-various
468 :link '(custom-manual "(message)Message Headers")
471 (defcustom message-use-subject-re t
472 "*If t, remove any (buggy) \"Re: \"'s from the subject of the precursor
473 and add a new \"Re: \". If it is nil, use the subject \"as-is\". If it
474 is the symbol `guess', try to detect \"Re: \" within an encoded-word."
475 :group 'message-various
476 :type '(choice (const :tag "off" nil)
481 (defcustom message-signature-separator "^-- *$"
482 "Regexp matching the signature separator."
484 :link '(custom-manual "(message)Various Message Variables")
485 :group 'message-various)
487 (defcustom message-signature-separator-for-insertion "-- \n"
488 "*Signature separator. This value will be inserted as signature separator
489 when composing message. Default value is \"-- \\n\". Notice: Changing this
490 value may go against RFC-1036 and draft-ietf-usefor-article-05.txt. "
492 :group 'message-insertion)
494 (defcustom message-elide-ellipsis "\n[...]\n\n"
495 "*The string which is inserted for elided text."
497 :link '(custom-manual "(message)Insertion Variables")
498 :group 'message-various)
500 (defcustom message-interactive t
501 "Non-nil means when sending a message wait for and display errors.
502 nil means let mailer mail back a message to report errors."
503 :group 'message-sending
505 :link '(custom-manual "(message)Sending Variables")
508 (defcustom message-generate-new-buffers 'unique
509 "*Non-nil means create a new message buffer whenever `message-setup' is called.
510 If this is a function, call that function with three parameters: The type,
511 the to address and the group name. (Any of these may be nil.) The function
512 should return the new buffer name."
513 :group 'message-buffers
514 :link '(custom-manual "(message)Message Buffers")
515 :type '(choice (const :tag "off" nil)
516 (const :tag "unique" unique)
517 (const :tag "unsent" unsent)
520 (defcustom message-kill-buffer-on-exit nil
521 "*Non-nil means that the message buffer will be killed after sending a message."
522 :group 'message-buffers
523 :link '(custom-manual "(message)Message Buffers")
526 (defcustom message-kill-buffer-query-function 'yes-or-no-p
527 "*Function used to prompt user whether to kill the message buffer. If
528 it is t, the buffer will be killed unconditionally."
529 :type '(radio (function-item yes-or-no-p)
530 (function-item y-or-n-p)
531 (function-item nnheader-Y-or-n-p)
532 (function :tag "Other" t))
533 :group 'message-buffers)
535 (defcustom message-kill-buffer-and-remove-file t
536 "*Non-nil means that the associated file will be removed before
537 removing the message buffer. However, it is treated as nil when the
538 command `message-mimic-kill-buffer' is used."
539 :group 'message-buffers
543 (defvar gnus-local-organization))
544 (defcustom message-user-organization
545 (or (and (boundp 'gnus-local-organization)
546 (stringp gnus-local-organization)
547 gnus-local-organization)
548 (getenv "ORGANIZATION")
550 "*String to be used as an Organization header.
551 If t, use `message-user-organization-file'."
552 :group 'message-headers
553 :type '(choice string
554 (const :tag "consult file" t)))
557 (defcustom message-user-organization-file "/usr/lib/news/organization"
558 "*Local news organization file."
560 :link '(custom-manual "(message)News Headers")
561 :group 'message-headers)
563 (defcustom message-forward-start-separator
564 (concat (mime-make-tag "message" "rfc822") "\n")
565 "*Delimiter inserted before forwarded messages."
566 :group 'message-forwarding
569 (defcustom message-forward-end-separator
570 (concat (mime-make-tag "text" "plain") "\n")
571 "*Delimiter inserted after forwarded messages."
572 :group 'message-forwarding
575 (defcustom message-included-forward-headers
576 "^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:"
577 "*Regexp matching headers to be included in forwarded messages."
578 :group 'message-forwarding
581 (defcustom message-make-forward-subject-function
582 #'message-forward-subject-name-subject
583 "*List of functions called to generate subject headers for forwarded messages.
584 The subject generated by the previous function is passed into each
587 The provided functions are:
589 * `message-forward-subject-author-subject' Source of article (author or
590 newsgroup), in brackets followed by the subject
591 * `message-forward-subject-name-subject' Source of article (name of author
592 or newsgroup), in brackets followed by the subject
593 * `message-forward-subject-fwd' Subject of article with 'Fwd:' prepended
595 :group 'message-forwarding
596 :link '(custom-manual "(message)Forwarding")
597 :type '(radio (function-item message-forward-subject-author-subject)
598 (function-item message-forward-subject-fwd)
599 (function-item message-forward-subject-name-subject)
600 (repeat :tag "List of functions" function)))
602 (defcustom message-forward-as-mime t
603 "*Non-nil means forward messages as an inline/rfc822 MIME section.
604 Otherwise, directly inline the old message in the forwarded message."
606 :group 'message-forwarding
607 :link '(custom-manual "(message)Forwarding")
610 (defcustom message-forward-show-mml 'best
611 "*Non-nil means show forwarded messages as MML (decoded from MIME).
612 Otherwise, forwarded messages are unchanged.
613 Can also be the symbol `best' to indicate that MML should be
614 used, except when it is a bad idea to use MML. One example where
615 it is a bad idea is when forwarding a signed or encrypted
616 message, because converting MIME to MML would invalidate the
619 :group 'message-forwarding
620 :type '(choice (const :tag "use MML" t)
621 (const :tag "don't use MML " nil)
622 (const :tag "use MML when appropriate" best)))
624 (defcustom message-forward-before-signature t
625 "*Non-nil means put forwarded message before signature, else after."
626 :group 'message-forwarding
629 (defcustom message-wash-forwarded-subjects nil
630 "*Non-nil means try to remove as much cruft as possible from the subject.
631 Done before generating the new subject of a forward."
632 :group 'message-forwarding
633 :link '(custom-manual "(message)Forwarding")
636 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From "
637 "*All headers that match this regexp will be deleted when resending a message."
638 :group 'message-interface
639 :link '(custom-manual "(message)Resending")
642 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
643 "*All headers that match this regexp will be deleted when forwarding a message."
645 :group 'message-forwarding
646 :type '(choice (const :tag "None" nil)
649 (defcustom message-ignored-cited-headers "."
650 "*Delete these headers from the messages you yank."
651 :group 'message-insertion
652 :link '(custom-manual "(message)Insertion Variables")
655 (defcustom message-cite-prefix-regexp
656 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
657 "\\([ \t]*[-_.[:word:]]+>+\\|[ \t]*[]>|}+]\\)+"
658 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
659 (let (non-word-constituents)
660 (with-syntax-table text-mode-syntax-table
661 (setq non-word-constituents
663 (if (string-match "\\w" "-") "" "-")
664 (if (string-match "\\w" "_") "" "_")
665 (if (string-match "\\w" ".") "" "."))))
666 (if (equal non-word-constituents "")
667 "\\([ \t]*\\(\\w\\)+>+\\|[ \t]*[]>|}+]\\)+"
668 (concat "\\([ \t]*\\(\\w\\|["
669 non-word-constituents
670 "]\\)+>+\\|[ \t]*[]>|}+]\\)+"))))
671 "*Regexp matching the longest possible citation prefix on a line."
672 :group 'message-insertion
673 :link '(custom-manual "(message)Insertion Variables")
676 (defcustom message-cancel-message "I am canceling my own article.\n"
677 "Message to be inserted in the cancel message."
678 :group 'message-interface
679 :link '(custom-manual "(message)Canceling News")
682 ;; Useful to set in site-init.el
684 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
685 "Function to call to send the current buffer as mail.
686 The headers should be delimited by a line whose contents match the
687 variable `mail-header-separator'.
689 Valid values include `message-send-mail-with-sendmail' (the default),
690 `message-send-mail-with-mh', `message-send-mail-with-qmail',
691 `message-send-mail-with-smtp', `message-smtpmail-send-it',
692 `smtpmail-send-it' and `feedmail-send-it'.
694 See also `send-mail-function'."
695 :type '(radio (function-item message-send-mail-with-sendmail)
696 (function-item message-send-mail-with-mh)
697 (function-item message-send-mail-with-qmail)
698 (function-item message-send-mail-with-smtp)
699 (function-item message-smtpmail-send-it)
700 (function-item smtpmail-send-it)
701 (function-item feedmail-send-it)
702 (function :tag "Other"))
703 :group 'message-sending
704 :link '(custom-manual "(message)Mail Variables")
705 :group 'message-mail)
707 ;; 1997-09-29 by MORIOKA Tomohiko
708 (defcustom message-send-news-function 'message-send-news-with-gnus
709 "Function to call to send the current buffer as news.
710 The headers should be delimited by a line whose contents match the
711 variable `mail-header-separator'."
712 :group 'message-sending
714 :link '(custom-manual "(message)News Variables")
717 (defcustom message-reply-to-function nil
718 "If non-nil, function that should return a list of headers.
719 This function should pick out addresses from the To, Cc, and From headers
720 and respond with new To and Cc headers."
721 :group 'message-interface
722 :link '(custom-manual "(message)Reply")
723 :type '(choice function (const nil)))
725 (defcustom message-wide-reply-to-function nil
726 "If non-nil, function that should return a list of headers.
727 This function should pick out addresses from the To, Cc, and From headers
728 and respond with new To and Cc headers."
729 :group 'message-interface
730 :link '(custom-manual "(message)Wide Reply")
731 :type '(choice function (const nil)))
733 (defcustom message-followup-to-function nil
734 "If non-nil, function that should return a list of headers.
735 This function should pick out addresses from the To, Cc, and From headers
736 and respond with new To and Cc headers."
737 :group 'message-interface
738 :link '(custom-manual "(message)Followup")
739 :type '(choice function (const nil)))
741 (defcustom message-use-followup-to 'ask
742 "*Specifies what to do with Followup-To header.
743 If nil, always ignore the header. If it is t, use its value, but
744 query before using the \"poster\" value. If it is the symbol `ask',
745 always query the user whether to use the value. If it is the symbol
746 `use', always use the value."
747 :group 'message-interface
748 :link '(custom-manual "(message)Followup")
749 :type '(choice (const :tag "ignore" nil)
750 (const :tag "use & query" t)
751 (const :tag "maybe" t)
752 (const :tag "always" use)
753 (const :tag "ask" ask)))
755 (defcustom message-use-mail-copies-to 'ask
756 "*Specifies what to do with Mail-Copies-To header.
757 If nil, always ignore the header. If it is t, use its value, but
758 query before using the value other than \"always\" or \"never\".
759 If it is the symbol `ask', always query the user whether to use
760 the value. If it is the symbol `use', always use the value."
761 :group 'message-interface
762 :link '(custom-manual "(message)Mailing Lists")
763 :type '(choice (const :tag "ignore" nil)
764 (const :tag "maybe" t)
765 (const :tag "always" use)
766 (const :tag "ask" ask)))
768 ;;; XXX: 'ask and 'use are not implemented yet.
769 (defcustom message-use-mail-reply-to 'ask
770 "*Specifies what to do with Mail-Reply-To/Reply-To header.
771 If nil, always ignore the header. If it is t or the symbol `use', use
772 its value. If it is the symbol `ask', always query the user whether to
773 use the value. Note that if \"Reply-To\" is marked as \"broken\", its value
775 :group 'message-interface
776 :type '(choice (const :tag "ignore" nil)
777 (const :tag "maybe" t)
778 (const :tag "always" use)
779 (const :tag "ask" ask)))
781 (defcustom message-use-mail-followup-to 'use
782 "*Specifies what to do with Mail-Followup-To header.
783 If nil, always ignore the header. If it is the symbol `ask', always
784 query the user whether to use the value. If it is t or the symbol
785 `use', always use the value."
786 :group 'message-interface
787 :type '(choice (const :tag "ignore" nil)
788 (const :tag "maybe" t)
789 (const :tag "always" use)
790 (const :tag "ask" ask)))
792 (defcustom message-subscribed-address-functions nil
793 "*Specifies functions for determining list subscription.
794 If nil, do not attempt to determine list subscription with functions.
795 If non-nil, this variable contains a list of functions which return
796 regular expressions to match lists. These functions can be used in
797 conjunction with `message-subscribed-regexps' and
798 `message-subscribed-addresses'."
799 :group 'message-interface
800 :link '(custom-manual "(message)Mailing Lists")
801 :type '(repeat sexp))
803 (defcustom message-subscribed-address-file nil
804 "*A file containing addresses the user is subscribed to.
805 If nil, do not look at any files to determine list subscriptions. If
806 non-nil, each line of this file should be a mailing list address."
807 :group 'message-interface
808 :link '(custom-manual "(message)Mailing Lists")
809 :type '(radio (file :format "%t: %v\n" :size 0)
812 (defcustom message-subscribed-addresses nil
813 "*Specifies a list of addresses the user is subscribed to.
814 If nil, do not use any predefined list subscriptions. This list of
815 addresses can be used in conjunction with
816 `message-subscribed-address-functions' and `message-subscribed-regexps'."
817 :group 'message-interface
818 :link '(custom-manual "(message)Mailing Lists")
819 :type '(repeat string))
821 (defcustom message-subscribed-regexps nil
822 "*Specifies a list of addresses the user is subscribed to.
823 If nil, do not use any predefined list subscriptions. This list of
824 regular expressions can be used in conjunction with
825 `message-subscribed-address-functions' and `message-subscribed-addresses'."
826 :group 'message-interface
827 :link '(custom-manual "(message)Mailing Lists")
828 :type '(repeat regexp))
830 (defcustom message-allow-no-recipients 'ask
831 "Specifies what to do when there are no recipients other than Gcc/Fcc.
832 If it is the symbol `always', the posting is allowed. If it is the
833 symbol `never', the posting is not allowed. If it is the symbol
834 `ask', you are prompted."
835 :group 'message-interface
836 :link '(custom-manual "(message)Message Headers")
837 :type '(choice (const always)
841 (defcustom message-sendmail-f-is-evil nil
842 "*Non-nil means don't add \"-f username\" to the sendmail command line.
843 Doing so would be even more evil than leaving it out."
844 :group 'message-sending
845 :link '(custom-manual "(message)Mail Variables")
848 (defcustom message-sendmail-envelope-from nil
849 "*Envelope-from when sending mail with sendmail.
850 If this is nil, use `user-mail-address'. If it is the symbol
851 `header', use the From: header of the message."
852 :type '(choice (string :tag "From name")
853 (const :tag "Use From: header from message" header)
854 (const :tag "Use `user-mail-address'" nil))
855 :link '(custom-manual "(message)Mail Variables")
856 :group 'message-sending)
858 ;; qmail-related stuff
859 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
860 "Location of the qmail-inject program."
861 :group 'message-sending
862 :link '(custom-manual "(message)Mail Variables")
865 (defcustom message-qmail-inject-args nil
866 "Arguments passed to qmail-inject programs.
867 This should be a list of strings, one string for each argument. It
868 may also be a function.
870 For e.g., if you wish to set the envelope sender address so that bounces
871 go to the right place or to deal with listserv's usage of that address, you
872 might set this variable to '(\"-f\" \"you@some.where\")."
873 :group 'message-sending
874 :link '(custom-manual "(message)Mail Variables")
875 :type '(choice (function)
879 (defvar gnus-post-method)
880 (defvar gnus-select-method))
881 (defcustom message-post-method
882 (cond ((and (boundp 'gnus-post-method)
883 (listp gnus-post-method)
886 ((boundp 'gnus-select-method)
889 "*Method used to post news.
890 Note that when posting from inside Gnus, for instance, this
891 variable isn't used."
893 :group 'message-sending
894 ;; This should be the `gnus-select-method' widget, but that might
895 ;; create a dependence to `gnus.el'.
898 ;; FIXME: This should be a temporary workaround until someone implements a
899 ;; proper solution. If a crash happens while replying, the auto-save file
900 ;; will *not* have a `References:' header if `message-generate-headers-first'
901 ;; is nil. See: http://article.gmane.org/gmane.emacs.gnus.general/51138
902 (defcustom message-generate-headers-first '(references)
903 "Which headers should be generated before starting to compose a message.
904 If t, generate all required headers. This can also be a list of headers to
905 generate. The variables `message-required-news-headers' and
906 `message-required-mail-headers' specify which headers to generate.
908 Note that the variable `message-deletable-headers' specifies headers which
909 are to be deleted and then re-generated before sending, so this variable
910 will not have a visible effect for those headers."
911 :group 'message-headers
912 :link '(custom-manual "(message)Message Headers")
913 :type '(choice (const :tag "None" nil)
914 (const :tag "References" '(references))
916 (repeat (sexp :tag "Header"))))
918 (defcustom message-setup-hook '(turn-on-mime-edit)
919 "Normal hook, run each time a new outgoing message is initialized.
920 The function `message-setup' runs this hook."
921 :group 'message-various
922 :link '(custom-manual "(message)Various Message Variables")
925 (defcustom message-cancel-hook nil
926 "Hook run when cancelling articles."
927 :group 'message-various
928 :link '(custom-manual "(message)Various Message Variables")
931 (defcustom message-signature-setup-hook nil
932 "Normal hook, run each time a new outgoing message is initialized.
933 It is run after the headers have been inserted and before
934 the signature is inserted."
935 :group 'message-various
936 :link '(custom-manual "(message)Various Message Variables")
939 (defcustom message-bounce-setup-hook nil
940 "Normal hook, run each time a re-sending bounced message is initialized.
941 The function `message-bounce' runs this hook."
942 :group 'message-various
945 (defcustom message-supersede-setup-hook nil
946 "Normal hook, run each time a supersede message is initialized.
947 The function `message-supersede' runs this hook."
948 :group 'message-various
951 (defcustom message-mode-hook nil
952 "Hook run in message mode buffers."
953 :group 'message-various
956 (defcustom message-header-hook '((lambda () (mime-encode-header-in-buffer t)))
957 "Hook run in a message mode buffer narrowed to the headers."
958 :group 'message-various
961 (defcustom message-header-setup-hook nil
962 "Hook called narrowed to the headers when setting up a message buffer."
963 :group 'message-various
964 :link '(custom-manual "(message)Various Message Variables")
967 (defcustom message-minibuffer-local-map
968 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
969 (set-keymap-parent map minibuffer-local-map)
971 "Keymap for `message-read-from-minibuffer'.")
974 (defcustom message-citation-line-function 'message-insert-citation-line
975 "*Function called to insert the \"Whomever writes:\" line.
977 Note that Gnus provides a feature where the reader can click on
978 `writes:' to hide the cited text. If you change this line too much,
979 people who read your message will have to change their Gnus
980 configuration. See the variable `gnus-cite-attribution-suffix'."
982 :link '(custom-manual "(message)Insertion Variables")
983 :group 'message-insertion)
986 (defcustom message-yank-prefix "> "
987 "*Prefix inserted on the lines of yanked messages.
988 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
989 See also `message-yank-cited-prefix'."
991 :link '(custom-manual "(message)Insertion Variables")
992 :group 'message-insertion)
994 (defcustom message-yank-add-new-references t
995 "Non-nil means new IDs will be added to \"References\" field when an
996 article is yanked by the command `message-yank-original' interactively.
997 If it is a symbol `message-id-only', only an ID from \"Message-ID\" field
998 is used, otherwise IDs extracted from \"References\", \"In-Reply-To\" and
999 \"Message-ID\" fields are used."
1000 :type '(radio (const :tag "Do not add anything" nil)
1001 (const :tag "From Message-Id, References and In-Reply-To fields" t)
1002 (const :tag "From only Message-Id field." message-id-only))
1003 :group 'message-insertion)
1005 (defcustom message-list-references-add-position nil
1006 "Integer value means position for adding to \"References\" field when
1007 an article is yanked by the command `message-yank-original' interactively."
1008 :type '(radio (const :tag "Add to last" nil)
1009 (integer :tag "Position from last ID"))
1010 :group 'message-insertion)
1012 (defcustom message-yank-cited-prefix ">"
1013 "*Prefix inserted on cited or empty lines of yanked messages.
1014 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1015 See also `message-yank-prefix'."
1017 :link '(custom-manual "(message)Insertion Variables")
1018 :group 'message-insertion)
1020 (defcustom message-indentation-spaces 3
1021 "*Number of spaces to insert at the beginning of each cited line.
1022 Used by `message-yank-original' via `message-yank-cite'."
1023 :group 'message-insertion
1024 :link '(custom-manual "(message)Insertion Variables")
1028 (defcustom message-cite-function 'message-cite-original
1029 "*Function for citing an original message.
1030 Predefined functions include `message-cite-original' and
1031 `message-cite-original-without-signature'.
1032 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
1033 :type '(radio (function-item message-cite-original)
1034 (function-item message-cite-original-without-signature)
1035 (function-item mu-cite-original)
1036 (function-item sc-cite-original)
1037 (function :tag "Other"))
1038 :link '(custom-manual "(message)Insertion Variables")
1039 :group 'message-insertion)
1042 (defcustom message-suspend-font-lock-when-citing nil
1043 "Non-nil means suspend font-lock'ing while citing an original message.
1044 Some lazy demand-driven fontification tools (or Emacs itself) have a
1045 bug that they often miss a buffer to be fontified. It will mostly
1046 occur when Emacs prompts user for any inputs in the minibuffer.
1047 Setting this option to non-nil may help you to avoid unpleasant errors
1048 even if it is an add-hoc expedient."
1050 :group 'message-insertion)
1053 (defcustom message-indent-citation-function 'message-indent-citation
1054 "*Function for modifying a citation just inserted in the mail buffer.
1055 This can also be a list of functions. Each function can find the
1056 citation between (point) and (mark t). And each function should leave
1057 point and mark around the citation text as modified."
1059 :link '(custom-manual "(message)Insertion Variables")
1060 :group 'message-insertion)
1063 (defcustom message-signature t
1064 "*String to be inserted at the end of the message buffer.
1065 If t, the `message-signature-file' file will be inserted instead.
1066 If a function, the result from the function will be used instead.
1067 If a form, the result from the form will be used instead."
1069 :link '(custom-manual "(message)Insertion Variables")
1070 :group 'message-insertion)
1073 (defcustom message-signature-file "~/.signature"
1074 "*Name of file containing the text inserted at end of message buffer.
1075 Ignored if the named file doesn't exist.
1076 If nil, don't insert a signature."
1077 :type '(choice file (const :tags "None" nil))
1078 :link '(custom-manual "(message)Insertion Variables")
1079 :group 'message-insertion)
1082 (defcustom message-signature-insert-empty-line t
1083 "*If non-nil, insert an empty line before the signature separator."
1085 :link '(custom-manual "(message)Insertion Variables")
1086 :group 'message-insertion)
1088 (defcustom message-distribution-function nil
1089 "*Function called to return a Distribution header."
1090 :group 'message-news
1091 :group 'message-headers
1092 :link '(custom-manual "(message)News Headers")
1093 :type '(choice function (const nil)))
1095 (defcustom message-expires 14
1096 "Number of days before your article expires."
1097 :group 'message-news
1098 :group 'message-headers
1099 :link '(custom-manual "(message)News Headers")
1102 (defcustom message-user-path nil
1103 "If nil, use the NNTP server name in the Path header.
1104 If stringp, use this; if non-nil, use no host name (user name only)."
1105 :group 'message-news
1106 :group 'message-headers
1107 :link '(custom-manual "(message)News Headers")
1108 :type '(choice (const :tag "nntp" nil)
1109 (string :tag "name")
1110 (sexp :tag "none" :format "%t" t)))
1112 (defvar message-reply-buffer nil)
1113 (defvar message-reply-headers nil
1114 "The headers of the current replied article.
1115 It is a vector of the following headers:
1116 \[number subject from date id references chars lines xref extra].")
1117 (defvar message-sent-message-via nil)
1118 (defvar message-checksum nil)
1119 (defvar message-send-actions nil
1120 "A list of actions to be performed upon successful sending of a message.")
1121 (defvar message-exit-actions nil
1122 "A list of actions to be performed upon exiting after sending a message.")
1123 (defvar message-kill-actions nil
1124 "A list of actions to be performed before killing a message buffer.")
1125 (defvar message-postpone-actions nil
1126 "A list of actions to be performed after postponing a message.")
1127 (defvar message-original-frame nil)
1128 (defvar message-parameter-alist nil)
1129 (defvar message-startup-parameter-alist nil)
1131 (define-widget 'message-header-lines 'text
1132 "All header lines must be LFD terminated."
1133 :format "%{%t%}:%n%v"
1134 :valid-regexp "^\\'"
1135 :error "All header lines must be newline terminated")
1137 (defcustom message-default-headers ""
1138 "*A string containing header lines to be inserted in outgoing messages.
1139 It is inserted before you edit the message, so you can edit or delete
1141 :group 'message-headers
1142 :link '(custom-manual "(message)Message Headers")
1143 :type 'message-header-lines)
1145 (defcustom message-default-mail-headers ""
1146 "*A string of header lines to be inserted in outgoing mails."
1147 :group 'message-headers
1148 :group 'message-mail
1149 :link '(custom-manual "(message)Mail Headers")
1150 :type 'message-header-lines)
1152 (defcustom message-default-news-headers ""
1153 "*A string of header lines to be inserted in outgoing news articles."
1154 :group 'message-headers
1155 :group 'message-news
1156 :link '(custom-manual "(message)News Headers")
1157 :type 'message-header-lines)
1159 ;; Note: could use /usr/ucb/mail instead of sendmail;
1160 ;; options -t, and -v if not interactive.
1161 (defcustom message-mailer-swallows-blank-line
1162 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1163 system-configuration)
1164 (file-readable-p "/etc/sendmail.cf")
1165 (let ((buffer (get-buffer-create " *temp*")))
1169 (insert-file-contents "/etc/sendmail.cf")
1170 (goto-char (point-min))
1171 (let ((case-fold-search nil))
1172 (re-search-forward "^OR\\>" nil t)))
1173 (kill-buffer buffer))))
1174 ;; According to RFC822, "The field-name must be composed of printable
1175 ;; ASCII characters (i. e., characters that have decimal values between
1176 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1178 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1179 "*Set this non-nil if the system's mailer runs the header and body together.
1180 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1181 The value should be an expression to test whether the problem will
1183 :group 'message-sending
1184 :link '(custom-manual "(message)Mail Variables")
1187 ;;; XXX: This symbol is overloaded! See below.
1188 (defvar message-user-agent nil
1189 "String of the form of PRODUCT/VERSION. Used for User-Agent header field.")
1192 (define-mail-user-agent 'message-user-agent
1193 'message-mail 'message-send-and-exit
1194 'message-kill-buffer 'message-send-hook)
1196 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
1197 "If non-nil, delete the deletable headers before feeding to mh.")
1199 (defvar message-send-method-alist
1200 '((news message-news-p message-send-via-news)
1201 (mail message-mail-p message-send-via-mail))
1202 "Alist of ways to send outgoing messages.
1203 Each element has the form
1205 \(TYPE PREDICATE FUNCTION)
1207 where TYPE is a symbol that names the method; PREDICATE is a function
1208 called without any parameters to determine whether the message is
1209 a message of type TYPE; and FUNCTION is a function to be called if
1210 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1213 (defcustom message-mail-alias-type 'abbrev
1214 "*What alias expansion type to use in Message buffers.
1215 The default is `abbrev', which uses mailabbrev. nil switches
1218 :link '(custom-manual "(message)Mail Aliases")
1219 :type '(choice (const :tag "Use Mailabbrev" abbrev)
1220 (const :tag "No expansion" nil)))
1222 (defcustom message-auto-save-directory
1223 (file-name-as-directory (nnheader-concat message-directory "drafts"))
1224 "*Directory where Message auto-saves buffers if Gnus isn't running.
1225 If nil, Message won't auto-save."
1226 :group 'message-buffers
1227 :link '(custom-manual "(message)Various Message Variables")
1228 :type '(choice directory (const :tag "Don't auto-save" nil)))
1230 (defcustom message-default-charset
1231 (and (featurep 'xemacs) (not (featurep 'mule)) 'iso-8859-1)
1232 "Default charset used in non-MULE XEmacsen."
1235 :link '(custom-manual "(message)Various Message Variables")
1238 (defcustom message-dont-reply-to-names
1239 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
1240 "*A regexp specifying addresses to prune when doing wide replies.
1241 A value of nil means exclude your own user name only."
1244 :link '(custom-manual "(message)Wide Reply")
1245 :type '(choice (const :tag "Yourself" nil)
1248 (defvar message-shoot-gnksa-feet nil
1249 "*A list of GNKSA feet you are allowed to shoot.
1250 Gnus gives you all the opportunity you could possibly want for
1251 shooting yourself in the foot. Also, Gnus allows you to shoot the
1252 feet of Good Net-Keeping Seal of Approval. The following are foot
1254 `empty-article' Allow you to post an empty article;
1255 `quoted-text-only' Allow you to post quoted text only;
1256 `multiple-copies' Allow you to post multiple copies;
1257 `cancel-messages' Allow you to cancel or supersede messages from
1258 your other email addresses.")
1260 (defsubst message-gnksa-enable-p (feature)
1261 (or (not (listp message-shoot-gnksa-feet))
1262 (memq feature message-shoot-gnksa-feet)))
1264 (defcustom message-hidden-headers nil
1265 "Regexp of headers to be hidden when composing new messages.
1266 This can also be a list of regexps to match headers. Or a list
1267 starting with `not' and followed by regexps."
1269 :link '(custom-manual "(message)Message Headers")
1270 :type '(repeat regexp))
1272 ;;; Internal variables.
1273 ;;; Well, not really internal.
1275 (defvar message-mode-syntax-table
1276 (let ((table (copy-syntax-table text-mode-syntax-table)))
1277 (modify-syntax-entry ?% ". " table)
1278 (modify-syntax-entry ?> ". " table)
1279 (modify-syntax-entry ?< ". " table)
1281 "Syntax table used while in Message mode.")
1283 (defface message-header-to-face
1286 (:foreground "green2" :bold t))
1289 (:foreground "MidnightBlue" :bold t))
1291 (:bold t :italic t)))
1292 "Face used for displaying From headers."
1293 :group 'message-faces)
1295 (defface message-header-cc-face
1298 (:foreground "green4" :bold t))
1301 (:foreground "MidnightBlue"))
1304 "Face used for displaying Cc headers."
1305 :group 'message-faces)
1307 (defface message-header-subject-face
1310 (:foreground "green3"))
1313 (:foreground "navy blue" :bold t))
1316 "Face used for displaying subject headers."
1317 :group 'message-faces)
1319 (defface message-header-newsgroups-face
1322 (:foreground "yellow" :bold t :italic t))
1325 (:foreground "blue4" :bold t :italic t))
1327 (:bold t :italic t)))
1328 "Face used for displaying newsgroups headers."
1329 :group 'message-faces)
1331 (defface message-header-other-face
1334 (:foreground "#b00000"))
1337 (:foreground "steel blue"))
1339 (:bold t :italic t)))
1340 "Face used for displaying newsgroups headers."
1341 :group 'message-faces)
1343 (defface message-header-name-face
1346 (:foreground "DarkGreen"))
1349 (:foreground "cornflower blue"))
1352 "Face used for displaying header names."
1353 :group 'message-faces)
1355 (defface message-header-xheader-face
1358 (:foreground "blue"))
1361 (:foreground "blue"))
1364 "Face used for displaying X-Header headers."
1365 :group 'message-faces)
1367 (defface message-separator-face
1370 (:foreground "blue3"))
1373 (:foreground "brown"))
1376 "Face used for displaying the separator."
1377 :group 'message-faces)
1379 (defface message-cited-text-face
1382 (:foreground "red"))
1385 (:foreground "red"))
1388 "Face used for displaying cited text names."
1389 :group 'message-faces)
1391 (defface message-mml-face
1394 (:foreground "ForestGreen"))
1397 (:foreground "ForestGreen"))
1400 "Face used for displaying MML."
1401 :group 'message-faces)
1403 (defun message-font-lock-make-header-matcher (regexp)
1406 (let ((start (point)))
1409 (goto-char (point-min))
1410 (if (re-search-forward
1411 (concat "^" (regexp-quote mail-header-separator) "$")
1413 (setq limit (min limit (match-beginning 0))))
1415 (and (< start limit)
1416 (re-search-forward ,regexp limit t))))))
1417 (if (featurep 'bytecomp)
1421 (defvar message-font-lock-keywords
1422 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1423 `((,(message-font-lock-make-header-matcher
1424 (concat "^\\([Tt]o:\\)" content))
1425 (1 'message-header-name-face)
1426 (2 'message-header-to-face nil t))
1427 (,(message-font-lock-make-header-matcher
1428 (concat "^\\([GBF]?[Cc][Cc]:\\|[Rr]eply-[Tt]o:\\|"
1429 "[Mm]ail-[Cc]opies-[Tt]o:\\|"
1430 "[Mm]ail-[Rr]eply-[Tt]o:\\|"
1431 "[Mm]ail-[Ff]ollowup-[Tt]o:\\)" content))
1432 (1 'message-header-name-face)
1433 (2 'message-header-cc-face nil t))
1434 (,(message-font-lock-make-header-matcher
1435 (concat "^\\([Ss]ubject:\\)" content))
1436 (1 'message-header-name-face)
1437 (2 'message-header-subject-face nil t))
1438 (,(message-font-lock-make-header-matcher
1439 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content))
1440 (1 'message-header-name-face)
1441 (2 'message-header-newsgroups-face nil t))
1442 (,(message-font-lock-make-header-matcher
1443 (concat "^\\([A-Z][^: \n\t]+:\\)" content))
1444 (1 'message-header-name-face)
1445 (2 'message-header-other-face nil t))
1446 (,(message-font-lock-make-header-matcher
1447 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content))
1448 (1 'message-header-name-face)
1449 (2 'message-header-name-face))
1450 ,@(if (and mail-header-separator
1451 (not (equal mail-header-separator "")))
1452 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1453 1 'message-separator-face))
1456 (re-search-forward (concat "^\\("
1457 message-cite-prefix-regexp
1460 (0 'message-cited-text-face))
1461 (,mime-edit-tag-regexp
1462 (0 'message-mml-face))))
1463 "Additional expressions to highlight in Message mode.")
1465 ;; XEmacs does it like this. For Emacs, we have to set the
1466 ;; `font-lock-defaults' buffer-local variable.
1467 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
1469 (defvar message-face-alist
1470 '((bold . bold-region)
1471 (underline . underline-region)
1472 (default . (lambda (b e)
1474 (ununderline-region b e))))
1475 "Alist of mail and news faces for facemenu.
1476 The cdr of each entry is a function for applying the face to a region.")
1478 (defcustom message-send-hook nil
1479 "Hook run before sending messages.
1480 This hook is run quite early when sending."
1481 :group 'message-various
1482 :options '(ispell-message)
1483 :link '(custom-manual "(message)Various Message Variables")
1486 (defcustom message-send-mail-hook nil
1487 "Hook run before sending mail messages.
1488 This hook is run very late -- just before the message is sent as
1490 :group 'message-various
1491 :link '(custom-manual "(message)Various Message Variables")
1494 (defcustom message-send-news-hook nil
1495 "Hook run before sending news messages.
1496 This hook is run very late -- just before the message is sent as
1498 :group 'message-various
1499 :link '(custom-manual "(message)Various Message Variables")
1502 (defcustom message-sent-hook nil
1503 "Hook run after sending messages."
1504 :group 'message-various
1507 (defcustom message-use-multi-frames nil
1508 "Make new frame when sending messages."
1509 :group 'message-frames
1512 (defcustom message-delete-frame-on-exit nil
1513 "Delete frame after sending messages."
1514 :group 'message-frames
1515 :type '(choice (const :tag "off" nil)
1516 (const :tag "always" t)
1517 (const :tag "ask" ask)))
1519 (defvar message-draft-coding-system
1520 nnheader-auto-save-coding-system
1521 "*Coding system to compose mail.
1522 If you'd like to make it possible to share draft files between XEmacs
1523 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1524 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1526 (defcustom message-send-mail-partially-limit 1000000
1527 "The limitation of messages sent as message/partial.
1528 The lower bound of message size in characters, beyond which the message
1529 should be sent in several parts. If it is nil, the size is unlimited."
1531 :group 'message-buffers
1532 :link '(custom-manual "(message)Mail Variables")
1533 :type '(choice (const :tag "unlimited" nil)
1536 (defcustom message-alternative-emails nil
1537 "A regexp to match the alternative email addresses.
1538 The first matched address (not primary one) is used in the From field."
1539 :group 'message-headers
1540 :link '(custom-manual "(message)Message Headers")
1541 :type '(choice (const :tag "Always use primary" nil)
1544 (defcustom message-hierarchical-addresses nil
1545 "A list of hierarchical mail address definitions.
1547 Inside each entry, the first address is the \"top\" address, and
1548 subsequent addresses are subaddresses; this is used to indicate that
1549 mail sent to the first address will automatically be delivered to the
1550 subaddresses. So if the first address appears in the recipient list
1551 for a message, the subaddresses will be removed (if present) before
1552 the mail is sent. All addresses in this structure should be
1554 :group 'message-headers
1555 :type '(repeat (repeat string)))
1557 (defcustom message-mail-user-agent nil
1558 "Like `mail-user-agent'.
1559 Except if it is nil, use Gnus native MUA; if it is t, use
1561 :type '(radio (const :tag "Gnus native"
1564 (const :tag "`mail-user-agent'"
1567 (function-item :tag "Default Emacs mail"
1569 sendmail-user-agent)
1570 (function-item :tag "Emacs interface to MH"
1573 (function :tag "Other"))
1577 (defcustom message-wide-reply-confirm-recipients nil
1578 "Whether to confirm a wide reply to multiple email recipients.
1579 If this variable is nil, don't ask whether to reply to all recipients.
1580 If this variable is non-nil, pose the question \"Reply to all
1581 recipients?\" before a wide reply to multiple recipients. If the user
1582 answers yes, reply to all recipients as usual. If the user answers
1583 no, only reply back to the author."
1585 :group 'message-headers
1586 :link '(custom-manual "(message)Wide Reply")
1589 (defcustom message-user-fqdn nil
1590 "*Domain part of Messsage-Ids."
1591 :group 'message-headers
1592 :link '(custom-manual "(message)News Headers")
1593 :type '(radio (const :format "%v " nil)
1594 (string :format "FQDN: %v\n" :size 0)))
1596 (defcustom message-use-idna (and (condition-case nil (require 'idna)
1598 (mm-coding-system-p 'utf-8)
1599 (executable-find idna-program)
1601 "Whether to encode non-ASCII in domain names into ASCII according to IDNA."
1602 :group 'message-headers
1603 :link '(custom-manual "(message)IDNA")
1604 :type '(choice (const :tag "Ask" ask)
1605 (const :tag "Never" nil)
1606 (const :tag "Always" t)))
1608 ;;; Internal variables.
1610 (defvar message-sending-message "Sending...")
1611 (defvar message-buffer-list nil)
1612 (defvar message-this-is-news nil)
1613 (defvar message-this-is-mail nil)
1614 (defvar message-draft-article nil)
1615 (defvar message-mime-part nil)
1616 (defvar message-posting-charset nil)
1617 (defvar message-inserted-headers nil)
1619 ;; Byte-compiler warning
1621 (defvar gnus-active-hashtb)
1622 (defvar gnus-read-active-file))
1624 ;;; Regexp matching the delimiter of messages in UNIX mail format
1625 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1626 ;;; of rmail.el's rmail-unix-mail-delimiter.
1627 (defvar message-unix-mail-delimiter
1628 (let ((time-zone-regexp
1629 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1630 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1636 ;; Many things can happen to an RFC 822 mailbox before it is put into
1637 ;; a `From' line. The leading phrase can be stripped, e.g.
1638 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1639 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1640 ;; can be removed, e.g.
1641 ;; From: joe@y.z (Joe K
1643 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1646 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1647 ;; The mailbox can be removed or be replaced by white space, e.g.
1648 ;; From: "Joe User"{space}{tab}
1650 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1651 ;; where {space} and {tab} represent the Ascii space and tab characters.
1652 ;; We want to match the results of any of these manglings.
1653 ;; The following regexp rejects names whose first characters are
1654 ;; obviously bogus, but after that anything goes.
1655 "\\([^\0-\b\n-\r\^?].*\\)?"
1657 ;; The time the message was sent.
1658 "\\([^\0-\r \^?]+\\) +" ; day of the week
1659 "\\([^\0-\r \^?]+\\) +" ; month
1660 "\\([0-3]?[0-9]\\) +" ; day of month
1661 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1663 ;; Perhaps a time zone, specified by an abbreviation, or by a
1668 " \\([0-9][0-9]+\\) *"
1670 ;; On some systems the time zone can appear after the year, too.
1674 "\\(remote from .*\\)?"
1677 "Regexp matching the delimiter of messages in UNIX mail format.")
1679 (defvar message-unsent-separator
1680 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1681 "^ *---+ +Returned message +---+ *$\\|"
1682 "^Start of returned message$\\|"
1683 "^ *---+ +Original message +---+ *$\\|"
1684 "^ *--+ +begin message +--+ *$\\|"
1685 "^ *---+ +Original message follows +---+ *$\\|"
1686 "^ *---+ +Undelivered message follows +---+ *$\\|"
1687 "^|? *---+ +Message text follows: +---+ *|?$")
1688 "A regexp that matches the separator before the text of a failed message.")
1690 (defvar message-field-fillers
1691 '((To message-fill-field-address)
1692 (Cc message-fill-field-address)
1693 (From message-fill-field-address))
1694 "Alist of header names/filler functions.")
1696 (defvar message-header-format-alist
1710 (References . message-shorten-references)
1712 "Alist used for formatting headers.")
1714 (defvar message-options nil
1715 "Some saved answers when sending message.")
1717 (defvar message-send-mail-real-function nil
1718 "Internal send mail function.")
1720 (defvar message-bogus-system-names "^localhost\\."
1721 "The regexp of bogus system names.")
1723 (defcustom message-valid-fqdn-regexp
1724 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1726 "\\([a-z][a-z]" ;; two letter country TDLs
1727 "\\|biz\\|com\\|edu\\|gov\\|int\\|mil\\|net\\|org"
1728 "\\|aero\\|coop\\|info\\|name\\|museum"
1729 "\\|arpa\\|pro\\|uucp\\|bitnet\\|bofh" ;; old style?
1731 "Regular expression that matches a valid FQDN."
1732 ;; see also: gnus-button-valid-fqdn-regexp
1733 :group 'message-headers
1737 (autoload 'gnus-alive-p "gnus-util")
1738 (autoload 'gnus-delay-article "gnus-delay")
1739 (autoload 'gnus-extract-address-components "gnus-util")
1740 (autoload 'gnus-find-method-for-group "gnus")
1741 (autoload 'gnus-group-decoded-name "gnus-group")
1742 (autoload 'gnus-group-name-charset "gnus-group")
1743 (autoload 'gnus-group-name-decode "gnus-group")
1744 (autoload 'gnus-groups-from-server "gnus")
1745 (autoload 'gnus-make-local-hook "gnus-util")
1746 (autoload 'gnus-open-server "gnus-int")
1747 (autoload 'gnus-output-to-mail "gnus-util")
1748 (autoload 'gnus-output-to-rmail "gnus-util")
1749 (autoload 'gnus-request-post "gnus-int")
1750 (autoload 'gnus-server-string "gnus")
1751 (autoload 'idna-to-ascii "idna")
1752 (autoload 'message-setup-toolbar "messagexmas")
1753 (autoload 'mh-new-draft-name "mh-comp")
1754 (autoload 'mh-send-letter "mh-comp")
1755 (autoload 'mu-cite-original "mu-cite")
1756 (autoload 'nndraft-request-associate-buffer "nndraft")
1757 (autoload 'nndraft-request-expire-articles "nndraft")
1758 (autoload 'nnvirtual-find-group-art "nnvirtual")
1759 (autoload 'rmail-dont-reply-to "mail-utils")
1760 (autoload 'rmail-msg-is-pruned "rmail")
1761 (autoload 'rmail-msg-restore-non-pruned-header "rmail")
1762 (autoload 'rmail-output "rmailout"))
1765 (autoload 'sha1 "sha1-el"))
1770 ;;; Utility functions.
1772 (defun message-eval-parameter (parameter)
1774 (if (symbolp parameter)
1775 (if (functionp parameter)
1781 (defsubst message-get-parameter (key &optional alist)
1783 (setq alist message-parameter-alist))
1784 (cdr (assq key alist)))
1786 (defmacro message-get-parameter-with-eval (key &optional alist)
1787 `(message-eval-parameter (message-get-parameter ,key ,alist)))
1789 (defmacro message-y-or-n-p (question show &rest text)
1790 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1791 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1793 (defmacro message-delete-line (&optional n)
1794 "Delete the current line (and the next N lines)."
1795 `(delete-region (progn (beginning-of-line) (point))
1796 (progn (forward-line ,(or n 1)) (point))))
1798 (defun message-mark-active-p ()
1799 "Non-nil means the mark and region are currently active in this buffer."
1802 (defun message-unquote-tokens (elems)
1803 "Remove double quotes (\") from strings in list ELEMS."
1804 (mapcar (lambda (item)
1805 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1806 (setq item (concat (match-string 1 item)
1807 (match-string 2 item))))
1811 (defun message-tokenize-header (header &optional separator)
1812 "Split HEADER into a list of header elements.
1813 SEPARATOR is a string of characters to be used as separators. \",\"
1814 is used by default."
1817 (let ((regexp (format "[%s]+" (or separator ",")))
1822 (set-buffer-multibyte t)
1824 (goto-char (point-min))
1829 (cond ((and (> (point) beg)
1831 (and (looking-at regexp)
1834 (push (buffer-substring beg (point)) elems)
1835 (setq beg (match-end 0)))
1836 ((eq (char-after) ?\")
1837 (setq quoted (not quoted)))
1838 ((and (eq (char-after) ?\()
1841 ((and (eq (char-after) ?\))
1844 (nreverse elems)))))
1846 (defun message-mail-file-mbox-p (file)
1847 "Say whether FILE looks like a Unix mbox file."
1848 (when (and (file-exists-p file)
1849 (file-readable-p file)
1850 (file-regular-p file))
1852 (nnheader-insert-file-contents file)
1853 (goto-char (point-min))
1854 (looking-at message-unix-mail-delimiter))))
1856 (defun message-fetch-field (header &optional not-all)
1857 "The same as `mail-fetch-field', only remove all newlines.
1858 The buffer is expected to be narrowed to just the header of the message;
1859 see `message-narrow-to-headers-or-head'."
1860 (let* ((inhibit-point-motion-hooks t)
1861 (value (mail-fetch-field header nil (not not-all))))
1863 (while (string-match "\n[\t ]+" value)
1864 (setq value (replace-match " " t t value)))
1865 (set-text-properties 0 (length value) nil value)
1868 (defun message-field-value (header &optional not-all)
1869 "The same as `message-fetch-field', only narrow to the headers first."
1872 (message-narrow-to-headers-or-head)
1873 (message-fetch-field header not-all))))
1875 (defun message-narrow-to-field ()
1876 "Narrow the buffer to the header on the current line."
1878 (while (looking-at "[ \t]")
1884 (if (re-search-forward "^[^ \n\t]" nil t)
1887 (goto-char (point-min)))
1889 (defun message-add-header (&rest headers)
1890 "Add the HEADERS to the message header, skipping those already present."
1893 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1894 (error "Invalid header `%s'" (car headers)))
1895 (setq hclean (match-string 1 (car headers)))
1897 (message-narrow-to-headers)
1898 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1899 (goto-char (point-max))
1900 (if (string-match "\n$" (car headers))
1901 (insert (car headers))
1902 (insert (car headers) ?\n)))))
1903 (setq headers (cdr headers))))
1905 (defmacro message-with-reply-buffer (&rest forms)
1906 "Evaluate FORMS in the reply buffer, if it exists."
1907 `(let ((buffer (message-eval-parameter message-reply-buffer)))
1909 (buffer-name buffer))
1914 (put 'message-with-reply-buffer 'lisp-indent-function 0)
1915 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
1917 (defun message-fetch-reply-field (header)
1918 "Fetch field HEADER from the message we're replying to."
1919 (message-with-reply-buffer
1921 (mail-narrow-to-head)
1922 (message-fetch-field header))))
1924 (defun message-strip-list-identifiers (subject)
1925 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1926 (require 'gnus-sum) ; for gnus-list-identifiers
1927 (let ((regexp (if (stringp gnus-list-identifiers)
1928 gnus-list-identifiers
1929 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1930 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1931 " *\\)\\)+\\(Re: +\\)?\\)") subject)
1932 (concat (substring subject 0 (match-beginning 1))
1933 (or (match-string 3 subject)
1934 (match-string 5 subject))
1939 (defun message-strip-subject-re (subject)
1940 "Remove \"Re:\" from subject lines in string SUBJECT."
1941 (if (string-match message-subject-re-regexp subject)
1942 (substring subject (match-end 0))
1945 ;;; Start of functions adopted from `message-utils.el'.
1947 (defun message-strip-subject-trailing-was (subject)
1948 "Remove trailing \"(Was: <old subject>)\" from SUBJECT lines.
1949 Leading \"Re: \" is not stripped by this function. Use the function
1950 `message-strip-subject-re' for this."
1951 (let* ((query message-subject-trailing-was-query)
1956 message-subject-trailing-was-ask-regexp
1957 message-subject-trailing-was-regexp)
1960 (setq new (substring subject 0 (match-beginning 0))))
1961 (if (or (not found) (eq query nil))
1964 (if (message-y-or-n-p
1965 "Strip `(was: <old subject>)' in subject? " t
1967 "Strip `(was: <old subject>)' in subject "
1968 "and use the new one instead?\n\n"
1969 "Current subject is: \""
1971 "New subject would be: \""
1973 "See the variable `message-subject-trailing-was-query' "
1974 "to get rid of this query."
1979 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
1982 (defun message-change-subject (new-subject)
1983 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
1984 ;; <URL:http://www.landfield.com/usefor/drafts/draft-ietf-usefor-useage--1.02.unpaged>
1987 (read-from-minibuffer "New subject: ")))
1988 (cond ((and (not (or (null new-subject) ; new subject not empty
1989 (zerop (string-width new-subject))
1990 (string-match "^[ \t]*$" new-subject))))
1994 (message-narrow-to-headers)
1995 (message-fetch-field "Subject"))))
1996 (cond ((not old-subject)
1997 (error "No current subject"))
2000 (regexp-quote new-subject)
2002 old-subject)) ; yes, it really is a new subject
2003 ;; delete eventual Re: prefix
2005 (message-strip-subject-re old-subject))
2006 (message-goto-subject)
2007 (message-delete-line)
2008 (insert (concat "Subject: "
2011 old-subject ")\n")))))))))
2014 (defun message-mark-inserted-region (beg end)
2015 "Mark some region in the current article with enclosing tags.
2016 See `message-mark-insert-begin' and `message-mark-insert-end'."
2019 ;; add to the end of the region first, otherwise end would be invalid
2021 (insert message-mark-insert-end)
2023 (insert message-mark-insert-begin)))
2026 (defun message-mark-insert-file (file)
2027 "Insert FILE at point, marking it with enclosing tags.
2028 See `message-mark-insert-begin' and `message-mark-insert-end'."
2029 (interactive "fFile to insert: ")
2030 ;; reverse insertion to get correct result.
2032 (insert message-mark-insert-end)
2034 (insert-file-contents file)
2036 (insert message-mark-insert-begin)))
2039 (defun message-add-archive-header ()
2040 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
2041 The note can be customized using `message-archive-note'. When called with a
2042 prefix argument, ask for a text to insert. If you don't want the note in the
2043 body, set `message-archive-note' to nil."
2045 (if current-prefix-arg
2046 (setq message-archive-note
2047 (read-from-minibuffer "Reason for No-Archive: "
2048 (cons message-archive-note 0))))
2050 (if (message-goto-signature)
2051 (re-search-backward message-signature-separator))
2052 (when message-archive-note
2053 (insert message-archive-note)
2055 (message-add-header message-archive-header)
2056 (message-sort-headers)))
2059 (defun message-cross-post-followup-to-header (target-group)
2060 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
2061 With prefix-argument just set Follow-Up, don't cross-post."
2063 (list ; Completion based on Gnus
2064 (completing-read "Followup To: "
2065 (if (boundp 'gnus-newsrc-alist)
2067 nil nil '("poster" . 0)
2068 (if (boundp 'gnus-group-history)
2069 'gnus-group-history))))
2070 (message-remove-header "Follow[Uu]p-[Tt]o" t)
2071 (message-goto-newsgroups)
2073 ;; if we already did a crosspost before, kill old target
2074 (if (and message-cross-post-old-target
2076 (regexp-quote (concat "," message-cross-post-old-target))
2079 ;; unless (followup is to poster or user explicitly asked not
2080 ;; to cross-post, or target-group is already in Newsgroups)
2081 ;; add target-group to Newsgroups line.
2083 ;; def: cross-post, req:no
2084 (and message-cross-post-default (not current-prefix-arg))
2085 ;; def: no-cross-post, req:yes
2086 (and (not message-cross-post-default) current-prefix-arg))
2087 (not (string-match "poster" target-group))
2088 (not (string-match (regexp-quote target-group)
2089 (message-fetch-field "Newsgroups"))))
2091 (insert (concat "," target-group))))
2092 (end-of-line) ; ensure Followup: comes after Newsgroups:
2093 ;; unless new followup would be identical to Newsgroups line
2094 ;; make a new Followup-To line
2095 (if (not (string-match (concat "^[ \t]*"
2098 (message-fetch-field "Newsgroups")))
2099 (insert (concat "\nFollowup-To: " target-group)))
2100 (setq message-cross-post-old-target target-group))
2103 (defun message-cross-post-insert-note (target-group cross-post in-old
2105 "Insert a in message body note about a set Followup or Crosspost.
2106 If there have been previous notes, delete them. TARGET-GROUP specifies the
2107 group to Followup-To. When CROSS-POST is t, insert note about
2108 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
2109 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
2110 been made to before the user asked for a Crosspost."
2111 ;; start scanning body for previous uses
2112 (message-goto-signature)
2113 (let ((head (re-search-backward
2114 (concat "^" mail-header-separator)
2115 nil t))) ; just search in body
2116 (message-goto-signature)
2117 (while (re-search-backward
2118 (concat "^" (regexp-quote message-cross-post-note) ".*")
2120 (message-delete-line))
2121 (message-goto-signature)
2122 (while (re-search-backward
2123 (concat "^" (regexp-quote message-followup-to-note) ".*")
2125 (message-delete-line))
2127 (if (message-goto-signature)
2128 (re-search-backward message-signature-separator))
2131 (string-match "^[ \t]*poster[ \t]*$" target-group))
2132 (insert (concat message-followup-to-note target-group "\n"))
2133 (insert (concat message-cross-post-note target-group "\n")))))
2136 (defun message-cross-post-followup-to (target-group)
2137 "Crossposts message and set Followup-To to TARGET-GROUP.
2138 With prefix-argument just set Follow-Up, don't cross-post."
2140 (list ; Completion based on Gnus
2141 (completing-read "Followup To: "
2142 (if (boundp 'gnus-newsrc-alist)
2144 nil nil '("poster" . 0)
2145 (if (boundp 'gnus-group-history)
2146 'gnus-group-history))))
2147 (cond ((not (or (null target-group) ; new subject not empty
2148 (zerop (string-width target-group))
2149 (string-match "^[ \t]*$" target-group)))
2151 (let* ((old-groups (message-fetch-field "Newsgroups"))
2152 (in-old (string-match
2153 (regexp-quote target-group)
2154 (or old-groups ""))))
2155 ;; check whether target exactly matches old Newsgroups
2156 (cond ((not old-groups)
2157 (error "No current newsgroup"))
2161 (regexp-quote target-group)
2164 ;; yes, Newsgroups line must change
2165 (message-cross-post-followup-to-header target-group)
2166 ;; insert note whether we do cross-post or followup-to
2167 (funcall message-cross-post-note-function
2169 (if (or (and message-cross-post-default
2170 (not current-prefix-arg))
2171 (and (not message-cross-post-default)
2172 current-prefix-arg)) t)
2173 in-old old-groups))))))))
2175 ;;; Reduce To: to Cc: or Bcc: header
2178 (defun message-reduce-to-to-cc ()
2179 "Replace contents of To: header with contents of Cc: or Bcc: header."
2182 (save-restriction (message-narrow-to-headers)
2183 (message-fetch-field "cc")))
2185 (if (and (not cc-content)
2188 (message-narrow-to-headers)
2189 (message-fetch-field "bcc"))))
2194 (message-delete-line)
2195 (insert (concat "To: " cc-content "\n"))
2197 (message-narrow-to-headers)
2198 (message-remove-header (if bcc
2202 ;;; End of functions adopted from `message-utils.el'.
2204 (defun message-remove-header (header &optional is-regexp first reverse)
2205 "Remove HEADER in the narrowed buffer.
2206 If IS-REGEXP, HEADER is a regular expression.
2207 If FIRST, only remove the first instance of the header.
2208 Return the number of headers removed."
2209 (goto-char (point-min))
2210 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
2212 (case-fold-search t)
2214 (while (and (not (eobp))
2217 (not (looking-at regexp))
2218 (looking-at regexp))
2225 ;; There might be a continuation header, so we have to search
2226 ;; until we find a new non-continuation line.
2229 (if (re-search-forward "^[^ \t]" nil t)
2230 (goto-char (match-beginning 0))
2233 (if (re-search-forward "^[^ \t]" nil t)
2234 (goto-char (match-beginning 0))
2235 (goto-char (point-max)))))
2238 (defun message-remove-first-header (header)
2239 "Remove the first instance of HEADER if there is more than one."
2241 (regexp (concat "^" (regexp-quote header) ":")))
2243 (goto-char (point-min))
2244 (while (re-search-forward regexp nil t)
2247 (message-remove-header header nil t)
2250 (defun message-narrow-to-headers ()
2251 "Narrow the buffer to the head of the message."
2254 (goto-char (point-min))
2255 (if (re-search-forward
2256 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2259 (goto-char (point-min)))
2261 (defun message-narrow-to-head-1 ()
2262 "Like `message-narrow-to-head'. Don't widen."
2264 (goto-char (point-min))
2265 (if (search-forward "\n\n" nil 1)
2268 (goto-char (point-min)))
2270 (defun message-narrow-to-head ()
2271 "Narrow the buffer to the head of the message.
2272 Point is left at the beginning of the narrowed-to region."
2274 (message-narrow-to-head-1))
2276 (defun message-narrow-to-headers-or-head ()
2277 "Narrow the buffer to the head of the message."
2280 (goto-char (point-min))
2283 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2284 (match-beginning 0))
2285 ((search-forward "\n\n" nil t)
2289 (goto-char (point-min)))
2291 (defun message-news-p ()
2292 "Say whether the current buffer contains a news message."
2293 (and (not message-this-is-mail)
2294 (or message-this-is-news
2297 (message-narrow-to-headers)
2298 (and (message-fetch-field "newsgroups")
2299 (not (message-fetch-field "posted-to"))))))))
2301 (defun message-mail-p ()
2302 "Say whether the current buffer contains a mail message."
2303 (and (not message-this-is-news)
2304 (or message-this-is-mail
2307 (message-narrow-to-headers)
2308 (or (message-fetch-field "to")
2309 (message-fetch-field "cc")
2310 (message-fetch-field "bcc")))))))
2312 (defun message-subscribed-p ()
2313 "Say whether we need to insert a MFT header."
2314 (or message-subscribed-regexps
2315 message-subscribed-addresses
2316 message-subscribed-address-file
2317 message-subscribed-address-functions))
2319 (defun message-next-header ()
2320 "Go to the beginning of the next header."
2322 (or (eobp) (forward-char 1))
2323 (not (if (re-search-forward "^[^ \t]" nil t)
2325 (goto-char (point-max)))))
2327 (defun message-sort-headers-1 ()
2328 "Sort the buffer as headers using `message-rank' text props."
2329 (goto-char (point-min))
2332 nil 'message-next-header
2334 (message-next-header)
2338 (or (get-text-property (point) 'message-rank)
2341 (defun message-sort-headers ()
2342 "Sort the headers of the current message according to `message-header-format-alist'."
2346 (let ((max (1+ (length message-header-format-alist)))
2348 (message-narrow-to-headers)
2349 (while (re-search-forward "^[^ \n]+:" nil t)
2351 (match-beginning 0) (1+ (match-beginning 0))
2353 (if (setq rank (length (memq (assq (intern (buffer-substring
2355 (1- (match-end 0))))
2356 message-header-format-alist)
2357 message-header-format-alist)))
2360 (message-sort-headers-1))))
2362 (defun message-kill-address ()
2363 "Kill the address under point."
2365 (let ((start (point)))
2366 (message-skip-to-next-address)
2367 (kill-region start (point))))
2377 (defvar message-mode-map nil)
2379 (unless message-mode-map
2380 (setq message-mode-map (make-keymap))
2381 (set-keymap-parent message-mode-map text-mode-map)
2382 (define-key message-mode-map "\C-c?" 'describe-mode)
2384 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
2385 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
2386 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
2387 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
2388 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
2389 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2390 ;; (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2391 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-mail-reply-to)
2392 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2393 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2394 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2395 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2396 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2397 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2398 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2399 (define-key message-mode-map "\C-c\C-f\C-i"
2400 'message-insert-or-toggle-importance)
2401 (define-key message-mode-map "\C-c\C-f\C-a"
2402 'message-generate-unsubscribed-mail-followup-to)
2404 ;; modify headers (and insert notes in body)
2405 (define-key message-mode-map "\C-c\C-fs" 'message-change-subject)
2407 (define-key message-mode-map "\C-c\C-fx" 'message-cross-post-followup-to)
2408 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2409 (define-key message-mode-map "\C-c\C-ft" 'message-reduce-to-to-cc)
2410 (define-key message-mode-map "\C-c\C-fa" 'message-add-archive-header)
2411 ;; mark inserted text
2412 (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2413 (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2415 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2416 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2417 (define-key message-mode-map "\C-c\C-fc" 'message-goto-mail-copies-to)
2419 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2420 (define-key message-mode-map "\C-c\C-fw" 'message-insert-wide-reply)
2421 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2422 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2424 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2425 (define-key message-mode-map "\C-c\M-n"
2426 'message-insert-disposition-notification-to)
2428 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2429 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2430 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2431 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2432 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2433 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2434 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2435 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2437 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2438 (define-key message-mode-map "\C-c\C-s" 'message-send)
2439 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2440 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2441 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2443 (define-key message-mode-map "\C-c\M-k" 'message-kill-address)
2444 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2445 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2446 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2447 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2448 (define-key message-mode-map [remap split-line] 'message-split-line)
2450 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2451 (define-key message-mode-map "\t" 'message-tab)
2452 (define-key message-mode-map "\M-;" 'comment-region)
2454 (define-key message-mode-map "\C-xk" 'message-mimic-kill-buffer))
2457 message-mode-menu message-mode-map "Message Menu."
2459 ["Yank Original" message-yank-original t]
2460 ["Fill Yanked Message" message-fill-yanked-message t]
2461 ["Insert Signature" message-insert-signature t]
2462 ["Caesar (rot13) Message" message-caesar-buffer-body t]
2463 ["Caesar (rot13) Region" message-caesar-region (message-mark-active-p)]
2464 ["Elide Region" message-elide-region
2465 :active (message-mark-active-p)
2466 ,@(if (featurep 'xemacs) nil
2467 '(:help "Replace text in region with an ellipsis"))]
2468 ["Delete Outside Region" message-delete-not-region
2469 :active (message-mark-active-p)
2470 ,@(if (featurep 'xemacs) nil
2471 '(:help "Delete all quoted text outside region"))]
2472 ["Kill To Signature" message-kill-to-signature t]
2473 ["Newline and Reformat" message-newline-and-reformat t]
2474 ["Rename buffer" message-rename-buffer t]
2475 ["Spellcheck" ispell-message
2476 ,@(if (featurep 'xemacs) '(t)
2477 '(:help "Spellcheck this message"))]
2478 ["Attach file as MIME" mime-edit-insert-file
2479 ,@(if (featurep 'xemacs) '(t)
2480 '(:help "Attach a file at point"))]
2482 ["Insert Region Marked" message-mark-inserted-region
2483 :active (message-mark-active-p)
2484 ,@(if (featurep 'xemacs) nil
2485 '(:help "Mark region with enclosing tags"))]
2486 ["Insert File Marked..." message-mark-insert-file
2487 ,@(if (featurep 'xemacs) '(t)
2488 '(:help "Insert file at point marked with enclosing tags"))]
2490 ["Send Message" message-send-and-exit
2491 ,@(if (featurep 'xemacs) '(t)
2492 '(:help "Send this message"))]
2493 ["Postpone Message" message-dont-send
2494 ,@(if (featurep 'xemacs) '(t)
2495 '(:help "File this draft message and exit"))]
2496 ["Send at Specific Time..." gnus-delay-article
2497 ,@(if (featurep 'xemacs) '(t)
2498 '(:help "Ask, then arrange to send message at that time"))]
2499 ["Kill Message" message-kill-buffer
2500 ,@(if (featurep 'xemacs) '(t)
2501 '(:help "Delete this message without sending"))]))
2504 message-mode-field-menu message-mode-map ""
2506 ["To" message-goto-to t]
2507 ["From" message-goto-from t]
2508 ["Subject" message-goto-subject t]
2509 ["Change subject..." message-change-subject t]
2510 ["Cc" message-goto-cc t]
2511 ["Bcc" message-goto-bcc t]
2512 ["Fcc" message-goto-fcc t]
2513 ["Reply-To" message-goto-reply-to t]
2514 ["Flag As Important" message-insert-importance-high
2515 ,@(if (featurep 'xemacs) '(t)
2516 '(:help "Mark this message as important"))]
2517 ["Flag As Unimportant" message-insert-importance-low
2518 ,@(if (featurep 'xemacs) '(t)
2519 '(:help "Mark this message as unimportant"))]
2521 message-insert-disposition-notification-to
2522 ,@(if (featurep 'xemacs) '(t)
2523 '(:help "Request a receipt notification"))]
2525 ;; (typical) news stuff
2526 ["Summary" message-goto-summary t]
2527 ["Keywords" message-goto-keywords t]
2528 ["Newsgroups" message-goto-newsgroups t]
2529 ["Fetch Newsgroups" message-insert-newsgroups t]
2530 ["Followup-To" message-goto-followup-to t]
2531 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2532 ["Crosspost / Followup-To..." message-cross-post-followup-to t]
2533 ["Distribution" message-goto-distribution t]
2534 ["X-No-Archive:" message-add-archive-header t ]
2536 ;; (typical) mailing-lists stuff
2537 ["Fetch To" message-insert-to
2538 ,@(if (featurep 'xemacs) '(t)
2539 '(:help "Insert a To header that points to the author."))]
2540 ["Fetch To and Cc" message-insert-wide-reply
2541 ,@(if (featurep 'xemacs) '(t)
2543 "Insert To and Cc headers as if you were doing a wide reply."))]
2545 ["Send to list only" message-to-list-only t]
2546 ["Mail-Followup-To" message-goto-mail-followup-to t]
2547 ["Mail-Reply-To" message-goto-mail-reply-to t]
2548 ["Mail-Copies-To" message-goto-mail-copies-to t]
2549 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2550 ,@(if (featurep 'xemacs) '(t)
2551 '(:help "Insert a reasonable `Mail-Followup-To:' header."))]
2552 ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2554 ["Sort Headers" message-sort-headers t]
2555 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t]
2556 ["Goto Body" message-goto-body t]
2557 ["Goto Signature" message-goto-signature t]))
2559 (defvar message-tool-bar-map nil)
2562 (defvar facemenu-add-face-function)
2563 (defvar facemenu-remove-face-function))
2565 ;;; Forbidden properties
2567 ;; We use `after-change-functions' to keep special text properties
2568 ;; that interfer with the normal function of message mode out of the
2571 (defcustom message-strip-special-text-properties t
2572 "Strip special properties from the message buffer.
2574 Emacs has a number of special text properties which can break message
2575 composing in various ways. If this option is set, message will strip
2576 these properties from the message composition buffer. However, some
2577 packages requires these properties to be present in order to work.
2578 If you use one of these packages, turn this option off, and hope the
2579 message composition doesn't break too bad."
2580 :group 'message-various
2581 :link '(custom-manual "(message)Various Message Variables")
2584 (defconst message-forbidden-properties
2585 ;; No reason this should be clutter up customize. We make it a
2586 ;; property list (rather than a list of property symbols), to be
2587 ;; directly useful for `remove-text-properties'.
2588 '(field nil read-only nil invisible nil intangible nil
2589 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2590 insert-behind-hooks nil point-entered nil point-left nil)
2591 ;; Other special properties:
2592 ;; category, face, display: probably doesn't do any harm.
2593 ;; fontified: is used by font-lock.
2594 ;; syntax-table, local-map: I dunno.
2595 ;; We need to add XEmacs names to the list.
2596 "Property list of with properties.forbidden in message buffers.
2597 The values of the properties are ignored, only the property names are used.")
2599 (defun message-tamago-not-in-use-p (pos)
2600 "Return t when tamago version 4 is not in use at the cursor position.
2601 Tamago version 4 is a popular input method for writing Japanese text.
2602 It uses the properties `intangible', `invisible', `modification-hooks'
2603 and `read-only' when translating ascii or kana text to kanji text.
2604 These properties are essential to work, so we should never strip them."
2605 (not (and (boundp 'egg-modefull-mode)
2606 (symbol-value 'egg-modefull-mode)
2607 (or (memq (get-text-property pos 'intangible)
2608 '(its-part-1 its-part-2))
2609 (get-text-property pos 'egg-end)
2610 (get-text-property pos 'egg-lang)
2611 (get-text-property pos 'egg-start)))))
2613 (defun message-strip-forbidden-properties (begin end &optional old-length)
2614 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2615 This function is intended to be called from `after-change-functions'.
2616 See also `message-forbidden-properties'."
2617 (when (and message-strip-special-text-properties
2618 (message-tamago-not-in-use-p begin)
2619 ;; Check whether the invisible MIME part is not inserted.
2620 (not (text-property-any begin end 'mime-edit-invisible t)))
2621 (while (not (= begin end))
2622 (when (not (get-text-property begin 'message-hidden))
2623 (remove-text-properties begin (1+ begin)
2624 message-forbidden-properties))
2628 (define-derived-mode message-mode text-mode "Message"
2629 "Major mode for editing mail and news to be sent.
2630 Like Text Mode but with these additional commands:\\<message-mode-map>
2631 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2632 C-c C-d Postpone sending the message C-c C-k Kill the message
2633 C-c C-f move to a header field (and create it if there isn't):
2634 C-c C-f C-t move to To C-c C-f C-s move to Subject
2635 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2636 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2637 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2638 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2639 C-c C-f C-o move to From (\"Originator\")
2640 C-c C-f C-f move to Followup-To
2641 C-c C-f C-m move to Mail-Followup-To
2642 C-c C-f c move to Mail-Copies-To
2643 C-c C-f C-i cycle through Importance values
2644 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2645 C-c C-f x crossposting with FollowUp-To header and note in body
2646 C-c C-f t replace To: header with contents of Cc: or Bcc:
2647 C-c C-f a Insert X-No-Archive: header and a note in the body
2648 C-c C-t `message-insert-to' (add a To header to a news followup)
2649 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2650 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2651 C-c C-b `message-goto-body' (move to beginning of message text).
2652 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2653 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2654 C-c C-y `message-yank-original' (insert current message, if any).
2655 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2656 C-c C-e `message-elide-region' (elide the text between point and mark).
2657 C-c C-v `message-delete-not-region' (remove the text outside the region).
2658 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2659 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2660 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2661 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2662 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2663 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2664 M-RET `message-newline-and-reformat' (break the line and reformat)."
2665 (setq local-abbrev-table text-mode-abbrev-table)
2666 (set (make-local-variable 'message-reply-buffer) nil)
2667 (set (make-local-variable 'message-inserted-headers) nil)
2668 (set (make-local-variable 'message-send-actions) nil)
2669 (set (make-local-variable 'message-exit-actions) nil)
2670 (set (make-local-variable 'message-kill-actions) nil)
2671 (set (make-local-variable 'message-postpone-actions) nil)
2672 (set (make-local-variable 'message-draft-article) nil)
2673 (setq buffer-offer-save t)
2674 (set (make-local-variable 'facemenu-add-face-function)
2676 (let ((face-fun (cdr (assq face message-face-alist))))
2678 (funcall face-fun (point) end)
2679 (error "Face %s not configured for %s mode" face mode-name)))
2681 (set (make-local-variable 'facemenu-remove-face-function) t)
2682 (set (make-local-variable 'message-reply-headers) nil)
2683 (make-local-variable 'message-user-agent)
2684 (make-local-variable 'message-post-method)
2685 (set (make-local-variable 'message-sent-message-via) nil)
2686 (set (make-local-variable 'message-checksum) nil)
2687 (make-local-variable 'message-parameter-alist)
2688 (setq message-parameter-alist
2689 (copy-sequence message-startup-parameter-alist))
2690 (message-setup-fill-variables)
2691 ;; Allow using comment commands to add/remove quoting.
2692 (set (make-local-variable 'comment-start) message-yank-prefix)
2693 (if (featurep 'xemacs)
2694 (message-setup-toolbar)
2695 (set (make-local-variable 'font-lock-defaults)
2696 '(message-font-lock-keywords t))
2697 (if (boundp 'tool-bar-map)
2698 (set (make-local-variable 'tool-bar-map) (message-tool-bar-map))))
2699 (easy-menu-add message-mode-menu message-mode-map)
2700 (easy-menu-add message-mode-field-menu message-mode-map)
2701 (gnus-make-local-hook 'after-change-functions)
2702 ;; Mmmm... Forbidden properties...
2703 (add-hook 'after-change-functions 'message-strip-forbidden-properties
2705 ;; Allow mail alias things.
2706 (when (eq message-mail-alias-type 'abbrev)
2707 (if (fboundp 'mail-abbrevs-setup)
2708 (mail-abbrevs-setup)
2709 (if (fboundp 'mail-aliases-setup) ; warning avoidance
2710 (mail-aliases-setup))))
2711 (unless buffer-file-name
2712 (message-set-auto-save-file-name))
2713 (set (make-local-variable 'indent-tabs-mode) nil)) ;No tabs for indentation.
2715 (defun message-setup-fill-variables ()
2716 "Setup message fill variables."
2717 (set (make-local-variable 'fill-paragraph-function)
2718 'message-fill-paragraph)
2719 (make-local-variable 'paragraph-separate)
2720 (make-local-variable 'paragraph-start)
2721 (make-local-variable 'adaptive-fill-regexp)
2722 (unless (boundp 'adaptive-fill-first-line-regexp)
2723 (setq adaptive-fill-first-line-regexp nil))
2724 (make-local-variable 'adaptive-fill-first-line-regexp)
2725 (let ((quote-prefix-regexp
2726 ;; User should change message-cite-prefix-regexp if
2727 ;; message-yank-prefix is set to an abnormal value.
2728 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
2729 (setq paragraph-start
2731 (regexp-quote mail-header-separator) "$\\|"
2732 "[ \t]*$\\|" ; blank lines
2733 "-- $\\|" ; signature delimiter
2734 "---+$\\|" ; delimiters for forwarded messages
2735 page-delimiter "$\\|" ; spoiler warnings
2736 ".*wrote:$\\|" ; attribution lines
2737 quote-prefix-regexp "$\\|" ; empty lines in quoted text
2738 mime-edit-tag-regexp)) ; MIME-Edit tags
2739 (setq paragraph-separate paragraph-start)
2740 (setq adaptive-fill-regexp
2741 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
2742 (setq adaptive-fill-first-line-regexp
2743 (concat quote-prefix-regexp "\\|"
2744 adaptive-fill-first-line-regexp)))
2745 (make-local-variable 'auto-fill-inhibit-regexp)
2746 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2747 (setq auto-fill-inhibit-regexp nil)
2748 (make-local-variable 'normal-auto-fill-function)
2749 (setq normal-auto-fill-function 'message-do-auto-fill)
2750 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2751 ;; In that case, ensure that it uses the right function. The real
2752 ;; solution would be not to use `define-derived-mode', and run
2753 ;; `text-mode-hook' ourself at the end of the mode.
2754 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2755 (when auto-fill-function
2756 (setq auto-fill-function normal-auto-fill-function)))
2761 ;;; Message mode commands
2764 ;;; Movement commands
2766 (defun message-goto-to ()
2767 "Move point to the To header."
2769 (message-position-on-field "To"))
2771 (defun message-goto-from ()
2772 "Move point to the From header."
2774 (message-position-on-field "From"))
2776 (defun message-goto-subject ()
2777 "Move point to the Subject header."
2779 (message-position-on-field "Subject"))
2781 (defun message-goto-cc ()
2782 "Move point to the Cc header."
2784 (message-position-on-field "Cc" "To"))
2786 (defun message-goto-bcc ()
2787 "Move point to the Bcc header."
2789 (message-position-on-field "Bcc" "Cc" "To"))
2791 (defun message-goto-fcc ()
2792 "Move point to the Fcc header."
2794 (message-position-on-field "Fcc" "To" "Newsgroups"))
2796 (defun message-goto-reply-to ()
2797 "Move point to the Reply-To header."
2799 (message-position-on-field "Reply-To" "Subject"))
2801 (defun message-goto-mail-reply-to ()
2802 "Move point to the Mail-Reply-To header."
2804 (message-position-on-field "Mail-Reply-To" "Subject"))
2806 (defun message-goto-mail-copies-to ()
2807 "Move point to the Mail-Copies-To header. If the header is newly created,
2808 a string \"never\" is inserted in default."
2810 (unless (message-position-on-field "Mail-Copies-To" "Subject")
2814 (defun message-goto-newsgroups ()
2815 "Move point to the Newsgroups header."
2817 (message-position-on-field "Newsgroups"))
2819 (defun message-goto-distribution ()
2820 "Move point to the Distribution header."
2822 (message-position-on-field "Distribution"))
2824 (defun message-goto-followup-to ()
2825 "Move point to the Followup-To header."
2827 (message-position-on-field "Followup-To" "Newsgroups"))
2829 (defun message-goto-mail-followup-to ()
2830 "Move point to the Mail-Followup-To header. If the header is newly created
2831 and To field contains only one address, the address is inserted in default."
2833 (unless (message-position-on-field "Mail-Followup-To" "Subject")
2834 (let ((start (point))
2837 (message-narrow-to-headers)
2838 (setq addresses (split-string (mail-strip-quoted-names
2839 (or (std11-fetch-field "to") ""))
2841 (when (eq 1 (length addresses))
2843 (insert (car addresses))
2844 (goto-char start))))))
2846 (defun message-goto-keywords ()
2847 "Move point to the Keywords header."
2849 (message-position-on-field "Keywords" "Subject"))
2851 (defun message-goto-summary ()
2852 "Move point to the Summary header."
2854 (message-position-on-field "Summary" "Subject"))
2856 (defun message-goto-body (&optional interactivep)
2857 "Move point to the beginning of the message body."
2858 (interactive (list t))
2859 (when (and interactivep
2860 (looking-at "[ \t]*\n"))
2862 (goto-char (point-min))
2863 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
2864 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
2866 (defun message-goto-eoh ()
2867 "Move point to the end of the headers."
2872 (defun message-goto-signature ()
2873 "Move point to the beginning of the message signature.
2874 If there is no signature in the article, go to the end and
2877 (goto-char (point-min))
2878 (if (re-search-forward message-signature-separator nil t)
2880 (goto-char (point-max))
2883 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc)
2884 "Insert a reasonable MFT header in a post to an unsubscribed list.
2885 When making original posts to a mailing list you are not subscribed to,
2886 you have to type in a MFT header by hand. The contents, usually, are
2887 the addresses of the list and your own address. This function inserts
2888 such a header automatically. It fetches the contents of the To: header
2889 in the current mail buffer, and appends the current `user-mail-address'.
2891 If the optional argument INCLUDE-CC is non-nil, the addresses in the
2892 Cc: header are also put into the MFT."
2897 (message-narrow-to-headers)
2898 (message-remove-header "Mail-Followup-To")
2899 (setq cc (and include-cc (message-fetch-field "Cc")))
2901 (concat (message-fetch-field "To") "," cc)
2902 (message-fetch-field "To"))))
2903 (message-goto-mail-followup-to)
2904 (insert (concat tos ", " user-mail-address))))
2908 (defun message-insert-to (&optional force)
2909 "Insert a To header that points to the author of the article being replied to.
2910 If the original author requested not to be sent mail, don't insert unless the
2911 prefix FORCE is given."
2913 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
2914 (dont (and mct (or (equal (downcase mct) "never")
2915 (equal (downcase mct) "nobody"))))
2916 (to (or (message-fetch-reply-field "mail-reply-to")
2917 (message-fetch-reply-field "reply-to")
2918 (message-fetch-reply-field "from"))))
2922 "Ignoring the user request not to have copies sent via mail"
2923 "Complying with the user request not to have copies sent via mail")))
2924 (when (and force (not to))
2925 (error "No mail address in the article"))
2926 (when (and to (or force (not dont)))
2927 (message-carefully-insert-headers (list (cons 'To to))))))
2929 (defun message-insert-wide-reply ()
2930 "Insert To and Cc headers as if you were doing a wide reply."
2932 (let ((headers (message-with-reply-buffer
2933 (message-get-reply-headers t))))
2934 (message-carefully-insert-headers headers)))
2936 (defcustom message-header-synonyms
2938 "List of lists of header synonyms.
2939 E.g., if this list contains a member list with elements `Cc' and `To',
2940 then `message-carefully-insert-headers' will not insert a `To' header
2941 when the message is already `Cc'ed to the recipient."
2942 :group 'message-headers
2943 :link '(custom-manual "(message)Message Headers")
2944 :type '(repeat sexp))
2946 (defun message-carefully-insert-headers (headers)
2947 "Insert the HEADERS, an alist, into the message buffer.
2948 Does not insert the headers when they are already present there
2949 or in the synonym headers, defined by `message-header-synonyms'."
2950 ;; FIXME: Should compare only the address and not the full name. Comparison
2951 ;; should be done case-folded (and with `string=' rather than
2953 (dolist (header headers)
2954 (let* ((header-name (symbol-name (car header)))
2955 (new-header (cdr header))
2956 (synonyms (loop for synonym in message-header-synonyms
2957 when (memq (car header) synonym) return synonym))
2959 (loop for synonym in synonyms
2960 for old-header = (mail-fetch-field (symbol-name synonym))
2961 when (and old-header (string-match new-header old-header))
2964 (message "already have `%s' in `%s'" new-header old-header)
2965 (when (and (message-position-on-field header-name)
2966 (setq old-header (mail-fetch-field header-name))
2967 (not (string-match "\\` *\\'" old-header)))
2969 (insert new-header)))))
2971 (defun message-widen-reply ()
2972 "Widen the reply to include maximum recipients."
2975 (and message-reply-buffer
2976 (buffer-name message-reply-buffer)
2978 (set-buffer message-reply-buffer)
2979 (message-get-reply-headers t)))))
2982 (message-narrow-to-headers)
2983 (dolist (elem follow-to)
2984 (message-remove-header (symbol-name (car elem)))
2985 (goto-char (point-min))
2986 (insert (symbol-name (car elem)) ": "
2987 (cdr elem) "\n"))))))
2989 (defun message-insert-newsgroups ()
2990 "Insert the Newsgroups header from the article being replied to."
2992 (when (and (message-position-on-field "Newsgroups")
2993 (mail-fetch-field "newsgroups")
2994 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
2996 (insert (or (message-fetch-reply-field "newsgroups") "")))
3000 ;;; Various commands
3002 (defun message-delete-not-region (beg end)
3003 "Delete everything in the body of the current message outside of the region."
3008 ;; snarf citation prefix, if appropriate
3009 (unless (eq (point) (progn (beginning-of-line) (point)))
3010 (when (looking-at message-cite-prefix-regexp)
3011 (setq citeprefix (match-string 0))))
3013 (delete-region (point) (if (not (message-goto-signature))
3019 (delete-region beg (progn (message-goto-body)
3023 (insert citeprefix))))
3024 (when (message-goto-signature)
3027 (defun message-kill-to-signature (&optional arg)
3028 "Kill all text up to the signature.
3029 If a numberic argument or prefix arg is given, leave that number
3030 of lines before the signature intact."
3034 (let ((point (point)))
3035 (narrow-to-region point (point-max))
3036 (message-goto-signature)
3038 (if (and arg (numberp arg))
3039 (forward-line (- -1 arg))
3041 (unless (= point (point))
3042 (kill-region point (point))
3045 (defun message-newline-and-reformat (&optional arg not-break)
3046 "Insert four newlines, and then reformat if inside quoted text.
3047 Prefix arg means justify as well."
3048 (interactive (list (if current-prefix-arg 'full)))
3049 (let (quoted point beg end leading-space bolp)
3050 (setq point (point))
3053 (setq bolp (= beg point))
3054 ;; Find first line of the paragraph.
3056 (while (and (not (eobp))
3057 (not (looking-at message-cite-prefix-regexp))
3058 (looking-at paragraph-start))
3061 (when (looking-at message-cite-prefix-regexp)
3062 (setq quoted (match-string 0))
3063 (goto-char (match-end 0))
3064 (looking-at "[ \t]*")
3065 (setq leading-space (match-string 0)))
3069 (< (- point beg) (length quoted)))
3070 ;; break inside the cite prefix.
3076 (while (and (not (eobp))
3077 (not (looking-at paragraph-separate))
3078 (looking-at message-cite-prefix-regexp)
3079 (equal quoted (match-string 0)))
3080 (goto-char (match-end 0))
3081 (looking-at "[ \t]*")
3082 (if (> (length leading-space) (length (match-string 0)))
3083 (setq leading-space (match-string 0)))
3087 (while (and (if (bobp) nil (forward-line -1) t)
3088 (not (looking-at paragraph-start))
3089 (looking-at message-cite-prefix-regexp)
3090 (equal quoted (match-string 0)))
3092 (goto-char (match-end 0))
3093 (looking-at "[ \t]*")
3094 (if (> (length leading-space) (length (match-string 0)))
3095 (setq leading-space (match-string 0)))))
3096 (while (and (not (eobp))
3097 (not (looking-at paragraph-separate))
3098 (not (looking-at message-cite-prefix-regexp)))
3102 (while (and (if (bobp) nil (forward-line -1) t)
3103 (not (looking-at paragraph-start))
3104 (not (looking-at message-cite-prefix-regexp)))
3105 (setq beg (point))))
3108 (narrow-to-region beg end)
3115 (setq point (point))
3116 ;; (newline 2) doesn't mark both newline's as hard, so call
3117 ;; newline twice. -jas
3120 (delete-region (point) (re-search-forward "[ \t]*"))
3121 (when (and quoted (not bolp))
3122 (insert quoted leading-space)))
3125 (let* ((adaptive-fill-regexp
3126 (regexp-quote (concat quoted leading-space)))
3127 (adaptive-fill-first-line-regexp
3128 adaptive-fill-regexp ))
3129 (fill-paragraph arg))
3130 (fill-paragraph arg))
3131 (if point (goto-char point)))))
3133 (defun message-fill-paragraph (&optional arg)
3134 "Like `fill-paragraph'."
3135 (interactive (list (if current-prefix-arg 'full)))
3136 (if (if (boundp 'filladapt-mode) filladapt-mode)
3138 (if (message-point-in-header-p)
3139 (message-fill-field)
3140 (message-newline-and-reformat arg t))
3143 ;; Is it better to use `mail-header-end'?
3144 (defun message-point-in-header-p ()
3145 "Return t if point is in the header."
3148 (goto-char (point-min))
3149 (not (re-search-forward
3150 (concat "^" (regexp-quote mail-header-separator) "\n")
3153 (defun message-do-auto-fill ()
3154 "Like `do-auto-fill', but don't fill in message header."
3155 (unless (message-point-in-header-p)
3158 (defun message-insert-signature (&optional force)
3159 "Insert a signature. See documentation for variable `message-signature'."
3160 (interactive (list 0))
3163 ((and (null message-signature)
3166 (goto-char (point-max))
3167 (not (re-search-backward message-signature-separator nil t))))
3168 ((and (null message-signature)
3171 ((functionp message-signature)
3172 (funcall message-signature))
3173 ((listp message-signature)
3174 (eval message-signature))
3175 (t message-signature)))
3177 (cond ((stringp signature)
3179 ((and (eq t signature)
3180 message-signature-file
3181 (file-exists-p message-signature-file))
3184 (goto-char (point-max))
3185 ;; Insert the signature.
3188 (when message-signature-insert-empty-line
3190 (insert "\n" message-signature-separator-for-insertion)
3193 (if (eq signature t)
3194 (insert-file-contents message-signature-file)
3196 (goto-char (point-max))
3197 (or (bolp) (insert "\n")))))
3199 (defun message-insert-importance-high ()
3200 "Insert header to mark message as important."
3204 (message-narrow-to-headers)
3205 (message-remove-header "Importance"))
3207 (insert "Importance: high\n")))
3209 (defun message-insert-importance-low ()
3210 "Insert header to mark message as unimportant."
3214 (message-narrow-to-headers)
3215 (message-remove-header "Importance"))
3217 (insert "Importance: low\n")))
3219 (defun message-insert-or-toggle-importance ()
3220 "Insert a \"Importance: high\" header, or cycle through the header values.
3221 The three allowed values according to RFC 1327 are `high', `normal'
3225 (let ((valid '("high" "normal" "low"))
3229 (message-narrow-to-headers)
3230 (when (setq cur (message-fetch-field "Importance"))
3231 (message-remove-header "Importance")
3232 (setq new (cond ((string= cur "high")
3234 ((string= cur "low")
3239 (insert (format "Importance: %s\n" new)))))
3241 (defun message-insert-disposition-notification-to ()
3242 "Request a disposition notification (return receipt) to this message.
3243 Note that this should not be used in newsgroups."
3247 (message-narrow-to-headers)
3248 (message-remove-header "Disposition-Notification-To"))
3250 (insert (format "Disposition-Notification-To: %s\n"
3251 (or (message-field-value "Reply-to")
3252 (message-field-value "From")
3253 (message-make-from))))))
3255 (defun message-elide-region (b e)
3256 "Elide the text in the region.
3257 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3261 (insert message-elide-ellipsis))
3263 (defvar message-caesar-translation-table nil)
3265 (defun message-caesar-region (b e &optional n)
3266 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3269 (min (point) (or (mark t) (point)))
3270 (max (point) (or (mark t) (point)))
3271 (when current-prefix-arg
3272 (prefix-numeric-value current-prefix-arg))))
3274 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
3275 (unless (or (zerop n) ; no action needed for a rot of 0
3276 (= b e)) ; no region to rotate
3277 ;; We build the table, if necessary.
3278 (when (or (not message-caesar-translation-table)
3279 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
3280 (setq message-caesar-translation-table
3281 (message-make-caesar-translation-table n)))
3282 (translate-region b e message-caesar-translation-table)))
3284 (defun message-make-caesar-translation-table (n)
3285 "Create a rot table with offset N."
3287 (table (make-string 256 0)))
3288 (while (< (incf i) 256)
3291 (substring table 0 ?A)
3292 (substring table (+ ?A n) (+ ?A n (- 26 n)))
3293 (substring table ?A (+ ?A n))
3294 (substring table (+ ?A 26) ?a)
3295 (substring table (+ ?a n) (+ ?a n (- 26 n)))
3296 (substring table ?a (+ ?a n))
3297 (substring table (+ ?a 26) 255))))
3299 (defun message-caesar-buffer-body (&optional rotnum)
3300 "Caesar rotate all letters in the current buffer by 13 places.
3301 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3302 With prefix arg, specifies the number of places to rotate each letter forward.
3303 Mail and USENET news headers are not rotated."
3304 (interactive (if current-prefix-arg
3305 (list (prefix-numeric-value current-prefix-arg))
3309 (when (message-goto-body)
3310 (narrow-to-region (point) (point-max)))
3311 (message-caesar-region (point-min) (point-max) rotnum))))
3313 (defun message-pipe-buffer-body (program)
3314 "Pipe the message body in the current buffer through PROGRAM."
3317 (when (message-goto-body)
3318 (narrow-to-region (point) (point-max)))
3319 (shell-command-on-region
3320 (point-min) (point-max) program nil t))))
3322 (defun message-rename-buffer (&optional enter-string)
3323 "Rename the *message* buffer to \"*message* RECIPIENT\".
3324 If the function is run with a prefix, it will ask for a new buffer
3325 name, rather than giving an automatic name."
3326 (interactive "Pbuffer name: ")
3329 (goto-char (point-min))
3330 (narrow-to-region (point)
3331 (search-forward mail-header-separator nil 'end))
3333 (if (message-news-p) (message-fetch-field "Newsgroups")
3334 (message-fetch-field "To"))
3337 (if (string-match "," mail-to)
3338 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
3340 (name-default (concat "*message* " mail-trimmed-to))
3341 (name (if enter-string
3342 (read-string "New buffer name: " name-default)
3344 (rename-buffer name t)))))
3346 (defun message-fill-yanked-message (&optional justifyp)
3347 "Fill the paragraphs of a message yanked into this one.
3348 Numeric argument means justify as well."
3351 (goto-char (point-min))
3352 (search-forward (concat "\n" mail-header-separator "\n") nil t)
3353 (let ((fill-prefix message-yank-prefix))
3354 (fill-individual-paragraphs (point) (point-max) justifyp))))
3356 (defun message-indent-citation ()
3357 "Modify text just inserted from a message to be cited.
3358 The inserted text should be the region.
3359 When this function returns, the region is again around the modified text.
3361 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3362 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3363 (let ((start (point)))
3364 ;; Remove unwanted headers.
3365 (when message-ignored-cited-headers
3370 (if (search-forward "\n\n" nil t)
3373 (message-remove-header message-ignored-cited-headers t)
3374 (when (= (point-min) (point-max))
3375 (setq all-removed t))
3376 (goto-char (point-max)))
3380 ;; Delete blank lines at the start of the buffer.
3381 (while (and (point-min)
3384 (message-delete-line))
3385 ;; Delete blank lines at the end of the buffer.
3386 (goto-char (point-max))
3389 (while (and (zerop (forward-line -1))
3391 (message-delete-line))
3392 ;; Do the indentation.
3393 (if (null message-yank-prefix)
3394 (indent-rigidly start (mark t) message-indentation-spaces)
3397 (while (< (point) (mark t))
3398 (if (or (looking-at ">") (looking-at "^$"))
3399 (insert message-yank-cited-prefix)
3400 (insert message-yank-prefix))
3404 (defun message-list-references (refs-list &rest refs-strs)
3405 "Add `Message-ID's which appear in REFS-STRS but not in REFS-LIST,
3407 (let (refs ref id saved-id)
3408 (when (and refs-list
3409 (integerp message-list-references-add-position))
3410 (let ((pos message-list-references-add-position))
3411 (while (and refs-list
3413 (push (pop refs-list) saved-id)
3414 (setq pos (1- pos)))))
3416 (when (setq refs (pop refs-strs))
3417 (setq refs (std11-parse-msg-ids (std11-lexical-analyze refs)))
3419 (when (eq (car (setq ref (pop refs))) 'msg-id)
3420 (setq id (concat "<" (mapconcat 'cdr (cdr ref) "") ">"))
3421 (or (member id refs-list)
3422 (member id saved-id)
3423 (push id refs-list))))))
3425 (push (pop saved-id) refs-list))
3428 (defun message-yank-original (&optional arg)
3429 "Insert the message being replied to, if any.
3430 Puts point before the text and mark after.
3431 Normally indents each nonblank line ARG spaces (default 3). However,
3432 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3434 This function uses `message-cite-function' to do the actual citing.
3436 Just \\[universal-argument] as argument means don't indent, insert no
3437 prefix, and don't delete any headers.
3439 In addition, if `message-yank-add-new-references' is non-nil and this
3440 command is called interactively, new IDs from the yanked article will
3441 be added to the \"References\" field."
3443 (let ((modified (buffer-modified-p)))
3444 (when (let ((buffer (message-eval-parameter message-reply-buffer)))
3446 message-cite-function
3449 (delete-windows-on buffer t)
3450 ; The mark will be set at the end of the article.
3451 (insert-buffer buffer))))
3452 ;; Add new IDs to the References field.
3453 (when (and message-yank-add-new-references
3455 (let ((start (point))
3461 (setq refs (message-list-references
3463 (or (message-make-references)
3465 (message-narrow-to-headers)
3466 (message-fetch-field "References")
3468 (narrow-to-region start end)
3469 (std11-narrow-to-header)
3470 (unless (equal (setq newrefs
3471 (message-list-references
3472 (copy-sequence refs)
3473 (unless (eq message-yank-add-new-references
3475 (or (message-fetch-field "References")
3476 (message-fetch-field "In-Reply-To")))
3477 (message-fetch-field "Message-ID")))
3479 ;; If the References field has been changed, we make it
3480 ;; visible in the header.
3481 (when message-reply-headers
3482 (mail-header-set-message-id message-reply-headers nil)
3483 (mail-header-set-references message-reply-headers nil))
3485 (message-narrow-to-headers)
3486 (if (let ((case-fold-search t))
3487 (re-search-forward "^References:\\([\t ]+.+\n\\)+"
3490 (goto-char (point-max)))
3492 (list (or (assq 'References message-header-format-alist)
3493 '(References . message-fill-references)))
3494 (list (cons 'References (mapconcat 'identity
3495 (nreverse newrefs) " "))))
3496 (backward-delete-char 1))))))
3498 (if (and message-suspend-font-lock-when-citing
3499 (boundp 'font-lock-mode)
3500 (symbol-value 'font-lock-mode))
3505 (funcall message-cite-function))
3507 (funcall message-cite-function)))
3508 (message-exchange-point-and-mark)
3512 (setq message-checksum (message-checksum))))))
3514 (defun message-yank-buffer (buffer)
3515 "Insert BUFFER into the current buffer and quote it."
3516 (interactive "bYank buffer: ")
3517 (let ((message-reply-buffer (get-buffer buffer)))
3518 (save-window-excursion
3519 (message-yank-original))))
3521 (defun message-buffers ()
3522 "Return a list of active message buffers."
3525 (dolist (buffer (buffer-list t))
3527 (when (and (eq major-mode 'message-mode)
3528 (null message-sent-message-via))
3529 (push (buffer-name buffer) buffers))))
3530 (nreverse buffers)))
3532 (defun message-cite-original-without-signature ()
3533 "Cite function in the standard Message manner."
3534 (let ((start (point))
3537 (when message-indent-citation-function
3538 (if (listp message-indent-citation-function)
3539 message-indent-citation-function
3540 (list message-indent-citation-function))))
3541 (message-reply-headers (or message-reply-headers
3542 (make-mail-header))))
3543 (mail-header-set-from message-reply-headers
3547 (if (search-forward "\n\n" nil t)
3550 (or (message-fetch-field "from")
3555 (when (re-search-backward message-signature-separator start t)
3556 ;; Also peel off any blank lines before the signature.
3558 (while (looking-at "^[ \t]*$")
3561 (delete-region (point) end)
3562 (unless (search-backward "\n\n" start t)
3563 ;; Insert a blank line if it is peeled off.
3567 (funcall (pop functions)))
3568 (when message-citation-line-function
3571 (funcall message-citation-line-function))))
3573 (eval-when-compile (defvar mail-citation-hook)) ;Compiler directive
3574 (defun message-cite-original ()
3575 "Cite function in the standard Message manner."
3576 (if (and (boundp 'mail-citation-hook)
3578 (run-hooks 'mail-citation-hook)
3579 (let ((start (point))
3583 (when message-indent-citation-function
3584 (if (listp message-indent-citation-function)
3585 message-indent-citation-function
3586 (list message-indent-citation-function))))
3587 (message-reply-headers (or message-reply-headers
3588 (make-mail-header))))
3590 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
3593 (mail-header-set-from message-reply-headers
3594 (or (message-fetch-field "from")
3596 (setq x-no-archive (message-fetch-field "x-no-archive")))
3599 (funcall (pop functions)))
3600 (when message-citation-line-function
3603 (funcall message-citation-line-function))
3604 (when (and x-no-archive
3605 (string-match "yes" x-no-archive))
3607 (delete-region (point) (mark t))
3608 (insert "> [Quoted text removed due to X-No-Archive]\n")
3609 (forward-line -1)))))
3611 (defun message-insert-citation-line ()
3612 "Insert a simple citation line."
3613 (when message-reply-headers
3614 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
3616 (defun message-position-on-field (header &rest afters)
3617 (let ((case-fold-search t))
3620 (goto-char (point-min))
3623 (concat "^" (regexp-quote mail-header-separator) "$"))
3624 (match-beginning 0)))
3625 (goto-char (point-min))
3626 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
3628 (re-search-forward "^[^ \t]" nil 'move)
3630 (skip-chars-backward "\n")
3633 (not (re-search-forward
3634 (concat "^" (regexp-quote (car afters)) ":")
3638 (re-search-forward "^[^ \t]" nil 'move)
3639 (beginning-of-line))
3640 (insert header ": \n")
3644 (defun message-remove-signature ()
3645 "Remove the signature from the text between point and mark.
3646 The text will also be indented the normal way."
3648 (let ((start (point))
3650 (if (not (re-search-forward message-signature-separator (mark t) t))
3651 ;; No signature here, so we just indent the cited text.
3652 (message-indent-citation)
3653 ;; Find the last non-empty line.
3655 (while (looking-at "[ \t]*$")
3658 (setq mark (set-marker (make-marker) (point)))
3660 (message-indent-citation)
3661 ;; Enable undoing the deletion.
3663 (delete-region mark (mark t))
3664 (set-marker mark nil)))))
3669 ;;; Sending messages
3672 ;; Avoid byte-compile warning.
3673 (defvar message-encoding-buffer nil)
3674 (defvar message-edit-buffer nil)
3675 (defvar message-mime-mode nil)
3677 (defun message-send-and-exit (&optional arg)
3678 "Send message like `message-send', then, if no errors, exit from mail buffer."
3680 (let ((buf (current-buffer))
3681 (actions message-exit-actions)
3682 (frame (selected-frame))
3683 (org-frame message-original-frame))
3684 (when (and (message-send arg)
3686 (if message-kill-buffer-on-exit
3689 (when (eq buf (current-buffer))
3690 (message-bury buf)))
3691 (message-do-actions actions)
3692 (message-delete-frame frame org-frame)
3695 (defun message-dont-send ()
3696 "Don't send the message you have been editing.
3697 Instead, just auto-save the buffer and then bury it."
3699 (set-buffer-modified-p t)
3701 (let ((actions message-postpone-actions)
3702 (frame (selected-frame))
3703 (org-frame message-original-frame))
3704 (message-bury (current-buffer))
3705 (message-do-actions actions)
3706 (message-delete-frame frame org-frame)))
3708 (defun message-kill-buffer ()
3709 "Kill the current buffer."
3711 (when (or (not (buffer-modified-p))
3712 (eq t message-kill-buffer-query-function)
3713 (funcall message-kill-buffer-query-function
3714 "The buffer modified; kill anyway? "))
3715 (let ((actions message-kill-actions)
3716 (draft-article message-draft-article)
3717 (auto-save-file-name buffer-auto-save-file-name)
3718 (file-name buffer-file-name)
3719 (modified (buffer-modified-p))
3720 (frame (selected-frame))
3721 (org-frame message-original-frame))
3722 (setq buffer-file-name nil)
3723 (kill-buffer (current-buffer))
3724 (when (and message-kill-buffer-and-remove-file
3725 (or (and auto-save-file-name
3726 (file-exists-p auto-save-file-name))
3728 (file-exists-p file-name)))
3729 (yes-or-no-p (format "Remove the backup file%s? "
3730 (if modified " too" ""))))
3732 (delete-file auto-save-file-name))
3733 (let ((message-draft-article draft-article))
3734 (message-disassociate-draft)))
3735 (message-do-actions actions)
3736 (message-delete-frame frame org-frame)))
3739 (defun message-mimic-kill-buffer ()
3740 "Kill the current buffer with query. This is an imitation for
3741 `kill-buffer', but it will delete a message frame."
3743 (let ((bufname (read-buffer (format "Kill buffer: (default %s) "
3745 message-kill-buffer-and-remove-file)
3746 (when (or (not bufname)
3747 (string-equal bufname "")
3748 (string-equal bufname (buffer-name)))
3749 (message-kill-buffer))))
3751 (defun message-delete-frame (frame org-frame)
3752 "Delete frame for editing message."
3753 (when (and (static-if (featurep 'xemacs)
3754 (device-on-window-system-p)
3756 (or (and (eq message-delete-frame-on-exit t)
3757 (select-frame frame)
3758 (or (eq frame org-frame)
3760 (y-or-n-p "Delete this frame?")
3762 (and (eq message-delete-frame-on-exit 'ask)
3763 (select-frame frame)
3765 (y-or-n-p "Delete this frame?")
3767 (delete-frame frame)))
3769 (defun message-bury (buffer)
3770 "Bury this mail BUFFER."
3771 (let ((newbuf (other-buffer buffer)))
3772 (bury-buffer buffer)
3773 (if (and (fboundp 'frame-parameters)
3774 (cdr (assq 'dedicated (frame-parameters)))
3775 (not (null (delq (selected-frame) (visible-frame-list)))))
3776 (delete-frame (selected-frame))
3777 (switch-to-buffer newbuf))))
3779 (defun message-send (&optional arg)
3780 "Send the message in the current buffer.
3781 If `message-interactive' is non-nil, wait for success indication or
3782 error messages, and inform user.
3783 Otherwise any failure is reported in a message back to the user from
3785 The usage of ARG is defined by the instance that called Message.
3786 It should typically alter the sending method in some way or other."
3789 (when (or (buffer-modified-p)
3790 (message-check-element 'unchanged)
3791 (y-or-n-p "No changes in the buffer; really send? "))
3792 ;; Make it possible to undo the coming changes.
3794 (let ((inhibit-read-only t))
3795 (put-text-property (point-min) (point-max) 'read-only nil))
3796 (run-hooks 'message-send-hook)
3797 (message-fix-before-sending)
3798 (message message-sending-message)
3799 (let ((message-encoding-buffer
3800 (message-generate-new-buffer-clone-locals " message encoding"))
3801 (message-edit-buffer (current-buffer))
3802 (message-mime-mode mime-edit-mode-flag)
3803 (alist message-send-method-alist)
3805 elem sent dont-barf-on-no-method
3806 (message-options message-options))
3809 (message-options-set-recipient)
3811 (set-buffer message-encoding-buffer)
3813 ;; ;; Avoid copying text props (except hard newlines).
3814 ;; T-gnus change: copy all text props from the editing buffer
3815 ;; into the encoding buffer.
3816 (insert-buffer-substring message-edit-buffer)
3817 (funcall message-encode-function)
3819 (setq elem (pop alist)))
3820 (when (funcall (cadr elem))
3822 (or (not (memq (car elem)
3823 message-sent-message-via))
3824 (message-fetch-field "supersedes")
3825 (if (or (message-gnksa-enable-p 'multiple-copies)
3826 (not (eq (car elem) 'news)))
3829 "Already sent message via %s; resend? "
3831 (error "Denied posting -- multiple copies")))
3832 (setq success (funcall (caddr elem) arg)))
3838 (let ((fcc (message-fetch-field "Fcc"))
3839 (gcc (message-fetch-field "Gcc")))
3842 (eq message-allow-no-recipients 'always)
3843 (and (not (eq message-allow-no-recipients 'never))
3844 (setq dont-barf-on-no-method
3846 (format "No receiver, perform %s anyway? "
3847 (cond ((and fcc gcc) "Fcc and Gcc")
3850 (error "No methods specified to send by"))
3851 (when (or dont-barf-on-no-method
3855 (run-hooks 'message-sent-hook))
3856 (message "Sending...done")
3857 ;; Mark the buffer as unmodified and delete auto-save.
3858 (set-buffer-modified-p nil)
3859 (delete-auto-save-file-if-necessary t)
3860 (message-disassociate-draft)
3861 ;; Delete other mail buffers and stuff.
3862 (message-do-send-housekeeping)
3863 (message-do-actions message-send-actions)
3866 (kill-buffer message-encoding-buffer)))))
3868 (defun message-send-via-mail (arg)
3869 "Send the current message via mail."
3870 (message-send-mail arg))
3872 (defun message-send-via-news (arg)
3873 "Send the current message via news."
3874 (message-send-news arg))
3876 (defmacro message-check (type &rest forms)
3877 "Eval FORMS if TYPE is to be checked."
3878 `(or (message-check-element ,type)
3882 (put 'message-check 'lisp-indent-function 1)
3883 (put 'message-check 'edebug-form-spec '(form body))
3885 ;; Advise the function `invisible-region'.
3886 (let (current-load-list)
3888 `(defadvice invisible-region (around add-mime-edit-invisible (start end)
3890 "Advised by T-gnus Message.
3891 Add the text property `mime-edit-invisible' to an invisible text when
3892 the buffer's major mode is `message-mode'. The added property will be
3893 used to distinguish whether the invisible text is a MIME part or not."
3894 ,(if (featurep 'xemacs)
3895 '(if (eq ?\n (char-after start))
3896 (setq start (1+ start)))
3897 '(if (eq ?\n (char-after (1- end)))
3898 (setq end (1- end))))
3899 (setq ad-return-value
3900 (if (eq 'message-mode major-mode)
3901 (add-text-properties start end
3902 '(invisible t mime-edit-invisible t))
3903 (put-text-property start end 'invisible t))))))
3905 (defun message-text-with-property (prop)
3906 "Return a list of all points where the text has PROP."
3908 (point (point-min)))
3910 (while (< point (point-max))
3911 (when (get-text-property point prop)
3912 (push point points))
3916 (defun message-fix-before-sending ()
3917 "Do various things to make the message nice before sending it."
3918 ;; Make sure there's a newline at the end of the message.
3920 (goto-char (point-max))
3923 ;; Make the hidden headers visible.
3924 (let ((points (message-text-with-property 'message-hidden)))
3926 (goto-char (car points))
3927 (dolist (point points)
3928 (add-text-properties point (1+ point)
3929 '(invisible nil intangible nil)))))
3930 ;; Make invisible text visible except for mime parts which may be
3931 ;; inserted by the MIME-Edit.
3932 ;; It doesn't seem as if this is useful, since the invisible property
3933 ;; is clobbered by an after-change hook anyhow.
3934 (message-check 'invisible-text
3935 ;; FIXME T-gnus: It should also detect invisible overlays.
3938 mime-from mime-to hidden-start)
3939 (while (setq from (text-property-any to (point-max) 'invisible t))
3940 (setq to (or (text-property-not-all from (point-max) 'invisible t)
3943 (while (setq mime-from (text-property-any mime-to to
3944 'mime-edit-invisible t))
3945 (when (> mime-from mime-to)
3946 (setq hidden-start (or hidden-start mime-to))
3947 (add-text-properties mime-to mime-from
3948 '(invisible nil face highlight
3949 font-lock-face highlight)))
3950 (setq mime-to (or (text-property-not-all mime-from to
3951 'mime-edit-invisible t)
3953 (when (< mime-to to)
3954 (setq hidden-start (or hidden-start mime-to))
3955 (add-text-properties mime-to to
3956 '(invisible nil face highlight
3957 font-lock-face highlight))))
3959 (goto-char hidden-start)
3960 (set-window-start (selected-window) (point-at-bol))
3961 (unless (yes-or-no-p
3962 "Invisible text found and made visible; continue sending? ")
3963 (error "Invisible text found and made visible")))))
3964 ;; The following check is needless to T-gnus since T-gnus determines
3965 ;; a MIME charset forcibly (even if it cannot be determined properly,
3966 ;; the value of the `default-mime-charset-for-write' variable is used).
3967 ;; (message-check 'illegible-text
3968 ;; (let (found choice)
3969 ;; (message-goto-body)
3970 ;; (skip-chars-forward mm-7bit-chars)
3971 ;; (while (not (eobp))
3972 ;; (when (let ((char (char-after)))
3973 ;; (or (< (mm-char-int char) 128)
3974 ;; (and (mm-multibyte-p)
3975 ;; (memq (char-charset char)
3976 ;; '(eight-bit-control eight-bit-graphic
3978 ;; (not (get-text-property
3979 ;; (point) 'untranslated-utf-8)))))
3980 ;; (message-overlay-put (message-make-overlay (point) (1+ (point)))
3981 ;; 'face 'highlight)
3984 ;; (skip-chars-forward mm-7bit-chars))
3987 ;; (gnus-multiple-choice
3988 ;; "Non-printable characters found. Continue sending?"
3989 ;; '((?d "Remove non-printable characters and send")
3990 ;; (?r "Replace non-printable characters with dots and send")
3991 ;; (?i "Ignore non-printable characters and send")
3992 ;; (?e "Continue editing"))))
3993 ;; (if (eq choice ?e)
3994 ;; (error "Non-printable characters"))
3995 ;; (message-goto-body)
3996 ;; (skip-chars-forward mm-7bit-chars)
3997 ;; (while (not (eobp))
3998 ;; (when (let ((char (char-after)))
3999 ;; (or (< (mm-char-int char) 128)
4000 ;; (and (mm-multibyte-p)
4001 ;; ;; Fixme: Wrong for Emacs 22 and for things
4002 ;; ;; like undecable utf-8. Should at least
4003 ;; ;; use find-coding-systems-region.
4004 ;; (memq (char-charset char)
4005 ;; '(eight-bit-control eight-bit-graphic
4007 ;; (not (get-text-property
4008 ;; (point) 'untranslated-utf-8)))))
4009 ;; (if (eq choice ?i)
4010 ;; (message-kill-all-overlays)
4012 ;; (when (eq choice ?r)
4015 ;; (skip-chars-forward mm-7bit-chars)))))
4018 (defun message-add-action (action &rest types)
4019 "Add ACTION to be performed when doing an exit of type TYPES."
4021 (add-to-list (intern (format "message-%s-actions" (pop types)))
4024 (defun message-delete-action (action &rest types)
4025 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
4028 (set (setq var (intern (format "message-%s-actions" (pop types))))
4029 (delq action (symbol-value var))))))
4031 (defun message-do-actions (actions)
4032 "Perform all actions in ACTIONS."
4033 ;; Now perform actions on successful sending.
4037 ;; A simple function.
4038 ((functionp (car actions))
4039 (funcall (car actions)))
4040 ;; Something to be evaled.
4042 (eval (car actions)))))
4045 (defsubst message-maybe-split-and-send-mail ()
4046 "Split a message if necessary, and send it via mail.
4047 Returns nil if sending succeeded, returns any string if sending failed.
4048 This sub function is for exclusive use of `message-send-mail'."
4049 (let ((mime-edit-split-ignored-field-regexp
4050 mime-edit-split-ignored-field-regexp)
4051 (case-fold-search t)
4053 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
4054 (setq mime-edit-split-ignored-field-regexp
4055 (concat (substring mime-edit-split-ignored-field-regexp
4056 0 (match-beginning 0))
4057 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
4058 "_so_don't_rape_it!"
4059 (substring mime-edit-split-ignored-field-regexp
4063 (catch 'message-sending-mail-failure
4064 (mime-edit-maybe-split-and-send
4069 (std11-narrow-to-header mail-header-separator)
4070 (goto-char (point-min))
4071 (when (re-search-forward "^Message-ID:" nil t)
4072 (delete-region (match-end 0) (std11-field-end))
4073 (insert " " (message-make-message-id))))
4075 (funcall (or message-send-mail-real-function
4076 message-send-mail-function))
4078 (throw 'message-sending-mail-failure err))))))
4082 (funcall (or message-send-mail-real-function
4083 message-send-mail-function))
4087 (if (eq 'error (car failure))
4089 (prin1-to-string failure)))))
4091 (defun message-send-mail-partially ()
4092 "Send mail as message/partial."
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")
4098 (run-hooks 'message-send-mail-hook)
4099 (let ((p (goto-char (point-min)))
4100 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
4101 (curbuf (current-buffer))
4102 (id (message-make-message-id)) (n 1)
4103 plist total header required-mail-headers)
4105 (if (< (point-max) (+ p message-send-mail-partially-limit))
4106 (goto-char (point-max))
4107 (goto-char (+ p message-send-mail-partially-limit))
4109 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
4112 (setq total (length plist))
4113 (push (point-max) plist)
4114 (setq plist (nreverse plist))
4117 (setq p (pop plist))
4120 (copy-to-buffer tembuf p (car plist))
4122 (goto-char (point-min))
4125 (goto-char (point-min))
4126 (narrow-to-region (point) (point))
4129 (setq header (buffer-substring (point-min) (point)))
4130 (goto-char (point-min))
4131 (narrow-to-region (point) (point))
4133 (message-remove-header "Mime-Version")
4134 (message-remove-header "Content-Type")
4135 (message-remove-header "Content-Transfer-Encoding")
4136 (message-remove-header "Message-ID")
4137 (message-remove-header "Lines")
4138 (goto-char (point-max))
4139 (insert "Mime-Version: 1.0\n")
4140 (setq header (buffer-string)))
4141 (goto-char (point-max))
4142 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
4145 (let ((mail-header-separator ""))
4146 (when (memq 'Message-ID message-required-mail-headers)
4147 (insert "Message-ID: " (message-make-message-id) "\n"))
4148 (when (memq 'Lines message-required-mail-headers)
4149 (insert "Lines: " (message-make-lines) "\n"))
4150 (message-goto-subject)
4152 (insert (format " (%d/%d)" n total))
4154 (mm-with-unibyte-current-buffer
4155 (funcall (or message-send-mail-real-function
4156 message-send-mail-function))))
4158 (setq p (pop plist))
4160 (kill-buffer tembuf))))
4162 (defun message-send-mail (&optional arg)
4163 (require 'mail-utils)
4164 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
4165 (case-fold-search nil)
4166 (news (message-news-p))
4167 (message-this-is-mail t)
4168 (headers message-required-mail-headers)
4171 (message-narrow-to-headers)
4172 ;; Generate the Mail-Followup-To header if the header is not there...
4173 (if (and (message-subscribed-p)
4174 (not (mail-fetch-field "mail-followup-to")))
4177 (cons "Mail-Followup-To" (message-make-mail-followup-to))
4178 message-required-mail-headers))
4179 ;; otherwise, delete the MFT header if the field is empty
4180 (when (equal "" (mail-fetch-field "mail-followup-to"))
4181 (message-remove-header "^Mail-Followup-To:")))
4182 ;; Insert some headers.
4183 (let ((message-deletable-headers
4184 (if news nil message-deletable-headers)))
4185 (message-generate-headers headers))
4186 ;; Let the user do all of the above.
4187 (run-hooks 'message-header-hook))
4188 (if (not (message-check-mail-syntax))
4196 ;; ;; Avoid copying text props (except hard newlines).
4197 ;; T-gnus change: copy all text props from the editing buffer
4198 ;; into the encoding buffer.
4199 (insert-buffer-substring message-encoding-buffer)
4200 ;; Remove some headers.
4202 (message-narrow-to-headers)
4203 ;; We Semi-gnus people have no use for it.
4204 ;; ;; We (re)generate the Lines header.
4205 ;; (when (memq 'Lines message-required-mail-headers)
4206 ;; (message-generate-headers '(Lines)))
4207 (message-remove-header message-ignored-mail-headers t))
4208 (goto-char (point-max))
4209 ;; require one newline at the end.
4210 (or (= (preceding-char) ?\n)
4212 (message-cleanup-headers)
4213 ;; FIXME: we're inserting the courtesy copy after encoding.
4214 ;; This is wrong if the courtesy copy string contains
4215 ;; non-ASCII characters. -- jh
4218 (message-narrow-to-headers)
4220 (or (message-fetch-field "cc")
4221 (message-fetch-field "bcc")
4222 (message-fetch-field "to"))
4223 (let ((content-type (mime-read-Content-Type)))
4228 (eq 'text (cdr (assq 'type content-type)))
4229 (eq 'plain (cdr (assq 'subtype content-type)))))
4232 (mime-read-Content-Transfer-Encoding)))))))
4233 (message-insert-courtesy-copy))
4234 (setq failure (message-maybe-split-and-send-mail)))
4235 (kill-buffer tembuf))
4236 (set-buffer message-edit-buffer)
4239 (message "Couldn't send message via mail: %s" failure)
4241 (push 'mail message-sent-message-via)))))
4243 (defun message-send-mail-with-sendmail ()
4244 "Send off the prepared buffer with sendmail."
4245 (let ((errbuf (if message-interactive
4246 (message-generate-new-buffer-clone-locals
4249 resend-to-addresses delimline)
4252 (let ((case-fold-search t))
4254 (message-narrow-to-headers)
4255 (setq resend-to-addresses (message-fetch-field "resent-to")))
4256 ;; Change header-delimiter to be what sendmail expects.
4257 (goto-char (point-min))
4259 (concat "^" (regexp-quote mail-header-separator) "\n"))
4260 (replace-match "\n")
4262 (setq delimline (point-marker))
4263 (run-hooks 'message-send-mail-hook)
4264 ;; Insert an extra newline if we need it to work around
4265 ;; Sun's bug that swallows newlines.
4266 (goto-char (1+ delimline))
4267 (when (eval message-mailer-swallows-blank-line)
4269 (when message-interactive
4273 (let* ((default-directory "/")
4274 (cpr (as-binary-process
4276 'call-process-region
4278 (list (point-min) (point-max)
4279 (if (boundp 'sendmail-program)
4281 "/usr/lib/sendmail")
4282 nil errbuf nil "-oi")
4283 ;; Always specify who from,
4284 ;; since some systems have broken sendmails.
4285 ;; But some systems are more broken with -f, so
4286 ;; we'll let users override this.
4287 (if (null message-sendmail-f-is-evil)
4288 (list "-f" (message-sendmail-envelope-from)))
4289 ;; These mean "report errors by mail"
4290 ;; and "deliver in background".
4291 (if (null message-interactive) '("-oem" "-odb"))
4292 ;; Get the addresses from the message
4293 ;; unless this is a resend.
4294 ;; We must not do that for a resend
4295 ;; because we would find the original addresses.
4296 ;; For a resend, include the specific addresses.
4297 (if resend-to-addresses
4298 (list resend-to-addresses)
4300 (unless (or (null cpr) (and (numberp cpr) (zerop cpr)))
4301 (error "Sending...failed with exit value %d" cpr)))
4302 (when message-interactive
4305 (goto-char (point-min))
4306 (while (re-search-forward "\n\n* *" nil t)
4307 (replace-match "; "))
4308 (if (not (zerop (buffer-size)))
4309 (error "Sending...failed to %s"
4310 (buffer-string))))))
4311 (when (bufferp errbuf)
4312 (kill-buffer errbuf)))))
4314 (defun message-send-mail-with-qmail ()
4315 "Pass the prepared message buffer to qmail-inject.
4316 Refer to the documentation for the variable `message-send-mail-function'
4317 to find out how to use this."
4318 ;; replace the header delimiter with a blank line
4319 (goto-char (point-min))
4321 (concat "^" (regexp-quote mail-header-separator) "\n"))
4322 (replace-match "\n")
4324 (run-hooks 'message-send-mail-hook)
4329 'call-process-region 1 (point-max) message-qmail-inject-program
4331 ;; qmail-inject's default behaviour is to look for addresses on the
4332 ;; command line; if there're none, it scans the headers.
4333 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4335 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4336 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4337 ;; message from stdin.
4339 ;; qmail also has the advantage of not having been raped by
4340 ;; various vendors, so we don't have to allow for that, either --
4341 ;; compare this with message-send-mail-with-sendmail and weep
4342 ;; for sendmail's lost innocence.
4344 ;; all this is way cool coz it lets us keep the arguments entirely
4345 ;; free for -inject-arguments -- a big win for the user and for us
4346 ;; since we don't have to play that double-guessing game and the user
4347 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4348 (if (functionp message-qmail-inject-args)
4349 (funcall message-qmail-inject-args)
4350 message-qmail-inject-args)))
4351 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4352 ;; we have to look at the retval instead
4354 (100 (error "qmail-inject reported permanent failure"))
4355 (111 (error "qmail-inject reported transient failure"))
4356 ;; should never happen
4357 (t (error "qmail-inject reported unknown failure"))))
4359 (defun message-send-mail-with-mh ()
4360 "Send the prepared message buffer with mh."
4361 (let ((mh-previous-window-config nil)
4362 (name (mh-new-draft-name)))
4363 (setq buffer-file-name name)
4364 ;; MH wants to generate these headers itself.
4365 (when message-mh-deletable-headers
4366 (let ((headers message-mh-deletable-headers))
4368 (goto-char (point-min))
4369 (and (re-search-forward
4370 (concat "^" (symbol-name (car headers)) ": *") nil t)
4371 (message-delete-line))
4373 (run-hooks 'message-send-mail-hook)
4374 ;; Pass it on to mh.
4377 (defun message-send-mail-with-smtp ()
4378 "Send off the prepared buffer with SMTP."
4379 (require 'smtp) ; XXX
4380 (let ((case-fold-search t)
4383 (message-narrow-to-headers)
4385 ;; XXX: Should be replaced by better one.
4386 (smtp-deduce-address-list (current-buffer)
4387 (point-min) (point-max)))
4388 ;; Remove BCC lines.
4389 (message-remove-header "bcc"))
4390 ;; replace the header delimiter with a blank line.
4391 (goto-char (point-min))
4393 (concat "^" (regexp-quote mail-header-separator) "\n"))
4394 (replace-match "\n")
4396 (run-hooks 'message-send-mail-hook)
4398 (smtp-send-buffer user-mail-address recipients (current-buffer))
4399 (error "Sending failed; no recipients"))))
4401 (defsubst message-maybe-split-and-send-news (method)
4402 "Split a message if necessary, and send it via news.
4403 Returns nil if sending succeeded, returns t if sending failed.
4404 This sub function is for exclusive use of `message-send-news'."
4405 (let ((mime-edit-split-ignored-field-regexp
4406 mime-edit-split-ignored-field-regexp)
4407 (case-fold-search t))
4408 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
4409 (setq mime-edit-split-ignored-field-regexp
4410 (concat (substring mime-edit-split-ignored-field-regexp
4411 0 (match-beginning 0))
4412 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
4413 "_so_don't_rape_it!"
4414 (substring mime-edit-split-ignored-field-regexp
4417 (catch 'message-sending-news-failure
4418 (mime-edit-maybe-split-and-send
4423 (std11-narrow-to-header mail-header-separator)
4424 (goto-char (point-min))
4425 (when (re-search-forward "^Message-ID:" nil t)
4426 (delete-region (match-end 0) (std11-field-end))
4427 (insert " " (message-make-message-id))))
4428 (unless (funcall message-send-news-function method)
4429 (throw 'message-sending-news-failure t)))))
4431 (not (funcall message-send-news-function method)))))
4433 (defun message-smtpmail-send-it ()
4434 "Send the prepared message buffer with `smtpmail-send-it'.
4435 This only differs from `smtpmail-send-it' that this command evaluates
4436 `message-send-mail-hook' just before sending a message. It is useful
4437 if your ISP requires the POP-before-SMTP authentication. See the Gnus
4438 manual for details."
4439 (run-hooks 'message-send-mail-hook)
4442 (defun message-canlock-generate ()
4443 "Return a string that is non-trivial to guess.
4444 Do not use this for anything important, it is cryptographically weak."
4446 (let (sha1-maximum-internal-length)
4447 (sha1 (concat (message-unique-id)
4448 (format "%x%x%x" (random) (random t) (random))
4449 (prin1-to-string (recent-keys))
4450 (prin1-to-string (garbage-collect))))))
4452 (defun message-canlock-password ()
4453 "The password used by message for cancel locks.
4454 This is the value of `canlock-password', if that option is non-nil.
4455 Otherwise, generate and save a value for `canlock-password' first."
4456 (unless canlock-password
4457 (customize-save-variable 'canlock-password (message-canlock-generate))
4458 (setq canlock-password-for-verify canlock-password))
4461 (defun message-insert-canlock ()
4462 (when message-insert-canlock
4463 (message-canlock-password)
4464 (canlock-insert-header)))
4466 (defun message-send-news (&optional arg)
4467 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4468 (case-fold-search nil)
4469 (method (if (functionp message-post-method)
4470 (funcall message-post-method arg)
4471 message-post-method))
4472 (newsgroups-field (save-restriction
4473 (message-narrow-to-headers-or-head)
4474 (message-fetch-field "Newsgroups")))
4475 (followup-field (save-restriction
4476 (message-narrow-to-headers-or-head)
4477 (message-fetch-field "Followup-To")))
4478 ;; BUG: We really need to get the charset for each name in the
4479 ;; Newsgroups and Followup-To lines to allow crossposting
4480 ;; between group namess with incompatible character sets.
4481 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4482 (group-field-charset
4483 (gnus-group-name-charset method newsgroups-field))
4484 (followup-field-charset
4485 (gnus-group-name-charset method (or followup-field "")))
4486 (mime-field-encoding-method-alist
4487 (append (when group-field-charset
4488 (list (cons "Newsgroups" group-field-charset)))
4489 (when followup-field-charset
4490 (list (cons "Followup-To" followup-field-charset)))
4491 mime-field-encoding-method-alist))
4492 (message-syntax-checks
4494 (listp message-syntax-checks))
4495 (cons '(existing-newsgroups . disabled)
4496 message-syntax-checks)
4497 message-syntax-checks))
4498 (message-this-is-news t)
4501 (message-narrow-to-headers)
4502 ;; Insert some headers.
4503 (message-generate-headers message-required-news-headers)
4504 (message-insert-canlock)
4505 ;; Let the user do all of the above.
4506 (run-hooks 'message-header-hook))
4507 ;; Note: This check will be disabled by the ".*" default value for
4508 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4509 (when (and group-field-charset
4510 (listp message-syntax-checks))
4511 (setq message-syntax-checks
4512 (cons '(valid-newsgroups . disabled)
4513 message-syntax-checks)))
4514 (message-cleanup-headers)
4515 (if (not (let ((message-post-method method))
4516 (message-check-news-syntax)))
4521 (buffer-disable-undo)
4523 (insert-buffer-substring message-encoding-buffer)
4524 ;; Remove some headers.
4526 (message-narrow-to-headers)
4527 ;; We Semi-gnus people have no use for it.
4528 ;; ;; We (re)generate the Lines header.
4529 ;; (when (memq 'Lines message-required-mail-headers)
4530 ;; (message-generate-headers '(Lines)))
4531 ;; Remove some headers.
4532 (message-remove-header message-ignored-news-headers t))
4533 (goto-char (point-max))
4534 ;; require one newline at the end.
4535 (or (= (preceding-char) ?\n)
4537 (setq result (message-maybe-split-and-send-news method)))
4538 (kill-buffer tembuf))
4539 (set-buffer message-edit-buffer)
4542 (message "Couldn't send message via news: %s"
4543 (nnheader-get-report (car method)))
4545 (push 'news message-sent-message-via)))))
4547 ;; 1997-09-29 by MORIOKA Tomohiko
4548 (defun message-send-news-with-gnus (method)
4549 (let ((case-fold-search t))
4550 ;; Remove the delimiter.
4551 (goto-char (point-min))
4553 (concat "^" (regexp-quote mail-header-separator) "\n"))
4554 (replace-match "\n")
4556 (run-hooks 'message-send-news-hook)
4557 (gnus-open-server method)
4558 (message "Sending news via %s..." (gnus-server-string method))
4559 (gnus-request-post method)
4563 ;;; Header generation & syntax checking.
4566 (defun message-check-element (type)
4567 "Return non-nil if this TYPE is not to be checked."
4568 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
4570 (let ((able (assq type message-syntax-checks)))
4572 (eq (cdr able) 'disabled)))))
4574 (defun message-check-news-syntax ()
4575 "Check the syntax of the message."
4580 ;; We narrow to the headers and check them first.
4583 (message-narrow-to-headers)
4584 (message-check-news-header-syntax)))
4587 (set-buffer message-edit-buffer)
4588 (message-check-news-body-syntax))))))
4590 (defun message-check-news-header-syntax ()
4592 ;; Check Newsgroups header.
4593 (message-check 'newsgroups
4594 (let ((group (message-fetch-field "newsgroups")))
4597 (not (string-match "\\`[ \t]*\\'" group)))
4600 "The newsgroups field is empty or missing. Posting is denied.")))))
4601 ;; Check the Subject header.
4602 (message-check 'subject
4603 (let* ((case-fold-search t)
4604 (subject (message-fetch-field "subject")))
4607 (not (string-match "\\`[ \t]*\\'" subject)))
4610 "The subject field is empty or missing. Posting is denied.")))))
4611 ;; Check for commands in Subject.
4612 (message-check 'subject-cmsg
4613 (if (string-match "^cmsg " (message-fetch-field "subject"))
4615 "The control code \"cmsg\" is in the subject. Really post? ")
4617 ;; Check long header lines.
4618 (message-check 'long-header-lines
4619 (let ((start (point))
4623 (while (and (not found)
4624 (re-search-forward "^\\([^ \t:]+\\): " nil t))
4625 (if (> (- (point) (match-beginning 0)) 998)
4627 length (- (point) (match-beginning 0)))
4628 (setq header (match-string-no-properties 1)))
4629 (setq start (match-beginning 0))
4632 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
4635 ;; Check for multiple identical headers.
4636 (message-check 'multiple-headers
4638 (while (and (not found)
4639 (re-search-forward "^[^ \t:]+: " nil t))
4641 (or (re-search-forward
4646 (match-beginning 0) (- (match-end 0) 2))))
4651 (y-or-n-p (format "Multiple %s headers. Really post? " found))
4653 ;; Check for Version and Sendsys.
4654 (message-check 'sendsys
4655 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
4657 (format "The article contains a %s command. Really post? "
4658 (buffer-substring (match-beginning 0)
4659 (1- (match-end 0)))))
4661 ;; See whether we can shorten Followup-To.
4662 (message-check 'shorten-followup-to
4663 (let ((newsgroups (message-fetch-field "newsgroups"))
4664 (followup-to (message-fetch-field "followup-to"))
4666 (when (and newsgroups
4667 (string-match "," newsgroups)
4672 (setq to (completing-read
4673 "Followups to (default: no Followup-To header) "
4676 (message-tokenize-header
4678 (goto-char (point-min))
4679 (insert "Followup-To: " to "\n"))
4681 ;; Check "Shoot me".
4682 (message-check 'shoot
4683 (if (re-search-forward
4684 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t)
4685 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
4687 ;; Check for Approved.
4688 (message-check 'approved
4689 (if (re-search-forward "^Approved:" nil t)
4690 (y-or-n-p "The article contains an Approved header. Really post? ")
4692 ;; Check the Message-ID header.
4693 (message-check 'message-id
4694 (let* ((case-fold-search t)
4695 (message-id (message-fetch-field "message-id" t)))
4696 (or (not message-id)
4697 ;; Is there an @ in the ID?
4698 (and (string-match "@" message-id)
4699 ;; Is there a dot in the ID?
4700 (string-match "@[^.]*\\." message-id)
4701 ;; Does the ID end with a dot?
4702 (not (string-match "\\.>" message-id)))
4704 (format "The Message-ID looks strange: \"%s\". Really post? "
4706 ;; Check the Newsgroups & Followup-To headers.
4707 (message-check 'existing-newsgroups
4708 (let* ((case-fold-search t)
4709 (newsgroups (message-fetch-field "newsgroups"))
4710 (followup-to (message-fetch-field "followup-to"))
4711 (groups (message-tokenize-header
4713 (concat newsgroups "," followup-to)
4715 (post-method (if (functionp message-post-method)
4716 (funcall message-post-method)
4717 message-post-method))
4718 ;; KLUDGE to handle nnvirtual groups. Doing this right
4719 ;; would probably involve a new nnoo function.
4720 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
4721 (method (if (and (consp post-method)
4722 (eq (car post-method) 'nnvirtual)
4723 gnus-message-group-art)
4724 (let ((group (car (nnvirtual-find-group-art
4725 (car gnus-message-group-art)
4726 (cdr gnus-message-group-art)))))
4727 (gnus-find-method-for-group group))
4731 (gnus-group-name-decode
4732 (gnus-group-real-name n)
4733 (gnus-group-name-charset method n)))
4734 (gnus-groups-from-server method)))
4737 (when (and (not (equal (car groups) "poster"))
4738 (not (member (car groups) known-groups))
4739 (not (member (car groups) errors)))
4740 (push (car groups) errors))
4743 ;; Gnus is not running.
4744 ((or (not (and (boundp 'gnus-active-hashtb)
4745 gnus-active-hashtb))
4746 (not (boundp 'gnus-read-active-file)))
4748 ;; We don't have all the group names.
4749 ((and (or (not gnus-read-active-file)
4750 (eq gnus-read-active-file 'some))
4754 "Really use %s possibly unknown group%s: %s? "
4755 (if (= (length errors) 1) "this" "these")
4756 (if (= (length errors) 1) "" "s")
4757 (mapconcat 'identity errors ", "))))
4758 ;; There were no errors.
4761 ;; There are unknown groups.
4765 "Really post to %s unknown group%s: %s? "
4766 (if (= (length errors) 1) "this" "these")
4767 (if (= (length errors) 1) "" "s")
4768 (mapconcat 'identity errors ", ")))))))
4769 ;; Check continuation headers.
4770 (message-check 'continuation-headers
4771 (goto-char (point-min))
4772 (let ((do-posting t))
4773 (while (re-search-forward "^[^ \t\n][^:\n]*$" nil t)
4774 (if (y-or-n-p "Fix continuation lines? ")
4776 (goto-char (match-beginning 0))
4778 (unless (y-or-n-p "Send anyway? ")
4779 (setq do-posting nil))))
4781 ;; Check the Newsgroups & Followup-To headers for syntax errors.
4782 (message-check 'valid-newsgroups
4783 (let ((case-fold-search t)
4784 (headers '("Newsgroups" "Followup-To"))
4786 (while (and headers (not error))
4787 (when (setq header (mail-fetch-field (car headers)))
4791 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
4796 (not (string-match "\\.\\'\\|\\.\\." g)))
4797 (message-tokenize-header header ","))))
4804 (format "The %s header looks odd: \"%s\". Really post? "
4805 (car headers) header)))))
4806 (message-check 'repeated-newsgroups
4807 (let ((case-fold-search t)
4808 (headers '("Newsgroups" "Followup-To"))
4809 header error groups group)
4812 (when (setq header (mail-fetch-field (pop headers)))
4813 (setq groups (message-tokenize-header header ","))
4814 (while (setq group (pop groups))
4815 (when (member group groups)
4821 (format "Group %s is repeated in headers. Really post? " error)))))
4822 ;; Check the From header.
4823 (message-check 'from
4824 (let* ((case-fold-search t)
4825 (from (message-fetch-field "from"))
4829 (message "There is no From line. Posting is denied.")
4831 ((or (not (string-match
4833 (setq ad (nth 1 (std11-extract-address-components
4834 from))))) ;larsi@ifi
4835 (string-match "\\.\\." ad) ;larsi@ifi..uio
4836 (string-match "@\\." ad) ;larsi@.ifi.uio
4837 (string-match "\\.$" ad) ;larsi@ifi.uio.
4838 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4839 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
4841 "Denied posting -- the From looks strange: \"%s\"." from)
4843 ((let ((addresses (rfc822-addresses from)))
4844 (while (and addresses
4845 (not (eq (string-to-char (car addresses)) ?\()))
4846 (setq addresses (cdr addresses)))
4849 "Denied posting -- bad From address: \"%s\"." from)
4852 ;; Check the Reply-To header.
4853 (message-check 'reply-to
4854 (let* ((case-fold-search t)
4855 (reply-to (message-fetch-field "reply-to"))
4860 ((string-match "," reply-to)
4862 (format "Multiple Reply-To addresses: \"%s\". Really post? "
4864 ((or (not (string-match
4866 (setq ad (nth 1 (std11-extract-address-components
4867 reply-to))))) ;larsi@ifi
4868 (string-match "\\.\\." ad) ;larsi@ifi..uio
4869 (string-match "@\\." ad) ;larsi@.ifi.uio
4870 (string-match "\\.$" ad) ;larsi@ifi.uio.
4871 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4872 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
4875 "The Reply-To looks strange: \"%s\". Really post? "
4879 (defun message-check-news-body-syntax ()
4881 ;; Check for long lines.
4882 (message-check 'long-lines
4883 (goto-char (point-min))
4885 (concat "^" (regexp-quote mail-header-separator) "$"))
4889 mime-edit-tag-regexp)
4892 (< (- (point) p) 80)))
4893 (zerop (forward-line 1))))
4897 "You have lines longer than 79 characters. Really post? ")))
4898 ;; Check whether the article is empty.
4899 (message-check 'empty
4900 (goto-char (point-min))
4902 (concat "^" (regexp-quote mail-header-separator) "$"))
4905 (goto-char (point-max))
4906 (re-search-backward message-signature-separator nil t)
4908 (or (re-search-backward "[^ \n\t]" b t)
4909 (if (message-gnksa-enable-p 'empty-article)
4910 (y-or-n-p "Empty article. Really post? ")
4911 (message "Denied posting -- Empty article.")
4913 ;; Check for control characters.
4914 (message-check 'control-chars
4915 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
4917 "The article contains control characters. Really post? ")
4919 ;; Check 8bit characters.
4920 (message-check '8bit
4921 (message-check-8bit))
4922 ;; Check excessive size.
4923 (message-check 'size
4924 (if (> (buffer-size) 60000)
4926 (format "The article is %d octets long. Really post? "
4929 ;; Check whether any new text has been added.
4930 (message-check 'new-text
4932 (not message-checksum)
4933 (not (eq (message-checksum) message-checksum))
4934 (if (message-gnksa-enable-p 'quoted-text-only)
4936 "It looks like no new text has been added. Really post? ")
4937 (message "Denied posting -- no new text has been added.")
4939 ;; Check the length of the signature.
4940 (message-check 'signature
4941 (goto-char (point-max))
4942 (if (> (count-lines (point) (point-max)) 5)
4945 "Your .sig is %d lines; it should be max 4. Really post? "
4946 (1- (count-lines (point) (point-max)))))
4948 ;; Ensure that text follows last quoted portion.
4949 (message-check 'quoting-style
4950 (goto-char (point-max))
4951 (let ((no-problem t))
4952 (when (search-backward-regexp "^>[^\n]*\n" nil t)
4953 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
4956 (if (message-gnksa-enable-p 'quoted-text-only)
4957 (y-or-n-p "Your text should follow quoted text. Really post? ")
4959 (goto-char (point-min))
4961 (concat "^" (regexp-quote mail-header-separator) "$"))
4962 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
4963 (y-or-n-p "Your text should follow quoted text. Really post? ")
4964 (message "Denied posting -- only quoted text.")
4967 (defun message-check-mail-syntax ()
4968 "Check the syntax of the message."
4973 ;; We narrow to the headers and check them first.
4976 (message-narrow-to-headers)
4977 (message-check-mail-header-syntax)))
4980 (set-buffer message-edit-buffer)
4981 (message-check-mail-body-syntax))))))
4983 (defun message-check-mail-header-syntax ()
4986 (defun message-check-mail-body-syntax ()
4988 ;; Check 8bit characters.
4989 (message-check '8bit
4990 (message-check-8bit)
4993 (defun message-check-8bit ()
4994 "Check the article contains 8bit characters."
4996 (set-buffer message-encoding-buffer)
4997 (message-narrow-to-headers)
4998 (let* ((case-fold-search t)
4999 (field-value (message-fetch-field "content-transfer-encoding")))
5000 (if (and field-value
5001 (member (downcase field-value) message-8bit-encoding-list))
5004 (set-buffer (get-buffer-create " message syntax"))
5006 (goto-char (point-min))
5007 (set-buffer-multibyte nil)
5008 (insert-buffer-substring message-encoding-buffer)
5009 (goto-char (point-min))
5010 (if (re-search-forward "[^\x00-\x7f]" nil t)
5012 "The article contains 8bit characters. Really post? ")
5015 (defun message-checksum ()
5016 "Return a \"checksum\" for the current buffer."
5019 (goto-char (point-min))
5021 (concat "^" (regexp-quote mail-header-separator) "$"))
5023 (when (not (looking-at "[ \t\n]"))
5024 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
5029 (defun message-do-fcc ()
5030 "Process Fcc headers in the current buffer."
5031 (let ((case-fold-search t)
5032 (coding-system-for-write 'raw-text)
5034 (mml-externalize-attachments message-fcc-externalize-attachments))
5037 (message-narrow-to-headers)
5038 (setq file (message-fetch-field "fcc" t)))
5040 (set-buffer (get-buffer-create " *message temp*"))
5042 (insert-buffer-substring message-encoding-buffer)
5044 (message-narrow-to-headers)
5045 (while (setq file (message-fetch-field "fcc"))
5047 (message-remove-header "fcc" nil t)))
5048 (goto-char (point-min))
5049 (when (re-search-forward
5050 (concat "^" (regexp-quote mail-header-separator) "$")
5052 (replace-match "" t t))
5053 ;; Process FCC operations.
5055 (setq file (pop list))
5056 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
5057 ;; Pipe the article to the program in question.
5058 (call-process-region (point-min) (point-max) shell-file-name
5059 nil nil nil shell-command-switch
5060 (match-string 1 file))
5061 ;; Save the article.
5062 (setq file (expand-file-name file))
5063 (unless (file-exists-p (file-name-directory file))
5064 (make-directory (file-name-directory file) t))
5065 (if (and message-fcc-handler-function
5066 (not (eq message-fcc-handler-function 'rmail-output)))
5067 (funcall message-fcc-handler-function file)
5068 (if (and (file-readable-p file) (mail-file-babyl-p file))
5069 (rmail-output file 1 nil t)
5070 (let ((mail-use-rfc822 t))
5071 (rmail-output file 1 t t))))))
5072 (kill-buffer (current-buffer))))))
5074 (defun message-output (filename)
5075 "Append this article to Unix/babyl mail file FILENAME."
5076 (if (and (file-readable-p filename)
5077 (mail-file-babyl-p filename))
5078 (gnus-output-to-rmail filename t)
5079 (gnus-output-to-mail filename t)))
5081 (defun message-cleanup-headers ()
5082 "Do various automatic cleanups of the headers."
5083 ;; Remove empty lines in the header.
5085 (message-narrow-to-headers)
5086 ;; Remove blank lines.
5087 (while (re-search-forward "^[ \t]*\n" nil t)
5088 (replace-match "" t t))
5090 ;; Correct Newsgroups and Followup-To headers: Change sequence of
5091 ;; spaces to comma and eliminate spaces around commas. Eliminate
5092 ;; embedded line breaks.
5093 (goto-char (point-min))
5094 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
5098 (if (re-search-forward "^[^ \t]" nil t)
5102 (goto-char (point-min))
5103 (while (re-search-forward "\n[ \t]+" nil t)
5104 (replace-match " " t t)) ;No line breaks (too confusing)
5105 (goto-char (point-min))
5106 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
5107 (replace-match "," t t))
5108 (goto-char (point-min))
5109 ;; Remove trailing commas.
5110 (when (re-search-forward ",+$" nil t)
5111 (replace-match "" t t))))))
5113 (defun message-make-date (&optional now)
5114 "Make a valid data header.
5115 If NOW, use that time instead."
5116 (let* ((now (or now (current-time)))
5117 (zone (nth 8 (decode-time now)))
5121 (setq zone (- zone)))
5123 ;; The day name of the %a spec is locale-specific. Pfff.
5124 (format "%s, " (capitalize (car (rassoc (nth 6 (decode-time now))
5125 parse-time-weekdays))))
5126 (format-time-string "%d" now)
5127 ;; The month name of the %b spec is locale-specific. Pfff.
5129 (capitalize (car (rassoc (nth 4 (decode-time now))
5130 parse-time-months))))
5131 (format-time-string "%Y %H:%M:%S " now)
5132 ;; We do all of this because XEmacs doesn't have the %z spec.
5133 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
5135 (defun message-make-followup-subject (subject)
5136 "Make a followup Subject."
5138 ((and (eq message-use-subject-re 'guess)
5139 (string-match message-subject-encoded-re-regexp subject))
5141 (message-use-subject-re
5142 (concat "Re: " (message-strip-subject-re subject)))
5145 (defun message-make-message-id ()
5146 "Make a unique Message-ID."
5147 (concat "<" (message-unique-id)
5148 (let ((psubject (save-excursion (message-fetch-field "subject")))
5150 (save-excursion (message-fetch-field "supersedes"))))
5152 (and message-reply-headers
5153 (mail-header-references message-reply-headers)
5154 (mail-header-subject message-reply-headers)
5157 (message-strip-subject-re
5158 (mail-header-subject message-reply-headers))
5159 (message-strip-subject-re psubject))))
5161 (string-match "_-_@" psupersedes)))
5163 "@" (message-make-fqdn) ">"))
5165 (defvar message-unique-id-char nil)
5167 ;; If you ever change this function, make sure the new version
5168 ;; cannot generate IDs that the old version could.
5169 ;; You might for example insert a "." somewhere (not next to another dot
5170 ;; or string boundary), or modify the "fsf" string.
5171 (defun message-unique-id ()
5172 ;; Don't use microseconds from (current-time), they may be unsupported.
5173 ;; Instead we use this randomly inited counter.
5174 (setq message-unique-id-char
5175 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
5176 ;; (current-time) returns 16-bit ints,
5177 ;; and 2^16*25 just fits into 4 digits i base 36.
5179 (let ((tm (current-time)))
5181 (if (memq system-type '(ms-dos emx vax-vms))
5182 (let ((user (downcase (user-login-name))))
5183 (while (string-match "[^a-z0-9_]" user)
5184 (aset user (match-beginning 0) ?_))
5186 (message-number-base36 (user-uid) -1))
5187 (message-number-base36 (+ (car tm)
5188 (lsh (% message-unique-id-char 25) 16)) 4)
5189 (message-number-base36 (+ (nth 1 tm)
5190 (lsh (/ message-unique-id-char 25) 16)) 4)
5191 ;; Append a given name, because while the generated ID is unique
5192 ;; to this newsreader, other newsreaders might otherwise generate
5193 ;; the same ID via another algorithm.
5196 (defun message-number-base36 (num len)
5201 (concat (message-number-base36 (/ num 36) (1- len))
5202 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
5205 (defun message-make-organization ()
5206 "Make an Organization header."
5207 (let* ((organization
5208 (when message-user-organization
5209 (if (functionp message-user-organization)
5210 (funcall message-user-organization)
5211 message-user-organization))))
5213 (set-buffer-multibyte t)
5214 (cond ((stringp organization)
5215 (insert organization))
5216 ((and (eq t organization)
5217 message-user-organization-file
5218 (file-exists-p message-user-organization-file))
5219 (insert-file-contents message-user-organization-file)))
5220 (goto-char (point-min))
5221 (while (re-search-forward "[\t\n]+" nil t)
5222 (replace-match "" t t))
5223 (unless (zerop (buffer-size))
5226 (defun message-make-lines ()
5227 "Count the number of lines and return numeric string."
5232 (int-to-string (count-lines (point) (point-max))))))
5234 (defun message-make-references ()
5235 "Return the References header for this message."
5236 (when message-reply-headers
5237 (let ((message-id (mail-header-message-id message-reply-headers))
5238 (references (mail-header-references message-reply-headers))
5240 (if (or references message-id)
5241 (concat (or references "") (and references " ")
5245 (defun message-make-in-reply-to ()
5246 "Return the In-Reply-To header for this message."
5247 (when message-reply-headers
5248 (let ((from (mail-header-from message-reply-headers))
5249 (date (mail-header-date message-reply-headers))
5250 (msg-id (mail-header-message-id message-reply-headers)))
5252 (let ((name (std11-extract-address-components from)))
5253 (concat msg-id (if msg-id " (")
5257 (if (or (not date) (string= date ""))
5258 "(unknown date)" date)
5259 "\"" (if msg-id ")")))))))
5261 (defun message-make-distribution ()
5262 "Make a Distribution header."
5263 (let ((orig-distribution (message-fetch-reply-field "distribution")))
5264 (cond ((functionp message-distribution-function)
5265 (funcall message-distribution-function))
5266 (t orig-distribution))))
5268 (defun message-make-expires ()
5269 "Return an Expires header based on `message-expires'."
5270 (let ((current (current-time))
5271 (future (* 1.0 message-expires 60 60 24)))
5272 ;; Add the future to current.
5273 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
5274 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
5275 (message-make-date current)))
5277 (defun message-make-path ()
5279 (let ((login-name (user-login-name)))
5280 (cond ((null message-user-path)
5281 (concat (system-name) "!" login-name))
5282 ((stringp message-user-path)
5283 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
5284 (concat message-user-path "!" login-name))
5287 (defun message-make-from ()
5288 "Make a From header."
5289 (let* ((style message-from-style)
5290 (login (message-make-address))
5292 (or (and (boundp 'user-full-name)
5295 (when (string= fullname "&")
5296 (setq fullname (user-login-name)))
5298 (set-buffer-multibyte t)
5301 (equal fullname ""))
5303 ((or (eq style 'angles)
5304 (and (not (eq style 'parens))
5305 ;; Use angles if no quoting is needed, or if parens would
5306 ;; need quoting too.
5307 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
5308 (let ((tmp (concat fullname nil)))
5309 (while (string-match "([^()]*)" tmp)
5310 (aset tmp (match-beginning 0) ?-)
5311 (aset tmp (1- (match-end 0)) ?-))
5312 (string-match "[\\()]" tmp)))))
5314 (goto-char (point-min))
5315 ;; Look for a character that cannot appear unquoted
5316 ;; according to RFC 822.
5317 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
5318 ;; Quote fullname, escaping specials.
5319 (goto-char (point-min))
5321 (while (re-search-forward "[\"\\]" nil 1)
5322 (replace-match "\\\\\\&" t))
5324 (insert " <" login ">"))
5325 (t ; 'parens or default
5327 (let ((fullname-start (point)))
5329 (goto-char fullname-start)
5330 ;; RFC 822 says \ and nonmatching parentheses
5331 ;; must be escaped in comments.
5332 ;; Escape every instance of ()\ ...
5333 (while (re-search-forward "[()\\]" nil 1)
5334 (replace-match "\\\\\\&" t))
5335 ;; ... then undo escaping of matching parentheses,
5336 ;; including matching nested parentheses.
5337 (goto-char fullname-start)
5338 (while (re-search-forward
5339 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
5341 (replace-match "\\1(\\3)" t)
5342 (goto-char fullname-start)))
5346 (defun message-make-sender ()
5347 "Return the \"real\" user address.
5348 This function tries to ignore all user modifications, and
5349 give as trustworthy answer as possible."
5350 (concat (user-login-name) "@" (system-name)))
5352 (defun message-make-address ()
5353 "Make the address of the user."
5354 (or (message-user-mail-address)
5355 (concat (user-login-name) "@" (message-make-domain))))
5357 (defun message-user-mail-address ()
5358 "Return the pertinent part of `user-mail-address'."
5359 (when (and user-mail-address
5360 (string-match "@.*\\." user-mail-address))
5361 (if (string-match " " user-mail-address)
5362 (nth 1 (std11-extract-address-components user-mail-address))
5363 user-mail-address)))
5365 (defun message-sendmail-envelope-from ()
5366 "Return the envelope from."
5367 (cond ((eq message-sendmail-envelope-from 'header)
5368 (nth 1 (std11-extract-address-components
5369 (message-fetch-field "from"))))
5370 ((stringp message-sendmail-envelope-from)
5371 message-sendmail-envelope-from)
5373 (message-make-address))))
5375 (defun message-make-fqdn ()
5376 "Return user's fully qualified domain name."
5377 (let* ((system-name (system-name))
5378 (user-mail (message-user-mail-address))
5381 (string-match "@\\(.*\\)\\'" user-mail))
5382 (match-string 1 user-mail)))
5383 (case-fold-search t))
5385 ((and message-user-fqdn
5386 (stringp message-user-fqdn)
5387 (string-match message-valid-fqdn-regexp message-user-fqdn)
5388 (not (string-match message-bogus-system-names message-user-fqdn)))
5390 ;; `message-user-fqdn' seems to be valid
5391 ((and (string-match message-valid-fqdn-regexp system-name)
5392 (not (string-match message-bogus-system-names system-name)))
5393 ;; `system-name' returned the right result.
5395 ;; Try `mail-host-address'.
5396 ((and (boundp 'mail-host-address)
5397 (stringp mail-host-address)
5398 (string-match message-valid-fqdn-regexp mail-host-address)
5399 (not (string-match message-bogus-system-names mail-host-address)))
5401 ;; We try `user-mail-address' as a backup.
5403 (stringp user-domain)
5404 (string-match message-valid-fqdn-regexp user-domain)
5405 (not (string-match message-bogus-system-names user-domain)))
5407 ;; Default to this bogus thing.
5410 ".i-did-not-set--mail-host-address--so-tickle-me")))))
5412 (defun message-make-host-name ()
5413 "Return the name of the host."
5414 (let ((fqdn (message-make-fqdn)))
5415 (string-match "^[^.]+\\." fqdn)
5416 (substring fqdn 0 (1- (match-end 0)))))
5418 (defun message-make-domain ()
5419 "Return the domain name."
5420 (or mail-host-address
5421 (message-make-fqdn)))
5423 (defun message-to-list-only ()
5424 "Send a message to the list only.
5425 Remove all addresses but the list address from To and Cc headers."
5427 (let ((listaddr (message-make-mail-followup-to t)))
5430 (message-remove-header "to")
5431 (message-remove-header "cc")
5432 (message-position-on-field "To" "X-Draft-From")
5433 (insert listaddr)))))
5435 (defun message-make-mail-followup-to (&optional only-show-subscribed)
5436 "Return the Mail-Followup-To header.
5437 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5438 subscribed address (and not the additional To and Cc header contents)."
5439 (let* ((case-fold-search t)
5440 (to (message-fetch-field "To"))
5441 (cc (message-fetch-field "cc"))
5442 (msg-recipients (concat to (and to cc ", ") cc))
5444 (mapcar 'mail-strip-quoted-names
5445 (message-tokenize-header msg-recipients)))
5447 (if message-subscribed-address-file
5448 (let (begin end item re)
5451 (insert-file-contents message-subscribed-address-file)
5453 (setq begin (point))
5456 (if (bolp) (setq end (1- end)))
5457 (setq item (regexp-quote (buffer-substring begin end)))
5458 (if re (setq re (concat re "\\|" item))
5459 (setq re (concat "\\`\\(" item))))
5460 (and re (list (concat re "\\)\\'"))))))))
5461 (mft-regexps (apply 'append message-subscribed-regexps
5462 (mapcar 'regexp-quote
5463 message-subscribed-addresses)
5466 message-subscribed-address-functions))))
5468 (let ((subscribed-lists nil)
5470 (loop for recipient in recipients
5471 when (loop for regexp in mft-regexps
5472 when (string-match regexp recipient) return t)
5475 (if only-show-subscribed
5477 msg-recipients))))))
5479 ;; Dummy to avoid byte-compile warning.
5480 (defvar mule-version)
5481 (defvar emacs-beta-version)
5482 (defvar xemacs-codename)
5483 (defvar gnus-inviolable-extended-version)
5485 (defun message-make-user-agent ()
5486 "Return user-agent info if the value `message-user-agent' is non-nil. If the
5487 \"User-Agent\" field has already exist, remove it."
5488 (when message-user-agent
5490 (goto-char (point-min))
5491 (let ((case-fold-search t))
5492 (when (re-search-forward "^User-Agent:[\t ]*" nil t)
5493 (delete-region (match-beginning 0) (1+ (std11-field-end)))))))
5496 (defun message-idna-to-ascii-rhs-1 (header)
5497 "Interactively potentially IDNA encode domain names in HEADER."
5498 (let ((field (message-fetch-field header))
5501 (dolist (address (mail-header-parse-addresses field))
5502 (setq address (car address)
5503 rhs (downcase (cadr (split-string address "@")))
5504 ace (downcase (idna-to-ascii rhs)))
5505 (when (and (not (equal rhs ace))
5506 (or (not (eq message-use-idna 'ask))
5507 (y-or-n-p (format "Replace %s with %s? " rhs ace))))
5508 (goto-char (point-min))
5509 (while (re-search-forward (concat "^" header ":") nil t)
5510 (message-narrow-to-field)
5511 (while (search-forward (concat "@" rhs) nil t)
5512 (replace-match (concat "@" ace) t t))
5513 (goto-char (point-max))
5516 (defun message-idna-to-ascii-rhs ()
5517 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
5518 See `message-idna-encode'."
5520 (when message-use-idna
5523 (message-narrow-to-head)
5524 (message-idna-to-ascii-rhs-1 "From")
5525 (message-idna-to-ascii-rhs-1 "To")
5526 (message-idna-to-ascii-rhs-1 "Cc")))))
5528 (defun message-generate-headers (headers)
5529 "Prepare article HEADERS.
5530 Headers already prepared in the buffer are not modified."
5531 (setq headers (append headers message-required-headers))
5533 (message-narrow-to-headers)
5534 (let* ((Date (message-make-date))
5535 (Message-ID (message-make-message-id))
5536 (Organization (message-make-organization))
5537 (From (message-make-from))
5538 (Path (message-make-path))
5541 (In-Reply-To (message-make-in-reply-to))
5542 (References (message-make-references))
5544 (Distribution (message-make-distribution))
5545 (Lines (message-make-lines))
5546 (User-Agent (message-make-user-agent))
5547 (Expires (message-make-expires))
5548 (case-fold-search t)
5550 header value elem header-string)
5551 ;; First we remove any old generated headers.
5552 (let ((headers message-deletable-headers))
5553 (unless (buffer-modified-p)
5554 (setq headers (delq 'Message-ID (copy-sequence headers))))
5556 (goto-char (point-min))
5557 (and (re-search-forward
5558 (concat "^" (symbol-name (car headers)) ": *") nil t)
5559 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
5560 (message-delete-line))
5562 ;; Go through all the required headers and see if they are in the
5563 ;; articles already. If they are not, or are empty, they are
5564 ;; inserted automatically - except for Subject, Newsgroups and
5567 (goto-char (point-min))
5568 (setq elem (pop headers))
5570 (if (eq (car elem) 'optional)
5571 (setq header (cdr elem)
5573 (setq header (car elem)))
5575 (setq header-string (if (stringp header)
5577 (symbol-name header)))
5578 (when (or (not (re-search-forward
5580 (regexp-quote (downcase header-string))
5584 ;; The header was found. We insert a space after the
5585 ;; colon, if there is none.
5586 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
5587 ;; Find out whether the header is empty.
5588 (looking-at "[ \t]*\n[^ \t]")))
5589 ;; So we find out what value we should insert.
5593 (eq (car elem) 'optional)
5594 (not (member header-string message-inserted-headers)))
5595 ;; This is an optional header. If the cdr of this
5596 ;; is something that is nil, then we do not insert
5598 (setq header (cdr elem))
5599 (or (and (functionp (cdr elem))
5600 (funcall (cdr elem)))
5601 (and (boundp (cdr elem))
5602 (symbol-value (cdr elem)))))
5604 ;; The element is a cons. Either the cdr is a
5605 ;; string to be inserted verbatim, or it is a
5606 ;; function, and we insert the value returned from
5608 (or (and (stringp (cdr elem))
5610 (and (functionp (cdr elem))
5611 (funcall (cdr elem)))))
5612 ((and (boundp header)
5613 (symbol-value header))
5614 ;; The element is a symbol. We insert the value
5615 ;; of this symbol, if any.
5616 (symbol-value header))
5617 ((not (message-check-element header))
5618 ;; We couldn't generate a value for this header,
5619 ;; so we just ask the user.
5620 (read-from-minibuffer
5621 (format "Empty header for %s; enter value: " header)))))
5622 ;; Finally insert the header.
5624 (not (equal value "")))
5628 ;; This header didn't exist, so we insert it.
5629 (goto-char (point-max))
5631 (cdr (assq header message-header-format-alist))))
5633 (funcall formatter header value)
5634 (insert header-string ": " value))
5635 (goto-char (message-fill-field))
5636 ;; We check whether the value was ended by a
5637 ;; newline. If not, we insert one.
5641 ;; The value of this header was empty, so we clear
5642 ;; totally and insert the new value.
5643 (delete-region (point) (point-at-eol))
5644 ;; If the header is optional, and the header was
5645 ;; empty, we can't insert it anyway.
5647 (push header-string message-inserted-headers)
5649 (message-fill-field)))
5650 ;; Add the deletable property to the headers that require it.
5651 (and (memq header message-deletable-headers)
5652 (progn (beginning-of-line) (looking-at "[^:]+: "))
5653 (add-text-properties
5654 (point) (match-end 0)
5655 '(message-deletable t face italic) (current-buffer)))))))
5656 ;; Insert new Sender if the From is strange.
5657 (let ((from (message-fetch-field "from"))
5658 (sender (message-fetch-field "sender"))
5659 (secure-sender (message-make-sender)))
5661 (not (message-check-element 'sender))
5664 (cadr (std11-extract-address-components from)))
5665 (downcase secure-sender)))
5670 (cadr (std11-extract-address-components sender)))
5671 (downcase secure-sender)))))
5672 (goto-char (point-min))
5673 ;; Rename any old Sender headers to Original-Sender.
5674 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
5676 (insert "Original-")
5677 (beginning-of-line))
5678 (when (or (message-news-p)
5679 (string-match "@.+\\.." secure-sender))
5680 (insert "Sender: " secure-sender "\n"))))
5682 (message-idna-to-ascii-rhs))))
5684 (defun message-insert-courtesy-copy ()
5685 "Insert a courtesy message in mail copies of combined messages."
5689 (message-narrow-to-headers)
5690 (when (setq newsgroups (message-fetch-field "newsgroups"))
5691 (goto-char (point-max))
5692 (insert "Posted-To: " newsgroups "\n")))
5694 (when message-courtesy-message
5696 ((string-match "%s" message-courtesy-message)
5697 (insert (format message-courtesy-message newsgroups)))
5699 (insert message-courtesy-message)))))))
5702 ;;; Setting up a message buffer
5705 (defun message-skip-to-next-address ()
5706 (let ((end (save-excursion
5707 (message-next-header)
5710 (when (looking-at ",")
5712 (while (and (not (= (point) end))
5713 (or (not (eq char ?,))
5715 (skip-chars-forward "^,\"" (point-max))
5716 (when (eq (setq char (following-char)) ?\")
5717 (setq quoted (not quoted)))
5718 (unless (= (point) end)
5720 (skip-chars-forward " \t\n")))
5722 (defun message-fill-address (header value)
5723 (insert (capitalize (symbol-name header))
5725 (if (consp value) (car value) value)
5727 (message-fill-field-address))
5729 (defun message-fill-references (header value)
5730 (insert (capitalize (symbol-name header))
5732 (std11-fill-msg-id-list-string
5733 (if (consp value) (car value) value))
5736 (defun message-split-line ()
5737 "Split current line, moving portion beyond point vertically down.
5738 If the current line has `message-yank-prefix', insert it on the new line."
5741 (split-line message-yank-prefix) ;; Emacs 21.3.50+ supports arg.
5745 (defun message-insert-header (header value)
5746 (insert (capitalize (symbol-name header))
5748 (if (consp value) (car value) value)))
5750 (defun message-field-name ()
5752 (goto-char (point-min))
5753 (when (looking-at "\\([^:]+\\):")
5754 (intern (capitalize (match-string 1))))))
5756 (defun message-fill-field ()
5759 (message-narrow-to-field)
5760 (let ((field-name (message-field-name)))
5761 (funcall (or (cadr (assq field-name message-field-fillers))
5762 'message-fill-field-general)))
5765 (defun message-fill-field-address ()
5767 (message-skip-to-next-address)
5769 (if (and (> (current-column) 78)
5775 (setq last (1+ (point))))
5776 (setq last (1+ (point)))))))
5778 (defun message-fill-field-general ()
5779 (let ((begin (point))
5782 (while (and (search-forward "\n" nil t)
5784 (replace-match " " t t))
5785 (fill-region-as-paragraph begin (point-max))
5786 ;; Tapdance around looong Message-IDs.
5788 (when (looking-at "[ \t]*$")
5789 (message-delete-line))
5791 (re-search-forward ":" nil t)
5792 (when (looking-at "\n[ \t]+")
5793 (replace-match " " t t))
5794 (goto-char (point-max))))
5796 (defun message-shorten-1 (list cut surplus)
5797 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
5798 (setcdr (nthcdr (- cut 2) list)
5799 (nthcdr (+ (- cut 2) surplus 1) list)))
5801 (defun message-shorten-references (header references)
5802 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
5803 When sending via news, also check that the REFERENCES are less
5804 than 988 characters long, and if they are not, trim them until
5812 (goto-char (point-min))
5813 ;; Cons a list of valid references.
5814 (while (re-search-forward "<[^>]+>" nil t)
5815 (push (match-string 0) refs))
5816 (setq refs (nreverse refs)
5817 count (length refs)))
5819 ;; If the list has more than MAXCOUNT elements, trim it by
5820 ;; removing the CUTth element and the required number of
5821 ;; elements that follow.
5822 (when (> count maxcount)
5823 (let ((surplus (- count maxcount)))
5824 (message-shorten-1 refs cut surplus)
5825 (decf count surplus)))
5827 ;; When sending via news, make sure the total folded length will
5828 ;; be less than 998 characters. This is to cater to broken INN
5829 ;; 2.3 which counts the total number of characters in a header
5830 ;; rather than the physical line length of each line, as it shuld.
5832 ;; This hack should be removed when it's believed than INN 2.3 is
5833 ;; no longer widely used.
5835 ;; At this point the headers have not been generated, thus we use
5836 ;; message-this-is-news directly.
5837 (when message-this-is-news
5840 (message-insert-header
5841 header (mapconcat #'identity refs " "))
5843 (message-shorten-1 refs cut 1)))
5844 ;; Finally, collect the references back into a string and insert
5845 ;; it into the buffer.
5846 (message-insert-header header (mapconcat #'identity refs " "))))
5848 (defun message-position-point ()
5849 "Move point to where the user probably wants to find it."
5850 (message-narrow-to-headers)
5852 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
5853 (search-backward ":" )
5856 (if (eq (char-after) ? )
5860 (goto-char (point-max))
5863 (unless (looking-at "$")
5867 (defcustom message-beginning-of-line t
5868 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
5869 goes to beginning of header values."
5870 :group 'message-buffers
5871 :link '(custom-manual "(message)Movement")
5874 (defun message-beginning-of-line (&optional n)
5875 "Move point to beginning of header value or to beginning of line.
5876 The prefix argument N is passed directly to `beginning-of-line'.
5878 This command is identical to `beginning-of-line' if point is
5879 outside the message header or if the option `message-beginning-of-line'
5882 If point is in the message header and on a (non-continued) header
5883 line, move point to the beginning of the header value. If point
5884 is already there, move point to beginning of line. Therefore,
5885 repeated calls will toggle point between beginning of field and
5888 (let ((zrs 'zmacs-region-stays))
5889 (when (and (interactive-p) (boundp zrs))
5891 (if (and message-beginning-of-line
5892 (message-point-in-header-p))
5893 (let* ((here (point))
5894 (bol (progn (beginning-of-line n) (point)))
5895 (eol (point-at-eol))
5896 (eoh (re-search-forward ": *" eol t)))
5897 (if (or (not eoh) (equal here eoh))
5900 (beginning-of-line n)))
5902 (defun message-buffer-name (type &optional to group)
5903 "Return a new (unique) buffer name based on TYPE and TO."
5905 ;; Generate a new buffer name The Message Way.
5906 ((eq message-generate-new-buffers 'unique)
5907 (generate-new-buffer-name
5911 (or (car (std11-extract-address-components to))
5914 (if (and group (not (string= group ""))) (concat " on " group) "")
5916 ;; Check whether `message-generate-new-buffers' is a function,
5917 ;; and if so, call it.
5918 ((functionp message-generate-new-buffers)
5919 (funcall message-generate-new-buffers type to group))
5920 ((eq message-generate-new-buffers 'unsent)
5921 (generate-new-buffer-name
5922 (concat "*unsent " type
5925 (or (car (std11-extract-address-components to))
5928 (if (and group (not (string= group ""))) (concat " on " group) "")
5930 ;; Use standard name.
5932 (format "*%s message*" type))))
5934 (defmacro message-pop-to-buffer-1 (buffer)
5936 (let (special-display-buffer-names
5937 special-display-regexps
5938 same-window-buffer-names
5939 same-window-regexps)
5940 (pop-to-buffer ,buffer))
5941 (pop-to-buffer ,buffer)))
5943 (defun message-pop-to-buffer (name)
5944 "Pop to buffer NAME, and warn if it already exists and is modified."
5945 (let ((buffer (get-buffer name))
5946 (pop-up-frames (and (static-if (featurep 'xemacs)
5947 (device-on-window-system-p)
5949 message-use-multi-frames)))
5951 (buffer-name buffer))
5953 (message-pop-to-buffer-1 buffer)
5954 (when (and (buffer-modified-p)
5956 "Message already being composed; erase? ")))
5957 (error "Message being composed")))
5958 (message-pop-to-buffer-1 name))
5962 (set (make-local-variable 'message-original-frame) (selected-frame)))))
5964 (defun message-do-send-housekeeping ()
5965 "Kill old message buffers."
5966 ;; We might have sent this buffer already. Delete it from the
5968 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
5969 (while (and message-max-buffers
5971 (>= (length message-buffer-list) message-max-buffers))
5972 ;; Kill the oldest buffer -- unless it has been changed.
5973 (let ((buffer (pop message-buffer-list)))
5974 (when (and (buffer-name buffer)
5975 (not (buffer-modified-p buffer)))
5976 (kill-buffer buffer))))
5977 ;; Rename the buffer.
5978 (if message-send-rename-function
5979 (funcall message-send-rename-function)
5980 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
5982 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
5984 (let ((name (match-string 2 (buffer-name)))
5986 (if (not (or (null name)
5987 (string-equal name "mail")
5988 (string-equal name "posting")))
5989 (setq name (concat "*sent " name "*"))
5990 (message-narrow-to-headers)
5991 (setq to (message-fetch-field "to"))
5992 (setq group (message-fetch-field "newsgroups"))
5996 (to (concat "*sent mail to "
5997 (or (car (std11-extract-address-components to))
5999 ((and group (not (string= group "")))
6000 (concat "*sent posting on " group "*"))
6001 (t "*sent mail*"))))
6002 (unless (string-equal name (buffer-name))
6003 (rename-buffer name t)))))
6004 ;; Push the current buffer onto the list.
6005 (when message-max-buffers
6006 (setq message-buffer-list
6007 (nconc message-buffer-list (list (current-buffer))))))
6009 (defun message-mail-user-agent ()
6011 ((not message-mail-user-agent) nil)
6012 ((eq message-mail-user-agent t) mail-user-agent)
6013 (t message-mail-user-agent))))
6014 (if (memq mua '(message-user-agent gnus-user-agent))
6018 (defun message-setup (headers &optional replybuffer actions switch-function)
6019 (let ((mua (message-mail-user-agent))
6020 subject to field yank-action)
6021 (if (not (and message-this-is-mail mua))
6022 (message-setup-1 headers replybuffer actions)
6024 (setq yank-action (list 'insert-buffer replybuffer)))
6025 (setq headers (copy-sequence headers))
6026 (setq field (assq 'Subject headers))
6028 (setq subject (cdr field))
6029 (setq headers (delq field headers)))
6030 (setq field (assq 'To headers))
6032 (setq to (cdr field))
6033 (setq headers (delq field headers)))
6034 (let ((mail-user-agent mua))
6035 (compose-mail to subject
6036 (mapcar (lambda (item)
6038 (format "%s" (car item))
6041 nil switch-function yank-action actions)))))
6043 (defun message-headers-to-generate (headers included-headers excluded-headers)
6044 "Return a list that includes all headers from HEADERS.
6045 If INCLUDED-HEADERS is a list, just include those headers. If if is
6046 t, include all headers. In any case, headers from EXCLUDED-HEADERS
6050 (dolist (header headers)
6051 (setq header-name (cond
6052 ((and (consp header)
6053 (eq (car header) 'optional))
6054 ;; On the form (optional . Header)
6057 ;; On the form (Header . function)
6062 (when (and (not (memq header-name excluded-headers))
6063 (or (eq included-headers t)
6064 (memq header-name included-headers)))
6065 (push header result)))
6068 (defun message-setup-1 (headers &optional replybuffer actions)
6069 (dolist (action actions)
6071 (add-to-list 'message-send-actions
6072 `(apply ',(car action) ',(cdr action)))))
6073 (setq message-reply-buffer
6074 (or (message-get-parameter 'reply-buffer)
6076 (goto-char (point-min))
6077 ;; Insert all the headers.
6080 (alist message-header-format-alist))
6082 (unless (assq (caar h) message-header-format-alist)
6083 (push (list (caar h)) alist))
6087 (delete-region (point) (progn (forward-line -1) (point)))
6088 (when message-default-headers
6089 (insert message-default-headers)
6090 (or (bolp) (insert ?\n)))
6091 (insert mail-header-separator "\n")
6093 (when (message-news-p)
6094 (when message-default-news-headers
6095 (insert message-default-news-headers)
6096 (or (bolp) (insert ?\n)))
6097 (when message-generate-headers-first
6098 (message-generate-headers
6099 (message-headers-to-generate
6100 (append message-required-news-headers
6101 message-required-headers)
6102 message-generate-headers-first
6103 '(Lines Subject)))))
6104 (when (message-mail-p)
6105 (when message-default-mail-headers
6106 (insert message-default-mail-headers)
6107 (or (bolp) (insert ?\n)))
6109 (message-narrow-to-headers)
6110 (if (and replybuffer
6111 message-alternative-emails)
6112 (message-use-alternative-email-as-from)))
6113 (when message-generate-headers-first
6114 (message-generate-headers
6115 (message-headers-to-generate
6116 (append message-required-mail-headers
6117 message-required-headers)
6118 message-generate-headers-first
6119 '(Lines Subject)))))
6120 (run-hooks 'message-signature-setup-hook)
6121 (message-insert-signature)
6123 (message-narrow-to-headers)
6124 (run-hooks 'message-header-setup-hook))
6125 (set-buffer-modified-p nil)
6126 (setq buffer-undo-list nil)
6127 (run-hooks 'message-setup-hook)
6128 (message-position-point)
6131 (defun message-set-auto-save-file-name ()
6132 "Associate the message buffer with a file in the drafts directory."
6133 (when message-auto-save-directory
6134 (unless (file-directory-p
6135 (directory-file-name message-auto-save-directory))
6136 (make-directory message-auto-save-directory t))
6138 (setq message-draft-article
6139 (nndraft-request-associate-buffer "drafts"))
6140 (setq buffer-file-name (expand-file-name
6141 (if (memq system-type
6142 '(ms-dos ms-windows windows-nt
6143 cygwin cygwin32 win32 w32
6147 message-auto-save-directory))
6148 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
6149 (clear-visited-file-modtime)
6150 (setq buffer-file-coding-system message-draft-coding-system)))
6152 (defun message-disassociate-draft ()
6153 "Disassociate the message buffer from the drafts directory."
6154 (when message-draft-article
6155 (nndraft-request-expire-articles
6156 (list message-draft-article) "drafts" nil t)))
6158 (defun message-insert-headers ()
6159 "Generate the headers for the article."
6163 (message-narrow-to-headers)
6164 (when (message-news-p)
6165 (message-generate-headers
6168 (copy-sequence message-required-news-headers)))))
6169 (when (message-mail-p)
6170 (message-generate-headers
6173 (copy-sequence message-required-mail-headers))))))))
6178 ;;; Commands for interfacing with message
6182 (defun message-mail (&optional to subject
6183 other-headers continue switch-function
6184 yank-action send-actions)
6185 "Start editing a mail message to be sent.
6186 OTHER-HEADERS is an alist of header/value pairs."
6188 (let ((message-this-is-mail t) replybuffer)
6189 (unless (message-mail-user-agent)
6190 (message-pop-to-buffer (message-buffer-name "mail" to)))
6191 ;; FIXME: message-mail should do something if YANK-ACTION is not
6193 (and (consp yank-action) (eq (car yank-action) 'insert-buffer)
6194 (setq replybuffer (nth 1 yank-action)))
6197 `((To . ,(or to "")) (Subject . ,(or subject "")))
6198 (when other-headers other-headers))
6199 replybuffer send-actions)
6200 ;; FIXME: Should return nil if failure.
6204 (defun message-news (&optional newsgroups subject)
6205 "Start editing a news article to be sent."
6207 (let ((message-this-is-news t))
6208 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
6209 (message-setup `((Newsgroups . ,(or newsgroups ""))
6210 (Subject . ,(or subject ""))))))
6212 (defun message-get-reply-headers (wide &optional to-address address-headers)
6213 (let (follow-to mct never-mct to cc author mft recipients)
6214 ;; Find all relevant headers we need.
6216 (message-narrow-to-headers-or-head)
6217 (let ((mrt (when message-use-mail-reply-to
6218 (message-fetch-field "mail-reply-to")))
6219 (reply-to (message-fetch-field "reply-to")))
6220 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
6221 ;; message-header-synonyms.
6222 (setq to (or (message-fetch-field "to")
6223 (and (loop for synonym in message-header-synonyms
6224 when (memq 'Original-To synonym)
6226 (message-fetch-field "original-to")))
6227 cc (message-fetch-field "cc")
6228 mct (when message-use-mail-copies-to
6229 (message-fetch-field "mail-copies-to"))
6232 (message-fetch-field "from")
6234 mft (when (and (not (or to-address mrt reply-to))
6235 message-use-mail-followup-to)
6236 (message-fetch-field "mail-followup-to")))))
6239 ;; Handle special values of Mail-Copies-To.
6241 (cond ((or (equal (downcase mct) "never")
6242 (equal (downcase mct) "nobody"))
6243 (when (or (not (eq message-use-mail-copies-to 'ask))
6245 (concat "Obey Mail-Copies-To: never? ") t "\
6246 You should normally obey the Mail-Copies-To: header.
6248 `Mail-Copies-To: " mct "'
6249 directs you not to send your response to the author."))
6252 ((or (equal (downcase mct) "always")
6253 (equal (downcase mct) "poster"))
6254 (if (or (not (eq message-use-mail-copies-to 'ask))
6256 (concat "Obey Mail-Copies-To: always? ") t "\
6257 You should normally obey the Mail-Copies-To: header.
6259 `Mail-Copies-To: " mct "'
6260 sends a copy of your response to the author."))
6263 ((and (eq message-use-mail-copies-to 'ask)
6264 (not (message-y-or-n-p
6265 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
6266 You should normally obey the Mail-Copies-To: header.
6268 `Mail-Copies-To: " mct "'
6269 sends a copy of your response to " (if (string-match "," mct)
6270 "the specified addresses"
6271 "that address") ".")))
6274 ;; Build (textual) list of new recipient addresses.
6277 (setq recipients (concat ", " author)))
6279 (dolist (header address-headers)
6280 (let ((value (message-fetch-field header)))
6282 (setq recipients (concat recipients ", " value))))))
6284 (string-match "[^ \t,]" mft)
6285 (or (not (eq message-use-mail-followup-to 'ask))
6286 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
6287 You should normally obey the Mail-Followup-To: header. In this
6288 article, it has the value of
6292 which directs your response to " (if (string-match "," mft)
6293 "the specified addresses"
6294 "that address only") ".
6296 Most commonly, Mail-Followup-To is used by a mailing list poster to
6297 express that responses should be sent to just the list, and not the
6300 If a message is posted to several mailing lists, Mail-Followup-To may
6301 also be used to direct the following discussion to one list only,
6302 because discussions that are spread over several lists tend to be
6303 fragmented and very difficult to follow.
6305 Also, some source/announcement lists are not intended for discussion;
6306 responses here are directed to other addresses.")))
6307 (setq recipients (concat ", " mft)))
6309 (setq recipients (concat ", " to-address))
6310 ;; If the author explicitly asked for a copy, we don't deny it to them.
6311 (if mct (setq recipients (concat recipients ", " mct))))
6313 (setq recipients (if never-mct "" (concat ", " author)))
6314 (if to (setq recipients (concat recipients ", " to)))
6315 (if cc (setq recipients (concat recipients ", " cc)))
6316 (if mct (setq recipients (concat recipients ", " mct)))))
6317 (if (>= (length recipients) 2)
6318 ;; Strip the leading ", ".
6319 (setq recipients (substring recipients 2)))
6320 ;; Squeeze whitespace.
6321 (while (string-match "[ \t][ \t]+" recipients)
6322 (setq recipients (replace-match " " t t recipients)))
6323 ;; Remove addresses that match `rmail-dont-reply-to-names'.
6324 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
6325 (setq recipients (rmail-dont-reply-to recipients)))
6326 ;; Perhaps "Mail-Copies-To: never" removed the only address?
6327 (if (string-equal recipients "")
6328 (setq recipients author))
6329 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
6333 (cons (downcase (mail-strip-quoted-names addr)) addr))
6334 (message-tokenize-header recipients)))
6335 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
6336 (let ((s recipients))
6338 (setq recipients (delq (assoc (car (pop s)) s) recipients))))
6340 ;; Remove hierarchical lists that are contained within each other,
6341 ;; if message-hierarchical-addresses is defined.
6342 (when message-hierarchical-addresses
6343 (let ((plain-addrs (mapcar 'car recipients))
6346 (setq subaddrs (assoc (car plain-addrs)
6347 message-hierarchical-addresses)
6348 plain-addrs (cdr plain-addrs))
6350 (setq subaddrs (cdr subaddrs))
6352 (setq recip (assoc (car subaddrs) recipients)
6353 subaddrs (cdr subaddrs))
6355 (setq recipients (delq recip recipients))))))))
6357 ;; Build the header alist. Allow the user to be asked whether
6358 ;; or not to reply to all recipients in a wide reply.
6359 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
6360 (when (and recipients
6361 (or (not message-wide-reply-confirm-recipients)
6362 (y-or-n-p "Reply to all recipients? ")))
6363 (setq recipients (mapconcat
6364 (lambda (addr) (cdr addr)) recipients ", "))
6365 (if (string-match "^ +" recipients)
6366 (setq recipients (substring recipients (match-end 0))))
6367 (push (cons 'Cc recipients) follow-to)))
6371 (defun message-reply (&optional to-address wide)
6372 "Start editing a reply to the article in the current buffer."
6374 (require 'gnus-sum) ; for gnus-list-identifiers
6375 (let ((cur (current-buffer))
6377 references message-id follow-to
6378 (inhibit-point-motion-hooks t)
6379 (message-this-is-mail t)
6380 gnus-warning in-reply-to)
6382 (message-narrow-to-head-1)
6383 ;; Allow customizations to have their say.
6385 ;; This is a regular reply.
6386 (when (functionp message-reply-to-function)
6388 (setq follow-to (funcall message-reply-to-function))))
6389 ;; This is a followup.
6390 (when (functionp message-wide-reply-to-function)
6393 (funcall message-wide-reply-to-function)))))
6394 (setq message-id (message-fetch-field "message-id" t)
6395 references (message-fetch-field "references")
6396 date (message-fetch-field "date")
6397 from (message-fetch-field "from")
6398 subject (or (message-fetch-field "subject") "none"))
6399 (when gnus-list-identifiers
6400 (setq subject (message-strip-list-identifiers subject)))
6401 (setq subject (message-make-followup-subject subject))
6402 (when message-subject-trailing-was-query
6403 (setq subject (message-strip-subject-trailing-was subject)))
6405 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6406 (string-match "<[^>]+>" gnus-warning))
6407 (setq message-id (match-string 0 gnus-warning)))
6410 (setq follow-to (message-get-reply-headers wide to-address)))
6412 ;; Get the references from "In-Reply-To" field if there were
6413 ;; no references and "In-Reply-To" field looks promising.
6415 (when (and (setq in-reply-to (message-fetch-field "in-reply-to"))
6416 (string-match "<[^>]+>" in-reply-to))
6417 (setq references (match-string 0 in-reply-to)))))
6419 (unless (message-mail-user-agent)
6420 (message-pop-to-buffer
6421 (message-buffer-name
6422 (if wide "wide reply" "reply") from
6423 (if wide to-address nil))))
6425 (setq message-reply-headers
6426 (make-full-mail-header-from-decoded-header
6427 0 subject from date message-id references 0 0 ""))
6430 `((Subject . ,subject)
6435 (defun message-wide-reply (&optional to-address)
6436 "Make a \"wide\" reply to the message in the current buffer."
6438 (message-reply to-address t))
6441 (defun message-followup (&optional to-newsgroups)
6442 "Follow up to the message in the current buffer.
6443 If TO-NEWSGROUPS, use that as the new Newsgroups line."
6445 (require 'gnus-sum) ; for gnus-list-identifiers
6446 (let ((cur (current-buffer))
6447 from subject date reply-to mrt mct mft
6448 references message-id follow-to
6449 (inhibit-point-motion-hooks t)
6450 (message-this-is-news t)
6451 followup-to distribution newsgroups gnus-warning posted-to)
6453 (message-narrow-to-head)
6454 (when (functionp message-followup-to-function)
6456 (funcall message-followup-to-function)))
6457 (setq from (message-fetch-field "from")
6458 date (message-fetch-field "date")
6459 subject (or (message-fetch-field "subject") "none")
6460 references (message-fetch-field "references")
6461 message-id (message-fetch-field "message-id" t)
6462 followup-to (message-fetch-field "followup-to")
6463 newsgroups (message-fetch-field "newsgroups")
6464 posted-to (message-fetch-field "posted-to")
6465 reply-to (message-fetch-field "reply-to")
6466 mrt (when message-use-mail-reply-to
6467 (message-fetch-field "mail-reply-to"))
6468 distribution (message-fetch-field "distribution")
6469 mct (when message-use-mail-copies-to
6470 (message-fetch-field "mail-copies-to"))
6471 mft (when message-use-mail-followup-to
6472 (message-fetch-field "mail-followup-to")))
6473 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6474 (string-match "<[^>]+>" gnus-warning))
6475 (setq message-id (match-string 0 gnus-warning)))
6476 ;; Remove bogus distribution.
6477 (when (and (stringp distribution)
6478 (let ((case-fold-search t))
6479 (string-match "world" distribution)))
6480 (setq distribution nil))
6481 (if gnus-list-identifiers
6482 (setq subject (message-strip-list-identifiers subject)))
6483 (setq subject (message-make-followup-subject subject))
6484 (when message-subject-trailing-was-query
6485 (setq subject (message-strip-subject-trailing-was subject)))
6488 ;; Handle special values of Mail-Copies-To.
6491 ((and (or (equal (downcase mct) "never")
6492 (equal (downcase mct) "nobody")))
6494 ((and (or (equal (downcase mct) "always")
6495 (equal (downcase mct) "poster")))
6496 (if (or (not (eq message-use-mail-copies-to 'ask))
6498 (concat "Obey Mail-Copies-To: always? ") t "\
6499 You should normally obey the Mail-Copies-To: header.
6501 `Mail-Copies-To: " mct "'
6502 sends a copy of your response to the author."))
6503 (setq mct (or mrt reply-to from))
6505 ((and (eq message-use-mail-copies-to 'ask)
6508 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
6509 You should normally obey the Mail-Copies-To: header.
6511 `Mail-Copies-To: " mct "'
6512 sends a copy of your response to " (if (string-match "," mct)
6513 "the specified addresses"
6514 "that address") ".")))
6519 (to-newsgroups (setq follow-to (list (cons 'Newsgroups to-newsgroups))))
6520 ;; Handle Followup-To.
6523 ((equal (downcase followup-to) "poster")
6524 (if (or (and followup-to (eq message-use-followup-to 'use))
6525 (message-y-or-n-p "Obey Followup-To: poster? " t "\
6526 You should normally obey the Followup-To: header.
6528 `Followup-To: poster'
6529 sends your response via e-mail instead of news.
6531 A typical situation where `Followup-To: poster' is used is when the author
6532 does not read the newsgroup, so he wouldn't see any replies sent to it."))
6533 (setq message-this-is-news nil
6535 follow-to (list (cons 'To (or mrt reply-to from ""))))
6536 (setq follow-to (list (cons 'Newsgroups newsgroups)))))
6538 (if (or (equal followup-to newsgroups)
6539 (not (and followup-to (eq message-use-followup-to 'ask)))
6541 (concat "Obey Followup-To: " followup-to "? ") t "\
6542 You should normally obey the Followup-To: header.
6544 `Followup-To: " followup-to "'
6545 directs your response to " (if (string-match "," followup-to)
6546 "the specified newsgroups"
6547 "that newsgroup only") ".
6549 If a message is posted to several newsgroups, Followup-To is often
6550 used to direct the following discussion to one newsgroup only,
6551 because discussions that are spread over several newsgroup tend to
6552 be fragmented and very difficult to follow.
6554 Also, some source/announcement newsgroups are not intended for discussion;
6555 responses here are directed to other newsgroups."))
6556 (setq follow-to (list (cons 'Newsgroups followup-to)))
6557 (setq follow-to (list (cons 'Newsgroups newsgroups)))))))
6558 ;; Handle Mail-Followup-To, followup via e-mail.
6560 (or (not (eq message-use-mail-followup-to 'ask))
6562 (concat "Obey Mail-Followup-To: " mft "? ") t "\
6563 You should normally obey the Mail-Followup-To: header.
6565 `Mail-Followup-To: " mft "'
6566 directs your response to " (if (string-match "," mft)
6567 "the specified addresses"
6568 "that address only") " instead of news.
6570 A typical situation where Mail-Followup-To is used is when the author thinks
6571 that further discussion should take place only in "
6572 (if (string-match "," mft)
6573 "the specified mailing lists"
6574 "that mailing list") ".")))
6575 (setq message-this-is-news nil
6577 follow-to (list (cons 'To mft))))
6578 (posted-to (setq follow-to (list (cons 'Newsgroups posted-to))))
6580 (setq follow-to (list (cons 'Newsgroups newsgroups))))))
6582 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
6584 (setq message-reply-headers
6585 (make-full-mail-header-from-decoded-header
6586 0 subject from date message-id references 0 0 ""))
6589 `((Subject . ,subject)
6591 ,@(and mct (list (cons 'Cc mct)))
6592 ,@(and distribution (list (cons 'Distribution distribution))))
6595 (defun message-is-yours-p ()
6596 "Non-nil means current article is yours.
6597 If you have added 'cancel-messages to 'message-shoot-gnksa-feet', all articles
6598 are yours except those that have Cancel-Lock header not belonging to you.
6599 Instead of shooting GNKSA feet, you should modify 'message-alternative-emails'
6600 regexp to match all of yours addresses."
6601 ;; Canlock-logic as suggested by Per Abrahamsen
6602 ;; <abraham@dina.kvl.dk>
6604 ;; IF article has cancel-lock THEN
6605 ;; IF we can verify it THEN
6608 ;; error: cancellock: article is not yours
6610 ;; Use old rules, comparing sender...
6613 (message-narrow-to-head-1)
6614 (if (message-fetch-field "Cancel-Lock")
6615 (if (null (canlock-verify))
6617 (error "Failed to verify Cancel-lock: This article is not yours"))
6620 (message-gnksa-enable-p 'cancel-messages)
6621 (and (setq sender (message-fetch-field "sender"))
6622 (string-equal (downcase sender)
6623 (downcase (message-make-sender))))
6624 ;; Email address in From field equals to our address
6625 (and (setq from (message-fetch-field "from"))
6627 (downcase (cadr (std11-extract-address-components from)))
6628 (downcase (cadr (std11-extract-address-components
6629 (message-make-from))))))
6630 ;; Email address in From field matches
6631 ;; 'message-alternative-emails' regexp
6633 message-alternative-emails
6635 message-alternative-emails
6636 (cadr (std11-extract-address-components from))))))))))
6639 (defun message-cancel-news (&optional arg)
6640 "Cancel an article you posted.
6641 If ARG, allow editing of the cancellation message."
6643 (unless (message-news-p)
6644 (error "This is not a news article; canceling is impossible"))
6645 (let (from newsgroups message-id distribution buf)
6647 ;; Get header info from original article.
6649 (message-narrow-to-head-1)
6650 (setq from (message-fetch-field "from")
6651 newsgroups (message-fetch-field "newsgroups")
6652 message-id (message-fetch-field "message-id" t)
6653 distribution (message-fetch-field "distribution")))
6654 ;; Make sure that this article was written by the user.
6655 (unless (message-is-yours-p)
6656 (error "This article is not yours"))
6657 (when (yes-or-no-p "Do you really want to cancel this article? ")
6658 ;; Make control message.
6661 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
6663 (insert "Newsgroups: " newsgroups "\n"
6665 "Subject: cmsg cancel " message-id "\n"
6666 "Control: cancel " message-id "\n"
6668 (concat "Distribution: " distribution "\n")
6670 mail-header-separator "\n"
6671 message-cancel-message)
6672 (run-hooks 'message-cancel-hook)
6674 (message "Canceling your article...")
6675 (if (let ((message-syntax-checks
6676 'dont-check-for-anything-just-trust-me)
6677 (message-encoding-buffer (current-buffer))
6678 (message-edit-buffer (current-buffer)))
6679 (message-send-news))
6680 (message "Canceling your article...done"))
6681 (kill-buffer buf))))))
6683 (defun message-supersede-setup-for-mime-edit ()
6684 (set (make-local-variable 'message-setup-hook) nil)
6688 (defun message-supersede ()
6689 "Start composing a message to supersede the current message.
6690 This is done simply by taking the old article and adding a Supersedes
6691 header line with the old Message-ID."
6693 (let ((cur (current-buffer)))
6694 ;; Check whether the user owns the article that is to be superseded.
6695 (unless (message-is-yours-p)
6696 (error "This article is not yours"))
6697 ;; Get a normal message buffer.
6698 (message-pop-to-buffer (message-buffer-name "supersede"))
6699 (insert-buffer-substring cur)
6700 (message-narrow-to-head-1)
6701 ;; Remove unwanted headers.
6702 (when message-ignored-supersedes-headers
6703 (message-remove-header message-ignored-supersedes-headers t))
6704 (goto-char (point-min))
6705 (if (not (re-search-forward "^Message-ID: " nil t))
6706 (error "No Message-ID in this article")
6707 (replace-match "Supersedes: " t t))
6708 (goto-char (point-max))
6709 (insert mail-header-separator)
6711 (when message-supersede-setup-function
6712 (funcall message-supersede-setup-function))
6713 (run-hooks 'message-supersede-setup-hook)
6714 (goto-char (point-min))
6715 (search-forward (concat "\n" mail-header-separator "\n") nil t)))
6718 (defun message-recover ()
6719 "Reread contents of current buffer from its last auto-save file."
6721 (let ((file-name (make-auto-save-file-name)))
6722 (cond ((save-window-excursion
6723 (if (not (eq system-type 'vax-vms))
6724 (with-output-to-temp-buffer "*Directory*"
6725 (with-current-buffer standard-output
6726 (fundamental-mode)) ; for Emacs 20.4+
6727 (buffer-disable-undo standard-output)
6728 (let ((default-directory "/"))
6730 "ls" nil standard-output nil "-l" file-name))))
6731 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
6732 (let ((buffer-read-only nil))
6734 (insert-file-contents file-name nil)))
6735 (t (error "message-recover cancelled")))))
6737 ;;; Washing Subject:
6739 (defun message-wash-subject (subject)
6740 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
6741 Previous forwarders, replyers, etc. may add it."
6744 (goto-char (point-min))
6745 ;; strip Re/Fwd stuff off the beginning
6746 (while (re-search-forward
6747 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
6750 ;; and gnus-style forwards [foo@bar.com] subject
6751 (goto-char (point-min))
6752 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
6756 (goto-char (point-max))
6757 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
6760 ;; and finally, any whitespace that was left-over
6761 (goto-char (point-min))
6762 (while (re-search-forward "^[ \t]+" nil t)
6764 (goto-char (point-max))
6765 (while (re-search-backward "[ \t]+$" nil t)
6770 ;;; Forwarding messages.
6772 (defvar message-forward-decoded-p nil
6773 "Non-nil means the original message is decoded.")
6775 (defun message-forward-subject-name-subject (subject)
6776 "Generate a SUBJECT for a forwarded message.
6777 The form is: [Source] Subject, where if the original message was mail,
6778 Source is the name of the sender, and if the original message was
6779 news, Source is the list of newsgroups is was posted to."
6781 (let ((group (message-fetch-field "newsgroups"))
6784 (gnus-group-decoded-name group)
6785 (or (and (setq from (message-fetch-field "from"))
6786 (car (std11-extract-address-components
6787 (nnheader-decode-from from))))
6791 (defun message-forward-subject-author-subject (subject)
6792 "Generate a SUBJECT for a forwarded message.
6793 The form is: [Source] Subject, where if the original message was mail,
6794 Source is the sender, and if the original message was news, Source is
6795 the list of newsgroups is was posted to."
6797 (let ((group (message-fetch-field "newsgroups"))
6800 (gnus-group-decoded-name group)
6801 (if (setq from (message-fetch-field "from"))
6802 (nnheader-decode-from from)
6806 (defun message-forward-subject-fwd (subject)
6807 "Generate a SUBJECT for a forwarded message.
6808 The form is: Fwd: Subject, where Subject is the original subject of
6810 (if (string-match "^Fwd: " subject)
6812 (concat "Fwd: " subject)))
6814 (defun message-make-forward-subject ()
6815 "Return a Subject header suitable for the message in the current buffer."
6818 (message-narrow-to-head-1)
6819 (let ((funcs message-make-forward-subject-function)
6820 (subject (message-fetch-field "Subject")))
6823 (if message-forward-decoded-p
6825 (nnheader-decode-subject subject))
6827 (if message-wash-forwarded-subjects
6828 (setq subject (message-wash-subject subject)))
6829 ;; Make sure funcs is a list.
6832 (setq funcs (list funcs)))
6833 ;; Apply funcs in order, passing subject generated by previous
6834 ;; func to the next one.
6836 (when (functionp (car funcs))
6837 (setq subject (funcall (car funcs) subject)))
6838 (setq funcs (cdr funcs)))
6842 (defun message-forward (&optional news)
6843 "Forward the current message via mail.
6844 Optional NEWS will use news to forward instead of mail."
6846 (let ((cur (current-buffer))
6847 (subject (message-make-forward-subject)))
6849 (message-news nil subject)
6850 (message-mail nil subject))
6851 (message-forward-make-body cur)))
6853 (defun message-forward-make-body-plain (forward-buffer)
6855 "\n-------------------- Start of forwarded message --------------------\n")
6856 (let ((b (point)) e)
6859 (mm-disable-multibyte)
6861 (with-current-buffer forward-buffer
6862 (mm-with-unibyte-current-buffer (buffer-string))))
6863 (mm-enable-multibyte)
6865 (goto-char (point-min))
6866 (when (looking-at "From ")
6867 (replace-match "X-From-Line: "))
6871 "\n-------------------- End of forwarded message --------------------\n")
6872 (when (and (not current-prefix-arg)
6873 message-forward-ignored-headers)
6875 (narrow-to-region b e)
6877 (narrow-to-region (point)
6878 (or (search-forward "\n\n" nil t) (point)))
6879 (message-remove-header message-forward-ignored-headers t)))))
6881 (defun message-forward-make-body-mime (forward-buffer)
6882 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
6883 (let ((b (point)) e)
6885 (narrow-to-region (point) (point))
6886 (mml-insert-buffer forward-buffer)
6887 (goto-char (point-min))
6888 (when (looking-at "From ")
6889 (replace-match "X-From-Line: "))
6890 (goto-char (point-max)))
6892 (insert "<#/part>\n")))
6894 (defun message-forward-make-body-mml (forward-buffer)
6895 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
6896 (let ((b (point)) e)
6897 (if (not message-forward-decoded-p)
6900 (mm-disable-multibyte)
6902 (with-current-buffer forward-buffer
6903 (mm-with-unibyte-current-buffer (buffer-string))))
6904 (mm-enable-multibyte)
6906 (goto-char (point-min))
6907 (when (looking-at "From ")
6908 (replace-match "X-From-Line: "))
6911 (narrow-to-region (point) (point))
6912 (mml-insert-buffer forward-buffer)
6913 (goto-char (point-min))
6914 (when (looking-at "From ")
6915 (replace-match "X-From-Line: "))
6916 (goto-char (point-max))))
6918 (insert "<#/mml>\n")
6919 (when (and (not current-prefix-arg)
6920 message-forward-ignored-headers)
6922 (narrow-to-region b e)
6924 (narrow-to-region (point)
6925 (or (search-forward "\n\n" nil t) (point)))
6926 (message-remove-header message-forward-ignored-headers t)))))
6928 (defun message-forward-make-body-digest-plain (forward-buffer)
6930 "\n-------------------- Start of forwarded message --------------------\n")
6931 (let ((b (point)) e)
6932 (mml-insert-buffer forward-buffer)
6935 "\n-------------------- End of forwarded message --------------------\n")))
6937 (defun message-forward-make-body-digest-mime (forward-buffer)
6938 (insert "\n<#multipart type=digest>\n")
6939 (let ((b (point)) e)
6940 (insert-buffer-substring forward-buffer)
6942 (insert "<#/multipart>\n")
6944 (narrow-to-region b e)
6946 (narrow-to-region (point)
6947 (or (search-forward "\n\n" nil t) (point)))
6948 (delete-region (point-min) (point-max)))))
6950 (defun message-forward-make-body-digest (forward-buffer)
6951 (if message-forward-as-mime
6952 (message-forward-make-body-digest-mime forward-buffer)
6953 (message-forward-make-body-digest-plain forward-buffer)))
6956 (defun message-forward-make-body (forward-buffer)
6957 ;; Put point where we want it before inserting the forwarded
6959 ;; Note that this function definition for T-gnus is totally different
6960 ;; from the original Gnus."
6961 (if message-forward-before-signature
6963 (goto-char (point-max)))
6964 ;; Make sure we're at the start of the line.
6967 ;; Narrow to the area we are to insert.
6968 (narrow-to-region (point) (point))
6969 ;; Insert the separators and the forwarded buffer.
6970 (insert message-forward-start-separator)
6971 (let ((art-beg (point)))
6972 (insert-buffer-substring forward-buffer)
6973 (goto-char (point-max))
6974 (insert message-forward-end-separator)
6975 (set-text-properties (point-min) (point-max) nil)
6976 ;; Remove all unwanted headers.
6978 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
6981 (goto-char (point-min))
6982 (message-remove-header message-included-forward-headers t nil t)
6984 (message-position-point)))
6987 (defun message-forward-rmail-make-body (forward-buffer)
6988 (save-window-excursion
6989 (set-buffer forward-buffer)
6990 (if (rmail-msg-is-pruned)
6991 (rmail-msg-restore-non-pruned-header)))
6992 (message-forward-make-body forward-buffer))
6994 (eval-when-compile (defvar rmail-enable-mime-composing))
6996 ;; Fixme: Should have defcustom.
6998 (defun message-insinuate-rmail ()
6999 "Let RMAIL use message to forward."
7001 (setq rmail-enable-mime-composing t)
7002 (setq rmail-insert-mime-forwarded-message-function
7003 'message-forward-rmail-make-body))
7006 (defun message-resend (address)
7007 "Resend the current article to ADDRESS."
7009 (list (message-read-from-minibuffer "Resend message to: ")))
7010 (message "Resending message to %s..." address)
7012 (let ((cur (current-buffer))
7014 ;; We first set up a normal mail buffer.
7015 (unless (message-mail-user-agent)
7016 (set-buffer (get-buffer-create " *message resend*"))
7018 (let ((message-this-is-mail t)
7020 (message-setup `((To . ,address))))
7021 ;; Insert our usual headers.
7022 (message-generate-headers '(From Date To Message-ID))
7023 (message-narrow-to-headers)
7024 ;; Remove X-Draft-From header etc.
7025 (message-remove-header message-ignored-mail-headers t)
7026 ;; Rename them all to "Resent-*".
7027 (goto-char (point-min))
7028 (while (re-search-forward "^[A-Za-z]" nil t)
7033 (delete-region (point) (point-max))
7035 ;; Insert the message to be resent.
7036 (insert-buffer-substring cur)
7037 (goto-char (point-min))
7038 (search-forward "\n\n")
7041 (narrow-to-region beg (point))
7042 (message-remove-header message-ignored-resent-headers t)
7043 (goto-char (point-max)))
7044 (insert mail-header-separator)
7045 ;; Rename all old ("Also-")Resent headers.
7046 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
7049 ;; Quote any "From " lines at the beginning.
7051 (when (looking-at "From ")
7052 (replace-match "X-From-Line: "))
7054 (let ((message-encoding-buffer (current-buffer))
7055 (message-edit-buffer (current-buffer))
7056 message-required-mail-headers)
7057 (message-send-mail))
7058 (kill-buffer (current-buffer)))
7059 (message "Resending message to %s...done" address)))
7061 (defun message-bounce-setup-for-mime-edit ()
7062 (set (make-local-variable 'message-setup-hook) nil)
7066 (defun message-bounce ()
7067 "Re-mail the current message.
7068 This only makes sense if the current message is a bounce message that
7069 contains some mail you have written which has been bounced back to
7072 (let ((cur (current-buffer))
7073 mime-boundary boundary)
7074 (message-pop-to-buffer (message-buffer-name "bounce"))
7075 (insert-buffer-substring cur)
7077 (message-narrow-to-head)
7078 (if (and (message-fetch-field "MIME-Version")
7079 (setq mime-boundary (message-fetch-field "Content-Type")))
7080 (if (string-match "boundary=\"\\([^\"]+\\)\"" mime-boundary)
7081 (setq mime-boundary (concat (regexp-quote
7082 (match-string 1 mime-boundary))
7083 " *\nContent-Type: message/rfc822"))
7084 (setq mime-boundary nil)))
7086 (goto-char (point-min))
7087 (re-search-forward "\n\n+" nil t)
7088 (setq boundary (point))
7089 ;; We remove everything before the bounced mail.
7090 (if (or (and mime-boundary
7091 (re-search-forward mime-boundary nil t)
7093 (re-search-forward message-unsent-separator nil t)
7095 (search-forward "\n\n" nil 'move)
7096 (re-search-backward "^Return-Path:.*\n" boundary t)))
7099 (delete-region (point-min)
7100 (if (re-search-forward "^[^ \n\t]+:" nil t)
7103 (when (re-search-backward "^.?From .*\n" nil t)
7104 (delete-region (match-beginning 0) (match-end 0))))
7106 (message-narrow-to-head-1)
7107 (message-remove-header message-ignored-bounced-headers t)
7108 (goto-char (point-max))
7109 (insert mail-header-separator))
7110 (when message-bounce-setup-function
7111 (funcall message-bounce-setup-function))
7112 (run-hooks 'message-bounce-setup-hook)
7113 (message-position-point)))
7116 ;;; Interactive entry points for new message buffers.
7120 (defun message-mail-other-window (&optional to subject)
7121 "Like `message-mail' command, but display mail buffer in another window."
7123 (unless (message-mail-user-agent)
7124 (let ((pop-up-windows t)
7125 (special-display-buffer-names nil)
7126 (special-display-regexps nil)
7127 (same-window-buffer-names nil)
7128 (same-window-regexps nil))
7129 (message-pop-to-buffer (message-buffer-name "mail" to))))
7130 (let ((message-this-is-mail t))
7131 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7132 nil nil 'switch-to-buffer-other-window)))
7135 (defun message-mail-other-frame (&optional to subject)
7136 "Like `message-mail' command, but display mail buffer in another frame."
7138 (unless (message-mail-user-agent)
7139 (let ((pop-up-frames t)
7140 (special-display-buffer-names nil)
7141 (special-display-regexps nil)
7142 (same-window-buffer-names nil)
7143 (same-window-regexps nil))
7144 (message-pop-to-buffer (message-buffer-name "mail" to))))
7145 (let ((message-this-is-mail t))
7146 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7147 nil nil 'switch-to-buffer-other-frame)))
7150 (defun message-news-other-window (&optional newsgroups subject)
7151 "Start editing a news article to be sent."
7153 (let ((pop-up-windows t)
7154 (special-display-buffer-names nil)
7155 (special-display-regexps nil)
7156 (same-window-buffer-names nil)
7157 (same-window-regexps nil))
7158 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
7159 (let ((message-this-is-news t))
7160 (message-setup `((Newsgroups . ,(or newsgroups ""))
7161 (Subject . ,(or subject ""))))))
7164 (defun message-news-other-frame (&optional newsgroups subject)
7165 "Start editing a news article to be sent."
7167 (let ((pop-up-frames t)
7168 (special-display-buffer-names nil)
7169 (special-display-regexps nil)
7170 (same-window-buffer-names nil)
7171 (same-window-regexps nil))
7172 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
7173 (let ((message-this-is-news t))
7174 (message-setup `((Newsgroups . ,(or newsgroups ""))
7175 (Subject . ,(or subject ""))))))
7179 ;; This code should be moved to underline.el (from which it is stolen).
7182 (defun bold-region (start end)
7183 "Bold all nonblank characters in the region.
7184 Works by overstriking characters.
7185 Called from program, takes two arguments START and END
7186 which specify the range to operate on."
7189 (let ((end1 (make-marker)))
7190 (move-marker end1 (max start end))
7191 (goto-char (min start end))
7192 (while (< (point) end1)
7193 (or (looking-at "[_\^@- ]")
7194 (insert (char-after) "\b"))
7195 (forward-char 1)))))
7198 (defun unbold-region (start end)
7199 "Remove all boldness (overstruck characters) in the region.
7200 Called from program, takes two arguments START and END
7201 which specify the range to operate on."
7204 (let ((end1 (make-marker)))
7205 (move-marker end1 (max start end))
7206 (goto-char (min start end))
7207 (while (re-search-forward "\b" end1 t)
7208 (if (eq (char-after) (char-after (- (point) 2)))
7209 (delete-char -2))))))
7211 (defun message-exchange-point-and-mark ()
7212 "Exchange point and mark, but don't activate region if it was inactive."
7214 (message-mark-active-p)
7215 (exchange-point-and-mark))
7216 (setq mark-active nil)))
7218 (defalias 'message-make-overlay 'make-overlay)
7219 (defalias 'message-delete-overlay 'delete-overlay)
7220 (defalias 'message-overlay-put 'overlay-put)
7221 (defun message-kill-all-overlays ()
7222 (if (featurep 'xemacs)
7223 (map-extents (lambda (extent ignore) (delete-extent extent)))
7224 (mapcar #'delete-overlay (overlays-in (point-min) (point-max)))))
7226 ;; Support for toolbar
7228 (defvar tool-bar-map)
7229 (defvar tool-bar-mode))
7231 (defun message-tool-bar-local-item-from-menu (command icon in-map &optional from-map &rest props)
7232 ;; We need to make tool bar entries in local keymaps with
7233 ;; `tool-bar-local-item-from-menu' in Emacs > 21.3
7234 (if (fboundp 'tool-bar-local-item-from-menu)
7235 ;; This is for Emacs 21.3
7236 (tool-bar-local-item-from-menu command icon in-map from-map props)
7237 (tool-bar-add-item-from-menu command icon from-map props)))
7239 (defun message-tool-bar-map ()
7240 (or message-tool-bar-map
7241 (setq message-tool-bar-map
7243 (condition-case nil (require 'tool-bar) (error nil))
7244 (fboundp 'tool-bar-add-item-from-menu)
7246 (let ((tool-bar-map (copy-keymap tool-bar-map))
7247 (load-path (mm-image-load-path)))
7248 ;; Zap some items which aren't so relevant and take
7250 (dolist (key '(print-buffer kill-buffer save-buffer
7251 write-file dired open-file))
7252 (define-key tool-bar-map (vector key) nil))
7253 (message-tool-bar-local-item-from-menu
7254 'message-send-and-exit "mail_send" tool-bar-map message-mode-map)
7255 (message-tool-bar-local-item-from-menu
7256 'message-kill-buffer "close" tool-bar-map message-mode-map)
7257 (message-tool-bar-local-item-from-menu
7258 'message-dont-send "cancel" tool-bar-map message-mode-map)
7259 ;; (message-tool-bar-local-item-from-menu
7260 ;; 'mime-edit-insert-file "attach"
7261 ;; tool-bar-map mime-edit-mode-map)
7262 (message-tool-bar-local-item-from-menu
7263 'ispell-message "spell" tool-bar-map message-mode-map)
7264 ;; (message-tool-bar-local-item-from-menu
7265 ;; 'mime-edit-preview-message "preview"
7266 ;; tool-bar-map mime-edit-mode-map)
7267 (message-tool-bar-local-item-from-menu
7268 'message-insert-importance-high "important"
7269 tool-bar-map message-mode-map)
7270 (message-tool-bar-local-item-from-menu
7271 'message-insert-importance-low "unimportant"
7272 tool-bar-map message-mode-map)
7273 (message-tool-bar-local-item-from-menu
7274 'message-insert-disposition-notification-to "receipt"
7275 tool-bar-map message-mode-map)
7278 ;;; Group name completion.
7280 (defcustom message-newgroups-header-regexp
7281 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
7282 "Regexp that match headers that lists groups."
7286 (defcustom message-completion-alist
7287 (list (cons message-newgroups-header-regexp 'message-expand-group)
7288 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name)
7289 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
7290 . message-expand-name)
7291 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
7292 . message-expand-name))
7293 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
7295 :type '(alist :key-type regexp :value-type function))
7297 (defcustom message-expand-name-function
7298 (cond ((and (boundp 'eudc-protocol)
7300 'eudc-expand-inline)
7301 ((fboundp 'bbdb-complete-name)
7302 'bbdb-complete-name)
7303 ((fboundp 'lsdb-complete-name)
7304 'lsdb-complete-name)
7306 "*A function called to expand addresses in field body."
7310 (defcustom message-tab-body-function nil
7311 "*Function to execute when `message-tab' (TAB) is executed in the body.
7312 If nil, the function bound in `text-mode-map' or `global-map' is executed."
7314 :link '(custom-manual "(message)Various Commands")
7317 (defun message-tab ()
7318 "Complete names according to `message-completion-alist'.
7319 Execute function specified by `message-tab-body-function' when not in
7322 (let ((alist message-completion-alist))
7324 (let ((mail-abbrev-mode-regexp (caar alist)))
7325 (not (mail-abbrev-in-expansion-header-p))))
7326 (setq alist (cdr alist)))
7327 (funcall (or (cdar alist) message-tab-body-function
7328 (lookup-key text-mode-map "\t")
7329 (lookup-key global-map "\t")
7330 'indent-relative))))
7332 (defun message-expand-group ()
7333 "Expand the group name under point."
7334 (let* ((b (save-excursion
7339 (skip-chars-forward "^:")
7342 (skip-chars-backward "^, \t\n") (point))))
7343 (completion-ignore-case t)
7344 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
7346 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
7347 (completions (all-completions string hashtb))
7349 (delete-region b (point))
7351 ((= (length completions) 1)
7352 (if (string= (car completions) string)
7355 (message "Only matching group"))
7356 (insert (car completions))))
7357 ((and (setq comp (try-completion string hashtb))
7358 (not (string= comp string)))
7363 (message "No matching groups")
7364 (save-selected-window
7365 (pop-to-buffer "*Completions*")
7366 (buffer-disable-undo)
7367 (let ((buffer-read-only nil))
7369 (let ((standard-output (current-buffer)))
7370 (display-completion-list (sort completions 'string<)))
7371 (goto-char (point-min))
7372 (delete-region (point) (progn (forward-line 3) (point))))))))))
7374 (defun message-expand-name ()
7375 (funcall message-expand-name-function))
7379 (defun message-talkative-question (ask question show &rest text)
7380 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
7381 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
7382 The following arguments may contain lists of values."
7384 (setq text (message-flatten-list text)))
7385 (save-window-excursion
7387 (with-output-to-temp-buffer " *MESSAGE information message*"
7388 (set-buffer " *MESSAGE information message*")
7389 (fundamental-mode) ; for Emacs 20.4+
7390 (mapcar 'princ text)
7391 (goto-char (point-min))))
7392 (funcall ask question))
7393 (funcall ask question)))
7395 (defun message-flatten-list (list)
7396 "Return a new, flat list that contains all elements of LIST.
7398 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
7401 (apply 'append (mapcar 'message-flatten-list list)))
7405 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
7406 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
7407 Then clone the local variables and values from the old buffer to the
7408 new one, cloning only the locals having a substring matching the
7410 (let ((oldbuf (current-buffer)))
7412 (set-buffer (generate-new-buffer name))
7413 (message-clone-locals oldbuf varstr)
7416 (defun message-clone-locals (buffer &optional varstr)
7417 "Clone the local variables from BUFFER to the current buffer."
7418 (let ((locals (save-excursion
7420 (buffer-local-variables)))
7422 "^\\(gnus\\|nn\\|message\\|user-\\(mail-address\\|full-name\\)\\)"))
7425 (when (and (consp local)
7427 (string-match regexp (symbol-name (car local)))
7429 (string-match varstr (symbol-name (car local)))))
7431 (set (make-local-variable (car local))
7435 ;;; @ for MIME Edit mode
7438 (defun message-maybe-encode ()
7439 (when message-mime-mode
7440 ;; Inherit the buffer local variable `mime-edit-pgp-processing'.
7441 (let ((pgp-processing (with-current-buffer message-edit-buffer
7442 mime-edit-pgp-processing)))
7443 (setq mime-edit-pgp-processing pgp-processing))
7444 (run-hooks 'mime-edit-translate-hook)
7445 (if (catch 'mime-edit-error
7447 (mime-edit-pgp-enclose-buffer)
7448 (mime-edit-translate-body)))
7449 (error "Translation error!"))
7450 (run-hooks 'mime-edit-exit-hook)))
7452 (defun message-mime-insert-article (&optional full-headers)
7454 (let ((message-cite-function 'mime-edit-inserted-message-filter)
7455 (message-reply-buffer
7456 (message-get-parameter-with-eval 'original-buffer))
7458 (message-yank-original nil)
7460 (narrow-to-region (goto-char start)
7461 (if (search-forward "\n\n" nil t)
7464 (goto-char (point-min))
7465 (let ((message-included-forward-headers
7466 (if full-headers "" message-included-forward-headers)))
7467 (message-remove-header message-included-forward-headers t nil t))
7470 (set-alist 'mime-edit-message-inserter-alist
7471 'message-mode (function message-mime-insert-article))
7477 (defvar message-inhibit-body-encoding t)
7479 (defun message-encode-message-body ()
7480 (unless message-inhibit-body-encoding
7481 (let ((mail-parse-charset (or mail-parse-charset
7482 message-default-charset))
7483 (case-fold-search t)
7484 lines content-type-p)
7487 (narrow-to-region (point) (point-max))
7488 (let ((new (mml-generate-mime)))
7490 (delete-region (point-min) (point-max))
7492 (goto-char (point-min))
7493 (if (eq (aref new 0) ?\n)
7495 (search-forward "\n\n")
7496 (setq lines (buffer-substring (point-min) (1- (point))))
7497 (delete-region (point-min) (point))))))
7499 (message-narrow-to-headers-or-head)
7500 (message-remove-header "Mime-Version")
7501 (goto-char (point-max))
7502 (insert "MIME-Version: 1.0\n")
7505 (setq content-type-p
7507 (re-search-backward "^Content-Type:" nil t))))
7509 (message-narrow-to-headers-or-head)
7510 (message-remove-first-header "Content-Type")
7511 (message-remove-first-header "Content-Transfer-Encoding"))
7512 ;; We always make sure that the message has a Content-Type
7513 ;; header. This is because some broken MTAs and MUAs get
7514 ;; awfully confused when confronted with a message with a
7515 ;; MIME-Version header and without a Content-Type header. For
7516 ;; instance, Solaris' /usr/bin/mail.
7517 (unless content-type-p
7518 (goto-char (point-min))
7519 ;; For unknown reason, MIME-Version doesn't exist.
7520 (when (re-search-forward "^MIME-Version:" nil t)
7522 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
7524 (defun message-read-from-minibuffer (prompt &optional initial-contents)
7525 "Read from the minibuffer while providing abbrev expansion."
7526 (if (fboundp 'mail-abbrevs-setup)
7527 (let ((mail-abbrev-mode-regexp "")
7528 (minibuffer-setup-hook 'mail-abbrevs-setup)
7529 (minibuffer-local-map message-minibuffer-local-map))
7530 (read-from-minibuffer prompt initial-contents))
7531 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
7532 (minibuffer-local-map message-minibuffer-local-map))
7533 (read-string prompt initial-contents))))
7535 (defun message-use-alternative-email-as-from ()
7536 (require 'mail-utils)
7537 (let* ((fields '("To" "Cc"))
7540 (mail-strip-quoted-names
7541 (mapconcat 'message-fetch-reply-field fields ","))
7545 (if (string-match message-alternative-emails (car emails))
7546 (setq email (car emails)
7549 (unless (or (not email) (equal email user-mail-address))
7550 (goto-char (point-max))
7551 (insert "From: " email "\n"))))
7553 (defun message-options-get (symbol)
7554 (cdr (assq symbol message-options)))
7556 (defun message-options-set (symbol value)
7557 (let ((the-cons (assq symbol message-options)))
7560 (setcdr the-cons value)
7561 (setq message-options (delq the-cons message-options)))
7563 (push (cons symbol value) message-options))))
7566 (defun message-options-set-recipient ()
7568 (message-narrow-to-headers-or-head)
7569 (message-options-set 'message-sender
7570 (mail-strip-quoted-names
7571 (message-fetch-field "from")))
7572 (message-options-set 'message-recipients
7573 (mail-strip-quoted-names
7574 (let ((to (message-fetch-field "to"))
7575 (cc (message-fetch-field "cc"))
7576 (bcc (message-fetch-field "bcc")))
7579 (if (and to cc) ", ")
7581 (if (and (or to cc) bcc) ", ")
7584 (defun message-hide-headers ()
7585 "Hide headers based on the `message-hidden-headers' variable."
7586 (let ((regexps (if (stringp message-hidden-headers)
7587 (list message-hidden-headers)
7588 message-hidden-headers))
7589 (inhibit-point-motion-hooks t)
7590 (after-change-functions nil))
7594 (message-narrow-to-headers)
7595 (goto-char (point-min))
7597 (if (not (message-hide-header-p regexps))
7598 (message-next-header)
7599 (let ((begin (point)))
7600 (message-next-header)
7601 (add-text-properties
7603 '(invisible t message-hidden t))))))))))
7605 (defun message-hide-header-p (regexps)
7608 (when (eq (car regexps) 'not)
7611 (dolist (regexp regexps)
7612 (setq result (or result (looking-at regexp))))
7617 (when (featurep 'xemacs)
7618 (require 'messagexmas)
7619 (message-xmas-redefine))
7623 (run-hooks 'message-load-hook)
7626 ;; coding: iso-8859-1
7629 ;;; message.el ends here