1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; Keywords: mail, news
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
26 ;; This mode provides mail-sending facilities from within Emacs. It
27 ;; consists mainly of large chunks of code from the sendmail.el,
28 ;; gnus-msg.el and rnewspost.el files.
32 (eval-when-compile (require 'cl
))
39 (if (string-match "XEmacs\\|Lucid" emacs-version
)
40 (require 'mail-abbrevs
)
41 (require 'mailabbrev
))
43 (defgroup message
'((user-mail-address custom-variable
)
44 (user-full-name custom-variable
))
45 "Mail and news message composing."
46 :link
'(custom-manual "(message)Top")
50 (put 'user-mail-address
'custom-type
'string
)
51 (put 'user-full-name
'custom-type
'string
)
53 (defgroup message-various nil
54 "Various Message Variables"
55 :link
'(custom-manual "(message)Various Message Variables")
58 (defgroup message-buffers nil
60 :link
'(custom-manual "(message)Message Buffers")
63 (defgroup message-sending nil
65 :link
'(custom-manual "(message)Sending Variables")
68 (defgroup message-interface nil
70 :link
'(custom-manual "(message)Interface")
73 (defgroup message-forwarding nil
75 :link
'(custom-manual "(message)Forwarding")
76 :group
'message-interface
)
78 (defgroup message-insertion nil
80 :link
'(custom-manual "(message)Insertion")
83 (defgroup message-headers nil
85 :link
'(custom-manual "(message)Message Headers")
88 (defgroup message-news nil
89 "Composing News Messages"
92 (defgroup message-mail nil
93 "Composing Mail Messages"
96 (defgroup message-faces nil
97 "Faces used for message composing."
101 (defcustom message-directory
"~/Mail/"
102 "*Directory from which all other mail file variables are derived."
103 :group
'message-various
106 (defcustom message-max-buffers
10
107 "*How many buffers to keep before starting to kill them off."
108 :group
'message-buffers
111 (defcustom message-send-rename-function nil
112 "Function called to rename the buffer after sending it."
113 :group
'message-buffers
116 (defcustom message-fcc-handler-function
'message-output
117 "*A function called to save outgoing articles.
118 This function will be called with the name of the file to store the
119 article in. The default function is `message-output' which saves in Unix
121 :type
'(radio (function-item message-output
)
122 (function :tag
"Other"))
123 :group
'message-sending
)
125 (defcustom message-courtesy-message
126 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
127 "*This is inserted at the start of a mailed copy of a posted message.
128 If the string contains the format spec \"%s\", the Newsgroups
129 the article has been posted to will be inserted there.
130 If this variable is nil, no such courtesy message will be added."
131 :group
'message-sending
134 (defcustom message-ignored-bounced-headers
"^\\(Received\\|Return-Path\\):"
135 "*Regexp that matches headers to be removed in resent bounced mail."
136 :group
'message-interface
140 (defcustom message-from-style
'default
141 "*Specifies how \"From\" headers look.
143 If `nil', they contain just the return address like:
145 If `parens', they look like:
146 king@grassland.com (Elvis Parsley)
147 If `angles', they look like:
148 Elvis Parsley <king@grassland.com>
150 Otherwise, most addresses look like `angles', but they look like
151 `parens' if `angles' would need quoting and `parens' would not."
152 :type
'(choice (const :tag
"simple" nil
)
156 :group
'message-headers
)
158 (defcustom message-syntax-checks nil
159 ; Guess this one shouldn't be easy to customize...
160 "*Controls what syntax checks should not be performed on outgoing posts.
161 To disable checking of long signatures, for instance, add
162 `(signature . disabled)' to this list.
164 Don't touch this variable unless you really know what you're doing.
166 Checks include subject-cmsg multiple-headers sendsys message-id from
167 long-lines control-chars size new-text redirected-followup signature
168 approved sender empty empty-headers message-id from subject
169 shorten-followup-to existing-newsgroups buffer-file-name unchanged."
170 :group
'message-news
)
172 (defcustom message-required-news-headers
173 '(From Newsgroups Subject Date Message-ID
174 (optional . Organization
) Lines
175 (optional . X-Newsreader
))
176 "*Headers to be generated or prompted for when posting an article.
177 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
178 Message-ID. Organization, Lines, In-Reply-To, Expires, and
179 X-Newsreader are optional. If don't you want message to insert some
180 header, remove it from this list."
182 :group
'message-headers
183 :type
'(repeat sexp
))
185 (defcustom message-required-mail-headers
186 '(From Subject Date
(optional . In-Reply-To
) Message-ID Lines
187 (optional . X-Mailer
))
188 "*Headers to be generated or prompted for when mailing a message.
189 RFC822 required that From, Date, To, Subject and Message-ID be
190 included. Organization, Lines and X-Mailer are optional."
192 :group
'message-headers
193 :type
'(repeat sexp
))
195 (defcustom message-deletable-headers
'(Message-ID Date Lines
)
196 "Headers to be deleted if they already exist and were generated by message previously."
197 :group
'message-headers
200 (defcustom message-ignored-news-headers
201 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:"
202 "*Regexp of headers to be removed unconditionally before posting."
204 :group
'message-headers
207 (defcustom message-ignored-mail-headers
"^[GF]cc:\\|^Resent-Fcc:\\|^Xref:"
208 "*Regexp of headers to be removed unconditionally before mailing."
210 :group
'message-headers
213 (defcustom message-ignored-supersedes-headers
"^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|^X-Trace:\\|^X-Complaints-To:\\|Return-Path:\\|^Supersedes:\\|^X-Trace:\\|^X-Complaints-To:\\|^NNTP-Posting-Date:"
214 "*Header lines matching this regexp will be deleted before posting.
215 It's best to delete old Path and Date headers before posting to avoid
217 :group
'message-interface
220 (defcustom message-subject-re-regexp
"^[ \t]*\\([Rr][Ee]:[ \t]*\\)*[ \t]*"
221 "*Regexp matching \"Re: \" in the subject line."
222 :group
'message-various
226 (defcustom message-signature-separator
"^-- *$"
227 "Regexp matching the signature separator."
229 :group
'message-various
)
231 (defcustom message-elide-elipsis
"\n[...]\n\n"
232 "*The string which is inserted for elided text."
234 :group
'message-various
)
236 (defcustom message-interactive nil
237 "Non-nil means when sending a message wait for and display errors.
238 nil means let mailer mail back a message to report errors."
239 :group
'message-sending
243 (defcustom message-generate-new-buffers t
244 "*Non-nil means that a new message buffer will be created whenever `message-setup' is called.
245 If this is a function, call that function with three parameters: The type,
246 the to address and the group name. (Any of these may be nil.) The function
247 should return the new buffer name."
248 :group
'message-buffers
249 :type
'(choice (const :tag
"off" nil
)
253 (defcustom message-kill-buffer-on-exit nil
254 "*Non-nil means that the message buffer will be killed after sending a message."
255 :group
'message-buffers
258 (defvar gnus-local-organization
)
259 (defcustom message-user-organization
260 (or (and (boundp 'gnus-local-organization
)
261 (stringp gnus-local-organization
)
262 gnus-local-organization
)
263 (getenv "ORGANIZATION")
265 "*String to be used as an Organization header.
266 If t, use `message-user-organization-file'."
267 :group
'message-headers
268 :type
'(choice string
269 (const :tag
"consult file" t
)))
272 (defcustom message-user-organization-file
"/usr/lib/news/organization"
273 "*Local news organization file."
275 :group
'message-headers
)
277 (defcustom message-forward-start-separator
278 "------- Start of forwarded message -------\n"
279 "*Delimiter inserted before forwarded messages."
280 :group
'message-forwarding
283 (defcustom message-forward-end-separator
284 "------- End of forwarded message -------\n"
285 "*Delimiter inserted after forwarded messages."
286 :group
'message-forwarding
289 (defcustom message-signature-before-forwarded-message t
290 "*If non-nil, put the signature before any included forwarded message."
291 :group
'message-forwarding
294 (defcustom message-included-forward-headers
295 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-\\|^Message-ID:\\|^References:\\|^Content-Transfer-Encoding:\\|^Content-Type:\\|^Mime-Version:"
296 "*Regexp matching headers to be included in forwarded messages."
297 :group
'message-forwarding
300 (defcustom message-make-forward-subject-function
301 'message-forward-subject-author-subject
302 "*A list of functions that are called to generate a subject header for forwarded messages.
303 The subject generated by the previous function is passed into each
306 The provided functions are:
308 * message-forward-subject-author-subject (Source of article (author or
309 newsgroup)), in brackets followed by the subject
310 * message-forward-subject-fwd (Subject of article with 'Fwd:' prepended
312 :group
'message-forwarding
313 :type
'(radio (function-item message-forward-subject-author-subject
)
314 (function-item message-forward-subject-fwd
)))
316 (defcustom message-wash-forwarded-subjects nil
317 "*If non-nil, try to remove as much old cruft as possible from the subject of messages before generating the new subject of a forward."
318 :group
'message-forwarding
321 (defcustom message-ignored-resent-headers
"^Return-receipt"
322 "*All headers that match this regexp will be deleted when resending a message."
323 :group
'message-interface
326 (defcustom message-ignored-cited-headers
"."
327 "*Delete these headers from the messages you yank."
328 :group
'message-insertion
331 (defcustom message-cancel-message
"I am canceling my own article."
332 "Message to be inserted in the cancel message."
333 :group
'message-interface
336 ;; Useful to set in site-init.el
338 (defcustom message-send-mail-function
'message-send-mail-with-sendmail
339 "Function to call to send the current buffer as mail.
340 The headers should be delimited by a line whose contents match the
341 variable `mail-header-separator'.
343 Legal values include `message-send-mail-with-sendmail' (the default),
344 `message-send-mail-with-mh', `message-send-mail-with-qmail' and
346 :type
'(radio (function-item message-send-mail-with-sendmail
)
347 (function-item message-send-mail-with-mh
)
348 (function-item message-send-mail-with-qmail
)
349 (function-item smtpmail-send-it
)
350 (function :tag
"Other"))
351 :group
'message-sending
352 :group
'message-mail
)
354 (defcustom message-send-news-function
'message-send-news
355 "Function to call to send the current buffer as news.
356 The headers should be delimited by a line whose contents match the
357 variable `mail-header-separator'."
358 :group
'message-sending
362 (defcustom message-reply-to-function nil
363 "Function that should return a list of headers.
364 This function should pick out addresses from the To, Cc, and From headers
365 and respond with new To and Cc headers."
366 :group
'message-interface
369 (defcustom message-wide-reply-to-function nil
370 "Function that should return a list of headers.
371 This function should pick out addresses from the To, Cc, and From headers
372 and respond with new To and Cc headers."
373 :group
'message-interface
376 (defcustom message-followup-to-function nil
377 "Function that should return a list of headers.
378 This function should pick out addresses from the To, Cc, and From headers
379 and respond with new To and Cc headers."
380 :group
'message-interface
383 (defcustom message-use-followup-to
'ask
384 "*Specifies what to do with Followup-To header.
385 If nil, always ignore the header. If it is t, use its value, but
386 query before using the \"poster\" value. If it is the symbol `ask',
387 always query the user whether to use the value. If it is the symbol
388 `use', always use the value."
389 :group
'message-interface
390 :type
'(choice (const :tag
"ignore" nil
)
394 ;; stuff relating to broken sendmail in MMDF
395 (defcustom message-sendmail-f-is-evil nil
396 "*Non-nil means that \"-f username\" should not be added to the sendmail
397 command line, because it is even more evil than leaving it out."
398 :group
'message-sending
401 ;; qmail-related stuff
402 (defcustom message-qmail-inject-program
"/var/qmail/bin/qmail-inject"
403 "Location of the qmail-inject program."
404 :group
'message-sending
407 (defcustom message-qmail-inject-args nil
408 "Arguments passed to qmail-inject programs.
409 This should be a list of strings, one string for each argument.
411 For e.g., if you wish to set the envelope sender address so that bounces
412 go to the right place or to deal with listserv's usage of that address, you
413 might set this variable to '(\"-f\" \"you@some.where\")."
414 :group
'message-sending
415 :type
'(repeat string
))
417 (defvar gnus-post-method
)
418 (defvar gnus-select-method
)
419 (defcustom message-post-method
420 (cond ((and (boundp 'gnus-post-method
)
421 (listp gnus-post-method
)
424 ((boundp 'gnus-select-method
)
427 "*Method used to post news.
428 Note that when posting from inside Gnus, for instance, this
429 variable isn't used."
431 :group
'message-sending
432 ;; This should be the `gnus-select-method' widget, but that might
433 ;; create a dependence to `gnus.el'.
436 (defcustom message-generate-headers-first nil
437 "*If non-nil, generate all possible headers before composing."
438 :group
'message-headers
441 (defcustom message-setup-hook nil
442 "Normal hook, run each time a new outgoing message is initialized.
443 The function `message-setup' runs this hook."
444 :group
'message-various
447 (defcustom message-signature-setup-hook nil
448 "Normal hook, run each time a new outgoing message is initialized.
449 It is run after the headers have been inserted and before
450 the signature is inserted."
451 :group
'message-various
454 (defcustom message-mode-hook nil
455 "Hook run in message mode buffers."
456 :group
'message-various
459 (defcustom message-header-hook nil
460 "Hook run in a message mode buffer narrowed to the headers."
461 :group
'message-various
464 (defcustom message-header-setup-hook nil
465 "Hook called narrowed to the headers when setting up a message buffer."
466 :group
'message-various
470 (defcustom message-citation-line-function
'message-insert-citation-line
471 "*Function called to insert the \"Whomever writes:\" line."
473 :group
'message-insertion
)
476 (defcustom message-yank-prefix
"> "
477 "*Prefix inserted on the lines of yanked messages.
478 nil means use indentation."
480 :group
'message-insertion
)
482 (defcustom message-indentation-spaces
3
483 "*Number of spaces to insert at the beginning of each cited line.
484 Used by `message-yank-original' via `message-yank-cite'."
485 :group
'message-insertion
489 (defcustom message-cite-function
'message-cite-original
490 "*Function for citing an original message.
491 Predefined functions include `message-cite-original' and
492 `message-cite-original-without-signature'.
493 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
494 :type
'(radio (function-item message-cite-original
)
495 (function-item sc-cite-original
)
496 (function :tag
"Other"))
497 :group
'message-insertion
)
500 (defcustom message-indent-citation-function
'message-indent-citation
501 "*Function for modifying a citation just inserted in the mail buffer.
502 This can also be a list of functions. Each function can find the
503 citation between (point) and (mark t). And each function should leave
504 point and mark around the citation text as modified."
506 :group
'message-insertion
)
508 (defvar message-abbrevs-loaded nil
)
511 (defcustom message-signature t
512 "*String to be inserted at the end of the message buffer.
513 If t, the `message-signature-file' file will be inserted instead.
514 If a function, the result from the function will be used instead.
515 If a form, the result from the form will be used instead."
517 :group
'message-insertion
)
520 (defcustom message-signature-file
"~/.signature"
521 "*File containing the text inserted at end of message buffer."
523 :group
'message-insertion
)
525 (defcustom message-distribution-function nil
526 "*Function called to return a Distribution header."
528 :group
'message-headers
531 (defcustom message-expires
14
532 "Number of days before your article expires."
534 :group
'message-headers
535 :link
'(custom-manual "(message)News Headers")
538 (defcustom message-user-path nil
539 "If nil, use the NNTP server name in the Path header.
540 If stringp, use this; if non-nil, use no host name (user name only)."
542 :group
'message-headers
543 :link
'(custom-manual "(message)News Headers")
544 :type
'(choice (const :tag
"nntp" nil
)
546 (sexp :tag
"none" :format
"%t" t
)))
548 (defvar message-reply-buffer nil
)
549 (defvar message-reply-headers nil
)
550 (defvar message-newsreader nil
)
551 (defvar message-mailer nil
)
552 (defvar message-sent-message-via nil
)
553 (defvar message-checksum nil
)
554 (defvar message-send-actions nil
555 "A list of actions to be performed upon successful sending of a message.")
556 (defvar message-exit-actions nil
557 "A list of actions to be performed upon exiting after sending a message.")
558 (defvar message-kill-actions nil
559 "A list of actions to be performed before killing a message buffer.")
560 (defvar message-postpone-actions nil
561 "A list of actions to be performed after postponing a message.")
563 (define-widget 'message-header-lines
'text
564 "All header lines must be LFD terminated."
567 :error
"All header lines must be newline terminated")
569 (defcustom message-default-headers
""
570 "*A string containing header lines to be inserted in outgoing messages.
571 It is inserted before you edit the message, so you can edit or delete
573 :group
'message-headers
574 :type
'message-header-lines
)
576 (defcustom message-default-mail-headers
""
577 "*A string of header lines to be inserted in outgoing mails."
578 :group
'message-headers
580 :type
'message-header-lines
)
582 (defcustom message-default-news-headers
""
583 "*A string of header lines to be inserted in outgoing news
585 :group
'message-headers
587 :type
'message-header-lines
)
589 ;; Note: could use /usr/ucb/mail instead of sendmail;
590 ;; options -t, and -v if not interactive.
591 (defcustom message-mailer-swallows-blank-line
592 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
593 system-configuration
)
594 (file-readable-p "/etc/sendmail.cf")
595 (let ((buffer (get-buffer-create " *temp*")))
599 (insert-file-contents "/etc/sendmail.cf")
600 (goto-char (point-min))
601 (let ((case-fold-search nil
))
602 (re-search-forward "^OR\\>" nil t
)))
603 (kill-buffer buffer
))))
604 ;; According to RFC822, "The field-name must be composed of printable
605 ;; ASCII characters (i. e., characters that have decimal values between
606 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
608 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
609 "*Set this non-nil if the system's mailer runs the header and body together.
610 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
611 The value should be an expression to test whether the problem will
613 :group
'message-sending
616 ;; Ignore errors in case this is used in Emacs 19.
617 ;; Don't use ignore-errors because this is copied into loaddefs.el.
620 (define-mail-user-agent 'message-user-agent
621 'message-mail
'message-send-and-exit
622 'message-kill-buffer
'message-send-hook
)
625 (defvar message-mh-deletable-headers
'(Message-ID Date Lines Sender
)
626 "If non-nil, delete the deletable headers before feeding to mh.")
628 (defvar message-send-method-alist
629 '((news message-news-p message-send-via-news
)
630 (mail message-mail-p message-send-via-mail
))
631 "Alist of ways to send outgoing messages.
632 Each element has the form
634 \(TYPE PREDICATE FUNCTION)
636 where TYPE is a symbol that names the method; PREDICATE is a function
637 called without any parameters to determine whether the message is
638 a message of type TYPE; and FUNCTION is a function to be called if
639 PREDICATE returns non-nil. FUNCTION is called with one parameter --
642 (defvar message-mail-alias-type
'abbrev
643 "*What alias expansion type to use in Message buffers.
644 The default is `abbrev', which uses mailabbrev. nil switches
647 (defcustom message-auto-save-directory
648 (nnheader-concat message-directory
"drafts/")
649 "*Directory where Message auto-saves buffers if Gnus isn't running.
650 If nil, Message won't auto-save."
651 :group
'message-buffers
654 ;;; Internal variables.
655 ;;; Well, not really internal.
657 (defvar message-mode-syntax-table
658 (let ((table (copy-syntax-table text-mode-syntax-table
)))
659 (modify-syntax-entry ?%
". " table
)
661 "Syntax table used while in Message mode.")
663 (defvar message-mode-abbrev-table text-mode-abbrev-table
664 "Abbrev table used in Message mode buffers.
665 Defaults to `text-mode-abbrev-table'.")
666 (defgroup message-headers nil
668 :link
'(custom-manual "(message)Variables")
671 (defface message-header-to-face
674 (:foreground
"green2" :bold t
))
677 (:foreground
"MidnightBlue" :bold t
))
679 (:bold t
:italic t
)))
680 "Face used for displaying From headers."
681 :group
'message-faces
)
683 (defface message-header-cc-face
686 (:foreground
"green4" :bold t
))
689 (:foreground
"MidnightBlue"))
692 "Face used for displaying Cc headers."
693 :group
'message-faces
)
695 (defface message-header-subject-face
698 (:foreground
"green3"))
701 (:foreground
"navy blue" :bold t
))
704 "Face used for displaying subject headers."
705 :group
'message-faces
)
707 (defface message-header-newsgroups-face
710 (:foreground
"yellow" :bold t
:italic t
))
713 (:foreground
"blue4" :bold t
:italic t
))
715 (:bold t
:italic t
)))
716 "Face used for displaying newsgroups headers."
717 :group
'message-faces
)
719 (defface message-header-other-face
722 (:foreground
"#b00000"))
725 (:foreground
"steel blue"))
727 (:bold t
:italic t
)))
728 "Face used for displaying newsgroups headers."
729 :group
'message-faces
)
731 (defface message-header-name-face
734 (:foreground
"DarkGreen"))
737 (:foreground
"cornflower blue"))
740 "Face used for displaying header names."
741 :group
'message-faces
)
743 (defface message-header-xheader-face
746 (:foreground
"blue"))
749 (:foreground
"blue"))
752 "Face used for displaying X-Header headers."
753 :group
'message-faces
)
755 (defface message-separator-face
758 (:foreground
"blue3"))
761 (:foreground
"brown"))
764 "Face used for displaying the separator."
765 :group
'message-faces
)
767 (defface message-cited-text-face
776 "Face used for displaying cited text names."
777 :group
'message-faces
)
779 (defvar message-font-lock-keywords
780 (let* ((cite-prefix "A-Za-z")
781 (cite-suffix (concat cite-prefix
"0-9_.@-"))
782 (content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)"))
783 `((,(concat "^\\([Tt]o:\\)" content
)
784 (1 'message-header-name-face
)
785 (2 'message-header-to-face nil t
))
786 (,(concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content
)
787 (1 'message-header-name-face
)
788 (2 'message-header-cc-face nil t
))
789 (,(concat "^\\([Ss]ubject:\\)" content
)
790 (1 'message-header-name-face
)
791 (2 'message-header-subject-face nil t
))
792 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content
)
793 (1 'message-header-name-face
)
794 (2 'message-header-newsgroups-face nil t
))
795 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content
)
796 (1 'message-header-name-face
)
797 (2 'message-header-other-face nil t
))
798 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content
)
799 (1 'message-header-name-face
)
800 (2 'message-header-name-face
))
801 ,@(if (and mail-header-separator
802 (not (equal mail-header-separator
"")))
803 `((,(concat "^\\(" (regexp-quote mail-header-separator
) "\\)$")
804 1 'message-separator-face
))
807 "\\([" cite-prefix
"]+[" cite-suffix
"]*\\)?"
809 (0 'message-cited-text-face
))))
810 "Additional expressions to highlight in Message mode.")
812 ;; XEmacs does it like this. For Emacs, we have to set the
813 ;; `font-lock-defaults' buffer-local variable.
814 (put 'message-mode
'font-lock-defaults
'(message-font-lock-keywords t
))
816 (defvar message-face-alist
817 '((bold . bold-region
)
818 (underline . underline-region
)
819 (default .
(lambda (b e
)
821 (ununderline-region b e
))))
822 "Alist of mail and news faces for facemenu.
823 The cdr of ech entry is a function for applying the face to a region.")
825 (defcustom message-send-hook nil
826 "Hook run before sending messages."
827 :group
'message-various
828 :options
'(ispell-message)
831 (defcustom message-send-mail-hook nil
832 "Hook run before sending mail messages."
833 :group
'message-various
836 (defcustom message-send-news-hook nil
837 "Hook run before sending news messages."
838 :group
'message-various
841 (defcustom message-sent-hook nil
842 "Hook run after sending messages."
843 :group
'message-various
846 (defvar message-send-coding-system
'binary
847 "Coding system to encode outgoing mail.")
849 ;;; Internal variables.
851 (defvar message-buffer-list nil
)
852 (defvar message-this-is-news nil
)
853 (defvar message-this-is-mail nil
)
854 (defvar message-draft-article nil
)
856 ;; Byte-compiler warning
857 (defvar gnus-active-hashtb
)
858 (defvar gnus-read-active-file
)
860 ;;; Regexp matching the delimiter of messages in UNIX mail format
861 ;;; (UNIX From lines), minus the initial ^. It should be a copy
862 ;;; of rmail.el's rmail-unix-mail-delimiter.
863 (defvar message-unix-mail-delimiter
864 (let ((time-zone-regexp
865 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
866 "\\|[-+]?[0-9][0-9][0-9][0-9]"
872 ;; Many things can happen to an RFC 822 mailbox before it is put into
873 ;; a `From' line. The leading phrase can be stripped, e.g.
874 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
875 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
876 ;; can be removed, e.g.
877 ;; From: joe@y.z (Joe K
879 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
882 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
883 ;; The mailbox can be removed or be replaced by white space, e.g.
884 ;; From: "Joe User"{space}{tab}
886 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
887 ;; where {space} and {tab} represent the Ascii space and tab characters.
888 ;; We want to match the results of any of these manglings.
889 ;; The following regexp rejects names whose first characters are
890 ;; obviously bogus, but after that anything goes.
891 "\\([^\0-\b\n-\r\^?].*\\)? "
893 ;; The time the message was sent.
894 "\\([^\0-\r \^?]+\\) +" ; day of the week
895 "\\([^\0-\r \^?]+\\) +" ; month
896 "\\([0-3]?[0-9]\\) +" ; day of month
897 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
899 ;; Perhaps a time zone, specified by an abbreviation, or by a
904 " \\([0-9][0-9]+\\) *"
906 ;; On some systems the time zone can appear after the year, too.
910 "\\(remote from .*\\)?"
913 "Regexp matching the delimiter of messages in UNIX mail format.")
915 (defvar message-unsent-separator
916 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
917 "^ *---+ +Returned message +---+ *$\\|"
918 "^Start of returned message$\\|"
919 "^ *---+ +Original message +---+ *$\\|"
920 "^ *--+ +begin message +--+ *$\\|"
921 "^ *---+ +Original message follows +---+ *$\\|"
922 "^|? *---+ +Message text follows: +---+ *|?$")
923 "A regexp that matches the separator before the text of a failed message.")
925 (defvar message-header-format-alist
927 (To . message-fill-address
)
928 (Cc . message-fill-address
)
939 (References . message-shorten-references
)
942 "Alist used for formatting headers.")
945 (autoload 'message-setup-toolbar
"messagexmas")
946 (autoload 'mh-new-draft-name
"mh-comp")
947 (autoload 'mh-send-letter
"mh-comp")
948 (autoload 'gnus-point-at-eol
"gnus-util")
949 (autoload 'gnus-point-at-bol
"gnus-util")
950 (autoload 'gnus-output-to-mail
"gnus-util")
951 (autoload 'gnus-output-to-rmail
"gnus-util")
952 (autoload 'mail-abbrev-in-expansion-header-p
"mailabbrev")
953 (autoload 'nndraft-request-associate-buffer
"nndraft")
954 (autoload 'nndraft-request-expire-articles
"nndraft")
955 (autoload 'gnus-open-server
"gnus-int")
956 (autoload 'gnus-request-post
"gnus-int")
957 (autoload 'gnus-alive-p
"gnus-util")
958 (autoload 'rmail-output
"rmail"))
963 ;;; Utility functions.
966 (defmacro message-y-or-n-p
(question show
&rest text
)
967 "Ask QUESTION, displaying the rest of the arguments in a temp. buffer if SHOW"
968 `(message-talkative-question 'y-or-n-p
,question
,show
,@text
))
970 ;; Delete the current line (and the next N lines.);
971 (defmacro message-delete-line
(&optional n
)
972 `(delete-region (progn (beginning-of-line) (point))
973 (progn (forward-line ,(or n
1)) (point))))
975 (defun message-tokenize-header (header &optional separator
)
976 "Split HEADER into a list of header elements.
977 \",\" is used as the separator."
980 (let ((regexp (format "[%s]+" (or separator
",")))
985 (message-set-work-buffer)
987 (goto-char (point-min))
992 (cond ((and (> (point) beg
)
994 (and (looking-at regexp
)
997 (push (buffer-substring beg
(point)) elems
)
998 (setq beg
(match-end 0)))
999 ((= (following-char) ?
\")
1000 (setq quoted
(not quoted
)))
1001 ((and (= (following-char) ?\
()
1004 ((and (= (following-char) ?\
))
1007 (nreverse elems
)))))
1009 (defun message-mail-file-mbox-p (file)
1010 "Say whether FILE looks like a Unix mbox file."
1011 (when (and (file-exists-p file
)
1012 (file-readable-p file
)
1013 (file-regular-p file
))
1014 (nnheader-temp-write nil
1015 (nnheader-insert-file-contents file
)
1016 (goto-char (point-min))
1017 (looking-at message-unix-mail-delimiter
))))
1019 (defun message-fetch-field (header &optional not-all
)
1020 "The same as `mail-fetch-field', only remove all newlines."
1021 (let* ((inhibit-point-motion-hooks t
)
1022 (value (mail-fetch-field header nil
(not not-all
))))
1024 (nnheader-replace-chars-in-string value ?
\n ?
))))
1026 (defun message-add-header (&rest headers
)
1027 "Add the HEADERS to the message header, skipping those already present."
1030 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers
))
1031 (error "Invalid header `%s'" (car headers
)))
1032 (setq hclean
(match-string 1 (car headers
)))
1034 (message-narrow-to-headers)
1035 (unless (re-search-forward (concat "^" (regexp-quote hclean
) ":") nil t
)
1036 (insert (car headers
) ?
\n))))
1037 (setq headers
(cdr headers
))))
1039 (defun message-fetch-reply-field (header)
1040 "Fetch FIELD from the message we're replying to."
1041 (when (and message-reply-buffer
1042 (buffer-name message-reply-buffer
))
1044 (set-buffer message-reply-buffer
)
1045 (message-fetch-field header
))))
1047 (defun message-set-work-buffer ()
1048 (if (get-buffer " *message work*")
1050 (set-buffer " *message work*")
1052 (set-buffer (get-buffer-create " *message work*"))
1053 (kill-all-local-variables)
1054 (buffer-disable-undo (current-buffer))))
1056 (defun message-functionp (form)
1057 "Return non-nil if FORM is funcallable."
1058 (or (and (symbolp form
) (fboundp form
))
1059 (and (listp form
) (eq (car form
) 'lambda
))
1060 (byte-code-function-p form
)))
1062 (defun message-strip-subject-re (subject)
1063 "Remove \"Re:\" from subject lines."
1064 (if (string-match message-subject-re-regexp subject
)
1065 (substring subject
(match-end 0))
1068 (defun message-remove-header (header &optional is-regexp first reverse
)
1069 "Remove HEADER in the narrowed buffer.
1070 If REGEXP, HEADER is a regular expression.
1071 If FIRST, only remove the first instance of the header.
1072 Return the number of headers removed."
1073 (goto-char (point-min))
1074 (let ((regexp (if is-regexp header
(concat "^" (regexp-quote header
) ":")))
1076 (case-fold-search t
)
1078 (while (and (not (eobp))
1081 (not (looking-at regexp
))
1082 (looking-at regexp
))
1089 ;; There might be a continuation header, so we have to search
1090 ;; until we find a new non-continuation line.
1093 (if (re-search-forward "^[^ \t]" nil t
)
1094 (goto-char (match-beginning 0))
1097 (if (re-search-forward "^[^ \t]" nil t
)
1098 (goto-char (match-beginning 0))
1102 (defun message-narrow-to-headers ()
1103 "Narrow the buffer to the head of the message."
1106 (goto-char (point-min))
1107 (if (re-search-forward
1108 (concat "^" (regexp-quote mail-header-separator
) "\n") nil t
)
1111 (goto-char (point-min)))
1113 (defun message-narrow-to-head ()
1114 "Narrow the buffer to the head of the message."
1117 (goto-char (point-min))
1118 (if (search-forward "\n\n" nil
1)
1121 (goto-char (point-min)))
1123 (defun message-news-p ()
1124 "Say whether the current buffer contains a news message."
1125 (and (not message-this-is-mail
)
1126 (or message-this-is-news
1129 (message-narrow-to-headers)
1130 (and (message-fetch-field "newsgroups")
1131 (not (message-fetch-field "posted-to"))))))))
1133 (defun message-mail-p ()
1134 "Say whether the current buffer contains a mail message."
1135 (and (not message-this-is-news
)
1136 (or message-this-is-mail
1139 (message-narrow-to-headers)
1140 (or (message-fetch-field "to")
1141 (message-fetch-field "cc")
1142 (message-fetch-field "bcc")))))))
1144 (defun message-next-header ()
1145 "Go to the beginning of the next header."
1147 (or (eobp) (forward-char 1))
1148 (not (if (re-search-forward "^[^ \t]" nil t
)
1150 (goto-char (point-max)))))
1152 (defun message-sort-headers-1 ()
1153 "Sort the buffer as headers using `message-rank' text props."
1154 (goto-char (point-min))
1156 nil
'message-next-header
1158 (message-next-header)
1162 (or (get-text-property (point) 'message-rank
)
1165 (defun message-sort-headers ()
1166 "Sort the headers of the current message according to `message-header-format-alist'."
1170 (let ((max (1+ (length message-header-format-alist
)))
1172 (message-narrow-to-headers)
1173 (while (re-search-forward "^[^ \n]+:" nil t
)
1175 (match-beginning 0) (1+ (match-beginning 0))
1177 (if (setq rank
(length (memq (assq (intern (buffer-substring
1179 (1- (match-end 0))))
1180 message-header-format-alist
)
1181 message-header-format-alist
)))
1184 (message-sort-headers-1))))
1194 (defvar message-mode-map nil
)
1196 (unless message-mode-map
1197 (setq message-mode-map
(copy-keymap text-mode-map
))
1198 (define-key message-mode-map
"\C-c?" 'describe-mode
)
1200 (define-key message-mode-map
"\C-c\C-f\C-t" 'message-goto-to
)
1201 (define-key message-mode-map
"\C-c\C-f\C-b" 'message-goto-bcc
)
1202 (define-key message-mode-map
"\C-c\C-f\C-w" 'message-goto-fcc
)
1203 (define-key message-mode-map
"\C-c\C-f\C-c" 'message-goto-cc
)
1204 (define-key message-mode-map
"\C-c\C-f\C-s" 'message-goto-subject
)
1205 (define-key message-mode-map
"\C-c\C-f\C-r" 'message-goto-reply-to
)
1206 (define-key message-mode-map
"\C-c\C-f\C-n" 'message-goto-newsgroups
)
1207 (define-key message-mode-map
"\C-c\C-f\C-d" 'message-goto-distribution
)
1208 (define-key message-mode-map
"\C-c\C-f\C-f" 'message-goto-followup-to
)
1209 (define-key message-mode-map
"\C-c\C-f\C-k" 'message-goto-keywords
)
1210 (define-key message-mode-map
"\C-c\C-f\C-u" 'message-goto-summary
)
1211 (define-key message-mode-map
"\C-c\C-b" 'message-goto-body
)
1212 (define-key message-mode-map
"\C-c\C-i" 'message-goto-signature
)
1214 (define-key message-mode-map
"\C-c\C-t" 'message-insert-to
)
1215 (define-key message-mode-map
"\C-c\C-n" 'message-insert-newsgroups
)
1217 (define-key message-mode-map
"\C-c\C-y" 'message-yank-original
)
1218 (define-key message-mode-map
"\C-c\C-q" 'message-fill-yanked-message
)
1219 (define-key message-mode-map
"\C-c\C-w" 'message-insert-signature
)
1220 (define-key message-mode-map
"\C-c\C-r" 'message-caesar-buffer-body
)
1221 (define-key message-mode-map
"\C-c\C-o" 'message-sort-headers
)
1222 (define-key message-mode-map
"\C-c\M-r" 'message-rename-buffer
)
1224 (define-key message-mode-map
"\C-c\C-c" 'message-send-and-exit
)
1225 (define-key message-mode-map
"\C-c\C-s" 'message-send
)
1226 (define-key message-mode-map
"\C-c\C-k" 'message-kill-buffer
)
1227 (define-key message-mode-map
"\C-c\C-d" 'message-dont-send
)
1229 (define-key message-mode-map
"\C-c\C-e" 'message-elide-region
)
1230 (define-key message-mode-map
"\C-c\C-v" 'message-delete-not-region
)
1231 (define-key message-mode-map
"\C-c\C-z" 'message-kill-to-signature
)
1232 (define-key message-mode-map
"\M-\r" 'message-newline-and-reformat
)
1234 (define-key message-mode-map
"\t" 'message-tab
))
1237 message-mode-menu message-mode-map
"Message Menu."
1239 ["Sort Headers" message-sort-headers t
]
1240 ["Yank Original" message-yank-original t
]
1241 ["Fill Yanked Message" message-fill-yanked-message t
]
1242 ["Insert Signature" message-insert-signature t
]
1243 ["Caesar (rot13) Message" message-caesar-buffer-body t
]
1244 ["Caesar (rot13) Region" message-caesar-region
(mark t
)]
1245 ["Elide Region" message-elide-region
(mark t
)]
1246 ["Delete Outside Region" message-delete-not-region
(mark t
)]
1247 ["Kill To Signature" message-kill-to-signature t
]
1248 ["Newline and Reformat" message-newline-and-reformat t
]
1249 ["Rename buffer" message-rename-buffer t
]
1250 ["Spellcheck" ispell-message t
]
1252 ["Send Message" message-send-and-exit t
]
1253 ["Abort Message" message-dont-send t
]
1254 ["Kill Message" message-kill-buffer t
]))
1257 message-mode-field-menu message-mode-map
""
1259 ["Fetch To" message-insert-to t
]
1260 ["Fetch Newsgroups" message-insert-newsgroups t
]
1262 ["To" message-goto-to t
]
1263 ["Subject" message-goto-subject t
]
1264 ["Cc" message-goto-cc t
]
1265 ["Reply-To" message-goto-reply-to t
]
1266 ["Summary" message-goto-summary t
]
1267 ["Keywords" message-goto-keywords t
]
1268 ["Newsgroups" message-goto-newsgroups t
]
1269 ["Followup-To" message-goto-followup-to t
]
1270 ["Distribution" message-goto-distribution t
]
1271 ["Body" message-goto-body t
]
1272 ["Signature" message-goto-signature t
]))
1274 (defvar facemenu-add-face-function
)
1275 (defvar facemenu-remove-face-function
)
1278 (defun message-mode ()
1279 "Major mode for editing mail and news to be sent.
1280 Like Text Mode but with these additional commands:
1281 C-c C-s message-send (send the message) C-c C-c message-send-and-exit
1282 C-c C-f move to a header field (and create it if there isn't):
1283 C-c C-f C-t move to To C-c C-f C-s move to Subject
1284 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1285 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1286 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1287 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1288 C-c C-f C-f move to Followup-To
1289 C-c C-t message-insert-to (add a To header to a news followup)
1290 C-c C-n message-insert-newsgroups (add a Newsgroup header to a news reply)
1291 C-c C-b message-goto-body (move to beginning of message text).
1292 C-c C-i message-goto-signature (move to the beginning of the signature).
1293 C-c C-w message-insert-signature (insert `message-signature-file' file).
1294 C-c C-y message-yank-original (insert current message, if any).
1295 C-c C-q message-fill-yanked-message (fill what was yanked).
1296 C-c C-e message-elide-region (elide the text between point and mark).
1297 C-c C-z message-kill-to-signature (kill the text up to the signature).
1298 C-c C-r message-caesar-buffer-body (rot13 the message body)."
1300 (kill-all-local-variables)
1301 (make-local-variable 'message-reply-buffer
)
1302 (setq message-reply-buffer nil
)
1303 (make-local-variable 'message-send-actions
)
1304 (make-local-variable 'message-exit-actions
)
1305 (make-local-variable 'message-kill-actions
)
1306 (make-local-variable 'message-postpone-actions
)
1307 (make-local-variable 'message-draft-article
)
1308 (make-local-hook 'kill-buffer-hook
)
1309 (set-syntax-table message-mode-syntax-table
)
1310 (use-local-map message-mode-map
)
1311 (setq local-abbrev-table message-mode-abbrev-table
)
1312 (setq major-mode
'message-mode
)
1313 (setq mode-name
"Message")
1314 (setq buffer-offer-save t
)
1315 (make-local-variable 'facemenu-add-face-function
)
1316 (make-local-variable 'facemenu-remove-face-function
)
1317 (setq facemenu-add-face-function
1319 (let ((face-fun (cdr (assq face message-face-alist
))))
1321 (funcall face-fun
(point) end
)
1322 (error "Face %s not configured for %s mode" face mode-name
)))
1324 facemenu-remove-face-function t
)
1325 (make-local-variable 'paragraph-separate
)
1326 (make-local-variable 'paragraph-start
)
1327 ;; `-- ' precedes the signature. `-----' appears at the start of the
1328 ;; lines that delimit forwarded messages.
1329 ;; Lines containing just >= 3 dashes, perhaps after whitespace,
1330 ;; are also sometimes used and should be separators.
1331 (setq paragraph-start
(concat (regexp-quote mail-header-separator
)
1332 "$\\|[ \t]*[a-z0-9A-Z]*>+[ \t]*$\\|[ \t]*$\\|"
1335 (setq paragraph-separate paragraph-start
)
1336 (make-local-variable 'message-reply-headers
)
1337 (setq message-reply-headers nil
)
1338 (make-local-variable 'message-newsreader
)
1339 (make-local-variable 'message-mailer
)
1340 (make-local-variable 'message-post-method
)
1341 (make-local-variable 'message-sent-message-via
)
1342 (setq message-sent-message-via nil
)
1343 (make-local-variable 'message-checksum
)
1344 (setq message-checksum nil
)
1345 ;;(when (fboundp 'mail-hist-define-keys)
1346 ;; (mail-hist-define-keys))
1347 (when (string-match "XEmacs\\|Lucid" emacs-version
)
1348 (message-setup-toolbar))
1349 (easy-menu-add message-mode-menu message-mode-map
)
1350 (easy-menu-add message-mode-field-menu message-mode-map
)
1351 (make-local-variable 'adaptive-fill-regexp
)
1352 (setq adaptive-fill-regexp
1353 (concat "[ \t]*[-a-z0-9A-Z]*>+[ \t]*\\|" adaptive-fill-regexp
))
1354 (make-local-variable 'adaptive-fill-first-line-regexp
)
1355 (setq adaptive-fill-first-line-regexp
1356 (concat "[ \t]*[-a-z0-9A-Z]*>+[ \t]*\\|"
1357 adaptive-fill-first-line-regexp
))
1358 ;; Allow mail alias things.
1359 (when (eq message-mail-alias-type
'abbrev
)
1360 (if (fboundp 'mail-abbrevs-setup
)
1361 (mail-abbrevs-setup)
1362 (mail-aliases-setup)))
1363 (message-set-auto-save-file-name)
1364 (unless (string-match "XEmacs" emacs-version
)
1365 (set (make-local-variable 'font-lock-defaults
)
1366 '(message-font-lock-keywords t
)))
1367 (make-local-variable 'adaptive-fill-regexp
)
1368 (setq adaptive-fill-regexp
1369 (concat "[ \t]*[-a-z0-9A-Z]*>+[ \t]*\\|" adaptive-fill-regexp
))
1370 (unless (boundp 'adaptive-fill-first-line-regexp
)
1371 (setq adaptive-fill-first-line-regexp nil
))
1372 (make-local-variable 'adaptive-fill-first-line-regexp
)
1373 (setq adaptive-fill-first-line-regexp
1374 (concat "[ \t]*[-a-z0-9A-Z]*>+[ \t]*\\|"
1375 adaptive-fill-first-line-regexp
))
1376 (run-hooks 'text-mode-hook
'message-mode-hook
))
1381 ;;; Message mode commands
1384 ;;; Movement commands
1386 (defun message-goto-to ()
1387 "Move point to the To header."
1389 (message-position-on-field "To"))
1391 (defun message-goto-subject ()
1392 "Move point to the Subject header."
1394 (message-position-on-field "Subject"))
1396 (defun message-goto-cc ()
1397 "Move point to the Cc header."
1399 (message-position-on-field "Cc" "To"))
1401 (defun message-goto-bcc ()
1402 "Move point to the Bcc header."
1404 (message-position-on-field "Bcc" "Cc" "To"))
1406 (defun message-goto-fcc ()
1407 "Move point to the Fcc header."
1409 (message-position-on-field "Fcc" "To" "Newsgroups"))
1411 (defun message-goto-reply-to ()
1412 "Move point to the Reply-To header."
1414 (message-position-on-field "Reply-To" "Subject"))
1416 (defun message-goto-newsgroups ()
1417 "Move point to the Newsgroups header."
1419 (message-position-on-field "Newsgroups"))
1421 (defun message-goto-distribution ()
1422 "Move point to the Distribution header."
1424 (message-position-on-field "Distribution"))
1426 (defun message-goto-followup-to ()
1427 "Move point to the Followup-To header."
1429 (message-position-on-field "Followup-To" "Newsgroups"))
1431 (defun message-goto-keywords ()
1432 "Move point to the Keywords header."
1434 (message-position-on-field "Keywords" "Subject"))
1436 (defun message-goto-summary ()
1437 "Move point to the Summary header."
1439 (message-position-on-field "Summary" "Subject"))
1441 (defun message-goto-body ()
1442 "Move point to the beginning of the message body."
1444 (if (looking-at "[ \t]*\n") (expand-abbrev))
1445 (goto-char (point-min))
1446 (search-forward (concat "\n" mail-header-separator
"\n") nil t
))
1448 (defun message-goto-eoh ()
1449 "Move point to the end of the headers."
1454 (defun message-goto-signature ()
1455 "Move point to the beginning of the message signature.
1456 If there is no signature in the article, go to the end and
1459 (goto-char (point-min))
1460 (if (re-search-forward message-signature-separator nil t
)
1462 (goto-char (point-max))
1467 (defun message-insert-to (&optional force
)
1468 "Insert a To header that points to the author of the article being replied to.
1469 If the original author requested not to be sent mail, the function signals
1471 With the prefix argument FORCE, insert the header anyway."
1473 (let ((co (message-fetch-reply-field "mail-copies-to")))
1474 (when (and (null force
)
1476 (equal (downcase co
) "never"))
1477 (error "The user has requested not to have copies sent via mail")))
1478 (when (and (message-position-on-field "To")
1479 (mail-fetch-field "to")
1480 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
1482 (insert (or (message-fetch-reply-field "reply-to")
1483 (message-fetch-reply-field "from") "")))
1485 (defun message-insert-newsgroups ()
1486 "Insert the Newsgroups header from the article being replied to."
1488 (when (and (message-position-on-field "Newsgroups")
1489 (mail-fetch-field "newsgroups")
1490 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
1492 (insert (or (message-fetch-reply-field "newsgroups") "")))
1496 ;;; Various commands
1498 (defun message-delete-not-region (beg end
)
1499 "Delete everything in the body of the current message that is outside of the region."
1503 (delete-region (point) (if (not (message-goto-signature))
1509 (delete-region beg
(progn (message-goto-body)
1512 (when (message-goto-signature)
1515 (defun message-kill-to-signature ()
1516 "Deletes all text up to the signature."
1518 (let ((point (point)))
1519 (message-goto-signature)
1522 (kill-region point
(point))
1526 (defun message-newline-and-reformat ()
1527 "Insert four newlines, and then reformat if inside quoted text."
1529 (let ((point (point))
1533 (setq quoted
(looking-at (regexp-quote message-yank-prefix
))))
1536 (insert message-yank-prefix
))
1537 (fill-paragraph nil
)
1541 (defun message-insert-signature (&optional force
)
1542 "Insert a signature. See documentation for the `message-signature' variable."
1543 (interactive (list 0))
1546 ((and (null message-signature
)
1549 (goto-char (point-max))
1550 (not (re-search-backward
1551 message-signature-separator nil t
))))
1552 ((and (null message-signature
)
1555 ((message-functionp message-signature
)
1556 (funcall message-signature
))
1557 ((listp message-signature
)
1558 (eval message-signature
))
1559 (t message-signature
)))
1561 (cond ((stringp signature
)
1563 ((and (eq t signature
)
1564 message-signature-file
1565 (file-exists-p message-signature-file
))
1568 (goto-char (point-max))
1569 ;; Insert the signature.
1573 (if (eq signature t
)
1574 (insert-file-contents message-signature-file
)
1576 (goto-char (point-max))
1577 (or (bolp) (insert "\n")))))
1579 (defun message-elide-region (b e
)
1580 "Elide the text between point and mark.
1581 An ellipsis (from `message-elide-elipsis') will be inserted where the
1587 (insert message-elide-elipsis
))
1589 (defvar message-caesar-translation-table nil
)
1591 (defun message-caesar-region (b e
&optional n
)
1592 "Caesar rotation of region by N, default 13, for decrypting netnews."
1595 (min (point) (or (mark t
) (point)))
1596 (max (point) (or (mark t
) (point)))
1597 (when current-prefix-arg
1598 (prefix-numeric-value current-prefix-arg
))))
1600 (setq n
(if (numberp n
) (mod n
26) 13)) ;canonize N
1601 (unless (or (zerop n
) ; no action needed for a rot of 0
1602 (= b e
)) ; no region to rotate
1603 ;; We build the table, if necessary.
1604 (when (or (not message-caesar-translation-table
)
1605 (/= (aref message-caesar-translation-table ?a
) (+ ?a n
)))
1606 (setq message-caesar-translation-table
1607 (message-make-caesar-translation-table n
)))
1608 ;; Then we translate the region. Do it this way to retain
1611 (subst-char-in-region
1612 b
(1+ b
) (char-after b
)
1613 (aref message-caesar-translation-table
(char-after b
)))
1616 (defun message-make-caesar-translation-table (n)
1617 "Create a rot table with offset N."
1619 (table (make-string 256 0)))
1620 (while (< (incf i
) 256)
1623 (substring table
0 ?A
)
1624 (substring table
(+ ?A n
) (+ ?A n
(- 26 n
)))
1625 (substring table ?A
(+ ?A n
))
1626 (substring table
(+ ?A
26) ?a
)
1627 (substring table
(+ ?a n
) (+ ?a n
(- 26 n
)))
1628 (substring table ?a
(+ ?a n
))
1629 (substring table
(+ ?a
26) 255))))
1631 (defun message-caesar-buffer-body (&optional rotnum
)
1632 "Caesar rotates all letters in the current buffer by 13 places.
1633 Used to encode/decode possiblyun offensive messages (commonly in net.jokes).
1634 With prefix arg, specifies the number of places to rotate each letter forward.
1635 Mail and USENET news headers are not rotated."
1636 (interactive (if current-prefix-arg
1637 (list (prefix-numeric-value current-prefix-arg
))
1641 (when (message-goto-body)
1642 (narrow-to-region (point) (point-max)))
1643 (message-caesar-region (point-min) (point-max) rotnum
))))
1645 (defun message-pipe-buffer-body (program)
1646 "Pipe the message body in the current buffer through PROGRAM."
1649 (when (message-goto-body)
1650 (narrow-to-region (point) (point-max)))
1651 (let ((body (buffer-substring (point-min) (point-max))))
1652 (unless (equal 0 (call-process-region
1653 (point-min) (point-max) program t t
))
1655 (message "%s failed." program
))))))
1657 (defun message-rename-buffer (&optional enter-string
)
1658 "Rename the *message* buffer to \"*message* RECIPIENT\".
1659 If the function is run with a prefix, it will ask for a new buffer
1660 name, rather than giving an automatic name."
1661 (interactive "Pbuffer name: ")
1664 (goto-char (point-min))
1665 (narrow-to-region (point)
1666 (search-forward mail-header-separator nil
'end
))
1668 (if (message-news-p) (message-fetch-field "Newsgroups")
1669 (message-fetch-field "To"))
1672 (if (string-match "," mail-to
)
1673 (concat (substring mail-to
0 (match-beginning 0)) ", ...")
1675 (name-default (concat "*message* " mail-trimmed-to
))
1676 (name (if enter-string
1677 (read-string "New buffer name: " name-default
)
1679 (rename-buffer name t
)))))
1681 (defun message-fill-yanked-message (&optional justifyp
)
1682 "Fill the paragraphs of a message yanked into this one.
1683 Numeric argument means justify as well."
1686 (goto-char (point-min))
1687 (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
1688 (let ((fill-prefix message-yank-prefix
))
1689 (fill-individual-paragraphs (point) (point-max) justifyp
1690 mail-citation-prefix-regexp
))))
1692 (defun message-indent-citation ()
1693 "Modify text just inserted from a message to be cited.
1694 The inserted text should be the region.
1695 When this function returns, the region is again around the modified text.
1697 Normally, indent each nonblank line `message-indentation-spaces' spaces.
1698 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
1699 (let ((start (point)))
1700 ;; Remove unwanted headers.
1701 (when message-ignored-cited-headers
1706 (if (search-forward "\n\n" nil t
)
1709 (message-remove-header message-ignored-cited-headers t
)
1710 (when (= (point-min) (point-max))
1711 (setq all-removed t
))
1712 (goto-char (point-max)))
1716 ;; Delete blank lines at the start of the buffer.
1717 (while (and (point-min)
1720 (message-delete-line))
1721 ;; Delete blank lines at the end of the buffer.
1722 (goto-char (point-max))
1725 (while (and (zerop (forward-line -
1))
1727 (message-delete-line))
1728 ;; Do the indentation.
1729 (if (null message-yank-prefix
)
1730 (indent-rigidly start
(mark t
) message-indentation-spaces
)
1733 (while (< (point) (mark t
))
1734 (insert message-yank-prefix
)
1738 (defun message-yank-original (&optional arg
)
1739 "Insert the message being replied to, if any.
1740 Puts point before the text and mark after.
1741 Normally indents each nonblank line ARG spaces (default 3). However,
1742 if `message-yank-prefix' is non-nil, insert that prefix on each line.
1744 This function uses `message-cite-function' to do the actual citing.
1746 Just \\[universal-argument] as argument means don't indent, insert no
1747 prefix, and don't delete any headers."
1749 (let ((modified (buffer-modified-p)))
1750 (when (and message-reply-buffer
1751 message-cite-function
)
1752 (delete-windows-on message-reply-buffer t
)
1753 (insert-buffer message-reply-buffer
)
1754 (funcall message-cite-function
)
1755 (message-exchange-point-and-mark)
1759 (setq message-checksum
(message-checksum))))))
1761 (defun message-cite-original-without-signature ()
1762 "Cite function in the standard Message manner."
1763 (let ((start (point))
1766 (when message-indent-citation-function
1767 (if (listp message-indent-citation-function
)
1768 message-indent-citation-function
1769 (list message-indent-citation-function
)))))
1771 (when (re-search-backward "^-- $" start t
)
1772 ;; Also peel off any blank lines before the signature.
1774 (while (looking-at "^[ \t]*$")
1777 (delete-region (point) end
))
1780 (funcall (pop functions
)))
1781 (when message-citation-line-function
1784 (funcall message-citation-line-function
))))
1786 (defvar mail-citation-hook
) ;Compiler directive
1787 (defun message-cite-original ()
1788 "Cite function in the standard Message manner."
1789 (if (and (boundp 'mail-citation-hook
)
1791 (run-hooks 'mail-citation-hook
)
1792 (let ((start (point))
1794 (when message-indent-citation-function
1795 (if (listp message-indent-citation-function
)
1796 message-indent-citation-function
1797 (list message-indent-citation-function
)))))
1800 (funcall (pop functions
)))
1801 (when message-citation-line-function
1804 (funcall message-citation-line-function
)))))
1806 (defun message-insert-citation-line ()
1807 "Function that inserts a simple citation line."
1808 (when message-reply-headers
1809 (insert (mail-header-from message-reply-headers
) " writes:\n\n")))
1811 (defun message-position-on-field (header &rest afters
)
1812 (let ((case-fold-search t
))
1815 (goto-char (point-min))
1818 (concat "^" (regexp-quote mail-header-separator
) "$"))
1819 (match-beginning 0)))
1820 (goto-char (point-min))
1821 (if (re-search-forward (concat "^" (regexp-quote header
) ":") nil t
)
1823 (re-search-forward "^[^ \t]" nil
'move
)
1825 (skip-chars-backward "\n")
1828 (not (re-search-forward
1829 (concat "^" (regexp-quote (car afters
)) ":")
1833 (re-search-forward "^[^ \t]" nil
'move
)
1834 (beginning-of-line))
1835 (insert header
": \n")
1839 (defun message-remove-signature ()
1840 "Remove the signature from the text between point and mark.
1841 The text will also be indented the normal way."
1843 (let ((start (point))
1845 (if (not (re-search-forward message-signature-separator
(mark t
) t
))
1846 ;; No signature here, so we just indent the cited text.
1847 (message-indent-citation)
1848 ;; Find the last non-empty line.
1850 (while (looking-at "[ \t]*$")
1853 (setq mark
(set-marker (make-marker) (point)))
1855 (message-indent-citation)
1856 ;; Enable undoing the deletion.
1858 (delete-region mark
(mark t
))
1859 (set-marker mark nil
)))))
1864 ;;; Sending messages
1867 (defun message-send-and-exit (&optional arg
)
1868 "Send message like `message-send', then, if no errors, exit from mail buffer."
1870 (let ((buf (current-buffer))
1871 (actions message-exit-actions
))
1872 (when (and (message-send arg
)
1874 (if message-kill-buffer-on-exit
1877 (when (eq buf
(current-buffer))
1878 (message-bury buf
)))
1879 (message-do-actions actions
)
1882 (defun message-dont-send ()
1883 "Don't send the message you have been editing."
1885 (set-buffer-modified-p t
)
1887 (let ((actions message-postpone-actions
))
1888 (message-bury (current-buffer))
1889 (message-do-actions actions
)))
1891 (defun message-kill-buffer ()
1892 "Kill the current buffer."
1894 (when (or (not (buffer-modified-p))
1895 (yes-or-no-p "Message modified; kill anyway? "))
1896 (let ((actions message-kill-actions
))
1897 (setq buffer-file-name nil
)
1898 (kill-buffer (current-buffer))
1899 (message-do-actions actions
))))
1901 (defun message-bury (buffer)
1902 "Bury this mail buffer."
1903 (let ((newbuf (other-buffer buffer
)))
1904 (bury-buffer buffer
)
1905 (if (and (fboundp 'frame-parameters
)
1906 (cdr (assq 'dedicated
(frame-parameters)))
1907 (not (null (delq (selected-frame) (visible-frame-list)))))
1908 (delete-frame (selected-frame))
1909 (switch-to-buffer newbuf
))))
1911 (defun message-send (&optional arg
)
1912 "Send the message in the current buffer.
1913 If `message-interactive' is non-nil, wait for success indication
1914 or error messages, and inform user.
1915 Otherwise any failure is reported in a message back to
1916 the user from the mailer."
1919 (when (or (buffer-modified-p)
1920 (message-check-element 'unchanged
)
1921 (y-or-n-p "No changes in the buffer; really send? "))
1922 ;; Make it possible to undo the coming changes.
1924 (let ((inhibit-read-only t
))
1925 (put-text-property (point-min) (point-max) 'read-only nil
))
1926 (message-fix-before-sending)
1927 (run-hooks 'message-send-hook
)
1928 (message "Sending...")
1929 (let ((alist message-send-method-alist
)
1933 (setq elem
(pop alist
)))
1934 (when (and (or (not (funcall (cadr elem
)))
1935 (and (or (not (memq (car elem
)
1936 message-sent-message-via
))
1939 "Already sent message via %s; resend? "
1941 (setq success
(funcall (caddr elem
) arg
)))))
1943 (when (and success sent
)
1945 ;;(when (fboundp 'mail-hist-put-headers-into-history)
1946 ;; (mail-hist-put-headers-into-history))
1947 (run-hooks 'message-sent-hook
)
1948 (message "Sending...done")
1949 ;; Mark the buffer as unmodified and delete auto-save.
1950 (set-buffer-modified-p nil
)
1951 (delete-auto-save-file-if-necessary t
)
1952 (message-disassociate-draft)
1953 ;; Delete other mail buffers and stuff.
1954 (message-do-send-housekeeping)
1955 (message-do-actions message-send-actions
)
1959 (defun message-send-via-mail (arg)
1960 "Send the current message via mail."
1961 (message-send-mail arg
))
1963 (defun message-send-via-news (arg)
1964 "Send the current message via news."
1965 (funcall message-send-news-function arg
))
1967 (defun message-fix-before-sending ()
1968 "Do various things to make the message nice before sending it."
1969 ;; Make sure there's a newline at the end of the message.
1970 (goto-char (point-max))
1973 ;; Make all invisible text visible.
1974 ;;(when (text-property-any (point-min) (point-max) 'invisible t)
1975 ;; (put-text-property (point-min) (point-max) 'invisible nil)
1976 ;; (unless (yes-or-no-p "Invisible text found and made visible; continue posting?")
1977 ;; (error "Invisible text found and made visible")))
1980 (defun message-add-action (action &rest types
)
1981 "Add ACTION to be performed when doing an exit of type TYPES."
1984 (set (setq var
(intern (format "message-%s-actions" (pop types
))))
1985 (nconc (symbol-value var
) (list action
))))))
1987 (defun message-do-actions (actions)
1988 "Perform all actions in ACTIONS."
1989 ;; Now perform actions on successful sending.
1993 ;; A simple function.
1994 ((message-functionp (car actions
))
1995 (funcall (car actions
)))
1996 ;; Something to be evaled.
1998 (eval (car actions
)))))
2001 (defun message-send-mail (&optional arg
)
2002 (require 'mail-utils
)
2003 (let ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
2004 (case-fold-search nil
)
2005 (news (message-news-p))
2006 (mailbuf (current-buffer)))
2008 (message-narrow-to-headers)
2009 ;; Insert some headers.
2010 (let ((message-deletable-headers
2011 (if news nil message-deletable-headers
)))
2012 (message-generate-headers message-required-mail-headers
))
2013 ;; Let the user do all of the above.
2014 (run-hooks 'message-header-hook
))
2019 ;; Avoid copying text props.
2021 "%s" (save-excursion
2022 (set-buffer mailbuf
)
2024 ;; Remove some headers.
2026 (message-narrow-to-headers)
2027 ;; Remove some headers.
2028 (message-remove-header message-ignored-mail-headers t
))
2029 (goto-char (point-max))
2030 ;; require one newline at the end.
2031 (or (= (preceding-char) ?
\n)
2034 (or (message-fetch-field "cc")
2035 (message-fetch-field "to")))
2036 (message-insert-courtesy-copy))
2037 (funcall message-send-mail-function
))
2038 (kill-buffer tembuf
))
2039 (set-buffer mailbuf
)
2040 (push 'mail message-sent-message-via
)))
2042 (defun message-send-mail-with-sendmail ()
2043 "Send off the prepared buffer with sendmail."
2044 (let ((errbuf (if message-interactive
2045 (generate-new-buffer " sendmail errors")
2047 resend-to-addresses delimline
)
2048 (let ((case-fold-search t
))
2050 (message-narrow-to-headers)
2051 (setq resend-to-addresses
(message-fetch-field "resent-to")))
2052 ;; Change header-delimiter to be what sendmail expects.
2053 (goto-char (point-min))
2055 (concat "^" (regexp-quote mail-header-separator
) "\n"))
2056 (replace-match "\n")
2058 (setq delimline
(point-marker))
2059 (run-hooks 'message-send-mail-hook
)
2060 ;; Insert an extra newline if we need it to work around
2061 ;; Sun's bug that swallows newlines.
2062 (goto-char (1+ delimline
))
2063 (when (eval message-mailer-swallows-blank-line
)
2065 (when message-interactive
2069 (let ((default-directory "/")
2070 (coding-system-for-write message-send-coding-system
))
2071 (apply 'call-process-region
2072 (append (list (point-min) (point-max)
2073 (if (boundp 'sendmail-program
)
2075 "/usr/lib/sendmail")
2076 nil errbuf nil
"-oi")
2077 ;; Always specify who from,
2078 ;; since some systems have broken sendmails.
2079 ;; But some systems are more broken with -f, so
2080 ;; we'll let users override this.
2081 (if (null message-sendmail-f-is-evil
)
2082 (list "-f" (user-login-name)))
2083 ;; These mean "report errors by mail"
2084 ;; and "deliver in background".
2085 (if (null message-interactive
) '("-oem" "-odb"))
2086 ;; Get the addresses from the message
2087 ;; unless this is a resend.
2088 ;; We must not do that for a resend
2089 ;; because we would find the original addresses.
2090 ;; For a resend, include the specific addresses.
2091 (if resend-to-addresses
2092 (list resend-to-addresses
)
2094 (when message-interactive
2097 (goto-char (point-min))
2098 (while (re-search-forward "\n\n* *" nil t
)
2099 (replace-match "; "))
2100 (if (not (zerop (buffer-size)))
2101 (error "Sending...failed to %s"
2102 (buffer-substring (point-min) (point-max)))))
2103 (when (bufferp errbuf
)
2104 (kill-buffer errbuf
)))))
2106 (defun message-send-mail-with-qmail ()
2107 "Pass the prepared message buffer to qmail-inject.
2108 Refer to the documentation for the variable `message-send-mail-function'
2109 to find out how to use this."
2110 ;; replace the header delimiter with a blank line
2111 (goto-char (point-min))
2113 (concat "^" (regexp-quote mail-header-separator
) "\n"))
2114 (replace-match "\n")
2115 (run-hooks 'message-send-mail-hook
)
2118 (let ((coding-system-for-write message-send-coding-system
))
2120 'call-process-region
1 (point-max) message-qmail-inject-program
2122 ;; qmail-inject's default behaviour is to look for addresses on the
2123 ;; command line; if there're none, it scans the headers.
2124 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
2126 ;; in general, ALL of qmail-inject's defaults are perfect for simply
2127 ;; reading a formatted (i. e., at least a To: or Resent-To header)
2128 ;; message from stdin.
2130 ;; qmail also has the advantage of not having been raped by
2131 ;; various vendors, so we don't have to allow for that, either --
2132 ;; compare this with message-send-mail-with-sendmail and weep
2133 ;; for sendmail's lost innocence.
2135 ;; all this is way cool coz it lets us keep the arguments entirely
2136 ;; free for -inject-arguments -- a big win for the user and for us
2137 ;; since we don't have to play that double-guessing game and the user
2138 ;; gets full control (no gestapo'ish -f's, for instance). --sj
2139 message-qmail-inject-args
))
2140 ;; qmail-inject doesn't say anything on it's stdout/stderr,
2141 ;; we have to look at the retval instead
2143 (1 (error "qmail-inject reported permanent failure"))
2144 (111 (error "qmail-inject reported transient failure"))
2145 ;; should never happen
2146 (t (error "qmail-inject reported unknown failure"))))
2148 (defun message-send-mail-with-mh ()
2149 "Send the prepared message buffer with mh."
2150 (let ((mh-previous-window-config nil
)
2151 (name (mh-new-draft-name)))
2152 (setq buffer-file-name name
)
2153 ;; MH wants to generate these headers itself.
2154 (when message-mh-deletable-headers
2155 (let ((headers message-mh-deletable-headers
))
2157 (goto-char (point-min))
2158 (and (re-search-forward
2159 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
2160 (message-delete-line))
2162 (run-hooks 'message-send-mail-hook
)
2163 ;; Pass it on to mh.
2166 (defun message-send-news (&optional arg
)
2167 (let ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
2168 (case-fold-search nil
)
2169 (method (if (message-functionp message-post-method
)
2170 (funcall message-post-method arg
)
2171 message-post-method
))
2172 (messbuf (current-buffer))
2173 (message-syntax-checks
2175 (cons '(existing-newsgroups . disabled
)
2176 message-syntax-checks
)
2177 message-syntax-checks
))
2180 (message-narrow-to-headers)
2181 ;; Insert some headers.
2182 (message-generate-headers message-required-news-headers
)
2183 ;; Let the user do all of the above.
2184 (run-hooks 'message-header-hook
))
2185 (message-cleanup-headers)
2186 (if (not (message-check-news-syntax))
2188 ;;(message "Posting not performed")
2193 (buffer-disable-undo (current-buffer))
2195 ;; Avoid copying text props.
2197 "%s" (save-excursion
2198 (set-buffer messbuf
)
2200 ;; Remove some headers.
2202 (message-narrow-to-headers)
2203 ;; Remove some headers.
2204 (message-remove-header message-ignored-news-headers t
))
2205 (goto-char (point-max))
2206 ;; require one newline at the end.
2207 (or (= (preceding-char) ?
\n)
2209 (let ((case-fold-search t
))
2210 ;; Remove the delimiter.
2211 (goto-char (point-min))
2213 (concat "^" (regexp-quote mail-header-separator
) "\n"))
2214 (replace-match "\n")
2216 (run-hooks 'message-send-news-hook
)
2217 ;;(require (car method))
2218 ;;(funcall (intern (format "%s-open-server" (car method)))
2219 ;;(cadr method) (cddr method))
2221 ;; (funcall (intern (format "%s-request-post" (car method)))
2223 (gnus-open-server method
)
2224 (setq result
(gnus-request-post method
)))
2225 (kill-buffer tembuf
))
2226 (set-buffer messbuf
)
2228 (push 'news message-sent-message-via
)
2229 (message "Couldn't send message via news: %s"
2230 (nnheader-get-report (car method
)))
2234 ;;; Header generation & syntax checking.
2237 (defmacro message-check
(type &rest forms
)
2238 "Eval FORMS if TYPE is to be checked."
2239 `(or (message-check-element ,type
)
2243 (put 'message-check
'lisp-indent-function
1)
2244 (put 'message-check
'edebug-form-spec
'(form body
))
2246 (defun message-check-element (type)
2247 "Returns non-nil if this type is not to be checked."
2248 (if (eq message-syntax-checks
'dont-check-for-anything-just-trust-me
)
2250 (let ((able (assq type message-syntax-checks
)))
2252 (eq (cdr able
) 'disabled
)))))
2254 (defun message-check-news-syntax ()
2255 "Check the syntax of the message."
2260 ;; We narrow to the headers and check them first.
2263 (message-narrow-to-headers)
2264 (message-check-news-header-syntax)))
2266 (message-check-news-body-syntax)))))
2268 (defun message-check-news-header-syntax ()
2270 ;; Check the Subject header.
2271 (message-check 'subject
2272 (let* ((case-fold-search t
)
2273 (subject (message-fetch-field "subject")))
2276 (not (string-match "\\`[ \t]*\\'" subject
)))
2279 "The subject field is empty or missing. Posting is denied.")))))
2280 ;; Check for commands in Subject.
2281 (message-check 'subject-cmsg
2282 (if (string-match "^cmsg " (message-fetch-field "subject"))
2284 "The control code \"cmsg\" is in the subject. Really post? ")
2286 ;; Check for multiple identical headers.
2287 (message-check 'multiple-headers
2289 (while (and (not found
)
2290 (re-search-forward "^[^ \t:]+: " nil t
))
2292 (or (re-search-forward
2297 (match-beginning 0) (- (match-end 0) 2))))
2302 (y-or-n-p (format "Multiple %s headers. Really post? " found
))
2304 ;; Check for Version and Sendsys.
2305 (message-check 'sendsys
2306 (if (re-search-forward "^Sendsys:\\|^Version:" nil t
)
2308 (format "The article contains a %s command. Really post? "
2309 (buffer-substring (match-beginning 0)
2310 (1- (match-end 0)))))
2312 ;; See whether we can shorten Followup-To.
2313 (message-check 'shorten-followup-to
2314 (let ((newsgroups (message-fetch-field "newsgroups"))
2315 (followup-to (message-fetch-field "followup-to"))
2317 (when (and newsgroups
2318 (string-match "," newsgroups
)
2323 (setq to
(completing-read
2324 "Followups to: (default all groups) "
2325 (mapcar (lambda (g) (list g
))
2327 (message-tokenize-header
2329 (goto-char (point-min))
2330 (insert "Followup-To: " to
"\n"))
2332 ;; Check "Shoot me".
2333 (message-check 'shoot
2334 (if (re-search-forward
2335 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t
)
2336 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
2338 ;; Check for Approved.
2339 (message-check 'approved
2340 (if (re-search-forward "^Approved:" nil t
)
2341 (y-or-n-p "The article contains an Approved header. Really post? ")
2343 ;; Check the Message-ID header.
2344 (message-check 'message-id
2345 (let* ((case-fold-search t
)
2346 (message-id (message-fetch-field "message-id" t
)))
2347 (or (not message-id
)
2348 ;; Is there an @ in the ID?
2349 (and (string-match "@" message-id
)
2350 ;; Is there a dot in the ID?
2351 (string-match "@[^.]*\\." message-id
)
2352 ;; Does the ID end with a dot?
2353 (not (string-match "\\.>" message-id
)))
2355 (format "The Message-ID looks strange: \"%s\". Really post? "
2357 ;; Check the Newsgroups & Followup-To headers.
2358 (message-check 'existing-newsgroups
2359 (let* ((case-fold-search t
)
2360 (newsgroups (message-fetch-field "newsgroups"))
2361 (followup-to (message-fetch-field "followup-to"))
2362 (groups (message-tokenize-header
2364 (concat newsgroups
"," followup-to
)
2366 (hashtb (and (boundp 'gnus-active-hashtb
)
2367 gnus-active-hashtb
))
2369 (if (or (not hashtb
)
2370 (not (boundp 'gnus-read-active-file
))
2371 (not gnus-read-active-file
)
2372 (eq gnus-read-active-file
'some
))
2375 (when (and (not (boundp (intern (car groups
) hashtb
)))
2376 (not (equal (car groups
) "poster")))
2377 (push (car groups
) errors
))
2383 "Really post to %s unknown group%s: %s "
2384 (if (= (length errors
) 1) "this" "these")
2385 (if (= (length errors
) 1) "" "s")
2386 (mapconcat 'identity errors
", ")))))))
2387 ;; Check the Newsgroups & Followup-To headers for syntax errors.
2388 (message-check 'valid-newsgroups
2389 (let ((case-fold-search t
)
2390 (headers '("Newsgroups" "Followup-To"))
2392 (while (and headers
(not error
))
2393 (when (setq header
(mail-fetch-field (car headers
)))
2397 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
2402 (not (string-match "\\.\\'\\|\\.\\." g
)))
2403 (message-tokenize-header header
","))))
2410 (format "The %s header looks odd: \"%s\". Really post? "
2411 (car headers
) header
)))))
2412 (message-check 'repeated-newsgroups
2413 (let ((case-fold-search t
)
2414 (headers '("Newsgroups" "Followup-To"))
2415 header error groups group
)
2418 (when (setq header
(mail-fetch-field (pop headers
)))
2419 (setq groups
(message-tokenize-header header
","))
2420 (while (setq group
(pop groups
))
2421 (when (member group groups
)
2427 (format "Group %s is repeated in headers. Really post? " error
)))))
2428 ;; Check the From header.
2429 (message-check 'from
2430 (let* ((case-fold-search t
)
2431 (from (message-fetch-field "from"))
2432 (ad (nth 1 (mail-extract-address-components from
))))
2435 (message "There is no From line. Posting is denied.")
2437 ((or (not (string-match "@[^\\.]*\\." ad
)) ;larsi@ifi
2438 (string-match "\\.\\." ad
) ;larsi@ifi..uio
2439 (string-match "@\\." ad
) ;larsi@.ifi.uio
2440 (string-match "\\.$" ad
) ;larsi@ifi.uio.
2441 (not (string-match "^[^@]+@[^@]+$" ad
)) ;larsi.ifi.uio
2442 (string-match "(.*).*(.*)" from
)) ;(lars) (lars)
2444 "Denied posting -- the From looks strange: \"%s\"." from
)
2448 (defun message-check-news-body-syntax ()
2450 ;; Check for long lines.
2451 (message-check 'long-lines
2452 (goto-char (point-min))
2454 (concat "^" (regexp-quote mail-header-separator
) "$"))
2458 (< (current-column) 80))
2459 (zerop (forward-line 1))))
2463 "You have lines longer than 79 characters. Really post? ")))
2464 ;; Check whether the article is empty.
2465 (message-check 'empty
2466 (goto-char (point-min))
2468 (concat "^" (regexp-quote mail-header-separator
) "$"))
2471 (goto-char (point-max))
2472 (re-search-backward message-signature-separator nil t
)
2474 (or (re-search-backward "[^ \n\t]" b t
)
2475 (y-or-n-p "Empty article. Really post? "))))
2476 ;; Check for control characters.
2477 (message-check 'control-chars
2478 (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t
)
2480 "The article contains control characters. Really post? ")
2482 ;; Check excessive size.
2483 (message-check 'size
2484 (if (> (buffer-size) 60000)
2486 (format "The article is %d octets long. Really post? "
2489 ;; Check whether any new text has been added.
2490 (message-check 'new-text
2492 (not message-checksum
)
2493 (not (eq (message-checksum) message-checksum
))
2495 "It looks like no new text has been added. Really post? ")))
2496 ;; Check the length of the signature.
2497 (message-check 'signature
2498 (goto-char (point-max))
2499 (if (or (not (re-search-backward message-signature-separator nil t
))
2500 (search-forward message-forward-end-separator nil t
))
2502 (if (> (count-lines (point) (point-max)) 5)
2505 "Your .sig is %d lines; it should be max 4. Really post? "
2506 (1- (count-lines (point) (point-max)))))
2509 (defun message-checksum ()
2510 "Return a \"checksum\" for the current buffer."
2513 (goto-char (point-min))
2515 (concat "^" (regexp-quote mail-header-separator
) "$"))
2517 (when (not (looking-at "[ \t\n]"))
2518 (setq sum
(logxor (ash sum
1) (if (natnump sum
) 0 1)
2523 (defun message-do-fcc ()
2524 "Process Fcc headers in the current buffer."
2525 (let ((case-fold-search t
)
2526 (buf (current-buffer))
2529 (set-buffer (get-buffer-create " *message temp*"))
2530 (buffer-disable-undo (current-buffer))
2532 (insert-buffer-substring buf
)
2534 (message-narrow-to-headers)
2535 (while (setq file
(message-fetch-field "fcc"))
2537 (message-remove-header "fcc" nil t
)))
2538 (goto-char (point-min))
2539 (re-search-forward (concat "^" (regexp-quote mail-header-separator
) "$"))
2540 (replace-match "" t t
)
2541 ;; Process FCC operations.
2543 (setq file
(pop list
))
2544 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file
)
2545 ;; Pipe the article to the program in question.
2546 (call-process-region (point-min) (point-max) shell-file-name
2547 nil nil nil shell-command-switch
2548 (match-string 1 file
))
2549 ;; Save the article.
2550 (setq file
(expand-file-name file
))
2551 (unless (file-exists-p (file-name-directory file
))
2552 (make-directory (file-name-directory file
) t
))
2553 (if (and message-fcc-handler-function
2554 (not (eq message-fcc-handler-function
'rmail-output
)))
2555 (funcall message-fcc-handler-function file
)
2556 (if (and (file-readable-p file
) (mail-file-babyl-p file
))
2557 (rmail-output file
1 nil t
)
2558 (let ((mail-use-rfc822 t
))
2559 (rmail-output file
1 t t
))))))
2561 (kill-buffer (current-buffer)))))
2563 (defun message-output (filename)
2564 "Append this article to Unix/babyl mail file.."
2565 (if (and (file-readable-p filename
)
2566 (mail-file-babyl-p filename
))
2567 (gnus-output-to-rmail filename t
)
2568 (gnus-output-to-mail filename t
)))
2570 (defun message-cleanup-headers ()
2571 "Do various automatic cleanups of the headers."
2572 ;; Remove empty lines in the header.
2574 (message-narrow-to-headers)
2575 ;; Remove blank lines.
2576 (while (re-search-forward "^[ \t]*\n" nil t
)
2577 (replace-match "" t t
))
2579 ;; Correct Newsgroups and Followup-To headers: Change sequence of
2580 ;; spaces to comma and eliminate spaces around commas. Eliminate
2581 ;; embedded line breaks.
2582 (goto-char (point-min))
2583 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t
)
2587 (if (re-search-forward "^[^ \t]" nil t
)
2591 (goto-char (point-min))
2592 (while (re-search-forward "\n[ \t]+" nil t
)
2593 (replace-match " " t t
)) ;No line breaks (too confusing)
2594 (goto-char (point-min))
2595 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t
)
2596 (replace-match "," t t
))
2597 (goto-char (point-min))
2598 ;; Remove trailing commas.
2599 (when (re-search-forward ",+$" nil t
)
2600 (replace-match "" t t
))))))
2602 (defun message-make-date ()
2603 "Make a valid data header."
2604 (let ((now (current-time)))
2605 (timezone-make-date-arpa-standard
2606 (current-time-string now
) (current-time-zone now
))))
2608 (defun message-make-message-id ()
2609 "Make a unique Message-ID."
2610 (concat "<" (message-unique-id)
2611 (let ((psubject (save-excursion (message-fetch-field "subject")))
2613 (save-excursion (message-fetch-field "supersedes"))))
2615 (and message-reply-headers
2616 (mail-header-references message-reply-headers
)
2617 (mail-header-subject message-reply-headers
)
2619 (mail-header-subject message-reply-headers
)
2621 (message-strip-subject-re
2622 (mail-header-subject message-reply-headers
))
2623 (message-strip-subject-re psubject
))))
2625 (string-match "_-_@" psupersedes
)))
2627 "@" (message-make-fqdn) ">"))
2629 (defvar message-unique-id-char nil
)
2631 ;; If you ever change this function, make sure the new version
2632 ;; cannot generate IDs that the old version could.
2633 ;; You might for example insert a "." somewhere (not next to another dot
2634 ;; or string boundary), or modify the "fsf" string.
2635 (defun message-unique-id ()
2636 ;; Don't use microseconds from (current-time), they may be unsupported.
2637 ;; Instead we use this randomly inited counter.
2638 (setq message-unique-id-char
2639 (%
(1+ (or message-unique-id-char
(logand (random t
) (1- (lsh 1 20)))))
2640 ;; (current-time) returns 16-bit ints,
2641 ;; and 2^16*25 just fits into 4 digits i base 36.
2643 (let ((tm (current-time)))
2645 (if (memq system-type
'(ms-dos emx vax-vms
))
2646 (let ((user (downcase (user-login-name))))
2647 (while (string-match "[^a-z0-9_]" user
)
2648 (aset user
(match-beginning 0) ?_
))
2650 (message-number-base36 (user-uid) -
1))
2651 (message-number-base36 (+ (car tm
)
2652 (lsh (% message-unique-id-char
25) 16)) 4)
2653 (message-number-base36 (+ (nth 1 tm
)
2654 (lsh (/ message-unique-id-char
25) 16)) 4)
2655 ;; Append the newsreader name, because while the generated
2656 ;; ID is unique to this newsreader, other newsreaders might
2657 ;; otherwise generate the same ID via another algorithm.
2660 (defun message-number-base36 (num len
)
2665 (concat (message-number-base36 (/ num
36) (1- len
))
2666 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
2669 (defun message-make-organization ()
2670 "Make an Organization header."
2671 (let* ((organization
2672 (when message-user-organization
2673 (if (message-functionp message-user-organization
)
2674 (funcall message-user-organization
)
2675 message-user-organization
))))
2677 (message-set-work-buffer)
2678 (cond ((stringp organization
)
2679 (insert organization
))
2680 ((and (eq t organization
)
2681 message-user-organization-file
2682 (file-exists-p message-user-organization-file
))
2683 (insert-file-contents message-user-organization-file
)))
2684 (goto-char (point-min))
2685 (while (re-search-forward "[\t\n]+" nil t
)
2686 (replace-match "" t t
))
2687 (unless (zerop (buffer-size))
2690 (defun message-make-lines ()
2691 "Count the number of lines and return numeric string."
2695 (goto-char (point-min))
2697 (concat "^" (regexp-quote mail-header-separator
) "$"))
2699 (int-to-string (count-lines (point) (point-max))))))
2701 (defun message-make-in-reply-to ()
2702 "Return the In-Reply-To header for this message."
2703 (when message-reply-headers
2704 (let ((from (mail-header-from message-reply-headers
))
2705 (date (mail-header-date message-reply-headers
)))
2708 (string-match " *at \\| *@ \\| *(\\| *<" from
)))
2709 (concat (if (and stop-pos
2710 (not (zerop stop-pos
)))
2711 (substring from
0 stop-pos
) from
)
2713 (if (or (not date
) (string= date
""))
2714 "(unknown date)" date
)
2717 (defun message-make-distribution ()
2718 "Make a Distribution header."
2719 (let ((orig-distribution (message-fetch-reply-field "distribution")))
2720 (cond ((message-functionp message-distribution-function
)
2721 (funcall message-distribution-function
))
2722 (t orig-distribution
))))
2724 (defun message-make-expires ()
2725 "Return an Expires header based on `message-expires'."
2726 (let ((current (current-time))
2727 (future (* 1.0 message-expires
60 60 24)))
2728 ;; Add the future to current.
2729 (setcar current
(+ (car current
) (round (/ future
(expt 2 16)))))
2730 (setcar (cdr current
) (+ (nth 1 current
) (%
(round future
) (expt 2 16))))
2731 ;; Return the date in the future in UT.
2732 (timezone-make-date-arpa-standard
2733 (current-time-string current
) (current-time-zone current
) '(0 "UT"))))
2735 (defun message-make-path ()
2737 (let ((login-name (user-login-name)))
2738 (cond ((null message-user-path
)
2739 (concat (system-name) "!" login-name
))
2740 ((stringp message-user-path
)
2741 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
2742 (concat message-user-path
"!" login-name
))
2745 (defun message-make-from ()
2746 "Make a From header."
2747 (let* ((style message-from-style
)
2748 (login (message-make-address))
2750 (or (and (boundp 'user-full-name
)
2753 (when (string= fullname
"&")
2754 (setq fullname
(user-login-name)))
2756 (message-set-work-buffer)
2759 (equal fullname
""))
2761 ((or (eq style
'angles
)
2762 (and (not (eq style
'parens
))
2763 ;; Use angles if no quoting is needed, or if parens would
2764 ;; need quoting too.
2765 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname
))
2766 (let ((tmp (concat fullname nil
)))
2767 (while (string-match "([^()]*)" tmp
)
2768 (aset tmp
(match-beginning 0) ?-
)
2769 (aset tmp
(1- (match-end 0)) ?-
))
2770 (string-match "[\\()]" tmp
)))))
2772 (goto-char (point-min))
2773 ;; Look for a character that cannot appear unquoted
2774 ;; according to RFC 822.
2775 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil
1)
2776 ;; Quote fullname, escaping specials.
2777 (goto-char (point-min))
2779 (while (re-search-forward "[\"\\]" nil
1)
2780 (replace-match "\\\\\\&" t
))
2782 (insert " <" login
">"))
2783 (t ; 'parens or default
2785 (let ((fullname-start (point)))
2787 (goto-char fullname-start
)
2788 ;; RFC 822 says \ and nonmatching parentheses
2789 ;; must be escaped in comments.
2790 ;; Escape every instance of ()\ ...
2791 (while (re-search-forward "[()\\]" nil
1)
2792 (replace-match "\\\\\\&" t
))
2793 ;; ... then undo escaping of matching parentheses,
2794 ;; including matching nested parentheses.
2795 (goto-char fullname-start
)
2796 (while (re-search-forward
2797 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
2799 (replace-match "\\1(\\3)" t
)
2800 (goto-char fullname-start
)))
2804 (defun message-make-sender ()
2805 "Return the \"real\" user address.
2806 This function tries to ignore all user modifications, and
2807 give as trustworthy answer as possible."
2808 (concat (user-login-name) "@" (system-name)))
2810 (defun message-make-address ()
2811 "Make the address of the user."
2812 (or (message-user-mail-address)
2813 (concat (user-login-name) "@" (message-make-domain))))
2815 (defun message-user-mail-address ()
2816 "Return the pertinent part of `user-mail-address'."
2817 (when user-mail-address
2818 (if (string-match " " user-mail-address
)
2819 (nth 1 (mail-extract-address-components user-mail-address
))
2820 user-mail-address
)))
2822 (defun message-make-fqdn ()
2823 "Return user's fully qualified domain name."
2824 (let ((system-name (system-name))
2825 (user-mail (message-user-mail-address)))
2827 ((string-match "[^.]\\.[^.]" system-name
)
2828 ;; `system-name' returned the right result.
2830 ;; Try `mail-host-address'.
2831 ((and (boundp 'mail-host-address
)
2832 (stringp mail-host-address
)
2833 (string-match "\\." mail-host-address
))
2835 ;; We try `user-mail-address' as a backup.
2837 (string-match "\\." user-mail
)
2838 (string-match "@\\(.*\\)\\'" user-mail
))
2839 (match-string 1 user-mail
))
2840 ;; Default to this bogus thing.
2842 (concat system-name
".i-did-not-set--mail-host-address--so-shoot-me")))))
2844 (defun message-make-host-name ()
2845 "Return the name of the host."
2846 (let ((fqdn (message-make-fqdn)))
2847 (string-match "^[^.]+\\." fqdn
)
2848 (substring fqdn
0 (1- (match-end 0)))))
2850 (defun message-make-domain ()
2851 "Return the domain name."
2852 (or mail-host-address
2853 (message-make-fqdn)))
2855 (defun message-generate-headers (headers)
2856 "Prepare article HEADERS.
2857 Headers already prepared in the buffer are not modified."
2859 (message-narrow-to-headers)
2860 (let* ((Date (message-make-date))
2861 (Message-ID (message-make-message-id))
2862 (Organization (message-make-organization))
2863 (From (message-make-from))
2864 (Path (message-make-path))
2867 (In-Reply-To (message-make-in-reply-to))
2869 (Distribution (message-make-distribution))
2870 (Lines (message-make-lines))
2871 (X-Newsreader message-newsreader
)
2872 (X-Mailer (and (not (message-fetch-field "X-Newsreader"))
2874 (Expires (message-make-expires))
2875 (case-fold-search t
)
2877 ;; First we remove any old generated headers.
2878 (let ((headers message-deletable-headers
))
2879 (unless (buffer-modified-p)
2880 (setq headers
(delq 'Message-ID
(copy-sequence headers
))))
2882 (goto-char (point-min))
2883 (and (re-search-forward
2884 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
2885 (get-text-property (1+ (match-beginning 0)) 'message-deletable
)
2886 (message-delete-line))
2888 ;; Go through all the required headers and see if they are in the
2889 ;; articles already. If they are not, or are empty, they are
2890 ;; inserted automatically - except for Subject, Newsgroups and
2893 (goto-char (point-min))
2894 (setq elem
(pop headers
))
2896 (if (eq (car elem
) 'optional
)
2897 (setq header
(cdr elem
))
2898 (setq header
(car elem
)))
2900 (when (or (not (re-search-forward
2904 (if (stringp header
)
2906 (symbol-name header
))))
2910 ;; The header was found. We insert a space after the
2911 ;; colon, if there is none.
2912 (if (/= (following-char) ?
) (insert " ") (forward-char 1))
2913 ;; Find out whether the header is empty...
2914 (looking-at "[ \t]*$")))
2915 ;; So we find out what value we should insert.
2918 ((and (consp elem
) (eq (car elem
) 'optional
))
2919 ;; This is an optional header. If the cdr of this
2920 ;; is something that is nil, then we do not insert
2922 (setq header
(cdr elem
))
2923 (or (and (fboundp (cdr elem
)) (funcall (cdr elem
)))
2924 (and (boundp (cdr elem
)) (symbol-value (cdr elem
)))))
2926 ;; The element is a cons. Either the cdr is a
2927 ;; string to be inserted verbatim, or it is a
2928 ;; function, and we insert the value returned from
2930 (or (and (stringp (cdr elem
)) (cdr elem
))
2931 (and (fboundp (cdr elem
)) (funcall (cdr elem
)))))
2932 ((and (boundp header
) (symbol-value header
))
2933 ;; The element is a symbol. We insert the value
2934 ;; of this symbol, if any.
2935 (symbol-value header
))
2937 ;; We couldn't generate a value for this header,
2938 ;; so we just ask the user.
2939 (read-from-minibuffer
2940 (format "Empty header for %s; enter value: " header
)))))
2941 ;; Finally insert the header.
2943 (not (equal value
"")))
2947 ;; This header didn't exist, so we insert it.
2948 (goto-char (point-max))
2949 (insert (if (stringp header
) header
(symbol-name header
))
2952 ;; The value of this header was empty, so we clear
2953 ;; totally and insert the new value.
2954 (delete-region (point) (gnus-point-at-eol))
2956 ;; Add the deletable property to the headers that require it.
2957 (and (memq header message-deletable-headers
)
2958 (progn (beginning-of-line) (looking-at "[^:]+: "))
2959 (add-text-properties
2960 (point) (match-end 0)
2961 '(message-deletable t face italic
) (current-buffer)))))))
2962 ;; Insert new Sender if the From is strange.
2963 (let ((from (message-fetch-field "from"))
2964 (sender (message-fetch-field "sender"))
2965 (secure-sender (message-make-sender)))
2967 (not (message-check-element 'sender
))
2970 (cadr (mail-extract-address-components from
)))
2971 (downcase secure-sender
)))
2976 (cadr (mail-extract-address-components sender
)))
2977 (downcase secure-sender
)))))
2978 (goto-char (point-min))
2979 ;; Rename any old Sender headers to Original-Sender.
2980 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t
)
2982 (insert "Original-")
2983 (beginning-of-line))
2984 (when (or (message-news-p)
2985 (string-match "@.+\\.." secure-sender
))
2986 (insert "Sender: " secure-sender
"\n")))))))
2988 (defun message-insert-courtesy-copy ()
2989 "Insert a courtesy message in mail copies of combined messages."
2993 (message-narrow-to-headers)
2994 (when (setq newsgroups
(message-fetch-field "newsgroups"))
2995 (goto-char (point-max))
2996 (insert "Posted-To: " newsgroups
"\n")))
2998 (when message-courtesy-message
3000 ((string-match "%s" message-courtesy-message
)
3001 (insert (format message-courtesy-message newsgroups
)))
3003 (insert message-courtesy-message
)))))))
3006 ;;; Setting up a message buffer
3009 (defun message-fill-address (header value
)
3011 (narrow-to-region (point) (point))
3012 (insert (capitalize (symbol-name header
))
3014 (if (consp value
) (car value
) value
)
3016 (narrow-to-region (point-min) (1- (point-max)))
3018 (goto-char (point-min))
3020 (skip-chars-forward "^,\"" (point-max))
3021 (if (or (= (following-char) ?
,)
3024 (if (and (> (current-column) 78)
3030 (setq last
(1+ (point))))
3031 (setq last
(1+ (point)))))
3032 (setq quoted
(not quoted
)))
3035 (goto-char (point-max))
3039 (defun message-fill-header (header value
)
3040 (let ((begin (point))
3043 (insert (capitalize (symbol-name header
))
3045 (if (consp value
) (car value
) value
)
3048 (narrow-to-region begin
(point))
3049 (fill-region-as-paragraph begin
(point))
3050 ;; Tapdance around looong Message-IDs.
3052 (when (looking-at "[ \t]*$")
3053 (message-delete-line))
3055 (re-search-forward ":" nil t
)
3056 (when (looking-at "\n[ \t]+")
3057 (replace-match " " t t
))
3058 (goto-char (point-max)))))
3060 (defun message-shorten-references (header references
)
3061 "Limit REFERENCES to be shorter than 988 characters."
3065 (nnheader-temp-write nil
3067 (goto-char (point-min))
3068 (while (re-search-forward "<[^>]+>" nil t
)
3069 (push (match-string 0) refs
))
3070 (setq refs
(nreverse refs
))
3071 (while (> (length (mapconcat 'identity refs
" ")) max
)
3072 (when (< (length refs
) (1+ cut
))
3074 (setcdr (nthcdr cut refs
) (cddr (nthcdr cut refs
)))))
3075 (insert (capitalize (symbol-name header
)) ": "
3076 (mapconcat 'identity refs
" ") "\n")))
3078 (defun message-position-point ()
3079 "Move point to where the user probably wants to find it."
3080 (message-narrow-to-headers)
3082 ((re-search-forward "^[^:]+:[ \t]*$" nil t
)
3083 (search-backward ":" )
3086 (if (= (following-char) ?
)
3090 (goto-char (point-max))
3093 (unless (looking-at "$")
3097 (defun message-buffer-name (type &optional to group
)
3098 "Return a new (unique) buffer name based on TYPE and TO."
3100 ;; Check whether `message-generate-new-buffers' is a function,
3101 ;; and if so, call it.
3102 ((message-functionp message-generate-new-buffers
)
3103 (funcall message-generate-new-buffers type to group
))
3104 ;; Generate a new buffer name The Message Way.
3105 (message-generate-new-buffers
3106 (generate-new-buffer-name
3110 (or (car (mail-extract-address-components to
))
3113 (if (and group
(not (string= group
""))) (concat " on " group
) "")
3115 ;; Use standard name.
3117 (format "*%s message*" type
))))
3119 (defun message-pop-to-buffer (name)
3120 "Pop to buffer NAME, and warn if it already exists and is modified."
3121 (let ((buffer (get-buffer name
)))
3123 (buffer-name buffer
))
3125 (set-buffer (pop-to-buffer buffer
))
3126 (when (and (buffer-modified-p)
3128 "Message already being composed; erase? ")))
3129 (error "Message being composed")))
3130 (set-buffer (pop-to-buffer name
)))
3134 (defun message-do-send-housekeeping ()
3135 "Kill old message buffers."
3136 ;; We might have sent this buffer already. Delete it from the
3138 (setq message-buffer-list
(delq (current-buffer) message-buffer-list
))
3139 (while (and message-max-buffers
3141 (>= (length message-buffer-list
) message-max-buffers
))
3142 ;; Kill the oldest buffer -- unless it has been changed.
3143 (let ((buffer (pop message-buffer-list
)))
3144 (when (and (buffer-name buffer
)
3145 (not (buffer-modified-p buffer
)))
3146 (kill-buffer buffer
))))
3147 ;; Rename the buffer.
3148 (if message-send-rename-function
3149 (funcall message-send-rename-function
)
3150 (when (string-match "\\`\\*" (buffer-name))
3152 (concat "*sent " (substring (buffer-name) (match-end 0))) t
)))
3153 ;; Push the current buffer onto the list.
3154 (when message-max-buffers
3155 (setq message-buffer-list
3156 (nconc message-buffer-list
(list (current-buffer))))))
3158 (defvar mc-modes-alist
)
3159 (defun message-setup (headers &optional replybuffer actions
)
3160 (when (and (boundp 'mc-modes-alist
)
3161 (not (assq 'message-mode mc-modes-alist
)))
3162 (push '(message-mode (encrypt . mc-encrypt-message
)
3163 (sign . mc-sign-message
))
3166 (setq message-send-actions actions
))
3167 (setq message-reply-buffer replybuffer
)
3168 (goto-char (point-min))
3169 ;; Insert all the headers.
3172 (alist message-header-format-alist
))
3174 (unless (assq (caar h
) message-header-format-alist
)
3175 (push (list (caar h
)) alist
))
3179 (delete-region (point) (progn (forward-line -
1) (point)))
3180 (when message-default-headers
3181 (insert message-default-headers
)
3182 (or (bolp) (insert ?
\n)))
3186 (insert mail-header-separator
"\n")
3190 (when (message-news-p)
3191 (when message-default-news-headers
3192 (insert message-default-news-headers
)
3193 (or (bolp) (insert ?
\n)))
3194 (when message-generate-headers-first
3195 (message-generate-headers
3198 (copy-sequence message-required-news-headers
))))))
3199 (when (message-mail-p)
3200 (when message-default-mail-headers
3201 (insert message-default-mail-headers
)
3202 (or (bolp) (insert ?
\n)))
3203 (when message-generate-headers-first
3204 (message-generate-headers
3207 (copy-sequence message-required-mail-headers
))))))
3208 (run-hooks 'message-signature-setup-hook
)
3209 (message-insert-signature)
3211 (message-narrow-to-headers)
3212 (run-hooks 'message-header-setup-hook
))
3213 (set-buffer-modified-p nil
)
3214 (setq buffer-undo-list nil
)
3215 (run-hooks 'message-setup-hook
)
3216 (message-position-point)
3219 (defun message-set-auto-save-file-name ()
3220 "Associate the message buffer with a file in the drafts directory."
3221 (when message-auto-save-directory
3223 (setq message-draft-article
3224 (nndraft-request-associate-buffer "drafts"))
3225 (setq buffer-file-name
(expand-file-name "*message*"
3226 message-auto-save-directory
))
3227 (setq buffer-auto-save-file-name
(make-auto-save-file-name)))
3228 (clear-visited-file-modtime)))
3230 (defun message-disassociate-draft ()
3231 "Disassociate the message buffer from the drafts directory."
3232 (when message-draft-article
3233 (nndraft-request-expire-articles
3234 (list message-draft-article
) "drafts" nil t
)))
3239 ;;; Commands for interfacing with message
3243 (defun message-mail (&optional to subject
3244 other-headers continue switch-function
3245 yank-action send-actions
)
3246 "Start editing a mail message to be sent.
3247 OTHER-HEADERS is an alist of header/value pairs."
3249 (let ((message-this-is-mail t
))
3250 (message-pop-to-buffer (message-buffer-name "mail" to
))
3253 `((To .
,(or to
"")) (Subject .
,(or subject
"")))
3254 (when other-headers other-headers
)))))
3257 (defun message-news (&optional newsgroups subject
)
3258 "Start editing a news article to be sent."
3260 (let ((message-this-is-news t
))
3261 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups
))
3262 (message-setup `((Newsgroups .
,(or newsgroups
""))
3263 (Subject .
,(or subject
""))))))
3266 (defun message-reply (&optional to-address wide
)
3267 "Start editing a reply to the article in the current buffer."
3269 (let ((cur (current-buffer))
3270 from subject date reply-to to cc
3271 references message-id follow-to
3272 (inhibit-point-motion-hooks t
)
3273 mct never-mct gnus-warning
)
3275 (message-narrow-to-head)
3276 ;; Allow customizations to have their say.
3278 ;; This is a regular reply.
3279 (if (message-functionp message-reply-to-function
)
3280 (setq follow-to
(funcall message-reply-to-function
)))
3281 ;; This is a followup.
3282 (if (message-functionp message-wide-reply-to-function
)
3285 (funcall message-wide-reply-to-function
)))))
3286 ;; Find all relevant headers we need.
3287 (setq from
(message-fetch-field "from")
3288 date
(message-fetch-field "date")
3289 subject
(or (message-fetch-field "subject") "none")
3290 to
(message-fetch-field "to")
3291 cc
(message-fetch-field "cc")
3292 mct
(message-fetch-field "mail-copies-to")
3293 reply-to
(message-fetch-field "reply-to")
3294 references
(message-fetch-field "references")
3295 message-id
(message-fetch-field "message-id" t
))
3296 ;; Remove any (buggy) Re:'s that are present and make a
3298 (when (string-match message-subject-re-regexp subject
)
3299 (setq subject
(substring subject
(match-end 0))))
3300 (setq subject
(concat "Re: " subject
))
3302 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
3303 (string-match "<[^>]+>" gnus-warning
))
3304 (setq message-id
(match-string 0 gnus-warning
)))
3306 ;; Handle special values of Mail-Copies-To.
3308 (cond ((equal (downcase mct
) "never")
3311 ((equal (downcase mct
) "always")
3312 (setq mct
(or reply-to from
)))))
3318 (setq follow-to
(list (cons 'To
(or to-address reply-to from
))))
3319 (when (and wide mct
)
3320 (push (cons 'Cc mct
) follow-to
)))
3323 (message-set-work-buffer)
3325 (insert (or reply-to from
"")))
3326 (insert (if to
(concat (if (bolp) "" ", ") to
"") ""))
3327 (insert (if mct
(concat (if (bolp) "" ", ") mct
) ""))
3328 (insert (if cc
(concat (if (bolp) "" ", ") cc
) ""))
3329 (goto-char (point-min))
3330 (while (re-search-forward "[ \t]+" nil t
)
3331 (replace-match " " t t
))
3332 ;; Remove addresses that match `rmail-dont-reply-to-names'.
3333 (insert (prog1 (rmail-dont-reply-to (buffer-string))
3335 (goto-char (point-min))
3336 ;; Perhaps Mail-Copies-To: never removed the only address?
3338 (insert (or reply-to from
"")))
3342 (cons (mail-strip-quoted-names addr
) addr
))
3343 (message-tokenize-header (buffer-string))))
3346 (setq ccalist
(delq (assoc (car (pop s
)) s
) ccalist
)))))
3347 (setq follow-to
(list (cons 'To
(cdr (pop ccalist
)))))
3349 (let ((ccs (cons 'Cc
(mapconcat
3350 (lambda (addr) (cdr addr
)) ccalist
", "))))
3351 (when (string-match "^ +" (cdr ccs
))
3352 (setcdr ccs
(substring (cdr ccs
) (match-end 0))))
3353 (push ccs follow-to
))))))
3356 (message-pop-to-buffer (message-buffer-name
3357 (if wide
"wide reply" "reply") from
3358 (if wide to-address nil
)))
3360 (setq message-reply-headers
3361 (vector 0 subject from date message-id references
0 0 ""))
3364 `((Subject .
,subject
)
3366 ,@(if (or references message-id
)
3367 `((References .
,(concat (or references
"") (and references
" ")
3368 (or message-id
""))))
3373 (defun message-wide-reply (&optional to-address
)
3374 "Make a \"wide\" reply to the message in the current buffer."
3376 (message-reply to-address t
))
3379 (defun message-followup (&optional to-newsgroups
)
3380 "Follow up to the message in the current buffer.
3381 If TO-NEWSGROUPS, use that as the new Newsgroups line."
3383 (let ((cur (current-buffer))
3384 from subject date reply-to mct
3385 references message-id follow-to
3386 (inhibit-point-motion-hooks t
)
3387 (message-this-is-news t
)
3388 followup-to distribution newsgroups gnus-warning posted-to
)
3391 (goto-char (point-min))
3392 (if (search-forward "\n\n" nil t
)
3395 (when (message-functionp message-followup-to-function
)
3397 (funcall message-followup-to-function
)))
3398 (setq from
(message-fetch-field "from")
3399 date
(message-fetch-field "date")
3400 subject
(or (message-fetch-field "subject") "none")
3401 references
(message-fetch-field "references")
3402 message-id
(message-fetch-field "message-id" t
)
3403 followup-to
(message-fetch-field "followup-to")
3404 newsgroups
(message-fetch-field "newsgroups")
3405 posted-to
(message-fetch-field "posted-to")
3406 reply-to
(message-fetch-field "reply-to")
3407 distribution
(message-fetch-field "distribution")
3408 mct
(message-fetch-field "mail-copies-to"))
3409 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
3410 (string-match "<[^>]+>" gnus-warning
))
3411 (setq message-id
(match-string 0 gnus-warning
)))
3412 ;; Remove bogus distribution.
3413 (when (and (stringp distribution
)
3414 (let ((case-fold-search t
))
3415 (string-match "world" distribution
)))
3416 (setq distribution nil
))
3417 ;; Remove any (buggy) Re:'s that are present and make a
3419 (when (string-match message-subject-re-regexp subject
)
3420 (setq subject
(substring subject
(match-end 0))))
3421 (setq subject
(concat "Re: " subject
))
3424 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups
))
3427 `((Subject .
,subject
)
3430 (list (cons 'Newsgroups to-newsgroups
)))
3431 (follow-to follow-to
)
3432 ((and followup-to message-use-followup-to
)
3435 ((equal (downcase followup-to
) "poster")
3436 (if (or (eq message-use-followup-to
'use
)
3437 (message-y-or-n-p "Obey Followup-To: poster? " t
"\
3438 You should normally obey the Followup-To: header.
3440 `Followup-To: poster' sends your response via e-mail instead of news.
3442 A typical situation where `Followup-To: poster' is used is when the poster
3443 does not read the newsgroup, so he wouldn't see any replies sent to it."))
3445 (setq message-this-is-news nil
)
3446 (cons 'To
(or reply-to from
"")))
3447 (cons 'Newsgroups newsgroups
)))
3449 (if (or (equal followup-to newsgroups
)
3450 (not (eq message-use-followup-to
'ask
))
3452 (concat "Obey Followup-To: " followup-to
"? ") t
"\
3453 You should normally obey the Followup-To: header.
3455 `Followup-To: " followup-to
"'
3456 directs your response to " (if (string-match "," followup-to
)
3457 "the specified newsgroups"
3458 "that newsgroup only") ".
3460 If a message is posted to several newsgroups, Followup-To is often
3461 used to direct the following discussion to one newsgroup only,
3462 because discussions that are spread over several newsgroup tend to
3463 be fragmented and very difficult to follow.
3465 Also, some source/announcement newsgroups are not indented for discussion;
3466 responses here are directed to other newsgroups."))
3467 (cons 'Newsgroups followup-to
)
3468 (cons 'Newsgroups newsgroups
))))))
3470 `((Newsgroups .
,posted-to
)))
3472 `((Newsgroups .
,newsgroups
))))
3473 ,@(and distribution
(list (cons 'Distribution distribution
)))
3474 ,@(if (or references message-id
)
3475 `((References .
,(concat (or references
"") (and references
" ")
3476 (or message-id
"")))))
3478 (not (equal (downcase mct
) "never")))
3479 (list (cons 'Cc
(if (equal (downcase mct
) "always")
3480 (or reply-to from
"")
3485 (setq message-reply-headers
3486 (vector 0 subject from date message-id references
0 0 ""))))
3490 (defun message-cancel-news ()
3491 "Cancel an article you posted."
3493 (unless (message-news-p)
3494 (error "This is not a news article; canceling is impossible"))
3495 (when (yes-or-no-p "Do you really want to cancel this article? ")
3496 (let (from newsgroups message-id distribution buf sender
)
3498 ;; Get header info. from original article.
3500 (message-narrow-to-head)
3501 (setq from
(message-fetch-field "from")
3502 sender
(message-fetch-field "sender")
3503 newsgroups
(message-fetch-field "newsgroups")
3504 message-id
(message-fetch-field "message-id" t
)
3505 distribution
(message-fetch-field "distribution")))
3506 ;; Make sure that this article was written by the user.
3507 (unless (or (and sender
3510 (downcase (message-make-sender))))
3512 (downcase (cadr (mail-extract-address-components from
)))
3513 (downcase (cadr (mail-extract-address-components
3514 (message-make-from))))))
3515 (error "This article is not yours"))
3516 ;; Make control message.
3517 (setq buf
(set-buffer (get-buffer-create " *message cancel*")))
3518 (buffer-disable-undo (current-buffer))
3520 (insert "Newsgroups: " newsgroups
"\n"
3521 "From: " (message-make-from) "\n"
3522 "Subject: cmsg cancel " message-id
"\n"
3523 "Control: cancel " message-id
"\n"
3525 (concat "Distribution: " distribution
"\n")
3527 mail-header-separator
"\n"
3528 message-cancel-message
)
3529 (message "Canceling your article...")
3530 (if (let ((message-syntax-checks
3531 'dont-check-for-anything-just-trust-me
))
3532 (funcall message-send-news-function
))
3533 (message "Canceling your article...done"))
3534 (kill-buffer buf
)))))
3537 (defun message-supersede ()
3538 "Start composing a message to supersede the current message.
3539 This is done simply by taking the old article and adding a Supersedes
3540 header line with the old Message-ID."
3542 (let ((cur (current-buffer))
3543 (sender (message-fetch-field "sender"))
3544 (from (message-fetch-field "from")))
3545 ;; Check whether the user owns the article that is to be superseded.
3546 (unless (or (and sender
3549 (downcase (message-make-sender))))
3551 (downcase (cadr (mail-extract-address-components from
)))
3552 (downcase (cadr (mail-extract-address-components
3553 (message-make-from))))))
3554 (error "This article is not yours"))
3555 ;; Get a normal message buffer.
3556 (message-pop-to-buffer (message-buffer-name "supersede"))
3557 (insert-buffer-substring cur
)
3558 (message-narrow-to-head)
3559 ;; Remove unwanted headers.
3560 (when message-ignored-supersedes-headers
3561 (message-remove-header message-ignored-supersedes-headers t
))
3562 (goto-char (point-min))
3563 (if (not (re-search-forward "^Message-ID: " nil t
))
3564 (error "No Message-ID in this article")
3565 (replace-match "Supersedes: " t t
))
3566 (goto-char (point-max))
3567 (insert mail-header-separator
)
3572 (defun message-recover ()
3573 "Reread contents of current buffer from its last auto-save file."
3575 (let ((file-name (make-auto-save-file-name)))
3576 (cond ((save-window-excursion
3577 (if (not (eq system-type
'vax-vms
))
3578 (with-output-to-temp-buffer "*Directory*"
3579 (buffer-disable-undo standard-output
)
3580 (let ((default-directory "/"))
3582 "ls" nil standard-output nil
"-l" file-name
))))
3583 (yes-or-no-p (format "Recover auto save file %s? " file-name
)))
3584 (let ((buffer-read-only nil
))
3586 (insert-file-contents file-name nil
)))
3587 (t (error "message-recover cancelled")))))
3589 ;;; Washing Subject:
3591 (defun message-wash-subject (subject)
3592 "Remove junk like \"Re:\", \"(fwd)\", etc. that was added to the subject by previous forwarders, replyers, etc."
3593 (nnheader-temp-write nil
3594 (insert-string subject
)
3595 (goto-char (point-min))
3596 ;; strip Re/Fwd stuff off the beginning
3597 (while (re-search-forward
3598 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t
)
3601 ;; and gnus-style forwards [foo@bar.com] subject
3602 (goto-char (point-min))
3603 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t
)
3607 (goto-char (point-max))
3608 (while (re-search-backward "([Ff][Ww][Dd])" nil t
)
3611 ;; and finally, any whitespace that was left-over
3612 (goto-char (point-min))
3613 (while (re-search-forward "^[ \t]+" nil t
)
3615 (goto-char (point-max))
3616 (while (re-search-backward "[ \t]+$" nil t
)
3621 ;;; Forwarding messages.
3623 (defun message-forward-subject-author-subject (subject)
3624 "Generate a subject for a forwarded message.
3625 The form is: [Source] Subject, where if the original message was mail,
3626 Source is the sender, and if the original message was news, Source is
3627 the list of newsgroups is was posted to."
3629 (or (message-fetch-field
3630 (if (message-news-p) "newsgroups" "from"))
3634 (defun message-forward-subject-fwd (subject)
3635 "Generate a subject for a forwarded message.
3636 The form is: Fwd: Subject, where Subject is the original subject of
3638 (concat "Fwd: " subject
))
3640 (defun message-make-forward-subject ()
3641 "Return a Subject header suitable for the message in the current buffer."
3645 (message-narrow-to-head)
3646 (let ((funcs message-make-forward-subject-function
)
3647 (subject (if message-wash-forwarded-subjects
3648 (message-wash-subject
3649 (or (message-fetch-field "Subject") ""))
3650 (or (message-fetch-field "Subject") ""))))
3651 ;; Make sure funcs is a list.
3654 (setq funcs
(list funcs
)))
3655 ;; Apply funcs in order, passing subject generated by previous
3656 ;; func to the next one.
3658 (when (message-functionp (car funcs
))
3659 (setq subject
(funcall (car funcs
) subject
)))
3660 (setq funcs
(cdr funcs
)))
3664 (defun message-forward (&optional news
)
3665 "Forward the current message via mail.
3666 Optional NEWS will use news to forward instead of mail."
3668 (let ((cur (current-buffer))
3669 (subject (message-make-forward-subject))
3671 (if news
(message-news nil subject
) (message-mail nil subject
))
3672 ;; Put point where we want it before inserting the forwarded
3674 (if message-signature-before-forwarded-message
3675 (goto-char (point-max))
3676 (message-goto-body))
3677 ;; Make sure we're at the start of the line.
3680 ;; Narrow to the area we are to insert.
3681 (narrow-to-region (point) (point))
3682 ;; Insert the separators and the forwarded buffer.
3683 (insert message-forward-start-separator
)
3684 (setq art-beg
(point))
3685 (insert-buffer-substring cur
)
3686 (goto-char (point-max))
3687 (insert message-forward-end-separator
)
3688 (set-text-properties (point-min) (point-max) nil
)
3689 ;; Remove all unwanted headers.
3691 (narrow-to-region (point) (if (search-forward "\n\n" nil t
)
3694 (goto-char (point-min))
3695 (message-remove-header message-included-forward-headers t nil t
)
3697 (message-position-point)))
3700 (defun message-resend (address)
3701 "Resend the current article to ADDRESS."
3702 (interactive "sResend message to: ")
3703 (message "Resending message to %s..." address
)
3705 (let ((cur (current-buffer))
3707 ;; We first set up a normal mail buffer.
3708 (set-buffer (get-buffer-create " *message resend*"))
3709 (buffer-disable-undo (current-buffer))
3711 (message-setup `((To .
,address
)))
3712 ;; Insert our usual headers.
3713 (message-generate-headers '(From Date To
))
3714 (message-narrow-to-headers)
3715 ;; Rename them all to "Resent-*".
3716 (while (re-search-forward "^[A-Za-z]" nil t
)
3721 (delete-region (point) (point-max))
3723 ;; Insert the message to be resent.
3724 (insert-buffer-substring cur
)
3725 (goto-char (point-min))
3726 (search-forward "\n\n")
3729 (narrow-to-region beg
(point))
3730 (message-remove-header message-ignored-resent-headers t
)
3731 (goto-char (point-max)))
3732 (insert mail-header-separator
)
3733 ;; Rename all old ("Also-")Resent headers.
3734 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t
)
3737 ;; Quote any "From " lines at the beginning.
3739 (when (looking-at "From ")
3740 (replace-match "X-From-Line: "))
3743 (kill-buffer (current-buffer)))
3744 (message "Resending message to %s...done" address
)))
3747 (defun message-bounce ()
3748 "Re-mail the current message.
3749 This only makes sense if the current message is a bounce message than
3750 contains some mail you have written which has been bounced back to
3753 (let ((cur (current-buffer))
3755 (message-pop-to-buffer (message-buffer-name "bounce"))
3756 (insert-buffer-substring cur
)
3758 (message-narrow-to-head)
3759 (if (and (message-fetch-field "Mime-Version")
3760 (setq boundary
(message-fetch-field "Content-Type")))
3761 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary
)
3762 (setq boundary
(concat (match-string 1 boundary
) " *\n"
3763 "Content-Type: message/rfc822"))
3764 (setq boundary nil
)))
3766 (goto-char (point-min))
3767 (search-forward "\n\n" nil t
)
3769 (re-search-forward boundary nil t
)
3771 (and (re-search-forward message-unsent-separator nil t
)
3773 (re-search-forward "^Return-Path:.*\n" nil t
))
3774 ;; We remove everything before the bounced mail.
3777 (if (re-search-forward "^[^ \n\t]+:" nil t
)
3781 (message-narrow-to-head)
3782 (message-remove-header message-ignored-bounced-headers t
)
3783 (goto-char (point-max))
3784 (insert mail-header-separator
))
3785 (message-position-point)))
3788 ;;; Interactive entry points for new message buffers.
3792 (defun message-mail-other-window (&optional to subject
)
3793 "Like `message-mail' command, but display mail buffer in another window."
3795 (let ((pop-up-windows t
)
3796 (special-display-buffer-names nil
)
3797 (special-display-regexps nil
)
3798 (same-window-buffer-names nil
)
3799 (same-window-regexps nil
))
3800 (message-pop-to-buffer (message-buffer-name "mail" to
)))
3801 (let ((message-this-is-mail t
))
3802 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
""))))))
3805 (defun message-mail-other-frame (&optional to subject
)
3806 "Like `message-mail' command, but display mail buffer in another frame."
3808 (let ((pop-up-frames t
)
3809 (special-display-buffer-names nil
)
3810 (special-display-regexps nil
)
3811 (same-window-buffer-names nil
)
3812 (same-window-regexps nil
))
3813 (message-pop-to-buffer (message-buffer-name "mail" to
)))
3814 (let ((message-this-is-mail t
))
3815 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
""))))))
3818 (defun message-news-other-window (&optional newsgroups subject
)
3819 "Start editing a news article to be sent."
3821 (let ((pop-up-windows 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 "news" nil newsgroups
)))
3827 (let ((message-this-is-news t
))
3828 (message-setup `((Newsgroups .
,(or newsgroups
""))
3829 (Subject .
,(or subject
""))))))
3832 (defun message-news-other-frame (&optional newsgroups subject
)
3833 "Start editing a news article to be sent."
3835 (let ((pop-up-frames t
)
3836 (special-display-buffer-names nil
)
3837 (special-display-regexps nil
)
3838 (same-window-buffer-names nil
)
3839 (same-window-regexps nil
))
3840 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups
)))
3841 (let ((message-this-is-news t
))
3842 (message-setup `((Newsgroups .
,(or newsgroups
""))
3843 (Subject .
,(or subject
""))))))
3847 ;; This code should be moved to underline.el (from which it is stolen).
3850 (defun bold-region (start end
)
3851 "Bold all nonblank characters in the region.
3852 Works by overstriking characters.
3853 Called from program, takes two arguments START and END
3854 which specify the range to operate on."
3857 (let ((end1 (make-marker)))
3858 (move-marker end1
(max start end
))
3859 (goto-char (min start end
))
3860 (while (< (point) end1
)
3861 (or (looking-at "[_\^@- ]")
3862 (insert (following-char) "\b"))
3863 (forward-char 1)))))
3866 (defun unbold-region (start end
)
3867 "Remove all boldness (overstruck characters) in the region.
3868 Called from program, takes two arguments START and END
3869 which specify the range to operate on."
3872 (let ((end1 (make-marker)))
3873 (move-marker end1
(max start end
))
3874 (goto-char (min start end
))
3875 (while (re-search-forward "\b" end1 t
)
3876 (if (eq (following-char) (char-after (- (point) 2)))
3877 (delete-char -
2))))))
3879 (defalias 'message-exchange-point-and-mark
'exchange-point-and-mark
)
3881 ;; Support for toolbar
3882 (when (string-match "XEmacs\\|Lucid" emacs-version
)
3883 (require 'messagexmas
))
3885 ;;; Group name completion.
3887 (defvar message-newgroups-header-regexp
3888 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
3889 "Regexp that match headers that lists groups.")
3891 (defun message-tab ()
3892 "Expand group names in Newsgroups and Followup-To headers.
3893 Do a `tab-to-tab-stop' if not in those headers."
3895 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp
))
3896 (mail-abbrev-in-expansion-header-p))
3897 (message-expand-group)
3900 (defvar gnus-active-hashtb
)
3901 (defun message-expand-group ()
3902 "Expand the group name under point."
3903 (let* ((b (save-excursion
3908 (skip-chars-forward "^:")
3911 (skip-chars-backward "^, \t\n") (point))))
3912 (completion-ignore-case t
)
3913 (string (buffer-substring b
(progn (skip-chars-forward "^,\t\n ")
3915 (hashtb (and (boundp 'gnus-active-hashtb
) gnus-active-hashtb
))
3916 (completions (all-completions string hashtb
))
3918 (delete-region b
(point))
3920 ((= (length completions
) 1)
3921 (if (string= (car completions
) string
)
3924 (message "Only matching group"))
3925 (insert (car completions
))))
3926 ((and (setq comp
(try-completion string hashtb
))
3927 (not (string= comp string
)))
3932 (message "No matching groups")
3933 (save-selected-window
3934 (pop-to-buffer "*Completions*")
3935 (buffer-disable-undo (current-buffer))
3936 (let ((buffer-read-only nil
))
3938 (let ((standard-output (current-buffer)))
3939 (display-completion-list (sort completions
'string
<)))
3940 (goto-char (point-min))
3941 (delete-region (point) (progn (forward-line 3) (point))))))))))
3945 (defun message-talkative-question (ask question show
&rest text
)
3946 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
3947 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
3948 The following arguments may contain lists of values."
3950 (setq text
(message-flatten-list text
)))
3951 (save-window-excursion
3953 (with-output-to-temp-buffer " *MESSAGE information message*"
3954 (set-buffer " *MESSAGE information message*")
3955 (mapcar 'princ text
)
3956 (goto-char (point-min))))
3957 (funcall ask question
))
3958 (funcall ask question
)))
3960 (defun message-flatten-list (list)
3961 "Return a new, flat list that contains all elements of LIST.
3963 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
3966 (apply 'append
(mapcar 'message-flatten-list list
)))
3970 (defun message-generate-new-buffer-clone-locals (name &optional varstr
)
3971 "Create and return a buffer with a name based on NAME using generate-new-buffer.
3972 Then clone the local variables and values from the old buffer to the
3973 new one, cloning only the locals having a substring matching the
3975 (let ((oldbuf (current-buffer)))
3977 (set-buffer (generate-new-buffer name
))
3978 (message-clone-locals oldbuf
)
3981 (defun message-clone-locals (buffer)
3982 "Clone the local variables from BUFFER to the current buffer."
3983 (let ((locals (save-excursion
3985 (buffer-local-variables)))
3986 (regexp "^gnus\\|^nn\\|^message"))
3989 (when (and (consp local
)
3991 (string-match regexp
(symbol-name (car local
))))
3993 (set (make-local-variable (car local
))
3997 ;;; Miscellaneous functions
3999 ;; stolen (and renamed) from nnheader.el
4000 (defun message-replace-chars-in-string (string from to
)
4001 "Replace characters in STRING from FROM to TO."
4002 (let ((string (substring string
0)) ;Copy string.
4003 (len (length string
))
4005 ;; Replace all occurrences of FROM with TO.
4007 (when (= (aref string idx
) from
)
4008 (aset string idx to
))
4009 (setq idx
(1+ idx
)))
4012 (run-hooks 'message-load-hook
)
4016 ;;; message.el ends here