mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-17 17:47:03 +00:00
Support numeric domain-parts, closes #24
This commit is contained in:
@@ -20,7 +20,7 @@ func ParseMailboxName(localPart string) (result string, err error) {
|
|||||||
|
|
||||||
invalid := make([]byte, 0, 10)
|
invalid := make([]byte, 0, 10)
|
||||||
|
|
||||||
for i := 0; i<len(result); i++ {
|
for i := 0; i < len(result); i++ {
|
||||||
c := result[i]
|
c := result[i]
|
||||||
switch {
|
switch {
|
||||||
case 'a' <= c && c <= 'z':
|
case 'a' <= c && c <= 'z':
|
||||||
@@ -73,15 +73,14 @@ func ValidateDomainPart(domain string) bool {
|
|||||||
}
|
}
|
||||||
prev := '.'
|
prev := '.'
|
||||||
labelLen := 0
|
labelLen := 0
|
||||||
hasLetters := false
|
hasAlphaNum := false
|
||||||
|
|
||||||
for _, c := range domain {
|
for _, c := range domain {
|
||||||
switch {
|
switch {
|
||||||
case ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || c == '_':
|
case ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') ||
|
||||||
|
('0' <= c && c <= '9') || c == '_':
|
||||||
// Must contain some of these to be a valid label
|
// Must contain some of these to be a valid label
|
||||||
hasLetters = true
|
hasAlphaNum = true
|
||||||
labelLen++
|
|
||||||
case '0' <= c && c <= '9':
|
|
||||||
labelLen++
|
labelLen++
|
||||||
case c == '-':
|
case c == '-':
|
||||||
if prev == '.' {
|
if prev == '.' {
|
||||||
@@ -96,11 +95,11 @@ func ValidateDomainPart(domain string) bool {
|
|||||||
if labelLen > 63 {
|
if labelLen > 63 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if !hasLetters {
|
if !hasAlphaNum {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
labelLen = 0
|
labelLen = 0
|
||||||
hasLetters = false
|
hasAlphaNum = false
|
||||||
default:
|
default:
|
||||||
// Unknown character
|
// Unknown character
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
package smtpd
|
package smtpd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestParseMailboxName(t *testing.T) {
|
func TestParseMailboxName(t *testing.T) {
|
||||||
var validTable = []struct{
|
var validTable = []struct {
|
||||||
input string
|
input string
|
||||||
expect string
|
expect string
|
||||||
}{
|
}{
|
||||||
{"mailbox", "mailbox"},
|
{"mailbox", "mailbox"},
|
||||||
@@ -33,7 +34,7 @@ func TestParseMailboxName(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var invalidTable = []struct{
|
var invalidTable = []struct {
|
||||||
input, msg string
|
input, msg string
|
||||||
}{
|
}{
|
||||||
{"", "Empty mailbox name is not permitted"},
|
{"", "Empty mailbox name is not permitted"},
|
||||||
@@ -74,9 +75,10 @@ func TestValidateDomain(t *testing.T) {
|
|||||||
{"_domainkey.foo.com", true, "Underscores are allowed"},
|
{"_domainkey.foo.com", true, "Underscores are allowed"},
|
||||||
{"bar.com.", true, "Must be able to end with a dot"},
|
{"bar.com.", true, "Must be able to end with a dot"},
|
||||||
{"ABC.6DBS.com", true, "Mixed case is OK"},
|
{"ABC.6DBS.com", true, "Mixed case is OK"},
|
||||||
|
{"mail.123.com", true, "Number only label valid"},
|
||||||
|
{"123.com", true, "Number only label valid"},
|
||||||
{"google..com", false, "Double dot not valid"},
|
{"google..com", false, "Double dot not valid"},
|
||||||
{".foo.com", false, "Cannot start with a dot"},
|
{".foo.com", false, "Cannot start with a dot"},
|
||||||
{"mail.123.com", false, "Number only label not valid"},
|
|
||||||
{"google\r.com", false, "Special chars not allowed"},
|
{"google\r.com", false, "Special chars not allowed"},
|
||||||
{"foo.-bar.com", false, "Label cannot start with hyphen"},
|
{"foo.-bar.com", false, "Label cannot start with hyphen"},
|
||||||
{"foo-.bar.com", false, "Label cannot end with hyphen"},
|
{"foo-.bar.com", false, "Label cannot end with hyphen"},
|
||||||
|
|||||||
Reference in New Issue
Block a user