MCPcopy Index your code
hub / github.com/coder/coder / validateFromAddr

Method validateFromAddr

coderd/notifications/dispatch/smtp.go:496–508  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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>").
496func (*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
510func (s *SMTPHandler) validateToAddrs(to string) ([]string, error) {
511 addrs, err := mail.ParseAddressList(to)

Callers 2

dispatchMethod · 0.95
TestValidateFromAddrFunction · 0.95

Calls 1

ErrorfMethod · 0.45

Tested by 1

TestValidateFromAddrFunction · 0.76