private string CreateEntity(ref Stream dataStream, ref IMultipartEntity parent, out IEntity entity) { entity = null; IList <RFC822.Field> fields; int cause = ParseFields(ref dataStream, out fields); if (cause > 0) { foreach (RFC822.Field contentField in fields) { if (contentField is ContentTypeField) { ContentTypeField contentTypeField = contentField as ContentTypeField; if (m_FieldParser.CompositeType.IsMatch(contentTypeField.Type)) { MultipartEntity mEntity = new MultipartEntity(); mEntity.Fields = fields; entity = mEntity; entity.Parent = parent; parent.BodyParts.Add(entity); if (Regex.IsMatch(contentTypeField.Type, "(?i)message") && Regex.IsMatch(contentTypeField.SubType, "(?i)rfc822")) { Message message = new Message(); IList <RFC822.Field> messageFields; cause = ParseFields(ref dataStream, out messageFields); message.Fields = messageFields; mEntity.BodyParts.Add(message); message.Parent = mEntity; if (cause > 0) { return(ParseMessage(ref dataStream, ref message, messageFields)); } break; } else { mEntity.Delimiter = ReadDelimiter(ref contentTypeField); return(parent.Delimiter); } } else if (m_FieldParser.DescriteType.IsMatch(contentTypeField.Type)) { entity = new Entity(); entity.Fields = fields; entity.Parent = parent; parent.BodyParts.Add(entity); return(parent.Delimiter); } } } } return(string.Empty); }
private void LoadAttachments(IEntity parent) { if (parent is MultipartEntity) { MultipartEntity mpe = parent as MultipartEntity; foreach (Entity entity in mpe.BodyParts) { if (entity is MultipartEntity && !(entity is Message)) { LoadAttachments(entity); } else if (!(entity is MultipartEntity) && !(entity is Message)) { ContentDispositionField dispositionField = null; ContentTypeField contentTypeField = null; foreach (RFC822.Field field in entity.Fields) { if (field is RFC2183.ContentDispositionField) { dispositionField = field as ContentDispositionField; } if (field is ContentTypeField) { contentTypeField = field as ContentTypeField; } } if (dispositionField != null && contentTypeField != null) { IAttachment attachment = new Attachment(); attachment.Disposition = dispositionField.Disposition; attachment.Name = dispositionField.Parameters["filename"]; attachment.Data = entity.Body; attachment.Type = contentTypeField.Type; attachment.SubType = contentTypeField.SubType; m_Attachments.Add(attachment); } } } } }
private void LoadMessages(IEntity parent) { if (parent is MultipartEntity) { MultipartEntity mpe = parent as MultipartEntity; foreach (Entity child in mpe.BodyParts) { if (child is MultipartEntity && !(child is Message)) { LoadMessages(child); } else if (child is Message) { Message message = child as Message; m_Messages.Add(message); } } } }
private void LoadBody(Entity parent) { if (parent is MultipartEntity) { MultipartEntity mpe = parent as MultipartEntity; foreach (Entity child in mpe.BodyParts) { if (child != parent && !(child is Message)) { LoadBody(child); } } } ContentTypeField contentTypeField = null; ContentDispositionField contentDispositionField = null; foreach (RFC822.Field field in parent.Fields) { if (field is ContentTypeField) { ContentTypeField contentField = field as ContentTypeField; if (contentField.Type.ToLower().Equals("text")) { contentTypeField = contentField; } } if (field is ContentDispositionField) { contentDispositionField = field as ContentDispositionField; } } if (contentTypeField != null && (contentDispositionField == null || contentDispositionField.Disposition.ToLower().Equals("inline"))) { string text = ToString(parent.Body); m_Body.Add(contentTypeField.Type + "/" + contentTypeField.SubType, text); } }