Exemple #1
0
        private MessageEntitySummary HandleMimeEntity(MimeEntity entity)
        {
            int index = 0;

            return(MimeEntityVisitor.VisitWithResults <MessageEntitySummary>(entity, (e, p) =>
            {
                MessageEntitySummary result = new MessageEntitySummary()
                {
                    MessageId = Id,
                    Id = index.ToString(),
                    ContentId = e.ContentId,
                    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,
                    MimeEntity = e
                };

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

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

                index++;
                return result;
            }));
        }
Exemple #2
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>()
                };

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

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

                index++;
                return result;
            }));
        }
Exemple #3
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);
        }
Exemple #4
0
        private MessageEntitySummary HandleMimeEntity(MimeEntity entity)
        {
            int index = 0;

            return(MimeEntityVisitor.VisitWithResults <MessageEntitySummary>(entity, (e, p) =>
            {
                string fileName = PunyCodeReplacer.DecodePunycode(!string.IsNullOrEmpty(e.ContentDisposition?.FileName)
            ? e.ContentDisposition?.FileName
            : e.ContentType?.Name);

                MessageEntitySummary result = new MessageEntitySummary()
                {
                    MessageId = Id,
                    Id = index.ToString(),
                    ContentId = e.ContentId,
                    Name = (fileName ?? e.ContentId ?? index.ToString()) + " - " + e.ContentType.MimeType,
                    Headers = e.Headers.Select(h => new Header {
                        Name = h.Field, Value = PunyCodeReplacer.DecodePunycode(h.Value)
                    }).ToList(),
                    ChildParts = new List <MessageEntitySummary>(),
                    Attachments = new List <AttachmentSummary>(),
                    Warnings = new List <MessageWarning>(),
                    Size = e.ToString().Length,
                    IsAttachment = (e.ContentDisposition?.Disposition != "inline" && !string.IsNullOrEmpty(fileName)) || e.ContentDisposition?.Disposition == "attachment",
                    MimeEntity = e
                };

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

                    if (result.IsAttachment)
                    {
                        if (e.ContentDisposition?.Disposition != "attachment")
                        {
                            result.Warnings.Add(new MessageWarning {
                                Details = $"Attachment '{fileName}' should have \"Content-Disposition: attachment\" header."
                            });
                        }

                        if (string.IsNullOrEmpty(fileName))
                        {
                            result.Warnings.Add(new MessageWarning {
                                Details = $"Attachment with content ID '{e.ContentId}' should have filename specified in either 'Content-Type' or 'Content-Disposition' header."
                            });
                        }

                        p.Attachments.Add(new AttachmentSummary()
                        {
                            Id = result.Id,
                            ContentId = result.ContentId,
                            FileName = fileName,
                            Url = $"api/messages/{Id}/part/{result.Id}/content"
                        });
                    }
                }

                index++;
                return result;
            }));
        }