如何使用 commons ImapClient 获取有用的邮件信息?不仅仅是布尔状态而是真实信息? [英] How get useful mail info with commons ImapClient? Not just boolean status but real info?

查看:26
本文介绍了如何使用 commons ImapClient 获取有用的邮件信息?不仅仅是布尔状态而是真实信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的专家是

<dependency>
    <groupId>commons-net</groupId>
    <artifactId>commons-net</artifactId>
    <version>3.3</version>
</dependency>

我的代码如下

IMAPClient client = new IMAPClient();
client.connect("localhost");
for(50K users){
    client.login(login + emailSuffix, password);
    for (int i = 0; i < folders.length; i++) {
        System.out.println(client.select("INOX"); //prints true, it's ok
    }
}

如何使用 apache commons 客户端抓取消息?所有方法都返回布尔值或空值,所以看起来只是服务器检查库,对吗?是否有可能以某种方式从 imapclient 获取有用的信息? 我的意思是未读消息的数量、某些术语的消息对象(内容+标题+对象)等等.

How may I grab messages with apache commons client? All methods return boolean or void, so it's looks like just server checking library am I right? Is it possible to somehow get useful info from imapclient? I mean number of unread messages, Message objects (content+headers+sibject) by some term and so on.

附言Java Mail api 当然具有我需要的所有功能,但是在 50K 循环中使用它非常慢(我在 其他 SO 问题.Commons 的连接速度要快得多,但无法提供有用的信息(

P.S. Java Mail api of course has all functions I need but it very slow for using it in 50K loop (My efforts on Java Mail API described on other SO question. Commons is much more faster in connection but couldn't give useful info(

推荐答案

最终通过简单的迭代文件系统(我有 maildir 格式)解决了我的问题.我猜 Java Mail API 为 store.connect 中的每个用户创建了新的 dovecot 身份验证,而它应该只连接一次(使用 dovecot 身份验证),然后为每个用户登录(使用 dovecot imap-login).这就是为什么我每次迭代都等待 1 分钟 - 它在 dovecot 配置中的身份验证过程中处于标准空闲状态.我不确定,但看起来如此.

Finally solved my problem by simple iterating over file system (I have maildir format). I guess Java Mail API makes new dovecot auth for each user in store.connect while it should just connect once (consume dovecot auth) and after that login for each user (consume dovecot imap-login). That's why I waited 1 minute for each iteration - it's std idle for auth process in dovecot config. I'm not sure but looks so.

Apache lib 运行速度很快,但它只是用于 ping 服务器的测试库,检查连接和其他 imap 操作.它返回有关操作的布尔结果,但不返回有用的信息(

Apache lib works fast but it's just testing library for pinging server, checking connection and other imap operations. It returns boolean result about operations but not useful information(

这篇关于如何使用 commons ImapClient 获取有用的邮件信息?不仅仅是布尔状态而是真实信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆