- (let ((nov (concat nnspool-nov-directory
- (nnspool-replace-chars-in-string
- nnspool-current-group ?. ?/)
- "/.overview"))
- article)
- (if (file-exists-p nov)
- (save-excursion
- (set-buffer nntp-server-buffer)
- (erase-buffer)
- (if nnspool-sift-nov-with-sed
- (nnspool-sift-nov-with-sed articles nov)
- (insert-file-contents nov)
- ;; First we find the first wanted line. We issue a number
- ;; of search-forwards - the first article we are lookign
- ;; for may be expired, so we have to go on searching until
- ;; we find one of the articles we want.
- (while (and articles
- (setq article (concat (int-to-string
- (car articles)) "\t"))
- (not (or (looking-at article)
- (search-forward (concat "\n" article)
- nil t))))
- (setq articles (cdr articles)))
- (if (not articles)
- ()
- (beginning-of-line)
- (delete-region (point-min) (point))
- ;; Then we find the last wanted line. We go to the end
- ;; of the buffer and search backward much the same way
- ;; we did to find the first article.
- ;; !!! Perhaps it would be better just to do a (last articles),
- ;; and go forward successively over each line and
- ;; compare to avoid this (reverse), like this:
- ;; (while (and (>= last (read nntp-server-buffer)))
- ;; (zerop (forward-line 1))))
- (setq articles (reverse articles))
- (goto-char (point-max))
- (while (and articles
- (not (search-backward
- (concat "\n" (int-to-string (car articles))
- "\t") nil t)))
- (setq articles (cdr articles)))
- (if articles
- (progn
- (forward-line 2)
- (delete-region (point) (point-max)))))
- (or articles (progn (erase-buffer) nil))))))))
-
+ (let ((nov (nnheader-group-pathname
+ nnspool-current-group nnspool-nov-directory ".overview")))
+ (if (not (file-exists-p nov))
+ ()
+ (save-excursion
+ (set-buffer nntp-server-buffer)
+ (erase-buffer)
+ (if nnspool-sift-nov-with-sed
+ (nnspool-sift-nov-with-sed articles nov)
+ (insert-file-contents nov)
+ (if (and fetch-old
+ (not (numberp fetch-old)))
+ t ; We want all the headers.
+ ;; First we find the first wanted line.
+ (nnspool-find-nov-line
+ (if fetch-old (max 1 (- (car articles) fetch-old))
+ (car articles)))
+ (delete-region (point-min) (point))
+ ;; Then we find the last wanted line.
+ (if (nnspool-find-nov-line
+ (progn (while (cdr articles) (setq articles (cdr articles)))
+ (car articles)))
+ (forward-line 1))
+ (delete-region (point) (point-max))
+ ;; If the buffer is empty, this wasn't very successful.
+ (not (zerop (buffer-size))))))))))
+
+(defun nnspool-find-nov-line (article)
+ (let ((max (point-max))
+ (min (goto-char (point-min)))
+ (cur (current-buffer))
+ (prev (point-min))
+ num found)
+ (while (not found)
+ (goto-char (/ (+ max min) 2))
+ (beginning-of-line)
+ (if (or (= (point) prev)
+ (eobp))
+ (setq found t)
+ (setq prev (point))
+ (cond ((> (setq num (read cur)) article)
+ (setq max (point)))
+ ((< num article)
+ (setq min (point)))
+ (t
+ (setq found t)))))
+ ;; Now we may have found the article we're looking for, or we
+ ;; may be somewhere near it.
+ (when (not (eq num article))
+ (setq found (point))
+ (while (and (< (point) max)
+ (< num article))
+ (forward-line 1)
+ (setq found (point))
+ (or (eobp)
+ (= (setq num (read cur)) article)))
+ (unless (eq num article)
+ (goto-char found)))
+ (beginning-of-line)
+ (eq num article)))
+