Skip to content

Commit 80d1896

Browse files
committed
Refactored address handling for improved consistency and formatting
- Replaced repetitive address string manipulation with `mailAddressStringWithoutName` helper function. - Updated sender and recipient parsing logic to ensure proper handling of addresses without names. - Improved clarity and maintainability by standardizing address formatting logic. This fixes a regression introduced in v0.7.1 (see #497)
1 parent 42e92cf commit 80d1896

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

msg.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,9 +1496,9 @@ func (m *Msg) GetSender(useFullAddr bool) (string, error) {
14961496
}
14971497
}
14981498

1499-
addr := from[0]
1499+
addr := *from[0]
15001500
if !useFullAddr {
1501-
addr.Name = ""
1501+
return mailAddressStringWithoutName(addr), nil
15021502
}
15031503
return addr.String(), nil
15041504
}
@@ -1524,8 +1524,7 @@ func (m *Msg) GetRecipients() ([]string, error) {
15241524
continue
15251525
}
15261526
for _, r := range addresses {
1527-
r.Name = ""
1528-
rcpts = append(rcpts, r.String())
1527+
rcpts = append(rcpts, mailAddressStringWithoutName(*r))
15291528
}
15301529
}
15311530
if len(rcpts) <= 0 {
@@ -3327,3 +3326,8 @@ func writeFuncFromBuffer(buffer *bytes.Buffer) func(io.Writer) (int64, error) {
33273326
}
33283327
return writeFunc
33293328
}
3329+
3330+
func mailAddressStringWithoutName(addr mail.Address) string {
3331+
addr.Name = ""
3332+
return addr.String()
3333+
}

0 commit comments

Comments
 (0)