a8db42d4d5d4b6e6300604ee2360f1cfcffd0f6c
[gnus] / lisp / nnfolder.el
1 ;;; nnfolder.el --- mail folder access for Gnus
2 ;; Copyright (C) 1995 Free Software Foundation, Inc.
3
4 ;; Author: Scott Byer <byer@mv.us.adobe.com>
5 ;;      Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
6 ;;      Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
7 ;; Keywords: news, mail
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24
25 ;;; Commentary:
26
27 ;; For an overview of what the interface functions do, please see the
28 ;; Gnus sources.  
29
30 ;; Various enhancements by byer@mv.us.adobe.com (Scott Byer).
31
32 ;;; Code:
33
34 (require 'nnheader)
35 (require 'rmail)
36 (require 'nnmail)
37
38 (defvar nnfolder-directory (expand-file-name "~/Mail/")
39   "The name of the mail box file in the users home directory.")
40
41 (defvar nnfolder-active-file (concat nnfolder-directory  "active")
42   "The name of the active file.")
43
44 ;; I renamed this variable to somehting more in keeping with the general GNU
45 ;; style. -SLB
46
47 (defvar nnfolder-ignore-active-file nil
48   "If non-nil, causes nnfolder to do some extra work in order to determine the true active ranges of an mbox file.  
49 Note that the active file is still saved, but it's values are not
50 used.  This costs some extra time when scanning an mbox when opening
51 it.")
52
53 ;; Note that this variable may not be completely implemented yet. -SLB
54
55 (defvar nnfolder-always-close nil
56   "If non-nil, nnfolder attempts to only ever have one mbox open at a time.  
57 This is a straight space/performance trade off, as the mboxes will have to 
58 be scaned every time they are read in.  If nil (default), nnfolder will
59 attempt to keep the buffers around (saving the nnfolder's buffer upon group 
60 close, but not killing it), speeding some things up tremendously, especially
61 such things as moving mail.  All buffers always get killed upon server close.")
62
63 (defvar nnfolder-newsgroups-file (concat nnfolder-directory "newsgroups")
64   "Mail newsgroups description file.")
65
66 (defvar nnfolder-get-new-mail t
67   "If non-nil, nnml will check the incoming mail file and split the mail.")
68
69 \f
70
71 (defconst nnfolder-version "nnfolder 0.2"
72   "nnfolder version.")
73
74 (defconst nnfolder-article-marker "X-Gnus-Article-Number: "
75   "String used to demarcate what the article number for a message is.")
76
77 (defvar nnfolder-current-group nil)
78 (defvar nnfolder-current-buffer nil)
79 (defvar nnfolder-status-string "")
80 (defvar nnfolder-group-alist nil)
81 (defvar nnfolder-buffer-alist nil)
82
83 (defmacro nnfolder-article-string (article)
84   (` (concat "\n" nnfolder-article-marker (int-to-string (, article)) " ")))
85
86 \f
87
88 (defvar nnfolder-current-server nil)
89 (defvar nnfolder-server-alist nil)
90 (defvar nnfolder-server-variables 
91   (list 
92    (list 'nnfolder-directory nnfolder-directory)
93    (list 'nnfolder-active-file nnfolder-active-file)
94    (list 'nnfolder-newsgroups-file nnfolder-newsgroups-file)
95    (list 'nnfolder-get-new-mail nnfolder-get-new-mail)
96    '(nnfolder-current-group nil)
97    '(nnfolder-current-buffer nil)
98    '(nnfolder-status-string "")
99    '(nnfolder-group-alist nil)
100    '(nnfolder-buffer-alist nil)))
101
102 \f
103
104 ;;; Interface functions
105
106 (defun nnfolder-retrieve-headers (sequence &optional newsgroup server)
107   (save-excursion
108     (set-buffer nntp-server-buffer)
109     (erase-buffer)
110     (let ((file nil)
111           (number (length sequence))
112           (delim-string (concat "^" rmail-unix-mail-delimiter))
113           beg article art-string start stop)
114       (nnfolder-possibly-change-group newsgroup)
115       (set-buffer nnfolder-current-buffer)
116       (goto-char (point-min))
117       (while sequence
118         (setq article (car sequence))
119         (setq art-string (nnfolder-article-string article))
120         (set-buffer nnfolder-current-buffer)
121         (if (or (search-forward art-string nil t)
122                 ;; Don't search the whole file twice!  Also, articles
123                 ;; probably have some locality by number, so searching
124                 ;; backwards will be faster.  Especially if we're at the
125                 ;; beginning of the buffer :-). -SLB
126                 (search-backward art-string nil t))
127             (progn
128               (setq start (or (re-search-backward delim-string nil t)
129                               (point)))
130               (search-forward "\n\n" nil t)
131               (setq stop (1- (point)))
132               (set-buffer nntp-server-buffer)
133               (insert (format "221 %d Article retrieved.\n" article))
134               (setq beg (point))
135               (insert-buffer-substring nnfolder-current-buffer start stop)
136               (goto-char (point-max))
137               (insert ".\n")))
138         (setq sequence (cdr sequence)))
139
140       ;; Fold continuation lines.
141       (set-buffer nntp-server-buffer)
142       (goto-char 1)
143       (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t)
144         (replace-match " " t t))
145       'headers)))
146
147 (defun nnfolder-open-server (server &optional defs)
148   (nnheader-init-server-buffer)
149   (if (equal server nnfolder-current-server)
150       t
151     (if nnfolder-current-server
152         (setq nnfolder-server-alist 
153               (cons (list nnfolder-current-server
154                           (nnheader-save-variables nnfolder-server-variables))
155                     nnfolder-server-alist)))
156     (let ((state (assoc server nnfolder-server-alist)))
157       (if state 
158           (progn
159             (nnheader-restore-variables (nth 1 state))
160             (setq nnfolder-server-alist (delq state nnfolder-server-alist)))
161         (nnheader-set-init-variables nnfolder-server-variables defs)))
162     (setq nnfolder-current-server server)))
163
164 (defun nnfolder-close-server (&optional server)
165   t)
166
167 (defun nnfolder-server-opened (&optional server)
168   (and (equal server nnfolder-current-server)
169        nntp-server-buffer
170        (buffer-name nntp-server-buffer)))
171
172 (defun nnfolder-request-close ()
173   (let ((alist nnfolder-buffer-alist))
174     (while alist
175       (nnfolder-close-group (car (car alist)) nil t)
176       (setq alist (cdr alist))))
177   (setq nnfolder-buffer-alist nil
178         nnfolder-group-alist nil))
179
180 (defun nnfolder-status-message (&optional server)
181   nnfolder-status-string)
182
183 (defun nnfolder-request-article (article &optional newsgroup server buffer)
184   (nnfolder-possibly-change-group newsgroup)
185   (if (stringp article)
186       nil
187     (save-excursion
188       (set-buffer nnfolder-current-buffer)
189       (goto-char (point-min))
190       (if (search-forward (nnfolder-article-string article) nil t)
191           (let (start stop)
192             (re-search-backward (concat "^" rmail-unix-mail-delimiter) nil t)
193             (setq start (point))
194             (forward-line 1)
195             (or (and (re-search-forward 
196                       (concat "^" rmail-unix-mail-delimiter) nil t)
197                      (forward-line -1))
198                 (goto-char (point-max)))
199             (setq stop (point))
200             (let ((nntp-server-buffer (or buffer nntp-server-buffer)))
201               (set-buffer nntp-server-buffer)
202               (erase-buffer)
203               (insert-buffer-substring nnfolder-current-buffer start stop)
204               (goto-char (point-min))
205               (while (looking-at "From ")
206                 (delete-char 5)
207                 (insert "X-From-Line: ")
208                 (forward-line 1))
209               t))))))
210
211 (defun nnfolder-request-group (group &optional server dont-check)
212   (save-excursion
213     (nnfolder-possibly-change-group group)
214     (and (assoc group nnfolder-group-alist)
215          (progn
216            (if dont-check
217                t
218              (nnfolder-get-new-mail))
219            (let* ((active (assoc group nnfolder-group-alist))
220                   (group (car active))
221                   (range (car (cdr active)))
222                   (minactive (car range))
223                   (maxactive (cdr range)))
224              ;; I've been getting stray 211 lines in my nnfolder active
225              ;; file.  So, let's make sure that doesn't happen. -SLB
226              (set-buffer nntp-server-buffer)
227              (erase-buffer)
228              (insert (format "211 %d %d %d %s\n" 
229                              (1+ (- maxactive minactive))
230                              minactive maxactive group))
231              t)))))
232
233 ;; Don't close the buffer if we're not shutting down the server.  This way,
234 ;; we can keep the buffer in the group buffer cache, and not have to grovel
235 ;; over the buffer again unless we add new mail to it or modify it in some
236 ;; way.
237
238 (defun nnfolder-close-group (group &optional server force)
239   (nnfolder-possibly-change-group group)
240   (save-excursion
241     (set-buffer nnfolder-current-buffer)
242     ;; If the buffer was modified, write the file out now.
243     (and (buffer-modified-p) (save-buffer))
244     (if (or force
245             nnfolder-always-close)
246         ;; If we're shutting the server down, we need to kill the buffer and
247         ;; remove it from the open buffer list.  Or, of course, if we're
248         ;; trying to minimize our space impact.
249         (progn
250           (kill-buffer (current-buffer))
251           (setq nnfolder-buffer-alist (delq (assoc group nnfolder-buffer-alist)
252                                             nnfolder-buffer-alist))))
253     (setq nnfolder-current-group nil
254           nnfolder-current-buffer nil))
255   t)
256
257 (defun nnfolder-request-list (&optional server)
258   (if server (nnfolder-get-new-mail))
259   (or nnfolder-group-alist
260       (nnmail-find-file nnfolder-active-file)
261       (progn
262         (setq nnfolder-group-alist (nnmail-get-active))
263         (nnmail-save-active nnfolder-group-alist nnfolder-active-file)
264         (nnmail-find-file nnfolder-active-file))))
265
266 (defun nnfolder-request-newgroups (date &optional server)
267   (nnfolder-request-list server))
268
269 (defun nnfolder-request-list-newsgroups (&optional server)
270   (nnmail-find-file nnfolder-newsgroups-file))
271
272 (defun nnfolder-request-post (&optional server)
273   (mail-send-and-exit nil))
274
275 (fset 'nnfolder-request-post-buffer 'nnmail-request-post-buffer)
276
277 (defun nnfolder-request-expire-articles (articles newsgroup &optional server force)
278   (nnfolder-possibly-change-group newsgroup)
279   (let* ((days (or (and nnmail-expiry-wait-function
280                         (funcall nnmail-expiry-wait-function newsgroup))
281                    nnmail-expiry-wait))
282          article rest)
283     (save-excursion 
284       (set-buffer nnfolder-current-buffer)
285       (while articles
286         (goto-char 1)
287         (if (search-forward (nnfolder-article-string (car articles)) nil t)
288             (if (or force
289                     (> (nnmail-days-between 
290                         (current-time-string)
291                         (buffer-substring 
292                          (point) (progn (end-of-line) (point))))
293                        days))
294                 (progn
295                   (and gnus-verbose-backends
296                        (message "Deleting: %s" (car articles)))
297                   (nnfolder-delete-mail))
298               (setq rest (cons (car articles) rest))))
299         (setq articles (cdr articles)))
300       (and (buffer-modified-p) (save-buffer))
301       ;; Find the lowest active article in this group.
302       (let* ((active (car (cdr (assoc newsgroup nnfolder-group-alist))))
303              (marker (concat "\n" nnfolder-article-marker))
304              (number "[0-9]+")
305              (activemin (cdr active)))
306         (goto-char (point-min))
307         (while (and (search-forward marker nil t)
308                     (re-search-forward number nil t))
309           (setq activemin (min activemin
310                                (string-to-number (buffer-substring
311                                                   (match-beginning 0)
312                                                   (match-end 0))))))
313         (setcar active activemin))
314       (nnmail-save-active nnfolder-group-alist nnfolder-active-file)
315       rest)))
316
317 (defun nnfolder-request-move-article
318   (article group server accept-form &optional last)
319   (nnfolder-possibly-change-group group)
320   (let ((buf (get-buffer-create " *nnfolder move*"))
321         result)
322     (and 
323      (nnfolder-request-article article group server)
324      (save-excursion
325        (set-buffer buf)
326        (buffer-disable-undo (current-buffer))
327        (erase-buffer)
328        (insert-buffer-substring nntp-server-buffer)
329        (goto-char (point-min))
330        (while (re-search-forward 
331                "^X-Gnus-Newsgroup:" 
332                (save-excursion (search-forward "\n\n" nil t) (point)) t)
333          (delete-region (progn (beginning-of-line) (point))
334                         (progn (forward-line 1) (point))))
335        (setq result (eval accept-form))
336        (kill-buffer buf)
337        result)
338      (save-excursion
339        (nnfolder-possibly-change-group group)
340        (set-buffer nnfolder-current-buffer)
341        (goto-char 1)
342        (if (search-forward (nnfolder-article-string article) nil t)
343            (nnfolder-delete-mail))
344        (and last 
345             (buffer-modified-p)
346             (save-buffer))))
347     result))
348
349 (defun nnfolder-request-accept-article (group &optional last)
350   (nnfolder-possibly-change-group group)
351   (let ((buf (current-buffer))
352         result beg)
353     (goto-char (point-min))
354     (if (looking-at "X-From-Line: ")
355         (replace-match "From ")
356       (insert "From nobody " (current-time-string) "\n"))
357     (and 
358      (nnfolder-request-list)
359      (progn
360        (set-buffer buf)
361        (goto-char (point-min))
362        (search-forward "\n\n" nil t)
363        (forward-line -1)
364        (while (re-search-backward "^X-Gnus-Newsgroup: " nil t)
365          (delete-region (point) (progn (forward-line 1) (point))))
366        (setq result (car (nnfolder-save-mail (and (stringp group) group)))))
367      (save-excursion
368        (set-buffer nnfolder-current-buffer)
369        (insert-buffer-substring buf)
370        (and last (buffer-modified-p) (save-buffer))
371        result)
372      (nnmail-save-active nnfolder-group-alist nnfolder-active-file))
373     result))
374
375 (defun nnfolder-request-replace-article (article group buffer)
376   (nnfolder-possibly-change-group group)
377   (save-excursion
378     (set-buffer nnfolder-current-buffer)
379     (goto-char 1)
380     (if (not (search-forward (nnfolder-article-string article) nil t))
381         nil
382       (nnfolder-delete-mail t t)
383       (insert-buffer-substring buffer)
384       (and (buffer-modified-p) (save-buffer))
385       t)))
386
387 \f
388 ;;; Internal functions.
389
390 (defun nnfolder-delete-mail (&optional force leave-delim)
391   ;; Beginning of the article.
392   (save-excursion
393     (save-restriction
394       (narrow-to-region
395        (save-excursion
396          (re-search-backward (concat "^" rmail-unix-mail-delimiter) nil t)
397          (if leave-delim (progn (forward-line 1) (point))
398            (match-beginning 0)))
399        (progn
400          (forward-line 1)
401          (or (and (re-search-forward (concat "^" rmail-unix-mail-delimiter) 
402                                      nil t)
403                   (if (and (not (bobp)) leave-delim)
404                       (progn (forward-line -2) (point))
405                     (match-beginning 0)))
406              (point-max))))
407       (delete-region (point-min) (point-max)))))
408
409 (defun nnfolder-possibly-change-group (group)
410   (or (file-exists-p nnfolder-directory)
411       (make-directory (directory-file-name nnfolder-directory)))
412   (if (not nnfolder-group-alist)
413       (progn
414         (nnfolder-request-list)
415         (setq nnfolder-group-alist (nnmail-get-active))))
416   (or (assoc group nnfolder-group-alist)
417       (not (file-exists-p (concat nnfolder-directory group)))
418       (progn
419         (setq nnfolder-group-alist 
420               (cons (list group (cons 1 0)) nnfolder-group-alist))
421         (nnmail-save-active nnfolder-group-alist nnfolder-active-file)))
422   (let (inf file)
423     (if (and (equal group nnfolder-current-group)
424              (buffer-name nnfolder-current-buffer))
425         ()
426       (setq nnfolder-current-group group)
427
428       ;; If we have to change groups, see if we don't already have the mbox
429       ;; in memory.  If we do, verify the modtime and destroy the mbox if
430       ;; needed so we can rescan it.
431       (if (setq inf (assoc group nnfolder-buffer-alist))
432           (setq nnfolder-current-buffer (nth 1 inf)))
433
434       ;; If the buffer is not live, make sure it isn't in the alist.  If it
435       ;; is live, verify that nobody else has touched the file since last
436       ;; time.
437       (if (or (not (buffer-name nnfolder-current-buffer))
438               (not (and (bufferp nnfolder-current-buffer)
439                         (verify-visited-file-modtime nnfolder-current-buffer))))
440           (progn
441             (if (and (buffer-name nnfolder-current-buffer)
442                      (bufferp nnfolder-current-buffer))
443                 (kill-buffer nnfolder-current-buffer))
444             (setq nnfolder-buffer-alist (delq inf nnfolder-buffer-alist))
445             (setq inf nil)))
446       
447       (if inf
448           ()
449         (save-excursion
450           (setq file (concat nnfolder-directory group))
451           (if (not (file-exists-p file))
452               (write-region 1 1 file t 'nomesg))
453           (set-buffer (nnfolder-read-folder file))
454           (setq nnfolder-buffer-alist (cons (list group (current-buffer))
455                                             nnfolder-buffer-alist))))))
456   (setq nnfolder-current-group group))
457
458 (defun nnfolder-save-mail (&optional group)
459   "Called narrowed to an article."
460   (let* ((nnmail-split-methods 
461           (if group (list (list group "")) nnmail-split-methods))
462          (group-art-list
463           (nreverse (nnmail-article-group 'nnfolder-active-number)))
464          save-list group-art)
465     (setq save-list group-art-list)
466     (nnmail-insert-lines)
467     (nnmail-insert-xref group-art-list)
468
469     ;; Insert the mail into each of the destination groups.
470     (while group-art-list
471       (setq group-art (car group-art-list)
472             group-art-list (cdr group-art-list))
473
474       ;; Kill the previous newsgroup markers.
475       (goto-char (point-min))
476       (search-forward "\n\n" nil t)
477       (forward-line -1)
478       (while (search-backward (concat "\n" nnfolder-article-marker) nil t)
479         (delete-region (point) (progn (forward-line 1) (point))))
480
481       ;; Insert the new newsgroup marker.
482       (nnfolder-possibly-change-group (car group-art))
483       (nnfolder-insert-newsgroup-line group-art)
484       (let ((beg (point-min))
485             (end (point-max))
486             (obuf (current-buffer)))
487         (set-buffer nnfolder-current-buffer)
488         (goto-char (point-max))
489         (insert-buffer-substring obuf beg end)
490         (set-buffer obuf)))
491
492     ;; Did we save it anywhere?
493     save-list))
494
495 (defun nnfolder-insert-newsgroup-line (group-art)
496   (save-excursion
497     (goto-char (point-min))
498     (if (search-forward "\n\n" nil t)
499         (progn
500           (forward-char -1)
501           (insert (format (concat nnfolder-article-marker "%d   %s\n")
502                           (cdr group-art) (current-time-string)))))))
503
504 (defun nnfolder-active-number (group)
505   (if (not nnfolder-group-alist)
506       (save-excursion
507         (nnfolder-request-list)
508         (setq nnfolder-group-alist (nnmail-get-active))))
509   (let ((active (car (cdr (assoc group nnfolder-group-alist)))))
510     (setcdr active (1+ (cdr active)))
511     (cdr active)))
512
513
514 ;; This method has a problem if you've accidentally let the active list get
515 ;; out of sync with the files.  This could happen, say, if you've
516 ;; accidentally gotten new mail with something other than (ding) (but why
517 ;; would _that_ ever happen? :-).  In that case, we will be in the middle of
518 ;; processing the file, ready to add new X-Gnus article number markers, and
519 ;; we'll run accross a message with no ID yet - the active list _may_not_ be
520 ;; ready for us yet.
521
522 ;; To handle this, I'm modifying this routine to maintain the maximum ID seen
523 ;; so far, and when we hit a message with no ID, we will _manually_ scan the
524 ;; rest of the message looking for any more, possibly higher IDs.  We'll
525 ;; assume the maximum that we find is the highest active.  Note that this
526 ;; shouldn't cost us much extra time at all, but will be a lot less
527 ;; vulnerable to glitches between the mbox and the active file.
528
529 (defun nnfolder-read-folder (file)
530   (save-excursion
531     (if (not nnfolder-group-alist)
532         (progn
533           (nnfolder-request-list)
534           (setq nnfolder-group-alist (nnmail-get-active))))
535     ;; We should be paranoid here and make sure the group is in the alist,
536     ;; and add it if it isn't.
537     ;;(if (not (assoc nnfoler-current-group nnfolder-group-alist)
538     (set-buffer (setq nnfolder-current-buffer (find-file-noselect file)))
539     (buffer-disable-undo (current-buffer))
540     (let ((delim (concat "^" rmail-unix-mail-delimiter))
541           (marker (concat "\n" nnfolder-article-marker))
542           (number "[0-9]+")
543           (active (car (cdr (assoc nnfolder-current-group 
544                                    nnfolder-group-alist))))
545           activenumber activemin start end)
546       (goto-char (point-min))
547       ;;
548       ;; Anytime the active number is 1 or 0, it is supect.  In that case,
549       ;; search the file manually to find the active number.  Or, of course,
550       ;; if we're being paranoid.  (This would also be the place to build
551       ;; other lists from the header markers, such as expunge lists, etc., if
552       ;; we ever desired to abandon the active file entirely for mboxes.)
553       (setq activenumber (cdr active))
554       (if (or nnfolder-ignore-active-file
555               (< activenumber 2))
556           (progn
557             (setq activemin (max (1- (lsh 1 23)) 
558                                  (1- (lsh 1 24)) 
559                                  (1- (lsh 1 25))))
560             (while (and (search-forward marker nil t)
561                         (re-search-forward number nil t))
562               (let ((newnum (string-to-number (buffer-substring
563                                               (match-beginning 0)
564                                               (match-end 0)))))
565                 (setq activenumber (max activenumber newnum))
566                 (setq activemin (min activemin newnum))))
567             (setcar active (min activemin activenumber))
568             (setcdr active activenumber)
569             (goto-char (point-min))))
570
571       ;; Keep track of the active number on our own, and insert it back into
572       ;; the active list when we're done. Also, prime the pump to cut down on
573       ;; the number of searches we do.
574       (setq end (point-marker))
575       (set-marker end (or (and (re-search-forward delim nil t)
576                                (match-beginning 0))
577                           (point-max)))
578       (while (not (= end (point-max)))
579         (setq start (marker-position end))
580         (goto-char end)
581         (end-of-line)
582         (set-marker end (or (and (re-search-forward delim nil t)
583                                  (match-beginning 0))
584                             (point-max)))
585         (goto-char start)
586         (if (not (search-forward marker end t))
587             (progn
588               (narrow-to-region start end)
589               (nnmail-insert-lines)
590               (setq activenumber (1+ activenumber))
591               (nnfolder-insert-newsgroup-line (cons nil activenumber))
592               (widen))))
593
594       ;; Make absolutely sure that the active list reflects reality!
595       (setcdr active activenumber)
596       (nnmail-save-active nnfolder-group-alist nnfolder-active-file)
597       (current-buffer))))
598
599 (defun nnfolder-get-new-mail ()
600   (let (incoming)
601     (if (and nnmail-spool-file
602              nnfolder-get-new-mail
603              (file-exists-p nnmail-spool-file)
604              (> (nth 7 (file-attributes nnmail-spool-file)) 0))
605         (progn
606           (and gnus-verbose-backends
607                (message "nnfolder: Reading incoming mail..."))
608           (setq incoming 
609                 (nnmail-move-inbox nnmail-spool-file
610                                    (concat nnfolder-directory "Incoming")))
611           (nnmail-split-incoming incoming 'nnfolder-save-mail)
612           (run-hooks 'nnmail-read-incoming-hook)
613           (nnmail-save-active nnfolder-group-alist nnfolder-active-file)
614           (and gnus-verbose-backends
615                (message "nnfolder: Reading incoming mail...done"))))
616     (let ((bufs nnfolder-buffer-alist))
617       (save-excursion
618         (while bufs
619           (if (not (buffer-name (nth 1 (car bufs))))
620               (setq nnfolder-buffer-alist 
621                     (delq (car bufs) nnfolder-buffer-alist))
622             (set-buffer (nth 1 (car bufs)))
623             (and (buffer-modified-p) (save-buffer)))
624           (setq bufs (cdr bufs)))))
625     ;; (if incoming (delete-file incoming))
626     ))
627
628 (provide 'nnfolder)
629
630 ;;; nnfolder.el ends here