如何从imap只下载新的电子邮件? [英] How to download only new emails from imap?

查看:388
本文介绍了如何从imap只下载新的电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于使用imap存档电子邮件的应用程序。此应用程序中还有许多需要存档的imap帐户。

I have an application that is used to archive emails using imap. Also in this application are many imap accounts that need to be archived.

此时应用程序会不时连接到imap帐户并仅下载新电子邮件。我的问题是,每次连接到imap帐户时,它都会验证来自所有文件夹的所有电子邮件,并仅下载尚未下载的电子邮件(我存储所有电子邮件的邮件ID,并仅下载具有邮件ID的电子邮件)没有存储)。
所以我想知道是否有替代方案,因为需要一些时间来验证所有电子邮件(10-20K需要2-5分钟)。

In this moment from time to time the application connects to imap accounts and download only new emails. My issue is that every time when it connects to an imap account it verifies all emails from all folders and downloads only emails that aren't downloaded yet (I store Message-ID for all emails and download only emails that have an Message-ID that is not stored). So I want to know if there is an alternative for this, because it takes some time to verify all emails (for 10-20K it takes 2-5 minutes).

我使用JavaMail API连接到imap帐户。

I use JavaMail API to connect to imap accounts.

推荐答案

javadoc 帮助:

IMAPFolder提供方法:

IMAPFolder provides the methods:

getMessagesByUID(长开始,长尾)和

getMessagesByUID(long start, long end) and

getUID(消息消息)

getUID(Message message)

使用getUID(),您可以获得已下载的最后一条消息的UID。使用getMessagesByUID,您可以将已下载的最后一条消息定义为start-range,并使用方法getUIDNext()查找最后一条消息,该消息将是该范围的结尾。

With getUID() you can get the UID of the last message you already have downloaded. With getMessagesByUID you can define this last message you have downloaded as start-range and look with the method getUIDNext() to find the last message which would be the end of the range.

这篇关于如何从imap只下载新的电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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