Exemple #1
0
        public MailItemBase(string source)
        {
            if (String.IsNullOrEmpty(source))
            {
                throw new Exception("Source is required.");
            }
            _Source = source;
            // get headers
            int    headersTail = source.IndexOf("\r\n\r\n"); // for next time
            string h           = String.Empty;

            if (headersTail == -1)
            { // tail not found. Source as headers.
                h = source;
            }
            else
            { // separate headers
                h = source.Substring(0, headersTail);
            }
            _Headers = ParseHeaders(h);

            if (headersTail == -1)
            {
                return;              // tail not found and not mail body (only headers). exit.
            }
            // get mail body
            string b = source.Substring(headersTail + 4, source.Length - headersTail - 4); // 4 = "\r\n\r\n".Length

            if (_Headers.ContainsKey("Content-Transfer-Encoding"))
            {
                _ContentTransferEncoding = _Headers["Content-Transfer-Encoding"].ToString().ToLower();
            }
            if (_Headers.ContainsKey("Content-Type"))
            {
                _ContentType = new Pop3Lib.MIME.ContentType(_Headers["Content-Type"].ToString());
            }
            else
            {
                _ContentType = new Pop3Lib.MIME.ContentType("");
            }
            if (_Headers.ContainsKey("Content-Disposition"))
            {
                _ContentDisposition = new Pop3Lib.MIME.ContentDisposition(_Headers["Content-Disposition"].ToString());
            }

            // parse content
            if (_ContentType.Type.StartsWith("multipart"))
            {
                // is multipart
                ParseMultiPart(b); // parse multipart
            }
            else if (_ContentType.Type.StartsWith("application") || _ContentType.Type.StartsWith("image") || _ContentType.Type.StartsWith("video") || _ContentType.Type.StartsWith("audio"))
            {
                // is binary
                if (_ContentTransferEncoding != "base64")
                {
                    throw new Exception("Base64 expected...");
                }
                _Data = Convert.FromBase64String(b);
            }
            else
            { // is text
                _Data = DecodeContent(_ContentTransferEncoding, b);
            }
        }
Exemple #2
0
    public MailItemBase(string source)
    {
      if (String.IsNullOrEmpty(source))
      {
        throw new Exception("Source is required.");
      }
      _Source = source;
      // get headers
      int headersTail = source.IndexOf("\r\n\r\n"); // for next time
      string h = String.Empty;
      if (headersTail == -1)
      {  // tail not found. Source as headers.
        h = source;
      }
      else
      { // separate headers
        h = source.Substring(0, headersTail);
      }
      _Headers = ParseHeaders(h);

      if (headersTail == -1) return; // tail not found and not mail body (only headers). exit.

      // get mail body
      string b = source.Substring(headersTail + 4, source.Length - headersTail - 4); // 4 = "\r\n\r\n".Length
      if (_Headers.ContainsKey("Content-Transfer-Encoding"))
      {
        _ContentTransferEncoding = _Headers["Content-Transfer-Encoding"].ToString().ToLower();
      }
      if (_Headers.ContainsKey("Content-Type"))
      {
        _ContentType = new Pop3Lib.MIME.ContentType(_Headers["Content-Type"].ToString());
      }
      else
      {
        _ContentType = new Pop3Lib.MIME.ContentType("");
      }
      if (_Headers.ContainsKey("Content-Disposition"))
      {
        _ContentDisposition = new Pop3Lib.MIME.ContentDisposition(_Headers["Content-Disposition"].ToString());
      }

      // parse content
      if (_ContentType.Type.StartsWith("multipart"))
      {
        // is multipart
        ParseMultiPart(b); // parse multipart
      }
      else if (_ContentType.Type.StartsWith("application") || _ContentType.Type.StartsWith("image") || _ContentType.Type.StartsWith("video") || _ContentType.Type.StartsWith("audio"))
      {
        // is binary
        if (_ContentTransferEncoding != "base64")
        {
          throw new Exception("Base64 expected...");
        }
        _Data = Convert.FromBase64String(b);
      }
      else
      { // is text
        _Data = DecodeContent(_ContentTransferEncoding, b);
      }
    }
Exemple #3
0
 public MailBinary(byte[] data, Pop3Lib.MIME.ContentDisposition contentDisposition) : base()
 {
   _Data = data;
   _ContentDisposition = contentDisposition;
 }
Exemple #4
0
 public MailBinary(byte[] data, Pop3Lib.MIME.ContentDisposition contentDisposition) : base()
 {
     _Data = data;
     _ContentDisposition = contentDisposition;
 }