Gmail IMAP,为 X 个最近活动的 Gmail 线程搜索最佳方法
我正在寻找获取前 X 个最近活跃 Gmail 线程列表的最佳方法。
背景:
我正在使用 Java 访问 IMAP with OAuth Google Apps for Education 域。 Gmail Atom 收件箱供稿可用,它可以列出最近 20 个帖子,其中包含未读消息。访问此提要似乎比我使用 OAuth/IMAP 设法生成的任何内容都快得多。
使用 IMAP 方法相对于 Gmail Atom 收件箱提要的优势在于,使用 IMAP,我可以访问任意数量的邮件(不仅仅是 20 条)、查看已读邮件、获取线程大小、获取任何关联的 google 标签、获取配额详细信息并检查旗帜。本质上,这将为我的用户提供更像 Gmail 的体验(我只需要为我们的门户提供只读体验)。我的问题是 IMAP 访问速度明显慢于 Atom feed。相比之下,IMAP 方法大约需要 10 秒,而 Atom 提要通常在 2 秒内返回。
我了解并一直在使用 Gmail IMAP 扩展 和 Gmail 高级搜索语法 。
当前方法:
假设我想要从 IMAP 收件箱中获取前 40 个主题。目前,我下载了一些任意数量的消息,例如(40 * 4),仅获取X-GM-THRID。我会遍历这些存储线程 ID 的消息(如果需要,则获取更多消息),直到耗尽收件箱消息列表或达到目标线程数。
然后,我有一个 Gmail 线程 id 列表,可用于执行 IMAP 搜索(使用适当的 FetchProfile.Item,具体取决于所需的邮件详细信息)。
我迭代搜索结果,生成类似的内容(使用精彩的 Google Guava/Google Collections Multimap):
Multimap<Long, Message> threadMultiMap = LinkedListMultimap.create();
这很容易理解为:
LinkedHashMap<Long, Message[]> threadMap;
有没有比迭代 INBOX 直到识别出 X 个不同的消息线程更好的方法?
I am looking for the optimal way to acquire a list of the top X most recently active Gmail threads.
Background:
I am using Java accessing IMAP with OAuth in a Google Apps for Education domain. A Gmail Atom inbox feed is available which can list the last 20 threads containing unread messages. Access to this feed seems to be very fast much faster than anything I having managed to produce using OAuth/IMAP.
The advantage of using the IMAP approach over the Gmail Atom inbox feed is with IMAP I can access an arbitrary number of messages (not just 20), see read messages, get thread size, get any associated google labels, fetch quota details and check for flags. Essentially this will give my users a much more Gmail like experience (I only need a read only experience for our portal). My problem is IMAP access is significantly slower than the Atom feed. Comparison wise the IMAP method takes around 10 seconds whilst the Atom feed is usually returned within 2 seconds.
I am aware and have been working with the Gmail IMAP Extensions and Gmail Advanced Search syntax .
Current Method:
Imagine I want the top 40 threads from my IMAP inbox. Currently I download some arbitrary number of messages say (40 * 4), fetching only the X-GM-THRID. I iterate through these messages storing the thread id as I go (fetching more messages if required) until I either exhaust the list of inbox messages or I reach my target number of threads.
I then have a list of Gmail thread ids which I can use to perform an IMAP search (with an appropriate FetchProfile.Item's, depending on what message details are required).
I iterate through the search results producing something like (using the wonderful Google Guava/Google Collections Multimap):
Multimap<Long, Message> threadMultiMap = LinkedListMultimap.create();
and this is easily massaged into:
LinkedHashMap<Long, Message[]> threadMap;
Is there a better way than iterating through the INBOX until X distinct message threads have been identified?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上不是答案,而是相关查询。
标记,根据您的 api 请求,我将发布评论作为答案 (http://code.google.com/p/java-gmail-imap/wiki/DisplayingGmailThreadBasedView)
您的库是否支持 3 条腿oauth,我尝试在存储库中的源代码中查找 XoauthAuthenticator,但找不到它。
谢谢
您好,agallego,
我将 java-gmail-imap 与 XOAUTH 一起使用。 JavaMail 中没有明确要求进行任何更改才能使用 XOAUTH。
如果您查看 XOAUTH 项目 (google-mail-xoauth-tools 和 google-mail-xoauth-tool-java-two-legged)您将看到可以创建一个可用于对 Gmail 进行身份验证的 SASL 提供程序。请参阅例如 XoauthAuthenticator.java
我希望这有帮助,
马克
Not actually an answer but a relevant query.
Mark, as per your api request, I'm posting a comment as an answer (http://code.google.com/p/java-gmail-imap/wiki/DisplayingGmailThreadBasedView)
Does your lib support 3 legged oauth, I tried looking for XoauthAuthenticator on the source in the repo and could not find it.
Thanks
Hi agallego,
I use java-gmail-imap with XOAUTH. There is nothing explicitly in JavaMail that requires any changes to work with XOAUTH.
If you look at the XOAUTH projects (google-mail-xoauth-tools and google-mail-xoauth-tool-java-two-legged) you will see that you can create a SASL provider that can be used to authenticate against Gmail. See e.g. XoauthAuthenticator.java
I hope this helps,
Mark