def validateFrom(self, helo, origin): if not helo: raise smtp.SMTPBadSender(origin, 503, "Who are you? Say HELO first.") if origin.local != '' and origin.domain == '': raise smtp.SMTPBadSender(origin, 501, "Sender address must contain domain.") return origin
def validateFrom(self, helo, origin): log.msg("validateFrom(): %s" % origin) if not helo: raise smtp.SMTPBadSender(origin, 503, "Who are you? Say HELO first.") if origin.local != '': # if local user self.orig_is_local = True # a flag that validateTo will use. log.msg("DEBUG: setting orig_is_local=True") if origin.local != '' and origin.domain == '': raise smtp.SMTPBadSender(origin, 501, "Sender address must contain domain.") return origin
def validateFrom(self, helo, origin): """ Validate the address from which the message originates. :param helo: The argument to the HELO command and the client's IP address. :type: (str, str) :param origin: The address the message is from. :type origin: twisted.mail.smtp.Address @return: origin or a Deferred whose callback will be passed origin. @rtype: Deferred or Address @raise twisted.mail.smtp.SMTPBadSender: Raised if messages from this address are not to be accepted. """ # accept mail from anywhere. To reject an address, raise # smtp.SMTPBadSender here. if str(origin) != str(self._userid): logger.error( "Rejecting sender {0}, expected {1}".format(origin, self._userid)) raise smtp.SMTPBadSender(origin) self._origin = origin return origin
def validateFrom(self, helo, origin): if str( origin ) not in BLACKLIST_ADDRESSES and origin.domain not in BLACKLIST_HOSTS: return origin else: raise smtp.SMTPBadSender(origin)
def validateFrom(self, helo, originAddress): myHostname, clientIP = helo if self._allow_all or str(clientIP) in self._whitelist: return originAddress self.__logger__.error('Sender not whitelisted') self.__logger__.error('offending IP: ' + str(clientIP)) raise smtp.SMTPBadSender(originAddress)
def validateFrom(self, helo, origin): """ Verify that the given origin address is one this user is allowed to claim. """ for local, domain in userbase.getAccountNames(self.avatar.store): if local == origin.local and domain == origin.domain: self.origin = origin return defer.succeed(origin) return defer.fail(smtp.SMTPBadSender(origin))
def validateFrom(self, helo, origin): """Validate the ``MAIL FROM:`` address on the incoming SMTP connection. This is done at the SMTP layer. Meaning that if a Postfix or other email server is proxying emails from the outside world to BridgeDB, the :api:`origin.domain <twisted.email.smtp.Address.domain>` will be set to the local hostname. Therefore, if the SMTP ``MAIL FROM:`` domain name is our own hostname (as returned from :func:`socket.gethostname`) or our own FQDN, allow the connection. Otherwise, if the ``MAIL FROM:`` domain has a canonical domain in our mapping (taken from our :data:`context.canon`, which is taken in turn from the ``EMAIL_DOMAIN_MAP``), then our :data:`fromCanonicalSMTP` is set to that domain. :type helo: tuple :param helo: The lines received during SMTP client HELO. :type origin: :api:`twisted.mail.smtp.Address` :param origin: The email address we received this message from. :raises: :api:`twisted.mail.smtp.SMTPBadSender` if the ``origin.domain`` was neither our local hostname, nor one of the canonical domains listed in :attr:`context.canon`. :rtype: :api:`twisted.mail.smtp.Address` :returns: The ``origin``. We *must* return some non-``None`` data from this method, or else Twisted will reply to the sender with a 503 error. """ try: if str(origin) in self.context.whitelist.keys(): logging.warn("Got SMTP 'MAIL FROM:' whitelisted address: %s." % str(origin)) # We need to be certain later that when the fromCanonicalSMTP # domain is checked again the email 'From:' canonical domain, # that we allow whitelisted addresses through the check. self.fromCanonicalSMTP = origin.domain return origin if ((origin.domain == self.context.hostname) or (origin.domain == smtp.DNSNAME)): self.fromCanonicalSMTP = origin.domain else: logging.debug("Canonicalizing client SMTP domain...") canonical = canonicalizeEmailDomain(origin.domain, self.context.canon) logging.debug("Canonical SMTP domain: %r" % canonical) self.fromCanonicalSMTP = canonical except UnsupportedDomain as error: logging.info(error) raise smtp.SMTPBadSender(origin) except Exception as error: logging.exception(error) # This method **cannot** return None, or it'll cause a 503 error. return origin
def validateFrom(self, helo, origin): """ Validate the address from which a message originates. @type helo: 2-L{tuple} of (L{bytes}, L{bytes}) @param helo: The client's identity as sent in the HELO command and its IP address. @type origin: L{Address} @param origin: The origination address of the message. @rtype: L{Address} @return: The origination address. @raise SMTPBadSender: When messages cannot be accepted from the origination address. """ if not helo: raise smtp.SMTPBadSender(origin, 503, "Who are you? Say HELO first.") if origin.local != b"" and origin.domain == b"": raise smtp.SMTPBadSender(origin, 501, "Sender address must contain domain.") return origin
def validateFrom(self, helo, origin): self.logger.info( 'validateFrom: helo={helo!r} origin={origin!r}', helo=helo, origin=origin, ) accessToken = yield self.mailerFactory.tokenAcquirer.acquirePassword( str(origin), ) if accessToken is None: self.logger.error('accessToken cannot be acquired') raise smtp.SMTPBadSender(origin) self.logger.info('accessToken can be acquired') self.mailer = self.mailerFactory.createMailer(str(origin)) returnValue(origin)
def validateFrom(self, helo, origin): raise smtp.SMTPBadSender(origin)
def validateFrom(self, helo, origin): if origin.domain in userbase.getDomainNames(self.store): return defer.fail(smtp.SMTPBadSender(origin)) return defer.succeed(origin)
def validateFrom(self, helo, origin): if origin.domain != self.postbox: raise smtp.SMTPBadSender(origin) return origin