diff --git a/lib/index.js b/lib/index.js index 7bd7b9a..7a081d6 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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({ @@ -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); diff --git a/test/index.js b/test/index.js index c7a9fbd..a9c0e94 100644 --- a/test/index.js +++ b/test/index.js @@ -230,6 +230,24 @@ describe('lib/index', () => { return self.validator.verify('bar@foo.com') .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('bar@foo.com') + .then(({ validMailbox }) => should(validMailbox).equal(false)); + }); + }); context('given no mx records', () => {