切换到 com.sun.mail:javax.mail 后不能再使用带有变音符号的 InternetAddress
Cant use InternetAddress with umlauts anymore after switching to com.sun.mail:javax.mail
我们最近从 javax.mail:mail
切换到 com.sun.mail:javax.mail
。
此后以下代码失败:
new InternetAddress("chr@möllers.de", false).validate();
Caught: javax.mail.internet.AddressException: Domain contains control or whitespace in string ``chr@möllers.de''
javax.mail.internet.AddressException: Domain contains control or whitespace in string ``chr@möllers.de''
InternetAddress#validate()
的实现明显改变了。此代码段后跟一些关于 CRLF 检查的附加行:
else if (c <= 040 || c >= 0177) {
throw new AddressException(
"Domain contains control or whitespace", addr);
每个 >= 177 的字符都被视为控制或空白 - 这是错误的,例如对于变音符 (ö = 246)。
所以异常消息具有误导性。
更改 validate() 是否引入了错误?
现在,Internet 电子邮件地址可能包含以 punycode 编码的变音符号。这就是为什么我希望安全地传递带有变音符号的字符串。
在这种情况下,InternetAddress 是否打算与编码字符串一起使用?
提前致谢
更新比尔·香农的回答
我的评论中提到的 Groovy 格式精美的脚本:
@GrabResolver(name='snapshots', root='https://maven.java.net/content/repositories/snapshots/', m2Compatible='true')
@Grab("com.sun.mail:javax.mail:1.6.0-SNAPSHOT")
import javax.mail.internet.InternetAddress
new InternetAddress("chr@möllers.de", false)
更新:使用最新快照进行测试
import org.junit.Test;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
public class ValidateEmailTest {
@Test
public void test() throws AddressException {
new InternetAddress("chr@möllers.de", true).validate();
new InternetAddress("chr@möllers.de", false).validate();
}
}
测试成功运行(未抛出 AddressException),最新快照 1.6.0-SNAPSHOT 当前来自 2 月 21 日星期二。
在域名中使用 non-ASCII 个字符需要支持 RFC 6530, RFC 6531, and RFC 6532. Both the client and the server need to support these new standards. I've added such support to JavaMail 1.6; you can download a development SNAPSHOT release as described on the JavaMail web page。需要保证服务器支持SMTPUTF8扩展,需要设置Session属性mail.mime.allowutf8
为true
.
如果您能够使用真实的邮件服务器测试这种对国际化电子邮件地址的新支持,请通过 javamail_ww@oracle.com 告诉我您的体验,无论好坏。谢谢
我们最近从 javax.mail:mail
切换到 com.sun.mail:javax.mail
。
此后以下代码失败:
new InternetAddress("chr@möllers.de", false).validate();
Caught: javax.mail.internet.AddressException: Domain contains control or whitespace in string ``chr@möllers.de''
javax.mail.internet.AddressException: Domain contains control or whitespace in string ``chr@möllers.de''
InternetAddress#validate()
的实现明显改变了。此代码段后跟一些关于 CRLF 检查的附加行:
else if (c <= 040 || c >= 0177) {
throw new AddressException(
"Domain contains control or whitespace", addr);
每个 >= 177 的字符都被视为控制或空白 - 这是错误的,例如对于变音符 (ö = 246)。 所以异常消息具有误导性。
更改 validate() 是否引入了错误?
现在,Internet 电子邮件地址可能包含以 punycode 编码的变音符号。这就是为什么我希望安全地传递带有变音符号的字符串。
在这种情况下,InternetAddress 是否打算与编码字符串一起使用?
提前致谢
更新比尔·香农的回答
我的评论中提到的 Groovy 格式精美的脚本:
@GrabResolver(name='snapshots', root='https://maven.java.net/content/repositories/snapshots/', m2Compatible='true')
@Grab("com.sun.mail:javax.mail:1.6.0-SNAPSHOT")
import javax.mail.internet.InternetAddress
new InternetAddress("chr@möllers.de", false)
更新:使用最新快照进行测试
import org.junit.Test;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
public class ValidateEmailTest {
@Test
public void test() throws AddressException {
new InternetAddress("chr@möllers.de", true).validate();
new InternetAddress("chr@möllers.de", false).validate();
}
}
测试成功运行(未抛出 AddressException),最新快照 1.6.0-SNAPSHOT 当前来自 2 月 21 日星期二。
在域名中使用 non-ASCII 个字符需要支持 RFC 6530, RFC 6531, and RFC 6532. Both the client and the server need to support these new standards. I've added such support to JavaMail 1.6; you can download a development SNAPSHOT release as described on the JavaMail web page。需要保证服务器支持SMTPUTF8扩展,需要设置Session属性mail.mime.allowutf8
为true
.
如果您能够使用真实的邮件服务器测试这种对国际化电子邮件地址的新支持,请通过 javamail_ww@oracle.com 告诉我您的体验,无论好坏。谢谢