Merge pull request #5640 from sbwalker/dev
improve NotificationJob validation logic
This commit is contained in:
@ -171,7 +171,7 @@ namespace Oqtane.Infrastructure
|
|||||||
// create mailbox addresses
|
// create mailbox addresses
|
||||||
MailboxAddress to = null;
|
MailboxAddress to = null;
|
||||||
MailboxAddress from = null;
|
MailboxAddress from = null;
|
||||||
var error = "";
|
var mailboxAddressValidationError = "";
|
||||||
|
|
||||||
// sender
|
// sender
|
||||||
if (settingRepository.GetSettingValue(settings, "SMTPRelay", "False") != "True")
|
if (settingRepository.GetSettingValue(settings, "SMTPRelay", "False") != "True")
|
||||||
@ -180,26 +180,42 @@ namespace Oqtane.Infrastructure
|
|||||||
fromName = string.IsNullOrEmpty(fromName) ? site.Name : fromName;
|
fromName = string.IsNullOrEmpty(fromName) ? site.Name : fromName;
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
|
{
|
||||||
|
// exception handler is necessary because of https://github.com/jstedfast/MimeKit/issues/1186
|
||||||
|
if (MailboxAddress.TryParse(fromEmail, out _))
|
||||||
{
|
{
|
||||||
from = new MailboxAddress(fromName, fromEmail);
|
from = new MailboxAddress(fromName, fromEmail);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
// parse error creating sender mailbox address
|
// parse error creating sender mailbox address
|
||||||
error += $" Invalid Sender: {fromName} <{fromEmail}>";
|
}
|
||||||
|
if (from == null)
|
||||||
|
{
|
||||||
|
|
||||||
|
mailboxAddressValidationError += $" Invalid Sender: {fromName} <{fromEmail}>";
|
||||||
}
|
}
|
||||||
|
|
||||||
// recipient
|
// recipient
|
||||||
try
|
try
|
||||||
|
{
|
||||||
|
// exception handler is necessary because of https://github.com/jstedfast/MimeKit/issues/1186
|
||||||
|
if (MailboxAddress.TryParse(toEmail, out _))
|
||||||
{
|
{
|
||||||
to = new MailboxAddress(toName, toEmail);
|
to = new MailboxAddress(toName, toEmail);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
// parse error creating recipient mailbox address
|
// parse error creating recipient mailbox address
|
||||||
error += $" Invalid Recipient: {toName} <{toEmail}>";
|
}
|
||||||
|
if (to == null)
|
||||||
|
{
|
||||||
|
mailboxAddressValidationError += $" Invalid Recipient: {toName} <{toEmail}>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if mailbox addresses are valid
|
||||||
if (from != null && to != null)
|
if (from != null && to != null)
|
||||||
{
|
{
|
||||||
// create mail message
|
// create mail message
|
||||||
@ -235,17 +251,18 @@ namespace Oqtane.Infrastructure
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
// error
|
|
||||||
log += $"Error Sending Notification Id: {notification.NotificationId} - {ex.Message}<br />";
|
log += $"Error Sending Notification Id: {notification.NotificationId} - {ex.Message}<br />";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log += $"Notification Id: {notification.NotificationId} Has An {error} And Has Been Deleted<br />";
|
// invalid mailbox address
|
||||||
|
log += $"Notification Id: {notification.NotificationId} Has An {mailboxAddressValidationError} And Has Been Deleted<br />";
|
||||||
notification.IsDeleted = true;
|
notification.IsDeleted = true;
|
||||||
notificationRepository.UpdateNotification(notification);
|
notificationRepository.UpdateNotification(notification);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log += "Notifications Delivered: " + sent + "<br />";
|
log += "Notifications Delivered: " + sent + "<br />";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user