1 ;;; nnml.el --- mail spool access for Gnus
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
7 ;; Keywords: news, mail
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
28 ;; Based on nnspool.el by Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>.
29 ;; For an overview of what the interface functions do, please see the
37 (eval-when-compile (require 'cl
))
39 (autoload 'gnus-sorted-intersection
"gnus-range"))
43 (defvoo nnml-directory message-directory
44 "Spool directory for the nnml mail backend.")
46 (defvoo nnml-active-file
47 (expand-file-name "active" nnml-directory
)
50 (defvoo nnml-newsgroups-file
51 (expand-file-name "newsgroups" nnml-directory
)
52 "Mail newsgroups description file.")
54 (defvoo nnml-get-new-mail t
55 "If non-nil, nnml will check the incoming mail file and split the mail.")
57 (defvoo nnml-nov-is-evil nil
58 "If non-nil, Gnus will never generate and use nov databases for mail groups.
59 Using nov databases will speed up header fetching considerably.
60 This variable shouldn't be flipped much. If you have, for some reason,
61 set this to t, and want to set it to nil again, you should always run
62 the `nnml-generate-nov-databases' command. The function will go
63 through all nnml directories and generate nov databases for them
64 all. This may very well take some time.")
66 (defvoo nnml-prepare-save-mail-hook nil
67 "Hook run narrowed to an article before saving.")
69 (defvoo nnml-inhibit-expiry nil
70 "If non-nil, inhibit expiry.")
75 (defconst nnml-version
"nnml 1.0"
78 (defvoo nnml-nov-file-name
".overview")
80 (defvoo nnml-current-directory nil
)
81 (defvoo nnml-current-group nil
)
82 (defvoo nnml-status-string
"")
83 (defvoo nnml-nov-buffer-alist nil
)
84 (defvoo nnml-group-alist nil
)
85 (defvoo nnml-active-timestamp nil
)
86 (defvoo nnml-article-file-alist nil
)
88 (defvoo nnml-generate-active-function
'nnml-generate-active-info
)
90 (defvar nnml-nov-buffer-file-name nil
)
92 (defvoo nnml-file-coding-system nnmail-file-coding-system
)
96 ;;; Interface functions.
98 (nnoo-define-basics nnml
)
100 (deffoo nnml-retrieve-headers
(sequence &optional group server fetch-old
)
101 (when (nnml-possibly-change-directory group server
)
103 (set-buffer nntp-server-buffer
)
106 (number (length sequence
))
108 (file-name-coding-system nnmail-pathname-coding-system
)
110 (if (stringp (car sequence
))
112 (if (nnml-retrieve-headers-with-nov sequence fetch-old
)
115 (setq article
(car sequence
))
116 (setq file
(nnml-article-to-file article
))
119 (not (file-directory-p file
)))
120 (insert (format "221 %d Article retrieved.\n" article
))
122 (nnheader-insert-head file
)
124 (if (search-forward "\n\n" nil t
)
126 (goto-char (point-max))
129 (delete-region (point) (point-max)))
130 (setq sequence
(cdr sequence
))
131 (setq count
(1+ count
))
132 (and (numberp nnmail-large-newsgroup
)
133 (> number nnmail-large-newsgroup
)
135 (nnheader-message 6 "nnml: Receiving headers... %d%%"
136 (/ (* count
100) number
))))
138 (and (numberp nnmail-large-newsgroup
)
139 (> number nnmail-large-newsgroup
)
140 (nnheader-message 6 "nnml: Receiving headers...done"))
142 (nnheader-fold-continuation-lines)
145 (deffoo nnml-open-server
(server &optional defs
)
146 (nnoo-change-server 'nnml server defs
)
147 (when (not (file-exists-p nnml-directory
))
148 (ignore-errors (make-directory nnml-directory t
)))
150 ((not (file-exists-p nnml-directory
))
152 (nnheader-report 'nnml
"Couldn't create directory: %s" nnml-directory
))
153 ((not (file-directory-p (file-truename nnml-directory
)))
155 (nnheader-report 'nnml
"Not a directory: %s" nnml-directory
))
157 (nnheader-report 'nnml
"Opened server %s using directory %s"
158 server nnml-directory
)
161 (defun nnml-request-regenerate (server)
162 (nnml-possibly-change-directory nil server
)
163 (nnml-generate-nov-databases)
166 (deffoo nnml-request-article
(id &optional group server buffer
)
167 (nnml-possibly-change-directory group server
)
168 (let* ((nntp-server-buffer (or buffer nntp-server-buffer
))
169 (file-name-coding-system nnmail-pathname-coding-system
)
170 path gpath group-num
)
172 (when (and (setq group-num
(nnml-find-group-number id
))
174 (assq (cdr group-num
)
175 (nnheader-article-to-file-alist
177 (nnmail-group-pathname
180 (setq path
(concat gpath
(int-to-string (cdr group-num
)))))
181 (setq path
(nnml-article-to-file id
)))
184 (nnheader-report 'nnml
"No such article: %s" id
))
185 ((not (file-exists-p path
))
186 (nnheader-report 'nnml
"No such file: %s" path
))
187 ((file-directory-p path
)
188 (nnheader-report 'nnml
"File is a directory: %s" path
))
189 ((not (save-excursion (let ((nnmail-file-coding-system
190 nnml-file-coding-system
))
191 (nnmail-find-file path
))))
192 (nnheader-report 'nnml
"Couldn't read file: %s" path
))
194 (nnheader-report 'nnml
"Article %s retrieved" id
)
195 ;; We return the article number.
196 (cons (if group-num
(car group-num
) group
)
197 (string-to-int (file-name-nondirectory path
)))))))
199 (deffoo nnml-request-group
(group &optional server dont-check
)
200 (let ((file-name-coding-system nnmail-pathname-coding-system
))
202 ((not (nnml-possibly-change-directory group server
))
203 (nnheader-report 'nnml
"Invalid group (no such directory)"))
204 ((not (file-exists-p nnml-current-directory
))
205 (nnheader-report 'nnml
"Directory %s does not exist"
206 nnml-current-directory
))
207 ((not (file-directory-p nnml-current-directory
))
208 (nnheader-report 'nnml
"%s is not a directory" nnml-current-directory
))
210 (nnheader-report 'nnml
"Group %s selected" group
)
213 (nnheader-re-read-dir nnml-current-directory
)
214 (nnmail-activate 'nnml
)
215 (let ((active (nth 1 (assoc group nnml-group-alist
))))
217 (nnheader-report 'nnml
"No such group: %s" group
)
218 (nnheader-report 'nnml
"Selected group %s" group
)
219 (nnheader-insert "211 %d %d %d %s\n"
220 (max (1+ (- (cdr active
) (car active
))) 0)
221 (car active
) (cdr active
) group
)))))))
223 (deffoo nnml-request-scan
(&optional group server
)
224 (setq nnml-article-file-alist nil
)
225 (nnml-possibly-change-directory group server
)
226 (nnmail-get-new-mail 'nnml
'nnml-save-nov nnml-directory group
))
228 (deffoo nnml-close-group
(group &optional server
)
229 (setq nnml-article-file-alist nil
)
232 (deffoo nnml-request-create-group
(group &optional server args
)
233 (nnml-possibly-change-directory nil server
)
234 (nnmail-activate 'nnml
)
236 ((assoc group nnml-group-alist
)
238 ((and (file-exists-p (nnmail-group-pathname group nnml-directory
))
239 (not (file-directory-p (nnmail-group-pathname group nnml-directory
))))
240 (nnheader-report 'nnml
"%s is a file"
241 (nnmail-group-pathname group nnml-directory
)))
244 (push (list group
(setq active
(cons 1 0)))
246 (nnml-possibly-create-directory group
)
247 (nnml-possibly-change-directory group server
)
248 (let ((articles (nnheader-directory-articles nnml-current-directory
)))
250 (setcar active
(apply 'min articles
))
251 (setcdr active
(apply 'max articles
))))
252 (nnmail-save-active nnml-group-alist nnml-active-file
)
255 (deffoo nnml-request-list
(&optional server
)
257 (let ((nnmail-file-coding-system nnmail-active-file-coding-system
)
258 (file-name-coding-system nnmail-pathname-coding-system
))
259 (nnmail-find-file nnml-active-file
))
260 (setq nnml-group-alist
(nnmail-get-active))
263 (deffoo nnml-request-newgroups
(date &optional server
)
264 (nnml-request-list server
))
266 (deffoo nnml-request-list-newsgroups
(&optional server
)
268 (nnmail-find-file nnml-newsgroups-file
)))
270 (deffoo nnml-request-expire-articles
(articles group
&optional server force
)
271 (nnml-possibly-change-directory group server
)
272 (let ((active-articles
273 (nnheader-directory-articles nnml-current-directory
))
275 article rest mod-time number
)
276 (nnmail-activate 'nnml
)
278 (setq active-articles
(sort active-articles
'<))
279 ;; Articles not listed in active-articles are already gone,
280 ;; so don't try to expire them.
281 (setq articles
(gnus-sorted-intersection articles active-articles
))
283 (while (and articles is-old
)
284 (when (setq article
(nnml-article-to-file (setq number
(pop articles
))))
285 (when (setq mod-time
(nth 5 (file-attributes article
)))
286 (if (and (nnml-deletable-article-p group number
)
288 (nnmail-expired-article-p group mod-time force
289 nnml-inhibit-expiry
)))
291 ;; Allow a special target group.
292 (unless (eq nnmail-expiry-target
'delete
)
294 (nnml-request-article number group server
296 (let ((nnml-current-directory nil
))
297 (nnmail-expiry-target-group
298 nnmail-expiry-target group
))))
299 (nnheader-message 5 "Deleting article %s in %s"
302 (funcall nnmail-delete-file-function article
)
305 (setq active-articles
(delq number active-articles
))
306 (nnml-nov-delete-article group number
))
307 (push number rest
)))))
308 (let ((active (nth 1 (assoc group nnml-group-alist
))))
310 (setcar active
(or (and active-articles
311 (apply 'min active-articles
))
313 (nnmail-save-active nnml-group-alist nnml-active-file
))
315 (nconc rest articles
)))
317 (deffoo nnml-request-move-article
318 (article group server accept-form
&optional last
)
319 (let ((buf (get-buffer-create " *nnml move*"))
321 (nnml-possibly-change-directory group server
)
322 (nnml-update-file-alist)
324 (nnml-deletable-article-p group article
)
325 (nnml-request-article article group server
)
326 (let (nnml-current-directory
328 nnml-article-file-alist
)
331 (insert-buffer-substring nntp-server-buffer
)
332 (setq result
(eval accept-form
))
333 (kill-buffer (current-buffer))
336 (nnml-possibly-change-directory group server
)
338 (funcall nnmail-delete-file-function
339 (nnml-article-to-file article
))
341 (nnml-nov-delete-article group article
)
344 (nnmail-save-active nnml-group-alist nnml-active-file
))))
347 (deffoo nnml-request-accept-article
(group &optional server last
)
348 (nnml-possibly-change-directory group server
)
349 (nnmail-check-syntax)
351 (when nnmail-cache-accepted-message-ids
352 (nnmail-cache-insert (nnmail-fetch-field "message-id")))
355 (nnmail-activate 'nnml
)
356 (setq result
(car (nnml-save-mail
357 (list (cons group
(nnml-active-number group
))))))
359 (nnmail-save-active nnml-group-alist nnml-active-file
)
360 (and last
(nnml-save-nov))))
362 (nnmail-activate 'nnml
)
363 (if (and (not (setq result
(nnmail-article-group 'nnml-active-number
)))
364 (yes-or-no-p "Moved to `junk' group; delete article? "))
366 (setq result
(car (nnml-save-mail result
))))
368 (nnmail-save-active nnml-group-alist nnml-active-file
)
369 (when nnmail-cache-accepted-message-ids
370 (nnmail-cache-close))
374 (deffoo nnml-request-replace-article
(article group buffer
)
375 (nnml-possibly-change-directory group
)
378 (nnml-possibly-create-directory group
)
379 (let ((chars (nnmail-insert-lines))
380 (art (concat (int-to-string article
) "\t"))
384 (point-min) (point-max)
385 (or (nnml-article-to-file article
)
386 (expand-file-name (int-to-string article
)
387 nnml-current-directory
))
388 nil
(if (nnheader-be-verbose 5) nil
'nomesg
))
390 (setq headers
(nnml-parse-head chars article
))
391 ;; Replace the NOV line in the NOV file.
393 (set-buffer (nnml-open-nov group
))
394 (goto-char (point-min))
395 (if (or (looking-at art
)
396 (search-forward (concat "\n" art
) nil t
))
397 ;; Delete the old NOV line.
398 (delete-region (progn (beginning-of-line) (point))
399 (progn (forward-line 1) (point)))
400 ;; The line isn't here, so we have to find out where
401 ;; we should insert it. (This situation should never
402 ;; occur, but one likes to make sure...)
403 (while (and (looking-at "[0-9]+\t")
406 (match-beginning 0) (match-end 0)))
408 (zerop (forward-line 1)))))
410 (nnheader-insert-nov headers
)
414 (deffoo nnml-request-delete-group
(group &optional force server
)
415 (nnml-possibly-change-directory group server
)
417 ;; Delete all articles in GROUP.
420 nnml-current-directory t
421 (concat nnheader-numerical-short-files
422 "\\|" (regexp-quote nnml-nov-file-name
) "$")))
425 (setq article
(pop articles
))
426 (when (file-writable-p article
)
427 (nnheader-message 5 "Deleting article %s in %s..." article group
)
428 (funcall nnmail-delete-file-function article
))))
429 ;; Try to delete the directory itself.
430 (ignore-errors (delete-directory nnml-current-directory
)))
431 ;; Remove the group from all structures.
432 (setq nnml-group-alist
433 (delq (assoc group nnml-group-alist
) nnml-group-alist
)
434 nnml-current-group nil
435 nnml-current-directory nil
)
436 ;; Save the active file.
437 (nnmail-save-active nnml-group-alist nnml-active-file
)
440 (deffoo nnml-request-rename-group
(group new-name
&optional server
)
441 (nnml-possibly-change-directory group server
)
442 (let ((new-dir (nnmail-group-pathname new-name nnml-directory
))
443 (old-dir (nnmail-group-pathname group nnml-directory
)))
445 (make-directory new-dir t
)
447 ;; We move the articles file by file instead of renaming
448 ;; the directory -- there may be subgroups in this group.
449 ;; One might be more clever, I guess.
450 (let ((files (nnheader-article-to-file-alist old-dir
)))
453 (concat old-dir
(cdar files
))
454 (concat new-dir
(cdar files
)))
456 ;; Move .overview file.
457 (let ((overview (concat old-dir nnml-nov-file-name
)))
458 (when (file-exists-p overview
)
459 (rename-file overview
(concat new-dir nnml-nov-file-name
))))
460 (when (<= (length (directory-files old-dir
)) 2)
461 (ignore-errors (delete-directory old-dir
)))
462 ;; That went ok, so we change the internal structures.
463 (let ((entry (assoc group nnml-group-alist
)))
465 (setcar entry new-name
))
466 (setq nnml-current-directory nil
467 nnml-current-group nil
)
468 ;; Save the new group alist.
469 (nnmail-save-active nnml-group-alist nnml-active-file
)
472 (deffoo nnml-set-status
(article name value
&optional group server
)
473 (nnml-possibly-change-directory group server
)
474 (let ((file (nnml-article-to-file article
)))
476 ((not (file-exists-p file
))
477 (nnheader-report 'nnml
"File %s does not exist" file
))
480 (nnheader-insert-file-contents file
)
481 (nnmail-replace-status name value
))
485 ;;; Internal functions.
487 (defun nnml-article-to-file (article)
488 (nnml-update-file-alist)
490 (if (setq file
(cdr (assq article nnml-article-file-alist
)))
491 (expand-file-name file nnml-current-directory
)
492 ;; Just to make sure nothing went wrong when reading over NFS --
495 (setq file
(expand-file-name (number-to-string article
)
496 nnml-current-directory
)))
497 (nnml-update-file-alist t
)
500 (defun nnml-deletable-article-p (group article
)
501 "Say whether ARTICLE in GROUP can be deleted."
503 (when (setq path
(nnml-article-to-file article
))
504 (when (file-writable-p path
)
505 (or (not nnmail-keep-last-article
)
506 (not (eq (cdr (nth 1 (assoc group nnml-group-alist
)))
509 ;; Find an article number in the current group given the Message-ID.
510 (defun nnml-find-group-number (id)
512 (set-buffer (get-buffer-create " *nnml id*"))
513 (let ((alist nnml-group-alist
)
515 ;; We want to look through all .overview files, but we want to
516 ;; start with the one in the current directory. It seems most
517 ;; likely that the article we are looking for is in that group.
518 (if (setq number
(nnml-find-id nnml-current-group id
))
519 (cons nnml-current-group number
)
520 ;; It wasn't there, so we look through the other groups as well.
521 (while (and (not number
)
523 (or (string= (caar alist
) nnml-current-group
)
524 (setq number
(nnml-find-id (caar alist
) id
)))
526 (setq alist
(cdr alist
))))
528 (cons (caar alist
) number
))))))
530 (defun nnml-find-id (group id
)
532 (let ((nov (expand-file-name nnml-nov-file-name
533 (nnmail-group-pathname group nnml-directory
)))
535 (when (file-exists-p nov
)
536 (nnheader-insert-file-contents nov
)
537 (while (and (not found
)
538 (search-forward id nil t
)) ; We find the ID.
539 ;; And the id is in the fourth field.
540 (if (not (and (search-backward "\t" nil t
4)
541 (not (search-backward"\t" (gnus-point-at-bol) t
))))
545 ;; We return the article number.
547 (ignore-errors (read (current-buffer))))))
550 (defun nnml-retrieve-headers-with-nov (articles &optional fetch-old
)
551 (if (or gnus-nov-is-evil nnml-nov-is-evil
)
553 (let ((nov (expand-file-name nnml-nov-file-name nnml-current-directory
)))
554 (when (file-exists-p nov
)
556 (set-buffer nntp-server-buffer
)
558 (nnheader-insert-file-contents nov
)
560 (not (numberp fetch-old
)))
561 t
; Don't remove anything.
562 (nnheader-nov-delete-outside-range
563 (if fetch-old
(max 1 (- (car articles
) fetch-old
))
565 (car (last articles
)))
568 (defun nnml-possibly-change-directory (group &optional server
)
570 (not (nnml-server-opened server
)))
571 (nnml-open-server server
))
574 (let ((pathname (nnmail-group-pathname group nnml-directory
))
575 (file-name-coding-system nnmail-pathname-coding-system
))
576 (when (not (equal pathname nnml-current-directory
))
577 (setq nnml-current-directory pathname
578 nnml-current-group group
579 nnml-article-file-alist nil
))
580 (file-exists-p nnml-current-directory
))))
582 (defun nnml-possibly-create-directory (group)
583 (let ((dir (nnmail-group-pathname group nnml-directory
)))
584 (unless (file-exists-p dir
)
585 (make-directory (directory-file-name dir
) t
)
586 (nnheader-message 5 "Creating mail directory %s" dir
))))
588 (defun nnml-save-mail (group-art)
589 "Called narrowed to an article."
591 (setq chars
(nnmail-insert-lines))
592 (nnmail-insert-xref group-art
)
593 (run-hooks 'nnmail-prepare-save-mail-hook
)
594 (run-hooks 'nnml-prepare-save-mail-hook
)
595 (goto-char (point-min))
596 (while (looking-at "From ")
597 (replace-match "X-From-Line: ")
599 ;; We save the article in all the groups it belongs in.
603 (nnml-possibly-create-directory (caar ga
))
604 (let ((file (concat (nnmail-group-pathname
605 (caar ga
) nnml-directory
)
606 (int-to-string (cdar ga
)))))
608 ;; It was already saved, so we just make a hard link.
609 (funcall nnmail-crosspost-link-function first file t
)
611 (nnmail-write-region (point-min) (point-max) file nil
612 (if (nnheader-be-verbose 5) nil
'nomesg
))
615 ;; Generate a nov line for this article. We generate the nov
616 ;; line after saving, because nov generation destroys the
618 (setq headers
(nnml-parse-head chars
))
619 ;; Output the nov line to all nov databases that should have it.
620 (let ((ga group-art
))
622 (nnml-add-nov (caar ga
) (cdar ga
) headers
)
626 (defun nnml-active-number (group)
627 "Compute the next article number in GROUP."
628 (let ((active (cadr (assoc group nnml-group-alist
))))
629 ;; The group wasn't known to nnml, so we just create an active
632 ;; Perhaps the active file was corrupt? See whether
633 ;; there are any articles in this group.
634 (nnml-possibly-create-directory group
)
635 (nnml-possibly-change-directory group
)
636 (unless nnml-article-file-alist
637 (setq nnml-article-file-alist
639 (nnheader-article-to-file-alist nnml-current-directory
)
640 'car-less-than-car
)))
642 (if nnml-article-file-alist
643 (cons (caar nnml-article-file-alist
)
644 (caar (last nnml-article-file-alist
)))
646 (push (list group active
) nnml-group-alist
))
647 (setcdr active
(1+ (cdr active
)))
648 (while (file-exists-p
649 (expand-file-name (int-to-string (cdr active
))
650 (nnmail-group-pathname group nnml-directory
)))
651 (setcdr active
(1+ (cdr active
))))
654 (defun nnml-add-nov (group article headers
)
655 "Add a nov line for the GROUP base."
657 (set-buffer (nnml-open-nov group
))
658 (goto-char (point-max))
659 (mail-header-set-number headers article
)
660 (nnheader-insert-nov headers
)))
662 (defsubst nnml-header-value
()
663 (buffer-substring (match-end 0) (progn (end-of-line) (point))))
665 (defun nnml-parse-head (chars &optional number
)
666 "Parse the head of the current buffer."
669 (unless (zerop (buffer-size))
671 (goto-char (point-min))
672 (if (search-forward "\n\n" nil t
) (1- (point)) (point-max))))
673 ;; Fold continuation lines.
674 (goto-char (point-min))
675 (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t
)
676 (replace-match " " t t
))
677 ;; Remove any tabs; they are too confusing.
678 (subst-char-in-region (point-min) (point-max) ?
\t ?
)
679 (let ((headers (nnheader-parse-head t
)))
680 (mail-header-set-chars headers chars
)
681 (mail-header-set-number headers number
)
684 (defun nnml-open-nov (group)
685 (or (cdr (assoc group nnml-nov-buffer-alist
))
686 (let ((buffer (get-buffer-create (format " *nnml overview %s*" group
))))
689 (set (make-local-variable 'nnml-nov-buffer-file-name
)
692 (nnmail-group-pathname group nnml-directory
)))
694 (when (file-exists-p nnml-nov-buffer-file-name
)
695 (nnheader-insert-file-contents nnml-nov-buffer-file-name
)))
696 (push (cons group buffer
) nnml-nov-buffer-alist
)
699 (defun nnml-save-nov ()
701 (while nnml-nov-buffer-alist
702 (when (buffer-name (cdar nnml-nov-buffer-alist
))
703 (set-buffer (cdar nnml-nov-buffer-alist
))
704 (when (buffer-modified-p)
705 (nnmail-write-region 1 (point-max) nnml-nov-buffer-file-name
707 (set-buffer-modified-p nil
)
708 (kill-buffer (current-buffer)))
709 (setq nnml-nov-buffer-alist
(cdr nnml-nov-buffer-alist
)))))
712 (defun nnml-generate-nov-databases ()
713 "Generate NOV databases in all nnml directories."
715 ;; Read the active file to make sure we don't re-use articles
716 ;; numbers in empty groups.
717 (nnmail-activate 'nnml
)
718 (nnml-open-server (or (nnoo-current-server 'nnml
) ""))
719 (setq nnml-directory
(expand-file-name nnml-directory
))
720 ;; Recurse down the directories.
721 (nnml-generate-nov-databases-1 nnml-directory nil t
)
722 ;; Save the active file.
723 (nnmail-save-active nnml-group-alist nnml-active-file
))
725 (defun nnml-generate-nov-databases-1 (dir &optional seen no-active
)
726 "Regenerate the NOV database in DIR."
727 (interactive "DRegenerate NOV in: ")
728 (setq dir
(file-name-as-directory dir
))
729 ;; Only scan this sub-tree if we haven't been here yet.
730 (unless (member (file-truename dir
) seen
)
731 (push (file-truename dir
) seen
)
732 ;; We descend recursively
733 (let ((dirs (directory-files dir t nil t
))
735 (while (setq dir
(pop dirs
))
736 (when (and (not (string-match "^\\." (file-name-nondirectory dir
)))
737 (file-directory-p dir
))
738 (nnml-generate-nov-databases-1 dir seen
))))
739 ;; Do this directory.
740 (let ((files (sort (nnheader-article-to-file-alist dir
)
741 'car-less-than-car
)))
743 (let* ((group (nnheader-file-to-group
744 (directory-file-name dir
) nnml-directory
))
745 (info (cadr (assoc group nnml-group-alist
))))
747 (setcar info
(1+ (cdr info
)))))
748 (funcall nnml-generate-active-function dir
)
749 ;; Generate the nov file.
750 (nnml-generate-nov-file dir files
)
752 (nnmail-save-active nnml-group-alist nnml-active-file
))))))
754 (eval-when-compile (defvar files
))
755 (defun nnml-generate-active-info (dir)
756 ;; Update the active info for this group.
757 (let ((group (nnheader-file-to-group
758 (directory-file-name dir
) nnml-directory
)))
759 (setq nnml-group-alist
760 (delq (assoc group nnml-group-alist
) nnml-group-alist
))
764 (while (cdr f
) (setq f
(cdr f
)))
768 (defun nnml-generate-nov-file (dir files
)
769 (let* ((dir (file-name-as-directory dir
))
770 (nov (concat dir nnml-nov-file-name
))
771 (nov-buffer (get-buffer-create " *nov*"))
774 ;; Init the nov buffer.
775 (set-buffer nov-buffer
)
776 (buffer-disable-undo)
778 (set-buffer nntp-server-buffer
)
779 ;; Delete the old NOV file.
780 (when (file-exists-p nov
)
781 (funcall nnmail-delete-file-function nov
))
783 (unless (file-directory-p (setq file
(concat dir
(cdar files
))))
785 (nnheader-insert-file-contents file
)
787 (goto-char (point-min))
789 (search-forward "\n\n" nil t
)
790 (setq chars
(- (point-max) (point)))
791 (max 1 (1- (point)))))
792 (unless (zerop (buffer-size))
793 (goto-char (point-min))
794 (setq headers
(nnml-parse-head chars
(caar files
)))
796 (set-buffer nov-buffer
)
797 (goto-char (point-max))
798 (nnheader-insert-nov headers
)))
800 (setq files
(cdr files
)))
802 (set-buffer nov-buffer
)
803 (nnmail-write-region 1 (point-max) nov nil
'nomesg
)
804 (kill-buffer (current-buffer))))))
806 (defun nnml-nov-delete-article (group article
)
808 (set-buffer (nnml-open-nov group
))
809 (when (nnheader-find-nov-line article
)
810 (delete-region (point) (progn (forward-line 1) (point)))
812 (let ((active (cadr (assoc group nnml-group-alist
)))
816 (setf (car active
) (1+ (cdr active
)))
817 (when (and (setq num
(ignore-errors (read (current-buffer))))
819 (setf (car active
) num
)))))))
822 (defun nnml-update-file-alist (&optional force
)
823 (when (or (not nnml-article-file-alist
)
825 (setq nnml-article-file-alist
826 (nnheader-article-to-file-alist nnml-current-directory
))))
830 ;;; nnml.el ends here