+(defun spam-necessary-extra-headers ()
+ "Return the extra headers spam.el thinks are necessary."
+ (let (list)
+ (when (or spam-use-spamassassin
+ spam-use-spamassassin-headers
+ spam-use-regex-headers)
+ (push 'X-Spam-Status list))
+ list))
+
+(defun spam-user-format-function-S (headers)
+ (when headers
+ (spam-summary-score headers)))
+
+(defun spam-article-sort-by-spam-status (h1 h2)
+ "Sort articles by score."
+ (let (result)
+ (dolist (header (spam-necessary-extra-headers))
+ (let ((s1 (spam-summary-score h1 header))
+ (s2 (spam-summary-score h2 header)))
+ (unless (= s1 s2)
+ (setq result (< s1 s2))
+ (return))))
+ result))
+
+(defun spam-extra-header-to-number (header headers)
+ "Transform an extra header to a number."
+ (if (gnus-extra-header header headers)
+ (cond
+ ((eq header 'X-Spam-Status)
+ (string-to-number (gnus-replace-in-string
+ (gnus-extra-header header headers)
+ ".*hits=" "")))
+ (t nil))
+ nil))
+
+(defun spam-summary-score (headers &optional specific-header)
+ "Score an article for the summary buffer, as fast as possible.
+With SPECIFIC-HEADER, returns only that header's score.
+Will not return a nil score."
+ (let (score)
+ (dolist (header
+ (if specific-header
+ (list specific-header)
+ (spam-necessary-extra-headers)))
+ (setq score
+ (spam-extra-header-to-number header headers))
+ (when score
+ (return)))
+ (or score 0)))
+