Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

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

Please help me out for decoding.
Posted

1 solution

That is a UTF-8 encoded String:

Encoding:
Java
String strName ="Attachment";
try { strName = MimeUtility.encodeText(oAttachment.getName(),"utf-8",null); }
catch (UnsupportedEncodingException oException) { LOGGER.error(oException); }


Decoding:
Java
String strDecoded = MimeUtility.decodeText(strEncoded);


EDIT: please delete that String modifying stuff. That is not needed and not a proper way to deal with string values.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900