Skip to content

Commit

Permalink
Merge pull request #186 from mocktools/develop
Browse files Browse the repository at this point in the history
Golang smtpmock v2.3.2
  • Loading branch information
bestwebua authored Nov 14, 2024
2 parents 1b8e678 + 0a11be2 commit 5df633f
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .circleci/.goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---

version: 2

builds:
- id: "smtpmock-build"
dir: cmd
Expand Down
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
golang 1.22.5
golang 1.23.0
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)<?((.+)@` + domainRegexPattern + `)>?`
emailRegexPattern = `(?i)<?([\p{L}0-9][\p{L}0-9\-.]*[\p{L}0-9]+@` + domainRegexPattern + `)>?`
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 + `\]`

Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
18 changes: 18 additions & 0 deletions handler_mailfrom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := "[email protected]@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 := "[email protected]"

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 := "[email protected]"

assert.Equal(t, emptyString, handler.mailfromEmail("MAIL FROM: "+invalidEmail))
})
}

func TestHandlerHeloIsBlacklistedEmail(t *testing.T) {
Expand Down
18 changes: 18 additions & 0 deletions handler_rcptto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := "[email protected]@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 := "[email protected]"

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 := "[email protected]"

assert.Equal(t, emptyString, handler.rcpttoEmail("RCPT TO: "+invalidEmail))
})
}

func TestHandlerRcpttoIsBlacklistedEmail(t *testing.T) {
Expand Down

0 comments on commit 5df633f

Please sign in to comment.