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

解决邮件内容为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

原文地址:https://www.cnblogs.com/xueyuan299/p/6405952.html