JavaMail:如何获取与时间戳比较的新邮件
我试图在某个时间戳之后获取消息,我的编码方式是由本网站的另一位程序员建议的:
GregorianCalendar date = new GregorianCalendar();
SearchTerm newer = new ReceivedDateTerm(ComparisonTerm.GT,date.getTime());
Message msgs[] = folder.search(newerThen);
问题是我收到了自该日期以来的所有消息,而不是特定时间。我想知道是否有一些解决方法可以模拟这一点。我的意思是,例如,如果我想收到今天中午以来的所有消息,我会具体收到这些消息,而不是今天早上收到的消息。
提前致谢,
编辑:
对此有一个新的想法:也许一些日期操作可以完成这项工作。我的意思是,比较时间戳中的分钟并以编程方式过滤那些不符合条件的消息。我知道这不是最好的方法,但它可行。
PS:我正在使用 IMAP 并尝试从 gmail 获取邮件,但我想无论邮件服务器是什么,它都应该可以工作。
I'm trying to get messages after a certain time-stamp, the way I've coded it was suggested by another programmer in this site:
GregorianCalendar date = new GregorianCalendar();
SearchTerm newer = new ReceivedDateTerm(ComparisonTerm.GT,date.getTime());
Message msgs[] = folder.search(newerThen);
The issue is that I get all the messages since the date, not the specific time. I was wondering if there is some work-around to emulate this. I mean, for an instance, if I want to get all the messages since today in the midday I would get those messages spicifically and not those ones received in today's morning.
Thanks in advance,
EDIT:
A new thought concerning to this: perhaps some date manipulation could do the job. I mean, comparing the minutes in the timestamp and filter programmatically those messages that don't fit the criteria. I know it's not the best way, but it could work.
PS: I'm using IMAP and trying to get mails from gmail, but I guess it should work no matter what the mail-server is.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不幸的是,没有。在本例中,JavaMail 类正在使用 IMAP 协议,并且 IMAP 的
SEARCH
命令 仅采用日期,而不采用时间(请参阅SINCE
和SENTSINCE
标准)。Unfortunately, no. In this case, the IMAP protocol is being used by the JavaMail classes, and IMAP's
SEARCH
command takes only dates, not times (see theSINCE
andSENTSINCE
criteria).您可以使用
setTime()
方法来查询某个特定时间。例子:
You could use the
setTime()
method to query for some specific time.Example: