Initial revision
[bpt/emacs.git] / lisp / mail / sendmail.el
CommitLineData
20a8832d
RS
1;; Mail sending commands for Emacs.
2;; Copyright (C) 1985, 1986 Free Software Foundation, Inc.
3
4;; This file is part of GNU Emacs.
5
6;; GNU Emacs is free software; you can redistribute it and/or modify
7;; it under the terms of the GNU General Public License as published by
8;; the Free Software Foundation; either version 1, or (at your option)
9;; any later version.
10
11;; GNU Emacs is distributed in the hope that it will be useful,
12;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14;; GNU General Public License for more details.
15
16;; You should have received a copy of the GNU General Public License
17;; along with GNU Emacs; see the file COPYING. If not, write to
18;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19
20
21(provide 'sendmail)
22
23;;;###autoload
24(defconst mail-self-blind nil "\
25Non-nil means insert BCC to self in messages to be sent.
26This is done when the message is initialized,
27so you can remove or alter the BCC field to override the default.")
28
29;;;###autoload
30(defconst mail-interactive nil "\
31Non-nil means when sending a message wait for and display errors.
32nil means let mailer mail back a message to report errors.")
33
34;;;###autoload
35(defconst mail-yank-ignored-headers "^via:\\|^mail-from:\\|^origin:\\|^status:\\|^remailed\\|^received:\\|^message-id:\\|^summary-line:\\|^to:\\|^subject:\\|^in-reply-to:\\|^return-path:" "\
36Delete these headers from old message when it's inserted in a reply.")
37
38;; Useful to set in site-init.el
39;;;###autoload
40(defconst send-mail-function 'sendmail-send-it "\
41Function to call to send the current buffer as mail.
42The headers are be delimited by a line which is mail-header-separator.")
43
44;;;###autoload
45(defvar mail-header-separator "--text follows this line--" "\
46*Line used to separate headers from text in messages being composed.")
47
48;;;###autoload
49(defvar mail-archive-file-name nil "\
50*Name of file to write all outgoing messages in, or nil for none.
51Do not use an rmail file here! Instead, use its inbox file.")
52
53;;;###autoload
54(defvar mail-aliases t "\
55Alias of mail address aliases,
56or t meaning should be initialized from .mailrc.")
57
58(defvar mail-default-reply-to nil
59 "*Address to insert as default Reply-to field of outgoing messages.")
60
61(defvar mail-alias-file nil
62 "*If non-nil, the name of a file to use instead of `/usr/lib/aliases'.
63This file defines aliases to be expanded by the mailer; this is a different
64feature from that of defining aliases in `.mailrc' to be expanded in Emacs.
65This variable has no effect unless your system uses sendmail as its mailer.")
66
67(defvar mail-yank-prefix nil
68 "*Prefix insert on lines of yanked message being replied to.
69nil means use indentation.")
70
71(defvar mail-abbrevs-loaded nil)
72(defvar mail-mode-map nil)
73
74(defvar mail-signature nil
75 "*Text inserted at end of mail buffer when a message is initialized.
76If t, it means to insert the contents of the file `~/.signature'.")
77
78(defvar mail-reply-buffer nil)
79(defvar mail-send-actions nil
80 "A list of actions to be performed upon successful sending of a message.")
81
82(defvar mail-default-headers nil
83 "*A string containing header lines, to be inserted in outgoing messages.
84It is inserted before you edit the message,
85so you can edit or delete these lines.")
86
87(defvar mail-mode-syntax-table nil
88 "Syntax table used while in mail mode.")
89
90(if (null mail-mode-syntax-table)
91 (progn
92 (setq mail-mode-syntax-table (copy-syntax-table text-mode-syntax-table))
93 (modify-syntax-entry ?% ". " mail-mode-syntax-table)))
94
95(autoload 'build-mail-aliases "mailalias"
96 "Read mail aliases from ~/.mailrc and set mail-aliases."
97 nil)
98
99(autoload 'expand-mail-aliases "mailalias"
100 "Expand all mail aliases in suitable header fields found between BEG and END.
101Suitable header fields are To, CC and BCC."
102 nil)
103
104(defun mail-setup (to subject in-reply-to cc replybuffer actions)
105 (setq mail-send-actions actions)
106 (if (eq mail-aliases t)
107 (progn
108 (setq mail-aliases nil)
109 (if (file-exists-p "~/.mailrc")
110 (build-mail-aliases))))
111 (setq mail-reply-buffer replybuffer)
112 (goto-char (point-min))
113 (insert "To: ")
114 (save-excursion
115 (if to
116 (progn
117 (insert to "\n")
118 ;;; Here removed code to extract names from within <...>
119 ;;; on the assumption that mail-strip-quoted-names
120 ;;; has been called and has done so.
121 (let ((fill-prefix "\t"))
122 (fill-region (point-min) (point-max))))
123 (newline))
124 (if cc
125 (let ((opos (point))
126 (fill-prefix "\t"))
127 (insert "CC: " cc "\n")
128 (fill-region-as-paragraph opos (point-max))))
129 (if in-reply-to
130 (insert "In-reply-to: " in-reply-to "\n"))
131 (insert "Subject: " (or subject "") "\n")
132 (if mail-default-headers
133 (insert mail-default-headers))
134 (if mail-default-reply-to
135 (insert "Reply-to: " mail-default-reply-to "\n"))
136 (if mail-self-blind
137 (insert "BCC: " (user-login-name) "\n"))
138 (if mail-archive-file-name
139 (insert "FCC: " mail-archive-file-name "\n"))
140 (insert mail-header-separator "\n")
141 ;; Read the .signature file if we haven't already done so
142 ;; (and if the user has not overridden it).
143 (cond ((eq mail-signature t)
144 (insert "--\n")
145 (insert-file-contents "~/.signature"))
146 (mail-signature
147 (insert mail-signature)))
148 (goto-char (point-max))
149 (or (bolp) (newline)))
150 (if to (goto-char (point-max)))
151 (or to subject in-reply-to
152 (set-buffer-modified-p nil))
153 (run-hooks 'mail-setup-hook))
154
155;;;###autoload
156(defun mail-mode ()
157 "Major mode for editing mail to be sent.
158Like Text Mode but with these additional commands:
159C-c C-s mail-send (send the message) C-c C-c mail-send-and-exit
160C-c C-f move to a header field (and create it if there isn't):
161 C-c C-f C-t move to To: C-c C-f C-s move to Subj:
162 C-c C-f C-b move to BCC: C-c C-f C-c move to CC:
163C-c C-t move to message text.
164C-c C-y mail-yank-original (insert current message, in Rmail).
165C-c C-q mail-fill-yanked-message (fill what was yanked).
166C-c C-v mail-sent-via (add a sent-via field for each To or CC)."
167 (interactive)
168 (kill-all-local-variables)
169 (make-local-variable 'mail-reply-buffer)
170 (setq mail-reply-buffer nil)
171 (make-local-variable 'mail-send-actions)
172 (set-syntax-table mail-mode-syntax-table)
173 (use-local-map mail-mode-map)
174 (setq local-abbrev-table text-mode-abbrev-table)
175 (setq major-mode 'mail-mode)
176 (setq mode-name "Mail")
177 (setq buffer-offer-save t)
178 (make-local-variable 'paragraph-separate)
179 (make-local-variable 'paragraph-start)
180 (setq paragraph-start (concat "^" mail-header-separator
181 "$\\|^[ \t]*[-_][-_][-_]+$\\|"
182 paragraph-start))
183 (setq paragraph-separate (concat "^" mail-header-separator
184 "$\\|^[ \t]*[-_][-_][-_]+$\\|"
185 paragraph-separate))
186 (run-hooks 'text-mode-hook 'mail-mode-hook))
187
188(if mail-mode-map
189 nil
190 (setq mail-mode-map (nconc (make-sparse-keymap) text-mode-map))
191 (define-key mail-mode-map "\C-c?" 'describe-mode)
192 (define-key mail-mode-map "\C-c\C-f\C-t" 'mail-to)
193 (define-key mail-mode-map "\C-c\C-f\C-b" 'mail-bcc)
194 (define-key mail-mode-map "\C-c\C-f\C-c" 'mail-cc)
195 (define-key mail-mode-map "\C-c\C-f\C-s" 'mail-subject)
196 (define-key mail-mode-map "\C-c\C-t" 'mail-text)
197 (define-key mail-mode-map "\C-c\C-y" 'mail-yank-original)
198 (define-key mail-mode-map "\C-c\C-q" 'mail-fill-yanked-message)
199 (define-key mail-mode-map "\C-c\C-w" 'mail-signature)
200 (define-key mail-mode-map "\C-c\C-v" 'mail-sent-via)
201 (define-key mail-mode-map "\C-c\C-c" 'mail-send-and-exit)
202 (define-key mail-mode-map "\C-c\C-s" 'mail-send))
203\f
204(defun mail-send-and-exit (arg)
205 "Send message like mail-send, then, if no errors, exit from mail buffer.
206Prefix arg means don't delete this window."
207 (interactive "P")
208 (mail-send)
209 (bury-buffer (current-buffer))
210 (if (or (one-window-p) arg)
211 (switch-to-buffer (other-buffer (current-buffer)))
212 (delete-window)))
213
214(defun mail-send ()
215 "Send the message in the current buffer.
216If `mail-interactive' is non-nil, wait for success indication
217or error messages, and inform user.
218Otherwise any failure is reported in a message back to
219the user from the mailer."
220 (interactive)
221 (if (or (buffer-modified-p)
222 (y-or-n-p "Message already sent; resend? "))
223 (progn
224 (message "Sending...")
225 (run-hooks 'mail-send-hook)
226 (funcall send-mail-function)
227 ;; Now perform actions on successful sending.
228 (while mail-send-actions
229 (condition-case nil
230 (apply (car (car mail-send-actions)) (cdr (car mail-send-actions)))
231 (error))
232 (setq mail-send-actions (cdr mail-send-actions)))
233 (set-buffer-modified-p nil)
234 (delete-auto-save-file-if-necessary t)
235 (message "Sending...done"))))
236
237(defun sendmail-send-it ()
238 (let ((errbuf (if mail-interactive
239 (generate-new-buffer " sendmail errors")
240 0))
241 (tembuf (generate-new-buffer " sendmail temp"))
242 (case-fold-search nil)
243 delimline
244 (mailbuf (current-buffer)))
245 (unwind-protect
246 (save-excursion
247 (set-buffer tembuf)
248 (erase-buffer)
249 (insert-buffer-substring mailbuf)
250 (goto-char (point-max))
251 ;; require one newline at the end.
252 (or (= (preceding-char) ?\n)
253 (insert ?\n))
254 ;; Change header-delimiter to be what sendmail expects.
255 (goto-char (point-min))
256 (re-search-forward
257 (concat "^" (regexp-quote mail-header-separator) "\n"))
258 (replace-match "\n")
259 (backward-char 1)
260 (setq delimline (point-marker))
261 (if mail-aliases
262 (expand-mail-aliases (point-min) delimline))
263 (goto-char (point-min))
264 ;; ignore any blank lines in the header
265 (while (and (re-search-forward "\n\n\n*" delimline t)
266 (< (point) delimline))
267 (replace-match "\n"))
268 (let ((case-fold-search t))
269 (goto-char (point-min))
270 (if (re-search-forward "^Sender:" delimline t)
271 (error "Sender may not be specified."))
272 ;; Find and handle any FCC fields.
273 (goto-char (point-min))
274 (if (re-search-forward "^FCC:" delimline t)
275 (mail-do-fcc delimline))
276 ;; If the From is different than current user, insert Sender.
277 (goto-char (point-min))
278 (and (re-search-forward "^From:" delimline t)
279 (progn
280 (require 'mail-utils)
281 (not (string-equal
282 (mail-strip-quoted-names
283 (save-restriction
284 (narrow-to-region (point-min) delimline)
285 (mail-fetch-field "From")))
286 (user-login-name))))
287 (progn
288 (forward-line 1)
289 (insert "Sender: " (user-login-name) "\n")))
290 ;; "S:" is an abbreviation for "Subject:".
291 (goto-char (point-min))
292 (if (re-search-forward "^S:" delimline t)
293 (replace-match "Subject:"))
294 ;; Don't send out a blank subject line
295 (goto-char (point-min))
296 (if (re-search-forward "^Subject:[ \t]*\n" delimline t)
297 (replace-match ""))
298 (if mail-interactive
299 (save-excursion
300 (set-buffer errbuf)
301 (erase-buffer))))
302 (apply 'call-process-region
303 (append (list (point-min) (point-max)
304 (if (boundp 'sendmail-program)
305 sendmail-program
306 "/usr/lib/sendmail")
307 nil errbuf nil
308 "-oi" "-t")
309 ;; Always specify who from,
310 ;; since some systems have broken sendmails.
311 (list "-f" (user-login-name))
312;;; ;; Don't say "from root" if running under su.
313;;; (and (equal (user-real-login-name) "root")
314;;; (list "-f" (user-login-name)))
315 (and mail-alias-file
316 (list (concat "-oA" mail-alias-file)))
317 ;; These mean "report errors by mail"
318 ;; and "deliver in background".
319 (if (null mail-interactive) '("-oem" "-odb"))))
320 (if mail-interactive
321 (save-excursion
322 (set-buffer errbuf)
323 (goto-char (point-min))
324 (while (re-search-forward "\n\n* *" nil t)
325 (replace-match "; "))
326 (if (not (zerop (buffer-size)))
327 (error "Sending...failed to %s"
328 (buffer-substring (point-min) (point-max)))))))
329 (kill-buffer tembuf)
330 (if (bufferp errbuf)
331 (kill-buffer errbuf)))))
332
333(defun mail-do-fcc (header-end)
334 (let (fcc-list
335 (rmailbuf (current-buffer))
336 (tembuf (generate-new-buffer " rmail output"))
337 (case-fold-search t))
338 (save-excursion
339 (goto-char (point-min))
340 (while (re-search-forward "^FCC:[ \t]*" header-end t)
341 (setq fcc-list (cons (buffer-substring (point)
342 (progn
343 (end-of-line)
344 (skip-chars-backward " \t")
345 (point)))
346 fcc-list))
347 (delete-region (match-beginning 0)
348 (progn (forward-line 1) (point))))
349 (set-buffer tembuf)
350 (erase-buffer)
351 (insert "\nFrom " (user-login-name) " "
352 (current-time-string) "\n")
353 (insert-buffer-substring rmailbuf)
354 ;; Make sure messages are separated.
355 (goto-char (point-max))
356 (insert ?\n)
357 (goto-char 2)
358 ;; ``Quote'' "^From " as ">From "
359 ;; (note that this isn't really quoting, as there is no requirement
360 ;; that "^[>]+From " be quoted in the same transparent way.)
361 (let ((case-fold-search nil))
362 (while (search-forward "\nFrom " nil t)
363 (forward-char -5)
364 (insert ?>)))
365 (while fcc-list
366 (let ((buffer (get-file-buffer (car fcc-list))))
367 (if buffer
368 ;; File is present in a buffer => append to that buffer.
369 (let ((curbuf (current-buffer))
370 (beg (point-min)) (end (point-max)))
371 (save-excursion
372 (set-buffer buffer)
373 ;; Keep the end of the accessible portion at the same place
374 ;; unless it is the end of the buffer.
375 (let ((max (if (/= (1+ (buffer-size)) (point-max))
376 (point-max))))
377 (unwind-protect
378 (progn
379 (narrow-to-region (point-min) (1+ (buffer-size)))
380 (goto-char (point-max))
381 (if (eq major-mode 'rmail-mode)
382 ;; Append as a message to an RMAIL file
383 (let ((buffer-read-only nil))
384 ;; This forces RMAIL's message counters to be
385 ;; recomputed when the next RMAIL operation is
386 ;; done on the buffer.
387 ;; See rmail-maybe-set-message-counters.
388 (setq rmail-total-messages nil)
389 (insert "\C-l\n0, unseen,,\n*** EOOH ***\n"
390 "From: " (user-login-name) "\n"
391 "Date: " (current-time-string) "\n")
392 (insert-buffer-substring curbuf beg end)
393 (insert "\n\C-_"))
394 (insert-buffer-substring curbuf beg end)))
395 (if max (narrow-to-region (point-min) max))))))
396 ;; Else append to the file directly.
397 (write-region
398 ;; Include a blank line before if file already exists.
399 (if (file-exists-p (car fcc-list)) (point-min) (1+ (point-min)))
400 (point-max) (car fcc-list) t)))
401 (setq fcc-list (cdr fcc-list))))
402 (kill-buffer tembuf)))
403
404(defun mail-sent-via ()
405 "Make a Sent-via header line from each To or CC header line."
406 (interactive)
407 (save-excursion
408 (goto-char (point-min))
409 ;; find the header-separator
410 (search-forward (concat "\n" mail-header-separator "\n"))
411 (forward-line -1)
412 ;; put a marker at the end of the header
413 (let ((end (point-marker))
414 (case-fold-search t)
415 to-line)
416 (goto-char (point-min))
417 ;; search for the To: lines and make Sent-via: lines from them
418 ;; search for the next To: line
419 (while (re-search-forward "^\\(to\\|cc\\):" end t)
420 ;; Grab this line plus all its continuations, sans the `to:'.
421 (let ((to-line
422 (buffer-substring (point)
423 (progn
424 (if (re-search-forward "^[^ \t\n]" end t)
425 (backward-char 1)
426 (goto-char end))
427 (point)))))
428 ;; Insert a copy, with altered header field name.
429 (insert-before-markers "Sent-via:" to-line))))))
430\f
431(defun mail-to ()
432 "Move point to end of To-field."
433 (interactive)
434 (expand-abbrev)
435 (mail-position-on-field "To"))
436
437(defun mail-subject ()
438 "Move point to end of Subject-field."
439 (interactive)
440 (expand-abbrev)
441 (mail-position-on-field "Subject"))
442
443(defun mail-cc ()
444 "Move point to end of CC-field. Create a CC field if none."
445 (interactive)
446 (expand-abbrev)
447 (or (mail-position-on-field "cc" t)
448 (progn (mail-position-on-field "to")
449 (insert "\nCC: "))))
450
451(defun mail-bcc ()
452 "Move point to end of BCC-field. Create a BCC field if none."
453 (interactive)
454 (expand-abbrev)
455 (or (mail-position-on-field "bcc" t)
456 (progn (mail-position-on-field "to")
457 (insert "\nBCC: "))))
458
459(defun mail-position-on-field (field &optional soft)
460 (let (end
461 (case-fold-search t))
462 (goto-char (point-min))
463 (search-forward (concat "\n" mail-header-separator "\n"))
464 (setq end (match-beginning 0))
465 (goto-char (point-min))
466 (if (re-search-forward (concat "^" (regexp-quote field) ":") end t)
467 (progn
468 (re-search-forward "^[^ \t]" nil 'move)
469 (beginning-of-line)
470 (skip-chars-backward "\n")
471 t)
472 (or soft
473 (progn (goto-char end)
474 (skip-chars-backward "\n")
475 (insert "\n" field ": ")))
476 nil)))
477
478(defun mail-text ()
479 "Move point to beginning of text field."
480 (interactive)
481 (goto-char (point-min))
482 (search-forward (concat "\n" mail-header-separator "\n")))
483\f
484(defun mail-signature ()
485 "Sign letter with contents of ~/.signature file."
486 (interactive)
487 (save-excursion
488 (goto-char (point-max))
489 (skip-chars-backward " \t\n")
490 (end-of-line)
491 (delete-region (point) (point-max))
492 (insert "\n\n--\n")
493 (insert-file-contents (expand-file-name "~/.signature"))))
494
495(defun mail-fill-yanked-message (&optional justifyp)
496 "Fill the paragraphs of a message yanked into this one.
497Numeric argument means justify as well."
498 (interactive "P")
499 (save-excursion
500 (goto-char (point-min))
501 (search-forward (concat "\n" mail-header-separator "\n") nil t)
502 (fill-individual-paragraphs (point)
503 (point-max)
504 justifyp
505 t)))
506
507(defun mail-yank-original (arg)
508 "Insert the message being replied to, if any (in rmail).
509Puts point before the text and mark after.
510Normally, indents each nonblank line ARG spaces (default 3).
511However, if `mail-yank-prefix' is non-nil, insert that prefix on each line.
512
513Just \\[universal-argument] as argument means don't indent, insert no prefix,
514and don't delete any header fields."
515 (interactive "P")
516 (if mail-reply-buffer
517 (let ((start (point)))
518 (delete-windows-on mail-reply-buffer)
519 (insert-buffer mail-reply-buffer)
520 (if (consp arg)
521 nil
522 (mail-yank-clear-headers start (mark))
523 (if (null mail-yank-prefix)
524 (indent-rigidly start (mark)
525 (if arg (prefix-numeric-value arg) 3))
526 (save-excursion
527 (goto-char start)
528 (while (< (point) (mark))
529 (insert mail-yank-prefix)
530 (forward-line 1)))))
531 (exchange-point-and-mark)
532 (if (not (eolp)) (insert ?\n)))))
533
534(defun mail-yank-clear-headers (start end)
535 (save-excursion
536 (goto-char start)
537 (if (search-forward "\n\n" end t)
538 (save-restriction
539 (narrow-to-region start (point))
540 (goto-char start)
541 (while (let ((case-fold-search t))
542 (re-search-forward mail-yank-ignored-headers nil t))
543 (beginning-of-line)
544 (delete-region (point)
545 (progn (re-search-forward "\n[^ \t]")
546 (forward-char -1)
547 (point))))))))
548\f
549;; Put these last, to reduce chance of lossage from quitting in middle of loading the file.
550
551;;;###autoload
552(defun mail (&optional noerase to subject in-reply-to cc replybuffer actions)
553 "Edit a message to be sent. Argument means resume editing (don't erase).
554Search for an existing mail buffer currently not in use and initialize it,
555or make a new one if all existing mail buffers are busy.
556With an argument, search for a busy existing mail buffer and re-select it.
557
558Returns with message buffer selected; value t if message freshly initialized.
559By default, the signature file `~/.signature' is inserted at the end;
560see the variable `mail-signature'.
561
562\\<mail-mode-map>
563While editing message, type \\[mail-send-and-exit] to send the message and exit.
564
565Various special commands starting with C-c are available in sendmail mode
566to move to message header fields:
567\\{mail-mode-map}
568
569If `mail-self-blind' is non-nil, a BCC to yourself is inserted
570when the message is initialized.
571
572If `mail-default-reply-to' is non-nil, it should be an address (a string);
573a Reply-to: field with that address is inserted.
574
575If `mail-archive-file-name' is non-nil, an FCC field with that file name
576is inserted.
577
578If `mail-setup-hook' is bound, its value is called with no arguments
579after the message is initialized. It can add more default fields.
580
581When calling from a program, the second through fifth arguments
582 TO, SUBJECT, IN-REPLY-TO and CC specify if non-nil
583 the initial contents of those header fields.
584 These arguments should not have final newlines.
585The sixth argument REPLYBUFFER is a buffer whose contents
586 should be yanked if the user types C-c C-y.
587The seventh argument ACTIONS is a list of actions to take
588 if/when the message is sent. Each action looks like (FUNCTION . ARGS);
589 when the message is sent, we apply FUNCTION to ARGS.
590 This is how Rmail arranges to mark messages `answered'."
591 (interactive "P")
592 (let ((index 1)
593 buffer)
594 ;; If requested, look for a mail buffer that is modified and go to it.
595 (if noerase
596 (progn
597 (while (and (setq buffer
598 (get-buffer (if (= 1 index) "*mail*"
599 (format "*mail*<%d>" index))))
600 (not (buffer-modified-p buffer)))
601 (setq index (1+ index)))
602 (if buffer (switch-to-buffer buffer)
603 ;; If none exists, start a new message.
604 ;; This will never re-use an existing unmodified mail buffer
605 ;; (since index is not 1 anymore). Perhaps it should.
606 (setq noerase nil))))
607 ;; Unless we found a modified message and are happy, start a new message.
608 (if (not noerase)
609 (progn
610 ;; Look for existing unmodified mail buffer.
611 (while (and (setq buffer
612 (get-buffer (if (= 1 index) "*mail*"
613 (format "*mail*<%d>" index))))
614 (buffer-modified-p buffer))
615 (setq index (1+ index)))
616 ;; If none, make a new one.
617 (or buffer
618 (setq buffer (generate-new-buffer "*mail*")))
619 ;; Go there and initialize it.
620 (switch-to-buffer buffer)
621 (erase-buffer)
622 (setq default-directory (expand-file-name "~/"))
623 (auto-save-mode auto-save-default)
624 (mail-mode)
625 (mail-setup to subject in-reply-to cc replybuffer actions)
626 (if (and buffer-auto-save-file-name
627 (file-exists-p buffer-auto-save-file-name))
628 (message "Auto save file for draft message exists; consider M-x mail-recover"))
629 t))))
630
631;;;###autoload
632(define-key ctl-x-map "m" 'mail)
633
634(defun mail-recover ()
635 "Reread contents of current buffer from its last auto-save file."
636 (interactive)
637 (let ((file-name (make-auto-save-file-name)))
638 (cond ((save-window-excursion
639 (if (not (eq system-type 'vax-vms))
640 (with-output-to-temp-buffer "*Directory*"
641 (buffer-disable-undo standard-output)
642 (call-process "ls" nil standard-output nil "-l" file-name)))
643 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
644 (let ((buffer-read-only nil))
645 (erase-buffer)
646 (insert-file-contents file-name nil)))
647 (t (error "mail-recover cancelled.")))))
648
649;;;###autoload
650(defun mail-other-window (&optional noerase to subject in-reply-to cc replybuffer sendactions)
651 "Like `mail' command, but display mail buffer in another window."
652 (interactive "P")
653 (let ((pop-up-windows t))
654 (pop-to-buffer "*mail*"))
655 (mail noerase to subject in-reply-to cc replybuffer sendactions))
656
657;;;###autoload
658(defun mail-other-screen (&optional noerase to subject in-reply-to cc replybuffer sendactions)
659 "Like `mail' command, but display mail buffer in another screen."
660 (interactive "P")
661 (let ((pop-up-screens t))
662 (pop-to-buffer "*mail*"))
663 (mail noerase to subject in-reply-to cc replybuffer sendactions))
664
665
666;;;###autoload
667(define-key ctl-x-4-map "m" 'mail-other-window)
668
669;;;###autoload
670(define-key ctl-x-3-map "m" 'mail-other-screen)
671
672
673;;; Do not add anything but external entries on this page.