def add_queue_policies(queue, policy_options): for policy in policy_options: if policy.type == 'add_date_header': queue.add_policy(AddDateHeader()) elif policy.type == 'add_messageid_header': hostname = policy.hostname queue.add_policy(AddMessageIdHeader(hostname)) elif policy.type == 'add_received_header': queue.add_policy(AddReceivedHeader()) elif policy.type == 'recipient_split': queue.add_policy(RecipientSplit()) elif policy.type == 'recipient_domain_split': queue.add_policy(RecipientDomainSplit()) elif policy.type == 'lookup': lookup = load_lookup(policy.get('lookup', {})) on_sender = policy.get('on_sender', False) on_rcpts = policy.get('on_recipients', True) if lookup: lookup_policy = LookupPolicy(lookup, on_sender=on_sender, on_rcpts=on_rcpts) queue.add_policy(lookup_policy) else: msg = 'Incomplete lookup policy section' raise ConfigValidationError(msg) elif policy.type == 'forward': forward = Forward() for pattern, repl in dict(policy.get('mapping', {})).items(): forward.add_mapping(pattern, repl) queue.add_policy(forward) elif policy.type == 'spamassassin': queue.add_policy(_get_spamassassin_object(policy))
def test_shortcircuit(self): env = Envelope('*****@*****.**', ['*****@*****.**']) fwd = Forward() fwd.add_mapping(r'^rcpt', 'test') fwd.add_mapping(r'^example', 'testdomain') fwd.apply(env) self.assertEqual('*****@*****.**', env.sender) self.assertEqual(['*****@*****.**'], env.recipients)
def test_simple(self): env = Envelope('*****@*****.**', ['*****@*****.**', '*****@*****.**']) fwd = Forward() fwd.add_mapping(r'^rcpt', 'test') fwd.add_mapping(r'test\.com$', 'example.com') fwd.apply(env) assert_equal('*****@*****.**', env.sender) assert_equal(['*****@*****.**', '*****@*****.**'], env.recipients)
def add_queue_policies(queue, policy_options): for policy in policy_options: if policy.type == 'add_date_header': queue.add_policy(AddDateHeader()) elif policy.type == 'add_messageid_header': hostname = policy.get('hostname') queue.add_policy(AddMessageIdHeader(hostname)) elif policy.type == 'add_received_header': queue.add_policy(AddReceivedHeader()) elif policy.type == 'recipient_split': queue.add_policy(RecipientSplit()) elif policy.type == 'recipient_domain_split': queue.add_policy(RecipientDomainSplit()) elif policy.type == 'forward': forward = Forward() for pattern, repl in dict(policy.get('mapping', {})).items(): forward.add_mapping(pattern, repl) queue.add_policy(forward) elif policy.type == 'spamassassin': queue.add_policy(_get_spamassassin_object(policy))
def test_simple(self): env = Envelope('*****@*****.**', ['*****@*****.**', '*****@*****.**']) fwd = Forward() fwd.add_mapping(r'^rcpt', 'test') fwd.add_mapping(r'test\.com$', 'example.com') fwd.apply(env) self.assertEqual('*****@*****.**', env.sender) self.assertEqual(['*****@*****.**', '*****@*****.**'], env.recipients)
def test_no_matches(self): env = Envelope('*****@*****.**', ['*****@*****.**']) fwd = Forward() fwd.add_mapping(r'nomatch', 'test') fwd.apply(env) self.assertEqual('*****@*****.**', env.sender) self.assertEqual(['*****@*****.**'], env.recipients)
def add_queue_policies(queue, policy_options): for policy in policy_options: if policy.type == 'add_date_header': queue.add_policy(AddDateHeader()) elif policy.type == 'add_messageid_header': hostname = policy.get('hostname') queue.add_policy(AddMessageIdHeader(hostname)) elif policy.type == 'add_received_header': queue.add_policy(AddReceivedHeader()) elif policy.type == 'recipient_split': queue.add_policy(RecipientSplit()) elif policy.type == 'recipient_domain_split': queue.add_policy(RecipientDomainSplit()) elif policy.type == 'forward': forward = Forward() for pattern, repl in dict(policy.get('mappings', {})).items(): forward.add_mapping(pattern, reply) queue.add_policy(forward) elif policy.type == 'spamassassin': host = policy.get('host', 'localhost') port = int(policy.get('port', 783)) queue.add_policy(SpamAssassin((host, port)))
def test_no_mappings(self): env = Envelope('*****@*****.**', ['*****@*****.**']) fwd = Forward() fwd.apply(env) assert_equal('*****@*****.**', env.sender) assert_equal(['*****@*****.**'], env.recipients)