Skip to content

Commit

Permalink
add system generated flag
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbr0wn committed Oct 21, 2024
1 parent c292501 commit 772fa17
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 21 deletions.
44 changes: 42 additions & 2 deletions mailvalidate/role_emails.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,33 @@ matches = [
'api',
'app',
'apps',
'appstore',
'apple',
'arin',
'asd',
'ask',
'asset',
'avis',
'bcc',
'bd',
'beta',
'bod',
'bot',
'bills',
'biz',
'ca',
'capital',
'care',
'ceo',
'chat',
'church',
'clay',
'cm',
'com',
'crm',
'cs',
'csm',
'dandb',
'dev',
'dns',
'eng',
Expand All @@ -51,6 +57,8 @@ matches = [
'ftp',
'fun',
'gm',
'hatch',
'heap',
'hi',
'hq',
'hr',
Expand All @@ -63,6 +71,8 @@ matches = [
'lab',
'labs',
'lead',
'learn',
'learning',
'lusha',
'md',
'mt',
Expand All @@ -83,14 +93,17 @@ matches = [
'sac',
'sale',
'sales',
'send',
'ship',
'signal',
'se',
'sem',
'seo',
'sf',
'ta',
'tax',
'tips',
'token',
'uk',
'us',
'usa',
Expand All @@ -102,24 +115,28 @@ matches = [
contains = [
'abuse',
'academy',
'accessibility',
'access',
'account',
'acquisition',
'admin',
'admisiones',
'admissions',
'adobe',
'adops',
'adventure',
'advertise',
'advertising',
'advice',
'advisor',
'adwords',
'aetna',
'affiliate',
'africa',
'agence',
'agencia',
'agency',
'agents',
'airbnb',
'airbyte',
'alarm',
'alert',
Expand All @@ -139,12 +156,14 @@ contains = [
'ambassadors',
'american',
'amministrazione',
'amazon',
'analysts',
'analytics',
'android',
'angels',
'animation',
'announce',
'apple',
'application',
'apply',
'appointments',
Expand All @@ -161,6 +180,8 @@ contains = [
'atencionalcliente',
'atendimento',
'auctions',
'author',
'auto-',
'automation',
'available',
'awesome',
Expand All @@ -179,6 +200,7 @@ contains = [
'bizdev',
'blog',
'board',
'books',
'bookclub',
'bookkeeping',
'booking',
Expand All @@ -189,22 +211,29 @@ contains = [
'broadcast',
'broker',
'buchhaltung',
'budget',
'bugs',
'build',
'bursar',
'busdev',
'business',
'butik',
'buyer',
'caltrain',
'campaign',
'campusteam',
'capacitacion',
'capital',
'capetown',
'captain',
'cards',
'career',
'catering',
'celsius',
'central',
'centro',
'ceos',
'certific',
'change',
'channel',
'chartering',
Expand All @@ -216,6 +245,7 @@ contains = [
'claim',
'classof',
'classroom',
'clearbit',
'client',
'clinic',
'cloud',
Expand Down Expand Up @@ -286,6 +316,7 @@ contains = [
'database',
'deals',
'delivery',
'deltek',
'demo',
'denver',
'departures',
Expand All @@ -296,6 +327,7 @@ contains = [
'dev.',
'dev-',
'dev_',
'developer',
'digest',
'digital',
'digsitesvalue',
Expand All @@ -307,6 +339,7 @@ contains = [
'discuss',
'dispatch',
'diversity',
'dividend',
'dmarc',
'dns.',
'dns-',
Expand Down Expand Up @@ -415,6 +448,7 @@ contains = [
'hsbc',
'hsstaff',
'hsteachers',
'hubspot',
'human_resources',
'humanresources',
'idea',
Expand All @@ -438,6 +472,7 @@ contains = [
'instagram',
'insurance',
'integration',
'interest',
'intern',
'invest',
'invite',
Expand Down Expand Up @@ -469,6 +504,7 @@ contains = [
'library',
'licensing',
'lifesum',
'linkedin',
'links',
'list',
'login',
Expand Down Expand Up @@ -604,6 +640,7 @@ contains = [
'receipt',
'recepcion',
'reception',
'reconciliation',
'record',
'recruit',
'recrutement',
Expand All @@ -614,7 +651,7 @@ contains = [
'redazione',
'referrals',
'register',
'registrar',
'registra',
'registration',
'regulatory',
'reklama',
Expand All @@ -640,6 +677,7 @@ contains = [
'retool',
'returns',
'revenue',
'reward',
'rezervari',
'rfp',
'rockstars',
Expand Down Expand Up @@ -672,6 +710,7 @@ contains = [
'server',
'service',
'servicioalcliente',
'session',
'shareholders',
'ship',
'shipping',
Expand Down Expand Up @@ -744,6 +783,7 @@ contains = [
'tribe',
'truck',
'trustees',
'turbotax',
'turismo',
'twitter',
'undisclosed',
Expand Down
94 changes: 94 additions & 0 deletions mailvalidate/system_generated.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package mailvalidate

import (
"regexp"
"strings"
"unicode"
)

func IsSystemGeneratedUser(user string) bool {
if isNumeric(user) || isRandomUsername(user) {
return true
}
return false
}

func isNumeric(s string) bool {
for _, char := range s {
if !unicode.IsDigit(char) {
return false
}
}
return true
}

func isRandomUsername(username string) bool {
// Check if the username contains only allowed characters
allowedChars := regexp.MustCompile(`^[a-zA-Z0-9.=_-]+$`)
if !allowedChars.MatchString(username) {
return false
}

// Check for patterns with many numbers and dashes
numDashPattern := regexp.MustCompile(`(\d+-){3,}|\d{5,}`)
if numDashPattern.MatchString(username) {
return true
}

// Check for long hexadecimal-like strings
hexPattern := regexp.MustCompile(`^[a-f0-9]{10,}$`)
if hexPattern.MatchString(username) {
return true
}

// Check for multiple segments separated by dots with numbers
segments := strings.Split(username, ".")
numericSegments := 0
for _, segment := range segments {
if regexp.MustCompile(`^\d+$`).MatchString(segment) {
numericSegments++
}
}
if numericSegments >= 3 {
return true
}

// Check for long random string followed by a more structured part
randomStructuredPattern := regexp.MustCompile(`^[a-z0-9]{20,}[-=][a-z0-9._-]+$`)
if randomStructuredPattern.MatchString(username) {
return true
}

// If none of the above patterns match, it's likely not a random username
return false
}

func countTransitions(s string) int {
transitions := 0
prevType := otherType
for _, char := range s {
currentType := charTypeCheck(char)
if currentType != prevType && prevType != otherType && currentType != otherType {
transitions++
}
prevType = currentType
}
return transitions
}

type charType int

const (
otherType charType = iota
letterType
digitType
)

func charTypeCheck(r rune) charType {
if unicode.IsLetter(r) {
return letterType
} else if unicode.IsDigit(r) {
return digitType
}
return otherType
}
Loading

0 comments on commit 772fa17

Please sign in to comment.