Commits

Zhang Huangbin committed eb8bc3a

Fixed: not delete real-time mailbox quota while removing mail domain or user.

Comments (0)

Files changed (3)

libs/ldaplib/domain.py

         if not isinstance(domains, list):
             return (False, 'INVALID_DOMAIN_NAME')
 
+        domains = [str(v).lower()
+                   for v in domains
+                   if iredutils.isDomain(v)
+                  ]
+
+        if not domains:
+            return (True,)
+
         msg = {}
         for domain in domains:
-            if not iredutils.isDomain(domain):
-                continue
-
             dn = ldaputils.convKeywordToDN(web.safestr(domain), accountType='domain')
             if dn[0] is False:
                 return dn
             except ldap.LDAPError, e:
                 msg[domain] = str(e)
 
+        # Delete real-time mailbox quota.
+        try:
+            web.admindb.query(
+                'DELETE FROM used_quota WHERE %s' % \
+                web.sqlors('username LIKE ', ['%@' + d for d in domains])
+            )
+        except:
+            pass
+
         if msg == {}:
             return (True,)
         else:

libs/mysql/domain.py

             return (False, 'INVALID_DOMAIN_NAME')
 
         domains = [str(v).lower()
-                        for v in domains
-                        if iredutils.isDomain(v)
-                       ]
+                   for v in domains
+                   if iredutils.isDomain(v)
+                  ]
+
+        if not domains:
+            return (True, )
+
         sql_vars = {'domains': domains, }
 
         # Delete domain and related records.
         try:
+            self.conn.delete('domain', vars=sql_vars, where='domain IN $domains', )
+
             self.conn.delete(
                 'alias_domain',
                 vars=sql_vars,
                     where='domain IN $domains',
                 )
 
-            # Finally, delete from table `domain` to make sure all related
-            # records were deleted.
-            self.conn.delete('domain', vars=sql_vars, where='domain IN $domains', )
+            # Delete real-time mailbox quota.
+            try:
+                self.conn.query(
+                    'DELETE FROM used_quota WHERE %s' % \
+                    web.sqlors('username LIKE ', ['%@' + d for d in domains])
+                )
+            except:
+                pass
 
             for d in domains:
                 web.logger(msg="Delete domain: %s." % (d), domain=d, event='delete',)
+
             return (True,)
         except Exception, e:
             return (False, str(e))

libs/pgsql/domain.py

             return (False, 'INVALID_DOMAIN_NAME')
 
         domains = [str(v).lower()
-                        for v in domains
-                        if iredutils.isDomain(v)
-                       ]
+                   for v in domains
+                   if iredutils.isDomain(v)
+                  ]
+
+        if not domains:
+            return (True, )
+
         sql_vars = {'domains': domains, }
 
         # Delete domain and related records.
         try:
+            self.conn.delete('domain', vars=sql_vars, where='domain IN $domains', )
+
             self.conn.delete(
                 'alias_domain',
                 vars=sql_vars,
                     where='domain IN $domains',
                 )
 
-            # Finally, delete from table `domain` to make sure all related
-            # records were deleted.
-            self.conn.delete('domain', vars=sql_vars, where='domain IN $domains', )
+            # Delete real-time mailbox quota.
+            try:
+                self.conn.query(
+                    'DELETE FROM used_quota WHERE %s' % \
+                    web.sqlors('username LIKE ', ['%@' + d for d in domains])
+                )
+            except:
+                pass
 
             for d in domains:
                 web.logger(msg="Delete domain: %s." % (d), domain=d, event='delete',)