码迷,mamicode.com
首页 > 其他好文 > 详细

lumisoft邮件内容中文乱码问题

时间:2017-02-16 15:41:43      阅读:294      评论:0      收藏:0      [点我收藏+]

标签:argument   lin   sub   部分   乱码   return   not   windows   static   

修改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

lumisoft邮件内容中文乱码问题

标签:argument   lin   sub   部分   乱码   return   not   windows   static   

原文地址:http://www.cnblogs.com/xueyuan299/p/6405913.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!