JavaMail中文附件的处理方法

来源:互联网 发布:淘宝网娶个什么名字 编辑:程序博客网 时间:2024/05/17 08:46
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
JavaMail能很好的支持中文,但在测试过程中发现使用JavaMail发带有中文文件名的
附件时,文件名是乱码,经测试与查看源文件发现,是在JavaMail包里的一个写邮件
的方法没有考虑国际化因素,对双字节或多字节的字符没有考虑。即在
com.sun.mail.util.LineOutputStream调用
com.sun.mail.util.ASCIIUtility.getBytes(String s);
此方法直接将字符串转化成字符然后转换成字节。其实在String类里的getBytes()
方法就直接可以按照系统缺省的编码正确转换成字节码。
解决方法:将com.sun.mail.util.LineOutputStream中调用ASCIIUtility.getBytes(String s);
方法的部分改为s.getBytes()解决了此问题。
用重新编译好的LineOutputStream.class文件替换JavaMail里的Com/sun/mail/util/LineOutputStream.class文件即可<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>