File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other JSE/JEE APIs and the fly likes Reading utf-8 data from email attachments Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Reading utf-8 data from email attachments" Watch "Reading utf-8 data from email attachments" New topic

Reading utf-8 data from email attachments

Peter Straw
Ranch Hand

Joined: Jan 08, 2002
Posts: 79

I'm trying to use Java to read a series of attachments from an eml file that has been written to disk. If I open the eml with an email client then the attachments are displayed correctly, but when I try to turn them into Multipart objects in Java and then print these to a console some of the charaters are incorrectly shown as '?' (the majority of the characters are rendered correctly).

The eml file is shown as 'utf-8 unicode' when opened in an email client. Can anybody suggest how I could use java character encoding to display the '?' correctly please (or suggest an alternative)?

Many thanks..
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

The chances are that it's the printing-to-console part that's going wrong, not the reading-from-attachment part. Consoles are notorious for failing to support UTF-8, and you already have a test (your e-mail client) which shows that reading from the attachment can work correctly.

So I would suggest testing with something which supports UTF-8 properly. A small Swing application with a text component would do quite well. If you still have a problem, then it's time to look at your code.
I agree. Here's the link:
subject: Reading utf-8 data from email attachments
It's not a secret anymore!