0 votes

Hello,

We use following code to get mails from inbox

List uids = imap.Search(Flag.All); (now we get a list of 11 uids range 78-88)
But we dont get the mails order from older to newer. I send you a link to see a printscreen

http://www.cav.gr/Error-mail-order.PNG

Here you see that the order is not according to date. (in red text you see the date and uid)

Can you please help me with this

/Kind regards
Christer Vaitsis
enter image description here

by

1 Answer

0 votes

Unless your IMAP server is not following the protocol specification, UIDs are assigned by IMAP server in ascending order. That means that emails received later will have higher UID value.

Imap.Search returns UIDs ordered by value.

Now, email can have 2 dates assigned to it:

  1. "Date: " header (IMail.Date) - it is assigned by the sender, it says when email was sent. And as it is set by someone out-of-your control it may be bogus.

  2. IMAP server assigns internal date to every email it receives (Envelope.InternalDate obtained from Imap.GetMessageInfoByUID / Imap.GetEnvelopeByUID).

You can check 2nd to see if UID order matches InternalDate.

I noticed that all emails with wrong dates are invitations, maybe the problem is with the invitations sender? For example it may produce emails with broken "Date: " header (for example using invalid timezone).

by (301k points)
edited by
...