]> code.delx.au - gnu-emacs/blobdiff - lisp/mail/rmailout.el
Add 2010 to copyright years.
[gnu-emacs] / lisp / mail / rmailout.el
index 51aa6fc5bcf3d6b7ad621e0093a863d394301bc3..a6ff75e4efef78252a956fb459deca79622dc2f4 100644 (file)
@@ -1,7 +1,7 @@
 ;;; rmailout.el --- "RMAIL" mail reader for Emacs: output message to a file
 
 ;; Copyright (C) 1985, 1987, 1993, 1994, 2001, 2002, 2003, 2004, 2005,
-;;   2006, 2007, 2008, 2009  Free Software Foundation, Inc.
+;;   2006, 2007, 2008, 2009, 2010  Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
 ;; Keywords: mail
@@ -33,6 +33,7 @@
   :type 'boolean
   :group 'rmail-output)
 
+;; FIXME risky?
 (defcustom rmail-output-file-alist nil
   "Alist matching regexps to suggested output Rmail files.
 This is a list of elements of the form (REGEXP . NAME-EXP).
@@ -45,6 +46,7 @@ a file name as a string."
                               (string :tag "File Name")
                               sexp)))
   :group 'rmail-output)
+;;;###autoload(put 'rmail-output-file-alist 'risky-local-variable t)
 
 (defcustom rmail-fields-not-to-output nil
   "Regexp describing fields to exclude when outputting a message to a file.
@@ -168,7 +170,7 @@ display message number MSG."
     (save-restriction
       (unless (looking-at "^From ")
        (error "Invalid mbox message"))
-      (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
+      (insert "\^L\n0,,\n*** EOOH ***\n")
       (rmail-nuke-pinhead-header)
       ;; Decode base64 or quoted printable contents, Rmail style.
       (let* ((header-end (save-excursion
@@ -335,15 +337,13 @@ AS-SEEN is non-nil if we are copying the message \"as seen\"."
     (widen)
     ;; Make sure message ends with blank line.
     (goto-char (point-max))
-    (unless (bolp)
-       (insert "\n"))
-    (unless (looking-back "\n\n")
-      (insert "\n"))
+    (rmail-ensure-blank-line)
     (goto-char (point-min))
     (let ((buf (find-buffer-visiting file-name))
          (tembuf (current-buffer)))
       (if (null buf)
          (let ((coding-system-for-write 'raw-text-unix))
+           ;; FIXME should ensure existing file ends with a blank line.
            (write-region (point-min) (point-max) file-name t nomsg))
        (if (eq buf (current-buffer))
            (error "Can't output message to same file it's already in"))
@@ -367,15 +367,23 @@ Do what is necessary to make Rmail know about the new message. then
 display message number MSG."
   (save-excursion
     (rmail-swap-buffers-maybe)
-    ;; Turn on Auto Save mode, if it's off in this
-    ;; buffer but enabled by default.
+    (rmail-modify-format)
+    ;; Turn on Auto Save mode, if it's off in this buffer but enabled
+    ;; by default.
     (and (not buffer-auto-save-file-name)
         auto-save-default
         (auto-save-mode t))
     (rmail-maybe-set-message-counters)
+    ;; Insert the new message after the last old message.
+    (widen)
+    ;; Make sure the last old message ends with a blank line.
+    (goto-char (point-max))
+    (rmail-ensure-blank-line)
+    ;; Insert the new message at the end.
     (narrow-to-region (point-max) (point-max))
     (insert-buffer-substring tembuf)
     (rmail-count-new-messages t)
+    ;; FIXME should re-use existing windows.
     (if (rmail-summary-exists)
        (rmail-select-summary (rmail-update-summary)))
     (rmail-show-message-1 msg)))
@@ -427,7 +435,20 @@ from a non-Rmail buffer.  In this case, COUNT is ignored."
   (if noattribute (setq noattribute 'nomsg))
   (let ((babyl-format (and (file-readable-p file-name)
                           (mail-file-babyl-p file-name)))
-       (cur (current-buffer)))
+       (cur (current-buffer))
+       (buf (find-buffer-visiting file-name)))
+
+    ;; If a babyl file is visited in a buffer, is it visited as babyl
+    ;; or as mbox?
+    (and babyl-format buf
+        (with-current-buffer buf
+          (save-restriction
+            (widen)
+            (save-excursion
+              (goto-char (point-min))
+              (setq babyl-format
+                    (looking-at "BABYL OPTIONS:"))))))
+
     (if not-rmail               ; eg via message-fcc-handler-function
        (with-temp-buffer
          (insert-buffer-substring cur)
@@ -477,6 +498,7 @@ from a non-Rmail buffer.  In this case, COUNT is ignored."
 
 ;; FIXME nothing outside uses this, so NOT-RMAIL could be dropped.
 ;; FIXME this duplicates code from rmail-output.
+;;;###autoload
 (defun rmail-output-as-seen (file-name &optional count noattribute not-rmail)
   "Append this message to mbox file named FILE-NAME.
 The details are as for `rmail-output', except that: