예제 #1
0
파일: smtp.py 프로젝트: tv42/scalemail
    def validateTo(self, user):
        if not user.dest.domain:
            raise smtp.SMTPBadRcpt, (user, 550, 'No domain name given')

        # test whether such host dir exists
        box, domain=util.host_split(user.dest.domain)

        if domain is None:
            raise smtp.SMTPBadRcpt, (user, 550, 'Invalid domain name given: %r' % user.dest.domain)

        if box is None:
            d = self._userBelongsToMe(user, domain)
        else:
            d = defer.succeed(box)

        d.addCallback(self._cbGotBox, domain, user)
        return d
예제 #2
0
파일: respond.py 프로젝트: tv42/scalemail
def prepare(msg, reply, recipient=None, recipientName=None, subjectPrefix=None):
    sender = goneutil.getSender(msg)

    if "From" not in reply and recipient is not None:
        if "@" in recipient:
            local, host = recipient.split("@", 1)
            box, domain = util.host_split(host)
            if domain is not None:
                host = domain
            recipient = str(smtp.Address(local, host))
        reply["From"] = email.Utils.formataddr((recipientName, recipient))

    to = msg.get_all("Sender", None)
    if to is None:
        to = msg.get_all("From", None)
    if to is None:
        to = [sender]
    for addr in to:
        reply["To"] = addr

    if "Subject" not in reply:
        subject = msg["Subject"]
        if subject is None:
            # echo foo | mail testaccount has no subject, if vacation
            # message has no subject either, sees this.. ugly due to
            # lack of l10n
            subject = "Your mail"
        if subjectPrefix is not None:
            subject = subjectPrefix + subject
        reply["Subject"] = subject

    msgid = msg.get("Message-ID", None)
    if msgid is not None:
        msgid = msgid.strip()
        reply["In-Reply-To"] = msgid

    if reply.is_multipart():
        reply.attach(MIMEMessage(msg))
    return reply
예제 #3
0
파일: virtual.py 프로젝트: tv42/scalemail
    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