0

Is there any way to download all emails that are recived between date?

i.e.:

Date from = ...
Date to = ...
Folder inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_ONLY);

Message[] messages = inbox.getMessages(from, to);
user2365209
  • 99
  • 1
  • 1
  • 9

2 Answers2

2

Use Folder#search(SearchTerm). Implement a concrete subclass of SearchTerm that overrides the SearchTerm#match(Message) method. Have it return true if the date of the Message matches what you're interested in.

Eric Stein
  • 13,209
  • 3
  • 37
  • 52
1

Use two ReceivedDateTerms and an AndTerm to search for messages where the date is between the two values. Once you have the Message objects, you can download or access whatever you need.

Bill Shannon
  • 29,579
  • 6
  • 38
  • 40
  • The IMAP protocol only supports dates with days, not times. If you need to search based on times you can use Folder.search to narrow the list down to days and then use Message.match to find messages within the specified times. The latter will be done on the client by downloading the required information for each message. – Bill Shannon Oct 09 '13 at 18:38