On Thu, 21 Feb 2003, Timo Sirainen wrote:
> I'd like to know how you can make a client efficiently handle sequence
> numbers. If internal message structure contains just the sequence
> number, it has to be updated every time an older message is deleted.

An obvious structure is a vector of pointers to a msgstruct, indexed by
sequence number.  All you have to do for EXPUNGE is byte-blat the pointers
down; that's a memmove() which some processors implement in hardware.

You don't have to do the blat to EXPUNGE based upon UIDs, but you have to
have some sort of hash based on UID to locate the msgstruct.  Locating a
msgstruct is a much more common operation than expunging one.

There's also the big cost of fetching the UID map at session startup,
which is completely unnecessary unless you have a local cache of the
mailbox state.

> I see sequence numbers useful only when you know you want to fetch
> exactly n messages, and even that doesn't work if some of those messages
> just happened to get deleted.

Nope.  You missed the part in which a server can't do untagged expunges
except at certain well-defined points.

> Actually in some situations relying on sequence numbers could even lose
> messages. Suppose a client (maybe a webmail) showing messages 1..10 on
> screen. Next-button would load the next 10. If the IMAP connection got
> closed before next-button was clicked and some of those messages were
> expunged before connection was up again, fetching 10..20 would have
> skipped over some of the unread messages.

Ah, you're assuming a stupid webmail client which continually reopens new
IMAP sessions for the same webmail session.  Fortunately, there is such a
thing as good quality webmail clients which keep a single IMAP session
open throughout the webmail session.

And guess what!  Those good quality webmail clients scream in performance
compared to the stupid ones.

> Also, the on-demand loading on scrolling works only if mailbox is
> unsorted. With server side sorting/threading you could use UIDs just as
> well.

You can do the same thing with message sequence numbers, and consume less
bandwidth since sequence numbers are smaller than UIDs.

> I really don't see when/why sequences are so much better than UIDs.

Unlike UIDs, you know exactly how many messages are in a sequence, even if
you currently have no information about any of those messages in the
client state.

With UIDs, you have to download the UID map, which for a moderate to large
mailbox (e.g. 5000 messages) is a substantial amount of data.  It will
kill you unless you have a fast network.  Try it over CDPD (packet IP over
cellular) sometime.

-- Mark --

http://staff.washington.edu/mrc
Science does not emerge from voting, party politics, or public debate.

Reply via email to