-(defun nnfolder-read-folder (file)
- (save-excursion
- (nnfolder-possibly-activate-groups nil)
- ;; We should be paranoid here and make sure the group is in the alist,
- ;; and add it if it isn't.
- ;;(if (not (assoc nnfoler-current-group nnfolder-group-alist)
- (set-buffer (setq nnfolder-current-buffer
- (nnheader-find-file-noselect file nil 'raw)))
- (buffer-disable-undo (current-buffer))
- (let* ((delim (concat "^" rmail-unix-mail-delimiter))
- (marker (concat "\n" nnfolder-article-marker))
- (number "[0-9]+")
- (active (cadr (assoc nnfolder-current-group
- nnfolder-group-alist)))
- ;; Set min to Big Number.
- (min (max (1- (lsh 1 23)) (1- (lsh 1 24)) (1- (lsh 1 25))))
- (max (cdr active))
- start end)
- (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
- (< max 2))
- (while (and (search-forward marker nil t)
- (re-search-forward number nil t))
- (let ((newnum (string-to-number (match-string 0))))
- (setq max (max max newnum))
- (setq min (min min newnum))))
- (setcar active (max 1 (min min max)))
- (setcdr active (max max (cdr active)))
- (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.
- (setq end (point-marker))
- (set-marker end (or (and (re-search-forward delim nil t)
- (match-beginning 0))
- (point-max)))
- (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 (or (and (re-search-forward delim nil t)
- (match-beginning 0))
- (point-max)))
- (goto-char start)
- (if (not (search-forward marker end t))
- (progn
+(defun nnfolder-read-folder (file &optional scanning)
+ ;; This is an attempt at a serious shortcut - don't even read in the file
+ ;; if we know we've seen it since the last time it was touched.
+ (let ((scantime (cadr (assoc nnfolder-current-group
+ nnfolder-scantime-alist)))
+ (modtime (nth 5 (or (file-attributes file) '(nil nil nil nil nil)))))
+ (if (and scanning scantime
+ (eq (car scantime) (car modtime))
+ (eq (cdr scantime) (cadr modtime)))
+ nil
+ (save-excursion
+ (nnfolder-possibly-activate-groups nil)
+ ;; Read in the file.
+ (set-buffer (setq nnfolder-current-buffer
+ (nnheader-find-file-noselect file nil 'raw)))
+ (buffer-disable-undo (current-buffer))
+ ;; If the file hasn't been touched since the last time we scanned it,
+ ;; don't bother doing anything with it.
+ (let ((delim (concat "^" message-unix-mail-delimiter))
+ (marker (concat "\n" nnfolder-article-marker))
+ (number "[0-9]+")
+ (active (or (cadr (assoc nnfolder-current-group
+ nnfolder-group-alist))
+ (cons 1 0)))
+ (scantime (assoc nnfolder-current-group nnfolder-scantime-alist))
+ (minid (lsh -1 -1))
+ maxid start end newscantime)
+
+ (setq maxid (or (cdr active) 0))
+ (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 (re-search-backward delim nil t))
+ (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.
+ (setq end (point-marker))
+ (set-marker end (or (and (re-search-forward delim nil t)
+ (match-beginning 0))
+ (point-max)))
+ (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 (or (and (re-search-forward delim nil t)
+ (match-beginning 0))
+ (point-max)))
+ (goto-char start)
+ (when (not (search-forward marker end t))