Skip to content

Commit 971c67e

Browse files
committed
Merge branch 'release/6.1.0' into master
2 parents 965a347 + 0a5d90b commit 971c67e

File tree

18 files changed

+454
-72
lines changed

18 files changed

+454
-72
lines changed

src/Papercut.App.WebApi/PapercutWebApiModule.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ protected override void Load(ContainerBuilder builder)
2929
builder.RegisterType<PapercutWebServer>().As<IPapercutWebServer>()
3030
.SingleInstance();
3131

32+
builder.RegisterType<PapercutHttpServerSettings>().AsSelf().SingleInstance();
33+
3234
builder.RegisterApiControllers(this.ThisAssembly);
3335
}
3436
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Papercut
2+
//
3+
// Copyright © 2008 - 2012 Ken Robertson
4+
// Copyright © 2013 - 2022 Jaben Cargman
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
18+
19+
using System;
20+
21+
using Papercut.Core.Domain.Settings;
22+
23+
namespace Papercut.App.WebApi
24+
{
25+
public class PapercutHttpServerSettings : ISettingsTyped
26+
{
27+
public PapercutHttpServerSettings(ISettingStore settings)
28+
{
29+
this.Settings = settings;
30+
}
31+
32+
const string DefaultHttpBaseAddress = "http://127.0.0.1";
33+
34+
const int DefaultHttpPort = 37408;
35+
36+
public bool HttpServerEnabled
37+
{
38+
get => this.Settings.GetOrSet("HttpServerEnabled", true, "Is the Papercut Web UI Server enabled? (Defaults to true)");
39+
set { if (this.HttpServerEnabled != value) this.Settings.Set("HttpServerEnabled", value); }
40+
}
41+
42+
public int HttpPort
43+
{
44+
get => this.Settings.GetOrSet("HttpPort", DefaultHttpPort, $"The Papercut Web UI Server listening port (Defaults to {DefaultHttpPort}).");
45+
set { if (this.HttpPort != value) this.Settings.Set("HttpPort", value); }
46+
}
47+
48+
public string HttpBaseAddress
49+
{
50+
get =>
51+
this.Settings.GetOrSet<string>(
52+
"HttpBaseAddress",
53+
DefaultHttpBaseAddress,
54+
$"The Papercut Web UI Server listening address (Defaults to {DefaultHttpBaseAddress}).")
55+
.Replace("*", "0.0.0.0");
56+
57+
set { if (this.HttpBaseAddress != value) this.Settings.Set("HttpBaseAddress", value); }
58+
}
59+
60+
internal string GetListeningUri()
61+
{
62+
var uri = new UriBuilder($"{HttpBaseAddress.Trim()}:{HttpPort}");
63+
64+
return uri.ToString();
65+
}
66+
67+
public ISettingStore Settings { get; set; }
68+
}
69+
}

src/Papercut.App.WebApi/WebServer.cs

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,42 +37,34 @@ namespace Papercut.App.WebApi
3737

3838
internal class PapercutWebServer : Disposable, IPapercutWebServer
3939
{
40-
const string DefaultHttpBaseAddress = "http://127.0.0.1";
41-
42-
const int DefaultHttpPort = 37408;
43-
44-
readonly string _httpBaseAddress;
45-
46-
readonly int _httpPort;
47-
48-
readonly bool _httpServerEnabled;
49-
5040
readonly ILogger _logger;
5141

5242
readonly ILifetimeScope _scope;
5343

44+
private readonly PapercutHttpServerSettings _papercutHttpServerSettings;
45+
5446
volatile bool _isActive;
5547

5648
IDisposable _webAppDisposable;
5749

58-
public PapercutWebServer(ILifetimeScope scope, ISettingStore settingStore, ILogger logger)
50+
public PapercutWebServer(ILifetimeScope scope, PapercutHttpServerSettings papercutHttpServerSettings, ILogger logger)
5951
{
6052
this._scope = scope;
61-
this._logger = logger.ForContext<PapercutWebServer>();
62-
this._httpServerEnabled = settingStore.GetOrSet("HttpServerEnabled", true, $"Is the Papercut Web UI Server enabled (Defaults to true)?");
63-
this._httpBaseAddress = settingStore.GetOrSet("HttpBaseAddress", DefaultHttpBaseAddress, $"The Papercut Web UI Server listening address (Defaults to {DefaultHttpBaseAddress}).");
64-
this._httpPort = settingStore.GetOrSet("HttpPort", DefaultHttpPort, $"The Papercut Web UI Server listening port (Defaults to {DefaultHttpPort}).");
53+
this._papercutHttpServerSettings = papercutHttpServerSettings;
54+
this._logger = logger.ForContext<PapercutWebServer>().ForContext(
55+
nameof(PapercutHttpServerSettings),
56+
papercutHttpServerSettings);
6557
}
6658

6759
public Task StartAsync()
6860
{
69-
if (this._httpServerEnabled)
61+
if (this._papercutHttpServerSettings.HttpServerEnabled)
7062
{
7163
Task.Factory.StartNew(this.StartHttpServer);
7264
}
7365
else
7466
{
75-
this._logger.Information("Web Server is disabled");
67+
this._logger.Information("HTTP Server is disabled");
7668
}
7769

7870
return Task.CompletedTask;
@@ -100,22 +92,24 @@ void StartHttpServer()
10092
{
10193
if (this._isActive) return;
10294

103-
var uri = new UriBuilder(this._httpBaseAddress) { Port = this._httpPort }.Uri;
95+
string uri = this._papercutHttpServerSettings.GetListeningUri();
10496

10597
try
10698
{
107-
this._webAppDisposable = WebApp.Start(uri.ToString(), builder =>
108-
{
109-
var config = new HttpConfiguration();
99+
this._webAppDisposable = WebApp.Start(
100+
uri.Replace("0.0.0.0", "*"),
101+
builder =>
102+
{
103+
var config = new HttpConfiguration();
110104

111-
RouteConfig.Init(config, this._scope);
105+
RouteConfig.Init(config, this._scope);
112106

113-
builder.UseWebApi(config);
114-
});
107+
builder.UseWebApi(config);
108+
});
115109

116110
this._isActive = true;
117111

118-
this._logger.Information("[WebUI] Papercut Web UI is browsable at {@WebUiUri}", uri);
112+
this._logger.Information("[WebUI] Papercut Web UI is ready at {@WebUiUri}", uri);
119113
}
120114
catch (HttpListenerException ex)
121115
{

src/Papercut.Bootstrapper/PapercutVars.wxi

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<?define ProductName="Papercut SMTP" ?>
55

66
<?ifndef env.APPVEYOR_BUILD_VERSION ?>
7-
<?define Version="5.0.0.0" ?>
7+
<?define Version="6.0.0.0" ?>
88
<?else?>
99
<?define Version=$(env.APPVEYOR_BUILD_VERSION) ?>
1010
<?endif?>
@@ -14,15 +14,17 @@
1414
<?define PlatformPath = "x64" ?>
1515
<?define PlatformFolder = "win-x64" ?>
1616
<?define PlatformProgramFilesFolder = "ProgramFiles64Folder" ?>
17-
<?define EdgeRegistryKey = "SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" ?>
18-
<?define UpgradeCode="74DA413C-2E60-4151-9E56-AD3CC6320F7C" ?>
17+
<?define EdgeRegistryKeyOne = "SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" ?>
18+
<?define EdgeRegistryKeyTwo = "SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" ?>
19+
<?define UpgradeCode="74DA413C-2E60-4151-9E56-AD3CC6320F7C" ?>
1920
<?else ?>
2021
<?define Win64 = "no" ?>
2122
<?define PlatformPath = "x86" ?>
2223
<?define PlatformFolder = "win-x86" ?>
2324
<?define PlatformProgramFilesFolder = "ProgramFilesFolder" ?>
24-
<?define EdgeRegistryKey = "SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" ?>
25-
<?define UpgradeCode="74DA413C-2E60-4151-9E56-AD3CC6320F7D" ?>
25+
<?define EdgeRegistryKeyOne = "SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" ?>
26+
<?define EdgeRegistryKeyTwo = "SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" ?>
27+
<?define UpgradeCode="74DA413C-2E60-4151-9E56-AD3CC6320F7D" ?>
2628
<?endif ?>
2729

2830
<?define BinPath="bin\$(var.PlatformPath)\$(var.Configuration)" ?>

src/Papercut.Installer/PapercutVars.wxi

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<?define ProductName="Papercut SMTP" ?>
55

66
<?ifndef env.APPVEYOR_BUILD_VERSION ?>
7-
<?define Version="5.0.0.0" ?>
7+
<?define Version="6.0.0.0" ?>
88
<?else?>
99
<?define Version=$(env.APPVEYOR_BUILD_VERSION) ?>
1010
<?endif?>
@@ -14,14 +14,16 @@
1414
<?define PlatformPath = "x64" ?>
1515
<?define PlatformFolder = "win-x64" ?>
1616
<?define PlatformProgramFilesFolder = "ProgramFiles64Folder" ?>
17-
<?define EdgeRegistryKey = "SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" ?>
17+
<?define EdgeRegistryKeyOne = "SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" ?>
18+
<?define EdgeRegistryKeyTwo = "SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" ?>
1819
<?define UpgradeCode="74DA413C-2E60-4151-9E56-AD3CC6320F7C" ?>
1920
<?else ?>
2021
<?define Win64 = "no" ?>
2122
<?define PlatformPath = "x86" ?>
2223
<?define PlatformFolder = "win-x86" ?>
2324
<?define PlatformProgramFilesFolder = "ProgramFilesFolder" ?>
24-
<?define EdgeRegistryKey = "SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" ?>
25+
<?define EdgeRegistryKeyOne = "SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" ?>
26+
<?define EdgeRegistryKeyTwo = "SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" ?>
2527
<?define UpgradeCode="74DA413C-2E60-4151-9E56-AD3CC6320F7D" ?>
2628
<?endif ?>
2729

src/Papercut.Installer/Product.wxs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@
3333
<UIRef Id="UI_FeatureTree" />
3434

3535
<!-- Precondition: Check whether WebView RunTime already installed or not -->
36-
<Property Id="WVRTINSTALLED">
37-
<RegistrySearch Id="WVRTInstalled" Root="HKLM" Key="$(var.EdgeRegistryKey)" Name="name" Type="raw" Win64="$(var.Win64)"/>
36+
<Property Id="WVRTINSTALLEDCHECKONE">
37+
<RegistrySearch Id="WVRTInstalledCheckOne" Root="HKLM" Key="$(var.EdgeRegistryKeyOne)" Name="name" Type="raw" Win64="$(var.Win64)"/>
38+
</Property>
39+
40+
<Property Id="WVRTINSTALLEDCHECKTWO">
41+
<RegistrySearch Id="WVRTInstalledCheckTwo" Root="HKCU" Key="$(var.EdgeRegistryKeyTwo)" Name="name" Type="raw" Win64="$(var.Win64)"/>
3842
</Property>
3943

4044
<CustomAction Id="DownloadAndInvokeBootstrapper" Directory="INSTALLFOLDER" Execute="deferred" ExeCommand='powershell.exe Invoke-WebRequest -Uri "https://go.microsoft.com/fwlink/p/?LinkId=2124703" -OutFile "$env:TEMP\MicrosoftEdgeWebview2Setup.exe" ; &amp; $env:TEMP\MicrosoftEdgeWebview2Setup.exe /install ;' Return='check'/>
@@ -43,7 +47,7 @@
4347
<!-- [Download Bootstrapper] Use fwlink to download the bootstrapper to user TEMP folder and invoke-->
4448
<!-- Only run DownloadAndInvokeBootstrapper action during app install, app repair and when WVRT wasn't installed-->
4549
<Custom Action='DownloadAndInvokeBootstrapper' Before='InstallFinalize'>
46-
<![CDATA[NOT(REMOVE OR WVRTINSTALLED)]]>
50+
<![CDATA[NOT(REMOVE OR WVRTINSTALLEDCHECKONE OR WVRTINSTALLEDCHECKTWO)]]>
4751
</Custom>
4852
</InstallExecuteSequence>
4953

src/Papercut.Service/Papercut.Service.Settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"HttpBaseAddress": "http://127.0.0.1",
3-
"HttpBaseAddress_Description": "## The Papercut Web UI Server listening address (Defaults to http://127.0.0.1).",
3+
"HttpBaseAddress_Description": "## The Papercut Web UI Server listening address e.g. specific hostname http://hostname (Defaults to http://127.0.0.1). If you want listen to all hostnames use http://* . Warning: This option needs administrator permission. Please be carfully with this option for security reason! ",
44
"HttpPort": "37408",
55
"HttpPort_Description": "## The Http Web UI Server listening port (Defaults to 37408). Set to 0 to disable Http Web UI Server.",
66
"HttpServerEnabled": "True",
@@ -29,4 +29,4 @@
2929
"Port_Description": "## SMTP Server listening Port. Default is 25.",
3030
"SeqEndpoint": null,
3131
"SeqEndpoint_Description": "## Populate with a endpoint if you want to enable SEQ (https://getseq.net/) logging."
32-
}
32+
}

src/Papercut.UI/Helpers/MimeMessageEntry.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public int AttachmentsCount
5656
if (value == _attachmentsCount) return;
5757
_attachmentsCount = value;
5858
OnPropertyChanged(nameof(AttachmentsCount));
59+
OnPropertyChanged(nameof(HasAttachments));
5960
}
6061
}
6162

@@ -80,5 +81,10 @@ protected set
8081
OnPropertyChanged(nameof(Subject));
8182
}
8283
}
84+
85+
public bool HasAttachments
86+
{
87+
get => this.AttachmentsCount > 0;
88+
}
8389
}
8490
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// Papercut
2+
//
3+
// Copyright © 2008 - 2012 Ken Robertson
4+
// Copyright © 2013 - 2022 Jaben Cargman
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
18+
19+
using System;
20+
21+
using Autofac;
22+
23+
using Microsoft.Web.WebView2.Core;
24+
25+
using Papercut.Core.Annotations;
26+
27+
namespace Papercut.Infrastructure.WebView
28+
{
29+
public enum WebView2InstallType
30+
{
31+
WebView2, EdgeChromiumBeta, EdgeChromiumCanary, EdgeChromiumDev, NotInstalled
32+
}
33+
34+
/// <summary>
35+
/// Code from https://github.com/mortenbrudvik/KioskBrowser/blob/main/src/KioskBrowser/WebView2Install.cs
36+
/// THANK YOU
37+
/// </summary>
38+
public class WebView2Information
39+
{
40+
public WebView2Information()
41+
{
42+
this.Version = GetWebView2Version();
43+
this.InstallType = GetInstallType(this.Version);
44+
}
45+
46+
public string Version { get; }
47+
48+
public WebView2InstallType InstallType { get; }
49+
50+
public bool IsInstalled => InstallType != WebView2InstallType.NotInstalled;
51+
52+
private static string GetWebView2Version()
53+
{
54+
try
55+
{
56+
return CoreWebView2Environment.GetAvailableBrowserVersionString();
57+
}
58+
catch (Exception) { return ""; }
59+
}
60+
61+
private static WebView2InstallType GetInstallType(string version)
62+
{
63+
if (string.IsNullOrWhiteSpace(version))
64+
{
65+
return WebView2InstallType.NotInstalled;
66+
}
67+
68+
if (version.Contains("dev"))
69+
return WebView2InstallType.EdgeChromiumDev;
70+
71+
if (version.Contains("beta"))
72+
return WebView2InstallType.EdgeChromiumBeta;
73+
74+
if (version.Contains("canary"))
75+
return WebView2InstallType.EdgeChromiumCanary;
76+
77+
return WebView2InstallType.WebView2;
78+
}
79+
80+
#region Begin Static Container Registrations
81+
82+
/// <summary>
83+
/// Called dynamically from the RegisterStaticMethods() call in the container module.
84+
/// </summary>
85+
/// <param name="builder"></param>
86+
[UsedImplicitly]
87+
static void Register([NotNull] ContainerBuilder builder)
88+
{
89+
if (builder == null) throw new ArgumentNullException(nameof(builder));
90+
91+
builder.RegisterType<WebView2Information>().AsSelf().SingleInstance();
92+
}
93+
94+
#endregion
95+
}
96+
}

0 commit comments

Comments
 (0)