INT-2803 Fix Lazy Fetch of Email Messages

INT-2805 Update JavaMail to 1.4.5

There is a need to fetch the entire email message before the folder
is closed. Once the folder is closed, you cannot perform any
more operations on the message.

Prior to RC1, the message was copied, which forced an eager fetch.

Add code to copy the message.

Also, transaction synchronization operations need access to a folder
instance to perform operations, such as delete, on a message.

Add a wrapper to lazily create a folder instance in message.getFolder()
when needed.

Add documentation to explain that messages must be re-fetched before
performing transaction synchronization operations.

JavaMail 1.4.5 is now Open Source, which makes debugging much
easier.
This commit is contained in:
Gary Russell
2012-11-01 17:14:31 -04:00
committed by Mark Fisher
parent bc8d499054
commit 413d5354a1
5 changed files with 215 additions and 59 deletions

View File

@@ -320,15 +320,27 @@ public class Mover {
public void process(MimeMessage message) throws Exception{
Folder folder = message.getFolder();
Store store = null;
if (!folder.isOpen()){
folder.open(Folder.READ_WRITE);
store = folder.getStore();
folder.open(Folder.READ_WRITE);
String messageId = message.getMessageID();
Message[] messages = folder.getMessages();
FetchProfile contentsProfile = new FetchProfile();
contentsProfile.add(FetchProfile.Item.ENVELOPE);
contentsProfile.add(FetchProfile.Item.CONTENT_INFO);
contentsProfile.add(FetchProfile.Item.FLAGS);
folder.fetch(messages, contentsProfile);
// find this message and mark for deletion
for (int i = 0; i < messages.length; i++) {
if (((MimeMessage) messages[i]).getMessageID().equals(messageId)) {
messages[i].setFlag(Flags.Flag.DELETED, true);
break;
}
}
message.setFlag(Flags.Flag.DELETED, true);
Folder fooFolder = store.getFolder("FOO"));
fooFolder.appendMessages(new MimeMessage[]{message});
folder.expunge();
folder.close(true);
fooFolder.close(false);
}
}]]></programlisting>
<important>