Refactor TLSPolicy documentation and String method

Updated the TLSPolicy type documentation to improve clarity and consistency. Enhanced the String method with detailed commentary and return value explanation, ensuring it better adheres to the fmt.Stringer interface.
This commit is contained in:
Winni Neessen 2024-10-06 17:15:39 +02:00
parent 6ce5c2a860
commit f0388ec600
Signed by: wneessen
GPG key ID: 385AC9889632126E

17
tls.go
View file

@ -4,25 +4,32 @@
package mail package mail
// TLSPolicy type describes a int alias for the different TLS policies we allow // TLSPolicy is a type wrapper for an int type and describes the different TLS policies we allow.
type TLSPolicy int type TLSPolicy int
const ( const (
// TLSMandatory requires that the connection to the server is // TLSMandatory requires that the connection to the server is
// encrypting using STARTTLS. If the server does not support STARTTLS // encrypting using STARTTLS. If the server does not support STARTTLS
// the connection will be terminated with an error // the connection will be terminated with an error.
TLSMandatory TLSPolicy = iota TLSMandatory TLSPolicy = iota
// TLSOpportunistic tries to establish an encrypted connection via the // TLSOpportunistic tries to establish an encrypted connection via the
// STARTTLS protocol. If the server does not support this, it will fall // STARTTLS protocol. If the server does not support this, it will fall
// back to non-encrypted plaintext transmission // back to non-encrypted plaintext transmission.
TLSOpportunistic TLSOpportunistic
// NoTLS forces the transaction to be not encrypted // NoTLS forces the transaction to be not encrypted.
NoTLS NoTLS
) )
// String is a standard method to convert a TLSPolicy into a printable format // 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.
func (p TLSPolicy) String() string { func (p TLSPolicy) String() string {
switch p { switch p {
case TLSMandatory: case TLSMandatory: