更快阅读Java中的收件箱 [英] Faster reading of inbox in Java

查看:104
本文介绍了更快阅读Java中的收件箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取收件箱中任何邮件中所包含的所有人的列表.现在,我可以使用javax邮件API通过IMAP进行连接并下载消息:

I'd like to get a list of everyone who's ever been included on any message in my inbox. Right now I can use the javax mail API to connect via IMAP and download the messages:

Folder folder = imapSslStore.getFolder("[Gmail]/All Mail");
folder.open(Folder.READ_ONLY);
Message[] messages = folder.getMessages();

for(int i = 0; i < messages.length; i++) {
  // This causes the message to be lazily loaded and is slow
  String[] from = messages[i].getFrom();
}

该行messages [i] .getFrom()的速度比我想要的慢,因为这会导致该消息被延迟加载.有什么我可以做的来加快速度吗?例如.有什么我可以做的而不是一一加载消息的批量加载吗?这会加载整个消息吗?有什么办法我只能加载to/from/cc字段或标头呢? POP会比IMAP快吗?

The line messages[i].getFrom() is slower than I'd like because is causes the message to be lazily loaded. Is there anything I can do to speed this up? E.g. is there some kind of bulk loading I can do instead of loading the messages one-by-one? Does this load the whole message and is there something I can do to only load the to/from/cc fields or headers instead? Would POP be any faster than IMAP?

推荐答案

您可以使用

You can use fetch-method in Folder. According Javadocs:

客户使用此方法表示指定的项目是 给定消息范围所需的en-masse.实现是 期望在给定的消息范围内检索这些项目 有效的方式.请注意,此方法只是对 实现以预取所需的项目.

Clients use this method to indicate that the specified items are needed en-masse for the given message range. Implementations are expected to retrieve these items for the given message range in a efficient manner. Note that this method is just a hint to the implementation to prefetch the desired items.

要从相应的FetchProfile中进行提取,请 ENVELOPE .当然,这仍然取决于实施,而邮件服务器确实可以起到帮助作用.

For fetching FROM appropriate FetchProfile is ENVELOPE. Of course it is still up to implementation and mail server does that really help.

这篇关于更快阅读Java中的收件箱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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