Exemplo n.º 1
0
        private static string EncodeHeaderValue(string value)
        {
            StringBuilder sb = new StringBuilder();

            if (StringHandler.IsAscii(value))
            {
                return(value);
            }
            if (StringHandler.IsAnsi(value))
            {
                Encoding enc = Encoding.GetEncoding(1252);
                sb.Append("=?");
                sb.Append(enc.BodyName);
                sb.Append("?Q?");
                sb.Append(StringHandler.EncodeToQuotedPrintable(value, enc, true));
                sb.Append("?=");
            }
            else
            {
                sb.Append("=?utf-8?B?");
                sb.Append(Convert.ToBase64String(Encoding.UTF8.GetBytes(value)));
                sb.Append("?=");
            }
            return(sb.ToString());
        }
Exemplo n.º 2
0
 private static void AppendMessage(StringBuilder sb, string message, string format, Encoding encoding)
 {
     if (message == null)
     {
         message = string.Empty;
     }
     sb.Append("Content-Type: text/");
     sb.Append(format);
     if (StringHandler.IsAscii(message))
     {
         sb.Append("\r\n");
         sb.Append("Content-Transfer-Encoding: 7Bit\r\n");
         sb.Append("\r\n");
         sb.Append(message);
     }
     else
     {
         if ((encoding == null && !StringHandler.IsAnsi(message)) || (encoding != null && encoding.Equals(Encoding.UTF8)))
         {
             sb.Append("; charset=utf-8\r\n");
             sb.Append("Content-Transfer-Encoding: base64\r\n");
             sb.Append("\r\n");
             string base64String = Convert.ToBase64String(Encoding.UTF8.GetBytes(message));
             ChunkString(sb, base64String, 73);
         }
         else
         {
             if (encoding == null)
             {
                 encoding = Encoding.GetEncoding(1252);
             }
             sb.Append("; charset=");
             sb.Append(encoding.BodyName);
             sb.Append("\r\n");
             sb.Append("Content-Transfer-Encoding: quoted-printable\r\n");
             sb.Append("\r\n");
             sb.Append(StringHandler.EncodeToQuotedPrintable(message, encoding));
         }
     }
     if (!message.EndsWith("\r\n"))
     {
         sb.Append("\r\n");
     }
     sb.Append("\r\n");
 }