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
48 ;; This is apparently necessary even though things are autoloaded.
49 ;; Because we dynamically bind mail-abbrev-mode-regexp, we'd better
50 ;; require mailabbrev here.
51 (if (featurep 'xemacs)
52 (require 'mail-abbrevs)
53 (require 'mailabbrev))
55 (eval-when-compile (require 'static))
57 ;; Avoid byte-compile warnings.
64 (defgroup message '((user-mail-address custom-variable)
65 (user-full-name custom-variable))
66 "Mail and news message composing."
67 :link '(custom-manual "(message)Top")
71 (put 'user-mail-address 'custom-type 'string)
72 (put 'user-full-name 'custom-type 'string)
74 (defgroup message-various nil
75 "Various Message Variables"
76 :link '(custom-manual "(message)Various Message Variables")
79 (defgroup message-buffers nil
81 :link '(custom-manual "(message)Message Buffers")
84 (defgroup message-sending nil
86 :link '(custom-manual "(message)Sending Variables")
89 (defgroup message-interface nil
91 :link '(custom-manual "(message)Interface")
94 (defgroup message-forwarding nil
96 :link '(custom-manual "(message)Forwarding")
97 :group 'message-interface)
99 (defgroup message-insertion nil
101 :link '(custom-manual "(message)Insertion")
104 (defgroup message-headers nil
106 :link '(custom-manual "(message)Message Headers")
109 (defgroup message-news nil
110 "Composing News Messages"
113 (defgroup message-mail nil
114 "Composing Mail Messages"
117 (defgroup message-faces nil
118 "Faces used for message composing."
122 (defgroup message-frames nil
126 (defcustom message-directory "~/Mail/"
127 "*Directory from which all other mail file variables are derived."
128 :group 'message-various
131 (defcustom message-max-buffers 10
132 "*How many buffers to keep before starting to kill them off."
133 :group 'message-buffers
136 (defcustom message-send-rename-function nil
137 "Function called to rename the buffer after sending it."
138 :group 'message-buffers
139 :type '(choice function (const nil)))
141 (defcustom message-fcc-handler-function 'message-output
142 "*A function called to save outgoing articles.
143 This function will be called with the name of the file to store the
144 article in. The default function is `message-output' which saves in Unix
146 :type '(radio (function-item message-output)
147 (function :tag "Other"))
148 :group 'message-sending)
150 (defcustom message-encode-function 'message-maybe-encode
151 "*A function called to encode messages."
152 :group 'message-sending
155 (defcustom message-8bit-encoding-list '(8bit binary)
156 "*8bit encoding type in Content-Transfer-Encoding field."
157 :group 'message-sending
158 :type '(repeat (symbol :tag "Type")))
160 (defcustom message-fcc-externalize-attachments nil
161 "If non-nil, attachments are included as external parts in Fcc copies."
164 :group 'message-sending)
166 (defcustom message-courtesy-message
167 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
168 "*This is inserted at the start of a mailed copy of a posted message.
169 If the string contains the format spec \"%s\", the Newsgroups
170 the article has been posted to will be inserted there.
171 If this variable is nil, no such courtesy message will be added."
172 :group 'message-sending
173 :type '(radio (string :format "%t: %v\n" :size 0) (const nil)))
175 (defcustom message-ignored-bounced-headers
176 "^\\(Received\\|Return-Path\\|Delivered-To\\):"
177 "*Regexp that matches headers to be removed in resent bounced mail."
178 :group 'message-interface
181 (defcustom message-bounce-setup-function 'message-bounce-setup-for-mime-edit
182 "Function to setup a re-sending bounced message."
183 :group 'message-sending
186 ;;; Start of variables adopted from `message-utils.el'.
188 (defcustom message-subject-trailing-was-query 'ask
189 "*What to do with trailing \"(was: <old subject>)\" in subject lines.
190 If nil, leave the subject unchanged. If it is the symbol `ask', query
191 the user what do do. In this case, the subject is matched against
192 `message-subject-trailing-was-ask-regexp'. If
193 `message-subject-trailing-was-query' is t, always strip the trailing
194 old subject. In this case, `message-subject-trailing-was-regexp' is
197 :type '(choice (const :tag "never" nil)
198 (const :tag "always strip" t)
200 :link '(custom-manual "(message)Message Headers")
201 :group 'message-various)
203 (defcustom message-subject-trailing-was-ask-regexp
204 "[ \t]*\\([[(]+[Ww][Aa][Ss][ \t]*.*[\])]+\\)"
205 "*Regexp matching \"(was: <old subject>)\" in the subject line.
207 The function `message-strip-subject-trailing-was' uses this regexp if
208 `message-subject-trailing-was-query' is set to the symbol `ask'. If
209 the variable is t instead of `ask', use
210 `message-subject-trailing-was-regexp' instead.
212 It is okay to create some false positives here, as the user is asked."
214 :group 'message-various
215 :link '(custom-manual "(message)Message Headers")
218 (defcustom message-subject-trailing-was-regexp
219 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
220 "*Regexp matching \"(was: <old subject>)\" in the subject line.
222 If `message-subject-trailing-was-query' is set to t, the subject is
223 matched against `message-subject-trailing-was-regexp' in
224 `message-strip-subject-trailing-was'. You should use a regexp creating very
225 few false positives here."
227 :group 'message-various
228 :link '(custom-manual "(message)Message Headers")
231 ;; Fixme: Why are all these things autoloaded?
233 ;;; marking inserted text
236 (defcustom message-mark-insert-begin
237 "--8<---------------cut here---------------start------------->8---\n"
238 "How to mark the beginning of some inserted text."
241 :link '(custom-manual "(message)Insertion Variables")
242 :group 'message-various)
245 (defcustom message-mark-insert-end
246 "--8<---------------cut here---------------end--------------->8---\n"
247 "How to mark the end of some inserted text."
250 :link '(custom-manual "(message)Insertion Variables")
251 :group 'message-various)
254 (defcustom message-archive-header
255 "X-No-Archive: Yes\n"
256 "Header to insert when you don't want your article to be archived.
257 Archives \(such as groups.google.com\) respect this header."
260 :link '(custom-manual "(message)Header Commands")
261 :group 'message-various)
264 (defcustom message-archive-note
265 "X-No-Archive: Yes - save http://groups.google.com/"
266 "Note to insert why you wouldn't want this posting archived.
267 If nil, don't insert any text in the body."
269 :type '(radio (string :format "%t: %v\n" :size 0)
271 :link '(custom-manual "(message)Header Commands")
272 :group 'message-various)
274 ;;; Crossposts and Followups
275 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
276 ;; new suggestions by R. Weikusat <rw at another.de>
278 (defvar message-cross-post-old-target nil
279 "Old target for cross-posts or follow-ups.")
280 (make-variable-buffer-local 'message-cross-post-old-target)
283 (defcustom message-cross-post-default t
284 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
285 If nil, `message-cross-post-followup-to' will only do a followup. Note that
286 you can explicitly override this setting by calling
287 `message-cross-post-followup-to' with a prefix."
290 :group 'message-various)
293 (defcustom message-cross-post-note
294 "Crosspost & Followup-To: "
295 "Note to insert before signature to notify of xpost and follow-up."
298 :group 'message-various)
301 (defcustom message-followup-to-note
303 "Note to insert before signature to notify of follow-up only."
306 :group 'message-various)
309 (defcustom message-cross-post-note-function
310 'message-cross-post-insert-note
311 "Function to use to insert note about Crosspost or Followup-To.
312 The function will be called with four arguments. The function should not only
313 insert a note, but also ensure old notes are deleted. See the documentation
314 for `message-cross-post-insert-note'."
317 :group 'message-various)
319 ;;; End of variables adopted from `message-utils.el'.
322 (defcustom message-from-style 'default
323 "*Specifies how \"From\" headers look.
325 If nil, they contain just the return address like:
327 If `parens', they look like:
328 king@grassland.com (Elvis Parsley)
329 If `angles', they look like:
330 Elvis Parsley <king@grassland.com>
332 Otherwise, most addresses look like `angles', but they look like
333 `parens' if `angles' would need quoting and `parens' would not."
334 :type '(choice (const :tag "simple" nil)
338 :group 'message-headers)
340 (defcustom message-insert-canlock t
341 "Whether to insert a Cancel-Lock header in news postings."
343 :group 'message-headers
346 (defcustom message-syntax-checks
347 (if message-insert-canlock '((sender . disabled)) nil)
348 ;; Guess this one shouldn't be easy to customize...
349 "*Controls what syntax checks should not be performed on outgoing posts.
350 To disable checking of long signatures, for instance, add
351 `(signature . disabled)' to this list.
353 Don't touch this variable unless you really know what you're doing.
355 Checks include `subject-cmsg', `multiple-headers', `sendsys',
356 `message-id', `from', `long-lines', `control-chars', `size',
357 `new-text', `quoting-style', `redirected-followup', `signature',
358 `approved', `sender', `empty', `empty-headers', `message-id', `from',
359 `subject', `shorten-followup-to', `existing-newsgroups',
360 `buffer-file-name', `unchanged', `newsgroups', `reply-to',
361 `continuation-headers', `long-header-lines', `invisible-text' and
364 :type '(repeat sexp)) ; Fixme: improve this
366 (defcustom message-required-headers '((optional . References)
368 "*Headers to be generated or prompted for when sending a message.
369 Also see `message-required-news-headers' and
370 `message-required-mail-headers'."
373 :group 'message-headers
374 :link '(custom-manual "(message)Message Headers")
375 :type '(repeat sexp))
377 (defcustom message-draft-headers '(References From)
378 "*Headers to be generated when saving a draft message."
381 :group 'message-headers
382 :link '(custom-manual "(message)Message Headers")
383 :type '(repeat sexp))
385 (defcustom message-required-news-headers
386 '(From Newsgroups Subject Date Message-ID
387 (optional . Organization)
388 (optional . User-Agent))
389 "*Headers to be generated or prompted for when posting an article.
390 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
391 Message-ID. Organization, Lines, In-Reply-To, Expires, and
392 User-Agent are optional. If don't you want message to insert some
393 header, remove it from this list."
395 :group 'message-headers
396 :link '(custom-manual "(message)Message Headers")
397 :type '(repeat sexp))
399 (defcustom message-required-mail-headers
400 '(From Subject Date (optional . In-Reply-To) Message-ID
401 (optional . User-Agent))
402 "*Headers to be generated or prompted for when mailing a message.
403 It is recommended that From, Date, To, Subject and Message-ID be
404 included. Organization and User-Agent are optional."
406 :group 'message-headers
407 :link '(custom-manual "(message)Message Headers")
408 :type '(repeat sexp))
410 (defcustom message-deletable-headers '(Message-ID Date Lines)
411 "Headers to be deleted if they already exist and were generated by message previously."
412 :group 'message-headers
413 :link '(custom-manual "(message)Message Headers")
416 (defcustom message-ignored-news-headers
417 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
418 "*Regexp of headers to be removed unconditionally before posting."
420 :group 'message-headers
421 :link '(custom-manual "(message)Message Headers")
424 (defcustom message-ignored-mail-headers
425 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
426 "*Regexp of headers to be removed unconditionally before mailing."
428 :group 'message-headers
429 :link '(custom-manual "(message)Mail Headers")
432 (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:\\|^Approved:"
433 "*Header lines matching this regexp will be deleted before posting.
434 It's best to delete old Path and Date headers before posting to avoid
436 :group 'message-interface
437 :link '(custom-manual "(message)Superseding")
440 (defcustom message-supersede-setup-function
441 'message-supersede-setup-for-mime-edit
442 "Function to setup a supersede message."
443 :group 'message-sending
446 (defcustom message-subject-re-regexp
447 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)*:[ \t]*\\)*[ \t]*"
448 "*Regexp matching \"Re: \" in the subject line."
449 :group 'message-various
450 :link '(custom-manual "(message)Message Headers")
453 ;;; Some sender agents encode the whole subject including leading "Re: ".
454 ;;; And if followup agent does not decode it for some reason (e.g. unknown
455 ;;; charset) and just add a new "Re: " in front of the encoded-word, the
456 ;;; result will contain multiple "Re: "'s.
457 (defcustom message-subject-encoded-re-regexp
461 "[-!#$%&'*+0-9A-Z^_`a-z{|}~]+" ; charset
464 "[Bb]" (regexp-quote "?") ; B encoding
465 "\\(\\(CQk\\|CSA\\|IAk\\|ICA\\)[Jg]\\)*" ; \([ \t][ \t][ \t]\)*
467 "[Uc][km]U6" ; [Rr][Ee]:
469 "\\(C[VX]\\|I[FH]\\)J[Fl]O[g-v]" ; [ \t][Rr][Ee]:
471 "\\(CQl\\|CSB\\|IAl\\|ICB\\)[Sy][RZ]T[o-r]" ; [ \t][ \t][Rr][Ee]:
474 "[Qb]" (regexp-quote "?") ; Q encoding
475 "\\(_\\|=09\\|=20\\)*"
476 "\\([Rr]\\|=[57]2\\)\\([Ee]\\|=[46]5\\)\\(:\\|=3[Aa]\\)"
479 "*Regexp matching \"Re: \" in the subject line.
480 Unlike `message-subject-re-regexp', this regexp matches \"Re: \" within
482 :group 'message-various
483 :link '(custom-manual "(message)Message Headers")
486 (defcustom message-use-subject-re t
487 "*If t, remove any (buggy) \"Re: \"'s from the subject of the precursor
488 and add a new \"Re: \". If it is nil, use the subject \"as-is\". If it
489 is the symbol `guess', try to detect \"Re: \" within an encoded-word."
490 :group 'message-various
491 :type '(choice (const :tag "off" nil)
496 (defcustom message-signature-separator "^-- *$"
497 "Regexp matching the signature separator."
499 :link '(custom-manual "(message)Various Message Variables")
500 :group 'message-various)
502 (defcustom message-signature-separator-for-insertion "-- \n"
503 "*Signature separator. This value will be inserted as signature separator
504 when composing message. Default value is \"-- \\n\". Notice: Changing this
505 value may go against RFC-1036 and draft-ietf-usefor-article-05.txt. "
507 :group 'message-insertion)
509 (defcustom message-elide-ellipsis "\n[...]\n\n"
510 "*The string which is inserted for elided text."
512 :link '(custom-manual "(message)Insertion Variables")
513 :group 'message-various)
515 (defcustom message-interactive t
516 "Non-nil means when sending a message wait for and display errors.
517 nil means let mailer mail back a message to report errors."
518 :group 'message-sending
520 :link '(custom-manual "(message)Sending Variables")
523 (defcustom message-generate-new-buffers 'unique
524 "*Non-nil means create a new message buffer whenever `message-setup' is called.
525 If this is a function, call that function with three parameters: The type,
526 the to address and the group name. (Any of these may be nil.) The function
527 should return the new buffer name."
528 :group 'message-buffers
529 :link '(custom-manual "(message)Message Buffers")
530 :type '(choice (const :tag "off" nil)
531 (const :tag "unique" unique)
532 (const :tag "unsent" unsent)
535 (defcustom message-kill-buffer-on-exit nil
536 "*Non-nil means that the message buffer will be killed after sending a message."
537 :group 'message-buffers
538 :link '(custom-manual "(message)Message Buffers")
541 (defcustom message-kill-buffer-query-function 'yes-or-no-p
542 "*Function used to prompt user whether to kill the message buffer. If
543 it is t, the buffer will be killed unconditionally."
544 :type '(radio (function-item yes-or-no-p)
545 (function-item y-or-n-p)
546 (function-item nnheader-Y-or-n-p)
547 (function :tag "Other" t))
548 :group 'message-buffers)
550 (defcustom message-kill-buffer-and-remove-file t
551 "*Non-nil means that the associated file will be removed before
552 removing the message buffer. However, it is treated as nil when the
553 command `message-mimic-kill-buffer' is used."
554 :group 'message-buffers
558 (defvar gnus-local-organization))
559 (defcustom message-user-organization
560 (or (and (boundp 'gnus-local-organization)
561 (stringp gnus-local-organization)
562 gnus-local-organization)
563 (getenv "ORGANIZATION")
565 "*String to be used as an Organization header.
566 If t, use `message-user-organization-file'."
567 :group 'message-headers
568 :type '(choice string
569 (const :tag "consult file" t)))
572 (defcustom message-user-organization-file "/usr/lib/news/organization"
573 "*Local news organization file."
575 :link '(custom-manual "(message)News Headers")
576 :group 'message-headers)
578 (defcustom message-forward-start-separator
579 (concat (mime-make-tag "message" "rfc822") "\n")
580 "*Delimiter inserted before forwarded messages."
581 :group 'message-forwarding
584 (defcustom message-forward-end-separator
585 (concat (mime-make-tag "text" "plain") "\n")
586 "*Delimiter inserted after forwarded messages."
587 :group 'message-forwarding
590 (defcustom message-included-forward-headers
591 "^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:"
592 "*Regexp matching headers to be included in forwarded messages."
593 :group 'message-forwarding
596 (defcustom message-make-forward-subject-function
597 #'message-forward-subject-name-subject
598 "*List of functions called to generate subject headers for forwarded messages.
599 The subject generated by the previous function is passed into each
602 The provided functions are:
604 * `message-forward-subject-author-subject' Source of article (author or
605 newsgroup), in brackets followed by the subject
606 * `message-forward-subject-name-subject' Source of article (name of author
607 or newsgroup), in brackets followed by the subject
608 * `message-forward-subject-fwd' Subject of article with 'Fwd:' prepended
610 :group 'message-forwarding
611 :link '(custom-manual "(message)Forwarding")
612 :type '(radio (function-item message-forward-subject-author-subject)
613 (function-item message-forward-subject-fwd)
614 (function-item message-forward-subject-name-subject)
615 (repeat :tag "List of functions" function)))
617 (defcustom message-forward-as-mime t
618 "*Non-nil means forward messages as an inline/rfc822 MIME section.
619 Otherwise, directly inline the old message in the forwarded message."
621 :group 'message-forwarding
622 :link '(custom-manual "(message)Forwarding")
625 (defcustom message-forward-show-mml 'best
626 "*Non-nil means show forwarded messages as MML (decoded from MIME).
627 Otherwise, forwarded messages are unchanged.
628 Can also be the symbol `best' to indicate that MML should be
629 used, except when it is a bad idea to use MML. One example where
630 it is a bad idea is when forwarding a signed or encrypted
631 message, because converting MIME to MML would invalidate the
634 :group 'message-forwarding
635 :type '(choice (const :tag "use MML" t)
636 (const :tag "don't use MML " nil)
637 (const :tag "use MML when appropriate" best)))
639 (defcustom message-forward-before-signature t
640 "*Non-nil means put forwarded message before signature, else after."
641 :group 'message-forwarding
644 (defcustom message-wash-forwarded-subjects nil
645 "*Non-nil means try to remove as much cruft as possible from the subject.
646 Done before generating the new subject of a forward."
647 :group 'message-forwarding
648 :link '(custom-manual "(message)Forwarding")
651 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From "
652 "*All headers that match this regexp will be deleted when resending a message."
653 :group 'message-interface
654 :link '(custom-manual "(message)Resending")
657 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
658 "*All headers that match this regexp will be deleted when forwarding a message."
660 :group 'message-forwarding
661 :type '(choice (const :tag "None" nil)
664 (defcustom message-ignored-cited-headers "."
665 "*Delete these headers from the messages you yank."
666 :group 'message-insertion
667 :link '(custom-manual "(message)Insertion Variables")
670 (defcustom message-cite-prefix-regexp
671 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
672 "\\([ \t]*[-_.[:word:]]+>+\\|[ \t]*[]>|}+]\\)+"
673 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
674 (let (non-word-constituents)
675 (with-syntax-table text-mode-syntax-table
676 (setq non-word-constituents
678 (if (string-match "\\w" "-") "" "-")
679 (if (string-match "\\w" "_") "" "_")
680 (if (string-match "\\w" ".") "" "."))))
681 (if (equal non-word-constituents "")
682 "\\([ \t]*\\(\\w\\)+>+\\|[ \t]*[]>|}+]\\)+"
683 (concat "\\([ \t]*\\(\\w\\|["
684 non-word-constituents
685 "]\\)+>+\\|[ \t]*[]>|}+]\\)+"))))
686 "*Regexp matching the longest possible citation prefix on a line."
687 :group 'message-insertion
688 :link '(custom-manual "(message)Insertion Variables")
691 (defcustom message-cancel-message "I am canceling my own article.\n"
692 "Message to be inserted in the cancel message."
693 :group 'message-interface
694 :link '(custom-manual "(message)Canceling News")
697 ;; Useful to set in site-init.el
699 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
700 "Function to call to send the current buffer as mail.
701 The headers should be delimited by a line whose contents match the
702 variable `mail-header-separator'.
704 Valid values include `message-send-mail-with-sendmail' (the default),
705 `message-send-mail-with-mh', `message-send-mail-with-qmail',
706 `message-send-mail-with-smtp', `message-smtpmail-send-it',
707 `smtpmail-send-it' and `feedmail-send-it'.
709 See also `send-mail-function'."
710 :type '(radio (function-item message-send-mail-with-sendmail)
711 (function-item message-send-mail-with-mh)
712 (function-item message-send-mail-with-qmail)
713 (function-item message-send-mail-with-smtp)
714 (function-item message-smtpmail-send-it)
715 (function-item smtpmail-send-it)
716 (function-item feedmail-send-it)
717 (function :tag "Other"))
718 :group 'message-sending
719 :link '(custom-manual "(message)Mail Variables")
720 :group 'message-mail)
722 ;; 1997-09-29 by MORIOKA Tomohiko
723 (defcustom message-send-news-function 'message-send-news-with-gnus
724 "Function to call to send the current buffer as news.
725 The headers should be delimited by a line whose contents match the
726 variable `mail-header-separator'."
727 :group 'message-sending
729 :link '(custom-manual "(message)News Variables")
732 (defcustom message-reply-to-function nil
733 "If non-nil, function that should return a list of headers.
734 This function should pick out addresses from the To, Cc, and From headers
735 and respond with new To and Cc headers."
736 :group 'message-interface
737 :link '(custom-manual "(message)Reply")
738 :type '(choice function (const nil)))
740 (defcustom message-wide-reply-to-function nil
741 "If non-nil, function that should return a list of headers.
742 This function should pick out addresses from the To, Cc, and From headers
743 and respond with new To and Cc headers."
744 :group 'message-interface
745 :link '(custom-manual "(message)Wide Reply")
746 :type '(choice function (const nil)))
748 (defcustom message-followup-to-function nil
749 "If non-nil, function that should return a list of headers.
750 This function should pick out addresses from the To, Cc, and From headers
751 and respond with new To and Cc headers."
752 :group 'message-interface
753 :link '(custom-manual "(message)Followup")
754 :type '(choice function (const nil)))
756 (defcustom message-use-followup-to 'ask
757 "*Specifies what to do with Followup-To header.
758 If nil, always ignore the header. If it is t, use its value, but
759 query before using the \"poster\" value. If it is the symbol `ask',
760 always query the user whether to use the value. If it is the symbol
761 `use', always use the value."
762 :group 'message-interface
763 :link '(custom-manual "(message)Followup")
764 :type '(choice (const :tag "ignore" nil)
765 (const :tag "use & query" t)
766 (const :tag "maybe" t)
767 (const :tag "always" use)
768 (const :tag "ask" ask)))
770 (defcustom message-use-mail-copies-to 'ask
771 "*Specifies what to do with Mail-Copies-To header.
772 If nil, always ignore the header. If it is t, use its value, but
773 query before using the value other than \"always\" or \"never\".
774 If it is the symbol `ask', always query the user whether to use
775 the value. If it is the symbol `use', always use the value."
776 :group 'message-interface
777 :link '(custom-manual "(message)Mailing Lists")
778 :type '(choice (const :tag "ignore" nil)
779 (const :tag "maybe" t)
780 (const :tag "always" use)
781 (const :tag "ask" ask)))
783 ;;; XXX: 'ask and 'use are not implemented yet.
784 (defcustom message-use-mail-reply-to 'ask
785 "*Specifies what to do with Mail-Reply-To/Reply-To header.
786 If nil, always ignore the header. If it is t or the symbol `use', use
787 its value. If it is the symbol `ask', always query the user whether to
788 use the value. Note that if \"Reply-To\" is marked as \"broken\", its value
790 :group 'message-interface
791 :type '(choice (const :tag "ignore" nil)
792 (const :tag "maybe" t)
793 (const :tag "always" use)
794 (const :tag "ask" ask)))
796 (defcustom message-use-mail-followup-to 'use
797 "*Specifies what to do with Mail-Followup-To header.
798 If nil, always ignore the header. If it is the symbol `ask', always
799 query the user whether to use the value. If it is t or the symbol
800 `use', always use the value."
802 :group 'message-interface
803 :type '(choice (const :tag "ignore" nil)
804 (const :tag "maybe" t)
805 (const :tag "always" use)
806 (const :tag "ask" ask)))
808 (defcustom message-subscribed-address-functions nil
809 "*Specifies functions for determining list subscription.
810 If nil, do not attempt to determine list subscription with functions.
811 If non-nil, this variable contains a list of functions which return
812 regular expressions to match lists. These functions can be used in
813 conjunction with `message-subscribed-regexps' and
814 `message-subscribed-addresses'."
816 :group 'message-interface
817 :link '(custom-manual "(message)Mailing Lists")
818 :type '(repeat sexp))
820 (defcustom message-subscribed-address-file nil
821 "*A file containing addresses the user is subscribed to.
822 If nil, do not look at any files to determine list subscriptions. If
823 non-nil, each line of this file should be a mailing list address."
825 :group 'message-interface
826 :link '(custom-manual "(message)Mailing Lists")
827 :type '(radio (file :format "%t: %v\n" :size 0)
830 (defcustom message-subscribed-addresses nil
831 "*Specifies a list of addresses the user is subscribed to.
832 If nil, do not use any predefined list subscriptions. This list of
833 addresses can be used in conjunction with
834 `message-subscribed-address-functions' and `message-subscribed-regexps'."
836 :group 'message-interface
837 :link '(custom-manual "(message)Mailing Lists")
838 :type '(repeat string))
840 (defcustom message-subscribed-regexps nil
841 "*Specifies a list of addresses the user is subscribed to.
842 If nil, do not use any predefined list subscriptions. This list of
843 regular expressions can be used in conjunction with
844 `message-subscribed-address-functions' and `message-subscribed-addresses'."
846 :group 'message-interface
847 :link '(custom-manual "(message)Mailing Lists")
848 :type '(repeat regexp))
850 (defcustom message-allow-no-recipients 'ask
851 "Specifies what to do when there are no recipients other than Gcc/Fcc.
852 If it is the symbol `always', the posting is allowed. If it is the
853 symbol `never', the posting is not allowed. If it is the symbol
854 `ask', you are prompted."
856 :group 'message-interface
857 :link '(custom-manual "(message)Message Headers")
858 :type '(choice (const always)
862 (defcustom message-sendmail-f-is-evil nil
863 "*Non-nil means don't add \"-f username\" to the sendmail command line.
864 Doing so would be even more evil than leaving it out."
865 :group 'message-sending
866 :link '(custom-manual "(message)Mail Variables")
869 (defcustom message-sendmail-envelope-from nil
870 "*Envelope-from when sending mail with sendmail.
871 If this is nil, use `user-mail-address'. If it is the symbol
872 `header', use the From: header of the message."
873 :type '(choice (string :tag "From name")
874 (const :tag "Use From: header from message" header)
875 (const :tag "Use `user-mail-address'" nil))
876 :link '(custom-manual "(message)Mail Variables")
877 :group 'message-sending)
879 ;; qmail-related stuff
880 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
881 "Location of the qmail-inject program."
882 :group 'message-sending
883 :link '(custom-manual "(message)Mail Variables")
886 (defcustom message-qmail-inject-args nil
887 "Arguments passed to qmail-inject programs.
888 This should be a list of strings, one string for each argument. It
889 may also be a function.
891 For e.g., if you wish to set the envelope sender address so that bounces
892 go to the right place or to deal with listserv's usage of that address, you
893 might set this variable to '(\"-f\" \"you@some.where\")."
894 :group 'message-sending
895 :link '(custom-manual "(message)Mail Variables")
896 :type '(choice (function)
900 (defvar gnus-post-method)
901 (defvar gnus-select-method))
902 (defcustom message-post-method
903 (cond ((and (boundp 'gnus-post-method)
904 (listp gnus-post-method)
907 ((boundp 'gnus-select-method)
910 "*Method used to post news.
911 Note that when posting from inside Gnus, for instance, this
912 variable isn't used."
914 :group 'message-sending
915 ;; This should be the `gnus-select-method' widget, but that might
916 ;; create a dependence to `gnus.el'.
919 ;; FIXME: This should be a temporary workaround until someone implements a
920 ;; proper solution. If a crash happens while replying, the auto-save file
921 ;; will *not* have a `References:' header if `message-generate-headers-first'
922 ;; is nil. See: http://article.gmane.org/gmane.emacs.gnus.general/51138
923 (defcustom message-generate-headers-first '(references)
924 "Which headers should be generated before starting to compose a message.
925 If t, generate all required headers. This can also be a list of headers to
926 generate. The variables `message-required-news-headers' and
927 `message-required-mail-headers' specify which headers to generate.
929 Note that the variable `message-deletable-headers' specifies headers which
930 are to be deleted and then re-generated before sending, so this variable
931 will not have a visible effect for those headers."
932 :group 'message-headers
933 :link '(custom-manual "(message)Message Headers")
934 :type '(choice (const :tag "None" nil)
935 (const :tag "References" '(references))
937 (repeat (sexp :tag "Header"))))
939 (defcustom message-setup-hook '(turn-on-mime-edit)
940 "Normal hook, run each time a new outgoing message is initialized.
941 The function `message-setup' runs this hook."
942 :group 'message-various
943 :link '(custom-manual "(message)Various Message Variables")
946 (defcustom message-cancel-hook nil
947 "Hook run when cancelling articles."
948 :group 'message-various
949 :link '(custom-manual "(message)Various Message Variables")
952 (defcustom message-signature-setup-hook nil
953 "Normal hook, run each time a new outgoing message is initialized.
954 It is run after the headers have been inserted and before
955 the signature is inserted."
956 :group 'message-various
957 :link '(custom-manual "(message)Various Message Variables")
960 (defcustom message-bounce-setup-hook nil
961 "Normal hook, run each time a re-sending bounced message is initialized.
962 The function `message-bounce' runs this hook."
963 :group 'message-various
966 (defcustom message-supersede-setup-hook nil
967 "Normal hook, run each time a supersede message is initialized.
968 The function `message-supersede' runs this hook."
969 :group 'message-various
972 (defcustom message-mode-hook nil
973 "Hook run in message mode buffers."
974 :group 'message-various
977 (defcustom message-header-hook '((lambda () (mime-encode-header-in-buffer t)))
978 "Hook run in a message mode buffer narrowed to the headers."
979 :group 'message-various
982 (defcustom message-header-setup-hook nil
983 "Hook called narrowed to the headers when setting up a message buffer."
984 :group 'message-various
985 :link '(custom-manual "(message)Various Message Variables")
988 (defcustom message-minibuffer-local-map
989 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
990 (set-keymap-parent map minibuffer-local-map)
992 "Keymap for `message-read-from-minibuffer'.")
995 (defcustom message-citation-line-function 'message-insert-citation-line
996 "*Function called to insert the \"Whomever writes:\" line.
998 Note that Gnus provides a feature where the reader can click on
999 `writes:' to hide the cited text. If you change this line too much,
1000 people who read your message will have to change their Gnus
1001 configuration. See the variable `gnus-cite-attribution-suffix'."
1003 :link '(custom-manual "(message)Insertion Variables")
1004 :group 'message-insertion)
1007 (defcustom message-yank-prefix "> "
1008 "*Prefix inserted on the lines of yanked messages.
1009 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1010 See also `message-yank-cited-prefix'."
1012 :link '(custom-manual "(message)Insertion Variables")
1013 :group 'message-insertion)
1015 (defcustom message-yank-add-new-references t
1016 "Non-nil means new IDs will be added to \"References\" field when an
1017 article is yanked by the command `message-yank-original' interactively.
1018 If it is a symbol `message-id-only', only an ID from \"Message-ID\" field
1019 is used, otherwise IDs extracted from \"References\", \"In-Reply-To\" and
1020 \"Message-ID\" fields are used."
1021 :type '(radio (const :tag "Do not add anything" nil)
1022 (const :tag "From Message-Id, References and In-Reply-To fields" t)
1023 (const :tag "From only Message-Id field." message-id-only))
1024 :group 'message-insertion)
1026 (defcustom message-list-references-add-position nil
1027 "Integer value means position for adding to \"References\" field when
1028 an article is yanked by the command `message-yank-original' interactively."
1029 :type '(radio (const :tag "Add to last" nil)
1030 (integer :tag "Position from last ID"))
1031 :group 'message-insertion)
1033 (defcustom message-yank-cited-prefix ">"
1034 "*Prefix inserted on cited or empty lines of yanked messages.
1035 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1036 See also `message-yank-prefix'."
1039 :link '(custom-manual "(message)Insertion Variables")
1040 :group 'message-insertion)
1042 (defcustom message-indentation-spaces 3
1043 "*Number of spaces to insert at the beginning of each cited line.
1044 Used by `message-yank-original' via `message-yank-cite'."
1045 :group 'message-insertion
1046 :link '(custom-manual "(message)Insertion Variables")
1050 (defcustom message-cite-function 'message-cite-original
1051 "*Function for citing an original message.
1052 Predefined functions include `message-cite-original' and
1053 `message-cite-original-without-signature'.
1054 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
1055 :type '(radio (function-item message-cite-original)
1056 (function-item message-cite-original-without-signature)
1057 (function-item mu-cite-original)
1058 (function-item sc-cite-original)
1059 (function :tag "Other"))
1060 :link '(custom-manual "(message)Insertion Variables")
1061 :group 'message-insertion)
1064 (defcustom message-suspend-font-lock-when-citing nil
1065 "Non-nil means suspend font-lock'ing while citing an original message.
1066 Some lazy demand-driven fontification tools (or Emacs itself) have a
1067 bug that they often miss a buffer to be fontified. It will mostly
1068 occur when Emacs prompts user for any inputs in the minibuffer.
1069 Setting this option to non-nil may help you to avoid unpleasant errors
1070 even if it is an add-hoc expedient."
1072 :group 'message-insertion)
1075 (defcustom message-indent-citation-function 'message-indent-citation
1076 "*Function for modifying a citation just inserted in the mail buffer.
1077 This can also be a list of functions. Each function can find the
1078 citation between (point) and (mark t). And each function should leave
1079 point and mark around the citation text as modified."
1081 :link '(custom-manual "(message)Insertion Variables")
1082 :group 'message-insertion)
1085 (defcustom message-signature t
1086 "*String to be inserted at the end of the message buffer.
1087 If t, the `message-signature-file' file will be inserted instead.
1088 If a function, the result from the function will be used instead.
1089 If a form, the result from the form will be used instead."
1091 :link '(custom-manual "(message)Insertion Variables")
1092 :group 'message-insertion)
1095 (defcustom message-signature-file "~/.signature"
1096 "*Name of file containing the text inserted at end of message buffer.
1097 Ignored if the named file doesn't exist.
1098 If nil, don't insert a signature."
1099 :type '(choice file (const :tags "None" nil))
1100 :link '(custom-manual "(message)Insertion Variables")
1101 :group 'message-insertion)
1104 (defcustom message-signature-insert-empty-line t
1105 "*If non-nil, insert an empty line before the signature separator."
1108 :link '(custom-manual "(message)Insertion Variables")
1109 :group 'message-insertion)
1111 (defcustom message-distribution-function nil
1112 "*Function called to return a Distribution header."
1113 :group 'message-news
1114 :group 'message-headers
1115 :link '(custom-manual "(message)News Headers")
1116 :type '(choice function (const nil)))
1118 (defcustom message-expires 14
1119 "Number of days before your article expires."
1120 :group 'message-news
1121 :group 'message-headers
1122 :link '(custom-manual "(message)News Headers")
1125 (defcustom message-user-path nil
1126 "If nil, use the NNTP server name in the Path header.
1127 If stringp, use this; if non-nil, use no host name (user name only)."
1128 :group 'message-news
1129 :group 'message-headers
1130 :link '(custom-manual "(message)News Headers")
1131 :type '(choice (const :tag "nntp" nil)
1132 (string :tag "name")
1133 (sexp :tag "none" :format "%t" t)))
1135 (defvar message-reply-buffer nil)
1136 (defvar message-reply-headers nil
1137 "The headers of the current replied article.
1138 It is a vector of the following headers:
1139 \[number subject from date id references chars lines xref extra].")
1140 (defvar message-sent-message-via nil)
1141 (defvar message-checksum nil)
1142 (defvar message-send-actions nil
1143 "A list of actions to be performed upon successful sending of a message.")
1144 (defvar message-exit-actions nil
1145 "A list of actions to be performed upon exiting after sending a message.")
1146 (defvar message-kill-actions nil
1147 "A list of actions to be performed before killing a message buffer.")
1148 (defvar message-postpone-actions nil
1149 "A list of actions to be performed after postponing a message.")
1150 (defvar message-original-frame nil)
1151 (defvar message-parameter-alist nil)
1152 (defvar message-startup-parameter-alist nil)
1154 (define-widget 'message-header-lines 'text
1155 "All header lines must be LFD terminated."
1156 :format "%{%t%}:%n%v"
1157 :valid-regexp "^\\'"
1158 :error "All header lines must be newline terminated")
1160 (defcustom message-default-headers ""
1161 "*A string containing header lines to be inserted in outgoing messages.
1162 It is inserted before you edit the message, so you can edit or delete
1164 :group 'message-headers
1165 :link '(custom-manual "(message)Message Headers")
1166 :type 'message-header-lines)
1168 (defcustom message-default-mail-headers ""
1169 "*A string of header lines to be inserted in outgoing mails."
1170 :group 'message-headers
1171 :group 'message-mail
1172 :link '(custom-manual "(message)Mail Headers")
1173 :type 'message-header-lines)
1175 (defcustom message-default-news-headers ""
1176 "*A string of header lines to be inserted in outgoing news articles."
1177 :group 'message-headers
1178 :group 'message-news
1179 :link '(custom-manual "(message)News Headers")
1180 :type 'message-header-lines)
1182 ;; Note: could use /usr/ucb/mail instead of sendmail;
1183 ;; options -t, and -v if not interactive.
1184 (defcustom message-mailer-swallows-blank-line
1185 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1186 system-configuration)
1187 (file-readable-p "/etc/sendmail.cf")
1188 (let ((buffer (get-buffer-create " *temp*")))
1192 (insert-file-contents "/etc/sendmail.cf")
1193 (goto-char (point-min))
1194 (let ((case-fold-search nil))
1195 (re-search-forward "^OR\\>" nil t)))
1196 (kill-buffer buffer))))
1197 ;; According to RFC822, "The field-name must be composed of printable
1198 ;; ASCII characters (i. e., characters that have decimal values between
1199 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1201 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1202 "*Set this non-nil if the system's mailer runs the header and body together.
1203 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1204 The value should be an expression to test whether the problem will
1206 :group 'message-sending
1207 :link '(custom-manual "(message)Mail Variables")
1210 ;;; XXX: This symbol is overloaded! See below.
1211 (defvar message-user-agent nil
1212 "String of the form of PRODUCT/VERSION. Used for User-Agent header field.")
1215 (define-mail-user-agent 'message-user-agent
1216 'message-mail 'message-send-and-exit
1217 'message-kill-buffer 'message-send-hook)
1219 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
1220 "If non-nil, delete the deletable headers before feeding to mh.")
1222 (defvar message-send-method-alist
1223 '((news message-news-p message-send-via-news)
1224 (mail message-mail-p message-send-via-mail))
1225 "Alist of ways to send outgoing messages.
1226 Each element has the form
1228 \(TYPE PREDICATE FUNCTION)
1230 where TYPE is a symbol that names the method; PREDICATE is a function
1231 called without any parameters to determine whether the message is
1232 a message of type TYPE; and FUNCTION is a function to be called if
1233 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1236 (defcustom message-mail-alias-type 'abbrev
1237 "*What alias expansion type to use in Message buffers.
1238 The default is `abbrev', which uses mailabbrev. nil switches
1241 :link '(custom-manual "(message)Mail Aliases")
1242 :type '(choice (const :tag "Use Mailabbrev" abbrev)
1243 (const :tag "No expansion" nil)))
1245 (defcustom message-auto-save-directory
1246 (file-name-as-directory (nnheader-concat message-directory "drafts"))
1247 "*Directory where Message auto-saves buffers if Gnus isn't running.
1248 If nil, Message won't auto-save."
1249 :group 'message-buffers
1250 :link '(custom-manual "(message)Various Message Variables")
1251 :type '(choice directory (const :tag "Don't auto-save" nil)))
1253 (defcustom message-default-charset
1254 (and (featurep 'xemacs) (not (featurep 'mule)) 'iso-8859-1)
1255 "Default charset used in non-MULE XEmacsen."
1258 :link '(custom-manual "(message)Various Message Variables")
1261 (defcustom message-dont-reply-to-names
1262 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
1263 "*A regexp specifying addresses to prune when doing wide replies.
1264 A value of nil means exclude your own user name only."
1267 :link '(custom-manual "(message)Wide Reply")
1268 :type '(choice (const :tag "Yourself" nil)
1271 (defvar message-shoot-gnksa-feet nil
1272 "*A list of GNKSA feet you are allowed to shoot.
1273 Gnus gives you all the opportunity you could possibly want for
1274 shooting yourself in the foot. Also, Gnus allows you to shoot the
1275 feet of Good Net-Keeping Seal of Approval. The following are foot
1277 `empty-article' Allow you to post an empty article;
1278 `quoted-text-only' Allow you to post quoted text only;
1279 `multiple-copies' Allow you to post multiple copies;
1280 `cancel-messages' Allow you to cancel or supersede messages from
1281 your other email addresses.")
1283 (defsubst message-gnksa-enable-p (feature)
1284 (or (not (listp message-shoot-gnksa-feet))
1285 (memq feature message-shoot-gnksa-feet)))
1287 (defcustom message-hidden-headers nil
1288 "Regexp of headers to be hidden when composing new messages.
1289 This can also be a list of regexps to match headers. Or a list
1290 starting with `not' and followed by regexps."
1293 :link '(custom-manual "(message)Message Headers")
1294 :type '(repeat regexp))
1296 (defcustom message-cite-articles-with-x-no-archive t
1297 "If non-nil, cite text from articles that has X-No-Archive set."
1301 ;;; Internal variables.
1302 ;;; Well, not really internal.
1304 (defvar message-mode-syntax-table
1305 (let ((table (copy-syntax-table text-mode-syntax-table)))
1306 (modify-syntax-entry ?% ". " table)
1307 (modify-syntax-entry ?> ". " table)
1308 (modify-syntax-entry ?< ". " table)
1310 "Syntax table used while in Message mode.")
1312 (defface message-header-to-face
1315 (:foreground "green2" :bold t))
1318 (:foreground "MidnightBlue" :bold t))
1320 (:bold t :italic t)))
1321 "Face used for displaying From headers."
1322 :group 'message-faces)
1324 (defface message-header-cc-face
1327 (:foreground "green4" :bold t))
1330 (:foreground "MidnightBlue"))
1333 "Face used for displaying Cc headers."
1334 :group 'message-faces)
1336 (defface message-header-subject-face
1339 (:foreground "green3"))
1342 (:foreground "navy blue" :bold t))
1345 "Face used for displaying subject headers."
1346 :group 'message-faces)
1348 (defface message-header-newsgroups-face
1351 (:foreground "yellow" :bold t :italic t))
1354 (:foreground "blue4" :bold t :italic t))
1356 (:bold t :italic t)))
1357 "Face used for displaying newsgroups headers."
1358 :group 'message-faces)
1360 (defface message-header-other-face
1363 (:foreground "#b00000"))
1366 (:foreground "steel blue"))
1368 (:bold t :italic t)))
1369 "Face used for displaying newsgroups headers."
1370 :group 'message-faces)
1372 (defface message-header-name-face
1375 (:foreground "DarkGreen"))
1378 (:foreground "cornflower blue"))
1381 "Face used for displaying header names."
1382 :group 'message-faces)
1384 (defface message-header-xheader-face
1387 (:foreground "blue"))
1390 (:foreground "blue"))
1393 "Face used for displaying X-Header headers."
1394 :group 'message-faces)
1396 (defface message-separator-face
1399 (:foreground "blue3"))
1402 (:foreground "brown"))
1405 "Face used for displaying the separator."
1406 :group 'message-faces)
1408 (defface message-cited-text-face
1411 (:foreground "red"))
1414 (:foreground "red"))
1417 "Face used for displaying cited text names."
1418 :group 'message-faces)
1420 (defface message-mml-face
1423 (:foreground "ForestGreen"))
1426 (:foreground "ForestGreen"))
1429 "Face used for displaying MML."
1430 :group 'message-faces)
1432 (defun message-font-lock-make-header-matcher (regexp)
1435 (let ((start (point)))
1438 (goto-char (point-min))
1439 (if (re-search-forward
1440 (concat "^" (regexp-quote mail-header-separator) "$")
1442 (setq limit (min limit (match-beginning 0))))
1444 (and (< start limit)
1445 (re-search-forward ,regexp limit t))))))
1446 (if (featurep 'bytecomp)
1450 (defvar message-font-lock-keywords
1451 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1452 `((,(message-font-lock-make-header-matcher
1453 (concat "^\\([Tt]o:\\)" content))
1454 (1 'message-header-name-face)
1455 (2 'message-header-to-face nil t))
1456 (,(message-font-lock-make-header-matcher
1457 (concat "^\\([GBF]?[Cc][Cc]:\\|[Rr]eply-[Tt]o:\\|"
1458 "[Mm]ail-[Cc]opies-[Tt]o:\\|"
1459 "[Mm]ail-[Rr]eply-[Tt]o:\\|"
1460 "[Mm]ail-[Ff]ollowup-[Tt]o:\\)" content))
1461 (1 'message-header-name-face)
1462 (2 'message-header-cc-face nil t))
1463 (,(message-font-lock-make-header-matcher
1464 (concat "^\\([Ss]ubject:\\)" content))
1465 (1 'message-header-name-face)
1466 (2 'message-header-subject-face nil t))
1467 (,(message-font-lock-make-header-matcher
1468 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content))
1469 (1 'message-header-name-face)
1470 (2 'message-header-newsgroups-face nil t))
1471 (,(message-font-lock-make-header-matcher
1472 (concat "^\\([A-Z][^: \n\t]+:\\)" content))
1473 (1 'message-header-name-face)
1474 (2 'message-header-other-face nil t))
1475 (,(message-font-lock-make-header-matcher
1476 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content))
1477 (1 'message-header-name-face)
1478 (2 'message-header-name-face))
1479 ,@(if (and mail-header-separator
1480 (not (equal mail-header-separator "")))
1481 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1482 1 'message-separator-face))
1485 (re-search-forward (concat "^\\("
1486 message-cite-prefix-regexp
1489 (0 'message-cited-text-face))
1490 (,mime-edit-tag-regexp
1491 (0 'message-mml-face))))
1492 "Additional expressions to highlight in Message mode.")
1494 ;; XEmacs does it like this. For Emacs, we have to set the
1495 ;; `font-lock-defaults' buffer-local variable.
1496 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
1498 (defvar message-face-alist
1499 '((bold . bold-region)
1500 (underline . underline-region)
1501 (default . (lambda (b e)
1503 (ununderline-region b e))))
1504 "Alist of mail and news faces for facemenu.
1505 The cdr of each entry is a function for applying the face to a region.")
1507 (defcustom message-send-hook nil
1508 "Hook run before sending messages.
1509 This hook is run quite early when sending."
1510 :group 'message-various
1511 :options '(ispell-message)
1512 :link '(custom-manual "(message)Various Message Variables")
1515 (defcustom message-send-mail-hook nil
1516 "Hook run before sending mail messages.
1517 This hook is run very late -- just before the message is sent as
1519 :group 'message-various
1520 :link '(custom-manual "(message)Various Message Variables")
1523 (defcustom message-send-news-hook nil
1524 "Hook run before sending news messages.
1525 This hook is run very late -- just before the message is sent as
1527 :group 'message-various
1528 :link '(custom-manual "(message)Various Message Variables")
1531 (defcustom message-sent-hook nil
1532 "Hook run after sending messages."
1533 :group 'message-various
1536 (defcustom message-use-multi-frames nil
1537 "Make new frame when sending messages."
1538 :group 'message-frames
1541 (defcustom message-delete-frame-on-exit nil
1542 "Delete frame after sending messages."
1543 :group 'message-frames
1544 :type '(choice (const :tag "off" nil)
1545 (const :tag "always" t)
1546 (const :tag "ask" ask)))
1548 (defvar message-draft-coding-system
1549 nnheader-auto-save-coding-system
1550 "*Coding system to compose mail.
1551 If you'd like to make it possible to share draft files between XEmacs
1552 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1553 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1555 (defcustom message-send-mail-partially-limit 1000000
1556 "The limitation of messages sent as message/partial.
1557 The lower bound of message size in characters, beyond which the message
1558 should be sent in several parts. If it is nil, the size is unlimited."
1560 :group 'message-buffers
1561 :link '(custom-manual "(message)Mail Variables")
1562 :type '(choice (const :tag "unlimited" nil)
1565 (defcustom message-alternative-emails nil
1566 "A regexp to match the alternative email addresses.
1567 The first matched address (not primary one) is used in the From field."
1568 :group 'message-headers
1569 :link '(custom-manual "(message)Message Headers")
1570 :type '(choice (const :tag "Always use primary" nil)
1573 (defcustom message-hierarchical-addresses nil
1574 "A list of hierarchical mail address definitions.
1576 Inside each entry, the first address is the \"top\" address, and
1577 subsequent addresses are subaddresses; this is used to indicate that
1578 mail sent to the first address will automatically be delivered to the
1579 subaddresses. So if the first address appears in the recipient list
1580 for a message, the subaddresses will be removed (if present) before
1581 the mail is sent. All addresses in this structure should be
1584 :group 'message-headers
1585 :type '(repeat (repeat string)))
1587 (defcustom message-mail-user-agent nil
1588 "Like `mail-user-agent'.
1589 Except if it is nil, use Gnus native MUA; if it is t, use
1592 :type '(radio (const :tag "Gnus native"
1595 (const :tag "`mail-user-agent'"
1598 (function-item :tag "Default Emacs mail"
1600 sendmail-user-agent)
1601 (function-item :tag "Emacs interface to MH"
1604 (function :tag "Other"))
1608 (defcustom message-wide-reply-confirm-recipients nil
1609 "Whether to confirm a wide reply to multiple email recipients.
1610 If this variable is nil, don't ask whether to reply to all recipients.
1611 If this variable is non-nil, pose the question \"Reply to all
1612 recipients?\" before a wide reply to multiple recipients. If the user
1613 answers yes, reply to all recipients as usual. If the user answers
1614 no, only reply back to the author."
1616 :group 'message-headers
1617 :link '(custom-manual "(message)Wide Reply")
1620 (defcustom message-user-fqdn nil
1621 "*Domain part of Messsage-Ids."
1622 :group 'message-headers
1623 :link '(custom-manual "(message)News Headers")
1624 :type '(radio (const :format "%v " nil)
1625 (string :format "FQDN: %v\n" :size 0)))
1627 (defcustom message-use-idna (and (condition-case nil (require 'idna)
1629 (mm-coding-system-p 'utf-8)
1630 (executable-find idna-program)
1632 "Whether to encode non-ASCII in domain names into ASCII according to IDNA."
1634 :group 'message-headers
1635 :link '(custom-manual "(message)IDNA")
1636 :type '(choice (const :tag "Ask" ask)
1637 (const :tag "Never" nil)
1638 (const :tag "Always" t)))
1640 (defcustom message-generate-hashcash nil
1641 "*Whether to generate X-Hashcash: headers.
1642 You must have the \"hashcash\" binary installed, see `hashcash-path'."
1643 :group 'message-headers
1644 :link '(custom-manual "(message)Mail Headers")
1647 ;;; Internal variables.
1649 (defvar message-sending-message "Sending...")
1650 (defvar message-buffer-list nil)
1651 (defvar message-this-is-news nil)
1652 (defvar message-this-is-mail nil)
1653 (defvar message-draft-article nil)
1654 (defvar message-mime-part nil)
1655 (defvar message-posting-charset nil)
1656 (defvar message-inserted-headers nil)
1658 ;; Byte-compiler warning
1660 (defvar gnus-active-hashtb)
1661 (defvar gnus-read-active-file))
1663 ;;; Regexp matching the delimiter of messages in UNIX mail format
1664 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1665 ;;; of rmail.el's rmail-unix-mail-delimiter.
1666 (defvar message-unix-mail-delimiter
1667 (let ((time-zone-regexp
1668 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1669 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1675 ;; Many things can happen to an RFC 822 mailbox before it is put into
1676 ;; a `From' line. The leading phrase can be stripped, e.g.
1677 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1678 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1679 ;; can be removed, e.g.
1680 ;; From: joe@y.z (Joe K
1682 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1685 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1686 ;; The mailbox can be removed or be replaced by white space, e.g.
1687 ;; From: "Joe User"{space}{tab}
1689 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1690 ;; where {space} and {tab} represent the Ascii space and tab characters.
1691 ;; We want to match the results of any of these manglings.
1692 ;; The following regexp rejects names whose first characters are
1693 ;; obviously bogus, but after that anything goes.
1694 "\\([^\0-\b\n-\r\^?].*\\)?"
1696 ;; The time the message was sent.
1697 "\\([^\0-\r \^?]+\\) +" ; day of the week
1698 "\\([^\0-\r \^?]+\\) +" ; month
1699 "\\([0-3]?[0-9]\\) +" ; day of month
1700 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1702 ;; Perhaps a time zone, specified by an abbreviation, or by a
1707 " \\([0-9][0-9]+\\) *"
1709 ;; On some systems the time zone can appear after the year, too.
1713 "\\(remote from .*\\)?"
1716 "Regexp matching the delimiter of messages in UNIX mail format.")
1718 (defvar message-unsent-separator
1719 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1720 "^ *---+ +Returned message +---+ *$\\|"
1721 "^Start of returned message$\\|"
1722 "^ *---+ +Original message +---+ *$\\|"
1723 "^ *--+ +begin message +--+ *$\\|"
1724 "^ *---+ +Original message follows +---+ *$\\|"
1725 "^ *---+ +Undelivered message follows +---+ *$\\|"
1726 "^|? *---+ +Message text follows: +---+ *|?$")
1727 "A regexp that matches the separator before the text of a failed message.")
1729 (defvar message-field-fillers
1730 '((To message-fill-field-address)
1731 (Cc message-fill-field-address)
1732 (From message-fill-field-address))
1733 "Alist of header names/filler functions.")
1735 (defvar message-header-format-alist
1749 (References . message-shorten-references)
1751 "Alist used for formatting headers.")
1753 (defvar message-options nil
1754 "Some saved answers when sending message.")
1756 (defvar message-send-mail-real-function nil
1757 "Internal send mail function.")
1759 (defvar message-bogus-system-names "^localhost\\."
1760 "The regexp of bogus system names.")
1762 (defcustom message-valid-fqdn-regexp
1763 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1765 "\\([a-z][a-z]" ;; two letter country TDLs
1766 "\\|biz\\|com\\|edu\\|gov\\|int\\|mil\\|net\\|org"
1767 "\\|aero\\|coop\\|info\\|name\\|museum"
1768 "\\|arpa\\|pro\\|uucp\\|bitnet\\|bofh" ;; old style?
1770 "Regular expression that matches a valid FQDN."
1771 ;; see also: gnus-button-valid-fqdn-regexp
1773 :group 'message-headers
1777 (autoload 'gnus-alive-p "gnus-util")
1778 (autoload 'gnus-delay-article "gnus-delay")
1779 (autoload 'gnus-extract-address-components "gnus-util")
1780 (autoload 'gnus-find-method-for-group "gnus")
1781 (autoload 'gnus-group-decoded-name "gnus-group")
1782 (autoload 'gnus-group-name-charset "gnus-group")
1783 (autoload 'gnus-group-name-decode "gnus-group")
1784 (autoload 'gnus-groups-from-server "gnus")
1785 (autoload 'gnus-make-local-hook "gnus-util")
1786 (autoload 'gnus-open-server "gnus-int")
1787 (autoload 'gnus-output-to-mail "gnus-util")
1788 (autoload 'gnus-output-to-rmail "gnus-util")
1789 (autoload 'gnus-request-post "gnus-int")
1790 (autoload 'gnus-server-string "gnus")
1791 (autoload 'idna-to-ascii "idna")
1792 (autoload 'message-setup-toolbar "messagexmas")
1793 (autoload 'mh-new-draft-name "mh-comp")
1794 (autoload 'mh-send-letter "mh-comp")
1795 (autoload 'mu-cite-original "mu-cite")
1796 (autoload 'nndraft-request-associate-buffer "nndraft")
1797 (autoload 'nndraft-request-expire-articles "nndraft")
1798 (autoload 'nnvirtual-find-group-art "nnvirtual")
1799 (autoload 'rmail-dont-reply-to "mail-utils")
1800 (autoload 'rmail-msg-is-pruned "rmail")
1801 (autoload 'rmail-msg-restore-non-pruned-header "rmail")
1802 (autoload 'rmail-output "rmailout"))
1807 ;;; Utility functions.
1809 (defun message-eval-parameter (parameter)
1811 (if (symbolp parameter)
1812 (if (functionp parameter)
1818 (defsubst message-get-parameter (key &optional alist)
1820 (setq alist message-parameter-alist))
1821 (cdr (assq key alist)))
1823 (defmacro message-get-parameter-with-eval (key &optional alist)
1824 `(message-eval-parameter (message-get-parameter ,key ,alist)))
1826 (defmacro message-y-or-n-p (question show &rest text)
1827 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1828 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1830 (defmacro message-delete-line (&optional n)
1831 "Delete the current line (and the next N lines)."
1832 `(delete-region (progn (beginning-of-line) (point))
1833 (progn (forward-line ,(or n 1)) (point))))
1835 (defun message-mark-active-p ()
1836 "Non-nil means the mark and region are currently active in this buffer."
1839 (defun message-unquote-tokens (elems)
1840 "Remove double quotes (\") from strings in list ELEMS."
1841 (mapcar (lambda (item)
1842 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1843 (setq item (concat (match-string 1 item)
1844 (match-string 2 item))))
1848 (defun message-tokenize-header (header &optional separator)
1849 "Split HEADER into a list of header elements.
1850 SEPARATOR is a string of characters to be used as separators. \",\"
1851 is used by default."
1854 (let ((regexp (format "[%s]+" (or separator ",")))
1859 (set-buffer-multibyte t)
1861 (goto-char (point-min))
1866 (cond ((and (> (point) beg)
1868 (and (looking-at regexp)
1871 (push (buffer-substring beg (point)) elems)
1872 (setq beg (match-end 0)))
1873 ((eq (char-after) ?\")
1874 (setq quoted (not quoted)))
1875 ((and (eq (char-after) ?\()
1878 ((and (eq (char-after) ?\))
1881 (nreverse elems)))))
1883 (defun message-mail-file-mbox-p (file)
1884 "Say whether FILE looks like a Unix mbox file."
1885 (when (and (file-exists-p file)
1886 (file-readable-p file)
1887 (file-regular-p file))
1889 (nnheader-insert-file-contents file)
1890 (goto-char (point-min))
1891 (looking-at message-unix-mail-delimiter))))
1893 (defun message-fetch-field (header &optional not-all)
1894 "The same as `mail-fetch-field', only remove all newlines.
1895 The buffer is expected to be narrowed to just the header of the message;
1896 see `message-narrow-to-headers-or-head'."
1897 (let* ((inhibit-point-motion-hooks t)
1898 (value (mail-fetch-field header nil (not not-all))))
1900 (while (string-match "\n[\t ]+" value)
1901 (setq value (replace-match " " t t value)))
1904 (defun message-field-value (header &optional not-all)
1905 "The same as `message-fetch-field', only narrow to the headers first."
1908 (message-narrow-to-headers-or-head)
1909 (message-fetch-field header not-all))))
1911 (defun message-narrow-to-field ()
1912 "Narrow the buffer to the header on the current line."
1914 (while (looking-at "[ \t]")
1920 (if (re-search-forward "^[^ \n\t]" nil t)
1923 (goto-char (point-min)))
1925 (defun message-add-header (&rest headers)
1926 "Add the HEADERS to the message header, skipping those already present."
1929 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1930 (error "Invalid header `%s'" (car headers)))
1931 (setq hclean (match-string 1 (car headers)))
1933 (message-narrow-to-headers)
1934 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1935 (goto-char (point-max))
1936 (if (string-match "\n$" (car headers))
1937 (insert (car headers))
1938 (insert (car headers) ?\n)))))
1939 (setq headers (cdr headers))))
1941 (defmacro message-with-reply-buffer (&rest forms)
1942 "Evaluate FORMS in the reply buffer, if it exists."
1943 `(let ((buffer (message-eval-parameter message-reply-buffer)))
1945 (buffer-name buffer))
1950 (put 'message-with-reply-buffer 'lisp-indent-function 0)
1951 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
1953 (defun message-fetch-reply-field (header)
1954 "Fetch field HEADER from the message we're replying to."
1955 (message-with-reply-buffer
1957 (mail-narrow-to-head)
1958 (message-fetch-field header))))
1960 (defun message-strip-list-identifiers (subject)
1961 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1962 (require 'gnus-sum) ; for gnus-list-identifiers
1963 (let ((regexp (if (stringp gnus-list-identifiers)
1964 gnus-list-identifiers
1965 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1966 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1967 " *\\)\\)+\\(Re: +\\)?\\)") subject)
1968 (concat (substring subject 0 (match-beginning 1))
1969 (or (match-string 3 subject)
1970 (match-string 5 subject))
1975 (defun message-strip-subject-re (subject)
1976 "Remove \"Re:\" from subject lines in string SUBJECT."
1977 (if (string-match message-subject-re-regexp subject)
1978 (substring subject (match-end 0))
1981 ;;; Start of functions adopted from `message-utils.el'.
1983 (defun message-strip-subject-trailing-was (subject)
1984 "Remove trailing \"(Was: <old subject>)\" from SUBJECT lines.
1985 Leading \"Re: \" is not stripped by this function. Use the function
1986 `message-strip-subject-re' for this."
1987 (let* ((query message-subject-trailing-was-query)
1992 message-subject-trailing-was-ask-regexp
1993 message-subject-trailing-was-regexp)
1996 (setq new (substring subject 0 (match-beginning 0))))
1997 (if (or (not found) (eq query nil))
2000 (if (message-y-or-n-p
2001 "Strip `(was: <old subject>)' in subject? " t
2003 "Strip `(was: <old subject>)' in subject "
2004 "and use the new one instead?\n\n"
2005 "Current subject is: \""
2007 "New subject would be: \""
2009 "See the variable `message-subject-trailing-was-query' "
2010 "to get rid of this query."
2015 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
2018 (defun message-change-subject (new-subject)
2019 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
2020 ;; <URL:http://www.landfield.com/usefor/drafts/draft-ietf-usefor-useage--1.02.unpaged>
2023 (read-from-minibuffer "New subject: ")))
2024 (cond ((and (not (or (null new-subject) ; new subject not empty
2025 (zerop (string-width new-subject))
2026 (string-match "^[ \t]*$" new-subject))))
2030 (message-narrow-to-headers)
2031 (message-fetch-field "Subject"))))
2032 (cond ((not old-subject)
2033 (error "No current subject"))
2036 (regexp-quote new-subject)
2038 old-subject)) ; yes, it really is a new subject
2039 ;; delete eventual Re: prefix
2041 (message-strip-subject-re old-subject))
2042 (message-goto-subject)
2043 (message-delete-line)
2044 (insert (concat "Subject: "
2047 old-subject ")\n")))))))))
2050 (defun message-mark-inserted-region (beg end)
2051 "Mark some region in the current article with enclosing tags.
2052 See `message-mark-insert-begin' and `message-mark-insert-end'."
2055 ;; add to the end of the region first, otherwise end would be invalid
2057 (insert message-mark-insert-end)
2059 (insert message-mark-insert-begin)))
2062 (defun message-mark-insert-file (file)
2063 "Insert FILE at point, marking it with enclosing tags.
2064 See `message-mark-insert-begin' and `message-mark-insert-end'."
2065 (interactive "fFile to insert: ")
2066 ;; reverse insertion to get correct result.
2068 (insert message-mark-insert-end)
2070 (insert-file-contents file)
2072 (insert message-mark-insert-begin)))
2075 (defun message-add-archive-header ()
2076 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
2077 The note can be customized using `message-archive-note'. When called with a
2078 prefix argument, ask for a text to insert. If you don't want the note in the
2079 body, set `message-archive-note' to nil."
2081 (if current-prefix-arg
2082 (setq message-archive-note
2083 (read-from-minibuffer "Reason for No-Archive: "
2084 (cons message-archive-note 0))))
2086 (if (message-goto-signature)
2087 (re-search-backward message-signature-separator))
2088 (when message-archive-note
2089 (insert message-archive-note)
2091 (message-add-header message-archive-header)
2092 (message-sort-headers)))
2095 (defun message-cross-post-followup-to-header (target-group)
2096 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
2097 With prefix-argument just set Follow-Up, don't cross-post."
2099 (list ; Completion based on Gnus
2100 (completing-read "Followup To: "
2101 (if (boundp 'gnus-newsrc-alist)
2103 nil nil '("poster" . 0)
2104 (if (boundp 'gnus-group-history)
2105 'gnus-group-history))))
2106 (message-remove-header "Follow[Uu]p-[Tt]o" t)
2107 (message-goto-newsgroups)
2109 ;; if we already did a crosspost before, kill old target
2110 (if (and message-cross-post-old-target
2112 (regexp-quote (concat "," message-cross-post-old-target))
2115 ;; unless (followup is to poster or user explicitly asked not
2116 ;; to cross-post, or target-group is already in Newsgroups)
2117 ;; add target-group to Newsgroups line.
2119 ;; def: cross-post, req:no
2120 (and message-cross-post-default (not current-prefix-arg))
2121 ;; def: no-cross-post, req:yes
2122 (and (not message-cross-post-default) current-prefix-arg))
2123 (not (string-match "poster" target-group))
2124 (not (string-match (regexp-quote target-group)
2125 (message-fetch-field "Newsgroups"))))
2127 (insert (concat "," target-group))))
2128 (end-of-line) ; ensure Followup: comes after Newsgroups:
2129 ;; unless new followup would be identical to Newsgroups line
2130 ;; make a new Followup-To line
2131 (if (not (string-match (concat "^[ \t]*"
2134 (message-fetch-field "Newsgroups")))
2135 (insert (concat "\nFollowup-To: " target-group)))
2136 (setq message-cross-post-old-target target-group))
2139 (defun message-cross-post-insert-note (target-group cross-post in-old
2141 "Insert a in message body note about a set Followup or Crosspost.
2142 If there have been previous notes, delete them. TARGET-GROUP specifies the
2143 group to Followup-To. When CROSS-POST is t, insert note about
2144 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
2145 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
2146 been made to before the user asked for a Crosspost."
2147 ;; start scanning body for previous uses
2148 (message-goto-signature)
2149 (let ((head (re-search-backward
2150 (concat "^" mail-header-separator)
2151 nil t))) ; just search in body
2152 (message-goto-signature)
2153 (while (re-search-backward
2154 (concat "^" (regexp-quote message-cross-post-note) ".*")
2156 (message-delete-line))
2157 (message-goto-signature)
2158 (while (re-search-backward
2159 (concat "^" (regexp-quote message-followup-to-note) ".*")
2161 (message-delete-line))
2163 (if (message-goto-signature)
2164 (re-search-backward message-signature-separator))
2167 (string-match "^[ \t]*poster[ \t]*$" target-group))
2168 (insert (concat message-followup-to-note target-group "\n"))
2169 (insert (concat message-cross-post-note target-group "\n")))))
2172 (defun message-cross-post-followup-to (target-group)
2173 "Crossposts message and set Followup-To to TARGET-GROUP.
2174 With prefix-argument just set Follow-Up, don't cross-post."
2176 (list ; Completion based on Gnus
2177 (completing-read "Followup To: "
2178 (if (boundp 'gnus-newsrc-alist)
2180 nil nil '("poster" . 0)
2181 (if (boundp 'gnus-group-history)
2182 'gnus-group-history))))
2183 (cond ((not (or (null target-group) ; new subject not empty
2184 (zerop (string-width target-group))
2185 (string-match "^[ \t]*$" target-group)))
2187 (let* ((old-groups (message-fetch-field "Newsgroups"))
2188 (in-old (string-match
2189 (regexp-quote target-group)
2190 (or old-groups ""))))
2191 ;; check whether target exactly matches old Newsgroups
2192 (cond ((not old-groups)
2193 (error "No current newsgroup"))
2197 (regexp-quote target-group)
2200 ;; yes, Newsgroups line must change
2201 (message-cross-post-followup-to-header target-group)
2202 ;; insert note whether we do cross-post or followup-to
2203 (funcall message-cross-post-note-function
2205 (if (or (and message-cross-post-default
2206 (not current-prefix-arg))
2207 (and (not message-cross-post-default)
2208 current-prefix-arg)) t)
2209 in-old old-groups))))))))
2211 ;;; Reduce To: to Cc: or Bcc: header
2214 (defun message-reduce-to-to-cc ()
2215 "Replace contents of To: header with contents of Cc: or Bcc: header."
2218 (save-restriction (message-narrow-to-headers)
2219 (message-fetch-field "cc")))
2221 (if (and (not cc-content)
2224 (message-narrow-to-headers)
2225 (message-fetch-field "bcc"))))
2230 (message-delete-line)
2231 (insert (concat "To: " cc-content "\n"))
2233 (message-narrow-to-headers)
2234 (message-remove-header (if bcc
2238 ;;; End of functions adopted from `message-utils.el'.
2240 (defun message-remove-header (header &optional is-regexp first reverse)
2241 "Remove HEADER in the narrowed buffer.
2242 If IS-REGEXP, HEADER is a regular expression.
2243 If FIRST, only remove the first instance of the header.
2244 Return the number of headers removed."
2245 (goto-char (point-min))
2246 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
2248 (case-fold-search t)
2250 (while (and (not (eobp))
2253 (not (looking-at regexp))
2254 (looking-at regexp))
2261 ;; There might be a continuation header, so we have to search
2262 ;; until we find a new non-continuation line.
2265 (if (re-search-forward "^[^ \t]" nil t)
2266 (goto-char (match-beginning 0))
2269 (if (re-search-forward "^[^ \t]" nil t)
2270 (goto-char (match-beginning 0))
2271 (goto-char (point-max)))))
2274 (defun message-remove-first-header (header)
2275 "Remove the first instance of HEADER if there is more than one."
2277 (regexp (concat "^" (regexp-quote header) ":")))
2279 (goto-char (point-min))
2280 (while (re-search-forward regexp nil t)
2283 (message-remove-header header nil t)
2286 (defun message-narrow-to-headers ()
2287 "Narrow the buffer to the head of the message."
2290 (goto-char (point-min))
2291 (if (re-search-forward
2292 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2295 (goto-char (point-min)))
2297 (defun message-narrow-to-head-1 ()
2298 "Like `message-narrow-to-head'. Don't widen."
2300 (goto-char (point-min))
2301 (if (search-forward "\n\n" nil 1)
2304 (goto-char (point-min)))
2306 (defun message-narrow-to-head ()
2307 "Narrow the buffer to the head of the message.
2308 Point is left at the beginning of the narrowed-to region."
2310 (message-narrow-to-head-1))
2312 (defun message-narrow-to-headers-or-head ()
2313 "Narrow the buffer to the head of the message."
2316 (goto-char (point-min))
2319 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2320 (match-beginning 0))
2321 ((search-forward "\n\n" nil t)
2325 (goto-char (point-min)))
2327 (defun message-news-p ()
2328 "Say whether the current buffer contains a news message."
2329 (and (not message-this-is-mail)
2330 (or message-this-is-news
2333 (message-narrow-to-headers)
2334 (and (message-fetch-field "newsgroups")
2335 (not (message-fetch-field "posted-to"))))))))
2337 (defun message-mail-p ()
2338 "Say whether the current buffer contains a mail message."
2339 (and (not message-this-is-news)
2340 (or message-this-is-mail
2343 (message-narrow-to-headers)
2344 (or (message-fetch-field "to")
2345 (message-fetch-field "cc")
2346 (message-fetch-field "bcc")))))))
2348 (defun message-subscribed-p ()
2349 "Say whether we need to insert a MFT header."
2350 (or message-subscribed-regexps
2351 message-subscribed-addresses
2352 message-subscribed-address-file
2353 message-subscribed-address-functions))
2355 (defun message-next-header ()
2356 "Go to the beginning of the next header."
2358 (or (eobp) (forward-char 1))
2359 (not (if (re-search-forward "^[^ \t]" nil t)
2361 (goto-char (point-max)))))
2363 (defun message-sort-headers-1 ()
2364 "Sort the buffer as headers using `message-rank' text props."
2365 (goto-char (point-min))
2368 nil 'message-next-header
2370 (message-next-header)
2374 (or (get-text-property (point) 'message-rank)
2377 (defun message-sort-headers ()
2378 "Sort the headers of the current message according to `message-header-format-alist'."
2382 (let ((max (1+ (length message-header-format-alist)))
2384 (message-narrow-to-headers)
2385 (while (re-search-forward "^[^ \n]+:" nil t)
2387 (match-beginning 0) (1+ (match-beginning 0))
2389 (if (setq rank (length (memq (assq (intern (buffer-substring
2391 (1- (match-end 0))))
2392 message-header-format-alist)
2393 message-header-format-alist)))
2396 (message-sort-headers-1))))
2398 (defun message-kill-address ()
2399 "Kill the address under point."
2401 (let ((start (point)))
2402 (message-skip-to-next-address)
2403 (kill-region start (point))))
2413 (defvar message-mode-map nil)
2415 (unless message-mode-map
2416 (setq message-mode-map (make-keymap))
2417 (set-keymap-parent message-mode-map text-mode-map)
2418 (define-key message-mode-map "\C-c?" 'describe-mode)
2420 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
2421 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
2422 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
2423 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
2424 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
2425 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2426 ;; (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2427 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-mail-reply-to)
2428 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2429 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2430 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2431 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2432 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2433 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2434 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2435 (define-key message-mode-map "\C-c\C-f\C-i"
2436 'message-insert-or-toggle-importance)
2437 (define-key message-mode-map "\C-c\C-f\C-a"
2438 'message-generate-unsubscribed-mail-followup-to)
2440 ;; modify headers (and insert notes in body)
2441 (define-key message-mode-map "\C-c\C-fs" 'message-change-subject)
2443 (define-key message-mode-map "\C-c\C-fx" 'message-cross-post-followup-to)
2444 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2445 (define-key message-mode-map "\C-c\C-ft" 'message-reduce-to-to-cc)
2446 (define-key message-mode-map "\C-c\C-fa" 'message-add-archive-header)
2447 ;; mark inserted text
2448 (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2449 (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2451 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2452 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2453 (define-key message-mode-map "\C-c\C-fc" 'message-goto-mail-copies-to)
2455 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2456 (define-key message-mode-map "\C-c\C-fw" 'message-insert-wide-reply)
2457 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2458 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2460 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2461 (define-key message-mode-map "\C-c\M-n"
2462 'message-insert-disposition-notification-to)
2464 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2465 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2466 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2467 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2468 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2469 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2470 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2471 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2473 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2474 (define-key message-mode-map "\C-c\C-s" 'message-send)
2475 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2476 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2477 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2479 (define-key message-mode-map "\C-c\M-k" 'message-kill-address)
2480 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2481 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2482 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2483 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2484 (define-key message-mode-map [remap split-line] 'message-split-line)
2486 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2487 (define-key message-mode-map "\t" 'message-tab)
2488 (define-key message-mode-map "\M-;" 'comment-region)
2490 (define-key message-mode-map "\C-xk" 'message-mimic-kill-buffer))
2493 message-mode-menu message-mode-map "Message Menu."
2495 ["Yank Original" message-yank-original t]
2496 ["Fill Yanked Message" message-fill-yanked-message t]
2497 ["Insert Signature" message-insert-signature t]
2498 ["Caesar (rot13) Message" message-caesar-buffer-body t]
2499 ["Caesar (rot13) Region" message-caesar-region (message-mark-active-p)]
2500 ["Elide Region" message-elide-region
2501 :active (message-mark-active-p)
2502 ,@(if (featurep 'xemacs) nil
2503 '(:help "Replace text in region with an ellipsis"))]
2504 ["Delete Outside Region" message-delete-not-region
2505 :active (message-mark-active-p)
2506 ,@(if (featurep 'xemacs) nil
2507 '(:help "Delete all quoted text outside region"))]
2508 ["Kill To Signature" message-kill-to-signature t]
2509 ["Newline and Reformat" message-newline-and-reformat t]
2510 ["Rename buffer" message-rename-buffer t]
2511 ["Spellcheck" ispell-message
2512 ,@(if (featurep 'xemacs) '(t)
2513 '(:help "Spellcheck this message"))]
2514 ["Attach file as MIME" mime-edit-insert-file
2515 ,@(if (featurep 'xemacs) '(t)
2516 '(:help "Attach a file at point"))]
2518 ["Insert Region Marked" message-mark-inserted-region
2519 :active (message-mark-active-p)
2520 ,@(if (featurep 'xemacs) nil
2521 '(:help "Mark region with enclosing tags"))]
2522 ["Insert File Marked..." message-mark-insert-file
2523 ,@(if (featurep 'xemacs) '(t)
2524 '(:help "Insert file at point marked with enclosing tags"))]
2526 ["Send Message" message-send-and-exit
2527 ,@(if (featurep 'xemacs) '(t)
2528 '(:help "Send this message"))]
2529 ["Postpone Message" message-dont-send
2530 ,@(if (featurep 'xemacs) '(t)
2531 '(:help "File this draft message and exit"))]
2532 ["Send at Specific Time..." gnus-delay-article
2533 ,@(if (featurep 'xemacs) '(t)
2534 '(:help "Ask, then arrange to send message at that time"))]
2535 ["Kill Message" message-kill-buffer
2536 ,@(if (featurep 'xemacs) '(t)
2537 '(:help "Delete this message without sending"))]))
2540 message-mode-field-menu message-mode-map ""
2542 ["To" message-goto-to t]
2543 ["From" message-goto-from t]
2544 ["Subject" message-goto-subject t]
2545 ["Change subject..." message-change-subject t]
2546 ["Cc" message-goto-cc t]
2547 ["Bcc" message-goto-bcc t]
2548 ["Fcc" message-goto-fcc t]
2549 ["Reply-To" message-goto-reply-to t]
2550 ["Flag As Important" message-insert-importance-high
2551 ,@(if (featurep 'xemacs) '(t)
2552 '(:help "Mark this message as important"))]
2553 ["Flag As Unimportant" message-insert-importance-low
2554 ,@(if (featurep 'xemacs) '(t)
2555 '(:help "Mark this message as unimportant"))]
2557 message-insert-disposition-notification-to
2558 ,@(if (featurep 'xemacs) '(t)
2559 '(:help "Request a receipt notification"))]
2561 ;; (typical) news stuff
2562 ["Summary" message-goto-summary t]
2563 ["Keywords" message-goto-keywords t]
2564 ["Newsgroups" message-goto-newsgroups t]
2565 ["Fetch Newsgroups" message-insert-newsgroups t]
2566 ["Followup-To" message-goto-followup-to t]
2567 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2568 ["Crosspost / Followup-To..." message-cross-post-followup-to t]
2569 ["Distribution" message-goto-distribution t]
2570 ["X-No-Archive:" message-add-archive-header t ]
2572 ;; (typical) mailing-lists stuff
2573 ["Fetch To" message-insert-to
2574 ,@(if (featurep 'xemacs) '(t)
2575 '(:help "Insert a To header that points to the author."))]
2576 ["Fetch To and Cc" message-insert-wide-reply
2577 ,@(if (featurep 'xemacs) '(t)
2579 "Insert To and Cc headers as if you were doing a wide reply."))]
2581 ["Send to list only" message-to-list-only t]
2582 ["Mail-Followup-To" message-goto-mail-followup-to t]
2583 ["Mail-Reply-To" message-goto-mail-reply-to t]
2584 ["Mail-Copies-To" message-goto-mail-copies-to t]
2585 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2586 ,@(if (featurep 'xemacs) '(t)
2587 '(:help "Insert a reasonable `Mail-Followup-To:' header."))]
2588 ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2590 ["Sort Headers" message-sort-headers t]
2591 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t]
2592 ["Goto Body" message-goto-body t]
2593 ["Goto Signature" message-goto-signature t]))
2595 (defvar message-tool-bar-map nil)
2598 (defvar facemenu-add-face-function)
2599 (defvar facemenu-remove-face-function))
2601 ;;; Forbidden properties
2603 ;; We use `after-change-functions' to keep special text properties
2604 ;; that interfer with the normal function of message mode out of the
2607 (defcustom message-strip-special-text-properties t
2608 "Strip special properties from the message buffer.
2610 Emacs has a number of special text properties which can break message
2611 composing in various ways. If this option is set, message will strip
2612 these properties from the message composition buffer. However, some
2613 packages requires these properties to be present in order to work.
2614 If you use one of these packages, turn this option off, and hope the
2615 message composition doesn't break too bad."
2617 :group 'message-various
2618 :link '(custom-manual "(message)Various Message Variables")
2621 (defconst message-forbidden-properties
2622 ;; No reason this should be clutter up customize. We make it a
2623 ;; property list (rather than a list of property symbols), to be
2624 ;; directly useful for `remove-text-properties'.
2625 '(field nil read-only nil invisible nil intangible nil
2626 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2627 insert-behind-hooks nil point-entered nil point-left nil)
2628 ;; Other special properties:
2629 ;; category, face, display: probably doesn't do any harm.
2630 ;; fontified: is used by font-lock.
2631 ;; syntax-table, local-map: I dunno.
2632 ;; We need to add XEmacs names to the list.
2633 "Property list of with properties.forbidden in message buffers.
2634 The values of the properties are ignored, only the property names are used.")
2636 (defun message-tamago-not-in-use-p (pos)
2637 "Return t when tamago version 4 is not in use at the cursor position.
2638 Tamago version 4 is a popular input method for writing Japanese text.
2639 It uses the properties `intangible', `invisible', `modification-hooks'
2640 and `read-only' when translating ascii or kana text to kanji text.
2641 These properties are essential to work, so we should never strip them."
2642 (not (and (boundp 'egg-modefull-mode)
2643 (symbol-value 'egg-modefull-mode)
2644 (or (memq (get-text-property pos 'intangible)
2645 '(its-part-1 its-part-2))
2646 (get-text-property pos 'egg-end)
2647 (get-text-property pos 'egg-lang)
2648 (get-text-property pos 'egg-start)))))
2650 (defun message-strip-forbidden-properties (begin end &optional old-length)
2651 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2652 This function is intended to be called from `after-change-functions'.
2653 See also `message-forbidden-properties'."
2654 (when (and message-strip-special-text-properties
2655 (message-tamago-not-in-use-p begin)
2656 ;; Check whether the invisible MIME part is not inserted.
2657 (not (text-property-any begin end 'mime-edit-invisible t)))
2658 (dolist (from-to (message-text-with-property 'message-hidden
2660 (remove-text-properties (car from-to) (cdr from-to)
2661 message-forbidden-properties))))
2664 (define-derived-mode message-mode text-mode "Message"
2665 "Major mode for editing mail and news to be sent.
2666 Like Text Mode but with these additional commands:\\<message-mode-map>
2667 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2668 C-c C-d Postpone sending the message C-c C-k Kill the message
2669 C-c C-f move to a header field (and create it if there isn't):
2670 C-c C-f C-t move to To C-c C-f C-s move to Subject
2671 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2672 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2673 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2674 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2675 C-c C-f C-o move to From (\"Originator\")
2676 C-c C-f C-f move to Followup-To
2677 C-c C-f C-m move to Mail-Followup-To
2678 C-c C-f c move to Mail-Copies-To
2679 C-c C-f C-i cycle through Importance values
2680 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2681 C-c C-f x crossposting with FollowUp-To header and note in body
2682 C-c C-f t replace To: header with contents of Cc: or Bcc:
2683 C-c C-f a Insert X-No-Archive: header and a note in the body
2684 C-c C-t `message-insert-to' (add a To header to a news followup)
2685 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2686 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2687 C-c C-b `message-goto-body' (move to beginning of message text).
2688 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2689 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2690 C-c C-y `message-yank-original' (insert current message, if any).
2691 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2692 C-c C-e `message-elide-region' (elide the text between point and mark).
2693 C-c C-v `message-delete-not-region' (remove the text outside the region).
2694 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2695 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2696 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2697 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2698 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2699 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2700 M-RET `message-newline-and-reformat' (break the line and reformat)."
2701 (setq local-abbrev-table text-mode-abbrev-table)
2702 (set (make-local-variable 'message-reply-buffer) nil)
2703 (set (make-local-variable 'message-inserted-headers) nil)
2704 (set (make-local-variable 'message-send-actions) nil)
2705 (set (make-local-variable 'message-exit-actions) nil)
2706 (set (make-local-variable 'message-kill-actions) nil)
2707 (set (make-local-variable 'message-postpone-actions) nil)
2708 (set (make-local-variable 'message-draft-article) nil)
2709 (setq buffer-offer-save t)
2710 (set (make-local-variable 'facemenu-add-face-function)
2712 (let ((face-fun (cdr (assq face message-face-alist))))
2714 (funcall face-fun (point) end)
2715 (error "Face %s not configured for %s mode" face mode-name)))
2717 (set (make-local-variable 'facemenu-remove-face-function) t)
2718 (set (make-local-variable 'message-reply-headers) nil)
2719 (make-local-variable 'message-user-agent)
2720 (make-local-variable 'message-post-method)
2721 (set (make-local-variable 'message-sent-message-via) nil)
2722 (set (make-local-variable 'message-checksum) nil)
2723 (make-local-variable 'message-parameter-alist)
2724 (setq message-parameter-alist
2725 (copy-sequence message-startup-parameter-alist))
2726 (message-setup-fill-variables)
2727 ;; Allow using comment commands to add/remove quoting.
2728 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2729 (when message-yank-prefix
2730 (set (make-local-variable 'comment-start) message-yank-prefix)
2731 (set (make-local-variable 'comment-start-skip)
2732 (concat "^" (regexp-quote message-yank-prefix) "[ \t]*")))
2733 (if (featurep 'xemacs)
2734 (message-setup-toolbar)
2735 (set (make-local-variable 'font-lock-defaults)
2736 '(message-font-lock-keywords t))
2737 (if (boundp 'tool-bar-map)
2738 (set (make-local-variable 'tool-bar-map) (message-tool-bar-map))))
2739 (easy-menu-add message-mode-menu message-mode-map)
2740 (easy-menu-add message-mode-field-menu message-mode-map)
2741 (gnus-make-local-hook 'after-change-functions)
2742 ;; Mmmm... Forbidden properties...
2743 (add-hook 'after-change-functions 'message-strip-forbidden-properties
2745 ;; Allow mail alias things.
2746 (when (eq message-mail-alias-type 'abbrev)
2747 (if (fboundp 'mail-abbrevs-setup)
2748 (mail-abbrevs-setup)
2749 (if (fboundp 'mail-aliases-setup) ; warning avoidance
2750 (mail-aliases-setup))))
2751 (unless buffer-file-name
2752 (message-set-auto-save-file-name))
2753 (set (make-local-variable 'indent-tabs-mode) nil)) ;No tabs for indentation.
2755 (defun message-setup-fill-variables ()
2756 "Setup message fill variables."
2757 (set (make-local-variable 'fill-paragraph-function)
2758 'message-fill-paragraph)
2759 (make-local-variable 'paragraph-separate)
2760 (make-local-variable 'paragraph-start)
2761 (make-local-variable 'adaptive-fill-regexp)
2762 (unless (boundp 'adaptive-fill-first-line-regexp)
2763 (setq adaptive-fill-first-line-regexp nil))
2764 (make-local-variable 'adaptive-fill-first-line-regexp)
2765 (let ((quote-prefix-regexp
2766 ;; User should change message-cite-prefix-regexp if
2767 ;; message-yank-prefix is set to an abnormal value.
2768 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
2769 (setq paragraph-start
2771 (regexp-quote mail-header-separator) "$\\|"
2772 "[ \t]*$\\|" ; blank lines
2773 "-- $\\|" ; signature delimiter
2774 "---+$\\|" ; delimiters for forwarded messages
2775 page-delimiter "$\\|" ; spoiler warnings
2776 ".*wrote:$\\|" ; attribution lines
2777 quote-prefix-regexp "$\\|" ; empty lines in quoted text
2778 mime-edit-tag-regexp)) ; MIME-Edit tags
2779 (setq paragraph-separate paragraph-start)
2780 (setq adaptive-fill-regexp
2781 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
2782 (setq adaptive-fill-first-line-regexp
2783 (concat quote-prefix-regexp "\\|"
2784 adaptive-fill-first-line-regexp)))
2785 (make-local-variable 'auto-fill-inhibit-regexp)
2786 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2787 (setq auto-fill-inhibit-regexp nil)
2788 (make-local-variable 'normal-auto-fill-function)
2789 (setq normal-auto-fill-function 'message-do-auto-fill)
2790 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2791 ;; In that case, ensure that it uses the right function. The real
2792 ;; solution would be not to use `define-derived-mode', and run
2793 ;; `text-mode-hook' ourself at the end of the mode.
2794 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2795 (when auto-fill-function
2796 (setq auto-fill-function normal-auto-fill-function)))
2801 ;;; Message mode commands
2804 ;;; Movement commands
2806 (defun message-goto-to ()
2807 "Move point to the To header."
2809 (message-position-on-field "To"))
2811 (defun message-goto-from ()
2812 "Move point to the From header."
2814 (message-position-on-field "From"))
2816 (defun message-goto-subject ()
2817 "Move point to the Subject header."
2819 (message-position-on-field "Subject"))
2821 (defun message-goto-cc ()
2822 "Move point to the Cc header."
2824 (message-position-on-field "Cc" "To"))
2826 (defun message-goto-bcc ()
2827 "Move point to the Bcc header."
2829 (message-position-on-field "Bcc" "Cc" "To"))
2831 (defun message-goto-fcc ()
2832 "Move point to the Fcc header."
2834 (message-position-on-field "Fcc" "To" "Newsgroups"))
2836 (defun message-goto-reply-to ()
2837 "Move point to the Reply-To header."
2839 (message-position-on-field "Reply-To" "Subject"))
2841 (defun message-goto-mail-reply-to ()
2842 "Move point to the Mail-Reply-To header."
2844 (message-position-on-field "Mail-Reply-To" "Subject"))
2846 (defun message-goto-mail-copies-to ()
2847 "Move point to the Mail-Copies-To header. If the header is newly created,
2848 a string \"never\" is inserted in default."
2850 (unless (message-position-on-field "Mail-Copies-To" "Subject")
2854 (defun message-goto-newsgroups ()
2855 "Move point to the Newsgroups header."
2857 (message-position-on-field "Newsgroups"))
2859 (defun message-goto-distribution ()
2860 "Move point to the Distribution header."
2862 (message-position-on-field "Distribution"))
2864 (defun message-goto-followup-to ()
2865 "Move point to the Followup-To header."
2867 (message-position-on-field "Followup-To" "Newsgroups"))
2869 (defun message-goto-mail-followup-to ()
2870 "Move point to the Mail-Followup-To header.
2871 If the header is newly created and To field contains only one address,
2872 the address is inserted by default."
2874 (unless (message-position-on-field "Mail-Followup-To" "To")
2875 (let ((start (point))
2878 (message-narrow-to-headers)
2879 (setq addresses (split-string (mail-strip-quoted-names
2880 (or (std11-fetch-field "to") ""))
2882 (when (eq 1 (length addresses))
2884 (insert (car addresses))
2885 (goto-char start))))))
2887 (defun message-goto-keywords ()
2888 "Move point to the Keywords header."
2890 (message-position-on-field "Keywords" "Subject"))
2892 (defun message-goto-summary ()
2893 "Move point to the Summary header."
2895 (message-position-on-field "Summary" "Subject"))
2897 (defun message-goto-body (&optional interactivep)
2898 "Move point to the beginning of the message body."
2899 (interactive (list t))
2900 (when (and interactivep
2901 (looking-at "[ \t]*\n"))
2903 (goto-char (point-min))
2904 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
2905 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
2907 (defun message-goto-eoh ()
2908 "Move point to the end of the headers."
2913 (defun message-goto-signature ()
2914 "Move point to the beginning of the message signature.
2915 If there is no signature in the article, go to the end and
2918 (goto-char (point-min))
2919 (if (re-search-forward message-signature-separator nil t)
2921 (goto-char (point-max))
2924 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc)
2925 "Insert a reasonable MFT header in a post to an unsubscribed list.
2926 When making original posts to a mailing list you are not subscribed to,
2927 you have to type in a MFT header by hand. The contents, usually, are
2928 the addresses of the list and your own address. This function inserts
2929 such a header automatically. It fetches the contents of the To: header
2930 in the current mail buffer, and appends the current `user-mail-address'.
2932 If the optional argument INCLUDE-CC is non-nil, the addresses in the
2933 Cc: header are also put into the MFT."
2938 (message-narrow-to-headers)
2939 (message-remove-header "Mail-Followup-To")
2940 (setq cc (and include-cc (message-fetch-field "Cc")))
2942 (concat (message-fetch-field "To") "," cc)
2943 (message-fetch-field "To"))))
2944 (message-goto-mail-followup-to)
2945 (insert (concat tos ", " user-mail-address))))
2949 (defun message-insert-to (&optional force)
2950 "Insert a To header that points to the author of the article being replied to.
2951 If the original author requested not to be sent mail, don't insert unless the
2952 prefix FORCE is given."
2954 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
2955 (dont (and mct (or (equal (downcase mct) "never")
2956 (equal (downcase mct) "nobody"))))
2957 (to (or (message-fetch-reply-field "mail-reply-to")
2958 (message-fetch-reply-field "reply-to")
2959 (message-fetch-reply-field "from"))))
2963 "Ignoring the user request not to have copies sent via mail"
2964 "Complying with the user request not to have copies sent via mail")))
2965 (when (and force (not to))
2966 (error "No mail address in the article"))
2967 (when (and to (or force (not dont)))
2968 (message-carefully-insert-headers (list (cons 'To to))))))
2970 (defun message-insert-wide-reply ()
2971 "Insert To and Cc headers as if you were doing a wide reply."
2973 (let ((headers (message-with-reply-buffer
2974 (message-get-reply-headers t))))
2975 (message-carefully-insert-headers headers)))
2977 (defcustom message-header-synonyms
2979 "List of lists of header synonyms.
2980 E.g., if this list contains a member list with elements `Cc' and `To',
2981 then `message-carefully-insert-headers' will not insert a `To' header
2982 when the message is already `Cc'ed to the recipient."
2984 :group 'message-headers
2985 :link '(custom-manual "(message)Message Headers")
2986 :type '(repeat sexp))
2988 (defun message-carefully-insert-headers (headers)
2989 "Insert the HEADERS, an alist, into the message buffer.
2990 Does not insert the headers when they are already present there
2991 or in the synonym headers, defined by `message-header-synonyms'."
2992 ;; FIXME: Should compare only the address and not the full name. Comparison
2993 ;; should be done case-folded (and with `string=' rather than
2995 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
2996 (dolist (header headers)
2997 (let* ((header-name (symbol-name (car header)))
2998 (new-header (cdr header))
2999 (synonyms (loop for synonym in message-header-synonyms
3000 when (memq (car header) synonym) return synonym))
3002 (loop for synonym in synonyms
3003 for old-header = (mail-fetch-field (symbol-name synonym))
3004 when (and old-header (string-match new-header old-header))
3007 (message "already have `%s' in `%s'" new-header old-header)
3008 (when (and (message-position-on-field header-name)
3009 (setq old-header (mail-fetch-field header-name))
3010 (not (string-match "\\` *\\'" old-header)))
3012 (insert new-header)))))
3014 (defun message-widen-reply ()
3015 "Widen the reply to include maximum recipients."
3018 (and message-reply-buffer
3019 (buffer-name message-reply-buffer)
3021 (set-buffer message-reply-buffer)
3022 (message-get-reply-headers t)))))
3025 (message-narrow-to-headers)
3026 (dolist (elem follow-to)
3027 (message-remove-header (symbol-name (car elem)))
3028 (goto-char (point-min))
3029 (insert (symbol-name (car elem)) ": "
3030 (cdr elem) "\n"))))))
3032 (defun message-insert-newsgroups ()
3033 "Insert the Newsgroups header from the article being replied to."
3035 (when (and (message-position-on-field "Newsgroups")
3036 (mail-fetch-field "newsgroups")
3037 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
3039 (insert (or (message-fetch-reply-field "newsgroups") "")))
3043 ;;; Various commands
3045 (defun message-delete-not-region (beg end)
3046 "Delete everything in the body of the current message outside of the region."
3051 ;; snarf citation prefix, if appropriate
3052 (unless (eq (point) (progn (beginning-of-line) (point)))
3053 (when (looking-at message-cite-prefix-regexp)
3054 (setq citeprefix (match-string 0))))
3056 (delete-region (point) (if (not (message-goto-signature))
3062 (delete-region beg (progn (message-goto-body)
3066 (insert citeprefix))))
3067 (when (message-goto-signature)
3070 (defun message-kill-to-signature (&optional arg)
3071 "Kill all text up to the signature.
3072 If a numberic argument or prefix arg is given, leave that number
3073 of lines before the signature intact."
3077 (let ((point (point)))
3078 (narrow-to-region point (point-max))
3079 (message-goto-signature)
3081 (if (and arg (numberp arg))
3082 (forward-line (- -1 arg))
3084 (unless (= point (point))
3085 (kill-region point (point))
3088 (defun message-newline-and-reformat (&optional arg not-break)
3089 "Insert four newlines, and then reformat if inside quoted text.
3090 Prefix arg means justify as well."
3091 (interactive (list (if current-prefix-arg 'full)))
3092 (let (quoted point beg end leading-space bolp)
3093 (setq point (point))
3096 (setq bolp (= beg point))
3097 ;; Find first line of the paragraph.
3099 (while (and (not (eobp))
3100 (not (looking-at message-cite-prefix-regexp))
3101 (looking-at paragraph-start))
3104 (when (looking-at message-cite-prefix-regexp)
3105 (setq quoted (match-string 0))
3106 (goto-char (match-end 0))
3107 (looking-at "[ \t]*")
3108 (setq leading-space (match-string 0)))
3112 (< (- point beg) (length quoted)))
3113 ;; break inside the cite prefix.
3119 (while (and (not (eobp))
3120 (not (looking-at paragraph-separate))
3121 (looking-at message-cite-prefix-regexp)
3122 (equal quoted (match-string 0)))
3123 (goto-char (match-end 0))
3124 (looking-at "[ \t]*")
3125 (if (> (length leading-space) (length (match-string 0)))
3126 (setq leading-space (match-string 0)))
3130 (while (and (if (bobp) nil (forward-line -1) t)
3131 (not (looking-at paragraph-start))
3132 (looking-at message-cite-prefix-regexp)
3133 (equal quoted (match-string 0)))
3135 (goto-char (match-end 0))
3136 (looking-at "[ \t]*")
3137 (if (> (length leading-space) (length (match-string 0)))
3138 (setq leading-space (match-string 0)))))
3139 (while (and (not (eobp))
3140 (not (looking-at paragraph-separate))
3141 (not (looking-at message-cite-prefix-regexp)))
3145 (while (and (if (bobp) nil (forward-line -1) t)
3146 (not (looking-at paragraph-start))
3147 (not (looking-at message-cite-prefix-regexp)))
3148 (setq beg (point))))
3151 (narrow-to-region beg end)
3158 (setq point (point))
3159 ;; (newline 2) doesn't mark both newline's as hard, so call
3160 ;; newline twice. -jas
3163 (delete-region (point) (re-search-forward "[ \t]*"))
3164 (when (and quoted (not bolp))
3165 (insert quoted leading-space)))
3168 (let* ((adaptive-fill-regexp
3169 (regexp-quote (concat quoted leading-space)))
3170 (adaptive-fill-first-line-regexp
3171 adaptive-fill-regexp ))
3172 (fill-paragraph arg))
3173 (fill-paragraph arg))
3174 (if point (goto-char point)))))
3176 (defun message-fill-paragraph (&optional arg)
3177 "Like `fill-paragraph'."
3178 (interactive (list (if current-prefix-arg 'full)))
3179 (if (if (boundp 'filladapt-mode) filladapt-mode)
3181 (if (message-point-in-header-p)
3182 (message-fill-field)
3183 (message-newline-and-reformat arg t))
3186 ;; Is it better to use `mail-header-end'?
3187 (defun message-point-in-header-p ()
3188 "Return t if point is in the header."
3191 (goto-char (point-min))
3192 (not (re-search-forward
3193 (concat "^" (regexp-quote mail-header-separator) "\n")
3196 (defun message-do-auto-fill ()
3197 "Like `do-auto-fill', but don't fill in message header."
3198 (unless (message-point-in-header-p)
3201 (defun message-insert-signature (&optional force)
3202 "Insert a signature. See documentation for variable `message-signature'."
3203 (interactive (list 0))
3206 ((and (null message-signature)
3209 (goto-char (point-max))
3210 (not (re-search-backward message-signature-separator nil t))))
3211 ((and (null message-signature)
3214 ((functionp message-signature)
3215 (funcall message-signature))
3216 ((listp message-signature)
3217 (eval message-signature))
3218 (t message-signature)))
3220 (cond ((stringp signature)
3222 ((and (eq t signature)
3223 message-signature-file
3224 (file-exists-p message-signature-file))
3227 (goto-char (point-max))
3228 ;; Insert the signature.
3231 (when message-signature-insert-empty-line
3233 (insert "\n" message-signature-separator-for-insertion)
3236 (if (eq signature t)
3237 (insert-file-contents message-signature-file)
3239 (goto-char (point-max))
3240 (or (bolp) (insert "\n")))))
3242 (defun message-insert-importance-high ()
3243 "Insert header to mark message as important."
3247 (message-narrow-to-headers)
3248 (message-remove-header "Importance"))
3250 (insert "Importance: high\n")))
3252 (defun message-insert-importance-low ()
3253 "Insert header to mark message as unimportant."
3257 (message-narrow-to-headers)
3258 (message-remove-header "Importance"))
3260 (insert "Importance: low\n")))
3262 (defun message-insert-or-toggle-importance ()
3263 "Insert a \"Importance: high\" header, or cycle through the header values.
3264 The three allowed values according to RFC 1327 are `high', `normal'
3268 (let ((valid '("high" "normal" "low"))
3272 (message-narrow-to-headers)
3273 (when (setq cur (message-fetch-field "Importance"))
3274 (message-remove-header "Importance")
3275 (setq new (cond ((string= cur "high")
3277 ((string= cur "low")
3282 (insert (format "Importance: %s\n" new)))))
3284 (defun message-insert-disposition-notification-to ()
3285 "Request a disposition notification (return receipt) to this message.
3286 Note that this should not be used in newsgroups."
3290 (message-narrow-to-headers)
3291 (message-remove-header "Disposition-Notification-To"))
3293 (insert (format "Disposition-Notification-To: %s\n"
3294 (or (message-field-value "Reply-to")
3295 (message-field-value "From")
3296 (message-make-from))))))
3298 (defun message-elide-region (b e)
3299 "Elide the text in the region.
3300 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3304 (insert message-elide-ellipsis))
3306 (defvar message-caesar-translation-table nil)
3308 (defun message-caesar-region (b e &optional n)
3309 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3312 (min (point) (or (mark t) (point)))
3313 (max (point) (or (mark t) (point)))
3314 (when current-prefix-arg
3315 (prefix-numeric-value current-prefix-arg))))
3317 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
3318 (unless (or (zerop n) ; no action needed for a rot of 0
3319 (= b e)) ; no region to rotate
3320 ;; We build the table, if necessary.
3321 (when (or (not message-caesar-translation-table)
3322 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
3323 (setq message-caesar-translation-table
3324 (message-make-caesar-translation-table n)))
3325 (translate-region b e message-caesar-translation-table)))
3327 (defun message-make-caesar-translation-table (n)
3328 "Create a rot table with offset N."
3330 (table (make-string 256 0)))
3331 (while (< (incf i) 256)
3334 (substring table 0 ?A)
3335 (substring table (+ ?A n) (+ ?A n (- 26 n)))
3336 (substring table ?A (+ ?A n))
3337 (substring table (+ ?A 26) ?a)
3338 (substring table (+ ?a n) (+ ?a n (- 26 n)))
3339 (substring table ?a (+ ?a n))
3340 (substring table (+ ?a 26) 255))))
3342 (defun message-caesar-buffer-body (&optional rotnum)
3343 "Caesar rotate all letters in the current buffer by 13 places.
3344 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3345 With prefix arg, specifies the number of places to rotate each letter forward.
3346 Mail and USENET news headers are not rotated."
3347 (interactive (if current-prefix-arg
3348 (list (prefix-numeric-value current-prefix-arg))
3352 (when (message-goto-body)
3353 (narrow-to-region (point) (point-max)))
3354 (message-caesar-region (point-min) (point-max) rotnum))))
3356 (defun message-pipe-buffer-body (program)
3357 "Pipe the message body in the current buffer through PROGRAM."
3360 (when (message-goto-body)
3361 (narrow-to-region (point) (point-max)))
3362 (shell-command-on-region
3363 (point-min) (point-max) program nil t))))
3365 (defun message-rename-buffer (&optional enter-string)
3366 "Rename the *message* buffer to \"*message* RECIPIENT\".
3367 If the function is run with a prefix, it will ask for a new buffer
3368 name, rather than giving an automatic name."
3369 (interactive "Pbuffer name: ")
3372 (goto-char (point-min))
3373 (narrow-to-region (point)
3374 (search-forward mail-header-separator nil 'end))
3376 (if (message-news-p) (message-fetch-field "Newsgroups")
3377 (message-fetch-field "To"))
3380 (if (string-match "," mail-to)
3381 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
3383 (name-default (concat "*message* " mail-trimmed-to))
3384 (name (if enter-string
3385 (read-string "New buffer name: " name-default)
3387 (rename-buffer name t)))))
3389 (defun message-fill-yanked-message (&optional justifyp)
3390 "Fill the paragraphs of a message yanked into this one.
3391 Numeric argument means justify as well."
3394 (goto-char (point-min))
3395 (search-forward (concat "\n" mail-header-separator "\n") nil t)
3396 (let ((fill-prefix message-yank-prefix))
3397 (fill-individual-paragraphs (point) (point-max) justifyp))))
3399 (defun message-indent-citation ()
3400 "Modify text just inserted from a message to be cited.
3401 The inserted text should be the region.
3402 When this function returns, the region is again around the modified text.
3404 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3405 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3406 (let ((start (point)))
3407 ;; Remove unwanted headers.
3408 (when message-ignored-cited-headers
3413 (if (search-forward "\n\n" nil t)
3416 (message-remove-header message-ignored-cited-headers t)
3417 (when (= (point-min) (point-max))
3418 (setq all-removed t))
3419 (goto-char (point-max)))
3423 ;; Delete blank lines at the start of the buffer.
3424 (while (and (point-min)
3427 (message-delete-line))
3428 ;; Delete blank lines at the end of the buffer.
3429 (goto-char (point-max))
3432 (while (and (zerop (forward-line -1))
3434 (message-delete-line))
3435 ;; Do the indentation.
3436 (if (null message-yank-prefix)
3437 (indent-rigidly start (mark t) message-indentation-spaces)
3440 (while (< (point) (mark t))
3441 (if (or (looking-at ">") (looking-at "^$"))
3442 (insert message-yank-cited-prefix)
3443 (insert message-yank-prefix))
3447 (defun message-list-references (refs-list &rest refs-strs)
3448 "Add `Message-ID's which appear in REFS-STRS but not in REFS-LIST,
3450 (let (refs ref id saved-id)
3451 (when (and refs-list
3452 (integerp message-list-references-add-position))
3453 (let ((pos message-list-references-add-position))
3454 (while (and refs-list
3456 (push (pop refs-list) saved-id)
3457 (setq pos (1- pos)))))
3459 (when (setq refs (pop refs-strs))
3460 (setq refs (std11-parse-msg-ids (std11-lexical-analyze refs)))
3462 (when (eq (car (setq ref (pop refs))) 'msg-id)
3463 (setq id (concat "<" (mapconcat 'cdr (cdr ref) "") ">"))
3464 (or (member id refs-list)
3465 (member id saved-id)
3466 (push id refs-list))))))
3468 (push (pop saved-id) refs-list))
3471 (defun message-yank-original (&optional arg)
3472 "Insert the message being replied to, if any.
3473 Puts point before the text and mark after.
3474 Normally indents each nonblank line ARG spaces (default 3). However,
3475 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3477 This function uses `message-cite-function' to do the actual citing.
3479 Just \\[universal-argument] as argument means don't indent, insert no
3480 prefix, and don't delete any headers.
3482 In addition, if `message-yank-add-new-references' is non-nil and this
3483 command is called interactively, new IDs from the yanked article will
3484 be added to the \"References\" field."
3486 (let ((modified (buffer-modified-p)))
3487 (when (let ((buffer (message-eval-parameter message-reply-buffer)))
3489 message-cite-function
3492 (delete-windows-on buffer t)
3493 ; The mark will be set at the end of the article.
3494 (insert-buffer buffer))))
3495 ;; Add new IDs to the References field.
3496 (when (and message-yank-add-new-references
3498 (let ((start (point))
3504 (setq refs (message-list-references
3506 (or (message-make-references)
3508 (message-narrow-to-headers)
3509 (message-fetch-field "References")
3511 (narrow-to-region start end)
3512 (std11-narrow-to-header)
3513 (unless (equal (setq newrefs
3514 (message-list-references
3515 (copy-sequence refs)
3516 (unless (eq message-yank-add-new-references
3518 (or (message-fetch-field "References")
3519 (message-fetch-field "In-Reply-To")))
3520 (message-fetch-field "Message-ID")))
3522 ;; If the References field has been changed, we make it
3523 ;; visible in the header.
3524 (when message-reply-headers
3525 (mail-header-set-message-id message-reply-headers nil)
3526 (mail-header-set-references message-reply-headers nil))
3528 (message-narrow-to-headers)
3529 (if (let ((case-fold-search t))
3530 (re-search-forward "^References:\\([\t ]+.+\n\\)+"
3533 (goto-char (point-max)))
3535 (list (or (assq 'References message-header-format-alist)
3536 '(References . message-fill-references)))
3537 (list (cons 'References (mapconcat 'identity
3538 (nreverse newrefs) " "))))
3539 (backward-delete-char 1))))))
3541 (if (and message-suspend-font-lock-when-citing
3542 (boundp 'font-lock-mode)
3543 (symbol-value 'font-lock-mode))
3548 (funcall message-cite-function))
3550 (funcall message-cite-function)))
3551 (message-exchange-point-and-mark)
3555 (setq message-checksum (message-checksum))))))
3557 (defun message-yank-buffer (buffer)
3558 "Insert BUFFER into the current buffer and quote it."
3559 (interactive "bYank buffer: ")
3560 (let ((message-reply-buffer (get-buffer buffer)))
3561 (save-window-excursion
3562 (message-yank-original))))
3564 (defun message-buffers ()
3565 "Return a list of active message buffers."
3568 (dolist (buffer (buffer-list t))
3570 (when (and (eq major-mode 'message-mode)
3571 (null message-sent-message-via))
3572 (push (buffer-name buffer) buffers))))
3573 (nreverse buffers)))
3575 (defun message-cite-original-without-signature ()
3576 "Cite function in the standard Message manner."
3577 (let ((start (point))
3580 (when message-indent-citation-function
3581 (if (listp message-indent-citation-function)
3582 message-indent-citation-function
3583 (list message-indent-citation-function))))
3584 (message-reply-headers (or message-reply-headers
3585 (make-mail-header))))
3586 (mail-header-set-from message-reply-headers
3590 (if (search-forward "\n\n" nil t)
3593 (or (message-fetch-field "from")
3598 (when (re-search-backward message-signature-separator start t)
3599 ;; Also peel off any blank lines before the signature.
3601 (while (looking-at "^[ \t]*$")
3604 (delete-region (point) end)
3605 (unless (search-backward "\n\n" start t)
3606 ;; Insert a blank line if it is peeled off.
3609 (mapc 'funcall functions)
3610 (when message-citation-line-function
3613 (funcall message-citation-line-function))))
3615 (eval-when-compile (defvar mail-citation-hook)) ;Compiler directive
3616 (defun message-cite-original ()
3617 "Cite function in the standard Message manner."
3618 (if (and (boundp 'mail-citation-hook)
3620 (run-hooks 'mail-citation-hook)
3621 (let ((start (point))
3625 (when message-indent-citation-function
3626 (if (listp message-indent-citation-function)
3627 message-indent-citation-function
3628 (list message-indent-citation-function))))
3629 (message-reply-headers (or message-reply-headers
3630 (make-mail-header))))
3632 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
3635 (mail-header-set-from message-reply-headers
3636 (or (message-fetch-field "from")
3638 (setq x-no-archive (message-fetch-field "x-no-archive")))
3640 (mapc 'funcall functions)
3641 (when message-citation-line-function
3644 (funcall message-citation-line-function))
3645 (when (and x-no-archive
3646 (not message-cite-articles-with-x-no-archive)
3647 (string-match "yes" x-no-archive))
3649 (delete-region (point) (mark t))
3650 (insert "> [Quoted text removed due to X-No-Archive]\n")
3651 (forward-line -1)))))
3653 (defun message-insert-citation-line ()
3654 "Insert a simple citation line."
3655 (when message-reply-headers
3656 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
3658 (defun message-position-on-field (header &rest afters)
3659 (let ((case-fold-search t))
3662 (goto-char (point-min))
3665 (concat "^" (regexp-quote mail-header-separator) "$"))
3666 (match-beginning 0)))
3667 (goto-char (point-min))
3668 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
3670 (re-search-forward "^[^ \t]" nil 'move)
3672 (skip-chars-backward "\n")
3675 (not (re-search-forward
3676 (concat "^" (regexp-quote (car afters)) ":")
3680 (re-search-forward "^[^ \t]" nil 'move)
3681 (beginning-of-line))
3682 (insert header ": \n")
3686 (defun message-remove-signature ()
3687 "Remove the signature from the text between point and mark.
3688 The text will also be indented the normal way."
3690 (let ((start (point))
3692 (if (not (re-search-forward message-signature-separator (mark t) t))
3693 ;; No signature here, so we just indent the cited text.
3694 (message-indent-citation)
3695 ;; Find the last non-empty line.
3697 (while (looking-at "[ \t]*$")
3700 (setq mark (set-marker (make-marker) (point)))
3702 (message-indent-citation)
3703 ;; Enable undoing the deletion.
3705 (delete-region mark (mark t))
3706 (set-marker mark nil)))))
3711 ;;; Sending messages
3714 ;; Avoid byte-compile warning.
3715 (defvar message-encoding-buffer nil)
3716 (defvar message-edit-buffer nil)
3717 (defvar message-mime-mode nil)
3719 (defun message-send-and-exit (&optional arg)
3720 "Send message like `message-send', then, if no errors, exit from mail buffer."
3722 (let ((buf (current-buffer))
3723 (actions message-exit-actions)
3724 (frame (selected-frame))
3725 (org-frame message-original-frame))
3726 (when (and (message-send arg)
3728 (if message-kill-buffer-on-exit
3731 (when (eq buf (current-buffer))
3732 (message-bury buf)))
3733 (message-do-actions actions)
3734 (message-delete-frame frame org-frame)
3737 (defun message-dont-send ()
3738 "Don't send the message you have been editing.
3739 Instead, just auto-save the buffer and then bury it."
3741 (set-buffer-modified-p t)
3743 (let ((actions message-postpone-actions)
3744 (frame (selected-frame))
3745 (org-frame message-original-frame))
3746 (message-bury (current-buffer))
3747 (message-do-actions actions)
3748 (message-delete-frame frame org-frame)))
3750 (defun message-kill-buffer ()
3751 "Kill the current buffer."
3753 (when (or (not (buffer-modified-p))
3754 (eq t message-kill-buffer-query-function)
3755 (funcall message-kill-buffer-query-function
3756 "The buffer modified; kill anyway? "))
3757 (let ((actions message-kill-actions)
3758 (draft-article message-draft-article)
3759 (auto-save-file-name buffer-auto-save-file-name)
3760 (file-name buffer-file-name)
3761 (modified (buffer-modified-p))
3762 (frame (selected-frame))
3763 (org-frame message-original-frame))
3764 (setq buffer-file-name nil)
3765 (kill-buffer (current-buffer))
3766 (when (and message-kill-buffer-and-remove-file
3767 (or (and auto-save-file-name
3768 (file-exists-p auto-save-file-name))
3770 (file-exists-p file-name)))
3771 (yes-or-no-p (format "Remove the backup file%s? "
3772 (if modified " too" ""))))
3774 (delete-file auto-save-file-name))
3775 (let ((message-draft-article draft-article))
3776 (message-disassociate-draft)))
3777 (message-do-actions actions)
3778 (message-delete-frame frame org-frame)))
3781 (defun message-mimic-kill-buffer ()
3782 "Kill the current buffer with query. This is an imitation for
3783 `kill-buffer', but it will delete a message frame."
3785 (let ((bufname (read-buffer (format "Kill buffer: (default %s) "
3787 message-kill-buffer-and-remove-file)
3788 (when (or (not bufname)
3789 (string-equal bufname "")
3790 (string-equal bufname (buffer-name)))
3791 (message-kill-buffer))))
3793 (defun message-delete-frame (frame org-frame)
3794 "Delete frame for editing message."
3795 (when (and (static-if (featurep 'xemacs)
3796 (device-on-window-system-p)
3798 (or (and (eq message-delete-frame-on-exit t)
3799 (select-frame frame)
3800 (or (eq frame org-frame)
3802 (y-or-n-p "Delete this frame?")
3804 (and (eq message-delete-frame-on-exit 'ask)
3805 (select-frame frame)
3807 (y-or-n-p "Delete this frame?")
3809 (delete-frame frame)))
3811 (defun message-bury (buffer)
3812 "Bury this mail BUFFER."
3813 (let ((newbuf (other-buffer buffer)))
3814 (bury-buffer buffer)
3815 (if (and (fboundp 'frame-parameters)
3816 (cdr (assq 'dedicated (frame-parameters)))
3817 (not (null (delq (selected-frame) (visible-frame-list)))))
3818 (delete-frame (selected-frame))
3819 (switch-to-buffer newbuf))))
3821 (defun message-send (&optional arg)
3822 "Send the message in the current buffer.
3823 If `message-interactive' is non-nil, wait for success indication or
3824 error messages, and inform user.
3825 Otherwise any failure is reported in a message back to the user from
3827 The usage of ARG is defined by the instance that called Message.
3828 It should typically alter the sending method in some way or other."
3831 (when (or (buffer-modified-p)
3832 (message-check-element 'unchanged)
3833 (y-or-n-p "No changes in the buffer; really send? "))
3834 ;; Make it possible to undo the coming changes.
3836 (let ((inhibit-read-only t))
3837 (put-text-property (point-min) (point-max) 'read-only nil))
3838 (run-hooks 'message-send-hook)
3839 (message-fix-before-sending)
3840 (message message-sending-message)
3841 (let ((message-encoding-buffer
3842 (message-generate-new-buffer-clone-locals " message encoding"))
3843 (message-edit-buffer (current-buffer))
3844 (message-mime-mode mime-edit-mode-flag)
3845 (alist message-send-method-alist)
3847 elem sent dont-barf-on-no-method
3848 (message-options message-options))
3851 (message-options-set-recipient)
3853 (set-buffer message-encoding-buffer)
3855 ;; ;; Avoid copying text props (except hard newlines).
3856 ;; T-gnus change: copy all text props from the editing buffer
3857 ;; into the encoding buffer.
3858 (insert-buffer-substring message-edit-buffer)
3859 (funcall message-encode-function)
3861 (setq elem (pop alist)))
3862 (when (funcall (cadr elem))
3864 (or (not (memq (car elem)
3865 message-sent-message-via))
3866 (message-fetch-field "supersedes")
3867 (if (or (message-gnksa-enable-p 'multiple-copies)
3868 (not (eq (car elem) 'news)))
3871 "Already sent message via %s; resend? "
3873 (error "Denied posting -- multiple copies")))
3874 (setq success (funcall (caddr elem) arg)))
3880 (let ((fcc (message-fetch-field "Fcc"))
3881 (gcc (message-fetch-field "Gcc")))
3884 (eq message-allow-no-recipients 'always)
3885 (and (not (eq message-allow-no-recipients 'never))
3886 (setq dont-barf-on-no-method
3888 (format "No receiver, perform %s anyway? "
3889 (cond ((and fcc gcc) "Fcc and Gcc")
3892 (error "No methods specified to send by"))
3893 (when (or dont-barf-on-no-method
3897 (run-hooks 'message-sent-hook))
3898 (message "Sending...done")
3899 ;; Mark the buffer as unmodified and delete auto-save.
3900 (set-buffer-modified-p nil)
3901 (delete-auto-save-file-if-necessary t)
3902 (message-disassociate-draft)
3903 ;; Delete other mail buffers and stuff.
3904 (message-do-send-housekeeping)
3905 (message-do-actions message-send-actions)
3908 (kill-buffer message-encoding-buffer)))))
3910 (defun message-send-via-mail (arg)
3911 "Send the current message via mail."
3912 (message-send-mail arg))
3914 (defun message-send-via-news (arg)
3915 "Send the current message via news."
3916 (message-send-news arg))
3918 (defmacro message-check (type &rest forms)
3919 "Eval FORMS if TYPE is to be checked."
3920 `(or (message-check-element ,type)
3924 (put 'message-check 'lisp-indent-function 1)
3925 (put 'message-check 'edebug-form-spec '(form body))
3927 ;; Advise the function `invisible-region'.
3928 (let (current-load-list)
3930 `(defadvice invisible-region (around add-mime-edit-invisible (start end)
3932 "Advised by T-gnus Message.
3933 Add the text property `mime-edit-invisible' to an invisible text when
3934 the buffer's major mode is `message-mode'. The added property will be
3935 used to distinguish whether the invisible text is a MIME part or not."
3936 ,(if (featurep 'xemacs)
3937 '(if (eq ?\n (char-after start))
3938 (setq start (1+ start)))
3939 '(if (eq ?\n (char-after (1- end)))
3940 (setq end (1- end))))
3941 (setq ad-return-value
3942 (if (eq 'message-mode major-mode)
3943 (add-text-properties start end
3944 '(invisible t mime-edit-invisible t))
3945 (put-text-property start end 'invisible t))))))
3947 (defun message-text-with-property (prop &optional start end reverse)
3948 "Return a list of start and end positions where the text has PROP.
3949 START and END bound the search, they default to `point-min' and
3950 `point-max' respectively. If REVERSE is non-nil, find text which does
3953 (setq start (point-min)))
3955 (setq end (point-max)))
3959 (setq start (text-property-any start end prop nil)))
3960 (setq next (next-single-property-change start prop nil end))
3961 (push (cons start (or next end)) regions)
3964 (or (get-text-property start prop)
3965 (and (setq start (next-single-property-change
3966 start prop nil end))
3967 (get-text-property start prop))))
3968 (setq next (text-property-any start end prop nil))
3969 (push (cons start (or next end)) regions)
3971 (nreverse regions)))
3973 (defun message-fix-before-sending ()
3974 "Do various things to make the message nice before sending it."
3975 ;; Make sure there's a newline at the end of the message.
3977 (goto-char (point-max))
3980 ;; Make the hidden headers visible.
3981 (dolist (from-to (message-text-with-property 'message-hidden))
3982 (add-text-properties (car from-to) (cdr from-to)
3983 '(invisible nil intangible nil)))
3984 ;; Make invisible text visible except for mime parts which may be
3985 ;; inserted by the MIME-Edit.
3986 ;; It doesn't seem as if this is useful, since the invisible property
3987 ;; is clobbered by an after-change hook anyhow.
3988 (message-check 'invisible-text
3989 ;; FIXME T-gnus: It should also detect invisible overlays.
3992 mime-from mime-to hidden-start)
3993 (while (setq from (text-property-any to (point-max) 'invisible t))
3994 (setq to (or (text-property-not-all from (point-max) 'invisible t)
3997 (while (setq mime-from (text-property-any mime-to to
3998 'mime-edit-invisible t))
3999 (when (> mime-from mime-to)
4000 (setq hidden-start (or hidden-start mime-to))
4001 (add-text-properties mime-to mime-from
4002 '(invisible nil face highlight
4003 font-lock-face highlight)))
4004 (setq mime-to (or (text-property-not-all mime-from to
4005 'mime-edit-invisible t)
4007 (when (< mime-to to)
4008 (setq hidden-start (or hidden-start mime-to))
4009 (add-text-properties mime-to to
4010 '(invisible nil face highlight
4011 font-lock-face highlight))))
4013 (goto-char hidden-start)
4014 (set-window-start (selected-window) (point-at-bol))
4015 (unless (yes-or-no-p
4016 "Invisible text found and made visible; continue sending? ")
4017 (error "Invisible text found and made visible")))))
4018 ;; The following check is needless to T-gnus since T-gnus determines
4019 ;; a MIME charset forcibly (even if it cannot be determined properly,
4020 ;; the value of the `default-mime-charset-for-write' variable is used).
4021 ;; (message-check 'illegible-text
4022 ;; (let (found choice)
4023 ;; (message-goto-body)
4024 ;; (skip-chars-forward mm-7bit-chars)
4025 ;; (while (not (eobp))
4026 ;; (when (let ((char (char-after)))
4027 ;; (or (< (mm-char-int char) 128)
4028 ;; (and (mm-multibyte-p)
4029 ;; (memq (char-charset char)
4030 ;; '(eight-bit-control eight-bit-graphic
4032 ;; (not (get-text-property
4033 ;; (point) 'untranslated-utf-8)))))
4034 ;; (message-overlay-put (message-make-overlay (point) (1+ (point)))
4035 ;; 'face 'highlight)
4038 ;; (skip-chars-forward mm-7bit-chars))
4041 ;; (gnus-multiple-choice
4042 ;; "Non-printable characters found. Continue sending?"
4043 ;; '((?d "Remove non-printable characters and send")
4044 ;; (?r "Replace non-printable characters with dots and send")
4045 ;; (?i "Ignore non-printable characters and send")
4046 ;; (?e "Continue editing"))))
4047 ;; (if (eq choice ?e)
4048 ;; (error "Non-printable characters"))
4049 ;; (message-goto-body)
4050 ;; (skip-chars-forward mm-7bit-chars)
4051 ;; (while (not (eobp))
4052 ;; (when (let ((char (char-after)))
4053 ;; (or (< (mm-char-int char) 128)
4054 ;; (and (mm-multibyte-p)
4055 ;; ;; Fixme: Wrong for Emacs 22 and for things
4056 ;; ;; like undecable utf-8. Should at least
4057 ;; ;; use find-coding-systems-region.
4058 ;; (memq (char-charset char)
4059 ;; '(eight-bit-control eight-bit-graphic
4061 ;; (not (get-text-property
4062 ;; (point) 'untranslated-utf-8)))))
4063 ;; (if (eq choice ?i)
4064 ;; (message-kill-all-overlays)
4066 ;; (when (eq choice ?r)
4069 ;; (skip-chars-forward mm-7bit-chars)))))
4072 (defun message-add-action (action &rest types)
4073 "Add ACTION to be performed when doing an exit of type TYPES."
4075 (add-to-list (intern (format "message-%s-actions" (pop types)))
4078 (defun message-delete-action (action &rest types)
4079 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
4082 (set (setq var (intern (format "message-%s-actions" (pop types))))
4083 (delq action (symbol-value var))))))
4085 (defun message-do-actions (actions)
4086 "Perform all actions in ACTIONS."
4087 ;; Now perform actions on successful sending.
4088 (dolist (action actions)
4091 ;; A simple function.
4094 ;; Something to be evaled.
4098 (defsubst message-maybe-split-and-send-mail ()
4099 "Split a message if necessary, and send it via mail.
4100 Returns nil if sending succeeded, returns any string if sending failed.
4101 This sub function is for exclusive use of `message-send-mail'."
4102 (let ((mime-edit-split-ignored-field-regexp
4103 mime-edit-split-ignored-field-regexp)
4104 (case-fold-search t)
4106 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
4107 (setq mime-edit-split-ignored-field-regexp
4108 (concat (substring mime-edit-split-ignored-field-regexp
4109 0 (match-beginning 0))
4110 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
4111 "_so_don't_rape_it!"
4112 (substring mime-edit-split-ignored-field-regexp
4116 (catch 'message-sending-mail-failure
4117 (mime-edit-maybe-split-and-send
4122 (std11-narrow-to-header mail-header-separator)
4123 (goto-char (point-min))
4124 (when (re-search-forward "^Message-ID:" nil t)
4125 (delete-region (match-end 0) (std11-field-end))
4126 (insert " " (message-make-message-id))))
4128 (funcall (or message-send-mail-real-function
4129 message-send-mail-function))
4131 (throw 'message-sending-mail-failure err))))))
4135 (funcall (or message-send-mail-real-function
4136 message-send-mail-function))
4140 (if (eq 'error (car failure))
4142 (prin1-to-string failure)))))
4144 (defun message-send-mail-partially ()
4145 "Send mail as message/partial."
4146 ;; replace the header delimiter with a blank line
4147 (goto-char (point-min))
4149 (concat "^" (regexp-quote mail-header-separator) "\n"))
4150 (replace-match "\n")
4151 (run-hooks 'message-send-mail-hook)
4152 (let ((p (goto-char (point-min)))
4153 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
4154 (curbuf (current-buffer))
4155 (id (message-make-message-id)) (n 1)
4156 plist total header required-mail-headers)
4158 (if (< (point-max) (+ p message-send-mail-partially-limit))
4159 (goto-char (point-max))
4160 (goto-char (+ p message-send-mail-partially-limit))
4162 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
4165 (setq total (length plist))
4166 (push (point-max) plist)
4167 (setq plist (nreverse plist))
4170 (setq p (pop plist))
4173 (copy-to-buffer tembuf p (car plist))
4175 (goto-char (point-min))
4178 (goto-char (point-min))
4179 (narrow-to-region (point) (point))
4182 (setq header (buffer-substring (point-min) (point)))
4183 (goto-char (point-min))
4184 (narrow-to-region (point) (point))
4186 (message-remove-header "Mime-Version")
4187 (message-remove-header "Content-Type")
4188 (message-remove-header "Content-Transfer-Encoding")
4189 (message-remove-header "Message-ID")
4190 (message-remove-header "Lines")
4191 (goto-char (point-max))
4192 (insert "Mime-Version: 1.0\n")
4193 (setq header (buffer-string)))
4194 (goto-char (point-max))
4195 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
4198 (let ((mail-header-separator ""))
4199 (when (memq 'Message-ID message-required-mail-headers)
4200 (insert "Message-ID: " (message-make-message-id) "\n"))
4201 (when (memq 'Lines message-required-mail-headers)
4202 (insert "Lines: " (message-make-lines) "\n"))
4203 (message-goto-subject)
4205 (insert (format " (%d/%d)" n total))
4207 (mm-with-unibyte-current-buffer
4208 (funcall (or message-send-mail-real-function
4209 message-send-mail-function))))
4211 (setq p (pop plist))
4213 (kill-buffer tembuf))))
4215 (defun message-send-mail (&optional arg)
4216 (require 'mail-utils)
4217 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
4218 (case-fold-search nil)
4219 (news (message-news-p))
4220 (message-this-is-mail t)
4221 (headers message-required-mail-headers)
4223 (when message-generate-hashcash
4225 (message-narrow-to-headers)
4226 (message-remove-header "X-Hashcash"))
4227 (message "Generating hashcash...")
4229 (message "Generating hashcash...done"))
4231 (message-narrow-to-headers)
4232 ;; Generate the Mail-Followup-To header if the header is not there...
4233 (if (and (message-subscribed-p)
4234 (not (mail-fetch-field "mail-followup-to")))
4237 (cons "Mail-Followup-To" (message-make-mail-followup-to))
4238 message-required-mail-headers))
4239 ;; otherwise, delete the MFT header if the field is empty
4240 (when (equal "" (mail-fetch-field "mail-followup-to"))
4241 (message-remove-header "^Mail-Followup-To:")))
4242 ;; Insert some headers.
4243 (let ((message-deletable-headers
4244 (if news nil message-deletable-headers)))
4245 (message-generate-headers headers))
4246 ;; Let the user do all of the above.
4247 (run-hooks 'message-header-hook))
4248 (if (not (message-check-mail-syntax))
4256 ;; ;; Avoid copying text props (except hard newlines).
4257 ;; T-gnus change: copy all text props from the editing buffer
4258 ;; into the encoding buffer.
4259 (insert-buffer-substring message-encoding-buffer)
4260 ;; Remove some headers.
4262 (message-narrow-to-headers)
4263 ;; We Semi-gnus people have no use for it.
4264 ;; ;; We (re)generate the Lines header.
4265 ;; (when (memq 'Lines message-required-mail-headers)
4266 ;; (message-generate-headers '(Lines)))
4267 (message-remove-header message-ignored-mail-headers t))
4268 (goto-char (point-max))
4269 ;; require one newline at the end.
4270 (or (= (preceding-char) ?\n)
4272 (message-cleanup-headers)
4273 ;; FIXME: we're inserting the courtesy copy after encoding.
4274 ;; This is wrong if the courtesy copy string contains
4275 ;; non-ASCII characters. -- jh
4278 (message-narrow-to-headers)
4280 (or (message-fetch-field "cc")
4281 (message-fetch-field "bcc")
4282 (message-fetch-field "to"))
4283 (let ((content-type (mime-read-Content-Type)))
4288 (eq 'text (cdr (assq 'type content-type)))
4289 (eq 'plain (cdr (assq 'subtype content-type)))))
4292 (mime-read-Content-Transfer-Encoding)))))))
4293 (message-insert-courtesy-copy))
4294 (setq failure (message-maybe-split-and-send-mail)))
4295 (kill-buffer tembuf))
4296 (set-buffer message-edit-buffer)
4299 (message "Couldn't send message via mail: %s" failure)
4301 (push 'mail message-sent-message-via)))))
4303 (defun message-send-mail-with-sendmail ()
4304 "Send off the prepared buffer with sendmail."
4305 (let ((errbuf (if message-interactive
4306 (message-generate-new-buffer-clone-locals
4309 resend-to-addresses delimline)
4312 (let ((case-fold-search t))
4314 (message-narrow-to-headers)
4315 (setq resend-to-addresses (message-fetch-field "resent-to")))
4316 ;; Change header-delimiter to be what sendmail expects.
4317 (goto-char (point-min))
4319 (concat "^" (regexp-quote mail-header-separator) "\n"))
4320 (replace-match "\n")
4322 (setq delimline (point-marker))
4323 (run-hooks 'message-send-mail-hook)
4324 ;; Insert an extra newline if we need it to work around
4325 ;; Sun's bug that swallows newlines.
4326 (goto-char (1+ delimline))
4327 (when (eval message-mailer-swallows-blank-line)
4329 (when message-interactive
4330 (with-current-buffer errbuf
4332 (let* ((default-directory "/")
4333 (cpr (as-binary-process
4335 'call-process-region
4337 (list (point-min) (point-max)
4338 (if (boundp 'sendmail-program)
4340 "/usr/lib/sendmail")
4341 nil errbuf nil "-oi")
4342 ;; Always specify who from,
4343 ;; since some systems have broken sendmails.
4344 ;; But some systems are more broken with -f, so
4345 ;; we'll let users override this.
4346 (if (null message-sendmail-f-is-evil)
4347 (list "-f" (message-sendmail-envelope-from)))
4348 ;; These mean "report errors by mail"
4349 ;; and "deliver in background".
4350 (if (null message-interactive) '("-oem" "-odb"))
4351 ;; Get the addresses from the message
4352 ;; unless this is a resend.
4353 ;; We must not do that for a resend
4354 ;; because we would find the original addresses.
4355 ;; For a resend, include the specific addresses.
4356 (if resend-to-addresses
4357 (list resend-to-addresses)
4359 (unless (or (null cpr) (and (numberp cpr) (zerop cpr)))
4360 (error "Sending...failed with exit value %d" cpr)))
4361 (when message-interactive
4364 (goto-char (point-min))
4365 (while (re-search-forward "\n+ *" nil t)
4366 (replace-match "; "))
4367 (if (not (zerop (buffer-size)))
4368 (error "Sending...failed to %s"
4369 (buffer-string))))))
4370 (when (bufferp errbuf)
4371 (kill-buffer errbuf)))))
4373 (defun message-send-mail-with-qmail ()
4374 "Pass the prepared message buffer to qmail-inject.
4375 Refer to the documentation for the variable `message-send-mail-function'
4376 to find out how to use this."
4377 ;; replace the header delimiter with a blank line
4378 (goto-char (point-min))
4380 (concat "^" (regexp-quote mail-header-separator) "\n"))
4381 (replace-match "\n")
4383 (run-hooks 'message-send-mail-hook)
4388 'call-process-region (point-min) (point-max)
4389 message-qmail-inject-program nil nil nil
4390 ;; qmail-inject's default behaviour is to look for addresses on the
4391 ;; command line; if there're none, it scans the headers.
4392 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4394 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4395 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4396 ;; message from stdin.
4398 ;; qmail also has the advantage of not having been raped by
4399 ;; various vendors, so we don't have to allow for that, either --
4400 ;; compare this with message-send-mail-with-sendmail and weep
4401 ;; for sendmail's lost innocence.
4403 ;; all this is way cool coz it lets us keep the arguments entirely
4404 ;; free for -inject-arguments -- a big win for the user and for us
4405 ;; since we don't have to play that double-guessing game and the user
4406 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4407 (if (functionp message-qmail-inject-args)
4408 (funcall message-qmail-inject-args)
4409 message-qmail-inject-args)))
4410 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4411 ;; we have to look at the retval instead
4413 (100 (error "qmail-inject reported permanent failure"))
4414 (111 (error "qmail-inject reported transient failure"))
4415 ;; should never happen
4416 (t (error "qmail-inject reported unknown failure"))))
4418 (defun message-send-mail-with-mh ()
4419 "Send the prepared message buffer with mh."
4420 (let ((mh-previous-window-config nil)
4421 (name (mh-new-draft-name)))
4422 (setq buffer-file-name name)
4423 ;; MH wants to generate these headers itself.
4424 (when message-mh-deletable-headers
4425 (let ((headers message-mh-deletable-headers))
4427 (goto-char (point-min))
4428 (and (re-search-forward
4429 (concat "^" (symbol-name (car headers)) ": *") nil t)
4430 (message-delete-line))
4432 (run-hooks 'message-send-mail-hook)
4433 ;; Pass it on to mh.
4436 (defun message-send-mail-with-smtp ()
4437 "Send off the prepared buffer with SMTP."
4438 (require 'smtp) ; XXX
4439 (let ((case-fold-search t)
4442 (message-narrow-to-headers)
4444 ;; XXX: Should be replaced by better one.
4445 (smtp-deduce-address-list (current-buffer)
4446 (point-min) (point-max)))
4447 ;; Remove BCC lines.
4448 (message-remove-header "bcc"))
4449 ;; replace the header delimiter with a blank line.
4450 (goto-char (point-min))
4452 (concat "^" (regexp-quote mail-header-separator) "\n"))
4453 (replace-match "\n")
4455 (run-hooks 'message-send-mail-hook)
4457 (smtp-send-buffer user-mail-address recipients (current-buffer))
4458 (error "Sending failed; no recipients"))))
4460 (defsubst message-maybe-split-and-send-news (method)
4461 "Split a message if necessary, and send it via news.
4462 Returns nil if sending succeeded, returns t if sending failed.
4463 This sub function is for exclusive use of `message-send-news'."
4464 (let ((mime-edit-split-ignored-field-regexp
4465 mime-edit-split-ignored-field-regexp)
4466 (case-fold-search t))
4467 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
4468 (setq mime-edit-split-ignored-field-regexp
4469 (concat (substring mime-edit-split-ignored-field-regexp
4470 0 (match-beginning 0))
4471 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
4472 "_so_don't_rape_it!"
4473 (substring mime-edit-split-ignored-field-regexp
4476 (catch 'message-sending-news-failure
4477 (mime-edit-maybe-split-and-send
4482 (std11-narrow-to-header mail-header-separator)
4483 (goto-char (point-min))
4484 (when (re-search-forward "^Message-ID:" nil t)
4485 (delete-region (match-end 0) (std11-field-end))
4486 (insert " " (message-make-message-id))))
4487 (unless (funcall message-send-news-function method)
4488 (throw 'message-sending-news-failure t)))))
4490 (not (funcall message-send-news-function method)))))
4492 (defun message-smtpmail-send-it ()
4493 "Send the prepared message buffer with `smtpmail-send-it'.
4494 This only differs from `smtpmail-send-it' that this command evaluates
4495 `message-send-mail-hook' just before sending a message. It is useful
4496 if your ISP requires the POP-before-SMTP authentication. See the Gnus
4497 manual for details."
4498 (run-hooks 'message-send-mail-hook)
4501 (defun message-canlock-generate ()
4502 "Return a string that is non-trivial to guess.
4503 Do not use this for anything important, it is cryptographically weak."
4505 (let (sha1-maximum-internal-length)
4506 (sha1 (concat (message-unique-id)
4507 (format "%x%x%x" (random) (random t) (random))
4508 (prin1-to-string (recent-keys))
4509 (prin1-to-string (garbage-collect))))))
4511 (defun message-canlock-password ()
4512 "The password used by message for cancel locks.
4513 This is the value of `canlock-password', if that option is non-nil.
4514 Otherwise, generate and save a value for `canlock-password' first."
4515 (unless canlock-password
4516 (customize-save-variable 'canlock-password (message-canlock-generate))
4517 (setq canlock-password-for-verify canlock-password))
4520 (defun message-insert-canlock ()
4521 (when message-insert-canlock
4522 (message-canlock-password)
4523 (canlock-insert-header)))
4525 (defun message-send-news (&optional arg)
4526 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4527 (case-fold-search nil)
4528 (method (if (functionp message-post-method)
4529 (funcall message-post-method arg)
4530 message-post-method))
4531 (newsgroups-field (save-restriction
4532 (message-narrow-to-headers-or-head)
4533 (message-fetch-field "Newsgroups")))
4534 (followup-field (save-restriction
4535 (message-narrow-to-headers-or-head)
4536 (message-fetch-field "Followup-To")))
4537 ;; BUG: We really need to get the charset for each name in the
4538 ;; Newsgroups and Followup-To lines to allow crossposting
4539 ;; between group namess with incompatible character sets.
4540 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4541 (group-field-charset
4542 (gnus-group-name-charset method newsgroups-field))
4543 (followup-field-charset
4544 (gnus-group-name-charset method (or followup-field "")))
4545 (mime-field-encoding-method-alist
4546 (append (when group-field-charset
4547 (list (cons "Newsgroups" group-field-charset)))
4548 (when followup-field-charset
4549 (list (cons "Followup-To" followup-field-charset)))
4550 mime-field-encoding-method-alist))
4551 (message-syntax-checks
4553 (listp message-syntax-checks))
4554 (cons '(existing-newsgroups . disabled)
4555 message-syntax-checks)
4556 message-syntax-checks))
4557 (message-this-is-news t)
4560 (message-narrow-to-headers)
4561 ;; Insert some headers.
4562 (message-generate-headers message-required-news-headers)
4563 (message-insert-canlock)
4564 ;; Let the user do all of the above.
4565 (run-hooks 'message-header-hook))
4566 ;; Note: This check will be disabled by the ".*" default value for
4567 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4568 (when (and group-field-charset
4569 (listp message-syntax-checks))
4570 (setq message-syntax-checks
4571 (cons '(valid-newsgroups . disabled)
4572 message-syntax-checks)))
4573 (message-cleanup-headers)
4574 (if (not (let ((message-post-method method))
4575 (message-check-news-syntax)))
4580 (buffer-disable-undo)
4582 (insert-buffer-substring message-encoding-buffer)
4583 ;; Remove some headers.
4585 (message-narrow-to-headers)
4586 ;; We Semi-gnus people have no use for it.
4587 ;; ;; We (re)generate the Lines header.
4588 ;; (when (memq 'Lines message-required-mail-headers)
4589 ;; (message-generate-headers '(Lines)))
4590 ;; Remove some headers.
4591 (message-remove-header message-ignored-news-headers t))
4592 (goto-char (point-max))
4593 ;; require one newline at the end.
4594 (or (= (preceding-char) ?\n)
4596 (setq result (message-maybe-split-and-send-news method)))
4597 (kill-buffer tembuf))
4598 (set-buffer message-edit-buffer)
4601 (message "Couldn't send message via news: %s"
4602 (nnheader-get-report (car method)))
4604 (push 'news message-sent-message-via)))))
4606 ;; 1997-09-29 by MORIOKA Tomohiko
4607 (defun message-send-news-with-gnus (method)
4608 (let ((case-fold-search t))
4609 ;; Remove the delimiter.
4610 (goto-char (point-min))
4612 (concat "^" (regexp-quote mail-header-separator) "\n"))
4613 (replace-match "\n")
4615 (run-hooks 'message-send-news-hook)
4616 (gnus-open-server method)
4617 (message "Sending news via %s..." (gnus-server-string method))
4618 (gnus-request-post method)
4622 ;;; Header generation & syntax checking.
4625 (defun message-check-element (type)
4626 "Return non-nil if this TYPE is not to be checked."
4627 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
4629 (let ((able (assq type message-syntax-checks)))
4631 (eq (cdr able) 'disabled)))))
4633 (defun message-check-news-syntax ()
4634 "Check the syntax of the message."
4639 ;; We narrow to the headers and check them first.
4642 (message-narrow-to-headers)
4643 (message-check-news-header-syntax)))
4646 (set-buffer message-edit-buffer)
4647 (message-check-news-body-syntax))))))
4649 (defun message-check-news-header-syntax ()
4651 ;; Check Newsgroups header.
4652 (message-check 'newsgroups
4653 (let ((group (message-fetch-field "newsgroups")))
4656 (not (string-match "\\`[ \t]*\\'" group)))
4659 "The newsgroups field is empty or missing. Posting is denied.")))))
4660 ;; Check the Subject header.
4661 (message-check 'subject
4662 (let* ((case-fold-search t)
4663 (subject (message-fetch-field "subject")))
4666 (not (string-match "\\`[ \t]*\\'" subject)))
4669 "The subject field is empty or missing. Posting is denied.")))))
4670 ;; Check for commands in Subject.
4671 (message-check 'subject-cmsg
4672 (if (string-match "^cmsg " (message-fetch-field "subject"))
4674 "The control code \"cmsg\" is in the subject. Really post? ")
4676 ;; Check long header lines.
4677 (message-check 'long-header-lines
4678 (let ((start (point))
4682 (while (and (not found)
4683 (re-search-forward "^\\([^ \t:]+\\): " nil t))
4684 (if (> (- (point) (match-beginning 0)) 998)
4686 length (- (point) (match-beginning 0)))
4687 (setq header (match-string-no-properties 1)))
4688 (setq start (match-beginning 0))
4691 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
4694 ;; Check for multiple identical headers.
4695 (message-check 'multiple-headers
4697 (while (and (not found)
4698 (re-search-forward "^[^ \t:]+: " nil t))
4700 (or (re-search-forward
4705 (match-beginning 0) (- (match-end 0) 2))))
4710 (y-or-n-p (format "Multiple %s headers. Really post? " found))
4712 ;; Check for Version and Sendsys.
4713 (message-check 'sendsys
4714 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
4716 (format "The article contains a %s command. Really post? "
4717 (buffer-substring (match-beginning 0)
4718 (1- (match-end 0)))))
4720 ;; See whether we can shorten Followup-To.
4721 (message-check 'shorten-followup-to
4722 (let ((newsgroups (message-fetch-field "newsgroups"))
4723 (followup-to (message-fetch-field "followup-to"))
4725 (when (and newsgroups
4726 (string-match "," newsgroups)
4731 (setq to (completing-read
4732 "Followups to (default: no Followup-To header) "
4735 (message-tokenize-header
4737 (goto-char (point-min))
4738 (insert "Followup-To: " to "\n"))
4740 ;; Check "Shoot me".
4741 (message-check 'shoot
4742 (if (re-search-forward
4743 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t)
4744 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
4746 ;; Check for Approved.
4747 (message-check 'approved
4748 (if (re-search-forward "^Approved:" nil t)
4749 (y-or-n-p "The article contains an Approved header. Really post? ")
4751 ;; Check the Message-ID header.
4752 (message-check 'message-id
4753 (let* ((case-fold-search t)
4754 (message-id (message-fetch-field "message-id" t)))
4755 (or (not message-id)
4756 ;; Is there an @ in the ID?
4757 (and (string-match "@" message-id)
4758 ;; Is there a dot in the ID?
4759 (string-match "@[^.]*\\." message-id)
4760 ;; Does the ID end with a dot?
4761 (not (string-match "\\.>" message-id)))
4763 (format "The Message-ID looks strange: \"%s\". Really post? "
4765 ;; Check the Newsgroups & Followup-To headers.
4766 (message-check 'existing-newsgroups
4767 (let* ((case-fold-search t)
4768 (newsgroups (message-fetch-field "newsgroups"))
4769 (followup-to (message-fetch-field "followup-to"))
4770 (groups (message-tokenize-header
4772 (concat newsgroups "," followup-to)
4774 (post-method (if (functionp message-post-method)
4775 (funcall message-post-method)
4776 message-post-method))
4777 ;; KLUDGE to handle nnvirtual groups. Doing this right
4778 ;; would probably involve a new nnoo function.
4779 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
4780 (method (if (and (consp post-method)
4781 (eq (car post-method) 'nnvirtual)
4782 gnus-message-group-art)
4783 (let ((group (car (nnvirtual-find-group-art
4784 (car gnus-message-group-art)
4785 (cdr gnus-message-group-art)))))
4786 (gnus-find-method-for-group group))
4790 (gnus-group-name-decode
4791 (gnus-group-real-name n)
4792 (gnus-group-name-charset method n)))
4793 (gnus-groups-from-server method)))
4796 (when (and (not (equal (car groups) "poster"))
4797 (not (member (car groups) known-groups))
4798 (not (member (car groups) errors)))
4799 (push (car groups) errors))
4802 ;; Gnus is not running.
4803 ((or (not (and (boundp 'gnus-active-hashtb)
4804 gnus-active-hashtb))
4805 (not (boundp 'gnus-read-active-file)))
4807 ;; We don't have all the group names.
4808 ((and (or (not gnus-read-active-file)
4809 (eq gnus-read-active-file 'some))
4813 "Really use %s possibly unknown group%s: %s? "
4814 (if (= (length errors) 1) "this" "these")
4815 (if (= (length errors) 1) "" "s")
4816 (mapconcat 'identity errors ", "))))
4817 ;; There were no errors.
4820 ;; There are unknown groups.
4824 "Really post to %s unknown group%s: %s? "
4825 (if (= (length errors) 1) "this" "these")
4826 (if (= (length errors) 1) "" "s")
4827 (mapconcat 'identity errors ", ")))))))
4828 ;; Check continuation headers.
4829 (message-check 'continuation-headers
4830 (goto-char (point-min))
4831 (let ((do-posting t))
4832 (while (re-search-forward "^[^ \t\n][^:\n]*$" nil t)
4833 (if (y-or-n-p "Fix continuation lines? ")
4835 (goto-char (match-beginning 0))
4837 (unless (y-or-n-p "Send anyway? ")
4838 (setq do-posting nil))))
4840 ;; Check the Newsgroups & Followup-To headers for syntax errors.
4841 (message-check 'valid-newsgroups
4842 (let ((case-fold-search t)
4843 (headers '("Newsgroups" "Followup-To"))
4845 (while (and headers (not error))
4846 (when (setq header (mail-fetch-field (car headers)))
4850 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
4855 (not (string-match "\\.\\'\\|\\.\\." g)))
4856 (message-tokenize-header header ","))))
4863 (format "The %s header looks odd: \"%s\". Really post? "
4864 (car headers) header)))))
4865 (message-check 'repeated-newsgroups
4866 (let ((case-fold-search t)
4867 (headers '("Newsgroups" "Followup-To"))
4868 header error groups group)
4871 (when (setq header (mail-fetch-field (pop headers)))
4872 (setq groups (message-tokenize-header header ","))
4873 (while (setq group (pop groups))
4874 (when (member group groups)
4880 (format "Group %s is repeated in headers. Really post? " error)))))
4881 ;; Check the From header.
4882 (message-check 'from
4883 (let* ((case-fold-search t)
4884 (from (message-fetch-field "from"))
4888 (message "There is no From line. Posting is denied.")
4890 ((or (not (string-match
4892 (setq ad (nth 1 (std11-extract-address-components
4893 from))))) ;larsi@ifi
4894 (string-match "\\.\\." ad) ;larsi@ifi..uio
4895 (string-match "@\\." ad) ;larsi@.ifi.uio
4896 (string-match "\\.$" ad) ;larsi@ifi.uio.
4897 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4898 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
4900 "Denied posting -- the From looks strange: \"%s\"." from)
4902 ((let ((addresses (rfc822-addresses from)))
4903 (while (and addresses
4904 (not (eq (string-to-char (car addresses)) ?\()))
4905 (setq addresses (cdr addresses)))
4908 "Denied posting -- bad From address: \"%s\"." from)
4911 ;; Check the Reply-To header.
4912 (message-check 'reply-to
4913 (let* ((case-fold-search t)
4914 (reply-to (message-fetch-field "reply-to"))
4919 ((string-match "," reply-to)
4921 (format "Multiple Reply-To addresses: \"%s\". Really post? "
4923 ((or (not (string-match
4925 (setq ad (nth 1 (std11-extract-address-components
4926 reply-to))))) ;larsi@ifi
4927 (string-match "\\.\\." ad) ;larsi@ifi..uio
4928 (string-match "@\\." ad) ;larsi@.ifi.uio
4929 (string-match "\\.$" ad) ;larsi@ifi.uio.
4930 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4931 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
4934 "The Reply-To looks strange: \"%s\". Really post? "
4938 (defun message-check-news-body-syntax ()
4940 ;; Check for long lines.
4941 (message-check 'long-lines
4942 (goto-char (point-min))
4944 (concat "^" (regexp-quote mail-header-separator) "$"))
4948 mime-edit-tag-regexp)
4951 (< (- (point) p) 80)))
4952 (zerop (forward-line 1))))
4956 "You have lines longer than 79 characters. Really post? ")))
4957 ;; Check whether the article is empty.
4958 (message-check 'empty
4959 (goto-char (point-min))
4961 (concat "^" (regexp-quote mail-header-separator) "$"))
4964 (goto-char (point-max))
4965 (re-search-backward message-signature-separator nil t)
4967 (or (re-search-backward "[^ \n\t]" b t)
4968 (if (message-gnksa-enable-p 'empty-article)
4969 (y-or-n-p "Empty article. Really post? ")
4970 (message "Denied posting -- Empty article.")
4972 ;; Check for control characters.
4973 (message-check 'control-chars
4974 (if (re-search-forward
4975 (string-as-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
4978 "The article contains control characters. Really post? ")
4980 ;; Check 8bit characters.
4981 (message-check '8bit
4982 (message-check-8bit))
4983 ;; Check excessive size.
4984 (message-check 'size
4985 (if (> (buffer-size) 60000)
4987 (format "The article is %d octets long. Really post? "
4990 ;; Check whether any new text has been added.
4991 (message-check 'new-text
4993 (not message-checksum)
4994 (not (eq (message-checksum) message-checksum))
4995 (if (message-gnksa-enable-p 'quoted-text-only)
4997 "It looks like no new text has been added. Really post? ")
4998 (message "Denied posting -- no new text has been added.")
5000 ;; Check the length of the signature.
5001 (message-check 'signature
5002 (goto-char (point-max))
5003 (if (> (count-lines (point) (point-max)) 5)
5006 "Your .sig is %d lines; it should be max 4. Really post? "
5007 (1- (count-lines (point) (point-max)))))
5009 ;; Ensure that text follows last quoted portion.
5010 (message-check 'quoting-style
5011 (goto-char (point-max))
5012 (let ((no-problem t))
5013 (when (search-backward-regexp "^>[^\n]*\n" nil t)
5014 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
5017 (if (message-gnksa-enable-p 'quoted-text-only)
5018 (y-or-n-p "Your text should follow quoted text. Really post? ")
5020 (goto-char (point-min))
5022 (concat "^" (regexp-quote mail-header-separator) "$"))
5023 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
5024 (y-or-n-p "Your text should follow quoted text. Really post? ")
5025 (message "Denied posting -- only quoted text.")
5028 (defun message-check-mail-syntax ()
5029 "Check the syntax of the message."
5034 ;; We narrow to the headers and check them first.
5037 (message-narrow-to-headers)
5038 (message-check-mail-header-syntax)))
5041 (set-buffer message-edit-buffer)
5042 (message-check-mail-body-syntax))))))
5044 (defun message-check-mail-header-syntax ()
5047 (defun message-check-mail-body-syntax ()
5049 ;; Check 8bit characters.
5050 (message-check '8bit
5051 (message-check-8bit)
5054 (defun message-check-8bit ()
5055 "Check the article contains 8bit characters."
5057 (set-buffer message-encoding-buffer)
5058 (message-narrow-to-headers)
5059 (let* ((case-fold-search t)
5060 (field-value (message-fetch-field "content-transfer-encoding")))
5061 (if (and field-value
5062 (member (downcase field-value) message-8bit-encoding-list))
5065 (set-buffer (get-buffer-create " message syntax"))
5067 (goto-char (point-min))
5068 (set-buffer-multibyte nil)
5069 (insert-buffer-substring message-encoding-buffer)
5070 (goto-char (point-min))
5071 (if (re-search-forward "[^\x00-\x7f]" nil t)
5073 "The article contains 8bit characters. Really post? ")
5076 (defun message-checksum ()
5077 "Return a \"checksum\" for the current buffer."
5080 (goto-char (point-min))
5082 (concat "^" (regexp-quote mail-header-separator) "$"))
5084 (when (not (looking-at "[ \t\n]"))
5085 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
5090 (defun message-do-fcc ()
5091 "Process Fcc headers in the current buffer."
5092 (let ((case-fold-search t)
5093 (coding-system-for-write 'raw-text)
5095 (mml-externalize-attachments message-fcc-externalize-attachments))
5098 (message-narrow-to-headers)
5099 (setq file (message-fetch-field "fcc" t)))
5101 (set-buffer (get-buffer-create " *message temp*"))
5103 (insert-buffer-substring message-encoding-buffer)
5105 (message-narrow-to-headers)
5106 (while (setq file (message-fetch-field "fcc"))
5108 (message-remove-header "fcc" nil t)))
5109 (goto-char (point-min))
5110 (when (re-search-forward
5111 (concat "^" (regexp-quote mail-header-separator) "$")
5113 (replace-match "" t t))
5114 ;; Process FCC operations.
5116 (setq file (pop list))
5117 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
5118 ;; Pipe the article to the program in question.
5119 (call-process-region (point-min) (point-max) shell-file-name
5120 nil nil nil shell-command-switch
5121 (match-string 1 file))
5122 ;; Save the article.
5123 (setq file (expand-file-name file))
5124 (unless (file-exists-p (file-name-directory file))
5125 (make-directory (file-name-directory file) t))
5126 (if (and message-fcc-handler-function
5127 (not (eq message-fcc-handler-function 'rmail-output)))
5128 (funcall message-fcc-handler-function file)
5129 (if (and (file-readable-p file) (mail-file-babyl-p file))
5130 (rmail-output file 1 nil t)
5131 (let ((mail-use-rfc822 t))
5132 (rmail-output file 1 t t))))))
5133 (kill-buffer (current-buffer))))))
5135 (defun message-output (filename)
5136 "Append this article to Unix/babyl mail file FILENAME."
5137 (if (and (file-readable-p filename)
5138 (mail-file-babyl-p filename))
5139 (gnus-output-to-rmail filename t)
5140 (gnus-output-to-mail filename t)))
5142 (defun message-cleanup-headers ()
5143 "Do various automatic cleanups of the headers."
5144 ;; Remove empty lines in the header.
5146 (message-narrow-to-headers)
5147 ;; Remove blank lines.
5148 (while (re-search-forward "^[ \t]*\n" nil t)
5149 (replace-match "" t t))
5151 ;; Correct Newsgroups and Followup-To headers: Change sequence of
5152 ;; spaces to comma and eliminate spaces around commas. Eliminate
5153 ;; embedded line breaks.
5154 (goto-char (point-min))
5155 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
5159 (if (re-search-forward "^[^ \t]" nil t)
5163 (goto-char (point-min))
5164 (while (re-search-forward "\n[ \t]+" nil t)
5165 (replace-match " " t t)) ;No line breaks (too confusing)
5166 (goto-char (point-min))
5167 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
5168 (replace-match "," t t))
5169 (goto-char (point-min))
5170 ;; Remove trailing commas.
5171 (when (re-search-forward ",+$" nil t)
5172 (replace-match "" t t))))))
5174 (defun message-make-date (&optional now)
5175 "Make a valid data header.
5176 If NOW, use that time instead."
5177 (let ((system-time-locale "C"))
5178 (format-time-string "%a, %d %b %Y %T %z" now)))
5180 (defun message-make-followup-subject (subject)
5181 "Make a followup Subject."
5183 ((and (eq message-use-subject-re 'guess)
5184 (string-match message-subject-encoded-re-regexp subject))
5186 (message-use-subject-re
5187 (concat "Re: " (message-strip-subject-re subject)))
5190 (defun message-make-message-id ()
5191 "Make a unique Message-ID."
5192 (concat "<" (message-unique-id)
5193 (let ((psubject (save-excursion (message-fetch-field "subject")))
5195 (save-excursion (message-fetch-field "supersedes"))))
5197 (and message-reply-headers
5198 (mail-header-references message-reply-headers)
5199 (mail-header-subject message-reply-headers)
5202 (message-strip-subject-re
5203 (mail-header-subject message-reply-headers))
5204 (message-strip-subject-re psubject))))
5206 (string-match "_-_@" psupersedes)))
5208 "@" (message-make-fqdn) ">"))
5210 (defvar message-unique-id-char nil)
5212 ;; If you ever change this function, make sure the new version
5213 ;; cannot generate IDs that the old version could.
5214 ;; You might for example insert a "." somewhere (not next to another dot
5215 ;; or string boundary), or modify the "fsf" string.
5216 (defun message-unique-id ()
5217 ;; Don't use microseconds from (current-time), they may be unsupported.
5218 ;; Instead we use this randomly inited counter.
5219 (setq message-unique-id-char
5220 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
5221 ;; (current-time) returns 16-bit ints,
5222 ;; and 2^16*25 just fits into 4 digits i base 36.
5224 (let ((tm (current-time)))
5226 (if (memq system-type '(ms-dos emx vax-vms))
5227 (let ((user (downcase (user-login-name))))
5228 (while (string-match "[^a-z0-9_]" user)
5229 (aset user (match-beginning 0) ?_))
5231 (message-number-base36 (user-uid) -1))
5232 (message-number-base36 (+ (car tm)
5233 (lsh (% message-unique-id-char 25) 16)) 4)
5234 (message-number-base36 (+ (nth 1 tm)
5235 (lsh (/ message-unique-id-char 25) 16)) 4)
5236 ;; Append a given name, because while the generated ID is unique
5237 ;; to this newsreader, other newsreaders might otherwise generate
5238 ;; the same ID via another algorithm.
5241 (defun message-number-base36 (num len)
5246 (concat (message-number-base36 (/ num 36) (1- len))
5247 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
5250 (defun message-make-organization ()
5251 "Make an Organization header."
5252 (let* ((organization
5253 (when message-user-organization
5254 (if (functionp message-user-organization)
5255 (funcall message-user-organization)
5256 message-user-organization))))
5258 (set-buffer-multibyte t)
5259 (cond ((stringp organization)
5260 (insert organization))
5261 ((and (eq t organization)
5262 message-user-organization-file
5263 (file-exists-p message-user-organization-file))
5264 (insert-file-contents message-user-organization-file)))
5265 (goto-char (point-min))
5266 (while (re-search-forward "[\t\n]+" nil t)
5267 (replace-match "" t t))
5268 (unless (zerop (buffer-size))
5271 (defun message-make-lines ()
5272 "Count the number of lines and return numeric string."
5277 (int-to-string (count-lines (point) (point-max))))))
5279 (defun message-make-references ()
5280 "Return the References header for this message."
5281 (when message-reply-headers
5282 (let ((message-id (mail-header-message-id message-reply-headers))
5283 (references (mail-header-references message-reply-headers))
5285 (if (or references message-id)
5286 (concat (or references "") (and references " ")
5290 (defun message-make-in-reply-to ()
5291 "Return the In-Reply-To header for this message."
5292 (when message-reply-headers
5293 (let ((from (mail-header-from message-reply-headers))
5294 (date (mail-header-date message-reply-headers))
5295 (msg-id (mail-header-message-id message-reply-headers)))
5297 (let ((name (std11-extract-address-components from)))
5298 (concat msg-id (if msg-id " (")
5302 (if (or (not date) (string= date ""))
5303 "(unknown date)" date)
5304 "\"" (if msg-id ")")))))))
5306 (defun message-make-distribution ()
5307 "Make a Distribution header."
5308 (let ((orig-distribution (message-fetch-reply-field "distribution")))
5309 (cond ((functionp message-distribution-function)
5310 (funcall message-distribution-function))
5311 (t orig-distribution))))
5313 (defun message-make-expires ()
5314 "Return an Expires header based on `message-expires'."
5315 (let ((current (current-time))
5316 (future (* 1.0 message-expires 60 60 24)))
5317 ;; Add the future to current.
5318 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
5319 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
5320 (message-make-date current)))
5322 (defun message-make-path ()
5324 (let ((login-name (user-login-name)))
5325 (cond ((null message-user-path)
5326 (concat (system-name) "!" login-name))
5327 ((stringp message-user-path)
5328 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
5329 (concat message-user-path "!" login-name))
5332 (defun message-make-from ()
5333 "Make a From header."
5334 (let* ((style message-from-style)
5335 (login (message-make-address))
5337 (or (and (boundp 'user-full-name)
5340 (when (string= fullname "&")
5341 (setq fullname (user-login-name)))
5343 (set-buffer-multibyte t)
5346 (equal fullname ""))
5348 ((or (eq style 'angles)
5349 (and (not (eq style 'parens))
5350 ;; Use angles if no quoting is needed, or if parens would
5351 ;; need quoting too.
5352 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
5353 (let ((tmp (concat fullname nil)))
5354 (while (string-match "([^()]*)" tmp)
5355 (aset tmp (match-beginning 0) ?-)
5356 (aset tmp (1- (match-end 0)) ?-))
5357 (string-match "[\\()]" tmp)))))
5359 (goto-char (point-min))
5360 ;; Look for a character that cannot appear unquoted
5361 ;; according to RFC 822.
5362 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
5363 ;; Quote fullname, escaping specials.
5364 (goto-char (point-min))
5366 (while (re-search-forward "[\"\\]" nil 1)
5367 (replace-match "\\\\\\&" t))
5369 (insert " <" login ">"))
5370 (t ; 'parens or default
5372 (let ((fullname-start (point)))
5374 (goto-char fullname-start)
5375 ;; RFC 822 says \ and nonmatching parentheses
5376 ;; must be escaped in comments.
5377 ;; Escape every instance of ()\ ...
5378 (while (re-search-forward "[()\\]" nil 1)
5379 (replace-match "\\\\\\&" t))
5380 ;; ... then undo escaping of matching parentheses,
5381 ;; including matching nested parentheses.
5382 (goto-char fullname-start)
5383 (while (re-search-forward
5384 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
5386 (replace-match "\\1(\\3)" t)
5387 (goto-char fullname-start)))
5391 (defun message-make-sender ()
5392 "Return the \"real\" user address.
5393 This function tries to ignore all user modifications, and
5394 give as trustworthy answer as possible."
5395 (concat (user-login-name) "@" (system-name)))
5397 (defun message-make-address ()
5398 "Make the address of the user."
5399 (or (message-user-mail-address)
5400 (concat (user-login-name) "@" (message-make-domain))))
5402 (defun message-user-mail-address ()
5403 "Return the pertinent part of `user-mail-address'."
5404 (when (and user-mail-address
5405 (string-match "@.*\\." user-mail-address))
5406 (if (string-match " " user-mail-address)
5407 (nth 1 (std11-extract-address-components user-mail-address))
5408 user-mail-address)))
5410 (defun message-sendmail-envelope-from ()
5411 "Return the envelope from."
5412 (cond ((eq message-sendmail-envelope-from 'header)
5413 (nth 1 (std11-extract-address-components
5414 (message-fetch-field "from"))))
5415 ((stringp message-sendmail-envelope-from)
5416 message-sendmail-envelope-from)
5418 (message-make-address))))
5420 (defun message-make-fqdn ()
5421 "Return user's fully qualified domain name."
5422 (let* ((system-name (system-name))
5423 (user-mail (message-user-mail-address))
5426 (string-match "@\\(.*\\)\\'" user-mail))
5427 (match-string 1 user-mail)))
5428 (case-fold-search t))
5430 ((and message-user-fqdn
5431 (stringp message-user-fqdn)
5432 (string-match message-valid-fqdn-regexp message-user-fqdn)
5433 (not (string-match message-bogus-system-names message-user-fqdn)))
5435 ;; `message-user-fqdn' seems to be valid
5436 ((and (string-match message-valid-fqdn-regexp system-name)
5437 (not (string-match message-bogus-system-names system-name)))
5438 ;; `system-name' returned the right result.
5440 ;; Try `mail-host-address'.
5441 ((and (boundp 'mail-host-address)
5442 (stringp mail-host-address)
5443 (string-match message-valid-fqdn-regexp mail-host-address)
5444 (not (string-match message-bogus-system-names mail-host-address)))
5446 ;; We try `user-mail-address' as a backup.
5448 (stringp user-domain)
5449 (string-match message-valid-fqdn-regexp user-domain)
5450 (not (string-match message-bogus-system-names user-domain)))
5452 ;; Default to this bogus thing.
5455 ".i-did-not-set--mail-host-address--so-tickle-me")))))
5457 (defun message-make-host-name ()
5458 "Return the name of the host."
5459 (let ((fqdn (message-make-fqdn)))
5460 (string-match "^[^.]+\\." fqdn)
5461 (substring fqdn 0 (1- (match-end 0)))))
5463 (defun message-make-domain ()
5464 "Return the domain name."
5465 (or mail-host-address
5466 (message-make-fqdn)))
5468 (defun message-to-list-only ()
5469 "Send a message to the list only.
5470 Remove all addresses but the list address from To and Cc headers."
5472 (let ((listaddr (message-make-mail-followup-to t)))
5475 (message-remove-header "to")
5476 (message-remove-header "cc")
5477 (message-position-on-field "To" "X-Draft-From")
5478 (insert listaddr)))))
5480 (defun message-make-mail-followup-to (&optional only-show-subscribed)
5481 "Return the Mail-Followup-To header.
5482 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5483 subscribed address (and not the additional To and Cc header contents)."
5484 (let* ((case-fold-search t)
5485 (to (message-fetch-field "To"))
5486 (cc (message-fetch-field "cc"))
5487 (msg-recipients (concat to (and to cc ", ") cc))
5489 (mapcar 'mail-strip-quoted-names
5490 (message-tokenize-header msg-recipients)))
5492 (if message-subscribed-address-file
5493 (let (begin end item re)
5496 (insert-file-contents message-subscribed-address-file)
5498 (setq begin (point))
5501 (if (bolp) (setq end (1- end)))
5502 (setq item (regexp-quote (buffer-substring begin end)))
5503 (if re (setq re (concat re "\\|" item))
5504 (setq re (concat "\\`\\(" item))))
5505 (and re (list (concat re "\\)\\'"))))))))
5506 (mft-regexps (apply 'append message-subscribed-regexps
5507 (mapcar 'regexp-quote
5508 message-subscribed-addresses)
5511 message-subscribed-address-functions))))
5513 (let ((subscribed-lists nil)
5515 (loop for recipient in recipients
5516 when (loop for regexp in mft-regexps
5517 when (string-match regexp recipient) return t)
5520 (if only-show-subscribed
5522 msg-recipients))))))
5524 ;; Dummy to avoid byte-compile warning.
5525 (defvar mule-version)
5526 (defvar emacs-beta-version)
5527 (defvar xemacs-codename)
5528 (defvar gnus-inviolable-extended-version)
5530 (defun message-make-user-agent ()
5531 "Return user-agent info if the value `message-user-agent' is non-nil. If the
5532 \"User-Agent\" field has already exist, remove it."
5533 (when message-user-agent
5535 (goto-char (point-min))
5536 (let ((case-fold-search t))
5537 (when (re-search-forward "^User-Agent:[\t ]*" nil t)
5538 (delete-region (match-beginning 0) (1+ (std11-field-end)))))))
5541 (defun message-idna-to-ascii-rhs-1 (header)
5542 "Interactively potentially IDNA encode domain names in HEADER."
5543 (let ((field (message-fetch-field header))
5546 (dolist (address (mail-header-parse-addresses field))
5547 (setq address (car address)
5548 rhs (downcase (or (cadr (split-string address "@")) ""))
5549 ace (downcase (idna-to-ascii rhs)))
5550 (when (and (not (equal rhs ace))
5551 (or (not (eq message-use-idna 'ask))
5552 (y-or-n-p (format "Replace %s with %s? " rhs ace))))
5553 (goto-char (point-min))
5554 (while (re-search-forward (concat "^" header ":") nil t)
5555 (message-narrow-to-field)
5556 (while (search-forward (concat "@" rhs) nil t)
5557 (replace-match (concat "@" ace) t t))
5558 (goto-char (point-max))
5561 (defun message-idna-to-ascii-rhs ()
5562 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
5563 See `message-idna-encode'."
5565 (when message-use-idna
5568 (message-narrow-to-head)
5569 (message-idna-to-ascii-rhs-1 "From")
5570 (message-idna-to-ascii-rhs-1 "To")
5571 (message-idna-to-ascii-rhs-1 "Cc")))))
5573 (defun message-generate-headers (headers)
5574 "Prepare article HEADERS.
5575 Headers already prepared in the buffer are not modified."
5576 (setq headers (append headers message-required-headers))
5578 (message-narrow-to-headers)
5579 (let* ((Date (message-make-date))
5580 (Message-ID (message-make-message-id))
5581 (Organization (message-make-organization))
5582 (From (message-make-from))
5583 (Path (message-make-path))
5586 (In-Reply-To (message-make-in-reply-to))
5587 (References (message-make-references))
5589 (Distribution (message-make-distribution))
5590 (Lines (message-make-lines))
5591 (User-Agent (message-make-user-agent))
5592 (Expires (message-make-expires))
5593 (case-fold-search t)
5595 header value elem header-string)
5596 ;; First we remove any old generated headers.
5597 (let ((headers message-deletable-headers))
5598 (unless (buffer-modified-p)
5599 (setq headers (delq 'Message-ID (copy-sequence headers))))
5601 (goto-char (point-min))
5602 (and (re-search-forward
5603 (concat "^" (symbol-name (car headers)) ": *") nil t)
5604 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
5605 (message-delete-line))
5607 ;; Go through all the required headers and see if they are in the
5608 ;; articles already. If they are not, or are empty, they are
5609 ;; inserted automatically - except for Subject, Newsgroups and
5612 (goto-char (point-min))
5613 (setq elem (pop headers))
5615 (if (eq (car elem) 'optional)
5616 (setq header (cdr elem)
5618 (setq header (car elem)))
5620 (setq header-string (if (stringp header)
5622 (symbol-name header)))
5623 (when (or (not (re-search-forward
5625 (regexp-quote (downcase header-string))
5629 ;; The header was found. We insert a space after the
5630 ;; colon, if there is none.
5631 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
5632 ;; Find out whether the header is empty.
5633 (looking-at "[ \t]*\n[^ \t]")))
5634 ;; So we find out what value we should insert.
5638 (eq (car elem) 'optional)
5639 (not (member header-string message-inserted-headers)))
5640 ;; This is an optional header. If the cdr of this
5641 ;; is something that is nil, then we do not insert
5643 (setq header (cdr elem))
5644 (or (and (functionp (cdr elem))
5645 (funcall (cdr elem)))
5646 (and (boundp (cdr elem))
5647 (symbol-value (cdr elem)))))
5649 ;; The element is a cons. Either the cdr is a
5650 ;; string to be inserted verbatim, or it is a
5651 ;; function, and we insert the value returned from
5653 (or (and (stringp (cdr elem))
5655 (and (functionp (cdr elem))
5656 (funcall (cdr elem)))))
5657 ((and (boundp header)
5658 (symbol-value header))
5659 ;; The element is a symbol. We insert the value
5660 ;; of this symbol, if any.
5661 (symbol-value header))
5662 ((not (message-check-element header))
5663 ;; We couldn't generate a value for this header,
5664 ;; so we just ask the user.
5665 (read-from-minibuffer
5666 (format "Empty header for %s; enter value: " header)))))
5667 ;; Finally insert the header.
5669 (not (equal value "")))
5673 ;; This header didn't exist, so we insert it.
5674 (goto-char (point-max))
5676 (cdr (assq header message-header-format-alist))))
5678 (funcall formatter header value)
5679 (insert header-string ": " value))
5680 (goto-char (message-fill-field))
5681 ;; We check whether the value was ended by a
5682 ;; newline. If not, we insert one.
5686 ;; The value of this header was empty, so we clear
5687 ;; totally and insert the new value.
5688 (delete-region (point) (point-at-eol))
5689 ;; If the header is optional, and the header was
5690 ;; empty, we can't insert it anyway.
5692 (push header-string message-inserted-headers)
5694 (message-fill-field)))
5695 ;; Add the deletable property to the headers that require it.
5696 (and (memq header message-deletable-headers)
5697 (progn (beginning-of-line) (looking-at "[^:]+: "))
5698 (add-text-properties
5699 (point) (match-end 0)
5700 '(message-deletable t face italic) (current-buffer)))))))
5701 ;; Insert new Sender if the From is strange.
5702 (let ((from (message-fetch-field "from"))
5703 (sender (message-fetch-field "sender"))
5704 (secure-sender (message-make-sender)))
5706 (not (message-check-element 'sender))
5709 (cadr (std11-extract-address-components from)))
5710 (downcase secure-sender)))
5715 (cadr (std11-extract-address-components sender)))
5716 (downcase secure-sender)))))
5717 (goto-char (point-min))
5718 ;; Rename any old Sender headers to Original-Sender.
5719 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
5721 (insert "Original-")
5722 (beginning-of-line))
5723 (when (or (message-news-p)
5724 (string-match "@.+\\.." secure-sender))
5725 (insert "Sender: " secure-sender "\n"))))
5727 (message-idna-to-ascii-rhs))))
5729 (defun message-insert-courtesy-copy ()
5730 "Insert a courtesy message in mail copies of combined messages."
5734 (message-narrow-to-headers)
5735 (when (setq newsgroups (message-fetch-field "newsgroups"))
5736 (goto-char (point-max))
5737 (insert "Posted-To: " newsgroups "\n")))
5739 (when message-courtesy-message
5741 ((string-match "%s" message-courtesy-message)
5742 (insert (format message-courtesy-message newsgroups)))
5744 (insert message-courtesy-message)))))))
5747 ;;; Setting up a message buffer
5750 (defun message-skip-to-next-address ()
5751 (let ((end (save-excursion
5752 (message-next-header)
5755 (when (looking-at ",")
5757 (while (and (not (= (point) end))
5758 (or (not (eq char ?,))
5760 (skip-chars-forward "^,\"" (point-max))
5761 (when (eq (setq char (following-char)) ?\")
5762 (setq quoted (not quoted)))
5763 (unless (= (point) end)
5765 (skip-chars-forward " \t\n")))
5767 (defun message-fill-address (header value)
5768 (insert (capitalize (symbol-name header))
5770 (if (consp value) (car value) value)
5772 (message-fill-field-address))
5774 (defun message-fill-references (header value)
5775 (insert (capitalize (symbol-name header))
5777 (std11-fill-msg-id-list-string
5778 (if (consp value) (car value) value))
5781 (defun message-split-line ()
5782 "Split current line, moving portion beyond point vertically down.
5783 If the current line has `message-yank-prefix', insert it on the new line."
5786 (split-line message-yank-prefix) ;; Emacs 21.3.50+ supports arg.
5790 (defun message-insert-header (header value)
5791 (insert (capitalize (symbol-name header))
5793 (if (consp value) (car value) value)))
5795 (defun message-field-name ()
5797 (goto-char (point-min))
5798 (when (looking-at "\\([^:]+\\):")
5799 (intern (capitalize (match-string 1))))))
5801 (defun message-fill-field ()
5804 (message-narrow-to-field)
5805 (let ((field-name (message-field-name)))
5806 (funcall (or (cadr (assq field-name message-field-fillers))
5807 'message-fill-field-general)))
5810 (defun message-fill-field-address ()
5812 (message-skip-to-next-address)
5814 (if (and (> (current-column) 78)
5820 (setq last (1+ (point))))
5821 (setq last (1+ (point)))))))
5823 (defun message-fill-field-general ()
5824 (let ((begin (point))
5827 (while (and (search-forward "\n" nil t)
5829 (replace-match " " t t))
5830 (fill-region-as-paragraph begin (point-max))
5831 ;; Tapdance around looong Message-IDs.
5833 (when (looking-at "[ \t]*$")
5834 (message-delete-line))
5836 (search-forward ":" nil t)
5837 (when (looking-at "\n[ \t]+")
5838 (replace-match " " t t))
5839 (goto-char (point-max))))
5841 (defun message-shorten-1 (list cut surplus)
5842 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
5843 (setcdr (nthcdr (- cut 2) list)
5844 (nthcdr (+ (- cut 2) surplus 1) list)))
5846 (defun message-shorten-references (header references)
5847 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
5848 When sending via news, also check that the REFERENCES are less
5849 than 988 characters long, and if they are not, trim them until
5857 (goto-char (point-min))
5858 ;; Cons a list of valid references.
5859 (while (re-search-forward "<[^>]+>" nil t)
5860 (push (match-string 0) refs))
5861 (setq refs (nreverse refs)
5862 count (length refs)))
5864 ;; If the list has more than MAXCOUNT elements, trim it by
5865 ;; removing the CUTth element and the required number of
5866 ;; elements that follow.
5867 (when (> count maxcount)
5868 (let ((surplus (- count maxcount)))
5869 (message-shorten-1 refs cut surplus)
5870 (decf count surplus)))
5872 ;; When sending via news, make sure the total folded length will
5873 ;; be less than 998 characters. This is to cater to broken INN
5874 ;; 2.3 which counts the total number of characters in a header
5875 ;; rather than the physical line length of each line, as it should.
5877 ;; This hack should be removed when it's believed than INN 2.3 is
5878 ;; no longer widely used.
5880 ;; At this point the headers have not been generated, thus we use
5881 ;; message-this-is-news directly.
5882 (when message-this-is-news
5885 (message-insert-header
5886 header (mapconcat #'identity refs " "))
5888 (message-shorten-1 refs cut 1)))
5889 ;; Finally, collect the references back into a string and insert
5890 ;; it into the buffer.
5891 (message-insert-header header (mapconcat #'identity refs " "))))
5893 (defun message-position-point ()
5894 "Move point to where the user probably wants to find it."
5895 (message-narrow-to-headers)
5897 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
5898 (search-backward ":" )
5901 (if (eq (char-after) ? )
5905 (goto-char (point-max))
5908 (unless (looking-at "$")
5912 (defcustom message-beginning-of-line t
5913 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
5914 goes to beginning of header values."
5916 :group 'message-buffers
5917 :link '(custom-manual "(message)Movement")
5920 (defun message-beginning-of-line (&optional n)
5921 "Move point to beginning of header value or to beginning of line.
5922 The prefix argument N is passed directly to `beginning-of-line'.
5924 This command is identical to `beginning-of-line' if point is
5925 outside the message header or if the option `message-beginning-of-line'
5928 If point is in the message header and on a (non-continued) header
5929 line, move point to the beginning of the header value. If point
5930 is already there, move point to beginning of line. Therefore,
5931 repeated calls will toggle point between beginning of field and
5934 (let ((zrs 'zmacs-region-stays))
5935 (when (and (interactive-p) (boundp zrs))
5937 (if (and message-beginning-of-line
5938 (message-point-in-header-p))
5939 (let* ((here (point))
5940 (bol (progn (beginning-of-line n) (point)))
5941 (eol (point-at-eol))
5942 (eoh (re-search-forward ": *" eol t)))
5943 (if (or (not eoh) (equal here eoh))
5946 (beginning-of-line n)))
5948 (defun message-buffer-name (type &optional to group)
5949 "Return a new (unique) buffer name based on TYPE and TO."
5951 ;; Generate a new buffer name The Message Way.
5952 ((eq message-generate-new-buffers 'unique)
5953 (generate-new-buffer-name
5957 (or (car (std11-extract-address-components to))
5960 (if (and group (not (string= group ""))) (concat " on " group) "")
5962 ;; Check whether `message-generate-new-buffers' is a function,
5963 ;; and if so, call it.
5964 ((functionp message-generate-new-buffers)
5965 (funcall message-generate-new-buffers type to group))
5966 ((eq message-generate-new-buffers 'unsent)
5967 (generate-new-buffer-name
5968 (concat "*unsent " type
5971 (or (car (std11-extract-address-components to))
5974 (if (and group (not (string= group ""))) (concat " on " group) "")
5976 ;; Use standard name.
5978 (format "*%s message*" type))))
5980 (defmacro message-pop-to-buffer-1 (buffer)
5982 (let (special-display-buffer-names
5983 special-display-regexps
5984 same-window-buffer-names
5985 same-window-regexps)
5986 (pop-to-buffer ,buffer))
5987 (pop-to-buffer ,buffer)))
5989 (defun message-pop-to-buffer (name)
5990 "Pop to buffer NAME, and warn if it already exists and is modified."
5991 (let ((buffer (get-buffer name))
5992 (pop-up-frames (and (static-if (featurep 'xemacs)
5993 (device-on-window-system-p)
5995 message-use-multi-frames)))
5997 (buffer-name buffer))
5999 (message-pop-to-buffer-1 buffer)
6000 (when (and (buffer-modified-p)
6002 "Message already being composed; erase? ")))
6003 (error "Message being composed")))
6004 (message-pop-to-buffer-1 name))
6008 (set (make-local-variable 'message-original-frame) (selected-frame)))))
6010 (defun message-do-send-housekeeping ()
6011 "Kill old message buffers."
6012 ;; We might have sent this buffer already. Delete it from the
6014 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
6015 (while (and message-max-buffers
6017 (>= (length message-buffer-list) message-max-buffers))
6018 ;; Kill the oldest buffer -- unless it has been changed.
6019 (let ((buffer (pop message-buffer-list)))
6020 (when (and (buffer-name buffer)
6021 (not (buffer-modified-p buffer)))
6022 (kill-buffer buffer))))
6023 ;; Rename the buffer.
6024 (if message-send-rename-function
6025 (funcall message-send-rename-function)
6026 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
6028 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
6030 (let ((name (match-string 2 (buffer-name)))
6032 (if (not (or (null name)
6033 (string-equal name "mail")
6034 (string-equal name "posting")))
6035 (setq name (concat "*sent " name "*"))
6036 (message-narrow-to-headers)
6037 (setq to (message-fetch-field "to"))
6038 (setq group (message-fetch-field "newsgroups"))
6042 (to (concat "*sent mail to "
6043 (or (car (std11-extract-address-components to))
6045 ((and group (not (string= group "")))
6046 (concat "*sent posting on " group "*"))
6047 (t "*sent mail*"))))
6048 (unless (string-equal name (buffer-name))
6049 (rename-buffer name t)))))
6050 ;; Push the current buffer onto the list.
6051 (when message-max-buffers
6052 (setq message-buffer-list
6053 (nconc message-buffer-list (list (current-buffer))))))
6055 (defun message-mail-user-agent ()
6057 ((not message-mail-user-agent) nil)
6058 ((eq message-mail-user-agent t) mail-user-agent)
6059 (t message-mail-user-agent))))
6060 (if (memq mua '(message-user-agent gnus-user-agent))
6064 (defun message-setup (headers &optional replybuffer actions switch-function)
6065 (let ((mua (message-mail-user-agent))
6066 subject to field yank-action)
6067 (if (not (and message-this-is-mail mua))
6068 (message-setup-1 headers replybuffer actions)
6070 (setq yank-action (list 'insert-buffer replybuffer)))
6071 (setq headers (copy-sequence headers))
6072 (setq field (assq 'Subject headers))
6074 (setq subject (cdr field))
6075 (setq headers (delq field headers)))
6076 (setq field (assq 'To headers))
6078 (setq to (cdr field))
6079 (setq headers (delq field headers)))
6080 (let ((mail-user-agent mua))
6081 (compose-mail to subject
6082 (mapcar (lambda (item)
6084 (format "%s" (car item))
6087 nil switch-function yank-action actions)))))
6089 (defun message-headers-to-generate (headers included-headers excluded-headers)
6090 "Return a list that includes all headers from HEADERS.
6091 If INCLUDED-HEADERS is a list, just include those headers. If if is
6092 t, include all headers. In any case, headers from EXCLUDED-HEADERS
6096 (dolist (header headers)
6097 (setq header-name (cond
6098 ((and (consp header)
6099 (eq (car header) 'optional))
6100 ;; On the form (optional . Header)
6103 ;; On the form (Header . function)
6108 (when (and (not (memq header-name excluded-headers))
6109 (or (eq included-headers t)
6110 (memq header-name included-headers)))
6111 (push header result)))
6114 (defun message-setup-1 (headers &optional replybuffer actions)
6115 (dolist (action actions)
6117 (add-to-list 'message-send-actions
6118 `(apply ',(car action) ',(cdr action)))))
6119 (setq message-reply-buffer
6120 (or (message-get-parameter 'reply-buffer)
6122 (goto-char (point-min))
6123 ;; Insert all the headers.
6126 (alist message-header-format-alist))
6128 (unless (assq (caar h) message-header-format-alist)
6129 (push (list (caar h)) alist))
6133 (delete-region (point) (progn (forward-line -1) (point)))
6134 (when message-default-headers
6135 (insert message-default-headers)
6136 (or (bolp) (insert ?\n)))
6137 (insert mail-header-separator "\n")
6139 (when (message-news-p)
6140 (when message-default-news-headers
6141 (insert message-default-news-headers)
6142 (or (bolp) (insert ?\n)))
6143 (when message-generate-headers-first
6144 (message-generate-headers
6145 (message-headers-to-generate
6146 (append message-required-news-headers
6147 message-required-headers)
6148 message-generate-headers-first
6149 '(Lines Subject)))))
6150 (when (message-mail-p)
6151 (when message-default-mail-headers
6152 (insert message-default-mail-headers)
6153 (or (bolp) (insert ?\n)))
6155 (message-narrow-to-headers)
6156 (if (and replybuffer
6157 message-alternative-emails)
6158 (message-use-alternative-email-as-from)))
6159 (when message-generate-headers-first
6160 (message-generate-headers
6161 (message-headers-to-generate
6162 (append message-required-mail-headers
6163 message-required-headers)
6164 message-generate-headers-first
6165 '(Lines Subject)))))
6166 (run-hooks 'message-signature-setup-hook)
6167 (message-insert-signature)
6169 (message-narrow-to-headers)
6170 (run-hooks 'message-header-setup-hook))
6171 (set-buffer-modified-p nil)
6172 (setq buffer-undo-list nil)
6173 (run-hooks 'message-setup-hook)
6174 (message-position-point)
6177 (defun message-set-auto-save-file-name ()
6178 "Associate the message buffer with a file in the drafts directory."
6179 (when message-auto-save-directory
6180 (unless (file-directory-p
6181 (directory-file-name message-auto-save-directory))
6182 (make-directory message-auto-save-directory t))
6184 (setq message-draft-article
6185 (nndraft-request-associate-buffer "drafts"))
6186 (setq buffer-file-name (expand-file-name
6187 (if (memq system-type
6188 '(ms-dos ms-windows windows-nt
6189 cygwin cygwin32 win32 w32
6193 message-auto-save-directory))
6194 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
6195 (clear-visited-file-modtime)
6196 (setq buffer-file-coding-system message-draft-coding-system)))
6198 (defun message-disassociate-draft ()
6199 "Disassociate the message buffer from the drafts directory."
6200 (when message-draft-article
6201 (nndraft-request-expire-articles
6202 (list message-draft-article) "drafts" nil t)))
6204 (defun message-insert-headers ()
6205 "Generate the headers for the article."
6209 (message-narrow-to-headers)
6210 (when (message-news-p)
6211 (message-generate-headers
6214 (copy-sequence message-required-news-headers)))))
6215 (when (message-mail-p)
6216 (message-generate-headers
6219 (copy-sequence message-required-mail-headers))))))))
6224 ;;; Commands for interfacing with message
6228 (defun message-mail (&optional to subject
6229 other-headers continue switch-function
6230 yank-action send-actions)
6231 "Start editing a mail message to be sent.
6232 OTHER-HEADERS is an alist of header/value pairs."
6234 (let ((message-this-is-mail t) replybuffer)
6235 (unless (message-mail-user-agent)
6236 (message-pop-to-buffer (message-buffer-name "mail" to)))
6237 ;; FIXME: message-mail should do something if YANK-ACTION is not
6239 (and (consp yank-action) (eq (car yank-action) 'insert-buffer)
6240 (setq replybuffer (nth 1 yank-action)))
6243 `((To . ,(or to "")) (Subject . ,(or subject "")))
6244 (when other-headers other-headers))
6245 replybuffer send-actions)
6246 ;; FIXME: Should return nil if failure.
6250 (defun message-news (&optional newsgroups subject)
6251 "Start editing a news article to be sent."
6253 (let ((message-this-is-news t))
6254 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
6255 (message-setup `((Newsgroups . ,(or newsgroups ""))
6256 (Subject . ,(or subject ""))))))
6258 (defun message-get-reply-headers (wide &optional to-address address-headers)
6259 (let (follow-to mct never-mct to cc author mft recipients)
6260 ;; Find all relevant headers we need.
6262 (message-narrow-to-headers-or-head)
6263 (let ((mrt (when message-use-mail-reply-to
6264 (message-fetch-field "mail-reply-to")))
6265 (reply-to (message-fetch-field "reply-to")))
6266 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
6267 ;; message-header-synonyms.
6268 (setq to (or (message-fetch-field "to")
6269 (and (loop for synonym in message-header-synonyms
6270 when (memq 'Original-To synonym)
6272 (message-fetch-field "original-to")))
6273 cc (message-fetch-field "cc")
6274 mct (when message-use-mail-copies-to
6275 (message-fetch-field "mail-copies-to"))
6278 (message-fetch-field "from")
6280 mft (when (and (not (or to-address mrt reply-to))
6281 message-use-mail-followup-to)
6282 (message-fetch-field "mail-followup-to")))))
6285 ;; Handle special values of Mail-Copies-To.
6287 (cond ((or (equal (downcase mct) "never")
6288 (equal (downcase mct) "nobody"))
6289 (when (or (not (eq message-use-mail-copies-to 'ask))
6291 (concat "Obey Mail-Copies-To: never? ") t "\
6292 You should normally obey the Mail-Copies-To: header.
6294 `Mail-Copies-To: " mct "'
6295 directs you not to send your response to the author."))
6298 ((or (equal (downcase mct) "always")
6299 (equal (downcase mct) "poster"))
6300 (if (or (not (eq message-use-mail-copies-to 'ask))
6302 (concat "Obey Mail-Copies-To: always? ") t "\
6303 You should normally obey the Mail-Copies-To: header.
6305 `Mail-Copies-To: " mct "'
6306 sends a copy of your response to the author."))
6309 ((and (eq message-use-mail-copies-to 'ask)
6310 (not (message-y-or-n-p
6311 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
6312 You should normally obey the Mail-Copies-To: header.
6314 `Mail-Copies-To: " mct "'
6315 sends a copy of your response to " (if (string-match "," mct)
6316 "the specified addresses"
6317 "that address") ".")))
6320 ;; Build (textual) list of new recipient addresses.
6323 (setq recipients (concat ", " author)))
6325 (dolist (header address-headers)
6326 (let ((value (message-fetch-field header)))
6328 (setq recipients (concat recipients ", " value))))))
6330 (string-match "[^ \t,]" mft)
6331 (or (not (eq message-use-mail-followup-to 'ask))
6332 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
6333 You should normally obey the Mail-Followup-To: header. In this
6334 article, it has the value of
6338 which directs your response to " (if (string-match "," mft)
6339 "the specified addresses"
6340 "that address only") ".
6342 Most commonly, Mail-Followup-To is used by a mailing list poster to
6343 express that responses should be sent to just the list, and not the
6346 If a message is posted to several mailing lists, Mail-Followup-To may
6347 also be used to direct the following discussion to one list only,
6348 because discussions that are spread over several lists tend to be
6349 fragmented and very difficult to follow.
6351 Also, some source/announcement lists are not intended for discussion;
6352 responses here are directed to other addresses.")))
6353 (setq recipients (concat ", " mft)))
6355 (setq recipients (concat ", " to-address))
6356 ;; If the author explicitly asked for a copy, we don't deny it to them.
6357 (if mct (setq recipients (concat recipients ", " mct))))
6359 (setq recipients (if never-mct "" (concat ", " author)))
6360 (if to (setq recipients (concat recipients ", " to)))
6361 (if cc (setq recipients (concat recipients ", " cc)))
6362 (if mct (setq recipients (concat recipients ", " mct)))))
6363 (if (>= (length recipients) 2)
6364 ;; Strip the leading ", ".
6365 (setq recipients (substring recipients 2)))
6366 ;; Squeeze whitespace.
6367 (while (string-match "[ \t][ \t]+" recipients)
6368 (setq recipients (replace-match " " t t recipients)))
6369 ;; Remove addresses that match `rmail-dont-reply-to-names'.
6370 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
6371 (setq recipients (rmail-dont-reply-to recipients)))
6372 ;; Perhaps "Mail-Copies-To: never" removed the only address?
6373 (if (string-equal recipients "")
6374 (setq recipients author))
6375 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
6379 (cons (downcase (mail-strip-quoted-names addr)) addr))
6380 (message-tokenize-header recipients)))
6381 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
6382 (let ((s recipients))
6384 (setq recipients (delq (assoc (car (pop s)) s) recipients))))
6386 ;; Remove hierarchical lists that are contained within each other,
6387 ;; if message-hierarchical-addresses is defined.
6388 (when message-hierarchical-addresses
6389 (let ((plain-addrs (mapcar 'car recipients))
6392 (setq subaddrs (assoc (car plain-addrs)
6393 message-hierarchical-addresses)
6394 plain-addrs (cdr plain-addrs))
6396 (setq subaddrs (cdr subaddrs))
6398 (setq recip (assoc (car subaddrs) recipients)
6399 subaddrs (cdr subaddrs))
6401 (setq recipients (delq recip recipients))))))))
6403 ;; Build the header alist. Allow the user to be asked whether
6404 ;; or not to reply to all recipients in a wide reply.
6405 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
6406 (when (and recipients
6407 (or (not message-wide-reply-confirm-recipients)
6408 (y-or-n-p "Reply to all recipients? ")))
6409 (setq recipients (mapconcat
6410 (lambda (addr) (cdr addr)) recipients ", "))
6411 (if (string-match "^ +" recipients)
6412 (setq recipients (substring recipients (match-end 0))))
6413 (push (cons 'Cc recipients) follow-to)))
6417 (defun message-reply (&optional to-address wide)
6418 "Start editing a reply to the article in the current buffer."
6420 (require 'gnus-sum) ; for gnus-list-identifiers
6421 (let ((cur (current-buffer))
6423 references message-id follow-to
6424 (inhibit-point-motion-hooks t)
6425 (message-this-is-mail t)
6426 gnus-warning in-reply-to)
6428 (message-narrow-to-head-1)
6429 ;; Allow customizations to have their say.
6431 ;; This is a regular reply.
6432 (when (functionp message-reply-to-function)
6434 (setq follow-to (funcall message-reply-to-function))))
6435 ;; This is a followup.
6436 (when (functionp message-wide-reply-to-function)
6439 (funcall message-wide-reply-to-function)))))
6440 (setq message-id (message-fetch-field "message-id" t)
6441 references (message-fetch-field "references")
6442 date (message-fetch-field "date")
6443 from (message-fetch-field "from")
6444 subject (or (message-fetch-field "subject") "none"))
6445 (when gnus-list-identifiers
6446 (setq subject (message-strip-list-identifiers subject)))
6447 (setq subject (message-make-followup-subject subject))
6448 (when message-subject-trailing-was-query
6449 (setq subject (message-strip-subject-trailing-was subject)))
6451 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6452 (string-match "<[^>]+>" gnus-warning))
6453 (setq message-id (match-string 0 gnus-warning)))
6456 (setq follow-to (message-get-reply-headers wide to-address)))
6458 ;; Get the references from "In-Reply-To" field if there were
6459 ;; no references and "In-Reply-To" field looks promising.
6461 (when (and (setq in-reply-to (message-fetch-field "in-reply-to"))
6462 (string-match "<[^>]+>" in-reply-to))
6463 (setq references (match-string 0 in-reply-to)))))
6465 (unless (message-mail-user-agent)
6466 (message-pop-to-buffer
6467 (message-buffer-name
6468 (if wide "wide reply" "reply") from
6469 (if wide to-address nil))))
6471 (setq message-reply-headers
6472 (make-full-mail-header-from-decoded-header
6473 0 subject from date message-id references 0 0 ""))
6476 `((Subject . ,subject)
6481 (defun message-wide-reply (&optional to-address)
6482 "Make a \"wide\" reply to the message in the current buffer."
6484 (message-reply to-address t))
6487 (defun message-followup (&optional to-newsgroups)
6488 "Follow up to the message in the current buffer.
6489 If TO-NEWSGROUPS, use that as the new Newsgroups line."
6491 (require 'gnus-sum) ; for gnus-list-identifiers
6492 (let ((cur (current-buffer))
6493 from subject date reply-to mrt mct mft
6494 references message-id follow-to
6495 (inhibit-point-motion-hooks t)
6496 (message-this-is-news t)
6497 followup-to distribution newsgroups gnus-warning posted-to)
6499 (message-narrow-to-head)
6500 (when (functionp message-followup-to-function)
6502 (funcall message-followup-to-function)))
6503 (setq from (message-fetch-field "from")
6504 date (message-fetch-field "date")
6505 subject (or (message-fetch-field "subject") "none")
6506 references (message-fetch-field "references")
6507 message-id (message-fetch-field "message-id" t)
6508 followup-to (message-fetch-field "followup-to")
6509 newsgroups (message-fetch-field "newsgroups")
6510 posted-to (message-fetch-field "posted-to")
6511 reply-to (message-fetch-field "reply-to")
6512 mrt (when message-use-mail-reply-to
6513 (message-fetch-field "mail-reply-to"))
6514 distribution (message-fetch-field "distribution")
6515 mct (when message-use-mail-copies-to
6516 (message-fetch-field "mail-copies-to"))
6517 mft (when message-use-mail-followup-to
6518 (message-fetch-field "mail-followup-to")))
6519 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6520 (string-match "<[^>]+>" gnus-warning))
6521 (setq message-id (match-string 0 gnus-warning)))
6522 ;; Remove bogus distribution.
6523 (when (and (stringp distribution)
6524 (let ((case-fold-search t))
6525 (string-match "world" distribution)))
6526 (setq distribution nil))
6527 (if gnus-list-identifiers
6528 (setq subject (message-strip-list-identifiers subject)))
6529 (setq subject (message-make-followup-subject subject))
6530 (when message-subject-trailing-was-query
6531 (setq subject (message-strip-subject-trailing-was subject)))
6534 ;; Handle special values of Mail-Copies-To.
6537 ((and (or (equal (downcase mct) "never")
6538 (equal (downcase mct) "nobody")))
6540 ((and (or (equal (downcase mct) "always")
6541 (equal (downcase mct) "poster")))
6542 (if (or (not (eq message-use-mail-copies-to 'ask))
6544 (concat "Obey Mail-Copies-To: always? ") t "\
6545 You should normally obey the Mail-Copies-To: header.
6547 `Mail-Copies-To: " mct "'
6548 sends a copy of your response to the author."))
6549 (setq mct (or mrt reply-to from))
6551 ((and (eq message-use-mail-copies-to 'ask)
6554 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
6555 You should normally obey the Mail-Copies-To: header.
6557 `Mail-Copies-To: " mct "'
6558 sends a copy of your response to " (if (string-match "," mct)
6559 "the specified addresses"
6560 "that address") ".")))
6565 (to-newsgroups (setq follow-to (list (cons 'Newsgroups to-newsgroups))))
6566 ;; Handle Followup-To.
6569 ((equal (downcase followup-to) "poster")
6570 (if (or (and followup-to (eq message-use-followup-to 'use))
6571 (message-y-or-n-p "Obey Followup-To: poster? " t "\
6572 You should normally obey the Followup-To: header.
6574 `Followup-To: poster'
6575 sends your response via e-mail instead of news.
6577 A typical situation where `Followup-To: poster' is used is when the author
6578 does not read the newsgroup, so he wouldn't see any replies sent to it."))
6579 (setq message-this-is-news nil
6581 follow-to (list (cons 'To (or mrt reply-to from ""))))
6582 (setq follow-to (list (cons 'Newsgroups newsgroups)))))
6584 (if (or (equal followup-to newsgroups)
6585 (not (and followup-to (eq message-use-followup-to 'ask)))
6587 (concat "Obey Followup-To: " followup-to "? ") t "\
6588 You should normally obey the Followup-To: header.
6590 `Followup-To: " followup-to "'
6591 directs your response to " (if (string-match "," followup-to)
6592 "the specified newsgroups"
6593 "that newsgroup only") ".
6595 If a message is posted to several newsgroups, Followup-To is often
6596 used to direct the following discussion to one newsgroup only,
6597 because discussions that are spread over several newsgroup tend to
6598 be fragmented and very difficult to follow.
6600 Also, some source/announcement newsgroups are not intended for discussion;
6601 responses here are directed to other newsgroups."))
6602 (setq follow-to (list (cons 'Newsgroups followup-to)))
6603 (setq follow-to (list (cons 'Newsgroups newsgroups)))))))
6604 ;; Handle Mail-Followup-To, followup via e-mail.
6606 (or (not (eq message-use-mail-followup-to 'ask))
6608 (concat "Obey Mail-Followup-To: " mft "? ") t "\
6609 You should normally obey the Mail-Followup-To: header.
6611 `Mail-Followup-To: " mft "'
6612 directs your response to " (if (string-match "," mft)
6613 "the specified addresses"
6614 "that address only") " instead of news.
6616 A typical situation where Mail-Followup-To is used is when the author thinks
6617 that further discussion should take place only in "
6618 (if (string-match "," mft)
6619 "the specified mailing lists"
6620 "that mailing list") ".")))
6621 (setq message-this-is-news nil
6623 follow-to (list (cons 'To mft))))
6624 (posted-to (setq follow-to (list (cons 'Newsgroups posted-to))))
6626 (setq follow-to (list (cons 'Newsgroups newsgroups))))))
6628 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
6630 (setq message-reply-headers
6631 (make-full-mail-header-from-decoded-header
6632 0 subject from date message-id references 0 0 ""))
6635 `((Subject . ,subject)
6637 ,@(and mct (list (cons 'Cc mct)))
6638 ,@(and distribution (list (cons 'Distribution distribution))))
6641 (defun message-is-yours-p ()
6642 "Non-nil means current article is yours.
6643 If you have added 'cancel-messages to 'message-shoot-gnksa-feet', all articles
6644 are yours except those that have Cancel-Lock header not belonging to you.
6645 Instead of shooting GNKSA feet, you should modify 'message-alternative-emails'
6646 regexp to match all of yours addresses."
6647 ;; Canlock-logic as suggested by Per Abrahamsen
6648 ;; <abraham@dina.kvl.dk>
6650 ;; IF article has cancel-lock THEN
6651 ;; IF we can verify it THEN
6654 ;; error: cancellock: article is not yours
6656 ;; Use old rules, comparing sender...
6659 (message-narrow-to-head-1)
6660 (if (message-fetch-field "Cancel-Lock")
6661 (if (null (canlock-verify))
6663 (error "Failed to verify Cancel-lock: This article is not yours"))
6666 (message-gnksa-enable-p 'cancel-messages)
6667 (and (setq sender (message-fetch-field "sender"))
6668 (string-equal (downcase sender)
6669 (downcase (message-make-sender))))
6670 ;; Email address in From field equals to our address
6671 (and (setq from (message-fetch-field "from"))
6673 (downcase (cadr (std11-extract-address-components from)))
6674 (downcase (cadr (std11-extract-address-components
6675 (message-make-from))))))
6676 ;; Email address in From field matches
6677 ;; 'message-alternative-emails' regexp
6679 message-alternative-emails
6681 message-alternative-emails
6682 (cadr (std11-extract-address-components from))))))))))
6685 (defun message-cancel-news (&optional arg)
6686 "Cancel an article you posted.
6687 If ARG, allow editing of the cancellation message."
6689 (unless (message-news-p)
6690 (error "This is not a news article; canceling is impossible"))
6691 (let (from newsgroups message-id distribution buf)
6693 ;; Get header info from original article.
6695 (message-narrow-to-head-1)
6696 (setq from (message-fetch-field "from")
6697 newsgroups (message-fetch-field "newsgroups")
6698 message-id (message-fetch-field "message-id" t)
6699 distribution (message-fetch-field "distribution")))
6700 ;; Make sure that this article was written by the user.
6701 (unless (message-is-yours-p)
6702 (error "This article is not yours"))
6703 (when (yes-or-no-p "Do you really want to cancel this article? ")
6704 ;; Make control message.
6707 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
6709 (insert "Newsgroups: " newsgroups "\n"
6711 "Subject: cmsg cancel " message-id "\n"
6712 "Control: cancel " message-id "\n"
6714 (concat "Distribution: " distribution "\n")
6716 mail-header-separator "\n"
6717 message-cancel-message)
6718 (run-hooks 'message-cancel-hook)
6720 (message "Canceling your article...")
6721 (if (let ((message-syntax-checks
6722 'dont-check-for-anything-just-trust-me)
6723 (message-encoding-buffer (current-buffer))
6724 (message-edit-buffer (current-buffer)))
6725 (message-send-news))
6726 (message "Canceling your article...done"))
6727 (kill-buffer buf))))))
6729 (defun message-supersede-setup-for-mime-edit ()
6730 (set (make-local-variable 'message-setup-hook) nil)
6734 (defun message-supersede ()
6735 "Start composing a message to supersede the current message.
6736 This is done simply by taking the old article and adding a Supersedes
6737 header line with the old Message-ID."
6739 (let ((cur (current-buffer)))
6740 ;; Check whether the user owns the article that is to be superseded.
6741 (unless (message-is-yours-p)
6742 (error "This article is not yours"))
6743 ;; Get a normal message buffer.
6744 (message-pop-to-buffer (message-buffer-name "supersede"))
6745 (insert-buffer-substring cur)
6746 (message-narrow-to-head-1)
6747 ;; Remove unwanted headers.
6748 (when message-ignored-supersedes-headers
6749 (message-remove-header message-ignored-supersedes-headers t))
6750 (goto-char (point-min))
6751 (if (not (re-search-forward "^Message-ID: " nil t))
6752 (error "No Message-ID in this article")
6753 (replace-match "Supersedes: " t t))
6754 (goto-char (point-max))
6755 (insert mail-header-separator)
6757 (when message-supersede-setup-function
6758 (funcall message-supersede-setup-function))
6759 (run-hooks 'message-supersede-setup-hook)
6760 (goto-char (point-min))
6761 (search-forward (concat "\n" mail-header-separator "\n") nil t)))
6764 (defun message-recover ()
6765 "Reread contents of current buffer from its last auto-save file."
6767 (let ((file-name (make-auto-save-file-name)))
6768 (cond ((save-window-excursion
6769 (if (not (eq system-type 'vax-vms))
6770 (with-output-to-temp-buffer "*Directory*"
6771 (with-current-buffer standard-output
6772 (fundamental-mode)) ; for Emacs 20.4+
6773 (buffer-disable-undo standard-output)
6774 (let ((default-directory "/"))
6776 "ls" nil standard-output nil "-l" file-name))))
6777 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
6778 (let ((buffer-read-only nil))
6780 (insert-file-contents file-name nil)))
6781 (t (error "message-recover cancelled")))))
6783 ;;; Washing Subject:
6785 (defun message-wash-subject (subject)
6786 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
6787 Previous forwarders, replyers, etc. may add it."
6790 (goto-char (point-min))
6791 ;; strip Re/Fwd stuff off the beginning
6792 (while (re-search-forward
6793 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
6796 ;; and gnus-style forwards [foo@bar.com] subject
6797 (goto-char (point-min))
6798 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
6802 (goto-char (point-max))
6803 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
6806 ;; and finally, any whitespace that was left-over
6807 (goto-char (point-min))
6808 (while (re-search-forward "^[ \t]+" nil t)
6810 (goto-char (point-max))
6811 (while (re-search-backward "[ \t]+$" nil t)
6816 ;;; Forwarding messages.
6818 (defvar message-forward-decoded-p nil
6819 "Non-nil means the original message is decoded.")
6821 (defun message-forward-subject-name-subject (subject)
6822 "Generate a SUBJECT for a forwarded message.
6823 The form is: [Source] Subject, where if the original message was mail,
6824 Source is the name of the sender, and if the original message was
6825 news, Source is the list of newsgroups is was posted to."
6827 (let ((group (message-fetch-field "newsgroups"))
6830 (gnus-group-decoded-name group)
6831 (or (and (setq from (message-fetch-field "from"))
6832 (car (std11-extract-address-components
6833 (nnheader-decode-from from))))
6837 (defun message-forward-subject-author-subject (subject)
6838 "Generate a SUBJECT for a forwarded message.
6839 The form is: [Source] Subject, where if the original message was mail,
6840 Source is the sender, and if the original message was news, Source is
6841 the list of newsgroups is was posted to."
6843 (let ((group (message-fetch-field "newsgroups"))
6846 (gnus-group-decoded-name group)
6847 (if (setq from (message-fetch-field "from"))
6848 (nnheader-decode-from from)
6852 (defun message-forward-subject-fwd (subject)
6853 "Generate a SUBJECT for a forwarded message.
6854 The form is: Fwd: Subject, where Subject is the original subject of
6856 (if (string-match "^Fwd: " subject)
6858 (concat "Fwd: " subject)))
6860 (defun message-make-forward-subject ()
6861 "Return a Subject header suitable for the message in the current buffer."
6864 (message-narrow-to-head-1)
6865 (let ((funcs message-make-forward-subject-function)
6866 (subject (message-fetch-field "Subject")))
6869 (if message-forward-decoded-p
6871 (nnheader-decode-subject subject))
6873 (when message-wash-forwarded-subjects
6874 (setq subject (message-wash-subject subject)))
6875 ;; Make sure funcs is a list.
6878 (setq funcs (list funcs)))
6879 ;; Apply funcs in order, passing subject generated by previous
6880 ;; func to the next one.
6881 (dolist (func funcs)
6882 (when (functionp func)
6883 (setq subject (funcall func subject))))
6887 (defun message-forward (&optional news)
6888 "Forward the current message via mail.
6889 Optional NEWS will use news to forward instead of mail."
6891 (let ((cur (current-buffer))
6892 (subject (message-make-forward-subject)))
6894 (message-news nil subject)
6895 (message-mail nil subject))
6896 (message-forward-make-body cur)))
6898 (defun message-forward-make-body-plain (forward-buffer)
6900 "\n-------------------- Start of forwarded message --------------------\n")
6901 (let ((b (point)) e)
6904 (mm-disable-multibyte)
6906 (with-current-buffer forward-buffer
6907 (mm-with-unibyte-current-buffer (buffer-string))))
6908 (mm-enable-multibyte)
6910 (goto-char (point-min))
6911 (when (looking-at "From ")
6912 (replace-match "X-From-Line: "))
6916 "\n-------------------- End of forwarded message --------------------\n")
6917 (when (and (not current-prefix-arg)
6918 message-forward-ignored-headers)
6920 (narrow-to-region b e)
6922 (narrow-to-region (point)
6923 (or (search-forward "\n\n" nil t) (point)))
6924 (message-remove-header message-forward-ignored-headers t)))))
6926 (defun message-forward-make-body-mime (forward-buffer)
6927 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
6928 (let ((b (point)) e)
6930 (narrow-to-region (point) (point))
6931 (mml-insert-buffer forward-buffer)
6932 (goto-char (point-min))
6933 (when (looking-at "From ")
6934 (replace-match "X-From-Line: "))
6935 (goto-char (point-max)))
6937 (insert "<#/part>\n")))
6939 (defun message-forward-make-body-mml (forward-buffer)
6940 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
6941 (let ((b (point)) e)
6942 (if (not message-forward-decoded-p)
6945 (mm-disable-multibyte)
6947 (with-current-buffer forward-buffer
6948 (mm-with-unibyte-current-buffer (buffer-string))))
6949 (mm-enable-multibyte)
6951 (goto-char (point-min))
6952 (when (looking-at "From ")
6953 (replace-match "X-From-Line: "))
6956 (narrow-to-region (point) (point))
6957 (mml-insert-buffer forward-buffer)
6958 (goto-char (point-min))
6959 (when (looking-at "From ")
6960 (replace-match "X-From-Line: "))
6961 (goto-char (point-max))))
6963 (insert "<#/mml>\n")
6964 (when (and (not current-prefix-arg)
6965 message-forward-ignored-headers)
6967 (narrow-to-region b e)
6969 (narrow-to-region (point)
6970 (or (search-forward "\n\n" nil t) (point)))
6971 (message-remove-header message-forward-ignored-headers t)))))
6973 (defun message-forward-make-body-digest-plain (forward-buffer)
6975 "\n-------------------- Start of forwarded message --------------------\n")
6976 (let ((b (point)) e)
6977 (mml-insert-buffer forward-buffer)
6980 "\n-------------------- End of forwarded message --------------------\n")))
6982 (defun message-forward-make-body-digest-mime (forward-buffer)
6983 (insert "\n<#multipart type=digest>\n")
6984 (let ((b (point)) e)
6985 (insert-buffer-substring forward-buffer)
6987 (insert "<#/multipart>\n")
6989 (narrow-to-region b e)
6991 (narrow-to-region (point)
6992 (or (search-forward "\n\n" nil t) (point)))
6993 (delete-region (point-min) (point-max)))))
6995 (defun message-forward-make-body-digest (forward-buffer)
6996 (if message-forward-as-mime
6997 (message-forward-make-body-digest-mime forward-buffer)
6998 (message-forward-make-body-digest-plain forward-buffer)))
7001 (defun message-forward-make-body (forward-buffer)
7002 ;; Put point where we want it before inserting the forwarded
7004 ;; Note that this function definition for T-gnus is totally different
7005 ;; from the original Gnus."
7006 (if message-forward-before-signature
7008 (goto-char (point-max)))
7009 ;; Make sure we're at the start of the line.
7012 ;; Narrow to the area we are to insert.
7013 (narrow-to-region (point) (point))
7014 ;; Insert the separators and the forwarded buffer.
7015 (insert message-forward-start-separator)
7016 (let ((art-beg (point)))
7017 (insert-buffer-substring forward-buffer)
7018 (goto-char (point-max))
7019 (insert message-forward-end-separator)
7020 (set-text-properties (point-min) (point-max) nil)
7021 ;; Remove all unwanted headers.
7023 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
7026 (goto-char (point-min))
7027 (message-remove-header message-included-forward-headers t nil t)
7029 (message-position-point)))
7032 (defun message-forward-rmail-make-body (forward-buffer)
7033 (save-window-excursion
7034 (set-buffer forward-buffer)
7035 (if (rmail-msg-is-pruned)
7036 (rmail-msg-restore-non-pruned-header)))
7037 (message-forward-make-body forward-buffer))
7039 (eval-when-compile (defvar rmail-enable-mime-composing))
7041 ;; Fixme: Should have defcustom.
7043 (defun message-insinuate-rmail ()
7044 "Let RMAIL use message to forward."
7046 (setq rmail-enable-mime-composing t)
7047 (setq rmail-insert-mime-forwarded-message-function
7048 'message-forward-rmail-make-body))
7051 (defun message-resend (address)
7052 "Resend the current article to ADDRESS."
7054 (list (message-read-from-minibuffer "Resend message to: ")))
7055 (message "Resending message to %s..." address)
7057 (let ((cur (current-buffer))
7059 ;; We first set up a normal mail buffer.
7060 (unless (message-mail-user-agent)
7061 (set-buffer (get-buffer-create " *message resend*"))
7063 (let ((message-this-is-mail t)
7065 (message-setup `((To . ,address))))
7066 ;; Insert our usual headers.
7067 (message-generate-headers '(From Date To Message-ID))
7068 (message-narrow-to-headers)
7069 ;; Remove X-Draft-From header etc.
7070 (message-remove-header message-ignored-mail-headers t)
7071 ;; Rename them all to "Resent-*".
7072 (goto-char (point-min))
7073 (while (re-search-forward "^[A-Za-z]" nil t)
7078 (delete-region (point) (point-max))
7080 ;; Insert the message to be resent.
7081 (insert-buffer-substring cur)
7082 (goto-char (point-min))
7083 (search-forward "\n\n")
7086 (narrow-to-region beg (point))
7087 (message-remove-header message-ignored-resent-headers t)
7088 (goto-char (point-max)))
7089 (insert mail-header-separator)
7090 ;; Rename all old ("Also-")Resent headers.
7091 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
7094 ;; Quote any "From " lines at the beginning.
7096 (when (looking-at "From ")
7097 (replace-match "X-From-Line: "))
7099 (let ((message-encoding-buffer (current-buffer))
7100 (message-edit-buffer (current-buffer))
7101 message-required-mail-headers)
7102 (message-send-mail))
7103 (kill-buffer (current-buffer)))
7104 (message "Resending message to %s...done" address)))
7106 (defun message-bounce-setup-for-mime-edit ()
7107 (set (make-local-variable 'message-setup-hook) nil)
7111 (defun message-bounce ()
7112 "Re-mail the current message.
7113 This only makes sense if the current message is a bounce message that
7114 contains some mail you have written which has been bounced back to
7117 (let ((cur (current-buffer))
7118 mime-boundary boundary)
7119 (message-pop-to-buffer (message-buffer-name "bounce"))
7120 (insert-buffer-substring cur)
7122 (message-narrow-to-head)
7123 (if (and (message-fetch-field "MIME-Version")
7124 (setq mime-boundary (message-fetch-field "Content-Type")))
7125 (if (string-match "boundary=\"\\([^\"]+\\)\"" mime-boundary)
7126 (setq mime-boundary (concat (regexp-quote
7127 (match-string 1 mime-boundary))
7128 " *\nContent-Type: message/rfc822"))
7129 (setq mime-boundary nil)))
7131 (goto-char (point-min))
7132 (re-search-forward "\n\n+" nil t)
7133 (setq boundary (point))
7134 ;; We remove everything before the bounced mail.
7135 (if (or (and mime-boundary
7136 (re-search-forward mime-boundary nil t)
7138 (re-search-forward message-unsent-separator nil t)
7140 (search-forward "\n\n" nil 'move)
7141 (re-search-backward "^Return-Path:.*\n" boundary t)))
7144 (delete-region (point-min)
7145 (if (re-search-forward "^[^ \n\t]+:" nil t)
7148 (when (re-search-backward "^.?From .*\n" nil t)
7149 (delete-region (match-beginning 0) (match-end 0))))
7151 (message-narrow-to-head-1)
7152 (message-remove-header message-ignored-bounced-headers t)
7153 (goto-char (point-max))
7154 (insert mail-header-separator))
7155 (when message-bounce-setup-function
7156 (funcall message-bounce-setup-function))
7157 (run-hooks 'message-bounce-setup-hook)
7158 (message-position-point)))
7161 ;;; Interactive entry points for new message buffers.
7165 (defun message-mail-other-window (&optional to subject)
7166 "Like `message-mail' command, but display mail buffer in another window."
7168 (unless (message-mail-user-agent)
7169 (let ((pop-up-windows t)
7170 (special-display-buffer-names nil)
7171 (special-display-regexps nil)
7172 (same-window-buffer-names nil)
7173 (same-window-regexps nil))
7174 (message-pop-to-buffer (message-buffer-name "mail" to))))
7175 (let ((message-this-is-mail t))
7176 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7177 nil nil 'switch-to-buffer-other-window)))
7180 (defun message-mail-other-frame (&optional to subject)
7181 "Like `message-mail' command, but display mail buffer in another frame."
7183 (unless (message-mail-user-agent)
7184 (let ((pop-up-frames t)
7185 (special-display-buffer-names nil)
7186 (special-display-regexps nil)
7187 (same-window-buffer-names nil)
7188 (same-window-regexps nil))
7189 (message-pop-to-buffer (message-buffer-name "mail" to))))
7190 (let ((message-this-is-mail t))
7191 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7192 nil nil 'switch-to-buffer-other-frame)))
7195 (defun message-news-other-window (&optional newsgroups subject)
7196 "Start editing a news article to be sent."
7198 (let ((pop-up-windows t)
7199 (special-display-buffer-names nil)
7200 (special-display-regexps nil)
7201 (same-window-buffer-names nil)
7202 (same-window-regexps nil))
7203 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
7204 (let ((message-this-is-news t))
7205 (message-setup `((Newsgroups . ,(or newsgroups ""))
7206 (Subject . ,(or subject ""))))))
7209 (defun message-news-other-frame (&optional newsgroups subject)
7210 "Start editing a news article to be sent."
7212 (let ((pop-up-frames t)
7213 (special-display-buffer-names nil)
7214 (special-display-regexps nil)
7215 (same-window-buffer-names nil)
7216 (same-window-regexps nil))
7217 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
7218 (let ((message-this-is-news t))
7219 (message-setup `((Newsgroups . ,(or newsgroups ""))
7220 (Subject . ,(or subject ""))))))
7224 ;; This code should be moved to underline.el (from which it is stolen).
7227 (defun bold-region (start end)
7228 "Bold all nonblank characters in the region.
7229 Works by overstriking characters.
7230 Called from program, takes two arguments START and END
7231 which specify the range to operate on."
7234 (let ((end1 (make-marker)))
7235 (move-marker end1 (max start end))
7236 (goto-char (min start end))
7237 (while (< (point) end1)
7238 (or (looking-at "[_\^@- ]")
7239 (insert (char-after) "\b"))
7240 (forward-char 1)))))
7243 (defun unbold-region (start end)
7244 "Remove all boldness (overstruck characters) in the region.
7245 Called from program, takes two arguments START and END
7246 which specify the range to operate on."
7249 (let ((end1 (make-marker)))
7250 (move-marker end1 (max start end))
7251 (goto-char (min start end))
7252 (while (search-forward "\b" end1 t)
7253 (if (eq (char-after) (char-after (- (point) 2)))
7254 (delete-char -2))))))
7256 (defun message-exchange-point-and-mark ()
7257 "Exchange point and mark, but don't activate region if it was inactive."
7259 (message-mark-active-p)
7260 (exchange-point-and-mark))
7261 (setq mark-active nil)))
7263 (defalias 'message-make-overlay 'make-overlay)
7264 (defalias 'message-delete-overlay 'delete-overlay)
7265 (defalias 'message-overlay-put 'overlay-put)
7266 (defun message-kill-all-overlays ()
7267 (if (featurep 'xemacs)
7268 (map-extents (lambda (extent ignore) (delete-extent extent)))
7269 (mapcar #'delete-overlay (overlays-in (point-min) (point-max)))))
7271 ;; Support for toolbar
7273 (defvar tool-bar-map)
7274 (defvar tool-bar-mode))
7276 (defun message-tool-bar-local-item-from-menu (command icon in-map &optional from-map &rest props)
7277 ;; We need to make tool bar entries in local keymaps with
7278 ;; `tool-bar-local-item-from-menu' in Emacs > 21.3
7279 (if (fboundp 'tool-bar-local-item-from-menu)
7280 ;; This is for Emacs 21.3
7281 (tool-bar-local-item-from-menu command icon in-map from-map props)
7282 (tool-bar-add-item-from-menu command icon from-map props)))
7284 (defun message-tool-bar-map ()
7285 (or message-tool-bar-map
7286 (setq message-tool-bar-map
7288 (condition-case nil (require 'tool-bar) (error nil))
7289 (fboundp 'tool-bar-add-item-from-menu)
7291 (let ((tool-bar-map (copy-keymap tool-bar-map))
7292 (load-path (mm-image-load-path)))
7293 ;; Zap some items which aren't so relevant and take
7295 (dolist (key '(print-buffer kill-buffer save-buffer
7296 write-file dired open-file))
7297 (define-key tool-bar-map (vector key) nil))
7298 (message-tool-bar-local-item-from-menu
7299 'message-send-and-exit "mail_send" tool-bar-map message-mode-map)
7300 (message-tool-bar-local-item-from-menu
7301 'message-kill-buffer "close" tool-bar-map message-mode-map)
7302 (message-tool-bar-local-item-from-menu
7303 'message-dont-send "cancel" tool-bar-map message-mode-map)
7304 ;; (message-tool-bar-local-item-from-menu
7305 ;; 'mime-edit-insert-file "attach"
7306 ;; tool-bar-map mime-edit-mode-map)
7307 (message-tool-bar-local-item-from-menu
7308 'ispell-message "spell" tool-bar-map message-mode-map)
7309 ;; (message-tool-bar-local-item-from-menu
7310 ;; 'mime-edit-preview-message "preview"
7311 ;; tool-bar-map mime-edit-mode-map)
7312 (message-tool-bar-local-item-from-menu
7313 'message-insert-importance-high "important"
7314 tool-bar-map message-mode-map)
7315 (message-tool-bar-local-item-from-menu
7316 'message-insert-importance-low "unimportant"
7317 tool-bar-map message-mode-map)
7318 (message-tool-bar-local-item-from-menu
7319 'message-insert-disposition-notification-to "receipt"
7320 tool-bar-map message-mode-map)
7323 ;;; Group name completion.
7325 (defcustom message-newgroups-header-regexp
7326 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
7327 "Regexp that match headers that lists groups."
7331 (defcustom message-completion-alist
7332 (list (cons message-newgroups-header-regexp 'message-expand-group)
7333 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name)
7334 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
7335 . message-expand-name)
7336 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
7337 . message-expand-name))
7338 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
7340 :type '(alist :key-type regexp :value-type function))
7342 (defcustom message-expand-name-databases
7343 (list 'bbdb 'eudc 'lsdb)
7344 "List of databases to try for name completion (`message-expand-name').
7345 Each element is a symbol and can be `bbdb', `eudc' or `lsdb'."
7347 :type '(set (const bbdb) (const eudc) (const lsdb)))
7349 (defcustom message-expand-name-function
7350 (cond ((and (boundp 'eudc-protocol)
7352 'eudc-expand-inline)
7353 ((fboundp 'bbdb-complete-name)
7354 'bbdb-complete-name)
7355 ((fboundp 'lsdb-complete-name)
7356 'lsdb-complete-name)
7358 "*A function called to expand addresses in field body.
7359 This variable is semi-obsolete, set it as nil and use
7360 `message-expand-name-databases' instead."
7362 :type '(radio (const :format "Invalidate it: %v\n" nil)
7363 (function-item :format "eudc: %v\n" eudc-expand-inline)
7364 (function-item :format "bbdb: %v\n" bbdb-complete-name)
7365 (function-item :format "lsdb: %v\n" lsdb-complete-name)
7366 (function :size 0 :value expand-abbrev)))
7368 (defcustom message-tab-body-function nil
7369 "*Function to execute when `message-tab' (TAB) is executed in the body.
7370 If nil, the function bound in `text-mode-map' or `global-map' is executed."
7373 :link '(custom-manual "(message)Various Commands")
7376 (defun message-tab ()
7377 "Complete names according to `message-completion-alist'.
7378 Execute function specified by `message-tab-body-function' when not in
7381 (let ((alist message-completion-alist))
7383 (let ((mail-abbrev-mode-regexp (caar alist)))
7384 (not (mail-abbrev-in-expansion-header-p))))
7385 (setq alist (cdr alist)))
7386 (funcall (or (cdar alist) message-tab-body-function
7387 (lookup-key text-mode-map "\t")
7388 (lookup-key global-map "\t")
7389 'indent-relative))))
7391 (defun message-expand-group ()
7392 "Expand the group name under point."
7393 (let* ((b (save-excursion
7398 (skip-chars-forward "^:")
7401 (skip-chars-backward "^, \t\n") (point))))
7402 (completion-ignore-case t)
7403 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
7405 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
7406 (completions (all-completions string hashtb))
7408 (delete-region b (point))
7410 ((= (length completions) 1)
7411 (if (string= (car completions) string)
7414 (message "Only matching group"))
7415 (insert (car completions))))
7416 ((and (setq comp (try-completion string hashtb))
7417 (not (string= comp string)))
7422 (message "No matching groups")
7423 (save-selected-window
7424 (pop-to-buffer "*Completions*")
7425 (buffer-disable-undo)
7426 (let ((buffer-read-only nil))
7428 (let ((standard-output (current-buffer)))
7429 (display-completion-list (sort completions 'string<)))
7430 (goto-char (point-min))
7431 (delete-region (point) (progn (forward-line 3) (point))))))))))
7433 (defun message-expand-name ()
7434 (cond (message-expand-name-function
7435 (funcall message-expand-name-function))
7436 ((and (memq 'eudc message-expand-name-databases)
7437 (boundp 'eudc-protocol)
7439 (eudc-expand-inline))
7440 ((and (memq 'bbdb message-expand-name-databases)
7441 (fboundp 'bbdb-complete-name))
7442 (bbdb-complete-name))
7443 ((and (memq 'lsdb message-expand-name-databases)
7444 (fboundp 'lsdb-complete-name))
7445 (lsdb-complete-name))
7446 (t 'expand-abbrev)))
7450 (defun message-talkative-question (ask question show &rest text)
7451 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
7452 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
7453 The following arguments may contain lists of values."
7455 (setq text (message-flatten-list text)))
7456 (save-window-excursion
7458 (with-output-to-temp-buffer " *MESSAGE information message*"
7459 (set-buffer " *MESSAGE information message*")
7460 (fundamental-mode) ; for Emacs 20.4+
7461 (mapcar 'princ text)
7462 (goto-char (point-min))))
7463 (funcall ask question))
7464 (funcall ask question)))
7466 (defun message-flatten-list (list)
7467 "Return a new, flat list that contains all elements of LIST.
7469 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
7472 (apply 'append (mapcar 'message-flatten-list list)))
7476 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
7477 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
7478 Then clone the local variables and values from the old buffer to the
7479 new one, cloning only the locals having a substring matching the
7481 (let ((oldbuf (current-buffer)))
7483 (set-buffer (generate-new-buffer name))
7484 (message-clone-locals oldbuf varstr)
7487 (defun message-clone-locals (buffer &optional varstr)
7488 "Clone the local variables from BUFFER to the current buffer."
7489 (let ((locals (save-excursion
7491 (buffer-local-variables)))
7492 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address\\|^user-full-name"))
7495 (when (and (consp local)
7497 (string-match regexp (symbol-name (car local)))
7499 (string-match varstr (symbol-name (car local)))))
7501 (set (make-local-variable (car local))
7505 ;;; @ for MIME Edit mode
7508 (defun message-maybe-encode ()
7509 (when message-mime-mode
7510 ;; Inherit the buffer local variable `mime-edit-pgp-processing'.
7511 (let ((pgp-processing (with-current-buffer message-edit-buffer
7512 mime-edit-pgp-processing)))
7513 (setq mime-edit-pgp-processing pgp-processing))
7514 (run-hooks 'mime-edit-translate-hook)
7515 (if (catch 'mime-edit-error
7517 (mime-edit-pgp-enclose-buffer)
7518 (mime-edit-translate-body)))
7519 (error "Translation error!"))
7520 (run-hooks 'mime-edit-exit-hook)))
7522 (defun message-mime-insert-article (&optional full-headers)
7524 (let ((message-cite-function 'mime-edit-inserted-message-filter)
7525 (message-reply-buffer
7526 (message-get-parameter-with-eval 'original-buffer))
7528 (message-yank-original nil)
7530 (narrow-to-region (goto-char start)
7531 (if (search-forward "\n\n" nil t)
7534 (goto-char (point-min))
7535 (let ((message-included-forward-headers
7536 (if full-headers "" message-included-forward-headers)))
7537 (message-remove-header message-included-forward-headers t nil t))
7540 (set-alist 'mime-edit-message-inserter-alist
7541 'message-mode (function message-mime-insert-article))
7547 (defvar message-inhibit-body-encoding t)
7549 (defun message-encode-message-body ()
7550 (unless message-inhibit-body-encoding
7551 (let ((mail-parse-charset (or mail-parse-charset
7552 message-default-charset))
7553 (case-fold-search t)
7554 lines content-type-p)
7557 (narrow-to-region (point) (point-max))
7558 (let ((new (mml-generate-mime)))
7560 (delete-region (point-min) (point-max))
7562 (goto-char (point-min))
7563 (if (eq (aref new 0) ?\n)
7565 (search-forward "\n\n")
7566 (setq lines (buffer-substring (point-min) (1- (point))))
7567 (delete-region (point-min) (point))))))
7569 (message-narrow-to-headers-or-head)
7570 (message-remove-header "Mime-Version")
7571 (goto-char (point-max))
7572 (insert "MIME-Version: 1.0\n")
7575 (setq content-type-p
7577 (re-search-backward "^Content-Type:" nil t))))
7579 (message-narrow-to-headers-or-head)
7580 (message-remove-first-header "Content-Type")
7581 (message-remove-first-header "Content-Transfer-Encoding"))
7582 ;; We always make sure that the message has a Content-Type
7583 ;; header. This is because some broken MTAs and MUAs get
7584 ;; awfully confused when confronted with a message with a
7585 ;; MIME-Version header and without a Content-Type header. For
7586 ;; instance, Solaris' /usr/bin/mail.
7587 (unless content-type-p
7588 (goto-char (point-min))
7589 ;; For unknown reason, MIME-Version doesn't exist.
7590 (when (re-search-forward "^MIME-Version:" nil t)
7592 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
7594 (defun message-read-from-minibuffer (prompt &optional initial-contents)
7595 "Read from the minibuffer while providing abbrev expansion."
7596 (if (fboundp 'mail-abbrevs-setup)
7597 (let ((mail-abbrev-mode-regexp "")
7598 (minibuffer-setup-hook 'mail-abbrevs-setup)
7599 (minibuffer-local-map message-minibuffer-local-map))
7600 (read-from-minibuffer prompt initial-contents))
7601 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
7602 (minibuffer-local-map message-minibuffer-local-map))
7603 (read-string prompt initial-contents))))
7605 (defun message-use-alternative-email-as-from ()
7606 (require 'mail-utils)
7607 (let* ((fields '("To" "Cc"))
7610 (mail-strip-quoted-names
7611 (mapconcat 'message-fetch-reply-field fields ","))
7615 (if (string-match message-alternative-emails (car emails))
7616 (setq email (car emails)
7619 (unless (or (not email) (equal email user-mail-address))
7620 (goto-char (point-max))
7621 (insert "From: " email "\n"))))
7623 (defun message-options-get (symbol)
7624 (cdr (assq symbol message-options)))
7626 (defun message-options-set (symbol value)
7627 (let ((the-cons (assq symbol message-options)))
7630 (setcdr the-cons value)
7631 (setq message-options (delq the-cons message-options)))
7633 (push (cons symbol value) message-options))))
7636 (defun message-options-set-recipient ()
7638 (message-narrow-to-headers-or-head)
7639 (message-options-set 'message-sender
7640 (mail-strip-quoted-names
7641 (message-fetch-field "from")))
7642 (message-options-set 'message-recipients
7643 (mail-strip-quoted-names
7644 (let ((to (message-fetch-field "to"))
7645 (cc (message-fetch-field "cc"))
7646 (bcc (message-fetch-field "bcc")))
7649 (if (and to cc) ", ")
7651 (if (and (or to cc) bcc) ", ")
7654 (defun message-hide-headers ()
7655 "Hide headers based on the `message-hidden-headers' variable."
7656 (let ((regexps (if (stringp message-hidden-headers)
7657 (list message-hidden-headers)
7658 message-hidden-headers))
7659 (inhibit-point-motion-hooks t)
7660 (after-change-functions nil))
7664 (message-narrow-to-headers)
7665 (goto-char (point-min))
7667 (if (not (message-hide-header-p regexps))
7668 (message-next-header)
7669 (let ((begin (point)))
7670 (message-next-header)
7671 (add-text-properties
7673 '(invisible t message-hidden t))))))))))
7675 (defun message-hide-header-p (regexps)
7678 (when (eq (car regexps) 'not)
7681 (dolist (regexp regexps)
7682 (setq result (or result (looking-at regexp))))
7687 (when (featurep 'xemacs)
7688 (require 'messagexmas)
7689 (message-xmas-redefine))
7693 (run-hooks 'message-load-hook)
7696 ;; coding: iso-8859-1
7699 ;;; message.el ends here