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