Question

I'm stuck on thi sproblem since yesterday, so hope here someone can help.

I'm writing an app that should read email from a POP3 server. Actually the app is working but I have the problem that, for some message, I get the "From" field with something like that inside:

=?UTF-8?Q?aaaa=20bbbb?=

what is that? I can read the sender name in (that is, in the example, "aaaabbbb"), but how can I decode it?

I have to show this string inside a TextView, maybe there is a property of the textview that I can set?

thank you all very much Cristiano

EDIT: I have found another post ("=?utf-8?Q?" appended while fetching emails) where someone is suggesting to use the PHP "mb_decode_mimeheader" function to get the data without that kind of boring header...is there any equivalent for Javamail?

EDIT: Ok, found the solution in this post: Decoding UTF-8 email subject?

the last answer, MimeUtility.decodeText is working perfectly for me.

Was it helpful?

Solution

So here we go.

here is what I found: from here I understood what are these markers and why they are there.

Then here on SO I have found a solution that was working for me...at the beginning. After a further check, I have found some email that was not correctly deecoded by the decodeText method, and then I have found why: sometime, actually I don't know why, subjects came surrounded by quotes, and each time it happened the decodeText did not work.

Workaround: simply remove all quotes from string (or the quotes at the beginning and at the end if you can have more into your string):

string2beConverted = string2beConverted.replace("\"", ""); String decodedString = MimeUtiliy.decodeText(string2beConverted);

Cristiano

OTHER TIPS

I think it is a UTF8 image code. If you have ever gotten an email with a image in the subject line, like a heart or other thing.

Here is a link to similar UTF8 image strings: http://thisthingiscrazy.com/a-collection-of-email-subject-utf-8-images/

If you are showing this in a TextView, this SO link may help: How do I go about setting TextView to display UTF-8 when the String is not an embedded Resource?

Are you using the getFrom method? It should handle all the decoding for you. It will return an array of Address objects, which you can cast to InternetAddress objects, and then extract the email address and personal name fields. The personal name field will be decoded for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top