Reputation: 2171
Does anyone have experience with the Javamail javax.mail.FolderClosedException
?
My problem is:
I want to read some mails, everything ok. But i've changed my reader class to a more technical class, wich only gets the Message
Objects.
In a second step i want to make beans. Getting the information like subject is very easy:
public void getMail(Message msg) {
subject = msg.getSubject();
...
}
Main problem here: msg.getContent
requires a opened folder...
but my technical reader class gets all the message objects, closes the folder...
after that my business-method getMail
does the msg.getContent
is it possible to do that in that way with a business-class and a technical class, or do i have to setup the mail-beans in the technical class and return a list of them?!
Upvotes: 1
Views: 2559
Reputation: 500
Your problem seems to be that getContent()
will load the content from the server, as the JavaMail implementation normally first begins to download the requested information, when you actually need it, e.g. by calling getContent()
.
You could kind of force to download everything completely before handing over the stuff to your business code. So, instead of handing over the message objects directly you get from your technical class, you can create a copy of them. This forces the JavaMail classes using e.g. an IMAP connection to fully download your message:
/* assuming you retrieved 'message' from your folder object */
Message copyOfMessage = new MimeMessage( (MimeMessage) message );
[..]
folder.close();
[..]
yourBusinessObject.getMail( copyOfMessage );
But I have to admit I have never tried to access the copied object after closing the folder. And also never used this with POP3. But I would give it a try.
Upvotes: 3
Reputation: 2625
How about just passing in the stuff you need, instead of the Message
instance? Like
public void getMail(String subject, Object content, ...) {
...
}
of course it's not as clean as before, but might do the trick ;)
PS: Für d'IPA, oder hesch die dure?
Upvotes: 1