1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
package smtp
import (
"github.com/nicholas-fedor/shoutrrr/pkg/format"
"github.com/nicholas-fedor/shoutrrr/pkg/types"
)
const (
// EncNone represents no encryption.
EncNone encMethod = iota // 0
// EncExplicitTLS represents explicit TLS initiated with StartTLS.
EncExplicitTLS // 1
// EncImplicitTLS represents implicit TLS used throughout the session.
EncImplicitTLS // 2
// EncAuto represents automatic TLS selection based on port.
EncAuto // 3
// ImplicitTLSPort is the de facto standard SMTPS port for implicit TLS.
ImplicitTLSPort = 465
)
// EncMethods is the enum helper for populating the Encryption field.
var EncMethods = &encMethodVals{
None: EncNone,
ExplicitTLS: EncExplicitTLS,
ImplicitTLS: EncImplicitTLS,
Auto: EncAuto,
Enum: format.CreateEnumFormatter(
[]string{
"None",
"ExplicitTLS",
"ImplicitTLS",
"Auto",
}),
}
type encMethod int
type encMethodVals struct {
// None means no encryption
None encMethod
// ExplicitTLS means that TLS needs to be initiated by using StartTLS
ExplicitTLS encMethod
// ImplicitTLS means that TLS is used for the whole session
ImplicitTLS encMethod
// Auto means that TLS will be implicitly used for port 465, otherwise explicit TLS will be used if supported
Auto encMethod
// Enum is the EnumFormatter instance for EncMethods
Enum types.EnumFormatter
}
func (at encMethod) String() string {
return EncMethods.Enum.Print(int(at))
}
// useImplicitTLS determines if implicit TLS should be used based on encryption method and port.
func useImplicitTLS(encryption encMethod, port uint16) bool {
switch encryption {
case EncNone:
return false
case EncExplicitTLS:
return false
case EncImplicitTLS:
return true
case EncAuto:
return port == ImplicitTLSPort
default:
return false // Unreachable due to enum constraints, but included for safety
}
}
|