我正在尝试从消息ID获取IMAP消息,这个案例对于用于Gmail的IMAP服务器(即IMAP)是成功的。gmail。com,但我正在尝试使用雅虎IMAP服务器。邮政雅虎。com,收件箱。搜索(searrr[0])返回null。
获取消息的代码块是-
Message[] msgs = null;
MessageIDTerm[] searArr = new MessageIDTerm[]{new MessageIDTerm((String) strMessageID)};
if (inbox != null && inbox.isOpen()) {
msgs = inbox.search(searArr[0]);
}
for (int i = 0; i < msgs.length; i++) {
System.out.println("Message: " + msgs[i]);
}
我使用的是JavaMail-1.4.5版本。
这是一封Yahoo电子邮件的协议跟踪-
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 imap404.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 180505
A1 CAPABILITY
* CAPABILITY IMAP4rev1 ID NAMESPACE X-ID-ACLID UIDPLUS LITERAL+ XAPPLEPUSHSERVICE XYMHIGHESTMODSEQ
A1 OK CAPABILITY completed
imaps://mymail%40yahoo.com@imap.mail.yahoo.com
DEBUG IMAPS: connection available -- size: 1
A2 SELECT nsharma
* 1 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1379585757] UIDs valid
* OK [UIDNEXT 13] Predicted next UID
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft)] Permanent flags
* OK [HIGHESTMODSEQ 5925277392193028104]
A2 OK [READ-WRITE] SELECT completed; now in selected state
Press (U) to get only unread mails OR Press (A) to get all mails:
a
DEBUG IMAPS: IMAPProtocol noop
A3 NOOP
A3 OK NOOP completed
MAILS: 1
A4 FETCH 1 (ENVELOPE INTERNALDATE RFC822.SIZE)
* 1 FETCH (INTERNALDATE "19-Sep-2013 06:51:31 +0000" RFC822.SIZE 5747 ENVELOPE ("Thu, 19 Sep 2013 14:48:53 +0800 (SGT)" "test" (("Monu Jain" NIL "jainmonu_21" "yahoo.com")) (("Monu Jain" NIL "jainmonu_21" "yahoo.com")) (("Monu Jain" NIL "jainmonu_21" "yahoo.com")) (("mymail@yahoo.com" NIL "mymail" "yahoo.com")("mailmover1@yahoo.com" NIL "mailmover1" "yahoo.com")) NIL NIL NIL "<1379573333.18873.YahooMailNeo@web193105.mail.sg3.yahoo.com>"))
A4 OK FETCH completed
DATE: Thu Sep 19 12:18:53 IST 2013
FROM: Monu Jain <jainmonu_21@yahoo.com>
SUBJECT: test
A5 FETCH 1 (BODYSTRUCTURE)
* 1 FETCH (BODYSTRUCTURE (("text" "plain" ("charset" "utf-8") NIL NIL "quoted-printable" 348 4 NIL NIL NIL NIL)("text" "html" ("charset" "utf-8") NIL NIL "quoted-printable" 646 8 NIL NIL NIL NIL) "alternative" ("boundary" "2118110249-1131840139-1379573333=:18873") NIL))
A5 OK FETCH completed
CONTENT: com.sun.mail.imap.IMAPInputStream@3b0a0018
Message Number: 1
Message ID: <1379573333.18873.YahooMailNeo@web193105.mail.sg3.yahoo.com>
A6 SEARCH HEADER Message-ID <1379573333.18873.YahooMailNeo@web193105.mail.sg3.yahoo.com> ALL
* SEARCH
A6 OK SEARCH completed
类似的,我尝试使用一个Gmail邮件,它的协议跟踪是-
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: mail.imap.fetchsize: 16384
DEBUG: mail.imap.statuscachetimeout: 1000
DEBUG: mail.imap.appendbuffersize: -1
DEBUG: mail.imap.minidletime: 10
DEBUG: trying to connect to host "imap.gmail.com", port 993, isSSL true
* OK Gimap ready for requests from 59.99.161.6 b10if5712468ibd.89
A0 CAPABILITY
* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 XYZZY SASL-IR AUTH=XOAUTH AUTH=XOAUTH2 AUTH=PLAIN AUTH=PLAIN-CLIENTTOKEN
A0 OK Thats all she wrote! b10if5712468ibd.89
DEBUG IMAP: AUTH: XOAUTH
DEBUG IMAP: AUTH: XOAUTH2
DEBUG IMAP: AUTH: PLAIN
DEBUG IMAP: AUTH: PLAIN-CLIENTTOKEN
DEBUG: protocolConnect login, host=imap.gmail.com, user=mymail@gmail.com, password=<non-null>
DEBUG IMAP: AUTHENTICATE PLAIN command trace suppressed
DEBUG IMAP: AUTHENTICATE PLAIN command result: A1 OK mymail@gmail.com Ronak Jain authenticated (Success)
A2 CAPABILITY
* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS COMPRESS=DEFLATE ENABLE MOVE CONDSTORE ESEARCH
A2 OK Success
imaps://mymail%40gmail.com@imap.gmail.com
DEBUG: connection available -- size: 1
A3 SELECT Inbox
* FLAGS (\Answered \Flagged \Draft \Deleted \Seen XAOL-RECEIVED XAOL-BILLPAY-MAIL XAOL-READ $hasEmbedded $hasAttached XAOL-SENT XAOL-GOODCHECK-DONE XAOL-OFFICIAL-MAIL $NotJunk NotJunk XAOL-GOOD XAOL-CERTIFIED-MAIL $Junk)
* OK [PERMANENTFLAGS (\Answered \Flagged \Draft \Deleted \Seen XAOL-RECEIVED XAOL-BILLPAY-MAIL XAOL-READ $hasEmbedded $hasAttached XAOL-SENT XAOL-GOODCHECK-DONE XAOL-OFFICIAL-MAIL $NotJunk NotJunk XAOL-GOOD XAOL-CERTIFIED-MAIL $Junk \*)] Flags permitted.
* OK [UIDVALIDITY 635312281] UIDs valid.
* 1102 EXISTS
* 0 RECENT
* OK [UIDNEXT 1532] Predicted next UID.
* OK [HIGHESTMODSEQ 199446]
A3 OK [READ-WRITE] Inbox selected. (Success)
Press (U) to get only unread mails OR Press (A) to get all mails:
a
DEBUG IMAP: IMAPProtocol noop
A4 NOOP
A4 OK Success
MAILS: 1102
A5 FETCH 1 (ENVELOPE INTERNALDATE RFC822.SIZE)
* 1 FETCH (RFC822.SIZE 57661 INTERNALDATE "02-Dec-2011 23:25:41 +0000" ENVELOPE ("Fri, 2 Dec 2011 17:35:54 -0500" "Hack Your Gadgets and Home to Teach Yourself a New Language" (("Lifehacker" NIL "email" "lifehacker.com")) (("<email=lifehacker.com@mail93.us1.rsgsv.net>" NIL "\"Lifehacker\"" NIL)) (("Lifehacker" NIL "email" "lifehacker.com")) ((NIL NIL "mymail" "gmail.com")) NIL NIL NIL "<251e609e1dba3888b86c21cc80f7e853471.20111202223539@mail93.us1.rsgsv.net>"))
A5 OK Success
DATE: Sat Dec 03 04:05:54 IST 2011
FROM: Lifehacker <email@lifehacker.com>
SUBJECT: Hack Your Gadgets and Home to Teach Yourself a New Language
A6 FETCH 1 (BODYSTRUCTURE)
* 1 FETCH (BODYSTRUCTURE (("TEXT" "PLAIN" ("CHARSET" "utf-8" "FORMAT" "fixed") NIL NIL "QUOTED-PRINTABLE" 21176 467 NIL NIL NIL)("TEXT" "HTML" ("CHARSET" "utf-8") NIL NIL "QUOTED-PRINTABLE" 33978 531 NIL NIL NIL) "ALTERNATIVE" ("BOUNDARY" "_----------=_MCPart_211467328") NIL NIL))
A6 OK Success
CONTENT: com.sun.mail.imap.IMAPInputStream@109fd086
Message Number: 1
Message ID: <251e609e1dba3888b86c21cc80f7e853471.20111202223539@mail93.us1.rsgsv.net>
DEBUG IMAP: IMAPProtocol noop
A7 NOOP
A7 OK Success
A8 SEARCH HEADER Message-ID <251e609e1dba3888b86c21cc80f7e853471.20111202223539@mail93.us1.rsgsv.net> ALL
* SEARCH 1
A8 OK SEARCH completed (Success)
文件夹Gmail搜索(MessageIDTerm)工作正常。我发现这两种类型的服务器在协议跟踪中返回的响应之间存在许多差异。我发现两条消息的字符集不同(Gmail中BODYSTRUCTURE的大写字母)-
For Yahoo -- ("charset" "utf-8")
For Gmail -- ("CHARSET" "utf-8" "FORMAT" "fixed")
Yahoo不支持MessageIDTerm搜索消息吗??在为Yahoo搜索SearchTerm时,只有我在Yahoo IMAP帐户中找到了关于FlagTerm的示例。
雅虎是否需要任何其他设置?或者Yahoo不支持搜索特定消息??
更新:
我已经尝试了javaMail-1.5的更新方法
private int[] search(String msgSequence, SearchTerm term)
throws ProtocolException, SearchException {
我通过了“utf-8”来代替null它在使用folder.search方法插入时返回消息。变化是-
return issueSearch(msgSequence, term, "utf-8");
一封雅虎邮件的协议跟踪现在是在进行上述更改后-
debug:
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 imap427.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 139230
A1 CAPABILITY
* CAPABILITY IMAP4rev1 ID NAMESPACE X-ID-ACLID UIDPLUS LITERAL+ XAPPLEPUSHSERVICE XYMHIGHESTMODSEQ
A1 OK CAPABILITY completed
imaps://mymail%40yahoo.com@imap.mail.yahoo.com
DEBUG IMAPS: connection available -- size: 1
A2 SELECT Inbox
* 7 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1379569582] UIDs valid
* OK [UIDNEXT 12] Predicted next UID
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft)] Permanent flags
* OK [HIGHESTMODSEQ 5926810751342850952]
A2 OK [READ-WRITE] SELECT completed; now in selected state
DEBUG IMAPS: IMAPProtocol noop
A3 NOOP
A3 OK NOOP completed
MAILS: 7
A4 FETCH 1 (ENVELOPE INTERNALDATE RFC822.SIZE)
* 1 FETCH (INTERNALDATE "19-Sep-2013 05:57:28 +0000" RFC822.SIZE 9404 ENVELOPE ("Thu, 19 Sep 2013 11:27:07 +0530" "Fwd: Commander Report on 2013-09-13T13:38:14" (("Neelam Sharma" NIL "neelamudr" "gmail.com")) (("Neelam Sharma" NIL "neelamudr" "gmail.com")) (("Neelam Sharma" NIL "neelamudr" "gmail.com")) ((NIL NIL "mymail" "yahoo.com")(NIL NIL "mailmover1" "yahoo.com")) NIL NIL "<2013042856.0.1379059694398.JavaMail.admin@machine-166>" "<CAJDwy1HgUQzmRYmMZRY-r9-2wCQGDcpvwR+4Chn82L+kZV1p0A@mail.gmail.com>"))
A4 OK FETCH completed
DATE: Thu Sep 19 11:27:07 IST 2013
A5 FETCH 1 (BODY.PEEK[HEADER.FIELDS (Message-Id)])
* 1 FETCH (BODY[HEADER.FIELDS (MESSAGE-ID)] {84}
Message-ID: <CAJDwy1HgUQzmRYmMZRY-r9-2wCQGDcpvwR+4Chn82L+kZV1p0A@mail.gmail.com>
)
A5 OK FETCH completed
Headers: [Ljava.lang.String;@13e1329e
FROM: Neelam Sharma <neelamudr@gmail.com>
SUBJECT: Fwd: Commander Report on 2013-09-13T13:38:14
A6 FETCH 1 (BODYSTRUCTURE)
* 1 FETCH (BODYSTRUCTURE (("text" "plain" ("charset" "iso-8859-1") NIL NIL "7bit" 2288 52 NIL NIL NIL NIL)("text" "html" ("charset" "iso-8859-1") NIL NIL "quoted-printable" 3408 55 NIL NIL NIL NIL) "alternative" ("boundary" "001a1130ca2e86248804e6b63a47") NIL))
A6 OK FETCH completed
CONTENT: com.sun.mail.imap.IMAPInputStream@fd49559
Message Number: 1
Message ID: <CAJDwy1HgUQzmRYmMZRY-r9-2wCQGDcpvwR+4Chn82L+kZV1p0A@mail.gmail.com>
A7 SEARCH CHARSET utf-8 HEADER Message-ID <CAJDwy1HgUQzmRYmMZRY-r9-2wCQGDcpvwR+4Chn82L+kZV1p0A@mail.gmail.com> ALL
A7 NO [BADCHARSET] SEARCH SEARCH error: charset not supported
DEBUG IMAPS: IMAPProtocol noop
A8 NOOP
A8 OK NOOP completed
A9 SEARCH CHARSET utf-8 HEADER Message-ID <CAJDwy1HgUQzmRYmMZRY-r9-2wCQGDcpvwR+4Chn82L+kZV1p0A@mail.gmail.com> 1:7
A9 NO [BADCHARSET] SEARCH SEARCH error: charset not supported
A10 FETCH 2 (BODY.PEEK[HEADER.FIELDS (Message-ID)])
* 2 FETCH (BODY[HEADER.FIELDS (MESSAGE-ID)] {84}
Message-ID: <CAJDwy1EG+w_toT+L1yRW3+FxdFULUq_7o-7jX_NdW9H8PCDuFA@mail.gmail.com>
)
A10 OK FETCH completed
A11 FETCH 3 (BODY.PEEK[HEADER.FIELDS (Message-ID)])
* 3 FETCH (BODY[HEADER.FIELDS (MESSAGE-ID)] {84}
Message-ID: <CAJDwy1EbOgtCQj+PzrYzifFZwbOvShV6LTzZ+CJBRGm+xZhvvg@mail.gmail.com>
)
A11 OK FETCH completed
A12 FETCH 4 (BODY.PEEK[HEADER.FIELDS (Message-ID)])
* 4 FETCH (BODY[HEADER.FIELDS (MESSAGE-ID)] {84}
Message-ID: <CAJDwy1Fr_HRMAmJKBoUEC+UfkArSvDPFrL8UZCyM8rMkt7uGGQ@mail.gmail.com>
)
A12 OK FETCH completed
A13 FETCH 5 (BODY.PEEK[HEADER.FIELDS (Message-ID)])
* 5 FETCH (BODY[HEADER.FIELDS (MESSAGE-ID)] {76}
Message-ID: <1379573294.59617.YahooMailNeo@web193103.mail.sg3.yahoo.com>
)
A13 OK FETCH completed
A14 FETCH 6 (BODY.PEEK[HEADER.FIELDS (Message-ID)])
* 6 FETCH (BODY[HEADER.FIELDS (MESSAGE-ID)] {76}
Message-ID: <1379573283.17330.YahooMailNeo@web193105.mail.sg3.yahoo.com>
)
A14 OK FETCH completed
A15 FETCH 7 (BODY.PEEK[HEADER.FIELDS (Message-ID)])
* 7 FETCH (BODY[HEADER.FIELDS (MESSAGE-ID)] {76}
Message-ID: <1379573333.18873.YahooMailNeo@web193105.mail.sg3.yahoo.com>
)
A15 OK FETCH completed
Found message #0: Fwd: Commander Report on 2013-09-13T13:38:14
Message: com.sun.mail.imap.IMAPMessage@3b733273
FROM12: Neelam Sharma <neelamudr@gmail.com>
SUBJECT12: Fwd: Commander Report on 2013-09-13T13:38:14
CONTENT12: com.sun.mail.imap.IMAPInputStream@6e912008
Message Number12: 1
Message ID12: <CAJDwy1HgUQzmRYmMZRY-r9-2wCQGDcpvwR+4Chn82L+kZV1p0A@mail.gmail.com>
******************************************
这是获取信息的正确方式吗??
已编辑:将SearchTerm类的方法match()重写为match messageID-
SearchTerm messageIDTerm= new SearchTerm() {
@Override
public boolean match(Message message) {
try {
if (((MimeMessage) message).getMessageID().contains(sMessageId)) {
return true;
}
} catch (MessagingException ex) {
ex.printStackTrace();
}
return false;
}
};
msgs = folder.search(messageIDTerm);
此搜索返回由message-ID给出的消息。
谢谢
尼拉姆·夏尔马
我假设您已确保邮箱中确实存在具有该邮件ID的邮件?
查看YahooIMAP服务器实际返回的内容会很有趣。尝试打开会话调试并查看协议跟踪。YahooIMAP服务器可能不支持此功能;它似乎只支持现有移动客户端的需求。
通过将SearchTerm类的方法match()重写为match messageID,我的问题得以解决-
SearchTerm messageIDTerm= new SearchTerm() {
@Override
public boolean match(Message message) {
try {
if (((MimeMessage) message).getMessageID().contains(sMessageId)) {
return true;
}
} catch (MessagingException ex) {
ex.printStackTrace();
}
return false;
}
};
msgs = folder.search(messageIDTerm);
此搜索返回由message-ID给出的消息。我使用的是JavaMail-1.5版本。它起作用了!!
我正在尝试这样做: https://developers.google.com/identity/sign-in/web/backend-auth#calling-the-tokeninfo-endpoint 我用CLIENT_ID复制了粘贴的Java代码,但是除了用户标识、电子邮件和电子邮件验证之外,我无法获得任何更多的信息。idTokenString验证确定。还有其他人可以这样做吗? 我要求这
问题内容: 我下载了文件作为ajax的响应。如何从内容处置中获取文件名和文件类型并显示其缩略图。我有许多搜索结果,但找不到正确的方法。 控制台输出: 问题答案: 这是我有时使用它的方式。我假设您将附件作为服务器响应提供。 我从REST服务中这样设置响应头 编辑:编辑答案以适合您的问题-使用单词代替
问题内容: 在docker-compose.yml中: 我如何在yml配置文件中获取此变量: 在$ _SERVER中,它们的获取方式如下: 问题答案: 在symfony中,可以将PHP文件包含在yaml配置中,在其中可以在运行时设置参数,以覆盖parameters.yml中的静态参数值。 在您的app / config / config.yml中 然后使用以下内容创建文件app / config
我刚刚将我们的Spring Boot项目从引导升级到v2.6.2,从Spring Cloud升级到2021.0.0。 现在,我的远程配置获取没有任何效果,应用程序也无法获取正确的属性文件 [main]INFO o. s. c. c. c. ConfigServiceProperty tySourceLocator-从服务器获取配置:http://localhost:8080 [main]WARN
Build.Gradle
不管配置文件名如何,是否有任何方法可以将当前加载的配置传递给PropertySource?从cloud config成功获取配置后收到的日志,用于应用程序:web-server profile:LOCAL