annotate lisp/gnus/gnus-cache.el @ 155:43dd3413c7c7 r20-3b4

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