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

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

问题描述

我建立一个系统,在C#阅读电子邮件。我已经得到了解析的问题,我认为这是涉及到编码的问题一个问题。



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



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



下面是我试过的解决方案之一:

 编码ISO = Encoding.GetEncoding(ISO-8859-1); 
编码UTF = Encoding.UTF8;
串decodedSubject =
utf.GetString(Encoding.Convert(UTF,异,
iso.GetBytes(m.Subject.Split()[3]))'?');


解决方案

编码被称为的引用的可打印



请参阅答案的this 问题。



从接受的回答:

 公共字符串DecodeQuotedPrintable(字符串值)
{
附件附件= Attachment.CreateAttachmentFromString(,值);
返回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天全站免登陆