Possible bug while fetching on date.

Dec 14, 2011 at 12:14 PM
Edited Dec 14, 2011 at 12:14 PM


While using the code below, some mails sent that day won't show up, unless I check for DateTime.Now.AddDays(1). Is this a bug or am I doing it wrong?
client.Security = Security.SecurityPolicies.Explicit;
client.Connect("imap.gmail.com", ImapPorts.Ssl);
client.Authenticate("evomailtest@gmail.com", "*********", Security.Authentication.SaslMechanics.Login);
//var query = client.Messages.Where(x => x.Date < DateTime.Now.AddDays(1)).Select( <--- works
var query = client.Messages.Where(x => x.InternalDate < DateTime.Now).Select(
    x => new Container()
        Envelope = x.Envelope,
        BodyStructure = x.BodyStructure,
        Date = x.Date,
        InternalDate = x.InternalDate
var message = query.ToList();
int i = 1;

Dec 15, 2011 at 12:30 PM

Well, this is a tricky.

I am unsure if this is by choice or by accident, but you check against two different dates. The first query checks vs the date header and the second one checks vs he internal date. The date header is set by the sender's client, which means if someone from spain sends a mail to someone in spain, the time zone's will match.
The internal date however is the date the server registered the message in it's own timezone. If the server is located in a different time zone you will need to adjust for the difference. You could compare the internal dates with the date header and see if there is a diference.