+ (nnmail-activate 'nnfolder)
+ ;; Read in the file.
+ (let ((delim (concat "^" message-unix-mail-delimiter))
+ (marker (concat "\n" nnfolder-article-marker))
+ (number "[0-9]+")
+ (active (cadr (assoc group nnfolder-group-alist)))
+ (scantime (assoc group nnfolder-scantime-alist))
+ (minid (lsh -1 -1))
+ maxid start end newscantime
+ buffer-read-only)
+ (buffer-disable-undo (current-buffer))
+ (setq maxid (cdr active))
+ (goto-char (point-min))
+
+ ;; Anytime the active number is 1 or 0, it is suspect. In that
+ ;; case, search the file manually to find the active number. Or,
+ ;; of course, if we're being paranoid. (This would also be the
+ ;; place to build other lists from the header markers, such as
+ ;; expunge lists, etc., if we ever desired to abandon the active
+ ;; file entirely for mboxes.)
+ (when (or nnfolder-ignore-active-file
+ (< maxid 2))
+ (while (and (search-forward marker nil t)
+ (re-search-forward number nil t))
+ (let ((newnum (string-to-number (match-string 0))))
+ (setq maxid (max maxid newnum))
+ (setq minid (min minid newnum))))
+ (setcar active (max 1 (min minid maxid)))
+ (setcdr active (max maxid (cdr active)))
+ (goto-char (point-min)))
+
+ ;; As long as we trust that the user will only insert unmarked mail
+ ;; at the end, go to the end and search backwards for the last
+ ;; marker. Find the start of that message, and begin to search for
+ ;; unmarked messages from there.
+ (when (not (or nnfolder-distrust-mbox
+ (< maxid 2)))
+ (goto-char (point-max))
+ (if (not (re-search-backward marker nil t))
+ (goto-char (point-min))
+ (when (not (nnmail-search-unix-mail-delim))
+ (goto-char (point-min)))))
+
+ ;; Keep track of the active number on our own, and insert it back
+ ;; into the active list when we're done. Also, prime the pump to
+ ;; cut down on the number of searches we do.
+ (unless (nnmail-search-unix-mail-delim)
+ (goto-char (point-max)))
+ (setq end (point-marker))
+ (while (not (= end (point-max)))
+ (setq start (marker-position end))
+ (goto-char end)
+ ;; There may be more than one "From " line, so we skip past
+ ;; them.
+ (while (looking-at delim)
+ (forward-line 1))
+ (set-marker end (if (nnmail-search-unix-mail-delim)
+ (point)
+ (point-max)))
+ (goto-char start)
+ (when (not (search-forward marker end t))
+ (narrow-to-region start end)
+ (nnmail-insert-lines)
+ (nnfolder-insert-newsgroup-line
+ (cons nil (nnfolder-active-number nnfolder-current-group)))
+ (widen)))
+
+ (set-marker end nil)
+ ;; Make absolutely sure that the active list reflects reality!
+ (nnmail-save-active nnfolder-group-alist nnfolder-active-file)
+ ;; Set the scantime for this group.
+ (setq newscantime (visited-file-modtime))
+ (if scantime
+ (setcdr scantime (list newscantime))
+ (push (list nnfolder-current-group newscantime)
+ nnfolder-scantime-alist))
+ (current-buffer))))))
+
+;;;###autoload
+(defun nnfolder-generate-active-file ()
+ "Look for mbox folders in the nnfolder directory and make them into groups."
+ (interactive)
+ (nnmail-activate 'nnfolder)
+ (let ((files (directory-files nnfolder-directory))
+ file)
+ (while (setq file (pop files))
+ (when (and (not (backup-file-name-p file))
+ (nnheader-mail-file-mbox-p
+ (concat nnfolder-directory file)))
+ (nnheader-message 5 "Adding group %s..." file)
+ (push (list file (cons 1 0)) nnfolder-group-alist)
+ (nnfolder-possibly-change-group file)
+ (nnfolder-close-group file))
+ (message ""))))
+
+(defun nnfolder-group-pathname (group)
+ "Make pathname for GROUP."
+ (let ((dir (file-name-as-directory (expand-file-name nnfolder-directory))))
+ ;; If this file exists, we use it directly.
+ (if (or nnmail-use-long-file-names
+ (file-exists-p (concat dir group)))
+ (concat dir group)
+ ;; If not, we translate dots into slashes.
+ (concat dir (nnheader-replace-chars-in-string group ?. ?/)))))
+
+(defun nnfolder-save-buffer ()
+ "Save the buffer."
+ (when (buffer-modified-p)
+ (run-hooks 'nnfolder-save-buffer-hook)
+ (save-buffer)))