Exemplo n.º 1
0
        public void TestEncode()
        {
            //=?utf-8?B?UEZFbWFpbE1xX3Byb2R1Y2VyX+S8muWRmOi1hOaWmeihqA==?=
            string s1 = "UEZFbWFpbE1xX3Byb2R1Y2VyX+S8muWRmOi1hOaWmeihqA==";
            var    v1 = PFDataHelper.Decode(s1, PFEncodeType.Base64, PFEncodeType.UTF8);

            Assert.IsTrue(v1 == "PFEmailMq_producer_会员资料表");
            var r1 = PFDataHelper.Encode(v1, PFEncodeType.Base64, PFEncodeType.UTF8);

            Assert.IsTrue(r1 == s1);

            //=?gb18030?B?UEZFbWFpbE1xX3Byb2R1Y2VyX2Zyb21RUU1haWxf?=
            string s2 = "UEZFbWFpbE1xX3Byb2R1Y2VyX2Zyb21RUU1haWxf";
            var    v2 = PFDataHelper.Decode(s2, PFEncodeType.Bit8, PFEncodeType.GB18030);

            Assert.IsTrue(v2 == "PFEmailMq_producer_fromQQMail_");
            var r2 = PFDataHelper.Encode(v2, PFEncodeType.Bit8, PFEncodeType.GB18030);

            Assert.IsTrue(r2 == s2);

            //qqmail body
            string s3 = "MjAxOS4wMdTCveHK/b7dsbi33cfpv/Y6DQoNCiANCiANCmFhYQ0KIA0KYmJi";
            var    v3 = PFDataHelper.Decode(s3, PFEncodeType.Bit8, PFEncodeType.GB18030);

            Assert.IsTrue(v2 == "PFEmailMq_producer_fromQQMail_");
            //var r2 = PFDataHelper.Encode(v2, PFEncodeType.Bit8, PFEncodeType.GB18030);
            //Assert.IsTrue(r2 == s2);

            //126mail Subject: =?GBK?Q?PFEmailMq=5Fproducer?=
            //=?GBK?Q?=5Ffrom126Mail=5F=BB=E1=D4=B1=D7=CA=C1=CF=B1=ED?=
            var s4 = "PFEmailMq=5Fproducer";
            var v4 = PFDataHelper.Decode(s4, PFEncodeType.QuotedPrintable, PFEncodeType.GBK);

            Assert.IsTrue(v4 == "PFEmailMq_producer");
            var s5 = "=5Ffrom126Mail=5F=BB=E1=D4=B1=D7=CA=C1=CF=B1=ED";
            var v5 = PFDataHelper.Decode(s5, PFEncodeType.QuotedPrintable, PFEncodeType.GBK);

            Assert.IsTrue(v5 == "_from126Mail_会员资料表");

            //aliyunEmail
            //PGRpdiBjbGFzcz0iX19hbGl5dW5fZW1haWxfYm9keV9ibG9jayI+PGRpdiAgc3R5bGU9ImxpbmUt
            var s6 = "PGRpdiBjbGFzcz0iX19hbGl5dW5fZW1haWxfYm9keV9ibG9jayI+PGRpdiAgc3R5bGU9ImxpbmUt";
            var v6 = PFDataHelper.Decode(s6, PFEncodeType.Base64, PFEncodeType.UTF8);

            Assert.IsTrue(v6 == "<div class=\"__aliyun_email_body_block\"><div  style=\"line-");

            var s7 = "<html xmlns:v=3D\"urn:schemas-microsoft-com:vml\" ";//只要没最后的等号就不报错
            var v7 = PFDataHelper.Decode(s7, PFEncodeType.QuotedPrintable, PFEncodeType.GB2312);
            //正确是  <html xmlns:v="urn:schemas-microsoft-com:vml" %
            //参考http://web.chacuo.net/charsetquotedprintable/


            //=?GB2312?B?16q3ojogRnc6IMfryr4=?=
            string s8 = "16q3ojogRnc6IMfryr4=";
            var    v8 = PFDataHelper.Decode(s8, PFEncodeType.Bit8, PFEncodeType.GB2312);

            Assert.IsTrue(v8 == "转发: Fw: 请示");
            var r8 = PFDataHelper.Encode(v8, PFEncodeType.Bit8, PFEncodeType.GB2312);

            Assert.IsTrue(r8 == s8);
        }