*** empty log message ***
[gnus] / lisp / nnml.el
1 ;;; nnml.el --- mail spool access for Gnus
2 ;; Copyright (C) 1995 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
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23
24 ;;; Commentary:
25
26 ;; Based on nnspool.el by Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>.
27 ;; For an overview of what the interface functions do, please see the
28 ;; Gnus sources.  
29
30 ;;; Code:
31
32 (require 'nnheader)
33 (require 'nnmail)
34
35 (defvar nnml-directory "~/Mail/"
36   "Mail spool directory.")
37
38 (defvar nnml-active-file (concat nnml-directory "active")
39   "Mail active file.")
40
41 (defvar nnml-newsgroups-file (concat nnml-directory "newsgroups")
42   "Mail newsgroups description file.")
43
44 (defvar nnml-get-new-mail t
45   "If non-nil, nnml will check the incoming mail file and split the mail.")
46
47 (defvar nnml-nov-is-evil nil
48   "If non-nil, Gnus will never generate and use nov databases for mail groups.
49 Using nov databases will speed up header fetching considerably.
50 This variable shouldn't be flipped much. If you have, for some reason,
51 set this to t, and want to set it to nil again, you should always run
52 the `nnml-generate-nov-databases' command. The function will go
53 through all nnml directories and generate nov databases for them
54 all. This may very well take some time.")
55
56 (defvar nnml-prepare-save-mail-hook nil
57   "Hook run narrowed to an article before saving.")
58
59 \f
60
61 (defconst nnml-version "nnml 0.2"
62   "nnml version.")
63
64 (defvar nnml-nov-file-name ".overview")
65
66 (defvar nnml-current-directory nil)
67 (defvar nnml-status-string "")
68 (defvar nnml-nov-buffer-alist nil)
69 (defvar nnml-group-alist nil)
70 (defvar nnml-active-timestamp nil)
71
72 \f
73
74 ;; Server variables.
75
76 (defvar nnml-current-server nil)
77 (defvar nnml-server-alist nil)
78 (defvar nnml-server-variables 
79   (list 
80    (list 'nnml-directory nnml-directory)
81    (list 'nnml-active-file nnml-active-file)
82    (list 'nnml-newsgroups-file nnml-newsgroups-file)
83    (list 'nnml-get-new-mail nnml-get-new-mail)
84    (list 'nnml-nov-is-evil nnml-nov-is-evil)
85    (list 'nnml-nov-file-name nnml-nov-file-name)
86    '(nnml-current-directory nil)
87    '(nnml-status-string "")
88    '(nnml-nov-buffer-alist nil)
89    '(nnml-group-alist nil)
90    '(nnml-active-timestamp nil)))
91
92 \f
93
94 ;;; Interface functions.
95
96 (defun nnml-retrieve-headers (sequence &optional newsgroup server)
97   (save-excursion
98     (set-buffer nntp-server-buffer)
99     (erase-buffer)
100     (let ((file nil)
101           (number (length sequence))
102           (count 0)
103           beg article)
104       (if (stringp (car sequence))
105           'headers
106         (nnml-possibly-change-directory newsgroup)
107         (if (nnml-retrieve-headers-with-nov sequence)
108             'nov
109           (while sequence
110             (setq article (car sequence))
111             (setq file
112                   (concat nnml-current-directory (int-to-string article)))
113             (if (and (file-exists-p file)
114                      (not (file-directory-p file)))
115                 (progn
116                   (insert (format "221 %d Article retrieved.\n" article))
117                   (setq beg (point))
118                   (nnheader-insert-head file)
119                   (goto-char beg)
120                   (if (search-forward "\n\n" nil t)
121                       (forward-char -1)
122                     (goto-char (point-max))
123                     (insert "\n\n"))
124                   (insert ".\n")
125                   (delete-region (point) (point-max))))
126             (setq sequence (cdr sequence))
127             (setq count (1+ count))
128             (and (numberp nnmail-large-newsgroup)
129                  (> number nnmail-large-newsgroup)
130                  (zerop (% count 20))
131                  gnus-verbose-backends
132                  (message "nnml: Receiving headers... %d%%"
133                           (/ (* count 100) number))))
134
135           (and (numberp nnmail-large-newsgroup)
136                (> number nnmail-large-newsgroup)
137                gnus-verbose-backends
138                (message "nnml: Receiving headers...done"))
139
140           ;; Fold continuation lines.
141           (goto-char (point-min))
142           (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t)
143             (replace-match " " t t))
144           'headers)))))
145
146 (defun nnml-open-server (server &optional defs)
147   (nnheader-init-server-buffer)
148   (if (equal server nnml-current-server)
149       t
150     (if nnml-current-server
151         (setq nnml-server-alist 
152               (cons (list nnml-current-server
153                           (nnheader-save-variables nnml-server-variables))
154                     nnml-server-alist)))
155     (let ((state (assoc server nnml-server-alist)))
156       (if state 
157           (progn
158             (nnheader-restore-variables (nth 1 state))
159             (setq nnml-server-alist (delq state nnml-server-alist)))
160         (nnheader-set-init-variables nnml-server-variables defs)))
161     (setq nnml-current-server server)))
162
163 (defun nnml-close-server (&optional server)
164   t)
165
166 (defun nnml-server-opened (&optional server)
167   (and (equal server nnml-current-server)
168        nntp-server-buffer
169        (buffer-name nntp-server-buffer)))
170
171 (defun nnml-status-message (&optional server)
172   nnml-status-string)
173
174 (defun nnml-request-article (id &optional newsgroup server buffer)
175   (nnml-possibly-change-directory newsgroup)
176   (let ((file (if (stringp id)
177                   nil
178                 (concat nnml-current-directory (int-to-string id))))
179         (nntp-server-buffer (or buffer nntp-server-buffer)))
180     (if (and (stringp file)
181              (file-exists-p file)
182              (not (file-directory-p file)))
183         (save-excursion
184           (nnmail-find-file file)))))
185
186 (defun nnml-request-group (group &optional server dont-check)
187   (if (not (nnml-possibly-change-directory group))
188       (progn
189         (setq nnml-status-string "Invalid group (no such directory)")
190         nil)
191     (if dont-check 
192         t
193       (nnml-get-new-mail group)
194       (let ((timestamp (nth 5 (file-attributes nnml-active-file))))
195         (if (or (not nnml-active-timestamp)
196                 (> (nth 0 timestamp) (nth 0 nnml-active-timestamp))
197                 (> (nth 1 timestamp) (nth 1 nnml-active-timestamp)))
198             (progn
199               (setq nnml-active-timestamp timestamp)
200               (nnml-request-list)
201               (setq nnml-group-alist (nnmail-get-active))))
202         (let ((active (nth 1 (assoc group nnml-group-alist))))
203           (save-excursion
204             (set-buffer nntp-server-buffer)
205             (erase-buffer)
206             (if (not active)
207                 ()
208               (insert (format "211 %d %d %d %s\n" 
209                               (max (1+ (- (cdr active) (car active))) 0)
210                               (car active) (cdr active) group))
211               t)))))))
212
213 (defun nnml-close-group (group &optional server)
214   t)
215
216 (defun nnml-request-close ()
217   (setq nnml-current-server nil)
218   (setq nnml-server-alist nil)
219   t)
220
221 (defun nnml-request-create-group (group &optional server) 
222   (nnml-request-list)
223   (setq nnml-group-alist (nnmail-get-active))
224   (or (assoc group nnml-group-alist)
225       (let (active)
226         (setq nnml-group-alist (cons (list group (setq active (cons 0 0)))
227                                      nnml-group-alist))
228         (nnml-possibly-create-directory group)
229         (nnml-possibly-change-directory group)
230         (let ((articles (mapcar
231                          (lambda (file)
232                            (string-to-int file))
233                          (directory-files 
234                           nnml-current-directory nil "^[0-9]+$"))))
235           (and articles
236                (progn
237                  (setcar active (apply 'min articles))
238                  (setcdr active (apply 'max articles)))))
239         (nnmail-save-active nnml-group-alist nnml-active-file)))
240   t)
241
242 (defun nnml-request-list (&optional server)
243   (if server (nnml-get-new-mail))
244   (save-excursion
245     (nnmail-find-file nnml-active-file)
246     (setq nnml-group-alist (nnmail-get-active))))
247
248 (defun nnml-request-newgroups (date &optional server)
249   (nnml-request-list server))
250
251 (defun nnml-request-list-newsgroups (&optional server)
252   (save-excursion
253     (nnmail-find-file nnml-newsgroups-file)))
254
255 (defun nnml-request-post (&optional server)
256   (mail-send-and-exit nil))
257
258 (defalias 'nnml-request-post-buffer 'nnmail-request-post-buffer)
259
260 (defun nnml-request-expire-articles (articles newsgroup &optional server force)
261   (nnml-possibly-change-directory newsgroup)
262   (let* ((days (or (and nnmail-expiry-wait-function
263                         (funcall nnmail-expiry-wait-function newsgroup))
264                    nnmail-expiry-wait))
265          (active-articles 
266           (mapcar
267            (function
268             (lambda (name)
269               (string-to-int name)))
270            (directory-files nnml-current-directory nil "^[0-9]+$" t)))
271          (max-article (and active-articles (apply 'max active-articles)))
272          (is-old t)
273          article rest mod-time)
274     (while (and articles is-old)
275       (setq article (concat nnml-current-directory 
276                             (int-to-string (car articles))))
277       (if (setq mod-time (nth 5 (file-attributes article)))
278           (if (and (or (not nnmail-keep-last-article)
279                        (not max-article)
280                        (not (= (car articles) max-article)))
281                    (not (equal mod-time '(0 0)))
282                    (or force
283                        (setq is-old
284                              (> (nnmail-days-between
285                                  (current-time-string)
286                                  (current-time-string mod-time))
287                                 days))))
288               (progn
289                 (and gnus-verbose-backends (message "Deleting %s..." article))
290                 (condition-case ()
291                     (delete-file article)
292                   (file-error
293                    (setq rest (cons (car articles) rest))))
294                 (setq active-articles (delq (car articles) active-articles))
295                 (nnml-nov-delete-article newsgroup (car articles)))
296             (setq rest (cons (car articles) rest))))
297       (setq articles (cdr articles)))
298     (let ((active (nth 1 (assoc newsgroup nnml-group-alist))))
299       (and active
300            (setcar active (or (and active-articles
301                                    (apply 'min active-articles))
302                               0)))
303       (nnmail-save-active nnml-group-alist nnml-active-file))
304     (nnml-save-nov)
305     (message "")
306     (nconc rest articles)))
307
308 (defun nnml-request-move-article 
309   (article group server accept-form &optional last)
310   (let ((buf (get-buffer-create " *nnml move*"))
311         result)
312     (and 
313      (nnml-request-article article group server)
314      (save-excursion
315        (set-buffer buf)
316        (insert-buffer-substring nntp-server-buffer)
317        (setq result (eval accept-form))
318        (kill-buffer (current-buffer))
319        result)
320      (progn
321        (condition-case ()
322            (delete-file (concat nnml-current-directory 
323                                 (int-to-string article)))
324          (file-error nil))
325        (nnml-nov-delete-article group article)
326        (and last (nnml-save-nov))))
327     result))
328
329 (defun nnml-request-accept-article (group &optional last)
330   (let (result)
331     (if (stringp group)
332         (and 
333          (nnml-request-list)
334          (setq nnml-group-alist (nnmail-get-active))
335          ;; We trick the choosing function into believing that only one
336          ;; group is availiable.  
337          (let ((nnmail-split-methods (list (list group ""))))
338            (setq result (car (nnml-save-mail))))
339          (progn
340            (nnmail-save-active nnml-group-alist nnml-active-file)
341            (and last (nnml-save-nov))))
342       (and
343        (nnml-request-list)
344        (setq nnml-group-alist (nnmail-get-active))
345        (setq result (car (nnml-save-mail)))
346        (progn
347          (nnmail-save-active nnml-group-alist nnml-active-file)
348          (and last (nnml-save-nov)))))
349     result))
350
351 (defun nnml-request-replace-article (article group buffer)
352   (nnml-possibly-change-directory group)
353   (save-excursion
354     (set-buffer buffer)
355     (nnml-possibly-create-directory group)
356     (if (not (condition-case ()
357                  (progn
358                    (write-region (point-min) (point-max)
359                                  (concat nnml-current-directory 
360                                          (int-to-string article))
361                                  nil (if gnus-verbose-backends nil 'nomesg))
362                    t)
363                (error nil)))
364         ()
365       (let ((chars (nnmail-insert-lines))
366             (art (concat (int-to-string article) "\t"))
367             nov-line)
368         (setq nov-line (nnml-make-nov-line chars))
369         (save-excursion 
370           (set-buffer (nnml-open-nov group))
371           (goto-char (point-min))
372           (if (or (looking-at art)
373                   (search-forward (concat "\n" art)))
374               (progn
375                 (delete-region (progn (beginning-of-line) (point))
376                                (progn (forward-line 1) (point)))
377                 (insert (int-to-string article) nov-line)
378                 (nnml-save-nov))
379             (kill-buffer (current-buffer)))
380           t)))))
381
382
383 \f
384 ;;; Internal functions
385
386 (defun nnml-retrieve-headers-with-nov (articles)
387   (if (or gnus-nov-is-evil nnml-nov-is-evil)
388       nil
389     (let ((first (car articles))
390           (last (progn (while (cdr articles) (setq articles (cdr articles)))
391                        (car articles)))
392           (nov (concat nnml-current-directory nnml-nov-file-name)))
393       (if (file-exists-p nov)
394           (save-excursion
395             (set-buffer nntp-server-buffer)
396             (erase-buffer)
397             (insert-file-contents nov)
398             (goto-char (point-min))
399             (while (and (not (eobp)) (< first (read (current-buffer))))
400               (forward-line 1))
401             (beginning-of-line)
402             (if (not (eobp)) (delete-region 1 (point)))
403             (while (and (not (eobp)) (>= last (read (current-buffer))))
404               (forward-line 1))
405             (beginning-of-line)
406             (if (not (eobp)) (delete-region (point) (point-max)))
407             t)))))
408
409 (defun nnml-possibly-change-directory (newsgroup &optional force)
410   (if newsgroup
411       (let ((pathname (nnmail-article-pathname newsgroup nnml-directory)))
412         (and (or force (file-directory-p pathname))
413              (setq nnml-current-directory pathname)))
414     t))
415
416 (defun nnml-possibly-create-directory (group)
417   (let (dir dirs)
418     (setq dir (nnmail-article-pathname group nnml-directory))
419     (while (not (file-directory-p dir))
420       (setq dirs (cons dir dirs))
421       (setq dir (file-name-directory (directory-file-name dir))))
422     (while dirs
423       (if (make-directory (directory-file-name (car dirs)))
424           (error "Could not create directory %s" (car dirs)))
425       (and gnus-verbose-backends 
426            (message "Creating mail directory %s" (car dirs)))
427       (setq dirs (cdr dirs)))))
428              
429 (defun nnml-save-mail ()
430   "Called narrowed to an article."
431   (let ((group-art (nreverse (nnmail-article-group 'nnml-active-number)))
432         chars nov-line)
433     (setq chars (nnmail-insert-lines))
434     (nnmail-insert-xref group-art)
435     (run-hooks 'nnml-prepare-save-mail-hook)
436     (goto-char (point-min))
437     (while (looking-at "From ")
438       (replace-match "X-From-Line: ")
439       (forward-line 1))
440     ;; We save the article in all the newsgroups it belongs in.
441     (let ((ga group-art)
442           first)
443       (while ga
444         (nnml-possibly-create-directory (car (car ga)))
445         (let ((file (concat (nnmail-article-pathname 
446                              (car (car ga)) nnml-directory)
447                             (int-to-string (cdr (car ga))))))
448           (if first
449               ;; It was already saved, so we just make a hard link.
450               (add-name-to-file first file t)
451             ;; Save the article.
452             (write-region (point-min) (point-max) file nil 
453                           (if gnus-verbose-backends nil 'nomesg))
454             (setq first file)))
455         (setq ga (cdr ga))))
456     ;; Generate a nov line for this article. We generate the nov
457     ;; line after saving, because nov generation destroys the
458     ;; header. 
459     (setq nov-line (nnml-make-nov-line chars))
460     ;; Output the nov line to all nov databases that should have it.
461     (let ((ga group-art))
462       (while ga
463         (nnml-add-nov (car (car ga)) (cdr (car ga)) nov-line)
464         (setq ga (cdr ga))))
465     group-art))
466
467 (defun nnml-active-number (group)
468   "Compute the next article number in GROUP."
469   (let ((active (car (cdr (assoc group nnml-group-alist)))))
470     (or active
471         (progn
472           (setq active (cons 1 0))
473           (setq nnml-group-alist (cons (list group active) nnml-group-alist))))
474     (setcdr active (1+ (cdr active)))
475     (while (file-exists-p
476             (concat (nnmail-article-pathname group nnml-directory)
477                     (int-to-string (cdr active))))
478       (setcdr active (1+ (cdr active))))
479     (cdr active)))
480
481 (defun nnml-get-new-mail (&optional group)
482   "Read new incoming mail."
483   (let* ((spools (nnmail-get-spool-files group))
484          (group-in group)
485          incoming incomings)
486     (if (or (not nnml-get-new-mail) (not nnmail-spool-file))
487         ()
488       ;; We first activate all the groups.
489       (if (or (not group) (not nnml-group-alist))
490           (progn
491             (nnml-request-list)
492             (setq nnml-group-alist (nnmail-get-active))))
493       ;; The we go through all the existing spool files and split the
494       ;; mail from each.
495       (while spools
496         (and
497          (file-exists-p (car spools))
498          (> (nth 7 (file-attributes (car spools))) 0)
499          (progn
500            (and gnus-verbose-backends 
501                 (message "nnml: Reading incoming mail..."))
502            (setq incoming 
503                  (nnmail-move-inbox 
504                   (car spools) (concat nnml-directory "Incoming")))
505            (setq group (nnmail-get-split-group (car spools) group-in))
506            (nnmail-split-incoming incoming 'nnml-save-mail nil group)
507            (setq incomings (cons incoming incomings))))
508         (setq spools (cdr spools)))
509       ;; If we did indeed read any incoming spools, we save all info. 
510       (if incoming 
511           (progn
512             (nnmail-save-active nnml-group-alist nnml-active-file)
513             (nnml-save-nov)
514             (run-hooks 'nnmail-read-incoming-hook)
515             (and gnus-verbose-backends
516                  (message "nnml: Reading incoming mail...done"))))
517       (while incomings
518         (and nnmail-delete-incoming
519              (file-writable-p incoming)
520              (delete-file incoming))
521         (setq incomings (cdr incomings))))))
522
523
524 (defun nnml-add-nov (group article line)
525   "Add a nov line for the GROUP base."
526   (save-excursion 
527     (set-buffer (nnml-open-nov group))
528     (goto-char (point-max))
529     (insert (int-to-string article) line)))
530
531 (defsubst nnml-header-value ()
532   (buffer-substring (match-end 0) (save-excursion (end-of-line) (point))))
533
534 (defun nnml-make-nov-line (chars)
535   "Create a nov from the current headers."
536   (let ((case-fold-search t)
537         subject from date id references lines xref in-reply-to char)
538     (save-excursion
539       (save-restriction
540         (goto-char (point-min))
541         (narrow-to-region 
542          (point)
543          (1- (or (search-forward "\n\n" nil t) (point-max))))
544         ;; Fold continuation lines.
545         (goto-char (point-min))
546         (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t)
547           (replace-match " " t t))
548         (subst-char-in-region (point-min) (point-max) ?\t ? )
549         ;; [number subject from date id references chars lines xref]
550         (save-excursion
551           (goto-char (point-min))
552           (while (re-search-forward "^\\(from\\|subject\\|message-id\\|date\\|lines\\|xref\\|references\\|in-reply-to\\): "
553                                     nil t)
554             (beginning-of-line)
555             (setq char (downcase (following-char))) 
556             (cond
557              ((eq char ?s)
558               (setq subject (nnml-header-value)))
559              ((eq char ?f)
560               (setq from (nnml-header-value)))
561              ((eq char ?x)
562               (setq xref (nnml-header-value)))
563              ((eq char ?l)
564               (setq lines (nnml-header-value)))
565              ((eq char ?d)
566               (setq date (nnml-header-value)))
567              ((eq char ?m)
568               (setq id (setq id (nnml-header-value))))
569              ((eq char ?r)
570               (setq references (nnml-header-value)))
571              ((eq char ?i)
572               (setq in-reply-to (nnml-header-value))))
573             (forward-line 1))
574       
575           (and (not references)
576                in-reply-to
577                (string-match "<[^>]+>" in-reply-to)
578                (setq references
579                      (substring in-reply-to (match-beginning 0)
580                                 (match-end 0)))))
581         ;; [number subject from date id references chars lines xref]
582         (format "\t%s\t%s\t%s\t%s\t%s\t%d\t%s\t%s\t\n"
583                 (or subject "(none)")
584                 (or from "(nobody)") (or date "")
585                 (or id (concat "nnml-dummy-id-" 
586                                (mapconcat 
587                                 (lambda (time) (int-to-string time))
588                                 (current-time) "-")))
589                 (or references "")
590                 (or chars 0) (or lines "0") (or xref ""))))))
591
592 (defun nnml-open-nov (group)
593   (or (cdr (assoc group nnml-nov-buffer-alist))
594       (let ((buffer (find-file-noselect 
595                      (concat (nnmail-article-pathname 
596                               group nnml-directory) nnml-nov-file-name))))
597         (save-excursion
598           (set-buffer buffer)
599           (buffer-disable-undo (current-buffer)))
600         (setq nnml-nov-buffer-alist 
601               (cons (cons group buffer) nnml-nov-buffer-alist))
602         buffer)))
603
604 (defun nnml-save-nov ()
605   (save-excursion
606     (while nnml-nov-buffer-alist
607       (if (buffer-name (cdr (car nnml-nov-buffer-alist)))
608           (progn
609             (set-buffer (cdr (car nnml-nov-buffer-alist)))
610             (and (buffer-modified-p)
611                  (write-region 
612                   1 (point-max) (buffer-file-name) nil 'nomesg))
613             (set-buffer-modified-p nil)
614             (kill-buffer (current-buffer))))
615       (setq nnml-nov-buffer-alist (cdr nnml-nov-buffer-alist)))))
616
617 ;;;###autoload
618 (defun nnml-generate-nov-databases (dir)
619   "Generate nov databases in all nnml mail newsgroups."
620   (interactive 
621    (progn   
622      (setq nnml-group-alist nil)
623      (list nnml-directory)))
624   (nnml-open-server (or nnml-current-server ""))
625   (let ((dirs (directory-files dir t nil t)))
626     (while dirs 
627       (if (and (not (string-match "/\\.\\.$" (car dirs)))
628                (not (string-match "/\\.$" (car dirs)))
629                (file-directory-p (car dirs)))
630           (nnml-generate-nov-databases (car dirs)))
631       (setq dirs (cdr dirs))))
632   (let ((files (sort
633                 (mapcar
634                  (function
635                   (lambda (name)
636                     (string-to-int name)))
637                  (directory-files dir nil "^[0-9]+$" t))
638                 (function <)))
639         (nov (concat dir "/" nnml-nov-file-name))
640         (nov-buffer (get-buffer-create "*nov*"))
641         nov-line chars)
642     (if files
643         (setq nnml-group-alist 
644               (cons (list (nnmail-replace-chars-in-string 
645                            (substring (expand-file-name dir)
646                                       (length (expand-file-name 
647                                                nnml-directory)))
648                            ?/ ?.)
649                           (cons (car files)
650                                 (let ((f files))
651                                   (while (cdr f) (setq f (cdr f)))
652                                   (car f))))
653                     nnml-group-alist)))
654     (if files
655         (save-excursion
656           (set-buffer nntp-server-buffer)
657           (if (file-exists-p nov)
658               (delete-file nov))
659           (save-excursion
660             (set-buffer nov-buffer)
661             (buffer-disable-undo (current-buffer))
662             (erase-buffer))
663           (while files
664             (erase-buffer)
665             (insert-file-contents (concat dir "/" (int-to-string (car files))))
666             (goto-char (point-min))
667             (narrow-to-region 1 (save-excursion (search-forward "\n\n" nil t)
668                                                 (setq chars (- (point-max) 
669                                                                (point)))
670                                                 (point)))
671             (if (not (= 0 chars)) ; none of them empty files...
672                 (progn
673                   (setq nov-line (nnml-make-nov-line chars))
674                   (save-excursion
675                     (set-buffer nov-buffer)
676                     (goto-char (point-max))
677                     (insert (int-to-string (car files)) nov-line))))
678             (widen)
679             (setq files (cdr files)))
680           (save-excursion
681             (set-buffer nov-buffer)
682             (write-region 1 (point-max) (expand-file-name nov) nil
683                           'nomesg)
684             (kill-buffer (current-buffer)))))
685     (nnmail-save-active nnml-group-alist nnml-active-file)))
686
687 (defun nnml-nov-delete-article (group article)
688   (save-excursion
689     (set-buffer (nnml-open-nov group))
690     (goto-char (point-min))
691     (if (re-search-forward (concat "^" (int-to-string article) "\t") nil t)
692         (delete-region (match-beginning 0) (progn (forward-line 1) (point))))
693     t))
694
695 (provide 'nnml)
696
697 ;;; nnml.el ends here