无法通过SearchTerm搜索Outlook电子邮件

时间:2013-10-29 11:01:21

标签: email outlook javamail imap

我编写了一个示例代码,用于在给定的日期范围内提供一个Outlook电子邮件帐户文件夹的电子邮件。我正在使用Java Mail API 1.5和Java 7.

为了获取消息,我写了以下代码,搜索自1970年1月1日至2013年10月30日之前的电子邮件 -

Date FutureDate = new Date(2013 - 1900, 9, 30, 00, 00, 00);
Date PastDate = new Date(1970 - 1900, 0, 1);
SearchTerm newerThen = new ReceivedDateTerm(ComparisonTerm.LE, FutureDate);
SearchTerm olderThen = new ReceivedDateTerm(ComparisonTerm.GE, PastDate);
SearchTerm andTerm = new AndTerm(olderThen, newerThen);
Message[] msg = folder.search(andTerm);

此代码返回零长度消息,即自1970年1月1日至2013年10月30日之前未发现任何消息,但我的文件夹包含204个此范围之间的电子邮件。

令人惊讶的是,相同的代码可以正常搜索Gmail和Yahoo IMAP帐户的文件夹。

以下是Outlook“收件箱”文件夹的协议跟踪,其中包含204封电子邮件但未通过日期范围搜索字词搜索电子邮件 -

DEBUG: setDebug: JavaMail version ${mail.version}
DEBUG: getProvider() returning javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc.,${mail.version}]
DEBUG IMAPS: mail.imap.fetchsize: 16384
DEBUG IMAPS: mail.imap.ignorebodystructuresize: false
DEBUG IMAPS: mail.imap.statuscachetimeout: 1000
DEBUG IMAPS: mail.imap.appendbuffersize: -1
DEBUG IMAPS: mail.imap.minidletime: 10
DEBUG IMAPS: trying to connect to host "imap-mail.outlook.com", port 993, isSSL true
* OK Outlook.com IMAP4rev1 server version 17.3.0.0 ready (BLU451-IMAP84)
A0 CAPABILITY
* CAPABILITY IMAP4rev1 CHILDREN ID NAMESPACE AUTH=PLAIN AUTH=XOAUTH2 SASL-IR
A0 OK CAPABILITY completed
DEBUG IMAPS: AUTH: PLAIN
DEBUG IMAPS: AUTH: XOAUTH2
DEBUG IMAPS: protocolConnect login, host=imap-mail.outlook.com, user=mymail@outlook.com, password=<non-null>
DEBUG IMAPS: AUTHENTICATE PLAIN command trace suppressed
DEBUG IMAPS: AUTHENTICATE PLAIN command result: A1 OK mymail@outlook.com authenticated successfully
A2 CAPABILITY
* CAPABILITY IMAP4rev1 CHILDREN ID NAMESPACE
A2 OK CAPABILITY completed
Store gmail:imaps://mymail%40outlook.com@imap-mail.outlook.com
DEBUG IMAPS: connection available -- size: 1
A3 SELECT Inbox
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
* 204 EXISTS
* 0 RECENT
* OK [UNSEEN 101] Message 101 is first unseen
* OK [UIDVALIDITY 376204] UIDs valid
* OK [UIDNEXT 100235] Predicted next UID
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft)] Limited
A3 OK [READ-WRITE] SELECT completed.
TOTAL MAILS: 204
A4 SEARCH DELETED ALL
* SEARCH 1
A4 OK SEARCH Completed
FOLDER: Inbox
FUTURE DATE: Wed Oct 30 00:00:00 IST 2013
PAST DATE: Thu Jan 01 00:00:00 IST 1970
A5 SEARCH OR SINCE 1-Jan-1970 ON 1-Jan-1970 OR BEFORE 30-Oct-2013 ON 30-Oct-2013 ALL
* SEARCH
A5 OK SEARCH Completed
MESSAGE FOUND: 0

雅虎收件箱的协议跟踪,其中只包含一封电子邮件,并且搜索带有搜索字词的电子邮件 -

DEBUG: setDebug: JavaMail version ${mail.version}
DEBUG: getProvider() returning javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc.,${mail.version}]
DEBUG IMAPS: mail.imap.fetchsize: 16384
DEBUG IMAPS: mail.imap.ignorebodystructuresize: false
DEBUG IMAPS: mail.imap.statuscachetimeout: 1000
DEBUG IMAPS: mail.imap.appendbuffersize: -1
DEBUG IMAPS: mail.imap.minidletime: 10
DEBUG IMAPS: trying to connect to host "imap.mail.yahoo.com", port 993, isSSL true
* OK [CAPABILITY IMAP4rev1 ID NAMESPACE X-ID-ACLID UIDPLUS LITERAL+ CHILDREN XAPPLEPUSHSERVICE XYMHIGHESTMODSEQ AUTH=PLAIN AUTH=LOGIN AUTH=XYMCOOKIE AUTH=XYMECOOKIE AUTH=XYMCOOKIEB64 AUTH=XYMPKI] IMAP4rev1 imapgate-0.7.68_14.446672 imap411.mail.bf1.yahoo.com
DEBUG IMAPS: AUTH: PLAIN
DEBUG IMAPS: AUTH: LOGIN
DEBUG IMAPS: AUTH: XYMCOOKIE
DEBUG IMAPS: AUTH: XYMECOOKIE
DEBUG IMAPS: AUTH: XYMCOOKIEB64
DEBUG IMAPS: AUTH: XYMPKI
DEBUG IMAPS: protocolConnect login, host=imap.mail.yahoo.com, user=mymail@yahoo.com, password=<non-null>
DEBUG IMAPS: AUTHENTICATE PLAIN command trace suppressed
DEBUG IMAPS: AUTHENTICATE PLAIN command result: A0 OK AUTHENTICATE completed - Mailbox size in bytes is 33054009
A1 CAPABILITY
* CAPABILITY IMAP4rev1 ID NAMESPACE X-ID-ACLID UIDPLUS LITERAL+ XAPPLEPUSHSERVICE XYMHIGHESTMODSEQ
A1 OK CAPABILITY completed
Store gmail:imaps://mymail%40yahoo.com@imap.mail.yahoo.com
DEBUG IMAPS: connection available -- size: 1
A2 SELECT Inbox
* 1 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1379569582] UIDs valid
* OK [UIDNEXT 7322] Predicted next UID
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft)] Permanent flags
* OK [HIGHESTMODSEQ 5940064101685223608]
A2 OK [READ-WRITE] SELECT completed; now in selected state
TOTAL MAILS: 1
A3 SEARCH DELETED ALL
* SEARCH
A3 OK SEARCH completed
FOLDER: Inbox
FUTURE DATE: Wed Oct 30 00:00:00 IST 2013
PAST DATE: Thu Jan 01 00:00:00 IST 1970
A4 SEARCH OR SINCE 1-Jan-1970 ON 1-Jan-1970 OR BEFORE 30-Oct-2013 ON 30-Oct-2013 ALL
* SEARCH 1
A4 OK SEARCH completed
MESSAGE FOUND: 1

请指导我在哪里进行更改,以通过日期范围创建的搜索字词获取电子邮件? outlook是否不支持使用SearchTerm搜索日期?

由于

Neelam Sharma

2 个答案:

答案 0 :(得分:1)

看起来outlook.com服务器坏了;请向Microsoft报告此问题。

答案 1 :(得分:0)

我在使用imapsync迁移邮件时偶然发现了一个类似的问题,该邮件也使用IMAP SEARCH来实现邮件过滤。

通过IMAP SEARCH(请参阅RFC 3501, section 6.4.4)搜索outlook.com通常可以正常工作。但是以我的经验,在 some 文件夹中专门搜索邮件之前似乎不起作用。例如。 Outlook.com中SENTBEFORE文件夹上的Sent筛选已损坏。我在寻找解决方案时发现了您的问题。

一种解决方法似乎是使用BEFORE IMAP搜索键,该键不使用消息的Date:标头,而是使用内部IMAP服务器日期。 (尽管我不知道该如何转换以及是否转换为JavaMail API。)

根据Outlook.com的规范,似乎有些事情(仍然)没有实现。