共享quoted-printable解码(C#)

    今天终于把邮件的收发搞定,借助于jmail。虽然不是很满意,但基本功能都能实现。过程中,也遇到过不少问题,如解码问题,收未读邮件问题等等。
      邮件解码,一般分为base64和quoted-printable,在网上曾搜索过,但未找到C#版的(可能是未努力去找),只找到C++和C两个版本的。在这里,俺把C#版的quoted-printable解码发布出来,供大家分享:
 1 ContractedBlock.gif ExpandedBlockStart.gif quoted-printable解码 #region quoted-printable解码
 2InBlock.gif        private string QPUnEncryCode(string source)
 3ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 4InBlock.gif            source=source.Replace ("=\r\n","");
 5InBlock.gif            int len=source.Length ;
 6InBlock.gif            string dest=string.Empty ;
 7InBlock.gif            int i=0;
 8InBlock.gif            while(i<len)
 9ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
10InBlock.gif                string temp=source.Substring (i,1);
11InBlock.gif                if(temp=="=")
12ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
13InBlock.gif                    int code=Convert.ToInt32 (source.Substring (i+1,2),16);
14InBlock.gif                    if(Convert.ToInt32 (code.ToString (),10)<127
15ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{
16InBlock.gif                        dest+=((char)code).ToString ();
17InBlock.gif                        i=i+3;
18ExpandedSubBlockEnd.gif                    }

19InBlock.gif                    else  
20ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{
21ExpandedSubBlockStart.gifContractedSubBlock.gif                        dest+=System.Text.Encoding.Default.GetString(new byte []dot.gif{Convert.ToByte  (source.Substring (i+1,2),16),Convert.ToByte  (source.Substring (i+4,2),16)}) ;
22InBlock.gif                        i=i+6;
23ExpandedSubBlockEnd.gif                    }

24ExpandedSubBlockEnd.gif                }

25InBlock.gif                else
26ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
27InBlock.gif                    dest+=temp;
28InBlock.gif                    i++;
29ExpandedSubBlockEnd.gif                }

30ExpandedSubBlockEnd.gif            }

31InBlock.gif            return dest;
32ExpandedSubBlockEnd.gif        }

33InBlock.gif
34ExpandedBlockEnd.gif        #endregion

转载于:https://www.cnblogs.com/jerrie/archive/2006/07/29/462798.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值