如何解码[MIME] Java邮件中的附件文件 [英] How to decode the attachment file in [MIME] java mail
本文介绍了如何解码[MIME] Java邮件中的附件文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法解码附件.类似于 =?utf-8?B?MS5qcGc = 进行编码.我需要解码该附件.我用来解码的Java代码
I am unable to decode the attachment. It something like =?utf-8?B?MS5qcGc= which is encoded. I need to decode that attachment. The java code i am using to decode
private static String decodeName(String name) throws Exception {
if (name == null || name.length() == 0) {
return "unknown";
}
String ret = java.net.URLDecoder.decode(name, "UTF-8");
// also check for a few other things in the string:
ret = ret.replaceAll("=\\?utf-8\\?q\\?", "");
ret = ret.replaceAll("\\?=", "");
ret = ret.replaceAll("=20", " ");
return ret;
}
请帮我解码.
Please help me out for decoding.
推荐答案
这是UTF-8编码的String:
编码:
That is a UTF-8 encoded String:
Encoding:
String strName ="Attachment";
try { strName = MimeUtility.encodeText(oAttachment.getName(),"utf-8",null); }
catch (UnsupportedEncodingException oException) { LOGGER.error(oException); }
解码:
Decoding:
String strDecoded = MimeUtility.decodeText(strEncoded);
请删除该字符串修改内容.这不是必需的,也不是处理字符串值的正确方法.
please delete that String modifying stuff. That is not needed and not a proper way to deal with string values.
这篇关于如何解码[MIME] Java邮件中的附件文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文