classpathx-javamail
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AW: [Classpathx-javamail] IllegalStateException: Folder is not Open


From: Jonathan Melhuish
Subject: Re: AW: [Classpathx-javamail] IllegalStateException: Folder is not Open
Date: Wed, 28 Jul 2004 16:38:06 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; fr-FR; rv:1.6) Gecko/20040413 Debian/1.6-5

Yay!  That fixed it... :-)

The only thing I had forgotten was Folder.close(), without which no data is actually written disk.

Now I just have to work out why POP3Message.getSender() equates to null...

Thanks,

Jon

Stephan Mikaty wrote:

The MimeMessage you retrieved from the POP3 folder is
just a proxy to the physical one located on the pop3 server.
Storing it requires that it be fetched first. If the delay
between acquiring the pop3 MimeMessage instance and reading
its data from the server is too long, the pop3 connection
might get closed. To avoid this, you need to physically fetch
the whole message shortly after acquiring the MimeMessage
instance from the pop3 provider.

My favorite way of doing this is to use the MimeMessage's copy
constructor to build a new, standalone message.

After doing this, you cand pass the message copy to storeMessage:

MimeMessage pop3Message = (message you retrived from pop3);
MimeMessage messageCopy = new MimeMessage(pop3Message);
...storeMessage(messageCopy);

Beware though, the whole message data resides in memory, so
big messages could be a problem.

Hope that helps,

Stephane

-----Ursprüngliche Nachricht-----
Von: address@hidden
[mailto:address@hidden
Im Auftrag
von Jonathan Melhuish
Gesendet: Mittwoch, 28. Juli 2004 13:01
An: address@hidden
Betreff: [Classpathx-javamail] IllegalStateException: Folder is not Open


Hi,

I'm trying to write a simple program that downloads messages from a POP3
server and writes them to disk.  I've successfully used the Sun
libraries to download the messages, but I need to use the GNU Javamail
implementation to save the messages to an Mbox file.  I couldn't find
much in the way of usage instructions or code examples (which is a
shame), but through a bit of guesswork I came up with this:

public void storeMessage(MimeMessage message) {
URLName mbox = new URLName("mbox:///home/jon/epmail/test");
           Store store = session.getStore(mbox);
           Folder root = store.getDefaultFolder();
           if(!root.exists()) root.create(Folder.HOLDS_MESSAGES);
           root.open(Folder.READ_WRITE);

           // Add message to store
           MimeMessage[] messagearray = new MimeMessage[1];
           messagearray[0] = message;
           root.appendMessages(messagearray);
           root.releaseLock();
}

When running this code, I get:

Exception in thread "main" java.lang.IllegalStateException: Folder is
not Open
   at com.sun.mail.pop3.POP3Folder.checkOpen(POP3Folder.java:414)
   at com.sun.mail.pop3.POP3Folder.getProtocol(POP3Folder.java:441)
   at com.sun.mail.pop3.POP3Message.getSize(POP3Message.java:92)
   at javax.mail.internet.MimeMessage.<init>(MimeMessage.java:189)
at gnu.mail.providers.ReadOnlyMessage.<init>(ReadOnlyMessage.java:73)
   at gnu.mail.providers.mbox.MboxMessage.<init>(MboxMessage.java:83)
at gnu.mail.providers.mbox.MboxFolder.appendMessages(MboxFolder.java:558) at com.qinetiq.dtg.email.MailClient.storeMessage(MailClient.java:150)
   at com.qinetiq.dtg.email.MainTimer.main(MainTimer.java:59)

Even though Folder.exists() returns true, Folder.isOpen() also returns
true and an empty file is created in the desired location.

The mentions of POP3Folder in the above error concerns me somewhat, but
I'm not sure where that's coming from as the argument should now be a
MimeMessage. I tried casting the MimeMessage to an MboxMessage just for
good measure, but got a ClassCastException.

If I comment out the Folder.create() line and delete the output file, Folder.exists() still returns true, but Folder.open(Folder.READ_WRITE) gives a "MessagingException: Folder is read-only". I'm not sure if this is relevant, but I can't find any meaningful documentation for Folder.create.

Anybody got any ideas?

Cheers,

Jon




_______________________________________________
Classpathx-javamail mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/classpathx-javamail



_______________________________________________
Classpathx-javamail mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/classpathx-javamail







reply via email to

[Prev in Thread] Current Thread [Next in Thread]