1 ;;; message.el --- composing mail and news messages -*- coding: iso-latin-1 -*-
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
8 ;; Keiichi Suzuki <kei-suzu@mail.wbs.ne.jp>
9 ;; Tatsuya Ichikawa <t-ichi@po.shiojiri.ne.jp>
10 ;; Katsumi Yamaoka <yamaoka@jpl.org>
11 ;; Kiyokazu SUTO <suto@merry.xmath.ous.ac.jp>
12 ;; Keywords: mail, news, MIME
14 ;; This file is part of GNU Emacs.
16 ;; GNU Emacs is free software; you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation; either version 2, or (at your option)
21 ;; GNU Emacs is distributed in the hope that it will be useful,
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;; GNU General Public License for more details.
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs; see the file COPYING. If not, write to the
28 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
29 ;; Boston, MA 02111-1307, USA.
33 ;; This mode provides mail-sending facilities from within Emacs. It
34 ;; consists mainly of large chunks of code from the sendmail.el,
35 ;; gnus-msg.el and rnewspost.el files.
42 (defvar gnus-list-identifiers)) ; gnus-sum is required where necessary
45 ;; This is apparently necessary even though things are autoloaded:
46 (if (featurep 'xemacs)
47 (require 'mail-abbrevs))
49 (eval-when-compile (require 'static))
51 ;; Avoid byte-compile warnings.
56 (defgroup message '((user-mail-address custom-variable)
57 (user-full-name custom-variable))
58 "Mail and news message composing."
59 :link '(custom-manual "(message)Top")
63 (put 'user-mail-address 'custom-type 'string)
64 (put 'user-full-name 'custom-type 'string)
66 (defgroup message-various nil
67 "Various Message Variables"
68 :link '(custom-manual "(message)Various Message Variables")
71 (defgroup message-buffers nil
73 :link '(custom-manual "(message)Message Buffers")
76 (defgroup message-sending nil
78 :link '(custom-manual "(message)Sending Variables")
81 (defgroup message-interface nil
83 :link '(custom-manual "(message)Interface")
86 (defgroup message-forwarding nil
88 :link '(custom-manual "(message)Forwarding")
89 :group 'message-interface)
91 (defgroup message-insertion nil
93 :link '(custom-manual "(message)Insertion")
96 (defgroup message-headers nil
98 :link '(custom-manual "(message)Message Headers")
101 (defgroup message-news nil
102 "Composing News Messages"
105 (defgroup message-mail nil
106 "Composing Mail Messages"
109 (defgroup message-faces nil
110 "Faces used for message composing."
114 (defgroup message-frames nil
118 (defcustom message-directory "~/Mail/"
119 "*Directory from which all other mail file variables are derived."
120 :group 'message-various
123 (defcustom message-max-buffers 10
124 "*How many buffers to keep before starting to kill them off."
125 :group 'message-buffers
128 (defcustom message-send-rename-function nil
129 "Function called to rename the buffer after sending it."
130 :group 'message-buffers
131 :type '(choice function (const nil)))
133 (defcustom message-fcc-handler-function 'message-output
134 "*A function called to save outgoing articles.
135 This function will be called with the name of the file to store the
136 article in. The default function is `message-output' which saves in Unix
138 :type '(radio (function-item message-output)
139 (function :tag "Other"))
140 :group 'message-sending)
142 (defcustom message-encode-function 'message-maybe-encode
143 "*A function called to encode messages."
144 :group 'message-sending
147 (defcustom message-8bit-encoding-list '(8bit binary)
148 "*8bit encoding type in Content-Transfer-Encoding field."
149 :group 'message-sending
150 :type '(repeat (symbol :tag "Type")))
152 (defcustom message-courtesy-message
153 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
154 "*This is inserted at the start of a mailed copy of a posted message.
155 If the string contains the format spec \"%s\", the Newsgroups
156 the article has been posted to will be inserted there.
157 If this variable is nil, no such courtesy message will be added."
158 :group 'message-sending
161 (defcustom message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):"
162 "*Regexp that matches headers to be removed in resent bounced mail."
163 :group 'message-interface
166 (defcustom message-bounce-setup-function 'message-bounce-setup-for-mime-edit
167 "Function to setup a re-sending bounced message."
168 :group 'message-sending
172 (defcustom message-from-style 'default
173 "*Specifies how \"From\" headers look.
175 If nil, they contain just the return address like:
177 If `parens', they look like:
178 king@grassland.com (Elvis Parsley)
179 If `angles', they look like:
180 Elvis Parsley <king@grassland.com>
182 Otherwise, most addresses look like `angles', but they look like
183 `parens' if `angles' would need quoting and `parens' would not."
184 :type '(choice (const :tag "simple" nil)
188 :group 'message-headers)
190 (defcustom message-syntax-checks nil
191 ;; Guess this one shouldn't be easy to customize...
192 "*Controls what syntax checks should not be performed on outgoing posts.
193 To disable checking of long signatures, for instance, add
194 `(signature . disabled)' to this list.
196 Don't touch this variable unless you really know what you're doing.
198 Checks include `subject-cmsg', `multiple-headers', `sendsys',
199 `message-id', `from', `long-lines', `control-chars', `size',
200 `new-text', `quoting-style', `redirected-followup', `signature',
201 `approved', `sender', `empty', `empty-headers', `message-id', `from',
202 `subject', `shorten-followup-to', `existing-newsgroups',
203 `buffer-file-name', `unchanged', `newsgroups'."
205 :type '(repeat sexp)) ; Fixme: improve this
207 (defcustom message-required-news-headers
208 '(From Newsgroups Subject Date Message-ID
209 (optional . Organization) Lines
210 (optional . User-Agent))
211 "*Headers to be generated or prompted for when posting an article.
212 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
213 Message-ID. Organization, Lines, In-Reply-To, Expires, and
214 User-Agent are optional. If don't you want message to insert some
215 header, remove it from this list."
217 :group 'message-headers
218 :type '(repeat sexp))
220 (defcustom message-required-mail-headers
221 '(From Subject Date (optional . In-Reply-To) Message-ID Lines
222 (optional . User-Agent))
223 "*Headers to be generated or prompted for when mailing a message.
224 RFC822 required that From, Date, To, Subject and Message-ID be
225 included. Organization, Lines and User-Agent are optional."
227 :group 'message-headers
228 :type '(repeat sexp))
230 (defcustom message-deletable-headers '(Message-ID Date Lines)
231 "Headers to be deleted if they already exist and were generated by message previously."
232 :group 'message-headers
235 (defcustom message-ignored-news-headers
236 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:"
237 "*Regexp of headers to be removed unconditionally before posting."
239 :group 'message-headers
242 (defcustom message-ignored-mail-headers
243 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:"
244 "*Regexp of headers to be removed unconditionally before mailing."
246 :group 'message-headers
249 (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:"
250 "*Header lines matching this regexp will be deleted before posting.
251 It's best to delete old Path and Date headers before posting to avoid
253 :group 'message-interface
256 (defcustom message-supersede-setup-function
257 'message-supersede-setup-for-mime-edit
258 "Function to setup a supersede message."
259 :group 'message-sending
262 (defcustom message-subject-re-regexp "^[ \t]*\\([Rr][Ee]:[ \t]*\\)*[ \t]*"
263 "*Regexp matching \"Re: \" in the subject line."
264 :group 'message-various
267 ;;; Some sender agents encode the whole subject including leading "Re: ".
268 ;;; And if followup agent does not decode it for some reason (e.g. unknown
269 ;;; charset) and just add a new "Re: " in front of the encoded-word, the
270 ;;; result will contain multiple "Re: "'s.
271 (defcustom message-subject-encoded-re-regexp
275 "[-!#$%&'*+0-9A-Z^_`a-z{|}~]+" ; charset
278 "[Bb]" (regexp-quote "?") ; B encoding
279 "\\(\\(CQk\\|CSA\\|IAk\\|ICA\\)[Jg]\\)*" ; \([ \t][ \t][ \t]\)*
281 "[Uc][km]U6" ; [Rr][Ee]:
283 "\\(C[VX]\\|I[FH]\\)J[Fl]O[g-v]" ; [ \t][Rr][Ee]:
285 "\\(CQl\\|CSB\\|IAl\\|ICB\\)[Sy][RZ]T[o-r]" ; [ \t][ \t][Rr][Ee]:
288 "[Qb]" (regexp-quote "?") ; Q encoding
289 "\\(_\\|=09\\|=20\\)*"
290 "\\([Rr]\\|=[57]2\\)\\([Ee]\\|=[46]5\\)\\(:\\|=3[Aa]\\)"
293 "*Regexp matching \"Re: \" in the subject line.
294 Unlike `message-subject-re-regexp', this regexp matches \"Re: \" within
296 :group 'message-various
299 (defcustom message-use-subject-re t
300 "*If t, remove any (buggy) \"Re: \"'s from the subject of the precursor
301 and add a new \"Re: \". If it is nil, use the subject \"as-is\". If it
302 is the symbol `guess', try to detect \"Re: \" within an encoded-word."
303 :group 'message-various
304 :type '(choice (const :tag "off" nil)
309 (defcustom message-signature-separator "^-- *$"
310 "Regexp matching the signature separator."
312 :group 'message-various)
314 (defcustom message-elide-ellipsis "\n[...]\n\n"
315 "*The string which is inserted for elided text."
317 :group 'message-various)
319 (defcustom message-interactive nil
320 "Non-nil means when sending a message wait for and display errors.
321 nil means let mailer mail back a message to report errors."
322 :group 'message-sending
326 (defcustom message-generate-new-buffers 'unique
327 "*Non-nil means create a new message buffer whenever `message-setup' is called.
328 If this is a function, call that function with three parameters: The type,
329 the to address and the group name. (Any of these may be nil.) The function
330 should return the new buffer name."
331 :group 'message-buffers
332 :type '(choice (const :tag "off" nil)
333 (const :tag "unique" unique)
334 (const :tag "unsent" unsent)
337 (defcustom message-kill-buffer-on-exit nil
338 "*Non-nil means that the message buffer will be killed after sending a message."
339 :group 'message-buffers
342 (defcustom message-kill-buffer-query-function 'yes-or-no-p
343 "*A function called to query the user whether to kill buffer anyway or not.
344 If it is t, the buffer will be killed peremptorily."
345 :type '(radio (function-item yes-or-no-p)
346 (function-item y-or-n-p)
347 (function-item nnheader-Y-or-n-p)
348 (function :tag "Other" t))
349 :group 'message-buffers)
352 (defvar gnus-local-organization))
353 (defcustom message-user-organization
354 (or (and (boundp 'gnus-local-organization)
355 (stringp gnus-local-organization)
356 gnus-local-organization)
357 (getenv "ORGANIZATION")
359 "*String to be used as an Organization header.
360 If t, use `message-user-organization-file'."
361 :group 'message-headers
362 :type '(choice string
363 (const :tag "consult file" t)))
366 (defcustom message-user-organization-file "/usr/lib/news/organization"
367 "*Local news organization file."
369 :group 'message-headers)
371 (defcustom message-forward-start-separator
372 (concat (mime-make-tag "message" "rfc822") "\n")
373 "*Delimiter inserted before forwarded messages."
374 :group 'message-forwarding
377 (defcustom message-forward-end-separator
378 (concat (mime-make-tag "text" "plain") "\n")
379 "*Delimiter inserted after forwarded messages."
380 :group 'message-forwarding
383 (defcustom message-included-forward-headers
384 "^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:"
385 "*Regexp matching headers to be included in forwarded messages."
386 :group 'message-forwarding
389 (defcustom message-make-forward-subject-function
390 'message-forward-subject-author-subject
391 "*List of functions called to generate subject headers for forwarded messages.
392 The subject generated by the previous function is passed into each
395 The provided functions are:
397 * `message-forward-subject-author-subject' (Source of article (author or
398 newsgroup)), in brackets followed by the subject
399 * `message-forward-subject-fwd' (Subject of article with 'Fwd:' prepended
401 :group 'message-forwarding
402 :type '(radio (function-item message-forward-subject-author-subject)
403 (function-item message-forward-subject-fwd)
404 (repeat :tag "List of functions" function)))
406 (defcustom message-forward-as-mime t
407 "*If non-nil, forward messages as an inline/rfc822 MIME section. Otherwise, directly inline the old message in the forwarded message."
409 :group 'message-forwarding
412 (defcustom message-forward-show-mml t
413 "*If non-nil, forward messages are shown as mml. Otherwise, forward messages are unchanged."
415 :group 'message-forwarding
418 (defcustom message-forward-before-signature t
419 "*If non-nil, put forwarded message before signature, else after."
420 :group 'message-forwarding
423 (defcustom message-wash-forwarded-subjects nil
424 "*If non-nil, try to remove as much old cruft as possible from the subject of messages before generating the new subject of a forward."
425 :group 'message-forwarding
428 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:"
429 "*All headers that match this regexp will be deleted when resending a message."
430 :group 'message-interface
433 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
434 "*All headers that match this regexp will be deleted when forwarding a message."
436 :group 'message-forwarding
437 :type '(choice (const :tag "None" nil)
440 (defcustom message-ignored-cited-headers "."
441 "*Delete these headers from the messages you yank."
442 :group 'message-insertion
445 (defcustom message-cite-prefix-regexp
446 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
447 "\\([ \t]*[-_.[:word:]]+>+\\|[ \t]*[]>»|:}+]\\)+"
448 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
449 "\\([ \t]*\\(\\w\\|[-_.]\\)+>+\\|[ \t]*[]>»|:}+]\\)+")
450 "*Regexp matching the longest possible citation prefix on a line."
451 :group 'message-insertion
454 (defcustom message-cancel-message "I am canceling my own article.\n"
455 "Message to be inserted in the cancel message."
456 :group 'message-interface
459 ;; Useful to set in site-init.el
461 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
462 "Function to call to send the current buffer as mail.
463 The headers should be delimited by a line whose contents match the
464 variable `mail-header-separator'.
466 Valid values include `message-send-mail-with-sendmail' (the default),
467 `message-send-mail-with-mh', `message-send-mail-with-qmail',
468 `message-send-mail-with-smtp', `smtpmail-send-it' and `feedmail-send-it'.
470 See also `send-mail-function'."
471 :type '(radio (function-item message-send-mail-with-sendmail)
472 (function-item message-send-mail-with-mh)
473 (function-item message-send-mail-with-qmail)
474 (function-item message-send-mail-with-smtp)
475 (function-item smtpmail-send-it)
476 (function-item feedmail-send-it)
477 (function :tag "Other"))
478 :group 'message-sending
479 :group 'message-mail)
481 ;; 1997-09-29 by MORIOKA Tomohiko
482 (defcustom message-send-news-function 'message-send-news-with-gnus
483 "Function to call to send the current buffer as news.
484 The headers should be delimited by a line whose contents match the
485 variable `mail-header-separator'."
486 :group 'message-sending
490 (defcustom message-reply-to-function nil
491 "If non-nil, function that should return a list of headers.
492 This function should pick out addresses from the To, Cc, and From headers
493 and respond with new To and Cc headers."
494 :group 'message-interface
495 :type '(choice function (const nil)))
497 (defcustom message-wide-reply-to-function nil
498 "If non-nil, function that should return a list of headers.
499 This function should pick out addresses from the To, Cc, and From headers
500 and respond with new To and Cc headers."
501 :group 'message-interface
502 :type '(choice function (const nil)))
504 (defcustom message-followup-to-function nil
505 "If non-nil, function that should return a list of headers.
506 This function should pick out addresses from the To, Cc, and From headers
507 and respond with new To and Cc headers."
508 :group 'message-interface
509 :type '(choice function (const nil)))
511 (defcustom message-use-followup-to 'ask
512 "*Specifies what to do with Followup-To header.
513 If nil, always ignore the header. If it is t, use its value, but
514 query before using the \"poster\" value. If it is the symbol `ask',
515 always query the user whether to use the value. If it is the symbol
516 `use', always use the value."
517 :group 'message-interface
518 :type '(choice (const :tag "ignore" nil)
519 (const :tag "maybe" t)
520 (const :tag "always" use)
521 (const :tag "ask" ask)))
523 (defcustom message-use-mail-copies-to 'ask
524 "*Specifies what to do with Mail-Copies-To header.
525 If nil, always ignore the header. If it is t, use its value, but
526 query before using the value other than \"always\" or \"never\".
527 If it is the symbol `ask', always query the user whether to use
528 the value. If it is the symbol `use', always use the value."
529 :group 'message-interface
530 :type '(choice (const :tag "ignore" nil)
531 (const :tag "maybe" t)
532 (const :tag "always" use)
533 (const :tag "ask" ask)))
535 (defcustom message-use-mail-followup-to 'ask
536 "*Specifies what to do with Mail-Followup-To header.
537 If nil, always ignore the header. If it is the symbol `ask', always
538 query the user whether to use the value. If it is t or the symbol
539 `use', always use the value."
540 :group 'message-interface
541 :type '(choice (const :tag "ignore" nil)
542 (const :tag "maybe" t)
543 (const :tag "always" use)
544 (const :tag "ask" ask)))
546 ;;; XXX: 'ask and 'use are not implemented yet.
547 (defcustom message-use-mail-reply-to 'ask
548 "*Specifies what to do with Mail-Reply-To/Reply-To header.
549 If nil, always ignore the header. If it is t or the symbol `use', use
550 its value. If it is the symbol `ask', always query the user whether to
551 use the value. Note that if \"Reply-To\" is marked as \"broken\", its value
553 :group 'message-interface
554 :type '(choice (const :tag "ignore" nil)
555 (const :tag "maybe" t)
556 (const :tag "always" use)
557 (const :tag "ask" ask)))
559 (defcustom message-sendmail-f-is-evil nil
560 "*Non-nil means don't add \"-f username\" to the sendmail command line.
561 Doing so would be even more evil than leaving it out."
562 :group 'message-sending
565 ;; qmail-related stuff
566 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
567 "Location of the qmail-inject program."
568 :group 'message-sending
571 (defcustom message-qmail-inject-args nil
572 "Arguments passed to qmail-inject programs.
573 This should be a list of strings, one string for each argument.
575 For e.g., if you wish to set the envelope sender address so that bounces
576 go to the right place or to deal with listserv's usage of that address, you
577 might set this variable to '(\"-f\" \"you@some.where\")."
578 :group 'message-sending
579 :type '(repeat string))
581 (defvar message-cater-to-broken-inn t
582 "Non-nil means Gnus should not fold the `References' header.
583 Folding `References' makes ancient versions of INN create incorrect
587 (defvar gnus-post-method)
588 (defvar gnus-select-method))
589 (defcustom message-post-method
590 (cond ((and (boundp 'gnus-post-method)
591 (listp gnus-post-method)
594 ((boundp 'gnus-select-method)
597 "*Method used to post news.
598 Note that when posting from inside Gnus, for instance, this
599 variable isn't used."
601 :group 'message-sending
602 ;; This should be the `gnus-select-method' widget, but that might
603 ;; create a dependence to `gnus.el'.
606 (defcustom message-generate-headers-first nil
607 "*If non-nil, generate all required headers before composing.
608 The variables `message-required-news-headers' and
609 `message-required-mail-headers' specify which headers to generate.
611 Note that the variable `message-deletable-headers' specifies headers which
612 are to be deleted and then re-generated before sending, so this variable
613 will not have a visible effect for those headers."
614 :group 'message-headers
617 (defcustom message-setup-hook '(turn-on-mime-edit)
618 "Normal hook, run each time a new outgoing message is initialized.
619 The function `message-setup' runs this hook."
620 :group 'message-various
623 (defcustom message-cancel-hook nil
624 "Hook run when cancelling articles."
625 :group 'message-various
628 (defcustom message-signature-setup-hook nil
629 "Normal hook, run each time a new outgoing message is initialized.
630 It is run after the headers have been inserted and before
631 the signature is inserted."
632 :group 'message-various
635 (defcustom message-bounce-setup-hook nil
636 "Normal hook, run each time a re-sending bounced message is initialized.
637 The function `message-bounce' runs this hook."
638 :group 'message-various
641 (defcustom message-supersede-setup-hook nil
642 "Normal hook, run each time a supersede message is initialized.
643 The function `message-supersede' runs this hook."
644 :group 'message-various
647 (defcustom message-mode-hook nil
648 "Hook run in message mode buffers."
649 :group 'message-various
652 (defcustom message-header-hook '((lambda () (eword-encode-header t)))
653 "Hook run in a message mode buffer narrowed to the headers."
654 :group 'message-various
657 (defcustom message-header-setup-hook nil
658 "Hook called narrowed to the headers when setting up a message buffer."
659 :group 'message-various
662 (defcustom message-minibuffer-local-map
663 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
664 (set-keymap-parent map minibuffer-local-map)
666 "Keymap for `message-read-from-minibuffer'.")
669 (defcustom message-citation-line-function 'message-insert-citation-line
670 "*Function called to insert the \"Whomever writes:\" line."
672 :group 'message-insertion)
675 (defcustom message-yank-prefix "> "
676 "*Prefix inserted on the lines of yanked messages.
677 Fix `message-cite-prefix-regexp' if it is set to an abnormal value."
679 :group 'message-insertion)
681 (defcustom message-yank-add-new-references t
682 "Non-nil means new IDs will be added to \"References\" field when an
683 article is yanked by the command `message-yank-original' interactively.
684 If it is a symbol `message-id-only', only an ID from \"Message-ID\" field
685 is used, otherwise IDs extracted from \"References\", \"In-Reply-To\" and
686 \"Message-ID\" fields are used."
687 :type '(radio (const :tag "Do not add anything" nil)
688 (const :tag "From Message-Id, References and In-Reply-To fields" t)
689 (const :tag "From only Message-Id field." message-id-only))
690 :group 'message-insertion)
692 (defcustom message-list-references-add-position nil
693 "Integer value means position for adding to \"References\" field when
694 an article is yanked by the command `message-yank-original' interactively."
695 :type '(radio (const :tag "Add to last" nil)
696 (integer :tag "Position from last ID"))
697 :group 'message-insertion)
699 (defcustom message-indentation-spaces 3
700 "*Number of spaces to insert at the beginning of each cited line.
701 Used by `message-yank-original' via `message-yank-cite'."
702 :group 'message-insertion
706 (defcustom message-cite-function 'message-cite-original
707 "*Function for citing an original message.
708 Predefined functions include `message-cite-original' and
709 `message-cite-original-without-signature'.
710 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
711 :type '(radio (function-item message-cite-original)
712 (function-item message-cite-original-without-signature)
713 (function-item mu-cite-original)
714 (function-item sc-cite-original)
715 (function :tag "Other"))
716 :group 'message-insertion)
719 (defcustom message-indent-citation-function 'message-indent-citation
720 "*Function for modifying a citation just inserted in the mail buffer.
721 This can also be a list of functions. Each function can find the
722 citation between (point) and (mark t). And each function should leave
723 point and mark around the citation text as modified."
725 :group 'message-insertion)
727 (defvar message-abbrevs-loaded nil)
730 (defcustom message-signature t
731 "*String to be inserted at the end of the message buffer.
732 If t, the `message-signature-file' file will be inserted instead.
733 If a function, the result from the function will be used instead.
734 If a form, the result from the form will be used instead."
736 :group 'message-insertion)
739 (defcustom message-signature-file "~/.signature"
740 "*Name of file containing the text inserted at end of message buffer.
741 Ignored if the named file doesn't exist.
742 If nil, don't insert a signature."
743 :type '(choice file (const :tags "None" nil))
744 :group 'message-insertion)
746 (defcustom message-distribution-function nil
747 "*Function called to return a Distribution header."
749 :group 'message-headers
750 :type '(choice function (const nil)))
752 (defcustom message-expires 14
753 "Number of days before your article expires."
755 :group 'message-headers
756 :link '(custom-manual "(message)News Headers")
759 (defcustom message-user-path nil
760 "If nil, use the NNTP server name in the Path header.
761 If stringp, use this; if non-nil, use no host name (user name only)."
763 :group 'message-headers
764 :link '(custom-manual "(message)News Headers")
765 :type '(choice (const :tag "nntp" nil)
767 (sexp :tag "none" :format "%t" t)))
769 (defvar message-reply-buffer nil)
770 (defvar message-reply-headers nil)
771 (defvar message-sent-message-via nil)
772 (defvar message-checksum nil)
773 (defvar message-send-actions nil
774 "A list of actions to be performed upon successful sending of a message.")
775 (defvar message-exit-actions nil
776 "A list of actions to be performed upon exiting after sending a message.")
777 (defvar message-kill-actions nil
778 "A list of actions to be performed before killing a message buffer.")
779 (defvar message-postpone-actions nil
780 "A list of actions to be performed after postponing a message.")
781 (defvar message-original-frame nil)
782 (defvar message-parameter-alist nil)
783 (defvar message-startup-parameter-alist nil)
785 (define-widget 'message-header-lines 'text
786 "All header lines must be LFD terminated."
787 :format "%{%t%}:%n%v"
789 :error "All header lines must be newline terminated")
791 (defcustom message-default-headers ""
792 "*A string containing header lines to be inserted in outgoing messages.
793 It is inserted before you edit the message, so you can edit or delete
795 :group 'message-headers
796 :type 'message-header-lines)
798 (defcustom message-default-mail-headers ""
799 "*A string of header lines to be inserted in outgoing mails."
800 :group 'message-headers
802 :type 'message-header-lines)
804 (defcustom message-default-news-headers ""
805 "*A string of header lines to be inserted in outgoing news articles."
806 :group 'message-headers
808 :type 'message-header-lines)
810 ;; Note: could use /usr/ucb/mail instead of sendmail;
811 ;; options -t, and -v if not interactive.
812 (defcustom message-mailer-swallows-blank-line
813 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
814 system-configuration)
815 (file-readable-p "/etc/sendmail.cf")
816 (let ((buffer (get-buffer-create " *temp*")))
820 (insert-file-contents "/etc/sendmail.cf")
821 (goto-char (point-min))
822 (let ((case-fold-search nil))
823 (re-search-forward "^OR\\>" nil t)))
824 (kill-buffer buffer))))
825 ;; According to RFC822, "The field-name must be composed of printable
826 ;; ASCII characters (i. e., characters that have decimal values between
827 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
829 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
830 "*Set this non-nil if the system's mailer runs the header and body together.
831 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
832 The value should be an expression to test whether the problem will
834 :group 'message-sending
837 ;;; XXX: This symbol is overloaded! See below.
838 (defvar message-user-agent nil
839 "String of the form of PRODUCT/VERSION. Used for User-Agent header field.")
841 (static-when (boundp 'MULE)
842 (require 'reporter));; `define-mail-user-agent' is here.
845 (define-mail-user-agent 'message-user-agent
846 'message-mail 'message-send-and-exit
847 'message-kill-buffer 'message-send-hook)
849 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
850 "If non-nil, delete the deletable headers before feeding to mh.")
852 (defvar message-send-method-alist
853 '((news message-news-p message-send-via-news)
854 (mail message-mail-p message-send-via-mail))
855 "Alist of ways to send outgoing messages.
856 Each element has the form
858 \(TYPE PREDICATE FUNCTION)
860 where TYPE is a symbol that names the method; PREDICATE is a function
861 called without any parameters to determine whether the message is
862 a message of type TYPE; and FUNCTION is a function to be called if
863 PREDICATE returns non-nil. FUNCTION is called with one parameter --
866 (defcustom message-mail-alias-type 'abbrev
867 "*What alias expansion type to use in Message buffers.
868 The default is `abbrev', which uses mailabbrev. nil switches
871 :link '(custom-manual "(message)Mail Aliases")
872 :type '(choice (const :tag "Use Mailabbrev" abbrev)
873 (const :tag "No expansion" nil)))
875 (defcustom message-auto-save-directory
876 (file-name-as-directory (nnheader-concat message-directory "drafts"))
877 "*Directory where Message auto-saves buffers if Gnus isn't running.
878 If nil, Message won't auto-save."
879 :group 'message-buffers
880 :type '(choice directory (const :tag "Don't auto-save" nil)))
882 (defcustom message-buffer-naming-style 'unique
883 "*The way new message buffers are named.
884 Valid valued are `unique' and `unsent'."
886 :group 'message-buffers
887 :type '(choice (const :tag "unique" unique)
888 (const :tag "unsent" unsent)))
890 (defcustom message-default-charset
891 (and (featurep 'xemacs) (not (featurep 'mule)) 'iso-8859-1)
892 "Default charset used in non-MULE XEmacsen."
897 (defcustom message-dont-reply-to-names
898 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
899 "*A regexp specifying names to prune when doing wide replies.
900 A value of nil means exclude your own name only."
903 :type '(choice (const :tag "Yourself" nil)
906 (defvar message-shoot-gnksa-feet nil
907 "*A list of GNKSA feet you are allowed to shoot.
908 Gnus gives you all the opportunity you could possibly want for
909 shooting yourself in the foot. Also, Gnus allows you to shoot the
910 feet of Good Net-Keeping Seal of Approval. The following are foot
912 `empty-article' Allow you to post an empty article;
913 `quoted-text-only' Allow you to post quoted text only;
914 `multiple-copies' Allow you to post multiple copies.")
915 ;; `cancel-messages' Allow you to cancel or supersede others' messages.
917 (defsubst message-gnksa-enable-p (feature)
918 (or (not (listp message-shoot-gnksa-feet))
919 (memq feature message-shoot-gnksa-feet)))
921 ;;; Internal variables.
922 ;;; Well, not really internal.
924 (defvar message-mode-syntax-table
925 (let ((table (copy-syntax-table text-mode-syntax-table)))
926 (modify-syntax-entry ?% ". " table)
927 (modify-syntax-entry ?> ". " table)
928 (modify-syntax-entry ?< ". " table)
930 "Syntax table used while in Message mode.")
932 (defvar message-mode-abbrev-table text-mode-abbrev-table
933 "Abbrev table used in Message mode buffers.
934 Defaults to `text-mode-abbrev-table'.")
936 (defface message-header-to-face
939 (:foreground "green2" :bold t))
942 (:foreground "MidnightBlue" :bold t))
944 (:bold t :italic t)))
945 "Face used for displaying From headers."
946 :group 'message-faces)
948 (defface message-header-cc-face
951 (:foreground "green4" :bold t))
954 (:foreground "MidnightBlue"))
957 "Face used for displaying Cc headers."
958 :group 'message-faces)
960 (defface message-header-subject-face
963 (:foreground "green3"))
966 (:foreground "navy blue" :bold t))
969 "Face used for displaying subject headers."
970 :group 'message-faces)
972 (defface message-header-newsgroups-face
975 (:foreground "yellow" :bold t :italic t))
978 (:foreground "blue4" :bold t :italic t))
980 (:bold t :italic t)))
981 "Face used for displaying newsgroups headers."
982 :group 'message-faces)
984 (defface message-header-other-face
987 (:foreground "#b00000"))
990 (:foreground "steel blue"))
992 (:bold t :italic t)))
993 "Face used for displaying newsgroups headers."
994 :group 'message-faces)
996 (defface message-header-name-face
999 (:foreground "DarkGreen"))
1002 (:foreground "cornflower blue"))
1005 "Face used for displaying header names."
1006 :group 'message-faces)
1008 (defface message-header-xheader-face
1011 (:foreground "blue"))
1014 (:foreground "blue"))
1017 "Face used for displaying X-Header headers."
1018 :group 'message-faces)
1020 (defface message-separator-face
1023 (:foreground "blue3"))
1026 (:foreground "brown"))
1029 "Face used for displaying the separator."
1030 :group 'message-faces)
1032 (defface message-cited-text-face
1035 (:foreground "red"))
1038 (:foreground "red"))
1041 "Face used for displaying cited text names."
1042 :group 'message-faces)
1044 (defface message-mml-face
1047 (:foreground "ForestGreen"))
1050 (:foreground "ForestGreen"))
1053 "Face used for displaying MML."
1054 :group 'message-faces)
1056 (defvar message-font-lock-fence-open-regexp "[+|]"
1057 "*Regexp that matches fence open string.")
1059 (defvar message-font-lock-fence-close-regexp "|"
1060 "*Regexp that matches fence close string.")
1062 (defvar message-font-lock-fence-open-position nil
1063 "*Cons of SYMBOL of a function or a variable and a number of OFFSET that
1064 indicate the fence open position. If it is non-nil,
1065 `message-font-lock-fence-open-regexp' is not used for searching for the
1066 fence open position. If SYMBOL is a function, it is called with one argument
1067 last cursor position and should return the fence open position as a number
1068 or a marker. If SYMBOL is a variable symbol, the value is examined with
1069 `symbol-value'. OFFSET is added to the position to compensate the value.
1070 For example, the following combinations of variable symbol and offset value
1073 Egg v3: '(egg:*region-start* . -1)
1074 Canna: '(canna:*region-start* . 0)
1077 (defvar message-font-lock-fence-close-position nil
1078 "*Cons of SYMBOL of a function or a variable and a number of OFFSET that
1079 indicate the fence close position. If it is non-nil,
1080 `message-font-lock-fence-close-regexp' is not used for searching for the
1081 fence close position. If SYMBOL is a function, it is called with one argument
1082 last cursor position and should return the fence close position as a number
1083 or a marker. If SYMBOL is a variable symbol, the value is examined with
1084 `symbol-value'. OFFSET is added to the position to compensate the value.
1085 For example, the following combinations of variable symbol and offset value
1088 Egg v3: '(egg:*region-end* . 0)
1089 Canna: '(canna:*region-end* . 0)
1092 (defvar message-font-lock-cited-text-regexp
1093 "^[\t ]*\\([^\000- :>|}\177]*\\)[:>|}].*"
1094 "*Regexp that matches cited text. It should have a grouping for the
1095 citation prefix which is ended at the beginning of citation mark string.")
1097 (defvar message-font-lock-citation-name-max-column 10
1098 "*Maximun number of column for citation name for fontifying.")
1100 (defvar message-font-lock-last-position nil
1101 "Internal buffer local variable to save the last cursor position
1102 before fontifying.")
1104 (eval-after-load "font-lock"
1105 '(defadvice font-lock-after-change-function
1106 (before message-font-lock-save-last-position activate)
1107 "Save last cursor position before fontifying."
1108 (if (eq 'message-mode major-mode)
1109 (setq message-font-lock-last-position (point)))))
1111 (defun message-font-lock-cited-text-matcher (limit)
1112 "Search for a cited text containing `message-font-lock-cited-text-regexp'
1113 forward. Argument LIMIT bounds the search. If a cited text is found, it
1114 returns t and sets match data 1 and 2, otherwise it returns nil. Normally,
1115 match data 2 has zero length, but if the FENCE (for input method) is detected
1116 in matched text, result is divided into match data 1 and 2 across the FENCE.
1117 See also the documentations for the following variables:
1118 `message-font-lock-fence-open-regexp'
1119 `message-font-lock-fence-close-regexp'
1120 `message-font-lock-fence-open-position'
1121 `message-font-lock-fence-close-position'
1124 (when (re-search-forward message-font-lock-cited-text-regexp limit t)
1125 (let* ((start0 (match-beginning 0))
1126 (end0 (match-end 0))
1127 (cite-mark (match-end 1))
1130 (goto-char cite-mark)
1131 (<= (current-column)
1132 message-font-lock-citation-name-max-column)))
1136 message-font-lock-last-position
1137 (>= message-font-lock-last-position start0)
1138 (<= message-font-lock-last-position end0)
1140 (message-font-lock-fence-open-position
1141 (let* ((symbol (car message-font-lock-fence-open-position))
1143 (cond ((functionp symbol)
1144 (funcall symbol message-font-lock-last-position))
1145 ((and (symbolp symbol)
1147 (symbol-value symbol)))))
1148 (when (markerp open)
1149 (setq open (marker-position open)))
1153 (cdr message-font-lock-fence-open-position)))
1154 (>= message-font-lock-last-position open)
1156 (or (not message-font-lock-fence-open-regexp)
1157 (looking-at message-font-lock-fence-open-regexp))
1159 (message-font-lock-fence-open-regexp
1160 (goto-char message-font-lock-last-position)
1161 (when (re-search-backward
1162 message-font-lock-fence-open-regexp start0 t)
1163 (setq end1 (match-beginning 0)))))
1164 (setq should-fontify
1165 (and message-font-lock-fence-open-position
1166 (not (eq cite-mark end1))))
1168 (message-font-lock-fence-close-position
1169 (let* ((symbol (car message-font-lock-fence-close-position))
1171 (cond ((functionp symbol)
1172 (funcall symbol message-font-lock-last-position))
1173 ((and (symbolp symbol)
1175 (symbol-value symbol)))))
1176 (when (markerp close)
1177 (setq close (marker-position close)))
1178 (and (numberp close)
1181 (cdr message-font-lock-fence-close-position)))
1182 (<= message-font-lock-last-position close)
1183 (setq start2 close))))
1184 (message-font-lock-fence-close-regexp
1185 (goto-char message-font-lock-last-position)
1186 (when (looking-at message-font-lock-fence-close-regexp)
1187 (setq start2 (match-end 0)))))
1188 (setq should-fontify
1189 (and (not (and (not message-font-lock-fence-open-position)
1190 (eq cite-mark end1)))
1191 (not (eq cite-mark start2)))))
1193 (when should-fontify
1195 (store-match-data (list start0 end0 start0 end1 start2 end0))
1196 (store-match-data (list start0 end0 start0 end0 end0 end0)))
1198 (setq message-font-lock-last-position nil)))
1200 (defvar message-font-lock-keywords-1
1201 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1202 `((,(concat "^\\([Tt]o:\\)" content)
1203 (1 'message-header-name-face)
1204 (2 'message-header-to-face nil t))
1205 (,(concat "^\\([GBF]?[Cc][Cc]:\\|[Rr]eply-[Tt]o:\\|"
1206 "[Mm]ail-[Cc]opies-[Tt]o:\\|"
1207 "[Mm]ail-[Rr]eply-[Tt]o:\\|"
1208 "[Mm]ail-[Ff]ollowup-[Tt]o:\\)" content)
1209 (1 'message-header-name-face)
1210 (2 'message-header-cc-face nil t))
1211 (,(concat "^\\([Ss]ubject:\\)" content)
1212 (1 'message-header-name-face)
1213 (2 'message-header-subject-face nil t))
1214 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content)
1215 (1 'message-header-name-face)
1216 (2 'message-header-newsgroups-face nil t))
1217 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content)
1218 (1 'message-header-name-face)
1219 (2 'message-header-other-face nil t))
1220 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content)
1221 (1 'message-header-name-face)
1222 (2 'message-header-name-face))
1223 ,@(if (and mail-header-separator
1224 (not (equal mail-header-separator "")))
1225 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1226 1 'message-separator-face))
1229 (defvar message-font-lock-keywords-2
1230 (append message-font-lock-keywords-1
1231 `((message-font-lock-cited-text-matcher
1232 (1 'message-cited-text-face)
1233 (2 'message-cited-text-face))
1234 (,(concat "^\\(" message-cite-prefix-regexp "\\).*")
1235 (0 'message-cited-text-face))
1236 ("<#/?\\(multipart\\|part\\|external\\|mml\\).*>"
1237 (0 'message-mml-face)))))
1239 (defvar message-font-lock-keywords message-font-lock-keywords-2
1240 "Additional expressions to highlight in Message mode.")
1242 ;; XEmacs does it like this. For Emacs, we have to set the
1243 ;; `font-lock-defaults' buffer-local variable.
1244 (put 'message-mode 'font-lock-defaults
1245 '((message-font-lock-keywords
1246 message-font-lock-keywords-1
1247 message-font-lock-keywords-2)
1249 (font-lock-mark-block-function . mark-paragraph)))
1251 (defvar message-face-alist
1252 '((bold . bold-region)
1253 (underline . underline-region)
1254 (default . (lambda (b e)
1256 (ununderline-region b e))))
1257 "Alist of mail and news faces for facemenu.
1258 The cdr of ech entry is a function for applying the face to a region.")
1260 (defcustom message-send-hook nil
1261 "Hook run before sending messages."
1262 :group 'message-various
1263 :options '(ispell-message)
1266 (defcustom message-send-mail-hook nil
1267 "Hook run before sending mail messages."
1268 :group 'message-various
1271 (defcustom message-send-news-hook nil
1272 "Hook run before sending news messages."
1273 :group 'message-various
1276 (defcustom message-sent-hook nil
1277 "Hook run after sending messages."
1278 :group 'message-various
1281 (defcustom message-use-multi-frames nil
1282 "Make new frame when sending messages."
1283 :group 'message-frames
1286 (defcustom message-delete-frame-on-exit nil
1287 "Delete frame after sending messages."
1288 :group 'message-frames
1289 :type '(choice (const :tag "off" nil)
1290 (const :tag "always" t)
1291 (const :tag "ask" ask)))
1293 (defvar message-draft-coding-system
1295 ((boundp 'MULE) '*junet*)
1296 ((not (fboundp 'find-coding-system)) nil)
1297 ((find-coding-system 'emacs-mule)
1298 (if (memq system-type '(windows-nt ms-dos ms-windows))
1299 'emacs-mule-dos 'emacs-mule))
1300 ((find-coding-system 'escape-quoted) 'escape-quoted)
1301 ((find-coding-system 'no-conversion) 'no-conversion)
1303 "Coding system to compose mail.")
1305 (defcustom message-send-mail-partially-limit 1000000
1306 "The limitation of messages sent as message/partial.
1307 The lower bound of message size in characters, beyond which the message
1308 should be sent in several parts. If it is nil, the size is unlimited."
1310 :group 'message-buffers
1311 :type '(choice (const :tag "unlimited" nil)
1314 (defcustom message-alternative-emails nil
1315 "A regexp to match the alternative email addresses.
1316 The first matched address (not primary one) is used in the From field."
1317 :group 'message-headers
1318 :type '(choice (const :tag "Always use primary" nil)
1321 (defcustom message-mail-user-agent nil
1322 "Like `mail-user-agent'.
1323 Except if it is nil, use Gnus native MUA; if it is t, use
1325 :type '(radio (const :tag "Gnus native"
1328 (const :tag "`mail-user-agent'"
1331 (function-item :tag "Default Emacs mail"
1333 sendmail-user-agent)
1334 (function-item :tag "Emacs interface to MH"
1337 (function :tag "Other"))
1341 ;;; Internal variables.
1343 (defvar message-sending-message "Sending...")
1344 (defvar message-buffer-list nil)
1345 (defvar message-this-is-news nil)
1346 (defvar message-this-is-mail nil)
1347 (defvar message-draft-article nil)
1348 (defvar message-mime-part nil)
1349 (defvar message-posting-charset nil)
1351 ;; Byte-compiler warning
1353 (defvar gnus-active-hashtb)
1354 (defvar gnus-read-active-file))
1356 ;;; Regexp matching the delimiter of messages in UNIX mail format
1357 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1358 ;;; of rmail.el's rmail-unix-mail-delimiter.
1359 (defvar message-unix-mail-delimiter
1360 (let ((time-zone-regexp
1361 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1362 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1368 ;; Many things can happen to an RFC 822 mailbox before it is put into
1369 ;; a `From' line. The leading phrase can be stripped, e.g.
1370 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1371 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1372 ;; can be removed, e.g.
1373 ;; From: joe@y.z (Joe K
1375 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1378 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1379 ;; The mailbox can be removed or be replaced by white space, e.g.
1380 ;; From: "Joe User"{space}{tab}
1382 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1383 ;; where {space} and {tab} represent the Ascii space and tab characters.
1384 ;; We want to match the results of any of these manglings.
1385 ;; The following regexp rejects names whose first characters are
1386 ;; obviously bogus, but after that anything goes.
1387 "\\([^\0-\b\n-\r\^?].*\\)? "
1389 ;; The time the message was sent.
1390 "\\([^\0-\r \^?]+\\) +" ; day of the week
1391 "\\([^\0-\r \^?]+\\) +" ; month
1392 "\\([0-3]?[0-9]\\) +" ; day of month
1393 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1395 ;; Perhaps a time zone, specified by an abbreviation, or by a
1400 " \\([0-9][0-9]+\\) *"
1402 ;; On some systems the time zone can appear after the year, too.
1406 "\\(remote from .*\\)?"
1409 "Regexp matching the delimiter of messages in UNIX mail format.")
1411 (defvar message-unsent-separator
1412 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1413 "^ *---+ +Returned message +---+ *$\\|"
1414 "^Start of returned message$\\|"
1415 "^ *---+ +Original message +---+ *$\\|"
1416 "^ *--+ +begin message +--+ *$\\|"
1417 "^ *---+ +Original message follows +---+ *$\\|"
1418 "^ *---+ +Undelivered message follows +---+ *$\\|"
1419 "^|? *---+ +Message text follows: +---+ *|?$")
1420 "A regexp that matches the separator before the text of a failed message.")
1422 (defvar message-header-format-alist
1424 (To . message-fill-address)
1425 (Cc . message-fill-address)
1436 (References . message-shorten-references)
1438 "Alist used for formatting headers.")
1440 (defvar message-options nil
1441 "Some saved answers when sending message.")
1444 (autoload 'message-setup-toolbar "messagexmas")
1445 (autoload 'mh-new-draft-name "mh-comp")
1446 (autoload 'mh-send-letter "mh-comp")
1447 (autoload 'gnus-point-at-eol "gnus-util")
1448 (autoload 'gnus-point-at-bol "gnus-util")
1449 (autoload 'gnus-output-to-rmail "gnus-util")
1450 (autoload 'gnus-output-to-mail "gnus-util")
1451 (autoload 'mail-abbrev-in-expansion-header-p "mailabbrev")
1452 (autoload 'nndraft-request-associate-buffer "nndraft")
1453 (autoload 'nndraft-request-expire-articles "nndraft")
1454 (autoload 'gnus-open-server "gnus-int")
1455 (autoload 'gnus-request-post "gnus-int")
1456 (autoload 'gnus-copy-article-buffer "gnus-msg")
1457 (autoload 'gnus-alive-p "gnus-util")
1458 (autoload 'gnus-server-string "gnus")
1459 (autoload 'gnus-group-name-charset "gnus-group")
1460 (autoload 'rmail-output "rmailout")
1461 (autoload 'mu-cite-original "mu-cite"))
1466 ;;; Utility functions.
1468 (defun message-eval-parameter (parameter)
1470 (if (symbolp parameter)
1471 (if (functionp parameter)
1477 (defsubst message-get-parameter (key &optional alist)
1479 (setq alist message-parameter-alist))
1480 (cdr (assq key alist)))
1482 (defmacro message-get-parameter-with-eval (key &optional alist)
1483 `(message-eval-parameter (message-get-parameter ,key ,alist)))
1485 (defmacro message-y-or-n-p (question show &rest text)
1486 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1487 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1489 (defmacro message-delete-line (&optional n)
1490 "Delete the current line (and the next N lines)."
1491 `(delete-region (progn (beginning-of-line) (point))
1492 (progn (forward-line ,(or n 1)) (point))))
1494 (defun message-unquote-tokens (elems)
1495 "Remove double quotes (\") from strings in list ELEMS."
1496 (mapcar (lambda (item)
1497 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1498 (setq item (concat (match-string 1 item)
1499 (match-string 2 item))))
1503 (defun message-tokenize-header (header &optional separator)
1504 "Split HEADER into a list of header elements.
1505 SEPARATOR is a string of characters to be used as separators. \",\"
1506 is used by default."
1509 (let ((regexp (format "[%s]+" (or separator ",")))
1514 (message-set-work-buffer)
1516 (goto-char (point-min))
1521 (cond ((and (> (point) beg)
1523 (and (looking-at regexp)
1526 (push (buffer-substring beg (point)) elems)
1527 (setq beg (match-end 0)))
1528 ((eq (char-after) ?\")
1529 (setq quoted (not quoted)))
1530 ((and (eq (char-after) ?\()
1533 ((and (eq (char-after) ?\))
1536 (nreverse elems)))))
1538 (defun message-mail-file-mbox-p (file)
1539 "Say whether FILE looks like a Unix mbox file."
1540 (when (and (file-exists-p file)
1541 (file-readable-p file)
1542 (file-regular-p file))
1544 (nnheader-insert-file-contents file)
1545 (goto-char (point-min))
1546 (looking-at message-unix-mail-delimiter))))
1548 (defun message-fetch-field (header &optional not-all)
1549 "The same as `mail-fetch-field', only remove all newlines."
1550 (let* ((inhibit-point-motion-hooks t)
1551 (case-fold-search t)
1552 (value (mail-fetch-field header nil (not not-all))))
1554 (while (string-match "\n[\t ]+" value)
1555 (setq value (replace-match " " t t value)))
1556 (set-text-properties 0 (length value) nil value)
1559 (defun message-narrow-to-field ()
1560 "Narrow the buffer to the header on the current line."
1566 (if (re-search-forward "^[^ \n\t]" nil t)
1571 (goto-char (point-min)))
1573 (defun message-add-header (&rest headers)
1574 "Add the HEADERS to the message header, skipping those already present."
1577 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1578 (error "Invalid header `%s'" (car headers)))
1579 (setq hclean (match-string 1 (car headers)))
1581 (message-narrow-to-headers)
1582 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1583 (goto-char (point-max))
1584 (if (string-match "\n$" (car headers))
1585 (insert (car headers))
1586 (insert (car headers) ?\n)))))
1587 (setq headers (cdr headers))))
1590 (defun message-fetch-reply-field (header)
1591 "Fetch field HEADER from the message we're replying to."
1592 (let ((buffer (message-eval-parameter message-reply-buffer)))
1594 (buffer-name buffer))
1597 (message-fetch-field header)))))
1599 (defun message-set-work-buffer ()
1600 (if (get-buffer " *message work*")
1602 (set-buffer " *message work*")
1604 (set-buffer (get-buffer-create " *message work*"))
1605 (kill-all-local-variables)))
1607 (defun message-functionp (form)
1608 "Return non-nil if FORM is funcallable."
1609 (or (and (symbolp form) (fboundp form))
1610 (and (listp form) (eq (car form) 'lambda))
1611 (byte-code-function-p form)))
1613 (defun message-strip-list-identifiers (subject)
1614 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1615 (require 'gnus-sum) ; for gnus-list-identifiers
1616 (let ((regexp (if (stringp gnus-list-identifiers)
1617 gnus-list-identifiers
1618 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1619 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1620 " *\\)\\)+\\(Re: +\\)?\\)") subject)
1621 (concat (substring subject 0 (match-beginning 1))
1622 (or (match-string 3 subject)
1623 (match-string 5 subject))
1628 (defun message-strip-subject-re (subject)
1629 "Remove \"Re:\" from subject lines in string SUBJECT."
1630 (if (string-match message-subject-re-regexp subject)
1631 (substring subject (match-end 0))
1634 (defun message-remove-header (header &optional is-regexp first reverse)
1635 "Remove HEADER in the narrowed buffer.
1636 If IS-REGEXP, HEADER is a regular expression.
1637 If FIRST, only remove the first instance of the header.
1638 Return the number of headers removed."
1639 (goto-char (point-min))
1640 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
1642 (case-fold-search t)
1644 (while (and (not (eobp))
1647 (not (looking-at regexp))
1648 (looking-at regexp))
1655 ;; There might be a continuation header, so we have to search
1656 ;; until we find a new non-continuation line.
1659 (if (re-search-forward "^[^ \t]" nil t)
1660 (goto-char (match-beginning 0))
1663 (if (re-search-forward "^[^ \t]" nil t)
1664 (goto-char (match-beginning 0))
1665 (goto-char (point-max)))))
1668 (defun message-remove-first-header (header)
1669 "Remove the first instance of HEADER if there is more than one."
1671 (regexp (concat "^" (regexp-quote header) ":")))
1673 (goto-char (point-min))
1674 (while (re-search-forward regexp nil t)
1677 (message-remove-header header nil t)
1680 (defun message-narrow-to-headers ()
1681 "Narrow the buffer to the head of the message."
1684 (goto-char (point-min))
1685 (if (re-search-forward
1686 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1689 (goto-char (point-min)))
1691 (defun message-narrow-to-head-1 ()
1692 "Like `message-narrow-to-head'. Don't widen."
1694 (goto-char (point-min))
1695 (if (search-forward "\n\n" nil 1)
1698 (goto-char (point-min)))
1700 (defun message-narrow-to-head ()
1701 "Narrow the buffer to the head of the message.
1702 Point is left at the beginning of the narrowed-to region."
1704 (message-narrow-to-head-1))
1706 (defun message-narrow-to-headers-or-head ()
1707 "Narrow the buffer to the head of the message."
1710 (goto-char (point-min))
1713 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1714 (match-beginning 0))
1715 ((search-forward "\n\n" nil t)
1719 (goto-char (point-min)))
1721 (defun message-news-p ()
1722 "Say whether the current buffer contains a news message."
1723 (and (not message-this-is-mail)
1724 (or message-this-is-news
1727 (message-narrow-to-headers)
1728 (and (message-fetch-field "newsgroups")
1729 (not (message-fetch-field "posted-to"))))))))
1731 (defun message-mail-p ()
1732 "Say whether the current buffer contains a mail message."
1733 (and (not message-this-is-news)
1734 (or message-this-is-mail
1737 (message-narrow-to-headers)
1738 (or (message-fetch-field "to")
1739 (message-fetch-field "cc")
1740 (message-fetch-field "bcc")))))))
1742 (defun message-next-header ()
1743 "Go to the beginning of the next header."
1745 (or (eobp) (forward-char 1))
1746 (not (if (re-search-forward "^[^ \t]" nil t)
1748 (goto-char (point-max)))))
1750 (defun message-sort-headers-1 ()
1751 "Sort the buffer as headers using `message-rank' text props."
1752 (goto-char (point-min))
1755 nil 'message-next-header
1757 (message-next-header)
1761 (or (get-text-property (point) 'message-rank)
1764 (defun message-sort-headers ()
1765 "Sort the headers of the current message according to `message-header-format-alist'."
1769 (let ((max (1+ (length message-header-format-alist)))
1771 (message-narrow-to-headers)
1772 (while (re-search-forward "^[^ \n]+:" nil t)
1774 (match-beginning 0) (1+ (match-beginning 0))
1776 (if (setq rank (length (memq (assq (intern (buffer-substring
1778 (1- (match-end 0))))
1779 message-header-format-alist)
1780 message-header-format-alist)))
1783 (message-sort-headers-1))))
1793 (defvar message-mode-map nil)
1795 (unless message-mode-map
1796 (setq message-mode-map (make-keymap))
1797 (set-keymap-parent message-mode-map text-mode-map)
1798 (define-key message-mode-map "\C-c?" 'describe-mode)
1800 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
1801 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
1802 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
1803 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
1804 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
1805 ;; (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
1806 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-mail-reply-to)
1807 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
1808 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
1809 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
1810 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
1811 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
1812 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
1813 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
1814 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
1815 (define-key message-mode-map "\C-c\C-fc" 'message-goto-mail-copies-to)
1817 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
1818 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
1820 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
1821 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
1822 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
1823 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
1824 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
1825 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
1826 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
1827 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
1829 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
1830 (define-key message-mode-map "\C-c\C-s" 'message-send)
1831 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
1832 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
1834 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
1835 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
1836 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
1837 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
1838 ;;(define-key message-mode-map "\M-q" 'message-fill-paragraph)
1840 (define-key message-mode-map "\t" 'message-tab)
1841 (define-key message-mode-map "\M-;" 'comment-region)
1843 (define-key message-mode-map "\C-x\C-s" 'message-save-drafts)
1844 (define-key message-mode-map "\C-xk" 'message-mimic-kill-buffer))
1847 message-mode-menu message-mode-map "Message Menu."
1849 ["Sort Headers" message-sort-headers t]
1850 ["Yank Original" message-yank-original t]
1851 ["Fill Yanked Message" message-fill-yanked-message t]
1852 ["Insert Signature" message-insert-signature t]
1853 ["Caesar (rot13) Message" message-caesar-buffer-body t]
1854 ["Caesar (rot13) Region" message-caesar-region (mark t)]
1855 ["Elide Region" message-elide-region (mark t)]
1856 ["Delete Outside Region" message-delete-not-region (mark t)]
1857 ["Kill To Signature" message-kill-to-signature t]
1858 ["Newline and Reformat" message-newline-and-reformat t]
1859 ["Rename buffer" message-rename-buffer t]
1860 ["Spellcheck" ispell-message
1861 ,@(if (featurep 'xemacs) '(t)
1862 '(:help "Spellcheck this message"))]
1863 ["Attach file as MIME" mime-edit-insert-file
1864 ,@(if (featurep 'xemacs) '(t)
1865 '(:help "Attach a file at point"))]
1867 ["Send Message" message-send-and-exit
1868 ,@(if (featurep 'xemacs) '(t)
1869 '(:help "Send this message"))]
1870 ["Abort Message" message-dont-send
1871 ,@(if (featurep 'xemacs) '(t)
1872 '(:help "File this draft message and exit"))]
1873 ["Kill Message" message-kill-buffer
1874 ,@(if (featurep 'xemacs) '(t)
1875 '(:help "Delete this message without sending"))]))
1878 message-mode-field-menu message-mode-map ""
1880 ["Fetch To" message-insert-to t]
1881 ["Fetch Newsgroups" message-insert-newsgroups t]
1883 ["To" message-goto-to t]
1884 ["Subject" message-goto-subject t]
1885 ["Cc" message-goto-cc t]
1886 ["Reply-To" message-goto-reply-to t]
1887 ["Mail-Reply-To" message-goto-mail-reply-to t]
1888 ["Mail-Followup-To" message-goto-mail-followup-to t]
1889 ["Mail-Copies-To" message-goto-mail-copies-to t]
1890 ["Summary" message-goto-summary t]
1891 ["Keywords" message-goto-keywords t]
1892 ["Newsgroups" message-goto-newsgroups t]
1893 ["Followup-To" message-goto-followup-to t]
1894 ["Distribution" message-goto-distribution t]
1895 ["Body" message-goto-body t]
1896 ["Signature" message-goto-signature t]))
1898 (defvar message-tool-bar-map nil)
1901 (defvar facemenu-add-face-function)
1902 (defvar facemenu-remove-face-function))
1905 (defun message-mode ()
1906 "Major mode for editing mail and news to be sent.
1907 Like Text Mode but with these additional commands:\\<message-mode-map>
1908 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
1909 C-c C-d Postpone sending the message C-c C-k Kill the message
1910 C-c C-f move to a header field (and create it if there isn't):
1911 C-c C-f C-t move to To C-c C-f C-s move to Subject
1912 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1913 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1914 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1915 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1916 C-c C-f C-m move to Mail-Followup-To
1917 C-c C-f C-f move to Followup-To
1918 C-c C-t `message-insert-to' (add a To header to a news followup)
1919 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
1920 C-c C-b `message-goto-body' (move to beginning of message text).
1921 C-c C-i `message-goto-signature' (move to the beginning of the signature).
1922 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
1923 C-c C-y `message-yank-original' (insert current message, if any).
1924 C-c C-q `message-fill-yanked-message' (fill what was yanked).
1925 C-c C-e `message-elide-region' (elide the text between point and mark).
1926 C-c C-v `message-delete-not-region' (remove the text outside the region).
1927 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
1928 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
1929 M-RET `message-newline-and-reformat' (break the line and reformat)."
1931 (kill-all-local-variables)
1932 (set (make-local-variable 'message-reply-buffer) nil)
1933 (make-local-variable 'message-send-actions)
1934 (make-local-variable 'message-exit-actions)
1935 (make-local-variable 'message-kill-actions)
1936 (make-local-variable 'message-postpone-actions)
1937 (make-local-variable 'message-draft-article)
1938 (make-local-hook 'kill-buffer-hook)
1939 (set-syntax-table message-mode-syntax-table)
1940 (use-local-map message-mode-map)
1941 (setq local-abbrev-table message-mode-abbrev-table)
1942 (setq major-mode 'message-mode)
1943 (setq mode-name "Message")
1944 (setq buffer-offer-save t)
1945 (make-local-variable 'facemenu-add-face-function)
1946 (make-local-variable 'facemenu-remove-face-function)
1947 (setq facemenu-add-face-function
1949 (let ((face-fun (cdr (assq face message-face-alist))))
1951 (funcall face-fun (point) end)
1952 (error "Face %s not configured for %s mode" face mode-name)))
1954 facemenu-remove-face-function t)
1955 (make-local-variable 'message-reply-headers)
1956 (setq message-reply-headers nil)
1957 (make-local-variable 'message-user-agent)
1958 (make-local-variable 'message-post-method)
1959 (set (make-local-variable 'message-sent-message-via) nil)
1960 (set (make-local-variable 'message-checksum) nil)
1961 (make-local-variable 'message-parameter-alist)
1962 (setq message-parameter-alist
1963 (copy-sequence message-startup-parameter-alist))
1964 (message-setup-fill-variables)
1965 ;; Allow using comment commands to add/remove quoting.
1966 (set (make-local-variable 'comment-start) message-yank-prefix)
1967 (if (featurep 'xemacs)
1968 (message-setup-toolbar)
1969 (set (make-local-variable 'font-lock-defaults)
1970 '((message-font-lock-keywords
1971 message-font-lock-keywords-1
1972 message-font-lock-keywords-2)
1974 (font-lock-mark-block-function . mark-paragraph)))
1975 (if (boundp 'tool-bar-map)
1976 (set (make-local-variable 'tool-bar-map) (message-tool-bar-map))))
1977 (set (make-local-variable 'message-font-lock-last-position) nil)
1978 (easy-menu-add message-mode-menu message-mode-map)
1979 (easy-menu-add message-mode-field-menu message-mode-map)
1980 ;; Allow mail alias things.
1981 (when (eq message-mail-alias-type 'abbrev)
1982 (if (fboundp 'mail-abbrevs-setup)
1983 (mail-abbrevs-setup)
1984 (mail-aliases-setup)))
1985 (message-set-auto-save-file-name)
1986 (make-local-variable 'indent-tabs-mode) ;Turn off tabs for indentation.
1987 (setq indent-tabs-mode nil)
1988 (run-hooks 'text-mode-hook 'message-mode-hook))
1990 (defun message-setup-fill-variables ()
1991 "Setup message fill variables."
1992 (set (make-local-variable 'fill-paragraph-function)
1993 'message-fill-paragraph)
1994 (make-local-variable 'paragraph-separate)
1995 (make-local-variable 'paragraph-start)
1996 (make-local-variable 'adaptive-fill-regexp)
1997 (unless (boundp 'adaptive-fill-first-line-regexp)
1998 (setq adaptive-fill-first-line-regexp nil))
1999 (make-local-variable 'adaptive-fill-first-line-regexp)
2000 (make-local-variable 'auto-fill-inhibit-regexp)
2001 (let ((quote-prefix-regexp
2002 ;; User should change message-cite-prefix-regexp if
2003 ;; message-yank-prefix is set to an abnormal value.
2004 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
2005 (setq paragraph-start
2007 (regexp-quote mail-header-separator) "$\\|"
2008 "[ \t]*$\\|" ; blank lines
2009 "-- $\\|" ; signature delimiter
2010 "---+$\\|" ; delimiters for forwarded messages
2011 page-delimiter "$\\|" ; spoiler warnings
2012 ".*wrote:$\\|" ; attribution lines
2013 quote-prefix-regexp "$")) ; empty lines in quoted text
2014 (setq paragraph-separate paragraph-start)
2015 (setq adaptive-fill-regexp
2016 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
2017 (setq adaptive-fill-first-line-regexp
2018 (concat quote-prefix-regexp "\\|"
2019 adaptive-fill-first-line-regexp))
2020 (setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")))
2025 ;;; Message mode commands
2028 ;;; Movement commands
2030 (defun message-goto-to ()
2031 "Move point to the To header."
2033 (message-position-on-field "To"))
2035 (defun message-goto-subject ()
2036 "Move point to the Subject header."
2038 (message-position-on-field "Subject"))
2040 (defun message-goto-cc ()
2041 "Move point to the Cc header."
2043 (message-position-on-field "Cc" "To"))
2045 (defun message-goto-bcc ()
2046 "Move point to the Bcc header."
2048 (message-position-on-field "Bcc" "Cc" "To"))
2050 (defun message-goto-fcc ()
2051 "Move point to the Fcc header."
2053 (message-position-on-field "Fcc" "To" "Newsgroups"))
2055 (defun message-goto-reply-to ()
2056 "Move point to the Reply-To header."
2058 (message-position-on-field "Reply-To" "Subject"))
2060 (defun message-goto-mail-reply-to ()
2061 "Move point to the Mail-Reply-To header."
2063 (message-position-on-field "Mail-Reply-To" "Subject"))
2065 (defun message-goto-mail-followup-to ()
2066 "Move point to the Mail-Followup-To header. If the header is newly created
2067 and To field contains only one address, the address is inserted in default."
2069 (unless (message-position-on-field "Mail-Followup-To" "Subject")
2070 (let ((start (point))
2073 (message-narrow-to-headers)
2074 (setq addresses (split-string (mail-strip-quoted-names
2075 (or (std11-fetch-field "to") ""))
2077 (when (eq 1 (length addresses))
2079 (insert (car addresses))
2080 (goto-char start))))))
2082 (defun message-goto-mail-copies-to ()
2083 "Move point to the Mail-Copies-To header. If the header is newly created,
2084 a string \"never\" is inserted in default."
2086 (unless (message-position-on-field "Mail-Copies-To" "Subject")
2090 (defun message-goto-newsgroups ()
2091 "Move point to the Newsgroups header."
2093 (message-position-on-field "Newsgroups"))
2095 (defun message-goto-distribution ()
2096 "Move point to the Distribution header."
2098 (message-position-on-field "Distribution"))
2100 (defun message-goto-followup-to ()
2101 "Move point to the Followup-To header."
2103 (message-position-on-field "Followup-To" "Newsgroups"))
2105 (defun message-goto-keywords ()
2106 "Move point to the Keywords header."
2108 (message-position-on-field "Keywords" "Subject"))
2110 (defun message-goto-summary ()
2111 "Move point to the Summary header."
2113 (message-position-on-field "Summary" "Subject"))
2115 (defun message-goto-body (&optional interactivep)
2116 "Move point to the beginning of the message body."
2117 (interactive (list t))
2118 (when (and interactivep
2119 (looking-at "[ \t]*\n"))
2121 (goto-char (point-min))
2122 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
2123 (search-forward "\n\n" nil t)))
2125 (defun message-goto-eoh ()
2126 "Move point to the end of the headers."
2131 (defun message-goto-signature ()
2132 "Move point to the beginning of the message signature.
2133 If there is no signature in the article, go to the end and
2136 (goto-char (point-min))
2137 (if (re-search-forward message-signature-separator nil t)
2139 (goto-char (point-max))
2144 (defun message-insert-to (&optional force)
2145 "Insert a To header that points to the author of the article being replied to.
2146 If the original author requested not to be sent mail, the function signals
2148 With the prefix argument FORCE, insert the header anyway."
2150 (let ((co (message-fetch-reply-field "mail-copies-to")))
2151 (when (and (null force)
2153 (or (equal (downcase co) "never")
2154 (equal (downcase co) "nobody")))
2155 (error "The user has requested not to have copies sent via mail")))
2156 (when (and (message-position-on-field "To")
2157 (mail-fetch-field "to")
2158 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
2160 (insert (or (message-fetch-reply-field "mail-reply-to")
2161 (message-fetch-reply-field "reply-to")
2162 (message-fetch-reply-field "from") "")))
2164 (defun message-widen-reply ()
2165 "Widen the reply to include maximum recipients."
2168 (and message-reply-buffer
2169 (buffer-name message-reply-buffer)
2171 (set-buffer message-reply-buffer)
2172 (message-get-reply-headers t)))))
2175 (message-narrow-to-headers)
2176 (dolist (elem follow-to)
2177 (message-remove-header (symbol-name (car elem)))
2178 (goto-char (point-min))
2179 (insert (symbol-name (car elem)) ": "
2180 (cdr elem) "\n"))))))
2182 (defun message-insert-newsgroups ()
2183 "Insert the Newsgroups header from the article being replied to."
2185 (when (and (message-position-on-field "Newsgroups")
2186 (mail-fetch-field "newsgroups")
2187 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
2189 (insert (or (message-fetch-reply-field "newsgroups") "")))
2193 ;;; Various commands
2195 (defun message-delete-not-region (beg end)
2196 "Delete everything in the body of the current message outside of the region."
2200 (delete-region (point) (if (not (message-goto-signature))
2206 (delete-region beg (progn (message-goto-body)
2209 (when (message-goto-signature)
2212 (defun message-kill-to-signature ()
2213 "Deletes all text up to the signature."
2215 (let ((point (point)))
2216 (message-goto-signature)
2219 (kill-region point (point))
2223 (defun message-newline-and-reformat (&optional arg not-break)
2224 "Insert four newlines, and then reformat if inside quoted text.
2225 Prefix arg means justify as well."
2226 (interactive (list (if current-prefix-arg 'full)))
2227 (let (quoted point beg end leading-space bolp)
2228 (setq point (point))
2231 (setq bolp (= beg point))
2232 ;; Find first line of the paragraph.
2234 (while (and (not (eobp))
2235 (not (looking-at message-cite-prefix-regexp))
2236 (looking-at paragraph-start))
2239 (when (looking-at message-cite-prefix-regexp)
2240 (setq quoted (match-string 0))
2241 (goto-char (match-end 0))
2242 (looking-at "[ \t]*")
2243 (setq leading-space (match-string 0)))
2247 (< (- point beg) (length quoted)))
2248 ;; break inside the cite prefix.
2254 (while (and (not (eobp))
2255 (not (looking-at paragraph-separate))
2256 (looking-at message-cite-prefix-regexp)
2257 (equal quoted (match-string 0)))
2258 (goto-char (match-end 0))
2259 (looking-at "[ \t]*")
2260 (if (> (length leading-space) (length (match-string 0)))
2261 (setq leading-space (match-string 0)))
2265 (while (and (if (bobp) nil (forward-line -1) t)
2266 (not (looking-at paragraph-start))
2267 (looking-at message-cite-prefix-regexp)
2268 (equal quoted (match-string 0)))
2270 (goto-char (match-end 0))
2271 (looking-at "[ \t]*")
2272 (if (> (length leading-space) (length (match-string 0)))
2273 (setq leading-space (match-string 0)))))
2274 (while (and (not (eobp))
2275 (not (looking-at paragraph-separate))
2276 (not (looking-at message-cite-prefix-regexp)))
2280 (while (and (if (bobp) nil (forward-line -1) t)
2281 (not (looking-at paragraph-start))
2282 (not (looking-at message-cite-prefix-regexp)))
2283 (setq beg (point))))
2286 (narrow-to-region beg end)
2292 (setq point (point))
2294 (delete-region (point) (re-search-forward "[ \t]*"))
2295 (when (and quoted (not bolp))
2296 (insert quoted leading-space)))
2298 (let* ((adaptive-fill-regexp
2299 (regexp-quote (concat quoted leading-space)))
2300 (adaptive-fill-first-line-regexp
2301 adaptive-fill-regexp ))
2302 (fill-paragraph arg))
2303 (fill-paragraph arg))
2304 (if point (goto-char point)))))
2306 (defun message-fill-paragraph (&optional arg)
2307 "Like `fill-paragraph'."
2308 (interactive (list (if current-prefix-arg 'full)))
2309 (message-newline-and-reformat arg t)
2312 (defun message-insert-signature (&optional force)
2313 "Insert a signature. See documentation for variable `message-signature'."
2314 (interactive (list 0))
2317 ((and (null message-signature)
2320 (goto-char (point-max))
2321 (not (re-search-backward message-signature-separator nil t))))
2322 ((and (null message-signature)
2325 ((message-functionp message-signature)
2326 (funcall message-signature))
2327 ((listp message-signature)
2328 (eval message-signature))
2329 (t message-signature)))
2331 (cond ((stringp signature)
2333 ((and (eq t signature)
2334 message-signature-file
2335 (file-exists-p message-signature-file))
2338 (goto-char (point-max))
2339 ;; Insert the signature.
2343 (if (eq signature t)
2344 (insert-file-contents message-signature-file)
2346 (goto-char (point-max))
2347 (or (bolp) (insert "\n")))))
2349 (defun message-elide-region (b e)
2350 "Elide the text in the region.
2351 An ellipsis (from `message-elide-ellipsis') will be inserted where the
2355 (insert message-elide-ellipsis))
2357 (defvar message-caesar-translation-table nil)
2359 (defun message-caesar-region (b e &optional n)
2360 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
2363 (min (point) (or (mark t) (point)))
2364 (max (point) (or (mark t) (point)))
2365 (when current-prefix-arg
2366 (prefix-numeric-value current-prefix-arg))))
2368 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
2369 (unless (or (zerop n) ; no action needed for a rot of 0
2370 (= b e)) ; no region to rotate
2371 ;; We build the table, if necessary.
2372 (when (or (not message-caesar-translation-table)
2373 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
2374 (setq message-caesar-translation-table
2375 (message-make-caesar-translation-table n)))
2376 (translate-region b e message-caesar-translation-table)))
2378 (defun message-make-caesar-translation-table (n)
2379 "Create a rot table with offset N."
2381 (table (make-string 256 0)))
2382 (while (< (incf i) 256)
2385 (substring table 0 ?A)
2386 (substring table (+ ?A n) (+ ?A n (- 26 n)))
2387 (substring table ?A (+ ?A n))
2388 (substring table (+ ?A 26) ?a)
2389 (substring table (+ ?a n) (+ ?a n (- 26 n)))
2390 (substring table ?a (+ ?a n))
2391 (substring table (+ ?a 26) 255))))
2393 (defun message-caesar-buffer-body (&optional rotnum)
2394 "Caesar rotate all letters in the current buffer by 13 places.
2395 Used to encode/decode possibly offensive messages (commonly in rec.humor).
2396 With prefix arg, specifies the number of places to rotate each letter forward.
2397 Mail and USENET news headers are not rotated."
2398 (interactive (if current-prefix-arg
2399 (list (prefix-numeric-value current-prefix-arg))
2403 (when (message-goto-body)
2404 (narrow-to-region (point) (point-max)))
2405 (message-caesar-region (point-min) (point-max) rotnum))))
2407 (defun message-pipe-buffer-body (program)
2408 "Pipe the message body in the current buffer through PROGRAM."
2411 (when (message-goto-body)
2412 (narrow-to-region (point) (point-max)))
2413 (shell-command-on-region
2414 (point-min) (point-max) program nil t))))
2416 (defun message-rename-buffer (&optional enter-string)
2417 "Rename the *message* buffer to \"*message* RECIPIENT\".
2418 If the function is run with a prefix, it will ask for a new buffer
2419 name, rather than giving an automatic name."
2420 (interactive "Pbuffer name: ")
2423 (goto-char (point-min))
2424 (narrow-to-region (point)
2425 (search-forward mail-header-separator nil 'end))
2427 (if (message-news-p) (message-fetch-field "Newsgroups")
2428 (message-fetch-field "To"))
2431 (if (string-match "," mail-to)
2432 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
2434 (name-default (concat "*message* " mail-trimmed-to))
2435 (name (if enter-string
2436 (read-string "New buffer name: " name-default)
2438 (rename-buffer name t)))))
2440 (defun message-fill-yanked-message (&optional justifyp)
2441 "Fill the paragraphs of a message yanked into this one.
2442 Numeric argument means justify as well."
2445 (goto-char (point-min))
2446 (search-forward (concat "\n" mail-header-separator "\n") nil t)
2447 (let ((fill-prefix message-yank-prefix))
2448 (fill-individual-paragraphs (point) (point-max) justifyp))))
2450 (defun message-indent-citation ()
2451 "Modify text just inserted from a message to be cited.
2452 The inserted text should be the region.
2453 When this function returns, the region is again around the modified text.
2455 Normally, indent each nonblank line `message-indentation-spaces' spaces.
2456 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
2457 (let ((start (point)))
2458 ;; Remove unwanted headers.
2459 (when message-ignored-cited-headers
2464 (if (search-forward "\n\n" nil t)
2467 (message-remove-header message-ignored-cited-headers t)
2468 (when (= (point-min) (point-max))
2469 (setq all-removed t))
2470 (goto-char (point-max)))
2474 ;; Delete blank lines at the start of the buffer.
2475 (while (and (point-min)
2478 (message-delete-line))
2479 ;; Delete blank lines at the end of the buffer.
2480 (goto-char (point-max))
2483 (while (and (zerop (forward-line -1))
2485 (message-delete-line))
2486 ;; Do the indentation.
2487 (if (null message-yank-prefix)
2488 (indent-rigidly start (mark t) message-indentation-spaces)
2491 (while (< (point) (mark t))
2492 (insert message-yank-prefix)
2496 (defun message-list-references (refs-list &rest refs-strs)
2497 "Add `Message-ID's which appear in REFS-STRS but not in REFS-LIST,
2499 (let (refs ref id saved-id)
2500 (when (and refs-list
2501 (integerp message-list-references-add-position))
2502 (let ((pos message-list-references-add-position))
2503 (while (and refs-list
2505 (push (pop refs-list) saved-id)
2506 (setq pos (1- pos)))))
2508 (when (setq refs (pop refs-strs))
2509 (setq refs (std11-parse-msg-ids (std11-lexical-analyze refs)))
2511 (when (eq (car (setq ref (pop refs))) 'msg-id)
2512 (setq id (concat "<" (mapconcat 'cdr (cdr ref) "") ">"))
2513 (or (member id refs-list)
2514 (member id saved-id)
2515 (push id refs-list))))))
2517 (push (pop saved-id) refs-list))
2520 (defvar gnus-article-copy)
2521 (defun message-yank-original (&optional arg)
2522 "Insert the message being replied to, if any.
2523 Puts point before the text and mark after.
2524 Normally indents each nonblank line ARG spaces (default 3). However,
2525 if `message-yank-prefix' is non-nil, insert that prefix on each line.
2527 This function uses `message-cite-function' to do the actual citing.
2529 Just \\[universal-argument] as argument means don't indent, insert no
2530 prefix, and don't delete any headers.
2532 In addition, if `message-yank-add-new-references' is non-nil and this
2533 command is called interactively, new IDs from the yanked article will
2534 be added to \"References\" field.
2535 \(See also `message-yank-add-new-references'.)"
2537 (let ((modified (buffer-modified-p))
2538 (buffer (message-eval-parameter message-reply-buffer))
2541 message-cite-function)
2542 (delete-windows-on buffer t)
2543 (insert-buffer buffer) ; mark will be set at the end of article.
2547 ;; Add new IDs to References field.
2548 (when (and message-yank-add-new-references (interactive-p))
2551 (message-narrow-to-headers)
2552 (setq refs (message-list-references
2554 (message-fetch-field "References")))
2556 (narrow-to-region start end)
2557 (std11-narrow-to-header)
2558 (when (setq refs (message-list-references
2560 (unless (eq message-yank-add-new-references
2562 (or (message-fetch-field "References")
2563 (message-fetch-field "In-Reply-To")))
2564 (message-fetch-field "Message-ID")))
2566 (message-narrow-to-headers)
2567 (goto-char (point-min))
2568 (let ((case-fold-search t))
2569 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
2571 (goto-char (point-max))))
2573 (list (or (assq 'References message-header-format-alist)
2574 '(References . message-fill-references)))
2575 (list (cons 'References
2576 (mapconcat 'identity (nreverse refs) " "))))
2577 (backward-delete-char 1)))))
2580 (funcall message-cite-function))
2581 (message-exchange-point-and-mark)
2585 (setq message-checksum (message-checksum))))))
2587 (defun message-yank-buffer (buffer)
2588 "Insert BUFFER into the current buffer and quote it."
2589 (interactive "bYank buffer: ")
2590 (let ((message-reply-buffer buffer))
2591 (save-window-excursion
2592 (message-yank-original))))
2594 (defun message-buffers ()
2595 "Return a list of active message buffers."
2598 (dolist (buffer (buffer-list t))
2600 (when (and (eq major-mode 'message-mode)
2601 (null message-sent-message-via))
2602 (push (buffer-name buffer) buffers))))
2603 (nreverse buffers)))
2605 (defun message-cite-original-without-signature ()
2606 "Cite function in the standard Message manner."
2607 (let ((start (point))
2610 (when message-indent-citation-function
2611 (if (listp message-indent-citation-function)
2612 message-indent-citation-function
2613 (list message-indent-citation-function))))
2614 (message-reply-headers (or message-reply-headers
2615 (make-mail-header))))
2616 (mail-header-set-from message-reply-headers
2620 (if (search-forward "\n\n" nil t)
2623 (or (message-fetch-field "from")
2628 (when (re-search-backward message-signature-separator start t)
2629 ;; Also peel off any blank lines before the signature.
2631 (while (looking-at "^[ \t]*$")
2634 (delete-region (point) end)
2635 (unless (search-backward "\n\n" start t)
2636 ;; Insert a blank line if it is peeled off.
2640 (funcall (pop functions)))
2641 (when message-citation-line-function
2644 (funcall message-citation-line-function))))
2646 (eval-when-compile (defvar mail-citation-hook)) ;Compiler directive
2647 (defun message-cite-original ()
2648 "Cite function in the standard Message manner."
2649 (if (and (boundp 'mail-citation-hook)
2651 (run-hooks 'mail-citation-hook)
2652 (let ((start (point))
2655 (when message-indent-citation-function
2656 (if (listp message-indent-citation-function)
2657 message-indent-citation-function
2658 (list message-indent-citation-function))))
2659 (message-reply-headers (or message-reply-headers
2660 (make-mail-header))))
2661 (mail-header-set-from message-reply-headers
2665 (if (search-forward "\n\n" nil t)
2668 (or (message-fetch-field "from")
2672 (funcall (pop functions)))
2673 (when message-citation-line-function
2676 (funcall message-citation-line-function)))))
2678 (defun message-insert-citation-line ()
2679 "Insert a simple citation line."
2680 (when message-reply-headers
2681 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
2683 (defun message-position-on-field (header &rest afters)
2684 (let ((case-fold-search t))
2687 (goto-char (point-min))
2690 (concat "^" (regexp-quote mail-header-separator) "$"))
2691 (match-beginning 0)))
2692 (goto-char (point-min))
2693 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
2695 (re-search-forward "^[^ \t]" nil 'move)
2697 (skip-chars-backward "\n")
2700 (not (re-search-forward
2701 (concat "^" (regexp-quote (car afters)) ":")
2705 (re-search-forward "^[^ \t]" nil 'move)
2706 (beginning-of-line))
2707 (insert header ": \n")
2711 (defun message-remove-signature ()
2712 "Remove the signature from the text between point and mark.
2713 The text will also be indented the normal way."
2715 (let ((start (point))
2717 (if (not (re-search-forward message-signature-separator (mark t) t))
2718 ;; No signature here, so we just indent the cited text.
2719 (message-indent-citation)
2720 ;; Find the last non-empty line.
2722 (while (looking-at "[ \t]*$")
2725 (setq mark (set-marker (make-marker) (point)))
2727 (message-indent-citation)
2728 ;; Enable undoing the deletion.
2730 (delete-region mark (mark t))
2731 (set-marker mark nil)))))
2736 ;;; Sending messages
2739 ;; Avoid byte-compile warning.
2740 (defvar message-encoding-buffer nil)
2741 (defvar message-edit-buffer nil)
2742 (defvar message-mime-mode nil)
2744 (defun message-send-and-exit (&optional arg)
2745 "Send message like `message-send', then, if no errors, exit from mail buffer."
2747 (let ((buf (current-buffer))
2748 (actions message-exit-actions)
2749 (frame (selected-frame))
2750 (org-frame message-original-frame))
2751 (when (and (message-send arg)
2753 (if message-kill-buffer-on-exit
2756 (when (eq buf (current-buffer))
2757 (message-bury buf)))
2758 (message-do-actions actions)
2759 (message-delete-frame frame org-frame)
2762 (defun message-dont-send ()
2763 "Don't send the message you have been editing."
2765 (message-save-drafts)
2766 (let ((actions message-postpone-actions)
2767 (frame (selected-frame))
2768 (org-frame message-original-frame))
2769 (message-bury (current-buffer))
2770 (message-do-actions actions)
2771 (message-delete-frame frame org-frame)))
2773 (defun message-kill-buffer ()
2774 "Kill the current buffer."
2776 (when (or (not (buffer-modified-p))
2777 (eq t message-kill-buffer-query-function)
2778 (funcall message-kill-buffer-query-function
2779 "The buffer modified; kill anyway? "))
2780 (let ((actions message-kill-actions)
2781 (frame (selected-frame))
2782 (org-frame message-original-frame))
2783 (setq buffer-file-name nil)
2784 (kill-buffer (current-buffer))
2785 (message-do-actions actions)
2786 (message-delete-frame frame org-frame)))
2789 (defun message-mimic-kill-buffer ()
2790 "Kill the current buffer with query."
2792 (unless (eq 'message-mode major-mode)
2793 (error "%s must be invoked from a message buffer." this-command))
2794 (let ((command this-command)
2795 (bufname (read-buffer (format "Kill buffer: (default %s) "
2797 (if (or (not bufname)
2798 (string-equal bufname "")
2799 (string-equal bufname (buffer-name)))
2800 (message-kill-buffer)
2801 (message "%s must be invoked only for the current buffer." command))))
2803 (defun message-delete-frame (frame org-frame)
2804 "Delete frame for editing message."
2805 (when (and (or (static-if (featurep 'xemacs)
2806 (device-on-window-system-p)
2808 (>= emacs-major-version 20))
2809 (or (and (eq message-delete-frame-on-exit t)
2810 (select-frame frame)
2811 (or (eq frame org-frame)
2813 (y-or-n-p "Delete this frame?")
2815 (and (eq message-delete-frame-on-exit 'ask)
2816 (select-frame frame)
2818 (y-or-n-p "Delete this frame?")
2820 (delete-frame frame)))
2822 (defun message-bury (buffer)
2823 "Bury this mail BUFFER."
2824 (let ((newbuf (other-buffer buffer)))
2825 (bury-buffer buffer)
2826 (if (and (fboundp 'frame-parameters)
2827 (cdr (assq 'dedicated (frame-parameters)))
2828 (not (null (delq (selected-frame) (visible-frame-list)))))
2829 (delete-frame (selected-frame))
2830 (switch-to-buffer newbuf))))
2832 (defun message-send (&optional arg)
2833 "Send the message in the current buffer.
2834 If `message-interactive' is non-nil, wait for success indication or
2835 error messages, and inform user.
2836 Otherwise any failure is reported in a message back to the user from
2838 The usage of ARG is defined by the instance that called Message.
2839 It should typically alter the sending method in some way or other."
2842 (when (or (buffer-modified-p)
2843 (message-check-element 'unchanged)
2844 (y-or-n-p "No changes in the buffer; really send? "))
2845 ;; Make it possible to undo the coming changes.
2847 (let ((inhibit-read-only t))
2848 (put-text-property (point-min) (point-max) 'read-only nil))
2849 (run-hooks 'message-send-hook)
2850 (message-fix-before-sending)
2851 (message message-sending-message)
2852 (let ((message-encoding-buffer
2853 (message-generate-new-buffer-clone-locals " message encoding"))
2854 (message-edit-buffer (current-buffer))
2855 (message-mime-mode mime-edit-mode-flag)
2856 (alist message-send-method-alist)
2859 (message-options message-options))
2860 (message-options-set-recipient)
2862 (set-buffer message-encoding-buffer)
2864 ;; Avoid copying text props.
2865 (let (message-invisibles)
2867 (with-current-buffer message-edit-buffer
2868 (setq message-invisibles (message-find-invisible-regions))
2869 (buffer-substring-no-properties (point-min) (point-max))))
2870 ;; Inherit the invisible property of texts to make MIME-Edit
2871 ;; find the MIME part boundaries.
2872 (dolist (region message-invisibles)
2873 (put-text-property (car region) (cdr region) 'invisible t)))
2874 (funcall message-encode-function)
2876 (setq elem (pop alist)))
2877 (when (funcall (cadr elem))
2878 (when (and (or (not (memq (car elem)
2879 message-sent-message-via))
2880 (if (or (message-gnksa-enable-p 'multiple-copies)
2881 (not (eq (car elem) 'news)))
2884 "Already sent message via %s; resend? "
2886 (error "Denied posting -- multiple copies.")))
2887 (setq success (funcall (caddr elem) arg)))
2889 (unless (or sent (not success))
2890 (error "No methods specified to send by"))
2892 (when (and success sent)
2895 (run-hooks 'message-sent-hook))
2896 (message "Sending...done")
2897 ;; Mark the buffer as unmodified and delete auto-save.
2898 (set-buffer-modified-p nil)
2899 (delete-auto-save-file-if-necessary t)
2900 (message-disassociate-draft)
2901 ;; Delete other mail buffers and stuff.
2902 (message-do-send-housekeeping)
2903 (message-do-actions message-send-actions)
2906 (kill-buffer message-encoding-buffer)))))
2908 (defun message-send-via-mail (arg)
2909 "Send the current message via mail."
2910 (message-send-mail arg))
2912 (defun message-send-via-news (arg)
2913 "Send the current message via news."
2914 (message-send-news arg))
2916 (defmacro message-check (type &rest forms)
2917 "Eval FORMS if TYPE is to be checked."
2918 `(or (message-check-element ,type)
2922 (put 'message-check 'lisp-indent-function 1)
2923 (put 'message-check 'edebug-form-spec '(form body))
2925 ;; This function will be used by MIME-Edit when inserting invisible parts.
2926 (defun message-invisible-region (start end)
2927 (if (featurep 'xemacs)
2930 (eq (following-char) ?\n))
2931 (setq start (1+ start)))
2933 (goto-char (1- end))
2934 (eq (following-char) ?\n))
2935 (setq end (1- end))))
2936 (put-text-property start end 'invisible t)
2937 (if (eq 'message-mode major-mode)
2938 (put-text-property start end 'message-invisible t)))
2940 (eval-after-load "invisible"
2941 '(defalias 'invisible-region 'message-invisible-region))
2943 (defun message-find-invisible-regions ()
2944 "Find invisible texts with the property `message-invisible' and
2945 return a list of points."
2949 (while (setq from (text-property-any to (point-max)
2950 'message-invisible t))
2951 (setq to (or (text-property-not-all from (point-max)
2952 'message-invisible t)
2954 (push (cons from to) regions))
2957 (defun message-fix-before-sending ()
2958 "Do various things to make the message nice before sending it."
2959 ;; Make sure there's a newline at the end of the message.
2961 (goto-char (point-max))
2964 ;; Expose all invisible text with the property `message-invisible'.
2965 ;; We should believe that the things might be created by MIME-Edit.
2966 (let ((message-invisibles (message-find-invisible-regions)))
2967 (dolist (region message-invisibles)
2968 (put-text-property (car region) (cdr region) 'invisible nil))
2969 ;; Expose all invisible text.
2970 (message-check 'invisible-text
2971 (when (text-property-any (point-min) (point-max) 'invisible t)
2972 (put-text-property (point-min) (point-max) 'invisible nil)
2973 (unless (yes-or-no-p
2974 "Invisible text found and made visible; continue posting? ")
2975 (error "Invisible text found and made visible"))))
2976 ;; Hide again all text with the property `message-invisible'.
2977 ;; It is needed to make MIME-Edit find the MIME part boundaries.
2978 (dolist (region message-invisibles)
2979 (put-text-property (car region) (cdr region) 'invisible t))))
2981 (defun message-add-action (action &rest types)
2982 "Add ACTION to be performed when doing an exit of type TYPES."
2985 (set (setq var (intern (format "message-%s-actions" (pop types))))
2986 (nconc (symbol-value var) (list action))))))
2988 (defun message-do-actions (actions)
2989 "Perform all actions in ACTIONS."
2990 ;; Now perform actions on successful sending.
2994 ;; A simple function.
2995 ((message-functionp (car actions))
2996 (funcall (car actions)))
2997 ;; Something to be evaled.
2999 (eval (car actions)))))
3002 (defsubst message-maybe-split-and-send-mail ()
3003 "Split a message if necessary, and send it via mail.
3004 Returns nil if sending succeeded, returns any string if sending failed.
3005 This sub function is for exclusive use of `message-send-mail'."
3006 (let ((mime-edit-split-ignored-field-regexp
3007 mime-edit-split-ignored-field-regexp)
3008 (case-fold-search t)
3010 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
3011 (setq mime-edit-split-ignored-field-regexp
3012 (concat (substring mime-edit-split-ignored-field-regexp
3013 0 (match-beginning 0))
3014 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
3015 "_so_don't_rape_it!"
3016 (substring mime-edit-split-ignored-field-regexp
3020 (catch 'message-sending-mail-failure
3021 (mime-edit-maybe-split-and-send
3026 (std11-narrow-to-header mail-header-separator)
3027 (goto-char (point-min))
3028 (when (re-search-forward "^Message-ID:" nil t)
3029 (delete-region (match-end 0) (std11-field-end))
3030 (insert " " (message-make-message-id))))
3032 (funcall message-send-mail-function)
3034 (throw 'message-sending-mail-failure err))))))
3038 (funcall message-send-mail-function)
3042 (if (eq 'error (car failure))
3044 (prin1-to-string failure)))))
3046 (defun message-send-mail-partially ()
3047 "Send mail as message/partial."
3048 ;; replace the header delimiter with a blank line
3049 (goto-char (point-min))
3051 (concat "^" (regexp-quote mail-header-separator) "\n"))
3052 (replace-match "\n")
3053 (run-hooks 'message-send-mail-hook)
3054 (let ((p (goto-char (point-min)))
3055 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
3056 (curbuf (current-buffer))
3057 (id (message-make-message-id)) (n 1)
3058 plist total header required-mail-headers)
3060 (if (< (point-max) (+ p message-send-mail-partially-limit))
3061 (goto-char (point-max))
3062 (goto-char (+ p message-send-mail-partially-limit))
3064 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
3067 (setq total (length plist))
3068 (push (point-max) plist)
3069 (setq plist (nreverse plist))
3072 (setq p (pop plist))
3075 (copy-to-buffer tembuf p (car plist))
3077 (goto-char (point-min))
3080 (goto-char (point-min))
3081 (narrow-to-region (point) (point))
3084 (setq header (buffer-substring (point-min) (point)))
3085 (goto-char (point-min))
3086 (narrow-to-region (point) (point))
3088 (message-remove-header "Mime-Version")
3089 (message-remove-header "Content-Type")
3090 (message-remove-header "Content-Transfer-Encoding")
3091 (message-remove-header "Message-ID")
3092 (message-remove-header "Lines")
3093 (goto-char (point-max))
3094 (insert "Mime-Version: 1.0\n")
3095 (setq header (buffer-substring (point-min) (point-max))))
3096 (goto-char (point-max))
3097 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n"
3099 (let ((mail-header-separator ""))
3100 (when (memq 'Message-ID message-required-mail-headers)
3101 (insert "Message-ID: " (message-make-message-id) "\n"))
3102 (when (memq 'Lines message-required-mail-headers)
3103 (let ((mail-header-separator ""))
3104 (insert "Lines: " (message-make-lines) "\n")))
3105 (message-goto-subject)
3107 (insert (format " (%d/%d)" n total))
3108 (goto-char (point-max))
3111 (mm-with-unibyte-current-buffer
3112 (funcall message-send-mail-function)))
3114 (setq p (pop plist))
3116 (kill-buffer tembuf))))
3118 (defun message-send-mail (&optional arg)
3119 (require 'mail-utils)
3120 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
3121 (case-fold-search nil)
3122 (news (message-news-p))
3123 (message-this-is-mail t)
3126 (message-narrow-to-headers)
3127 ;; Insert some headers.
3128 (let ((message-deletable-headers
3129 (if news nil message-deletable-headers)))
3130 (message-generate-headers message-required-mail-headers))
3131 ;; Let the user do all of the above.
3132 (run-hooks 'message-header-hook))
3133 (if (not (message-check-mail-syntax))
3141 (insert-buffer message-encoding-buffer)
3142 ;; Remove some headers.
3144 (message-narrow-to-headers)
3145 ;; We Semi-gnus people have no use for it.
3146 ;; ;; We (re)generate the Lines header.
3147 ;; (when (memq 'Lines message-required-mail-headers)
3148 ;; (message-generate-headers '(Lines)))
3149 ;; Remove some headers.
3150 (message-remove-header message-ignored-mail-headers t))
3151 (goto-char (point-max))
3152 ;; require one newline at the end.
3153 (or (= (preceding-char) ?\n)
3157 (message-narrow-to-headers)
3159 (or (message-fetch-field "cc")
3160 (message-fetch-field "to"))
3161 (let ((ct (mime-read-Content-Type)))
3163 (and (eq 'text (cdr (assq 'type ct)))
3164 (eq 'plain (cdr (assq 'subtype ct))))))))
3165 (message-insert-courtesy-copy))
3166 (setq failure (message-maybe-split-and-send-mail)))
3167 (kill-buffer tembuf))
3168 (set-buffer message-edit-buffer)
3171 (message "Couldn't send message via mail: %s" failure)
3173 (push 'mail message-sent-message-via)))))
3175 (defun message-send-mail-with-sendmail ()
3176 "Send off the prepared buffer with sendmail."
3177 (let ((errbuf (if message-interactive
3178 (message-generate-new-buffer-clone-locals
3181 resend-to-addresses delimline)
3182 (let ((case-fold-search t))
3184 (message-narrow-to-headers)
3185 (setq resend-to-addresses (message-fetch-field "resent-to")))
3186 ;; Change header-delimiter to be what sendmail expects.
3187 (goto-char (point-min))
3189 (concat "^" (regexp-quote mail-header-separator) "\n"))
3190 (replace-match "\n")
3192 (setq delimline (point-marker))
3193 (run-hooks 'message-send-mail-hook)
3194 ;; Insert an extra newline if we need it to work around
3195 ;; Sun's bug that swallows newlines.
3196 (goto-char (1+ delimline))
3197 (when (eval message-mailer-swallows-blank-line)
3199 (when message-interactive
3203 (let ((default-directory "/"))
3205 (apply 'call-process-region
3206 (append (list (point-min) (point-max)
3207 (if (boundp 'sendmail-program)
3209 "/usr/lib/sendmail")
3210 nil errbuf nil "-oi")
3211 ;; Always specify who from,
3212 ;; since some systems have broken sendmails.
3213 ;; But some systems are more broken with -f, so
3214 ;; we'll let users override this.
3215 (if (null message-sendmail-f-is-evil)
3216 (list "-f" (message-make-address)))
3217 ;; These mean "report errors by mail"
3218 ;; and "deliver in background".
3219 (if (null message-interactive) '("-oem" "-odb"))
3220 ;; Get the addresses from the message
3221 ;; unless this is a resend.
3222 ;; We must not do that for a resend
3223 ;; because we would find the original addresses.
3224 ;; For a resend, include the specific addresses.
3225 (if resend-to-addresses
3226 (list resend-to-addresses)
3228 (when message-interactive
3231 (goto-char (point-min))
3232 (while (re-search-forward "\n\n* *" nil t)
3233 (replace-match "; "))
3234 (if (not (zerop (buffer-size)))
3235 (error "Sending...failed to %s"
3236 (buffer-substring (point-min) (point-max)))))
3237 (when (bufferp errbuf)
3238 (kill-buffer errbuf)))))
3240 (defun message-send-mail-with-qmail ()
3241 "Pass the prepared message buffer to qmail-inject.
3242 Refer to the documentation for the variable `message-send-mail-function'
3243 to find out how to use this."
3244 ;; replace the header delimiter with a blank line
3245 (goto-char (point-min))
3247 (concat "^" (regexp-quote mail-header-separator) "\n"))
3248 (replace-match "\n")
3250 (run-hooks 'message-send-mail-hook)
3255 'call-process-region 1 (point-max) message-qmail-inject-program
3257 ;; qmail-inject's default behaviour is to look for addresses on the
3258 ;; command line; if there're none, it scans the headers.
3259 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
3261 ;; in general, ALL of qmail-inject's defaults are perfect for simply
3262 ;; reading a formatted (i. e., at least a To: or Resent-To header)
3263 ;; message from stdin.
3265 ;; qmail also has the advantage of not having been raped by
3266 ;; various vendors, so we don't have to allow for that, either --
3267 ;; compare this with message-send-mail-with-sendmail and weep
3268 ;; for sendmail's lost innocence.
3270 ;; all this is way cool coz it lets us keep the arguments entirely
3271 ;; free for -inject-arguments -- a big win for the user and for us
3272 ;; since we don't have to play that double-guessing game and the user
3273 ;; gets full control (no gestapo'ish -f's, for instance). --sj
3274 message-qmail-inject-args))
3275 ;; qmail-inject doesn't say anything on it's stdout/stderr,
3276 ;; we have to look at the retval instead
3278 (1 (error "qmail-inject reported permanent failure"))
3279 (111 (error "qmail-inject reported transient failure"))
3280 ;; should never happen
3281 (t (error "qmail-inject reported unknown failure"))))
3283 (defun message-send-mail-with-mh ()
3284 "Send the prepared message buffer with mh."
3285 (let ((mh-previous-window-config nil)
3286 (name (mh-new-draft-name)))
3287 (setq buffer-file-name name)
3288 ;; MH wants to generate these headers itself.
3289 (when message-mh-deletable-headers
3290 (let ((headers message-mh-deletable-headers))
3292 (goto-char (point-min))
3293 (and (re-search-forward
3294 (concat "^" (symbol-name (car headers)) ": *") nil t)
3295 (message-delete-line))
3297 (run-hooks 'message-send-mail-hook)
3298 ;; Pass it on to mh.
3301 (defun message-send-mail-with-smtp ()
3302 "Send off the prepared buffer with SMTP."
3303 (require 'smtp) ; XXX
3304 (let ((case-fold-search t)
3307 (message-narrow-to-headers)
3309 ;; XXX: Should be replaced by better one.
3310 (smtp-deduce-address-list (current-buffer)
3311 (point-min) (point-max)))
3312 ;; Remove BCC lines.
3313 (message-remove-header "bcc"))
3314 ;; replace the header delimiter with a blank line.
3315 (goto-char (point-min))
3317 (concat "^" (regexp-quote mail-header-separator) "\n"))
3318 (replace-match "\n")
3320 (run-hooks 'message-send-mail-hook)
3322 (static-if (fboundp 'smtp-send-buffer)
3323 (smtp-send-buffer user-mail-address recipients
3325 (let ((result (smtp-via-smtp user-mail-address recipients
3327 (unless (eq result t)
3328 (error "Sending failed; %s" result))))
3329 (error "Sending failed; no recipients"))))
3331 (defsubst message-maybe-split-and-send-news (method)
3332 "Split a message if necessary, and send it via news.
3333 Returns nil if sending succeeded, returns t if sending failed.
3334 This sub function is for exclusive use of `message-send-news'."
3335 (let ((mime-edit-split-ignored-field-regexp
3336 mime-edit-split-ignored-field-regexp)
3337 (case-fold-search t))
3338 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
3339 (setq mime-edit-split-ignored-field-regexp
3340 (concat (substring mime-edit-split-ignored-field-regexp
3341 0 (match-beginning 0))
3342 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
3343 "_so_don't_rape_it!"
3344 (substring mime-edit-split-ignored-field-regexp
3347 (catch 'message-sending-news-failure
3348 (mime-edit-maybe-split-and-send
3353 (std11-narrow-to-header mail-header-separator)
3354 (goto-char (point-min))
3355 (when (re-search-forward "^Message-ID:" nil t)
3356 (delete-region (match-end 0) (std11-field-end))
3357 (insert " " (message-make-message-id))))
3358 (unless (funcall message-send-news-function method)
3359 (throw 'message-sending-news-failure t)))))
3361 (not (funcall message-send-news-function method)))))
3363 (defun message-send-news (&optional arg)
3364 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
3365 (case-fold-search nil)
3366 (method (if (message-functionp message-post-method)
3367 (funcall message-post-method arg)
3368 message-post-method))
3369 (group-name-charset (gnus-group-name-charset method ""))
3370 (message-syntax-checks
3372 (cons '(existing-newsgroups . disabled)
3373 message-syntax-checks)
3374 message-syntax-checks))
3375 (message-this-is-news t)
3378 (message-narrow-to-headers)
3379 ;; Insert some headers.
3380 (message-generate-headers message-required-news-headers)
3381 ;; Let the user do all of the above.
3382 (run-hooks 'message-header-hook))
3383 (when group-name-charset
3384 (setq message-syntax-checks
3385 (cons '(valid-newsgroups . disabled)
3386 message-syntax-checks)))
3387 (message-cleanup-headers)
3388 (if (not (message-check-news-syntax))
3393 (buffer-disable-undo)
3395 (insert-buffer message-encoding-buffer)
3396 ;; Remove some headers.
3398 (message-narrow-to-headers)
3399 ;; We Semi-gnus people have no use for it.
3400 ;; ;; We (re)generate the Lines header.
3401 ;; (when (memq 'Lines message-required-mail-headers)
3402 ;; (message-generate-headers '(Lines)))
3403 ;; Remove some headers.
3404 (message-remove-header message-ignored-news-headers t))
3405 (goto-char (point-max))
3406 ;; require one newline at the end.
3407 (or (= (preceding-char) ?\n)
3409 (setq result (message-maybe-split-and-send-news method)))
3410 (kill-buffer tembuf))
3411 (set-buffer message-edit-buffer)
3414 (message "Couldn't send message via news: %s"
3415 (nnheader-get-report (car method)))
3417 (push 'news message-sent-message-via)))))
3419 ;; 1997-09-29 by MORIOKA Tomohiko
3420 (defun message-send-news-with-gnus (method)
3421 (let ((case-fold-search t))
3422 ;; Remove the delimiter.
3423 (goto-char (point-min))
3425 (concat "^" (regexp-quote mail-header-separator) "\n"))
3426 (replace-match "\n")
3428 (run-hooks 'message-send-news-hook)
3429 (gnus-open-server method)
3430 (message "Sending news with %s..." (gnus-server-string method))
3431 (gnus-request-post method)
3435 ;;; Header generation & syntax checking.
3438 (defun message-check-element (type)
3439 "Return non-nil if this TYPE is not to be checked."
3440 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
3442 (let ((able (assq type message-syntax-checks)))
3444 (eq (cdr able) 'disabled)))))
3446 (defun message-check-news-syntax ()
3447 "Check the syntax of the message."
3452 ;; We narrow to the headers and check them first.
3455 (message-narrow-to-headers)
3456 (message-check-news-header-syntax)))
3459 (set-buffer message-edit-buffer)
3460 (message-check-news-body-syntax))))))
3462 (defun message-check-news-header-syntax ()
3464 ;; Check Newsgroups header.
3465 (message-check 'newsgroups
3466 (let ((group (message-fetch-field "newsgroups")))
3469 (not (string-match "\\`[ \t]*\\'" group)))
3472 "The newsgroups field is empty or missing. Posting is denied.")))))
3473 ;; Check the Subject header.
3474 (message-check 'subject
3475 (let* ((case-fold-search t)
3476 (subject (message-fetch-field "subject")))
3479 (not (string-match "\\`[ \t]*\\'" subject)))
3482 "The subject field is empty or missing. Posting is denied.")))))
3483 ;; Check for commands in Subject.
3484 (message-check 'subject-cmsg
3485 (if (string-match "^cmsg " (message-fetch-field "subject"))
3487 "The control code \"cmsg\" is in the subject. Really post? ")
3489 ;; Check for multiple identical headers.
3490 (message-check 'multiple-headers
3492 (while (and (not found)
3493 (re-search-forward "^[^ \t:]+: " nil t))
3495 (or (re-search-forward
3500 (match-beginning 0) (- (match-end 0) 2))))
3505 (y-or-n-p (format "Multiple %s headers. Really post? " found))
3507 ;; Check for Version and Sendsys.
3508 (message-check 'sendsys
3509 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
3511 (format "The article contains a %s command. Really post? "
3512 (buffer-substring (match-beginning 0)
3513 (1- (match-end 0)))))
3515 ;; See whether we can shorten Followup-To.
3516 (message-check 'shorten-followup-to
3517 (let ((newsgroups (message-fetch-field "newsgroups"))
3518 (followup-to (message-fetch-field "followup-to"))
3520 (when (and newsgroups
3521 (string-match "," newsgroups)
3526 (setq to (completing-read
3527 "Followups to: (default all groups) "
3528 (mapcar (lambda (g) (list g))
3530 (message-tokenize-header
3532 (goto-char (point-min))
3533 (insert "Followup-To: " to "\n"))
3535 ;; Check "Shoot me".
3536 (message-check 'shoot
3537 (if (re-search-forward
3538 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
3539 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
3541 ;; Check for Approved.
3542 (message-check 'approved
3543 (if (re-search-forward "^Approved:" nil t)
3544 (y-or-n-p "The article contains an Approved header. Really post? ")
3546 ;; Check the Message-ID header.
3547 (message-check 'message-id
3548 (let* ((case-fold-search t)
3549 (message-id (message-fetch-field "message-id" t)))
3550 (or (not message-id)
3551 ;; Is there an @ in the ID?
3552 (and (string-match "@" message-id)
3553 ;; Is there a dot in the ID?
3554 (string-match "@[^.]*\\." message-id)
3555 ;; Does the ID end with a dot?
3556 (not (string-match "\\.>" message-id)))
3558 (format "The Message-ID looks strange: \"%s\". Really post? "
3560 ;; Check the Newsgroups & Followup-To headers.
3561 (message-check 'existing-newsgroups
3562 (let* ((case-fold-search t)
3563 (newsgroups (message-fetch-field "newsgroups"))
3564 (followup-to (message-fetch-field "followup-to"))
3565 (groups (message-tokenize-header
3567 (concat newsgroups "," followup-to)
3569 (hashtb (and (boundp 'gnus-active-hashtb)
3570 gnus-active-hashtb))
3573 (when (and (not (boundp (intern (car groups) hashtb)))
3574 (not (equal (car groups) "poster")))
3575 (push (car groups) errors))
3578 ;; Gnus is not running.
3580 (not (boundp 'gnus-read-active-file)))
3582 ;; We don't have all the group names.
3583 ((and (or (not gnus-read-active-file)
3584 (eq gnus-read-active-file 'some))
3588 "Really post to %s possibly unknown group%s: %s? "
3589 (if (= (length errors) 1) "this" "these")
3590 (if (= (length errors) 1) "" "s")
3591 (mapconcat 'identity errors ", "))))
3592 ;; There were no errors.
3595 ;; There are unknown groups.
3599 "Really post to %s unknown group%s: %s? "
3600 (if (= (length errors) 1) "this" "these")
3601 (if (= (length errors) 1) "" "s")
3602 (mapconcat 'identity errors ", ")))))))
3603 ;; Check the Newsgroups & Followup-To headers for syntax errors.
3604 (message-check 'valid-newsgroups
3605 (let ((case-fold-search t)
3606 (headers '("Newsgroups" "Followup-To"))
3608 (while (and headers (not error))
3609 (when (setq header (mail-fetch-field (car headers)))
3613 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
3618 (not (string-match "\\.\\'\\|\\.\\." g)))
3619 (message-tokenize-header header ","))))
3626 (format "The %s header looks odd: \"%s\". Really post? "
3627 (car headers) header)))))
3628 (message-check 'repeated-newsgroups
3629 (let ((case-fold-search t)
3630 (headers '("Newsgroups" "Followup-To"))
3631 header error groups group)
3634 (when (setq header (mail-fetch-field (pop headers)))
3635 (setq groups (message-tokenize-header header ","))
3636 (while (setq group (pop groups))
3637 (when (member group groups)
3643 (format "Group %s is repeated in headers. Really post? " error)))))
3644 ;; Check the From header.
3645 (message-check 'from
3646 (let* ((case-fold-search t)
3647 (from (message-fetch-field "from"))
3651 (message "There is no From line. Posting is denied.")
3653 ((or (not (string-match
3655 (setq ad (nth 1 (mail-extract-address-components
3656 from))))) ;larsi@ifi
3657 (string-match "\\.\\." ad) ;larsi@ifi..uio
3658 (string-match "@\\." ad) ;larsi@.ifi.uio
3659 (string-match "\\.$" ad) ;larsi@ifi.uio.
3660 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
3661 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
3663 "Denied posting -- the From looks strange: \"%s\"." from)
3667 (defun message-check-news-body-syntax ()
3669 ;; Check for long lines.
3670 (message-check 'long-lines
3671 (goto-char (point-min))
3673 (concat "^" (regexp-quote mail-header-separator) "$"))
3677 mime-edit-tag-regexp)
3680 (< (- (point) p) 80)))
3681 (zerop (forward-line 1))))
3685 "You have lines longer than 79 characters. Really post? ")))
3686 ;; Check whether the article is empty.
3687 (message-check 'empty
3688 (goto-char (point-min))
3690 (concat "^" (regexp-quote mail-header-separator) "$"))
3693 (goto-char (point-max))
3694 (re-search-backward message-signature-separator nil t)
3696 (or (re-search-backward "[^ \n\t]" b t)
3697 (if (message-gnksa-enable-p 'empty-article)
3698 (y-or-n-p "Empty article. Really post? ")
3699 (message "Denied posting -- Empty article.")
3701 ;; Check for control characters.
3702 (message-check 'control-chars
3703 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
3705 "The article contains control characters. Really post? ")
3707 ;; Check 8bit characters.
3708 (message-check '8bit
3709 (message-check-8bit))
3710 ;; Check excessive size.
3711 (message-check 'size
3712 (if (> (buffer-size) 60000)
3714 (format "The article is %d octets long. Really post? "
3717 ;; Check whether any new text has been added.
3718 (message-check 'new-text
3720 (not message-checksum)
3721 (not (eq (message-checksum) message-checksum))
3722 (if (message-gnksa-enable-p 'quoted-text-only)
3724 "It looks like no new text has been added. Really post? ")
3725 (message "Denied posting -- no new text has been added.")
3727 ;; Check the length of the signature.
3728 (message-check 'signature
3729 (goto-char (point-max))
3730 (if (> (count-lines (point) (point-max)) 5)
3733 "Your .sig is %d lines; it should be max 4. Really post? "
3734 (1- (count-lines (point) (point-max)))))
3736 ;; Ensure that text follows last quoted portion.
3737 (message-check 'quoting-style
3738 (goto-char (point-max))
3739 (let ((no-problem t))
3740 (when (search-backward-regexp "^>[^\n]*\n" nil t)
3741 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
3744 (if (message-gnksa-enable-p 'quoted-text-only)
3745 (y-or-n-p "Your text should follow quoted text. Really post? ")
3747 (goto-char (point-min))
3749 (concat "^" (regexp-quote mail-header-separator) "$"))
3750 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
3751 (y-or-n-p "Your text should follow quoted text. Really post? ")
3752 (message "Denied posting -- only quoted text.")
3755 (defun message-check-mail-syntax ()
3756 "Check the syntax of the message."
3761 ;; We narrow to the headers and check them first.
3764 (message-narrow-to-headers)
3765 (message-check-mail-header-syntax)))
3768 (set-buffer message-edit-buffer)
3769 (message-check-mail-body-syntax))))))
3771 (defun message-check-mail-header-syntax ()
3774 (defun message-check-mail-body-syntax ()
3776 ;; Check 8bit characters.
3777 (message-check '8bit
3778 (message-check-8bit)
3781 (defun message-check-8bit ()
3782 "Check the article contains 8bit characters."
3784 (set-buffer message-encoding-buffer)
3785 (message-narrow-to-headers)
3786 (let* ((case-fold-search t)
3787 (field-value (message-fetch-field "content-transfer-encoding")))
3788 (if (and field-value
3789 (member (downcase field-value) message-8bit-encoding-list))
3792 (set-buffer (get-buffer-create " message syntax"))
3794 (goto-char (point-min))
3795 (set-buffer-multibyte nil)
3796 (insert-buffer message-encoding-buffer)
3797 (goto-char (point-min))
3798 (if (re-search-forward "[^\x00-\x7f]" nil t)
3800 "The article contains 8bit characters. Really post? ")
3803 (defun message-checksum ()
3804 "Return a \"checksum\" for the current buffer."
3807 (goto-char (point-min))
3809 (concat "^" (regexp-quote mail-header-separator) "$"))
3811 (when (not (looking-at "[ \t\n]"))
3812 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
3817 (defun message-do-fcc ()
3818 "Process Fcc headers in the current buffer."
3819 (let ((case-fold-search t)
3820 (coding-system-for-write 'raw-text)
3821 (output-coding-system 'raw-text)
3824 (set-buffer (get-buffer-create " *message temp*"))
3826 (insert-buffer-substring message-encoding-buffer)
3828 (message-narrow-to-headers)
3829 (while (setq file (message-fetch-field "fcc"))
3831 (message-remove-header "fcc" nil t)))
3832 (goto-char (point-min))
3833 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
3834 (replace-match "" t t)
3835 ;; Process FCC operations.
3837 (setq file (pop list))
3838 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
3839 ;; Pipe the article to the program in question.
3840 (call-process-region (point-min) (point-max) shell-file-name
3841 nil nil nil shell-command-switch
3842 (match-string 1 file))
3843 ;; Save the article.
3844 (setq file (expand-file-name file))
3845 (unless (file-exists-p (file-name-directory file))
3846 (make-directory (file-name-directory file) t))
3847 (if (and message-fcc-handler-function
3848 (not (eq message-fcc-handler-function 'rmail-output)))
3849 (funcall message-fcc-handler-function file)
3850 (if (and (file-readable-p file) (mail-file-babyl-p file))
3851 (rmail-output file 1 nil t)
3852 (let ((mail-use-rfc822 t))
3853 (rmail-output file 1 t t))))))
3854 (kill-buffer (current-buffer)))))
3856 (defun message-output (filename)
3857 "Append this article to Unix/babyl mail file FILENAME."
3858 (if (and (file-readable-p filename)
3859 (mail-file-babyl-p filename))
3860 (gnus-output-to-rmail filename t)
3861 (gnus-output-to-mail filename t)))
3863 (defun message-cleanup-headers ()
3864 "Do various automatic cleanups of the headers."
3865 ;; Remove empty lines in the header.
3867 (message-narrow-to-headers)
3868 ;; Remove blank lines.
3869 (while (re-search-forward "^[ \t]*\n" nil t)
3870 (replace-match "" t t))
3872 ;; Correct Newsgroups and Followup-To headers: Change sequence of
3873 ;; spaces to comma and eliminate spaces around commas. Eliminate
3874 ;; embedded line breaks.
3875 (goto-char (point-min))
3876 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
3880 (if (re-search-forward "^[^ \t]" nil t)
3884 (goto-char (point-min))
3885 (while (re-search-forward "\n[ \t]+" nil t)
3886 (replace-match " " t t)) ;No line breaks (too confusing)
3887 (goto-char (point-min))
3888 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
3889 (replace-match "," t t))
3890 (goto-char (point-min))
3891 ;; Remove trailing commas.
3892 (when (re-search-forward ",+$" nil t)
3893 (replace-match "" t t))))))
3895 (defun message-make-date (&optional now)
3896 "Make a valid data header.
3897 If NOW, use that time instead."
3898 (let* ((now (or now (current-time)))
3899 (zone (nth 8 (decode-time now)))
3903 (setq zone (- zone)))
3905 (format-time-string "%d" now)
3906 ;; The month name of the %b spec is locale-specific. Pfff.
3908 (capitalize (car (rassoc (nth 4 (decode-time now))
3909 parse-time-months))))
3910 (format-time-string "%Y %H:%M:%S " now)
3911 ;; We do all of this because XEmacs doesn't have the %z spec.
3912 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
3914 (defun message-make-followup-subject (subject)
3915 "Make a followup Subject."
3917 ((and (eq message-use-subject-re 'guess)
3918 (string-match message-subject-encoded-re-regexp subject))
3920 (message-use-subject-re
3921 (concat "Re: " (message-strip-subject-re subject)))
3924 (defun message-make-message-id ()
3925 "Make a unique Message-ID."
3926 (concat "<" (message-unique-id)
3927 (let ((psubject (save-excursion (message-fetch-field "subject")))
3929 (save-excursion (message-fetch-field "supersedes"))))
3931 (and message-reply-headers
3932 (mail-header-references message-reply-headers)
3933 (mail-header-subject message-reply-headers)
3936 (message-strip-subject-re
3937 (mail-header-subject message-reply-headers))
3938 (message-strip-subject-re psubject))))
3940 (string-match "_-_@" psupersedes)))
3942 "@" (message-make-fqdn) ">"))
3944 (defvar message-unique-id-char nil)
3946 ;; If you ever change this function, make sure the new version
3947 ;; cannot generate IDs that the old version could.
3948 ;; You might for example insert a "." somewhere (not next to another dot
3949 ;; or string boundary), or modify the "fsf" string.
3950 (defun message-unique-id ()
3951 ;; Don't use microseconds from (current-time), they may be unsupported.
3952 ;; Instead we use this randomly inited counter.
3953 (setq message-unique-id-char
3954 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
3955 ;; (current-time) returns 16-bit ints,
3956 ;; and 2^16*25 just fits into 4 digits i base 36.
3958 (let ((tm (current-time)))
3960 (if (memq system-type '(ms-dos emx vax-vms))
3961 (let ((user (downcase (user-login-name))))
3962 (while (string-match "[^a-z0-9_]" user)
3963 (aset user (match-beginning 0) ?_))
3965 (message-number-base36 (user-uid) -1))
3966 (message-number-base36 (+ (car tm)
3967 (lsh (% message-unique-id-char 25) 16)) 4)
3968 (message-number-base36 (+ (nth 1 tm)
3969 (lsh (/ message-unique-id-char 25) 16)) 4)
3970 ;; Append the newsreader name, because while the generated
3971 ;; ID is unique to this newsreader, other newsreaders might
3972 ;; otherwise generate the same ID via another algorithm.
3975 (defun message-number-base36 (num len)
3980 (concat (message-number-base36 (/ num 36) (1- len))
3981 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
3984 (defun message-make-organization ()
3985 "Make an Organization header."
3986 (let* ((organization
3987 (when message-user-organization
3988 (if (message-functionp message-user-organization)
3989 (funcall message-user-organization)
3990 message-user-organization))))
3992 (message-set-work-buffer)
3993 (cond ((stringp organization)
3994 (insert organization))
3995 ((and (eq t organization)
3996 message-user-organization-file
3997 (file-exists-p message-user-organization-file))
3998 (insert-file-contents message-user-organization-file)))
3999 (goto-char (point-min))
4000 (while (re-search-forward "[\t\n]+" nil t)
4001 (replace-match "" t t))
4002 (unless (zerop (buffer-size))
4005 (defun message-make-lines ()
4006 "Count the number of lines and return numeric string."
4011 (int-to-string (count-lines (point) (point-max))))))
4013 (defun message-make-in-reply-to ()
4014 "Return the In-Reply-To header for this message."
4015 (when message-reply-headers
4016 (let ((from (mail-header-from message-reply-headers))
4017 (date (mail-header-date message-reply-headers))
4018 (msg-id (mail-header-message-id message-reply-headers)))
4022 (let ((pair (std11-extract-address-components from)))
4024 (or (car pair) (cadr pair))
4026 (if (or (not date) (string= date ""))
4027 "(unknown date)" date)
4030 (defun message-make-distribution ()
4031 "Make a Distribution header."
4032 (let ((orig-distribution (message-fetch-reply-field "distribution")))
4033 (cond ((message-functionp message-distribution-function)
4034 (funcall message-distribution-function))
4035 (t orig-distribution))))
4037 (defun message-make-expires ()
4038 "Return an Expires header based on `message-expires'."
4039 (let ((current (current-time))
4040 (future (* 1.0 message-expires 60 60 24)))
4041 ;; Add the future to current.
4042 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
4043 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
4044 (message-make-date current)))
4046 (defun message-make-path ()
4048 (let ((login-name (user-login-name)))
4049 (cond ((null message-user-path)
4050 (concat (system-name) "!" login-name))
4051 ((stringp message-user-path)
4052 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
4053 (concat message-user-path "!" login-name))
4056 (defun message-make-from ()
4057 "Make a From header."
4058 (let* ((style message-from-style)
4059 (login (message-make-address))
4061 (or (and (boundp 'user-full-name)
4064 (when (string= fullname "&")
4065 (setq fullname (user-login-name)))
4067 (message-set-work-buffer)
4070 (equal fullname ""))
4072 ((or (eq style 'angles)
4073 (and (not (eq style 'parens))
4074 ;; Use angles if no quoting is needed, or if parens would
4075 ;; need quoting too.
4076 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
4077 (let ((tmp (concat fullname nil)))
4078 (while (string-match "([^()]*)" tmp)
4079 (aset tmp (match-beginning 0) ?-)
4080 (aset tmp (1- (match-end 0)) ?-))
4081 (string-match "[\\()]" tmp)))))
4083 (goto-char (point-min))
4084 ;; Look for a character that cannot appear unquoted
4085 ;; according to RFC 822.
4086 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
4087 ;; Quote fullname, escaping specials.
4088 (goto-char (point-min))
4090 (while (re-search-forward "[\"\\]" nil 1)
4091 (replace-match "\\\\\\&" t))
4093 (insert " <" login ">"))
4094 (t ; 'parens or default
4096 (let ((fullname-start (point)))
4098 (goto-char fullname-start)
4099 ;; RFC 822 says \ and nonmatching parentheses
4100 ;; must be escaped in comments.
4101 ;; Escape every instance of ()\ ...
4102 (while (re-search-forward "[()\\]" nil 1)
4103 (replace-match "\\\\\\&" t))
4104 ;; ... then undo escaping of matching parentheses,
4105 ;; including matching nested parentheses.
4106 (goto-char fullname-start)
4107 (while (re-search-forward
4108 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
4110 (replace-match "\\1(\\3)" t)
4111 (goto-char fullname-start)))
4115 (defun message-make-sender ()
4116 "Return the \"real\" user address.
4117 This function tries to ignore all user modifications, and
4118 give as trustworthy answer as possible."
4119 (concat (user-login-name) "@" (system-name)))
4121 (defun message-make-address ()
4122 "Make the address of the user."
4123 (or (message-user-mail-address)
4124 (concat (user-login-name) "@" (message-make-domain))))
4126 (defun message-user-mail-address ()
4127 "Return the pertinent part of `user-mail-address'."
4128 (when user-mail-address
4129 (if (string-match " " user-mail-address)
4130 (nth 1 (std11-extract-address-components user-mail-address))
4131 user-mail-address)))
4133 (defun message-make-fqdn ()
4134 "Return user's fully qualified domain name."
4135 (let ((system-name (system-name))
4136 (user-mail (message-user-mail-address)))
4138 ((string-match "[^.]\\.[^.]" system-name)
4139 ;; `system-name' returned the right result.
4141 ;; Try `mail-host-address'.
4142 ((and (boundp 'mail-host-address)
4143 (stringp mail-host-address)
4144 (string-match "\\." mail-host-address))
4146 ;; We try `user-mail-address' as a backup.
4148 (string-match "\\." user-mail)
4149 (string-match "@\\(.*\\)\\'" user-mail))
4150 (match-string 1 user-mail))
4151 ;; Default to this bogus thing.
4153 (concat system-name ".i-did-not-set--mail-host-address--so-shoot-me")))))
4155 (defun message-make-host-name ()
4156 "Return the name of the host."
4157 (let ((fqdn (message-make-fqdn)))
4158 (string-match "^[^.]+\\." fqdn)
4159 (substring fqdn 0 (1- (match-end 0)))))
4161 (defun message-make-domain ()
4162 "Return the domain name."
4163 (or mail-host-address
4164 (message-make-fqdn)))
4166 ;; Dummy to avoid byte-compile warning.
4167 (defvar mule-version)
4168 (defvar emacs-beta-version)
4169 (defvar xemacs-codename)
4170 (defvar gnus-inviolable-extended-version)
4172 (defun message-make-user-agent ()
4173 "Return user-agent info if the value `message-user-agent' is non-nil. If the
4174 \"User-Agent\" field has already exist, it's value will be added in the return
4176 (when message-user-agent
4178 (goto-char (point-min))
4179 (let ((case-fold-search t)
4180 user-agent start p end)
4181 (if (re-search-forward "^User-Agent:[\t ]*" nil t)
4183 (setq start (match-beginning 0)
4185 end (std11-field-end)
4186 user-agent (buffer-substring-no-properties p end))
4187 (delete-region start (1+ end))
4188 (concat message-user-agent " " user-agent))
4189 message-user-agent)))))
4191 (defun message-generate-headers (headers)
4192 "Prepare article HEADERS.
4193 Headers already prepared in the buffer are not modified."
4195 (message-narrow-to-headers)
4196 (let* ((Date (message-make-date))
4197 (Message-ID (message-make-message-id))
4198 (Organization (message-make-organization))
4199 (From (message-make-from))
4200 (Path (message-make-path))
4203 (In-Reply-To (message-make-in-reply-to))
4205 (Distribution (message-make-distribution))
4206 (Lines (message-make-lines))
4207 (User-Agent (message-make-user-agent))
4208 (Expires (message-make-expires))
4209 (case-fold-search t)
4211 ;; First we remove any old generated headers.
4212 (let ((headers message-deletable-headers))
4213 (unless (buffer-modified-p)
4214 (setq headers (delq 'Message-ID (copy-sequence headers))))
4216 (goto-char (point-min))
4217 (and (re-search-forward
4218 (concat "^" (symbol-name (car headers)) ": *") nil t)
4219 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
4220 (message-delete-line))
4222 ;; Go through all the required headers and see if they are in the
4223 ;; articles already. If they are not, or are empty, they are
4224 ;; inserted automatically - except for Subject, Newsgroups and
4227 (goto-char (point-min))
4228 (setq elem (pop headers))
4230 (if (eq (car elem) 'optional)
4231 (setq header (cdr elem))
4232 (setq header (car elem)))
4234 (when (or (not (re-search-forward
4238 (if (stringp header)
4240 (symbol-name header))))
4244 ;; The header was found. We insert a space after the
4245 ;; colon, if there is none.
4246 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
4247 ;; Find out whether the header is empty...
4248 (looking-at "[ \t]*\n[^ \t]")))
4249 ;; So we find out what value we should insert.
4252 ((and (consp elem) (eq (car elem) 'optional))
4253 ;; This is an optional header. If the cdr of this
4254 ;; is something that is nil, then we do not insert
4256 (setq header (cdr elem))
4257 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
4258 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
4260 ;; The element is a cons. Either the cdr is a
4261 ;; string to be inserted verbatim, or it is a
4262 ;; function, and we insert the value returned from
4264 (or (and (stringp (cdr elem)) (cdr elem))
4265 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
4266 ((and (boundp header) (symbol-value header))
4267 ;; The element is a symbol. We insert the value
4268 ;; of this symbol, if any.
4269 (symbol-value header))
4270 ((not (message-check-element header))
4271 ;; We couldn't generate a value for this header,
4272 ;; so we just ask the user.
4273 (read-from-minibuffer
4274 (format "Empty header for %s; enter value: " header)))))
4275 ;; Finally insert the header.
4277 (not (equal value "")))
4281 ;; This header didn't exist, so we insert it.
4282 (goto-char (point-max))
4283 (insert (if (stringp header) header (symbol-name header))
4288 ;; The value of this header was empty, so we clear
4289 ;; totally and insert the new value.
4290 (delete-region (point) (gnus-point-at-eol))
4294 ;; Add the deletable property to the headers that require it.
4295 (and (memq header message-deletable-headers)
4296 (progn (beginning-of-line) (looking-at "[^:]+: "))
4297 (add-text-properties
4298 (point) (match-end 0)
4299 '(message-deletable t face italic) (current-buffer)))))))
4300 ;; Insert new Sender if the From is strange.
4301 (let ((from (message-fetch-field "from"))
4302 (sender (message-fetch-field "sender"))
4303 (secure-sender (message-make-sender)))
4305 (not (message-check-element 'sender))
4308 (cadr (std11-extract-address-components from)))
4309 (downcase secure-sender)))
4314 (cadr (std11-extract-address-components sender)))
4315 (downcase secure-sender)))))
4316 (goto-char (point-min))
4317 ;; Rename any old Sender headers to Original-Sender.
4318 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
4320 (insert "Original-")
4321 (beginning-of-line))
4322 (when (or (message-news-p)
4323 (string-match "@.+\\.." secure-sender))
4324 (insert "Sender: " secure-sender "\n")))))))
4326 (defun message-insert-courtesy-copy ()
4327 "Insert a courtesy message in mail copies of combined messages."
4331 (message-narrow-to-headers)
4332 (when (setq newsgroups (message-fetch-field "newsgroups"))
4333 (goto-char (point-max))
4334 (insert "Posted-To: " newsgroups "\n")))
4336 (when message-courtesy-message
4338 ((string-match "%s" message-courtesy-message)
4339 (insert (format message-courtesy-message newsgroups)))
4341 (insert message-courtesy-message)))))))
4344 ;;; Setting up a message buffer
4347 (defun message-fill-address (header value)
4349 (narrow-to-region (point) (point))
4350 (insert (capitalize (symbol-name header))
4352 (if (consp value) (car value) value)
4354 (narrow-to-region (point-min) (1- (point-max)))
4356 (goto-char (point-min))
4358 (skip-chars-forward "^,\"" (point-max))
4359 (if (or (eq (char-after) ?,)
4362 (if (and (> (current-column) 78)
4366 (looking-at "[ \t]*")
4367 (replace-match "\n " t t)))
4368 (setq last (1+ (point))))
4369 (setq quoted (not quoted)))
4372 (goto-char (point-max))
4376 (defun message-fill-references (header value)
4377 (insert (capitalize (symbol-name header))
4379 (std11-fill-msg-id-list-string
4380 (if (consp value) (car value) value))
4383 (defun message-fill-header (header value)
4384 (let ((begin (point))
4387 (insert (capitalize (symbol-name header))
4389 (if (consp value) (car value) value)
4392 (narrow-to-region begin (point))
4393 (fill-region-as-paragraph begin (point))
4394 ;; Tapdance around looong Message-IDs.
4396 (when (looking-at "[ \t]*$")
4397 (message-delete-line))
4399 (re-search-forward ":" nil t)
4400 (when (looking-at "\n[ \t]+")
4401 (replace-match " " t t))
4402 (goto-char (point-max)))))
4404 (defun message-shorten-1 (list cut surplus)
4405 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
4406 (setcdr (nthcdr (- cut 2) list)
4407 (nthcdr (+ (- cut 2) surplus 1) list)))
4409 (defun message-shorten-references (header references)
4410 "Trim REFERENCES to be less than 31 Message-ID long, and fold them.
4411 If folding is disallowed, also check that the REFERENCES are less
4412 than 988 characters long, and if they are not, trim them until they are."
4419 (goto-char (point-min))
4420 ;; Cons a list of valid references.
4421 (while (re-search-forward "<[^>]+>" nil t)
4422 (push (match-string 0) refs))
4423 (setq refs (nreverse refs)
4424 count (length refs)))
4426 ;; If the list has more than MAXCOUNT elements, trim it by
4427 ;; removing the CUTth element and the required number of
4428 ;; elements that follow.
4429 (when (> count maxcount)
4430 (let ((surplus (- count maxcount)))
4431 (message-shorten-1 refs cut surplus)
4432 (decf count surplus)))
4434 ;; If folding is disallowed, make sure the total length (including
4435 ;; the spaces between) will be less than MAXSIZE characters.
4437 ;; Only disallow folding for News messages. At this point the headers
4438 ;; have not been generated, thus we use message-this-is-news directly.
4439 (when (and message-this-is-news message-cater-to-broken-inn)
4441 (totalsize (+ (apply #'+ (mapcar #'length refs))
4444 (ptr (nthcdr (1- cut) refs)))
4445 ;; Decide how many elements to cut off...
4446 (while (> totalsize maxsize)
4447 (decf totalsize (1+ (length (car ptr))))
4449 (setq ptr (cdr ptr)))
4452 (message-shorten-1 refs cut surplus))))
4454 ;; Finally, collect the references back into a string and insert
4455 ;; it into the buffer.
4456 (let ((refstring (mapconcat #'identity refs " ")))
4457 (if (and message-this-is-news message-cater-to-broken-inn)
4458 (insert (capitalize (symbol-name header)) ": "
4460 (message-fill-header header refstring)))))
4462 (defun message-position-point ()
4463 "Move point to where the user probably wants to find it."
4464 (message-narrow-to-headers)
4466 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
4467 (search-backward ":" )
4470 (if (eq (char-after) ? )
4474 (goto-char (point-max))
4477 (unless (looking-at "$")
4481 (defun message-buffer-name (type &optional to group)
4482 "Return a new (unique) buffer name based on TYPE and TO."
4484 ;; Generate a new buffer name The Message Way.
4485 ((eq message-generate-new-buffers 'unique)
4486 (generate-new-buffer-name
4490 (or (car (std11-extract-address-components to))
4493 (if (and group (not (string= group ""))) (concat " on " group) "")
4495 ;; Check whether `message-generate-new-buffers' is a function,
4496 ;; and if so, call it.
4497 ((message-functionp message-generate-new-buffers)
4498 (funcall message-generate-new-buffers type to group))
4499 ((eq message-generate-new-buffers 'unsent)
4500 (generate-new-buffer-name
4501 (concat "*unsent " type
4504 (or (car (mail-extract-address-components to))
4507 (if (and group (not (string= group ""))) (concat " on " group) "")
4509 ;; Use standard name.
4511 (format "*%s message*" type))))
4513 (defmacro message-pop-to-buffer-1 (buffer)
4515 (let (special-display-buffer-names
4516 special-display-regexps
4517 same-window-buffer-names
4518 same-window-regexps)
4519 (pop-to-buffer ,buffer))
4520 (pop-to-buffer ,buffer)))
4522 (defun message-pop-to-buffer (name)
4523 "Pop to buffer NAME, and warn if it already exists and is modified."
4524 (let ((buffer (get-buffer name))
4525 (pop-up-frames (and (or (static-if (featurep 'xemacs)
4526 (device-on-window-system-p)
4528 (>= emacs-major-version 20))
4529 message-use-multi-frames)))
4531 (buffer-name buffer))
4533 (message-pop-to-buffer-1 buffer)
4534 (when (and (buffer-modified-p)
4536 "Message already being composed; erase? ")))
4537 (error "Message being composed")))
4538 (message-pop-to-buffer-1 name))
4542 (set (make-local-variable 'message-original-frame) (selected-frame)))))
4544 (defun message-do-send-housekeeping ()
4545 "Kill old message buffers."
4546 ;; We might have sent this buffer already. Delete it from the
4548 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
4549 (while (and message-max-buffers
4551 (>= (length message-buffer-list) message-max-buffers))
4552 ;; Kill the oldest buffer -- unless it has been changed.
4553 (let ((buffer (pop message-buffer-list)))
4554 (when (and (buffer-name buffer)
4555 (not (buffer-modified-p buffer)))
4556 (kill-buffer buffer))))
4557 ;; Rename the buffer.
4558 (if message-send-rename-function
4559 (funcall message-send-rename-function)
4560 (when (string-match "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*"
4562 (let ((name (match-string 2 (buffer-name)))
4564 (if (not (or (string-equal name "mail")
4565 (string-equal name "news")))
4566 (setq name (concat "*sent " name "*"))
4567 (setq to (message-fetch-field "to"))
4568 (setq group (message-fetch-field "newsgroups"))
4571 (to (concat "*sent mail to "
4572 (or (car (mail-extract-address-components to))
4574 ((and group (not (string= group "")))
4575 (concat "*sent news on " group "*"))
4576 (t "*sent mail*"))))
4577 (unless (string-equal name (buffer-name))
4578 (rename-buffer name t)))))
4579 ;; Push the current buffer onto the list.
4580 (when message-max-buffers
4581 (setq message-buffer-list
4582 (nconc message-buffer-list (list (current-buffer))))))
4584 (defun message-mail-user-agent ()
4586 ((not message-mail-user-agent) nil)
4587 ((eq message-mail-user-agent t) mail-user-agent)
4588 (t message-mail-user-agent))))
4589 (if (memq mua '(message-user-agent gnus-user-agent))
4593 (defun message-setup (headers &optional replybuffer actions switch-function)
4594 (let ((mua (message-mail-user-agent))
4595 subject to field yank-action)
4596 (if (not (and message-this-is-mail mua))
4597 (message-setup-1 headers replybuffer actions)
4599 (setq yank-action (list 'insert-buffer replybuffer)))
4600 (setq headers (copy-sequence headers))
4601 (setq field (assq 'Subject headers))
4603 (setq subject (cdr field))
4604 (setq headers (delq field headers)))
4605 (setq field (assq 'To headers))
4607 (setq to (cdr field))
4608 (setq headers (delq field headers)))
4609 (let ((mail-user-agent mua))
4610 (compose-mail to subject
4611 (mapcar (lambda (item)
4613 (format "%s" (car item))
4616 nil switch-function yank-action actions)))))
4618 ;;;(defvar mc-modes-alist)
4619 (defun message-setup-1 (headers &optional replybuffer actions)
4620 ;;; (when (and (boundp 'mc-modes-alist)
4621 ;;; (not (assq 'message-mode mc-modes-alist)))
4622 ;;; (push '(message-mode (encrypt . mc-encrypt-message)
4623 ;;; (sign . mc-sign-message))
4624 ;;; mc-modes-alist))
4626 (setq message-send-actions actions))
4627 (setq message-reply-buffer
4628 (or (message-get-parameter 'reply-buffer)
4630 (goto-char (point-min))
4631 ;; Insert all the headers.
4634 (alist message-header-format-alist))
4636 (unless (assq (caar h) message-header-format-alist)
4637 (push (list (caar h)) alist))
4641 (delete-region (point) (progn (forward-line -1) (point)))
4642 (when message-default-headers
4643 (insert message-default-headers)
4644 (or (bolp) (insert ?\n)))
4648 (insert mail-header-separator "\n")
4652 (when (message-news-p)
4653 (when message-default-news-headers
4654 (insert message-default-news-headers)
4655 (or (bolp) (insert ?\n)))
4656 (when message-generate-headers-first
4657 (message-generate-headers
4660 (copy-sequence message-required-news-headers))))))
4661 (when (message-mail-p)
4662 (when message-default-mail-headers
4663 (insert message-default-mail-headers)
4664 (or (bolp) (insert ?\n)))
4665 (when message-generate-headers-first
4666 (message-generate-headers
4669 (copy-sequence message-required-mail-headers))))))
4670 (run-hooks 'message-signature-setup-hook)
4671 (message-insert-signature)
4673 (message-narrow-to-headers)
4674 (if message-alternative-emails
4675 (message-use-alternative-email-as-from))
4676 (run-hooks 'message-header-setup-hook))
4677 (set-buffer-modified-p nil)
4678 (setq buffer-undo-list nil)
4679 (run-hooks 'message-setup-hook)
4680 (message-position-point)
4683 (defun message-set-auto-save-file-name ()
4684 "Associate the message buffer with a file in the drafts directory."
4685 (when message-auto-save-directory
4686 (unless (file-directory-p
4687 (directory-file-name message-auto-save-directory))
4688 (gnus-make-directory message-auto-save-directory))
4690 (setq message-draft-article
4691 (nndraft-request-associate-buffer "drafts"))
4692 (setq buffer-file-name (expand-file-name
4693 (if (eq system-type 'windows-nt)
4696 message-auto-save-directory))
4697 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
4698 (clear-visited-file-modtime)
4699 (static-if (boundp 'MULE)
4700 (set-file-coding-system message-draft-coding-system)
4701 (setq buffer-file-coding-system message-draft-coding-system))))
4703 (defun message-disassociate-draft ()
4704 "Disassociate the message buffer from the drafts directory."
4705 (when message-draft-article
4706 (nndraft-request-expire-articles
4707 (list message-draft-article) "drafts" nil t)))
4709 (defun message-insert-headers ()
4710 "Generate the headers for the article."
4714 (message-narrow-to-headers)
4715 (when (message-news-p)
4716 (message-generate-headers
4719 (copy-sequence message-required-news-headers)))))
4720 (when (message-mail-p)
4721 (message-generate-headers
4724 (copy-sequence message-required-mail-headers))))))))
4729 ;;; Commands for interfacing with message
4733 (defun message-mail (&optional to subject
4734 other-headers continue switch-function
4735 yank-action send-actions)
4736 "Start editing a mail message to be sent.
4737 OTHER-HEADERS is an alist of header/value pairs."
4739 (let ((message-this-is-mail t) replybuffer)
4740 (unless (message-mail-user-agent)
4741 (message-pop-to-buffer (message-buffer-name "mail" to)))
4742 ;; FIXME: message-mail should do something if YANK-ACTION is not
4744 (and (consp yank-action) (eq (car yank-action) 'insert-buffer)
4745 (setq replybuffer (nth 1 yank-action)))
4748 `((To . ,(or to "")) (Subject . ,(or subject "")))
4749 (when other-headers other-headers))
4751 ;; FIXME: Should return nil if failure.
4755 (defun message-news (&optional newsgroups subject)
4756 "Start editing a news article to be sent."
4758 (let ((message-this-is-news t))
4759 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))
4760 (message-setup `((Newsgroups . ,(or newsgroups ""))
4761 (Subject . ,(or subject ""))))))
4763 (defun message-get-reply-headers (wide &optional to-address)
4764 (let (follow-to mct never-mct from to cc reply-to mrt mft)
4765 ;; Find all relevant headers we need.
4766 (setq from (message-fetch-field "from")
4767 to (message-fetch-field "to")
4768 cc (message-fetch-field "cc")
4769 mct (when message-use-mail-copies-to
4770 (message-fetch-field "mail-copies-to"))
4771 reply-to (message-fetch-field "reply-to")
4772 mrt (when message-use-mail-reply-to
4773 (message-fetch-field "mail-reply-to"))
4774 mft (when (and (not (or to-address mrt reply-to))
4775 (or message-use-followup-to
4776 message-use-mail-followup-to))
4777 (message-fetch-field "mail-followup-to")))
4779 ;; Handle special values of Mail-Copies-To.
4782 ((and (or (equal (downcase mct) "never")
4783 (equal (downcase mct) "nobody")))
4784 (when (or (not (eq message-use-mail-copies-to 'ask))
4786 (concat "Obey Mail-Copies-To: never? ") t "\
4787 You should normally obey the Mail-Copies-To: header.
4789 `Mail-Copies-To: " mct "'
4790 directs you not to send your response to the author."))
4793 ((and (or (equal (downcase mct) "always")
4794 (equal (downcase mct) "poster")))
4795 (if (or (not (eq message-use-mail-copies-to 'ask))
4797 (concat "Obey Mail-Copies-To: always? ") t "\
4798 You should normally obey the Mail-Copies-To: header.
4800 `Mail-Copies-To: " mct "'
4801 sends a copy of your response to the author."))
4802 (setq mct (or mrt reply-to from))
4804 ((and (eq message-use-mail-copies-to 'ask)
4805 (not (message-y-or-n-p
4806 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
4807 You should normally obey the Mail-Copies-To: header.
4809 `Mail-Copies-To: " mct "'
4810 sends a copy of your response to " (if (string-match "," mct)
4811 "the specified addresses"
4812 "that address") ".")))
4815 ;; Handle Mail-Followup-To.
4817 (eq (or message-use-followup-to
4818 message-use-mail-followup-to) 'ask)
4819 (not (message-y-or-n-p
4820 (concat "Obey Mail-Followup-To: " mft "? ") t "\
4821 You should normally obey the Mail-Followup-To: header.
4823 `Mail-Followup-To: " mft "'
4824 directs your response to " (if (string-match "," mft)
4825 "the specified addresses"
4826 "that address only") ".
4828 A typical situation where Mail-Followup-To is used is when the author thinks
4829 that further discussion should take place only in "
4830 (if (string-match "," mft)
4831 "the specified mailing lists"
4832 "that mailing list") ".")))
4839 (setq follow-to (list (cons 'To
4840 (or to-address mrt reply-to mft from))))
4842 (not (member (cons 'To mct) follow-to)))
4843 (push (cons 'Cc mct) follow-to)))
4846 (message-set-work-buffer)
4848 message-use-followup-to
4849 (or (not (eq message-use-followup-to 'ask))
4850 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
4851 You should normally obey the Mail-Followup-To: header. In this
4852 article, it has the value of
4856 which directs your response to " (if (string-match "," mft)
4857 "the specified addresses"
4858 "that address only") ".
4860 If a message is posted to several mailing lists, Mail-Followup-To is
4861 often used to direct the following discussion to one list only,
4862 because discussions that are spread over several lists tend to be
4863 fragmented and very difficult to follow.
4865 Also, some source/announcement lists are not indented for discussion;
4866 responses here are directed to other addresses.")))
4869 (insert (or mrt reply-to from "")))
4870 (insert (if to (concat (if (bolp) "" ", ") to) ""))
4871 (insert (if mct (concat (if (bolp) "" ", ") mct) ""))
4872 (insert (if cc (concat (if (bolp) "" ", ") cc) "")))
4873 (goto-char (point-min))
4874 (while (re-search-forward "[ \t]+" nil t)
4875 (replace-match " " t t))
4876 ;; Remove addresses that match `rmail-dont-reply-to-names'.
4877 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
4878 (insert (prog1 (rmail-dont-reply-to (buffer-string))
4880 (goto-char (point-min))
4881 ;; Perhaps "Mail-Copies-To: never" removed the only address?
4883 (insert (or mrt reply-to from "")))
4887 (cons (mail-strip-quoted-names addr) addr))
4888 (message-tokenize-header (buffer-string))))
4891 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
4892 (setq follow-to (list (cons 'To (cdr (pop ccalist)))))
4894 (let ((ccs (cons 'Cc (mapconcat
4895 (lambda (addr) (cdr addr)) ccalist ", "))))
4896 (when (string-match "^ +" (cdr ccs))
4897 (setcdr ccs (substring (cdr ccs) (match-end 0))))
4898 (push ccs follow-to)))))
4902 (defun message-reply (&optional to-address wide)
4903 "Start editing a reply to the article in the current buffer."
4905 (require 'gnus-sum) ; for gnus-list-identifiers
4906 (let ((cur (current-buffer))
4908 references message-id follow-to
4909 (inhibit-point-motion-hooks t)
4910 (message-this-is-mail t)
4911 gnus-warning in-reply-to)
4913 (message-narrow-to-head-1)
4914 ;; Allow customizations to have their say.
4916 ;; This is a regular reply.
4917 (when (message-functionp message-reply-to-function)
4919 (setq follow-to (funcall message-reply-to-function))))
4920 ;; This is a followup.
4921 (when (message-functionp message-wide-reply-to-function)
4924 (funcall message-wide-reply-to-function)))))
4925 (setq message-id (message-fetch-field "message-id" t)
4926 references (message-fetch-field "references")
4927 date (message-fetch-field "date")
4928 from (message-fetch-field "from")
4929 subject (or (message-fetch-field "subject") "none"))
4930 (when gnus-list-identifiers
4931 (setq subject (message-strip-list-identifiers subject)))
4932 (setq subject (message-make-followup-subject subject))
4934 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
4935 (string-match "<[^>]+>" gnus-warning))
4936 (setq message-id (match-string 0 gnus-warning)))
4939 (setq follow-to (message-get-reply-headers wide to-address)))
4941 ;; Get the references from "In-Reply-To" field if there were
4942 ;; no references and "In-Reply-To" field looks promising.
4944 (when (and (setq in-reply-to (message-fetch-field "in-reply-to"))
4945 (string-match "<[^>]+>" in-reply-to))
4946 (setq references (match-string 0 in-reply-to)))))
4948 (unless (message-mail-user-agent)
4949 (message-pop-to-buffer
4950 (message-buffer-name
4951 (if wide "wide reply" "reply") from
4952 (if wide to-address nil))))
4954 (setq message-reply-headers
4955 (make-full-mail-header-from-decoded-header
4956 0 subject from date message-id references 0 0 ""))
4959 `((Subject . ,subject)
4961 ,@(if (or references message-id)
4962 `((References . ,(concat (or references "") (and references " ")
4963 (or message-id ""))))
4968 (defun message-wide-reply (&optional to-address)
4969 "Make a \"wide\" reply to the message in the current buffer."
4971 (message-reply to-address t))
4974 (defun message-followup (&optional to-newsgroups)
4975 "Follow up to the message in the current buffer.
4976 If TO-NEWSGROUPS, use that as the new Newsgroups line."
4978 (require 'gnus-sum) ; for gnus-list-identifiers
4979 (let ((cur (current-buffer))
4980 from subject date reply-to mrt mct mft
4981 references message-id follow-to
4982 (inhibit-point-motion-hooks t)
4983 (message-this-is-news t)
4984 followup-to distribution newsgroups gnus-warning posted-to)
4986 (message-narrow-to-head)
4987 (when (message-functionp message-followup-to-function)
4989 (funcall message-followup-to-function)))
4990 (setq from (message-fetch-field "from")
4991 date (message-fetch-field "date")
4992 subject (or (message-fetch-field "subject") "none")
4993 references (message-fetch-field "references")
4994 message-id (message-fetch-field "message-id" t)
4995 followup-to (message-fetch-field "followup-to")
4996 newsgroups (message-fetch-field "newsgroups")
4997 posted-to (message-fetch-field "posted-to")
4998 reply-to (message-fetch-field "reply-to")
4999 mrt (when message-use-mail-reply-to
5000 (message-fetch-field "mail-reply-to"))
5001 distribution (message-fetch-field "distribution")
5002 mct (when message-use-mail-copies-to
5003 (message-fetch-field "mail-copies-to"))
5004 mft (when (or message-use-followup-to
5005 message-use-mail-followup-to)
5006 (message-fetch-field "mail-followup-to")))
5007 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
5008 (string-match "<[^>]+>" gnus-warning))
5009 (setq message-id (match-string 0 gnus-warning)))
5010 ;; Remove bogus distribution.
5011 (when (and (stringp distribution)
5012 (let ((case-fold-search t))
5013 (string-match "world" distribution)))
5014 (setq distribution nil))
5015 (if gnus-list-identifiers
5016 (setq subject (message-strip-list-identifiers subject)))
5017 (setq subject (message-make-followup-subject subject))
5020 ;; Handle special values of Mail-Copies-To.
5023 ((and (or (equal (downcase mct) "never")
5024 (equal (downcase mct) "nobody")))
5026 ((and (or (equal (downcase mct) "always")
5027 (equal (downcase mct) "poster")))
5028 (if (or (not (eq message-use-mail-copies-to 'ask))
5030 (concat "Obey Mail-Copies-To: always? ") t "\
5031 You should normally obey the Mail-Copies-To: header.
5033 `Mail-Copies-To: " mct "'
5034 sends a copy of your response to the author."))
5035 (setq mct (or mrt reply-to from))
5037 ((and (eq message-use-mail-copies-to 'ask)
5040 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
5041 You should normally obey the Mail-Copies-To: header.
5043 `Mail-Copies-To: " mct "'
5044 sends a copy of your response to " (if (string-match "," mct)
5045 "the specified addresses"
5046 "that address") ".")))
5051 (to-newsgroups (setq follow-to (list (cons 'Newsgroups to-newsgroups))))
5052 ;; Handle Followup-To.
5055 ((equal (downcase followup-to) "poster")
5056 (if (or (and followup-to (eq message-use-followup-to 'use))
5057 (message-y-or-n-p "Obey Followup-To: poster? " t "\
5058 You should normally obey the Followup-To: header.
5060 `Followup-To: poster'
5061 sends your response via e-mail instead of news.
5063 A typical situation where `Followup-To: poster' is used is when the author
5064 does not read the newsgroup, so he wouldn't see any replies sent to it."))
5065 (setq message-this-is-news nil
5067 follow-to (list (cons 'To (or mrt reply-to from ""))))
5068 (setq follow-to (list (cons 'Newsgroups newsgroups)))))
5070 (if (or (equal followup-to newsgroups)
5071 (not (and followup-to (eq message-use-followup-to 'ask)))
5073 (concat "Obey Followup-To: " followup-to "? ") t "\
5074 You should normally obey the Followup-To: header.
5076 `Followup-To: " followup-to "'
5077 directs your response to " (if (string-match "," followup-to)
5078 "the specified newsgroups"
5079 "that newsgroup only") ".
5081 If a message is posted to several newsgroups, Followup-To is often
5082 used to direct the following discussion to one newsgroup only,
5083 because discussions that are spread over several newsgroup tend to
5084 be fragmented and very difficult to follow.
5086 Also, some source/announcement newsgroups are not indented for discussion;
5087 responses here are directed to other newsgroups."))
5088 (setq follow-to (list (cons 'Newsgroups followup-to)))
5089 (setq follow-to (list (cons 'Newsgroups newsgroups)))))))
5090 ;; Handle Mail-Followup-To, followup via e-mail.
5092 (or (not (eq (or message-use-followup-to
5093 message-use-mail-followup-to) 'ask))
5095 (concat "Obey Mail-Followup-To: " mft "? ") t "\
5096 You should normally obey the Mail-Followup-To: header.
5098 `Mail-Followup-To: " mft "'
5099 directs your response to " (if (string-match "," mft)
5100 "the specified addresses"
5101 "that address only") " instead of news.
5103 A typical situation where Mail-Followup-To is used is when the author thinks
5104 that further discussion should take place only in "
5105 (if (string-match "," mft)
5106 "the specified mailing lists"
5107 "that mailing list") ".")))
5108 (setq message-this-is-news nil
5110 follow-to (list (cons 'To mft))))
5111 (posted-to (setq follow-to (list (cons 'Newsgroups posted-to))))
5113 (setq follow-to (list (cons 'Newsgroups newsgroups))))))
5115 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
5118 `((Subject . ,subject)
5120 ,@(and mct (list (cons 'Cc mct)))
5121 ,@(and distribution (list (cons 'Distribution distribution)))
5122 ,@(if (or references message-id)
5123 `((References . ,(concat (or references "") (and references " ")
5124 (or message-id ""))))))
5127 (setq message-reply-headers
5128 (make-full-mail-header-from-decoded-header
5129 0 subject from date message-id references 0 0 ""))))
5132 (defun message-cancel-news (&optional arg)
5133 "Cancel an article you posted.
5134 If ARG, allow editing of the cancellation message."
5136 (unless (message-news-p)
5137 (error "This is not a news article; canceling is impossible"))
5138 (let (from newsgroups message-id distribution buf sender)
5140 ;; Get header info from original article.
5142 (message-narrow-to-head-1)
5143 (setq from (message-fetch-field "from")
5144 sender (message-fetch-field "sender")
5145 newsgroups (message-fetch-field "newsgroups")
5146 message-id (message-fetch-field "message-id" t)
5147 distribution (message-fetch-field "distribution")))
5148 ;; Make sure that this article was written by the user.
5149 (unless (or (message-gnksa-enable-p 'cancel-messages)
5153 (downcase (message-make-sender))))
5155 (downcase (cadr (std11-extract-address-components from)))
5156 (downcase (cadr (std11-extract-address-components
5157 (message-make-from))))))
5158 (error "This article is not yours"))
5159 (when (yes-or-no-p "Do you really want to cancel this article? ")
5160 ;; Make control message.
5163 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
5165 (insert "Newsgroups: " newsgroups "\n"
5167 "Subject: cmsg cancel " message-id "\n"
5168 "Control: cancel " message-id "\n"
5170 (concat "Distribution: " distribution "\n")
5172 mail-header-separator "\n"
5173 message-cancel-message)
5174 (run-hooks 'message-cancel-hook)
5176 (message "Canceling your article...")
5177 (if (let ((message-syntax-checks
5178 'dont-check-for-anything-just-trust-me)
5179 (message-encoding-buffer (current-buffer))
5180 (message-edit-buffer (current-buffer)))
5181 (message-send-news))
5182 (message "Canceling your article...done"))
5183 (kill-buffer buf))))))
5185 (defun message-supersede-setup-for-mime-edit ()
5186 (set (make-local-variable 'message-setup-hook) nil)
5190 (defun message-supersede ()
5191 "Start composing a message to supersede the current message.
5192 This is done simply by taking the old article and adding a Supersedes
5193 header line with the old Message-ID."
5195 (let ((cur (current-buffer))
5196 (sender (message-fetch-field "sender"))
5197 (from (message-fetch-field "from")))
5198 ;; Check whether the user owns the article that is to be superseded.
5199 (unless (or (message-gnksa-enable-p 'cancel-messages)
5203 (downcase (message-make-sender))))
5205 (downcase (cadr (std11-extract-address-components from)))
5206 (downcase (cadr (std11-extract-address-components
5207 (message-make-from))))))
5208 (error "This article is not yours"))
5209 ;; Get a normal message buffer.
5210 (message-pop-to-buffer (message-buffer-name "supersede"))
5211 (insert-buffer-substring cur)
5212 (message-narrow-to-head-1)
5213 ;; Remove unwanted headers.
5214 (when message-ignored-supersedes-headers
5215 (message-remove-header message-ignored-supersedes-headers t))
5216 (goto-char (point-min))
5217 (if (not (re-search-forward "^Message-ID: " nil t))
5218 (error "No Message-ID in this article")
5219 (replace-match "Supersedes: " t t))
5220 (goto-char (point-max))
5221 (insert mail-header-separator)
5223 (when message-supersede-setup-function
5224 (funcall message-supersede-setup-function))
5225 (run-hooks 'message-supersede-setup-hook)
5226 (goto-char (point-min))
5227 (search-forward (concat "\n" mail-header-separator "\n") nil t)))
5230 (defun message-recover ()
5231 "Reread contents of current buffer from its last auto-save file."
5233 (let ((file-name (make-auto-save-file-name)))
5234 (cond ((save-window-excursion
5235 (if (not (eq system-type 'vax-vms))
5236 (with-output-to-temp-buffer "*Directory*"
5237 (with-current-buffer standard-output
5238 (fundamental-mode)) ; for Emacs 20.4+
5239 (buffer-disable-undo standard-output)
5240 (let ((default-directory "/"))
5242 "ls" nil standard-output nil "-l" file-name))))
5243 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
5244 (let ((buffer-read-only nil))
5246 (insert-file-contents file-name nil)))
5247 (t (error "message-recover cancelled")))))
5249 ;;; Washing Subject:
5251 (defun message-wash-subject (subject)
5252 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
5253 Previous forwarders, replyers, etc. may add it."
5255 (insert-string subject)
5256 (goto-char (point-min))
5257 ;; strip Re/Fwd stuff off the beginning
5258 (while (re-search-forward
5259 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
5262 ;; and gnus-style forwards [foo@bar.com] subject
5263 (goto-char (point-min))
5264 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
5268 (goto-char (point-max))
5269 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
5272 ;; and finally, any whitespace that was left-over
5273 (goto-char (point-min))
5274 (while (re-search-forward "^[ \t]+" nil t)
5276 (goto-char (point-max))
5277 (while (re-search-backward "[ \t]+$" nil t)
5282 ;;; Forwarding messages.
5284 (defvar message-forward-decoded-p nil
5285 "Non-nil means the original message is decoded.")
5287 (defun message-forward-subject-author-subject (subject)
5288 "Generate a SUBJECT for a forwarded message.
5289 The form is: [Source] Subject, where if the original message was mail,
5290 Source is the sender, and if the original message was news, Source is
5291 the list of newsgroups is was posted to."
5293 (if (message-news-p)
5294 (or (message-fetch-field "newsgroups")
5296 (let ((from (message-fetch-field "from")))
5298 (nnheader-decode-from from)
5302 (defun message-forward-subject-fwd (subject)
5303 "Generate a SUBJECT for a forwarded message.
5304 The form is: Fwd: Subject, where Subject is the original subject of
5306 (concat "Fwd: " subject))
5308 (defun message-make-forward-subject ()
5309 "Return a Subject header suitable for the message in the current buffer."
5312 (message-narrow-to-head-1)
5313 (let ((funcs message-make-forward-subject-function)
5314 (subject (message-fetch-field "Subject")))
5317 (if message-forward-decoded-p
5319 (nnheader-decode-subject subject))
5321 (if message-wash-forwarded-subjects
5322 (setq subject (message-wash-subject subject)))
5323 ;; Make sure funcs is a list.
5326 (setq funcs (list funcs)))
5327 ;; Apply funcs in order, passing subject generated by previous
5328 ;; func to the next one.
5330 (when (message-functionp (car funcs))
5331 (setq subject (funcall (car funcs) subject)))
5332 (setq funcs (cdr funcs)))
5336 (defun message-forward (&optional news)
5337 "Forward the current message via mail.
5338 Optional NEWS will use news to forward instead of mail."
5340 (let ((cur (current-buffer))
5341 (subject (message-make-forward-subject))
5344 (message-news nil subject)
5345 (message-mail nil subject))
5346 ;; Put point where we want it before inserting the forwarded
5348 (if message-forward-before-signature
5350 (goto-char (point-max)))
5351 ;; Make sure we're at the start of the line.
5354 ;; Narrow to the area we are to insert.
5355 (narrow-to-region (point) (point))
5356 ;; Insert the separators and the forwarded buffer.
5357 (insert message-forward-start-separator)
5358 (setq art-beg (point))
5359 (insert-buffer-substring cur)
5360 (goto-char (point-max))
5361 (insert message-forward-end-separator)
5362 (set-text-properties (point-min) (point-max) nil)
5363 ;; Remove all unwanted headers.
5365 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
5368 (goto-char (point-min))
5369 (message-remove-header message-included-forward-headers t nil t)
5371 (message-position-point)))
5374 (defun message-resend (address)
5375 "Resend the current article to ADDRESS."
5377 (list (message-read-from-minibuffer "Resend message to: ")))
5378 (message "Resending message to %s..." address)
5380 (let ((cur (current-buffer))
5382 ;; We first set up a normal mail buffer.
5383 (unless (message-mail-user-agent)
5384 (set-buffer (get-buffer-create " *message resend*"))
5386 (let ((message-this-is-mail t)
5387 ;; avoid to turn-on-mime-edit
5389 (message-setup `((To . ,address)))))
5390 ;; Insert our usual headers.
5391 (message-generate-headers '(From Date To))
5392 (message-narrow-to-headers)
5393 ;; Rename them all to "Resent-*".
5394 (while (re-search-forward "^[A-Za-z]" nil t)
5399 (delete-region (point) (point-max))
5401 ;; Insert the message to be resent.
5402 (insert-buffer-substring cur)
5403 (goto-char (point-min))
5404 (search-forward "\n\n")
5407 (narrow-to-region beg (point))
5408 (message-remove-header message-ignored-resent-headers t)
5409 (goto-char (point-max)))
5410 (insert mail-header-separator)
5411 ;; Rename all old ("Also-")Resent headers.
5412 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
5415 ;; Quote any "From " lines at the beginning.
5417 (when (looking-at "From ")
5418 (replace-match "X-From-Line: "))
5420 (let ((message-encoding-buffer (current-buffer))
5421 (message-edit-buffer (current-buffer)))
5422 (let (message-required-mail-headers)
5423 (message-send-mail)))
5424 (kill-buffer (current-buffer)))
5425 (message "Resending message to %s...done" address)))
5427 (defun message-bounce-setup-for-mime-edit ()
5428 (set (make-local-variable 'message-setup-hook) nil)
5432 (defun message-bounce ()
5433 "Re-mail the current message.
5434 This only makes sense if the current message is a bounce message that
5435 contains some mail you have written which has been bounced back to
5438 (let ((cur (current-buffer))
5440 (message-pop-to-buffer (message-buffer-name "bounce"))
5441 (insert-buffer-substring cur)
5443 (message-narrow-to-head)
5444 (if (and (message-fetch-field "MIME-Version")
5445 (setq boundary (message-fetch-field "Content-Type")))
5446 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary)
5447 (setq boundary (concat (match-string 1 boundary) " *\n"
5448 "Content-Type: message/rfc822"))
5449 (setq boundary nil)))
5451 (goto-char (point-min))
5452 (search-forward "\n\n" nil t)
5454 (re-search-forward boundary nil t)
5456 (and (re-search-forward message-unsent-separator nil t)
5458 (re-search-forward "^Return-Path:.*\n" nil t))
5459 ;; We remove everything before the bounced mail.
5462 (if (re-search-forward "^[^ \n\t]+:" nil t)
5466 (message-narrow-to-head-1)
5467 (message-remove-header message-ignored-bounced-headers t)
5468 (goto-char (point-max))
5469 (insert mail-header-separator))
5470 (when message-bounce-setup-function
5471 (funcall message-bounce-setup-function))
5472 (run-hooks 'message-bounce-setup-hook)
5473 (message-position-point)))
5476 ;;; Interactive entry points for new message buffers.
5480 (defun message-mail-other-window (&optional to subject)
5481 "Like `message-mail' command, but display mail buffer in another window."
5483 (unless (message-mail-user-agent)
5484 (let ((pop-up-windows t)
5485 (special-display-buffer-names nil)
5486 (special-display-regexps nil)
5487 (same-window-buffer-names nil)
5488 (same-window-regexps nil))
5489 (message-pop-to-buffer (message-buffer-name "mail" to))))
5490 (let ((message-this-is-mail t))
5491 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
5492 nil nil 'switch-to-buffer-other-window)))
5495 (defun message-mail-other-frame (&optional to subject)
5496 "Like `message-mail' command, but display mail buffer in another frame."
5498 (unless (message-mail-user-agent)
5499 (let ((pop-up-frames t)
5500 (special-display-buffer-names nil)
5501 (special-display-regexps nil)
5502 (same-window-buffer-names nil)
5503 (same-window-regexps nil))
5504 (message-pop-to-buffer (message-buffer-name "mail" to))))
5505 (let ((message-this-is-mail t))
5506 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
5507 nil nil 'switch-to-buffer-other-frame)))
5510 (defun message-news-other-window (&optional newsgroups subject)
5511 "Start editing a news article to be sent."
5513 (let ((pop-up-windows t)
5514 (special-display-buffer-names nil)
5515 (special-display-regexps nil)
5516 (same-window-buffer-names nil)
5517 (same-window-regexps nil))
5518 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
5519 (let ((message-this-is-news t))
5520 (message-setup `((Newsgroups . ,(or newsgroups ""))
5521 (Subject . ,(or subject ""))))))
5524 (defun message-news-other-frame (&optional newsgroups subject)
5525 "Start editing a news article to be sent."
5527 (let ((pop-up-frames t)
5528 (special-display-buffer-names nil)
5529 (special-display-regexps nil)
5530 (same-window-buffer-names nil)
5531 (same-window-regexps nil))
5532 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
5533 (let ((message-this-is-news t))
5534 (message-setup `((Newsgroups . ,(or newsgroups ""))
5535 (Subject . ,(or subject ""))))))
5539 ;; This code should be moved to underline.el (from which it is stolen).
5542 (defun bold-region (start end)
5543 "Bold all nonblank characters in the region.
5544 Works by overstriking characters.
5545 Called from program, takes two arguments START and END
5546 which specify the range to operate on."
5549 (let ((end1 (make-marker)))
5550 (move-marker end1 (max start end))
5551 (goto-char (min start end))
5552 (while (< (point) end1)
5553 (or (looking-at "[_\^@- ]")
5554 (insert (char-after) "\b"))
5555 (forward-char 1)))))
5558 (defun unbold-region (start end)
5559 "Remove all boldness (overstruck characters) in the region.
5560 Called from program, takes two arguments START and END
5561 which specify the range to operate on."
5564 (let ((end1 (make-marker)))
5565 (move-marker end1 (max start end))
5566 (goto-char (min start end))
5567 (while (re-search-forward "\b" end1 t)
5568 (if (eq (char-after) (char-after (- (point) 2)))
5569 (delete-char -2))))))
5571 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
5573 ;; Support for toolbar
5575 (defvar tool-bar-map)
5576 (defvar tool-bar-mode))
5578 (defun message-tool-bar-map ()
5579 (or message-tool-bar-map
5580 (setq message-tool-bar-map
5581 (and (fboundp 'tool-bar-add-item-from-menu)
5583 (let ((tool-bar-map (copy-keymap tool-bar-map))
5584 (load-path (mm-image-load-path)))
5585 ;; Zap some items which aren't so relevant and take
5587 (dolist (key '(print-buffer kill-buffer save-buffer
5588 write-file dired open-file))
5589 (define-key tool-bar-map (vector key) nil))
5590 (tool-bar-add-item-from-menu
5591 'message-send-and-exit "mail_send" message-mode-map)
5592 (tool-bar-add-item-from-menu
5593 'message-kill-buffer "close" message-mode-map)
5594 (tool-bar-add-item-from-menu
5595 'message-dont-send "cancel" message-mode-map)
5596 (tool-bar-add-item-from-menu
5597 'mml-attach-file "attach" message-mode-map)
5598 (tool-bar-add-item-from-menu
5599 'ispell-message "spell" message-mode-map)
5602 ;;; Group name completion.
5604 (defvar message-newgroups-header-regexp
5605 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
5606 "Regexp that match headers that lists groups.")
5608 (defun message-tab ()
5609 "Expand group names in Newsgroups and Followup-To headers.
5610 Do a `tab-to-tab-stop' if not in those headers."
5612 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp))
5613 (mail-abbrev-in-expansion-header-p))
5614 (message-expand-group)
5617 (defun message-expand-group ()
5618 "Expand the group name under point."
5619 (let* ((b (save-excursion
5624 (skip-chars-forward "^:")
5627 (skip-chars-backward "^, \t\n") (point))))
5628 (completion-ignore-case t)
5629 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
5631 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
5632 (completions (all-completions string hashtb))
5634 (delete-region b (point))
5636 ((= (length completions) 1)
5637 (if (string= (car completions) string)
5640 (message "Only matching group"))
5641 (insert (car completions))))
5642 ((and (setq comp (try-completion string hashtb))
5643 (not (string= comp string)))
5648 (message "No matching groups")
5649 (save-selected-window
5650 (pop-to-buffer "*Completions*")
5651 (buffer-disable-undo)
5652 (let ((buffer-read-only nil))
5654 (let ((standard-output (current-buffer)))
5655 (display-completion-list (sort completions 'string<)))
5656 (goto-char (point-min))
5657 (delete-region (point) (progn (forward-line 3) (point))))))))))
5661 (defun message-talkative-question (ask question show &rest text)
5662 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
5663 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
5664 The following arguments may contain lists of values."
5666 (setq text (message-flatten-list text)))
5667 (save-window-excursion
5669 (with-output-to-temp-buffer " *MESSAGE information message*"
5670 (set-buffer " *MESSAGE information message*")
5671 (fundamental-mode) ; for Emacs 20.4+
5672 (mapcar 'princ text)
5673 (goto-char (point-min))))
5674 (funcall ask question))
5675 (funcall ask question)))
5677 (defun message-flatten-list (list)
5678 "Return a new, flat list that contains all elements of LIST.
5680 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
5683 (apply 'append (mapcar 'message-flatten-list list)))
5687 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
5688 "Create and return a buffer with name based on NAME using `generate-new-buffer.'
5689 Then clone the local variables and values from the old buffer to the
5690 new one, cloning only the locals having a substring matching the
5692 (let ((oldbuf (current-buffer)))
5694 (set-buffer (generate-new-buffer name))
5695 (message-clone-locals oldbuf varstr)
5698 (defun message-clone-locals (buffer &optional varstr)
5699 "Clone the local variables from BUFFER to the current buffer."
5700 (let ((locals (save-excursion
5702 (buffer-local-variables)))
5704 "^\\(gnus\\|nn\\|message\\|user-\\(mail-address\\|full-name\\)\\)"))
5707 (when (and (consp local)
5709 (string-match regexp (symbol-name (car local)))
5711 (string-match varstr (symbol-name (car local)))))
5713 (set (make-local-variable (car local))
5718 ;;; @ for MIME Edit mode
5721 (defun message-maybe-encode ()
5722 (when message-mime-mode
5723 ;; Inherit the buffer local variable `mime-edit-pgp-processing'.
5724 (let ((pgp-processing (with-current-buffer message-edit-buffer
5725 mime-edit-pgp-processing)))
5726 (setq mime-edit-pgp-processing pgp-processing))
5727 (run-hooks 'mime-edit-translate-hook)
5728 (if (catch 'mime-edit-error
5730 (mime-edit-pgp-enclose-buffer)
5731 (mime-edit-translate-body)
5733 (error "Translation error!")
5736 (run-hooks 'mime-edit-exit-hook)
5739 (defun message-mime-insert-article (&optional full-headers)
5741 (let ((message-cite-function 'mime-edit-inserted-message-filter)
5742 (message-reply-buffer
5743 (message-get-parameter-with-eval 'original-buffer))
5745 (message-yank-original nil)
5747 (narrow-to-region (goto-char start)
5748 (if (search-forward "\n\n" nil t)
5751 (goto-char (point-min))
5752 (let ((message-included-forward-headers
5753 (if full-headers "" message-included-forward-headers)))
5754 (message-remove-header message-included-forward-headers t nil t))
5757 (set-alist 'mime-edit-message-inserter-alist
5758 'message-mode (function message-mime-insert-article))
5760 ;;; Miscellaneous functions
5762 ;; stolen (and renamed) from nnheader.el
5763 (static-if (fboundp 'subst-char-in-string)
5764 (defsubst message-replace-chars-in-string (string from to)
5765 (subst-char-in-string from to string))
5766 (defun message-replace-chars-in-string (string from to)
5767 "Replace characters in STRING from FROM to TO."
5768 (let ((string (substring string 0)) ;Copy string.
5769 (len (length string))
5771 ;; Replace all occurrences of FROM with TO.
5773 (when (= (aref string idx) from)
5774 (aset string idx to))
5775 (setq idx (1+ idx)))
5782 (defvar message-inhibit-body-encoding t)
5784 (defun message-encode-message-body ()
5785 (unless message-inhibit-body-encoding
5786 (let ((mail-parse-charset (or mail-parse-charset
5787 message-default-charset))
5788 (case-fold-search t)
5789 lines content-type-p)
5792 (narrow-to-region (point) (point-max))
5793 (let ((new (mml-generate-mime)))
5795 (delete-region (point-min) (point-max))
5797 (goto-char (point-min))
5798 (if (eq (aref new 0) ?\n)
5800 (search-forward "\n\n")
5801 (setq lines (buffer-substring (point-min) (1- (point))))
5802 (delete-region (point-min) (point))))))
5804 (message-narrow-to-headers-or-head)
5805 (message-remove-header "Mime-Version")
5806 (goto-char (point-max))
5807 (insert "MIME-Version: 1.0\n")
5810 (setq content-type-p
5812 (re-search-backward "^Content-Type:" nil t))))
5814 (message-narrow-to-headers-or-head)
5815 (message-remove-first-header "Content-Type")
5816 (message-remove-first-header "Content-Transfer-Encoding"))
5817 ;; We always make sure that the message has a Content-Type header.
5818 ;; This is because some broken MTAs and MUAs get awfully confused
5819 ;; when confronted with a message with a MIME-Version header and
5820 ;; without a Content-Type header. For instance, Solaris'
5822 (unless content-type-p
5823 (goto-char (point-min))
5824 (re-search-forward "^MIME-Version:")
5826 (insert "Content-Type: text/plain; charset=us-ascii\n")))))
5828 (defun message-read-from-minibuffer (prompt)
5829 "Read from the minibuffer while providing abbrev expansion."
5830 (if (fboundp 'mail-abbrevs-setup)
5831 (let ((mail-abbrev-mode-regexp "")
5832 (minibuffer-setup-hook 'mail-abbrevs-setup)
5833 (minibuffer-local-map message-minibuffer-local-map))
5834 (read-from-minibuffer prompt))
5835 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
5836 (minibuffer-local-map message-minibuffer-local-map))
5837 (read-string prompt))))
5839 (defun message-use-alternative-email-as-from ()
5840 (require 'mail-utils)
5841 (let* ((fields '("To" "Cc"))
5844 (mail-strip-quoted-names
5845 (mapconcat 'message-fetch-reply-field fields ","))
5849 (if (string-match message-alternative-emails (car emails))
5850 (setq email (car emails)
5853 (unless (or (not email) (equal email user-mail-address))
5854 (goto-char (point-max))
5855 (insert "From: " email "\n"))))
5857 (defun message-options-get (symbol)
5858 (cdr (assq symbol message-options)))
5860 (defun message-options-set (symbol value)
5861 (let ((the-cons (assq symbol message-options)))
5864 (setcdr the-cons value)
5865 (setq message-options (delq the-cons message-options)))
5867 (push (cons symbol value) message-options))))
5870 (defun message-options-set-recipient ()
5872 (message-narrow-to-headers-or-head)
5873 (message-options-set 'message-sender
5874 (mail-strip-quoted-names
5875 (message-fetch-field "from")))
5876 (message-options-set 'message-recipients
5877 (mail-strip-quoted-names
5879 (or (message-fetch-field "to") "") ", "
5880 (or (message-fetch-field "cc") "") ", "
5881 (or (message-fetch-field "bcc") ""))))))
5883 (when (featurep 'xemacs)
5884 (require 'messagexmas)
5885 (message-xmas-redefine))
5887 (defun message-save-drafts ()
5888 "Postponing the message."
5890 (message "Saving %s..." buffer-file-name)
5891 (let ((reply-headers message-reply-headers)
5892 (msg (buffer-substring-no-properties (point-min) (point-max)))
5893 (message-invisibles (message-find-invisible-regions)))
5894 (with-temp-file buffer-file-name
5896 ;; Inherit the invisible property of texts to make MIME-Edit
5897 ;; find the MIME part boundaries.
5898 (dolist (region message-invisibles)
5899 (put-text-property (car region) (cdr region) 'invisible t))
5900 (setq message-reply-headers reply-headers)
5901 (message-generate-headers '((optional . In-Reply-To)))
5902 (mime-edit-translate-buffer))
5903 (set-buffer-modified-p nil))
5904 (message "Saving %s...done" buffer-file-name))
5908 (run-hooks 'message-load-hook)
5911 ;; coding: iso-8859-1
5914 ;;; message.el ends here