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