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