]> code.delx.au - gnu-emacs/blobdiff - lisp/mail/unrmail.el
Update docs for `customize-mode'
[gnu-emacs] / lisp / mail / unrmail.el
index bf7b9abe2c16874e4d68bdd35c584edae77b4c39..1f7b862c3bd58469d32931111102ceff50e7d603 100644 (file)
@@ -1,8 +1,8 @@
-;;; unrmail.el --- convert Rmail Babyl files to mailbox files
+;;; unrmail.el --- convert Rmail Babyl files to mbox files
 
-;; Copyright (C) 1992, 2001-201 Free Software Foundation, Inc.
+;; Copyright (C) 1992, 2001-2016 Free Software Foundation, Inc.
 
-;; Maintainer: FSF
+;; Maintainer: emacs-devel@gnu.org
 ;; Keywords: mail
 
 ;; This file is part of GNU Emacs.
@@ -26,7 +26,7 @@
 
 ;;;###autoload
 (defun batch-unrmail ()
-  "Convert old-style Rmail Babyl files to system inbox format.
+  "Convert old-style Rmail Babyl files to mbox format.
 Specify the input Rmail Babyl file names as command line arguments.
 For each Rmail file, the corresponding output file name
 is made by adding `.mail' at the end.
@@ -45,9 +45,26 @@ For example, invoke `emacs -batch -f batch-unrmail RMAIL'."
 (declare-function mail-mbox-from "mail-utils" ())
 (defvar rmime-magic-string)            ; in rmime.el, if you have it
 
+(defcustom unrmail-mbox-format 'mboxrd
+  "The mbox format that `unrmail' should produce.
+These formats separate messages using lines that start with \"From \".
+Therefore any lines in the message bodies that start with \"From \"
+must be quoted.  The `mboxo' format just prepends a \">\" to such lines.
+This is not reversible, because given a line starting with \">From \" in
+an mboxo file, it is not possible to know whether the original had a \">\"
+or not.  The `mboxrd' format avoids this by also quoting \">From \" as
+\">>From \", and so on.  For this reason, mboxrd is recommended.
+
+See also `rmail-mbox-format'."
+  :type '(choice (const mboxrd)
+                (const mboxo))
+  :version "24.4"
+  :group 'rmail-files)
+
 ;;;###autoload
 (defun unrmail (file to-file)
-  "Convert old-style Rmail Babyl file FILE to system inbox format file TO-FILE."
+  "Convert old-style Rmail Babyl file FILE to mbox format file TO-FILE.
+The variable `unrmail-mbox-format' controls which mbox format to use."
   (interactive "fUnrmail (babyl file): \nFUnrmail into (new mailbox file): ")
   (with-temp-buffer
     ;; Read in the old Rmail file with no decoding.
@@ -77,11 +94,9 @@ For example, invoke `emacs -batch -f batch-unrmail RMAIL'."
              ;; earlier versions did that with the current buffer's encoding.
              ;; So we want to favor detection of emacs-mule (whose normal
              ;; priority is quite low), but still allow detection of other
-             ;; encodings if emacs-mule won't fit.  The call to
-             ;; detect-coding-with-priority below achieves that.
-             (car (detect-coding-with-priority
-                   from to
-                   '((coding-category-emacs-mule . emacs-mule))))))
+             ;; encodings if emacs-mule won't fit.
+             (car (with-coding-priority '(emacs-mule)
+                    (detect-coding-region from to)))))
       (unless (memq coding-system
                    '(undecided undecided-unix))
        (set-buffer-modified-p t)       ; avoid locking when decoding
@@ -223,14 +238,15 @@ For example, invoke `emacs -batch -f batch-unrmail RMAIL'."
            (insert "X-RMAIL-ATTRIBUTES: " (apply 'string attrs) "\n")
            (when keywords
              (insert "X-RMAIL-KEYWORDS: " keywords "\n"))
-           (goto-char (point-min))
-           ;; ``Quote'' "\nFrom " as "\n>From "
-           ;;  (note that this isn't really quoting, as there is no requirement
-           ;;   that "\n[>]+From " be quoted in the same transparent way.)
-           (let ((case-fold-search nil))
-             (while (search-forward "\nFrom " nil t)
-               (forward-char -5)
-               (insert ?>)))
+           ;; Convert From to >From, etc.
+           (let ((case-fold-search nil)
+                 (fromline (if (eq 'mboxrd unrmail-mbox-format)
+                           "^>*From "
+                         "^From ")))
+             (while (re-search-forward fromline nil t)
+               (beginning-of-line)
+               (insert ?>)
+               (forward-line 1)))
            (goto-char (point-max))
            ;; Add terminator blank line to message.
            (insert "\n")