zoukankan      html  css  js  c++  java
  • lumisoft邮件内容中文乱码问题

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

  • 相关阅读:
    揭秘淘宝286亿海量图片存储与处理架构
    从能做的事做起,做越来越多的事
    用表驱动代替switchcase
    文件过滤驱动中的重入处理
    谈谈对APC的一点理解
    StartIo例程的作用
    C++各大名库的介绍
    IRQL
    FastIO
    一道面试题,看这段代码最后抛出什么异常
  • 原文地址:https://www.cnblogs.com/xueyuan299/p/6405913.html
Copyright © 2011-2022 走看看