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