How get useful mail info with commons ImapClient?

2019-08-01 19:16发布

问题:

My maven is

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

My code is the following

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
    }
}

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.

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(

回答1:

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 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(