Java:IMAP与Apache Commons Net-选择根文件夹

Java:IMAP与Apache Commons Net-选择根文件夹,java,gmail,imap,apache-commons-net,Java,Gmail,Imap,Apache Commons Net,我正在使用ApacheCommonsNet,我的目标是获得现有Gmail文件夹的列表。我正在尝试以下代码: IMAPClient imap = new IMAPSClient(); imap.setDefaultPort(port); imap.addProtocolCommandListener(new PrintCommandListener(System.out, true)); imap.connect(server); imap.login(username, password); i

我正在使用ApacheCommonsNet,我的目标是获得现有Gmail文件夹的列表。我正在尝试以下代码:

IMAPClient imap = new IMAPSClient();
imap.setDefaultPort(port);
imap.addProtocolCommandListener(new PrintCommandListener(System.out, true));
imap.connect(server);
imap.login(username, password);
imap.list("", "*")
但它给了我:

I/System.out: * OK Gimap ready for requests from 5.18.55.93 fi8mb55620436ldc
I/System.out: AAAA LOGIN *******
I/System.out: * CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS COMPRESS=DEFLATE ENABLE MOVE CONDSTORE ESEARCH UTF8=ACCEPT LIST-EXTENDED LIST-STATUS LITERAL- APPENDLIMIT=35651584
I/System.out: AAAA OK rextuz@gmail.com authenticated (Success)
I/System.out: AAAB LIST  *
I/System.out: AAAB BAD Could not parse command
我需要服务器向我提供文件夹列表,因为可能存在自定义或本地化的文件夹。

您可以使用

列表()

方法将列表命令发送到gmail imap服务器。添加适当的

addProtocolCommandListener

以列出命令响应。这将列出您登录帐户的文件夹

IMAP命令:

A11列表“*”

其实这个

I/System.out: AAAB LIST  *
给了我一个替换的想法

imap.list("", "*")


这很有魅力。

我已经试过了,但我不懂语法或smth。我正在使用以下命令:
imap.connect(服务器);imap.login(用户名、密码);imap.list(“,”*”)并获取:I/System.out:AAAB列表“”*I/System.out:AAAB BAD无法解析command@rextuz
AAAB列表“*
非常简单。还有别的事吗?你能用你尝试过的代码更新你的问题吗?@Max我已经设法解决了我的问题。我没有正确使用语法,谢谢你的帮助!
imap.list("\"\"", "\"*\"");