1+ using System ;
2+ using ActiveUp . Net . Mail ;
3+ using NUnit . Framework ;
4+
5+ namespace ActiveUp . Net . Tests . Common
6+ {
7+ public class CodecTests
8+ {
9+ /// <summary>
10+ /// Headers to be decoded
11+ /// </summary>
12+ private static string [ ] sampleEncodedHeaders = new [ ]
13+ {
14+ "From: =?US-ASCII?Q?Keith_Moore?= <[email protected] >" , 15+ "To: =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= <[email protected] >" , 16+ "CC: =?ISO-8859-1?Q?Andr=E9?= Pirard <[email protected] >" , 17+ "Subject: =?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=\n =?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=" ,
18+ "From: =?ISO-8859-1?Q?Olle_J=E4rnefors?= <[email protected] >" , 19+ 20+ "Subject: Time for ISO 10646?" ,
21+ "To: Dave Crocker <[email protected] >" , 22+ 23+ "From: =?ISO-8859-1?Q?Patrik_F=E4ltstr=F6m?= <[email protected] >" , 24+ "Subject: Re: RFC-HDR care and feeding" ,
25+ "To: Greg Vaudreuil <[email protected] >, Ned Freed\n <[email protected] >, Keith Moore <[email protected] >" , 26+ "Subject: Test of new header generator" ,
27+ "MIME-Version: 1.0" ,
28+ "Content-type: text/plain; charset=ISO-8859-1" ,
29+ "(=?ISO-8859-1?Q?a?=)" ,
30+ "(=?ISO-8859-1?Q?a?= b)" ,
31+ "(=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?=)" ,
32+ "(=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?=)" ,
33+ "(=?ISO-8859-1?Q?a?=\n =?ISO-8859-1?Q?b?=)" ,
34+ "(=?ISO-8859-1?Q?a_b?=)" ,
35+ "(=?ISO-8859-1?Q?a?= =?ISO-8859-2?Q?_b?=)"
36+ } ;
37+
38+ /// <summary>
39+ /// Decoded headers
40+ /// </summary>
41+ private static string [ ] expectedDecodedHeaders = new [ ]
42+ {
43+ "From: Keith Moore <[email protected] >" , 44+ "To: Keld Jørn Simonsen <[email protected] >" , 45+ "CC: André Pirard <[email protected] >" , 46+ "Subject: If you can read this you understand the example." ,
47+ "From: Olle Järnefors <[email protected] >" , 48+ 49+ "Subject: Time for ISO 10646?" ,
50+ "To: Dave Crocker <[email protected] >" , 51+ 52+ "From: Patrik Fältström <[email protected] >" , 53+ "Subject: Re: RFC-HDR care and feeding" ,
54+ "To: Greg Vaudreuil <[email protected] >, Ned Freed\n <[email protected] >, Keith Moore <[email protected] >" , 55+ "Subject: Test of new header generator" ,
56+ "MIME-Version: 1.0" ,
57+ "Content-type: text/plain; charset=ISO-8859-1" ,
58+ "(a)" ,
59+ "(a b)" ,
60+ "(ab)" ,
61+ "(ab)" ,
62+ "(ab)" ,
63+ "(a b)" ,
64+ "(a b)"
65+ } ;
66+
67+ [ Test ]
68+ public void should_handle_examples_from_the_rfc_2047 ( )
69+ {
70+ for ( var i = 0 ; i < sampleEncodedHeaders . GetLength ( 0 ) ; i ++ )
71+ Codec . RFC2047Decode ( sampleEncodedHeaders [ i ] ) . ShouldEqual ( expectedDecodedHeaders [ i ] ) ;
72+ }
73+
74+ [ Test ]
75+ public void should_decode_RFC2047_encoded_words ( )
76+ {
77+ // Second, ensure that an encoded sentence from Codec.RFC2047Encode is correctly decoded
78+ var sampleText = "Je suis Liégeois et je suis prêt à rencontrer Asger Jørnow" ;
79+ var encodedText = Codec . RFC2047Encode ( sampleText , "iso-8859-1" ) ;
80+ sampleText . ShouldEqual ( Codec . RFC2047Decode ( encodedText ) ) ;
81+ }
82+
83+ [ Test ]
84+ public void toto ( )
85+ {
86+ var decodedString = Codec . RFC2047Decode (
87+ @"=?utf-8?B?0JjQpNClIC0gKtCT0LDQt9C/0YDQvtC8KiDQvtGC0LzQtdC9?=
88+ =?utf-8?B?0LjQuyDRgtC10L3QtNC10YDRiyDQvdCwINC30LDQutGD0L/QutGDINGC?=
89+ =?utf-8?B?0YDRg9CxINCx0L7Qu9GM0YjQvtCz0L4g0LTQuNCw0LzQtdGC0YDQsCDQ?=
90+ =?utf-8?B?vdCwIDEyINC80LvRgNC0INGA0YPQsdC70LXQuS4=?=" ) ;
91+
92+ decodedString . ShouldEqual ( "ИФХ - *Газпром* отменил тендеры на закупку труб большого диаметра на 12 млрд рублей." ) ;
93+ }
94+
95+ [ Test ]
96+ public void should_handle_mixed_content ( )
97+ {
98+ var decodedString = Codec . RFC2047Decode ( "This is some russian:\t =?utf-8?B?0JjQpNClIC0gKtCT0LDQt9C/0YDQvtC8KiDQvtGC0LzQtdC9?= wasn't that cool?" ) ;
99+
100+ decodedString . ShouldEqual ( "This is some russian:\t ИФХ - *Газпром* отмен wasn't that cool?" ) ;
101+ }
102+
103+ [ Test ]
104+ public void should_support_different_encoding_after_line_break ( )
105+ {
106+ throw new NotImplementedException ( ) ;
107+ }
108+
109+ [ Test ]
110+ public void should_test_one_word ( )
111+ {
112+ throw new NotImplementedException ( ) ;
113+ }
114+
115+ [ Test ]
116+ public void should_test_one_space ( )
117+ {
118+ throw new NotImplementedException ( ) ;
119+ }
120+ }
121+ }
0 commit comments