自制Pop3邮件接收系统(一):利用MatchEvaluator实现HZ的解码

要作自制的Pop3邮件接收系统,就要自己处理邮件的编码

大家可能会收到以下的“乱码”,
~{4s

 1<r:c#,nrjg~}qiushuiwuhen~{#,;6s-@45=~}csdn. ;="" byte[]="" byte[tmp.length-4];="" decode="+strHz); 
 2
 3  
 4随便带上编码的代码(可用来发送邮件用) 
 5
 6String hzEncode(Match m){   
 7byte[] tmp=Encoding.GetEncoding(936).GetBytes(m.ToString());   
 8StringBuilder ret=new StringBuilder(" encoding.getencoding(936).getstring(ret);="" for(int="" hzdecode(match="" i="0;i&lt;tmp.Length;i++)" m){="" matchevaluator(hzdecode));="" matchevaluator(hzencode));="" response.write("<xmp="" response.write("\nhz="" ret="new" ret.append("~}");="" ret.append((char)(tmp[i]-128));="" ret.tostring();="" ret[i]="(byte)(tmp[i+2]+128);" return="" strhz='Regex.Replace(strHz,@"[^\x00-\xff]+",new' string="" tmp="m.ToString();" }="" ~{");="" 使用范例:="" 因为邮件协议体系通常是七位的,而汉字却是双字节的="" 实际上是简体中文的hz编码,在邮件中经常会出现,="" 所以就使用以下的方法对其进行解码="">HZ Encode="+strHz); 
 9
10原理:使用MatchEvaluator的回调(CallBack)函数执行Regex的替换操作</r:c#,nrjg~}qiushuiwuhen~{#,;6s-@45=~}csdn.>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus