I have -- Object content = messages.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
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.
posted 3 weeks ago
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.
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.
posted 3 weeks ago
You don't understand my intentions. This is JavaMail.
Messagemessages = inbox.getMessages(); // I have here all message of my email from IMAP
Object content = messages.getContent(); // create object with my first email message (messages) 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.
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.
posted 3 weeks ago
I understand all, but one other thing.. Please helps me to create code.
First, I have this:
Second, I have this:
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.
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).