質問

I have a performance issue with expunging thousands, sometimes millions, of mails from email servers by using JavaMail API on imaps and pop3s protocols. I found a way to fetch mails relatively quickly, in bulks, but when I want to remove fetched mails it becomes very slow, e.g. just around 2000 mails were marked deleted in 5 hours (I fetch 10.000 mails in less then a minute).

Can I use some kind of bulk mark of messages. I mean to mark messages as deleted locally and then update/sent all the headers in a bulk?

役に立ちましたか?

解決 2

Thanx Gigi you saved my day, let me complete the answer with what I have done and maybe somebody would find it useful. STORE <<startScope>>:<<endScope>> +FLAGS (\Delete) is the real solution in my case. I am now using something like this:

private Object storeDeletion(IMAPProtocol protocol, int startID, int endID) 
                                                   throws ProtocolException{
    String args = Integer.toString(startID) + ":" 
                  + Integer.toString(endID) 
                  + " +FLAGS" + " (\\Deleted)";
    Response[] r = protocol.command("STORE " + args, null);
    int notDeleted = 0;
    for (Response res : r) {
        // do something here with each response, but avoid last one (summary response) 
    }
    // dispatch remaining untagged responses
    protocol.notifyResponseHandlers(r);
    protocol.handleResult(r[r.length-1]);
    return "" + (r.length - notDeleted - 1);
}

If you don't want to check all the responses you can use +FLAGS.SILENT instead of +FLAGS. notDeleted is incremented inside the for loop for all problematic mails that couldn't be marked as deleted for some reason.

他のヒント

How are you marking them exactly? If you send a STORE command per message then it's going to be expensive. Ideally use a sequence set of UIDs (e.g. 1:4,6,8,10:12,15). Don't let that get too long though, e.g. send a new STORE command once the sequence set exceeds 100 characters.

(The length of the sequence set is arbitrary and you can experiment, but it's not recommended to go to lengths that the server may not be able to handle.)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top