예제 #1
0
        public void should_decode_RFC2047_encoded_words()
        {
            // Second, ensure that an encoded sentence from Codec.RFC2047Encode is correctly decoded
            var sampleText  = "Je suis Liégeois et je suis prêt à rencontrer Asger Jørnow";
            var encodedText = Rfc2047Codec.Encode(sampleText, "iso-8859-1");

            sampleText.ShouldEqual(Rfc2047Codec.Decode(encodedText));
        }
예제 #2
0
        public void should_remove_trailing_equals_when_grouping_base64_encoded_words()
        {
            var input = " =?UTF-8?B?KDIpICpCT01CQVJESUVSIENFTyBTQVlTIExPT0tJTkcgRg==?= =?UTF-8?B?T1JXQVJEIFRPIEhJR0gtU1BFRUQgVFJBSU5TIElOIFUuUw==?=";

            var decodedString = Rfc2047Codec.Decode(input);

            decodedString.ShouldEqual("(2) *BOMBARDIER CEO SAYS LOOKING FORWARD TO HIGH-SPEED TRAINS IN U.S");
        }
예제 #3
0
        public void should_handle_strings_with_space_in_front()
        {
            var input = " [email protected]\r";

            var decodedString = Rfc2047Codec.Decode(input);

            decodedString.ShouldEqual(" [email protected]\r");
        }
예제 #4
0
        public void should_split_string_using_a_single_token()
        {
            var input = "i like pineapples";

            var parts = Rfc2047Codec.TokenizeOnLinearWhiteSpace(input);

            parts.ShouldEqual(new[] { "i", " ", "like", " ", "pineapples" });
        }
예제 #5
0
        public void should_group_different_separators_at_the_end_of_the_input()
        {
            var input = " i like pineapples\t \r\n";

            var parts = Rfc2047Codec.TokenizeOnLinearWhiteSpace(input);

            parts.ShouldEqual(new[] { " ", "i", " ", "like", " ", "pineapples", "\t \r\n" });
        }
예제 #6
0
        public void should_handle_delimiters_on_the_sides_of_the_string()
        {
            var input = " i like\tpineapples ";

            var parts = Rfc2047Codec.TokenizeOnLinearWhiteSpace(input);

            parts.ShouldEqual(new[] { " ", "i", " ", "like", "\t", "pineapples", " " });
        }
예제 #7
0
        public void should_handle_multi_byte_unicode_chars_spanning_over_multiple_words()
        {
            var decodedString = Rfc2047Codec.Decode(
                @"=?utf-8?B?0JjQpNClIC0gKtCT0LDQt9C/0YDQvtC8KiDQvtGC0LzQtdC9?=
 =?utf-8?B?0LjQuyDRgtC10L3QtNC10YDRiyDQvdCwINC30LDQutGD0L/QutGDINGC?=
 =?utf-8?B?0YDRg9CxINCx0L7Qu9GM0YjQvtCz0L4g0LTQuNCw0LzQtdGC0YDQsCDQ?=
 =?utf-8?B?vdCwIDEyINC80LvRgNC0INGA0YPQsdC70LXQuS4=?=");

            decodedString.ShouldEqual("ИФХ - *Газпром* отменил тендеры на закупку труб большого диаметра на 12 млрд рублей.");
        }
예제 #8
0
 /// <summary>
 /// Decodes the given string from the format specified in RFC 2047 (=?charset?value?=).
 /// </summary>
 /// <param name="input">The string to be decoded.</param>
 /// <returns>The decoded string.</returns>
 /// <example>
 /// The example below illustrates the decoding of a string.
 /// <code>
 /// C#
 ///
 /// string input = "I once wrote that =?iso-8859-1?B?QWN0aXZlTWFpbCByb2NrcyAhIEhlcmUgYXJlIHNvbWUgd2VpcmQgY2hhcmFjdGVycyA95y4=?=";
 /// string output = Codec.RFC2047Decode(input);
 /// </code>
 ///
 /// output returns I once wrote that ActiveMail rocks ! Here are some weird characters =ç.
 /// </example>
 public static string RFC2047Decode(string input)
 {
     return(Rfc2047Codec.Decode(input));
 }
예제 #9
0
 /// <summary>
 /// Encodes the given string in a format (specified in RFC 2047) that can be used in RFC 2822 headers to represent non-ASCII textual data.
 /// </summary>
 /// <param name="input">The string to be encoded (the Header field's value).</param>
 /// <param name="charset">The charset of the Header field's value.</param>
 /// <returns>The encoded string with only 7bit characters.</returns>
 /// <remarks>ActiveMail only encodes in this format using Base64, but the RFC2047Decode method also decodes string encoded in this format with quoted-printable.</remarks>
 /// <example>
 /// The example below illustrates the encoding of a string.
 /// <code>
 /// C#
 ///
 /// string input = "ActiveMail rocks ! Here are some non-ASCII characters =ç.";
 /// string output = Codec.RFC2047Encode(input,"iso-8859-1");
 /// </code>
 ///
 /// output returns =?iso-8859-1?B?QWN0aXZlTWFpbCByb2NrcyAhIEhlcmUgYXJlIHNvbWUgd2VpcmQgY2hhcmFjdGVycyA95y4=?=
 ///
 /// This value can be used as for example the subject of a message.
 /// If you suspect the text to contain non ASCII characters, do message.Subject = Codec.RFC2047Encode(yourRawValue);.
 /// </example>
 public static string RFC2047Encode(string input, string charset)
 {
     return(Rfc2047Codec.Encode(input, charset));
 }
예제 #10
0
        public void should_handle_examples_from_the_rfc_2047(DecodingSample decodingSample)
        {
            var decodedHeader = Rfc2047Codec.Decode(decodingSample.SampleEncodedHeader);

            decodedHeader.ShouldEqual(decodingSample.ExpectedDecodedHeader);
        }
예제 #11
0
        public void should_handle_mixed_content()
        {
            var decodedString = Rfc2047Codec.Decode("This is some russian:\t=?utf-8?B?0JjQpNClIC0gKtCT0LDQt9C/0YDQvtC8KiDQvtGC0LzQtdC9?= wasn't that cool?");

            decodedString.ShouldEqual("This is some russian:\tИФХ - *Газпром* отмен wasn't that cool?");
        }