1 ;;; sendmail.el --- mail sending commands for Emacs -*- lexical-binding:t -*-
3 ;; Copyright (C) 1985-1986, 1992-1996, 1998, 2000-2018 Free Software
6 ;; Maintainer: emacs-devel@gnu.org
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
26 ;; This mode provides mail-sending facilities from within Emacs. It is
27 ;; documented in the Emacs user's manual.
32 (autoload 'message-make-date
"message")
34 (defgroup sendmail nil
35 "Mail sending commands for Emacs."
39 (defcustom mail-setup-with-from t
40 "Non-nil means insert `From:' field when setting up the message."
45 (defcustom sendmail-program
46 (or (executable-find "sendmail")
48 ((file-exists-p "/usr/sbin/sendmail") "/usr/sbin/sendmail")
49 ((file-exists-p "/usr/lib/sendmail") "/usr/lib/sendmail")
50 ((file-exists-p "/usr/ucblib/sendmail") "/usr/ucblib/sendmail")
52 "Program used to send messages."
53 :version
"24.1" ; add executable-find, remove fakemail
58 (defcustom mail-from-style
'angles
59 "Specifies how \"From:\" fields look.
61 If nil, they contain just the return address like:
63 If `parens', they look like:
64 king@grassland.com (Elvis Parsley)
65 If `angles', they look like:
66 Elvis Parsley <king@grassland.com>
68 Otherwise, most addresses look like `angles', but they look like
69 `parens' if `angles' would need quoting and `parens' would not."
70 ;; The value `system-default' is now deprecated.
71 :type
'(choice (const :tag
"simple" nil
)
77 (make-obsolete-variable
79 "only the `angles' value is valid according to RFC2822." "27.1" 'set
)
82 (defcustom mail-specify-envelope-from nil
83 "If non-nil, specify the envelope-from address when sending mail.
84 The value used to specify it is whatever is found in
85 the variable `mail-envelope-from', with `user-mail-address' as fallback.
87 On most systems, specifying the envelope-from address is a
88 privileged operation. This variable affects sendmail and
89 smtpmail -- if you use feedmail to send mail, see instead the
90 variable `feedmail-deduce-envelope-from'."
95 (defcustom mail-envelope-from nil
96 "If non-nil, designate the envelope-from address when sending mail.
97 This only has an effect if `mail-specify-envelope-from' is non-nil.
98 The value should be either a string, or the symbol `header' (in
99 which case the contents of the \"From\" header of the message
100 being sent is used), or nil (in which case the value of
101 `user-mail-address' is used)."
103 :type
'(choice (string :tag
"From-name")
104 (const :tag
"Use From: header from message" header
)
105 (const :tag
"Use `user-mail-address'" nil
))
109 (defcustom mail-self-blind nil
110 "Non-nil means insert Bcc to self in messages to be sent.
111 This is done when the message is initialized,
112 so you can remove or alter the Bcc field to override the default."
117 (defcustom mail-interactive t
118 ;; We used to use a default of nil rather than t, but nowadays it is very
119 ;; common for sendmail to be misconfigured, so one cannot rely on the
120 ;; bounce message to be delivered anywhere, least of all to the
122 "Non-nil means when sending a message wait for and display errors.
123 Otherwise, let mailer send back a message to report errors."
125 :version
"23.1" ; changed from nil to t
128 (defcustom mail-yank-ignored-headers
130 (regexp-opt '("via" "mail-from" "origin" "status" "remailed"
131 "received" "message-id" "summary-line" "to" "subject"
132 "in-reply-to" "return-path" "mail-reply-to"
133 ;; Should really be rmail-attribute-header and
134 ;; rmail-keyword-header, but this file does not
135 ;; require rmail (at run time).
136 "x-rmail-attributes" "x-rmail-keywords"
137 "mail-followup-to") "\\(?:")
139 "Delete these headers from old message when it's inserted in a reply."
144 ;; Useful to set in site-init.el
146 (defcustom send-mail-function
147 ;; Assume smtpmail is the preferred choice if it's already configured.
148 (if (and (boundp 'smtpmail-smtp-server
)
149 smtpmail-smtp-server
)
150 'smtpmail-send-it
'sendmail-query-once
)
151 "Function to call to send the current buffer as mail.
152 The headers should be delimited by a line which is
153 not a valid RFC822 header or continuation line,
154 that matches the variable `mail-header-separator'.
155 This is used by the default mail-sending commands. See also
156 `message-send-mail-function' for use with the Message package."
157 :type
'(radio (function-item sendmail-send-it
:tag
"Use Sendmail package")
158 (function-item sendmail-query-once
:tag
"Query the user")
159 (function-item smtpmail-send-it
:tag
"Use SMTPmail package")
160 (function-item feedmail-send-it
:tag
"Use Feedmail package")
161 (function-item mailclient-send-it
:tag
"Use Mailclient package")
167 (defcustom mail-header-separator
(purecopy "--text follows this line--")
168 "Line used to separate headers from text in messages being composed."
172 ;; Set up mail-header-separator for use as a category text property.
173 (put 'mail-header-separator
'rear-nonsticky
'(category))
174 ;; This was a nice idea, for preventing accidental modification of
175 ;; the separator. But I found it also prevented or obstructed
176 ;; certain deliberate operations, such as copying the separator line
177 ;; up to the top to send myself a copy of an already sent outgoing message
178 ;; and other things. So I turned it off. --rms.
179 ;;(put 'mail-header-separator 'read-only t)
182 (defcustom mail-archive-file-name nil
183 "Name of file to write all outgoing messages in, or nil for none.
184 This is normally an mbox file, but for backwards compatibility may also
186 :type
'(choice file
(const nil
))
190 (defcustom mail-default-reply-to nil
191 "Address to insert as default Reply-To field of outgoing messages.
192 If nil, it will be initialized from the REPLYTO environment variable
193 when you first send mail."
194 :type
'(choice (const nil
) string
)
197 (defcustom mail-alias-file nil
198 "If non-nil, the name of a file to use instead of the sendmail default.
199 This file defines aliases to be expanded by the mailer; this is a different
200 feature from that of defining aliases in `.mailrc' to be expanded in Emacs.
201 This variable has no effect unless your system uses sendmail as its mailer.
202 The default file is defined in sendmail's configuration file, e.g.
204 :type
'(choice (const :tag
"Sendmail default" nil
) file
)
208 (defcustom mail-personal-alias-file
(purecopy "~/.mailrc")
209 "If non-nil, the name of the user's personal mail alias file.
210 This file typically should be in same format as the `.mailrc' file used by
211 the `Mail' or `mailx' program.
212 This file need not actually exist."
213 :type
'(choice (const nil
) file
)
217 (defcustom mail-setup-hook nil
218 "Normal hook, run each time a new outgoing message is initialized."
220 :options
'(fortune-to-signature spook mail-abbrevs-setup
)
224 (defvar mail-aliases t
225 "Alist of mail address aliases,
226 or t meaning should be initialized from your mail aliases file.
227 \(The file's name is normally `~/.mailrc', but `mail-personal-alias-file'
228 can specify a different file name.)
229 The alias definitions in the file have this form:
230 alias ALIAS MEANING")
232 (defvar mail-alias-modtime nil
233 "The modification time of your mail alias file when it was last examined.")
236 (defcustom mail-yank-prefix
"> "
237 "Prefix insert on lines of yanked message being replied to.
238 If this is nil, use indentation, as specified by `mail-indentation-spaces'."
239 :type
'(choice (const nil
) string
)
243 (defcustom mail-indentation-spaces
3
244 "Number of spaces to insert at the beginning of each cited line.
245 Used by `mail-yank-original' via `mail-indent-citation'."
250 (defcustom mail-citation-hook nil
251 "Hook for modifying a citation just inserted in the mail buffer.
252 Each hook function can find the citation between (point) and (mark t),
253 and should leave point and mark around the citation text as modified.
254 The hook functions can find the header of the cited message
255 in the variable `mail-citation-header', whether or not this is included
256 in the cited portion of the message.
258 If this hook is entirely empty (nil), a default action is taken
259 instead of no action."
263 (defvar mail-citation-header nil
264 "While running `mail-citation-hook', this variable holds the message header.
265 This enables the hook functions to see the whole message header
266 regardless of what part of it (if any) is included in the cited text.")
269 (defcustom mail-citation-prefix-regexp
270 (purecopy "\\([ \t]*\\(\\w\\|[_.]\\)+>+\\|[ \t]*[]>|]\\)+")
271 "Regular expression to match a citation prefix plus whitespace.
272 It should match whatever sort of citation prefixes you want to handle,
273 with whitespace before and after; it should also match just whitespace.
274 The default value matches citations like `foo-bar>' plus whitespace."
279 (defvar mail-abbrevs-loaded nil
)
280 (defvar mail-mode-map
281 (let ((map (make-sparse-keymap)))
282 (define-key map
"\M-\t" 'completion-at-point
)
283 (define-key map
"\C-c?" 'describe-mode
)
284 (define-key map
"\C-c\C-f\C-t" 'mail-to
)
285 (define-key map
"\C-c\C-f\C-b" 'mail-bcc
)
286 (define-key map
"\C-c\C-f\C-f" 'mail-fcc
)
287 (define-key map
"\C-c\C-f\C-c" 'mail-cc
)
288 (define-key map
"\C-c\C-f\C-s" 'mail-subject
)
289 (define-key map
"\C-c\C-f\C-r" 'mail-reply-to
)
290 (define-key map
"\C-c\C-f\C-a" 'mail-mail-reply-to
) ; author
291 (define-key map
"\C-c\C-f\C-l" 'mail-mail-followup-to
) ; list
292 (define-key map
"\C-c\C-t" 'mail-text
)
293 (define-key map
"\C-c\C-y" 'mail-yank-original
)
294 (define-key map
"\C-c\C-r" 'mail-yank-region
)
295 (define-key map
[remap split-line
] 'mail-split-line
)
296 (define-key map
"\C-c\C-q" 'mail-fill-yanked-message
)
297 (define-key map
"\C-c\C-w" 'mail-signature
)
298 (define-key map
"\C-c\C-c" 'mail-send-and-exit
)
299 (define-key map
"\C-c\C-s" 'mail-send
)
300 (define-key map
"\C-c\C-i" 'mail-insert-file
)
301 ;; FIXME add this? "b" = bury buffer. It's in the menu-bar.
302 ;;; (define-key map "\C-c\C-b" 'mail-dont-send)
304 (define-key map
[menu-bar mail
]
305 (cons "Mail" (make-sparse-keymap "Mail")))
307 (define-key map
[menu-bar mail attachment
]
308 '("Attach File" . mail-add-attachment
))
310 (define-key map
[menu-bar mail fill
]
311 '("Fill Citation" . mail-fill-yanked-message
))
313 (define-key map
[menu-bar mail yank
]
314 '(menu-item "Cite Original" mail-yank-original
:enable mail-reply-action
))
316 (define-key map
[menu-bar mail signature
]
317 '("Insert Signature" . mail-signature
))
319 (define-key map
[menu-bar mail mail-sep
]
322 (define-key map
[menu-bar mail cancel
]
323 '("Cancel" . mail-dont-send
))
325 (define-key map
[menu-bar mail send-stay
]
326 '("Send, Keep Editing" . mail-send
))
328 (define-key map
[menu-bar mail send
]
329 '("Send Message" . mail-send-and-exit
))
331 (define-key map
[menu-bar headers
]
332 (cons "Headers" (make-sparse-keymap "Move to Header")))
334 (define-key map
[menu-bar headers text
]
335 '("Text" . mail-text
))
337 (define-key map
[menu-bar headers expand-aliases
]
338 '("Expand Aliases" . expand-mail-aliases
))
340 (define-key map
[menu-bar headers mail-reply-to
]
341 '("Mail-Reply-To" . mail-mail-reply-to
))
343 (define-key map
[menu-bar headers mail-followup-to
]
344 '("Mail-Followup-To" . mail-mail-followup-to
))
346 (define-key map
[menu-bar headers reply-to
]
347 '("Reply-To" . mail-reply-to
))
349 (define-key map
[menu-bar headers bcc
]
352 (define-key map
[menu-bar headers fcc
]
355 (define-key map
[menu-bar headers cc
]
358 (define-key map
[menu-bar headers subject
]
359 '("Subject" . mail-subject
))
361 (define-key map
[menu-bar headers to
]
366 (autoload 'build-mail-aliases
"mailalias"
367 "Read mail aliases from personal aliases file and set `mail-aliases'.
368 By default, this is the file specified by `mail-personal-alias-file'." t
)
371 (defcustom mail-signature t
372 "Text inserted at end of mail buffer when a message is initialized.
373 If t, it means to insert the contents of the file `mail-signature-file'.
374 If a string, that string is inserted.
375 (To make a proper signature, the string should begin with \\n\\n-- \\n,
376 which is the standard way to delimit a signature in a message.)
377 Otherwise, it should be an expression; it is evaluated
378 and should insert whatever you want to insert."
379 :type
'(choice (const :tag
"None" nil
)
380 (const :tag
"Use `.signature' file" t
)
381 (string :tag
"String to insert")
382 (sexp :tag
"Expression to evaluate"))
384 (put 'mail-signature
'risky-local-variable t
)
387 (defcustom mail-signature-file
(purecopy "~/.signature")
388 "File containing the text inserted at end of mail buffer."
393 (defcustom mail-default-directory
(purecopy "~/")
394 "Value of `default-directory' for Mail mode buffers.
395 This directory is used for auto-save files of Mail mode buffers.
397 Note that Message mode does not use this variable; it auto-saves
398 in `message-auto-save-directory'."
399 :type
'(directory :tag
"Directory")
403 (defvar mail-reply-action nil
)
404 (defvar mail-send-actions nil
405 "A list of actions to be performed upon successful sending of a message.")
406 (defvar mail-return-action nil
)
409 (defcustom mail-default-headers nil
410 "A string containing header lines, to be inserted in outgoing messages.
411 It can contain newlines, and should end in one. It is inserted
412 before you edit the message, so you can edit or delete the lines."
413 :type
'(choice (const nil
) string
)
416 (defcustom mail-bury-selects-summary t
417 "If non-nil, try to show Rmail summary buffer after returning from mail.
418 The functions \\[mail-send-on-exit] or \\[mail-dont-send] select
419 the Rmail summary buffer before returning, if it exists and this variable
424 (defcustom mail-send-nonascii
'mime
425 "Specify whether to allow sending non-ASCII characters in mail.
426 If t, that means do allow it. nil means don't allow it.
427 `query' means ask the user each time.
428 `mime' means add an appropriate MIME header if none already present.
429 The default is `mime'.
430 Including non-ASCII characters in a mail message can be problematical
431 for the recipient, who may not know how to decode them properly."
432 :type
'(choice (const t
) (const nil
) (const query
) (const mime
))
435 (defcustom mail-use-dsn nil
436 "Ask MTA for notification of failed, delayed or successful delivery.
437 Note that only some MTAs (currently only recent versions of Sendmail)
438 support Delivery Status Notification."
440 :type
'(repeat (radio (const :tag
"Failure" failure
)
441 (const :tag
"Delay" delay
)
442 (const :tag
"Success" success
)))
445 ;; Note: could use /usr/ucb/mail instead of sendmail;
446 ;; options -t, and -v if not interactive.
447 (defvar mail-mailer-swallows-blank-line nil
448 "Set this non-nil if the system's mailer runs the header and body together.
449 The actual value should be an expression to evaluate that returns
450 non-nil if the problem will actually occur.
451 \(As far as we know, this is not an issue on any system still supported
454 (put 'mail-mailer-swallows-blank-line
'risky-local-variable t
) ; gets evalled
455 (make-obsolete-variable 'mail-mailer-swallows-blank-line
456 "no need to set this on any modern system."
459 (defvar mail-mode-syntax-table
460 ;; define-derived-mode will make it inherit from text-mode-syntax-table.
461 (let ((st (make-syntax-table)))
462 ;; FIXME this is probably very obsolete now ("percent hack").
463 ;; sending.texi used to say:
464 ;; Mail mode defines the character `%' as a word separator; this
465 ;; is helpful for using the word commands to edit mail addresses.
466 (modify-syntax-entry ?%
". " st
)
468 "Syntax table used while in `mail-mode'.")
470 (defvar mail-font-lock-keywords
472 (let* ((cite-chars "[>|}]")
473 (cite-prefix "[:alpha:]")
474 (cite-suffix (concat cite-prefix
"0-9_.@-`'\"")))
475 (list '("^\\(To\\|Newsgroups\\):" . font-lock-function-name-face
)
476 '("^\\(B?Cc\\|Reply-To\\|Mail-\\(Reply\\|Followup\\)-To\\):" . font-lock-keyword-face
)
477 '("^\\(Subject:\\)[ \t]*\\(.+\\)?"
478 (1 font-lock-comment-face
)
479 ;; (2 font-lock-type-face nil t)
481 ;; Use EVAL to delay in case `mail-header-separator' gets changed.
483 (let ((separator (if (zerop (length mail-header-separator
))
485 (regexp-quote mail-header-separator
))))
486 (cons (concat "^" separator
"$") 'font-lock-warning-face
)))
487 ;; Use MATCH-ANCHORED to effectively anchor the regexp left side.
489 (,(concat "\\=[ \t]*"
490 "\\(\\(\\([" cite-prefix
"]+[" cite-suffix
"]*\\)?"
491 "\\(" cite-chars
"[ \t]*\\)\\)+\\)"
493 (beginning-of-line) (end-of-line)
494 (1 font-lock-comment-delimiter-face nil t
)
495 (5 font-lock-comment-face nil t
)))
496 '("^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):.*\\(\n[ \t]+.*\\)*$"
497 . font-lock-string-face
))))
498 "Additional expressions to highlight in Mail mode.")
502 (defun sendmail-query-once ()
503 "Query for `send-mail-function' and send mail with it.
504 This also saves the value of `send-mail-function' via Customize."
505 ;; If send-mail-function is already setup, we're incorrectly called
506 ;; a second time, probably because someone's using an old value
507 ;; of send-mail-function.
508 (if (not (eq send-mail-function
'sendmail-query-once
))
509 (funcall send-mail-function
)
510 (let ((function (sendmail-query-user-about-smtp)))
512 (when (y-or-n-p "Save this mail sending choice?")
513 (setq send-mail-function function
)
514 (customize-save-variable 'send-mail-function function
)))))
516 (defun sendmail-query-user-about-smtp ()
517 (let* ((options `(("mail client" . mailclient-send-it
)
518 ,@(when (and sendmail-program
519 (executable-find sendmail-program
))
520 '(("transport" . sendmail-send-it
)))
521 ("smtp" . smtpmail-send-it
)))
525 (rename-buffer "*Emacs Mail Setup Help*" t
)
526 (insert (substitute-command-keys "\
527 Emacs is about to send an email message, but it has not been
528 configured for sending email. To tell Emacs how to send email:
531 (propertize "mail client" 'face
'bold
)
532 (substitute-command-keys "\
533 ' to start your default email client and
534 pass it the message text.\n\n"))
535 (and sendmail-program
536 (executable-find sendmail-program
)
537 (insert (substitute-command-keys "\
539 (propertize "transport" 'face
'bold
)
540 (substitute-command-keys "\
541 ' to invoke the system's mail transport agent
544 (substitute-command-keys "' program).\n\n")))
545 (insert (substitute-command-keys "\
547 (propertize "smtp" 'face
'bold
)
548 (substitute-command-keys "' to send mail directly to an \"outgoing mail\" server.
549 (Emacs may prompt you for SMTP settings).
551 Emacs will record your selection and will use it thereafter.
552 To change it later, customize the option `send-mail-function'.\n"))
553 (goto-char (point-min))
554 (display-buffer (current-buffer))
555 (let ((completion-ignore-case t
))
557 (format "Send mail via (default %s): " (caar options
))
558 options nil
'require-match nil nil
(car options
))))))
559 ;; Return the choice.
560 (cdr (assoc-string choice options t
))))
562 (defun sendmail-sync-aliases ()
563 (when mail-personal-alias-file
564 (let ((modtime (file-attribute-modification-time
565 (file-attributes mail-personal-alias-file
))))
566 (or (equal mail-alias-modtime modtime
)
567 (setq mail-alias-modtime modtime
572 (define-mail-user-agent 'sendmail-user-agent
573 'sendmail-user-agent-compose
577 (defun sendmail-user-agent-compose (&optional to subject other-headers
578 continue switch-function yank-action
579 send-actions return-action
582 (funcall switch-function
"*mail*"))
583 (let ((cc (cdr (assoc-string "cc" other-headers t
)))
584 (in-reply-to (cdr (assoc-string "in-reply-to" other-headers t
)))
585 (body (cdr (assoc-string "body" other-headers t
))))
586 (or (mail continue to subject in-reply-to cc yank-action
587 send-actions return-action
)
589 (error "Message aborted"))
593 (unless (member-ignore-case (car (car other-headers
))
594 '("in-reply-to" "cc" "body"))
595 (insert (car (car other-headers
)) ": "
596 (cdr (car other-headers
))
597 (if use-hard-newlines hard-newline
"\n")))
598 (setq other-headers
(cdr other-headers
)))
604 (defun mail-setup (to subject in-reply-to cc replybuffer
605 actions return-action
)
606 (or mail-default-reply-to
607 (setq mail-default-reply-to
(getenv "REPLYTO")))
608 (sendmail-sync-aliases)
609 (when (eq mail-aliases t
)
610 (setq mail-aliases nil
)
611 (and mail-personal-alias-file
612 (file-exists-p mail-personal-alias-file
)
613 (build-mail-aliases)))
614 ;; Don't leave this around from a previous message.
615 (kill-local-variable 'buffer-file-coding-system
)
616 ;; This doesn't work for enable-multibyte-characters.
617 ;; (kill-local-variable 'enable-multibyte-characters)
618 (set-buffer-multibyte t
)
619 (if current-input-method
620 (deactivate-input-method))
622 ;; Local variables for Mail mode.
623 (setq mail-send-actions actions
)
624 (setq mail-reply-action replybuffer
)
625 (setq mail-return-action return-action
)
627 (goto-char (point-min))
628 (if mail-setup-with-from
629 (mail-insert-from-field))
633 ;; Here removed code to extract names from within <...>
634 ;; on the assumption that mail-strip-quoted-names
635 ;; has been called and has done so.
636 (let ((fill-prefix "\t")
637 (address-start (point)))
639 (fill-region-as-paragraph address-start
(point-max))
640 (goto-char (point-max))
645 (let ((fill-prefix "\t")
646 (address-start (progn (insert "Cc: ") (point))))
648 (fill-region-as-paragraph address-start
(point-max))
649 (goto-char (point-max))
653 (let ((fill-prefix "\t")
655 (address-start (point)))
656 (insert "In-Reply-To: " in-reply-to
"\n")
657 (fill-region-as-paragraph address-start
(point-max))
658 (goto-char (point-max))
661 (insert "Subject: " (or subject
"") "\n")
662 (if mail-default-headers
663 (insert mail-default-headers
))
664 (if mail-default-reply-to
665 (insert "Reply-To: " mail-default-reply-to
"\n"))
667 (insert "Bcc: " user-mail-address
"\n"))
668 (if mail-archive-file-name
669 (insert "Fcc: " mail-archive-file-name
"\n"))
670 (put-text-property (point)
672 (insert mail-header-separator
"\n")
674 'category
'mail-header-separator
)
675 ;; Insert the signature. But remember the beginning of the message.
676 (if to
(setq to
(point)))
677 (if mail-signature
(mail-signature t
))
678 (goto-char (point-max))
679 (or (bolp) (newline)))
680 (if to
(goto-char to
))
681 (or to subject in-reply-to
682 (set-buffer-modified-p nil
))
683 (run-hooks 'mail-setup-hook
))
685 (defcustom mail-mode-hook nil
686 "Hook run by Mail mode.
687 When composing a mail, this runs immediately after creating, or
688 switching to, the `*mail*' buffer. See also `mail-setup-hook'."
691 :options
'(footnote-mode))
693 (defvar mail-mode-abbrev-table text-mode-abbrev-table
)
694 (defvar mail-encode-mml
)
696 (define-derived-mode mail-mode text-mode
"Mail"
697 "Major mode for editing mail to be sent.
698 Like Text Mode but with these additional commands:
700 \\[mail-send] mail-send (send the message)
701 \\[mail-send-and-exit] mail-send-and-exit (send the message and exit)
703 Here are commands that move to a header field (and create it if there isn't):
704 \\[mail-to] move to To: \\[mail-subject] move to Subj:
705 \\[mail-bcc] move to Bcc: \\[mail-cc] move to Cc:
706 \\[mail-fcc] move to Fcc: \\[mail-reply-to] move to Reply-To:
707 \\[mail-mail-reply-to] move to Mail-Reply-To:
708 \\[mail-mail-followup-to] move to Mail-Followup-To:
709 \\[mail-text] move to message text.
710 \\[mail-signature] mail-signature (insert `mail-signature-file' file).
711 \\[mail-yank-original] mail-yank-original (insert current message, in Rmail).
712 \\[mail-fill-yanked-message] mail-fill-yanked-message (fill what was yanked).
713 \\[mail-insert-file] insert a text file into the message.
714 \\[mail-add-attachment] attach to the message a file as binary attachment.
715 Turning on Mail mode runs the normal hooks `text-mode-hook' and
716 `mail-mode-hook' (in that order)."
717 (make-local-variable 'mail-reply-action
)
718 (make-local-variable 'mail-send-actions
)
719 (make-local-variable 'mail-return-action
)
720 (make-local-variable 'mail-encode-mml
)
721 (setq mail-encode-mml nil
)
722 (setq buffer-offer-save t
)
723 (make-local-variable 'font-lock-defaults
)
724 (setq font-lock-defaults
'(mail-font-lock-keywords t t
))
725 (make-local-variable 'paragraph-separate
)
726 (make-local-variable 'normal-auto-fill-function
)
727 (setq normal-auto-fill-function
'mail-mode-auto-fill
)
728 (make-local-variable 'fill-paragraph-function
)
729 (setq fill-paragraph-function
'mail-mode-fill-paragraph
)
730 ;; Allow using comment commands to add/remove quoting (this only does
731 ;; anything if mail-yank-prefix is set to a non-nil value).
732 (set (make-local-variable 'comment-start
) mail-yank-prefix
)
734 (set (make-local-variable 'comment-start-skip
)
735 (concat "^" (regexp-quote mail-yank-prefix
) "[ \t]*")))
736 (make-local-variable 'adaptive-fill-regexp
)
737 ;; Also update the paragraph-separate entry if you change this.
738 (setq adaptive-fill-regexp
739 (concat "[ \t]*[-[:alnum:]]+>+[ \t]*\\|"
740 adaptive-fill-regexp
))
741 (make-local-variable 'adaptive-fill-first-line-regexp
)
742 (setq adaptive-fill-first-line-regexp
743 (concat "[ \t]*[-[:alnum:]]*>+[ \t]*\\|"
744 adaptive-fill-first-line-regexp
))
745 (add-hook 'completion-at-point-functions
#'mail-completion-at-point-function
747 ;; `-- ' precedes the signature. `-----' appears at the start of the
748 ;; lines that delimit forwarded messages.
749 ;; Lines containing just >= 3 dashes, perhaps after whitespace,
750 ;; are also sometimes used and should be separators.
751 (setq paragraph-separate
752 (concat (regexp-quote mail-header-separator
)
753 ;; This is based on adaptive-fill-regexp (presumably
754 ;; the idea is to allow navigation etc of cited paragraphs).
755 "$\\|\t*[-–!|#%;>*·•‣⁃◦ ]+$"
756 "\\|[ \t]*[-[:alnum:]]*>+[ \t]*$\\|[ \t]*$\\|"
761 (defun mail-header-end ()
762 "Return the buffer location of the end of headers, as a number."
769 (defun mail-text-start ()
770 "Return the buffer location of the start of text, as a number."
778 (defun mail-sendmail-delimit-header ()
779 "Set up whatever header delimiter convention sendmail will use.
780 Concretely: replace the first blank line in the header with the separator."
782 (insert mail-header-separator
)
785 (defun mail-sendmail-undelimit-header ()
786 "Remove header separator to put the message in correct form for sendmail.
787 Leave point at the start of the delimiter line."
788 (goto-char (point-min))
789 (when (re-search-forward
790 (concat "^" (regexp-quote mail-header-separator
) "\n")
792 (replace-match "\n"))
795 (defun mail-mode-auto-fill ()
796 "Carry out Auto Fill for Mail mode.
797 If within the headers, this makes the new lines into continuation lines."
798 (if (< (point) (mail-header-end))
799 (let ((old-line-start (line-beginning-position)))
803 (while (not (eq (point) old-line-start
))
804 ;; Use insert-before-markers in case we're inserting
805 ;; before the saved value of point (which is common).
806 (insert-before-markers " ")
811 (defun mail-mode-fill-paragraph (arg)
812 ;; Do something special only if within the headers.
813 (if (< (point) (mail-header-end))
814 (let (beg end fieldname
)
815 (when (prog1 (re-search-backward "^[-a-zA-Z]+:" nil
'yes
)
818 (downcase (buffer-substring beg
(1- (match-end 0))))))
820 ;; Find continuation lines and get rid of their continuation markers.
821 (while (looking-at "[ \t]")
822 (delete-horizontal-space)
824 (setq end
(point-marker))
826 ;; If this field contains addresses,
827 ;; make sure we can fill after each address.
828 (if (member fieldname
829 '("to" "cc" "bcc" "from" "reply-to"
830 "mail-reply-to" "mail-followup-to"
831 "resent-to" "resent-cc" "resent-bcc"
832 "resent-from" "resent-reply-to"))
833 (while (search-forward "," end t
)
834 (or (looking-at "[ \t]")
836 (fill-region-as-paragraph beg end arg
)
837 ;; Mark all lines except the first as continuations.
840 (while (< (point) end
)
843 (move-marker end nil
)
846 ;; User-level commands for sending.
848 (defun mail-send-and-exit (&optional arg
)
849 "Send message like `mail-send', then, if no errors, exit from mail buffer.
850 Prefix arg means don't delete this window."
855 (defun mail-dont-send (&optional arg
)
856 "Don't send the message you have been editing.
857 Prefix arg means don't delete this window."
861 (defun mail-bury (&optional arg
)
862 "Bury this mail buffer."
863 (let ((newbuf (other-buffer (current-buffer)))
864 (return-action mail-return-action
))
865 (bury-buffer (current-buffer))
866 ;; If there is an Rmail buffer, return to it nicely
867 ;; even if this message was not started by an Rmail command.
868 (unless return-action
869 (dolist (buffer (buffer-list))
870 (if (and (eq (buffer-local-value 'major-mode buffer
) 'rmail-mode
)
872 ;; Don't match message-viewer buffer.
873 (not (string-match "\\` " (buffer-name buffer
))))
874 (setq return-action
`(rmail-mail-return ,buffer
)))))
875 (if (and (null arg
) return-action
)
876 (apply (car return-action
) (cdr return-action
))
877 (switch-to-buffer newbuf
))))
879 (defcustom mail-send-hook nil
880 "Hook run just before sending a message."
882 :options
'(flyspell-mode-off)
886 (defcustom mail-mailing-lists nil
887 "List of mailing list addresses the user is subscribed to.
888 The variable is used to trigger insertion of the \"Mail-Followup-To\"
889 header when sending a message to a mailing list."
890 :type
'(repeat string
)
893 (declare-function mml-to-mime
"mml" ())
896 "Send the message in the current buffer.
897 If `mail-interactive' is non-nil, wait for success indication
898 or error messages, and inform user.
899 Otherwise any failure is reported in a message back to
900 the user from the mailer."
902 (if (if buffer-file-name
903 (y-or-n-p "Send buffer contents as mail message? ")
904 (or (buffer-modified-p)
905 (y-or-n-p "Message already sent; resend? ")))
906 (let ((inhibit-read-only t
)
908 (ml (when mail-mailing-lists
909 ;; The surrounding regexp assumes the use of
910 ;; `mail-strip-quoted-names' on addresses before matching
911 ;; Cannot deal with full RFC 822 freedom, but that is
912 ;; unlikely to be problematic.
913 (concat "\\(?:[[:space:];,]\\|\\`\\)"
914 (regexp-opt mail-mailing-lists t
)
915 "\\(?:[[:space:];,]\\|\\'\\)"))))
916 (mail-combine-fields "To")
917 (mail-combine-fields "Cc")
918 ;; If there are mailing lists defined
921 (let* ((to (mail-fetch-field "to" nil t
))
922 (cc (mail-fetch-field "cc" nil t
))
923 (new-header-values ; To: and Cc:
924 (mail-strip-quoted-names
925 (concat to
(when cc
(concat ", " cc
))))))
926 ;; If message goes to known mailing list ...
927 (when (string-match ml new-header-values
)
928 ;; Add Mail-Followup-To if none yet
929 (unless (mail-fetch-field "mail-followup-to")
930 (goto-char (mail-header-end))
931 (insert "Mail-Followup-To: "
938 (split-string new-header-values
940 (mapconcat 'identity l
", "))
942 ;; Add Mail-Reply-To if none yet
943 (unless (mail-fetch-field "mail-reply-to")
944 (goto-char (mail-header-end))
945 (insert "Mail-Reply-To: "
946 (or (mail-fetch-field "reply-to")
949 (unless (memq mail-send-nonascii
'(t mime
))
950 (goto-char (point-min))
951 (skip-chars-forward "\0-\177")
952 (or (= (point) (point-max))
953 (if (eq mail-send-nonascii
'query
)
954 (or (y-or-n-p "Message contains non-ASCII characters; send anyway? ")
956 (error "Message contains non-ASCII characters"))))
957 ;; Complain about any invalid line.
958 (goto-char (point-min))
959 (re-search-forward (regexp-quote mail-header-separator
) (point-max) t
)
960 (let ((header-end (or (match-beginning 0) (point-max))))
961 (goto-char (point-min))
962 (while (< (point) header-end
)
963 (unless (looking-at "[ \t]\\|.*:\\|$")
965 (error "Invalid header line (maybe a continuation line lacks initial whitespace)"))
968 (when mail-encode-mml
970 (setq mail-encode-mml nil
))
971 (run-hooks 'mail-send-hook
)
972 (message "Sending...")
973 (funcall send-mail-function
)
974 ;; Now perform actions on successful sending.
975 (while mail-send-actions
977 (apply (car (car mail-send-actions
))
978 (cdr (car mail-send-actions
)))
980 (setq mail-send-actions
(cdr mail-send-actions
)))
981 (message "Sending...done")
982 ;; If buffer has no file, mark it as unmodified and delete auto-save.
983 (if (not buffer-file-name
)
985 (set-buffer-modified-p nil
)
986 (delete-auto-save-file-if-necessary t
))))))
988 (defun mail-envelope-from ()
989 "Return the envelope mail address to use when sending mail.
990 This function uses `mail-envelope-from'."
991 (if (eq mail-envelope-from
'header
)
992 (nth 1 (mail-extract-address-components
993 (mail-fetch-field "From")))
996 ;; This does the real work of sending a message via sendmail.
997 ;; It is called via the variable send-mail-function.
1000 (defvar sendmail-coding-system nil
1001 "Coding system for encoding the outgoing mail.
1002 This has higher priority than the default `buffer-file-coding-system'
1003 and `default-sendmail-coding-system',
1004 but lower priority than the local value of `buffer-file-coding-system'.
1005 See also the function `select-message-coding-system'.")
1008 (defvar default-sendmail-coding-system
'iso-latin-1
1009 "Default coding system for encoding the outgoing mail.
1010 This variable is used only when `sendmail-coding-system' is nil.
1012 This variable is set/changed by the command `set-language-environment'.
1013 User should not set this variable manually,
1014 instead use `sendmail-coding-system' to get a constant encoding
1015 of outgoing mails regardless of the current language environment.
1016 See also the function `select-message-coding-system'.")
1018 (defun mail-insert-from-field ()
1019 "Insert the \"From:\" field of a mail header.
1020 The style of the field is determined by the variable `mail-from-style'.
1021 This function does not perform RFC2047 encoding."
1022 (let* ((login user-mail-address
)
1023 (fullname (user-full-name))
1024 (quote-fullname nil
))
1025 (if (string-match "[^\0-\177]" fullname
)
1026 (setq quote-fullname t
))
1027 (cond ((null mail-from-style
)
1028 (insert "From: " login
"\n"))
1029 ;; This is deprecated.
1030 ((eq mail-from-style
'system-default
)
1032 ((or (eq mail-from-style
'angles
)
1033 (and (not (eq mail-from-style
'parens
))
1034 ;; Use angles if no quoting is needed, or if
1035 ;; parens would need quoting too.
1036 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname
))
1037 (let ((tmp (concat fullname nil
)))
1038 (while (string-match "([^()]*)" tmp
)
1039 (aset tmp
(match-beginning 0) ?-
)
1040 (aset tmp
(1- (match-end 0)) ?-
))
1041 (string-match "[\\()]" tmp
)))))
1042 (insert "From: " fullname
)
1043 (let ((fullname-start (+ (point-min) 6))
1044 (fullname-end (point-marker)))
1045 (goto-char fullname-start
)
1046 ;; Look for a character that cannot appear unquoted
1047 ;; according to RFC 822.
1048 (if (or (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]"
1052 ;; Quote fullname, escaping specials.
1053 (goto-char fullname-start
)
1055 (while (re-search-forward "[\"\\]"
1057 (replace-match "\\\\\\&" t
))
1059 (insert " <" login
">\n"))
1060 ;; 'parens or default
1062 (insert "From: " login
" (")
1063 (let ((fullname-start (point)))
1069 (let ((fullname-end (point-marker)))
1070 (goto-char fullname-start
)
1071 ;; RFC 822 says \ and nonmatching parentheses
1072 ;; must be escaped in comments.
1073 ;; Escape every instance of ()\ ...
1074 (while (re-search-forward "[()\\]" fullname-end
1)
1075 (replace-match "\\\\\\&" t
))
1076 ;; ... then undo escaping of matching parentheses,
1077 ;; including matching nested parentheses.
1078 (goto-char fullname-start
)
1079 (while (re-search-forward
1080 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
1082 (replace-match "\\1(\\3)" t
)
1083 (goto-char fullname-start
))))
1086 (defun mail-combine-fields (field)
1087 "Offer to combine all FIELD fields in buffer into one FIELD field.
1088 If this finds multiple FIELD fields, it asks the user whether
1089 to combine them into one, and does so if the user says y."
1090 (let ((search-pattern (format "^%s[ \t]*:" field
))
1095 (old-max (point-max)))
1098 (goto-char (point-min))
1099 (narrow-to-region (point-min) (mail-header-end))
1100 ;; Find the first FIELD field and record where it ends.
1101 (when (re-search-forward search-pattern nil t
)
1103 (re-search-forward "^[^ \t]" nil t
)
1105 (setq first-to-end
(point-marker))
1106 (set-marker-insertion-type first-to-end t
)
1107 ;; Find each following FIELD field
1108 ;; and combine it with the first FIELD field.
1109 (while (re-search-forward search-pattern nil t
)
1110 ;; For the second FIELD field, ask user to
1111 ;; approve combining them.
1112 ;; But if the user refuse to combine them, signal error.
1115 ;; This is just so the screen doesn't change.
1116 (narrow-to-region (point-min) old-max
)
1118 (goto-char old-point
)
1119 (setq query-asked t
)
1120 (if (y-or-n-p (format "Message contains multiple %s fields. Combine? " field
))
1121 (setq query-answer t
)))))
1123 (let ((this-to-start (line-beginning-position))
1127 (re-search-forward "^[^ \t]" nil t
)
1129 (setq this-to-end
(point))
1130 ;; Get the text of this FIELD field.
1131 (setq this-to
(buffer-substring this-to-start this-to-end
))
1133 (delete-region this-to-start this-to-end
)
1135 ;; Put a comma after the first FIELD field.
1136 (goto-char first-to-end
)
1139 ;; Copy this one after it.
1140 (goto-char first-to-end
)
1143 ;; Replace the FIELD: with spaces.
1144 (looking-at search-pattern
)
1145 ;; Try to preserve alignment of contents of the field
1146 (let ((prefix-length (length (match-string 0))))
1148 (dotimes (_ (1- prefix-length
))
1150 (set-marker first-to-end nil
))))))
1152 (defun mail-encode-header (beg end
)
1153 "Encode the mail header between BEG and END according to RFC2047.
1154 Return non-nil if and only if some part of the header is encoded."
1156 (narrow-to-region beg end
)
1157 (let* ((selected (select-message-coding-system))
1158 (mm-coding-system-priorities
1159 (if (and selected
(coding-system-get selected
:mime-charset
))
1160 (cons selected mm-coding-system-priorities
)
1161 mm-coding-system-priorities
))
1162 (tick (buffer-chars-modified-tick))
1163 ;; Many mailers, including Gnus, passes a message of which
1164 ;; the header is already encoded, so this is necessary to
1165 ;; prevent it from being encoded again.
1166 (rfc2047-encode-encoded-words nil
))
1167 (rfc2047-encode-message-header)
1168 (= tick
(buffer-chars-modified-tick)))))
1170 ;; Normally you will not need to modify these options unless you are
1171 ;; using some non-genuine substitute for sendmail which does not
1172 ;; implement each and every option that the original supports.
1173 ;; E.g., ssmtp does not support "-odb", so, if your site uses it,
1174 ;; you will need to modify `sendmail-error-reporting-non-interactive'
1175 ;; in your site-init.el.
1176 (defvar sendmail-error-reporting-interactive
1177 ;; These mean "report errors to terminal" and "deliver interactively"
1179 (defvar sendmail-error-reporting-non-interactive
1180 ;; These mean "report errors by mail" and "deliver in background".
1183 (defun sendmail-send-it ()
1184 "Send the current mail buffer using the Sendmail package.
1185 This is a suitable value for `send-mail-function'. It sends using the
1186 external program defined by `sendmail-program'."
1187 (require 'mail-utils
)
1188 (let ((errbuf (if mail-interactive
1189 (generate-new-buffer " sendmail errors")
1192 (tembuf (generate-new-buffer " sendmail temp"))
1193 (multibyte enable-multibyte-characters
)
1194 (case-fold-search nil
)
1195 (selected-coding (select-message-coding-system))
1199 (mailbuf (current-buffer))
1200 ;; Examine these variables now, so that
1201 ;; local binding in the mail buffer will take effect.
1203 (and mail-specify-envelope-from
1204 (or (mail-envelope-from) user-mail-address
))))
1206 (with-current-buffer tembuf
1209 (set-buffer-multibyte nil
))
1210 (insert-buffer-substring mailbuf
)
1211 (set-buffer-file-coding-system selected-coding
)
1212 (goto-char (point-max))
1213 ;; require one newline at the end.
1214 (or (= (preceding-char) ?
\n)
1216 ;; Change header-delimiter to be what sendmail expects.
1217 (goto-char (mail-header-end))
1218 (delete-region (point) (progn (end-of-line) (point)))
1219 (setq delimline
(point-marker))
1220 (sendmail-sync-aliases)
1222 (expand-mail-aliases (point-min) delimline
))
1223 (goto-char (point-min))
1224 ;; Ignore any blank lines in the header
1225 (while (and (re-search-forward "\n\n\n*" delimline t
)
1226 (< (point) delimline
))
1227 (replace-match "\n"))
1228 (goto-char (point-min))
1229 ;; Look for Resent- headers. They require sending
1230 ;; the message specially.
1231 (let ((case-fold-search t
))
1232 (goto-char (point-min))
1233 (while (re-search-forward "^Resent-\\(To\\|Cc\\|Bcc\\):" delimline t
)
1234 ;; Put a list of such addresses in resend-to-addresses.
1235 (setq resend-to-addresses
1237 (narrow-to-region (point)
1240 (while (looking-at "^[ \t]")
1243 (append (mail-parse-comma-list)
1244 resend-to-addresses
)))
1245 ;; Delete Resent-Bcc ourselves
1246 (if (save-excursion (beginning-of-line)
1247 (looking-at "resent-bcc"))
1248 (delete-region (line-beginning-position)
1249 (line-beginning-position 2))))
1250 ;; Apparently this causes a duplicate Sender.
1251 ;; ;; If the From is different than current user, insert Sender.
1252 ;; (goto-char (point-min))
1253 ;; (and (re-search-forward "^From:" delimline t)
1255 ;; (require 'mail-utils)
1256 ;; (not (string-equal
1257 ;; (mail-strip-quoted-names
1258 ;; (save-restriction
1259 ;; (narrow-to-region (point-min) delimline)
1260 ;; (mail-fetch-field "From")))
1261 ;; (user-login-name))))
1264 ;; (insert "Sender: " (user-login-name) "\n")))
1265 ;; Don't send out a blank subject line
1266 (goto-char (point-min))
1267 (if (re-search-forward "^Subject:\\([ \t]*\n\\)+\\b" delimline t
)
1269 ;; This one matches a Subject just before the header delimiter.
1270 (if (and (re-search-forward "^Subject:\\([ \t]*\n\\)+" delimline t
)
1271 (= (match-end 0) delimline
))
1272 (replace-match "")))
1273 ;; Put the "From:" field in unless for some odd reason
1274 ;; they put one in themselves.
1275 (goto-char (point-min))
1276 (if (not (re-search-forward "^From:" delimline t
))
1277 (mail-insert-from-field))
1278 ;; Possibly add a MIME header for the current coding system
1279 (let (charset where-content-type
)
1280 (goto-char (point-min))
1281 (setq where-content-type
1282 (re-search-forward "^Content-type:" delimline t
))
1283 (goto-char (point-min))
1284 (and (eq mail-send-nonascii
'mime
)
1285 (not (re-search-forward "^MIME-version:" delimline t
))
1286 (progn (skip-chars-forward "\0-\177")
1287 (/= (point) (point-max)))
1290 (coding-system-get selected-coding
:mime-charset
))
1292 (goto-char delimline
)
1293 (insert "MIME-version: 1.0\n"
1294 "Content-type: text/plain; charset="
1295 (symbol-name charset
)
1296 "\nContent-Transfer-Encoding: 8bit\n")
1297 ;; The character set we will actually use
1298 ;; should override any specified in the message itself.
1299 (when where-content-type
1300 (goto-char where-content-type
)
1301 (delete-region (point-at-bol)
1302 (progn (forward-line 1) (point)))))))
1303 ;; Insert an extra newline if we need it to work around
1304 ;; Sun's bug that swallows newlines.
1305 (goto-char (1+ delimline
))
1306 (if (eval mail-mailer-swallows-blank-line
)
1308 ;; Find and handle any Fcc fields.
1309 (goto-char (point-min))
1310 (if (re-search-forward "^Fcc:" delimline t
)
1312 (setq fcc-was-found t
)
1313 (mail-do-fcc delimline
)))
1314 (if mail-interactive
1315 (with-current-buffer errbuf
1317 ;; Encode the header according to RFC2047.
1318 (mail-encode-header (point-min) delimline
)
1319 (goto-char (point-min))
1320 (if (let ((case-fold-search t
))
1321 (or resend-to-addresses
1322 (re-search-forward "^To:\\|^cc:\\|^bcc:"
1324 (let* ((default-directory "/")
1325 (coding-system-for-write selected-coding
)
1327 (append (list (point-min) (point-max)
1329 nil errbuf nil
"-oi")
1331 (list "-f" envelope-from
))
1332 ;; ;; Don't say "from root" if running under su.
1333 ;; (and (equal (user-real-login-name) "root")
1334 ;; (list "-f" (user-login-name)))
1335 (and mail-alias-file
1336 (list (concat "-oA" mail-alias-file
)))
1337 (if mail-interactive
1338 sendmail-error-reporting-interactive
1339 sendmail-error-reporting-non-interactive
)
1340 ;; Get the addresses from the message
1341 ;; unless this is a resend.
1342 ;; We must not do that for a resend
1343 ;; because we would find the original addresses.
1344 ;; For a resend, include the specific addresses.
1345 (or resend-to-addresses
1349 (list "-N" (mapconcat 'symbol-name
1353 (exit-value (apply 'call-process-region args
)))
1354 (cond ((or (null exit-value
) (eq 0 exit-value
)))
1355 ((numberp exit-value
)
1357 (error "Sending...failed with exit value %d" exit-value
))
1358 ((stringp exit-value
)
1360 (error "Sending...terminated by signal: %s" exit-value
))
1363 (error "SENDMAIL-SEND-IT -- fall through: %S" exit-value
))))
1365 (error "No recipients")))
1366 (if mail-interactive
1367 (with-current-buffer errbuf
1368 (goto-char (point-min))
1369 (while (re-search-forward "\n\n* *" nil t
)
1370 (replace-match "; "))
1371 (unless (zerop (buffer-size))
1373 (error "Sending...failed to %s"
1374 (buffer-substring (point-min) (point-max)))))))
1375 (kill-buffer tembuf
)
1376 (when (buffer-live-p errbuf
)
1378 (switch-to-buffer-other-window errbuf
)
1379 (kill-buffer errbuf
))))))
1381 (autoload 'rmail-output-to-rmail-buffer
"rmailout")
1383 (defun mail-do-fcc (header-end)
1384 "Find and act on any Fcc: headers in the current message before HEADER-END.
1385 If a buffer is visiting the Fcc file, append to it before
1386 offering to save it, if it was modified initially. If this is an
1387 Rmail buffer, update Rmail as needed. If there is no buffer,
1388 just append to the file, in Babyl format if necessary."
1389 (unless (markerp header-end
)
1390 (error "Value of `header-end' must be a marker"))
1392 (mailbuf (current-buffer))
1393 (time (current-time)))
1395 (goto-char (point-min))
1396 (let ((case-fold-search t
))
1397 (while (re-search-forward "^Fcc:[ \t]*" header-end t
)
1398 (push (buffer-substring (point)
1401 (skip-chars-backward " \t")
1404 (delete-region (match-beginning 0)
1405 (progn (forward-line 1) (point)))))
1407 ;; This initial newline is not written out if we create a new
1408 ;; file (see below).
1409 (insert "\nFrom " (user-login-name) " " (current-time-string time
) "\n")
1410 ;; Insert the time zone before the year.
1412 (forward-word-strictly -
1)
1413 (require 'mail-utils
)
1414 (insert (mail-rfc822-time-zone time
) " ")
1415 (goto-char (point-max))
1416 (insert "Date: " (message-make-date) "\n")
1417 (insert-buffer-substring mailbuf
)
1418 ;; Make sure messages are separated.
1419 (goto-char (point-max))
1422 ;; ``Quote'' "^From " as ">From "
1423 ;; (note that this isn't really quoting, as there is no requirement
1424 ;; that "^[>]+From " be quoted in the same transparent way.)
1425 (let ((case-fold-search nil
))
1426 (while (search-forward "\nFrom " nil t
)
1429 (dolist (fcc fcc-list
)
1430 (let* ((buffer (find-buffer-visiting fcc
))
1431 (curbuf (current-buffer))
1434 (beg (point-min)) ; the initial blank line
1436 ;; After the ^From line.
1437 (beg2 (save-excursion (goto-char (point-min))
1438 (forward-line 2) (point))))
1440 ;; File is present in a buffer => append to that buffer.
1441 (with-current-buffer buffer
1442 (setq buffer-matches-file
1443 (and (not (buffer-modified-p))
1444 (verify-visited-file-modtime buffer
)))
1445 (let ((msg (bound-and-true-p rmail-current-message
))
1446 (buffer-read-only nil
))
1447 ;; If MSG is non-nil, buffer is in Rmail mode.
1449 (let ((buff (generate-new-buffer " *mail-do-fcc")))
1452 (with-current-buffer buff
1453 (insert-buffer-substring curbuf
(1+ beg
) end
))
1454 (rmail-output-to-rmail-buffer buff msg
))
1455 (kill-buffer buff
)))
1456 ;; Output file not in Rmail mode => just insert
1460 (goto-char (point-max))
1461 (insert-buffer-substring curbuf beg end
)))
1462 ;; Offer to save the buffer if it was modified
1463 ;; before we started.
1464 (unless buffer-matches-file
1465 (if (y-or-n-p (format "Save file %s? " fcc
))
1467 (setq dont-write-the-file t
)))))
1468 ;; Append to the file directly, unless we've already taken
1470 (unless dont-write-the-file
1471 (if (and (file-exists-p fcc
)
1472 (mail-file-babyl-p fcc
))
1473 ;; If the file is a Babyl file, convert the message to
1474 ;; Babyl format. Even though Rmail no longer uses
1475 ;; Babyl, this code can remain for the time being, on
1476 ;; the off-chance one Fccs to a Babyl file that has
1477 ;; not yet been converted to mbox.
1478 (let ((coding-system-for-write
1479 (or rmail-file-coding-system
'emacs-mule
)))
1481 (insert "\C-l\n0, unseen,,\n*** EOOH ***\nDate: "
1482 (mail-rfc822-date) "\n")
1483 (insert-buffer-substring curbuf beg2 end
)
1485 (write-region (point-min) (point-max) fcc t
)))
1486 ;; Ensure there is a blank line between messages, but
1487 ;; not at the very start of the file.
1488 (write-region (if (file-exists-p fcc
)
1491 (point-max) fcc t
)))
1492 (and buffer
(not dont-write-the-file
)
1493 (with-current-buffer buffer
1494 (set-visited-file-modtime)))))))))
1496 (defun mail-sent-via ()
1497 "Make a Sent-via header line from each To or Cc header line."
1498 (declare (obsolete "nobody can remember what it is for." "24.1"))
1501 ;; put a marker at the end of the header
1502 (let ((end (copy-marker (mail-header-end)))
1503 (case-fold-search t
))
1504 (goto-char (point-min))
1505 ;; search for the To: lines and make Sent-via: lines from them
1506 ;; search for the next To: line
1507 (while (re-search-forward "^\\(to\\|cc\\):" end t
)
1508 ;; Grab this line plus all its continuations, sans the `to:'.
1510 (buffer-substring (point)
1512 (if (re-search-forward "^[^ \t\n]" end t
)
1516 ;; Insert a copy, with altered header field name.
1517 (insert-before-markers "Sent-via:" to-line
))))))
1520 "Move point to end of To field, creating it if necessary."
1523 (mail-position-on-field "To"))
1525 (defun mail-subject ()
1526 "Move point to end of Subject field, creating it if necessary."
1529 (mail-position-on-field "Subject"))
1532 "Move point to end of Cc field, creating it if necessary."
1535 (or (mail-position-on-field "cc" t
)
1536 (progn (mail-position-on-field "to")
1537 (insert "\nCC: "))))
1540 "Move point to end of Bcc field, creating it if necessary."
1543 (or (mail-position-on-field "bcc" t
)
1544 (progn (mail-position-on-field "to")
1545 (insert "\nBcc: "))))
1547 (defun mail-fcc (folder)
1548 "Add a new Fcc field, with file name completion."
1549 (interactive "FFolder carbon copy: ")
1551 (or (mail-position-on-field "fcc" t
) ;Put new field after exiting Fcc.
1552 (mail-position-on-field "to"))
1553 (insert "\nFcc: " folder
))
1555 (defun mail-reply-to ()
1556 "Move point to end of Reply-To field, creating it if necessary."
1559 (mail-position-on-field "Reply-To"))
1561 (defun mail-mail-reply-to ()
1562 "Move point to end of Mail-Reply-To field, creating it if necessary."
1565 (or (mail-position-on-field "mail-reply-to" t
)
1566 (progn (mail-position-on-field "to")
1567 (insert "\nMail-Reply-To: "))))
1569 (defun mail-mail-followup-to ()
1570 "Move point to end of Mail-Followup-To field, creating it if necessary."
1573 (or (mail-position-on-field "mail-followup-to" t
)
1574 (progn (mail-position-on-field "to")
1575 (insert "\nMail-Followup-To: "))))
1577 (defun mail-position-on-field (field &optional soft
)
1578 "Move to the end of the contents of header field FIELD.
1579 If there is no such header, insert one, unless SOFT is non-nil.
1580 If there are multiple FIELD fields, this goes to the first.
1581 Returns non-nil if FIELD was originally present."
1583 (case-fold-search t
))
1584 (setq end
(mail-header-end))
1585 (goto-char (point-min))
1586 (if (re-search-forward (concat "^" (regexp-quote field
) ":") end t
)
1588 (re-search-forward "^[^ \t]" nil
'move
)
1590 (skip-chars-backward "\n")
1593 (progn (goto-char end
)
1594 (insert field
": \n")
1595 (skip-chars-backward "\n")))
1599 "Move point to beginning of text field."
1602 (goto-char (mail-text-start)))
1604 (defun mail-signature (&optional atpoint
)
1605 "Sign letter with signature.
1606 If the variable `mail-signature' is a string, inserts it.
1607 If it is t or nil, inserts the contents of the file `mail-signature-file'.
1608 Otherwise, evals `mail-signature'.
1609 Prefix argument ATPOINT means insert at point rather than the end."
1611 ;; Test for an unreadable file here, before we delete trailing
1612 ;; whitespace, so that we don't modify the buffer needlessly.
1613 (if (and (memq mail-signature
'(t nil
))
1614 (not (file-readable-p mail-signature-file
)))
1615 (if (called-interactively-p 'interactive
)
1616 (message "The signature file `%s' could not be read"
1617 mail-signature-file
))
1620 (goto-char (point-max))
1621 ;; Delete trailing whitespace and blank lines.
1622 (skip-chars-backward " \t\n")
1624 (delete-region (point) (point-max)))
1625 (cond ((stringp mail-signature
)
1626 (insert mail-signature
))
1627 ((memq mail-signature
'(t nil
))
1628 (insert "\n\n-- \n")
1629 (insert-file-contents (expand-file-name mail-signature-file
)))
1631 ;; FIXME add condition-case error handling?
1632 (eval mail-signature
))))))
1634 (defun mail-fill-yanked-message (&optional justifyp
)
1635 "Fill the paragraphs of a message yanked into this one.
1636 Numeric argument means justify as well."
1639 (goto-char (mail-text-start))
1640 (fill-individual-paragraphs (point)
1643 mail-citation-prefix-regexp
)))
1645 (defun mail-indent-citation ()
1646 "Modify text just inserted from a message to be cited.
1647 The inserted text should be the region.
1648 When this function returns, the region is again around the modified text.
1650 Normally, indent each nonblank line `mail-indentation-spaces' spaces.
1651 However, if `mail-yank-prefix' is non-nil, insert that prefix on each line."
1652 (mail-yank-clear-headers (region-beginning) (region-end))
1653 (if (null mail-yank-prefix
)
1654 (indent-rigidly (region-beginning) (region-end)
1655 mail-indentation-spaces
)
1657 (let ((end (set-marker (make-marker) (region-end))))
1658 (goto-char (region-beginning))
1659 (while (< (point) end
)
1660 (insert mail-yank-prefix
)
1661 (forward-line 1))))))
1663 (defun mail-yank-original (arg)
1664 "Insert the message being replied to, if any (in Rmail).
1665 Puts point after the text and mark before.
1666 Normally, indents each nonblank line ARG spaces (default 3).
1667 However, if `mail-yank-prefix' is non-nil, insert that prefix on each line.
1669 Just \\[universal-argument] as argument means don't indent, insert no prefix,
1670 and don't delete any header fields."
1672 (if mail-reply-action
1673 (let ((start (point))
1674 (original mail-reply-action
)
1676 (and (consp original
) (eq (car original
) 'insert-buffer
)
1677 (setq original
(nth 1 original
)))
1678 (if (consp original
)
1680 ;; Call yank function, and set the mark if it doesn't.
1681 (apply (car original
) (cdr original
))
1682 (if (eq omark
(mark t
))
1684 ;; If the original message is in another window in the same
1685 ;; frame, delete that window to save space.
1686 (delete-windows-on original t
)
1688 ;; We really want this to set mark.
1689 (insert-buffer original
)
1690 ;; If they yank the original text, the encoding of the
1691 ;; original message is a better default than
1692 ;; the default buffer-file-coding-system.
1693 (and (coding-system-equal
1694 (default-value 'buffer-file-coding-system
)
1695 buffer-file-coding-system
)
1696 (setq buffer-file-coding-system
1697 (coding-system-change-text-conversion
1698 buffer-file-coding-system
1700 (with-current-buffer original
1701 buffer-file-coding-system
))))))
1702 (set-text-properties (point) (mark t
) nil
))
1706 (let ((mail-indentation-spaces (if arg
(prefix-numeric-value arg
)
1707 mail-indentation-spaces
))
1708 ;; Avoid error in Transient Mark mode
1709 ;; on account of mark's being inactive.
1710 (mark-even-if-inactive t
))
1711 (cond (mail-citation-hook
1712 ;; Bind mail-citation-header to the inserted
1713 ;; message's header.
1714 (let ((mail-citation-header
1715 (buffer-substring-no-properties
1719 (narrow-to-region start
(point-max))
1723 (run-hooks 'mail-citation-hook
)))
1725 (mail-indent-citation)))))
1726 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
1727 ;; It is cleaner to avoid activation, even though the command
1728 ;; loop would deactivate the mark because we inserted text.
1729 (goto-char (prog1 (mark t
)
1730 (set-marker (mark-marker) (point) (current-buffer))))
1731 (if (not (eolp)) (insert ?
\n)))))
1733 (defun mail-yank-clear-headers (start end
)
1736 (setq temp start start end end temp
)))
1737 (if mail-yank-ignored-headers
1740 (if (search-forward "\n\n" end t
)
1742 (narrow-to-region start
(point))
1744 (while (let ((case-fold-search t
))
1745 (re-search-forward mail-yank-ignored-headers nil t
))
1747 (delete-region (point)
1748 (progn (re-search-forward "\n[^ \t]")
1752 (defun mail-yank-region (arg)
1753 "Insert the selected region from the message being replied to.
1754 Puts point after the text and mark before.
1755 Normally, indents each nonblank line ARG spaces (default 3).
1756 However, if `mail-yank-prefix' is non-nil, insert that prefix on each line.
1758 Just \\[universal-argument] as argument means don't indent, insert no prefix,
1759 and don't delete any header fields."
1761 (and (consp mail-reply-action
)
1762 (memq (car mail-reply-action
)
1763 '(rmail-yank-current-message insert-buffer
))
1764 (with-current-buffer (nth 1 mail-reply-action
)
1766 (error "No mark set: %S" (current-buffer))))
1767 (let ((buffer (nth 1 mail-reply-action
))
1769 ;; Avoid error in Transient Mark mode
1770 ;; on account of mark's being inactive.
1771 (mark-even-if-inactive t
))
1772 ;; Insert the citation text.
1773 (insert (with-current-buffer buffer
1774 (buffer-substring-no-properties (point) (mark))))
1776 ;; Indent or otherwise annotate the citation text.
1779 (let ((mail-indentation-spaces (if arg
(prefix-numeric-value arg
)
1780 mail-indentation-spaces
)))
1781 (if mail-citation-hook
1782 ;; Bind mail-citation-header to the original message's header.
1783 (let ((mail-citation-header
1784 (with-current-buffer buffer
1785 (buffer-substring-no-properties
1788 (goto-char (point-min))
1791 (run-hooks 'mail-citation-hook
))
1792 (mail-indent-citation)))))))
1794 (defun mail-split-line ()
1795 "Split current line, moving portion beyond point vertically down.
1796 If the current line has `mail-yank-prefix', insert it on the new line."
1798 (split-line mail-yank-prefix
))
1801 (defun mail-insert-file (&optional file
)
1802 "Insert a file at the end of the buffer, with separator lines around it."
1803 (interactive "fAttach file: ")
1805 (goto-char (point-max))
1806 (or (bolp) (newline))
1808 (let ((start (point))
1810 (insert (format "===File %s===" file
))
1811 (insert-char ?
= (max 0 (- 60 (current-column))))
1813 (setq middle
(point))
1814 (insert "============================================================\n")
1817 (insert-file-contents file
)
1818 (or (bolp) (newline))
1819 (goto-char start
))))
1821 (define-obsolete-function-alias 'mail-attach-file
'mail-insert-file
"24.1")
1823 (declare-function mml-attach-file
"mml"
1824 (file &optional type description disposition
))
1825 (declare-function mm-default-file-encoding
"mm-encode" (file))
1827 (defun mail-add-attachment (file)
1828 "Add FILE as a MIME attachment to the end of the mail message being composed."
1829 (interactive "fAttach file: ")
1830 (mml-attach-file file
1831 (or (mm-default-file-encoding file
)
1832 "application/octet-stream") nil
)
1833 (setq mail-encode-mml t
))
1836 ;; Put these commands last, to reduce chance of lossage from quitting
1837 ;; in middle of loading the file.
1840 (defun mail (&optional noerase to subject in-reply-to cc replybuffer
1841 actions return-action
)
1842 "Edit a message to be sent. Prefix arg means resume editing (don't erase).
1843 When this function returns, the buffer `*mail*' is selected.
1844 The value is t if the message was newly initialized; otherwise, nil.
1846 Optionally, the signature file `mail-signature-file' can be inserted at the
1847 end; see the variable `mail-signature'.
1850 While editing message, type \\[mail-send-and-exit] to send the message and exit.
1852 Various special commands starting with C-c are available in sendmail mode
1853 to move to message header fields:
1856 If `mail-self-blind' is non-nil, a Bcc to yourself is inserted
1857 when the message is initialized.
1859 If `mail-default-reply-to' is non-nil, it should be an address (a string);
1860 a Reply-To: field with that address is inserted.
1862 If `mail-archive-file-name' is non-nil, an Fcc field with that file name
1865 The normal hook `mail-setup-hook' is run after the message is
1866 initialized. It can add more default fields to the message.
1868 The first argument, NOERASE, determines what to do when there is
1869 an existing modified `*mail*' buffer. If NOERASE is nil, the
1870 existing mail buffer is used, and the user is prompted whether to
1871 keep the old contents or to erase them. If NOERASE has the value
1872 `new', a new mail buffer will be created instead of using the old
1873 one. Any other non-nil value means to always select the old
1874 buffer without erasing the contents.
1876 The second through fifth arguments,
1877 TO, SUBJECT, IN-REPLY-TO and CC, specify if non-nil
1878 the initial contents of those header fields.
1879 These arguments should not have final newlines.
1880 The sixth argument REPLYBUFFER is a buffer which contains an
1881 original message being replied to, or else an action
1882 of the form (FUNCTION . ARGS) which says how to insert the original.
1883 Or it can be nil, if not replying to anything.
1884 The seventh argument ACTIONS is a list of actions to take
1885 if/when the message is sent. Each action looks like (FUNCTION . ARGS);
1886 when the message is sent, we apply FUNCTION to ARGS.
1887 This is how Rmail arranges to mark messages `answered'."
1889 (if (eq noerase
'new
)
1890 (pop-to-buffer-same-window (generate-new-buffer "*mail*"))
1892 (not (get-buffer "*mail*"))
1894 (pop-to-buffer-same-window "*mail*"))
1896 ;; Avoid danger that the auto-save file can't be written.
1897 (let ((dir (expand-file-name
1898 (file-name-as-directory mail-default-directory
))))
1899 (if (file-exists-p dir
)
1900 (setq default-directory dir
)))
1901 ;; Only call auto-save-mode if necessary, to avoid changing auto-save file.
1902 (if (or (and auto-save-default
(not buffer-auto-save-file-name
))
1903 (and (not auto-save-default
) buffer-auto-save-file-name
))
1904 (auto-save-mode auto-save-default
))
1906 ;; Disconnect the buffer from its visited file
1907 ;; (in case the user has actually visited a file *mail*).
1908 ;; (set-visited-file-name nil)
1910 (and (not (and noerase
1911 (not (eq noerase
'new
))))
1912 (if buffer-file-name
1913 (if (buffer-modified-p)
1914 (when (y-or-n-p "Buffer has unsaved changes; reinitialize it and discard them? ")
1915 (if (y-or-n-p "Disconnect buffer from visited file? ")
1916 (set-visited-file-name nil
))
1918 (when (y-or-n-p "Reinitialize buffer, and disconnect it from the visited file? ")
1919 (set-visited-file-name nil
)
1921 ;; A non-file-visiting buffer.
1922 (if (buffer-modified-p)
1923 (y-or-n-p "Unsent message being composed; erase it? ")
1925 (let ((inhibit-read-only t
))
1927 (mail-setup to subject in-reply-to cc replybuffer actions
1929 (setq initialized t
)))
1930 (if (and buffer-auto-save-file-name
1931 (file-exists-p buffer-auto-save-file-name
))
1932 (message "Auto save file for draft message exists; consider M-x mail-recover"))
1935 (declare-function dired-view-file
"dired" ())
1936 (declare-function dired-get-filename
"dired" (&optional localp no-error-if-not-filep
))
1938 (defun mail-recover-1 ()
1939 "Pop up a list of auto-saved draft messages so you can recover one of them."
1941 (let ((file-name (make-auto-save-file-name))
1942 (ls-lisp-support-shell-wildcards t
)
1943 non-random-len wildcard
)
1944 ;; Remove the random part from the auto-save-file-name, and
1945 ;; create a wildcard which matches possible candidates.
1946 ;; Note: this knows that make-auto-save-file-name appends
1947 ;; "#<RANDOM-STUFF>#" to the buffer name, where RANDOM-STUFF
1948 ;; is the result of (make-temp-name "").
1949 (setq non-random-len
1950 (- (length file-name
) (length (make-temp-name "")) 1))
1951 (setq wildcard
(concat (substring file-name
0 non-random-len
) "*"))
1952 (if (null (file-expand-wildcards wildcard
))
1953 (message "There are no auto-saved drafts to recover")
1954 ;; Bind dired-trivial-filenames to t because all auto-save file
1955 ;; names are normally ``trivial'', so Dired will set point after
1956 ;; all the files, at buffer bottom. We want it on the first
1958 ;; Require dired so that dired-trivial-filenames does not get
1959 ;; unbound on exit from the let.
1961 (defvar dired-trivial-filenames
)
1962 (let ((dired-trivial-filenames t
))
1963 (dired-other-window wildcard
(concat dired-listing-switches
" -t")))
1964 (rename-buffer "*Auto-saved Drafts*" t
)
1966 (goto-char (point-min))
1967 (or (looking-at " Move to the draft file you want to recover,")
1968 (let ((inhibit-read-only t
))
1969 ;; Each line starts with a space so that Font Lock mode
1970 ;; won't highlight the first character.
1972 Move to the draft file you want to recover, then type C-c C-c
1973 to recover text of message whose composition was interrupted.
1974 To browse text of a draft, type v on the draft file's line.
1976 You can also delete some of these files;
1977 type d on a line to mark that file for deletion.
1979 List of possible auto-save files for recovery:
1983 (let ((map (make-sparse-keymap)))
1984 (set-keymap-parent map
(current-local-map))
1986 (define-key (current-local-map) "v"
1989 (let ((coding-system-for-read 'utf-8-emacs-unix
))
1990 (dired-view-file))))
1991 (define-key (current-local-map) "\C-c\C-c"
1994 (let ((fname (dired-get-filename))
1995 ;; Auto-saved files are written in the internal
1996 ;; representation, so they should be read accordingly.
1997 (coding-system-for-read 'utf-8-emacs-unix
))
1998 (switch-to-buffer-other-window "*mail*")
1999 (let ((buffer-read-only nil
))
2001 (insert-file-contents fname nil
)
2002 ;; insert-file-contents will set buffer-file-coding-system
2003 ;; to utf-8-emacs, which is probably not what they want to
2004 ;; use for sending the message. But we don't know what
2005 ;; was its value before the buffer was killed or Emacs
2006 ;; crashed. We therefore reset buffer-file-coding-system
2007 ;; to the default value, so that either the default does
2008 ;; TRT, or the user will get prompted for the right
2009 ;; encoding when they send the message.
2010 (setq buffer-file-coding-system
2011 (default-value 'buffer-file-coding-system
)))))))))
2013 (declare-function dired-move-to-filename
"dired" (&optional raise-error eol
))
2014 (declare-function dired-get-filename
"dired" (&optional localp no-error-if-not-filep
))
2015 (declare-function dired-view-file
"dired" ())
2017 (defun mail-recover ()
2018 "Recover interrupted mail composition from auto-save files.
2020 If the mail buffer has a current valid auto-save file,
2021 the command recovers that file. Otherwise, it displays a
2022 buffer showing the existing auto-saved draft messages;
2023 you can move to one of them and type C-c C-c to recover that one."
2025 ;; In case they invoke us from some random buffer...
2026 (switch-to-buffer "*mail*")
2027 ;; If *mail* didn't exist, set its directory, so that auto-saved
2028 ;; drafts will be found.
2029 (let ((dir (expand-file-name
2030 (file-name-as-directory mail-default-directory
))))
2031 (if (file-exists-p dir
)
2032 (setq default-directory dir
)))
2033 (or (eq major-mode
'mail-mode
)
2035 (let ((file-name buffer-auto-save-file-name
))
2036 (cond ((and file-name
(file-exists-p file-name
))
2038 ;; This used to invoke `ls' via call-process, but
2039 ;; dired-noselect is more portable to systems where
2040 ;; `ls' is not a standard program (it will use
2041 ;; ls-lisp instead).
2042 (dired-noselect file-name
2043 (concat dired-listing-switches
" -t"))))
2044 (save-selected-window
2045 (switch-to-buffer-other-window dispbuf
)
2046 (goto-char (point-min))
2048 (dired-move-to-filename)
2049 (setq dispbuf
(rename-buffer "*Directory*" t
)))
2050 (if (not (yes-or-no-p
2051 (format "Recover mail draft from auto save file %s? "
2053 (error "mail-recover canceled")
2054 (let ((buffer-read-only nil
)
2055 (buffer-coding buffer-file-coding-system
)
2056 ;; Auto-save files are written in internal
2057 ;; representation of non-ASCII characters.
2058 (coding-system-for-read 'utf-8-emacs-unix
))
2060 (insert-file-contents file-name nil
)
2061 (setq buffer-file-coding-system buffer-coding
)))))
2062 (t (mail-recover-1)))))
2065 (defun mail-other-window (&optional noerase to subject in-reply-to cc replybuffer sendactions
)
2066 "Like `mail' command, but display mail buffer in another window."
2068 (switch-to-buffer-other-window "*mail*")
2069 (mail noerase to subject in-reply-to cc replybuffer sendactions
))
2072 (defun mail-other-frame (&optional noerase to subject in-reply-to cc replybuffer sendactions
)
2073 "Like `mail' command, but display mail buffer in another frame."
2075 (switch-to-buffer-other-frame "*mail*")
2076 (mail noerase to subject in-reply-to cc replybuffer sendactions
))
2078 ;; Do not add anything but external entries on this page.
2083 ;; byte-compile-dynamic: t
2086 ;;; sendmail.el ends here