6 commits - pykolab/auth pykolab/plugins pykolab/utils.py

Jeroen van Meeuwen vanmeeuwen at kolabsys.com
Thu May 16 20:45:15 CEST 2013


 pykolab/auth/ldap/__init__.py               |   21 ++++++++++++++++++++-
 pykolab/plugins/recipientpolicy/__init__.py |   24 ++++++++++++++++++------
 pykolab/utils.py                            |    3 +++
 3 files changed, 41 insertions(+), 7 deletions(-)

New commits:
commit fdf323657d2ccb3dcb3b77bed091707b2dfc0c23
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Thu May 16 20:43:18 2013 +0200

    pykolab/utils really cannot deal with a list of primary mail attribute values

diff --git a/pykolab/utils.py b/pykolab/utils.py
index b0de166..5cba8f9 100644
--- a/pykolab/utils.py
+++ b/pykolab/utils.py
@@ -321,6 +321,9 @@ def normalize(_object):
             result['surname'] = result['sn'].replace(' ', '')
 
         if result.has_key('mail'):
+            if isinstance(result['mail'], list):
+                result['mail'] = result['mail'][0]
+
             if len(result['mail']) > 0:
                 if len(result['mail'].split('@')) > 1:
                     result['domain'] = result['mail'].split('@')[1]


commit 2086e982f410d70c11a9da7eb463cd1b917c8175
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Thu May 16 20:42:57 2013 +0200

    Catch the cases where a recipient policy fails

diff --git a/pykolab/plugins/recipientpolicy/__init__.py b/pykolab/plugins/recipientpolicy/__init__.py
index 4a19132..6ca70ef 100644
--- a/pykolab/plugins/recipientpolicy/__init__.py
+++ b/pykolab/plugins/recipientpolicy/__init__.py
@@ -121,7 +121,14 @@ class KolabRecipientpolicy(object):
         _domains = [ kw['primary_domain'] ] + kw['secondary_domains']
 
         for attr in [ 'givenname', 'sn', 'surname' ]:
-            user_attrs[attr] = utils.translate(user_attrs[attr], user_attrs['preferredlanguage'])
+            try:
+                user_attrs[attr] = utils.translate(user_attrs[attr], user_attrs['preferredlanguage'])
+            except Exception, errmsg:
+                log.error(_("An error occurred in composing the secondary mail attribute for entry %r") % (user_attrs['id']))
+                if conf.debuglevel > 8:
+                    import traceback
+                    traceback.print_exc()
+                return []
 
         for number in alternative_mail_routines.keys():
             for routine in alternative_mail_routines[number].keys():
@@ -131,8 +138,12 @@ class KolabRecipientpolicy(object):
                     log.debug(_("Appending additional mail address: %s") % (retval), level=8)
                     alternative_mail.append(retval)
 
-                except KeyError, e:
-                    log.warning(_("Attribute substitution for 'alternative_mail' failed in Recipient Policy"))
+                except Exception, errmsg:
+                    log.error(_("Policy for secondary email address failed: %r") % (errmsg))
+                    if conf.debuglevel > 8:
+                        import traceback
+                        traceback.print_exc()
+                    return []
 
                 for _domain in kw['secondary_domains']:
                     user_attrs['domain'] = _domain


commit 576a71426204e91a9d55a788df30babf9f6e848a
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Thu May 16 20:42:17 2013 +0200

    Be a little more verbose about what exactly goes wrong when we catch the exception

diff --git a/pykolab/auth/ldap/__init__.py b/pykolab/auth/ldap/__init__.py
index 97ff4df..441153a 100644
--- a/pykolab/auth/ldap/__init__.py
+++ b/pykolab/auth/ldap/__init__.py
@@ -2441,7 +2441,11 @@ class LDAP(pykolab.base.Base):
 
                 break
 
-            except:
+            except Exception, errmsg:
+                log.error(_("An error occured using %s: %r") % (supported_control, errmsg))
+                if conf.debuglevel > 8:
+                    import traceback
+                    traceback.print_exc()
                 continue
 
         return _results


commit 62884c68f77046eb0e18075f0e0bd78c4e37eb8e
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Thu May 16 20:00:37 2013 +0200

    Return user_attrs['mail'], which exists, while mail is not set

diff --git a/pykolab/plugins/recipientpolicy/__init__.py b/pykolab/plugins/recipientpolicy/__init__.py
index 8ea2c89..4a19132 100644
--- a/pykolab/plugins/recipientpolicy/__init__.py
+++ b/pykolab/plugins/recipientpolicy/__init__.py
@@ -78,7 +78,7 @@ class KolabRecipientpolicy(object):
         except KeyError, e:
             log.warning(_("Attribute substitution for 'mail' failed in Recipient Policy"))
             if user_attrs.has_key('mail'):
-                return mail
+                return user_attrs['mail']
             else:
                 return None
 


commit 744c3f038b4befea35e4dad67acb0a42d1a10dd1
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Thu May 16 19:44:43 2013 +0200

    Make sure a non-existent result attribute value does not result in an attempt to create a mailbox

diff --git a/pykolab/auth/ldap/__init__.py b/pykolab/auth/ldap/__init__.py
index 1c41924..97ff4df 100644
--- a/pykolab/auth/ldap/__init__.py
+++ b/pykolab/auth/ldap/__init__.py
@@ -1185,6 +1185,9 @@ class LDAP(pykolab.base.Base):
         if entry[result_attribute] == None:
             return
 
+        if entry[result_attribute] == '':
+            return
+
         cache.get_entry(self.domain, entry)
 
         self.imap.connect(domain=self.domain)
@@ -1316,6 +1319,15 @@ class LDAP(pykolab.base.Base):
             for key in entry_changes.keys():
                 entry[key] = entry_changes[key]
 
+            if not entry.has_key(result_attribute):
+                return
+
+            if entry[result_attribute] == None:
+                return
+
+            if entry[result_attribute] == '':
+                return
+
             # Now look at entry_changes and old_canon_attr, and see if they're
             # the same value.
             if entry_changes.has_key(result_attribute):


commit f1351a4c2485a9be8f0a524e63652addcb385a5d
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Thu May 16 19:41:29 2013 +0200

    Make sure a failing recipient policy does not result in a blocked process (#1878)

diff --git a/pykolab/auth/ldap/__init__.py b/pykolab/auth/ldap/__init__.py
index 0a564fa..1c41924 100644
--- a/pykolab/auth/ldap/__init__.py
+++ b/pykolab/auth/ldap/__init__.py
@@ -566,6 +566,9 @@ class LDAP(pykolab.base.Base):
                         }
                 )
 
+            if primary_mail_address == None:
+                return entry_modifications
+
             i = 1
             _primary_mail = primary_mail_address
 
diff --git a/pykolab/plugins/recipientpolicy/__init__.py b/pykolab/plugins/recipientpolicy/__init__.py
index 8dff05e..8ea2c89 100644
--- a/pykolab/plugins/recipientpolicy/__init__.py
+++ b/pykolab/plugins/recipientpolicy/__init__.py
@@ -77,9 +77,10 @@ class KolabRecipientpolicy(object):
             return mail
         except KeyError, e:
             log.warning(_("Attribute substitution for 'mail' failed in Recipient Policy"))
-            mail = utils.translate(user_attrs['mail'], user_attrs['preferredlanguage'])
-            mail = mail.lower()
-            return mail
+            if user_attrs.has_key('mail'):
+                return mail
+            else:
+                return None
 
     def set_secondary_mail(self, *args, **kw):
         """





More information about the commits mailing list