tests/unit wallace/module_invitationpolicy.py
Thomas Brüderli
bruederli at kolabsys.com
Wed Aug 6 12:10:29 CEST 2014
tests/unit/test-012-wallace_invitationpolicy.py | 24 ++++++++++++------------
wallace/module_invitationpolicy.py | 18 ++++++++----------
2 files changed, 20 insertions(+), 22 deletions(-)
New commits:
commit a921c792c8dfbee3dcc2af9b3dc6f6215692c166
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date: Tue Aug 5 10:51:48 2014 -0400
Compoare full sender email address for matching policies, not only the domain part
diff --git a/tests/unit/test-012-wallace_invitationpolicy.py b/tests/unit/test-012-wallace_invitationpolicy.py
index dbe0713..aabf676 100644
--- a/tests/unit/test-012-wallace_invitationpolicy.py
+++ b/tests/unit/test-012-wallace_invitationpolicy.py
@@ -121,12 +121,12 @@ class TestWallaceInvitationpolicy(unittest.TestCase):
'ACT_REJECT:gmail.com',
'ACT_MANUAL:*'
] }
- self.assertEqual(MIP.get_matching_invitation_policies(user, 'fastmail.net'), [MIP.ACT_MANUAL])
- self.assertEqual(MIP.get_matching_invitation_policies(user, 'example.org'), [MIP.ACT_ACCEPT,MIP.ACT_MANUAL])
- self.assertEqual(MIP.get_matching_invitation_policies(user, 'gmail.com'), [MIP.ACT_REJECT,MIP.ACT_MANUAL])
+ self.assertEqual(MIP.get_matching_invitation_policies(user, 'a at fastmail.net'), [MIP.ACT_MANUAL])
+ self.assertEqual(MIP.get_matching_invitation_policies(user, 'b at example.org'), [MIP.ACT_ACCEPT,MIP.ACT_MANUAL])
+ self.assertEqual(MIP.get_matching_invitation_policies(user, 'c at gmail.com'), [MIP.ACT_REJECT,MIP.ACT_MANUAL])
user = { 'kolabinvitationpolicy': ['ACT_ACCEPT:example.org', 'ACT_MANUAL:others'] }
- self.assertEqual(MIP.get_matching_invitation_policies(user, 'somedomain.net'), [MIP.ACT_MANUAL])
+ self.assertEqual(MIP.get_matching_invitation_policies(user, 'd at somedomain.net'), [MIP.ACT_MANUAL])
def test_004_write_locks(self):
user = { 'cn': 'John Doe', 'mail': "doe at example.org" }
@@ -150,12 +150,12 @@ class TestWallaceInvitationpolicy(unittest.TestCase):
accept_some = [ 'ACT_ACCEPT_IF_NO_CONFLICT', 'ACT_SAVE_TO_CALENDAR:example.org', 'ACT_REJECT_IF_CONFLICT' ]
accept_avail = [ 'ACT_ACCEPT_IF_NO_CONFLICT', 'ACT_REJECT_IF_CONFLICT:example.org' ]
- self.assertFalse( MIP.is_auto_reply({ 'kolabinvitationpolicy':all_manual }, 'domain.org'))
- self.assertTrue( MIP.is_auto_reply({ 'kolabinvitationpolicy':accept_none }, 'domain.org'))
- self.assertTrue( MIP.is_auto_reply({ 'kolabinvitationpolicy':accept_all }, 'domain.com'))
- self.assertTrue( MIP.is_auto_reply({ 'kolabinvitationpolicy':accept_cond }, 'domain.com'))
- self.assertTrue( MIP.is_auto_reply({ 'kolabinvitationpolicy':accept_some }, 'domain.com'))
- self.assertFalse( MIP.is_auto_reply({ 'kolabinvitationpolicy':accept_some }, 'example.org'))
- self.assertFalse( MIP.is_auto_reply({ 'kolabinvitationpolicy':accept_avail }, 'domain.com'))
- self.assertTrue( MIP.is_auto_reply({ 'kolabinvitationpolicy':accept_avail }, 'example.org'))
+ self.assertFalse( MIP.is_auto_reply({ 'kolabinvitationpolicy':all_manual }, 'user at domain.org'))
+ self.assertTrue( MIP.is_auto_reply({ 'kolabinvitationpolicy':accept_none }, 'user at domain.org'))
+ self.assertTrue( MIP.is_auto_reply({ 'kolabinvitationpolicy':accept_all }, 'user at domain.com'))
+ self.assertTrue( MIP.is_auto_reply({ 'kolabinvitationpolicy':accept_cond }, 'user at domain.com'))
+ self.assertTrue( MIP.is_auto_reply({ 'kolabinvitationpolicy':accept_some }, 'user at domain.com'))
+ self.assertFalse( MIP.is_auto_reply({ 'kolabinvitationpolicy':accept_some }, 'sam at example.org'))
+ self.assertFalse( MIP.is_auto_reply({ 'kolabinvitationpolicy':accept_avail }, 'user at domain.com'))
+ self.assertTrue( MIP.is_auto_reply({ 'kolabinvitationpolicy':accept_avail }, 'john at example.org'))
\ No newline at end of file
diff --git a/wallace/module_invitationpolicy.py b/wallace/module_invitationpolicy.py
index 9e0fa37..4796aed 100644
--- a/wallace/module_invitationpolicy.py
+++ b/wallace/module_invitationpolicy.py
@@ -266,8 +266,7 @@ def execute(*args, **kw):
pykolab.translate.setUserLanguage(receiving_user['preferredlanguage'])
# find user's kolabInvitationPolicy settings and the matching policy values
- sender_domain = str(sender_email).split('@')[-1]
- policies = get_matching_invitation_policies(receiving_user, sender_domain)
+ policies = get_matching_invitation_policies(receiving_user, sender_email)
# select a processing function according to the iTip request method
method_processing_map = {
@@ -284,7 +283,7 @@ def execute(*args, **kw):
imap.connect()
for policy in policies:
- log.debug(_("Apply invitation policy %r for domain %r") % (policy_value_map[policy], sender_domain), level=8)
+ log.debug(_("Apply invitation policy %r for sender %r") % (policy_value_map[policy], sender_email), level=8)
done = processor_func(itip_event, policy, recipient_email, sender_email, receiving_user)
# matching policy found
@@ -534,7 +533,7 @@ def user_dn_from_email_address(email_address):
user_dn_from_email_address.cache = {}
-def get_matching_invitation_policies(receiving_user, sender_domain):
+def get_matching_invitation_policies(receiving_user, sender_email):
# get user's kolabInvitationPolicy settings
policies = receiving_user['kolabinvitationpolicy'] if receiving_user.has_key('kolabinvitationpolicy') else []
if policies and not isinstance(policies, list):
@@ -543,7 +542,7 @@ def get_matching_invitation_policies(receiving_user, sender_domain):
if len(policies) == 0:
policies = conf.get_list('wallace', 'kolab_invitation_policy')
- # match policies agains the given sender_domain
+ # match policies agains the given sender_email
matches = []
for p in policies:
if ':' in p:
@@ -552,7 +551,7 @@ def get_matching_invitation_policies(receiving_user, sender_domain):
value = p
domain = ''
- if domain == '' or domain == '*' or sender_domain.endswith(domain):
+ if domain == '' or domain == '*' or str(sender_email).endswith(domain):
value = value.upper()
if policy_name_map.has_key(value):
matches.append(policy_name_map[value])
@@ -870,7 +869,6 @@ def send_reply_notification(event, receiving_user):
organizer = event.get_organizer()
orgemail = organizer.email()
orgname = organizer.name()
- sender_domain = orgemail.split('@')[-1]
auto_replies_expected = 0
auto_replies_received = 0
@@ -894,7 +892,7 @@ def send_reply_notification(event, receiving_user):
if attendee_dn:
attendee_rec = auth.get_entry_attributes(None, attendee_dn, ['kolabinvitationpolicy'])
- if is_auto_reply(attendee_rec, sender_domain):
+ if is_auto_reply(attendee_rec, orgemail):
auto_replies_expected += 1
if not parstat == 'NEEDS-ACTION':
auto_replies_received += 1
@@ -941,10 +939,10 @@ def send_reply_notification(event, receiving_user):
smtp.quit()
-def is_auto_reply(user, sender_domain):
+def is_auto_reply(user, sender_email):
accept_available = False
accept_conflicts = False
- for policy in get_matching_invitation_policies(user, sender_domain):
+ for policy in get_matching_invitation_policies(user, sender_email):
if policy & (ACT_ACCEPT | ACT_REJECT | ACT_DELEGATE):
if check_policy_condition(policy, True):
accept_available = True
More information about the commits
mailing list