diff --git a/.circleci/.goreleaser.yml b/.circleci/.goreleaser.yml index e3010e6..7f53071 100644 --- a/.circleci/.goreleaser.yml +++ b/.circleci/.goreleaser.yml @@ -1,5 +1,7 @@ --- +version: 2 + builds: - id: "smtpmock-build" dir: cmd diff --git a/.circleci/config.yml b/.circleci/config.yml index 5a418d6..0b65f05 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,7 +5,7 @@ version: 2.1 defaults: &defaults working_directory: ~/go-smtp-mock docker: - - image: cimg/go:1.22.5 + - image: cimg/go:1.23.0 jobs: linters: diff --git a/.tool-versions b/.tool-versions index 009efa3..1a59aeb 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -golang 1.22.5 +golang 1.23.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index b8343ea..1a29273 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.3.2] - 2024-11-14 + +### Fixed + +- Fixed issue with [invalid email address parsing](https://github.com/mocktools/go-smtp-mock/issues/135) for `MAIL FROM` and `RCPT TO` commands + ## [2.3.1] - 2024-08-04 ### Updated diff --git a/consts.go b/consts.go index c55a390..5a6637b 100644 --- a/consts.go +++ b/consts.go @@ -53,7 +53,7 @@ const ( // Regex patterns availableCmdsRegexPattern = `(?i)helo|ehlo|mail from:|rcpt to:|data|rset|noop|quit` domainRegexPattern = `(?i)([\p{L}0-9]+([\-.]{1}[\p{L}0-9]+)*\.\p{L}{2,63}|localhost)` - emailRegexPattern = `(?i)?` + emailRegexPattern = `(?i)?` ipAddressRegexPattern = `(\b25[0-5]|\b2[0-4][0-9]|\b[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}` addressLiteralRegexPattern = `|\[` + ipAddressRegexPattern + `\]` diff --git a/go.sum b/go.sum index e26f03f..63e9a8f 100644 --- a/go.sum +++ b/go.sum @@ -1,18 +1,14 @@ -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0 h1:M2gUjqZET1qApGOWNSnZ49BAIMX4F/1plDv3+l31EJ4= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= diff --git a/handler_mailfrom_test.go b/handler_mailfrom_test.go index d10f3f4..0393c0b 100644 --- a/handler_mailfrom_test.go +++ b/handler_mailfrom_test.go @@ -245,6 +245,24 @@ func TestHandlerMailfromMailfromEmail(t *testing.T) { assert.Equal(t, emptyString, handler.mailfromEmail("MAIL FROM: "+invalidEmail)) }) + + t.Run("when request includes invalid email with multiple @ symbols", func(t *testing.T) { + invalidEmail := "a@a.com@b.com" + + assert.Equal(t, emptyString, handler.mailfromEmail("MAIL FROM: "+invalidEmail)) + }) + + t.Run("when request includes invalid email starting with dot", func(t *testing.T) { + invalidEmail := ".user@example.com" + + assert.Equal(t, emptyString, handler.mailfromEmail("MAIL FROM: "+invalidEmail)) + }) + + t.Run("when request includes invalid email ending with dot before @", func(t *testing.T) { + invalidEmail := "user.@example.com" + + assert.Equal(t, emptyString, handler.mailfromEmail("MAIL FROM: "+invalidEmail)) + }) } func TestHandlerHeloIsBlacklistedEmail(t *testing.T) { diff --git a/handler_rcptto_test.go b/handler_rcptto_test.go index 7933860..c98247e 100644 --- a/handler_rcptto_test.go +++ b/handler_rcptto_test.go @@ -345,6 +345,24 @@ func TestHandlerRcpttoRcpttoEmail(t *testing.T) { assert.Equal(t, emptyString, handler.rcpttoEmail("RCPT TO: "+invalidEmail)) }) + + t.Run("when request includes invalid email address, wrong format", func(t *testing.T) { + invalidEmail := "a@a.com@b.com" + + assert.Equal(t, emptyString, handler.rcpttoEmail("RCPT TO: "+invalidEmail)) + }) + + t.Run("when request includes invalid email starting with dot", func(t *testing.T) { + invalidEmail := ".user@example.com" + + assert.Equal(t, emptyString, handler.rcpttoEmail("RCPT TO: "+invalidEmail)) + }) + + t.Run("when request includes invalid email ending with dot before @", func(t *testing.T) { + invalidEmail := "user.@example.com" + + assert.Equal(t, emptyString, handler.rcpttoEmail("RCPT TO: "+invalidEmail)) + }) } func TestHandlerRcpttoIsBlacklistedEmail(t *testing.T) {