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', `reply-to'."
205 :type '(repeat sexp)) ; Fixme: improve this
207 (defcustom message-required-news-headers
208 '(From Newsgroups Subject Date Message-ID
209 (optional . Organization) Lines
210 (optional . User-Agent))
211 "*Headers to be generated or prompted for when posting an article.
212 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
213 Message-ID. Organization, Lines, In-Reply-To, Expires, and
214 User-Agent are optional. If don't you want message to insert some
215 header, remove it from this list."
217 :group 'message-headers
218 :type '(repeat sexp))
220 (defcustom message-required-mail-headers
221 '(From Subject Date (optional . In-Reply-To) Message-ID Lines
222 (optional . User-Agent))
223 "*Headers to be generated or prompted for when mailing a message.
224 RFC822 required that From, Date, To, Subject and Message-ID be
225 included. Organization, Lines and User-Agent are optional."
227 :group 'message-headers
228 :type '(repeat sexp))
230 (defcustom message-deletable-headers '(Message-ID Date Lines)
231 "Headers to be deleted if they already exist and were generated by message previously."
232 :group 'message-headers
235 (defcustom message-ignored-news-headers
236 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:"
237 "*Regexp of headers to be removed unconditionally before posting."
239 :group 'message-headers
242 (defcustom message-ignored-mail-headers
243 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:"
244 "*Regexp of headers to be removed unconditionally before mailing."
246 :group 'message-headers
249 (defcustom message-ignored-supersedes-headers "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|^X-Trace:\\|^X-Complaints-To:\\|Return-Path:\\|^Supersedes:\\|^NNTP-Posting-Date:\\|^X-Trace:\\|^X-Complaints-To:"
250 "*Header lines matching this regexp will be deleted before posting.
251 It's best to delete old Path and Date headers before posting to avoid
253 :group 'message-interface
256 (defcustom message-supersede-setup-function
257 'message-supersede-setup-for-mime-edit
258 "Function to setup a supersede message."
259 :group 'message-sending
262 (defcustom message-subject-re-regexp "^[ \t]*\\([Rr][Ee]:[ \t]*\\)*[ \t]*"
263 "*Regexp matching \"Re: \" in the subject line."
264 :group 'message-various
267 ;;; Some sender agents encode the whole subject including leading "Re: ".
268 ;;; And if followup agent does not decode it for some reason (e.g. unknown
269 ;;; charset) and just add a new "Re: " in front of the encoded-word, the
270 ;;; result will contain multiple "Re: "'s.
271 (defcustom message-subject-encoded-re-regexp
275 "[-!#$%&'*+0-9A-Z^_`a-z{|}~]+" ; charset
278 "[Bb]" (regexp-quote "?") ; B encoding
279 "\\(\\(CQk\\|CSA\\|IAk\\|ICA\\)[Jg]\\)*" ; \([ \t][ \t][ \t]\)*
281 "[Uc][km]U6" ; [Rr][Ee]:
283 "\\(C[VX]\\|I[FH]\\)J[Fl]O[g-v]" ; [ \t][Rr][Ee]:
285 "\\(CQl\\|CSB\\|IAl\\|ICB\\)[Sy][RZ]T[o-r]" ; [ \t][ \t][Rr][Ee]:
288 "[Qb]" (regexp-quote "?") ; Q encoding
289 "\\(_\\|=09\\|=20\\)*"
290 "\\([Rr]\\|=[57]2\\)\\([Ee]\\|=[46]5\\)\\(:\\|=3[Aa]\\)"
293 "*Regexp matching \"Re: \" in the subject line.
294 Unlike `message-subject-re-regexp', this regexp matches \"Re: \" within
296 :group 'message-various
299 (defcustom message-use-subject-re t
300 "*If t, remove any (buggy) \"Re: \"'s from the subject of the precursor
301 and add a new \"Re: \". If it is nil, use the subject \"as-is\". If it
302 is the symbol `guess', try to detect \"Re: \" within an encoded-word."
303 :group 'message-various
304 :type '(choice (const :tag "off" nil)
309 (defcustom message-signature-separator "^-- *$"
310 "Regexp matching the signature separator."
312 :group 'message-various)
314 (defcustom message-elide-ellipsis "\n[...]\n\n"
315 "*The string which is inserted for elided text."
317 :group 'message-various)
319 (defcustom message-interactive nil
320 "Non-nil means when sending a message wait for and display errors.
321 nil means let mailer mail back a message to report errors."
322 :group 'message-sending
326 (defcustom message-generate-new-buffers 'unique
327 "*Non-nil means create a new message buffer whenever `message-setup' is called.
328 If this is a function, call that function with three parameters: The type,
329 the to address and the group name. (Any of these may be nil.) The function
330 should return the new buffer name."
331 :group 'message-buffers
332 :type '(choice (const :tag "off" nil)
333 (const :tag "unique" unique)
334 (const :tag "unsent" unsent)
337 (defcustom message-kill-buffer-on-exit nil
338 "*Non-nil means that the message buffer will be killed after sending a message."
339 :group 'message-buffers
342 (defcustom message-kill-buffer-query-function 'yes-or-no-p
343 "*A function called to query the user whether to kill buffer anyway or not.
344 If it is t, the buffer will be killed peremptorily."
345 :type '(radio (function-item yes-or-no-p)
346 (function-item y-or-n-p)
347 (function-item nnheader-Y-or-n-p)
348 (function :tag "Other" t))
349 :group 'message-buffers)
352 (defvar gnus-local-organization))
353 (defcustom message-user-organization
354 (or (and (boundp 'gnus-local-organization)
355 (stringp gnus-local-organization)
356 gnus-local-organization)
357 (getenv "ORGANIZATION")
359 "*String to be used as an Organization header.
360 If t, use `message-user-organization-file'."
361 :group 'message-headers
362 :type '(choice string
363 (const :tag "consult file" t)))
366 (defcustom message-user-organization-file "/usr/lib/news/organization"
367 "*Local news organization file."
369 :group 'message-headers)
371 (defcustom message-forward-start-separator
372 (concat (mime-make-tag "message" "rfc822") "\n")
373 "*Delimiter inserted before forwarded messages."
374 :group 'message-forwarding
377 (defcustom message-forward-end-separator
378 (concat (mime-make-tag "text" "plain") "\n")
379 "*Delimiter inserted after forwarded messages."
380 :group 'message-forwarding
383 (defcustom message-included-forward-headers
384 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^\\(Mail-\\)?Followup-To:\\|^\\(Mail-\\)?Reply-To:\\|^Mail-Copies-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-\\|^Message-ID:\\|^References:\\|^Content-\\|^MIME-Version:"
385 "*Regexp matching headers to be included in forwarded messages."
386 :group 'message-forwarding
389 (defcustom message-make-forward-subject-function
390 'message-forward-subject-author-subject
391 "*List of functions called to generate subject headers for forwarded messages.
392 The subject generated by the previous function is passed into each
395 The provided functions are:
397 * `message-forward-subject-author-subject' (Source of article (author or
398 newsgroup)), in brackets followed by the subject
399 * `message-forward-subject-fwd' (Subject of article with 'Fwd:' prepended
401 :group 'message-forwarding
402 :type '(radio (function-item message-forward-subject-author-subject)
403 (function-item message-forward-subject-fwd)
404 (repeat :tag "List of functions" function)))
406 (defcustom message-forward-as-mime t
407 "*If non-nil, forward messages as an inline/rfc822 MIME section. Otherwise, directly inline the old message in the forwarded message."
409 :group 'message-forwarding
412 (defcustom message-forward-show-mml t
413 "*If non-nil, forward messages are shown as mml. Otherwise, forward messages are unchanged."
415 :group 'message-forwarding
418 (defcustom message-forward-before-signature t
419 "*If non-nil, put forwarded message before signature, else after."
420 :group 'message-forwarding
423 (defcustom message-wash-forwarded-subjects nil
424 "*If non-nil, try to remove as much old cruft as possible from the subject of messages before generating the new subject of a forward."
425 :group 'message-forwarding
428 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:"
429 "*All headers that match this regexp will be deleted when resending a message."
430 :group 'message-interface
433 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
434 "*All headers that match this regexp will be deleted when forwarding a message."
436 :group 'message-forwarding
437 :type '(choice (const :tag "None" nil)
440 (defcustom message-ignored-cited-headers "."
441 "*Delete these headers from the messages you yank."
442 :group 'message-insertion
445 (defcustom message-cite-prefix-regexp
446 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
447 "\\([ \t]*[-_.[:word:]]+>+\\|[ \t]*[]>»|:}+]\\)+"
448 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
449 "\\([ \t]*\\(\\w\\|[-_.]\\)+>+\\|[ \t]*[]>»|:}+]\\)+")
450 "*Regexp matching the longest possible citation prefix on a line."
451 :group 'message-insertion
454 (defcustom message-cancel-message "I am canceling my own article.\n"
455 "Message to be inserted in the cancel message."
456 :group 'message-interface
459 ;; Useful to set in site-init.el
461 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
462 "Function to call to send the current buffer as mail.
463 The headers should be delimited by a line whose contents match the
464 variable `mail-header-separator'.
466 Valid values include `message-send-mail-with-sendmail' (the default),
467 `message-send-mail-with-mh', `message-send-mail-with-qmail',
468 `message-send-mail-with-smtp', `smtpmail-send-it' and `feedmail-send-it'.
470 See also `send-mail-function'."
471 :type '(radio (function-item message-send-mail-with-sendmail)
472 (function-item message-send-mail-with-mh)
473 (function-item message-send-mail-with-qmail)
474 (function-item message-send-mail-with-smtp)
475 (function-item smtpmail-send-it)
476 (function-item feedmail-send-it)
477 (function :tag "Other"))
478 :group 'message-sending
479 :group 'message-mail)
481 ;; 1997-09-29 by MORIOKA Tomohiko
482 (defcustom message-send-news-function 'message-send-news-with-gnus
483 "Function to call to send the current buffer as news.
484 The headers should be delimited by a line whose contents match the
485 variable `mail-header-separator'."
486 :group 'message-sending
490 (defcustom message-reply-to-function nil
491 "If non-nil, function that should return a list of headers.
492 This function should pick out addresses from the To, Cc, and From headers
493 and respond with new To and Cc headers."
494 :group 'message-interface
495 :type '(choice function (const nil)))
497 (defcustom message-wide-reply-to-function nil
498 "If non-nil, function that should return a list of headers.
499 This function should pick out addresses from the To, Cc, and From headers
500 and respond with new To and Cc headers."
501 :group 'message-interface
502 :type '(choice function (const nil)))
504 (defcustom message-followup-to-function nil
505 "If non-nil, function that should return a list of headers.
506 This function should pick out addresses from the To, Cc, and From headers
507 and respond with new To and Cc headers."
508 :group 'message-interface
509 :type '(choice function (const nil)))
511 (defcustom message-use-followup-to 'ask
512 "*Specifies what to do with Followup-To header.
513 If nil, always ignore the header. If it is t, use its value, but
514 query before using the \"poster\" value. If it is the symbol `ask',
515 always query the user whether to use the value. If it is the symbol
516 `use', always use the value."
517 :group 'message-interface
518 :type '(choice (const :tag "ignore" nil)
519 (const :tag "use & query" t)
520 (const :tag "maybe" t)
521 (const :tag "always" use)
522 (const :tag "ask" ask)))
524 (defcustom message-use-mail-copies-to 'ask
525 "*Specifies what to do with Mail-Copies-To header.
526 If nil, always ignore the header. If it is t, use its value, but
527 query before using the value other than \"always\" or \"never\".
528 If it is the symbol `ask', always query the user whether to use
529 the value. If it is the symbol `use', always use the value."
530 :group 'message-interface
531 :type '(choice (const :tag "ignore" nil)
532 (const :tag "maybe" t)
533 (const :tag "always" use)
534 (const :tag "ask" ask)))
536 ;;; XXX: 'ask and 'use are not implemented yet.
537 (defcustom message-use-mail-reply-to 'ask
538 "*Specifies what to do with Mail-Reply-To/Reply-To header.
539 If nil, always ignore the header. If it is t or the symbol `use', use
540 its value. If it is the symbol `ask', always query the user whether to
541 use the value. Note that if \"Reply-To\" is marked as \"broken\", its value
543 :group 'message-interface
544 :type '(choice (const :tag "ignore" nil)
545 (const :tag "maybe" t)
546 (const :tag "always" use)
547 (const :tag "ask" ask)))
549 (defcustom message-use-mail-followup-to 'use
550 "*Specifies what to do with Mail-Followup-To header.
551 If nil, always ignore the header. If it is the symbol `ask', always
552 query the user whether to use the value. If it is t or the symbol
553 `use', always use the value."
554 :group 'message-interface
555 :type '(choice (const :tag "ignore" nil)
556 (const :tag "maybe" t)
557 (const :tag "always" use)
558 (const :tag "ask" ask)))
560 (defcustom message-sendmail-f-is-evil nil
561 "*Non-nil means don't add \"-f username\" to the sendmail command line.
562 Doing so would be even more evil than leaving it out."
563 :group 'message-sending
566 ;; qmail-related stuff
567 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
568 "Location of the qmail-inject program."
569 :group 'message-sending
572 (defcustom message-qmail-inject-args nil
573 "Arguments passed to qmail-inject programs.
574 This should be a list of strings, one string for each argument.
576 For e.g., if you wish to set the envelope sender address so that bounces
577 go to the right place or to deal with listserv's usage of that address, you
578 might set this variable to '(\"-f\" \"you@some.where\")."
579 :group 'message-sending
580 :type '(repeat string))
582 (defvar message-cater-to-broken-inn t
583 "Non-nil means Gnus should not fold the `References' header.
584 Folding `References' makes ancient versions of INN create incorrect
588 (defvar gnus-post-method)
589 (defvar gnus-select-method))
590 (defcustom message-post-method
591 (cond ((and (boundp 'gnus-post-method)
592 (listp gnus-post-method)
595 ((boundp 'gnus-select-method)
598 "*Method used to post news.
599 Note that when posting from inside Gnus, for instance, this
600 variable isn't used."
602 :group 'message-sending
603 ;; This should be the `gnus-select-method' widget, but that might
604 ;; create a dependence to `gnus.el'.
607 (defcustom message-generate-headers-first nil
608 "*If non-nil, generate all required headers before composing.
609 The variables `message-required-news-headers' and
610 `message-required-mail-headers' specify which headers to generate.
612 Note that the variable `message-deletable-headers' specifies headers which
613 are to be deleted and then re-generated before sending, so this variable
614 will not have a visible effect for those headers."
615 :group 'message-headers
618 (defcustom message-setup-hook '(turn-on-mime-edit)
619 "Normal hook, run each time a new outgoing message is initialized.
620 The function `message-setup' runs this hook."
621 :group 'message-various
624 (defcustom message-cancel-hook nil
625 "Hook run when cancelling articles."
626 :group 'message-various
629 (defcustom message-signature-setup-hook nil
630 "Normal hook, run each time a new outgoing message is initialized.
631 It is run after the headers have been inserted and before
632 the signature is inserted."
633 :group 'message-various
636 (defcustom message-bounce-setup-hook nil
637 "Normal hook, run each time a re-sending bounced message is initialized.
638 The function `message-bounce' runs this hook."
639 :group 'message-various
642 (defcustom message-supersede-setup-hook nil
643 "Normal hook, run each time a supersede message is initialized.
644 The function `message-supersede' runs this hook."
645 :group 'message-various
648 (defcustom message-mode-hook nil
649 "Hook run in message mode buffers."
650 :group 'message-various
653 (defcustom message-header-hook '((lambda () (eword-encode-header t)))
654 "Hook run in a message mode buffer narrowed to the headers."
655 :group 'message-various
658 (defcustom message-header-setup-hook nil
659 "Hook called narrowed to the headers when setting up a message buffer."
660 :group 'message-various
663 (defcustom message-minibuffer-local-map
664 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
665 (set-keymap-parent map minibuffer-local-map)
667 "Keymap for `message-read-from-minibuffer'.")
670 (defcustom message-citation-line-function 'message-insert-citation-line
671 "*Function called to insert the \"Whomever writes:\" line.
673 Note that Gnus provides a feature where the reader can click on
674 `writes:' to hide the cited text. If you change this line too much,
675 people who read your message will have to change their Gnus
676 configuration. See the variable `gnus-cite-attribution-suffix'."
678 :group 'message-insertion)
681 (defcustom message-yank-prefix "> "
682 "*Prefix inserted on the lines of yanked messages.
683 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
684 See also `message-yank-cited-prefix'."
686 :group 'message-insertion)
688 (defcustom message-yank-add-new-references t
689 "Non-nil means new IDs will be added to \"References\" field when an
690 article is yanked by the command `message-yank-original' interactively.
691 If it is a symbol `message-id-only', only an ID from \"Message-ID\" field
692 is used, otherwise IDs extracted from \"References\", \"In-Reply-To\" and
693 \"Message-ID\" fields are used."
694 :type '(radio (const :tag "Do not add anything" nil)
695 (const :tag "From Message-Id, References and In-Reply-To fields" t)
696 (const :tag "From only Message-Id field." message-id-only))
697 :group 'message-insertion)
699 (defcustom message-list-references-add-position nil
700 "Integer value means position for adding to \"References\" field when
701 an article is yanked by the command `message-yank-original' interactively."
702 :type '(radio (const :tag "Add to last" nil)
703 (integer :tag "Position from last ID"))
704 :group 'message-insertion)
706 (defcustom message-yank-cited-prefix ">"
707 "*Prefix inserted on cited lines of yanked messages.
708 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
709 See also `message-yank-prefix'."
711 :group 'message-insertion)
713 (defcustom message-indentation-spaces 3
714 "*Number of spaces to insert at the beginning of each cited line.
715 Used by `message-yank-original' via `message-yank-cite'."
716 :group 'message-insertion
720 (defcustom message-cite-function 'message-cite-original
721 "*Function for citing an original message.
722 Predefined functions include `message-cite-original' and
723 `message-cite-original-without-signature'.
724 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
725 :type '(radio (function-item message-cite-original)
726 (function-item message-cite-original-without-signature)
727 (function-item mu-cite-original)
728 (function-item sc-cite-original)
729 (function :tag "Other"))
730 :group 'message-insertion)
733 (defcustom message-suspend-font-lock-when-citing nil
734 "Non-nil means suspend font-lock'ing while citing an original message.
735 Some lazy demand-driven fontification tools (or Emacs itself) have a
736 bug that they often miss a buffer to be fontified. It will mostly
737 occur when Emacs prompts user for any inputs in the minibuffer.
738 Setting this option to non-nil may help you to avoid unpleasant errors
739 even if it is an add-hoc expedient."
741 :group 'message-insertion)
744 (defcustom message-indent-citation-function 'message-indent-citation
745 "*Function for modifying a citation just inserted in the mail buffer.
746 This can also be a list of functions. Each function can find the
747 citation between (point) and (mark t). And each function should leave
748 point and mark around the citation text as modified."
750 :group 'message-insertion)
752 (defvar message-abbrevs-loaded nil)
755 (defcustom message-signature t
756 "*String to be inserted at the end of the message buffer.
757 If t, the `message-signature-file' file will be inserted instead.
758 If a function, the result from the function will be used instead.
759 If a form, the result from the form will be used instead."
761 :group 'message-insertion)
764 (defcustom message-signature-file "~/.signature"
765 "*Name of file containing the text inserted at end of message buffer.
766 Ignored if the named file doesn't exist.
767 If nil, don't insert a signature."
768 :type '(choice file (const :tags "None" nil))
769 :group 'message-insertion)
771 (defcustom message-distribution-function nil
772 "*Function called to return a Distribution header."
774 :group 'message-headers
775 :type '(choice function (const nil)))
777 (defcustom message-expires 14
778 "Number of days before your article expires."
780 :group 'message-headers
781 :link '(custom-manual "(message)News Headers")
784 (defcustom message-user-path nil
785 "If nil, use the NNTP server name in the Path header.
786 If stringp, use this; if non-nil, use no host name (user name only)."
788 :group 'message-headers
789 :link '(custom-manual "(message)News Headers")
790 :type '(choice (const :tag "nntp" nil)
792 (sexp :tag "none" :format "%t" t)))
794 (defvar message-reply-buffer nil)
795 (defvar message-reply-headers nil)
796 (defvar message-sent-message-via nil)
797 (defvar message-checksum nil)
798 (defvar message-send-actions nil
799 "A list of actions to be performed upon successful sending of a message.")
800 (defvar message-exit-actions nil
801 "A list of actions to be performed upon exiting after sending a message.")
802 (defvar message-kill-actions nil
803 "A list of actions to be performed before killing a message buffer.")
804 (defvar message-postpone-actions nil
805 "A list of actions to be performed after postponing a message.")
806 (defvar message-original-frame nil)
807 (defvar message-parameter-alist nil)
808 (defvar message-startup-parameter-alist nil)
810 (define-widget 'message-header-lines 'text
811 "All header lines must be LFD terminated."
812 :format "%{%t%}:%n%v"
814 :error "All header lines must be newline terminated")
816 (defcustom message-default-headers ""
817 "*A string containing header lines to be inserted in outgoing messages.
818 It is inserted before you edit the message, so you can edit or delete
820 :group 'message-headers
821 :type 'message-header-lines)
823 (defcustom message-default-mail-headers ""
824 "*A string of header lines to be inserted in outgoing mails."
825 :group 'message-headers
827 :type 'message-header-lines)
829 (defcustom message-default-news-headers ""
830 "*A string of header lines to be inserted in outgoing news articles."
831 :group 'message-headers
833 :type 'message-header-lines)
835 ;; Note: could use /usr/ucb/mail instead of sendmail;
836 ;; options -t, and -v if not interactive.
837 (defcustom message-mailer-swallows-blank-line
838 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
839 system-configuration)
840 (file-readable-p "/etc/sendmail.cf")
841 (let ((buffer (get-buffer-create " *temp*")))
845 (insert-file-contents "/etc/sendmail.cf")
846 (goto-char (point-min))
847 (let ((case-fold-search nil))
848 (re-search-forward "^OR\\>" nil t)))
849 (kill-buffer buffer))))
850 ;; According to RFC822, "The field-name must be composed of printable
851 ;; ASCII characters (i. e., characters that have decimal values between
852 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
854 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
855 "*Set this non-nil if the system's mailer runs the header and body together.
856 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
857 The value should be an expression to test whether the problem will
859 :group 'message-sending
862 ;;; XXX: This symbol is overloaded! See below.
863 (defvar message-user-agent nil
864 "String of the form of PRODUCT/VERSION. Used for User-Agent header field.")
866 (static-when (boundp 'MULE)
867 (require 'reporter));; `define-mail-user-agent' is here.
870 (define-mail-user-agent 'message-user-agent
871 'message-mail 'message-send-and-exit
872 'message-kill-buffer 'message-send-hook)
874 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
875 "If non-nil, delete the deletable headers before feeding to mh.")
877 (defvar message-send-method-alist
878 '((news message-news-p message-send-via-news)
879 (mail message-mail-p message-send-via-mail))
880 "Alist of ways to send outgoing messages.
881 Each element has the form
883 \(TYPE PREDICATE FUNCTION)
885 where TYPE is a symbol that names the method; PREDICATE is a function
886 called without any parameters to determine whether the message is
887 a message of type TYPE; and FUNCTION is a function to be called if
888 PREDICATE returns non-nil. FUNCTION is called with one parameter --
891 (defcustom message-mail-alias-type 'abbrev
892 "*What alias expansion type to use in Message buffers.
893 The default is `abbrev', which uses mailabbrev. nil switches
896 :link '(custom-manual "(message)Mail Aliases")
897 :type '(choice (const :tag "Use Mailabbrev" abbrev)
898 (const :tag "No expansion" nil)))
900 (defcustom message-auto-save-directory
901 (file-name-as-directory (nnheader-concat message-directory "drafts"))
902 "*Directory where Message auto-saves buffers if Gnus isn't running.
903 If nil, Message won't auto-save."
904 :group 'message-buffers
905 :type '(choice directory (const :tag "Don't auto-save" nil)))
907 (defcustom message-buffer-naming-style 'unique
908 "*The way new message buffers are named.
909 Valid valued are `unique' and `unsent'."
911 :group 'message-buffers
912 :type '(choice (const :tag "unique" unique)
913 (const :tag "unsent" unsent)))
915 (defcustom message-default-charset
916 (and (featurep 'xemacs) (not (featurep 'mule)) 'iso-8859-1)
917 "Default charset used in non-MULE XEmacsen."
922 (defcustom message-dont-reply-to-names
923 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
924 "*A regexp specifying addresses to prune when doing wide replies.
925 A value of nil means exclude your own user name only."
928 :type '(choice (const :tag "Yourself" nil)
931 (defvar message-shoot-gnksa-feet nil
932 "*A list of GNKSA feet you are allowed to shoot.
933 Gnus gives you all the opportunity you could possibly want for
934 shooting yourself in the foot. Also, Gnus allows you to shoot the
935 feet of Good Net-Keeping Seal of Approval. The following are foot
937 `empty-article' Allow you to post an empty article;
938 `quoted-text-only' Allow you to post quoted text only;
939 `multiple-copies' Allow you to post multiple copies.")
940 ;; `cancel-messages' Allow you to cancel or supersede others' messages.
942 (defsubst message-gnksa-enable-p (feature)
943 (or (not (listp message-shoot-gnksa-feet))
944 (memq feature message-shoot-gnksa-feet)))
946 ;;; Internal variables.
947 ;;; Well, not really internal.
949 (defvar message-mode-syntax-table
950 (let ((table (copy-syntax-table text-mode-syntax-table)))
951 (modify-syntax-entry ?% ". " table)
952 (modify-syntax-entry ?> ". " table)
953 (modify-syntax-entry ?< ". " table)
955 "Syntax table used while in Message mode.")
957 (defface message-header-to-face
960 (:foreground "green2" :bold t))
963 (:foreground "MidnightBlue" :bold t))
965 (:bold t :italic t)))
966 "Face used for displaying From headers."
967 :group 'message-faces)
969 (defface message-header-cc-face
972 (:foreground "green4" :bold t))
975 (:foreground "MidnightBlue"))
978 "Face used for displaying Cc headers."
979 :group 'message-faces)
981 (defface message-header-subject-face
984 (:foreground "green3"))
987 (:foreground "navy blue" :bold t))
990 "Face used for displaying subject headers."
991 :group 'message-faces)
993 (defface message-header-newsgroups-face
996 (:foreground "yellow" :bold t :italic t))
999 (:foreground "blue4" :bold t :italic t))
1001 (:bold t :italic t)))
1002 "Face used for displaying newsgroups headers."
1003 :group 'message-faces)
1005 (defface message-header-other-face
1008 (:foreground "#b00000"))
1011 (:foreground "steel blue"))
1013 (:bold t :italic t)))
1014 "Face used for displaying newsgroups headers."
1015 :group 'message-faces)
1017 (defface message-header-name-face
1020 (:foreground "DarkGreen"))
1023 (:foreground "cornflower blue"))
1026 "Face used for displaying header names."
1027 :group 'message-faces)
1029 (defface message-header-xheader-face
1032 (:foreground "blue"))
1035 (:foreground "blue"))
1038 "Face used for displaying X-Header headers."
1039 :group 'message-faces)
1041 (defface message-separator-face
1044 (:foreground "blue3"))
1047 (:foreground "brown"))
1050 "Face used for displaying the separator."
1051 :group 'message-faces)
1053 (defface message-cited-text-face
1056 (:foreground "red"))
1059 (:foreground "red"))
1062 "Face used for displaying cited text names."
1063 :group 'message-faces)
1065 (defface message-mml-face
1068 (:foreground "ForestGreen"))
1071 (:foreground "ForestGreen"))
1074 "Face used for displaying MML."
1075 :group 'message-faces)
1077 (defvar message-font-lock-keywords
1078 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1079 `((,(concat "^\\([Tt]o:\\)" content)
1080 (1 'message-header-name-face)
1081 (2 'message-header-to-face nil t))
1082 (,(concat "^\\([GBF]?[Cc][Cc]:\\|[Rr]eply-[Tt]o:\\|"
1083 "[Mm]ail-[Cc]opies-[Tt]o:\\|"
1084 "[Mm]ail-[Rr]eply-[Tt]o:\\|"
1085 "[Mm]ail-[Ff]ollowup-[Tt]o:\\)" content)
1086 (1 'message-header-name-face)
1087 (2 'message-header-cc-face nil t))
1088 (,(concat "^\\([Ss]ubject:\\)" content)
1089 (1 'message-header-name-face)
1090 (2 'message-header-subject-face nil t))
1091 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content)
1092 (1 'message-header-name-face)
1093 (2 'message-header-newsgroups-face nil t))
1094 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content)
1095 (1 'message-header-name-face)
1096 (2 'message-header-other-face nil t))
1097 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content)
1098 (1 'message-header-name-face)
1099 (2 'message-header-name-face))
1100 ,@(if (and mail-header-separator
1101 (not (equal mail-header-separator "")))
1102 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1103 1 'message-separator-face))
1105 (,(concat "^\\(" message-cite-prefix-regexp "\\).*")
1106 (0 'message-cited-text-face))
1107 (,mime-edit-tag-regexp
1108 (0 'message-mml-face))))
1109 "Additional expressions to highlight in Message mode.")
1111 ;; XEmacs does it like this. For Emacs, we have to set the
1112 ;; `font-lock-defaults' buffer-local variable.
1113 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
1115 (defvar message-face-alist
1116 '((bold . bold-region)
1117 (underline . underline-region)
1118 (default . (lambda (b e)
1120 (ununderline-region b e))))
1121 "Alist of mail and news faces for facemenu.
1122 The cdr of ech entry is a function for applying the face to a region.")
1124 (defcustom message-send-hook nil
1125 "Hook run before sending messages."
1126 :group 'message-various
1127 :options '(ispell-message)
1130 (defcustom message-send-mail-hook nil
1131 "Hook run before sending mail messages."
1132 :group 'message-various
1135 (defcustom message-send-news-hook nil
1136 "Hook run before sending news messages."
1137 :group 'message-various
1140 (defcustom message-sent-hook nil
1141 "Hook run after sending messages."
1142 :group 'message-various
1145 (defcustom message-use-multi-frames nil
1146 "Make new frame when sending messages."
1147 :group 'message-frames
1150 (defcustom message-delete-frame-on-exit nil
1151 "Delete frame after sending messages."
1152 :group 'message-frames
1153 :type '(choice (const :tag "off" nil)
1154 (const :tag "always" t)
1155 (const :tag "ask" ask)))
1157 (defvar message-draft-coding-system
1159 ((boundp 'MULE) '*junet*)
1160 ((not (fboundp 'find-coding-system)) nil)
1161 ((find-coding-system 'emacs-mule)
1162 (if (memq system-type '(windows-nt ms-dos ms-windows))
1163 'emacs-mule-dos 'emacs-mule))
1164 ((find-coding-system 'escape-quoted) 'escape-quoted)
1165 ((find-coding-system 'no-conversion) 'no-conversion)
1167 "Coding system to compose mail.")
1169 (defcustom message-send-mail-partially-limit 1000000
1170 "The limitation of messages sent as message/partial.
1171 The lower bound of message size in characters, beyond which the message
1172 should be sent in several parts. If it is nil, the size is unlimited."
1174 :group 'message-buffers
1175 :type '(choice (const :tag "unlimited" nil)
1178 (defcustom message-alternative-emails nil
1179 "A regexp to match the alternative email addresses.
1180 The first matched address (not primary one) is used in the From field."
1181 :group 'message-headers
1182 :type '(choice (const :tag "Always use primary" nil)
1185 (defcustom message-mail-user-agent nil
1186 "Like `mail-user-agent'.
1187 Except if it is nil, use Gnus native MUA; if it is t, use
1189 :type '(radio (const :tag "Gnus native"
1192 (const :tag "`mail-user-agent'"
1195 (function-item :tag "Default Emacs mail"
1197 sendmail-user-agent)
1198 (function-item :tag "Emacs interface to MH"
1201 (function :tag "Other"))
1205 (defcustom message-wide-reply-confirm-recipients nil
1206 "Whether to confirm a wide reply to multiple email recipients.
1207 If this variable is nil, don't ask whether to reply to all recipients.
1208 If this variable is non-nil, pose the question \"Reply to all
1209 recipients?\" before a wide reply to multiple recipients. If the user
1210 answers yes, reply to all recipients as usual. If the user answers
1211 no, only reply back to the author."
1212 :group 'message-headers
1215 ;;; Internal variables.
1217 (defvar message-sending-message "Sending...")
1218 (defvar message-buffer-list nil)
1219 (defvar message-this-is-news nil)
1220 (defvar message-this-is-mail nil)
1221 (defvar message-draft-article nil)
1222 (defvar message-mime-part nil)
1223 (defvar message-posting-charset nil)
1225 ;; Byte-compiler warning
1227 (defvar gnus-active-hashtb)
1228 (defvar gnus-read-active-file))
1230 ;;; Regexp matching the delimiter of messages in UNIX mail format
1231 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1232 ;;; of rmail.el's rmail-unix-mail-delimiter.
1233 (defvar message-unix-mail-delimiter
1234 (let ((time-zone-regexp
1235 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1236 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1242 ;; Many things can happen to an RFC 822 mailbox before it is put into
1243 ;; a `From' line. The leading phrase can be stripped, e.g.
1244 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1245 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1246 ;; can be removed, e.g.
1247 ;; From: joe@y.z (Joe K
1249 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1252 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1253 ;; The mailbox can be removed or be replaced by white space, e.g.
1254 ;; From: "Joe User"{space}{tab}
1256 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1257 ;; where {space} and {tab} represent the Ascii space and tab characters.
1258 ;; We want to match the results of any of these manglings.
1259 ;; The following regexp rejects names whose first characters are
1260 ;; obviously bogus, but after that anything goes.
1261 "\\([^\0-\b\n-\r\^?].*\\)? "
1263 ;; The time the message was sent.
1264 "\\([^\0-\r \^?]+\\) +" ; day of the week
1265 "\\([^\0-\r \^?]+\\) +" ; month
1266 "\\([0-3]?[0-9]\\) +" ; day of month
1267 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1269 ;; Perhaps a time zone, specified by an abbreviation, or by a
1274 " \\([0-9][0-9]+\\) *"
1276 ;; On some systems the time zone can appear after the year, too.
1280 "\\(remote from .*\\)?"
1283 "Regexp matching the delimiter of messages in UNIX mail format.")
1285 (defvar message-unsent-separator
1286 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1287 "^ *---+ +Returned message +---+ *$\\|"
1288 "^Start of returned message$\\|"
1289 "^ *---+ +Original message +---+ *$\\|"
1290 "^ *--+ +begin message +--+ *$\\|"
1291 "^ *---+ +Original message follows +---+ *$\\|"
1292 "^ *---+ +Undelivered message follows +---+ *$\\|"
1293 "^|? *---+ +Message text follows: +---+ *|?$")
1294 "A regexp that matches the separator before the text of a failed message.")
1296 (defvar message-header-format-alist
1298 (To . message-fill-address)
1299 (Cc . message-fill-address)
1310 (References . message-shorten-references)
1312 "Alist used for formatting headers.")
1314 (defvar message-options nil
1315 "Some saved answers when sending message.")
1317 (defvar message-send-mail-real-function nil
1318 "Internal send mail function.")
1321 (autoload 'message-setup-toolbar "messagexmas")
1322 (autoload 'mh-new-draft-name "mh-comp")
1323 (autoload 'mh-send-letter "mh-comp")
1324 (autoload 'gnus-point-at-eol "gnus-util")
1325 (autoload 'gnus-point-at-bol "gnus-util")
1326 (autoload 'gnus-output-to-rmail "gnus-util")
1327 (autoload 'gnus-output-to-mail "gnus-util")
1328 (autoload 'mail-abbrev-in-expansion-header-p "mailabbrev")
1329 (autoload 'nndraft-request-associate-buffer "nndraft")
1330 (autoload 'nndraft-request-expire-articles "nndraft")
1331 (autoload 'gnus-open-server "gnus-int")
1332 (autoload 'gnus-request-post "gnus-int")
1333 (autoload 'gnus-copy-article-buffer "gnus-msg")
1334 (autoload 'gnus-alive-p "gnus-util")
1335 (autoload 'gnus-server-string "gnus")
1336 (autoload 'gnus-group-name-charset "gnus-group")
1337 (autoload 'rmail-output "rmailout")
1338 (autoload 'mu-cite-original "mu-cite"))
1343 ;;; Utility functions.
1345 (defun message-eval-parameter (parameter)
1347 (if (symbolp parameter)
1348 (if (functionp parameter)
1354 (defsubst message-get-parameter (key &optional alist)
1356 (setq alist message-parameter-alist))
1357 (cdr (assq key alist)))
1359 (defmacro message-get-parameter-with-eval (key &optional alist)
1360 `(message-eval-parameter (message-get-parameter ,key ,alist)))
1362 (defmacro message-y-or-n-p (question show &rest text)
1363 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1364 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1366 (defmacro message-delete-line (&optional n)
1367 "Delete the current line (and the next N lines)."
1368 `(delete-region (progn (beginning-of-line) (point))
1369 (progn (forward-line ,(or n 1)) (point))))
1371 (defun message-unquote-tokens (elems)
1372 "Remove double quotes (\") from strings in list ELEMS."
1373 (mapcar (lambda (item)
1374 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1375 (setq item (concat (match-string 1 item)
1376 (match-string 2 item))))
1380 (defun message-tokenize-header (header &optional separator)
1381 "Split HEADER into a list of header elements.
1382 SEPARATOR is a string of characters to be used as separators. \",\"
1383 is used by default."
1386 (let ((regexp (format "[%s]+" (or separator ",")))
1391 (message-set-work-buffer)
1393 (goto-char (point-min))
1398 (cond ((and (> (point) beg)
1400 (and (looking-at regexp)
1403 (push (buffer-substring beg (point)) elems)
1404 (setq beg (match-end 0)))
1405 ((eq (char-after) ?\")
1406 (setq quoted (not quoted)))
1407 ((and (eq (char-after) ?\()
1410 ((and (eq (char-after) ?\))
1413 (nreverse elems)))))
1415 (defun message-mail-file-mbox-p (file)
1416 "Say whether FILE looks like a Unix mbox file."
1417 (when (and (file-exists-p file)
1418 (file-readable-p file)
1419 (file-regular-p file))
1421 (nnheader-insert-file-contents file)
1422 (goto-char (point-min))
1423 (looking-at message-unix-mail-delimiter))))
1425 (defun message-fetch-field (header &optional not-all)
1426 "The same as `mail-fetch-field', only remove all newlines."
1427 (let* ((inhibit-point-motion-hooks t)
1428 (case-fold-search t)
1429 (value (mail-fetch-field header nil (not not-all))))
1431 (while (string-match "\n[\t ]+" value)
1432 (setq value (replace-match " " t t value)))
1433 (set-text-properties 0 (length value) nil value)
1436 (defun message-narrow-to-field ()
1437 "Narrow the buffer to the header on the current line."
1443 (if (re-search-forward "^[^ \n\t]" nil t)
1448 (goto-char (point-min)))
1450 (defun message-add-header (&rest headers)
1451 "Add the HEADERS to the message header, skipping those already present."
1454 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1455 (error "Invalid header `%s'" (car headers)))
1456 (setq hclean (match-string 1 (car headers)))
1458 (message-narrow-to-headers)
1459 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1460 (goto-char (point-max))
1461 (if (string-match "\n$" (car headers))
1462 (insert (car headers))
1463 (insert (car headers) ?\n)))))
1464 (setq headers (cdr headers))))
1467 (defun message-fetch-reply-field (header)
1468 "Fetch field HEADER from the message we're replying to."
1469 (let ((buffer (message-eval-parameter message-reply-buffer)))
1471 (buffer-name buffer))
1474 (message-fetch-field header)))))
1476 (defun message-set-work-buffer ()
1477 (if (get-buffer " *message work*")
1479 (set-buffer " *message work*")
1481 (set-buffer (get-buffer-create " *message work*"))
1482 (kill-all-local-variables)))
1484 (defun message-functionp (form)
1485 "Return non-nil if FORM is funcallable."
1486 (or (and (symbolp form) (fboundp form))
1487 (and (listp form) (eq (car form) 'lambda))
1488 (byte-code-function-p form)))
1490 (defun message-strip-list-identifiers (subject)
1491 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1492 (require 'gnus-sum) ; for gnus-list-identifiers
1493 (let ((regexp (if (stringp gnus-list-identifiers)
1494 gnus-list-identifiers
1495 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1496 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1497 " *\\)\\)+\\(Re: +\\)?\\)") subject)
1498 (concat (substring subject 0 (match-beginning 1))
1499 (or (match-string 3 subject)
1500 (match-string 5 subject))
1505 (defun message-strip-subject-re (subject)
1506 "Remove \"Re:\" from subject lines in string SUBJECT."
1507 (if (string-match message-subject-re-regexp subject)
1508 (substring subject (match-end 0))
1511 (defun message-remove-header (header &optional is-regexp first reverse)
1512 "Remove HEADER in the narrowed buffer.
1513 If IS-REGEXP, HEADER is a regular expression.
1514 If FIRST, only remove the first instance of the header.
1515 Return the number of headers removed."
1516 (goto-char (point-min))
1517 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
1519 (case-fold-search t)
1521 (while (and (not (eobp))
1524 (not (looking-at regexp))
1525 (looking-at regexp))
1532 ;; There might be a continuation header, so we have to search
1533 ;; until we find a new non-continuation line.
1536 (if (re-search-forward "^[^ \t]" nil t)
1537 (goto-char (match-beginning 0))
1540 (if (re-search-forward "^[^ \t]" nil t)
1541 (goto-char (match-beginning 0))
1542 (goto-char (point-max)))))
1545 (defun message-remove-first-header (header)
1546 "Remove the first instance of HEADER if there is more than one."
1548 (regexp (concat "^" (regexp-quote header) ":")))
1550 (goto-char (point-min))
1551 (while (re-search-forward regexp nil t)
1554 (message-remove-header header nil t)
1557 (defun message-narrow-to-headers ()
1558 "Narrow the buffer to the head of the message."
1561 (goto-char (point-min))
1562 (if (re-search-forward
1563 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1566 (goto-char (point-min)))
1568 (defun message-narrow-to-head-1 ()
1569 "Like `message-narrow-to-head'. Don't widen."
1571 (goto-char (point-min))
1572 (if (search-forward "\n\n" nil 1)
1575 (goto-char (point-min)))
1577 (defun message-narrow-to-head ()
1578 "Narrow the buffer to the head of the message.
1579 Point is left at the beginning of the narrowed-to region."
1581 (message-narrow-to-head-1))
1583 (defun message-narrow-to-headers-or-head ()
1584 "Narrow the buffer to the head of the message."
1587 (goto-char (point-min))
1590 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1591 (match-beginning 0))
1592 ((search-forward "\n\n" nil t)
1596 (goto-char (point-min)))
1598 (defun message-news-p ()
1599 "Say whether the current buffer contains a news message."
1600 (and (not message-this-is-mail)
1601 (or message-this-is-news
1604 (message-narrow-to-headers)
1605 (and (message-fetch-field "newsgroups")
1606 (not (message-fetch-field "posted-to"))))))))
1608 (defun message-mail-p ()
1609 "Say whether the current buffer contains a mail message."
1610 (and (not message-this-is-news)
1611 (or message-this-is-mail
1614 (message-narrow-to-headers)
1615 (or (message-fetch-field "to")
1616 (message-fetch-field "cc")
1617 (message-fetch-field "bcc")))))))
1619 (defun message-next-header ()
1620 "Go to the beginning of the next header."
1622 (or (eobp) (forward-char 1))
1623 (not (if (re-search-forward "^[^ \t]" nil t)
1625 (goto-char (point-max)))))
1627 (defun message-sort-headers-1 ()
1628 "Sort the buffer as headers using `message-rank' text props."
1629 (goto-char (point-min))
1632 nil 'message-next-header
1634 (message-next-header)
1638 (or (get-text-property (point) 'message-rank)
1641 (defun message-sort-headers ()
1642 "Sort the headers of the current message according to `message-header-format-alist'."
1646 (let ((max (1+ (length message-header-format-alist)))
1648 (message-narrow-to-headers)
1649 (while (re-search-forward "^[^ \n]+:" nil t)
1651 (match-beginning 0) (1+ (match-beginning 0))
1653 (if (setq rank (length (memq (assq (intern (buffer-substring
1655 (1- (match-end 0))))
1656 message-header-format-alist)
1657 message-header-format-alist)))
1660 (message-sort-headers-1))))
1670 (defvar message-mode-map nil)
1672 (unless message-mode-map
1673 (setq message-mode-map (make-keymap))
1674 (set-keymap-parent message-mode-map text-mode-map)
1675 (define-key message-mode-map "\C-c?" 'describe-mode)
1677 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
1678 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
1679 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
1680 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
1681 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
1682 ;; (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
1683 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-mail-reply-to)
1684 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
1685 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
1686 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
1687 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
1688 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
1689 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
1690 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
1691 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
1692 (define-key message-mode-map "\C-c\C-fc" 'message-goto-mail-copies-to)
1694 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
1695 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
1697 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
1698 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
1699 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
1700 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
1701 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
1702 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
1703 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
1704 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
1706 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
1707 (define-key message-mode-map "\C-c\C-s" 'message-send)
1708 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
1709 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
1711 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
1712 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
1713 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
1714 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
1715 ;;(define-key message-mode-map "\M-q" 'message-fill-paragraph)
1717 (define-key message-mode-map "\t" 'message-tab)
1718 (define-key message-mode-map "\M-;" 'comment-region)
1720 (define-key message-mode-map "\C-x\C-s" 'message-save-drafts)
1721 (define-key message-mode-map "\C-xk" 'message-mimic-kill-buffer))
1724 message-mode-menu message-mode-map "Message Menu."
1726 ["Sort Headers" message-sort-headers t]
1727 ["Yank Original" message-yank-original t]
1728 ["Fill Yanked Message" message-fill-yanked-message t]
1729 ["Insert Signature" message-insert-signature t]
1730 ["Caesar (rot13) Message" message-caesar-buffer-body t]
1731 ["Caesar (rot13) Region" message-caesar-region (mark t)]
1732 ["Elide Region" message-elide-region (mark t)]
1733 ["Delete Outside Region" message-delete-not-region (mark t)]
1734 ["Kill To Signature" message-kill-to-signature t]
1735 ["Newline and Reformat" message-newline-and-reformat t]
1736 ["Rename buffer" message-rename-buffer t]
1737 ["Spellcheck" ispell-message
1738 ,@(if (featurep 'xemacs) '(t)
1739 '(:help "Spellcheck this message"))]
1740 ["Attach file as MIME" mime-edit-insert-file
1741 ,@(if (featurep 'xemacs) '(t)
1742 '(:help "Attach a file at point"))]
1744 ["Send Message" message-send-and-exit
1745 ,@(if (featurep 'xemacs) '(t)
1746 '(:help "Send this message"))]
1747 ["Abort Message" message-dont-send
1748 ,@(if (featurep 'xemacs) '(t)
1749 '(:help "File this draft message and exit"))]
1750 ["Kill Message" message-kill-buffer
1751 ,@(if (featurep 'xemacs) '(t)
1752 '(:help "Delete this message without sending"))]))
1755 message-mode-field-menu message-mode-map ""
1757 ["Fetch To" message-insert-to t]
1758 ["Fetch Newsgroups" message-insert-newsgroups t]
1760 ["To" message-goto-to t]
1761 ["Subject" message-goto-subject t]
1762 ["Cc" message-goto-cc t]
1763 ["Reply-To" message-goto-reply-to t]
1764 ["Mail-Reply-To" message-goto-mail-reply-to t]
1765 ["Mail-Followup-To" message-goto-mail-followup-to t]
1766 ["Mail-Copies-To" message-goto-mail-copies-to t]
1767 ["Summary" message-goto-summary t]
1768 ["Keywords" message-goto-keywords t]
1769 ["Newsgroups" message-goto-newsgroups t]
1770 ["Followup-To" message-goto-followup-to t]
1771 ["Distribution" message-goto-distribution t]
1772 ["Body" message-goto-body t]
1773 ["Signature" message-goto-signature t]))
1775 (defvar message-tool-bar-map nil)
1778 (defvar facemenu-add-face-function)
1779 (defvar facemenu-remove-face-function))
1782 (define-derived-mode message-mode text-mode "Message"
1783 "Major mode for editing mail and news to be sent.
1784 Like Text Mode but with these additional commands:\\<message-mode-map>
1785 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
1786 C-c C-d Postpone sending the message C-c C-k Kill the message
1787 C-c C-f move to a header field (and create it if there isn't):
1788 C-c C-f C-t move to To C-c C-f C-s move to Subject
1789 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1790 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1791 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1792 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1793 C-c C-f C-m move to Mail-Followup-To
1794 C-c C-f C-f move to Followup-To
1795 C-c C-f c move to Mail-Copies-To
1796 C-c C-t `message-insert-to' (add a To header to a news followup)
1797 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
1798 C-c C-b `message-goto-body' (move to beginning of message text).
1799 C-c C-i `message-goto-signature' (move to the beginning of the signature).
1800 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
1801 C-c C-y `message-yank-original' (insert current message, if any).
1802 C-c C-q `message-fill-yanked-message' (fill what was yanked).
1803 C-c C-e `message-elide-region' (elide the text between point and mark).
1804 C-c C-v `message-delete-not-region' (remove the text outside the region).
1805 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
1806 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
1807 M-RET `message-newline-and-reformat' (break the line and reformat)."
1808 (set (make-local-variable 'message-reply-buffer) nil)
1809 (make-local-variable 'message-send-actions)
1810 (make-local-variable 'message-exit-actions)
1811 (make-local-variable 'message-kill-actions)
1812 (make-local-variable 'message-postpone-actions)
1813 (make-local-variable 'message-draft-article)
1814 (setq buffer-offer-save t)
1815 (set (make-local-variable 'facemenu-add-face-function)
1817 (let ((face-fun (cdr (assq face message-face-alist))))
1819 (funcall face-fun (point) end)
1820 (error "Face %s not configured for %s mode" face mode-name)))
1822 (set (make-local-variable 'facemenu-remove-face-function) t)
1823 (set (make-local-variable 'message-reply-headers) nil)
1824 (make-local-variable 'message-user-agent)
1825 (make-local-variable 'message-post-method)
1826 (set (make-local-variable 'message-sent-message-via) nil)
1827 (set (make-local-variable 'message-checksum) nil)
1828 (make-local-variable 'message-parameter-alist)
1829 (setq message-parameter-alist
1830 (copy-sequence message-startup-parameter-alist))
1831 (message-setup-fill-variables)
1832 ;; Allow using comment commands to add/remove quoting.
1833 (set (make-local-variable 'comment-start) message-yank-prefix)
1834 (if (featurep 'xemacs)
1835 (message-setup-toolbar)
1836 (set (make-local-variable 'font-lock-defaults)
1837 '(message-font-lock-keywords t))
1838 (if (boundp 'tool-bar-map)
1839 (set (make-local-variable 'tool-bar-map) (message-tool-bar-map))))
1840 (easy-menu-add message-mode-menu message-mode-map)
1841 (easy-menu-add message-mode-field-menu message-mode-map)
1842 ;; Allow mail alias things.
1843 (when (eq message-mail-alias-type 'abbrev)
1844 (if (fboundp 'mail-abbrevs-setup)
1845 (mail-abbrevs-setup)
1846 (mail-aliases-setup)))
1847 (message-set-auto-save-file-name)
1848 (set (make-local-variable 'indent-tabs-mode) nil)) ;No tabs for indentation.
1850 (defun message-setup-fill-variables ()
1851 "Setup message fill variables."
1852 (set (make-local-variable 'fill-paragraph-function)
1853 'message-fill-paragraph)
1854 (make-local-variable 'paragraph-separate)
1855 (make-local-variable 'paragraph-start)
1856 (make-local-variable 'adaptive-fill-regexp)
1857 (unless (boundp 'adaptive-fill-first-line-regexp)
1858 (setq adaptive-fill-first-line-regexp nil))
1859 (make-local-variable 'adaptive-fill-first-line-regexp)
1860 (make-local-variable 'auto-fill-inhibit-regexp)
1861 (let ((quote-prefix-regexp
1862 ;; User should change message-cite-prefix-regexp if
1863 ;; message-yank-prefix is set to an abnormal value.
1864 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
1865 (setq paragraph-start
1867 (regexp-quote mail-header-separator) "$\\|"
1868 "[ \t]*$\\|" ; blank lines
1869 "-- $\\|" ; signature delimiter
1870 "---+$\\|" ; delimiters for forwarded messages
1871 page-delimiter "$\\|" ; spoiler warnings
1872 ".*wrote:$\\|" ; attribution lines
1873 quote-prefix-regexp "$")) ; empty lines in quoted text
1874 (setq paragraph-separate paragraph-start)
1875 (setq adaptive-fill-regexp
1876 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
1877 (setq adaptive-fill-first-line-regexp
1878 (concat quote-prefix-regexp "\\|"
1879 adaptive-fill-first-line-regexp))
1880 (setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")))
1885 ;;; Message mode commands
1888 ;;; Movement commands
1890 (defun message-goto-to ()
1891 "Move point to the To header."
1893 (message-position-on-field "To"))
1895 (defun message-goto-subject ()
1896 "Move point to the Subject header."
1898 (message-position-on-field "Subject"))
1900 (defun message-goto-cc ()
1901 "Move point to the Cc header."
1903 (message-position-on-field "Cc" "To"))
1905 (defun message-goto-bcc ()
1906 "Move point to the Bcc header."
1908 (message-position-on-field "Bcc" "Cc" "To"))
1910 (defun message-goto-fcc ()
1911 "Move point to the Fcc header."
1913 (message-position-on-field "Fcc" "To" "Newsgroups"))
1915 (defun message-goto-reply-to ()
1916 "Move point to the Reply-To header."
1918 (message-position-on-field "Reply-To" "Subject"))
1920 (defun message-goto-mail-reply-to ()
1921 "Move point to the Mail-Reply-To header."
1923 (message-position-on-field "Mail-Reply-To" "Subject"))
1925 (defun message-goto-mail-followup-to ()
1926 "Move point to the Mail-Followup-To header. If the header is newly created
1927 and To field contains only one address, the address is inserted in default."
1929 (unless (message-position-on-field "Mail-Followup-To" "Subject")
1930 (let ((start (point))
1933 (message-narrow-to-headers)
1934 (setq addresses (split-string (mail-strip-quoted-names
1935 (or (std11-fetch-field "to") ""))
1937 (when (eq 1 (length addresses))
1939 (insert (car addresses))
1940 (goto-char start))))))
1942 (defun message-goto-mail-copies-to ()
1943 "Move point to the Mail-Copies-To header. If the header is newly created,
1944 a string \"never\" is inserted in default."
1946 (unless (message-position-on-field "Mail-Copies-To" "Subject")
1950 (defun message-goto-newsgroups ()
1951 "Move point to the Newsgroups header."
1953 (message-position-on-field "Newsgroups"))
1955 (defun message-goto-distribution ()
1956 "Move point to the Distribution header."
1958 (message-position-on-field "Distribution"))
1960 (defun message-goto-followup-to ()
1961 "Move point to the Followup-To header."
1963 (message-position-on-field "Followup-To" "Newsgroups"))
1965 (defun message-goto-keywords ()
1966 "Move point to the Keywords header."
1968 (message-position-on-field "Keywords" "Subject"))
1970 (defun message-goto-summary ()
1971 "Move point to the Summary header."
1973 (message-position-on-field "Summary" "Subject"))
1975 (defun message-goto-body (&optional interactivep)
1976 "Move point to the beginning of the message body."
1977 (interactive (list t))
1978 (when (and interactivep
1979 (looking-at "[ \t]*\n"))
1981 (goto-char (point-min))
1982 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
1983 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
1985 (defun message-goto-eoh ()
1986 "Move point to the end of the headers."
1991 (defun message-goto-signature ()
1992 "Move point to the beginning of the message signature.
1993 If there is no signature in the article, go to the end and
1996 (goto-char (point-min))
1997 (if (re-search-forward message-signature-separator nil t)
1999 (goto-char (point-max))
2004 (defun message-insert-to (&optional force)
2005 "Insert a To header that points to the author of the article being replied to.
2006 If the original author requested not to be sent mail, the function signals
2008 With the prefix argument FORCE, insert the header anyway."
2010 (let ((co (message-fetch-reply-field "mail-copies-to")))
2011 (when (and (null force)
2013 (or (equal (downcase co) "never")
2014 (equal (downcase co) "nobody")))
2015 (error "The user has requested not to have copies sent via mail")))
2016 (when (and (message-position-on-field "To")
2017 (mail-fetch-field "to")
2018 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
2020 (insert (or (message-fetch-reply-field "mail-reply-to")
2021 (message-fetch-reply-field "reply-to")
2022 (message-fetch-reply-field "from") "")))
2024 (defun message-widen-reply ()
2025 "Widen the reply to include maximum recipients."
2028 (and message-reply-buffer
2029 (buffer-name message-reply-buffer)
2031 (set-buffer message-reply-buffer)
2032 (message-get-reply-headers t)))))
2035 (message-narrow-to-headers)
2036 (dolist (elem follow-to)
2037 (message-remove-header (symbol-name (car elem)))
2038 (goto-char (point-min))
2039 (insert (symbol-name (car elem)) ": "
2040 (cdr elem) "\n"))))))
2042 (defun message-insert-newsgroups ()
2043 "Insert the Newsgroups header from the article being replied to."
2045 (when (and (message-position-on-field "Newsgroups")
2046 (mail-fetch-field "newsgroups")
2047 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
2049 (insert (or (message-fetch-reply-field "newsgroups") "")))
2053 ;;; Various commands
2055 (defun message-delete-not-region (beg end)
2056 "Delete everything in the body of the current message outside of the region."
2061 ;; snarf citation prefix, if appropriate
2062 (unless (eq (point) (progn (beginning-of-line) (point)))
2063 (when (looking-at message-cite-prefix-regexp)
2064 (setq citeprefix (match-string 0))))
2066 (delete-region (point) (if (not (message-goto-signature))
2072 (delete-region beg (progn (message-goto-body)
2076 (insert citeprefix))))
2077 (when (message-goto-signature)
2080 (defun message-kill-to-signature ()
2081 "Deletes all text up to the signature."
2083 (let ((point (point)))
2084 (message-goto-signature)
2087 (kill-region point (point))
2091 (defun message-newline-and-reformat (&optional arg not-break)
2092 "Insert four newlines, and then reformat if inside quoted text.
2093 Prefix arg means justify as well."
2094 (interactive (list (if current-prefix-arg 'full)))
2095 (let (quoted point beg end leading-space bolp)
2096 (setq point (point))
2099 (setq bolp (= beg point))
2100 ;; Find first line of the paragraph.
2102 (while (and (not (eobp))
2103 (not (looking-at message-cite-prefix-regexp))
2104 (looking-at paragraph-start))
2107 (when (looking-at message-cite-prefix-regexp)
2108 (setq quoted (match-string 0))
2109 (goto-char (match-end 0))
2110 (looking-at "[ \t]*")
2111 (setq leading-space (match-string 0)))
2115 (< (- point beg) (length quoted)))
2116 ;; break inside the cite prefix.
2122 (while (and (not (eobp))
2123 (not (looking-at paragraph-separate))
2124 (looking-at message-cite-prefix-regexp)
2125 (equal quoted (match-string 0)))
2126 (goto-char (match-end 0))
2127 (looking-at "[ \t]*")
2128 (if (> (length leading-space) (length (match-string 0)))
2129 (setq leading-space (match-string 0)))
2133 (while (and (if (bobp) nil (forward-line -1) t)
2134 (not (looking-at paragraph-start))
2135 (looking-at message-cite-prefix-regexp)
2136 (equal quoted (match-string 0)))
2138 (goto-char (match-end 0))
2139 (looking-at "[ \t]*")
2140 (if (> (length leading-space) (length (match-string 0)))
2141 (setq leading-space (match-string 0)))))
2142 (while (and (not (eobp))
2143 (not (looking-at paragraph-separate))
2144 (not (looking-at message-cite-prefix-regexp)))
2148 (while (and (if (bobp) nil (forward-line -1) t)
2149 (not (looking-at paragraph-start))
2150 (not (looking-at message-cite-prefix-regexp)))
2151 (setq beg (point))))
2154 (narrow-to-region beg end)
2160 (setq point (point))
2162 (delete-region (point) (re-search-forward "[ \t]*"))
2163 (when (and quoted (not bolp))
2164 (insert quoted leading-space)))
2166 (let* ((adaptive-fill-regexp
2167 (regexp-quote (concat quoted leading-space)))
2168 (adaptive-fill-first-line-regexp
2169 adaptive-fill-regexp ))
2170 (fill-paragraph arg))
2171 (fill-paragraph arg))
2172 (if point (goto-char point)))))
2174 (defun message-fill-paragraph (&optional arg)
2175 "Like `fill-paragraph'."
2176 (interactive (list (if current-prefix-arg 'full)))
2177 (message-newline-and-reformat arg t)
2180 (defun message-insert-signature (&optional force)
2181 "Insert a signature. See documentation for variable `message-signature'."
2182 (interactive (list 0))
2185 ((and (null message-signature)
2188 (goto-char (point-max))
2189 (not (re-search-backward message-signature-separator nil t))))
2190 ((and (null message-signature)
2193 ((message-functionp message-signature)
2194 (funcall message-signature))
2195 ((listp message-signature)
2196 (eval message-signature))
2197 (t message-signature)))
2199 (cond ((stringp signature)
2201 ((and (eq t signature)
2202 message-signature-file
2203 (file-exists-p message-signature-file))
2206 (goto-char (point-max))
2207 ;; Insert the signature.
2211 (if (eq signature t)
2212 (insert-file-contents message-signature-file)
2214 (goto-char (point-max))
2215 (or (bolp) (insert "\n")))))
2217 (defun message-elide-region (b e)
2218 "Elide the text in the region.
2219 An ellipsis (from `message-elide-ellipsis') will be inserted where the
2223 (insert message-elide-ellipsis))
2225 (defvar message-caesar-translation-table nil)
2227 (defun message-caesar-region (b e &optional n)
2228 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
2231 (min (point) (or (mark t) (point)))
2232 (max (point) (or (mark t) (point)))
2233 (when current-prefix-arg
2234 (prefix-numeric-value current-prefix-arg))))
2236 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
2237 (unless (or (zerop n) ; no action needed for a rot of 0
2238 (= b e)) ; no region to rotate
2239 ;; We build the table, if necessary.
2240 (when (or (not message-caesar-translation-table)
2241 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
2242 (setq message-caesar-translation-table
2243 (message-make-caesar-translation-table n)))
2244 (translate-region b e message-caesar-translation-table)))
2246 (defun message-make-caesar-translation-table (n)
2247 "Create a rot table with offset N."
2249 (table (make-string 256 0)))
2250 (while (< (incf i) 256)
2253 (substring table 0 ?A)
2254 (substring table (+ ?A n) (+ ?A n (- 26 n)))
2255 (substring table ?A (+ ?A n))
2256 (substring table (+ ?A 26) ?a)
2257 (substring table (+ ?a n) (+ ?a n (- 26 n)))
2258 (substring table ?a (+ ?a n))
2259 (substring table (+ ?a 26) 255))))
2261 (defun message-caesar-buffer-body (&optional rotnum)
2262 "Caesar rotate all letters in the current buffer by 13 places.
2263 Used to encode/decode possibly offensive messages (commonly in rec.humor).
2264 With prefix arg, specifies the number of places to rotate each letter forward.
2265 Mail and USENET news headers are not rotated."
2266 (interactive (if current-prefix-arg
2267 (list (prefix-numeric-value current-prefix-arg))
2271 (when (message-goto-body)
2272 (narrow-to-region (point) (point-max)))
2273 (message-caesar-region (point-min) (point-max) rotnum))))
2275 (defun message-pipe-buffer-body (program)
2276 "Pipe the message body in the current buffer through PROGRAM."
2279 (when (message-goto-body)
2280 (narrow-to-region (point) (point-max)))
2281 (shell-command-on-region
2282 (point-min) (point-max) program nil t))))
2284 (defun message-rename-buffer (&optional enter-string)
2285 "Rename the *message* buffer to \"*message* RECIPIENT\".
2286 If the function is run with a prefix, it will ask for a new buffer
2287 name, rather than giving an automatic name."
2288 (interactive "Pbuffer name: ")
2291 (goto-char (point-min))
2292 (narrow-to-region (point)
2293 (search-forward mail-header-separator nil 'end))
2295 (if (message-news-p) (message-fetch-field "Newsgroups")
2296 (message-fetch-field "To"))
2299 (if (string-match "," mail-to)
2300 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
2302 (name-default (concat "*message* " mail-trimmed-to))
2303 (name (if enter-string
2304 (read-string "New buffer name: " name-default)
2306 (rename-buffer name t)))))
2308 (defun message-fill-yanked-message (&optional justifyp)
2309 "Fill the paragraphs of a message yanked into this one.
2310 Numeric argument means justify as well."
2313 (goto-char (point-min))
2314 (search-forward (concat "\n" mail-header-separator "\n") nil t)
2315 (let ((fill-prefix message-yank-prefix))
2316 (fill-individual-paragraphs (point) (point-max) justifyp))))
2318 (defun message-indent-citation ()
2319 "Modify text just inserted from a message to be cited.
2320 The inserted text should be the region.
2321 When this function returns, the region is again around the modified text.
2323 Normally, indent each nonblank line `message-indentation-spaces' spaces.
2324 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
2325 (let ((start (point)))
2326 ;; Remove unwanted headers.
2327 (when message-ignored-cited-headers
2332 (if (search-forward "\n\n" nil t)
2335 (message-remove-header message-ignored-cited-headers t)
2336 (when (= (point-min) (point-max))
2337 (setq all-removed t))
2338 (goto-char (point-max)))
2342 ;; Delete blank lines at the start of the buffer.
2343 (while (and (point-min)
2346 (message-delete-line))
2347 ;; Delete blank lines at the end of the buffer.
2348 (goto-char (point-max))
2351 (while (and (zerop (forward-line -1))
2353 (message-delete-line))
2354 ;; Do the indentation.
2355 (if (null message-yank-prefix)
2356 (indent-rigidly start (mark t) message-indentation-spaces)
2359 (while (< (point) (mark t))
2360 (if (looking-at message-cite-prefix-regexp)
2361 (insert message-yank-cited-prefix)
2362 (insert message-yank-prefix))
2366 (defun message-list-references (refs-list &rest refs-strs)
2367 "Add `Message-ID's which appear in REFS-STRS but not in REFS-LIST,
2369 (let (refs ref id saved-id)
2370 (when (and refs-list
2371 (integerp message-list-references-add-position))
2372 (let ((pos message-list-references-add-position))
2373 (while (and refs-list
2375 (push (pop refs-list) saved-id)
2376 (setq pos (1- pos)))))
2378 (when (setq refs (pop refs-strs))
2379 (setq refs (std11-parse-msg-ids (std11-lexical-analyze refs)))
2381 (when (eq (car (setq ref (pop refs))) 'msg-id)
2382 (setq id (concat "<" (mapconcat 'cdr (cdr ref) "") ">"))
2383 (or (member id refs-list)
2384 (member id saved-id)
2385 (push id refs-list))))))
2387 (push (pop saved-id) refs-list))
2390 (defvar gnus-article-copy)
2391 (defun message-yank-original (&optional arg)
2392 "Insert the message being replied to, if any.
2393 Puts point before the text and mark after.
2394 Normally indents each nonblank line ARG spaces (default 3). However,
2395 if `message-yank-prefix' is non-nil, insert that prefix on each line.
2397 This function uses `message-cite-function' to do the actual citing.
2399 Just \\[universal-argument] as argument means don't indent, insert no
2400 prefix, and don't delete any headers.
2402 In addition, if `message-yank-add-new-references' is non-nil and this
2403 command is called interactively, new IDs from the yanked article will
2404 be added to \"References\" field.
2405 \(See also `message-yank-add-new-references'.)"
2407 (let ((modified (buffer-modified-p))
2408 (buffer (message-eval-parameter message-reply-buffer))
2411 message-cite-function)
2412 (delete-windows-on buffer t)
2413 (insert-buffer buffer) ; mark will be set at the end of article.
2417 ;; Add new IDs to References field.
2418 (when (and message-yank-add-new-references (interactive-p))
2421 (message-narrow-to-headers)
2422 (setq refs (message-list-references
2424 (message-fetch-field "References")))
2426 (narrow-to-region start end)
2427 (std11-narrow-to-header)
2428 (when (setq refs (message-list-references
2430 (unless (eq message-yank-add-new-references
2432 (or (message-fetch-field "References")
2433 (message-fetch-field "In-Reply-To")))
2434 (message-fetch-field "Message-ID")))
2436 (message-narrow-to-headers)
2437 (goto-char (point-min))
2438 (let ((case-fold-search t))
2439 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
2441 (goto-char (point-max))))
2443 (list (or (assq 'References message-header-format-alist)
2444 '(References . message-fill-references)))
2445 (list (cons 'References
2446 (mapconcat 'identity (nreverse refs) " "))))
2447 (backward-delete-char 1)))))
2450 (if (and message-suspend-font-lock-when-citing
2451 (boundp 'font-lock-mode)
2452 (symbol-value 'font-lock-mode))
2457 (funcall message-cite-function))
2459 (funcall message-cite-function)))
2460 (message-exchange-point-and-mark)
2464 (setq message-checksum (message-checksum))))))
2466 (defun message-yank-buffer (buffer)
2467 "Insert BUFFER into the current buffer and quote it."
2468 (interactive "bYank buffer: ")
2469 (let ((message-reply-buffer buffer))
2470 (save-window-excursion
2471 (message-yank-original))))
2473 (defun message-buffers ()
2474 "Return a list of active message buffers."
2477 (dolist (buffer (buffer-list t))
2479 (when (and (eq major-mode 'message-mode)
2480 (null message-sent-message-via))
2481 (push (buffer-name buffer) buffers))))
2482 (nreverse buffers)))
2484 (defun message-cite-original-without-signature ()
2485 "Cite function in the standard Message manner."
2486 (let ((start (point))
2489 (when message-indent-citation-function
2490 (if (listp message-indent-citation-function)
2491 message-indent-citation-function
2492 (list message-indent-citation-function))))
2493 (message-reply-headers (or message-reply-headers
2494 (make-mail-header))))
2495 (mail-header-set-from message-reply-headers
2499 (if (search-forward "\n\n" nil t)
2502 (or (message-fetch-field "from")
2507 (when (re-search-backward message-signature-separator start t)
2508 ;; Also peel off any blank lines before the signature.
2510 (while (looking-at "^[ \t]*$")
2513 (delete-region (point) end)
2514 (unless (search-backward "\n\n" start t)
2515 ;; Insert a blank line if it is peeled off.
2519 (funcall (pop functions)))
2520 (when message-citation-line-function
2523 (funcall message-citation-line-function))))
2525 (eval-when-compile (defvar mail-citation-hook)) ;Compiler directive
2526 (defun message-cite-original ()
2527 "Cite function in the standard Message manner."
2528 (if (and (boundp 'mail-citation-hook)
2530 (run-hooks 'mail-citation-hook)
2531 (let ((start (point))
2534 (when message-indent-citation-function
2535 (if (listp message-indent-citation-function)
2536 message-indent-citation-function
2537 (list message-indent-citation-function))))
2538 (message-reply-headers (or message-reply-headers
2539 (make-mail-header))))
2540 (mail-header-set-from message-reply-headers
2544 (if (search-forward "\n\n" nil t)
2547 (or (message-fetch-field "from")
2551 (funcall (pop functions)))
2552 (when message-citation-line-function
2555 (funcall message-citation-line-function)))))
2557 (defun message-insert-citation-line ()
2558 "Insert a simple citation line."
2559 (when message-reply-headers
2560 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
2562 (defun message-position-on-field (header &rest afters)
2563 (let ((case-fold-search t))
2566 (goto-char (point-min))
2569 (concat "^" (regexp-quote mail-header-separator) "$"))
2570 (match-beginning 0)))
2571 (goto-char (point-min))
2572 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
2574 (re-search-forward "^[^ \t]" nil 'move)
2576 (skip-chars-backward "\n")
2579 (not (re-search-forward
2580 (concat "^" (regexp-quote (car afters)) ":")
2584 (re-search-forward "^[^ \t]" nil 'move)
2585 (beginning-of-line))
2586 (insert header ": \n")
2590 (defun message-remove-signature ()
2591 "Remove the signature from the text between point and mark.
2592 The text will also be indented the normal way."
2594 (let ((start (point))
2596 (if (not (re-search-forward message-signature-separator (mark t) t))
2597 ;; No signature here, so we just indent the cited text.
2598 (message-indent-citation)
2599 ;; Find the last non-empty line.
2601 (while (looking-at "[ \t]*$")
2604 (setq mark (set-marker (make-marker) (point)))
2606 (message-indent-citation)
2607 ;; Enable undoing the deletion.
2609 (delete-region mark (mark t))
2610 (set-marker mark nil)))))
2615 ;;; Sending messages
2618 ;; Avoid byte-compile warning.
2619 (defvar message-encoding-buffer nil)
2620 (defvar message-edit-buffer nil)
2621 (defvar message-mime-mode nil)
2623 (defun message-send-and-exit (&optional arg)
2624 "Send message like `message-send', then, if no errors, exit from mail buffer."
2626 (let ((buf (current-buffer))
2627 (actions message-exit-actions)
2628 (frame (selected-frame))
2629 (org-frame message-original-frame))
2630 (when (and (message-send arg)
2632 (if message-kill-buffer-on-exit
2635 (when (eq buf (current-buffer))
2636 (message-bury buf)))
2637 (message-do-actions actions)
2638 (message-delete-frame frame org-frame)
2641 (defun message-dont-send ()
2642 "Don't send the message you have been editing."
2644 (message-save-drafts)
2645 (let ((actions message-postpone-actions)
2646 (frame (selected-frame))
2647 (org-frame message-original-frame))
2648 (message-bury (current-buffer))
2649 (message-do-actions actions)
2650 (message-delete-frame frame org-frame)))
2652 (defun message-kill-buffer ()
2653 "Kill the current buffer."
2655 (when (or (not (buffer-modified-p))
2656 (eq t message-kill-buffer-query-function)
2657 (funcall message-kill-buffer-query-function
2658 "The buffer modified; kill anyway? "))
2659 (let ((actions message-kill-actions)
2660 (frame (selected-frame))
2661 (org-frame message-original-frame))
2662 (setq buffer-file-name nil)
2663 (kill-buffer (current-buffer))
2664 (message-do-actions actions)
2665 (message-delete-frame frame org-frame)))
2668 (defun message-mimic-kill-buffer ()
2669 "Kill the current buffer with query."
2671 (unless (eq 'message-mode major-mode)
2672 (error "%s must be invoked from a message buffer." this-command))
2673 (let ((command this-command)
2674 (bufname (read-buffer (format "Kill buffer: (default %s) "
2676 (if (or (not bufname)
2677 (string-equal bufname "")
2678 (string-equal bufname (buffer-name)))
2679 (message-kill-buffer)
2680 (message "%s must be invoked only for the current buffer." command))))
2682 (defun message-delete-frame (frame org-frame)
2683 "Delete frame for editing message."
2684 (when (and (or (static-if (featurep 'xemacs)
2685 (device-on-window-system-p)
2687 (>= emacs-major-version 20))
2688 (or (and (eq message-delete-frame-on-exit t)
2689 (select-frame frame)
2690 (or (eq frame org-frame)
2692 (y-or-n-p "Delete this frame?")
2694 (and (eq message-delete-frame-on-exit 'ask)
2695 (select-frame frame)
2697 (y-or-n-p "Delete this frame?")
2699 (delete-frame frame)))
2701 (defun message-bury (buffer)
2702 "Bury this mail BUFFER."
2703 (let ((newbuf (other-buffer buffer)))
2704 (bury-buffer buffer)
2705 (if (and (fboundp 'frame-parameters)
2706 (cdr (assq 'dedicated (frame-parameters)))
2707 (not (null (delq (selected-frame) (visible-frame-list)))))
2708 (delete-frame (selected-frame))
2709 (switch-to-buffer newbuf))))
2711 (defun message-send (&optional arg)
2712 "Send the message in the current buffer.
2713 If `message-interactive' is non-nil, wait for success indication or
2714 error messages, and inform user.
2715 Otherwise any failure is reported in a message back to the user from
2717 The usage of ARG is defined by the instance that called Message.
2718 It should typically alter the sending method in some way or other."
2721 (when (or (buffer-modified-p)
2722 (message-check-element 'unchanged)
2723 (y-or-n-p "No changes in the buffer; really send? "))
2724 ;; Make it possible to undo the coming changes.
2726 (let ((inhibit-read-only t))
2727 (put-text-property (point-min) (point-max) 'read-only nil))
2728 (run-hooks 'message-send-hook)
2729 (message-fix-before-sending)
2730 (message message-sending-message)
2731 (let ((message-encoding-buffer
2732 (message-generate-new-buffer-clone-locals " message encoding"))
2733 (message-edit-buffer (current-buffer))
2734 (message-mime-mode mime-edit-mode-flag)
2735 (alist message-send-method-alist)
2738 (message-options message-options))
2739 (message-options-set-recipient)
2741 (set-buffer message-encoding-buffer)
2743 ;; Avoid copying text props.
2744 (let (message-invisibles)
2746 (with-current-buffer message-edit-buffer
2747 (setq message-invisibles (message-find-invisible-regions))
2748 (buffer-substring-no-properties (point-min) (point-max))))
2749 ;; Inherit the invisible property of texts to make MIME-Edit
2750 ;; find the MIME part boundaries.
2751 (dolist (region message-invisibles)
2752 (put-text-property (car region) (cdr region) 'invisible t)))
2753 (funcall message-encode-function)
2755 (setq elem (pop alist)))
2756 (when (funcall (cadr elem))
2757 (when (and (or (not (memq (car elem)
2758 message-sent-message-via))
2759 (if (or (message-gnksa-enable-p 'multiple-copies)
2760 (not (eq (car elem) 'news)))
2763 "Already sent message via %s; resend? "
2765 (error "Denied posting -- multiple copies")))
2766 (setq success (funcall (caddr elem) arg)))
2768 (unless (or sent (not success))
2769 (error "No methods specified to send by"))
2771 (when (and success sent)
2774 (run-hooks 'message-sent-hook))
2775 (message "Sending...done")
2776 ;; Mark the buffer as unmodified and delete auto-save.
2777 (set-buffer-modified-p nil)
2778 (delete-auto-save-file-if-necessary t)
2779 (message-disassociate-draft)
2780 ;; Delete other mail buffers and stuff.
2781 (message-do-send-housekeeping)
2782 (message-do-actions message-send-actions)
2785 (kill-buffer message-encoding-buffer)))))
2787 (defun message-send-via-mail (arg)
2788 "Send the current message via mail."
2789 (message-send-mail arg))
2791 (defun message-send-via-news (arg)
2792 "Send the current message via news."
2793 (message-send-news arg))
2795 (defmacro message-check (type &rest forms)
2796 "Eval FORMS if TYPE is to be checked."
2797 `(or (message-check-element ,type)
2801 (put 'message-check 'lisp-indent-function 1)
2802 (put 'message-check 'edebug-form-spec '(form body))
2804 ;; This function will be used by MIME-Edit when inserting invisible parts.
2805 (defun message-invisible-region (start end)
2806 (if (featurep 'xemacs)
2809 (eq (following-char) ?\n))
2810 (setq start (1+ start)))
2812 (goto-char (1- end))
2813 (eq (following-char) ?\n))
2814 (setq end (1- end))))
2815 (put-text-property start end 'invisible t)
2816 (if (eq 'message-mode major-mode)
2817 (put-text-property start end 'message-invisible t)))
2819 (eval-after-load "invisible"
2820 '(defalias 'invisible-region 'message-invisible-region))
2822 (defun message-find-invisible-regions ()
2823 "Find invisible texts with the property `message-invisible' and
2824 return a list of points."
2828 (while (setq from (text-property-any to (point-max)
2829 'message-invisible t))
2830 (setq to (or (text-property-not-all from (point-max)
2831 'message-invisible t)
2833 (push (cons from to) regions))
2836 (defun message-fix-before-sending ()
2837 "Do various things to make the message nice before sending it."
2838 ;; Make sure there's a newline at the end of the message.
2840 (goto-char (point-max))
2843 ;; Expose all invisible text with the property `message-invisible'.
2844 ;; We should believe that the things might be created by MIME-Edit.
2845 (let ((message-invisibles (message-find-invisible-regions)))
2846 (dolist (region message-invisibles)
2847 (put-text-property (car region) (cdr region) 'invisible nil))
2848 ;; Expose all invisible text.
2849 (message-check 'invisible-text
2850 (when (text-property-any (point-min) (point-max) 'invisible t)
2851 (put-text-property (point-min) (point-max) 'invisible nil)
2852 (unless (yes-or-no-p
2853 "Invisible text found and made visible; continue posting? ")
2854 (error "Invisible text found and made visible"))))
2855 ;; Hide again all text with the property `message-invisible'.
2856 ;; It is needed to make MIME-Edit find the MIME part boundaries.
2857 (dolist (region message-invisibles)
2858 (put-text-property (car region) (cdr region) 'invisible t))))
2860 (defun message-add-action (action &rest types)
2861 "Add ACTION to be performed when doing an exit of type TYPES."
2864 (set (setq var (intern (format "message-%s-actions" (pop types))))
2865 (nconc (symbol-value var) (list action))))))
2867 (defun message-do-actions (actions)
2868 "Perform all actions in ACTIONS."
2869 ;; Now perform actions on successful sending.
2873 ;; A simple function.
2874 ((message-functionp (car actions))
2875 (funcall (car actions)))
2876 ;; Something to be evaled.
2878 (eval (car actions)))))
2881 (defsubst message-maybe-split-and-send-mail ()
2882 "Split a message if necessary, and send it via mail.
2883 Returns nil if sending succeeded, returns any string if sending failed.
2884 This sub function is for exclusive use of `message-send-mail'."
2885 (let ((mime-edit-split-ignored-field-regexp
2886 mime-edit-split-ignored-field-regexp)
2887 (case-fold-search t)
2889 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
2890 (setq mime-edit-split-ignored-field-regexp
2891 (concat (substring mime-edit-split-ignored-field-regexp
2892 0 (match-beginning 0))
2893 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
2894 "_so_don't_rape_it!"
2895 (substring mime-edit-split-ignored-field-regexp
2899 (catch 'message-sending-mail-failure
2900 (mime-edit-maybe-split-and-send
2905 (std11-narrow-to-header mail-header-separator)
2906 (goto-char (point-min))
2907 (when (re-search-forward "^Message-ID:" nil t)
2908 (delete-region (match-end 0) (std11-field-end))
2909 (insert " " (message-make-message-id))))
2911 (funcall (or message-send-mail-real-function
2912 message-send-mail-function))
2914 (throw 'message-sending-mail-failure err))))))
2918 (funcall (or message-send-mail-real-function
2919 message-send-mail-function))
2923 (if (eq 'error (car failure))
2925 (prin1-to-string failure)))))
2927 (defun message-send-mail-partially ()
2928 "Send mail as message/partial."
2929 ;; replace the header delimiter with a blank line
2930 (goto-char (point-min))
2932 (concat "^" (regexp-quote mail-header-separator) "\n"))
2933 (replace-match "\n")
2934 (run-hooks 'message-send-mail-hook)
2935 (let ((p (goto-char (point-min)))
2936 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
2937 (curbuf (current-buffer))
2938 (id (message-make-message-id)) (n 1)
2939 plist total header required-mail-headers)
2941 (if (< (point-max) (+ p message-send-mail-partially-limit))
2942 (goto-char (point-max))
2943 (goto-char (+ p message-send-mail-partially-limit))
2945 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
2948 (setq total (length plist))
2949 (push (point-max) plist)
2950 (setq plist (nreverse plist))
2953 (setq p (pop plist))
2956 (copy-to-buffer tembuf p (car plist))
2958 (goto-char (point-min))
2961 (goto-char (point-min))
2962 (narrow-to-region (point) (point))
2965 (setq header (buffer-substring (point-min) (point)))
2966 (goto-char (point-min))
2967 (narrow-to-region (point) (point))
2969 (message-remove-header "Mime-Version")
2970 (message-remove-header "Content-Type")
2971 (message-remove-header "Content-Transfer-Encoding")
2972 (message-remove-header "Message-ID")
2973 (message-remove-header "Lines")
2974 (goto-char (point-max))
2975 (insert "Mime-Version: 1.0\n")
2976 (setq header (buffer-substring (point-min) (point-max))))
2977 (goto-char (point-max))
2978 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n"
2980 (let ((mail-header-separator ""))
2981 (when (memq 'Message-ID message-required-mail-headers)
2982 (insert "Message-ID: " (message-make-message-id) "\n"))
2983 (when (memq 'Lines message-required-mail-headers)
2984 (let ((mail-header-separator ""))
2985 (insert "Lines: " (message-make-lines) "\n")))
2986 (message-goto-subject)
2988 (insert (format " (%d/%d)" n total))
2989 (goto-char (point-max))
2992 (mm-with-unibyte-current-buffer
2993 (funcall (or message-send-mail-real-function
2994 message-send-mail-function))))
2996 (setq p (pop plist))
2998 (kill-buffer tembuf))))
3000 (defun message-send-mail (&optional arg)
3001 (require 'mail-utils)
3002 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
3003 (case-fold-search nil)
3004 (news (message-news-p))
3005 (message-this-is-mail t)
3008 (message-narrow-to-headers)
3009 ;; Insert some headers.
3010 (let ((message-deletable-headers
3011 (if news nil message-deletable-headers)))
3012 (message-generate-headers message-required-mail-headers))
3013 ;; Let the user do all of the above.
3014 (run-hooks 'message-header-hook))
3015 (if (not (message-check-mail-syntax))
3023 (insert-buffer message-encoding-buffer)
3024 ;; Remove some headers.
3026 (message-narrow-to-headers)
3027 ;; We Semi-gnus people have no use for it.
3028 ;; ;; We (re)generate the Lines header.
3029 ;; (when (memq 'Lines message-required-mail-headers)
3030 ;; (message-generate-headers '(Lines)))
3031 ;; Remove some headers.
3032 (message-remove-header message-ignored-mail-headers t))
3033 (goto-char (point-max))
3034 ;; require one newline at the end.
3035 (or (= (preceding-char) ?\n)
3039 (message-narrow-to-headers)
3041 (or (message-fetch-field "cc")
3042 (message-fetch-field "to"))
3043 (let ((ct (mime-read-Content-Type)))
3045 (and (eq 'text (cdr (assq 'type ct)))
3046 (eq 'plain (cdr (assq 'subtype ct))))))))
3047 (message-insert-courtesy-copy))
3048 (setq failure (message-maybe-split-and-send-mail)))
3049 (kill-buffer tembuf))
3050 (set-buffer message-edit-buffer)
3053 (message "Couldn't send message via mail: %s" failure)
3055 (push 'mail message-sent-message-via)))))
3057 (defun message-send-mail-with-sendmail ()
3058 "Send off the prepared buffer with sendmail."
3059 (let ((errbuf (if message-interactive
3060 (message-generate-new-buffer-clone-locals
3063 resend-to-addresses delimline)
3064 (let ((case-fold-search t))
3066 (message-narrow-to-headers)
3067 (setq resend-to-addresses (message-fetch-field "resent-to")))
3068 ;; Change header-delimiter to be what sendmail expects.
3069 (goto-char (point-min))
3071 (concat "^" (regexp-quote mail-header-separator) "\n"))
3072 (replace-match "\n")
3074 (setq delimline (point-marker))
3075 (run-hooks 'message-send-mail-hook)
3076 ;; Insert an extra newline if we need it to work around
3077 ;; Sun's bug that swallows newlines.
3078 (goto-char (1+ delimline))
3079 (when (eval message-mailer-swallows-blank-line)
3081 (when message-interactive
3085 (let ((default-directory "/"))
3087 (apply 'call-process-region
3088 (append (list (point-min) (point-max)
3089 (if (boundp 'sendmail-program)
3091 "/usr/lib/sendmail")
3092 nil errbuf nil "-oi")
3093 ;; Always specify who from,
3094 ;; since some systems have broken sendmails.
3095 ;; But some systems are more broken with -f, so
3096 ;; we'll let users override this.
3097 (if (null message-sendmail-f-is-evil)
3098 (list "-f" (message-make-address)))
3099 ;; These mean "report errors by mail"
3100 ;; and "deliver in background".
3101 (if (null message-interactive) '("-oem" "-odb"))
3102 ;; Get the addresses from the message
3103 ;; unless this is a resend.
3104 ;; We must not do that for a resend
3105 ;; because we would find the original addresses.
3106 ;; For a resend, include the specific addresses.
3107 (if resend-to-addresses
3108 (list resend-to-addresses)
3110 (when message-interactive
3113 (goto-char (point-min))
3114 (while (re-search-forward "\n\n* *" nil t)
3115 (replace-match "; "))
3116 (if (not (zerop (buffer-size)))
3117 (error "Sending...failed to %s"
3118 (buffer-substring (point-min) (point-max)))))
3119 (when (bufferp errbuf)
3120 (kill-buffer errbuf)))))
3122 (defun message-send-mail-with-qmail ()
3123 "Pass the prepared message buffer to qmail-inject.
3124 Refer to the documentation for the variable `message-send-mail-function'
3125 to find out how to use this."
3126 ;; replace the header delimiter with a blank line
3127 (goto-char (point-min))
3129 (concat "^" (regexp-quote mail-header-separator) "\n"))
3130 (replace-match "\n")
3132 (run-hooks 'message-send-mail-hook)
3137 'call-process-region 1 (point-max) message-qmail-inject-program
3139 ;; qmail-inject's default behaviour is to look for addresses on the
3140 ;; command line; if there're none, it scans the headers.
3141 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
3143 ;; in general, ALL of qmail-inject's defaults are perfect for simply
3144 ;; reading a formatted (i. e., at least a To: or Resent-To header)
3145 ;; message from stdin.
3147 ;; qmail also has the advantage of not having been raped by
3148 ;; various vendors, so we don't have to allow for that, either --
3149 ;; compare this with message-send-mail-with-sendmail and weep
3150 ;; for sendmail's lost innocence.
3152 ;; all this is way cool coz it lets us keep the arguments entirely
3153 ;; free for -inject-arguments -- a big win for the user and for us
3154 ;; since we don't have to play that double-guessing game and the user
3155 ;; gets full control (no gestapo'ish -f's, for instance). --sj
3156 message-qmail-inject-args))
3157 ;; qmail-inject doesn't say anything on it's stdout/stderr,
3158 ;; we have to look at the retval instead
3160 (100 (error "qmail-inject reported permanent failure"))
3161 (111 (error "qmail-inject reported transient failure"))
3162 ;; should never happen
3163 (t (error "qmail-inject reported unknown failure"))))
3165 (defun message-send-mail-with-mh ()
3166 "Send the prepared message buffer with mh."
3167 (let ((mh-previous-window-config nil)
3168 (name (mh-new-draft-name)))
3169 (setq buffer-file-name name)
3170 ;; MH wants to generate these headers itself.
3171 (when message-mh-deletable-headers
3172 (let ((headers message-mh-deletable-headers))
3174 (goto-char (point-min))
3175 (and (re-search-forward
3176 (concat "^" (symbol-name (car headers)) ": *") nil t)
3177 (message-delete-line))
3179 (run-hooks 'message-send-mail-hook)
3180 ;; Pass it on to mh.
3183 (defun message-send-mail-with-smtp ()
3184 "Send off the prepared buffer with SMTP."
3185 (require 'smtp) ; XXX
3186 (let ((case-fold-search t)
3189 (message-narrow-to-headers)
3191 ;; XXX: Should be replaced by better one.
3192 (smtp-deduce-address-list (current-buffer)
3193 (point-min) (point-max)))
3194 ;; Remove BCC lines.
3195 (message-remove-header "bcc"))
3196 ;; replace the header delimiter with a blank line.
3197 (goto-char (point-min))
3199 (concat "^" (regexp-quote mail-header-separator) "\n"))
3200 (replace-match "\n")
3202 (run-hooks 'message-send-mail-hook)
3204 (static-if (fboundp 'smtp-send-buffer)
3205 (smtp-send-buffer user-mail-address recipients
3207 (let ((result (smtp-via-smtp user-mail-address recipients
3209 (unless (eq result t)
3210 (error "Sending failed; %s" result))))
3211 (error "Sending failed; no recipients"))))
3213 (defsubst message-maybe-split-and-send-news (method)
3214 "Split a message if necessary, and send it via news.
3215 Returns nil if sending succeeded, returns t if sending failed.
3216 This sub function is for exclusive use of `message-send-news'."
3217 (let ((mime-edit-split-ignored-field-regexp
3218 mime-edit-split-ignored-field-regexp)
3219 (case-fold-search t))
3220 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
3221 (setq mime-edit-split-ignored-field-regexp
3222 (concat (substring mime-edit-split-ignored-field-regexp
3223 0 (match-beginning 0))
3224 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
3225 "_so_don't_rape_it!"
3226 (substring mime-edit-split-ignored-field-regexp
3229 (catch 'message-sending-news-failure
3230 (mime-edit-maybe-split-and-send
3235 (std11-narrow-to-header mail-header-separator)
3236 (goto-char (point-min))
3237 (when (re-search-forward "^Message-ID:" nil t)
3238 (delete-region (match-end 0) (std11-field-end))
3239 (insert " " (message-make-message-id))))
3240 (unless (funcall message-send-news-function method)
3241 (throw 'message-sending-news-failure t)))))
3243 (not (funcall message-send-news-function method)))))
3245 (defun message-send-news (&optional arg)
3246 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
3247 (case-fold-search nil)
3248 (method (if (message-functionp message-post-method)
3249 (funcall message-post-method arg)
3250 message-post-method))
3251 (group-name-charset (gnus-group-name-charset method ""))
3252 (message-syntax-checks
3254 (cons '(existing-newsgroups . disabled)
3255 message-syntax-checks)
3256 message-syntax-checks))
3257 (message-this-is-news t)
3260 (message-narrow-to-headers)
3261 ;; Insert some headers.
3262 (message-generate-headers message-required-news-headers)
3263 ;; Let the user do all of the above.
3264 (run-hooks 'message-header-hook))
3265 (when group-name-charset
3266 (setq message-syntax-checks
3267 (cons '(valid-newsgroups . disabled)
3268 message-syntax-checks)))
3269 (message-cleanup-headers)
3270 (if (not (message-check-news-syntax))
3275 (buffer-disable-undo)
3277 (insert-buffer message-encoding-buffer)
3278 ;; Remove some headers.
3280 (message-narrow-to-headers)
3281 ;; We Semi-gnus people have no use for it.
3282 ;; ;; We (re)generate the Lines header.
3283 ;; (when (memq 'Lines message-required-mail-headers)
3284 ;; (message-generate-headers '(Lines)))
3285 ;; Remove some headers.
3286 (message-remove-header message-ignored-news-headers t))
3287 (goto-char (point-max))
3288 ;; require one newline at the end.
3289 (or (= (preceding-char) ?\n)
3291 (setq result (message-maybe-split-and-send-news method)))
3292 (kill-buffer tembuf))
3293 (set-buffer message-edit-buffer)
3296 (message "Couldn't send message via news: %s"
3297 (nnheader-get-report (car method)))
3299 (push 'news message-sent-message-via)))))
3301 ;; 1997-09-29 by MORIOKA Tomohiko
3302 (defun message-send-news-with-gnus (method)
3303 (let ((case-fold-search t))
3304 ;; Remove the delimiter.
3305 (goto-char (point-min))
3307 (concat "^" (regexp-quote mail-header-separator) "\n"))
3308 (replace-match "\n")
3310 (run-hooks 'message-send-news-hook)
3311 (gnus-open-server method)
3312 (message "Sending news with %s..." (gnus-server-string method))
3313 (gnus-request-post method)
3317 ;;; Header generation & syntax checking.
3320 (defun message-check-element (type)
3321 "Return non-nil if this TYPE is not to be checked."
3322 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
3324 (let ((able (assq type message-syntax-checks)))
3326 (eq (cdr able) 'disabled)))))
3328 (defun message-check-news-syntax ()
3329 "Check the syntax of the message."
3334 ;; We narrow to the headers and check them first.
3337 (message-narrow-to-headers)
3338 (message-check-news-header-syntax)))
3341 (set-buffer message-edit-buffer)
3342 (message-check-news-body-syntax))))))
3344 (defun message-check-news-header-syntax ()
3346 ;; Check Newsgroups header.
3347 (message-check 'newsgroups
3348 (let ((group (message-fetch-field "newsgroups")))
3351 (not (string-match "\\`[ \t]*\\'" group)))
3354 "The newsgroups field is empty or missing. Posting is denied.")))))
3355 ;; Check the Subject header.
3356 (message-check 'subject
3357 (let* ((case-fold-search t)
3358 (subject (message-fetch-field "subject")))
3361 (not (string-match "\\`[ \t]*\\'" subject)))
3364 "The subject field is empty or missing. Posting is denied.")))))
3365 ;; Check for commands in Subject.
3366 (message-check 'subject-cmsg
3367 (if (string-match "^cmsg " (message-fetch-field "subject"))
3369 "The control code \"cmsg\" is in the subject. Really post? ")
3371 ;; Check for multiple identical headers.
3372 (message-check 'multiple-headers
3374 (while (and (not found)
3375 (re-search-forward "^[^ \t:]+: " nil t))
3377 (or (re-search-forward
3382 (match-beginning 0) (- (match-end 0) 2))))
3387 (y-or-n-p (format "Multiple %s headers. Really post? " found))
3389 ;; Check for Version and Sendsys.
3390 (message-check 'sendsys
3391 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
3393 (format "The article contains a %s command. Really post? "
3394 (buffer-substring (match-beginning 0)
3395 (1- (match-end 0)))))
3397 ;; See whether we can shorten Followup-To.
3398 (message-check 'shorten-followup-to
3399 (let ((newsgroups (message-fetch-field "newsgroups"))
3400 (followup-to (message-fetch-field "followup-to"))
3402 (when (and newsgroups
3403 (string-match "," newsgroups)
3408 (setq to (completing-read
3409 "Followups to: (default all groups) "
3410 (mapcar (lambda (g) (list g))
3412 (message-tokenize-header
3414 (goto-char (point-min))
3415 (insert "Followup-To: " to "\n"))
3417 ;; Check "Shoot me".
3418 (message-check 'shoot
3419 (if (re-search-forward
3420 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
3421 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
3423 ;; Check for Approved.
3424 (message-check 'approved
3425 (if (re-search-forward "^Approved:" nil t)
3426 (y-or-n-p "The article contains an Approved header. Really post? ")
3428 ;; Check the Message-ID header.
3429 (message-check 'message-id
3430 (let* ((case-fold-search t)
3431 (message-id (message-fetch-field "message-id" t)))
3432 (or (not message-id)
3433 ;; Is there an @ in the ID?
3434 (and (string-match "@" message-id)
3435 ;; Is there a dot in the ID?
3436 (string-match "@[^.]*\\." message-id)
3437 ;; Does the ID end with a dot?
3438 (not (string-match "\\.>" message-id)))
3440 (format "The Message-ID looks strange: \"%s\". Really post? "
3442 ;; Check the Newsgroups & Followup-To headers.
3443 (message-check 'existing-newsgroups
3444 (let* ((case-fold-search t)
3445 (newsgroups (message-fetch-field "newsgroups"))
3446 (followup-to (message-fetch-field "followup-to"))
3447 (groups (message-tokenize-header
3449 (concat newsgroups "," followup-to)
3452 (mapcar '(lambda (n) (gnus-group-real-name n))
3453 (gnus-groups-from-server
3454 (cond ((equal gnus-post-method 'current)
3455 gnus-current-select-method)
3456 (gnus-post-method gnus-post-method)
3457 (t gnus-select-method)))))
3460 (unless (or (equal (car groups) "poster")
3461 (member (car groups) known-groups))
3462 (push (car groups) errors))
3465 ;; Gnus is not running.
3466 ((or (not (and (boundp 'gnus-active-hashtb)
3467 gnus-active-hashtb))
3468 (not (boundp 'gnus-read-active-file)))
3470 ;; We don't have all the group names.
3471 ((and (or (not gnus-read-active-file)
3472 (eq gnus-read-active-file 'some))
3476 "Really post to %s possibly unknown group%s: %s? "
3477 (if (= (length errors) 1) "this" "these")
3478 (if (= (length errors) 1) "" "s")
3479 (mapconcat 'identity errors ", "))))
3480 ;; There were no errors.
3483 ;; There are unknown groups.
3487 "Really post to %s unknown group%s: %s? "
3488 (if (= (length errors) 1) "this" "these")
3489 (if (= (length errors) 1) "" "s")
3490 (mapconcat 'identity errors ", ")))))))
3491 ;; Check the Newsgroups & Followup-To headers for syntax errors.
3492 (message-check 'valid-newsgroups
3493 (let ((case-fold-search t)
3494 (headers '("Newsgroups" "Followup-To"))
3496 (while (and headers (not error))
3497 (when (setq header (mail-fetch-field (car headers)))
3501 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
3506 (not (string-match "\\.\\'\\|\\.\\." g)))
3507 (message-tokenize-header header ","))))
3514 (format "The %s header looks odd: \"%s\". Really post? "
3515 (car headers) header)))))
3516 (message-check 'repeated-newsgroups
3517 (let ((case-fold-search t)
3518 (headers '("Newsgroups" "Followup-To"))
3519 header error groups group)
3522 (when (setq header (mail-fetch-field (pop headers)))
3523 (setq groups (message-tokenize-header header ","))
3524 (while (setq group (pop groups))
3525 (when (member group groups)
3531 (format "Group %s is repeated in headers. Really post? " error)))))
3532 ;; Check the From header.
3533 (message-check 'from
3534 (let* ((case-fold-search t)
3535 (from (message-fetch-field "from"))
3539 (message "There is no From line. Posting is denied.")
3541 ((or (not (string-match
3543 (setq ad (nth 1 (mail-extract-address-components
3544 from))))) ;larsi@ifi
3545 (string-match "\\.\\." ad) ;larsi@ifi..uio
3546 (string-match "@\\." ad) ;larsi@.ifi.uio
3547 (string-match "\\.$" ad) ;larsi@ifi.uio.
3548 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
3549 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
3551 "Denied posting -- the From looks strange: \"%s\"." from)
3554 ;; Check the Reply-To header.
3555 (message-check 'reply-to
3556 (let* ((case-fold-search t)
3557 (reply-to (message-fetch-field "reply-to"))
3562 ((string-match "," reply-to)
3564 (format "Multiple Reply-To addresses: \"%s\". Really post? "
3566 ((or (not (string-match
3568 (setq ad (nth 1 (mail-extract-address-components
3569 reply-to))))) ;larsi@ifi
3570 (string-match "\\.\\." ad) ;larsi@ifi..uio
3571 (string-match "@\\." ad) ;larsi@.ifi.uio
3572 (string-match "\\.$" ad) ;larsi@ifi.uio.
3573 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
3574 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
3577 "The Reply-To looks strange: \"%s\". Really post? "
3581 (defun message-check-news-body-syntax ()
3583 ;; Check for long lines.
3584 (message-check 'long-lines
3585 (goto-char (point-min))
3587 (concat "^" (regexp-quote mail-header-separator) "$"))
3591 mime-edit-tag-regexp)
3594 (< (- (point) p) 80)))
3595 (zerop (forward-line 1))))
3599 "You have lines longer than 79 characters. Really post? ")))
3600 ;; Check whether the article is empty.
3601 (message-check 'empty
3602 (goto-char (point-min))
3604 (concat "^" (regexp-quote mail-header-separator) "$"))
3607 (goto-char (point-max))
3608 (re-search-backward message-signature-separator nil t)
3610 (or (re-search-backward "[^ \n\t]" b t)
3611 (if (message-gnksa-enable-p 'empty-article)
3612 (y-or-n-p "Empty article. Really post? ")
3613 (message "Denied posting -- Empty article.")
3615 ;; Check for control characters.
3616 (message-check 'control-chars
3617 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
3619 "The article contains control characters. Really post? ")
3621 ;; Check 8bit characters.
3622 (message-check '8bit
3623 (message-check-8bit))
3624 ;; Check excessive size.
3625 (message-check 'size
3626 (if (> (buffer-size) 60000)
3628 (format "The article is %d octets long. Really post? "
3631 ;; Check whether any new text has been added.
3632 (message-check 'new-text
3634 (not message-checksum)
3635 (not (eq (message-checksum) message-checksum))
3636 (if (message-gnksa-enable-p 'quoted-text-only)
3638 "It looks like no new text has been added. Really post? ")
3639 (message "Denied posting -- no new text has been added.")
3641 ;; Check the length of the signature.
3642 (message-check 'signature
3643 (goto-char (point-max))
3644 (if (> (count-lines (point) (point-max)) 5)
3647 "Your .sig is %d lines; it should be max 4. Really post? "
3648 (1- (count-lines (point) (point-max)))))
3650 ;; Ensure that text follows last quoted portion.
3651 (message-check 'quoting-style
3652 (goto-char (point-max))
3653 (let ((no-problem t))
3654 (when (search-backward-regexp "^>[^\n]*\n" nil t)
3655 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
3658 (if (message-gnksa-enable-p 'quoted-text-only)
3659 (y-or-n-p "Your text should follow quoted text. Really post? ")
3661 (goto-char (point-min))
3663 (concat "^" (regexp-quote mail-header-separator) "$"))
3664 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
3665 (y-or-n-p "Your text should follow quoted text. Really post? ")
3666 (message "Denied posting -- only quoted text.")
3669 (defun message-check-mail-syntax ()
3670 "Check the syntax of the message."
3675 ;; We narrow to the headers and check them first.
3678 (message-narrow-to-headers)
3679 (message-check-mail-header-syntax)))
3682 (set-buffer message-edit-buffer)
3683 (message-check-mail-body-syntax))))))
3685 (defun message-check-mail-header-syntax ()
3688 (defun message-check-mail-body-syntax ()
3690 ;; Check 8bit characters.
3691 (message-check '8bit
3692 (message-check-8bit)
3695 (defun message-check-8bit ()
3696 "Check the article contains 8bit characters."
3698 (set-buffer message-encoding-buffer)
3699 (message-narrow-to-headers)
3700 (let* ((case-fold-search t)
3701 (field-value (message-fetch-field "content-transfer-encoding")))
3702 (if (and field-value
3703 (member (downcase field-value) message-8bit-encoding-list))
3706 (set-buffer (get-buffer-create " message syntax"))
3708 (goto-char (point-min))
3709 (set-buffer-multibyte nil)
3710 (insert-buffer message-encoding-buffer)
3711 (goto-char (point-min))
3712 (if (re-search-forward "[^\x00-\x7f]" nil t)
3714 "The article contains 8bit characters. Really post? ")
3717 (defun message-checksum ()
3718 "Return a \"checksum\" for the current buffer."
3721 (goto-char (point-min))
3723 (concat "^" (regexp-quote mail-header-separator) "$"))
3725 (when (not (looking-at "[ \t\n]"))
3726 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
3731 (defun message-do-fcc ()
3732 "Process Fcc headers in the current buffer."
3733 (let ((case-fold-search t)
3734 (coding-system-for-write 'raw-text)
3735 (output-coding-system 'raw-text)
3739 (message-narrow-to-headers)
3740 (setq file (message-fetch-field "fcc" t)))
3742 (set-buffer (get-buffer-create " *message temp*"))
3744 (insert-buffer-substring message-encoding-buffer)
3746 (message-narrow-to-headers)
3747 (while (setq file (message-fetch-field "fcc"))
3749 (message-remove-header "fcc" nil t)))
3750 (goto-char (point-min))
3751 (when (re-search-forward
3752 (concat "^" (regexp-quote mail-header-separator) "$")
3754 (replace-match "" t t))
3755 ;; Process FCC operations.
3757 (setq file (pop list))
3758 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
3759 ;; Pipe the article to the program in question.
3760 (call-process-region (point-min) (point-max) shell-file-name
3761 nil nil nil shell-command-switch
3762 (match-string 1 file))
3763 ;; Save the article.
3764 (setq file (expand-file-name file))
3765 (unless (file-exists-p (file-name-directory file))
3766 (make-directory (file-name-directory file) t))
3767 (if (and message-fcc-handler-function
3768 (not (eq message-fcc-handler-function 'rmail-output)))
3769 (funcall message-fcc-handler-function file)
3770 (if (and (file-readable-p file) (mail-file-babyl-p file))
3771 (rmail-output file 1 nil t)
3772 (let ((mail-use-rfc822 t))
3773 (rmail-output file 1 t t))))))
3774 (kill-buffer (current-buffer))))))
3776 (defun message-output (filename)
3777 "Append this article to Unix/babyl mail file FILENAME."
3778 (if (and (file-readable-p filename)
3779 (mail-file-babyl-p filename))
3780 (gnus-output-to-rmail filename t)
3781 (gnus-output-to-mail filename t)))
3783 (defun message-cleanup-headers ()
3784 "Do various automatic cleanups of the headers."
3785 ;; Remove empty lines in the header.
3787 (message-narrow-to-headers)
3788 ;; Remove blank lines.
3789 (while (re-search-forward "^[ \t]*\n" nil t)
3790 (replace-match "" t t))
3792 ;; Correct Newsgroups and Followup-To headers: Change sequence of
3793 ;; spaces to comma and eliminate spaces around commas. Eliminate
3794 ;; embedded line breaks.
3795 (goto-char (point-min))
3796 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
3800 (if (re-search-forward "^[^ \t]" nil t)
3804 (goto-char (point-min))
3805 (while (re-search-forward "\n[ \t]+" nil t)
3806 (replace-match " " t t)) ;No line breaks (too confusing)
3807 (goto-char (point-min))
3808 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
3809 (replace-match "," t t))
3810 (goto-char (point-min))
3811 ;; Remove trailing commas.
3812 (when (re-search-forward ",+$" nil t)
3813 (replace-match "" t t))))))
3815 (defun message-make-date (&optional now)
3816 "Make a valid data header.
3817 If NOW, use that time instead."
3818 (let* ((now (or now (current-time)))
3819 (zone (nth 8 (decode-time now)))
3823 (setq zone (- zone)))
3825 ;; The day name of the %a spec is locale-specific. Pfff.
3826 (format "%s, " (capitalize (car (rassoc (nth 6 (decode-time now))
3827 parse-time-weekdays))))
3828 (format-time-string "%d" now)
3829 ;; The month name of the %b spec is locale-specific. Pfff.
3831 (capitalize (car (rassoc (nth 4 (decode-time now))
3832 parse-time-months))))
3833 (format-time-string "%Y %H:%M:%S " now)
3834 ;; We do all of this because XEmacs doesn't have the %z spec.
3835 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
3837 (defun message-make-followup-subject (subject)
3838 "Make a followup Subject."
3840 ((and (eq message-use-subject-re 'guess)
3841 (string-match message-subject-encoded-re-regexp subject))
3843 (message-use-subject-re
3844 (concat "Re: " (message-strip-subject-re subject)))
3847 (defun message-make-message-id ()
3848 "Make a unique Message-ID."
3849 (concat "<" (message-unique-id)
3850 (let ((psubject (save-excursion (message-fetch-field "subject")))
3852 (save-excursion (message-fetch-field "supersedes"))))
3854 (and message-reply-headers
3855 (mail-header-references message-reply-headers)
3856 (mail-header-subject message-reply-headers)
3859 (message-strip-subject-re
3860 (mail-header-subject message-reply-headers))
3861 (message-strip-subject-re psubject))))
3863 (string-match "_-_@" psupersedes)))
3865 "@" (message-make-fqdn) ">"))
3867 (defvar message-unique-id-char nil)
3869 ;; If you ever change this function, make sure the new version
3870 ;; cannot generate IDs that the old version could.
3871 ;; You might for example insert a "." somewhere (not next to another dot
3872 ;; or string boundary), or modify the "fsf" string.
3873 (defun message-unique-id ()
3874 ;; Don't use microseconds from (current-time), they may be unsupported.
3875 ;; Instead we use this randomly inited counter.
3876 (setq message-unique-id-char
3877 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
3878 ;; (current-time) returns 16-bit ints,
3879 ;; and 2^16*25 just fits into 4 digits i base 36.
3881 (let ((tm (current-time)))
3883 (if (memq system-type '(ms-dos emx vax-vms))
3884 (let ((user (downcase (user-login-name))))
3885 (while (string-match "[^a-z0-9_]" user)
3886 (aset user (match-beginning 0) ?_))
3888 (message-number-base36 (user-uid) -1))
3889 (message-number-base36 (+ (car tm)
3890 (lsh (% message-unique-id-char 25) 16)) 4)
3891 (message-number-base36 (+ (nth 1 tm)
3892 (lsh (/ message-unique-id-char 25) 16)) 4)
3893 ;; Append the newsreader name, because while the generated
3894 ;; ID is unique to this newsreader, other newsreaders might
3895 ;; otherwise generate the same ID via another algorithm.
3898 (defun message-number-base36 (num len)
3903 (concat (message-number-base36 (/ num 36) (1- len))
3904 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
3907 (defun message-make-organization ()
3908 "Make an Organization header."
3909 (let* ((organization
3910 (when message-user-organization
3911 (if (message-functionp message-user-organization)
3912 (funcall message-user-organization)
3913 message-user-organization))))
3915 (message-set-work-buffer)
3916 (cond ((stringp organization)
3917 (insert organization))
3918 ((and (eq t organization)
3919 message-user-organization-file
3920 (file-exists-p message-user-organization-file))
3921 (insert-file-contents message-user-organization-file)))
3922 (goto-char (point-min))
3923 (while (re-search-forward "[\t\n]+" nil t)
3924 (replace-match "" t t))
3925 (unless (zerop (buffer-size))
3928 (defun message-make-lines ()
3929 "Count the number of lines and return numeric string."
3934 (int-to-string (count-lines (point) (point-max))))))
3936 (defun message-make-in-reply-to ()
3937 "Return the In-Reply-To header for this message."
3938 (when message-reply-headers
3939 (let ((from (mail-header-from message-reply-headers))
3940 (date (mail-header-date message-reply-headers))
3941 (msg-id (mail-header-message-id message-reply-headers)))
3945 (let ((pair (std11-extract-address-components from)))
3947 (or (car pair) (cadr pair))
3949 (if (or (not date) (string= date ""))
3950 "(unknown date)" date)
3953 (defun message-make-distribution ()
3954 "Make a Distribution header."
3955 (let ((orig-distribution (message-fetch-reply-field "distribution")))
3956 (cond ((message-functionp message-distribution-function)
3957 (funcall message-distribution-function))
3958 (t orig-distribution))))
3960 (defun message-make-expires ()
3961 "Return an Expires header based on `message-expires'."
3962 (let ((current (current-time))
3963 (future (* 1.0 message-expires 60 60 24)))
3964 ;; Add the future to current.
3965 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
3966 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
3967 (message-make-date current)))
3969 (defun message-make-path ()
3971 (let ((login-name (user-login-name)))
3972 (cond ((null message-user-path)
3973 (concat (system-name) "!" login-name))
3974 ((stringp message-user-path)
3975 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
3976 (concat message-user-path "!" login-name))
3979 (defun message-make-from ()
3980 "Make a From header."
3981 (let* ((style message-from-style)
3982 (login (message-make-address))
3984 (or (and (boundp 'user-full-name)
3987 (when (string= fullname "&")
3988 (setq fullname (user-login-name)))
3990 (message-set-work-buffer)
3993 (equal fullname ""))
3995 ((or (eq style 'angles)
3996 (and (not (eq style 'parens))
3997 ;; Use angles if no quoting is needed, or if parens would
3998 ;; need quoting too.
3999 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
4000 (let ((tmp (concat fullname nil)))
4001 (while (string-match "([^()]*)" tmp)
4002 (aset tmp (match-beginning 0) ?-)
4003 (aset tmp (1- (match-end 0)) ?-))
4004 (string-match "[\\()]" tmp)))))
4006 (goto-char (point-min))
4007 ;; Look for a character that cannot appear unquoted
4008 ;; according to RFC 822.
4009 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
4010 ;; Quote fullname, escaping specials.
4011 (goto-char (point-min))
4013 (while (re-search-forward "[\"\\]" nil 1)
4014 (replace-match "\\\\\\&" t))
4016 (insert " <" login ">"))
4017 (t ; 'parens or default
4019 (let ((fullname-start (point)))
4021 (goto-char fullname-start)
4022 ;; RFC 822 says \ and nonmatching parentheses
4023 ;; must be escaped in comments.
4024 ;; Escape every instance of ()\ ...
4025 (while (re-search-forward "[()\\]" nil 1)
4026 (replace-match "\\\\\\&" t))
4027 ;; ... then undo escaping of matching parentheses,
4028 ;; including matching nested parentheses.
4029 (goto-char fullname-start)
4030 (while (re-search-forward
4031 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
4033 (replace-match "\\1(\\3)" t)
4034 (goto-char fullname-start)))
4038 (defun message-make-sender ()
4039 "Return the \"real\" user address.
4040 This function tries to ignore all user modifications, and
4041 give as trustworthy answer as possible."
4042 (concat (user-login-name) "@" (system-name)))
4044 (defun message-make-address ()
4045 "Make the address of the user."
4046 (or (message-user-mail-address)
4047 (concat (user-login-name) "@" (message-make-domain))))
4049 (defun message-user-mail-address ()
4050 "Return the pertinent part of `user-mail-address'."
4051 (when user-mail-address
4052 (if (string-match " " user-mail-address)
4053 (nth 1 (std11-extract-address-components user-mail-address))
4054 user-mail-address)))
4056 (defun message-make-fqdn ()
4057 "Return user's fully qualified domain name."
4058 (let ((system-name (system-name))
4059 (user-mail (message-user-mail-address)))
4061 ((string-match "[^.]\\.[^.]" system-name)
4062 ;; `system-name' returned the right result.
4064 ;; Try `mail-host-address'.
4065 ((and (boundp 'mail-host-address)
4066 (stringp mail-host-address)
4067 (string-match "\\." mail-host-address))
4069 ;; We try `user-mail-address' as a backup.
4071 (string-match "\\." user-mail)
4072 (string-match "@\\(.*\\)\\'" user-mail))
4073 (match-string 1 user-mail))
4074 ;; Default to this bogus thing.
4076 (concat system-name ".i-did-not-set--mail-host-address--so-shoot-me")))))
4078 (defun message-make-host-name ()
4079 "Return the name of the host."
4080 (let ((fqdn (message-make-fqdn)))
4081 (string-match "^[^.]+\\." fqdn)
4082 (substring fqdn 0 (1- (match-end 0)))))
4084 (defun message-make-domain ()
4085 "Return the domain name."
4086 (or mail-host-address
4087 (message-make-fqdn)))
4089 ;; Dummy to avoid byte-compile warning.
4090 (defvar mule-version)
4091 (defvar emacs-beta-version)
4092 (defvar xemacs-codename)
4093 (defvar gnus-inviolable-extended-version)
4095 (defun message-make-user-agent ()
4096 "Return user-agent info if the value `message-user-agent' is non-nil. If the
4097 \"User-Agent\" field has already exist, it's value will be added in the return
4099 (when message-user-agent
4101 (goto-char (point-min))
4102 (let ((case-fold-search t)
4103 user-agent start p end)
4104 (if (re-search-forward "^User-Agent:[\t ]*" nil t)
4106 (setq start (match-beginning 0)
4108 end (std11-field-end)
4109 user-agent (buffer-substring-no-properties p end))
4110 (delete-region start (1+ end))
4111 (concat message-user-agent " " user-agent))
4112 message-user-agent)))))
4114 (defun message-generate-headers (headers)
4115 "Prepare article HEADERS.
4116 Headers already prepared in the buffer are not modified."
4118 (message-narrow-to-headers)
4119 (let* ((Date (message-make-date))
4120 (Message-ID (message-make-message-id))
4121 (Organization (message-make-organization))
4122 (From (message-make-from))
4123 (Path (message-make-path))
4126 (In-Reply-To (message-make-in-reply-to))
4128 (Distribution (message-make-distribution))
4129 (Lines (message-make-lines))
4130 (User-Agent (message-make-user-agent))
4131 (Expires (message-make-expires))
4132 (case-fold-search t)
4134 ;; First we remove any old generated headers.
4135 (let ((headers message-deletable-headers))
4136 (unless (buffer-modified-p)
4137 (setq headers (delq 'Message-ID (copy-sequence headers))))
4139 (goto-char (point-min))
4140 (and (re-search-forward
4141 (concat "^" (symbol-name (car headers)) ": *") nil t)
4142 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
4143 (message-delete-line))
4145 ;; Go through all the required headers and see if they are in the
4146 ;; articles already. If they are not, or are empty, they are
4147 ;; inserted automatically - except for Subject, Newsgroups and
4150 (goto-char (point-min))
4151 (setq elem (pop headers))
4153 (if (eq (car elem) 'optional)
4154 (setq header (cdr elem))
4155 (setq header (car elem)))
4157 (when (or (not (re-search-forward
4161 (if (stringp header)
4163 (symbol-name header))))
4167 ;; The header was found. We insert a space after the
4168 ;; colon, if there is none.
4169 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
4170 ;; Find out whether the header is empty...
4171 (looking-at "[ \t]*\n[^ \t]")))
4172 ;; So we find out what value we should insert.
4175 ((and (consp elem) (eq (car elem) 'optional))
4176 ;; This is an optional header. If the cdr of this
4177 ;; is something that is nil, then we do not insert
4179 (setq header (cdr elem))
4180 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
4181 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
4183 ;; The element is a cons. Either the cdr is a
4184 ;; string to be inserted verbatim, or it is a
4185 ;; function, and we insert the value returned from
4187 (or (and (stringp (cdr elem)) (cdr elem))
4188 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
4189 ((and (boundp header) (symbol-value header))
4190 ;; The element is a symbol. We insert the value
4191 ;; of this symbol, if any.
4192 (symbol-value header))
4193 ((not (message-check-element header))
4194 ;; We couldn't generate a value for this header,
4195 ;; so we just ask the user.
4196 (read-from-minibuffer
4197 (format "Empty header for %s; enter value: " header)))))
4198 ;; Finally insert the header.
4200 (not (equal value "")))
4204 ;; This header didn't exist, so we insert it.
4205 (goto-char (point-max))
4206 (insert (if (stringp header) header (symbol-name header))
4211 ;; The value of this header was empty, so we clear
4212 ;; totally and insert the new value.
4213 (delete-region (point) (gnus-point-at-eol))
4217 ;; Add the deletable property to the headers that require it.
4218 (and (memq header message-deletable-headers)
4219 (progn (beginning-of-line) (looking-at "[^:]+: "))
4220 (add-text-properties
4221 (point) (match-end 0)
4222 '(message-deletable t face italic) (current-buffer)))))))
4223 ;; Insert new Sender if the From is strange.
4224 (let ((from (message-fetch-field "from"))
4225 (sender (message-fetch-field "sender"))
4226 (secure-sender (message-make-sender)))
4228 (not (message-check-element 'sender))
4231 (cadr (std11-extract-address-components from)))
4232 (downcase secure-sender)))
4237 (cadr (std11-extract-address-components sender)))
4238 (downcase secure-sender)))))
4239 (goto-char (point-min))
4240 ;; Rename any old Sender headers to Original-Sender.
4241 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
4243 (insert "Original-")
4244 (beginning-of-line))
4245 (when (or (message-news-p)
4246 (string-match "@.+\\.." secure-sender))
4247 (insert "Sender: " secure-sender "\n")))))))
4249 (defun message-insert-courtesy-copy ()
4250 "Insert a courtesy message in mail copies of combined messages."
4254 (message-narrow-to-headers)
4255 (when (setq newsgroups (message-fetch-field "newsgroups"))
4256 (goto-char (point-max))
4257 (insert "Posted-To: " newsgroups "\n")))
4259 (when message-courtesy-message
4261 ((string-match "%s" message-courtesy-message)
4262 (insert (format message-courtesy-message newsgroups)))
4264 (insert message-courtesy-message)))))))
4267 ;;; Setting up a message buffer
4270 (defun message-fill-address (header value)
4272 (narrow-to-region (point) (point))
4273 (insert (capitalize (symbol-name header))
4275 (if (consp value) (car value) value)
4277 (narrow-to-region (point-min) (1- (point-max)))
4279 (goto-char (point-min))
4281 (skip-chars-forward "^,\"" (point-max))
4282 (if (or (eq (char-after) ?,)
4285 (if (and (> (current-column) 78)
4289 (looking-at "[ \t]*")
4290 (replace-match "\n " t t)))
4291 (setq last (1+ (point))))
4292 (setq quoted (not quoted)))
4295 (goto-char (point-max))
4299 (defun message-fill-references (header value)
4300 (insert (capitalize (symbol-name header))
4302 (std11-fill-msg-id-list-string
4303 (if (consp value) (car value) value))
4306 (defun message-fill-header (header value)
4307 (let ((begin (point))
4310 (insert (capitalize (symbol-name header))
4312 (if (consp value) (car value) value)
4315 (narrow-to-region begin (point))
4316 (fill-region-as-paragraph begin (point))
4317 ;; Tapdance around looong Message-IDs.
4319 (when (looking-at "[ \t]*$")
4320 (message-delete-line))
4322 (re-search-forward ":" nil t)
4323 (when (looking-at "\n[ \t]+")
4324 (replace-match " " t t))
4325 (goto-char (point-max)))))
4327 (defun message-shorten-1 (list cut surplus)
4328 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
4329 (setcdr (nthcdr (- cut 2) list)
4330 (nthcdr (+ (- cut 2) surplus 1) list)))
4332 (defun message-shorten-references (header references)
4333 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
4334 If folding is disallowed, also check that the REFERENCES are less
4335 than 988 characters long, and if they are not, trim them until they are."
4342 (goto-char (point-min))
4343 ;; Cons a list of valid references.
4344 (while (re-search-forward "<[^>]+>" nil t)
4345 (push (match-string 0) refs))
4346 (setq refs (nreverse refs)
4347 count (length refs)))
4349 ;; If the list has more than MAXCOUNT elements, trim it by
4350 ;; removing the CUTth element and the required number of
4351 ;; elements that follow.
4352 (when (> count maxcount)
4353 (let ((surplus (- count maxcount)))
4354 (message-shorten-1 refs cut surplus)
4355 (decf count surplus)))
4357 ;; If folding is disallowed, make sure the total length (including
4358 ;; the spaces between) will be less than MAXSIZE characters.
4360 ;; Only disallow folding for News messages. At this point the headers
4361 ;; have not been generated, thus we use message-this-is-news directly.
4362 (when (and message-this-is-news message-cater-to-broken-inn)
4364 (totalsize (+ (apply #'+ (mapcar #'length refs))
4367 (ptr (nthcdr (1- cut) refs)))
4368 ;; Decide how many elements to cut off...
4369 (while (> totalsize maxsize)
4370 (decf totalsize (1+ (length (car ptr))))
4372 (setq ptr (cdr ptr)))
4375 (message-shorten-1 refs cut surplus))))
4377 ;; Finally, collect the references back into a string and insert
4378 ;; it into the buffer.
4379 (let ((refstring (mapconcat #'identity refs " ")))
4380 (if (and message-this-is-news message-cater-to-broken-inn)
4381 (insert (capitalize (symbol-name header)) ": "
4383 (message-fill-header header refstring)))))
4385 (defun message-position-point ()
4386 "Move point to where the user probably wants to find it."
4387 (message-narrow-to-headers)
4389 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
4390 (search-backward ":" )
4393 (if (eq (char-after) ? )
4397 (goto-char (point-max))
4400 (unless (looking-at "$")
4404 (defun message-buffer-name (type &optional to group)
4405 "Return a new (unique) buffer name based on TYPE and TO."
4407 ;; Generate a new buffer name The Message Way.
4408 ((eq message-generate-new-buffers 'unique)
4409 (generate-new-buffer-name
4413 (or (car (std11-extract-address-components to))
4416 (if (and group (not (string= group ""))) (concat " on " group) "")
4418 ;; Check whether `message-generate-new-buffers' is a function,
4419 ;; and if so, call it.
4420 ((message-functionp message-generate-new-buffers)
4421 (funcall message-generate-new-buffers type to group))
4422 ((eq message-generate-new-buffers 'unsent)
4423 (generate-new-buffer-name
4424 (concat "*unsent " type
4427 (or (car (mail-extract-address-components to))
4430 (if (and group (not (string= group ""))) (concat " on " group) "")
4432 ;; Use standard name.
4434 (format "*%s message*" type))))
4436 (defmacro message-pop-to-buffer-1 (buffer)
4438 (let (special-display-buffer-names
4439 special-display-regexps
4440 same-window-buffer-names
4441 same-window-regexps)
4442 (pop-to-buffer ,buffer))
4443 (pop-to-buffer ,buffer)))
4445 (defun message-pop-to-buffer (name)
4446 "Pop to buffer NAME, and warn if it already exists and is modified."
4447 (let ((buffer (get-buffer name))
4448 (pop-up-frames (and (or (static-if (featurep 'xemacs)
4449 (device-on-window-system-p)
4451 (>= emacs-major-version 20))
4452 message-use-multi-frames)))
4454 (buffer-name buffer))
4456 (message-pop-to-buffer-1 buffer)
4457 (when (and (buffer-modified-p)
4459 "Message already being composed; erase? ")))
4460 (error "Message being composed")))
4461 (message-pop-to-buffer-1 name))
4465 (set (make-local-variable 'message-original-frame) (selected-frame)))))
4467 (defun message-do-send-housekeeping ()
4468 "Kill old message buffers."
4469 ;; We might have sent this buffer already. Delete it from the
4471 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
4472 (while (and message-max-buffers
4474 (>= (length message-buffer-list) message-max-buffers))
4475 ;; Kill the oldest buffer -- unless it has been changed.
4476 (let ((buffer (pop message-buffer-list)))
4477 (when (and (buffer-name buffer)
4478 (not (buffer-modified-p buffer)))
4479 (kill-buffer buffer))))
4480 ;; Rename the buffer.
4481 (if message-send-rename-function
4482 (funcall message-send-rename-function)
4483 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
4485 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
4487 (let ((name (match-string 2 (buffer-name)))
4489 (if (not (or (null name)
4490 (string-equal name "mail")
4491 (string-equal name "news")))
4492 (setq name (concat "*sent " name "*"))
4493 (message-narrow-to-headers)
4494 (setq to (message-fetch-field "to"))
4495 (setq group (message-fetch-field "newsgroups"))
4499 (to (concat "*sent mail to "
4500 (or (car (mail-extract-address-components to))
4502 ((and group (not (string= group "")))
4503 (concat "*sent news on " group "*"))
4504 (t "*sent mail*"))))
4505 (unless (string-equal name (buffer-name))
4506 (rename-buffer name t)))))
4507 ;; Push the current buffer onto the list.
4508 (when message-max-buffers
4509 (setq message-buffer-list
4510 (nconc message-buffer-list (list (current-buffer))))))
4512 (defun message-mail-user-agent ()
4514 ((not message-mail-user-agent) nil)
4515 ((eq message-mail-user-agent t) mail-user-agent)
4516 (t message-mail-user-agent))))
4517 (if (memq mua '(message-user-agent gnus-user-agent))
4521 (defun message-setup (headers &optional replybuffer actions switch-function)
4522 (let ((mua (message-mail-user-agent))
4523 subject to field yank-action)
4524 (if (not (and message-this-is-mail mua))
4525 (message-setup-1 headers replybuffer actions)
4527 (setq yank-action (list 'insert-buffer replybuffer)))
4528 (setq headers (copy-sequence headers))
4529 (setq field (assq 'Subject headers))
4531 (setq subject (cdr field))
4532 (setq headers (delq field headers)))
4533 (setq field (assq 'To headers))
4535 (setq to (cdr field))
4536 (setq headers (delq field headers)))
4537 (let ((mail-user-agent mua))
4538 (compose-mail to subject
4539 (mapcar (lambda (item)
4541 (format "%s" (car item))
4544 nil switch-function yank-action actions)))))
4546 ;;;(defvar mc-modes-alist)
4547 (defun message-setup-1 (headers &optional replybuffer actions)
4548 ;;; (when (and (boundp 'mc-modes-alist)
4549 ;;; (not (assq 'message-mode mc-modes-alist)))
4550 ;;; (push '(message-mode (encrypt . mc-encrypt-message)
4551 ;;; (sign . mc-sign-message))
4552 ;;; mc-modes-alist))
4554 (setq message-send-actions actions))
4555 (setq message-reply-buffer
4556 (or (message-get-parameter 'reply-buffer)
4558 (goto-char (point-min))
4559 ;; Insert all the headers.
4562 (alist message-header-format-alist))
4564 (unless (assq (caar h) message-header-format-alist)
4565 (push (list (caar h)) alist))
4569 (delete-region (point) (progn (forward-line -1) (point)))
4570 (when message-default-headers
4571 (insert message-default-headers)
4572 (or (bolp) (insert ?\n)))
4576 (insert mail-header-separator "\n")
4580 (when (message-news-p)
4581 (when message-default-news-headers
4582 (insert message-default-news-headers)
4583 (or (bolp) (insert ?\n)))
4584 (when message-generate-headers-first
4585 (message-generate-headers
4588 (copy-sequence message-required-news-headers))))))
4589 (when (message-mail-p)
4590 (when message-default-mail-headers
4591 (insert message-default-mail-headers)
4592 (or (bolp) (insert ?\n)))
4593 (when message-generate-headers-first
4594 (message-generate-headers
4597 (copy-sequence message-required-mail-headers))))))
4598 (run-hooks 'message-signature-setup-hook)
4599 (message-insert-signature)
4601 (message-narrow-to-headers)
4602 (if message-alternative-emails
4603 (message-use-alternative-email-as-from))
4604 (run-hooks 'message-header-setup-hook))
4605 (set-buffer-modified-p nil)
4606 (setq buffer-undo-list nil)
4607 (run-hooks 'message-setup-hook)
4608 (message-position-point)
4611 (defun message-set-auto-save-file-name ()
4612 "Associate the message buffer with a file in the drafts directory."
4613 (when message-auto-save-directory
4614 (unless (file-directory-p
4615 (directory-file-name message-auto-save-directory))
4616 (gnus-make-directory message-auto-save-directory))
4618 (setq message-draft-article
4619 (nndraft-request-associate-buffer "drafts"))
4620 (setq buffer-file-name (expand-file-name
4621 (if (eq system-type 'windows-nt)
4624 message-auto-save-directory))
4625 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
4626 (clear-visited-file-modtime)
4627 (static-if (boundp 'MULE)
4628 (set-file-coding-system message-draft-coding-system)
4629 (setq buffer-file-coding-system message-draft-coding-system))))
4631 (defun message-disassociate-draft ()
4632 "Disassociate the message buffer from the drafts directory."
4633 (when message-draft-article
4634 (nndraft-request-expire-articles
4635 (list message-draft-article) "drafts" nil t)))
4637 (defun message-insert-headers ()
4638 "Generate the headers for the article."
4642 (message-narrow-to-headers)
4643 (when (message-news-p)
4644 (message-generate-headers
4647 (copy-sequence message-required-news-headers)))))
4648 (when (message-mail-p)
4649 (message-generate-headers
4652 (copy-sequence message-required-mail-headers))))))))
4657 ;;; Commands for interfacing with message
4661 (defun message-mail (&optional to subject
4662 other-headers continue switch-function
4663 yank-action send-actions)
4664 "Start editing a mail message to be sent.
4665 OTHER-HEADERS is an alist of header/value pairs."
4667 (let ((message-this-is-mail t) replybuffer)
4668 (unless (message-mail-user-agent)
4669 (message-pop-to-buffer (message-buffer-name "mail" to)))
4670 ;; FIXME: message-mail should do something if YANK-ACTION is not
4672 (and (consp yank-action) (eq (car yank-action) 'insert-buffer)
4673 (setq replybuffer (nth 1 yank-action)))
4676 `((To . ,(or to "")) (Subject . ,(or subject "")))
4677 (when other-headers other-headers))
4678 replybuffer send-actions)
4679 ;; FIXME: Should return nil if failure.
4683 (defun message-news (&optional newsgroups subject)
4684 "Start editing a news article to be sent."
4686 (let ((message-this-is-news t))
4687 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))
4688 (message-setup `((Newsgroups . ,(or newsgroups ""))
4689 (Subject . ,(or subject ""))))))
4691 (defun message-get-reply-headers (wide &optional to-address)
4692 (let (follow-to mct never-mct from to cc reply-to mrt mft)
4693 ;; Find all relevant headers we need.
4694 (setq from (message-fetch-field "from")
4695 to (message-fetch-field "to")
4696 cc (message-fetch-field "cc")
4697 mct (when message-use-mail-copies-to
4698 (message-fetch-field "mail-copies-to"))
4699 reply-to (message-fetch-field "reply-to")
4700 mrt (when message-use-mail-reply-to
4701 (message-fetch-field "mail-reply-to"))
4702 mft (when (and (not (or to-address mrt reply-to))
4703 message-use-mail-followup-to)
4704 (message-fetch-field "mail-followup-to")))
4706 ;; Handle special values of Mail-Copies-To.
4709 ((and (or (equal (downcase mct) "never")
4710 (equal (downcase mct) "nobody")))
4711 (when (or (not (eq message-use-mail-copies-to 'ask))
4713 (concat "Obey Mail-Copies-To: never? ") t "\
4714 You should normally obey the Mail-Copies-To: header.
4716 `Mail-Copies-To: " mct "'
4717 directs you not to send your response to the author."))
4720 ((and (or (equal (downcase mct) "always")
4721 (equal (downcase mct) "poster")))
4722 (if (or (not (eq message-use-mail-copies-to 'ask))
4724 (concat "Obey Mail-Copies-To: always? ") t "\
4725 You should normally obey the Mail-Copies-To: header.
4727 `Mail-Copies-To: " mct "'
4728 sends a copy of your response to the author."))
4729 (setq mct (or mrt reply-to from))
4731 ((and (eq message-use-mail-copies-to 'ask)
4732 (not (message-y-or-n-p
4733 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
4734 You should normally obey the Mail-Copies-To: header.
4736 `Mail-Copies-To: " mct "'
4737 sends a copy of your response to " (if (string-match "," mct)
4738 "the specified addresses"
4739 "that address") ".")))
4742 ;; Handle Mail-Followup-To.
4744 (eq message-use-mail-followup-to 'ask)
4745 (not (message-y-or-n-p
4746 (concat "Obey Mail-Followup-To: " mft "? ") t "\
4747 You should normally obey the Mail-Followup-To: header.
4749 `Mail-Followup-To: " mft "'
4750 directs your response to " (if (string-match "," mft)
4751 "the specified addresses"
4752 "that address only") ".
4754 A typical situation where Mail-Followup-To is used is when the author thinks
4755 that further discussion should take place only in "
4756 (if (string-match "," mft)
4757 "the specified mailing lists"
4758 "that mailing list") ".")))
4765 (setq follow-to (list (cons 'To
4766 (or to-address mrt reply-to mft from))))
4768 (not (member (cons 'To mct) follow-to)))
4769 (push (cons 'Cc mct) follow-to)))
4772 (message-set-work-buffer)
4775 (or (not (eq message-use-mail-followup-to 'ask))
4776 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
4777 You should normally obey the Mail-Followup-To: header. In this
4778 article, it has the value of
4782 which directs your response to " (if (string-match "," mft)
4783 "the specified addresses"
4784 "that address only") ".
4786 Most commonly, Mail-Followup-To is used by a mailing list poster to
4787 express that responses should be sent to just the list, and not the
4790 If a message is posted to several mailing lists, Mail-Followup-To may
4791 also be used to direct the following discussion to one list only,
4792 because discussions that are spread over several lists tend to be
4793 fragmented and very difficult to follow.
4795 Also, some source/announcement lists are not intended for discussion;
4796 responses here are directed to other addresses.")))
4799 (insert (or mrt reply-to from "")))
4800 (insert (if to (concat (if (bolp) "" ", ") to) ""))
4801 (insert (if mct (concat (if (bolp) "" ", ") mct) ""))
4802 (insert (if cc (concat (if (bolp) "" ", ") cc) "")))
4803 (goto-char (point-min))
4804 (while (re-search-forward "[ \t]+" nil t)
4805 (replace-match " " t t))
4806 ;; Remove addresses that match `rmail-dont-reply-to-names'.
4807 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
4808 (insert (prog1 (rmail-dont-reply-to (buffer-string))
4810 (goto-char (point-min))
4811 ;; Perhaps "Mail-Copies-To: never" removed the only address?
4813 (insert (or mrt reply-to from "")))
4817 (cons (mail-strip-quoted-names addr) addr))
4818 (message-tokenize-header (buffer-string))))
4821 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
4822 (setq follow-to (list (cons 'To (cdr (pop ccalist)))))
4824 (let ((ccs (cons 'Cc (mapconcat
4825 (lambda (addr) (cdr addr)) ccalist ", "))))
4826 (when (string-match "^ +" (cdr ccs))
4827 (setcdr ccs (substring (cdr ccs) (match-end 0))))
4828 (push ccs follow-to)))
4829 ;; Allow the user to be asked whether or not to reply to all
4830 ;; recipients in a wide reply.
4831 (if (and ccalist wide message-wide-reply-confirm-recipients
4832 (not (y-or-n-p "Reply to all recipients?")))
4833 (setq follow-to (delq (assoc 'Cc follow-to) follow-to)))))
4837 (defun message-reply (&optional to-address wide)
4838 "Start editing a reply to the article in the current buffer."
4840 (require 'gnus-sum) ; for gnus-list-identifiers
4841 (let ((cur (current-buffer))
4843 references message-id follow-to
4844 (inhibit-point-motion-hooks t)
4845 (message-this-is-mail t)
4846 gnus-warning in-reply-to)
4848 (message-narrow-to-head-1)
4849 ;; Allow customizations to have their say.
4851 ;; This is a regular reply.
4852 (when (message-functionp message-reply-to-function)
4854 (setq follow-to (funcall message-reply-to-function))))
4855 ;; This is a followup.
4856 (when (message-functionp message-wide-reply-to-function)
4859 (funcall message-wide-reply-to-function)))))
4860 (setq message-id (message-fetch-field "message-id" t)
4861 references (message-fetch-field "references")
4862 date (message-fetch-field "date")
4863 from (message-fetch-field "from")
4864 subject (or (message-fetch-field "subject") "none"))
4865 (when gnus-list-identifiers
4866 (setq subject (message-strip-list-identifiers subject)))
4867 (setq subject (message-make-followup-subject subject))
4869 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
4870 (string-match "<[^>]+>" gnus-warning))
4871 (setq message-id (match-string 0 gnus-warning)))
4874 (setq follow-to (message-get-reply-headers wide to-address)))
4876 ;; Get the references from "In-Reply-To" field if there were
4877 ;; no references and "In-Reply-To" field looks promising.
4879 (when (and (setq in-reply-to (message-fetch-field "in-reply-to"))
4880 (string-match "<[^>]+>" in-reply-to))
4881 (setq references (match-string 0 in-reply-to)))))
4883 (unless (message-mail-user-agent)
4884 (message-pop-to-buffer
4885 (message-buffer-name
4886 (if wide "wide reply" "reply") from
4887 (if wide to-address nil))))
4889 (setq message-reply-headers
4890 (make-full-mail-header-from-decoded-header
4891 0 subject from date message-id references 0 0 ""))
4894 `((Subject . ,subject)
4896 ,@(if (or references message-id)
4897 `((References . ,(concat (or references "") (and references " ")
4898 (or message-id ""))))
4903 (defun message-wide-reply (&optional to-address)
4904 "Make a \"wide\" reply to the message in the current buffer."
4906 (message-reply to-address t))
4909 (defun message-followup (&optional to-newsgroups)
4910 "Follow up to the message in the current buffer.
4911 If TO-NEWSGROUPS, use that as the new Newsgroups line."
4913 (require 'gnus-sum) ; for gnus-list-identifiers
4914 (let ((cur (current-buffer))
4915 from subject date reply-to mrt mct mft
4916 references message-id follow-to
4917 (inhibit-point-motion-hooks t)
4918 (message-this-is-news t)
4919 followup-to distribution newsgroups gnus-warning posted-to)
4921 (message-narrow-to-head)
4922 (when (message-functionp message-followup-to-function)
4924 (funcall message-followup-to-function)))
4925 (setq from (message-fetch-field "from")
4926 date (message-fetch-field "date")
4927 subject (or (message-fetch-field "subject") "none")
4928 references (message-fetch-field "references")
4929 message-id (message-fetch-field "message-id" t)
4930 followup-to (message-fetch-field "followup-to")
4931 newsgroups (message-fetch-field "newsgroups")
4932 posted-to (message-fetch-field "posted-to")
4933 reply-to (message-fetch-field "reply-to")
4934 mrt (when message-use-mail-reply-to
4935 (message-fetch-field "mail-reply-to"))
4936 distribution (message-fetch-field "distribution")
4937 mct (when message-use-mail-copies-to
4938 (message-fetch-field "mail-copies-to"))
4939 mft (when message-use-mail-followup-to
4940 (message-fetch-field "mail-followup-to")))
4941 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
4942 (string-match "<[^>]+>" gnus-warning))
4943 (setq message-id (match-string 0 gnus-warning)))
4944 ;; Remove bogus distribution.
4945 (when (and (stringp distribution)
4946 (let ((case-fold-search t))
4947 (string-match "world" distribution)))
4948 (setq distribution nil))
4949 (if gnus-list-identifiers
4950 (setq subject (message-strip-list-identifiers subject)))
4951 (setq subject (message-make-followup-subject subject))
4954 ;; Handle special values of Mail-Copies-To.
4957 ((and (or (equal (downcase mct) "never")
4958 (equal (downcase mct) "nobody")))
4960 ((and (or (equal (downcase mct) "always")
4961 (equal (downcase mct) "poster")))
4962 (if (or (not (eq message-use-mail-copies-to 'ask))
4964 (concat "Obey Mail-Copies-To: always? ") t "\
4965 You should normally obey the Mail-Copies-To: header.
4967 `Mail-Copies-To: " mct "'
4968 sends a copy of your response to the author."))
4969 (setq mct (or mrt reply-to from))
4971 ((and (eq message-use-mail-copies-to 'ask)
4974 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
4975 You should normally obey the Mail-Copies-To: header.
4977 `Mail-Copies-To: " mct "'
4978 sends a copy of your response to " (if (string-match "," mct)
4979 "the specified addresses"
4980 "that address") ".")))
4985 (to-newsgroups (setq follow-to (list (cons 'Newsgroups to-newsgroups))))
4986 ;; Handle Followup-To.
4989 ((equal (downcase followup-to) "poster")
4990 (if (or (and followup-to (eq message-use-followup-to 'use))
4991 (message-y-or-n-p "Obey Followup-To: poster? " t "\
4992 You should normally obey the Followup-To: header.
4994 `Followup-To: poster'
4995 sends your response via e-mail instead of news.
4997 A typical situation where `Followup-To: poster' is used is when the author
4998 does not read the newsgroup, so he wouldn't see any replies sent to it."))
4999 (setq message-this-is-news nil
5001 follow-to (list (cons 'To (or mrt reply-to from ""))))
5002 (setq follow-to (list (cons 'Newsgroups newsgroups)))))
5004 (if (or (equal followup-to newsgroups)
5005 (not (and followup-to (eq message-use-followup-to 'ask)))
5007 (concat "Obey Followup-To: " followup-to "? ") t "\
5008 You should normally obey the Followup-To: header.
5010 `Followup-To: " followup-to "'
5011 directs your response to " (if (string-match "," followup-to)
5012 "the specified newsgroups"
5013 "that newsgroup only") ".
5015 If a message is posted to several newsgroups, Followup-To is often
5016 used to direct the following discussion to one newsgroup only,
5017 because discussions that are spread over several newsgroup tend to
5018 be fragmented and very difficult to follow.
5020 Also, some source/announcement newsgroups are not intended for discussion;
5021 responses here are directed to other newsgroups."))
5022 (setq follow-to (list (cons 'Newsgroups followup-to)))
5023 (setq follow-to (list (cons 'Newsgroups newsgroups)))))))
5024 ;; Handle Mail-Followup-To, followup via e-mail.
5026 (or (not (eq message-use-mail-followup-to 'ask))
5028 (concat "Obey Mail-Followup-To: " mft "? ") t "\
5029 You should normally obey the Mail-Followup-To: header.
5031 `Mail-Followup-To: " mft "'
5032 directs your response to " (if (string-match "," mft)
5033 "the specified addresses"
5034 "that address only") " instead of news.
5036 A typical situation where Mail-Followup-To is used is when the author thinks
5037 that further discussion should take place only in "
5038 (if (string-match "," mft)
5039 "the specified mailing lists"
5040 "that mailing list") ".")))
5041 (setq message-this-is-news nil
5043 follow-to (list (cons 'To mft))))
5044 (posted-to (setq follow-to (list (cons 'Newsgroups posted-to))))
5046 (setq follow-to (list (cons 'Newsgroups newsgroups))))))
5048 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
5051 `((Subject . ,subject)
5053 ,@(and mct (list (cons 'Cc mct)))
5054 ,@(and distribution (list (cons 'Distribution distribution)))
5055 ,@(if (or references message-id)
5056 `((References . ,(concat (or references "") (and references " ")
5057 (or message-id ""))))))
5060 (setq message-reply-headers
5061 (make-full-mail-header-from-decoded-header
5062 0 subject from date message-id references 0 0 ""))))
5065 (defun message-cancel-news (&optional arg)
5066 "Cancel an article you posted.
5067 If ARG, allow editing of the cancellation message."
5069 (unless (message-news-p)
5070 (error "This is not a news article; canceling is impossible"))
5071 (let (from newsgroups message-id distribution buf sender)
5073 ;; Get header info from original article.
5075 (message-narrow-to-head-1)
5076 (setq from (message-fetch-field "from")
5077 sender (message-fetch-field "sender")
5078 newsgroups (message-fetch-field "newsgroups")
5079 message-id (message-fetch-field "message-id" t)
5080 distribution (message-fetch-field "distribution")))
5081 ;; Make sure that this article was written by the user.
5082 (unless (or (message-gnksa-enable-p 'cancel-messages)
5086 (downcase (message-make-sender))))
5088 (downcase (cadr (std11-extract-address-components from)))
5089 (downcase (cadr (std11-extract-address-components
5090 (message-make-from))))))
5091 (error "This article is not yours"))
5092 (when (yes-or-no-p "Do you really want to cancel this article? ")
5093 ;; Make control message.
5096 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
5098 (insert "Newsgroups: " newsgroups "\n"
5100 "Subject: cmsg cancel " message-id "\n"
5101 "Control: cancel " message-id "\n"
5103 (concat "Distribution: " distribution "\n")
5105 mail-header-separator "\n"
5106 message-cancel-message)
5107 (run-hooks 'message-cancel-hook)
5109 (message "Canceling your article...")
5110 (if (let ((message-syntax-checks
5111 'dont-check-for-anything-just-trust-me)
5112 (message-encoding-buffer (current-buffer))
5113 (message-edit-buffer (current-buffer)))
5114 (message-send-news))
5115 (message "Canceling your article...done"))
5116 (kill-buffer buf))))))
5118 (defun message-supersede-setup-for-mime-edit ()
5119 (set (make-local-variable 'message-setup-hook) nil)
5123 (defun message-supersede ()
5124 "Start composing a message to supersede the current message.
5125 This is done simply by taking the old article and adding a Supersedes
5126 header line with the old Message-ID."
5128 (let ((cur (current-buffer))
5129 (sender (message-fetch-field "sender"))
5130 (from (message-fetch-field "from")))
5131 ;; Check whether the user owns the article that is to be superseded.
5132 (unless (or (message-gnksa-enable-p 'cancel-messages)
5136 (downcase (message-make-sender))))
5138 (downcase (cadr (std11-extract-address-components from)))
5139 (downcase (cadr (std11-extract-address-components
5140 (message-make-from))))))
5141 (error "This article is not yours"))
5142 ;; Get a normal message buffer.
5143 (message-pop-to-buffer (message-buffer-name "supersede"))
5144 (insert-buffer-substring cur)
5145 (message-narrow-to-head-1)
5146 ;; Remove unwanted headers.
5147 (when message-ignored-supersedes-headers
5148 (message-remove-header message-ignored-supersedes-headers t))
5149 (goto-char (point-min))
5150 (if (not (re-search-forward "^Message-ID: " nil t))
5151 (error "No Message-ID in this article")
5152 (replace-match "Supersedes: " t t))
5153 (goto-char (point-max))
5154 (insert mail-header-separator)
5156 (when message-supersede-setup-function
5157 (funcall message-supersede-setup-function))
5158 (run-hooks 'message-supersede-setup-hook)
5159 (goto-char (point-min))
5160 (search-forward (concat "\n" mail-header-separator "\n") nil t)))
5163 (defun message-recover ()
5164 "Reread contents of current buffer from its last auto-save file."
5166 (let ((file-name (make-auto-save-file-name)))
5167 (cond ((save-window-excursion
5168 (if (not (eq system-type 'vax-vms))
5169 (with-output-to-temp-buffer "*Directory*"
5170 (with-current-buffer standard-output
5171 (fundamental-mode)) ; for Emacs 20.4+
5172 (buffer-disable-undo standard-output)
5173 (let ((default-directory "/"))
5175 "ls" nil standard-output nil "-l" file-name))))
5176 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
5177 (let ((buffer-read-only nil))
5179 (insert-file-contents file-name nil)))
5180 (t (error "message-recover cancelled")))))
5182 ;;; Washing Subject:
5184 (defun message-wash-subject (subject)
5185 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
5186 Previous forwarders, replyers, etc. may add it."
5188 (insert-string subject)
5189 (goto-char (point-min))
5190 ;; strip Re/Fwd stuff off the beginning
5191 (while (re-search-forward
5192 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
5195 ;; and gnus-style forwards [foo@bar.com] subject
5196 (goto-char (point-min))
5197 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
5201 (goto-char (point-max))
5202 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
5205 ;; and finally, any whitespace that was left-over
5206 (goto-char (point-min))
5207 (while (re-search-forward "^[ \t]+" nil t)
5209 (goto-char (point-max))
5210 (while (re-search-backward "[ \t]+$" nil t)
5215 ;;; Forwarding messages.
5217 (defvar message-forward-decoded-p nil
5218 "Non-nil means the original message is decoded.")
5220 (defun message-forward-subject-author-subject (subject)
5221 "Generate a SUBJECT for a forwarded message.
5222 The form is: [Source] Subject, where if the original message was mail,
5223 Source is the sender, and if the original message was news, Source is
5224 the list of newsgroups is was posted to."
5226 (if (message-news-p)
5227 (or (message-fetch-field "newsgroups")
5229 (let ((from (message-fetch-field "from")))
5231 (nnheader-decode-from from)
5235 (defun message-forward-subject-fwd (subject)
5236 "Generate a SUBJECT for a forwarded message.
5237 The form is: Fwd: Subject, where Subject is the original subject of
5239 (concat "Fwd: " subject))
5241 (defun message-make-forward-subject ()
5242 "Return a Subject header suitable for the message in the current buffer."
5245 (message-narrow-to-head-1)
5246 (let ((funcs message-make-forward-subject-function)
5247 (subject (message-fetch-field "Subject")))
5250 (if message-forward-decoded-p
5252 (nnheader-decode-subject subject))
5254 (if message-wash-forwarded-subjects
5255 (setq subject (message-wash-subject subject)))
5256 ;; Make sure funcs is a list.
5259 (setq funcs (list funcs)))
5260 ;; Apply funcs in order, passing subject generated by previous
5261 ;; func to the next one.
5263 (when (message-functionp (car funcs))
5264 (setq subject (funcall (car funcs) subject)))
5265 (setq funcs (cdr funcs)))
5269 (defun message-forward (&optional news)
5270 "Forward the current message via mail.
5271 Optional NEWS will use news to forward instead of mail."
5273 (let ((cur (current-buffer))
5274 (subject (message-make-forward-subject))
5277 (message-news nil subject)
5278 (message-mail nil subject))
5279 ;; Put point where we want it before inserting the forwarded
5281 (if message-forward-before-signature
5283 (goto-char (point-max)))
5284 ;; Make sure we're at the start of the line.
5287 ;; Narrow to the area we are to insert.
5288 (narrow-to-region (point) (point))
5289 ;; Insert the separators and the forwarded buffer.
5290 (insert message-forward-start-separator)
5291 (setq art-beg (point))
5292 (insert-buffer-substring cur)
5293 (goto-char (point-max))
5294 (insert message-forward-end-separator)
5295 (set-text-properties (point-min) (point-max) nil)
5296 ;; Remove all unwanted headers.
5298 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
5301 (goto-char (point-min))
5302 (message-remove-header message-included-forward-headers t nil t)
5304 (message-position-point)))
5307 (defun message-resend (address)
5308 "Resend the current article to ADDRESS."
5310 (list (message-read-from-minibuffer "Resend message to: ")))
5311 (message "Resending message to %s..." address)
5313 (let ((cur (current-buffer))
5315 ;; We first set up a normal mail buffer.
5316 (unless (message-mail-user-agent)
5317 (set-buffer (get-buffer-create " *message resend*"))
5319 (let ((message-this-is-mail t)
5320 ;; avoid to turn-on-mime-edit
5322 (message-setup `((To . ,address)))))
5323 ;; Insert our usual headers.
5324 (message-generate-headers '(From Date To))
5325 (message-narrow-to-headers)
5326 ;; Rename them all to "Resent-*".
5327 (while (re-search-forward "^[A-Za-z]" nil t)
5332 (delete-region (point) (point-max))
5334 ;; Insert the message to be resent.
5335 (insert-buffer-substring cur)
5336 (goto-char (point-min))
5337 (search-forward "\n\n")
5340 (narrow-to-region beg (point))
5341 (message-remove-header message-ignored-resent-headers t)
5342 (goto-char (point-max)))
5343 (insert mail-header-separator)
5344 ;; Rename all old ("Also-")Resent headers.
5345 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
5348 ;; Quote any "From " lines at the beginning.
5350 (when (looking-at "From ")
5351 (replace-match "X-From-Line: "))
5353 (let ((message-encoding-buffer (current-buffer))
5354 (message-edit-buffer (current-buffer)))
5355 (let (message-required-mail-headers)
5356 (message-send-mail)))
5357 (kill-buffer (current-buffer)))
5358 (message "Resending message to %s...done" address)))
5360 (defun message-bounce-setup-for-mime-edit ()
5361 (set (make-local-variable 'message-setup-hook) nil)
5365 (defun message-bounce ()
5366 "Re-mail the current message.
5367 This only makes sense if the current message is a bounce message that
5368 contains some mail you have written which has been bounced back to
5371 (let ((cur (current-buffer))
5373 (message-pop-to-buffer (message-buffer-name "bounce"))
5374 (insert-buffer-substring cur)
5376 (message-narrow-to-head)
5377 (if (and (message-fetch-field "MIME-Version")
5378 (setq boundary (message-fetch-field "Content-Type")))
5379 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary)
5380 (setq boundary (concat (match-string 1 boundary) " *\n"
5381 "Content-Type: message/rfc822"))
5382 (setq boundary nil)))
5384 (goto-char (point-min))
5385 (search-forward "\n\n" nil t)
5386 (if (or (and boundary
5387 (re-search-forward boundary nil t)
5389 (and (re-search-forward message-unsent-separator nil t)
5391 (re-search-forward "^Return-Path:.*\n" nil t))
5392 ;; We remove everything before the bounced mail.
5395 (if (re-search-forward "^[^ \n\t]+:" nil t)
5398 (when (re-search-backward "^.?From .*\n" nil t)
5399 (delete-region (match-beginning 0) (match-end 0))))
5401 (message-narrow-to-head-1)
5402 (message-remove-header message-ignored-bounced-headers t)
5403 (goto-char (point-max))
5404 (insert mail-header-separator))
5405 (when message-bounce-setup-function
5406 (funcall message-bounce-setup-function))
5407 (run-hooks 'message-bounce-setup-hook)
5408 (message-position-point)))
5411 ;;; Interactive entry points for new message buffers.
5415 (defun message-mail-other-window (&optional to subject)
5416 "Like `message-mail' command, but display mail buffer in another window."
5418 (unless (message-mail-user-agent)
5419 (let ((pop-up-windows t)
5420 (special-display-buffer-names nil)
5421 (special-display-regexps nil)
5422 (same-window-buffer-names nil)
5423 (same-window-regexps nil))
5424 (message-pop-to-buffer (message-buffer-name "mail" to))))
5425 (let ((message-this-is-mail t))
5426 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
5427 nil nil 'switch-to-buffer-other-window)))
5430 (defun message-mail-other-frame (&optional to subject)
5431 "Like `message-mail' command, but display mail buffer in another frame."
5433 (unless (message-mail-user-agent)
5434 (let ((pop-up-frames t)
5435 (special-display-buffer-names nil)
5436 (special-display-regexps nil)
5437 (same-window-buffer-names nil)
5438 (same-window-regexps nil))
5439 (message-pop-to-buffer (message-buffer-name "mail" to))))
5440 (let ((message-this-is-mail t))
5441 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
5442 nil nil 'switch-to-buffer-other-frame)))
5445 (defun message-news-other-window (&optional newsgroups subject)
5446 "Start editing a news article to be sent."
5448 (let ((pop-up-windows t)
5449 (special-display-buffer-names nil)
5450 (special-display-regexps nil)
5451 (same-window-buffer-names nil)
5452 (same-window-regexps nil))
5453 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
5454 (let ((message-this-is-news t))
5455 (message-setup `((Newsgroups . ,(or newsgroups ""))
5456 (Subject . ,(or subject ""))))))
5459 (defun message-news-other-frame (&optional newsgroups subject)
5460 "Start editing a news article to be sent."
5462 (let ((pop-up-frames t)
5463 (special-display-buffer-names nil)
5464 (special-display-regexps nil)
5465 (same-window-buffer-names nil)
5466 (same-window-regexps nil))
5467 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
5468 (let ((message-this-is-news t))
5469 (message-setup `((Newsgroups . ,(or newsgroups ""))
5470 (Subject . ,(or subject ""))))))
5474 ;; This code should be moved to underline.el (from which it is stolen).
5477 (defun bold-region (start end)
5478 "Bold all nonblank characters in the region.
5479 Works by overstriking characters.
5480 Called from program, takes two arguments START and END
5481 which specify the range to operate on."
5484 (let ((end1 (make-marker)))
5485 (move-marker end1 (max start end))
5486 (goto-char (min start end))
5487 (while (< (point) end1)
5488 (or (looking-at "[_\^@- ]")
5489 (insert (char-after) "\b"))
5490 (forward-char 1)))))
5493 (defun unbold-region (start end)
5494 "Remove all boldness (overstruck characters) in the region.
5495 Called from program, takes two arguments START and END
5496 which specify the range to operate on."
5499 (let ((end1 (make-marker)))
5500 (move-marker end1 (max start end))
5501 (goto-char (min start end))
5502 (while (re-search-forward "\b" end1 t)
5503 (if (eq (char-after) (char-after (- (point) 2)))
5504 (delete-char -2))))))
5506 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
5508 ;; Support for toolbar
5510 (defvar tool-bar-map)
5511 (defvar tool-bar-mode))
5513 (defun message-tool-bar-map ()
5514 (or message-tool-bar-map
5515 (setq message-tool-bar-map
5516 (and (fboundp 'tool-bar-add-item-from-menu)
5518 (let ((tool-bar-map (copy-keymap tool-bar-map))
5519 (load-path (mm-image-load-path)))
5520 ;; Zap some items which aren't so relevant and take
5522 (dolist (key '(print-buffer kill-buffer save-buffer
5523 write-file dired open-file))
5524 (define-key tool-bar-map (vector key) nil))
5525 (tool-bar-add-item-from-menu
5526 'message-send-and-exit "mail_send" message-mode-map)
5527 (tool-bar-add-item-from-menu
5528 'message-kill-buffer "close" message-mode-map)
5529 (tool-bar-add-item-from-menu
5530 'message-dont-send "cancel" message-mode-map)
5531 (tool-bar-add-item-from-menu
5532 'mml-attach-file "attach" message-mode-map)
5533 (tool-bar-add-item-from-menu
5534 'ispell-message "spell" message-mode-map)
5537 ;;; Group name completion.
5539 (defvar message-newgroups-header-regexp
5540 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
5541 "Regexp that match headers that lists groups.")
5543 (defvar message-completion-alist
5544 (list (cons message-newgroups-header-regexp 'message-expand-group)
5545 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name))
5546 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE.")
5548 (defun message-tab ()
5549 "Expand group names in Newsgroups and Followup-To headers.
5550 Do a `tab-to-tab-stop' if not in those headers."
5552 (let ((alist message-completion-alist))
5554 (let ((mail-abbrev-mode-regexp (caar alist)))
5555 (not (mail-abbrev-in-expansion-header-p))))
5556 (setq alist (cdr alist)))
5557 (funcall (or (cdar alist) (default-value 'indent-line-function)))))
5559 (defun message-expand-group ()
5560 "Expand the group name under point."
5561 (let* ((b (save-excursion
5566 (skip-chars-forward "^:")
5569 (skip-chars-backward "^, \t\n") (point))))
5570 (completion-ignore-case t)
5571 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
5573 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
5574 (completions (all-completions string hashtb))
5576 (delete-region b (point))
5578 ((= (length completions) 1)
5579 (if (string= (car completions) string)
5582 (message "Only matching group"))
5583 (insert (car completions))))
5584 ((and (setq comp (try-completion string hashtb))
5585 (not (string= comp string)))
5590 (message "No matching groups")
5591 (save-selected-window
5592 (pop-to-buffer "*Completions*")
5593 (buffer-disable-undo)
5594 (let ((buffer-read-only nil))
5596 (let ((standard-output (current-buffer)))
5597 (display-completion-list (sort completions 'string<)))
5598 (goto-char (point-min))
5599 (delete-region (point) (progn (forward-line 3) (point))))))))))
5601 (defun message-expand-name ()
5602 (if (fboundp 'bbdb-complete-name)
5603 (bbdb-complete-name)
5608 (defun message-talkative-question (ask question show &rest text)
5609 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
5610 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
5611 The following arguments may contain lists of values."
5613 (setq text (message-flatten-list text)))
5614 (save-window-excursion
5616 (with-output-to-temp-buffer " *MESSAGE information message*"
5617 (set-buffer " *MESSAGE information message*")
5618 (fundamental-mode) ; for Emacs 20.4+
5619 (mapcar 'princ text)
5620 (goto-char (point-min))))
5621 (funcall ask question))
5622 (funcall ask question)))
5624 (defun message-flatten-list (list)
5625 "Return a new, flat list that contains all elements of LIST.
5627 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
5630 (apply 'append (mapcar 'message-flatten-list list)))
5634 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
5635 "Create and return a buffer with name based on NAME using `generate-new-buffer.'
5636 Then clone the local variables and values from the old buffer to the
5637 new one, cloning only the locals having a substring matching the
5639 (let ((oldbuf (current-buffer)))
5641 (set-buffer (generate-new-buffer name))
5642 (message-clone-locals oldbuf varstr)
5645 (defun message-clone-locals (buffer &optional varstr)
5646 "Clone the local variables from BUFFER to the current buffer."
5647 (let ((locals (save-excursion
5649 (buffer-local-variables)))
5651 "^\\(gnus\\|nn\\|message\\|user-\\(mail-address\\|full-name\\)\\)"))
5654 (when (and (consp local)
5656 (string-match regexp (symbol-name (car local)))
5658 (string-match varstr (symbol-name (car local)))))
5660 (set (make-local-variable (car local))
5665 ;;; @ for MIME Edit mode
5668 (defun message-maybe-encode ()
5669 (when message-mime-mode
5670 ;; Inherit the buffer local variable `mime-edit-pgp-processing'.
5671 (let ((pgp-processing (with-current-buffer message-edit-buffer
5672 mime-edit-pgp-processing)))
5673 (setq mime-edit-pgp-processing pgp-processing))
5674 (run-hooks 'mime-edit-translate-hook)
5675 (if (catch 'mime-edit-error
5677 (mime-edit-pgp-enclose-buffer)
5678 (mime-edit-translate-body)))
5679 (error "Translation error!"))
5680 (run-hooks 'mime-edit-exit-hook)))
5682 (defun message-mime-insert-article (&optional full-headers)
5684 (let ((message-cite-function 'mime-edit-inserted-message-filter)
5685 (message-reply-buffer
5686 (message-get-parameter-with-eval 'original-buffer))
5688 (message-yank-original nil)
5690 (narrow-to-region (goto-char start)
5691 (if (search-forward "\n\n" nil t)
5694 (goto-char (point-min))
5695 (let ((message-included-forward-headers
5696 (if full-headers "" message-included-forward-headers)))
5697 (message-remove-header message-included-forward-headers t nil t))
5700 (set-alist 'mime-edit-message-inserter-alist
5701 'message-mode (function message-mime-insert-article))
5703 ;;; Miscellaneous functions
5705 ;; stolen (and renamed) from nnheader.el
5706 (static-if (fboundp 'subst-char-in-string)
5707 (defsubst message-replace-chars-in-string (string from to)
5708 (subst-char-in-string from to string))
5709 (defun message-replace-chars-in-string (string from to)
5710 "Replace characters in STRING from FROM to TO."
5711 (let ((string (substring string 0)) ;Copy string.
5712 (len (length string))
5714 ;; Replace all occurrences of FROM with TO.
5716 (when (= (aref string idx) from)
5717 (aset string idx to))
5718 (setq idx (1+ idx)))
5725 (defvar message-inhibit-body-encoding t)
5727 (defun message-encode-message-body ()
5728 (unless message-inhibit-body-encoding
5729 (let ((mail-parse-charset (or mail-parse-charset
5730 message-default-charset))
5731 (case-fold-search t)
5732 lines content-type-p)
5735 (narrow-to-region (point) (point-max))
5736 (let ((new (mml-generate-mime)))
5738 (delete-region (point-min) (point-max))
5740 (goto-char (point-min))
5741 (if (eq (aref new 0) ?\n)
5743 (search-forward "\n\n")
5744 (setq lines (buffer-substring (point-min) (1- (point))))
5745 (delete-region (point-min) (point))))))
5747 (message-narrow-to-headers-or-head)
5748 (message-remove-header "Mime-Version")
5749 (goto-char (point-max))
5750 (insert "MIME-Version: 1.0\n")
5753 (setq content-type-p
5755 (re-search-backward "^Content-Type:" nil t))))
5757 (message-narrow-to-headers-or-head)
5758 (message-remove-first-header "Content-Type")
5759 (message-remove-first-header "Content-Transfer-Encoding"))
5760 ;; We always make sure that the message has a Content-Type header.
5761 ;; This is because some broken MTAs and MUAs get awfully confused
5762 ;; when confronted with a message with a MIME-Version header and
5763 ;; without a Content-Type header. For instance, Solaris'
5765 (unless content-type-p
5766 (goto-char (point-min))
5767 (re-search-forward "^MIME-Version:")
5769 (insert "Content-Type: text/plain; charset=us-ascii\n")))))
5771 (defun message-read-from-minibuffer (prompt)
5772 "Read from the minibuffer while providing abbrev expansion."
5773 (if (fboundp 'mail-abbrevs-setup)
5774 (let ((mail-abbrev-mode-regexp "")
5775 (minibuffer-setup-hook 'mail-abbrevs-setup)
5776 (minibuffer-local-map message-minibuffer-local-map))
5777 (read-from-minibuffer prompt))
5778 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
5779 (minibuffer-local-map message-minibuffer-local-map))
5780 (read-string prompt))))
5782 (defun message-use-alternative-email-as-from ()
5783 (require 'mail-utils)
5784 (let* ((fields '("To" "Cc"))
5787 (mail-strip-quoted-names
5788 (mapconcat 'message-fetch-reply-field fields ","))
5792 (if (string-match message-alternative-emails (car emails))
5793 (setq email (car emails)
5796 (unless (or (not email) (equal email user-mail-address))
5797 (goto-char (point-max))
5798 (insert "From: " email "\n"))))
5800 (defun message-options-get (symbol)
5801 (cdr (assq symbol message-options)))
5803 (defun message-options-set (symbol value)
5804 (let ((the-cons (assq symbol message-options)))
5807 (setcdr the-cons value)
5808 (setq message-options (delq the-cons message-options)))
5810 (push (cons symbol value) message-options))))
5813 (defun message-options-set-recipient ()
5815 (message-narrow-to-headers-or-head)
5816 (message-options-set 'message-sender
5817 (mail-strip-quoted-names
5818 (message-fetch-field "from")))
5819 (message-options-set 'message-recipients
5820 (mail-strip-quoted-names
5821 (let ((to (message-fetch-field "to"))
5822 (cc (message-fetch-field "cc"))
5823 (bcc (message-fetch-field "bcc")))
5826 (if (and to cc) ", ")
5828 (if (and (or to cc) bcc) ", ")
5831 (when (featurep 'xemacs)
5832 (require 'messagexmas)
5833 (message-xmas-redefine))
5835 (defun message-save-drafts ()
5836 "Postponing the message."
5838 (message "Saving %s..." buffer-file-name)
5839 (let ((reply-headers message-reply-headers)
5840 (msg (buffer-substring-no-properties (point-min) (point-max)))
5841 (message-invisibles (message-find-invisible-regions)))
5842 (with-temp-file buffer-file-name
5844 ;; Inherit the invisible property of texts to make MIME-Edit
5845 ;; find the MIME part boundaries.
5846 (dolist (region message-invisibles)
5847 (put-text-property (car region) (cdr region) 'invisible t))
5848 (setq message-reply-headers reply-headers)
5849 (message-generate-headers '((optional . In-Reply-To)))
5850 (mime-edit-translate-buffer))
5851 (set-buffer-modified-p nil))
5852 (message "Saving %s...done" buffer-file-name))
5856 (run-hooks 'message-load-hook)
5859 ;; coding: iso-8859-1
5862 ;;; message.el ends here