-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
46 lines (39 loc) · 1.81 KB
/
index.js
File metadata and controls
46 lines (39 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const fs = require('node:fs');
const path = require('node:path');
// Load disposable domains from the file
const disposableDomains = fs.readFileSync(path.join(__dirname, 'disposabledomains.txt'), 'utf-8')
.split('\n')
.map(domain => domain.trim())
.filter(domain => domain.length > 0);
/**
* Check if an email address appears generated.
* @param {string} email - The email address to check.
* @returns {boolean} - Returns true if the email appears generated.
*/
function isGeneratedEmail(email) {
// Split email into local part and domain part
const [localPart, domain] = email.split("@");
if (!localPart || !domain) {
return false; // Not a valid email format
}
// Check if the domain is in the list of disposable domains
if (disposableDomains.includes(domain.toLowerCase())) {
return true;
}
// Check for excessive length and patterns like random characters
const excessiveLength = localPart.length > 30;
const randomPattern = /^[a-zA-Z0-9]{8,}$/; // Long strings of alphanumeric characters
const leadingNumbersPattern = /^[0-9][a-zA-Z0-9]{7,}$/; // Starts with a number, followed by alphanumeric characters
const commonGeneratedPatterns = /^(test|user|demo|sample|temp)[0-9]*$/i; // Common generated email patterns
if (excessiveLength || randomPattern.test(localPart) || leadingNumbersPattern.test(localPart) || commonGeneratedPatterns.test(localPart)) {
return true;
}
// Check for local part patterns like many dots or special characters
const unusualPatterns = /[^a-zA-Z0-9._]/; // Characters outside normal email pattern
const tooManyDots = (localPart.match(/\./g) || []).length > 3;
if (unusualPatterns.test(localPart) || tooManyDots) {
return true;
}
return false;
}
module.exports = { isGeneratedEmail };