JavaMail由ReceivedDate搜索,没有工作到第二个? [英] JavaMail search by ReceivedDate, doesn't work down to the second?

查看:152
本文介绍了JavaMail由ReceivedDate搜索,没有工作到第二个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在IMAP中,消息编号基于消息何时被放入文件夹(即文件夹中的第一个消息是1,第二个消息是2等)。但是,这种排序不考虑消息的接收日期。我担心的是比文件夹的消息号1更早的消息,即用户手动将其移动到文件夹中的消息(而不是当它被接收到系统中时)。



我不能只是收到每封邮件的receivedDate,因为这是可怕的无效。



/ em>我可以做一个JavaMail搜索,以获得所有收到的日期 的消息比第一个消息的接收日期(同样然后进行搜索以获取所有收到的日期的消息比第一个消息的接收日期更新,这将是很多,但是当我需要处理所有较旧的消息时,我只需要处理一些较新的消息(并且通过进程,我的意思是



但是,当我使用搜索时,它似乎没有正常工作。

 消息[] 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);

消息[] oldMsgs = csqFolder.search(msgsOlderThanOETFirst,messages);
log.trace(Size of oldMsgs:<+ oldMsgs.length +>);
消息[] newMsgs = csqFolder.search(msgsNewerThanFirst,messages);
log.trace(Size of newMsgs:<+ newMsgs.length +>);

但是,当我运行这些搜索时,似乎没有给出正确的结果。 >

在8个消息的文件夹中,其中7个收件日期时间为8月5日上午12:00左右,但文件夹中的第一条消息为4:00我们将看到以下内容:

 消息1 receivedDate:< Fri Aug 05 16:46:57 CDT 2011> 
oldMsgs的大小:< 0>
newMsgs的大小:< 7>

但是,剩下的七条消息中的所有消息都比第一条消息更旧...他们应该都是在oldMsgs。



这就是说,如果我把一个消息从前一天(8月4日)在那个文件夹中,那么搜索将coreectly工作...为那一个信息。这就像搜索仅在日常工作,而不是第二个...



我应该注意,在msgsOlderThanOETFirst这个词中,我原来是然而,使用LE(因此名称),将翻转上述重新排列 - 所有的消息将在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

这将在两种情况下评估为真,这是我们期望的,因为日期在所需的范围内。



同样,我的代码如下:

  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

以上评估为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); - >真正?
SearchTerm msgsNewerThanFirst = 8/4/2011 12:00:00> 8/5/2011 16:46:00
new ReceivedDateTerm(DateTerm.GT,receivedDate); - >假?

除了,否 - 我们没有得到 - 相反,我们得到相反的...在这个时候很容易想到自己在圈子里,但是我已经仔细检查了几次。 JavaMail有什么问题,还是我完全混淆?如果是后者,请纠正我的烦恼!

解决方案

根据JM开发者Bill Shannon的说法,这是IMAP协议的限制:

 从Bill Shannon 
到Jonathan Hanson
cc javamail_ww@oracle.com
date周三,2011年8月10日上午11:55
主题Re:由ReceivedDateTerms搜索的错误
mailed by by oracle.com
重要的是因为您与对话中的消息交互。

隐藏详细信息11:55 AM(16分钟前)

IMAP服务器正在进行搜索,您正在遇到IMAP协议的限制。


In IMAP, message numbering is based on when a message is placed into a folder (i.e. first message in the folder is 1, second message in is 2, etc.). However, this ordering has no regard for a message's received date. What I'm concerned about are messages older than message number 1 of the folder, i.e. a message that's been moved into a folder by a user manually (and not by when it was received into the system).

I cannot just get every message's receivedDate, as this is horrendoulsy inefficent.

I thought I could do a JavaMail search to get all messages with a received date older than the first message's received date, (and likewise then do a search to get all message with a recieved date newer than the first message's received date... which would be many, but while I need to process ALL of the older ones, I only need to process a few of the newer ones, (and by process, I mean download its headers).

However, when I am using the search, it just doesn't seem to work right.

        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 + ">");

However, when I run these searches, it does not seem to give the correct results.

On a folder with 8 messages, 7 of which have a received date time of around 12:00 pm on Aug 5, but the first message in the folder which is at 4:00 pm on Aug 5, we will see the following:

Message 1 receivedDate: <Fri Aug 05 16:46:57 CDT 2011>
Size of oldMsgs: <0>
Size of newMsgs: <7>

However, ALL of the remaining seven messages are older than the first message... they should ALL be in oldMsgs.

That said, IF I put a message from the previous day (Aug 4) in that folder, then the search will coreectly work... for that ONE message. It's like the search only works on a day-by-day basis, not down to the second...

I should note that in the term msgsOlderThanOETFirst, I originally was using LE (hence the name), however, that would flip the above resutls -- ALL the messages would then be found in oldMsgs.

Can anyone else confirm if this behavior is true, and if so, would it point to a bug in Java?

I tried to look into the source code of search but I think I was getting a command line version of it and not the kind that the javamail package uses....

I'm using MS Exchange 2007 with SP1, and JavaMail 1.4.3.

Thanks for any suggestions.

UPDATE: I don't think my reading of the comparator order is wrong. Look the answer given in the following thread: java imap fetch messages since a date

Suppose we use that answer, and we have our boundaries from 7/15/2011 to 9/15/2011. Then we have the search compare a message with a given date of 8/4/2011. Then we would have the following:

                                              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

This would evaluate to true in both cases, which is what we expect, since the date is in the desired range.

Likewise, my code is as follows:

    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

The above evaluations to TRUE and FALSE are what I am expecting, and will receive. However, If we take a given message at 8/5/2011 12:00:00, we get the following:

    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?

Except, no -- we don't get that -- instead, we get the reverse..... it's easy to think yourself in circles at this point, but... I've double-checked this several times. Is there something wrong with JavaMail, or am I utterly confused? Please correct my confustion if it is the latter!

解决方案

According to JM developer Bill Shannon, this is a limitation of the IMAP protocol:

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.

这篇关于JavaMail由ReceivedDate搜索,没有工作到第二个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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