Subject: bug#21071: Gnus message flags must be set before expiration, not afterwards

From: Nikolaus Rath <[email-masked]>
Date: Tue, 06 Oct 2015 14:03:12 -0700

Hello,

This issue is caused by article expiry being done in
gnus-summary-prepare-exit-hook. gnus-summary-exit calls this hook before
calling gnus-update-read-articles (which sets the read mark).

A trivial patch is to invert the order:

#V+
diff --git a/lisp/gnus-sum.el b/lisp/gnus-sum.el
index 37a707e..56406d0 100644
--- a/lisp/gnus-sum.el
+++ b/lisp/gnus-sum.el
@@ -7252,7 +7252,6 @@ If FORCE (the prefix), also save the .newsrc file(s)."
        (gnus-score-adaptive))
       (when gnus-use-scoring
        (gnus-score-save)))
-    (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
     (when gnus-use-cache
       (gnus-cache-possibly-remove-articles)
       (gnus-cache-save-buffers))
@@ -7269,6 +7268,7 @@ If FORCE (the prefix), also save the .newsrc file(s)."
     (unless quit-config
       (gnus-run-hooks 'gnus-exit-group-hook)
       (gnus-summary-update-info))
+    (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
     (gnus-close-group group)
     ;; Make sure where we were, and go to next newsgroup.
     (when (buffer-live-p (get-buffer gnus-group-buffer))
#V-

I did not find any specific guarantees on when
gnus-summary-prepare-exit-hook is called in the documentation, but that
doesn't mean that people are not relying on the current calling
order. Would a change like that nevertheless be acceptable?

Alternatively, is what do people think about removing
gnus-summary-expire-articles from the default value of
gnus-summary-prepare-exit-hook and explicitly calling
gnus-summary-expire-articles from gnus-summary-exit?

Best,
-Nikolaus

-- 
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             »Time flies like an arrow, fruit flies like a Banana.«