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