validateFromAddr parses the "from" address and returns two values: 1. envelopeFrom: The bare email address for use in the SMTP MAIL FROM command. 2. headerFrom: The original address (possibly including display name) for use in the email header. This separation is necessary because SMTP envelope add
(from string)
| 494 | // and RCPT TO commands) must be bare email addresses, while email headers can |
| 495 | // include display names (e.g., "John Doe <john@example.com>"). |
| 496 | func (*SMTPHandler) validateFromAddr(from string) (envelopeFrom, headerFrom string, err error) { |
| 497 | addrs, err := mail.ParseAddressList(from) |
| 498 | if err != nil { |
| 499 | return "", "", xerrors.Errorf("parse 'from' address: %w", err) |
| 500 | } |
| 501 | if len(addrs) != 1 { |
| 502 | return "", "", ErrValidationNoFromAddress |
| 503 | } |
| 504 | // Use the parsed email address for the SMTP envelope (MAIL FROM command), |
| 505 | // but preserve the original string for the email header (which may include |
| 506 | // a display name). |
| 507 | return addrs[0].Address, from, nil |
| 508 | } |
| 509 | |
| 510 | func (s *SMTPHandler) validateToAddrs(to string) ([]string, error) { |
| 511 | addrs, err := mail.ParseAddressList(to) |