Function: nnmh-update-gnus-unreads

nnmh-update-gnus-unreads is a byte-compiled function defined in nnmh.el.gz.

Signature

(nnmh-update-gnus-unreads GROUP)

Source Code

;; Defined in /usr/src/emacs/lisp/gnus/nnmh.el.gz
(defun nnmh-update-gnus-unreads (group)
  ;; Go through the .nnmh-articles file and compare with the actual
  ;; articles in this folder.  The articles that are "new" will be
  ;; marked as unread by Gnus.
  (let* ((dir nnmh-current-directory)
	 (files (sort (mapcar #'string-to-number
			      (directory-files nnmh-current-directory
					       nil "\\`[0-9]+\\'" t))
		      #'<))
	 (nnmh-file (concat dir ".nnmh-articles"))
	 new articles)
    ;; Load the .nnmh-articles file.
    (when (file-exists-p nnmh-file)
      (setq articles
	    (let (nnmh-newsgroup-articles)
	      (ignore-errors (load nnmh-file nil t t))
	      nnmh-newsgroup-articles)))
    ;; Add all new articles to the `new' list.
    (let ((art files))
      (while art
	(unless (assq (car art) articles)
	  (push (car art) new))
	(setq art (cdr art))))
    ;; Remove all deleted articles.
    (let ((art articles))
      (while art
	(unless (memq (caar art) files)
	  (setq articles (delq (car art) articles)))
	(setq art (cdr art))))
    ;; Check whether the articles really are the ones that Gnus thinks
    ;; they are by looking at the time-stamps.
    (let ((arts articles)
	  art)
      (while (setq art (pop arts))
	(when (not (equal
		    (file-attribute-modification-time
		     (file-attributes (concat dir (int-to-string (car art)))))
		    (cdr art)))
	  (setq articles (delq art articles))
	  (push (car art) new))))
    ;; Go through all the new articles and add them, and their
    ;; time-stamps, to the list.
    (setq articles
	  (nconc articles
		 (mapcar
		  (lambda (art)
		    (cons art
			  (file-attribute-modification-time
			   (file-attributes
			    (concat dir (int-to-string art))))))
		  new)))
    ;; Make Gnus mark all new articles as unread.
    (when new
      (gnus-make-articles-unread
       (gnus-group-prefixed-name group (list 'nnmh ""))
       (setq new (sort new #'<))))
    ;; Sort the article list with highest numbers first.
    (setq articles (sort articles (lambda (art1 art2)
				    (> (car art1) (car art2)))))
    ;; Finally write this list back to the .nnmh-articles file.
    (with-temp-file nnmh-file
      (insert ";; Gnus article active file for " group "\n\n")
      (insert "(setq nnmh-newsgroup-articles '")
      (gnus-prin1 articles)
      (insert ")\n"))))