2023-01-15 16:14:19 +01:00
|
|
|
// SPDX-FileCopyrightText: 2022-2023 The go-mail Authors
|
2022-06-17 15:05:54 +02:00
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2022-03-05 16:27:09 +01:00
|
|
|
package mail
|
|
|
|
|
2024-10-06 17:15:39 +02:00
|
|
|
// 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 (
|
2024-02-24 21:46:48 +01:00
|
|
|
// 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
|
2024-10-06 17:15:39 +02:00
|
|
|
// the connection will be terminated with an error.
|
2022-03-05 16:27:09 +01:00
|
|
|
TLSMandatory TLSPolicy = iota
|
|
|
|
|
2024-02-24 21:46:48 +01:00
|
|
|
// 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
|
2024-10-06 17:15:39 +02:00
|
|
|
// back to non-encrypted plaintext transmission.
|
2022-03-05 16:27:09 +01:00
|
|
|
TLSOpportunistic
|
|
|
|
|
2024-10-06 17:15:39 +02:00
|
|
|
// 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
|
|
|
|
2024-10-06 17:15:39 +02: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"
|
|
|
|
}
|
|
|
|
}
|