classpathx-javamail
[Top][All Lists]
Advanced

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

Re: [Classpathx-javamail] Folder objects sharing same folder


From: Chris Burdess
Subject: Re: [Classpathx-javamail] Folder objects sharing same folder
Date: Thu, 30 Aug 2007 22:48:01 +0100
User-agent: Mutt/1.3.28i

foo wrote:
> I am trying to append messages to an IMAP folder. My IMAP server, for some 
> reason, does not allow appending messages to a folder that is opened 
> read-only
> 
> If I do the following code:
> 
> Folder f = store.getFolder("foo");
> f.appendMessages(msgs);
> 
> It succeeds, because you can append messages to a closed folder.
> 
> If I do the following code:
> 
> Folder f = store.getFolder("foo");
> f.open(Folder.READ_ONLY);
> f.appendMessages(msgs);
> 
> It fails, because you cannot append messages to a folder opened read-only.
> 
> But if I create another Folder object which points to the same folder 
> without opening it, it still fails:
> 
> Folder f = store.getFolder("foo");
> f.open(Folder.READ_ONLY);
> Folder g = store.getFolder("foo");
> g.appendMessages(msgs);
> 
> Even though the Folder object "g" has not been "opened". Is this because 
> they both share the same connection or something?

The IMAP server doesn't have a concept of folder object references. It
just refers to the folders by name. So once you have opened the folder
"foo" it becomes the current open folder, whether or not your code
refers to f or g. This will generally be true of most mail folder
implementations.

> How do I work around this?

Generally the idea is that appendMessages works ith a folder that is not
the current folder you're working with. So you have references to
folders f and g by name (different names). Open f. Fetch some messages.
Append them to g. Close f.

This is the general algorithm you'd be using if you were developing a
mail user agent. I can see that there might be problems if you're just
using JavaMail in a more abstract sense. It might be worthwhile bringing
up your issues on the javamail-interest mailing list if this concerns
you.
-- 
Chris Burdess




reply via email to

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