public void TestBlueBluttonSerialization() { RequestContext context = this.CreateContext(); MimeEntity entity = null; Assert.DoesNotThrow(() => entity = context.ToMimeEntity()); string entityText = null; Assert.DoesNotThrow(() => entityText = entity.ToString()); MimeEntity parsedEntity = null; Assert.DoesNotThrow(() => parsedEntity = MimeSerializer.Default.Deserialize <MimeEntity>(entityText)); Attachment attachment = null; Assert.DoesNotThrow(() => attachment = context.ToAttachment()); Assert.True(attachment.ContentType.MediaType == MediaTypeNames.Text.Plain); Assert.True(attachment.ContentDisposition.FileName == RequestContext.AttachmentName); string attachmentBody = attachment.StringContent(); Assert.True(attachmentBody.Contains(RequestContext.FieldNames.DocumentSource)); RequestContext contextParsed = new RequestContext(parsedEntity.Body.Text); this.Compare(context.GetDocumentSources(), contextParsed.GetDocumentSources()); }
internal static string GetPartContentAsText(Message result, string id) { MimeEntity contentEntity = GetPart(result, id); if (contentEntity is MimePart part) { using (StreamReader reader = new StreamReader(part.Content.Open())) { return(reader.ReadToEnd()); } } else { return(contentEntity.ToString()); } }
public void TestCryptographerLineLengths() { string messageText = m_tester.ReadMessageText("simple.eml"); Message message = MimeSerializer.Default.Deserialize <Message>(messageText); SignedEntity signedEntity = m_cryptographer.Sign(message, m_cert); string signedEntityText = signedEntity.Aggregate("", (s, e) => s += e.ToString()); string[] signedEntityLines = signedEntityText.Split(new[] { "\r\n" }, StringSplitOptions.None); int longestDecryptedLine = signedEntityLines.Max(l => l.Length); MimeEntity encryptedEntity = m_cryptographer.Encrypt(signedEntity.ToEntity(), m_cert); string encryptedEntityText = encryptedEntity.ToString(); string[] encryptedEntityLines = encryptedEntityText.Split(new[] { "\r\n" }, StringSplitOptions.None); int longestEncryptedLine = encryptedEntityLines.Max(l => l.Length); //RFC 2822 Section 2.1.1 sets a maximum line length of 998 + CRLF. //https://www.ietf.org/rfc/rfc2822.txt Assert.True(longestEncryptedLine < 998); Assert.True(longestDecryptedLine < 998); }
private MessageEntitySummary HandleMimeEntity(MimeEntity entity) { MessageEntitySummary result = new MessageEntitySummary() { Name = entity.ContentId + " - " + entity.ContentType.MimeType, Headers = entity.Headers.Select(h => new Header { Name = h.Field, Value = h.Value }).ToList(), ChildParts = new List <MessageEntitySummary>(), Source = entity.ToString() }; using (MemoryStream memoryStream = new MemoryStream()) { entity.WriteTo(memoryStream, true); result.Body = Encoding.UTF8.GetString(memoryStream.ToArray()); } if (entity is Multipart multipart) { foreach (MimeEntity childEntity in multipart) { result.ChildParts.Add(HandleMimeEntity(childEntity)); } } else if (entity is MimeKit.MessagePart rfc822) { result.Html = rfc822.Message.HtmlBody; result.ChildParts.Add(HandleMimeEntity(rfc822.Message.Body)); } else { var part = (MimePart)entity; } return(result); }
internal static string GetPartSource(DbModel.Message result, string cid) { MimeEntity contentEntity = GetPart(result, cid); return(contentEntity.ToString()); }
internal static string GetPartSource(Message message, string id) { MimeEntity contentEntity = GetPart(message, id); return(contentEntity.ToString()); }