public void TestEmoji() { var expected = "<html><body>😱<br/></body></html>"; var buffer = Encoding.ASCII.GetBytes("=F0=9F=98=B1"); var decoder = new QuotedPrintableDecoder(); var length = decoder.EstimateOutputLength(buffer.Length); var decoded = new byte[length]; var n = decoder.Decode(buffer, 0, buffer.Length, decoded); var emoji = Encoding.UTF8.GetString(decoded, 0, n); var converter = new TextToHtml(); var result = converter.Convert(emoji); Assert.AreEqual(expected, result); }
public static Byte[] DecodeQuoted(String data) { Byte[] buffer = Encoding.ASCII.GetBytes(data); QuotedPrintableDecoder decoder = new QuotedPrintableDecoder(); Byte[] output = new Byte[decoder.EstimateOutputLength(buffer.Length)]; Int32 length = decoder.Decode(buffer, 0, buffer.Length, output); MemoryStream stream = new MemoryStream(output, 0, length); return(stream.ToArray()); }
protected byte[] DecodeQuotedPrintable(string input) { try { QuotedPrintableDecoder encoder = new QuotedPrintableDecoder(false); byte[] inputBytes = Encoding.UTF8.GetBytes(input); byte[] outputBytes = new byte[encoder.EstimateOutputLength(inputBytes.Length)]; int length = encoder.Decode(inputBytes, 0, inputBytes.Length, outputBytes); return(outputBytes.Take(length).ToArray()); } catch { return(null); } }