1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
5 ;; Keywords: mail, news
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
26 ;; This mode provides mail-sending facilities from within Emacs. It
27 ;; consists mainly of large chunks of code from the sendmail.el,
28 ;; gnus-msg.el and rnewspost.el files.
39 (if (string-match "XEmacs\\|Lucid" emacs-version)
40 (require 'mail-abbrevs)
41 (require 'mailabbrev))
43 (defvar message-directory "~/Mail/"
44 "*Directory from which all other mail file variables are derived.")
46 (defvar message-max-buffers 10
47 "*How many buffers to keep before starting to kill them off.")
49 (defvar message-send-rename-function nil
50 "Function called to rename the buffer after sending it.")
53 (defvar message-fcc-handler-function 'rmail-output
54 "*A function called to save outgoing articles.
55 This function will be called with the name of the file to store the
56 article in. The default function is `rmail-output' which saves in Unix
59 (defvar message-courtesy-message
60 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
61 "*This is inserted at the start of a mailed copy of a posted message.
62 If the string contains the format spec \"%s\", the Newsgroups
63 the article has been posted to will be inserted there.
64 If this variable is nil, no such courtesy message will be added.")
66 (defvar message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):"
67 "*Regexp that matches headers to be removed in resent bounced mail.")
70 (defvar message-from-style 'default
71 "*Specifies how \"From\" headers look.
73 If `nil', they contain just the return address like:
75 If `parens', they look like:
76 king@grassland.com (Elvis Parsley)
77 If `angles', they look like:
78 Elvis Parsley <king@grassland.com>
80 Otherwise, most addresses look like `angles', but they look like
81 `parens' if `angles' would need quoting and `parens' would not.")
83 (defvar message-syntax-checks nil
84 "Controls what syntax checks should not be performed on outgoing posts.
85 To disable checking of long signatures, for instance, add
86 `(signature . disabled)' to this list.
88 Don't touch this variable unless you really know what you're doing.
90 Checks include subject-cmsg multiple-headers sendsys message-id from
91 long-lines control-chars size new-text redirected-followup signature
92 approved sender empty empty-headers message-id from subject
93 shorten-followup-to existing-newsgroups.")
95 (defvar message-required-news-headers
96 '(From Newsgroups Subject Date Message-ID
97 (optional . Organization) Lines
98 (optional . X-Newsreader))
99 "*Headers to be generated or prompted for when posting an article.
100 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
101 Message-ID. Organization, Lines, In-Reply-To, Expires, and
102 X-Newsreader are optional. If don't you want message to insert some
103 header, remove it from this list.")
105 (defvar message-required-mail-headers
106 '(From Subject Date (optional . In-Reply-To) Message-ID Lines
107 (optional . X-Mailer))
108 "*Headers to be generated or prompted for when mailing a message.
109 RFC822 required that From, Date, To, Subject and Message-ID be
110 included. Organization, Lines and X-Mailer are optional.")
112 (defvar message-deletable-headers '(Message-ID Date Lines)
113 "*Headers to be deleted if they already exist and were generated by message previously.")
115 (defvar message-ignored-news-headers
116 "^NNTP-Posting-Host:\\|^Xref:\\|^Bcc:\\|^Gcc:\\|^Fcc:\\|^Resent-Fcc:"
117 "*Regexp of headers to be removed unconditionally before posting.")
119 (defvar message-ignored-mail-headers "^Gcc:\\|^Fcc:\\|^Resent-Fcc:"
120 "*Regexp of headers to be removed unconditionally before mailing.")
122 (defvar message-ignored-supersedes-headers "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|Return-Path:\\|^Supersedes:"
123 "*Header lines matching this regexp will be deleted before posting.
124 It's best to delete old Path and Date headers before posting to avoid
128 (defvar message-signature-separator "^-- *$"
129 "Regexp matching the signature separator.")
131 (defvar message-interactive nil
132 "Non-nil means when sending a message wait for and display errors.
133 nil means let mailer mail back a message to report errors.")
135 (defvar message-generate-new-buffers t
136 "*Non-nil means that a new message buffer will be created whenever `mail-setup' is called.
137 If this is a function, call that function with three parameters: The type,
138 the to address and the group name. (Any of these may be nil.) The function
139 should return the new buffer name.")
141 (defvar message-kill-buffer-on-exit nil
142 "*Non-nil means that the message buffer will be killed after sending a message.")
144 (defvar gnus-local-organization)
145 (defvar message-user-organization
146 (or (and (boundp 'gnus-local-organization)
147 gnus-local-organization)
148 (getenv "ORGANIZATION")
150 "*String to be used as an Organization header.
151 If t, use `message-user-organization-file'.")
154 (defvar message-user-organization-file "/usr/lib/news/organization"
155 "*Local news organization file.")
157 (defvar message-autosave-directory "~/"
158 ; (concat (file-name-as-directory message-directory) "drafts/")
159 "*Directory where message autosaves buffers.
160 If nil, message won't autosave.")
162 (defvar message-forward-start-separator
163 "------- Start of forwarded message -------\n"
164 "*Delimiter inserted before forwarded messages.")
166 (defvar message-forward-end-separator
167 "------- End of forwarded message -------\n"
168 "*Delimiter inserted after forwarded messages.")
170 (defvar message-signature-before-forwarded-message t
171 "*If non-nil, put the signature before any included forwarded message.")
173 (defvar message-included-forward-headers
174 "^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:"
175 "*Regexp matching headers to be included in forwarded messages.")
177 (defvar message-ignored-resent-headers "^Return-receipt"
178 "*All headers that match this regexp will be deleted when resending a message.")
180 (defvar message-ignored-cited-headers "."
181 "*Delete these headers from the messages you yank.")
183 (defvar message-cancel-message "I am canceling my own article."
184 "Message to be inserted in the cancel message.")
186 ;; Useful to set in site-init.el
188 (defvar message-send-mail-function 'message-send-mail-with-sendmail
189 "Function to call to send the current buffer as mail.
190 The headers should be delimited by a line whose contents match the
191 variable `mail-header-separator'.
193 Legal values include `message-send-mail-with-sendmail' (the default),
194 `message-send-mail-with-mh' and `message-send-mail-with-qmail'.")
196 (defvar message-send-news-function 'message-send-news
197 "Function to call to send the current buffer as news.
198 The headers should be delimited by a line whose contents match the
199 variable `mail-header-separator'.")
201 (defvar message-reply-to-function nil
202 "Function that should return a list of headers.
203 This function should pick out addresses from the To, Cc, and From headers
204 and respond with new To and Cc headers.")
206 (defvar message-wide-reply-to-function nil
207 "Function that should return a list of headers.
208 This function should pick out addresses from the To, Cc, and From headers
209 and respond with new To and Cc headers.")
211 (defvar message-followup-to-function nil
212 "Function that should return a list of headers.
213 This function should pick out addresses from the To, Cc, and From headers
214 and respond with new To and Cc headers.")
216 (defvar message-use-followup-to 'ask
217 "*Specifies what to do with Followup-To header.
218 If nil, ignore the header. If it is t, use its value, but query before
219 using the \"poster\" value. If it is the symbol `ask', query the user
220 whether to ignore the \"poster\" value. If it is the symbol `use',
221 always use the value.")
223 ;; qmail-related stuff
224 (defvar message-qmail-inject-program "/var/qmail/bin/qmail-inject"
225 "Location of the qmail-inject program.")
227 (defvar message-qmail-inject-args nil
228 "Arguments passed to qmail-inject programs.
229 This should be a list of strings, one string for each argument.
231 For e.g., if you wish to set the envelope sender address so that bounces
232 go to the right place or to deal with listserv's usage of that address, you
233 might set this variable to '(\"-f\" \"you@some.where\").")
235 (defvar gnus-post-method)
236 (defvar gnus-select-method)
237 (defvar message-post-method
238 (cond ((and (boundp 'gnus-post-method)
241 ((boundp 'gnus-select-method)
244 "Method used to post news.")
246 (defvar message-generate-headers-first nil
247 "*If non-nil, generate all possible headers before composing.")
249 (defvar message-setup-hook nil
250 "Normal hook, run each time a new outgoing message is initialized.
251 The function `message-setup' runs this hook.")
253 (defvar message-signature-setup-hook nil
254 "Normal hook, run each time a new outgoing message is initialized.
255 It is run after the headers have been inserted and before
256 the signature is inserted.")
258 (defvar message-mode-hook nil
259 "Hook run in message mode buffers.")
261 (defvar message-header-hook nil
262 "Hook run in a message mode buffer narrowed to the headers.")
264 (defvar message-header-setup-hook nil
265 "Hook called narrowed to the headers when setting up a message buffer.")
268 (defvar message-citation-line-function 'message-insert-citation-line
269 "*Function called to insert the \"Whomever writes:\" line.")
272 (defvar message-yank-prefix "> "
273 "*Prefix inserted on the lines of yanked messages.
274 nil means use indentation.")
276 (defvar message-indentation-spaces 3
277 "*Number of spaces to insert at the beginning of each cited line.
278 Used by `message-yank-original' via `message-yank-cite'.")
281 (defvar message-cite-function
282 (if (and (boundp 'mail-citation-hook)
285 'message-cite-original)
286 "*Function for citing an original message.")
289 (defvar message-indent-citation-function 'message-indent-citation
290 "*Function for modifying a citation just inserted in the mail buffer.
291 This can also be a list of functions. Each function can find the
292 citation between (point) and (mark t). And each function should leave
293 point and mark around the citation text as modified.")
295 (defvar message-abbrevs-loaded nil)
298 (defvar message-signature t
299 "*String to be inserted at the end of the message buffer.
300 If t, the `message-signature-file' file will be inserted instead.
301 If a function, the result from the function will be used instead.
302 If a form, the result from the form will be used instead.")
305 (defvar message-signature-file "~/.signature"
306 "*File containing the text inserted at end of message buffer.")
308 (defvar message-distribution-function nil
309 "*Function called to return a Distribution header.")
311 (defvar message-expires 14
312 "*Number of days before your article expires.")
314 (defvar message-user-path nil
315 "If nil, use the NNTP server name in the Path header.
316 If stringp, use this; if non-nil, use no host name (user name only).")
318 (defvar message-reply-buffer nil)
319 (defvar message-reply-headers nil)
320 (defvar message-newsreader nil)
321 (defvar message-mailer nil)
322 (defvar message-sent-message-via nil)
323 (defvar message-checksum nil)
324 (defvar message-send-actions nil
325 "A list of actions to be performed upon successful sending of a message.")
326 (defvar message-exit-actions nil
327 "A list of actions to be performed upon exiting after sending a message.")
328 (defvar message-kill-actions nil
329 "A list of actions to be performed before killing a message buffer.")
330 (defvar message-postpone-actions nil
331 "A list of actions to be performed after postponing a message.")
333 (defvar message-default-headers nil
334 "*A string containing header lines to be inserted in outgoing messages.
335 It is inserted before you edit the message, so you can edit or delete
338 (defvar message-default-mail-headers nil
339 "*A string of header lines to be inserted in outgoing mails.")
341 (defvar message-default-news-headers nil
342 "*A string of header lines to be inserted in outgoing news articles.")
344 ;; Note: could use /usr/ucb/mail instead of sendmail;
345 ;; options -t, and -v if not interactive.
346 (defvar message-mailer-swallows-blank-line
347 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
348 system-configuration)
349 (file-readable-p "/etc/sendmail.cf")
350 (let ((buffer (get-buffer-create " *temp*")))
354 (insert-file-contents "/etc/sendmail.cf")
355 (goto-char (point-min))
356 (let ((case-fold-search nil))
357 (re-search-forward "^OR\\>" nil t)))
358 (kill-buffer buffer))))
359 ;; According to RFC822, "The field-name must be composed of printable
360 ;; ASCII characters (i. e., characters that have decimal values between
361 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
363 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
364 "Set this non-nil if the system's mailer runs the header and body together.
365 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
366 The value should be an expression to test whether the problem will
369 ;;; Internal variables.
370 ;;; Well, not really internal.
372 (defvar message-mode-syntax-table
373 (let ((table (copy-syntax-table text-mode-syntax-table)))
374 (modify-syntax-entry ?% ". " table)
376 "Syntax table used while in Message mode.")
378 (defvar message-mode-abbrev-table text-mode-abbrev-table
379 "Abbrev table used in Message mode buffers.
380 Defaults to `text-mode-abbrev-table'.")
382 (defvar message-font-lock-keywords
383 (let* ((cite-prefix "A-Za-z") (cite-suffix (concat cite-prefix "0-9_.@-")))
384 (list '("^To:" . font-lock-function-name-face)
385 '("^[GBF]?[Cc][Cc]:\\|^Reply-To:" . font-lock-keyword-face)
386 '("^\\(Subject:\\)[ \t]*\\(.+\\)?"
387 (1 font-lock-comment-face) (2 font-lock-type-face nil t))
388 (list (concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
389 1 'font-lock-comment-face)
390 (cons (concat "^[ \t]*"
391 "\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
393 'font-lock-reference-face)
394 '("^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):.*"
395 . font-lock-string-face)))
396 "Additional expressions to highlight in Message mode.")
398 (defvar message-face-alist
399 '((bold . bold-region)
400 (underline . underline-region)
401 (default . (lambda (b e)
403 (ununderline-region b e))))
404 "Alist of mail and news faces for facemenu.
405 The cdr of ech entry is a function for applying the face to a region.")
407 (defvar message-send-hook nil
408 "Hook run before sending messages.")
410 (defvar message-send-mail-hook nil
411 "Hook run before sending mail messages.")
413 (defvar message-send-news-hook nil
414 "Hook run before sending news messages.")
416 (defvar message-sent-hook nil
417 "Hook run after sending messages.")
419 ;;; Internal variables.
421 (defvar message-buffer-list nil)
423 ;; Byte-compiler warning
424 (defvar gnus-active-hashtb)
426 ;;; Regexp matching the delimiter of messages in UNIX mail format
427 ;;; (UNIX From lines), minus the initial ^.
428 (defvar message-unix-mail-delimiter
429 (let ((time-zone-regexp
430 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
431 "\\|[-+]?[0-9][0-9][0-9][0-9]"
437 ;; Username, perhaps with a quoted section that can contain spaces.
440 "\\(\\|\".*\"[^ \n]*\\)"
444 ;; The time the message was sent.
445 "\\([^ \n]*\\) *" ; day of the week
446 "\\([^ ]*\\) *" ; month
447 "\\([0-9]*\\) *" ; day of month
448 "\\([0-9:]*\\) *" ; time of day
450 ;; Perhaps a time zone, specified by an abbreviation, or by a
455 " [0-9][0-9]\\([0-9]*\\) *"
457 ;; On some systems the time zone can appear after the year, too.
461 "\\(remote from .*\\)?"
465 (defvar message-unsent-separator
466 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
467 "^ *---+ +Returned message +---+ *$\\|"
468 "^Start of returned message$\\|"
469 "^ *---+ +Original message +---+ *$\\|"
470 "^ *--+ +begin message +--+ *$\\|"
471 "^ *---+ +Original message follows +---+ *$\\|"
472 "^|? *---+ +Message text follows: +---+ *|?$")
473 "A regexp that matches the separator before the text of a failed message.")
475 (defvar message-header-format-alist
477 (To . message-fill-address)
478 (Cc . message-fill-address)
492 "Alist used for formatting headers.")
495 (autoload 'message-setup-toolbar "messagexmas")
496 (autoload 'mh-send-letter "mh-comp"))
501 ;;; Utility functions.
504 (defun message-point-at-bol ()
505 "Return point at the beginning of the line."
512 (defun message-point-at-eol ()
513 "Return point at the end of the line."
520 (defmacro message-y-or-n-p (question show &rest text)
521 "Ask QUESTION, displaying the rest of the arguments in a temp. buffer if SHOW"
522 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
524 ;; Delete the current line (and the next N lines.);
525 (defmacro message-delete-line (&optional n)
526 `(delete-region (progn (beginning-of-line) (point))
527 (progn (forward-line ,(or n 1)) (point))))
529 (defun message-tokenize-header (header &optional separator)
530 "Split HEADER into a list of header elements.
531 \",\" is used as the separator."
534 (let ((regexp (format "[%s]+" (or separator ",")))
539 (message-set-work-buffer)
541 (goto-char (point-min))
546 (cond ((and (> (point) beg)
548 (and (looking-at regexp)
551 (push (buffer-substring beg (point)) elems)
552 (setq beg (match-end 0)))
553 ((= (following-char) ?\")
554 (setq quoted (not quoted)))
555 ((and (= (following-char) ?\()
558 ((and (= (following-char) ?\))
563 (defun message-fetch-field (header)
564 "The same as `mail-fetch-field', only remove all newlines."
565 (let ((value (mail-fetch-field header)))
567 (nnheader-replace-chars-in-string value ?\n ? ))))
569 (defun message-fetch-reply-field (header)
570 "Fetch FIELD from the message we're replying to."
571 (when (and message-reply-buffer
572 (buffer-name message-reply-buffer))
574 (set-buffer message-reply-buffer)
575 (message-fetch-field header))))
577 (defun message-set-work-buffer ()
578 (if (get-buffer " *message work*")
580 (set-buffer " *message work*")
582 (set-buffer (get-buffer-create " *message work*"))
583 (kill-all-local-variables)
584 (buffer-disable-undo (current-buffer))))
586 (defun message-functionp (form)
587 "Return non-nil if FORM is funcallable."
588 (or (and (symbolp form) (fboundp form))
589 (and (listp form) (eq (car form) 'lambda))))
591 (defun message-strip-subject-re (subject)
592 "Remove \"Re:\" from subject lines."
593 (if (string-match "^[Rr][Ee]: *" subject)
594 (substring subject (match-end 0))
597 (defun message-remove-header (header &optional is-regexp first reverse)
598 "Remove HEADER in the narrowed buffer.
599 If REGEXP, HEADER is a regular expression.
600 If FIRST, only remove the first instance of the header.
601 Return the number of headers removed."
602 (goto-char (point-min))
603 (let ((regexp (if is-regexp header (concat "^" header ":")))
607 (while (and (not (eobp))
610 (not (looking-at regexp))
618 ;; There might be a continuation header, so we have to search
619 ;; until we find a new non-continuation line.
622 (if (re-search-forward "^[^ \t]" nil t)
623 (goto-char (match-beginning 0))
626 (if (re-search-forward "^[^ \t]" nil t)
627 (goto-char (match-beginning 0))
631 (defun message-narrow-to-headers ()
632 "Narrow the buffer to the head of the message."
635 (goto-char (point-min))
636 (if (re-search-forward
637 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
640 (goto-char (point-min)))
642 (defun message-narrow-to-head ()
643 "Narrow the buffer to the head of the message."
646 (goto-char (point-min))
647 (if (search-forward "\n\n" nil 1)
650 (goto-char (point-min)))
652 (defun message-news-p ()
653 "Say whether the current buffer contains a news message."
656 (message-narrow-to-headers)
657 (message-fetch-field "newsgroups"))))
659 (defun message-mail-p ()
660 "Say whether the current buffer contains a mail message."
663 (message-narrow-to-headers)
664 (or (message-fetch-field "to")
665 (message-fetch-field "cc")
666 (message-fetch-field "bcc")))))
668 (defun message-next-header ()
669 "Go to the beginning of the next header."
671 (or (eobp) (forward-char 1))
672 (not (if (re-search-forward "^[^ \t]" nil t)
674 (goto-char (point-max)))))
676 (defun message-sort-headers-1 ()
677 "Sort the buffer as headers using `message-rank' text props."
678 (goto-char (point-min))
680 nil 'message-next-header
682 (message-next-header)
686 (or (get-text-property (point) 'message-rank)
689 (defun message-sort-headers ()
690 "Sort the headers of the current message according to `message-header-format-alist'."
694 (let ((max (1+ (length message-header-format-alist)))
696 (message-narrow-to-headers)
697 (while (re-search-forward "^[^ \n]+:" nil t)
699 (match-beginning 0) (1+ (match-beginning 0))
701 (if (setq rank (length (memq (assq (intern (buffer-substring
704 message-header-format-alist)
705 message-header-format-alist)))
708 (message-sort-headers-1))))
718 (defvar message-mode-map nil)
720 (unless message-mode-map
721 (setq message-mode-map (copy-keymap text-mode-map))
722 (define-key message-mode-map "\C-c?" 'describe-mode)
724 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
725 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
726 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
727 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
728 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
729 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
730 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
731 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
732 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
733 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
734 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
735 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
736 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
738 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
739 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
741 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
742 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
743 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
744 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
745 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
746 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
748 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
749 (define-key message-mode-map "\C-c\C-s" 'message-send)
750 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
751 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
753 (define-key message-mode-map "\t" 'message-tab))
755 (easy-menu-define message-mode-menu message-mode-map
760 ["To" message-goto-to t]
761 ["Subject" message-goto-subject t]
762 ["Cc" message-goto-cc t]
763 ["Reply-To" message-goto-reply-to t]
764 ["Summary" message-goto-summary t]
765 ["Keywords" message-goto-keywords t]
766 ["Newsgroups" message-goto-newsgroups t]
767 ["Followup-To" message-goto-followup-to t]
768 ["Distribution" message-goto-distribution t]
769 ["Body" message-goto-body t]
770 ["Signature" message-goto-signature t]
772 "Miscellaneous Commands:"
774 ["Sort Headers" message-sort-headers t]
775 ["Yank Original" message-yank-original t]
776 ["Fill Yanked Message" message-fill-yanked-message t]
777 ["Insert Signature" message-insert-signature t]
778 ["Caesar (rot13) Message" message-caesar-buffer-body t]
779 ["Rename buffer" message-rename-buffer t]
780 ["Spellcheck" ispell-message t]
782 ["Send Message" message-send-and-exit t]
783 ["Abort Message" message-dont-send t]))
785 (defvar facemenu-add-face-function)
786 (defvar facemenu-remove-face-function)
789 (defun message-mode ()
790 "Major mode for editing mail and news to be sent.
791 Like Text Mode but with these additional commands:
792 C-c C-s message-send (send the message) C-c C-c message-send-and-exit
793 C-c C-f move to a header field (and create it if there isn't):
794 C-c C-f C-t move to To C-c C-f C-s move to Subject
795 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
796 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
797 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
798 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
799 C-c C-f C-f move to Followup-To
800 C-c C-t message-insert-to (add a To header to a news followup)
801 C-c C-n message-insert-newsgroups (add a Newsgroup header to a news reply)
802 C-c C-b message-goto-body (move to beginning of message text).
803 C-c C-i message-goto-signature (move to the beginning of the signature).
804 C-c C-w message-insert-signature (insert `message-signature-file' file).
805 C-c C-y message-yank-original (insert current message, if any).
806 C-c C-q message-fill-yanked-message (fill what was yanked).
807 C-c C-r message-caesar-buffer-body (rot13 the message body)."
809 (kill-all-local-variables)
810 (make-local-variable 'message-reply-buffer)
811 (setq message-reply-buffer nil)
812 (make-local-variable 'message-send-actions)
813 (make-local-variable 'message-exit-actions)
814 (make-local-variable 'message-kill-actions)
815 (make-local-variable 'message-postpone-actions)
816 (set-syntax-table message-mode-syntax-table)
817 (use-local-map message-mode-map)
818 (setq local-abbrev-table message-mode-abbrev-table)
819 (setq major-mode 'message-mode)
820 (setq mode-name "Message")
821 (setq buffer-offer-save t)
822 (make-local-variable 'font-lock-defaults)
823 (setq font-lock-defaults '(message-font-lock-keywords t))
824 (make-local-variable 'facemenu-add-face-function)
825 (make-local-variable 'facemenu-remove-face-function)
826 (setq facemenu-add-face-function
828 (let ((face-fun (cdr (assq face message-face-alist))))
830 (funcall face-fun (point) end)
831 (error "Face %s not configured for %s mode" face mode-name)))
833 facemenu-remove-face-function t)
834 (make-local-variable 'paragraph-separate)
835 (make-local-variable 'paragraph-start)
836 (setq paragraph-start (concat (regexp-quote mail-header-separator)
837 "$\\|[ \t]*[-_][-_][-_]+$\\|"
840 (setq paragraph-separate (concat (regexp-quote mail-header-separator)
841 "$\\|[ \t]*[-_][-_][-_]+$\\|"
844 (make-local-variable 'message-reply-headers)
845 (setq message-reply-headers nil)
846 (make-local-variable 'message-newsreader)
847 (make-local-variable 'message-mailer)
848 (make-local-variable 'message-post-method)
849 (make-local-variable 'message-sent-message-via)
850 (setq message-sent-message-via nil)
851 (make-local-variable 'message-checksum)
852 (setq message-checksum nil)
853 ;;(when (fboundp 'mail-hist-define-keys)
854 ;; (mail-hist-define-keys))
855 (when (string-match "XEmacs\\|Lucid" emacs-version)
856 (message-setup-toolbar))
857 (easy-menu-add message-mode-menu message-mode-map)
858 ;; Allow mail alias things.
859 (if (fboundp 'mail-abbrevs-setup)
861 (funcall (intern "mail-aliases-setup")))
862 (run-hooks 'text-mode-hook 'message-mode-hook))
867 ;;; Message mode commands
870 ;;; Movement commands
872 (defun message-goto-to ()
873 "Move point to the To header."
875 (message-position-on-field "To"))
877 (defun message-goto-subject ()
878 "Move point to the Subject header."
880 (message-position-on-field "Subject"))
882 (defun message-goto-cc ()
883 "Move point to the Cc header."
885 (message-position-on-field "Cc" "To"))
887 (defun message-goto-bcc ()
888 "Move point to the Bcc header."
890 (message-position-on-field "Bcc" "Cc" "To"))
892 (defun message-goto-fcc ()
893 "Move point to the Fcc header."
895 (message-position-on-field "Fcc" "To" "Newsgroups"))
897 (defun message-goto-reply-to ()
898 "Move point to the Reply-To header."
900 (message-position-on-field "Reply-To" "Subject"))
902 (defun message-goto-newsgroups ()
903 "Move point to the Newsgroups header."
905 (message-position-on-field "Newsgroups"))
907 (defun message-goto-distribution ()
908 "Move point to the Distribution header."
910 (message-position-on-field "Distribution"))
912 (defun message-goto-followup-to ()
913 "Move point to the Followup-To header."
915 (message-position-on-field "Followup-To" "Newsgroups"))
917 (defun message-goto-keywords ()
918 "Move point to the Keywords header."
920 (message-position-on-field "Keywords" "Subject"))
922 (defun message-goto-summary ()
923 "Move point to the Summary header."
925 (message-position-on-field "Summary" "Subject"))
927 (defun message-goto-body ()
928 "Move point to the beginning of the message body."
930 (if (looking-at "[ \t]*\n") (expand-abbrev))
931 (goto-char (point-min))
932 (search-forward (concat "\n" mail-header-separator "\n") nil t))
934 (defun message-goto-signature ()
935 "Move point to the beginning of the message signature."
937 (goto-char (point-min))
938 (if (re-search-forward message-signature-separator nil t)
940 (goto-char (point-max))))
944 (defun message-insert-to ()
945 "Insert a To header that points to the author of the article being replied to."
947 (when (and (message-position-on-field "To")
948 (mail-fetch-field "to")
949 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
951 (insert (or (message-fetch-reply-field "reply-to")
952 (message-fetch-reply-field "from") "")))
954 (defun message-insert-newsgroups ()
955 "Insert the Newsgroups header from the article being replied to."
957 (when (and (message-position-on-field "Newsgroups")
958 (mail-fetch-field "newsgroups")
959 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
961 (insert (or (message-fetch-reply-field "newsgroups") "")))
967 (defun message-insert-signature (&optional force)
968 "Insert a signature. See documentation for the `message-signature' variable."
969 (interactive (list 0))
972 ((and (null message-signature)
975 (goto-char (point-max))
976 (not (re-search-backward
977 message-signature-separator nil t))))
978 ((and (null message-signature)
981 ((message-functionp message-signature)
982 (funcall message-signature))
983 ((listp message-signature)
984 (eval message-signature))
985 (t message-signature)))
987 (cond ((stringp signature)
989 ((and (eq t signature)
990 message-signature-file
991 (file-exists-p message-signature-file))
994 (goto-char (point-max))
995 ;; Insert the signature.
1000 (insert-file-contents message-signature-file)
1002 (goto-char (point-max))
1003 (or (bolp) (insert "\n")))))
1005 (defvar message-caesar-translation-table nil)
1007 (defun message-caesar-region (b e &optional n)
1008 "Caesar rotation of region by N, default 13, for decrypting netnews."
1011 (min (point) (or (mark t) (point)))
1012 (max (point) (or (mark t) (point)))
1013 (when current-prefix-arg
1014 (prefix-numeric-value current-prefix-arg))))
1016 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
1017 (unless (or (zerop n) ; no action needed for a rot of 0
1018 (= b e)) ; no region to rotate
1019 ;; We build the table, if necessary.
1020 (when (or (not message-caesar-translation-table)
1021 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
1023 (table (make-string 256 0)))
1024 (while (< (incf i) 256)
1028 (substring table 0 ?A)
1029 (substring table (+ ?A n) (+ ?A n (- 26 n)))
1030 (substring table ?A (+ ?A n))
1031 (substring table (+ ?A 26) ?a)
1032 (substring table (+ ?a n) (+ ?a n (- 26 n)))
1033 (substring table ?a (+ ?a n))
1034 (substring table (+ ?a 26) 255)))
1035 (setq message-caesar-translation-table table)))
1036 ;; Then we translate the region. Do it this way to retain
1039 (subst-char-in-region
1040 b (1+ b) (char-after b)
1041 (aref message-caesar-translation-table (char-after b)))
1044 (defun message-caesar-buffer-body (&optional rotnum)
1045 "Caesar rotates all letters in the current buffer by 13 places.
1046 Used to encode/decode possibly offensive messages (commonly in net.jokes).
1047 With prefix arg, specifies the number of places to rotate each letter forward.
1048 Mail and USENET news headers are not rotated."
1049 (interactive (if current-prefix-arg
1050 (list (prefix-numeric-value current-prefix-arg))
1054 (when (message-goto-body)
1055 (narrow-to-region (point) (point-max)))
1056 (message-caesar-region (point-min) (point-max) rotnum))))
1058 (defun message-rename-buffer (&optional enter-string)
1059 "Rename the *message* buffer to \"*message* RECIPIENT\".
1060 If the function is run with a prefix, it will ask for a new buffer
1061 name, rather than giving an automatic name."
1062 (interactive "Pbuffer name: ")
1065 (goto-char (point-min))
1066 (narrow-to-region (point)
1067 (search-forward mail-header-separator nil 'end))
1068 (let* ((mail-to (if (message-news-p) (message-fetch-field "Newsgroups")
1069 (message-fetch-field "To")))
1071 (if (string-match "," mail-to)
1072 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
1074 (name-default (concat "*message* " mail-trimmed-to))
1075 (name (if enter-string
1076 (read-string "New buffer name: " name-default)
1079 (file-name-as-directory message-autosave-directory)))
1080 (rename-buffer name t)))))
1082 (defun message-fill-yanked-message (&optional justifyp)
1083 "Fill the paragraphs of a message yanked into this one.
1084 Numeric argument means justify as well."
1087 (goto-char (point-min))
1088 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1089 (let ((fill-prefix message-yank-prefix))
1090 (fill-individual-paragraphs (point) (point-max) justifyp t))))
1092 (defun message-indent-citation ()
1093 "Modify text just inserted from a message to be cited.
1094 The inserted text should be the region.
1095 When this function returns, the region is again around the modified text.
1097 Normally, indent each nonblank line `message-indentation-spaces' spaces.
1098 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
1099 (let ((start (point)))
1100 ;; Remove unwanted headers.
1101 (when message-ignored-cited-headers
1105 (if (search-forward "\n\n" nil t)
1108 (message-remove-header message-ignored-cited-headers t)
1109 (goto-char (point-max))))
1110 ;; Delete blank lines at the start of the buffer.
1111 (while (and (point-min)
1114 (message-delete-line))
1115 ;; Delete blank lines at the end of the buffer.
1116 (goto-char (point-max))
1119 (while (and (zerop (forward-line -1))
1121 (message-delete-line))
1122 ;; Do the indentation.
1123 (if (null message-yank-prefix)
1124 (indent-rigidly start (mark t) message-indentation-spaces)
1127 (while (< (point) (mark t))
1128 (insert message-yank-prefix)
1130 (goto-char start))))
1132 (defun message-yank-original (&optional arg)
1133 "Insert the message being replied to, if any.
1134 Puts point before the text and mark after.
1135 Normally indents each nonblank line ARG spaces (default 3). However,
1136 if `message-yank-prefix' is non-nil, insert that prefix on each line.
1138 This function uses `message-cite-function' to do the actual citing.
1140 Just \\[universal-argument] as argument means don't indent, insert no
1141 prefix, and don't delete any headers."
1143 (let ((modified (buffer-modified-p)))
1144 (when (and message-reply-buffer
1145 message-cite-function)
1146 (delete-windows-on message-reply-buffer t)
1147 (insert-buffer message-reply-buffer)
1148 (funcall message-cite-function)
1149 (message-exchange-point-and-mark)
1153 (setq message-checksum (cons (message-checksum) (buffer-size)))))))
1155 (defun message-cite-original ()
1156 "Cite function in the standard Message manner."
1157 (let ((start (point))
1159 (when message-indent-citation-function
1160 (if (listp message-indent-citation-function)
1161 message-indent-citation-function
1162 (list message-indent-citation-function)))))
1165 (funcall (pop functions)))
1166 (when message-citation-line-function
1169 (funcall message-citation-line-function))))
1171 (defun message-insert-citation-line ()
1172 "Function that inserts a simple citation line."
1173 (when message-reply-headers
1174 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
1176 (defun message-position-on-field (header &rest afters)
1177 (let ((case-fold-search t))
1180 (goto-char (point-min))
1183 (concat "^" (regexp-quote mail-header-separator) "$"))
1184 (match-beginning 0)))
1185 (goto-char (point-min))
1186 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
1188 (re-search-forward "^[^ \t]" nil 'move)
1190 (skip-chars-backward "\n")
1193 (not (re-search-forward
1194 (concat "^" (regexp-quote (car afters)) ":")
1198 (re-search-forward "^[^ \t]" nil 'move)
1199 (beginning-of-line))
1200 (insert header ": \n")
1204 (defun message-remove-signature ()
1205 "Remove the signature from the text between point and mark.
1206 The text will also be indented the normal way."
1208 (let ((start (point))
1210 (if (not (re-search-forward message-signature-separator (mark t) t))
1211 ;; No signature here, so we just indent the cited text.
1212 (message-indent-citation)
1213 ;; Find the last non-empty line.
1215 (while (looking-at "[ \t]*$")
1218 (setq mark (set-marker (make-marker) (point)))
1220 (message-indent-citation)
1221 ;; Enable undoing the deletion.
1223 (delete-region mark (mark t))
1224 (set-marker mark nil)))))
1229 ;;; Sending messages
1232 (defun message-send-and-exit (&optional arg)
1233 "Send message like `message-send', then, if no errors, exit from mail buffer."
1235 (let ((buf (current-buffer))
1236 (actions message-exit-actions))
1237 (when (and (message-send arg)
1239 (if message-kill-buffer-on-exit
1242 (when (eq buf (current-buffer))
1243 (message-bury buf)))
1244 (message-do-actions actions))))
1246 (defun message-dont-send ()
1247 "Don't send the message you have been editing."
1249 (let ((actions message-postpone-actions))
1250 (message-bury (current-buffer))
1251 (message-do-actions actions)))
1253 (defun message-kill-buffer ()
1254 "Kill the current buffer."
1256 (let ((actions message-kill-actions))
1257 (kill-buffer (current-buffer))
1258 (message-do-actions actions)))
1260 (defun message-bury (buffer)
1261 "Bury this mail buffer."
1262 (let ((newbuf (other-buffer buffer)))
1263 (bury-buffer buffer)
1264 (if (and (fboundp 'frame-parameters)
1265 (cdr (assq 'dedicated (frame-parameters)))
1266 (not (null (delq (selected-frame) (visible-frame-list)))))
1267 (delete-frame (selected-frame))
1268 (switch-to-buffer newbuf))))
1270 (defun message-send (&optional arg)
1271 "Send the message in the current buffer.
1272 If `message-interactive' is non-nil, wait for success indication
1273 or error messages, and inform user.
1274 Otherwise any failure is reported in a message back to
1275 the user from the mailer."
1277 (when (if buffer-file-name
1278 (y-or-n-p (format "Send buffer contents as %s message? "
1279 (if (message-mail-p)
1280 (if (message-news-p) "mail and news" "mail")
1282 (or (buffer-modified-p)
1283 (y-or-n-p "No changes in the buffer; really send? ")))
1284 ;; Make it possible to undo the coming changes.
1286 (let ((inhibit-read-only t))
1287 (put-text-property (point-min) (point-max) 'read-only nil))
1288 (message-fix-before-sending)
1289 (run-hooks 'message-send-hook)
1290 (message "Sending...")
1291 (when (and (or (not (message-news-p))
1292 (and (or (not (memq 'news message-sent-message-via))
1294 "Already sent message via news; resend? "))
1295 (funcall message-send-news-function arg)))
1296 (or (not (message-mail-p))
1297 (and (or (not (memq 'mail message-sent-message-via))
1299 "Already sent message via mail; resend? "))
1300 (message-send-mail arg))))
1302 ;;(when (fboundp 'mail-hist-put-headers-into-history)
1303 ;; (mail-hist-put-headers-into-history))
1304 (run-hooks 'message-sent-hook)
1305 (message "Sending...done")
1306 ;; If buffer has no file, mark it as unmodified and delete autosave.
1307 (unless buffer-file-name
1308 (set-buffer-modified-p nil)
1309 (delete-auto-save-file-if-necessary t))
1310 ;; Delete other mail buffers and stuff.
1311 (message-do-send-housekeeping)
1312 (message-do-actions message-send-actions)
1316 (defun message-fix-before-sending ()
1317 "Do various things to make the message nice before sending it."
1318 ;; Make sure there's a newline at the end of the message.
1319 (goto-char (point-max))
1323 (defun message-add-action (action &rest types)
1324 "Add ACTION to be performed when doing an exit of type TYPES."
1327 (set (setq var (intern (format "message-%s-actions" (pop types))))
1328 (nconc (symbol-value var) (list action))))))
1330 (defun message-do-actions (actions)
1331 "Perform all actions in ACTIONS."
1332 ;; Now perform actions on successful sending.
1336 ;; A simple function.
1337 ((message-functionp (car actions))
1338 (funcall (car actions)))
1339 ;; Something to be evaled.
1341 (eval (car actions))))
1345 (defun message-send-mail (&optional arg)
1346 (require 'mail-utils)
1347 (let ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
1348 (case-fold-search nil)
1349 (news (message-news-p))
1350 (mailbuf (current-buffer)))
1352 (message-narrow-to-headers)
1353 ;; Insert some headers.
1354 (let ((message-deletable-headers
1355 (if news nil message-deletable-headers)))
1356 (message-generate-headers message-required-mail-headers))
1357 ;; Let the user do all of the above.
1358 (run-hooks 'message-header-hook))
1363 ;; Avoid copying text props.
1365 "%s" (save-excursion
1366 (set-buffer mailbuf)
1368 ;; Remove some headers.
1370 (message-narrow-to-headers)
1371 ;; Remove some headers.
1372 (message-remove-header message-ignored-mail-headers t))
1373 (goto-char (point-max))
1374 ;; require one newline at the end.
1375 (or (= (preceding-char) ?\n)
1378 (or (message-fetch-field "cc")
1379 (message-fetch-field "to")))
1380 (message-insert-courtesy-copy))
1381 (funcall message-send-mail-function))
1382 (kill-buffer tembuf))
1383 (set-buffer mailbuf)
1384 (push 'mail message-sent-message-via)))
1386 (defun message-send-mail-with-sendmail ()
1387 "Send off the prepared buffer with sendmail."
1388 (let ((errbuf (if message-interactive
1389 (generate-new-buffer " sendmail errors")
1391 resend-to-addresses delimline)
1392 (let ((case-fold-search t))
1394 (message-narrow-to-headers)
1395 (setq resend-to-addresses (message-fetch-field "resent-to")))
1396 ;; Change header-delimiter to be what sendmail expects.
1397 (goto-char (point-min))
1399 (concat "^" (regexp-quote mail-header-separator) "\n"))
1400 (replace-match "\n")
1402 (setq delimline (point-marker))
1403 (run-hooks 'message-send-mail-hook)
1404 ;; Insert an extra newline if we need it to work around
1405 ;; Sun's bug that swallows newlines.
1406 (goto-char (1+ delimline))
1407 (when (eval message-mailer-swallows-blank-line)
1409 (when message-interactive
1413 (let ((default-directory "/"))
1414 (apply 'call-process-region
1415 (append (list (point-min) (point-max)
1416 (if (boundp 'sendmail-program)
1418 "/usr/lib/sendmail")
1419 nil errbuf nil "-oi")
1420 ;; Always specify who from,
1421 ;; since some systems have broken sendmails.
1422 (list "-f" (user-login-name))
1423 ;; These mean "report errors by mail"
1424 ;; and "deliver in background".
1425 (if (null message-interactive) '("-oem" "-odb"))
1426 ;; Get the addresses from the message
1427 ;; unless this is a resend.
1428 ;; We must not do that for a resend
1429 ;; because we would find the original addresses.
1430 ;; For a resend, include the specific addresses.
1431 (if resend-to-addresses
1432 (list resend-to-addresses)
1434 (when message-interactive
1437 (goto-char (point-min))
1438 (while (re-search-forward "\n\n* *" nil t)
1439 (replace-match "; "))
1440 (if (not (zerop (buffer-size)))
1441 (error "Sending...failed to %s"
1442 (buffer-substring (point-min) (point-max)))))
1443 (when (bufferp errbuf)
1444 (kill-buffer errbuf)))))
1446 (defun message-send-mail-with-qmail ()
1447 "Pass the prepared message buffer to qmail-inject.
1448 Refer to the documentation for the variable `message-send-mail-function'
1449 to find out how to use this."
1450 ;; replace the header delimiter with a blank line
1451 (goto-char (point-min))
1453 (concat "^" (regexp-quote mail-header-separator) "\n"))
1454 (replace-match "\n")
1455 (run-hooks 'message-send-mail-hook)
1459 'call-process-region 1 (point-max) message-qmail-inject-program
1461 ;; qmail-inject's default behaviour is to look for addresses on the
1462 ;; command line; if there're none, it scans the headers.
1463 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
1465 ;; in general, ALL of qmail-inject's defaults are perfect for simply
1466 ;; reading a formatted (i. e., at least a To: or Resent-To header)
1467 ;; message from stdin.
1469 ;; qmail also has the advantage of not having been raped by
1470 ;; various vendors, so we don't have to allow for that, either --
1471 ;; compare this with message-send-mail-with-sendmail and weep
1472 ;; for sendmail's lost innocence.
1474 ;; all this is way cool coz it lets us keep the arguments entirely
1475 ;; free for -inject-arguments -- a big win for the user and for us
1476 ;; since we don't have to play that double-guessing game and the user
1477 ;; gets full control (no gestapo'ish -f's, for instance). --sj
1478 message-qmail-inject-args)
1479 ;; qmail-inject doesn't say anything on it's stdout/stderr,
1480 ;; we have to look at the retval instead
1482 (1 (error "qmail-inject reported permanent failure."))
1483 (111 (error "qmail-inject reported transient failure."))
1484 ;; should never happen
1485 (t (error "qmail-inject reported unknown failure."))))
1487 (defun message-send-mail-with-mh ()
1488 "Send the prepared message buffer with mh."
1489 (let ((mh-previous-window-config nil)
1490 (name (make-temp-name
1491 (concat (file-name-as-directory message-autosave-directory)
1493 (setq buffer-file-name name)
1494 ;; MH wants to generate these headers itself.
1495 (let ((headers message-deletable-headers))
1497 (goto-char (point-min))
1498 ;;(message "Deleting header %s" (car headers)) (sit-for 5)
1499 (and (re-search-forward
1500 (concat "^" (symbol-name (car headers)) ": *") nil t)
1501 (message-delete-line))
1503 (run-hooks 'message-send-mail-hook)
1504 ;; Pass it on to mh.
1507 (defun message-send-news (&optional arg)
1508 (let ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
1509 (case-fold-search nil)
1510 (method (if (message-functionp message-post-method)
1511 (funcall message-post-method arg)
1512 message-post-method))
1513 (messbuf (current-buffer))
1514 (message-syntax-checks
1516 (cons '(existing-newsgroups . disabled)
1517 message-syntax-checks)
1518 message-syntax-checks))
1521 (message-narrow-to-headers)
1522 ;; Insert some headers.
1523 (message-generate-headers message-required-news-headers)
1524 ;; Let the user do all of the above.
1525 (run-hooks 'message-header-hook))
1526 (message-cleanup-headers)
1527 (if (not (message-check-news-syntax))
1529 ;;(message "Posting not performed")
1534 (buffer-disable-undo (current-buffer))
1536 ;; Avoid copying text props.
1538 "%s" (save-excursion
1539 (set-buffer messbuf)
1541 ;; Remove some headers.
1543 (message-narrow-to-headers)
1544 ;; Remove some headers.
1545 (message-remove-header message-ignored-news-headers t))
1546 (goto-char (point-max))
1547 ;; require one newline at the end.
1548 (or (= (preceding-char) ?\n)
1550 (let ((case-fold-search t))
1551 ;; Remove the delimiter.
1552 (goto-char (point-min))
1554 (concat "^" (regexp-quote mail-header-separator) "\n"))
1555 (replace-match "\n")
1557 (run-hooks 'message-send-news-hook)
1558 (require (car method))
1559 (funcall (intern (format "%s-open-server" (car method)))
1560 (cadr method) (cddr method))
1562 (funcall (intern (format "%s-request-post" (car method))))))
1563 (kill-buffer tembuf))
1564 (set-buffer messbuf)
1566 (push 'news message-sent-message-via)
1567 (message "Couldn't send message via news: %s"
1568 (nnheader-get-report (car method)))
1572 ;;; Header generation & syntax checking.
1575 (defmacro message-check (type &rest forms)
1576 "Eval FORMS if TYPE is to be checked."
1577 `(or (message-check-element ,type)
1581 (put 'message-check 'lisp-indent-function 1)
1582 (put 'message-check 'edebug-form-spec '(form body))
1584 (defun message-check-element (type)
1585 "Returns non-nil if this type is not to be checked."
1586 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
1588 (let ((able (assq type message-syntax-checks)))
1590 (eq (cdr able) 'disabled)))))
1592 (defun message-check-news-syntax ()
1593 "Check the syntax of the message."
1598 ;; We narrow to the headers and check them first.
1601 (message-narrow-to-headers)
1602 (message-check-news-header-syntax)))
1604 (message-check-news-body-syntax)))))
1606 (defun message-check-news-header-syntax ()
1608 ;; Check for commands in Subject.
1609 (message-check 'subject-cmsg
1610 (if (string-match "^cmsg " (message-fetch-field "subject"))
1612 "The control code \"cmsg\" is in the subject. Really post? ")
1614 ;; Check for multiple identical headers.
1615 (message-check 'multiple-headers
1617 (while (and (not found)
1618 (re-search-forward "^[^ \t:]+: " nil t))
1620 (or (re-search-forward
1625 (match-beginning 0) (- (match-end 0) 2))))
1630 (y-or-n-p (format "Multiple %s headers. Really post? " found))
1632 ;; Check for Version and Sendsys.
1633 (message-check 'sendsys
1634 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
1636 (format "The article contains a %s command. Really post? "
1637 (buffer-substring (match-beginning 0)
1638 (1- (match-end 0)))))
1640 ;; See whether we can shorten Followup-To.
1641 (message-check 'shorten-followup-to
1642 (let ((newsgroups (message-fetch-field "newsgroups"))
1643 (followup-to (message-fetch-field "followup-to"))
1645 (when (and newsgroups
1646 (string-match "," newsgroups)
1651 (setq to (completing-read
1652 "Followups to: (default all groups) "
1653 (mapcar (lambda (g) (list g))
1655 (message-tokenize-header
1657 (goto-char (point-min))
1658 (insert "Followup-To: " to "\n"))
1660 ;; Check "Shoot me".
1661 (message-check 'shoot
1662 (if (re-search-forward
1663 "Message-ID.*.i-have-a-misconfigured-system-so-shoot-me" nil t)
1664 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
1666 ;; Check for Approved.
1667 (message-check 'approved
1668 (if (re-search-forward "^Approved:" nil t)
1669 (y-or-n-p "The article contains an Approved header. Really post? ")
1671 ;; Check the Message-ID header.
1672 (message-check 'message-id
1673 (let* ((case-fold-search t)
1674 (message-id (message-fetch-field "message-id")))
1675 (or (not message-id)
1676 (and (string-match "@" message-id)
1677 (string-match "@[^\\.]*\\." message-id))
1679 (format "The Message-ID looks strange: \"%s\". Really post? "
1681 ;; Check the Subject header.
1682 (message-check 'subject
1683 (let* ((case-fold-search t)
1684 (subject (message-fetch-field "subject")))
1687 (not (string-match "\\`[ \t]*\\'" subject)))
1690 "The subject field is empty or missing. Posting is denied.")))))
1691 ;; Check the Newsgroups & Followup-To headers.
1692 (message-check 'existing-newsgroups
1693 (let* ((case-fold-search t)
1694 (newsgroups (message-fetch-field "newsgroups"))
1695 (followup-to (message-fetch-field "followup-to"))
1696 (groups (message-tokenize-header
1698 (concat newsgroups "," followup-to)
1700 (hashtb (and (boundp 'gnus-active-hashtb)
1701 gnus-active-hashtb))
1706 (when (and (not (boundp (intern (car groups) hashtb)))
1707 (not (equal (car groups) "poster")))
1708 (push (car groups) errors))
1714 "Really post to %s unknown group%s: %s "
1715 (if (= (length errors) 1) "this" "these")
1716 (if (= (length errors) 1) "" "s")
1717 (mapconcat 'identity errors ", ")))))))
1718 ;; Check the Newsgroups & Followup-To headers for syntax errors.
1719 (message-check 'valid-newsgroups
1720 (let ((case-fold-search t)
1721 (headers '("Newsgroups" "Followup-To"))
1723 (while (and headers (not error))
1724 (when (setq header (mail-fetch-field (car headers)))
1728 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
1733 (not (string-match "\\.\\'\\|\\.\\." g)))
1734 (message-tokenize-header header ","))))
1741 (format "The %s header looks odd: \"%s\". Really post? "
1742 (car headers) header)))))
1743 ;; Check the From header.
1744 (message-check 'from
1745 (let* ((case-fold-search t)
1746 (from (message-fetch-field "from"))
1747 (ad (nth 1 (mail-extract-address-components from))))
1750 (message "There is no From line. Posting is denied.")
1752 ((or (not (string-match "@[^\\.]*\\." ad)) ;larsi@ifi
1753 (string-match "\\.\\." ad) ;larsi@ifi..uio
1754 (string-match "@\\." ad) ;larsi@.ifi.uio
1755 (string-match "\\.$" ad) ;larsi@ifi.uio.
1756 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
1757 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
1759 "Denied posting -- the From looks strange: \"%s\"." from)
1763 (defun message-check-news-body-syntax ()
1765 ;; Check for long lines.
1766 (message-check 'long-lines
1767 (goto-char (point-min))
1769 (concat "^" (regexp-quote mail-header-separator) "$"))
1773 (< (current-column) 80))
1774 (zerop (forward-line 1))))
1778 "You have lines longer than 79 characters. Really post? ")))
1779 ;; Check whether the article is empty.
1780 (message-check 'empty
1781 (goto-char (point-min))
1783 (concat "^" (regexp-quote mail-header-separator) "$"))
1786 (goto-char (point-max))
1787 (re-search-backward message-signature-separator nil t)
1789 (or (re-search-backward "[^ \n\t]" b t)
1790 (y-or-n-p "Empty article. Really post? "))))
1791 ;; Check for control characters.
1792 (message-check 'control-chars
1793 (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t)
1795 "The article contains control characters. Really post? ")
1797 ;; Check excessive size.
1798 (message-check 'size
1799 (if (> (buffer-size) 60000)
1801 (format "The article is %d octets long. Really post? "
1804 ;; Check whether any new text has been added.
1805 (message-check 'new-text
1807 (not message-checksum)
1808 (not (and (eq (message-checksum) (car message-checksum))
1809 (eq (buffer-size) (cdr message-checksum))))
1811 "It looks like no new text has been added. Really post? ")))
1812 ;; Check the length of the signature.
1813 (message-check 'signature
1814 (goto-char (point-max))
1815 (if (or (not (re-search-backward message-signature-separator nil t))
1816 (search-forward message-forward-end-separator nil t))
1818 (if (> (count-lines (point) (point-max)) 5)
1821 "Your .sig is %d lines; it should be max 4. Really post? "
1822 (1- (count-lines (point) (point-max)))))
1825 (defun message-checksum ()
1826 "Return a \"checksum\" for the current buffer."
1829 (goto-char (point-min))
1831 (concat "^" (regexp-quote mail-header-separator) "$"))
1833 (when (not (looking-at "[ \t\n]"))
1834 (setq sum (logxor (ash sum 1) (following-char))))
1838 (defun message-do-fcc ()
1839 "Process Fcc headers in the current buffer."
1840 (let ((case-fold-search t)
1841 (buf (current-buffer))
1844 (set-buffer (get-buffer-create " *message temp*"))
1845 (buffer-disable-undo (current-buffer))
1847 (insert-buffer-substring buf)
1849 (message-narrow-to-headers)
1850 (while (setq file (message-fetch-field "fcc"))
1852 (message-remove-header "fcc" nil t)))
1853 (goto-char (point-min))
1854 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1855 (replace-match "" t t)
1856 ;; Process FCC operations.
1858 (setq file (pop list))
1859 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
1860 ;; Pipe the article to the program in question.
1861 (call-process-region (point-min) (point-max) shell-file-name
1862 nil nil nil shell-command-switch
1863 (match-string 1 file))
1864 ;; Save the article.
1865 (setq file (expand-file-name file))
1866 (unless (file-exists-p (file-name-directory file))
1867 (make-directory (file-name-directory file) t))
1868 (if (and message-fcc-handler-function
1869 (not (eq message-fcc-handler-function 'rmail-output)))
1870 (funcall message-fcc-handler-function file)
1871 (if (and (file-readable-p file) (mail-file-babyl-p file))
1872 (rmail-output file 1)
1873 (let ((mail-use-rfc822 t))
1874 (rmail-output file 1 t t))))))
1875 (kill-buffer (current-buffer)))))
1877 (defun message-cleanup-headers ()
1878 "Do various automatic cleanups of the headers."
1879 ;; Remove empty lines in the header.
1881 (message-narrow-to-headers)
1882 (while (re-search-forward "^[ \t]*\n" nil t)
1883 (replace-match "" t t)))
1885 ;; Correct Newsgroups and Followup-To headers: change sequence of
1886 ;; spaces to comma and eliminate spaces around commas. Eliminate
1887 ;; embedded line breaks.
1888 (goto-char (point-min))
1889 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
1893 (if (re-search-forward "^[^ \t]" nil t)
1897 (goto-char (point-min))
1898 (while (re-search-forward "\n[ \t]+" nil t)
1899 (replace-match " " t t)) ;No line breaks (too confusing)
1900 (goto-char (point-min))
1901 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
1902 (replace-match "," t t))
1903 (goto-char (point-min))
1904 ;; Remove trailing commas.
1905 (when (re-search-forward ",+$" nil t)
1906 (replace-match "" t t)))))
1908 (defun message-make-date ()
1909 "Make a valid data header."
1910 (let ((now (current-time)))
1911 (timezone-make-date-arpa-standard
1912 (current-time-string now) (current-time-zone now))))
1914 (defun message-make-message-id ()
1915 "Make a unique Message-ID."
1916 (concat "<" (message-unique-id)
1917 (let ((psubject (save-excursion (message-fetch-field "subject"))))
1918 (if (and message-reply-headers
1919 (mail-header-references message-reply-headers)
1920 (mail-header-subject message-reply-headers)
1922 (mail-header-subject message-reply-headers)
1924 (message-strip-subject-re
1925 (mail-header-subject message-reply-headers))
1926 (message-strip-subject-re psubject))))
1928 "@" (message-make-fqdn) ">"))
1930 (defvar message-unique-id-char nil)
1932 ;; If you ever change this function, make sure the new version
1933 ;; cannot generate IDs that the old version could.
1934 ;; You might for example insert a "." somewhere (not next to another dot
1935 ;; or string boundary), or modify the "fsf" string.
1936 (defun message-unique-id ()
1937 ;; Don't use microseconds from (current-time), they may be unsupported.
1938 ;; Instead we use this randomly inited counter.
1939 (setq message-unique-id-char
1940 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
1941 ;; (current-time) returns 16-bit ints,
1942 ;; and 2^16*25 just fits into 4 digits i base 36.
1944 (let ((tm (current-time)))
1946 (if (memq system-type '(ms-dos emx vax-vms))
1947 (let ((user (downcase (user-login-name))))
1948 (while (string-match "[^a-z0-9_]" user)
1949 (aset user (match-beginning 0) ?_))
1951 (message-number-base36 (user-uid) -1))
1952 (message-number-base36 (+ (car tm)
1953 (lsh (% message-unique-id-char 25) 16)) 4)
1954 (message-number-base36 (+ (nth 1 tm)
1955 (lsh (/ message-unique-id-char 25) 16)) 4)
1956 ;; Append the newsreader name, because while the generated
1957 ;; ID is unique to this newsreader, other newsreaders might
1958 ;; otherwise generate the same ID via another algorithm.
1961 (defun message-number-base36 (num len)
1962 (if (if (< len 0) (<= num 0) (= len 0))
1964 (concat (message-number-base36 (/ num 36) (1- len))
1965 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
1968 (defun message-make-organization ()
1969 "Make an Organization header."
1970 (let* ((organization
1971 (or (getenv "ORGANIZATION")
1972 (when message-user-organization
1973 (if (message-functionp message-user-organization)
1974 (funcall message-user-organization)
1975 message-user-organization)))))
1977 (message-set-work-buffer)
1978 (cond ((stringp organization)
1979 (insert organization))
1980 ((and (eq t organization)
1981 message-user-organization-file
1982 (file-exists-p message-user-organization-file))
1983 (insert-file-contents message-user-organization-file)))
1984 (goto-char (point-min))
1985 (while (re-search-forward "[\t\n]+" nil t)
1986 (replace-match "" t t))
1987 (unless (zerop (buffer-size))
1990 (defun message-make-lines ()
1991 "Count the number of lines and return numeric string."
1995 (goto-char (point-min))
1997 (concat "^" (regexp-quote mail-header-separator) "$"))
1999 (int-to-string (count-lines (point) (point-max))))))
2001 (defun message-make-in-reply-to ()
2002 "Return the In-Reply-To header for this message."
2003 (when message-reply-headers
2004 (let ((from (mail-header-from message-reply-headers))
2005 (date (mail-header-date message-reply-headers)))
2008 (string-match " *at \\| *@ \\| *(\\| *<" from)))
2009 (concat (if stop-pos (substring from 0 stop-pos) from)
2011 (if (or (not date) (string= date ""))
2012 "(unknown date)" date)))))))
2014 (defun message-make-distribution ()
2015 "Make a Distribution header."
2016 (let ((orig-distribution (message-fetch-reply-field "distribution")))
2017 (cond ((message-functionp message-distribution-function)
2018 (funcall message-distribution-function))
2019 (t orig-distribution))))
2021 (defun message-make-expires ()
2022 "Return an Expires header based on `message-expires'."
2023 (let ((current (current-time))
2024 (future (* 1.0 message-expires 60 60 24)))
2025 ;; Add the future to current.
2026 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
2027 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
2028 ;; Return the date in the future in UT.
2029 (timezone-make-date-arpa-standard
2030 (current-time-string current) (current-time-zone current) '(0 "UT"))))
2032 (defun message-make-path ()
2034 (let ((login-name (user-login-name)))
2035 (cond ((null message-user-path)
2036 (concat (system-name) "!" login-name))
2037 ((stringp message-user-path)
2038 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
2039 (concat message-user-path "!" login-name))
2042 (defun message-make-from ()
2043 "Make a From header."
2044 (let* ((login (message-make-address))
2046 (or (and (boundp 'user-full-name)
2049 (when (string= fullname "&")
2050 (setq fullname (user-login-name)))
2052 (message-set-work-buffer)
2054 ((or (null message-from-style)
2055 (equal fullname ""))
2057 ((or (eq message-from-style 'angles)
2058 (and (not (eq message-from-style 'parens))
2059 ;; Use angles if no quoting is needed, or if parens would
2060 ;; need quoting too.
2061 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
2062 (let ((tmp (concat fullname nil)))
2063 (while (string-match "([^()]*)" tmp)
2064 (aset tmp (match-beginning 0) ?-)
2065 (aset tmp (1- (match-end 0)) ?-))
2066 (string-match "[\\()]" tmp)))))
2068 (goto-char (point-min))
2069 ;; Look for a character that cannot appear unquoted
2070 ;; according to RFC 822.
2071 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
2072 ;; Quote fullname, escaping specials.
2073 (goto-char (point-min))
2075 (while (re-search-forward "[\"\\]" nil 1)
2076 (replace-match "\\\\\\&" t))
2078 (insert " <" login ">"))
2079 (t ; 'parens or default
2081 (let ((fullname-start (point)))
2083 (goto-char fullname-start)
2084 ;; RFC 822 says \ and nonmatching parentheses
2085 ;; must be escaped in comments.
2086 ;; Escape every instance of ()\ ...
2087 (while (re-search-forward "[()\\]" nil 1)
2088 (replace-match "\\\\\\&" t))
2089 ;; ... then undo escaping of matching parentheses,
2090 ;; including matching nested parentheses.
2091 (goto-char fullname-start)
2092 (while (re-search-forward
2093 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
2095 (replace-match "\\1(\\3)" t)
2096 (goto-char fullname-start)))
2100 (defun message-make-sender ()
2101 "Return the \"real\" user address.
2102 This function tries to ignore all user modifications, and
2103 give as trustworthy answer as possible."
2104 (concat (user-login-name) "@" (system-name)))
2106 (defun message-make-address ()
2107 "Make the address of the user."
2108 (or (message-user-mail-address)
2109 (concat (user-login-name) "@" (message-make-domain))))
2111 (defun message-user-mail-address ()
2112 "Return the pertinent part of `user-mail-address'."
2113 (when user-mail-address
2114 (nth 1 (mail-extract-address-components user-mail-address))))
2116 (defun message-make-fqdn ()
2117 "Return user's fully qualified domain name."
2118 (let ((system-name (system-name))
2119 (user-mail (message-user-mail-address)))
2121 ((string-match "[^.]\\.[^.]" system-name)
2122 ;; `system-name' returned the right result.
2124 ;; Try `mail-host-address'.
2125 ((and (boundp 'mail-host-address)
2126 (stringp mail-host-address)
2127 (string-match "\\." mail-host-address))
2129 ;; We try `user-mail-address' as a backup.
2130 ((and (string-match "\\." user-mail)
2131 (string-match "@\\(.*\\)\\'" user-mail))
2132 (match-string 1 user-mail))
2133 ;; Default to this bogus thing.
2135 (concat system-name ".i-have-a-misconfigured-system-so-shoot-me")))))
2137 (defun message-make-host-name ()
2138 "Return the name of the host."
2139 (let ((fqdn (message-make-fqdn)))
2140 (string-match "^[^.]+\\." fqdn)
2141 (substring fqdn 0 (1- (match-end 0)))))
2143 (defun message-make-domain ()
2144 "Return the domain name."
2145 (or mail-host-address
2146 (message-make-fqdn)))
2148 (defun message-generate-headers (headers)
2149 "Prepare article HEADERS.
2150 Headers already prepared in the buffer are not modified."
2152 (message-narrow-to-headers)
2153 (let* ((Date (message-make-date))
2154 (Message-ID (message-make-message-id))
2155 (Organization (message-make-organization))
2156 (From (message-make-from))
2157 (Path (message-make-path))
2160 (In-Reply-To (message-make-in-reply-to))
2162 (Distribution (message-make-distribution))
2163 (Lines (message-make-lines))
2164 (X-Newsreader message-newsreader)
2165 (X-Mailer (and (not (message-fetch-field "X-Newsreader"))
2167 (Expires (message-make-expires))
2168 (case-fold-search t)
2170 ;; First we remove any old generated headers.
2171 (let ((headers message-deletable-headers))
2173 (goto-char (point-min))
2174 (and (re-search-forward
2175 (concat "^" (symbol-name (car headers)) ": *") nil t)
2176 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
2177 (message-delete-line))
2179 ;; Go through all the required headers and see if they are in the
2180 ;; articles already. If they are not, or are empty, they are
2181 ;; inserted automatically - except for Subject, Newsgroups and
2184 (goto-char (point-min))
2185 (setq elem (pop headers))
2187 (if (eq (car elem) 'optional)
2188 (setq header (cdr elem))
2189 (setq header (car elem)))
2191 (when (or (not (re-search-forward
2192 (concat "^" (downcase (symbol-name header)) ":")
2195 ;; The header was found. We insert a space after the
2196 ;; colon, if there is none.
2197 (if (/= (following-char) ? ) (insert " ") (forward-char 1))
2198 ;; Find out whether the header is empty...
2199 (looking-at "[ \t]*$")))
2200 ;; So we find out what value we should insert.
2203 ((and (consp elem) (eq (car elem) 'optional))
2204 ;; This is an optional header. If the cdr of this
2205 ;; is something that is nil, then we do not insert
2207 (setq header (cdr elem))
2208 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
2209 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
2211 ;; The element is a cons. Either the cdr is a
2212 ;; string to be inserted verbatim, or it is a
2213 ;; function, and we insert the value returned from
2215 (or (and (stringp (cdr elem)) (cdr elem))
2216 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
2217 ((and (boundp header) (symbol-value header))
2218 ;; The element is a symbol. We insert the value
2219 ;; of this symbol, if any.
2220 (symbol-value header))
2222 ;; We couldn't generate a value for this header,
2223 ;; so we just ask the user.
2224 (read-from-minibuffer
2225 (format "Empty header for %s; enter value: " header)))))
2226 ;; Finally insert the header.
2228 (not (equal value "")))
2232 ;; This header didn't exist, so we insert it.
2233 (goto-char (point-max))
2234 (insert (symbol-name header) ": " value "\n")
2236 ;; The value of this header was empty, so we clear
2237 ;; totally and insert the new value.
2238 (delete-region (point) (message-point-at-eol))
2240 ;; Add the deletable property to the headers that require it.
2241 (and (memq header message-deletable-headers)
2242 (progn (beginning-of-line) (looking-at "[^:]+: "))
2243 (add-text-properties
2244 (point) (match-end 0)
2245 '(message-deletable t face italic) (current-buffer)))))))
2246 ;; Insert new Sender if the From is strange.
2247 (let ((from (message-fetch-field "from"))
2248 (sender (message-fetch-field "sender"))
2249 (secure-sender (message-make-sender)))
2251 (not (message-check-element 'sender))
2254 (cadr (mail-extract-address-components from)))
2255 (downcase secure-sender)))
2260 (cadr (mail-extract-address-components sender)))
2261 (downcase secure-sender)))))
2262 (goto-char (point-min))
2263 ;; Rename any old Sender headers to Original-Sender.
2264 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
2266 (insert "Original-")
2267 (beginning-of-line))
2268 (insert "Sender: " secure-sender "\n"))))))
2270 (defun message-insert-courtesy-copy ()
2271 "Insert a courtesy message in mail copies of combined messages."
2275 (message-narrow-to-headers)
2276 (when (setq newsgroups (message-fetch-field "newsgroups"))
2277 (goto-char (point-max))
2278 (insert "Posted-To: " newsgroups "\n")))
2280 (when message-courtesy-message
2282 ((string-match "%s" message-courtesy-message)
2283 (insert (format message-courtesy-message newsgroups)))
2285 (insert message-courtesy-message)))))))
2288 ;;; Setting up a message buffer
2291 (defun message-fill-address (header value)
2293 (narrow-to-region (point) (point))
2294 (insert (capitalize (symbol-name header))
2296 (if (consp value) (car value) value)
2298 (narrow-to-region (point-min) (1- (point-max)))
2300 (goto-char (point-min))
2302 (skip-chars-forward "^,\"" (point-max))
2303 (if (or (= (following-char) ?,)
2306 (if (and (> (current-column) 78)
2312 (setq last (1+ (point))))
2313 (setq last (1+ (point)))))
2314 (setq quoted (not quoted)))
2317 (goto-char (point-max))
2321 (defun message-fill-header (header value)
2322 (let ((begin (point))
2325 (insert (capitalize (symbol-name header))
2327 (if (consp value) (car value) value)
2330 (narrow-to-region begin (point))
2331 (fill-region-as-paragraph begin (point))
2332 ;; Tapdance around looong Message-IDs.
2334 (when (looking-at "[ \t]*$")
2335 (message-delete-line))
2337 (re-search-forward ":" nil t)
2338 (when (looking-at "\n[ \t]+")
2339 (replace-match " " t t))
2340 (goto-char (point-max)))))
2342 (defun message-position-point ()
2343 "Move point to where the user probably wants to find it."
2344 (message-narrow-to-headers)
2346 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
2347 (search-backward ":" )
2350 (if (= (following-char) ? )
2354 (goto-char (point-max))
2357 (unless (looking-at "$")
2361 (defun message-buffer-name (type &optional to group)
2362 "Return a new (unique) buffer name based on TYPE and TO."
2364 ;; Check whether `message-generate-new-buffers' is a function,
2365 ;; and if so, call it.
2366 ((message-functionp message-generate-new-buffers)
2367 (funcall message-generate-new-buffers type to group))
2368 ;; Generate a new buffer name The Message Way.
2369 (message-generate-new-buffers
2370 (generate-new-buffer-name
2374 (or (car (mail-extract-address-components to))
2377 (if (and group (not (string= group ""))) (concat " on " group) "")
2379 ;; Use standard name.
2381 (format "*%s message*" type))))
2383 (defun message-pop-to-buffer (name)
2384 "Pop to buffer NAME, and warn if it already exists and is modified."
2385 (let ((buffer (get-buffer name)))
2387 (buffer-name buffer))
2389 (set-buffer (pop-to-buffer buffer))
2390 (when (and (buffer-modified-p)
2392 "Message already being composed; erase? ")))
2393 (error "Message being composed")))
2394 (set-buffer (pop-to-buffer name))))
2398 (defun message-do-send-housekeeping ()
2399 "Kill old message buffers."
2400 ;; We might have sent this buffer already. Delete it from the
2402 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
2403 (while (and message-max-buffers
2404 (>= (length message-buffer-list) message-max-buffers))
2405 ;; Kill the oldest buffer -- unless it has been changed.
2406 (let ((buffer (pop message-buffer-list)))
2407 (when (and (buffer-name buffer)
2408 (not (buffer-modified-p buffer)))
2409 (kill-buffer buffer))))
2410 ;; Rename the buffer.
2411 (if message-send-rename-function
2412 (funcall message-send-rename-function)
2413 (when (string-match "\\`\\*" (buffer-name))
2415 (concat "*sent " (substring (buffer-name) (match-end 0))) t)))
2416 ;; Push the current buffer onto the list.
2417 (when message-max-buffers
2418 (setq message-buffer-list
2419 (nconc message-buffer-list (list (current-buffer))))))
2421 (defvar mc-modes-alist)
2422 (defun message-setup (headers &optional replybuffer actions)
2423 (when (and (boundp 'mc-modes-alist)
2424 (not (assq 'message-mode mc-modes-alist)))
2425 (push '(message-mode (encrypt . mc-encrypt-message)
2426 (sign . mc-sign-message))
2429 (setq message-send-actions actions))
2430 (setq message-reply-buffer replybuffer)
2431 (goto-char (point-min))
2432 ;; Insert all the headers.
2435 (alist message-header-format-alist))
2437 (unless (assq (caar h) message-header-format-alist)
2438 (push (list (caar h)) alist))
2442 (delete-region (point) (progn (forward-line -1) (point)))
2443 (when message-default-headers
2444 (insert message-default-headers))
2448 (insert mail-header-separator "\n")
2452 (when (message-news-p)
2453 (when message-default-news-headers
2454 (insert message-default-news-headers))
2455 (when message-generate-headers-first
2456 (message-generate-headers
2459 (copy-sequence message-required-news-headers))))))
2460 (when (message-mail-p)
2461 (when message-default-mail-headers
2462 (insert message-default-mail-headers))
2463 (when message-generate-headers-first
2464 (message-generate-headers
2467 (copy-sequence message-required-mail-headers))))))
2468 (run-hooks 'message-signature-setup-hook)
2469 (message-insert-signature)
2470 (message-set-auto-save-file-name)
2472 (message-narrow-to-headers)
2473 (run-hooks 'message-header-setup-hook))
2474 (set-buffer-modified-p nil)
2475 (run-hooks 'message-setup-hook)
2476 (message-position-point)
2479 (defun message-set-auto-save-file-name ()
2480 "Associate the message buffer with a file in the drafts directory."
2481 (when message-autosave-directory
2482 (unless (file-exists-p message-autosave-directory)
2483 (make-directory message-autosave-directory t))
2484 (let ((name (make-temp-name
2485 (concat (file-name-as-directory message-autosave-directory)
2487 (setq buffer-auto-save-file-name
2491 (set-buffer (get-buffer-create " *draft tmp*"))
2492 (setq buffer-file-name name)
2493 (make-auto-save-file-name))
2494 (kill-buffer (current-buffer)))))
2495 (clear-visited-file-modtime))))
2500 ;;; Commands for interfacing with message
2504 (defun message-mail (&optional to subject)
2505 "Start editing a mail message to be sent."
2507 (message-pop-to-buffer (message-buffer-name "mail" to))
2508 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))))
2511 (defun message-news (&optional newsgroups subject)
2512 "Start editing a news article to be sent."
2514 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))
2515 (message-setup `((Newsgroups . ,(or newsgroups ""))
2516 (Subject . ,(or subject "")))))
2519 (defun message-reply (&optional to-address wide ignore-reply-to)
2520 "Start editing a reply to the article in the current buffer."
2522 (let ((cur (current-buffer))
2523 from subject date reply-to to cc
2524 references message-id follow-to
2525 (inhibit-point-motion-hooks t)
2526 mct never-mct gnus-warning)
2528 (message-narrow-to-head)
2529 ;; Allow customizations to have their say.
2531 ;; This is a regular reply.
2532 (if (message-functionp message-reply-to-function)
2533 (setq follow-to (funcall message-reply-to-function)))
2534 ;; This is a followup.
2535 (if (message-functionp message-wide-reply-to-function)
2538 (funcall message-wide-reply-to-function)))))
2539 ;; Find all relevant headers we need.
2540 (setq from (message-fetch-field "from")
2541 date (message-fetch-field "date")
2542 subject (or (message-fetch-field "subject") "none")
2543 to (message-fetch-field "to")
2544 cc (message-fetch-field "cc")
2545 mct (message-fetch-field "mail-copies-to")
2546 reply-to (unless ignore-reply-to (message-fetch-field "reply-to"))
2547 references (message-fetch-field "references")
2548 message-id (message-fetch-field "message-id"))
2549 ;; Remove any (buggy) Re:'s that are present and make a
2551 (when (string-match "^[ \t]*[Rr][Ee]:[ \t]*" subject)
2552 (setq subject (substring subject (match-end 0))))
2553 (setq subject (concat "Re: " subject))
2555 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
2556 (string-match "<[^>]+>" gnus-warning))
2557 (setq message-id (match-string 0 gnus-warning)))
2559 ;; Handle special values of Mail-Copies-To.
2561 (cond ((equal (downcase mct) "never")
2564 ((equal (downcase mct) "always")
2565 (setq mct (or reply-to from)))))
2570 (setq follow-to (list (cons 'To (or to-address reply-to from))))
2573 (message-set-work-buffer)
2575 (insert (or reply-to from "")))
2576 (insert (if (bolp) "" ", ") (or to ""))
2577 (insert (if mct (concat (if (bolp) "" ", ") mct) ""))
2578 (insert (if cc (concat (if (bolp) "" ", ") cc) ""))
2579 ;; Remove addresses that match `rmail-dont-reply-to-names'.
2580 (insert (prog1 (rmail-dont-reply-to (buffer-string))
2582 (goto-char (point-min))
2586 (cons (mail-strip-quoted-names addr) addr))
2587 (message-tokenize-header (buffer-string))))
2590 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
2591 (setq follow-to (list (cons 'To (cdr (pop ccalist)))))
2593 (let ((ccs (cons 'Cc (mapconcat
2594 (lambda (addr) (cdr addr)) ccalist ", "))))
2595 (when (string-match "^ +" (cdr ccs))
2596 (setcdr ccs (substring (cdr ccs) (match-end 0))))
2597 (push ccs follow-to))))))
2600 (message-pop-to-buffer (message-buffer-name
2601 (if wide "wide reply" "reply") from
2602 (if wide to-address nil)))
2604 (setq message-reply-headers
2605 (vector 0 subject from date message-id references 0 0 ""))
2608 `((Subject . ,subject)
2610 ,@(if (or references message-id)
2611 `((References . ,(concat (or references "") (and references " ")
2612 (or message-id ""))))
2617 (defun message-wide-reply (&optional to-address)
2618 "Make a \"wide\" reply to the message in the current buffer."
2620 (message-reply to-address t))
2623 (defun message-followup (&optional to-newsgroups)
2624 "Follow up to the message in the current buffer.
2625 If TO-NEWSGROUPS, use that as the new Newsgroups line."
2627 (let ((cur (current-buffer))
2628 from subject date reply-to mct
2629 references message-id follow-to
2630 (inhibit-point-motion-hooks t)
2631 followup-to distribution newsgroups gnus-warning)
2634 (goto-char (point-min))
2635 (if (search-forward "\n\n" nil t)
2638 (when (message-functionp message-followup-to-function)
2640 (funcall message-followup-to-function)))
2641 (setq from (message-fetch-field "from")
2642 date (message-fetch-field "date")
2643 subject (or (message-fetch-field "subject") "none")
2644 references (message-fetch-field "references")
2645 message-id (message-fetch-field "message-id")
2646 followup-to (message-fetch-field "followup-to")
2647 newsgroups (message-fetch-field "newsgroups")
2648 reply-to (message-fetch-field "reply-to")
2649 distribution (message-fetch-field "distribution")
2650 mct (message-fetch-field "mail-copies-to"))
2651 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
2652 (string-match "<[^>]+>" gnus-warning))
2653 (setq message-id (match-string 0 gnus-warning)))
2654 ;; Remove bogus distribution.
2655 (and (stringp distribution)
2656 (string-match "world" distribution)
2657 (setq distribution nil))
2658 ;; Remove any (buggy) Re:'s that are present and make a
2660 (when (string-match "^[ \t]*[Rr][Ee]:[ \t]*" subject)
2661 (setq subject (substring subject (match-end 0))))
2662 (setq subject (concat "Re: " subject))
2665 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
2668 `((Subject . ,subject)
2671 (list (cons 'Newsgroups to-newsgroups)))
2672 (follow-to follow-to)
2673 ((and followup-to message-use-followup-to)
2676 ((equal (downcase followup-to) "poster")
2677 (if (or (eq message-use-followup-to 'use)
2678 (message-y-or-n-p "Obey Followup-To: poster? " t "\
2679 You should normally obey the Followup-To: header.
2681 `Followup-To: poster' sends your response via e-mail instead of news.
2683 A typical situation where `Followup-To: poster' is used is when the poster
2684 does not read the newsgroup, so he wouldn't see any replies sent to it."))
2685 (cons 'To (or reply-to from ""))
2686 (cons 'Newsgroups newsgroups)))
2688 (if (or (equal followup-to newsgroups)
2689 (not (eq message-use-followup-to 'ask))
2691 (concat "Obey Followup-To: " followup-to "? ") t "\
2692 You should normally obey the Followup-To: header.
2694 `Followup-To: " followup-to "'
2695 directs your response to " (if (string-match "," followup-to)
2696 "the specified newsgroups"
2697 "that newsgroup only") ".
2699 If a message is posted to several newsgroups, Followup-To is often
2700 used to direct the following discussion to one newsgroup only,
2701 because discussions that are spread over several newsgroup tend to
2702 be fragmented and very difficult to follow.
2704 Also, some source/announcement newsgroups are not indented for discussion;
2705 responses here are directed to other newsgroups."))
2706 (cons 'Newsgroups followup-to)
2707 (cons 'Newsgroups newsgroups))))))
2709 `((Newsgroups . ,newsgroups))))
2710 ,@(and distribution (list (cons 'Distribution distribution)))
2711 ,@(if (or references message-id)
2712 `((References . ,(concat (or references "") (and references " ")
2713 (or message-id "")))))
2715 (not (equal (downcase mct) "never")))
2716 (list (cons 'Cc (if (equal (downcase mct) "always")
2717 (or reply-to from "")
2722 (setq message-reply-headers
2723 (vector 0 subject from date message-id references 0 0 ""))))
2727 (defun message-cancel-news ()
2728 "Cancel an article you posted."
2730 (unless (message-news-p)
2731 (error "This is not a news article; canceling is impossible"))
2732 (when (yes-or-no-p "Do you really want to cancel this article? ")
2733 (let (from newsgroups message-id distribution buf)
2735 ;; Get header info. from original article.
2737 (message-narrow-to-head)
2738 (setq from (message-fetch-field "from")
2739 newsgroups (message-fetch-field "newsgroups")
2740 message-id (message-fetch-field "message-id")
2741 distribution (message-fetch-field "distribution")))
2742 ;; Make sure that this article was written by the user.
2743 (unless (string-equal
2744 (downcase (cadr (mail-extract-address-components from)))
2745 (downcase (message-make-address)))
2746 (error "This article is not yours"))
2747 ;; Make control message.
2748 (setq buf (set-buffer (get-buffer-create " *message cancel*")))
2749 (buffer-disable-undo (current-buffer))
2751 (insert "Newsgroups: " newsgroups "\n"
2752 "From: " (message-make-from) "\n"
2753 "Subject: cmsg cancel " message-id "\n"
2754 "Control: cancel " message-id "\n"
2756 (concat "Distribution: " distribution "\n")
2758 mail-header-separator "\n"
2759 message-cancel-message)
2760 (message "Canceling your article...")
2761 (let ((message-syntax-checks 'dont-check-for-anything-just-trust-me))
2762 (funcall message-send-news-function))
2763 (message "Canceling your article...done")
2764 (kill-buffer buf)))))
2767 (defun message-supersede ()
2768 "Start composing a message to supersede the current message.
2769 This is done simply by taking the old article and adding a Supersedes
2770 header line with the old Message-ID."
2772 (let ((cur (current-buffer)))
2773 ;; Check whether the user owns the article that is to be superseded.
2774 (unless (string-equal
2775 (downcase (cadr (mail-extract-address-components
2776 (message-fetch-field "from"))))
2777 (downcase (message-make-address)))
2778 (error "This article is not yours"))
2779 ;; Get a normal message buffer.
2780 (message-pop-to-buffer (message-buffer-name "supersede"))
2781 (insert-buffer-substring cur)
2782 (message-narrow-to-head)
2783 ;; Remove unwanted headers.
2784 (when message-ignored-supersedes-headers
2785 (message-remove-header message-ignored-supersedes-headers t))
2786 (goto-char (point-min))
2787 (if (not (re-search-forward "^Message-ID: " nil t))
2788 (error "No Message-ID in this article")
2789 (replace-match "Supersedes: " t t))
2790 (goto-char (point-max))
2791 (insert mail-header-separator)
2796 (defun message-recover ()
2797 "Reread contents of current buffer from its last auto-save file."
2799 (let ((file-name (make-auto-save-file-name)))
2800 (cond ((save-window-excursion
2801 (if (not (eq system-type 'vax-vms))
2802 (with-output-to-temp-buffer "*Directory*"
2803 (buffer-disable-undo standard-output)
2804 (let ((default-directory "/"))
2806 "ls" nil standard-output nil "-l" file-name))))
2807 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
2808 (let ((buffer-read-only nil))
2810 (insert-file-contents file-name nil)))
2811 (t (error "message-recover cancelled")))))
2813 ;;; Forwarding messages.
2815 (defun message-make-forward-subject ()
2816 "Return a Subject header suitable for the message in the current buffer."
2817 (concat "[" (or (message-fetch-field
2818 (if (message-news-p) "newsgroups" "from"))
2820 "] " (or (message-fetch-field "Subject") "")))
2823 (defun message-forward (&optional news)
2824 "Forward the current message via mail.
2825 Optional NEWS will use news to forward instead of mail."
2827 (let ((cur (current-buffer))
2828 (subject (message-make-forward-subject))
2830 (if news (message-news nil subject) (message-mail nil subject))
2831 ;; Put point where we want it before inserting the forwarded
2833 (if message-signature-before-forwarded-message
2834 (goto-char (point-max))
2835 (message-goto-body))
2836 ;; Make sure we're at the start of the line.
2839 ;; Narrow to the area we are to insert.
2840 (narrow-to-region (point) (point))
2841 ;; Insert the separators and the forwarded buffer.
2842 (insert message-forward-start-separator)
2843 (setq art-beg (point))
2844 (insert-buffer-substring cur)
2845 (goto-char (point-max))
2846 (insert message-forward-end-separator)
2847 (set-text-properties (point-min) (point-max) nil)
2848 ;; Remove all unwanted headers.
2850 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
2853 (goto-char (point-min))
2854 (message-remove-header message-included-forward-headers t nil t)
2856 (message-position-point)))
2859 (defun message-resend (address)
2860 "Resend the current article to ADDRESS."
2861 (interactive "sResend message to: ")
2862 (message "Resending message to %s..." address)
2864 (let ((cur (current-buffer))
2866 ;; We first set up a normal mail buffer.
2867 (set-buffer (get-buffer-create " *message resend*"))
2868 (buffer-disable-undo (current-buffer))
2870 (message-setup `((To . ,address)))
2871 ;; Insert our usual headers.
2872 (message-generate-headers '(From Date To))
2873 (message-narrow-to-headers)
2874 ;; Rename them all to "Resent-*".
2875 (while (re-search-forward "^[A-Za-z]" nil t)
2880 (delete-region (point) (point-max))
2882 ;; Insert the message to be resent.
2883 (insert-buffer-substring cur)
2884 (goto-char (point-min))
2885 (search-forward "\n\n")
2888 (narrow-to-region beg (point))
2889 (message-remove-header message-ignored-resent-headers t)
2890 (goto-char (point-max)))
2891 (insert mail-header-separator)
2892 ;; Rename all old ("Also-")Resent headers.
2893 (while (re-search-backward "^\\(Also-\\)?Resent-" beg t)
2898 (kill-buffer (current-buffer)))
2899 (message "Resending message to %s...done" address)))
2902 (defun message-bounce ()
2903 "Re-mail the current message.
2904 This only makes sense if the current message is a bounce message than
2905 contains some mail you have written which has been bounced back to
2908 (let ((cur (current-buffer))
2910 (message-pop-to-buffer (message-buffer-name "bounce"))
2911 (insert-buffer-substring cur)
2913 (message-narrow-to-head)
2914 (if (and (message-fetch-field "Mime-Version")
2915 (setq boundary (message-fetch-field "Content-Type")))
2916 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary)
2917 (setq boundary (concat (match-string 1 boundary) " *\n"
2918 "Content-Type: message/rfc822"))
2919 (setq boundary nil)))
2921 (goto-char (point-min))
2922 (search-forward "\n\n" nil t)
2924 (re-search-forward boundary nil t)
2926 (and (re-search-forward message-unsent-separator nil t)
2928 (and (search-forward "\n\n" nil t)
2929 (re-search-forward "^Return-Path:.*\n" nil t)))
2930 ;; We remove everything before the bounced mail.
2933 (if (re-search-forward "^[^ \n\t]+:" nil t)
2937 (message-narrow-to-head)
2938 (message-remove-header message-ignored-bounced-headers t)
2939 (goto-char (point-max))
2940 (insert mail-header-separator))
2941 (message-position-point)))
2944 ;;; Interactive entry points for new message buffers.
2948 (defun message-mail-other-window (&optional to subject)
2949 "Like `message-mail' command, but display mail buffer in another window."
2951 (let ((pop-up-windows t)
2952 (special-display-buffer-names nil)
2953 (special-display-regexps nil)
2954 (same-window-buffer-names nil)
2955 (same-window-regexps nil))
2956 (message-pop-to-buffer (message-buffer-name "mail" to)))
2957 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))))
2960 (defun message-mail-other-frame (&optional to subject)
2961 "Like `message-mail' command, but display mail buffer in another frame."
2963 (let ((pop-up-frames t)
2964 (special-display-buffer-names nil)
2965 (special-display-regexps nil)
2966 (same-window-buffer-names nil)
2967 (same-window-regexps nil))
2968 (message-pop-to-buffer (message-buffer-name "mail" to)))
2969 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))))
2972 (defun message-news-other-window (&optional newsgroups subject)
2973 "Start editing a news article to be sent."
2975 (let ((pop-up-windows t)
2976 (special-display-buffer-names nil)
2977 (special-display-regexps nil)
2978 (same-window-buffer-names nil)
2979 (same-window-regexps nil))
2980 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
2981 (message-setup `((Newsgroups . ,(or newsgroups ""))
2982 (Subject . ,(or subject "")))))
2985 (defun message-news-other-frame (&optional newsgroups subject)
2986 "Start editing a news article to be sent."
2988 (let ((pop-up-frames t)
2989 (special-display-buffer-names nil)
2990 (special-display-regexps nil)
2991 (same-window-buffer-names nil)
2992 (same-window-regexps nil))
2993 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
2994 (message-setup `((Newsgroups . ,(or newsgroups ""))
2995 (Subject . ,(or subject "")))))
2999 ;; This code should be moved to underline.el (from which it is stolen).
3002 (defun bold-region (start end)
3003 "Bold all nonblank characters in the region.
3004 Works by overstriking characters.
3005 Called from program, takes two arguments START and END
3006 which specify the range to operate on."
3009 (let ((end1 (make-marker)))
3010 (move-marker end1 (max start end))
3011 (goto-char (min start end))
3012 (while (< (point) end1)
3013 (or (looking-at "[_\^@- ]")
3014 (insert (following-char) "\b"))
3015 (forward-char 1)))))
3018 (defun unbold-region (start end)
3019 "Remove all boldness (overstruck characters) in the region.
3020 Called from program, takes two arguments START and END
3021 which specify the range to operate on."
3024 (let ((end1 (make-marker)))
3025 (move-marker end1 (max start end))
3026 (goto-char (min start end))
3027 (while (re-search-forward "\b" end1 t)
3028 (if (eq (following-char) (char-after (- (point) 2)))
3029 (delete-char -2))))))
3031 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
3033 ;; Support for toolbar
3034 (when (string-match "XEmacs\\|Lucid" emacs-version)
3035 (require 'messagexmas))
3037 ;;; Group name completion.
3039 (defvar message-newgroups-header-regexp
3040 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\):"
3041 "Regexp that match headers that lists groups.")
3043 (defun message-tab ()
3044 "Expand group names in Newsgroups and Followup-To headers.
3045 Do a `tab-to-tab-stop' if not in those headers."
3047 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp))
3048 (mail-abbrev-in-expansion-header-p))
3049 (message-expand-group)
3052 (defvar gnus-active-hashtb)
3053 (defun message-expand-group ()
3054 (let* ((b (save-excursion (skip-chars-backward "^, :\t\n") (point)))
3055 (completion-ignore-case t)
3056 (string (buffer-substring b (point)))
3057 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
3058 (completions (all-completions string hashtb))
3059 (cur (current-buffer))
3061 (delete-region b (point))
3063 ((= (length completions) 1)
3064 (if (string= (car completions) string)
3067 (message "Only matching group"))
3068 (insert (car completions))))
3069 ((and (setq comp (try-completion string hashtb))
3070 (not (string= comp string)))
3075 (message "No matching groups")
3076 (pop-to-buffer "*Completions*")
3077 (buffer-disable-undo (current-buffer))
3078 (let ((buffer-read-only nil))
3080 (let ((standard-output (current-buffer)))
3081 (display-completion-list (sort completions 'string<)))
3082 (goto-char (point-min))
3083 (pop-to-buffer cur)))))))
3087 (defun message-talkative-question (ask question show &rest text)
3088 "Call FUNCTION with argument QUESTION, displaying the rest of the arguments in a temporary buffer if SHOW.
3089 The following arguments may contain lists of values."
3091 (setq text (message-flatten-list text)))
3092 (save-window-excursion
3094 (with-output-to-temp-buffer " *MESSAGE information message*"
3095 (set-buffer " *MESSAGE information message*")
3096 (mapcar 'princ text)
3097 (goto-char (point-min))))
3098 (funcall ask question))
3099 (funcall ask question)))
3101 (defun message-flatten-list (&rest list)
3102 (message-flatten-list-1 list))
3104 (defun message-flatten-list-1 (list)
3106 (apply 'append (mapcar 'message-flatten-list-1 list)))
3110 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
3111 "Create and return a buffer with a name based on NAME using generate-new-buffer.
3112 Then clone the local variables and values from the old buffer to the
3113 new one, cloning only the locals having a substring matching the
3115 (let ((oldlocals (buffer-local-variables)))
3117 (set-buffer (generate-new-buffer name))
3118 (mapcar (lambda (dude)
3119 (when (and (car dude)
3121 (string-match varstr (symbol-name (car dude)))))
3123 (set (make-local-variable (car dude))
3129 (run-hooks 'message-load-hook)
3133 ;;; message.el ends here