From 429d2e2b3ab155013f643fd54ad089dd305d20d9 Mon Sep 17 00:00:00 2001 From: Ralph Slooten Date: Sat, 21 Jun 2025 23:32:53 +1200 Subject: [PATCH] Chore: Remove unused functionality/deadcode (golangci-lint) --- cmd/root.go | 8 ------- internal/logger/logger.go | 11 ---------- internal/spamassassin/spamassassin.go | 7 ------- .../storage/{testing.go => functions_test.go} | 0 internal/storage/tags.go | 11 ---------- internal/storage/tags_test.go | 21 +++++++++++++++---- 6 files changed, 17 insertions(+), 41 deletions(-) rename internal/storage/{testing.go => functions_test.go} (100%) diff --git a/cmd/root.go b/cmd/root.go index 3ba73e9..e8912cf 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -67,14 +67,6 @@ func Execute() { } } -// SendmailExecute adds all child commands to the root command and sets flags appropriately. -// This is called by main.main(). It only needs to happen once to the rootCmd. -func SendmailExecute() { - args := []string{"mailpit", "sendmail"} - - rootCmd.Run(sendmailCmd, args) -} - func init() { // hide autocompletion rootCmd.CompletionOptions.HiddenDefaultCmd = true diff --git a/internal/logger/logger.go b/internal/logger/logger.go index 5e00dae..88b31ec 100644 --- a/internal/logger/logger.go +++ b/internal/logger/logger.go @@ -66,17 +66,6 @@ func PrettyPrint(i interface{}) { fmt.Println(string(s)) } -// CleanIP returns a human-readable IP for the logging interface -// when starting services. It translates [::]: to "0.0.0.0:" -func CleanIP(s string) string { - re := regexp.MustCompile(`^\[\:\:\]\:\d+`) - if re.MatchString(s) { - return "0.0.0.0:" + s[5:] - } - - return s -} - // CleanHTTPIP returns a human-readable IP for the logging interface // when starting services. It translates [::]: to "localhost:" func CleanHTTPIP(s string) string { diff --git a/internal/spamassassin/spamassassin.go b/internal/spamassassin/spamassassin.go index 044c897..8693771 100644 --- a/internal/spamassassin/spamassassin.go +++ b/internal/spamassassin/spamassassin.go @@ -57,13 +57,6 @@ func SetService(s string) { } } -// SetTimeout defines the timeout -func SetTimeout(t int) { - if t > 0 { - timeout = t - } -} - // Ping returns whether a service is active or not func Ping() error { if service == "postmark" { diff --git a/internal/storage/testing.go b/internal/storage/functions_test.go similarity index 100% rename from internal/storage/testing.go rename to internal/storage/functions_test.go diff --git a/internal/storage/tags.go b/internal/storage/tags.go index 0b13eff..3627069 100644 --- a/internal/storage/tags.go +++ b/internal/storage/tags.go @@ -138,17 +138,6 @@ func deleteMessageTag(id, name string) error { return pruneUnusedTags() } -// DeleteAllMessageTags deleted all tags from a message -func DeleteAllMessageTags(id string) error { - if _, err := sqlf.DeleteFrom(tenant("message_tags")). - Where(tenant("message_tags.ID")+" = ?", id). - ExecAndClose(context.TODO(), db); err != nil { - return err - } - - return pruneUnusedTags() -} - // GetAllTags returns all used tags func GetAllTags() []string { var tags = []string{} diff --git a/internal/storage/tags_test.go b/internal/storage/tags_test.go index e67d799..c12cc1b 100644 --- a/internal/storage/tags_test.go +++ b/internal/storage/tags_test.go @@ -1,11 +1,13 @@ package storage import ( + "context" "fmt" "strings" "testing" "github.com/axllent/mailpit/config" + "github.com/leporo/sqlf" ) func TestTags(t *testing.T) { @@ -83,7 +85,7 @@ func TestTags(t *testing.T) { assertEqual(t, strings.Join(newTags[1:], "|"), strings.Join(returnedTags, "|"), "Message tags do not match after deleting 1") // remove all tags - if err := DeleteAllMessageTags(id); err != nil { + if err := deleteAllMessageTags(id); err != nil { t.Log("error ", err) t.Fail() } @@ -97,7 +99,7 @@ func TestTags(t *testing.T) { } returnedTags = getMessageTags(id) assertEqual(t, "Duplicate Tag", strings.Join(returnedTags, "|"), "Message tags should be duplicated") - if err := DeleteAllMessageTags(id); err != nil { + if err := deleteAllMessageTags(id); err != nil { t.Log("error ", err) t.Fail() } @@ -109,7 +111,7 @@ func TestTags(t *testing.T) { } returnedTags = getMessageTags(id) assertEqual(t, "Dirty Tag", strings.Join(returnedTags, "|"), "Dirty message tag did not clean as expected") - if err := DeleteAllMessageTags(id); err != nil { + if err := deleteAllMessageTags(id); err != nil { t.Log("error ", err) t.Fail() } @@ -132,7 +134,7 @@ func TestTags(t *testing.T) { returnedTags = getMessageTags(id) assertEqual(t, "BccTag|CcTag|FromFag|ToTag|X-tag1|X-tag2", strings.Join(returnedTags, "|"), "Tags not detected correctly") - if err := DeleteAllMessageTags(id); err != nil { + if err := deleteAllMessageTags(id); err != nil { t.Log("error ", err) t.Fail() } @@ -186,3 +188,14 @@ func TestUsernameAutoTagging(t *testing.T) { } }) } + +// DeleteAllMessageTags deleted all tags from a message +func deleteAllMessageTags(id string) error { + if _, err := sqlf.DeleteFrom(tenant("message_tags")). + Where(tenant("message_tags.ID")+" = ?", id). + ExecAndClose(context.TODO(), db); err != nil { + return err + } + + return pruneUnusedTags() +}