1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
5 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: mail, news, MIME
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; This mode provides mail-sending facilities from within Emacs. It
28 ;; consists mainly of large chunks of code from the sendmail.el,
29 ;; gnus-msg.el and rnewspost.el files.
43 (if (string-match "XEmacs\\|Lucid" emacs-version)
44 (require 'mail-abbrevs)
45 (require 'mailabbrev))
48 (defgroup message '((user-mail-address custom-variable)
49 (user-full-name custom-variable))
50 "Mail and news message composing."
51 :link '(custom-manual "(message)Top")
55 (put 'user-mail-address 'custom-type 'string)
56 (put 'user-full-name 'custom-type 'string)
58 (defgroup message-various nil
59 "Various Message Variables"
60 :link '(custom-manual "(message)Various Message Variables")
63 (defgroup message-buffers nil
65 :link '(custom-manual "(message)Message Buffers")
68 (defgroup message-sending nil
70 :link '(custom-manual "(message)Sending Variables")
73 (defgroup message-interface nil
75 :link '(custom-manual "(message)Interface")
78 (defgroup message-forwarding nil
80 :link '(custom-manual "(message)Forwarding")
81 :group 'message-interface)
83 (defgroup message-insertion nil
85 :link '(custom-manual "(message)Insertion")
88 (defgroup message-headers nil
90 :link '(custom-manual "(message)Message Headers")
93 (defgroup message-news nil
94 "Composing News Messages"
97 (defgroup message-mail nil
98 "Composing Mail Messages"
101 (defgroup message-faces nil
102 "Faces used for message composing."
106 (defcustom message-directory "~/Mail/"
107 "*Directory from which all other mail file variables are derived."
108 :group 'message-various
111 (defcustom message-max-buffers 10
112 "*How many buffers to keep before starting to kill them off."
113 :group 'message-buffers
116 (defcustom message-send-rename-function nil
117 "Function called to rename the buffer after sending it."
118 :group 'message-buffers
121 (defcustom message-fcc-handler-function 'message-output
122 "*A function called to save outgoing articles.
123 This function will be called with the name of the file to store the
124 article in. The default function is `message-output' which saves in Unix
126 :type '(radio (function-item message-output)
127 (function :tag "Other"))
128 :group 'message-sending)
130 (defcustom message-encode-function 'message-maybe-encode
131 "*A function called to encode messages."
132 :group 'message-sending
135 (defcustom message-courtesy-message
136 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
137 "*This is inserted at the start of a mailed copy of a posted message.
138 If the string contains the format spec \"%s\", the Newsgroups
139 the article has been posted to will be inserted there.
140 If this variable is nil, no such courtesy message will be added."
141 :group 'message-sending
144 (defcustom message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):"
145 "*Regexp that matches headers to be removed in resent bounced mail."
146 :group 'message-interface
150 (defcustom message-from-style 'default
151 "*Specifies how \"From\" headers look.
153 If `nil', they contain just the return address like:
155 If `parens', they look like:
156 king@grassland.com (Elvis Parsley)
157 If `angles', they look like:
158 Elvis Parsley <king@grassland.com>
160 Otherwise, most addresses look like `angles', but they look like
161 `parens' if `angles' would need quoting and `parens' would not."
162 :type '(choice (const :tag "simple" nil)
166 :group 'message-headers)
168 (defcustom message-syntax-checks nil
169 ; Guess this one shouldn't be easy to customize...
170 "*Controls what syntax checks should not be performed on outgoing posts.
171 To disable checking of long signatures, for instance, add
172 `(signature . disabled)' to this list.
174 Don't touch this variable unless you really know what you're doing.
176 Checks include subject-cmsg multiple-headers sendsys message-id from
177 long-lines control-chars size new-text redirected-followup signature
178 approved sender empty empty-headers message-id from subject
179 shorten-followup-to existing-newsgroups buffer-file-name unchanged."
180 :group 'message-news)
182 (defcustom message-required-news-headers
183 '(From Newsgroups Subject Date Message-ID
184 (optional . Organization) Lines
185 (optional . X-Newsreader))
186 "*Headers to be generated or prompted for when posting an article.
187 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
188 Message-ID. Organization, Lines, In-Reply-To, Expires, and
189 X-Newsreader are optional. If don't you want message to insert some
190 header, remove it from this list."
192 :group 'message-headers
193 :type '(repeat sexp))
195 (defcustom message-required-mail-headers
196 '(From Subject Date (optional . In-Reply-To) Message-ID Lines
197 (optional . X-Mailer))
198 "*Headers to be generated or prompted for when mailing a message.
199 RFC822 required that From, Date, To, Subject and Message-ID be
200 included. Organization, Lines and X-Mailer are optional."
202 :group 'message-headers
203 :type '(repeat sexp))
205 (defcustom message-deletable-headers '(Message-ID Date Lines)
206 "Headers to be deleted if they already exist and were generated by message previously."
207 :group 'message-headers
210 (defcustom message-ignored-news-headers
211 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:"
212 "*Regexp of headers to be removed unconditionally before posting."
214 :group 'message-headers
217 (defcustom message-ignored-mail-headers "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:"
218 "*Regexp of headers to be removed unconditionally before mailing."
220 :group 'message-headers
223 (defcustom message-ignored-supersedes-headers "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|^X-Trace:\\|^X-Complaints-To:\\|Return-Path:\\|^Supersedes:"
224 "*Header lines matching this regexp will be deleted before posting.
225 It's best to delete old Path and Date headers before posting to avoid
227 :group 'message-interface
231 (defcustom message-signature-separator "^-- *$"
232 "Regexp matching the signature separator."
234 :group 'message-various)
236 (defcustom message-elide-elipsis "\n[...]\n\n"
237 "*The string which is inserted for elided text."
239 :group 'message-various)
241 (defcustom message-interactive nil
242 "Non-nil means when sending a message wait for and display errors.
243 nil means let mailer mail back a message to report errors."
244 :group 'message-sending
248 (defcustom message-generate-new-buffers t
249 "*Non-nil means that a new message buffer will be created whenever `mail-setup' is called.
250 If this is a function, call that function with three parameters: The type,
251 the to address and the group name. (Any of these may be nil.) The function
252 should return the new buffer name."
253 :group 'message-buffers
254 :type '(choice (const :tag "off" nil)
258 (defcustom message-kill-buffer-on-exit nil
259 "*Non-nil means that the message buffer will be killed after sending a message."
260 :group 'message-buffers
263 (defvar gnus-local-organization)
264 (defcustom message-user-organization
265 (or (and (boundp 'gnus-local-organization)
266 (stringp gnus-local-organization)
267 gnus-local-organization)
268 (getenv "ORGANIZATION")
270 "*String to be used as an Organization header.
271 If t, use `message-user-organization-file'."
272 :group 'message-headers
273 :type '(choice string
274 (const :tag "consult file" t)))
277 (defcustom message-user-organization-file "/usr/lib/news/organization"
278 "*Local news organization file."
280 :group 'message-headers)
282 (defcustom message-autosave-directory
283 (nnheader-concat message-directory "drafts/")
284 "*Directory where Message autosaves buffers.
285 If nil, Message won't autosave."
286 :group 'message-buffers
289 (defcustom message-forward-start-separator
290 (concat (mime-make-tag "message" "rfc822") "\n")
291 "*Delimiter inserted before forwarded messages."
292 :group 'message-forwarding
295 (defcustom message-forward-end-separator
297 "*Delimiter inserted after forwarded messages."
298 :group 'message-forwarding
301 (defcustom message-signature-before-forwarded-message t
302 "*If non-nil, put the signature before any included forwarded message."
303 :group 'message-forwarding
306 (defcustom message-included-forward-headers
307 "^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:"
308 "*Regexp matching headers to be included in forwarded messages."
309 :group 'message-forwarding
312 (defcustom message-ignored-resent-headers "^Return-receipt"
313 "*All headers that match this regexp will be deleted when resending a message."
314 :group 'message-interface
317 (defcustom message-ignored-cited-headers "."
318 "*Delete these headers from the messages you yank."
319 :group 'message-insertion
322 (defcustom message-cancel-message "I am canceling my own article."
323 "Message to be inserted in the cancel message."
324 :group 'message-interface
327 ;; Useful to set in site-init.el
329 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
330 "Function to call to send the current buffer as mail.
331 The headers should be delimited by a line whose contents match the
332 variable `mail-header-separator'.
334 Legal values include `message-send-mail-with-sendmail' (the default),
335 `message-send-mail-with-mh', `message-send-mail-with-qmail' and
336 `message-send-mail-with-smtp'."
337 :type '(radio (function-item message-send-mail-with-sendmail)
338 (function-item message-send-mail-with-mh)
339 (function-item message-send-mail-with-qmail)
340 (function-item message-send-mail-with-smtp)
341 (function :tag "Other"))
342 :group 'message-sending
343 :group 'message-mail)
345 ;; 1997-09-29 by MORIOKA Tomohiko
346 (defcustom message-send-news-function 'message-send-news-with-gnus
347 "Function to call to send the current buffer as news.
348 The headers should be delimited by a line whose contents match the
349 variable `mail-header-separator'."
350 :group 'message-sending
354 (defcustom message-reply-to-function nil
355 "Function that should return a list of headers.
356 This function should pick out addresses from the To, Cc, and From headers
357 and respond with new To and Cc headers."
358 :group 'message-interface
361 (defcustom message-wide-reply-to-function nil
362 "Function that should return a list of headers.
363 This function should pick out addresses from the To, Cc, and From headers
364 and respond with new To and Cc headers."
365 :group 'message-interface
368 (defcustom message-followup-to-function nil
369 "Function that should return a list of headers.
370 This function should pick out addresses from the To, Cc, and From headers
371 and respond with new To and Cc headers."
372 :group 'message-interface
375 (defcustom message-use-followup-to 'ask
376 "*Specifies what to do with Followup-To header.
377 If nil, always ignore the header. If it is t, use its value, but
378 query before using the \"poster\" value. If it is the symbol `ask',
379 always query the user whether to use the value. If it is the symbol
380 `use', always use the value."
381 :group 'message-interface
382 :type '(choice (const :tag "ignore" nil)
386 ;; stuff relating to broken sendmail in MMDF
387 (defcustom message-sendmail-f-is-evil nil
388 "*Non-nil means that \"-f username\" should not be added to the sendmail
389 command line, because it is even more evil than leaving it out."
390 :group 'message-sending
393 ;; qmail-related stuff
394 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
395 "Location of the qmail-inject program."
396 :group 'message-sending
399 (defcustom message-qmail-inject-args nil
400 "Arguments passed to qmail-inject programs.
401 This should be a list of strings, one string for each argument.
403 For e.g., if you wish to set the envelope sender address so that bounces
404 go to the right place or to deal with listserv's usage of that address, you
405 might set this variable to '(\"-f\" \"you@some.where\")."
406 :group 'message-sending
407 :type '(repeat string))
409 (defvar gnus-post-method)
410 (defvar gnus-select-method)
411 (defcustom message-post-method
412 (cond ((and (boundp 'gnus-post-method)
415 ((boundp 'gnus-select-method)
418 "*Method used to post news."
420 :group 'message-sending
421 ;; This should be the `gnus-select-method' widget, but that might
422 ;; create a dependence to `gnus.el'.
425 (defcustom message-generate-headers-first nil
426 "*If non-nil, generate all possible headers before composing."
427 :group 'message-headers
430 (defcustom message-setup-hook
431 '(message-maybe-setup-default-charset turn-on-mime-edit)
432 "Normal hook, run each time a new outgoing message is initialized.
433 The function `message-setup' runs this hook."
434 :group 'message-various
437 (defcustom message-signature-setup-hook nil
438 "Normal hook, run each time a new outgoing message is initialized.
439 It is run after the headers have been inserted and before
440 the signature is inserted."
441 :group 'message-various
444 (defcustom message-mode-hook nil
445 "Hook run in message mode buffers."
446 :group 'message-various
449 (defcustom message-header-hook '(eword-encode-header)
450 "Hook run in a message mode buffer narrowed to the headers."
451 :group 'message-various
454 (defcustom message-header-setup-hook nil
455 "Hook called narrowed to the headers when setting up a message
457 :group 'message-various
461 (defcustom message-citation-line-function 'message-insert-citation-line
462 "*Function called to insert the \"Whomever writes:\" line."
464 :group 'message-insertion)
467 (defcustom message-yank-prefix "> "
468 "*Prefix inserted on the lines of yanked messages.
469 nil means use indentation."
471 :group 'message-insertion)
473 (defcustom message-indentation-spaces 3
474 "*Number of spaces to insert at the beginning of each cited line.
475 Used by `message-yank-original' via `message-yank-cite'."
476 :group 'message-insertion
480 (defcustom message-cite-function
481 (if (and (boundp 'mail-citation-hook)
484 'message-cite-original)
485 "*Function for citing an original message.
486 Pre-defined functions include `message-cite-original' and
487 `message-cite-original-without-signature'."
488 :type '(radio (function-item message-cite-original)
489 (function-item message-cite-original-without-signature)
490 (function-item sc-cite-original)
491 (function :tag "Other"))
492 :group 'message-insertion)
495 (defcustom message-indent-citation-function 'message-indent-citation
496 "*Function for modifying a citation just inserted in the mail buffer.
497 This can also be a list of functions. Each function can find the
498 citation between (point) and (mark t). And each function should leave
499 point and mark around the citation text as modified."
501 :group 'message-insertion)
503 (defvar message-abbrevs-loaded nil)
506 (defcustom message-signature t
507 "*String to be inserted at the end of the message buffer.
508 If t, the `message-signature-file' file will be inserted instead.
509 If a function, the result from the function will be used instead.
510 If a form, the result from the form will be used instead."
512 :group 'message-insertion)
515 (defcustom message-signature-file "~/.signature"
516 "*File containing the text inserted at end of message buffer."
518 :group 'message-insertion)
520 (defcustom message-distribution-function nil
521 "*Function called to return a Distribution header."
523 :group 'message-headers
526 (defcustom message-expires 14
527 "Number of days before your article expires."
529 :group 'message-headers
530 :link '(custom-manual "(message)News Headers")
533 (defcustom message-user-path nil
534 "If nil, use the NNTP server name in the Path header.
535 If stringp, use this; if non-nil, use no host name (user name only)."
537 :group 'message-headers
538 :link '(custom-manual "(message)News Headers")
539 :type '(choice (const :tag "nntp" nil)
541 (sexp :tag "none" :format "%t" t)))
543 (defvar message-reply-buffer nil)
544 (defvar message-reply-headers nil)
545 (defvar message-newsreader nil)
546 (defvar message-mailer nil)
547 (defvar message-sent-message-via nil)
548 (defvar message-checksum nil)
549 (defvar message-send-actions nil
550 "A list of actions to be performed upon successful sending of a message.")
551 (defvar message-exit-actions nil
552 "A list of actions to be performed upon exiting after sending a message.")
553 (defvar message-kill-actions nil
554 "A list of actions to be performed before killing a message buffer.")
555 (defvar message-postpone-actions nil
556 "A list of actions to be performed after postponing a message.")
558 (define-widget 'message-header-lines 'text
559 "All header lines must be LFD terminated."
561 :error "All header lines must be newline terminated")
563 (defcustom message-default-headers ""
564 "*A string containing header lines to be inserted in outgoing messages.
565 It is inserted before you edit the message, so you can edit or delete
567 :group 'message-headers
568 :type 'message-header-lines)
570 (defcustom message-default-mail-headers ""
571 "*A string of header lines to be inserted in outgoing mails."
572 :group 'message-headers
574 :type 'message-header-lines)
576 (defcustom message-default-news-headers ""
577 "*A string of header lines to be inserted in outgoing news
579 :group 'message-headers
581 :type 'message-header-lines)
583 ;; Note: could use /usr/ucb/mail instead of sendmail;
584 ;; options -t, and -v if not interactive.
585 (defcustom message-mailer-swallows-blank-line
586 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
587 system-configuration)
588 (file-readable-p "/etc/sendmail.cf")
589 (let ((buffer (get-buffer-create " *temp*")))
593 (insert-file-contents "/etc/sendmail.cf")
594 (goto-char (point-min))
595 (let ((case-fold-search nil))
596 (re-search-forward "^OR\\>" nil t)))
597 (kill-buffer buffer))))
598 ;; According to RFC822, "The field-name must be composed of printable
599 ;; ASCII characters (i. e., characters that have decimal values between
600 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
602 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
603 "*Set this non-nil if the system's mailer runs the header and body together.
604 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
605 The value should be an expression to test whether the problem will
607 :group 'message-sending
610 ;; Ignore errors in case this is used in Emacs 19.
611 ;; Don't use ignore-errors because this is copied into loaddefs.el.
614 (define-mail-user-agent 'message-user-agent
615 'message-mail 'message-send-and-exit
616 'message-kill-buffer 'message-send-hook)
619 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
620 "If non-nil, delete the deletable headers before feeding to mh.")
622 (defvar message-send-method-alist
623 '((news message-news-p message-send-via-news)
624 (mail message-mail-p message-send-via-mail))
625 "Alist of ways to send outgoing messages.
626 Each element has the form
628 \(TYPE PREDICATE FUNCTION)
630 where TYPE is a symbol that names the method; PREDICATE is a function
631 called without any parameters to determine whether the message is
632 a message of type TYPE; and FUNCTION is a function to be called if
633 PREDICATE returns non-nil. FUNCTION is called with one parameter --
636 (defvar message-mail-alias-type 'abbrev
637 "*What alias expansion type to use in Message buffers.
638 The default is `abbrev', which uses mailabbrev. nil switches
641 ;;; Internal variables.
642 ;;; Well, not really internal.
644 (defvar message-mode-syntax-table
645 (let ((table (copy-syntax-table text-mode-syntax-table)))
646 (modify-syntax-entry ?% ". " table)
648 "Syntax table used while in Message mode.")
650 (defvar message-mode-abbrev-table text-mode-abbrev-table
651 "Abbrev table used in Message mode buffers.
652 Defaults to `text-mode-abbrev-table'.")
653 (defgroup message-headers nil
655 :link '(custom-manual "(message)Variables")
658 (defface message-header-to-face
661 (:foreground "green2" :bold t))
664 (:foreground "MidnightBlue" :bold t))
666 (:bold t :italic t)))
667 "Face used for displaying From headers."
668 :group 'message-faces)
670 (defface message-header-cc-face
673 (:foreground "green4" :bold t))
676 (:foreground "MidnightBlue"))
679 "Face used for displaying Cc headers."
680 :group 'message-faces)
682 (defface message-header-subject-face
685 (:foreground "green3"))
688 (:foreground "navy blue" :bold t))
691 "Face used for displaying subject headers."
692 :group 'message-faces)
694 (defface message-header-newsgroups-face
697 (:foreground "yellow" :bold t :italic t))
700 (:foreground "blue4" :bold t :italic t))
702 (:bold t :italic t)))
703 "Face used for displaying newsgroups headers."
704 :group 'message-faces)
706 (defface message-header-other-face
709 (:foreground "#b00000"))
712 (:foreground "steel blue"))
714 (:bold t :italic t)))
715 "Face used for displaying newsgroups headers."
716 :group 'message-faces)
718 (defface message-header-name-face
721 (:foreground "DarkGreen"))
724 (:foreground "cornflower blue"))
727 "Face used for displaying header names."
728 :group 'message-faces)
730 (defface message-header-xheader-face
733 (:foreground "blue"))
736 (:foreground "blue"))
739 "Face used for displaying X-Header headers."
740 :group 'message-faces)
742 (defface message-separator-face
745 (:foreground "blue3"))
748 (:foreground "brown"))
751 "Face used for displaying the separator."
752 :group 'message-faces)
754 (defface message-cited-text-face
763 "Face used for displaying cited text names."
764 :group 'message-faces)
766 (defvar message-font-lock-keywords
767 (let* ((cite-prefix "A-Za-z")
768 (cite-suffix (concat cite-prefix "0-9_.@-"))
769 (content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)"))
770 `((,(concat "^\\([Tt]o:\\)" content)
771 (1 'message-header-name-face)
772 (2 'message-header-to-face nil t))
773 (,(concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content)
774 (1 'message-header-name-face)
775 (2 'message-header-cc-face nil t))
776 (,(concat "^\\([Ss]ubject:\\)" content)
777 (1 'message-header-name-face)
778 (2 'message-header-subject-face nil t))
779 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content)
780 (1 'message-header-name-face)
781 (2 'message-header-newsgroups-face nil t))
782 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content)
783 (1 'message-header-name-face)
784 (2 'message-header-other-face nil t))
785 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content)
786 (1 'message-header-name-face)
787 (2 'message-header-name-face))
788 (,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
789 1 'message-separator-face)
791 "\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
793 (0 'message-cited-text-face))))
794 "Additional expressions to highlight in Message mode.")
796 ;; XEmacs does it like this. For Emacs, we have to set the
797 ;; `font-lock-defaults' buffer-local variable.
798 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
800 (defvar message-face-alist
801 '((bold . bold-region)
802 (underline . underline-region)
803 (default . (lambda (b e)
805 (ununderline-region b e))))
806 "Alist of mail and news faces for facemenu.
807 The cdr of ech entry is a function for applying the face to a region.")
809 (defcustom message-send-hook nil
810 "Hook run before sending messages."
811 :group 'message-various
812 :options '(ispell-message)
815 (defcustom message-send-mail-hook nil
816 "Hook run before sending mail messages."
817 :group 'message-various
820 (defcustom message-send-news-hook nil
821 "Hook run before sending news messages."
822 :group 'message-various
825 (defcustom message-sent-hook nil
826 "Hook run after sending messages."
827 :group 'message-various
830 ;;; Internal variables.
832 (defvar message-buffer-list nil)
833 (defvar message-this-is-news nil)
834 (defvar message-this-is-mail nil)
835 (defvar message-draft-article nil)
837 ;; Byte-compiler warning
838 (defvar gnus-active-hashtb)
839 (defvar gnus-read-active-file)
841 ;;; Regexp matching the delimiter of messages in UNIX mail format
842 ;;; (UNIX From lines), minus the initial ^. It should be a copy
843 ;;; of rmail.el's rmail-unix-mail-delimiter.
844 (defvar message-unix-mail-delimiter
845 (let ((time-zone-regexp
846 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
847 "\\|[-+]?[0-9][0-9][0-9][0-9]"
853 ;; Many things can happen to an RFC 822 mailbox before it is put into
854 ;; a `From' line. The leading phrase can be stripped, e.g.
855 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
856 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
857 ;; can be removed, e.g.
858 ;; From: joe@y.z (Joe K
860 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
863 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
864 ;; The mailbox can be removed or be replaced by white space, e.g.
865 ;; From: "Joe User"{space}{tab}
867 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
868 ;; where {space} and {tab} represent the Ascii space and tab characters.
869 ;; We want to match the results of any of these manglings.
870 ;; The following regexp rejects names whose first characters are
871 ;; obviously bogus, but after that anything goes.
872 "\\([^\0-\b\n-\r\^?].*\\)? "
874 ;; The time the message was sent.
875 "\\([^\0-\r \^?]+\\) +" ; day of the week
876 "\\([^\0-\r \^?]+\\) +" ; month
877 "\\([0-3]?[0-9]\\) +" ; day of month
878 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
880 ;; Perhaps a time zone, specified by an abbreviation, or by a
885 " \\([0-9][0-9]+\\) *"
887 ;; On some systems the time zone can appear after the year, too.
891 "\\(remote from .*\\)?"
894 "Regexp matching the delimiter of messages in UNIX mail format.")
896 (defvar message-unsent-separator
897 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
898 "^ *---+ +Returned message +---+ *$\\|"
899 "^Start of returned message$\\|"
900 "^ *---+ +Original message +---+ *$\\|"
901 "^ *--+ +begin message +--+ *$\\|"
902 "^ *---+ +Original message follows +---+ *$\\|"
903 "^|? *---+ +Message text follows: +---+ *|?$")
904 "A regexp that matches the separator before the text of a failed message.")
906 (defvar message-header-format-alist
908 (To . message-fill-address)
909 (Cc . message-fill-address)
920 (References . message-fill-references)
923 "Alist used for formatting headers.")
926 (autoload 'message-setup-toolbar "messagexmas")
927 (autoload 'mh-new-draft-name "mh-comp")
928 (autoload 'mh-send-letter "mh-comp")
929 (autoload 'gnus-point-at-eol "gnus-util")
930 (autoload 'gnus-point-at-bol "gnus-util")
931 (autoload 'gnus-output-to-mail "gnus-util")
932 (autoload 'gnus-output-to-rmail "gnus-util")
933 (autoload 'mail-abbrev-in-expansion-header-p "mailabbrev")
934 (autoload 'nndraft-request-associate-buffer "nndraft")
935 (autoload 'nndraft-request-expire-articles "nndraft"))
940 ;;; Utility functions.
943 (defmacro message-y-or-n-p (question show &rest text)
944 "Ask QUESTION, displaying the rest of the arguments in a temp. buffer if SHOW"
945 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
947 ;; Delete the current line (and the next N lines.);
948 (defmacro message-delete-line (&optional n)
949 `(delete-region (progn (beginning-of-line) (point))
950 (progn (forward-line ,(or n 1)) (point))))
952 (defun message-tokenize-header (header &optional separator)
953 "Split HEADER into a list of header elements.
954 \",\" is used as the separator."
957 (let ((regexp (format "[%s]+" (or separator ",")))
962 (message-set-work-buffer)
964 (goto-char (point-min))
969 (cond ((and (> (point) beg)
971 (and (looking-at regexp)
974 (push (buffer-substring beg (point)) elems)
975 (setq beg (match-end 0)))
976 ((= (following-char) ?\")
977 (setq quoted (not quoted)))
978 ((and (= (following-char) ?\()
981 ((and (= (following-char) ?\))
986 (defun message-mail-file-mbox-p (file)
987 "Say whether FILE looks like a Unix mbox file."
988 (when (and (file-exists-p file)
989 (file-readable-p file)
990 (file-regular-p file))
991 (nnheader-temp-write nil
992 (nnheader-insert-file-contents file)
993 (goto-char (point-min))
994 (looking-at message-unix-mail-delimiter))))
996 (defun message-fetch-field (header &optional not-all)
997 "The same as `mail-fetch-field', only remove all newlines."
998 (let ((value (mail-fetch-field header nil (not not-all))))
1000 (nnheader-replace-chars-in-string value ?\n ? ))))
1002 (defun message-add-header (&rest headers)
1003 "Add the HEADERS to the message header, skipping those already present."
1006 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1007 (error "Invalid header `%s'" (car headers)))
1008 (setq hclean (match-string 1 (car headers)))
1010 (message-narrow-to-headers)
1011 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1012 (insert (car headers) ?\n))))
1013 (setq headers (cdr headers))))
1015 (defun message-fetch-reply-field (header)
1016 "Fetch FIELD from the message we're replying to."
1017 (when (and message-reply-buffer
1018 (buffer-name message-reply-buffer))
1020 (set-buffer message-reply-buffer)
1021 (message-fetch-field header))))
1023 (defun message-set-work-buffer ()
1024 (if (get-buffer " *message work*")
1026 (set-buffer " *message work*")
1028 (set-buffer (get-buffer-create " *message work*"))
1029 (kill-all-local-variables)
1030 (buffer-disable-undo (current-buffer))))
1032 (defun message-functionp (form)
1033 "Return non-nil if FORM is funcallable."
1034 (or (and (symbolp form) (fboundp form))
1035 (and (listp form) (eq (car form) 'lambda))
1036 (byte-code-function-p form)))
1038 (defun message-strip-subject-re (subject)
1039 "Remove \"Re:\" from subject lines."
1040 (if (string-match "^[Rr][Ee]: *" subject)
1041 (substring subject (match-end 0))
1044 (defun message-remove-header (header &optional is-regexp first reverse)
1045 "Remove HEADER in the narrowed buffer.
1046 If REGEXP, HEADER is a regular expression.
1047 If FIRST, only remove the first instance of the header.
1048 Return the number of headers removed."
1049 (goto-char (point-min))
1050 (let ((regexp (if is-regexp header (concat "^" header ":")))
1052 (case-fold-search t)
1054 (while (and (not (eobp))
1057 (not (looking-at regexp))
1058 (looking-at regexp))
1065 ;; There might be a continuation header, so we have to search
1066 ;; until we find a new non-continuation line.
1069 (if (re-search-forward "^[^ \t]" nil t)
1070 (goto-char (match-beginning 0))
1073 (if (re-search-forward "^[^ \t]" nil t)
1074 (goto-char (match-beginning 0))
1078 (defun message-narrow-to-headers ()
1079 "Narrow the buffer to the head of the message."
1082 (goto-char (point-min))
1083 (if (re-search-forward
1084 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1087 (goto-char (point-min)))
1089 (defun message-narrow-to-head ()
1090 "Narrow the buffer to the head of the message."
1093 (goto-char (point-min))
1094 (if (search-forward "\n\n" nil 1)
1097 (goto-char (point-min)))
1099 (defun message-news-p ()
1100 "Say whether the current buffer contains a news message."
1101 (or message-this-is-news
1104 (message-narrow-to-headers)
1105 (and (message-fetch-field "newsgroups")
1106 (not (message-fetch-field "posted-to")))))))
1108 (defun message-mail-p ()
1109 "Say whether the current buffer contains a mail message."
1110 (or message-this-is-mail
1113 (message-narrow-to-headers)
1114 (or (message-fetch-field "to")
1115 (message-fetch-field "cc")
1116 (message-fetch-field "bcc"))))))
1118 (defun message-next-header ()
1119 "Go to the beginning of the next header."
1121 (or (eobp) (forward-char 1))
1122 (not (if (re-search-forward "^[^ \t]" nil t)
1124 (goto-char (point-max)))))
1126 (defun message-sort-headers-1 ()
1127 "Sort the buffer as headers using `message-rank' text props."
1128 (goto-char (point-min))
1130 nil 'message-next-header
1132 (message-next-header)
1136 (or (get-text-property (point) 'message-rank)
1139 (defun message-sort-headers ()
1140 "Sort the headers of the current message according to `message-header-format-alist'."
1144 (let ((max (1+ (length message-header-format-alist)))
1146 (message-narrow-to-headers)
1147 (while (re-search-forward "^[^ \n]+:" nil t)
1149 (match-beginning 0) (1+ (match-beginning 0))
1151 (if (setq rank (length (memq (assq (intern (buffer-substring
1153 (1- (match-end 0))))
1154 message-header-format-alist)
1155 message-header-format-alist)))
1158 (message-sort-headers-1))))
1168 (defvar message-mode-map nil)
1170 (unless message-mode-map
1171 (setq message-mode-map (copy-keymap text-mode-map))
1172 (define-key message-mode-map "\C-c?" 'describe-mode)
1174 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
1175 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
1176 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
1177 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
1178 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
1179 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
1180 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
1181 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
1182 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
1183 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
1184 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
1185 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
1186 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
1188 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
1189 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
1191 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
1192 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
1193 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
1194 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
1195 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
1196 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
1198 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
1199 (define-key message-mode-map "\C-c\C-s" 'message-send)
1200 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
1201 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
1203 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
1204 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
1205 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
1206 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
1208 (define-key message-mode-map "\t" 'message-tab))
1211 message-mode-menu message-mode-map "Message Menu."
1213 ["Sort Headers" message-sort-headers t]
1214 ["Yank Original" message-yank-original t]
1215 ["Fill Yanked Message" message-fill-yanked-message t]
1216 ["Insert Signature" message-insert-signature t]
1217 ["Caesar (rot13) Message" message-caesar-buffer-body t]
1218 ["Caesar (rot13) Region" message-caesar-region (mark t)]
1219 ["Elide Region" message-elide-region (mark t)]
1220 ["Delete Outside Region" message-delete-not-region (mark t)]
1221 ["Kill To Signature" message-kill-to-signature t]
1222 ["Newline and Reformat" message-newline-and-reformat t]
1223 ["Rename buffer" message-rename-buffer t]
1224 ["Spellcheck" ispell-message t]
1226 ["Send Message" message-send-and-exit t]
1227 ["Abort Message" message-dont-send t]))
1230 message-mode-field-menu message-mode-map ""
1232 ["Fetch To" message-insert-to t]
1233 ["Fetch Newsgroups" message-insert-newsgroups t]
1235 ["To" message-goto-to t]
1236 ["Subject" message-goto-subject t]
1237 ["Cc" message-goto-cc t]
1238 ["Reply-To" message-goto-reply-to t]
1239 ["Summary" message-goto-summary t]
1240 ["Keywords" message-goto-keywords t]
1241 ["Newsgroups" message-goto-newsgroups t]
1242 ["Followup-To" message-goto-followup-to t]
1243 ["Distribution" message-goto-distribution t]
1244 ["Body" message-goto-body t]
1245 ["Signature" message-goto-signature t]))
1247 (defvar facemenu-add-face-function)
1248 (defvar facemenu-remove-face-function)
1251 (defun message-mode ()
1252 "Major mode for editing mail and news to be sent.
1253 Like Text Mode but with these additional commands:
1254 C-c C-s message-send (send the message) C-c C-c message-send-and-exit
1255 C-c C-f move to a header field (and create it if there isn't):
1256 C-c C-f C-t move to To C-c C-f C-s move to Subject
1257 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1258 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1259 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1260 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1261 C-c C-f C-f move to Followup-To
1262 C-c C-t message-insert-to (add a To header to a news followup)
1263 C-c C-n message-insert-newsgroups (add a Newsgroup header to a news reply)
1264 C-c C-b message-goto-body (move to beginning of message text).
1265 C-c C-i message-goto-signature (move to the beginning of the signature).
1266 C-c C-w message-insert-signature (insert `message-signature-file' file).
1267 C-c C-y message-yank-original (insert current message, if any).
1268 C-c C-q message-fill-yanked-message (fill what was yanked).
1269 C-c C-e message-elide-region (elide the text between point and mark).
1270 C-c C-r message-caesar-buffer-body (rot13 the message body)."
1272 (kill-all-local-variables)
1273 (make-local-variable 'message-reply-buffer)
1274 (setq message-reply-buffer nil)
1275 (make-local-variable 'message-send-actions)
1276 (make-local-variable 'message-exit-actions)
1277 (make-local-variable 'message-kill-actions)
1278 (make-local-variable 'message-postpone-actions)
1279 (make-local-variable 'message-draft-article)
1280 (make-local-hook 'kill-buffer-hook)
1281 (set-syntax-table message-mode-syntax-table)
1282 (use-local-map message-mode-map)
1283 (setq local-abbrev-table message-mode-abbrev-table)
1284 (setq major-mode 'message-mode)
1285 (setq mode-name "Message")
1286 (setq buffer-offer-save t)
1287 (make-local-variable 'facemenu-add-face-function)
1288 (make-local-variable 'facemenu-remove-face-function)
1289 (setq facemenu-add-face-function
1291 (let ((face-fun (cdr (assq face message-face-alist))))
1293 (funcall face-fun (point) end)
1294 (error "Face %s not configured for %s mode" face mode-name)))
1296 facemenu-remove-face-function t)
1297 (make-local-variable 'paragraph-separate)
1298 (make-local-variable 'paragraph-start)
1299 (setq paragraph-start
1300 (concat (regexp-quote mail-header-separator)
1301 "$\\|[ \t]*[-_][-_][-_]+$\\|"
1303 ;;!!! Uhm... shurely this can't be right.
1304 "[> " (regexp-quote message-yank-prefix) "]+$\\|"
1306 (setq paragraph-separate
1307 (concat (regexp-quote mail-header-separator)
1308 "$\\|[ \t]*[-_][-_][-_]+$\\|"
1310 "[> " (regexp-quote message-yank-prefix) "]+$\\|"
1311 paragraph-separate))
1312 (make-local-variable 'message-reply-headers)
1313 (setq message-reply-headers nil)
1314 (make-local-variable 'message-newsreader)
1315 (make-local-variable 'message-mailer)
1316 (make-local-variable 'message-post-method)
1317 (make-local-variable 'message-sent-message-via)
1318 (setq message-sent-message-via nil)
1319 (make-local-variable 'message-checksum)
1320 (setq message-checksum nil)
1321 ;;(when (fboundp 'mail-hist-define-keys)
1322 ;; (mail-hist-define-keys))
1323 (when (string-match "XEmacs\\|Lucid" emacs-version)
1324 (message-setup-toolbar))
1325 (easy-menu-add message-mode-menu message-mode-map)
1326 (easy-menu-add message-mode-field-menu message-mode-map)
1327 ;; Allow mail alias things.
1328 (when (eq message-mail-alias-type 'abbrev)
1329 (if (fboundp 'mail-abbrevs-setup)
1330 (mail-abbrevs-setup)
1331 (funcall (intern "mail-aliases-setup"))))
1332 (message-set-auto-save-file-name)
1333 (unless (string-match "XEmacs" emacs-version)
1334 (set (make-local-variable 'font-lock-defaults)
1335 '(message-font-lock-keywords t)))
1336 (run-hooks 'text-mode-hook 'message-mode-hook))
1341 ;;; Message mode commands
1344 ;;; Movement commands
1346 (defun message-goto-to ()
1347 "Move point to the To header."
1349 (message-position-on-field "To"))
1351 (defun message-goto-subject ()
1352 "Move point to the Subject header."
1354 (message-position-on-field "Subject"))
1356 (defun message-goto-cc ()
1357 "Move point to the Cc header."
1359 (message-position-on-field "Cc" "To"))
1361 (defun message-goto-bcc ()
1362 "Move point to the Bcc header."
1364 (message-position-on-field "Bcc" "Cc" "To"))
1366 (defun message-goto-fcc ()
1367 "Move point to the Fcc header."
1369 (message-position-on-field "Fcc" "To" "Newsgroups"))
1371 (defun message-goto-reply-to ()
1372 "Move point to the Reply-To header."
1374 (message-position-on-field "Reply-To" "Subject"))
1376 (defun message-goto-newsgroups ()
1377 "Move point to the Newsgroups header."
1379 (message-position-on-field "Newsgroups"))
1381 (defun message-goto-distribution ()
1382 "Move point to the Distribution header."
1384 (message-position-on-field "Distribution"))
1386 (defun message-goto-followup-to ()
1387 "Move point to the Followup-To header."
1389 (message-position-on-field "Followup-To" "Newsgroups"))
1391 (defun message-goto-keywords ()
1392 "Move point to the Keywords header."
1394 (message-position-on-field "Keywords" "Subject"))
1396 (defun message-goto-summary ()
1397 "Move point to the Summary header."
1399 (message-position-on-field "Summary" "Subject"))
1401 (defun message-goto-body ()
1402 "Move point to the beginning of the message body."
1404 (if (looking-at "[ \t]*\n") (expand-abbrev))
1405 (goto-char (point-min))
1406 (search-forward (concat "\n" mail-header-separator "\n") nil t))
1408 (defun message-goto-signature ()
1409 "Move point to the beginning of the message signature."
1411 (goto-char (point-min))
1412 (if (re-search-forward message-signature-separator nil t)
1414 (goto-char (point-max))))
1418 (defun message-insert-to (&optional force)
1419 "Insert a To header that points to the author of the article being replied to.
1420 If the original author requested not to be sent mail, the function signals
1422 With the prefix argument FORCE, insert the header anyway."
1424 (let ((co (message-fetch-reply-field "mail-copies-to")))
1425 (when (and (null force)
1427 (equal (downcase co) "never"))
1428 (error "The user has requested not to have copies sent via mail")))
1429 (when (and (message-position-on-field "To")
1430 (mail-fetch-field "to")
1431 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
1433 (insert (or (message-fetch-reply-field "reply-to")
1434 (message-fetch-reply-field "from") "")))
1436 (defun message-insert-newsgroups ()
1437 "Insert the Newsgroups header from the article being replied to."
1439 (when (and (message-position-on-field "Newsgroups")
1440 (mail-fetch-field "newsgroups")
1441 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
1443 (insert (or (message-fetch-reply-field "newsgroups") "")))
1447 ;;; Various commands
1449 (defun message-delete-not-region (beg end)
1450 "Delete everything in the body of the current message that is outside of the region."
1454 (delete-region (point) (progn (message-goto-signature)
1459 (delete-region beg (progn (message-goto-body)
1462 (message-goto-signature)
1465 (defun message-kill-to-signature ()
1466 "Deletes all text up to the signature."
1468 (let ((point (point)))
1469 (message-goto-signature)
1472 (kill-region point (point))
1476 (defun message-newline-and-reformat ()
1477 "Insert four newlines, and then reformat if inside quoted text."
1479 (let ((point (point))
1483 (setq quoted (looking-at (regexp-quote message-yank-prefix))))
1486 (insert message-yank-prefix))
1487 (fill-paragraph nil)
1491 (defun message-insert-signature (&optional force)
1492 "Insert a signature. See documentation for the `message-signature' variable."
1493 (interactive (list 0))
1496 ((and (null message-signature)
1499 (goto-char (point-max))
1500 (not (re-search-backward
1501 message-signature-separator nil t))))
1502 ((and (null message-signature)
1505 ((message-functionp message-signature)
1506 (funcall message-signature))
1507 ((listp message-signature)
1508 (eval message-signature))
1509 (t message-signature)))
1511 (cond ((stringp signature)
1513 ((and (eq t signature)
1514 message-signature-file
1515 (file-exists-p message-signature-file))
1518 (goto-char (point-max))
1519 ;; Insert the signature.
1523 (if (eq signature t)
1524 (insert-file-contents message-signature-file)
1526 (goto-char (point-max))
1527 (or (bolp) (insert "\n")))))
1529 (defun message-elide-region (b e)
1530 "Elide the text between point and mark.
1531 An ellipsis (from `message-elide-elipsis') will be inserted where the
1537 (insert message-elide-elipsis))
1539 (defvar message-caesar-translation-table nil)
1541 (defun message-caesar-region (b e &optional n)
1542 "Caesar rotation of region by N, default 13, for decrypting netnews."
1545 (min (point) (or (mark t) (point)))
1546 (max (point) (or (mark t) (point)))
1547 (when current-prefix-arg
1548 (prefix-numeric-value current-prefix-arg))))
1550 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
1551 (unless (or (zerop n) ; no action needed for a rot of 0
1552 (= b e)) ; no region to rotate
1553 ;; We build the table, if necessary.
1554 (when (or (not message-caesar-translation-table)
1555 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
1556 (setq message-caesar-translation-table
1557 (message-make-caesar-translation-table n)))
1558 ;; Then we translate the region. Do it this way to retain
1561 (subst-char-in-region
1562 b (1+ b) (char-after b)
1563 (aref message-caesar-translation-table (char-after b)))
1566 (defun message-make-caesar-translation-table (n)
1567 "Create a rot table with offset N."
1569 (table (make-string 256 0)))
1570 (while (< (incf i) 256)
1573 (substring table 0 ?A)
1574 (substring table (+ ?A n) (+ ?A n (- 26 n)))
1575 (substring table ?A (+ ?A n))
1576 (substring table (+ ?A 26) ?a)
1577 (substring table (+ ?a n) (+ ?a n (- 26 n)))
1578 (substring table ?a (+ ?a n))
1579 (substring table (+ ?a 26) 255))))
1581 (defun message-caesar-buffer-body (&optional rotnum)
1582 "Caesar rotates all letters in the current buffer by 13 places.
1583 Used to encode/decode possiblyun offensive messages (commonly in net.jokes).
1584 With prefix arg, specifies the number of places to rotate each letter forward.
1585 Mail and USENET news headers are not rotated."
1586 (interactive (if current-prefix-arg
1587 (list (prefix-numeric-value current-prefix-arg))
1591 (when (message-goto-body)
1592 (narrow-to-region (point) (point-max)))
1593 (message-caesar-region (point-min) (point-max) rotnum))))
1595 (defun message-pipe-buffer-body (program)
1596 "Pipe the message body in the current buffer through PROGRAM."
1599 (when (message-goto-body)
1600 (narrow-to-region (point) (point-max)))
1601 (let ((body (buffer-substring (point-min) (point-max))))
1602 (unless (equal 0 (call-process-region
1603 (point-min) (point-max) program t t))
1605 (message "%s failed." program))))))
1607 (defun message-rename-buffer (&optional enter-string)
1608 "Rename the *message* buffer to \"*message* RECIPIENT\".
1609 If the function is run with a prefix, it will ask for a new buffer
1610 name, rather than giving an automatic name."
1611 (interactive "Pbuffer name: ")
1614 (goto-char (point-min))
1615 (narrow-to-region (point)
1616 (search-forward mail-header-separator nil 'end))
1618 (if (message-news-p) (message-fetch-field "Newsgroups")
1619 (message-fetch-field "To"))
1622 (if (string-match "," mail-to)
1623 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
1625 (name-default (concat "*message* " mail-trimmed-to))
1626 (name (if enter-string
1627 (read-string "New buffer name: " name-default)
1630 (if message-autosave-directory
1631 (file-name-as-directory message-autosave-directory)
1632 default-directory)))
1633 (rename-buffer name t)))))
1635 (defun message-fill-yanked-message (&optional justifyp)
1636 "Fill the paragraphs of a message yanked into this one.
1637 Numeric argument means justify as well."
1640 (goto-char (point-min))
1641 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1642 (let ((fill-prefix message-yank-prefix))
1643 (fill-individual-paragraphs (point) (point-max) justifyp t))))
1645 (defun message-indent-citation ()
1646 "Modify text just inserted from a message to be cited.
1647 The inserted text should be the region.
1648 When this function returns, the region is again around the modified text.
1650 Normally, indent each nonblank line `message-indentation-spaces' spaces.
1651 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
1652 (let ((start (point)))
1653 ;; Remove unwanted headers.
1654 (when message-ignored-cited-headers
1659 (if (search-forward "\n\n" nil t)
1662 (message-remove-header message-ignored-cited-headers t)
1663 (when (= (point-min) (point-max))
1664 (setq all-removed t))
1665 (goto-char (point-max)))
1669 ;; Delete blank lines at the start of the buffer.
1670 (while (and (point-min)
1673 (message-delete-line))
1674 ;; Delete blank lines at the end of the buffer.
1675 (goto-char (point-max))
1678 (while (and (zerop (forward-line -1))
1680 (message-delete-line))
1681 ;; Do the indentation.
1682 (if (null message-yank-prefix)
1683 (indent-rigidly start (mark t) message-indentation-spaces)
1686 (while (< (point) (mark t))
1687 (insert message-yank-prefix)
1691 (defun message-yank-original (&optional arg)
1692 "Insert the message being replied to, if any.
1693 Puts point before the text and mark after.
1694 Normally indents each nonblank line ARG spaces (default 3). However,
1695 if `message-yank-prefix' is non-nil, insert that prefix on each line.
1697 This function uses `message-cite-function' to do the actual citing.
1699 Just \\[universal-argument] as argument means don't indent, insert no
1700 prefix, and don't delete any headers."
1702 (let ((modified (buffer-modified-p)))
1703 (when (and message-reply-buffer
1704 message-cite-function)
1705 (delete-windows-on message-reply-buffer t)
1706 (insert-buffer message-reply-buffer)
1707 (funcall message-cite-function)
1708 (message-exchange-point-and-mark)
1712 (setq message-checksum (cons (message-checksum) (buffer-size)))))))
1714 (defun message-cite-original-without-signature ()
1715 "Cite function in the standard Message manner."
1716 (let ((start (point))
1719 (when message-indent-citation-function
1720 (if (listp message-indent-citation-function)
1721 message-indent-citation-function
1722 (list message-indent-citation-function)))))
1724 (when (re-search-backward "^-- $" start t)
1725 (delete-region (point) end))
1728 (funcall (pop functions)))
1729 (when message-citation-line-function
1732 (funcall message-citation-line-function))))
1734 (defun message-cite-original ()
1735 "Cite function in the standard Message manner."
1736 (let ((start (point))
1738 (when message-indent-citation-function
1739 (if (listp message-indent-citation-function)
1740 message-indent-citation-function
1741 (list message-indent-citation-function)))))
1744 (funcall (pop functions)))
1745 (when message-citation-line-function
1748 (funcall message-citation-line-function))))
1750 (defun message-insert-citation-line ()
1751 "Function that inserts a simple citation line."
1752 (when message-reply-headers
1753 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
1755 (defun message-position-on-field (header &rest afters)
1756 (let ((case-fold-search t))
1759 (goto-char (point-min))
1762 (concat "^" (regexp-quote mail-header-separator) "$"))
1763 (match-beginning 0)))
1764 (goto-char (point-min))
1765 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
1767 (re-search-forward "^[^ \t]" nil 'move)
1769 (skip-chars-backward "\n")
1772 (not (re-search-forward
1773 (concat "^" (regexp-quote (car afters)) ":")
1777 (re-search-forward "^[^ \t]" nil 'move)
1778 (beginning-of-line))
1779 (insert header ": \n")
1783 (defun message-remove-signature ()
1784 "Remove the signature from the text between point and mark.
1785 The text will also be indented the normal way."
1787 (let ((start (point))
1789 (if (not (re-search-forward message-signature-separator (mark t) t))
1790 ;; No signature here, so we just indent the cited text.
1791 (message-indent-citation)
1792 ;; Find the last non-empty line.
1794 (while (looking-at "[ \t]*$")
1797 (setq mark (set-marker (make-marker) (point)))
1799 (message-indent-citation)
1800 ;; Enable undoing the deletion.
1802 (delete-region mark (mark t))
1803 (set-marker mark nil)))))
1808 ;;; Sending messages
1811 (defun message-send-and-exit (&optional arg)
1812 "Send message like `message-send', then, if no errors, exit from mail buffer."
1814 (let ((buf (current-buffer))
1815 (actions message-exit-actions))
1816 (when (and (message-send arg)
1818 (if message-kill-buffer-on-exit
1821 (when (eq buf (current-buffer))
1822 (message-bury buf)))
1823 (message-do-actions actions))))
1825 (defun message-dont-send ()
1826 "Don't send the message you have been editing."
1828 (set-buffer-modified-p t)
1830 (let ((actions message-postpone-actions))
1831 (message-bury (current-buffer))
1832 (message-do-actions actions)))
1834 (defun message-kill-buffer ()
1835 "Kill the current buffer."
1837 (when (or (not (buffer-modified-p))
1838 (yes-or-no-p "Message modified; kill anyway? "))
1839 (let ((actions message-kill-actions))
1840 (setq buffer-file-name nil)
1841 (kill-buffer (current-buffer))
1842 (message-do-actions actions))))
1844 (defun message-bury (buffer)
1845 "Bury this mail buffer."
1846 (let ((newbuf (other-buffer buffer)))
1847 (bury-buffer buffer)
1848 (if (and (fboundp 'frame-parameters)
1849 (cdr (assq 'dedicated (frame-parameters)))
1850 (not (null (delq (selected-frame) (visible-frame-list)))))
1851 (delete-frame (selected-frame))
1852 (switch-to-buffer newbuf))))
1854 (defun message-send (&optional arg)
1855 "Send the message in the current buffer.
1856 If `message-interactive' is non-nil, wait for success indication
1857 or error messages, and inform user.
1858 Otherwise any failure is reported in a message back to
1859 the user from the mailer."
1862 (when (or (buffer-modified-p)
1863 (message-check-element 'unchanged)
1864 (y-or-n-p "No changes in the buffer; really send? "))
1865 ;; Make it possible to undo the coming changes.
1867 (let ((inhibit-read-only t))
1868 (put-text-property (point-min) (point-max) 'read-only nil))
1869 (message-fix-before-sending)
1870 (run-hooks 'message-send-hook)
1871 (message "Sending...")
1872 (let ((message-encoding-buffer
1873 (message-generate-new-buffer-clone-locals " message encoding"))
1874 (message-edit-buffer (current-buffer))
1875 (message-mime-mode mime-edit-mode-flag)
1876 (alist message-send-method-alist)
1880 (set-buffer message-encoding-buffer)
1882 (insert-buffer message-edit-buffer)
1883 (funcall message-encode-function)
1885 (setq elem (pop alist)))
1886 (when (and (or (not (funcall (cadr elem)))
1887 (and (or (not (memq (car elem)
1888 message-sent-message-via))
1891 "Already sent message via %s; resend? "
1893 (setq success (funcall (caddr elem) arg)))))
1895 (when (and success sent)
1897 ;;(when (fboundp 'mail-hist-put-headers-into-history)
1898 ;; (mail-hist-put-headers-into-history))
1899 (run-hooks 'message-sent-hook)
1900 (message "Sending...done")
1901 ;; Mark the buffer as unmodified and delete autosave.
1902 (set-buffer-modified-p nil)
1903 (delete-auto-save-file-if-necessary t)
1904 (message-disassociate-draft)
1905 ;; Delete other mail buffers and stuff.
1906 (message-do-send-housekeeping)
1907 (message-do-actions message-send-actions)
1911 (defun message-send-via-mail (arg)
1912 "Send the current message via mail."
1913 (message-send-mail arg))
1915 (defun message-send-via-news (arg)
1916 "Send the current message via news."
1917 (message-send-news arg))
1919 (defun message-fix-before-sending ()
1920 "Do various things to make the message nice before sending it."
1921 ;; Make sure there's a newline at the end of the message.
1922 (goto-char (point-max))
1926 (defun message-add-action (action &rest types)
1927 "Add ACTION to be performed when doing an exit of type TYPES."
1930 (set (setq var (intern (format "message-%s-actions" (pop types))))
1931 (nconc (symbol-value var) (list action))))))
1933 (defun message-do-actions (actions)
1934 "Perform all actions in ACTIONS."
1935 ;; Now perform actions on successful sending.
1939 ;; A simple function.
1940 ((message-functionp (car actions))
1941 (funcall (car actions)))
1942 ;; Something to be evaled.
1944 (eval (car actions)))))
1947 (defun message-send-mail (&optional arg)
1948 (require 'mail-utils)
1949 (let ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
1950 (case-fold-search nil)
1951 (news (message-news-p)))
1953 (message-narrow-to-headers)
1954 ;; Insert some headers.
1955 (let ((message-deletable-headers
1956 (if news nil message-deletable-headers)))
1957 (message-generate-headers message-required-mail-headers))
1958 ;; Let the user do all of the above.
1959 (run-hooks 'message-header-hook))
1964 (insert-buffer message-encoding-buffer)
1965 ;; Remove some headers.
1967 (message-narrow-to-headers)
1968 ;; Remove some headers.
1969 (message-remove-header message-ignored-mail-headers t))
1970 (goto-char (point-max))
1971 ;; require one newline at the end.
1972 (or (= (preceding-char) ?\n)
1975 (or (message-fetch-field "cc")
1976 (message-fetch-field "to")))
1977 (message-insert-courtesy-copy))
1978 (mime-edit-maybe-split-and-send
1982 (funcall message-send-mail-function)
1984 (funcall message-send-mail-function))
1985 (kill-buffer tembuf))
1986 (set-buffer message-edit-buffer)
1987 (push 'mail message-sent-message-via)))
1989 (defun message-send-mail-with-sendmail ()
1990 "Send off the prepared buffer with sendmail."
1991 (let ((errbuf (if message-interactive
1992 (generate-new-buffer " sendmail errors")
1994 resend-to-addresses delimline)
1995 (let ((case-fold-search t))
1997 (message-narrow-to-headers)
1998 (setq resend-to-addresses (message-fetch-field "resent-to")))
1999 ;; Change header-delimiter to be what sendmail expects.
2000 (goto-char (point-min))
2002 (concat "^" (regexp-quote mail-header-separator) "\n"))
2003 (replace-match "\n")
2005 (setq delimline (point-marker))
2006 (run-hooks 'message-send-mail-hook)
2007 ;; Insert an extra newline if we need it to work around
2008 ;; Sun's bug that swallows newlines.
2009 (goto-char (1+ delimline))
2010 (when (eval message-mailer-swallows-blank-line)
2012 (when message-interactive
2016 (let ((default-directory "/")
2017 (coding-system-for-write 'binary))
2018 (apply 'call-process-region
2019 (append (list (point-min) (point-max)
2020 (if (boundp 'sendmail-program)
2022 "/usr/lib/sendmail")
2023 nil errbuf nil "-oi")
2024 ;; Always specify who from,
2025 ;; since some systems have broken sendmails.
2026 ;; But some systems are more broken with -f, so
2027 ;; we'll let users override this.
2028 (if (null message-sendmail-f-is-evil)
2029 (list "-f" (user-login-name)))
2030 ;; These mean "report errors by mail"
2031 ;; and "deliver in background".
2032 (if (null message-interactive) '("-oem" "-odb"))
2033 ;; Get the addresses from the message
2034 ;; unless this is a resend.
2035 ;; We must not do that for a resend
2036 ;; because we would find the original addresses.
2037 ;; For a resend, include the specific addresses.
2038 (if resend-to-addresses
2039 (list resend-to-addresses)
2041 (when message-interactive
2044 (goto-char (point-min))
2045 (while (re-search-forward "\n\n* *" nil t)
2046 (replace-match "; "))
2047 (if (not (zerop (buffer-size)))
2048 (error "Sending...failed to %s"
2049 (buffer-substring (point-min) (point-max)))))
2050 (when (bufferp errbuf)
2051 (kill-buffer errbuf)))))
2053 (defun message-send-mail-with-qmail ()
2054 "Pass the prepared message buffer to qmail-inject.
2055 Refer to the documentation for the variable `message-send-mail-function'
2056 to find out how to use this."
2057 ;; replace the header delimiter with a blank line
2058 (goto-char (point-min))
2060 (concat "^" (regexp-quote mail-header-separator) "\n"))
2061 (replace-match "\n")
2062 (run-hooks 'message-send-mail-hook)
2065 (let ((coding-system-for-write 'binary))
2067 'call-process-region 1 (point-max) message-qmail-inject-program
2069 ;; qmail-inject's default behaviour is to look for addresses on the
2070 ;; command line; if there're none, it scans the headers.
2071 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
2073 ;; in general, ALL of qmail-inject's defaults are perfect for simply
2074 ;; reading a formatted (i. e., at least a To: or Resent-To header)
2075 ;; message from stdin.
2077 ;; qmail also has the advantage of not having been raped by
2078 ;; various vendors, so we don't have to allow for that, either --
2079 ;; compare this with message-send-mail-with-sendmail and weep
2080 ;; for sendmail's lost innocence.
2082 ;; all this is way cool coz it lets us keep the arguments entirely
2083 ;; free for -inject-arguments -- a big win for the user and for us
2084 ;; since we don't have to play that double-guessing game and the user
2085 ;; gets full control (no gestapo'ish -f's, for instance). --sj
2086 message-qmail-inject-args))
2087 ;; qmail-inject doesn't say anything on it's stdout/stderr,
2088 ;; we have to look at the retval instead
2090 (1 (error "qmail-inject reported permanent failure"))
2091 (111 (error "qmail-inject reported transient failure"))
2092 ;; should never happen
2093 (t (error "qmail-inject reported unknown failure"))))
2095 (defun message-send-mail-with-mh ()
2096 "Send the prepared message buffer with mh."
2097 (let ((mh-previous-window-config nil)
2098 (name (mh-new-draft-name)))
2099 (setq buffer-file-name name)
2100 ;; MH wants to generate these headers itself.
2101 (when message-mh-deletable-headers
2102 (let ((headers message-mh-deletable-headers))
2104 (goto-char (point-min))
2105 (and (re-search-forward
2106 (concat "^" (symbol-name (car headers)) ": *") nil t)
2107 (message-delete-line))
2109 (run-hooks 'message-send-mail-hook)
2110 ;; Pass it on to mh.
2113 (defun message-send-mail-with-smtp ()
2114 "Send the prepared message buffer with SMTP."
2116 (let ((errbuf (if mail-interactive
2117 (generate-new-buffer " smtp errors")
2119 (case-fold-search nil)
2124 (goto-char (point-max))
2125 ;; require one newline at the end.
2126 (or (= (preceding-char) ?\n)
2128 ;; Change header-delimiter to be what sendmail expects.
2129 (goto-char (point-min))
2131 (concat "^" (regexp-quote mail-header-separator) "\n"))
2132 (replace-match "\n")
2134 (setq delimline (point-marker))
2135 (run-hooks 'message-send-mail-hook)
2136 ;; (sendmail-synch-aliases)
2138 ;; (expand-mail-aliases (point-min) delimline))
2139 (goto-char (point-min))
2140 ;; ignore any blank lines in the header
2141 (while (and (re-search-forward "\n\n\n*" delimline t)
2142 (< (point) delimline))
2143 (replace-match "\n"))
2144 (let ((case-fold-search t))
2145 (goto-char (point-min))
2146 (goto-char (point-min))
2147 (while (re-search-forward "^Resent-to:" delimline t)
2148 (setq resend-to-addresses
2150 (narrow-to-region (point)
2154 (append (mail-parse-comma-list)
2155 resend-to-addresses))))
2156 ;;; Apparently this causes a duplicate Sender.
2157 ;;; ;; If the From is different than current user, insert Sender.
2158 ;;; (goto-char (point-min))
2159 ;;; (and (re-search-forward "^From:" delimline t)
2161 ;;; (require 'mail-utils)
2162 ;;; (not (string-equal
2163 ;;; (mail-strip-quoted-names
2164 ;;; (save-restriction
2165 ;;; (narrow-to-region (point-min) delimline)
2166 ;;; (mail-fetch-field "From")))
2167 ;;; (user-login-name))))
2169 ;;; (forward-line 1)
2170 ;;; (insert "Sender: " (user-login-name) "\n")))
2171 ;; Don't send out a blank subject line
2172 (goto-char (point-min))
2173 (if (re-search-forward "^Subject:[ \t]*\n" delimline t)
2175 ;; Put the "From:" field in unless for some odd reason
2176 ;; they put one in themselves.
2177 (goto-char (point-min))
2178 (if (not (re-search-forward "^From:" delimline t))
2179 (let* ((login user-mail-address)
2180 (fullname (user-full-name)))
2181 (cond ((eq mail-from-style 'angles)
2182 (insert "From: " fullname)
2183 (let ((fullname-start (+ (point-min) 6))
2184 (fullname-end (point-marker)))
2185 (goto-char fullname-start)
2186 ;; Look for a character that cannot appear unquoted
2187 ;; according to RFC 822.
2188 (if (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]"
2191 ;; Quote fullname, escaping specials.
2192 (goto-char fullname-start)
2194 (while (re-search-forward "[\"\\]"
2196 (replace-match "\\\\\\&" t))
2198 (insert " <" login ">\n"))
2199 ((eq mail-from-style 'parens)
2200 (insert "From: " login " (")
2201 (let ((fullname-start (point)))
2203 (let ((fullname-end (point-marker)))
2204 (goto-char fullname-start)
2205 ;; RFC 822 says \ and nonmatching parentheses
2206 ;; must be escaped in comments.
2207 ;; Escape every instance of ()\ ...
2208 (while (re-search-forward "[()\\]" fullname-end 1)
2209 (replace-match "\\\\\\&" t))
2210 ;; ... then undo escaping of matching parentheses,
2211 ;; including matching nested parentheses.
2212 (goto-char fullname-start)
2213 (while (re-search-forward
2214 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
2216 (replace-match "\\1(\\3)" t)
2217 (goto-char fullname-start))))
2219 ((null mail-from-style)
2220 (insert "From: " login "\n")))))
2221 ;; Insert an extra newline if we need it to work around
2222 ;; Sun's bug that swallows newlines.
2223 (goto-char (1+ delimline))
2224 (if (eval mail-mailer-swallows-blank-line)
2226 ;; Find and handle any FCC fields.
2227 (goto-char (point-min))
2228 (if (re-search-forward "^FCC:" delimline t)
2229 (mail-do-fcc delimline))
2230 (if mail-interactive
2237 (let ((recipient-address-list
2238 (or resend-to-addresses
2239 (smtp-deduce-address-list (current-buffer)
2240 (point-min) delimline))))
2241 (smtp-do-bcc delimline)
2243 (if recipient-address-list
2244 (if (not (smtp-via-smtp recipient-address-list
2246 (error "Sending failed; SMTP protocol error"))
2247 (error "Sending failed; no recipients"))
2249 (if (bufferp errbuf)
2250 (kill-buffer errbuf)))))
2252 (defun message-send-news (&optional arg)
2253 (let ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
2254 (case-fold-search nil)
2255 (method (if (message-functionp message-post-method)
2256 (funcall message-post-method arg)
2257 message-post-method))
2258 (message-syntax-checks
2260 (cons '(existing-newsgroups . disabled)
2261 message-syntax-checks)
2262 message-syntax-checks))
2265 (message-narrow-to-headers)
2266 ;; Insert some headers.
2267 (message-generate-headers message-required-news-headers)
2268 ;; Let the user do all of the above.
2269 (run-hooks 'message-header-hook))
2270 (message-cleanup-headers)
2271 (if (not (message-check-news-syntax))
2273 ;;(message "Posting not performed")
2278 (buffer-disable-undo (current-buffer))
2280 (insert-buffer message-encoding-buffer)
2281 ;; Remove some headers.
2283 (message-narrow-to-headers)
2284 ;; Remove some headers.
2285 (message-remove-header message-ignored-news-headers t))
2286 (goto-char (point-max))
2287 ;; require one newline at the end.
2288 (or (= (preceding-char) ?\n)
2290 (mime-edit-maybe-split-and-send
2295 (std11-narrow-to-header mail-header-separator)
2296 (goto-char (point-min))
2297 (when (re-search-forward "^Message-Id:" nil t)
2298 (delete-region (match-end 0)(std11-field-end))
2299 (insert (concat " " (message-make-message-id)))
2301 (funcall message-send-news-function method)
2303 (setq result (funcall message-send-news-function method)))
2304 (kill-buffer tembuf))
2305 (set-buffer message-edit-buffer)
2307 (push 'news message-sent-message-via)
2308 (message "Couldn't send message via news: %s"
2309 (nnheader-get-report (car method)))
2312 ;; 1997-09-29 by MORIOKA Tomohiko
2313 (defun message-send-news-with-gnus (method)
2314 (let ((case-fold-search t))
2315 ;; Remove the delimiter.
2316 (goto-char (point-min))
2318 (concat "^" (regexp-quote mail-header-separator) "\n"))
2319 (replace-match "\n")
2321 (run-hooks 'message-send-news-hook)
2322 ;;(require (car method))
2323 ;;(funcall (intern (format "%s-open-server" (car method)))
2324 ;;(cadr method) (cddr method))
2326 ;; (funcall (intern (format "%s-request-post" (car method)))
2328 (gnus-open-server method)
2329 (gnus-request-post method)
2333 ;;; Header generation & syntax checking.
2336 (defmacro message-check (type &rest forms)
2337 "Eval FORMS if TYPE is to be checked."
2338 `(or (message-check-element ,type)
2342 (put 'message-check 'lisp-indent-function 1)
2343 (put 'message-check 'edebug-form-spec '(form body))
2345 (defun message-check-element (type)
2346 "Returns non-nil if this type is not to be checked."
2347 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
2349 (let ((able (assq type message-syntax-checks)))
2351 (eq (cdr able) 'disabled)))))
2353 (defun message-check-news-syntax ()
2354 "Check the syntax of the message."
2359 ;; We narrow to the headers and check them first.
2362 (message-narrow-to-headers)
2363 (message-check-news-header-syntax)))
2366 (set-buffer message-edit-buffer)
2367 (message-check-news-body-syntax))))))
2369 (defun message-check-news-header-syntax ()
2371 ;; Check the Subject header.
2372 (message-check 'subject
2373 (let* ((case-fold-search t)
2374 (subject (message-fetch-field "subject")))
2377 (not (string-match "\\`[ \t]*\\'" subject)))
2380 "The subject field is empty or missing. Posting is denied.")))))
2381 ;; Check for commands in Subject.
2382 (message-check 'subject-cmsg
2383 (if (string-match "^cmsg " (message-fetch-field "subject"))
2385 "The control code \"cmsg\" is in the subject. Really post? ")
2387 ;; Check for multiple identical headers.
2388 (message-check 'multiple-headers
2390 (while (and (not found)
2391 (re-search-forward "^[^ \t:]+: " nil t))
2393 (or (re-search-forward
2398 (match-beginning 0) (- (match-end 0) 2))))
2403 (y-or-n-p (format "Multiple %s headers. Really post? " found))
2405 ;; Check for Version and Sendsys.
2406 (message-check 'sendsys
2407 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
2409 (format "The article contains a %s command. Really post? "
2410 (buffer-substring (match-beginning 0)
2411 (1- (match-end 0)))))
2413 ;; See whether we can shorten Followup-To.
2414 (message-check 'shorten-followup-to
2415 (let ((newsgroups (message-fetch-field "newsgroups"))
2416 (followup-to (message-fetch-field "followup-to"))
2418 (when (and newsgroups
2419 (string-match "," newsgroups)
2424 (setq to (completing-read
2425 "Followups to: (default all groups) "
2426 (mapcar (lambda (g) (list g))
2428 (message-tokenize-header
2430 (goto-char (point-min))
2431 (insert "Followup-To: " to "\n"))
2433 ;; Check "Shoot me".
2434 (message-check 'shoot
2435 (if (re-search-forward
2436 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
2437 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
2439 ;; Check for Approved.
2440 (message-check 'approved
2441 (if (re-search-forward "^Approved:" nil t)
2442 (y-or-n-p "The article contains an Approved header. Really post? ")
2444 ;; Check the Message-ID header.
2445 (message-check 'message-id
2446 (let* ((case-fold-search t)
2447 (message-id (message-fetch-field "message-id" t)))
2448 (or (not message-id)
2449 ;; Is there an @ in the ID?
2450 (and (string-match "@" message-id)
2451 ;; Is there a dot in the ID?
2452 (string-match "@[^.]*\\." message-id)
2453 ;; Does the ID end with a dot?
2454 (not (string-match "\\.>" message-id)))
2456 (format "The Message-ID looks strange: \"%s\". Really post? "
2458 ;; Check the Newsgroups & Followup-To headers.
2459 (message-check 'existing-newsgroups
2460 (let* ((case-fold-search t)
2461 (newsgroups (message-fetch-field "newsgroups"))
2462 (followup-to (message-fetch-field "followup-to"))
2463 (groups (message-tokenize-header
2465 (concat newsgroups "," followup-to)
2467 (hashtb (and (boundp 'gnus-active-hashtb)
2468 gnus-active-hashtb))
2470 (if (or (not hashtb)
2471 (not (boundp 'gnus-read-active-file))
2472 (not gnus-read-active-file)
2473 (eq gnus-read-active-file 'some))
2476 (when (and (not (boundp (intern (car groups) hashtb)))
2477 (not (equal (car groups) "poster")))
2478 (push (car groups) errors))
2484 "Really post to %s unknown group%s: %s "
2485 (if (= (length errors) 1) "this" "these")
2486 (if (= (length errors) 1) "" "s")
2487 (mapconcat 'identity errors ", ")))))))
2488 ;; Check the Newsgroups & Followup-To headers for syntax errors.
2489 (message-check 'valid-newsgroups
2490 (let ((case-fold-search t)
2491 (headers '("Newsgroups" "Followup-To"))
2493 (while (and headers (not error))
2494 (when (setq header (mail-fetch-field (car headers)))
2498 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
2503 (not (string-match "\\.\\'\\|\\.\\." g)))
2504 (message-tokenize-header header ","))))
2511 (format "The %s header looks odd: \"%s\". Really post? "
2512 (car headers) header)))))
2513 (message-check 'repeated-newsgroups
2514 (let ((case-fold-search t)
2515 (headers '("Newsgroups" "Followup-To"))
2516 header error groups group)
2519 (when (setq header (mail-fetch-field (pop headers)))
2520 (setq groups (message-tokenize-header header ","))
2521 (while (setq group (pop groups))
2522 (when (member group groups)
2528 (format "Group %s is repeated in headers. Really post? " error)))))
2529 ;; Check the From header.
2530 (message-check 'from
2531 (let* ((case-fold-search t)
2532 (from (message-fetch-field "from"))
2533 (ad (nth 1 (mail-extract-address-components from))))
2536 (message "There is no From line. Posting is denied.")
2538 ((or (not (string-match "@[^\\.]*\\." ad)) ;larsi@ifi
2539 (string-match "\\.\\." ad) ;larsi@ifi..uio
2540 (string-match "@\\." ad) ;larsi@.ifi.uio
2541 (string-match "\\.$" ad) ;larsi@ifi.uio.
2542 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
2543 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
2545 "Denied posting -- the From looks strange: \"%s\"." from)
2549 (defun message-check-news-body-syntax ()
2551 ;; Check for long lines.
2552 (message-check 'long-lines
2553 (goto-char (point-min))
2555 (concat "^" (regexp-quote mail-header-separator) "$"))
2559 (< (current-column) 80))
2560 (zerop (forward-line 1))))
2564 "You have lines longer than 79 characters. Really post? ")))
2565 ;; Check whether the article is empty.
2566 (message-check 'empty
2567 (goto-char (point-min))
2569 (concat "^" (regexp-quote mail-header-separator) "$"))
2572 (goto-char (point-max))
2573 (re-search-backward message-signature-separator nil t)
2575 (or (re-search-backward "[^ \n\t]" b t)
2576 (y-or-n-p "Empty article. Really post? "))))
2577 ;; Check for control characters.
2578 (message-check 'control-chars
2579 (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t)
2581 "The article contains control characters. Really post? ")
2583 ;; Check excessive size.
2584 (message-check 'size
2585 (if (> (buffer-size) 60000)
2587 (format "The article is %d octets long. Really post? "
2590 ;; Check whether any new text has been added.
2591 (message-check 'new-text
2593 (not message-checksum)
2594 (not (and (eq (message-checksum) (car message-checksum))
2595 (eq (buffer-size) (cdr message-checksum))))
2597 "It looks like no new text has been added. Really post? ")))
2598 ;; Check the length of the signature.
2599 (message-check 'signature
2600 (goto-char (point-max))
2601 (if (or (not (re-search-backward message-signature-separator nil t))
2602 (search-forward message-forward-end-separator nil t))
2604 (if (> (count-lines (point) (point-max)) 5)
2607 "Your .sig is %d lines; it should be max 4. Really post? "
2608 (1- (count-lines (point) (point-max)))))
2611 (defun message-checksum ()
2612 "Return a \"checksum\" for the current buffer."
2615 (goto-char (point-min))
2617 (concat "^" (regexp-quote mail-header-separator) "$"))
2619 (when (not (looking-at "[ \t\n]"))
2620 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
2625 (defun message-do-fcc ()
2626 "Process Fcc headers in the current buffer."
2627 (let ((case-fold-search t)
2628 (coding-system-for-write 'raw-text)
2631 (set-buffer (get-buffer-create " *message temp*"))
2632 (buffer-disable-undo (current-buffer))
2634 (insert-buffer-substring message-encoding-buffer)
2636 (message-narrow-to-headers)
2637 (while (setq file (message-fetch-field "fcc"))
2639 (message-remove-header "fcc" nil t)))
2640 (run-hooks 'message-header-hook 'message-before-do-fcc-hook)
2641 (goto-char (point-min))
2642 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
2643 (replace-match "" t t)
2644 ;; Process FCC operations.
2646 (setq file (pop list))
2647 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
2648 ;; Pipe the article to the program in question.
2649 (call-process-region (point-min) (point-max) shell-file-name
2650 nil nil nil shell-command-switch
2651 (match-string 1 file))
2652 ;; Save the article.
2653 (setq file (expand-file-name file))
2654 (unless (file-exists-p (file-name-directory file))
2655 (make-directory (file-name-directory file) t))
2656 (if (and message-fcc-handler-function
2657 (not (eq message-fcc-handler-function 'rmail-output)))
2658 (funcall message-fcc-handler-function file)
2659 (if (and (file-readable-p file) (mail-file-babyl-p file))
2660 (rmail-output file 1 nil t)
2661 (let ((mail-use-rfc822 t))
2662 (rmail-output file 1 t t))))))
2664 (kill-buffer (current-buffer)))))
2666 (defun message-output (filename)
2667 "Append this article to Unix/babyl mail file.."
2668 (if (and (file-readable-p filename)
2669 (mail-file-babyl-p filename))
2670 (gnus-output-to-rmail filename t)
2671 (gnus-output-to-mail filename t)))
2673 (defun message-cleanup-headers ()
2674 "Do various automatic cleanups of the headers."
2675 ;; Remove empty lines in the header.
2677 (message-narrow-to-headers)
2678 ;; Remove blank lines.
2679 (while (re-search-forward "^[ \t]*\n" nil t)
2680 (replace-match "" t t))
2682 ;; Correct Newsgroups and Followup-To headers: Change sequence of
2683 ;; spaces to comma and eliminate spaces around commas. Eliminate
2684 ;; embedded line breaks.
2685 (goto-char (point-min))
2686 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
2690 (if (re-search-forward "^[^ \t]" nil t)
2694 (goto-char (point-min))
2695 (while (re-search-forward "\n[ \t]+" nil t)
2696 (replace-match " " t t)) ;No line breaks (too confusing)
2697 (goto-char (point-min))
2698 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
2699 (replace-match "," t t))
2700 (goto-char (point-min))
2701 ;; Remove trailing commas.
2702 (when (re-search-forward ",+$" nil t)
2703 (replace-match "" t t))))))
2705 (defun message-make-date ()
2706 "Make a valid data header."
2707 (let ((now (current-time)))
2708 (timezone-make-date-arpa-standard
2709 (current-time-string now) (current-time-zone now))))
2711 (defun message-make-message-id ()
2712 "Make a unique Message-ID."
2713 (concat "<" (message-unique-id)
2714 (let ((psubject (save-excursion (message-fetch-field "subject")))
2716 (save-excursion (message-fetch-field "supersedes"))))
2718 (and message-reply-headers
2719 (mail-header-references message-reply-headers)
2720 (mail-header-subject message-reply-headers)
2722 (mail-header-subject message-reply-headers)
2724 (message-strip-subject-re
2725 (mail-header-subject message-reply-headers))
2726 (message-strip-subject-re psubject))))
2728 (string-match "_-_@" psupersedes)))
2730 "@" (message-make-fqdn) ">"))
2732 (defvar message-unique-id-char nil)
2734 ;; If you ever change this function, make sure the new version
2735 ;; cannot generate IDs that the old version could.
2736 ;; You might for example insert a "." somewhere (not next to another dot
2737 ;; or string boundary), or modify the "fsf" string.
2738 (defun message-unique-id ()
2739 ;; Don't use microseconds from (current-time), they may be unsupported.
2740 ;; Instead we use this randomly inited counter.
2741 (setq message-unique-id-char
2742 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
2743 ;; (current-time) returns 16-bit ints,
2744 ;; and 2^16*25 just fits into 4 digits i base 36.
2746 (let ((tm (current-time)))
2748 (if (memq system-type '(ms-dos emx vax-vms))
2749 (let ((user (downcase (user-login-name))))
2750 (while (string-match "[^a-z0-9_]" user)
2751 (aset user (match-beginning 0) ?_))
2753 (message-number-base36 (user-uid) -1))
2754 (message-number-base36 (+ (car tm)
2755 (lsh (% message-unique-id-char 25) 16)) 4)
2756 (message-number-base36 (+ (nth 1 tm)
2757 (lsh (/ message-unique-id-char 25) 16)) 4)
2758 ;; Append the newsreader name, because while the generated
2759 ;; ID is unique to this newsreader, other newsreaders might
2760 ;; otherwise generate the same ID via another algorithm.
2763 (defun message-number-base36 (num len)
2768 (concat (message-number-base36 (/ num 36) (1- len))
2769 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
2772 (defun message-make-organization ()
2773 "Make an Organization header."
2774 (let* ((organization
2775 (when message-user-organization
2776 (if (message-functionp message-user-organization)
2777 (funcall message-user-organization)
2778 message-user-organization))))
2780 (message-set-work-buffer)
2781 (cond ((stringp organization)
2782 (insert organization))
2783 ((and (eq t organization)
2784 message-user-organization-file
2785 (file-exists-p message-user-organization-file))
2786 (insert-file-contents message-user-organization-file)))
2787 (goto-char (point-min))
2788 (while (re-search-forward "[\t\n]+" nil t)
2789 (replace-match "" t t))
2790 (unless (zerop (buffer-size))
2793 (defun message-make-lines ()
2794 "Count the number of lines and return numeric string."
2798 (goto-char (point-min))
2800 (concat "^" (regexp-quote mail-header-separator) "$"))
2802 (int-to-string (count-lines (point) (point-max))))))
2804 (defun message-make-in-reply-to ()
2805 "Return the In-Reply-To header for this message."
2806 (when message-reply-headers
2807 (let ((from (mail-header-from message-reply-headers))
2808 (date (mail-header-date message-reply-headers)))
2811 (string-match " *at \\| *@ \\| *(\\| *<" from)))
2812 (concat (if stop-pos (substring from 0 stop-pos) from)
2814 (if (or (not date) (string= date ""))
2815 "(unknown date)" date)
2818 (defun message-make-distribution ()
2819 "Make a Distribution header."
2820 (let ((orig-distribution (message-fetch-reply-field "distribution")))
2821 (cond ((message-functionp message-distribution-function)
2822 (funcall message-distribution-function))
2823 (t orig-distribution))))
2825 (defun message-make-expires ()
2826 "Return an Expires header based on `message-expires'."
2827 (let ((current (current-time))
2828 (future (* 1.0 message-expires 60 60 24)))
2829 ;; Add the future to current.
2830 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
2831 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
2832 ;; Return the date in the future in UT.
2833 (timezone-make-date-arpa-standard
2834 (current-time-string current) (current-time-zone current) '(0 "UT"))))
2836 (defun message-make-path ()
2838 (let ((login-name (user-login-name)))
2839 (cond ((null message-user-path)
2840 (concat (system-name) "!" login-name))
2841 ((stringp message-user-path)
2842 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
2843 (concat message-user-path "!" login-name))
2846 (defun message-make-from ()
2847 "Make a From header."
2848 (let* ((style message-from-style)
2849 (login (message-make-address))
2851 (or (and (boundp 'user-full-name)
2854 (when (string= fullname "&")
2855 (setq fullname (user-login-name)))
2857 (message-set-work-buffer)
2860 (equal fullname ""))
2862 ((or (eq style 'angles)
2863 (and (not (eq style 'parens))
2864 ;; Use angles if no quoting is needed, or if parens would
2865 ;; need quoting too.
2866 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
2867 (let ((tmp (concat fullname nil)))
2868 (while (string-match "([^()]*)" tmp)
2869 (aset tmp (match-beginning 0) ?-)
2870 (aset tmp (1- (match-end 0)) ?-))
2871 (string-match "[\\()]" tmp)))))
2873 (goto-char (point-min))
2874 ;; Look for a character that cannot appear unquoted
2875 ;; according to RFC 822.
2876 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
2877 ;; Quote fullname, escaping specials.
2878 (goto-char (point-min))
2880 (while (re-search-forward "[\"\\]" nil 1)
2881 (replace-match "\\\\\\&" t))
2883 (insert " <" login ">"))
2884 (t ; 'parens or default
2886 (let ((fullname-start (point)))
2888 (goto-char fullname-start)
2889 ;; RFC 822 says \ and nonmatching parentheses
2890 ;; must be escaped in comments.
2891 ;; Escape every instance of ()\ ...
2892 (while (re-search-forward "[()\\]" nil 1)
2893 (replace-match "\\\\\\&" t))
2894 ;; ... then undo escaping of matching parentheses,
2895 ;; including matching nested parentheses.
2896 (goto-char fullname-start)
2897 (while (re-search-forward
2898 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
2900 (replace-match "\\1(\\3)" t)
2901 (goto-char fullname-start)))
2905 (defun message-make-sender ()
2906 "Return the \"real\" user address.
2907 This function tries to ignore all user modifications, and
2908 give as trustworthy answer as possible."
2909 (concat (user-login-name) "@" (system-name)))
2911 (defun message-make-address ()
2912 "Make the address of the user."
2913 (or (message-user-mail-address)
2914 (concat (user-login-name) "@" (message-make-domain))))
2916 (defun message-user-mail-address ()
2917 "Return the pertinent part of `user-mail-address'."
2918 (when user-mail-address
2919 (if (string-match " " user-mail-address)
2920 (nth 1 (mail-extract-address-components user-mail-address))
2921 user-mail-address)))
2923 (defun message-make-fqdn ()
2924 "Return user's fully qualified domain name."
2925 (let ((system-name (system-name))
2926 (user-mail (message-user-mail-address)))
2928 ((string-match "[^.]\\.[^.]" system-name)
2929 ;; `system-name' returned the right result.
2931 ;; Try `mail-host-address'.
2932 ((and (boundp 'mail-host-address)
2933 (stringp mail-host-address)
2934 (string-match "\\." mail-host-address))
2936 ;; We try `user-mail-address' as a backup.
2938 (string-match "\\." user-mail)
2939 (string-match "@\\(.*\\)\\'" user-mail))
2940 (match-string 1 user-mail))
2941 ;; Default to this bogus thing.
2943 (concat system-name ".i-did-not-set--mail-host-address--so-shoot-me")))))
2945 (defun message-make-host-name ()
2946 "Return the name of the host."
2947 (let ((fqdn (message-make-fqdn)))
2948 (string-match "^[^.]+\\." fqdn)
2949 (substring fqdn 0 (1- (match-end 0)))))
2951 (defun message-make-domain ()
2952 "Return the domain name."
2953 (or mail-host-address
2954 (message-make-fqdn)))
2956 (defun message-generate-headers (headers)
2957 "Prepare article HEADERS.
2958 Headers already prepared in the buffer are not modified."
2960 (message-narrow-to-headers)
2961 (let* ((Date (message-make-date))
2962 (Message-ID (message-make-message-id))
2963 (Organization (message-make-organization))
2964 (From (message-make-from))
2965 (Path (message-make-path))
2968 (In-Reply-To (message-make-in-reply-to))
2970 (Distribution (message-make-distribution))
2971 (Lines (message-make-lines))
2972 (X-Newsreader message-newsreader)
2973 (X-Mailer (and (not (message-fetch-field "X-Newsreader"))
2975 (Expires (message-make-expires))
2976 (case-fold-search t)
2978 ;; First we remove any old generated headers.
2979 (let ((headers message-deletable-headers))
2980 (unless (buffer-modified-p)
2981 (setq headers (delq 'Message-ID (copy-sequence headers))))
2983 (goto-char (point-min))
2984 (and (re-search-forward
2985 (concat "^" (symbol-name (car headers)) ": *") nil t)
2986 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
2987 (message-delete-line))
2989 ;; Go through all the required headers and see if they are in the
2990 ;; articles already. If they are not, or are empty, they are
2991 ;; inserted automatically - except for Subject, Newsgroups and
2994 (goto-char (point-min))
2995 (setq elem (pop headers))
2997 (if (eq (car elem) 'optional)
2998 (setq header (cdr elem))
2999 (setq header (car elem)))
3001 (when (or (not (re-search-forward
3002 (concat "^" (downcase (symbol-name header)) ":")
3005 ;; The header was found. We insert a space after the
3006 ;; colon, if there is none.
3007 (if (/= (following-char) ? ) (insert " ") (forward-char 1))
3008 ;; Find out whether the header is empty...
3009 (looking-at "[ \t]*$")))
3010 ;; So we find out what value we should insert.
3013 ((and (consp elem) (eq (car elem) 'optional))
3014 ;; This is an optional header. If the cdr of this
3015 ;; is something that is nil, then we do not insert
3017 (setq header (cdr elem))
3018 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
3019 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
3021 ;; The element is a cons. Either the cdr is a
3022 ;; string to be inserted verbatim, or it is a
3023 ;; function, and we insert the value returned from
3025 (or (and (stringp (cdr elem)) (cdr elem))
3026 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
3027 ((and (boundp header) (symbol-value header))
3028 ;; The element is a symbol. We insert the value
3029 ;; of this symbol, if any.
3030 (symbol-value header))
3032 ;; We couldn't generate a value for this header,
3033 ;; so we just ask the user.
3034 (read-from-minibuffer
3035 (format "Empty header for %s; enter value: " header)))))
3036 ;; Finally insert the header.
3038 (not (equal value "")))
3042 ;; This header didn't exist, so we insert it.
3043 (goto-char (point-max))
3044 (insert (symbol-name header) ": " value "\n")
3046 ;; The value of this header was empty, so we clear
3047 ;; totally and insert the new value.
3048 (delete-region (point) (gnus-point-at-eol))
3050 ;; Add the deletable property to the headers that require it.
3051 (and (memq header message-deletable-headers)
3052 (progn (beginning-of-line) (looking-at "[^:]+: "))
3053 (add-text-properties
3054 (point) (match-end 0)
3055 '(message-deletable t face italic) (current-buffer)))))))
3056 ;; Insert new Sender if the From is strange.
3057 (let ((from (message-fetch-field "from"))
3058 (sender (message-fetch-field "sender"))
3059 (secure-sender (message-make-sender)))
3061 (not (message-check-element 'sender))
3064 (cadr (mail-extract-address-components from)))
3065 (downcase secure-sender)))
3070 (cadr (mail-extract-address-components sender)))
3071 (downcase secure-sender)))))
3072 (goto-char (point-min))
3073 ;; Rename any old Sender headers to Original-Sender.
3074 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
3076 (insert "Original-")
3077 (beginning-of-line))
3078 (when (or (message-news-p)
3079 (string-match "^[^@]@.+\\..+" secure-sender))
3080 (insert "Sender: " secure-sender "\n")))))))
3082 (defun message-insert-courtesy-copy ()
3083 "Insert a courtesy message in mail copies of combined messages."
3087 (message-narrow-to-headers)
3088 (when (setq newsgroups (message-fetch-field "newsgroups"))
3089 (goto-char (point-max))
3090 (insert "Posted-To: " newsgroups "\n")))
3092 (when message-courtesy-message
3094 ((string-match "%s" message-courtesy-message)
3095 (insert (format message-courtesy-message newsgroups)))
3097 (insert message-courtesy-message)))))))
3100 ;;; Setting up a message buffer
3103 (defun message-fill-address (header value)
3105 (narrow-to-region (point) (point))
3106 (insert (capitalize (symbol-name header))
3108 (if (consp value) (car value) value)
3110 (narrow-to-region (point-min) (1- (point-max)))
3112 (goto-char (point-min))
3114 (skip-chars-forward "^,\"" (point-max))
3115 (if (or (= (following-char) ?,)
3118 (if (and (> (current-column) 78)
3124 (setq last (1+ (point))))
3125 (setq last (1+ (point)))))
3126 (setq quoted (not quoted)))
3129 (goto-char (point-max))
3133 (defun message-fill-references (header value)
3134 (let ((begin (point))
3137 (insert (capitalize (symbol-name header))
3139 (std11-fill-msg-id-list-string
3140 (if (consp value) (car value) value))
3143 (defun message-fill-header (header value)
3144 (let ((begin (point))
3147 (insert (capitalize (symbol-name header))
3149 (if (consp value) (car value) value)
3152 (narrow-to-region begin (point))
3153 (fill-region-as-paragraph begin (point))
3154 ;; Tapdance around looong Message-IDs.
3156 (when (looking-at "[ \t]*$")
3157 (message-delete-line))
3159 (re-search-forward ":" nil t)
3160 (when (looking-at "\n[ \t]+")
3161 (replace-match " " t t))
3162 (goto-char (point-max)))))
3164 (defun message-position-point ()
3165 "Move point to where the user probably wants to find it."
3166 (message-narrow-to-headers)
3168 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
3169 (search-backward ":" )
3172 (if (= (following-char) ? )
3176 (goto-char (point-max))
3179 (unless (looking-at "$")
3183 (defun message-buffer-name (type &optional to group)
3184 "Return a new (unique) buffer name based on TYPE and TO."
3186 ;; Check whether `message-generate-new-buffers' is a function,
3187 ;; and if so, call it.
3188 ((message-functionp message-generate-new-buffers)
3189 (funcall message-generate-new-buffers type to group))
3190 ;; Generate a new buffer name The Message Way.
3191 (message-generate-new-buffers
3192 (generate-new-buffer-name
3196 (or (car (mail-extract-address-components to))
3199 (if (and group (not (string= group ""))) (concat " on " group) "")
3201 ;; Use standard name.
3203 (format "*%s message*" type))))
3205 (defun message-pop-to-buffer (name)
3206 "Pop to buffer NAME, and warn if it already exists and is modified."
3207 (let ((buffer (get-buffer name)))
3209 (buffer-name buffer))
3211 (set-buffer (pop-to-buffer buffer))
3212 (when (and (buffer-modified-p)
3214 "Message already being composed; erase? ")))
3215 (error "Message being composed")))
3216 (set-buffer (pop-to-buffer name))))
3220 (defun message-do-send-housekeeping ()
3221 "Kill old message buffers."
3222 ;; We might have sent this buffer already. Delete it from the
3224 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
3225 (while (and message-max-buffers
3227 (>= (length message-buffer-list) message-max-buffers))
3228 ;; Kill the oldest buffer -- unless it has been changed.
3229 (let ((buffer (pop message-buffer-list)))
3230 (when (and (buffer-name buffer)
3231 (not (buffer-modified-p buffer)))
3232 (kill-buffer buffer))))
3233 ;; Rename the buffer.
3234 (if message-send-rename-function
3235 (funcall message-send-rename-function)
3236 (when (string-match "\\`\\*" (buffer-name))
3238 (concat "*sent " (substring (buffer-name) (match-end 0))) t)))
3239 ;; Push the current buffer onto the list.
3240 (when message-max-buffers
3241 (setq message-buffer-list
3242 (nconc message-buffer-list (list (current-buffer))))))
3244 (defvar mc-modes-alist)
3245 (defun message-setup (headers &optional replybuffer actions)
3246 (when (and (boundp 'mc-modes-alist)
3247 (not (assq 'message-mode mc-modes-alist)))
3248 (push '(message-mode (encrypt . mc-encrypt-message)
3249 (sign . mc-sign-message))
3252 (setq message-send-actions actions))
3253 (setq message-reply-buffer replybuffer)
3254 (goto-char (point-min))
3255 ;; Insert all the headers.
3258 (alist message-header-format-alist))
3260 (unless (assq (caar h) message-header-format-alist)
3261 (push (list (caar h)) alist))
3265 (delete-region (point) (progn (forward-line -1) (point)))
3266 (when message-default-headers
3267 (insert message-default-headers)
3268 (or (bolp) (insert ?\n)))
3272 (insert mail-header-separator "\n")
3276 (when (message-news-p)
3277 (when message-default-news-headers
3278 (insert message-default-news-headers)
3279 (or (bolp) (insert ?\n)))
3280 (when message-generate-headers-first
3281 (message-generate-headers
3284 (copy-sequence message-required-news-headers))))))
3285 (when (message-mail-p)
3286 (when message-default-mail-headers
3287 (insert message-default-mail-headers)
3288 (or (bolp) (insert ?\n)))
3289 (when message-generate-headers-first
3290 (message-generate-headers
3293 (copy-sequence message-required-mail-headers))))))
3294 (run-hooks 'message-signature-setup-hook)
3295 (message-insert-signature)
3297 (message-narrow-to-headers)
3298 (run-hooks 'message-header-setup-hook))
3299 (set-buffer-modified-p nil)
3300 (setq buffer-undo-list nil)
3301 (run-hooks 'message-setup-hook)
3302 (message-position-point)
3305 (defun message-set-auto-save-file-name ()
3306 "Associate the message buffer with a file in the drafts directory."
3307 (when message-autosave-directory
3308 (setq message-draft-article (nndraft-request-associate-buffer "drafts"))
3309 (clear-visited-file-modtime)))
3311 (defun message-disassociate-draft ()
3312 "Disassociate the message buffer from the drafts directory."
3313 (when message-draft-article
3314 (nndraft-request-expire-articles
3315 (list message-draft-article) "drafts" nil t)))
3320 ;;; Commands for interfacing with message
3324 (defun message-mail (&optional to subject
3325 other-headers continue switch-function
3326 yank-action send-actions)
3327 "Start editing a mail message to be sent."
3329 (let ((message-this-is-mail t))
3330 (message-pop-to-buffer (message-buffer-name "mail" to))
3333 `((To . ,(or to "")) (Subject . ,(or subject "")))
3334 (when other-headers other-headers)))))
3337 (defun message-news (&optional newsgroups subject)
3338 "Start editing a news article to be sent."
3340 (let ((message-this-is-news t))
3341 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))
3342 (message-setup `((Newsgroups . ,(or newsgroups ""))
3343 (Subject . ,(or subject ""))))))
3346 (defun message-reply (&optional to-address wide ignore-reply-to)
3347 "Start editing a reply to the article in the current buffer."
3349 (let ((cur (current-buffer))
3350 from subject date reply-to to cc
3351 references message-id follow-to
3352 (inhibit-point-motion-hooks t)
3353 mct never-mct gnus-warning)
3355 (message-narrow-to-head)
3356 ;; Allow customizations to have their say.
3358 ;; This is a regular reply.
3359 (if (message-functionp message-reply-to-function)
3360 (setq follow-to (funcall message-reply-to-function)))
3361 ;; This is a followup.
3362 (if (message-functionp message-wide-reply-to-function)
3365 (funcall message-wide-reply-to-function)))))
3366 ;; Find all relevant headers we need.
3367 (setq from (message-fetch-field "from")
3368 date (message-fetch-field "date")
3369 subject (or (message-fetch-field "subject") "none")
3370 to (message-fetch-field "to")
3371 cc (message-fetch-field "cc")
3372 mct (message-fetch-field "mail-copies-to")
3373 reply-to (unless ignore-reply-to (message-fetch-field "reply-to"))
3374 references (message-fetch-field "references")
3375 message-id (message-fetch-field "message-id" t))
3376 ;; Remove any (buggy) Re:'s that are present and make a
3378 (when (string-match "^[ \t]*[Rr][Ee]:[ \t]*" subject)
3379 (setq subject (substring subject (match-end 0))))
3380 (setq subject (concat "Re: " subject))
3382 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
3383 (string-match "<[^>]+>" gnus-warning))
3384 (setq message-id (match-string 0 gnus-warning)))
3386 ;; Handle special values of Mail-Copies-To.
3388 (cond ((equal (downcase mct) "never")
3391 ((equal (downcase mct) "always")
3392 (setq mct (or reply-to from)))))
3398 (setq follow-to (list (cons 'To (or to-address reply-to from))))
3399 (when (and wide mct)
3400 (push (cons 'Cc mct) follow-to)))
3403 (message-set-work-buffer)
3405 (insert (or reply-to from "")))
3406 (insert (if to (concat (if (bolp) "" ", ") to "") ""))
3407 (insert (if mct (concat (if (bolp) "" ", ") mct) ""))
3408 (insert (if cc (concat (if (bolp) "" ", ") cc) ""))
3409 (goto-char (point-min))
3410 (while (re-search-forward "[ \t]+" nil t)
3411 (replace-match " " t t))
3412 ;; Remove addresses that match `rmail-dont-reply-to-names'.
3413 (insert (prog1 (rmail-dont-reply-to (buffer-string))
3415 (goto-char (point-min))
3416 ;; Perhaps Mail-Copies-To: never removed the only address?
3418 (insert (or reply-to from "")))
3422 (cons (mail-strip-quoted-names addr) addr))
3423 (message-tokenize-header (buffer-string))))
3426 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
3427 (setq follow-to (list (cons 'To (cdr (pop ccalist)))))
3429 (let ((ccs (cons 'Cc (mapconcat
3430 (lambda (addr) (cdr addr)) ccalist ", "))))
3431 (when (string-match "^ +" (cdr ccs))
3432 (setcdr ccs (substring (cdr ccs) (match-end 0))))
3433 (push ccs follow-to))))))
3436 (message-pop-to-buffer (message-buffer-name
3437 (if wide "wide reply" "reply") from
3438 (if wide to-address nil)))
3440 (setq message-reply-headers
3441 (vector 0 subject from date message-id references 0 0 ""))
3444 `((Subject . ,subject)
3446 ,@(if (or references message-id)
3447 `((References . ,(concat (or references "") (and references " ")
3448 (or message-id ""))))
3453 (defun message-wide-reply (&optional to-address ignore-reply-to)
3454 "Make a \"wide\" reply to the message in the current buffer."
3456 (message-reply to-address t ignore-reply-to))
3459 (defun message-followup (&optional to-newsgroups)
3460 "Follow up to the message in the current buffer.
3461 If TO-NEWSGROUPS, use that as the new Newsgroups line."
3463 (let ((cur (current-buffer))
3464 from subject date reply-to mct
3465 references message-id follow-to
3466 (inhibit-point-motion-hooks t)
3467 (message-this-is-news t)
3468 followup-to distribution newsgroups gnus-warning posted-to)
3471 (goto-char (point-min))
3472 (if (search-forward "\n\n" nil t)
3475 (when (message-functionp message-followup-to-function)
3477 (funcall message-followup-to-function)))
3478 (setq from (message-fetch-field "from")
3479 date (message-fetch-field "date")
3480 subject (or (message-fetch-field "subject") "none")
3481 references (message-fetch-field "references")
3482 message-id (message-fetch-field "message-id" t)
3483 followup-to (message-fetch-field "followup-to")
3484 newsgroups (message-fetch-field "newsgroups")
3485 posted-to (message-fetch-field "posted-to")
3486 reply-to (message-fetch-field "reply-to")
3487 distribution (message-fetch-field "distribution")
3488 mct (message-fetch-field "mail-copies-to"))
3489 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
3490 (string-match "<[^>]+>" gnus-warning))
3491 (setq message-id (match-string 0 gnus-warning)))
3492 ;; Remove bogus distribution.
3493 (when (and (stringp distribution)
3494 (let ((case-fold-search t))
3495 (string-match "world" distribution)))
3496 (setq distribution nil))
3497 ;; Remove any (buggy) Re:'s that are present and make a
3499 (when (string-match "^[ \t]*[Rr][Ee]:[ \t]*" subject)
3500 (setq subject (substring subject (match-end 0))))
3501 (setq subject (concat "Re: " subject))
3504 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
3507 `((Subject . ,subject)
3510 (list (cons 'Newsgroups to-newsgroups)))
3511 (follow-to follow-to)
3512 ((and followup-to message-use-followup-to)
3515 ((equal (downcase followup-to) "poster")
3516 (if (or (eq message-use-followup-to 'use)
3517 (message-y-or-n-p "Obey Followup-To: poster? " t "\
3518 You should normally obey the Followup-To: header.
3520 `Followup-To: poster' sends your response via e-mail instead of news.
3522 A typical situation where `Followup-To: poster' is used is when the poster
3523 does not read the newsgroup, so he wouldn't see any replies sent to it."))
3525 (setq message-this-is-news nil)
3526 (cons 'To (or reply-to from "")))
3527 (cons 'Newsgroups newsgroups)))
3529 (if (or (equal followup-to newsgroups)
3530 (not (eq message-use-followup-to 'ask))
3532 (concat "Obey Followup-To: " followup-to "? ") t "\
3533 You should normally obey the Followup-To: header.
3535 `Followup-To: " followup-to "'
3536 directs your response to " (if (string-match "," followup-to)
3537 "the specified newsgroups"
3538 "that newsgroup only") ".
3540 If a message is posted to several newsgroups, Followup-To is often
3541 used to direct the following discussion to one newsgroup only,
3542 because discussions that are spread over several newsgroup tend to
3543 be fragmented and very difficult to follow.
3545 Also, some source/announcement newsgroups are not indented for discussion;
3546 responses here are directed to other newsgroups."))
3547 (cons 'Newsgroups followup-to)
3548 (cons 'Newsgroups newsgroups))))))
3550 `((Newsgroups . ,posted-to)))
3552 `((Newsgroups . ,newsgroups))))
3553 ,@(and distribution (list (cons 'Distribution distribution)))
3554 ,@(if (or references message-id)
3555 `((References . ,(concat (or references "") (and references " ")
3556 (or message-id "")))))
3558 (not (equal (downcase mct) "never")))
3559 (list (cons 'Cc (if (equal (downcase mct) "always")
3560 (or reply-to from "")
3565 (setq message-reply-headers
3566 (vector 0 subject from date message-id references 0 0 ""))))
3570 (defun message-cancel-news ()
3571 "Cancel an article you posted."
3573 (unless (message-news-p)
3574 (error "This is not a news article; canceling is impossible"))
3575 (when (yes-or-no-p "Do you really want to cancel this article? ")
3576 (let (from newsgroups message-id distribution buf)
3578 ;; Get header info. from original article.
3580 (message-narrow-to-head)
3581 (setq from (message-fetch-field "from")
3582 newsgroups (message-fetch-field "newsgroups")
3583 message-id (message-fetch-field "message-id" t)
3584 distribution (message-fetch-field "distribution")))
3585 ;; Make sure that this article was written by the user.
3586 (unless (string-equal
3587 (downcase (cadr (std11-extract-address-components from)))
3588 (downcase (message-make-address)))
3589 (error "This article is not yours"))
3590 ;; Make control message.
3591 (setq buf (set-buffer (get-buffer-create " *message cancel*")))
3592 (buffer-disable-undo (current-buffer))
3594 (insert "Newsgroups: " newsgroups "\n"
3595 "From: " (message-make-from) "\n"
3596 "Subject: cmsg cancel " message-id "\n"
3597 "Control: cancel " message-id "\n"
3599 (concat "Distribution: " distribution "\n")
3601 mail-header-separator "\n"
3602 message-cancel-message)
3603 (message "Canceling your article...")
3604 (if (let ((message-syntax-checks
3605 'dont-check-for-anything-just-trust-me)
3606 (message-encoding-buffer (current-buffer))
3607 (message-edit-buffer (current-buffer)))
3608 (message-send-news))
3609 (message "Canceling your article...done"))
3610 (kill-buffer buf)))))
3613 (defun message-supersede ()
3614 "Start composing a message to supersede the current message.
3615 This is done simply by taking the old article and adding a Supersedes
3616 header line with the old Message-ID."
3618 (let ((cur (current-buffer)))
3619 ;; Check whether the user owns the article that is to be superseded.
3620 (unless (string-equal
3621 (downcase (cadr (mail-extract-address-components
3622 (message-fetch-field "from"))))
3623 (downcase (message-make-address)))
3624 (error "This article is not yours"))
3625 ;; Get a normal message buffer.
3626 (message-pop-to-buffer (message-buffer-name "supersede"))
3627 (insert-buffer-substring cur)
3628 (message-narrow-to-head)
3629 ;; Remove unwanted headers.
3630 (when message-ignored-supersedes-headers
3631 (message-remove-header message-ignored-supersedes-headers t))
3632 (goto-char (point-min))
3633 (if (not (re-search-forward "^Message-ID: " nil t))
3634 (error "No Message-ID in this article")
3635 (replace-match "Supersedes: " t t))
3636 (goto-char (point-max))
3637 (insert mail-header-separator)
3642 (defun message-recover ()
3643 "Reread contents of current buffer from its last auto-save file."
3645 (let ((file-name (make-auto-save-file-name)))
3646 (cond ((save-window-excursion
3647 (if (not (eq system-type 'vax-vms))
3648 (with-output-to-temp-buffer "*Directory*"
3649 (buffer-disable-undo standard-output)
3650 (let ((default-directory "/"))
3652 "ls" nil standard-output nil "-l" file-name))))
3653 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
3654 (let ((buffer-read-only nil))
3656 (insert-file-contents file-name nil)))
3657 (t (error "message-recover cancelled")))))
3659 ;;; Forwarding messages.
3661 (defun message-make-forward-subject ()
3662 "Return a Subject header suitable for the message in the current buffer."
3666 (message-narrow-to-head)
3667 (concat "[" (or (message-fetch-field
3668 (if (message-news-p) "newsgroups" "from"))
3670 "] " (or (message-fetch-field "Subject") "")))))
3673 (defun message-forward (&optional news)
3674 "Forward the current message via mail.
3675 Optional NEWS will use news to forward instead of mail."
3677 (let ((cur (current-buffer))
3678 (subject (message-make-forward-subject))
3680 (if news (message-news nil subject) (message-mail nil subject))
3681 ;; Put point where we want it before inserting the forwarded
3683 (if message-signature-before-forwarded-message
3684 (goto-char (point-max))
3685 (message-goto-body))
3686 ;; Make sure we're at the start of the line.
3689 ;; Narrow to the area we are to insert.
3690 (narrow-to-region (point) (point))
3691 ;; Insert the separators and the forwarded buffer.
3692 (insert message-forward-start-separator)
3693 (setq art-beg (point))
3694 (insert-buffer-substring cur)
3695 (goto-char (point-max))
3696 (insert message-forward-end-separator)
3697 (set-text-properties (point-min) (point-max) nil)
3698 ;; Remove all unwanted headers.
3700 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
3703 (goto-char (point-min))
3704 (message-remove-header message-included-forward-headers t nil t)
3706 (message-position-point)))
3709 (defun message-resend (address)
3710 "Resend the current article to ADDRESS."
3711 (interactive "sResend message to: ")
3712 (message "Resending message to %s..." address)
3714 (let ((cur (current-buffer))
3716 ;; We first set up a normal mail buffer.
3717 (set-buffer (get-buffer-create " *message resend*"))
3718 (buffer-disable-undo (current-buffer))
3720 ;; avoid to turn-on-mime-edit
3721 (let (message-setup-hook)
3722 (message-setup `((To . ,address)))
3724 ;; Insert our usual headers.
3725 (message-generate-headers '(From Date To))
3726 (message-narrow-to-headers)
3727 ;; Rename them all to "Resent-*".
3728 (while (re-search-forward "^[A-Za-z]" nil t)
3733 (delete-region (point) (point-max))
3735 ;; Insert the message to be resent.
3736 (insert-buffer-substring cur)
3737 (goto-char (point-min))
3738 (search-forward "\n\n")
3741 (narrow-to-region beg (point))
3742 (message-remove-header message-ignored-resent-headers t)
3743 (goto-char (point-max)))
3744 (insert mail-header-separator)
3745 ;; Rename all old ("Also-")Resent headers.
3746 (while (re-search-backward "^\\(Also-\\)?Resent-" beg t)
3749 ;; Quote any "From " lines at the beginning.
3751 (when (looking-at "From ")
3752 (replace-match "X-From-Line: "))
3754 (let ((message-encoding-buffer (current-buffer))
3755 (message-edit-buffer (current-buffer)))
3756 (message-send-mail))
3757 (kill-buffer (current-buffer)))
3758 (message "Resending message to %s...done" address)))
3761 (defun message-bounce ()
3762 "Re-mail the current message.
3763 This only makes sense if the current message is a bounce message than
3764 contains some mail you have written which has been bounced back to
3767 (let ((cur (current-buffer))
3769 (message-pop-to-buffer (message-buffer-name "bounce"))
3770 (insert-buffer-substring cur)
3772 (message-narrow-to-head)
3773 (if (and (message-fetch-field "Mime-Version")
3774 (setq boundary (message-fetch-field "Content-Type")))
3775 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary)
3776 (setq boundary (concat (match-string 1 boundary) " *\n"
3777 "Content-Type: message/rfc822"))
3778 (setq boundary nil)))
3780 (goto-char (point-min))
3781 (search-forward "\n\n" nil t)
3783 (re-search-forward boundary nil t)
3785 (and (re-search-forward message-unsent-separator nil t)
3787 (re-search-forward "^Return-Path:.*\n" nil t))
3788 ;; We remove everything before the bounced mail.
3791 (if (re-search-forward "^[^ \n\t]+:" nil t)
3795 (message-narrow-to-head)
3796 (message-remove-header message-ignored-bounced-headers t)
3797 (goto-char (point-max))
3798 (insert mail-header-separator))
3799 (message-position-point)))
3802 ;;; Interactive entry points for new message buffers.
3806 (defun message-mail-other-window (&optional to subject)
3807 "Like `message-mail' command, but display mail buffer in another window."
3809 (let ((pop-up-windows t)
3810 (special-display-buffer-names nil)
3811 (special-display-regexps nil)
3812 (same-window-buffer-names nil)
3813 (same-window-regexps nil))
3814 (message-pop-to-buffer (message-buffer-name "mail" to)))
3815 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))))
3818 (defun message-mail-other-frame (&optional to subject)
3819 "Like `message-mail' command, but display mail buffer in another frame."
3821 (let ((pop-up-frames t)
3822 (special-display-buffer-names nil)
3823 (special-display-regexps nil)
3824 (same-window-buffer-names nil)
3825 (same-window-regexps nil))
3826 (message-pop-to-buffer (message-buffer-name "mail" to)))
3827 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))))
3830 (defun message-news-other-window (&optional newsgroups subject)
3831 "Start editing a news article to be sent."
3833 (let ((pop-up-windows t)
3834 (special-display-buffer-names nil)
3835 (special-display-regexps nil)
3836 (same-window-buffer-names nil)
3837 (same-window-regexps nil))
3838 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
3839 (message-setup `((Newsgroups . ,(or newsgroups ""))
3840 (Subject . ,(or subject "")))))
3843 (defun message-news-other-frame (&optional newsgroups subject)
3844 "Start editing a news article to be sent."
3846 (let ((pop-up-frames t)
3847 (special-display-buffer-names nil)
3848 (special-display-regexps nil)
3849 (same-window-buffer-names nil)
3850 (same-window-regexps nil))
3851 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
3852 (message-setup `((Newsgroups . ,(or newsgroups ""))
3853 (Subject . ,(or subject "")))))
3857 ;; This code should be moved to underline.el (from which it is stolen).
3860 (defun bold-region (start end)
3861 "Bold all nonblank characters in the region.
3862 Works by overstriking characters.
3863 Called from program, takes two arguments START and END
3864 which specify the range to operate on."
3867 (let ((end1 (make-marker)))
3868 (move-marker end1 (max start end))
3869 (goto-char (min start end))
3870 (while (< (point) end1)
3871 (or (looking-at "[_\^@- ]")
3872 (insert (following-char) "\b"))
3873 (forward-char 1)))))
3876 (defun unbold-region (start end)
3877 "Remove all boldness (overstruck characters) in the region.
3878 Called from program, takes two arguments START and END
3879 which specify the range to operate on."
3882 (let ((end1 (make-marker)))
3883 (move-marker end1 (max start end))
3884 (goto-char (min start end))
3885 (while (re-search-forward "\b" end1 t)
3886 (if (eq (following-char) (char-after (- (point) 2)))
3887 (delete-char -2))))))
3889 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
3891 ;; Support for toolbar
3892 (when (string-match "XEmacs\\|Lucid" emacs-version)
3893 (require 'messagexmas))
3895 ;;; Group name completion.
3897 (defvar message-newgroups-header-regexp
3898 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
3899 "Regexp that match headers that lists groups.")
3901 (defun message-tab ()
3902 "Expand group names in Newsgroups and Followup-To headers.
3903 Do a `tab-to-tab-stop' if not in those headers."
3905 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp))
3906 (mail-abbrev-in-expansion-header-p))
3907 (message-expand-group)
3910 (defvar gnus-active-hashtb)
3911 (defun message-expand-group ()
3912 "Expand the group name under point."
3913 (let* ((b (save-excursion
3918 (skip-chars-forward "^:")
3921 (skip-chars-backward "^, \t\n") (point))))
3922 (completion-ignore-case t)
3923 (string (buffer-substring b (point)))
3924 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
3925 (completions (all-completions string hashtb))
3926 (cur (current-buffer))
3928 (delete-region b (point))
3930 ((= (length completions) 1)
3931 (if (string= (car completions) string)
3934 (message "Only matching group"))
3935 (insert (car completions))))
3936 ((and (setq comp (try-completion string hashtb))
3937 (not (string= comp string)))
3942 (message "No matching groups")
3943 (save-selected-window
3944 (pop-to-buffer "*Completions*")
3945 (buffer-disable-undo (current-buffer))
3946 (let ((buffer-read-only nil))
3948 (let ((standard-output (current-buffer)))
3949 (display-completion-list (sort completions 'string<)))
3950 (goto-char (point-min))
3951 (delete-region (point) (progn (forward-line 3) (point))))))))))
3955 (defun message-talkative-question (ask question show &rest text)
3956 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
3957 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
3958 The following arguments may contain lists of values."
3960 (setq text (message-flatten-list text)))
3961 (save-window-excursion
3963 (with-output-to-temp-buffer " *MESSAGE information message*"
3964 (set-buffer " *MESSAGE information message*")
3965 (mapcar 'princ text)
3966 (goto-char (point-min))))
3967 (funcall ask question))
3968 (funcall ask question)))
3970 (defun message-flatten-list (list)
3971 "Return a new, flat list that contains all elements of LIST.
3973 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
3976 (apply 'append (mapcar 'message-flatten-list list)))
3980 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
3981 "Create and return a buffer with a name based on NAME using generate-new-buffer.
3982 Then clone the local variables and values from the old buffer to the
3983 new one, cloning only the locals having a substring matching the
3985 (let ((oldbuf (current-buffer)))
3987 (set-buffer (generate-new-buffer name))
3988 (message-clone-locals oldbuf)
3991 (defun message-clone-locals (buffer)
3992 "Clone the local variables from BUFFER to the current buffer."
3993 (let ((locals (save-excursion
3995 (buffer-local-variables)))
3996 (regexp "^gnus\\|^nn\\|^message"))
3999 (when (and (consp local)
4001 (string-match regexp (symbol-name (car local))))
4003 (set (make-local-variable (car local))
4008 ;;; @ for MIME Edit mode
4011 (defun message-maybe-setup-default-charset ()
4013 (and (boundp 'gnus-summary-buffer)
4014 (buffer-live-p gnus-summary-buffer)
4016 (set-buffer gnus-summary-buffer)
4017 default-mime-charset))))
4020 (make-local-variable 'default-mime-charset)
4021 (setq default-mime-charset charset)
4024 (defun message-maybe-encode ()
4025 (when message-mime-mode
4026 (run-hooks 'mime-edit-translate-hook)
4027 (if (catch 'mime-edit-error
4029 (mime-edit-translate-body)
4031 (error "Translation error!")
4034 (run-hooks 'mime-edit-exit-hook)
4037 (defun message-mime-insert-article (&optional message)
4039 (let ((message-cite-function 'mime-edit-inserted-message-filter)
4040 (message-reply-buffer gnus-original-article-buffer)
4042 (message-yank-original nil)
4045 (set-alist 'mime-edit-message-inserter-alist
4046 'message-mode (function message-mime-insert-article))
4048 ;;; Miscellaneous functions
4050 ;; stolen (and renamed) from nnheader.el
4051 (defun message-replace-chars-in-string (string from to)
4052 "Replace characters in STRING from FROM to TO."
4053 (let ((string (substring string 0)) ;Copy string.
4054 (len (length string))
4056 ;; Replace all occurrences of FROM with TO.
4058 (when (= (aref string idx) from)
4059 (aset string idx to))
4060 (setq idx (1+ idx)))
4063 (run-hooks 'message-load-hook)
4067 ;;; message.el ends here