VirtualMailManager/common.py
changeset 611 8e9b0046bc8f
parent 609 56ec275911f2
child 614 1ec3497a6733
equal deleted inserted replaced
610:b6c4e77046b9 611:8e9b0046bc8f
   185         raise ValueError('Invalid version: %r' % hex(version))
   185         raise ValueError('Invalid version: %r' % hex(version))
   186 
   186 
   187     _version_cache[version] = version_string
   187     _version_cache[version] = version_string
   188     return version_string
   188     return version_string
   189 
   189 
       
   190 
   190 def format_domain_default(domaindata):
   191 def format_domain_default(domaindata):
   191     """Format info output when the value displayed is the domain default."""
   192     """Format info output when the value displayed is the domain default."""
   192     # TP: [domain default] indicates that a user's setting is the same as
   193     # TP: [domain default] indicates that a user's setting is the same as
   193     # configured in the user's domain.
   194     # configured in the user's domain.
   194     # e.g.: [  0.84%] 42/5,000 [domain default]
   195     # e.g.: [  0.84%] 42/5,000 [domain default]
   216     second element is a dictionary indexed by domain ID, holding lists to
   217     second element is a dictionary indexed by domain ID, holding lists to
   217     associated addresses. Each address is itself actually a tuple of address,
   218     associated addresses. Each address is itself actually a tuple of address,
   218     type, and boolean indicating whether the address stems from an alias
   219     type, and boolean indicating whether the address stems from an alias
   219     domain.
   220     domain.
   220     """
   221     """
   221     if typelimit == None:
   222     if typelimit is None:
   222             typelimit = TYPE_ACCOUNT | TYPE_ALIAS | TYPE_RELOCATED
   223             typelimit = TYPE_ACCOUNT | TYPE_ALIAS | TYPE_RELOCATED
   223     queries = []
   224     queries = []
   224     if typelimit & TYPE_ACCOUNT:
   225     if typelimit & TYPE_ACCOUNT:
   225         queries.append('SELECT gid, local_part, %d AS type FROM users'
   226         queries.append('SELECT gid, local_part, %d AS type FROM users'
   226                        % TYPE_ACCOUNT)
   227                        % TYPE_ACCOUNT)
   227     if typelimit & TYPE_ALIAS:
   228     if typelimit & TYPE_ALIAS:
   228         queries.append('SELECT DISTINCT gid, address as local_part, %d AS type '
   229         queries.append('SELECT DISTINCT gid, address as local_part, '
   229                        'FROM alias' % TYPE_ALIAS)
   230                        '%d AS type FROM alias' % TYPE_ALIAS)
   230     if typelimit & TYPE_RELOCATED:
   231     if typelimit & TYPE_RELOCATED:
   231         queries.append('SELECT gid, address as local_part, %d AS type '
   232         queries.append('SELECT gid, address as local_part, %d AS type '
   232                        'FROM relocated' % TYPE_RELOCATED)
   233                        'FROM relocated' % TYPE_RELOCATED)
   233     sql  = "SELECT gid, local_part || '@' || domainname AS address, "
   234     sql = "SELECT gid, local_part || '@' || domainname AS address, "
   234     sql += 'type, NOT is_primary AS from_aliasdomain FROM ('
   235     sql += 'type, NOT is_primary AS from_aliasdomain FROM ('
   235     sql += ' UNION '.join(queries)
   236     sql += ' UNION '.join(queries)
   236     sql += ') a JOIN domain_name USING (gid)'
   237     sql += ') a JOIN domain_name USING (gid)'
   237     nextkw = 'WHERE'
   238     nextkw = 'WHERE'
   238     sqlargs = []
   239     sqlargs = []
   239     for like, field, pattern in ((dlike, 'domainname', dpattern),
   240     for like, field, pattern in ((dlike, 'domainname', dpattern),
   240                                  (llike, 'local_part', lpattern)):
   241                                  (llike, 'local_part', lpattern)):
   241         if like:
   242         if like:
   242             match = 'LIKE'
   243             match = 'LIKE'
   243         else:
   244         else:
   244             if not pattern: continue
   245             if not pattern:
       
   246                 continue
   245             match = '='
   247             match = '='
   246         sql += ' %s %s %s %%s' % (nextkw, field, match)
   248         sql += ' %s %s %s %%s' % (nextkw, field, match)
   247         sqlargs.append(pattern)
   249         sqlargs.append(pattern)
   248         nextkw = 'AND'
   250         nextkw = 'AND'
   249     sql += ' ORDER BY domainname, local_part'
   251     sql += ' ORDER BY domainname, local_part'