Fix in address handling and more header related methods

This commit is contained in:
Winni Neessen 2022-03-14 16:25:24 +01:00
parent 066b421725
commit 557a161a12
Signed by: wneessen
GPG key ID: 385AC9889632126E
2 changed files with 24 additions and 1 deletions

View file

@ -20,6 +20,9 @@ const (
// HeaderContentLang is the "Content-Language" header
HeaderContentLang Header = "Content-Language"
// HeaderContentLocation is the "Content-Location" header (RFC 2110)
HeaderContentLocation Header = "Content-Location"
// HeaderContentTransferEnc is the "Content-Transfer-Encoding" header
HeaderContentTransferEnc Header = "Content-Transfer-Encoding"
@ -50,6 +53,9 @@ const (
// See: https://datatracker.ietf.org/doc/html/rfc2045#section-4
HeaderMIMEVersion Header = "MIME-Version"
// HeaderOrganization is the "Organization" header field
HeaderOrganization Header = "Organization"
// HeaderPrecedence is the "Precedence" header field
HeaderPrecedence Header = "Precedence"
@ -62,6 +68,12 @@ const (
// HeaderSubject is the "Subject" header field
HeaderSubject Header = "Subject"
// HeaderUserAgent is the "User-Agent" header field
HeaderUserAgent Header = "User-Agent"
// HeaderXMailer is the "X-Mailer" header field
HeaderXMailer Header = "X-Mailer"
// HeaderXMSMailPriority is the "X-MSMail-Priority" header field
HeaderXMSMailPriority Header = "X-MSMail-Priority"

13
msg.go
View file

@ -151,7 +151,7 @@ func (m *Msg) SetHeader(h Header, v ...string) {
func (m *Msg) SetAddrHeader(h AddrHeader, v ...string) error {
var al []*mail.Address
for _, av := range v {
a, err := mail.ParseAddress(m.encodeString(av))
a, err := mail.ParseAddress(av)
if err != nil {
return fmt.Errorf("failed to parse mail address header %q: %w", av, err)
}
@ -337,6 +337,17 @@ func (m *Msg) SetImportance(i Importance) {
m.SetHeader(HeaderXMSMailPriority, i.NumString())
}
// SetOrganization sets the provided string as Organization header for the Msg
func (m *Msg) SetOrganization(o string) {
m.SetHeader(HeaderOrganization, o)
}
// SetUserAgent sets the User-Agent/X-Mailer header for the Msg
func (m *Msg) SetUserAgent(a string) {
m.SetHeader(HeaderUserAgent, a)
m.SetHeader(HeaderXMailer, a)
}
// GetSender returns the currently set FROM address. If f is true, it will return the full
// address string including the address name, if set
func (m *Msg) GetSender(ff bool) (string, error) {