*** empty log message ***
[gnus] / lisp / nnfolder.el
index 479024d..ff92039 100644 (file)
@@ -1,5 +1,5 @@
 ;;; nnfolder.el --- mail folder access for Gnus
-;; Copyright (C) 1995 Free Software Foundation, Inc.
+;; Copyright (C) 1995,96 Free Software Foundation, Inc.
 
 ;; Author: Scott Byer <byer@mv.us.adobe.com>
 ;;     Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
 (require 'nnheader)
 (require 'rmail)
 (require 'nnmail)
+(eval-when-compile (require 'cl))
 
 (defvar nnfolder-directory (expand-file-name "~/Mail/")
   "The name of the mail box file in the users home directory.")
 
-(defvar nnfolder-active-file (concat nnfolder-directory "active")
+(defvar nnfolder-active-file 
+  (concat (file-name-as-directory nnfolder-directory) "active")
   "The name of the active file.")
 
 ;; I renamed this variable to somehting more in keeping with the general GNU
@@ -60,18 +62,22 @@ attempt to keep the buffers around (saving the nnfolder's buffer upon group
 close, but not killing it), speeding some things up tremendously, especially
 such things as moving mail.  All buffers always get killed upon server close.")
 
-(defvar nnfolder-newsgroups-file (concat nnfolder-directory "newsgroups")
+(defvar nnfolder-newsgroups-file 
+  (concat (file-name-as-directory nnfolder-directory) "newsgroups")
   "Mail newsgroups description file.")
 
 (defvar nnfolder-get-new-mail t
-  "If non-nil, nnml will check the incoming mail file and split the mail.")
+  "If non-nil, nnfolder will check the incoming mail file and split the mail.")
 
 (defvar nnfolder-prepare-save-mail-hook nil
   "Hook run narrowed to an article before saving.")
 
+(defvar nnfolder-inhibit-expiry nil
+  "If non-nil, inhibit expiry.")
+
 \f
 
-(defconst nnfolder-version "nnfolder 0.2"
+(defconst nnfolder-version "nnfolder 1.0"
   "nnfolder version.")
 
 (defconst nnfolder-article-marker "X-Gnus-Article-Number: "
@@ -82,9 +88,7 @@ such things as moving mail.  All buffers always get killed upon server close.")
 (defvar nnfolder-status-string "")
 (defvar nnfolder-group-alist nil)
 (defvar nnfolder-buffer-alist nil)
-
-(defmacro nnfolder-article-string (article)
-  (` (concat "\n" nnfolder-article-marker (int-to-string (, article)) " ")))
+(defvar nnfolder-active-timestamp nil)
 
 \f
 
@@ -96,24 +100,24 @@ such things as moving mail.  All buffers always get killed upon server close.")
    (list 'nnfolder-active-file nnfolder-active-file)
    (list 'nnfolder-newsgroups-file nnfolder-newsgroups-file)
    (list 'nnfolder-get-new-mail nnfolder-get-new-mail)
+   (list 'nnfolder-inhibit-expiry nnfolder-inhibit-expiry) 
    '(nnfolder-current-group nil)
    '(nnfolder-current-buffer nil)
    '(nnfolder-status-string "")
    '(nnfolder-group-alist nil)
-   '(nnfolder-buffer-alist nil)))
+   '(nnfolder-buffer-alist nil)
+   '(nnfolder-active-timestamp nil)))
 
 \f
 
 ;;; Interface functions
 
-(defun nnfolder-retrieve-headers (sequence &optional newsgroup server)
+(defun nnfolder-retrieve-headers (sequence &optional newsgroup server fetch-old)
   (save-excursion
     (set-buffer nntp-server-buffer)
     (erase-buffer)
-    (let ((file nil)
-         (number (length sequence))
-         (delim-string (concat "^" rmail-unix-mail-delimiter))
-         beg article art-string start stop)
+    (let ((delim-string (concat "^" rmail-unix-mail-delimiter))
+         article art-string start stop)
       (nnfolder-possibly-change-group newsgroup)
       (set-buffer nnfolder-current-buffer)
       (goto-char (point-min))
@@ -136,17 +140,13 @@ such things as moving mail.  All buffers always get killed upon server close.")
                (setq stop (1- (point)))
                (set-buffer nntp-server-buffer)
                (insert (format "221 %d Article retrieved.\n" article))
-               (setq beg (point))
                (insert-buffer-substring nnfolder-current-buffer start stop)
                (goto-char (point-max))
                (insert ".\n")))
          (setq sequence (cdr sequence)))
 
-       ;; Fold continuation lines.
        (set-buffer nntp-server-buffer)
-       (goto-char (point-min))
-       (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t)
-         (replace-match " " t t))
+       (nnheader-fold-continuation-lines)
        'headers))))
 
 (defun nnfolder-open-server (server &optional defs)
@@ -167,6 +167,7 @@ such things as moving mail.  All buffers always get killed upon server close.")
     (setq nnfolder-current-server server)))
 
 (defun nnfolder-close-server (&optional server)
+  (setq nnfolder-current-server nil)
   t)
 
 (defun nnfolder-server-opened (&optional server)
@@ -187,53 +188,79 @@ such things as moving mail.  All buffers always get killed upon server close.")
 
 (defun nnfolder-request-article (article &optional newsgroup server buffer)
   (nnfolder-possibly-change-group newsgroup)
-  (if (stringp article)
-      nil
-    (save-excursion
-      (set-buffer nnfolder-current-buffer)
-      (goto-char (point-min))
-      (if (search-forward (nnfolder-article-string article) nil t)
-         (let (start stop)
-           (re-search-backward (concat "^" rmail-unix-mail-delimiter) nil t)
-           (setq start (point))
-           (forward-line 1)
-           (or (and (re-search-forward 
-                     (concat "^" rmail-unix-mail-delimiter) nil t)
-                    (forward-line -1))
-               (goto-char (point-max)))
-           (setq stop (point))
-           (let ((nntp-server-buffer (or buffer nntp-server-buffer)))
-             (set-buffer nntp-server-buffer)
-             (erase-buffer)
-             (insert-buffer-substring nnfolder-current-buffer start stop)
+  (save-excursion
+    (set-buffer nnfolder-current-buffer)
+    (goto-char (point-min))
+    (if (search-forward (nnfolder-article-string article) nil t)
+       (let (start stop)
+         (re-search-backward (concat "^" rmail-unix-mail-delimiter) nil t)
+         (setq start (point))
+         (forward-line 1)
+         (or (and (re-search-forward 
+                   (concat "^" rmail-unix-mail-delimiter) nil t)
+                  (forward-line -1))
+             (goto-char (point-max)))
+         (setq stop (point))
+         (let ((nntp-server-buffer (or buffer nntp-server-buffer)))
+           (set-buffer nntp-server-buffer)
+           (erase-buffer)
+           (insert-buffer-substring nnfolder-current-buffer start stop)
+           (goto-char (point-min))
+           (while (looking-at "From ")
+             (delete-char 5)
+             (insert "X-From-Line: ")
+             (forward-line 1))
+           (if (numberp article) 
+               (cons nnfolder-current-group article)
              (goto-char (point-min))
-             (while (looking-at "From ")
-               (delete-char 5)
-               (insert "X-From-Line: ")
-               (forward-line 1))
-             t))))))
+             (search-forward (concat "\n" nnfolder-article-marker))
+             (cons nnfolder-current-group
+                   (string-to-int 
+                    (buffer-substring 
+                     (point) (progn (end-of-line) (point)))))))))))
 
 (defun nnfolder-request-group (group &optional server dont-check)
   (save-excursion
-    (nnfolder-possibly-change-group group)
-    (and (assoc group nnfolder-group-alist)
-        (progn
-          (if dont-check
-              t
-            (nnfolder-get-new-mail group))
-          (let* ((active (assoc group nnfolder-group-alist))
-                 (group (car active))
-                 (range (car (cdr active)))
-                 (minactive (car range))
-                 (maxactive (cdr range)))
-            ;; I've been getting stray 211 lines in my nnfolder active
-            ;; file.  So, let's make sure that doesn't happen. -SLB
-            (set-buffer nntp-server-buffer)
-            (erase-buffer)
-            (insert (format "211 %d %d %d %s\n" 
-                            (1+ (- maxactive minactive))
-                            minactive maxactive group))
-            t)))))
+    (nnmail-activate 'nnfolder)
+    (when (assoc group nnfolder-group-alist)
+      (nnfolder-possibly-change-group group)
+      (cond 
+       (dont-check
+       (nnheader-report 'nnfolder "Selected group %s" group)
+       t)
+       (t
+       (let* ((active (assoc group nnfolder-group-alist))
+              (group (car active))
+              (range (car (cdr active)))
+              (minactive (car range))
+              (maxactive (cdr range)))
+         (set-buffer nntp-server-buffer)
+         (erase-buffer)
+         (cond 
+          ((null active)
+           (nnheader-report 'nnfolder "No such group: %s" group))
+          (t
+           (nnheader-report 'nnfolder "Selected group %s" group)
+           (insert (format "211 %d %d %d %s\n" 
+                           (1+ (- maxactive minactive))
+                           minactive maxactive group))
+           t))))))))
+
+(defun nnfolder-request-scan (&optional group server)
+  (nnmail-get-new-mail
+   'nnfolder 
+   (lambda ()
+     (let ((bufs nnfolder-buffer-alist))
+       (save-excursion
+        (while bufs
+          (if (not (buffer-name (nth 1 (car bufs))))
+              (setq nnfolder-buffer-alist 
+                    (delq (car bufs) nnfolder-buffer-alist))
+            (set-buffer (nth 1 (car bufs)))
+            (and (buffer-modified-p) (save-buffer)))
+          (setq bufs (cdr bufs))))))
+   nnfolder-directory
+   group))
 
 ;; Don't close the buffer if we're not shutting down the server.  This way,
 ;; we can keep the buffer in the group buffer cache, and not have to grovel
@@ -265,25 +292,19 @@ such things as moving mail.  All buffers always get killed upon server close.")
   t)
 
 (defun nnfolder-request-create-group (group &optional server) 
-  (nnfolder-request-list)
-  (setq nnfolder-group-alist (nnmail-get-active))
+  (nnmail-activate 'nnfolder)
   (or (assoc group nnfolder-group-alist)
       (let (active)
        (setq nnfolder-group-alist 
-             (cons (list group (setq active (cons 0 0)))
+             (cons (list group (setq active (cons 1 0)))
                    nnfolder-group-alist))
        (nnmail-save-active nnfolder-group-alist nnfolder-active-file)))
   t)
 
 (defun nnfolder-request-list (&optional server)
-  (if server (nnfolder-get-new-mail))
   (save-excursion
-    (or nnfolder-group-alist
-       (nnmail-find-file nnfolder-active-file)
-       (progn
-         (setq nnfolder-group-alist (nnmail-get-active))
-         (nnmail-save-active nnfolder-group-alist nnfolder-active-file)
-         (nnmail-find-file nnfolder-active-file)))))
+    (nnmail-find-file nnfolder-active-file)
+    (setq nnfolder-group-alist (nnmail-get-active))))
 
 (defun nnfolder-request-newgroups (date &optional server)
   (nnfolder-request-list server))
@@ -295,28 +316,27 @@ such things as moving mail.  All buffers always get killed upon server close.")
 (defun nnfolder-request-post (&optional server)
   (mail-send-and-exit nil))
 
-(defalias 'nnfolder-request-post-buffer 'nnmail-request-post-buffer)
-
-(defun nnfolder-request-expire-articles (articles newsgroup &optional server force)
+(defun nnfolder-request-expire-articles 
+  (articles newsgroup &optional server force)
   (nnfolder-possibly-change-group newsgroup)
-  (let* ((days (or (and nnmail-expiry-wait-function
-                       (funcall nnmail-expiry-wait-function newsgroup))
-                  nnmail-expiry-wait))
-        article rest)
+  (let* ((is-old t)
+        rest)
+    (nnmail-activate 'nnfolder)
+
     (save-excursion 
       (set-buffer nnfolder-current-buffer)
-      (while articles
+      (while (and articles is-old)
        (goto-char (point-min))
        (if (search-forward (nnfolder-article-string (car articles)) nil t)
-           (if (or force
-                   (> (nnmail-days-between 
-                       (current-time-string)
-                       (buffer-substring 
-                        (point) (progn (end-of-line) (point))))
-                      days))
+           (if (setq is-old
+                     (nnmail-expired-article-p 
+                      newsgroup
+                      (buffer-substring 
+                       (point) (progn (end-of-line) (point))) 
+                      force nnfolder-inhibit-expiry))
                (progn
-                 (and gnus-verbose-backends
-                      (message "Deleting: %s" (car articles)))
+                 (nnheader-message 5 "Deleting article %d..." 
+                                   (car articles) newsgroup)
                  (nnfolder-delete-mail))
              (setq rest (cons (car articles) rest))))
        (setq articles (cdr articles)))
@@ -335,7 +355,7 @@ such things as moving mail.  All buffers always get killed upon server close.")
                                                  (match-end 0))))))
        (setcar active activemin))
       (nnmail-save-active nnfolder-group-alist nnfolder-active-file)
-      rest)))
+      (nconc rest articles))))
 
 (defun nnfolder-request-move-article
   (article group server accept-form &optional last)
@@ -351,7 +371,7 @@ such things as moving mail.  All buffers always get killed upon server close.")
        (insert-buffer-substring nntp-server-buffer)
        (goto-char (point-min))
        (while (re-search-forward 
-              "^X-Gnus-Newsgroup:" 
+              (concat "^" nnfolder-article-marker)
               (save-excursion (search-forward "\n\n" nil t) (point)) t)
         (delete-region (progn (beginning-of-line) (point))
                        (progn (forward-line 1) (point))))
@@ -370,13 +390,12 @@ such things as moving mail.  All buffers always get killed upon server close.")
     result))
 
 (defun nnfolder-request-accept-article (group &optional last)
-  (nnfolder-possibly-change-group group)
+  (and (stringp group) (nnfolder-possibly-change-group group))
   (let ((buf (current-buffer))
-       result beg)
+       result)
     (goto-char (point-min))
-    (if (looking-at "X-From-Line: ")
-       (replace-match "From ")
-      (insert "From nobody " (current-time-string) "\n"))
+    (when (looking-at "X-From-Line: ")
+      (replace-match "From "))
     (and 
      (nnfolder-request-list)
      (save-excursion
@@ -384,7 +403,7 @@ such things as moving mail.  All buffers always get killed upon server close.")
        (goto-char (point-min))
        (search-forward "\n\n" nil t)
        (forward-line -1)
-       (while (re-search-backward "^X-Gnus-Newsgroup: " nil t)
+       (while (re-search-backward (concat "^" nnfolder-article-marker) nil t)
         (delete-region (point) (progn (forward-line 1) (point))))
        (setq result (car (nnfolder-save-mail (and (stringp group) group)))))
      (save-excursion
@@ -405,9 +424,56 @@ such things as moving mail.  All buffers always get killed upon server close.")
       (and (buffer-modified-p) (save-buffer))
       t)))
 
+(defun nnfolder-request-delete-group (group &optional force server)
+  (nnfolder-close-group group server t)
+  ;; Delete all articles in GROUP.
+  (if (not force)
+      ()                               ; Don't delete the articles.
+    ;; Delete the file that holds the group.
+    (condition-case nil
+       (delete-file (concat (file-name-as-directory nnfolder-directory)
+                            group))
+      (error nil)))
+  ;; Remove the group from all structures.
+  (setq nnfolder-group-alist 
+       (delq (assoc group nnfolder-group-alist) nnfolder-group-alist)
+       nnfolder-current-group nil
+       nnfolder-current-buffer nil)
+  ;; Save the active file.
+  (nnmail-save-active nnfolder-group-alist nnfolder-active-file)
+  t)
+
+(defun nnfolder-request-rename-group (group new-name &optional server)
+  (nnfolder-possibly-change-group group)
+  (save-excursion
+    (set-buffer nnfolder-current-buffer)
+    (and (file-writable-p buffer-file-name)
+        (condition-case ()
+            (progn
+              (rename-file buffer-file-name
+                           (concat (file-name-as-directory nnfolder-directory)
+                                   new-name))
+              t)
+          (error nil))
+        ;; That went ok, so we change the internal structures.
+        (let ((entry (assoc group nnfolder-group-alist)))
+          (and entry (setcar entry new-name))
+          (setq nnfolder-current-buffer nil
+                nnfolder-current-group nil)
+          ;; Save the new group alist.
+          (nnmail-save-active nnfolder-group-alist nnfolder-active-file)
+          ;; We kill the buffer instead of renaming it and stuff.
+          (kill-buffer (current-buffer))
+          t))))
+
 \f
 ;;; Internal functions.
 
+(defun nnfolder-article-string (article)
+  (if (numberp article)
+      (concat "\n" nnfolder-article-marker (int-to-string article) " ")
+    (concat "\nMessage-ID: " article)))
+
 (defun nnfolder-delete-mail (&optional force leave-delim)
   ;; Beginning of the article.
   (save-excursion
@@ -429,16 +495,18 @@ such things as moving mail.  All buffers always get killed upon server close.")
 
 (defun nnfolder-possibly-change-group (group)
   (or (file-exists-p nnfolder-directory)
-      (make-directory (directory-file-name nnfolder-directory)))
+      (make-directory (directory-file-name nnfolder-directory) t))
   (nnfolder-possibly-activate-groups nil)
   (or (assoc group nnfolder-group-alist)
-      (not (file-exists-p (concat nnfolder-directory group)))
+      (not (file-exists-p (concat (file-name-as-directory nnfolder-directory)
+                                 group)))
       (progn
        (setq nnfolder-group-alist 
              (cons (list group (cons 1 0)) nnfolder-group-alist))
        (nnmail-save-active nnfolder-group-alist nnfolder-active-file)))
   (let (inf file)
     (if (and (equal group nnfolder-current-group)
+            nnfolder-current-buffer
             (buffer-name nnfolder-current-buffer))
        ()
       (setq nnfolder-current-group group)
@@ -452,12 +520,14 @@ such things as moving mail.  All buffers always get killed upon server close.")
       ;; If the buffer is not live, make sure it isn't in the alist.  If it
       ;; is live, verify that nobody else has touched the file since last
       ;; time.
-      (if (or (not (buffer-name nnfolder-current-buffer))
+      (if (or (not (and nnfolder-current-buffer
+                       (buffer-name nnfolder-current-buffer)))
              (not (and (bufferp nnfolder-current-buffer)
                        (verify-visited-file-modtime 
                         nnfolder-current-buffer))))
          (progn
-           (if (and (buffer-name nnfolder-current-buffer)
+           (if (and nnfolder-current-buffer
+                    (buffer-name nnfolder-current-buffer)
                     (bufferp nnfolder-current-buffer))
                (kill-buffer nnfolder-current-buffer))
            (setq nnfolder-buffer-alist (delq inf nnfolder-buffer-alist))
@@ -466,15 +536,16 @@ such things as moving mail.  All buffers always get killed upon server close.")
       (if inf
          ()
        (save-excursion
-         (setq file (concat nnfolder-directory group))
-         (if (or (file-directory-p file)
-                 (file-symlink-p file))
+         (setq file (concat (file-name-as-directory nnfolder-directory)
+                            group))
+         (if (file-directory-p (file-truename file))
              ()
            (if (not (file-exists-p file))
                (write-region 1 1 file t 'nomesg))
+           (setq nnfolder-current-buffer 
+                 (set-buffer (nnfolder-read-folder file)))
            (setq nnfolder-buffer-alist (cons (list group (current-buffer))
-                                             nnfolder-buffer-alist))
-           (set-buffer (nnfolder-read-folder file)))))))
+                                             nnfolder-buffer-alist)))))))
   (setq nnfolder-current-group group))
 
 (defun nnfolder-save-mail (&optional group)
@@ -483,7 +554,18 @@ such things as moving mail.  All buffers always get killed upon server close.")
          (if group (list (list group "")) nnmail-split-methods))
         (group-art-list
          (nreverse (nnmail-article-group 'nnfolder-active-number)))
+        (delim (concat "^" rmail-unix-mail-delimiter))
         save-list group-art)
+    (goto-char (point-min))
+    ;; This might come from somewhere else.
+    (unless (looking-at delim)
+      (insert "From nobody " (current-time-string) "\n")
+      (goto-char (point-min)))
+    ;; Quote all "From " lines in the article.
+    (forward-line 1)
+    (while (re-search-forward delim nil t)
+      (beginning-of-line)
+      (insert "> "))
     (setq save-list group-art-list)
     (nnmail-insert-lines)
     (nnmail-insert-xref group-art-list)
@@ -499,7 +581,7 @@ such things as moving mail.  All buffers always get killed upon server close.")
       (search-forward "\n\n" nil t)
       (forward-line -1)
       (while (search-backward (concat "\n" nnfolder-article-marker) nil t)
-       (delete-region (point) (progn (forward-line 1) (point))))
+       (delete-region (1+ (point)) (progn (forward-line 2) (point))))
 
       ;; Insert the new newsgroup marker.
       (nnfolder-possibly-change-group (car group-art))
@@ -527,24 +609,32 @@ such things as moving mail.  All buffers always get killed upon server close.")
 (defun nnfolder-possibly-activate-groups (&optional group)
   (save-excursion
     ;; If we're looking for the activation of a specific group, find out
-    ;; it's real name and switch to it.
+    ;; its real name and switch to it.
     (if group (nnfolder-possibly-change-group group))
     ;; If the group alist isn't active, activate it now.
-    (if (not nnfolder-group-alist)
-       (progn
-         (nnfolder-request-list)
-         (setq nnfolder-group-alist (nnmail-get-active))))))
+    (nnmail-activate 'nnfolder)))
 
 (defun nnfolder-active-number (group)
   (save-excursion 
-    (nnfolder-possibly-activate-groups group)
-    (let ((active (car (cdr (assoc group nnfolder-group-alist)))))
-      (setcdr active (1+ (cdr active)))
-      (cdr active))))
+    ;; Find the next article number in GROUP.
+    (prog1
+       (let ((active (car (cdr (assoc group nnfolder-group-alist)))))
+         (if active
+             (setcdr active (1+ (cdr active)))
+           ;; This group is new, so we create a new entry for it.
+           ;; This might be a bit naughty... creating groups on the drop of
+           ;; a hat, but I don't know...
+           (setq nnfolder-group-alist 
+                 (cons (list group (setq active (cons 1 1)))
+                       nnfolder-group-alist)))
+         (cdr active))
+      (nnmail-save-active nnfolder-group-alist nnfolder-active-file)
+      (nnfolder-possibly-activate-groups group))))
+
 
 ;; This method has a problem if you've accidentally let the active list get
 ;; out of sync with the files.  This could happen, say, if you've
-;; accidentally gotten new mail with something other than (ding) (but why
+;; accidentally gotten new mail with something other than Gnus (but why
 ;; would _that_ ever happen? :-).  In that case, we will be in the middle of
 ;; processing the file, ready to add new X-Gnus article number markers, and
 ;; we'll run accross a message with no ID yet - the active list _may_not_ be
@@ -563,7 +653,8 @@ such things as moving mail.  All buffers always get killed upon server close.")
     ;; We should be paranoid here and make sure the group is in the alist,
     ;; and add it if it isn't.
     ;;(if (not (assoc nnfoler-current-group nnfolder-group-alist)
-    (set-buffer (setq nnfolder-current-buffer (find-file-noselect file)))
+    (set-buffer (setq nnfolder-current-buffer 
+                     (find-file-noselect file nil 'raw)))
     (buffer-disable-undo (current-buffer))
     (let ((delim (concat "^" rmail-unix-mail-delimiter))
          (marker (concat "\n" nnfolder-article-marker))
@@ -588,12 +679,12 @@ such things as moving mail.  All buffers always get killed upon server close.")
            (while (and (search-forward marker nil t)
                        (re-search-forward number nil t))
              (let ((newnum (string-to-number (buffer-substring
-                                             (match-beginning 0)
-                                             (match-end 0)))))
+                                              (match-beginning 0)
+                                              (match-end 0)))))
                (setq activenumber (max activenumber newnum))
                (setq activemin (min activemin newnum))))
-           (setcar active (min activemin activenumber))
-           (setcdr active activenumber)
+           (setcar active (max 1 (min activemin activenumber)))
+           (setcdr active (max activenumber (cdr active)))
            (goto-char (point-min))))
 
       ;; Keep track of the active number on our own, and insert it back into
@@ -606,7 +697,10 @@ such things as moving mail.  All buffers always get killed upon server close.")
       (while (not (= end (point-max)))
        (setq start (marker-position end))
        (goto-char end)
-       (end-of-line)
+       ;; There may be more than one "From " line, so we skip past
+       ;; them.  
+       (while (looking-at delim) 
+         (forward-line 1))
        (set-marker end (or (and (re-search-forward delim nil t)
                                 (match-beginning 0))
                            (point-max)))
@@ -615,63 +709,28 @@ such things as moving mail.  All buffers always get killed upon server close.")
            (progn
              (narrow-to-region start end)
              (nnmail-insert-lines)
-             (setq activenumber (1+ activenumber))
-             (nnfolder-insert-newsgroup-line (cons nil activenumber))
+             (nnfolder-insert-newsgroup-line
+              (cons nil (nnfolder-active-number nnfolder-current-group)))
              (widen))))
 
       ;; Make absolutely sure that the active list reflects reality!
-      (setcdr active activenumber)
       (nnmail-save-active nnfolder-group-alist nnfolder-active-file)
       (current-buffer))))
 
-(defun nnfolder-get-new-mail (&optional group)
-  "Read new incoming mail."
-  (let* ((spools (nnmail-get-spool-files group))
-        (all-spools spools)
-        (group-in group)
-        incomings incoming)
-    (if (or (not nnfolder-get-new-mail) (not nnmail-spool-file))
-       ()
-      ;; We first activate all the groups.
-      (nnfolder-possibly-activate-groups nil)
-      ;; The we go through all the existing spool files and split the
-      ;; mail from each.
-      (while spools
-       (and
-        (file-exists-p (car spools))
-        (> (nth 7 (file-attributes (car spools))) 0)
-        (progn
-          (and gnus-verbose-backends 
-               (message "nnfolder: Reading incoming mail..."))
-          (setq incoming 
-                (nnmail-move-inbox 
-                 (car spools) (concat nnfolder-directory "Incoming")))
-          (setq incomings (cons incoming incomings))
-          (setq group (nnmail-get-split-group (car spools) group-in))
-          (nnmail-split-incoming incoming 'nnfolder-save-mail nil group)))
-       (setq spools (cdr spools)))
-      ;; If we did indeed read any incoming spools, we save all info. 
-      (if incoming 
-         (progn
-           (nnmail-save-active nnfolder-group-alist nnfolder-active-file)
-           (run-hooks 'nnmail-read-incoming-hook)
-           (and gnus-verbose-backends
-                (message "nnfolder: Reading incoming mail...done"))))
-      (let ((bufs nnfolder-buffer-alist))
-       (save-excursion
-         (while bufs
-           (if (not (buffer-name (nth 1 (car bufs))))
-               (setq nnfolder-buffer-alist 
-                     (delq (car bufs) nnfolder-buffer-alist))
-             (set-buffer (nth 1 (car bufs)))
-             (and (buffer-modified-p) (save-buffer)))
-           (setq bufs (cdr bufs)))))
-      (while incomings
-       (and 
-        nnmail-delete-incoming
-        (file-writable-p incoming)
-        (delete-file incoming))
-       (setq incomings (cdr incomings))))))
+;;;###autoload
+(defun nnfolder-generate-active-file ()
+  "Look for mbox folders in the nnfolder directory and make them into groups."
+  (interactive)
+  (nnmail-activate 'nnfolder)
+  (let ((files (directory-files nnfolder-directory))
+       file group)
+    (while (setq file (pop files))
+      (when (nnheader-mail-file-mbox-p file)
+       (nnheader-message 5 "Adding group %s..." file)
+       (push (list file (cons 1 0)) nnfolder-group-alist)
+       (nnfolder-read-folder file)
+       (nnfolder-close-group file))
+      (message ""))))
 
 (provide 'nnfolder)