]> code.delx.au - gnu-emacs/blobdiff - lisp/mail/unrmail.el
(mail-yank-original): Set buffer-file-coding-system from the one used
[gnu-emacs] / lisp / mail / unrmail.el
index ecf4bdeec4fb78ef57616f5f3bf5cbcbb9dd2bff..e06c41b2c2e793bf955d299e4d8e347f1037a473 100644 (file)
@@ -43,7 +43,8 @@ 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
 (defun unrmail (file to-file)
@@ -132,14 +133,16 @@ For example, invoke `emacs -batch -f batch-unrmail RMAIL'."
                  (buffer-substring (point)
                                    (save-excursion (forward-line 1)
                                                    (point))))
-           (search-forward ",,")
+           (re-search-forward ",, ?")
            (unless (eolp)
              (setq keywords
                    (buffer-substring (point)
                                      (progn (end-of-line)
                                             (1- (point)))))
-             (setq keywords
-                   (replace-regexp-in-string ", " "," keywords)))
+             ;; Mbox rmail needs the spaces.  Bug#2303.
+             ;;; (setq keywords
+             ;;;           (replace-regexp-in-string ", " "," keywords))
+             )
 
            (setq attrs
                  (list
@@ -188,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")))
@@ -224,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
@@ -237,6 +232,10 @@ For example, invoke `emacs -batch -f batch-unrmail RMAIL'."
              (while (search-forward "\nFrom " nil t)
                (forward-char -5)
                (insert ?>)))
+           ;; Make sure the message ends with two newlines
+           (goto-char (point-max))
+           (unless (looking-back "\n\n")
+             (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