cc-engine.el (c-beginning-of-statement-1): Enhance to parse case clauses
[emacs.git] / lisp / mail / sendmail.el
blob4b18da3524d6b2c00786bd40b5fdaabb60bba96b
1 ;;; sendmail.el --- mail sending commands for Emacs. -*- byte-compile-dynamic: t -*-
3 ;; Copyright (C) 1985, 1986, 1992, 1993, 1994, 1995, 1996, 1998, 2000,
4 ;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
5 ;; Free Software Foundation, Inc.
7 ;; Maintainer: FSF
8 ;; Keywords: mail
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;; Commentary:
27 ;; This mode provides mail-sending facilities from within Emacs. It is
28 ;; documented in the Emacs user's manual.
30 ;;; Code:
31 (eval-when-compile
32 ;; Necessary to avoid recursive `require's.
33 (provide 'sendmail)
34 (require 'rmail)
35 (require 'mailalias))
37 (autoload 'rfc2047-encode-string "rfc2047")
39 (defgroup sendmail nil
40 "Mail sending commands for Emacs."
41 :prefix "mail-"
42 :group 'mail)
44 (defcustom mail-setup-with-from t
45 "Non-nil means insert `From:' field when setting up the message."
46 :type 'boolean
47 :group 'sendmail
48 :version "22.1")
50 (defcustom sendmail-program
51 (cond
52 ((file-exists-p "/usr/sbin/sendmail") "/usr/sbin/sendmail")
53 ((file-exists-p "/usr/lib/sendmail") "/usr/lib/sendmail")
54 ((file-exists-p "/usr/ucblib/sendmail") "/usr/ucblib/sendmail")
55 (t "fakemail")) ;In ../etc, to interface to /bin/mail.
56 "Program used to send messages."
57 :group 'mail
58 :type 'file)
60 ;;;###autoload
61 (defcustom mail-from-style 'angles
62 "Specifies how \"From:\" fields look.
64 If `nil', they contain just the return address like:
65 king@grassland.com
66 If `parens', they look like:
67 king@grassland.com (Elvis Parsley)
68 If `angles', they look like:
69 Elvis Parsley <king@grassland.com>
70 If `system-default', allows the mailer to insert its default From field
71 derived from the envelope-from address.
73 In old versions of Emacs, the `system-default' setting also caused
74 Emacs to pass the proper email address from `user-mail-address'
75 to the mailer to specify the envelope-from address. But that is now
76 controlled by a separate variable, `mail-specify-envelope-from'."
77 :type '(choice (const nil) (const parens) (const angles)
78 (const system-default))
79 :version "20.3"
80 :group 'sendmail)
82 ;;;###autoload
83 (defcustom mail-specify-envelope-from nil
84 "If non-nil, specify the envelope-from address when sending mail.
85 The value used to specify it is whatever is found in
86 the variable `mail-envelope-from', with `user-mail-address' as fallback.
88 On most systems, specifying the envelope-from address is a
89 privileged operation. This variable affects sendmail and
90 smtpmail -- if you use feedmail to send mail, see instead the
91 variable `feedmail-deduce-envelope-from'."
92 :version "21.1"
93 :type 'boolean
94 :group 'sendmail)
96 (defcustom mail-envelope-from nil
97 "If non-nil, designate the envelope-from address when sending mail.
98 This only has an effect if `mail-specify-envelope-from' is non-nil.
99 The value should be either a string, or the symbol `header' (in
100 which case the contents of the \"From\" header of the message
101 being sent is used), or nil (in which case the value of
102 `user-mail-address' is used)."
103 :version "21.1"
104 :type '(choice (string :tag "From-name")
105 (const :tag "Use From: header from message" header)
106 (const :tag "Use `user-mail-address'" nil))
107 :group 'sendmail)
109 ;;;###autoload
110 (defcustom mail-self-blind nil
111 "Non-nil means insert BCC to self in messages to be sent.
112 This is done when the message is initialized,
113 so you can remove or alter the BCC field to override the default."
114 :type 'boolean
115 :group 'sendmail)
117 ;;;###autoload
118 (defcustom mail-interactive t
119 ;; We used to use a default of nil rather than t, but nowadays it is very
120 ;; common for sendmail to be misconfigured, so one cannot rely on the
121 ;; bounce message to be delivered anywhere, least of all to the
122 ;; user's mailbox.
123 "Non-nil means when sending a message wait for and display errors.
124 nil means let mailer mail back a message to report errors."
125 :type 'boolean
126 :version "23.1" ; changed from nil to t
127 :group 'sendmail)
129 (defcustom mail-yank-ignored-headers
130 (concat "^"
131 (regexp-opt '("via" "mail-from" "origin" "status" "remailed"
132 "received" "message-id" "summary-line" "to" "subject"
133 "in-reply-to" "return-path" "mail-reply-to"
134 "mail-followup-to") "\\(?:")
135 ":")
136 "Delete these headers from old message when it's inserted in a reply."
137 :type 'regexp
138 :group 'sendmail)
140 ;; Prevent problems with `window-system' not having the correct value
141 ;; when loaddefs.el is loaded. `custom-reevaluate-setting' needs the
142 ;; standard value.
143 ;;;###autoload
144 (put 'send-mail-function 'standard-value
145 '((if (and window-system (memq system-type '(darwin windows-nt)))
146 'mailclient-send-it
147 'sendmail-send-it)))
149 ;; Useful to set in site-init.el
150 ;;;###autoload
151 (defcustom send-mail-function
152 (if (and window-system (memq system-type '(darwin windows-nt)))
153 'mailclient-send-it
154 'sendmail-send-it)
155 "Function to call to send the current buffer as mail.
156 The headers should be delimited by a line which is
157 not a valid RFC822 header or continuation line,
158 that matches the variable `mail-header-separator'.
159 This is used by the default mail-sending commands. See also
160 `message-send-mail-function' for use with the Message package."
161 :type '(radio (function-item sendmail-send-it :tag "Use Sendmail package")
162 (function-item smtpmail-send-it :tag "Use SMTPmail package")
163 (function-item feedmail-send-it :tag "Use Feedmail package")
164 (function-item mailclient-send-it :tag "Use Mailclient package")
165 function)
166 :group 'sendmail)
168 ;;;###autoload
169 (defcustom mail-header-separator "--text follows this line--"
170 "Line used to separate headers from text in messages being composed."
171 :type 'string
172 :group 'sendmail)
174 ;; Set up mail-header-separator for use as a category text property.
175 (put 'mail-header-separator 'rear-nonsticky '(category))
176 ;; This was a nice idea, for preventing accidental modification of
177 ;; the separator. But I found it also prevented or obstructed
178 ;; certain deliberate operations, such as copying the separator line
179 ;; up to the top to send myself a copy of an already sent outgoing message
180 ;; and other things. So I turned it off. --rms.
181 ;;(put 'mail-header-separator 'read-only t)
183 ;;;###autoload
184 (defcustom mail-archive-file-name nil
185 "Name of file to write all outgoing messages in, or nil for none.
186 This can be an inbox file or an Rmail file."
187 :type '(choice file (const nil))
188 :group 'sendmail)
190 ;;;###autoload
191 (defcustom mail-default-reply-to nil
192 "Address to insert as default Reply-to field of outgoing messages.
193 If nil, it will be initialized from the REPLYTO environment variable
194 when you first send mail."
195 :type '(choice (const nil) string)
196 :group 'sendmail)
198 ;;;###autoload
199 (defcustom mail-alias-file nil
200 "If non-nil, the name of a file to use instead of `/usr/lib/aliases'.
201 This file defines aliases to be expanded by the mailer; this is a different
202 feature from that of defining aliases in `.mailrc' to be expanded in Emacs.
203 This variable has no effect unless your system uses sendmail as its mailer."
204 :type '(choice (const nil) file)
205 :group 'sendmail)
207 ;;;###autoload
208 (defcustom mail-personal-alias-file "~/.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)
214 :group 'sendmail)
216 ;;;###autoload
217 (defcustom mail-setup-hook nil
218 "Normal hook, run each time a new outgoing mail message is initialized.
219 The function `mail-setup' runs this hook."
220 :type 'hook
221 :options '(fortune-to-signature spook mail-abbrevs-setup)
222 :group 'sendmail)
224 ;;;###autoload
225 (defvar mail-aliases t
226 "Alist of mail address aliases,
227 or t meaning should be initialized from your mail aliases file.
228 \(The file's name is normally `~/.mailrc', but `mail-personal-alias-file'
229 can specify a different file name.)
230 The alias definitions in the file have this form:
231 alias ALIAS MEANING")
233 (defvar mail-alias-modtime nil
234 "The modification time of your mail alias file when it was last examined.")
236 ;;;###autoload
237 (defcustom mail-yank-prefix nil
238 "Prefix insert on lines of yanked message being replied to.
239 nil means use indentation."
240 :type '(choice (const nil) string)
241 :group 'sendmail)
243 ;;;###autoload
244 (defcustom mail-indentation-spaces 3
245 "Number of spaces to insert at the beginning of each cited line.
246 Used by `mail-yank-original' via `mail-indent-citation'."
247 :type 'integer
248 :group 'sendmail)
250 (defvar mail-yank-hooks nil
251 "Obsolete 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 each hook function should leave point and mark around the citation
254 text as modified.
256 This is a normal hook, misnamed for historical reasons.
257 It is semi-obsolete and mail agents should no longer use it.")
259 ;;;###autoload
260 (defcustom mail-citation-hook nil
261 "Hook for modifying a citation just inserted in the mail buffer.
262 Each hook function can find the citation between (point) and (mark t),
263 and should leave point and mark around the citation text as modified.
264 The hook functions can find the header of the cited message
265 in the variable `mail-citation-header', whether or not this is included
266 in the cited portion of the message.
268 If this hook is entirely empty (nil), a default action is taken
269 instead of no action."
270 :type 'hook
271 :group 'sendmail)
273 (defvar mail-citation-header nil
274 "While running `mail-citation-hook', this variable holds the message header.
275 This enables the hook functions to see the whole message header
276 regardless of what part of it (if any) is included in the cited text.")
278 ;;;###autoload
279 (defcustom mail-citation-prefix-regexp "[ \t]*[-a-z0-9A-Z]*>+[ \t]*\\|[ \t]*"
280 "Regular expression to match a citation prefix plus whitespace.
281 It should match whatever sort of citation prefixes you want to handle,
282 with whitespace before and after; it should also match just whitespace.
283 The default value matches citations like `foo-bar>' plus whitespace."
284 :type 'regexp
285 :group 'sendmail
286 :version "20.3")
288 (defvar mail-abbrevs-loaded nil)
289 (defvar mail-mode-map
290 (let ((map (make-sparse-keymap)))
291 (define-key map "\M-\t" 'mail-complete)
292 (define-key map "\C-c?" 'describe-mode)
293 (define-key map "\C-c\C-f\C-t" 'mail-to)
294 (define-key map "\C-c\C-f\C-b" 'mail-bcc)
295 (define-key map "\C-c\C-f\C-f" 'mail-fcc)
296 (define-key map "\C-c\C-f\C-c" 'mail-cc)
297 (define-key map "\C-c\C-f\C-s" 'mail-subject)
298 (define-key map "\C-c\C-f\C-r" 'mail-reply-to)
299 (define-key map "\C-c\C-f\C-a" 'mail-mail-reply-to) ; author
300 (define-key map "\C-c\C-f\C-l" 'mail-mail-followup-to) ; list
301 (define-key map "\C-c\C-t" 'mail-text)
302 (define-key map "\C-c\C-y" 'mail-yank-original)
303 (define-key map "\C-c\C-r" 'mail-yank-region)
304 (define-key map [remap split-line] 'mail-split-line)
305 (define-key map "\C-c\C-q" 'mail-fill-yanked-message)
306 (define-key map "\C-c\C-w" 'mail-signature)
307 (define-key map "\C-c\C-v" 'mail-sent-via)
308 (define-key map "\C-c\C-c" 'mail-send-and-exit)
309 (define-key map "\C-c\C-s" 'mail-send)
310 (define-key map "\C-c\C-i" 'mail-attach-file)
312 (define-key map [menu-bar mail]
313 (cons "Mail" (make-sparse-keymap "Mail")))
315 (define-key map [menu-bar mail fill]
316 '("Fill Citation" . mail-fill-yanked-message))
318 (define-key map [menu-bar mail yank]
319 '("Cite Original" . mail-yank-original))
321 (define-key map [menu-bar mail signature]
322 '("Insert Signature" . mail-signature))
324 (define-key map [menu-bar mail mail-sep]
325 '("--"))
327 (define-key map [menu-bar mail cancel]
328 '("Cancel" . mail-dont-send))
330 (define-key map [menu-bar mail send-stay]
331 '("Send, Keep Editing" . mail-send))
333 (define-key map [menu-bar mail send]
334 '("Send Message" . mail-send-and-exit))
336 (define-key map [menu-bar headers]
337 (cons "Headers" (make-sparse-keymap "Move to Header")))
339 (define-key map [menu-bar headers text]
340 '("Text" . mail-text))
342 (define-key map [menu-bar headers expand-aliases]
343 '("Expand Aliases" . expand-mail-aliases))
345 (define-key map [menu-bar headers sent-via]
346 '("Sent Via" . mail-sent-via))
348 (define-key map [menu-bar headers mail-reply-to]
349 '("Mail Reply To" . mail-mail-reply-to))
351 (define-key map [menu-bar headers mail-followup-to]
352 '("Mail Followup To" . mail-mail-followup-to))
354 (define-key map [menu-bar headers reply-to]
355 '("Reply-To" . mail-reply-to))
357 (define-key map [menu-bar headers bcc]
358 '("Bcc" . mail-bcc))
360 (define-key map [menu-bar headers fcc]
361 '("Fcc" . mail-fcc))
363 (define-key map [menu-bar headers cc]
364 '("Cc" . mail-cc))
366 (define-key map [menu-bar headers subject]
367 '("Subject" . mail-subject))
369 (define-key map [menu-bar headers to]
370 '("To" . mail-to))
372 map))
374 (autoload 'build-mail-aliases "mailalias"
375 "Read mail aliases from user's personal aliases file and set `mail-aliases'."
376 nil)
378 (autoload 'expand-mail-aliases "mailalias"
379 "Expand all mail aliases in suitable header fields found between BEG and END.
380 Suitable header fields are `To', `Cc' and `Bcc' and their `Resent-' variants.
381 Optional second arg EXCLUDE may be a regular expression defining text to be
382 removed from alias expansions."
383 nil)
385 ;;;###autoload
386 (defcustom mail-signature nil
387 "Text inserted at end of mail buffer when a message is initialized.
388 If t, it means to insert the contents of the file `mail-signature-file'.
389 If a string, that string is inserted.
390 (To make a proper signature, the string should begin with \\n\\n-- \\n,
391 which is the standard way to delimit a signature in a message.)
392 Otherwise, it should be an expression; it is evaluated
393 and should insert whatever you want to insert."
394 :type '(choice (const :tag "None" nil)
395 (const :tag "Use `.signature' file" t)
396 (string :tag "String to insert")
397 (sexp :tag "Expression to evaluate"))
398 :group 'sendmail)
399 (put 'mail-signature 'risky-local-variable t)
401 ;;;###autoload
402 (defcustom mail-signature-file "~/.signature"
403 "File containing the text inserted at end of mail buffer."
404 :type 'file
405 :group 'sendmail)
407 ;;;###autoload
408 (defcustom mail-default-directory "~/"
409 "Directory for mail buffers.
410 Value of `default-directory' for mail buffers.
411 This directory is used for auto-save files of mail buffers."
412 :type '(directory :tag "Directory")
413 :group 'sendmail
414 :version "22.1")
416 (defvar mail-reply-action nil)
417 (defvar mail-send-actions nil
418 "A list of actions to be performed upon successful sending of a message.")
419 (put 'mail-reply-action 'permanent-local t)
420 (put 'mail-send-actions 'permanent-local t)
422 ;;;###autoload
423 (defcustom mail-default-headers nil
424 "A string containing header lines, to be inserted in outgoing messages.
425 It is inserted before you edit the message,
426 so you can edit or delete these lines."
427 :type '(choice (const nil) string)
428 :group 'sendmail)
430 ;;;###autoload
431 (defcustom mail-bury-selects-summary t
432 "If non-nil, try to show Rmail summary buffer after returning from mail.
433 The functions \\[mail-send-on-exit] or \\[mail-dont-send] select
434 the Rmail summary buffer before returning, if it exists and this variable
435 is non-nil."
436 :type 'boolean
437 :group 'sendmail)
439 ;;;###autoload
440 (defcustom mail-send-nonascii 'mime
441 "Specify whether to allow sending non-ASCII characters in mail.
442 If t, that means do allow it. nil means don't allow it.
443 `query' means ask the user each time.
444 `mime' means add an appropriate MIME header if none already present.
445 The default is `mime'.
446 Including non-ASCII characters in a mail message can be problematical
447 for the recipient, who may not know how to decode them properly."
448 :type '(choice (const t) (const nil) (const query) (const mime))
449 :group 'sendmail)
451 (defcustom mail-use-dsn nil
452 "Ask MTA for notification of failed, delayed or successful delivery.
453 Note that only some MTAs (currently only recent versions of Sendmail)
454 support Delivery Status Notification."
455 :group 'sendmail
456 :type '(repeat (radio (const :tag "Failure" failure)
457 (const :tag "Delay" delay)
458 (const :tag "Success" success)))
459 :version "22.1")
461 ;; Note: could use /usr/ucb/mail instead of sendmail;
462 ;; options -t, and -v if not interactive.
463 (defvar mail-mailer-swallows-blank-line
464 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)" system-configuration)
465 (file-readable-p "/etc/sendmail.cf")
466 (with-temp-buffer
467 (insert-file-contents "/etc/sendmail.cf")
468 (goto-char (point-min))
469 (let ((case-fold-search nil))
470 (re-search-forward "^OR\\>" nil t))))
471 ;; According to RFC822, "The field-name must be composed of printable
472 ;; ASCII characters (i.e. characters that have decimal values between
473 ;; 33 and 126, except colon)", i.e. any chars except ctl chars,
474 ;; space, or colon.
475 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
476 "Set this non-nil if the system's mailer runs the header and body together.
477 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
478 The value should be an expression to test whether the problem will
479 actually occur.")
481 (defvar mail-mode-syntax-table
482 (let ((st (make-syntax-table)))
483 ;; define-derived-mode will make it inherit from text-mode-syntax-table.
484 (modify-syntax-entry ?% ". " st)
486 "Syntax table used while in `mail-mode'.")
488 (defvar mail-font-lock-keywords
489 (eval-when-compile
490 (let* ((cite-chars "[>|}]")
491 (cite-prefix "[:alpha:]")
492 (cite-suffix (concat cite-prefix "0-9_.@-`'\"")))
493 (list '("^\\(To\\|Newsgroups\\):" . font-lock-function-name-face)
494 '("^\\(B?CC\\|Reply-to\\|Mail-\\(reply\\|followup\\)-to\\):" . font-lock-keyword-face)
495 '("^\\(Subject:\\)[ \t]*\\(.+\\)?"
496 (1 font-lock-comment-face)
497 ;; (2 font-lock-type-face nil t)
499 ;; Use EVAL to delay in case `mail-header-separator' gets changed.
500 '(eval .
501 (let ((separator (if (zerop (length mail-header-separator))
502 " \\`\\' "
503 (regexp-quote mail-header-separator))))
504 (cons (concat "^" separator "$") 'font-lock-warning-face)))
505 ;; Use MATCH-ANCHORED to effectively anchor the regexp left side.
506 `(,cite-chars
507 (,(concat "\\=[ \t]*"
508 "\\(\\(\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
509 "\\(" cite-chars "[ \t]*\\)\\)+\\)"
510 "\\(.*\\)")
511 (beginning-of-line) (end-of-line)
512 (1 font-lock-comment-delimiter-face nil t)
513 (5 font-lock-comment-face nil t)))
514 '("^\\(X-[A-Za-z0-9-]+\\|In-reply-to\\):.*\\(\n[ \t]+.*\\)*$"
515 . font-lock-string-face))))
516 "Additional expressions to highlight in Mail mode.")
519 (defun sendmail-sync-aliases ()
520 (when mail-personal-alias-file
521 (let ((modtime (nth 5 (file-attributes mail-personal-alias-file))))
522 (or (equal mail-alias-modtime modtime)
523 (setq mail-alias-modtime modtime
524 mail-aliases t)))))
526 (defun mail-setup (to subject in-reply-to cc replybuffer actions)
527 (or mail-default-reply-to
528 (setq mail-default-reply-to (getenv "REPLYTO")))
529 (sendmail-sync-aliases)
530 (if (eq mail-aliases t)
531 (progn
532 (setq mail-aliases nil)
533 (when mail-personal-alias-file
534 (if (file-exists-p mail-personal-alias-file)
535 (build-mail-aliases)))))
536 ;; Don't leave this around from a previous message.
537 (kill-local-variable 'buffer-file-coding-system)
538 ;; This doesn't work for enable-multibyte-characters.
539 ;; (kill-local-variable 'enable-multibyte-characters)
540 (set-buffer-multibyte default-enable-multibyte-characters)
541 (if current-input-method
542 (inactivate-input-method))
543 (setq mail-send-actions actions)
544 (setq mail-reply-action replybuffer)
545 (goto-char (point-min))
546 (if mail-setup-with-from
547 (mail-insert-from-field))
548 (insert "To: ")
549 (save-excursion
550 (if to
551 ;; Here removed code to extract names from within <...>
552 ;; on the assumption that mail-strip-quoted-names
553 ;; has been called and has done so.
554 (let ((fill-prefix "\t")
555 (address-start (point)))
556 (insert to "\n")
557 (fill-region-as-paragraph address-start (point-max))
558 (goto-char (point-max))
559 (unless (bolp)
560 (newline)))
561 (newline))
562 (if cc
563 (let ((fill-prefix "\t")
564 (address-start (progn (insert "CC: ") (point))))
565 (insert cc "\n")
566 (fill-region-as-paragraph address-start (point-max))
567 (goto-char (point-max))
568 (unless (bolp)
569 (newline))))
570 (if in-reply-to
571 (let ((fill-prefix "\t")
572 (fill-column 78)
573 (address-start (point)))
574 (insert "In-reply-to: " in-reply-to "\n")
575 (fill-region-as-paragraph address-start (point-max))
576 (goto-char (point-max))
577 (unless (bolp)
578 (newline))))
579 (insert "Subject: " (or subject "") "\n")
580 (if mail-default-headers
581 (insert mail-default-headers))
582 (if mail-default-reply-to
583 (insert "Reply-to: " mail-default-reply-to "\n"))
584 (if mail-self-blind
585 (insert "BCC: " user-mail-address "\n"))
586 (if mail-archive-file-name
587 (insert "FCC: " mail-archive-file-name "\n"))
588 (put-text-property (point)
589 (progn
590 (insert mail-header-separator "\n")
591 (1- (point)))
592 'category 'mail-header-separator)
593 ;; Insert the signature. But remember the beginning of the message.
594 (if to (setq to (point)))
595 (cond ((eq mail-signature t)
596 (if (file-exists-p mail-signature-file)
597 (progn
598 (insert "\n\n-- \n")
599 (insert-file-contents mail-signature-file))))
600 ((stringp mail-signature)
601 (insert mail-signature))
603 (eval mail-signature)))
604 (goto-char (point-max))
605 (or (bolp) (newline)))
606 (if to (goto-char to))
607 (or to subject in-reply-to
608 (set-buffer-modified-p nil))
609 (run-hooks 'mail-setup-hook))
611 (defcustom mail-mode-hook nil
612 "Hook run by Mail mode."
613 :group 'sendmail
614 :type 'hook
615 :options '(footnote-mode))
617 (defvar mail-mode-abbrev-table text-mode-abbrev-table)
618 ;;;###autoload
619 (define-derived-mode mail-mode text-mode "Mail"
620 "Major mode for editing mail to be sent.
621 Like Text Mode but with these additional commands:
623 \\[mail-send] mail-send (send the message)
624 \\[mail-send-and-exit] mail-send-and-exit (send the message and exit)
626 Here are commands that move to a header field (and create it if there isn't):
627 \\[mail-to] move to To: \\[mail-subject] move to Subj:
628 \\[mail-bcc] move to BCC: \\[mail-cc] move to CC:
629 \\[mail-fcc] move to FCC: \\[mail-reply-to] move to Reply-To:
630 \\[mail-mail-reply-to] move to Mail-Reply-To:
631 \\[mail-mail-followup-to] move to Mail-Followup-To:
632 \\[mail-text] move to message text.
633 \\[mail-signature] mail-signature (insert `mail-signature-file' file).
634 \\[mail-yank-original] mail-yank-original (insert current message, in Rmail).
635 \\[mail-fill-yanked-message] mail-fill-yanked-message (fill what was yanked).
636 \\[mail-sent-via] mail-sent-via (add a sent-via field for each To or CC).
637 Turning on Mail mode runs the normal hooks `text-mode-hook' and
638 `mail-mode-hook' (in that order)."
639 (make-local-variable 'mail-reply-action)
640 (make-local-variable 'mail-send-actions)
641 (setq buffer-offer-save t)
642 (make-local-variable 'font-lock-defaults)
643 (setq font-lock-defaults '(mail-font-lock-keywords t t))
644 (make-local-variable 'paragraph-separate)
645 (make-local-variable 'normal-auto-fill-function)
646 (setq normal-auto-fill-function 'mail-mode-auto-fill)
647 (make-local-variable 'fill-paragraph-function)
648 (setq fill-paragraph-function 'mail-mode-fill-paragraph)
649 ;; Allow using comment commands to add/remove quoting (this only does
650 ;; anything if mail-yank-prefix is set to a non-nil value).
651 (set (make-local-variable 'comment-start) mail-yank-prefix)
652 (if mail-yank-prefix
653 (set (make-local-variable 'comment-start-skip)
654 (concat "^" (regexp-quote mail-yank-prefix) "[ \t]*")))
655 (make-local-variable 'adaptive-fill-regexp)
656 (setq adaptive-fill-regexp
657 (concat "[ \t]*[-[:alnum:]]+>+[ \t]*\\|"
658 adaptive-fill-regexp))
659 (make-local-variable 'adaptive-fill-first-line-regexp)
660 (setq adaptive-fill-first-line-regexp
661 (concat "[ \t]*[-[:alnum:]]*>+[ \t]*\\|"
662 adaptive-fill-first-line-regexp))
663 ;; `-- ' precedes the signature. `-----' appears at the start of the
664 ;; lines that delimit forwarded messages.
665 ;; Lines containing just >= 3 dashes, perhaps after whitespace,
666 ;; are also sometimes used and should be separators.
667 (setq paragraph-separate (concat (regexp-quote mail-header-separator)
668 "$\\|\t*\\([-|#;>* ]\\|(?[0-9]+[.)]\\)+$"
669 "\\|[ \t]*[[:alnum:]]*>+[ \t]*$\\|[ \t]*$\\|"
670 "--\\( \\|-+\\)$\\|"
671 page-delimiter)))
674 (defun mail-header-end ()
675 "Return the buffer location of the end of headers, as a number."
676 (save-restriction
677 (widen)
678 (save-excursion
679 (rfc822-goto-eoh)
680 (point))))
682 (defun mail-text-start ()
683 "Return the buffer location of the start of text, as a number."
684 (save-restriction
685 (widen)
686 (save-excursion
687 (rfc822-goto-eoh)
688 (forward-line 1)
689 (point))))
691 (defun mail-sendmail-delimit-header ()
692 "Set up whatever header delimiter convention sendmail will use.
693 Concretely: replace the first blank line in the header with the separator."
694 (rfc822-goto-eoh)
695 (insert mail-header-separator)
696 (point))
698 (defun mail-sendmail-undelimit-header ()
699 "Remove header separator to put the message in correct form for sendmail.
700 Leave point at the start of the delimiter line."
701 (rfc822-goto-eoh)
702 (delete-region (point) (progn (end-of-line) (point))))
704 (defun mail-mode-auto-fill ()
705 "Carry out Auto Fill for Mail mode.
706 If within the headers, this makes the new lines into continuation lines."
707 (if (< (point) (mail-header-end))
708 (let ((old-line-start (save-excursion (beginning-of-line) (point))))
709 (if (do-auto-fill)
710 (save-excursion
711 (beginning-of-line)
712 (while (not (eq (point) old-line-start))
713 ;; Use insert-before-markers in case we're inserting
714 ;; before the saved value of point (which is common).
715 (insert-before-markers " ")
716 (forward-line -1))
717 t)))
718 (do-auto-fill)))
720 (defun mail-mode-fill-paragraph (arg)
721 ;; Do something special only if within the headers.
722 (if (< (point) (mail-header-end))
723 (let (beg end fieldname)
724 (when (prog1 (re-search-backward "^[-a-zA-Z]+:" nil 'yes)
725 (setq beg (point)))
726 (setq fieldname
727 (downcase (buffer-substring beg (1- (match-end 0))))))
728 (forward-line 1)
729 ;; Find continuation lines and get rid of their continuation markers.
730 (while (looking-at "[ \t]")
731 (delete-horizontal-space)
732 (forward-line 1))
733 (setq end (point-marker))
734 (goto-char beg)
735 ;; If this field contains addresses,
736 ;; make sure we can fill after each address.
737 (if (member fieldname
738 '("to" "cc" "bcc" "from" "reply-to"
739 "mail-reply-to" "mail-followup-to"
740 "resent-to" "resent-cc" "resent-bcc"
741 "resent-from" "resent-reply-to"))
742 (while (search-forward "," end t)
743 (or (looking-at "[ \t]")
744 (insert " "))))
745 (fill-region-as-paragraph beg end arg)
746 ;; Mark all lines except the first as continuations.
747 (goto-char beg)
748 (forward-line 1)
749 (while (< (point) end)
750 (insert " ")
751 (forward-line 1))
752 (move-marker end nil)
753 t)))
755 ;; User-level commands for sending.
757 (defun mail-send-and-exit (&optional arg)
758 "Send message like `mail-send', then, if no errors, exit from mail buffer.
759 Prefix arg means don't delete this window."
760 (interactive "P")
761 (mail-send)
762 (mail-bury arg))
764 (defun mail-dont-send (&optional arg)
765 "Don't send the message you have been editing.
766 Prefix arg means don't delete this window."
767 (interactive "P")
768 (mail-bury arg))
770 (defun mail-bury (&optional arg)
771 "Bury this mail buffer."
772 (let ((newbuf (other-buffer (current-buffer))))
773 (bury-buffer (current-buffer))
774 (if (and (or nil
775 ;; In this case, we need to go to a different frame.
776 (window-dedicated-p (frame-selected-window))
777 ;; In this mode of operation, the frame was probably
778 ;; made for this buffer, so the user probably wants
779 ;; to delete it now.
780 (and pop-up-frames (one-window-p))
781 (cdr (assq 'mail-dedicated-frame (frame-parameters))))
782 (not (null (delq (selected-frame) (visible-frame-list)))))
783 (progn
784 (if (display-multi-frame-p)
785 (delete-frame (selected-frame))
786 ;; The previous frame is where normally they have the
787 ;; Rmail buffer displayed.
788 (other-frame -1)))
789 (let (rmail-flag summary-buffer)
790 (and (not arg)
791 (not (one-window-p))
792 (with-current-buffer
793 (window-buffer (next-window (selected-window) 'not))
794 (setq rmail-flag (eq major-mode 'rmail-mode))
795 (setq summary-buffer
796 (and mail-bury-selects-summary
797 (boundp 'rmail-summary-buffer)
798 rmail-summary-buffer
799 (buffer-name rmail-summary-buffer)
800 (not (get-buffer-window rmail-summary-buffer))
801 rmail-summary-buffer))))
802 (if rmail-flag
803 ;; If the Rmail buffer has a summary, show that.
804 (if summary-buffer (switch-to-buffer summary-buffer)
805 (delete-window))
806 (switch-to-buffer newbuf))))))
808 (defcustom mail-send-hook nil
809 "Hook run just before sending mail with `mail-send'."
810 :type 'hook
811 :options '(flyspell-mode-off)
812 :group 'sendmail)
814 ;;;###autoload
815 (defcustom mail-mailing-lists nil "\
816 *List of mailing list addresses the user is subscribed to.
818 The variable is used to trigger insertion of the \"Mail-Followup-To\"
819 header when sending a message to a mailing list."
820 :type '(repeat string)
821 :group 'sendmail)
824 (defun mail-send ()
825 "Send the message in the current buffer.
826 If `mail-interactive' is non-nil, wait for success indication
827 or error messages, and inform user.
828 Otherwise any failure is reported in a message back to
829 the user from the mailer."
830 (interactive)
831 (if (if buffer-file-name
832 (y-or-n-p "Send buffer contents as mail message? ")
833 (or (buffer-modified-p)
834 (y-or-n-p "Message already sent; resend? ")))
835 (let ((inhibit-read-only t)
836 (opoint (point))
837 (ml (when mail-mailing-lists
838 ;; The surrounding regexp assumes the use of
839 ;; `mail-strip-quoted-names' on addresses before matching
840 ;; Cannot deal with full RFC 822 freedom, but that is
841 ;; unlikely to be problematic.
842 (concat "\\(?:[[:space:];,]\\|\\`\\)"
843 (regexp-opt mail-mailing-lists t)
844 "\\(?:[[:space:];,]\\|\\'\\)"))))
845 ;; If there are mailing lists defined
846 (when ml
847 (save-excursion
848 (let* ((to (mail-fetch-field "to" nil t))
849 (cc (mail-fetch-field "cc" nil t))
850 (new-header-values ; To: and Cc:
851 (mail-strip-quoted-names
852 (concat to (when cc (concat ", " cc))))))
853 ;; If message goes to known mailing list ...
854 (when (string-match ml new-header-values)
855 ;; Add Mail-Followup-To if none yet
856 (unless (mail-fetch-field "mail-followup-to")
857 (goto-char (mail-header-end))
858 (insert "Mail-Followup-To: "
859 (let ((l))
860 (mapc
861 ;; remove duplicates
862 '(lambda (e)
863 (unless (member e l)
864 (push e l)))
865 (split-string new-header-values
866 ",[[:space:]]+" t))
867 (mapconcat 'identity l ", "))
868 "\n"))
869 ;; Add Mail-Reply-To if none yet
870 (unless (mail-fetch-field "mail-reply-to")
871 (goto-char (mail-header-end))
872 (insert "Mail-Reply-To: "
873 (or (mail-fetch-field "reply-to")
874 user-mail-address)
875 "\n"))))))
876 (unless (memq mail-send-nonascii '(t mime))
877 (goto-char (point-min))
878 (skip-chars-forward "\0-\177")
879 (or (= (point) (point-max))
880 (if (eq mail-send-nonascii 'query)
881 (or (y-or-n-p "Message contains non-ASCII characters; send anyway? ")
882 (error "Aborted"))
883 (error "Message contains non-ASCII characters"))))
884 ;; Complain about any invalid line.
885 (goto-char (point-min))
886 (re-search-forward (regexp-quote mail-header-separator) (point-max) t)
887 (let ((header-end (or (match-beginning 0) (point-max))))
888 (goto-char (point-min))
889 (while (< (point) header-end)
890 (unless (looking-at "[ \t]\\|.*:\\|$")
891 (push-mark opoint)
892 (error "Invalid header line (maybe a continuation line lacks initial whitespace)"))
893 (forward-line 1)))
894 (goto-char opoint)
895 (run-hooks 'mail-send-hook)
896 (message "Sending...")
897 (funcall send-mail-function)
898 ;; Now perform actions on successful sending.
899 (while mail-send-actions
900 (condition-case nil
901 (apply (car (car mail-send-actions))
902 (cdr (car mail-send-actions)))
903 (error))
904 (setq mail-send-actions (cdr mail-send-actions)))
905 (message "Sending...done")
906 ;; If buffer has no file, mark it as unmodified and delete auto-save.
907 (if (not buffer-file-name)
908 (progn
909 (set-buffer-modified-p nil)
910 (delete-auto-save-file-if-necessary t))))))
912 (defun mail-envelope-from ()
913 "Return the envelope mail address to use when sending mail.
914 This function uses `mail-envelope-from'."
915 (if (eq mail-envelope-from 'header)
916 (nth 1 (mail-extract-address-components
917 (mail-fetch-field "From")))
918 mail-envelope-from))
920 ;; This does the real work of sending a message via sendmail.
921 ;; It is called via the variable send-mail-function.
923 ;;;###autoload
924 (defvar sendmail-coding-system nil
925 "*Coding system for encoding the outgoing mail.
926 This has higher priority than `default-buffer-file-coding-system'
927 and `default-sendmail-coding-system',
928 but lower priority than the local value of `buffer-file-coding-system'.
929 See also the function `select-message-coding-system'.")
931 ;;;###autoload
932 (defvar default-sendmail-coding-system 'iso-latin-1
933 "Default coding system for encoding the outgoing mail.
934 This variable is used only when `sendmail-coding-system' is nil.
936 This variable is set/changed by the command `set-language-environment'.
937 User should not set this variable manually,
938 instead use `sendmail-coding-system' to get a constant encoding
939 of outgoing mails regardless of the current language environment.
940 See also the function `select-message-coding-system'.")
942 (defun mail-insert-from-field ()
943 (let* ((login user-mail-address)
944 (fullname (user-full-name))
945 (quote-fullname nil))
946 (if (string-match "[^\0-\177]" fullname)
947 (setq fullname (rfc2047-encode-string fullname)
948 quote-fullname t))
949 (cond ((eq mail-from-style 'angles)
950 (insert "From: " fullname)
951 (let ((fullname-start (+ (point-min) 6))
952 (fullname-end (point-marker)))
953 (goto-char fullname-start)
954 ;; Look for a character that cannot appear unquoted
955 ;; according to RFC 822.
956 (if (or (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]"
957 fullname-end 1)
958 quote-fullname)
959 (progn
960 ;; Quote fullname, escaping specials.
961 (goto-char fullname-start)
962 (insert "\"")
963 (while (re-search-forward "[\"\\]"
964 fullname-end 1)
965 (replace-match "\\\\\\&" t))
966 (insert "\""))))
967 (insert " <" login ">\n"))
968 ((eq mail-from-style 'parens)
969 (insert "From: " login " (")
970 (let ((fullname-start (point)))
971 (if quote-fullname
972 (insert "\""))
973 (insert fullname)
974 (if quote-fullname
975 (insert "\""))
976 (let ((fullname-end (point-marker)))
977 (goto-char fullname-start)
978 ;; RFC 822 says \ and nonmatching parentheses
979 ;; must be escaped in comments.
980 ;; Escape every instance of ()\ ...
981 (while (re-search-forward "[()\\]" fullname-end 1)
982 (replace-match "\\\\\\&" t))
983 ;; ... then undo escaping of matching parentheses,
984 ;; including matching nested parentheses.
985 (goto-char fullname-start)
986 (while (re-search-forward
987 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
988 fullname-end 1)
989 (replace-match "\\1(\\3)" t)
990 (goto-char fullname-start))))
991 (insert ")\n"))
992 ((null mail-from-style)
993 (insert "From: " login "\n"))
994 ((eq mail-from-style 'system-default)
995 nil)
996 (t (error "Invalid value for `mail-from-style'")))))
998 ;; Normally you will not need to modify these options unless you are
999 ;; using some non-genuine substitute for sendmail which does not
1000 ;; implement each and every option that the original supports.
1001 ;; E.g., ssmtp does not support "-odb", so, if your site uses it,
1002 ;; you will need to modify `sendmail-error-reporting-non-interactive'
1003 ;; in your site-init.el.
1004 (defvar sendmail-error-reporting-interactive
1005 ;; These mean "report errors to terminal" and "deliver interactively"
1006 '("-oep" "-odi"))
1007 (defvar sendmail-error-reporting-non-interactive
1008 ;; These mean "report errors by mail" and "deliver in background".
1009 '("-oem" "-odb"))
1011 (defun sendmail-send-it ()
1012 "Send the current mail buffer using the Sendmail package.
1013 This is a suitable value for `send-mail-function'. It sends using the
1014 external program defined by `sendmail-program'."
1015 (require 'mail-utils)
1016 (let ((errbuf (if mail-interactive
1017 (generate-new-buffer " sendmail errors")
1019 (tembuf (generate-new-buffer " sendmail temp"))
1020 (multibyte enable-multibyte-characters)
1021 (case-fold-search nil)
1022 (selected-coding (select-message-coding-system))
1023 resend-to-addresses
1024 delimline
1025 fcc-was-found
1026 (mailbuf (current-buffer))
1027 (program (if (boundp 'sendmail-program)
1028 sendmail-program
1029 "/usr/lib/sendmail"))
1030 ;; Examine these variables now, so that
1031 ;; local binding in the mail buffer will take effect.
1032 (envelope-from
1033 (and mail-specify-envelope-from
1034 (or (mail-envelope-from) user-mail-address))))
1035 (unwind-protect
1036 (with-current-buffer tembuf
1037 (erase-buffer)
1038 (unless multibyte
1039 (set-buffer-multibyte nil))
1040 (insert-buffer-substring mailbuf)
1041 (goto-char (point-max))
1042 ;; require one newline at the end.
1043 (or (= (preceding-char) ?\n)
1044 (insert ?\n))
1045 ;; Change header-delimiter to be what sendmail expects.
1046 (goto-char (mail-header-end))
1047 (delete-region (point) (progn (end-of-line) (point)))
1048 (setq delimline (point-marker))
1049 (sendmail-sync-aliases)
1050 (if mail-aliases
1051 (expand-mail-aliases (point-min) delimline))
1052 (goto-char (point-min))
1053 ;; Ignore any blank lines in the header
1054 (while (and (re-search-forward "\n\n\n*" delimline t)
1055 (< (point) delimline))
1056 (replace-match "\n"))
1057 (goto-char (point-min))
1058 ;; Look for Resent- headers. They require sending
1059 ;; the message specially.
1060 (let ((case-fold-search t))
1061 (goto-char (point-min))
1062 (while (re-search-forward "^Resent-\\(to\\|cc\\|bcc\\):" delimline t)
1063 ;; Put a list of such addresses in resend-to-addresses.
1064 (setq resend-to-addresses
1065 (save-restriction
1066 (narrow-to-region (point)
1067 (save-excursion
1068 (forward-line 1)
1069 (while (looking-at "^[ \t]")
1070 (forward-line 1))
1071 (point)))
1072 (append (mail-parse-comma-list)
1073 resend-to-addresses)))
1074 ;; Delete Resent-BCC ourselves
1075 (if (save-excursion (beginning-of-line)
1076 (looking-at "resent-bcc"))
1077 (delete-region (save-excursion (beginning-of-line) (point))
1078 (save-excursion (end-of-line) (1+ (point))))))
1079 ;;; Apparently this causes a duplicate Sender.
1080 ;;; ;; If the From is different than current user, insert Sender.
1081 ;;; (goto-char (point-min))
1082 ;;; (and (re-search-forward "^From:" delimline t)
1083 ;;; (progn
1084 ;;; (require 'mail-utils)
1085 ;;; (not (string-equal
1086 ;;; (mail-strip-quoted-names
1087 ;;; (save-restriction
1088 ;;; (narrow-to-region (point-min) delimline)
1089 ;;; (mail-fetch-field "From")))
1090 ;;; (user-login-name))))
1091 ;;; (progn
1092 ;;; (forward-line 1)
1093 ;;; (insert "Sender: " (user-login-name) "\n")))
1094 ;; Don't send out a blank subject line
1095 (goto-char (point-min))
1096 (if (re-search-forward "^Subject:\\([ \t]*\n\\)+\\b" delimline t)
1097 (replace-match "")
1098 ;; This one matches a Subject just before the header delimiter.
1099 (if (and (re-search-forward "^Subject:\\([ \t]*\n\\)+" delimline t)
1100 (= (match-end 0) delimline))
1101 (replace-match "")))
1102 ;; Put the "From:" field in unless for some odd reason
1103 ;; they put one in themselves.
1104 (goto-char (point-min))
1105 (if (not (re-search-forward "^From:" delimline t))
1106 (mail-insert-from-field))
1107 ;; Possibly add a MIME header for the current coding system
1108 (let (charset)
1109 (goto-char (point-min))
1110 (and (eq mail-send-nonascii 'mime)
1111 (not (re-search-forward "^MIME-version:" delimline t))
1112 (progn (skip-chars-forward "\0-\177")
1113 (/= (point) (point-max)))
1114 selected-coding
1115 (setq charset
1116 (coding-system-get selected-coding :mime-charset))
1117 (goto-char delimline)
1118 (insert "MIME-version: 1.0\n"
1119 "Content-type: text/plain; charset="
1120 (symbol-name charset)
1121 "\nContent-Transfer-Encoding: 8bit\n")))
1122 ;; Insert an extra newline if we need it to work around
1123 ;; Sun's bug that swallows newlines.
1124 (goto-char (1+ delimline))
1125 (if (eval mail-mailer-swallows-blank-line)
1126 (newline))
1127 ;; Find and handle any FCC fields.
1128 (goto-char (point-min))
1129 (if (re-search-forward "^FCC:" delimline t)
1130 (progn
1131 (setq fcc-was-found t)
1132 (mail-do-fcc delimline)))
1133 (if mail-interactive
1134 (with-current-buffer errbuf
1135 (erase-buffer))))
1136 (goto-char (point-min))
1137 (if (let ((case-fold-search t))
1138 (or resend-to-addresses
1139 (re-search-forward "^To:\\|^cc:\\|^bcc:"
1140 delimline t)))
1141 (let* ((default-directory "/")
1142 (coding-system-for-write selected-coding)
1143 (args
1144 (append (list (point-min) (point-max)
1145 program
1146 nil errbuf nil "-oi")
1147 (and envelope-from
1148 (list "-f" envelope-from))
1149 ;;; ;; Don't say "from root" if running under su.
1150 ;;; (and (equal (user-real-login-name) "root")
1151 ;;; (list "-f" (user-login-name)))
1152 (and mail-alias-file
1153 (list (concat "-oA" mail-alias-file)))
1154 (if mail-interactive
1155 sendmail-error-reporting-interactive
1156 sendmail-error-reporting-non-interactive)
1157 ;; Get the addresses from the message
1158 ;; unless this is a resend.
1159 ;; We must not do that for a resend
1160 ;; because we would find the original addresses.
1161 ;; For a resend, include the specific addresses.
1162 (or resend-to-addresses
1163 '("-t")
1165 (if mail-use-dsn
1166 (list "-N" (mapconcat 'symbol-name
1167 mail-use-dsn ",")))
1170 (exit-value (apply 'call-process-region args)))
1171 (or (null exit-value) (eq 0 exit-value)
1172 (error "Sending...failed with exit value %d" exit-value)))
1173 (or fcc-was-found
1174 (error "No recipients")))
1175 (if mail-interactive
1176 (with-current-buffer errbuf
1177 (goto-char (point-min))
1178 (while (re-search-forward "\n\n* *" nil t)
1179 (replace-match "; "))
1180 (if (not (zerop (buffer-size)))
1181 (error "Sending...failed to %s"
1182 (buffer-substring (point-min) (point-max)))))))
1183 (kill-buffer tembuf)
1184 (if (bufferp errbuf)
1185 (kill-buffer errbuf)))))
1187 (autoload 'rmail-output-to-rmail-buffer "rmailout")
1189 (defun mail-do-fcc (header-end)
1190 "Find and act on any FCC: headers in the current message before HEADER-END.
1191 If a buffer is visiting the FCC file, append to it before
1192 offering to save it, if it was modified initially. If this is an
1193 Rmail buffer, update Rmail as needed. If there is no buffer,
1194 just append to the file, in Babyl format if necessary."
1195 (unless (markerp header-end)
1196 (error "Value of `header-end' must be a marker"))
1197 (let (fcc-list
1198 (mailbuf (current-buffer))
1199 (time (current-time)))
1200 (save-excursion
1201 (goto-char (point-min))
1202 (let ((case-fold-search t))
1203 (while (re-search-forward "^FCC:[ \t]*" header-end t)
1204 (push (buffer-substring (point)
1205 (progn
1206 (end-of-line)
1207 (skip-chars-backward " \t")
1208 (point)))
1209 fcc-list)
1210 (delete-region (match-beginning 0)
1211 (progn (forward-line 1) (point)))))
1212 (with-temp-buffer
1213 ;; This initial newline is not written out if we create a new
1214 ;; file (see below).
1215 (insert "\nFrom " (user-login-name) " " (current-time-string time) "\n")
1216 ;; Insert the time zone before the year.
1217 (forward-char -1)
1218 (forward-word -1)
1219 (require 'mail-utils)
1220 (insert (mail-rfc822-time-zone time) " ")
1221 (goto-char (point-max))
1222 (insert-buffer-substring mailbuf)
1223 ;; Make sure messages are separated.
1224 (goto-char (point-max))
1225 (insert ?\n)
1226 (goto-char 2)
1227 ;; ``Quote'' "^From " as ">From "
1228 ;; (note that this isn't really quoting, as there is no requirement
1229 ;; that "^[>]+From " be quoted in the same transparent way.)
1230 (let ((case-fold-search nil))
1231 (while (search-forward "\nFrom " nil t)
1232 (forward-char -5)
1233 (insert ?>)))
1234 (dolist (fcc fcc-list)
1235 (let* ((buffer (find-buffer-visiting fcc))
1236 (curbuf (current-buffer))
1237 dont-write-the-file
1238 buffer-matches-file
1239 (beg (point-min)) ; the initial blank line
1240 (end (point-max))
1241 ;; After the ^From line.
1242 (beg2 (save-excursion (goto-char (point-min))
1243 (forward-line 2) (point))))
1244 (if buffer
1245 ;; File is present in a buffer => append to that buffer.
1246 (with-current-buffer buffer
1247 (setq buffer-matches-file
1248 (and (not (buffer-modified-p))
1249 (verify-visited-file-modtime buffer)))
1250 (let ((msg (bound-and-true-p rmail-current-message))
1251 (buffer-read-only nil))
1252 ;; If MSG is non-nil, buffer is in Rmail mode.
1253 (if msg
1254 (let ((buff (generate-new-buffer " *mail-do-fcc")))
1255 (unwind-protect
1256 (progn
1257 (with-current-buffer buff
1258 (insert-buffer-substring curbuf (1+ beg) end))
1259 (rmail-output-to-rmail-buffer buff msg))
1260 (kill-buffer buff)))
1261 ;; Output file not in Rmail mode => just insert
1262 ;; at the end.
1263 (save-restriction
1264 (widen)
1265 (goto-char (point-max))
1266 (insert-buffer-substring curbuf beg end)))
1267 ;; Offer to save the buffer if it was modified
1268 ;; before we started.
1269 (unless buffer-matches-file
1270 (if (y-or-n-p (format "Save file %s? " fcc))
1271 (save-buffer))
1272 (setq dont-write-the-file t)))))
1273 ;; Append to the file directly, unless we've already taken
1274 ;; care of it.
1275 (unless dont-write-the-file
1276 (if (and (file-exists-p fcc)
1277 (mail-file-babyl-p fcc))
1278 ;; If the file is a Babyl file, convert the message to
1279 ;; Babyl format. Even though Rmail no longer uses
1280 ;; Babyl, this code can remain for the time being, on
1281 ;; the off-chance one FCCs to a Babyl file that has
1282 ;; not yet been converted to mbox.
1283 (let ((coding-system-for-write
1284 (or rmail-file-coding-system 'emacs-mule)))
1285 (with-temp-buffer
1286 (insert "\C-l\n0, unseen,,\n*** EOOH ***\nDate: "
1287 (mail-rfc822-date) "\n")
1288 (insert-buffer-substring curbuf beg2 end)
1289 (insert "\n\C-_")
1290 (write-region (point-min) (point-max) fcc t)))
1291 ;; Ensure there is a blank line between messages, but
1292 ;; not at the very start of the file.
1293 (write-region (if (file-exists-p fcc)
1294 (point-min)
1295 (1+ (point-min)))
1296 (point-max) fcc t)))
1297 (and buffer (not dont-write-the-file)
1298 (with-current-buffer buffer
1299 (set-visited-file-modtime)))))))))
1301 (defun mail-sent-via ()
1302 "Make a Sent-via header line from each To or CC header line."
1303 (interactive)
1304 (save-excursion
1305 ;; put a marker at the end of the header
1306 (let ((end (copy-marker (mail-header-end)))
1307 (case-fold-search t))
1308 (goto-char (point-min))
1309 ;; search for the To: lines and make Sent-via: lines from them
1310 ;; search for the next To: line
1311 (while (re-search-forward "^\\(to\\|cc\\):" end t)
1312 ;; Grab this line plus all its continuations, sans the `to:'.
1313 (let ((to-line
1314 (buffer-substring (point)
1315 (progn
1316 (if (re-search-forward "^[^ \t\n]" end t)
1317 (backward-char 1)
1318 (goto-char end))
1319 (point)))))
1320 ;; Insert a copy, with altered header field name.
1321 (insert-before-markers "Sent-via:" to-line))))))
1323 (defun mail-to ()
1324 "Move point to end of To-field."
1325 (interactive)
1326 (expand-abbrev)
1327 (mail-position-on-field "To"))
1329 (defun mail-subject ()
1330 "Move point to end of Subject-field."
1331 (interactive)
1332 (expand-abbrev)
1333 (mail-position-on-field "Subject"))
1335 (defun mail-cc ()
1336 "Move point to end of CC-field. Create a CC field if none."
1337 (interactive)
1338 (expand-abbrev)
1339 (or (mail-position-on-field "cc" t)
1340 (progn (mail-position-on-field "to")
1341 (insert "\nCC: "))))
1343 (defun mail-bcc ()
1344 "Move point to end of BCC-field. Create a BCC field if none."
1345 (interactive)
1346 (expand-abbrev)
1347 (or (mail-position-on-field "bcc" t)
1348 (progn (mail-position-on-field "to")
1349 (insert "\nBCC: "))))
1351 (defun mail-fcc (folder)
1352 "Add a new FCC field, with file name completion."
1353 (interactive "FFolder carbon copy: ")
1354 (expand-abbrev)
1355 (or (mail-position-on-field "fcc" t) ;Put new field after exiting FCC.
1356 (mail-position-on-field "to"))
1357 (insert "\nFCC: " folder))
1359 (defun mail-reply-to ()
1360 "Move point to end of Reply-To-field. Create a Reply-To field if none."
1361 (interactive)
1362 (expand-abbrev)
1363 (mail-position-on-field "Reply-To"))
1365 (defun mail-mail-reply-to ()
1366 "Move point to end of Mail-Reply-To field.
1367 Create a Mail-Reply-To field if none."
1368 (interactive)
1369 (expand-abbrev)
1370 (or (mail-position-on-field "mail-reply-to" t)
1371 (progn (mail-position-on-field "to")
1372 (insert "\nMail-Reply-To: "))))
1374 (defun mail-mail-followup-to ()
1375 "Move point to end of Mail-Followup-To field.
1376 Create a Mail-Followup-To field if none."
1377 (interactive)
1378 (expand-abbrev)
1379 (or (mail-position-on-field "mail-followup-to" t)
1380 (progn (mail-position-on-field "to")
1381 (insert "\nMail-Followup-To: "))))
1383 (defun mail-position-on-field (field &optional soft)
1384 (let (end
1385 (case-fold-search t))
1386 (setq end (mail-header-end))
1387 (goto-char (point-min))
1388 (if (re-search-forward (concat "^" (regexp-quote field) ":") end t)
1389 (progn
1390 (re-search-forward "^[^ \t]" nil 'move)
1391 (beginning-of-line)
1392 (skip-chars-backward "\n")
1394 (or soft
1395 (progn (goto-char end)
1396 (insert field ": \n")
1397 (skip-chars-backward "\n")))
1398 nil)))
1400 (defun mail-text ()
1401 "Move point to beginning of text field."
1402 (interactive)
1403 (expand-abbrev)
1404 (goto-char (mail-text-start)))
1406 (defun mail-signature (&optional atpoint)
1407 "Sign letter with signature based on `mail-signature-file'.
1408 Prefix arg means put contents at point."
1409 (interactive "P")
1410 (save-excursion
1411 (or atpoint
1412 (goto-char (point-max)))
1413 (skip-chars-backward " \t\n")
1414 (end-of-line)
1415 (or atpoint
1416 (delete-region (point) (point-max)))
1417 (if (stringp mail-signature)
1418 (insert mail-signature)
1419 (insert "\n\n-- \n")
1420 (insert-file-contents (expand-file-name mail-signature-file)))))
1422 (defun mail-fill-yanked-message (&optional justifyp)
1423 "Fill the paragraphs of a message yanked into this one.
1424 Numeric argument means justify as well."
1425 (interactive "P")
1426 (save-excursion
1427 (goto-char (mail-text-start))
1428 (fill-individual-paragraphs (point)
1429 (point-max)
1430 justifyp
1431 mail-citation-prefix-regexp)))
1433 (defun mail-indent-citation ()
1434 "Modify text just inserted from a message to be cited.
1435 The inserted text should be the region.
1436 When this function returns, the region is again around the modified text.
1438 Normally, indent each nonblank line `mail-indentation-spaces' spaces.
1439 However, if `mail-yank-prefix' is non-nil, insert that prefix on each line."
1440 (mail-yank-clear-headers (region-beginning) (region-end))
1441 (if (null mail-yank-prefix)
1442 (indent-rigidly (region-beginning) (region-end)
1443 mail-indentation-spaces)
1444 (save-excursion
1445 (let ((end (set-marker (make-marker) (region-end))))
1446 (goto-char (region-beginning))
1447 (while (< (point) end)
1448 (insert mail-yank-prefix)
1449 (forward-line 1))))))
1451 (defun mail-yank-original (arg)
1452 "Insert the message being replied to, if any (in Rmail).
1453 Puts point after the text and mark before.
1454 Normally, indents each nonblank line ARG spaces (default 3).
1455 However, if `mail-yank-prefix' is non-nil, insert that prefix on each line.
1457 Just \\[universal-argument] as argument means don't indent, insert no prefix,
1458 and don't delete any header fields."
1459 (interactive "P")
1460 (if mail-reply-action
1461 (let ((start (point))
1462 (original mail-reply-action))
1463 (and (consp original) (eq (car original) 'insert-buffer)
1464 (setq original (nth 1 original)))
1465 (if (consp original)
1466 (apply (car original) (cdr original))
1467 ;; If the original message is in another window in the same frame,
1468 ;; delete that window to save screen space.
1469 ;; t means don't alter other frames.
1470 (delete-windows-on original t)
1471 (with-no-warnings
1472 ;; We really want this to set mark.
1473 (insert-buffer original))
1474 (set-text-properties (point) (mark t) nil))
1475 (if (consp arg)
1477 (goto-char start)
1478 (let ((mail-indentation-spaces (if arg (prefix-numeric-value arg)
1479 mail-indentation-spaces))
1480 ;; Avoid error in Transient Mark mode
1481 ;; on account of mark's being inactive.
1482 (mark-even-if-inactive t))
1483 (cond (mail-citation-hook
1484 ;; Bind mail-citation-header to the inserted
1485 ;; message's header.
1486 (let ((mail-citation-header
1487 (buffer-substring-no-properties
1488 start
1489 (save-excursion
1490 (save-restriction
1491 (narrow-to-region start (point-max))
1492 (goto-char start)
1493 (rfc822-goto-eoh)
1494 (point))))))
1495 (run-hooks 'mail-citation-hook)))
1496 (mail-yank-hooks
1497 (run-hooks 'mail-yank-hooks))
1499 (mail-indent-citation)))))
1500 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
1501 ;; It is cleaner to avoid activation, even though the command
1502 ;; loop would deactivate the mark because we inserted text.
1503 (goto-char (prog1 (mark t)
1504 (set-marker (mark-marker) (point) (current-buffer))))
1505 (if (not (eolp)) (insert ?\n)))))
1507 (defun mail-yank-clear-headers (start end)
1508 (if (< end start)
1509 (let (temp)
1510 (setq temp start start end end temp)))
1511 (if mail-yank-ignored-headers
1512 (save-excursion
1513 (goto-char start)
1514 (if (search-forward "\n\n" end t)
1515 (save-restriction
1516 (narrow-to-region start (point))
1517 (goto-char start)
1518 (while (let ((case-fold-search t))
1519 (re-search-forward mail-yank-ignored-headers nil t))
1520 (beginning-of-line)
1521 (delete-region (point)
1522 (progn (re-search-forward "\n[^ \t]")
1523 (forward-char -1)
1524 (point)))))))))
1526 (defun mail-yank-region (arg)
1527 "Insert the selected region from the message being replied to.
1528 Puts point after the text and mark before.
1529 Normally, indents each nonblank line ARG spaces (default 3).
1530 However, if `mail-yank-prefix' is non-nil, insert that prefix on each line.
1532 Just \\[universal-argument] as argument means don't indent, insert no prefix,
1533 and don't delete any header fields."
1534 (interactive "P")
1535 (and (consp mail-reply-action)
1536 (eq (car mail-reply-action) 'insert-buffer)
1537 (with-current-buffer (nth 1 mail-reply-action)
1538 (or (mark t)
1539 (error "No mark set: %S" (current-buffer))))
1540 (let ((buffer (nth 1 mail-reply-action))
1541 (start (point))
1542 ;; Avoid error in Transient Mark mode
1543 ;; on account of mark's being inactive.
1544 (mark-even-if-inactive t))
1545 ;; Insert the citation text.
1546 (insert (with-current-buffer buffer
1547 (buffer-substring-no-properties (point) (mark))))
1548 (push-mark start)
1549 ;; Indent or otherwise annotate the citation text.
1550 (if (consp arg)
1552 (let ((mail-indentation-spaces (if arg (prefix-numeric-value arg)
1553 mail-indentation-spaces)))
1554 (if mail-citation-hook
1555 ;; Bind mail-citation-header to the original message's header.
1556 (let ((mail-citation-header
1557 (with-current-buffer buffer
1558 (buffer-substring-no-properties
1559 (point-min)
1560 (save-excursion
1561 (goto-char (point-min))
1562 (rfc822-goto-eoh)
1563 (point))))))
1564 (run-hooks 'mail-citation-hook))
1565 (if mail-yank-hooks
1566 (run-hooks 'mail-yank-hooks)
1567 (mail-indent-citation))))))))
1569 (defun mail-split-line ()
1570 "Split current line, moving portion beyond point vertically down.
1571 If the current line has `mail-yank-prefix', insert it on the new line."
1572 (interactive "*")
1573 (split-line mail-yank-prefix))
1576 (defun mail-attach-file (&optional file)
1577 "Insert a file at the end of the buffer, with separator lines around it."
1578 (interactive "fAttach file: ")
1579 (save-excursion
1580 (goto-char (point-max))
1581 (or (bolp) (newline))
1582 (newline)
1583 (let ((start (point))
1584 middle)
1585 (insert (format "===File %s===" file))
1586 (insert-char ?= (max 0 (- 60 (current-column))))
1587 (newline)
1588 (setq middle (point))
1589 (insert "============================================================\n")
1590 (push-mark)
1591 (goto-char middle)
1592 (insert-file-contents file)
1593 (or (bolp) (newline))
1594 (goto-char start))))
1596 ;; Put these commands last, to reduce chance of lossage from quitting
1597 ;; in middle of loading the file.
1599 ;;;###autoload (add-hook 'same-window-buffer-names "*mail*")
1601 ;;;###autoload
1602 (defun mail (&optional noerase to subject in-reply-to cc replybuffer actions)
1603 "Edit a message to be sent. Prefix arg means resume editing (don't erase).
1604 When this function returns, the buffer `*mail*' is selected.
1605 The value is t if the message was newly initialized; otherwise, nil.
1607 Optionally, the signature file `mail-signature-file' can be inserted at the
1608 end; see the variable `mail-signature'.
1610 \\<mail-mode-map>
1611 While editing message, type \\[mail-send-and-exit] to send the message and exit.
1613 Various special commands starting with C-c are available in sendmail mode
1614 to move to message header fields:
1615 \\{mail-mode-map}
1617 If `mail-self-blind' is non-nil, a BCC to yourself is inserted
1618 when the message is initialized.
1620 If `mail-default-reply-to' is non-nil, it should be an address (a string);
1621 a Reply-to: field with that address is inserted.
1623 If `mail-archive-file-name' is non-nil, an FCC field with that file name
1624 is inserted.
1626 The normal hook `mail-setup-hook' is run after the message is
1627 initialized. It can add more default fields to the message.
1629 The first argument, NOERASE, determines what to do when there is
1630 an existing modified `*mail*' buffer. If NOERASE is nil, the
1631 existing mail buffer is used, and the user is prompted whether to
1632 keep the old contents or to erase them. If NOERASE has the value
1633 `new', a new mail buffer will be created instead of using the old
1634 one. Any other non-nil value means to always select the old
1635 buffer without erasing the contents.
1637 The second through fifth arguments,
1638 TO, SUBJECT, IN-REPLY-TO and CC, specify if non-nil
1639 the initial contents of those header fields.
1640 These arguments should not have final newlines.
1641 The sixth argument REPLYBUFFER is a buffer which contains an
1642 original message being replied to, or else an action
1643 of the form (FUNCTION . ARGS) which says how to insert the original.
1644 Or it can be nil, if not replying to anything.
1645 The seventh argument ACTIONS is a list of actions to take
1646 if/when the message is sent. Each action looks like (FUNCTION . ARGS);
1647 when the message is sent, we apply FUNCTION to ARGS.
1648 This is how Rmail arranges to mark messages `answered'."
1649 (interactive "P")
1650 ;;; This is commented out because I found it was confusing in practice.
1651 ;;; It is easy enough to rename *mail* by hand with rename-buffer
1652 ;;; if you want to have multiple mail buffers.
1653 ;;; And then you can control which messages to save. --rms.
1654 ;;; (let ((index 1)
1655 ;;; buffer)
1656 ;;; ;; If requested, look for a mail buffer that is modified and go to it.
1657 ;;; (if noerase
1658 ;;; (progn
1659 ;;; (while (and (setq buffer
1660 ;;; (get-buffer (if (= 1 index) "*mail*"
1661 ;;; (format "*mail*<%d>" index))))
1662 ;;; (not (buffer-modified-p buffer)))
1663 ;;; (setq index (1+ index)))
1664 ;;; (if buffer (switch-to-buffer buffer)
1665 ;;; ;; If none exists, start a new message.
1666 ;;; ;; This will never re-use an existing unmodified mail buffer
1667 ;;; ;; (since index is not 1 anymore). Perhaps it should.
1668 ;;; (setq noerase nil))))
1669 ;;; ;; Unless we found a modified message and are happy, start a new message.
1670 ;;; (if (not noerase)
1671 ;;; (progn
1672 ;;; ;; Look for existing unmodified mail buffer.
1673 ;;; (while (and (setq buffer
1674 ;;; (get-buffer (if (= 1 index) "*mail*"
1675 ;;; (format "*mail*<%d>" index))))
1676 ;;; (buffer-modified-p buffer))
1677 ;;; (setq index (1+ index)))
1678 ;;; ;; If none, make a new one.
1679 ;;; (or buffer
1680 ;;; (setq buffer (generate-new-buffer "*mail*")))
1681 ;;; ;; Go there and initialize it.
1682 ;;; (switch-to-buffer buffer)
1683 ;;; (erase-buffer)
1684 ;;; (setq default-directory (expand-file-name "~/"))
1685 ;;; (auto-save-mode auto-save-default)
1686 ;;; (mail-mode)
1687 ;;; (mail-setup to subject in-reply-to cc replybuffer actions)
1688 ;;; (if (and buffer-auto-save-file-name
1689 ;;; (file-exists-p buffer-auto-save-file-name))
1690 ;;; (message "Auto save file for draft message exists; consider M-x mail-recover"))
1691 ;;; t))
1693 (if (eq noerase 'new)
1694 (pop-to-buffer (generate-new-buffer "*mail*"))
1695 (and noerase
1696 (not (get-buffer "*mail*"))
1697 (setq noerase nil))
1698 (pop-to-buffer "*mail*"))
1700 ;; Avoid danger that the auto-save file can't be written.
1701 (let ((dir (expand-file-name
1702 (file-name-as-directory mail-default-directory))))
1703 (if (file-exists-p dir)
1704 (setq default-directory dir)))
1705 ;; Only call auto-save-mode if necessary, to avoid changing auto-save file.
1706 (if (or (and auto-save-default (not buffer-auto-save-file-name))
1707 (and (not auto-save-default) buffer-auto-save-file-name))
1708 (auto-save-mode auto-save-default))
1709 (mail-mode)
1710 ;; Disconnect the buffer from its visited file
1711 ;; (in case the user has actually visited a file *mail*).
1712 ;;; (set-visited-file-name nil)
1713 (let (initialized)
1714 (and (not (and noerase
1715 (not (eq noerase 'new))))
1716 (if buffer-file-name
1717 (if (buffer-modified-p)
1718 (when (y-or-n-p "Buffer has unsaved changes; reinitialize it and discard them? ")
1719 (if (y-or-n-p "Disconnect buffer from visited file? ")
1720 (set-visited-file-name nil))
1722 (when (y-or-n-p "Reinitialize buffer, and disconnect it from the visited file? ")
1723 (set-visited-file-name nil)
1725 ;; A non-file-visiting buffer.
1726 (if (buffer-modified-p)
1727 (y-or-n-p "Unsent message being composed; erase it? ")
1729 (let ((inhibit-read-only t))
1730 (erase-buffer)
1731 (mail-setup to subject in-reply-to cc replybuffer actions)
1732 (setq initialized t)))
1733 (if (and buffer-auto-save-file-name
1734 (file-exists-p buffer-auto-save-file-name))
1735 (message "Auto save file for draft message exists; consider M-x mail-recover"))
1736 initialized))
1738 (declare-function dired-view-file "dired" ())
1739 (declare-function dired-get-filename "dired" (&optional localp no-error-if-not-filep))
1741 (defun mail-recover-1 ()
1742 "Pop up a list of auto-saved draft messages so you can recover one of them."
1743 (interactive)
1744 (let ((file-name (make-auto-save-file-name))
1745 (ls-lisp-support-shell-wildcards t)
1746 non-random-len wildcard)
1747 ;; Remove the random part from the auto-save-file-name, and
1748 ;; create a wildcard which matches possible candidates.
1749 ;; Note: this knows that make-auto-save-file-name appends
1750 ;; "#<RANDOM-STUFF>#" to the buffer name, where RANDOM-STUFF
1751 ;; is the result of (make-temp-name "").
1752 (setq non-random-len
1753 (- (length file-name) (length (make-temp-name "")) 1))
1754 (setq wildcard (concat (substring file-name 0 non-random-len) "*"))
1755 (if (null (file-expand-wildcards wildcard))
1756 (message "There are no auto-saved drafts to recover")
1757 ;; Bind dired-trivial-filenames to t because all auto-save file
1758 ;; names are normally ``trivial'', so Dired will set point after
1759 ;; all the files, at buffer bottom. We want it on the first
1760 ;; file instead.
1761 (let ((dired-trivial-filenames t))
1762 (dired-other-window wildcard (concat dired-listing-switches "t")))
1763 (rename-buffer "*Auto-saved Drafts*" t)
1764 (save-excursion
1765 (goto-char (point-min))
1766 (or (looking-at " Move to the draft file you want to recover,")
1767 (let ((inhibit-read-only t))
1768 ;; Each line starts with a space so that Font Lock mode
1769 ;; won't highlight the first character.
1770 (insert "\
1771 Move to the draft file you want to recover, then type C-c C-c
1772 to recover text of message whose composition was interrupted.
1773 To browse text of a draft, type v on the draft file's line.
1775 You can also delete some of these files;
1776 type d on a line to mark that file for deletion.
1778 List of possible auto-save files for recovery:
1780 "))))
1781 (use-local-map
1782 (let ((map (make-sparse-keymap)))
1783 (set-keymap-parent map (current-local-map))
1784 map))
1785 (define-key (current-local-map) "v"
1786 (lambda ()
1787 (interactive)
1788 (let ((coding-system-for-read 'utf-8-emacs-unix))
1789 (dired-view-file))))
1790 (define-key (current-local-map) "\C-c\C-c"
1791 (lambda ()
1792 (interactive)
1793 (let ((fname (dired-get-filename))
1794 ;; Auto-saved files are written in the internal
1795 ;; representation, so they should be read accordingly.
1796 (coding-system-for-read 'utf-8-emacs-unix))
1797 (switch-to-buffer-other-window "*mail*")
1798 (let ((buffer-read-only nil))
1799 (erase-buffer)
1800 (insert-file-contents fname nil)
1801 ;; insert-file-contents will set buffer-file-coding-system
1802 ;; to utf-8-emacs, which is probably not what they want to
1803 ;; use for sending the message. But we don't know what
1804 ;; was its value before the buffer was killed or Emacs
1805 ;; crashed. We therefore reset buffer-file-coding-system
1806 ;; to the default value, so that either the default does
1807 ;; TRT, or the user will get prompted for the right
1808 ;; encoding when they send the message.
1809 (setq buffer-file-coding-system
1810 default-buffer-file-coding-system))))))))
1812 (declare-function dired-move-to-filename "dired" (&optional raise-error eol))
1813 (declare-function dired-get-filename "dired" (&optional localp no-error-if-not-filep))
1814 (declare-function dired-view-file "dired" ())
1816 (defun mail-recover ()
1817 "Recover interrupted mail composition from auto-save files.
1819 If the mail buffer has a current valid auto-save file,
1820 the command recovers that file. Otherwise, it displays a
1821 buffer showing the existing auto-saved draft messages;
1822 you can move to one of them and type C-c C-c to recover that one."
1823 (interactive)
1824 ;; In case they invoke us from some random buffer...
1825 (switch-to-buffer "*mail*")
1826 ;; If *mail* didn't exist, set its directory, so that auto-saved
1827 ;; drafts will be found.
1828 (let ((dir (expand-file-name
1829 (file-name-as-directory mail-default-directory))))
1830 (if (file-exists-p dir)
1831 (setq default-directory dir)))
1832 (or (eq major-mode 'mail-mode)
1833 (mail-mode))
1834 (let ((file-name buffer-auto-save-file-name))
1835 (cond ((and file-name (file-exists-p file-name))
1836 (let ((dispbuf
1837 ;; This used to invoke `ls' via call-process, but
1838 ;; dired-noselect is more portable to systems where
1839 ;; `ls' is not a standard program (it will use
1840 ;; ls-lisp instead).
1841 (dired-noselect file-name
1842 (concat dired-listing-switches "t"))))
1843 (save-selected-window
1844 (select-window (display-buffer dispbuf t))
1845 (goto-char (point-min))
1846 (forward-line 2)
1847 (dired-move-to-filename)
1848 (setq dispbuf (rename-buffer "*Directory*" t)))
1849 (if (not (yes-or-no-p
1850 (format "Recover mail draft from auto save file %s? "
1851 file-name)))
1852 (error "mail-recover cancelled")
1853 (let ((buffer-read-only nil)
1854 (buffer-coding buffer-file-coding-system)
1855 ;; Auto-save files are written in internal
1856 ;; representation of non-ASCII characters.
1857 (coding-system-for-read 'utf-8-emacs-unix))
1858 (erase-buffer)
1859 (insert-file-contents file-name nil)
1860 (setq buffer-file-coding-system buffer-coding)))))
1861 (t (mail-recover-1)))))
1863 ;;;###autoload
1864 (defun mail-other-window (&optional noerase to subject in-reply-to cc replybuffer sendactions)
1865 "Like `mail' command, but display mail buffer in another window."
1866 (interactive "P")
1867 (let ((pop-up-windows t)
1868 (special-display-buffer-names nil)
1869 (special-display-regexps nil)
1870 (same-window-buffer-names nil)
1871 (same-window-regexps nil))
1872 (pop-to-buffer "*mail*"))
1873 (mail noerase to subject in-reply-to cc replybuffer sendactions))
1875 ;;;###autoload
1876 (defun mail-other-frame (&optional noerase to subject in-reply-to cc replybuffer sendactions)
1877 "Like `mail' command, but display mail buffer in another frame."
1878 (interactive "P")
1879 (let ((pop-up-frames t)
1880 (special-display-buffer-names nil)
1881 (special-display-regexps nil)
1882 (same-window-buffer-names nil)
1883 (same-window-regexps nil))
1884 (pop-to-buffer "*mail*"))
1885 (mail noerase to subject in-reply-to cc replybuffer sendactions))
1887 ;; Do not add anything but external entries on this page.
1889 (provide 'sendmail)
1891 ;; arch-tag: 48bc1025-d993-4d31-8d81-2a29491f0626
1892 ;;; sendmail.el ends here