C# 电子邮件主题解析
我正在用 C# 构建一个用于阅读电子邮件的系统。我在解析主题时遇到问题,我认为该问题与编码有关。
我正在阅读的主题如下:=?ISO-8859-1?Q?=E6=F8sd=E5f=F8sdf_sdfsdf?=
,发送的原始主题是æøsdåføsdf sdfsdf(其中有挪威语字符)。
有什么想法可以更改编码或正确解析它吗?到目前为止,我已经尝试使用 C# 编码转换技术将主题编码为 utf8,但没有任何运气。
这是我尝试过的解决方案之一:
Encoding iso = Encoding.GetEncoding("iso-8859-1");
Encoding utf = Encoding.UTF8;
string decodedSubject =
utf.GetString(Encoding.Convert(utf, iso,
iso.GetBytes(m.Subject.Split('?')[3])));
I'm building a system for reading emails in C#. I've got a problem parsing the subject, a problem which I think is related to encoding.
The subject I'm reading is as follows: =?ISO-8859-1?Q?=E6=F8sd=E5f=F8sdf_sdfsdf?=
, the original subject sent is æøsdåføsdf sdfsdf
(Norwegian characters in there).
Any ideas how I can change encoding or parse this correctly? So far I've tried to use the C# encoding conversion techniques to encode the subject to utf8, but without any luck.
Here is one of the solutions I tried:
Encoding iso = Encoding.GetEncoding("iso-8859-1");
Encoding utf = Encoding.UTF8;
string decodedSubject =
utf.GetString(Encoding.Convert(utf, iso,
iso.GetBytes(m.Subject.Split('?')[3])));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该编码称为quoted printable。
请参阅此问题的答案。
改编自已接受的答案:
当传递字符串时
=?ISO-8859-1?Q?=E6=F8sd=E5f=F8sdf_sdfsdf?=
这将返回“æøsdåføsdf_sdfsdf”。The encoding is called quoted printable.
See the answers to this question.
Adapted from the accepted answer:
When passed the string
=?ISO-8859-1?Q?=E6=F8sd=E5f=F8sdf_sdfsdf?=
this returns "æøsdåføsdf_sdfsdf".