Skip to content

Commit

Permalink
feat (Config/IMAP): Explicit config to enable/disable IMAP server rat…
Browse files Browse the repository at this point in the history
…her than relying on omission of IMAP port. By default set to true to match existing behaviour.
  • Loading branch information
jafin committed Aug 11, 2021
1 parent 25d4275 commit 4fe90c3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions Rnwood.Smtp4dev/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ private static MapOptions<CommandLineOptions> 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) }
Expand Down
8 changes: 7 additions & 1 deletion Rnwood.Smtp4dev/Server/ImapServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,15 @@ public bool IsRunning

public void TryStart()
{
if (!serverOptions.CurrentValue.ImapServerEnabled)
{
Console.WriteLine("IMAP Server disabled");
return;
}

if (!serverOptions.CurrentValue.ImapPort.HasValue)
{
Console.WriteLine($"IMAP server disabled");
Console.WriteLine($"IMAP server disabled, no ImapPort specified");
return;
}

Expand Down
2 changes: 2 additions & 0 deletions Rnwood.Smtp4dev/Server/ServerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class ServerOptions

public int? ImapPort { get; set; } = 143;

public bool ImapServerEnabled { get; set; } = true;

public bool RecreateDb { get; set; }
}
}
5 changes: 4 additions & 1 deletion Rnwood.Smtp4dev/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,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": {
Expand Down

0 comments on commit 4fe90c3

Please sign in to comment.