/// <summary> /// Toes the mail message ex. /// </summary> /// <param name="entity">The entity.</param> /// <returns></returns> private MailMessageEx ToMailMessageEx(MimeEntity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } //parse standard headers and create base email. MailMessageEx message = MailMessageEx.CreateMailMessageFromEntity(entity); if (!string.IsNullOrEmpty(entity.ContentType.Boundary)) { message = MailMessageEx.CreateMailMessageFromEntity(entity); BuildMultiPartMessage(entity, message); } //parse multipart message into sub parts. else if (string.Equals(entity.ContentType.MediaType, MediaTypes.MessageRfc822, StringComparison.InvariantCultureIgnoreCase)) { //use the first child to create the multipart message. if (entity.Children.Count < 0) { throw new Exception("Invalid child count on message/rfc822 entity."); } //create the mail message from the first child because it will //contain all of the mail headers. The entity in this state //only contains simple content type headers indicating, disposition, type and description. //This means we can't create the mail message from this type as there is no //internet mail headers attached to this entity. message = MailMessageEx.CreateMailMessageFromEntity(entity.Children[0]); BuildMultiPartMessage(entity, message); } //parse nested message. else { message = MailMessageEx.CreateMailMessageFromEntity(entity); BuildSinglePartMessage(entity, message); } //Create single part message. return(message); }