Example #1
0
        public byte[] decodeBinary(string text)
        {
            MemoryStream bin = new MemoryStream();
            LL1          rr  = new LL1(text);

            while (!rr.EOF)
            {
                char c = rr.read();
                if (c == '=')
                {
                    string t = rr.readStr(2);
                    if (t == null)
                    {
                        bin.WriteByte((byte)'=');
                    }
                    else
                    {
                        bin.WriteByte(Convert.ToByte(t, 16));
                    }
                }
                else
                {
                    bin.WriteByte((byte)c);
                }
            }
            return(bin.ToArray());
        }
Example #2
0
        public static string decode(string text)
        {
            LL1           rr  = new LL1(text);
            StringBuilder res = new StringBuilder();

            while (!rr.EOF)
            {
                if (rr.compare("=?", true))
                {
                    res.Append(parseEncode(rr));
                }
                else
                {
                    res.Append(rr.read());
                }
            }
            return(res.ToString());
        }
Example #3
0
        static string parseEncode(LL1 rr)
        {
            Encoding enc = null;

            if (rr.compareNoCase("ISO-2022-JP?B?", true))
            {
                enc = Encoding.GetEncoding("iso-2022-jp");
            }
            else if (rr.compareNoCase("SHIFT_JIS?B?", true))
            {
                enc = Encoding.GetEncoding(932);
            }
            else if (rr.compareNoCase("UTF-8?B?", true))
            {
                enc = Encoding.UTF8;
            }

            if (enc != null)
            {
                string bEnc = "";
                while (true)
                {
                    if (rr.compare("?=", true))
                    {
                        break;
                    }
                    string text = rr.readStr(4);
                    if (text == null)
                    {
                        throw new ArgumentException("不正なSubjectEncoding", rr.peekStr(10));
                    }
                    bEnc += text;
                }
                return(enc.GetString(Convert.FromBase64String(bEnc)));
            }
            else
            {
                throw new NotSupportedException("不明な文字コードでした");
            }
        }
Example #4
0
 public byte[] decodeBinary(string text) {
     MemoryStream bin = new MemoryStream();
     LL1 rr = new LL1(text);
     while (!rr.EOF) {
         char c = rr.read();
         if (c == '=') {
             string t = rr.readStr(2);
             if (t == null) bin.WriteByte((byte)'=');
             else bin.WriteByte(Convert.ToByte(t, 16));
         }
         else {
             bin.WriteByte((byte)c);
         }
     }
     return bin.ToArray();
 }
Example #5
0
        static string parseEncode(LL1 rr) {
            Encoding enc = null;

            if (rr.compareNoCase("ISO-2022-JP?B?", true))
                enc = Encoding.GetEncoding("iso-2022-jp");
            else if (rr.compareNoCase("SHIFT_JIS?B?", true))
                enc = Encoding.GetEncoding(932);
            else if (rr.compareNoCase("UTF-8?B?", true))
                enc = Encoding.UTF8;

            if (enc != null) {
                string bEnc = "";
                while (true) {
                    if (rr.compare("?=", true)) {
                        break;
                    }
                    string text = rr.readStr(4);
                    if (text == null)
                        throw new ArgumentException("不正なSubjectEncoding", rr.peekStr(10));
                    bEnc += text;
                }
                return enc.GetString(Convert.FromBase64String(bEnc));
            }
            else {
                throw new NotSupportedException("不明な文字コードでした");
            }
        }
Example #6
0
 public static string decode(string text) {
     LL1 rr = new LL1(text);
     StringBuilder res = new StringBuilder();
     while (!rr.EOF) {
         if (rr.compare("=?", true)) {
             res.Append(parseEncode(rr));
         }
         else {
             res.Append(rr.read());
         }
     }
     return res.ToString();
 }