Beispiel #1
0
    def test_create(self):
        class A:
            NAME = 'a'

        class B(A):
            NAME = 'b'

        class C(B):
            NAME = 'c'

        expected = {
            'a': A,
            'b': B,
            'c': C,
        }
        actual = lookup.make_lookup_table(A, 'NAME')
        self.assertEqual(expected, actual)
Beispiel #2
0
        cfg,
    ):
        super().__init__(rule_data, cfg)
        self._age = rule_data['time-limit']['age']

    def check(self, message):
        date = parsedate_to_datetime(i18n.get_header_value(message, 'date'))
        if self._age:
            time_limit = datetime.now() - timedelta(days=self._age)
            if date <= time_limit:
                return True
            else:
                return 0


_lookup_table = lookup.make_lookup_table(Rule, 'NAME')


def factory(rule_data, cfg):
    """Create a rule processor.

    :param rule_data: portion of configuration describing the rule
    :type rule_data: dict
    :param cfg: full configuration data
    :type cfg: dict

    Using the rule type, instantiate a rule processor that can check
    the rule against a message.

    """
    for key in rule_data:
Beispiel #3
0
    NAME = 'delete'
    _log = logging.getLogger(NAME)

    def report(self, conn, mailbox_name, message_id, message):
        self._log.info('%s (%s)', message_id,
                       i18n.get_header_value(message, 'subject'))

    def invoke(self, conn, mailbox_name, message_id, message):
        conn.delete_message(
            mailbox_name,
            message_id,
            message,
        )


_lookup_table = lookup.make_lookup_table(Action, 'NAME')


def factory(action_data, cfg):
    """Create an Action instance.

    :param action_data: portion of configuration describing the action
    :type action_data: dict
    :param cfg: full configuration data
    :type cfg: dict

    Using the action type, instantiate an action object that can
    process a message.

    """
    name = action_data.get('name')