コード例 #1
0
        private void Parse(ref MimeParser mp, MimeMultipartBody parentMultipartBody)
        {
            try
            {
                string sLine = "";
                byte [] buffer = null;
                bool isEOC = false;
                bool readBinaryBody = false;

                while(sLine != null)
                {
                    //Check if the Binary encoding header is found
                    if (_headers["content-transfer-encoding"] != null &&
                        MimeBodyPart.GetMimeEncoding(_headers["content-transfer-encoding"].Value) == MimeBodyPart.MimeEncoding.Binary
                        && buffer == null)
                    {
                        readBinaryBody = true;
                    }
                    MimeParser.ChunkType chunkType = mp.ReadNextChunk(ref sLine, ref isEOC, ref readBinaryBody, ref buffer);

                    switch(chunkType)
                    {
                        case MimeParser.ChunkType.VersionHeader:
                        case MimeParser.ChunkType.Header:
                            MimeHeader mh = new MimeHeader(sLine);
                            InitializeMultipart(ref mp, mh);
                            _headers.Add(mh);
                            break;
                        case MimeParser.ChunkType.Body:
                            CreateBody(sLine, buffer);
                            break;
                        case MimeParser.ChunkType.StartBoundary:
                            if (_body == null)
                                CreateBody("", buffer);
                            MimeMessage firstMessage = new MimeMessage(ref mp, (MimeMultipartBody)_body);
                            break;
                        case MimeParser.ChunkType.Boundary:
                            MimeMessage nextMessage = new MimeMessage(ref mp, parentMultipartBody);
                            return;
                        case MimeParser.ChunkType.EndBoundary:
                            return;
                        case MimeParser.ChunkType.EOF:
                            break;
                        default:
                            break;
                    }
                }
            }
            catch(Exception err)
            {
                logger.Error(err);
                throw;
            }
        }
コード例 #2
0
 /// <summary>
 /// Append the given part to the body
 /// </summary>
 /// <param name="part"></param>
 public void AppendPart(MimeMessage part)
 {
     if (_isMultiPart)
     {
         if (_body == null)
         {
             _body  = new MimeMultipartBody();
         }
         ((MimeMultipartBody)_body).Add(part);
     }
 }
コード例 #3
0
 /// <summary>
 /// Construct a new Mime Multipart message
 /// </summary>
 /// <returns></returns>
 public static MimeMessage CreateMimeMultipartRelated()
 {
     MimeMessage message = new MimeMessage();
     message._body = new MimeMultipartBody();
     message.Headers.Add(new MimeHeader("Content-Type:" + message._body.ContentType + "; boundary=" + ((MimeMultipartBody)message._body).Boundary));
     message._body.SetText("This is a multi-part message in MIME format.");
     message._isMultiPart = true;
     return message;
 }
コード例 #4
0
 /// <summary>
 /// Add a mime message to the multipart message.
 /// </summary>
 /// <param name="part">The MimeMessage to add.</param>
 /// <returns>The newly added MimeMessage</returns>
 public MimeMessage Add(MimeMessage part)
 {
     return _parts.Add(part);
 }
コード例 #5
0
 /// <summary>
 /// Remove the given MimeMessage from this multipart message.
 /// </summary>
 /// <param name="part">The MimeMessage to remove.</param>
 public void Remove(MimeMessage part)
 {
     _parts.Remove(part);
 }
コード例 #6
0
 /// <summary>
 /// Add a mime message.
 /// </summary>
 /// <param name="part">The part to add.</param>
 /// <returns>The newly added part.</returns>
 public MimeMessage Add(MimeMessage part)
 {
     _parts.Add(part);
     return part;
 }