*** 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          article rest mod-time)
273     (while articles
274       (setq article (concat nnml-current-directory (int-to-string
275                                                       (car articles))))
276       (if (setq mod-time (nth 5 (file-attributes article)))
277           (if (and (or (not nnmail-keep-last-article)
278                        (not max-article)
279                        (not (= (car articles) max-article)))
280                    (or force
281                        (> (nnmail-days-between
282                            (current-time-string)
283                            (current-time-string mod-time))
284                           days)))
285               (progn
286                 (and gnus-verbose-backends (message "Deleting %s..." article))
287                 (condition-case ()
288                     (delete-file article)
289                   (file-error nil))
290                 (setq active-articles (delq (car articles) active-articles))
291                 (nnml-nov-delete-article newsgroup (car articles)))
292             (setq rest (cons (car articles) rest))))
293       (setq articles (cdr articles)))
294     (let ((active (nth 1 (assoc newsgroup nnml-group-alist))))
295       (and active
296            (setcar active (or (and active-articles
297                                    (apply 'min active-articles))
298                               0)))
299       (nnmail-save-active nnml-group-alist nnml-active-file))
300     (nnml-save-nov)
301     (message "")
302     rest))
303
304 (defun nnml-request-move-article 
305   (article group server accept-form &optional last)
306   (let ((buf (get-buffer-create " *nnml move*"))
307         result)
308     (and 
309      (nnml-request-article article group server)
310      (save-excursion
311        (set-buffer buf)
312        (insert-buffer-substring nntp-server-buffer)
313        (setq result (eval accept-form))
314        (kill-buffer (current-buffer))
315        result)
316      (progn
317        (condition-case ()
318            (delete-file (concat nnml-current-directory 
319                                 (int-to-string article)))
320          (file-error nil))
321        (nnml-nov-delete-article group article)
322        (and last (nnml-save-nov))))
323     result))
324
325 (defun nnml-request-accept-article (group &optional last)
326   (let (result)
327     (if (stringp group)
328         (and 
329          (nnml-request-list)
330          (setq nnml-group-alist (nnmail-get-active))
331          ;; We trick the choosing function into believing that only one
332          ;; group is availiable.  
333          (let ((nnmail-split-methods (list (list group ""))))
334            (setq result (car (nnml-save-mail))))
335          (progn
336            (nnmail-save-active nnml-group-alist nnml-active-file)
337            (and last (nnml-save-nov))))
338       (and
339        (nnml-request-list)
340        (setq nnml-group-alist (nnmail-get-active))
341        (setq result (car (nnml-save-mail)))
342        (progn
343          (nnmail-save-active nnml-group-alist nnml-active-file)
344          (and last (nnml-save-nov)))))
345     result))
346
347 (defun nnml-request-replace-article (article group buffer)
348   (nnml-possibly-change-directory group)
349   (save-excursion
350     (set-buffer buffer)
351     (nnml-possibly-create-directory group)
352     (if (not (condition-case ()
353                  (progn
354                    (write-region (point-min) (point-max)
355                                  (concat nnml-current-directory 
356                                          (int-to-string article))
357                                  nil (if gnus-verbose-backends nil 'nomesg))
358                    t)
359                (error nil)))
360         ()
361       (let ((chars (nnmail-insert-lines))
362             (art (concat (int-to-string article) "\t"))
363             nov-line)
364         (setq nov-line (nnml-make-nov-line chars))
365         (save-excursion 
366           (set-buffer (nnml-open-nov group))
367           (goto-char (point-min))
368           (if (or (looking-at art)
369                   (search-forward (concat "\n" art)))
370               (progn
371                 (delete-region (progn (beginning-of-line) (point))
372                                (progn (forward-line 1) (point)))
373                 (insert (int-to-string article) nov-line)
374                 (nnml-save-nov))
375             (kill-buffer (current-buffer)))
376           t)))))
377
378
379 \f
380 ;;; Internal functions
381
382 (defun nnml-retrieve-headers-with-nov (articles)
383   (if (or gnus-nov-is-evil nnml-nov-is-evil)
384       nil
385     (let ((first (car articles))
386           (last (progn (while (cdr articles) (setq articles (cdr articles)))
387                        (car articles)))
388           (nov (concat nnml-current-directory nnml-nov-file-name)))
389       (if (file-exists-p nov)
390           (save-excursion
391             (set-buffer nntp-server-buffer)
392             (erase-buffer)
393             (insert-file-contents nov)
394             (goto-char (point-min))
395             (while (and (not (eobp)) (< first (read (current-buffer))))
396               (forward-line 1))
397             (beginning-of-line)
398             (if (not (eobp)) (delete-region 1 (point)))
399             (while (and (not (eobp)) (>= last (read (current-buffer))))
400               (forward-line 1))
401             (beginning-of-line)
402             (if (not (eobp)) (delete-region (point) (point-max)))
403             t)))))
404
405 (defun nnml-possibly-change-directory (newsgroup &optional force)
406   (if newsgroup
407       (let ((pathname (nnmail-article-pathname newsgroup nnml-directory)))
408         (and (or force (file-directory-p pathname))
409              (setq nnml-current-directory pathname)))
410     t))
411
412 (defun nnml-possibly-create-directory (group)
413   (let (dir dirs)
414     (setq dir (nnmail-article-pathname group nnml-directory))
415     (while (not (file-directory-p dir))
416       (setq dirs (cons dir dirs))
417       (setq dir (file-name-directory (directory-file-name dir))))
418     (while dirs
419       (if (make-directory (directory-file-name (car dirs)))
420           (error "Could not create directory %s" (car dirs)))
421       (and gnus-verbose-backends 
422            (message "Creating mail directory %s" (car dirs)))
423       (setq dirs (cdr dirs)))))
424              
425 (defun nnml-save-mail ()
426   "Called narrowed to an article."
427   (let ((group-art (nreverse (nnmail-article-group 'nnml-active-number)))
428         chars nov-line)
429     (setq chars (nnmail-insert-lines))
430     (nnmail-insert-xref group-art)
431     (run-hooks 'nnml-prepare-save-mail-hook)
432     (goto-char (point-min))
433     (while (looking-at "From ")
434       (replace-match "X-From-Line: ")
435       (forward-line 1))
436     ;; We save the article in all the newsgroups it belongs in.
437     (let ((ga group-art)
438           first)
439       (while ga
440         (nnml-possibly-create-directory (car (car ga)))
441         (let ((file (concat (nnmail-article-pathname 
442                              (car (car ga)) nnml-directory)
443                             (int-to-string (cdr (car ga))))))
444           (if first
445               ;; It was already saved, so we just make a hard link.
446               (add-name-to-file first file t)
447             ;; Save the article.
448             (write-region (point-min) (point-max) file nil 
449                           (if gnus-verbose-backends nil 'nomesg))
450             (setq first file)))
451         (setq ga (cdr ga))))
452     ;; Generate a nov line for this article. We generate the nov
453     ;; line after saving, because nov generation destroys the
454     ;; header. 
455     (setq nov-line (nnml-make-nov-line chars))
456     ;; Output the nov line to all nov databases that should have it.
457     (let ((ga group-art))
458       (while ga
459         (nnml-add-nov (car (car ga)) (cdr (car ga)) nov-line)
460         (setq ga (cdr ga))))
461     group-art))
462
463 (defun nnml-active-number (group)
464   "Compute the next article number in GROUP."
465   (let ((active (car (cdr (assoc group nnml-group-alist)))))
466     (or active
467         (progn
468           (setq active (cons 1 0))
469           (setq nnml-group-alist (cons (list group active) nnml-group-alist))))
470     (setcdr active (1+ (cdr active)))
471     (let (file)
472       (while (file-exists-p
473               (setq file (concat (nnmail-article-pathname 
474                                   group nnml-directory)
475                                  (int-to-string (cdr active)))))
476         (setcdr active (1+ (cdr active)))))
477     (cdr active)))
478
479 (defun nnml-get-new-mail (&optional group)
480   "Read new incoming mail."
481   (let ((spools (nnmail-get-spool-files group))
482         incoming incomings)
483     (if (or (not nnml-get-new-mail) (not nnmail-spool-file))
484         ()
485       ;; We first activate all the groups.
486       (if (or (not group) (not nnml-group-alist))
487           (progn
488             (nnml-request-list)
489             (setq nnml-group-alist (nnmail-get-active))))
490       ;; The we go through all the existing spool files and split the
491       ;; mail from each.
492       (while spools
493         (and
494          (file-exists-p (car spools))
495          (> (nth 7 (file-attributes (car spools))) 0)
496          (progn
497            (and gnus-verbose-backends 
498                 (message "nnml: Reading incoming mail..."))
499            (setq incoming 
500                  (nnmail-move-inbox 
501                   (car spools) (concat nnml-directory "Incoming")))
502            (nnmail-split-incoming incoming 'nnml-save-mail nil group)
503            (setq incomings (cons incoming incomings))
504            ;; The following has been commented away, just to make sure
505            ;; that nobody ever loses any mail. If you feel safe that
506            ;; nnml will never do anything strange, just remove those
507            ;; two semicolons, and avoid having lots of "Incoming*"
508            ;; files. 
509            ;; (delete-file incoming)
510            ))
511         (setq spools (cdr spools)))
512       ;; If we did indeed read any incoming spools, we save all info. 
513       (if incoming 
514           (progn
515             (nnmail-save-active nnml-group-alist nnml-active-file)
516             (nnml-save-nov)
517             (run-hooks 'nnmail-read-incoming-hook)
518             (and gnus-verbose-backends
519                  (message "nnml: Reading incoming mail...done"))))
520       (while incomings
521         ;; The following has been commented away, just to make sure
522         ;; that nobody ever loses any mail. If you feel safe that
523         ;; nnfolder will never do anything strange, just remove those
524         ;; two semicolons, and avoid having lots of "Incoming*"
525         ;; files. 
526         ;; (and (file-writable-p incoming) (delete-file incoming))
527         (setq incomings (cdr incomings))))))
528
529
530 (defun nnml-add-nov (group article line)
531   "Add a nov line for the GROUP base."
532   (save-excursion 
533     (set-buffer (nnml-open-nov group))
534     (goto-char (point-max))
535     (insert (int-to-string article) line)))
536
537 (defsubst nnml-header-value ()
538   (buffer-substring (match-end 0) (save-excursion (end-of-line) (point))))
539
540 (defun nnml-make-nov-line (chars)
541   "Create a nov from the current headers."
542   (let ((case-fold-search t)
543         subject from date id references lines xref in-reply-to char)
544     (save-excursion
545       (save-restriction
546         (goto-char (point-min))
547         (narrow-to-region 
548          (point)
549          (1- (or (search-forward "\n\n" nil t) (point-max))))
550         ;; Fold continuation lines.
551         (goto-char (point-min))
552         (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t)
553           (replace-match " " t t))
554         (subst-char-in-region (point-min) (point-max) ?\t ? )
555         ;; [number subject from date id references chars lines xref]
556         (save-excursion
557           (goto-char (point-min))
558           (while (re-search-forward "^\\(from\\|subject\\|message-id\\|date\\|lines\\|xref\\|references\\|in-reply-to\\): "
559                                     nil t)
560             (beginning-of-line)
561             (setq char (downcase (following-char))) 
562             (cond
563              ((eq char ?s)
564               (setq subject (nnml-header-value)))
565              ((eq char ?f)
566               (setq from (nnml-header-value)))
567              ((eq char ?x)
568               (setq xref (nnml-header-value)))
569              ((eq char ?l)
570               (setq lines (nnml-header-value)))
571              ((eq char ?d)
572               (setq date (nnml-header-value)))
573              ((eq char ?m)
574               (setq id (setq id (nnml-header-value))))
575              ((eq char ?r)
576               (setq references (nnml-header-value)))
577              ((eq char ?i)
578               (setq in-reply-to (nnml-header-value))))
579             (forward-line 1))
580       
581           (and (not references)
582                in-reply-to
583                (string-match "<[^>]+>" in-reply-to)
584                (setq references
585                      (substring in-reply-to (match-beginning 0)
586                                 (match-end 0)))))
587         ;; [number subject from date id references chars lines xref]
588         (format "\t%s\t%s\t%s\t%s\t%s\t%d\t%s\t%s\t\n"
589                 (or subject "(none)")
590                 (or from "(nobody)") (or date "")
591                 (or id (concat "nnml-dummy-id-" 
592                                (mapconcat 
593                                 (lambda (time) (int-to-string time))
594                                 (current-time) "-")))
595                 (or references "")
596                 (or chars 0) (or lines "0") (or xref ""))))))
597
598 (defun nnml-open-nov (group)
599   (or (cdr (assoc group nnml-nov-buffer-alist))
600       (let ((buffer (find-file-noselect 
601                      (concat (nnmail-article-pathname 
602                               group nnml-directory) nnml-nov-file-name))))
603         (save-excursion
604           (set-buffer buffer)
605           (buffer-disable-undo (current-buffer)))
606         (setq nnml-nov-buffer-alist 
607               (cons (cons group buffer) nnml-nov-buffer-alist))
608         buffer)))
609
610 (defun nnml-save-nov ()
611   (save-excursion
612     (while nnml-nov-buffer-alist
613       (if (buffer-name (cdr (car nnml-nov-buffer-alist)))
614           (progn
615             (set-buffer (cdr (car nnml-nov-buffer-alist)))
616             (and (buffer-modified-p)
617                  (write-region 
618                   1 (point-max) (buffer-file-name) nil 'nomesg))
619             (set-buffer-modified-p nil)
620             (kill-buffer (current-buffer))))
621       (setq nnml-nov-buffer-alist (cdr nnml-nov-buffer-alist)))))
622
623 ;;;###autoload
624 (defun nnml-generate-nov-databases (dir)
625   "Generate nov databases in all nnml mail newsgroups."
626   (interactive 
627    (progn   
628      (setq nnml-group-alist nil)
629      (list nnml-directory)))
630   (nnml-open-server (or nnml-current-server ""))
631   (let ((dirs (directory-files dir t nil t)))
632     (while dirs 
633       (if (and (not (string-match "/\\.\\.$" (car dirs)))
634                (not (string-match "/\\.$" (car dirs)))
635                (file-directory-p (car dirs)))
636           (nnml-generate-nov-databases (car dirs)))
637       (setq dirs (cdr dirs))))
638   (let ((files (sort
639                 (mapcar
640                  (function
641                   (lambda (name)
642                     (string-to-int name)))
643                  (directory-files dir nil "^[0-9]+$" t))
644                 (function <)))
645         (nov (concat dir "/" nnml-nov-file-name))
646         (nov-buffer (get-buffer-create "*nov*"))
647         nov-line chars)
648     (if files
649         (setq nnml-group-alist 
650               (cons (list (nnmail-replace-chars-in-string 
651                            (substring (expand-file-name dir)
652                                       (length (expand-file-name 
653                                                nnml-directory)))
654                            ?/ ?.)
655                           (cons (car files)
656                                 (let ((f files))
657                                   (while (cdr f) (setq f (cdr f)))
658                                   (car f))))
659                     nnml-group-alist)))
660     (if files
661         (save-excursion
662           (set-buffer nntp-server-buffer)
663           (if (file-exists-p nov)
664               (delete-file nov))
665           (save-excursion
666             (set-buffer nov-buffer)
667             (buffer-disable-undo (current-buffer))
668             (erase-buffer))
669           (while files
670             (erase-buffer)
671             (insert-file-contents (concat dir "/" (int-to-string (car files))))
672             (goto-char (point-min))
673             (narrow-to-region 1 (save-excursion (search-forward "\n\n" nil t)
674                                                 (setq chars (- (point-max) 
675                                                                (point)))
676                                                 (point)))
677             (if (not (= 0 chars)) ; none of them empty files...
678                 (progn
679                   (setq nov-line (nnml-make-nov-line chars))
680                   (save-excursion
681                     (set-buffer nov-buffer)
682                     (goto-char (point-max))
683                     (insert (int-to-string (car files)) nov-line))))
684             (widen)
685             (setq files (cdr files)))
686           (save-excursion
687             (set-buffer nov-buffer)
688             (write-region 1 (point-max) (expand-file-name nov) nil
689                           'nomesg)
690             (kill-buffer (current-buffer)))))
691     (nnmail-save-active nnml-group-alist nnml-active-file)))
692
693 (defun nnml-nov-delete-article (group article)
694   (save-excursion
695     (set-buffer (nnml-open-nov group))
696     (goto-char (point-min))
697     (if (re-search-forward (concat "^" (int-to-string article) "\t") nil t)
698         (delete-region (match-beginning 0) (progn (forward-line 1) (point))))
699     t))
700
701 (provide 'nnml)
702
703 ;;; nnml.el ends here