Decode() public static method

A quoted printable string is composed only of the ASCII characters 0 to 9, A to F and =. But in fact it represents an array of bytes from the range 0 to 255. These bytes will later be converted to a string using the character set specified in the Content-Type header.
public static Decode ( byte contentLines ) : byte[]
contentLines byte
return byte[]
示例#1
0
        /// <summary>
        /// Decode the content into the given charset
        /// </summary>
        private static string DecodeQuotedPrintable(MimeEntity entity)
        {
            byte[] decodedBytes = QuotedPrintableEncoding.Decode(entity.ContentLines);

            if (entity.ContentType.CharSet != null)
            {
                return(DecodeBytesWithSpecificCharset(decodedBytes, entity.ContentType.CharSet));
            }
            else
            {
                // by default, a text/plain ContentType without Specific Charset must default to ISO-8859-1.
                // Other text/* ContentType without Specific charset must default to utf-8
                // See http://tools.ietf.org/html/rfc6657#page-3

                string encodingName = "utf-8";

                if (entity.ContentType != null && string.Compare(entity.ContentType.MediaType, "text/plain", true) == 0)
                {
                    encodingName = "ISO-8859-1";
                }

                string decodedBytesString = Encoding.GetEncoding(encodingName).GetString(decodedBytes);
                return(decodedBytesString);
            }
        }
示例#2
0
        /// <summary>
        /// Sets the decoded content stream by decoding the EncodedMessage
        /// and writing it to the entity content stream.
        /// </summary>
        public static byte[] DecodeBytes(MimeEntity entity)
        {
            switch (entity.ContentTransferEncoding)
            {
            case TransferEncoding.Base64:
                byte[] decodedBytes = Convert.FromBase64String(Encoding.ASCII.GetString(entity.ContentBytes));
                return(decodedBytes);

            case TransferEncoding.QuotedPrintable:
                return(QuotedPrintableEncoding.Decode(entity.ContentLines));

            case TransferEncoding.SevenBit:
            default:
                return(entity.ContentBytes);
            }
        }