Refactor RequestMDNAddTo

Simplify the address handling for the "Disposition-Notification-To" header in msg.go. The code now directly reassigns the previously fetched addresses and ensures appending the new address effectively. This improves code readability and correctness in updating the header.
This commit is contained in:
Winni Neessen 2024-10-26 22:13:37 +02:00
parent 4f97cd8261
commit 4fe9022815
Signed by: wneessen
GPG key ID: 385AC9889632126E

8
msg.go
View file

@ -1237,11 +1237,11 @@ func (m *Msg) RequestMDNAddTo(rcpt string) error {
return fmt.Errorf(errParseMailAddr, rcpt, err) return fmt.Errorf(errParseMailAddr, rcpt, err)
} }
var addresses []string var addresses []string
addresses = append(addresses, m.genHeader[HeaderDispositionNotificationTo]...) if current, ok := m.genHeader[HeaderDispositionNotificationTo]; ok {
addresses = append(addresses, address.String()) addresses = current
if _, ok := m.genHeader[HeaderDispositionNotificationTo]; ok {
m.genHeader[HeaderDispositionNotificationTo] = addresses
} }
addresses = append(addresses, address.String())
m.genHeader[HeaderDispositionNotificationTo] = addresses
return nil return nil
} }