Reputation: 350
I'm trying to retrieve messages from a specific date using IMAP. (Yahoo mailbox ) This line should give me back nothing cause there are no new emails from this moment:
Message[] mlist = inbox.search(new ReceivedDateTerm(ComparisonTerm.GT, new Date()));
But insted it returns all of the messages in the folder Inbox. Anyone now how fix it? I have tried every example I have found online and nothing worked so far... I don't want to go over mail by mail and check the received date...
Thanks
Upvotes: 0
Views: 847
Reputation: 9
I may be a little late, but I hope this will be helpful for someone else :
private SearchTerm getDate(){
Date yesterdayDate = new Date(new Date().getTime() - (1000 * 60 * 60 * 24));
return new ReceivedDateTerm(ComparisonTerm.GT, yesterdayDate);
}
private FetchProfile getFetchProfile() {
FetchProfile fetchProfile = new FetchProfile();
fetchProfile.add(FetchProfileItem.ENVELOPE);
fetchProfile.add(FetchProfileItem.CONTENT_INFO);
fetchProfile.add("X-mailer");
return fetchProfile;
}
and in your main method
Store store = getImapStore(email, password);
Folder folder = getFolderFromStore(store, "INBOX");
Message[] messages = folder.search(getDate());
folder.fetch(messages, getFetchProfile());
Upvotes: 0
Reputation: 29961
Do you have any messages received today? If so, you're probably running into this bug, plus the fact that IMAP date comparisons only consider the day, not the time. You can try the JavaMail 1.5.3 SNAPSHOT release, which fixes that bug. If that's not the problem, please post the debug output when this problem occurs, along with the received dates of messages in your folder.
Upvotes: 3