mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-22 05:40:50 +01:00
Initialize address header map and enforce single 'From' address.
This commit ensures that the address header map is properly initialized before assigning addresses to it. Additionally, it enforces the rule that only a single 'From' address is allowed, preventing multiple addresses from being set for the 'From' header. These misses were found while working on the enhanced testing suite
This commit is contained in:
parent
7d352bc58e
commit
08fe44c051
1 changed files with 11 additions and 1 deletions
12
msg.go
12
msg.go
|
@ -583,6 +583,9 @@ func (m *Msg) SetAddrHeader(header AddrHeader, values ...string) error {
|
|||
// References:
|
||||
// - https://datatracker.ietf.org/doc/html/rfc5322#section-3.4
|
||||
func (m *Msg) SetAddrHeaderIgnoreInvalid(header AddrHeader, values ...string) {
|
||||
if m.addrHeader == nil {
|
||||
m.addrHeader = make(map[AddrHeader][]*mail.Address)
|
||||
}
|
||||
var addresses []*mail.Address
|
||||
for _, addrVal := range values {
|
||||
address, err := mail.ParseAddress(m.encodeString(addrVal))
|
||||
|
@ -591,7 +594,14 @@ func (m *Msg) SetAddrHeaderIgnoreInvalid(header AddrHeader, values ...string) {
|
|||
}
|
||||
addresses = append(addresses, address)
|
||||
}
|
||||
m.addrHeader[header] = addresses
|
||||
switch header {
|
||||
case HeaderFrom:
|
||||
if len(addresses) > 0 {
|
||||
m.addrHeader[header] = []*mail.Address{addresses[0]}
|
||||
}
|
||||
default:
|
||||
m.addrHeader[header] = addresses
|
||||
}
|
||||
}
|
||||
|
||||
// EnvelopeFrom sets the envelope from address for the Msg.
|
||||
|
|
Loading…
Reference in a new issue