1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; Keywords: mail, news
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
26 ;; This mode provides mail-sending facilities from within Emacs. It
27 ;; consists mainly of large chunks of code from the sendmail.el,
28 ;; gnus-msg.el and rnewspost.el files.
32 (eval-when-compile (require 'cl))
38 (if (string-match "XEmacs\\|Lucid" emacs-version)
39 (require 'mail-abbrevs)
40 (require 'mailabbrev))
45 (defgroup message '((user-mail-address custom-variable)
46 (user-full-name custom-variable))
47 "Mail and news message composing."
48 :link '(custom-manual "(message)Top")
52 (put 'user-mail-address 'custom-type 'string)
53 (put 'user-full-name 'custom-type 'string)
55 (defgroup message-various nil
56 "Various Message Variables"
57 :link '(custom-manual "(message)Various Message Variables")
60 (defgroup message-buffers nil
62 :link '(custom-manual "(message)Message Buffers")
65 (defgroup message-sending nil
67 :link '(custom-manual "(message)Sending Variables")
70 (defgroup message-interface nil
72 :link '(custom-manual "(message)Interface")
75 (defgroup message-forwarding nil
77 :link '(custom-manual "(message)Forwarding")
78 :group 'message-interface)
80 (defgroup message-insertion nil
82 :link '(custom-manual "(message)Insertion")
85 (defgroup message-headers nil
87 :link '(custom-manual "(message)Message Headers")
90 (defgroup message-news nil
91 "Composing News Messages"
94 (defgroup message-mail nil
95 "Composing Mail Messages"
98 (defgroup message-faces nil
99 "Faces used for message composing."
103 (defcustom message-directory "~/Mail/"
104 "*Directory from which all other mail file variables are derived."
105 :group 'message-various
108 (defcustom message-max-buffers 10
109 "*How many buffers to keep before starting to kill them off."
110 :group 'message-buffers
113 (defcustom message-send-rename-function nil
114 "Function called to rename the buffer after sending it."
115 :group 'message-buffers
118 (defcustom message-fcc-handler-function 'message-output
119 "*A function called to save outgoing articles.
120 This function will be called with the name of the file to store the
121 article in. The default function is `message-output' which saves in Unix
123 :type '(radio (function-item message-output)
124 (function :tag "Other"))
125 :group 'message-sending)
127 (defcustom message-courtesy-message
128 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
129 "*This is inserted at the start of a mailed copy of a posted message.
130 If the string contains the format spec \"%s\", the Newsgroups
131 the article has been posted to will be inserted there.
132 If this variable is nil, no such courtesy message will be added."
133 :group 'message-sending
136 (defcustom message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):"
137 "*Regexp that matches headers to be removed in resent bounced mail."
138 :group 'message-interface
142 (defcustom message-from-style 'default
143 "*Specifies how \"From\" headers look.
145 If `nil', they contain just the return address like:
147 If `parens', they look like:
148 king@grassland.com (Elvis Parsley)
149 If `angles', they look like:
150 Elvis Parsley <king@grassland.com>
152 Otherwise, most addresses look like `angles', but they look like
153 `parens' if `angles' would need quoting and `parens' would not."
154 :type '(choice (const :tag "simple" nil)
158 :group 'message-headers)
160 (defcustom message-syntax-checks nil
161 ; Guess this one shouldn't be easy to customize...
162 "*Controls what syntax checks should not be performed on outgoing posts.
163 To disable checking of long signatures, for instance, add
164 `(signature . disabled)' to this list.
166 Don't touch this variable unless you really know what you're doing.
168 Checks include subject-cmsg multiple-headers sendsys message-id from
169 long-lines control-chars size new-text redirected-followup signature
170 approved sender empty empty-headers message-id from subject
171 shorten-followup-to existing-newsgroups buffer-file-name unchanged."
172 :group 'message-news)
174 (defcustom message-required-news-headers
175 '(From Newsgroups Subject Date Message-ID
176 (optional . Organization) Lines
177 (optional . User-Agent))
178 "*Headers to be generated or prompted for when posting an article.
179 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
180 Message-ID. Organization, Lines, In-Reply-To, Expires, and
181 User-Agent are optional. If don't you want message to insert some
182 header, remove it from this list."
184 :group 'message-headers
185 :type '(repeat sexp))
187 (defcustom message-required-mail-headers
188 '(From Subject Date (optional . In-Reply-To) Message-ID Lines
189 (optional . User-Agent))
190 "*Headers to be generated or prompted for when mailing a message.
191 RFC822 required that From, Date, To, Subject and Message-ID be
192 included. Organization, Lines and User-Agent are optional."
194 :group 'message-headers
195 :type '(repeat sexp))
197 (defcustom message-deletable-headers '(Message-ID Date Lines)
198 "Headers to be deleted if they already exist and were generated by message previously."
199 :group 'message-headers
202 (defcustom message-ignored-news-headers
203 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:"
204 "*Regexp of headers to be removed unconditionally before posting."
206 :group 'message-headers
209 (defcustom message-ignored-mail-headers "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:"
210 "*Regexp of headers to be removed unconditionally before mailing."
212 :group 'message-headers
215 (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:"
216 "*Header lines matching this regexp will be deleted before posting.
217 It's best to delete old Path and Date headers before posting to avoid
219 :group 'message-interface
222 (defcustom message-subject-re-regexp "^[ \t]*\\([Rr][Ee]:[ \t]*\\)*[ \t]*"
223 "*Regexp matching \"Re: \" in the subject line."
224 :group 'message-various
228 (defcustom message-signature-separator "^-- *$"
229 "Regexp matching the signature separator."
231 :group 'message-various)
233 (defcustom message-elide-elipsis "\n[...]\n\n"
234 "*The string which is inserted for elided text."
236 :group 'message-various)
238 (defcustom message-interactive nil
239 "Non-nil means when sending a message wait for and display errors.
240 nil means let mailer mail back a message to report errors."
241 :group 'message-sending
245 (defcustom message-generate-new-buffers 'unique
246 "*Non-nil means that a new message buffer will be created whenever `message-setup' is called.
247 If this is a function, call that function with three parameters: The type,
248 the to address and the group name. (Any of these may be nil.) The function
249 should return the new buffer name."
250 :group 'message-buffers
251 :type '(choice (const :tag "off" nil)
252 (const :tag "unique" unique)
253 (const :tag "unsuniqueent" unsent)
256 (defcustom message-kill-buffer-on-exit nil
257 "*Non-nil means that the message buffer will be killed after sending a message."
258 :group 'message-buffers
261 (defvar gnus-local-organization)
262 (defcustom message-user-organization
263 (or (and (boundp 'gnus-local-organization)
264 (stringp gnus-local-organization)
265 gnus-local-organization)
266 (getenv "ORGANIZATION")
268 "*String to be used as an Organization header.
269 If t, use `message-user-organization-file'."
270 :group 'message-headers
271 :type '(choice string
272 (const :tag "consult file" t)))
275 (defcustom message-user-organization-file "/usr/lib/news/organization"
276 "*Local news organization file."
278 :group 'message-headers)
280 (defcustom message-forward-start-separator
281 "------- Start of forwarded message -------\n"
282 "*Delimiter inserted before forwarded messages."
283 :group 'message-forwarding
286 (defcustom message-forward-end-separator
287 "------- End of forwarded message -------\n"
288 "*Delimiter inserted after forwarded messages."
289 :group 'message-forwarding
292 (defcustom message-signature-before-forwarded-message t
293 "*If non-nil, put the signature before any included forwarded message."
294 :group 'message-forwarding
297 (defcustom message-included-forward-headers
298 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-\\|^Message-ID:\\|^References:\\|^Content-Transfer-Encoding:\\|^Content-Type:\\|^Mime-Version:"
299 "*Regexp matching headers to be included in forwarded messages."
300 :group 'message-forwarding
303 (defcustom message-make-forward-subject-function
304 'message-forward-subject-author-subject
305 "*A list of functions that are called to generate a subject header for forwarded messages.
306 The subject generated by the previous function is passed into each
309 The provided functions are:
311 * message-forward-subject-author-subject (Source of article (author or
312 newsgroup)), in brackets followed by the subject
313 * message-forward-subject-fwd (Subject of article with 'Fwd:' prepended
315 :group 'message-forwarding
316 :type '(radio (function-item message-forward-subject-author-subject)
317 (function-item message-forward-subject-fwd)))
319 (defcustom message-wash-forwarded-subjects nil
320 "*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."
321 :group 'message-forwarding
324 (defcustom message-ignored-resent-headers "^Return-receipt"
325 "*All headers that match this regexp will be deleted when resending a message."
326 :group 'message-interface
329 (defcustom message-ignored-cited-headers "."
330 "*Delete these headers from the messages you yank."
331 :group 'message-insertion
334 (defcustom message-cancel-message "I am canceling my own article."
335 "Message to be inserted in the cancel message."
336 :group 'message-interface
339 ;; Useful to set in site-init.el
341 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
342 "Function to call to send the current buffer as mail.
343 The headers should be delimited by a line whose contents match the
344 variable `mail-header-separator'.
346 Legal values include `message-send-mail-with-sendmail' (the default),
347 `message-send-mail-with-mh', `message-send-mail-with-qmail' and
349 :type '(radio (function-item message-send-mail-with-sendmail)
350 (function-item message-send-mail-with-mh)
351 (function-item message-send-mail-with-qmail)
352 (function-item smtpmail-send-it)
353 (function :tag "Other"))
354 :group 'message-sending
355 :group 'message-mail)
357 (defcustom message-send-news-function 'message-send-news
358 "Function to call to send the current buffer as news.
359 The headers should be delimited by a line whose contents match the
360 variable `mail-header-separator'."
361 :group 'message-sending
365 (defcustom message-reply-to-function nil
366 "Function that should return a list of headers.
367 This function should pick out addresses from the To, Cc, and From headers
368 and respond with new To and Cc headers."
369 :group 'message-interface
372 (defcustom message-wide-reply-to-function nil
373 "Function that should return a list of headers.
374 This function should pick out addresses from the To, Cc, and From headers
375 and respond with new To and Cc headers."
376 :group 'message-interface
379 (defcustom message-followup-to-function nil
380 "Function that should return a list of headers.
381 This function should pick out addresses from the To, Cc, and From headers
382 and respond with new To and Cc headers."
383 :group 'message-interface
386 (defcustom message-use-followup-to 'ask
387 "*Specifies what to do with Followup-To header.
388 If nil, always ignore the header. If it is t, use its value, but
389 query before using the \"poster\" value. If it is the symbol `ask',
390 always query the user whether to use the value. If it is the symbol
391 `use', always use the value."
392 :group 'message-interface
393 :type '(choice (const :tag "ignore" nil)
397 ;; stuff relating to broken sendmail in MMDF
398 (defcustom message-sendmail-f-is-evil nil
399 "*Non-nil means that \"-f username\" should not be added to the sendmail
400 command line, because it is even more evil than leaving it out."
401 :group 'message-sending
404 ;; qmail-related stuff
405 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
406 "Location of the qmail-inject program."
407 :group 'message-sending
410 (defcustom message-qmail-inject-args nil
411 "Arguments passed to qmail-inject programs.
412 This should be a list of strings, one string for each argument.
414 For e.g., if you wish to set the envelope sender address so that bounces
415 go to the right place or to deal with listserv's usage of that address, you
416 might set this variable to '(\"-f\" \"you@some.where\")."
417 :group 'message-sending
418 :type '(repeat string))
420 (defvar gnus-post-method)
421 (defvar gnus-select-method)
422 (defcustom message-post-method
423 (cond ((and (boundp 'gnus-post-method)
424 (listp gnus-post-method)
427 ((boundp 'gnus-select-method)
430 "*Method used to post news.
431 Note that when posting from inside Gnus, for instance, this
432 variable isn't used."
434 :group 'message-sending
435 ;; This should be the `gnus-select-method' widget, but that might
436 ;; create a dependence to `gnus.el'.
439 (defcustom message-generate-headers-first nil
440 "*If non-nil, generate all possible headers before composing."
441 :group 'message-headers
444 (defcustom message-setup-hook nil
445 "Normal hook, run each time a new outgoing message is initialized.
446 The function `message-setup' runs this hook."
447 :group 'message-various
450 (defcustom message-signature-setup-hook nil
451 "Normal hook, run each time a new outgoing message is initialized.
452 It is run after the headers have been inserted and before
453 the signature is inserted."
454 :group 'message-various
457 (defcustom message-mode-hook nil
458 "Hook run in message mode buffers."
459 :group 'message-various
462 (defcustom message-header-hook nil
463 "Hook run in a message mode buffer narrowed to the headers."
464 :group 'message-various
467 (defcustom message-header-setup-hook nil
468 "Hook called narrowed to the headers when setting up a message buffer."
469 :group 'message-various
473 (defcustom message-citation-line-function 'message-insert-citation-line
474 "*Function called to insert the \"Whomever writes:\" line."
476 :group 'message-insertion)
479 (defcustom message-yank-prefix "> "
480 "*Prefix inserted on the lines of yanked messages.
481 nil means use indentation."
483 :group 'message-insertion)
485 (defcustom message-indentation-spaces 3
486 "*Number of spaces to insert at the beginning of each cited line.
487 Used by `message-yank-original' via `message-yank-cite'."
488 :group 'message-insertion
492 (defcustom message-cite-function 'message-cite-original
493 "*Function for citing an original message.
494 Predefined functions include `message-cite-original' and
495 `message-cite-original-without-signature'.
496 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
497 :type '(radio (function-item message-cite-original)
498 (function-item sc-cite-original)
499 (function :tag "Other"))
500 :group 'message-insertion)
503 (defcustom message-indent-citation-function 'message-indent-citation
504 "*Function for modifying a citation just inserted in the mail buffer.
505 This can also be a list of functions. Each function can find the
506 citation between (point) and (mark t). And each function should leave
507 point and mark around the citation text as modified."
509 :group 'message-insertion)
511 (defvar message-abbrevs-loaded nil)
514 (defcustom message-signature t
515 "*String to be inserted at the end of the message buffer.
516 If t, the `message-signature-file' file will be inserted instead.
517 If a function, the result from the function will be used instead.
518 If a form, the result from the form will be used instead."
520 :group 'message-insertion)
523 (defcustom message-signature-file "~/.signature"
524 "*File containing the text inserted at end of message buffer."
526 :group 'message-insertion)
528 (defcustom message-distribution-function nil
529 "*Function called to return a Distribution header."
531 :group 'message-headers
534 (defcustom message-expires 14
535 "Number of days before your article expires."
537 :group 'message-headers
538 :link '(custom-manual "(message)News Headers")
541 (defcustom message-user-path nil
542 "If nil, use the NNTP server name in the Path header.
543 If stringp, use this; if non-nil, use no host name (user name only)."
545 :group 'message-headers
546 :link '(custom-manual "(message)News Headers")
547 :type '(choice (const :tag "nntp" nil)
549 (sexp :tag "none" :format "%t" t)))
551 (defvar message-reply-buffer nil)
552 (defvar message-reply-headers nil)
553 (defvar message-newsreader nil)
554 (defvar message-mailer nil)
555 (defvar message-sent-message-via nil)
556 (defvar message-checksum nil)
557 (defvar message-send-actions nil
558 "A list of actions to be performed upon successful sending of a message.")
559 (defvar message-exit-actions nil
560 "A list of actions to be performed upon exiting after sending a message.")
561 (defvar message-kill-actions nil
562 "A list of actions to be performed before killing a message buffer.")
563 (defvar message-postpone-actions nil
564 "A list of actions to be performed after postponing a message.")
566 (define-widget 'message-header-lines 'text
567 "All header lines must be LFD terminated."
570 :error "All header lines must be newline terminated")
572 (defcustom message-default-headers ""
573 "*A string containing header lines to be inserted in outgoing messages.
574 It is inserted before you edit the message, so you can edit or delete
576 :group 'message-headers
577 :type 'message-header-lines)
579 (defcustom message-default-mail-headers ""
580 "*A string of header lines to be inserted in outgoing mails."
581 :group 'message-headers
583 :type 'message-header-lines)
585 (defcustom message-default-news-headers ""
586 "*A string of header lines to be inserted in outgoing news
588 :group 'message-headers
590 :type 'message-header-lines)
592 ;; Note: could use /usr/ucb/mail instead of sendmail;
593 ;; options -t, and -v if not interactive.
594 (defcustom message-mailer-swallows-blank-line
595 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
596 system-configuration)
597 (file-readable-p "/etc/sendmail.cf")
598 (let ((buffer (get-buffer-create " *temp*")))
602 (insert-file-contents "/etc/sendmail.cf")
603 (goto-char (point-min))
604 (let ((case-fold-search nil))
605 (re-search-forward "^OR\\>" nil t)))
606 (kill-buffer buffer))))
607 ;; According to RFC822, "The field-name must be composed of printable
608 ;; ASCII characters (i. e., characters that have decimal values between
609 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
611 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
612 "*Set this non-nil if the system's mailer runs the header and body together.
613 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
614 The value should be an expression to test whether the problem will
616 :group 'message-sending
619 ;; Ignore errors in case this is used in Emacs 19.
620 ;; Don't use ignore-errors because this is copied into loaddefs.el.
623 (define-mail-user-agent 'message-user-agent
624 'message-mail 'message-send-and-exit
625 'message-kill-buffer 'message-send-hook)
628 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
629 "If non-nil, delete the deletable headers before feeding to mh.")
631 (defvar message-send-method-alist
632 '((news message-news-p message-send-via-news)
633 (mail message-mail-p message-send-via-mail))
634 "Alist of ways to send outgoing messages.
635 Each element has the form
637 \(TYPE PREDICATE FUNCTION)
639 where TYPE is a symbol that names the method; PREDICATE is a function
640 called without any parameters to determine whether the message is
641 a message of type TYPE; and FUNCTION is a function to be called if
642 PREDICATE returns non-nil. FUNCTION is called with one parameter --
645 (defvar message-mail-alias-type 'abbrev
646 "*What alias expansion type to use in Message buffers.
647 The default is `abbrev', which uses mailabbrev. nil switches
650 (defcustom message-auto-save-directory
651 (nnheader-concat message-directory "drafts/")
652 "*Directory where Message auto-saves buffers if Gnus isn't running.
653 If nil, Message won't auto-save."
654 :group 'message-buffers
657 (defcustom message-buffer-naming-style 'unique
658 "*The way new message buffers are named.
659 Valid valued are `unique' and `unsent'."
660 :group 'message-buffers
661 :type '(choice (const :tag "unique" unique)
662 (const :tag "unsent" unsent)))
664 ;;; Internal variables.
665 ;;; Well, not really internal.
667 (defvar message-mode-syntax-table
668 (let ((table (copy-syntax-table text-mode-syntax-table)))
669 (modify-syntax-entry ?% ". " table)
671 "Syntax table used while in Message mode.")
673 (defvar message-mode-abbrev-table text-mode-abbrev-table
674 "Abbrev table used in Message mode buffers.
675 Defaults to `text-mode-abbrev-table'.")
676 (defgroup message-headers nil
678 :link '(custom-manual "(message)Variables")
681 (defface message-header-to-face
684 (:foreground "green2" :bold t))
687 (:foreground "MidnightBlue" :bold t))
689 (:bold t :italic t)))
690 "Face used for displaying From headers."
691 :group 'message-faces)
693 (defface message-header-cc-face
696 (:foreground "green4" :bold t))
699 (:foreground "MidnightBlue"))
702 "Face used for displaying Cc headers."
703 :group 'message-faces)
705 (defface message-header-subject-face
708 (:foreground "green3"))
711 (:foreground "navy blue" :bold t))
714 "Face used for displaying subject headers."
715 :group 'message-faces)
717 (defface message-header-newsgroups-face
720 (:foreground "yellow" :bold t :italic t))
723 (:foreground "blue4" :bold t :italic t))
725 (:bold t :italic t)))
726 "Face used for displaying newsgroups headers."
727 :group 'message-faces)
729 (defface message-header-other-face
732 (:foreground "#b00000"))
735 (:foreground "steel blue"))
737 (:bold t :italic t)))
738 "Face used for displaying newsgroups headers."
739 :group 'message-faces)
741 (defface message-header-name-face
744 (:foreground "DarkGreen"))
747 (:foreground "cornflower blue"))
750 "Face used for displaying header names."
751 :group 'message-faces)
753 (defface message-header-xheader-face
756 (:foreground "blue"))
759 (:foreground "blue"))
762 "Face used for displaying X-Header headers."
763 :group 'message-faces)
765 (defface message-separator-face
768 (:foreground "blue3"))
771 (:foreground "brown"))
774 "Face used for displaying the separator."
775 :group 'message-faces)
777 (defface message-cited-text-face
786 "Face used for displaying cited text names."
787 :group 'message-faces)
789 (defvar message-font-lock-keywords
790 (let* ((cite-prefix "A-Za-z")
791 (cite-suffix (concat cite-prefix "0-9_.@-"))
792 (content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)"))
793 `((,(concat "^\\([Tt]o:\\)" content)
794 (1 'message-header-name-face)
795 (2 'message-header-to-face nil t))
796 (,(concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content)
797 (1 'message-header-name-face)
798 (2 'message-header-cc-face nil t))
799 (,(concat "^\\([Ss]ubject:\\)" content)
800 (1 'message-header-name-face)
801 (2 'message-header-subject-face nil t))
802 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content)
803 (1 'message-header-name-face)
804 (2 'message-header-newsgroups-face nil t))
805 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content)
806 (1 'message-header-name-face)
807 (2 'message-header-other-face nil t))
808 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content)
809 (1 'message-header-name-face)
810 (2 'message-header-name-face))
811 ,@(if (and mail-header-separator
812 (not (equal mail-header-separator "")))
813 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
814 1 'message-separator-face))
817 "\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
819 (0 'message-cited-text-face))))
820 "Additional expressions to highlight in Message mode.")
822 ;; XEmacs does it like this. For Emacs, we have to set the
823 ;; `font-lock-defaults' buffer-local variable.
824 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
826 (defvar message-face-alist
827 '((bold . bold-region)
828 (underline . underline-region)
829 (default . (lambda (b e)
831 (ununderline-region b e))))
832 "Alist of mail and news faces for facemenu.
833 The cdr of ech entry is a function for applying the face to a region.")
835 (defcustom message-send-hook nil
836 "Hook run before sending messages."
837 :group 'message-various
838 :options '(ispell-message)
841 (defcustom message-send-mail-hook nil
842 "Hook run before sending mail messages."
843 :group 'message-various
846 (defcustom message-send-news-hook nil
847 "Hook run before sending news messages."
848 :group 'message-various
851 (defcustom message-sent-hook nil
852 "Hook run after sending messages."
853 :group 'message-various
856 (defvar message-send-coding-system 'binary
857 "Coding system to encode outgoing mail.")
859 ;;; Internal variables.
861 (defvar message-default-charset nil)
862 (defvar message-buffer-list nil)
863 (defvar message-this-is-news nil)
864 (defvar message-this-is-mail nil)
865 (defvar message-draft-article nil)
867 ;; Byte-compiler warning
868 (defvar gnus-active-hashtb)
869 (defvar gnus-read-active-file)
871 ;;; Regexp matching the delimiter of messages in UNIX mail format
872 ;;; (UNIX From lines), minus the initial ^. It should be a copy
873 ;;; of rmail.el's rmail-unix-mail-delimiter.
874 (defvar message-unix-mail-delimiter
875 (let ((time-zone-regexp
876 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
877 "\\|[-+]?[0-9][0-9][0-9][0-9]"
883 ;; Many things can happen to an RFC 822 mailbox before it is put into
884 ;; a `From' line. The leading phrase can be stripped, e.g.
885 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
886 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
887 ;; can be removed, e.g.
888 ;; From: joe@y.z (Joe K
890 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
893 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
894 ;; The mailbox can be removed or be replaced by white space, e.g.
895 ;; From: "Joe User"{space}{tab}
897 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
898 ;; where {space} and {tab} represent the Ascii space and tab characters.
899 ;; We want to match the results of any of these manglings.
900 ;; The following regexp rejects names whose first characters are
901 ;; obviously bogus, but after that anything goes.
902 "\\([^\0-\b\n-\r\^?].*\\)? "
904 ;; The time the message was sent.
905 "\\([^\0-\r \^?]+\\) +" ; day of the week
906 "\\([^\0-\r \^?]+\\) +" ; month
907 "\\([0-3]?[0-9]\\) +" ; day of month
908 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
910 ;; Perhaps a time zone, specified by an abbreviation, or by a
915 " \\([0-9][0-9]+\\) *"
917 ;; On some systems the time zone can appear after the year, too.
921 "\\(remote from .*\\)?"
924 "Regexp matching the delimiter of messages in UNIX mail format.")
926 (defvar message-unsent-separator
927 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
928 "^ *---+ +Returned message +---+ *$\\|"
929 "^Start of returned message$\\|"
930 "^ *---+ +Original message +---+ *$\\|"
931 "^ *--+ +begin message +--+ *$\\|"
932 "^ *---+ +Original message follows +---+ *$\\|"
933 "^|? *---+ +Message text follows: +---+ *|?$")
934 "A regexp that matches the separator before the text of a failed message.")
936 (defvar message-header-format-alist
938 (To . message-fill-address)
939 (Cc . message-fill-address)
950 (References . message-shorten-references)
952 "Alist used for formatting headers.")
955 (autoload 'message-setup-toolbar "messagexmas")
956 (autoload 'mh-new-draft-name "mh-comp")
957 (autoload 'mh-send-letter "mh-comp")
958 (autoload 'gnus-point-at-eol "gnus-util")
959 (autoload 'gnus-point-at-bol "gnus-util")
960 (autoload 'gnus-output-to-mail "gnus-util")
961 (autoload 'mail-abbrev-in-expansion-header-p "mailabbrev")
962 (autoload 'nndraft-request-associate-buffer "nndraft")
963 (autoload 'nndraft-request-expire-articles "nndraft")
964 (autoload 'gnus-open-server "gnus-int")
965 (autoload 'gnus-request-post "gnus-int")
966 (autoload 'gnus-alive-p "gnus-util")
967 (autoload 'rmail-output "rmail"))
972 ;;; Utility functions.
975 (defmacro message-y-or-n-p (question show &rest text)
976 "Ask QUESTION, displaying the rest of the arguments in a temp. buffer if SHOW"
977 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
979 ;; Delete the current line (and the next N lines.);
980 (defmacro message-delete-line (&optional n)
981 `(delete-region (progn (beginning-of-line) (point))
982 (progn (forward-line ,(or n 1)) (point))))
984 (defun message-tokenize-header (header &optional separator)
985 "Split HEADER into a list of header elements.
986 \",\" is used as the separator."
989 (let ((regexp (format "[%s]+" (or separator ",")))
994 (message-set-work-buffer)
996 (goto-char (point-min))
1001 (cond ((and (> (point) beg)
1003 (and (looking-at regexp)
1006 (push (buffer-substring beg (point)) elems)
1007 (setq beg (match-end 0)))
1008 ((eq (char-after) ?\")
1009 (setq quoted (not quoted)))
1010 ((and (eq (char-after) ?\()
1013 ((and (eq (char-after) ?\))
1016 (nreverse elems)))))
1018 (defun message-mail-file-mbox-p (file)
1019 "Say whether FILE looks like a Unix mbox file."
1020 (when (and (file-exists-p file)
1021 (file-readable-p file)
1022 (file-regular-p file))
1024 (nnheader-insert-file-contents file)
1025 (goto-char (point-min))
1026 (looking-at message-unix-mail-delimiter))))
1028 (defun message-fetch-field (header &optional not-all)
1029 "The same as `mail-fetch-field', only remove all newlines."
1030 (let* ((inhibit-point-motion-hooks t)
1031 (value (mail-fetch-field header nil (not not-all))))
1033 (while (string-match "\n[\t ]+" value)
1034 (setq value (replace-match " " t t value)))
1037 (defun message-narrow-to-field ()
1038 "Narrow the buffer to the header on the current line."
1044 (if (re-search-forward "^[^ \n\t]" nil t)
1049 (goto-char (point-min)))
1051 (defun message-add-header (&rest headers)
1052 "Add the HEADERS to the message header, skipping those already present."
1055 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1056 (error "Invalid header `%s'" (car headers)))
1057 (setq hclean (match-string 1 (car headers)))
1059 (message-narrow-to-headers)
1060 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1061 (insert (car headers) ?\n))))
1062 (setq headers (cdr headers))))
1064 (defun message-fetch-reply-field (header)
1065 "Fetch FIELD from the message we're replying to."
1066 (when (and message-reply-buffer
1067 (buffer-name message-reply-buffer))
1069 (set-buffer message-reply-buffer)
1070 (message-fetch-field header))))
1072 (defun message-set-work-buffer ()
1073 (if (get-buffer " *message work*")
1075 (set-buffer " *message work*")
1077 (set-buffer (get-buffer-create " *message work*"))
1078 (kill-all-local-variables)
1079 (mm-enable-multibyte)))
1081 (defun message-functionp (form)
1082 "Return non-nil if FORM is funcallable."
1083 (or (and (symbolp form) (fboundp form))
1084 (and (listp form) (eq (car form) 'lambda))
1085 (byte-code-function-p form)))
1087 (defun message-strip-subject-re (subject)
1088 "Remove \"Re:\" from subject lines."
1089 (if (string-match message-subject-re-regexp subject)
1090 (substring subject (match-end 0))
1093 (defun message-remove-header (header &optional is-regexp first reverse)
1094 "Remove HEADER in the narrowed buffer.
1095 If REGEXP, HEADER is a regular expression.
1096 If FIRST, only remove the first instance of the header.
1097 Return the number of headers removed."
1098 (goto-char (point-min))
1099 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
1101 (case-fold-search t)
1103 (while (and (not (eobp))
1106 (not (looking-at regexp))
1107 (looking-at regexp))
1114 ;; There might be a continuation header, so we have to search
1115 ;; until we find a new non-continuation line.
1118 (if (re-search-forward "^[^ \t]" nil t)
1119 (goto-char (match-beginning 0))
1122 (if (re-search-forward "^[^ \t]" nil t)
1123 (goto-char (match-beginning 0))
1127 (defun message-narrow-to-headers ()
1128 "Narrow the buffer to the head of the message."
1131 (goto-char (point-min))
1132 (if (re-search-forward
1133 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1136 (goto-char (point-min)))
1138 (defun message-narrow-to-head ()
1139 "Narrow the buffer to the head of the message.
1140 Point is left at the beginning of the narrowed-to region."
1143 (goto-char (point-min))
1144 (if (search-forward "\n\n" nil 1)
1147 (goto-char (point-min)))
1149 (defun message-narrow-to-headers-or-head ()
1150 "Narrow the buffer to the head of the message."
1153 (goto-char (point-min))
1156 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1157 (match-beginning 0))
1158 ((search-forward "\n\n" nil t)
1162 (goto-char (point-min)))
1164 (defun message-news-p ()
1165 "Say whether the current buffer contains a news message."
1166 (and (not message-this-is-mail)
1167 (or message-this-is-news
1170 (message-narrow-to-headers)
1171 (and (message-fetch-field "newsgroups")
1172 (not (message-fetch-field "posted-to"))))))))
1174 (defun message-mail-p ()
1175 "Say whether the current buffer contains a mail message."
1176 (and (not message-this-is-news)
1177 (or message-this-is-mail
1180 (message-narrow-to-headers)
1181 (or (message-fetch-field "to")
1182 (message-fetch-field "cc")
1183 (message-fetch-field "bcc")))))))
1185 (defun message-next-header ()
1186 "Go to the beginning of the next header."
1188 (or (eobp) (forward-char 1))
1189 (not (if (re-search-forward "^[^ \t]" nil t)
1191 (goto-char (point-max)))))
1193 (defun message-sort-headers-1 ()
1194 "Sort the buffer as headers using `message-rank' text props."
1195 (goto-char (point-min))
1197 nil 'message-next-header
1199 (message-next-header)
1203 (or (get-text-property (point) 'message-rank)
1206 (defun message-sort-headers ()
1207 "Sort the headers of the current message according to `message-header-format-alist'."
1211 (let ((max (1+ (length message-header-format-alist)))
1213 (message-narrow-to-headers)
1214 (while (re-search-forward "^[^ \n]+:" nil t)
1216 (match-beginning 0) (1+ (match-beginning 0))
1218 (if (setq rank (length (memq (assq (intern (buffer-substring
1220 (1- (match-end 0))))
1221 message-header-format-alist)
1222 message-header-format-alist)))
1225 (message-sort-headers-1))))
1235 (defvar message-mode-map nil)
1237 (unless message-mode-map
1238 (setq message-mode-map (make-keymap))
1239 (set-keymap-parent message-mode-map text-mode-map)
1240 (define-key message-mode-map "\C-c?" 'describe-mode)
1242 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
1243 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
1244 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
1245 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
1246 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
1247 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
1248 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
1249 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
1250 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
1251 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
1252 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
1253 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
1254 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
1256 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
1257 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
1259 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
1260 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
1261 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
1262 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
1263 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
1264 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
1266 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
1267 (define-key message-mode-map "\C-c\C-s" 'message-send)
1268 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
1269 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
1271 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
1272 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
1273 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
1274 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
1276 (define-key message-mode-map "\t" 'message-tab))
1279 message-mode-menu message-mode-map "Message Menu."
1281 ["Sort Headers" message-sort-headers t]
1282 ["Yank Original" message-yank-original t]
1283 ["Fill Yanked Message" message-fill-yanked-message t]
1284 ["Insert Signature" message-insert-signature t]
1285 ["Caesar (rot13) Message" message-caesar-buffer-body t]
1286 ["Caesar (rot13) Region" message-caesar-region (mark t)]
1287 ["Elide Region" message-elide-region (mark t)]
1288 ["Delete Outside Region" message-delete-not-region (mark t)]
1289 ["Kill To Signature" message-kill-to-signature t]
1290 ["Newline and Reformat" message-newline-and-reformat t]
1291 ["Rename buffer" message-rename-buffer t]
1292 ["Spellcheck" ispell-message t]
1294 ["Send Message" message-send-and-exit t]
1295 ["Abort Message" message-dont-send t]
1296 ["Kill Message" message-kill-buffer t]))
1299 message-mode-field-menu message-mode-map ""
1301 ["Fetch To" message-insert-to t]
1302 ["Fetch Newsgroups" message-insert-newsgroups t]
1304 ["To" message-goto-to t]
1305 ["Subject" message-goto-subject t]
1306 ["Cc" message-goto-cc t]
1307 ["Reply-To" message-goto-reply-to t]
1308 ["Summary" message-goto-summary t]
1309 ["Keywords" message-goto-keywords t]
1310 ["Newsgroups" message-goto-newsgroups t]
1311 ["Followup-To" message-goto-followup-to t]
1312 ["Distribution" message-goto-distribution t]
1313 ["Body" message-goto-body t]
1314 ["Signature" message-goto-signature t]))
1316 (defvar facemenu-add-face-function)
1317 (defvar facemenu-remove-face-function)
1320 (defun message-mode ()
1321 "Major mode for editing mail and news to be sent.
1322 Like Text Mode but with these additional commands:
1323 C-c C-s message-send (send the message) C-c C-c message-send-and-exit
1324 C-c C-f move to a header field (and create it if there isn't):
1325 C-c C-f C-t move to To C-c C-f C-s move to Subject
1326 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1327 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1328 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1329 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1330 C-c C-f C-f move to Followup-To
1331 C-c C-t message-insert-to (add a To header to a news followup)
1332 C-c C-n message-insert-newsgroups (add a Newsgroup header to a news reply)
1333 C-c C-b message-goto-body (move to beginning of message text).
1334 C-c C-i message-goto-signature (move to the beginning of the signature).
1335 C-c C-w message-insert-signature (insert `message-signature-file' file).
1336 C-c C-y message-yank-original (insert current message, if any).
1337 C-c C-q message-fill-yanked-message (fill what was yanked).
1338 C-c C-e message-elide-region (elide the text between point and mark).
1339 C-c C-v message-delete-not-region (remove the text outside the region).
1340 C-c C-z message-kill-to-signature (kill the text up to the signature).
1341 C-c C-r message-caesar-buffer-body (rot13 the message body)."
1343 (kill-all-local-variables)
1344 (make-local-variable 'message-reply-buffer)
1345 (setq message-reply-buffer nil)
1346 (make-local-variable 'message-send-actions)
1347 (make-local-variable 'message-exit-actions)
1348 (make-local-variable 'message-kill-actions)
1349 (make-local-variable 'message-postpone-actions)
1350 (make-local-variable 'message-draft-article)
1351 (make-local-hook 'kill-buffer-hook)
1352 (set-syntax-table message-mode-syntax-table)
1353 (use-local-map message-mode-map)
1354 (setq local-abbrev-table message-mode-abbrev-table)
1355 (setq major-mode 'message-mode)
1356 (setq mode-name "Message")
1357 (setq buffer-offer-save t)
1358 (make-local-variable 'facemenu-add-face-function)
1359 (make-local-variable 'facemenu-remove-face-function)
1360 (setq facemenu-add-face-function
1362 (let ((face-fun (cdr (assq face message-face-alist))))
1364 (funcall face-fun (point) end)
1365 (error "Face %s not configured for %s mode" face mode-name)))
1367 facemenu-remove-face-function t)
1368 (make-local-variable 'paragraph-separate)
1369 (make-local-variable 'paragraph-start)
1370 ;; `-- ' precedes the signature. `-----' appears at the start of the
1371 ;; lines that delimit forwarded messages.
1372 ;; Lines containing just >= 3 dashes, perhaps after whitespace,
1373 ;; are also sometimes used and should be separators.
1374 (setq paragraph-start
1375 (concat (regexp-quote mail-header-separator)
1376 "$\\|[ \t]*[a-z0-9A-Z]*>+[ \t]*$\\|[ \t]*$\\|"
1379 ;;!!! Uhm... shurely this can't be right?
1380 "[> " (regexp-quote message-yank-prefix) "]+$"))
1381 (setq paragraph-separate paragraph-start)
1382 (make-local-variable 'message-reply-headers)
1383 (setq message-reply-headers nil)
1384 (make-local-variable 'message-newsreader)
1385 (make-local-variable 'message-mailer)
1386 (make-local-variable 'message-post-method)
1387 (make-local-variable 'message-sent-message-via)
1388 (setq message-sent-message-via nil)
1389 (make-local-variable 'message-checksum)
1390 (setq message-checksum nil)
1391 ;;(when (fboundp 'mail-hist-define-keys)
1392 ;; (mail-hist-define-keys))
1393 (when (string-match "XEmacs\\|Lucid" emacs-version)
1394 (message-setup-toolbar))
1395 (easy-menu-add message-mode-menu message-mode-map)
1396 (easy-menu-add message-mode-field-menu message-mode-map)
1397 ;; Allow mail alias things.
1398 (when (eq message-mail-alias-type 'abbrev)
1399 (if (fboundp 'mail-abbrevs-setup)
1400 (mail-abbrevs-setup)
1401 (mail-aliases-setup)))
1402 (message-set-auto-save-file-name)
1403 (unless (string-match "XEmacs" emacs-version)
1404 (set (make-local-variable 'font-lock-defaults)
1405 '(message-font-lock-keywords t)))
1406 (make-local-variable 'adaptive-fill-regexp)
1407 (setq adaptive-fill-regexp
1408 (concat "[ \t]*[-a-z0-9A-Z]*>+[ \t]*\\|" adaptive-fill-regexp))
1409 (unless (boundp 'adaptive-fill-first-line-regexp)
1410 (setq adaptive-fill-first-line-regexp nil))
1411 (make-local-variable 'adaptive-fill-first-line-regexp)
1412 (setq adaptive-fill-first-line-regexp
1413 (concat "[ \t]*[-a-z0-9A-Z]*>+[ \t]*\\|"
1414 adaptive-fill-first-line-regexp))
1415 (mm-enable-multibyte)
1416 (run-hooks 'text-mode-hook 'message-mode-hook))
1421 ;;; Message mode commands
1424 ;;; Movement commands
1426 (defun message-goto-to ()
1427 "Move point to the To header."
1429 (message-position-on-field "To"))
1431 (defun message-goto-subject ()
1432 "Move point to the Subject header."
1434 (message-position-on-field "Subject"))
1436 (defun message-goto-cc ()
1437 "Move point to the Cc header."
1439 (message-position-on-field "Cc" "To"))
1441 (defun message-goto-bcc ()
1442 "Move point to the Bcc header."
1444 (message-position-on-field "Bcc" "Cc" "To"))
1446 (defun message-goto-fcc ()
1447 "Move point to the Fcc header."
1449 (message-position-on-field "Fcc" "To" "Newsgroups"))
1451 (defun message-goto-reply-to ()
1452 "Move point to the Reply-To header."
1454 (message-position-on-field "Reply-To" "Subject"))
1456 (defun message-goto-newsgroups ()
1457 "Move point to the Newsgroups header."
1459 (message-position-on-field "Newsgroups"))
1461 (defun message-goto-distribution ()
1462 "Move point to the Distribution header."
1464 (message-position-on-field "Distribution"))
1466 (defun message-goto-followup-to ()
1467 "Move point to the Followup-To header."
1469 (message-position-on-field "Followup-To" "Newsgroups"))
1471 (defun message-goto-keywords ()
1472 "Move point to the Keywords header."
1474 (message-position-on-field "Keywords" "Subject"))
1476 (defun message-goto-summary ()
1477 "Move point to the Summary header."
1479 (message-position-on-field "Summary" "Subject"))
1481 (defun message-goto-body ()
1482 "Move point to the beginning of the message body."
1484 (if (looking-at "[ \t]*\n") (expand-abbrev))
1485 (goto-char (point-min))
1486 (search-forward (concat "\n" mail-header-separator "\n") nil t))
1488 (defun message-goto-eoh ()
1489 "Move point to the end of the headers."
1494 (defun message-goto-signature ()
1495 "Move point to the beginning of the message signature.
1496 If there is no signature in the article, go to the end and
1499 (goto-char (point-min))
1500 (if (re-search-forward message-signature-separator nil t)
1502 (goto-char (point-max))
1507 (defun message-insert-to (&optional force)
1508 "Insert a To header that points to the author of the article being replied to.
1509 If the original author requested not to be sent mail, the function signals
1511 With the prefix argument FORCE, insert the header anyway."
1513 (let ((co (message-fetch-reply-field "mail-copies-to")))
1514 (when (and (null force)
1516 (or (equal (downcase co) "never")
1517 (equal (downcase co) "nobody")))
1518 (error "The user has requested not to have copies sent via mail")))
1519 (when (and (message-position-on-field "To")
1520 (mail-fetch-field "to")
1521 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
1523 (insert (or (message-fetch-reply-field "reply-to")
1524 (message-fetch-reply-field "from") "")))
1526 (defun message-insert-newsgroups ()
1527 "Insert the Newsgroups header from the article being replied to."
1529 (when (and (message-position-on-field "Newsgroups")
1530 (mail-fetch-field "newsgroups")
1531 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
1533 (insert (or (message-fetch-reply-field "newsgroups") "")))
1537 ;;; Various commands
1539 (defun message-delete-not-region (beg end)
1540 "Delete everything in the body of the current message that is outside of the region."
1544 (delete-region (point) (if (not (message-goto-signature))
1550 (delete-region beg (progn (message-goto-body)
1553 (when (message-goto-signature)
1556 (defun message-kill-to-signature ()
1557 "Deletes all text up to the signature."
1559 (let ((point (point)))
1560 (message-goto-signature)
1563 (kill-region point (point))
1567 (defun message-newline-and-reformat ()
1568 "Insert four newlines, and then reformat if inside quoted text."
1570 (let ((point (point))
1574 (setq quoted (looking-at (regexp-quote message-yank-prefix))))
1577 (insert message-yank-prefix))
1578 (fill-paragraph nil)
1582 (defun message-insert-signature (&optional force)
1583 "Insert a signature. See documentation for the `message-signature' variable."
1584 (interactive (list 0))
1587 ((and (null message-signature)
1590 (goto-char (point-max))
1591 (not (re-search-backward
1592 message-signature-separator nil t))))
1593 ((and (null message-signature)
1596 ((message-functionp message-signature)
1597 (funcall message-signature))
1598 ((listp message-signature)
1599 (eval message-signature))
1600 (t message-signature)))
1602 (cond ((stringp signature)
1604 ((and (eq t signature)
1605 message-signature-file
1606 (file-exists-p message-signature-file))
1609 (goto-char (point-max))
1610 ;; Insert the signature.
1614 (if (eq signature t)
1615 (insert-file-contents message-signature-file)
1617 (goto-char (point-max))
1618 (or (bolp) (insert "\n")))))
1620 (defun message-elide-region (b e)
1621 "Elide the text between point and mark.
1622 An ellipsis (from `message-elide-elipsis') will be inserted where the
1628 (insert message-elide-elipsis))
1630 (defvar message-caesar-translation-table nil)
1632 (defun message-caesar-region (b e &optional n)
1633 "Caesar rotation of region by N, default 13, for decrypting netnews."
1636 (min (point) (or (mark t) (point)))
1637 (max (point) (or (mark t) (point)))
1638 (when current-prefix-arg
1639 (prefix-numeric-value current-prefix-arg))))
1641 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
1642 (unless (or (zerop n) ; no action needed for a rot of 0
1643 (= b e)) ; no region to rotate
1644 ;; We build the table, if necessary.
1645 (when (or (not message-caesar-translation-table)
1646 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
1647 (setq message-caesar-translation-table
1648 (message-make-caesar-translation-table n)))
1649 ;; Then we translate the region. Do it this way to retain
1652 (when (< (char-after b) 255)
1653 (subst-char-in-region
1654 b (1+ b) (char-after b)
1655 (aref message-caesar-translation-table (char-after b))))
1658 (defun message-make-caesar-translation-table (n)
1659 "Create a rot table with offset N."
1661 (table (make-string 256 0)))
1662 (while (< (incf i) 256)
1665 (substring table 0 ?A)
1666 (substring table (+ ?A n) (+ ?A n (- 26 n)))
1667 (substring table ?A (+ ?A n))
1668 (substring table (+ ?A 26) ?a)
1669 (substring table (+ ?a n) (+ ?a n (- 26 n)))
1670 (substring table ?a (+ ?a n))
1671 (substring table (+ ?a 26) 255))))
1673 (defun message-caesar-buffer-body (&optional rotnum)
1674 "Caesar rotates all letters in the current buffer by 13 places.
1675 Used to encode/decode possiblyun offensive messages (commonly in net.jokes).
1676 With prefix arg, specifies the number of places to rotate each letter forward.
1677 Mail and USENET news headers are not rotated."
1678 (interactive (if current-prefix-arg
1679 (list (prefix-numeric-value current-prefix-arg))
1683 (when (message-goto-body)
1684 (narrow-to-region (point) (point-max)))
1685 (message-caesar-region (point-min) (point-max) rotnum))))
1687 (defun message-pipe-buffer-body (program)
1688 "Pipe the message body in the current buffer through PROGRAM."
1691 (when (message-goto-body)
1692 (narrow-to-region (point) (point-max)))
1693 (let ((body (buffer-substring (point-min) (point-max))))
1694 (unless (equal 0 (call-process-region
1695 (point-min) (point-max) program t t))
1697 (message "%s failed." program))))))
1699 (defun message-rename-buffer (&optional enter-string)
1700 "Rename the *message* buffer to \"*message* RECIPIENT\".
1701 If the function is run with a prefix, it will ask for a new buffer
1702 name, rather than giving an automatic name."
1703 (interactive "Pbuffer name: ")
1706 (goto-char (point-min))
1707 (narrow-to-region (point)
1708 (search-forward mail-header-separator nil 'end))
1710 (if (message-news-p) (message-fetch-field "Newsgroups")
1711 (message-fetch-field "To"))
1714 (if (string-match "," mail-to)
1715 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
1717 (name-default (concat "*message* " mail-trimmed-to))
1718 (name (if enter-string
1719 (read-string "New buffer name: " name-default)
1721 (rename-buffer name t)))))
1723 (defun message-fill-yanked-message (&optional justifyp)
1724 "Fill the paragraphs of a message yanked into this one.
1725 Numeric argument means justify as well."
1728 (goto-char (point-min))
1729 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1730 (let ((fill-prefix message-yank-prefix))
1731 (fill-individual-paragraphs (point) (point-max) justifyp t))))
1733 (defun message-indent-citation ()
1734 "Modify text just inserted from a message to be cited.
1735 The inserted text should be the region.
1736 When this function returns, the region is again around the modified text.
1738 Normally, indent each nonblank line `message-indentation-spaces' spaces.
1739 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
1740 (let ((start (point)))
1741 ;; Remove unwanted headers.
1742 (when message-ignored-cited-headers
1747 (if (search-forward "\n\n" nil t)
1750 (message-remove-header message-ignored-cited-headers t)
1751 (when (= (point-min) (point-max))
1752 (setq all-removed t))
1753 (goto-char (point-max)))
1757 ;; Delete blank lines at the start of the buffer.
1758 (while (and (point-min)
1761 (message-delete-line))
1762 ;; Delete blank lines at the end of the buffer.
1763 (goto-char (point-max))
1766 (while (and (zerop (forward-line -1))
1768 (message-delete-line))
1769 ;; Do the indentation.
1770 (if (null message-yank-prefix)
1771 (indent-rigidly start (mark t) message-indentation-spaces)
1774 (while (< (point) (mark t))
1775 (insert message-yank-prefix)
1779 (defun message-yank-original (&optional arg)
1780 "Insert the message being replied to, if any.
1781 Puts point before the text and mark after.
1782 Normally indents each nonblank line ARG spaces (default 3). However,
1783 if `message-yank-prefix' is non-nil, insert that prefix on each line.
1785 This function uses `message-cite-function' to do the actual citing.
1787 Just \\[universal-argument] as argument means don't indent, insert no
1788 prefix, and don't delete any headers."
1790 (let ((modified (buffer-modified-p)))
1791 (when (and message-reply-buffer
1792 message-cite-function)
1793 (delete-windows-on message-reply-buffer t)
1794 (insert-buffer message-reply-buffer)
1795 (funcall message-cite-function)
1796 (message-exchange-point-and-mark)
1800 (setq message-checksum (message-checksum))))))
1802 (defun message-cite-original-without-signature ()
1803 "Cite function in the standard Message manner."
1804 (let ((start (point))
1807 (when message-indent-citation-function
1808 (if (listp message-indent-citation-function)
1809 message-indent-citation-function
1810 (list message-indent-citation-function)))))
1812 (when (re-search-backward "^-- $" start t)
1813 ;; Also peel off any blank lines before the signature.
1815 (while (looking-at "^[ \t]*$")
1818 (delete-region (point) end))
1821 (funcall (pop functions)))
1822 (when message-citation-line-function
1825 (funcall message-citation-line-function))))
1827 (defvar mail-citation-hook) ;Compiler directive
1828 (defun message-cite-original ()
1829 "Cite function in the standard Message manner."
1830 (if (and (boundp 'mail-citation-hook)
1832 (run-hooks 'mail-citation-hook)
1833 (let ((start (point))
1835 (when message-indent-citation-function
1836 (if (listp message-indent-citation-function)
1837 message-indent-citation-function
1838 (list message-indent-citation-function)))))
1841 (funcall (pop functions)))
1842 (when message-citation-line-function
1845 (funcall message-citation-line-function)))))
1847 (defun message-insert-citation-line ()
1848 "Function that inserts a simple citation line."
1849 (when message-reply-headers
1850 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
1852 (defun message-position-on-field (header &rest afters)
1853 (let ((case-fold-search t))
1856 (goto-char (point-min))
1859 (concat "^" (regexp-quote mail-header-separator) "$"))
1860 (match-beginning 0)))
1861 (goto-char (point-min))
1862 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
1864 (re-search-forward "^[^ \t]" nil 'move)
1866 (skip-chars-backward "\n")
1869 (not (re-search-forward
1870 (concat "^" (regexp-quote (car afters)) ":")
1874 (re-search-forward "^[^ \t]" nil 'move)
1875 (beginning-of-line))
1876 (insert header ": \n")
1880 (defun message-remove-signature ()
1881 "Remove the signature from the text between point and mark.
1882 The text will also be indented the normal way."
1884 (let ((start (point))
1886 (if (not (re-search-forward message-signature-separator (mark t) t))
1887 ;; No signature here, so we just indent the cited text.
1888 (message-indent-citation)
1889 ;; Find the last non-empty line.
1891 (while (looking-at "[ \t]*$")
1894 (setq mark (set-marker (make-marker) (point)))
1896 (message-indent-citation)
1897 ;; Enable undoing the deletion.
1899 (delete-region mark (mark t))
1900 (set-marker mark nil)))))
1905 ;;; Sending messages
1908 (defun message-send-and-exit (&optional arg)
1909 "Send message like `message-send', then, if no errors, exit from mail buffer."
1911 (let ((buf (current-buffer))
1912 (actions message-exit-actions))
1913 (when (and (message-send arg)
1915 (if message-kill-buffer-on-exit
1918 (when (eq buf (current-buffer))
1919 (message-bury buf)))
1920 (message-do-actions actions)
1923 (defun message-dont-send ()
1924 "Don't send the message you have been editing."
1926 (set-buffer-modified-p t)
1928 (let ((actions message-postpone-actions))
1929 (message-bury (current-buffer))
1930 (message-do-actions actions)))
1932 (defun message-kill-buffer ()
1933 "Kill the current buffer."
1935 (when (or (not (buffer-modified-p))
1936 (yes-or-no-p "Message modified; kill anyway? "))
1937 (let ((actions message-kill-actions))
1938 (setq buffer-file-name nil)
1939 (kill-buffer (current-buffer))
1940 (message-do-actions actions))))
1942 (defun message-bury (buffer)
1943 "Bury this mail buffer."
1944 (let ((newbuf (other-buffer buffer)))
1945 (bury-buffer buffer)
1946 (if (and (fboundp 'frame-parameters)
1947 (cdr (assq 'dedicated (frame-parameters)))
1948 (not (null (delq (selected-frame) (visible-frame-list)))))
1949 (delete-frame (selected-frame))
1950 (switch-to-buffer newbuf))))
1952 (defun message-send (&optional arg)
1953 "Send the message in the current buffer.
1954 If `message-interactive' is non-nil, wait for success indication
1955 or error messages, and inform user.
1956 Otherwise any failure is reported in a message back to
1957 the user from the mailer."
1959 ;; Make it possible to undo the coming changes.
1961 (let ((inhibit-read-only t))
1962 (put-text-property (point-min) (point-max) 'read-only nil))
1963 (message-fix-before-sending)
1964 (run-hooks 'message-send-hook)
1965 (message "Sending...")
1966 (let ((alist message-send-method-alist)
1970 (setq elem (pop alist)))
1971 (when (and (or (not (funcall (cadr elem)))
1972 (and (or (not (memq (car elem)
1973 message-sent-message-via))
1976 "Already sent message via %s; resend? "
1978 (setq success (funcall (caddr elem) arg)))))
1980 (when (and success sent)
1982 ;;(when (fboundp 'mail-hist-put-headers-into-history)
1983 ;; (mail-hist-put-headers-into-history))
1984 (run-hooks 'message-sent-hook)
1985 (message "Sending...done")
1986 ;; Mark the buffer as unmodified and delete auto-save.
1987 (set-buffer-modified-p nil)
1988 (delete-auto-save-file-if-necessary t)
1989 (message-disassociate-draft)
1990 ;; Delete other mail buffers and stuff.
1991 (message-do-send-housekeeping)
1992 (message-do-actions message-send-actions)
1996 (defun message-send-via-mail (arg)
1997 "Send the current message via mail."
1998 (message-send-mail arg))
2000 (defun message-send-via-news (arg)
2001 "Send the current message via news."
2002 (funcall message-send-news-function arg))
2004 (defmacro message-check (type &rest forms)
2005 "Eval FORMS if TYPE is to be checked."
2006 `(or (message-check-element ,type)
2010 (put 'message-check 'lisp-indent-function 1)
2011 (put 'message-check 'edebug-form-spec '(form body))
2013 (defun message-fix-before-sending ()
2014 "Do various things to make the message nice before sending it."
2015 ;; Make sure there's a newline at the end of the message.
2016 (goto-char (point-max))
2019 ;; Delete all invisible text.
2020 (message-check 'invisible-text
2021 (when (text-property-any (point-min) (point-max) 'invisible t)
2022 (put-text-property (point-min) (point-max) 'invisible nil)
2023 (unless (yes-or-no-p "Invisible text found and made visible; continue posting? ")
2024 (error "Invisible text found and made visible")))))
2026 (defun message-add-action (action &rest types)
2027 "Add ACTION to be performed when doing an exit of type TYPES."
2030 (set (setq var (intern (format "message-%s-actions" (pop types))))
2031 (nconc (symbol-value var) (list action))))))
2033 (defun message-do-actions (actions)
2034 "Perform all actions in ACTIONS."
2035 ;; Now perform actions on successful sending.
2039 ;; A simple function.
2040 ((message-functionp (car actions))
2041 (funcall (car actions)))
2042 ;; Something to be evaled.
2044 (eval (car actions)))))
2047 (defun message-send-mail (&optional arg)
2048 (require 'mail-utils)
2049 (let ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
2050 (case-fold-search nil)
2051 (news (message-news-p))
2052 (mailbuf (current-buffer)))
2054 (message-narrow-to-headers)
2055 ;; Insert some headers.
2056 (let ((message-deletable-headers
2057 (if news nil message-deletable-headers)))
2058 (message-generate-headers message-required-mail-headers))
2059 (mail-encode-encoded-word-buffer)
2060 ;; Let the user do all of the above.
2061 (run-hooks 'message-header-hook))
2062 (message-encode-message-body)
2067 ;; Avoid copying text props.
2069 "%s" (save-excursion
2070 (set-buffer mailbuf)
2072 ;; Remove some headers.
2074 (message-narrow-to-headers)
2075 ;; Remove some headers.
2076 (message-remove-header message-ignored-mail-headers t))
2077 (goto-char (point-max))
2078 ;; require one newline at the end.
2079 (or (= (preceding-char) ?\n)
2082 (or (message-fetch-field "cc")
2083 (message-fetch-field "to")))
2084 (message-insert-courtesy-copy))
2085 (funcall message-send-mail-function))
2086 (kill-buffer tembuf))
2087 (set-buffer mailbuf)
2088 (push 'mail message-sent-message-via)))
2090 (defun message-send-mail-with-sendmail ()
2091 "Send off the prepared buffer with sendmail."
2092 (let ((errbuf (if message-interactive
2093 (generate-new-buffer " sendmail errors")
2095 resend-to-addresses delimline)
2096 (let ((case-fold-search t))
2098 (message-narrow-to-headers)
2099 (setq resend-to-addresses (message-fetch-field "resent-to")))
2100 ;; Change header-delimiter to be what sendmail expects.
2101 (goto-char (point-min))
2103 (concat "^" (regexp-quote mail-header-separator) "\n"))
2104 (replace-match "\n")
2106 (setq delimline (point-marker))
2107 (run-hooks 'message-send-mail-hook)
2108 ;; Insert an extra newline if we need it to work around
2109 ;; Sun's bug that swallows newlines.
2110 (goto-char (1+ delimline))
2111 (when (eval message-mailer-swallows-blank-line)
2113 (when message-interactive
2117 (let ((default-directory "/")
2118 (coding-system-for-write message-send-coding-system))
2119 (apply 'call-process-region
2120 (append (list (point-min) (point-max)
2121 (if (boundp 'sendmail-program)
2123 "/usr/lib/sendmail")
2124 nil errbuf nil "-oi")
2125 ;; Always specify who from,
2126 ;; since some systems have broken sendmails.
2127 ;; But some systems are more broken with -f, so
2128 ;; we'll let users override this.
2129 (if (null message-sendmail-f-is-evil)
2130 (list "-f" (user-login-name)))
2131 ;; These mean "report errors by mail"
2132 ;; and "deliver in background".
2133 (if (null message-interactive) '("-oem" "-odb"))
2134 ;; Get the addresses from the message
2135 ;; unless this is a resend.
2136 ;; We must not do that for a resend
2137 ;; because we would find the original addresses.
2138 ;; For a resend, include the specific addresses.
2139 (if resend-to-addresses
2140 (list resend-to-addresses)
2142 (when message-interactive
2145 (goto-char (point-min))
2146 (while (re-search-forward "\n\n* *" nil t)
2147 (replace-match "; "))
2148 (if (not (zerop (buffer-size)))
2149 (error "Sending...failed to %s"
2150 (buffer-substring (point-min) (point-max)))))
2151 (when (bufferp errbuf)
2152 (kill-buffer errbuf)))))
2154 (defun message-send-mail-with-qmail ()
2155 "Pass the prepared message buffer to qmail-inject.
2156 Refer to the documentation for the variable `message-send-mail-function'
2157 to find out how to use this."
2158 ;; replace the header delimiter with a blank line
2159 (goto-char (point-min))
2161 (concat "^" (regexp-quote mail-header-separator) "\n"))
2162 (replace-match "\n")
2163 (run-hooks 'message-send-mail-hook)
2166 (let ((coding-system-for-write message-send-coding-system))
2168 'call-process-region 1 (point-max) message-qmail-inject-program
2170 ;; qmail-inject's default behaviour is to look for addresses on the
2171 ;; command line; if there're none, it scans the headers.
2172 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
2174 ;; in general, ALL of qmail-inject's defaults are perfect for simply
2175 ;; reading a formatted (i. e., at least a To: or Resent-To header)
2176 ;; message from stdin.
2178 ;; qmail also has the advantage of not having been raped by
2179 ;; various vendors, so we don't have to allow for that, either --
2180 ;; compare this with message-send-mail-with-sendmail and weep
2181 ;; for sendmail's lost innocence.
2183 ;; all this is way cool coz it lets us keep the arguments entirely
2184 ;; free for -inject-arguments -- a big win for the user and for us
2185 ;; since we don't have to play that double-guessing game and the user
2186 ;; gets full control (no gestapo'ish -f's, for instance). --sj
2187 message-qmail-inject-args))
2188 ;; qmail-inject doesn't say anything on it's stdout/stderr,
2189 ;; we have to look at the retval instead
2191 (1 (error "qmail-inject reported permanent failure"))
2192 (111 (error "qmail-inject reported transient failure"))
2193 ;; should never happen
2194 (t (error "qmail-inject reported unknown failure"))))
2196 (defun message-send-mail-with-mh ()
2197 "Send the prepared message buffer with mh."
2198 (let ((mh-previous-window-config nil)
2199 (name (mh-new-draft-name)))
2200 (setq buffer-file-name name)
2201 ;; MH wants to generate these headers itself.
2202 (when message-mh-deletable-headers
2203 (let ((headers message-mh-deletable-headers))
2205 (goto-char (point-min))
2206 (and (re-search-forward
2207 (concat "^" (symbol-name (car headers)) ": *") nil t)
2208 (message-delete-line))
2210 (run-hooks 'message-send-mail-hook)
2211 ;; Pass it on to mh.
2214 (defun message-send-news (&optional arg)
2215 (let ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
2216 (case-fold-search nil)
2217 (method (if (message-functionp message-post-method)
2218 (funcall message-post-method arg)
2219 message-post-method))
2220 (messbuf (current-buffer))
2221 (message-syntax-checks
2223 (cons '(existing-newsgroups . disabled)
2224 message-syntax-checks)
2225 message-syntax-checks))
2228 (message-narrow-to-headers)
2229 ;; Insert some headers.
2230 (message-generate-headers message-required-news-headers)
2231 (mail-encode-encoded-word-buffer)
2232 ;; Let the user do all of the above.
2233 (run-hooks 'message-header-hook))
2234 (message-cleanup-headers)
2235 (if (not (message-check-news-syntax))
2237 (message-encode-message-body)
2241 (buffer-disable-undo)
2243 ;; Avoid copying text props.
2245 "%s" (save-excursion
2246 (set-buffer messbuf)
2248 ;; Remove some headers.
2250 (message-narrow-to-headers)
2251 ;; Remove some headers.
2252 (message-remove-header message-ignored-news-headers t))
2253 (goto-char (point-max))
2254 ;; require one newline at the end.
2255 (or (= (preceding-char) ?\n)
2257 (let ((case-fold-search t))
2258 ;; Remove the delimiter.
2259 (goto-char (point-min))
2261 (concat "^" (regexp-quote mail-header-separator) "\n"))
2262 (replace-match "\n")
2264 (run-hooks 'message-send-news-hook)
2265 ;;(require (car method))
2266 ;;(funcall (intern (format "%s-open-server" (car method)))
2267 ;;(cadr method) (cddr method))
2269 ;; (funcall (intern (format "%s-request-post" (car method)))
2271 (gnus-open-server method)
2272 (setq result (gnus-request-post method)))
2273 (kill-buffer tembuf))
2274 (set-buffer messbuf)
2276 (push 'news message-sent-message-via)
2277 (message "Couldn't send message via news: %s"
2278 (nnheader-get-report (car method)))
2282 ;;; Header generation & syntax checking.
2285 (defun message-check-element (type)
2286 "Returns non-nil if this type is not to be checked."
2287 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
2289 (let ((able (assq type message-syntax-checks)))
2291 (eq (cdr able) 'disabled)))))
2293 (defun message-check-news-syntax ()
2294 "Check the syntax of the message."
2299 ;; We narrow to the headers and check them first.
2302 (message-narrow-to-headers)
2303 (message-check-news-header-syntax)))
2305 (message-check-news-body-syntax)))))
2307 (defun message-check-news-header-syntax ()
2309 ;; Check the Subject header.
2310 (message-check 'subject
2311 (let* ((case-fold-search t)
2312 (subject (message-fetch-field "subject")))
2315 (not (string-match "\\`[ \t]*\\'" subject)))
2318 "The subject field is empty or missing. Posting is denied.")))))
2319 ;; Check for commands in Subject.
2320 (message-check 'subject-cmsg
2321 (if (string-match "^cmsg " (message-fetch-field "subject"))
2323 "The control code \"cmsg\" is in the subject. Really post? ")
2325 ;; Check for multiple identical headers.
2326 (message-check 'multiple-headers
2328 (while (and (not found)
2329 (re-search-forward "^[^ \t:]+: " nil t))
2331 (or (re-search-forward
2336 (match-beginning 0) (- (match-end 0) 2))))
2341 (y-or-n-p (format "Multiple %s headers. Really post? " found))
2343 ;; Check for Version and Sendsys.
2344 (message-check 'sendsys
2345 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
2347 (format "The article contains a %s command. Really post? "
2348 (buffer-substring (match-beginning 0)
2349 (1- (match-end 0)))))
2351 ;; See whether we can shorten Followup-To.
2352 (message-check 'shorten-followup-to
2353 (let ((newsgroups (message-fetch-field "newsgroups"))
2354 (followup-to (message-fetch-field "followup-to"))
2356 (when (and newsgroups
2357 (string-match "," newsgroups)
2362 (setq to (completing-read
2363 "Followups to: (default all groups) "
2364 (mapcar (lambda (g) (list g))
2366 (message-tokenize-header
2368 (goto-char (point-min))
2369 (insert "Followup-To: " to "\n"))
2371 ;; Check "Shoot me".
2372 (message-check 'shoot
2373 (if (re-search-forward
2374 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
2375 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
2377 ;; Check for Approved.
2378 (message-check 'approved
2379 (if (re-search-forward "^Approved:" nil t)
2380 (y-or-n-p "The article contains an Approved header. Really post? ")
2382 ;; Check the Message-ID header.
2383 (message-check 'message-id
2384 (let* ((case-fold-search t)
2385 (message-id (message-fetch-field "message-id" t)))
2386 (or (not message-id)
2387 ;; Is there an @ in the ID?
2388 (and (string-match "@" message-id)
2389 ;; Is there a dot in the ID?
2390 (string-match "@[^.]*\\." message-id)
2391 ;; Does the ID end with a dot?
2392 (not (string-match "\\.>" message-id)))
2394 (format "The Message-ID looks strange: \"%s\". Really post? "
2396 ;; Check the Newsgroups & Followup-To headers.
2397 (message-check 'existing-newsgroups
2398 (let* ((case-fold-search t)
2399 (newsgroups (message-fetch-field "newsgroups"))
2400 (followup-to (message-fetch-field "followup-to"))
2401 (groups (message-tokenize-header
2403 (concat newsgroups "," followup-to)
2405 (hashtb (and (boundp 'gnus-active-hashtb)
2406 gnus-active-hashtb))
2408 (if (or (not hashtb)
2409 (not (boundp 'gnus-read-active-file))
2410 (not gnus-read-active-file)
2411 (eq gnus-read-active-file 'some))
2414 (when (and (not (boundp (intern (car groups) hashtb)))
2415 (not (equal (car groups) "poster")))
2416 (push (car groups) errors))
2422 "Really post to %s unknown group%s: %s "
2423 (if (= (length errors) 1) "this" "these")
2424 (if (= (length errors) 1) "" "s")
2425 (mapconcat 'identity errors ", ")))))))
2426 ;; Check the Newsgroups & Followup-To headers for syntax errors.
2427 (message-check 'valid-newsgroups
2428 (let ((case-fold-search t)
2429 (headers '("Newsgroups" "Followup-To"))
2431 (while (and headers (not error))
2432 (when (setq header (mail-fetch-field (car headers)))
2436 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
2441 (not (string-match "\\.\\'\\|\\.\\." g)))
2442 (message-tokenize-header header ","))))
2449 (format "The %s header looks odd: \"%s\". Really post? "
2450 (car headers) header)))))
2451 (message-check 'repeated-newsgroups
2452 (let ((case-fold-search t)
2453 (headers '("Newsgroups" "Followup-To"))
2454 header error groups group)
2457 (when (setq header (mail-fetch-field (pop headers)))
2458 (setq groups (message-tokenize-header header ","))
2459 (while (setq group (pop groups))
2460 (when (member group groups)
2466 (format "Group %s is repeated in headers. Really post? " error)))))
2467 ;; Check the From header.
2468 (message-check 'from
2469 (let* ((case-fold-search t)
2470 (from (message-fetch-field "from"))
2471 (ad (nth 1 (mail-extract-address-components from))))
2474 (message "There is no From line. Posting is denied.")
2476 ((or (not (string-match "@[^\\.]*\\." ad)) ;larsi@ifi
2477 (string-match "\\.\\." ad) ;larsi@ifi..uio
2478 (string-match "@\\." ad) ;larsi@.ifi.uio
2479 (string-match "\\.$" ad) ;larsi@ifi.uio.
2480 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
2481 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
2483 "Denied posting -- the From looks strange: \"%s\"." from)
2487 (defun message-check-news-body-syntax ()
2489 ;; Check for long lines.
2490 (message-check 'long-lines
2491 (goto-char (point-min))
2493 (concat "^" (regexp-quote mail-header-separator) "$"))
2497 (< (current-column) 80))
2498 (zerop (forward-line 1))))
2502 "You have lines longer than 79 characters. Really post? ")))
2503 ;; Check whether the article is empty.
2504 (message-check 'empty
2505 (goto-char (point-min))
2507 (concat "^" (regexp-quote mail-header-separator) "$"))
2510 (goto-char (point-max))
2511 (re-search-backward message-signature-separator nil t)
2513 (or (re-search-backward "[^ \n\t]" b t)
2514 (y-or-n-p "Empty article. Really post? "))))
2515 ;; Check for control characters.
2516 (message-check 'control-chars
2517 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
2519 "The article contains control characters. Really post? ")
2521 ;; Check excessive size.
2522 (message-check 'size
2523 (if (> (buffer-size) 60000)
2525 (format "The article is %d octets long. Really post? "
2528 ;; Check whether any new text has been added.
2529 (message-check 'new-text
2531 (not message-checksum)
2532 (not (eq (message-checksum) message-checksum))
2534 "It looks like no new text has been added. Really post? ")))
2535 ;; Check the length of the signature.
2536 (message-check 'signature
2537 (goto-char (point-max))
2538 (if (or (not (re-search-backward message-signature-separator nil t))
2539 (search-forward message-forward-end-separator nil t))
2541 (if (> (count-lines (point) (point-max)) 5)
2544 "Your .sig is %d lines; it should be max 4. Really post? "
2545 (1- (count-lines (point) (point-max)))))
2548 (defun message-checksum ()
2549 "Return a \"checksum\" for the current buffer."
2552 (goto-char (point-min))
2554 (concat "^" (regexp-quote mail-header-separator) "$"))
2556 (when (not (looking-at "[ \t\n]"))
2557 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
2562 (defun message-do-fcc ()
2563 "Process Fcc headers in the current buffer."
2564 (let ((case-fold-search t)
2565 (buf (current-buffer))
2568 (set-buffer (get-buffer-create " *message temp*"))
2570 (insert-buffer-substring buf)
2572 (message-narrow-to-headers)
2573 (while (setq file (message-fetch-field "fcc"))
2575 (message-remove-header "fcc" nil t)))
2576 (goto-char (point-min))
2577 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
2578 (replace-match "" t t)
2579 ;; Process FCC operations.
2581 (setq file (pop list))
2582 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
2583 ;; Pipe the article to the program in question.
2584 (call-process-region (point-min) (point-max) shell-file-name
2585 nil nil nil shell-command-switch
2586 (match-string 1 file))
2587 ;; Save the article.
2588 (setq file (expand-file-name file))
2589 (unless (file-exists-p (file-name-directory file))
2590 (make-directory (file-name-directory file) t))
2591 (if (and message-fcc-handler-function
2592 (not (eq message-fcc-handler-function 'rmail-output)))
2593 (funcall message-fcc-handler-function file)
2594 (if (and (file-readable-p file) (mail-file-babyl-p file))
2595 (rmail-output file 1 nil t)
2596 (let ((mail-use-rfc822 t))
2597 (rmail-output file 1 t t))))))
2599 (kill-buffer (current-buffer)))))
2601 (defun message-output (filename)
2602 "Append this article to Unix/babyl mail file.."
2603 (if (and (file-readable-p filename)
2604 (mail-file-babyl-p filename))
2605 (rmail-output-to-rmail-file filename t)
2606 (gnus-output-to-mail filename t)))
2608 (defun message-cleanup-headers ()
2609 "Do various automatic cleanups of the headers."
2610 ;; Remove empty lines in the header.
2612 (message-narrow-to-headers)
2613 ;; Remove blank lines.
2614 (while (re-search-forward "^[ \t]*\n" nil t)
2615 (replace-match "" t t))
2617 ;; Correct Newsgroups and Followup-To headers: Change sequence of
2618 ;; spaces to comma and eliminate spaces around commas. Eliminate
2619 ;; embedded line breaks.
2620 (goto-char (point-min))
2621 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
2625 (if (re-search-forward "^[^ \t]" nil t)
2629 (goto-char (point-min))
2630 (while (re-search-forward "\n[ \t]+" nil t)
2631 (replace-match " " t t)) ;No line breaks (too confusing)
2632 (goto-char (point-min))
2633 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
2634 (replace-match "," t t))
2635 (goto-char (point-min))
2636 ;; Remove trailing commas.
2637 (when (re-search-forward ",+$" nil t)
2638 (replace-match "" t t))))))
2640 (defun message-make-date (&optional now)
2641 "Make a valid data header.
2642 If NOW, use that time instead."
2643 (let* ((now (or now (current-time)))
2644 (zone (nth 8 (decode-time now)))
2649 (format-time-string "%d" now)
2650 ;; The month name of the %b spec is locale-specific. Pfff.
2652 (capitalize (car (rassoc (nth 4 (decode-time now))
2653 parse-time-months))))
2654 (format-time-string "%Y %H:%M:%S " now)
2655 ;; We do all of this because XEmacs doesn't have the %z spec.
2656 (format "%s%02d%02d" sign (/ zone 3600) (% zone 3600)))))
2658 (defun message-make-message-id ()
2659 "Make a unique Message-ID."
2660 (concat "<" (message-unique-id)
2661 (let ((psubject (save-excursion (message-fetch-field "subject")))
2663 (save-excursion (message-fetch-field "supersedes"))))
2665 (and message-reply-headers
2666 (mail-header-references message-reply-headers)
2667 (mail-header-subject message-reply-headers)
2669 (mail-header-subject message-reply-headers)
2671 (message-strip-subject-re
2672 (mail-header-subject message-reply-headers))
2673 (message-strip-subject-re psubject))))
2675 (string-match "_-_@" psupersedes)))
2677 "@" (message-make-fqdn) ">"))
2679 (defvar message-unique-id-char nil)
2681 ;; If you ever change this function, make sure the new version
2682 ;; cannot generate IDs that the old version could.
2683 ;; You might for example insert a "." somewhere (not next to another dot
2684 ;; or string boundary), or modify the "fsf" string.
2685 (defun message-unique-id ()
2686 ;; Don't use microseconds from (current-time), they may be unsupported.
2687 ;; Instead we use this randomly inited counter.
2688 (setq message-unique-id-char
2689 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
2690 ;; (current-time) returns 16-bit ints,
2691 ;; and 2^16*25 just fits into 4 digits i base 36.
2693 (let ((tm (current-time)))
2695 (if (memq system-type '(ms-dos emx vax-vms))
2696 (let ((user (downcase (user-login-name))))
2697 (while (string-match "[^a-z0-9_]" user)
2698 (aset user (match-beginning 0) ?_))
2700 (message-number-base36 (user-uid) -1))
2701 (message-number-base36 (+ (car tm)
2702 (lsh (% message-unique-id-char 25) 16)) 4)
2703 (message-number-base36 (+ (nth 1 tm)
2704 (lsh (/ message-unique-id-char 25) 16)) 4)
2705 ;; Append the newsreader name, because while the generated
2706 ;; ID is unique to this newsreader, other newsreaders might
2707 ;; otherwise generate the same ID via another algorithm.
2710 (defun message-number-base36 (num len)
2715 (concat (message-number-base36 (/ num 36) (1- len))
2716 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
2719 (defun message-make-organization ()
2720 "Make an Organization header."
2721 (let* ((organization
2722 (when message-user-organization
2723 (if (message-functionp message-user-organization)
2724 (funcall message-user-organization)
2725 message-user-organization))))
2727 (message-set-work-buffer)
2728 (cond ((stringp organization)
2729 (insert organization))
2730 ((and (eq t organization)
2731 message-user-organization-file
2732 (file-exists-p message-user-organization-file))
2733 (insert-file-contents message-user-organization-file)))
2734 (goto-char (point-min))
2735 (while (re-search-forward "[\t\n]+" nil t)
2736 (replace-match "" t t))
2737 (unless (zerop (buffer-size))
2740 (defun message-make-lines ()
2741 "Count the number of lines and return numeric string."
2745 (goto-char (point-min))
2747 (concat "^" (regexp-quote mail-header-separator) "$"))
2749 (int-to-string (count-lines (point) (point-max))))))
2751 (defun message-make-in-reply-to ()
2752 "Return the In-Reply-To header for this message."
2753 (when message-reply-headers
2754 (let ((from (mail-header-from message-reply-headers))
2755 (date (mail-header-date message-reply-headers)))
2758 (string-match " *at \\| *@ \\| *(\\| *<" from)))
2759 (concat (if (and stop-pos
2760 (not (zerop stop-pos)))
2761 (substring from 0 stop-pos) from)
2763 (if (or (not date) (string= date ""))
2764 "(unknown date)" date)
2767 (defun message-make-distribution ()
2768 "Make a Distribution header."
2769 (let ((orig-distribution (message-fetch-reply-field "distribution")))
2770 (cond ((message-functionp message-distribution-function)
2771 (funcall message-distribution-function))
2772 (t orig-distribution))))
2774 (defun message-make-expires ()
2775 "Return an Expires header based on `message-expires'."
2776 (let ((current (current-time))
2777 (future (* 1.0 message-expires 60 60 24)))
2778 ;; Add the future to current.
2779 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
2780 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
2781 (message-make-date current)))
2783 (defun message-make-path ()
2785 (let ((login-name (user-login-name)))
2786 (cond ((null message-user-path)
2787 (concat (system-name) "!" login-name))
2788 ((stringp message-user-path)
2789 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
2790 (concat message-user-path "!" login-name))
2793 (defun message-make-from ()
2794 "Make a From header."
2795 (let* ((style message-from-style)
2796 (login (message-make-address))
2798 (or (and (boundp 'user-full-name)
2801 (when (string= fullname "&")
2802 (setq fullname (user-login-name)))
2804 (message-set-work-buffer)
2807 (equal fullname ""))
2809 ((or (eq style 'angles)
2810 (and (not (eq style 'parens))
2811 ;; Use angles if no quoting is needed, or if parens would
2812 ;; need quoting too.
2813 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
2814 (let ((tmp (concat fullname nil)))
2815 (while (string-match "([^()]*)" tmp)
2816 (aset tmp (match-beginning 0) ?-)
2817 (aset tmp (1- (match-end 0)) ?-))
2818 (string-match "[\\()]" tmp)))))
2820 (goto-char (point-min))
2821 ;; Look for a character that cannot appear unquoted
2822 ;; according to RFC 822.
2823 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
2824 ;; Quote fullname, escaping specials.
2825 (goto-char (point-min))
2827 (while (re-search-forward "[\"\\]" nil 1)
2828 (replace-match "\\\\\\&" t))
2830 (insert " <" login ">"))
2831 (t ; 'parens or default
2833 (let ((fullname-start (point)))
2835 (goto-char fullname-start)
2836 ;; RFC 822 says \ and nonmatching parentheses
2837 ;; must be escaped in comments.
2838 ;; Escape every instance of ()\ ...
2839 (while (re-search-forward "[()\\]" nil 1)
2840 (replace-match "\\\\\\&" t))
2841 ;; ... then undo escaping of matching parentheses,
2842 ;; including matching nested parentheses.
2843 (goto-char fullname-start)
2844 (while (re-search-forward
2845 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
2847 (replace-match "\\1(\\3)" t)
2848 (goto-char fullname-start)))
2852 (defun message-make-sender ()
2853 "Return the \"real\" user address.
2854 This function tries to ignore all user modifications, and
2855 give as trustworthy answer as possible."
2856 (concat (user-login-name) "@" (system-name)))
2858 (defun message-make-address ()
2859 "Make the address of the user."
2860 (or (message-user-mail-address)
2861 (concat (user-login-name) "@" (message-make-domain))))
2863 (defun message-user-mail-address ()
2864 "Return the pertinent part of `user-mail-address'."
2865 (when user-mail-address
2866 (if (string-match " " user-mail-address)
2867 (nth 1 (mail-extract-address-components user-mail-address))
2868 user-mail-address)))
2870 (defun message-make-fqdn ()
2871 "Return user's fully qualified domain name."
2872 (let ((system-name (system-name))
2873 (user-mail (message-user-mail-address)))
2875 ((string-match "[^.]\\.[^.]" system-name)
2876 ;; `system-name' returned the right result.
2878 ;; Try `mail-host-address'.
2879 ((and (boundp 'mail-host-address)
2880 (stringp mail-host-address)
2881 (string-match "\\." mail-host-address))
2883 ;; We try `user-mail-address' as a backup.
2885 (string-match "\\." user-mail)
2886 (string-match "@\\(.*\\)\\'" user-mail))
2887 (match-string 1 user-mail))
2888 ;; Default to this bogus thing.
2890 (concat system-name ".i-did-not-set--mail-host-address--so-shoot-me")))))
2892 (defun message-make-host-name ()
2893 "Return the name of the host."
2894 (let ((fqdn (message-make-fqdn)))
2895 (string-match "^[^.]+\\." fqdn)
2896 (substring fqdn 0 (1- (match-end 0)))))
2898 (defun message-make-domain ()
2899 "Return the domain name."
2900 (or mail-host-address
2901 (message-make-fqdn)))
2903 (defun message-generate-headers (headers)
2904 "Prepare article HEADERS.
2905 Headers already prepared in the buffer are not modified."
2907 (message-narrow-to-headers)
2908 (let* ((Date (message-make-date))
2909 (Message-ID (message-make-message-id))
2910 (Organization (message-make-organization))
2911 (From (message-make-from))
2912 (Path (message-make-path))
2915 (In-Reply-To (message-make-in-reply-to))
2917 (Distribution (message-make-distribution))
2918 (Lines (message-make-lines))
2919 (User-Agent message-newsreader)
2920 (Expires (message-make-expires))
2921 (case-fold-search t)
2923 ;; First we remove any old generated headers.
2924 (let ((headers message-deletable-headers))
2925 (unless (buffer-modified-p)
2926 (setq headers (delq 'Message-ID (copy-sequence headers))))
2928 (goto-char (point-min))
2929 (and (re-search-forward
2930 (concat "^" (symbol-name (car headers)) ": *") nil t)
2931 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
2932 (message-delete-line))
2934 ;; Go through all the required headers and see if they are in the
2935 ;; articles already. If they are not, or are empty, they are
2936 ;; inserted automatically - except for Subject, Newsgroups and
2939 (goto-char (point-min))
2940 (setq elem (pop headers))
2942 (if (eq (car elem) 'optional)
2943 (setq header (cdr elem))
2944 (setq header (car elem)))
2946 (when (or (not (re-search-forward
2950 (if (stringp header)
2952 (symbol-name header))))
2956 ;; The header was found. We insert a space after the
2957 ;; colon, if there is none.
2958 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
2959 ;; Find out whether the header is empty...
2960 (looking-at "[ \t]*$")))
2961 ;; So we find out what value we should insert.
2964 ((and (consp elem) (eq (car elem) 'optional))
2965 ;; This is an optional header. If the cdr of this
2966 ;; is something that is nil, then we do not insert
2968 (setq header (cdr elem))
2969 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
2970 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
2972 ;; The element is a cons. Either the cdr is a
2973 ;; string to be inserted verbatim, or it is a
2974 ;; function, and we insert the value returned from
2976 (or (and (stringp (cdr elem)) (cdr elem))
2977 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
2978 ((and (boundp header) (symbol-value header))
2979 ;; The element is a symbol. We insert the value
2980 ;; of this symbol, if any.
2981 (symbol-value header))
2983 ;; We couldn't generate a value for this header,
2984 ;; so we just ask the user.
2985 (read-from-minibuffer
2986 (format "Empty header for %s; enter value: " header)))))
2987 ;; Finally insert the header.
2989 (not (equal value "")))
2993 ;; This header didn't exist, so we insert it.
2994 (goto-char (point-max))
2995 (insert (if (stringp header) header (symbol-name header))
2998 ;; The value of this header was empty, so we clear
2999 ;; totally and insert the new value.
3000 (delete-region (point) (gnus-point-at-eol))
3002 ;; Add the deletable property to the headers that require it.
3003 (and (memq header message-deletable-headers)
3004 (progn (beginning-of-line) (looking-at "[^:]+: "))
3005 (add-text-properties
3006 (point) (match-end 0)
3007 '(message-deletable t face italic) (current-buffer)))))))
3008 ;; Insert new Sender if the From is strange.
3009 (let ((from (message-fetch-field "from"))
3010 (sender (message-fetch-field "sender"))
3011 (secure-sender (message-make-sender)))
3013 (not (message-check-element 'sender))
3016 (cadr (mail-extract-address-components from)))
3017 (downcase secure-sender)))
3022 (cadr (mail-extract-address-components sender)))
3023 (downcase secure-sender)))))
3024 (goto-char (point-min))
3025 ;; Rename any old Sender headers to Original-Sender.
3026 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
3028 (insert "Original-")
3029 (beginning-of-line))
3030 (when (or (message-news-p)
3031 (string-match "@.+\\.." secure-sender))
3032 (insert "Sender: " secure-sender "\n")))))))
3034 (defun message-insert-courtesy-copy ()
3035 "Insert a courtesy message in mail copies of combined messages."
3039 (message-narrow-to-headers)
3040 (when (setq newsgroups (message-fetch-field "newsgroups"))
3041 (goto-char (point-max))
3042 (insert "Posted-To: " newsgroups "\n")))
3044 (when message-courtesy-message
3046 ((string-match "%s" message-courtesy-message)
3047 (insert (format message-courtesy-message newsgroups)))
3049 (insert message-courtesy-message)))))))
3052 ;;; Setting up a message buffer
3055 (defun message-fill-address (header value)
3057 (narrow-to-region (point) (point))
3058 (insert (capitalize (symbol-name header))
3060 (if (consp value) (car value) value)
3062 (narrow-to-region (point-min) (1- (point-max)))
3064 (goto-char (point-min))
3066 (skip-chars-forward "^,\"" (point-max))
3067 (if (or (eq (char-after) ?,)
3070 (if (and (> (current-column) 78)
3076 (setq last (1+ (point))))
3077 (setq last (1+ (point)))))
3078 (setq quoted (not quoted)))
3081 (goto-char (point-max))
3085 (defun message-fill-header (header value)
3086 (let ((begin (point))
3089 (insert (capitalize (symbol-name header))
3091 (if (consp value) (car value) value)
3094 (narrow-to-region begin (point))
3095 (fill-region-as-paragraph begin (point))
3096 ;; Tapdance around looong Message-IDs.
3098 (when (looking-at "[ \t]*$")
3099 (message-delete-line))
3101 (re-search-forward ":" nil t)
3102 (when (looking-at "\n[ \t]+")
3103 (replace-match " " t t))
3104 (goto-char (point-max)))))
3106 (defun message-shorten-references (header references)
3107 "Limit REFERENCES to be shorter than 988 characters."
3113 (goto-char (point-min))
3114 (while (re-search-forward "<[^>]+>" nil t)
3115 (push (match-string 0) refs))
3116 (setq refs (nreverse refs))
3117 (while (> (length (mapconcat 'identity refs " ")) max)
3118 (when (< (length refs) (1+ cut))
3120 (setcdr (nthcdr cut refs) (cddr (nthcdr cut refs)))))
3121 (insert (capitalize (symbol-name header)) ": "
3122 (mapconcat 'identity refs " ") "\n")))
3124 (defun message-position-point ()
3125 "Move point to where the user probably wants to find it."
3126 (message-narrow-to-headers)
3128 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
3129 (search-backward ":" )
3132 (if (eq (char-after) ? )
3136 (goto-char (point-max))
3139 (unless (looking-at "$")
3143 (defun message-buffer-name (type &optional to group)
3144 "Return a new (unique) buffer name based on TYPE and TO."
3146 ;; Check whether `message-generate-new-buffers' is a function,
3147 ;; and if so, call it.
3148 ((message-functionp message-generate-new-buffers)
3149 (funcall message-generate-new-buffers type to group))
3150 ;; Generate a new buffer name The Message Way.
3151 ((eq message-generate-new-buffers 'unique)
3152 (generate-new-buffer-name
3156 (or (car (mail-extract-address-components to))
3159 (if (and group (not (string= group ""))) (concat " on " group) "")
3161 ((eq message-generate-new-buffers 'unsent)
3162 (generate-new-buffer-name
3163 (concat "*unsent " type
3166 (or (car (mail-extract-address-components to))
3169 (if (and group (not (string= group ""))) (concat " on " group) "")
3171 ;; Use standard name.
3173 (format "*%s message*" type))))
3175 (defun message-pop-to-buffer (name)
3176 "Pop to buffer NAME, and warn if it already exists and is modified."
3177 (let ((buffer (get-buffer name)))
3179 (buffer-name buffer))
3181 (set-buffer (pop-to-buffer buffer))
3182 (when (and (buffer-modified-p)
3184 "Message already being composed; erase? ")))
3185 (error "Message being composed")))
3186 (set-buffer (pop-to-buffer name)))
3190 (defun message-do-send-housekeeping ()
3191 "Kill old message buffers."
3192 ;; We might have sent this buffer already. Delete it from the
3194 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
3195 (while (and message-max-buffers
3197 (>= (length message-buffer-list) message-max-buffers))
3198 ;; Kill the oldest buffer -- unless it has been changed.
3199 (let ((buffer (pop message-buffer-list)))
3200 (when (and (buffer-name buffer)
3201 (not (buffer-modified-p buffer)))
3202 (kill-buffer buffer))))
3203 ;; Rename the buffer.
3204 (if message-send-rename-function
3205 (funcall message-send-rename-function)
3206 (when (string-match "\\`\\*\\(unsent \\)?" (buffer-name))
3208 (concat "*sent " (substring (buffer-name) (match-end 0))) t)))
3209 ;; Push the current buffer onto the list.
3210 (when message-max-buffers
3211 (setq message-buffer-list
3212 (nconc message-buffer-list (list (current-buffer))))))
3214 (defvar mc-modes-alist)
3215 (defun message-setup (headers &optional replybuffer actions)
3216 (when (and (boundp 'mc-modes-alist)
3217 (not (assq 'message-mode mc-modes-alist)))
3218 (push '(message-mode (encrypt . mc-encrypt-message)
3219 (sign . mc-sign-message))
3222 (setq message-send-actions actions))
3223 (setq message-reply-buffer replybuffer)
3224 (goto-char (point-min))
3225 ;; Insert all the headers.
3228 (alist message-header-format-alist))
3230 (unless (assq (caar h) message-header-format-alist)
3231 (push (list (caar h)) alist))
3235 (delete-region (point) (progn (forward-line -1) (point)))
3236 (when message-default-headers
3237 (insert message-default-headers)
3238 (or (bolp) (insert ?\n)))
3242 (insert mail-header-separator "\n")
3246 (when (message-news-p)
3247 (when message-default-news-headers
3248 (insert message-default-news-headers)
3249 (or (bolp) (insert ?\n)))
3250 (when message-generate-headers-first
3251 (message-generate-headers
3254 (copy-sequence message-required-news-headers))))))
3255 (when (message-mail-p)
3256 (when message-default-mail-headers
3257 (insert message-default-mail-headers)
3258 (or (bolp) (insert ?\n)))
3259 (when message-generate-headers-first
3260 (message-generate-headers
3263 (copy-sequence message-required-mail-headers))))))
3264 (run-hooks 'message-signature-setup-hook)
3265 (message-insert-signature)
3267 (message-narrow-to-headers)
3268 (run-hooks 'message-header-setup-hook))
3269 (set-buffer-modified-p nil)
3270 (setq buffer-undo-list nil)
3271 (run-hooks 'message-setup-hook)
3272 (message-position-point)
3275 (defun message-set-auto-save-file-name ()
3276 "Associate the message buffer with a file in the drafts directory."
3277 (when message-auto-save-directory
3279 (setq message-draft-article
3280 (nndraft-request-associate-buffer "drafts"))
3281 (setq buffer-file-name (expand-file-name "*message*"
3282 message-auto-save-directory))
3283 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
3284 (clear-visited-file-modtime)))
3286 (defun message-disassociate-draft ()
3287 "Disassociate the message buffer from the drafts directory."
3288 (when message-draft-article
3289 (nndraft-request-expire-articles
3290 (list message-draft-article) "drafts" nil t)))
3295 ;;; Commands for interfacing with message
3299 (defun message-mail (&optional to subject
3300 other-headers continue switch-function
3301 yank-action send-actions)
3302 "Start editing a mail message to be sent.
3303 OTHER-HEADERS is an alist of header/value pairs."
3305 (let ((message-this-is-mail t))
3306 (message-pop-to-buffer (message-buffer-name "mail" to))
3309 `((To . ,(or to "")) (Subject . ,(or subject "")))
3310 (when other-headers other-headers)))))
3313 (defun message-news (&optional newsgroups subject)
3314 "Start editing a news article to be sent."
3316 (let ((message-this-is-news t))
3317 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))
3318 (message-setup `((Newsgroups . ,(or newsgroups ""))
3319 (Subject . ,(or subject ""))))))
3322 (defun message-reply (&optional to-address wide)
3323 "Start editing a reply to the article in the current buffer."
3325 (let ((cur (current-buffer))
3326 from subject date reply-to to cc
3327 references message-id follow-to
3328 (inhibit-point-motion-hooks t)
3329 mct never-mct gnus-warning)
3331 (message-narrow-to-head)
3332 ;; Allow customizations to have their say.
3334 ;; This is a regular reply.
3335 (if (message-functionp message-reply-to-function)
3336 (setq follow-to (funcall message-reply-to-function)))
3337 ;; This is a followup.
3338 (if (message-functionp message-wide-reply-to-function)
3341 (funcall message-wide-reply-to-function)))))
3342 ;; Find all relevant headers we need.
3343 (setq from (message-fetch-field "from")
3344 date (message-fetch-field "date")
3345 subject (or (message-fetch-field "subject") "none")
3346 to (message-fetch-field "to")
3347 cc (message-fetch-field "cc")
3348 mct (message-fetch-field "mail-copies-to")
3349 reply-to (message-fetch-field "reply-to")
3350 references (message-fetch-field "references")
3351 message-id (message-fetch-field "message-id" t))
3352 ;; Remove any (buggy) Re:'s that are present and make a
3354 (when (string-match message-subject-re-regexp subject)
3355 (setq subject (substring subject (match-end 0))))
3356 (setq subject (concat "Re: " subject))
3358 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
3359 (string-match "<[^>]+>" gnus-warning))
3360 (setq message-id (match-string 0 gnus-warning)))
3362 ;; Handle special values of Mail-Copies-To.
3364 (cond ((or (equal (downcase mct) "never")
3365 (equal (downcase mct) "nobody"))
3368 ((or (equal (downcase mct) "always")
3369 (equal (downcase mct) "poster"))
3370 (setq mct (or reply-to from)))))
3376 (setq follow-to (list (cons 'To (or to-address reply-to from))))
3377 (when (and wide mct)
3378 (push (cons 'Cc mct) follow-to)))
3381 (message-set-work-buffer)
3383 (insert (or reply-to from "")))
3384 (insert (if to (concat (if (bolp) "" ", ") to "") ""))
3385 (insert (if mct (concat (if (bolp) "" ", ") mct) ""))
3386 (insert (if cc (concat (if (bolp) "" ", ") cc) ""))
3387 (goto-char (point-min))
3388 (while (re-search-forward "[ \t]+" nil t)
3389 (replace-match " " t t))
3390 ;; Remove addresses that match `rmail-dont-reply-to-names'.
3391 (insert (prog1 (rmail-dont-reply-to (buffer-string))
3393 (goto-char (point-min))
3394 ;; Perhaps Mail-Copies-To: never removed the only address?
3396 (insert (or reply-to from "")))
3400 (cons (mail-strip-quoted-names addr) addr))
3401 (message-tokenize-header (buffer-string))))
3404 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
3405 (setq follow-to (list (cons 'To (cdr (pop ccalist)))))
3407 (let ((ccs (cons 'Cc (mapconcat
3408 (lambda (addr) (cdr addr)) ccalist ", "))))
3409 (when (string-match "^ +" (cdr ccs))
3410 (setcdr ccs (substring (cdr ccs) (match-end 0))))
3411 (push ccs follow-to))))))
3414 (message-pop-to-buffer (message-buffer-name
3415 (if wide "wide reply" "reply") from
3416 (if wide to-address nil)))
3418 (setq message-reply-headers
3419 (vector 0 subject from date message-id references 0 0 ""))
3422 `((Subject . ,subject)
3424 ,@(if (or references message-id)
3425 `((References . ,(concat (or references "") (and references " ")
3426 (or message-id ""))))
3431 (defun message-wide-reply (&optional to-address)
3432 "Make a \"wide\" reply to the message in the current buffer."
3434 (message-reply to-address t))
3437 (defun message-followup (&optional to-newsgroups)
3438 "Follow up to the message in the current buffer.
3439 If TO-NEWSGROUPS, use that as the new Newsgroups line."
3441 (let ((cur (current-buffer))
3442 from subject date reply-to mct
3443 references message-id follow-to
3444 (inhibit-point-motion-hooks t)
3445 (message-this-is-news t)
3446 followup-to distribution newsgroups gnus-warning posted-to)
3449 (goto-char (point-min))
3450 (if (search-forward "\n\n" nil t)
3453 (when (message-functionp message-followup-to-function)
3455 (funcall message-followup-to-function)))
3456 (setq from (message-fetch-field "from")
3457 date (message-fetch-field "date")
3458 subject (or (message-fetch-field "subject") "none")
3459 references (message-fetch-field "references")
3460 message-id (message-fetch-field "message-id" t)
3461 followup-to (message-fetch-field "followup-to")
3462 newsgroups (message-fetch-field "newsgroups")
3463 posted-to (message-fetch-field "posted-to")
3464 reply-to (message-fetch-field "reply-to")
3465 distribution (message-fetch-field "distribution")
3466 mct (message-fetch-field "mail-copies-to"))
3467 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
3468 (string-match "<[^>]+>" gnus-warning))
3469 (setq message-id (match-string 0 gnus-warning)))
3470 ;; Remove bogus distribution.
3471 (when (and (stringp distribution)
3472 (let ((case-fold-search t))
3473 (string-match "world" distribution)))
3474 (setq distribution nil))
3475 ;; Remove any (buggy) Re:'s that are present and make a
3477 (when (string-match message-subject-re-regexp subject)
3478 (setq subject (substring subject (match-end 0))))
3479 (setq subject (concat "Re: " subject))
3482 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
3485 `((Subject . ,subject)
3488 (list (cons 'Newsgroups to-newsgroups)))
3489 (follow-to follow-to)
3490 ((and followup-to message-use-followup-to)
3493 ((equal (downcase followup-to) "poster")
3494 (if (or (eq message-use-followup-to 'use)
3495 (message-y-or-n-p "Obey Followup-To: poster? " t "\
3496 You should normally obey the Followup-To: header.
3498 `Followup-To: poster' sends your response via e-mail instead of news.
3500 A typical situation where `Followup-To: poster' is used is when the poster
3501 does not read the newsgroup, so he wouldn't see any replies sent to it."))
3503 (setq message-this-is-news nil)
3504 (cons 'To (or reply-to from "")))
3505 (cons 'Newsgroups newsgroups)))
3507 (if (or (equal followup-to newsgroups)
3508 (not (eq message-use-followup-to 'ask))
3510 (concat "Obey Followup-To: " followup-to "? ") t "\
3511 You should normally obey the Followup-To: header.
3513 `Followup-To: " followup-to "'
3514 directs your response to " (if (string-match "," followup-to)
3515 "the specified newsgroups"
3516 "that newsgroup only") ".
3518 If a message is posted to several newsgroups, Followup-To is often
3519 used to direct the following discussion to one newsgroup only,
3520 because discussions that are spread over several newsgroup tend to
3521 be fragmented and very difficult to follow.
3523 Also, some source/announcement newsgroups are not indented for discussion;
3524 responses here are directed to other newsgroups."))
3525 (cons 'Newsgroups followup-to)
3526 (cons 'Newsgroups newsgroups))))))
3528 `((Newsgroups . ,posted-to)))
3530 `((Newsgroups . ,newsgroups))))
3531 ,@(and distribution (list (cons 'Distribution distribution)))
3532 ,@(if (or references message-id)
3533 `((References . ,(concat (or references "") (and references " ")
3534 (or message-id "")))))
3536 (not (or (equal (downcase mct) "never")
3537 (equal (downcase mct) "nobody"))))
3538 (list (cons 'Cc (if (or (equal (downcase mct) "always")
3539 (equal (downcase mct) "poster"))
3540 (or reply-to from "")
3545 (setq message-reply-headers
3546 (vector 0 subject from date message-id references 0 0 ""))))
3550 (defun message-cancel-news ()
3551 "Cancel an article you posted."
3553 (unless (message-news-p)
3554 (error "This is not a news article; canceling is impossible"))
3555 (when (yes-or-no-p "Do you really want to cancel this article? ")
3556 (let (from newsgroups message-id distribution buf sender)
3558 ;; Get header info. from original article.
3560 (message-narrow-to-head)
3561 (setq from (message-fetch-field "from")
3562 sender (message-fetch-field "sender")
3563 newsgroups (message-fetch-field "newsgroups")
3564 message-id (message-fetch-field "message-id" t)
3565 distribution (message-fetch-field "distribution")))
3566 ;; Make sure that this article was written by the user.
3567 (unless (or (and sender
3570 (downcase (message-make-sender))))
3572 (downcase (cadr (mail-extract-address-components from)))
3573 (downcase (cadr (mail-extract-address-components
3574 (message-make-from))))))
3575 (error "This article is not yours"))
3576 ;; Make control message.
3577 (setq buf (set-buffer (get-buffer-create " *message cancel*")))
3579 (insert "Newsgroups: " newsgroups "\n"
3580 "From: " (message-make-from) "\n"
3581 "Subject: cmsg cancel " message-id "\n"
3582 "Control: cancel " message-id "\n"
3584 (concat "Distribution: " distribution "\n")
3586 mail-header-separator "\n"
3587 message-cancel-message)
3588 (message "Canceling your article...")
3589 (if (let ((message-syntax-checks
3590 'dont-check-for-anything-just-trust-me))
3591 (funcall message-send-news-function))
3592 (message "Canceling your article...done"))
3593 (kill-buffer buf)))))
3596 (defun message-supersede ()
3597 "Start composing a message to supersede the current message.
3598 This is done simply by taking the old article and adding a Supersedes
3599 header line with the old Message-ID."
3601 (let ((cur (current-buffer))
3602 (sender (message-fetch-field "sender"))
3603 (from (message-fetch-field "from")))
3604 ;; Check whether the user owns the article that is to be superseded.
3605 (unless (or (and sender
3608 (downcase (message-make-sender))))
3610 (downcase (cadr (mail-extract-address-components from)))
3611 (downcase (cadr (mail-extract-address-components
3612 (message-make-from))))))
3613 (error "This article is not yours"))
3614 ;; Get a normal message buffer.
3615 (message-pop-to-buffer (message-buffer-name "supersede"))
3616 (insert-buffer-substring cur)
3617 (message-narrow-to-head)
3618 ;; Remove unwanted headers.
3619 (when message-ignored-supersedes-headers
3620 (message-remove-header message-ignored-supersedes-headers t))
3621 (goto-char (point-min))
3622 (if (not (re-search-forward "^Message-ID: " nil t))
3623 (error "No Message-ID in this article")
3624 (replace-match "Supersedes: " t t))
3625 (goto-char (point-max))
3626 (insert mail-header-separator)
3631 (defun message-recover ()
3632 "Reread contents of current buffer from its last auto-save file."
3634 (let ((file-name (make-auto-save-file-name)))
3635 (cond ((save-window-excursion
3636 (if (not (eq system-type 'vax-vms))
3637 (with-output-to-temp-buffer "*Directory*"
3638 (buffer-disable-undo standard-output)
3639 (let ((default-directory "/"))
3641 "ls" nil standard-output nil "-l" file-name))))
3642 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
3643 (let ((buffer-read-only nil))
3645 (insert-file-contents file-name nil)))
3646 (t (error "message-recover cancelled")))))
3648 ;;; Washing Subject:
3650 (defun message-wash-subject (subject)
3651 "Remove junk like \"Re:\", \"(fwd)\", etc. that was added to the subject by previous forwarders, replyers, etc."
3653 (insert-string subject)
3654 (goto-char (point-min))
3655 ;; strip Re/Fwd stuff off the beginning
3656 (while (re-search-forward
3657 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
3660 ;; and gnus-style forwards [foo@bar.com] subject
3661 (goto-char (point-min))
3662 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
3666 (goto-char (point-max))
3667 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
3670 ;; and finally, any whitespace that was left-over
3671 (goto-char (point-min))
3672 (while (re-search-forward "^[ \t]+" nil t)
3674 (goto-char (point-max))
3675 (while (re-search-backward "[ \t]+$" nil t)
3680 ;;; Forwarding messages.
3682 (defun message-forward-subject-author-subject (subject)
3683 "Generate a subject for a forwarded message.
3684 The form is: [Source] Subject, where if the original message was mail,
3685 Source is the sender, and if the original message was news, Source is
3686 the list of newsgroups is was posted to."
3688 (or (message-fetch-field
3689 (if (message-news-p) "newsgroups" "from"))
3693 (defun message-forward-subject-fwd (subject)
3694 "Generate a subject for a forwarded message.
3695 The form is: Fwd: Subject, where Subject is the original subject of
3697 (concat "Fwd: " subject))
3699 (defun message-make-forward-subject ()
3700 "Return a Subject header suitable for the message in the current buffer."
3704 (message-narrow-to-head)
3705 (let ((funcs message-make-forward-subject-function)
3706 (subject (if message-wash-forwarded-subjects
3707 (message-wash-subject
3708 (or (message-fetch-field "Subject") ""))
3709 (or (message-fetch-field "Subject") ""))))
3710 ;; Make sure funcs is a list.
3713 (setq funcs (list funcs)))
3714 ;; Apply funcs in order, passing subject generated by previous
3715 ;; func to the next one.
3717 (when (message-functionp (car funcs))
3718 (setq subject (funcall (car funcs) subject)))
3719 (setq funcs (cdr funcs)))
3723 (defun message-forward (&optional news)
3724 "Forward the current message via mail.
3725 Optional NEWS will use news to forward instead of mail."
3727 (let ((cur (current-buffer))
3728 (subject (message-make-forward-subject))
3730 (if news (message-news nil subject) (message-mail nil subject))
3731 ;; Put point where we want it before inserting the forwarded
3733 (if message-signature-before-forwarded-message
3734 (goto-char (point-max))
3735 (message-goto-body))
3736 ;; Make sure we're at the start of the line.
3739 ;; Narrow to the area we are to insert.
3740 (narrow-to-region (point) (point))
3741 ;; Insert the separators and the forwarded buffer.
3742 (insert message-forward-start-separator)
3743 (setq art-beg (point))
3744 (insert-buffer-substring cur)
3745 (goto-char (point-max))
3746 (insert message-forward-end-separator)
3747 (set-text-properties (point-min) (point-max) nil)
3748 ;; Remove all unwanted headers.
3750 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
3753 (goto-char (point-min))
3754 (message-remove-header message-included-forward-headers t nil t)
3756 (message-position-point)))
3759 (defun message-resend (address)
3760 "Resend the current article to ADDRESS."
3761 (interactive "sResend message to: ")
3762 (message "Resending message to %s..." address)
3764 (let ((cur (current-buffer))
3766 ;; We first set up a normal mail buffer.
3767 (set-buffer (get-buffer-create " *message resend*"))
3769 (message-setup `((To . ,address)))
3770 ;; Insert our usual headers.
3771 (message-generate-headers '(From Date To))
3772 (message-narrow-to-headers)
3773 ;; Rename them all to "Resent-*".
3774 (while (re-search-forward "^[A-Za-z]" nil t)
3779 (delete-region (point) (point-max))
3781 ;; Insert the message to be resent.
3782 (insert-buffer-substring cur)
3783 (goto-char (point-min))
3784 (search-forward "\n\n")
3787 (narrow-to-region beg (point))
3788 (message-remove-header message-ignored-resent-headers t)
3789 (goto-char (point-max)))
3790 (insert mail-header-separator)
3791 ;; Rename all old ("Also-")Resent headers.
3792 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
3795 ;; Quote any "From " lines at the beginning.
3797 (when (looking-at "From ")
3798 (replace-match "X-From-Line: "))
3801 (kill-buffer (current-buffer)))
3802 (message "Resending message to %s...done" address)))
3805 (defun message-bounce ()
3806 "Re-mail the current message.
3807 This only makes sense if the current message is a bounce message than
3808 contains some mail you have written which has been bounced back to
3811 (let ((cur (current-buffer))
3813 (message-pop-to-buffer (message-buffer-name "bounce"))
3814 (insert-buffer-substring cur)
3816 (message-narrow-to-head)
3817 (if (and (message-fetch-field "Mime-Version")
3818 (setq boundary (message-fetch-field "Content-Type")))
3819 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary)
3820 (setq boundary (concat (match-string 1 boundary) " *\n"
3821 "Content-Type: message/rfc822"))
3822 (setq boundary nil)))
3824 (goto-char (point-min))
3825 (search-forward "\n\n" nil t)
3827 (re-search-forward boundary nil t)
3829 (and (re-search-forward message-unsent-separator nil t)
3831 (re-search-forward "^Return-Path:.*\n" nil t))
3832 ;; We remove everything before the bounced mail.
3835 (if (re-search-forward "^[^ \n\t]+:" nil t)
3839 (message-narrow-to-head)
3840 (message-remove-header message-ignored-bounced-headers t)
3841 (goto-char (point-max))
3842 (insert mail-header-separator))
3843 (message-position-point)))
3846 ;;; Interactive entry points for new message buffers.
3850 (defun message-mail-other-window (&optional to subject)
3851 "Like `message-mail' command, but display mail buffer in another window."
3853 (let ((pop-up-windows t)
3854 (special-display-buffer-names nil)
3855 (special-display-regexps nil)
3856 (same-window-buffer-names nil)
3857 (same-window-regexps nil))
3858 (message-pop-to-buffer (message-buffer-name "mail" to)))
3859 (let ((message-this-is-mail t))
3860 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
3863 (defun message-mail-other-frame (&optional to subject)
3864 "Like `message-mail' command, but display mail buffer in another frame."
3866 (let ((pop-up-frames t)
3867 (special-display-buffer-names nil)
3868 (special-display-regexps nil)
3869 (same-window-buffer-names nil)
3870 (same-window-regexps nil))
3871 (message-pop-to-buffer (message-buffer-name "mail" to)))
3872 (let ((message-this-is-mail t))
3873 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
3876 (defun message-news-other-window (&optional newsgroups subject)
3877 "Start editing a news article to be sent."
3879 (let ((pop-up-windows t)
3880 (special-display-buffer-names nil)
3881 (special-display-regexps nil)
3882 (same-window-buffer-names nil)
3883 (same-window-regexps nil))
3884 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
3885 (let ((message-this-is-news t))
3886 (message-setup `((Newsgroups . ,(or newsgroups ""))
3887 (Subject . ,(or subject ""))))))
3890 (defun message-news-other-frame (&optional newsgroups subject)
3891 "Start editing a news article to be sent."
3893 (let ((pop-up-frames t)
3894 (special-display-buffer-names nil)
3895 (special-display-regexps nil)
3896 (same-window-buffer-names nil)
3897 (same-window-regexps nil))
3898 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
3899 (let ((message-this-is-news t))
3900 (message-setup `((Newsgroups . ,(or newsgroups ""))
3901 (Subject . ,(or subject ""))))))
3905 ;; This code should be moved to underline.el (from which it is stolen).
3908 (defun bold-region (start end)
3909 "Bold all nonblank characters in the region.
3910 Works by overstriking characters.
3911 Called from program, takes two arguments START and END
3912 which specify the range to operate on."
3915 (let ((end1 (make-marker)))
3916 (move-marker end1 (max start end))
3917 (goto-char (min start end))
3918 (while (< (point) end1)
3919 (or (looking-at "[_\^@- ]")
3920 (insert (char-after) "\b"))
3921 (forward-char 1)))))
3924 (defun unbold-region (start end)
3925 "Remove all boldness (overstruck characters) in the region.
3926 Called from program, takes two arguments START and END
3927 which specify the range to operate on."
3930 (let ((end1 (make-marker)))
3931 (move-marker end1 (max start end))
3932 (goto-char (min start end))
3933 (while (re-search-forward "\b" end1 t)
3934 (if (eq (char-after) (char-after (- (point) 2)))
3935 (delete-char -2))))))
3937 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
3939 ;; Support for toolbar
3940 (when (string-match "XEmacs\\|Lucid" emacs-version)
3941 (require 'messagexmas))
3943 ;;; Group name completion.
3945 (defvar message-newgroups-header-regexp
3946 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
3947 "Regexp that match headers that lists groups.")
3949 (defun message-tab ()
3950 "Expand group names in Newsgroups and Followup-To headers.
3951 Do a `tab-to-tab-stop' if not in those headers."
3953 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp))
3954 (mail-abbrev-in-expansion-header-p))
3955 (message-expand-group)
3958 (defvar gnus-active-hashtb)
3959 (defun message-expand-group ()
3960 "Expand the group name under point."
3961 (let* ((b (save-excursion
3966 (skip-chars-forward "^:")
3969 (skip-chars-backward "^, \t\n") (point))))
3970 (completion-ignore-case t)
3971 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
3973 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
3974 (completions (all-completions string hashtb))
3976 (delete-region b (point))
3978 ((= (length completions) 1)
3979 (if (string= (car completions) string)
3982 (message "Only matching group"))
3983 (insert (car completions))))
3984 ((and (setq comp (try-completion string hashtb))
3985 (not (string= comp string)))
3990 (message "No matching groups")
3991 (save-selected-window
3992 (pop-to-buffer "*Completions*")
3993 (buffer-disable-undo)
3994 (let ((buffer-read-only nil))
3996 (let ((standard-output (current-buffer)))
3997 (display-completion-list (sort completions 'string<)))
3998 (goto-char (point-min))
3999 (delete-region (point) (progn (forward-line 3) (point))))))))))
4003 (defun message-talkative-question (ask question show &rest text)
4004 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
4005 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
4006 The following arguments may contain lists of values."
4008 (setq text (message-flatten-list text)))
4009 (save-window-excursion
4011 (with-output-to-temp-buffer " *MESSAGE information message*"
4012 (set-buffer " *MESSAGE information message*")
4013 (mapcar 'princ text)
4014 (goto-char (point-min))))
4015 (funcall ask question))
4016 (funcall ask question)))
4018 (defun message-flatten-list (list)
4019 "Return a new, flat list that contains all elements of LIST.
4021 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
4024 (apply 'append (mapcar 'message-flatten-list list)))
4028 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
4029 "Create and return a buffer with a name based on NAME using generate-new-buffer.
4030 Then clone the local variables and values from the old buffer to the
4031 new one, cloning only the locals having a substring matching the
4033 (let ((oldbuf (current-buffer)))
4035 (set-buffer (generate-new-buffer name))
4036 (message-clone-locals oldbuf)
4039 (defun message-clone-locals (buffer)
4040 "Clone the local variables from BUFFER to the current buffer."
4041 (let ((locals (save-excursion
4043 (buffer-local-variables)))
4044 (regexp "^gnus\\|^nn\\|^message"))
4047 (when (and (consp local)
4049 (string-match regexp (symbol-name (car local))))
4051 (set (make-local-variable (car local))
4055 ;;; Miscellaneous functions
4057 ;; stolen (and renamed) from nnheader.el
4058 (defun message-replace-chars-in-string (string from to)
4059 "Replace characters in STRING from FROM to TO."
4060 (let ((string (substring string 0)) ;Copy string.
4061 (len (length string))
4063 ;; Replace all occurrences of FROM with TO.
4065 (when (= (aref string idx) from)
4066 (aset string idx to))
4067 (setq idx (1+ idx)))
4074 (defun message-encode-message-body ()
4075 "Examine the message body, encode it, and add the requisite headers."
4076 (when (featurep 'mule)
4080 (message-narrow-to-headers-or-head)
4081 (unless (setq old-headers (message-fetch-field "mime-version"))
4082 (message-remove-header
4083 "^Content-Transfer-Encoding:\\|^Content-Type:\\|^Mime-Version:" t))
4084 (goto-char (point-max))
4086 (narrow-to-region (point) (point-max))
4087 (let* ((charset (mm-encode-body))
4088 (encoding (mm-body-encoding)))
4089 (when (consp charset)
4090 (error "Can't encode messages with multiple charsets (yet)"))
4092 (message-narrow-to-headers-or-head)
4093 (goto-char (point-max))
4094 (setq charset (or charset
4095 (mm-mule-charset-to-mime-charset 'ascii)))
4096 ;; We don't insert MIME headers if they only say the default.
4097 (when (and (not old-headers)
4098 (not (and (eq charset 'us-ascii)
4099 (eq encoding '7bit))))
4100 (mm-insert-rfc822-headers charset encoding))
4101 (mm-encode-body)))))))
4103 (run-hooks 'message-load-hook)
4107 ;;; message.el ends here