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

12/3/2006来源:其它邮件服务器软件人气:7609

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

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

实际上是简体中文的HZ编码,在邮件中经常会出现,

因为邮件协议体系通常是七位的,而汉字却是双字节的

所以就使用以下的方法对其进行解码

String hzDecode(Match m){
String tmp=m.ToString();
byte[] ret=new byte[tmp.Length-4];
for(int i=0;i ret[i]=(byte)(tmp[i+2]+128);
return Encoding.GetEncoding(936).GetString(ret);
}


使用范例:
string strHz="~{4s strHz=Regex.Replace(strHz,@"~{(.+?)~}",new MatchEvaluator(hzDecode));
Response.Write(" HZ Decode="+strHz);


随便带上编码的代码(可用来发送邮件用)

String hzEncode(Match m){
byte[] tmp=Encoding.GetEncoding(936).GetBytes(m.ToString());
StringBuilder ret=new StringBuilder("~{");
for(int i=0;i ret.Append((char)(tmp[i]-128));
ret.Append("~}");
return ret.ToString();
}

使用范例:
string strHz="大家好,我是qiushuiwuhen,欢迎来到csdn.";
strHz=Regex.Replace(strHz,@"[^x00-xff]+",new MatchEvaluator(hzEncode));
Response.Write("

HZ Encode="+strHz);</P><P>原理:使用MatchEvaluator的回调(CallBack)函数执行Regex的替换操作</P>, </font><br> <div class="bdsharebuttonbox"><a href="#" class="bds_more" data-cmd="more"></a><a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信"></a><a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间"></a><a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博"></a><a href="#" class="bds_tqq" data-cmd="tqq" title="分享到腾讯微博"></a><a href="#" class="bds_renren" data-cmd="renren" title="分享到人人网"></a><a href="#" class="bds_bdysc" data-cmd="bdysc" title="分享到百度云收藏"></a><a href="#" class="bds_tieba" data-cmd="tieba" title="分享到百度贴吧"></a></div> <script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"32"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script> <br> <script type="text/javascript"> /*学院显示页 内容下*/ var cpro_id = "u2659928"; </script> <script type="text/javascript" src="http://cpro.baidustatic.com/cpro/ui/c.js"></script> <div style="font-size: 0px; height: 0px; clear: both;"></div> </div> </div> </div> <div class="zxtw mt20"> <div class="zxtwt cl"> <h3>优质网站模板</h3> </div> <div class="zxtwc"> <div class="bd"> <ul> <li> <div class="zxtwpic"><a href="http://moban.knowsky.com/mobanlist_14859.htm" title="电脑主机模板下载"><img src="http://s9.knowsky.com/moban/sjpg/2011120607402160953.jpg" border="0" alt="电脑主机模板下载"></a></div> <p><a href="http://moban.knowsky.com/mobanlist_14859.htm" title="电脑主机模板下载">电脑主机模板下载</a></p> </li> <li> <div class="zxtwpic"><a href="http://moban.knowsky.com/mobanlist_14858.htm" title="欧美打猎网站模板"><img src="http://s9.knowsky.com/moban/sjpg/2011120607402120331.jpg" border="0" alt="欧美打猎网站模板"></a></div> <p><a href="http://moban.knowsky.com/mobanlist_14858.htm" title="欧美打猎网站模板">欧美打猎网站模板</a></p> </li> <li> <div class="zxtwpic"><a href="http://moban.knowsky.com/mobanlist_14857.htm" title="棒球网站模板"><img src="http://s9.knowsky.com/moban/sjpg/2011120607402112533.jpg" border="0" alt="棒球网站模板"></a></div> <p><a href="http://moban.knowsky.com/mobanlist_14857.htm" title="棒球网站模板">棒球网站模板</a></p> </li> <li> <div class="zxtwpic"><a href="http://moban.knowsky.com/mobanlist_14856.htm" title="医院公司网站模板"><img src="http://s9.knowsky.com/moban/sjpg/2011120607402070325.jpg" border="0" alt="医院公司网站模板"></a></div> <p><a href="http://moban.knowsky.com/mobanlist_14856.htm" title="医院公司网站模板">医院公司网站模板</a></p> </li> <li> <div class="zxtwpic"><a href="http://moban.knowsky.com/mobanlist_14855.htm" title="欧美企业汽车模板"><img src="http://s9.knowsky.com/moban/sjpg/2011120607402064055.jpg" border="0" alt="欧美企业汽车模板"></a></div> <p><a href="http://moban.knowsky.com/mobanlist_14855.htm" title="欧美企业汽车模板">欧美企业汽车模板</a></p> </li> <li> <div class="zxtwpic"><a href="http://moban.knowsky.com/mobanlist_14854.htm" title="娱乐休闲音乐模板"><img src="http://s9.knowsky.com/moban/sjpg/2011120607402023444.jpg" border="0" alt="娱乐休闲音乐模板"></a></div> <p><a href="http://moban.knowsky.com/mobanlist_14854.htm" title="娱乐休闲音乐模板">娱乐休闲音乐模板</a></p> </li> <li> <div class="zxtwpic"><a href="http://moban.knowsky.com/mobanlist_14853.htm" title="欧美音乐网站模板"><img src="http://s9.knowsky.com/moban/sjpg/2011120607402014097.jpg" border="0" alt="欧美音乐网站模板"></a></div> <p><a href="http://moban.knowsky.com/mobanlist_14853.htm" title="欧美音乐网站模板">欧美音乐网站模板</a></p> </li> <li> <div class="zxtwpic"><a href="http://moban.knowsky.com/mobanlist_14852.htm" title="欧美音乐网站模板"><img src="http://s9.knowsky.com/moban/sjpg/2011120607401978185.jpg" border="0" alt="欧美音乐网站模板"></a></div> <p><a href="http://moban.knowsky.com/mobanlist_14852.htm" title="欧美音乐网站模板">欧美音乐网站模板</a></p> </li> <li> <div class="zxtwpic"><a href="http://moban.knowsky.com/mobanlist_14851.htm" title="旅游网站模板"><img src="http://s9.knowsky.com/moban/sjpg/2011120607401971825.jpg" border="0" alt="旅游网站模板"></a></div> <p><a href="http://moban.knowsky.com/mobanlist_14851.htm" title="旅游网站模板">旅游网站模板</a></p> </li> <li> <div class="zxtwpic"><a href="http://moban.knowsky.com/mobanlist_14850.htm" title="鱼模板下载"><img src="http://s9.knowsky.com/moban/sjpg/2011120607401948464.jpg" border="0" alt="鱼模板下载"></a></div> <p><a href="http://moban.knowsky.com/mobanlist_14850.htm" title="鱼模板下载">鱼模板下载</a></p> </li> <li> <div class="zxtwpic"><a href="http://moban.knowsky.com/mobanlist_14849.htm" title="模特时尚网站模板"><img src="http://s9.knowsky.com/moban/sjpg/2011120607401939057.jpg" border="0" alt="模特时尚网站模板"></a></div> <p><a href="http://moban.knowsky.com/mobanlist_14849.htm" title="模特时尚网站模板">模特时尚网站模板</a></p> </li> <li> <div class="zxtwpic"><a href="http://moban.knowsky.com/mobanlist_14848.htm" title="音乐网站模板"><img src="http://s9.knowsky.com/moban/sjpg/2011120607401893782.jpg" border="0" alt="音乐网站模板"></a></div> <p><a href="http://moban.knowsky.com/mobanlist_14848.htm" title="音乐网站模板">音乐网站模板</a></p> </li> </ul> </div> <div class="hd"> <ul><li class="on">1</li><li class="">2</li><li class="">3</li></ul> </div> <div class="slider-nav"> <a href="javascript:void(0)" class="prev"></a> <a href="javascript:void(0)" class="next"></a> </div> </div> </div> <script type="text/javascript"> jq(".zxtw").slide({ mainCell:".bd ul", effect:"leftLoop", vis:4, scroll:4,interTime:5000,autoPlay:true});</script> <div class="box mt20"> <script type="text/javascript"> /*多彩标签*/ var cpro_id = "u2662353"; </script> <script src="http://cpro.baidustatic.com/cpro/ui/c.js" type="text/javascript"></script> </div> </div> <div class="w300 y"> <div class="ad mb20"> <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:inline-block;width:300px;height:300px" data-ad-client="ca-pub-6565147514244127" data-ad-slot="1127493168"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <div class="aside"> <div class="subcate border mb20"> <div class="asidetit cl"> <h3>邮件系统软件文章分类</h3> </div> <div class="subcatec"> <ul> <li><i></i><a href="http://www.knowsky.com/article.asp?typeid=120">Qmail</a></li> <li><i></i><a href="http://www.knowsky.com/article.asp?typeid=121">IMail Server</a></li> <li><i></i><a href="http://www.knowsky.com/article.asp?typeid=122">MDaemon Server</a></li> <li><i></i><a href="http://www.knowsky.com/article.asp?typeid=123">Exchange Server</a></li> <li><i></i><a href="http://www.knowsky.com/article.asp?typeid=124">Lotus Notes</a></li> <li><i></i><a href="http://www.knowsky.com/article.asp?typeid=125">其它邮件服务器软件</a></li> </ul> </div> </div> <div class="ad mb20"> <script type="text/javascript"> /*学院右则*/ var cpro_id = "u2656701"; </script> <script type="text/javascript" src="http://cpro.baidustatic.com/cpro/ui/c.js"></script> </div> <div class="catecommentrank border mb20"> <div class="asidetit cl"> <h3>最新文章推荐</h3> </div> <div class="asidelist caterankc"> <ul> <li class="cl"><em class="no1">1</em><a href="http://www.knowsky.com/341828.html" title="使用Magic Winmail Server轻松架设邮件服务器(一)">使用Magic Winmail Server轻松架设</a></li><li class="cl"><em class="no1">2</em><a href="http://www.knowsky.com/341827.html" title="使用Magic Winmail Server轻松架设邮件服务器(二)">使用Magic Winmail Server轻松架设</a></li><li class="cl"><em class="no1">3</em><a href="http://www.knowsky.com/341826.html" title="使用Magic Winmail Server轻松架设邮件服务器(三)">使用Magic Winmail Server轻松架设</a></li><li class="cl"><em class="no1">4</em><a href="http://www.knowsky.com/341825.html" title="使用Magic Winmail Server轻松架设邮件服务器(四)">使用Magic Winmail Server轻松架设</a></li><li class="cl"><em class="no1">5</em><a href="http://www.knowsky.com/341824.html" title="使用Magic Winmail Server轻松架设邮件服务器(五)">使用Magic Winmail Server轻松架设</a></li><li class="cl"><em class="no1">6</em><a href="http://www.knowsky.com/341823.html" title="使用Magic Winmail Server轻松架设邮件服务器(六)">使用Magic Winmail Server轻松架设</a></li><li class="cl"><em class="no1">7</em><a href="http://www.knowsky.com/341822.html" title="使用Magic Winmail Server轻松架设邮件服务器(七)">使用Magic Winmail Server轻松架设</a></li><li class="cl"><em class="no1">8</em><a href="http://www.knowsky.com/341821.html" title="如何能让Webmail运行在IIS/PWS环境中(一)">如何能让Webmail运行在IIS/PWS环境中(一)</a></li><li class="cl"><em class="no1">9</em><a href="http://www.knowsky.com/341820.html" title="如何能让Webmail运行在IIS/PWS环境中(二)">如何能让Webmail运行在IIS/PWS环境中(二)</a></li><li class="cl"><em class="no1">10</em><a href="http://www.knowsky.com/341819.html" title="如何能让Webmail运行在IIS/PWS环境中(三)">如何能让Webmail运行在IIS/PWS环境中(三)</a></li> </ul> </div> </div> <div class="catecommentrank border mb20"> <div class="asidetit cl"> <h3>邮件系统软件推荐</h3> </div> <div class="asidelist caterankc"> <ul><li class="cl"><em class="no1">1</em><a href="http://www.knowsky.com/343318.html" title="qmail+vpopmail+mysql+qmailadmin+ezmlm+igenus构建企业邮局">qmail+vpopmail+mysql+qmail</a></li><li class="cl"><em class="no1">2</em><a href="http://www.knowsky.com/343317.html" title="通过qmailadmin来实现qmail下的域空间设置">通过qmailadmin来实现qmail下的域空间设置</a></li><li class="cl"><em class="no1">3</em><a href="http://www.knowsky.com/343316.html" title="Redhat 7.2下qmail安装(一)">Redhat 7.2下qmail安装(一)</a></li><li class="cl"><em class="no1">4</em><a href="http://www.knowsky.com/343315.html" title="Redhat 7.2下qmail安装(二)">Redhat 7.2下qmail安装(二)</a></li><li class="cl"><em class="no1">5</em><a href="http://www.knowsky.com/343314.html" title="qmail邮件系统安装(freebsd 3.4)">qmail邮件系统安装(freebsd 3.4)</a></li><li class="cl"><em class="no1">6</em><a href="http://www.knowsky.com/343313.html" title="Qmail邮件系统下防止滥用mail relay完全解决方案">Qmail邮件系统下防止滥用mail relay完全</a></li><li class="cl"><em class="no1">7</em><a href="http://www.knowsky.com/343312.html" title="Qmail使用SMTP发信的设置问题集">Qmail使用SMTP发信的设置问题集</a></li><li class="cl"><em class="no1">8</em><a href="http://www.knowsky.com/343311.html" title="SMTP-AUTH:Qmail+vpopmail(转)">SMTP-AUTH:Qmail+vpopmail(转)</a></li><li class="cl"><em class="no1">9</em><a href="http://www.knowsky.com/343310.html" title="qmail+vpopmail邮件过滤(练习篇)">qmail+vpopmail邮件过滤(练习篇)</a></li><li class="cl"><em class="no1">10</em><a href="http://www.knowsky.com/343309.html" title="Linux邮件服务器软件比较">Linux邮件服务器软件比较</a></li> </ul> </div> </div> </div> </div> <div class="clear"></div> </div> </div> <script type="text/javascript"> /*学院图加*/ var cpro_id = "u2656836"; </script> <script type="text/javascript" src="http://cpro.baidustatic.com/cpro/ui/i.js"></script> <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https'){ bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else{ bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> <div class="footer"> <div class="main"> <p><a href="http://wpa.qq.com/msgrd?v=3&uin=1783983&site=qq&menu=yes" target="_blank">广告刊登</a> | <a href="http://wpa.qq.com/msgrd?v=3&uin=1783983&site=qq&menu=yes" target="_blank">版权声明</a> | <a href="http://wpa.qq.com/msgrd?v=3&uin=1783983&site=qq&menu=yes" target="_blank">联系我们</a> | <a href="http://m.knowsky.com">移动版</a></p><p>Copyright © 2000-2017 www.knowsky.com All rights reserved | 沪ICP备05001343号</p> </div> </div> <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> <script type="text/javascript"> jq(".slide").slide({ mainCell:".bd ul",titCell:".hd ul",delayTime:300,interTime:3000,effect:"fade",autoPlay:true,autoPage:true,switchLoad:"_src"}); jq(".slide").each(function(s){ jq(this).hover( function(){ jq(this).children(".slider-nav").show(); }, function(){ jq(this).children(".slider-nav").hide(); }) }) jq(".slb").slide({ mainCell:".bd ul",titCell:".hd ul",delayTime:300,interTime:3000,effect:"leftLoop",autoPlay:true,autoPage:true,switchLoad:"_src"}); </script> <script type="text/javascript"> jq(".topnav li.dropdown").each(function(s){ jq(this).hover(function(){ jq(this).addClass("hover"); },function(){ jq(this).removeClass("hover"); }) }) </script> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "//hm.baidu.com/hm.js?a89960924c54901de40c2bead6702d5c"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> <script type="text/javascript"> /*knowsky统一悬浮*/ var cpro_id = "u2868460"; </script> <script type="text/javascript" src="http://cpro.baidustatic.com/cpro/ui/c.js"></script> <script> (function(){ var src = (document.location.protocol == "http:") ? "http://js.passport.qihucdn.com/11.0.1.js?ace780b426d47cac8ab65a3e85eb9406":"https://jspassport.ssl.qhimg.com/11.0.1.js?ace780b426d47cac8ab65a3e85eb9406"; document.write('<script src="' + src + '" id="sozz"><\/script>'); })(); </script> </body> </html>