Reputation: 580
I'm creating email client, when i receive emails from blackberry server it sends file name as "=?utf-8?B?anBlZ2F0dGFjaG1lbnQuSlBFRw==?=" but the original filename was "jpegattachment.JPEG", and sometime I get the plain text when I receive from other mail servers. So here my problem is I can get a string which may or may not be encoded.
Is there any way, I can get the encoding of string and decode that into plain text.
Either the input string is "=?utf-8?B?anBlZ2F0dGFjaG1lbnQuSlBFRw==?=" or "jpegattachment.JPEG" output should be "jpegattachment.JPEG".
Any Idea??
Upvotes: 0
Views: 1059
Reputation: 75456
This is MIME-encoded. Even though Base64 is most popular, it may use other encodings like Quoted-printable, binary etc. So you should use an existing library to decode this. Any mail program will have decoder built-in.
You can use the decodeWord()
from Java Mail,
Try deocdeText()
if you want leave plain-text alone.
Upvotes: 1
Reputation: 11343
Yes, this: anBlZ2F0dGFjaG1lbnQuSlBFRw==
is base64 encoded jpegattachment.JPEG
. So just decode it with base64.
Answered how, here: Decode Base64 data in Java
Upvotes: 1