Function: gnus-score-headers

gnus-score-headers is an autoloaded and byte-compiled function defined in gnus-score.el.gz.

Signature

(gnus-score-headers SCORE-FILES &optional TRACE)

Source Code

;; Defined in /usr/src/emacs/lisp/gnus/gnus-score.el.gz
(defun gnus-score-headers (score-files &optional trace)
  ;; Score `gnus-newsgroup-headers'.
  (let (scores news)
    ;; PLM: probably this is not the best place to clear orphan-score
    (setq gnus-orphan-score nil
	  gnus-scores-articles nil
	  gnus-scores-exclude-files nil
	  scores (gnus-score-load-files score-files))
    (setq news scores)
    ;; Do the scoring.
    (while news
      (setq scores news
	    news nil)
      (when (and gnus-summary-default-score
		 scores)
	(let* ((entries gnus-header-index)
	       (now (time-to-days nil))
	       (expire (and gnus-score-expiry-days
			    (- now gnus-score-expiry-days)))
	       (headers gnus-newsgroup-headers)
	       (current-score-file gnus-current-score-file)
	       entry header new)
	  (gnus-message 7 "Scoring...")
	  ;; Create articles, an alist of the form `(HEADER . SCORE)'.
	  (while (setq header (pop headers))
	    ;; WARNING: The assq makes the function O(N*S) while it could
	    ;; be written as O(N+S), where N is (length gnus-newsgroup-headers)
	    ;; and S is (length gnus-newsgroup-scored).
	    (unless (assq (mail-header-number header) gnus-newsgroup-scored)
	      (setq gnus-scores-articles ;Total of 2 * N cons-cells used.
		    (cons (cons header (or gnus-summary-default-score 0))
			  gnus-scores-articles))))

	  (with-current-buffer (gnus-get-buffer-create "*Headers*")
	    (buffer-disable-undo)
	    (when (gnus-buffer-live-p gnus-summary-buffer)
	      (message-clone-locals gnus-summary-buffer))

	    ;; Set the global variant of this variable.
	    (setq gnus-current-score-file current-score-file)
	    ;; score orphans
	    (when gnus-orphan-score
	      (setq gnus-score-index
		    (nth 1 (assoc "references" gnus-header-index)))
	      (gnus-score-orphans gnus-orphan-score))
	    ;; Run each header through the score process.
	    (while entries
	      (setq entry (pop entries)
		    header (nth 0 entry)
		    gnus-score-index (nth 1 (assoc header gnus-header-index)))
	      (when (< 0 (apply #'max (mapcar
				       (lambda (score)
					 (length (gnus-score-get header score)))
				       scores)))
		(when (if (and gnus-inhibit-slow-scoring
			       (or (eq gnus-inhibit-slow-scoring t)
				   (and (stringp gnus-inhibit-slow-scoring)
					;; Always true here?
					;; (stringp gnus-newsgroup-name)
					(string-match
					 gnus-inhibit-slow-scoring
					 gnus-newsgroup-name)))
			       (> 0 (nth 1 (assoc header gnus-header-index))))
			  (progn
			    (gnus-message
			     7 "Scoring on headers or body skipped.")
			    nil)
			;; Run score-fn
			(if (eq header 'score-fn)
			    (setq new (gnus-score-func scores trace))
			  ;; Call the scoring function for this type of "header".
			  (setq new (funcall (nth 2 entry) scores header
					     now expire trace))))
		  (push new news))))

	    (when (gnus-buffer-live-p gnus-summary-buffer)
	      (let ((scored gnus-newsgroup-scored))
		(with-current-buffer gnus-summary-buffer
		  (setq gnus-newsgroup-scored scored))))
	    ;; Remove the buffer.
	    (gnus-kill-buffer (current-buffer)))

	  ;; Add articles to `gnus-newsgroup-scored'.
	  (while gnus-scores-articles
	    (when (or (/= gnus-summary-default-score
			  (cdar gnus-scores-articles))
		      gnus-save-score)
	      (push (cons (mail-header-number (caar gnus-scores-articles))
			  (cdar gnus-scores-articles))
		    gnus-newsgroup-scored))
	    (setq gnus-scores-articles (cdr gnus-scores-articles)))

	  (let (score)
	    (while (setq score (pop scores))
	      (while score
		(when (consp (caar score))
		  (gnus-score-advanced (car score) trace))
		(pop score))))

	  (gnus-message 7 "Scoring...done"))))))