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))
44 (defgroup message '((user-mail-address custom-variable)
45 (user-full-name custom-variable))
46 "Mail and news message composing."
47 :link '(custom-manual "(message)Top")
51 (put 'user-mail-address 'custom-type 'string)
52 (put 'user-full-name 'custom-type 'string)
54 (defgroup message-various nil
55 "Various Message Variables"
56 :link '(custom-manual "(message)Various Message Variables")
59 (defgroup message-buffers nil
61 :link '(custom-manual "(message)Message Buffers")
64 (defgroup message-sending nil
66 :link '(custom-manual "(message)Sending Variables")
69 (defgroup message-interface nil
71 :link '(custom-manual "(message)Interface")
74 (defgroup message-forwarding nil
76 :link '(custom-manual "(message)Forwarding")
77 :group 'message-interface)
79 (defgroup message-insertion nil
81 :link '(custom-manual "(message)Insertion")
84 (defgroup message-headers nil
86 :link '(custom-manual "(message)Message Headers")
89 (defgroup message-news nil
90 "Composing News Messages"
93 (defgroup message-mail nil
94 "Composing Mail Messages"
97 (defgroup message-faces nil
98 "Faces used for message composing."
102 (defcustom message-directory "~/Mail/"
103 "*Directory from which all other mail file variables are derived."
104 :group 'message-various
107 (defcustom message-max-buffers 10
108 "*How many buffers to keep before starting to kill them off."
109 :group 'message-buffers
112 (defcustom message-send-rename-function nil
113 "Function called to rename the buffer after sending it."
114 :group 'message-buffers
117 (defcustom message-fcc-handler-function 'message-output
118 "*A function called to save outgoing articles.
119 This function will be called with the name of the file to store the
120 article in. The default function is `message-output' which saves in Unix
122 :type '(radio (function-item message-output)
123 (function :tag "Other"))
124 :group 'message-sending)
126 (defcustom message-courtesy-message
127 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
128 "*This is inserted at the start of a mailed copy of a posted message.
129 If the string contains the format spec \"%s\", the Newsgroups
130 the article has been posted to will be inserted there.
131 If this variable is nil, no such courtesy message will be added."
132 :group 'message-sending
135 (defcustom message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):"
136 "*Regexp that matches headers to be removed in resent bounced mail."
137 :group 'message-interface
141 (defcustom message-from-style 'default
142 "*Specifies how \"From\" headers look.
144 If `nil', they contain just the return address like:
146 If `parens', they look like:
147 king@grassland.com (Elvis Parsley)
148 If `angles', they look like:
149 Elvis Parsley <king@grassland.com>
151 Otherwise, most addresses look like `angles', but they look like
152 `parens' if `angles' would need quoting and `parens' would not."
153 :type '(choice (const :tag "simple" nil)
157 :group 'message-headers)
159 (defcustom message-syntax-checks nil
160 ; Guess this one shouldn't be easy to customize...
161 "*Controls what syntax checks should not be performed on outgoing posts.
162 To disable checking of long signatures, for instance, add
163 `(signature . disabled)' to this list.
165 Don't touch this variable unless you really know what you're doing.
167 Checks include subject-cmsg multiple-headers sendsys message-id from
168 long-lines control-chars size new-text redirected-followup signature
169 approved sender empty empty-headers message-id from subject
170 shorten-followup-to existing-newsgroups buffer-file-name unchanged."
171 :group 'message-news)
173 (defcustom message-required-news-headers
174 '(From Newsgroups Subject Date Message-ID
175 (optional . Organization) Lines
176 (optional . User-Agent))
177 "*Headers to be generated or prompted for when posting an article.
178 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
179 Message-ID. Organization, Lines, In-Reply-To, Expires, and
180 User-Agent are optional. If don't you want message to insert some
181 header, remove it from this list."
183 :group 'message-headers
184 :type '(repeat sexp))
186 (defcustom message-required-mail-headers
187 '(From Subject Date (optional . In-Reply-To) Message-ID Lines
188 (optional . User-Agent))
189 "*Headers to be generated or prompted for when mailing a message.
190 RFC822 required that From, Date, To, Subject and Message-ID be
191 included. Organization, Lines and User-Agent are optional."
193 :group 'message-headers
194 :type '(repeat sexp))
196 (defcustom message-deletable-headers '(Message-ID Date Lines)
197 "Headers to be deleted if they already exist and were generated by message previously."
198 :group 'message-headers
201 (defcustom message-ignored-news-headers
202 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:"
203 "*Regexp of headers to be removed unconditionally before posting."
205 :group 'message-headers
208 (defcustom message-ignored-mail-headers "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:"
209 "*Regexp of headers to be removed unconditionally before mailing."
211 :group 'message-headers
214 (defcustom message-ignored-supersedes-headers "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|^X-Trace:\\|^X-Complaints-To:\\|Return-Path:\\|^Supersedes:\\|^X-Trace:\\|^X-Complaints-To:"
215 "*Header lines matching this regexp will be deleted before posting.
216 It's best to delete old Path and Date headers before posting to avoid
218 :group 'message-interface
221 (defcustom message-subject-re-regexp "^[ \t]*\\([Rr][Ee]:[ \t]*\\)*[ \t]*"
222 "*Regexp matching \"Re: \" in the subject line."
223 :group 'message-various
227 (defcustom message-signature-separator "^-- *$"
228 "Regexp matching the signature separator."
230 :group 'message-various)
232 (defcustom message-elide-elipsis "\n[...]\n\n"
233 "*The string which is inserted for elided text."
235 :group 'message-various)
237 (defcustom message-interactive nil
238 "Non-nil means when sending a message wait for and display errors.
239 nil means let mailer mail back a message to report errors."
240 :group 'message-sending
244 (defcustom message-generate-new-buffers t
245 "*Non-nil means that a new message buffer will be created whenever `message-setup' is called.
246 If this is a function, call that function with three parameters: The type,
247 the to address and the group name. (Any of these may be nil.) The function
248 should return the new buffer name."
249 :group 'message-buffers
250 :type '(choice (const :tag "off" nil)
254 (defcustom message-kill-buffer-on-exit nil
255 "*Non-nil means that the message buffer will be killed after sending a message."
256 :group 'message-buffers
259 (defvar gnus-local-organization)
260 (defcustom message-user-organization
261 (or (and (boundp 'gnus-local-organization)
262 (stringp gnus-local-organization)
263 gnus-local-organization)
264 (getenv "ORGANIZATION")
266 "*String to be used as an Organization header.
267 If t, use `message-user-organization-file'."
268 :group 'message-headers
269 :type '(choice string
270 (const :tag "consult file" t)))
273 (defcustom message-user-organization-file "/usr/lib/news/organization"
274 "*Local news organization file."
276 :group 'message-headers)
278 (defcustom message-forward-start-separator
279 "------- Start of forwarded message -------\n"
280 "*Delimiter inserted before forwarded messages."
281 :group 'message-forwarding
284 (defcustom message-forward-end-separator
285 "------- End of forwarded message -------\n"
286 "*Delimiter inserted after forwarded messages."
287 :group 'message-forwarding
290 (defcustom message-signature-before-forwarded-message t
291 "*If non-nil, put the signature before any included forwarded message."
292 :group 'message-forwarding
295 (defcustom message-included-forward-headers
296 "^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:"
297 "*Regexp matching headers to be included in forwarded messages."
298 :group 'message-forwarding
301 (defcustom message-make-forward-subject-function
302 'message-forward-subject-author-subject
303 "*A list of functions that are called to generate a subject header for forwarded messages.
304 The subject generated by the previous function is passed into each
307 The provided functions are:
309 * message-forward-subject-author-subject (Source of article (author or
310 newsgroup)), in brackets followed by the subject
311 * message-forward-subject-fwd (Subject of article with 'Fwd:' prepended
313 :group 'message-forwarding
314 :type '(radio (function-item message-forward-subject-author-subject)
315 (function-item message-forward-subject-fwd)))
317 (defcustom message-wash-forwarded-subjects nil
318 "*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."
319 :group 'message-forwarding
322 (defcustom message-ignored-resent-headers "^Return-receipt"
323 "*All headers that match this regexp will be deleted when resending a message."
324 :group 'message-interface
327 (defcustom message-ignored-cited-headers "."
328 "*Delete these headers from the messages you yank."
329 :group 'message-insertion
332 (defcustom message-cancel-message "I am canceling my own article."
333 "Message to be inserted in the cancel message."
334 :group 'message-interface
337 ;; Useful to set in site-init.el
339 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
340 "Function to call to send the current buffer as mail.
341 The headers should be delimited by a line whose contents match the
342 variable `mail-header-separator'.
344 Legal values include `message-send-mail-with-sendmail' (the default),
345 `message-send-mail-with-mh', `message-send-mail-with-qmail' and
347 :type '(radio (function-item message-send-mail-with-sendmail)
348 (function-item message-send-mail-with-mh)
349 (function-item message-send-mail-with-qmail)
350 (function-item smtpmail-send-it)
351 (function :tag "Other"))
352 :group 'message-sending
353 :group 'message-mail)
355 (defcustom message-send-news-function 'message-send-news
356 "Function to call to send the current buffer as news.
357 The headers should be delimited by a line whose contents match the
358 variable `mail-header-separator'."
359 :group 'message-sending
363 (defcustom message-reply-to-function nil
364 "Function that should return a list of headers.
365 This function should pick out addresses from the To, Cc, and From headers
366 and respond with new To and Cc headers."
367 :group 'message-interface
370 (defcustom message-wide-reply-to-function nil
371 "Function that should return a list of headers.
372 This function should pick out addresses from the To, Cc, and From headers
373 and respond with new To and Cc headers."
374 :group 'message-interface
377 (defcustom message-followup-to-function nil
378 "Function that should return a list of headers.
379 This function should pick out addresses from the To, Cc, and From headers
380 and respond with new To and Cc headers."
381 :group 'message-interface
384 (defcustom message-use-followup-to 'ask
385 "*Specifies what to do with Followup-To header.
386 If nil, always ignore the header. If it is t, use its value, but
387 query before using the \"poster\" value. If it is the symbol `ask',
388 always query the user whether to use the value. If it is the symbol
389 `use', always use the value."
390 :group 'message-interface
391 :type '(choice (const :tag "ignore" nil)
395 ;; stuff relating to broken sendmail in MMDF
396 (defcustom message-sendmail-f-is-evil nil
397 "*Non-nil means that \"-f username\" should not be added to the sendmail
398 command line, because it is even more evil than leaving it out."
399 :group 'message-sending
402 ;; qmail-related stuff
403 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
404 "Location of the qmail-inject program."
405 :group 'message-sending
408 (defcustom message-qmail-inject-args nil
409 "Arguments passed to qmail-inject programs.
410 This should be a list of strings, one string for each argument.
412 For e.g., if you wish to set the envelope sender address so that bounces
413 go to the right place or to deal with listserv's usage of that address, you
414 might set this variable to '(\"-f\" \"you@some.where\")."
415 :group 'message-sending
416 :type '(repeat string))
418 (defvar gnus-post-method)
419 (defvar gnus-select-method)
420 (defcustom message-post-method
421 (cond ((and (boundp 'gnus-post-method)
422 (listp gnus-post-method)
425 ((boundp 'gnus-select-method)
428 "*Method used to post news.
429 Note that when posting from inside Gnus, for instance, this
430 variable isn't used."
432 :group 'message-sending
433 ;; This should be the `gnus-select-method' widget, but that might
434 ;; create a dependence to `gnus.el'.
437 (defcustom message-generate-headers-first nil
438 "*If non-nil, generate all possible headers before composing."
439 :group 'message-headers
442 (defcustom message-setup-hook nil
443 "Normal hook, run each time a new outgoing message is initialized.
444 The function `message-setup' runs this hook."
445 :group 'message-various
448 (defcustom message-signature-setup-hook nil
449 "Normal hook, run each time a new outgoing message is initialized.
450 It is run after the headers have been inserted and before
451 the signature is inserted."
452 :group 'message-various
455 (defcustom message-mode-hook nil
456 "Hook run in message mode buffers."
457 :group 'message-various
460 (defcustom message-header-hook nil
461 "Hook run in a message mode buffer narrowed to the headers."
462 :group 'message-various
465 (defcustom message-header-setup-hook nil
466 "Hook called narrowed to the headers when setting up a message buffer."
467 :group 'message-various
471 (defcustom message-citation-line-function 'message-insert-citation-line
472 "*Function called to insert the \"Whomever writes:\" line."
474 :group 'message-insertion)
477 (defcustom message-yank-prefix "> "
478 "*Prefix inserted on the lines of yanked messages.
479 nil means use indentation."
481 :group 'message-insertion)
483 (defcustom message-indentation-spaces 3
484 "*Number of spaces to insert at the beginning of each cited line.
485 Used by `message-yank-original' via `message-yank-cite'."
486 :group 'message-insertion
490 (defcustom message-cite-function 'message-cite-original
491 "*Function for citing an original message.
492 Predefined functions include `message-cite-original' and
493 `message-cite-original-without-signature'.
494 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
495 :type '(radio (function-item message-cite-original)
496 (function-item sc-cite-original)
497 (function :tag "Other"))
498 :group 'message-insertion)
501 (defcustom message-indent-citation-function 'message-indent-citation
502 "*Function for modifying a citation just inserted in the mail buffer.
503 This can also be a list of functions. Each function can find the
504 citation between (point) and (mark t). And each function should leave
505 point and mark around the citation text as modified."
507 :group 'message-insertion)
509 (defvar message-abbrevs-loaded nil)
512 (defcustom message-signature t
513 "*String to be inserted at the end of the message buffer.
514 If t, the `message-signature-file' file will be inserted instead.
515 If a function, the result from the function will be used instead.
516 If a form, the result from the form will be used instead."
518 :group 'message-insertion)
521 (defcustom message-signature-file "~/.signature"
522 "*File containing the text inserted at end of message buffer."
524 :group 'message-insertion)
526 (defcustom message-distribution-function nil
527 "*Function called to return a Distribution header."
529 :group 'message-headers
532 (defcustom message-expires 14
533 "Number of days before your article expires."
535 :group 'message-headers
536 :link '(custom-manual "(message)News Headers")
539 (defcustom message-user-path nil
540 "If nil, use the NNTP server name in the Path header.
541 If stringp, use this; if non-nil, use no host name (user name only)."
543 :group 'message-headers
544 :link '(custom-manual "(message)News Headers")
545 :type '(choice (const :tag "nntp" nil)
547 (sexp :tag "none" :format "%t" t)))
549 (defvar message-reply-buffer nil)
550 (defvar message-reply-headers nil)
551 (defvar message-newsreader nil)
552 (defvar message-mailer nil)
553 (defvar message-sent-message-via nil)
554 (defvar message-checksum nil)
555 (defvar message-send-actions nil
556 "A list of actions to be performed upon successful sending of a message.")
557 (defvar message-exit-actions nil
558 "A list of actions to be performed upon exiting after sending a message.")
559 (defvar message-kill-actions nil
560 "A list of actions to be performed before killing a message buffer.")
561 (defvar message-postpone-actions nil
562 "A list of actions to be performed after postponing a message.")
564 (define-widget 'message-header-lines 'text
565 "All header lines must be LFD terminated."
568 :error "All header lines must be newline terminated")
570 (defcustom message-default-headers ""
571 "*A string containing header lines to be inserted in outgoing messages.
572 It is inserted before you edit the message, so you can edit or delete
574 :group 'message-headers
575 :type 'message-header-lines)
577 (defcustom message-default-mail-headers ""
578 "*A string of header lines to be inserted in outgoing mails."
579 :group 'message-headers
581 :type 'message-header-lines)
583 (defcustom message-default-news-headers ""
584 "*A string of header lines to be inserted in outgoing news
586 :group 'message-headers
588 :type 'message-header-lines)
590 ;; Note: could use /usr/ucb/mail instead of sendmail;
591 ;; options -t, and -v if not interactive.
592 (defcustom message-mailer-swallows-blank-line
593 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
594 system-configuration)
595 (file-readable-p "/etc/sendmail.cf")
596 (let ((buffer (get-buffer-create " *temp*")))
600 (insert-file-contents "/etc/sendmail.cf")
601 (goto-char (point-min))
602 (let ((case-fold-search nil))
603 (re-search-forward "^OR\\>" nil t)))
604 (kill-buffer buffer))))
605 ;; According to RFC822, "The field-name must be composed of printable
606 ;; ASCII characters (i. e., characters that have decimal values between
607 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
609 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
610 "*Set this non-nil if the system's mailer runs the header and body together.
611 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
612 The value should be an expression to test whether the problem will
614 :group 'message-sending
617 ;; Ignore errors in case this is used in Emacs 19.
618 ;; Don't use ignore-errors because this is copied into loaddefs.el.
621 (define-mail-user-agent 'message-user-agent
622 'message-mail 'message-send-and-exit
623 'message-kill-buffer 'message-send-hook)
626 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
627 "If non-nil, delete the deletable headers before feeding to mh.")
629 (defvar message-send-method-alist
630 '((news message-news-p message-send-via-news)
631 (mail message-mail-p message-send-via-mail))
632 "Alist of ways to send outgoing messages.
633 Each element has the form
635 \(TYPE PREDICATE FUNCTION)
637 where TYPE is a symbol that names the method; PREDICATE is a function
638 called without any parameters to determine whether the message is
639 a message of type TYPE; and FUNCTION is a function to be called if
640 PREDICATE returns non-nil. FUNCTION is called with one parameter --
643 (defvar message-mail-alias-type 'abbrev
644 "*What alias expansion type to use in Message buffers.
645 The default is `abbrev', which uses mailabbrev. nil switches
648 (defcustom message-autosave-directory
649 (nnheader-concat message-directory "drafts/")
650 "*Directory where Message autosaves buffers if Gnus isn't running.
651 If nil, Message won't autosave."
652 :group 'message-buffers
655 ;;; Internal variables.
656 ;;; Well, not really internal.
658 (defvar message-mode-syntax-table
659 (let ((table (copy-syntax-table text-mode-syntax-table)))
660 (modify-syntax-entry ?% ". " table)
662 "Syntax table used while in Message mode.")
664 (defvar message-mode-abbrev-table text-mode-abbrev-table
665 "Abbrev table used in Message mode buffers.
666 Defaults to `text-mode-abbrev-table'.")
667 (defgroup message-headers nil
669 :link '(custom-manual "(message)Variables")
672 (defface message-header-to-face
675 (:foreground "green2" :bold t))
678 (:foreground "MidnightBlue" :bold t))
680 (:bold t :italic t)))
681 "Face used for displaying From headers."
682 :group 'message-faces)
684 (defface message-header-cc-face
687 (:foreground "green4" :bold t))
690 (:foreground "MidnightBlue"))
693 "Face used for displaying Cc headers."
694 :group 'message-faces)
696 (defface message-header-subject-face
699 (:foreground "green3"))
702 (:foreground "navy blue" :bold t))
705 "Face used for displaying subject headers."
706 :group 'message-faces)
708 (defface message-header-newsgroups-face
711 (:foreground "yellow" :bold t :italic t))
714 (:foreground "blue4" :bold t :italic t))
716 (:bold t :italic t)))
717 "Face used for displaying newsgroups headers."
718 :group 'message-faces)
720 (defface message-header-other-face
723 (:foreground "#b00000"))
726 (:foreground "steel blue"))
728 (:bold t :italic t)))
729 "Face used for displaying newsgroups headers."
730 :group 'message-faces)
732 (defface message-header-name-face
735 (:foreground "DarkGreen"))
738 (:foreground "cornflower blue"))
741 "Face used for displaying header names."
742 :group 'message-faces)
744 (defface message-header-xheader-face
747 (:foreground "blue"))
750 (:foreground "blue"))
753 "Face used for displaying X-Header headers."
754 :group 'message-faces)
756 (defface message-separator-face
759 (:foreground "blue3"))
762 (:foreground "brown"))
765 "Face used for displaying the separator."
766 :group 'message-faces)
768 (defface message-cited-text-face
777 "Face used for displaying cited text names."
778 :group 'message-faces)
780 (defvar message-font-lock-keywords
781 (let* ((cite-prefix "A-Za-z")
782 (cite-suffix (concat cite-prefix "0-9_.@-"))
783 (content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)"))
784 `((,(concat "^\\([Tt]o:\\)" content)
785 (1 'message-header-name-face)
786 (2 'message-header-to-face nil t))
787 (,(concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content)
788 (1 'message-header-name-face)
789 (2 'message-header-cc-face nil t))
790 (,(concat "^\\([Ss]ubject:\\)" content)
791 (1 'message-header-name-face)
792 (2 'message-header-subject-face nil t))
793 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content)
794 (1 'message-header-name-face)
795 (2 'message-header-newsgroups-face nil t))
796 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content)
797 (1 'message-header-name-face)
798 (2 'message-header-other-face nil t))
799 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content)
800 (1 'message-header-name-face)
801 (2 'message-header-name-face))
802 ,@(if (and mail-header-separator
803 (not (equal mail-header-separator "")))
804 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
805 1 'message-separator-face))
808 "\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
810 (0 'message-cited-text-face))))
811 "Additional expressions to highlight in Message mode.")
813 ;; XEmacs does it like this. For Emacs, we have to set the
814 ;; `font-lock-defaults' buffer-local variable.
815 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
817 (defvar message-face-alist
818 '((bold . bold-region)
819 (underline . underline-region)
820 (default . (lambda (b e)
822 (ununderline-region b e))))
823 "Alist of mail and news faces for facemenu.
824 The cdr of ech entry is a function for applying the face to a region.")
826 (defcustom message-send-hook nil
827 "Hook run before sending messages."
828 :group 'message-various
829 :options '(ispell-message)
832 (defcustom message-send-mail-hook nil
833 "Hook run before sending mail messages."
834 :group 'message-various
837 (defcustom message-send-news-hook nil
838 "Hook run before sending news messages."
839 :group 'message-various
842 (defcustom message-sent-hook nil
843 "Hook run after sending messages."
844 :group 'message-various
847 (defvar message-send-coding-system 'binary
848 "Coding system to encode outgoing mail.")
850 ;;; Internal variables.
852 (defvar message-default-charset nil)
853 (defvar message-buffer-list nil)
854 (defvar message-this-is-news nil)
855 (defvar message-this-is-mail nil)
856 (defvar message-draft-article nil)
858 ;; Byte-compiler warning
859 (defvar gnus-active-hashtb)
860 (defvar gnus-read-active-file)
862 ;;; Regexp matching the delimiter of messages in UNIX mail format
863 ;;; (UNIX From lines), minus the initial ^. It should be a copy
864 ;;; of rmail.el's rmail-unix-mail-delimiter.
865 (defvar message-unix-mail-delimiter
866 (let ((time-zone-regexp
867 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
868 "\\|[-+]?[0-9][0-9][0-9][0-9]"
874 ;; Many things can happen to an RFC 822 mailbox before it is put into
875 ;; a `From' line. The leading phrase can be stripped, e.g.
876 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
877 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
878 ;; can be removed, e.g.
879 ;; From: joe@y.z (Joe K
881 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
884 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
885 ;; The mailbox can be removed or be replaced by white space, e.g.
886 ;; From: "Joe User"{space}{tab}
888 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
889 ;; where {space} and {tab} represent the Ascii space and tab characters.
890 ;; We want to match the results of any of these manglings.
891 ;; The following regexp rejects names whose first characters are
892 ;; obviously bogus, but after that anything goes.
893 "\\([^\0-\b\n-\r\^?].*\\)? "
895 ;; The time the message was sent.
896 "\\([^\0-\r \^?]+\\) +" ; day of the week
897 "\\([^\0-\r \^?]+\\) +" ; month
898 "\\([0-3]?[0-9]\\) +" ; day of month
899 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
901 ;; Perhaps a time zone, specified by an abbreviation, or by a
906 " \\([0-9][0-9]+\\) *"
908 ;; On some systems the time zone can appear after the year, too.
912 "\\(remote from .*\\)?"
915 "Regexp matching the delimiter of messages in UNIX mail format.")
917 (defvar message-unsent-separator
918 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
919 "^ *---+ +Returned message +---+ *$\\|"
920 "^Start of returned message$\\|"
921 "^ *---+ +Original message +---+ *$\\|"
922 "^ *--+ +begin message +--+ *$\\|"
923 "^ *---+ +Original message follows +---+ *$\\|"
924 "^|? *---+ +Message text follows: +---+ *|?$")
925 "A regexp that matches the separator before the text of a failed message.")
927 (defvar message-header-format-alist
929 (To . message-fill-address)
930 (Cc . message-fill-address)
941 (References . message-shorten-references)
943 "Alist used for formatting headers.")
946 (autoload 'message-setup-toolbar "messagexmas")
947 (autoload 'mh-new-draft-name "mh-comp")
948 (autoload 'mh-send-letter "mh-comp")
949 (autoload 'gnus-point-at-eol "gnus-util")
950 (autoload 'gnus-point-at-bol "gnus-util")
951 (autoload 'gnus-output-to-mail "gnus-util")
952 (autoload 'mail-abbrev-in-expansion-header-p "mailabbrev")
953 (autoload 'nndraft-request-associate-buffer "nndraft")
954 (autoload 'nndraft-request-expire-articles "nndraft")
955 (autoload 'gnus-open-server "gnus-int")
956 (autoload 'gnus-request-post "gnus-int")
957 (autoload 'gnus-alive-p "gnus-util")
958 (autoload 'rmail-output "rmail"))
963 ;;; Utility functions.
966 (defmacro message-y-or-n-p (question show &rest text)
967 "Ask QUESTION, displaying the rest of the arguments in a temp. buffer if SHOW"
968 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
970 ;; Delete the current line (and the next N lines.);
971 (defmacro message-delete-line (&optional n)
972 `(delete-region (progn (beginning-of-line) (point))
973 (progn (forward-line ,(or n 1)) (point))))
975 (defun message-tokenize-header (header &optional separator)
976 "Split HEADER into a list of header elements.
977 \",\" is used as the separator."
980 (let ((regexp (format "[%s]+" (or separator ",")))
985 (message-set-work-buffer)
987 (goto-char (point-min))
992 (cond ((and (> (point) beg)
994 (and (looking-at regexp)
997 (push (buffer-substring beg (point)) elems)
998 (setq beg (match-end 0)))
999 ((= (following-char) ?\")
1000 (setq quoted (not quoted)))
1001 ((and (= (following-char) ?\()
1004 ((and (= (following-char) ?\))
1007 (nreverse elems)))))
1009 (defun message-mail-file-mbox-p (file)
1010 "Say whether FILE looks like a Unix mbox file."
1011 (when (and (file-exists-p file)
1012 (file-readable-p file)
1013 (file-regular-p file))
1015 (nnheader-insert-file-contents file)
1016 (goto-char (point-min))
1017 (looking-at message-unix-mail-delimiter))))
1019 (defun message-fetch-field (header &optional not-all)
1020 "The same as `mail-fetch-field', only remove all newlines."
1021 (let* ((inhibit-point-motion-hooks t)
1022 (value (mail-fetch-field header nil (not not-all))))
1024 (nnheader-replace-chars-in-string value ?\n ? ))))
1026 (defun message-narrow-to-field ()
1027 "Narrow the buffer to the header on the current line."
1033 (if (re-search-forward "^[^ \n\t]" nil t)
1038 (goto-char (point-min)))
1040 (defun message-add-header (&rest headers)
1041 "Add the HEADERS to the message header, skipping those already present."
1044 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1045 (error "Invalid header `%s'" (car headers)))
1046 (setq hclean (match-string 1 (car headers)))
1048 (message-narrow-to-headers)
1049 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1050 (insert (car headers) ?\n))))
1051 (setq headers (cdr headers))))
1053 (defun message-fetch-reply-field (header)
1054 "Fetch FIELD from the message we're replying to."
1055 (when (and message-reply-buffer
1056 (buffer-name message-reply-buffer))
1058 (set-buffer message-reply-buffer)
1059 (message-fetch-field header))))
1061 (defun message-set-work-buffer ()
1062 (if (get-buffer " *message work*")
1064 (set-buffer " *message work*")
1066 (set-buffer (get-buffer-create " *message work*"))
1067 (kill-all-local-variables)
1068 (mm-enable-multibyte)))
1070 (defun message-functionp (form)
1071 "Return non-nil if FORM is funcallable."
1072 (or (and (symbolp form) (fboundp form))
1073 (and (listp form) (eq (car form) 'lambda))
1074 (byte-code-function-p form)))
1076 (defun message-strip-subject-re (subject)
1077 "Remove \"Re:\" from subject lines."
1078 (if (string-match message-subject-re-regexp subject)
1079 (substring subject (match-end 0))
1082 (defun message-remove-header (header &optional is-regexp first reverse)
1083 "Remove HEADER in the narrowed buffer.
1084 If REGEXP, HEADER is a regular expression.
1085 If FIRST, only remove the first instance of the header.
1086 Return the number of headers removed."
1087 (goto-char (point-min))
1088 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
1090 (case-fold-search t)
1092 (while (and (not (eobp))
1095 (not (looking-at regexp))
1096 (looking-at regexp))
1103 ;; There might be a continuation header, so we have to search
1104 ;; until we find a new non-continuation line.
1107 (if (re-search-forward "^[^ \t]" nil t)
1108 (goto-char (match-beginning 0))
1111 (if (re-search-forward "^[^ \t]" nil t)
1112 (goto-char (match-beginning 0))
1116 (defun message-narrow-to-headers ()
1117 "Narrow the buffer to the head of the message."
1120 (goto-char (point-min))
1121 (if (re-search-forward
1122 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1125 (goto-char (point-min)))
1127 (defun message-narrow-to-head ()
1128 "Narrow the buffer to the head of the message.
1129 Point is left at the beginning of the narrowed-to region."
1132 (goto-char (point-min))
1133 (if (search-forward "\n\n" nil 1)
1136 (goto-char (point-min)))
1138 (defun message-news-p ()
1139 "Say whether the current buffer contains a news message."
1140 (and (not message-this-is-mail)
1141 (or message-this-is-news
1144 (message-narrow-to-headers)
1145 (and (message-fetch-field "newsgroups")
1146 (not (message-fetch-field "posted-to"))))))))
1148 (defun message-mail-p ()
1149 "Say whether the current buffer contains a mail message."
1150 (and (not message-this-is-news)
1151 (or message-this-is-mail
1154 (message-narrow-to-headers)
1155 (or (message-fetch-field "to")
1156 (message-fetch-field "cc")
1157 (message-fetch-field "bcc")))))))
1159 (defun message-next-header ()
1160 "Go to the beginning of the next header."
1162 (or (eobp) (forward-char 1))
1163 (not (if (re-search-forward "^[^ \t]" nil t)
1165 (goto-char (point-max)))))
1167 (defun message-sort-headers-1 ()
1168 "Sort the buffer as headers using `message-rank' text props."
1169 (goto-char (point-min))
1171 nil 'message-next-header
1173 (message-next-header)
1177 (or (get-text-property (point) 'message-rank)
1180 (defun message-sort-headers ()
1181 "Sort the headers of the current message according to `message-header-format-alist'."
1185 (let ((max (1+ (length message-header-format-alist)))
1187 (message-narrow-to-headers)
1188 (while (re-search-forward "^[^ \n]+:" nil t)
1190 (match-beginning 0) (1+ (match-beginning 0))
1192 (if (setq rank (length (memq (assq (intern (buffer-substring
1194 (1- (match-end 0))))
1195 message-header-format-alist)
1196 message-header-format-alist)))
1199 (message-sort-headers-1))))
1209 (defvar message-mode-map nil)
1211 (unless message-mode-map
1212 (setq message-mode-map (copy-keymap text-mode-map))
1213 (define-key message-mode-map "\C-c?" 'describe-mode)
1215 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
1216 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
1217 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
1218 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
1219 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
1220 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
1221 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
1222 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
1223 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
1224 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
1225 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
1226 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
1227 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
1229 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
1230 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
1232 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
1233 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
1234 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
1235 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
1236 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
1237 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
1239 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
1240 (define-key message-mode-map "\C-c\C-s" 'message-send)
1241 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
1242 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
1244 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
1245 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
1246 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
1247 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
1249 (define-key message-mode-map "\t" 'message-tab))
1252 message-mode-menu message-mode-map "Message Menu."
1254 ["Sort Headers" message-sort-headers t]
1255 ["Yank Original" message-yank-original t]
1256 ["Fill Yanked Message" message-fill-yanked-message t]
1257 ["Insert Signature" message-insert-signature t]
1258 ["Caesar (rot13) Message" message-caesar-buffer-body t]
1259 ["Caesar (rot13) Region" message-caesar-region (mark t)]
1260 ["Elide Region" message-elide-region (mark t)]
1261 ["Delete Outside Region" message-delete-not-region (mark t)]
1262 ["Kill To Signature" message-kill-to-signature t]
1263 ["Newline and Reformat" message-newline-and-reformat t]
1264 ["Rename buffer" message-rename-buffer t]
1265 ["Spellcheck" ispell-message t]
1267 ["Send Message" message-send-and-exit t]
1268 ["Abort Message" message-dont-send t]
1269 ["Kill Message" message-kill-buffer t]))
1272 message-mode-field-menu message-mode-map ""
1274 ["Fetch To" message-insert-to t]
1275 ["Fetch Newsgroups" message-insert-newsgroups t]
1277 ["To" message-goto-to t]
1278 ["Subject" message-goto-subject t]
1279 ["Cc" message-goto-cc t]
1280 ["Reply-To" message-goto-reply-to t]
1281 ["Summary" message-goto-summary t]
1282 ["Keywords" message-goto-keywords t]
1283 ["Newsgroups" message-goto-newsgroups t]
1284 ["Followup-To" message-goto-followup-to t]
1285 ["Distribution" message-goto-distribution t]
1286 ["Body" message-goto-body t]
1287 ["Signature" message-goto-signature t]))
1289 (defvar facemenu-add-face-function)
1290 (defvar facemenu-remove-face-function)
1293 (defun message-mode ()
1294 "Major mode for editing mail and news to be sent.
1295 Like Text Mode but with these additional commands:
1296 C-c C-s message-send (send the message) C-c C-c message-send-and-exit
1297 C-c C-f move to a header field (and create it if there isn't):
1298 C-c C-f C-t move to To C-c C-f C-s move to Subject
1299 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1300 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1301 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1302 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1303 C-c C-f C-f move to Followup-To
1304 C-c C-t message-insert-to (add a To header to a news followup)
1305 C-c C-n message-insert-newsgroups (add a Newsgroup header to a news reply)
1306 C-c C-b message-goto-body (move to beginning of message text).
1307 C-c C-i message-goto-signature (move to the beginning of the signature).
1308 C-c C-w message-insert-signature (insert `message-signature-file' file).
1309 C-c C-y message-yank-original (insert current message, if any).
1310 C-c C-q message-fill-yanked-message (fill what was yanked).
1311 C-c C-e message-elide-region (elide the text between point and mark).
1312 C-c C-z message-kill-to-signature (kill the text up to the signature).
1313 C-c C-r message-caesar-buffer-body (rot13 the message body)."
1315 (kill-all-local-variables)
1316 (make-local-variable 'message-reply-buffer)
1317 (setq message-reply-buffer nil)
1318 (make-local-variable 'message-send-actions)
1319 (make-local-variable 'message-exit-actions)
1320 (make-local-variable 'message-kill-actions)
1321 (make-local-variable 'message-postpone-actions)
1322 (make-local-variable 'message-draft-article)
1323 (make-local-hook 'kill-buffer-hook)
1324 (set-syntax-table message-mode-syntax-table)
1325 (use-local-map message-mode-map)
1326 (setq local-abbrev-table message-mode-abbrev-table)
1327 (setq major-mode 'message-mode)
1328 (setq mode-name "Message")
1329 (setq buffer-offer-save t)
1330 (make-local-variable 'facemenu-add-face-function)
1331 (make-local-variable 'facemenu-remove-face-function)
1332 (setq facemenu-add-face-function
1334 (let ((face-fun (cdr (assq face message-face-alist))))
1336 (funcall face-fun (point) end)
1337 (error "Face %s not configured for %s mode" face mode-name)))
1339 facemenu-remove-face-function t)
1340 (make-local-variable 'paragraph-separate)
1341 (make-local-variable 'paragraph-start)
1342 ;; `-- ' precedes the signature. `-----' appears at the start of the
1343 ;; lines that delimit forwarded messages.
1344 ;; Lines containing just >= 3 dashes, perhaps after whitespace,
1345 ;; are also sometimes used and should be separators.
1346 (setq paragraph-start
1347 (concat (regexp-quote mail-header-separator)
1348 "$\\|[ \t]*[a-z0-9A-Z]*>+[ \t]*$\\|[ \t]*$\\|"
1351 ;;!!! Uhm... shurely this can't be right?
1352 "[> " (regexp-quote message-yank-prefix) "]+$"))
1353 (setq paragraph-separate paragraph-start)
1354 (make-local-variable 'message-reply-headers)
1355 (setq message-reply-headers nil)
1356 (make-local-variable 'message-newsreader)
1357 (make-local-variable 'message-mailer)
1358 (make-local-variable 'message-post-method)
1359 (make-local-variable 'message-sent-message-via)
1360 (setq message-sent-message-via nil)
1361 (make-local-variable 'message-checksum)
1362 (setq message-checksum nil)
1363 ;;(when (fboundp 'mail-hist-define-keys)
1364 ;; (mail-hist-define-keys))
1365 (when (string-match "XEmacs\\|Lucid" emacs-version)
1366 (message-setup-toolbar))
1367 (easy-menu-add message-mode-menu message-mode-map)
1368 (easy-menu-add message-mode-field-menu message-mode-map)
1369 ;; Allow mail alias things.
1370 (when (eq message-mail-alias-type 'abbrev)
1371 (if (fboundp 'mail-abbrevs-setup)
1372 (mail-abbrevs-setup)
1373 (mail-aliases-setup)))
1374 (message-set-auto-save-file-name)
1375 (unless (string-match "XEmacs" emacs-version)
1376 (set (make-local-variable 'font-lock-defaults)
1377 '(message-font-lock-keywords t)))
1378 (make-local-variable 'adaptive-fill-regexp)
1379 (setq adaptive-fill-regexp
1380 (concat "[ \t]*[-a-z0-9A-Z]*>+[ \t]*\\|" adaptive-fill-regexp))
1381 (unless (boundp 'adaptive-fill-first-line-regexp)
1382 (setq adaptive-fill-first-line-regexp nil))
1383 (make-local-variable 'adaptive-fill-first-line-regexp)
1384 (setq adaptive-fill-first-line-regexp
1385 (concat "[ \t]*[-a-z0-9A-Z]*>+[ \t]*\\|"
1386 adaptive-fill-first-line-regexp))
1387 (mm-enable-multibyte)
1388 (run-hooks 'text-mode-hook 'message-mode-hook))
1393 ;;; Message mode commands
1396 ;;; Movement commands
1398 (defun message-goto-to ()
1399 "Move point to the To header."
1401 (message-position-on-field "To"))
1403 (defun message-goto-subject ()
1404 "Move point to the Subject header."
1406 (message-position-on-field "Subject"))
1408 (defun message-goto-cc ()
1409 "Move point to the Cc header."
1411 (message-position-on-field "Cc" "To"))
1413 (defun message-goto-bcc ()
1414 "Move point to the Bcc header."
1416 (message-position-on-field "Bcc" "Cc" "To"))
1418 (defun message-goto-fcc ()
1419 "Move point to the Fcc header."
1421 (message-position-on-field "Fcc" "To" "Newsgroups"))
1423 (defun message-goto-reply-to ()
1424 "Move point to the Reply-To header."
1426 (message-position-on-field "Reply-To" "Subject"))
1428 (defun message-goto-newsgroups ()
1429 "Move point to the Newsgroups header."
1431 (message-position-on-field "Newsgroups"))
1433 (defun message-goto-distribution ()
1434 "Move point to the Distribution header."
1436 (message-position-on-field "Distribution"))
1438 (defun message-goto-followup-to ()
1439 "Move point to the Followup-To header."
1441 (message-position-on-field "Followup-To" "Newsgroups"))
1443 (defun message-goto-keywords ()
1444 "Move point to the Keywords header."
1446 (message-position-on-field "Keywords" "Subject"))
1448 (defun message-goto-summary ()
1449 "Move point to the Summary header."
1451 (message-position-on-field "Summary" "Subject"))
1453 (defun message-goto-body ()
1454 "Move point to the beginning of the message body."
1456 (if (looking-at "[ \t]*\n") (expand-abbrev))
1457 (goto-char (point-min))
1458 (search-forward (concat "\n" mail-header-separator "\n") nil t))
1460 (defun message-goto-eoh ()
1461 "Move point to the end of the headers."
1466 (defun message-goto-signature ()
1467 "Move point to the beginning of the message signature.
1468 If there is no signature in the article, go to the end and
1471 (goto-char (point-min))
1472 (if (re-search-forward message-signature-separator nil t)
1474 (goto-char (point-max))
1479 (defun message-insert-to (&optional force)
1480 "Insert a To header that points to the author of the article being replied to.
1481 If the original author requested not to be sent mail, the function signals
1483 With the prefix argument FORCE, insert the header anyway."
1485 (let ((co (message-fetch-reply-field "mail-copies-to")))
1486 (when (and (null force)
1488 (equal (downcase co) "never"))
1489 (error "The user has requested not to have copies sent via mail")))
1490 (when (and (message-position-on-field "To")
1491 (mail-fetch-field "to")
1492 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
1494 (insert (or (message-fetch-reply-field "reply-to")
1495 (message-fetch-reply-field "from") "")))
1497 (defun message-insert-newsgroups ()
1498 "Insert the Newsgroups header from the article being replied to."
1500 (when (and (message-position-on-field "Newsgroups")
1501 (mail-fetch-field "newsgroups")
1502 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
1504 (insert (or (message-fetch-reply-field "newsgroups") "")))
1508 ;;; Various commands
1510 (defun message-delete-not-region (beg end)
1511 "Delete everything in the body of the current message that is outside of the region."
1515 (delete-region (point) (if (not (message-goto-signature))
1521 (delete-region beg (progn (message-goto-body)
1524 (when (message-goto-signature)
1527 (defun message-kill-to-signature ()
1528 "Deletes all text up to the signature."
1530 (let ((point (point)))
1531 (message-goto-signature)
1534 (kill-region point (point))
1538 (defun message-newline-and-reformat ()
1539 "Insert four newlines, and then reformat if inside quoted text."
1541 (let ((point (point))
1545 (setq quoted (looking-at (regexp-quote message-yank-prefix))))
1548 (insert message-yank-prefix))
1549 (fill-paragraph nil)
1553 (defun message-insert-signature (&optional force)
1554 "Insert a signature. See documentation for the `message-signature' variable."
1555 (interactive (list 0))
1558 ((and (null message-signature)
1561 (goto-char (point-max))
1562 (not (re-search-backward
1563 message-signature-separator nil t))))
1564 ((and (null message-signature)
1567 ((message-functionp message-signature)
1568 (funcall message-signature))
1569 ((listp message-signature)
1570 (eval message-signature))
1571 (t message-signature)))
1573 (cond ((stringp signature)
1575 ((and (eq t signature)
1576 message-signature-file
1577 (file-exists-p message-signature-file))
1580 (goto-char (point-max))
1581 ;; Insert the signature.
1585 (if (eq signature t)
1586 (insert-file-contents message-signature-file)
1588 (goto-char (point-max))
1589 (or (bolp) (insert "\n")))))
1591 (defun message-elide-region (b e)
1592 "Elide the text between point and mark.
1593 An ellipsis (from `message-elide-elipsis') will be inserted where the
1599 (insert message-elide-elipsis))
1601 (defvar message-caesar-translation-table nil)
1603 (defun message-caesar-region (b e &optional n)
1604 "Caesar rotation of region by N, default 13, for decrypting netnews."
1607 (min (point) (or (mark t) (point)))
1608 (max (point) (or (mark t) (point)))
1609 (when current-prefix-arg
1610 (prefix-numeric-value current-prefix-arg))))
1612 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
1613 (unless (or (zerop n) ; no action needed for a rot of 0
1614 (= b e)) ; no region to rotate
1615 ;; We build the table, if necessary.
1616 (when (or (not message-caesar-translation-table)
1617 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
1618 (setq message-caesar-translation-table
1619 (message-make-caesar-translation-table n)))
1620 ;; Then we translate the region. Do it this way to retain
1623 (when (< (char-after b) 255)
1624 (subst-char-in-region
1625 b (1+ b) (char-after b)
1626 (aref message-caesar-translation-table (char-after b))))
1629 (defun message-make-caesar-translation-table (n)
1630 "Create a rot table with offset N."
1632 (table (make-string 256 0)))
1633 (while (< (incf i) 256)
1636 (substring table 0 ?A)
1637 (substring table (+ ?A n) (+ ?A n (- 26 n)))
1638 (substring table ?A (+ ?A n))
1639 (substring table (+ ?A 26) ?a)
1640 (substring table (+ ?a n) (+ ?a n (- 26 n)))
1641 (substring table ?a (+ ?a n))
1642 (substring table (+ ?a 26) 255))))
1644 (defun message-caesar-buffer-body (&optional rotnum)
1645 "Caesar rotates all letters in the current buffer by 13 places.
1646 Used to encode/decode possiblyun offensive messages (commonly in net.jokes).
1647 With prefix arg, specifies the number of places to rotate each letter forward.
1648 Mail and USENET news headers are not rotated."
1649 (interactive (if current-prefix-arg
1650 (list (prefix-numeric-value current-prefix-arg))
1654 (when (message-goto-body)
1655 (narrow-to-region (point) (point-max)))
1656 (message-caesar-region (point-min) (point-max) rotnum))))
1658 (defun message-pipe-buffer-body (program)
1659 "Pipe the message body in the current buffer through PROGRAM."
1662 (when (message-goto-body)
1663 (narrow-to-region (point) (point-max)))
1664 (let ((body (buffer-substring (point-min) (point-max))))
1665 (unless (equal 0 (call-process-region
1666 (point-min) (point-max) program t t))
1668 (message "%s failed." program))))))
1670 (defun message-rename-buffer (&optional enter-string)
1671 "Rename the *message* buffer to \"*message* RECIPIENT\".
1672 If the function is run with a prefix, it will ask for a new buffer
1673 name, rather than giving an automatic name."
1674 (interactive "Pbuffer name: ")
1677 (goto-char (point-min))
1678 (narrow-to-region (point)
1679 (search-forward mail-header-separator nil 'end))
1681 (if (message-news-p) (message-fetch-field "Newsgroups")
1682 (message-fetch-field "To"))
1685 (if (string-match "," mail-to)
1686 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
1688 (name-default (concat "*message* " mail-trimmed-to))
1689 (name (if enter-string
1690 (read-string "New buffer name: " name-default)
1692 (rename-buffer name t)))))
1694 (defun message-fill-yanked-message (&optional justifyp)
1695 "Fill the paragraphs of a message yanked into this one.
1696 Numeric argument means justify as well."
1699 (goto-char (point-min))
1700 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1701 (let ((fill-prefix message-yank-prefix))
1702 (fill-individual-paragraphs (point) (point-max) justifyp t))))
1704 (defun message-indent-citation ()
1705 "Modify text just inserted from a message to be cited.
1706 The inserted text should be the region.
1707 When this function returns, the region is again around the modified text.
1709 Normally, indent each nonblank line `message-indentation-spaces' spaces.
1710 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
1711 (let ((start (point)))
1712 ;; Remove unwanted headers.
1713 (when message-ignored-cited-headers
1718 (if (search-forward "\n\n" nil t)
1721 (message-remove-header message-ignored-cited-headers t)
1722 (when (= (point-min) (point-max))
1723 (setq all-removed t))
1724 (goto-char (point-max)))
1728 ;; Delete blank lines at the start of the buffer.
1729 (while (and (point-min)
1732 (message-delete-line))
1733 ;; Delete blank lines at the end of the buffer.
1734 (goto-char (point-max))
1737 (while (and (zerop (forward-line -1))
1739 (message-delete-line))
1740 ;; Do the indentation.
1741 (if (null message-yank-prefix)
1742 (indent-rigidly start (mark t) message-indentation-spaces)
1745 (while (< (point) (mark t))
1746 (insert message-yank-prefix)
1750 (defun message-yank-original (&optional arg)
1751 "Insert the message being replied to, if any.
1752 Puts point before the text and mark after.
1753 Normally indents each nonblank line ARG spaces (default 3). However,
1754 if `message-yank-prefix' is non-nil, insert that prefix on each line.
1756 This function uses `message-cite-function' to do the actual citing.
1758 Just \\[universal-argument] as argument means don't indent, insert no
1759 prefix, and don't delete any headers."
1761 (let ((modified (buffer-modified-p)))
1762 (when (and message-reply-buffer
1763 message-cite-function)
1764 (delete-windows-on message-reply-buffer t)
1765 (insert-buffer message-reply-buffer)
1766 (funcall message-cite-function)
1767 (message-exchange-point-and-mark)
1771 (setq message-checksum (message-checksum))))))
1773 (defun message-cite-original-without-signature ()
1774 "Cite function in the standard Message manner."
1775 (let ((start (point))
1778 (when message-indent-citation-function
1779 (if (listp message-indent-citation-function)
1780 message-indent-citation-function
1781 (list message-indent-citation-function)))))
1783 (when (re-search-backward "^-- $" start t)
1784 ;; Also peel off any blank lines before the signature.
1786 (while (looking-at "^[ \t]*$")
1789 (delete-region (point) end))
1792 (funcall (pop functions)))
1793 (when message-citation-line-function
1796 (funcall message-citation-line-function))))
1798 (defvar mail-citation-hook) ;Compiler directive
1799 (defun message-cite-original ()
1800 "Cite function in the standard Message manner."
1801 (if (and (boundp 'mail-citation-hook)
1803 (run-hooks 'mail-citation-hook)
1804 (let ((start (point))
1806 (when message-indent-citation-function
1807 (if (listp message-indent-citation-function)
1808 message-indent-citation-function
1809 (list message-indent-citation-function)))))
1812 (funcall (pop functions)))
1813 (when message-citation-line-function
1816 (funcall message-citation-line-function)))))
1818 (defun message-insert-citation-line ()
1819 "Function that inserts a simple citation line."
1820 (when message-reply-headers
1821 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
1823 (defun message-position-on-field (header &rest afters)
1824 (let ((case-fold-search t))
1827 (goto-char (point-min))
1830 (concat "^" (regexp-quote mail-header-separator) "$"))
1831 (match-beginning 0)))
1832 (goto-char (point-min))
1833 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
1835 (re-search-forward "^[^ \t]" nil 'move)
1837 (skip-chars-backward "\n")
1840 (not (re-search-forward
1841 (concat "^" (regexp-quote (car afters)) ":")
1845 (re-search-forward "^[^ \t]" nil 'move)
1846 (beginning-of-line))
1847 (insert header ": \n")
1851 (defun message-remove-signature ()
1852 "Remove the signature from the text between point and mark.
1853 The text will also be indented the normal way."
1855 (let ((start (point))
1857 (if (not (re-search-forward message-signature-separator (mark t) t))
1858 ;; No signature here, so we just indent the cited text.
1859 (message-indent-citation)
1860 ;; Find the last non-empty line.
1862 (while (looking-at "[ \t]*$")
1865 (setq mark (set-marker (make-marker) (point)))
1867 (message-indent-citation)
1868 ;; Enable undoing the deletion.
1870 (delete-region mark (mark t))
1871 (set-marker mark nil)))))
1876 ;;; Sending messages
1879 (defun message-send-and-exit (&optional arg)
1880 "Send message like `message-send', then, if no errors, exit from mail buffer."
1882 (let ((buf (current-buffer))
1883 (actions message-exit-actions))
1884 (when (and (message-send arg)
1886 (if message-kill-buffer-on-exit
1889 (when (eq buf (current-buffer))
1890 (message-bury buf)))
1891 (message-do-actions actions)
1894 (defun message-dont-send ()
1895 "Don't send the message you have been editing."
1897 (set-buffer-modified-p t)
1899 (let ((actions message-postpone-actions))
1900 (message-bury (current-buffer))
1901 (message-do-actions actions)))
1903 (defun message-kill-buffer ()
1904 "Kill the current buffer."
1906 (when (or (not (buffer-modified-p))
1907 (yes-or-no-p "Message modified; kill anyway? "))
1908 (let ((actions message-kill-actions))
1909 (setq buffer-file-name nil)
1910 (kill-buffer (current-buffer))
1911 (message-do-actions actions))))
1913 (defun message-bury (buffer)
1914 "Bury this mail buffer."
1915 (let ((newbuf (other-buffer buffer)))
1916 (bury-buffer buffer)
1917 (if (and (fboundp 'frame-parameters)
1918 (cdr (assq 'dedicated (frame-parameters)))
1919 (not (null (delq (selected-frame) (visible-frame-list)))))
1920 (delete-frame (selected-frame))
1921 (switch-to-buffer newbuf))))
1923 (defun message-send (&optional arg)
1924 "Send the message in the current buffer.
1925 If `message-interactive' is non-nil, wait for success indication
1926 or error messages, and inform user.
1927 Otherwise any failure is reported in a message back to
1928 the user from the mailer."
1931 (when (or (buffer-modified-p)
1932 (message-check-element 'unchanged)
1933 (y-or-n-p "No changes in the buffer; really send? "))
1934 ;; Make it possible to undo the coming changes.
1936 (let ((inhibit-read-only t))
1937 (put-text-property (point-min) (point-max) 'read-only nil))
1938 (message-fix-before-sending)
1939 (run-hooks 'message-send-hook)
1940 (message "Sending...")
1941 (let ((alist message-send-method-alist)
1945 (setq elem (pop alist)))
1946 (when (and (or (not (funcall (cadr elem)))
1947 (and (or (not (memq (car elem)
1948 message-sent-message-via))
1951 "Already sent message via %s; resend? "
1953 (setq success (funcall (caddr elem) arg)))))
1955 (when (and success sent)
1957 ;;(when (fboundp 'mail-hist-put-headers-into-history)
1958 ;; (mail-hist-put-headers-into-history))
1959 (run-hooks 'message-sent-hook)
1960 (message "Sending...done")
1961 ;; Mark the buffer as unmodified and delete autosave.
1962 (set-buffer-modified-p nil)
1963 (delete-auto-save-file-if-necessary t)
1964 (message-disassociate-draft)
1965 ;; Delete other mail buffers and stuff.
1966 (message-do-send-housekeeping)
1967 (message-do-actions message-send-actions)
1971 (defun message-send-via-mail (arg)
1972 "Send the current message via mail."
1973 (message-send-mail arg))
1975 (defun message-send-via-news (arg)
1976 "Send the current message via news."
1977 (funcall message-send-news-function arg))
1979 (defun message-fix-before-sending ()
1980 "Do various things to make the message nice before sending it."
1981 ;; Make sure there's a newline at the end of the message.
1982 (goto-char (point-max))
1985 ;; Delete all invisible text.
1986 (when (text-property-any (point-min) (point-max) 'invisible t)
1987 (put-text-property (point-min) (point-max) 'invisible nil)
1988 (unless (yes-or-no-p "Invisible text found and made visible; continue posting?")
1989 (error "Invisible text found and made visible"))))
1991 (defun message-add-action (action &rest types)
1992 "Add ACTION to be performed when doing an exit of type TYPES."
1995 (set (setq var (intern (format "message-%s-actions" (pop types))))
1996 (nconc (symbol-value var) (list action))))))
1998 (defun message-do-actions (actions)
1999 "Perform all actions in ACTIONS."
2000 ;; Now perform actions on successful sending.
2004 ;; A simple function.
2005 ((message-functionp (car actions))
2006 (funcall (car actions)))
2007 ;; Something to be evaled.
2009 (eval (car actions)))))
2012 (defun message-send-mail (&optional arg)
2013 (require 'mail-utils)
2014 (let ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
2015 (case-fold-search nil)
2016 (news (message-news-p))
2017 (mailbuf (current-buffer)))
2019 (message-narrow-to-headers)
2020 ;; Insert some headers.
2021 (let ((message-deletable-headers
2022 (if news nil message-deletable-headers)))
2023 (message-generate-headers message-required-mail-headers))
2024 (rfc2047-encode-message-header)
2025 ;; Let the user do all of the above.
2026 (run-hooks 'message-header-hook))
2027 (message-encode-message-body)
2032 ;; Avoid copying text props.
2034 "%s" (save-excursion
2035 (set-buffer mailbuf)
2037 ;; Remove some headers.
2039 (message-narrow-to-headers)
2040 ;; Remove some headers.
2041 (message-remove-header message-ignored-mail-headers t))
2042 (goto-char (point-max))
2043 ;; require one newline at the end.
2044 (or (= (preceding-char) ?\n)
2047 (or (message-fetch-field "cc")
2048 (message-fetch-field "to")))
2049 (message-insert-courtesy-copy))
2050 (funcall message-send-mail-function))
2051 (kill-buffer tembuf))
2052 (set-buffer mailbuf)
2053 (push 'mail message-sent-message-via)))
2055 (defun message-send-mail-with-sendmail ()
2056 "Send off the prepared buffer with sendmail."
2057 (let ((errbuf (if message-interactive
2058 (generate-new-buffer " sendmail errors")
2060 resend-to-addresses delimline)
2061 (let ((case-fold-search t))
2063 (message-narrow-to-headers)
2064 (setq resend-to-addresses (message-fetch-field "resent-to")))
2065 ;; Change header-delimiter to be what sendmail expects.
2066 (goto-char (point-min))
2068 (concat "^" (regexp-quote mail-header-separator) "\n"))
2069 (replace-match "\n")
2071 (setq delimline (point-marker))
2072 (run-hooks 'message-send-mail-hook)
2073 ;; Insert an extra newline if we need it to work around
2074 ;; Sun's bug that swallows newlines.
2075 (goto-char (1+ delimline))
2076 (when (eval message-mailer-swallows-blank-line)
2078 (when message-interactive
2082 (let ((default-directory "/")
2083 (coding-system-for-write message-send-coding-system))
2084 (apply 'call-process-region
2085 (append (list (point-min) (point-max)
2086 (if (boundp 'sendmail-program)
2088 "/usr/lib/sendmail")
2089 nil errbuf nil "-oi")
2090 ;; Always specify who from,
2091 ;; since some systems have broken sendmails.
2092 ;; But some systems are more broken with -f, so
2093 ;; we'll let users override this.
2094 (if (null message-sendmail-f-is-evil)
2095 (list "-f" (user-login-name)))
2096 ;; These mean "report errors by mail"
2097 ;; and "deliver in background".
2098 (if (null message-interactive) '("-oem" "-odb"))
2099 ;; Get the addresses from the message
2100 ;; unless this is a resend.
2101 ;; We must not do that for a resend
2102 ;; because we would find the original addresses.
2103 ;; For a resend, include the specific addresses.
2104 (if resend-to-addresses
2105 (list resend-to-addresses)
2107 (when message-interactive
2110 (goto-char (point-min))
2111 (while (re-search-forward "\n\n* *" nil t)
2112 (replace-match "; "))
2113 (if (not (zerop (buffer-size)))
2114 (error "Sending...failed to %s"
2115 (buffer-substring (point-min) (point-max)))))
2116 (when (bufferp errbuf)
2117 (kill-buffer errbuf)))))
2119 (defun message-send-mail-with-qmail ()
2120 "Pass the prepared message buffer to qmail-inject.
2121 Refer to the documentation for the variable `message-send-mail-function'
2122 to find out how to use this."
2123 ;; replace the header delimiter with a blank line
2124 (goto-char (point-min))
2126 (concat "^" (regexp-quote mail-header-separator) "\n"))
2127 (replace-match "\n")
2128 (run-hooks 'message-send-mail-hook)
2131 (let ((coding-system-for-write message-send-coding-system))
2133 'call-process-region 1 (point-max) message-qmail-inject-program
2135 ;; qmail-inject's default behaviour is to look for addresses on the
2136 ;; command line; if there're none, it scans the headers.
2137 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
2139 ;; in general, ALL of qmail-inject's defaults are perfect for simply
2140 ;; reading a formatted (i. e., at least a To: or Resent-To header)
2141 ;; message from stdin.
2143 ;; qmail also has the advantage of not having been raped by
2144 ;; various vendors, so we don't have to allow for that, either --
2145 ;; compare this with message-send-mail-with-sendmail and weep
2146 ;; for sendmail's lost innocence.
2148 ;; all this is way cool coz it lets us keep the arguments entirely
2149 ;; free for -inject-arguments -- a big win for the user and for us
2150 ;; since we don't have to play that double-guessing game and the user
2151 ;; gets full control (no gestapo'ish -f's, for instance). --sj
2152 message-qmail-inject-args))
2153 ;; qmail-inject doesn't say anything on it's stdout/stderr,
2154 ;; we have to look at the retval instead
2156 (1 (error "qmail-inject reported permanent failure"))
2157 (111 (error "qmail-inject reported transient failure"))
2158 ;; should never happen
2159 (t (error "qmail-inject reported unknown failure"))))
2161 (defun message-send-mail-with-mh ()
2162 "Send the prepared message buffer with mh."
2163 (let ((mh-previous-window-config nil)
2164 (name (mh-new-draft-name)))
2165 (setq buffer-file-name name)
2166 ;; MH wants to generate these headers itself.
2167 (when message-mh-deletable-headers
2168 (let ((headers message-mh-deletable-headers))
2170 (goto-char (point-min))
2171 (and (re-search-forward
2172 (concat "^" (symbol-name (car headers)) ": *") nil t)
2173 (message-delete-line))
2175 (run-hooks 'message-send-mail-hook)
2176 ;; Pass it on to mh.
2179 (defun message-send-news (&optional arg)
2180 (let ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
2181 (case-fold-search nil)
2182 (method (if (message-functionp message-post-method)
2183 (funcall message-post-method arg)
2184 message-post-method))
2185 (messbuf (current-buffer))
2186 (message-syntax-checks
2188 (cons '(existing-newsgroups . disabled)
2189 message-syntax-checks)
2190 message-syntax-checks))
2193 (message-narrow-to-headers)
2194 ;; Insert some headers.
2195 (message-generate-headers message-required-news-headers)
2196 (rfc2047-encode-message-header)
2197 ;; Let the user do all of the above.
2198 (run-hooks 'message-header-hook))
2199 (message-encode-message-body)
2200 (message-cleanup-headers)
2201 (if (not (message-check-news-syntax))
2203 ;;(message "Posting not performed")
2208 (buffer-disable-undo (current-buffer))
2210 ;; Avoid copying text props.
2212 "%s" (save-excursion
2213 (set-buffer messbuf)
2215 ;; Remove some headers.
2217 (message-narrow-to-headers)
2218 ;; Remove some headers.
2219 (message-remove-header message-ignored-news-headers t))
2220 (goto-char (point-max))
2221 ;; require one newline at the end.
2222 (or (= (preceding-char) ?\n)
2224 (let ((case-fold-search t))
2225 ;; Remove the delimiter.
2226 (goto-char (point-min))
2228 (concat "^" (regexp-quote mail-header-separator) "\n"))
2229 (replace-match "\n")
2231 (run-hooks 'message-send-news-hook)
2232 ;;(require (car method))
2233 ;;(funcall (intern (format "%s-open-server" (car method)))
2234 ;;(cadr method) (cddr method))
2236 ;; (funcall (intern (format "%s-request-post" (car method)))
2238 (gnus-open-server method)
2239 (setq result (gnus-request-post method)))
2240 (kill-buffer tembuf))
2241 (set-buffer messbuf)
2243 (push 'news message-sent-message-via)
2244 (message "Couldn't send message via news: %s"
2245 (nnheader-get-report (car method)))
2249 ;;; Header generation & syntax checking.
2252 (defmacro message-check (type &rest forms)
2253 "Eval FORMS if TYPE is to be checked."
2254 `(or (message-check-element ,type)
2258 (put 'message-check 'lisp-indent-function 1)
2259 (put 'message-check 'edebug-form-spec '(form body))
2261 (defun message-check-element (type)
2262 "Returns non-nil if this type is not to be checked."
2263 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
2265 (let ((able (assq type message-syntax-checks)))
2267 (eq (cdr able) 'disabled)))))
2269 (defun message-check-news-syntax ()
2270 "Check the syntax of the message."
2275 ;; We narrow to the headers and check them first.
2278 (message-narrow-to-headers)
2279 (message-check-news-header-syntax)))
2281 (message-check-news-body-syntax)))))
2283 (defun message-check-news-header-syntax ()
2285 ;; Check the Subject header.
2286 (message-check 'subject
2287 (let* ((case-fold-search t)
2288 (subject (message-fetch-field "subject")))
2291 (not (string-match "\\`[ \t]*\\'" subject)))
2294 "The subject field is empty or missing. Posting is denied.")))))
2295 ;; Check for commands in Subject.
2296 (message-check 'subject-cmsg
2297 (if (string-match "^cmsg " (message-fetch-field "subject"))
2299 "The control code \"cmsg\" is in the subject. Really post? ")
2301 ;; Check for multiple identical headers.
2302 (message-check 'multiple-headers
2304 (while (and (not found)
2305 (re-search-forward "^[^ \t:]+: " nil t))
2307 (or (re-search-forward
2312 (match-beginning 0) (- (match-end 0) 2))))
2317 (y-or-n-p (format "Multiple %s headers. Really post? " found))
2319 ;; Check for Version and Sendsys.
2320 (message-check 'sendsys
2321 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
2323 (format "The article contains a %s command. Really post? "
2324 (buffer-substring (match-beginning 0)
2325 (1- (match-end 0)))))
2327 ;; See whether we can shorten Followup-To.
2328 (message-check 'shorten-followup-to
2329 (let ((newsgroups (message-fetch-field "newsgroups"))
2330 (followup-to (message-fetch-field "followup-to"))
2332 (when (and newsgroups
2333 (string-match "," newsgroups)
2338 (setq to (completing-read
2339 "Followups to: (default all groups) "
2340 (mapcar (lambda (g) (list g))
2342 (message-tokenize-header
2344 (goto-char (point-min))
2345 (insert "Followup-To: " to "\n"))
2347 ;; Check "Shoot me".
2348 (message-check 'shoot
2349 (if (re-search-forward
2350 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
2351 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
2353 ;; Check for Approved.
2354 (message-check 'approved
2355 (if (re-search-forward "^Approved:" nil t)
2356 (y-or-n-p "The article contains an Approved header. Really post? ")
2358 ;; Check the Message-ID header.
2359 (message-check 'message-id
2360 (let* ((case-fold-search t)
2361 (message-id (message-fetch-field "message-id" t)))
2362 (or (not message-id)
2363 ;; Is there an @ in the ID?
2364 (and (string-match "@" message-id)
2365 ;; Is there a dot in the ID?
2366 (string-match "@[^.]*\\." message-id)
2367 ;; Does the ID end with a dot?
2368 (not (string-match "\\.>" message-id)))
2370 (format "The Message-ID looks strange: \"%s\". Really post? "
2372 ;; Check the Newsgroups & Followup-To headers.
2373 (message-check 'existing-newsgroups
2374 (let* ((case-fold-search t)
2375 (newsgroups (message-fetch-field "newsgroups"))
2376 (followup-to (message-fetch-field "followup-to"))
2377 (groups (message-tokenize-header
2379 (concat newsgroups "," followup-to)
2381 (hashtb (and (boundp 'gnus-active-hashtb)
2382 gnus-active-hashtb))
2384 (if (or (not hashtb)
2385 (not (boundp 'gnus-read-active-file))
2386 (not gnus-read-active-file)
2387 (eq gnus-read-active-file 'some))
2390 (when (and (not (boundp (intern (car groups) hashtb)))
2391 (not (equal (car groups) "poster")))
2392 (push (car groups) errors))
2398 "Really post to %s unknown group%s: %s "
2399 (if (= (length errors) 1) "this" "these")
2400 (if (= (length errors) 1) "" "s")
2401 (mapconcat 'identity errors ", ")))))))
2402 ;; Check the Newsgroups & Followup-To headers for syntax errors.
2403 (message-check 'valid-newsgroups
2404 (let ((case-fold-search t)
2405 (headers '("Newsgroups" "Followup-To"))
2407 (while (and headers (not error))
2408 (when (setq header (mail-fetch-field (car headers)))
2412 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
2417 (not (string-match "\\.\\'\\|\\.\\." g)))
2418 (message-tokenize-header header ","))))
2425 (format "The %s header looks odd: \"%s\". Really post? "
2426 (car headers) header)))))
2427 (message-check 'repeated-newsgroups
2428 (let ((case-fold-search t)
2429 (headers '("Newsgroups" "Followup-To"))
2430 header error groups group)
2433 (when (setq header (mail-fetch-field (pop headers)))
2434 (setq groups (message-tokenize-header header ","))
2435 (while (setq group (pop groups))
2436 (when (member group groups)
2442 (format "Group %s is repeated in headers. Really post? " error)))))
2443 ;; Check the From header.
2444 (message-check 'from
2445 (let* ((case-fold-search t)
2446 (from (message-fetch-field "from"))
2447 (ad (nth 1 (mail-extract-address-components from))))
2450 (message "There is no From line. Posting is denied.")
2452 ((or (not (string-match "@[^\\.]*\\." ad)) ;larsi@ifi
2453 (string-match "\\.\\." ad) ;larsi@ifi..uio
2454 (string-match "@\\." ad) ;larsi@.ifi.uio
2455 (string-match "\\.$" ad) ;larsi@ifi.uio.
2456 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
2457 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
2459 "Denied posting -- the From looks strange: \"%s\"." from)
2463 (defun message-check-news-body-syntax ()
2465 ;; Check for long lines.
2466 (message-check 'long-lines
2467 (goto-char (point-min))
2469 (concat "^" (regexp-quote mail-header-separator) "$"))
2473 (< (current-column) 80))
2474 (zerop (forward-line 1))))
2478 "You have lines longer than 79 characters. Really post? ")))
2479 ;; Check whether the article is empty.
2480 (message-check 'empty
2481 (goto-char (point-min))
2483 (concat "^" (regexp-quote mail-header-separator) "$"))
2486 (goto-char (point-max))
2487 (re-search-backward message-signature-separator nil t)
2489 (or (re-search-backward "[^ \n\t]" b t)
2490 (y-or-n-p "Empty article. Really post? "))))
2491 ;; Check for control characters.
2492 (message-check 'control-chars
2493 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
2495 "The article contains control characters. Really post? ")
2497 ;; Check excessive size.
2498 (message-check 'size
2499 (if (> (buffer-size) 60000)
2501 (format "The article is %d octets long. Really post? "
2504 ;; Check whether any new text has been added.
2505 (message-check 'new-text
2507 (not message-checksum)
2508 (not (eq (message-checksum) message-checksum))
2510 "It looks like no new text has been added. Really post? ")))
2511 ;; Check the length of the signature.
2512 (message-check 'signature
2513 (goto-char (point-max))
2514 (if (or (not (re-search-backward message-signature-separator nil t))
2515 (search-forward message-forward-end-separator nil t))
2517 (if (> (count-lines (point) (point-max)) 5)
2520 "Your .sig is %d lines; it should be max 4. Really post? "
2521 (1- (count-lines (point) (point-max)))))
2524 (defun message-checksum ()
2525 "Return a \"checksum\" for the current buffer."
2528 (goto-char (point-min))
2530 (concat "^" (regexp-quote mail-header-separator) "$"))
2532 (when (not (looking-at "[ \t\n]"))
2533 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
2538 (defun message-do-fcc ()
2539 "Process Fcc headers in the current buffer."
2540 (let ((case-fold-search t)
2541 (buf (current-buffer))
2544 (set-buffer (get-buffer-create " *message temp*"))
2545 (buffer-disable-undo (current-buffer))
2547 (insert-buffer-substring buf)
2549 (message-narrow-to-headers)
2550 (while (setq file (message-fetch-field "fcc"))
2552 (message-remove-header "fcc" nil t)))
2553 (goto-char (point-min))
2554 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
2555 (replace-match "" t t)
2556 ;; Process FCC operations.
2558 (setq file (pop list))
2559 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
2560 ;; Pipe the article to the program in question.
2561 (call-process-region (point-min) (point-max) shell-file-name
2562 nil nil nil shell-command-switch
2563 (match-string 1 file))
2564 ;; Save the article.
2565 (setq file (expand-file-name file))
2566 (unless (file-exists-p (file-name-directory file))
2567 (make-directory (file-name-directory file) t))
2568 (if (and message-fcc-handler-function
2569 (not (eq message-fcc-handler-function 'rmail-output)))
2570 (funcall message-fcc-handler-function file)
2571 (if (and (file-readable-p file) (mail-file-babyl-p file))
2572 (rmail-output file 1 nil t)
2573 (let ((mail-use-rfc822 t))
2574 (rmail-output file 1 t t))))))
2576 (kill-buffer (current-buffer)))))
2578 (defun message-output (filename)
2579 "Append this article to Unix/babyl mail file.."
2580 (if (and (file-readable-p filename)
2581 (mail-file-babyl-p filename))
2582 (rmail-output-to-rmail-file filename t)
2583 (gnus-output-to-mail filename t)))
2585 (defun message-cleanup-headers ()
2586 "Do various automatic cleanups of the headers."
2587 ;; Remove empty lines in the header.
2589 (message-narrow-to-headers)
2590 ;; Remove blank lines.
2591 (while (re-search-forward "^[ \t]*\n" nil t)
2592 (replace-match "" t t))
2594 ;; Correct Newsgroups and Followup-To headers: Change sequence of
2595 ;; spaces to comma and eliminate spaces around commas. Eliminate
2596 ;; embedded line breaks.
2597 (goto-char (point-min))
2598 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
2602 (if (re-search-forward "^[^ \t]" nil t)
2606 (goto-char (point-min))
2607 (while (re-search-forward "\n[ \t]+" nil t)
2608 (replace-match " " t t)) ;No line breaks (too confusing)
2609 (goto-char (point-min))
2610 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
2611 (replace-match "," t t))
2612 (goto-char (point-min))
2613 ;; Remove trailing commas.
2614 (when (re-search-forward ",+$" nil t)
2615 (replace-match "" t t))))))
2617 (defun message-make-date (&optional now)
2618 "Make a valid data header.
2619 If NOW, use that time instead."
2620 (let* ((now (or now (current-time)))
2621 (zone (nth 8 (decode-time now)))
2623 ;; We do all of this because XEmacs doesn't have the %z spec.
2624 (when (> (/ zone 3600) 12)
2626 zone (- zone (* 3600 12))))
2627 (concat (format-time-string "%d %b %Y %H:%M:%S " (or now (current-time)))
2628 (format "%s%02d%02d"
2632 (defun message-make-message-id ()
2633 "Make a unique Message-ID."
2634 (concat "<" (message-unique-id)
2635 (let ((psubject (save-excursion (message-fetch-field "subject")))
2637 (save-excursion (message-fetch-field "supersedes"))))
2639 (and message-reply-headers
2640 (mail-header-references message-reply-headers)
2641 (mail-header-subject message-reply-headers)
2643 (mail-header-subject message-reply-headers)
2645 (message-strip-subject-re
2646 (mail-header-subject message-reply-headers))
2647 (message-strip-subject-re psubject))))
2649 (string-match "_-_@" psupersedes)))
2651 "@" (message-make-fqdn) ">"))
2653 (defvar message-unique-id-char nil)
2655 ;; If you ever change this function, make sure the new version
2656 ;; cannot generate IDs that the old version could.
2657 ;; You might for example insert a "." somewhere (not next to another dot
2658 ;; or string boundary), or modify the "fsf" string.
2659 (defun message-unique-id ()
2660 ;; Don't use microseconds from (current-time), they may be unsupported.
2661 ;; Instead we use this randomly inited counter.
2662 (setq message-unique-id-char
2663 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
2664 ;; (current-time) returns 16-bit ints,
2665 ;; and 2^16*25 just fits into 4 digits i base 36.
2667 (let ((tm (current-time)))
2669 (if (memq system-type '(ms-dos emx vax-vms))
2670 (let ((user (downcase (user-login-name))))
2671 (while (string-match "[^a-z0-9_]" user)
2672 (aset user (match-beginning 0) ?_))
2674 (message-number-base36 (user-uid) -1))
2675 (message-number-base36 (+ (car tm)
2676 (lsh (% message-unique-id-char 25) 16)) 4)
2677 (message-number-base36 (+ (nth 1 tm)
2678 (lsh (/ message-unique-id-char 25) 16)) 4)
2679 ;; Append the newsreader name, because while the generated
2680 ;; ID is unique to this newsreader, other newsreaders might
2681 ;; otherwise generate the same ID via another algorithm.
2684 (defun message-number-base36 (num len)
2689 (concat (message-number-base36 (/ num 36) (1- len))
2690 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
2693 (defun message-make-organization ()
2694 "Make an Organization header."
2695 (let* ((organization
2696 (when message-user-organization
2697 (if (message-functionp message-user-organization)
2698 (funcall message-user-organization)
2699 message-user-organization))))
2701 (message-set-work-buffer)
2702 (cond ((stringp organization)
2703 (insert organization))
2704 ((and (eq t organization)
2705 message-user-organization-file
2706 (file-exists-p message-user-organization-file))
2707 (insert-file-contents message-user-organization-file)))
2708 (goto-char (point-min))
2709 (while (re-search-forward "[\t\n]+" nil t)
2710 (replace-match "" t t))
2711 (unless (zerop (buffer-size))
2714 (defun message-make-lines ()
2715 "Count the number of lines and return numeric string."
2719 (goto-char (point-min))
2721 (concat "^" (regexp-quote mail-header-separator) "$"))
2723 (int-to-string (count-lines (point) (point-max))))))
2725 (defun message-make-in-reply-to ()
2726 "Return the In-Reply-To header for this message."
2727 (when message-reply-headers
2728 (let ((from (mail-header-from message-reply-headers))
2729 (date (mail-header-date message-reply-headers)))
2732 (string-match " *at \\| *@ \\| *(\\| *<" from)))
2733 (concat (if (and stop-pos
2734 (not (zerop stop-pos)))
2735 (substring from 0 stop-pos) from)
2737 (if (or (not date) (string= date ""))
2738 "(unknown date)" date)
2741 (defun message-make-distribution ()
2742 "Make a Distribution header."
2743 (let ((orig-distribution (message-fetch-reply-field "distribution")))
2744 (cond ((message-functionp message-distribution-function)
2745 (funcall message-distribution-function))
2746 (t orig-distribution))))
2748 (defun message-make-expires ()
2749 "Return an Expires header based on `message-expires'."
2750 (let ((current (current-time))
2751 (future (* 1.0 message-expires 60 60 24)))
2752 ;; Add the future to current.
2753 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
2754 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
2755 (message-make-date current)))
2757 (defun message-make-path ()
2759 (let ((login-name (user-login-name)))
2760 (cond ((null message-user-path)
2761 (concat (system-name) "!" login-name))
2762 ((stringp message-user-path)
2763 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
2764 (concat message-user-path "!" login-name))
2767 (defun message-make-from ()
2768 "Make a From header."
2769 (let* ((style message-from-style)
2770 (login (message-make-address))
2772 (or (and (boundp 'user-full-name)
2775 (when (string= fullname "&")
2776 (setq fullname (user-login-name)))
2778 (message-set-work-buffer)
2781 (equal fullname ""))
2783 ((or (eq style 'angles)
2784 (and (not (eq style 'parens))
2785 ;; Use angles if no quoting is needed, or if parens would
2786 ;; need quoting too.
2787 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
2788 (let ((tmp (concat fullname nil)))
2789 (while (string-match "([^()]*)" tmp)
2790 (aset tmp (match-beginning 0) ?-)
2791 (aset tmp (1- (match-end 0)) ?-))
2792 (string-match "[\\()]" tmp)))))
2794 (goto-char (point-min))
2795 ;; Look for a character that cannot appear unquoted
2796 ;; according to RFC 822.
2797 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
2798 ;; Quote fullname, escaping specials.
2799 (goto-char (point-min))
2801 (while (re-search-forward "[\"\\]" nil 1)
2802 (replace-match "\\\\\\&" t))
2804 (insert " <" login ">"))
2805 (t ; 'parens or default
2807 (let ((fullname-start (point)))
2809 (goto-char fullname-start)
2810 ;; RFC 822 says \ and nonmatching parentheses
2811 ;; must be escaped in comments.
2812 ;; Escape every instance of ()\ ...
2813 (while (re-search-forward "[()\\]" nil 1)
2814 (replace-match "\\\\\\&" t))
2815 ;; ... then undo escaping of matching parentheses,
2816 ;; including matching nested parentheses.
2817 (goto-char fullname-start)
2818 (while (re-search-forward
2819 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
2821 (replace-match "\\1(\\3)" t)
2822 (goto-char fullname-start)))
2826 (defun message-make-sender ()
2827 "Return the \"real\" user address.
2828 This function tries to ignore all user modifications, and
2829 give as trustworthy answer as possible."
2830 (concat (user-login-name) "@" (system-name)))
2832 (defun message-make-address ()
2833 "Make the address of the user."
2834 (or (message-user-mail-address)
2835 (concat (user-login-name) "@" (message-make-domain))))
2837 (defun message-user-mail-address ()
2838 "Return the pertinent part of `user-mail-address'."
2839 (when user-mail-address
2840 (if (string-match " " user-mail-address)
2841 (nth 1 (mail-extract-address-components user-mail-address))
2842 user-mail-address)))
2844 (defun message-make-fqdn ()
2845 "Return user's fully qualified domain name."
2846 (let ((system-name (system-name))
2847 (user-mail (message-user-mail-address)))
2849 ((string-match "[^.]\\.[^.]" system-name)
2850 ;; `system-name' returned the right result.
2852 ;; Try `mail-host-address'.
2853 ((and (boundp 'mail-host-address)
2854 (stringp mail-host-address)
2855 (string-match "\\." mail-host-address))
2857 ;; We try `user-mail-address' as a backup.
2859 (string-match "\\." user-mail)
2860 (string-match "@\\(.*\\)\\'" user-mail))
2861 (match-string 1 user-mail))
2862 ;; Default to this bogus thing.
2864 (concat system-name ".i-did-not-set--mail-host-address--so-shoot-me")))))
2866 (defun message-make-host-name ()
2867 "Return the name of the host."
2868 (let ((fqdn (message-make-fqdn)))
2869 (string-match "^[^.]+\\." fqdn)
2870 (substring fqdn 0 (1- (match-end 0)))))
2872 (defun message-make-domain ()
2873 "Return the domain name."
2874 (or mail-host-address
2875 (message-make-fqdn)))
2877 (defun message-generate-headers (headers)
2878 "Prepare article HEADERS.
2879 Headers already prepared in the buffer are not modified."
2881 (message-narrow-to-headers)
2882 (let* ((Date (message-make-date))
2883 (Message-ID (message-make-message-id))
2884 (Organization (message-make-organization))
2885 (From (message-make-from))
2886 (Path (message-make-path))
2889 (In-Reply-To (message-make-in-reply-to))
2891 (Distribution (message-make-distribution))
2892 (Lines (message-make-lines))
2893 (User-Agent message-newsreader)
2894 (Expires (message-make-expires))
2895 (case-fold-search t)
2897 ;; First we remove any old generated headers.
2898 (let ((headers message-deletable-headers))
2899 (unless (buffer-modified-p)
2900 (setq headers (delq 'Message-ID (copy-sequence headers))))
2902 (goto-char (point-min))
2903 (and (re-search-forward
2904 (concat "^" (symbol-name (car headers)) ": *") nil t)
2905 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
2906 (message-delete-line))
2908 ;; Go through all the required headers and see if they are in the
2909 ;; articles already. If they are not, or are empty, they are
2910 ;; inserted automatically - except for Subject, Newsgroups and
2913 (goto-char (point-min))
2914 (setq elem (pop headers))
2916 (if (eq (car elem) 'optional)
2917 (setq header (cdr elem))
2918 (setq header (car elem)))
2920 (when (or (not (re-search-forward
2924 (if (stringp header)
2926 (symbol-name header))))
2930 ;; The header was found. We insert a space after the
2931 ;; colon, if there is none.
2932 (if (/= (following-char) ? ) (insert " ") (forward-char 1))
2933 ;; Find out whether the header is empty...
2934 (looking-at "[ \t]*$")))
2935 ;; So we find out what value we should insert.
2938 ((and (consp elem) (eq (car elem) 'optional))
2939 ;; This is an optional header. If the cdr of this
2940 ;; is something that is nil, then we do not insert
2942 (setq header (cdr elem))
2943 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
2944 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
2946 ;; The element is a cons. Either the cdr is a
2947 ;; string to be inserted verbatim, or it is a
2948 ;; function, and we insert the value returned from
2950 (or (and (stringp (cdr elem)) (cdr elem))
2951 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
2952 ((and (boundp header) (symbol-value header))
2953 ;; The element is a symbol. We insert the value
2954 ;; of this symbol, if any.
2955 (symbol-value header))
2957 ;; We couldn't generate a value for this header,
2958 ;; so we just ask the user.
2959 (read-from-minibuffer
2960 (format "Empty header for %s; enter value: " header)))))
2961 ;; Finally insert the header.
2963 (not (equal value "")))
2967 ;; This header didn't exist, so we insert it.
2968 (goto-char (point-max))
2969 (insert (if (stringp header) header (symbol-name header))
2972 ;; The value of this header was empty, so we clear
2973 ;; totally and insert the new value.
2974 (delete-region (point) (gnus-point-at-eol))
2976 ;; Add the deletable property to the headers that require it.
2977 (and (memq header message-deletable-headers)
2978 (progn (beginning-of-line) (looking-at "[^:]+: "))
2979 (add-text-properties
2980 (point) (match-end 0)
2981 '(message-deletable t face italic) (current-buffer)))))))
2982 ;; Insert new Sender if the From is strange.
2983 (let ((from (message-fetch-field "from"))
2984 (sender (message-fetch-field "sender"))
2985 (secure-sender (message-make-sender)))
2987 (not (message-check-element 'sender))
2990 (cadr (mail-extract-address-components from)))
2991 (downcase secure-sender)))
2996 (cadr (mail-extract-address-components sender)))
2997 (downcase secure-sender)))))
2998 (goto-char (point-min))
2999 ;; Rename any old Sender headers to Original-Sender.
3000 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
3002 (insert "Original-")
3003 (beginning-of-line))
3004 (when (or (message-news-p)
3005 (string-match "@.+\\.." secure-sender))
3006 (insert "Sender: " secure-sender "\n")))))))
3008 (defun message-insert-courtesy-copy ()
3009 "Insert a courtesy message in mail copies of combined messages."
3013 (message-narrow-to-headers)
3014 (when (setq newsgroups (message-fetch-field "newsgroups"))
3015 (goto-char (point-max))
3016 (insert "Posted-To: " newsgroups "\n")))
3018 (when message-courtesy-message
3020 ((string-match "%s" message-courtesy-message)
3021 (insert (format message-courtesy-message newsgroups)))
3023 (insert message-courtesy-message)))))))
3026 ;;; Setting up a message buffer
3029 (defun message-fill-address (header value)
3031 (narrow-to-region (point) (point))
3032 (insert (capitalize (symbol-name header))
3034 (if (consp value) (car value) value)
3036 (narrow-to-region (point-min) (1- (point-max)))
3038 (goto-char (point-min))
3040 (skip-chars-forward "^,\"" (point-max))
3041 (if (or (= (following-char) ?,)
3044 (if (and (> (current-column) 78)
3050 (setq last (1+ (point))))
3051 (setq last (1+ (point)))))
3052 (setq quoted (not quoted)))
3055 (goto-char (point-max))
3059 (defun message-fill-header (header value)
3060 (let ((begin (point))
3063 (insert (capitalize (symbol-name header))
3065 (if (consp value) (car value) value)
3068 (narrow-to-region begin (point))
3069 (fill-region-as-paragraph begin (point))
3070 ;; Tapdance around looong Message-IDs.
3072 (when (looking-at "[ \t]*$")
3073 (message-delete-line))
3075 (re-search-forward ":" nil t)
3076 (when (looking-at "\n[ \t]+")
3077 (replace-match " " t t))
3078 (goto-char (point-max)))))
3080 (defun message-shorten-references (header references)
3081 "Limit REFERENCES to be shorter than 988 characters."
3087 (goto-char (point-min))
3088 (while (re-search-forward "<[^>]+>" nil t)
3089 (push (match-string 0) refs))
3090 (setq refs (nreverse refs))
3091 (while (> (length (mapconcat 'identity refs " ")) max)
3092 (when (< (length refs) (1+ cut))
3094 (setcdr (nthcdr cut refs) (cddr (nthcdr cut refs)))))
3095 (insert (capitalize (symbol-name header)) ": "
3096 (mapconcat 'identity refs " ") "\n")))
3098 (defun message-position-point ()
3099 "Move point to where the user probably wants to find it."
3100 (message-narrow-to-headers)
3102 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
3103 (search-backward ":" )
3106 (if (= (following-char) ? )
3110 (goto-char (point-max))
3113 (unless (looking-at "$")
3117 (defun message-buffer-name (type &optional to group)
3118 "Return a new (unique) buffer name based on TYPE and TO."
3120 ;; Check whether `message-generate-new-buffers' is a function,
3121 ;; and if so, call it.
3122 ((message-functionp message-generate-new-buffers)
3123 (funcall message-generate-new-buffers type to group))
3124 ;; Generate a new buffer name The Message Way.
3125 (message-generate-new-buffers
3126 (generate-new-buffer-name
3130 (or (car (mail-extract-address-components to))
3133 (if (and group (not (string= group ""))) (concat " on " group) "")
3135 ;; Use standard name.
3137 (format "*%s message*" type))))
3139 (defun message-pop-to-buffer (name)
3140 "Pop to buffer NAME, and warn if it already exists and is modified."
3141 (let ((buffer (get-buffer name)))
3143 (buffer-name buffer))
3145 (set-buffer (pop-to-buffer buffer))
3146 (when (and (buffer-modified-p)
3148 "Message already being composed; erase? ")))
3149 (error "Message being composed")))
3150 (set-buffer (pop-to-buffer name)))
3154 (defun message-do-send-housekeeping ()
3155 "Kill old message buffers."
3156 ;; We might have sent this buffer already. Delete it from the
3158 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
3159 (while (and message-max-buffers
3161 (>= (length message-buffer-list) message-max-buffers))
3162 ;; Kill the oldest buffer -- unless it has been changed.
3163 (let ((buffer (pop message-buffer-list)))
3164 (when (and (buffer-name buffer)
3165 (not (buffer-modified-p buffer)))
3166 (kill-buffer buffer))))
3167 ;; Rename the buffer.
3168 (if message-send-rename-function
3169 (funcall message-send-rename-function)
3170 (when (string-match "\\`\\*" (buffer-name))
3172 (concat "*sent " (substring (buffer-name) (match-end 0))) t)))
3173 ;; Push the current buffer onto the list.
3174 (when message-max-buffers
3175 (setq message-buffer-list
3176 (nconc message-buffer-list (list (current-buffer))))))
3178 (defvar mc-modes-alist)
3179 (defun message-setup (headers &optional replybuffer actions)
3180 (when (and (boundp 'mc-modes-alist)
3181 (not (assq 'message-mode mc-modes-alist)))
3182 (push '(message-mode (encrypt . mc-encrypt-message)
3183 (sign . mc-sign-message))
3186 (setq message-send-actions actions))
3187 (setq message-reply-buffer replybuffer)
3188 (goto-char (point-min))
3189 ;; Insert all the headers.
3192 (alist message-header-format-alist))
3194 (unless (assq (caar h) message-header-format-alist)
3195 (push (list (caar h)) alist))
3199 (delete-region (point) (progn (forward-line -1) (point)))
3200 (when message-default-headers
3201 (insert message-default-headers)
3202 (or (bolp) (insert ?\n)))
3206 (insert mail-header-separator "\n")
3210 (when (message-news-p)
3211 (when message-default-news-headers
3212 (insert message-default-news-headers)
3213 (or (bolp) (insert ?\n)))
3214 (when message-generate-headers-first
3215 (message-generate-headers
3218 (copy-sequence message-required-news-headers))))))
3219 (when (message-mail-p)
3220 (when message-default-mail-headers
3221 (insert message-default-mail-headers)
3222 (or (bolp) (insert ?\n)))
3223 (when message-generate-headers-first
3224 (message-generate-headers
3227 (copy-sequence message-required-mail-headers))))))
3228 (run-hooks 'message-signature-setup-hook)
3229 (message-insert-signature)
3231 (message-narrow-to-headers)
3232 (run-hooks 'message-header-setup-hook))
3233 (set-buffer-modified-p nil)
3234 (setq buffer-undo-list nil)
3235 (run-hooks 'message-setup-hook)
3236 (message-position-point)
3239 (defun message-set-auto-save-file-name ()
3240 "Associate the message buffer with a file in the drafts directory."
3241 (when message-autosave-directory
3243 (setq message-draft-article
3244 (nndraft-request-associate-buffer "drafts"))
3245 (setq buffer-file-name (expand-file-name "*message*"
3246 message-autosave-directory))
3247 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
3248 (clear-visited-file-modtime)))
3250 (defun message-disassociate-draft ()
3251 "Disassociate the message buffer from the drafts directory."
3252 (when message-draft-article
3253 (nndraft-request-expire-articles
3254 (list message-draft-article) "drafts" nil t)))
3259 ;;; Commands for interfacing with message
3263 (defun message-mail (&optional to subject
3264 other-headers continue switch-function
3265 yank-action send-actions)
3266 "Start editing a mail message to be sent.
3267 OTHER-HEADERS is an alist of header/value pairs."
3269 (let ((message-this-is-mail t))
3270 (message-pop-to-buffer (message-buffer-name "mail" to))
3273 `((To . ,(or to "")) (Subject . ,(or subject "")))
3274 (when other-headers other-headers)))))
3277 (defun message-news (&optional newsgroups subject)
3278 "Start editing a news article to be sent."
3280 (let ((message-this-is-news t))
3281 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))
3282 (message-setup `((Newsgroups . ,(or newsgroups ""))
3283 (Subject . ,(or subject ""))))))
3286 (defun message-reply (&optional to-address wide)
3287 "Start editing a reply to the article in the current buffer."
3289 (let ((cur (current-buffer))
3290 from subject date reply-to to cc
3291 references message-id follow-to
3292 (inhibit-point-motion-hooks t)
3293 mct never-mct gnus-warning)
3295 (message-narrow-to-head)
3296 ;; Allow customizations to have their say.
3298 ;; This is a regular reply.
3299 (if (message-functionp message-reply-to-function)
3300 (setq follow-to (funcall message-reply-to-function)))
3301 ;; This is a followup.
3302 (if (message-functionp message-wide-reply-to-function)
3305 (funcall message-wide-reply-to-function)))))
3306 ;; Find all relevant headers we need.
3307 (setq from (message-fetch-field "from")
3308 date (message-fetch-field "date")
3309 subject (or (message-fetch-field "subject") "none")
3310 to (message-fetch-field "to")
3311 cc (message-fetch-field "cc")
3312 mct (message-fetch-field "mail-copies-to")
3313 reply-to (message-fetch-field "reply-to")
3314 references (message-fetch-field "references")
3315 message-id (message-fetch-field "message-id" t))
3316 ;; Remove any (buggy) Re:'s that are present and make a
3318 (when (string-match message-subject-re-regexp subject)
3319 (setq subject (substring subject (match-end 0))))
3320 (setq subject (concat "Re: " subject))
3322 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
3323 (string-match "<[^>]+>" gnus-warning))
3324 (setq message-id (match-string 0 gnus-warning)))
3326 ;; Handle special values of Mail-Copies-To.
3328 (cond ((equal (downcase mct) "never")
3331 ((equal (downcase mct) "always")
3332 (setq mct (or reply-to from)))))
3338 (setq follow-to (list (cons 'To (or to-address reply-to from))))
3339 (when (and wide mct)
3340 (push (cons 'Cc mct) follow-to)))
3343 (message-set-work-buffer)
3345 (insert (or reply-to from "")))
3346 (insert (if to (concat (if (bolp) "" ", ") to "") ""))
3347 (insert (if mct (concat (if (bolp) "" ", ") mct) ""))
3348 (insert (if cc (concat (if (bolp) "" ", ") cc) ""))
3349 (goto-char (point-min))
3350 (while (re-search-forward "[ \t]+" nil t)
3351 (replace-match " " t t))
3352 ;; Remove addresses that match `rmail-dont-reply-to-names'.
3353 (insert (prog1 (rmail-dont-reply-to (buffer-string))
3355 (goto-char (point-min))
3356 ;; Perhaps Mail-Copies-To: never removed the only address?
3358 (insert (or reply-to from "")))
3362 (cons (mail-strip-quoted-names addr) addr))
3363 (message-tokenize-header (buffer-string))))
3366 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
3367 (setq follow-to (list (cons 'To (cdr (pop ccalist)))))
3369 (let ((ccs (cons 'Cc (mapconcat
3370 (lambda (addr) (cdr addr)) ccalist ", "))))
3371 (when (string-match "^ +" (cdr ccs))
3372 (setcdr ccs (substring (cdr ccs) (match-end 0))))
3373 (push ccs follow-to))))))
3376 (message-pop-to-buffer (message-buffer-name
3377 (if wide "wide reply" "reply") from
3378 (if wide to-address nil)))
3380 (setq message-reply-headers
3381 (vector 0 subject from date message-id references 0 0 ""))
3384 `((Subject . ,subject)
3386 ,@(if (or references message-id)
3387 `((References . ,(concat (or references "") (and references " ")
3388 (or message-id ""))))
3393 (defun message-wide-reply (&optional to-address)
3394 "Make a \"wide\" reply to the message in the current buffer."
3396 (message-reply to-address t))
3399 (defun message-followup (&optional to-newsgroups)
3400 "Follow up to the message in the current buffer.
3401 If TO-NEWSGROUPS, use that as the new Newsgroups line."
3403 (let ((cur (current-buffer))
3404 from subject date reply-to mct
3405 references message-id follow-to
3406 (inhibit-point-motion-hooks t)
3407 (message-this-is-news t)
3408 followup-to distribution newsgroups gnus-warning posted-to)
3411 (goto-char (point-min))
3412 (if (search-forward "\n\n" nil t)
3415 (when (message-functionp message-followup-to-function)
3417 (funcall message-followup-to-function)))
3418 (setq from (message-fetch-field "from")
3419 date (message-fetch-field "date")
3420 subject (or (message-fetch-field "subject") "none")
3421 references (message-fetch-field "references")
3422 message-id (message-fetch-field "message-id" t)
3423 followup-to (message-fetch-field "followup-to")
3424 newsgroups (message-fetch-field "newsgroups")
3425 posted-to (message-fetch-field "posted-to")
3426 reply-to (message-fetch-field "reply-to")
3427 distribution (message-fetch-field "distribution")
3428 mct (message-fetch-field "mail-copies-to"))
3429 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
3430 (string-match "<[^>]+>" gnus-warning))
3431 (setq message-id (match-string 0 gnus-warning)))
3432 ;; Remove bogus distribution.
3433 (when (and (stringp distribution)
3434 (let ((case-fold-search t))
3435 (string-match "world" distribution)))
3436 (setq distribution nil))
3437 ;; Remove any (buggy) Re:'s that are present and make a
3439 (when (string-match message-subject-re-regexp subject)
3440 (setq subject (substring subject (match-end 0))))
3441 (setq subject (concat "Re: " subject))
3444 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
3447 `((Subject . ,subject)
3450 (list (cons 'Newsgroups to-newsgroups)))
3451 (follow-to follow-to)
3452 ((and followup-to message-use-followup-to)
3455 ((equal (downcase followup-to) "poster")
3456 (if (or (eq message-use-followup-to 'use)
3457 (message-y-or-n-p "Obey Followup-To: poster? " t "\
3458 You should normally obey the Followup-To: header.
3460 `Followup-To: poster' sends your response via e-mail instead of news.
3462 A typical situation where `Followup-To: poster' is used is when the poster
3463 does not read the newsgroup, so he wouldn't see any replies sent to it."))
3465 (setq message-this-is-news nil)
3466 (cons 'To (or reply-to from "")))
3467 (cons 'Newsgroups newsgroups)))
3469 (if (or (equal followup-to newsgroups)
3470 (not (eq message-use-followup-to 'ask))
3472 (concat "Obey Followup-To: " followup-to "? ") t "\
3473 You should normally obey the Followup-To: header.
3475 `Followup-To: " followup-to "'
3476 directs your response to " (if (string-match "," followup-to)
3477 "the specified newsgroups"
3478 "that newsgroup only") ".
3480 If a message is posted to several newsgroups, Followup-To is often
3481 used to direct the following discussion to one newsgroup only,
3482 because discussions that are spread over several newsgroup tend to
3483 be fragmented and very difficult to follow.
3485 Also, some source/announcement newsgroups are not indented for discussion;
3486 responses here are directed to other newsgroups."))
3487 (cons 'Newsgroups followup-to)
3488 (cons 'Newsgroups newsgroups))))))
3490 `((Newsgroups . ,posted-to)))
3492 `((Newsgroups . ,newsgroups))))
3493 ,@(and distribution (list (cons 'Distribution distribution)))
3494 ,@(if (or references message-id)
3495 `((References . ,(concat (or references "") (and references " ")
3496 (or message-id "")))))
3498 (not (equal (downcase mct) "never")))
3499 (list (cons 'Cc (if (equal (downcase mct) "always")
3500 (or reply-to from "")
3505 (setq message-reply-headers
3506 (vector 0 subject from date message-id references 0 0 ""))))
3510 (defun message-cancel-news ()
3511 "Cancel an article you posted."
3513 (unless (message-news-p)
3514 (error "This is not a news article; canceling is impossible"))
3515 (when (yes-or-no-p "Do you really want to cancel this article? ")
3516 (let (from newsgroups message-id distribution buf sender)
3518 ;; Get header info. from original article.
3520 (message-narrow-to-head)
3521 (setq from (message-fetch-field "from")
3522 sender (message-fetch-field "sender")
3523 newsgroups (message-fetch-field "newsgroups")
3524 message-id (message-fetch-field "message-id" t)
3525 distribution (message-fetch-field "distribution")))
3526 ;; Make sure that this article was written by the user.
3527 (unless (or (and sender
3530 (downcase (message-make-sender))))
3532 (downcase (cadr (mail-extract-address-components from)))
3533 (downcase (cadr (mail-extract-address-components
3534 (message-make-from))))))
3535 (error "This article is not yours"))
3536 ;; Make control message.
3537 (setq buf (set-buffer (get-buffer-create " *message cancel*")))
3538 (buffer-disable-undo (current-buffer))
3540 (insert "Newsgroups: " newsgroups "\n"
3541 "From: " (message-make-from) "\n"
3542 "Subject: cmsg cancel " message-id "\n"
3543 "Control: cancel " message-id "\n"
3545 (concat "Distribution: " distribution "\n")
3547 mail-header-separator "\n"
3548 message-cancel-message)
3549 (message "Canceling your article...")
3550 (if (let ((message-syntax-checks
3551 'dont-check-for-anything-just-trust-me))
3552 (funcall message-send-news-function))
3553 (message "Canceling your article...done"))
3554 (kill-buffer buf)))))
3557 (defun message-supersede ()
3558 "Start composing a message to supersede the current message.
3559 This is done simply by taking the old article and adding a Supersedes
3560 header line with the old Message-ID."
3562 (let ((cur (current-buffer))
3563 (sender (message-fetch-field "sender"))
3564 (from (message-fetch-field "from")))
3565 ;; Check whether the user owns the article that is to be superseded.
3566 (unless (or (and sender
3569 (downcase (message-make-sender))))
3571 (downcase (cadr (mail-extract-address-components from)))
3572 (downcase (cadr (mail-extract-address-components
3573 (message-make-from))))))
3574 (error "This article is not yours"))
3575 ;; Get a normal message buffer.
3576 (message-pop-to-buffer (message-buffer-name "supersede"))
3577 (insert-buffer-substring cur)
3578 (message-narrow-to-head)
3579 ;; Remove unwanted headers.
3580 (when message-ignored-supersedes-headers
3581 (message-remove-header message-ignored-supersedes-headers t))
3582 (goto-char (point-min))
3583 (if (not (re-search-forward "^Message-ID: " nil t))
3584 (error "No Message-ID in this article")
3585 (replace-match "Supersedes: " t t))
3586 (goto-char (point-max))
3587 (insert mail-header-separator)
3592 (defun message-recover ()
3593 "Reread contents of current buffer from its last auto-save file."
3595 (let ((file-name (make-auto-save-file-name)))
3596 (cond ((save-window-excursion
3597 (if (not (eq system-type 'vax-vms))
3598 (with-output-to-temp-buffer "*Directory*"
3599 (buffer-disable-undo standard-output)
3600 (let ((default-directory "/"))
3602 "ls" nil standard-output nil "-l" file-name))))
3603 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
3604 (let ((buffer-read-only nil))
3606 (insert-file-contents file-name nil)))
3607 (t (error "message-recover cancelled")))))
3609 ;;; Washing Subject:
3611 (defun message-wash-subject (subject)
3612 "Remove junk like \"Re:\", \"(fwd)\", etc. that was added to the subject by previous forwarders, replyers, etc."
3614 (insert-string subject)
3615 (goto-char (point-min))
3616 ;; strip Re/Fwd stuff off the beginning
3617 (while (re-search-forward
3618 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
3621 ;; and gnus-style forwards [foo@bar.com] subject
3622 (goto-char (point-min))
3623 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
3627 (goto-char (point-max))
3628 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
3631 ;; and finally, any whitespace that was left-over
3632 (goto-char (point-min))
3633 (while (re-search-forward "^[ \t]+" nil t)
3635 (goto-char (point-max))
3636 (while (re-search-backward "[ \t]+$" nil t)
3641 ;;; Forwarding messages.
3643 (defun message-forward-subject-author-subject (subject)
3644 "Generate a subject for a forwarded message.
3645 The form is: [Source] Subject, where if the original message was mail,
3646 Source is the sender, and if the original message was news, Source is
3647 the list of newsgroups is was posted to."
3649 (or (message-fetch-field
3650 (if (message-news-p) "newsgroups" "from"))
3654 (defun message-forward-subject-fwd (subject)
3655 "Generate a subject for a forwarded message.
3656 The form is: Fwd: Subject, where Subject is the original subject of
3658 (concat "Fwd: " subject))
3660 (defun message-make-forward-subject ()
3661 "Return a Subject header suitable for the message in the current buffer."
3665 (message-narrow-to-head)
3666 (let ((funcs message-make-forward-subject-function)
3667 (subject (if message-wash-forwarded-subjects
3668 (message-wash-subject
3669 (or (message-fetch-field "Subject") ""))
3670 (or (message-fetch-field "Subject") ""))))
3671 ;; Make sure funcs is a list.
3674 (setq funcs (list funcs)))
3675 ;; Apply funcs in order, passing subject generated by previous
3676 ;; func to the next one.
3678 (when (message-functionp (car funcs))
3679 (setq subject (funcall (car funcs) subject)))
3680 (setq funcs (cdr funcs)))
3684 (defun message-forward (&optional news)
3685 "Forward the current message via mail.
3686 Optional NEWS will use news to forward instead of mail."
3688 (let ((cur (current-buffer))
3689 (subject (message-make-forward-subject))
3691 (if news (message-news nil subject) (message-mail nil subject))
3692 ;; Put point where we want it before inserting the forwarded
3694 (if message-signature-before-forwarded-message
3695 (goto-char (point-max))
3696 (message-goto-body))
3697 ;; Make sure we're at the start of the line.
3700 ;; Narrow to the area we are to insert.
3701 (narrow-to-region (point) (point))
3702 ;; Insert the separators and the forwarded buffer.
3703 (insert message-forward-start-separator)
3704 (setq art-beg (point))
3705 (insert-buffer-substring cur)
3706 (goto-char (point-max))
3707 (insert message-forward-end-separator)
3708 (set-text-properties (point-min) (point-max) nil)
3709 ;; Remove all unwanted headers.
3711 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
3714 (goto-char (point-min))
3715 (message-remove-header message-included-forward-headers t nil t)
3717 (message-position-point)))
3720 (defun message-resend (address)
3721 "Resend the current article to ADDRESS."
3722 (interactive "sResend message to: ")
3723 (message "Resending message to %s..." address)
3725 (let ((cur (current-buffer))
3727 ;; We first set up a normal mail buffer.
3728 (set-buffer (get-buffer-create " *message resend*"))
3729 (buffer-disable-undo (current-buffer))
3731 (message-setup `((To . ,address)))
3732 ;; Insert our usual headers.
3733 (message-generate-headers '(From Date To))
3734 (message-narrow-to-headers)
3735 ;; Rename them all to "Resent-*".
3736 (while (re-search-forward "^[A-Za-z]" nil t)
3741 (delete-region (point) (point-max))
3743 ;; Insert the message to be resent.
3744 (insert-buffer-substring cur)
3745 (goto-char (point-min))
3746 (search-forward "\n\n")
3749 (narrow-to-region beg (point))
3750 (message-remove-header message-ignored-resent-headers t)
3751 (goto-char (point-max)))
3752 (insert mail-header-separator)
3753 ;; Rename all old ("Also-")Resent headers.
3754 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
3757 ;; Quote any "From " lines at the beginning.
3759 (when (looking-at "From ")
3760 (replace-match "X-From-Line: "))
3763 (kill-buffer (current-buffer)))
3764 (message "Resending message to %s...done" address)))
3767 (defun message-bounce ()
3768 "Re-mail the current message.
3769 This only makes sense if the current message is a bounce message than
3770 contains some mail you have written which has been bounced back to
3773 (let ((cur (current-buffer))
3775 (message-pop-to-buffer (message-buffer-name "bounce"))
3776 (insert-buffer-substring cur)
3778 (message-narrow-to-head)
3779 (if (and (message-fetch-field "Mime-Version")
3780 (setq boundary (message-fetch-field "Content-Type")))
3781 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary)
3782 (setq boundary (concat (match-string 1 boundary) " *\n"
3783 "Content-Type: message/rfc822"))
3784 (setq boundary nil)))
3786 (goto-char (point-min))
3787 (search-forward "\n\n" nil t)
3789 (re-search-forward boundary nil t)
3791 (and (re-search-forward message-unsent-separator nil t)
3793 (re-search-forward "^Return-Path:.*\n" nil t))
3794 ;; We remove everything before the bounced mail.
3797 (if (re-search-forward "^[^ \n\t]+:" nil t)
3801 (message-narrow-to-head)
3802 (message-remove-header message-ignored-bounced-headers t)
3803 (goto-char (point-max))
3804 (insert mail-header-separator))
3805 (message-position-point)))
3808 ;;; Interactive entry points for new message buffers.
3812 (defun message-mail-other-window (&optional to subject)
3813 "Like `message-mail' command, but display mail buffer in another window."
3815 (let ((pop-up-windows t)
3816 (special-display-buffer-names nil)
3817 (special-display-regexps nil)
3818 (same-window-buffer-names nil)
3819 (same-window-regexps nil))
3820 (message-pop-to-buffer (message-buffer-name "mail" to)))
3821 (let ((message-this-is-mail t))
3822 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
3825 (defun message-mail-other-frame (&optional to subject)
3826 "Like `message-mail' command, but display mail buffer in another frame."
3828 (let ((pop-up-frames t)
3829 (special-display-buffer-names nil)
3830 (special-display-regexps nil)
3831 (same-window-buffer-names nil)
3832 (same-window-regexps nil))
3833 (message-pop-to-buffer (message-buffer-name "mail" to)))
3834 (let ((message-this-is-mail t))
3835 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
3838 (defun message-news-other-window (&optional newsgroups subject)
3839 "Start editing a news article to be sent."
3841 (let ((pop-up-windows t)
3842 (special-display-buffer-names nil)
3843 (special-display-regexps nil)
3844 (same-window-buffer-names nil)
3845 (same-window-regexps nil))
3846 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
3847 (let ((message-this-is-news t))
3848 (message-setup `((Newsgroups . ,(or newsgroups ""))
3849 (Subject . ,(or subject ""))))))
3852 (defun message-news-other-frame (&optional newsgroups subject)
3853 "Start editing a news article to be sent."
3855 (let ((pop-up-frames t)
3856 (special-display-buffer-names nil)
3857 (special-display-regexps nil)
3858 (same-window-buffer-names nil)
3859 (same-window-regexps nil))
3860 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
3861 (let ((message-this-is-news t))
3862 (message-setup `((Newsgroups . ,(or newsgroups ""))
3863 (Subject . ,(or subject ""))))))
3867 ;; This code should be moved to underline.el (from which it is stolen).
3870 (defun bold-region (start end)
3871 "Bold all nonblank characters in the region.
3872 Works by overstriking characters.
3873 Called from program, takes two arguments START and END
3874 which specify the range to operate on."
3877 (let ((end1 (make-marker)))
3878 (move-marker end1 (max start end))
3879 (goto-char (min start end))
3880 (while (< (point) end1)
3881 (or (looking-at "[_\^@- ]")
3882 (insert (following-char) "\b"))
3883 (forward-char 1)))))
3886 (defun unbold-region (start end)
3887 "Remove all boldness (overstruck characters) in the region.
3888 Called from program, takes two arguments START and END
3889 which specify the range to operate on."
3892 (let ((end1 (make-marker)))
3893 (move-marker end1 (max start end))
3894 (goto-char (min start end))
3895 (while (re-search-forward "\b" end1 t)
3896 (if (eq (following-char) (char-after (- (point) 2)))
3897 (delete-char -2))))))
3899 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
3901 ;; Support for toolbar
3902 (when (string-match "XEmacs\\|Lucid" emacs-version)
3903 (require 'messagexmas))
3905 ;;; Group name completion.
3907 (defvar message-newgroups-header-regexp
3908 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
3909 "Regexp that match headers that lists groups.")
3911 (defun message-tab ()
3912 "Expand group names in Newsgroups and Followup-To headers.
3913 Do a `tab-to-tab-stop' if not in those headers."
3915 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp))
3916 (mail-abbrev-in-expansion-header-p))
3917 (message-expand-group)
3920 (defvar gnus-active-hashtb)
3921 (defun message-expand-group ()
3922 "Expand the group name under point."
3923 (let* ((b (save-excursion
3928 (skip-chars-forward "^:")
3931 (skip-chars-backward "^, \t\n") (point))))
3932 (completion-ignore-case t)
3933 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
3935 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
3936 (completions (all-completions string hashtb))
3938 (delete-region b (point))
3940 ((= (length completions) 1)
3941 (if (string= (car completions) string)
3944 (message "Only matching group"))
3945 (insert (car completions))))
3946 ((and (setq comp (try-completion string hashtb))
3947 (not (string= comp string)))
3952 (message "No matching groups")
3953 (save-selected-window
3954 (pop-to-buffer "*Completions*")
3955 (buffer-disable-undo (current-buffer))
3956 (let ((buffer-read-only nil))
3958 (let ((standard-output (current-buffer)))
3959 (display-completion-list (sort completions 'string<)))
3960 (goto-char (point-min))
3961 (delete-region (point) (progn (forward-line 3) (point))))))))))
3965 (defun message-talkative-question (ask question show &rest text)
3966 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
3967 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
3968 The following arguments may contain lists of values."
3970 (setq text (message-flatten-list text)))
3971 (save-window-excursion
3973 (with-output-to-temp-buffer " *MESSAGE information message*"
3974 (set-buffer " *MESSAGE information message*")
3975 (mapcar 'princ text)
3976 (goto-char (point-min))))
3977 (funcall ask question))
3978 (funcall ask question)))
3980 (defun message-flatten-list (list)
3981 "Return a new, flat list that contains all elements of LIST.
3983 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
3986 (apply 'append (mapcar 'message-flatten-list list)))
3990 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
3991 "Create and return a buffer with a name based on NAME using generate-new-buffer.
3992 Then clone the local variables and values from the old buffer to the
3993 new one, cloning only the locals having a substring matching the
3995 (let ((oldbuf (current-buffer)))
3997 (set-buffer (generate-new-buffer name))
3998 (message-clone-locals oldbuf)
4001 (defun message-clone-locals (buffer)
4002 "Clone the local variables from BUFFER to the current buffer."
4003 (let ((locals (save-excursion
4005 (buffer-local-variables)))
4006 (regexp "^gnus\\|^nn\\|^message"))
4009 (when (and (consp local)
4011 (string-match regexp (symbol-name (car local))))
4013 (set (make-local-variable (car local))
4017 ;;; Miscellaneous functions
4019 ;; stolen (and renamed) from nnheader.el
4020 (defun message-replace-chars-in-string (string from to)
4021 "Replace characters in STRING from FROM to TO."
4022 (let ((string (substring string 0)) ;Copy string.
4023 (len (length string))
4025 ;; Replace all occurrences of FROM with TO.
4027 (when (= (aref string idx) from)
4028 (aset string idx to))
4029 (setq idx (1+ idx)))
4036 (defun message-encode-message-body ()
4037 "Examine the message body, encode it, and add the requisite headers."
4038 (when (featurep 'mule)
4041 (message-narrow-to-headers)
4042 (message-remove-header
4043 "^Content-Transfer-Encoding:\\|^Content-Type:\\|^Mime-Version:" t)
4044 (goto-char (point-max))
4046 (narrow-to-region (point) (point-max))
4047 (let* ((charset (mm-encode-body))
4048 (encoding (mm-body-encoding)))
4049 (when (consp charset)
4050 (error "Can't encode messages with multiple charsets (yet)"))
4052 (message-narrow-to-headers)
4053 (goto-char (point-max))
4054 (setq charset (or charset (mm-mule-charset-to-mime-charset 'ascii)))
4055 ;; We don't insert MIME headers if they only say the default.
4056 (unless (and (eq charset 'ascii)
4057 (eq encoding '7bit))
4058 (mm-insert-rfc822-headers charset encoding))
4059 (mm-encode-body))))))
4061 (run-hooks 'message-load-hook)
4065 ;;; message.el ends here