PIbd-21 Potapov N.S. LabWork07 #8
@ -1,4 +1,5 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DocumentFormat.OpenXml.Drawing;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SecuritySystemContracts.BindingModels;
|
||||
using SecuritySystemContracts.BusinessLogicsContracts;
|
||||
using SecuritySystemContracts.SearchModels;
|
||||
@ -11,10 +12,12 @@ namespace SecuritySystemBusinessLogic.BusinessLogics
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IMessageInfoStorage _messageInfoStorage;
|
||||
public MessageInfoLogic(ILogger<MessageInfoLogic> logger, IMessageInfoStorage messageInfoStorage)
|
||||
private readonly IClientLogic _clientLogic;
|
||||
public MessageInfoLogic(ILogger<MessageInfoLogic> logger, IMessageInfoStorage messageInfoStorage, IClientLogic clientLogic)
|
||||
{
|
||||
_logger = logger;
|
||||
_messageInfoStorage = messageInfoStorage;
|
||||
_clientLogic = clientLogic;
|
||||
}
|
||||
|
||||
public bool Create(MessageInfoBindingModel model)
|
||||
@ -23,6 +26,11 @@ namespace SecuritySystemBusinessLogic.BusinessLogics
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var client = _clientLogic.ReadElement(new ClientSearchModel { Email = model.SenderName });
|
||||
if (client != null)
|
||||
{
|
||||
model.ClientId = client.Id;
|
||||
}
|
||||
if (_messageInfoStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
|
@ -40,8 +40,6 @@ namespace SecuritySystemBusinessLogic.MailWorker
|
||||
protected override async Task<List<MessageInfoBindingModel>> ReceiveMailAsync()
|
||||
{
|
||||
var list = new List<MessageInfoBindingModel>();
|
||||
string regexpPattern = "(\\<(/?[^>]+)>)";
|
||||
Regex regexp = new Regex(regexpPattern);
|
||||
using var client = new Pop3Client();
|
||||
await Task.Run(() =>
|
||||
{
|
||||
@ -60,7 +58,7 @@ namespace SecuritySystemBusinessLogic.MailWorker
|
||||
MessageId = message.MessageId,
|
||||
SenderName = mail.Address,
|
||||
Subject = message.Subject,
|
||||
Body = regexp.Replace(message.HtmlBody, "")
|
||||
Body = message.TextBody != null ? message.TextBody : message.HtmlBody
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -67,10 +67,11 @@ namespace SecuritySystemRestApi.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mailLogic.ReadList(new MessageInfoSearchModel
|
||||
var mails = _mailLogic.ReadList(new MessageInfoSearchModel
|
||||
{
|
||||
ClientId = clientId
|
||||
});
|
||||
return mails;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user