Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
93a9bf437d | |||
a7c6f75cc5 | |||
f67750ff0f | |||
ee25cfc78f |
10478
assets/domains.json
Normal file
10478
assets/domains.json
Normal file
File diff suppressed because it is too large
Load Diff
21
license
Normal file
21
license
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) Lossless GmbH
|
||||||
|
Copyright (c) Romain SIMON
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CON
|
7505
package-lock.json
generated
7505
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
17
package.json
17
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartmail",
|
"name": "@pushrocks/smartmail",
|
||||||
"version": "1.0.16",
|
"version": "1.0.18",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "a unified format for representing and dealing with mails",
|
"description": "a unified format for representing and dealing with mails",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -15,16 +15,17 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.24",
|
"@gitzone/tsbuild": "^2.1.24",
|
||||||
"@gitzone/tsrun": "^1.2.12",
|
"@gitzone/tsrun": "^1.2.12",
|
||||||
"@gitzone/tstest": "^1.0.33",
|
"@gitzone/tstest": "^1.0.43",
|
||||||
"@pushrocks/tapbundle": "^3.2.1",
|
"@pushrocks/tapbundle": "^3.2.9",
|
||||||
"@types/node": "^14.0.13",
|
"@types/node": "^14.0.27",
|
||||||
"tslint": "^6.1.2",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartdns": "^4.0.3",
|
"@pushrocks/smartdns": "^4.0.4",
|
||||||
"@pushrocks/smartfile": "^7.0.12",
|
"@pushrocks/smartfile": "^8.0.0",
|
||||||
"@pushrocks/smartmustache": "^2.0.9"
|
"@pushrocks/smartmustache": "^2.0.9",
|
||||||
|
"@pushrocks/smartrequest": "^1.1.47"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
|
17
test/test.ts
17
test/test.ts
@ -10,6 +10,23 @@ tap.test('should create an instance of EmailAddressValidator', async () => {
|
|||||||
|
|
||||||
tap.test('should validate an email', async () => {
|
tap.test('should validate an email', async () => {
|
||||||
const result = await emailAddressValidatorInstance.validate('sandbox@bleu.de');
|
const result = await emailAddressValidatorInstance.validate('sandbox@bleu.de');
|
||||||
|
expect(result.freemail).to.be.false;
|
||||||
|
expect(result.disposable).to.be.false;
|
||||||
|
console.log(result);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should recognize an email as freemail', async () => {
|
||||||
|
const result = await emailAddressValidatorInstance.validate('sandbox@gmail.com');
|
||||||
|
expect(result.freemail).to.be.true;
|
||||||
|
expect(result.disposable).to.be.false;
|
||||||
|
console.log(result);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should recognize an email as disposable', async () => {
|
||||||
|
const result = await emailAddressValidatorInstance.validate('sandbox@gmx.de');
|
||||||
|
expect(result.freemail).to.be.false;
|
||||||
|
expect(result.disposable).to.be.true;
|
||||||
|
console.log(result);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should create a SmartMail', async () => {
|
tap.test('should create a SmartMail', async () => {
|
||||||
|
@ -1,19 +1,58 @@
|
|||||||
import * as plugins from './smartmail.plugins';
|
import * as plugins from './smartmail.plugins';
|
||||||
|
import * as paths from './smartmail.paths';
|
||||||
|
|
||||||
export interface IEmailValidationResult {
|
export interface IEmailValidationResult {
|
||||||
valid: boolean;
|
valid: boolean;
|
||||||
|
disposable: boolean;
|
||||||
|
freemail: boolean;
|
||||||
reason: string;
|
reason: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class EmailAddressValidator {
|
export class EmailAddressValidator {
|
||||||
|
public domainMap: { [key: string]: 'disposable' | 'freemail'};
|
||||||
|
|
||||||
public smartdns = new plugins.smartdns.Smartdns({});
|
public smartdns = new plugins.smartdns.Smartdns({});
|
||||||
|
|
||||||
public async validate(emailArg: string): Promise<IEmailValidationResult> {
|
public async validate(emailArg: string): Promise<IEmailValidationResult> {
|
||||||
|
await this.fetchDomains();
|
||||||
const emailArray = emailArg.split('@');
|
const emailArray = emailArg.split('@');
|
||||||
const result = await this.smartdns.getRecord(emailArray[1], 'MX');
|
const result = await this.smartdns.getRecord(emailArray[1], 'MX');
|
||||||
|
// console.log(emailArray);
|
||||||
|
// console.log(this.domainMap[emailArray[1]]);
|
||||||
return {
|
return {
|
||||||
valid: !!result,
|
valid: !!result,
|
||||||
reason: 'todo'
|
reason: 'todo',
|
||||||
|
disposable: this.domainMap[emailArray[1]] === 'disposable',
|
||||||
|
freemail: this.domainMap[emailArray[1]] === 'freemail'
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async fetchDomains() {
|
||||||
|
if (!this.domainMap) {
|
||||||
|
const localFileString = plugins.smartfile.fs.toStringSync(
|
||||||
|
plugins.path.join(paths.assetDir, 'domains.json')
|
||||||
|
);
|
||||||
|
const localFileObject = JSON.parse(localFileString);
|
||||||
|
|
||||||
|
|
||||||
|
let onlineFileObject: any;
|
||||||
|
try {
|
||||||
|
onlineFileObject = (
|
||||||
|
await plugins.smartrequest.getJson(
|
||||||
|
'https://raw.githubusercontent.com/romainsimon/emailvalid/master/domains.json'
|
||||||
|
)
|
||||||
|
).body;
|
||||||
|
this.domainMap = onlineFileObject;
|
||||||
|
console.log(
|
||||||
|
'smartmail EmailAddressValidator: Using online email list for email validation'
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
this.domainMap = localFileObject;
|
||||||
|
console.log(e);
|
||||||
|
console.log(
|
||||||
|
'smartmail EmailAddressValidator: Using local email list for email validation'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
4
ts/smartmail.paths.ts
Normal file
4
ts/smartmail.paths.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import * as plugins from './smartmail.plugins';
|
||||||
|
|
||||||
|
export const packageDir = plugins.path.join(__dirname, '../');
|
||||||
|
export const assetDir = plugins.path.join(packageDir, './assets');
|
@ -1,5 +1,14 @@
|
|||||||
|
// node native scope
|
||||||
|
import * as path from 'path';
|
||||||
|
|
||||||
|
export {
|
||||||
|
path
|
||||||
|
};
|
||||||
|
|
||||||
|
// pushrocks scope
|
||||||
import * as smartdns from '@pushrocks/smartdns';
|
import * as smartdns from '@pushrocks/smartdns';
|
||||||
import * as smartfile from '@pushrocks/smartfile';
|
import * as smartfile from '@pushrocks/smartfile';
|
||||||
import * as smartmustache from '@pushrocks/smartmustache';
|
import * as smartmustache from '@pushrocks/smartmustache';
|
||||||
|
import * as smartrequest from '@pushrocks/smartrequest';
|
||||||
|
|
||||||
export { smartdns, smartfile, smartmustache };
|
export { smartdns, smartfile, smartmustache, smartrequest };
|
||||||
|
Reference in New Issue
Block a user