2020-10-02 18:29:25 +00:00
|
|
|
using System;
|
2020-04-13 06:52:06 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using FluentValidation;
|
2013-05-19 23:17:32 +00:00
|
|
|
using NzbDrone.Core.Annotations;
|
2015-03-17 04:33:34 +00:00
|
|
|
using NzbDrone.Core.Validation;
|
2013-05-19 23:17:32 +00:00
|
|
|
|
2013-05-27 05:44:54 +00:00
|
|
|
namespace NzbDrone.Core.Notifications.Email
|
2013-05-19 23:17:32 +00:00
|
|
|
{
|
2013-10-12 18:44:40 +00:00
|
|
|
public class EmailSettingsValidator : AbstractValidator<EmailSettings>
|
|
|
|
{
|
|
|
|
public EmailSettingsValidator()
|
|
|
|
{
|
|
|
|
RuleFor(c => c.Server).NotEmpty();
|
2017-01-27 06:35:16 +00:00
|
|
|
RuleFor(c => c.Port).InclusiveBetween(1, 65535);
|
2021-01-07 04:11:15 +00:00
|
|
|
RuleFor(c => c.From).NotEmpty();
|
2020-04-13 06:52:06 +00:00
|
|
|
RuleForEach(c => c.To).EmailAddress();
|
2023-04-16 23:17:03 +00:00
|
|
|
RuleForEach(c => c.Cc).EmailAddress();
|
2020-04-13 06:52:06 +00:00
|
|
|
RuleForEach(c => c.Bcc).EmailAddress();
|
|
|
|
|
|
|
|
// Only require one of three send fields to be set
|
2023-04-16 23:17:03 +00:00
|
|
|
RuleFor(c => c.To).NotEmpty().Unless(c => c.Bcc.Any() || c.Cc.Any());
|
|
|
|
RuleFor(c => c.Cc).NotEmpty().Unless(c => c.To.Any() || c.Bcc.Any());
|
|
|
|
RuleFor(c => c.Bcc).NotEmpty().Unless(c => c.To.Any() || c.Cc.Any());
|
2013-10-12 18:44:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-14 04:16:26 +00:00
|
|
|
public class EmailSettings : NotificationSettingsBase<EmailSettings>
|
2013-05-19 23:17:32 +00:00
|
|
|
{
|
2024-04-14 04:16:26 +00:00
|
|
|
private static readonly EmailSettingsValidator Validator = new ();
|
2013-10-12 18:44:40 +00:00
|
|
|
|
2013-08-09 06:22:26 +00:00
|
|
|
public EmailSettings()
|
|
|
|
{
|
2023-04-23 01:18:22 +00:00
|
|
|
Port = 587;
|
|
|
|
|
2020-10-02 18:29:25 +00:00
|
|
|
To = Array.Empty<string>();
|
2023-04-16 23:17:03 +00:00
|
|
|
Cc = Array.Empty<string>();
|
2020-10-02 18:29:25 +00:00
|
|
|
Bcc = Array.Empty<string>();
|
2013-08-09 06:22:26 +00:00
|
|
|
}
|
|
|
|
|
2024-01-03 20:41:16 +00:00
|
|
|
[FieldDefinition(0, Label = "NotificationsEmailSettingsServer", HelpText = "NotificationsEmailSettingsServerHelpText", Placeholder = "smtp.gmail.com")]
|
2015-10-03 17:45:26 +00:00
|
|
|
public string Server { get; set; }
|
2013-05-19 23:17:32 +00:00
|
|
|
|
2013-05-27 05:44:54 +00:00
|
|
|
[FieldDefinition(1, Label = "Port")]
|
2015-10-03 17:45:26 +00:00
|
|
|
public int Port { get; set; }
|
2013-05-19 23:17:32 +00:00
|
|
|
|
2024-01-24 10:11:51 +00:00
|
|
|
[FieldDefinition(2, Label = "NotificationsEmailSettingsUseEncryption", HelpText = "NotificationsEmailSettingsUseEncryptionHelpText", Type = FieldType.Select, SelectOptions = typeof(EmailEncryptionType))]
|
|
|
|
public int UseEncryption { get; set; }
|
2013-05-19 23:17:32 +00:00
|
|
|
|
2020-10-17 03:27:01 +00:00
|
|
|
[FieldDefinition(3, Label = "Username", Privacy = PrivacyLevel.UserName)]
|
2015-10-03 17:45:26 +00:00
|
|
|
public string Username { get; set; }
|
2013-05-19 23:17:32 +00:00
|
|
|
|
2020-10-17 03:27:01 +00:00
|
|
|
[FieldDefinition(4, Label = "Password", Type = FieldType.Password, Privacy = PrivacyLevel.Password)]
|
2015-10-03 17:45:26 +00:00
|
|
|
public string Password { get; set; }
|
2013-05-19 23:17:32 +00:00
|
|
|
|
2024-01-03 20:41:16 +00:00
|
|
|
[FieldDefinition(5, Label = "NotificationsEmailSettingsFromAddress", Placeholder = "example@email.com")]
|
2015-10-03 17:45:26 +00:00
|
|
|
public string From { get; set; }
|
2013-05-19 23:17:32 +00:00
|
|
|
|
2024-01-03 20:41:16 +00:00
|
|
|
[FieldDefinition(6, Label = "NotificationsEmailSettingsRecipientAddress", HelpText = "NotificationsEmailSettingsRecipientAddressHelpText", Placeholder = "example@email.com,example1@email.com")]
|
2020-04-13 06:52:06 +00:00
|
|
|
public IEnumerable<string> To { get; set; }
|
|
|
|
|
2024-01-03 20:41:16 +00:00
|
|
|
[FieldDefinition(7, Label = "NotificationsEmailSettingsCcAddress", HelpText = "NotificationsEmailSettingsCcAddressHelpText", Placeholder = "example@email.com,example1@email.com", Advanced = true)]
|
2023-04-16 23:17:03 +00:00
|
|
|
public IEnumerable<string> Cc { get; set; }
|
2020-04-13 06:52:06 +00:00
|
|
|
|
2024-01-03 20:41:16 +00:00
|
|
|
[FieldDefinition(8, Label = "NotificationsEmailSettingsBccAddress", HelpText = "NotificationsEmailSettingsBccAddressHelpText", Placeholder = "example@email.com,example1@email.com", Advanced = true)]
|
2020-04-13 06:52:06 +00:00
|
|
|
public IEnumerable<string> Bcc { get; set; }
|
2013-05-19 23:17:32 +00:00
|
|
|
|
2024-04-14 04:16:26 +00:00
|
|
|
public override NzbDroneValidationResult Validate()
|
2013-05-19 23:17:32 +00:00
|
|
|
{
|
2015-03-17 04:33:34 +00:00
|
|
|
return new NzbDroneValidationResult(Validator.Validate(this));
|
2013-09-21 07:09:26 +00:00
|
|
|
}
|
2013-05-19 23:17:32 +00:00
|
|
|
}
|
2024-01-24 10:11:51 +00:00
|
|
|
|
|
|
|
public enum EmailEncryptionType
|
|
|
|
{
|
|
|
|
Preferred = 0,
|
|
|
|
Always = 1,
|
|
|
|
Never = 2
|
|
|
|
}
|
2013-05-19 23:17:32 +00:00
|
|
|
}
|