Function: gnus-agent-fetch-articles
gnus-agent-fetch-articles is a byte-compiled function defined in
gnus-agent.el.gz.
Signature
(gnus-agent-fetch-articles GROUP ARTICLES)
Documentation
Fetch ARTICLES from GROUP and put them into the Agent.
Source Code
;; Defined in /usr/src/emacs/lisp/gnus/gnus-agent.el.gz
;;;
;;; Fetching
;;;
(defun gnus-agent-fetch-articles (group articles)
"Fetch ARTICLES from GROUP and put them into the Agent."
(when (and articles
(gnus-online (gnus-group-method group)))
(gnus-agent-load-alist group)
(let* ((alist gnus-agent-article-alist)
(headers (if (< (length articles) 2) nil gnus-newsgroup-headers))
(selected-sets (list nil))
(current-set-size 0)
article
header-number)
;; Check each article
(while (setq article (pop articles))
;; Skip alist entries preceding this article
(while (> article (or (caar alist) (1+ article)))
(setq alist (cdr alist)))
;; Prune off articles that we have already fetched.
(unless (and (eq article (caar alist))
(cdar alist))
;; Skip headers preceding this article
(while (> article
(setq header-number
(let* ((header (car headers)))
(if header
(mail-header-number header)
(1+ article)))))
(setq headers (cdr headers)))
;; Add this article to the current set
(setcar selected-sets (cons article (car selected-sets)))
;; Update the set size, when the set is too large start a
;; new one. I do this after adding the article as I want at
;; least one article in each set.
(when (< gnus-agent-max-fetch-size
(setq current-set-size
(+ current-set-size
(if (= header-number article)
(let ((char-size (mail-header-chars
(car headers))))
(if (<= char-size 0)
;; The char size was missing/invalid,
;; assume a worst-case situation of
;; 65 char/line. If the line count
;; is missing, arbitrarily assume a
;; size of 1000 characters.
(max (* 65 (mail-header-lines
(car headers)))
1000)
char-size))
0))))
(setcar selected-sets (nreverse (car selected-sets)))
(setq selected-sets (cons nil selected-sets)
current-set-size 0))))
(when (or (cdr selected-sets) (car selected-sets))
(let* ((fetched-articles (list nil))
(tail-fetched-articles fetched-articles)
(dir (gnus-agent-group-pathname group))
(date (time-to-days nil))
(case-fold-search t)
pos crosses
(file-name-coding-system nnmail-pathname-coding-system))
(setcar selected-sets (nreverse (car selected-sets)))
(setq selected-sets (nreverse selected-sets))
(gnus-make-directory dir)
(gnus-message 7 "Fetching articles for %s..." group)
(unwind-protect
(while (setq articles (pop selected-sets))
;; Fetch the articles from the backend.
(if (gnus-check-backend-function 'retrieve-articles group)
(setq pos (gnus-retrieve-articles articles group))
(with-temp-buffer
(let (article)
(while (setq article (pop articles))
(gnus-message 10 "Fetching article %s for %s..."
article group)
(when (or
(gnus-backlog-request-article group article
nntp-server-buffer)
(gnus-request-article article group))
(goto-char (point-max))
(push (cons article (point)) pos)
(insert-buffer-substring nntp-server-buffer)))
(copy-to-buffer
nntp-server-buffer (point-min) (point-max))
(setq pos (nreverse pos)))))
;; Then save these articles into the Agent.
(with-current-buffer nntp-server-buffer
(while pos
(narrow-to-region (cdar pos) (or (cdadr pos) (point-max)))
(goto-char (point-min))
(unless (eobp) ;; Don't save empty articles.
(when (search-forward "\n\n" nil t)
(when (search-backward "\nXrefs: " nil t)
;; Handle cross posting.
(goto-char (match-end 0)) ; move to end of header name
(skip-chars-forward "^ ") ; skip server name
(skip-chars-forward " ")
(setq crosses nil)
(while (looking-at "\\([^: \n]+\\):\\([0-9]+\\) *")
(push (cons (match-string 1)
(string-to-number (match-string 2)))
crosses)
(goto-char (match-end 0)))
(gnus-agent-crosspost crosses (caar pos) date)))
(goto-char (point-min))
(let ((coding-system-for-write
gnus-agent-file-coding-system))
(write-region (point-min) (point-max)
(concat dir (number-to-string (caar pos)))
nil 'silent))
(gnus-agent-append-to-list
tail-fetched-articles (caar pos)))
(widen)
(setq pos (cdr pos)))))
(gnus-agent-save-alist group (cdr fetched-articles) date)
(gnus-agent-update-files-total-fetched-for group (cdr fetched-articles))
(gnus-message 7 ""))
(cdr fetched-articles))))))