From 557a161a12f1f7b2b5e2e6e7056b4140455ea6f0 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Mon, 14 Mar 2022 16:25:24 +0100 Subject: [PATCH] Fix in address handling and more header related methods --- header.go | 12 ++++++++++++ msg.go | 13 ++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/header.go b/header.go index c97f6e9..5975000 100644 --- a/header.go +++ b/header.go @@ -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" diff --git a/msg.go b/msg.go index 1394f7e..b5fcfa5 100644 --- a/msg.go +++ b/msg.go @@ -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) {