VirtualMailManager/account.py
branchv0.6.x
changeset 338 45834dcc280e
parent 334 3f550826b1cc
child 341 6709d0faf2f5
equal deleted inserted replaced
337:150ddcc8b315 338:45834dcc280e
    18      NO_SUCH_DOMAIN, UNKNOWN_SERVICE
    18      NO_SUCH_DOMAIN, UNKNOWN_SERVICE
    19 from VirtualMailManager.errors import AccountError as AErr
    19 from VirtualMailManager.errors import AccountError as AErr
    20 from VirtualMailManager.maillocation import MailLocation
    20 from VirtualMailManager.maillocation import MailLocation
    21 from VirtualMailManager.password import pwhash
    21 from VirtualMailManager.password import pwhash
    22 
    22 
       
    23 __all__ = ('SERVICES', 'Account', 'get_account_by_uid')
       
    24 
       
    25 SERVICES = ('imap', 'pop3', 'smtp', 'sieve')
    23 
    26 
    24 _ = lambda msg: msg
    27 _ = lambda msg: msg
    25 cfg_dget = lambda option: None
    28 cfg_dget = lambda option: None
    26 
    29 
    27 
    30 
    28 class Account(object):
    31 class Account(object):
    29     """Class to manage e-mail accounts."""
    32     """Class to manage e-mail accounts."""
    30     __slots__ = ('_addr', '_dbh', '_domain', '_mail', '_new', '_passwd',
    33     __slots__ = ('_addr', '_dbh', '_domain', '_mail', '_new', '_passwd',
    31                  '_transport', '_uid')
    34                  '_transport', '_uid')
    32     _services = ('imap', 'pop3', 'smtp', 'sieve')
       
    33 
    35 
    34     def __init__(self, dbh, address):
    36     def __init__(self, dbh, address):
    35         """Creates a new Account instance.
    37         """Creates a new Account instance.
    36 
    38 
    37         When an account with the given *address* could be found in the
    39         When an account with the given *address* could be found in the
   117         """
   119         """
   118         self._chk_state()
   120         self._chk_state()
   119         if services:
   121         if services:
   120             services = set(services)
   122             services = set(services)
   121             for service in services:
   123             for service in services:
   122                 if service not in self.__class__._services:
   124                 if service not in SERVICES:
   123                     raise AErr(_(u"Unknown service: '%s'.") % service,
   125                     raise AErr(_(u"Unknown service: '%s'.") % service,
   124                                UNKNOWN_SERVICE)
   126                                UNKNOWN_SERVICE)
   125         else:
   127         else:
   126             services = self.__class__._services
   128             services = SERVICES
   127         state = ('FALSE', 'TRUE')[activate]
   129         state = ('FALSE', 'TRUE')[activate]
   128         sql = 'UPDATE users SET %s WHERE uid = %u' % (
   130         sql = 'UPDATE users SET %s WHERE uid = %u' % (
   129                     (' = %(s)s, '.join(services) + ' = %(s)s') % {'s': state},
   131                     (' = %(s)s, '.join(services) + ' = %(s)s') % {'s': state},
   130                     self._uid)
   132                     self._uid)
   131         if 'sieve' in services and \
   133         if 'sieve' in services and \