We are developing a java based mail client for IMAP accounts and use latest java mail api (1.5.6). Our customers have mail accounts with more than 400 folders. Users perform
Way too many questions for one post. Let me try to answer a few of them...
After you close a Folder, you shouldn't use any Message objects from the Folder, so only close the Folder when you're done using its Messages.
If a single user has 400 folders, you can use a single Store connection since each open Folder will get its own connection.
If you open and close Folders frequently, increasing the connection pool size can help since the connection for a closed Folder will be added to the pool and reused when you open a new Folder, without needing to create a new connection.
Closing the Store should close all the Folders for that Store, but there's an inherent race condition if multiple threads are involved. Closing the Store is a way to clean up all the connections when you're done using it, not a way to prevent other threads from re-opening Folders.
Caching Folder objects for closed Folders is not likely to be a big advantage over calling getFolder each time.