Exemplo n.º 1
0
 def domainExists(self, rawDomain):
     domain = util.quot(rawDomain)
     if os.path.isdir(os.path.join(
         self.config.getSpool(),
         domain)):
         return True
     else:
         return False
Exemplo n.º 2
0
    def get(self, key):
        if '@' not in key:
            box, domain = util.host_split(key)

            if box is not None:
                # box.scalemail.example.com
                # tell postfix this isn't a virtual domain,
                # so it will obey transports
                return

            # example.com or scalemail.example.com
            if domain is None:
                # example.com
                domain = util.quot(key)
            if self.domainExists(domain):
                return 'DOMAINEXISTS'
            else:
                return None
        else:
            local, host = key.split('@', 1)

            if not host:
                # "foo@", no way it'll ever match anything, claim it's
                # not found
                return None

            box, domain = util.host_split(host)

            if box is not None and domain is None:
                raise ScalemailVirtualMapImpossibleDomain, \
                      (key, box, domain)

            if domain is None:
                # [email protected]
                # handle just like [email protected]
                domain = util.quot(host)

            if not self.domainExists(domain):
                # [email protected], where example.com is not known
                return None

            if box is not None:
                # [email protected]
                # no need to rewrite, claim it's not found
                return None

            d = self.callMappers('pre',
                                 config=self.config,
                                 local=local,
                                 domain=domain)
            def _afterPreMappers(answer, callMappers, config, local, domain):
                if answer is not None:
                    return answer
                d = self._getAccount(config, local, domain)

                def _gotAccount(account, callMappers, *a, **kw):
                    d = callMappers('post', account=account, *a, **kw)
                    return d
                d.addCallback(_gotAccount, callMappers, config=self.config, local=local, domain=domain)
                return d
            d.addCallback(_afterPreMappers, self.callMappers, self.config, local, domain)

            def _joinAnswer(answer):
                if answer is not None:
                    answer = ', '.join(answer)
                return answer
            d.addCallback(_joinAnswer)

            def _fail(fail):
                fail.trap(util.ScaleMailAccountNotFound)
                return None
            d.addErrback(_fail)
            return d