0
|
1 ;;; gnus-cache.el --- cache interface for Gnus
|
98
|
2 ;; Copyright (C) 1995,96,97 Free Software Foundation, Inc.
|
0
|
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)
|
98
|
29 (require 'gnus-int)
|
|
30 (require 'gnus-range)
|
|
31 (require 'gnus-start)
|
|
32 (eval-when-compile
|
|
33 (require 'gnus-sum))
|
0
|
34
|
98
|
35 (defgroup gnus-cache nil
|
|
36 "Cache interface."
|
|
37 :group 'gnus)
|
|
38
|
|
39 (defcustom gnus-cache-directory
|
0
|
40 (nnheader-concat gnus-directory "cache/")
|
98
|
41 "*The directory where cached articles will be stored."
|
|
42 :group 'gnus-cache
|
|
43 :type 'directory)
|
0
|
44
|
108
|
45 (defcustom gnus-cache-active-file
|
0
|
46 (concat (file-name-as-directory gnus-cache-directory) "active")
|
98
|
47 "*The cache active file."
|
|
48 :group 'gnus-cache
|
|
49 :type 'file)
|
0
|
50
|
98
|
51 (defcustom gnus-cache-enter-articles '(ticked dormant)
|
|
52 "Classes of articles to enter into the cache."
|
|
53 :group 'gnus-cache
|
|
54 :type '(set (const ticked) (const dormant) (const unread) (const read)))
|
16
|
55
|
98
|
56 (defcustom gnus-cache-remove-articles '(read)
|
|
57 "Classes of articles to remove from the cache."
|
|
58 :group 'gnus-cache
|
|
59 :type '(set (const ticked) (const dormant) (const unread) (const read)))
|
|
60
|
|
61 (defcustom gnus-uncacheable-groups nil
|
0
|
62 "*Groups that match this regexp will not be cached.
|
|
63
|
|
64 If you want to avoid caching your nnml groups, you could set this
|
98
|
65 variable to \"^nnml\"."
|
|
66 :group 'gnus-cache
|
|
67 :type '(choice (const :tag "off" nil)
|
|
68 regexp))
|
0
|
69
|
|
70
|
|
71
|
|
72 ;;; Internal variables.
|
|
73
|
98
|
74 (defvar gnus-cache-removable-articles nil)
|
0
|
75 (defvar gnus-cache-buffer nil)
|
|
76 (defvar gnus-cache-active-hashtb nil)
|
|
77 (defvar gnus-cache-active-altered nil)
|
|
78
|
|
79 (eval-and-compile
|
|
80 (autoload 'nnml-generate-nov-databases-1 "nnml")
|
|
81 (autoload 'nnvirtual-find-group-art "nnvirtual"))
|
|
82
|
|
83
|
|
84
|
|
85 ;;; Functions called from Gnus.
|
|
86
|
|
87 (defun gnus-cache-open ()
|
|
88 "Initialize the cache."
|
2
|
89 (when (or (file-exists-p gnus-cache-directory)
|
|
90 (and gnus-use-cache
|
|
91 (not (eq gnus-use-cache 'passive))))
|
|
92 (gnus-cache-read-active)))
|
0
|
93
|
98
|
94 ;; Complexities of byte-compiling make this kludge necessary. Eeek.
|
|
95 (ignore-errors
|
|
96 (gnus-add-shutdown 'gnus-cache-close 'gnus))
|
0
|
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
|
98
|
107 (when gnus-cache-buffer
|
0
|
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
|
98
|
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.
|
0
|
129 (gnus-kill-buffer buffer)
|
|
130 (setq gnus-cache-buffer nil))))
|
|
131
|
108
|
132 (defun gnus-cache-possibly-enter-article
|
0
|
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)
|
98
|
137 (vectorp headers))
|
|
138 ; This might be a dummy article.
|
0
|
139 ;; If this is a virtual group, we find the real group.
|
|
140 (when (gnus-virtual-group-p group)
|
108
|
141 (let ((result (nnvirtual-find-group-art
|
0
|
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
|
98
|
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)))
|
0
|
155 (not (file-exists-p (setq file (gnus-cache-file-name
|
|
156 group number)))))
|
|
157 ;; Possibly create the cache directory.
|
98
|
158 (gnus-make-directory (setq dir (file-name-directory file)))
|
0
|
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)
|
98
|
167 (gnus-write-buffer file)
|
0
|
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 ()
|
98
|
173 (when (not (bobp))
|
|
174 (> (read (current-buffer)) number))
|
0
|
175 (error
|
|
176 ;; The line was malformed, so we just remove it!!
|
|
177 (gnus-delete-line)
|
|
178 t))
|
|
179 (forward-line -1))
|
98
|
180 (if (bobp)
|
0
|
181 (if (not (eobp))
|
|
182 (progn
|
|
183 (beginning-of-line)
|
98
|
184 (when (< (read (current-buffer)) number)
|
|
185 (forward-line 1)))
|
0
|
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
|
98
|
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))))))
|
0
|
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."
|
98
|
258 (when (equal group "no.norsk") (error "hie"))
|
2
|
259 (when gnus-cache-active-hashtb
|
|
260 (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb)))
|
108
|
261 (and cache-active
|
2
|
262 (< (car cache-active) (car active))
|
|
263 (setcar active (car cache-active)))
|
|
264 (and cache-active
|
|
265 (> (cdr cache-active) (cdr active))
|
|
266 (setcdr active (cdr cache-active))))))
|
0
|
267
|
|
268 (defun gnus-cache-retrieve-headers (articles group &optional fetch-old)
|
|
269 "Retrieve the headers for ARTICLES in GROUP."
|
108
|
270 (let ((cached
|
0
|
271 (setq gnus-newsgroup-cached (gnus-cache-articles-in-group group))))
|
|
272 (if (not cached)
|
|
273 ;; No cached articles here, so we just retrieve them
|
|
274 ;; the normal way.
|
|
275 (let ((gnus-use-cache nil))
|
|
276 (gnus-retrieve-headers articles group fetch-old))
|
|
277 (let ((uncached-articles (gnus-sorted-intersection
|
|
278 (gnus-sorted-complement articles cached)
|
|
279 articles))
|
|
280 (cache-file (gnus-cache-file-name group ".overview"))
|
|
281 type)
|
108
|
282 ;; We first retrieve all the headers that we don't have in
|
0
|
283 ;; the cache.
|
|
284 (let ((gnus-use-cache nil))
|
|
285 (when uncached-articles
|
108
|
286 (setq type (and articles
|
|
287 (gnus-retrieve-headers
|
0
|
288 uncached-articles group fetch-old)))))
|
|
289 (gnus-cache-save-buffers)
|
|
290 ;; Then we insert the cached headers.
|
|
291 (save-excursion
|
|
292 (cond
|
|
293 ((not (file-exists-p cache-file))
|
|
294 ;; There are no cached headers.
|
|
295 type)
|
|
296 ((null type)
|
108
|
297 ;; There were no uncached headers (or retrieval was
|
0
|
298 ;; unsuccessful), so we use the cached headers exclusively.
|
|
299 (set-buffer nntp-server-buffer)
|
|
300 (erase-buffer)
|
|
301 (insert-file-contents cache-file)
|
|
302 'nov)
|
|
303 ((eq type 'nov)
|
|
304 ;; We have both cached and uncached NOV headers, so we
|
|
305 ;; braid them.
|
|
306 (gnus-cache-braid-nov group cached)
|
|
307 type)
|
|
308 (t
|
|
309 ;; We braid HEADs.
|
|
310 (gnus-cache-braid-heads group (gnus-sorted-intersection
|
|
311 cached articles))
|
|
312 type)))))))
|
|
313
|
|
314 (defun gnus-cache-enter-article (&optional n)
|
|
315 "Enter the next N articles into the cache.
|
|
316 If not given a prefix, use the process marked articles instead.
|
|
317 Returns the list of articles entered."
|
|
318 (interactive "P")
|
|
319 (gnus-set-global-variables)
|
|
320 (let ((articles (gnus-summary-work-articles n))
|
|
321 article out)
|
98
|
322 (while (setq article (pop articles))
|
|
323 (if (natnump article)
|
108
|
324 (when (gnus-cache-possibly-enter-article
|
|
325 gnus-newsgroup-name article
|
98
|
326 (gnus-summary-article-header article)
|
|
327 nil nil nil t)
|
|
328 (push article out))
|
|
329 (gnus-message 2 "Can't cache article %d" article))
|
0
|
330 (gnus-summary-remove-process-mark article)
|
|
331 (gnus-summary-update-secondary-mark article))
|
|
332 (gnus-summary-next-subject 1)
|
|
333 (gnus-summary-position-point)
|
|
334 (nreverse out)))
|
|
335
|
|
336 (defun gnus-cache-remove-article (n)
|
|
337 "Remove the next N articles from the cache.
|
|
338 If not given a prefix, use the process marked articles instead.
|
|
339 Returns the list of articles removed."
|
|
340 (interactive "P")
|
|
341 (gnus-set-global-variables)
|
|
342 (gnus-cache-change-buffer gnus-newsgroup-name)
|
|
343 (let ((articles (gnus-summary-work-articles n))
|
|
344 article out)
|
|
345 (while articles
|
|
346 (setq article (pop articles))
|
|
347 (when (gnus-cache-possibly-remove-article article nil nil nil t)
|
|
348 (push article out))
|
|
349 (gnus-summary-remove-process-mark article)
|
|
350 (gnus-summary-update-secondary-mark article))
|
|
351 (gnus-summary-next-subject 1)
|
|
352 (gnus-summary-position-point)
|
|
353 (nreverse out)))
|
|
354
|
|
355 (defun gnus-cached-article-p (article)
|
|
356 "Say whether ARTICLE is cached in the current group."
|
|
357 (memq article gnus-newsgroup-cached))
|
|
358
|
98
|
359 (defun gnus-summary-insert-cached-articles ()
|
|
360 "Insert all the articles cached for this group into the current buffer."
|
|
361 (interactive)
|
|
362 (let ((cached gnus-newsgroup-cached)
|
|
363 (gnus-verbose (max 6 gnus-verbose)))
|
|
364 (unless cached
|
|
365 (error "No cached articles for this group"))
|
|
366 (while cached
|
|
367 (gnus-summary-goto-subject (pop cached) t))))
|
|
368
|
0
|
369 ;;; Internal functions.
|
|
370
|
|
371 (defun gnus-cache-change-buffer (group)
|
|
372 (and gnus-cache-buffer
|
|
373 ;; See if the current group's overview cache has been loaded.
|
|
374 (or (string= group (car gnus-cache-buffer))
|
|
375 ;; Another overview cache is current, save it.
|
|
376 (gnus-cache-save-buffers)))
|
|
377 ;; if gnus-cache buffer is nil, create it
|
98
|
378 (unless gnus-cache-buffer
|
|
379 ;; Create cache buffer
|
|
380 (save-excursion
|
|
381 (setq gnus-cache-buffer
|
|
382 (cons group
|
|
383 (set-buffer (get-buffer-create " *gnus-cache-overview*"))))
|
|
384 (buffer-disable-undo (current-buffer))
|
|
385 ;; Insert the contents of this group's cache overview.
|
|
386 (erase-buffer)
|
|
387 (let ((file (gnus-cache-file-name group ".overview")))
|
|
388 (when (file-exists-p file)
|
|
389 (nnheader-insert-file-contents file)))
|
108
|
390 ;; We have a fresh (empty/just loaded) buffer,
|
98
|
391 ;; mark it as unmodified to save a redundant write later.
|
|
392 (set-buffer-modified-p nil))))
|
0
|
393
|
|
394 ;; Return whether an article is a member of a class.
|
|
395 (defun gnus-cache-member-of-class (class ticked dormant unread)
|
|
396 (or (and ticked (memq 'ticked class))
|
|
397 (and dormant (memq 'dormant class))
|
|
398 (and unread (memq 'unread class))
|
|
399 (and (not unread) (not ticked) (not dormant) (memq 'read class))))
|
|
400
|
|
401 (defun gnus-cache-file-name (group article)
|
|
402 (concat (file-name-as-directory gnus-cache-directory)
|
|
403 (file-name-as-directory
|
98
|
404 (nnheader-translate-file-chars
|
|
405 (if (gnus-use-long-file-name 'not-cache)
|
|
406 group
|
|
407 (let ((group (nnheader-replace-chars-in-string group ?/ ?_)))
|
|
408 ;; Translate the first colon into a slash.
|
|
409 (when (string-match ":" group)
|
|
410 (aset group (match-beginning 0) ?/))
|
|
411 (nnheader-replace-chars-in-string group ?. ?/)))))
|
0
|
412 (if (stringp article) article (int-to-string article))))
|
|
413
|
|
414 (defun gnus-cache-update-article (group article)
|
|
415 "If ARTICLE is in the cache, remove it and re-enter it."
|
|
416 (when (gnus-cache-possibly-remove-article article nil nil nil t)
|
|
417 (let ((gnus-use-cache nil))
|
108
|
418 (gnus-cache-possibly-enter-article
|
0
|
419 gnus-newsgroup-name article (gnus-summary-article-header article)
|
|
420 nil nil nil t))))
|
|
421
|
108
|
422 (defun gnus-cache-possibly-remove-article (article ticked dormant unread
|
0
|
423 &optional force)
|
|
424 "Possibly remove ARTICLE from the cache."
|
|
425 (let ((group gnus-newsgroup-name)
|
|
426 (number article)
|
|
427 file)
|
|
428 ;; If this is a virtual group, we find the real group.
|
|
429 (when (gnus-virtual-group-p group)
|
108
|
430 (let ((result (nnvirtual-find-group-art
|
0
|
431 (gnus-group-real-name group) article)))
|
|
432 (setq group (car result)
|
|
433 number (cdr result))))
|
|
434 (setq file (gnus-cache-file-name group number))
|
|
435 (when (and (file-exists-p file)
|
|
436 (or force
|
|
437 (gnus-cache-member-of-class
|
|
438 gnus-cache-remove-articles ticked dormant unread)))
|
|
439 (save-excursion
|
|
440 (delete-file file)
|
|
441 (set-buffer (cdr gnus-cache-buffer))
|
|
442 (goto-char (point-min))
|
98
|
443 (when (or (looking-at (concat (int-to-string number) "\t"))
|
|
444 (search-forward (concat "\n" (int-to-string number) "\t")
|
|
445 (point-max) t))
|
|
446 (delete-region (progn (beginning-of-line) (point))
|
|
447 (progn (forward-line 1) (point)))))
|
0
|
448 (setq gnus-newsgroup-cached
|
|
449 (delq article gnus-newsgroup-cached))
|
|
450 (gnus-summary-update-secondary-mark article)
|
|
451 t)))
|
|
452
|
|
453 (defun gnus-cache-articles-in-group (group)
|
|
454 "Return a sorted list of cached articles in GROUP."
|
98
|
455 (let ((dir (file-name-directory (gnus-cache-file-name group 1))))
|
0
|
456 (when (file-exists-p dir)
|
98
|
457 (sort (mapcar (lambda (name) (string-to-int name))
|
0
|
458 (directory-files dir nil "^[0-9]+$" t))
|
|
459 '<))))
|
|
460
|
|
461 (defun gnus-cache-braid-nov (group cached)
|
|
462 (let ((cache-buf (get-buffer-create " *gnus-cache*"))
|
|
463 beg end)
|
|
464 (gnus-cache-save-buffers)
|
|
465 (save-excursion
|
|
466 (set-buffer cache-buf)
|
|
467 (buffer-disable-undo (current-buffer))
|
|
468 (erase-buffer)
|
|
469 (insert-file-contents (gnus-cache-file-name group ".overview"))
|
|
470 (goto-char (point-min))
|
|
471 (insert "\n")
|
|
472 (goto-char (point-min)))
|
|
473 (set-buffer nntp-server-buffer)
|
|
474 (goto-char (point-min))
|
|
475 (while cached
|
|
476 (while (and (not (eobp))
|
|
477 (< (read (current-buffer)) (car cached)))
|
|
478 (forward-line 1))
|
|
479 (beginning-of-line)
|
|
480 (save-excursion
|
|
481 (set-buffer cache-buf)
|
|
482 (if (search-forward (concat "\n" (int-to-string (car cached)) "\t")
|
|
483 nil t)
|
|
484 (setq beg (progn (beginning-of-line) (point))
|
|
485 end (progn (end-of-line) (point)))
|
|
486 (setq beg nil)))
|
98
|
487 (when beg
|
|
488 (insert-buffer-substring cache-buf beg end)
|
|
489 (insert "\n"))
|
0
|
490 (setq cached (cdr cached)))
|
|
491 (kill-buffer cache-buf)))
|
|
492
|
|
493 (defun gnus-cache-braid-heads (group cached)
|
|
494 (let ((cache-buf (get-buffer-create " *gnus-cache*")))
|
|
495 (save-excursion
|
|
496 (set-buffer cache-buf)
|
|
497 (buffer-disable-undo (current-buffer))
|
|
498 (erase-buffer))
|
|
499 (set-buffer nntp-server-buffer)
|
|
500 (goto-char (point-min))
|
|
501 (while cached
|
|
502 (while (and (not (eobp))
|
|
503 (looking-at "2.. +\\([0-9]+\\) ")
|
|
504 (< (progn (goto-char (match-beginning 1))
|
|
505 (read (current-buffer)))
|
|
506 (car cached)))
|
|
507 (search-forward "\n.\n" nil 'move))
|
|
508 (beginning-of-line)
|
|
509 (save-excursion
|
|
510 (set-buffer cache-buf)
|
|
511 (erase-buffer)
|
|
512 (insert-file-contents (gnus-cache-file-name group (car cached)))
|
|
513 (goto-char (point-min))
|
|
514 (insert "220 ")
|
|
515 (princ (car cached) (current-buffer))
|
|
516 (insert " Article retrieved.\n")
|
|
517 (search-forward "\n\n" nil 'move)
|
|
518 (delete-region (point) (point-max))
|
|
519 (forward-char -1)
|
|
520 (insert "."))
|
|
521 (insert-buffer-substring cache-buf)
|
|
522 (setq cached (cdr cached)))
|
|
523 (kill-buffer cache-buf)))
|
|
524
|
|
525 ;;;###autoload
|
|
526 (defun gnus-jog-cache ()
|
98
|
527 "Go through all groups and put the articles into the cache.
|
|
528
|
|
529 Usage:
|
|
530 $ emacs -batch -l ~/.emacs -l gnus -f gnus-jog-cache"
|
0
|
531 (interactive)
|
|
532 (let ((gnus-mark-article-hook nil)
|
|
533 (gnus-expert-user t)
|
|
534 (nnmail-spool-file nil)
|
|
535 (gnus-use-dribble-file nil)
|
|
536 (gnus-novice-user nil)
|
|
537 (gnus-large-newsgroup nil))
|
|
538 ;; Start Gnus.
|
|
539 (gnus)
|
|
540 ;; Go through all groups...
|
|
541 (gnus-group-mark-buffer)
|
108
|
542 (gnus-group-universal-argument
|
|
543 nil nil
|
0
|
544 (lambda ()
|
98
|
545 (interactive)
|
|
546 (gnus-summary-read-group (gnus-group-group-name) nil t)
|
0
|
547 ;; ... and enter the articles into the cache.
|
|
548 (when (eq major-mode 'gnus-summary-mode)
|
|
549 (gnus-uu-mark-buffer)
|
|
550 (gnus-cache-enter-article)
|
|
551 (kill-buffer (current-buffer)))))))
|
|
552
|
|
553 (defun gnus-cache-read-active (&optional force)
|
|
554 "Read the cache active file."
|
98
|
555 (gnus-make-directory gnus-cache-directory)
|
0
|
556 (if (not (and (file-exists-p gnus-cache-active-file)
|
|
557 (or force (not gnus-cache-active-hashtb))))
|
|
558 ;; There is no active file, so we generate one.
|
|
559 (gnus-cache-generate-active)
|
|
560 ;; We simply read the active file.
|
|
561 (save-excursion
|
|
562 (gnus-set-work-buffer)
|
|
563 (insert-file-contents gnus-cache-active-file)
|
|
564 (gnus-active-to-gnus-format
|
108
|
565 nil (setq gnus-cache-active-hashtb
|
|
566 (gnus-make-hashtable
|
0
|
567 (count-lines (point-min) (point-max)))))
|
|
568 (setq gnus-cache-active-altered nil))))
|
108
|
569
|
0
|
570 (defun gnus-cache-write-active (&optional force)
|
|
571 "Write the active hashtb to the active file."
|
|
572 (when (or force
|
|
573 (and gnus-cache-active-hashtb
|
|
574 gnus-cache-active-altered))
|
98
|
575 (nnheader-temp-write gnus-cache-active-file
|
0
|
576 (mapatoms
|
|
577 (lambda (sym)
|
|
578 (when (and sym (boundp sym))
|
|
579 (insert (format "%s %d %d y\n"
|
|
580 (symbol-name sym) (cdr (symbol-value sym))
|
|
581 (car (symbol-value sym))))))
|
98
|
582 gnus-cache-active-hashtb))
|
0
|
583 ;; Mark the active hashtb as unaltered.
|
|
584 (setq gnus-cache-active-altered nil)))
|
|
585
|
|
586 (defun gnus-cache-update-active (group number &optional low)
|
|
587 "Update the upper bound of the active info of GROUP to NUMBER.
|
|
588 If LOW, update the lower bound instead."
|
|
589 (let ((active (gnus-gethash group gnus-cache-active-hashtb)))
|
|
590 (if (null active)
|
|
591 ;; We just create a new active entry for this group.
|
|
592 (gnus-sethash group (cons number number) gnus-cache-active-hashtb)
|
|
593 ;; Update the lower or upper bound.
|
|
594 (if low
|
|
595 (setcar active number)
|
98
|
596 (setcdr active number)))
|
|
597 ;; Mark the active hashtb as altered.
|
|
598 (setq gnus-cache-active-altered t)))
|
0
|
599
|
|
600 ;;;###autoload
|
|
601 (defun gnus-cache-generate-active (&optional directory)
|
|
602 "Generate the cache active file."
|
|
603 (interactive)
|
|
604 (let* ((top (null directory))
|
|
605 (directory (expand-file-name (or directory gnus-cache-directory)))
|
|
606 (files (directory-files directory 'full))
|
108
|
607 (group
|
0
|
608 (if top
|
|
609 ""
|
108
|
610 (string-match
|
0
|
611 (concat "^" (file-name-as-directory
|
|
612 (expand-file-name gnus-cache-directory)))
|
|
613 (directory-file-name directory))
|
108
|
614 (nnheader-replace-chars-in-string
|
0
|
615 (substring (directory-file-name directory) (match-end 0))
|
|
616 ?/ ?.)))
|
|
617 nums alphs)
|
|
618 (when top
|
|
619 (gnus-message 5 "Generating the cache active file...")
|
|
620 (setq gnus-cache-active-hashtb (gnus-make-hashtable 123)))
|
|
621 ;; Separate articles from all other files and directories.
|
|
622 (while files
|
|
623 (if (string-match "^[0-9]+$" (file-name-nondirectory (car files)))
|
|
624 (push (string-to-int (file-name-nondirectory (pop files))) nums)
|
|
625 (push (pop files) alphs)))
|
|
626 ;; If we have nums, then this is probably a valid group.
|
|
627 (when (setq nums (sort nums '<))
|
|
628 (gnus-sethash group (cons (car nums) (gnus-last-element nums))
|
|
629 gnus-cache-active-hashtb))
|
|
630 ;; Go through all the other files.
|
|
631 (while alphs
|
|
632 (when (and (file-directory-p (car alphs))
|
|
633 (not (string-match "^\\.\\.?$"
|
|
634 (file-name-nondirectory (car alphs)))))
|
|
635 ;; We descend directories.
|
|
636 (gnus-cache-generate-active (car alphs)))
|
|
637 (setq alphs (cdr alphs)))
|
|
638 ;; Write the new active file.
|
|
639 (when top
|
|
640 (gnus-cache-write-active t)
|
|
641 (gnus-message 5 "Generating the cache active file...done"))))
|
|
642
|
|
643 ;;;###autoload
|
|
644 (defun gnus-cache-generate-nov-databases (dir)
|
|
645 "Generate NOV files recursively starting in DIR."
|
|
646 (interactive (list gnus-cache-directory))
|
|
647 (gnus-cache-close)
|
|
648 (let ((nnml-generate-active-function 'identity))
|
|
649 (nnml-generate-nov-databases-1 dir)))
|
|
650
|
98
|
651 (defun gnus-cache-move-cache (dir)
|
|
652 "Move the cache tree to somewhere else."
|
|
653 (interactive "DMove the cache tree to: ")
|
|
654 (rename-file gnus-cache-directory dir))
|
|
655
|
0
|
656 (provide 'gnus-cache)
|
108
|
657
|
0
|
658 ;;; gnus-cache.el ends here
|