1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996,97 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
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))
39 (if (string-match "XEmacs\\|Lucid" emacs-version)
40 (require 'mail-abbrevs)
41 (require 'mailabbrev))
43 (defgroup message '((user-mail-address custom-variable)
44 (user-full-name custom-variable))
45 "Mail and news message composing."
46 :link '(custom-manual "(message)Top")
50 (put 'user-mail-address 'custom-type 'string)
51 (put 'user-full-name 'custom-type 'string)
53 (defgroup message-various nil
54 "Various Message Variables"
55 :link '(custom-manual "(message)Various Message Variables")
58 (defgroup message-buffers nil
60 :link '(custom-manual "(message)Message Buffers")
63 (defgroup message-sending nil
65 :link '(custom-manual "(message)Sending Variables")
68 (defgroup message-interface nil
70 :link '(custom-manual "(message)Interface")
73 (defgroup message-forwarding nil
75 :link '(custom-manual "(message)Forwarding")
76 :group 'message-interface)
78 (defgroup message-insertion nil
80 :link '(custom-manual "(message)Insertion")
83 (defgroup message-headers nil
85 :link '(custom-manual "(message)Message Headers")
88 (defgroup message-news nil
89 "Composing News Messages"
92 (defgroup message-mail nil
93 "Composing Mail Messages"
96 (defgroup message-faces nil
97 "Faces used for message composing."
101 (defcustom message-directory "~/Mail/"
102 "*Directory from which all other mail file variables are derived."
103 :group 'message-various
106 (defcustom message-max-buffers 10
107 "*How many buffers to keep before starting to kill them off."
108 :group 'message-buffers
111 (defcustom message-send-rename-function nil
112 "Function called to rename the buffer after sending it."
113 :group 'message-buffers
116 (defcustom message-fcc-handler-function 'message-output
117 "*A function called to save outgoing articles.
118 This function will be called with the name of the file to store the
119 article in. The default function is `message-output' which saves in Unix
121 :type '(radio (function-item message-output)
122 (function :tag "Other"))
123 :group 'message-sending)
125 (defcustom message-courtesy-message
126 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
127 "*This is inserted at the start of a mailed copy of a posted message.
128 If the string contains the format spec \"%s\", the Newsgroups
129 the article has been posted to will be inserted there.
130 If this variable is nil, no such courtesy message will be added."
131 :group 'message-sending
134 (defcustom message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):"
135 "*Regexp that matches headers to be removed in resent bounced mail."
136 :group 'message-interface
140 (defcustom message-from-style 'default
141 "*Specifies how \"From\" headers look.
143 If `nil', they contain just the return address like:
145 If `parens', they look like:
146 king@grassland.com (Elvis Parsley)
147 If `angles', they look like:
148 Elvis Parsley <king@grassland.com>
150 Otherwise, most addresses look like `angles', but they look like
151 `parens' if `angles' would need quoting and `parens' would not."
152 :type '(choice (const :tag "simple" nil)
156 :group 'message-headers)
158 (defcustom message-syntax-checks nil
159 ;; Guess this one shouldn't be easy to customize...
160 "Controls what syntax checks should not be performed on outgoing posts.
161 To disable checking of long signatures, for instance, add
162 `(signature . disabled)' to this list.
164 Don't touch this variable unless you really know what you're doing.
166 Checks include subject-cmsg multiple-headers sendsys message-id from
167 long-lines control-chars size new-text redirected-followup signature
168 approved sender empty empty-headers message-id from subject
169 shorten-followup-to existing-newsgroups buffer-file-name unchanged."
170 :group 'message-news)
172 (defcustom message-required-news-headers
173 '(From Newsgroups Subject Date Message-ID
174 (optional . Organization) Lines
175 (optional . X-Newsreader))
176 "Headers to be generated or prompted for when posting an article.
177 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
178 Message-ID. Organization, Lines, In-Reply-To, Expires, and
179 X-Newsreader are optional. If don't you want message to insert some
180 header, remove it from this list."
182 :group 'message-headers
183 :type '(repeat sexp))
185 (defcustom message-required-mail-headers
186 '(From Subject Date (optional . In-Reply-To) Message-ID Lines
187 (optional . X-Mailer))
188 "Headers to be generated or prompted for when mailing a message.
189 RFC822 required that From, Date, To, Subject and Message-ID be
190 included. Organization, Lines and X-Mailer are optional."
192 :group 'message-headers
193 :type '(repeat sexp))
195 (defcustom message-deletable-headers '(Message-ID Date Lines)
196 "Headers to be deleted if they already exist and were generated by message previously."
197 :group 'message-headers
200 (defcustom message-ignored-news-headers
201 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:"
202 "*Regexp of headers to be removed unconditionally before posting."
204 :group 'message-headers
207 (defcustom message-ignored-mail-headers "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:"
208 "*Regexp of headers to be removed unconditionally before mailing."
210 :group 'message-headers
213 (defcustom message-ignored-supersedes-headers "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|X-Trace:\\|X-Complaints-To:\\|Return-Path:\\|^Supersedes:"
214 "*Header lines matching this regexp will be deleted before posting.
215 It's best to delete old Path and Date headers before posting to avoid
217 :group 'message-interface
221 (defcustom message-signature-separator "^-- *$"
222 "Regexp matching the signature separator."
224 :group 'message-various)
226 (defcustom message-elide-elipsis "\n[...]\n\n"
227 "*The string which is inserted for elided text.")
229 (defcustom message-interactive nil
230 "Non-nil means when sending a message wait for and display errors.
231 nil means let mailer mail back a message to report errors."
232 :group 'message-sending
236 (defcustom message-generate-new-buffers t
237 "*Non-nil means that a new message buffer will be created whenever `mail-setup' is called.
238 If this is a function, call that function with three parameters: The type,
239 the to address and the group name. (Any of these may be nil.) The function
240 should return the new buffer name."
241 :group 'message-buffers
242 :type '(choice (const :tag "off" nil)
246 (defcustom message-kill-buffer-on-exit nil
247 "*Non-nil means that the message buffer will be killed after sending a message."
248 :group 'message-buffers
251 (defvar gnus-local-organization)
252 (defcustom message-user-organization
253 (or (and (boundp 'gnus-local-organization)
254 (stringp gnus-local-organization)
255 gnus-local-organization)
256 (getenv "ORGANIZATION")
258 "*String to be used as an Organization header.
259 If t, use `message-user-organization-file'."
260 :group 'message-headers
261 :type '(choice string
262 (const :tag "consult file" t)))
265 (defcustom message-user-organization-file "/usr/lib/news/organization"
266 "*Local news organization file."
268 :group 'message-headers)
270 (defcustom message-autosave-directory
271 (nnheader-concat message-directory "drafts/")
272 "*Directory where Message autosaves buffers.
273 If nil, Message won't autosave."
274 :group 'message-buffers
277 (defcustom message-forward-start-separator
278 "------- Start of forwarded message -------\n"
279 "*Delimiter inserted before forwarded messages."
280 :group 'message-forwarding
283 (defcustom message-forward-end-separator
284 "------- End of forwarded message -------\n"
285 "*Delimiter inserted after forwarded messages."
286 :group 'message-forwarding
289 (defcustom message-signature-before-forwarded-message t
290 "*If non-nil, put the signature before any included forwarded message."
291 :group 'message-forwarding
294 (defcustom message-included-forward-headers
295 "^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:"
296 "*Regexp matching headers to be included in forwarded messages."
297 :group 'message-forwarding
300 (defcustom message-ignored-resent-headers "^Return-receipt"
301 "*All headers that match this regexp will be deleted when resending a message."
302 :group 'message-interface
305 (defcustom message-ignored-cited-headers "."
306 "*Delete these headers from the messages you yank."
307 :group 'message-insertion
310 (defcustom message-cancel-message "I am canceling my own article."
311 "Message to be inserted in the cancel message."
312 :group 'message-interface
315 ;; Useful to set in site-init.el
317 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
318 "Function to call to send the current buffer as mail.
319 The headers should be delimited by a line whose contents match the
320 variable `mail-header-separator'.
322 Legal values include `message-send-mail-with-sendmail' (the default),
323 `message-send-mail-with-mh', `message-send-mail-with-qmail' and
325 :type '(radio (function-item message-send-mail-with-sendmail)
326 (function-item message-send-mail-with-mh)
327 (function-item message-send-mail-with-qmail)
328 (function-item smtpmail-send-it)
329 (function :tag "Other"))
330 :group 'message-sending
331 :group 'message-mail)
333 (defcustom message-send-news-function 'message-send-news
334 "Function to call to send the current buffer as news.
335 The headers should be delimited by a line whose contents match the
336 variable `mail-header-separator'."
337 :group 'message-sending
341 (defcustom message-reply-to-function nil
342 "Function that should return a list of headers.
343 This function should pick out addresses from the To, Cc, and From headers
344 and respond with new To and Cc headers."
345 :group 'message-interface
348 (defcustom message-wide-reply-to-function nil
349 "Function that should return a list of headers.
350 This function should pick out addresses from the To, Cc, and From headers
351 and respond with new To and Cc headers."
352 :group 'message-interface
355 (defcustom message-followup-to-function nil
356 "Function that should return a list of headers.
357 This function should pick out addresses from the To, Cc, and From headers
358 and respond with new To and Cc headers."
359 :group 'message-interface
362 (defcustom message-use-followup-to 'ask
363 "*Specifies what to do with Followup-To header.
364 If nil, always ignore the header. If it is t, use its value, but
365 query before using the \"poster\" value. If it is the symbol `ask',
366 always query the user whether to use the value. If it is the symbol
367 `use', always use the value."
368 :group 'message-interface
369 :type '(choice (const :tag "ignore" nil)
373 ;; stuff relating to broken sendmail in MMDF
374 (defcustom message-sendmail-f-is-evil nil
375 "*Non-nil means that \"-f username\" should not be added to the sendmail
376 command line, because it is even more evil than leaving it out."
377 :group 'message-sending
380 ;; qmail-related stuff
381 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
382 "Location of the qmail-inject program."
383 :group 'message-sending
386 (defcustom message-qmail-inject-args nil
387 "Arguments passed to qmail-inject programs.
388 This should be a list of strings, one string for each argument.
390 For e.g., if you wish to set the envelope sender address so that bounces
391 go to the right place or to deal with listserv's usage of that address, you
392 might set this variable to '(\"-f\" \"you@some.where\")."
393 :group 'message-sending
394 :type '(repeat string))
396 (defvar gnus-post-method)
397 (defvar gnus-select-method)
398 (defcustom message-post-method
399 (cond ((and (boundp 'gnus-post-method)
402 ((boundp 'gnus-select-method)
405 "Method used to post news."
407 :group 'message-sending
408 ;; This should be the `gnus-select-method' widget, but that might
409 ;; create a dependence to `gnus.el'.
412 (defcustom message-generate-headers-first nil
413 "*If non-nil, generate all possible headers before composing."
414 :group 'message-headers
417 (defcustom message-setup-hook nil
418 "Normal hook, run each time a new outgoing message is initialized.
419 The function `message-setup' runs this hook."
420 :group 'message-various
423 (defcustom message-signature-setup-hook nil
424 "Normal hook, run each time a new outgoing message is initialized.
425 It is run after the headers have been inserted and before
426 the signature is inserted."
427 :group 'message-various
430 (defcustom message-mode-hook nil
431 "Hook run in message mode buffers."
432 :group 'message-various
435 (defcustom message-header-hook nil
436 "Hook run in a message mode buffer narrowed to the headers."
437 :group 'message-various
440 (defcustom message-header-setup-hook nil
441 "Hook called narrowed to the headers when setting up a message
443 :group 'message-various
447 (defcustom message-citation-line-function 'message-insert-citation-line
448 "*Function called to insert the \"Whomever writes:\" line."
450 :group 'message-insertion)
453 (defcustom message-yank-prefix "> "
454 "*Prefix inserted on the lines of yanked messages.
455 nil means use indentation."
457 :group 'message-insertion)
459 (defcustom message-indentation-spaces 3
460 "*Number of spaces to insert at the beginning of each cited line.
461 Used by `message-yank-original' via `message-yank-cite'."
462 :group 'message-insertion
466 (defcustom message-cite-function
467 (if (and (boundp 'mail-citation-hook)
470 'message-cite-original)
471 "*Function for citing an original message.
472 Pre-defined functions include `message-cite-original' and
473 `message-cite-original-without-signature'."
474 :type '(radio (function-item message-cite-original)
475 (function-item message-cite-original-without-signature)
476 (function-item sc-cite-original)
477 (function :tag "Other"))
478 :group 'message-insertion)
481 (defcustom message-indent-citation-function 'message-indent-citation
482 "*Function for modifying a citation just inserted in the mail buffer.
483 This can also be a list of functions. Each function can find the
484 citation between (point) and (mark t). And each function should leave
485 point and mark around the citation text as modified."
487 :group 'message-insertion)
489 (defvar message-abbrevs-loaded nil)
492 (defcustom message-signature t
493 "*String to be inserted at the end of the message buffer.
494 If t, the `message-signature-file' file will be inserted instead.
495 If a function, the result from the function will be used instead.
496 If a form, the result from the form will be used instead."
498 :group 'message-insertion)
501 (defcustom message-signature-file "~/.signature"
502 "*File containing the text inserted at end of message buffer."
504 :group 'message-insertion)
506 (defcustom message-distribution-function nil
507 "*Function called to return a Distribution header."
509 :group 'message-headers
512 (defcustom message-expires 14
513 "Number of days before your article expires."
515 :group 'message-headers
516 :link '(custom-manual "(message)News Headers")
519 (defcustom message-user-path nil
520 "If nil, use the NNTP server name in the Path header.
521 If stringp, use this; if non-nil, use no host name (user name only)."
523 :group 'message-headers
524 :link '(custom-manual "(message)News Headers")
525 :type '(choice (const :tag "nntp" nil)
527 (sexp :tag "none" :format "%t" t)))
529 (defvar message-reply-buffer nil)
530 (defvar message-reply-headers nil)
531 (defvar message-newsreader nil)
532 (defvar message-mailer nil)
533 (defvar message-sent-message-via nil)
534 (defvar message-checksum nil)
535 (defvar message-send-actions nil
536 "A list of actions to be performed upon successful sending of a message.")
537 (defvar message-exit-actions nil
538 "A list of actions to be performed upon exiting after sending a message.")
539 (defvar message-kill-actions nil
540 "A list of actions to be performed before killing a message buffer.")
541 (defvar message-postpone-actions nil
542 "A list of actions to be performed after postponing a message.")
544 (define-widget 'message-header-lines 'text
545 "All header lines must be LFD terminated."
547 :error "All header lines must be newline terminated")
549 (defcustom message-default-headers ""
550 "*A string containing header lines to be inserted in outgoing messages.
551 It is inserted before you edit the message, so you can edit or delete
553 :group 'message-headers
554 :type 'message-header-lines)
556 (defcustom message-default-mail-headers ""
557 "*A string of header lines to be inserted in outgoing mails."
558 :group 'message-headers
560 :type 'message-header-lines)
562 (defcustom message-default-news-headers ""
563 "*A string of header lines to be inserted in outgoing news
565 :group 'message-headers
567 :type 'message-header-lines)
569 ;; Note: could use /usr/ucb/mail instead of sendmail;
570 ;; options -t, and -v if not interactive.
571 (defcustom message-mailer-swallows-blank-line
572 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
573 system-configuration)
574 (file-readable-p "/etc/sendmail.cf")
575 (let ((buffer (get-buffer-create " *temp*")))
579 (insert-file-contents "/etc/sendmail.cf")
580 (goto-char (point-min))
581 (let ((case-fold-search nil))
582 (re-search-forward "^OR\\>" nil t)))
583 (kill-buffer buffer))))
584 ;; According to RFC822, "The field-name must be composed of printable
585 ;; ASCII characters (i. e., characters that have decimal values between
586 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
588 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
589 "Set this non-nil if the system's mailer runs the header and body together.
590 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
591 The value should be an expression to test whether the problem will
593 :group 'message-sending
596 ;; Ignore errors in case this is used in Emacs 19.
597 ;; Don't use ignore-errors because this is copied into loaddefs.el.
600 (define-mail-user-agent 'message-user-agent
601 'message-mail 'message-send-and-exit
602 'message-kill-buffer 'message-send-hook)
605 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
606 "If non-nil, delete the deletable headers before feeding to mh.")
608 (defvar message-send-method-alist
609 '((news message-news-p message-send-via-news)
610 (mail message-mail-p message-send-via-mail))
611 "Alist of ways to send outgoing messages.
612 Each element has the form
614 \(TYPE PREDICATE FUNCTION)
616 where TYPE is a symbol that names the method; PREDICATE is a function
617 called without any parameters to determine whether the message is
618 a message of type TYPE; and FUNCTION is a function to be called if
619 PREDICATE returns non-nil. FUNCTION is called with one parameter --
622 (defvar message-mail-alias-type 'abbrev
623 "*What alias expansion type to use in Message buffers.
624 The default is `abbrev', which uses mailabbrev. nil switches
627 ;;; Internal variables.
628 ;;; Well, not really internal.
630 (defvar message-mode-syntax-table
631 (let ((table (copy-syntax-table text-mode-syntax-table)))
632 (modify-syntax-entry ?% ". " table)
634 "Syntax table used while in Message mode.")
636 (defvar message-mode-abbrev-table text-mode-abbrev-table
637 "Abbrev table used in Message mode buffers.
638 Defaults to `text-mode-abbrev-table'.")
639 (defgroup message-headers nil
641 :link '(custom-manual "(message)Variables")
644 (defface message-header-to-face
647 (:foreground "green2" :bold t))
650 (:foreground "MidnightBlue" :bold t))
652 (:bold t :italic t)))
653 "Face used for displaying From headers."
654 :group 'message-faces)
656 (defface message-header-cc-face
659 (:foreground "green4" :bold t))
662 (:foreground "MidnightBlue"))
665 "Face used for displaying Cc headers."
666 :group 'message-faces)
668 (defface message-header-subject-face
671 (:foreground "green3"))
674 (:foreground "navy blue" :bold t))
677 "Face used for displaying subject headers."
678 :group 'message-faces)
680 (defface message-header-newsgroups-face
683 (:foreground "yellow" :bold t :italic t))
686 (:foreground "blue4" :bold t :italic t))
688 (:bold t :italic t)))
689 "Face used for displaying newsgroups headers."
690 :group 'message-faces)
692 (defface message-header-other-face
695 (:foreground "#b00000"))
698 (:foreground "steel blue"))
700 (:bold t :italic t)))
701 "Face used for displaying newsgroups headers."
702 :group 'message-faces)
704 (defface message-header-name-face
707 (:foreground "DarkGreen"))
710 (:foreground "cornflower blue"))
713 "Face used for displaying header names."
714 :group 'message-faces)
716 (defface message-header-xheader-face
719 (:foreground "blue"))
722 (:foreground "blue"))
725 "Face used for displaying X-Header headers."
726 :group 'message-faces)
728 (defface message-separator-face
731 (:foreground "blue3"))
734 (:foreground "brown"))
737 "Face used for displaying the separator."
738 :group 'message-faces)
740 (defface message-cited-text-face
749 "Face used for displaying cited text names."
750 :group 'message-faces)
752 (defvar message-font-lock-keywords
753 (let* ((cite-prefix "A-Za-z")
754 (cite-suffix (concat cite-prefix "0-9_.@-"))
755 (content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)"))
756 `((,(concat "^\\([Tt]o:\\)" content)
757 (1 'message-header-name-face)
758 (2 'message-header-to-face nil t))
759 (,(concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content)
760 (1 'message-header-name-face)
761 (2 'message-header-cc-face nil t))
762 (,(concat "^\\([Ss]ubject:\\)" content)
763 (1 'message-header-name-face)
764 (2 'message-header-subject-face nil t))
765 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content)
766 (1 'message-header-name-face)
767 (2 'message-header-newsgroups-face nil t))
768 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content)
769 (1 'message-header-name-face)
770 (2 'message-header-other-face nil t))
771 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content)
772 (1 'message-header-name-face)
773 (2 'message-header-name-face))
774 (,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
775 1 'message-separator-face)
777 "\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
779 (0 'message-cited-text-face))))
780 "Additional expressions to highlight in Message mode.")
782 ;; XEmacs does it like this. For Emacs, we have to set the
783 ;; `font-lock-defaults' buffer-local variable.
784 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
786 (defvar message-face-alist
787 '((bold . bold-region)
788 (underline . underline-region)
789 (default . (lambda (b e)
791 (ununderline-region b e))))
792 "Alist of mail and news faces for facemenu.
793 The cdr of ech entry is a function for applying the face to a region.")
795 (defcustom message-send-hook nil
796 "Hook run before sending messages."
797 :group 'message-various
798 :options '(ispell-message)
801 (defcustom message-send-mail-hook nil
802 "Hook run before sending mail messages."
803 :group 'message-various
806 (defcustom message-send-news-hook nil
807 "Hook run before sending news messages."
808 :group 'message-various
811 (defcustom message-sent-hook nil
812 "Hook run after sending messages."
813 :group 'message-various
816 ;;; Internal variables.
818 (defvar message-buffer-list nil)
819 (defvar message-this-is-news nil)
820 (defvar message-this-is-mail nil)
821 (defvar message-draft-article nil)
823 ;; Byte-compiler warning
824 (defvar gnus-active-hashtb)
825 (defvar gnus-read-active-file)
827 ;;; Regexp matching the delimiter of messages in UNIX mail format
828 ;;; (UNIX From lines), minus the initial ^. It should be a copy
829 ;;; of rmail.el's rmail-unix-mail-delimiter.
830 (defvar message-unix-mail-delimiter
831 (let ((time-zone-regexp
832 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
833 "\\|[-+]?[0-9][0-9][0-9][0-9]"
839 ;; Many things can happen to an RFC 822 mailbox before it is put into
840 ;; a `From' line. The leading phrase can be stripped, e.g.
841 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
842 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
843 ;; can be removed, e.g.
844 ;; From: joe@y.z (Joe K
846 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
849 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
850 ;; The mailbox can be removed or be replaced by white space, e.g.
851 ;; From: "Joe User"{space}{tab}
853 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
854 ;; where {space} and {tab} represent the Ascii space and tab characters.
855 ;; We want to match the results of any of these manglings.
856 ;; The following regexp rejects names whose first characters are
857 ;; obviously bogus, but after that anything goes.
858 "\\([^\0-\b\n-\r\^?].*\\)? "
860 ;; The time the message was sent.
861 "\\([^\0-\r \^?]+\\) +" ; day of the week
862 "\\([^\0-\r \^?]+\\) +" ; month
863 "\\([0-3]?[0-9]\\) +" ; day of month
864 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
866 ;; Perhaps a time zone, specified by an abbreviation, or by a
871 " \\([0-9][0-9]+\\) *"
873 ;; On some systems the time zone can appear after the year, too.
877 "\\(remote from .*\\)?"
880 "Regexp matching the delimiter of messages in UNIX mail format.")
882 (defvar message-unsent-separator
883 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
884 "^ *---+ +Returned message +---+ *$\\|"
885 "^Start of returned message$\\|"
886 "^ *---+ +Original message +---+ *$\\|"
887 "^ *--+ +begin message +--+ *$\\|"
888 "^ *---+ +Original message follows +---+ *$\\|"
889 "^|? *---+ +Message text follows: +---+ *|?$")
890 "A regexp that matches the separator before the text of a failed message.")
892 (defvar message-header-format-alist
894 (To . message-fill-address)
895 (Cc . message-fill-address)
906 (References . message-fill-header)
909 "Alist used for formatting headers.")
912 (autoload 'message-setup-toolbar "messagexmas")
913 (autoload 'mh-new-draft-name "mh-comp")
914 (autoload 'mh-send-letter "mh-comp")
915 (autoload 'gnus-point-at-eol "gnus-util")
916 (autoload 'gnus-point-at-bol "gnus-util")
917 (autoload 'gnus-output-to-mail "gnus-util")
918 (autoload 'gnus-output-to-rmail "gnus-util")
919 (autoload 'mail-abbrev-in-expansion-header-p "mailabbrev")
920 (autoload 'nndraft-request-associate-buffer "nndraft")
921 (autoload 'nndraft-request-expire-articles "nndraft"))
926 ;;; Utility functions.
929 (defmacro message-y-or-n-p (question show &rest text)
930 "Ask QUESTION, displaying the rest of the arguments in a temp. buffer if SHOW"
931 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
933 ;; Delete the current line (and the next N lines.);
934 (defmacro message-delete-line (&optional n)
935 `(delete-region (progn (beginning-of-line) (point))
936 (progn (forward-line ,(or n 1)) (point))))
938 (defun message-tokenize-header (header &optional separator)
939 "Split HEADER into a list of header elements.
940 \",\" is used as the separator."
943 (let ((regexp (format "[%s]+" (or separator ",")))
948 (message-set-work-buffer)
950 (goto-char (point-min))
955 (cond ((and (> (point) beg)
957 (and (looking-at regexp)
960 (push (buffer-substring beg (point)) elems)
961 (setq beg (match-end 0)))
962 ((= (following-char) ?\")
963 (setq quoted (not quoted)))
964 ((and (= (following-char) ?\()
967 ((and (= (following-char) ?\))
972 (defun message-mail-file-mbox-p (file)
973 "Say whether FILE looks like a Unix mbox file."
974 (when (and (file-exists-p file)
975 (file-readable-p file)
976 (file-regular-p file))
977 (nnheader-temp-write nil
978 (nnheader-insert-file-contents file)
979 (goto-char (point-min))
980 (looking-at message-unix-mail-delimiter))))
982 (defun message-fetch-field (header &optional not-all)
983 "The same as `mail-fetch-field', only remove all newlines."
984 (let ((value (mail-fetch-field header nil (not not-all))))
986 (nnheader-replace-chars-in-string value ?\n ? ))))
988 (defun message-add-header (&rest headers)
989 "Add the HEADERS to the message header, skipping those already present."
992 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
993 (error "Invalid header `%s'" (car headers)))
994 (setq hclean (match-string 1 (car headers)))
996 (message-narrow-to-headers)
997 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
998 (insert (car headers) ?\n))))
999 (setq headers (cdr headers))))
1001 (defun message-fetch-reply-field (header)
1002 "Fetch FIELD from the message we're replying to."
1003 (when (and message-reply-buffer
1004 (buffer-name message-reply-buffer))
1006 (set-buffer message-reply-buffer)
1007 (message-fetch-field header))))
1009 (defun message-set-work-buffer ()
1010 (if (get-buffer " *message work*")
1012 (set-buffer " *message work*")
1014 (set-buffer (get-buffer-create " *message work*"))
1015 (kill-all-local-variables)
1016 (buffer-disable-undo (current-buffer))))
1018 (defun message-functionp (form)
1019 "Return non-nil if FORM is funcallable."
1020 (or (and (symbolp form) (fboundp form))
1021 (and (listp form) (eq (car form) 'lambda))
1022 (byte-code-function-p form)))
1024 (defun message-strip-subject-re (subject)
1025 "Remove \"Re:\" from subject lines."
1026 (if (string-match "^[Rr][Ee]: *" subject)
1027 (substring subject (match-end 0))
1030 (defun message-remove-header (header &optional is-regexp first reverse)
1031 "Remove HEADER in the narrowed buffer.
1032 If REGEXP, HEADER is a regular expression.
1033 If FIRST, only remove the first instance of the header.
1034 Return the number of headers removed."
1035 (goto-char (point-min))
1036 (let ((regexp (if is-regexp header (concat "^" header ":")))
1038 (case-fold-search t)
1040 (while (and (not (eobp))
1043 (not (looking-at regexp))
1044 (looking-at regexp))
1051 ;; There might be a continuation header, so we have to search
1052 ;; until we find a new non-continuation line.
1055 (if (re-search-forward "^[^ \t]" nil t)
1056 (goto-char (match-beginning 0))
1059 (if (re-search-forward "^[^ \t]" nil t)
1060 (goto-char (match-beginning 0))
1064 (defun message-narrow-to-headers ()
1065 "Narrow the buffer to the head of the message."
1068 (goto-char (point-min))
1069 (if (re-search-forward
1070 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1073 (goto-char (point-min)))
1075 (defun message-narrow-to-head ()
1076 "Narrow the buffer to the head of the message."
1079 (goto-char (point-min))
1080 (if (search-forward "\n\n" nil 1)
1083 (goto-char (point-min)))
1085 (defun message-news-p ()
1086 "Say whether the current buffer contains a news message."
1087 (or message-this-is-news
1090 (message-narrow-to-headers)
1091 (and (message-fetch-field "newsgroups")
1092 (not (message-fetch-field "posted-to")))))))
1094 (defun message-mail-p ()
1095 "Say whether the current buffer contains a mail message."
1096 (or message-this-is-mail
1099 (message-narrow-to-headers)
1100 (or (message-fetch-field "to")
1101 (message-fetch-field "cc")
1102 (message-fetch-field "bcc"))))))
1104 (defun message-next-header ()
1105 "Go to the beginning of the next header."
1107 (or (eobp) (forward-char 1))
1108 (not (if (re-search-forward "^[^ \t]" nil t)
1110 (goto-char (point-max)))))
1112 (defun message-sort-headers-1 ()
1113 "Sort the buffer as headers using `message-rank' text props."
1114 (goto-char (point-min))
1116 nil 'message-next-header
1118 (message-next-header)
1122 (or (get-text-property (point) 'message-rank)
1125 (defun message-sort-headers ()
1126 "Sort the headers of the current message according to `message-header-format-alist'."
1130 (let ((max (1+ (length message-header-format-alist)))
1132 (message-narrow-to-headers)
1133 (while (re-search-forward "^[^ \n]+:" nil t)
1135 (match-beginning 0) (1+ (match-beginning 0))
1137 (if (setq rank (length (memq (assq (intern (buffer-substring
1139 (1- (match-end 0))))
1140 message-header-format-alist)
1141 message-header-format-alist)))
1144 (message-sort-headers-1))))
1154 (defvar message-mode-map nil)
1156 (unless message-mode-map
1157 (setq message-mode-map (copy-keymap text-mode-map))
1158 (define-key message-mode-map "\C-c?" 'describe-mode)
1160 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
1161 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
1162 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
1163 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
1164 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
1165 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
1166 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
1167 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
1168 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
1169 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
1170 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
1171 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
1172 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
1174 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
1175 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
1177 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
1178 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
1179 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
1180 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
1181 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
1182 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
1184 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
1185 (define-key message-mode-map "\C-c\C-s" 'message-send)
1186 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
1187 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
1189 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
1190 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
1191 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
1192 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
1194 (define-key message-mode-map "\t" 'message-tab))
1197 message-mode-menu message-mode-map "Message Menu."
1199 ["Sort Headers" message-sort-headers t]
1200 ["Yank Original" message-yank-original t]
1201 ["Fill Yanked Message" message-fill-yanked-message t]
1202 ["Insert Signature" message-insert-signature t]
1203 ["Caesar (rot13) Message" message-caesar-buffer-body t]
1204 ["Caesar (rot13) Region" message-caesar-region (mark t)]
1205 ["Elide Region" message-elide-region (mark t)]
1206 ["Delete Outside Region" message-delete-not-region (mark t)]
1207 ["Kill To Signature" message-kill-to-signature t]
1208 ["Newline and Reformat" message-newline-and-reformat t]
1209 ["Rename buffer" message-rename-buffer t]
1210 ["Spellcheck" ispell-message t]
1212 ["Send Message" message-send-and-exit t]
1213 ["Abort Message" message-dont-send t]))
1216 message-mode-field-menu message-mode-map ""
1218 ["Fetch To" message-insert-to t]
1219 ["Fetch Newsgroups" message-insert-newsgroups t]
1221 ["To" message-goto-to t]
1222 ["Subject" message-goto-subject t]
1223 ["Cc" message-goto-cc t]
1224 ["Reply-To" message-goto-reply-to t]
1225 ["Summary" message-goto-summary t]
1226 ["Keywords" message-goto-keywords t]
1227 ["Newsgroups" message-goto-newsgroups t]
1228 ["Followup-To" message-goto-followup-to t]
1229 ["Distribution" message-goto-distribution t]
1230 ["Body" message-goto-body t]
1231 ["Signature" message-goto-signature t]))
1233 (defvar facemenu-add-face-function)
1234 (defvar facemenu-remove-face-function)
1237 (defun message-mode ()
1238 "Major mode for editing mail and news to be sent.
1239 Like Text Mode but with these additional commands:
1240 C-c C-s message-send (send the message) C-c C-c message-send-and-exit
1241 C-c C-f move to a header field (and create it if there isn't):
1242 C-c C-f C-t move to To C-c C-f C-s move to Subject
1243 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1244 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1245 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1246 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1247 C-c C-f C-f move to Followup-To
1248 C-c C-t message-insert-to (add a To header to a news followup)
1249 C-c C-n message-insert-newsgroups (add a Newsgroup header to a news reply)
1250 C-c C-b message-goto-body (move to beginning of message text).
1251 C-c C-i message-goto-signature (move to the beginning of the signature).
1252 C-c C-w message-insert-signature (insert `message-signature-file' file).
1253 C-c C-y message-yank-original (insert current message, if any).
1254 C-c C-q message-fill-yanked-message (fill what was yanked).
1255 C-c C-e message-elide-region (elide the text between point and mark).
1256 C-c C-r message-caesar-buffer-body (rot13 the message body)."
1258 (kill-all-local-variables)
1259 (make-local-variable 'message-reply-buffer)
1260 (setq message-reply-buffer nil)
1261 (make-local-variable 'message-send-actions)
1262 (make-local-variable 'message-exit-actions)
1263 (make-local-variable 'message-kill-actions)
1264 (make-local-variable 'message-postpone-actions)
1265 (make-local-variable 'message-draft-article)
1266 (make-local-hook 'kill-buffer-hook)
1267 (set-syntax-table message-mode-syntax-table)
1268 (use-local-map message-mode-map)
1269 (setq local-abbrev-table message-mode-abbrev-table)
1270 (setq major-mode 'message-mode)
1271 (setq mode-name "Message")
1272 (setq buffer-offer-save t)
1273 (make-local-variable 'facemenu-add-face-function)
1274 (make-local-variable 'facemenu-remove-face-function)
1275 (setq facemenu-add-face-function
1277 (let ((face-fun (cdr (assq face message-face-alist))))
1279 (funcall face-fun (point) end)
1280 (error "Face %s not configured for %s mode" face mode-name)))
1282 facemenu-remove-face-function t)
1283 (make-local-variable 'paragraph-separate)
1284 (make-local-variable 'paragraph-start)
1285 (setq paragraph-start
1286 (concat (regexp-quote mail-header-separator)
1287 "$\\|[ \t]*[-_][-_][-_]+$\\|"
1289 ;;!!! Uhm... shurely this can't be right.
1290 "[> " (regexp-quote message-yank-prefix) "]+$\\|"
1292 (setq paragraph-separate
1293 (concat (regexp-quote mail-header-separator)
1294 "$\\|[ \t]*[-_][-_][-_]+$\\|"
1296 "[> " (regexp-quote message-yank-prefix) "]+$\\|"
1297 paragraph-separate))
1298 (make-local-variable 'message-reply-headers)
1299 (setq message-reply-headers nil)
1300 (make-local-variable 'message-newsreader)
1301 (make-local-variable 'message-mailer)
1302 (make-local-variable 'message-post-method)
1303 (make-local-variable 'message-sent-message-via)
1304 (setq message-sent-message-via nil)
1305 (make-local-variable 'message-checksum)
1306 (setq message-checksum nil)
1307 ;;(when (fboundp 'mail-hist-define-keys)
1308 ;; (mail-hist-define-keys))
1309 (when (string-match "XEmacs\\|Lucid" emacs-version)
1310 (message-setup-toolbar))
1311 (easy-menu-add message-mode-menu message-mode-map)
1312 (easy-menu-add message-mode-field-menu message-mode-map)
1313 ;; Allow mail alias things.
1314 (when (eq message-mail-alias-type 'abbrev)
1315 (if (fboundp 'mail-abbrevs-setup)
1316 (mail-abbrevs-setup)
1317 (funcall (intern "mail-aliases-setup"))))
1318 (message-set-auto-save-file-name)
1319 (run-hooks 'text-mode-hook 'message-mode-hook)
1320 (unless (string-match "XEmacs" emacs-version)
1321 (set (make-local-variable 'font-lock-defaults)
1322 '(message-font-lock-keywords t))))
1327 ;;; Message mode commands
1330 ;;; Movement commands
1332 (defun message-goto-to ()
1333 "Move point to the To header."
1335 (message-position-on-field "To"))
1337 (defun message-goto-subject ()
1338 "Move point to the Subject header."
1340 (message-position-on-field "Subject"))
1342 (defun message-goto-cc ()
1343 "Move point to the Cc header."
1345 (message-position-on-field "Cc" "To"))
1347 (defun message-goto-bcc ()
1348 "Move point to the Bcc header."
1350 (message-position-on-field "Bcc" "Cc" "To"))
1352 (defun message-goto-fcc ()
1353 "Move point to the Fcc header."
1355 (message-position-on-field "Fcc" "To" "Newsgroups"))
1357 (defun message-goto-reply-to ()
1358 "Move point to the Reply-To header."
1360 (message-position-on-field "Reply-To" "Subject"))
1362 (defun message-goto-newsgroups ()
1363 "Move point to the Newsgroups header."
1365 (message-position-on-field "Newsgroups"))
1367 (defun message-goto-distribution ()
1368 "Move point to the Distribution header."
1370 (message-position-on-field "Distribution"))
1372 (defun message-goto-followup-to ()
1373 "Move point to the Followup-To header."
1375 (message-position-on-field "Followup-To" "Newsgroups"))
1377 (defun message-goto-keywords ()
1378 "Move point to the Keywords header."
1380 (message-position-on-field "Keywords" "Subject"))
1382 (defun message-goto-summary ()
1383 "Move point to the Summary header."
1385 (message-position-on-field "Summary" "Subject"))
1387 (defun message-goto-body ()
1388 "Move point to the beginning of the message body."
1390 (if (looking-at "[ \t]*\n") (expand-abbrev))
1391 (goto-char (point-min))
1392 (search-forward (concat "\n" mail-header-separator "\n") nil t))
1394 (defun message-goto-signature ()
1395 "Move point to the beginning of the message signature."
1397 (goto-char (point-min))
1398 (if (re-search-forward message-signature-separator nil t)
1400 (goto-char (point-max))))
1404 (defun message-insert-to (&optional force)
1405 "Insert a To header that points to the author of the article being replied to.
1406 If the original author requested not to be sent mail, the function signals
1408 With the prefix argument FORCE, insert the header anyway."
1410 (let ((co (message-fetch-reply-field "mail-copies-to")))
1411 (when (and (null force)
1413 (equal (downcase co) "never"))
1414 (error "The user has requested not to have copies sent via mail")))
1415 (when (and (message-position-on-field "To")
1416 (mail-fetch-field "to")
1417 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
1419 (insert (or (message-fetch-reply-field "reply-to")
1420 (message-fetch-reply-field "from") "")))
1422 (defun message-insert-newsgroups ()
1423 "Insert the Newsgroups header from the article being replied to."
1425 (when (and (message-position-on-field "Newsgroups")
1426 (mail-fetch-field "newsgroups")
1427 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
1429 (insert (or (message-fetch-reply-field "newsgroups") "")))
1433 ;;; Various commands
1435 (defun message-delete-not-region (beg end)
1436 "Delete everything in the body of the current message that is outside of the region."
1440 (delete-region (point) (progn (message-goto-signature)
1445 (delete-region beg (progn (message-goto-body)
1448 (message-goto-signature)
1451 (defun message-kill-to-signature ()
1452 "Deletes all text up to the signature."
1454 (let ((point (point)))
1455 (message-goto-signature)
1457 (kill-region point (point))
1461 (defun message-newline-and-reformat ()
1462 "Insert four newlines, and then reformat if inside quoted text."
1464 (let ((point (point))
1468 (setq quoted (looking-at (regexp-quote message-yank-prefix))))
1471 (insert message-yank-prefix))
1472 (fill-paragraph nil)
1476 (defun message-insert-signature (&optional force)
1477 "Insert a signature. See documentation for the `message-signature' variable."
1478 (interactive (list 0))
1481 ((and (null message-signature)
1484 (goto-char (point-max))
1485 (not (re-search-backward
1486 message-signature-separator nil t))))
1487 ((and (null message-signature)
1490 ((message-functionp message-signature)
1491 (funcall message-signature))
1492 ((listp message-signature)
1493 (eval message-signature))
1494 (t message-signature)))
1496 (cond ((stringp signature)
1498 ((and (eq t signature)
1499 message-signature-file
1500 (file-exists-p message-signature-file))
1503 (goto-char (point-max))
1504 ;; Insert the signature.
1508 (if (eq signature t)
1509 (insert-file-contents message-signature-file)
1511 (goto-char (point-max))
1512 (or (bolp) (insert "\n")))))
1514 (defun message-elide-region (b e)
1515 "Elide the text between point and mark. An ellipsis (from
1516 message-elide-elipsis) will be inserted where the text was killed."
1521 (insert message-elide-elipsis))
1523 (defvar message-caesar-translation-table nil)
1525 (defun message-caesar-region (b e &optional n)
1526 "Caesar rotation of region by N, default 13, for decrypting netnews."
1529 (min (point) (or (mark t) (point)))
1530 (max (point) (or (mark t) (point)))
1531 (when current-prefix-arg
1532 (prefix-numeric-value current-prefix-arg))))
1534 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
1535 (unless (or (zerop n) ; no action needed for a rot of 0
1536 (= b e)) ; no region to rotate
1537 ;; We build the table, if necessary.
1538 (when (or (not message-caesar-translation-table)
1539 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
1540 (setq message-caesar-translation-table
1541 (message-make-caesar-translation-table n)))
1542 ;; Then we translate the region. Do it this way to retain
1545 (subst-char-in-region
1546 b (1+ b) (char-after b)
1547 (aref message-caesar-translation-table (char-after b)))
1550 (defun message-make-caesar-translation-table (n)
1551 "Create a rot table with offset N."
1553 (table (make-string 256 0)))
1554 (while (< (incf i) 256)
1557 (substring table 0 ?A)
1558 (substring table (+ ?A n) (+ ?A n (- 26 n)))
1559 (substring table ?A (+ ?A n))
1560 (substring table (+ ?A 26) ?a)
1561 (substring table (+ ?a n) (+ ?a n (- 26 n)))
1562 (substring table ?a (+ ?a n))
1563 (substring table (+ ?a 26) 255))))
1565 (defun message-caesar-buffer-body (&optional rotnum)
1566 "Caesar rotates all letters in the current buffer by 13 places.
1567 Used to encode/decode possiblyun offensive messages (commonly in net.jokes).
1568 With prefix arg, specifies the number of places to rotate each letter forward.
1569 Mail and USENET news headers are not rotated."
1570 (interactive (if current-prefix-arg
1571 (list (prefix-numeric-value current-prefix-arg))
1575 (when (message-goto-body)
1576 (narrow-to-region (point) (point-max)))
1577 (message-caesar-region (point-min) (point-max) rotnum))))
1579 (defun message-pipe-buffer-body (program)
1580 "Pipe the message body in the current buffer through PROGRAM."
1583 (when (message-goto-body)
1584 (narrow-to-region (point) (point-max)))
1585 (let ((body (buffer-substring (point-min) (point-max))))
1586 (unless (equal 0 (call-process-region
1587 (point-min) (point-max) program t t))
1589 (message "%s failed." program))))))
1591 (defun message-rename-buffer (&optional enter-string)
1592 "Rename the *message* buffer to \"*message* RECIPIENT\".
1593 If the function is run with a prefix, it will ask for a new buffer
1594 name, rather than giving an automatic name."
1595 (interactive "Pbuffer name: ")
1598 (goto-char (point-min))
1599 (narrow-to-region (point)
1600 (search-forward mail-header-separator nil 'end))
1602 (if (message-news-p) (message-fetch-field "Newsgroups")
1603 (message-fetch-field "To"))
1606 (if (string-match "," mail-to)
1607 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
1609 (name-default (concat "*message* " mail-trimmed-to))
1610 (name (if enter-string
1611 (read-string "New buffer name: " name-default)
1614 (if message-autosave-directory
1615 (file-name-as-directory message-autosave-directory)
1616 default-directory)))
1617 (rename-buffer name t)))))
1619 (defun message-fill-yanked-message (&optional justifyp)
1620 "Fill the paragraphs of a message yanked into this one.
1621 Numeric argument means justify as well."
1624 (goto-char (point-min))
1625 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1626 (let ((fill-prefix message-yank-prefix))
1627 (fill-individual-paragraphs (point) (point-max) justifyp t))))
1629 (defun message-indent-citation ()
1630 "Modify text just inserted from a message to be cited.
1631 The inserted text should be the region.
1632 When this function returns, the region is again around the modified text.
1634 Normally, indent each nonblank line `message-indentation-spaces' spaces.
1635 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
1636 (let ((start (point)))
1637 ;; Remove unwanted headers.
1638 (when message-ignored-cited-headers
1643 (if (search-forward "\n\n" nil t)
1646 (message-remove-header message-ignored-cited-headers t)
1647 (when (= (point-min) (point-max))
1648 (setq all-removed t))
1649 (goto-char (point-max)))
1653 ;; Delete blank lines at the start of the buffer.
1654 (while (and (point-min)
1657 (message-delete-line))
1658 ;; Delete blank lines at the end of the buffer.
1659 (goto-char (point-max))
1662 (while (and (zerop (forward-line -1))
1664 (message-delete-line))
1665 ;; Do the indentation.
1666 (if (null message-yank-prefix)
1667 (indent-rigidly start (mark t) message-indentation-spaces)
1670 (while (< (point) (mark t))
1671 (insert message-yank-prefix)
1675 (defun message-yank-original (&optional arg)
1676 "Insert the message being replied to, if any.
1677 Puts point before the text and mark after.
1678 Normally indents each nonblank line ARG spaces (default 3). However,
1679 if `message-yank-prefix' is non-nil, insert that prefix on each line.
1681 This function uses `message-cite-function' to do the actual citing.
1683 Just \\[universal-argument] as argument means don't indent, insert no
1684 prefix, and don't delete any headers."
1686 (let ((modified (buffer-modified-p)))
1687 (when (and message-reply-buffer
1688 message-cite-function)
1689 (delete-windows-on message-reply-buffer t)
1690 (insert-buffer message-reply-buffer)
1691 (funcall message-cite-function)
1692 (message-exchange-point-and-mark)
1696 (setq message-checksum (cons (message-checksum) (buffer-size)))))))
1698 (defun message-cite-original-without-signature ()
1699 "Cite function in the standard Message manner."
1700 (let ((start (point))
1703 (when message-indent-citation-function
1704 (if (listp message-indent-citation-function)
1705 message-indent-citation-function
1706 (list message-indent-citation-function)))))
1708 (when (re-search-backward "^-- $" start t)
1709 (delete-region (point) end))
1712 (funcall (pop functions)))
1713 (when message-citation-line-function
1716 (funcall message-citation-line-function))))
1718 (defun message-cite-original ()
1719 "Cite function in the standard Message manner."
1720 (let ((start (point))
1722 (when message-indent-citation-function
1723 (if (listp message-indent-citation-function)
1724 message-indent-citation-function
1725 (list message-indent-citation-function)))))
1728 (funcall (pop functions)))
1729 (when message-citation-line-function
1732 (funcall message-citation-line-function))))
1734 (defun message-insert-citation-line ()
1735 "Function that inserts a simple citation line."
1736 (when message-reply-headers
1737 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
1739 (defun message-position-on-field (header &rest afters)
1740 (let ((case-fold-search t))
1743 (goto-char (point-min))
1746 (concat "^" (regexp-quote mail-header-separator) "$"))
1747 (match-beginning 0)))
1748 (goto-char (point-min))
1749 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
1751 (re-search-forward "^[^ \t]" nil 'move)
1753 (skip-chars-backward "\n")
1756 (not (re-search-forward
1757 (concat "^" (regexp-quote (car afters)) ":")
1761 (re-search-forward "^[^ \t]" nil 'move)
1762 (beginning-of-line))
1763 (insert header ": \n")
1767 (defun message-remove-signature ()
1768 "Remove the signature from the text between point and mark.
1769 The text will also be indented the normal way."
1771 (let ((start (point))
1773 (if (not (re-search-forward message-signature-separator (mark t) t))
1774 ;; No signature here, so we just indent the cited text.
1775 (message-indent-citation)
1776 ;; Find the last non-empty line.
1778 (while (looking-at "[ \t]*$")
1781 (setq mark (set-marker (make-marker) (point)))
1783 (message-indent-citation)
1784 ;; Enable undoing the deletion.
1786 (delete-region mark (mark t))
1787 (set-marker mark nil)))))
1792 ;;; Sending messages
1795 (defun message-send-and-exit (&optional arg)
1796 "Send message like `message-send', then, if no errors, exit from mail buffer."
1798 (let ((buf (current-buffer))
1799 (actions message-exit-actions))
1800 (when (and (message-send arg)
1802 (if message-kill-buffer-on-exit
1805 (when (eq buf (current-buffer))
1806 (message-bury buf)))
1807 (message-do-actions actions))))
1809 (defun message-dont-send ()
1810 "Don't send the message you have been editing."
1813 (let ((actions message-postpone-actions))
1814 (message-bury (current-buffer))
1815 (message-do-actions actions)))
1817 (defun message-kill-buffer ()
1818 "Kill the current buffer."
1820 (when (or (not (buffer-modified-p))
1821 (yes-or-no-p "Message modified; kill anyway? "))
1822 (let ((actions message-kill-actions))
1823 (setq buffer-file-name nil)
1824 (kill-buffer (current-buffer))
1825 (message-do-actions actions))))
1827 (defun message-bury (buffer)
1828 "Bury this mail buffer."
1829 (let ((newbuf (other-buffer buffer)))
1830 (bury-buffer buffer)
1831 (if (and (fboundp 'frame-parameters)
1832 (cdr (assq 'dedicated (frame-parameters)))
1833 (not (null (delq (selected-frame) (visible-frame-list)))))
1834 (delete-frame (selected-frame))
1835 (switch-to-buffer newbuf))))
1837 (defun message-send (&optional arg)
1838 "Send the message in the current buffer.
1839 If `message-interactive' is non-nil, wait for success indication
1840 or error messages, and inform user.
1841 Otherwise any failure is reported in a message back to
1842 the user from the mailer."
1845 (when (or (buffer-modified-p)
1846 (message-check-element 'unchanged)
1847 (y-or-n-p "No changes in the buffer; really send? "))
1848 ;; Make it possible to undo the coming changes.
1850 (let ((inhibit-read-only t))
1851 (put-text-property (point-min) (point-max) 'read-only nil))
1852 (message-fix-before-sending)
1853 (run-hooks 'message-send-hook)
1854 (message "Sending...")
1855 (let ((alist message-send-method-alist)
1859 (setq elem (pop alist)))
1860 (when (and (or (not (funcall (cadr elem)))
1861 (and (or (not (memq (car elem)
1862 message-sent-message-via))
1865 "Already sent message via %s; resend? "
1867 (setq success (funcall (caddr elem) arg)))))
1869 (when (and success sent)
1871 ;;(when (fboundp 'mail-hist-put-headers-into-history)
1872 ;; (mail-hist-put-headers-into-history))
1873 (run-hooks 'message-sent-hook)
1874 (message "Sending...done")
1875 ;; Mark the buffer as unmodified and delete autosave.
1876 (set-buffer-modified-p nil)
1877 (delete-auto-save-file-if-necessary t)
1878 (message-disassociate-draft)
1879 ;; Delete other mail buffers and stuff.
1880 (message-do-send-housekeeping)
1881 (message-do-actions message-send-actions)
1885 (defun message-send-via-mail (arg)
1886 "Send the current message via mail."
1887 (message-send-mail arg))
1889 (defun message-send-via-news (arg)
1890 "Send the current message via news."
1891 (funcall message-send-news-function arg))
1893 (defun message-fix-before-sending ()
1894 "Do various things to make the message nice before sending it."
1895 ;; Make sure there's a newline at the end of the message.
1896 (goto-char (point-max))
1900 (defun message-add-action (action &rest types)
1901 "Add ACTION to be performed when doing an exit of type TYPES."
1904 (set (setq var (intern (format "message-%s-actions" (pop types))))
1905 (nconc (symbol-value var) (list action))))))
1907 (defun message-do-actions (actions)
1908 "Perform all actions in ACTIONS."
1909 ;; Now perform actions on successful sending.
1913 ;; A simple function.
1914 ((message-functionp (car actions))
1915 (funcall (car actions)))
1916 ;; Something to be evaled.
1918 (eval (car actions)))))
1921 (defun message-send-mail (&optional arg)
1922 (require 'mail-utils)
1923 (let ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
1924 (case-fold-search nil)
1925 (news (message-news-p))
1926 (mailbuf (current-buffer)))
1928 (message-narrow-to-headers)
1929 ;; Insert some headers.
1930 (let ((message-deletable-headers
1931 (if news nil message-deletable-headers)))
1932 (message-generate-headers message-required-mail-headers))
1933 ;; Let the user do all of the above.
1934 (run-hooks 'message-header-hook))
1939 ;; Avoid copying text props.
1941 "%s" (save-excursion
1942 (set-buffer mailbuf)
1944 ;; Remove some headers.
1946 (message-narrow-to-headers)
1947 ;; Remove some headers.
1948 (message-remove-header message-ignored-mail-headers t))
1949 (goto-char (point-max))
1950 ;; require one newline at the end.
1951 (or (= (preceding-char) ?\n)
1954 (or (message-fetch-field "cc")
1955 (message-fetch-field "to")))
1956 (message-insert-courtesy-copy))
1957 (funcall message-send-mail-function))
1958 (kill-buffer tembuf))
1959 (set-buffer mailbuf)
1960 (push 'mail message-sent-message-via)))
1962 (defun message-send-mail-with-sendmail ()
1963 "Send off the prepared buffer with sendmail."
1964 (let ((errbuf (if message-interactive
1965 (generate-new-buffer " sendmail errors")
1967 resend-to-addresses delimline)
1968 (let ((case-fold-search t))
1970 (message-narrow-to-headers)
1971 (setq resend-to-addresses (message-fetch-field "resent-to")))
1972 ;; Change header-delimiter to be what sendmail expects.
1973 (goto-char (point-min))
1975 (concat "^" (regexp-quote mail-header-separator) "\n"))
1976 (replace-match "\n")
1978 (setq delimline (point-marker))
1979 (run-hooks 'message-send-mail-hook)
1980 ;; Insert an extra newline if we need it to work around
1981 ;; Sun's bug that swallows newlines.
1982 (goto-char (1+ delimline))
1983 (when (eval message-mailer-swallows-blank-line)
1985 (when message-interactive
1989 (let ((default-directory "/")
1990 (coding-system-for-write 'binary))
1991 (apply 'call-process-region
1992 (append (list (point-min) (point-max)
1993 (if (boundp 'sendmail-program)
1995 "/usr/lib/sendmail")
1996 nil errbuf nil "-oi")
1997 ;; Always specify who from,
1998 ;; since some systems have broken sendmails.
1999 ;; But some systems are more broken with -f, so
2000 ;; we'll let users override this.
2001 (if (null message-sendmail-f-is-evil)
2002 (list "-f" (user-login-name)))
2003 ;; These mean "report errors by mail"
2004 ;; and "deliver in background".
2005 (if (null message-interactive) '("-oem" "-odb"))
2006 ;; Get the addresses from the message
2007 ;; unless this is a resend.
2008 ;; We must not do that for a resend
2009 ;; because we would find the original addresses.
2010 ;; For a resend, include the specific addresses.
2011 (if resend-to-addresses
2012 (list resend-to-addresses)
2014 (when message-interactive
2017 (goto-char (point-min))
2018 (while (re-search-forward "\n\n* *" nil t)
2019 (replace-match "; "))
2020 (if (not (zerop (buffer-size)))
2021 (error "Sending...failed to %s"
2022 (buffer-substring (point-min) (point-max)))))
2023 (when (bufferp errbuf)
2024 (kill-buffer errbuf)))))
2026 (defun message-send-mail-with-qmail ()
2027 "Pass the prepared message buffer to qmail-inject.
2028 Refer to the documentation for the variable `message-send-mail-function'
2029 to find out how to use this."
2030 ;; replace the header delimiter with a blank line
2031 (goto-char (point-min))
2033 (concat "^" (regexp-quote mail-header-separator) "\n"))
2034 (replace-match "\n")
2035 (run-hooks 'message-send-mail-hook)
2038 (let ((coding-system-for-write 'binary))
2040 'call-process-region 1 (point-max) message-qmail-inject-program
2042 ;; qmail-inject's default behaviour is to look for addresses on the
2043 ;; command line; if there're none, it scans the headers.
2044 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
2046 ;; in general, ALL of qmail-inject's defaults are perfect for simply
2047 ;; reading a formatted (i. e., at least a To: or Resent-To header)
2048 ;; message from stdin.
2050 ;; qmail also has the advantage of not having been raped by
2051 ;; various vendors, so we don't have to allow for that, either --
2052 ;; compare this with message-send-mail-with-sendmail and weep
2053 ;; for sendmail's lost innocence.
2055 ;; all this is way cool coz it lets us keep the arguments entirely
2056 ;; free for -inject-arguments -- a big win for the user and for us
2057 ;; since we don't have to play that double-guessing game and the user
2058 ;; gets full control (no gestapo'ish -f's, for instance). --sj
2059 message-qmail-inject-args))
2060 ;; qmail-inject doesn't say anything on it's stdout/stderr,
2061 ;; we have to look at the retval instead
2063 (1 (error "qmail-inject reported permanent failure"))
2064 (111 (error "qmail-inject reported transient failure"))
2065 ;; should never happen
2066 (t (error "qmail-inject reported unknown failure"))))
2068 (defun message-send-mail-with-mh ()
2069 "Send the prepared message buffer with mh."
2070 (let ((mh-previous-window-config nil)
2071 (name (mh-new-draft-name)))
2072 (setq buffer-file-name name)
2073 ;; MH wants to generate these headers itself.
2074 (when message-mh-deletable-headers
2075 (let ((headers message-mh-deletable-headers))
2077 (goto-char (point-min))
2078 (and (re-search-forward
2079 (concat "^" (symbol-name (car headers)) ": *") nil t)
2080 (message-delete-line))
2082 (run-hooks 'message-send-mail-hook)
2083 ;; Pass it on to mh.
2086 (defun message-send-news (&optional arg)
2087 (let ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
2088 (case-fold-search nil)
2089 (method (if (message-functionp message-post-method)
2090 (funcall message-post-method arg)
2091 message-post-method))
2092 (messbuf (current-buffer))
2093 (message-syntax-checks
2095 (cons '(existing-newsgroups . disabled)
2096 message-syntax-checks)
2097 message-syntax-checks))
2100 (message-narrow-to-headers)
2101 ;; Insert some headers.
2102 (message-generate-headers message-required-news-headers)
2103 ;; Let the user do all of the above.
2104 (run-hooks 'message-header-hook))
2105 (message-cleanup-headers)
2106 (if (not (message-check-news-syntax))
2108 ;;(message "Posting not performed")
2113 (buffer-disable-undo (current-buffer))
2115 ;; Avoid copying text props.
2117 "%s" (save-excursion
2118 (set-buffer messbuf)
2120 ;; Remove some headers.
2122 (message-narrow-to-headers)
2123 ;; Remove some headers.
2124 (message-remove-header message-ignored-news-headers t))
2125 (goto-char (point-max))
2126 ;; require one newline at the end.
2127 (or (= (preceding-char) ?\n)
2129 (let ((case-fold-search t))
2130 ;; Remove the delimiter.
2131 (goto-char (point-min))
2133 (concat "^" (regexp-quote mail-header-separator) "\n"))
2134 (replace-match "\n")
2136 (run-hooks 'message-send-news-hook)
2137 ;;(require (car method))
2138 ;;(funcall (intern (format "%s-open-server" (car method)))
2139 ;;(cadr method) (cddr method))
2141 ;; (funcall (intern (format "%s-request-post" (car method)))
2143 (gnus-open-server method)
2144 (setq result (gnus-request-post method)))
2145 (kill-buffer tembuf))
2146 (set-buffer messbuf)
2148 (push 'news message-sent-message-via)
2149 (message "Couldn't send message via news: %s"
2150 (nnheader-get-report (car method)))
2154 ;;; Header generation & syntax checking.
2157 (defmacro message-check (type &rest forms)
2158 "Eval FORMS if TYPE is to be checked."
2159 `(or (message-check-element ,type)
2163 (put 'message-check 'lisp-indent-function 1)
2164 (put 'message-check 'edebug-form-spec '(form body))
2166 (defun message-check-element (type)
2167 "Returns non-nil if this type is not to be checked."
2168 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
2170 (let ((able (assq type message-syntax-checks)))
2172 (eq (cdr able) 'disabled)))))
2174 (defun message-check-news-syntax ()
2175 "Check the syntax of the message."
2180 ;; We narrow to the headers and check them first.
2183 (message-narrow-to-headers)
2184 (message-check-news-header-syntax)))
2186 (message-check-news-body-syntax)))))
2188 (defun message-check-news-header-syntax ()
2190 ;; Check the Subject header.
2191 (message-check 'subject
2192 (let* ((case-fold-search t)
2193 (subject (message-fetch-field "subject")))
2196 (not (string-match "\\`[ \t]*\\'" subject)))
2199 "The subject field is empty or missing. Posting is denied.")))))
2200 ;; Check for commands in Subject.
2201 (message-check 'subject-cmsg
2202 (if (string-match "^cmsg " (message-fetch-field "subject"))
2204 "The control code \"cmsg\" is in the subject. Really post? ")
2206 ;; Check for multiple identical headers.
2207 (message-check 'multiple-headers
2209 (while (and (not found)
2210 (re-search-forward "^[^ \t:]+: " nil t))
2212 (or (re-search-forward
2217 (match-beginning 0) (- (match-end 0) 2))))
2222 (y-or-n-p (format "Multiple %s headers. Really post? " found))
2224 ;; Check for Version and Sendsys.
2225 (message-check 'sendsys
2226 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
2228 (format "The article contains a %s command. Really post? "
2229 (buffer-substring (match-beginning 0)
2230 (1- (match-end 0)))))
2232 ;; See whether we can shorten Followup-To.
2233 (message-check 'shorten-followup-to
2234 (let ((newsgroups (message-fetch-field "newsgroups"))
2235 (followup-to (message-fetch-field "followup-to"))
2237 (when (and newsgroups
2238 (string-match "," newsgroups)
2243 (setq to (completing-read
2244 "Followups to: (default all groups) "
2245 (mapcar (lambda (g) (list g))
2247 (message-tokenize-header
2249 (goto-char (point-min))
2250 (insert "Followup-To: " to "\n"))
2252 ;; Check "Shoot me".
2253 (message-check 'shoot
2254 (if (re-search-forward
2255 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
2256 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
2258 ;; Check for Approved.
2259 (message-check 'approved
2260 (if (re-search-forward "^Approved:" nil t)
2261 (y-or-n-p "The article contains an Approved header. Really post? ")
2263 ;; Check the Message-ID header.
2264 (message-check 'message-id
2265 (let* ((case-fold-search t)
2266 (message-id (message-fetch-field "message-id" t)))
2267 (or (not message-id)
2268 (and (string-match "@" message-id)
2269 (string-match "@[^\\.]*\\." message-id))
2271 (format "The Message-ID looks strange: \"%s\". Really post? "
2273 ;; Check the Newsgroups & Followup-To headers.
2274 (message-check 'existing-newsgroups
2275 (let* ((case-fold-search t)
2276 (newsgroups (message-fetch-field "newsgroups"))
2277 (followup-to (message-fetch-field "followup-to"))
2278 (groups (message-tokenize-header
2280 (concat newsgroups "," followup-to)
2282 (hashtb (and (boundp 'gnus-active-hashtb)
2283 gnus-active-hashtb))
2285 (if (or (not hashtb)
2286 (not (boundp 'gnus-read-active-file))
2287 (not gnus-read-active-file)
2288 (eq gnus-read-active-file 'some))
2291 (when (and (not (boundp (intern (car groups) hashtb)))
2292 (not (equal (car groups) "poster")))
2293 (push (car groups) errors))
2299 "Really post to %s unknown group%s: %s "
2300 (if (= (length errors) 1) "this" "these")
2301 (if (= (length errors) 1) "" "s")
2302 (mapconcat 'identity errors ", ")))))))
2303 ;; Check the Newsgroups & Followup-To headers for syntax errors.
2304 (message-check 'valid-newsgroups
2305 (let ((case-fold-search t)
2306 (headers '("Newsgroups" "Followup-To"))
2308 (while (and headers (not error))
2309 (when (setq header (mail-fetch-field (car headers)))
2313 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
2318 (not (string-match "\\.\\'\\|\\.\\." g)))
2319 (message-tokenize-header header ","))))
2326 (format "The %s header looks odd: \"%s\". Really post? "
2327 (car headers) header)))))
2328 (message-check 'repeated-newsgroups
2329 (let ((case-fold-search t)
2330 (headers '("Newsgroups" "Followup-To"))
2331 header error groups group)
2334 (when (setq header (mail-fetch-field (pop headers)))
2335 (setq groups (message-tokenize-header header ","))
2336 (while (setq group (pop groups))
2337 (when (member group groups)
2343 (format "Group %s is repeated in headers. Really post? " error)))))
2344 ;; Check the From header.
2345 (message-check 'from
2346 (let* ((case-fold-search t)
2347 (from (message-fetch-field "from"))
2348 (ad (nth 1 (mail-extract-address-components from))))
2351 (message "There is no From line. Posting is denied.")
2353 ((or (not (string-match "@[^\\.]*\\." ad)) ;larsi@ifi
2354 (string-match "\\.\\." ad) ;larsi@ifi..uio
2355 (string-match "@\\." ad) ;larsi@.ifi.uio
2356 (string-match "\\.$" ad) ;larsi@ifi.uio.
2357 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
2358 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
2360 "Denied posting -- the From looks strange: \"%s\"." from)
2364 (defun message-check-news-body-syntax ()
2366 ;; Check for long lines.
2367 (message-check 'long-lines
2368 (goto-char (point-min))
2370 (concat "^" (regexp-quote mail-header-separator) "$"))
2374 (< (current-column) 80))
2375 (zerop (forward-line 1))))
2379 "You have lines longer than 79 characters. Really post? ")))
2380 ;; Check whether the article is empty.
2381 (message-check 'empty
2382 (goto-char (point-min))
2384 (concat "^" (regexp-quote mail-header-separator) "$"))
2387 (goto-char (point-max))
2388 (re-search-backward message-signature-separator nil t)
2390 (or (re-search-backward "[^ \n\t]" b t)
2391 (y-or-n-p "Empty article. Really post? "))))
2392 ;; Check for control characters.
2393 (message-check 'control-chars
2394 (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t)
2396 "The article contains control characters. Really post? ")
2398 ;; Check excessive size.
2399 (message-check 'size
2400 (if (> (buffer-size) 60000)
2402 (format "The article is %d octets long. Really post? "
2405 ;; Check whether any new text has been added.
2406 (message-check 'new-text
2408 (not message-checksum)
2409 (not (and (eq (message-checksum) (car message-checksum))
2410 (eq (buffer-size) (cdr message-checksum))))
2412 "It looks like no new text has been added. Really post? ")))
2413 ;; Check the length of the signature.
2414 (message-check 'signature
2415 (goto-char (point-max))
2416 (if (or (not (re-search-backward message-signature-separator nil t))
2417 (search-forward message-forward-end-separator nil t))
2419 (if (> (count-lines (point) (point-max)) 5)
2422 "Your .sig is %d lines; it should be max 4. Really post? "
2423 (1- (count-lines (point) (point-max)))))
2426 (defun message-checksum ()
2427 "Return a \"checksum\" for the current buffer."
2430 (goto-char (point-min))
2432 (concat "^" (regexp-quote mail-header-separator) "$"))
2434 (when (not (looking-at "[ \t\n]"))
2435 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
2440 (defun message-do-fcc ()
2441 "Process Fcc headers in the current buffer."
2442 (let ((case-fold-search t)
2443 (buf (current-buffer))
2446 (set-buffer (get-buffer-create " *message temp*"))
2447 (buffer-disable-undo (current-buffer))
2449 (insert-buffer-substring buf)
2451 (message-narrow-to-headers)
2452 (while (setq file (message-fetch-field "fcc"))
2454 (message-remove-header "fcc" nil t)))
2455 (goto-char (point-min))
2456 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
2457 (replace-match "" t t)
2458 ;; Process FCC operations.
2460 (setq file (pop list))
2461 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
2462 ;; Pipe the article to the program in question.
2463 (call-process-region (point-min) (point-max) shell-file-name
2464 nil nil nil shell-command-switch
2465 (match-string 1 file))
2466 ;; Save the article.
2467 (setq file (expand-file-name file))
2468 (unless (file-exists-p (file-name-directory file))
2469 (make-directory (file-name-directory file) t))
2470 (if (and message-fcc-handler-function
2471 (not (eq message-fcc-handler-function 'rmail-output)))
2472 (funcall message-fcc-handler-function file)
2473 (if (and (file-readable-p file) (mail-file-babyl-p file))
2474 (rmail-output file 1 nil t)
2475 (let ((mail-use-rfc822 t))
2476 (rmail-output file 1 t t))))))
2478 (kill-buffer (current-buffer)))))
2480 (defun message-output (filename)
2481 "Append this article to Unix/babyl mail file.."
2482 (if (and (file-readable-p filename)
2483 (mail-file-babyl-p filename))
2484 (gnus-output-to-rmail filename t)
2485 (gnus-output-to-mail filename t)))
2487 (defun message-cleanup-headers ()
2488 "Do various automatic cleanups of the headers."
2489 ;; Remove empty lines in the header.
2491 (message-narrow-to-headers)
2492 ;; Remove blank lines.
2493 (while (re-search-forward "^[ \t]*\n" nil t)
2494 (replace-match "" t t))
2496 ;; Correct Newsgroups and Followup-To headers: Change sequence of
2497 ;; spaces to comma and eliminate spaces around commas. Eliminate
2498 ;; embedded line breaks.
2499 (goto-char (point-min))
2500 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
2504 (if (re-search-forward "^[^ \t]" nil t)
2508 (goto-char (point-min))
2509 (while (re-search-forward "\n[ \t]+" nil t)
2510 (replace-match " " t t)) ;No line breaks (too confusing)
2511 (goto-char (point-min))
2512 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
2513 (replace-match "," t t))
2514 (goto-char (point-min))
2515 ;; Remove trailing commas.
2516 (when (re-search-forward ",+$" nil t)
2517 (replace-match "" t t))))))
2519 (defun message-make-date ()
2520 "Make a valid data header."
2521 (let ((now (current-time)))
2522 (timezone-make-date-arpa-standard
2523 (current-time-string now) (current-time-zone now))))
2525 (defun message-make-message-id ()
2526 "Make a unique Message-ID."
2527 (concat "<" (message-unique-id)
2528 (let ((psubject (save-excursion (message-fetch-field "subject")))
2530 (save-excursion (message-fetch-field "supersedes"))))
2532 (and message-reply-headers
2533 (mail-header-references message-reply-headers)
2534 (mail-header-subject message-reply-headers)
2536 (mail-header-subject message-reply-headers)
2538 (message-strip-subject-re
2539 (mail-header-subject message-reply-headers))
2540 (message-strip-subject-re psubject))))
2542 (string-match "_-_@" psupersedes)))
2544 "@" (message-make-fqdn) ">"))
2546 (defvar message-unique-id-char nil)
2548 ;; If you ever change this function, make sure the new version
2549 ;; cannot generate IDs that the old version could.
2550 ;; You might for example insert a "." somewhere (not next to another dot
2551 ;; or string boundary), or modify the "fsf" string.
2552 (defun message-unique-id ()
2553 ;; Don't use microseconds from (current-time), they may be unsupported.
2554 ;; Instead we use this randomly inited counter.
2555 (setq message-unique-id-char
2556 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
2557 ;; (current-time) returns 16-bit ints,
2558 ;; and 2^16*25 just fits into 4 digits i base 36.
2560 (let ((tm (current-time)))
2562 (if (memq system-type '(ms-dos emx vax-vms))
2563 (let ((user (downcase (user-login-name))))
2564 (while (string-match "[^a-z0-9_]" user)
2565 (aset user (match-beginning 0) ?_))
2567 (message-number-base36 (user-uid) -1))
2568 (message-number-base36 (+ (car tm)
2569 (lsh (% message-unique-id-char 25) 16)) 4)
2570 (message-number-base36 (+ (nth 1 tm)
2571 (lsh (/ message-unique-id-char 25) 16)) 4)
2572 ;; Append the newsreader name, because while the generated
2573 ;; ID is unique to this newsreader, other newsreaders might
2574 ;; otherwise generate the same ID via another algorithm.
2577 (defun message-number-base36 (num len)
2582 (concat (message-number-base36 (/ num 36) (1- len))
2583 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
2586 (defun message-make-organization ()
2587 "Make an Organization header."
2588 (let* ((organization
2589 (when message-user-organization
2590 (if (message-functionp message-user-organization)
2591 (funcall message-user-organization)
2592 message-user-organization))))
2594 (message-set-work-buffer)
2595 (cond ((stringp organization)
2596 (insert organization))
2597 ((and (eq t organization)
2598 message-user-organization-file
2599 (file-exists-p message-user-organization-file))
2600 (insert-file-contents message-user-organization-file)))
2601 (goto-char (point-min))
2602 (while (re-search-forward "[\t\n]+" nil t)
2603 (replace-match "" t t))
2604 (unless (zerop (buffer-size))
2607 (defun message-make-lines ()
2608 "Count the number of lines and return numeric string."
2612 (goto-char (point-min))
2614 (concat "^" (regexp-quote mail-header-separator) "$"))
2616 (int-to-string (count-lines (point) (point-max))))))
2618 (defun message-make-in-reply-to ()
2619 "Return the In-Reply-To header for this message."
2620 (when message-reply-headers
2621 (let ((from (mail-header-from message-reply-headers))
2622 (date (mail-header-date message-reply-headers)))
2625 (string-match " *at \\| *@ \\| *(\\| *<" from)))
2626 (concat (if stop-pos (substring from 0 stop-pos) from)
2628 (if (or (not date) (string= date ""))
2629 "(unknown date)" date)
2632 (defun message-make-distribution ()
2633 "Make a Distribution header."
2634 (let ((orig-distribution (message-fetch-reply-field "distribution")))
2635 (cond ((message-functionp message-distribution-function)
2636 (funcall message-distribution-function))
2637 (t orig-distribution))))
2639 (defun message-make-expires ()
2640 "Return an Expires header based on `message-expires'."
2641 (let ((current (current-time))
2642 (future (* 1.0 message-expires 60 60 24)))
2643 ;; Add the future to current.
2644 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
2645 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
2646 ;; Return the date in the future in UT.
2647 (timezone-make-date-arpa-standard
2648 (current-time-string current) (current-time-zone current) '(0 "UT"))))
2650 (defun message-make-path ()
2652 (let ((login-name (user-login-name)))
2653 (cond ((null message-user-path)
2654 (concat (system-name) "!" login-name))
2655 ((stringp message-user-path)
2656 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
2657 (concat message-user-path "!" login-name))
2660 (defun message-make-from ()
2661 "Make a From header."
2662 (let* ((style message-from-style)
2663 (login (message-make-address))
2665 (or (and (boundp 'user-full-name)
2668 (when (string= fullname "&")
2669 (setq fullname (user-login-name)))
2671 (message-set-work-buffer)
2674 (equal fullname ""))
2676 ((or (eq style 'angles)
2677 (and (not (eq style 'parens))
2678 ;; Use angles if no quoting is needed, or if parens would
2679 ;; need quoting too.
2680 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
2681 (let ((tmp (concat fullname nil)))
2682 (while (string-match "([^()]*)" tmp)
2683 (aset tmp (match-beginning 0) ?-)
2684 (aset tmp (1- (match-end 0)) ?-))
2685 (string-match "[\\()]" tmp)))))
2687 (goto-char (point-min))
2688 ;; Look for a character that cannot appear unquoted
2689 ;; according to RFC 822.
2690 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
2691 ;; Quote fullname, escaping specials.
2692 (goto-char (point-min))
2694 (while (re-search-forward "[\"\\]" nil 1)
2695 (replace-match "\\\\\\&" t))
2697 (insert " <" login ">"))
2698 (t ; 'parens or default
2700 (let ((fullname-start (point)))
2702 (goto-char fullname-start)
2703 ;; RFC 822 says \ and nonmatching parentheses
2704 ;; must be escaped in comments.
2705 ;; Escape every instance of ()\ ...
2706 (while (re-search-forward "[()\\]" nil 1)
2707 (replace-match "\\\\\\&" t))
2708 ;; ... then undo escaping of matching parentheses,
2709 ;; including matching nested parentheses.
2710 (goto-char fullname-start)
2711 (while (re-search-forward
2712 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
2714 (replace-match "\\1(\\3)" t)
2715 (goto-char fullname-start)))
2719 (defun message-make-sender ()
2720 "Return the \"real\" user address.
2721 This function tries to ignore all user modifications, and
2722 give as trustworthy answer as possible."
2723 (concat (user-login-name) "@" (system-name)))
2725 (defun message-make-address ()
2726 "Make the address of the user."
2727 (or (message-user-mail-address)
2728 (concat (user-login-name) "@" (message-make-domain))))
2730 (defun message-user-mail-address ()
2731 "Return the pertinent part of `user-mail-address'."
2732 (when user-mail-address
2733 (if (string-match " " user-mail-address)
2734 (nth 1 (mail-extract-address-components user-mail-address))
2735 user-mail-address)))
2737 (defun message-make-fqdn ()
2738 "Return user's fully qualified domain name."
2739 (let ((system-name (system-name))
2740 (user-mail (message-user-mail-address)))
2742 ((string-match "[^.]\\.[^.]" system-name)
2743 ;; `system-name' returned the right result.
2745 ;; Try `mail-host-address'.
2746 ((and (boundp 'mail-host-address)
2747 (stringp mail-host-address)
2748 (string-match "\\." mail-host-address))
2750 ;; We try `user-mail-address' as a backup.
2752 (string-match "\\." user-mail)
2753 (string-match "@\\(.*\\)\\'" user-mail))
2754 (match-string 1 user-mail))
2755 ;; Default to this bogus thing.
2757 (concat system-name ".i-did-not-set--mail-host-address--so-shoot-me")))))
2759 (defun message-make-host-name ()
2760 "Return the name of the host."
2761 (let ((fqdn (message-make-fqdn)))
2762 (string-match "^[^.]+\\." fqdn)
2763 (substring fqdn 0 (1- (match-end 0)))))
2765 (defun message-make-domain ()
2766 "Return the domain name."
2767 (or mail-host-address
2768 (message-make-fqdn)))
2770 (defun message-generate-headers (headers)
2771 "Prepare article HEADERS.
2772 Headers already prepared in the buffer are not modified."
2774 (message-narrow-to-headers)
2775 (let* ((Date (message-make-date))
2776 (Message-ID (message-make-message-id))
2777 (Organization (message-make-organization))
2778 (From (message-make-from))
2779 (Path (message-make-path))
2782 (In-Reply-To (message-make-in-reply-to))
2784 (Distribution (message-make-distribution))
2785 (Lines (message-make-lines))
2786 (X-Newsreader message-newsreader)
2787 (X-Mailer (and (not (message-fetch-field "X-Newsreader"))
2789 (Expires (message-make-expires))
2790 (case-fold-search t)
2792 ;; First we remove any old generated headers.
2793 (let ((headers message-deletable-headers))
2794 (unless (buffer-modified-p)
2795 (setq headers (delq 'Message-ID (copy-sequence headers))))
2797 (goto-char (point-min))
2798 (and (re-search-forward
2799 (concat "^" (symbol-name (car headers)) ": *") nil t)
2800 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
2801 (message-delete-line))
2803 ;; Go through all the required headers and see if they are in the
2804 ;; articles already. If they are not, or are empty, they are
2805 ;; inserted automatically - except for Subject, Newsgroups and
2808 (goto-char (point-min))
2809 (setq elem (pop headers))
2811 (if (eq (car elem) 'optional)
2812 (setq header (cdr elem))
2813 (setq header (car elem)))
2815 (when (or (not (re-search-forward
2816 (concat "^" (downcase (symbol-name header)) ":")
2819 ;; The header was found. We insert a space after the
2820 ;; colon, if there is none.
2821 (if (/= (following-char) ? ) (insert " ") (forward-char 1))
2822 ;; Find out whether the header is empty...
2823 (looking-at "[ \t]*$")))
2824 ;; So we find out what value we should insert.
2827 ((and (consp elem) (eq (car elem) 'optional))
2828 ;; This is an optional header. If the cdr of this
2829 ;; is something that is nil, then we do not insert
2831 (setq header (cdr elem))
2832 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
2833 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
2835 ;; The element is a cons. Either the cdr is a
2836 ;; string to be inserted verbatim, or it is a
2837 ;; function, and we insert the value returned from
2839 (or (and (stringp (cdr elem)) (cdr elem))
2840 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
2841 ((and (boundp header) (symbol-value header))
2842 ;; The element is a symbol. We insert the value
2843 ;; of this symbol, if any.
2844 (symbol-value header))
2846 ;; We couldn't generate a value for this header,
2847 ;; so we just ask the user.
2848 (read-from-minibuffer
2849 (format "Empty header for %s; enter value: " header)))))
2850 ;; Finally insert the header.
2852 (not (equal value "")))
2856 ;; This header didn't exist, so we insert it.
2857 (goto-char (point-max))
2858 (insert (symbol-name header) ": " value "\n")
2860 ;; The value of this header was empty, so we clear
2861 ;; totally and insert the new value.
2862 (delete-region (point) (gnus-point-at-eol))
2864 ;; Add the deletable property to the headers that require it.
2865 (and (memq header message-deletable-headers)
2866 (progn (beginning-of-line) (looking-at "[^:]+: "))
2867 (add-text-properties
2868 (point) (match-end 0)
2869 '(message-deletable t face italic) (current-buffer)))))))
2870 ;; Insert new Sender if the From is strange.
2871 (let ((from (message-fetch-field "from"))
2872 (sender (message-fetch-field "sender"))
2873 (secure-sender (message-make-sender)))
2875 (not (message-check-element 'sender))
2878 (cadr (mail-extract-address-components from)))
2879 (downcase secure-sender)))
2884 (cadr (mail-extract-address-components sender)))
2885 (downcase secure-sender)))))
2886 (goto-char (point-min))
2887 ;; Rename any old Sender headers to Original-Sender.
2888 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
2890 (insert "Original-")
2891 (beginning-of-line))
2892 (when (or (message-news-p)
2893 (string-match "^[^@]@.+\\..+" secure-sender))
2894 (insert "Sender: " secure-sender "\n")))))))
2896 (defun message-insert-courtesy-copy ()
2897 "Insert a courtesy message in mail copies of combined messages."
2901 (message-narrow-to-headers)
2902 (when (setq newsgroups (message-fetch-field "newsgroups"))
2903 (goto-char (point-max))
2904 (insert "Posted-To: " newsgroups "\n")))
2906 (when message-courtesy-message
2908 ((string-match "%s" message-courtesy-message)
2909 (insert (format message-courtesy-message newsgroups)))
2911 (insert message-courtesy-message)))))))
2914 ;;; Setting up a message buffer
2917 (defun message-fill-address (header value)
2919 (narrow-to-region (point) (point))
2920 (insert (capitalize (symbol-name header))
2922 (if (consp value) (car value) value)
2924 (narrow-to-region (point-min) (1- (point-max)))
2926 (goto-char (point-min))
2928 (skip-chars-forward "^,\"" (point-max))
2929 (if (or (= (following-char) ?,)
2932 (if (and (> (current-column) 78)
2938 (setq last (1+ (point))))
2939 (setq last (1+ (point)))))
2940 (setq quoted (not quoted)))
2943 (goto-char (point-max))
2947 (defun message-fill-header (header value)
2948 (let ((begin (point))
2951 (insert (capitalize (symbol-name header))
2953 (if (consp value) (car value) value)
2956 (narrow-to-region begin (point))
2957 (fill-region-as-paragraph begin (point))
2958 ;; Tapdance around looong Message-IDs.
2960 (when (looking-at "[ \t]*$")
2961 (message-delete-line))
2963 (re-search-forward ":" nil t)
2964 (when (looking-at "\n[ \t]+")
2965 (replace-match " " t t))
2966 (goto-char (point-max)))))
2968 (defun message-position-point ()
2969 "Move point to where the user probably wants to find it."
2970 (message-narrow-to-headers)
2972 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
2973 (search-backward ":" )
2976 (if (= (following-char) ? )
2980 (goto-char (point-max))
2983 (unless (looking-at "$")
2987 (defun message-buffer-name (type &optional to group)
2988 "Return a new (unique) buffer name based on TYPE and TO."
2990 ;; Check whether `message-generate-new-buffers' is a function,
2991 ;; and if so, call it.
2992 ((message-functionp message-generate-new-buffers)
2993 (funcall message-generate-new-buffers type to group))
2994 ;; Generate a new buffer name The Message Way.
2995 (message-generate-new-buffers
2996 (generate-new-buffer-name
3000 (or (car (mail-extract-address-components to))
3003 (if (and group (not (string= group ""))) (concat " on " group) "")
3005 ;; Use standard name.
3007 (format "*%s message*" type))))
3009 (defun message-pop-to-buffer (name)
3010 "Pop to buffer NAME, and warn if it already exists and is modified."
3011 (let ((buffer (get-buffer name)))
3013 (buffer-name buffer))
3015 (set-buffer (pop-to-buffer buffer))
3016 (when (and (buffer-modified-p)
3018 "Message already being composed; erase? ")))
3019 (error "Message being composed")))
3020 (set-buffer (pop-to-buffer name))))
3024 (defun message-do-send-housekeeping ()
3025 "Kill old message buffers."
3026 ;; We might have sent this buffer already. Delete it from the
3028 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
3029 (while (and message-max-buffers
3031 (>= (length message-buffer-list) message-max-buffers))
3032 ;; Kill the oldest buffer -- unless it has been changed.
3033 (let ((buffer (pop message-buffer-list)))
3034 (when (and (buffer-name buffer)
3035 (not (buffer-modified-p buffer)))
3036 (kill-buffer buffer))))
3037 ;; Rename the buffer.
3038 (if message-send-rename-function
3039 (funcall message-send-rename-function)
3040 (when (string-match "\\`\\*" (buffer-name))
3042 (concat "*sent " (substring (buffer-name) (match-end 0))) t)))
3043 ;; Push the current buffer onto the list.
3044 (when message-max-buffers
3045 (setq message-buffer-list
3046 (nconc message-buffer-list (list (current-buffer))))))
3048 (defvar mc-modes-alist)
3049 (defun message-setup (headers &optional replybuffer actions)
3050 (when (and (boundp 'mc-modes-alist)
3051 (not (assq 'message-mode mc-modes-alist)))
3052 (push '(message-mode (encrypt . mc-encrypt-message)
3053 (sign . mc-sign-message))
3056 (setq message-send-actions actions))
3057 (setq message-reply-buffer replybuffer)
3058 (goto-char (point-min))
3059 ;; Insert all the headers.
3062 (alist message-header-format-alist))
3064 (unless (assq (caar h) message-header-format-alist)
3065 (push (list (caar h)) alist))
3069 (delete-region (point) (progn (forward-line -1) (point)))
3070 (when message-default-headers
3071 (insert message-default-headers)
3072 (or (bolp) (insert ?\n)))
3076 (insert mail-header-separator "\n")
3080 (when (message-news-p)
3081 (when message-default-news-headers
3082 (insert message-default-news-headers)
3083 (or (bolp) (insert ?\n)))
3084 (when message-generate-headers-first
3085 (message-generate-headers
3088 (copy-sequence message-required-news-headers))))))
3089 (when (message-mail-p)
3090 (when message-default-mail-headers
3091 (insert message-default-mail-headers)
3092 (or (bolp) (insert ?\n)))
3093 (when message-generate-headers-first
3094 (message-generate-headers
3097 (copy-sequence message-required-mail-headers))))))
3098 (run-hooks 'message-signature-setup-hook)
3099 (message-insert-signature)
3101 (message-narrow-to-headers)
3102 (run-hooks 'message-header-setup-hook))
3103 (set-buffer-modified-p nil)
3104 (setq buffer-undo-list nil)
3105 (run-hooks 'message-setup-hook)
3106 (message-position-point)
3109 (defun message-set-auto-save-file-name ()
3110 "Associate the message buffer with a file in the drafts directory."
3111 (when message-autosave-directory
3112 (setq message-draft-article (nndraft-request-associate-buffer "drafts"))
3113 (clear-visited-file-modtime)))
3115 (defun message-disassociate-draft ()
3116 "Disassociate the message buffer from the drafts directory."
3117 (when message-draft-article
3118 (nndraft-request-expire-articles
3119 (list message-draft-article) "drafts" nil t)))
3124 ;;; Commands for interfacing with message
3128 (defun message-mail (&optional to subject
3129 other-headers continue switch-function
3130 yank-action send-actions)
3131 "Start editing a mail message to be sent."
3133 (let ((message-this-is-mail t))
3134 (message-pop-to-buffer (message-buffer-name "mail" to))
3137 `((To . ,(or to "")) (Subject . ,(or subject "")))
3138 (when other-headers other-headers)))))
3141 (defun message-news (&optional newsgroups subject)
3142 "Start editing a news article to be sent."
3144 (let ((message-this-is-news t))
3145 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))
3146 (message-setup `((Newsgroups . ,(or newsgroups ""))
3147 (Subject . ,(or subject ""))))))
3150 (defun message-reply (&optional to-address wide ignore-reply-to)
3151 "Start editing a reply to the article in the current buffer."
3153 (let ((cur (current-buffer))
3154 from subject date reply-to to cc
3155 references message-id follow-to
3156 (inhibit-point-motion-hooks t)
3157 mct never-mct gnus-warning)
3159 (message-narrow-to-head)
3160 ;; Allow customizations to have their say.
3162 ;; This is a regular reply.
3163 (if (message-functionp message-reply-to-function)
3164 (setq follow-to (funcall message-reply-to-function)))
3165 ;; This is a followup.
3166 (if (message-functionp message-wide-reply-to-function)
3169 (funcall message-wide-reply-to-function)))))
3170 ;; Find all relevant headers we need.
3171 (setq from (message-fetch-field "from")
3172 date (message-fetch-field "date")
3173 subject (or (message-fetch-field "subject") "none")
3174 to (message-fetch-field "to")
3175 cc (message-fetch-field "cc")
3176 mct (message-fetch-field "mail-copies-to")
3177 reply-to (unless ignore-reply-to (message-fetch-field "reply-to"))
3178 references (message-fetch-field "references")
3179 message-id (message-fetch-field "message-id" t))
3180 ;; Remove any (buggy) Re:'s that are present and make a
3182 (when (string-match "^[ \t]*[Rr][Ee]:[ \t]*" subject)
3183 (setq subject (substring subject (match-end 0))))
3184 (setq subject (concat "Re: " subject))
3186 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
3187 (string-match "<[^>]+>" gnus-warning))
3188 (setq message-id (match-string 0 gnus-warning)))
3190 ;; Handle special values of Mail-Copies-To.
3192 (cond ((equal (downcase mct) "never")
3195 ((equal (downcase mct) "always")
3196 (setq mct (or reply-to from)))))
3202 (setq follow-to (list (cons 'To (or to-address reply-to from))))
3203 (when (and wide mct)
3204 (push (cons 'Cc mct) follow-to)))
3207 (message-set-work-buffer)
3209 (insert (or reply-to from "")))
3210 (insert (if to (concat (if (bolp) "" ", ") to "") ""))
3211 (insert (if mct (concat (if (bolp) "" ", ") mct) ""))
3212 (insert (if cc (concat (if (bolp) "" ", ") cc) ""))
3213 (goto-char (point-min))
3214 (while (re-search-forward "[ \t]+" nil t)
3215 (replace-match " " t t))
3216 ;; Remove addresses that match `rmail-dont-reply-to-names'.
3217 (insert (prog1 (rmail-dont-reply-to (buffer-string))
3219 (goto-char (point-min))
3220 ;; Perhaps Mail-Copies-To: never removed the only address?
3222 (insert (or reply-to from "")))
3226 (cons (mail-strip-quoted-names addr) addr))
3227 (message-tokenize-header (buffer-string))))
3230 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
3231 (setq follow-to (list (cons 'To (cdr (pop ccalist)))))
3233 (let ((ccs (cons 'Cc (mapconcat
3234 (lambda (addr) (cdr addr)) ccalist ", "))))
3235 (when (string-match "^ +" (cdr ccs))
3236 (setcdr ccs (substring (cdr ccs) (match-end 0))))
3237 (push ccs follow-to))))))
3240 (message-pop-to-buffer (message-buffer-name
3241 (if wide "wide reply" "reply") from
3242 (if wide to-address nil)))
3244 (setq message-reply-headers
3245 (vector 0 subject from date message-id references 0 0 ""))
3248 `((Subject . ,subject)
3250 ,@(if (or references message-id)
3251 `((References . ,(concat (or references "") (and references " ")
3252 (or message-id ""))))
3257 (defun message-wide-reply (&optional to-address ignore-reply-to)
3258 "Make a \"wide\" reply to the message in the current buffer."
3260 (message-reply to-address t ignore-reply-to))
3263 (defun message-followup (&optional to-newsgroups)
3264 "Follow up to the message in the current buffer.
3265 If TO-NEWSGROUPS, use that as the new Newsgroups line."
3267 (let ((cur (current-buffer))
3268 from subject date reply-to mct
3269 references message-id follow-to
3270 (inhibit-point-motion-hooks t)
3271 (message-this-is-news t)
3272 followup-to distribution newsgroups gnus-warning posted-to)
3275 (goto-char (point-min))
3276 (if (search-forward "\n\n" nil t)
3279 (when (message-functionp message-followup-to-function)
3281 (funcall message-followup-to-function)))
3282 (setq from (message-fetch-field "from")
3283 date (message-fetch-field "date")
3284 subject (or (message-fetch-field "subject") "none")
3285 references (message-fetch-field "references")
3286 message-id (message-fetch-field "message-id" t)
3287 followup-to (message-fetch-field "followup-to")
3288 newsgroups (message-fetch-field "newsgroups")
3289 posted-to (message-fetch-field "posted-to")
3290 reply-to (message-fetch-field "reply-to")
3291 distribution (message-fetch-field "distribution")
3292 mct (message-fetch-field "mail-copies-to"))
3293 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
3294 (string-match "<[^>]+>" gnus-warning))
3295 (setq message-id (match-string 0 gnus-warning)))
3296 ;; Remove bogus distribution.
3297 (when (and (stringp distribution)
3298 (let ((case-fold-search t))
3299 (string-match "world" distribution)))
3300 (setq distribution nil))
3301 ;; Remove any (buggy) Re:'s that are present and make a
3303 (when (string-match "^[ \t]*[Rr][Ee]:[ \t]*" subject)
3304 (setq subject (substring subject (match-end 0))))
3305 (setq subject (concat "Re: " subject))
3308 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
3311 `((Subject . ,subject)
3314 (list (cons 'Newsgroups to-newsgroups)))
3315 (follow-to follow-to)
3316 ((and followup-to message-use-followup-to)
3319 ((equal (downcase followup-to) "poster")
3320 (if (or (eq message-use-followup-to 'use)
3321 (message-y-or-n-p "Obey Followup-To: poster? " t "\
3322 You should normally obey the Followup-To: header.
3324 `Followup-To: poster' sends your response via e-mail instead of news.
3326 A typical situation where `Followup-To: poster' is used is when the poster
3327 does not read the newsgroup, so he wouldn't see any replies sent to it."))
3329 (setq message-this-is-news nil)
3330 (cons 'To (or reply-to from "")))
3331 (cons 'Newsgroups newsgroups)))
3333 (if (or (equal followup-to newsgroups)
3334 (not (eq message-use-followup-to 'ask))
3336 (concat "Obey Followup-To: " followup-to "? ") t "\
3337 You should normally obey the Followup-To: header.
3339 `Followup-To: " followup-to "'
3340 directs your response to " (if (string-match "," followup-to)
3341 "the specified newsgroups"
3342 "that newsgroup only") ".
3344 If a message is posted to several newsgroups, Followup-To is often
3345 used to direct the following discussion to one newsgroup only,
3346 because discussions that are spread over several newsgroup tend to
3347 be fragmented and very difficult to follow.
3349 Also, some source/announcement newsgroups are not indented for discussion;
3350 responses here are directed to other newsgroups."))
3351 (cons 'Newsgroups followup-to)
3352 (cons 'Newsgroups newsgroups))))))
3354 `((Newsgroups . ,posted-to)))
3356 `((Newsgroups . ,newsgroups))))
3357 ,@(and distribution (list (cons 'Distribution distribution)))
3358 ,@(if (or references message-id)
3359 `((References . ,(concat (or references "") (and references " ")
3360 (or message-id "")))))
3362 (not (equal (downcase mct) "never")))
3363 (list (cons 'Cc (if (equal (downcase mct) "always")
3364 (or reply-to from "")
3369 (setq message-reply-headers
3370 (vector 0 subject from date message-id references 0 0 ""))))
3374 (defun message-cancel-news ()
3375 "Cancel an article you posted."
3377 (unless (message-news-p)
3378 (error "This is not a news article; canceling is impossible"))
3379 (when (yes-or-no-p "Do you really want to cancel this article? ")
3380 (let (from newsgroups message-id distribution buf)
3382 ;; Get header info. from original article.
3384 (message-narrow-to-head)
3385 (setq from (message-fetch-field "from")
3386 newsgroups (message-fetch-field "newsgroups")
3387 message-id (message-fetch-field "message-id" t)
3388 distribution (message-fetch-field "distribution")))
3389 ;; Make sure that this article was written by the user.
3390 (unless (string-equal
3391 (downcase (cadr (mail-extract-address-components from)))
3392 (downcase (message-make-address)))
3393 (error "This article is not yours"))
3394 ;; Make control message.
3395 (setq buf (set-buffer (get-buffer-create " *message cancel*")))
3396 (buffer-disable-undo (current-buffer))
3398 (insert "Newsgroups: " newsgroups "\n"
3399 "From: " (message-make-from) "\n"
3400 "Subject: cmsg cancel " message-id "\n"
3401 "Control: cancel " message-id "\n"
3403 (concat "Distribution: " distribution "\n")
3405 mail-header-separator "\n"
3406 message-cancel-message)
3407 (message "Canceling your article...")
3408 (if (let ((message-syntax-checks
3409 'dont-check-for-anything-just-trust-me))
3410 (funcall message-send-news-function))
3411 (message "Canceling your article...done"))
3412 (kill-buffer buf)))))
3415 (defun message-supersede ()
3416 "Start composing a message to supersede the current message.
3417 This is done simply by taking the old article and adding a Supersedes
3418 header line with the old Message-ID."
3420 (let ((cur (current-buffer)))
3421 ;; Check whether the user owns the article that is to be superseded.
3422 (unless (string-equal
3423 (downcase (cadr (mail-extract-address-components
3424 (message-fetch-field "from"))))
3425 (downcase (message-make-address)))
3426 (error "This article is not yours"))
3427 ;; Get a normal message buffer.
3428 (message-pop-to-buffer (message-buffer-name "supersede"))
3429 (insert-buffer-substring cur)
3430 (message-narrow-to-head)
3431 ;; Remove unwanted headers.
3432 (when message-ignored-supersedes-headers
3433 (message-remove-header message-ignored-supersedes-headers t))
3434 (goto-char (point-min))
3435 (if (not (re-search-forward "^Message-ID: " nil t))
3436 (error "No Message-ID in this article")
3437 (replace-match "Supersedes: " t t))
3438 (goto-char (point-max))
3439 (insert mail-header-separator)
3444 (defun message-recover ()
3445 "Reread contents of current buffer from its last auto-save file."
3447 (let ((file-name (make-auto-save-file-name)))
3448 (cond ((save-window-excursion
3449 (if (not (eq system-type 'vax-vms))
3450 (with-output-to-temp-buffer "*Directory*"
3451 (buffer-disable-undo standard-output)
3452 (let ((default-directory "/"))
3454 "ls" nil standard-output nil "-l" file-name))))
3455 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
3456 (let ((buffer-read-only nil))
3458 (insert-file-contents file-name nil)))
3459 (t (error "message-recover cancelled")))))
3461 ;;; Forwarding messages.
3463 (defun message-make-forward-subject ()
3464 "Return a Subject header suitable for the message in the current buffer."
3468 (message-narrow-to-head)
3469 (concat "[" (or (message-fetch-field
3470 (if (message-news-p) "newsgroups" "from"))
3472 "] " (or (message-fetch-field "Subject") "")))))
3475 (defun message-forward (&optional news)
3476 "Forward the current message via mail.
3477 Optional NEWS will use news to forward instead of mail."
3479 (let ((cur (current-buffer))
3480 (subject (message-make-forward-subject))
3482 (if news (message-news nil subject) (message-mail nil subject))
3483 ;; Put point where we want it before inserting the forwarded
3485 (if message-signature-before-forwarded-message
3486 (goto-char (point-max))
3487 (message-goto-body))
3488 ;; Make sure we're at the start of the line.
3491 ;; Narrow to the area we are to insert.
3492 (narrow-to-region (point) (point))
3493 ;; Insert the separators and the forwarded buffer.
3494 (insert message-forward-start-separator)
3495 (setq art-beg (point))
3496 (insert-buffer-substring cur)
3497 (goto-char (point-max))
3498 (insert message-forward-end-separator)
3499 (set-text-properties (point-min) (point-max) nil)
3500 ;; Remove all unwanted headers.
3502 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
3505 (goto-char (point-min))
3506 (message-remove-header message-included-forward-headers t nil t)
3508 (message-position-point)))
3511 (defun message-resend (address)
3512 "Resend the current article to ADDRESS."
3513 (interactive "sResend message to: ")
3514 (message "Resending message to %s..." address)
3516 (let ((cur (current-buffer))
3518 ;; We first set up a normal mail buffer.
3519 (set-buffer (get-buffer-create " *message resend*"))
3520 (buffer-disable-undo (current-buffer))
3522 (message-setup `((To . ,address)))
3523 ;; Insert our usual headers.
3524 (message-generate-headers '(From Date To))
3525 (message-narrow-to-headers)
3526 ;; Rename them all to "Resent-*".
3527 (while (re-search-forward "^[A-Za-z]" nil t)
3532 (delete-region (point) (point-max))
3534 ;; Insert the message to be resent.
3535 (insert-buffer-substring cur)
3536 (goto-char (point-min))
3537 (search-forward "\n\n")
3540 (narrow-to-region beg (point))
3541 (message-remove-header message-ignored-resent-headers t)
3542 (goto-char (point-max)))
3543 (insert mail-header-separator)
3544 ;; Rename all old ("Also-")Resent headers.
3545 (while (re-search-backward "^\\(Also-\\)?Resent-" beg t)
3548 ;; Quote any "From " lines at the beginning.
3550 (when (looking-at "From ")
3551 (replace-match "X-From-Line: "))
3554 (kill-buffer (current-buffer)))
3555 (message "Resending message to %s...done" address)))
3558 (defun message-bounce ()
3559 "Re-mail the current message.
3560 This only makes sense if the current message is a bounce message than
3561 contains some mail you have written which has been bounced back to
3564 (let ((cur (current-buffer))
3566 (message-pop-to-buffer (message-buffer-name "bounce"))
3567 (insert-buffer-substring cur)
3569 (message-narrow-to-head)
3570 (if (and (message-fetch-field "Mime-Version")
3571 (setq boundary (message-fetch-field "Content-Type")))
3572 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary)
3573 (setq boundary (concat (match-string 1 boundary) " *\n"
3574 "Content-Type: message/rfc822"))
3575 (setq boundary nil)))
3577 (goto-char (point-min))
3578 (search-forward "\n\n" nil t)
3580 (re-search-forward boundary nil t)
3582 (and (re-search-forward message-unsent-separator nil t)
3584 (re-search-forward "^Return-Path:.*\n" nil t))
3585 ;; We remove everything before the bounced mail.
3588 (if (re-search-forward "^[^ \n\t]+:" nil t)
3592 (message-narrow-to-head)
3593 (message-remove-header message-ignored-bounced-headers t)
3594 (goto-char (point-max))
3595 (insert mail-header-separator))
3596 (message-position-point)))
3599 ;;; Interactive entry points for new message buffers.
3603 (defun message-mail-other-window (&optional to subject)
3604 "Like `message-mail' command, but display mail buffer in another window."
3606 (let ((pop-up-windows t)
3607 (special-display-buffer-names nil)
3608 (special-display-regexps nil)
3609 (same-window-buffer-names nil)
3610 (same-window-regexps nil))
3611 (message-pop-to-buffer (message-buffer-name "mail" to)))
3612 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))))
3615 (defun message-mail-other-frame (&optional to subject)
3616 "Like `message-mail' command, but display mail buffer in another frame."
3618 (let ((pop-up-frames t)
3619 (special-display-buffer-names nil)
3620 (special-display-regexps nil)
3621 (same-window-buffer-names nil)
3622 (same-window-regexps nil))
3623 (message-pop-to-buffer (message-buffer-name "mail" to)))
3624 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))))
3627 (defun message-news-other-window (&optional newsgroups subject)
3628 "Start editing a news article to be sent."
3630 (let ((pop-up-windows t)
3631 (special-display-buffer-names nil)
3632 (special-display-regexps nil)
3633 (same-window-buffer-names nil)
3634 (same-window-regexps nil))
3635 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
3636 (message-setup `((Newsgroups . ,(or newsgroups ""))
3637 (Subject . ,(or subject "")))))
3640 (defun message-news-other-frame (&optional newsgroups subject)
3641 "Start editing a news article to be sent."
3643 (let ((pop-up-frames t)
3644 (special-display-buffer-names nil)
3645 (special-display-regexps nil)
3646 (same-window-buffer-names nil)
3647 (same-window-regexps nil))
3648 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
3649 (message-setup `((Newsgroups . ,(or newsgroups ""))
3650 (Subject . ,(or subject "")))))
3654 ;; This code should be moved to underline.el (from which it is stolen).
3657 (defun bold-region (start end)
3658 "Bold all nonblank characters in the region.
3659 Works by overstriking characters.
3660 Called from program, takes two arguments START and END
3661 which specify the range to operate on."
3664 (let ((end1 (make-marker)))
3665 (move-marker end1 (max start end))
3666 (goto-char (min start end))
3667 (while (< (point) end1)
3668 (or (looking-at "[_\^@- ]")
3669 (insert (following-char) "\b"))
3670 (forward-char 1)))))
3673 (defun unbold-region (start end)
3674 "Remove all boldness (overstruck characters) in the region.
3675 Called from program, takes two arguments START and END
3676 which specify the range to operate on."
3679 (let ((end1 (make-marker)))
3680 (move-marker end1 (max start end))
3681 (goto-char (min start end))
3682 (while (re-search-forward "\b" end1 t)
3683 (if (eq (following-char) (char-after (- (point) 2)))
3684 (delete-char -2))))))
3686 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
3688 ;; Support for toolbar
3689 (when (string-match "XEmacs\\|Lucid" emacs-version)
3690 (require 'messagexmas))
3692 ;;; Group name completion.
3694 (defvar message-newgroups-header-regexp
3695 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
3696 "Regexp that match headers that lists groups.")
3698 (defun message-tab ()
3699 "Expand group names in Newsgroups and Followup-To headers.
3700 Do a `tab-to-tab-stop' if not in those headers."
3702 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp))
3703 (mail-abbrev-in-expansion-header-p))
3704 (message-expand-group)
3707 (defvar gnus-active-hashtb)
3708 (defun message-expand-group ()
3709 "Expand the group name under point." (let* ((b (save-excursion
3714 (skip-chars-forward "^:")
3717 (skip-chars-backward "^, \t\n") (point))))
3718 (completion-ignore-case t)
3719 (string (buffer-substring b (point)))
3720 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
3721 (completions (all-completions string hashtb))
3722 (cur (current-buffer))
3724 (delete-region b (point))
3726 ((= (length completions) 1)
3727 (if (string= (car completions) string)
3730 (message "Only matching group"))
3731 (insert (car completions))))
3732 ((and (setq comp (try-completion string hashtb))
3733 (not (string= comp string)))
3738 (message "No matching groups")
3739 (save-selected-window
3740 (pop-to-buffer "*Completions*")
3741 (buffer-disable-undo (current-buffer))
3742 (let ((buffer-read-only nil))
3744 (let ((standard-output (current-buffer)))
3745 (display-completion-list (sort completions 'string<)))
3746 (goto-char (point-min))
3747 (delete-region (point) (progn (forward-line 3) (point))))))))))
3751 (defun message-talkative-question (ask question show &rest text)
3752 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
3753 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
3754 The following arguments may contain lists of values."
3756 (setq text (message-flatten-list text)))
3757 (save-window-excursion
3759 (with-output-to-temp-buffer " *MESSAGE information message*"
3760 (set-buffer " *MESSAGE information message*")
3761 (mapcar 'princ text)
3762 (goto-char (point-min))))
3763 (funcall ask question))
3764 (funcall ask question)))
3766 (defun message-flatten-list (list)
3767 "Return a new, flat list that contains all elements of LIST.
3769 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
3772 (apply 'append (mapcar 'message-flatten-list list)))
3776 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
3777 "Create and return a buffer with a name based on NAME using generate-new-buffer.
3778 Then clone the local variables and values from the old buffer to the
3779 new one, cloning only the locals having a substring matching the
3781 (let ((oldbuf (current-buffer)))
3783 (set-buffer (generate-new-buffer name))
3784 (message-clone-locals oldbuf)
3787 (defun message-clone-locals (buffer)
3788 "Clone the local variables from BUFFER to the current buffer."
3789 (let ((locals (save-excursion
3791 (buffer-local-variables)))
3792 (regexp "^gnus\\|^nn\\|^message"))
3795 (when (and (consp local)
3797 (string-match regexp (symbol-name (car local))))
3799 (set (make-local-variable (car local))
3803 ;;; Miscellaneous functions
3805 ;; stolen (and renamed) from nnheader.el
3806 (defun message-replace-chars-in-string (string from to)
3807 "Replace characters in STRING from FROM to TO."
3808 (let ((string (substring string 0)) ;Copy string.
3809 (len (length string))
3811 ;; Replace all occurrences of FROM with TO.
3813 (when (= (aref string idx) from)
3814 (aset string idx to))
3815 (setq idx (1+ idx)))
3818 (run-hooks 'message-load-hook)
3822 ;;; message.el ends here