From ebb8ad06b5a0cc073ad3fd778b13d4d564391a17 Mon Sep 17 00:00:00 2001 From: Mechiel Lukkien Date: Thu, 9 May 2024 21:26:22 +0200 Subject: [PATCH] use shorter smtp.NewAddress() instead of smtp.Address{...} --- dmarcdb/eval.go | 2 +- message/examples_test.go | 2 +- message/from.go | 2 +- mox-/admin.go | 4 ++-- quickstart.go | 2 +- subjectpass/subjectpass.go | 2 +- tlsrptsend/send.go | 2 +- webapisrv/server.go | 2 +- webmail/api.go | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/dmarcdb/eval.go b/dmarcdb/eval.go index 39b80e2..5874089 100644 --- a/dmarcdb/eval.go +++ b/dmarcdb/eval.go @@ -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. // A single report can contain deliveries from a single policy domain // 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 := fmt.Sprintf("Report Domain: %s Submitter: %s Report-ID: <%s>", dom.ASCII, mox.Conf.Static.HostnameDomain.ASCII, report.ReportMetadata.ReportID) diff --git a/message/examples_test.go b/message/examples_test.go index b98daea..c14b33f 100644 --- a/message/examples_test.go +++ b/message/examples_test.go @@ -107,7 +107,7 @@ func ExampleComposer() { }() // 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 xc.Subject("hi ☺") diff --git a/message/from.go b/message/from.go index 4ba3f78..5d46b0c 100644 --- a/message/from.go +++ b/message/from.go @@ -51,6 +51,6 @@ func From(elog *slog.Logger, strict bool, r io.ReaderAt, p *Part) (raddr smtp.Ad if err != nil { 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 } diff --git a/mox-/admin.go b/mox-/admin.go index 497328e..4d0012b 100644 --- a/mox-/admin.go +++ b/mox-/admin.go @@ -505,14 +505,14 @@ func DomainAdd(ctx context.Context, domain dns.Domain, accountName string, local } else if accountName == "" { return fmt.Errorf("%w: account name is empty", ErrRequest) } 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 { nacc := nc.Accounts[accountName] nd := map[string]config.Destination{} for k, v := range nacc.Destinations { nd[k] = v } - pmaddr := smtp.Address{Localpart: "postmaster", Domain: domain} + pmaddr := smtp.NewAddress("postmaster", domain) nd[pmaddr.String()] = config.Destination{} nacc.Destinations = nd nc.Accounts[accountName] = nacc diff --git a/quickstart.go b/quickstart.go index 1bedb46..7740030 100644 --- a/quickstart.go +++ b/quickstart.go @@ -673,7 +673,7 @@ many authentication failures). // Messages to postmaster will get to the account too. var contactEmail string if addr.Localpart.IsInternational() { - contactEmail = smtp.Address{Localpart: "postmaster", Domain: addr.Domain}.Pack(false) + contactEmail = smtp.NewAddress("postmaster", addr.Domain).Pack(false) } else { contactEmail = addr.Pack(false) } diff --git a/subjectpass/subjectpass.go b/subjectpass/subjectpass.go index db5b29a..d961b5b 100644 --- a/subjectpass/subjectpass.go +++ b/subjectpass/subjectpass.go @@ -120,7 +120,7 @@ func Verify(elog *slog.Logger, r io.ReaderAt, key []byte, period time.Duration) if err != nil { 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) if err != nil { diff --git a/tlsrptsend/send.go b/tlsrptsend/send.go index 2809005..69a05bd 100644 --- a/tlsrptsend/send.go +++ b/tlsrptsend/send.go @@ -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 // 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. - from := smtp.Address{Localpart: "postmaster", Domain: fromDom} + from := smtp.NewAddress("postmaster", fromDom) // 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) diff --git a/webapisrv/server.go b/webapisrv/server.go index d1d3aba..dc0a9b4 100644 --- a/webapisrv/server.go +++ b/webapisrv/server.go @@ -1229,7 +1229,7 @@ func (s server) MessageGet(ctx context.Context, req webapi.MessageGetRequest) (r var msgFrom string 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{ Size: m.Size, diff --git a/webmail/api.go b/webmail/api.go index bc94764..8705109 100644 --- a/webmail/api.go +++ b/webmail/api.go @@ -187,7 +187,7 @@ func fromAddrViewMode(tx *bstore.Tx, from MessageAddress) (store.ViewMode, error if err != 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} err = tx.Get(&fas) if err == bstore.ErrAbsent {