I'm trying to have an email-processing Java application move all processed mails from an IMAP inbox to a subfolder. If that subfolder does not exist, it should create it. This last bit is what doesn't work.
The code snippet is:
private void _backupMessage(Message msg, Folder folder, String sBackupFolderName) throws MessagingException
{
Folder backupFolder = folder.getFolder(sBackupFolderName);
if (!backupFolder.exists()) {
boolean f = backupFolder.create(Folder.HOLDS_FOLDERS & Folder.HOLDS_MESSAGES);
if (!f) {
this._triggerFaultEvent(new RuntimeException("Could not create backup folder."));
}
}
backupFolder.open(Folder.READ_WRITE);
folder.copyMessages(new Message[] { msg }, backupFolder);
backupFolder.close(true);
}
The corrsponding Javadoc is here, but it really doesn't say anything except that if create() returns false
, the folder wasn't created (surprise, surprise).
I was able to create the folder using Thunderbird with the same account.
My email server (Postfix) didn't show any log entries, except where it couldn't find the new folder. In the corresponding unit test, the mock email server (GreenMail) either works or ignores the command, in any case, the test passes.