JavaMail: how to get new messages comparing with time-stamps

拟墨画扇 提交于 2019-12-21 12:01:39

问题


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.


回答1:


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 the SINCE and SENTSINCE criteria).




回答2:


You could use the setTime() method to query for some specific time.

Example:

setTime(timeInMilliseconds)


来源:https://stackoverflow.com/questions/4650592/javamail-how-to-get-new-messages-comparing-with-time-stamps

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!