Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.5.1] - 2025-06-24

### Added

- Added [ability to use special characters in email regex pattern](https://github.com/mocktools/go-smtp-mock/pull/207)

## [2.5.0] - 2025-05-31

### Added
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- [Inside of Golang ecosystem](#inside-of-golang-ecosystem)
- [Configuring](#configuring)
- [Manipulation with server](#manipulation-with-server)
- [Using a custom logger](#using-a-custom-logger)
- [Inside of Ruby ecosystem](#inside-of-ruby-ecosystem)
- [Example of usage](#example-of-usage)
- [Inside of any ecosystem](#inside-of-any-ecosystem)
Expand Down
3 changes: 2 additions & 1 deletion consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ 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)(?:[\p{L}\p{N}\s]*?<?)*?([a-zA-Z0-9][-a-zA-Z0-9.]*[a-zA-Z0-9]@` + domainRegexPattern + `)>*`
localPartChars = `[a-zA-Z0-9.!#$%&'*+\-/=?^_\x60{|}~]`
emailRegexPattern = `(?i)(?:[\p{L}\p{N}\s]*?<?)*?(` + localPartChars + `+(?:\.` + localPartChars + `+)*@` + 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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/mocktools/go-smtp-mock/v2

go 1.15

require github.com/stretchr/testify v1.9.0
require github.com/stretchr/testify v1.10.0
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
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=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
22 changes: 16 additions & 6 deletions handler_mailfrom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,26 @@ func TestHandlerMailfromMailfromEmail(t *testing.T) {
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]"
t.Run("when request includes email with plus sign", func(t *testing.T) {
email := "[email protected]"
assert.Equal(t, email, handler.mailfromEmail("MAIL FROM: "+email))
})

assert.Equal(t, emptyString, handler.mailfromEmail("MAIL FROM: "+invalidEmail))
t.Run("when request includes email with multiple special characters", func(t *testing.T) {
email := "user.name+tag!#$%@example.com"
assert.Equal(t, email, handler.mailfromEmail("MAIL FROM: "+email))
})

t.Run("when request includes invalid email ending with dot before @", func(t *testing.T) {
invalidEmail := "[email protected]"
t.Run("when request includes email with special characters and angle brackets", func(t *testing.T) {
rawEmail := "[email protected]"
request := "MAIL FROM: <" + rawEmail + ">"
assert.Equal(t, rawEmail, handler.mailfromEmail(request))
})

assert.Equal(t, emptyString, handler.mailfromEmail("MAIL FROM: "+invalidEmail))
t.Run("when request includes email with special characters and display name", func(t *testing.T) {
rawEmail := "[email protected]"
request := "MAIL FROM: Support Team <" + rawEmail + ">"
assert.Equal(t, rawEmail, handler.mailfromEmail(request))
})
}

Expand Down
12 changes: 0 additions & 12 deletions handler_rcptto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,18 +359,6 @@ func TestHandlerRcpttoRcpttoEmail(t *testing.T) {

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
4 changes: 2 additions & 2 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func TestServerMessages(t *testing.T) {
server.messages.RLock()
assert.Empty(t, server.messages.items)
assert.Empty(t, server.Messages())
assert.NotSame(t, server.messages.items, server.Messages())
assert.NotEqual(t, server.messages.items, server.Messages())
server.messages.RUnlock()

message := new(Message)
Expand All @@ -176,7 +176,7 @@ func TestServerMessages(t *testing.T) {
server.messages.RLock()
assert.Equal(t, []*Message{message}, server.messages.items)
assert.Equal(t, []Message{*message}, server.Messages())
assert.NotSame(t, server.messages.items, server.Messages())
assert.NotEqual(t, server.messages.items, server.Messages())
server.messages.RUnlock()
})
}
Expand Down