Fix previous rmail-output-read-file-name change
[bpt/emacs.git] / lisp / mail / rmailout.el
1 ;;; rmailout.el --- "RMAIL" mail reader for Emacs: output message to a file
2
3 ;; Copyright (C) 1985, 1987, 1993-1994, 2001-2012
4 ;; Free Software Foundation, Inc.
5
6 ;; Maintainer: FSF
7 ;; Keywords: mail
8 ;; Package: rmail
9
10 ;; This file is part of GNU Emacs.
11
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.
16
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.
21
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/>.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (require 'rmail)
30 (provide 'rmailout)
31
32 (defcustom rmail-output-decode-coding nil
33 "If non-nil, do coding system decoding when outputting message as Babyl."
34 :type 'boolean
35 :group 'rmail-output)
36
37 (defcustom rmail-output-file-alist nil
38 "Alist matching regexps to suggested output Rmail files.
39 This is a list of elements of the form (REGEXP . NAME-EXP).
40 The suggestion is taken if REGEXP matches anywhere in the message buffer.
41 NAME-EXP may be a string constant giving the file name to use,
42 or more generally it may be any kind of expression that returns
43 a file name as a string."
44 :type '(repeat (cons regexp
45 (choice :value ""
46 (string :tag "File Name")
47 sexp)))
48 :group 'rmail-output)
49 ;; This is risky because NAME-EXP gets evalled.
50 ;;;###autoload(put 'rmail-output-file-alist 'risky-local-variable t)
51
52 (defcustom rmail-fields-not-to-output nil
53 "Regexp describing fields to exclude when outputting a message to a file.
54 The function `rmail-delete-unwanted-fields' uses this, ignoring case."
55 :type '(choice (const :tag "None" nil)
56 regexp)
57 :group 'rmail-output)
58
59 (defun rmail-output-read-file-name ()
60 "Read the file name to use for `rmail-output'.
61 Set `rmail-default-file' to this name as well as returning it.
62 This uses `rmail-output-file-alist'."
63 (let* ((default-file
64 (or
65 (when rmail-output-file-alist
66 (or rmail-buffer (error "There is no Rmail buffer"))
67 (save-current-buffer
68 (set-buffer rmail-buffer)
69 (let ((beg (rmail-msgbeg rmail-current-message))
70 (end (rmail-msgend rmail-current-message)))
71 (if (rmail-buffers-swapped-p) (set-buffer rmail-view-buffer))
72 (save-excursion
73 (save-restriction
74 (widen)
75 (narrow-to-region beg end)
76 (let ((tail rmail-output-file-alist)
77 answer)
78 ;; Suggest a file based on a pattern match.
79 (while (and tail (not answer))
80 (goto-char (point-min))
81 (if (re-search-forward (caar tail) nil t)
82 ;; FIXME trap and report any errors.
83 (setq answer (eval (cdar tail))))
84 (setq tail (cdr tail)))
85 answer))))))
86 ;; If no suggestion, use same file as last time.
87 rmail-default-file))
88 (read-file
89 (expand-file-name
90 (read-file-name
91 (concat "Output message to mail file (default "
92 (file-name-nondirectory default-file)
93 "): ")
94 (file-name-directory default-file)
95 (abbreviate-file-name default-file))
96 (file-name-directory default-file))))
97 (setq rmail-default-file
98 (if (file-directory-p read-file)
99 (expand-file-name (file-name-nondirectory default-file)
100 read-file)
101 (expand-file-name
102 (or read-file (file-name-nondirectory default-file))
103 (file-name-directory default-file))))))
104
105 (defun rmail-delete-unwanted-fields (preserve)
106 "Delete all headers matching `rmail-fields-not-to-output'.
107 Retains headers matching the regexp PRESERVE. Ignores case.
108 The buffer should be narrowed to just the header."
109 (if rmail-fields-not-to-output
110 (save-excursion
111 (goto-char (point-min))
112 (let ((case-fold-search t))
113 (while (re-search-forward rmail-fields-not-to-output nil t)
114 (beginning-of-line)
115 (unless (looking-at preserve)
116 (delete-region (point) (line-beginning-position 2))))))))
117 \f
118 (defun rmail-output-as-babyl (file-name nomsg)
119 "Convert the current buffer's text to Babyl and output to FILE-NAME.
120 Alters the current buffer's text, so it should be a temporary buffer.
121 If a buffer is visiting FILE-NAME, adds the text to that buffer
122 rather than saving the file directly. If the buffer is an Rmail buffer,
123 updates it accordingly. If no buffer is visiting FILE-NAME, appends
124 the text directly to FILE-NAME, and displays a \"Wrote file\" message
125 unless NOMSG is a symbol (neither nil nor t)."
126 (let ((coding-system-for-write 'emacs-mule-unix))
127 (save-restriction
128 (goto-char (point-min))
129 (search-forward "\n\n" nil 'move)
130 (narrow-to-region (point-min) (point))
131 (if rmail-fields-not-to-output
132 (rmail-delete-unwanted-fields nil)))
133
134 ;; Convert to Babyl format.
135 (rmail-convert-to-babyl-format)
136 ;; Write it into the file, or its buffer.
137 (let ((buf (find-buffer-visiting file-name))
138 (tembuf (current-buffer)))
139 (if (null buf)
140 (write-region (point-min) (point-max) file-name t nomsg)
141 (if (eq buf (current-buffer))
142 (error "Can't output message to same file it's already in"))
143 ;; File has been visited, in buffer BUF.
144 (set-buffer buf)
145 (let ((inhibit-read-only t)
146 (msg (bound-and-true-p rmail-current-message)))
147 ;; If MSG is non-nil, buffer is in RMAIL mode.
148 (if msg
149 (rmail-output-to-babyl-buffer tembuf msg)
150 ;; Output file not in rmail mode => just insert at the end.
151 (narrow-to-region (point-min) (1+ (buffer-size)))
152 (goto-char (point-max))
153 (insert-buffer-substring tembuf)))))))
154
155 ;; Called only if rmail-summary-exists, which means rmailsum is loaded.
156 (declare-function rmail-update-summary "rmailsum" (&rest ignore))
157
158 (defun rmail-output-to-babyl-buffer (tembuf msg)
159 "Copy message in TEMBUF into the current Babyl Rmail buffer.
160 Do what is necessary to make Rmail know about the new message, then
161 display message number MSG."
162 ;; Turn on Auto Save mode, if it's off in this buffer but enabled by default.
163 (and (not buffer-auto-save-file-name)
164 auto-save-default
165 (auto-save-mode t))
166 (rmail-maybe-set-message-counters)
167 (widen)
168 (narrow-to-region (point-max) (point-max))
169 (insert-buffer-substring tembuf)
170 (goto-char (point-min))
171 (widen)
172 (search-backward "\n\^_")
173 (narrow-to-region (point) (point-max))
174 (rmail-count-new-messages t)
175 (if (rmail-summary-exists)
176 (rmail-select-summary (rmail-update-summary)))
177 (rmail-show-message-1 msg))
178 \f
179 (defun rmail-convert-to-babyl-format ()
180 "Convert the mbox message in the current buffer to Babyl format."
181 (let ((count 0) (start (point-min))
182 (case-fold-search nil)
183 (buffer-undo-list t))
184 (goto-char (point-min))
185 (save-restriction
186 (unless (looking-at "^From ")
187 (error "Invalid mbox message"))
188 (insert "\^L\n0,,\n*** EOOH ***\n")
189 (rmail-nuke-pinhead-header)
190 ;; Decode base64 or quoted printable contents, Rmail style.
191 (let* ((header-end (save-excursion
192 (and (re-search-forward "\n\n" nil t)
193 (1- (point)))))
194 (case-fold-search t)
195 (quoted-printable-header-field-end
196 (save-excursion
197 (re-search-forward
198 "^content-transfer-encoding:\\(\n?[\t ]\\)*quoted-printable\\(\n?[\t ]\\)*"
199 header-end t)))
200 (base64-header-field-end
201 (and
202 ;; Don't decode non-text data.
203 (save-excursion
204 (re-search-forward
205 "^content-type:\\(\n?[\t ]\\)\\(text\\|message\\)/"
206 header-end t))
207 (save-excursion
208 (re-search-forward
209 "^content-transfer-encoding:\\(\n?[\t ]\\)*base64\\(\n?[\t ]\\)*"
210 header-end t)))))
211
212 (goto-char (point-max))
213 (if quoted-printable-header-field-end
214 (save-excursion
215 (unless (mail-unquote-printable-region
216 header-end (point) nil t t)
217 (message "Malformed MIME quoted-printable message"))
218 ;; Change "quoted-printable" to "8bit",
219 ;; to reflect the decoding we just did.
220 (goto-char quoted-printable-header-field-end)
221 (delete-region (point) (search-backward ":"))
222 (insert ": 8bit")))
223 (if base64-header-field-end
224 (save-excursion
225 (when (condition-case nil
226 (progn
227 (base64-decode-region
228 (1+ header-end)
229 (save-excursion
230 ;; Prevent base64-decode-region
231 ;; from removing newline characters.
232 (skip-chars-backward "\n\t ")
233 (point)))
234 t)
235 (error nil))
236 ;; Change "base64" to "8bit", to reflect the
237 ;; decoding we just did.
238 (goto-char base64-header-field-end)
239 (delete-region (point) (search-backward ":"))
240 (insert ": 8bit")))))
241 ;; Transform anything within the message text
242 ;; that might appear to be the end of a Babyl-format message.
243 (save-excursion
244 (save-restriction
245 (narrow-to-region start (point))
246 (goto-char (point-min))
247 (while (search-forward "\n\^_" nil t) ; single char
248 (replace-match "\n^_")))) ; 2 chars: "^" and "_"
249 ;; This is for malformed messages that don't end in newline.
250 ;; There shouldn't be any, but some users say occasionally
251 ;; there are some.
252 (or (bolp) (newline))
253 (insert ?\^_)
254 (setq last-coding-system-used nil)
255 ;; Decode coding system, following specs in the message header,
256 ;; and record what coding system was decoded.
257 (if rmail-output-decode-coding
258 (let ((mime-charset
259 (if (save-excursion
260 (goto-char start)
261 (search-forward "\n\n" nil t)
262 (let ((case-fold-search t))
263 (re-search-backward
264 rmail-mime-charset-pattern
265 start t)))
266 (intern (downcase (match-string 1))))))
267 (rmail-decode-region start (point) mime-charset)))
268 (save-excursion
269 (goto-char start)
270 (forward-line 3)
271 (insert "X-Coding-System: "
272 (symbol-name last-coding-system-used)
273 "\n")))))
274
275 (defun rmail-nuke-pinhead-header ()
276 "Delete the \"From \" line in the current mbox message.
277 The variable `rmail-unix-mail-delimiter' specifies the From line format.
278 Replaces the From line with a \"Mail-from\" header. Adds \"Date\" and
279 \"From\" headers if they are not already present."
280 (save-excursion
281 (save-restriction
282 (let ((start (point))
283 (end (progn
284 (condition-case ()
285 (search-forward "\n\n")
286 (error
287 (goto-char (point-max))
288 (insert "\n\n")))
289 (point)))
290 has-from has-date)
291 (narrow-to-region start end)
292 (let ((case-fold-search t))
293 (goto-char start)
294 (setq has-from (search-forward "\nFrom:" nil t))
295 (goto-char start)
296 (setq has-date (and (search-forward "\nDate:" nil t) (point)))
297 (goto-char start))
298 (let ((case-fold-search nil))
299 (if (re-search-forward (concat "^" rmail-unix-mail-delimiter) nil t)
300 (replace-match
301 (concat
302 "Mail-from: \\&"
303 ;; Keep and reformat the date if we don't
304 ;; have a Date: field.
305 (if has-date
306 ""
307 (concat
308 "Date: \\2, \\4 \\3 \\9 \\5 "
309
310 ;; The timezone could be matched by group 7 or group 10.
311 ;; If neither of them matched, assume EST, since only
312 ;; Easterners would be so sloppy.
313 ;; It's a shame the substitution can't use "\\10".
314 (cond
315 ((/= (match-beginning 7) (match-end 7)) "\\7")
316 ((/= (match-beginning 10) (match-end 10))
317 (buffer-substring (match-beginning 10)
318 (match-end 10)))
319 (t "EST"))
320 "\n"))
321 ;; Keep and reformat the sender if we don't
322 ;; have a From: field.
323 (if has-from
324 ""
325 "From: \\1\n"))
326 t)))))))
327 \f
328 (autoload 'mail-mbox-from "mail-utils")
329
330 (defun rmail-output-as-mbox (file-name nomsg &optional as-seen)
331 "Convert the current buffer's text to mbox and output to FILE-NAME.
332 Alters the current buffer's text, so it should be a temporary buffer.
333 If a buffer is visiting FILE-NAME, adds the text to that buffer
334 rather than saving the file directly. If the buffer is an Rmail buffer,
335 updates it accordingly. If no buffer is visiting FILE-NAME, appends
336 the text directly to FILE-NAME, and displays a \"Wrote file\" message
337 unless NOMSG is a symbol (neither nil nor t).
338 AS-SEEN is non-nil if we are copying the message \"as seen\"."
339 (let ((case-fold-search t)
340 from date)
341 (goto-char (point-min))
342 ;; Preserve the Mail-From and MIME-Version fields
343 ;; even if they have been pruned.
344 (search-forward "\n\n" nil 'move)
345 (narrow-to-region (point-min) (point))
346 (rmail-delete-unwanted-fields
347 (if rmail-enable-mime "Mail-From"
348 "Mail-From\\|MIME-Version\\|Content-type"))
349 (goto-char (point-min))
350 (or (looking-at "From ")
351 (insert (mail-mbox-from)))
352 (widen)
353 ;; Make sure message ends with blank line.
354 (goto-char (point-max))
355 (rmail-ensure-blank-line)
356 (goto-char (point-min))
357 (let ((buf (find-buffer-visiting file-name))
358 (tembuf (current-buffer)))
359 (if (null buf)
360 (let ((coding-system-for-write 'raw-text-unix))
361 ;; FIXME should ensure existing file ends with a blank line.
362 (write-region (point-min) (point-max) file-name t nomsg))
363 (if (eq buf (current-buffer))
364 (error "Can't output message to same file it's already in"))
365 ;; File has been visited, in buffer BUF.
366 (set-buffer buf)
367 (let ((inhibit-read-only t)
368 (msg (and (boundp 'rmail-current-message)
369 rmail-current-message)))
370 (and msg as-seen
371 (error "Can't output \"as seen\" to a visited Rmail file"))
372 (if msg
373 (rmail-output-to-rmail-buffer tembuf msg)
374 ;; Output file not in Rmail mode => just insert at the end.
375 (narrow-to-region (point-min) (1+ (buffer-size)))
376 (goto-char (point-max))
377 (insert-buffer-substring tembuf)))))))
378
379 (defun rmail-output-to-rmail-buffer (tembuf msg)
380 "Copy message in TEMBUF into the current Rmail buffer.
381 Do what is necessary to make Rmail know about the new message. then
382 display message number MSG."
383 (save-excursion
384 (rmail-swap-buffers-maybe)
385 (rmail-modify-format)
386 ;; Turn on Auto Save mode, if it's off in this buffer but enabled
387 ;; by default.
388 (and (not buffer-auto-save-file-name)
389 auto-save-default
390 (auto-save-mode t))
391 (rmail-maybe-set-message-counters)
392 ;; Insert the new message after the last old message.
393 (widen)
394 (unless (zerop (buffer-size))
395 ;; Make sure the last old message ends with a blank line.
396 (goto-char (point-max))
397 (rmail-ensure-blank-line)
398 ;; Insert the new message at the end.
399 (narrow-to-region (point-max) (point-max)))
400 (insert-buffer-substring tembuf)
401 (rmail-count-new-messages t)
402 ;; FIXME should re-use existing windows.
403 (if (rmail-summary-exists)
404 (rmail-select-summary (rmail-update-summary)))
405 (rmail-show-message-1 msg)))
406 \f
407 ;;; There are functions elsewhere in Emacs that use this function;
408 ;;; look at them before you change the calling method.
409 ;;;###autoload
410 (defun rmail-output (file-name &optional count noattribute not-rmail)
411 "Append this message to mail file FILE-NAME.
412 Writes mbox format, unless FILE-NAME exists and is Babyl format, in which
413 case it writes Babyl.
414
415 Interactively, the default file name comes from `rmail-default-file',
416 which is updated to the name you use in this command. In all uses, if
417 FILE-NAME is not absolute, it is expanded with the directory part of
418 `rmail-default-file'.
419
420 If a buffer is visiting FILE-NAME, adds the text to that buffer
421 rather than saving the file directly. If the buffer is an Rmail
422 buffer, updates it accordingly.
423
424 This command always outputs the complete message header, even if
425 the header display is currently pruned.
426
427 Optional prefix argument COUNT (default 1) says to output that
428 many consecutive messages, starting with the current one (ignoring
429 deleted messages). If `rmail-delete-after-output' is non-nil, deletes
430 messages after output.
431
432 The optional third argument NOATTRIBUTE, if non-nil, says not to
433 set the `filed' attribute, and not to display a \"Wrote file\"
434 message (if writing a file directly).
435
436 Set the optional fourth argument NOT-RMAIL non-nil if you call this
437 from a non-Rmail buffer. In this case, COUNT is ignored."
438 (interactive
439 (list (rmail-output-read-file-name)
440 (prefix-numeric-value current-prefix-arg)))
441 (or count (setq count 1))
442 (setq file-name
443 (expand-file-name file-name
444 (and rmail-default-file
445 (file-name-directory rmail-default-file))))
446 ;; Warn about creating new file.
447 (or (find-buffer-visiting file-name)
448 (file-exists-p file-name)
449 (yes-or-no-p (concat "\"" file-name "\" does not exist, create it? "))
450 (error "Output file does not exist"))
451 (if noattribute (setq noattribute 'nomsg))
452 (let ((babyl-format (and (file-readable-p file-name)
453 (mail-file-babyl-p file-name)))
454 (cur (current-buffer))
455 (buf (find-buffer-visiting file-name)))
456
457 ;; If a babyl file is visited in a buffer, is it visited as babyl
458 ;; or as mbox?
459 (and babyl-format buf
460 (with-current-buffer buf
461 (save-restriction
462 (widen)
463 (save-excursion
464 (goto-char (point-min))
465 (setq babyl-format
466 (looking-at "BABYL OPTIONS:"))))))
467
468 (if not-rmail ; eg via message-fcc-handler-function
469 (with-temp-buffer
470 (insert-buffer-substring cur)
471 ;; Output in the appropriate format.
472 (if babyl-format
473 (progn
474 (goto-char (point-min))
475 ;; rmail-convert-to-babyl-format errors if no From line,
476 ;; whereas rmail-output-as-mbox inserts one.
477 (or (looking-at "From ")
478 (insert (mail-mbox-from)))
479 (rmail-output-as-babyl file-name noattribute))
480 (rmail-output-as-mbox file-name noattribute)))
481 ;; Called from an Rmail buffer.
482 (if rmail-buffer
483 (set-buffer rmail-buffer)
484 (error "There is no Rmail buffer"))
485 (if (zerop rmail-total-messages)
486 (error "No messages to output"))
487 (let ((orig-count count)
488 beg end)
489 (while (> count 0)
490 (setq beg (rmail-msgbeg rmail-current-message)
491 end (rmail-msgend rmail-current-message))
492 ;; All access to the buffer's local variables is now finished...
493 (save-excursion
494 ;; ... so it is ok to go to a different buffer.
495 (if (rmail-buffers-swapped-p) (set-buffer rmail-view-buffer))
496 (setq cur (current-buffer))
497 (save-restriction
498 (widen)
499 (with-temp-buffer
500 (insert-buffer-substring cur beg end)
501 (if babyl-format
502 (rmail-output-as-babyl file-name noattribute)
503 (rmail-output-as-mbox file-name noattribute)))))
504 (or noattribute ; mark message as "filed"
505 (rmail-set-attribute rmail-filed-attr-index t))
506 (setq count (1- count))
507 (let ((next-message-p
508 (if rmail-delete-after-output
509 (rmail-delete-forward)
510 (if (> count 0)
511 (rmail-next-undeleted-message 1))))
512 (num-appended (- orig-count count)))
513 (if (and (> count 0) (not next-message-p))
514 (error "Only %d message%s appended" num-appended
515 (if (= num-appended 1) "" "s")))))))))
516
517 ;; FIXME nothing outside uses this, so NOT-RMAIL could be dropped.
518 ;; FIXME this duplicates code from rmail-output.
519 ;;;###autoload
520 (defun rmail-output-as-seen (file-name &optional count noattribute not-rmail)
521 "Append this message to mbox file named FILE-NAME.
522 The details are as for `rmail-output', except that:
523 i) the header is output as currently seen
524 ii) this function cannot write to Babyl files
525 iii) an Rmail buffer cannot be visiting FILE-NAME
526
527 Note that if NOT-RMAIL is non-nil, there is no difference between this
528 function and `rmail-output'. This argument may be removed in future,
529 so you should call `rmail-output' directly in that case."
530 (interactive
531 (list (rmail-output-read-file-name)
532 (prefix-numeric-value current-prefix-arg)))
533 (if not-rmail
534 (rmail-output file-name count noattribute not-rmail)
535 (or count (setq count 1))
536 (setq file-name
537 (expand-file-name file-name
538 (and rmail-default-file
539 (file-name-directory rmail-default-file))))
540 ;; Warn about creating new file.
541 (or (find-buffer-visiting file-name)
542 (file-exists-p file-name)
543 (yes-or-no-p (concat "\"" file-name "\" does not exist, create it? "))
544 (error "Output file does not exist"))
545 ;; FIXME why not?
546 (if (and (file-readable-p file-name) (mail-file-babyl-p file-name))
547 (error "Cannot output `as seen' to a Babyl file"))
548 (if noattribute (setq noattribute 'nomsg))
549 (if rmail-buffer
550 (set-buffer rmail-buffer)
551 (error "There is no Rmail buffer"))
552 (if (zerop rmail-total-messages)
553 (error "No messages to output"))
554 (let ((orig-count count)
555 (cur (current-buffer)))
556 (while (> count 0)
557 (let (beg end)
558 ;; If operating from whole-mbox buffer, get message bounds.
559 (or (rmail-buffers-swapped-p)
560 (setq beg (rmail-msgbeg rmail-current-message)
561 end (rmail-msgend rmail-current-message)))
562 (save-restriction
563 (widen)
564 ;; If operating from the view buffer, get the bounds.
565 (or beg
566 (setq beg (point-min)
567 end (point-max)))
568 (with-temp-buffer
569 (insert-buffer-substring cur beg end)
570 (rmail-output-as-mbox file-name noattribute t))))
571 (or noattribute ; mark message as "filed"
572 (rmail-set-attribute rmail-filed-attr-index t))
573 (setq count (1- count))
574 (let ((next-message-p
575 (if rmail-delete-after-output
576 (rmail-delete-forward)
577 (if (> count 0)
578 (rmail-next-undeleted-message 1))))
579 (num-appended (- orig-count count)))
580 (if (and (> count 0) (not next-message-p))
581 (error "Only %d message%s appended" num-appended
582 (if (= num-appended 1) "" "s"))))))))
583
584 \f
585 ;;;###autoload
586 (defun rmail-output-body-to-file (file-name)
587 "Write this message body to the file FILE-NAME.
588 Interactively, the default file name comes from either the message
589 \"Subject\" header, or from `rmail-default-body-file'. Updates the value
590 of `rmail-default-body-file' accordingly. In all uses, if FILE-NAME
591 is not absolute, it is expanded with the directory part of
592 `rmail-default-body-file'.
593
594 Note that this overwrites FILE-NAME (after confirmation), rather
595 than appending to it. Deletes the message after writing if
596 `rmail-delete-after-output' is non-nil."
597 (interactive
598 (let ((default-file
599 (or (mail-fetch-field "Subject")
600 rmail-default-body-file)))
601 (setq default-file
602 (replace-regexp-in-string ":" "-" default-file))
603 (setq default-file
604 (replace-regexp-in-string " " "-" default-file))
605 (list (setq rmail-default-body-file
606 (read-file-name
607 "Output message body to file: "
608 (and default-file (file-name-directory default-file))
609 default-file
610 nil default-file)))))
611 (setq file-name
612 (expand-file-name file-name
613 (and rmail-default-body-file
614 (file-name-directory rmail-default-body-file))))
615 (if (zerop rmail-current-message)
616 (error "No message to output"))
617 (save-excursion
618 (goto-char (point-min))
619 (search-forward "\n\n")
620 (and (file-exists-p file-name)
621 (not (y-or-n-p (format "File %s exists; overwrite? " file-name)))
622 (error "Operation aborted"))
623 (write-region (point) (point-max) file-name))
624 (if rmail-delete-after-output
625 (rmail-delete-forward)))
626
627 ;;; rmailout.el ends here