Branch 'pykolab-0.4' - 10 commits - bin/kolab_smtp_access_policy.py configure.ac conf/kolab.conf pykolab/imap pykolab/plugins

Jeroen van Meeuwen vanmeeuwen at kolabsys.com
Sun Sep 16 20:24:40 CEST 2012


 bin/kolab_smtp_access_policy.py          |   91 ++++++++++++++-----------------
 conf/kolab.conf                          |    2 
 configure.ac                             |    2 
 pykolab/imap/__init__.py                 |   12 ++++
 pykolab/imap/cyrus.py                    |   33 +++++++++++
 pykolab/plugins/dynamicquota/__init__.py |   66 +++++++++-------------
 6 files changed, 120 insertions(+), 86 deletions(-)

New commits:
commit 5f9f8c0e529bceee589277c5475508e91f146b64
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Sun Sep 16 19:23:51 2012 +0100

    Re-enable and tweak the kolab_smtp_access_policy cache

diff --git a/bin/kolab_smtp_access_policy.py b/bin/kolab_smtp_access_policy.py
index bd94925..bce2614 100755
--- a/bin/kolab_smtp_access_policy.py
+++ b/bin/kolab_smtp_access_policy.py
@@ -629,24 +629,15 @@ class PolicyRequest(object):
 
             # Got a final answer here, do the caching thing.
             if not cache == False:
-                records = cache_select(
+                record_id = cache_update(
                         function='verify_sender',
                         sender=self.sender,
                         recipients=self.recipients,
+                        result=(int)(False),
                         sasl_username=self.sasl_username,
                         sasl_sender=self.sasl_sender
                     )
 
-                if not len(records) == len(self.recipients):
-                    record_id = cache_insert(
-                            function='verify_sender',
-                            sender=self.sender,
-                            recipients=self.recipients,
-                            result=(int)(False),
-                            sasl_username=self.sasl_username,
-                            sasl_sender=self.sasl_sender
-                        )
-
             sender_is_delegate = False
 
         else:
@@ -1051,24 +1042,15 @@ class PolicyRequest(object):
             sender_verified = True
 
         if not cache == False:
-            records = cache_select(
+            record_id = cache_update(
                     function='verify_sender',
                     sender=self.sender,
                     recipients=self.recipients,
+                    result=(int)(sender_verified),
                     sasl_username=self.sasl_username,
-                    sasl_sender=self.sasl_sender,
+                    sasl_sender=self.sasl_sender
                 )
 
-            if len(records) == len(self.recipients):
-                record_id = cache_insert(
-                        function='verify_sender',
-                        sender=self.sender,
-                        recipients=self.recipients,
-                        result=(int)(sender_verified),
-                        sasl_username=self.sasl_username,
-                        sasl_sender=self.sasl_sender
-                    )
-
         return sender_verified
 
 def cache_cleanup():
@@ -1085,11 +1067,9 @@ def cache_cleanup():
 def cache_init():
     global cache, cache_expire, session
 
-    return False
-
     if conf.has_section('kolab_smtp_access_policy'):
-        if conf.has_option('kolab_smtp_access_policy', 'uri'):
-            cache_uri = conf.get('kolab_smtp_access_policy', 'uri')
+        if conf.has_option('kolab_smtp_access_policy', 'cache_uri'):
+            cache_uri = conf.get('kolab_smtp_access_policy', 'cache_uri')
             cache = True
             if conf.has_option('kolab_smtp_access_policy', 'retention'):
                 cache_expire = (int)(
@@ -1098,7 +1078,10 @@ def cache_init():
                                 'retention'
                             )
                     )
-
+        elif conf.has_option('kolab_smtp_access_policy', 'uri'):
+            log.warning(_("The 'uri' setting in the kolab_smtp_access_policy section is soon going to be deprecated in favor of 'cache_uri'"))
+            cache_uri = conf.get('kolab_smtp_access_policy', 'uri')
+            cache = True
         else:
             return False
     else:


commit 6394ca55d3a9700515face96bbb52004fcda7086
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Sun Sep 16 19:20:06 2012 +0100

    Set the default retention time for policy enforcement caching to 1 day

diff --git a/conf/kolab.conf b/conf/kolab.conf
index e9744d0..b402c54 100644
--- a/conf/kolab.conf
+++ b/conf/kolab.conf
@@ -132,7 +132,7 @@ auth_attributes = mail, alias, uid
 
 [kolab_smtp_access_policy]
 cache_uri = mysql://user:pass@localhost/database
-cache_retention = 30
+cache_retention = 86400
 address_search_attrs = mail, alias
 
 [kolab_wap]


commit 81bd7ea54d90e3960e52b9dace99678a746db672
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Sun Sep 16 18:55:09 2012 +0100

    Make sure Auth() is only created for the relevant domain, and at the right time (#1017)

diff --git a/bin/kolab_smtp_access_policy.py b/bin/kolab_smtp_access_policy.py
index d97690a..bd94925 100755
--- a/bin/kolab_smtp_access_policy.py
+++ b/bin/kolab_smtp_access_policy.py
@@ -66,8 +66,6 @@ log.remove_stdout_handler()
 
 conf = pykolab.getConf()
 
-auth = None
-
 #
 # Caching routines using SQLAlchemy.
 #
@@ -154,6 +152,8 @@ class PolicyRequest(object):
     email_address_keys = [ 'sender', 'recipient' ]
     recipients = []
 
+    auth = None
+
     sasl_domain = None
     sasl_user = None
     sender_domain = None
@@ -241,7 +241,7 @@ class PolicyRequest(object):
                     'address_search_attrs'
                 )
 
-            rule_subject = auth.get_user_attributes(
+            rule_subject = self.auth.get_user_attributes(
                     self.sasl_domain,
                     { 'dn': dn },
                     search_attrs + [ 'objectclass' ]
@@ -282,8 +282,8 @@ class PolicyRequest(object):
 
         users = []
 
-        auth._auth._bind()
-        _users = auth._auth._search(
+        self.auth._auth._bind()
+        _users = self.auth._auth._search(
                 _base_dn,
                 scope=LDAP_SCOPE[_scope],
                 filterstr=_filter,
@@ -457,7 +457,12 @@ class PolicyRequest(object):
             else:
                 self.sasl_domain = conf.get('kolab', 'primary_domain')
 
-        sasl_users = auth.find_recipient(
+        if self.auth == None:
+            self.auth = Auth(self.sasl_domain)
+        elif not self.auth.domain == self.sasl_domain:
+            self.auth = Auth(self.sasl_domain)
+
+        sasl_users = self.auth.find_recipient(
                 self.sasl_username,
                 domain=self.sasl_domain
             )
@@ -517,7 +522,7 @@ class PolicyRequest(object):
 
         attrs = list(set(attrs))
 
-        user_attrs = auth.get_user_attributes(
+        user_attrs = self.auth.get_user_attributes(
                 self.sasl_domain,
                 self.sasl_user,
                 attrs
@@ -555,7 +560,7 @@ class PolicyRequest(object):
                     'mail_attributes'
                 )
 
-        sender_users = auth.find_recipient(
+        sender_users = self.auth.find_recipient(
                 self.sender,
                 domain=self.sender_domain
             )
@@ -594,7 +599,7 @@ class PolicyRequest(object):
                     ]
             )
 
-        user_attrs = auth.get_user_attributes(
+        user_attrs = self.auth.get_user_attributes(
                 self.sender_domain,
                 self.sender_user,
                 attrs
@@ -648,7 +653,7 @@ class PolicyRequest(object):
             # See if we can match the value of the envelope sender delegates to
             # the actual sender sasl_username
             if self.sasl_user == None:
-                sasl_users = auth.find_recipient(
+                sasl_users = self.auth.find_recipient(
                         self.sasl_username,
                         domain=self.sasl_domain
                     )
@@ -665,7 +670,7 @@ class PolicyRequest(object):
             # Possible values for the kolabDelegate attribute are:
             # a 'uid', a 'dn'.
             if not self.sasl_user.has_key('uid'):
-                self.sasl_user['uid'] = auth.get_user_attribute(
+                self.sasl_user['uid'] = self.auth.get_user_attribute(
                         self.sasl_domain,
                         self.sasl_user,
                         'uid'
@@ -751,16 +756,16 @@ class PolicyRequest(object):
             sasl_domain = conf.get('kolab', 'primary_domain')
 
         if verify_domain(sasl_domain):
-            if auth.secondary_domains.has_key(sasl_domain):
+            if self.auth.secondary_domains.has_key(sasl_domain):
                 log.debug(
                         _("Using authentication domain %s instead of %s") % (
-                                auth.secondary_domains[sasl_domain],
+                                self.auth.secondary_domains[sasl_domain],
                                 sasl_domain
                             ),
                         level=8
                     )
 
-                sasl_domain = auth.secondary_domains[sasl_domain]
+                sasl_domain = self.auth.secondary_domains[sasl_domain]
             else:
                 log.debug(
                         _("Domain %s is a primary domain") % (
@@ -779,7 +784,12 @@ class PolicyRequest(object):
 
             return True
 
-        recipients = auth.find_recipient(
+        if self.auth == None:
+            self.auth = Auth(sasl_domain)
+        elif not self.auth.domain == sasl_domain:
+            self.auth = Auth(sasl_domain)
+
+        recipients = self.auth.find_recipient(
                 normalize_address(recipient),
                 domain=sasl_domain,
             )
@@ -839,7 +849,7 @@ class PolicyRequest(object):
                 return True
 
         if not recipient['dn'] == False:
-            recipient_policy = auth.get_entry_attribute(
+            recipient_policy = self.auth.get_entry_attribute(
                     sasl_domain,
                     recipient,
                     'kolabAllowSMTPSender'
@@ -999,7 +1009,7 @@ class PolicyRequest(object):
         if recipient_policy_user.has_key('kolaballowsmtprecipient'):
             recipient_policy = recipient_policy_user['kolaballowsmtprecipient']
         else:
-            recipient_policy = auth.get_user_attribute(
+            recipient_policy = self.auth.get_user_attribute(
                     recipient_policy_domain,
                     recipient_policy_user,
                     'kolabAllowSMTPRecipient'
@@ -1259,6 +1269,9 @@ def expand_mydomains():
         Return a list of my domains.
     """
 
+    auth = Auth()
+    auth.connect()
+
     mydomains = []
 
     _mydomains = auth.list_domains()
@@ -1326,6 +1339,9 @@ def verify_domain(domain):
         Verify whether the domain is internal (mine) or external.
     """
 
+    auth = Auth()
+    auth.connect()
+
     domain_verified = False
 
     _mydomains = auth.list_domains()
@@ -1372,8 +1388,6 @@ if __name__ == "__main__":
 
     conf.finalize_conf()
 
-    auth = Auth()
-
     cache = cache_init()
 
     policy_requests = {}


commit c3c50aa0be0277ec14bedb62d9139fc38b4594ef
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Sat Sep 15 15:24:52 2012 +0100

    Bump release for rebuild

diff --git a/configure.ac b/configure.ac
index 6cea032..6fb569f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,5 +1,5 @@
 AC_INIT([pykolab], 0.4.15)
-AC_SUBST([RELEASE], 3)
+AC_SUBST([RELEASE], 4)
 
 AC_CONFIG_SRCDIR(pykolab/constants.py.in)
 


commit f93ae44d9552cd1f6e18298683a423bf529d2f99
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Sat Sep 15 15:24:35 2012 +0100

    Provide "dummy" function connect()

diff --git a/pykolab/imap/cyrus.py b/pykolab/imap/cyrus.py
index ac580c9..f719e10 100644
--- a/pykolab/imap/cyrus.py
+++ b/pykolab/imap/cyrus.py
@@ -90,6 +90,39 @@ class Cyrus(cyruslib.CYRUS):
     def __del__(self):
         pass
 
+    def connect(self, uri):
+        """
+            Dummy connect function that checks if the server that we want to
+            connect to is actually the server we are connected to.
+
+            Uses pykolab.imap.IMAP.connect() in the background.
+        """
+        port = None
+
+        result = urlparse(uri)
+
+        if hasattr(result, 'hostname'):
+            scheme = result.scheme
+            hostname = result.hostname
+            port = result.port
+        else:
+            scheme = uri.split(':')[0]
+            (hostname, port) = uri.split('/')[2].split(':')
+
+        if not port:
+            if scheme == 'imap':
+                port = 143
+            else:
+                port = 993
+
+        if hostname == self.server:
+            return
+
+        imap = IMAP()
+        imap.connect(uri=uri)
+        if not self.SEP == self.separator:
+            self.separator = self.SEP
+
     def login(self, *args, **kw):
         """
             Login to the Cyrus IMAP server through cyruslib.CYRUS, but set our


commit 115a594214d83c7309c9980b71a5d583beb3c223
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Sat Sep 15 15:23:46 2012 +0100

    Bring the dynamicquota plugin back in sync

diff --git a/pykolab/plugins/dynamicquota/__init__.py b/pykolab/plugins/dynamicquota/__init__.py
index 6115dcd..ed3de12 100644
--- a/pykolab/plugins/dynamicquota/__init__.py
+++ b/pykolab/plugins/dynamicquota/__init__.py
@@ -40,51 +40,43 @@ class KolabDynamicquota(object):
             The arguments passed to the 'set_user_folder_quota' hook:
 
             - used (integer, in KB)
-            - current quota (integer, in KB)
-            - quota (integer, in KB)
-            - user
+            - imap_quota (current imap quota obtained from IMAP, integer, in KB)
+            - ldap_quota (current LDAP quota obtained from LDAP, integer, in KB)
+            - default_quota (integer, in KB)
+
+            Returns:
+
+            - None - an error has occurred and this plugin doesn't care.
+            - Negative 1 - remove quota.
+            - Zero - Absolute 0.
+            - Positive Integer - set new quota.
         """
 
-        for keyword in [ 'used', 'current_quota', 'new_quota', 'default_quota' ]:
+        for keyword in [ 'used', 'imap_quota', 'ldap_quota', 'default_quota' ]:
             if not kw.has_key(keyword):
-                log.warning(_("No keyword %s passed to set_user_folder_quota") % (keyword))
-                return 0
+                log.warning(
+                        _("No keyword %s passed to set_user_folder_quota") % (
+                                keyword
+                            )
+                    )
+
+                return
             else:
                 try:
-                    kw[keyword] = (int)(kw[keyword])
+                    if not kw[keyword] == None:
+                        kw[keyword] = (int)(kw[keyword])
+
                 except:
                     log.error(_("Quota '%s' not an integer!") % (keyword))
-                    return 0
+                    return
 
         # Escape the user without quota
-        if kw['new_quota'] == 0:
-            # Unless default quota is set
-            if kw['default_quota'] > 0:
-                log.info(_("The new quota was set to 0, but default quota > 0, returning default quota"))
-                return kw['default_quota']
-
-            return 0
-
-        # Make your adjustments here, for example:
-        #
-        # - increase the quota by 10% if the currently used storage size
-        #   is over 90%
-
-        if kw['new_quota'] < int(float(kw['used']) * 1.1):
-            _new_quota = int(float(kw['used']) * 1.1)
-        elif kw['new_quota'] > int(float(kw['used']) * 1.1):
-            # TODO: If the current quota in IMAP had been set to 0, but we want to apply quota, and
-            # 0 is current_quota, 90% of that is still 0...
-            _new_quota = int(float(kw['current_quota']) * 0.9)
-
-        if kw['new_quota'] == 0:
-            if kw['default_quota'] > _new_quota:
-                log.info(_("The default quota is larger then the calculated new quota, using the default quota"))
-                return kw['default_quota']
-
-            else:
-                new_quota = _new_quota
+        if kw['ldap_quota'] == None:
+            return kw['default_quota']
+        elif kw['ldap_quota'] == -1:
+            return -1
+        elif kw['ldap_quota'] > 0:
+            return kw['ldap_quota']
         else:
-            new_quota = kw['new_quota']
+            return kw['default_quota']
 
-        return new_quota


commit d74252281142056c8227aa48a4f7bdd6b324ec43
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Sat Sep 15 14:59:38 2012 +0100

    Bump release for rebuild

diff --git a/configure.ac b/configure.ac
index 15a8c58..6cea032 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,5 +1,5 @@
 AC_INIT([pykolab], 0.4.15)
-AC_SUBST([RELEASE], 2)
+AC_SUBST([RELEASE], 3)
 
 AC_CONFIG_SRCDIR(pykolab/constants.py.in)
 


commit c27897fbb45efd32ec1b5d6e4595cc13a94479ca
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Sat Sep 15 14:57:53 2012 +0100

    Add missing function set_quota() (#1013)

diff --git a/pykolab/imap/__init__.py b/pykolab/imap/__init__.py
index d04eeb1..79375d6 100644
--- a/pykolab/imap/__init__.py
+++ b/pykolab/imap/__init__.py
@@ -600,6 +600,9 @@ class IMAP(object):
             else:
                 auth.set_user_attribute(primary_domain, user, _mailserver_attr, _current_mailserver)
 
+    def set_quota(self, folder, quota):
+        self.imap._setquota(folder, quota)
+
     def parse_mailfolder(self, mailfolder):
         self.connect()
         return self.imap.parse_mailfolder(mailfolder)


commit 57d894c55dc3c98587c875b895ebb0ab84138dc9
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Sat Sep 15 14:42:25 2012 +0100

    Bump release for rebuild

diff --git a/configure.ac b/configure.ac
index 365379c..15a8c58 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,5 +1,5 @@
 AC_INIT([pykolab], 0.4.15)
-AC_SUBST([RELEASE], 1)
+AC_SUBST([RELEASE], 2)
 
 AC_CONFIG_SRCDIR(pykolab/constants.py.in)
 


commit 786155e9c1dc59d14fdb798091b5ba6802ba5124
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Sat Sep 15 14:41:52 2012 +0100

    Add missing functions get_quota() and get_quota_root()

diff --git a/pykolab/imap/__init__.py b/pykolab/imap/__init__.py
index f544beb..d04eeb1 100644
--- a/pykolab/imap/__init__.py
+++ b/pykolab/imap/__init__.py
@@ -718,6 +718,15 @@ class IMAP(object):
 
         self.set_user_mailhost(users, primary_domain, secondary_domains, self.inbox_folders)
 
+    def get_quota(self, mailfolder_path):
+        try:
+            return self.lq(mailfolder_path)
+        except:
+            return
+
+    def get_quota_root(self, mailfolder_path):
+        return self.lqr(mailfolder_path)
+
     def lm(self, *args, **kw):
         return self.imap.lm(*args, **kw)
 





More information about the commits mailing list