+1 vote

I am reading via IMAP from outlook.com

The first time I read I assume a lngLastReadUID of 0

 uids = m_imap.Search().Where(Expression.UID(Range.From(lngLastReadUID + 1)))

This gets me 18 emails, the uid of the last one is 100055

The next time I read, I read with lngLastReadUID of 100055

However the .Search call above returns 1 email, uid value 100055 even though I am passing in (lngLastReadUID + 1)

What am I missing - I was not expecting any new emails

by (260 points)
edited by

1 Answer

+1 vote

I know this is counter-intuitive but this is how IMAP works.

Expression.UID(Range.From(lastUID + 1))) issues the following query to the IMAP server:

20719a6078e94aeb UID SEARCH RETURN (ALL) UID 33548:*

33548:* is a range. For example 1:3 is range of three numbers: 1,2,3. As the order of the range endpoints is not important, 3:1 also represents 3 numbers: 1,2,3.

33548:* means a range between 33548 and the last UID, but it also represents a range between the last UID and 33548.

When 33548 is greater than the last uid in the folder (for example 101), this query represents all numbers from * (last uid) to 33548, which includes the last UID (101).

RFC 3501:

Also note that a UID range of 559:* always includes the UID of the
last message
in the mailbox, even if 559 is higher than any assigned
UID value. This is because the contents of a range are independent of
the order of the range endpoints.

The workaround is to simply remove the lngLastReadUID from the list:

uids.Remove(lngLastReadUID );
by (301k points)
edited by
Yes. Counter intuitive, but I think I understand the model now. Thanks.
...