Re: Which application uses GNU JavaMail ?
Cedric Hyppolite <[email protected]> Sat, 11 Feb 2006 21:06:16 +0100
| Newsgroups | gmane.comp.java.classpath.extensions.discuss |
|---|---|
| Message-ID | <[email protected]> |
Chris,
The exception is thrown on the indicated line:
in getSharedNamespaces (IMAPStore.java)
try
{
Namespaces ns =3D connection.namespace();
if (ns =3D=3D null)
{
throw new MethodNotSupportedException("IMAP =20
NAMESPACE " +
"command not =20
supported");
}
Namespaces.Namespace[] n =3D ns.getShared();
--> Folder[] f =3D new Folder[n.length];
for (int i =3D 0; i < n.length; i++)
{
String prefix =3D n[i].getPrefix();
char delimiter =3D n[i].getDelimiter();
f[i] =3D new IMAPFolder(this, prefix, delimiter);
}
return f;
}
catch (IOException e)
{
throw new MessagingException(e.getMessage(), e);
}
I modified the code not to open the folder. Now I start to see some =20
IMAP folders. However it seems that listing of a non default folder =20
returns itself as subfolder. Which make the recursive listing of =20
folders enter a loop.
Here is a test that could show the loop, if you want to try it.
This may be solved in the CVS_HEAD version that I will check ASAP. =20
Could you give me the cvs server connection info and the module list ?
Thanks,
Cedric
--------
private Store connect() throws MessagingException {
=09
Properties props =3D new Properties();
Store store;
Session session;
session =3D Session.getDefaultInstance(props, null);
=09
session.setDebug(true);
store =3D session.getStore("imap");
store.connect(host, username, password);
return store;
}
private void listSubFolders(Folder folder, boolean recurse) =
throws =20
MessagingException {
System.out.println("Folder " + folder.getFullName() + " =
type is " + =20
folder.getType());
if ((folder.getType() & Folder.HOLDS_FOLDERS) =3D=3D 0) =
{
=09
System.out.println("Folder " + =
folder.getFullName() + " cannot =20
contain subfolders.");
return;
}
System.out.println("Listing sub folders of " + =
folder.getFullName());
listFolders(folder.list(), recurse);
} =09
=09
private void listFolders(Folder[]array, boolean recurse) throws =20=
MessagingException {
for (int i =3D 0 ; i < array.length ; i++) {
Folder folder =3D array[i];
System.out.println("Found folder " =
+folder.getFullName());
if (recurse) {
listSubFolders(folder, recurse);
}
}
}
=09
=09
public void testFolderList() throws MessagingException {
Store store =3D connect();
Folder folder =3D store.getDefaultFolder();
listSubFolders(folder, true);
}
Le 11 f=C3=A9vr. 06 =C3=A0 19:49, Chris Burdess a =C3=A9crit :
> Cedric Hyppolite wrote:
>> Here is a test that shows the issues and the log. I cut the =20
>> irrelevant part of the stack trace.
>> I ran this test under MacOSX with Eclipse compiler and SUN JVM 1.4.2.
>
> See my comments below.
>
>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D TestCase =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D
>> import java.util.Properties;
>>
>> import javax.mail.Folder;
>> import javax.mail.MessagingException;
>> import javax.mail.Session;
>> import javax.mail.Store;
>>
>> import junit.framework.TestCase;
>>
>> public class IMAPFolderTest extends TestCase {
>> public void testIMAPFolder() throws MessagingException {
>> String host =3D "XXX"; =09
>> String username =3D "XXX";
>> String password =3D "XXX";
>> =09
>> Properties props =3D new Properties();
>> Store store;
>> Session session;
>> session =3D Session.getDefaultInstance(props, null);
>> =09
>> session.setDebug(true);
>> store =3D session.getStore("imap");
>> store.connect(host, username, password);
>> System.out.println("Listing Personal namespaces");
>> try {
>> // This will succeed.
>> listFolders(store.getPersonalNamespaces());
>> if (store.getPersonalNamespaces().length > 0) {
>> =
listSubFolders(store.getPersonalNamespaces()[0]);
>> }
>> } catch (Exception e) {
>> System.err.println("Error getting personal =
namespaces");
>> e.printStackTrace(); =09
>> }
>>
>> System.out.println("Listing Shared namespaces");
>> try {
>> // This will fail.
>> listFolders(store.getSharedNamespaces());
>> } catch (Exception e) {
>> System.err.println("Error getting shared =
namespaces");
>> e.printStackTrace(); =09
>> }
>
> I'm not sure what's going on with getSharedNamespaces as your =20
> stacktrace doesn't show line numbers that correspond to CVS HEAD - =20
> perhaps you could try with an up-to-date version and let me know =20
> the result?
>
>> =09
>> System.out.println("Listing User namespaces");
>> try {
>> // This will succeed.
>> listFolders(store.getUserNamespaces(username));
>> } catch (Exception e) {
>> System.err.println("Error getting user =
namespaces");
>> e.printStackTrace(); =09
>> }
>> =09
>> Folder folder =3D null;
>> try {
>> // This will fail.
>> folder =3D store.getDefaultFolder();
>> folder.open(Folder.READ_ONLY);
>> listSubFolders(folder);
>> folder.close(false);
>> } catch (MessagingException e){
>> System.err.println("Failed to open default =
folder as read-only");
>> e.printStackTrace(); =09
>> }
>>
>> try {
>> // This will fail.
>> folder =3D store.getDefaultFolder();
>> folder.open(Folder.READ_WRITE);
>> listSubFolders(folder);
>> folder.close(false);
>> } catch (MessagingException e){
>> System.err.println("Failed to open default =
folder as read-write");
>> e.printStackTrace(); =09
>> }
>
> This won't work: the "default folder" is supposed to be a sort of =20
> virtual root folder that contains other folders as children =20
> (notably INBOX). It can't be opened as it contains only folders, =20
> not messages: see the API documentation for Folder.open. You can =20
> use Folder.getType to discover whether a folder contains folders, =20
> messages, or both.
>
>> try {
>> // This will fail.
>> folder =3D store.getFolder("");
>> folder.open(Folder.READ_ONLY);
>> listSubFolders(folder);
>> folder.close(false);
>> } catch (MessagingException e){
>> System.err.println("Failed to open 'empty name' =
folder as read-=20
>> only");
>> e.printStackTrace(); =09
>> }
>> try {
>> // This will fail.
>> folder =3D store.getFolder("");
>> folder.open(Folder.READ_WRITE);
>> listSubFolders(folder);
>> folder.close(false);
>> } catch (MessagingException e){
>> System.err.println("Failed to open 'empty name' =
folder as read-=20
>> write");
>> e.printStackTrace(); =09
>> }
>
> The interpretation of this is up to your mail server, but typically =20=
> an empty-name folder refers to the default folder as above.
>
>> try {
>> // This will succeed.
>> folder =3D store.getFolder("INBOX");
>> folder.open(Folder.READ_ONLY);
>> listSubFolders(folder);
>> folder.close(false);
>> } catch (MessagingException e){
>> System.err.println("Failed to open 'INBOX' =
folder as read-only");
>> e.printStackTrace();
>> }
>> try {
>> // This will succeed.
>> folder =3D store.getFolder("INBOX");
>> folder.open(Folder.READ_WRITE);
>> listSubFolders(folder);
>> folder.close(false);
>> } catch (MessagingException e){
>> System.err.println("Failed to open 'INBOX' =
folder as read-write");
>> e.printStackTrace();
>> }
>> }
>> =09
>> private void listSubFolders(Folder folder) throws =20
>> MessagingException {
>> System.out.println("Folder " + folder.getFullName() + " =
type is =20
>> " + folder.getType());
>> if ((folder.getType() & Folder.HOLDS_FOLDERS) =3D=3D 0) =
{
>> =09
>> System.out.println("Folder " + =
folder.getFullName() + " cannot =20
>> contain subfolders.");
>> return;
>> }
>> System.out.println("Listing sub folders of " + =
folder.getFullName=20
>> ());
>> listFolders(folder.list());
>> } =09
>> =09
>> private void listFolders(Folder[]array) {
>> for (int i =3D 0 ; i < array.length ; i++) {
>> Folder folder =3D array[i];
>> System.out.println("Found folder " =
+folder.getFullName());
>> =09
>> }
>> }
>> }
>
> --=20
> =E7=8A=AC Chris Burdess
> "They that can give up essential liberty to obtain a little safety
> deserve neither liberty nor safety." - Benjamin Franklin
>
>
>
>