Esempio n. 1
0
        internal static string DecodeHeaderValue(string value)
        {
            int num;

            if ((value == null) || (value.Length == 0))
            {
                return(string.Empty);
            }
            string[] strArray = value.Split(new char[] { '?' });
            if (((strArray.Length != 5) || (strArray[0] != "=")) || (strArray[4] != "="))
            {
                return(value);
            }
            string name = strArray[1];
            bool   flag = strArray[2] == "B";

            byte[] bytes = Encoding.ASCII.GetBytes(strArray[3]);
            if (flag)
            {
                num = new Base64Stream().DecodeBytes(bytes, 0, bytes.Length);
            }
            else
            {
                num = new QuotedPrintableStream().DecodeBytes(bytes, 0, bytes.Length);
            }
            return(Encoding.GetEncoding(name).GetString(bytes, 0, num));
        }
Esempio n. 2
0
        internal static string EncodeHeaderValue(string value, Encoding encoding, bool base64Encoding)
        {
            StringBuilder builder = new StringBuilder();

            if ((encoding == null) && IsAscii(value, false))
            {
                return(value);
            }
            if (encoding == null)
            {
                encoding = Encoding.GetEncoding("utf-8");
            }
            string bodyName = encoding.BodyName();

            if (encoding == Encoding.BigEndianUnicode)
            {
                bodyName = "utf-16be";
            }
            builder.Append("=?");
            builder.Append(bodyName);
            builder.Append("?");
            builder.Append(base64Encoding ? "B" : "Q");
            builder.Append("?");
            byte[] bytes = encoding.GetBytes(value);
            if (base64Encoding)
            {
                Base64Stream stream = new Base64Stream(-1);
                stream.EncodeBytes(bytes, 0, bytes.Length, true);
                builder.Append(Encoding.ASCII.GetString(stream.WriteState.Buffer, 0, stream.WriteState.Length));
            }
            else
            {
                QuotedPrintableStream stream2 = new QuotedPrintableStream(-1);
                stream2.EncodeBytes(bytes, 0, bytes.Length);
                builder.Append(Encoding.ASCII.GetString(stream2.WriteState.Buffer, 0, stream2.WriteState.Length));
            }
            builder.Append("?=");
            return(builder.ToString());
        }