Fix create header maps in case SetHeader or SetAddrHeader is called on an empty Msg type

This commit is contained in:
Winni Neessen 2022-10-20 18:06:26 +02:00
parent 5faa6dfbd6
commit 183fb347d6
Signed by: wneessen
GPG key ID: 385AC9889632126E

6
msg.go
View file

@ -181,6 +181,9 @@ func (m *Msg) Charset() string {
// SetHeader sets a generic header field of the Msg
func (m *Msg) SetHeader(h Header, v ...string) {
if m.genHeader == nil {
m.genHeader = make(map[Header][]string)
}
for i, hv := range v {
v[i] = m.encodeString(hv)
}
@ -189,6 +192,9 @@ func (m *Msg) SetHeader(h Header, v ...string) {
// SetAddrHeader sets an address related header field of the Msg
func (m *Msg) SetAddrHeader(h AddrHeader, v ...string) error {
if m.addrHeader == nil {
m.addrHeader = make(map[AddrHeader][]*mail.Address)
}
var al []*mail.Address
for _, av := range v {
a, err := mail.ParseAddress(av)