2

I'm using the OpenPop library to read emails. I have the problem that when reading the body of the Email, the library modifies a character. See the following example:

Email body:

Diseño

Code c#:

OpenPop.Pop3.Pop3Client objPOP3 = new OpenPop.Pop3.Pop3Client();
OpenPop.Mime.Message message = default(OpenPop.Mime.Message);
OpenPop.Mime.MessagePart plainTextPart = default(OpenPop.Mime.MessagePart);
string bodyMailTxt = "";

objPOP3.Connect(Host, Port, UseSSL);
objPOP3.Authenticate(User, Password);

message = objPOP3.GetMessage(1);
plainTextPart = message.FindFirstPlainTextVersion();
bodyMailTxt = plainTextPart.GetBodyAsText();

Code vb:

Dim objPOP3 As New OpenPop.Pop3.Pop3Client
Dim message As OpenPop.Mime.Message
Dim plainTextPart As OpenPop.Mime.MessagePart
Dim bodyMailTxt As String = ""

ObjPOP3.Connect(Host, Port, UseSSL)
ObjPOP3.Authenticate(User, Password)

message = objPOP3.GetMessage(1)
plainTextPart = message.FindFirstPlainTextVersion()
bodyMailTxt = plainTextPart.GetBodyAsText()


bodyMailTxt value is "DiseÃf±o", which replaced the ƒ (latin small letter F whit hook) for f (latin small letter F).
I'd have to do to make this not happen?

Gonzalo
  • 141
  • 3
  • 9
  • Could you post the entire message (IE, the source code for the email) on a service such as pastebin? You could also try to mail the support mailing list hpop-users@lists.sourceforge.net – foens Nov 15 '12 at 17:11
  • what you mean with the source code of the email? The body of the email only has the word "Diseño". – Gonzalo Nov 16 '12 at 01:40
  • But what about the headers? For example subject, encoding, content type and so on. Like you only view the visual parts of a homepage, there is source code behind it (the HTML). The same applies to an email. An [introduction](http://hpop.sourceforge.net/emailIntroduction.php) is available at the OpenPop homepage. – foens Nov 16 '12 at 07:52
  • Link in pastebin of what you requested: [test mail](http://pastebin.com/embed_iframe.php?i=HuCAiPbv) – Gonzalo Nov 16 '12 at 13:16
  • Using [quoted-printable decoder](http://www.motobit.com/util/quoted-printable-decoder.asp) to decode "Dise=C3f=C2=B1o=20" in character set "iso-8859-1" gives "DiseÃf¹o". The "f" character is not encoded in the source, so OpenPop cannot give any other answer than "f". Does other email clients show your latin "ƒ"? – foens Nov 17 '12 at 14:03
  • But because it appears in the HTML "Dise=C3=83=C2=B1o", which when decoded gives "Diseùo" – Gonzalo Nov 17 '12 at 14:32
  • That is true. Did not notice that. According to [Wikipedia](http://en.wikipedia.org/wiki/ISO/IEC_8859-1) ƒ is not defined for iso-8859-1. Either way, it seems that OpenPop just decodes the source that it was given. Maybe something went wrong in the encoder? – foens Nov 17 '12 at 21:08
  • This means that no solution? – Gonzalo Nov 19 '12 at 18:11
  • I'm sorry but yes. The email does not contain the characters DiseÃf±o. It is erroneously encoded. Can you see the correct characters with some other email client? – foens Nov 19 '12 at 23:17

1 Answers1

0

From looking at the source for the OpenPop.Mime.MessagePart class, it looks like plainTextPart.GetBodyAsText(), is getting the text like this, return BodyEncoding.GetString(Body), where BodyEncoding is a public property of type Encoding and Body is a public property of the raw byte array that comprises the message.

I don't know and I can't really test, but it could be that the default encoding the message is using to decode the text isn't the same as what was used to send the text. You may be able to see what results you get by trying plainTextPart.Encoding = Encoding.ASCII, or plainTextPart.Encoding = Encoding.UTF8, or plainTextPart.Encoding = Encoding.Unicode before calling the .GetBodyAsText() method.

Link to MessagePart source file:

http://hpop.svn.sourceforge.net/viewvc/hpop/trunk/OpenPop/Mime/MessagePart.cs?revision=377&view=markup

Kratz
  • 4,280
  • 3
  • 32
  • 55