update email notifications

This commit is contained in:
Luke Pulverenti 2016-11-30 21:07:51 -05:00
parent 8978d94ecf
commit 3cc41de8c9
4 changed files with 17 additions and 49 deletions

View File

@ -1,15 +1,9 @@
using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Security;
using MediaBrowser.Plugins.SmtpNotifications.Configuration;
using MediaBrowser.Controller.Security;
using System;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Threading.Tasks;
using MediaBrowser.Model.Logging;
using System.Threading;
using MediaBrowser.Controller.Notifications;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Services;
@ -24,16 +18,20 @@ namespace MediaBrowser.Plugins.SmtpNotifications.Api
class ServerApiEndpoints : IService
{
private IUserManager _userManager;
private readonly IUserManager _userManager;
private readonly IEncryptionManager _encryption;
private readonly ILogger _logger;
public ServerApiEndpoints(IUserManager userManager)
public ServerApiEndpoints(IUserManager userManager, ILogger logger, IEncryptionManager encryption)
{
_userManager = userManager;
_logger = logger;
_encryption = encryption;
}
public void Post(TestNotification request)
{
var task = Notifier.Instance.SendNotification(new UserNotification
var task = new Notifier(_logger, _encryption).SendNotification(new UserNotification
{
Date = DateTime.UtcNow,
Description = "This is a test notification from Emby Server",

View File

@ -46,6 +46,7 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Security" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
@ -68,6 +69,7 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>xcopy "$(TargetPath)" "$(SolutionDir)\..\Emby.dev\ProgramData-Server\Plugins\" /y</PostBuildEvent>

View File

@ -18,10 +18,10 @@ namespace MediaBrowser.Plugins.SmtpNotifications
private readonly ILogger _logger;
public static Notifier Instance { get; private set; }
public Notifier(ILogManager logManager, IEncryptionManager encryption)
public Notifier(ILogger logger, IEncryptionManager encryption)
{
_encryption = encryption;
_logger = logManager.GetLogger(GetType().Name);
_logger = logger;
Instance = this;
}
@ -45,22 +45,7 @@ namespace MediaBrowser.Plugins.SmtpNotifications
}
private readonly SemaphoreSlim _resourcePool = new SemaphoreSlim(1, 1);
public async Task SendNotification(UserNotification request, CancellationToken cancellationToken)
{
await _resourcePool.WaitAsync(cancellationToken).ConfigureAwait(false);
try
{
await SendNotificationInternal(request, cancellationToken).ConfigureAwait(false);
}
finally
{
_resourcePool.Release();
}
}
private Task SendNotificationInternal(UserNotification request, CancellationToken cancellationToken)
public Task SendNotification(UserNotification request, CancellationToken cancellationToken)
{
var options = GetOptions(request.User);
@ -75,7 +60,8 @@ namespace MediaBrowser.Plugins.SmtpNotifications
Host = options.Server,
Port = options.Port,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false
UseDefaultCredentials = false,
Timeout = 20000
};
if (options.SSL) client.EnableSsl = true;
@ -84,7 +70,7 @@ namespace MediaBrowser.Plugins.SmtpNotifications
if (options.UseCredentials)
{
var pw = _encryption.DecryptString(options.PwData);
var pw = string.IsNullOrWhiteSpace(options.Password) ? _encryption.DecryptString(options.PwData) : options.Password;
client.Credentials = new NetworkCredential(options.Username, pw);
}

View File

@ -2,7 +2,6 @@
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Controller.Security;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Plugins.SmtpNotifications.Configuration;
@ -14,15 +13,13 @@ namespace MediaBrowser.Plugins.SmtpNotifications
/// </summary>
public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
{
protected ILogger Logger { get; set; }
private readonly IEncryptionManager _encryption;
public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer, ILogManager logManager, IEncryptionManager encryption)
public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer, IEncryptionManager encryption)
: base(applicationPaths, xmlSerializer)
{
_encryption = encryption;
Instance = this;
Logger = logManager.GetLogger("SMTP Notifications");
}
public IEnumerable<PluginPageInfo> GetPages()
@ -58,21 +55,6 @@ namespace MediaBrowser.Plugins.SmtpNotifications
}
}
public override void UpdateConfiguration(Model.Plugins.BasePluginConfiguration configuration)
{
var config = (PluginConfiguration) configuration;
// Encrypt password for saving. The Password field the config page sees will always be blank except when updated.
// The program actually uses the encrypted version
foreach (var optionSet in config.Options)
{
optionSet.PwData = _encryption.EncryptString(optionSet.Password ?? string.Empty);
optionSet.Password = null;
}
base.UpdateConfiguration(configuration);
}
/// <summary>
/// Gets the instance.
/// </summary>