This week's book giveaway is in the Open Source forum.
We're giving away four copies of Programmers Guide to Apache Thrift and have Randy Abernethy on-line!
See this thread for details.
Win a copy of Programmers Guide to Apache Thrift this week in the Open Source forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

decode(object) with UTF-8  RSS feed

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have -- Object content = messages[1].getContent();  -- and I want to decode this "content". How to do this ?

I using JavaMail.

"content" is wrong - is without polish letters like: ą, ć, ś etc. I think that inside this object is wrong text, that is why I try to decode "content" object with the text inside.

The result of my content is:
Niniejsza korespondencja nie wiąże się z udostępnieniem adresu e-mail użytkownika jakimkolwiek podmiotom trzecim. List został wysłany za zgodą użytkowników OnetPoczty i zgodnie z jej Regulaminem.Szczegóły dotyczące mailingów reklamowych można sprawdzić w ustawieniach konta. W razie dodatkowych pytań prosimy o kontakt

I encourage to discusses all you.
 
Saloon Keeper
Posts: 5475
143
Android Firefox Browser Mac OS X Safari Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

is without polish letters


How did you determine that? Note that printing out characters to a console or something similar will often cause accented characters to be printed incorrectly; thus is not a proper test of incorrect data.
 
Szymon Czerwiński
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This object "content" with message I save to file and I see this. Now I combinate to save this "content" to file with utf-8. I try create file with utf-8 at first time. This is my second preposition for this problem.

I create file: File f = new File("abc.doc"); How to do that file will open with utf-8 ? I try to set utf-8 for addition in this file. Text should be read corectly maybe.
 
Marshal
Posts: 64471
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Is the original file encoded in UTF‑8? When you read the file, how did you specify UTF‑8 encoding? What OS are you using? A Unix‑like terminal often has much more scope for printing ć than a Windows® command line. Try using this very old‑fashioned way of displaying your text:-Don't use File; look here in the Java™ Tutorials. You will end up with something likeIf the file is in the Microsoft .doc format, it isn't a text file and normal readers probably can't read it.
 
Szymon Czerwiński
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't understand my intentions. This is JavaMail.

Message[]messages = inbox.getMessages(); // I have here all message of my email from IMAP
Object content = messages[1].getContent(); // create object with my first email message (messages[1]) of body (there are pictures, text or only pictures and etc.)
MimeMessage cmm = new MimeMessage(session); // use mime message with 1 sesion

cmm.setContent(content, "UTF-8"); // save content (body of email) to mime message

Then I want to save this mime message with body of message ("content" object) to file. I did this. I cannot show code rest.
But now, I would like that this file when I will be open this with this save message, should be open with Unicode (UTF-8).

I create file like this: File eml = new File("abc.doc"); And now.... should be line of code with this: when I will be open file that my file will be open from Unicode (UTF-8). How is this line of code, which open file with unicode ?
File open with utf-8 alone. I don't want to read code in addition.
 
Campbell Ritchie
Marshal
Posts: 64471
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Szymon Czerwiński wrote:You don't understand my intentions. . . . .

No, sorry.
 
Tim Moores
Saloon Keeper
Posts: 5475
143
Android Firefox Browser Mac OS X Safari Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Creating a MimeMessage and somehow trying to save it is not the right approach. You should extract the text and the attachments and save them separately, using streams for attachments and Readers/Writers for the message content. While saving the message (and when reading it later) you would specify the UTF-8 encoding.
 
Szymon Czerwiński
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand all, but one other thing.. Please helps me to create code.

First, I have this:

Second, I have this:

Third:
         
I write in this third point "reader" object to file with utf-8. It's good. But how can be apperance reader ? It should be read "content" object with email.
 
Tim Moores
Saloon Keeper
Posts: 5475
143
Android Firefox Browser Mac OS X Safari Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Object content0 = messages[27].getContent();

BufferedReader reader = (something what will be read my object "content" line by line)



It's not as simple as that. getContent can return different things, which is why it returns Object rather than a specific type. If you read the javadocs, you'll notice that at the very least you should be prepared to handle String, InputStream and Multipart. So you'll likely need to use instanceof to differentiate between these cases. It's easy to construct a Reader from a String or an InputStream, and what's more, you can likely ignore Multipart and InputStream if you only call getContent on the Message object that represents the mail body (rather than the attachments).
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!