Akshay
Akshay

Reputation: 187

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

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.

Upvotes: 0

Views: 2342

Answers (1)

Bill Shannon
Bill Shannon

Reputation: 29971

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

Upvotes: 1

Related Questions