added possibility to limit the amount of emails to be read

This commit is contained in:
jomu
2017-07-05 08:07:15 +00:00
parent e391fe8791
commit 94073b43b3
2 changed files with 48 additions and 0 deletions

View File

@ -308,6 +308,43 @@ public abstract class DefaultMailReader implements MailReader {
return returnValue;
}
/**
* retrieves the list of messages stored in the given folder
*
* @param sourceFolder the folder to search return the emails for
* @param start the number of the first message
* @param end the number of the last message
* @return list of messages stored in the given folder
*
* @throws MailReaderException if the message list cannot be retrieved
*
*/
@Override
public List<MailMessage> getMessages(String sourceFolder, int start, int end) throws MailReaderException {
List<MailMessage> returnValue = new LinkedList<>();
Folder folder = getFolderObject(sourceFolder);
try {
folder.open(Folder.READ_ONLY);
Message[] messages = folder.getMessages(start, end);
for (Message msg : messages) {
returnValue.add(MailMessageUtils.getInstance(getValidMessage(msg)));
}
} catch (Exception ex) {
throw new MailReaderException("Cannot fetch email from folder " + folder.getFullName() + ". Reason: " + ex.getMessage(), ex);
} finally {
if ((folder != null) && (folder.isOpen())) {
try {
folder.close(false);
} catch (MessagingException ex) {
LOGGER.debug(StringUtil.getStackTraceString(ex));
}
}
}
return returnValue;
}
/**
* copies the given message from the source folder to the destination folder
*

View File

@ -71,6 +71,17 @@ public interface MailReader {
*/
List<MailMessage> getMessages(String folder) throws MailReaderException;
/**
* retrieves the list of messages stored in the given folder
*
* @param folder the folder to search return the emails for
* @return list of messages stored in the given folder
*
* @throws MailReaderException if the message list cannot be retrieved
*
*/
List<MailMessage> getMessages(String folder, int start, int end) throws MailReaderException;
/**
* copies the given message from the source folder to the destination folder
*