Function: gnus-agent-read-agentview

gnus-agent-read-agentview is a byte-compiled function defined in gnus-agent.el.gz.

Signature

(gnus-agent-read-agentview FILE)

Documentation

Load FILE and do a read there.

Source Code

;; Defined in /usr/src/emacs/lisp/gnus/gnus-agent.el.gz
(defun gnus-agent-read-agentview (file)
  "Load FILE and do a `read' there."
  (with-temp-buffer
    (condition-case nil
	(progn
	  (nnheader-insert-file-contents file)
	  (goto-char (point-min))
	  (let ((alist (read (current-buffer)))
		(version (condition-case nil (read (current-buffer))
			   (end-of-file 0)))
		changed-version)

	    (cond
	     ((= version 0)
	      (let ((inhibit-quit t)
		    entry)
		(gnus-agent-open-history)
		(set-buffer (gnus-agent-history-buffer))
		(goto-char (point-min))
		(while (not (eobp))
		  (if (and (looking-at
			    "[^\t\n]+\t\\([0-9]+\\)\t\\([^ \n]+\\) \\([0-9]+\\)")
			   (string= (match-string 2)
				    gnus-agent-read-agentview)
			   (setq entry (assoc (string-to-number (match-string 3)) alist)))
		      (setcdr entry (string-to-number (match-string 1))))
		  (forward-line 1))
		(gnus-agent-close-history)
		(setq changed-version t)))
	     ((= version 1)
	      (setq changed-version (not (= 1 gnus-agent-article-alist-save-format))))
	     ((= version 2)
	      (let (state sequence uncomp)
		(while alist
		  (setq state (caar alist)
			sequence (inline (range-uncompress (cdar alist)))
			alist (cdr alist))
		  (while sequence
		    (push (cons (pop sequence) state) uncomp)))
		(setq alist (sort uncomp #'car-less-than-car)))
	      (setq changed-version (not (= 2 gnus-agent-article-alist-save-format)))))
	    (when changed-version
	      (let ((gnus-agent-article-alist alist))
		(gnus-agent-save-alist gnus-agent-read-agentview)))
	    alist))
      ((end-of-file file-error)
       ;; The agentview file is missing.
       (condition-case nil
	   ;; If the agent directory exists, attempt to perform a brute-force
	   ;; reconstruction of its contents.
	   (let* (alist
		  (file-name-coding-system nnmail-pathname-coding-system)
		  (file-attributes (directory-files-and-attributes
				    (gnus-agent-article-name
				     "" gnus-agent-read-agentview)
				    nil "\\`[0-9]+\\'" t)))
	     (while file-attributes
	       (let ((fa (pop file-attributes)))
		 (unless (file-attribute-type (cdr fa))
		   (push (cons (string-to-number (car fa))
			       (time-to-days
				(file-attribute-access-time (cdr fa))))
			 alist))))
	     alist)
	 (file-error nil))))))