[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Classpathx-discuss] Which application uses GNU JavaMail ?
From: |
Cedric Hyppolite |
Subject: |
Re: [Classpathx-discuss] Which application uses GNU JavaMail ? |
Date: |
Sat, 11 Feb 2006 21:06:16 +0100 |
Chris,
The exception is thrown on the indicated line:
in getSharedNamespaces (IMAPStore.java)
try
{
Namespaces ns = connection.namespace();
if (ns == null)
{
throw new MethodNotSupportedException("IMAP
NAMESPACE " +
"command not
supported");
}
Namespaces.Namespace[] n = ns.getShared();
--> Folder[] f = new Folder[n.length];
for (int i = 0; i < n.length; i++)
{
String prefix = n[i].getPrefix();
char delimiter = n[i].getDelimiter();
f[i] = 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
IMAP folders. However it seems that listing of a non default folder
returns itself as subfolder. Which make the recursive listing of
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.
Could you give me the cvs server connection info and the module list ?
Thanks,
Cedric
--------
private Store connect() throws MessagingException {
Properties props = new Properties();
Store store;
Session session;
session = Session.getDefaultInstance(props, null);
session.setDebug(true);
store = session.getStore("imap");
store.connect(host, username, password);
return store;
}
private void listSubFolders(Folder folder, boolean recurse) throws
MessagingException {
System.out.println("Folder " + folder.getFullName() + " type is " +
folder.getType());
if ((folder.getType() & Folder.HOLDS_FOLDERS) == 0) {
System.out.println("Folder " + folder.getFullName() + " cannot
contain subfolders.");
return;
}
System.out.println("Listing sub folders of " +
folder.getFullName());
listFolders(folder.list(), recurse);
}
private void listFolders(Folder[]array, boolean recurse) throws
MessagingException {
for (int i = 0 ; i < array.length ; i++) {
Folder folder = array[i];
System.out.println("Found folder "
+folder.getFullName());
if (recurse) {
listSubFolders(folder, recurse);
}
}
}
public void testFolderList() throws MessagingException {
Store store = connect();
Folder folder = store.getDefaultFolder();
listSubFolders(folder, true);
}
Le 11 févr. 06 à 19:49, Chris Burdess a écrit :
Cedric Hyppolite wrote:
Here is a test that shows the issues and the log. I cut the
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.
========== TestCase =============
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 = "XXX";
String username = "XXX";
String password = "XXX";
Properties props = new Properties();
Store store;
Session session;
session = Session.getDefaultInstance(props, null);
session.setDebug(true);
store = 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();
}
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();
}
I'm not sure what's going on with getSharedNamespaces as your
stacktrace doesn't show line numbers that correspond to CVS HEAD -
perhaps you could try with an up-to-date version and let me know
the result?
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();
}
Folder folder = null;
try {
// This will fail.
folder = 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();
}
try {
// This will fail.
folder = 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();
}
This won't work: the "default folder" is supposed to be a sort of
virtual root folder that contains other folders as children
(notably INBOX). It can't be opened as it contains only folders,
not messages: see the API documentation for Folder.open. You can
use Folder.getType to discover whether a folder contains folders,
messages, or both.
try {
// This will fail.
folder = 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-
only");
e.printStackTrace();
}
try {
// This will fail.
folder = 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-
write");
e.printStackTrace();
}
The interpretation of this is up to your mail server, but typically
an empty-name folder refers to the default folder as above.
try {
// This will succeed.
folder = 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 = 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();
}
}
private void listSubFolders(Folder folder) throws
MessagingException {
System.out.println("Folder " + folder.getFullName() + " type is
" + folder.getType());
if ((folder.getType() & Folder.HOLDS_FOLDERS) == 0) {
System.out.println("Folder " + folder.getFullName() + " cannot
contain subfolders.");
return;
}
System.out.println("Listing sub folders of " + folder.getFullName
());
listFolders(folder.list());
}
private void listFolders(Folder[]array) {
for (int i = 0 ; i < array.length ; i++) {
Folder folder = array[i];
System.out.println("Found folder "
+folder.getFullName());
}
}
}
--
犬 Chris Burdess
"They that can give up essential liberty to obtain a little safety
deserve neither liberty nor safety." - Benjamin Franklin
- [Classpathx-discuss] Which application uses GNU JavaMail ?, Cedric Hyppolite, 2006/02/09
- Message not available
- Re: [Classpathx-discuss] Which application uses GNU JavaMail ?, Cedric Hyppolite, 2006/02/12
- Message not available
- Re: [Classpathx-discuss] Which application uses GNU JavaMail ?,
Cedric Hyppolite <=
- Message not available
- Re: [Classpathx-discuss] Which application uses GNU JavaMail ?, Cedric Hyppolite, 2006/02/13
- Message not available
- Re: [Classpathx-discuss] Which application uses GNU JavaMail ?, Cedric Hyppolite, 2006/02/13
- Message not available
- Re: [Classpathx-discuss] Which application uses GNU JavaMail ?, Cedric Hyppolite, 2006/02/14
- Message not available
- Re: [Classpathx-discuss] Which application uses GNU JavaMail ?, Cedric Hyppolite, 2006/02/15
- Re: [Classpathx-discuss] Which application uses GNU JavaMail ?, Cedric Hyppolite, 2006/02/15
- Message not available
- Re: [Classpathx-discuss] Which application uses GNU JavaMail ?, Cedric Hyppolite, 2006/02/21