Changeset View
Changeset View
Standalone View
Standalone View
bin/kolab_smtp_access_policy.py
Show First 20 Lines • Show All 178 Lines • ▼ Show 20 Lines | class PolicyRequest(object): | ||||
def __init__(self, policy_request={}): | def __init__(self, policy_request={}): | ||||
""" | """ | ||||
Creates a new policy request object. Pass it a policy_request | Creates a new policy request object. Pass it a policy_request | ||||
dictionary as described in the Postfix documentation on: | dictionary as described in the Postfix documentation on: | ||||
http://www.postfix.org/SMTPD_POLICY_README.html | http://www.postfix.org/SMTPD_POLICY_README.html | ||||
""" | """ | ||||
for key in policy_request.keys(): | for key in policy_request: | ||||
# Normalize email addresses (they may contain recipient delimiters) | # Normalize email addresses (they may contain recipient delimiters) | ||||
if key in self.email_address_keys: | if key in self.email_address_keys: | ||||
policy_request[key] = normalize_address(policy_request[key]) | policy_request[key] = normalize_address(policy_request[key]) | ||||
if not key == 'recipient': | if not key == 'recipient': | ||||
if policy_request[key] == '': | if policy_request[key] == '': | ||||
setattr(self, key, None) | setattr(self, key, None) | ||||
▲ Show 20 Lines • Show All 132 Lines • ▼ Show 20 Lines | def parse_policy(self, _subject, _object, policy): | ||||
if isinstance(policy, basestring): | if isinstance(policy, basestring): | ||||
policy = [policy] | policy = [policy] | ||||
for rule in policy: | for rule in policy: | ||||
# Find rules that are actually special values, simply by | # Find rules that are actually special values, simply by | ||||
# mapping the rule onto a key in "special_rule_values", a | # mapping the rule onto a key in "special_rule_values", a | ||||
# dictionary with the corresponding value set to a function to | # dictionary with the corresponding value set to a function to | ||||
# execute. | # execute. | ||||
if rule in special_rule_values.keys(): | if rule in special_rule_values: | ||||
special_rules = special_rule_values[rule]() | special_rules = special_rule_values[rule]() | ||||
if rule.startswith("-"): | if rule.startswith("-"): | ||||
rules['deny'].extend(special_rules) | rules['deny'].extend(special_rules) | ||||
else: | else: | ||||
rules['allow'].extend(special_rules) | rules['allow'].extend(special_rules) | ||||
continue | continue | ||||
▲ Show 20 Lines • Show All 1,249 Lines • ▼ Show 20 Lines | |||||
def verify_domain(domain): | def verify_domain(domain): | ||||
""" | """ | ||||
Verify whether the domain is internal (mine) or external. | Verify whether the domain is internal (mine) or external. | ||||
""" | """ | ||||
global auth, mydomains | global auth, mydomains | ||||
if mydomains is not None: | if mydomains is not None: | ||||
return domain in mydomains.keys() | return domain in mydomains | ||||
auth.connect() | auth.connect() | ||||
domain_verified = False | domain_verified = False | ||||
mydomains = auth.list_domains() | mydomains = auth.list_domains() | ||||
if mydomains is not None and domain in mydomains: | if mydomains is not None and domain in mydomains: | ||||
▲ Show 20 Lines • Show All 117 Lines • Show Last 20 Lines |