]> code.delx.au - gnu-emacs/blobdiff - lisp/mail/unrmail.el
Checked rmail.texi
[gnu-emacs] / lisp / mail / unrmail.el
index 86957813e1e822de87876dae63f3133cb5a5c343..af16bbf8c73f873e40e6b7d1e4a3a7ed0db34bcd 100644 (file)
@@ -1,7 +1,6 @@
 ;;; unrmail.el --- convert Rmail Babyl files to mailbox files
 
-;; Copyright (C) 1992, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
-;;   2009  Free Software Foundation, Inc.
+;; Copyright (C) 1992, 2001-2012  Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
 ;; Keywords: mail
@@ -43,7 +42,7 @@ For example, invoke `emacs -batch -f batch-unrmail RMAIL'."
     (message "Done")
     (kill-emacs (if error 1 0))))
 
-(declare-function mail-strip-quoted-names "mail-utils" (address))
+(declare-function mail-mbox-from "mail-utils" ())
 (defvar rmime-magic-string)            ; in rmime.el, if you have it
 
 ;;;###autoload
@@ -70,7 +69,8 @@ For example, invoke `emacs -batch -f batch-unrmail RMAIL'."
       (setq from (point))
       (goto-char (point-max))
       (search-backward "\n\^_" from 'mv)
-      (setq to (point))
+      (if (= from (setq to (point)))
+         (error "The input file contains no messages"))
       (unless (and coding-system
                   (coding-system-p coding-system))
        (setq coding-system
@@ -191,22 +191,14 @@ For example, invoke `emacs -batch -f batch-unrmail RMAIL'."
               (save-excursion (search-forward "\n\n" nil 'move) (point)))
 
              ;; Fetch or construct what we should use in the `From ' line.
-             (setq mail-from
-                   (or (mail-fetch-field "Mail-From")
-                       (concat "From "
-                               (mail-strip-quoted-names
-                                (or (mail-fetch-field "from")
-                                    (mail-fetch-field "really-from")
-                                    (mail-fetch-field "sender")
-                                    "unknown"))
-                               "  "
-                               (let ((date (mail-fetch-field "date")))
-                                 (or
-                                  (and date
-                                       (ignore-errors
-                                        (current-time-string
-                                         (date-to-time date))))
-                                  (current-time-string))))))
+             (setq mail-from (or (let ((from (mail-fetch-field "Mail-From")))
+                                   ;; mail-mbox-from (below) returns a
+                                   ;; string that ends in a newline, but
+                                   ;; but mail-fetch-field does not, so
+                                   ;; we append a newline here.
+                                   (if from
+                                       (format "%s\n" from)))
+                                 (mail-mbox-from)))
 
              ;; If the message specifies a coding system, use it.
              (let ((maybe-coding (mail-fetch-field "X-Coding-System")))
@@ -227,7 +219,7 @@ For example, invoke `emacs -batch -f batch-unrmail RMAIL'."
 
            (goto-char (point-min))
            ;; Insert the `From ' line.
-           (insert mail-from "\n")
+           (insert mail-from)
            ;; Record the keywords and attributes in our special way.
            (insert "X-RMAIL-ATTRIBUTES: " (apply 'string attrs) "\n")
            (when keywords
@@ -240,6 +232,9 @@ For example, invoke `emacs -batch -f batch-unrmail RMAIL'."
              (while (search-forward "\nFrom " nil t)
                (forward-char -5)
                (insert ?>)))
+           (goto-char (point-max))
+           ;; Add terminator blank line to message.
+           (insert "\n")
            ;; Write it to the output file, suitably encoded.
            (let ((coding-system-for-write coding))
              (write-region (point-min) (point-max) to-file t
@@ -249,5 +244,4 @@ For example, invoke `emacs -batch -f batch-unrmail RMAIL'."
 
 (provide 'unrmail)
 
-;; arch-tag: 14c6290d-60b2-456f-8909-5c2387de6acb
 ;;; unrmail.el ends here