users@javamail.java.net

removing attachments from locally stored message

From: <xoot123_at_yahoo.it>
Date: Mon, 29 Apr 2013 19:33:00 +0100 (BST)

Hello,
My application offers the possibility to save emails from IMAP accounts to a local database.
Later on, the user can remove the attachments from those saved messages, with two options:
a) remove the original message;
b) keep the original message.

The whole original message is saved locally, meaning that an OutputStream
is used to write the message (writeTo()) to it and from that an
InputStream is obtained that populates a BLOB column.

The problem is, in case (b) I can only create a MimeMessage from the saved stream, with new MimeMessage(null, myInputStream).
The new message is passed to a method that removes all its attachments.
I saw that when removing the attachments (and precisely when
saveChanges() is called) all the MimeMessage internal stream references
are nullified, so that a call to getSize() returns -1.

Since I need to store the message size on the database, along with other
informations, the only solutions I found to make JavaMail give me that
is to create a new MimeMessage from the attachments-removed MimeMessage.

So, to sum it up: <database column> -> msg = new MimeMessage(null, myIS) -> removeAttachments(msg) -> newMsg = new MimeMessage(null, msg).

Are all those steps necessary or is there a more efficient way to do this?



Thank you.
M. R.