c9d3a6d19a296ffbdc7565c15f69f7b4d7a9455e
[gnus] / lisp / gnus-cache.el
1 ;;; gnus-cache.el --- cache interface for Gnus
2 ;; Copyright (C) 1995,96 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
5 ;; Keywords: news
6
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
23
24 ;;; Commentary:
25
26 ;;; Code:
27
28 (require 'gnus)
29 (require 'gnus-int)
30 (require 'gnus-range)
31 (require 'gnus-sum)
32 (require 'gnus-start)
33
34 (defgroup gnus-cache nil
35   "Cache interface."
36   :group 'gnus)
37
38 (defcustom gnus-cache-directory
39   (nnheader-concat gnus-directory "cache/")
40   "*The directory where cached articles will be stored."
41   :group 'gnus-cache
42   :type 'directory)
43
44 (defcustom gnus-cache-active-file 
45   (concat (file-name-as-directory gnus-cache-directory) "active")
46   "*The cache active file."
47   :group 'gnus-cache
48   :type 'file)
49
50 (defcustom gnus-cache-enter-articles '(ticked dormant)
51   "Classes of articles to enter into the cache."
52   :group 'gnus-cache
53   :type '(set (const ticked) (const dormant) (const unread) (const read)))
54
55 (defcustom gnus-cache-remove-articles '(read)
56   "Classes of articles to remove from the cache."
57   :group 'gnus-cache
58   :type '(set (const ticked) (const dormant) (const unread) (const read)))
59
60 (defcustom gnus-uncacheable-groups nil
61   "*Groups that match this regexp will not be cached.
62
63 If you want to avoid caching your nnml groups, you could set this
64 variable to \"^nnml\"."
65   :group 'gnus-cache
66   :type '(choice (const :tag "off" nil)
67                  regexp))
68
69 \f
70
71 ;;; Internal variables.
72
73 (defvar gnus-cache-removable-articles nil)
74 (defvar gnus-cache-buffer nil)
75 (defvar gnus-cache-active-hashtb nil)
76 (defvar gnus-cache-active-altered nil)
77
78 (eval-and-compile
79   (autoload 'nnml-generate-nov-databases-1 "nnml")
80   (autoload 'nnvirtual-find-group-art "nnvirtual"))
81
82 \f
83
84 ;;; Functions called from Gnus.
85
86 (defun gnus-cache-open ()
87   "Initialize the cache."
88   (when (or (file-exists-p gnus-cache-directory)
89             (and gnus-use-cache
90                  (not (eq gnus-use-cache 'passive))))
91     (gnus-cache-read-active)))
92
93 (condition-case ()
94     (gnus-add-shutdown 'gnus-cache-close 'gnus)
95   ;; Complexities of byte-compiling makes this kludge necessary.  Eeek.
96   (error nil))
97
98 (defun gnus-cache-close ()
99   "Shut down the cache."
100   (gnus-cache-write-active)
101   (gnus-cache-save-buffers)
102   (setq gnus-cache-active-hashtb nil))
103
104 (defun gnus-cache-save-buffers ()
105   ;; save the overview buffer if it exists and has been modified
106   ;; delete empty cache subdirectories
107   (when gnus-cache-buffer
108     (let ((buffer (cdr gnus-cache-buffer))
109           (overview-file (gnus-cache-file-name
110                           (car gnus-cache-buffer) ".overview")))
111       ;; write the overview only if it was modified
112       (when (buffer-modified-p buffer)
113         (save-excursion
114           (set-buffer buffer)
115           (if (> (buffer-size) 0)
116               ;; Non-empty overview, write it to a file.
117               (gnus-write-buffer overview-file)
118             ;; Empty overview file, remove it
119             (when (file-exists-p overview-file)
120               (delete-file overview-file))
121             ;; If possible, remove group's cache subdirectory.
122             (condition-case nil
123                 ;; FIXME: we can detect the error type and warn the user
124                 ;; of any inconsistencies (articles w/o nov entries?).
125                 ;; for now, just be conservative...delete only if safe -- sj
126                 (delete-directory (file-name-directory overview-file))
127               (error nil)))))
128       ;; Kill the buffer -- it's either unmodified or saved.
129       (gnus-kill-buffer buffer)
130       (setq gnus-cache-buffer nil))))
131
132 (defun gnus-cache-possibly-enter-article 
133   (group article headers ticked dormant unread &optional force)
134   (when (and (or force (not (eq gnus-use-cache 'passive)))
135              (numberp article)
136              (> article 0)
137              (vectorp headers))
138                                         ; This might be a dummy article.
139     ;; If this is a virtual group, we find the real group.
140     (when (gnus-virtual-group-p group)
141       (let ((result (nnvirtual-find-group-art 
142                      (gnus-group-real-name group) article)))
143         (setq group (car result)
144               headers (copy-sequence headers))
145         (mail-header-set-number headers (cdr result))))
146     (let ((number (mail-header-number headers))
147           file dir)
148       (when (and (> number 0)           ; Reffed article.
149                  (or force
150                      (and (or (not gnus-uncacheable-groups)
151                               (not (string-match
152                                     gnus-uncacheable-groups group)))
153                           (gnus-cache-member-of-class
154                            gnus-cache-enter-articles ticked dormant unread)))
155                  (not (file-exists-p (setq file (gnus-cache-file-name
156                                                  group number)))))
157         ;; Possibly create the cache directory.
158         (gnus-make-directory (setq dir (file-name-directory file)))
159         ;; Save the article in the cache.
160         (if (file-exists-p file)
161             t                           ; The article already is saved.
162           (save-excursion
163             (set-buffer nntp-server-buffer)
164             (let ((gnus-use-cache nil))
165               (gnus-request-article-this-buffer number group))
166             (when (> (buffer-size) 0)
167               (gnus-write-buffer file)
168               (gnus-cache-change-buffer group)
169               (set-buffer (cdr gnus-cache-buffer))
170               (goto-char (point-max))
171               (forward-line -1)
172               (while (condition-case ()
173                          (when (not (bobp))
174                            (> (read (current-buffer)) number))
175                        (error
176                         ;; The line was malformed, so we just remove it!!
177                         (gnus-delete-line)
178                         t))
179                 (forward-line -1))
180               (if (bobp)
181                   (if (not (eobp))
182                       (progn
183                         (beginning-of-line)
184                         (when (< (read (current-buffer)) number)
185                           (forward-line 1)))
186                     (beginning-of-line))
187                 (forward-line 1))
188               (beginning-of-line)
189               ;; [number subject from date id references chars lines xref]
190               (insert (format "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t\n"
191                               (mail-header-number headers)
192                               (mail-header-subject headers)
193                               (mail-header-from headers)
194                               (mail-header-date headers)
195                               (mail-header-id headers)
196                               (or (mail-header-references headers) "")
197                               (or (mail-header-chars headers) "")
198                               (or (mail-header-lines headers) "")
199                               (or (mail-header-xref headers) "")))
200               ;; Update the active info.
201               (set-buffer gnus-summary-buffer)
202               (gnus-cache-update-active group number)
203               (push article gnus-newsgroup-cached)
204               (gnus-summary-update-secondary-mark article))
205             t))))))
206
207 (defun gnus-cache-enter-remove-article (article)
208   "Mark ARTICLE for later possible removal."
209   (when article
210     (push article gnus-cache-removable-articles)))
211
212 (defun gnus-cache-possibly-remove-articles ()
213   "Possibly remove some of the removable articles."
214   (if (not (gnus-virtual-group-p gnus-newsgroup-name))
215       (gnus-cache-possibly-remove-articles-1)
216     (let ((arts gnus-cache-removable-articles)
217           ga)
218       (while arts
219         (when (setq ga (nnvirtual-find-group-art
220                         (gnus-group-real-name gnus-newsgroup-name) (pop arts)))
221           (let ((gnus-cache-removable-articles (list (cdr ga)))
222                 (gnus-newsgroup-name (car ga)))
223             (gnus-cache-possibly-remove-articles-1)))))
224     (setq gnus-cache-removable-articles nil)))
225
226 (defun gnus-cache-possibly-remove-articles-1 ()
227   "Possibly remove some of the removable articles."
228   (unless (eq gnus-use-cache 'passive)
229     (let ((articles gnus-cache-removable-articles)
230           (cache-articles gnus-newsgroup-cached)
231           article)
232       (gnus-cache-change-buffer gnus-newsgroup-name)
233       (while articles
234         (when (memq (setq article (pop articles)) cache-articles)
235           ;; The article was in the cache, so we see whether we are
236           ;; supposed to remove it from the cache.
237           (gnus-cache-possibly-remove-article
238            article (memq article gnus-newsgroup-marked)
239            (memq article gnus-newsgroup-dormant)
240            (or (memq article gnus-newsgroup-unreads)
241                (memq article gnus-newsgroup-unselected))))))
242     ;; The overview file might have been modified, save it
243     ;; safe because we're only called at group exit anyway.
244     (gnus-cache-save-buffers)))
245
246 (defun gnus-cache-request-article (article group)
247   "Retrieve ARTICLE in GROUP from the cache."
248   (let ((file (gnus-cache-file-name group article))
249         (buffer-read-only nil))
250     (when (file-exists-p file)
251       (erase-buffer)
252       (gnus-kill-all-overlays)
253       (insert-file-contents file)
254       t)))
255
256 (defun gnus-cache-possibly-alter-active (group active)
257   "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
258   (when gnus-cache-active-hashtb
259     (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb)))
260       (and cache-active 
261            (< (car cache-active) (car active))
262            (setcar active (car cache-active)))
263       (and cache-active
264            (> (cdr cache-active) (cdr active))
265            (setcdr active (cdr cache-active))))))
266
267 (defun gnus-cache-retrieve-headers (articles group &optional fetch-old)
268   "Retrieve the headers for ARTICLES in GROUP."
269   (let ((cached 
270          (setq gnus-newsgroup-cached (gnus-cache-articles-in-group group))))
271     (if (not cached)
272         ;; No cached articles here, so we just retrieve them
273         ;; the normal way.
274         (let ((gnus-use-cache nil))
275           (gnus-retrieve-headers articles group fetch-old))
276       (let ((uncached-articles (gnus-sorted-intersection
277                                 (gnus-sorted-complement articles cached)
278                                 articles))
279             (cache-file (gnus-cache-file-name group ".overview"))
280             type)
281         ;; We first retrieve all the headers that we don't have in 
282         ;; the cache.
283         (let ((gnus-use-cache nil))
284           (when uncached-articles
285             (setq type (and articles 
286                             (gnus-retrieve-headers 
287                              uncached-articles group fetch-old)))))
288         (gnus-cache-save-buffers)
289         ;; Then we insert the cached headers.
290         (save-excursion
291           (cond
292            ((not (file-exists-p cache-file))
293             ;; There are no cached headers.
294             type)
295            ((null type)
296             ;; There were no uncached headers (or retrieval was 
297             ;; unsuccessful), so we use the cached headers exclusively.
298             (set-buffer nntp-server-buffer)
299             (erase-buffer)
300             (insert-file-contents cache-file)
301             'nov)
302            ((eq type 'nov)
303             ;; We have both cached and uncached NOV headers, so we
304             ;; braid them.
305             (gnus-cache-braid-nov group cached)
306             type)
307            (t
308             ;; We braid HEADs.
309             (gnus-cache-braid-heads group (gnus-sorted-intersection
310                                            cached articles))
311             type)))))))
312
313 (defun gnus-cache-enter-article (&optional n)
314   "Enter the next N articles into the cache.
315 If not given a prefix, use the process marked articles instead.
316 Returns the list of articles entered."
317   (interactive "P")
318   (gnus-set-global-variables)
319   (let ((articles (gnus-summary-work-articles n))
320         article out)
321     (while articles
322       (setq article (pop articles))
323       (when (gnus-cache-possibly-enter-article 
324              gnus-newsgroup-name article (gnus-summary-article-header article)
325              nil nil nil t)
326         (push article out))
327       (gnus-summary-remove-process-mark article)
328       (gnus-summary-update-secondary-mark article))
329     (gnus-summary-next-subject 1)
330     (gnus-summary-position-point)
331     (nreverse out)))
332
333 (defun gnus-cache-remove-article (n)
334   "Remove the next N articles from the cache.
335 If not given a prefix, use the process marked articles instead.
336 Returns the list of articles removed."
337   (interactive "P")
338   (gnus-set-global-variables)
339   (gnus-cache-change-buffer gnus-newsgroup-name)
340   (let ((articles (gnus-summary-work-articles n))
341         article out)
342     (while articles
343       (setq article (pop articles))
344       (when (gnus-cache-possibly-remove-article article nil nil nil t)
345         (push article out))
346       (gnus-summary-remove-process-mark article)
347       (gnus-summary-update-secondary-mark article))
348     (gnus-summary-next-subject 1)
349     (gnus-summary-position-point)
350     (nreverse out)))
351
352 (defun gnus-cached-article-p (article)
353   "Say whether ARTICLE is cached in the current group."
354   (memq article gnus-newsgroup-cached))
355
356 (defun gnus-summary-insert-cached-articles ()
357   "Insert all the articles cached for this group into the current buffer."
358   (interactive)
359   (let ((cached gnus-newsgroup-cached))
360     (unless cached
361       (error "No cached articles for this group"))
362     (while cached
363       (gnus-summary-goto-subject (pop cached) t))))
364
365 ;;; Internal functions.
366
367 (defun gnus-cache-change-buffer (group)
368   (and gnus-cache-buffer
369        ;; See if the current group's overview cache has been loaded.
370        (or (string= group (car gnus-cache-buffer))
371            ;; Another overview cache is current, save it.
372            (gnus-cache-save-buffers)))
373   ;; if gnus-cache buffer is nil, create it
374   (unless gnus-cache-buffer
375     ;; Create cache buffer
376     (save-excursion
377       (setq gnus-cache-buffer
378             (cons group
379                   (set-buffer (get-buffer-create " *gnus-cache-overview*"))))
380       (buffer-disable-undo (current-buffer))
381       ;; Insert the contents of this group's cache overview.
382       (erase-buffer)
383       (let ((file (gnus-cache-file-name group ".overview")))
384         (when (file-exists-p file)
385           (insert-file-contents file)))
386       ;; We have a fresh (empty/just loaded) buffer, 
387       ;; mark it as unmodified to save a redundant write later.
388       (set-buffer-modified-p nil))))
389
390 ;; Return whether an article is a member of a class.
391 (defun gnus-cache-member-of-class (class ticked dormant unread)
392   (or (and ticked (memq 'ticked class))
393       (and dormant (memq 'dormant class))
394       (and unread (memq 'unread class))
395       (and (not unread) (not ticked) (not dormant) (memq 'read class))))
396
397 (defun gnus-cache-file-name (group article)
398   (concat (file-name-as-directory gnus-cache-directory)
399           (file-name-as-directory
400            (if (gnus-use-long-file-name 'not-cache)
401                group 
402              (let ((group (nnheader-replace-chars-in-string group ?/ ?_)))
403                ;; Translate the first colon into a slash.
404                (when (string-match ":" group)
405                  (aset group (match-beginning 0) ?/))
406                (nnheader-replace-chars-in-string group ?. ?/))))
407           (if (stringp article) article (int-to-string article))))
408
409 (defun gnus-cache-update-article (group article)
410   "If ARTICLE is in the cache, remove it and re-enter it."
411   (when (gnus-cache-possibly-remove-article article nil nil nil t)
412     (let ((gnus-use-cache nil))
413       (gnus-cache-possibly-enter-article 
414        gnus-newsgroup-name article (gnus-summary-article-header article)
415        nil nil nil t))))
416
417 (defun gnus-cache-possibly-remove-article (article ticked dormant unread 
418                                                    &optional force)
419   "Possibly remove ARTICLE from the cache."
420   (let ((group gnus-newsgroup-name)
421         (number article)
422         file)
423     ;; If this is a virtual group, we find the real group.
424     (when (gnus-virtual-group-p group)
425       (let ((result (nnvirtual-find-group-art 
426                      (gnus-group-real-name group) article)))
427         (setq group (car result)
428               number (cdr result))))
429     (setq file (gnus-cache-file-name group number))
430     (when (and (file-exists-p file)
431                (or force
432                    (gnus-cache-member-of-class
433                     gnus-cache-remove-articles ticked dormant unread)))
434       (save-excursion
435         (delete-file file)
436         (set-buffer (cdr gnus-cache-buffer))
437         (goto-char (point-min))
438         (when (or (looking-at (concat (int-to-string number) "\t"))
439                   (search-forward (concat "\n" (int-to-string number) "\t")
440                                   (point-max) t))
441           (delete-region (progn (beginning-of-line) (point))
442                          (progn (forward-line 1) (point)))))
443       (setq gnus-newsgroup-cached
444             (delq article gnus-newsgroup-cached))
445       (gnus-summary-update-secondary-mark article)
446       t)))
447
448 (defun gnus-cache-articles-in-group (group)
449   "Return a sorted list of cached articles in GROUP."
450   (let ((dir (file-name-directory (gnus-cache-file-name group 1))))
451     (when (file-exists-p dir)
452       (sort (mapcar (lambda (name) (string-to-int name))
453                     (directory-files dir nil "^[0-9]+$" t))
454             '<))))
455
456 (defun gnus-cache-braid-nov (group cached)
457   (let ((cache-buf (get-buffer-create " *gnus-cache*"))
458         beg end)
459     (gnus-cache-save-buffers)
460     (save-excursion
461       (set-buffer cache-buf)
462       (buffer-disable-undo (current-buffer))
463       (erase-buffer)
464       (insert-file-contents (gnus-cache-file-name group ".overview"))
465       (goto-char (point-min))
466       (insert "\n")
467       (goto-char (point-min)))
468     (set-buffer nntp-server-buffer)
469     (goto-char (point-min))
470     (while cached
471       (while (and (not (eobp))
472                   (< (read (current-buffer)) (car cached)))
473         (forward-line 1))
474       (beginning-of-line)
475       (save-excursion
476         (set-buffer cache-buf)
477         (if (search-forward (concat "\n" (int-to-string (car cached)) "\t")
478                             nil t)
479             (setq beg (progn (beginning-of-line) (point))
480                   end (progn (end-of-line) (point)))
481           (setq beg nil)))
482       (when beg
483         (insert-buffer-substring cache-buf beg end)
484         (insert "\n"))
485       (setq cached (cdr cached)))
486     (kill-buffer cache-buf)))
487
488 (defun gnus-cache-braid-heads (group cached)
489   (let ((cache-buf (get-buffer-create " *gnus-cache*")))
490     (save-excursion
491       (set-buffer cache-buf)
492       (buffer-disable-undo (current-buffer))
493       (erase-buffer))
494     (set-buffer nntp-server-buffer)
495     (goto-char (point-min))
496     (while cached
497       (while (and (not (eobp))
498                   (looking-at "2.. +\\([0-9]+\\) ")
499                   (< (progn (goto-char (match-beginning 1))
500                             (read (current-buffer)))
501                      (car cached)))
502         (search-forward "\n.\n" nil 'move))
503       (beginning-of-line)
504       (save-excursion
505         (set-buffer cache-buf)
506         (erase-buffer)
507         (insert-file-contents (gnus-cache-file-name group (car cached)))
508         (goto-char (point-min))
509         (insert "220 ")
510         (princ (car cached) (current-buffer))
511         (insert " Article retrieved.\n")
512         (search-forward "\n\n" nil 'move)
513         (delete-region (point) (point-max))
514         (forward-char -1)
515         (insert "."))
516       (insert-buffer-substring cache-buf)
517       (setq cached (cdr cached)))
518     (kill-buffer cache-buf)))
519
520 ;;;###autoload
521 (defun gnus-jog-cache ()
522   "Go through all groups and put the articles into the cache.
523
524 Usage:
525 $ emacs -batch -l ~/.emacs -l gnus -f gnus-jog-cache"
526   (interactive)
527   (let ((gnus-mark-article-hook nil)
528         (gnus-expert-user t)
529         (nnmail-spool-file nil)
530         (gnus-use-dribble-file nil)
531         (gnus-novice-user nil)
532         (gnus-large-newsgroup nil))
533     ;; Start Gnus.
534     (gnus)
535     ;; Go through all groups...
536     (gnus-group-mark-buffer)
537     (gnus-group-universal-argument 
538      nil nil 
539      (lambda ()
540        (gnus-summary-read-group (gnus-group-group-name) nil t)
541        ;; ... and enter the articles into the cache.
542        (when (eq major-mode 'gnus-summary-mode)
543          (gnus-uu-mark-buffer)
544          (gnus-cache-enter-article)
545          (kill-buffer (current-buffer)))))))
546
547 (defun gnus-cache-read-active (&optional force)
548   "Read the cache active file."
549   (gnus-make-directory gnus-cache-directory)
550   (if (not (and (file-exists-p gnus-cache-active-file)
551                 (or force (not gnus-cache-active-hashtb))))
552       ;; There is no active file, so we generate one.
553       (gnus-cache-generate-active)
554     ;; We simply read the active file.
555     (save-excursion
556       (gnus-set-work-buffer)
557       (insert-file-contents gnus-cache-active-file)
558       (gnus-active-to-gnus-format
559        nil (setq gnus-cache-active-hashtb 
560                  (gnus-make-hashtable 
561                   (count-lines (point-min) (point-max)))))
562       (setq gnus-cache-active-altered nil))))
563        
564 (defun gnus-cache-write-active (&optional force)
565   "Write the active hashtb to the active file."
566   (when (or force
567             (and gnus-cache-active-hashtb
568                  gnus-cache-active-altered))
569     (nnheader-temp-write gnus-cache-active-file
570       (mapatoms
571        (lambda (sym)
572          (when (and sym (boundp sym))
573            (insert (format "%s %d %d y\n"
574                            (symbol-name sym) (cdr (symbol-value sym))
575                            (car (symbol-value sym))))))
576        gnus-cache-active-hashtb))
577     ;; Mark the active hashtb as unaltered.
578     (setq gnus-cache-active-altered nil)))
579
580 (defun gnus-cache-update-active (group number &optional low)
581   "Update the upper bound of the active info of GROUP to NUMBER.
582 If LOW, update the lower bound instead."
583   (let ((active (gnus-gethash group gnus-cache-active-hashtb)))
584     (if (null active)
585         ;; We just create a new active entry for this group.
586         (gnus-sethash group (cons number number) gnus-cache-active-hashtb)
587       ;; Update the lower or upper bound.
588       (if low
589           (setcar active number)
590         (setcdr active number))
591       ;; Mark the active hashtb as altered.
592       (setq gnus-cache-active-altered t))))
593
594 ;;;###autoload
595 (defun gnus-cache-generate-active (&optional directory)
596   "Generate the cache active file."
597   (interactive)
598   (let* ((top (null directory))
599          (directory (expand-file-name (or directory gnus-cache-directory)))
600          (files (directory-files directory 'full))
601          (group 
602           (if top
603               ""
604             (string-match 
605              (concat "^" (file-name-as-directory
606                           (expand-file-name gnus-cache-directory)))
607              (directory-file-name directory))
608             (nnheader-replace-chars-in-string 
609              (substring (directory-file-name directory) (match-end 0))
610              ?/ ?.)))
611          nums alphs)
612     (when top
613       (gnus-message 5 "Generating the cache active file...")
614       (setq gnus-cache-active-hashtb (gnus-make-hashtable 123)))
615     ;; Separate articles from all other files and directories.
616     (while files
617       (if (string-match "^[0-9]+$" (file-name-nondirectory (car files)))
618           (push (string-to-int (file-name-nondirectory (pop files))) nums)
619         (push (pop files) alphs)))
620     ;; If we have nums, then this is probably a valid group.
621     (when (setq nums (sort nums '<))
622       (gnus-sethash group (cons (car nums) (gnus-last-element nums))
623                     gnus-cache-active-hashtb))
624     ;; Go through all the other files.
625     (while alphs
626       (when (and (file-directory-p (car alphs))
627                  (not (string-match "^\\.\\.?$"
628                                     (file-name-nondirectory (car alphs)))))
629         ;; We descend directories.
630         (gnus-cache-generate-active (car alphs)))
631       (setq alphs (cdr alphs)))
632     ;; Write the new active file.
633     (when top
634       (gnus-cache-write-active t)
635       (gnus-message 5 "Generating the cache active file...done"))))
636
637 ;;;###autoload
638 (defun gnus-cache-generate-nov-databases (dir)
639   "Generate NOV files recursively starting in DIR."
640   (interactive (list gnus-cache-directory))
641   (gnus-cache-close)
642   (let ((nnml-generate-active-function 'identity))
643     (nnml-generate-nov-databases-1 dir)))
644
645 (provide 'gnus-cache)
646               
647 ;;; gnus-cache.el ends here