在Lumisoft.NET组件获取POP3邮件的时候,发现大多数邮件都能正常获取,不过对于一些特殊的邮件,好像总是会出现转换错误,或者出现乱码及部分乱码现象,有些在标题里面或者邮件接收人地址,而有些则在内容里面,为了更好整理相关的问题,写了本文,希望对大家使用该组件有一定的帮助作用。
1、 日期转换出错问题。
错误信息:[2013-05-04 10:49:03] 转换邮件的Date出错:账号wuhuacong@163.com 邮件标题:ICP???????????????????????wuhuacong)
LumiSoft.Net.ParseException: Header field 'Date' parsing failed.
在 LumiSoft.Net.Mail.Mail_Message.get_Date()
在 WHC.PlugInService.Pop3Helper.Receive() 位置 ......\Pop3Helper.cs:行号 160
错误原因:由于邮件格式的日期内容格式不同,导致无法正常解析。如一般的格式为下面
官方的代码如下所示
MIME_h h = this.Header.GetFirst("Date");
if(h != null){
try{
return MIME_Utils.ParseRfc2822DateTime(((MIME_h_Unstructured)h).Value);
}
catch{
throw new ParseException("Header field 'Date' parsing failed.");
}
}
else{
return DateTime.MinValue;
}
}
set{
if(this.IsDisposed){
throw new ObjectDisposedException(this.GetType().Name);
}
if(value == DateTime.MinValue){
this.Header.RemoveAll("Date");
}
else{
MIME_h h = this.Header.GetFirst("Date");
if(h == null){
this.Header.Add(new MIME_h_Unstructured("Date",MIME_Utils.DateTimeToRfc2822(value)));
}
else{
this.Header.ReplaceFirst(new MIME_h_Unstructured("Date",MIME_Utils.DateTimeToRfc2822(value)));
}
}
}
}
</div>
需要增加对普通日期格式的修改,修改后的代码如下所示
MIME_h h = this.Header.GetFirst("Date");
if(h != null){
try{
return MIME_Utils.ParseRfc2822DateTime(((MIME_h_Unstructured)h).Value);
}
catch{
&