Mercurial > emacs
annotate lisp/gnus/nnml.el @ 19860:c17fd465ea95 libc-970911 libc-970912 libc-970913 libc-970914 libc-970915 libc-970916 libc-970917 libc-970918 libc-970919 libc-970920 libc-970921 libc-970922 libc-970923 libc-970924 libc-970925 libc-970926 libc-970927 libc-970928 libc-970929 libc-970930 libc-971001 libc-971018 libc-971019 libc-971020 libc-971021 libc-971022 libc-971023 libc-971024 libc-971025 libc-971026 libc-971027 libc-971028 libc-971029 libc-971030 libc-971031 libc-971101 libc-971102 libc-971103 libc-971104 libc-971105 libc-971106 libc-971107 libc-971108 libc-971109 libc-971110 libc-971111 libc-971112 libc-971113 libc-971114 libc-971115 libc-971116 libc-971117 libc-971118 libc-971120 libc-971121 libc-971122 libc-971123 libc-971124 libc-971125 libc-971126 libc-971127 libc-971128 libc-971129 libc-971130 libc-971201 libc-971203 libc-971204 libc-971205 libc-971206 libc-971207 libc-971208 libc-971209 libc-971210 libc-971211 libc-971212 libc-971213 libc-971214 libc-971217 libc-971218 libc-971219 libc-971220 libc-971221 libc-971222 libc-971223 libc-971224 libc-971225 libc-971226 libc-971227 libc-971228 libc-971229 libc-971230 libc-971231 libc-980103 libc-980104 libc-980105 libc-980106 libc-980107 libc-980108 libc-980109 libc-980110 libc-980111 libc-980112 libc-980114 libc-980115 libc-980116 libc-980117 libc-980118 libc-980119 libc-980120 libc-980121 libc-980122 libc-980123 libc-980124 libc-980125 libc-980126 libc-980127 libc-980128
typos.
author | Jeff Law <law@redhat.com> |
---|---|
date | Wed, 10 Sep 1997 21:16:20 +0000 |
parents | f929cdcccb60 |
children | 5f1ab3dd344d |
rev | line source |
---|---|
17493 | 1 ;;; nnml.el --- mail spool access for Gnus |
2 ;; Copyright (C) 1995,96,97 Free Software Foundation, Inc. | |
3 | |
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no> | |
5 ;; Masanobu UMEDA <umerin@flab.flab.fujitsu.junet> | |
6 ;; Keywords: news, mail | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
24 | |
25 ;;; Commentary: | |
26 | |
27 ;; Based on nnspool.el by Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>. | |
28 ;; For an overview of what the interface functions do, please see the | |
29 ;; Gnus sources. | |
30 | |
31 ;;; Code: | |
32 | |
33 (require 'nnheader) | |
34 (require 'nnmail) | |
35 (require 'nnoo) | |
19494
4280cff25537
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
36 (eval-when-compile (require 'cl)) |
17493 | 37 |
38 (nnoo-declare nnml) | |
39 | |
40 (defvoo nnml-directory message-directory | |
41 "Mail spool directory.") | |
42 | |
43 (defvoo nnml-active-file | |
44 (concat (file-name-as-directory nnml-directory) "active") | |
45 "Mail active file.") | |
46 | |
47 (defvoo nnml-newsgroups-file | |
48 (concat (file-name-as-directory nnml-directory) "newsgroups") | |
49 "Mail newsgroups description file.") | |
50 | |
51 (defvoo nnml-get-new-mail t | |
52 "If non-nil, nnml will check the incoming mail file and split the mail.") | |
53 | |
54 (defvoo nnml-nov-is-evil nil | |
55 "If non-nil, Gnus will never generate and use nov databases for mail groups. | |
56 Using nov databases will speed up header fetching considerably. | |
57 This variable shouldn't be flipped much. If you have, for some reason, | |
58 set this to t, and want to set it to nil again, you should always run | |
59 the `nnml-generate-nov-databases' command. The function will go | |
60 through all nnml directories and generate nov databases for them | |
61 all. This may very well take some time.") | |
62 | |
63 (defvoo nnml-prepare-save-mail-hook nil | |
64 "Hook run narrowed to an article before saving.") | |
65 | |
66 (defvoo nnml-inhibit-expiry nil | |
67 "If non-nil, inhibit expiry.") | |
68 | |
69 | |
70 | |
71 | |
72 (defconst nnml-version "nnml 1.0" | |
73 "nnml version.") | |
74 | |
75 (defvoo nnml-nov-file-name ".overview") | |
76 | |
77 (defvoo nnml-current-directory nil) | |
78 (defvoo nnml-current-group nil) | |
79 (defvoo nnml-status-string "") | |
80 (defvoo nnml-nov-buffer-alist nil) | |
81 (defvoo nnml-group-alist nil) | |
82 (defvoo nnml-active-timestamp nil) | |
83 (defvoo nnml-article-file-alist nil) | |
84 | |
85 (defvoo nnml-generate-active-function 'nnml-generate-active-info) | |
86 | |
87 | |
88 | |
89 ;;; Interface functions. | |
90 | |
91 (nnoo-define-basics nnml) | |
92 | |
93 (deffoo nnml-retrieve-headers (sequence &optional group server fetch-old) | |
94 (when (nnml-possibly-change-directory group server) | |
95 (save-excursion | |
96 (set-buffer nntp-server-buffer) | |
97 (erase-buffer) | |
98 (let ((file nil) | |
99 (number (length sequence)) | |
100 (count 0) | |
19601
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
101 ;; 1997/8/12 by MORIOKA Tomohiko |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
102 ;; for XEmacs/mule. |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
103 (pathname-coding-system 'binary) |
17493 | 104 beg article) |
105 (if (stringp (car sequence)) | |
106 'headers | |
107 (if (nnml-retrieve-headers-with-nov sequence fetch-old) | |
108 'nov | |
109 (while sequence | |
110 (setq article (car sequence)) | |
111 (setq file (nnml-article-to-file article)) | |
112 (when (and file | |
113 (file-exists-p file) | |
114 (not (file-directory-p file))) | |
115 (insert (format "221 %d Article retrieved.\n" article)) | |
116 (setq beg (point)) | |
117 (nnheader-insert-head file) | |
118 (goto-char beg) | |
119 (if (search-forward "\n\n" nil t) | |
120 (forward-char -1) | |
121 (goto-char (point-max)) | |
122 (insert "\n\n")) | |
123 (insert ".\n") | |
124 (delete-region (point) (point-max))) | |
125 (setq sequence (cdr sequence)) | |
126 (setq count (1+ count)) | |
127 (and (numberp nnmail-large-newsgroup) | |
128 (> number nnmail-large-newsgroup) | |
129 (zerop (% count 20)) | |
130 (nnheader-message 6 "nnml: Receiving headers... %d%%" | |
131 (/ (* count 100) number)))) | |
132 | |
133 (and (numberp nnmail-large-newsgroup) | |
134 (> number nnmail-large-newsgroup) | |
135 (nnheader-message 6 "nnml: Receiving headers...done")) | |
136 | |
137 (nnheader-fold-continuation-lines) | |
138 'headers)))))) | |
139 | |
140 (deffoo nnml-open-server (server &optional defs) | |
141 (nnoo-change-server 'nnml server defs) | |
142 (when (not (file-exists-p nnml-directory)) | |
143 (condition-case () | |
144 (make-directory nnml-directory t) | |
145 (error))) | |
146 (cond | |
147 ((not (file-exists-p nnml-directory)) | |
148 (nnml-close-server) | |
149 (nnheader-report 'nnml "Couldn't create directory: %s" nnml-directory)) | |
150 ((not (file-directory-p (file-truename nnml-directory))) | |
151 (nnml-close-server) | |
152 (nnheader-report 'nnml "Not a directory: %s" nnml-directory)) | |
153 (t | |
154 (nnheader-report 'nnml "Opened server %s using directory %s" | |
155 server nnml-directory) | |
156 t))) | |
157 | |
158 (defun nnml-request-regenerate (server) | |
159 (nnml-possibly-change-directory nil server) | |
160 (nnml-generate-nov-databases) | |
161 t) | |
162 | |
163 (deffoo nnml-request-article (id &optional group server buffer) | |
164 (nnml-possibly-change-directory group server) | |
165 (let* ((nntp-server-buffer (or buffer nntp-server-buffer)) | |
19601
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
166 ;; 1997/8/12 by MORIOKA Tomohiko |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
167 ;; for XEmacs/mule. |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
168 (pathname-coding-system 'binary) |
17493 | 169 path gpath group-num) |
170 (if (stringp id) | |
171 (when (and (setq group-num (nnml-find-group-number id)) | |
172 (cdr | |
173 (assq (cdr group-num) | |
174 (nnheader-article-to-file-alist | |
175 (setq gpath | |
176 (nnmail-group-pathname | |
177 (car group-num) | |
178 nnml-directory)))))) | |
179 (setq path (concat gpath (int-to-string (cdr group-num))))) | |
180 (setq path (nnml-article-to-file id))) | |
181 (cond | |
182 ((not path) | |
183 (nnheader-report 'nnml "No such article: %s" id)) | |
184 ((not (file-exists-p path)) | |
185 (nnheader-report 'nnml "No such file: %s" path)) | |
186 ((file-directory-p path) | |
187 (nnheader-report 'nnml "File is a directory: %s" path)) | |
188 ((not (save-excursion (nnmail-find-file path))) | |
189 (nnheader-report 'nnml "Couldn't read file: %s" path)) | |
190 (t | |
191 (nnheader-report 'nnml "Article %s retrieved" id) | |
192 ;; We return the article number. | |
193 (cons (if group-num (car group-num) group) | |
194 (string-to-int (file-name-nondirectory path))))))) | |
195 | |
196 (deffoo nnml-request-group (group &optional server dont-check) | |
19601
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
197 ;; 1997/8/12 by MORIOKA Tomohiko |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
198 ;; for XEmacs/mule. |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
199 (let ((pathname-coding-system 'binary)) |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
200 (cond |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
201 ((not (nnml-possibly-change-directory group server)) |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
202 (nnheader-report 'nnml "Invalid group (no such directory)")) |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
203 ((not (file-exists-p nnml-current-directory)) |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
204 (nnheader-report 'nnml "Directory %s does not exist" |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
205 nnml-current-directory)) |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
206 ((not (file-directory-p nnml-current-directory)) |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
207 (nnheader-report 'nnml "%s is not a directory" nnml-current-directory)) |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
208 (dont-check |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
209 (nnheader-report 'nnml "Group %s selected" group) |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
210 t) |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
211 (t |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
212 (nnheader-re-read-dir nnml-current-directory) |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
213 (nnmail-activate 'nnml) |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
214 (let ((active (nth 1 (assoc group nnml-group-alist)))) |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
215 (if (not active) |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
216 (nnheader-report 'nnml "No such group: %s" group) |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
217 (nnheader-report 'nnml "Selected group %s" group) |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
218 (nnheader-insert "211 %d %d %d %s\n" |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
219 (max (1+ (- (cdr active) (car active))) 0) |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
220 (car active) (cdr active) group))))))) |
17493 | 221 |
222 (deffoo nnml-request-scan (&optional group server) | |
223 (setq nnml-article-file-alist nil) | |
224 (nnml-possibly-change-directory group server) | |
225 (nnmail-get-new-mail 'nnml 'nnml-save-nov nnml-directory group)) | |
226 | |
227 (deffoo nnml-close-group (group &optional server) | |
228 (setq nnml-article-file-alist nil) | |
229 t) | |
230 | |
231 (deffoo nnml-request-create-group (group &optional server args) | |
232 (nnmail-activate 'nnml) | |
233 (unless (assoc group nnml-group-alist) | |
234 (let (active) | |
235 (push (list group (setq active (cons 1 0))) | |
236 nnml-group-alist) | |
237 (nnml-possibly-create-directory group) | |
238 (nnml-possibly-change-directory group server) | |
239 (let ((articles (nnheader-directory-articles nnml-current-directory))) | |
240 (when articles | |
241 (setcar active (apply 'min articles)) | |
242 (setcdr active (apply 'max articles)))) | |
243 (nnmail-save-active nnml-group-alist nnml-active-file))) | |
244 t) | |
245 | |
246 (deffoo nnml-request-list (&optional server) | |
247 (save-excursion | |
19601
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
248 ;; 1997/8/12 by MORIOKA Tomohiko |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
249 ;; for XEmacs/mule. |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
250 (let ((nnmail-file-coding-system nnmail-active-file-coding-system) |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
251 (pathname-coding-system 'binary)) ; for XEmacs/mule |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
252 (nnmail-find-file nnml-active-file) |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
253 ) |
17493 | 254 (setq nnml-group-alist (nnmail-get-active)) |
255 t)) | |
256 | |
257 (deffoo nnml-request-newgroups (date &optional server) | |
258 (nnml-request-list server)) | |
259 | |
260 (deffoo nnml-request-list-newsgroups (&optional server) | |
261 (save-excursion | |
262 (nnmail-find-file nnml-newsgroups-file))) | |
263 | |
264 (deffoo nnml-request-expire-articles (articles group | |
265 &optional server force) | |
266 (nnml-possibly-change-directory group server) | |
267 (let* ((active-articles | |
268 (nnheader-directory-articles nnml-current-directory)) | |
269 (is-old t) | |
270 article rest mod-time number) | |
271 (nnmail-activate 'nnml) | |
272 | |
273 (while (and articles is-old) | |
274 (when (setq article (nnml-article-to-file (setq number (pop articles)))) | |
275 (when (setq mod-time (nth 5 (file-attributes article))) | |
276 (if (and (nnml-deletable-article-p group number) | |
277 (setq is-old | |
278 (nnmail-expired-article-p group mod-time force | |
279 nnml-inhibit-expiry))) | |
280 (progn | |
281 (nnheader-message 5 "Deleting article %s in %s" | |
282 article group) | |
283 (condition-case () | |
284 (funcall nnmail-delete-file-function article) | |
285 (file-error | |
286 (push number rest))) | |
287 (setq active-articles (delq number active-articles)) | |
288 (nnml-nov-delete-article group number)) | |
289 (push number rest))))) | |
290 (let ((active (nth 1 (assoc group nnml-group-alist)))) | |
291 (when active | |
292 (setcar active (or (and active-articles | |
293 (apply 'min active-articles)) | |
294 (1+ (cdr active))))) | |
295 (nnmail-save-active nnml-group-alist nnml-active-file)) | |
296 (nnml-save-nov) | |
297 (nconc rest articles))) | |
298 | |
299 (deffoo nnml-request-move-article | |
300 (article group server accept-form &optional last) | |
301 (let ((buf (get-buffer-create " *nnml move*")) | |
302 result) | |
303 (nnml-possibly-change-directory group server) | |
304 (nnml-update-file-alist) | |
305 (and | |
306 (nnml-deletable-article-p group article) | |
307 (nnml-request-article article group server) | |
308 (save-excursion | |
309 (set-buffer buf) | |
310 (insert-buffer-substring nntp-server-buffer) | |
311 (setq result (eval accept-form)) | |
312 (kill-buffer (current-buffer)) | |
313 result) | |
314 (progn | |
315 (nnml-possibly-change-directory group server) | |
316 (condition-case () | |
317 (funcall nnmail-delete-file-function | |
318 (nnml-article-to-file article)) | |
319 (file-error nil)) | |
320 (nnml-nov-delete-article group article) | |
321 (when last | |
322 (nnml-save-nov) | |
323 (nnmail-save-active nnml-group-alist nnml-active-file)))) | |
324 result)) | |
325 | |
326 (deffoo nnml-request-accept-article (group &optional server last) | |
327 (nnml-possibly-change-directory group server) | |
328 (nnmail-check-syntax) | |
329 (let (result) | |
330 (when nnmail-cache-accepted-message-ids | |
331 (nnmail-cache-insert (nnmail-fetch-field "message-id"))) | |
332 (if (stringp group) | |
333 (and | |
334 (nnmail-activate 'nnml) | |
335 (setq result (car (nnml-save-mail | |
336 (list (cons group (nnml-active-number group)))))) | |
337 (progn | |
338 (nnmail-save-active nnml-group-alist nnml-active-file) | |
339 (and last (nnml-save-nov)))) | |
340 (and | |
341 (nnmail-activate 'nnml) | |
342 (if (and (not (setq result (nnmail-article-group 'nnml-active-number))) | |
343 (yes-or-no-p "Moved to `junk' group; delete article? ")) | |
344 (setq result 'junk) | |
345 (setq result (car (nnml-save-mail result)))) | |
346 (when last | |
347 (nnmail-save-active nnml-group-alist nnml-active-file) | |
348 (when nnmail-cache-accepted-message-ids | |
349 (nnmail-cache-close)) | |
350 (nnml-save-nov)))) | |
351 result)) | |
352 | |
353 (deffoo nnml-request-replace-article (article group buffer) | |
354 (nnml-possibly-change-directory group) | |
355 (save-excursion | |
356 (set-buffer buffer) | |
357 (nnml-possibly-create-directory group) | |
358 (let ((chars (nnmail-insert-lines)) | |
359 (art (concat (int-to-string article) "\t")) | |
360 headers) | |
361 (when (condition-case () | |
362 (progn | |
363 (nnmail-write-region | |
364 (point-min) (point-max) | |
365 (or (nnml-article-to-file article) | |
366 (concat nnml-current-directory | |
367 (int-to-string article))) | |
368 nil (if (nnheader-be-verbose 5) nil 'nomesg)) | |
369 t) | |
370 (error nil)) | |
371 (setq headers (nnml-parse-head chars article)) | |
372 ;; Replace the NOV line in the NOV file. | |
373 (save-excursion | |
374 (set-buffer (nnml-open-nov group)) | |
375 (goto-char (point-min)) | |
376 (if (or (looking-at art) | |
377 (search-forward (concat "\n" art) nil t)) | |
378 ;; Delete the old NOV line. | |
379 (delete-region (progn (beginning-of-line) (point)) | |
380 (progn (forward-line 1) (point))) | |
381 ;; The line isn't here, so we have to find out where | |
382 ;; we should insert it. (This situation should never | |
383 ;; occur, but one likes to make sure...) | |
384 (while (and (looking-at "[0-9]+\t") | |
385 (< (string-to-int | |
386 (buffer-substring | |
387 (match-beginning 0) (match-end 0))) | |
388 article) | |
389 (zerop (forward-line 1))))) | |
390 (beginning-of-line) | |
391 (nnheader-insert-nov headers) | |
392 (nnml-save-nov) | |
393 t))))) | |
394 | |
395 (deffoo nnml-request-delete-group (group &optional force server) | |
396 (nnml-possibly-change-directory group server) | |
397 (when force | |
398 ;; Delete all articles in GROUP. | |
399 (let ((articles | |
400 (directory-files | |
401 nnml-current-directory t | |
402 (concat nnheader-numerical-short-files | |
403 "\\|" (regexp-quote nnml-nov-file-name) "$"))) | |
404 article) | |
405 (while articles | |
406 (setq article (pop articles)) | |
407 (when (file-writable-p article) | |
408 (nnheader-message 5 "Deleting article %s in %s..." article group) | |
409 (funcall nnmail-delete-file-function article)))) | |
410 ;; Try to delete the directory itself. | |
411 (condition-case () | |
412 (delete-directory nnml-current-directory) | |
413 (error nil))) | |
414 ;; Remove the group from all structures. | |
415 (setq nnml-group-alist | |
416 (delq (assoc group nnml-group-alist) nnml-group-alist) | |
417 nnml-current-group nil | |
418 nnml-current-directory nil) | |
419 ;; Save the active file. | |
420 (nnmail-save-active nnml-group-alist nnml-active-file) | |
421 t) | |
422 | |
423 (deffoo nnml-request-rename-group (group new-name &optional server) | |
424 (nnml-possibly-change-directory group server) | |
425 (let ((new-dir (nnmail-group-pathname new-name nnml-directory)) | |
426 (old-dir (nnmail-group-pathname group nnml-directory))) | |
427 (when (condition-case () | |
428 (progn | |
429 (make-directory new-dir t) | |
430 t) | |
431 (error nil)) | |
432 ;; We move the articles file by file instead of renaming | |
433 ;; the directory -- there may be subgroups in this group. | |
434 ;; One might be more clever, I guess. | |
435 (let ((files (nnheader-article-to-file-alist old-dir))) | |
436 (while files | |
437 (rename-file | |
438 (concat old-dir (cdar files)) | |
439 (concat new-dir (cdar files))) | |
440 (pop files))) | |
441 ;; Move .overview file. | |
442 (let ((overview (concat old-dir nnml-nov-file-name))) | |
443 (when (file-exists-p overview) | |
444 (rename-file overview (concat new-dir nnml-nov-file-name)))) | |
445 (when (<= (length (directory-files old-dir)) 2) | |
446 (condition-case () | |
447 (delete-directory old-dir) | |
448 (error nil))) | |
449 ;; That went ok, so we change the internal structures. | |
450 (let ((entry (assoc group nnml-group-alist))) | |
451 (when entry | |
452 (setcar entry new-name)) | |
453 (setq nnml-current-directory nil | |
454 nnml-current-group nil) | |
455 ;; Save the new group alist. | |
456 (nnmail-save-active nnml-group-alist nnml-active-file) | |
457 t)))) | |
458 | |
459 (deffoo nnml-set-status (article name value &optional group server) | |
460 (nnml-possibly-change-directory group server) | |
461 (let ((file (nnml-article-to-file article))) | |
462 (cond | |
463 ((not (file-exists-p file)) | |
464 (nnheader-report 'nnml "File %s does not exist" file)) | |
465 (t | |
466 (nnheader-temp-write file | |
467 (nnheader-insert-file-contents file) | |
468 (nnmail-replace-status name value)) | |
469 t)))) | |
470 | |
471 | |
472 ;;; Internal functions. | |
473 | |
474 (defun nnml-article-to-file (article) | |
475 (nnml-update-file-alist) | |
476 (let (file) | |
477 (when (setq file (cdr (assq article nnml-article-file-alist))) | |
478 (concat nnml-current-directory file)))) | |
479 | |
480 (defun nnml-deletable-article-p (group article) | |
481 "Say whether ARTICLE in GROUP can be deleted." | |
482 (let (path) | |
483 (when (setq path (nnml-article-to-file article)) | |
484 (when (file-writable-p path) | |
485 (or (not nnmail-keep-last-article) | |
486 (not (eq (cdr (nth 1 (assoc group nnml-group-alist))) | |
487 article))))))) | |
488 | |
489 ;; Find an article number in the current group given the Message-ID. | |
490 (defun nnml-find-group-number (id) | |
491 (save-excursion | |
492 (set-buffer (get-buffer-create " *nnml id*")) | |
493 (buffer-disable-undo (current-buffer)) | |
494 (let ((alist nnml-group-alist) | |
495 number) | |
496 ;; We want to look through all .overview files, but we want to | |
497 ;; start with the one in the current directory. It seems most | |
498 ;; likely that the article we are looking for is in that group. | |
499 (if (setq number (nnml-find-id nnml-current-group id)) | |
500 (cons nnml-current-group number) | |
501 ;; It wasn't there, so we look through the other groups as well. | |
502 (while (and (not number) | |
503 alist) | |
504 (or (string= (caar alist) nnml-current-group) | |
505 (setq number (nnml-find-id (caar alist) id))) | |
506 (or number | |
507 (setq alist (cdr alist)))) | |
508 (and number | |
509 (cons (caar alist) number)))))) | |
510 | |
511 (defun nnml-find-id (group id) | |
512 (erase-buffer) | |
513 (let ((nov (concat (nnmail-group-pathname group nnml-directory) | |
514 nnml-nov-file-name)) | |
515 number found) | |
516 (when (file-exists-p nov) | |
517 (nnheader-insert-file-contents nov) | |
518 (while (and (not found) | |
519 (search-forward id nil t)) ; We find the ID. | |
520 ;; And the id is in the fourth field. | |
521 (if (not (and (search-backward "\t" nil t 4) | |
522 (not (search-backward"\t" (gnus-point-at-bol) t)))) | |
523 (forward-line 1) | |
524 (beginning-of-line) | |
525 (setq found t) | |
526 ;; We return the article number. | |
527 (setq number | |
528 (condition-case () | |
529 (read (current-buffer)) | |
530 (error nil))))) | |
531 number))) | |
532 | |
533 (defun nnml-retrieve-headers-with-nov (articles &optional fetch-old) | |
534 (if (or gnus-nov-is-evil nnml-nov-is-evil) | |
535 nil | |
536 (let ((nov (concat nnml-current-directory nnml-nov-file-name))) | |
537 (when (file-exists-p nov) | |
538 (save-excursion | |
539 (set-buffer nntp-server-buffer) | |
540 (erase-buffer) | |
541 (nnheader-insert-file-contents nov) | |
542 (if (and fetch-old | |
543 (not (numberp fetch-old))) | |
544 t ; Don't remove anything. | |
545 (nnheader-nov-delete-outside-range | |
546 (if fetch-old (max 1 (- (car articles) fetch-old)) | |
547 (car articles)) | |
548 (car (last articles))) | |
549 t)))))) | |
550 | |
551 (defun nnml-possibly-change-directory (group &optional server) | |
552 (when (and server | |
553 (not (nnml-server-opened server))) | |
554 (nnml-open-server server)) | |
555 (if (not group) | |
556 t | |
19601
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
557 (let ((pathname (nnmail-group-pathname group nnml-directory)) |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
558 ;; 1997/8/14 by MORIOKA Tomohiko |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
559 ;; for XEmacs/mule. |
f929cdcccb60
(nnml-possibly-change-directory): Likewise
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
560 (pathname-coding-system 'binary)) |
17493 | 561 (when (not (equal pathname nnml-current-directory)) |
562 (setq nnml-current-directory pathname | |
563 nnml-current-group group | |
564 nnml-article-file-alist nil)) | |
565 (file-exists-p nnml-current-directory)))) | |
566 | |
567 (defun nnml-possibly-create-directory (group) | |
568 (let (dir dirs) | |
569 (setq dir (nnmail-group-pathname group nnml-directory)) | |
570 (while (not (file-directory-p dir)) | |
571 (push dir dirs) | |
572 (setq dir (file-name-directory (directory-file-name dir)))) | |
573 (while dirs | |
574 (make-directory (directory-file-name (car dirs))) | |
575 (nnheader-message 5 "Creating mail directory %s" (car dirs)) | |
576 (setq dirs (cdr dirs))))) | |
577 | |
578 (defun nnml-save-mail (group-art) | |
579 "Called narrowed to an article." | |
580 (let (chars headers) | |
581 (setq chars (nnmail-insert-lines)) | |
582 (nnmail-insert-xref group-art) | |
583 (run-hooks 'nnmail-prepare-save-mail-hook) | |
584 (run-hooks 'nnml-prepare-save-mail-hook) | |
585 (goto-char (point-min)) | |
586 (while (looking-at "From ") | |
587 (replace-match "X-From-Line: ") | |
588 (forward-line 1)) | |
589 ;; We save the article in all the groups it belongs in. | |
590 (let ((ga group-art) | |
591 first) | |
592 (while ga | |
593 (nnml-possibly-create-directory (caar ga)) | |
594 (let ((file (concat (nnmail-group-pathname | |
595 (caar ga) nnml-directory) | |
596 (int-to-string (cdar ga))))) | |
597 (if first | |
598 ;; It was already saved, so we just make a hard link. | |
599 (funcall nnmail-crosspost-link-function first file t) | |
600 ;; Save the article. | |
601 (nnmail-write-region (point-min) (point-max) file nil | |
602 (if (nnheader-be-verbose 5) nil 'nomesg)) | |
603 (setq first file))) | |
604 (setq ga (cdr ga)))) | |
605 ;; Generate a nov line for this article. We generate the nov | |
606 ;; line after saving, because nov generation destroys the | |
607 ;; header. | |
608 (setq headers (nnml-parse-head chars)) | |
609 ;; Output the nov line to all nov databases that should have it. | |
610 (let ((ga group-art)) | |
611 (while ga | |
612 (nnml-add-nov (caar ga) (cdar ga) headers) | |
613 (setq ga (cdr ga)))) | |
614 group-art)) | |
615 | |
616 (defun nnml-active-number (group) | |
617 "Compute the next article number in GROUP." | |
618 (let ((active (cadr (assoc group nnml-group-alist)))) | |
619 ;; The group wasn't known to nnml, so we just create an active | |
620 ;; entry for it. | |
621 (unless active | |
622 ;; Perhaps the active file was corrupt? See whether | |
623 ;; there are any articles in this group. | |
624 (nnml-possibly-create-directory group) | |
625 (nnml-possibly-change-directory group) | |
626 (unless nnml-article-file-alist | |
627 (setq nnml-article-file-alist | |
628 (sort | |
629 (nnheader-article-to-file-alist nnml-current-directory) | |
630 (lambda (a1 a2) (< (car a1) (car a2)))))) | |
631 (setq active | |
632 (if nnml-article-file-alist | |
633 (cons (caar nnml-article-file-alist) | |
634 (caar (last nnml-article-file-alist))) | |
635 (cons 1 0))) | |
636 (push (list group active) nnml-group-alist)) | |
637 (setcdr active (1+ (cdr active))) | |
638 (while (file-exists-p | |
639 (concat (nnmail-group-pathname group nnml-directory) | |
640 (int-to-string (cdr active)))) | |
641 (setcdr active (1+ (cdr active)))) | |
642 (cdr active))) | |
643 | |
644 (defun nnml-add-nov (group article headers) | |
645 "Add a nov line for the GROUP base." | |
646 (save-excursion | |
647 (set-buffer (nnml-open-nov group)) | |
648 (goto-char (point-max)) | |
649 (mail-header-set-number headers article) | |
650 (nnheader-insert-nov headers))) | |
651 | |
652 (defsubst nnml-header-value () | |
653 (buffer-substring (match-end 0) (progn (end-of-line) (point)))) | |
654 | |
655 (defun nnml-parse-head (chars &optional number) | |
656 "Parse the head of the current buffer." | |
657 (save-excursion | |
658 (save-restriction | |
659 (goto-char (point-min)) | |
660 (narrow-to-region | |
661 (point) | |
662 (1- (or (search-forward "\n\n" nil t) (point-max)))) | |
663 ;; Fold continuation lines. | |
664 (goto-char (point-min)) | |
665 (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t) | |
666 (replace-match " " t t)) | |
667 ;; Remove any tabs; they are too confusing. | |
668 (subst-char-in-region (point-min) (point-max) ?\t ? ) | |
669 (let ((headers (nnheader-parse-head t))) | |
670 (mail-header-set-chars headers chars) | |
671 (mail-header-set-number headers number) | |
672 headers)))) | |
673 | |
674 (defun nnml-open-nov (group) | |
675 (or (cdr (assoc group nnml-nov-buffer-alist)) | |
676 (let ((buffer (nnheader-find-file-noselect | |
677 (concat (nnmail-group-pathname group nnml-directory) | |
678 nnml-nov-file-name)))) | |
679 (save-excursion | |
680 (set-buffer buffer) | |
681 (buffer-disable-undo (current-buffer))) | |
682 (push (cons group buffer) nnml-nov-buffer-alist) | |
683 buffer))) | |
684 | |
685 (defun nnml-save-nov () | |
686 (save-excursion | |
687 (while nnml-nov-buffer-alist | |
688 (when (buffer-name (cdar nnml-nov-buffer-alist)) | |
689 (set-buffer (cdar nnml-nov-buffer-alist)) | |
690 (when (buffer-modified-p) | |
691 (nnmail-write-region 1 (point-max) (buffer-file-name) nil 'nomesg)) | |
692 (set-buffer-modified-p nil) | |
693 (kill-buffer (current-buffer))) | |
694 (setq nnml-nov-buffer-alist (cdr nnml-nov-buffer-alist))))) | |
695 | |
696 ;;;###autoload | |
697 (defun nnml-generate-nov-databases () | |
698 "Generate NOV databases in all nnml directories." | |
699 (interactive) | |
700 ;; Read the active file to make sure we don't re-use articles | |
701 ;; numbers in empty groups. | |
702 (nnmail-activate 'nnml) | |
703 (nnml-open-server (or (nnoo-current-server 'nnml) "")) | |
704 (setq nnml-directory (expand-file-name nnml-directory)) | |
705 ;; Recurse down the directories. | |
706 (nnml-generate-nov-databases-1 nnml-directory nil t) | |
707 ;; Save the active file. | |
708 (nnmail-save-active nnml-group-alist nnml-active-file)) | |
709 | |
710 (defun nnml-generate-nov-databases-1 (dir &optional seen no-active) | |
711 "Regenerate the NOV database in DIR." | |
712 (interactive "DRegenerate NOV in: ") | |
713 (setq dir (file-name-as-directory dir)) | |
714 ;; Only scan this sub-tree if we haven't been here yet. | |
715 (unless (member (file-truename dir) seen) | |
716 (push (file-truename dir) seen) | |
717 ;; We descend recursively | |
718 (let ((dirs (directory-files dir t nil t)) | |
719 dir) | |
720 (while (setq dir (pop dirs)) | |
721 (when (and (not (member (file-name-nondirectory dir) '("." ".."))) | |
722 (file-directory-p dir)) | |
723 (nnml-generate-nov-databases-1 dir seen)))) | |
724 ;; Do this directory. | |
725 (let ((files (sort (nnheader-article-to-file-alist dir) | |
726 (lambda (a b) (< (car a) (car b)))))) | |
727 (when files | |
728 (funcall nnml-generate-active-function dir) | |
729 ;; Generate the nov file. | |
730 (nnml-generate-nov-file dir files) | |
731 (unless no-active | |
732 (nnmail-save-active nnml-group-alist nnml-active-file)))))) | |
733 | |
734 (defvar files) | |
735 (defun nnml-generate-active-info (dir) | |
736 ;; Update the active info for this group. | |
737 (let ((group (nnheader-file-to-group | |
738 (directory-file-name dir) nnml-directory))) | |
739 (setq nnml-group-alist | |
740 (delq (assoc group nnml-group-alist) nnml-group-alist)) | |
741 (push (list group | |
742 (cons (caar files) | |
743 (let ((f files)) | |
744 (while (cdr f) (setq f (cdr f))) | |
745 (caar f)))) | |
746 nnml-group-alist))) | |
747 | |
748 (defun nnml-generate-nov-file (dir files) | |
749 (let* ((dir (file-name-as-directory dir)) | |
750 (nov (concat dir nnml-nov-file-name)) | |
751 (nov-buffer (get-buffer-create " *nov*")) | |
752 chars file headers) | |
753 (save-excursion | |
754 ;; Init the nov buffer. | |
755 (set-buffer nov-buffer) | |
756 (buffer-disable-undo (current-buffer)) | |
757 (erase-buffer) | |
758 (set-buffer nntp-server-buffer) | |
759 ;; Delete the old NOV file. | |
760 (when (file-exists-p nov) | |
761 (funcall nnmail-delete-file-function nov)) | |
762 (while files | |
763 (unless (file-directory-p (setq file (concat dir (cdar files)))) | |
764 (erase-buffer) | |
765 (nnheader-insert-file-contents file) | |
766 (narrow-to-region | |
767 (goto-char (point-min)) | |
768 (progn | |
769 (search-forward "\n\n" nil t) | |
770 (setq chars (- (point-max) (point))) | |
771 (max 1 (1- (point))))) | |
772 (when (and (not (= 0 chars)) ; none of them empty files... | |
773 (not (= (point-min) (point-max)))) | |
774 (goto-char (point-min)) | |
775 (setq headers (nnml-parse-head chars (caar files))) | |
776 (save-excursion | |
777 (set-buffer nov-buffer) | |
778 (goto-char (point-max)) | |
779 (nnheader-insert-nov headers))) | |
780 (widen)) | |
781 (setq files (cdr files))) | |
782 (save-excursion | |
783 (set-buffer nov-buffer) | |
784 (nnmail-write-region 1 (point-max) nov nil 'nomesg) | |
785 (kill-buffer (current-buffer)))))) | |
786 | |
787 (defun nnml-nov-delete-article (group article) | |
788 (save-excursion | |
789 (set-buffer (nnml-open-nov group)) | |
790 (when (nnheader-find-nov-line article) | |
791 (delete-region (point) (progn (forward-line 1) (point))) | |
792 (when (bobp) | |
793 (let ((active (cadr (assoc group nnml-group-alist))) | |
794 num) | |
795 (when active | |
796 (if (eobp) | |
797 (setf (car active) (1+ (cdr active))) | |
798 (when (and (setq num (ignore-errors (read (current-buffer)))) | |
799 (numberp num)) | |
800 (setf (car active) num))))))) | |
801 t)) | |
802 | |
803 (defun nnml-update-file-alist () | |
804 (unless nnml-article-file-alist | |
805 (setq nnml-article-file-alist | |
806 (nnheader-article-to-file-alist nnml-current-directory)))) | |
807 | |
808 (provide 'nnml) | |
809 | |
810 ;;; nnml.el ends here |