added possibility to limit the amount of emails to be read
This commit is contained in:
@ -307,6 +307,43 @@ public abstract class DefaultMailReader implements MailReader {
|
|||||||
|
|
||||||
return returnValue;
|
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
|
* copies the given message from the source folder to the destination folder
|
||||||
|
|||||||
@ -70,6 +70,17 @@ public interface MailReader {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
List<MailMessage> getMessages(String folder) throws MailReaderException;
|
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
|
* copies the given message from the source folder to the destination folder
|
||||||
|
|||||||
Reference in New Issue
Block a user