我编写了一个示例代码,可以在给定的日期范围内带来 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 帐户的电子邮件。
以下是包含 204 封电子邮件但不通过日期范围搜索词搜索电子邮件的 Outlook“收件箱”文件夹的协议跟踪-
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
Yahoo Inbox的协议跟踪仅包含一封电子邮件,并且使用搜索词搜索电子邮件 -
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 搜索日期吗?
谢谢
尼拉姆夏尔马