Exemplo n.º 1
0
    def rcpt(self, line):
        """
        This method handles the RCPT command parsing and checking of the
        recipient.

        :param line: The rest of the command line
        :type line: str
        """

        if not self.transaction and self.transaction.sender:
            return 503, 'Use MAIL before RCPT'

        log.info('full to_parameter: %s', line)

        try:
            addr, _params = parse_command('rcpt', line)
        except error.HookError as e:
            return 501, e.message or 'Syntax error in command'

        #msg = self.run_hooks('rcpt_parse', line)

        params = {}
        for param in _params:
            try:
                key, value = param.split('=')
            except:
                pass
            else:
                params[key.lower()] = value

        tnx = self.transaction
        try:
            addr = self.run_hooks('rcpt_pre', tnx, addr) or addr
        except error.HookError as e:
            pass

        log.debug('to email address: [%s]', addr)

        try:
            msg = self.run_hooks('rcpt', tnx, addr)

        except error.StopHooksError as e:
            return

        except error.HookError as e:
            return (450 if e.soft else 550,
                    e.message or 'relaying denied',
                    e.disconnect)
        else:
            #if not msg:
            #    return self.send_code(450,
            #        'No plugin decided if relaying is allowed')

            self.transaction.add_recipient(addr)
            return 250, '%s, recipient ok' % addr
Exemplo n.º 2
0
    def mail(self, line):
        """
        This method handles the MAIL command in the SMTP transaction.

        :param line: The rest of the command line
        :type line: str
        """

        if not self.hello:
            return 503, "Manners? You haven't said hello..."

        self.reset_transaction()
        log.info('full from_parameter: %s', line)

        # Disable until more operational, parsing hooks will be the last
        # hooks implemented.
        #
        #try:
        #    (from_addr, params) = self.run_hooks('mail_parse', line)
        #except error.HookError as e:
        #    self.send_syntax_error()
        #except Exception as e:
        #    pass
        #else:
        #    pass
        try:
            addr, _params = parse_command('mail', line)
        except error.HookError as e:
            return 501, e.message or 'Syntax error in command'

        params = {}
        for param in _params:
            try:
                key, value = param.split('=')
            except:
                pass
            else:
                params[key.lower()] = value

        # Check to see if the reported message size is too large for us and delay early if so
        if 'size' in params:
            try:
                size = int(params['size'])
            except TypeError:
                size = 0

            size_limit = self.config.getint('size_limit')
            if self.hello == 'ehlo' and size_limit < size:
                log.info('Message too large to receive, declining')
                return 552, 'Message too big!'

        tnx = self.transaction
        try:
            addr = self.run_hooks('mail_pre', tnx, addr, params) or addr
        except error.HookError as e:
            pass

        log.debug('from email address: [%s]', addr)

        # Turn addr into an Address object now
        addr = Address(addr)

        try:
            msg = self.run_hooks('mail', tnx, addr, params)
        except error.HookError as e:
            return 450 if e.soft else 550, e.message, e.disconnect

        log.info('getting from from %s', addr)
        tnx.sender = addr
        return (250,
                '%s sender OK - how exciting to get mail from you!' % addr)