'Validate the address from which the message originates.
@type helo: C{(bytes, bytes)}
@param helo: The argument to the HELO command and the client\'s IP
address.
@type origin: C{Address}
@param origin: The address the message is from
@rtype: C{Deferred} or C{Address}
@return: C{origin} or a C{Deferred} whose callback will be
passed C{origin}.
@raise SMTPBadSender: Raised of messages from this address are
not to be accepted.'

def validateFrom(self, helo, origin):

    if (self.deliveryFactory is not None):
        self.delivery = self.deliveryFactory.getMessageDelivery()
    if (self.delivery is not None):
        return defer.maybeDeferred(self.delivery.validateFrom, helo, origin)
    if self.portal:
        result = self.portal.login(cred.credentials.Anonymous(), None, IMessageDeliveryFactory, IMessageDelivery)
        def ebAuthentication(err):
            '\n                                                                Translate    cred    exceptions    into    SMTP    exceptions    so    that    the\n                                                                protocol    code    which    invokes    C{validateFrom}    can    properly    report\n                                                                the    failure.\n                                                                '
            if err.check(cred.error.UnauthorizedLogin):
                exc = SMTPBadSender(origin)
            elif err.check(cred.error.UnhandledCredentials):
                exc = SMTPBadSender(origin, resp='Unauthenticated    senders    not    allowed')
            else:
                return err
            return defer.fail(exc)
        result.addCallbacks(self._cbAnonymousAuthentication, ebAuthentication)
        def continueValidation(ignored):
            '\n                                                                Re-attempt    from    address    validation.\n                                                                '
            return self.validateFrom(helo, origin)
        result.addCallback(continueValidation)
        return result
    raise SMTPBadSender(origin)
