最近通过 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 解析邮件。
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"
才对
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.