开发者

ASP.NET MailMessage.BodyEncoding and MailMessage.SubjectEncoding defaults

Simple question but开发者_如何学JAVA I can't find the answer anywhere on MSDN...

Looking for the defaults ASP.NET will use for:

MailMessage.BodyEncoding and MailMessage.SubjectEncoding

If you don't set them in code?

Thanks


For MailMessage.BodyEncoding MSDN says:

The value specified for the BodyEncoding property sets the character set field in the Content-Type header. The default character set is "us-ascii".

For MailMessage.SubjectEncoding I was also unable to find any documented default value, but reflector is to rescue:

internal void set_Subject(string value)
{
    if ((value != null) && MailBnfHelper.HasCROrLF(value))
    {
        throw new ArgumentException(SR.GetString("MailSubjectInvalidFormat"));
    }
    this.subject = value;
    if (((this.subject != null) && (this.subjectEncoding == null)) && 
         !MimeBasePart.IsAscii(this.subject, false))
    {
        this.subjectEncoding = Encoding.GetEncoding("utf-8");
    }
}

MimeBasePart.IsAscii is an internal method which tries to determine whether the passed value is in ASCII encoding:

internal static bool IsAscii(string value, bool permitCROrLF)
{
    if (value == null)
    {
        throw new ArgumentNullException("value");
    }
    foreach (char ch in value)
    {
        if (ch > '\x007f')
        {
            return false;
        }
        if (!permitCROrLF && ((ch == '\r') || (ch == '\n')))
        {
            return false;
        }
    }
    return true;
}

So it seems the default encoding for subject will be UTF-8 in the most cases.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜