如何解决如何使用 C# MailKit 解码 ContentEncoding.SevenBit 和 ContentEncoding.EightBit MimePart
我有这段代码:
private string DecodeMimePart(MimePart mimePart)
{
var decodedString = "";
IMimeDecoder mimeDecoder = mimePart.ContentTransferEncoding switch
{
ContentEncoding.SevenBit => throw new NotImplementedException(),ContentEncoding.EightBit => throw new NotImplementedException(),ContentEncoding.Binary => new HexDecoder(),ContentEncoding.Base64 => new Base64Decoder(),ContentEncoding.QuotedPrintable => new QuotedPrintableDecoder(),ContentEncoding.UUEncode => new UUDecoder(),_ => throw new Exception($"ContentTransferEncoding '{mimePart.ContentTransferEncoding}' not supported"),};
using var streamReader = new StreamReader(mimePart.Content.Stream,true);
decodedString = streamReader.ReadToEnd();
var encodedStringBytes = Encoding.UTF8.GetBytes(decodedString);
var decodedStringBytes = new byte[4096];
int decodedBytesNumber = mimeDecoder.Decode(encodedStringBytes,encodedStringBytes.Length,decodedStringBytes);
decodedString = Encoding.UTF8.GetString(decodedStringBytes,decodedBytesNumber);
return decodedString;
}
而且我需要知道我必须使用什么解码器来进行 SevenBit 和 EightBit 内容编码。我查看了文档 here,但没有找到正确的解码器。
谢谢。
解决方法
为什么不使用 mimePart.Content.DecodeTo()
而不是尝试自己手动完成?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。