]> code.delx.au - gnu-emacs/blob - lisp/mail/sendmail.el
(mail-yank-clear-headers): Handle case of end < start.
[gnu-emacs] / lisp / mail / sendmail.el
1 ;;; sendmail.el --- mail sending commands for Emacs.
2
3 ;; Copyright (C) 1985, 86, 92, 93, 94, 95, 96 Free Software Foundation, Inc.
4
5 ;; Maintainer: FSF
6 ;; Keywords: mail
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;; This mode provides mail-sending facilities from within Emacs. It is
28 ;; documented in the Emacs user's manual.
29
30 ;;; Code:
31
32 ;;;###autoload
33 (defvar mail-from-style 'angles "\
34 *Specifies how \"From:\" fields look.
35
36 If `nil', they contain just the return address like:
37 king@grassland.com
38 If `parens', they look like:
39 king@grassland.com (Elvis Parsley)
40 If `angles', they look like:
41 Elvis Parsley <king@grassland.com>")
42
43 ;;;###autoload
44 (defvar mail-self-blind nil "\
45 *Non-nil means insert BCC to self in messages to be sent.
46 This is done when the message is initialized,
47 so you can remove or alter the BCC field to override the default.")
48
49 ;;;###autoload
50 (defvar mail-interactive nil "\
51 *Non-nil means when sending a message wait for and display errors.
52 nil means let mailer mail back a message to report errors.")
53
54 ;;;###autoload
55 (defvar mail-yank-ignored-headers "^via:\\|^mail-from:\\|^origin:\\|^status:\\|^remailed\\|^received:\\|^message-id:\\|^summary-line:\\|^to:\\|^subject:\\|^in-reply-to:\\|^return-path:" "\
56 *Delete these headers from old message when it's inserted in a reply.")
57
58 ;; Useful to set in site-init.el
59 ;;;###autoload
60 (defvar send-mail-function 'sendmail-send-it "\
61 Function to call to send the current buffer as mail.
62 The headers should be delimited by a line whose contents
63 match the variable `mail-header-separator'.")
64
65 ;;;###autoload
66 (defvar mail-header-separator "--text follows this line--" "\
67 *Line used to separate headers from text in messages being composed.")
68
69 ;; Set up mail-header-separator for use as a category text property.
70 (put 'mail-header-separator 'rear-nonsticky '(category))
71 ;;; This was a nice idea, for preventing accidental modification of
72 ;;; the separator. But I found it also prevented or obstructed
73 ;;; certain deliberate operations, such as copying the separator line
74 ;;; up to the top to send myself a copy of an already sent outgoing message
75 ;;; and other things. So I turned it off. --rms.
76 ;;;(put 'mail-header-separator 'read-only t)
77
78 ;;;###autoload
79 (defvar mail-archive-file-name nil "\
80 *Name of file to write all outgoing messages in, or nil for none.
81 This can be an inbox file or an Rmail file.")
82
83 ;;;###autoload
84 (defvar mail-default-reply-to nil
85 "*Address to insert as default Reply-to field of outgoing messages.
86 If nil, it will be initialized from the REPLYTO environment variable
87 when you first send mail.")
88
89 ;;;###autoload
90 (defvar mail-alias-file nil
91 "*If non-nil, the name of a file to use instead of `/usr/lib/aliases'.
92 This file defines aliases to be expanded by the mailer; this is a different
93 feature from that of defining aliases in `.mailrc' to be expanded in Emacs.
94 This variable has no effect unless your system uses sendmail as its mailer.")
95
96 ;;;###autoload
97 (defvar mail-personal-alias-file "~/.mailrc"
98 "*If non-nil, the name of the user's personal mail alias file.
99 This file typically should be in same format as the `.mailrc' file used by
100 the `Mail' or `mailx' program.
101 This file need not actually exist.")
102
103 (defvar mail-setup-hook nil
104 "Normal hook, run each time a new outgoing mail message is initialized.
105 The function `mail-setup' runs this hook.")
106
107 (defvar mail-aliases t
108 "Alist of mail address aliases,
109 or t meaning should be initialized from your mail aliases file.
110 \(The file's name is normally `~/.mailrc', but your MAILRC environment
111 variable can override that name.)
112 The alias definitions in the file have this form:
113 alias ALIAS MEANING")
114
115 (defvar mail-alias-modtime nil
116 "The modification time of your mail alias file when it was last examined.")
117
118 (defvar mail-yank-prefix nil
119 "*Prefix insert on lines of yanked message being replied to.
120 nil means use indentation.")
121 (defvar mail-indentation-spaces 3
122 "*Number of spaces to insert at the beginning of each cited line.
123 Used by `mail-yank-original' via `mail-indent-citation'.")
124 (defvar mail-yank-hooks nil
125 "Obsolete hook for modifying a citation just inserted in the mail buffer.
126 Each hook function can find the citation between (point) and (mark t).
127 And each hook function should leave point and mark around the citation
128 text as modified.
129
130 This is a normal hook, misnamed for historical reasons.
131 It is semi-obsolete and mail agents should no longer use it.")
132
133 (defvar mail-citation-hook nil
134 "*Hook for modifying a citation just inserted in the mail buffer.
135 Each hook function can find the citation between (point) and (mark t).
136 And each hook function should leave point and mark around the citation
137 text as modified.
138
139 If this hook is entirely empty (nil), a default action is taken
140 instead of no action.")
141
142 (defvar mail-abbrevs-loaded nil)
143 (defvar mail-mode-map nil)
144
145 (autoload 'build-mail-aliases "mailalias"
146 "Read mail aliases from user's personal aliases file and set `mail-aliases'."
147 nil)
148
149 (autoload 'expand-mail-aliases "mailalias"
150 "Expand all mail aliases in suitable header fields found between BEG and END.
151 Suitable header fields are `To', `Cc' and `Bcc' and their `Resent-' variants.
152 Optional second arg EXCLUDE may be a regular expression defining text to be
153 removed from alias expansions."
154 nil)
155
156 ;;;###autoload
157 (defvar mail-signature nil
158 "*Text inserted at end of mail buffer when a message is initialized.
159 If t, it means to insert the contents of the file `mail-signature-file'.")
160
161 (defvar mail-signature-file "~/.signature"
162 "*File containing the text inserted at end of mail buffer.")
163
164 (defvar mail-reply-action nil)
165 (defvar mail-send-actions nil
166 "A list of actions to be performed upon successful sending of a message.")
167 (put 'mail-reply-action 'permanent-local t)
168 (put 'mail-send-actions 'permanent-local t)
169
170 (defvar mail-default-headers nil
171 "*A string containing header lines, to be inserted in outgoing messages.
172 It is inserted before you edit the message,
173 so you can edit or delete these lines.")
174
175 (defvar mail-bury-selects-summary t
176 "*If non-nil, try to show RMAIL summary buffer after returning from mail.
177 The functions \\[mail-send-on-exit] or \\[mail-dont-send] select
178 the RMAIL summary buffer before returning, if it exists and this variable
179 is non-nil.")
180
181 ;; Note: could use /usr/ucb/mail instead of sendmail;
182 ;; options -t, and -v if not interactive.
183 (defvar mail-mailer-swallows-blank-line
184 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)" system-configuration)
185 (file-readable-p "/etc/sendmail.cf")
186 (let ((buffer (get-buffer-create " *temp*")))
187 (unwind-protect
188 (save-excursion
189 (set-buffer buffer)
190 (insert-file-contents "/etc/sendmail.cf")
191 (goto-char (point-min))
192 (let ((case-fold-search nil))
193 (re-search-forward "^OR\\>" nil t)))
194 (kill-buffer buffer))))
195 ;; According to RFC822, "The field-name must be composed of printable
196 ;; ASCII characters (i.e. characters that have decimal values between
197 ;; 33 and 126, except colon)", i.e. any chars except ctl chars,
198 ;; space, or colon.
199 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
200 "Set this non-nil if the system's mailer runs the header and body together.
201 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
202 The value should be an expression to test whether the problem will
203 actually occur.")
204
205 (defvar mail-mode-syntax-table nil
206 "Syntax table used while in mail mode.")
207
208 (if (not mail-mode-syntax-table)
209 (progn
210 (setq mail-mode-syntax-table (copy-syntax-table text-mode-syntax-table))
211 (modify-syntax-entry ?% ". " mail-mode-syntax-table)))
212
213 (defvar mail-font-lock-keywords
214 (eval-when-compile
215 (let* ((cite-chars "[>|}]")
216 (cite-prefix "A-Za-z")
217 (cite-suffix (concat cite-prefix "0-9_.@-`'\"")))
218 (list '("^To:" . font-lock-function-name-face)
219 '("^B?CC:\\|^Reply-to:" . font-lock-keyword-face)
220 '("^\\(Subject:\\)[ \t]*\\(.+\\)?"
221 (1 font-lock-comment-face) (2 font-lock-type-face nil t))
222 ;; Use EVAL to delay in case `mail-header-separator' gets changed.
223 '(eval cons (concat "^" (regexp-quote mail-header-separator) "$")
224 'font-lock-comment-face)
225 ;; Use MATCH-ANCHORED to effectively anchor the regexp left side.
226 `(,cite-chars
227 (,(concat "\\=[ \t]*"
228 "\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
229 cite-chars ".*")
230 (beginning-of-line) (end-of-line)
231 (0 font-lock-reference-face)))
232 '("^\\(X-[A-Za-z0-9-]+\\|In-reply-to\\):.*"
233 . font-lock-string-face))))
234 "Additional expressions to highlight in Mail mode.")
235
236 (defvar mail-send-hook nil
237 "Normal hook run before sending mail, in Mail mode.")
238 \f
239 (defun sendmail-sync-aliases ()
240 (let ((modtime (nth 5 (file-attributes mail-personal-alias-file))))
241 (or (equal mail-alias-modtime modtime)
242 (setq mail-alias-modtime modtime
243 mail-aliases t))))
244
245 (defun mail-setup (to subject in-reply-to cc replybuffer actions)
246 (or mail-default-reply-to
247 (setq mail-default-reply-to (getenv "REPLYTO")))
248 (sendmail-sync-aliases)
249 (if (eq mail-aliases t)
250 (progn
251 (setq mail-aliases nil)
252 (if (file-exists-p mail-personal-alias-file)
253 (build-mail-aliases))))
254 (setq mail-send-actions actions)
255 (setq mail-reply-action replybuffer)
256 (goto-char (point-min))
257 (insert "To: ")
258 (save-excursion
259 (if to
260 ;; Here removed code to extract names from within <...>
261 ;; on the assumption that mail-strip-quoted-names
262 ;; has been called and has done so.
263 (let ((fill-prefix "\t")
264 (address-start (point)))
265 (insert to "\n")
266 (fill-region-as-paragraph address-start (point-max)))
267 (newline))
268 (if cc
269 (let ((fill-prefix "\t")
270 (address-start (progn (insert "CC: ") (point))))
271 (insert cc "\n")
272 (fill-region-as-paragraph address-start (point-max))))
273 (if in-reply-to
274 (let ((fill-prefix "\t")
275 (fill-column 78)
276 (address-start (point)))
277 (insert "In-reply-to: " in-reply-to "\n")
278 (fill-region-as-paragraph address-start (point-max))))
279 (insert "Subject: " (or subject "") "\n")
280 (if mail-default-headers
281 (insert mail-default-headers))
282 (if mail-default-reply-to
283 (insert "Reply-to: " mail-default-reply-to "\n"))
284 (if mail-self-blind
285 (insert "BCC: " user-mail-address "\n"))
286 (if mail-archive-file-name
287 (insert "FCC: " mail-archive-file-name "\n"))
288 (put-text-property (point)
289 (progn
290 (insert mail-header-separator "\n")
291 (1- (point)))
292 'category 'mail-header-separator)
293 ;; Insert the signature. But remember the beginning of the message.
294 (if to (setq to (point)))
295 (cond ((eq mail-signature t)
296 (if (file-exists-p mail-signature-file)
297 (progn
298 (insert "\n\n-- \n")
299 (insert-file-contents mail-signature-file))))
300 (mail-signature
301 (insert mail-signature)))
302 (goto-char (point-max))
303 (or (bolp) (newline)))
304 (if to (goto-char to))
305 (or to subject in-reply-to
306 (set-buffer-modified-p nil))
307 (run-hooks 'mail-setup-hook))
308 \f
309 ;;;###autoload
310 (defun mail-mode ()
311 "Major mode for editing mail to be sent.
312 Like Text Mode but with these additional commands:
313 C-c C-s mail-send (send the message) C-c C-c mail-send-and-exit
314 C-c C-f move to a header field (and create it if there isn't):
315 C-c C-f C-t move to To: C-c C-f C-s move to Subject:
316 C-c C-f C-c move to CC: C-c C-f C-b move to BCC:
317 C-c C-f C-f move to FCC:
318 C-c C-t mail-text (move to beginning of message text).
319 C-c C-w mail-signature (insert `mail-signature-file' file).
320 C-c C-y mail-yank-original (insert current message, in Rmail).
321 C-c C-q mail-fill-yanked-message (fill what was yanked).
322 C-c C-v mail-sent-via (add a Sent-via field for each To or CC)."
323 (interactive)
324 (kill-all-local-variables)
325 (make-local-variable 'mail-reply-action)
326 (make-local-variable 'mail-send-actions)
327 (set-syntax-table mail-mode-syntax-table)
328 (use-local-map mail-mode-map)
329 (setq local-abbrev-table text-mode-abbrev-table)
330 (setq major-mode 'mail-mode)
331 (setq mode-name "Mail")
332 (setq buffer-offer-save t)
333 (make-local-variable 'font-lock-defaults)
334 (setq font-lock-defaults '(mail-font-lock-keywords t))
335 (make-local-variable 'paragraph-separate)
336 (make-local-variable 'paragraph-start)
337 (make-local-variable 'normal-auto-fill-function)
338 (setq normal-auto-fill-function 'mail-mode-auto-fill)
339 (setq fill-paragraph-function 'mail-mode-fill-paragraph)
340 ;; `-- ' precedes the signature. `-----' appears at the start of the
341 ;; lines that delimit forwarded messages.
342 ;; Lines containing just >= 3 dashes, perhaps after whitespace,
343 ;; are also sometimes used and should be separators.
344 (setq paragraph-start (concat (regexp-quote mail-header-separator)
345 "$\\|[ \t]*[-_][-_][-_]+$\\|-- $\\|-----\\|"
346 paragraph-start))
347 (setq paragraph-separate (concat (regexp-quote mail-header-separator)
348 "$\\|[ \t]*[-_][-_][-_]+$\\|-- $\\|-----\\|"
349 paragraph-separate))
350 (run-hooks 'text-mode-hook 'mail-mode-hook))
351
352 (defun mail-mode-auto-fill ()
353 "Carry out Auto Fill for Mail mode.
354 If within the headers, this makes the new lines into continuation lines."
355 (if (< (point)
356 (save-excursion
357 (goto-char (point-min))
358 (if (search-forward mail-header-separator nil t)
359 (point)
360 0)))
361 (let ((old-line-start (save-excursion (beginning-of-line) (point))))
362 (if (do-auto-fill)
363 (save-excursion
364 (beginning-of-line)
365 (while (not (eq (point) old-line-start))
366 (insert " ")
367 (forward-line -1))
368 t)))
369 (do-auto-fill)))
370
371 (defun mail-mode-fill-paragraph (arg)
372 ;; Do something special only if within the headers.
373 (if (< (point)
374 (save-excursion
375 (goto-char (point-min))
376 (if (search-forward mail-header-separator nil t)
377 (point)
378 0)))
379 (let (beg end fieldname)
380 (re-search-backward "^[-a-zA-Z]+:" nil 'yes)
381 (setq beg (point))
382 (setq fieldname
383 (downcase (buffer-substring beg (1- (match-end 0)))))
384 (forward-line 1)
385 ;; Find continuation lines and get rid of their continuation markers.
386 (while (looking-at "[ \t]")
387 (delete-horizontal-space)
388 (forward-line 1))
389 (setq end (point-marker))
390 (goto-char beg)
391 ;; If this field contains addresses,
392 ;; make sure we can fill after each address.
393 (if (member fieldname
394 '("to" "cc" "bcc" "from" "reply-to"
395 "resent-to" "resent-cc" "resent-bcc"
396 "resent-from" "resent-reply-to"))
397 (while (search-forward "," end t)
398 (or (looking-at "[ \t]")
399 (insert " "))))
400 (fill-region-as-paragraph beg end)
401 ;; Mark all lines except the first as continuations.
402 (goto-char beg)
403 (forward-line 1)
404 (while (< (point) end)
405 (insert " ")
406 (forward-line 1))
407 (move-marker end nil)
408 t)))
409 \f
410 ;;; Set up keymap.
411
412 (if mail-mode-map
413 nil
414 (setq mail-mode-map (nconc (make-sparse-keymap) text-mode-map))
415 (define-key mail-mode-map "\M-\t" 'mail-complete)
416 (define-key mail-mode-map "\C-c?" 'describe-mode)
417 (define-key mail-mode-map "\C-c\C-f\C-t" 'mail-to)
418 (define-key mail-mode-map "\C-c\C-f\C-b" 'mail-bcc)
419 (define-key mail-mode-map "\C-c\C-f\C-f" 'mail-fcc)
420 (define-key mail-mode-map "\C-c\C-f\C-c" 'mail-cc)
421 (define-key mail-mode-map "\C-c\C-f\C-s" 'mail-subject)
422 (define-key mail-mode-map "\C-c\C-f\C-r" 'mail-reply-to)
423 (define-key mail-mode-map "\C-c\C-t" 'mail-text)
424 (define-key mail-mode-map "\C-c\C-y" 'mail-yank-original)
425 (define-key mail-mode-map "\C-c\C-r" 'mail-yank-region)
426 (define-key mail-mode-map "\C-c\C-q" 'mail-fill-yanked-message)
427 (define-key mail-mode-map "\C-c\C-w" 'mail-signature)
428 (define-key mail-mode-map "\C-c\C-v" 'mail-sent-via)
429 (define-key mail-mode-map "\C-c\C-c" 'mail-send-and-exit)
430 (define-key mail-mode-map "\C-c\C-s" 'mail-send))
431
432 (define-key mail-mode-map [menu-bar mail]
433 (cons "Mail" (make-sparse-keymap "Mail")))
434
435 (define-key mail-mode-map [menu-bar mail fill]
436 '("Fill Citation" . mail-fill-yanked-message))
437
438 (define-key mail-mode-map [menu-bar mail yank]
439 '("Cite Original" . mail-yank-original))
440
441 (define-key mail-mode-map [menu-bar mail signature]
442 '("Insert Signature" . mail-signature))
443
444 (define-key mail-mode-map [menu-bar mail cancel]
445 '("Cancel" . mail-dont-send))
446
447 (define-key mail-mode-map [menu-bar mail send-stay]
448 '("Send, Keep Editing" . mail-send))
449
450 (define-key mail-mode-map [menu-bar mail send]
451 '("Send Message" . mail-send-and-exit))
452
453 (define-key mail-mode-map [menu-bar headers]
454 (cons "Headers" (make-sparse-keymap "Move to Header")))
455
456 (define-key mail-mode-map [menu-bar headers reply-to]
457 '("Reply-To" . mail-reply-to))
458
459 (define-key mail-mode-map [menu-bar headers sent-via]
460 '("Sent Via" . mail-sent-via))
461
462 (define-key mail-mode-map [menu-bar headers text]
463 '("Text" . mail-text))
464
465 (define-key mail-mode-map [menu-bar headers bcc]
466 '("Bcc" . mail-bcc))
467
468 (define-key mail-mode-map [menu-bar headers fcc]
469 '("Fcc" . mail-fcc))
470
471 (define-key mail-mode-map [menu-bar headers cc]
472 '("Cc" . mail-cc))
473
474 (define-key mail-mode-map [menu-bar headers subject]
475 '("Subject" . mail-subject))
476
477 (define-key mail-mode-map [menu-bar headers to]
478 '("To" . mail-to))
479 \f
480 ;; User-level commands for sending.
481
482 (defun mail-send-and-exit (arg)
483 "Send message like `mail-send', then, if no errors, exit from mail buffer.
484 Prefix arg means don't delete this window."
485 (interactive "P")
486 (mail-send)
487 (mail-bury arg))
488
489 (defun mail-dont-send (arg)
490 "Don't send the message you have been editing.
491 Prefix arg means don't delete this window."
492 (interactive "P")
493 (mail-bury arg))
494
495 (defun mail-bury (arg)
496 "Bury this mail buffer."
497 (let ((newbuf (other-buffer (current-buffer))))
498 (bury-buffer (current-buffer))
499 (if (and (or (window-dedicated-p (frame-selected-window))
500 (assq 'mail-dedicated-frame (frame-parameters)))
501 (not (null (delq (selected-frame) (visible-frame-list)))))
502 (delete-frame (selected-frame))
503 (let (rmail-flag summary-buffer)
504 (and (not arg)
505 (not (one-window-p))
506 (save-excursion
507 (set-buffer (window-buffer (next-window (selected-window) 'not)))
508 (setq rmail-flag (eq major-mode 'rmail-mode))
509 (setq summary-buffer
510 (and mail-bury-selects-summary
511 (boundp 'rmail-summary-buffer)
512 rmail-summary-buffer
513 (buffer-name rmail-summary-buffer)
514 (not (get-buffer-window rmail-summary-buffer))
515 rmail-summary-buffer))))
516 (if rmail-flag
517 ;; If the Rmail buffer has a summary, show that.
518 (if summary-buffer (switch-to-buffer summary-buffer)
519 (delete-window))
520 (switch-to-buffer newbuf))))))
521
522 (defun mail-send ()
523 "Send the message in the current buffer.
524 If `mail-interactive' is non-nil, wait for success indication
525 or error messages, and inform user.
526 Otherwise any failure is reported in a message back to
527 the user from the mailer."
528 (interactive)
529 (if (if buffer-file-name
530 (y-or-n-p "Send buffer contents as mail message? ")
531 (or (buffer-modified-p)
532 (y-or-n-p "Message already sent; resend? ")))
533 (let ((inhibit-read-only t))
534 (run-hooks 'mail-send-hook)
535 (message "Sending...")
536 (funcall send-mail-function)
537 ;; Now perform actions on successful sending.
538 (while mail-send-actions
539 (condition-case nil
540 (apply (car (car mail-send-actions))
541 (cdr (car mail-send-actions)))
542 (error))
543 (setq mail-send-actions (cdr mail-send-actions)))
544 (message "Sending...done")
545 ;; If buffer has no file, mark it as unmodified and delete autosave.
546 (if (not buffer-file-name)
547 (progn
548 (set-buffer-modified-p nil)
549 (delete-auto-save-file-if-necessary t))))))
550 \f
551 ;; This does the real work of sending a message via sendmail.
552 ;; It is called via the variable send-mail-function.
553
554 (defun sendmail-send-it ()
555 (require 'mail-utils)
556 (let ((errbuf (if mail-interactive
557 (generate-new-buffer " sendmail errors")
558 0))
559 (tembuf (generate-new-buffer " sendmail temp"))
560 (case-fold-search nil)
561 resend-to-addresses
562 delimline
563 fcc-was-found
564 (mailbuf (current-buffer)))
565 (unwind-protect
566 (save-excursion
567 (set-buffer tembuf)
568 (erase-buffer)
569 (insert-buffer-substring mailbuf)
570 (goto-char (point-max))
571 ;; require one newline at the end.
572 (or (= (preceding-char) ?\n)
573 (insert ?\n))
574 ;; Change header-delimiter to be what sendmail expects.
575 (goto-char (point-min))
576 (re-search-forward
577 (concat "^" (regexp-quote mail-header-separator) "\n"))
578 (replace-match "\n")
579 (backward-char 1)
580 (setq delimline (point-marker))
581 (sendmail-sync-aliases)
582 (if mail-aliases
583 (expand-mail-aliases (point-min) delimline))
584 (goto-char (point-min))
585 ;; ignore any blank lines in the header
586 (while (and (re-search-forward "\n\n\n*" delimline t)
587 (< (point) delimline))
588 (replace-match "\n"))
589 (let ((case-fold-search t))
590 (goto-char (point-min))
591 (while (re-search-forward "^Resent-\\(to\\|cc\\|bcc\\):" delimline t)
592 (setq resend-to-addresses
593 (save-restriction
594 (narrow-to-region (point)
595 (save-excursion
596 (end-of-line)
597 (point)))
598 (append (mail-parse-comma-list)
599 resend-to-addresses)))
600 ;; Delete Resent-BCC ourselves
601 (if (save-excursion (beginning-of-line)
602 (looking-at "resent-bcc"))
603 (delete-region (save-excursion (beginning-of-line) (point))
604 (save-excursion (end-of-line) (1+ (point))))))
605 ;;; Apparently this causes a duplicate Sender.
606 ;;; ;; If the From is different than current user, insert Sender.
607 ;;; (goto-char (point-min))
608 ;;; (and (re-search-forward "^From:" delimline t)
609 ;;; (progn
610 ;;; (require 'mail-utils)
611 ;;; (not (string-equal
612 ;;; (mail-strip-quoted-names
613 ;;; (save-restriction
614 ;;; (narrow-to-region (point-min) delimline)
615 ;;; (mail-fetch-field "From")))
616 ;;; (user-login-name))))
617 ;;; (progn
618 ;;; (forward-line 1)
619 ;;; (insert "Sender: " (user-login-name) "\n")))
620 ;; Don't send out a blank subject line
621 (goto-char (point-min))
622 (if (re-search-forward "^Subject:\\([ \t]*\n\\)+\\b" delimline t)
623 (replace-match "")
624 ;; This one matches a Subject just before the header delimiter.
625 (if (and (re-search-forward "^Subject:\\([ \t]*\n\\)+" delimline t)
626 (= (match-end 0) delimline))
627 (replace-match "")))
628 ;; Put the "From:" field in unless for some odd reason
629 ;; they put one in themselves.
630 (goto-char (point-min))
631 (if (not (re-search-forward "^From:" delimline t))
632 (let* ((login user-mail-address)
633 (fullname (user-full-name)))
634 (cond ((eq mail-from-style 'angles)
635 (insert "From: " fullname)
636 (let ((fullname-start (+ (point-min) 6))
637 (fullname-end (point-marker)))
638 (goto-char fullname-start)
639 ;; Look for a character that cannot appear unquoted
640 ;; according to RFC 822.
641 (if (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]"
642 fullname-end 1)
643 (progn
644 ;; Quote fullname, escaping specials.
645 (goto-char fullname-start)
646 (insert "\"")
647 (while (re-search-forward "[\"\\]"
648 fullname-end 1)
649 (replace-match "\\\\\\&" t))
650 (insert "\""))))
651 (insert " <" login ">\n"))
652 ((eq mail-from-style 'parens)
653 (insert "From: " login " (")
654 (let ((fullname-start (point)))
655 (insert fullname)
656 (let ((fullname-end (point-marker)))
657 (goto-char fullname-start)
658 ;; RFC 822 says \ and nonmatching parentheses
659 ;; must be escaped in comments.
660 ;; Escape every instance of ()\ ...
661 (while (re-search-forward "[()\\]" fullname-end 1)
662 (replace-match "\\\\\\&" t))
663 ;; ... then undo escaping of matching parentheses,
664 ;; including matching nested parentheses.
665 (goto-char fullname-start)
666 (while (re-search-forward
667 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
668 fullname-end 1)
669 (replace-match "\\1(\\3)" t)
670 (goto-char fullname-start))))
671 (insert ")\n"))
672 ((null mail-from-style)
673 (insert "From: " login "\n")))))
674 ;; Insert an extra newline if we need it to work around
675 ;; Sun's bug that swallows newlines.
676 (goto-char (1+ delimline))
677 (if (eval mail-mailer-swallows-blank-line)
678 (newline))
679 ;; Find and handle any FCC fields.
680 (goto-char (point-min))
681 (if (re-search-forward "^FCC:" delimline t)
682 (progn
683 (setq fcc-was-found t)
684 (mail-do-fcc delimline)))
685 (if mail-interactive
686 (save-excursion
687 (set-buffer errbuf)
688 (erase-buffer))))
689 (goto-char (point-min))
690 (if (let ((case-fold-search t))
691 (re-search-forward "^To:\\|^cc:\\|^bcc:\\|^resent-to:\
692 \\|^resent-cc:\\|^resent-bcc:"
693 delimline t))
694 (let ((default-directory "/"))
695 (apply 'call-process-region
696 (append (list (point-min) (point-max)
697 (if (boundp 'sendmail-program)
698 sendmail-program
699 "/usr/lib/sendmail")
700 nil errbuf nil "-oi")
701 ;; Always specify who from,
702 ;; since some systems have broken sendmails.
703 (list "-f" (user-login-name))
704 ;;; ;; Don't say "from root" if running under su.
705 ;;; (and (equal (user-real-login-name) "root")
706 ;;; (list "-f" (user-login-name)))
707 (and mail-alias-file
708 (list (concat "-oA" mail-alias-file)))
709 (if mail-interactive
710 ;; These mean "report errors to terminal"
711 ;; and "deliver interactively"
712 '("-oep" "-odi")
713 ;; These mean "report errors by mail"
714 ;; and "deliver in background".
715 '("-oem" "-odb"))
716 ;; Get the addresses from the message
717 ;; unless this is a resend.
718 ;; We must not do that for a resend
719 ;; because we would find the original addresses.
720 ;; For a resend, include the specific addresses.
721 (or resend-to-addresses
722 '("-t")))))
723 (or fcc-was-found
724 (error "No recipients")))
725 (if mail-interactive
726 (save-excursion
727 (set-buffer errbuf)
728 (goto-char (point-min))
729 (while (re-search-forward "\n\n* *" nil t)
730 (replace-match "; "))
731 (if (not (zerop (buffer-size)))
732 (error "Sending...failed to %s"
733 (buffer-substring (point-min) (point-max)))))))
734 (kill-buffer tembuf)
735 (if (bufferp errbuf)
736 (kill-buffer errbuf)))))
737
738 (defun mail-do-fcc (header-end)
739 (let (fcc-list
740 (rmailbuf (current-buffer))
741 (time (current-time))
742 (tembuf (generate-new-buffer " rmail output"))
743 (case-fold-search t))
744 (save-excursion
745 (goto-char (point-min))
746 (while (re-search-forward "^FCC:[ \t]*" header-end t)
747 (setq fcc-list (cons (buffer-substring (point)
748 (progn
749 (end-of-line)
750 (skip-chars-backward " \t")
751 (point)))
752 fcc-list))
753 (delete-region (match-beginning 0)
754 (progn (forward-line 1) (point))))
755 (set-buffer tembuf)
756 (erase-buffer)
757 ;; This initial newline is written out if the fcc file already exists.
758 (insert "\nFrom " (user-login-name) " "
759 (current-time-string time) "\n")
760 ;; Insert the time zone before the year.
761 (forward-char -1)
762 (forward-word -1)
763 (require 'mail-utils)
764 (insert (mail-rfc822-time-zone time) " ")
765 (goto-char (point-max))
766 (insert-buffer-substring rmailbuf)
767 ;; Make sure messages are separated.
768 (goto-char (point-max))
769 (insert ?\n)
770 (goto-char 2)
771 ;; ``Quote'' "^From " as ">From "
772 ;; (note that this isn't really quoting, as there is no requirement
773 ;; that "^[>]+From " be quoted in the same transparent way.)
774 (let ((case-fold-search nil))
775 (while (search-forward "\nFrom " nil t)
776 (forward-char -5)
777 (insert ?>)))
778 (while fcc-list
779 (let* ((buffer (find-buffer-visiting (car fcc-list)))
780 (curbuf (current-buffer))
781 (beg (point-min)) (end (point-max))
782 (beg2 (save-excursion (goto-char (point-min))
783 (forward-line 2) (point))))
784 (if buffer
785 ;; File is present in a buffer => append to that buffer.
786 (save-excursion
787 (set-buffer buffer)
788 ;; Keep the end of the accessible portion at the same place
789 ;; unless it is the end of the buffer.
790 (let ((max (if (/= (1+ (buffer-size)) (point-max))
791 (point-max))))
792 (unwind-protect
793 ;; Code below lifted from rmailout.el
794 ;; function rmail-output-to-rmail-file:
795 (let ((buffer-read-only nil)
796 (msg (and (boundp 'rmail-current-message)
797 rmail-current-message)))
798 ;; If MSG is non-nil, buffer is in RMAIL mode.
799 (if msg
800 (progn
801 (rmail-maybe-set-message-counters)
802 (widen)
803 (narrow-to-region (point-max) (point-max))
804 (insert "\C-l\n0, unseen,,\n*** EOOH ***\n"
805 "Date: " (mail-rfc822-date) "\n")
806 (insert-buffer-substring curbuf beg2 end)
807 (insert "\n\C-_")
808 (goto-char (point-min))
809 (widen)
810 (search-backward "\n\^_")
811 (narrow-to-region (point) (point-max))
812 (rmail-count-new-messages t)
813 (rmail-show-message msg)
814 (setq max nil))
815 ;; Output file not in rmail mode
816 ;; => just insert at the end.
817 (narrow-to-region (point-min) (1+ (buffer-size)))
818 (goto-char (point-max))
819 (insert-buffer-substring curbuf beg end)))
820 (if max (narrow-to-region (point-min) max)))))
821 ;; Else append to the file directly.
822 (if (and (file-exists-p (car fcc-list))
823 (mail-file-babyl-p (car fcc-list)))
824 ;; If the file is a Babyl file,
825 ;; convert the message to Babyl format.
826 (save-excursion
827 (set-buffer (get-buffer-create " mail-temp"))
828 (setq buffer-read-only nil)
829 (erase-buffer)
830 (insert "\C-l\n0, unseen,,\n*** EOOH ***\n"
831 "Date: " (mail-rfc822-date) "\n")
832 (insert-buffer-substring curbuf beg2 end)
833 (insert "\n\C-_")
834 (write-region (point-min) (point-max) (car fcc-list) t)
835 (erase-buffer))
836 (write-region
837 (1+ (point-min)) (point-max) (car fcc-list) t))))
838 (setq fcc-list (cdr fcc-list))))
839 (kill-buffer tembuf)))
840
841 (defun mail-sent-via ()
842 "Make a Sent-via header line from each To or CC header line."
843 (interactive)
844 (save-excursion
845 (goto-char (point-min))
846 ;; find the header-separator
847 (search-forward (concat "\n" mail-header-separator "\n"))
848 (forward-line -1)
849 ;; put a marker at the end of the header
850 (let ((end (point-marker))
851 (case-fold-search t)
852 to-line)
853 (goto-char (point-min))
854 ;; search for the To: lines and make Sent-via: lines from them
855 ;; search for the next To: line
856 (while (re-search-forward "^\\(to\\|cc\\):" end t)
857 ;; Grab this line plus all its continuations, sans the `to:'.
858 (let ((to-line
859 (buffer-substring (point)
860 (progn
861 (if (re-search-forward "^[^ \t\n]" end t)
862 (backward-char 1)
863 (goto-char end))
864 (point)))))
865 ;; Insert a copy, with altered header field name.
866 (insert-before-markers "Sent-via:" to-line))))))
867 \f
868 (defun mail-to ()
869 "Move point to end of To-field."
870 (interactive)
871 (expand-abbrev)
872 (mail-position-on-field "To"))
873
874 (defun mail-subject ()
875 "Move point to end of Subject-field."
876 (interactive)
877 (expand-abbrev)
878 (mail-position-on-field "Subject"))
879
880 (defun mail-cc ()
881 "Move point to end of CC-field. Create a CC field if none."
882 (interactive)
883 (expand-abbrev)
884 (or (mail-position-on-field "cc" t)
885 (progn (mail-position-on-field "to")
886 (insert "\nCC: "))))
887
888 (defun mail-bcc ()
889 "Move point to end of BCC-field. Create a BCC field if none."
890 (interactive)
891 (expand-abbrev)
892 (or (mail-position-on-field "bcc" t)
893 (progn (mail-position-on-field "to")
894 (insert "\nBCC: "))))
895
896 (defun mail-fcc (folder)
897 "Add a new FCC field, with file name completion."
898 (interactive "FFolder carbon copy: ")
899 (expand-abbrev)
900 (or (mail-position-on-field "fcc" t) ;Put new field after exiting FCC.
901 (mail-position-on-field "to"))
902 (insert "\nFCC: " folder))
903
904 (defun mail-reply-to ()
905 "Move point to end of Reply-To-field."
906 (interactive)
907 (expand-abbrev)
908 (mail-position-on-field "Reply-To"))
909
910 (defun mail-position-on-field (field &optional soft)
911 (let (end
912 (case-fold-search t))
913 (goto-char (point-min))
914 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
915 (setq end (match-beginning 0))
916 (goto-char (point-min))
917 (if (re-search-forward (concat "^" (regexp-quote field) ":") end t)
918 (progn
919 (re-search-forward "^[^ \t]" nil 'move)
920 (beginning-of-line)
921 (skip-chars-backward "\n")
922 t)
923 (or soft
924 (progn (goto-char end)
925 (insert field ": \n")
926 (skip-chars-backward "\n")))
927 nil)))
928
929 (defun mail-text ()
930 "Move point to beginning of message text."
931 (interactive)
932 (expand-abbrev)
933 (goto-char (point-min))
934 (search-forward (concat "\n" mail-header-separator "\n")))
935 \f
936 (defun mail-signature (atpoint)
937 "Sign letter with contents of the file `mail-signature-file'.
938 Prefix arg means put contents at point."
939 (interactive "P")
940 (save-excursion
941 (or atpoint
942 (goto-char (point-max)))
943 (skip-chars-backward " \t\n")
944 (end-of-line)
945 (or atpoint
946 (delete-region (point) (point-max)))
947 (insert "\n\n-- \n")
948 (insert-file-contents (expand-file-name mail-signature-file))))
949
950 (defun mail-fill-yanked-message (&optional justifyp)
951 "Fill the paragraphs of a message yanked into this one.
952 Numeric argument means justify as well."
953 (interactive "P")
954 (save-excursion
955 (goto-char (point-min))
956 (search-forward (concat "\n" mail-header-separator "\n") nil t)
957 (fill-individual-paragraphs (point)
958 (point-max)
959 justifyp
960 t)))
961
962 (defun mail-indent-citation ()
963 "Modify text just inserted from a message to be cited.
964 The inserted text should be the region.
965 When this function returns, the region is again around the modified text.
966
967 Normally, indent each nonblank line `mail-indentation-spaces' spaces.
968 However, if `mail-yank-prefix' is non-nil, insert that prefix on each line."
969 (mail-yank-clear-headers (region-beginning) (region-end))
970 (if (null mail-yank-prefix)
971 (indent-rigidly (region-beginning) (region-end)
972 mail-indentation-spaces)
973 (save-excursion
974 (goto-char (region-beginning))
975 (while (< (point) (region-end))
976 (insert mail-yank-prefix)
977 (forward-line 1)))))
978
979 (defun mail-yank-original (arg)
980 "Insert the message being replied to, if any (in rmail).
981 Puts point after the text and mark before.
982 Normally, indents each nonblank line ARG spaces (default 3).
983 However, if `mail-yank-prefix' is non-nil, insert that prefix on each line.
984
985 Just \\[universal-argument] as argument means don't indent, insert no prefix,
986 and don't delete any header fields."
987 (interactive "P")
988 (if mail-reply-action
989 (let ((start (point))
990 (original mail-reply-action))
991 (and (consp original) (eq (car original) 'insert-buffer)
992 (setq original (nth 1 original)))
993 (if (consp original)
994 (apply (car original) (cdr original))
995 ;; If the original message is in another window in the same frame,
996 ;; delete that window to save screen space.
997 ;; t means don't alter other frames.
998 (delete-windows-on original t)
999 (insert-buffer original))
1000 (if (consp arg)
1001 nil
1002 (goto-char start)
1003 (let ((mail-indentation-spaces (if arg (prefix-numeric-value arg)
1004 mail-indentation-spaces)))
1005 (if mail-citation-hook
1006 (run-hooks 'mail-citation-hook)
1007 (if mail-yank-hooks
1008 (run-hooks 'mail-yank-hooks)
1009 (mail-indent-citation)))))
1010 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
1011 ;; It is cleaner to avoid activation, even though the command
1012 ;; loop would deactivate the mark because we inserted text.
1013 (goto-char (prog1 (mark t)
1014 (set-marker (mark-marker) (point) (current-buffer))))
1015 (if (not (eolp)) (insert ?\n)))))
1016
1017 (defun mail-yank-clear-headers (start end)
1018 (if (< end start)
1019 (let (temp)
1020 (setq temp start start end end temp)))
1021 (if mail-yank-ignored-headers
1022 (save-excursion
1023 (goto-char start)
1024 (if (search-forward "\n\n" end t)
1025 (save-restriction
1026 (narrow-to-region start (point))
1027 (goto-char start)
1028 (while (let ((case-fold-search t))
1029 (re-search-forward mail-yank-ignored-headers nil t))
1030 (beginning-of-line)
1031 (delete-region (point)
1032 (progn (re-search-forward "\n[^ \t]")
1033 (forward-char -1)
1034 (point)))))))))
1035
1036 (defun mail-yank-region (arg)
1037 "Insert the selected region from the message being replied to.
1038 Puts point after the text and mark before.
1039 Normally, indents each nonblank line ARG spaces (default 3).
1040 However, if `mail-yank-prefix' is non-nil, insert that prefix on each line.
1041
1042 Just \\[universal-argument] as argument means don't indent, insert no prefix,
1043 and don't delete any header fields."
1044 (interactive "P")
1045 (and (consp mail-reply-action)
1046 (eq (car mail-reply-action) 'insert-buffer)
1047 (let ((buffer (nth 1 mail-reply-action))
1048 (start (point)))
1049 ;; Insert the citation text.
1050 (insert (with-current-buffer buffer
1051 (buffer-substring (point) (mark))))
1052 (push-mark start)
1053 ;; Indent or otherwise annotate the citation text.
1054 (if (consp arg)
1055 nil
1056 (let ((mail-indentation-spaces (if arg (prefix-numeric-value arg)
1057 mail-indentation-spaces)))
1058 (if mail-citation-hook
1059 (run-hooks 'mail-citation-hook)
1060 (if mail-yank-hooks
1061 (run-hooks 'mail-yank-hooks)
1062 (mail-indent-citation))))))))
1063 \f
1064 ;; Put these last, to reduce chance of lossage from quitting in middle of loading the file.
1065
1066 ;;;###autoload
1067 (defun mail (&optional noerase to subject in-reply-to cc replybuffer actions)
1068 "Edit a message to be sent. Prefix arg means resume editing (don't erase).
1069 When this function returns, the buffer `*mail*' is selected.
1070 The value is t if the message was newly initialized; otherwise, nil.
1071
1072 Optionally, the signature file `mail-signature-file' can be inserted at the
1073 end; see the variable `mail-signature'.
1074
1075 \\<mail-mode-map>
1076 While editing message, type \\[mail-send-and-exit] to send the message and exit.
1077
1078 Various special commands starting with C-c are available in sendmail mode
1079 to move to message header fields:
1080 \\{mail-mode-map}
1081
1082 If `mail-self-blind' is non-nil, a BCC to yourself is inserted
1083 when the message is initialized.
1084
1085 If `mail-default-reply-to' is non-nil, it should be an address (a string);
1086 a Reply-to: field with that address is inserted.
1087
1088 If `mail-archive-file-name' is non-nil, an FCC field with that file name
1089 is inserted.
1090
1091 The normal hook `mail-setup-hook' is run after the message is
1092 initialized. It can add more default fields to the message.
1093
1094 When calling from a program, the first argument if non-nil says
1095 not to erase the existing contents of the `*mail*' buffer.
1096
1097 The second through fifth arguments,
1098 TO, SUBJECT, IN-REPLY-TO and CC, specify if non-nil
1099 the initial contents of those header fields.
1100 These arguments should not have final newlines.
1101 The sixth argument REPLYBUFFER is a buffer which contains an
1102 original message being replied to, or else an action
1103 of the form (FUNCTION . ARGS) which says how to insert the original.
1104 Or it can be nil, if not replying to anything.
1105 The seventh argument ACTIONS is a list of actions to take
1106 if/when the message is sent. Each action looks like (FUNCTION . ARGS);
1107 when the message is sent, we apply FUNCTION to ARGS.
1108 This is how Rmail arranges to mark messages `answered'."
1109 (interactive "P")
1110 ;;; This is commented out because I found it was confusing in practice.
1111 ;;; It is easy enough to rename *mail* by hand with rename-buffer
1112 ;;; if you want to have multiple mail buffers.
1113 ;;; And then you can control which messages to save. --rms.
1114 ;;; (let ((index 1)
1115 ;;; buffer)
1116 ;;; ;; If requested, look for a mail buffer that is modified and go to it.
1117 ;;; (if noerase
1118 ;;; (progn
1119 ;;; (while (and (setq buffer
1120 ;;; (get-buffer (if (= 1 index) "*mail*"
1121 ;;; (format "*mail*<%d>" index))))
1122 ;;; (not (buffer-modified-p buffer)))
1123 ;;; (setq index (1+ index)))
1124 ;;; (if buffer (switch-to-buffer buffer)
1125 ;;; ;; If none exists, start a new message.
1126 ;;; ;; This will never re-use an existing unmodified mail buffer
1127 ;;; ;; (since index is not 1 anymore). Perhaps it should.
1128 ;;; (setq noerase nil))))
1129 ;;; ;; Unless we found a modified message and are happy, start a new message.
1130 ;;; (if (not noerase)
1131 ;;; (progn
1132 ;;; ;; Look for existing unmodified mail buffer.
1133 ;;; (while (and (setq buffer
1134 ;;; (get-buffer (if (= 1 index) "*mail*"
1135 ;;; (format "*mail*<%d>" index))))
1136 ;;; (buffer-modified-p buffer))
1137 ;;; (setq index (1+ index)))
1138 ;;; ;; If none, make a new one.
1139 ;;; (or buffer
1140 ;;; (setq buffer (generate-new-buffer "*mail*")))
1141 ;;; ;; Go there and initialize it.
1142 ;;; (switch-to-buffer buffer)
1143 ;;; (erase-buffer)
1144 ;;; (setq default-directory (expand-file-name "~/"))
1145 ;;; (auto-save-mode auto-save-default)
1146 ;;; (mail-mode)
1147 ;;; (mail-setup to subject in-reply-to cc replybuffer actions)
1148 ;;; (if (and buffer-auto-save-file-name
1149 ;;; (file-exists-p buffer-auto-save-file-name))
1150 ;;; (message "Auto save file for draft message exists; consider M-x mail-recover"))
1151 ;;; t))
1152 (pop-to-buffer "*mail*")
1153 ;; Put the auto-save file in the home dir
1154 ;; to avoid any danger that it can't be written.
1155 (if (file-exists-p (expand-file-name "~/"))
1156 (setq default-directory (expand-file-name "~/")))
1157 (auto-save-mode auto-save-default)
1158 (mail-mode)
1159 ;; Disconnect the buffer from its visited file
1160 ;; (in case the user has actually visited a file *mail*).
1161 ; (set-visited-file-name nil)
1162 (let (initialized)
1163 (and (not noerase)
1164 (or (not (buffer-modified-p))
1165 (y-or-n-p "Unsent message being composed; erase it? "))
1166 (let ((inhibit-read-only t))
1167 (erase-buffer)
1168 (mail-setup to subject in-reply-to cc replybuffer actions)
1169 (setq initialized t)))
1170 (if (and buffer-auto-save-file-name
1171 (file-exists-p buffer-auto-save-file-name))
1172 (message "Auto save file for draft message exists; consider M-x mail-recover"))
1173 initialized))
1174
1175 (defun mail-recover ()
1176 "Reread contents of current buffer from its last auto-save file."
1177 (interactive)
1178 (let ((file-name (make-auto-save-file-name)))
1179 (cond ((save-window-excursion
1180 (if (not (eq system-type 'vax-vms))
1181 (with-output-to-temp-buffer "*Directory*"
1182 (buffer-disable-undo standard-output)
1183 (let ((default-directory "/"))
1184 (call-process
1185 "ls" nil standard-output nil "-l" file-name))))
1186 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
1187 (let ((buffer-read-only nil))
1188 (erase-buffer)
1189 (insert-file-contents file-name nil)))
1190 (t (error "mail-recover cancelled")))))
1191
1192 ;;;###autoload
1193 (defun mail-other-window (&optional noerase to subject in-reply-to cc replybuffer sendactions)
1194 "Like `mail' command, but display mail buffer in another window."
1195 (interactive "P")
1196 (let ((pop-up-windows t)
1197 (special-display-buffer-names nil)
1198 (special-display-regexps nil)
1199 (same-window-buffer-names nil)
1200 (same-window-regexps nil))
1201 (pop-to-buffer "*mail*"))
1202 (mail noerase to subject in-reply-to cc replybuffer sendactions))
1203
1204 ;;;###autoload
1205 (defun mail-other-frame (&optional noerase to subject in-reply-to cc replybuffer sendactions)
1206 "Like `mail' command, but display mail buffer in another frame."
1207 (interactive "P")
1208 (let ((pop-up-frames t)
1209 (special-display-buffer-names nil)
1210 (special-display-regexps nil)
1211 (same-window-buffer-names nil)
1212 (same-window-regexps nil))
1213 (pop-to-buffer "*mail*"))
1214 (mail noerase to subject in-reply-to cc replybuffer sendactions))
1215
1216 ;;; Do not execute these when sendmail.el is loaded,
1217 ;;; only in loaddefs.el.
1218 ;;;###autoload (define-key ctl-x-map "m" 'mail)
1219 ;;;###autoload (define-key ctl-x-4-map "m" 'mail-other-window)
1220 ;;;###autoload (define-key ctl-x-5-map "m" 'mail-other-frame)
1221
1222 ;;;###autoload (add-hook 'same-window-buffer-names "*mail*")
1223
1224 ;;; Do not add anything but external entries on this page.
1225
1226 (provide 'sendmail)
1227
1228 ;;; sendmail.el ends here