最近通过 POP3 读取 QQ 邮箱的邮件,发现只要读取某封邮件后就会报错,debug 后发现,邮件片段是这样的:

* Support emails, files, beta testing, and documents.

Please note that our system did not have any backups saved for your account=
.

1 Second Everyday is a great way to capture and relive your favorite moment=
s. We're always looking forward to your return!

根据 RFC1939 ,"\r\n.\r\n"是邮件内容结束的标记,如果有一行开头是".",那么服务器应该在前面增加一个"."作为转义。腾讯没有正确实现这一点,导致我无法使用 eclipse-ee4j/angus-mail 解析邮件。

参考: https://www.ietf.org/rfc/rfc1939.txt

Responses to certain commands are multi-line. In these cases, which are clearly indicated below, after sending the first line of the response and a CRLF, any additional lines are sent, each terminated by a CRLF pair. When all lines of the response have been sent, a final line is sent, consisting of a termination octet (decimal code 046, ".") and a CRLF pair. If any line of the multi-line response begins with the termination octet, the line is "byte-stuffed" by pre-pending the termination octet to that line of the response. Hence a multi-line response is terminated with the five octets "CRLF.CRLF". When examining a multi-line response, the client checks to see if the line begins with the termination octet. If so and if octets other than CRLF follow, the first octet of the line (the termination octet) is stripped away. If so and if CRLF immediately follows the termination character, then the response from the POP server is ended and the line containing ".CRLF" is not considered part of the multi-line response.

eclipse-ee4j/angus-mail 的代码在这里: https://github.com/eclipse-ee4j/angus-mail/blob/master/providers/pop3/src/main/java/org/eclipse/angus/mail/pop3/Protocol.java 第 992 行,读取到"\n.\r",就认为邮件结束了。腾讯应该返回"\n..\r"才对

举报· 105 次点击
登录 注册 站外分享
快来抢沙发
0 条回复  
返回顶部