Original article:
Http://www.cnblogs.com/jerrie/archive/2006/07/29/462798.html#commentform
Today, we finally completed the sending and receiving of emails with jmail. Although not satisfied, the basic functions can be implemented. During the process, we also encountered many problems, such as decoding and unread emails.
Email decoding is generally divided into base64 and quoted-printable. I have searched the internet, but I have not found Version C # (maybe I have not tried to find it ), only the C ++ and C versions are available. Here, I will publish the quoted-printable Decoding of C # For your sharing:
1quoted-printable decoding # region quoted-printable Decoding
2 Private string qpunencrycode (string source)
3 {
4 Source = source. Replace ("= \ r \ n ","");
5 Int Len = source. length;
6 string DEST = string. empty;
7 int I = 0;
8 while (I <Len)
9 {
10 string temp = source. substring (I, 1 );
11 if (temp = "= ")
12 {
13 int code = convert. toint32 (source. substring (I + 1, 2), 16 );
14 if (convert. toint32 (code. tostring (), 10) <127)
15 {
16 DEST + = (char) Code). tostring ();
17 I = I + 3;
18}
19 else
20 {
21 DEST + = system. text. encoding. default. getstring (New byte [] {convert. tobyte (source. substring (I + 1, 2), 16), convert. tobyte (source. substring (I + 4, 2), 16 )});
22 I = I + 6;
23}
24}
25 else
26 {
27 DEST + = temp;
28 I ++;
29}
30}
31 return DEST;
32}
33
34 # endregion