Function: gnus-agent-fetch-headers

gnus-agent-fetch-headers is a byte-compiled function defined in gnus-agent.el.gz.

Signature

(gnus-agent-fetch-headers GROUP)

Documentation

Fetch interesting headers into the agent. The group's overview file will be updated to include the headers while a list of available article numbers will be returned.

Source Code

;; Defined in /usr/src/emacs/lisp/gnus/gnus-agent.el.gz
(defun gnus-agent-fetch-headers (group)
  "Fetch interesting headers into the agent.  The group's overview
file will be updated to include the headers while a list of available
article numbers will be returned."
  (let* ((fetch-all (and gnus-agent-consider-all-articles
                         ;; Do not fetch all headers if the predicate
                         ;; implies that we only consider unread articles.
                         (not (gnus-predicate-implies-unread
                               (gnus-agent-find-parameter group
                                                          'agent-predicate)))))
         (articles (if fetch-all
		       (if gnus-newsgroup-maximum-articles
			   (let ((active (gnus-active group)))
			     (range-uncompress
			      (cons (max (car active)
					 (- (cdr active)
					    gnus-newsgroup-maximum-articles
					    -1))
				    (cdr active))))
			 (range-uncompress (gnus-active group)))
                     (gnus-list-of-unread-articles group)))
         (gnus-decode-encoded-word-function 'identity)
	 (gnus-decode-encoded-address-function 'identity)
         (file (gnus-agent-article-name ".overview" group))
	 (file-name-coding-system nnmail-pathname-coding-system))

    (unless fetch-all
      ;; Add articles with marks to the list of article headers we want to
      ;; fetch.  Don't fetch articles solely on the basis of a recent or seen
      ;; mark, but do fetch recent or seen articles if they have other, more
      ;; interesting marks.  (We have to fetch articles with boring marks
      ;; because otherwise the agent will remove their marks.)
      (dolist (arts (gnus-info-marks (gnus-get-info group)))
        (unless (memq (car arts) '(seen recent killed cache))
          (setq articles (range-concat articles (cdr arts)))))
      (setq articles (sort (gnus-uncompress-sequence articles) #'<)))

    ;; At this point, I have the list of articles to consider for
    ;; fetching.  This is the list that I'll return to my caller. Some
    ;; of these articles may have already been fetched.  That's OK as
    ;; the fetch article code will filter those out.  Internally, I'll
    ;; filter this list to just those articles whose headers need to
    ;; be fetched.
    (let ((articles articles))
      ;; Remove known articles.
      (when (and (or gnus-agent-cache
                     (not gnus-plugged))
                 (gnus-agent-load-alist group))
        ;; Remove articles marked as downloaded.
        (if fetch-all
            ;; I want to fetch all headers in the active range.
            ;; Therefore, exclude only those headers that are in the
            ;; article alist.
            ;; NOTE: This is probably NOT what I want to do after
            ;; agent expiration in this group.
            (setq articles (gnus-agent-uncached-articles articles group))

          ;; I want to only fetch those headers that have never been
          ;; fetched.  Therefore, exclude all headers that are, or
          ;; WERE, in the article alist.
          (let ((low (1+ (caar (last gnus-agent-article-alist))))
                (high (cdr (gnus-active group))))
            ;; Low can be greater than High when the same group is
            ;; fetched twice in the same session {The first fetch will
            ;; fill the article alist such that (last
            ;; gnus-agent-article-alist) equals (cdr (gnus-active
            ;; group))}.  The addition of one(the 1+ above) then
            ;; forces Low to be greater than High.  When this happens,
            ;; range-list-intersection returns nil which
            ;; indicates that no headers need to be fetched. -- Kevin
            (setq articles (range-list-intersection
                            articles (list (cons low high)))))))

      (when articles
	(gnus-message
	 10 "gnus-agent-fetch-headers: undownloaded articles are `%s'"
	 (range-compress-list articles)))

      (with-current-buffer nntp-server-buffer
        (if articles
            (progn
	      (gnus-message 8 "Fetching headers for %s..." group)

              ;; Fetch them.
              (gnus-make-directory (nnheader-translate-file-chars
                                    (file-name-directory file) t))

              (unless (eq 'nov (gnus-retrieve-headers articles group))
                (nnvirtual-convert-headers))
              (gnus-agent-check-overview-buffer)
              ;; Move these headers to the overview buffer so that
              ;; gnus-agent-braid-nov can merge them with the contents
              ;; of FILE.
              (copy-to-buffer
	       gnus-agent-overview-buffer (point-min) (point-max))
	      ;; NOTE: Call g-a-brand-nov even when the file does not
	      ;; exist.  As a minimum, it will validate the article
	      ;; numbers already in the buffer.
	      (gnus-agent-braid-nov articles file)
              (let ((coding-system-for-write
                     gnus-agent-file-coding-system))
                (gnus-agent-check-overview-buffer)
                (write-region (point-min) (point-max) file nil 'silent))
	      (gnus-agent-update-view-total-fetched-for group t)
              (gnus-agent-save-alist group articles nil)
              articles)
          (ignore-errors
            (erase-buffer)
            (nnheader-insert-file-contents file)))))
    articles))