use shorter smtp.NewAddress() instead of smtp.Address{...}

This commit is contained in:
Mechiel Lukkien 2024-05-09 21:26:22 +02:00
parent 1179d9d80a
commit ebb8ad06b5
No known key found for this signature in database
9 changed files with 10 additions and 10 deletions

View file

@ -779,7 +779,7 @@ func sendReportDomain(ctx context.Context, log mlog.Log, resolver dns.Resolver,
// DKIM keys, so we can DKIM-sign our reports. SPF should pass anyway. // DKIM keys, so we can DKIM-sign our reports. SPF should pass anyway.
// A single report can contain deliveries from a single policy domain // A single report can contain deliveries from a single policy domain
// to multiple of our configured domains. // to multiple of our configured domains.
from := smtp.Address{Localpart: "postmaster", Domain: mox.Conf.Static.HostnameDomain} from := smtp.NewAddress("postmaster", mox.Conf.Static.HostnameDomain)
// Subject follows the form in RFC. ../rfc/7489:1871 // Subject follows the form in RFC. ../rfc/7489:1871
subject := fmt.Sprintf("Report Domain: %s Submitter: %s Report-ID: <%s>", dom.ASCII, mox.Conf.Static.HostnameDomain.ASCII, report.ReportMetadata.ReportID) subject := fmt.Sprintf("Report Domain: %s Submitter: %s Report-ID: <%s>", dom.ASCII, mox.Conf.Static.HostnameDomain.ASCII, report.ReportMetadata.ReportID)

View file

@ -107,7 +107,7 @@ func ExampleComposer() {
}() }()
// Add an address header. // Add an address header.
xc.HeaderAddrs("From", []message.NameAddress{{DisplayName: "Charlie", Address: smtp.Address{Localpart: "root", Domain: dns.Domain{ASCII: "localhost"}}}}) xc.HeaderAddrs("From", []message.NameAddress{{DisplayName: "Charlie", Address: smtp.NewAddress("root", dns.Domain{ASCII: "localhost"})}})
// Add subject header, with encoding // Add subject header, with encoding
xc.Subject("hi ☺") xc.Subject("hi ☺")

View file

@ -51,6 +51,6 @@ func From(elog *slog.Logger, strict bool, r io.ReaderAt, p *Part) (raddr smtp.Ad
if err != nil { if err != nil {
return raddr, nil, nil, fmt.Errorf("parsing localpart in from address: %v", err) return raddr, nil, nil, fmt.Errorf("parsing localpart in from address: %v", err)
} }
addr := smtp.Address{Localpart: lp, Domain: d} addr := smtp.NewAddress(lp, d)
return addr, p.Envelope, textproto.MIMEHeader(header), nil return addr, p.Envelope, textproto.MIMEHeader(header), nil
} }

View file

@ -505,14 +505,14 @@ func DomainAdd(ctx context.Context, domain dns.Domain, accountName string, local
} else if accountName == "" { } else if accountName == "" {
return fmt.Errorf("%w: account name is empty", ErrRequest) return fmt.Errorf("%w: account name is empty", ErrRequest)
} else if !ok { } else if !ok {
nc.Accounts[accountName] = MakeAccountConfig(smtp.Address{Localpart: localpart, Domain: domain}) nc.Accounts[accountName] = MakeAccountConfig(smtp.NewAddress(localpart, domain))
} else if accountName != Conf.Static.Postmaster.Account { } else if accountName != Conf.Static.Postmaster.Account {
nacc := nc.Accounts[accountName] nacc := nc.Accounts[accountName]
nd := map[string]config.Destination{} nd := map[string]config.Destination{}
for k, v := range nacc.Destinations { for k, v := range nacc.Destinations {
nd[k] = v nd[k] = v
} }
pmaddr := smtp.Address{Localpart: "postmaster", Domain: domain} pmaddr := smtp.NewAddress("postmaster", domain)
nd[pmaddr.String()] = config.Destination{} nd[pmaddr.String()] = config.Destination{}
nacc.Destinations = nd nacc.Destinations = nd
nc.Accounts[accountName] = nacc nc.Accounts[accountName] = nacc

View file

@ -673,7 +673,7 @@ many authentication failures).
// Messages to postmaster will get to the account too. // Messages to postmaster will get to the account too.
var contactEmail string var contactEmail string
if addr.Localpart.IsInternational() { if addr.Localpart.IsInternational() {
contactEmail = smtp.Address{Localpart: "postmaster", Domain: addr.Domain}.Pack(false) contactEmail = smtp.NewAddress("postmaster", addr.Domain).Pack(false)
} else { } else {
contactEmail = addr.Pack(false) contactEmail = addr.Pack(false)
} }

View file

@ -120,7 +120,7 @@ func Verify(elog *slog.Logger, r io.ReaderAt, key []byte, period time.Duration)
if err != nil { if err != nil {
return fmt.Errorf("%w: from address with bad localpart: %v", ErrFrom, err) return fmt.Errorf("%w: from address with bad localpart: %v", ErrFrom, err)
} }
addr := smtp.Address{Localpart: lp, Domain: d}.Pack(true) addr := smtp.NewAddress(lp, d).Pack(true)
buf, err := base64.RawURLEncoding.DecodeString(token) buf, err := base64.RawURLEncoding.DecodeString(token)
if err != nil { if err != nil {

View file

@ -508,7 +508,7 @@ func sendReportDomain(ctx context.Context, log mlog.Log, resolver dns.Resolver,
// typical setup the host is a subdomain of a configured domain with // typical setup the host is a subdomain of a configured domain with
// DKIM keys, so we can DKIM-sign our reports. SPF should pass anyway. // DKIM keys, so we can DKIM-sign our reports. SPF should pass anyway.
// todo future: when sending, use an SMTP MAIL FROM that we can relate back to recipient reporting address so we can stop trying to send reports in case of repeated delivery failure DSNs. // todo future: when sending, use an SMTP MAIL FROM that we can relate back to recipient reporting address so we can stop trying to send reports in case of repeated delivery failure DSNs.
from := smtp.Address{Localpart: "postmaster", Domain: fromDom} from := smtp.NewAddress("postmaster", fromDom)
// Subject follows the form from RFC. ../rfc/8460:959 // Subject follows the form from RFC. ../rfc/8460:959
subject := fmt.Sprintf("Report Domain: %s Submitter: %s Report-ID: <%s>", polDom.ASCII, fromDom, report.ReportID) subject := fmt.Sprintf("Report Domain: %s Submitter: %s Report-ID: <%s>", polDom.ASCII, fromDom, report.ReportID)

View file

@ -1229,7 +1229,7 @@ func (s server) MessageGet(ctx context.Context, req webapi.MessageGetRequest) (r
var msgFrom string var msgFrom string
if d, err := dns.ParseDomain(m.MsgFromDomain); err == nil { if d, err := dns.ParseDomain(m.MsgFromDomain); err == nil {
msgFrom = smtp.Address{Localpart: m.MsgFromLocalpart, Domain: d}.Pack(true) msgFrom = smtp.NewAddress(m.MsgFromLocalpart, d).Pack(true)
} }
meta := webapi.MessageMeta{ meta := webapi.MessageMeta{
Size: m.Size, Size: m.Size,

View file

@ -187,7 +187,7 @@ func fromAddrViewMode(tx *bstore.Tx, from MessageAddress) (store.ViewMode, error
if err != nil { if err != nil {
return store.ModeDefault, nil return store.ModeDefault, nil
} }
fromAddr := smtp.Address{Localpart: lp, Domain: from.Domain}.Pack(true) fromAddr := smtp.NewAddress(lp, from.Domain).Pack(true)
fas := store.FromAddressSettings{FromAddress: fromAddr} fas := store.FromAddressSettings{FromAddress: fromAddr}
err = tx.Get(&fas) err = tx.Get(&fas)
if err == bstore.ErrAbsent { if err == bstore.ErrAbsent {