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
34 (eval-when-compile (require 'cl))
35 (eval-when-compile (require 'gnus-clfns))
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 (pathname-coding-system 'binary)
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 (pathname-coding-system 'binary)
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 ((pathname-coding-system 'binary))
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 (pathname-coding-system 'binary))
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 article group server
296 (nnmail-expiry-target-group
297 nnmail-expiry-target group)))
298 (nnheader-message 5 "Deleting article %s in %s"
301 (funcall nnmail-delete-file-function article)
304 (setq active-articles (delq number active-articles))
305 (nnml-nov-delete-article group number))
306 (push number rest)))))
307 (let ((active (nth 1 (assoc group nnml-group-alist))))
309 (setcar active (or (and active-articles
310 (apply 'min active-articles))
312 (nnmail-save-active nnml-group-alist nnml-active-file))
314 (nconc rest articles)))
316 (deffoo nnml-request-move-article
317 (article group server accept-form &optional last)
318 (let ((buf (get-buffer-create " *nnml move*"))
320 (nnml-possibly-change-directory group server)
321 (nnml-update-file-alist)
323 (nnml-deletable-article-p group article)
324 (nnml-request-article article group server)
325 (let (nnml-current-directory
327 nnml-article-file-alist)
330 (insert-buffer-substring nntp-server-buffer)
331 (setq result (eval accept-form))
332 (kill-buffer (current-buffer))
335 (nnml-possibly-change-directory group server)
337 (funcall nnmail-delete-file-function
338 (nnml-article-to-file article))
340 (nnml-nov-delete-article group article)
343 (nnmail-save-active nnml-group-alist nnml-active-file))))
346 (deffoo nnml-request-accept-article (group &optional server last)
347 (nnml-possibly-change-directory group server)
348 (nnmail-check-syntax)
350 (when nnmail-cache-accepted-message-ids
351 (nnmail-cache-insert (nnmail-fetch-field "message-id")))
354 (nnmail-activate 'nnml)
355 (setq result (car (nnml-save-mail
356 (list (cons group (nnml-active-number group))))))
358 (nnmail-save-active nnml-group-alist nnml-active-file)
359 (and last (nnml-save-nov))))
361 (nnmail-activate 'nnml)
362 (if (and (not (setq result (nnmail-article-group 'nnml-active-number)))
363 (yes-or-no-p "Moved to `junk' group; delete article? "))
365 (setq result (car (nnml-save-mail result))))
367 (nnmail-save-active nnml-group-alist nnml-active-file)
368 (when nnmail-cache-accepted-message-ids
369 (nnmail-cache-close))
373 (deffoo nnml-request-replace-article (article group buffer)
374 (nnml-possibly-change-directory group)
377 (nnml-possibly-create-directory group)
378 (let ((chars (nnmail-insert-lines))
379 (art (concat (int-to-string article) "\t"))
383 (point-min) (point-max)
384 (or (nnml-article-to-file article)
385 (expand-file-name (int-to-string article)
386 nnml-current-directory))
387 nil (if (nnheader-be-verbose 5) nil 'nomesg))
389 (setq headers (nnml-parse-head chars article))
390 ;; Replace the NOV line in the NOV file.
392 (set-buffer (nnml-open-nov group))
393 (goto-char (point-min))
394 (if (or (looking-at art)
395 (search-forward (concat "\n" art) nil t))
396 ;; Delete the old NOV line.
397 (delete-region (progn (beginning-of-line) (point))
398 (progn (forward-line 1) (point)))
399 ;; The line isn't here, so we have to find out where
400 ;; we should insert it. (This situation should never
401 ;; occur, but one likes to make sure...)
402 (while (and (looking-at "[0-9]+\t")
405 (match-beginning 0) (match-end 0)))
407 (zerop (forward-line 1)))))
409 (nnheader-insert-nov headers)
413 (deffoo nnml-request-delete-group (group &optional force server)
414 (nnml-possibly-change-directory group server)
416 ;; Delete all articles in GROUP.
419 nnml-current-directory t
420 (concat nnheader-numerical-short-files
421 "\\|" (regexp-quote nnml-nov-file-name) "$")))
424 (setq article (pop articles))
425 (when (file-writable-p article)
426 (nnheader-message 5 "Deleting article %s in %s..." article group)
427 (funcall nnmail-delete-file-function article))))
428 ;; Try to delete the directory itself.
429 (ignore-errors (delete-directory nnml-current-directory)))
430 ;; Remove the group from all structures.
431 (setq nnml-group-alist
432 (delq (assoc group nnml-group-alist) nnml-group-alist)
433 nnml-current-group nil
434 nnml-current-directory nil)
435 ;; Save the active file.
436 (nnmail-save-active nnml-group-alist nnml-active-file)
439 (deffoo nnml-request-rename-group (group new-name &optional server)
440 (nnml-possibly-change-directory group server)
441 (let ((new-dir (nnmail-group-pathname new-name nnml-directory))
442 (old-dir (nnmail-group-pathname group nnml-directory)))
444 (make-directory new-dir t)
446 ;; We move the articles file by file instead of renaming
447 ;; the directory -- there may be subgroups in this group.
448 ;; One might be more clever, I guess.
449 (let ((files (nnheader-article-to-file-alist old-dir)))
452 (concat old-dir (cdar files))
453 (concat new-dir (cdar files)))
455 ;; Move .overview file.
456 (let ((overview (concat old-dir nnml-nov-file-name)))
457 (when (file-exists-p overview)
458 (rename-file overview (concat new-dir nnml-nov-file-name))))
459 (when (<= (length (directory-files old-dir)) 2)
460 (ignore-errors (delete-directory old-dir)))
461 ;; That went ok, so we change the internal structures.
462 (let ((entry (assoc group nnml-group-alist)))
464 (setcar entry new-name))
465 (setq nnml-current-directory nil
466 nnml-current-group nil)
467 ;; Save the new group alist.
468 (nnmail-save-active nnml-group-alist nnml-active-file)
471 (deffoo nnml-set-status (article name value &optional group server)
472 (nnml-possibly-change-directory group server)
473 (let ((file (nnml-article-to-file article)))
475 ((not (file-exists-p file))
476 (nnheader-report 'nnml "File %s does not exist" file))
479 (nnheader-insert-file-contents file)
480 (nnmail-replace-status name value))
484 ;;; Internal functions.
486 (defun nnml-article-to-file (article)
487 (nnml-update-file-alist)
489 (if (setq file (cdr (assq article nnml-article-file-alist)))
490 (expand-file-name file nnml-current-directory)
491 ;; Just to make sure nothing went wrong when reading over NFS --
494 (setq file (expand-file-name (number-to-string article)
495 nnml-current-directory)))
496 (nnml-update-file-alist t)
499 (defun nnml-deletable-article-p (group article)
500 "Say whether ARTICLE in GROUP can be deleted."
502 (when (setq path (nnml-article-to-file article))
503 (when (file-writable-p path)
504 (or (not nnmail-keep-last-article)
505 (not (eq (cdr (nth 1 (assoc group nnml-group-alist)))
508 ;; Find an article number in the current group given the Message-ID.
509 (defun nnml-find-group-number (id)
511 (set-buffer (get-buffer-create " *nnml id*"))
512 (let ((alist nnml-group-alist)
514 ;; We want to look through all .overview files, but we want to
515 ;; start with the one in the current directory. It seems most
516 ;; likely that the article we are looking for is in that group.
517 (if (setq number (nnml-find-id nnml-current-group id))
518 (cons nnml-current-group number)
519 ;; It wasn't there, so we look through the other groups as well.
520 (while (and (not number)
522 (or (string= (caar alist) nnml-current-group)
523 (setq number (nnml-find-id (caar alist) id)))
525 (setq alist (cdr alist))))
527 (cons (caar alist) number))))))
529 (defun nnml-find-id (group id)
531 (let ((nov (expand-file-name nnml-nov-file-name
532 (nnmail-group-pathname group nnml-directory)))
534 (when (file-exists-p nov)
535 (nnheader-insert-file-contents nov)
536 (while (and (not found)
537 (search-forward id nil t)) ; We find the ID.
538 ;; And the id is in the fourth field.
539 (if (not (and (search-backward "\t" nil t 4)
540 (not (search-backward"\t" (gnus-point-at-bol) t))))
544 ;; We return the article number.
546 (ignore-errors (read (current-buffer))))))
549 (defun nnml-retrieve-headers-with-nov (articles &optional fetch-old)
550 (if (or gnus-nov-is-evil nnml-nov-is-evil)
552 (let ((nov (expand-file-name nnml-nov-file-name nnml-current-directory)))
553 (when (file-exists-p nov)
555 (set-buffer nntp-server-buffer)
557 (nnheader-insert-file-contents nov)
559 (not (numberp fetch-old)))
560 t ; Don't remove anything.
561 (nnheader-nov-delete-outside-range
562 (if fetch-old (max 1 (- (car articles) fetch-old))
564 (car (last articles)))
567 (defun nnml-possibly-change-directory (group &optional server)
569 (not (nnml-server-opened server)))
570 (nnml-open-server server))
573 (let ((pathname (nnmail-group-pathname group nnml-directory))
574 (pathname-coding-system 'binary))
575 (when (not (equal pathname nnml-current-directory))
576 (setq nnml-current-directory pathname
577 nnml-current-group group
578 nnml-article-file-alist nil))
579 (file-exists-p nnml-current-directory))))
581 (defun nnml-possibly-create-directory (group)
582 (let ((dir (nnmail-group-pathname group nnml-directory)))
583 (unless (file-exists-p dir)
584 (make-directory (directory-file-name dir) t)
585 (nnheader-message 5 "Creating mail directory %s" dir))))
587 (defun nnml-save-mail (group-art)
588 "Called narrowed to an article."
590 (setq chars (nnmail-insert-lines))
591 (nnmail-insert-xref group-art)
592 (run-hooks 'nnmail-prepare-save-mail-hook)
593 (run-hooks 'nnml-prepare-save-mail-hook)
594 (goto-char (point-min))
595 (while (looking-at "From ")
596 (replace-match "X-From-Line: ")
598 ;; We save the article in all the groups it belongs in.
602 (nnml-possibly-create-directory (caar ga))
603 (let ((file (concat (nnmail-group-pathname
604 (caar ga) nnml-directory)
605 (int-to-string (cdar ga)))))
607 ;; It was already saved, so we just make a hard link.
608 (funcall nnmail-crosspost-link-function first file t)
610 (nnmail-write-region (point-min) (point-max) file nil
611 (if (nnheader-be-verbose 5) nil 'nomesg))
614 ;; Generate a nov line for this article. We generate the nov
615 ;; line after saving, because nov generation destroys the
617 (setq headers (nnml-parse-head chars))
618 ;; Output the nov line to all nov databases that should have it.
619 (let ((ga group-art))
621 (nnml-add-nov (caar ga) (cdar ga) headers)
625 (defun nnml-active-number (group)
626 "Compute the next article number in GROUP."
627 (let ((active (cadr (assoc group nnml-group-alist))))
628 ;; The group wasn't known to nnml, so we just create an active
631 ;; Perhaps the active file was corrupt? See whether
632 ;; there are any articles in this group.
633 (nnml-possibly-create-directory group)
634 (nnml-possibly-change-directory group)
635 (unless nnml-article-file-alist
636 (setq nnml-article-file-alist
638 (nnheader-article-to-file-alist nnml-current-directory)
639 'car-less-than-car)))
641 (if nnml-article-file-alist
642 (cons (caar nnml-article-file-alist)
643 (caar (last nnml-article-file-alist)))
645 (push (list group active) nnml-group-alist))
646 (setcdr active (1+ (cdr active)))
647 (while (file-exists-p
648 (expand-file-name (int-to-string (cdr active))
649 (nnmail-group-pathname group nnml-directory)))
650 (setcdr active (1+ (cdr active))))
653 (defun nnml-add-nov (group article headers)
654 "Add a nov line for the GROUP base."
656 (set-buffer (nnml-open-nov group))
657 (goto-char (point-max))
658 (mail-header-set-number headers article)
659 (nnheader-insert-nov headers)))
661 (defsubst nnml-header-value ()
662 (buffer-substring (match-end 0) (progn (end-of-line) (point))))
664 (defun nnml-parse-head (chars &optional number)
665 "Parse the head of the current buffer."
668 (unless (zerop (buffer-size))
670 (goto-char (point-min))
671 (if (search-forward "\n\n" nil t) (1- (point)) (point-max))))
672 ;; Fold continuation lines.
673 (goto-char (point-min))
674 (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t)
675 (replace-match " " t t))
676 ;; Remove any tabs; they are too confusing.
677 (subst-char-in-region (point-min) (point-max) ?\t ? )
678 (let ((headers (nnheader-parse-head t)))
679 (mail-header-set-chars headers chars)
680 (mail-header-set-number headers number)
683 (defun nnml-open-nov (group)
684 (or (cdr (assoc group nnml-nov-buffer-alist))
685 (let ((buffer (get-buffer-create (format " *nnml overview %s*" group))))
688 (set (make-local-variable 'nnml-nov-buffer-file-name)
691 (nnmail-group-pathname group nnml-directory)))
693 (when (file-exists-p nnml-nov-buffer-file-name)
694 (nnheader-insert-file-contents nnml-nov-buffer-file-name)))
695 (push (cons group buffer) nnml-nov-buffer-alist)
698 (defun nnml-save-nov ()
700 (while nnml-nov-buffer-alist
701 (when (buffer-name (cdar nnml-nov-buffer-alist))
702 (set-buffer (cdar nnml-nov-buffer-alist))
703 (when (buffer-modified-p)
704 (nnmail-write-region 1 (point-max) nnml-nov-buffer-file-name
706 (set-buffer-modified-p nil)
707 (kill-buffer (current-buffer)))
708 (setq nnml-nov-buffer-alist (cdr nnml-nov-buffer-alist)))))
711 (defun nnml-generate-nov-databases ()
712 "Generate NOV databases in all nnml directories."
714 ;; Read the active file to make sure we don't re-use articles
715 ;; numbers in empty groups.
716 (nnmail-activate 'nnml)
717 (nnml-open-server (or (nnoo-current-server 'nnml) ""))
718 (setq nnml-directory (expand-file-name nnml-directory))
719 ;; Recurse down the directories.
720 (nnml-generate-nov-databases-1 nnml-directory nil t)
721 ;; Save the active file.
722 (nnmail-save-active nnml-group-alist nnml-active-file))
724 (defun nnml-generate-nov-databases-1 (dir &optional seen no-active)
725 "Regenerate the NOV database in DIR."
726 (interactive "DRegenerate NOV in: ")
727 (setq dir (file-name-as-directory dir))
728 ;; Only scan this sub-tree if we haven't been here yet.
729 (unless (member (file-truename dir) seen)
730 (push (file-truename dir) seen)
731 ;; We descend recursively
732 (let ((dirs (directory-files dir t nil t))
734 (while (setq dir (pop dirs))
735 (when (and (not (string-match "^\\." (file-name-nondirectory dir)))
736 (file-directory-p dir))
737 (nnml-generate-nov-databases-1 dir seen))))
738 ;; Do this directory.
739 (let ((files (sort (nnheader-article-to-file-alist dir)
740 'car-less-than-car)))
742 (let* ((group (nnheader-file-to-group
743 (directory-file-name dir) nnml-directory))
744 (info (cadr (assoc group nnml-group-alist))))
746 (setcar info (1+ (cdr info)))))
747 (funcall nnml-generate-active-function dir)
748 ;; Generate the nov file.
749 (nnml-generate-nov-file dir files)
751 (nnmail-save-active nnml-group-alist nnml-active-file))))))
754 (defun nnml-generate-active-info (dir)
755 ;; Update the active info for this group.
756 (let ((group (nnheader-file-to-group
757 (directory-file-name dir) nnml-directory)))
758 (setq nnml-group-alist
759 (delq (assoc group nnml-group-alist) nnml-group-alist))
763 (while (cdr f) (setq f (cdr f)))
767 (defun nnml-generate-nov-file (dir files)
768 (let* ((dir (file-name-as-directory dir))
769 (nov (concat dir nnml-nov-file-name))
770 (nov-buffer (get-buffer-create " *nov*"))
773 ;; Init the nov buffer.
774 (set-buffer nov-buffer)
775 (buffer-disable-undo)
777 (set-buffer nntp-server-buffer)
778 ;; Delete the old NOV file.
779 (when (file-exists-p nov)
780 (funcall nnmail-delete-file-function nov))
782 (unless (file-directory-p (setq file (concat dir (cdar files))))
784 (nnheader-insert-file-contents file)
786 (goto-char (point-min))
788 (search-forward "\n\n" nil t)
789 (setq chars (- (point-max) (point)))
790 (max 1 (1- (point)))))
791 (unless (zerop (buffer-size))
792 (goto-char (point-min))
793 (setq headers (nnml-parse-head chars (caar files)))
795 (set-buffer nov-buffer)
796 (goto-char (point-max))
797 (nnheader-insert-nov headers)))
799 (setq files (cdr files)))
801 (set-buffer nov-buffer)
802 (nnmail-write-region 1 (point-max) nov nil 'nomesg)
803 (kill-buffer (current-buffer))))))
805 (defun nnml-nov-delete-article (group article)
807 (set-buffer (nnml-open-nov group))
808 (when (nnheader-find-nov-line article)
809 (delete-region (point) (progn (forward-line 1) (point)))
811 (let ((active (cadr (assoc group nnml-group-alist)))
815 (setf (car active) (1+ (cdr active)))
816 (when (and (setq num (ignore-errors (read (current-buffer))))
818 (setf (car active) num)))))))
821 (defun nnml-update-file-alist (&optional force)
822 (when (or (not nnml-article-file-alist)
824 (setq nnml-article-file-alist
825 (nnheader-article-to-file-alist nnml-current-directory))))
829 ;;; nnml.el ends here