Donald Jansen
Donald Jansen

Reputation: 1985

Imap Command Getting Confused

I am pulling a bunch of emails using Imap Commands so my process would be like follow

A6 UID FETCH 960 (FLAGS UID BODY[])
* 3 FETCH (UID 960 FLAGS (\\Seen) BODY[] {22655}
A6 OK UID completed

above is what I get 99% of the time and the message is received successfully

But then there are the 1% like the following

A72 UID FETCH 963 (FLAGS UID BODY[])
 * 7670 FETCH (FLAGS () UID 10667)

These messages I cannot read, they fail

If I do the following

    while (!sizeLine.Contains("BODY"))
    {
        sizeLine = ReadLine();
    }

I would get results like this example

A201 UID FETCH 1649 (FLAGS UID BODY[])
* 7670 FETCH (FLAGS () UID 10667) <--- why ?
* 7674 FETCH (FLAGS () UID 10671) <--- why ?
* 198 FETCH (UID 1649 FLAGS (\\Seen) BODY[] {22386} <--- this is what I expected

So there is a work around but not sure if it is correct ?

Upvotes: 0

Views: 61

Answers (1)

arnt
arnt

Reputation: 9685

IMAP is a cache fill protocol. Yous client is assumed to have a cache, and when something is missing from the cache you tell the server what you need, and the server sends you things to cache.

Note that the server may send you things to cache for reasons other than "you asked for this". The most common other reasons are "some new mail arrived" and "someone else read/deleted some mail".

The server's OK means "I've sent you all the stuff you asked for" and maybe the server has also sent you some more.

In this case, the server sent you three things: "The flags for UID 10667 are now an empty list", "The flags for UID 10671 are now an empty list" and the one you asked for. The usual reason to send flag updates is that many/most clients display those, for example some display the subjects of unseen mail in boldface. It doesn't matter. The server is trying to be helpful and doesn't know whether it actually helps you.

Upvotes: 3

Related Questions