Re: Which application uses GNU JavaMail ?

Cedric Hyppolite <[email protected]> Sat, 11 Feb 2006 13:51:31 +0100
Newsgroups gmane.comp.java.classpath.extensions.discuss
Message-ID <[email protected]>
Hi Chris,

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.

Regards,
Cedric

=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
		}
	=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
		}
		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
		}
		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 =
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());
	}	=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
		}
	}
}
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D LOG FILE =3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D
Listing Personal namespaces
Found folder ~
Folder ~ type is 2
Listing sub folders of ~
Listing Shared namespaces
Error getting shared namespaces
java.lang.NullPointerException
	at gnu.mail.providers.imap.IMAPStore.getSharedNamespaces=20
(IMAPStore.java:486)
	at org.humannetwork.net.mail.IMAPFolderTest.testIMAPFolder=20
(IMAPFolderTest.java:41)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke=20
(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke=20
(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:324)
	at junit.framework.TestCase.runTest(TestCase.java:154)
...
Listing User namespaces
Failed to open default folder as read-only
javax.mail.MessagingException: EXAMINE failed: Can't open mailbox : =20
no such mailbox;
   nested exception is:
	gnu.inet.imap.IMAPException: EXAMINE failed: Can't open mailbox =
: no =20
such mailbox
	at gnu.mail.providers.imap.IMAPFolder.open(IMAPFolder.java:357)
	at org.humannetwork.net.mail.IMAPFolderTest.testIMAPFolder=20
(IMAPFolderTest.java:59)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke=20
(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke=20
(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:324)
	at junit.framework.TestCase.runTest(TestCase.java:154)
...
nested exception is:
gnu.inet.imap.IMAPException: EXAMINE failed: Can't open mailbox : no =20
such mailbox
	at =
gnu.inet.imap.IMAPConnection.selectImpl(IMAPConnection.java:867)
	at gnu.inet.imap.IMAPConnection.examine(IMAPConnection.java:833)
	at gnu.mail.providers.imap.IMAPFolder.open(IMAPFolder.java:341)
	at org.humannetwork.net.mail.IMAPFolderTest.testIMAPFolder=20
(IMAPFolderTest.java:59)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke=20
(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke=20
(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:324)
	at junit.framework.TestCase.runTest(TestCase.java:154)
...
Failed to open default folder as read-write
javax.mail.MessagingException: SELECT failed: Can't open mailbox : no =20=

such mailbox;
   nested exception is:
	gnu.inet.imap.IMAPException: SELECT failed: Can't open mailbox : =
no =20
such mailbox
	at gnu.mail.providers.imap.IMAPFolder.open(IMAPFolder.java:357)
	at org.humannetwork.net.mail.IMAPFolderTest.testIMAPFolder=20
(IMAPFolderTest.java:70)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke=20
(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke=20
(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:324)
	at junit.framework.TestCase.runTest(TestCase.java:154)
...
nested exception is:
gnu.inet.imap.IMAPException: SELECT failed: Can't open mailbox : no =20
such mailbox
	at =
gnu.inet.imap.IMAPConnection.selectImpl(IMAPConnection.java:867)
	at gnu.inet.imap.IMAPConnection.select(IMAPConnection.java:821)
	at gnu.mail.providers.imap.IMAPFolder.open(IMAPFolder.java:338)
	at org.humannetwork.net.mail.IMAPFolderTest.testIMAPFolder=20
(IMAPFolderTest.java:70)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke=20
(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke=20
(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:324)
	at junit.framework.TestCase.runTest(TestCase.java:154)
...
Failed to open 'empty name' folder as read-only
javax.mail.MessagingException: EXAMINE failed: Can't open mailbox : =20
no such mailbox;
   nested exception is:
	gnu.inet.imap.IMAPException: EXAMINE failed: Can't open mailbox =
: no =20
such mailbox
	at gnu.mail.providers.imap.IMAPFolder.open(IMAPFolder.java:357)
	at org.humannetwork.net.mail.IMAPFolderTest.testIMAPFolder=20
(IMAPFolderTest.java:80)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke=20
(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke=20
(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:324)
	at junit.framework.TestCase.runTest(TestCase.java:154)
...
nested exception is:
gnu.inet.imap.IMAPException: EXAMINE failed: Can't open mailbox : no =20
such mailbox
	at =
gnu.inet.imap.IMAPConnection.selectImpl(IMAPConnection.java:867)
	at gnu.inet.imap.IMAPConnection.examine(IMAPConnection.java:833)
	at gnu.mail.providers.imap.IMAPFolder.open(IMAPFolder.java:341)
	at org.humannetwork.net.mail.IMAPFolderTest.testIMAPFolder=20
(IMAPFolderTest.java:80)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke=20
(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke=20
(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:324)
	at junit.framework.TestCase.runTest(TestCase.java:154)
...
Failed to open 'empty name' folder as read-write
javax.mail.MessagingException: SELECT failed: Can't open mailbox : no =20=

such mailbox;
   nested exception is:
	gnu.inet.imap.IMAPException: SELECT failed: Can't open mailbox : =
no =20
such mailbox
	at gnu.mail.providers.imap.IMAPFolder.open(IMAPFolder.java:357)
	at org.humannetwork.net.mail.IMAPFolderTest.testIMAPFolder=20
(IMAPFolderTest.java:90)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke=20
(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke=20
(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:324)
	at junit.framework.TestCase.runTest(TestCase.java:154)
...
nested exception is:
gnu.inet.imap.IMAPException: SELECT failed: Can't open mailbox : no =20
such mailbox
	at =
gnu.inet.imap.IMAPConnection.selectImpl(IMAPConnection.java:867)
	at gnu.inet.imap.IMAPConnection.select(IMAPConnection.java:821)
	at gnu.mail.providers.imap.IMAPFolder.open(IMAPFolder.java:338)
	at org.humannetwork.net.mail.IMAPFolderTest.testIMAPFolder=20
(IMAPFolderTest.java:90)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke=20
(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke=20
(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:324)
	at junit.framework.TestCase.runTest(TestCase.java:154)
...
Folder INBOX type is 0
Folder INBOX cannot contain subfolders.
Folder INBOX type is 0
Folder INBOX cannot contain subfolders.

Le 10 f=C3=A9vr. 06 =C3=A0 09:15, Chris Burdess a =C3=A9crit :

> Cedric Hyppolite wrote:
>> I am getting problems trying to list the subfolders of the default =20=

>> folder using GNU JavaMail IMAP provider v1.1.
>> I guess that my problem comes from a bad usage of the API so the =20
>> best would be to look into the code of a working application.
>
> It may be a bug, do you have a test for it?
> --=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
>
>
>
>