From 1d6e8e23a863b4a607fce8cd329407fdb7cfe18b Mon Sep 17 00:00:00 2001 From: DistractADD Date: Mon, 17 Aug 2026 10:29:45 +1000 Subject: [PATCH] Cleaned & Updated Program.cs --- smtpproxy.net/Program.cs | 110 +++++++++++++++++++++++---------------- 1 file changed, 66 insertions(+), 44 deletions(-) diff --git a/smtpproxy.net/Program.cs b/smtpproxy.net/Program.cs index 26a8d7b..2464eec 100644 --- a/smtpproxy.net/Program.cs +++ b/smtpproxy.net/Program.cs @@ -1,44 +1,66 @@ -using System.Configuration.Install; -using System.Reflection; -using System.ServiceProcess; - -namespace smtpproxy.net; - -internal static class Program -{ - private static void Main(string[] args) - { - SMTPProxy sMTPProxy = new SMTPProxy(); - ServiceBase[] services = new ServiceBase[1] { sMTPProxy }; - if (args.Length != 0) - { - switch (args[0]) - { - case "-install": - ManagedInstallerClass.InstallHelper(new string[1] { Assembly.GetExecutingAssembly().Location }); - break; - case "-uninstall": - ManagedInstallerClass.InstallHelper(new string[2] - { - "/u", - Assembly.GetExecutingAssembly().Location - }); - break; - case "-console": - if (args.Length > 1 && args[1] == "-reload") - { - sMTPProxy.Reload(args[2]); - } - else - { - sMTPProxy.Start(); - } - break; - } - } - else - { - ServiceBase.Run(services); - } - } -} +using System; +using System.Configuration.Install; +using System.Reflection; +using System.ServiceProcess; + +namespace smtpproxy.net +{ + internal static class Program + { + private static void Main(string[] args) + { + SMTPProxy smtpProxy = new SMTPProxy(); + + if (args.Length != 0) + { + string command = args[0].ToLowerInvariant(); + + switch (command) + { + case "-install": + Console.WriteLine("Installing SMTPProxy Windows Service..."); + ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location }); + Console.WriteLine("Service installed successfully."); + break; + + case "-uninstall": + Console.WriteLine("Uninstalling SMTPProxy Windows Service..."); + ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location }); + Console.WriteLine("Service uninstalled successfully."); + break; + + case "-console": + if (args.Length > 1 && args[1].Equals("-reload", StringComparison.OrdinalIgnoreCase)) + { + if (args.Length > 2) + { + Console.WriteLine(string.Format("Reloading queued emails from: {0}", args[2])); + smtpProxy.Reload(args[2]); + } + else + { + Console.WriteLine("Error: Missing target folder path for -reload. Usage: -console -reload "); + } + } + else + { + Console.WriteLine("Starting SMTPProxy in Interactive Console Mode..."); + Console.WriteLine("Press [Enter] or [Ctrl+C] to stop the proxy."); + smtpProxy.Start(); + Console.ReadLine(); + } + break; + + default: + Console.WriteLine("Unknown parameter. Valid options: -install, -uninstall, -console, -console -reload "); + break; + } + } + else + { + ServiceBase[] servicesToRun = new ServiceBase[] { smtpProxy }; + ServiceBase.Run(servicesToRun); + } + } + } +} \ No newline at end of file