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