c# 收取邮件 解析,C#电子邮件主题解析

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".

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值