This class is based on the QuotedPrintable class written by Bill Gearhart found at http://www.aspemporium.com/classes.aspx?cid=6
예제 #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);
            }
        }
예제 #3
0
        /// <summary>
        /// Decode the received single line using the correct decoder
        /// </summary>
        internal static string DecodeSingleLineString(string line, TransferEncoding encoding, string charSet)
        {
            switch (encoding)
            {
            case TransferEncoding.Base64:
            {
                byte[] decodedBytes = Encoding.ASCII.GetBytes(line);
                return(DecodeBase64(new byte[][] { decodedBytes }, charSet));
            }

            case TransferEncoding.QuotedPrintable:
            {
                byte[] decodedBytes = QuotedPrintableEncoding.DecodeSingleLine(line);
                return(DecodeBytesWithSpecificCharset(decodedBytes, charSet));
            }

            case TransferEncoding.SevenBit:
            default:
                return(line);
            }
        }