*** 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         (setq spools (cdr spools)))
505       ;; If we did indeed read any incoming spools, we save all info. 
506       (if incoming 
507           (progn
508             (nnmail-save-active nnml-group-alist nnml-active-file)
509             (nnml-save-nov)
510             (run-hooks 'nnmail-read-incoming-hook)
511             (and gnus-verbose-backends
512                  (message "nnml: Reading incoming mail...done"))))
513       (while incomings
514         (and nnmail-delete-incoming
515              (file-writable-p incoming)
516              (delete-file incoming))
517         (setq incomings (cdr incomings))))))
518
519
520 (defun nnml-add-nov (group article line)
521   "Add a nov line for the GROUP base."
522   (save-excursion 
523     (set-buffer (nnml-open-nov group))
524     (goto-char (point-max))
525     (insert (int-to-string article) line)))
526
527 (defsubst nnml-header-value ()
528   (buffer-substring (match-end 0) (save-excursion (end-of-line) (point))))
529
530 (defun nnml-make-nov-line (chars)
531   "Create a nov from the current headers."
532   (let ((case-fold-search t)
533         subject from date id references lines xref in-reply-to char)
534     (save-excursion
535       (save-restriction
536         (goto-char (point-min))
537         (narrow-to-region 
538          (point)
539          (1- (or (search-forward "\n\n" nil t) (point-max))))
540         ;; Fold continuation lines.
541         (goto-char (point-min))
542         (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t)
543           (replace-match " " t t))
544         (subst-char-in-region (point-min) (point-max) ?\t ? )
545         ;; [number subject from date id references chars lines xref]
546         (save-excursion
547           (goto-char (point-min))
548           (while (re-search-forward "^\\(from\\|subject\\|message-id\\|date\\|lines\\|xref\\|references\\|in-reply-to\\): "
549                                     nil t)
550             (beginning-of-line)
551             (setq char (downcase (following-char))) 
552             (cond
553              ((eq char ?s)
554               (setq subject (nnml-header-value)))
555              ((eq char ?f)
556               (setq from (nnml-header-value)))
557              ((eq char ?x)
558               (setq xref (nnml-header-value)))
559              ((eq char ?l)
560               (setq lines (nnml-header-value)))
561              ((eq char ?d)
562               (setq date (nnml-header-value)))
563              ((eq char ?m)
564               (setq id (setq id (nnml-header-value))))
565              ((eq char ?r)
566               (setq references (nnml-header-value)))
567              ((eq char ?i)
568               (setq in-reply-to (nnml-header-value))))
569             (forward-line 1))
570       
571           (and (not references)
572                in-reply-to
573                (string-match "<[^>]+>" in-reply-to)
574                (setq references
575                      (substring in-reply-to (match-beginning 0)
576                                 (match-end 0)))))
577         ;; [number subject from date id references chars lines xref]
578         (format "\t%s\t%s\t%s\t%s\t%s\t%d\t%s\t%s\t\n"
579                 (or subject "(none)")
580                 (or from "(nobody)") (or date "")
581                 (or id (concat "nnml-dummy-id-" 
582                                (mapconcat 
583                                 (lambda (time) (int-to-string time))
584                                 (current-time) "-")))
585                 (or references "")
586                 (or chars 0) (or lines "0") (or xref ""))))))
587
588 (defun nnml-open-nov (group)
589   (or (cdr (assoc group nnml-nov-buffer-alist))
590       (let ((buffer (find-file-noselect 
591                      (concat (nnmail-article-pathname 
592                               group nnml-directory) nnml-nov-file-name))))
593         (save-excursion
594           (set-buffer buffer)
595           (buffer-disable-undo (current-buffer)))
596         (setq nnml-nov-buffer-alist 
597               (cons (cons group buffer) nnml-nov-buffer-alist))
598         buffer)))
599
600 (defun nnml-save-nov ()
601   (save-excursion
602     (while nnml-nov-buffer-alist
603       (if (buffer-name (cdr (car nnml-nov-buffer-alist)))
604           (progn
605             (set-buffer (cdr (car nnml-nov-buffer-alist)))
606             (and (buffer-modified-p)
607                  (write-region 
608                   1 (point-max) (buffer-file-name) nil 'nomesg))
609             (set-buffer-modified-p nil)
610             (kill-buffer (current-buffer))))
611       (setq nnml-nov-buffer-alist (cdr nnml-nov-buffer-alist)))))
612
613 ;;;###autoload
614 (defun nnml-generate-nov-databases (dir)
615   "Generate nov databases in all nnml mail newsgroups."
616   (interactive 
617    (progn   
618      (setq nnml-group-alist nil)
619      (list nnml-directory)))
620   (nnml-open-server (or nnml-current-server ""))
621   (let ((dirs (directory-files dir t nil t)))
622     (while dirs 
623       (if (and (not (string-match "/\\.\\.$" (car dirs)))
624                (not (string-match "/\\.$" (car dirs)))
625                (file-directory-p (car dirs)))
626           (nnml-generate-nov-databases (car dirs)))
627       (setq dirs (cdr dirs))))
628   (let ((files (sort
629                 (mapcar
630                  (function
631                   (lambda (name)
632                     (string-to-int name)))
633                  (directory-files dir nil "^[0-9]+$" t))
634                 (function <)))
635         (nov (concat dir "/" nnml-nov-file-name))
636         (nov-buffer (get-buffer-create "*nov*"))
637         nov-line chars)
638     (if files
639         (setq nnml-group-alist 
640               (cons (list (nnmail-replace-chars-in-string 
641                            (substring (expand-file-name dir)
642                                       (length (expand-file-name 
643                                                nnml-directory)))
644                            ?/ ?.)
645                           (cons (car files)
646                                 (let ((f files))
647                                   (while (cdr f) (setq f (cdr f)))
648                                   (car f))))
649                     nnml-group-alist)))
650     (if files
651         (save-excursion
652           (set-buffer nntp-server-buffer)
653           (if (file-exists-p nov)
654               (delete-file nov))
655           (save-excursion
656             (set-buffer nov-buffer)
657             (buffer-disable-undo (current-buffer))
658             (erase-buffer))
659           (while files
660             (erase-buffer)
661             (insert-file-contents (concat dir "/" (int-to-string (car files))))
662             (goto-char (point-min))
663             (narrow-to-region 1 (save-excursion (search-forward "\n\n" nil t)
664                                                 (setq chars (- (point-max) 
665                                                                (point)))
666                                                 (point)))
667             (if (not (= 0 chars)) ; none of them empty files...
668                 (progn
669                   (setq nov-line (nnml-make-nov-line chars))
670                   (save-excursion
671                     (set-buffer nov-buffer)
672                     (goto-char (point-max))
673                     (insert (int-to-string (car files)) nov-line))))
674             (widen)
675             (setq files (cdr files)))
676           (save-excursion
677             (set-buffer nov-buffer)
678             (write-region 1 (point-max) (expand-file-name nov) nil
679                           'nomesg)
680             (kill-buffer (current-buffer)))))
681     (nnmail-save-active nnml-group-alist nnml-active-file)))
682
683 (defun nnml-nov-delete-article (group article)
684   (save-excursion
685     (set-buffer (nnml-open-nov group))
686     (goto-char (point-min))
687     (if (re-search-forward (concat "^" (int-to-string article) "\t") nil t)
688         (delete-region (match-beginning 0) (progn (forward-line 1) (point))))
689     t))
690
691 (provide 'nnml)
692
693 ;;; nnml.el ends here