- ;; 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)
- (if (or (eobp)
- (>= (setq num (read cur)) article))
- (beginning-of-line)
- (while (not found)
- (goto-char (/ (+ max min) 2))
- (forward-line 1)
- (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))))
- (beginning-of-line)))
- (or (not num) (= num article))))
-
+ (ignore-errors
+ ;; Delete unwanted NOV lines.
+ (nnheader-nov-delete-outside-range
+ (if fetch-old (max 1 (- (car articles) fetch-old))
+ (car articles))
+ (car (last articles)))
+ ;; If the buffer is empty, this wasn't very successful.
+ (unless (zerop (buffer-size))
+ ;; We check what the last article number was.
+ ;; The NOV file may be out of sync with the articles
+ ;; in the group.
+ (forward-line -1)
+ (setq last (read (current-buffer)))
+ (if (= last (car articles))
+ ;; Yup, it's all there.
+ t
+ ;; Perhaps not. We try to find the missing articles.
+ (while (and arts
+ (<= last (car arts)))
+ (pop arts))
+ ;; The articles in `arts' are missing from the buffer.
+ (mapc 'nnspool-insert-nov-head arts)
+ t))))))))))
+
+(defun nnspool-insert-nov-head (article)
+ "Read the head of ARTICLE, convert to NOV headers, and insert."
+ (save-excursion
+ (let ((cur (current-buffer))
+ buf)
+ (setq buf (nnheader-set-temp-buffer " *nnspool head*"))
+ (when (nnheader-insert-head
+ (nnspool-article-pathname nnspool-current-group article))
+ (nnheader-insert-article-line article)
+ (goto-char (point-min))
+ (let ((headers (nnheader-parse-head)))
+ (set-buffer cur)
+ (goto-char (point-max))
+ (nnheader-insert-nov headers)))
+ (kill-buffer buf))))