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