如何解码[MIME] java邮件中的附件文件

时间:2012-05-14 11:29:50

标签: java javamail mime decode mime-message

我无法解码附件。类似=?utf-8?B?MS5qcGc=的编码。我需要解码附件。 我用来解码的java代码

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;
 }

请帮我解码。

1 个答案:

答案 0 :(得分:1)

您正在尝试解码附件名称,对吧?请参阅this JavaMail FAQ entry