Пример #1
0
        private MessageEntitySummary HandleMimeEntity(MimeEntity entity)
        {
            int index = 0;

            return(MimeEntityVisitor.Visit <MessageEntitySummary>(entity, null, (e, p) =>
            {
                string cid = e.ContentId ?? index.ToString();

                MessageEntitySummary result = new MessageEntitySummary()
                {
                    MessageId = Id,
                    ContentId = cid,
                    Name = e.ContentId + " - " + e.ContentType.MimeType,
                    Headers = e.Headers.Select(h => new Header {
                        Name = h.Field, Value = h.Value
                    }).ToList(),
                    ChildParts = new List <MessageEntitySummary>(),
                    Attachments = new List <AttachmentSummary>(),
                    Size = e.ToString().Length
                };

                if (p != null)
                {
                    p.ChildParts.Add(result);

                    if (e.IsAttachment)
                    {
                        p.Attachments.Add(new AttachmentSummary()
                        {
                            ContentId = result.ContentId,
                            FileName = string.IsNullOrEmpty(e.ContentType?.Name)
                               ? e.ContentDisposition?.FileName
                               : e.ContentType.Name,
                            Url = $"/api/messages/{Id}/part/{result.ContentId}/content"
                        });
                    }
                }

                index++;
                return result;
            }));
        }
Пример #2
0
        private static MimeEntity GetPart(DbModel.Message message, string cid)
        {
            MimeEntity result = null;

            using (MemoryStream stream = new MemoryStream(message.Data))
            {
                MimeMessage mime = MimeMessage.Load(stream);

                int index = 0;
                MimeEntityVisitor.Visit <DBNull>(mime.Body, null, (e, p) =>
                {
                    if (((e as MimePart)?.ContentId ?? (index++.ToString())) == cid)
                    {
                        result = e;
                    }

                    return(DBNull.Value);
                });
            }

            return(result);
        }