Skip to content

Commit

Permalink
Code style improvements
Browse files Browse the repository at this point in the history
This patch contains some minor code style improvements, to leave the
linter happier and generally follow best practices in some areas where
things snuck through.
  • Loading branch information
albertito committed Dec 1, 2018
1 parent 4296e28 commit 4db9ffe
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 26 deletions.
5 changes: 4 additions & 1 deletion internal/courier/smtp_test.go
Expand Up @@ -110,7 +110,10 @@ func TestSMTP(t *testing.T) {
// lookup whick makes the test more hermetic. This is a hack, ideally we
// would be able to override the default resolver, but Go does not
// implement that yet.
testMX["to"] = []*net.MX{{":::", 10}, {host, 20}}
testMX["to"] = []*net.MX{
{Host: ":::", Pref: 10},
{Host: host, Pref: 20},
}
*smtpPort = port

s, tmpDir := newSMTP(t)
Expand Down
40 changes: 20 additions & 20 deletions internal/queue/queue.go
Expand Up @@ -393,27 +393,27 @@ func (item *Item) deliver(q *Queue, rcpt *Recipient) (err error, permanent bool)
if envelope.DomainIn(rcpt.Address, q.localDomains) {
deliverAttempts.Add("email:local", 1)
return q.localC.Deliver(item.From, rcpt.Address, item.Data)
} else {
deliverAttempts.Add("email:remote", 1)
from := item.From
if !envelope.DomainIn(item.From, q.localDomains) {
// We're sending from a non-local to a non-local. This should
// happen only when there's an alias to forward email to a
// non-local domain. In this case, using the original From is
// problematic, as we may not be an authorized sender for this.
// Some MTAs (like Exim) will do it anyway, others (like
// gmail) will construct a special address based on the
// original address. We go with the latter.
// Note this assumes "+" is an alias suffix separator.
// We use the IDNA version of the domain if possible, because
// we can't know if the other side will support SMTPUTF8.
from = fmt.Sprintf("%s+fwd_from=%s@%s",
envelope.UserOf(rcpt.OriginalAddress),
strings.Replace(from, "@", "=", -1),
mustIDNAToASCII(envelope.DomainOf(rcpt.OriginalAddress)))
}
return q.remoteC.Deliver(from, rcpt.Address, item.Data)
}

deliverAttempts.Add("email:remote", 1)
from := item.From
if !envelope.DomainIn(item.From, q.localDomains) {
// We're sending from a non-local to a non-local. This should
// happen only when there's an alias to forward email to a
// non-local domain. In this case, using the original From is
// problematic, as we may not be an authorized sender for this.
// Some MTAs (like Exim) will do it anyway, others (like
// gmail) will construct a special address based on the
// original address. We go with the latter.
// Note this assumes "+" is an alias suffix separator.
// We use the IDNA version of the domain if possible, because
// we can't know if the other side will support SMTPUTF8.
from = fmt.Sprintf("%s+fwd_from=%s@%s",
envelope.UserOf(rcpt.OriginalAddress),
strings.Replace(from, "@", "=", -1),
mustIDNAToASCII(envelope.DomainOf(rcpt.OriginalAddress)))
}
return q.remoteC.Deliver(from, rcpt.Address, item.Data)
}

// countRcpt counts how many recipients are in the given status.
Expand Down
2 changes: 1 addition & 1 deletion internal/smtpsrv/server_test.go
Expand Up @@ -374,7 +374,7 @@ func generateCert(path string) error {
x509.KeyUsageCertSign,

BasicConstraintsValid: true,
IsCA: true,
IsCA: true,
}

priv, err := rsa.GenerateKey(rand.Reader, 1024)
Expand Down
8 changes: 4 additions & 4 deletions internal/sts/sts_test.go
Expand Up @@ -385,7 +385,7 @@ func TestCacheBadData(t *testing.T) {
}
}

func mustFetch(t *testing.T, c *PolicyCache, ctx context.Context, d string) *Policy {
func (c *PolicyCache) mustFetch(ctx context.Context, t *testing.T, d string) *Policy {
p, err := c.Fetch(ctx, d)
if err != nil {
t.Fatalf("Fetch %q failed: %v", d, err)
Expand Down Expand Up @@ -421,7 +421,7 @@ func TestCacheRefresh(t *testing.T) {
mode: enforce
mx: mx
max_age: 100`
p := mustFetch(t, c, ctx, "refresh-test")
p := c.mustFetch(ctx, t, "refresh-test")
if p.MaxAge != 100*time.Second {
t.Fatalf("policy.MaxAge is %v, expected 100s", p.MaxAge)
}
Expand All @@ -434,7 +434,7 @@ func TestCacheRefresh(t *testing.T) {
mx: mx
max_age: 200`

p = mustFetch(t, c, ctx, "refresh-test")
p = c.mustFetch(ctx, t, "refresh-test")
if p.MaxAge != 100*time.Second {
t.Fatalf("policy.MaxAge is %v, expected 100s", p.MaxAge)
}
Expand All @@ -450,7 +450,7 @@ func TestCacheRefresh(t *testing.T) {
time.Sleep(5 * time.Millisecond)
}

p = mustFetch(t, c, ctx, "refresh-test")
p = c.mustFetch(ctx, t, "refresh-test")
if p.MaxAge != 200*time.Second {
t.Fatalf("policy.MaxAge is %v, expected 200s", p.MaxAge)
}
Expand Down

0 comments on commit 4db9ffe

Please sign in to comment.