From 89584d5e055fd5f837276115122b9242ecd71381 Mon Sep 17 00:00:00 2001 From: Jason Finch Date: Sat, 7 Aug 2021 11:59:55 +1000 Subject: [PATCH 1/2] feat (Config/IMAP): Explicit config to enable/disable IMAP server rather than relying on omission of IMAP port. By default set to true to match existing behaviour. --- Rnwood.Smtp4dev/Server/ImapServer.cs | 8 +++++++- Rnwood.Smtp4dev/Server/ServerOptions.cs | 2 ++ Rnwood.Smtp4dev/appsettings.json | 5 ++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Rnwood.Smtp4dev/Server/ImapServer.cs b/Rnwood.Smtp4dev/Server/ImapServer.cs index 8aa641caa..f7b3c7690 100644 --- a/Rnwood.Smtp4dev/Server/ImapServer.cs +++ b/Rnwood.Smtp4dev/Server/ImapServer.cs @@ -60,9 +60,15 @@ public bool IsRunning public void TryStart() { + if (!serverOptions.CurrentValue.ImapServerEnabled) + { + log.Information("IMAP Server disabled"); + return; + } + if (!serverOptions.CurrentValue.ImapPort.HasValue) { - log.Information("IMAP server disabled"); + log.Information("IMAP server disabled, no ImapPort specified"); return; } diff --git a/Rnwood.Smtp4dev/Server/ServerOptions.cs b/Rnwood.Smtp4dev/Server/ServerOptions.cs index 79c6631e0..2cd781064 100644 --- a/Rnwood.Smtp4dev/Server/ServerOptions.cs +++ b/Rnwood.Smtp4dev/Server/ServerOptions.cs @@ -22,6 +22,8 @@ public class ServerOptions public int? ImapPort { get; set; } = 143; + public bool ImapServerEnabled { get; set; } = true; + public bool RecreateDb { get; set; } } } diff --git a/Rnwood.Smtp4dev/appsettings.json b/Rnwood.Smtp4dev/appsettings.json index d9687ecf6..a1f79f65e 100644 --- a/Rnwood.Smtp4dev/appsettings.json +++ b/Rnwood.Smtp4dev/appsettings.json @@ -48,7 +48,10 @@ "TlsCertificate": "", //Specifies the port the IMAP server will listen on - allows standard email clients to view/retrieve messages - "ImapPort": 143 + "ImapPort": 143, + + // Explicity enable/disable IMAP server, default is true + "ImapServerEnabled": true }, "RelayOptions": { From 4129d572ced3bad311affe833e10d6a7b0d70555 Mon Sep 17 00:00:00 2001 From: Jason Finch Date: Sun, 26 Sep 2021 09:57:34 +1000 Subject: [PATCH 2/2] task (rebase): Rebase onto master. --- Rnwood.Smtp4dev/CommandLineParser.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Rnwood.Smtp4dev/CommandLineParser.cs b/Rnwood.Smtp4dev/CommandLineParser.cs index 69e80563b..ed897c898 100644 --- a/Rnwood.Smtp4dev/CommandLineParser.cs +++ b/Rnwood.Smtp4dev/CommandLineParser.cs @@ -37,6 +37,7 @@ public static MapOptions TryParseCommandLine(string[] args) { "relaypassword=", "The password for the SMTP server used to relay messages", data => map.Add(data, x=> x.RelayOptions.Password) }, { "relaytlsmode=", "Sets the TLS mode when connecting to relay SMTP server. See: http://www.mimekit.net/docs/html/T_MailKit_Security_SecureSocketOptions.htm", data => map.Add(data, x=> x.RelayOptions.TlsMode) }, { "imapport=", "Specifies the port the IMAP server will listen on - allows standard email clients to view/retrieve messages", data => map.Add(data, x=> x.ServerOptions.ImapPort) }, + { "imapserverenabled=", "Boolean to determine if IMAP server should start, default is true", data => map.Add(data, x=>x.ServerOptions.ImapServerEnabled)}, { "nousersettings", "Skip loading of appsetttings.json file in %APPDATA%", data => map.Add((data !=null).ToString(), x=> x.NoUserSettings) }, { "debugsettings", "Prints out most settings values on startup", data => map.Add((data !=null).ToString(), x=> x.DebugSettings) }, { "recreatedb", "Recreates the DB on startup if it already exists", data => map.Add((data !=null).ToString(), x=> x.ServerOptions.RecreateDb) }