Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

email-existence

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

email-existence - npm Package Compare versions

Comparing version 0.1.5 to 0.1.6

119

index.js
var dns = require('dns'),
net = require('net'),
os = require('os');
os = require('os'),
async = require('async');

@@ -8,2 +9,13 @@ module.exports = function (email, callback, timeout, from_email) {

from_email = from_email || email;
/* Does it look like a valid email? */
/* Our email regex is vulnerable to REDOS on very large input.
* Valid emails shouldn't be more than 300 characters anyway.
* https://www.rfc-editor.org/errata_search.php?eid=1690 */
const MAX_EMAIL_LEN = 300;
if (MAX_EMAIL_LEN < email.length) {
callback(null, false);
return;
}
if (!/^\S+@\S+$/.test(email)) {

@@ -13,2 +25,3 @@ callback(null, false);

}
dns.resolveMx(email.split('@')[1], function(err, addresses){

@@ -19,45 +32,71 @@ if (err || addresses.length === 0) {

}
var conn = net.createConnection(25, addresses[0].exchange);
var commands = [ "helo " + addresses[0].exchange, "mail from: <"+from_email+">", "rcpt to: <"+email+">" ];
var i = 0;
conn.setEncoding('ascii');
conn.setTimeout(timeout);
conn.on('error', function() {
conn.emit('false');
});
conn.on('false', function () {
callback(err, false);
conn.removeAllListeners();
});
conn.on('connect', function() {
conn.on('prompt', function () {
if(i < 3){
conn.write(commands[i]);
conn.write('\r\n');
i++;
} else {
callback(err, true);
conn.removeAllListeners();
conn.destroy(); //destroy socket manually
}
addresses = addresses.sort(function (a,b) {
return a.priority - b.priority
})
var res,undetermined;
var cond = false, j =0;
async.doWhilst(function (done) {
var conn = net.createConnection(25, addresses[j].exchange);
var commands = [ "helo " + addresses[j].exchange, "mail from: <"+from_email+">", "rcpt to: <"+email+">" ];
// console.log(commands);
var i = 0;
conn.setEncoding('ascii');
conn.setTimeout(timeout);
conn.on('error', function() {
conn.emit('false');
});
conn.on('undetermined', function () {
//in case of an unrecognisable response tell the callback we're not sure
callback(err, false, true);
conn.on('false', function () {
res = false
undetermined = false;
cond = false;
done(err, false);
conn.removeAllListeners();
conn.destroy(); //destroy socket manually
conn.destroy();
});
conn.on('timeout', function () {
conn.emit('undetermined');
conn.on('connect', function() {
conn.on('prompt', function () {
if(i < 3){
conn.write(commands[i]);
conn.write('\r\n');
i++;
} else {
res = true;
undetermined = false;
cond = false;
done(err, true);
conn.removeAllListeners();
conn.destroy(); //destroy socket manually
}
});
conn.on('undetermined', function () {
j++;
//in case of an unrecognisable response tell the callback we're not sure
cond = true;
res = false;
undetermined = true;
done(err, false, true);
conn.removeAllListeners();
conn.destroy(); //destroy socket manually
});
conn.on('timeout', function () {
conn.emit('undetermined');
});
conn.on('data', function(data) {
if(data.indexOf("220") == 0 || data.indexOf("250") == 0 || data.indexOf("\n220") != -1 || data.indexOf("\n250") != -1) {
conn.emit('prompt');
} else if(data.indexOf("\n550") != -1 || data.indexOf("550") == 0) {
conn.emit('false');
} else {
conn.emit('undetermined');
}
});
});
conn.on('data', function(data) {
if(data.indexOf("220") == 0 || data.indexOf("250") == 0 || data.indexOf("\n220") != -1 || data.indexOf("\n250") != -1) {
conn.emit('prompt');
} else if(data.indexOf("\n550") != -1 || data.indexOf("550") == 0) {
conn.emit('false');
} else {
conn.emit('undetermined');
}
});
});
}, function () {
return j < addresses.length && cond
},function (err) {
callback(err, res, undetermined);
})
});

@@ -64,0 +103,0 @@ };

{
"author": "Nicholas Manousos <nmanousos@gmail.com>",
"contributors": [
"scippio <scippio@2ants.eu>"
],
"name": "email-existence",

@@ -11,10 +14,10 @@ "description": "Checks existence of email addresses",

],
"version": "0.1.5",
"version": "0.1.6",
"repository": {
"type": "git",
"url": "git://github.com/nmanousos/email-existence.git"
"url": "https://github.com/scippio/email-existence.git"
},
"bugs": "http://github.com/nmanousos/email-existence/issues",
"bugs": "http://github.com/scippio/email-existence/issues",
"scripts": {
"test": "mocha"
"test": "mocha --reporter spec"
},

@@ -24,3 +27,6 @@ "devDependencies": {

"mocha": "~1.9.0"
},
"dependencies": {
"async": "^2.0.0-rc.6"
}
}

@@ -19,7 +19,7 @@ # email-existence

```
emailExistence.check('email@domain.com', function(err,res){
console.log('res: '+res);
emailExistence.check('email@domain.com', function(error, response){
console.log('res: '+response);
});
```
* The check function will return a boolean to indicate existence of an email address. Existence is determined by telnetting to the MX server of the email domain and attempting to send an email to the supplied address. MX servers return 250 if the email address exists and 550 if it does not. This test email is not ever sent.
* The check function will return a boolean in response callback function to indicate existence of an email address. Existence is determined by telnetting to the MX server of the email domain and attempting to send an email to the supplied address. MX servers return 250 if the email address exists and 550 if it does not. This test email is not ever sent.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc