1 ;;; nnml.el --- mail spool access for Gnus
2 ;; Copyright (C) 1995,96,97 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
5 ;; Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
6 ;; Keywords: news, mail
8 ;; This file is part of GNU Emacs.
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)
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.
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.
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
36 (eval-when-compile (require 'cl))
40 (defvoo nnml-directory message-directory
41 "Spool directory for the nnml mail backend.")
43 (defvoo nnml-active-file
44 (concat (file-name-as-directory nnml-directory) "active")
47 (defvoo nnml-newsgroups-file
48 (concat (file-name-as-directory nnml-directory) "newsgroups")
49 "Mail newsgroups description file.")
51 (defvoo nnml-get-new-mail t
52 "If non-nil, nnml will check the incoming mail file and split the mail.")
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.")
63 (defvoo nnml-prepare-save-mail-hook nil
64 "Hook run narrowed to an article before saving.")
66 (defvoo nnml-inhibit-expiry nil
67 "If non-nil, inhibit expiry.")
72 (defconst nnml-version "nnml 1.0"
75 (defvoo nnml-nov-file-name ".overview")
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)
85 (defvoo nnml-generate-active-function 'nnml-generate-active-info)
87 (defvar nnml-nov-buffer-file-name nil)
91 ;;; Interface functions.
93 (nnoo-define-basics nnml)
95 (deffoo nnml-retrieve-headers (sequence &optional group server fetch-old)
96 (when (nnml-possibly-change-directory group server)
98 (set-buffer nntp-server-buffer)
101 (number (length sequence))
103 (pathname-coding-system 'binary)
105 (if (stringp (car sequence))
107 (if (nnml-retrieve-headers-with-nov sequence fetch-old)
110 (setq article (car sequence))
111 (setq file (nnml-article-to-file article))
114 (not (file-directory-p file)))
115 (insert (format "221 %d Article retrieved.\n" article))
117 (nnheader-insert-head file)
119 (if (search-forward "\n\n" nil t)
121 (goto-char (point-max))
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)
130 (nnheader-message 6 "nnml: Receiving headers... %d%%"
131 (/ (* count 100) number))))
133 (and (numberp nnmail-large-newsgroup)
134 (> number nnmail-large-newsgroup)
135 (nnheader-message 6 "nnml: Receiving headers...done"))
137 (nnheader-fold-continuation-lines)
140 (deffoo nnml-open-server (server &optional defs)
141 (nnoo-change-server 'nnml server defs)
142 (when (not (file-exists-p nnml-directory))
144 (make-directory nnml-directory t)
147 ((not (file-exists-p nnml-directory))
149 (nnheader-report 'nnml "Couldn't create directory: %s" nnml-directory))
150 ((not (file-directory-p (file-truename nnml-directory)))
152 (nnheader-report 'nnml "Not a directory: %s" nnml-directory))
154 (nnheader-report 'nnml "Opened server %s using directory %s"
155 server nnml-directory)
158 (defun nnml-request-regenerate (server)
159 (nnml-possibly-change-directory nil server)
160 (nnml-generate-nov-databases)
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))
166 ;; 1997/8/12 by MORIOKA Tomohiko
168 (pathname-coding-system 'binary)
169 path gpath group-num)
171 (when (and (setq group-num (nnml-find-group-number id))
173 (assq (cdr group-num)
174 (nnheader-article-to-file-alist
176 (nnmail-group-pathname
179 (setq path (concat gpath (int-to-string (cdr group-num)))))
180 (setq path (nnml-article-to-file id)))
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))
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)))))))
196 (deffoo nnml-request-group (group &optional server dont-check)
197 (let ((pathname-coding-system 'binary))
199 ((not (nnml-possibly-change-directory group server))
200 (nnheader-report 'nnml "Invalid group (no such directory)"))
201 ((not (file-exists-p nnml-current-directory))
202 (nnheader-report 'nnml "Directory %s does not exist"
203 nnml-current-directory))
204 ((not (file-directory-p nnml-current-directory))
205 (nnheader-report 'nnml "%s is not a directory" nnml-current-directory))
207 (nnheader-report 'nnml "Group %s selected" group)
210 (nnheader-re-read-dir nnml-current-directory)
211 (nnmail-activate 'nnml)
212 (let ((active (nth 1 (assoc group nnml-group-alist))))
214 (nnheader-report 'nnml "No such group: %s" group)
215 (nnheader-report 'nnml "Selected group %s" group)
216 (nnheader-insert "211 %d %d %d %s\n"
217 (max (1+ (- (cdr active) (car active))) 0)
218 (car active) (cdr active) group)))))))
220 (deffoo nnml-request-scan (&optional group server)
221 (setq nnml-article-file-alist nil)
222 (nnml-possibly-change-directory group server)
223 (nnmail-get-new-mail 'nnml 'nnml-save-nov nnml-directory group))
225 (deffoo nnml-close-group (group &optional server)
226 (setq nnml-article-file-alist nil)
229 (deffoo nnml-request-create-group (group &optional server args)
230 (nnmail-activate 'nnml)
231 (unless (assoc group nnml-group-alist)
233 (push (list group (setq active (cons 1 0)))
235 (nnml-possibly-create-directory group)
236 (nnml-possibly-change-directory group server)
237 (let ((articles (nnheader-directory-articles nnml-current-directory)))
239 (setcar active (apply 'min articles))
240 (setcdr active (apply 'max articles))))
241 (nnmail-save-active nnml-group-alist nnml-active-file)))
244 (deffoo nnml-request-list (&optional server)
246 ;; 1997/8/12 by MORIOKA Tomohiko
248 (let ((nnmail-file-coding-system nnmail-active-file-coding-system)
249 (pathname-coding-system 'binary)) ; for XEmacs/mule
250 (nnmail-find-file nnml-active-file)
252 (setq nnml-group-alist (nnmail-get-active))
255 (deffoo nnml-request-newgroups (date &optional server)
256 (nnml-request-list server))
258 (deffoo nnml-request-list-newsgroups (&optional server)
260 (nnmail-find-file nnml-newsgroups-file)))
262 (deffoo nnml-request-expire-articles (articles group
263 &optional server force)
264 (nnml-possibly-change-directory group server)
265 (let ((active-articles
266 (nnheader-directory-articles nnml-current-directory))
268 article rest mod-time number)
269 (nnmail-activate 'nnml)
271 (while (and articles is-old)
272 (when (setq article (nnml-article-to-file (setq number (pop articles))))
273 (when (setq mod-time (nth 5 (file-attributes article)))
274 (if (and (nnml-deletable-article-p group number)
276 (nnmail-expired-article-p group mod-time force
277 nnml-inhibit-expiry)))
279 (nnheader-message 5 "Deleting article %s in %s"
282 (funcall nnmail-delete-file-function article)
285 (setq active-articles (delq number active-articles))
286 (nnml-nov-delete-article group number))
287 (push number rest)))))
288 (let ((active (nth 1 (assoc group nnml-group-alist))))
290 (setcar active (or (and active-articles
291 (apply 'min active-articles))
293 (nnmail-save-active nnml-group-alist nnml-active-file))
295 (nconc rest articles)))
297 (deffoo nnml-request-move-article
298 (article group server accept-form &optional last)
299 (let ((buf (get-buffer-create " *nnml move*"))
301 (nnml-possibly-change-directory group server)
302 (nnml-update-file-alist)
304 (nnml-deletable-article-p group article)
305 (nnml-request-article article group server)
308 (insert-buffer-substring nntp-server-buffer)
309 (setq result (eval accept-form))
310 (kill-buffer (current-buffer))
313 (nnml-possibly-change-directory group server)
315 (funcall nnmail-delete-file-function
316 (nnml-article-to-file article))
318 (nnml-nov-delete-article group article)
321 (nnmail-save-active nnml-group-alist nnml-active-file))))
324 (deffoo nnml-request-accept-article (group &optional server last)
325 (nnml-possibly-change-directory group server)
326 (nnmail-check-syntax)
328 (when nnmail-cache-accepted-message-ids
329 (nnmail-cache-insert (nnmail-fetch-field "message-id")))
332 (nnmail-activate 'nnml)
333 (setq result (car (nnml-save-mail
334 (list (cons group (nnml-active-number group))))))
336 (nnmail-save-active nnml-group-alist nnml-active-file)
337 (and last (nnml-save-nov))))
339 (nnmail-activate 'nnml)
340 (if (and (not (setq result (nnmail-article-group 'nnml-active-number)))
341 (yes-or-no-p "Moved to `junk' group; delete article? "))
343 (setq result (car (nnml-save-mail result))))
345 (nnmail-save-active nnml-group-alist nnml-active-file)
346 (when nnmail-cache-accepted-message-ids
347 (nnmail-cache-close))
351 (deffoo nnml-request-replace-article (article group buffer)
352 (nnml-possibly-change-directory group)
355 (nnml-possibly-create-directory group)
356 (let ((chars (nnmail-insert-lines))
357 (art (concat (int-to-string article) "\t"))
359 (when (condition-case ()
362 (point-min) (point-max)
363 (or (nnml-article-to-file article)
364 (concat nnml-current-directory
365 (int-to-string article)))
366 nil (if (nnheader-be-verbose 5) nil 'nomesg))
369 (setq headers (nnml-parse-head chars article))
370 ;; Replace the NOV line in the NOV file.
372 (set-buffer (nnml-open-nov group))
373 (goto-char (point-min))
374 (if (or (looking-at art)
375 (search-forward (concat "\n" art) nil t))
376 ;; Delete the old NOV line.
377 (delete-region (progn (beginning-of-line) (point))
378 (progn (forward-line 1) (point)))
379 ;; The line isn't here, so we have to find out where
380 ;; we should insert it. (This situation should never
381 ;; occur, but one likes to make sure...)
382 (while (and (looking-at "[0-9]+\t")
385 (match-beginning 0) (match-end 0)))
387 (zerop (forward-line 1)))))
389 (nnheader-insert-nov headers)
393 (deffoo nnml-request-delete-group (group &optional force server)
394 (nnml-possibly-change-directory group server)
396 ;; Delete all articles in GROUP.
399 nnml-current-directory t
400 (concat nnheader-numerical-short-files
401 "\\|" (regexp-quote nnml-nov-file-name) "$")))
404 (setq article (pop articles))
405 (when (file-writable-p article)
406 (nnheader-message 5 "Deleting article %s in %s..." article group)
407 (funcall nnmail-delete-file-function article))))
408 ;; Try to delete the directory itself.
410 (delete-directory nnml-current-directory)
412 ;; Remove the group from all structures.
413 (setq nnml-group-alist
414 (delq (assoc group nnml-group-alist) nnml-group-alist)
415 nnml-current-group nil
416 nnml-current-directory nil)
417 ;; Save the active file.
418 (nnmail-save-active nnml-group-alist nnml-active-file)
421 (deffoo nnml-request-rename-group (group new-name &optional server)
422 (nnml-possibly-change-directory group server)
423 (let ((new-dir (nnmail-group-pathname new-name nnml-directory))
424 (old-dir (nnmail-group-pathname group nnml-directory)))
425 (when (condition-case ()
427 (make-directory new-dir t)
430 ;; We move the articles file by file instead of renaming
431 ;; the directory -- there may be subgroups in this group.
432 ;; One might be more clever, I guess.
433 (let ((files (nnheader-article-to-file-alist old-dir)))
436 (concat old-dir (cdar files))
437 (concat new-dir (cdar files)))
439 ;; Move .overview file.
440 (let ((overview (concat old-dir nnml-nov-file-name)))
441 (when (file-exists-p overview)
442 (rename-file overview (concat new-dir nnml-nov-file-name))))
443 (when (<= (length (directory-files old-dir)) 2)
445 (delete-directory old-dir)
447 ;; That went ok, so we change the internal structures.
448 (let ((entry (assoc group nnml-group-alist)))
450 (setcar entry new-name))
451 (setq nnml-current-directory nil
452 nnml-current-group nil)
453 ;; Save the new group alist.
454 (nnmail-save-active nnml-group-alist nnml-active-file)
457 (deffoo nnml-set-status (article name value &optional group server)
458 (nnml-possibly-change-directory group server)
459 (let ((file (nnml-article-to-file article)))
461 ((not (file-exists-p file))
462 (nnheader-report 'nnml "File %s does not exist" file))
464 (nnheader-temp-write file
465 (nnheader-insert-file-contents file)
466 (nnmail-replace-status name value))
470 ;;; Internal functions.
472 (defun nnml-article-to-file (article)
473 (nnml-update-file-alist)
475 (if (setq file (cdr (assq article nnml-article-file-alist)))
476 (concat nnml-current-directory file)
477 ;; Just to make sure nothing went wrong when reading over NFS --
480 (setq file (concat nnml-current-directory "/"
481 (number-to-string article))))
482 (nnml-update-file-alist t)
485 (defun nnml-deletable-article-p (group article)
486 "Say whether ARTICLE in GROUP can be deleted."
488 (when (setq path (nnml-article-to-file article))
489 (when (file-writable-p path)
490 (or (not nnmail-keep-last-article)
491 (not (eq (cdr (nth 1 (assoc group nnml-group-alist)))
494 ;; Find an article number in the current group given the Message-ID.
495 (defun nnml-find-group-number (id)
497 (set-buffer (get-buffer-create " *nnml id*"))
498 (buffer-disable-undo (current-buffer))
499 (let ((alist nnml-group-alist)
501 ;; We want to look through all .overview files, but we want to
502 ;; start with the one in the current directory. It seems most
503 ;; likely that the article we are looking for is in that group.
504 (if (setq number (nnml-find-id nnml-current-group id))
505 (cons nnml-current-group number)
506 ;; It wasn't there, so we look through the other groups as well.
507 (while (and (not number)
509 (or (string= (caar alist) nnml-current-group)
510 (setq number (nnml-find-id (caar alist) id)))
512 (setq alist (cdr alist))))
514 (cons (caar alist) number))))))
516 (defun nnml-find-id (group id)
518 (let ((nov (concat (nnmail-group-pathname group nnml-directory)
521 (when (file-exists-p nov)
522 (nnheader-insert-file-contents nov)
523 (while (and (not found)
524 (search-forward id nil t)) ; We find the ID.
525 ;; And the id is in the fourth field.
526 (if (not (and (search-backward "\t" nil t 4)
527 (not (search-backward"\t" (gnus-point-at-bol) t))))
531 ;; We return the article number.
534 (read (current-buffer))
538 (defun nnml-retrieve-headers-with-nov (articles &optional fetch-old)
539 (if (or gnus-nov-is-evil nnml-nov-is-evil)
541 (let ((nov (concat nnml-current-directory nnml-nov-file-name)))
542 (when (file-exists-p nov)
544 (set-buffer nntp-server-buffer)
546 (nnheader-insert-file-contents nov)
548 (not (numberp fetch-old)))
549 t ; Don't remove anything.
550 (nnheader-nov-delete-outside-range
551 (if fetch-old (max 1 (- (car articles) fetch-old))
553 (car (last articles)))
556 (defun nnml-possibly-change-directory (group &optional server)
558 (not (nnml-server-opened server)))
559 (nnml-open-server server))
562 (let ((pathname (nnmail-group-pathname group nnml-directory))
563 (pathname-coding-system 'binary))
564 (when (not (equal pathname nnml-current-directory))
565 (setq nnml-current-directory pathname
566 nnml-current-group group
567 nnml-article-file-alist nil))
568 (file-exists-p nnml-current-directory))))
570 (defun nnml-possibly-create-directory (group)
572 (setq dir (nnmail-group-pathname group nnml-directory))
573 (while (not (file-directory-p dir))
575 (setq dir (file-name-directory (directory-file-name dir))))
577 (make-directory (directory-file-name (car dirs)))
578 (nnheader-message 5 "Creating mail directory %s" (car dirs))
579 (setq dirs (cdr dirs)))))
581 (defun nnml-save-mail (group-art)
582 "Called narrowed to an article."
584 (setq chars (nnmail-insert-lines))
585 (nnmail-insert-xref group-art)
586 (run-hooks 'nnmail-prepare-save-mail-hook)
587 (run-hooks 'nnml-prepare-save-mail-hook)
588 (goto-char (point-min))
589 (while (looking-at "From ")
590 (replace-match "X-From-Line: ")
592 ;; We save the article in all the groups it belongs in.
596 (nnml-possibly-create-directory (caar ga))
597 (let ((file (concat (nnmail-group-pathname
598 (caar ga) nnml-directory)
599 (int-to-string (cdar ga)))))
601 ;; It was already saved, so we just make a hard link.
602 (funcall nnmail-crosspost-link-function first file t)
604 (nnmail-write-region (point-min) (point-max) file nil
605 (if (nnheader-be-verbose 5) nil 'nomesg))
608 ;; Generate a nov line for this article. We generate the nov
609 ;; line after saving, because nov generation destroys the
611 (setq headers (nnml-parse-head chars))
612 ;; Output the nov line to all nov databases that should have it.
613 (let ((ga group-art))
615 (nnml-add-nov (caar ga) (cdar ga) headers)
619 (defun nnml-active-number (group)
620 "Compute the next article number in GROUP."
621 (let ((active (cadr (assoc group nnml-group-alist))))
622 ;; The group wasn't known to nnml, so we just create an active
625 ;; Perhaps the active file was corrupt? See whether
626 ;; there are any articles in this group.
627 (nnml-possibly-create-directory group)
628 (nnml-possibly-change-directory group)
629 (unless nnml-article-file-alist
630 (setq nnml-article-file-alist
632 (nnheader-article-to-file-alist nnml-current-directory)
633 'car-less-than-car)))
635 (if nnml-article-file-alist
636 (cons (caar nnml-article-file-alist)
637 (caar (last nnml-article-file-alist)))
639 (push (list group active) nnml-group-alist))
640 (setcdr active (1+ (cdr active)))
641 (while (file-exists-p
642 (concat (nnmail-group-pathname group nnml-directory)
643 (int-to-string (cdr active))))
644 (setcdr active (1+ (cdr active))))
647 (defun nnml-add-nov (group article headers)
648 "Add a nov line for the GROUP base."
650 (set-buffer (nnml-open-nov group))
651 (goto-char (point-max))
652 (mail-header-set-number headers article)
653 (nnheader-insert-nov headers)))
655 (defsubst nnml-header-value ()
656 (buffer-substring (match-end 0) (progn (end-of-line) (point))))
658 (defun nnml-parse-head (chars &optional number)
659 "Parse the head of the current buffer."
662 (goto-char (point-min))
663 (unless (zerop (buffer-size))
666 (1- (or (search-forward "\n\n" nil t) (point-max)))))
667 ;; Fold continuation lines.
668 (goto-char (point-min))
669 (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t)
670 (replace-match " " t t))
671 ;; Remove any tabs; they are too confusing.
672 (subst-char-in-region (point-min) (point-max) ?\t ? )
673 (let ((headers (nnheader-parse-head t)))
674 (mail-header-set-chars headers chars)
675 (mail-header-set-number headers number)
678 (defun nnml-open-nov (group)
679 (or (cdr (assoc group nnml-nov-buffer-alist))
680 (let ((buffer (get-buffer-create (format " *nnml overview %s*" group))))
683 (set (make-local-variable 'nnml-nov-buffer-file-name)
684 (concat (nnmail-group-pathname group nnml-directory)
687 (when (file-exists-p nnml-nov-buffer-file-name)
688 (nnheader-insert-file-contents nnml-nov-buffer-file-name)))
689 (push (cons group buffer) nnml-nov-buffer-alist)
692 (defun nnml-save-nov ()
694 (while nnml-nov-buffer-alist
695 (when (buffer-name (cdar nnml-nov-buffer-alist))
696 (set-buffer (cdar nnml-nov-buffer-alist))
697 (when (buffer-modified-p)
698 (nnmail-write-region 1 (point-max) nnml-nov-buffer-file-name
700 (set-buffer-modified-p nil)
701 (kill-buffer (current-buffer)))
702 (setq nnml-nov-buffer-alist (cdr nnml-nov-buffer-alist)))))
705 (defun nnml-generate-nov-databases ()
706 "Generate NOV databases in all nnml directories."
708 ;; Read the active file to make sure we don't re-use articles
709 ;; numbers in empty groups.
710 (nnmail-activate 'nnml)
711 (nnml-open-server (or (nnoo-current-server 'nnml) ""))
712 (setq nnml-directory (expand-file-name nnml-directory))
713 ;; Recurse down the directories.
714 (nnml-generate-nov-databases-1 nnml-directory nil t)
715 ;; Save the active file.
716 (nnmail-save-active nnml-group-alist nnml-active-file))
718 (defun nnml-generate-nov-databases-1 (dir &optional seen no-active)
719 "Regenerate the NOV database in DIR."
720 (interactive "DRegenerate NOV in: ")
721 (setq dir (file-name-as-directory dir))
722 ;; Only scan this sub-tree if we haven't been here yet.
723 (unless (member (file-truename dir) seen)
724 (push (file-truename dir) seen)
725 ;; We descend recursively
726 (let ((dirs (directory-files dir t nil t))
728 (while (setq dir (pop dirs))
729 (when (and (not (member (file-name-nondirectory dir) '("." "..")))
730 (file-directory-p dir))
731 (nnml-generate-nov-databases-1 dir seen))))
732 ;; Do this directory.
733 (let ((files (sort (nnheader-article-to-file-alist dir)
734 'car-less-than-car)))
736 (funcall nnml-generate-active-function dir)
737 ;; Generate the nov file.
738 (nnml-generate-nov-file dir files)
740 (nnmail-save-active nnml-group-alist nnml-active-file))))))
743 (defun nnml-generate-active-info (dir)
744 ;; Update the active info for this group.
745 (let ((group (nnheader-file-to-group
746 (directory-file-name dir) nnml-directory)))
747 (setq nnml-group-alist
748 (delq (assoc group nnml-group-alist) nnml-group-alist))
752 (while (cdr f) (setq f (cdr f)))
756 (defun nnml-generate-nov-file (dir files)
757 (let* ((dir (file-name-as-directory dir))
758 (nov (concat dir nnml-nov-file-name))
759 (nov-buffer (get-buffer-create " *nov*"))
762 ;; Init the nov buffer.
763 (set-buffer nov-buffer)
764 (buffer-disable-undo (current-buffer))
766 (set-buffer nntp-server-buffer)
767 ;; Delete the old NOV file.
768 (when (file-exists-p nov)
769 (funcall nnmail-delete-file-function nov))
771 (unless (file-directory-p (setq file (concat dir (cdar files))))
773 (nnheader-insert-file-contents file)
775 (goto-char (point-min))
777 (search-forward "\n\n" nil t)
778 (setq chars (- (point-max) (point)))
779 (max 1 (1- (point)))))
780 (unless (zerop (buffer-size))
781 (goto-char (point-min))
782 (setq headers (nnml-parse-head chars (caar files)))
784 (set-buffer nov-buffer)
785 (goto-char (point-max))
786 (nnheader-insert-nov headers)))
788 (setq files (cdr files)))
790 (set-buffer nov-buffer)
791 (nnmail-write-region 1 (point-max) nov nil 'nomesg)
792 (kill-buffer (current-buffer))))))
794 (defun nnml-nov-delete-article (group article)
796 (set-buffer (nnml-open-nov group))
797 (when (nnheader-find-nov-line article)
798 (delete-region (point) (progn (forward-line 1) (point)))
800 (let ((active (cadr (assoc group nnml-group-alist)))
804 (setf (car active) (1+ (cdr active)))
805 (when (and (setq num (ignore-errors (read (current-buffer))))
807 (setf (car active) num)))))))
810 (defun nnml-update-file-alist (&optional force)
811 (when (or (not nnml-article-file-alist)
813 (setq nnml-article-file-alist
814 (nnheader-article-to-file-alist nnml-current-directory))))
818 ;;; nnml.el ends here