修改MIME_b_Text.cs文件,红色字体为添加的部分,绿色为修改部分
private static Encoding m_pEncoding = Encoding.Default;
#region static method Parse
/// <summary>
/// Parses body from the specified stream
/// </summary>
/// <param name="owner">Owner MIME entity.</param>
/// <param name="defaultContentType">Default content-type for this body.</param>
/// <param name="stream">Stream from where to read body.</param>
/// <returns>Returns parsed body.</returns>
/// <exception cref="ArgumentNullException">Is raised when <b>stream</b>, <b>mediaType</b> or <b>stream</b> is null reference.</exception>
/// <exception cref="ParseException">Is raised when any parsing errors.</exception>
protected static new MIME_b Parse(MIME_Entity owner,MIME_h_ContentType defaultContentType,SmartStream stream)
{
if(owner == null){
throw new ArgumentNullException("owner");
}
if(defaultContentType == null){
throw new ArgumentNullException("defaultContentType");
}
if(stream == null){
throw new ArgumentNullException("stream");
}
MIME_b_Text retVal = null;
if(owner.ContentType != null){
retVal = new MIME_b_Text(owner.ContentType.TypeWithSubtype);
}
else{
retVal = new MIME_b_Text(defaultContentType.TypeWithSubtype);
}
Net_Utils.StreamCopy(stream,retVal.EncodedStream,32000);
m_pEncoding = stream.Encoding;
retVal.SetModified(false);
return retVal;
}
#endregion
#region method GetCharset
/// <summary>
/// Gets charset from Content-Type. If char set isn‘t specified, "ascii" is defined as default and it will be returned.
/// </summary>
/// <returns>Returns content charset.</returns>
/// <exception cref="ArgumentException">Is raised when Content-Type has not supported charset parameter value.</exception>
private Encoding GetCharset()
{
// RFC 2046 4.1.2. The default character set, US-ASCII.
if(this.Entity.ContentType == null || string.IsNullOrEmpty(this.Entity.ContentType.Param_Charset)){
//return Encoding.ASCII;
return m_pEncoding;
}
else{
// Handle custome/extended charsets, just remove "x-" from start.
if(this.Entity.ContentType.Param_Charset.ToLower().StartsWith("x-")){
return Encoding.GetEncoding(this.Entity.ContentType.Param_Charset.Substring(2));
}
// Cp1252 is not IANA reggistered, some mail clients send it, it equal to windows-1252.
else if(string.Equals(this.Entity.ContentType.Param_Charset,"cp1252",StringComparison.InvariantCultureIgnoreCase)){
return Encoding.GetEncoding("windows-1252");
}
else{
return Encoding.GetEncoding(this.Entity.ContentType.Param_Charset);
}
}
}
#endregion