summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2014-12-23 10:51:38 +0100
committerThomas Bruederli <bruederli@kolabsys.com>2014-12-23 10:51:38 +0100
commite99f7c72196969fdda36c801c953662b84bd10b1 (patch)
treee7dac1f4320306ba792bfdfed3a86e86ef61e491
parent856a2aa11f6d1d661eacbf9e4f34c92d23a2f4ce (diff)
downloadpykolab-e99f7c72196969fdda36c801c953662b84bd10b1.tar.gz
Consider all valid recipient email addresses, including aliases, when identifying attendees in iTip messages (#4074)
-rw-r--r--pykolab/auth/__init__.py6
-rw-r--r--pykolab/auth/ldap/__init__.py28
-rw-r--r--wallace/module_invitationpolicy.py13
3 files changed, 44 insertions, 3 deletions
diff --git a/pykolab/auth/__init__.py b/pykolab/auth/__init__.py
index 86479ce..cba3b62 100644
--- a/pykolab/auth/__init__.py
+++ b/pykolab/auth/__init__.py
@@ -216,6 +216,12 @@ class Auth(pykolab.base.Base):
def find_user_dn(self, login, kolabuser=False):
return self._auth._find_user_dn(login, kolabuser);
+ def list_recipient_addresses(self, user):
+ return self._auth.list_recipient_addresses(user)
+
+ def extract_recipient_addresses(self, entry):
+ return self._auth.extract_recipient_addresses(entry)
+
def list_domains(self, domain=None):
"""
List the domains using the auth_mechanism setting in the kolab
diff --git a/pykolab/auth/ldap/__init__.py b/pykolab/auth/ldap/__init__.py
index 33f3f8e..0b51a74 100644
--- a/pykolab/auth/ldap/__init__.py
+++ b/pykolab/auth/ldap/__init__.py
@@ -402,6 +402,34 @@ class LDAP(pykolab.base.Base):
return utils.normalize(_entry_attrs)
+ def list_recipient_addresses(self, entry_id):
+ """
+ Give a list of all valid recipient addresses for an LDAP entry
+ identified by its ID.
+ """
+ mail_attributes = conf.get_list('ldap', 'mail_attributes')
+ entry = self.get_entry_attributes(entry_id, mail_attributes)
+
+ return self.extract_recipient_addresses(entry) if entry is not None else []
+
+ def extract_recipient_addresses(self, entry):
+ """
+ Extact a list of all valid recipient addresses for the given LDAP entry.
+ This includes all attributes configured for ldap.mail_attributes
+ """
+ recipient_addresses = []
+ mail_attributes = conf.get_list('ldap', 'mail_attributes')
+
+ for attr in mail_attributes:
+ if entry.has_key(attr):
+ if isinstance(entry[attr], list):
+ recipient_addresses.extend(entry[attr])
+ elif isinstance(entry[attr], basestring):
+ recipient_addresses.append(entry[attr])
+
+ return recipient_addresses
+
+
def find_recipient(self, address="*", exclude_entry_id=None):
"""
Given an address string or list of addresses, find one or more valid
diff --git a/wallace/module_invitationpolicy.py b/wallace/module_invitationpolicy.py
index 6adf82d..1cf78a7 100644
--- a/wallace/module_invitationpolicy.py
+++ b/wallace/module_invitationpolicy.py
@@ -247,6 +247,7 @@ def execute(*args, **kw):
any_itips = False
recipient_email = None
+ recipient_emails = []
recipient_user_dn = None
# An iTip message may contain multiple events. Later on, test if the message
@@ -271,7 +272,10 @@ def execute(*args, **kw):
for recipient in recipients:
recipient_user_dn = user_dn_from_email_address(recipient)
if recipient_user_dn:
+ receiving_user = auth.get_entry_attributes(None, recipient_user_dn, ['*'])
+ recipient_emails = auth.extract_recipient_addresses(receiving_user)
recipient_email = recipient
+ log.debug(_("Recipient emails for %s: %r") % (recipient_user_dn, recipient_emails), level=8)
break
if not any_itips:
@@ -286,12 +290,13 @@ def execute(*args, **kw):
# for replies, the organizer is the recipient
if itip_event['method'] == 'REPLY':
- user_attendees = [itip_event['organizer']] if str(itip_event['organizer']).split(':')[-1] == recipient_email else []
+ organizer_mailto = str(itip_event['organizer']).split(':')[-1]
+ user_attendees = [organizer_mailto] if organizer_mailto in recipient_emails else []
else:
# Limit the attendees to the one that is actually invited with the current message.
attendees = [str(a).split(':')[-1] for a in (itip_event['attendees'] if itip_event.has_key('attendees') else [])]
- user_attendees = [a for a in attendees if a == recipient_email]
+ user_attendees = [a for a in attendees if a in recipient_emails]
if itip_event.has_key('organizer'):
sender_email = itip_event['xml'].get_organizer().email()
@@ -301,9 +306,11 @@ def execute(*args, **kw):
log.info(_("No user attendee matching envelope recipient %s, skip message") % (recipient_email))
return filepath
- receiving_user = auth.get_entry_attributes(None, recipient_user_dn, ['*'])
log.debug(_("Receiving user: %r") % (receiving_user), level=8)
+ # set recipient_email to the matching attendee mailto: address
+ recipient_email = user_attendees[0]
+
# change gettext language to the preferredlanguage setting of the receiving user
if receiving_user.has_key('preferredlanguage'):
pykolab.translate.setUserLanguage(receiving_user['preferredlanguage'])