Skip to content

Commit e0f2d3a

Browse files
committed
Extract IMailSettings
1 parent 098f830 commit e0f2d3a

File tree

7 files changed

+212
-165
lines changed

7 files changed

+212
-165
lines changed

DNN Platform/DotNetNuke.Abstractions/Application/IHostSettings.cs

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -253,49 +253,4 @@ public interface IHostSettings
253253

254254
/// <summary>Gets or sets the PerformanceSettings.</summary>
255255
public PerformanceSettings PerformanceSetting { get; set; }
256-
257-
/// <summary>Gets a value indicating whether SSL is Enabled for SMTP.</summary>
258-
/// <param name="portalId">The portal ID.</param>
259-
/// <returns>Whether SSL is enabled for SMTP in the given portal.</returns>
260-
public bool EnableSmtpSsl(int portalId);
261-
262-
/// <summary>Gets the currently configured SMTP OAuth provider if existing, for the current portal if portal SMTP enabled, otherwise for the installation.</summary>
263-
/// <param name="portalId">The portal ID.</param>
264-
/// <returns>The name of the SMTP OAuth provider.</returns>
265-
public string SmtpAuthProvider(int portalId);
266-
267-
/// <summary>Gets the SMTP Authentication type.</summary>
268-
/// <param name="portalId">The portal ID.</param>
269-
/// <returns>The authentication type indicator, <c>"1"</c> for basic auth, <c>"2"</c> for NTLM auth, <c>"3"</c> for OAuth, any other value for anonymous auth.</returns>
270-
public string SmtpAuthentication(int portalId);
271-
272-
/// <summary>Gets the SMTP Password.</summary>
273-
/// <param name="portalId">The portal ID.</param>
274-
/// <returns>The SMTP password.</returns>
275-
public string SmtpPassword(int portalId);
276-
277-
/// <summary>Gets the SMTP Server.</summary>
278-
/// <param name="portalId">The portal ID.</param>
279-
/// <returns>The SMTP server.</returns>
280-
public string SmtpServer(int portalId);
281-
282-
/// <summary>Gets the SMTP Username.</summary>
283-
/// <param name="portalId">The portal ID.</param>
284-
/// <returns>The SMTP username.</returns>
285-
public string SmtpUsername(int portalId);
286-
287-
/// <summary>Gets the SMTP Connection Limit.</summary>
288-
/// <param name="portalId">The portal ID.</param>
289-
/// <returns>The SMTP connection limit.</returns>
290-
public int SmtpConnectionLimit(int portalId);
291-
292-
/// <summary>Gets the SMTP MaxIdleTime.</summary>
293-
/// <param name="portalId">The portal ID.</param>
294-
/// <returns>The SMTP maximum idle time.</returns>
295-
public TimeSpan SmtpMaxIdleTime(int portalId);
296-
297-
/// <summary>Gets a value indicating whether SMTP information is stored at the portal level.</summary>
298-
/// <param name="portalId">The portal ID.</param>
299-
/// <returns>Whether SMTP information is stored per portal.</returns>
300-
public bool SmtpPortalEnabled(int portalId);
301256
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information
4+
5+
namespace DotNetNuke.Abstractions.Application;
6+
7+
using System;
8+
9+
/// <summary>Settings related to sending emails.</summary>
10+
public interface IMailSettings
11+
{
12+
/// <summary>Gets a value indicating whether secure connection are enabled for mail.</summary>
13+
/// <param name="portalId">The portal ID.</param>
14+
/// <returns>Whether secure connections are enabled for mail in the given portal.</returns>
15+
public bool GetSecureConnectionEnabled(int portalId);
16+
17+
/// <summary>Gets the currently configured mail OAuth provider if existing, for the current portal if portal mail enabled, otherwise for the installation.</summary>
18+
/// <param name="portalId">The portal ID.</param>
19+
/// <returns>The name of the mail OAuth provider.</returns>
20+
public string GetAuthProvider(int portalId);
21+
22+
/// <summary>Gets the mail Authentication type.</summary>
23+
/// <param name="portalId">The portal ID.</param>
24+
/// <returns>The authentication type indicator, <c>"1"</c> for basic auth, <c>"2"</c> for NTLM auth, <c>"3"</c> for OAuth, any other value for anonymous auth.</returns>
25+
public string GetAuthentication(int portalId);
26+
27+
/// <summary>Gets the mail Password.</summary>
28+
/// <param name="portalId">The portal ID.</param>
29+
/// <returns>The mail password.</returns>
30+
public string GetPassword(int portalId);
31+
32+
/// <summary>Gets the mail Server.</summary>
33+
/// <param name="portalId">The portal ID.</param>
34+
/// <returns>The mail server.</returns>
35+
public string GetServer(int portalId);
36+
37+
/// <summary>Gets the mail Username.</summary>
38+
/// <param name="portalId">The portal ID.</param>
39+
/// <returns>The mail username.</returns>
40+
public string GetUsername(int portalId);
41+
42+
/// <summary>Gets the mail Connection Limit.</summary>
43+
/// <param name="portalId">The portal ID.</param>
44+
/// <returns>The mail connection limit.</returns>
45+
public int GetConnectionLimit(int portalId);
46+
47+
/// <summary>Gets the mail MaxIdleTime.</summary>
48+
/// <param name="portalId">The portal ID.</param>
49+
/// <returns>The mail maximum idle time.</returns>
50+
public TimeSpan GetMaxIdleTime(int portalId);
51+
52+
/// <summary>Gets a value indicating whether mail information is stored at the portal level.</summary>
53+
/// <param name="portalId">The portal ID.</param>
54+
/// <returns>Whether mail information is stored per portal.</returns>
55+
public bool IsPortalEnabled(int portalId);
56+
}

DNN Platform/Library/DotNetNuke.Library.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@
240240
<Compile Include="Entities\Content\Taxonomy\ScopeTypeMemberNameFixer.cs" />
241241
<Compile Include="Entities\Content\Taxonomy\TermHelper.cs" />
242242
<Compile Include="Entities\Host\HostSettings.cs" />
243+
<Compile Include="Entities\Host\MailSettings.cs" />
243244
<Compile Include="Entities\Modules\BusinessControllerProvider.cs" />
244245
<Compile Include="Entities\Modules\BusinessControllerProviderExtensions.cs" />
245246
<Compile Include="Entities\Content\Workflow\Actions\TabActions\CompleteState.cs" />

DNN Platform/Library/Entities/Host/Host.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace DotNetNuke.Entities.Host
2020

2121
/// <summary>Contains most of the host settings.</summary>
2222
[Serializable]
23-
[DnnDeprecated(10, 0, 2, "Use DotNetNuke.Abstractions.Application.IHostSettings via dependency injection")]
23+
[DnnDeprecated(10, 0, 2, "Use DotNetNuke.Abstractions.Application.IHostSettings or DotNetNuke.Abstractions.Application.IMailSettings via dependency injection")]
2424
public partial class Host : BaseEntityInfo
2525
{
2626
private static Globals.PerformanceSettings? performanceSetting;

DNN Platform/Library/Entities/Host/HostSettings.cs

Lines changed: 41 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ namespace DotNetNuke.Entities.Host;
1010
using DotNetNuke.Abstractions.Security;
1111
using DotNetNuke.Common;
1212
using DotNetNuke.Common.Utilities;
13-
using DotNetNuke.Entities.Portals;
1413
using DotNetNuke.UI.Skins;
1514
using DotNetNuke.Web.Client;
1615

@@ -23,13 +22,16 @@ public class HostSettings(IHostSettingsService hostSettingsService) : IHostSetti
2322
private PerformanceSettings? performanceSettings;
2423

2524
/// <inheritdoc />
26-
public TimeSpan AutoAccountUnlockDuration => TimeSpan.FromMinutes(hostSettingsService.GetInteger("AutoAccountUnlockDuration", 10));
25+
public TimeSpan AutoAccountUnlockDuration =>
26+
TimeSpan.FromMinutes(hostSettingsService.GetInteger("AutoAccountUnlockDuration", 10));
2727

2828
/// <inheritdoc />
29-
public CacheControlHeader AuthenticatedCacheability => ToCacheControlHeader(hostSettingsService.GetString("AuthenticatedCacheability", "4"));
29+
public CacheControlHeader AuthenticatedCacheability =>
30+
ToCacheControlHeader(hostSettingsService.GetString("AuthenticatedCacheability", "4"));
3031

3132
/// <inheritdoc />
32-
public CacheControlHeader UnauthenticatedCacheability => ToCacheControlHeader(hostSettingsService.GetString("UnauthenticatedCacheability", "4"));
33+
public CacheControlHeader UnauthenticatedCacheability =>
34+
ToCacheControlHeader(hostSettingsService.GetString("UnauthenticatedCacheability", "4"));
3335

3436
/// <inheritdoc />
3537
public bool CdnEnabled => hostSettingsService.GetBoolean("CDNEnabled", false);
@@ -44,10 +46,13 @@ public class HostSettings(IHostSettingsService hostSettingsService) : IHostSetti
4446
public bool DisableEditBar => hostSettingsService.GetBoolean("DisableEditBar", false);
4547

4648
/// <inheritdoc />
47-
public bool AllowControlPanelToDetermineVisibility => hostSettingsService.GetBoolean("AllowControlPanelToDetermineVisibility", Globals.glbAllowControlPanelToDetermineVisibility);
49+
public bool AllowControlPanelToDetermineVisibility => hostSettingsService.GetBoolean(
50+
"AllowControlPanelToDetermineVisibility",
51+
Globals.glbAllowControlPanelToDetermineVisibility);
4852

4953
/// <inheritdoc />
50-
public bool CrmEnableCompositeFiles => hostSettingsService.GetBoolean(ClientResourceSettings.EnableCompositeFilesKey, false);
54+
public bool CrmEnableCompositeFiles =>
55+
hostSettingsService.GetBoolean(ClientResourceSettings.EnableCompositeFilesKey, false);
5156

5257
/// <inheritdoc />
5358
public bool CrmMinifyCss => hostSettingsService.GetBoolean(ClientResourceSettings.MinifyCssKey);
@@ -103,10 +108,12 @@ public string DefaultDocType
103108
doctype = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">";
104109
break;
105110
case "1":
106-
doctype = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
111+
doctype =
112+
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
107113
break;
108114
case "2":
109-
doctype = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";
115+
doctype =
116+
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";
110117
break;
111118
case "3":
112119
doctype = "<!DOCTYPE html>";
@@ -197,10 +204,12 @@ public string DefaultPortalSkin
197204
public bool EventLogBuffer => hostSettingsService.GetBoolean("EventLogBuffer", false);
198205

199206
/// <inheritdoc />
200-
public IFileExtensionAllowList AllowedExtensionAllowList => new FileExtensionWhitelist(hostSettingsService.GetString("FileExtensions"));
207+
public IFileExtensionAllowList AllowedExtensionAllowList =>
208+
new FileExtensionWhitelist(hostSettingsService.GetString("FileExtensions"));
201209

202210
/// <inheritdoc />
203-
public IFileExtensionAllowList DefaultEndUserExtensionAllowList => new FileExtensionWhitelist(hostSettingsService.GetString("DefaultEndUserExtensionWhitelist"));
211+
public IFileExtensionAllowList DefaultEndUserExtensionAllowList =>
212+
new FileExtensionWhitelist(hostSettingsService.GetString("DefaultEndUserExtensionWhitelist"));
204213

205214
/// <inheritdoc />
206215
public string Guid => GetHostGuid(hostSettingsService);
@@ -230,16 +239,19 @@ public string DefaultPortalSkin
230239
public int MessageSchedulerBatchSize => hostSettingsService.GetInteger("MessageSchedulerBatchSize", 50);
231240

232241
/// <inheritdoc />
233-
public TimeSpan MembershipResetLinkValidity => TimeSpan.FromMinutes(hostSettingsService.GetInteger("MembershipResetLinkValidity", 60));
242+
public TimeSpan MembershipResetLinkValidity =>
243+
TimeSpan.FromMinutes(hostSettingsService.GetInteger("MembershipResetLinkValidity", 60));
234244

235245
/// <inheritdoc />
236-
public TimeSpan AdminMembershipResetLinkValidity => TimeSpan.FromMinutes(hostSettingsService.GetInteger("AdminMembershipResetLinkValidity", 1440));
246+
public TimeSpan AdminMembershipResetLinkValidity =>
247+
TimeSpan.FromMinutes(hostSettingsService.GetInteger("AdminMembershipResetLinkValidity", 1440));
237248

238249
/// <inheritdoc />
239250
public int MembershipNumberPasswords => hostSettingsService.GetInteger("MembershipNumberPasswords", 5);
240251

241252
/// <inheritdoc />
242-
public int MembershipDaysBeforePasswordReuse => hostSettingsService.GetInteger("MembershipDaysBeforePasswordReuse", 0);
253+
public int MembershipDaysBeforePasswordReuse =>
254+
hostSettingsService.GetInteger("MembershipDaysBeforePasswordReuse", 0);
243255

244256
/// <inheritdoc />
245257
public string MembershipFailedIPException => hostSettingsService.GetString("MembershipFailedIPException", "403");
@@ -272,7 +284,8 @@ public string PageStatePersister
272284
public TimeSpan PasswordExpiry => TimeSpan.FromDays(hostSettingsService.GetInteger("PasswordExpiry", 0));
273285

274286
/// <inheritdoc />
275-
public TimeSpan PasswordExpiryReminder => TimeSpan.FromDays(hostSettingsService.GetInteger("PasswordExpiryReminder", 7));
287+
public TimeSpan PasswordExpiryReminder =>
288+
TimeSpan.FromDays(hostSettingsService.GetInteger("PasswordExpiryReminder", 7));
276289

277290
/// <inheritdoc />
278291
public string ProxyPassword => hostSettingsService.GetString("ProxyPassword");
@@ -290,10 +303,16 @@ public string PageStatePersister
290303
public bool RememberCheckbox => hostSettingsService.GetBoolean("RememberCheckbox", true);
291304

292305
/// <inheritdoc />
293-
public SchedulerMode SchedulerMode => !Enum.TryParse<SchedulerMode>(hostSettingsService.GetString("SchedulerMode"), ignoreCase: true, out var schedulerMode) ? SchedulerMode.TimerMethod : schedulerMode;
306+
public SchedulerMode SchedulerMode => !Enum.TryParse<SchedulerMode>(
307+
hostSettingsService.GetString("SchedulerMode"),
308+
ignoreCase: true,
309+
out var schedulerMode)
310+
? SchedulerMode.TimerMethod
311+
: schedulerMode;
294312

295313
/// <inheritdoc />
296-
public TimeSpan SchedulerDelayAtAppStart => TimeSpan.FromSeconds(hostSettingsService.GetInteger("SchedulerdelayAtAppStart", 1));
314+
public TimeSpan SchedulerDelayAtAppStart =>
315+
TimeSpan.FromSeconds(hostSettingsService.GetInteger("SchedulerdelayAtAppStart", 1));
297316

298317
/// <inheritdoc />
299318
public bool SearchIncludeCommon => hostSettingsService.GetBoolean("SearchIncludeCommon", false);
@@ -308,7 +327,8 @@ public string PageStatePersister
308327
public int SearchMinWordLength => hostSettingsService.GetInteger("MinSearchWordLength", 4);
309328

310329
/// <inheritdoc />
311-
public string SearchIncludedTagInfoFilter => hostSettingsService.GetString("SearchIncludedTagInfoFilter", string.Empty);
330+
public string SearchIncludedTagInfoFilter =>
331+
hostSettingsService.GetString("SearchIncludedTagInfoFilter", string.Empty);
312332

313333
/// <inheritdoc />
314334
public bool ShowCriticalErrors => hostSettingsService.GetBoolean("ShowCriticalErrors", true);
@@ -326,13 +346,15 @@ public string PageStatePersister
326346
public int UserQuota => hostSettingsService.GetInteger("UserQuota", 0);
327347

328348
/// <inheritdoc />
329-
public TimeSpan WebRequestTimeout => TimeSpan.FromMilliseconds(hostSettingsService.GetInteger("WebRequestTimeout", 10000));
349+
public TimeSpan WebRequestTimeout =>
350+
TimeSpan.FromMilliseconds(hostSettingsService.GetInteger("WebRequestTimeout", 10000));
330351

331352
/// <inheritdoc />
332353
public bool EnableMsAjaxCdn => hostSettingsService.GetBoolean("EnableMsAjaxCDN", false);
333354

334355
/// <inheritdoc />
335-
public TimeSpan AsyncTimeout => TimeSpan.FromMinutes(Math.Max(90, hostSettingsService.GetInteger("AsyncTimeout", 90)));
356+
public TimeSpan AsyncTimeout =>
357+
TimeSpan.FromMinutes(Math.Max(90, hostSettingsService.GetInteger("AsyncTimeout", 90)));
336358

337359
/// <inheritdoc />
338360
public bool IsLocked => hostSettingsService.GetBoolean("IsLocked", false);
@@ -373,95 +395,6 @@ public static string GetHostGuid(IHostSettingsService hostSettingsService)
373395
return hostSettingsService.GetString("GUID");
374396
}
375397

376-
/// <inheritdoc />
377-
public string SmtpAuthentication(int portalId) => this.GetSmtpSetting(portalId, "SMTPAuthentication");
378-
379-
/// <inheritdoc />
380-
public string SmtpPassword(int portalId)
381-
{
382-
if (this.SmtpPortalEnabled(portalId))
383-
{
384-
return PortalController.GetEncryptedString(this, "SMTPPassword", portalId, Config.GetDecryptionkey());
385-
}
386-
387-
string decryptedText;
388-
try
389-
{
390-
decryptedText = hostSettingsService.GetEncryptedString("SMTPPassword", Config.GetDecryptionkey());
391-
}
392-
catch (Exception)
393-
{
394-
// fixes case where SMTP Password failed to encrypt due to failing upgrade
395-
var current = hostSettingsService.GetString("SMTPPassword");
396-
if (!string.IsNullOrEmpty(current))
397-
{
398-
hostSettingsService.UpdateEncryptedString("SMTPPassword", current, Config.GetDecryptionkey());
399-
decryptedText = current;
400-
}
401-
else
402-
{
403-
decryptedText = string.Empty;
404-
}
405-
}
406-
407-
return decryptedText;
408-
}
409-
410-
/// <inheritdoc />
411-
public string SmtpServer(int portalId) => this.GetSmtpSetting(portalId, "SMTPServer");
412-
413-
/// <inheritdoc />
414-
public string SmtpUsername(int portalId) => this.GetSmtpSetting(portalId, "SMTPUsername");
415-
416-
/// <inheritdoc />
417-
public int SmtpConnectionLimit(int portalId)
418-
{
419-
if (this.SmtpPortalEnabled(portalId))
420-
{
421-
return PortalController.GetPortalSettingAsInteger("SMTPConnectionLimit", portalId, 2);
422-
}
423-
424-
return hostSettingsService.GetInteger("SMTPConnectionLimit", 2);
425-
}
426-
427-
/// <inheritdoc />
428-
public TimeSpan SmtpMaxIdleTime(int portalId)
429-
{
430-
var idleMilliseconds = this.SmtpPortalEnabled(portalId)
431-
? PortalController.GetPortalSettingAsInteger("SMTPMaxIdleTime", portalId, 100000)
432-
: hostSettingsService.GetInteger("SMTPMaxIdleTime", 100000);
433-
return TimeSpan.FromMilliseconds(idleMilliseconds);
434-
}
435-
436-
/// <inheritdoc />
437-
public bool EnableSmtpSsl(int portalId)
438-
{
439-
if (this.SmtpPortalEnabled(portalId))
440-
{
441-
return PortalController.GetPortalSettingAsBoolean("SMTPEnableSSL", portalId, false);
442-
}
443-
444-
return hostSettingsService.GetBoolean("SMTPEnableSSL", false);
445-
}
446-
447-
/// <inheritdoc />
448-
public string SmtpAuthProvider(int portalId)
449-
{
450-
if (this.SmtpPortalEnabled(portalId))
451-
{
452-
return PortalController.GetPortalSetting("SMTPAuthProvider", portalId, string.Empty);
453-
}
454-
455-
return hostSettingsService.GetString("SMTPAuthProvider", string.Empty);
456-
}
457-
458-
/// <inheritdoc />
459-
public bool SmtpPortalEnabled(int portalId)
460-
{
461-
var currentSmtpMode = PortalController.GetPortalSetting("SMTPmode", portalId, Null.NullString);
462-
return currentSmtpMode.Equals("P", StringComparison.OrdinalIgnoreCase);
463-
}
464-
465398
private static CacheControlHeader ToCacheControlHeader(string headerId)
466399
=> headerId switch
467400
{
@@ -473,15 +406,4 @@ private static CacheControlHeader ToCacheControlHeader(string headerId)
473406
"5" => CacheControlHeader.ServerAndPrivate,
474407
_ => CacheControlHeader.Unknown,
475408
};
476-
477-
/// <summary>Gets the SMTP setting, if portal SMTP is configured, it will return items from the portal settings collection.</summary>
478-
private string GetSmtpSetting(int portalId, string settingName)
479-
{
480-
if (this.SmtpPortalEnabled(portalId))
481-
{
482-
return PortalController.GetPortalSetting(settingName, portalId, Null.NullString);
483-
}
484-
485-
return hostSettingsService.GetString(settingName);
486-
}
487409
}

0 commit comments

Comments
 (0)