【问题标题】:Java: IMAP with Apache Commons Net - select root folderJava:带有 Apache Commons Net 的 IMAP - 选择根文件夹
【发布时间】:2016-11-05 19:24:16
【问题描述】:

我正在使用 Apache Commons Net,我的目标是获取现有 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

我需要服务器为我提供文件夹列表,因为可能存在自定义或本地化文件夹。

【问题讨论】:

    标签: java gmail imap apache-commons-net


    【解决方案1】:

    你可以使用

    列表()

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

    addProtocolCommandListener

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

    IMAP 命令:

    A11 列表“”“*”

    【讨论】:

    • 我已经尝试过了,但我无法理解语法或smth。我正在使用以下内容:imap.connect(server); imap.login(username, password); imap.list("","*"); 并得到:I/System.out: AAAB LIST "" * I/System.out: AAAB BAD 无法解析命令
    • @rextuz AAAB LIST "" * 是完美的。还有别的吗?你能用你试过的确切代码更新你的问题吗?
    • @Max 我已经设法解决了我的问题。我没有使用正确的语法,谢谢你的帮助!
    【解决方案2】:

    其实这个

    I/System.out: AAAB LIST  *
    

    给了我一个替换的想法

    imap.list("", "*")
    

    imap.list("\"\"", "\"*\"");
    

    效果很好。

    【讨论】:

      猜你喜欢
      • 2013-04-18
      • 2019-08-01
      • 2015-02-07
      • 2012-12-04
      • 2016-08-30
      • 1970-01-01
      • 2013-10-18
      • 2021-04-10
      • 1970-01-01
      相关资源
      最近更新 更多