all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Andrew Cohen <acohen@ust.hk>
To: emacs-devel@gnu.org
Subject: Re: Synchronize Gnus and IMAP's notion of read mail
Date: Sat, 22 Jun 2024 18:59:07 +0800	[thread overview]
Message-ID: <87jzihjlac.fsf@ust.hk> (raw)
In-Reply-To: jwvle2yypaf.fsf-monnier+emacs@gnu.org

>>>>> "SM" == Stefan Monnier <monnier@iro.umontreal.ca> writes:

    SM> Apparently there's a bug in Gnus which causes it to sometimes
    SM> fail to tell IMAP that some messages are "read" (or maybe it
    SM> causes some messages to be re-set to "unread"?  I don't know).

    SM> In any case, what I do know is that what my IMAP server
    SM> considers as "read" is not the same as what Gnus thinks, even
    SM> though I basically never access my IMAP server via anything else
    SM> than Gnus.

    SM> I have not yet figured out how/why this happens, but instead I'm
    SM> wondering how I can fix the consequence of the bug by
    SM> re-synchronize Gnus with IMAP.

    SM> I know how to get Gnus to forget its own notion of "read" and
    SM> (re)fetch all that info from IMAP.  But I'd like to do the
    SM> reverse: have Gnus tell IMAP which messages should be considered
    SM> "read" and which not (of course, being careful not to affect
    SM> those messages which Gnus hasn't seen yet).  E.g. something like
    SM> have Gnus go through all the messages that IMAP say are "unread"
    SM> and mark them (in IMAP) as "read" if Gnus thinks they've already
    SM> been "read".

WARNING! WARNING! Messing with message marks can be dangerous (that is,
you might lose your marks).  I can suggest how to do this (although I
haven't tested it). I would suggest testing on smallish groups where
losing the marks wouldn't be too painful.

The main thing you need is 'gnus-request-set-mark which allows you to
manipulate the marks in the backend. So here is a function (untested)
that takes a list of marks (defaulting to 'read) and installs gnus' current
vision of those marks into the backend, for the messages that gnus knows
about. It does this by deleting the mark from all messages that gnus
knows about, and then setting it for those messages gnus thinks should
have the mark. If there are messages that gnus doesn't know about they
won't be affected (at least this is what SHOULD happen, since the
actions use an explicit list of message UIDS, which can only include
those that gnus knows about).

(defun gnus-override-group-marks (group &optional marks)
  "Store gnus marks for GROUP in the backend.
If the list MARKS is non-nil, set these specific marks; otherwise set
only read and unread status."
  (let ((marks (or marks '(read)))
        (active (gnus-active group))
        (info-marks (gnus-info-marks (gnus-get-info group)))
        action)
    (dolist (mark marks)
      (if (eq mark 'read)
          (push (list (gnus-info-read (gnus-get-info group))
                      'add (list mark)) action)
        (push (list (cdr (assq mark info-marks)) 'add (list mark))  action)))
     ;; wipe out existing marks
    (gnus-request-set-mark group (list (list active 'del marks)))
    ;; add gnus version of marks
    (gnus-request-set-mark group action)))

If you want to know what the imap server thinks the marks are you can do
this (replace server and group with your values):

(mapcar (lambda (n) (elt n 1))
    (gnus-search-run-query '((search-query-spec (query . "not mark:read"))
                                      (search-group-spec ("server" "group")))))

(remove the "not" to find what the imap server thinks are the read articles).

Best,
Andy
-- 
Andrew Cohen




  parent reply	other threads:[~2024-06-22 10:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-21 21:21 Synchronize Gnus and IMAP's notion of read mail Stefan Monnier
2024-06-22  6:59 ` Eli Zaretskii
2024-06-22 10:59 ` Andrew Cohen [this message]
2024-06-23  0:04   ` Björn Bidar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87jzihjlac.fsf@ust.hk \
    --to=acohen@ust.hk \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.