Skip to content

Commit

Permalink
Fix in address handling and more header related methods
Browse files Browse the repository at this point in the history
  • Loading branch information
wneessen committed Mar 14, 2022
1 parent 066b421 commit 557a161
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
12 changes: 12 additions & 0 deletions header.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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"

Expand All @@ -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"

Expand Down
13 changes: 12 additions & 1 deletion msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 557a161

Please sign in to comment.