def testFDLeakBug(self): d = util.getAccount(self.config, local='""', domain='', clientFactory=CountingLDAPClient) self.assertFailure(d, ldaperrors.LDAPOther) def cb(e): self.assertEquals(e.message, 'just testing') self.assertEquals(CountingLDAPClient.count, 0) d.addCallback(cb) return d
def _userBelongsToMe(self, user, domain): """ Test whether given user belongs to this backend box. Return a deferred that becomes the box name if he does, fail with SMTPBadRcpt is he does not. """ root=os.path.join(self.proto.factory.spool, domain) d = util.getAccount(config=self.proto.factory.config, local=user.dest.local, domain=domain) d.addCallback(util.getBoxes, config=self.proto.factory.config) def _cbGotBoxes(boxes, root, user, domain): if not boxes: raise smtp.SMTPBadRcpt, ( user+'@'+domain, 550, 'User is not served by any scalemail backend.') for box in boxes: if os.path.isdir(os.path.join(root, box)): # this host serves this backend # -> user belongs to us # -> accept mail return box raise smtp.SMTPBadRcpt, ( user+'@'+domain, 550, 'User is not served by this scalemail backend.') d.addCallback(_cbGotBoxes, root=root, user=user.dest.local, domain=domain) def _setDomain(box, user): user.dest.domain = box + '.' + user.dest.domain return box d.addCallback(_setDomain, user) def _fail(reason): raise smtp.SMTPServerError, (451, 'Error contacting the LDAP server: %s' % reason.getErrorMessage()) d.addErrback(_fail) return d
def _getAccount(self, config, local, domain): return util.getAccount(config, local, domain)