如何使用 C# MailKit 解码 ContentEncoding.SevenBit 和 ContentEncoding.EightBit MimePart

How to decode ContentEncoding.SevenBit and ContentEncoding.EightBit MimePart with C# MailKit

我有这段代码:

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, 0, encodedStringBytes.Length, decodedStringBytes);

        decodedString = Encoding.UTF8.GetString(decodedStringBytes, 0, decodedBytesNumber);

    return decodedString;
}

而且我需要知道我必须使用什么解码器来处理 SevenBit 和 EightBit 内容编码。我已经检查了文档 here 但我没有找到正确的解码器。

谢谢。

为什么不使用 mimePart.Content.DecodeTo() 而不是尝试自己手动完成?