Exemplo 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;
        }
Exemplo 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);
 }
Exemplo 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);
        }
Exemplo 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;
        }
Exemplo n.º 5
0
        private string ParseBody()
        {
            var body = String.Join(Environment.NewLine, _message
                                   // skip the headers
                                   .SkipWhile((x, i) => x.Trim().Length > 0 && i >= 0)
                                   // skip the blanks after the headers
                                   .SkipWhile((x, i) => x.Trim().Length == 0));

            if (!string.IsNullOrEmpty(Boundary))
            {
                ParseMime(body, Boundary);
                if (AlternateViews.Count > 0)
                {
                    var att = AlternateViews.FirstOrDefault(x => x.ContentType.Is("text/plain")) ??
                              AlternateViews.FirstOrDefault(x => x.ContentType.Contains("html"));

                    if (att != null)
                    {
                        return(att.Body);
                    }
                }
            }
            else
            {
                if (ContentTransferEncoding.Is("quoted-printable"))
                {
                    return(Utilities.DecodeQuotedPrintable(body, _encoding));
                }
                if (ContentTransferEncoding.Is("base64")
                    //only decode the content if it is a text document
                    && ContentType.StartsWith("text/", StringComparison.OrdinalIgnoreCase))
                {
                    return(_encoding.GetString(Convert.FromBase64String(body)));
                }
                return(body);
            }
            return(String.Empty);
        }