go-mail/tls.go

45 lines
1.3 KiB
Go
Raw Permalink Normal View History

// SPDX-FileCopyrightText: 2022-2023 The go-mail Authors
//
// SPDX-License-Identifier: MIT
2022-03-05 16:27:09 +01:00
package mail
// TLSPolicy is a type wrapper for an int type and describes the different TLS policies we allow.
2022-03-05 16:27:09 +01:00
type TLSPolicy int
const (
// TLSMandatory requires that the connection to the server is
2022-03-05 16:27:09 +01:00
// encrypting using STARTTLS. If the server does not support STARTTLS
// the connection will be terminated with an error.
2022-03-05 16:27:09 +01:00
TLSMandatory TLSPolicy = iota
// TLSOpportunistic tries to establish an encrypted connection via the
2022-03-05 16:27:09 +01:00
// STARTTLS protocol. If the server does not support this, it will fall
// back to non-encrypted plaintext transmission.
2022-03-05 16:27:09 +01:00
TLSOpportunistic
// NoTLS forces the transaction to be not encrypted.
2022-03-05 16:27:09 +01:00
NoTLS
)
2022-03-07 16:24:49 +01:00
// String satisfies the fmt.Stringer interface for the TLSPolicy type.
//
// This function returns a string representation of the TLSPolicy. It matches the policy
// value to predefined constants and returns the corresponding string. If the policy does
// not match any known values, it returns "UnknownPolicy".
//
// Returns:
// - A string representing the TLSPolicy.
2022-03-07 16:24:49 +01:00
func (p TLSPolicy) String() string {
switch p {
case TLSMandatory:
return "TLSMandatory"
case TLSOpportunistic:
return "TLSOpportunistic"
case NoTLS:
return "NoTLS"
default:
return "UnknownPolicy"
}
}