MBOX-Line: From arnt at gulbrandsen.priv.no  Mon Jun 15 00:03:26 2009
To: imap-protocol@u.washington.edu
From: Arnt Gulbrandsen <arnt@gulbrandsen.priv.no>
Date: Fri Jun  8 12:34:42 2018
Subject: [Imap-protocol] No DateModified or Equivalent for use with
	Disconnected Clients?
In-Reply-To: <d055a06e0906130630j25eee4e7t65cf0a6f55d263e8@mail.gmail.com>
References: <d055a06e0906130630j25eee4e7t65cf0a6f55d263e8@mail.gmail.com>
Message-ID: <IZ41S0HKP0+51NRIZpeuWA.md5@lochnagar.oryx.com>

Tom Davis writes:
> Do I understand correctly that in order to determine if any old 
> messages on the server have changed after returning from a 
> disconnected state I have to:
>
> 1) Fetch header info (flags etc.) for every single message (1 to 
> UIDLASTSEEN) in the given server mailbox
>
> 2) Compare the flags etc., with last known state of all of the 
> messages stored on the client machine
>
> ...in order to see which old messages on the server have been modified?

More or less.

RFC 4551 changes this. It's available on some servers, but it's not 
commonly deployed yet. Cyrus supports it, and a google search says 
supporting versions are is available in freebsd and gentoo. Maybe 
another google search would name other platforms, but I'm too lazy.

The code to update your flags copy is something like this:

    if server advertise condstore, then send
         UID FETCH 1:* (FLAGS) (CHANGEDSINCE 99992)
    else
         UID FETCH 1:* (FLAGS)

(That 99992 is from a per-mailbox variable you have to remember, see below.)

You will receive a FETCH response for each message you need to update. 
If you do not receive a fetch response for a particular message, then 
your flags copy for that message is correct.

If the server supports condstore, then the fetch response will have a 
modseq field:

     * 2 FETCH (UID 6 MODSEQ (99996) FLAGS (\Deleted))

If the number 99996 is larger than your per-mailbox modseq variable, 
then you update that variable.

As you can see, it's not very much code.

> Any advice appreciated.

I'd rather just answer your specific question.

Arnt

