(Fdelete_backward_char): Convert Finsert_char argument to
[emacs.git] / lisp / mail / sendmail.el
blob355056122d1542cfa95bf49381d38ee9080c27d2
1 ;;; sendmail.el --- mail sending commands for Emacs.
3 ;; Copyright (C) 1985, 86, 92, 93, 94, 95, 96 Free Software Foundation, Inc.
5 ;; Maintainer: FSF
6 ;; Keywords: mail
8 ;; This file is part of GNU Emacs.
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.
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.
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.
25 ;;; Commentary:
27 ;; This mode provides mail-sending facilities from within Emacs. It is
28 ;; documented in the Emacs user's manual.
30 ;;; Code:
32 ;;;###autoload
33 (defvar mail-from-style 'angles "\
34 *Specifies how \"From:\" fields look.
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>")
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.")
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.")
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.")
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'.")
65 ;;;###autoload
66 (defvar mail-header-separator "--text follows this line--" "\
67 *Line used to separate headers from text in messages being composed.")
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)
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.")
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.")
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.")
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.")
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.")
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")
115 (defvar mail-alias-modtime nil
116 "The modification time of your mail alias file when it was last examined.")
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.
130 This is a normal hook, misnamed for historical reasons.
131 It is semi-obsolete and mail agents should no longer use it.")
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.
139 If this hook is entirely empty (nil), a default action is taken
140 instead of no action.")
142 (defvar mail-abbrevs-loaded nil)
143 (defvar mail-mode-map nil)
145 (autoload 'build-mail-aliases "mailalias"
146 "Read mail aliases from user's personal aliases file and set `mail-aliases'."
147 nil)
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)
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'.")
161 (defvar mail-signature-file "~/.signature"
162 "*File containing the text inserted at end of mail buffer.")
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)
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.")
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.")
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.")
205 (defvar mail-mode-syntax-table nil
206 "Syntax table used while in mail mode.")
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)))
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\\|Newsgroups\\):" . 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 .
224 (cons (concat "^" (regexp-quote mail-header-separator) "$")
225 'font-lock-warning-face))
226 ;; Use MATCH-ANCHORED to effectively anchor the regexp left side.
227 `(,cite-chars
228 (,(concat "\\=[ \t]*"
229 "\\(\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
230 "\\(" cite-chars "[ \t]*\\)\\)+"
231 "\\(.*\\)")
232 (beginning-of-line) (end-of-line)
233 (2 font-lock-reference-face nil t)
234 (4 font-lock-comment-face nil t)))
235 '("^\\(X-[A-Za-z0-9-]+\\|In-reply-to\\):.*"
236 . font-lock-string-face))))
237 "Additional expressions to highlight in Mail mode.")
239 (defvar mail-send-hook nil
240 "Normal hook run before sending mail, in Mail mode.")
242 (defun sendmail-sync-aliases ()
243 (let ((modtime (nth 5 (file-attributes mail-personal-alias-file))))
244 (or (equal mail-alias-modtime modtime)
245 (setq mail-alias-modtime modtime
246 mail-aliases t))))
248 (defun mail-setup (to subject in-reply-to cc replybuffer actions)
249 (or mail-default-reply-to
250 (setq mail-default-reply-to (getenv "REPLYTO")))
251 (sendmail-sync-aliases)
252 (if (eq mail-aliases t)
253 (progn
254 (setq mail-aliases nil)
255 (if (file-exists-p mail-personal-alias-file)
256 (build-mail-aliases))))
257 ;; Don't leave this around from a previous message.
258 (kill-local-variable 'buffer-file-coding-system)
259 (setq mail-send-actions actions)
260 (setq mail-reply-action replybuffer)
261 (goto-char (point-min))
262 (insert "To: ")
263 (save-excursion
264 (if to
265 ;; Here removed code to extract names from within <...>
266 ;; on the assumption that mail-strip-quoted-names
267 ;; has been called and has done so.
268 (let ((fill-prefix "\t")
269 (address-start (point)))
270 (insert to "\n")
271 (fill-region-as-paragraph address-start (point-max)))
272 (newline))
273 (if cc
274 (let ((fill-prefix "\t")
275 (address-start (progn (insert "CC: ") (point))))
276 (insert cc "\n")
277 (fill-region-as-paragraph address-start (point-max))))
278 (if in-reply-to
279 (let ((fill-prefix "\t")
280 (fill-column 78)
281 (address-start (point)))
282 (insert "In-reply-to: " in-reply-to "\n")
283 (fill-region-as-paragraph address-start (point-max))))
284 (insert "Subject: " (or subject "") "\n")
285 (if mail-default-headers
286 (insert mail-default-headers))
287 (if mail-default-reply-to
288 (insert "Reply-to: " mail-default-reply-to "\n"))
289 (if mail-self-blind
290 (insert "BCC: " user-mail-address "\n"))
291 (if mail-archive-file-name
292 (insert "FCC: " mail-archive-file-name "\n"))
293 (put-text-property (point)
294 (progn
295 (insert mail-header-separator "\n")
296 (1- (point)))
297 'category 'mail-header-separator)
298 ;; Insert the signature. But remember the beginning of the message.
299 (if to (setq to (point)))
300 (cond ((eq mail-signature t)
301 (if (file-exists-p mail-signature-file)
302 (progn
303 (insert "\n\n-- \n")
304 (insert-file-contents mail-signature-file))))
305 (mail-signature
306 (insert mail-signature)))
307 (goto-char (point-max))
308 (or (bolp) (newline)))
309 (if to (goto-char to))
310 (or to subject in-reply-to
311 (set-buffer-modified-p nil))
312 (run-hooks 'mail-setup-hook))
314 ;;;###autoload
315 (defun mail-mode ()
316 "Major mode for editing mail to be sent.
317 Like Text Mode but with these additional commands:
318 C-c C-s mail-send (send the message) C-c C-c mail-send-and-exit
319 C-c C-f move to a header field (and create it if there isn't):
320 C-c C-f C-t move to To: C-c C-f C-s move to Subject:
321 C-c C-f C-c move to CC: C-c C-f C-b move to BCC:
322 C-c C-f C-f move to FCC:
323 C-c C-t mail-text (move to beginning of message text).
324 C-c C-w mail-signature (insert `mail-signature-file' file).
325 C-c C-y mail-yank-original (insert current message, in Rmail).
326 C-c C-q mail-fill-yanked-message (fill what was yanked).
327 C-c C-v mail-sent-via (add a Sent-via field for each To or CC)."
328 (interactive)
329 (kill-all-local-variables)
330 (make-local-variable 'mail-reply-action)
331 (make-local-variable 'mail-send-actions)
332 (set-syntax-table mail-mode-syntax-table)
333 (use-local-map mail-mode-map)
334 (setq local-abbrev-table text-mode-abbrev-table)
335 (setq major-mode 'mail-mode)
336 (setq mode-name "Mail")
337 (setq buffer-offer-save t)
338 (make-local-variable 'font-lock-defaults)
339 (setq font-lock-defaults '(mail-font-lock-keywords t))
340 (make-local-variable 'paragraph-separate)
341 (make-local-variable 'paragraph-start)
342 (make-local-variable 'normal-auto-fill-function)
343 (setq normal-auto-fill-function 'mail-mode-auto-fill)
344 (make-local-variable 'fill-paragraph-function)
345 (setq fill-paragraph-function 'mail-mode-fill-paragraph)
346 ;; `-- ' precedes the signature. `-----' appears at the start of the
347 ;; lines that delimit forwarded messages.
348 ;; Lines containing just >= 3 dashes, perhaps after whitespace,
349 ;; are also sometimes used and should be separators.
350 (setq paragraph-start (concat (regexp-quote mail-header-separator)
351 "$\\|[ \t]*$\\|" page-delimiter))
352 (setq paragraph-separate paragraph-start)
353 (run-hooks 'text-mode-hook 'mail-mode-hook))
355 (defun mail-mode-auto-fill ()
356 "Carry out Auto Fill for Mail mode.
357 If within the headers, this makes the new lines into continuation lines."
358 (if (< (point)
359 (save-excursion
360 (goto-char (point-min))
361 (if (re-search-forward
362 (concat "^" (regexp-quote mail-header-separator) "$")
363 nil t)
364 (point)
365 0)))
366 (let ((old-line-start (save-excursion (beginning-of-line) (point))))
367 (if (do-auto-fill)
368 (save-excursion
369 (beginning-of-line)
370 (while (not (eq (point) old-line-start))
371 (insert " ")
372 (forward-line -1))
373 t)))
374 (do-auto-fill)))
376 (defun mail-mode-fill-paragraph (arg)
377 ;; Do something special only if within the headers.
378 (if (< (point)
379 (save-excursion
380 (goto-char (point-min))
381 (if (re-search-forward
382 (concat "^" (regexp-quote mail-header-separator) "$")
383 nil t)
384 (point)
385 0)))
386 (let (beg end fieldname)
387 (re-search-backward "^[-a-zA-Z]+:" nil 'yes)
388 (setq beg (point))
389 (setq fieldname
390 (downcase (buffer-substring beg (1- (match-end 0)))))
391 (forward-line 1)
392 ;; Find continuation lines and get rid of their continuation markers.
393 (while (looking-at "[ \t]")
394 (delete-horizontal-space)
395 (forward-line 1))
396 (setq end (point-marker))
397 (goto-char beg)
398 ;; If this field contains addresses,
399 ;; make sure we can fill after each address.
400 (if (member fieldname
401 '("to" "cc" "bcc" "from" "reply-to"
402 "resent-to" "resent-cc" "resent-bcc"
403 "resent-from" "resent-reply-to"))
404 (while (search-forward "," end t)
405 (or (looking-at "[ \t]")
406 (insert " "))))
407 (fill-region-as-paragraph beg end)
408 ;; Mark all lines except the first as continuations.
409 (goto-char beg)
410 (forward-line 1)
411 (while (< (point) end)
412 (insert " ")
413 (forward-line 1))
414 (move-marker end nil)
415 t)))
417 ;;; Set up keymap.
419 (if mail-mode-map
421 (setq mail-mode-map (nconc (make-sparse-keymap) text-mode-map))
422 (define-key mail-mode-map "\M-\t" 'mail-complete)
423 (define-key mail-mode-map "\C-c?" 'describe-mode)
424 (define-key mail-mode-map "\C-c\C-f\C-t" 'mail-to)
425 (define-key mail-mode-map "\C-c\C-f\C-b" 'mail-bcc)
426 (define-key mail-mode-map "\C-c\C-f\C-f" 'mail-fcc)
427 (define-key mail-mode-map "\C-c\C-f\C-c" 'mail-cc)
428 (define-key mail-mode-map "\C-c\C-f\C-s" 'mail-subject)
429 (define-key mail-mode-map "\C-c\C-f\C-r" 'mail-reply-to)
430 (define-key mail-mode-map "\C-c\C-t" 'mail-text)
431 (define-key mail-mode-map "\C-c\C-y" 'mail-yank-original)
432 (define-key mail-mode-map "\C-c\C-r" 'mail-yank-region)
433 (define-key mail-mode-map "\C-c\C-q" 'mail-fill-yanked-message)
434 (define-key mail-mode-map "\C-c\C-w" 'mail-signature)
435 (define-key mail-mode-map "\C-c\C-v" 'mail-sent-via)
436 (define-key mail-mode-map "\C-c\C-c" 'mail-send-and-exit)
437 (define-key mail-mode-map "\C-c\C-s" 'mail-send)
438 (define-key mail-mode-map "\C-c\C-i" 'mail-attach-file))
440 (define-key mail-mode-map [menu-bar mail]
441 (cons "Mail" (make-sparse-keymap "Mail")))
443 (define-key mail-mode-map [menu-bar mail fill]
444 '("Fill Citation" . mail-fill-yanked-message))
446 (define-key mail-mode-map [menu-bar mail yank]
447 '("Cite Original" . mail-yank-original))
449 (define-key mail-mode-map [menu-bar mail signature]
450 '("Insert Signature" . mail-signature))
452 (define-key mail-mode-map [menu-bar mail mail-sep]
453 '("--"))
455 (define-key mail-mode-map [menu-bar mail cancel]
456 '("Cancel" . mail-dont-send))
458 (define-key mail-mode-map [menu-bar mail send-stay]
459 '("Send, Keep Editing" . mail-send))
461 (define-key mail-mode-map [menu-bar mail send]
462 '("Send Message" . mail-send-and-exit))
464 (define-key mail-mode-map [menu-bar headers]
465 (cons "Headers" (make-sparse-keymap "Move to Header")))
467 (define-key mail-mode-map [menu-bar headers text]
468 '("Text" . mail-text))
470 (define-key mail-mode-map [menu-bar headers expand-aliases]
471 '("Expand Aliases" . expand-mail-aliases))
473 (define-key mail-mode-map [menu-bar headers sent-via]
474 '("Sent Via" . mail-sent-via))
476 (define-key mail-mode-map [menu-bar headers reply-to]
477 '("Reply-To" . mail-reply-to))
479 (define-key mail-mode-map [menu-bar headers bcc]
480 '("Bcc" . mail-bcc))
482 (define-key mail-mode-map [menu-bar headers fcc]
483 '("Fcc" . mail-fcc))
485 (define-key mail-mode-map [menu-bar headers cc]
486 '("Cc" . mail-cc))
488 (define-key mail-mode-map [menu-bar headers subject]
489 '("Subject" . mail-subject))
491 (define-key mail-mode-map [menu-bar headers to]
492 '("To" . mail-to))
494 ;; User-level commands for sending.
496 (defun mail-send-and-exit (arg)
497 "Send message like `mail-send', then, if no errors, exit from mail buffer.
498 Prefix arg means don't delete this window."
499 (interactive "P")
500 (mail-send)
501 (mail-bury arg))
503 (defun mail-dont-send (arg)
504 "Don't send the message you have been editing.
505 Prefix arg means don't delete this window."
506 (interactive "P")
507 (mail-bury arg))
509 (defun mail-bury (arg)
510 "Bury this mail buffer."
511 (let ((newbuf (other-buffer (current-buffer))))
512 (bury-buffer (current-buffer))
513 (if (and (or (window-dedicated-p (frame-selected-window))
514 (assq 'mail-dedicated-frame (frame-parameters)))
515 (not (null (delq (selected-frame) (visible-frame-list)))))
516 (delete-frame (selected-frame))
517 (let (rmail-flag summary-buffer)
518 (and (not arg)
519 (not (one-window-p))
520 (save-excursion
521 (set-buffer (window-buffer (next-window (selected-window) 'not)))
522 (setq rmail-flag (eq major-mode 'rmail-mode))
523 (setq summary-buffer
524 (and mail-bury-selects-summary
525 (boundp 'rmail-summary-buffer)
526 rmail-summary-buffer
527 (buffer-name rmail-summary-buffer)
528 (not (get-buffer-window rmail-summary-buffer))
529 rmail-summary-buffer))))
530 (if rmail-flag
531 ;; If the Rmail buffer has a summary, show that.
532 (if summary-buffer (switch-to-buffer summary-buffer)
533 (delete-window))
534 (switch-to-buffer newbuf))))))
536 (defun mail-send ()
537 "Send the message in the current buffer.
538 If `mail-interactive' is non-nil, wait for success indication
539 or error messages, and inform user.
540 Otherwise any failure is reported in a message back to
541 the user from the mailer."
542 (interactive)
543 (if (if buffer-file-name
544 (y-or-n-p "Send buffer contents as mail message? ")
545 (or (buffer-modified-p)
546 (y-or-n-p "Message already sent; resend? ")))
547 (let ((inhibit-read-only t))
548 (run-hooks 'mail-send-hook)
549 (message "Sending...")
550 (funcall send-mail-function)
551 ;; Now perform actions on successful sending.
552 (while mail-send-actions
553 (condition-case nil
554 (apply (car (car mail-send-actions))
555 (cdr (car mail-send-actions)))
556 (error))
557 (setq mail-send-actions (cdr mail-send-actions)))
558 (message "Sending...done")
559 ;; If buffer has no file, mark it as unmodified and delete autosave.
560 (if (not buffer-file-name)
561 (progn
562 (set-buffer-modified-p nil)
563 (delete-auto-save-file-if-necessary t))))))
565 ;; This does the real work of sending a message via sendmail.
566 ;; It is called via the variable send-mail-function.
568 ;;;###autoload
569 (defvar sendmail-coding-system nil
570 "Coding system to which to encode the mail.")
572 (defun sendmail-send-it ()
573 (require 'mail-utils)
574 (let ((errbuf (if mail-interactive
575 (generate-new-buffer " sendmail errors")
577 (tembuf (generate-new-buffer " sendmail temp"))
578 (case-fold-search nil)
579 resend-to-addresses
580 delimline
581 fcc-was-found
582 (mailbuf (current-buffer)))
583 (unwind-protect
584 (save-excursion
585 (set-buffer tembuf)
586 (erase-buffer)
587 (insert-buffer-substring mailbuf)
588 (goto-char (point-max))
589 ;; require one newline at the end.
590 (or (= (preceding-char) ?\n)
591 (insert ?\n))
592 ;; Change header-delimiter to be what sendmail expects.
593 (goto-char (point-min))
594 (re-search-forward
595 (concat "^" (regexp-quote mail-header-separator) "\n"))
596 (replace-match "\n")
597 (backward-char 1)
598 (setq delimline (point-marker))
599 (sendmail-sync-aliases)
600 (if mail-aliases
601 (expand-mail-aliases (point-min) delimline))
602 (goto-char (point-min))
603 ;; ignore any blank lines in the header
604 (while (and (re-search-forward "\n\n\n*" delimline t)
605 (< (point) delimline))
606 (replace-match "\n"))
607 (let ((case-fold-search t))
608 (goto-char (point-min))
609 (while (re-search-forward "^Resent-\\(to\\|cc\\|bcc\\):" delimline t)
610 (setq resend-to-addresses
611 (save-restriction
612 (narrow-to-region (point)
613 (save-excursion
614 (end-of-line)
615 (point)))
616 (append (mail-parse-comma-list)
617 resend-to-addresses)))
618 ;; Delete Resent-BCC ourselves
619 (if (save-excursion (beginning-of-line)
620 (looking-at "resent-bcc"))
621 (delete-region (save-excursion (beginning-of-line) (point))
622 (save-excursion (end-of-line) (1+ (point))))))
623 ;;; Apparently this causes a duplicate Sender.
624 ;;; ;; If the From is different than current user, insert Sender.
625 ;;; (goto-char (point-min))
626 ;;; (and (re-search-forward "^From:" delimline t)
627 ;;; (progn
628 ;;; (require 'mail-utils)
629 ;;; (not (string-equal
630 ;;; (mail-strip-quoted-names
631 ;;; (save-restriction
632 ;;; (narrow-to-region (point-min) delimline)
633 ;;; (mail-fetch-field "From")))
634 ;;; (user-login-name))))
635 ;;; (progn
636 ;;; (forward-line 1)
637 ;;; (insert "Sender: " (user-login-name) "\n")))
638 ;; Don't send out a blank subject line
639 (goto-char (point-min))
640 (if (re-search-forward "^Subject:\\([ \t]*\n\\)+\\b" delimline t)
641 (replace-match "")
642 ;; This one matches a Subject just before the header delimiter.
643 (if (and (re-search-forward "^Subject:\\([ \t]*\n\\)+" delimline t)
644 (= (match-end 0) delimline))
645 (replace-match "")))
646 ;; Put the "From:" field in unless for some odd reason
647 ;; they put one in themselves.
648 (goto-char (point-min))
649 (if (not (re-search-forward "^From:" delimline t))
650 (let* ((login user-mail-address)
651 (fullname (user-full-name))
652 (quote-fullname nil))
653 (if (string-match "[\200-\377]" fullname)
654 (setq fullname (mail-quote-printable fullname t)
655 quote-fullname t))
656 (cond ((eq mail-from-style 'angles)
657 (insert "From: " fullname)
658 (let ((fullname-start (+ (point-min) 6))
659 (fullname-end (point-marker)))
660 (goto-char fullname-start)
661 ;; Look for a character that cannot appear unquoted
662 ;; according to RFC 822.
663 (if (or (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]"
664 fullname-end 1)
665 quote-fullname)
666 (progn
667 ;; Quote fullname, escaping specials.
668 (goto-char fullname-start)
669 (insert "\"")
670 (while (re-search-forward "[\"\\]"
671 fullname-end 1)
672 (replace-match "\\\\\\&" t))
673 (insert "\""))))
674 (insert " <" login ">\n"))
675 ((eq mail-from-style 'parens)
676 (insert "From: " login " (")
677 (let ((fullname-start (point)))
678 (if quote-fullname
679 (insert "\""))
680 (insert fullname)
681 (if quote-fullname
682 (insert "\""))
683 (let ((fullname-end (point-marker)))
684 (goto-char fullname-start)
685 ;; RFC 822 says \ and nonmatching parentheses
686 ;; must be escaped in comments.
687 ;; Escape every instance of ()\ ...
688 (while (re-search-forward "[()\\]" fullname-end 1)
689 (replace-match "\\\\\\&" t))
690 ;; ... then undo escaping of matching parentheses,
691 ;; including matching nested parentheses.
692 (goto-char fullname-start)
693 (while (re-search-forward
694 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
695 fullname-end 1)
696 (replace-match "\\1(\\3)" t)
697 (goto-char fullname-start))))
698 (insert ")\n"))
699 ((null mail-from-style)
700 (insert "From: " login "\n")))))
701 ;; Insert an extra newline if we need it to work around
702 ;; Sun's bug that swallows newlines.
703 (goto-char (1+ delimline))
704 (if (eval mail-mailer-swallows-blank-line)
705 (newline))
706 ;; Find and handle any FCC fields.
707 (goto-char (point-min))
708 (if (re-search-forward "^FCC:" delimline t)
709 (progn
710 (setq fcc-was-found t)
711 (mail-do-fcc delimline)))
712 (if mail-interactive
713 (save-excursion
714 (set-buffer errbuf)
715 (erase-buffer))))
716 (goto-char (point-min))
717 (if (let ((case-fold-search t))
718 (re-search-forward "^To:\\|^cc:\\|^bcc:\\|^resent-to:\
719 \\|^resent-cc:\\|^resent-bcc:"
720 delimline t))
721 (let ((default-directory "/")
722 (coding-system-for-write sendmail-coding-system))
723 (apply 'call-process-region
724 (append (list (point-min) (point-max)
725 (if (boundp 'sendmail-program)
726 sendmail-program
727 "/usr/lib/sendmail")
728 nil errbuf nil "-oi")
729 ;; Always specify who from,
730 ;; since some systems have broken sendmails.
731 (list "-f" (user-login-name))
732 ;;; ;; Don't say "from root" if running under su.
733 ;;; (and (equal (user-real-login-name) "root")
734 ;;; (list "-f" (user-login-name)))
735 (and mail-alias-file
736 (list (concat "-oA" mail-alias-file)))
737 (if mail-interactive
738 ;; These mean "report errors to terminal"
739 ;; and "deliver interactively"
740 '("-oep" "-odi")
741 ;; These mean "report errors by mail"
742 ;; and "deliver in background".
743 '("-oem" "-odb"))
744 ;; Get the addresses from the message
745 ;; unless this is a resend.
746 ;; We must not do that for a resend
747 ;; because we would find the original addresses.
748 ;; For a resend, include the specific addresses.
749 (or resend-to-addresses
750 '("-t")))))
751 (or fcc-was-found
752 (error "No recipients")))
753 (if mail-interactive
754 (save-excursion
755 (set-buffer errbuf)
756 (goto-char (point-min))
757 (while (re-search-forward "\n\n* *" nil t)
758 (replace-match "; "))
759 (if (not (zerop (buffer-size)))
760 (error "Sending...failed to %s"
761 (buffer-substring (point-min) (point-max)))))))
762 (kill-buffer tembuf)
763 (if (bufferp errbuf)
764 (kill-buffer errbuf)))))
766 (defun mail-do-fcc (header-end)
767 (let (fcc-list
768 (rmailbuf (current-buffer))
769 (time (current-time))
770 (tembuf (generate-new-buffer " rmail output"))
771 (case-fold-search t))
772 (save-excursion
773 (goto-char (point-min))
774 (while (re-search-forward "^FCC:[ \t]*" header-end t)
775 (setq fcc-list (cons (buffer-substring (point)
776 (progn
777 (end-of-line)
778 (skip-chars-backward " \t")
779 (point)))
780 fcc-list))
781 (delete-region (match-beginning 0)
782 (progn (forward-line 1) (point))))
783 (set-buffer tembuf)
784 (erase-buffer)
785 ;; This initial newline is written out if the fcc file already exists.
786 (insert "\nFrom " (user-login-name) " "
787 (current-time-string time) "\n")
788 ;; Insert the time zone before the year.
789 (forward-char -1)
790 (forward-word -1)
791 (require 'mail-utils)
792 (insert (mail-rfc822-time-zone time) " ")
793 (goto-char (point-max))
794 (insert-buffer-substring rmailbuf)
795 ;; Make sure messages are separated.
796 (goto-char (point-max))
797 (insert ?\n)
798 (goto-char 2)
799 ;; ``Quote'' "^From " as ">From "
800 ;; (note that this isn't really quoting, as there is no requirement
801 ;; that "^[>]+From " be quoted in the same transparent way.)
802 (let ((case-fold-search nil))
803 (while (search-forward "\nFrom " nil t)
804 (forward-char -5)
805 (insert ?>)))
806 (while fcc-list
807 (let* ((buffer (find-buffer-visiting (car fcc-list)))
808 (curbuf (current-buffer))
809 dont-write-the-file
810 buffer-matches-file
811 (beg (point-min)) (end (point-max))
812 (beg2 (save-excursion (goto-char (point-min))
813 (forward-line 2) (point))))
814 (if buffer
815 ;; File is present in a buffer => append to that buffer.
816 (save-excursion
817 (set-buffer buffer)
818 (setq buffer-matches-file
819 (and (not (buffer-modified-p))
820 (verify-visited-file-modtime buffer)))
821 ;; Keep the end of the accessible portion at the same place
822 ;; unless it is the end of the buffer.
823 (let ((max (if (/= (1+ (buffer-size)) (point-max))
824 (point-max))))
825 (unwind-protect
826 ;; Code below lifted from rmailout.el
827 ;; function rmail-output-to-rmail-file:
828 (let ((buffer-read-only nil)
829 (msg (and (boundp 'rmail-current-message)
830 rmail-current-message)))
831 ;; If MSG is non-nil, buffer is in RMAIL mode.
832 (if msg
833 (progn
834 (rmail-maybe-set-message-counters)
835 (widen)
836 (narrow-to-region (point-max) (point-max))
837 (insert "\C-l\n0, unseen,,\n*** EOOH ***\n"
838 "Date: " (mail-rfc822-date) "\n")
839 (insert-buffer-substring curbuf beg2 end)
840 (insert "\n\C-_")
841 (goto-char (point-min))
842 (widen)
843 (search-backward "\n\^_")
844 (narrow-to-region (point) (point-max))
845 (rmail-count-new-messages t)
846 (rmail-show-message msg)
847 (setq max nil))
848 ;; Output file not in rmail mode
849 ;; => just insert at the end.
850 (narrow-to-region (point-min) (1+ (buffer-size)))
851 (goto-char (point-max))
852 (insert-buffer-substring curbuf beg end))
853 (or buffer-matches-file
854 (progn
855 (if (y-or-n-p (format "Save file %s? "
856 (car fcc-list)))
857 (save-buffer))
858 (setq dont-write-the-file t))))
859 (if max (narrow-to-region (point-min) max))))))
860 ;; Append to the file directly,
861 ;; unless we've already taken care of it.
862 (if (and (not dont-write-the-file)
863 (file-exists-p (car fcc-list))
864 (mail-file-babyl-p (car fcc-list)))
865 ;; If the file is a Babyl file,
866 ;; convert the message to Babyl format.
867 (save-excursion
868 (set-buffer (get-buffer-create " mail-temp"))
869 (setq buffer-read-only nil)
870 (erase-buffer)
871 (insert "\C-l\n0, unseen,,\n*** EOOH ***\n"
872 "Date: " (mail-rfc822-date) "\n")
873 (insert-buffer-substring curbuf beg2 end)
874 (insert "\n\C-_")
875 (write-region (point-min) (point-max) (car fcc-list) t)
876 (erase-buffer))
877 (write-region
878 (1+ (point-min)) (point-max) (car fcc-list) t))
879 (and buffer (not dont-write-the-file)
880 (with-current-buffer buffer
881 (set-visited-file-modtime))))
882 (setq fcc-list (cdr fcc-list))))
883 (kill-buffer tembuf)))
885 (defun mail-sent-via ()
886 "Make a Sent-via header line from each To or CC header line."
887 (interactive)
888 (save-excursion
889 (goto-char (point-min))
890 ;; find the header-separator
891 (search-forward (concat "\n" mail-header-separator "\n"))
892 (forward-line -1)
893 ;; put a marker at the end of the header
894 (let ((end (point-marker))
895 (case-fold-search t)
896 to-line)
897 (goto-char (point-min))
898 ;; search for the To: lines and make Sent-via: lines from them
899 ;; search for the next To: line
900 (while (re-search-forward "^\\(to\\|cc\\):" end t)
901 ;; Grab this line plus all its continuations, sans the `to:'.
902 (let ((to-line
903 (buffer-substring (point)
904 (progn
905 (if (re-search-forward "^[^ \t\n]" end t)
906 (backward-char 1)
907 (goto-char end))
908 (point)))))
909 ;; Insert a copy, with altered header field name.
910 (insert-before-markers "Sent-via:" to-line))))))
912 (defun mail-to ()
913 "Move point to end of To-field."
914 (interactive)
915 (expand-abbrev)
916 (mail-position-on-field "To"))
918 (defun mail-subject ()
919 "Move point to end of Subject-field."
920 (interactive)
921 (expand-abbrev)
922 (mail-position-on-field "Subject"))
924 (defun mail-cc ()
925 "Move point to end of CC-field. Create a CC field if none."
926 (interactive)
927 (expand-abbrev)
928 (or (mail-position-on-field "cc" t)
929 (progn (mail-position-on-field "to")
930 (insert "\nCC: "))))
932 (defun mail-bcc ()
933 "Move point to end of BCC-field. Create a BCC field if none."
934 (interactive)
935 (expand-abbrev)
936 (or (mail-position-on-field "bcc" t)
937 (progn (mail-position-on-field "to")
938 (insert "\nBCC: "))))
940 (defun mail-fcc (folder)
941 "Add a new FCC field, with file name completion."
942 (interactive "FFolder carbon copy: ")
943 (expand-abbrev)
944 (or (mail-position-on-field "fcc" t) ;Put new field after exiting FCC.
945 (mail-position-on-field "to"))
946 (insert "\nFCC: " folder))
948 (defun mail-reply-to ()
949 "Move point to end of Reply-To-field."
950 (interactive)
951 (expand-abbrev)
952 (mail-position-on-field "Reply-To"))
954 (defun mail-position-on-field (field &optional soft)
955 (let (end
956 (case-fold-search t))
957 (goto-char (point-min))
958 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
959 (setq end (match-beginning 0))
960 (goto-char (point-min))
961 (if (re-search-forward (concat "^" (regexp-quote field) ":") end t)
962 (progn
963 (re-search-forward "^[^ \t]" nil 'move)
964 (beginning-of-line)
965 (skip-chars-backward "\n")
967 (or soft
968 (progn (goto-char end)
969 (insert field ": \n")
970 (skip-chars-backward "\n")))
971 nil)))
973 (defun mail-text ()
974 "Move point to beginning of message text."
975 (interactive)
976 (expand-abbrev)
977 (goto-char (point-min))
978 (search-forward (concat "\n" mail-header-separator "\n")))
980 (defun mail-signature (atpoint)
981 "Sign letter with contents of the file `mail-signature-file'.
982 Prefix arg means put contents at point."
983 (interactive "P")
984 (save-excursion
985 (or atpoint
986 (goto-char (point-max)))
987 (skip-chars-backward " \t\n")
988 (end-of-line)
989 (or atpoint
990 (delete-region (point) (point-max)))
991 (insert "\n\n-- \n")
992 (insert-file-contents (expand-file-name mail-signature-file))))
994 (defun mail-fill-yanked-message (&optional justifyp)
995 "Fill the paragraphs of a message yanked into this one.
996 Numeric argument means justify as well."
997 (interactive "P")
998 (save-excursion
999 (goto-char (point-min))
1000 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1001 (fill-individual-paragraphs (point)
1002 (point-max)
1003 justifyp
1004 t)))
1006 (defun mail-indent-citation ()
1007 "Modify text just inserted from a message to be cited.
1008 The inserted text should be the region.
1009 When this function returns, the region is again around the modified text.
1011 Normally, indent each nonblank line `mail-indentation-spaces' spaces.
1012 However, if `mail-yank-prefix' is non-nil, insert that prefix on each line."
1013 (mail-yank-clear-headers (region-beginning) (region-end))
1014 (if (null mail-yank-prefix)
1015 (indent-rigidly (region-beginning) (region-end)
1016 mail-indentation-spaces)
1017 (save-excursion
1018 (goto-char (region-beginning))
1019 (while (< (point) (region-end))
1020 (insert mail-yank-prefix)
1021 (forward-line 1)))))
1023 (defun mail-yank-original (arg)
1024 "Insert the message being replied to, if any (in rmail).
1025 Puts point after the text and mark before.
1026 Normally, indents each nonblank line ARG spaces (default 3).
1027 However, if `mail-yank-prefix' is non-nil, insert that prefix on each line.
1029 Just \\[universal-argument] as argument means don't indent, insert no prefix,
1030 and don't delete any header fields."
1031 (interactive "P")
1032 (if mail-reply-action
1033 (let ((start (point))
1034 (original mail-reply-action))
1035 (and (consp original) (eq (car original) 'insert-buffer)
1036 (setq original (nth 1 original)))
1037 (if (consp original)
1038 (apply (car original) (cdr original))
1039 ;; If the original message is in another window in the same frame,
1040 ;; delete that window to save screen space.
1041 ;; t means don't alter other frames.
1042 (delete-windows-on original t)
1043 (insert-buffer original))
1044 (if (consp arg)
1046 (goto-char start)
1047 (let ((mail-indentation-spaces (if arg (prefix-numeric-value arg)
1048 mail-indentation-spaces)))
1049 (if mail-citation-hook
1050 (run-hooks 'mail-citation-hook)
1051 (if mail-yank-hooks
1052 (run-hooks 'mail-yank-hooks)
1053 (mail-indent-citation)))))
1054 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
1055 ;; It is cleaner to avoid activation, even though the command
1056 ;; loop would deactivate the mark because we inserted text.
1057 (goto-char (prog1 (mark t)
1058 (set-marker (mark-marker) (point) (current-buffer))))
1059 (if (not (eolp)) (insert ?\n)))))
1061 (defun mail-yank-clear-headers (start end)
1062 (if (< end start)
1063 (let (temp)
1064 (setq temp start start end end temp)))
1065 (if mail-yank-ignored-headers
1066 (save-excursion
1067 (goto-char start)
1068 (if (search-forward "\n\n" end t)
1069 (save-restriction
1070 (narrow-to-region start (point))
1071 (goto-char start)
1072 (while (let ((case-fold-search t))
1073 (re-search-forward mail-yank-ignored-headers nil t))
1074 (beginning-of-line)
1075 (delete-region (point)
1076 (progn (re-search-forward "\n[^ \t]")
1077 (forward-char -1)
1078 (point)))))))))
1080 (defun mail-yank-region (arg)
1081 "Insert the selected region from the message being replied to.
1082 Puts point after the text and mark before.
1083 Normally, indents each nonblank line ARG spaces (default 3).
1084 However, if `mail-yank-prefix' is non-nil, insert that prefix on each line.
1086 Just \\[universal-argument] as argument means don't indent, insert no prefix,
1087 and don't delete any header fields."
1088 (interactive "P")
1089 (and (consp mail-reply-action)
1090 (eq (car mail-reply-action) 'insert-buffer)
1091 (let ((buffer (nth 1 mail-reply-action))
1092 (start (point)))
1093 ;; Insert the citation text.
1094 (insert (with-current-buffer buffer
1095 (buffer-substring (point) (mark))))
1096 (push-mark start)
1097 ;; Indent or otherwise annotate the citation text.
1098 (if (consp arg)
1100 (let ((mail-indentation-spaces (if arg (prefix-numeric-value arg)
1101 mail-indentation-spaces)))
1102 (if mail-citation-hook
1103 (run-hooks 'mail-citation-hook)
1104 (if mail-yank-hooks
1105 (run-hooks 'mail-yank-hooks)
1106 (mail-indent-citation))))))))
1108 (defun mail-attach-file (&optional file)
1109 "Insert a file at the end of the buffer, with separator lines around it."
1110 (interactive "fAttach file: ")
1111 (save-excursion
1112 (goto-char (point-max))
1113 (or (bolp) (newline))
1114 (newline)
1115 (let ((start (point))
1116 middle)
1117 (insert (format "===File %s===" file))
1118 (insert-char ?= (max 0 (- 60 (current-column))))
1119 (newline)
1120 (setq middle (point))
1121 (insert "============================================================\n")
1122 (push-mark)
1123 (goto-char middle)
1124 (insert-file-contents file)
1125 (or (bolp) (newline))
1126 (goto-char start))))
1128 ;; Put these commands last, to reduce chance of lossage from quitting
1129 ;; in middle of loading the file.
1131 ;;;###autoload (add-hook 'same-window-buffer-names "*mail*")
1133 ;;;###autoload
1134 (defun mail (&optional noerase to subject in-reply-to cc replybuffer actions)
1135 "Edit a message to be sent. Prefix arg means resume editing (don't erase).
1136 When this function returns, the buffer `*mail*' is selected.
1137 The value is t if the message was newly initialized; otherwise, nil.
1139 Optionally, the signature file `mail-signature-file' can be inserted at the
1140 end; see the variable `mail-signature'.
1142 \\<mail-mode-map>
1143 While editing message, type \\[mail-send-and-exit] to send the message and exit.
1145 Various special commands starting with C-c are available in sendmail mode
1146 to move to message header fields:
1147 \\{mail-mode-map}
1149 If `mail-self-blind' is non-nil, a BCC to yourself is inserted
1150 when the message is initialized.
1152 If `mail-default-reply-to' is non-nil, it should be an address (a string);
1153 a Reply-to: field with that address is inserted.
1155 If `mail-archive-file-name' is non-nil, an FCC field with that file name
1156 is inserted.
1158 The normal hook `mail-setup-hook' is run after the message is
1159 initialized. It can add more default fields to the message.
1161 When calling from a program, the first argument if non-nil says
1162 not to erase the existing contents of the `*mail*' buffer.
1164 The second through fifth arguments,
1165 TO, SUBJECT, IN-REPLY-TO and CC, specify if non-nil
1166 the initial contents of those header fields.
1167 These arguments should not have final newlines.
1168 The sixth argument REPLYBUFFER is a buffer which contains an
1169 original message being replied to, or else an action
1170 of the form (FUNCTION . ARGS) which says how to insert the original.
1171 Or it can be nil, if not replying to anything.
1172 The seventh argument ACTIONS is a list of actions to take
1173 if/when the message is sent. Each action looks like (FUNCTION . ARGS);
1174 when the message is sent, we apply FUNCTION to ARGS.
1175 This is how Rmail arranges to mark messages `answered'."
1176 (interactive "P")
1177 ;;; This is commented out because I found it was confusing in practice.
1178 ;;; It is easy enough to rename *mail* by hand with rename-buffer
1179 ;;; if you want to have multiple mail buffers.
1180 ;;; And then you can control which messages to save. --rms.
1181 ;;; (let ((index 1)
1182 ;;; buffer)
1183 ;;; ;; If requested, look for a mail buffer that is modified and go to it.
1184 ;;; (if noerase
1185 ;;; (progn
1186 ;;; (while (and (setq buffer
1187 ;;; (get-buffer (if (= 1 index) "*mail*"
1188 ;;; (format "*mail*<%d>" index))))
1189 ;;; (not (buffer-modified-p buffer)))
1190 ;;; (setq index (1+ index)))
1191 ;;; (if buffer (switch-to-buffer buffer)
1192 ;;; ;; If none exists, start a new message.
1193 ;;; ;; This will never re-use an existing unmodified mail buffer
1194 ;;; ;; (since index is not 1 anymore). Perhaps it should.
1195 ;;; (setq noerase nil))))
1196 ;;; ;; Unless we found a modified message and are happy, start a new message.
1197 ;;; (if (not noerase)
1198 ;;; (progn
1199 ;;; ;; Look for existing unmodified mail buffer.
1200 ;;; (while (and (setq buffer
1201 ;;; (get-buffer (if (= 1 index) "*mail*"
1202 ;;; (format "*mail*<%d>" index))))
1203 ;;; (buffer-modified-p buffer))
1204 ;;; (setq index (1+ index)))
1205 ;;; ;; If none, make a new one.
1206 ;;; (or buffer
1207 ;;; (setq buffer (generate-new-buffer "*mail*")))
1208 ;;; ;; Go there and initialize it.
1209 ;;; (switch-to-buffer buffer)
1210 ;;; (erase-buffer)
1211 ;;; (setq default-directory (expand-file-name "~/"))
1212 ;;; (auto-save-mode auto-save-default)
1213 ;;; (mail-mode)
1214 ;;; (mail-setup to subject in-reply-to cc replybuffer actions)
1215 ;;; (if (and buffer-auto-save-file-name
1216 ;;; (file-exists-p buffer-auto-save-file-name))
1217 ;;; (message "Auto save file for draft message exists; consider M-x mail-recover"))
1218 ;;; t))
1219 (pop-to-buffer "*mail*")
1220 ;; Put the auto-save file in the home dir
1221 ;; to avoid any danger that it can't be written.
1222 (if (file-exists-p (expand-file-name "~/"))
1223 (setq default-directory (expand-file-name "~/")))
1224 (auto-save-mode auto-save-default)
1225 (mail-mode)
1226 ;; Disconnect the buffer from its visited file
1227 ;; (in case the user has actually visited a file *mail*).
1228 ; (set-visited-file-name nil)
1229 (let (initialized)
1230 (and (not noerase)
1231 (or (not (buffer-modified-p))
1232 (y-or-n-p "Unsent message being composed; erase it? "))
1233 (let ((inhibit-read-only t))
1234 (erase-buffer)
1235 (mail-setup to subject in-reply-to cc replybuffer actions)
1236 (setq initialized t)))
1237 (if (and buffer-auto-save-file-name
1238 (file-exists-p buffer-auto-save-file-name))
1239 (message "Auto save file for draft message exists; consider M-x mail-recover"))
1240 initialized))
1242 (defun mail-recover ()
1243 "Reread contents of current buffer from its last auto-save file."
1244 (interactive)
1245 (let ((file-name (make-auto-save-file-name)))
1246 (cond ((save-window-excursion
1247 (if (not (eq system-type 'vax-vms))
1248 (with-output-to-temp-buffer "*Directory*"
1249 (buffer-disable-undo standard-output)
1250 (let ((default-directory "/"))
1251 (call-process
1252 "ls" nil standard-output nil "-l" file-name))))
1253 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
1254 (let ((buffer-read-only nil))
1255 (erase-buffer)
1256 (insert-file-contents file-name nil)))
1257 (t (error "mail-recover cancelled")))))
1259 ;;;###autoload
1260 (defun mail-other-window (&optional noerase to subject in-reply-to cc replybuffer sendactions)
1261 "Like `mail' command, but display mail buffer in another window."
1262 (interactive "P")
1263 (let ((pop-up-windows t)
1264 (special-display-buffer-names nil)
1265 (special-display-regexps nil)
1266 (same-window-buffer-names nil)
1267 (same-window-regexps nil))
1268 (pop-to-buffer "*mail*"))
1269 (mail noerase to subject in-reply-to cc replybuffer sendactions))
1271 ;;;###autoload
1272 (defun mail-other-frame (&optional noerase to subject in-reply-to cc replybuffer sendactions)
1273 "Like `mail' command, but display mail buffer in another frame."
1274 (interactive "P")
1275 (let ((pop-up-frames t)
1276 (special-display-buffer-names nil)
1277 (special-display-regexps nil)
1278 (same-window-buffer-names nil)
1279 (same-window-regexps nil))
1280 (pop-to-buffer "*mail*"))
1281 (mail noerase to subject in-reply-to cc replybuffer sendactions))
1283 ;;; Do not add anything but external entries on this page.
1285 (provide 'sendmail)
1287 ;;; sendmail.el ends here