程序园

弹奏键盘人生,拂去青春的尘土,留下的只有岁月的痕迹
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

lumisoft邮件头不规范造成内容无法读取

Posted on 2017-02-16 15:30  程旭圆  阅读(177)  评论(0编辑  收藏  举报

解决邮件内容为multipart,并且Param_Boundary等于null的不规范邮件内容无法读取问题,这样的邮件内容头部往往带两个或多个ContentType。

红色为自己加的,绿色为注释掉原来的。

修改MIME_h_Collection.cs文件

#region method GetFirst

/// <summary>
/// Gets first header field with the specified name. returns null if specified header field doesn't exist.
/// </summary>
/// <param name="name">Header field name.</param>
/// <returns>Returns first header field with the specified name. returns null if specified header field doesn't exist.</returns>
/// <exception cref="ArgumentNullException">Is raised when <b>name</b> is null reference.</exception>
public MIME_h GetFirst(string name)
{
if(name == null){
throw new ArgumentNullException("name");
}
List<MIME_h> rl= m_pFields.FindAll(x => x.Name == name);
if (rl.Count > 0)
{
if (name != "Content-Type") return rl[0];
foreach (MIME_h field in rl)
{
if (!(field is MIME_h_ContentType))
{
throw new ParseException("Header field 'ContentType' parsing failed.");
}
MIME_h_ContentType h = (MIME_h_ContentType)field;
if (h.Type == "multipart" && h.Param_Boundary == null) continue;
return field;
}
}
//
//foreach (MIME_h field in m_pFields.ToArray())
//{
// if (string.Equals(name, field.Name, StringComparison.InvariantCultureIgnoreCase))
// {
// return field;
// }
//}
return null;
}

#endregion