Пример #1
0
        public string GetMessageHtml(Guid id)
        {
            Message result = GetDbMessage(id);

            string html = ApiModel.Message.GetHtml(result);

            if (html == null)
            {
                html = "<pre>" + HtmlAgilityPack.HtmlDocument.HtmlEncode(ApiModel.Message.GetText(result)) + "</pre>";
            }

            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(html);

            HtmlNodeCollection imageElements = doc.DocumentNode.SelectNodes("//img[starts-with(@src, 'cid:')]");

            if (imageElements != null)
            {
                foreach (HtmlNode imageElement in imageElements)
                {
                    string cid = imageElement.Attributes["src"].Value.Replace("cid:", "", StringComparison.OrdinalIgnoreCase);
                    imageElement.Attributes["src"].Value = $"/api/Messages/{id.ToString()}/part/{cid}/content";
                }
            }

            return(doc.DocumentNode.OuterHtml);
        }
Пример #2
0
        public FileStreamResult DownloadMessage(Guid id)
        {
            Message result = _dbContext.Messages.FirstOrDefault(m => m.Id == id);

            return(new FileStreamResult(new MemoryStream(result.Data), "message/rfc822")
            {
                FileDownloadName = $"{id}.eml"
            });
        }
Пример #3
0
        public FileStreamResult DownloadMessage(Guid id)
        {
            Message result = GetDbMessage(id);

            return(new FileStreamResult(new MemoryStream(result.Data), "message/rfc822")
            {
                FileDownloadName = $"{id}.eml"
            });
        }
Пример #4
0
        public IActionResult RelayMessage(Guid id, [FromBody] MessageRelayOptions options)
        {
            Message message = GetDbMessage(id);
            Dictionary <MailboxAddress, Exception> relayErrors = server.TryRelayMessage(message, options?.OverrideRecipientAddresses?.Length > 0 ? options?.OverrideRecipientAddresses.Select(a => MailboxAddress.Parse(a)).ToArray() : null);

            if (relayErrors.Any())
            {
                string relayErrorSummary = string.Join(". ", relayErrors.Select(e => e.Key.Address + ": " + e.Value.Message));
                return(Problem("Failed to relay to recipients: " + relayErrorSummary));
            }

            return(Ok());
        }
Пример #5
0
        public string GetPartSourceRaw(Guid id, string cid)
        {
            Message result = GetDbMessage(id);

            return(ApiModel.Message.GetPartSource(result, cid));
        }
Пример #6
0
        public FileStreamResult GetPartContent(Guid id, string cid)
        {
            Message result = GetDbMessage(id);

            return(ApiModel.Message.GetPartContent(result, cid));
        }
Пример #7
0
        public ApiModel.Message GetMessage(Guid id)
        {
            Message result = GetDbMessage(id);

            return(new ApiModel.Message(result));
        }
Пример #8
0
        public string GetPartSource(Guid id, string cid)
        {
            Message result = _dbContext.Messages.FirstOrDefault(m => m.Id == id);

            return(ApiModel.Message.GetPartSource(result, cid));
        }
Пример #9
0
        public FileStreamResult GetPartContent(Guid id, string cid)
        {
            Message result = _dbContext.Messages.FirstOrDefault(m => m.Id == id);

            return(ApiModel.Message.GetPartContent(result, cid));
        }
Пример #10
0
        public ApiModel.Message GetMessage(Guid id)
        {
            Message result = _dbContext.Messages.FirstOrDefault(m => m.Id == id);

            return(new ApiModel.Message(result));
        }