简体   繁体   English

使用javax.mail从IMAP服务器读取邮件

[英]Reading mail form IMAP server using javax.mail

I'm trying to read messages from IMAP folders using javax.mail, but after fetchig few messages Im getting following exception: 我正在尝试使用javax.mail从IMAP文件夹中读取消息,但是在fetchig之后我收到以下异常:

* 20 FETCH ()
DEBUG IMAPS: ignoring bad response, THROW: 
com.sun.mail.iap.ParsingException: error in FETCH parsing, unrecognized item at index 12, starts with ")
    at com.sun.mail.imap.protocol.FetchResponse.parse(FetchResponse.java:219)
    at com.sun.mail.imap.protocol.FetchResponse.<init>(FetchResponse.java:96)
    at com.sun.mail.imap.protocol.IMAPProtocol.readResponse(IMAPProtocol.java:392)
    at com.sun.mail.iap.Protocol.command(Protocol.java:354)
    at com.sun.mail.imap.protocol.IMAPProtocol.fetch(IMAPProtocol.java:2113)
    at com.sun.mail.imap.protocol.IMAPProtocol.fetch(IMAPProtocol.java:2094)
    at com.sun.mail.imap.IMAPFolder.fetch(IMAPFolder.java:1253)
    at app.mail.imap.ImapClient.synchronizeLocalData(ImapClient.java:563)
    at app.mail.imap.ImapClient.lambda$6(ImapClient.java:351)
    at java.lang.Thread.run(Thread.java:745)
* BYE Internal error occurred. Refer to server log for more information. [2016-11-03 21:20:44]

This is the code Im using to read messages (session, store and folder are already opened): 这是我用来读取消息的代码(会话,商店和文件夹已经打开):

final Message[] messages = imapFolder.getMessagesByUID(1, IMAPFolder.LASTUID);
final FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.ENVELOPE);
fp.add(FetchProfile.Item.FLAGS);
imapFolder.fetch(messages, fp);

for (final Message msg : messages)
{
    final long uid = imapFolder.getUID(msg);
    final String subject = MimeUtility.decodeText(msg.getSubject());
    final Date date = msg.getReceivedDate();
    info("MESSAGE: {} -> {} on {}", uid, subject, date);
}

It seems it's happening only on very specific messages and only when fetching more informations than message UID (if Im reading only uid then code works). 它似乎只发生在非常具体的消息上,并且仅在获取更多信息而不是消息UID时(如果我只读取uid然后代码工作)。

As far as I know many IMAP servers implementations lack many features from IMAP protocol. 据我所知,许多IMAP服务器实现缺少IMAP协议的许多功能。 Bearing that in mind, what is safest and most reliable method for fetching and reading messages from IMAP folders? 请记住,从IMAP文件夹中获取和读取邮件的最安全,最可靠的方法是什么?

javax.mail version: 1.5.3 (provided by wildfly app server 10.0.1.Final). javax.mail版本:1.5.3(由wildfly app server 10.0.1.Final提供)。

Thanks for your help. 谢谢你的帮助。 It seems it is indeed IMAP server error. 看来它确实是IMAP服务器错误。 When I'm opening message in web client i get: 当我在网络客户端打开消息时,我得到:

Connection error (#022).

Also KMail do not download messages for that folder (I bet other clients too). 此外,KMail不会下载该文件夹的消息(我也打赌其他客户)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM