1 ;;; nnfolder.el --- mail folder access for Gnus
2 ;; Copyright (C) 1995,96 Free Software Foundation, Inc.
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>
9 ;; This file is part of GNU Emacs.
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)
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.
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 the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
37 (nnoo-declare nnfolder)
39 (defvoo nnfolder-directory (expand-file-name message-directory)
40 "The name of the nnfolder directory.")
42 (defvoo nnfolder-active-file
43 (nnheader-concat nnfolder-directory "active")
44 "The name of the active file.")
46 ;; I renamed this variable to something more in keeping with the general GNU
49 (defvoo nnfolder-ignore-active-file nil
50 "If non-nil, causes nnfolder to do some extra work in order to determine
51 the true active ranges of an mbox file. Note that the active file is still
52 saved, but it's values are not used. This costs some extra time when
53 scanning an mbox when opening it.")
55 (defvoo nnfolder-distrust-mbox nil
56 "If non-nil, causes nnfolder to not trust the user with respect to
57 inserting unaccounted for mail in the middle of an mbox file. This can greatly
58 slow down scans, which now must scan the entire file for unmarked messages.
59 When nil, scans occur forward from the last marked message, a huge
60 time saver for large mailboxes.")
62 (defvoo nnfolder-newsgroups-file
63 (concat (file-name-as-directory nnfolder-directory) "newsgroups")
64 "Mail newsgroups description file.")
66 (defvoo nnfolder-get-new-mail t
67 "If non-nil, nnfolder will check the incoming mail file and split the mail.")
69 (defvoo nnfolder-prepare-save-mail-hook nil
70 "Hook run narrowed to an article before saving.")
72 (defvoo nnfolder-save-buffer-hook nil
73 "Hook run before saving the nnfolder mbox buffer.")
75 (defvoo nnfolder-inhibit-expiry nil
76 "If non-nil, inhibit expiry.")
80 (defconst nnfolder-version "nnfolder 1.0"
83 (defconst nnfolder-article-marker "X-Gnus-Article-Number: "
84 "String used to demarcate what the article number for a message is.")
86 (defvoo nnfolder-current-group nil)
87 (defvoo nnfolder-current-buffer nil)
88 (defvoo nnfolder-status-string "")
89 (defvoo nnfolder-group-alist nil)
90 (defvoo nnfolder-buffer-alist nil)
91 (defvoo nnfolder-scantime-alist nil)
95 ;;; Interface functions
97 (nnoo-define-basics nnfolder)
99 (deffoo nnfolder-retrieve-headers (articles &optional group server fetch-old)
101 (set-buffer nntp-server-buffer)
103 (let (article art-string start stop)
104 (nnfolder-possibly-change-group group server)
105 (when nnfolder-current-buffer
106 (set-buffer nnfolder-current-buffer)
107 (goto-char (point-min))
108 (if (stringp (car articles))
111 (setq article (car articles))
112 (setq art-string (nnfolder-article-string article))
113 (set-buffer nnfolder-current-buffer)
114 (when (or (search-forward art-string nil t)
115 ;; Don't search the whole file twice! Also, articles
116 ;; probably have some locality by number, so searching
117 ;; backwards will be faster. Especially if we're at the
118 ;; beginning of the buffer :-). -SLB
119 (search-backward art-string nil t))
120 (nnmail-search-unix-mail-delim-backward)
122 (search-forward "\n\n" nil t)
123 (setq stop (1- (point)))
124 (set-buffer nntp-server-buffer)
125 (insert (format "221 %d Article retrieved.\n" article))
126 (insert-buffer-substring nnfolder-current-buffer start stop)
127 (goto-char (point-max))
129 (setq articles (cdr articles)))
131 (set-buffer nntp-server-buffer)
132 (nnheader-fold-continuation-lines)
135 (deffoo nnfolder-open-server (server &optional defs)
136 (nnoo-change-server 'nnfolder server defs)
137 (when (not (file-exists-p nnfolder-directory))
138 (gnus-make-directory nnfolder-directory))
140 ((not (file-exists-p nnfolder-directory))
141 (nnfolder-close-server)
142 (nnheader-report 'nnfolder "Couldn't create directory: %s"
144 ((not (file-directory-p (file-truename nnfolder-directory)))
145 (nnfolder-close-server)
146 (nnheader-report 'nnfolder "Not a directory: %s" nnfolder-directory))
148 (nnheader-report 'nnfolder "Opened server %s using directory %s"
149 server nnfolder-directory)
152 (deffoo nnfolder-request-close ()
153 (let ((alist nnfolder-buffer-alist))
155 (nnfolder-close-group (caar alist) nil t)
156 (setq alist (cdr alist))))
157 (nnoo-close-server 'nnfolder)
158 (setq nnfolder-buffer-alist nil
159 nnfolder-group-alist nil))
161 (deffoo nnfolder-request-article (article &optional group server buffer)
162 (nnfolder-possibly-change-group group server)
164 (set-buffer nnfolder-current-buffer)
165 (goto-char (point-min))
166 (when (search-forward (nnfolder-article-string article) nil t)
168 (nnmail-search-unix-mail-delim-backward)
171 (unless (and (nnmail-search-unix-mail-delim)
173 (goto-char (point-max)))
175 (let ((nntp-server-buffer (or buffer nntp-server-buffer)))
176 (set-buffer nntp-server-buffer)
178 (insert-buffer-substring nnfolder-current-buffer start stop)
179 (goto-char (point-min))
180 (while (looking-at "From ")
182 (insert "X-From-Line: ")
184 (if (numberp article)
185 (cons nnfolder-current-group article)
186 (goto-char (point-min))
187 (search-forward (concat "\n" nnfolder-article-marker))
188 (cons nnfolder-current-group
191 (point) (progn (end-of-line) (point)))))))))))
193 (deffoo nnfolder-request-group (group &optional server dont-check)
195 (nnmail-activate 'nnfolder)
196 (if (not (assoc group nnfolder-group-alist))
197 (nnheader-report 'nnfolder "No such group: %s" group)
198 (nnfolder-possibly-change-group group server)
201 (nnheader-report 'nnfolder "Selected group %s" group)
203 (let* ((active (assoc group nnfolder-group-alist))
205 (range (cadr active)))
208 (nnheader-report 'nnfolder "No such group: %s" group))
209 ((null nnfolder-current-group)
210 (nnheader-report 'nnfolder "Empty group: %s" group))
212 (nnheader-report 'nnfolder "Selected group %s" group)
213 (nnheader-insert "211 %d %d %d %s\n"
214 (1+ (- (cdr range) (car range)))
215 (car range) (cdr range) group))))))))
217 (deffoo nnfolder-request-scan (&optional group server)
218 (nnfolder-possibly-change-group group server t)
222 (let ((bufs nnfolder-buffer-alist))
225 (if (not (buffer-name (nth 1 (car bufs))))
226 (setq nnfolder-buffer-alist
227 (delq (car bufs) nnfolder-buffer-alist))
228 (set-buffer (nth 1 (car bufs)))
229 (nnfolder-save-buffer)
230 (kill-buffer (current-buffer)))
231 (setq bufs (cdr bufs))))))
235 ;; Don't close the buffer if we're not shutting down the server. This way,
236 ;; we can keep the buffer in the group buffer cache, and not have to grovel
237 ;; over the buffer again unless we add new mail to it or modify it in some
240 (deffoo nnfolder-close-group (group &optional server force)
241 ;; Make sure we _had_ the group open.
242 (when (or (assoc group nnfolder-buffer-alist)
243 (equal group nnfolder-current-group))
244 (let ((inf (assoc group nnfolder-buffer-alist)))
246 (when nnfolder-current-group
247 (push (list nnfolder-current-group nnfolder-current-buffer)
248 nnfolder-buffer-alist))
249 (setq nnfolder-buffer-alist
250 (delq inf nnfolder-buffer-alist))
251 (setq nnfolder-current-buffer (cadr inf)
252 nnfolder-current-group (car inf))))
253 (when (and nnfolder-current-buffer
254 (buffer-name nnfolder-current-buffer))
256 (set-buffer nnfolder-current-buffer)
257 ;; If the buffer was modified, write the file out now.
258 (nnfolder-save-buffer)
259 ;; If we're shutting the server down, we need to kill the
260 ;; buffer and remove it from the open buffer list. Or, of
261 ;; course, if we're trying to minimize our space impact.
262 (kill-buffer (current-buffer))
263 (setq nnfolder-buffer-alist (delq (assoc group nnfolder-buffer-alist)
264 nnfolder-buffer-alist)))))
265 (setq nnfolder-current-group nil
266 nnfolder-current-buffer nil)
269 (deffoo nnfolder-request-create-group (group &optional server args)
270 (nnfolder-possibly-change-group nil server)
271 (nnmail-activate 'nnfolder)
273 (unless (assoc group nnfolder-group-alist)
274 (push (list group (cons 1 0)) nnfolder-group-alist)
275 (nnmail-save-active nnfolder-group-alist nnfolder-active-file)))
278 (deffoo nnfolder-request-list (&optional server)
279 (nnfolder-possibly-change-group nil server)
281 (nnmail-find-file nnfolder-active-file)
282 (setq nnfolder-group-alist (nnmail-get-active))
285 (deffoo nnfolder-request-newgroups (date &optional server)
286 (nnfolder-possibly-change-group nil server)
287 (nnfolder-request-list server))
289 (deffoo nnfolder-request-list-newsgroups (&optional server)
290 (nnfolder-possibly-change-group nil server)
292 (nnmail-find-file nnfolder-newsgroups-file)))
294 (deffoo nnfolder-request-expire-articles
295 (articles newsgroup &optional server force)
296 (nnfolder-possibly-change-group newsgroup server)
299 (nnmail-activate 'nnfolder)
302 (set-buffer nnfolder-current-buffer)
303 (while (and articles is-old)
304 (goto-char (point-min))
305 (when (search-forward (nnfolder-article-string (car articles)) nil t)
307 (nnmail-expired-article-p
310 (point) (progn (end-of-line) (point)))
311 force nnfolder-inhibit-expiry))
313 (nnheader-message 5 "Deleting article %d..."
314 (car articles) newsgroup)
315 (nnfolder-delete-mail))
316 (push (car articles) rest)))
317 (setq articles (cdr articles)))
318 (nnheader-message 5 "Deleting articles...done")
319 (nnfolder-save-buffer)
320 ;; Find the lowest active article in this group.
321 (let* ((active (cadr (assoc newsgroup nnfolder-group-alist)))
322 (marker (concat "\n" nnfolder-article-marker))
324 (activemin (cdr active)))
325 (goto-char (point-min))
326 (while (and (search-forward marker nil t)
327 (re-search-forward number nil t))
328 (setq activemin (min activemin
329 (string-to-number (buffer-substring
332 (setcar active activemin))
333 (nnmail-save-active nnfolder-group-alist nnfolder-active-file)
334 (nconc rest articles))))
336 (deffoo nnfolder-request-move-article
337 (article group server accept-form &optional last)
338 (let ((buf (get-buffer-create " *nnfolder move*"))
341 (nnfolder-request-article article group server)
344 (buffer-disable-undo (current-buffer))
346 (insert-buffer-substring nntp-server-buffer)
347 (goto-char (point-min))
348 (while (re-search-forward
349 (concat "^" nnfolder-article-marker)
350 (save-excursion (search-forward "\n\n" nil t) (point)) t)
351 (delete-region (progn (beginning-of-line) (point))
352 (progn (forward-line 1) (point))))
353 (setq result (eval accept-form))
357 (nnfolder-possibly-change-group group server)
358 (set-buffer nnfolder-current-buffer)
359 (goto-char (point-min))
360 (when (search-forward (nnfolder-article-string article) nil t)
361 (nnfolder-delete-mail))
362 (and last (nnfolder-save-buffer))))
365 (deffoo nnfolder-request-accept-article (group &optional server last)
366 (nnfolder-possibly-change-group group server)
367 (nnmail-check-syntax)
368 (let ((buf (current-buffer))
370 (goto-char (point-min))
371 (when (looking-at "X-From-Line: ")
372 (replace-match "From "))
374 (nnfolder-request-list)
377 (goto-char (point-min))
378 (search-forward "\n\n" nil t)
380 (while (re-search-backward (concat "^" nnfolder-article-marker) nil t)
381 (delete-region (point) (progn (forward-line 1) (point))))
383 (car (nnfolder-save-mail
385 (list (cons group (nnfolder-active-number group)))
386 (nnmail-article-group 'nnfolder-active-number))))))
388 (set-buffer nnfolder-current-buffer)
389 (and last (nnfolder-save-buffer))))
390 (nnmail-save-active nnfolder-group-alist nnfolder-active-file)
392 (nnheader-report 'nnfolder "Couldn't store article"))
395 (deffoo nnfolder-request-replace-article (article group buffer)
396 (nnfolder-possibly-change-group group)
398 (set-buffer nnfolder-current-buffer)
399 (goto-char (point-min))
400 (if (not (search-forward (nnfolder-article-string article) nil t))
402 (nnfolder-delete-mail t t)
403 (insert-buffer-substring buffer)
404 (nnfolder-save-buffer)
407 (deffoo nnfolder-request-delete-group (group &optional force server)
408 (nnfolder-close-group group server t)
409 ;; Delete all articles in GROUP.
411 () ; Don't delete the articles.
412 ;; Delete the file that holds the group.
414 (delete-file (nnfolder-group-pathname group))))
415 ;; Remove the group from all structures.
416 (setq nnfolder-group-alist
417 (delq (assoc group nnfolder-group-alist) nnfolder-group-alist)
418 nnfolder-current-group nil
419 nnfolder-current-buffer nil)
420 ;; Save the active file.
421 (nnmail-save-active nnfolder-group-alist nnfolder-active-file)
424 (deffoo nnfolder-request-rename-group (group new-name &optional server)
425 (nnfolder-possibly-change-group group server)
427 (set-buffer nnfolder-current-buffer)
428 (and (file-writable-p buffer-file-name)
432 (nnfolder-group-pathname new-name))
434 ;; That went ok, so we change the internal structures.
435 (let ((entry (assoc group nnfolder-group-alist)))
436 (and entry (setcar entry new-name))
437 (setq nnfolder-current-buffer nil
438 nnfolder-current-group nil)
439 ;; Save the new group alist.
440 (nnmail-save-active nnfolder-group-alist nnfolder-active-file)
441 ;; We kill the buffer instead of renaming it and stuff.
442 (kill-buffer (current-buffer))
446 ;;; Internal functions.
448 (defun nnfolder-article-string (article)
449 (if (numberp article)
450 (concat "\n" nnfolder-article-marker (int-to-string article) " ")
451 (concat "\nMessage-ID: " article)))
453 (defun nnfolder-delete-mail (&optional force leave-delim)
454 "Delete the message that point is in."
458 (nnmail-search-unix-mail-delim-backward)
459 (if leave-delim (progn (forward-line 1) (point))
463 (if (nnmail-search-unix-mail-delim)
464 (if (and (not (bobp)) leave-delim)
465 (progn (forward-line -2) (point))
469 ;; When scanning, we're not looking t immediately switch into the group - if
470 ;; we know our information is up to date, don't even bother reading the file.
471 (defun nnfolder-possibly-change-group (group &optional server scanning)
473 (not (nnfolder-server-opened server)))
474 (nnfolder-open-server server))
475 (when (and group (or nnfolder-current-buffer
476 (not (equal group nnfolder-current-group))))
477 (gnus-make-directory (directory-file-name nnfolder-directory))
478 (nnfolder-possibly-activate-groups nil)
479 (or (assoc group nnfolder-group-alist)
481 (nnfolder-group-pathname group)))
483 (push (list group (cons 1 0)) nnfolder-group-alist)
484 (nnmail-save-active nnfolder-group-alist nnfolder-active-file)))
486 (if (and (equal group nnfolder-current-group)
487 nnfolder-current-buffer
488 (buffer-name nnfolder-current-buffer))
490 (setq nnfolder-current-group group)
492 ;; If we have to change groups, see if we don't already have the mbox
493 ;; in memory. If we do, verify the modtime and destroy the mbox if
494 ;; needed so we can rescan it.
495 (when (setq inf (assoc group nnfolder-buffer-alist))
496 (setq nnfolder-current-buffer (nth 1 inf)))
498 ;; If the buffer is not live, make sure it isn't in the alist. If it
499 ;; is live, verify that nobody else has touched the file since last
501 (when (or (not (and nnfolder-current-buffer
502 (buffer-name nnfolder-current-buffer)))
503 (not (and (bufferp nnfolder-current-buffer)
504 (verify-visited-file-modtime
505 nnfolder-current-buffer))))
506 (when (and nnfolder-current-buffer
507 (buffer-name nnfolder-current-buffer)
508 (bufferp nnfolder-current-buffer))
509 (kill-buffer nnfolder-current-buffer))
510 (setq nnfolder-buffer-alist (delq inf nnfolder-buffer-alist))
515 (setq file (nnfolder-group-pathname group))
516 (unless (file-directory-p (file-truename file))
517 (unless (file-exists-p file)
518 (gnus-make-directory (file-name-directory file))
519 (nnmail-write-region 1 1 file t 'nomesg))
520 (setq nnfolder-current-buffer
521 (nnfolder-read-folder file scanning))
522 (when nnfolder-current-buffer
523 (set-buffer nnfolder-current-buffer)
524 (push (list group nnfolder-current-buffer)
525 nnfolder-buffer-alist)))))))
526 (setq nnfolder-current-group group)))
528 (defun nnfolder-save-mail (group-art-list)
529 "Called narrowed to an article."
530 (let* ((delim (concat "^" message-unix-mail-delimiter))
532 (goto-char (point-min))
533 ;; The From line may have been quoted by movemail.
534 (when (looking-at (concat ">" message-unix-mail-delimiter))
536 ;; This might come from somewhere else.
537 (unless (looking-at message-unix-mail-delimiter)
538 (insert "From nobody " (current-time-string) "\n")
539 (goto-char (point-min)))
540 ;; Quote all "From " lines in the article.
542 (while (re-search-forward "^From " nil t)
545 (setq save-list group-art-list)
546 (nnmail-insert-lines)
547 (nnmail-insert-xref group-art-list)
548 (run-hooks 'nnmail-prepare-save-mail-hook)
549 (run-hooks 'nnfolder-prepare-save-mail-hook)
551 ;; Insert the mail into each of the destination groups.
552 (while group-art-list
553 (setq group-art (car group-art-list)
554 group-art-list (cdr group-art-list))
556 ;; Kill the previous newsgroup markers.
557 (goto-char (point-min))
558 (search-forward "\n\n" nil t)
560 (while (search-backward (concat "\n" nnfolder-article-marker) nil t)
561 (delete-region (1+ (point)) (progn (forward-line 2) (point))))
563 (nnfolder-possibly-change-group (car group-art))
564 ;; Insert the new newsgroup marker.
565 (nnfolder-insert-newsgroup-line group-art)
566 (unless nnfolder-current-buffer
567 (nnfolder-close-group (car group-art))
568 (nnfolder-request-create-group (car group-art))
569 (nnfolder-possibly-change-group (car group-art)))
570 (let ((beg (point-min))
572 (obuf (current-buffer)))
573 (set-buffer nnfolder-current-buffer)
574 (goto-char (point-max))
579 (insert-buffer-substring obuf beg end)
582 ;; Did we save it anywhere?
585 (defun nnfolder-insert-newsgroup-line (group-art)
587 (goto-char (point-min))
588 (when (search-forward "\n\n" nil t)
590 (insert (format (concat nnfolder-article-marker "%d %s\n")
591 (cdr group-art) (current-time-string))))))
593 (defun nnfolder-possibly-activate-groups (&optional group)
595 ;; If we're looking for the activation of a specific group, find out
596 ;; its real name and switch to it.
598 (nnfolder-possibly-change-group group))
599 ;; If the group alist isn't active, activate it now.
600 (nnmail-activate 'nnfolder)))
602 (defun nnfolder-active-number (group)
605 ;; Find the next article number in GROUP.
607 (let ((active (cadr (assoc group nnfolder-group-alist))))
609 (setcdr active (1+ (cdr active)))
610 ;; This group is new, so we create a new entry for it.
611 ;; This might be a bit naughty... creating groups on the drop of
612 ;; a hat, but I don't know...
613 (push (list group (setq active (cons 1 1)))
614 nnfolder-group-alist))
616 (nnmail-save-active nnfolder-group-alist nnfolder-active-file)
617 (nnfolder-possibly-activate-groups group)))))
620 ;; This method has a problem if you've accidentally let the active list get
621 ;; out of sync with the files. This could happen, say, if you've
622 ;; accidentally gotten new mail with something other than Gnus (but why
623 ;; would _that_ ever happen? :-). In that case, we will be in the middle of
624 ;; processing the file, ready to add new X-Gnus article number markers, and
625 ;; we'll run across a message with no ID yet - the active list _may_not_ be
628 ;; To handle this, I'm modifying this routine to maintain the maximum ID seen
629 ;; so far, and when we hit a message with no ID, we will _manually_ scan the
630 ;; rest of the message looking for any more, possibly higher IDs. We'll
631 ;; assume the maximum that we find is the highest active. Note that this
632 ;; shouldn't cost us much extra time at all, but will be a lot less
633 ;; vulnerable to glitches between the mbox and the active file.
635 (defun nnfolder-read-folder (file &optional scanning)
636 ;; This is an attempt at a serious shortcut - don't even read in the file
637 ;; if we know we've seen it since the last time it was touched.
638 (let ((scantime (cadr (assoc nnfolder-current-group
639 nnfolder-scantime-alist)))
640 (modtime (nth 5 (file-attributes file))))
641 (if (and scanning scantime
642 (eq (car scantime) (car modtime))
643 (eq (cdr scantime) (cadr modtime)))
646 (nnfolder-possibly-activate-groups nil)
648 (set-buffer (setq nnfolder-current-buffer
649 (nnheader-find-file-noselect file)))
650 (buffer-disable-undo (current-buffer))
651 (setq buffer-read-only nil)
652 ;; If the file hasn't been touched since the last time we scanned it,
653 ;; don't bother doing anything with it.
654 (let ((delim (concat "^" message-unix-mail-delimiter))
655 (marker (concat "\n" nnfolder-article-marker))
657 (active (or (cadr (assoc nnfolder-current-group
658 nnfolder-group-alist))
660 (scantime (assoc nnfolder-current-group nnfolder-scantime-alist))
662 maxid start end newscantime)
664 (setq maxid (or (cdr active) 0))
665 (goto-char (point-min))
667 ;; Anytime the active number is 1 or 0, it is suspect. In that
668 ;; case, search the file manually to find the active number. Or,
669 ;; of course, if we're being paranoid. (This would also be the
670 ;; place to build other lists from the header markers, such as
671 ;; expunge lists, etc., if we ever desired to abandon the active
672 ;; file entirely for mboxes.)
673 (when (or nnfolder-ignore-active-file
675 (while (and (search-forward marker nil t)
676 (re-search-forward number nil t))
677 (let ((newnum (string-to-number (match-string 0))))
678 (setq maxid (max maxid newnum))
679 (setq minid (min minid newnum))))
680 (setcar active (max 1 (min minid maxid)))
681 (setcdr active (max maxid (cdr active)))
682 (goto-char (point-min)))
684 ;; As long as we trust that the user will only insert unmarked mail
685 ;; at the end, go to the end and search backwards for the last
686 ;; marker. Find the start of that message, and begin to search for
687 ;; unmarked messages from there.
688 (when (not (or nnfolder-distrust-mbox
690 (goto-char (point-max))
691 (if (not (re-search-backward marker nil t))
692 (goto-char (point-min))
693 (when (not (nnmail-search-unix-mail-delim))
694 (goto-char (point-min)))))
696 ;; Keep track of the active number on our own, and insert it back
697 ;; into the active list when we're done. Also, prime the pump to
698 ;; cut down on the number of searches we do.
699 (setq end (point-marker))
700 (set-marker end (or (and (nnmail-search-unix-mail-delim)
703 (while (not (= end (point-max)))
704 (setq start (marker-position end))
706 ;; There may be more than one "From " line, so we skip past
708 (while (looking-at delim)
710 (set-marker end (or (and (nnmail-search-unix-mail-delim)
714 (when (not (search-forward marker end t))
715 (narrow-to-region start end)
716 (nnmail-insert-lines)
717 (nnfolder-insert-newsgroup-line
718 (cons nil (nnfolder-active-number nnfolder-current-group)))
721 ;; Make absolutely sure that the active list reflects reality!
722 (nnmail-save-active nnfolder-group-alist nnfolder-active-file)
723 ;; Set the scantime for this group.
724 (setq newscantime (visited-file-modtime))
726 (setcdr scantime (list newscantime))
727 (push (list nnfolder-current-group newscantime)
728 nnfolder-scantime-alist))
729 (current-buffer))))))
732 (defun nnfolder-generate-active-file ()
733 "Look for mbox folders in the nnfolder directory and make them into groups."
735 (nnmail-activate 'nnfolder)
736 (let ((files (directory-files nnfolder-directory))
738 (while (setq file (pop files))
739 (when (and (not (backup-file-name-p file))
740 (nnheader-mail-file-mbox-p
741 (concat nnfolder-directory file)))
742 (nnheader-message 5 "Adding group %s..." file)
743 (push (list file (cons 1 0)) nnfolder-group-alist)
744 (nnfolder-possibly-change-group file)
745 (nnfolder-close-group file))
748 (defun nnfolder-group-pathname (group)
749 "Make pathname for GROUP."
750 (let ((dir (file-name-as-directory (expand-file-name nnfolder-directory))))
751 ;; If this file exists, we use it directly.
752 (if (or nnmail-use-long-file-names
753 (file-exists-p (concat dir group)))
755 ;; If not, we translate dots into slashes.
756 (concat dir (nnheader-replace-chars-in-string group ?. ?/)))))
758 (defun nnfolder-save-buffer ()
760 (when (buffer-modified-p)
761 (run-hooks 'nnfolder-save-buffer-hook)
766 ;;; nnfolder.el ends here