Пример #1
0
        private static void EncodeToBuffer(string value, StringBuilder builder, bool allowUnicode)
        {
            Encoding?encoding = MimeBasePart.DecodeEncoding(value);

            if (encoding != null) // Manually encoded elsewhere, pass through
            {
                builder.Append('\"').Append(value).Append('"');
            }
            else if ((allowUnicode && !MailBnfHelper.HasCROrLF(value)) || // Unicode without CL or LF's
                     MimeBasePart.IsAscii(value, false)) // Ascii
            {
                MailBnfHelper.GetTokenOrQuotedString(value, builder, allowUnicode);
            }
            else
            {
                // MIME Encoding required
                encoding = Encoding.GetEncoding(MimeBasePart.DefaultCharSet);
                builder.Append('"').Append(MimeBasePart.EncodeHeaderValue(value, encoding, MimeBasePart.ShouldUseBase64Encoding(encoding))).Append('"');
            }
        }