Jon*_*Jon 8 java email imap jakarta-mail exchange-server-2007
在IMAP中,消息编号基于消息被放入文件夹的时间(即文件夹中的第一条消息是1,第二条消息是2,等等).但是,此排序不考虑消息的接收日期.我关心的是比文件夹的第1号消息更早的消息,即用户手动(而不是在它被接收到系统中时)移动到文件夹中的消息.
我不能只收到每条消息的收到日期,因为这是非常糟糕的.
我以为我可以进行JavaMail搜索以获取收到的日期早于第一条消息的接收日期的所有消息(并且同样进行搜索以获取所有收到的日期比第一条消息的接收日期更新的消息...会很多,但是虽然我需要处理所有旧的,但我只需要处理一些较新的,(并且通过流程,我的意思是下载它的标题).
但是,当我使用搜索时,它似乎无法正常工作.
Message[] messages = csqFolder.getMessages();
if (messages != null && messages.length > 0) {
Date receivedDate = messages[0].getReceivedDate();
log.trace("Message 1 receivedDate: <" + receivedDate.toString() + ">");
SearchTerm msgsOlderThanOETFirst =
new ReceivedDateTerm(DateTerm.LT, receivedDate);
SearchTerm msgsNewerThanFirst =
new ReceivedDateTerm(DateTerm.GT, receivedDate);
Message[] oldMsgs = csqFolder.search(msgsOlderThanOETFirst, messages);
log.trace("Size of oldMsgs: <" + oldMsgs.length + ">");
Message[] newMsgs = csqFolder.search(msgsNewerThanFirst, messages);
log.trace("Size of newMsgs: <" + newMsgs.length + ">");
Run Code Online (Sandbox Code Playgroud)
但是,当我运行这些搜索时,它似乎没有给出正确的结果.
在包含8条消息的文件夹中,其中7条消息的日期时间为8月5日中午12点左右,但文件夹中的第一条消息是8月5日下午4点,我们将看到以下内容:
Message 1 receivedDate: <Fri Aug 05 16:46:57 CDT 2011>
Size of oldMsgs: <0>
Size of newMsgs: <7>
Run Code Online (Sandbox Code Playgroud)
但是,剩余的七条消息中的所有消息都比第一条消息旧...它们应该全部在oldMsgs中.
也就是说,如果我在前一天(8月4日)在该文件夹中放入一条消息,那么搜索将完全依赖于该消息.这就像搜索只能在日常工作中使用,而不是第二次...
我应该注意到,在术语msgsOlderThanOETFirst中,我最初使用LE(因此名称),但是,这将翻转上面的resutls - 所有消息将在oldMsgs中找到.
任何人都可以确认这种行为是否属实,如果是这样,它是否会指向Java中的错误?
我试着查看搜索的源代码,但我想我得到的是命令行版本而不是javamail包使用的那种....
我正在使用MS Exchange 2007 SP1和JavaMail 1.4.3.
谢谢你的任何建议.
更新:我不认为我对比较器顺序的读取是错误的.查看以下线程中给出的答案:java imap从日期开始获取消息
假设我们使用了这个答案,我们的界限从2011年7月15日到2011年9月15日.然后我们将搜索比较给定日期为8/4/2011的消息.然后我们会有以下内容:
8/4/2011 < 9/15/2011
SearchTerm olderThen = new ReceivedDateTerm(ComparisonTerm.LT, someFutureDate);
SearchTerm newerThen = new ReceivedDateTerm(ComparisonTerm.GT, somePastDate);
8/4/2011 > 7/15/2011
Run Code Online (Sandbox Code Playgroud)
在两种情况下都会评估为真,这是我们所期望的,因为日期在期望的范围内.
同样,我的代码如下:
SearchTerm msgsOlderThanOETFirst = 8/4/2011 < 8/5/2011
new ReceivedDateTerm(DateTerm.LT, receivedDate); --> TRUE
SearchTerm msgsNewerThanFirst = 8/4/2011 > 8/5/2011
new ReceivedDateTerm(DateTerm.GT, receivedDate); --> FALSE
Run Code Online (Sandbox Code Playgroud)
上述评估为TRUE和FALSE是我所期待的,并将得到.但是,如果我们在8/5/2011 12:00:00收到一条消息,我们会收到以下信息:
SearchTerm msgsOlderThanOETFirst = 8/5/2011 12:00:00 < 8/5/2011 16:46:00
new ReceivedDateTerm(DateTerm.LT, receivedDate); --> TRUE?
SearchTerm msgsNewerThanFirst = 8/4/2011 12:00:00 > 8/5/2011 16:46:00
new ReceivedDateTerm(DateTerm.GT, receivedDate); --> FALSE?
Run Code Online (Sandbox Code Playgroud)
除了,不 - 我们没有得到 - 相反,我们反过来......现在很容易在圈子里思考,但是......我已经多次仔细检查了几次.JavaMail有什么问题,还是我完全糊涂了?如果是后者,请纠正我的困惑!
根据JM开发人员Bill Shannon的说法,这是IMAP协议的限制:
from Bill Shannon
to Jonathan Hanson
cc javamail_ww@oracle.com
date Wed, Aug 10, 2011 at 11:55 AM
subject Re: Bug with searching by ReceivedDateTerms
mailed-by oracle.com
Important mainly because of your interaction with messages in the conversation.
hide details 11:55 AM (16 minutes ago)
The searching is being done by the IMAP server, and you're running into a limitation of the IMAP protocol.
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8532 次 |
最近记录: |