namespace ScadaLink.NotificationService; /// /// NS-005: The three TLS modes the design doc defines for SMTP connections. /// A single boolean cannot represent the requirement, so the configured /// SmtpConfiguration.TlsMode string is parsed into this three-state enum. /// public enum SmtpTlsMode { /// No transport security — plain SMTP. Maps to SecureSocketOptions.None. None, /// Opportunistic STARTTLS upgrade (typically port 587). Maps to SecureSocketOptions.StartTls. StartTls, /// Implicit TLS / SSL-on-connect (typically port 465). Maps to SecureSocketOptions.SslOnConnect. Ssl, } /// /// NS-005: Parses the free-text SmtpConfiguration.TlsMode value into a /// , rejecting unknown values rather than silently /// falling back to opportunistic negotiation. /// public static class SmtpTlsModeParser { /// /// Parses a configured TLS mode string. A null or empty value defaults to /// (the design-doc default for port 587). /// /// The value is not one of None/StartTLS/SSL. public static SmtpTlsMode Parse(string? tlsMode) { if (string.IsNullOrWhiteSpace(tlsMode)) { return SmtpTlsMode.StartTls; } return tlsMode.Trim().ToLowerInvariant() switch { "none" => SmtpTlsMode.None, "starttls" => SmtpTlsMode.StartTls, "ssl" => SmtpTlsMode.Ssl, _ => throw new ArgumentException( $"Unknown SMTP TLS mode '{tlsMode}'. Expected one of: None, StartTLS, SSL.", nameof(tlsMode)), }; } }