Mercurial > emacs
annotate lisp/gnus/nnmh.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 | 549f21ee4bf0 |
children | 5f1ab3dd344d |
rev | line source |
---|---|
17493 | 1 ;;; nnmh.el --- mhspool 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 'gnus-start) | |
36 (require 'nnoo) | |
19494
4280cff25537
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
37 (eval-when-compile (require 'cl)) |
17493 | 38 |
39 (nnoo-declare nnmh) | |
40 | |
41 (defvoo nnmh-directory message-directory | |
42 "*Mail spool directory.") | |
43 | |
44 (defvoo nnmh-get-new-mail t | |
45 "*If non-nil, nnmh will check the incoming mail file and split the mail.") | |
46 | |
47 (defvoo nnmh-prepare-save-mail-hook nil | |
48 "*Hook run narrowed to an article before saving.") | |
49 | |
50 (defvoo nnmh-be-safe nil | |
51 "*If non-nil, nnmh will check all articles to make sure whether they are new or not.") | |
52 | |
53 | |
54 | |
55 (defconst nnmh-version "nnmh 1.0" | |
56 "nnmh version.") | |
57 | |
58 (defvoo nnmh-current-directory nil | |
59 "Current news group directory.") | |
60 | |
61 (defvoo nnmh-status-string "") | |
62 (defvoo nnmh-group-alist nil) | |
63 | |
64 | |
65 | |
66 ;;; Interface functions. | |
67 | |
68 (nnoo-define-basics nnmh) | |
69 | |
70 (deffoo nnmh-retrieve-headers (articles &optional newsgroup server fetch-old) | |
71 (save-excursion | |
72 (set-buffer nntp-server-buffer) | |
73 (erase-buffer) | |
74 (let* ((file nil) | |
75 (number (length articles)) | |
76 (large (and (numberp nnmail-large-newsgroup) | |
77 (> number nnmail-large-newsgroup))) | |
78 (count 0) | |
19602
549f21ee4bf0
(nnmh-request-list, nnmh-active-number): Protect from
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
79 ;; 1997/8/12 by MORIOKA Tomohiko |
549f21ee4bf0
(nnmh-request-list, nnmh-active-number): Protect from
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
80 ;; for XEmacs/mule. |
549f21ee4bf0
(nnmh-request-list, nnmh-active-number): Protect from
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
81 (pathname-coding-system 'binary) |
17493 | 82 beg article) |
83 (nnmh-possibly-change-directory newsgroup server) | |
84 ;; We don't support fetching by Message-ID. | |
85 (if (stringp (car articles)) | |
86 'headers | |
87 (while articles | |
88 (when (and (file-exists-p | |
89 (setq file (concat (file-name-as-directory | |
90 nnmh-current-directory) | |
91 (int-to-string | |
92 (setq article (pop articles)))))) | |
93 (not (file-directory-p file))) | |
94 (insert (format "221 %d Article retrieved.\n" article)) | |
95 (setq beg (point)) | |
96 (nnheader-insert-head file) | |
97 (goto-char beg) | |
98 (if (search-forward "\n\n" nil t) | |
99 (forward-char -1) | |
100 (goto-char (point-max)) | |
101 (insert "\n\n")) | |
102 (insert ".\n") | |
103 (delete-region (point) (point-max))) | |
104 (setq count (1+ count)) | |
105 | |
106 (and large | |
107 (zerop (% count 20)) | |
108 (message "nnmh: Receiving headers... %d%%" | |
109 (/ (* count 100) number)))) | |
110 | |
111 (when large | |
112 (message "nnmh: Receiving headers...done")) | |
113 | |
114 (nnheader-fold-continuation-lines) | |
115 'headers)))) | |
116 | |
117 (deffoo nnmh-open-server (server &optional defs) | |
118 (nnoo-change-server 'nnmh server defs) | |
119 (when (not (file-exists-p nnmh-directory)) | |
120 (condition-case () | |
121 (make-directory nnmh-directory t) | |
122 (error t))) | |
123 (cond | |
124 ((not (file-exists-p nnmh-directory)) | |
125 (nnmh-close-server) | |
126 (nnheader-report 'nnmh "Couldn't create directory: %s" nnmh-directory)) | |
127 ((not (file-directory-p (file-truename nnmh-directory))) | |
128 (nnmh-close-server) | |
129 (nnheader-report 'nnmh "Not a directory: %s" nnmh-directory)) | |
130 (t | |
131 (nnheader-report 'nnmh "Opened server %s using directory %s" | |
132 server nnmh-directory) | |
133 t))) | |
134 | |
135 (deffoo nnmh-request-article (id &optional newsgroup server buffer) | |
136 (nnmh-possibly-change-directory newsgroup server) | |
137 (let ((file (if (stringp id) | |
138 nil | |
139 (concat nnmh-current-directory (int-to-string id)))) | |
19602
549f21ee4bf0
(nnmh-request-list, nnmh-active-number): Protect from
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
140 ;; 1997/8/12 by MORIOKA Tomohiko |
549f21ee4bf0
(nnmh-request-list, nnmh-active-number): Protect from
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
141 ;; for XEmacs/mule. |
549f21ee4bf0
(nnmh-request-list, nnmh-active-number): Protect from
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
142 (pathname-coding-system 'binary) |
17493 | 143 (nntp-server-buffer (or buffer nntp-server-buffer))) |
144 (and (stringp file) | |
145 (file-exists-p file) | |
146 (not (file-directory-p file)) | |
147 (save-excursion (nnmail-find-file file)) | |
148 (string-to-int (file-name-nondirectory file))))) | |
149 | |
150 (deffoo nnmh-request-group (group &optional server dont-check) | |
151 (let ((pathname (nnmail-group-pathname group nnmh-directory)) | |
19602
549f21ee4bf0
(nnmh-request-list, nnmh-active-number): Protect from
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
152 ;; 1997/8/12 by MORIOKA Tomohiko |
549f21ee4bf0
(nnmh-request-list, nnmh-active-number): Protect from
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
153 ;; for XEmacs/mule. |
549f21ee4bf0
(nnmh-request-list, nnmh-active-number): Protect from
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
154 (pathname-coding-system 'binary) |
17493 | 155 dir) |
156 (cond | |
157 ((not (file-directory-p pathname)) | |
158 (nnheader-report | |
159 'nnmh "Can't select group (no such directory): %s" group)) | |
160 (t | |
161 (setq nnmh-current-directory pathname) | |
162 (and nnmh-get-new-mail | |
163 nnmh-be-safe | |
164 (nnmh-update-gnus-unreads group)) | |
165 (cond | |
166 (dont-check | |
167 (nnheader-report 'nnmh "Selected group %s" group) | |
168 t) | |
169 (t | |
170 ;; Re-scan the directory if it's on a foreign system. | |
171 (nnheader-re-read-dir pathname) | |
172 (setq dir | |
173 (sort | |
174 (mapcar (lambda (name) (string-to-int name)) | |
175 (directory-files pathname nil "^[0-9]+$" t)) | |
176 '<)) | |
177 (cond | |
178 (dir | |
179 (nnheader-report 'nnmh "Selected group %s" group) | |
180 (nnheader-insert | |
181 "211 %d %d %d %s\n" (length dir) (car dir) | |
182 (progn (while (cdr dir) (setq dir (cdr dir))) (car dir)) | |
183 group)) | |
184 (t | |
185 (nnheader-report 'nnmh "Empty group %s" group) | |
186 (nnheader-insert (format "211 0 1 0 %s\n" group)))))))))) | |
187 | |
188 (deffoo nnmh-request-scan (&optional group server) | |
189 (nnmail-get-new-mail 'nnmh nil nnmh-directory group)) | |
190 | |
191 (deffoo nnmh-request-list (&optional server dir) | |
192 (nnheader-insert "") | |
19602
549f21ee4bf0
(nnmh-request-list, nnmh-active-number): Protect from
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
193 (let (;; 1997/8/14 by MORIOKA Tomohiko |
549f21ee4bf0
(nnmh-request-list, nnmh-active-number): Protect from
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
194 ;; for XEmacs/mule. |
549f21ee4bf0
(nnmh-request-list, nnmh-active-number): Protect from
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
195 (pathname-coding-system 'binary) |
549f21ee4bf0
(nnmh-request-list, nnmh-active-number): Protect from
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
196 (nnmh-toplev |
17493 | 197 (or dir (file-truename (file-name-as-directory nnmh-directory))))) |
198 (nnmh-request-list-1 nnmh-toplev)) | |
199 (setq nnmh-group-alist (nnmail-get-active)) | |
200 t) | |
201 | |
202 (defvar nnmh-toplev) | |
203 (defun nnmh-request-list-1 (dir) | |
204 (setq dir (expand-file-name dir)) | |
205 ;; Recurse down all directories. | |
206 (let ((dirs (and (file-readable-p dir) | |
207 (> (nth 1 (file-attributes (file-chase-links dir))) 2) | |
208 (directory-files dir t nil t))) | |
209 dir) | |
210 ;; Recurse down directories. | |
211 (while (setq dir (pop dirs)) | |
212 (when (and (not (member (file-name-nondirectory dir) '("." ".."))) | |
213 (file-directory-p dir) | |
214 (file-readable-p dir)) | |
215 (nnmh-request-list-1 dir)))) | |
216 ;; For each directory, generate an active file line. | |
217 (unless (string= (expand-file-name nnmh-toplev) dir) | |
218 (let ((files (mapcar | |
219 (lambda (name) (string-to-int name)) | |
220 (directory-files dir nil "^[0-9]+$" t)))) | |
221 (when files | |
222 (save-excursion | |
223 (set-buffer nntp-server-buffer) | |
224 (goto-char (point-max)) | |
225 (insert | |
226 (format | |
227 "%s %d %d y\n" | |
228 (progn | |
229 (string-match | |
230 (regexp-quote | |
231 (file-truename (file-name-as-directory | |
232 (expand-file-name nnmh-toplev)))) | |
233 dir) | |
234 (nnheader-replace-chars-in-string | |
19602
549f21ee4bf0
(nnmh-request-list, nnmh-active-number): Protect from
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
235 (decode-coding-string (substring dir (match-end 0)) |
549f21ee4bf0
(nnmh-request-list, nnmh-active-number): Protect from
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
236 nnmail-pathname-coding-system) |
549f21ee4bf0
(nnmh-request-list, nnmh-active-number): Protect from
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
237 ?/ ?.)) |
17493 | 238 (apply 'max files) |
239 (apply 'min files))))))) | |
240 t) | |
241 | |
242 (deffoo nnmh-request-newgroups (date &optional server) | |
243 (nnmh-request-list server)) | |
244 | |
245 (deffoo nnmh-request-expire-articles (articles newsgroup | |
246 &optional server force) | |
247 (nnmh-possibly-change-directory newsgroup server) | |
248 (let* ((active-articles | |
249 (mapcar | |
250 (function | |
251 (lambda (name) | |
252 (string-to-int name))) | |
253 (directory-files nnmh-current-directory nil "^[0-9]+$" t))) | |
254 (is-old t) | |
255 article rest mod-time) | |
256 (nnmail-activate 'nnmh) | |
257 | |
258 (while (and articles is-old) | |
259 (setq article (concat nnmh-current-directory | |
260 (int-to-string (car articles)))) | |
261 (when (setq mod-time (nth 5 (file-attributes article))) | |
262 (if (and (nnmh-deletable-article-p newsgroup (car articles)) | |
263 (setq is-old | |
264 (nnmail-expired-article-p newsgroup mod-time force))) | |
265 (progn | |
266 (nnheader-message 5 "Deleting article %s in %s..." | |
267 article newsgroup) | |
268 (condition-case () | |
269 (funcall nnmail-delete-file-function article) | |
270 (file-error | |
271 (nnheader-message 1 "Couldn't delete article %s in %s" | |
272 article newsgroup) | |
273 (push (car articles) rest)))) | |
274 (push (car articles) rest))) | |
275 (setq articles (cdr articles))) | |
276 (message "") | |
277 (nconc rest articles))) | |
278 | |
279 (deffoo nnmh-close-group (group &optional server) | |
280 t) | |
281 | |
282 (deffoo nnmh-request-move-article | |
283 (article group server accept-form &optional last) | |
284 (let ((buf (get-buffer-create " *nnmh move*")) | |
285 result) | |
286 (and | |
287 (nnmh-deletable-article-p group article) | |
288 (nnmh-request-article article group server) | |
289 (save-excursion | |
290 (set-buffer buf) | |
291 (erase-buffer) | |
292 (insert-buffer-substring nntp-server-buffer) | |
293 (setq result (eval accept-form)) | |
294 (kill-buffer (current-buffer)) | |
295 result) | |
296 (progn | |
297 (nnmh-possibly-change-directory group server) | |
298 (condition-case () | |
299 (funcall nnmail-delete-file-function | |
300 (concat nnmh-current-directory (int-to-string article))) | |
301 (file-error nil)))) | |
302 result)) | |
303 | |
304 (deffoo nnmh-request-accept-article (group &optional server last noinsert) | |
305 (nnmh-possibly-change-directory group server) | |
306 (nnmail-check-syntax) | |
307 (when nnmail-cache-accepted-message-ids | |
308 (nnmail-cache-insert (nnmail-fetch-field "message-id"))) | |
309 (prog1 | |
310 (if (stringp group) | |
311 (and | |
312 (nnmail-activate 'nnmh) | |
313 (car (nnmh-save-mail | |
314 (list (cons group (nnmh-active-number group))) | |
315 noinsert))) | |
316 (and | |
317 (nnmail-activate 'nnmh) | |
318 (let ((res (nnmail-article-group 'nnmh-active-number))) | |
319 (if (and (null res) | |
320 (yes-or-no-p "Moved to `junk' group; delete article? ")) | |
321 'junk | |
322 (car (nnmh-save-mail res noinsert)))))) | |
323 (when (and last nnmail-cache-accepted-message-ids) | |
324 (nnmail-cache-close)))) | |
325 | |
326 (deffoo nnmh-request-replace-article (article group buffer) | |
327 (nnmh-possibly-change-directory group) | |
328 (save-excursion | |
329 (set-buffer buffer) | |
330 (nnmh-possibly-create-directory group) | |
331 (ignore-errors | |
332 (nnmail-write-region | |
333 (point-min) (point-max) | |
334 (concat nnmh-current-directory (int-to-string article)) | |
335 nil (if (nnheader-be-verbose 5) nil 'nomesg)) | |
336 t))) | |
337 | |
338 (deffoo nnmh-request-create-group (group &optional server args) | |
339 (nnmail-activate 'nnmh) | |
340 (unless (assoc group nnmh-group-alist) | |
341 (let (active) | |
342 (push (list group (setq active (cons 1 0))) | |
343 nnmh-group-alist) | |
344 (nnmh-possibly-create-directory group) | |
345 (nnmh-possibly-change-directory group server) | |
346 (let ((articles (mapcar | |
347 (lambda (file) | |
348 (string-to-int file)) | |
349 (directory-files | |
350 nnmh-current-directory nil "^[0-9]+$")))) | |
351 (when articles | |
352 (setcar active (apply 'min articles)) | |
353 (setcdr active (apply 'max articles)))))) | |
354 t) | |
355 | |
356 (deffoo nnmh-request-delete-group (group &optional force server) | |
357 (nnmh-possibly-change-directory group server) | |
358 ;; Delete all articles in GROUP. | |
359 (if (not force) | |
360 () ; Don't delete the articles. | |
361 (let ((articles (directory-files nnmh-current-directory t "^[0-9]+$"))) | |
362 (while articles | |
363 (when (file-writable-p (car articles)) | |
364 (nnheader-message 5 "Deleting article %s in %s..." | |
365 (car articles) group) | |
366 (funcall nnmail-delete-file-function (car articles))) | |
367 (setq articles (cdr articles)))) | |
368 ;; Try to delete the directory itself. | |
369 (ignore-errors | |
370 (delete-directory nnmh-current-directory))) | |
371 ;; Remove the group from all structures. | |
372 (setq nnmh-group-alist | |
373 (delq (assoc group nnmh-group-alist) nnmh-group-alist) | |
374 nnmh-current-directory nil) | |
375 t) | |
376 | |
377 (deffoo nnmh-request-rename-group (group new-name &optional server) | |
378 (nnmh-possibly-change-directory group server) | |
379 (let ((new-dir (nnmail-group-pathname new-name nnmh-directory)) | |
380 (old-dir (nnmail-group-pathname group nnmh-directory))) | |
381 (when (ignore-errors | |
382 (make-directory new-dir t) | |
383 t) | |
384 ;; We move the articles file by file instead of renaming | |
385 ;; the directory -- there may be subgroups in this group. | |
386 ;; One might be more clever, I guess. | |
387 (let ((files (nnheader-article-to-file-alist old-dir))) | |
388 (while files | |
389 (rename-file | |
390 (concat old-dir (cdar files)) | |
391 (concat new-dir (cdar files))) | |
392 (pop files))) | |
393 (when (<= (length (directory-files old-dir)) 2) | |
394 (ignore-errors | |
395 (delete-directory old-dir))) | |
396 ;; That went ok, so we change the internal structures. | |
397 (let ((entry (assoc group nnmh-group-alist))) | |
398 (when entry | |
399 (setcar entry new-name)) | |
400 (setq nnmh-current-directory nil) | |
401 t)))) | |
402 | |
403 (nnoo-define-skeleton nnmh) | |
404 | |
405 | |
406 ;;; Internal functions. | |
407 | |
408 (defun nnmh-possibly-change-directory (newsgroup &optional server) | |
409 (when (and server | |
410 (not (nnmh-server-opened server))) | |
411 (nnmh-open-server server)) | |
412 (when newsgroup | |
19602
549f21ee4bf0
(nnmh-request-list, nnmh-active-number): Protect from
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
413 (let ((pathname (nnmail-group-pathname newsgroup nnmh-directory)) |
549f21ee4bf0
(nnmh-request-list, nnmh-active-number): Protect from
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
414 ;; 1997/8/12 by MORIOKA Tomohiko |
549f21ee4bf0
(nnmh-request-list, nnmh-active-number): Protect from
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
415 ;; for XEmacs/mule. |
549f21ee4bf0
(nnmh-request-list, nnmh-active-number): Protect from
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
416 (pathname-coding-system 'binary)) |
17493 | 417 (if (file-directory-p pathname) |
418 (setq nnmh-current-directory pathname) | |
419 (error "No such newsgroup: %s" newsgroup))))) | |
420 | |
421 (defun nnmh-possibly-create-directory (group) | |
422 (let (dir dirs) | |
423 (setq dir (nnmail-group-pathname group nnmh-directory)) | |
424 (while (not (file-directory-p dir)) | |
425 (push dir dirs) | |
426 (setq dir (file-name-directory (directory-file-name dir)))) | |
427 (while dirs | |
428 (when (make-directory (directory-file-name (car dirs))) | |
429 (error "Could not create directory %s" (car dirs))) | |
430 (nnheader-message 5 "Creating mail directory %s" (car dirs)) | |
431 (setq dirs (cdr dirs))))) | |
432 | |
433 (defun nnmh-save-mail (group-art &optional noinsert) | |
434 "Called narrowed to an article." | |
435 (unless noinsert | |
436 (nnmail-insert-lines) | |
437 (nnmail-insert-xref group-art)) | |
438 (run-hooks 'nnmail-prepare-save-mail-hook) | |
439 (run-hooks 'nnmh-prepare-save-mail-hook) | |
440 (goto-char (point-min)) | |
441 (while (looking-at "From ") | |
442 (replace-match "X-From-Line: ") | |
443 (forward-line 1)) | |
444 ;; We save the article in all the newsgroups it belongs in. | |
445 (let ((ga group-art) | |
446 first) | |
447 (while ga | |
448 (nnmh-possibly-create-directory (caar ga)) | |
449 (let ((file (concat (nnmail-group-pathname | |
450 (caar ga) nnmh-directory) | |
451 (int-to-string (cdar ga))))) | |
452 (if first | |
453 ;; It was already saved, so we just make a hard link. | |
454 (funcall nnmail-crosspost-link-function first file t) | |
455 ;; Save the article. | |
456 (nnmail-write-region (point-min) (point-max) file nil nil) | |
457 (setq first file))) | |
458 (setq ga (cdr ga)))) | |
459 group-art) | |
460 | |
461 (defun nnmh-active-number (group) | |
462 "Compute the next article number in GROUP." | |
463 (let ((active (cadr (assoc group nnmh-group-alist))) | |
19602
549f21ee4bf0
(nnmh-request-list, nnmh-active-number): Protect from
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
464 (dir (nnmail-group-pathname group nnmh-directory)) |
549f21ee4bf0
(nnmh-request-list, nnmh-active-number): Protect from
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
465 ;; 1997/8/14 by MORIOKA Tomohiko |
549f21ee4bf0
(nnmh-request-list, nnmh-active-number): Protect from
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
466 ;; for XEmacs/mule. |
549f21ee4bf0
(nnmh-request-list, nnmh-active-number): Protect from
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
467 (pathname-coding-system 'binary)) |
17493 | 468 (unless active |
469 ;; The group wasn't known to nnmh, so we just create an active | |
470 ;; entry for it. | |
471 (setq active (cons 1 0)) | |
472 (push (list group active) nnmh-group-alist) | |
473 (unless (file-exists-p dir) | |
474 (make-directory dir)) | |
475 ;; Find the highest number in the group. | |
476 (let ((files (sort | |
477 (mapcar | |
478 (lambda (f) | |
479 (string-to-int f)) | |
480 (directory-files dir nil "^[0-9]+$")) | |
481 '>))) | |
482 (when files | |
483 (setcdr active (car files))))) | |
484 (setcdr active (1+ (cdr active))) | |
485 (while (file-exists-p | |
486 (concat (nnmail-group-pathname group nnmh-directory) | |
487 (int-to-string (cdr active)))) | |
488 (setcdr active (1+ (cdr active)))) | |
489 (cdr active))) | |
490 | |
491 (defun nnmh-update-gnus-unreads (group) | |
492 ;; Go through the .nnmh-articles file and compare with the actual | |
493 ;; articles in this folder. The articles that are "new" will be | |
494 ;; marked as unread by Gnus. | |
495 (let* ((dir nnmh-current-directory) | |
496 (files (sort (mapcar (function (lambda (name) (string-to-int name))) | |
497 (directory-files nnmh-current-directory | |
498 nil "^[0-9]+$" t)) | |
499 '<)) | |
500 (nnmh-file (concat dir ".nnmh-articles")) | |
501 new articles) | |
502 ;; Load the .nnmh-articles file. | |
503 (when (file-exists-p nnmh-file) | |
504 (setq articles | |
505 (let (nnmh-newsgroup-articles) | |
506 (ignore-errors (load nnmh-file nil t t)) | |
507 nnmh-newsgroup-articles))) | |
508 ;; Add all new articles to the `new' list. | |
509 (let ((art files)) | |
510 (while art | |
511 (unless (assq (car art) articles) | |
512 (push (car art) new)) | |
513 (setq art (cdr art)))) | |
514 ;; Remove all deleted articles. | |
515 (let ((art articles)) | |
516 (while art | |
517 (unless (memq (caar art) files) | |
518 (setq articles (delq (car art) articles))) | |
519 (setq art (cdr art)))) | |
520 ;; Check whether the articles really are the ones that Gnus thinks | |
521 ;; they are by looking at the time-stamps. | |
522 (let ((arts articles) | |
523 art) | |
524 (while (setq art (pop arts)) | |
525 (when (not (equal | |
526 (nth 5 (file-attributes | |
527 (concat dir (int-to-string (car art))))) | |
528 (cdr art))) | |
529 (setq articles (delq art articles)) | |
530 (push (car art) new)))) | |
531 ;; Go through all the new articles and add them, and their | |
532 ;; time-stamps, to the list. | |
533 (setq articles | |
534 (nconc articles | |
535 (mapcar | |
536 (lambda (art) | |
537 (cons art | |
538 (nth 5 (file-attributes | |
539 (concat dir (int-to-string art)))))) | |
540 new))) | |
541 ;; Make Gnus mark all new articles as unread. | |
542 (when new | |
543 (gnus-make-articles-unread | |
544 (gnus-group-prefixed-name group (list 'nnmh "")) | |
545 (setq new (sort new '<)))) | |
546 ;; Sort the article list with highest numbers first. | |
547 (setq articles (sort articles (lambda (art1 art2) | |
548 (> (car art1) (car art2))))) | |
549 ;; Finally write this list back to the .nnmh-articles file. | |
550 (nnheader-temp-write nnmh-file | |
551 (insert ";; Gnus article active file for " group "\n\n") | |
552 (insert "(setq nnmh-newsgroup-articles '") | |
553 (gnus-prin1 articles) | |
554 (insert ")\n")))) | |
555 | |
556 (defun nnmh-deletable-article-p (group article) | |
557 "Say whether ARTICLE in GROUP can be deleted." | |
558 (let ((path (concat nnmh-current-directory (int-to-string article)))) | |
559 ;; Writable. | |
560 (and (file-writable-p path) | |
561 ;; We can never delete the last article in the group. | |
562 (not (eq (cdr (nth 1 (assoc group nnmh-group-alist))) | |
563 article))))) | |
564 | |
565 (provide 'nnmh) | |
566 | |
567 ;;; nnmh.el ends here |