Skip to content

Commit

Permalink
Merge pull request #7 from hashbangblob/master
Browse files Browse the repository at this point in the history
Fix rules for protonmail & add alternative domain names
  • Loading branch information
dimuska139 authored Jun 5, 2024
2 parents f96110d + 186674e commit 42af7d0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
7 changes: 7 additions & 0 deletions domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,10 @@ var yandexDomains = []string{
"yandex.asia",
"yandex.mobi",
}

var protonmailDomains = []string{
"protonmail.ch",
"protonmail.com",
"proton.me",
"pm.me",
}
6 changes: 5 additions & 1 deletion normalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ func NewNormalizer() *Normalizer {
rules[domain] = yandexRule
}

protonmailRule := &ProtonmailRule{}
for _, domain := range protonmailDomains {
rules[domain] = protonmailRule
}

appleRule := &AppleRule{}
rules["icloud.com"] = appleRule
rules["me.com"] = appleRule
rules["protonmail.ch"] = &ProtonmailRule{}
rules["emailsrvr.com"] = &RackspaceRule{}
rules["zoho.com"] = &ZohoRule{}
return &Normalizer{rules: rules}
Expand Down
9 changes: 8 additions & 1 deletion protonmail_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ type ProtonmailRule struct {

func (rule *ProtonmailRule) ProcessUsername(username string) string {
result := strings.ToLower(username)
return strings.Replace(result, "+", "", -1)
result = strings.Replace(result, ".", "", -1)

plusSignIndex := strings.Index(result, "+")
if plusSignIndex != -1 {
result = result[0:plusSignIndex]
}

return result
}

func (rule *ProtonmailRule) ProcessDomain(domain string) string {
Expand Down
2 changes: 1 addition & 1 deletion protonmail_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

func TestProtonmailUsername(t *testing.T) {
rule := ProtonmailRule{}
assert.Equal(t, "t.est", rule.ProcessUsername("t+.est"))
assert.Equal(t, "t", rule.ProcessUsername("t+.est"))
}

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

0 comments on commit 42af7d0

Please sign in to comment.