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 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
447 "\\([ \t]*\\(\\w\\|[-_.]\\)+>+\\|[ \t]*[]>»|:}+]\\)+"
448 "*Regexp matching the longest possible citation prefix on a line."
449 :group 'message-insertion
452 (defcustom message-cancel-message "I am canceling my own article.\n"
453 "Message to be inserted in the cancel message."
454 :group 'message-interface
457 ;; Useful to set in site-init.el
459 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
460 "Function to call to send the current buffer as mail.
461 The headers should be delimited by a line whose contents match the
462 variable `mail-header-separator'.
464 Valid values include `message-send-mail-with-sendmail' (the default),
465 `message-send-mail-with-mh', `message-send-mail-with-qmail',
466 `message-send-mail-with-smtp', `smtpmail-send-it' and `feedmail-send-it'.
468 See also `send-mail-function'."
469 :type '(radio (function-item message-send-mail-with-sendmail)
470 (function-item message-send-mail-with-mh)
471 (function-item message-send-mail-with-qmail)
472 (function-item message-send-mail-with-smtp)
473 (function-item smtpmail-send-it)
474 (function-item feedmail-send-it)
475 (function :tag "Other"))
476 :group 'message-sending
477 :group 'message-mail)
479 ;; 1997-09-29 by MORIOKA Tomohiko
480 (defcustom message-send-news-function 'message-send-news-with-gnus
481 "Function to call to send the current buffer as news.
482 The headers should be delimited by a line whose contents match the
483 variable `mail-header-separator'."
484 :group 'message-sending
488 (defcustom message-reply-to-function nil
489 "If non-nil, function that should return a list of headers.
490 This function should pick out addresses from the To, Cc, and From headers
491 and respond with new To and Cc headers."
492 :group 'message-interface
493 :type '(choice function (const nil)))
495 (defcustom message-wide-reply-to-function nil
496 "If non-nil, function that should return a list of headers.
497 This function should pick out addresses from the To, Cc, and From headers
498 and respond with new To and Cc headers."
499 :group 'message-interface
500 :type '(choice function (const nil)))
502 (defcustom message-followup-to-function nil
503 "If non-nil, function that should return a list of headers.
504 This function should pick out addresses from the To, Cc, and From headers
505 and respond with new To and Cc headers."
506 :group 'message-interface
507 :type '(choice function (const nil)))
509 (defcustom message-use-followup-to 'ask
510 "*Specifies what to do with Followup-To header.
511 If nil, always ignore the header. If it is t, use its value, but
512 query before using the \"poster\" value. If it is the symbol `ask',
513 always query the user whether to use the value. If it is the symbol
514 `use', always use the value."
515 :group 'message-interface
516 :type '(choice (const :tag "ignore" nil)
517 (const :tag "maybe" t)
518 (const :tag "always" use)
519 (const :tag "ask" ask)))
521 (defcustom message-use-mail-copies-to 'ask
522 "*Specifies what to do with Mail-Copies-To header.
523 If nil, always ignore the header. If it is t, use its value, but
524 query before using the value other than \"always\" or \"never\".
525 If it is the symbol `ask', always query the user whether to use
526 the value. If it is the symbol `use', always use the value."
527 :group 'message-interface
528 :type '(choice (const :tag "ignore" nil)
529 (const :tag "maybe" t)
530 (const :tag "always" use)
531 (const :tag "ask" ask)))
533 (defcustom message-use-mail-followup-to 'ask
534 "*Specifies what to do with Mail-Followup-To header.
535 If nil, always ignore the header. If it is the symbol `ask', always
536 query the user whether to use the value. If it is t or the symbol
537 `use', always use the value."
538 :group 'message-interface
539 :type '(choice (const :tag "ignore" nil)
540 (const :tag "maybe" t)
541 (const :tag "always" use)
542 (const :tag "ask" ask)))
544 ;;; XXX: 'ask and 'use are not implemented yet.
545 (defcustom message-use-mail-reply-to 'ask
546 "*Specifies what to do with Mail-Reply-To/Reply-To header.
547 If nil, always ignore the header. If it is t or the symbol `use', use
548 its value. If it is the symbol `ask', always query the user whether to
549 use the value. Note that if \"Reply-To\" is marked as \"broken\", its value
551 :group 'message-interface
552 :type '(choice (const :tag "ignore" nil)
553 (const :tag "maybe" t)
554 (const :tag "always" use)
555 (const :tag "ask" ask)))
557 (defcustom message-sendmail-f-is-evil nil
558 "*Non-nil means don't add \"-f username\" to the sendmail command line.
559 Doing so would be even more evil than leaving it out."
560 :group 'message-sending
563 ;; qmail-related stuff
564 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
565 "Location of the qmail-inject program."
566 :group 'message-sending
569 (defcustom message-qmail-inject-args nil
570 "Arguments passed to qmail-inject programs.
571 This should be a list of strings, one string for each argument.
573 For e.g., if you wish to set the envelope sender address so that bounces
574 go to the right place or to deal with listserv's usage of that address, you
575 might set this variable to '(\"-f\" \"you@some.where\")."
576 :group 'message-sending
577 :type '(repeat string))
579 (defvar message-cater-to-broken-inn t
580 "Non-nil means Gnus should not fold the `References' header.
581 Folding `References' makes ancient versions of INN create incorrect
585 (defvar gnus-post-method)
586 (defvar gnus-select-method))
587 (defcustom message-post-method
588 (cond ((and (boundp 'gnus-post-method)
589 (listp gnus-post-method)
592 ((boundp 'gnus-select-method)
595 "*Method used to post news.
596 Note that when posting from inside Gnus, for instance, this
597 variable isn't used."
599 :group 'message-sending
600 ;; This should be the `gnus-select-method' widget, but that might
601 ;; create a dependence to `gnus.el'.
604 (defcustom message-generate-headers-first nil
605 "*If non-nil, generate all required headers before composing."
606 :group 'message-headers
609 (defcustom message-setup-hook '(turn-on-mime-edit)
610 "Normal hook, run each time a new outgoing message is initialized.
611 The function `message-setup' runs this hook."
612 :group 'message-various
615 (defcustom message-cancel-hook nil
616 "Hook run when cancelling articles."
617 :group 'message-various
620 (defcustom message-signature-setup-hook nil
621 "Normal hook, run each time a new outgoing message is initialized.
622 It is run after the headers have been inserted and before
623 the signature is inserted."
624 :group 'message-various
627 (defcustom message-bounce-setup-hook nil
628 "Normal hook, run each time a re-sending bounced message is initialized.
629 The function `message-bounce' runs this hook."
630 :group 'message-various
633 (defcustom message-supersede-setup-hook nil
634 "Normal hook, run each time a supersede message is initialized.
635 The function `message-supersede' runs this hook."
636 :group 'message-various
639 (defcustom message-mode-hook nil
640 "Hook run in message mode buffers."
641 :group 'message-various
644 (defcustom message-header-hook '((lambda () (eword-encode-header t)))
645 "Hook run in a message mode buffer narrowed to the headers."
646 :group 'message-various
649 (defcustom message-header-setup-hook nil
650 "Hook called narrowed to the headers when setting up a message buffer."
651 :group 'message-various
654 (defcustom message-minibuffer-local-map
655 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
656 (set-keymap-parent map minibuffer-local-map)
658 "Keymap for `message-read-from-minibuffer'.")
661 (defcustom message-citation-line-function 'message-insert-citation-line
662 "*Function called to insert the \"Whomever writes:\" line."
664 :group 'message-insertion)
667 (defcustom message-yank-prefix "> "
668 "*Prefix inserted on the lines of yanked messages.
669 Fix `message-cite-prefix-regexp' if it is set to an abnormal value."
671 :group 'message-insertion)
673 (defcustom message-yank-add-new-references t
674 "Non-nil means new IDs will be added to \"References\" field when an
675 article is yanked by the command `message-yank-original' interactively.
676 If it is a symbol `message-id-only', only an ID from \"Message-ID\" field
677 is used, otherwise IDs extracted from \"References\", \"In-Reply-To\" and
678 \"Message-ID\" fields are used."
679 :type '(radio (const :tag "Do not add anything" nil)
680 (const :tag "From Message-Id, References and In-Reply-To fields" t)
681 (const :tag "From only Message-Id field." message-id-only))
682 :group 'message-insertion)
684 (defcustom message-list-references-add-position nil
685 "Integer value means position for adding to \"References\" field when
686 an article is yanked by the command `message-yank-original' interactively."
687 :type '(radio (const :tag "Add to last" nil)
688 (integer :tag "Position from last ID"))
689 :group 'message-insertion)
691 (defcustom message-indentation-spaces 3
692 "*Number of spaces to insert at the beginning of each cited line.
693 Used by `message-yank-original' via `message-yank-cite'."
694 :group 'message-insertion
698 (defcustom message-cite-function 'message-cite-original
699 "*Function for citing an original message.
700 Predefined functions include `message-cite-original' and
701 `message-cite-original-without-signature'.
702 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
703 :type '(radio (function-item message-cite-original)
704 (function-item message-cite-original-without-signature)
705 (function-item mu-cite-original)
706 (function-item sc-cite-original)
707 (function :tag "Other"))
708 :group 'message-insertion)
711 (defcustom message-indent-citation-function 'message-indent-citation
712 "*Function for modifying a citation just inserted in the mail buffer.
713 This can also be a list of functions. Each function can find the
714 citation between (point) and (mark t). And each function should leave
715 point and mark around the citation text as modified."
717 :group 'message-insertion)
719 (defvar message-abbrevs-loaded nil)
722 (defcustom message-signature t
723 "*String to be inserted at the end of the message buffer.
724 If t, the `message-signature-file' file will be inserted instead.
725 If a function, the result from the function will be used instead.
726 If a form, the result from the form will be used instead."
728 :group 'message-insertion)
731 (defcustom message-signature-file "~/.signature"
732 "*File containing the text inserted at end of message buffer."
734 :group 'message-insertion)
736 (defcustom message-distribution-function nil
737 "*Function called to return a Distribution header."
739 :group 'message-headers
740 :type '(choice function (const nil)))
742 (defcustom message-expires 14
743 "Number of days before your article expires."
745 :group 'message-headers
746 :link '(custom-manual "(message)News Headers")
749 (defcustom message-user-path nil
750 "If nil, use the NNTP server name in the Path header.
751 If stringp, use this; if non-nil, use no host name (user name only)."
753 :group 'message-headers
754 :link '(custom-manual "(message)News Headers")
755 :type '(choice (const :tag "nntp" nil)
757 (sexp :tag "none" :format "%t" t)))
759 (defvar message-reply-buffer nil)
760 (defvar message-reply-headers nil)
761 (defvar message-sent-message-via nil)
762 (defvar message-checksum nil)
763 (defvar message-send-actions nil
764 "A list of actions to be performed upon successful sending of a message.")
765 (defvar message-exit-actions nil
766 "A list of actions to be performed upon exiting after sending a message.")
767 (defvar message-kill-actions nil
768 "A list of actions to be performed before killing a message buffer.")
769 (defvar message-postpone-actions nil
770 "A list of actions to be performed after postponing a message.")
771 (defvar message-original-frame nil)
772 (defvar message-parameter-alist nil)
773 (defvar message-startup-parameter-alist nil)
775 (define-widget 'message-header-lines 'text
776 "All header lines must be LFD terminated."
777 :format "%{%t%}:%n%v"
779 :error "All header lines must be newline terminated")
781 (defcustom message-default-headers ""
782 "*A string containing header lines to be inserted in outgoing messages.
783 It is inserted before you edit the message, so you can edit or delete
785 :group 'message-headers
786 :type 'message-header-lines)
788 (defcustom message-default-mail-headers ""
789 "*A string of header lines to be inserted in outgoing mails."
790 :group 'message-headers
792 :type 'message-header-lines)
794 (defcustom message-default-news-headers ""
795 "*A string of header lines to be inserted in outgoing news articles."
796 :group 'message-headers
798 :type 'message-header-lines)
800 ;; Note: could use /usr/ucb/mail instead of sendmail;
801 ;; options -t, and -v if not interactive.
802 (defcustom message-mailer-swallows-blank-line
803 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
804 system-configuration)
805 (file-readable-p "/etc/sendmail.cf")
806 (let ((buffer (get-buffer-create " *temp*")))
810 (insert-file-contents "/etc/sendmail.cf")
811 (goto-char (point-min))
812 (let ((case-fold-search nil))
813 (re-search-forward "^OR\\>" nil t)))
814 (kill-buffer buffer))))
815 ;; According to RFC822, "The field-name must be composed of printable
816 ;; ASCII characters (i. e., characters that have decimal values between
817 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
819 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
820 "*Set this non-nil if the system's mailer runs the header and body together.
821 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
822 The value should be an expression to test whether the problem will
824 :group 'message-sending
827 ;;; XXX: This symbol is overloaded! See below.
828 (defvar message-user-agent nil
829 "String of the form of PRODUCT/VERSION. Used for User-Agent header field.")
831 (static-when (boundp 'MULE)
832 (require 'reporter));; `define-mail-user-agent' is here.
835 (define-mail-user-agent 'message-user-agent
836 'message-mail 'message-send-and-exit
837 'message-kill-buffer 'message-send-hook)
839 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
840 "If non-nil, delete the deletable headers before feeding to mh.")
842 (defvar message-send-method-alist
843 '((news message-news-p message-send-via-news)
844 (mail message-mail-p message-send-via-mail))
845 "Alist of ways to send outgoing messages.
846 Each element has the form
848 \(TYPE PREDICATE FUNCTION)
850 where TYPE is a symbol that names the method; PREDICATE is a function
851 called without any parameters to determine whether the message is
852 a message of type TYPE; and FUNCTION is a function to be called if
853 PREDICATE returns non-nil. FUNCTION is called with one parameter --
856 (defcustom message-mail-alias-type 'abbrev
857 "*What alias expansion type to use in Message buffers.
858 The default is `abbrev', which uses mailabbrev. nil switches
861 :link '(custom-manual "(message)Mail Aliases")
862 :type '(choice (const :tag "Use Mailabbrev" abbrev)
863 (const :tag "No expansion" nil)))
865 (defcustom message-auto-save-directory
866 (file-name-as-directory (nnheader-concat message-directory "drafts"))
867 "*Directory where Message auto-saves buffers if Gnus isn't running.
868 If nil, Message won't auto-save."
869 :group 'message-buffers
870 :type '(choice directory (const :tag "Don't auto-save" nil)))
872 (defcustom message-buffer-naming-style 'unique
873 "*The way new message buffers are named.
874 Valid valued are `unique' and `unsent'."
876 :group 'message-buffers
877 :type '(choice (const :tag "unique" unique)
878 (const :tag "unsent" unsent)))
880 (defcustom message-default-charset
881 (and (featurep 'xemacs) (not (featurep 'mule)) 'iso-8859-1)
882 "Default charset used in non-MULE XEmacsen."
887 (defcustom message-dont-reply-to-names
888 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
889 "*A regexp specifying names to prune when doing wide replies.
890 A value of nil means exclude your own name only."
893 :type '(choice (const :tag "Yourself" nil)
896 (defvar message-shoot-gnksa-feet nil
897 "*A list of GNKSA feet you are allowed to shoot.
898 Gnus gives you all the opportunity you could possibly want for
899 shooting yourself in the foot. Also, Gnus allows you to shoot the
900 feet of Good Net-Keeping Seal of Approval. The following are foot
902 `empty-article' Allow you to post an empty article;
903 `quoted-text-only' Allow you to post quoted text only;
904 `multiple-copies' Allow you to post multiple copies.")
906 (defsubst message-gnksa-enable-p (feature)
907 (or (not (listp message-shoot-gnksa-feet))
908 (memq feature message-shoot-gnksa-feet)))
910 ;;; Internal variables.
911 ;;; Well, not really internal.
913 (defvar message-mode-syntax-table
914 (let ((table (copy-syntax-table text-mode-syntax-table)))
915 (modify-syntax-entry ?% ". " table)
916 (modify-syntax-entry ?> ". " table)
917 (modify-syntax-entry ?< ". " table)
919 "Syntax table used while in Message mode.")
921 (defvar message-mode-abbrev-table text-mode-abbrev-table
922 "Abbrev table used in Message mode buffers.
923 Defaults to `text-mode-abbrev-table'.")
925 (defface message-header-to-face
928 (:foreground "green2" :bold t))
931 (:foreground "MidnightBlue" :bold t))
933 (:bold t :italic t)))
934 "Face used for displaying From headers."
935 :group 'message-faces)
937 (defface message-header-cc-face
940 (:foreground "green4" :bold t))
943 (:foreground "MidnightBlue"))
946 "Face used for displaying Cc headers."
947 :group 'message-faces)
949 (defface message-header-subject-face
952 (:foreground "green3"))
955 (:foreground "navy blue" :bold t))
958 "Face used for displaying subject headers."
959 :group 'message-faces)
961 (defface message-header-newsgroups-face
964 (:foreground "yellow" :bold t :italic t))
967 (:foreground "blue4" :bold t :italic t))
969 (:bold t :italic t)))
970 "Face used for displaying newsgroups headers."
971 :group 'message-faces)
973 (defface message-header-other-face
976 (:foreground "#b00000"))
979 (:foreground "steel blue"))
981 (:bold t :italic t)))
982 "Face used for displaying newsgroups headers."
983 :group 'message-faces)
985 (defface message-header-name-face
988 (:foreground "DarkGreen"))
991 (:foreground "cornflower blue"))
994 "Face used for displaying header names."
995 :group 'message-faces)
997 (defface message-header-xheader-face
1000 (:foreground "blue"))
1003 (:foreground "blue"))
1006 "Face used for displaying X-Header headers."
1007 :group 'message-faces)
1009 (defface message-separator-face
1012 (:foreground "blue3"))
1015 (:foreground "brown"))
1018 "Face used for displaying the separator."
1019 :group 'message-faces)
1021 (defface message-cited-text-face
1024 (:foreground "red"))
1027 (:foreground "red"))
1030 "Face used for displaying cited text names."
1031 :group 'message-faces)
1033 (defface message-mml-face
1036 (:foreground "ForestGreen"))
1039 (:foreground "ForestGreen"))
1042 "Face used for displaying MML."
1043 :group 'message-faces)
1045 (defvar message-font-lock-fence-open-regexp "[+|]"
1046 "*Regexp that matches fence open string.")
1048 (defvar message-font-lock-fence-close-regexp "|"
1049 "*Regexp that matches fence close string.")
1051 (defvar message-font-lock-fence-open-position nil
1052 "*Cons of SYMBOL of a function or a variable and a number of OFFSET that
1053 indicate the fence open position. If it is non-nil,
1054 `message-font-lock-fence-open-regexp' is not used for searching for the
1055 fence open position. If SYMBOL is a function, it is called with one argument
1056 last cursor position and should return the fence open position as a number
1057 or a marker. If SYMBOL is a variable symbol, the value is examined with
1058 `symbol-value'. OFFSET is added to the position to compensate the value.
1059 For example, the following combinations of variable symbol and offset value
1062 Egg v3: '(egg:*region-start* . -1)
1063 Canna: '(canna:*region-start* . 0)
1066 (defvar message-font-lock-fence-close-position nil
1067 "*Cons of SYMBOL of a function or a variable and a number of OFFSET that
1068 indicate the fence close position. If it is non-nil,
1069 `message-font-lock-fence-close-regexp' is not used for searching for the
1070 fence close position. If SYMBOL is a function, it is called with one argument
1071 last cursor position and should return the fence close position as a number
1072 or a marker. If SYMBOL is a variable symbol, the value is examined with
1073 `symbol-value'. OFFSET is added to the position to compensate the value.
1074 For example, the following combinations of variable symbol and offset value
1077 Egg v3: '(egg:*region-end* . 0)
1078 Canna: '(canna:*region-end* . 0)
1081 (defvar message-font-lock-cited-text-regexp
1082 "^[\t ]*\\([^\000- :>|}\177]*\\)[:>|}].*"
1083 "*Regexp that matches cited text. It should have a grouping for the
1084 citation prefix which is ended at the beginning of citation mark string.")
1086 (defvar message-font-lock-citation-name-max-column 10
1087 "*Maximun number of column for citation name for fontifying.")
1089 (defvar message-font-lock-last-position nil
1090 "Internal buffer local variable to save the last cursor position
1091 before fontifying.")
1093 (eval-after-load "font-lock"
1094 '(defadvice font-lock-after-change-function
1095 (before message-font-lock-save-last-position activate)
1096 "Save last cursor position before fontifying."
1097 (if (eq 'message-mode major-mode)
1098 (setq message-font-lock-last-position (point)))))
1100 (defun message-font-lock-cited-text-matcher (limit)
1101 "Search for a cited text containing `message-font-lock-cited-text-regexp'
1102 forward. Argument LIMIT bounds the search. If a cited text is found, it
1103 returns t and sets match data 1 and 2, otherwise it returns nil. Normally,
1104 match data 2 has zero length, but if the FENCE (for input method) is detected
1105 in matched text, result is divided into match data 1 and 2 across the FENCE.
1106 See also the documentations for the following variables:
1107 `message-font-lock-fence-open-regexp'
1108 `message-font-lock-fence-close-regexp'
1109 `message-font-lock-fence-open-position'
1110 `message-font-lock-fence-close-position'
1113 (when (re-search-forward message-font-lock-cited-text-regexp limit t)
1114 (let* ((start0 (match-beginning 0))
1115 (end0 (match-end 0))
1116 (cite-mark (match-end 1))
1119 (goto-char cite-mark)
1120 (<= (current-column)
1121 message-font-lock-citation-name-max-column)))
1125 message-font-lock-last-position
1126 (>= message-font-lock-last-position start0)
1127 (<= message-font-lock-last-position end0)
1129 (message-font-lock-fence-open-position
1130 (let* ((symbol (car message-font-lock-fence-open-position))
1132 (cond ((functionp symbol)
1133 (funcall symbol message-font-lock-last-position))
1134 ((and (symbolp symbol)
1136 (symbol-value symbol)))))
1137 (when (markerp open)
1138 (setq open (marker-position open)))
1142 (cdr message-font-lock-fence-open-position)))
1143 (>= message-font-lock-last-position open)
1145 (or (not message-font-lock-fence-open-regexp)
1146 (looking-at message-font-lock-fence-open-regexp))
1148 (message-font-lock-fence-open-regexp
1149 (goto-char message-font-lock-last-position)
1150 (when (re-search-backward
1151 message-font-lock-fence-open-regexp start0 t)
1152 (setq end1 (match-beginning 0)))))
1153 (setq should-fontify
1154 (and message-font-lock-fence-open-position
1155 (not (eq cite-mark end1))))
1157 (message-font-lock-fence-close-position
1158 (let* ((symbol (car message-font-lock-fence-close-position))
1160 (cond ((functionp symbol)
1161 (funcall symbol message-font-lock-last-position))
1162 ((and (symbolp symbol)
1164 (symbol-value symbol)))))
1165 (when (markerp close)
1166 (setq close (marker-position close)))
1167 (and (numberp close)
1170 (cdr message-font-lock-fence-close-position)))
1171 (<= message-font-lock-last-position close)
1172 (setq start2 close))))
1173 (message-font-lock-fence-close-regexp
1174 (goto-char message-font-lock-last-position)
1175 (when (looking-at message-font-lock-fence-close-regexp)
1176 (setq start2 (match-end 0)))))
1177 (setq should-fontify
1178 (and (not (and (not message-font-lock-fence-open-position)
1179 (eq cite-mark end1)))
1180 (not (eq cite-mark start2)))))
1182 (when should-fontify
1184 (store-match-data (list start0 end0 start0 end1 start2 end0))
1185 (store-match-data (list start0 end0 start0 end0 end0 end0)))
1187 (setq message-font-lock-last-position nil)))
1189 (defvar message-font-lock-keywords-1
1190 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1191 `((,(concat "^\\([Tt]o:\\)" content)
1192 (1 'message-header-name-face)
1193 (2 'message-header-to-face nil t))
1194 (,(concat "^\\([GBF]?[Cc][Cc]:\\|[Rr]eply-[Tt]o:\\|"
1195 "[Mm]ail-[Cc]opies-[Tt]o:\\|"
1196 "[Mm]ail-[Rr]eply-[Tt]o:\\|"
1197 "[Mm]ail-[Ff]ollowup-[Tt]o:\\)" content)
1198 (1 'message-header-name-face)
1199 (2 'message-header-cc-face nil t))
1200 (,(concat "^\\([Ss]ubject:\\)" content)
1201 (1 'message-header-name-face)
1202 (2 'message-header-subject-face nil t))
1203 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content)
1204 (1 'message-header-name-face)
1205 (2 'message-header-newsgroups-face nil t))
1206 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content)
1207 (1 'message-header-name-face)
1208 (2 'message-header-other-face nil t))
1209 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content)
1210 (1 'message-header-name-face)
1211 (2 'message-header-name-face))
1212 ,@(if (and mail-header-separator
1213 (not (equal mail-header-separator "")))
1214 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1215 1 'message-separator-face))
1218 (defvar message-font-lock-keywords-2
1219 (append message-font-lock-keywords-1
1220 `((message-font-lock-cited-text-matcher
1221 (1 'message-cited-text-face)
1222 (2 'message-cited-text-face))
1223 (,(concat "^\\(" message-cite-prefix-regexp "\\).*")
1224 (0 'message-cited-text-face))
1225 ("<#/?\\(multipart\\|part\\|external\\|mml\\).*>"
1226 (0 'message-mml-face)))))
1228 (defvar message-font-lock-keywords message-font-lock-keywords-2
1229 "Additional expressions to highlight in Message mode.")
1231 ;; XEmacs does it like this. For Emacs, we have to set the
1232 ;; `font-lock-defaults' buffer-local variable.
1233 (put 'message-mode 'font-lock-defaults
1234 '((message-font-lock-keywords
1235 message-font-lock-keywords-1
1236 message-font-lock-keywords-2)
1238 (font-lock-mark-block-function . mark-paragraph)))
1240 (defvar message-face-alist
1241 '((bold . bold-region)
1242 (underline . underline-region)
1243 (default . (lambda (b e)
1245 (ununderline-region b e))))
1246 "Alist of mail and news faces for facemenu.
1247 The cdr of ech entry is a function for applying the face to a region.")
1249 (defcustom message-send-hook nil
1250 "Hook run before sending messages."
1251 :group 'message-various
1252 :options '(ispell-message)
1255 (defcustom message-send-mail-hook nil
1256 "Hook run before sending mail messages."
1257 :group 'message-various
1260 (defcustom message-send-news-hook nil
1261 "Hook run before sending news messages."
1262 :group 'message-various
1265 (defcustom message-sent-hook nil
1266 "Hook run after sending messages."
1267 :group 'message-various
1270 (defcustom message-use-multi-frames nil
1271 "Make new frame when sending messages."
1272 :group 'message-frames
1275 (defcustom message-delete-frame-on-exit nil
1276 "Delete frame after sending messages."
1277 :group 'message-frames
1278 :type '(choice (const :tag "off" nil)
1279 (const :tag "always" t)
1280 (const :tag "ask" ask)))
1282 (defvar message-draft-coding-system
1284 ((boundp 'MULE) '*junet*)
1285 ((not (fboundp 'find-coding-system)) nil)
1286 ((find-coding-system 'emacs-mule)
1287 (if (memq system-type '(windows-nt ms-dos ms-windows))
1288 'emacs-mule-dos 'emacs-mule))
1289 ((find-coding-system 'escape-quoted) 'escape-quoted)
1290 ((find-coding-system 'no-conversion) 'no-conversion)
1292 "Coding system to compose mail.")
1294 (defcustom message-send-mail-partially-limit 1000000
1295 "The limitation of messages sent as message/partial.
1296 The lower bound of message size in characters, beyond which the message
1297 should be sent in several parts. If it is nil, the size is unlimited."
1299 :group 'message-buffers
1300 :type '(choice (const :tag "unlimited" nil)
1303 (defcustom message-alternative-emails nil
1304 "A regexp to match the alternative email addresses.
1305 The first matched address (not primary one) is used in the From field."
1306 :group 'message-headers
1307 :type '(choice (const :tag "Always use primary" nil)
1310 (defcustom message-mail-user-agent nil
1311 "Like `mail-user-agent'.
1312 Except if it is nil, use Gnus native MUA; if it is t, use
1314 :type '(radio (const :tag "Gnus native"
1317 (const :tag "`mail-user-agent'"
1320 (function-item :tag "Default Emacs mail"
1322 sendmail-user-agent)
1323 (function-item :tag "Emacs interface to MH"
1326 (function :tag "Other"))
1330 ;;; Internal variables.
1332 (defvar message-sending-message "Sending...")
1333 (defvar message-buffer-list nil)
1334 (defvar message-this-is-news nil)
1335 (defvar message-this-is-mail nil)
1336 (defvar message-draft-article nil)
1337 (defvar message-mime-part nil)
1338 (defvar message-posting-charset nil)
1340 ;; Byte-compiler warning
1342 (defvar gnus-active-hashtb)
1343 (defvar gnus-read-active-file))
1345 ;;; Regexp matching the delimiter of messages in UNIX mail format
1346 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1347 ;;; of rmail.el's rmail-unix-mail-delimiter.
1348 (defvar message-unix-mail-delimiter
1349 (let ((time-zone-regexp
1350 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1351 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1357 ;; Many things can happen to an RFC 822 mailbox before it is put into
1358 ;; a `From' line. The leading phrase can be stripped, e.g.
1359 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1360 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1361 ;; can be removed, e.g.
1362 ;; From: joe@y.z (Joe K
1364 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1367 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1368 ;; The mailbox can be removed or be replaced by white space, e.g.
1369 ;; From: "Joe User"{space}{tab}
1371 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1372 ;; where {space} and {tab} represent the Ascii space and tab characters.
1373 ;; We want to match the results of any of these manglings.
1374 ;; The following regexp rejects names whose first characters are
1375 ;; obviously bogus, but after that anything goes.
1376 "\\([^\0-\b\n-\r\^?].*\\)? "
1378 ;; The time the message was sent.
1379 "\\([^\0-\r \^?]+\\) +" ; day of the week
1380 "\\([^\0-\r \^?]+\\) +" ; month
1381 "\\([0-3]?[0-9]\\) +" ; day of month
1382 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1384 ;; Perhaps a time zone, specified by an abbreviation, or by a
1389 " \\([0-9][0-9]+\\) *"
1391 ;; On some systems the time zone can appear after the year, too.
1395 "\\(remote from .*\\)?"
1398 "Regexp matching the delimiter of messages in UNIX mail format.")
1400 (defvar message-unsent-separator
1401 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1402 "^ *---+ +Returned message +---+ *$\\|"
1403 "^Start of returned message$\\|"
1404 "^ *---+ +Original message +---+ *$\\|"
1405 "^ *--+ +begin message +--+ *$\\|"
1406 "^ *---+ +Original message follows +---+ *$\\|"
1407 "^ *---+ +Undelivered message follows +---+ *$\\|"
1408 "^|? *---+ +Message text follows: +---+ *|?$")
1409 "A regexp that matches the separator before the text of a failed message.")
1411 (defvar message-header-format-alist
1413 (To . message-fill-address)
1414 (Cc . message-fill-address)
1425 (References . message-shorten-references)
1427 "Alist used for formatting headers.")
1429 (defvar message-options nil
1430 "Some saved answers when sending message.")
1433 (autoload 'message-setup-toolbar "messagexmas")
1434 (autoload 'mh-new-draft-name "mh-comp")
1435 (autoload 'mh-send-letter "mh-comp")
1436 (autoload 'gnus-point-at-eol "gnus-util")
1437 (autoload 'gnus-point-at-bol "gnus-util")
1438 (autoload 'gnus-output-to-rmail "gnus-util")
1439 (autoload 'gnus-output-to-mail "gnus-util")
1440 (autoload 'mail-abbrev-in-expansion-header-p "mailabbrev")
1441 (autoload 'nndraft-request-associate-buffer "nndraft")
1442 (autoload 'nndraft-request-expire-articles "nndraft")
1443 (autoload 'gnus-open-server "gnus-int")
1444 (autoload 'gnus-request-post "gnus-int")
1445 (autoload 'gnus-copy-article-buffer "gnus-msg")
1446 (autoload 'gnus-alive-p "gnus-util")
1447 (autoload 'gnus-group-name-charset "gnus-group")
1448 (autoload 'rmail-output "rmail")
1449 (autoload 'mu-cite-original "mu-cite"))
1454 ;;; Utility functions.
1456 (defun message-eval-parameter (parameter)
1458 (if (symbolp parameter)
1459 (if (functionp parameter)
1465 (defsubst message-get-parameter (key &optional alist)
1467 (setq alist message-parameter-alist))
1468 (cdr (assq key alist)))
1470 (defmacro message-get-parameter-with-eval (key &optional alist)
1471 `(message-eval-parameter (message-get-parameter ,key ,alist)))
1473 (defmacro message-y-or-n-p (question show &rest text)
1474 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1475 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1477 (defmacro message-delete-line (&optional n)
1478 "Delete the current line (and the next N lines)."
1479 `(delete-region (progn (beginning-of-line) (point))
1480 (progn (forward-line ,(or n 1)) (point))))
1482 (defun message-unquote-tokens (elems)
1483 "Remove double quotes (\") from strings in list ELEMS."
1484 (mapcar (lambda (item)
1485 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1486 (setq item (concat (match-string 1 item)
1487 (match-string 2 item))))
1491 (defun message-tokenize-header (header &optional separator)
1492 "Split HEADER into a list of header elements.
1493 SEPARATOR is a string of characters to be used as separators. \",\"
1494 is used by default."
1497 (let ((regexp (format "[%s]+" (or separator ",")))
1502 (message-set-work-buffer)
1504 (goto-char (point-min))
1509 (cond ((and (> (point) beg)
1511 (and (looking-at regexp)
1514 (push (buffer-substring beg (point)) elems)
1515 (setq beg (match-end 0)))
1516 ((eq (char-after) ?\")
1517 (setq quoted (not quoted)))
1518 ((and (eq (char-after) ?\()
1521 ((and (eq (char-after) ?\))
1524 (nreverse elems)))))
1526 (defun message-mail-file-mbox-p (file)
1527 "Say whether FILE looks like a Unix mbox file."
1528 (when (and (file-exists-p file)
1529 (file-readable-p file)
1530 (file-regular-p file))
1532 (nnheader-insert-file-contents file)
1533 (goto-char (point-min))
1534 (looking-at message-unix-mail-delimiter))))
1536 (defun message-fetch-field (header &optional not-all)
1537 "The same as `mail-fetch-field', only remove all newlines."
1538 (let* ((inhibit-point-motion-hooks t)
1539 (case-fold-search t)
1540 (value (mail-fetch-field header nil (not not-all))))
1542 (while (string-match "\n[\t ]+" value)
1543 (setq value (replace-match " " t t value)))
1544 (set-text-properties 0 (length value) nil value)
1547 (defun message-narrow-to-field ()
1548 "Narrow the buffer to the header on the current line."
1554 (if (re-search-forward "^[^ \n\t]" nil t)
1559 (goto-char (point-min)))
1561 (defun message-add-header (&rest headers)
1562 "Add the HEADERS to the message header, skipping those already present."
1565 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1566 (error "Invalid header `%s'" (car headers)))
1567 (setq hclean (match-string 1 (car headers)))
1569 (message-narrow-to-headers)
1570 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1571 (goto-char (point-max))
1572 (if (string-match "\n$" (car headers))
1573 (insert (car headers))
1574 (insert (car headers) ?\n)))))
1575 (setq headers (cdr headers))))
1578 (defun message-fetch-reply-field (header)
1579 "Fetch field HEADER from the message we're replying to."
1580 (let ((buffer (message-eval-parameter message-reply-buffer)))
1582 (buffer-name buffer))
1585 (message-fetch-field header)))))
1587 (defun message-set-work-buffer ()
1588 (if (get-buffer " *message work*")
1590 (set-buffer " *message work*")
1592 (set-buffer (get-buffer-create " *message work*"))
1593 (kill-all-local-variables)))
1595 (defun message-functionp (form)
1596 "Return non-nil if FORM is funcallable."
1597 (or (and (symbolp form) (fboundp form))
1598 (and (listp form) (eq (car form) 'lambda))
1599 (byte-code-function-p form)))
1601 (defun message-strip-list-identifiers (subject)
1602 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1603 (require 'gnus-sum) ; for gnus-list-identifiers
1604 (let ((regexp (if (stringp gnus-list-identifiers)
1605 gnus-list-identifiers
1606 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1607 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1608 " *\\)\\)+\\(Re: +\\)?\\)") subject)
1609 (concat (substring subject 0 (match-beginning 1))
1610 (or (match-string 3 subject)
1611 (match-string 5 subject))
1616 (defun message-strip-subject-re (subject)
1617 "Remove \"Re:\" from subject lines in string SUBJECT."
1618 (if (string-match message-subject-re-regexp subject)
1619 (substring subject (match-end 0))
1622 (defun message-remove-header (header &optional is-regexp first reverse)
1623 "Remove HEADER in the narrowed buffer.
1624 If IS-REGEXP, HEADER is a regular expression.
1625 If FIRST, only remove the first instance of the header.
1626 Return the number of headers removed."
1627 (goto-char (point-min))
1628 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
1630 (case-fold-search t)
1632 (while (and (not (eobp))
1635 (not (looking-at regexp))
1636 (looking-at regexp))
1643 ;; There might be a continuation header, so we have to search
1644 ;; until we find a new non-continuation line.
1647 (if (re-search-forward "^[^ \t]" nil t)
1648 (goto-char (match-beginning 0))
1651 (if (re-search-forward "^[^ \t]" nil t)
1652 (goto-char (match-beginning 0))
1653 (goto-char (point-max)))))
1656 (defun message-remove-first-header (header)
1657 "Remove the first instance of HEADER if there is more than one."
1659 (regexp (concat "^" (regexp-quote header) ":")))
1661 (goto-char (point-min))
1662 (while (re-search-forward regexp nil t)
1665 (message-remove-header header nil t)
1668 (defun message-narrow-to-headers ()
1669 "Narrow the buffer to the head of the message."
1672 (goto-char (point-min))
1673 (if (re-search-forward
1674 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1677 (goto-char (point-min)))
1679 (defun message-narrow-to-head-1 ()
1680 "Like `message-narrow-to-head'. Don't widen."
1682 (goto-char (point-min))
1683 (if (search-forward "\n\n" nil 1)
1686 (goto-char (point-min)))
1688 (defun message-narrow-to-head ()
1689 "Narrow the buffer to the head of the message.
1690 Point is left at the beginning of the narrowed-to region."
1692 (message-narrow-to-head-1))
1694 (defun message-narrow-to-headers-or-head ()
1695 "Narrow the buffer to the head of the message."
1698 (goto-char (point-min))
1701 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1702 (match-beginning 0))
1703 ((search-forward "\n\n" nil t)
1707 (goto-char (point-min)))
1709 (defun message-news-p ()
1710 "Say whether the current buffer contains a news message."
1711 (and (not message-this-is-mail)
1712 (or message-this-is-news
1715 (message-narrow-to-headers)
1716 (and (message-fetch-field "newsgroups")
1717 (not (message-fetch-field "posted-to"))))))))
1719 (defun message-mail-p ()
1720 "Say whether the current buffer contains a mail message."
1721 (and (not message-this-is-news)
1722 (or message-this-is-mail
1725 (message-narrow-to-headers)
1726 (or (message-fetch-field "to")
1727 (message-fetch-field "cc")
1728 (message-fetch-field "bcc")))))))
1730 (defun message-next-header ()
1731 "Go to the beginning of the next header."
1733 (or (eobp) (forward-char 1))
1734 (not (if (re-search-forward "^[^ \t]" nil t)
1736 (goto-char (point-max)))))
1738 (defun message-sort-headers-1 ()
1739 "Sort the buffer as headers using `message-rank' text props."
1740 (goto-char (point-min))
1743 nil 'message-next-header
1745 (message-next-header)
1749 (or (get-text-property (point) 'message-rank)
1752 (defun message-sort-headers ()
1753 "Sort the headers of the current message according to `message-header-format-alist'."
1757 (let ((max (1+ (length message-header-format-alist)))
1759 (message-narrow-to-headers)
1760 (while (re-search-forward "^[^ \n]+:" nil t)
1762 (match-beginning 0) (1+ (match-beginning 0))
1764 (if (setq rank (length (memq (assq (intern (buffer-substring
1766 (1- (match-end 0))))
1767 message-header-format-alist)
1768 message-header-format-alist)))
1771 (message-sort-headers-1))))
1781 (defvar message-mode-map nil)
1783 (unless message-mode-map
1784 (setq message-mode-map (make-keymap))
1785 (set-keymap-parent message-mode-map text-mode-map)
1786 (define-key message-mode-map "\C-c?" 'describe-mode)
1788 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
1789 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
1790 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
1791 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
1792 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
1793 ;; (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
1794 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-mail-reply-to)
1795 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
1796 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
1797 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
1798 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
1799 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
1800 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
1801 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
1802 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
1803 (define-key message-mode-map "\C-c\C-fc" 'message-goto-mail-copies-to)
1805 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
1806 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
1808 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
1809 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
1810 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
1811 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
1812 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
1813 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
1814 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
1815 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
1817 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
1818 (define-key message-mode-map "\C-c\C-s" 'message-send)
1819 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
1820 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
1822 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
1823 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
1824 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
1825 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
1826 (define-key message-mode-map "\M-q" 'message-fill-paragraph)
1828 (define-key message-mode-map "\t" 'message-tab)
1829 (define-key message-mode-map "\M-;" 'comment-region)
1831 (define-key message-mode-map "\C-x\C-s" 'message-save-drafts)
1832 (define-key message-mode-map "\C-xk" 'message-mimic-kill-buffer))
1835 message-mode-menu message-mode-map "Message Menu."
1837 ["Sort Headers" message-sort-headers t]
1838 ["Yank Original" message-yank-original t]
1839 ["Fill Yanked Message" message-fill-yanked-message t]
1840 ["Insert Signature" message-insert-signature t]
1841 ["Caesar (rot13) Message" message-caesar-buffer-body t]
1842 ["Caesar (rot13) Region" message-caesar-region (mark t)]
1843 ["Elide Region" message-elide-region (mark t)]
1844 ["Delete Outside Region" message-delete-not-region (mark t)]
1845 ["Kill To Signature" message-kill-to-signature t]
1846 ["Newline and Reformat" message-newline-and-reformat t]
1847 ["Rename buffer" message-rename-buffer t]
1848 ["Spellcheck" ispell-message
1849 ,@(if (featurep 'xemacs) '(t)
1850 '(:help "Spellcheck this message"))]
1851 ["Attach file as MIME" mime-edit-insert-file
1852 ,@(if (featurep 'xemacs) '(t)
1853 '(:help "Attach a file at point"))]
1855 ["Send Message" message-send-and-exit
1856 ,@(if (featurep 'xemacs) '(t)
1857 '(:help "Send this message"))]
1858 ["Abort Message" message-dont-send
1859 ,@(if (featurep 'xemacs) '(t)
1860 '(:help "File this draft message and exit"))]
1861 ["Kill Message" message-kill-buffer
1862 ,@(if (featurep 'xemacs) '(t)
1863 '(:help "Delete this message without sending"))]))
1866 message-mode-field-menu message-mode-map ""
1868 ["Fetch To" message-insert-to t]
1869 ["Fetch Newsgroups" message-insert-newsgroups t]
1871 ["To" message-goto-to t]
1872 ["Subject" message-goto-subject t]
1873 ["Cc" message-goto-cc t]
1874 ["Reply-To" message-goto-reply-to t]
1875 ["Mail-Reply-To" message-goto-mail-reply-to t]
1876 ["Mail-Followup-To" message-goto-mail-followup-to t]
1877 ["Mail-Copies-To" message-goto-mail-copies-to t]
1878 ["Summary" message-goto-summary t]
1879 ["Keywords" message-goto-keywords t]
1880 ["Newsgroups" message-goto-newsgroups t]
1881 ["Followup-To" message-goto-followup-to t]
1882 ["Distribution" message-goto-distribution t]
1883 ["Body" message-goto-body t]
1884 ["Signature" message-goto-signature t]))
1886 (defvar message-tool-bar-map nil)
1889 (defvar facemenu-add-face-function)
1890 (defvar facemenu-remove-face-function))
1893 (defun message-mode ()
1894 "Major mode for editing mail and news to be sent.
1895 Like Text Mode but with these additional commands:\\<message-mode-map>
1896 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
1897 C-c C-d Postpone sending the message C-c C-k Kill the message
1898 C-c C-f move to a header field (and create it if there isn't):
1899 C-c C-f C-t move to To C-c C-f C-s move to Subject
1900 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1901 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1902 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1903 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1904 C-c C-f C-m move to Mail-Followup-To
1905 C-c C-f C-f move to Followup-To
1906 C-c C-t `message-insert-to' (add a To header to a news followup)
1907 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
1908 C-c C-b `message-goto-body' (move to beginning of message text).
1909 C-c C-i `message-goto-signature' (move to the beginning of the signature).
1910 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
1911 C-c C-y `message-yank-original' (insert current message, if any).
1912 C-c C-q `message-fill-yanked-message' (fill what was yanked).
1913 C-c C-e `message-elide-region' (elide the text between point and mark).
1914 C-c C-v `message-delete-not-region' (remove the text outside the region).
1915 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
1916 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
1917 M-RET `message-newline-and-reformat' (break the line and reformat)."
1919 (kill-all-local-variables)
1920 (set (make-local-variable 'message-reply-buffer) nil)
1921 (make-local-variable 'message-send-actions)
1922 (make-local-variable 'message-exit-actions)
1923 (make-local-variable 'message-kill-actions)
1924 (make-local-variable 'message-postpone-actions)
1925 (make-local-variable 'message-draft-article)
1926 (make-local-hook 'kill-buffer-hook)
1927 (set-syntax-table message-mode-syntax-table)
1928 (use-local-map message-mode-map)
1929 (setq local-abbrev-table message-mode-abbrev-table)
1930 (setq major-mode 'message-mode)
1931 (setq mode-name "Message")
1932 (setq buffer-offer-save t)
1933 (make-local-variable 'facemenu-add-face-function)
1934 (make-local-variable 'facemenu-remove-face-function)
1935 (setq facemenu-add-face-function
1937 (let ((face-fun (cdr (assq face message-face-alist))))
1939 (funcall face-fun (point) end)
1940 (error "Face %s not configured for %s mode" face mode-name)))
1942 facemenu-remove-face-function t)
1943 (make-local-variable 'message-reply-headers)
1944 (setq message-reply-headers nil)
1945 (make-local-variable 'message-user-agent)
1946 (make-local-variable 'message-post-method)
1947 (set (make-local-variable 'message-sent-message-via) nil)
1948 (set (make-local-variable 'message-checksum) nil)
1949 (make-local-variable 'message-parameter-alist)
1950 (setq message-parameter-alist
1951 (copy-sequence message-startup-parameter-alist))
1952 (message-setup-fill-variables)
1953 ;; Allow using comment commands to add/remove quoting.
1954 (set (make-local-variable 'comment-start) message-yank-prefix)
1955 (if (featurep 'xemacs)
1956 (message-setup-toolbar)
1957 (set (make-local-variable 'font-lock-defaults)
1958 '((message-font-lock-keywords
1959 message-font-lock-keywords-1
1960 message-font-lock-keywords-2)
1962 (font-lock-mark-block-function . mark-paragraph)))
1963 (if (boundp 'tool-bar-map)
1964 (set (make-local-variable 'tool-bar-map) (message-tool-bar-map))))
1965 (set (make-local-variable 'message-font-lock-last-position) nil)
1966 (easy-menu-add message-mode-menu message-mode-map)
1967 (easy-menu-add message-mode-field-menu message-mode-map)
1968 ;; Allow mail alias things.
1969 (when (eq message-mail-alias-type 'abbrev)
1970 (if (fboundp 'mail-abbrevs-setup)
1971 (mail-abbrevs-setup)
1972 (mail-aliases-setup)))
1973 (message-set-auto-save-file-name)
1974 (make-local-variable 'indent-tabs-mode) ;Turn off tabs for indentation.
1975 (setq indent-tabs-mode nil)
1976 (run-hooks 'text-mode-hook 'message-mode-hook))
1978 (defun message-setup-fill-variables ()
1979 "Setup message fill variables."
1980 (make-local-variable 'paragraph-separate)
1981 (make-local-variable 'paragraph-start)
1982 (make-local-variable 'adaptive-fill-regexp)
1983 (unless (boundp 'adaptive-fill-first-line-regexp)
1984 (setq adaptive-fill-first-line-regexp nil))
1985 (make-local-variable 'adaptive-fill-first-line-regexp)
1986 (make-local-variable 'auto-fill-inhibit-regexp)
1987 (let ((quote-prefix-regexp
1988 ;; User should change message-cite-prefix-regexp if
1989 ;; message-yank-prefix is set to an abnormal value.
1990 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
1991 (setq paragraph-start
1993 (regexp-quote mail-header-separator) "$\\|"
1994 "[ \t]*$\\|" ; blank lines
1995 "-- $\\|" ; signature delimiter
1996 "---+$\\|" ; delimiters for forwarded messages
1997 page-delimiter "$\\|" ; spoiler warnings
1998 ".*wrote:$\\|" ; attribution lines
1999 quote-prefix-regexp "$")) ; empty lines in quoted text
2000 (setq paragraph-separate paragraph-start)
2001 (setq adaptive-fill-regexp
2002 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
2003 (setq adaptive-fill-first-line-regexp
2004 (concat quote-prefix-regexp "\\|"
2005 adaptive-fill-first-line-regexp))
2006 (setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")))
2011 ;;; Message mode commands
2014 ;;; Movement commands
2016 (defun message-goto-to ()
2017 "Move point to the To header."
2019 (message-position-on-field "To"))
2021 (defun message-goto-subject ()
2022 "Move point to the Subject header."
2024 (message-position-on-field "Subject"))
2026 (defun message-goto-cc ()
2027 "Move point to the Cc header."
2029 (message-position-on-field "Cc" "To"))
2031 (defun message-goto-bcc ()
2032 "Move point to the Bcc header."
2034 (message-position-on-field "Bcc" "Cc" "To"))
2036 (defun message-goto-fcc ()
2037 "Move point to the Fcc header."
2039 (message-position-on-field "Fcc" "To" "Newsgroups"))
2041 (defun message-goto-reply-to ()
2042 "Move point to the Reply-To header."
2044 (message-position-on-field "Reply-To" "Subject"))
2046 (defun message-goto-mail-reply-to ()
2047 "Move point to the Mail-Reply-To header."
2049 (message-position-on-field "Mail-Reply-To" "Subject"))
2051 (defun message-goto-mail-followup-to ()
2052 "Move point to the Mail-Followup-To header. If the header is newly created
2053 and To field contains only one address, the address is inserted in default."
2055 (unless (message-position-on-field "Mail-Followup-To" "Subject")
2056 (let ((start (point))
2059 (message-narrow-to-headers)
2060 (setq addresses (split-string (mail-strip-quoted-names
2061 (or (std11-fetch-field "to") ""))
2063 (when (eq 1 (length addresses))
2065 (insert (car addresses))
2066 (goto-char start))))))
2068 (defun message-goto-mail-copies-to ()
2069 "Move point to the Mail-Copies-To header. If the header is newly created,
2070 a string \"never\" is inserted in default."
2072 (unless (message-position-on-field "Mail-Copies-To" "Subject")
2076 (defun message-goto-newsgroups ()
2077 "Move point to the Newsgroups header."
2079 (message-position-on-field "Newsgroups"))
2081 (defun message-goto-distribution ()
2082 "Move point to the Distribution header."
2084 (message-position-on-field "Distribution"))
2086 (defun message-goto-followup-to ()
2087 "Move point to the Followup-To header."
2089 (message-position-on-field "Followup-To" "Newsgroups"))
2091 (defun message-goto-keywords ()
2092 "Move point to the Keywords header."
2094 (message-position-on-field "Keywords" "Subject"))
2096 (defun message-goto-summary ()
2097 "Move point to the Summary header."
2099 (message-position-on-field "Summary" "Subject"))
2101 (defun message-goto-body (&optional interactivep)
2102 "Move point to the beginning of the message body."
2103 (interactive (list t))
2104 (when (and interactivep
2105 (looking-at "[ \t]*\n"))
2107 (goto-char (point-min))
2108 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
2109 (search-forward "\n\n" nil t)))
2111 (defun message-goto-eoh ()
2112 "Move point to the end of the headers."
2117 (defun message-goto-signature ()
2118 "Move point to the beginning of the message signature.
2119 If there is no signature in the article, go to the end and
2122 (goto-char (point-min))
2123 (if (re-search-forward message-signature-separator nil t)
2125 (goto-char (point-max))
2130 (defun message-insert-to (&optional force)
2131 "Insert a To header that points to the author of the article being replied to.
2132 If the original author requested not to be sent mail, the function signals
2134 With the prefix argument FORCE, insert the header anyway."
2136 (let ((co (message-fetch-reply-field "mail-copies-to")))
2137 (when (and (null force)
2139 (or (equal (downcase co) "never")
2140 (equal (downcase co) "nobody")))
2141 (error "The user has requested not to have copies sent via mail")))
2142 (when (and (message-position-on-field "To")
2143 (mail-fetch-field "to")
2144 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
2146 (insert (or (message-fetch-reply-field "mail-reply-to")
2147 (message-fetch-reply-field "reply-to")
2148 (message-fetch-reply-field "from") "")))
2150 (defun message-widen-reply ()
2151 "Widen the reply to include maximum recipients."
2154 (and message-reply-buffer
2155 (buffer-name message-reply-buffer)
2157 (set-buffer message-reply-buffer)
2158 (message-get-reply-headers t)))))
2161 (message-narrow-to-headers)
2162 (dolist (elem follow-to)
2163 (message-remove-header (symbol-name (car elem)))
2164 (goto-char (point-min))
2165 (insert (symbol-name (car elem)) ": "
2166 (cdr elem) "\n"))))))
2168 (defun message-insert-newsgroups ()
2169 "Insert the Newsgroups header from the article being replied to."
2171 (when (and (message-position-on-field "Newsgroups")
2172 (mail-fetch-field "newsgroups")
2173 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
2175 (insert (or (message-fetch-reply-field "newsgroups") "")))
2179 ;;; Various commands
2181 (defun message-delete-not-region (beg end)
2182 "Delete everything in the body of the current message outside of the region."
2186 (delete-region (point) (if (not (message-goto-signature))
2192 (delete-region beg (progn (message-goto-body)
2195 (when (message-goto-signature)
2198 (defun message-kill-to-signature ()
2199 "Deletes all text up to the signature."
2201 (let ((point (point)))
2202 (message-goto-signature)
2205 (kill-region point (point))
2209 (defun message-newline-and-reformat (&optional not-break)
2210 "Insert four newlines, and then reformat if inside quoted text."
2212 (let (quoted point beg end leading-space bolp)
2213 (setq point (point))
2216 (setq bolp (= beg point))
2217 ;; Find first line of the paragraph.
2219 (while (and (not (eobp))
2220 (not (looking-at message-cite-prefix-regexp))
2221 (looking-at paragraph-start))
2224 (when (looking-at message-cite-prefix-regexp)
2225 (setq quoted (match-string 0))
2226 (goto-char (match-end 0))
2227 (looking-at "[ \t]*")
2228 (setq leading-space (match-string 0)))
2232 (< (- point beg) (length quoted)))
2233 ;; break inside the cite prefix.
2239 (while (and (not (eobp))
2240 (not (looking-at paragraph-separate))
2241 (looking-at message-cite-prefix-regexp)
2242 (equal quoted (match-string 0)))
2243 (goto-char (match-end 0))
2244 (looking-at "[ \t]*")
2245 (if (> (length leading-space) (length (match-string 0)))
2246 (setq leading-space (match-string 0)))
2250 (while (and (if (bobp) nil (forward-line -1) t)
2251 (not (looking-at paragraph-start))
2252 (looking-at message-cite-prefix-regexp)
2253 (equal quoted (match-string 0)))
2255 (goto-char (match-end 0))
2256 (looking-at "[ \t]*")
2257 (if (> (length leading-space) (length (match-string 0)))
2258 (setq leading-space (match-string 0)))))
2259 (while (and (not (eobp))
2260 (not (looking-at paragraph-separate))
2261 (not (looking-at message-cite-prefix-regexp)))
2265 (while (and (if (bobp) nil (forward-line -1) t)
2266 (not (looking-at paragraph-start))
2267 (not (looking-at message-cite-prefix-regexp)))
2268 (setq beg (point))))
2271 (narrow-to-region beg end)
2277 (setq point (point))
2279 (delete-region (point) (re-search-forward "[ \t]*"))
2280 (when (and quoted (not bolp))
2281 (insert quoted leading-space)))
2283 (let* ((adaptive-fill-regexp
2284 (regexp-quote (concat quoted leading-space)))
2285 (adaptive-fill-first-line-regexp
2286 adaptive-fill-regexp ))
2287 (fill-paragraph nil))
2288 (fill-paragraph nil))
2289 (if point (goto-char point)))))
2291 (defun message-fill-paragraph ()
2292 "Like `fill-paragraph'."
2294 (message-newline-and-reformat t))
2296 (defun message-insert-signature (&optional force)
2297 "Insert a signature. See documentation for variable `message-signature'."
2298 (interactive (list 0))
2301 ((and (null message-signature)
2304 (goto-char (point-max))
2305 (not (re-search-backward message-signature-separator nil t))))
2306 ((and (null message-signature)
2309 ((message-functionp message-signature)
2310 (funcall message-signature))
2311 ((listp message-signature)
2312 (eval message-signature))
2313 (t message-signature)))
2315 (cond ((stringp signature)
2317 ((and (eq t signature)
2318 message-signature-file
2319 (file-exists-p message-signature-file))
2322 (goto-char (point-max))
2323 ;; Insert the signature.
2327 (if (eq signature t)
2328 (insert-file-contents message-signature-file)
2330 (goto-char (point-max))
2331 (or (bolp) (insert "\n")))))
2333 (defun message-elide-region (b e)
2334 "Elide the text in the region.
2335 An ellipsis (from `message-elide-ellipsis') will be inserted where the
2339 (insert message-elide-ellipsis))
2341 (defvar message-caesar-translation-table nil)
2343 (defun message-caesar-region (b e &optional n)
2344 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
2347 (min (point) (or (mark t) (point)))
2348 (max (point) (or (mark t) (point)))
2349 (when current-prefix-arg
2350 (prefix-numeric-value current-prefix-arg))))
2352 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
2353 (unless (or (zerop n) ; no action needed for a rot of 0
2354 (= b e)) ; no region to rotate
2355 ;; We build the table, if necessary.
2356 (when (or (not message-caesar-translation-table)
2357 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
2358 (setq message-caesar-translation-table
2359 (message-make-caesar-translation-table n)))
2360 (translate-region b e message-caesar-translation-table)))
2362 (defun message-make-caesar-translation-table (n)
2363 "Create a rot table with offset N."
2365 (table (make-string 256 0)))
2366 (while (< (incf i) 256)
2369 (substring table 0 ?A)
2370 (substring table (+ ?A n) (+ ?A n (- 26 n)))
2371 (substring table ?A (+ ?A n))
2372 (substring table (+ ?A 26) ?a)
2373 (substring table (+ ?a n) (+ ?a n (- 26 n)))
2374 (substring table ?a (+ ?a n))
2375 (substring table (+ ?a 26) 255))))
2377 (defun message-caesar-buffer-body (&optional rotnum)
2378 "Caesar rotate all letters in the current buffer by 13 places.
2379 Used to encode/decode possibly offensive messages (commonly in rec.humor).
2380 With prefix arg, specifies the number of places to rotate each letter forward.
2381 Mail and USENET news headers are not rotated."
2382 (interactive (if current-prefix-arg
2383 (list (prefix-numeric-value current-prefix-arg))
2387 (when (message-goto-body)
2388 (narrow-to-region (point) (point-max)))
2389 (message-caesar-region (point-min) (point-max) rotnum))))
2391 (defun message-pipe-buffer-body (program)
2392 "Pipe the message body in the current buffer through PROGRAM."
2395 (when (message-goto-body)
2396 (narrow-to-region (point) (point-max)))
2397 (shell-command-on-region
2398 (point-min) (point-max) program nil t))))
2400 (defun message-rename-buffer (&optional enter-string)
2401 "Rename the *message* buffer to \"*message* RECIPIENT\".
2402 If the function is run with a prefix, it will ask for a new buffer
2403 name, rather than giving an automatic name."
2404 (interactive "Pbuffer name: ")
2407 (goto-char (point-min))
2408 (narrow-to-region (point)
2409 (search-forward mail-header-separator nil 'end))
2411 (if (message-news-p) (message-fetch-field "Newsgroups")
2412 (message-fetch-field "To"))
2415 (if (string-match "," mail-to)
2416 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
2418 (name-default (concat "*message* " mail-trimmed-to))
2419 (name (if enter-string
2420 (read-string "New buffer name: " name-default)
2422 (rename-buffer name t)))))
2424 (defun message-fill-yanked-message (&optional justifyp)
2425 "Fill the paragraphs of a message yanked into this one.
2426 Numeric argument means justify as well."
2429 (goto-char (point-min))
2430 (search-forward (concat "\n" mail-header-separator "\n") nil t)
2431 (let ((fill-prefix message-yank-prefix))
2432 (fill-individual-paragraphs (point) (point-max) justifyp))))
2434 (defun message-indent-citation ()
2435 "Modify text just inserted from a message to be cited.
2436 The inserted text should be the region.
2437 When this function returns, the region is again around the modified text.
2439 Normally, indent each nonblank line `message-indentation-spaces' spaces.
2440 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
2441 (let ((start (point)))
2442 ;; Remove unwanted headers.
2443 (when message-ignored-cited-headers
2448 (if (search-forward "\n\n" nil t)
2451 (message-remove-header message-ignored-cited-headers t)
2452 (when (= (point-min) (point-max))
2453 (setq all-removed t))
2454 (goto-char (point-max)))
2458 ;; Delete blank lines at the start of the buffer.
2459 (while (and (point-min)
2462 (message-delete-line))
2463 ;; Delete blank lines at the end of the buffer.
2464 (goto-char (point-max))
2467 (while (and (zerop (forward-line -1))
2469 (message-delete-line))
2470 ;; Do the indentation.
2471 (if (null message-yank-prefix)
2472 (indent-rigidly start (mark t) message-indentation-spaces)
2475 (while (< (point) (mark t))
2476 (insert message-yank-prefix)
2480 (defun message-list-references (refs-list &rest refs-strs)
2481 "Add `Message-ID's which appear in REFS-STRS but not in REFS-LIST,
2483 (let (refs ref id saved-id)
2484 (when (and refs-list
2485 (integerp message-list-references-add-position))
2486 (let ((pos message-list-references-add-position))
2487 (while (and refs-list
2489 (push (pop refs-list) saved-id)
2490 (setq pos (1- pos)))))
2492 (when (setq refs (pop refs-strs))
2493 (setq refs (std11-parse-msg-ids (std11-lexical-analyze refs)))
2495 (when (eq (car (setq ref (pop refs))) 'msg-id)
2496 (setq id (concat "<" (mapconcat 'cdr (cdr ref) "") ">"))
2497 (or (member id refs-list)
2498 (member id saved-id)
2499 (push id refs-list))))))
2501 (push (pop saved-id) refs-list))
2504 (defvar gnus-article-copy)
2505 (defun message-yank-original (&optional arg)
2506 "Insert the message being replied to, if any.
2507 Puts point before the text and mark after.
2508 Normally indents each nonblank line ARG spaces (default 3). However,
2509 if `message-yank-prefix' is non-nil, insert that prefix on each line.
2511 This function uses `message-cite-function' to do the actual citing.
2513 Just \\[universal-argument] as argument means don't indent, insert no
2514 prefix, and don't delete any headers.
2516 In addition, if `message-yank-add-new-references' is non-nil and this
2517 command is called interactively, new IDs from the yanked article will
2518 be added to \"References\" field.
2519 \(See also `message-yank-add-new-references'.)"
2521 (let ((modified (buffer-modified-p))
2522 (buffer (message-eval-parameter message-reply-buffer))
2525 message-cite-function)
2526 (delete-windows-on buffer t)
2527 (insert-buffer buffer) ; mark will be set at the end of article.
2531 ;; Add new IDs to References field.
2532 (when (and message-yank-add-new-references (interactive-p))
2535 (message-narrow-to-headers)
2536 (setq refs (message-list-references
2538 (message-fetch-field "References")))
2540 (narrow-to-region start end)
2541 (std11-narrow-to-header)
2542 (when (setq refs (message-list-references
2544 (unless (eq message-yank-add-new-references
2546 (or (message-fetch-field "References")
2547 (message-fetch-field "In-Reply-To")))
2548 (message-fetch-field "Message-ID")))
2550 (message-narrow-to-headers)
2551 (goto-char (point-min))
2552 (let ((case-fold-search t))
2553 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
2555 (goto-char (point-max))))
2557 (list (or (assq 'References message-header-format-alist)
2558 '(References . message-fill-references)))
2559 (list (cons 'References
2560 (mapconcat 'identity (nreverse refs) " "))))
2561 (backward-delete-char 1)))))
2564 (funcall message-cite-function))
2565 (message-exchange-point-and-mark)
2569 (setq message-checksum (message-checksum))))))
2571 (defun message-yank-buffer (buffer)
2572 "Insert BUFFER into the current buffer and quote it."
2573 (interactive "bYank buffer: ")
2574 (let ((message-reply-buffer buffer))
2575 (save-window-excursion
2576 (message-yank-original))))
2578 (defun message-buffers ()
2579 "Return a list of active message buffers."
2582 (dolist (buffer (buffer-list t))
2584 (when (and (eq major-mode 'message-mode)
2585 (null message-sent-message-via))
2586 (push (buffer-name buffer) buffers))))
2587 (nreverse buffers)))
2589 (defun message-cite-original-without-signature ()
2590 "Cite function in the standard Message manner."
2591 (let ((start (point))
2594 (when message-indent-citation-function
2595 (if (listp message-indent-citation-function)
2596 message-indent-citation-function
2597 (list message-indent-citation-function)))))
2601 (when (re-search-backward message-signature-separator start t)
2602 ;; Also peel off any blank lines before the signature.
2604 (while (looking-at "^[ \t]*$")
2607 (delete-region (point) end)
2608 (unless (search-backward "\n\n" start t)
2609 ;; Insert a blank line if it is peeled off.
2613 (funcall (pop functions)))
2614 (when message-citation-line-function
2617 (funcall message-citation-line-function))))
2619 (eval-when-compile (defvar mail-citation-hook)) ;Compiler directive
2620 (defun message-cite-original ()
2621 "Cite function in the standard Message manner."
2622 (if (and (boundp 'mail-citation-hook)
2624 (run-hooks 'mail-citation-hook)
2625 (let ((start (point))
2628 (when message-indent-citation-function
2629 (if (listp message-indent-citation-function)
2630 message-indent-citation-function
2631 (list message-indent-citation-function))))
2632 (message-reply-headers (or message-reply-headers
2633 (make-mail-header))))
2634 (mail-header-set-from message-reply-headers
2638 (if (search-forward "\n\n" nil t)
2641 (or (message-fetch-field "from")
2645 (funcall (pop functions)))
2646 (when message-citation-line-function
2649 (funcall message-citation-line-function)))))
2651 (defun message-insert-citation-line ()
2652 "Insert a simple citation line."
2653 (when message-reply-headers
2654 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
2656 (defun message-position-on-field (header &rest afters)
2657 (let ((case-fold-search t))
2660 (goto-char (point-min))
2663 (concat "^" (regexp-quote mail-header-separator) "$"))
2664 (match-beginning 0)))
2665 (goto-char (point-min))
2666 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
2668 (re-search-forward "^[^ \t]" nil 'move)
2670 (skip-chars-backward "\n")
2673 (not (re-search-forward
2674 (concat "^" (regexp-quote (car afters)) ":")
2678 (re-search-forward "^[^ \t]" nil 'move)
2679 (beginning-of-line))
2680 (insert header ": \n")
2684 (defun message-remove-signature ()
2685 "Remove the signature from the text between point and mark.
2686 The text will also be indented the normal way."
2688 (let ((start (point))
2690 (if (not (re-search-forward message-signature-separator (mark t) t))
2691 ;; No signature here, so we just indent the cited text.
2692 (message-indent-citation)
2693 ;; Find the last non-empty line.
2695 (while (looking-at "[ \t]*$")
2698 (setq mark (set-marker (make-marker) (point)))
2700 (message-indent-citation)
2701 ;; Enable undoing the deletion.
2703 (delete-region mark (mark t))
2704 (set-marker mark nil)))))
2709 ;;; Sending messages
2712 ;; Avoid byte-compile warning.
2713 (defvar message-encoding-buffer nil)
2714 (defvar message-edit-buffer nil)
2715 (defvar message-mime-mode nil)
2717 (defun message-send-and-exit (&optional arg)
2718 "Send message like `message-send', then, if no errors, exit from mail buffer."
2720 (let ((buf (current-buffer))
2721 (actions message-exit-actions)
2722 (frame (selected-frame))
2723 (org-frame message-original-frame))
2724 (when (and (message-send arg)
2726 (if message-kill-buffer-on-exit
2729 (when (eq buf (current-buffer))
2730 (message-bury buf)))
2731 (message-do-actions actions)
2732 (message-delete-frame frame org-frame)
2735 (defun message-dont-send ()
2736 "Don't send the message you have been editing."
2738 (message-save-drafts)
2739 (let ((actions message-postpone-actions)
2740 (frame (selected-frame))
2741 (org-frame message-original-frame))
2742 (message-bury (current-buffer))
2743 (message-do-actions actions)
2744 (message-delete-frame frame org-frame)))
2746 (defun message-kill-buffer ()
2747 "Kill the current buffer."
2749 (when (or (not (buffer-modified-p))
2750 (eq t message-kill-buffer-query-function)
2751 (funcall message-kill-buffer-query-function
2752 "The buffer modified; kill anyway? "))
2753 (let ((actions message-kill-actions)
2754 (frame (selected-frame))
2755 (org-frame message-original-frame))
2756 (setq buffer-file-name nil)
2757 (kill-buffer (current-buffer))
2758 (message-do-actions actions)
2759 (message-delete-frame frame org-frame)))
2762 (defun message-mimic-kill-buffer ()
2763 "Kill the current buffer with query."
2765 (unless (eq 'message-mode major-mode)
2766 (error "%s must be invoked from a message buffer." this-command))
2767 (let ((command this-command)
2768 (bufname (read-buffer (format "Kill buffer: (default %s) "
2770 (if (or (not bufname)
2771 (string-equal bufname "")
2772 (string-equal bufname (buffer-name)))
2773 (message-kill-buffer)
2774 (message "%s must be invoked only for the current buffer." command))))
2776 (defun message-delete-frame (frame org-frame)
2777 "Delete frame for editing message."
2778 (when (and (or (static-if (featurep 'xemacs)
2779 (device-on-window-system-p)
2781 (>= emacs-major-version 20))
2782 (or (and (eq message-delete-frame-on-exit t)
2783 (select-frame frame)
2784 (or (eq frame org-frame)
2786 (y-or-n-p "Delete this frame?")
2788 (and (eq message-delete-frame-on-exit 'ask)
2789 (select-frame frame)
2791 (y-or-n-p "Delete this frame?")
2793 (delete-frame frame)))
2795 (defun message-bury (buffer)
2796 "Bury this mail BUFFER."
2797 (let ((newbuf (other-buffer buffer)))
2798 (bury-buffer buffer)
2799 (if (and (fboundp 'frame-parameters)
2800 (cdr (assq 'dedicated (frame-parameters)))
2801 (not (null (delq (selected-frame) (visible-frame-list)))))
2802 (delete-frame (selected-frame))
2803 (switch-to-buffer newbuf))))
2805 (defun message-send (&optional arg)
2806 "Send the message in the current buffer.
2807 If `message-interactive' is non-nil, wait for success indication or
2808 error messages, and inform user.
2809 Otherwise any failure is reported in a message back to the user from
2811 The usage of ARG is defined by the instance that called Message.
2812 It should typically alter the sending method in some way or other."
2815 (when (or (buffer-modified-p)
2816 (message-check-element 'unchanged)
2817 (y-or-n-p "No changes in the buffer; really send? "))
2818 ;; Make it possible to undo the coming changes.
2820 (let ((inhibit-read-only t))
2821 (put-text-property (point-min) (point-max) 'read-only nil))
2822 (run-hooks 'message-send-hook)
2823 (message-fix-before-sending)
2824 (message message-sending-message)
2825 (let ((message-encoding-buffer
2826 (message-generate-new-buffer-clone-locals " message encoding"))
2827 (message-edit-buffer (current-buffer))
2828 (message-mime-mode mime-edit-mode-flag)
2829 (alist message-send-method-alist)
2832 (message-options message-options))
2833 (message-options-set-recipient)
2835 (set-buffer message-encoding-buffer)
2837 ;; Avoid copying text props.
2838 (insert (with-current-buffer message-edit-buffer
2839 (buffer-substring-no-properties (point-min) (point-max))))
2840 (funcall message-encode-function)
2842 (setq elem (pop alist)))
2843 (when (funcall (cadr elem))
2844 (when (and (or (not (memq (car elem)
2845 message-sent-message-via))
2846 (if (or (message-gnksa-enable-p 'multiple-copies)
2847 (not (eq (car elem) 'news)))
2850 "Already sent message via %s; resend? "
2852 (error "Denied posting -- multiple copies.")))
2853 (setq success (funcall (caddr elem) arg)))
2855 (unless (or sent (not success))
2856 (error "No methods specified to send by"))
2858 (when (and success sent)
2861 (run-hooks 'message-sent-hook))
2862 (message "Sending...done")
2863 ;; Mark the buffer as unmodified and delete auto-save.
2864 (set-buffer-modified-p nil)
2865 (delete-auto-save-file-if-necessary t)
2866 (message-disassociate-draft)
2867 ;; Delete other mail buffers and stuff.
2868 (message-do-send-housekeeping)
2869 (message-do-actions message-send-actions)
2872 (kill-buffer message-encoding-buffer)))))
2874 (defun message-send-via-mail (arg)
2875 "Send the current message via mail."
2876 (message-send-mail arg))
2878 (defun message-send-via-news (arg)
2879 "Send the current message via news."
2880 (message-send-news arg))
2882 (defmacro message-check (type &rest forms)
2883 "Eval FORMS if TYPE is to be checked."
2884 `(or (message-check-element ,type)
2888 (put 'message-check 'lisp-indent-function 1)
2889 (put 'message-check 'edebug-form-spec '(form body))
2891 ;; This function will be used by MIME-Edit when inserting invisible parts.
2892 (defun message-invisible-region (start end)
2893 (if (featurep 'xemacs)
2896 (eq (following-char) ?\n))
2897 (setq start (1+ start)))
2899 (goto-char (1- end))
2900 (eq (following-char) ?\n))
2901 (setq end (1- end))))
2902 (put-text-property start end 'invisible t)
2903 (if (eq 'message-mode major-mode)
2904 (put-text-property start end 'message-invisible t)))
2906 (eval-after-load "invisible"
2907 '(defalias 'invisible-region 'message-invisible-region))
2909 (defun message-fix-before-sending ()
2910 "Do various things to make the message nice before sending it."
2911 ;; Make sure there's a newline at the end of the message.
2913 (goto-char (point-max))
2916 ;; Expose all invisible text with the property `message-invisible'.
2917 ;; We should believe that the things might be created by MIME-Edit.
2919 (while (setq start (text-property-any (point-min) (point-max)
2920 'message-invisible t))
2921 (remove-text-properties start
2922 (or (text-property-not-all start (point-max)
2923 'message-invisible t)
2925 '(invisible nil message-invisible nil))))
2926 ;; Expose all invisible text.
2927 (message-check 'invisible-text
2928 (when (text-property-any (point-min) (point-max) 'invisible t)
2929 (put-text-property (point-min) (point-max) 'invisible nil)
2930 (unless (yes-or-no-p
2931 "Invisible text found and made visible; continue posting? ")
2932 (error "Invisible text found and made visible")))))
2934 (defun message-add-action (action &rest types)
2935 "Add ACTION to be performed when doing an exit of type TYPES."
2938 (set (setq var (intern (format "message-%s-actions" (pop types))))
2939 (nconc (symbol-value var) (list action))))))
2941 (defun message-do-actions (actions)
2942 "Perform all actions in ACTIONS."
2943 ;; Now perform actions on successful sending.
2947 ;; A simple function.
2948 ((message-functionp (car actions))
2949 (funcall (car actions)))
2950 ;; Something to be evaled.
2952 (eval (car actions)))))
2955 (defsubst message-maybe-split-and-send-mail ()
2956 "Split a message if necessary, and send it via mail.
2957 Returns nil if sending succeeded, returns any string if sending failed.
2958 This sub function is for exclusive use of `message-send-mail'."
2959 (let ((mime-edit-split-ignored-field-regexp
2960 mime-edit-split-ignored-field-regexp)
2961 (case-fold-search t)
2963 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
2964 (setq mime-edit-split-ignored-field-regexp
2965 (concat (substring mime-edit-split-ignored-field-regexp
2966 0 (match-beginning 0))
2967 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
2968 "_so_don't_rape_it!"
2969 (substring mime-edit-split-ignored-field-regexp
2973 (catch 'message-sending-mail-failure
2974 (mime-edit-maybe-split-and-send
2979 (std11-narrow-to-header mail-header-separator)
2980 (goto-char (point-min))
2981 (when (re-search-forward "^Message-ID:" nil t)
2982 (delete-region (match-end 0) (std11-field-end))
2983 (insert " " (message-make-message-id))))
2985 (funcall message-send-mail-function)
2987 (throw 'message-sending-mail-failure err))))))
2991 (funcall message-send-mail-function)
2995 (if (eq 'error (car failure))
2997 (prin1-to-string failure)))))
2999 (defun message-send-mail-partially ()
3000 "Sendmail as message/partial."
3001 ;; replace the header delimiter with a blank line
3002 (goto-char (point-min))
3004 (concat "^" (regexp-quote mail-header-separator) "\n"))
3005 (replace-match "\n")
3006 (run-hooks 'message-send-mail-hook)
3007 (let ((p (goto-char (point-min)))
3008 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
3009 (curbuf (current-buffer))
3010 (id (message-make-message-id)) (n 1)
3011 plist total header required-mail-headers)
3013 (if (< (point-max) (+ p message-send-mail-partially-limit))
3014 (goto-char (point-max))
3015 (goto-char (+ p message-send-mail-partially-limit))
3017 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
3020 (setq total (length plist))
3021 (push (point-max) plist)
3022 (setq plist (nreverse plist))
3025 (setq p (pop plist))
3028 (copy-to-buffer tembuf p (car plist))
3030 (goto-char (point-min))
3033 (goto-char (point-min))
3034 (narrow-to-region (point) (point))
3037 (setq header (buffer-substring (point-min) (point)))
3038 (goto-char (point-min))
3039 (narrow-to-region (point) (point))
3041 (message-remove-header "Mime-Version")
3042 (message-remove-header "Content-Type")
3043 (message-remove-header "Content-Transfer-Encoding")
3044 (message-remove-header "Message-ID")
3045 (message-remove-header "Lines")
3046 (goto-char (point-max))
3047 (insert "Mime-Version: 1.0\n")
3048 (setq header (buffer-substring (point-min) (point-max))))
3049 (goto-char (point-max))
3050 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n"
3052 (let ((mail-header-separator ""))
3053 (when (memq 'Message-ID message-required-mail-headers)
3054 (insert "Message-ID: " (message-make-message-id) "\n"))
3055 (when (memq 'Lines message-required-mail-headers)
3056 (let ((mail-header-separator ""))
3057 (insert "Lines: " (message-make-lines) "\n")))
3058 (message-goto-subject)
3060 (insert (format " (%d/%d)" n total))
3061 (goto-char (point-max))
3064 (mm-with-unibyte-current-buffer
3065 (funcall message-send-mail-function)))
3067 (setq p (pop plist))
3069 (kill-buffer tembuf))))
3071 (defun message-send-mail (&optional arg)
3072 (require 'mail-utils)
3073 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
3074 (case-fold-search nil)
3075 (news (message-news-p))
3076 (message-this-is-mail t)
3079 (message-narrow-to-headers)
3080 ;; Insert some headers.
3081 (let ((message-deletable-headers
3082 (if news nil message-deletable-headers)))
3083 (message-generate-headers message-required-mail-headers))
3084 ;; Let the user do all of the above.
3085 (run-hooks 'message-header-hook))
3086 (if (not (message-check-mail-syntax))
3094 (insert-buffer message-encoding-buffer)
3095 ;; Remove some headers.
3097 (message-narrow-to-headers)
3098 ;; We Semi-gnus people have no use for it.
3099 ;; ;; We (re)generate the Lines header.
3100 ;; (when (memq 'Lines message-required-mail-headers)
3101 ;; (message-generate-headers '(Lines)))
3102 ;; Remove some headers.
3103 (message-remove-header message-ignored-mail-headers t))
3104 (goto-char (point-max))
3105 ;; require one newline at the end.
3106 (or (= (preceding-char) ?\n)
3110 (message-narrow-to-headers)
3112 (or (message-fetch-field "cc")
3113 (message-fetch-field "to"))
3114 (let ((ct (mime-read-Content-Type)))
3116 (and (eq 'text (cdr (assq 'type ct)))
3117 (eq 'plain (cdr (assq 'subtype ct))))))))
3118 (message-insert-courtesy-copy))
3119 (setq failure (message-maybe-split-and-send-mail)))
3120 (kill-buffer tembuf))
3121 (set-buffer message-edit-buffer)
3124 (message "Couldn't send message via mail: %s" failure)
3126 (push 'mail message-sent-message-via)))))
3128 (defun message-send-mail-with-sendmail ()
3129 "Send off the prepared buffer with sendmail."
3130 (let ((errbuf (if message-interactive
3131 (message-generate-new-buffer-clone-locals
3134 resend-to-addresses delimline)
3135 (let ((case-fold-search t))
3137 (message-narrow-to-headers)
3138 (setq resend-to-addresses (message-fetch-field "resent-to")))
3139 ;; Change header-delimiter to be what sendmail expects.
3140 (goto-char (point-min))
3142 (concat "^" (regexp-quote mail-header-separator) "\n"))
3143 (replace-match "\n")
3145 (setq delimline (point-marker))
3146 (run-hooks 'message-send-mail-hook)
3147 ;; Insert an extra newline if we need it to work around
3148 ;; Sun's bug that swallows newlines.
3149 (goto-char (1+ delimline))
3150 (when (eval message-mailer-swallows-blank-line)
3152 (when message-interactive
3156 (let ((default-directory "/"))
3158 (apply 'call-process-region
3159 (append (list (point-min) (point-max)
3160 (if (boundp 'sendmail-program)
3162 "/usr/lib/sendmail")
3163 nil errbuf nil "-oi")
3164 ;; Always specify who from,
3165 ;; since some systems have broken sendmails.
3166 ;; But some systems are more broken with -f, so
3167 ;; we'll let users override this.
3168 (if (null message-sendmail-f-is-evil)
3169 (list "-f" (message-make-address)))
3170 ;; These mean "report errors by mail"
3171 ;; and "deliver in background".
3172 (if (null message-interactive) '("-oem" "-odb"))
3173 ;; Get the addresses from the message
3174 ;; unless this is a resend.
3175 ;; We must not do that for a resend
3176 ;; because we would find the original addresses.
3177 ;; For a resend, include the specific addresses.
3178 (if resend-to-addresses
3179 (list resend-to-addresses)
3181 (when message-interactive
3184 (goto-char (point-min))
3185 (while (re-search-forward "\n\n* *" nil t)
3186 (replace-match "; "))
3187 (if (not (zerop (buffer-size)))
3188 (error "Sending...failed to %s"
3189 (buffer-substring (point-min) (point-max)))))
3190 (when (bufferp errbuf)
3191 (kill-buffer errbuf)))))
3193 (defun message-send-mail-with-qmail ()
3194 "Pass the prepared message buffer to qmail-inject.
3195 Refer to the documentation for the variable `message-send-mail-function'
3196 to find out how to use this."
3197 ;; replace the header delimiter with a blank line
3198 (goto-char (point-min))
3200 (concat "^" (regexp-quote mail-header-separator) "\n"))
3201 (replace-match "\n")
3203 (run-hooks 'message-send-mail-hook)
3208 'call-process-region 1 (point-max) message-qmail-inject-program
3210 ;; qmail-inject's default behaviour is to look for addresses on the
3211 ;; command line; if there're none, it scans the headers.
3212 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
3214 ;; in general, ALL of qmail-inject's defaults are perfect for simply
3215 ;; reading a formatted (i. e., at least a To: or Resent-To header)
3216 ;; message from stdin.
3218 ;; qmail also has the advantage of not having been raped by
3219 ;; various vendors, so we don't have to allow for that, either --
3220 ;; compare this with message-send-mail-with-sendmail and weep
3221 ;; for sendmail's lost innocence.
3223 ;; all this is way cool coz it lets us keep the arguments entirely
3224 ;; free for -inject-arguments -- a big win for the user and for us
3225 ;; since we don't have to play that double-guessing game and the user
3226 ;; gets full control (no gestapo'ish -f's, for instance). --sj
3227 message-qmail-inject-args))
3228 ;; qmail-inject doesn't say anything on it's stdout/stderr,
3229 ;; we have to look at the retval instead
3231 (1 (error "qmail-inject reported permanent failure"))
3232 (111 (error "qmail-inject reported transient failure"))
3233 ;; should never happen
3234 (t (error "qmail-inject reported unknown failure"))))
3236 (defun message-send-mail-with-mh ()
3237 "Send the prepared message buffer with mh."
3238 (let ((mh-previous-window-config nil)
3239 (name (mh-new-draft-name)))
3240 (setq buffer-file-name name)
3241 ;; MH wants to generate these headers itself.
3242 (when message-mh-deletable-headers
3243 (let ((headers message-mh-deletable-headers))
3245 (goto-char (point-min))
3246 (and (re-search-forward
3247 (concat "^" (symbol-name (car headers)) ": *") nil t)
3248 (message-delete-line))
3250 (run-hooks 'message-send-mail-hook)
3251 ;; Pass it on to mh.
3254 (defun message-send-mail-with-smtp ()
3255 "Send off the prepared buffer with SMTP."
3256 (require 'smtp) ; XXX
3257 (let ((case-fold-search t)
3260 (message-narrow-to-headers)
3262 ;; XXX: Should be replaced by better one.
3263 (smtp-deduce-address-list (current-buffer)
3264 (point-min) (point-max)))
3265 ;; Remove BCC lines.
3266 (message-remove-header "bcc"))
3267 ;; replace the header delimiter with a blank line.
3268 (goto-char (point-min))
3270 (concat "^" (regexp-quote mail-header-separator) "\n"))
3271 (replace-match "\n")
3273 (run-hooks 'message-send-mail-hook)
3275 (static-if (fboundp 'smtp-send-buffer)
3276 (smtp-send-buffer user-mail-address recipients
3278 (let ((result (smtp-via-smtp user-mail-address recipients
3280 (unless (eq result t)
3281 (error "Sending failed; %s" result))))
3282 (error "Sending failed; no recipients"))))
3284 (defsubst message-maybe-split-and-send-news (method)
3285 "Split a message if necessary, and send it via news.
3286 Returns nil if sending succeeded, returns t if sending failed.
3287 This sub function is for exclusive use of `message-send-news'."
3288 (let ((mime-edit-split-ignored-field-regexp
3289 mime-edit-split-ignored-field-regexp)
3290 (case-fold-search t))
3291 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
3292 (setq mime-edit-split-ignored-field-regexp
3293 (concat (substring mime-edit-split-ignored-field-regexp
3294 0 (match-beginning 0))
3295 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
3296 "_so_don't_rape_it!"
3297 (substring mime-edit-split-ignored-field-regexp
3300 (catch 'message-sending-news-failure
3301 (mime-edit-maybe-split-and-send
3306 (std11-narrow-to-header mail-header-separator)
3307 (goto-char (point-min))
3308 (when (re-search-forward "^Message-ID:" nil t)
3309 (delete-region (match-end 0) (std11-field-end))
3310 (insert " " (message-make-message-id))))
3311 (unless (funcall message-send-news-function method)
3312 (throw 'message-sending-news-failure t)))))
3314 (not (funcall message-send-news-function method)))))
3316 (defun message-send-news (&optional arg)
3317 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
3318 (case-fold-search nil)
3319 (method (if (message-functionp message-post-method)
3320 (funcall message-post-method arg)
3321 message-post-method))
3322 (group-name-charset (gnus-group-name-charset method ""))
3323 (message-syntax-checks
3325 (cons '(existing-newsgroups . disabled)
3326 message-syntax-checks)
3327 message-syntax-checks))
3328 (message-this-is-news t)
3331 (message-narrow-to-headers)
3332 ;; Insert some headers.
3333 (message-generate-headers message-required-news-headers)
3334 ;; Let the user do all of the above.
3335 (run-hooks 'message-header-hook))
3336 (if group-name-charset
3337 (setq message-syntax-checks
3338 (cons '(valid-newsgroups . disabled)
3339 message-syntax-checks)))
3340 (message-cleanup-headers)
3341 (if (not (message-check-news-syntax))
3346 (buffer-disable-undo)
3348 (insert-buffer message-encoding-buffer)
3349 ;; Remove some headers.
3351 (message-narrow-to-headers)
3352 ;; We Semi-gnus people have no use for it.
3353 ;; ;; We (re)generate the Lines header.
3354 ;; (when (memq 'Lines message-required-mail-headers)
3355 ;; (message-generate-headers '(Lines)))
3356 ;; Remove some headers.
3357 (message-remove-header message-ignored-news-headers t))
3358 (goto-char (point-max))
3359 ;; require one newline at the end.
3360 (or (= (preceding-char) ?\n)
3362 (setq result (message-maybe-split-and-send-news method)))
3363 (kill-buffer tembuf))
3364 (set-buffer message-edit-buffer)
3367 (message "Couldn't send message via news: %s"
3368 (nnheader-get-report (car method)))
3370 (push 'news message-sent-message-via)))))
3372 ;; 1997-09-29 by MORIOKA Tomohiko
3373 (defun message-send-news-with-gnus (method)
3374 (let ((case-fold-search t))
3375 ;; Remove the delimiter.
3376 (goto-char (point-min))
3378 (concat "^" (regexp-quote mail-header-separator) "\n"))
3379 (replace-match "\n")
3381 (run-hooks 'message-send-news-hook)
3382 (gnus-open-server method)
3383 (gnus-request-post method)
3387 ;;; Header generation & syntax checking.
3390 (defun message-check-element (type)
3391 "Return non-nil if this TYPE is not to be checked."
3392 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
3394 (let ((able (assq type message-syntax-checks)))
3396 (eq (cdr able) 'disabled)))))
3398 (defun message-check-news-syntax ()
3399 "Check the syntax of the message."
3404 ;; We narrow to the headers and check them first.
3407 (message-narrow-to-headers)
3408 (message-check-news-header-syntax)))
3411 (set-buffer message-edit-buffer)
3412 (message-check-news-body-syntax))))))
3414 (defun message-check-news-header-syntax ()
3416 ;; Check Newsgroups header.
3417 (message-check 'newsgroups
3418 (let ((group (message-fetch-field "newsgroups")))
3421 (not (string-match "\\`[ \t]*\\'" group)))
3424 "The newsgroups field is empty or missing. Posting is denied.")))))
3425 ;; Check the Subject header.
3426 (message-check 'subject
3427 (let* ((case-fold-search t)
3428 (subject (message-fetch-field "subject")))
3431 (not (string-match "\\`[ \t]*\\'" subject)))
3434 "The subject field is empty or missing. Posting is denied.")))))
3435 ;; Check for commands in Subject.
3436 (message-check 'subject-cmsg
3437 (if (string-match "^cmsg " (message-fetch-field "subject"))
3439 "The control code \"cmsg\" is in the subject. Really post? ")
3441 ;; Check for multiple identical headers.
3442 (message-check 'multiple-headers
3444 (while (and (not found)
3445 (re-search-forward "^[^ \t:]+: " nil t))
3447 (or (re-search-forward
3452 (match-beginning 0) (- (match-end 0) 2))))
3457 (y-or-n-p (format "Multiple %s headers. Really post? " found))
3459 ;; Check for Version and Sendsys.
3460 (message-check 'sendsys
3461 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
3463 (format "The article contains a %s command. Really post? "
3464 (buffer-substring (match-beginning 0)
3465 (1- (match-end 0)))))
3467 ;; See whether we can shorten Followup-To.
3468 (message-check 'shorten-followup-to
3469 (let ((newsgroups (message-fetch-field "newsgroups"))
3470 (followup-to (message-fetch-field "followup-to"))
3472 (when (and newsgroups
3473 (string-match "," newsgroups)
3478 (setq to (completing-read
3479 "Followups to: (default all groups) "
3480 (mapcar (lambda (g) (list g))
3482 (message-tokenize-header
3484 (goto-char (point-min))
3485 (insert "Followup-To: " to "\n"))
3487 ;; Check "Shoot me".
3488 (message-check 'shoot
3489 (if (re-search-forward
3490 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
3491 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
3493 ;; Check for Approved.
3494 (message-check 'approved
3495 (if (re-search-forward "^Approved:" nil t)
3496 (y-or-n-p "The article contains an Approved header. Really post? ")
3498 ;; Check the Message-ID header.
3499 (message-check 'message-id
3500 (let* ((case-fold-search t)
3501 (message-id (message-fetch-field "message-id" t)))
3502 (or (not message-id)
3503 ;; Is there an @ in the ID?
3504 (and (string-match "@" message-id)
3505 ;; Is there a dot in the ID?
3506 (string-match "@[^.]*\\." message-id)
3507 ;; Does the ID end with a dot?
3508 (not (string-match "\\.>" message-id)))
3510 (format "The Message-ID looks strange: \"%s\". Really post? "
3512 ;; Check the Newsgroups & Followup-To headers.
3513 (message-check 'existing-newsgroups
3514 (let* ((case-fold-search t)
3515 (newsgroups (message-fetch-field "newsgroups"))
3516 (followup-to (message-fetch-field "followup-to"))
3517 (groups (message-tokenize-header
3519 (concat newsgroups "," followup-to)
3521 (hashtb (and (boundp 'gnus-active-hashtb)
3522 gnus-active-hashtb))
3524 (if (or (not hashtb)
3525 (not (boundp 'gnus-read-active-file))
3526 (not gnus-read-active-file)
3527 (eq gnus-read-active-file 'some))
3530 (when (and (not (boundp (intern (car groups) hashtb)))
3531 (not (equal (car groups) "poster")))
3532 (push (car groups) errors))
3538 "Really post to %s unknown group%s: %s? "
3539 (if (= (length errors) 1) "this" "these")
3540 (if (= (length errors) 1) "" "s")
3541 (mapconcat 'identity errors ", ")))))))
3542 ;; Check the Newsgroups & Followup-To headers for syntax errors.
3543 (message-check 'valid-newsgroups
3544 (let ((case-fold-search t)
3545 (headers '("Newsgroups" "Followup-To"))
3547 (while (and headers (not error))
3548 (when (setq header (mail-fetch-field (car headers)))
3552 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
3557 (not (string-match "\\.\\'\\|\\.\\." g)))
3558 (message-tokenize-header header ","))))
3565 (format "The %s header looks odd: \"%s\". Really post? "
3566 (car headers) header)))))
3567 (message-check 'repeated-newsgroups
3568 (let ((case-fold-search t)
3569 (headers '("Newsgroups" "Followup-To"))
3570 header error groups group)
3573 (when (setq header (mail-fetch-field (pop headers)))
3574 (setq groups (message-tokenize-header header ","))
3575 (while (setq group (pop groups))
3576 (when (member group groups)
3582 (format "Group %s is repeated in headers. Really post? " error)))))
3583 ;; Check the From header.
3584 (message-check 'from
3585 (let* ((case-fold-search t)
3586 (from (message-fetch-field "from"))
3590 (message "There is no From line. Posting is denied.")
3592 ((or (not (string-match
3594 (setq ad (nth 1 (mail-extract-address-components
3595 from))))) ;larsi@ifi
3596 (string-match "\\.\\." ad) ;larsi@ifi..uio
3597 (string-match "@\\." ad) ;larsi@.ifi.uio
3598 (string-match "\\.$" ad) ;larsi@ifi.uio.
3599 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
3600 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
3602 "Denied posting -- the From looks strange: \"%s\"." from)
3606 (defun message-check-news-body-syntax ()
3608 ;; Check for long lines.
3609 (message-check 'long-lines
3610 (goto-char (point-min))
3612 (concat "^" (regexp-quote mail-header-separator) "$"))
3616 (< (current-column) 80))
3617 (zerop (forward-line 1))))
3621 "You have lines longer than 79 characters. Really post? ")))
3622 ;; Check whether the article is empty.
3623 (message-check 'empty
3624 (goto-char (point-min))
3626 (concat "^" (regexp-quote mail-header-separator) "$"))
3629 (goto-char (point-max))
3630 (re-search-backward message-signature-separator nil t)
3632 (or (re-search-backward "[^ \n\t]" b t)
3633 (if (message-gnksa-enable-p 'empty-article)
3634 (y-or-n-p "Empty article. Really post? ")
3635 (message "Denied posting -- Empty article.")
3637 ;; Check for control characters.
3638 (message-check 'control-chars
3639 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
3641 "The article contains control characters. Really post? ")
3643 ;; Check 8bit characters.
3644 (message-check '8bit
3645 (message-check-8bit))
3646 ;; Check excessive size.
3647 (message-check 'size
3648 (if (> (buffer-size) 60000)
3650 (format "The article is %d octets long. Really post? "
3653 ;; Check whether any new text has been added.
3654 (message-check 'new-text
3656 (not message-checksum)
3657 (not (eq (message-checksum) message-checksum))
3658 (if (message-gnksa-enable-p 'quoted-text-only)
3660 "It looks like no new text has been added. Really post? ")
3661 (message "Denied posting -- no new text has been added.")
3663 ;; Check the length of the signature.
3664 (message-check 'signature
3665 (goto-char (point-max))
3666 (if (> (count-lines (point) (point-max)) 5)
3669 "Your .sig is %d lines; it should be max 4. Really post? "
3670 (1- (count-lines (point) (point-max)))))
3672 ;; Ensure that text follows last quoted portion.
3673 (message-check 'quoting-style
3674 (goto-char (point-max))
3675 (let ((no-problem t))
3676 (when (search-backward-regexp "^>[^\n]*\n" nil t)
3677 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
3680 (if (message-gnksa-enable-p 'quoted-text-only)
3681 (y-or-n-p "Your text should follow quoted text. Really post? ")
3683 (goto-char (point-min))
3685 (concat "^" (regexp-quote mail-header-separator) "$"))
3686 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
3687 (y-or-n-p "Your text should follow quoted text. Really post? ")
3688 (message "Denied posting -- only quoted text.")
3691 (defun message-check-mail-syntax ()
3692 "Check the syntax of the message."
3697 ;; We narrow to the headers and check them first.
3700 (message-narrow-to-headers)
3701 (message-check-mail-header-syntax)))
3704 (set-buffer message-edit-buffer)
3705 (message-check-mail-body-syntax))))))
3707 (defun message-check-mail-header-syntax ()
3710 (defun message-check-mail-body-syntax ()
3712 ;; Check 8bit characters.
3713 (message-check '8bit
3714 (message-check-8bit)
3717 (defun message-check-8bit ()
3718 "Check the article contains 8bit characters."
3720 (set-buffer message-encoding-buffer)
3721 (message-narrow-to-headers)
3722 (let* ((case-fold-search t)
3723 (field-value (message-fetch-field "content-transfer-encoding")))
3724 (if (and field-value
3725 (member (downcase field-value) message-8bit-encoding-list))
3728 (set-buffer (get-buffer-create " message syntax"))
3730 (goto-char (point-min))
3731 (set-buffer-multibyte nil)
3732 (insert-buffer message-encoding-buffer)
3733 (goto-char (point-min))
3734 (if (re-search-forward "[^\x00-\x7f]" nil t)
3736 "The article contains 8bit characters. Really post? ")
3739 (defun message-checksum ()
3740 "Return a \"checksum\" for the current buffer."
3743 (goto-char (point-min))
3745 (concat "^" (regexp-quote mail-header-separator) "$"))
3747 (when (not (looking-at "[ \t\n]"))
3748 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
3753 (defun message-do-fcc ()
3754 "Process Fcc headers in the current buffer."
3755 (let ((case-fold-search t)
3756 (coding-system-for-write 'raw-text)
3757 (output-coding-system 'raw-text)
3760 (set-buffer (get-buffer-create " *message temp*"))
3762 (insert-buffer-substring message-encoding-buffer)
3764 (message-narrow-to-headers)
3765 (while (setq file (message-fetch-field "fcc"))
3767 (message-remove-header "fcc" nil t)))
3768 (goto-char (point-min))
3769 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
3770 (replace-match "" t t)
3771 ;; Process FCC operations.
3773 (setq file (pop list))
3774 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
3775 ;; Pipe the article to the program in question.
3776 (call-process-region (point-min) (point-max) shell-file-name
3777 nil nil nil shell-command-switch
3778 (match-string 1 file))
3779 ;; Save the article.
3780 (setq file (expand-file-name file))
3781 (unless (file-exists-p (file-name-directory file))
3782 (make-directory (file-name-directory file) t))
3783 (if (and message-fcc-handler-function
3784 (not (eq message-fcc-handler-function 'rmail-output)))
3785 (funcall message-fcc-handler-function file)
3786 (if (and (file-readable-p file) (mail-file-babyl-p file))
3787 (rmail-output file 1 nil t)
3788 (let ((mail-use-rfc822 t))
3789 (rmail-output file 1 t t))))))
3790 (kill-buffer (current-buffer)))))
3792 (defun message-output (filename)
3793 "Append this article to Unix/babyl mail file FILENAME."
3794 (if (and (file-readable-p filename)
3795 (mail-file-babyl-p filename))
3796 (gnus-output-to-rmail filename t)
3797 (gnus-output-to-mail filename t)))
3799 (defun message-cleanup-headers ()
3800 "Do various automatic cleanups of the headers."
3801 ;; Remove empty lines in the header.
3803 (message-narrow-to-headers)
3804 ;; Remove blank lines.
3805 (while (re-search-forward "^[ \t]*\n" nil t)
3806 (replace-match "" t t))
3808 ;; Correct Newsgroups and Followup-To headers: Change sequence of
3809 ;; spaces to comma and eliminate spaces around commas. Eliminate
3810 ;; embedded line breaks.
3811 (goto-char (point-min))
3812 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
3816 (if (re-search-forward "^[^ \t]" nil t)
3820 (goto-char (point-min))
3821 (while (re-search-forward "\n[ \t]+" nil t)
3822 (replace-match " " t t)) ;No line breaks (too confusing)
3823 (goto-char (point-min))
3824 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
3825 (replace-match "," t t))
3826 (goto-char (point-min))
3827 ;; Remove trailing commas.
3828 (when (re-search-forward ",+$" nil t)
3829 (replace-match "" t t))))))
3831 (defun message-make-date (&optional now)
3832 "Make a valid data header.
3833 If NOW, use that time instead."
3834 (let* ((now (or now (current-time)))
3835 (zone (nth 8 (decode-time now)))
3839 (setq zone (- zone)))
3841 (format-time-string "%d" now)
3842 ;; The month name of the %b spec is locale-specific. Pfff.
3844 (capitalize (car (rassoc (nth 4 (decode-time now))
3845 parse-time-months))))
3846 (format-time-string "%Y %H:%M:%S " now)
3847 ;; We do all of this because XEmacs doesn't have the %z spec.
3848 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
3850 (defun message-make-followup-subject (subject)
3851 "Make a followup Subject."
3853 ((and (eq message-use-subject-re 'guess)
3854 (string-match message-subject-encoded-re-regexp subject))
3856 (message-use-subject-re
3857 (concat "Re: " (message-strip-subject-re subject)))
3860 (defun message-make-message-id ()
3861 "Make a unique Message-ID."
3862 (concat "<" (message-unique-id)
3863 (let ((psubject (save-excursion (message-fetch-field "subject")))
3865 (save-excursion (message-fetch-field "supersedes"))))
3867 (and message-reply-headers
3868 (mail-header-references message-reply-headers)
3869 (mail-header-subject message-reply-headers)
3872 (message-strip-subject-re
3873 (mail-header-subject message-reply-headers))
3874 (message-strip-subject-re psubject))))
3876 (string-match "_-_@" psupersedes)))
3878 "@" (message-make-fqdn) ">"))
3880 (defvar message-unique-id-char nil)
3882 ;; If you ever change this function, make sure the new version
3883 ;; cannot generate IDs that the old version could.
3884 ;; You might for example insert a "." somewhere (not next to another dot
3885 ;; or string boundary), or modify the "fsf" string.
3886 (defun message-unique-id ()
3887 ;; Don't use microseconds from (current-time), they may be unsupported.
3888 ;; Instead we use this randomly inited counter.
3889 (setq message-unique-id-char
3890 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
3891 ;; (current-time) returns 16-bit ints,
3892 ;; and 2^16*25 just fits into 4 digits i base 36.
3894 (let ((tm (current-time)))
3896 (if (memq system-type '(ms-dos emx vax-vms))
3897 (let ((user (downcase (user-login-name))))
3898 (while (string-match "[^a-z0-9_]" user)
3899 (aset user (match-beginning 0) ?_))
3901 (message-number-base36 (user-uid) -1))
3902 (message-number-base36 (+ (car tm)
3903 (lsh (% message-unique-id-char 25) 16)) 4)
3904 (message-number-base36 (+ (nth 1 tm)
3905 (lsh (/ message-unique-id-char 25) 16)) 4)
3906 ;; Append the newsreader name, because while the generated
3907 ;; ID is unique to this newsreader, other newsreaders might
3908 ;; otherwise generate the same ID via another algorithm.
3911 (defun message-number-base36 (num len)
3916 (concat (message-number-base36 (/ num 36) (1- len))
3917 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
3920 (defun message-make-organization ()
3921 "Make an Organization header."
3922 (let* ((organization
3923 (when message-user-organization
3924 (if (message-functionp message-user-organization)
3925 (funcall message-user-organization)
3926 message-user-organization))))
3928 (message-set-work-buffer)
3929 (cond ((stringp organization)
3930 (insert organization))
3931 ((and (eq t organization)
3932 message-user-organization-file
3933 (file-exists-p message-user-organization-file))
3934 (insert-file-contents message-user-organization-file)))
3935 (goto-char (point-min))
3936 (while (re-search-forward "[\t\n]+" nil t)
3937 (replace-match "" t t))
3938 (unless (zerop (buffer-size))
3941 (defun message-make-lines ()
3942 "Count the number of lines and return numeric string."
3947 (int-to-string (count-lines (point) (point-max))))))
3949 (defun message-make-in-reply-to ()
3950 "Return the In-Reply-To header for this message."
3951 (when message-reply-headers
3952 (let ((from (mail-header-from message-reply-headers))
3953 (date (mail-header-date message-reply-headers))
3954 (msg-id (mail-header-message-id message-reply-headers)))
3958 (let ((pair (std11-extract-address-components from)))
3960 (or (car pair) (cadr pair))
3962 (if (or (not date) (string= date ""))
3963 "(unknown date)" date)
3966 (defun message-make-distribution ()
3967 "Make a Distribution header."
3968 (let ((orig-distribution (message-fetch-reply-field "distribution")))
3969 (cond ((message-functionp message-distribution-function)
3970 (funcall message-distribution-function))
3971 (t orig-distribution))))
3973 (defun message-make-expires ()
3974 "Return an Expires header based on `message-expires'."
3975 (let ((current (current-time))
3976 (future (* 1.0 message-expires 60 60 24)))
3977 ;; Add the future to current.
3978 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
3979 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
3980 (message-make-date current)))
3982 (defun message-make-path ()
3984 (let ((login-name (user-login-name)))
3985 (cond ((null message-user-path)
3986 (concat (system-name) "!" login-name))
3987 ((stringp message-user-path)
3988 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
3989 (concat message-user-path "!" login-name))
3992 (defun message-make-from ()
3993 "Make a From header."
3994 (let* ((style message-from-style)
3995 (login (message-make-address))
3997 (or (and (boundp 'user-full-name)
4000 (when (string= fullname "&")
4001 (setq fullname (user-login-name)))
4003 (message-set-work-buffer)
4006 (equal fullname ""))
4008 ((or (eq style 'angles)
4009 (and (not (eq style 'parens))
4010 ;; Use angles if no quoting is needed, or if parens would
4011 ;; need quoting too.
4012 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
4013 (let ((tmp (concat fullname nil)))
4014 (while (string-match "([^()]*)" tmp)
4015 (aset tmp (match-beginning 0) ?-)
4016 (aset tmp (1- (match-end 0)) ?-))
4017 (string-match "[\\()]" tmp)))))
4019 (goto-char (point-min))
4020 ;; Look for a character that cannot appear unquoted
4021 ;; according to RFC 822.
4022 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
4023 ;; Quote fullname, escaping specials.
4024 (goto-char (point-min))
4026 (while (re-search-forward "[\"\\]" nil 1)
4027 (replace-match "\\\\\\&" t))
4029 (insert " <" login ">"))
4030 (t ; 'parens or default
4032 (let ((fullname-start (point)))
4034 (goto-char fullname-start)
4035 ;; RFC 822 says \ and nonmatching parentheses
4036 ;; must be escaped in comments.
4037 ;; Escape every instance of ()\ ...
4038 (while (re-search-forward "[()\\]" nil 1)
4039 (replace-match "\\\\\\&" t))
4040 ;; ... then undo escaping of matching parentheses,
4041 ;; including matching nested parentheses.
4042 (goto-char fullname-start)
4043 (while (re-search-forward
4044 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
4046 (replace-match "\\1(\\3)" t)
4047 (goto-char fullname-start)))
4051 (defun message-make-sender ()
4052 "Return the \"real\" user address.
4053 This function tries to ignore all user modifications, and
4054 give as trustworthy answer as possible."
4055 (concat (user-login-name) "@" (system-name)))
4057 (defun message-make-address ()
4058 "Make the address of the user."
4059 (or (message-user-mail-address)
4060 (concat (user-login-name) "@" (message-make-domain))))
4062 (defun message-user-mail-address ()
4063 "Return the pertinent part of `user-mail-address'."
4064 (when user-mail-address
4065 (if (string-match " " user-mail-address)
4066 (nth 1 (std11-extract-address-components user-mail-address))
4067 user-mail-address)))
4069 (defun message-make-fqdn ()
4070 "Return user's fully qualified domain name."
4071 (let ((system-name (system-name))
4072 (user-mail (message-user-mail-address)))
4074 ((string-match "[^.]\\.[^.]" system-name)
4075 ;; `system-name' returned the right result.
4077 ;; Try `mail-host-address'.
4078 ((and (boundp 'mail-host-address)
4079 (stringp mail-host-address)
4080 (string-match "\\." mail-host-address))
4082 ;; We try `user-mail-address' as a backup.
4084 (string-match "\\." user-mail)
4085 (string-match "@\\(.*\\)\\'" user-mail))
4086 (match-string 1 user-mail))
4087 ;; Default to this bogus thing.
4089 (concat system-name ".i-did-not-set--mail-host-address--so-shoot-me")))))
4091 (defun message-make-host-name ()
4092 "Return the name of the host."
4093 (let ((fqdn (message-make-fqdn)))
4094 (string-match "^[^.]+\\." fqdn)
4095 (substring fqdn 0 (1- (match-end 0)))))
4097 (defun message-make-domain ()
4098 "Return the domain name."
4099 (or mail-host-address
4100 (message-make-fqdn)))
4102 ;; Dummy to avoid byte-compile warning.
4103 (defvar mule-version)
4104 (defvar emacs-beta-version)
4105 (defvar xemacs-codename)
4106 (defvar gnus-inviolable-extended-version)
4108 (defun message-make-user-agent ()
4109 "Return user-agent info if the value `message-user-agent' is non-nil. If the
4110 \"User-Agent\" field has already exist, it's value will be added in the return
4112 (when message-user-agent
4114 (goto-char (point-min))
4115 (let ((case-fold-search t)
4116 user-agent start p end)
4117 (if (re-search-forward "^User-Agent:[\t ]*" nil t)
4119 (setq start (match-beginning 0)
4121 end (std11-field-end)
4122 user-agent (buffer-substring-no-properties p end))
4123 (delete-region start (1+ end))
4124 (concat message-user-agent " " user-agent))
4125 message-user-agent)))))
4127 (defun message-generate-headers (headers)
4128 "Prepare article HEADERS.
4129 Headers already prepared in the buffer are not modified."
4131 (message-narrow-to-headers)
4132 (let* ((Date (message-make-date))
4133 (Message-ID (message-make-message-id))
4134 (Organization (message-make-organization))
4135 (From (message-make-from))
4136 (Path (message-make-path))
4139 (In-Reply-To (message-make-in-reply-to))
4141 (Distribution (message-make-distribution))
4142 (Lines (message-make-lines))
4143 (User-Agent (message-make-user-agent))
4144 (Expires (message-make-expires))
4145 (case-fold-search t)
4147 ;; First we remove any old generated headers.
4148 (let ((headers message-deletable-headers))
4149 (unless (buffer-modified-p)
4150 (setq headers (delq 'Message-ID (copy-sequence headers))))
4152 (goto-char (point-min))
4153 (and (re-search-forward
4154 (concat "^" (symbol-name (car headers)) ": *") nil t)
4155 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
4156 (message-delete-line))
4158 ;; Go through all the required headers and see if they are in the
4159 ;; articles already. If they are not, or are empty, they are
4160 ;; inserted automatically - except for Subject, Newsgroups and
4163 (goto-char (point-min))
4164 (setq elem (pop headers))
4166 (if (eq (car elem) 'optional)
4167 (setq header (cdr elem))
4168 (setq header (car elem)))
4170 (when (or (not (re-search-forward
4174 (if (stringp header)
4176 (symbol-name header))))
4180 ;; The header was found. We insert a space after the
4181 ;; colon, if there is none.
4182 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
4183 ;; Find out whether the header is empty...
4184 (looking-at "[ \t]*\n[^ \t]")))
4185 ;; So we find out what value we should insert.
4188 ((and (consp elem) (eq (car elem) 'optional))
4189 ;; This is an optional header. If the cdr of this
4190 ;; is something that is nil, then we do not insert
4192 (setq header (cdr elem))
4193 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
4194 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
4196 ;; The element is a cons. Either the cdr is a
4197 ;; string to be inserted verbatim, or it is a
4198 ;; function, and we insert the value returned from
4200 (or (and (stringp (cdr elem)) (cdr elem))
4201 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
4202 ((and (boundp header) (symbol-value header))
4203 ;; The element is a symbol. We insert the value
4204 ;; of this symbol, if any.
4205 (symbol-value header))
4206 ((not (message-check-element header))
4207 ;; We couldn't generate a value for this header,
4208 ;; so we just ask the user.
4209 (read-from-minibuffer
4210 (format "Empty header for %s; enter value: " header)))))
4211 ;; Finally insert the header.
4213 (not (equal value "")))
4217 ;; This header didn't exist, so we insert it.
4218 (goto-char (point-max))
4219 (insert (if (stringp header) header (symbol-name header))
4224 ;; The value of this header was empty, so we clear
4225 ;; totally and insert the new value.
4226 (delete-region (point) (gnus-point-at-eol))
4230 ;; Add the deletable property to the headers that require it.
4231 (and (memq header message-deletable-headers)
4232 (progn (beginning-of-line) (looking-at "[^:]+: "))
4233 (add-text-properties
4234 (point) (match-end 0)
4235 '(message-deletable t face italic) (current-buffer)))))))
4236 ;; Insert new Sender if the From is strange.
4237 (let ((from (message-fetch-field "from"))
4238 (sender (message-fetch-field "sender"))
4239 (secure-sender (message-make-sender)))
4241 (not (message-check-element 'sender))
4244 (cadr (std11-extract-address-components from)))
4245 (downcase secure-sender)))
4250 (cadr (std11-extract-address-components sender)))
4251 (downcase secure-sender)))))
4252 (goto-char (point-min))
4253 ;; Rename any old Sender headers to Original-Sender.
4254 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
4256 (insert "Original-")
4257 (beginning-of-line))
4258 (when (or (message-news-p)
4259 (string-match "@.+\\.." secure-sender))
4260 (insert "Sender: " secure-sender "\n")))))))
4262 (defun message-insert-courtesy-copy ()
4263 "Insert a courtesy message in mail copies of combined messages."
4267 (message-narrow-to-headers)
4268 (when (setq newsgroups (message-fetch-field "newsgroups"))
4269 (goto-char (point-max))
4270 (insert "Posted-To: " newsgroups "\n")))
4272 (when message-courtesy-message
4274 ((string-match "%s" message-courtesy-message)
4275 (insert (format message-courtesy-message newsgroups)))
4277 (insert message-courtesy-message)))))))
4280 ;;; Setting up a message buffer
4283 (defun message-fill-address (header value)
4285 (narrow-to-region (point) (point))
4286 (insert (capitalize (symbol-name header))
4288 (if (consp value) (car value) value)
4290 (narrow-to-region (point-min) (1- (point-max)))
4292 (goto-char (point-min))
4294 (skip-chars-forward "^,\"" (point-max))
4295 (if (or (eq (char-after) ?,)
4298 (if (and (> (current-column) 78)
4302 (looking-at "[ \t]*")
4303 (replace-match "\n " t t)))
4304 (setq last (1+ (point))))
4305 (setq quoted (not quoted)))
4308 (goto-char (point-max))
4312 (defun message-fill-references (header value)
4313 (insert (capitalize (symbol-name header))
4315 (std11-fill-msg-id-list-string
4316 (if (consp value) (car value) value))
4319 (defun message-fill-header (header value)
4320 (let ((begin (point))
4323 (insert (capitalize (symbol-name header))
4325 (if (consp value) (car value) value)
4328 (narrow-to-region begin (point))
4329 (fill-region-as-paragraph begin (point))
4330 ;; Tapdance around looong Message-IDs.
4332 (when (looking-at "[ \t]*$")
4333 (message-delete-line))
4335 (re-search-forward ":" nil t)
4336 (when (looking-at "\n[ \t]+")
4337 (replace-match " " t t))
4338 (goto-char (point-max)))))
4340 (defun message-shorten-1 (list cut surplus)
4341 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
4342 (setcdr (nthcdr (- cut 2) list)
4343 (nthcdr (+ (- cut 2) surplus 1) list)))
4345 (defun message-shorten-references (header references)
4346 "Trim REFERENCES to be less than 31 Message-ID long, and fold them.
4347 If folding is disallowed, also check that the REFERENCES are less
4348 than 988 characters long, and if they are not, trim them until they are."
4355 (goto-char (point-min))
4356 ;; Cons a list of valid references.
4357 (while (re-search-forward "<[^>]+>" nil t)
4358 (push (match-string 0) refs))
4359 (setq refs (nreverse refs)
4360 count (length refs)))
4362 ;; If the list has more than MAXCOUNT elements, trim it by
4363 ;; removing the CUTth element and the required number of
4364 ;; elements that follow.
4365 (when (> count maxcount)
4366 (let ((surplus (- count maxcount)))
4367 (message-shorten-1 refs cut surplus)
4368 (decf count surplus)))
4370 ;; If folding is disallowed, make sure the total length (including
4371 ;; the spaces between) will be less than MAXSIZE characters.
4373 ;; Only disallow folding for News messages. At this point the headers
4374 ;; have not been generated, thus we use message-this-is-news directly.
4375 (when (and message-this-is-news message-cater-to-broken-inn)
4377 (totalsize (+ (apply #'+ (mapcar #'length refs))
4380 (ptr (nthcdr (1- cut) refs)))
4381 ;; Decide how many elements to cut off...
4382 (while (> totalsize maxsize)
4383 (decf totalsize (1+ (length (car ptr))))
4385 (setq ptr (cdr ptr)))
4388 (message-shorten-1 refs cut surplus))))
4390 ;; Finally, collect the references back into a string and insert
4391 ;; it into the buffer.
4392 (let ((refstring (mapconcat #'identity refs " ")))
4393 (if (and message-this-is-news message-cater-to-broken-inn)
4394 (insert (capitalize (symbol-name header)) ": "
4396 (message-fill-header header refstring)))))
4398 (defun message-position-point ()
4399 "Move point to where the user probably wants to find it."
4400 (message-narrow-to-headers)
4402 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
4403 (search-backward ":" )
4406 (if (eq (char-after) ? )
4410 (goto-char (point-max))
4413 (unless (looking-at "$")
4417 (defun message-buffer-name (type &optional to group)
4418 "Return a new (unique) buffer name based on TYPE and TO."
4420 ;; Generate a new buffer name The Message Way.
4421 ((eq message-generate-new-buffers 'unique)
4422 (generate-new-buffer-name
4426 (or (car (std11-extract-address-components to))
4429 (if (and group (not (string= group ""))) (concat " on " group) "")
4431 ;; Check whether `message-generate-new-buffers' is a function,
4432 ;; and if so, call it.
4433 ((message-functionp message-generate-new-buffers)
4434 (funcall message-generate-new-buffers type to group))
4435 ((eq message-generate-new-buffers 'unsent)
4436 (generate-new-buffer-name
4437 (concat "*unsent " type
4440 (or (car (mail-extract-address-components to))
4443 (if (and group (not (string= group ""))) (concat " on " group) "")
4445 ;; Use standard name.
4447 (format "*%s message*" type))))
4449 (defmacro message-pop-to-buffer-1 (buffer)
4451 (let (special-display-buffer-names
4452 special-display-regexps
4453 same-window-buffer-names
4454 same-window-regexps)
4455 (pop-to-buffer ,buffer))
4456 (pop-to-buffer ,buffer)))
4458 (defun message-pop-to-buffer (name)
4459 "Pop to buffer NAME, and warn if it already exists and is modified."
4460 (let ((buffer (get-buffer name))
4461 (pop-up-frames (and (or (static-if (featurep 'xemacs)
4462 (device-on-window-system-p)
4464 (>= emacs-major-version 20))
4465 message-use-multi-frames)))
4467 (buffer-name buffer))
4469 (message-pop-to-buffer-1 buffer)
4470 (when (and (buffer-modified-p)
4472 "Message already being composed; erase? ")))
4473 (error "Message being composed")))
4474 (message-pop-to-buffer-1 name))
4478 (set (make-local-variable 'message-original-frame) (selected-frame)))))
4480 (defun message-do-send-housekeeping ()
4481 "Kill old message buffers."
4482 ;; We might have sent this buffer already. Delete it from the
4484 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
4485 (while (and message-max-buffers
4487 (>= (length message-buffer-list) message-max-buffers))
4488 ;; Kill the oldest buffer -- unless it has been changed.
4489 (let ((buffer (pop message-buffer-list)))
4490 (when (and (buffer-name buffer)
4491 (not (buffer-modified-p buffer)))
4492 (kill-buffer buffer))))
4493 ;; Rename the buffer.
4494 (if message-send-rename-function
4495 (funcall message-send-rename-function)
4496 (when (string-match "\\`\\*\\(unsent \\)?" (buffer-name))
4498 (concat "*sent " (substring (buffer-name) (match-end 0))) t)))
4499 ;; Push the current buffer onto the list.
4500 (when message-max-buffers
4501 (setq message-buffer-list
4502 (nconc message-buffer-list (list (current-buffer))))))
4504 (defun message-mail-user-agent ()
4506 ((not message-mail-user-agent) nil)
4507 ((eq message-mail-user-agent t) mail-user-agent)
4508 (t message-mail-user-agent))))
4509 (if (memq mua '(message-user-agent gnus-user-agent))
4513 (defun message-setup (headers &optional replybuffer actions switch-function)
4514 (let ((mua (message-mail-user-agent))
4515 subject to field yank-action)
4516 (if (not (and message-this-is-mail mua))
4517 (message-setup-1 headers replybuffer actions)
4519 (setq yank-action (list 'insert-buffer replybuffer)))
4520 (setq headers (copy-sequence headers))
4521 (setq field (assq 'Subject headers))
4523 (setq subject (cdr field))
4524 (setq headers (delq field headers)))
4525 (setq field (assq 'To headers))
4527 (setq to (cdr field))
4528 (setq headers (delq field headers)))
4529 (let ((mail-user-agent mua))
4530 (compose-mail to subject
4531 (mapcar (lambda (item)
4533 (format "%s" (car item))
4536 nil switch-function yank-action actions)))))
4538 ;;;(defvar mc-modes-alist)
4539 (defun message-setup-1 (headers &optional replybuffer actions)
4540 ;;; (when (and (boundp 'mc-modes-alist)
4541 ;;; (not (assq 'message-mode mc-modes-alist)))
4542 ;;; (push '(message-mode (encrypt . mc-encrypt-message)
4543 ;;; (sign . mc-sign-message))
4544 ;;; mc-modes-alist))
4546 (setq message-send-actions actions))
4547 (setq message-reply-buffer
4548 (or (message-get-parameter 'reply-buffer)
4550 (goto-char (point-min))
4551 ;; Insert all the headers.
4554 (alist message-header-format-alist))
4556 (unless (assq (caar h) message-header-format-alist)
4557 (push (list (caar h)) alist))
4561 (delete-region (point) (progn (forward-line -1) (point)))
4562 (when message-default-headers
4563 (insert message-default-headers)
4564 (or (bolp) (insert ?\n)))
4568 (insert mail-header-separator "\n")
4572 (when (message-news-p)
4573 (when message-default-news-headers
4574 (insert message-default-news-headers)
4575 (or (bolp) (insert ?\n)))
4576 (when message-generate-headers-first
4577 (message-generate-headers
4580 (copy-sequence message-required-news-headers))))))
4581 (when (message-mail-p)
4582 (when message-default-mail-headers
4583 (insert message-default-mail-headers)
4584 (or (bolp) (insert ?\n)))
4585 (when message-generate-headers-first
4586 (message-generate-headers
4589 (copy-sequence message-required-mail-headers))))))
4590 (run-hooks 'message-signature-setup-hook)
4591 (message-insert-signature)
4593 (message-narrow-to-headers)
4594 (if message-alternative-emails
4595 (message-use-alternative-email-as-from))
4596 (run-hooks 'message-header-setup-hook))
4597 (set-buffer-modified-p nil)
4598 (setq buffer-undo-list nil)
4599 (run-hooks 'message-setup-hook)
4600 (message-position-point)
4603 (defun message-set-auto-save-file-name ()
4604 "Associate the message buffer with a file in the drafts directory."
4605 (when message-auto-save-directory
4606 (unless (file-directory-p
4607 (directory-file-name message-auto-save-directory))
4608 (gnus-make-directory message-auto-save-directory))
4610 (setq message-draft-article
4611 (nndraft-request-associate-buffer "drafts"))
4612 (setq buffer-file-name (expand-file-name "*message*"
4613 message-auto-save-directory))
4614 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
4615 (clear-visited-file-modtime)
4616 (static-if (boundp 'MULE)
4617 (set-file-coding-system message-draft-coding-system)
4618 (setq buffer-file-coding-system message-draft-coding-system))))
4620 (defun message-disassociate-draft ()
4621 "Disassociate the message buffer from the drafts directory."
4622 (when message-draft-article
4623 (nndraft-request-expire-articles
4624 (list message-draft-article) "drafts" nil t)))
4626 (defun message-insert-headers ()
4627 "Generate the headers for the article."
4631 (message-narrow-to-headers)
4632 (when (message-news-p)
4633 (message-generate-headers
4636 (copy-sequence message-required-news-headers)))))
4637 (when (message-mail-p)
4638 (message-generate-headers
4641 (copy-sequence message-required-mail-headers))))))))
4646 ;;; Commands for interfacing with message
4650 (defun message-mail (&optional to subject
4651 other-headers continue switch-function
4652 yank-action send-actions)
4653 "Start editing a mail message to be sent.
4654 OTHER-HEADERS is an alist of header/value pairs."
4656 (let ((message-this-is-mail t) replybuffer)
4657 (unless (message-mail-user-agent)
4658 (message-pop-to-buffer (message-buffer-name "mail" to)))
4659 ;; FIXME: message-mail should do something if YANK-ACTION is not
4661 (and (consp yank-action) (eq (car yank-action) 'insert-buffer)
4662 (setq replybuffer (nth 1 yank-action)))
4665 `((To . ,(or to "")) (Subject . ,(or subject "")))
4666 (when other-headers other-headers))
4668 ;; FIXME: Should return nil if failure.
4672 (defun message-news (&optional newsgroups subject)
4673 "Start editing a news article to be sent."
4675 (let ((message-this-is-news t))
4676 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))
4677 (message-setup `((Newsgroups . ,(or newsgroups ""))
4678 (Subject . ,(or subject ""))))))
4680 (defun message-get-reply-headers (wide &optional to-address)
4681 (let (follow-to mct never-mct from to cc reply-to mrt mft)
4682 ;; Find all relevant headers we need.
4683 (setq from (message-fetch-field "from")
4684 to (message-fetch-field "to")
4685 cc (message-fetch-field "cc")
4686 mct (when message-use-mail-copies-to
4687 (message-fetch-field "mail-copies-to"))
4688 reply-to (message-fetch-field "reply-to")
4689 mrt (when message-use-mail-reply-to
4690 (message-fetch-field "mail-reply-to"))
4691 mft (when (and (not (or to-address mrt reply-to))
4692 message-use-mail-followup-to)
4693 (message-fetch-field "mail-followup-to")))
4695 ;; Handle special values of Mail-Copies-To.
4698 ((and (or (equal (downcase mct) "never")
4699 (equal (downcase mct) "nobody")))
4700 (when (or (not (eq message-use-mail-copies-to 'ask))
4702 (concat "Obey Mail-Copies-To: never? ") t "\
4703 You should normally obey the Mail-Copies-To: header.
4705 `Mail-Copies-To: " mct "'
4706 directs you not to send your response to the author."))
4709 ((and (or (equal (downcase mct) "always")
4710 (equal (downcase mct) "poster")))
4711 (if (or (not (eq message-use-mail-copies-to 'ask))
4713 (concat "Obey Mail-Copies-To: always? ") t "\
4714 You should normally obey the Mail-Copies-To: header.
4716 `Mail-Copies-To: " mct "'
4717 sends a copy of your response to the author."))
4718 (setq mct (or mrt reply-to from))
4720 ((and (eq message-use-mail-copies-to 'ask)
4721 (not (message-y-or-n-p
4722 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
4723 You should normally obey the Mail-Copies-To: header.
4725 `Mail-Copies-To: " mct "'
4726 sends a copy of your response to " (if (string-match "," mct)
4727 "the specified addresses"
4728 "that address") ".")))
4731 ;; Handle Mail-Followup-To.
4733 (eq message-use-mail-followup-to 'ask)
4734 (not (message-y-or-n-p
4735 (concat "Obey Mail-Followup-To: " mft "? ") t "\
4736 You should normally obey the Mail-Followup-To: header.
4738 `Mail-Followup-To: " mft "'
4739 directs your response to " (if (string-match "," mft)
4740 "the specified addresses"
4741 "that address only") ".
4743 A typical situation where Mail-Followup-To is used is when the author thinks
4744 that further discussion should take place only in "
4745 (if (string-match "," mft)
4746 "the specified mailing lists"
4747 "that mailing list") ".")))
4753 (setq follow-to (list (cons 'To
4754 (or to-address mrt reply-to mft from))))
4755 (when (and wide (or mft mct)
4756 (not (member (cons 'To (or mft mct)) follow-to)))
4757 (push (cons 'Cc mct) follow-to)))
4760 (message-set-work-buffer)
4762 message-use-followup-to
4763 (or (not (eq message-use-followup-to 'ask))
4764 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
4765 You should normally obey the Mail-Followup-To: header. In this
4766 article, it has the value of
4770 which directs your response to " (if (string-match "," mft)
4771 "the specified addresses"
4772 "that address only") ".
4774 If a message is posted to several mailing lists, Mail-Followup-To is
4775 often used to direct the following discussion to one list only,
4776 because discussions that are spread over several lists tend to be
4777 fragmented and very difficult to follow.
4779 Also, some source/announcement lists are not indented for discussion;
4780 responses here are directed to other addresses.")))
4783 (insert (or mrt reply-to from "")))
4784 (insert (if to (concat (if (bolp) "" ", ") to) ""))
4785 (insert (if mct (concat (if (bolp) "" ", ") mct) ""))
4786 (insert (if cc (concat (if (bolp) "" ", ") cc) "")))
4787 (goto-char (point-min))
4788 (while (re-search-forward "[ \t]+" nil t)
4789 (replace-match " " t t))
4790 ;; Remove addresses that match `rmail-dont-reply-to-names'.
4791 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
4792 (insert (prog1 (rmail-dont-reply-to (buffer-string))
4794 (goto-char (point-min))
4795 ;; Perhaps "Mail-Copies-To: never" removed the only address?
4797 (insert (or mrt reply-to from "")))
4801 (cons (mail-strip-quoted-names addr) addr))
4802 (message-tokenize-header (buffer-string))))
4805 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
4806 (setq follow-to (list (cons 'To (cdr (pop ccalist)))))
4808 (let ((ccs (cons 'Cc (mapconcat
4809 (lambda (addr) (cdr addr)) ccalist ", "))))
4810 (when (string-match "^ +" (cdr ccs))
4811 (setcdr ccs (substring (cdr ccs) (match-end 0))))
4812 (push ccs follow-to)))))
4817 (defun message-reply (&optional to-address wide)
4818 "Start editing a reply to the article in the current buffer."
4820 (require 'gnus-sum) ; for gnus-list-identifiers
4821 (let ((cur (current-buffer))
4823 references message-id follow-to
4824 (inhibit-point-motion-hooks t)
4825 (message-this-is-mail t)
4826 gnus-warning in-reply-to)
4828 (message-narrow-to-head-1)
4829 ;; Allow customizations to have their say.
4831 ;; This is a regular reply.
4832 (when (message-functionp message-reply-to-function)
4834 (setq follow-to (funcall message-reply-to-function))))
4835 ;; This is a followup.
4836 (when (message-functionp message-wide-reply-to-function)
4839 (funcall message-wide-reply-to-function)))))
4840 (setq message-id (message-fetch-field "message-id" t)
4841 references (message-fetch-field "references")
4842 date (message-fetch-field "date")
4843 from (message-fetch-field "from")
4844 subject (or (message-fetch-field "subject") "none"))
4845 (when gnus-list-identifiers
4846 (setq subject (message-strip-list-identifiers subject)))
4847 (setq subject (message-make-followup-subject subject))
4849 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
4850 (string-match "<[^>]+>" gnus-warning))
4851 (setq message-id (match-string 0 gnus-warning)))
4854 (setq follow-to (message-get-reply-headers wide to-address)))
4856 ;; Get the references from "In-Reply-To" field if there were
4857 ;; no references and "In-Reply-To" field looks promising.
4859 (when (and (setq in-reply-to (message-fetch-field "in-reply-to"))
4860 (string-match "<[^>]+>" in-reply-to))
4861 (setq references (match-string 0 in-reply-to)))))
4863 (unless (message-mail-user-agent)
4864 (message-pop-to-buffer
4865 (message-buffer-name
4866 (if wide "wide reply" "reply") from
4867 (if wide to-address nil))))
4869 (setq message-reply-headers
4870 (make-full-mail-header-from-decoded-header
4871 0 subject from date message-id references 0 0 ""))
4874 `((Subject . ,subject)
4876 ,@(if (or references message-id)
4877 `((References . ,(concat (or references "") (and references " ")
4878 (or message-id ""))))
4883 (defun message-wide-reply (&optional to-address)
4884 "Make a \"wide\" reply to the message in the current buffer."
4886 (message-reply to-address t))
4889 (defun message-followup (&optional to-newsgroups)
4890 "Follow up to the message in the current buffer.
4891 If TO-NEWSGROUPS, use that as the new Newsgroups line."
4893 (require 'gnus-sum) ; for gnus-list-identifiers
4894 (let ((cur (current-buffer))
4895 from subject date reply-to mrt mct mft
4896 references message-id follow-to
4897 (inhibit-point-motion-hooks t)
4898 (message-this-is-news t)
4899 followup-to distribution newsgroups gnus-warning posted-to)
4901 (message-narrow-to-head)
4902 (when (message-functionp message-followup-to-function)
4904 (funcall message-followup-to-function)))
4905 (setq from (message-fetch-field "from")
4906 date (message-fetch-field "date")
4907 subject (or (message-fetch-field "subject") "none")
4908 references (message-fetch-field "references")
4909 message-id (message-fetch-field "message-id" t)
4910 followup-to (message-fetch-field "followup-to")
4911 newsgroups (message-fetch-field "newsgroups")
4912 posted-to (message-fetch-field "posted-to")
4913 reply-to (message-fetch-field "reply-to")
4914 mrt (when message-use-mail-reply-to
4915 (message-fetch-field "mail-reply-to"))
4916 distribution (message-fetch-field "distribution")
4917 mct (when message-use-mail-copies-to
4918 (message-fetch-field "mail-copies-to"))
4919 mft (when message-use-mail-followup-to
4920 (message-fetch-field "mail-followup-to")))
4921 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
4922 (string-match "<[^>]+>" gnus-warning))
4923 (setq message-id (match-string 0 gnus-warning)))
4924 ;; Remove bogus distribution.
4925 (when (and (stringp distribution)
4926 (let ((case-fold-search t))
4927 (string-match "world" distribution)))
4928 (setq distribution nil))
4929 (if gnus-list-identifiers
4930 (setq subject (message-strip-list-identifiers subject)))
4931 (setq subject (message-make-followup-subject subject))
4934 ;; Handle special values of Mail-Copies-To.
4937 ((and (or (equal (downcase mct) "never")
4938 (equal (downcase mct) "nobody")))
4940 ((and (or (equal (downcase mct) "always")
4941 (equal (downcase mct) "poster")))
4942 (if (or (not (eq message-use-mail-copies-to 'ask))
4944 (concat "Obey Mail-Copies-To: always? ") t "\
4945 You should normally obey the Mail-Copies-To: header.
4947 `Mail-Copies-To: " mct "'
4948 sends a copy of your response to the author."))
4949 (setq mct (or mrt reply-to from))
4951 ((and (eq message-use-mail-copies-to 'ask)
4954 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
4955 You should normally obey the Mail-Copies-To: header.
4957 `Mail-Copies-To: " mct "'
4958 sends a copy of your response to " (if (string-match "," mct)
4959 "the specified addresses"
4960 "that address") ".")))
4965 (to-newsgroups (setq follow-to (list (cons 'Newsgroups to-newsgroups))))
4966 ;; Handle Followup-To.
4969 ((equal (downcase followup-to) "poster")
4970 (if (or (and followup-to (eq message-use-followup-to 'use))
4971 (message-y-or-n-p "Obey Followup-To: poster? " t "\
4972 You should normally obey the Followup-To: header.
4974 `Followup-To: poster'
4975 sends your response via e-mail instead of news.
4977 A typical situation where `Followup-To: poster' is used is when the author
4978 does not read the newsgroup, so he wouldn't see any replies sent to it."))
4979 (setq message-this-is-news nil
4981 follow-to (list (cons 'To (or mrt reply-to from ""))))
4982 (setq follow-to (list (cons 'Newsgroups newsgroups)))))
4984 (if (or (equal followup-to newsgroups)
4985 (not (and followup-to (eq message-use-followup-to 'ask)))
4987 (concat "Obey Followup-To: " followup-to "? ") t "\
4988 You should normally obey the Followup-To: header.
4990 `Followup-To: " followup-to "'
4991 directs your response to " (if (string-match "," followup-to)
4992 "the specified newsgroups"
4993 "that newsgroup only") ".
4995 If a message is posted to several newsgroups, Followup-To is often
4996 used to direct the following discussion to one newsgroup only,
4997 because discussions that are spread over several newsgroup tend to
4998 be fragmented and very difficult to follow.
5000 Also, some source/announcement newsgroups are not indented for discussion;
5001 responses here are directed to other newsgroups."))
5002 (setq follow-to (list (cons 'Newsgroups followup-to)))
5003 (setq follow-to (list (cons 'Newsgroups newsgroups)))))))
5004 ;; Handle Mail-Followup-To, followup via e-mail.
5006 (or (not (eq message-use-mail-followup-to 'ask))
5008 (concat "Obey Mail-Followup-To: " mft "? ") t "\
5009 You should normally obey the Mail-Followup-To: header.
5011 `Mail-Followup-To: " mft "'
5012 directs your response to " (if (string-match "," mft)
5013 "the specified addresses"
5014 "that address only") " instead of news.
5016 A typical situation where Mail-Followup-To is used is when the author thinks
5017 that further discussion should take place only in "
5018 (if (string-match "," mft)
5019 "the specified mailing lists"
5020 "that mailing list") ".")))
5021 (setq message-this-is-news nil
5023 follow-to (list (cons 'To mft))))
5024 (posted-to (setq follow-to (list (cons 'Newsgroups posted-to))))
5026 (setq follow-to (list (cons 'Newsgroups newsgroups))))))
5028 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
5031 `((Subject . ,subject)
5033 ,@(and mct (list (cons 'Cc mct)))
5034 ,@(and distribution (list (cons 'Distribution distribution)))
5035 ,@(if (or references message-id)
5036 `((References . ,(concat (or references "") (and references " ")
5037 (or message-id ""))))))
5040 (setq message-reply-headers
5041 (make-full-mail-header-from-decoded-header
5042 0 subject from date message-id references 0 0 ""))))
5045 (defun message-cancel-news (&optional arg)
5046 "Cancel an article you posted.
5047 If ARG, allow editing of the cancellation message."
5049 (unless (message-news-p)
5050 (error "This is not a news article; canceling is impossible"))
5051 (when (yes-or-no-p "Do you really want to cancel this article? ")
5052 (let (from newsgroups message-id distribution buf sender)
5054 ;; Get header info from original article.
5056 (message-narrow-to-head-1)
5057 (setq from (message-fetch-field "from")
5058 sender (message-fetch-field "sender")
5059 newsgroups (message-fetch-field "newsgroups")
5060 message-id (message-fetch-field "message-id" t)
5061 distribution (message-fetch-field "distribution")))
5062 ;; Make sure that this article was written by the user.
5063 (unless (or (and sender
5066 (downcase (message-make-sender))))
5068 (downcase (cadr (std11-extract-address-components
5070 (downcase (cadr (std11-extract-address-components
5071 (message-make-from))))))
5072 (error "This article is not yours"))
5073 ;; Make control message.
5076 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
5078 (insert "Newsgroups: " newsgroups "\n"
5080 "Subject: cmsg cancel " message-id "\n"
5081 "Control: cancel " message-id "\n"
5083 (concat "Distribution: " distribution "\n")
5085 mail-header-separator "\n"
5086 message-cancel-message)
5087 (run-hooks 'message-cancel-hook)
5088 (message "Canceling your article...")
5090 (if (let ((message-syntax-checks
5091 'dont-check-for-anything-just-trust-me)
5092 (message-encoding-buffer (current-buffer))
5093 (message-edit-buffer (current-buffer)))
5094 (message-send-news))
5095 (message "Canceling your article...done"))
5096 (kill-buffer buf))))))
5098 (defun message-supersede-setup-for-mime-edit ()
5099 (set (make-local-variable 'message-setup-hook) nil)
5103 (defun message-supersede ()
5104 "Start composing a message to supersede the current message.
5105 This is done simply by taking the old article and adding a Supersedes
5106 header line with the old Message-ID."
5108 (let ((cur (current-buffer))
5109 (sender (message-fetch-field "sender"))
5110 (from (message-fetch-field "from")))
5111 ;; Check whether the user owns the article that is to be superseded.
5112 (unless (or (and sender
5115 (downcase (message-make-sender))))
5117 (downcase (cadr (std11-extract-address-components from)))
5118 (downcase (cadr (std11-extract-address-components
5119 (message-make-from))))))
5120 (error "This article is not yours"))
5121 ;; Get a normal message buffer.
5122 (message-pop-to-buffer (message-buffer-name "supersede"))
5123 (insert-buffer-substring cur)
5124 (message-narrow-to-head-1)
5125 ;; Remove unwanted headers.
5126 (when message-ignored-supersedes-headers
5127 (message-remove-header message-ignored-supersedes-headers t))
5128 (goto-char (point-min))
5129 (if (not (re-search-forward "^Message-ID: " nil t))
5130 (error "No Message-ID in this article")
5131 (replace-match "Supersedes: " t t))
5132 (goto-char (point-max))
5133 (insert mail-header-separator)
5135 (when message-supersede-setup-function
5136 (funcall message-supersede-setup-function))
5137 (run-hooks 'message-supersede-setup-hook)
5138 (goto-char (point-min))
5139 (search-forward (concat "\n" mail-header-separator "\n") nil t)))
5142 (defun message-recover ()
5143 "Reread contents of current buffer from its last auto-save file."
5145 (let ((file-name (make-auto-save-file-name)))
5146 (cond ((save-window-excursion
5147 (if (not (eq system-type 'vax-vms))
5148 (with-output-to-temp-buffer "*Directory*"
5149 (with-current-buffer standard-output
5150 (fundamental-mode)) ; for Emacs 20.4+
5151 (buffer-disable-undo standard-output)
5152 (let ((default-directory "/"))
5154 "ls" nil standard-output nil "-l" file-name))))
5155 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
5156 (let ((buffer-read-only nil))
5158 (insert-file-contents file-name nil)))
5159 (t (error "message-recover cancelled")))))
5161 ;;; Washing Subject:
5163 (defun message-wash-subject (subject)
5164 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
5165 Previous forwarders, replyers, etc. may add it."
5167 (insert-string subject)
5168 (goto-char (point-min))
5169 ;; strip Re/Fwd stuff off the beginning
5170 (while (re-search-forward
5171 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
5174 ;; and gnus-style forwards [foo@bar.com] subject
5175 (goto-char (point-min))
5176 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
5180 (goto-char (point-max))
5181 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
5184 ;; and finally, any whitespace that was left-over
5185 (goto-char (point-min))
5186 (while (re-search-forward "^[ \t]+" nil t)
5188 (goto-char (point-max))
5189 (while (re-search-backward "[ \t]+$" nil t)
5194 ;;; Forwarding messages.
5196 (defun message-forward-subject-author-subject (subject)
5197 "Generate a SUBJECT for a forwarded message.
5198 The form is: [Source] Subject, where if the original message was mail,
5199 Source is the sender, and if the original message was news, Source is
5200 the list of newsgroups is was posted to."
5202 (or (message-fetch-field
5203 (if (message-news-p) "newsgroups" "from"))
5207 (defun message-forward-subject-fwd (subject)
5208 "Generate a SUBJECT for a forwarded message.
5209 The form is: Fwd: Subject, where Subject is the original subject of
5211 (concat "Fwd: " subject))
5213 (defun message-make-forward-subject (&optional decoded)
5214 "Return a Subject header suitable for the message in the current buffer."
5217 (message-narrow-to-head-1)
5218 (let ((funcs message-make-forward-subject-function)
5219 (subject (message-fetch-field "Subject")))
5224 (nnheader-decode-subject subject))
5226 (if message-wash-forwarded-subjects
5227 (setq subject (message-wash-subject subject)))
5228 ;; Make sure funcs is a list.
5231 (setq funcs (list funcs)))
5232 ;; Apply funcs in order, passing subject generated by previous
5233 ;; func to the next one.
5235 (when (message-functionp (car funcs))
5236 (setq subject (funcall (car funcs) subject)))
5237 (setq funcs (cdr funcs)))
5241 (defun message-forward (&optional news)
5242 "Forward the current message via mail.
5243 Optional NEWS will use news to forward instead of mail."
5245 (let ((cur (current-buffer))
5246 (subject (message-make-forward-subject))
5249 (message-news nil subject)
5250 (message-mail nil subject))
5251 ;; Put point where we want it before inserting the forwarded
5253 (if message-forward-before-signature
5255 (goto-char (point-max)))
5256 ;; Make sure we're at the start of the line.
5259 ;; Narrow to the area we are to insert.
5260 (narrow-to-region (point) (point))
5261 ;; Insert the separators and the forwarded buffer.
5262 (insert message-forward-start-separator)
5263 (setq art-beg (point))
5264 (insert-buffer-substring cur)
5265 (goto-char (point-max))
5266 (insert message-forward-end-separator)
5267 (set-text-properties (point-min) (point-max) nil)
5268 ;; Remove all unwanted headers.
5270 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
5273 (goto-char (point-min))
5274 (message-remove-header message-included-forward-headers t nil t)
5276 (message-position-point)))
5279 (defun message-resend (address)
5280 "Resend the current article to ADDRESS."
5282 (list (message-read-from-minibuffer "Resend message to: ")))
5283 (message "Resending message to %s..." address)
5285 (let ((cur (current-buffer))
5287 ;; We first set up a normal mail buffer.
5288 (unless (message-mail-user-agent)
5289 (set-buffer (get-buffer-create " *message resend*"))
5291 (let ((message-this-is-mail t)
5292 ;; avoid to turn-on-mime-edit
5294 (message-setup `((To . ,address)))))
5295 ;; Insert our usual headers.
5296 (message-generate-headers '(From Date To))
5297 (message-narrow-to-headers)
5298 ;; Rename them all to "Resent-*".
5299 (while (re-search-forward "^[A-Za-z]" nil t)
5304 (delete-region (point) (point-max))
5306 ;; Insert the message to be resent.
5307 (insert-buffer-substring cur)
5308 (goto-char (point-min))
5309 (search-forward "\n\n")
5312 (narrow-to-region beg (point))
5313 (message-remove-header message-ignored-resent-headers t)
5314 (goto-char (point-max)))
5315 (insert mail-header-separator)
5316 ;; Rename all old ("Also-")Resent headers.
5317 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
5320 ;; Quote any "From " lines at the beginning.
5322 (when (looking-at "From ")
5323 (replace-match "X-From-Line: "))
5325 (let ((message-encoding-buffer (current-buffer))
5326 (message-edit-buffer (current-buffer)))
5327 (let (message-required-mail-headers)
5328 (message-send-mail)))
5329 (kill-buffer (current-buffer)))
5330 (message "Resending message to %s...done" address)))
5332 (defun message-bounce-setup-for-mime-edit ()
5333 (set (make-local-variable 'message-setup-hook) nil)
5337 (defun message-bounce ()
5338 "Re-mail the current message.
5339 This only makes sense if the current message is a bounce message that
5340 contains some mail you have written which has been bounced back to
5343 (let ((cur (current-buffer))
5345 (message-pop-to-buffer (message-buffer-name "bounce"))
5346 (insert-buffer-substring cur)
5348 (message-narrow-to-head)
5349 (if (and (message-fetch-field "MIME-Version")
5350 (setq boundary (message-fetch-field "Content-Type")))
5351 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary)
5352 (setq boundary (concat (match-string 1 boundary) " *\n"
5353 "Content-Type: message/rfc822"))
5354 (setq boundary nil)))
5356 (goto-char (point-min))
5357 (search-forward "\n\n" nil t)
5359 (re-search-forward boundary nil t)
5361 (and (re-search-forward message-unsent-separator nil t)
5363 (re-search-forward "^Return-Path:.*\n" nil t))
5364 ;; We remove everything before the bounced mail.
5367 (if (re-search-forward "^[^ \n\t]+:" nil t)
5371 (message-narrow-to-head-1)
5372 (message-remove-header message-ignored-bounced-headers t)
5373 (goto-char (point-max))
5374 (insert mail-header-separator))
5375 (when message-bounce-setup-function
5376 (funcall message-bounce-setup-function))
5377 (run-hooks 'message-bounce-setup-hook)
5378 (message-position-point)))
5381 ;;; Interactive entry points for new message buffers.
5385 (defun message-mail-other-window (&optional to subject)
5386 "Like `message-mail' command, but display mail buffer in another window."
5388 (unless (message-mail-user-agent)
5389 (let ((pop-up-windows t)
5390 (special-display-buffer-names nil)
5391 (special-display-regexps nil)
5392 (same-window-buffer-names nil)
5393 (same-window-regexps nil))
5394 (message-pop-to-buffer (message-buffer-name "mail" to))))
5395 (let ((message-this-is-mail t))
5396 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
5397 nil nil 'switch-to-buffer-other-window)))
5400 (defun message-mail-other-frame (&optional to subject)
5401 "Like `message-mail' command, but display mail buffer in another frame."
5403 (unless (message-mail-user-agent)
5404 (let ((pop-up-frames t)
5405 (special-display-buffer-names nil)
5406 (special-display-regexps nil)
5407 (same-window-buffer-names nil)
5408 (same-window-regexps nil))
5409 (message-pop-to-buffer (message-buffer-name "mail" to))))
5410 (let ((message-this-is-mail t))
5411 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
5412 nil nil 'switch-to-buffer-other-frame)))
5415 (defun message-news-other-window (&optional newsgroups subject)
5416 "Start editing a news article to be sent."
5418 (let ((pop-up-windows t)
5419 (special-display-buffer-names nil)
5420 (special-display-regexps nil)
5421 (same-window-buffer-names nil)
5422 (same-window-regexps nil))
5423 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
5424 (let ((message-this-is-news t))
5425 (message-setup `((Newsgroups . ,(or newsgroups ""))
5426 (Subject . ,(or subject ""))))))
5429 (defun message-news-other-frame (&optional newsgroups subject)
5430 "Start editing a news article to be sent."
5432 (let ((pop-up-frames t)
5433 (special-display-buffer-names nil)
5434 (special-display-regexps nil)
5435 (same-window-buffer-names nil)
5436 (same-window-regexps nil))
5437 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
5438 (let ((message-this-is-news t))
5439 (message-setup `((Newsgroups . ,(or newsgroups ""))
5440 (Subject . ,(or subject ""))))))
5444 ;; This code should be moved to underline.el (from which it is stolen).
5447 (defun bold-region (start end)
5448 "Bold all nonblank characters in the region.
5449 Works by overstriking characters.
5450 Called from program, takes two arguments START and END
5451 which specify the range to operate on."
5454 (let ((end1 (make-marker)))
5455 (move-marker end1 (max start end))
5456 (goto-char (min start end))
5457 (while (< (point) end1)
5458 (or (looking-at "[_\^@- ]")
5459 (insert (char-after) "\b"))
5460 (forward-char 1)))))
5463 (defun unbold-region (start end)
5464 "Remove all boldness (overstruck characters) in the region.
5465 Called from program, takes two arguments START and END
5466 which specify the range to operate on."
5469 (let ((end1 (make-marker)))
5470 (move-marker end1 (max start end))
5471 (goto-char (min start end))
5472 (while (re-search-forward "\b" end1 t)
5473 (if (eq (char-after) (char-after (- (point) 2)))
5474 (delete-char -2))))))
5476 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
5478 ;; Support for toolbar
5480 (defvar tool-bar-map)
5481 (defvar tool-bar-mode))
5483 (defun message-tool-bar-map ()
5484 (or message-tool-bar-map
5485 (setq message-tool-bar-map
5486 (and (fboundp 'tool-bar-add-item-from-menu)
5488 (let ((tool-bar-map (copy-keymap tool-bar-map))
5489 (load-path (mm-image-load-path)))
5490 ;; Zap some items which aren't so relevant and take
5492 (dolist (key '(print-buffer kill-buffer save-buffer
5493 write-file dired open-file))
5494 (define-key tool-bar-map (vector key) nil))
5495 (tool-bar-add-item-from-menu
5496 'message-send-and-exit "mail_send" message-mode-map)
5497 (tool-bar-add-item-from-menu
5498 'message-kill-buffer "close" message-mode-map)
5499 (tool-bar-add-item-from-menu
5500 'message-dont-send "cancel" message-mode-map)
5501 (tool-bar-add-item-from-menu
5502 'mml-attach-file "attach" message-mode-map)
5503 (tool-bar-add-item-from-menu
5504 'ispell-message "spell" message-mode-map)
5507 ;;; Group name completion.
5509 (defvar message-newgroups-header-regexp
5510 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
5511 "Regexp that match headers that lists groups.")
5513 (defun message-tab ()
5514 "Expand group names in Newsgroups and Followup-To headers.
5515 Do a `tab-to-tab-stop' if not in those headers."
5517 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp))
5518 (mail-abbrev-in-expansion-header-p))
5519 (message-expand-group)
5522 (defun message-expand-group ()
5523 "Expand the group name under point."
5524 (let* ((b (save-excursion
5529 (skip-chars-forward "^:")
5532 (skip-chars-backward "^, \t\n") (point))))
5533 (completion-ignore-case t)
5534 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
5536 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
5537 (completions (all-completions string hashtb))
5539 (delete-region b (point))
5541 ((= (length completions) 1)
5542 (if (string= (car completions) string)
5545 (message "Only matching group"))
5546 (insert (car completions))))
5547 ((and (setq comp (try-completion string hashtb))
5548 (not (string= comp string)))
5553 (message "No matching groups")
5554 (save-selected-window
5555 (pop-to-buffer "*Completions*")
5556 (buffer-disable-undo)
5557 (let ((buffer-read-only nil))
5559 (let ((standard-output (current-buffer)))
5560 (display-completion-list (sort completions 'string<)))
5561 (goto-char (point-min))
5562 (delete-region (point) (progn (forward-line 3) (point))))))))))
5566 (defun message-talkative-question (ask question show &rest text)
5567 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
5568 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
5569 The following arguments may contain lists of values."
5571 (setq text (message-flatten-list text)))
5572 (save-window-excursion
5574 (with-output-to-temp-buffer " *MESSAGE information message*"
5575 (set-buffer " *MESSAGE information message*")
5576 (fundamental-mode) ; for Emacs 20.4+
5577 (mapcar 'princ text)
5578 (goto-char (point-min))))
5579 (funcall ask question))
5580 (funcall ask question)))
5582 (defun message-flatten-list (list)
5583 "Return a new, flat list that contains all elements of LIST.
5585 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
5588 (apply 'append (mapcar 'message-flatten-list list)))
5592 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
5593 "Create and return a buffer with name based on NAME using `generate-new-buffer.'
5594 Then clone the local variables and values from the old buffer to the
5595 new one, cloning only the locals having a substring matching the
5597 (let ((oldbuf (current-buffer)))
5599 (set-buffer (generate-new-buffer name))
5600 (message-clone-locals oldbuf varstr)
5603 (defun message-clone-locals (buffer &optional varstr)
5604 "Clone the local variables from BUFFER to the current buffer."
5605 (let ((locals (save-excursion
5607 (buffer-local-variables)))
5609 "^\\(gnus\\|nn\\|message\\|user-\\(mail-address\\|full-name\\)\\)"))
5612 (when (and (consp local)
5614 (string-match regexp (symbol-name (car local)))
5616 (string-match varstr (symbol-name (car local)))))
5618 (set (make-local-variable (car local))
5623 ;;; @ for MIME Edit mode
5626 (defun message-maybe-encode ()
5627 (when message-mime-mode
5628 ;; Inherit the buffer local variable `mime-edit-pgp-processing'.
5629 (let ((pgp-processing (with-current-buffer message-edit-buffer
5630 mime-edit-pgp-processing)))
5631 (setq mime-edit-pgp-processing pgp-processing))
5632 (run-hooks 'mime-edit-translate-hook)
5633 (if (catch 'mime-edit-error
5635 (mime-edit-pgp-enclose-buffer)
5636 (mime-edit-translate-body)
5638 (error "Translation error!")
5641 (run-hooks 'mime-edit-exit-hook)
5644 (defun message-mime-insert-article (&optional full-headers)
5646 (let ((message-cite-function 'mime-edit-inserted-message-filter)
5647 (message-reply-buffer
5648 (message-get-parameter-with-eval 'original-buffer))
5650 (message-yank-original nil)
5652 (narrow-to-region (goto-char start)
5653 (if (search-forward "\n\n" nil t)
5656 (goto-char (point-min))
5657 (let ((message-included-forward-headers
5658 (if full-headers "" message-included-forward-headers)))
5659 (message-remove-header message-included-forward-headers t nil t))
5662 (set-alist 'mime-edit-message-inserter-alist
5663 'message-mode (function message-mime-insert-article))
5665 ;;; Miscellaneous functions
5667 ;; stolen (and renamed) from nnheader.el
5668 (static-if (fboundp 'subst-char-in-string)
5669 (defsubst message-replace-chars-in-string (string from to)
5670 (subst-char-in-string from to string))
5671 (defun message-replace-chars-in-string (string from to)
5672 "Replace characters in STRING from FROM to TO."
5673 (let ((string (substring string 0)) ;Copy string.
5674 (len (length string))
5676 ;; Replace all occurrences of FROM with TO.
5678 (when (= (aref string idx) from)
5679 (aset string idx to))
5680 (setq idx (1+ idx)))
5687 (defvar message-inhibit-body-encoding t)
5689 (defun message-encode-message-body ()
5690 (unless message-inhibit-body-encoding
5691 (let ((mail-parse-charset (or mail-parse-charset
5692 message-default-charset))
5693 (case-fold-search t)
5694 lines content-type-p)
5697 (narrow-to-region (point) (point-max))
5698 (let ((new (mml-generate-mime)))
5700 (delete-region (point-min) (point-max))
5702 (goto-char (point-min))
5703 (if (eq (aref new 0) ?\n)
5705 (search-forward "\n\n")
5706 (setq lines (buffer-substring (point-min) (1- (point))))
5707 (delete-region (point-min) (point))))))
5709 (message-narrow-to-headers-or-head)
5710 (message-remove-header "Mime-Version")
5711 (goto-char (point-max))
5712 (insert "MIME-Version: 1.0\n")
5715 (setq content-type-p
5717 (re-search-backward "^Content-Type:" nil t))))
5719 (message-narrow-to-headers-or-head)
5720 (message-remove-first-header "Content-Type")
5721 (message-remove-first-header "Content-Transfer-Encoding"))
5722 ;; We always make sure that the message has a Content-Type header.
5723 ;; This is because some broken MTAs and MUAs get awfully confused
5724 ;; when confronted with a message with a MIME-Version header and
5725 ;; without a Content-Type header. For instance, Solaris'
5727 (unless content-type-p
5728 (goto-char (point-min))
5729 (re-search-forward "^MIME-Version:")
5731 (insert "Content-Type: text/plain; charset=us-ascii\n")))))
5733 (defun message-read-from-minibuffer (prompt)
5734 "Read from the minibuffer while providing abbrev expansion."
5735 (if (fboundp 'mail-abbrevs-setup)
5736 (let ((mail-abbrev-mode-regexp "")
5737 (minibuffer-setup-hook 'mail-abbrevs-setup)
5738 (minibuffer-local-map message-minibuffer-local-map))
5739 (read-from-minibuffer prompt))
5740 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
5741 (minibuffer-local-map message-minibuffer-local-map))
5742 (read-string prompt))))
5744 (defun message-use-alternative-email-as-from ()
5745 (require 'mail-utils)
5746 (let* ((fields '("To" "Cc"))
5749 (mail-strip-quoted-names
5750 (mapconcat 'message-fetch-reply-field fields ","))
5754 (if (string-match message-alternative-emails (car emails))
5755 (setq email (car emails)
5758 (unless (or (not email) (equal email user-mail-address))
5759 (goto-char (point-max))
5760 (insert "From: " email "\n"))))
5762 (defun message-options-get (symbol)
5763 (cdr (assq symbol message-options)))
5765 (defun message-options-set (symbol value)
5766 (let ((the-cons (assq symbol message-options)))
5769 (setcdr the-cons value)
5770 (setq message-options (delq the-cons message-options)))
5772 (push (cons symbol value) message-options))))
5775 (defun message-options-set-recipient ()
5777 (message-narrow-to-headers-or-head)
5778 (message-options-set 'message-sender
5779 (mail-strip-quoted-names
5780 (message-fetch-field "from")))
5781 (message-options-set 'message-recipients
5782 (mail-strip-quoted-names
5783 (message-fetch-field "to")))))
5785 (when (featurep 'xemacs)
5786 (require 'messagexmas)
5787 (message-xmas-redefine))
5789 (defun message-save-drafts ()
5790 "Postponing the message."
5792 (message "Saving %s..." buffer-file-name)
5793 (let ((reply-headers message-reply-headers)
5794 (msg (buffer-substring-no-properties (point-min) (point-max))))
5795 (with-temp-file buffer-file-name
5797 (setq message-reply-headers reply-headers)
5798 (message-generate-headers '((optional . In-Reply-To)))
5799 (mime-edit-translate-buffer))
5800 (set-buffer-modified-p nil))
5801 (message "Saving %s...done" buffer-file-name))
5805 (run-hooks 'message-load-hook)
5808 ;; coding: iso-8859-1
5811 ;;; message.el ends here