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
))
44 (defvar message-directory
"~/Mail/"
45 "*Directory from which all other mail file variables are derived.")
47 (defvar message-max-buffers
10
48 "*How many buffers to keep before starting to kill them off.")
50 (defvar message-send-rename-function nil
51 "Function called to rename the buffer after sending it.")
54 (defvar message-fcc-handler-function
'rmail-output
55 "*A function called to save outgoing articles.
56 This function will be called with the name of the file to store the
57 article in. The default function is `rmail-output' which saves in Unix
61 (defvar message-courtesy-message
62 "The following message is a courtesy copy of an article\nthat has been posted as well.\n\n"
63 "*This is inserted at the start of a mailed copy of a posted message.
64 If this variable is nil, no such courtesy message will be added.")
67 (defvar message-ignored-bounced-headers
"^\\(Received\\|Return-Path\\):"
68 "*Regexp that matches headers to be removed in resent bounced mail.")
71 (defvar message-from-style
'default
72 "*Specifies how \"From\" headers look.
74 If `nil', they contain just the return address like:
76 If `parens', they look like:
77 king@grassland.com (Elvis Parsley)
78 If `angles', they look like:
79 Elvis Parsley <king@grassland.com>
81 Otherwise, most addresses look like `angles', but they look like
82 `parens' if `angles' would need quoting and `parens' would not.")
85 (defvar message-syntax-checks nil
86 "Controls what syntax checks should not be performed on outgoing posts.
87 To disable checking of long signatures, for instance, add
88 `(signature . disabled)' to this list.
90 Don't touch this variable unless you really know what you're doing.
92 Checks include subject-cmsg multiple-headers sendsys message-id from
93 long-lines control-chars size new-text redirected-followup signature
94 approved sender empty empty-headers message-id from subject.")
97 (defvar message-required-news-headers
98 '(From Newsgroups Subject Date Message-ID
99 (optional . Organization
) Lines
100 (optional . X-Newsreader
))
101 "*Headers to be generated or prompted for when posting an article.
102 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
103 Message-ID. Organization, Lines, In-Reply-To, Expires, and
104 X-Newsreader are optional. If don't you want message to insert some
105 header, remove it from this list.")
108 (defvar message-required-mail-headers
109 '(From Subject Date
(optional . In-Reply-To
) Message-ID Lines
110 (optional . X-Mailer
))
111 "*Headers to be generated or prompted for when mailing a message.
112 RFC822 required that From, Date, To, Subject and Message-ID be
113 included. Organization, Lines and X-Mailer are optional.")
116 (defvar message-deletable-headers
'(Message-ID Date
)
117 "*Headers to be deleted if they already exist and were generated by message previously.")
120 (defvar message-ignored-news-headers
121 "^NNTP-Posting-Host:\\|^Xref:\\|^Bcc:\\|^Gcc:\\|^Fcc:"
122 "*Regexp of headers to be removed unconditionally before posting.")
125 (defvar message-ignored-mail-headers
"^Gcc:\\|^Fcc:"
126 "*Regexp of headers to be removed unconditionally before mailing.")
129 (defvar message-ignored-supersedes-headers
"^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|Return-Path:\\|^Supersedes:"
130 "*Header lines matching this regexp will be deleted before posting.
131 It's best to delete old Path and Date headers before posting to avoid
135 (defvar message-signature-separator
"^-- *$"
136 "Regexp matching the signature separator.")
139 (defvar message-interactive nil
140 "Non-nil means when sending a message wait for and display errors.
141 nil means let mailer mail back a message to report errors.")
144 (defvar message-generate-new-buffers t
145 "*Non-nil means that a new message buffer will be created whenever `mail-setup' is called.
146 If this is a function, call that function with three parameters: The type,
147 the to address and the group name. (Any of these may be nil.) The function
148 should return the new buffer name.")
151 (defvar message-kill-buffer-on-exit nil
152 "*Non-nil means that the message buffer will be killed after sending a message.")
154 (defvar gnus-local-organization
)
155 (defvar message-user-organization
156 (or (and (boundp 'gnus-local-organization
)
157 gnus-local-organization
)
158 (getenv "ORGANIZATION")
160 "*String to be used as an Organization header.
161 If t, use `message-user-organization-file'.")
164 (defvar message-user-organization-file
"/usr/lib/news/organization"
165 "*Local news organization file.")
168 (defvar message-autosave-directory
169 (concat (file-name-as-directory message-directory
) "drafts/")
170 "*Directory where message autosaves buffers.
171 If nil, message won't autosave.")
173 (defvar message-forward-start-separator
174 "------- Start of forwarded message -------\n"
175 "*Delimiter inserted before forwarded messages.")
177 (defvar message-forward-end-separator
178 "------- End of forwarded message -------\n"
179 "*Delimiter inserted after forwarded messages.")
182 (defvar message-signature-before-forwarded-message t
183 "*If non-nil, put the signature before any included forwarded message.")
186 (defvar message-included-forward-headers
187 "^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:"
188 "*Regexp matching headers to be included in forwarded messages.")
191 (defvar message-ignored-resent-headers
"^Return-receipt"
192 "*All headers that match this regexp will be deleted when resending a message.")
195 (defvar message-ignored-cited-headers
"."
196 "Delete these headers from the messages you yank.")
198 ;; Useful to set in site-init.el
200 (defvar message-send-mail-function
'message-send-mail-with-sendmail
201 "Function to call to send the current buffer as mail.
202 The headers should be delimited by a line whose contents match the
203 variable `mail-header-separator'.
205 Legal values include `message-send-mail-with-mh' and
206 `message-send-mail-with-sendmail', which is the default.")
209 (defvar message-send-news-function
'message-send-news
210 "Function to call to send the current buffer as news.
211 The headers should be delimited by a line whose contents match the
212 variable `mail-header-separator'.")
215 (defvar message-reply-to-function nil
216 "Function that should return a list of headers.
217 This function should pick out addresses from the To, Cc, and From headers
218 and respond with new To and Cc headers.")
221 (defvar message-wide-reply-to-function nil
222 "Function that should return a list of headers.
223 This function should pick out addresses from the To, Cc, and From headers
224 and respond with new To and Cc headers.")
227 (defvar message-followup-to-function nil
228 "Function that should return a list of headers.
229 This function should pick out addresses from the To, Cc, and From headers
230 and respond with new To and Cc headers.")
233 (defvar message-use-followup-to
'ask
234 "*Specifies what to do with Followup-To header.
235 If nil, ignore the header. If it is t, use its value, but query before
236 using the \"poster\" value. If it is the symbol `ask', query the user
237 whether to ignore the \"poster\" value. If it is the symbol `use',
238 always use the value.")
240 (defvar gnus-post-method
)
241 (defvar gnus-select-method
)
243 (defvar message-post-method
244 (cond ((and (boundp 'gnus-post-method
)
247 ((boundp 'gnus-select-method
)
250 "Method used to post news.")
253 (defvar message-generate-headers-first nil
254 "*If non-nil, generate all possible headers before composing.")
256 (defvar message-setup-hook nil
257 "Normal hook, run each time a new outgoing message is initialized.
258 The function `message-setup' runs this hook.")
260 (defvar message-signature-setup-hook nil
261 "Normal hook, run each time a new outgoing message is initialized.
262 It is run after the headers have been inserted and before
263 the signature is inserted.")
265 (defvar message-mode-hook nil
266 "Hook run in message mode buffers.")
268 (defvar message-header-hook nil
269 "Hook run in a message mode buffer narrowed to the headers.")
271 (defvar message-header-setup-hook nil
272 "Hook called narrowed to the headers when setting up a message buffer.")
275 (defvar message-citation-line-function
'message-insert-citation-line
276 "*Function called to insert the \"Whomever writes:\" line.")
279 (defvar message-yank-prefix
"> "
280 "*Prefix inserted on the lines of yanked messages.
281 nil means use indentation.")
283 (defvar message-indentation-spaces
3
284 "*Number of spaces to insert at the beginning of each cited line.
285 Used by `message-yank-original' via `message-yank-cite'.")
288 (defvar message-cite-function
'message-cite-original
289 "*Function for citing an original message.")
292 (defvar message-indent-citation-function
'message-indent-citation
293 "*Function for modifying a citation just inserted in the mail buffer.
294 This can also be a list of functions. Each function can find the
295 citation between (point) and (mark t). And each function should leave
296 point and mark around the citation text as modified.")
298 (defvar message-abbrevs-loaded nil
)
301 (defvar message-signature t
302 "*String to be inserted at the end of the message buffer.
303 If t, the `message-signature-file' file will be inserted instead.
304 If a function, the result from the function will be used instead.
305 If a form, the result from the form will be used instead.")
308 (defvar message-signature-file
"~/.signature"
309 "*File containing the text inserted at end of message. buffer.")
311 (defvar message-distribution-function nil
312 "*Function called to return a Distribution header.")
314 (defvar message-expires
14
315 "*Number of days before your article expires.")
317 (defvar message-user-path nil
318 "If nil, use the NNTP server name in the Path header.
319 If stringp, use this; if non-nil, use no host name (user name only).")
321 (defvar message-reply-buffer nil
)
322 (defvar message-reply-headers nil
)
323 (defvar message-newsreader nil
)
324 (defvar message-mailer nil
)
325 (defvar message-sent-message-via nil
)
326 (defvar message-checksum nil
)
327 (defvar message-send-actions nil
328 "A list of actions to be performed upon successful sending of a message.")
329 (defvar message-exit-actions nil
330 "A list of actions to be performed upon exiting after sending a message.")
331 (defvar message-kill-actions nil
332 "A list of actions to be performed before killing a message buffer.")
333 (defvar message-postpone-actions nil
334 "A list of actions to be performed after postponing a message.")
337 (defvar message-default-headers nil
338 "*A string containing header lines to be inserted in outgoing messages.
339 It is inserted before you edit the message, so you can edit or delete
343 (defvar message-default-mail-headers nil
344 "*A string of header lines to be inserted in outgoing mails.")
347 (defvar message-default-news-headers nil
348 "*A string of header lines to be inserted in outgoing news articles.")
350 ;; Note: could use /usr/ucb/mail instead of sendmail;
351 ;; options -t, and -v if not interactive.
352 (defvar message-mailer-swallows-blank-line
353 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
354 system-configuration
)
355 (file-readable-p "/etc/sendmail.cf")
356 (let ((buffer (get-buffer-create " *temp*")))
360 (insert-file-contents "/etc/sendmail.cf")
361 (goto-char (point-min))
362 (let ((case-fold-search nil
))
363 (re-search-forward "^OR\\>" nil t
)))
364 (kill-buffer buffer
))))
365 ;; According to RFC822, "The field-name must be composed of printable
366 ;; ASCII characters (i.e. characters that have decimal values between
367 ;; 33 and 126, except colon)", i.e. any chars except ctl chars,
369 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
370 "Set this non-nil if the system's mailer runs the header and body together.
371 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
372 The value should be an expression to test whether the problem will
375 (defvar message-mode-syntax-table
376 (let ((table (copy-syntax-table text-mode-syntax-table
)))
377 (modify-syntax-entry ?%
". " table
)
379 "Syntax table used while in Message mode.")
381 (defvar message-font-lock-keywords
382 (let* ((cite-prefix "A-Za-z") (cite-suffix (concat cite-prefix
"0-9_.@-")))
383 (list '("^To:" . font-lock-function-name-face
)
384 '("^[GBF]?[Cc][Cc]:\\|^Reply-To:" . font-lock-keyword-face
)
385 '("^\\(Subject:\\)[ \t]*\\(.+\\)?"
386 (1 font-lock-comment-face
) (2 font-lock-type-face nil t
))
387 (list (concat "^\\(" (regexp-quote mail-header-separator
) "\\)$")
388 1 'font-lock-comment-face
)
389 (cons (concat "^[ \t]*"
390 "\\([" cite-prefix
"]+[" cite-suffix
"]*\\)?"
392 'font-lock-reference-face
)
393 '("^\\(X-[A-Za-z0-9-]+\\|In-reply-to\\):.*"
394 . font-lock-string-face
)))
395 "Additional expressions to highlight in Message mode.")
397 (defvar message-face-alist
398 '((bold . bold-region
)
399 (underline . underline-region
)
400 (default .
(lambda (b e
)
402 (ununderline-region b e
))))
403 "Alist of mail and news faces for facemenu.
404 The cdr of ech entry is a function for applying the face to a region.")
406 (defvar message-send-hook nil
407 "Hook run before sending messages.")
409 (defvar message-sent-hook nil
410 "Hook run after sending messages.")
412 ;;; Internal variables.
414 (defvar message-buffer-list nil
)
416 ;;; Regexp matching the delimiter of messages in UNIX mail format
417 ;;; (UNIX From lines), minus the initial ^.
418 (defvar message-unix-mail-delimiter
419 (let ((time-zone-regexp
420 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
421 "\\|[-+]?[0-9][0-9][0-9][0-9]"
427 ;; Username, perhaps with a quoted section that can contain spaces.
430 "\\(\\|\".*\"[^ \n]*\\)"
434 ;; The time the message was sent.
435 "\\([^ \n]*\\) *" ; day of the week
436 "\\([^ ]*\\) *" ; month
437 "\\([0-9]*\\) *" ; day of month
438 "\\([0-9:]*\\) *" ; time of day
440 ;; Perhaps a time zone, specified by an abbreviation, or by a
445 " [0-9][0-9]\\([0-9]*\\) *"
447 ;; On some systems the time zone can appear after the year, too.
451 "\\(remote from .*\\)?"
455 (defvar message-unsent-separator
456 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
457 "^ *---+ +Returned message +---+ *$\\|"
458 "^Start of returned message$\\|"
459 "^ *---+ +Original message +---+ *$\\|"
460 "^ *--+ +begin message +--+ *$\\|"
461 "^ *---+ +Original message follows +---+ *$\\|"
462 "^|? *---+ +Message text follows: +---+ *|?$")
463 "A regexp that matches the separator before the text of a failed message.")
465 (defvar message-header-format-alist
467 (To . message-fill-address
)
468 (Cc . message-fill-address
)
479 (References . message-fill-header
)
482 "Alist used for formatting headers.")
485 (autoload 'message-setup-toolbar
"messagexmas")
486 (autoload 'mh-send-letter
"mh-comp"))
491 ;;; Utility functions.
494 (defun message-point-at-bol ()
495 "Return point at the beginning of the line."
502 (defun message-point-at-eol ()
503 "Return point at the end of the line."
510 ;; Delete the current line (and the next N lines.);
511 (defmacro message-delete-line
(&optional n
)
512 `(delete-region (progn (beginning-of-line) (point))
513 (progn (forward-line ,(or n
1)) (point))))
515 (defun message-tokenize-header (header &optional separator
)
516 "Split HEADER into a list of header elements.
517 \",\" is used as the separator."
518 (let ((regexp (format "[%s]+" (or separator
",")))
522 (message-set-work-buffer)
524 (goto-char (point-min))
527 (cond ((and (> (point) beg
)
529 (and (looking-at regexp
)
531 (push (buffer-substring beg
(point)) elems
)
532 (setq beg
(match-end 0)))
533 ((= (following-char) ?
\")
534 (setq quoted
(not quoted
)))))
537 (defun message-fetch-field (header)
538 "The same as `mail-fetch-field', only remove all newlines."
539 (let ((value (mail-fetch-field header
)))
541 (nnheader-replace-chars-in-string value ?
\n ?
))))
543 (defun message-fetch-reply-field (header)
544 "Fetch FIELD from the message we're replying to."
545 (when (and message-reply-buffer
546 (buffer-name message-reply-buffer
))
548 (set-buffer message-reply-buffer
)
549 (message-fetch-field header
))))
551 (defun message-set-work-buffer ()
552 (if (get-buffer " *message work*")
554 (set-buffer " *message work*")
556 (set-buffer (get-buffer-create " *message work*"))
557 (kill-all-local-variables)
558 (buffer-disable-undo (current-buffer))))
560 (defun message-functionp (form)
561 "Return non-nil if FORM is funcallable."
562 (or (and (symbolp form
) (fboundp form
))
563 (and (listp form
) (eq (car form
) 'lambda
))))
565 (defun message-strip-subject-re (subject)
566 "Remove \"Re:\" from subject lines."
567 (if (string-match "^[Rr][Ee]: *" subject
)
568 (substring subject
(match-end 0))
571 (defun message-remove-header (header &optional is-regexp first reverse
)
572 "Remove HEADER in the narrowed buffer.
573 If REGEXP, HEADER is a regular expression.
574 If FIRST, only remove the first instance of the header.
575 Return the number of headers removed."
576 (goto-char (point-min))
577 (let ((regexp (if is-regexp header
(concat "^" header
":")))
581 (while (and (not (eobp))
584 (not (looking-at regexp
))
592 ;; There might be a continuation header, so we have to search
593 ;; until we find a new non-continuation line.
596 (if (re-search-forward "^[^ \t]" nil t
)
597 (goto-char (match-beginning 0))
600 (if (re-search-forward "^[^ \t]" nil t
)
601 (goto-char (match-beginning 0))
605 (defun message-narrow-to-headers ()
606 "Narrow the buffer to the head of the message."
609 (goto-char (point-min))
610 (if (re-search-forward
611 (concat "^" (regexp-quote mail-header-separator
) "\n") nil t
)
614 (goto-char (point-min)))
616 (defun message-narrow-to-head ()
617 "Narrow the buffer to the head of the message."
620 (goto-char (point-min))
621 (if (search-forward "\n\n" nil
1)
624 (goto-char (point-min)))
626 (defun message-news-p ()
627 "Say whether the current buffer contains a news message."
630 (message-narrow-to-headers)
631 (message-fetch-field "newsgroups"))))
633 (defun message-mail-p ()
634 "Say whether the current buffer contains a mail message."
637 (message-narrow-to-headers)
638 (or (message-fetch-field "to")
639 (message-fetch-field "cc")
640 (message-fetch-field "bcc")))))
642 (defun message-next-header ()
643 "Go to the beginning of the next header."
645 (or (eobp) (forward-char 1))
646 (not (if (re-search-forward "^[^ \t]" nil t
)
648 (goto-char (point-max)))))
650 (defun message-sort-headers-1 ()
651 "Sort the buffer as headers using `message-rank' text props."
652 (goto-char (point-min))
654 nil
'message-next-header
656 (message-next-header)
660 (or (get-text-property (point) 'message-rank
)
663 (defun message-sort-headers ()
664 "Sort the headers of the current message according to `message-header-format-alist'."
668 (let ((max (1+ (length message-header-format-alist
)))
670 (message-narrow-to-headers)
671 (while (re-search-forward "^[^ \n]+:" nil t
)
673 (match-beginning 0) (1+ (match-beginning 0))
675 (if (setq rank
(length (memq (assq (intern (buffer-substring
678 message-header-format-alist
)
679 message-header-format-alist
)))
682 (message-sort-headers-1))))
692 (defvar message-mode-map nil
)
694 (unless message-mode-map
695 (setq message-mode-map
(copy-keymap text-mode-map
))
696 (define-key message-mode-map
"\C-c?" 'describe-mode
)
698 (define-key message-mode-map
"\C-c\C-f\C-t" 'message-goto-to
)
699 (define-key message-mode-map
"\C-c\C-f\C-b" 'message-goto-bcc
)
700 (define-key message-mode-map
"\C-c\C-f\C-w" 'message-goto-fcc
)
701 (define-key message-mode-map
"\C-c\C-f\C-c" 'message-goto-cc
)
702 (define-key message-mode-map
"\C-c\C-f\C-s" 'message-goto-subject
)
703 (define-key message-mode-map
"\C-c\C-f\C-r" 'message-goto-reply-to
)
704 (define-key message-mode-map
"\C-c\C-f\C-n" 'message-goto-newsgroups
)
705 (define-key message-mode-map
"\C-c\C-f\C-d" 'message-goto-distribution
)
706 (define-key message-mode-map
"\C-c\C-f\C-f" 'message-goto-followup-to
)
707 (define-key message-mode-map
"\C-c\C-f\C-k" 'message-goto-keywords
)
708 (define-key message-mode-map
"\C-c\C-f\C-u" 'message-goto-summary
)
709 (define-key message-mode-map
"\C-c\C-b" 'message-goto-body
)
710 (define-key message-mode-map
"\C-c\C-i" 'message-goto-signature
)
712 (define-key message-mode-map
"\C-c\C-t" 'message-insert-to
)
713 (define-key message-mode-map
"\C-c\C-n" 'message-insert-newsgroups
)
715 (define-key message-mode-map
"\C-c\C-y" 'message-yank-original
)
716 (define-key message-mode-map
"\C-c\C-q" 'message-fill-yanked-message
)
717 (define-key message-mode-map
"\C-c\C-w" 'message-insert-signature
)
718 (define-key message-mode-map
"\C-c\C-r" 'message-caesar-buffer-body
)
719 (define-key message-mode-map
"\C-c\C-o" 'message-sort-headers
)
720 (define-key message-mode-map
"\C-c\M-r" 'message-rename-buffer
)
722 (define-key message-mode-map
"\C-c\C-c" 'message-send-and-exit
)
723 (define-key message-mode-map
"\C-c\C-s" 'message-send
)
724 (define-key message-mode-map
"\C-c\C-k" 'message-kill-buffer
)
725 (define-key message-mode-map
"\C-c\C-d" 'message-dont-send
)
727 (define-key message-mode-map
"\t" 'message-tab
))
729 (easy-menu-define message-mode-menu message-mode-map
734 ["To" message-goto-to t
]
735 ["Subject" message-goto-subject t
]
736 ["Cc" message-goto-cc t
]
737 ["Reply-to" message-goto-reply-to t
]
738 ["Summary" message-goto-summary t
]
739 ["Keywords" message-goto-keywords t
]
740 ["Newsgroups" message-goto-newsgroups t
]
741 ["Followup-To" message-goto-followup-to t
]
742 ["Distribution" message-goto-distribution t
]
743 ["Body" message-goto-body t
]
744 ["Signature" message-goto-signature t
]
746 "Miscellaneous Commands:"
748 ["Sort Headers" message-sort-headers t
]
749 ["Yank Original" message-yank-original t
]
750 ["Fill Yanked Message" message-fill-yanked-message t
]
751 ["Insert Signature" message-insert-signature t
]
752 ["Caesar (rot13) Message" message-caesar-buffer-body t
]
753 ["Rename buffer" message-rename-buffer t
]
754 ["Spellcheck" ispell-message t
]
756 ["Send Message" message-send-and-exit t
]
757 ["Abort Message" message-dont-send t
]))
759 (defvar facemenu-add-face-function
)
760 (defvar facemenu-remove-face-function
)
763 (defun message-mode ()
764 "Major mode for editing mail and news to be sent.
765 Like Text Mode but with these additional commands:
766 C-c C-s message-send (send the message) C-c C-c message-send-and-exit
767 C-c C-f move to a header field (and create it if there isn't):
768 C-c C-f C-t move to To C-c C-f C-s move to Subject
769 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
770 C-c C-f C-f move to Fcc C-c C-f C-r move to Reply-To
771 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
772 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
773 C-c C-f C-o move to Followup-To
774 C-c C-t message-insert-to (add a To header to a news followup)
775 C-c C-n message-insert-newsgroups (add a Newsgroup header to a news reply)
776 C-c C-b message-goto-body (move to beginning of message text).
777 C-c C-i message-goto-signature (move to the beginning of the signature).
778 C-c C-w message-insert-signature (insert `message-signature-file' file).
779 C-c C-y message-yank-original (insert current message, if any).
780 C-c C-q message-fill-yanked-message (fill what was yanked).
781 C-c C-r message-ceasar-buffer-body (rot13 the message body)."
783 (kill-all-local-variables)
784 (make-local-variable 'message-reply-buffer
)
785 (setq message-reply-buffer nil
)
786 (make-local-variable 'message-send-actions
)
787 (make-local-variable 'message-exit-actions
)
788 (make-local-variable 'message-kill-actions
)
789 (make-local-variable 'message-postpone-actions
)
790 (set-syntax-table message-mode-syntax-table
)
791 (use-local-map message-mode-map
)
792 (setq local-abbrev-table text-mode-abbrev-table
)
793 (setq major-mode
'message-mode
)
794 (setq mode-name
"Message")
795 (setq buffer-offer-save t
)
796 (make-local-variable 'font-lock-defaults
)
797 (setq font-lock-defaults
'(message-font-lock-keywords t
))
798 (make-local-variable 'facemenu-add-face-function
)
799 (make-local-variable 'facemenu-remove-face-function
)
800 (setq facemenu-add-face-function
802 (let ((face-fun (cdr (assq face message-face-alist
))))
804 (funcall face-fun
(point) end
)
805 (error "Face %s not configured for %s mode" face mode-name
)))
807 facemenu-remove-face-function t
)
808 (make-local-variable 'paragraph-separate
)
809 (make-local-variable 'paragraph-start
)
810 (setq paragraph-start
(concat (regexp-quote mail-header-separator
)
811 "$\\|[ \t]*[-_][-_][-_]+$\\|"
814 (setq paragraph-separate
(concat (regexp-quote mail-header-separator
)
815 "$\\|[ \t]*[-_][-_][-_]+$\\|"
818 (make-local-variable 'message-reply-headers
)
819 (setq message-reply-headers nil
)
820 (make-local-variable 'message-newsreader
)
821 (make-local-variable 'message-mailer
)
822 (make-local-variable 'message-post-method
)
823 (make-local-variable 'message-sent-message-via
)
824 (setq message-sent-message-via nil
)
825 (make-local-variable 'message-checksum
)
826 (setq message-checksum nil
)
827 (when (fboundp 'mail-hist-define-keys
)
828 (mail-hist-define-keys))
829 (when (string-match "XEmacs\\|Lucid" emacs-version
)
830 (message-setup-toolbar))
831 (easy-menu-add message-mode-menu message-mode-map
)
832 ;; Allow mail alias things.
833 (if (fboundp 'mail-abbrevs-setup
)
835 (funcall (intern "mail-aliases-setup")))
836 (run-hooks 'text-mode-hook
'message-mode-hook
))
841 ;;; Message mode commands
844 ;;; Movement commands
846 (defun message-goto-to ()
847 "Move point to the To header."
849 (message-position-on-field "To"))
851 (defun message-goto-subject ()
852 "Move point to the Subject header."
854 (message-position-on-field "Subject"))
856 (defun message-goto-cc ()
857 "Move point to the Cc header."
859 (message-position-on-field "Cc" "To"))
861 (defun message-goto-bcc ()
862 "Move point to the Bcc header."
864 (message-position-on-field "Bcc" "Cc" "To"))
866 (defun message-goto-fcc ()
867 "Move point to the Fcc header."
869 (message-position-on-field "Fcc" "To" "Newsgroups"))
871 (defun message-goto-reply-to ()
872 "Move point to the Reply-To header."
874 (message-position-on-field "Reply-To" "Subject"))
876 (defun message-goto-newsgroups ()
877 "Move point to the Newsgroups header."
879 (message-position-on-field "Newsgroups"))
881 (defun message-goto-distribution ()
882 "Move point to the Distribution header."
884 (message-position-on-field "Distribution"))
886 (defun message-goto-followup-to ()
887 "Move point to the Followup-To header."
889 (message-position-on-field "Followup-To" "Newsgroups"))
891 (defun message-goto-keywords ()
892 "Move point to the Keywords header."
894 (message-position-on-field "Keywords" "Subject"))
896 (defun message-goto-summary ()
897 "Move point to the Summary header."
899 (message-position-on-field "Summary" "Subject"))
901 (defun message-goto-body ()
902 "Move point to the beginning of the message body."
904 (if (looking-at "[ \t]*\n") (expand-abbrev))
905 (goto-char (point-min))
906 (search-forward (concat "\n" mail-header-separator
"\n") nil t
))
908 (defun message-goto-signature ()
909 "Move point to the beginning of the message signature."
911 (goto-char (point-min))
912 (or (re-search-forward message-signature-separator nil t
)
913 (goto-char (point-max))))
917 (defun message-insert-to ()
918 "Insert a To header that points to the author of the article being replied to."
920 (when (and (message-position-on-field "To")
921 (mail-fetch-field "to")
922 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
924 (insert (or (message-fetch-reply-field "reply-to")
925 (message-fetch-reply-field "from") "")))
927 (defun message-insert-newsgroups ()
928 "Insert the Newsgroups header from the article being replied to."
930 (when (and (message-position-on-field "Newsgroups")
931 (mail-fetch-field "newsgroups")
932 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
934 (insert (or (message-fetch-reply-field "newsgroups") "")))
940 (defun message-insert-signature (&optional force
)
941 "Insert a signature. See documentation for the `message-signature' variable."
942 (interactive (list 0))
944 (cond ((and (null message-signature
)
947 (goto-char (point-max))
948 (not (re-search-backward
949 message-signature-separator nil t
))))
950 ((and (null message-signature
)
953 ((message-functionp message-signature
)
954 (funcall message-signature
))
955 ((listp message-signature
)
956 (eval message-signature
))
957 (t message-signature
)))
959 (cond ((stringp signature
)
961 ((and (eq t signature
)
962 message-signature-file
963 (file-exists-p message-signature-file
))
966 ; ;; Remove blank lines at the end of the message.
967 (goto-char (point-max))
968 ; (skip-chars-backward " \t\n")
969 ; (delete-region (point) (point-max))
970 ;; Insert the signature.
975 (insert-file-contents message-signature-file
)
977 (goto-char (point-max))
978 (or (bolp) (insert "\n")))))
980 (defvar message-caesar-translation-table nil
)
982 (defun message-caesar-region (b e
&optional n
)
983 "Caesar rotation of region by N, default 13, for decrypting netnews."
986 (min (point) (or (mark t
) (point)))
987 (max (point) (or (mark t
) (point)))
988 (when current-prefix-arg
989 (prefix-numeric-value current-prefix-arg
))))
991 (setq n
(if (numberp n
) (mod n
26) 13)) ;canonize N
992 (unless (or (zerop n
) ; no action needed for a rot of 0
993 (= b e
)) ; no region to rotate
994 ;; We build the table, if necessary.
995 (when (or (not message-caesar-translation-table
)
996 (/= (aref message-caesar-translation-table ?a
) (+ ?a n
)))
998 (table (make-string 256 0)))
999 (while (< (incf i
) 256)
1003 (substring table
0 ?A
)
1004 (substring table
(+ ?A n
) (+ ?A n
(- 26 n
)))
1005 (substring table ?A
(+ ?A n
))
1006 (substring table
(+ ?A
26) ?a
)
1007 (substring table
(+ ?a n
) (+ ?a n
(- 26 n
)))
1008 (substring table ?a
(+ ?a n
))
1009 (substring table
(+ ?a
26) 255)))
1010 (setq message-caesar-translation-table table
)))
1011 ;; Then we translate the region. Do it this way to retain
1014 (subst-char-in-region
1015 b
(1+ b
) (char-after b
)
1016 (aref message-caesar-translation-table
(char-after b
)))
1019 (defun message-caesar-buffer-body (&optional rotnum
)
1020 "Caesar rotates all letters in the current buffer by 13 places.
1021 Used to encode/decode possibly offensive messages (commonly in net.jokes).
1022 With prefix arg, specifies the number of places to rotate each letter forward.
1023 Mail and USENET news headers are not rotated."
1024 (interactive (if current-prefix-arg
1025 (list (prefix-numeric-value current-prefix-arg
))
1029 (when (message-goto-body)
1030 (narrow-to-region (point) (point-max)))
1031 (message-caesar-region (point-min) (point-max) rotnum
))))
1033 (defun message-rename-buffer (&optional enter-string
)
1034 "Rename the *message* buffer to \"*message* RECIPIENT\".
1035 If the function is run with a prefix, it will ask for a new buffer
1036 name, rather than giving an automatic name."
1037 (interactive "Pbuffer name: ")
1040 (goto-char (point-min))
1041 (narrow-to-region (point)
1042 (search-forward mail-header-separator nil
'end
))
1043 (let* ((mail-to (if (message-news-p) (message-fetch-field "Newsgroups")
1044 (message-fetch-field "To")))
1046 (if (string-match "," mail-to
)
1047 (concat (substring mail-to
0 (match-beginning 0)) ", ...")
1049 (name-default (concat "*message* " mail-trimmed-to
))
1050 (name (if enter-string
1051 (read-string "New buffer name: " name-default
)
1053 (rename-buffer name t
)))))
1055 (defun message-fill-yanked-message (&optional justifyp
)
1056 "Fill the paragraphs of a message yanked into this one.
1057 Numeric argument means justify as well."
1060 (goto-char (point-min))
1061 (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
1062 (let ((fill-prefix message-yank-prefix
))
1063 (fill-individual-paragraphs (point) (point-max) justifyp t
))))
1065 (defun message-indent-citation ()
1066 "Modify text just inserted from a message to be cited.
1067 The inserted text should be the region.
1068 When this function returns, the region is again around the modified text.
1070 Normally, indent each nonblank line `message-indentation-spaces' spaces.
1071 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
1072 (let ((start (point)))
1073 ;; Remove unwanted headers.
1074 (when message-ignored-cited-headers
1078 (if (search-forward "\n\n" nil t
)
1081 (message-remove-header message-ignored-cited-headers t
)))
1082 ;; Do the indentation.
1083 (if (null message-yank-prefix
)
1084 (indent-rigidly start
(mark t
) message-indentation-spaces
)
1087 (while (< (point) (mark t
))
1088 (insert message-yank-prefix
)
1090 (goto-char start
))))
1092 (defun message-yank-original (&optional arg
)
1093 "Insert the message being replied to, if any.
1094 Puts point before the text and mark after.
1095 Normally indents each nonblank line ARG spaces (default 3). However,
1096 if `message-yank-prefix' is non-nil, insert that prefix on each line.
1098 Just \\[universal-argument] as argument means don't indent, insert no
1099 prefix, and don't delete any headers."
1101 (let ((modified (buffer-modified-p)))
1102 (when (and message-reply-buffer
1103 message-cite-function
)
1104 (delete-windows-on message-reply-buffer t
)
1105 (insert-buffer message-reply-buffer
)
1106 (funcall message-cite-function
)
1107 (message-exchange-point-and-mark)
1111 (setq message-checksum
(cons (message-checksum) (buffer-size)))))))
1113 (defun message-cite-original ()
1114 (let ((start (point))
1116 (when message-indent-citation-function
1117 (if (listp message-indent-citation-function
)
1118 message-indent-citation-function
1119 (list message-indent-citation-function
)))))
1122 (funcall (pop functions
)))
1123 (when message-citation-line-function
1126 (funcall message-citation-line-function
))))
1128 (defun message-insert-citation-line ()
1129 "Function that inserts a simple citation line."
1130 (when message-reply-headers
1131 (insert (mail-header-from message-reply-headers
) " writes:\n\n")))
1133 (defun message-position-on-field (header &rest afters
)
1134 (let ((case-fold-search t
))
1137 (goto-char (point-min))
1140 (concat "^" (regexp-quote mail-header-separator
) "$"))
1141 (match-beginning 0)))
1142 (goto-char (point-min))
1143 (if (re-search-forward (concat "^" (regexp-quote header
) ":") nil t
)
1145 (re-search-forward "^[^ \t]" nil
'move
)
1147 (skip-chars-backward "\n")
1150 (not (re-search-forward
1151 (concat "^" (regexp-quote (car afters
)) ":")
1155 (re-search-forward "^[^ \t]" nil
'move
)
1156 (beginning-of-line))
1157 (insert header
": \n")
1161 (defun message-remove-signature ()
1162 "Remove the signature from the text between point and mark.
1163 The text will also be indented the normal way."
1165 (let ((start (point))
1167 (if (not (re-search-forward message-signature-separator
(mark t
) t
))
1168 ;; No signature here, so we just indent the cited text.
1169 (message-indent-citation)
1170 ;; Find the last non-empty line.
1172 (while (looking-at "[ \t]*$")
1175 (setq mark
(set-marker (make-marker) (point)))
1177 (message-indent-citation)
1178 ;; Enable undoing the deletion.
1180 (delete-region mark
(mark t
))
1181 (set-marker mark nil
)))))
1186 ;;; Sending messages
1189 (defun message-send-and-exit (&optional arg
)
1190 "Send message like `message-send', then, if no errors, exit from mail buffer."
1192 (let ((buf (current-buffer))
1193 (actions message-exit-actions
))
1194 (when (and (message-send arg
)
1196 (if message-kill-buffer-on-exit
1199 (when (eq buf
(current-buffer))
1200 (message-bury buf
)))
1201 (message-do-actions actions
))))
1203 (defun message-dont-send ()
1204 "Don't send the message you have been editing."
1206 (message-bury (current-buffer))
1207 (message-do-actions message-postpone-actions
))
1209 (defun message-kill-buffer ()
1210 "Kill the current buffer."
1212 (let ((actions message-kill-actions
))
1213 (kill-buffer (current-buffer))
1214 (message-do-actions actions
)))
1216 (defun message-bury (buffer)
1217 "Bury this mail buffer."
1218 (let ((newbuf (other-buffer buffer
)))
1219 (bury-buffer buffer
)
1220 (if (and (fboundp 'frame-parameters
)
1221 (cdr (assq 'dedicated
(frame-parameters)))
1222 (not (null (delq (selected-frame) (visible-frame-list)))))
1223 (delete-frame (selected-frame))
1224 (switch-to-buffer newbuf
))))
1226 (defun message-send (&optional arg
)
1227 "Send the message in the current buffer.
1228 If `message-interactive' is non-nil, wait for success indication
1229 or error messages, and inform user.
1230 Otherwise any failure is reported in a message back to
1231 the user from the mailer."
1233 (when (if buffer-file-name
1234 (y-or-n-p (format "Send buffer contents as %s message? "
1235 (if (message-mail-p)
1236 (if (message-news-p) "mail and news" "mail")
1238 (or (buffer-modified-p)
1239 (y-or-n-p "No changes in the buffer; really send? ")))
1240 ;; Make it possible to undo the coming changes.
1242 (let ((inhibit-read-only t
))
1243 (put-text-property (point-min) (point-max) 'read-only nil
))
1244 (message-fix-before-sending)
1245 (run-hooks 'message-send-hook
)
1246 (message "Sending...")
1247 (when (and (or (not (message-news-p))
1248 (and (or (not (memq 'news message-sent-message-via
))
1250 "Already sent message via news; resend? "))
1251 (funcall message-send-news-function arg
)))
1252 (or (not (message-mail-p))
1253 (and (or (not (memq 'mail message-sent-message-via
))
1255 "Already sent message via mail; resend? "))
1256 (message-send-mail arg
))))
1258 (when (fboundp 'mail-hist-put-headers-into-history
)
1259 (mail-hist-put-headers-into-history))
1260 (run-hooks 'message-sent-hook
)
1261 (message "Sending...done")
1262 ;; If buffer has no file, mark it as unmodified and delete autosave.
1263 (unless buffer-file-name
1264 (set-buffer-modified-p nil
)
1265 (delete-auto-save-file-if-necessary t
))
1266 ;; Delete other mail buffers and stuff.
1267 (message-do-send-housekeeping)
1268 (message-do-actions message-send-actions
)
1272 (defun message-fix-before-sending ()
1273 "Do various things to make the message nice before sending it."
1274 ;; Make sure there's a newline at the end of the message.
1275 (goto-char (point-max))
1279 (defun message-add-action (action &rest types
)
1280 "Add ACTION to be performed when doing an exit of type TYPES."
1283 (set (setq var
(intern (format "message-%s-actions" (pop types
))))
1284 (nconc (symbol-value var
) (list action
))))))
1286 (defun message-do-actions (actions)
1287 "Perform all actions in ACTIONS."
1288 ;; Now perform actions on successful sending.
1292 ;; A simple function.
1293 ((message-functionp (car actions
))
1294 (funcall (car actions
)))
1295 ;; Something to be evaled.
1297 (eval (car actions
))))
1301 (defun message-send-mail (&optional arg
)
1302 (require 'mail-utils
)
1303 (let ((tembuf (generate-new-buffer " message temp"))
1304 (case-fold-search nil
)
1305 (news (message-news-p))
1306 (mailbuf (current-buffer)))
1308 (message-narrow-to-headers)
1309 ;; Insert some headers.
1310 (let ((message-deletable-headers
1311 (if news nil message-deletable-headers
)))
1312 (message-generate-headers message-required-mail-headers
))
1313 ;; Let the user do all of the above.
1314 (run-hooks 'message-header-hook
))
1319 (insert-buffer-substring mailbuf
)
1320 ;; Remove some headers.
1322 (message-narrow-to-headers)
1323 ;; Remove some headers.
1324 (message-remove-header message-ignored-mail-headers t
))
1325 (goto-char (point-max))
1326 ;; require one newline at the end.
1327 (or (= (preceding-char) ?
\n)
1330 (or (message-fetch-field "cc")
1331 (message-fetch-field "to")))
1332 (message-insert-courtesy-copy))
1333 (funcall message-send-mail-function
))
1334 (kill-buffer tembuf
))
1335 (set-buffer mailbuf
)
1336 (push 'mail message-sent-message-via
)))
1338 (defun message-send-mail-with-sendmail ()
1339 "Send off the prepared buffer with sendmail."
1340 (let ((errbuf (if message-interactive
1341 (generate-new-buffer " sendmail errors")
1343 resend-to-addresses delimline
)
1344 (let ((case-fold-search t
))
1346 (message-narrow-to-headers)
1347 (setq resend-to-addresses
(message-fetch-field "resent-to")))
1348 ;; Change header-delimiter to be what sendmail expects.
1349 (goto-char (point-min))
1351 (concat "^" (regexp-quote mail-header-separator
) "\n"))
1352 (replace-match "\n")
1354 (setq delimline
(point-marker))
1355 ;; Insert an extra newline if we need it to work around
1356 ;; Sun's bug that swallows newlines.
1357 (goto-char (1+ delimline
))
1358 (when (eval message-mailer-swallows-blank-line
)
1360 (when message-interactive
1364 (let ((default-directory "/"))
1365 (apply 'call-process-region
1366 (append (list (point-min) (point-max)
1367 (if (boundp 'sendmail-program
)
1369 "/usr/lib/sendmail")
1370 nil errbuf nil
"-oi")
1371 ;; Always specify who from,
1372 ;; since some systems have broken sendmails.
1373 (list "-f" (user-login-name))
1374 ;; These mean "report errors by mail"
1375 ;; and "deliver in background".
1376 (if (null message-interactive
) '("-oem" "-odb"))
1377 ;; Get the addresses from the message
1378 ;; unless this is a resend.
1379 ;; We must not do that for a resend
1380 ;; because we would find the original addresses.
1381 ;; For a resend, include the specific addresses.
1382 (if resend-to-addresses
1383 (list resend-to-addresses
)
1385 (when message-interactive
1388 (goto-char (point-min))
1389 (while (re-search-forward "\n\n* *" nil t
)
1390 (replace-match "; "))
1391 (if (not (zerop (buffer-size)))
1392 (error "Sending...failed to %s"
1393 (buffer-substring (point-min) (point-max)))))
1394 (when (bufferp errbuf
)
1395 (kill-buffer errbuf
)))))
1397 (defun message-send-mail-with-mh ()
1398 "Send the prepared message buffer with mh."
1399 (let ((mh-previous-window-config nil
)
1400 (name (make-temp-name
1401 (concat (file-name-as-directory message-autosave-directory
)
1403 (setq buffer-file-name name
)
1409 (defun message-send-news (&optional arg
)
1410 (let ((tembuf (generate-new-buffer " *message temp*"))
1411 (case-fold-search nil
)
1412 (method (if (message-functionp message-post-method
)
1413 (funcall message-post-method arg
)
1414 message-post-method
))
1415 (messbuf (current-buffer))
1416 (message-syntax-checks
1418 (cons '(existing-newsgroups . disabled
)
1419 message-syntax-checks
)
1420 message-syntax-checks
))
1423 (message-narrow-to-headers)
1424 ;; Insert some headers.
1425 (message-generate-headers message-required-news-headers
)
1426 ;; Let the user do all of the above.
1427 (run-hooks 'message-header-hook
))
1428 (message-cleanup-headers)
1429 (when (message-check-news-syntax)
1433 (buffer-disable-undo (current-buffer))
1435 (insert-buffer-substring messbuf
)
1436 ;; Remove some headers.
1438 (message-narrow-to-headers)
1439 ;; Remove some headers.
1440 (message-remove-header message-ignored-news-headers t
))
1441 (goto-char (point-max))
1442 ;; require one newline at the end.
1443 (or (= (preceding-char) ?
\n)
1445 (let ((case-fold-search t
))
1446 ;; Remove the delimeter.
1447 (goto-char (point-min))
1449 (concat "^" (regexp-quote mail-header-separator
) "\n"))
1450 (replace-match "\n")
1452 (require (car method
))
1453 (funcall (intern (format "%s-open-server" (car method
)))
1454 (cadr method
) (cddr method
))
1456 (funcall (intern (format "%s-request-post" (car method
))))))
1457 (kill-buffer tembuf
))
1458 (set-buffer messbuf
)
1460 (push 'news message-sent-message-via
)
1461 (message "Couldn't send message via news: %s"
1462 (nnheader-get-report (car method
)))
1466 ;;; Header generation & syntax checking.
1469 (defun message-check-news-syntax ()
1470 "Check the syntax of the message."
1472 ;; We narrow to the headers and check them first.
1475 (message-narrow-to-headers)
1477 ;; Check for commands in Subject.
1479 (message-check-element 'subject-cmsg
)
1481 (if (string-match "^cmsg " (message-fetch-field "subject"))
1483 "The control code \"cmsg \" is in the subject. Really post? ")
1485 ;; Check for multiple identical headers.
1486 (or (message-check-element 'multiple-headers
)
1489 (while (and (not found
)
1490 (re-search-forward "^[^ \t:]+: " nil t
))
1492 (or (re-search-forward
1493 (concat "^" (setq found
1496 (- (match-end 0) 2))))
1501 (format "Multiple %s headers. Really post? " found
))
1503 ;; Check for Version and Sendsys.
1504 (or (message-check-element 'sendsys
)
1506 (if (re-search-forward "^Sendsys:\\|^Version:" nil t
)
1508 (format "The article contains a %s command. Really post? "
1509 (buffer-substring (match-beginning 0)
1510 (1- (match-end 0)))))
1512 ;; See whether we can shorten Followup-To.
1513 (or (message-check-element 'shorten-followup-to
)
1514 (let ((newsgroups (message-fetch-field "newsgroups"))
1515 (followup-to (message-fetch-field "followup-to"))
1517 (when (and newsgroups
(string-match "," newsgroups
)
1522 (setq to
(completing-read
1523 "Followups to: (default all groups) "
1524 (mapcar (lambda (g) (list g
))
1526 (message-tokenize-header
1528 (goto-char (point-min))
1529 (insert "Followup-To: " to
"\n"))
1531 ;; Check "Shoot me".
1532 (or (message-check-element 'shoot
)
1535 ".i-have-a-misconfigured-system-so-shoot-me" nil t
)
1537 "You appear to have a misconfigured system. Really post? ")
1539 ;; Check for Approved.
1540 (or (message-check-element 'approved
)
1542 (if (re-search-forward "^Approved:" nil t
)
1544 "The article contains an Approved header. Really post? ")
1546 ;; Check the Message-Id header.
1547 (or (message-check-element 'message-id
)
1549 (let* ((case-fold-search t
)
1550 (message-id (message-fetch-field "message-id")))
1551 (or (not message-id
)
1552 (and (string-match "@" message-id
)
1553 (string-match "@[^\\.]*\\." message-id
))
1556 "The Message-ID looks strange: \"%s\". Really post? "
1558 ;; Check the Subject header.
1560 (message-check-element 'subject
)
1562 (let* ((case-fold-search t
)
1563 (subject (message-fetch-field "subject")))
1566 (not (string-match "\\`[ \t]*\\'" subject
)))
1569 "The subject field is empty or missing. Posting is denied.")
1571 ;; Check the Newsgroups & Followup-To headers.
1573 (message-check-element 'existing-newsgroups
)
1574 (let* ((case-fold-search t
)
1575 (newsgroups (message-fetch-field "newsgroups"))
1576 (followup-to (message-fetch-field "followup-to"))
1577 (groups (message-tokenize-header
1579 (concat newsgroups
"," followup-to
)
1581 (hashtb (and (boundp 'gnus-active-hashtb
)
1582 gnus-active-hashtb
))
1587 (when (and (not (boundp (intern (car groups
) hashtb
)))
1588 (not (equal (car groups
) "poster")))
1589 (push (car groups
) errors
))
1595 "Really post to %s unknown group%s: %s "
1596 (if (= (length errors
) 1) "this" "these")
1597 (if (= (length errors
) 1) "" "s")
1598 (mapconcat 'identity errors
", ")))))))
1599 ;; Check the Newsgroups & Followup-To headers for syntax errors.
1601 (message-check-element 'valid-newsgroups
)
1602 (let ((case-fold-search t
)
1603 (headers '("Newsgroups" "Followup-To"))
1605 (while (and headers
(not error
))
1606 (when (setq header
(mail-fetch-field (car headers
)))
1610 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-.a-zA-Z0-9]+\\)*\\'"
1615 (not (string-match "\\.\\'\\|\\.\\." g
)))
1616 (message-tokenize-header header
","))))
1623 (format "The %s header looks odd: \"%s\". Really post? "
1624 (car headers
) header
)))))
1625 ;; Check the From header.
1628 (let* ((case-fold-search t
)
1629 (from (message-fetch-field "from")))
1632 (message "There is no From line. Posting is denied.")
1634 ((not (string-match "@[^\\.]*\\." from
))
1636 "Denied posting -- the From looks strange: \"%s\"." from
)
1638 ((string-match "@[^@]*@" from
)
1640 "Denied posting -- two \"@\"'s in the From header: %s." from
)
1642 ((string-match "(.*).*(.*)" from
)
1644 "Denied posting -- the From header looks strange: \"%s\"."
1648 ;; Check for long lines.
1649 (or (message-check-element 'long-lines
)
1651 (goto-char (point-min))
1653 (concat "^" (regexp-quote mail-header-separator
) "$"))
1657 (< (current-column) 80))
1658 (zerop (forward-line 1))))
1662 "You have lines longer than 79 characters. Really post? "))))
1663 ;; Check whether the article is empty.
1664 (or (message-check-element 'empty
)
1666 (goto-char (point-min))
1668 (concat "^" (regexp-quote mail-header-separator
) "$"))
1671 (or (re-search-forward message-signature-separator nil t
)
1672 (goto-char (point-max)))
1674 (or (re-search-backward "[^ \n\t]" b t
)
1675 (y-or-n-p "Empty article. Really post? ")))))
1676 ;; Check for control characters.
1677 (or (message-check-element 'control-chars
)
1679 (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t
)
1681 "The article contains control characters. Really post? ")
1683 ;; Check excessive size.
1684 (or (message-check-element 'size
)
1685 (if (> (buffer-size) 60000)
1687 (format "The article is %d octets long. Really post? "
1690 ;; Check whether any new text has been added.
1691 (or (message-check-element 'new-text
)
1692 (not message-checksum
)
1693 (not (and (eq (message-checksum) (car message-checksum
))
1694 (eq (buffer-size) (cdr message-checksum
))))
1696 "It looks like no new text has been added. Really post? "))
1697 ;; Check the length of the signature.
1699 (message-check-element 'signature
)
1701 (goto-char (point-max))
1702 (if (or (not (re-search-backward "^-- $" nil t
))
1703 (search-forward message-forward-end-separator nil t
))
1705 (if (> (count-lines (point) (point-max)) 5)
1708 "Your .sig is %d lines; it should be max 4. Really post? "
1709 (count-lines (point) (point-max))))
1712 (defun message-check-element (type)
1713 "Returns non-nil if this type is not to be checked."
1714 (if (eq message-syntax-checks
'dont-check-for-anything-just-trust-me
)
1716 (let ((able (assq type message-syntax-checks
)))
1718 (eq (cdr able
) 'disabled
)))))
1720 (defun message-checksum ()
1721 "Return a \"checksum\" for the current buffer."
1724 (goto-char (point-min))
1726 (concat "^" (regexp-quote mail-header-separator
) "$"))
1728 (when (not (looking-at "[ \t\n]"))
1729 (setq sum
(logxor (ash sum
1) (following-char))))
1733 (defun message-do-fcc ()
1734 "Process Fcc headers in the current buffer."
1735 (let ((case-fold-search t
)
1736 (buf (current-buffer))
1739 (set-buffer (get-buffer-create " *message temp*"))
1740 (buffer-disable-undo (current-buffer))
1742 (insert-buffer-substring buf
)
1744 (message-narrow-to-headers)
1745 (while (setq file
(message-fetch-field "fcc"))
1747 (message-remove-header "fcc" nil t
)))
1748 (goto-char (point-min))
1749 (re-search-forward (concat "^" (regexp-quote mail-header-separator
) "$"))
1750 (replace-match "" t t
)
1751 ;; Process FCC operations.
1753 (setq file
(pop list
))
1754 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file
)
1755 ;; Pipe the article to the program in question.
1756 (call-process-region (point-min) (point-max) shell-file-name
1757 nil nil nil shell-command-switch
1758 (match-string 1 file
))
1759 ;; Save the article.
1760 (setq file
(expand-file-name file
))
1761 (unless (file-exists-p (file-name-directory file
))
1762 (make-directory (file-name-directory file
) t
))
1763 (if (and message-fcc-handler-function
1764 (not (eq message-fcc-handler-function
'rmail-output
)))
1765 (funcall message-fcc-handler-function file
)
1766 (if (and (file-readable-p file
) (mail-file-babyl-p file
))
1767 (rmail-output file
1)
1768 (let ((mail-use-rfc822 t
))
1769 (rmail-output file
1 t t
))))))
1770 (kill-buffer (current-buffer)))))
1772 (defun message-cleanup-headers ()
1773 "Do various automatic cleanups of the headers."
1774 ;; Remove empty lines in the header.
1776 (message-narrow-to-headers)
1777 (while (re-search-forward "^[ \t]*\n" nil t
)
1778 (replace-match "" t t
)))
1780 ;; Correct Newsgroups and Followup-To headers: change sequence of
1781 ;; spaces to comma and eliminate spaces around commas. Eliminate
1782 ;; embedded line breaks.
1783 (goto-char (point-min))
1784 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t
)
1788 (if (re-search-forward "^[^ \t]" nil t
)
1792 (goto-char (point-min))
1793 (while (re-search-forward "\n[ \t]+" nil t
)
1794 (replace-match " " t t
)) ;No line breaks (too confusing)
1795 (goto-char (point-min))
1796 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t
)
1797 (replace-match "," t t
))
1798 (goto-char (point-min))
1799 ;; Remove trailing commas.
1800 (when (re-search-forward ",+$" nil t
)
1801 (replace-match "" t t
)))))
1803 (defun message-make-date ()
1804 "Make a valid data header."
1805 (let ((now (current-time)))
1806 (timezone-make-date-arpa-standard
1807 (current-time-string now
) (current-time-zone now
))))
1809 (defun message-make-message-id ()
1810 "Make a unique Message-ID."
1811 (concat "<" (message-unique-id)
1812 (let ((psubject (save-excursion (message-fetch-field "subject"))))
1813 (if (and message-reply-headers
1814 (mail-header-references message-reply-headers
)
1815 (mail-header-subject message-reply-headers
)
1817 (mail-header-subject message-reply-headers
)
1819 (message-strip-subject-re
1820 (mail-header-subject message-reply-headers
))
1821 (message-strip-subject-re psubject
))))
1823 "@" (message-make-fqdn) ">"))
1825 (defvar message-unique-id-char nil
)
1827 ;; If you ever change this function, make sure the new version
1828 ;; cannot generate IDs that the old version could.
1829 ;; You might for example insert a "." somewhere (not next to another dot
1830 ;; or string boundary), or modify the "fsf" string.
1831 (defun message-unique-id ()
1832 ;; Don't use microseconds from (current-time), they may be unsupported.
1833 ;; Instead we use this randomly inited counter.
1834 (setq message-unique-id-char
1835 (%
(1+ (or message-unique-id-char
(logand (random t
) (1- (lsh 1 20)))))
1836 ;; (current-time) returns 16-bit ints,
1837 ;; and 2^16*25 just fits into 4 digits i base 36.
1839 (let ((tm (current-time)))
1841 (if (memq system-type
'(ms-dos emx vax-vms
))
1842 (let ((user (downcase (user-login-name))))
1843 (while (string-match "[^a-z0-9_]" user
)
1844 (aset user
(match-beginning 0) ?_
))
1846 (message-number-base36 (user-uid) -
1))
1847 (message-number-base36 (+ (car tm
)
1848 (lsh (% message-unique-id-char
25) 16)) 4)
1849 (message-number-base36 (+ (nth 1 tm
)
1850 (lsh (/ message-unique-id-char
25) 16)) 4)
1851 ;; Append the newsreader name, because while the generated
1852 ;; ID is unique to this newsreader, other newsreaders might
1853 ;; otherwise generate the same ID via another algorithm.
1856 (defun message-number-base36 (num len
)
1857 (if (if (< len
0) (<= num
0) (= len
0))
1859 (concat (message-number-base36 (/ num
36) (1- len
))
1860 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
1863 (defun message-make-organization ()
1864 "Make an Organization header."
1865 (let* ((organization
1866 (or (getenv "ORGANIZATION")
1867 (when message-user-organization
1868 (if (message-functionp message-user-organization
)
1869 (funcall message-user-organization
)
1870 message-user-organization
)))))
1872 (message-set-work-buffer)
1873 (cond ((stringp organization
)
1874 (insert organization
))
1875 ((and (eq t organization
)
1876 message-user-organization-file
1877 (file-exists-p message-user-organization-file
))
1878 (insert-file-contents message-user-organization-file
)))
1879 (goto-char (point-min))
1880 (while (re-search-forward "[\t\n]+" nil t
)
1881 (replace-match "" t t
))
1882 (unless (zerop (buffer-size))
1885 (defun message-make-lines ()
1886 "Count the number of lines and return numeric string."
1890 (goto-char (point-min))
1892 (concat "^" (regexp-quote mail-header-separator
) "$"))
1894 (int-to-string (count-lines (point) (point-max))))))
1896 (defun message-make-in-reply-to ()
1897 "Return the In-Reply-To header for this message."
1898 (when message-reply-headers
1899 (let ((from (mail-header-from message-reply-headers
))
1900 (date (mail-header-date message-reply-headers
)))
1903 (string-match " *at \\| *@ \\| *(\\| *<" from
)))
1904 (concat (if stop-pos
(substring from
0 stop-pos
) from
)
1906 (if (or (not date
) (string= date
""))
1907 "(unknown date)" date
)))))))
1909 (defun message-make-distribution ()
1910 "Make a Distribution header."
1911 (let ((orig-distribution (message-fetch-reply-field "distribution")))
1912 (cond ((message-functionp message-distribution-function
)
1913 (funcall message-distribution-function
))
1914 (t orig-distribution
))))
1916 (defun message-make-expires ()
1917 "Return an Expires header based on `message-expires'."
1918 (let ((current (current-time))
1919 (future (* 1.0 message-expires
60 60 24)))
1920 ;; Add the future to current.
1921 (setcar current
(+ (car current
) (round (/ future
(expt 2 16)))))
1922 (setcar (cdr current
) (+ (nth 1 current
) (%
(round future
) (expt 2 16))))
1923 ;; Return the date in the future in UT.
1924 (timezone-make-date-arpa-standard
1925 (current-time-string current
) (current-time-zone current
) '(0 "UT"))))
1927 (defun message-make-path ()
1929 (let ((login-name (user-login-name)))
1930 (cond ((null message-user-path
)
1931 (concat (system-name) "!" login-name
))
1932 ((stringp message-user-path
)
1933 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
1934 (concat message-user-path
"!" login-name
))
1937 (defun message-make-from ()
1938 "Make a From header."
1939 (let* ((login (message-make-address))
1941 (or (and (boundp 'user-full-name
)
1944 (when (string= fullname
"&")
1945 (setq fullname
(user-login-name)))
1947 (message-set-work-buffer)
1949 ((or (null message-from-style
)
1950 (equal fullname
""))
1952 ((or (eq message-from-style
'angles
)
1953 (and (not (eq message-from-style
'parens
))
1954 ;; Use angles if no quoting is needed, or if parens would
1955 ;; need quoting too.
1956 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname
))
1957 (let ((tmp (concat fullname nil
)))
1958 (while (string-match "([^()]*)" tmp
)
1959 (aset tmp
(match-beginning 0) ?-
)
1960 (aset tmp
(1- (match-end 0)) ?-
))
1961 (string-match "[\\()]" tmp
)))))
1963 (goto-char (point-min))
1964 ;; Look for a character that cannot appear unquoted
1965 ;; according to RFC 822.
1966 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil
1)
1967 ;; Quote fullname, escaping specials.
1968 (goto-char (point-min))
1970 (while (re-search-forward "[\"\\]" nil
1)
1971 (replace-match "\\\\\\&" t
))
1973 (insert " <" login
">"))
1974 (t ; 'parens or default
1976 (let ((fullname-start (point)))
1978 (goto-char fullname-start
)
1979 ;; RFC 822 says \ and nonmatching parentheses
1980 ;; must be escaped in comments.
1981 ;; Escape every instance of ()\ ...
1982 (while (re-search-forward "[()\\]" nil
1)
1983 (replace-match "\\\\\\&" t
))
1984 ;; ... then undo escaping of matching parentheses,
1985 ;; including matching nested parentheses.
1986 (goto-char fullname-start
)
1987 (while (re-search-forward
1988 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
1990 (replace-match "\\1(\\3)" t
)
1991 (goto-char fullname-start
)))
1995 (defun message-make-sender ()
1996 "Return the \"real\" user address.
1997 This function tries to ignore all user modifications, and
1998 give as trustworthy answer as possible."
1999 (concat (user-login-name) "@" (system-name)))
2001 (defun message-make-address ()
2002 "Make the address of the user."
2003 (or (message-user-mail-address)
2004 (concat (user-login-name) "@" (message-make-domain))))
2006 (defun message-user-mail-address ()
2007 "Return the pertinent part of `user-mail-address'."
2008 (when user-mail-address
2009 (nth 1 (mail-extract-address-components user-mail-address
))))
2011 (defun message-make-fqdn ()
2012 "Return user's fully qualified domain name."
2013 (let ((system-name (system-name))
2014 (user-mail (message-user-mail-address)))
2016 ((string-match "[^.]\\.[^.]" system-name
)
2017 ;; `system-name' returned the right result.
2019 ;; Try `mail-host-address'.
2020 ((and (boundp 'mail-host-address
)
2021 (stringp mail-host-address
)
2022 (string-match "\\." mail-host-address
))
2024 ;; We try `user-mail-address' as a backup.
2025 ((and (string-match "\\." user-mail
)
2026 (string-match "@\\(.*\\)\\'" user-mail
))
2027 (match-string 1 user-mail
))
2028 ;; Default to this bogus thing.
2030 (concat system-name
".i-have-a-misconfigured-system-so-shoot-me")))))
2032 (defun message-make-host-name ()
2033 "Return the name of the host."
2034 (let ((fqdn (message-make-fqdn)))
2035 (string-match "^[^.]+\\." fqdn
)
2036 (substring fqdn
0 (1- (match-end 0)))))
2038 (defun message-make-domain ()
2039 "Return the domain name."
2040 (or mail-host-address
2041 (message-make-fqdn)))
2043 (defun message-generate-headers (headers)
2044 "Prepare article HEADERS.
2045 Headers already prepared in the buffer are not modified."
2047 (message-narrow-to-headers)
2048 (let* ((Date (message-make-date))
2049 (Message-ID (message-make-message-id))
2050 (Organization (message-make-organization))
2051 (From (message-make-from))
2052 (Path (message-make-path))
2055 (In-Reply-To (message-make-in-reply-to))
2057 (Distribution (message-make-distribution))
2058 (Lines (message-make-lines))
2059 (X-Newsreader message-newsreader
)
2060 (X-Mailer (and (not (message-fetch-field "X-Newsreader"))
2062 (Expires (message-make-expires))
2063 (case-fold-search t
)
2065 ;; First we remove any old generated headers.
2066 (let ((headers message-deletable-headers
))
2068 (goto-char (point-min))
2069 (and (re-search-forward
2070 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
2071 (get-text-property (1+ (match-beginning 0)) 'message-deletable
)
2072 (message-delete-line))
2074 ;; Go through all the required headers and see if they are in the
2075 ;; articles already. If they are not, or are empty, they are
2076 ;; inserted automatically - except for Subject, Newsgroups and
2079 (goto-char (point-min))
2080 (setq elem
(pop headers
))
2082 (if (eq (car elem
) 'optional
)
2083 (setq header
(cdr elem
))
2084 (setq header
(car elem
)))
2086 (when (or (not (re-search-forward
2087 (concat "^" (downcase (symbol-name header
)) ":")
2090 ;; The header was found. We insert a space after the
2091 ;; colon, if there is none.
2092 (if (/= (following-char) ?
) (insert " ") (forward-char 1))
2093 ;; Find out whether the header is empty...
2094 (looking-at "[ \t]*$")))
2095 ;; So we find out what value we should insert.
2098 ((and (consp elem
) (eq (car elem
) 'optional
))
2099 ;; This is an optional header. If the cdr of this
2100 ;; is something that is nil, then we do not insert
2102 (setq header
(cdr elem
))
2103 (or (and (fboundp (cdr elem
)) (funcall (cdr elem
)))
2104 (and (boundp (cdr elem
)) (symbol-value (cdr elem
)))))
2106 ;; The element is a cons. Either the cdr is a
2107 ;; string to be inserted verbatim, or it is a
2108 ;; function, and we insert the value returned from
2110 (or (and (stringp (cdr elem
)) (cdr elem
))
2111 (and (fboundp (cdr elem
)) (funcall (cdr elem
)))))
2112 ((and (boundp header
) (symbol-value header
))
2113 ;; The element is a symbol. We insert the value
2114 ;; of this symbol, if any.
2115 (symbol-value header
))
2117 ;; We couldn't generate a value for this header,
2118 ;; so we just ask the user.
2119 (read-from-minibuffer
2120 (format "Empty header for %s; enter value: " header
)))))
2121 ;; Finally insert the header.
2123 (not (equal value
"")))
2127 ;; This header didn't exist, so we insert it.
2128 (goto-char (point-max))
2129 (insert (symbol-name header
) ": " value
"\n")
2131 ;; The value of this header was empty, so we clear
2132 ;; totally and insert the new value.
2133 (delete-region (point) (message-point-at-eol))
2135 ;; Add the deletable property to the headers that require it.
2136 (and (memq header message-deletable-headers
)
2137 (progn (beginning-of-line) (looking-at "[^:]+: "))
2138 (add-text-properties
2139 (point) (match-end 0)
2140 '(message-deletable t face italic
) (current-buffer)))))))
2141 ;; Insert new Sender if the From is strange.
2142 (let ((from (message-fetch-field "from"))
2143 (sender (message-fetch-field "sender"))
2144 (secure-sender (message-make-sender)))
2146 (not (message-check-element 'sender
))
2149 (cadr (mail-extract-address-components from
)))
2150 (downcase secure-sender
)))
2155 (cadr (mail-extract-address-components sender
)))
2156 (downcase secure-sender
)))))
2157 (goto-char (point-min))
2158 ;; Rename any old Sender headers to Original-Sender.
2159 (when (re-search-forward "^Sender:" nil t
)
2161 (insert "Original-")
2162 (beginning-of-line))
2163 (insert "Sender: " secure-sender
"\n"))))))
2165 (defun message-insert-courtesy-copy ()
2166 "Insert a courtesy message in mail copies of combined messages."
2169 (message-narrow-to-headers)
2170 (let ((newsgroups (message-fetch-field "newsgroups")))
2172 (goto-char (point-max))
2173 (insert "Posted-To: " newsgroups
"\n"))))
2175 (insert message-courtesy-message
)))
2178 ;;; Setting up a message buffer
2181 (defun message-fill-address (header value
)
2183 (narrow-to-region (point) (point))
2184 (insert (capitalize (symbol-name header
))
2186 (if (consp value
) (car value
) value
)
2188 (narrow-to-region (point-min) (1- (point-max)))
2190 (goto-char (point-min))
2192 (skip-chars-forward "^,\"" (point-max))
2193 (if (or (= (following-char) ?
,)
2196 (if (and (> (current-column) 78)
2202 (setq last
(1+ (point))))
2203 (setq last
(1+ (point)))))
2204 (setq quoted
(not quoted
)))
2207 (goto-char (point-max))
2211 (defun message-fill-header (header value
)
2212 (let ((begin (point))
2215 (insert (capitalize (symbol-name header
))
2217 (if (consp value
) (car value
) value
)
2220 (narrow-to-region begin
(point))
2221 (fill-region-as-paragraph begin
(point))
2222 ;; Tapdance around looong Message-IDs.
2224 (when (looking-at "[ \t]*$")
2225 (message-delete-line))
2227 (re-search-forward ":" nil t
)
2228 (when (looking-at "\n[ \t]+")
2229 (replace-match " " t t
))
2230 (goto-char (point-max)))))
2232 (defun message-position-point ()
2233 "Move point to where the user probably wants to find it."
2234 (message-narrow-to-headers)
2236 ((re-search-forward "^[^:]+:[ \t]*$" nil t
)
2237 (search-backward ":" )
2240 (if (= (following-char) ?
)
2244 (goto-char (point-max))
2247 (unless (looking-at "$")
2251 (defun message-buffer-name (type &optional to group
)
2252 "Return a new (unique) buffer name based on TYPE and TO."
2254 ;; Check whether `message-generate-new-buffers' is a function,
2255 ;; and if so, call it.
2256 ((message-functionp message-generate-new-buffers
)
2257 (funcall message-generate-new-buffers type to group
))
2258 ;; Generate a new buffer name The Message Way.
2259 (message-generate-new-buffers
2260 (generate-new-buffer-name
2264 (or (car (mail-extract-address-components to
))
2267 (if (and group
(not (string= group
""))) (concat " on " group
) "")
2269 ;; Use standard name.
2271 (format "*%s message*" type
))))
2273 (defun message-pop-to-buffer (name)
2274 "Pop to buffer NAME, and warn if it already exists and is modified."
2275 (let ((buffer (get-buffer name
)))
2277 (buffer-name buffer
))
2279 (set-buffer (pop-to-buffer buffer
))
2280 (when (and (buffer-modified-p)
2282 "Message already being composed; erase? ")))
2283 (error "Message being composed")))
2284 (set-buffer (pop-to-buffer name
))))
2288 (defun message-do-send-housekeeping ()
2289 "Kill old message buffers."
2290 ;; We might have sent this buffer already. Delete it from the
2292 (setq message-buffer-list
(delq (current-buffer) message-buffer-list
))
2293 (when (and message-max-buffers
2294 (>= (length message-buffer-list
) message-max-buffers
))
2295 ;; Kill the oldest buffer -- unless it has been changed.
2296 (let ((buffer (pop message-buffer-list
)))
2297 (when (and (buffer-name buffer
)
2298 (not (buffer-modified-p buffer
)))
2299 (kill-buffer buffer
))))
2300 ;; Rename the buffer.
2301 (if message-send-rename-function
2302 (funcall message-send-rename-function
)
2303 (when (string-match "\\`\\*" (buffer-name))
2305 (concat "*sent " (substring (buffer-name) (match-end 0))) t
)))
2306 ;; Push the current buffer onto the list.
2307 (when message-max-buffers
2308 (setq message-buffer-list
2309 (nconc message-buffer-list
(list (current-buffer))))))
2311 (defvar mc-modes-alist
)
2312 (defun message-setup (headers &optional replybuffer actions
)
2313 (when (and (boundp 'mc-modes-alist
)
2314 (not (assq 'message-mode mc-modes-alist
)))
2315 (push '(message-mode (encrypt . mc-encrypt-message
)
2316 (sign . mc-sign-message
))
2319 (setq message-send-actions actions
))
2320 (setq message-reply-buffer replybuffer
)
2321 (goto-char (point-min))
2322 ;; Insert all the headers.
2325 (alist message-header-format-alist
))
2327 (unless (assq (caar h
) message-header-format-alist
)
2328 (push (list (caar h
)) alist
))
2332 (delete-region (point) (progn (forward-line -
1) (point)))
2333 (when message-default-headers
2334 (insert message-default-headers
))
2338 (insert mail-header-separator
"\n")
2342 (when (message-news-p)
2343 (when message-default-news-headers
2344 (insert message-default-news-headers
))
2345 (when message-generate-headers-first
2346 (message-generate-headers
2349 (copy-sequence message-required-news-headers
))))))
2350 (when (message-mail-p)
2351 (when message-default-mail-headers
2352 (insert message-default-mail-headers
))
2353 (when message-generate-headers-first
2354 (message-generate-headers
2357 (copy-sequence message-required-mail-headers
))))))
2358 (run-hooks 'message-signature-setup-hook
)
2359 (message-insert-signature)
2360 (message-set-auto-save-file-name)
2362 (message-narrow-to-headers)
2363 (run-hooks 'message-header-setup-hook
))
2364 (set-buffer-modified-p nil
)
2365 (run-hooks 'message-setup-hook
)
2366 (message-position-point)
2369 (defun message-set-auto-save-file-name ()
2370 "Associate the message buffer with a file in the drafts directory."
2371 (when message-autosave-directory
2372 (unless (file-exists-p message-autosave-directory
)
2373 (make-directory message-autosave-directory t
))
2374 (let ((name (make-temp-name
2375 (concat (file-name-as-directory message-autosave-directory
)
2377 (setq buffer-auto-save-file-name
2381 (set-buffer (get-buffer-create " *draft tmp*"))
2382 (setq buffer-file-name name
)
2383 (make-auto-save-file-name))
2384 (kill-buffer (current-buffer)))))
2385 (clear-visited-file-modtime))))
2390 ;;; Commands for interfacing with message
2394 (defun message-mail (&optional to subject
)
2395 "Start editing a mail message to be sent."
2397 (message-pop-to-buffer (message-buffer-name "mail" to
))
2398 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
"")))))
2401 (defun message-news (&optional newsgroups subject
)
2402 "Start editing a news article to be sent."
2404 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups
))
2405 (message-setup `((Newsgroups .
,(or newsgroups
""))
2406 (Subject .
,(or subject
"")))))
2409 (defun message-reply (&optional to-address wide ignore-reply-to
)
2410 "Start editing a reply to the article in the current buffer."
2412 (let ((cur (current-buffer))
2413 from subject date reply-to to cc
2414 references message-id follow-to
2415 mct never-mct gnus-warning
)
2418 (goto-char (point-min))
2419 (if (search-forward "\n\n" nil t
)
2422 ;; Allow customizations to have their say.
2424 ;; This is a regular reply.
2425 (if (message-functionp message-reply-to-function
)
2426 (setq follow-to
(funcall message-reply-to-function
)))
2427 ;; This is a followup.
2428 (if (message-functionp message-wide-reply-to-function
)
2431 (funcall message-wide-reply-to-function
)))))
2432 ;; Find all relevant headers we need.
2433 (setq from
(message-fetch-field "from")
2434 date
(message-fetch-field "date")
2435 subject
(or (message-fetch-field "subject") "none")
2436 to
(message-fetch-field "to")
2437 cc
(message-fetch-field "cc")
2438 mct
(message-fetch-field "mail-copies-to")
2439 reply-to
(unless ignore-reply-to
(message-fetch-field "reply-to"))
2440 references
(message-fetch-field "references")
2441 message-id
(message-fetch-field "message-id"))
2442 ;; Remove any (buggy) Re:'s that are present and make a
2444 (when (string-match "^[ \t]*[Rr][Ee]:[ \t]*" subject
)
2445 (setq subject
(substring subject
(match-end 0))))
2446 (setq subject
(concat "Re: " subject
))
2448 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
2449 (string-match "<[^>]+>" gnus-warning
))
2450 (setq message-id
(match-string 0 gnus-warning
)))
2452 ;; Handle special values of Mail-Copies-To.
2454 (cond ((equal (downcase mct
) "never")
2457 ((equal (downcase mct
) "always")
2458 (setq mct
(or reply-to from
)))))
2463 (setq follow-to
(list (cons 'To
(or to-address reply-to from
))))
2466 (message-set-work-buffer)
2468 (insert (or reply-to from
"")))
2470 (if (bolp) "" ", ") (or to
"")
2471 (if mct
(concat (if (bolp) "" ", ") mct
) "")
2472 (if cc
(concat (if (bolp) "" ", ") cc
) ""))
2473 ;; Remove addresses that match `rmail-dont-reply-to-names'.
2474 (insert (prog1 (rmail-dont-reply-to (buffer-string))
2476 (goto-char (point-min))
2480 (cons (mail-strip-quoted-names addr
) addr
))
2481 (nreverse (mail-parse-comma-list))))
2484 (setq ccalist
(delq (assoc (car (pop s
)) s
) ccalist
)))))
2485 (setq follow-to
(list (cons 'To
(cdr (pop ccalist
)))))
2488 (mapconcat (lambda (addr) (cdr addr
)) ccalist
", "))
2492 (message-pop-to-buffer (message-buffer-name "reply" from
))
2494 (setq message-reply-headers
2495 (vector 0 subject from date message-id references
0 0 ""))
2498 `((Subject .
,subject
)
2500 ,@(if (or references message-id
)
2501 `((References .
,(concat (or references
"") (and references
" ")
2502 (or message-id
""))))
2507 (defun message-wide-reply (&optional to-address
)
2509 (message-reply to-address t
))
2512 (defun message-followup ()
2514 (let ((cur (current-buffer))
2515 from subject date reply-to mct
2516 references message-id follow-to
2517 followup-to distribution newsgroups gnus-warning
)
2520 (goto-char (point-min))
2521 (if (search-forward "\n\n" nil t
)
2524 (when (message-functionp message-followup-to-function
)
2526 (funcall message-followup-to-function
)))
2527 (setq from
(message-fetch-field "from")
2528 date
(message-fetch-field "date")
2529 subject
(or (message-fetch-field "subject") "none")
2530 references
(message-fetch-field "references")
2531 message-id
(message-fetch-field "message-id")
2532 followup-to
(message-fetch-field "followup-to")
2533 newsgroups
(message-fetch-field "newsgroups")
2534 reply-to
(message-fetch-field "reply-to")
2535 distribution
(message-fetch-field "distribution")
2536 mct
(message-fetch-field "mail-copies-to"))
2537 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
2538 (string-match "<[^>]+>" gnus-warning
))
2539 (setq message-id
(match-string 0 gnus-warning
)))
2540 ;; Remove bogus distribution.
2541 (and (stringp distribution
)
2542 (string-match "world" distribution
)
2543 (setq distribution nil
))
2544 ;; Remove any (buggy) Re:'s that are present and make a
2546 (when (string-match "^[ \t]*[Rr][Ee]:[ \t]*" subject
)
2547 (setq subject
(substring subject
(match-end 0))))
2548 (setq subject
(concat "Re: " subject
))
2551 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups
))
2554 `((Subject .
,subject
)
2556 (follow-to follow-to
)
2557 ((and followup-to message-use-followup-to
)
2560 ((equal (downcase followup-to
) "poster")
2561 (if (or (eq message-use-followup-to
'use
)
2562 (message-y-or-n-p "Obey Followup-To: poster? " t
"\
2563 You should normally obey the Followup-To: header.
2565 `Followup-To: poster' sends your response via e-mail instead of news.
2567 A typical situation where `Followup-To: poster' is used is when the poster
2568 does not read the newsgroup, so he wouldn't see any replies sent to it."))
2569 (cons 'To
(or reply-to from
""))
2570 (cons 'Newsgroups newsgroups
)))
2572 (if (or (equal followup-to newsgroups
)
2573 (not (eq message-use-followup-to
'ask
))
2575 (concat "Obey Followup-To: " followup-to
"? ") t
"\
2576 You should normally obey the Followup-To: header.
2578 `Followup-To: " followup-to
"'
2579 directs your response to " (if (string-match "," followup-to
)
2580 "the specified newsgroups"
2581 "that newsgroup only") ".
2583 If a message is posted to several newsgroups, Followup-To is often
2584 used to direct the following discussion to one newsgroup only,
2585 because discussions that are spread over several newsgroup tend to
2586 be fragmented and very difficult to follow.
2588 Also, some source/announcment newsgroups are not indented for discussion;
2589 responses here are directed to other newsgroups."))
2590 (cons 'Newsgroups followup-to
)
2591 (cons 'Newsgroups newsgroups
))))))
2593 `((Newsgroups .
,newsgroups
))))
2594 ,@(and distribution
(list (cons 'Distribution distribution
)))
2595 (References .
,(concat (or references
"") (and references
" ")
2596 (or message-id
"")))
2598 (not (equal (downcase mct
) "never")))
2599 (list (cons 'Cc
(if (equal (downcase mct
) "always")
2600 (or reply-to from
"")
2605 (setq message-reply-headers
2606 (vector 0 subject from date message-id references
0 0 ""))))
2610 (defun message-cancel-news ()
2611 "Cancel an article you posted."
2613 (unless (message-news-p)
2614 (error "This is not a news article; canceling is impossible"))
2615 (when (yes-or-no-p "Do you really want to cancel this article? ")
2616 (let (from newsgroups message-id distribution buf
)
2618 ;; Get header info. from original article.
2620 (message-narrow-to-head)
2621 (setq from
(message-fetch-field "from")
2622 newsgroups
(message-fetch-field "newsgroups")
2623 message-id
(message-fetch-field "message-id")
2624 distribution
(message-fetch-field "distribution")))
2625 ;; Make sure that this article was written by the user.
2626 (unless (string-equal
2627 (downcase (cadr (mail-extract-address-components from
)))
2628 (downcase (message-make-address)))
2629 (error "This article is not yours"))
2630 ;; Make control message.
2631 (setq buf
(set-buffer (get-buffer-create " *message cancel*")))
2632 (buffer-disable-undo (current-buffer))
2634 (insert "Newsgroups: " newsgroups
"\n"
2635 "From: " (message-make-from) "\n"
2636 "Subject: cmsg cancel " message-id
"\n"
2637 "Control: cancel " message-id
"\n"
2639 (concat "Distribution: " distribution
"\n")
2641 mail-header-separator
"\n"
2642 "This is a cancel message from " from
".\n")
2643 (message "Canceling your article...")
2644 (let ((message-syntax-checks 'dont-check-for-anything-just-trust-me
))
2645 (funcall message-send-news-function
))
2646 (message "Canceling your article...done")
2647 (kill-buffer buf
)))))
2650 (defun message-supersede ()
2651 "Start composing a message to supersede the current message.
2652 This is done simply by taking the old article and adding a Supersedes
2653 header line with the old Message-ID."
2655 (let ((cur (current-buffer)))
2656 ;; Check whether the user owns the article that is to be superseded.
2657 (unless (string-equal
2658 (downcase (cadr (mail-extract-address-components
2659 (message-fetch-field "from"))))
2660 (downcase (message-make-address)))
2661 (error "This article is not yours"))
2662 ;; Get a normal message buffer.
2663 (message-pop-to-buffer (message-buffer-name "supersede"))
2664 (insert-buffer-substring cur
)
2665 (message-narrow-to-head)
2666 ;; Remove unwanted headers.
2667 (when message-ignored-supersedes-headers
2668 (message-remove-header message-ignored-supersedes-headers t
))
2669 (goto-char (point-min))
2670 (if (not (re-search-forward "^Message-ID: " nil t
))
2671 (error "No Message-ID in this article")
2672 (replace-match "Supersedes: " t t
))
2673 (goto-char (point-max))
2674 (insert mail-header-separator
)
2679 (defun message-recover ()
2680 "Reread contents of current buffer from its last auto-save file."
2682 (let ((file-name (make-auto-save-file-name)))
2683 (cond ((save-window-excursion
2684 (if (not (eq system-type
'vax-vms
))
2685 (with-output-to-temp-buffer "*Directory*"
2686 (buffer-disable-undo standard-output
)
2687 (let ((default-directory "/"))
2689 "ls" nil standard-output nil
"-l" file-name
))))
2690 (yes-or-no-p (format "Recover auto save file %s? " file-name
)))
2691 (let ((buffer-read-only nil
))
2693 (insert-file-contents file-name nil
)))
2694 (t (error "message-recover cancelled")))))
2696 ;;; Forwarding messages.
2698 (defun message-make-forward-subject ()
2699 "Return a Subject header suitable for the message in the current buffer."
2700 (concat "[" (or (message-fetch-field (if (message-news-p) "newsgroups" "from"))
2702 "] " (or (message-fetch-field "Subject") "")))
2705 (defun message-forward (&optional news
)
2706 "Forward the current message via mail.
2707 Optional NEWS will use news to forward instead of mail."
2709 (let ((cur (current-buffer))
2710 (subject (message-make-forward-subject)))
2711 (if news
(message-news nil subject
) (message-mail nil subject
))
2712 ;; Put point where we want it before inserting the forwarded
2714 (if message-signature-before-forwarded-message
2715 (goto-char (point-max))
2716 (message-goto-body))
2717 ;; Make sure we're at the start of the line.
2720 ;; Narrow to the area we are to insert.
2721 (narrow-to-region (point) (point))
2722 ;; Insert the separators and the forwarded buffer.
2723 (insert message-forward-start-separator
)
2724 (insert-buffer-substring cur
)
2725 (goto-char (point-max))
2726 (insert message-forward-end-separator
)
2727 (set-text-properties (point-min) (point-max) nil
)
2728 ;; Remove all unwanted headers.
2729 (goto-char (point-min))
2731 (narrow-to-region (point) (if (search-forward "\n\n" nil t
)
2734 (goto-char (point-min))
2735 (message-remove-header message-included-forward-headers t nil t
)
2737 (message-position-point)))
2740 (defun message-resend (address)
2741 "Resend the current article to ADDRESS."
2742 (interactive "sResend message to: ")
2744 (let ((cur (current-buffer))
2746 ;; We first set up a normal mail buffer.
2747 (set-buffer (get-buffer-create " *message resend*"))
2748 (buffer-disable-undo (current-buffer))
2750 (message-setup `((To .
,address
)))
2751 ;; Insert our usual headers.
2752 (message-generate-headers '(From Date To
))
2753 (message-narrow-to-headers)
2754 ;; Rename them all to "Resent-*".
2755 (while (re-search-forward "^[A-Za-z]" nil t
)
2760 (delete-region (point) (point-max))
2762 ;; Insert the message to be resent.
2763 (insert-buffer-substring cur
)
2764 (goto-char (point-min))
2765 (search-forward "\n\n")
2768 (narrow-to-region beg
(point))
2769 (message-remove-header message-ignored-resent-headers t
)
2770 (goto-char (point-max)))
2771 (insert mail-header-separator
)
2772 ;; Rename all old ("Also-")Resent headers.
2773 (while (re-search-backward "^\\(Also-\\)?Resent-" beg t
)
2778 (kill-buffer (current-buffer)))))
2781 (defun message-bounce ()
2782 "Re-mail the current message.
2783 This only makes sense if the current message is a bounce message than
2784 contains some mail you have written which has been bounced back to
2787 (let ((cur (current-buffer))
2789 (message-pop-to-buffer (message-buffer-name "bounce"))
2790 (insert-buffer-substring cur
)
2792 (message-narrow-to-head)
2793 (if (and (message-fetch-field "Mime-Version")
2794 (setq boundary
(message-fetch-field "Content-Type")))
2795 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary
)
2796 (setq boundary
(concat (match-string 1 boundary
) " *\n"
2797 "Content-Type: message/rfc822"))
2798 (setq boundary nil
)))
2800 (goto-char (point-min))
2801 (search-forward "\n\n" nil t
)
2803 (re-search-forward boundary nil t
)
2805 (and (re-search-forward message-unsent-separator nil t
)
2807 (and (search-forward "\n\n" nil t
)
2808 (re-search-forward "^Return-Path:.*\n" nil t
)))
2809 ;; We remove everything before the bounced mail.
2812 (if (re-search-forward "^[^ \n\t]+:" nil t
)
2816 (message-narrow-to-head)
2817 (message-remove-header message-ignored-bounced-headers t
)
2818 (goto-char (point-max))
2819 (insert mail-header-separator
))
2820 (message-position-point)))
2823 ;;; Interactive entry points for new message buffers.
2827 (defun message-mail-other-window (&optional to subject
)
2828 "Like `message-mail' command, but display mail buffer in another window."
2830 (let ((pop-up-windows t
)
2831 (special-display-buffer-names nil
)
2832 (special-display-regexps nil
)
2833 (same-window-buffer-names nil
)
2834 (same-window-regexps nil
))
2835 (message-pop-to-buffer (message-buffer-name "mail" to
)))
2836 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
"")))))
2839 (defun message-mail-other-frame (&optional to subject
)
2840 "Like `message-mail' command, but display mail buffer in another frame."
2842 (let ((pop-up-frames t
)
2843 (special-display-buffer-names nil
)
2844 (special-display-regexps nil
)
2845 (same-window-buffer-names nil
)
2846 (same-window-regexps nil
))
2847 (message-pop-to-buffer (message-buffer-name "mail" to
)))
2848 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
"")))))
2851 (defun message-news-other-window (&optional newsgroups subject
)
2852 "Start editing a news article to be sent."
2854 (let ((pop-up-windows t
)
2855 (special-display-buffer-names nil
)
2856 (special-display-regexps nil
)
2857 (same-window-buffer-names nil
)
2858 (same-window-regexps nil
))
2859 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups
)))
2860 (message-setup `((Newsgroups .
,(or newsgroups
""))
2861 (Subject .
,(or subject
"")))))
2864 (defun message-news-other-frame (&optional newsgroups subject
)
2865 "Start editing a news article to be sent."
2867 (let ((pop-up-frames t
)
2868 (special-display-buffer-names nil
)
2869 (special-display-regexps nil
)
2870 (same-window-buffer-names nil
)
2871 (same-window-regexps nil
))
2872 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups
)))
2873 (message-setup `((Newsgroups .
,(or newsgroups
""))
2874 (Subject .
,(or subject
"")))))
2878 ;; This code should be moved to underline.el (from which it is stolen).
2881 (defun bold-region (start end
)
2882 "Bold all nonblank characters in the region.
2883 Works by overstriking characters.
2884 Called from program, takes two arguments START and END
2885 which specify the range to operate on."
2888 (let ((end1 (make-marker)))
2889 (move-marker end1
(max start end
))
2890 (goto-char (min start end
))
2891 (while (< (point) end1
)
2892 (or (looking-at "[_\^@- ]")
2893 (insert (following-char) "\b"))
2894 (forward-char 1)))))
2897 (defun unbold-region (start end
)
2898 "Remove all boldness (overstruck characters) in the region.
2899 Called from program, takes two arguments START and END
2900 which specify the range to operate on."
2903 (let ((end1 (make-marker)))
2904 (move-marker end1
(max start end
))
2905 (goto-char (min start end
))
2906 (while (re-search-forward "\b" end1 t
)
2907 (if (eq (following-char) (char-after (- (point) 2)))
2908 (delete-char -
2))))))
2910 (fset 'message-exchange-point-and-mark
'exchange-point-and-mark
)
2912 ;; Support for toolbar
2913 (when (string-match "XEmacs\\|Lucid" emacs-version
)
2914 (require 'messagexmas
))
2916 ;;; Group name completion.
2918 (defvar message-newgroups-header-regexp
2919 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\):"
2920 "Regexp that match headers that lists groups.")
2922 (defun message-tab ()
2923 "Expand group names in Newsgroups and Followup-To headers.
2924 Do a `tab-to-tab-stop' if not in those headers."
2926 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp
))
2927 (mail-abbrev-in-expansion-header-p))
2928 (message-expand-group)
2931 (defvar gnus-active-hashtb
)
2932 (defun message-expand-group ()
2933 (let* ((b (save-excursion (skip-chars-backward "^, :\t\n") (point)))
2934 (completion-ignore-case t
)
2935 (string (buffer-substring b
(point)))
2936 (hashtb (and (boundp 'gnus-active-hashtb
) gnus-active-hashtb
))
2937 (completions (all-completions string hashtb
))
2938 (cur (current-buffer))
2940 (delete-region b
(point))
2942 ((= (length completions
) 1)
2943 (if (string= (car completions
) string
)
2946 (message "Only matching group"))
2947 (insert (car completions
))))
2948 ((and (setq comp
(try-completion string hashtb
))
2949 (not (string= comp string
)))
2954 (message "No matching groups")
2955 (pop-to-buffer "*Completions*")
2956 (buffer-disable-undo (current-buffer))
2957 (let ((buffer-read-only nil
))
2959 (let ((standard-output (current-buffer)))
2960 (display-completion-list (sort completions
'string
<)))
2961 (goto-char (point-min))
2962 (pop-to-buffer cur
)))))))
2966 (defmacro message-y-or-n-p
(question show
&rest text
)
2967 "Ask QUESTION, displaying the rest of the arguments in a temporary buffer."
2968 `(message-talkative-question 'y-or-n-p
,question
,show
,@text
))
2970 (defun message-talkative-question (ask question show
&rest text
)
2971 "Call FUNCTION with argument QUESTION, displaying the rest of the arguments in a temporary buffer if SHOW.
2972 The following arguments may contain lists of values."
2974 (setq text
(message-flatten-list text
)))
2975 (save-window-excursion
2977 (with-output-to-temp-buffer " *MESSAGE information message*"
2978 (set-buffer " *MESSAGE information message*")
2979 (mapcar 'princ text
)
2980 (goto-char (point-min))))
2981 (funcall ask question
))
2982 (funcall ask question
)))
2984 (defun message-flatten-list (&rest list
)
2985 (message-flatten-list-1 list
))
2987 (defun message-flatten-list-1 (list)
2989 (apply 'append
(mapcar 'message-flatten-list-1 list
)))
2993 (run-hooks 'message-load-hook
)
2997 ;;; message.el ends here