zb-email-verifier
Advanced tools
Comparing version 0.5.3 to 0.6.0
52
index.js
@@ -6,2 +6,3 @@ 'use strict'; | ||
const _ = require('lodash'); | ||
const randomstring = require('randomstring'); | ||
const netsend = require('./lib/netsend'); | ||
@@ -11,7 +12,7 @@ | ||
constructor ( message, extra ) { | ||
super() | ||
Error.captureStackTrace( this, this.constructor ) | ||
this.name = 'CustomError' | ||
this.message = message | ||
if ( extra ) this.extra = extra; | ||
super(); | ||
Error.captureStackTrace( this, this.constructor ); | ||
this.name = 'CustomError'; | ||
this.message = message; | ||
if( extra ) this.extra = extra; | ||
} | ||
@@ -37,10 +38,16 @@ } | ||
const generateRandomEmail = function() { | ||
debug('Domain...', emailHost); | ||
let radomString = randomstring.generate(32); | ||
return radomString + '@' + emailHost; | ||
}; | ||
return new P((resolve, reject) => { | ||
const jobDnsResolveMx = dnsResolveMx(emailHost).then(results => { | ||
if(_.isEmpty(results)) { | ||
throw new VerifyError('','MXRECORD_FAIL'); | ||
throw new VerifyError('', 'MXRECORD_FAIL'); | ||
} | ||
return results; | ||
},() => { | ||
throw new VerifyError('','MXRECORD_FAIL'); | ||
}, () => { | ||
throw new VerifyError('', 'MXRECORD_FAIL'); | ||
}); | ||
@@ -55,3 +62,3 @@ | ||
return netsend({port: 25, host: exchange}).catch(() => { | ||
throw new VerifyError('','CONN_FAIL'); | ||
throw new VerifyError('', 'CONN_FAIL'); | ||
}); | ||
@@ -67,3 +74,3 @@ }); | ||
if(resmsg[0].substr(0, 3) !== '220') { | ||
throw new VerifyError('','VERIFY_FAIL'); | ||
throw new VerifyError('', 'VERIFY_FAIL'); | ||
} | ||
@@ -80,3 +87,3 @@ | ||
if(resmsg[0].substr(0, 3) !== '250') { | ||
throw new VerifyError('','VERIFY_FAIL'); | ||
throw new VerifyError('', 'VERIFY_FAIL'); | ||
} | ||
@@ -93,4 +100,5 @@ | ||
if(resmsg[0].substr(0, 3) !== '250') { | ||
throw new VerifyError('','VERIFY_FAIL'); | ||
throw new VerifyError('', 'VERIFY_FAIL'); | ||
} | ||
const writeMsg = `RCPT TO: <${opts.to}>`; | ||
@@ -104,3 +112,19 @@ debug(writeMsg); | ||
if(resmsg[0].substr(0, 3) === '250') { | ||
return 'EXIST'; | ||
if(opts.catchalltest === true) { | ||
debug('MAILBOX EXIST..CHECKING FOR CATCHALL'); | ||
let randomUser = generateRandomEmail(); | ||
debug('RANDOM USER: ', randomUser); | ||
const writeMsg = `RCPT TO: <${randomUser}>`; | ||
debug(writeMsg); | ||
netConn.write(writeMsg); | ||
return netConn.response().then(resmsg => { | ||
if(resmsg[0].substr(0, 3) === '250') { | ||
return 'CATCH_ALL'; | ||
} else { | ||
return 'EXIST'; | ||
} | ||
}); | ||
} else { | ||
return 'EXIST'; | ||
} | ||
} else { | ||
@@ -116,3 +140,3 @@ return 'NOT_EXIST'; | ||
resolve(results); | ||
}).catch(VerifyError,(err) => { | ||
}).catch(VerifyError, (err) => { | ||
resolve(err.extra); | ||
@@ -119,0 +143,0 @@ }).catch((err) => { |
{ | ||
"name": "zb-email-verifier", | ||
"description": "Promise-based library for verify an email address existence via SMTP", | ||
"version": "0.5.3", | ||
"version": "0.6.0", | ||
"author": { | ||
@@ -26,3 +26,4 @@ "name": "ZIGBANG", | ||
"bluebird": "^3.4.6", | ||
"lodash": "^4.17.2" | ||
"lodash": "^4.17.2", | ||
"randomstring": "^1.1.5" | ||
}, | ||
@@ -29,0 +30,0 @@ "devDependencies": { |
@@ -29,2 +29,3 @@ # zb-email-verifier | ||
// NOT_EXIST - email is not existence | ||
// CATCH_ALL - catch all smtp server | ||
@@ -31,0 +32,0 @@ // MXRECORD_TIMEOUT - resolve mx record timeout |
@@ -12,2 +12,3 @@ 'use strict'; | ||
debug: true, | ||
catchalltest: true, | ||
timeout: 1500 | ||
@@ -32,3 +33,4 @@ }).then(result => { | ||
// NOT_EXIST | ||
// CATCH_ALL | ||
// UNKNOWN | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
235
39
38960
3
20
+ Addedrandomstring@^1.1.5
+ Addedrandombytes@2.0.3(transitive)
+ Addedrandomstring@1.3.0(transitive)