Documentation ¶
Index ¶
- Variables
- func ExtractBodyURLs(msg *Message) strutil.StringSet
- func HTMLToPlaintext(html []byte, delimiter string) (string, error)
- func IsExtraHeader(key string) bool
- func IsParsedHeader(key string) bool
- func NormalizeAddressList(list string) (normalized []string, err error)
- func ParseAddress(addr string) (mailAddress *mail.Address, err error)
- func ParseAddressList(list string) (addrs []*mail.Address, err error)
- func ProviderDomains() map[string]struct{}
- type Address
- func (a Address) AddressPart() (Address, error)
- func (a Address) AddressPartString() (string, error)
- func (a Address) AsList() AddressList
- func (a Address) DomainPart() string
- func (a Address) LocalPart() (string, error)
- func (a Address) NamePart() (string, error)
- func (a Address) Normalized() (Address, error)
- func (a Address) Nullable() NullableAddress
- func (a Address) Parse() (*mail.Address, error)
- func (a Address) Validate() error
- type AddressList
- func (l AddressList) Append(addrs ...Address) AddressList
- func (l AddressList) Normalized() (AddressList, error)
- func (l AddressList) Nullable() NullableAddressList
- func (l AddressList) Parse() ([]*mail.Address, error)
- func (l *AddressList) Scan(value any) error
- func (l AddressList) Split() ([]Address, error)
- func (l AddressList) UniqueAddressParts() (AddressSet, error)
- func (l AddressList) Validate() error
- type AddressSet
- func (set *AddressSet) Add(addr Address)
- func (set *AddressSet) AddAddressPart(addr Address) error
- func (set *AddressSet) AddNormalized(addr Address) error
- func (set *AddressSet) AddSet(other AddressSet)
- func (set AddressSet) AddressList() AddressList
- func (set AddressSet) Clear()
- func (set AddressSet) Clone() AddressSet
- func (set AddressSet) Contains(addr Address) bool
- func (set AddressSet) Delete(val Address)
- func (set AddressSet) DeleteSet(other AddressSet)
- func (set AddressSet) DeleteSlice(vals []Address)
- func (set AddressSet) GetOne() Address
- func (set AddressSet) IsEmpty() bool
- func (set AddressSet) IsNull() bool
- func (set AddressSet) Len() int
- func (set AddressSet) Normalized() (AddressSet, error)
- func (set *AddressSet) Scan(value any) error
- func (set AddressSet) Sorted() []Address
- func (set AddressSet) String() string
- func (set AddressSet) Strings() []string
- func (set AddressSet) Validate() error
- func (set AddressSet) Value() (driver.Value, error)
- type AllRule
- type AnyRule
- type Attachment
- type BoolRule
- type Header
- type Message
- func NewMessage(from Address, to AddressList, subject, body string, ...) *Message
- func ParseMIMEMessage(reader io.Reader) (msg *Message, err error)
- func ParseMIMEMessageBytes(msgBytes []byte) (msg *Message, err error)
- func ParseMIMEMessageFile(file fs.FileReader) (msg *Message, err error)
- func ParseMessage(data []byte) (msg *Message, err error)
- func ParseMessageFile(ctx context.Context, file fs.FileReader) (msg *Message, err error)
- func ParseTNEFMessageBytes(messageBytes []byte) (msg *Message, err error)
- func ParseTNEFMessageFile(ctx context.Context, file fs.FileReader) (msg *Message, err error)
- func (msg *Message) AddAttachment(partID, filename string, content []byte)
- func (msg *Message) AddAttachmentReadFile(ctx context.Context, partID string, file fs.FileReader) error
- func (msg *Message) AutoResponseSuppress() bool
- func (msg *Message) BuildRawMessage() (raw []byte, err error)
- func (msg *Message) FeedbackID() string
- func (msg *Message) IsAutoSubmitted() bool
- func (msg *Message) ListID() string
- func (msg *Message) NewReplyMessage(from Address, replyText, replyHTML string, keepAttachments bool, ...) (re *Message, err error)
- func (msg *Message) Recipients() []string
- func (msg *Message) ReferencesMessageIDs() []string
- func (msg *Message) ReplyToAddress() Address
- func (msg *Message) String() string
- type NullableAddress
- func (n NullableAddress) AddressPart() (NullableAddress, error)
- func (n NullableAddress) AsList() NullableAddressList
- func (n NullableAddress) DomainPart() string
- func (n NullableAddress) Get() Address
- func (n NullableAddress) GetOr(defaultAddress Address) Address
- func (n NullableAddress) IsNotNull() bool
- func (n NullableAddress) IsNull() bool
- func (n NullableAddress) LocalPart() (string, error)
- func (n NullableAddress) MarshalJSON() ([]byte, error)
- func (n NullableAddress) NamePart() (string, error)
- func (n NullableAddress) Normalized() (NullableAddress, error)
- func (n NullableAddress) Parse() (*mail.Address, error)
- func (n *NullableAddress) Scan(value any) error
- func (n *NullableAddress) Set(s Address)
- func (n *NullableAddress) SetNull()
- func (n NullableAddress) StringOr(nullString string) string
- func (n *NullableAddress) UnmarshalJSON(data []byte) error
- func (n *NullableAddress) UnmarshalText(text []byte) error
- func (n NullableAddress) Validate() error
- func (n NullableAddress) Value() (driver.Value, error)
- type NullableAddressList
- func (n NullableAddressList) Append(addrs ...Address) NullableAddressList
- func (n NullableAddressList) Get() string
- func (n NullableAddressList) IsNotNull() bool
- func (n NullableAddressList) IsNull() bool
- func (n NullableAddressList) MarshalJSON() ([]byte, error)
- func (n NullableAddressList) Normalized() (NullableAddressList, error)
- func (n NullableAddressList) Parse() ([]*mail.Address, error)
- func (n *NullableAddressList) Scan(value any) error
- func (n *NullableAddressList) Set(s string)
- func (n *NullableAddressList) SetNull()
- func (n NullableAddressList) Split() ([]Address, error)
- func (n NullableAddressList) StringOr(nullString string) string
- func (n *NullableAddressList) UnmarshalJSON(data []byte) error
- func (n *NullableAddressList) UnmarshalText(text []byte) error
- func (n NullableAddressList) Validate() error
- func (n NullableAddressList) Value() (driver.Value, error)
- type ReplyTemplateData
- type Rule
- type RuleFunc
Constants ¶
This section is empty.
Variables ¶
var ( // AddressRegexp is a compiled regular expression for an email address without name part AddressRegexp = regexp.MustCompile(addressRegex) )
Functions ¶
func ExtractBodyURLs ¶
ExtractBodyURLs returns all HTTP URLs from the message body
func HTMLToPlaintext ¶
HTMLToPlaintext converts HTML to plaintext by concaternating the content of text nodes with the passed delimiter between them. Whitespace is trimmed from the text nodes and nodes consisting only of whitespace are ignored. In case of an HTML parsing error all parsed text up until the error will be returned. Empty html will result in empty plaintext.
func IsExtraHeader ¶
func IsParsedHeader ¶
func NormalizeAddressList ¶
NormalizeAddressList parses an email address list less strict than the standard net/mail.ParseAddressList function fixing malformed addresses and lower cases the address part. Duplicates with the same normalized address part will be removed from the result. NormalizeAddressList returns an error if list does not contain at least one address.
func ParseAddress ¶
ParseAddress parses an email address less strict than the standard net/mail.ParseAddress function fixing malformed addresses and lower cases the address part. If the name part is identical with the address part then it will not be returned as name.
func ParseAddressList ¶
ParseAddressList parses an email address list less strict than the standard net/mail.ParseAddressList function fixing malformed addresses and lower cases the address part. ParseAddressList returns an error if list does not contain at least one address.
func ProviderDomains ¶
func ProviderDomains() map[string]struct{}
ProviderDomains returns a set of known email provider domain names.
Types ¶
type Address ¶
type Address string
Address is a string containing a non-normalized email-address with an optional name part before the mandatory address part.
func AddressFrom ¶
func FindAllAddresses ¶
FindAllAddresses uses the AddressRegexp to find all email addresses without name part in the passed text. The addresses are not normalized and returned in the order they were found in the text.
func NormalizedAddress ¶
NormalizedAddress parses an email address less strict than the standard net/mail.ParseAddress function fixing malformed addresses and lower cases the address part.
func UniqueNormalizedAddressSlice ¶
UniqueNormalizedAddressSlice returns the passed Address slice modified to only contain the sorted unique normalized address parts (address without name part) of the passed addresses.
func (Address) AddressPart ¶
AddressPart returns the normalized lower case address part from an email address with an optional name part.
func (Address) AddressPartString ¶
AddressPartString returns the normalized lower case address part from an email address with an optional name part.
func (Address) AsList ¶
func (a Address) AsList() AddressList
func (Address) DomainPart ¶
DomainPart returns the part of the address after the @ character or an empty string in case it can't be parsed.
func (Address) LocalPart ¶
LocalPart returns the sub-part of the address part before the @ character
func (Address) Normalized ¶
Normalized parses an email address less strict than the standard net/mail.ParseAddress function fixing malformed addresses and lower cases the address part.
func (Address) Nullable ¶
func (a Address) Nullable() NullableAddress
type AddressList ¶
type AddressList string
AddressList is a comma separated list of at least one email address.
Use NullableAddressList for a list that can contain zero addresses.
func AddressListJoin ¶
func AddressListJoin(addrs ...Address) AddressList
func AddressListJoinStrings ¶
func AddressListJoinStrings(addrs ...string) AddressList
func (AddressList) Append ¶
func (l AddressList) Append(addrs ...Address) AddressList
func (AddressList) Normalized ¶
func (l AddressList) Normalized() (AddressList, error)
func (AddressList) Nullable ¶
func (l AddressList) Nullable() NullableAddressList
func (*AddressList) Scan ¶
func (l *AddressList) Scan(value any) error
Scan implements the database/sql.Scanner interface. Supports scanning SQL strings and string arrays.
func (AddressList) Split ¶
func (l AddressList) Split() ([]Address, error)
func (AddressList) UniqueAddressParts ¶
func (l AddressList) UniqueAddressParts() (AddressSet, error)
func (AddressList) Validate ¶
func (l AddressList) Validate() error
type AddressSet ¶
type AddressSet map[Address]struct{}
AddressSet is a set of unique email addresses
func MakeAddressSet ¶
func MakeAddressSet(addrs ...Address) AddressSet
func NormalizedAddressPartSet ¶
func NormalizedAddressPartSet(addrs ...Address) (AddressSet, error)
func NormalizedAddressSet ¶
func NormalizedAddressSet(addrs ...Address) (AddressSet, error)
func (*AddressSet) Add ¶
func (set *AddressSet) Add(addr Address)
func (*AddressSet) AddAddressPart ¶
func (set *AddressSet) AddAddressPart(addr Address) error
func (*AddressSet) AddNormalized ¶
func (set *AddressSet) AddNormalized(addr Address) error
func (*AddressSet) AddSet ¶
func (set *AddressSet) AddSet(other AddressSet)
func (AddressSet) AddressList ¶
func (set AddressSet) AddressList() AddressList
func (AddressSet) Clear ¶
func (set AddressSet) Clear()
func (AddressSet) Clone ¶
func (set AddressSet) Clone() AddressSet
func (AddressSet) Contains ¶
func (set AddressSet) Contains(addr Address) bool
func (AddressSet) Delete ¶
func (set AddressSet) Delete(val Address)
func (AddressSet) DeleteSet ¶
func (set AddressSet) DeleteSet(other AddressSet)
func (AddressSet) DeleteSlice ¶
func (set AddressSet) DeleteSlice(vals []Address)
func (AddressSet) GetOne ¶
func (set AddressSet) GetOne() Address
GetOne returns one address of the set or an empty string if the set is empty.
func (AddressSet) IsEmpty ¶
func (set AddressSet) IsEmpty() bool
IsEmpty returns true if the set is empty or nil.
func (AddressSet) IsNull ¶
func (set AddressSet) IsNull() bool
IsNull implements the nullable.Nullable interface by returning true if the set is nil.
func (AddressSet) Len ¶
func (set AddressSet) Len() int
Len returns the number of values in the set.
func (AddressSet) Normalized ¶
func (set AddressSet) Normalized() (AddressSet, error)
func (*AddressSet) Scan ¶
func (set *AddressSet) Scan(value any) error
Scan implements the database/sql.Scanner interface. Supports scanning SQL strings and string arrays.
func (AddressSet) Sorted ¶
func (set AddressSet) Sorted() []Address
func (AddressSet) String ¶
func (set AddressSet) String() string
func (AddressSet) Strings ¶
func (set AddressSet) Strings() []string
func (AddressSet) Validate ¶
func (set AddressSet) Validate() error
Validate returns the first error encountered validating the addresses of the set.
type Attachment ¶
type Attachment struct { PartID string `json:"partID,omitempty"` ContentID string `json:"contentID,omitempty"` ContentType string `json:"contentType,omitempty"` Inline bool `json:"inline,omitempty"` fs.MemFile }
Attachment of an Email. Attachment implements fs.FileReader
func NewAttachment ¶
func NewAttachment(partID, filename string, content []byte) *Attachment
func NewAttachmentReadFile ¶
func NewAttachmentReadFile(ctx context.Context, partID string, file fs.FileReader) (*Attachment, error)
func (*Attachment) String ¶
func (a *Attachment) String() string
type Header ¶
type Header = textproto.MIMEHeader
type Message ¶
type Message struct { // ProviderID is the optional ID of the message // at the email provider like GMail that might be // different from the RFC 822 Message-ID. ProviderID nullable.TrimmedString `json:"providerID,omitempty"` // InReplyToProviderID is the ProviderID of the message // that this message is a reply to. InReplyToProviderID nullable.TrimmedString `json:"inReplyToProviderID,omitempty"` // ProviderLabels are optional labels from the email provider // like GMail that are not encoded in the message itself. ProviderLabels []string `json:"providerLabels,omitempty"` // MessageID is the "Message-ID" header according to RFC 822/2822/5322. // Find in Gmail via filter: rfc822msgid:MessageID MessageID nullable.TrimmedString `json:"messageID,omitempty"` // In-Reply-To header InReplyTo nullable.TrimmedString `json:"inReplyTo,omitempty"` // References header References nullable.TrimmedString `json:"references,omitempty"` // Date header Date *time.Time `json:"date,omitempty"` From Address `json:"from,omitempty"` ReplyTo NullableAddress `json:"replyTo,omitempty"` To AddressList `json:"to,omitempty"` DeliveredTo NullableAddress `json:"deliveredTo,omitempty"` Cc NullableAddressList `json:"cc,omitempty"` Bcc NullableAddressList `json:"bcc,omitempty"` // ExtraHeader can be used for additional header data // not covered by the other fields of the struct. ExtraHeader Header `json:"extraHeader,omitempty"` Subject string `json:"subject,omitempty"` // Body is the plaintext body of the email. Body string `json:"body,omitempty"` // BodyHTML returns the HTML body if available. BodyHTML nullable.TrimmedString `json:"bodyHTML,omitempty"` Attachments []*Attachment `json:"attachments,omitempty"` }
func NewMessage ¶
func NewMessage(from Address, to AddressList, subject, body string, bodyHTML nullable.TrimmedString) *Message
NewMessage returns a new message using the passed from, to, subject, body, and bodyHTML arguments.
func ParseMIMEMessageBytes ¶
func ParseMIMEMessageFile ¶
func ParseMessage ¶
func ParseMessageFile ¶
func ParseTNEFMessageBytes ¶
func ParseTNEFMessageFile ¶
func (*Message) AddAttachment ¶
func (*Message) AddAttachmentReadFile ¶
func (*Message) AutoResponseSuppress ¶
Returns if the X-Auto-Response-Suppress header contains any of the values "DR", "AutoReply", or "All". See https://docs.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-oxcmail/ced68690-498a-4567-9d14-5c01f974d8b1
func (*Message) BuildRawMessage ¶
func (*Message) FeedbackID ¶
FeedbackID returns the value of the "Feedback-Id" header or an empty string if not available.
func (*Message) IsAutoSubmitted ¶
Returns if the "Auto-Submitted" header is set and has a different value than "no". See RFC 3834: https://datatracker.ietf.org/doc/html/rfc3834
func (*Message) ListID ¶
ListID returns the value of the "List-Id" header or an empty string if not available.
func (*Message) NewReplyMessage ¶
func (msg *Message) NewReplyMessage(from Address, replyText, replyHTML string, keepAttachments bool, textTempl, htmlTempl string) (re *Message, err error)
NewReplyMessage creates a reply based on an existing message. The textTempl and htmlTempl templates will called with a ReplyTemplateData struct instance as context and are responsible to render the passed replyText and replyHTML together with a quotation of the original message. The passed replyText and replyHTML are not interpreted as templates.
func (*Message) Recipients ¶
Recipients returns the valid, normalized, name stripped, deduplicated addresses from the To, Cc, and Bcc fields.
func (*Message) ReferencesMessageIDs ¶
ReferencesMessageIDs returns the message IDs listed in the References header.
func (*Message) ReplyToAddress ¶
ReplyToAddress returns the ReplyTo address if available, else the From address.
type NullableAddress ¶
type NullableAddress string
NullableAddress is a string containing a non-normalized email-address with an optional name part before the mandatory address part. An empty string represents the SQL/JSON null value.
func NormalizedNullableAddress ¶
func NormalizedNullableAddress(addr string) (normalized NullableAddress, err error)
NormalizedNullableAddress parses an email address less strict than the standard net/mail.ParseAddress function fixing malformed addresses and lower cases the address part. An empty string is interpreted as valid NULL address.
func NullableAddressFrom ¶
func NullableAddressFrom(a *mail.Address) NullableAddress
func (NullableAddress) AddressPart ¶
func (n NullableAddress) AddressPart() (NullableAddress, error)
AddressPart returns the normalized lower case address part of an email address that may also contain a name part.
func (NullableAddress) AsList ¶
func (n NullableAddress) AsList() NullableAddressList
func (NullableAddress) DomainPart ¶
func (n NullableAddress) DomainPart() string
DomainPart returns the part of the address after the @ character or an empty string in case of a null address.
func (NullableAddress) Get ¶
func (n NullableAddress) Get() Address
Get returns the non nullable Address or panics if the NullableAddress is null. Note: check with IsNull before using Get!
func (NullableAddress) GetOr ¶
func (n NullableAddress) GetOr(defaultAddress Address) Address
GetOr returns the non nullable Address value or the passed defaultAddress if the NullableAddress is null.
func (NullableAddress) IsNotNull ¶
func (n NullableAddress) IsNotNull() bool
IsNotNull returns true if the string n is not empty.
func (NullableAddress) IsNull ¶
func (n NullableAddress) IsNull() bool
IsNull returns true if the string n is empty.
func (NullableAddress) LocalPart ¶
func (n NullableAddress) LocalPart() (string, error)
LocalPart returns the sub-part of the address part before the @ character or an empty string in case of a null address.
func (NullableAddress) MarshalJSON ¶
func (n NullableAddress) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (NullableAddress) NamePart ¶
func (n NullableAddress) NamePart() (string, error)
func (NullableAddress) Normalized ¶
func (n NullableAddress) Normalized() (NullableAddress, error)
Normalized parses an email address less strict than the standard net/mail.ParseAddress function fixing malformed addresses and lower cases the address part. An empty string is interpreted as valid NULL address.
func (*NullableAddress) Scan ¶
func (n *NullableAddress) Scan(value any) error
Scan implements the database/sql.Scanner interface.
func (*NullableAddress) Set ¶
func (n *NullableAddress) Set(s Address)
Set the passed Address as NullableAddress. Passing an empty string will be interpreted as setting NULL.
func (*NullableAddress) SetNull ¶
func (n *NullableAddress) SetNull()
SetNull sets the string to its null value
func (NullableAddress) StringOr ¶
func (n NullableAddress) StringOr(nullString string) string
StringOr returns the string value of n or the passed nullString if n.IsNull()
func (*NullableAddress) UnmarshalJSON ¶
func (n *NullableAddress) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface returning the JSON null value for and empty/NULL address.
func (*NullableAddress) UnmarshalText ¶
func (n *NullableAddress) UnmarshalText(text []byte) error
UnmarshalText implements encoding.TextUnmarshaler
func (NullableAddress) Validate ¶
func (n NullableAddress) Validate() error
type NullableAddressList ¶
type NullableAddressList string
NullableAddressList is a comma separated list of email addresses. The empty string default value represents an empty list and maps to SQL NULL and JSON null.
func NullableAddressListJoin ¶
func NullableAddressListJoin(addrs ...Address) NullableAddressList
func NullableAddressListJoinStrings ¶
func NullableAddressListJoinStrings(addrs ...string) NullableAddressList
func (NullableAddressList) Append ¶
func (n NullableAddressList) Append(addrs ...Address) NullableAddressList
func (NullableAddressList) Get ¶
func (n NullableAddressList) Get() string
Get returns the non nullable string value or panics if the NullableAddressList is null. Note: check with IsNull before using Get!
func (NullableAddressList) IsNotNull ¶
func (n NullableAddressList) IsNotNull() bool
IsNotNull returns true if the string n is not empty.
func (NullableAddressList) IsNull ¶
func (n NullableAddressList) IsNull() bool
IsNull returns true if the string n is empty.
func (NullableAddressList) MarshalJSON ¶
func (n NullableAddressList) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (NullableAddressList) Normalized ¶
func (n NullableAddressList) Normalized() (NullableAddressList, error)
func (*NullableAddressList) Scan ¶
func (n *NullableAddressList) Scan(value any) error
Scan implements the database/sql.Scanner interface. Supports scanning SQL strings and string arrays.
func (*NullableAddressList) Set ¶
func (n *NullableAddressList) Set(s string)
Set the passed string as NullableAddressList. Passing an empty string will be interpreted as setting NULL.
func (*NullableAddressList) SetNull ¶
func (n *NullableAddressList) SetNull()
SetNull sets the string to its null value
func (NullableAddressList) Split ¶
func (n NullableAddressList) Split() ([]Address, error)
func (NullableAddressList) StringOr ¶
func (n NullableAddressList) StringOr(nullString string) string
StringOr returns the string value of n or the passed nullString if n.IsNull()
func (*NullableAddressList) UnmarshalJSON ¶
func (n *NullableAddressList) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface returning the JSON null value for and empty/NULL address list.
func (*NullableAddressList) UnmarshalText ¶
func (n *NullableAddressList) UnmarshalText(text []byte) error
UnmarshalText implements encoding.TextUnmarshaler
func (NullableAddressList) Validate ¶
func (n NullableAddressList) Validate() error