1 ;;; sendmail.el --- mail sending commands for Emacs.
3 ;; Copyright (C) 1985, 1986, 1992, 1993, 1994 Free Software Foundation, Inc.
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)
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
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26 ;; This mode provides mail-sending facilities from within Emacs. It is
27 ;; documented in the Emacs user's manual.
32 (defvar mail-self-blind nil "\
33 Non-nil means insert BCC to self in messages to be sent.
34 This is done when the message is initialized,
35 so you can remove or alter the BCC field to override the default.")
38 (defvar mail-interactive nil "\
39 Non-nil means when sending a message wait for and display errors.
40 nil means let mailer mail back a message to report errors.")
43 (defvar mail-yank-ignored-headers "^via:\\|^mail-from:\\|^origin:\\|^status:\\|^remailed\\|^received:\\|^message-id:\\|^summary-line:\\|^to:\\|^subject:\\|^in-reply-to:\\|^return-path:" "\
44 Delete these headers from old message when it's inserted in a reply.")
46 ;; Useful to set in site-init.el
48 (defvar send-mail-function 'sendmail-send-it "\
49 Function to call to send the current buffer as mail.
50 The headers are be delimited by a line which is `mail-header-separator'.")
53 (defvar mail-header-separator "--text follows this line--" "\
54 *Line used to separate headers from text in messages being composed.")
57 (defvar mail-archive-file-name nil "\
58 *Name of file to write all outgoing messages in, or nil for none.
59 Do not use an rmail file here! Instead, use its inbox file.")
62 (defvar mail-default-reply-to nil
63 "*Address to insert as default Reply-to field of outgoing messages.")
66 (defvar mail-alias-file nil
67 "*If non-nil, the name of a file to use instead of `/usr/lib/aliases'.
68 This file defines aliases to be expanded by the mailer; this is a different
69 feature from that of defining aliases in `.mailrc' to be expanded in Emacs.
70 This variable has no effect unless your system uses sendmail as its mailer.")
72 (defvar mail-aliases t
73 "Alist of mail address aliases,
74 or t meaning should be initialized from `~/.mailrc'.
75 The alias definitions in `~/.mailrc' have this form:
78 (defvar mail-alias-modtime nil
79 "The modification time of ~/.mailrc when it was last examined.")
81 (defvar mail-yank-prefix nil
82 "*Prefix insert on lines of yanked message being replied to.
83 nil means use indentation.")
84 (defvar mail-indentation-spaces 3
85 "*Number of spaces to insert at the beginning of each cited line.
86 Used by `mail-yank-original' via `mail-yank-cite'.")
87 (defvar mail-yank-hooks nil
88 "Obsolete hook for modifying a citation just inserted in the mail buffer.
89 Each hook function can find the citation between (point) and (mark t).
90 And each hook function should leave point and mark around the citation
93 This is a normal hook, misnamed for historical reasons.
94 It is semi-obsolete and mail agents should no longer use it.")
96 (defvar mail-citation-hook nil
97 "*Hook for modifying a citation just inserted in the mail buffer.
98 Each hook function can find the citation between (point) and (mark t).
99 And each hook function should leave point and mark around the citation
102 If this hook is entirely empty (nil), a default action is taken
103 instead of no action.")
105 (defvar mail-abbrevs-loaded nil)
106 (defvar mail-mode-map nil)
108 (autoload 'build-mail-aliases "mailalias"
109 "Read mail aliases from `~/.mailrc' and set `mail-aliases'."
112 (autoload 'expand-mail-aliases "mailalias"
113 "Expand all mail aliases in suitable header fields found between BEG and END.
114 Suitable header fields are `To', `Cc' and `Bcc' and their `Resent-' variants.
115 Optional second arg EXCLUDE may be a regular expression defining text to be
116 removed from alias expansions."
120 (defvar mail-signature nil
121 "*Text inserted at end of mail buffer when a message is initialized.
122 If t, it means to insert the contents of the file `~/.signature'.")
124 (defvar mail-reply-buffer nil)
125 (defvar mail-send-actions nil
126 "A list of actions to be performed upon successful sending of a message.")
128 (defvar mail-default-headers nil
129 "*A string containing header lines, to be inserted in outgoing messages.
130 It is inserted before you edit the message,
131 so you can edit or delete these lines.")
133 ;; Note: could use /usr/ucb/mail instead of sendmail;
134 ;; options -t, and -v if not interactive.
135 (defvar mail-mailer-swallows-blank-line
136 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)" system-configuration)
137 (file-readable-p "/etc/sendmail.cf")
138 (let ((buffer (get-buffer-create " *temp*")))
142 (insert-file-contents "/etc/sendmail.cf")
143 (goto-char (point-min))
144 (let ((case-fold-search nil))
145 (re-search-forward "^OR\\>" nil t)))
146 (kill-buffer buffer))))
147 '(looking-at "[ \t]\\|[-a-zA-Z]+:"))
148 "Set this non-nil if the system's mailer runs the header and body together.
149 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
150 The value should be an expression to test whether the problem will
153 (defvar mail-mode-syntax-table nil
154 "Syntax table used while in mail mode.")
156 (if (null mail-mode-syntax-table)
158 (setq mail-mode-syntax-table (copy-syntax-table text-mode-syntax-table))
159 (modify-syntax-entry ?% ". " mail-mode-syntax-table)))
161 (defvar mail-send-hook nil
162 "Normal hook run before sending mail, in Mail mode.")
164 (defun synch-mail-aliases ()
165 (let ((modtime (nth 5 (file-attributes "~/.mailrc"))))
166 (or (equal mail-alias-modtime modtime)
167 (setq mail-alias-modtime modtime
170 (defun mail-setup (to subject in-reply-to cc replybuffer actions)
172 (if (eq mail-aliases t)
174 (setq mail-aliases nil)
175 (if (file-exists-p "~/.mailrc")
176 (build-mail-aliases))))
177 (setq mail-send-actions actions)
178 (setq mail-reply-buffer replybuffer)
179 (goto-char (point-min))
183 ;; Here removed code to extract names from within <...>
184 ;; on the assumption that mail-strip-quoted-names
185 ;; has been called and has done so.
186 (let ((fill-prefix "\t")
187 (address-start (point)))
189 (fill-region-as-paragraph address-start (point-max)))
192 (let ((fill-prefix "\t")
193 (address-start (progn (insert "CC: ") (point))))
195 (fill-region-as-paragraph address-start (point-max))))
197 (insert "In-reply-to: " in-reply-to "\n"))
198 (insert "Subject: " (or subject "") "\n")
199 (if mail-default-headers
200 (insert mail-default-headers))
201 (if mail-default-reply-to
202 (insert "Reply-to: " mail-default-reply-to "\n"))
204 (insert "BCC: " (user-login-name) "\n"))
205 (if mail-archive-file-name
206 (insert "FCC: " mail-archive-file-name "\n"))
207 (insert mail-header-separator "\n")
208 ;; Insert the signature. But remember the beginning of the message.
209 (if to (setq to (point)))
210 (cond ((eq mail-signature t)
211 (if (file-exists-p "~/.signature")
214 (insert-file-contents "~/.signature"))))
216 (insert mail-signature)))
217 (goto-char (point-max))
218 (or (bolp) (newline)))
219 (if to (goto-char to))
220 (or to subject in-reply-to
221 (set-buffer-modified-p nil))
222 (run-hooks 'mail-setup-hook))
226 "Major mode for editing mail to be sent.
227 Like Text Mode but with these additional commands:
228 C-c C-s mail-send (send the message) C-c C-c mail-send-and-exit
229 C-c C-f move to a header field (and create it if there isn't):
230 C-c C-f C-t move to To: C-c C-f C-s move to Subj:
231 C-c C-f C-b move to BCC: C-c C-f C-c move to CC:
232 C-c C-f C-f move to FCC:
233 C-c C-t move to message text.
234 C-c C-y mail-yank-original (insert current message, in Rmail).
235 C-c C-q mail-fill-yanked-message (fill what was yanked).
236 C-c C-v mail-sent-via (add a sent-via field for each To or CC)."
238 (kill-all-local-variables)
239 (make-local-variable 'mail-reply-buffer)
240 (setq mail-reply-buffer nil)
241 (make-local-variable 'mail-send-actions)
242 (set-syntax-table mail-mode-syntax-table)
243 (use-local-map mail-mode-map)
244 (setq local-abbrev-table text-mode-abbrev-table)
245 (setq major-mode 'mail-mode)
246 (setq mode-name "Mail")
247 (setq buffer-offer-save t)
248 (make-local-variable 'paragraph-separate)
249 (make-local-variable 'paragraph-start)
250 (setq paragraph-start (concat "^" mail-header-separator
251 "$\\|^[ \t]*[-_][-_][-_]+$\\|"
253 (setq paragraph-separate (concat "^" mail-header-separator
254 "$\\|^[ \t]*[-_][-_][-_]+$\\|"
256 (run-hooks 'text-mode-hook 'mail-mode-hook))
262 (setq mail-mode-map (nconc (make-sparse-keymap) text-mode-map))
263 (define-key mail-mode-map "\C-c?" 'describe-mode)
264 (define-key mail-mode-map "\C-c\C-f\C-t" 'mail-to)
265 (define-key mail-mode-map "\C-c\C-f\C-b" 'mail-bcc)
266 (define-key mail-mode-map "\C-c\C-f\C-f" 'mail-fcc)
267 (define-key mail-mode-map "\C-c\C-f\C-c" 'mail-cc)
268 (define-key mail-mode-map "\C-c\C-f\C-s" 'mail-subject)
269 (define-key mail-mode-map "\C-c\C-t" 'mail-text)
270 (define-key mail-mode-map "\C-c\C-y" 'mail-yank-original)
271 (define-key mail-mode-map "\C-c\C-q" 'mail-fill-yanked-message)
272 (define-key mail-mode-map "\C-c\C-w" 'mail-signature)
273 (define-key mail-mode-map "\C-c\C-v" 'mail-sent-via)
274 (define-key mail-mode-map "\C-c\C-c" 'mail-send-and-exit)
275 (define-key mail-mode-map "\C-c\C-s" 'mail-send))
277 (define-key mail-mode-map [menu-bar mail]
278 (cons "Mail" (make-sparse-keymap "Mail")))
280 (define-key mail-mode-map [menu-bar mail fill]
281 '("Fill Citation" . mail-fill-yanked-message))
283 (define-key mail-mode-map [menu-bar mail yank]
284 '("Cite Original" . mail-yank-original))
286 (define-key mail-mode-map [menu-bar mail signature]
287 '("Insert Signature" . mail-signature))
289 (define-key mail-mode-map [menu-bar mail cancel]
290 '("Cancel" . mail-dont-send))
292 (define-key mail-mode-map [menu-bar mail send-stay]
293 '("Send, Keep Editing" . mail-send))
295 (define-key mail-mode-map [menu-bar mail send]
296 '("Send Message" . mail-send-and-exit))
298 (define-key mail-mode-map [menu-bar headers]
299 (cons "Headers" (make-sparse-keymap "Headers")))
301 (define-key mail-mode-map [menu-bar headers sent-via]
302 '("Sent Via" . mail-sent-via))
304 (define-key mail-mode-map [menu-bar headers text]
305 '("Text" . mail-text))
307 (define-key mail-mode-map [menu-bar headers bcc]
310 (define-key mail-mode-map [menu-bar headers fcc]
313 (define-key mail-mode-map [menu-bar headers cc]
316 (define-key mail-mode-map [menu-bar headers subject]
317 '("Subject" . mail-subject))
319 (define-key mail-mode-map [menu-bar headers to]
322 (defun mail-send-and-exit (arg)
323 "Send message like `mail-send', then, if no errors, exit from mail buffer.
324 Prefix arg means don't delete this window."
329 (defun mail-dont-send (arg)
330 "Don't send the message you have been editing.
331 Prefix arg means don't delete this window."
335 (defun mail-bury (arg)
336 "Bury this mail buffer."
337 (let ((newbuf (other-buffer (current-buffer))))
338 (bury-buffer (current-buffer))
339 (if (and (fboundp 'frame-parameters)
340 (cdr (assq 'dedicated (frame-parameters)))
341 (not (null (delq (selected-frame) (visible-frame-list)))))
342 (delete-frame (selected-frame))
343 (let (rmail-flag summary-buffer)
347 (set-buffer (window-buffer (next-window (selected-window) 'not)))
348 (setq rmail-flag (eq major-mode 'rmail-mode))
350 (and (boundp 'rmail-summary-buffer)
352 (buffer-name rmail-summary-buffer)
353 (not (get-buffer-window rmail-summary-buffer))
354 rmail-summary-buffer))))
356 ;; If the Rmail buffer has a summary, show that.
357 (if summary-buffer (switch-to-buffer summary-buffer)
359 (switch-to-buffer newbuf))))))
362 "Send the message in the current buffer.
363 If `mail-interactive' is non-nil, wait for success indication
364 or error messages, and inform user.
365 Otherwise any failure is reported in a message back to
366 the user from the mailer."
368 (if (if buffer-file-name
369 (y-or-n-p "Send buffer contents as mail message? ")
370 (or (buffer-modified-p)
371 (y-or-n-p "Message already sent; resend? ")))
373 (run-hooks 'mail-send-hook)
374 (message "Sending...")
375 (funcall send-mail-function)
376 ;; Now perform actions on successful sending.
377 (while mail-send-actions
379 (apply (car (car mail-send-actions))
380 (cdr (car mail-send-actions)))
382 (setq mail-send-actions (cdr mail-send-actions)))
383 (message "Sending...done")
384 ;; If buffer has no file, mark it as unmodified and delete autosave.
385 (if (not buffer-file-name)
387 (set-buffer-modified-p nil)
388 (delete-auto-save-file-if-necessary t))))))
390 (defun sendmail-send-it ()
391 (let ((errbuf (if mail-interactive
392 (generate-new-buffer " sendmail errors")
394 (tembuf (generate-new-buffer " sendmail temp"))
395 (case-fold-search nil)
398 (mailbuf (current-buffer)))
403 (insert-buffer-substring mailbuf)
404 (goto-char (point-max))
405 ;; require one newline at the end.
406 (or (= (preceding-char) ?\n)
408 ;; Change header-delimiter to be what sendmail expects.
409 (goto-char (point-min))
411 (concat "^" (regexp-quote mail-header-separator) "\n"))
414 (setq delimline (point-marker))
417 (expand-mail-aliases (point-min) delimline))
418 (goto-char (point-min))
419 ;; ignore any blank lines in the header
420 (while (and (re-search-forward "\n\n\n*" delimline t)
421 (< (point) delimline))
422 (replace-match "\n"))
423 (let ((case-fold-search t))
424 (goto-char (point-min))
425 ;; Find and handle any FCC fields.
426 (goto-char (point-min))
427 (if (re-search-forward "^FCC:" delimline t)
428 (mail-do-fcc delimline))
429 (goto-char (point-min))
430 (require 'mail-utils)
431 (while (re-search-forward "^Resent-to:" delimline t)
432 (setq resend-to-addresses
434 (narrow-to-region (point)
438 (append (mail-parse-comma-list)
439 resend-to-addresses))))
440 ;;; Apparently this causes a duplicate Sender.
441 ;;; ;; If the From is different than current user, insert Sender.
442 ;;; (goto-char (point-min))
443 ;;; (and (re-search-forward "^From:" delimline t)
445 ;;; (require 'mail-utils)
446 ;;; (not (string-equal
447 ;;; (mail-strip-quoted-names
448 ;;; (save-restriction
449 ;;; (narrow-to-region (point-min) delimline)
450 ;;; (mail-fetch-field "From")))
451 ;;; (user-login-name))))
454 ;;; (insert "Sender: " (user-login-name) "\n")))
455 ;; "S:" is an abbreviation for "Subject:".
456 (goto-char (point-min))
457 (if (re-search-forward "^S:" delimline t)
458 (replace-match "Subject:"))
459 ;; Don't send out a blank subject line
460 (goto-char (point-min))
461 (if (re-search-forward "^Subject:[ \t]*\n" delimline t)
463 ;; Insert an extra newline if we need it to work around
464 ;; Sun's bug that swallows newlines.
465 (goto-char (1+ delimline))
466 (if (eval mail-mailer-swallows-blank-line)
472 (apply 'call-process-region
473 (append (list (point-min) (point-max)
474 (if (boundp 'sendmail-program)
477 nil errbuf nil "-oi")
478 ;; Always specify who from,
479 ;; since some systems have broken sendmails.
480 (list "-f" (user-login-name))
481 ;;; ;; Don't say "from root" if running under su.
482 ;;; (and (equal (user-real-login-name) "root")
483 ;;; (list "-f" (user-login-name)))
485 (list (concat "-oA" mail-alias-file)))
486 ;; These mean "report errors by mail"
487 ;; and "deliver in background".
488 (if (null mail-interactive) '("-oem" "-odb"))
489 ;; Get the addresses from the message
490 ;; unless this is a resend.
491 ;; We must not do that for a resend
492 ;; because we would find the original addresses.
493 ;; For a resend, include the specific addresses.
494 (or resend-to-addresses
499 (goto-char (point-min))
500 (while (re-search-forward "\n\n* *" nil t)
501 (replace-match "; "))
502 (if (not (zerop (buffer-size)))
503 (error "Sending...failed to %s"
504 (buffer-substring (point-min) (point-max)))))))
507 (kill-buffer errbuf)))))
509 (defun mail-do-fcc (header-end)
511 (rmailbuf (current-buffer))
512 (time (current-time))
513 (tembuf (generate-new-buffer " rmail output"))
514 (case-fold-search t))
516 (goto-char (point-min))
517 (while (re-search-forward "^FCC:[ \t]*" header-end t)
518 (setq fcc-list (cons (buffer-substring (point)
521 (skip-chars-backward " \t")
524 (delete-region (match-beginning 0)
525 (progn (forward-line 1) (point))))
528 ;; This initial newline is written out if the fcc file already exists.
529 (insert "\nFrom " (user-login-name) " "
530 (current-time-string time) "\n")
531 ;; Insert the time zone before the year.
534 (require 'mail-utils)
535 (insert (mail-rfc822-time-zone time) " ")
536 (goto-char (point-max))
537 (insert-buffer-substring rmailbuf)
538 ;; Make sure messages are separated.
539 (goto-char (point-max))
542 ;; ``Quote'' "^From " as ">From "
543 ;; (note that this isn't really quoting, as there is no requirement
544 ;; that "^[>]+From " be quoted in the same transparent way.)
545 (let ((case-fold-search nil))
546 (while (search-forward "\nFrom " nil t)
550 (let ((buffer (get-file-buffer (car fcc-list))))
552 ;; File is present in a buffer => append to that buffer.
553 (let ((curbuf (current-buffer))
554 (beg (point-min)) (end (point-max))
555 (beg2 (save-excursion (goto-char (point-min))
556 (forward-line 2) (point))))
559 ;; Keep the end of the accessible portion at the same place
560 ;; unless it is the end of the buffer.
561 (let ((max (if (/= (1+ (buffer-size)) (point-max))
564 ;; Code below lifted from rmailout.el
565 ;; function rmail-output-to-rmail-file:
566 (let ((buffer-read-only nil)
567 (msg (and (boundp 'rmail-current-message)
568 rmail-current-message)))
569 ;; If MSG is non-nil, buffer is in RMAIL mode.
572 (rmail-maybe-set-message-counters)
574 (narrow-to-region (point-max) (point-max))
575 (insert "\C-l\n0, unseen,,\n*** EOOH ***\n"
576 "From: " (user-login-name) "\n"
577 "Date: " (mail-rfc822-date) "\n")
578 (insert-buffer-substring curbuf beg2 end)
580 (goto-char (point-min))
582 (search-backward "\n\^_")
583 (narrow-to-region (point) (point-max))
584 (rmail-count-new-messages t)
585 (rmail-show-message msg)
587 ;; Output file not in rmail mode
588 ;; => just insert at the end.
589 (narrow-to-region (point-min) (1+ (buffer-size)))
590 (goto-char (point-max))
591 (insert-buffer-substring curbuf beg end)))
592 (if max (narrow-to-region (point-min) max))))))
593 ;; Else append to the file directly.
595 (1+ (point-min)) (point-max) (car fcc-list) t)))
596 (setq fcc-list (cdr fcc-list))))
597 (kill-buffer tembuf)))
599 (defun mail-sent-via ()
600 "Make a Sent-via header line from each To or CC header line."
603 (goto-char (point-min))
604 ;; find the header-separator
605 (search-forward (concat "\n" mail-header-separator "\n"))
607 ;; put a marker at the end of the header
608 (let ((end (point-marker))
611 (goto-char (point-min))
612 ;; search for the To: lines and make Sent-via: lines from them
613 ;; search for the next To: line
614 (while (re-search-forward "^\\(to\\|cc\\):" end t)
615 ;; Grab this line plus all its continuations, sans the `to:'.
617 (buffer-substring (point)
619 (if (re-search-forward "^[^ \t\n]" end t)
623 ;; Insert a copy, with altered header field name.
624 (insert-before-markers "Sent-via:" to-line))))))
627 "Move point to end of To-field."
630 (mail-position-on-field "To"))
632 (defun mail-subject ()
633 "Move point to end of Subject-field."
636 (mail-position-on-field "Subject"))
639 "Move point to end of CC-field. Create a CC field if none."
642 (or (mail-position-on-field "cc" t)
643 (progn (mail-position-on-field "to")
647 "Move point to end of BCC-field. Create a BCC field if none."
650 (or (mail-position-on-field "bcc" t)
651 (progn (mail-position-on-field "to")
652 (insert "\nBCC: "))))
654 (defun mail-fcc (folder)
655 "Add a new FCC field, with file name completion."
656 (interactive "FFolder carbon copy: ")
658 (or (mail-position-on-field "fcc" t) ;Put new field after exiting FCC.
659 (mail-position-on-field "to"))
660 (insert "\nFCC: " folder))
662 (defun mail-position-on-field (field &optional soft)
664 (case-fold-search t))
665 (goto-char (point-min))
666 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "\n"))
667 (setq end (match-beginning 0))
668 (goto-char (point-min))
669 (if (re-search-forward (concat "^" (regexp-quote field) ":") end t)
671 (re-search-forward "^[^ \t]" nil 'move)
673 (skip-chars-backward "\n")
676 (progn (goto-char end)
677 (insert field ": \n")
678 (skip-chars-backward "\n")))
682 "Move point to beginning of text field."
684 (goto-char (point-min))
685 (search-forward (concat "\n" mail-header-separator "\n")))
687 (defun mail-signature (atpoint)
688 "Sign letter with contents of the file `~/.signature'.
689 Prefix arg means put contents at point."
693 (goto-char (point-max)))
694 (skip-chars-backward " \t\n")
697 (delete-region (point) (point-max)))
699 (insert-file-contents (expand-file-name "~/.signature"))))
701 (defun mail-fill-yanked-message (&optional justifyp)
702 "Fill the paragraphs of a message yanked into this one.
703 Numeric argument means justify as well."
706 (goto-char (point-min))
707 (search-forward (concat "\n" mail-header-separator "\n") nil t)
708 (fill-individual-paragraphs (point)
713 (defun mail-indent-citation ()
714 "Modify text just inserted from a message to be cited.
715 The inserted text should be the region.
716 When this function returns, the region is again around the modified text.
718 Normally, indent each nonblank line `mail-indentation-spaces' spaces.
719 However, if `mail-yank-prefix' is non-nil, insert that prefix on each line."
720 (let ((start (point)))
721 (mail-yank-clear-headers start (mark t))
722 (if (null mail-yank-prefix)
723 (indent-rigidly start (mark t) mail-indentation-spaces)
726 (while (< (point) (mark t))
727 (insert mail-yank-prefix)
728 (forward-line 1))))))
730 (defun mail-yank-original (arg)
731 "Insert the message being replied to, if any (in rmail).
732 Puts point before the text and mark after.
733 Normally, indents each nonblank line ARG spaces (default 3).
734 However, if `mail-yank-prefix' is non-nil, insert that prefix on each line.
736 Just \\[universal-argument] as argument means don't indent, insert no prefix,
737 and don't delete any header fields."
739 (if mail-reply-buffer
740 (let ((start (point)))
741 ;; If the original message is in another window in the same frame,
742 ;; delete that window to save screen space.
743 ;; t means don't alter other frames.
744 (delete-windows-on mail-reply-buffer t)
745 (insert-buffer mail-reply-buffer)
749 (let ((mail-indentation-spaces (if arg (prefix-numeric-value arg)
750 mail-indentation-spaces)))
751 (if mail-citation-hook
752 (run-hooks 'mail-citation-hook)
754 (run-hooks 'mail-yank-hooks)
755 (mail-indent-citation)))))
756 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
757 ;; It is cleaner to avoid activation, even though the command
758 ;; loop would deactivate the mark because we inserted text.
759 (goto-char (prog1 (mark t)
760 (set-marker (mark-marker) (point) (current-buffer))))
761 (if (not (eolp)) (insert ?\n)))))
763 (defun mail-yank-clear-headers (start end)
766 (if (search-forward "\n\n" end t)
768 (narrow-to-region start (point))
770 (while (let ((case-fold-search t))
771 (re-search-forward mail-yank-ignored-headers nil t))
773 (delete-region (point)
774 (progn (re-search-forward "\n[^ \t]")
778 ;; Put these last, to reduce chance of lossage from quitting in middle of loading the file.
781 (defun mail (&optional noerase to subject in-reply-to cc replybuffer actions)
782 "Edit a message to be sent. Prefix arg means resume editing (don't erase).
783 When this function returns, the buffer `*mail*' is selected.
784 The value is t if the message was newly initialized; otherwise, nil.
786 By default, the signature file `~/.signature' is inserted at the end;
787 see the variable `mail-signature'.
790 While editing message, type \\[mail-send-and-exit] to send the message and exit.
792 Various special commands starting with C-c are available in sendmail mode
793 to move to message header fields:
796 If `mail-self-blind' is non-nil, a BCC to yourself is inserted
797 when the message is initialized.
799 If `mail-default-reply-to' is non-nil, it should be an address (a string);
800 a Reply-to: field with that address is inserted.
802 If `mail-archive-file-name' is non-nil, an FCC field with that file name
805 If `mail-setup-hook' is bound, its value is called with no arguments
806 after the message is initialized. It can add more default fields.
808 When calling from a program, the second through fifth arguments
809 TO, SUBJECT, IN-REPLY-TO and CC specify if non-nil
810 the initial contents of those header fields.
811 These arguments should not have final newlines.
812 The sixth argument REPLYBUFFER is a buffer whose contents
813 should be yanked if the user types C-c C-y.
814 The seventh argument ACTIONS is a list of actions to take
815 if/when the message is sent. Each action looks like (FUNCTION . ARGS);
816 when the message is sent, we apply FUNCTION to ARGS.
817 This is how Rmail arranges to mark messages `answered'."
819 ;;; This is commented out because I found it was confusing in practice.
820 ;;; It is easy enough to rename *mail* by hand with rename-buffer
821 ;;; if you want to have multiple mail buffers.
822 ;;; And then you can control which messages to save. --rms.
825 ;;; ;; If requested, look for a mail buffer that is modified and go to it.
828 ;;; (while (and (setq buffer
829 ;;; (get-buffer (if (= 1 index) "*mail*"
830 ;;; (format "*mail*<%d>" index))))
831 ;;; (not (buffer-modified-p buffer)))
832 ;;; (setq index (1+ index)))
833 ;;; (if buffer (switch-to-buffer buffer)
834 ;;; ;; If none exists, start a new message.
835 ;;; ;; This will never re-use an existing unmodified mail buffer
836 ;;; ;; (since index is not 1 anymore). Perhaps it should.
837 ;;; (setq noerase nil))))
838 ;;; ;; Unless we found a modified message and are happy, start a new message.
839 ;;; (if (not noerase)
841 ;;; ;; Look for existing unmodified mail buffer.
842 ;;; (while (and (setq buffer
843 ;;; (get-buffer (if (= 1 index) "*mail*"
844 ;;; (format "*mail*<%d>" index))))
845 ;;; (buffer-modified-p buffer))
846 ;;; (setq index (1+ index)))
847 ;;; ;; If none, make a new one.
849 ;;; (setq buffer (generate-new-buffer "*mail*")))
850 ;;; ;; Go there and initialize it.
851 ;;; (switch-to-buffer buffer)
853 ;;; (setq default-directory (expand-file-name "~/"))
854 ;;; (auto-save-mode auto-save-default)
856 ;;; (mail-setup to subject in-reply-to cc replybuffer actions)
857 ;;; (if (and buffer-auto-save-file-name
858 ;;; (file-exists-p buffer-auto-save-file-name))
859 ;;; (message "Auto save file for draft message exists; consider M-x mail-recover"))
861 (switch-to-buffer "*mail*")
862 (if (file-exists-p (expand-file-name "~/"))
863 (setq default-directory (expand-file-name "~/")))
864 (auto-save-mode auto-save-default)
866 ;; Disconnect the buffer from its visited file
867 ;; (in case the user has actually visited a file *mail*).
868 ; (set-visited-file-name nil)
871 (or (not (buffer-modified-p))
872 (y-or-n-p "Unsent message being composed; erase it? "))
873 (progn (erase-buffer)
874 (mail-setup to subject in-reply-to cc replybuffer actions)
875 (setq initialized t)))
876 (if (and buffer-auto-save-file-name
877 (file-exists-p buffer-auto-save-file-name))
878 (message "Auto save file for draft message exists; consider M-x mail-recover"))
881 (defun mail-recover ()
882 "Reread contents of current buffer from its last auto-save file."
884 (let ((file-name (make-auto-save-file-name)))
885 (cond ((save-window-excursion
886 (if (not (eq system-type 'vax-vms))
887 (with-output-to-temp-buffer "*Directory*"
888 (buffer-disable-undo standard-output)
889 (call-process "ls" nil standard-output nil "-l" file-name)))
890 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
891 (let ((buffer-read-only nil))
893 (insert-file-contents file-name nil)))
894 (t (error "mail-recover cancelled")))))
897 (defun mail-other-window (&optional noerase to subject in-reply-to cc replybuffer sendactions)
898 "Like `mail' command, but display mail buffer in another window."
900 (let ((pop-up-windows t))
901 (pop-to-buffer "*mail*"))
902 (mail noerase to subject in-reply-to cc replybuffer sendactions))
905 (defun mail-other-frame (&optional noerase to subject in-reply-to cc replybuffer sendactions)
906 "Like `mail' command, but display mail buffer in another frame."
908 (let ((pop-up-frames t))
909 (pop-to-buffer "*mail*"))
910 (mail noerase to subject in-reply-to cc replybuffer sendactions))
912 ;;; Do not execute these when sendmail.el is loaded,
913 ;;; only in loaddefs.el.
914 ;;;###autoload (define-key ctl-x-map "m" 'mail)
915 ;;;###autoload (define-key ctl-x-4-map "m" 'mail-other-window)
916 ;;;###autoload (define-key ctl-x-5-map "m" 'mail-other-frame)
918 ;;; Do not add anything but external entries on this page.
922 ;;; sendmail.el ends here