Skip to content

Commit

Permalink
Merge branch 'release/7.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaben committed Nov 9, 2024
2 parents 9264270 + a302607 commit 1137bc6
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 40 deletions.
12 changes: 6 additions & 6 deletions Papercut.sln
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{2D6337D4
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".Build", ".Build", "{8661B39E-1555-4A2F-B6C2-6442E83DE73D}"
ProjectSection(SolutionItems) = preProject
.dockerignore = .dockerignore
appveyor.yml = appveyor.yml
build-docker.ps1 = build-docker.ps1
build-docker.sh = build-docker.sh
build.cake = build.cake
build.ps1 = build.ps1
build\BuildInformation.cake = build\BuildInformation.cake
Directory.Build.props = Directory.Build.props
Dockerfile = Dockerfile
GitVersion.yml = GitVersion.yml
README.md = README.md
build\ReleaseNotes.cake = build\ReleaseNotes.cake
ReleaseNotes.md = ReleaseNotes.md
.dockerignore = .dockerignore
Dockerfile = Dockerfile
README.md = README.md
build-docker.sh = build-docker.sh
build-docker.ps1 = build-docker.ps1
build\Velopack.cake = build\Velopack.cake
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Papercut.Infrastructure.Smtp", "src\Papercut.Infrastructure.Smtp\Papercut.Infrastructure.Smtp.csproj", "{873EC485-8E94-4877-8EA7-A7DFE7612E0A}"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ Papercut SMTP UI Requires the "WebView2" Microsoft shared system component to be
![Logging View](https://changemakerstudios.us/content/images/2020/07/Papercut-Log.png)

## Papercut SMTP Service
Papercut SMTP has an optional HTTP server to receive emails even when the client is not running. It's installed by default with [Papercut.Setup.exe](https://github.com/ChangemakerStudios/Papercut/releases).
Alternatively, it can be run in an almost portable way by downloading [Papercut.Service.zip](https://github.com/ChangemakerStudios/Papercut/releases), unzipping and [following the service installation instructions](https://github.com/ChangemakerStudios/Papercut/tree/develop/src/Papercut.Service).
Papercut SMTP has an optional HTTP server to receive emails even when the client is not running.
It can be run in an almost portable way by downloading [Papercut.Smtp.Service.*.zip](https://github.com/ChangemakerStudios/Papercut/releases), unzipping, and [following the service installation instructions](https://github.com/ChangemakerStudios/Papercut/tree/develop/src/Papercut.Service).

### Host in Docker

Expand Down
4 changes: 4 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes

## Papercut SMTP v7.0.1 [2024-11-08]

- Fixed Run on Startup broken. (Thanks, [rikrak](https://github.com/rikrak)))

## Papercut SMTP v7.0.0 [2024-10-14]

_NOTE: Uninstall any existing Papercut SMTP installations BEFORE installing this new version._
Expand Down
6 changes: 3 additions & 3 deletions src/GlobalAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
//------------------------------------------------------------------------------
using System.Reflection;

[assembly: AssemblyVersion("7.1.0.0")]
[assembly: AssemblyFileVersion("7.1.0.0")]
[assembly: AssemblyInformationalVersion("7.1.0-dev.111+Branch.develop.Sha.c6c2a6557ac3b3a8d1ebd93f45de2ff515018f18")]
[assembly: AssemblyVersion("7.0.0.0")]
[assembly: AssemblyFileVersion("7.0.0.0")]
[assembly: AssemblyInformationalVersion("7.0.0.0")]
66 changes: 62 additions & 4 deletions src/Papercut.UI/AppLayer/Settings/AppRunOnStartupService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// limitations under the License.


using System.IO;
using System.Security;

using Autofac;
Expand All @@ -26,28 +27,74 @@
using Papercut.Common.Extensions;
using Papercut.Domain.Application;
using Papercut.Domain.Events;
using Papercut.Domain.LifecycleHooks;
using Papercut.Domain.UiCommands;

namespace Papercut.AppLayer.Settings;

public class AppRunOnStartupService(ILogger logger, IUiCommandHub uiCommandHub) : IEventHandler<SettingsUpdatedEvent>
public class AppRunOnStartupService(ILogger logger, IUiCommandHub uiCommandHub) : IAppLifecycleStarted, IEventHandler<SettingsUpdatedEvent>
{
const string AppStartupKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";

public Task OnStartedAsync()
{
if (Properties.Settings.Default.RunOnStartup)
{
// check if we need to migrate....
bool needsMigration = false;
try
{
using var registryKey = Registry.CurrentUser.OpenSubKey(AppStartupKey, true);

object? legacyAppKey = registryKey?.GetValue(PapercutAppConstants.LegacyName, null);

if (registryKey != null && legacyAppKey != null)
{
needsMigration = true;

logger.Information(
"Migrating App Run on Startup Registry {LegacyKey} to {NewKey}",
$"{AppStartupKey}\\{PapercutAppConstants.LegacyName}",
$"{AppStartupKey}\\{PapercutAppConstants.Name}");

registryKey.DeleteValue(PapercutAppConstants.LegacyName, false);
}
}
catch (Exception ex)
{
logger.Debug(ex, "Failure deleting legacy app key");
}

if (needsMigration)
{
UpdateRunAtStartup();
}
}

return Task.CompletedTask;
}

public Task HandleAsync(SettingsUpdatedEvent @event, CancellationToken token)
{
// check if the setting changed
if (@event.PreviousSettings.RunOnStartup == @event.NewSettings.RunOnStartup)
return Task.CompletedTask;

UpdateRunAtStartup();

return Task.CompletedTask;
}

private bool UpdateRunAtStartup()
{
try
{
var registryKey = Registry.CurrentUser.OpenSubKey(AppStartupKey, true);
using var registryKey = Registry.CurrentUser.OpenSubKey(AppStartupKey, true);

if (registryKey == null)
{
logger.Error("Failure opening registry key {AppStartupKey}", AppStartupKey);
return Task.CompletedTask;
return true;
}

var applicationName = PapercutAppConstants.Name;
Expand All @@ -59,6 +106,17 @@ public Task HandleAsync(SettingsUpdatedEvent @event, CancellationToken token)

if (Properties.Settings.Default.RunOnStartup && !runOnStartup)
{
if (!File.Exists(executablePath))
{
logger.Error(
"App Startup Failure: {ExecutablePath} for Papercut Doesn't Exist -- Run at Startup Disabled",
executablePath);

Properties.Settings.Default.RunOnStartup = false;

return false;
}

// turn on...
logger.Information(
"Setting AppStartup Registry {Key} to Run Papercut at {ExecutablePath}",
Expand Down Expand Up @@ -86,7 +144,7 @@ public Task HandleAsync(SettingsUpdatedEvent @event, CancellationToken token)
"Failed");
}

return Task.CompletedTask;
return false;
}

#region Begin Static Container Registrations
Expand Down
19 changes: 6 additions & 13 deletions src/Papercut.UI/AppLayer/Settings/MergeServerBackendSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,19 @@

namespace Papercut.AppLayer.Settings;

public class MergeServerBackendSettings : IEventHandler<AppProcessExchangeEvent>
public class MergeServerBackendSettings(
MessagePathConfigurator configurator,
IMessageBus messageBus)
: IEventHandler<AppProcessExchangeEvent>
{
readonly MessagePathConfigurator _configurator;

readonly IMessageBus _messageBus;

public MergeServerBackendSettings(MessagePathConfigurator configurator, IMessageBus messageBus)
{
this._configurator = configurator;
this._messageBus = messageBus;
}

public async Task HandleAsync(AppProcessExchangeEvent @event, CancellationToken token)
{
ArgumentNullException.ThrowIfNull(@event);

if (string.IsNullOrWhiteSpace(@event.MessageWritePath))
return;

if (!this._configurator.LoadPaths.Any(s => s.StartsWith(@event.MessageWritePath, StringComparison.OrdinalIgnoreCase)))
if (!configurator.LoadPaths.Any(s => s.StartsWith(@event.MessageWritePath, StringComparison.OrdinalIgnoreCase)))
{
// add it for watching...
Properties.Settings.Default.MessagePaths = $"{Properties.Settings.Default.MessagePaths};{@event.MessageWritePath}";
Expand All @@ -60,7 +53,7 @@ public async Task HandleAsync(AppProcessExchangeEvent @event, CancellationToken
Properties.Settings.Default.Port = @event.Port;
Properties.Settings.Default.Save();

await this._messageBus.PublishAsync(new SettingsUpdatedEvent(previousSettings), token);
await messageBus.PublishAsync(new SettingsUpdatedEvent(previousSettings), token);
}

#region Begin Static Container Registrations
Expand Down
13 changes: 3 additions & 10 deletions src/Papercut.UI/AppLayer/Settings/SaveSettingsOnExitService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,8 @@

namespace Papercut.AppLayer.Settings;

public class SaveSettingsOnExitService : IAppLifecyclePreExit
public class SaveSettingsOnExitService(ILogger logger) : IAppLifecyclePreExit
{
readonly ILogger _logger;

public SaveSettingsOnExitService(ILogger logger)
{
this._logger = logger;
}

public Task<AppLifecycleActionResultType> OnPreExit()
{
try
Expand All @@ -44,12 +37,12 @@ public Task<AppLifecycleActionResultType> OnPreExit()
Properties.Settings.Default.MainWindowWidth = 400;
}

this._logger.Debug("Saving Updated Settings...");
logger.Debug("Saving Updated Settings...");
Properties.Settings.Default.Save();
}
catch (Exception ex)
{
this._logger.Error(ex, "Failure Saving Settings File");
logger.Error(ex, "Failure Saving Settings File");
}

return Task.FromResult(AppLifecycleActionResultType.Continue);
Expand Down
7 changes: 5 additions & 2 deletions src/Papercut.UI/Domain/Application/PapercutAppConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ namespace Papercut.Domain.Application;

public static class PapercutAppConstants
{
internal static string Name { get; } = "Papercut.App";
internal static string Name => "Papercut.Smtp.App";

internal static string ExecutablePath { get; } = Assembly.GetExecutingAssembly().Location;
internal static string LegacyName => "Papercut.App";

internal static string ExecutablePath { get; } =
Assembly.GetExecutingAssembly().Location.Replace(".dll", ".exe");
}

0 comments on commit 1137bc6

Please sign in to comment.