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