Reputation: 168
Im trying to get emails of a certain date from an inbox in outlook using IMAP, but im getting emails from dates that dont correspond to the date im using for my search, my code is the following:
SimpleDateFormat df1 = new SimpleDateFormat( "MM/dd/yy" );
String dt="10/02/18";
java.util.Date dDate = df1.parse(dt);
/*
Connection code to the email goes here
*/
SearchTerm st = new ReceivedDateTerm(ComparisonTerm.EQ,dDate);
IMAPFolder inbox = (IMAPFolder) store.getFolder("INBOX");
inbox.open(Folder.READ_WRITE);
Message[] messages = inbox.search(st);
int total = messages.length;
/* RESULTS */
println("\nTotal_Email = " + messages.length);
for (int index = 0; index < total; index++) {
Date date=message.getReceivedDate();
System.out.println("DATE RECEIVED="+date);
}
Im getting the following result when I use the date "10/01/18"
Total_Email = 5
DATE RECEIVED=Mon Oct 01 17:45:44 COT 2018
DATE RECEIVED=Mon Oct 01 16:43:27 COT 2018
DATE RECEIVED=Mon Oct 01 16:17:11 COT 2018
DATE RECEIVED=Mon Oct 01 15:37:38 COT 2018
DATE RECEIVED=Mon Oct 01 14:53:48 COT 2018
And then Im getting the following result when I use the date "10/02/18"
Total_Email = 6
DATE RECEIVED=Tue Oct 02 08:09:53 COT 2018
DATE RECEIVED=Mon Oct 01 23:21:34 COT 2018
DATE RECEIVED=Mon Oct 01 22:37:22 COT 2018
DATE RECEIVED=Mon Oct 01 21:33:37 COT 2018
DATE RECEIVED=Mon Oct 01 20:21:20 COT 2018
DATE RECEIVED=Mon Oct 01 19:11:50 COT 2018
My guess is that it has to do with my timezone, I live in Colombia and my timezone is GMT-5, Is there any way to fix and get the correct results ?
Upvotes: 0
Views: 893
Reputation: 10985
No, IMAP is not timezone aware, and it is server specific what timezone it computes and reports the results in. You may need to request more than you need and do client side filtering.
Most of the large multinational servers use UTC for convenience, so you'd have to fetch the two days overlapping the period you're interested in.
Upvotes: 2