How to decode the attachment file in [MIME] java mail

2.3k Views Asked by At

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.

1

There are 1 best solutions below

0
On

You're trying to decode the attachment name, right? See this JavaMail FAQ entry.