C#电子邮件主题解析 [英] C# Email subject parsing

查看:308
本文介绍了C#电子邮件主题解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个在C#中阅读电子邮件的系统。解决问题时遇到问题,我认为与编码有关的问题。



我正在阅读的主题如下: =?ISO-8859-1?Q?= E6 = F8sd = E5f = F8sdf_sdfsdf? = ,发送的原始主题是æøsdåføsdfsdfsdf (挪威字符在那里)。



任何想法如何更改编码或解析这个正确?到目前为止,我试图使用C#编码转换技术将主题编码为utf8,但没有任何运气。



这是我尝试的一个解决方案: / p>

 编码iso = Encoding.GetEncoding(iso-8859-1); 
编码utf = Encoding.UTF8;
string decodingSubject =
utf.GetString(Encoding.Convert(utf,iso,
iso.GetBytes(m.Subject.Split('?')[3])));


解决方案

编码称为 quoted printable



查看问题。



改编自接受的答案


  public string DecodeQuotedPrintable(string value)
{
附件附件= Attachment.CreateAttachmentFromString(,value);
return attachment.Name;
}

传递字符串 =?ISO-8859- 1?Q?= E6 = F8sd = E5f = F8sdf_sdfsdf?= 返回æøsdåføsdf_sdfsdf。


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])));

解决方案

The encoding is called quoted printable.

See the answers to this question.

Adapted from the accepted answer:

public string DecodeQuotedPrintable(string value)
{
        Attachment attachment = Attachment.CreateAttachmentFromString("", value);
        return attachment.Name;
}

When passed the string =?ISO-8859-1?Q?=E6=F8sd=E5f=F8sdf_sdfsdf?= this returns "æøsdåføsdf_sdfsdf".

这篇关于C#电子邮件主题解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆