From 283250524ee74185b5bc8c54d0a583ba8e1094c3 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 14 Mar 2026 15:02:44 -0400 Subject: [PATCH] Fix some issues identified by gopls and go fix --- cmd/mailpopbox-router/monitor_test.go | 4 ++-- cmd/mailpopbox/pop3_test.go | 4 ++-- cmd/mailpopbox/smtp.go | 7 +++---- pkg/pop3/conn_test.go | 3 +-- pkg/smtp/relay_test.go | 8 ++++---- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/cmd/mailpopbox-router/monitor_test.go b/cmd/mailpopbox-router/monitor_test.go index e893d3c..e13e015 100644 --- a/cmd/mailpopbox-router/monitor_test.go +++ b/cmd/mailpopbox-router/monitor_test.go @@ -152,7 +152,7 @@ func TestMoveOneMessageSuccess(t *testing.T) { t.Errorf("Expected %d dest messages, got %d", want, got) } if !bytes.HasSuffix(d.msgs[0], msg.buf.Bytes()) { - t.Errorf("Expected dest message to contain %s, got %s", string(msg.buf.Bytes()), string(d.msgs[0])) + t.Errorf("Expected dest message to contain %s, got %s", msg.buf.String(), string(d.msgs[0])) } } @@ -220,6 +220,6 @@ func TestMoveOneMessageDeleteError(t *testing.T) { t.Errorf("Expected %d dest messages, got %d", want, got) } if !bytes.HasSuffix(d.msgs[0], msg.buf.Bytes()) { - t.Errorf("Expected dest message to contain %s, got %s", string(msg.buf.Bytes()), string(d.msgs[0])) + t.Errorf("Expected dest message to contain %s, got %s", msg.buf.String(), string(d.msgs[0])) } } diff --git a/cmd/mailpopbox/pop3_test.go b/cmd/mailpopbox/pop3_test.go index 2ec1f52..2a2c45b 100644 --- a/cmd/mailpopbox/pop3_test.go +++ b/cmd/mailpopbox/pop3_test.go @@ -144,7 +144,7 @@ func TestMailbox(t *testing.T) { t.Errorf("Failed to create a.msg: %v", err) return } - for i := 0; i < 1024*10; i++ { + for range 1024 * 10 { buf := []byte{'a'} _, err = f.Write(buf) if err != nil { @@ -159,7 +159,7 @@ func TestMailbox(t *testing.T) { t.Errorf("Failed to create b.msg: %v", err) return } - for i := 0; i < 1024*3; i++ { + for range 1024 * 3 { buf := []byte{'z'} _, err = f.Write(buf) if err != nil { diff --git a/cmd/mailpopbox/smtp.go b/cmd/mailpopbox/smtp.go index 93aed49..2cb6118 100644 --- a/cmd/mailpopbox/smtp.go +++ b/cmd/mailpopbox/smtp.go @@ -15,6 +15,7 @@ import ( "os" "path" "regexp" + "slices" "go.uber.org/zap" @@ -113,10 +114,8 @@ func (server *smtpServer) VerifyAddress(addr mail.Address) smtp.ReplyLine { if s == nil { return smtp.ReplyBadMailbox } - for _, blocked := range s.BlockedAddresses { - if blocked == addr.Address { - return smtp.ReplyMailboxUnallowed - } + if slices.Contains(s.BlockedAddresses, addr.Address) { + return smtp.ReplyMailboxUnallowed } return smtp.ReplyOK } diff --git a/pkg/pop3/conn_test.go b/pkg/pop3/conn_test.go index 2cfdc46..ce8c135 100644 --- a/pkg/pop3/conn_test.go +++ b/pkg/pop3/conn_test.go @@ -9,7 +9,6 @@ package pop3 import ( "fmt" "io" - "io/ioutil" "net" "net/textproto" "path/filepath" @@ -124,7 +123,7 @@ func (mb *testMailbox) GetMessage(id int) Message { func (mb *testMailbox) Retrieve(msg Message) (io.ReadCloser, error) { r := strings.NewReader(msg.(*testMessage).body) - return ioutil.NopCloser(r), nil + return io.NopCloser(r), nil } func (mb *testMailbox) Delete(msg Message) error { diff --git a/pkg/smtp/relay_test.go b/pkg/smtp/relay_test.go index 293165a..400ab1c 100644 --- a/pkg/smtp/relay_test.go +++ b/pkg/smtp/relay_test.go @@ -11,7 +11,7 @@ import ( "crypto/tls" "errors" "fmt" - "io/ioutil" + "io" "mime" "mime/multipart" "net" @@ -260,7 +260,7 @@ func TestDeliveryFailureMessage(t *testing.T) { t.Errorf("Part 0 type want %q, got %q", want, got) } - content, err := ioutil.ReadAll(part) + content, err := io.ReadAll(part) if err != nil { t.Errorf("Failed to read part 0 content: %v", err) return @@ -286,7 +286,7 @@ func TestDeliveryFailureMessage(t *testing.T) { t.Errorf("Part 1 type want %q, got %q", want, got) } - content, err = ioutil.ReadAll(part) + content, err = io.ReadAll(part) if err != nil { t.Errorf("Failed to read part 1 content: %v", err) return @@ -316,7 +316,7 @@ func TestDeliveryFailureMessage(t *testing.T) { t.Errorf("Part 2 type want %q, got %q", want, got) } - content, err = ioutil.ReadAll(part) + content, err = io.ReadAll(part) if err != nil { t.Errorf("Failed to read part 2 content: %v", err) return -- 2.52.0