使用MimeKit/MailKit进行内容编码 [英] Content encoding using MimeKit/MailKit

查看:160
本文介绍了使用MimeKit/MailKit进行内容编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们遇到了一些编码问题,特别是在使用8bit作为内容传输编码时. 首先,谁能告诉我a-变音符的8bit编码值是什么样的?

We are encountering some encoding issues, specially when using 8bit as content transfer encoding. First of all, can anyone please tell me how 8bit encoded value of a-umlaut looks like?

在实践中处理编码的最佳方法是什么?

What is best in practice to handle encoding?

我试图使用MIME实体的WriteTo()方法将内容写入流中,该方法在除8位编码以外的任何情况下都可以使用.

I tried to use the WriteTo() method of a MIME entity, to write the content into a stream, which works in any cases other than with 8bit encoding.

更新: 当前正在使用MimeKit示例之一中发布的代码:

UPDATE: Currently using the code as posted in one of the examples of MimeKit:

using (MemoryStream memStm = new MemoryStream())
{
    mime.WriteTo(memStm);
    message.MimeMessage = Encoding.UTF8.GetString(memStm.ToArray());
}

但是当我的MIME包含如下特殊字符时,它看起来像是某种双重编码: Ä 会导致类似: ¿½

But it seems like some kind of double encoding when my MIME contains special characters like: äÄ will result in something like: ¿½

如何避免这种双重编码情况?

How can I escape those double encoding situations?

推荐答案

8位MIME传输编码基本上是无编码",因此任何使用8位编码进行编码的MIME数据都与该文件的二进制表示形式相同.给定字符集中的数据 .例如,ä"在UTF-8中表示为以下字节序列:0xC30xA4.当使用8位时,您的MIME数据将是完全相同的字节序列.其他传输编码(例如quoted-printablebase64)将对这些字节进行不同的编码,例如为w6Q==C3=A4.

The 8-bit MIME transfer encoding is basically "no encoding", so any MIME data encoded with 8-bit encoding is the same as the binary representation of the data in the given charset. For instance, 'ä' represented in UTF-8 as the following sequence of bytes: 0xC3, 0xA4. When using 8-bit, your MIME data will be the very same sequence of bytes. Other transfer encodings like quoted-printable or base64 will encode those bytes differently, e.g. as w6Q= or =C3=A4.

结论是, MIME字符集指定了如何以二进制形式表示字符,而 MIME内容传输编码指定了如何在MIME文档本身中对这些字节进行编码

The takeaway is that the MIME character set specifies how characters are represented in binary form and the MIME content transfer encoding specifies how those bytes get encoded in the MIME document itself.

关于最佳做法,现代电子邮件服务器和客户端将很高兴处理8位编码的电子邮件.不过,习惯是使用quoted-printablebase64.

As for best practices, modern email servers and clients will happily deal with 8-bit encoded emails. Still, the custom is to use either quoted-printable or base64.

对于双重编码问题,序列äÄ双重UTF-8编码的序列看起来与¿½不同,所以我认为那里还有其他问题.我不熟悉MimeKit,您的代码示例包含的信息不足,但是如果您使用更完整的repro代码更新问题,我将很乐意更新我的答案.

As for the double-encoding issue, the sequence äÄ double UTF-8 encoded looks different from ¿½, so I thinks something else is going wrong there. I am not familiar with MimeKit and your code sample does not contain enough information, but if you update your question with more complete repro code, I will be happy to update my answer.

这篇关于使用MimeKit/MailKit进行内容编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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