Shared quoted-printable decoding (C #)-reprint

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.