(defvar command-line-args-left)
(defun batch-unrmail ()
"Convert Rmail files to system inbox format.
Specify the input Rmail file names as command line arguments.
For each Rmail file, the corresponding output file name
is made by adding `.mail' at the end.
For example, invoke `emacs -batch -f batch-unrmail RMAIL'."
(if (not noninteractive)
(error "`batch-unrmail' is to be used only with -batch"))
(let ((error nil))
(while command-line-args-left
(or (unrmail (car command-line-args-left)
(concat (car command-line-args-left) ".mail"))
(setq error t))
(setq command-line-args-left (cdr command-line-args-left)))
(message "Done")
(kill-emacs (if error 1 0))))
(defun unrmail (file to-file)
"Convert Rmail file FILE to system inbox format file TO-FILE."
(interactive "fUnrmail (rmail file): \nFUnrmail into (new mailbox file): ")
(let ((message-count 0)
(rmail-display-summary nil)
(rmail-delete-after-output nil))
(rmail file)
(setq to-file (expand-file-name to-file default-directory))
(message "Writing messages to %s..." to-file)
(while (< message-count rmail-total-messages)
(rmail-show-message
(setq message-count (1+ message-count)))
(rmail-toggle-header)
(rmail-output to-file 1 t))
(message "Writing messages to %s...done" to-file)))
(provide 'unrmail)