Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Over quota validation added #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ const isMultilineGreet = smtpReply => {
return smtpReply && /^(250|220)-/.test(smtpReply);
};

/**
* @param {String} smtpReply A message from the SMTP server.
* @return {Boolean} True if over quota.
*/
const isOverQuota = smtpReply => {
if (
smtpReply &&
/(over quota)/ig.test(smtpReply)
) return true;

return false;
};

class EmailValidator {
constructor(options = { }) {
this.options = Object.assign({
Expand Down Expand Up @@ -139,10 +152,15 @@ class EmailValidator {
log.debug('Mailbox: got data', data);

if (isInvalidMailboxError(data)) return ret(false);

if (isOverQuota(data)) return ret(false);

if (!data.includes(220) && !data.includes(250)) return ret(null);

if (isMultilineGreet(data)) return;



if (messages.length > 0) {
const message = messages.shift();
log.debug('Mailbox: writing message', message);
Expand Down
18 changes: 18 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,24 @@ describe('lib/index', () => {
return self.validator.verify('[email protected]')
.then(({ validMailbox }) => should(validMailbox).equal(null));
});


it('returns false on over quota check', () => {
const msg = '452-4.2.2 The email account that you tried to reach is over quota. Please direct';
const socket = new net.Socket({ });

self.sandbox.stub(socket, 'write').callsFake(function(data) {
if (!data.includes('QUIT')) this.emit('data', msg);
});

self.connectStub.returns(socket);

setTimeout(() => socket.write('250 Foo'), 10);

return self.validator.verify('[email protected]')
.then(({ validMailbox }) => should(validMailbox).equal(false));
});

});

context('given no mx records', () => {
Expand Down