- (let ((nov (concat (file-name-as-directory 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"))
+ (arts articles)
+ (nnheader-file-coding-system nnspool-file-coding-system)
+ last)
+ (if (not (file-exists-p nov))
+ ()
+ (with-current-buffer nntp-server-buffer
+ (erase-buffer)
+ (if nnspool-sift-nov-with-sed
+ (nnspool-sift-nov-with-sed articles nov)
+ (nnheader-insert-file-contents nov)
+ (if (and fetch-old
+ (not (numberp fetch-old)))
+ t ; We want all the headers.
+ (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))))