Encoding ISO-8859-1 will not work

R

Robert-Paul

I have some big trouble getting special characters right when reading from a
mailbox. I have a class that reads e-mails from a mailboxusing pop3
(language C#). I have tried various approaches from suggestions that I have
received from newsgroups.

Here's a small sample from how the e-mail looks like just after it is
received: (some headers removed)

MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: base64

Hi there! =
This is a test ISO-8859-1 =20

=3D=20

I have tried several ways to display this text correctly, for example this:
Encoding enc = Encoding.GetEncoding("iso-8859-1");
But var 'enc' does not display correctly.

If anyone can tell me what I am doing wrong or how to convert an e-mail,
written in ISO-8859-1 to normal text?

Greetings
Robert-Paul
http://www.robertp.nl
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi,

You should convert the message from the Quoted-Printable encoding to plain
text first.
 
P

Peter Strøiman

Your post is vague to say the least as to what you are actually doing and
what doesn't work, and what your symptoms are.
What do you mean by "But var 'enc' does not display correctly." Is it null ?

If you have a stream containing encoded binary data, you can read it using a
StreamReader class

Stream stream = // your stream!
Encoding enc = Encoding.GetEncoding("iso-8859-1"); // This SHOULD work
StreamReader reader = new StreamReader( stream, enc );
String str = reader.ReadToEnd();
 
R

Robert-Paul

Peter Strøiman said:
Your post is vague to say the least as to what you are actually doing and
what doesn't work, and what your symptoms are.
What do you mean by "But var 'enc' does not display correctly." Is it null ?

This is what I have:

string x = "body of mail with the special caracters....";
StringReader str = new StringReader(x);
Encoding enc = Encoding.GetEncoding("iso-8859-1");
StreamReader reader = StreamReader(str,enc);
string z = reader.ReadToEnd();

And in 'z' is nothing converted to iso-8859-1.

This is correct?

Greetzzz
Robert-Paul
 
J

Jon Skeet [C# MVP]

Robert-Paul said:
This is what I have:

string x = "body of mail with the special caracters....";
StringReader str = new StringReader(x);
Encoding enc = Encoding.GetEncoding("iso-8859-1");
StreamReader reader = StreamReader(str,enc);
string z = reader.ReadToEnd();

That won't actually compile, both because you've forgotten the "new" in
the fourth line, and because there is no constructor for StreamReader
which takes a StringReader as its first parameter.
And in 'z' is nothing converted to iso-8859-1.

This is correct?

The mail itself no doubt has quoted-printable characters. You need to
convert those into ISO-8859-1. That only has a bit to do with Encoding
objects, which are used to convert *binary* to text, not quoted
printable text to text.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top