Ejemplo n.º 1
0
        internal void SetBody(string value)
        {
            if (ContentTransferEncoding.Is("quoted-printable"))
            {
                value = Utilities.DecodeQuotedPrintable(value, Utilities.ParseCharsetToEncoding(Charset));
            }
            else if (ContentTransferEncoding.Is("base64")
                     //only decode the content if it is a text document
                     && ContentType.StartsWith("text/", StringComparison.OrdinalIgnoreCase) &&
                     Utilities.IsValidBase64String(value))
            {
                value = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(value));
                ContentTransferEncoding = string.Empty;
            }

            Body = value;
        }
Ejemplo n.º 2
0
 public byte[] GetData()
 {
     byte[] data;
     if (ContentTransferEncoding.Is("base64") && Utilities.IsValidBase64String(Body))
     {
         try {
             data = Convert.FromBase64String(Body);
         } catch (Exception) {
             data = System.Text.Encoding.UTF8.GetBytes(Body);
         }
     }
     else
     {
         data = System.Text.Encoding.UTF8.GetBytes(Body);
     }
     return(data);
 }
Ejemplo n.º 3
0
        public virtual byte[] GetData()
        {
            byte[] data;
            var    body = Body;

            if (ContentTransferEncoding.Is("base64") && Utilities.IsValidBase64String(ref body))
            {
                try {
                    data = Convert.FromBase64String(body);
                } catch (Exception) {
                    data = Encoding.GetBytes(body);
                }
            }
            else
            {
                data = Encoding.GetBytes(body);
            }
            return(data);
        }
Ejemplo n.º 4
0
        internal void SetBody(string value)
        {
            if (ContentTransferEncoding.Is("quoted-printable"))
            {
                value = Utilities.DecodeQuotedPrintable(value, Encoding);
            }
            else if (ContentTransferEncoding.Is("base64")
                     //only decode the content if it is a text document
                     && ContentType.StartsWith("text/", StringComparison.OrdinalIgnoreCase) &&
                     Utilities.IsValidBase64String(value))
            {
                var data = Convert.FromBase64String(value);
                using (var mem = new System.IO.MemoryStream(data))
                    using (var str = new System.IO.StreamReader(mem, Encoding))
                        value = str.ReadToEnd();

                ContentTransferEncoding = string.Empty;
            }

            Body = value;
        }