comparison lisp/mail/rmail.el @ 102925:f0dd383a41d7

(rmail-unrmail-new-mail, rmail-unrmail-new-mail-maybe): New functions. (rmail-insert-inbox-text): Use rmail-unrmail-new-mail-maybe to convert Babyl-formatted new mail to mbox format. (Bug#2942)
author Eli Zaretskii <eliz@gnu.org>
date Fri, 10 Apr 2009 10:41:19 +0000
parents 3d4fe9d9e9e6
children 0eb3cdddefb2
comparison
equal deleted inserted replaced
102924:41e596f3a3f8 102925:f0dd383a41d7
1831 1831
1832 (list file "pop" supplied-password got-password))) 1832 (list file "pop" supplied-password got-password)))
1833 1833
1834 (t 1834 (t
1835 (list file nil nil nil)))) 1835 (list file nil nil nil))))
1836
1837 (defun rmail-unrmail-new-mail (from-file)
1838 "Replace newly read mail in Babyl format with equivalent mbox format.
1839
1840 FROM-FILE is the Babyl file from which the new mail should be read."
1841 (let ((to-file (make-temp-file "rmail"))
1842 size)
1843 (unrmail from-file to-file)
1844 (let ((inhibit-read-only t)
1845 (coding-system-for-read 'raw-text)
1846 (buffer-undo-list t))
1847 (delete-region (point) (point-max))
1848 (setq size (nth 1 (insert-file-contents to-file)))
1849 (delete-file to-file)
1850 size)))
1851
1852 (defun rmail-unrmail-new-mail-maybe (file size)
1853 "If newly read mail from FILE is in Babyl format, convert it to mbox format.
1854
1855 SIZE is the original size of the newly read mail.
1856 Value is the size of the newly read mail after conversion."
1857 ;; Detect previous Babyl format files.
1858 (let ((case-fold-search nil)
1859 (old-file file)
1860 new-file)
1861 (cond ((looking-at "BABYL OPTIONS:")
1862 ;; The new mail is in Babyl version 5 format. Use unrmail
1863 ;; to convert it.
1864 (setq size (rmail-unrmail-new-mail old-file)))
1865 ((looking-at "Version: 5\n")
1866 ;; New mail is in Babyl format made by old version of
1867 ;; Rmail. Fix the babyl file header and use unrmail to
1868 ;; convert it.
1869 (let ((buffer-read-only nil)
1870 (write-region-annotate-functions nil)
1871 (write-region-post-annotation-function nil)
1872 (old-file (make-temp-file "rmail")))
1873 (insert "BABYL OPTIONS: -*- rmail -*-\n")
1874 (forward-line -1)
1875 (write-region (point) (point-max) old-file)
1876 (setq size (rmail-unrmail-new-mail old-file))
1877 (delete-file old-file))))
1878 size))
1836 1879
1837 (defun rmail-insert-inbox-text (files renamep) 1880 (defun rmail-insert-inbox-text (files renamep)
1838 ;; Detect a locked file now, so that we avoid moving mail 1881 ;; Detect a locked file now, so that we avoid moving mail
1839 ;; out of the real inbox file. (That could scare people.) 1882 ;; out of the real inbox file. (That could scare people.)
1840 (or (memq (file-locked-p buffer-file-name) '(nil t)) 1883 (or (memq (file-locked-p buffer-file-name) '(nil t))
1949 ;; or the actual inbox (if not renaming). 1992 ;; or the actual inbox (if not renaming).
1950 (if (file-exists-p tofile) 1993 (if (file-exists-p tofile)
1951 (let ((coding-system-for-read 'no-conversion) 1994 (let ((coding-system-for-read 'no-conversion)
1952 size) 1995 size)
1953 (goto-char (point-max)) 1996 (goto-char (point-max))
1954 (setq size (nth 1 (insert-file-contents tofile))) 1997 (setq size
1998 ;; If new mail is in Babyl format, convert it to mbox.
1999 (rmail-unrmail-new-mail-maybe
2000 tofile
2001 (nth 1 (insert-file-contents tofile))))
1955 ;; Determine if a pair of newline message separators need 2002 ;; Determine if a pair of newline message separators need
1956 ;; to be added to the new collection of messages. This is 2003 ;; to be added to the new collection of messages. This is
1957 ;; the case for all new message collections added to a 2004 ;; the case for all new message collections added to a
1958 ;; non-empty mail file. 2005 ;; non-empty mail file.
1959 (unless (zerop size) 2006 (unless (zerop size)