]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid modifying nnimap user option in spam.el
authorBasil L. Contovounesios <contovob@tcd.ie>
Sat, 5 Dec 2020 15:28:35 +0000 (15:28 +0000)
committerBasil L. Contovounesios <contovob@tcd.ie>
Sun, 6 Dec 2020 11:45:52 +0000 (11:45 +0000)
* lisp/gnus/nnimap.el (nnimap--split-download-body): New variable.
(nnimap-fetch-inbox): Use it in conjunction with
nnimap-split-download-body.
* lisp/gnus/spam.el: Don't load nnimap.el at compile time for a
dynamic variable.
(spam-setup-widening): Rather than unconditionally set user option
nnimap-split-download-body, set nnimap--split-download-body to a
unique non-nil value only if the variable was nil (bug#44981).
(spam-teardown-widening): New function that undoes this if
nnimap--split-download-body still holds the unique value.
(spam-unload-hook): Call spam-teardown-widening to revert any change
to the value of nnimap--split-download-body.

lisp/gnus/nnimap.el
lisp/gnus/spam.el

index a8603330662d6e452e7d77f82f7b5bc2063bb6c4..c8b700ebcc6a837eb7737abe22ea09dcaadcea62 100644 (file)
@@ -157,6 +157,9 @@ during splitting, which may be slow."
   :version "28.1"
   :type 'boolean)
 
+(defvar nnimap--split-download-body nil
+  "Like `nnimap-split-download-body', but for internal use.")
+
 (defvar nnimap-process nil)
 
 (defvar nnimap-status-string "")
@@ -2108,7 +2111,8 @@ Return the server's response to the SELECT or EXAMINE command."
                 "BODY.PEEK"
               "RFC822.PEEK"))
            (cond
-            (nnimap-split-download-body
+             ((or nnimap-split-download-body
+                  nnimap--split-download-body)
              "[]")
             ((nnimap-ver4-p)
              "[HEADER]")
index 27e559d383a6cea074beaba0e621b6976738a981..e74aef3efe6a786d0777831bb2e93befdf372ba9 100644 (file)
 ;;; for the definitions of group content classification and spam processors
 (require 'gnus)
 
-(eval-when-compile (require 'hashcash))
-
-;; for nnimap-split-download-body
-(eval-when-compile (require 'nnimap))
-
-(eval-when-compile (require 'cl-lib))
+(eval-when-compile
+  (require 'cl-lib)
+  (require 'hashcash))
 
 ;; autoload query-dig
 (autoload 'query-dig "dig")
@@ -1228,10 +1225,20 @@ Will not return a nil score."
 
 ;;{{{ set up widening, processor checks
 
-;;; set up IMAP widening if it's necessary
+(defconst spam--widened (list ())
+  "Unique value identifying changes to `nnimap--split-download-body'.")
+
 (defun spam-setup-widening ()
-  (when (spam-widening-needed-p)
-    (setq nnimap-split-download-body t)))
+  "Set up IMAP widening if it's necessary."
+  (and (boundp 'nnimap--split-download-body)
+       (not nnimap--split-download-body)
+       (spam-widening-needed-p)
+       (setq nnimap--split-download-body spam--widened)))
+
+(defun spam-teardown-widening ()
+  "Tear down IMAP widening."
+  (when (eq (bound-and-true-p nnimap--split-download-body) spam--widened)
+    (setq nnimap--split-download-body nil)))
 
 (defun spam-widening-needed-p (&optional force-symbols)
   (let (found)
@@ -2865,6 +2872,7 @@ installed through `spam-necessary-extra-headers'."
 (defun spam-unload-hook ()
   "Uninstall the spam.el hooks."
   (interactive)
+  (spam-teardown-widening)
   (remove-hook 'gnus-save-newsrc-hook 'spam-maybe-spam-stat-save)
   (remove-hook 'gnus-get-top-new-news-hook 'spam-maybe-spam-stat-load)
   (remove-hook 'gnus-startup-hook 'spam-maybe-spam-stat-load)