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-09 16:52:23 +01:00
|
|
|
package mail
|
|
|
|
|
2024-10-05 12:00:10 +02:00
|
|
|
// Header is a type wrapper for a string and represents email header fields in a Msg.
|
2022-03-09 16:52:23 +01:00
|
|
|
type Header string
|
|
|
|
|
2024-10-05 12:00:10 +02:00
|
|
|
// AddrHeader is a type wrapper for a string and represents email address headers fields in a Msg.
|
2022-03-10 16:19:51 +01:00
|
|
|
type AddrHeader string
|
2022-03-09 16:52:23 +01:00
|
|
|
|
2024-10-05 12:00:10 +02:00
|
|
|
// Importance is a type wrapper for an int and represents the level of importance or priority for a Msg.
|
2022-03-13 19:24:46 +01:00
|
|
|
type Importance int
|
|
|
|
|
2022-03-10 16:19:51 +01:00
|
|
|
const (
|
2024-10-05 12:00:10 +02:00
|
|
|
// HeaderContentDescription is the "Content-Description" header.
|
2023-01-31 18:35:48 +01:00
|
|
|
HeaderContentDescription Header = "Content-Description"
|
|
|
|
|
2024-10-05 12:00:10 +02:00
|
|
|
// HeaderContentDisposition is the "Content-Disposition" header.
|
2022-03-13 17:15:23 +01:00
|
|
|
HeaderContentDisposition Header = "Content-Disposition"
|
|
|
|
|
2024-10-05 12:00:10 +02:00
|
|
|
// HeaderContentID is the "Content-ID" header.
|
2022-03-14 10:29:53 +01:00
|
|
|
HeaderContentID Header = "Content-ID"
|
|
|
|
|
2024-10-05 12:00:10 +02:00
|
|
|
// HeaderContentLang is the "Content-Language" header.
|
2022-03-10 16:56:41 +01:00
|
|
|
HeaderContentLang Header = "Content-Language"
|
|
|
|
|
2024-10-05 12:00:10 +02:00
|
|
|
// HeaderContentLocation is the "Content-Location" header (RFC 2110).
|
|
|
|
// https://datatracker.ietf.org/doc/html/rfc2110#section-4.3
|
2022-03-14 16:25:24 +01:00
|
|
|
HeaderContentLocation Header = "Content-Location"
|
|
|
|
|
2024-10-05 12:00:10 +02:00
|
|
|
// HeaderContentTransferEnc is the "Content-Transfer-Encoding" header.
|
2022-03-13 17:15:23 +01:00
|
|
|
HeaderContentTransferEnc Header = "Content-Transfer-Encoding"
|
|
|
|
|
2024-10-05 12:00:10 +02:00
|
|
|
// HeaderContentType is the "Content-Type" header.
|
2022-03-10 16:56:41 +01:00
|
|
|
HeaderContentType Header = "Content-Type"
|
|
|
|
|
2024-10-05 12:00:10 +02:00
|
|
|
// HeaderDate represents the "Date" field.
|
|
|
|
// https://datatracker.ietf.org/doc/html/rfc822#section-5.1
|
2022-03-09 16:52:23 +01:00
|
|
|
HeaderDate Header = "Date"
|
|
|
|
|
2024-10-05 12:00:10 +02:00
|
|
|
// HeaderDispositionNotificationTo is the MDN header as described in RFC 8098.
|
|
|
|
// https://datatracker.ietf.org/doc/html/rfc8098#section-2.1
|
2022-09-09 11:35:45 +02:00
|
|
|
HeaderDispositionNotificationTo Header = "Disposition-Notification-To"
|
|
|
|
|
2024-10-05 12:00:10 +02:00
|
|
|
// HeaderImportance represents the "Importance" field.
|
2022-03-13 19:24:46 +01:00
|
|
|
HeaderImportance Header = "Importance"
|
|
|
|
|
2024-10-05 12:00:10 +02:00
|
|
|
// HeaderInReplyTo represents the "In-Reply-To" field.
|
2022-03-11 10:29:44 +01:00
|
|
|
HeaderInReplyTo Header = "In-Reply-To"
|
|
|
|
|
2024-10-05 12:00:10 +02:00
|
|
|
// HeaderListUnsubscribe is the "List-Unsubscribe" header field.
|
2022-03-11 10:29:44 +01:00
|
|
|
HeaderListUnsubscribe Header = "List-Unsubscribe"
|
|
|
|
|
2024-10-05 12:00:10 +02:00
|
|
|
// HeaderListUnsubscribePost is the "List-Unsubscribe-Post" header field.
|
2022-03-11 10:29:44 +01:00
|
|
|
HeaderListUnsubscribePost Header = "List-Unsubscribe-Post"
|
|
|
|
|
2024-10-05 12:00:10 +02:00
|
|
|
// HeaderMessageID represents the "Message-ID" field for message identification.
|
|
|
|
// https://datatracker.ietf.org/doc/html/rfc1036#section-2.1.5
|
2022-03-09 16:52:23 +01:00
|
|
|
HeaderMessageID Header = "Message-ID"
|
2022-03-10 16:19:51 +01:00
|
|
|
|
2024-10-05 12:00:10 +02:00
|
|
|
// HeaderMIMEVersion represents the "MIME-Version" field as per RFC 2045.
|
|
|
|
// https://datatracker.ietf.org/doc/html/rfc2045#section-4
|
2022-03-10 16:56:41 +01:00
|
|
|
HeaderMIMEVersion Header = "MIME-Version"
|
|
|
|
|
2024-10-05 12:00:10 +02:00
|
|
|
// HeaderOrganization is the "Organization" header field.
|
2022-03-14 16:25:24 +01:00
|
|
|
HeaderOrganization Header = "Organization"
|
|
|
|
|
2024-10-05 12:00:10 +02:00
|
|
|
// HeaderPrecedence is the "Precedence" header field.
|
2022-03-10 16:19:51 +01:00
|
|
|
HeaderPrecedence Header = "Precedence"
|
|
|
|
|
2024-10-05 12:00:10 +02:00
|
|
|
// HeaderPriority represents the "Priority" field.
|
2022-03-13 19:24:46 +01:00
|
|
|
HeaderPriority Header = "Priority"
|
|
|
|
|
2024-10-05 12:00:10 +02:00
|
|
|
// HeaderReferences is the "References" header field.
|
2023-10-13 15:06:54 +02:00
|
|
|
HeaderReferences Header = "References"
|
|
|
|
|
2024-10-05 12:00:10 +02:00
|
|
|
// HeaderReplyTo is the "Reply-To" header field.
|
2022-03-11 10:29:44 +01:00
|
|
|
HeaderReplyTo Header = "Reply-To"
|
|
|
|
|
2024-10-05 12:00:10 +02:00
|
|
|
// HeaderSubject is the "Subject" header field.
|
2022-03-10 16:19:51 +01:00
|
|
|
HeaderSubject Header = "Subject"
|
2022-03-13 19:24:46 +01:00
|
|
|
|
2024-10-05 12:00:10 +02:00
|
|
|
// HeaderUserAgent is the "User-Agent" header field.
|
2022-03-14 16:25:24 +01:00
|
|
|
HeaderUserAgent Header = "User-Agent"
|
|
|
|
|
2024-10-05 12:00:10 +02:00
|
|
|
// HeaderXAutoResponseSuppress is the "X-Auto-Response-Suppress" header field.
|
2024-02-08 16:45:06 +01:00
|
|
|
HeaderXAutoResponseSuppress Header = "X-Auto-Response-Suppress"
|
|
|
|
|
2024-10-05 12:00:10 +02:00
|
|
|
// HeaderXMailer is the "X-Mailer" header field.
|
2022-03-14 16:25:24 +01:00
|
|
|
HeaderXMailer Header = "X-Mailer"
|
|
|
|
|
2024-10-05 12:00:10 +02:00
|
|
|
// HeaderXMSMailPriority is the "X-MSMail-Priority" header field.
|
2022-03-13 19:24:46 +01:00
|
|
|
HeaderXMSMailPriority Header = "X-MSMail-Priority"
|
|
|
|
|
2024-10-05 12:00:10 +02:00
|
|
|
// HeaderXPriority is the "X-Priority" header field.
|
2022-03-13 19:24:46 +01:00
|
|
|
HeaderXPriority Header = "X-Priority"
|
2022-03-10 16:19:51 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2024-10-05 12:00:10 +02:00
|
|
|
// HeaderBcc is the "Blind Carbon Copy" header field.
|
2022-03-10 16:19:51 +01:00
|
|
|
HeaderBcc AddrHeader = "Bcc"
|
|
|
|
|
2024-10-05 12:00:10 +02:00
|
|
|
// HeaderCc is the "Carbon Copy" header field.
|
2022-03-10 16:19:51 +01:00
|
|
|
HeaderCc AddrHeader = "Cc"
|
|
|
|
|
2024-10-05 13:56:47 +02:00
|
|
|
// HeaderEnvelopeFrom is the envelope FROM header field.
|
|
|
|
//
|
|
|
|
// It is generally not included in the mail body but only used by the Client for the communication with the
|
|
|
|
// SMTP server. If the Msg has no "FROM" address set in the mail body, the msgWriter will try to use the
|
|
|
|
// envelope from address, if this has been set for the Msg.
|
2022-06-13 10:18:35 +02:00
|
|
|
HeaderEnvelopeFrom AddrHeader = "EnvelopeFrom"
|
|
|
|
|
2024-10-05 12:00:10 +02:00
|
|
|
// HeaderFrom is the "From" header field.
|
2022-03-10 16:19:51 +01:00
|
|
|
HeaderFrom AddrHeader = "From"
|
|
|
|
|
2024-10-05 12:00:10 +02:00
|
|
|
// HeaderTo is the "Receipient" header field.
|
2022-03-10 16:19:51 +01:00
|
|
|
HeaderTo AddrHeader = "To"
|
2022-03-09 16:52:23 +01:00
|
|
|
)
|
2022-03-13 19:24:46 +01:00
|
|
|
|
|
|
|
const (
|
2024-10-05 12:00:10 +02:00
|
|
|
// ImportanceLow indicates a low level of importance or priority in a Msg.
|
2022-03-13 19:24:46 +01:00
|
|
|
ImportanceLow Importance = iota
|
2024-10-05 12:00:10 +02:00
|
|
|
|
|
|
|
// ImportanceNormal indicates a standard level of importance or priority for a Msg.
|
2022-03-13 19:24:46 +01:00
|
|
|
ImportanceNormal
|
2024-10-05 12:00:10 +02:00
|
|
|
|
|
|
|
// ImportanceHigh indicates a high level of importance or priority in a Msg.
|
2022-03-13 19:24:46 +01:00
|
|
|
ImportanceHigh
|
2024-10-05 12:00:10 +02:00
|
|
|
|
|
|
|
// ImportanceNonUrgent indicates a non-urgent level of importance or priority in a Msg.
|
2022-03-13 19:24:46 +01:00
|
|
|
ImportanceNonUrgent
|
2024-10-05 12:00:10 +02:00
|
|
|
|
|
|
|
// ImportanceUrgent indicates an urgent level of importance or priority in a Msg.
|
2022-03-13 19:24:46 +01:00
|
|
|
ImportanceUrgent
|
|
|
|
)
|
|
|
|
|
2024-10-06 16:19:53 +02:00
|
|
|
// NumString returns a numerical string representation of the Importance level.
|
|
|
|
//
|
|
|
|
// This method maps ImportanceHigh and ImportanceUrgent to "1", while ImportanceNonUrgent and ImportanceLow
|
|
|
|
// are mapped to "0". Other values return an empty string.
|
|
|
|
//
|
|
|
|
// Returns:
|
|
|
|
// - A string representing the numerical value of the Importance level ("1" or "0"), or an empty string
|
|
|
|
// if the Importance level is unrecognized.
|
2022-03-13 19:24:46 +01:00
|
|
|
func (i Importance) NumString() string {
|
|
|
|
switch i {
|
|
|
|
case ImportanceNonUrgent:
|
|
|
|
return "0"
|
|
|
|
case ImportanceLow:
|
|
|
|
return "0"
|
|
|
|
case ImportanceHigh:
|
|
|
|
return "1"
|
|
|
|
case ImportanceUrgent:
|
|
|
|
return "1"
|
|
|
|
default:
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-06 16:19:53 +02:00
|
|
|
// XPrioString returns the X-Priority string representation of the Importance level.
|
|
|
|
//
|
|
|
|
// This method maps ImportanceHigh and ImportanceUrgent to "1", while ImportanceNonUrgent and ImportanceLow
|
|
|
|
// are mapped to "5". Other values return an empty string.
|
|
|
|
//
|
|
|
|
// Returns:
|
|
|
|
// - A string representing the X-Priority value of the Importance level ("1" or "5"), or an empty string
|
|
|
|
// if the Importance level is unrecognized.
|
2022-03-13 19:28:40 +01:00
|
|
|
func (i Importance) XPrioString() string {
|
|
|
|
switch i {
|
|
|
|
case ImportanceNonUrgent:
|
|
|
|
return "5"
|
|
|
|
case ImportanceLow:
|
|
|
|
return "5"
|
|
|
|
case ImportanceHigh:
|
|
|
|
return "1"
|
|
|
|
case ImportanceUrgent:
|
|
|
|
return "1"
|
|
|
|
default:
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-06 16:19:53 +02:00
|
|
|
// String satisfies the fmt.Stringer interface for the Importance type and returns the string
|
|
|
|
// representation of the Importance level.
|
|
|
|
//
|
|
|
|
// This method provides a human-readable string for each Importance level.
|
|
|
|
//
|
|
|
|
// Returns:
|
|
|
|
// - A string representing the Importance level ("non-urgent", "low", "high", or "urgent"), or an empty
|
|
|
|
// string if the Importance level is unrecognized.
|
2022-03-13 19:24:46 +01:00
|
|
|
func (i Importance) String() string {
|
|
|
|
switch i {
|
|
|
|
case ImportanceNonUrgent:
|
|
|
|
return "non-urgent"
|
|
|
|
case ImportanceLow:
|
|
|
|
return "low"
|
|
|
|
case ImportanceHigh:
|
|
|
|
return "high"
|
|
|
|
case ImportanceUrgent:
|
|
|
|
return "urgent"
|
|
|
|
default:
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
2022-03-18 10:35:51 +01:00
|
|
|
|
2024-10-06 16:19:53 +02:00
|
|
|
// String satisfies the fmt.Stringer interface for the Header type and returns the string
|
|
|
|
// representation of the Header.
|
|
|
|
//
|
|
|
|
// Returns:
|
|
|
|
// - A string representing the Header.
|
2022-03-18 10:35:51 +01:00
|
|
|
func (h Header) String() string {
|
|
|
|
return string(h)
|
|
|
|
}
|
|
|
|
|
2024-10-06 16:19:53 +02:00
|
|
|
// String satisfies the fmt.Stringer interface for the AddrHeader type and returns the string
|
|
|
|
// representation of the AddrHeader.
|
|
|
|
//
|
|
|
|
// Returns:
|
|
|
|
// - A string representing the AddrHeader.
|
2022-03-18 10:35:51 +01:00
|
|
|
func (a AddrHeader) String() string {
|
|
|
|
return string(a)
|
|
|
|
}
|