originURLName.getPort(), folder, originURLName.getUsername(), originURLName.getPassword());
Map<String, Integer> folderList = new Hashtable<String, Integer>();
try {
IMAPSSLStore imapStore = new IMAPSSLStore(session, urlName);
imapStore.connect();
IMAPFolder startFolder;
if (urlName.getFile() == null) {
// There is no folder given
startFolder = (IMAPFolder) imapStore.getDefaultFolder();
} else {
startFolder = (IMAPFolder) imapStore.getFolder(urlName.getFile());
}
// Find messages (if folder exist and could be openend)
if (startFolder.exists()) {
try {
startFolder.open(Folder.READ_ONLY);
Message[] msgs = startFolder.getMessages();
for (int i = 0; i < msgs.length; i++) {
MimeMessage message = (MimeMessage) msgs[i];
// It's a message -> Add a index job
addJob(folderUrl + "/message_" + startFolder.getUID(message), folderUrl, false, true, null);
}
startFolder.close(false);
} catch (MessagingException messageEx) {
mLog.debug("Could not open folder for reading but this is not an errror. Folder URL is " + folderUrl);
}
}
// Find all subfolder
folderList = ImapToolkit.getAllFolders(startFolder, false);
// Iterate over all subfolders
for (Map.Entry<String, Integer> entry : folderList.entrySet()) {
// It's a directory -> Add a parse job
String newFolder;
if( folderUrl == null || folderUrl.length() == 0 || !folderUrl.endsWith("/")) {
newFolder = "/" + (String) entry.getKey();
} else {
newFolder = (String) entry.getKey();
}
addJob(folderUrl + newFolder, folderUrl, true, false, null);
}
imapStore.close();
} catch (Exception ex) {
throw new RegainException("Couldn't determine IMAP entries.", ex);
}
}