Importing Gnus v5.8.7.
[elisp/gnus.git-] / lisp / mail-source.el
index 2fb2b28..be0cea4 100644 (file)
@@ -1,5 +1,5 @@
 ;;; mail-source.el --- functions for fetching mail
-;; Copyright (C) 1999 Free Software Foundation, Inc.
+;; Copyright (C) 1999, 2000 Free Software Foundation, Inc.
 
 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
 ;; Keywords: news, mail
@@ -62,7 +62,7 @@ If non-nil, this maildrop will be checked periodically for new mail."
   :group 'mail-source
   :type 'integer)
 
-(defcustom mail-source-delete-incoming t
+(defcustom mail-source-delete-incoming nil
   "*If non-nil, delete incoming files after handling."
   :group 'mail-source
   :type 'boolean)
@@ -114,7 +114,8 @@ Common keywords should be listed here.")
        (:password)
        (:authentication password))
       (maildir
-       (:path "~/Maildir/new/")
+       (:path (or (getenv "MAILDIR") "~/Maildir/"))
+       (:subdirs ("new" "cur"))
        (:function))
       (imap
        (:server (getenv "MAILHOST"))
@@ -606,13 +607,32 @@ This only works when `display-time' is enabled."
   "Fetcher for maildir sources."
   (mail-source-bind (maildir source)
     (let ((found 0)
-         (mail-source-string (format "maildir:%s" path)))
-      (dolist (file (directory-files path t))
-       (when (and (not (file-directory-p file))
-                  (not (if function
-                           (funcall function file mail-source-crash-box)
-                         (rename-file file mail-source-crash-box))))
-         (incf found (mail-source-callback callback file))))
+         mail-source-string)
+      (unless (string-match "/$" path)
+       (setq path (concat path "/")))
+      (dolist (subdir subdirs)
+       (when (file-directory-p (concat path subdir))
+         (setq mail-source-string (format "maildir:%s%s" path subdir))
+         (dolist (file (directory-files (concat path subdir) t))
+           (when (and (not (file-directory-p file))
+                      (not (if function
+                               (funcall function file mail-source-crash-box)
+                             (let ((coding-system-for-write 
+                                    mm-text-coding-system)
+                                   (coding-system-for-read 
+                                    mm-text-coding-system))
+                               (with-temp-file mail-source-crash-box
+                                 (insert-file-contents file)
+                                 (goto-char (point-min))
+                                 (unless (looking-at "\n*From ")
+                                   (insert "From maildir " 
+                                           (current-time-string) "\n"))
+                                 (while (re-search-forward "^From " nil t)
+                                   (replace-match ">From "))
+                                 (goto-char (point-max))
+                                 (insert "\n\n"))
+                               (delete-file file)))))
+             (incf found (mail-source-callback callback file))))))
       found)))
 
 (eval-and-compile