entered into RCS
[emacs.git] / lisp / mail / sendmail.el
blobb976cb398567088f46ae3b0e10722e52facd927a
1 ;;; sendmail.el --- mail sending commands for Emacs.
3 ;; Maintainer: FSF
4 ;; Last-Modified: 24 Jun 1992
5 ;; Keywords: mail
7 ;; Copyright (C) 1985, 1986, 1992 Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
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.
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.
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.
25 ;;; Code:
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.")
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.")
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.")
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.")
48 ;;;###autoload
49 (defvar mail-header-separator "--text follows this line--" "\
50 *Line used to separate headers from text in messages being composed.")
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.")
57 (defvar mail-default-reply-to nil
58 "*Address to insert as default Reply-to field of outgoing messages.")
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.")
66 (defvar mail-yank-prefix nil
67 "*Prefix insert on lines of yanked message being replied to.
68 nil means use indentation.")
70 (defvar mail-abbrevs-loaded nil)
71 (defvar mail-mode-map nil)
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'.")
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.")
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.")
86 (defvar mail-mode-syntax-table nil
87 "Syntax table used while in mail mode.")
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)))
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))
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))
174 (if mail-mode-map
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))
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 (and (not arg)
198 (not (one-window-p))
199 (save-excursion
200 (set-buffer (window-buffer (next-window (selected-window) 'not)))
201 (eq major-mode 'rmail-mode)))
202 (delete-window)
203 (switch-to-buffer (other-buffer (current-buffer)))))
205 (defun mail-send ()
206 "Send the message in the current buffer.
207 If `mail-interactive' is non-nil, wait for success indication
208 or error messages, and inform user.
209 Otherwise any failure is reported in a message back to
210 the user from the mailer."
211 (interactive)
212 (if (or (buffer-modified-p)
213 (y-or-n-p "Message already sent; resend? "))
214 (progn
215 (message "Sending...")
216 (run-hooks 'mail-send-hook)
217 (funcall send-mail-function)
218 ;; Now perform actions on successful sending.
219 (while mail-send-actions
220 (condition-case nil
221 (apply (car (car mail-send-actions)) (cdr (car mail-send-actions)))
222 (error))
223 (setq mail-send-actions (cdr mail-send-actions)))
224 (set-buffer-modified-p nil)
225 (delete-auto-save-file-if-necessary t)
226 (message "Sending...done"))))
228 (defun sendmail-send-it ()
229 (let ((errbuf (if mail-interactive
230 (generate-new-buffer " sendmail errors")
232 (tembuf (generate-new-buffer " sendmail temp"))
233 (case-fold-search nil)
234 delimline
235 (mailbuf (current-buffer)))
236 (unwind-protect
237 (save-excursion
238 (set-buffer tembuf)
239 (erase-buffer)
240 (insert-buffer-substring mailbuf)
241 (goto-char (point-max))
242 ;; require one newline at the end.
243 (or (= (preceding-char) ?\n)
244 (insert ?\n))
245 ;; Change header-delimiter to be what sendmail expects.
246 (goto-char (point-min))
247 (re-search-forward
248 (concat "^" (regexp-quote mail-header-separator) "\n"))
249 (replace-match "\n")
250 (backward-char 1)
251 (setq delimline (point-marker))
252 (goto-char (point-min))
253 ;; ignore any blank lines in the header
254 (while (and (re-search-forward "\n\n\n*" delimline t)
255 (< (point) delimline))
256 (replace-match "\n"))
257 (let ((case-fold-search t))
258 (goto-char (point-min))
259 (if (re-search-forward "^Sender:" delimline t)
260 (error "Sender may not be specified."))
261 ;; Find and handle any FCC fields.
262 (goto-char (point-min))
263 (if (re-search-forward "^FCC:" delimline t)
264 (mail-do-fcc delimline))
265 ;; If the From is different than current user, insert Sender.
266 (goto-char (point-min))
267 (and (re-search-forward "^From:" delimline t)
268 (progn
269 (require 'mail-utils)
270 (not (string-equal
271 (mail-strip-quoted-names
272 (save-restriction
273 (narrow-to-region (point-min) delimline)
274 (mail-fetch-field "From")))
275 (user-login-name))))
276 (progn
277 (forward-line 1)
278 (insert "Sender: " (user-login-name) "\n")))
279 ;; "S:" is an abbreviation for "Subject:".
280 (goto-char (point-min))
281 (if (re-search-forward "^S:" delimline t)
282 (replace-match "Subject:"))
283 ;; Don't send out a blank subject line
284 (goto-char (point-min))
285 (if (re-search-forward "^Subject:[ \t]*\n" delimline t)
286 (replace-match ""))
287 (if mail-interactive
288 (save-excursion
289 (set-buffer errbuf)
290 (erase-buffer))))
291 (apply 'call-process-region
292 (append (list (point-min) (point-max)
293 (if (boundp 'sendmail-program)
294 sendmail-program
295 "/usr/lib/sendmail")
296 nil errbuf nil
297 "-oi" "-t")
298 ;; Always specify who from,
299 ;; since some systems have broken sendmails.
300 (list "-f" (user-login-name))
301 ;;; ;; Don't say "from root" if running under su.
302 ;;; (and (equal (user-real-login-name) "root")
303 ;;; (list "-f" (user-login-name)))
304 (and mail-alias-file
305 (list (concat "-oA" mail-alias-file)))
306 ;; These mean "report errors by mail"
307 ;; and "deliver in background".
308 (if (null mail-interactive) '("-oem" "-odb"))))
309 (if mail-interactive
310 (save-excursion
311 (set-buffer errbuf)
312 (goto-char (point-min))
313 (while (re-search-forward "\n\n* *" nil t)
314 (replace-match "; "))
315 (if (not (zerop (buffer-size)))
316 (error "Sending...failed to %s"
317 (buffer-substring (point-min) (point-max)))))))
318 (kill-buffer tembuf)
319 (if (bufferp errbuf)
320 (kill-buffer errbuf)))))
322 (defun mail-do-fcc (header-end)
323 (let (fcc-list
324 (rmailbuf (current-buffer))
325 (tembuf (generate-new-buffer " rmail output"))
326 (case-fold-search t))
327 (save-excursion
328 (goto-char (point-min))
329 (while (re-search-forward "^FCC:[ \t]*" header-end t)
330 (setq fcc-list (cons (buffer-substring (point)
331 (progn
332 (end-of-line)
333 (skip-chars-backward " \t")
334 (point)))
335 fcc-list))
336 (delete-region (match-beginning 0)
337 (progn (forward-line 1) (point))))
338 (set-buffer tembuf)
339 (erase-buffer)
340 (insert "\nFrom " (user-login-name) " "
341 (current-time-string) "\n")
342 (insert-buffer-substring rmailbuf)
343 ;; Make sure messages are separated.
344 (goto-char (point-max))
345 (insert ?\n)
346 (goto-char 2)
347 ;; ``Quote'' "^From " as ">From "
348 ;; (note that this isn't really quoting, as there is no requirement
349 ;; that "^[>]+From " be quoted in the same transparent way.)
350 (let ((case-fold-search nil))
351 (while (search-forward "\nFrom " nil t)
352 (forward-char -5)
353 (insert ?>)))
354 (while fcc-list
355 (let ((buffer (get-file-buffer (car fcc-list))))
356 (if buffer
357 ;; File is present in a buffer => append to that buffer.
358 (let ((curbuf (current-buffer))
359 (beg (point-min)) (end (point-max)))
360 (save-excursion
361 (set-buffer buffer)
362 ;; Keep the end of the accessible portion at the same place
363 ;; unless it is the end of the buffer.
364 (let ((max (if (/= (1+ (buffer-size)) (point-max))
365 (point-max))))
366 (unwind-protect
367 (progn
368 (narrow-to-region (point-min) (1+ (buffer-size)))
369 (goto-char (point-max))
370 (if (eq major-mode 'rmail-mode)
371 ;; Append as a message to an RMAIL file
372 (let ((buffer-read-only nil))
373 ;; This forces RMAIL's message counters to be
374 ;; recomputed when the next RMAIL operation is
375 ;; done on the buffer.
376 ;; See rmail-maybe-set-message-counters.
377 (setq rmail-total-messages nil)
378 (insert "\C-l\n0, unseen,,\n*** EOOH ***\n"
379 "From: " (user-login-name) "\n"
380 "Date: " (current-time-string) "\n")
381 (insert-buffer-substring curbuf beg end)
382 (insert "\n\C-_")
383 (rmail-set-message-counters))
384 (insert-buffer-substring curbuf beg end)))
385 (if max (narrow-to-region (point-min) max))))))
386 ;; Else append to the file directly.
387 (write-region
388 ;; Include a blank line before if file already exists.
389 (if (file-exists-p (car fcc-list)) (point-min) (1+ (point-min)))
390 (point-max) (car fcc-list) t)))
391 (setq fcc-list (cdr fcc-list))))
392 (kill-buffer tembuf)))
394 (defun mail-sent-via ()
395 "Make a Sent-via header line from each To or CC header line."
396 (interactive)
397 (save-excursion
398 (goto-char (point-min))
399 ;; find the header-separator
400 (search-forward (concat "\n" mail-header-separator "\n"))
401 (forward-line -1)
402 ;; put a marker at the end of the header
403 (let ((end (point-marker))
404 (case-fold-search t)
405 to-line)
406 (goto-char (point-min))
407 ;; search for the To: lines and make Sent-via: lines from them
408 ;; search for the next To: line
409 (while (re-search-forward "^\\(to\\|cc\\):" end t)
410 ;; Grab this line plus all its continuations, sans the `to:'.
411 (let ((to-line
412 (buffer-substring (point)
413 (progn
414 (if (re-search-forward "^[^ \t\n]" end t)
415 (backward-char 1)
416 (goto-char end))
417 (point)))))
418 ;; Insert a copy, with altered header field name.
419 (insert-before-markers "Sent-via:" to-line))))))
421 (defun mail-to ()
422 "Move point to end of To-field."
423 (interactive)
424 (expand-abbrev)
425 (mail-position-on-field "To"))
427 (defun mail-subject ()
428 "Move point to end of Subject-field."
429 (interactive)
430 (expand-abbrev)
431 (mail-position-on-field "Subject"))
433 (defun mail-cc ()
434 "Move point to end of CC-field. Create a CC field if none."
435 (interactive)
436 (expand-abbrev)
437 (or (mail-position-on-field "cc" t)
438 (progn (mail-position-on-field "to")
439 (insert "\nCC: "))))
441 (defun mail-bcc ()
442 "Move point to end of BCC-field. Create a BCC field if none."
443 (interactive)
444 (expand-abbrev)
445 (or (mail-position-on-field "bcc" t)
446 (progn (mail-position-on-field "to")
447 (insert "\nBCC: "))))
449 (defun mail-fcc ()
450 "Add a new FCC field, with file name completion."
451 (interactive)
452 (expand-abbrev)
453 (or (mail-position-on-field "fcc" t) ;Put new field after exiting FCC.
454 (mail-position-on-field "to"))
455 (insert "\nFCC: " (read-file-name "Folder carbon copy: ")))
457 (defun mail-position-on-field (field &optional soft)
458 (let (end
459 (case-fold-search t))
460 (goto-char (point-min))
461 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "\n"))
462 (setq end (match-beginning 0))
463 (goto-char (point-min))
464 (if (re-search-forward (concat "^" (regexp-quote field) ":") end t)
465 (progn
466 (re-search-forward "^[^ \t]" nil 'move)
467 (beginning-of-line)
468 (skip-chars-backward "\n")
470 (or soft
471 (progn (goto-char end)
472 (skip-chars-backward "\n")
473 (insert field ": \n")
474 (skip-chars-backward "\n")))
475 nil)))
477 (defun mail-text ()
478 "Move point to beginning of text field."
479 (interactive)
480 (goto-char (point-min))
481 (search-forward (concat "\n" mail-header-separator "\n")))
483 (defun mail-signature (atpoint)
484 "Sign letter with contents of ~/.signature file."
485 (interactive "P")
486 (save-excursion
487 (or atpoint
488 (goto-char (point-max)))
489 (skip-chars-backward " \t\n")
490 (end-of-line)
491 (or atpoint
492 (delete-region (point) (point-max)))
493 (insert "\n\n--\n")
494 (insert-file-contents (expand-file-name "~/.signature"))))
496 (defun mail-fill-yanked-message (&optional justifyp)
497 "Fill the paragraphs of a message yanked into this one.
498 Numeric argument means justify as well."
499 (interactive "P")
500 (save-excursion
501 (goto-char (point-min))
502 (search-forward (concat "\n" mail-header-separator "\n") nil t)
503 (fill-individual-paragraphs (point)
504 (point-max)
505 justifyp
506 t)))
508 (defun mail-yank-original (arg)
509 "Insert the message being replied to, if any (in rmail).
510 Puts point before the text and mark after.
511 Normally, indents each nonblank line ARG spaces (default 3).
512 However, if `mail-yank-prefix' is non-nil, insert that prefix on each line.
514 Just \\[universal-argument] as argument means don't indent, insert no prefix,
515 and don't delete any header fields."
516 (interactive "P")
517 (if mail-reply-buffer
518 (let ((start (point)))
519 (delete-windows-on mail-reply-buffer)
520 (insert-buffer mail-reply-buffer)
521 (if (consp arg)
523 (mail-yank-clear-headers start (mark))
524 (if (null mail-yank-prefix)
525 (indent-rigidly start (mark)
526 (if arg (prefix-numeric-value arg) 3))
527 (save-excursion
528 (goto-char start)
529 (while (< (point) (mark))
530 (insert mail-yank-prefix)
531 (forward-line 1)))))
532 (exchange-point-and-mark)
533 (if (not (eolp)) (insert ?\n)))))
535 (defun mail-yank-clear-headers (start end)
536 (save-excursion
537 (goto-char start)
538 (if (search-forward "\n\n" end t)
539 (save-restriction
540 (narrow-to-region start (point))
541 (goto-char start)
542 (while (let ((case-fold-search t))
543 (re-search-forward mail-yank-ignored-headers nil t))
544 (beginning-of-line)
545 (delete-region (point)
546 (progn (re-search-forward "\n[^ \t]")
547 (forward-char -1)
548 (point))))))))
550 ;; Put these last, to reduce chance of lossage from quitting in middle of loading the file.
552 ;;;###autoload
553 (defun mail (&optional noerase to subject in-reply-to cc replybuffer actions)
554 "Edit a message to be sent. Argument means resume editing (don't erase).
555 Search for an existing mail buffer currently not in use and initialize it,
556 or make a new one if all existing mail buffers are busy.
557 With an argument, search for a busy existing mail buffer and re-select it.
559 Returns with message buffer selected; value t if message freshly initialized.
560 By default, the signature file `~/.signature' is inserted at the end;
561 see the variable `mail-signature'.
563 \\<mail-mode-map>
564 While editing message, type \\[mail-send-and-exit] to send the message and exit.
566 Various special commands starting with C-c are available in sendmail mode
567 to move to message header fields:
568 \\{mail-mode-map}
570 If `mail-self-blind' is non-nil, a BCC to yourself is inserted
571 when the message is initialized.
573 If `mail-default-reply-to' is non-nil, it should be an address (a string);
574 a Reply-to: field with that address is inserted.
576 If `mail-archive-file-name' is non-nil, an FCC field with that file name
577 is inserted.
579 If `mail-setup-hook' is bound, its value is called with no arguments
580 after the message is initialized. It can add more default fields.
582 When calling from a program, the second through fifth arguments
583 TO, SUBJECT, IN-REPLY-TO and CC specify if non-nil
584 the initial contents of those header fields.
585 These arguments should not have final newlines.
586 The sixth argument REPLYBUFFER is a buffer whose contents
587 should be yanked if the user types C-c C-y.
588 The seventh argument ACTIONS is a list of actions to take
589 if/when the message is sent. Each action looks like (FUNCTION . ARGS);
590 when the message is sent, we apply FUNCTION to ARGS.
591 This is how Rmail arranges to mark messages `answered'."
592 (interactive "P")
593 (let ((index 1)
594 buffer)
595 ;; If requested, look for a mail buffer that is modified and go to it.
596 (if noerase
597 (progn
598 (while (and (setq buffer
599 (get-buffer (if (= 1 index) "*mail*"
600 (format "*mail*<%d>" index))))
601 (not (buffer-modified-p buffer)))
602 (setq index (1+ index)))
603 (if buffer (switch-to-buffer buffer)
604 ;; If none exists, start a new message.
605 ;; This will never re-use an existing unmodified mail buffer
606 ;; (since index is not 1 anymore). Perhaps it should.
607 (setq noerase nil))))
608 ;; Unless we found a modified message and are happy, start a new message.
609 (if (not noerase)
610 (progn
611 ;; Look for existing unmodified mail buffer.
612 (while (and (setq buffer
613 (get-buffer (if (= 1 index) "*mail*"
614 (format "*mail*<%d>" index))))
615 (buffer-modified-p buffer))
616 (setq index (1+ index)))
617 ;; If none, make a new one.
618 (or buffer
619 (setq buffer (generate-new-buffer "*mail*")))
620 ;; Go there and initialize it.
621 (switch-to-buffer buffer)
622 (erase-buffer)
623 (setq default-directory (expand-file-name "~/"))
624 (auto-save-mode auto-save-default)
625 (mail-mode)
626 (mail-setup to subject in-reply-to cc replybuffer actions)
627 (if (and buffer-auto-save-file-name
628 (file-exists-p buffer-auto-save-file-name))
629 (message "Auto save file for draft message exists; consider M-x mail-recover"))
630 t))))
632 ;;;###autoload
633 (define-key ctl-x-map "m" 'mail)
635 (defun mail-recover ()
636 "Reread contents of current buffer from its last auto-save file."
637 (interactive)
638 (let ((file-name (make-auto-save-file-name)))
639 (cond ((save-window-excursion
640 (if (not (eq system-type 'vax-vms))
641 (with-output-to-temp-buffer "*Directory*"
642 (buffer-disable-undo standard-output)
643 (call-process "ls" nil standard-output nil "-l" file-name)))
644 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
645 (let ((buffer-read-only nil))
646 (erase-buffer)
647 (insert-file-contents file-name nil)))
648 (t (error "mail-recover cancelled.")))))
650 ;;;###autoload
651 (defun mail-other-window (&optional noerase to subject in-reply-to cc replybuffer sendactions)
652 "Like `mail' command, but display mail buffer in another window."
653 (interactive "P")
654 (let ((pop-up-windows t))
655 (pop-to-buffer "*mail*"))
656 (mail noerase to subject in-reply-to cc replybuffer sendactions))
658 ;;;###autoload
659 (defun mail-other-frame (&optional noerase to subject in-reply-to cc replybuffer sendactions)
660 "Like `mail' command, but display mail buffer in another frame."
661 (interactive "P")
662 (let ((pop-up-frames t))
663 (pop-to-buffer "*mail*"))
664 (mail noerase to subject in-reply-to cc replybuffer sendactions))
667 ;;;###autoload
668 (define-key ctl-x-4-map "m" 'mail-other-window)
670 ;;;###autoload
671 (define-key ctl-x-5-map "m" 'mail-other-frame)
674 ;;; Do not add anything but external entries on this page.
676 (provide 'sendmail)
678 ;;; sendmail.el ends here