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?

4

1 回答 1

0

OpenPop.Mime.MessagePart类的源代码来看,它看起来像这样plainTextPart.GetBodyAsText()获取文本 return BodyEncoding.GetString(Body),其中BodyEncoding是类型的公共属性,Encoding并且Body是包含消息的原始字节数组的公共属性。

我不知道,也无法真正测试,但可能是消息用于解码文本的默认编码与用于发送文本的编码不同。在调用该方法之前,您可以通过尝试plainTextPart.Encoding = Encoding.ASCII、 或 plainTextPart.Encoding = Encoding.UTF8或来查看得到的结果。plainTextPart.Encoding = Encoding.Unicode.GetBodyAsText()

链接到 MessagePart 源文件:

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

于 2012-11-14T22:56:15.640 回答