VirtualMailManager/account.py
branchv0.6.x
changeset 527 e09139525580
parent 526 85517c8fde36
child 528 4b8c3f51d7da
equal deleted inserted replaced
526:85517c8fde36 527:e09139525580
     6     ~~~~~~~~~~~~~~~~~~~~~~~~~~
     6     ~~~~~~~~~~~~~~~~~~~~~~~~~~
     7 
     7 
     8     Virtual Mail Manager's Account class to manage e-mail accounts.
     8     Virtual Mail Manager's Account class to manage e-mail accounts.
     9 """
     9 """
    10 
    10 
    11 from VirtualMailManager.common import version_str
    11 from VirtualMailManager.common import version_str, \
       
    12      format_domain_default
    12 from VirtualMailManager.constants import \
    13 from VirtualMailManager.constants import \
    13      ACCOUNT_EXISTS, ACCOUNT_MISSING_PASSWORD, ALIAS_PRESENT, \
    14      ACCOUNT_EXISTS, ACCOUNT_MISSING_PASSWORD, ALIAS_PRESENT, \
    14      INVALID_ARGUMENT, INVALID_MAIL_LOCATION, NO_SUCH_ACCOUNT, \
    15      INVALID_ARGUMENT, INVALID_MAIL_LOCATION, NO_SUCH_ACCOUNT, \
    15      NO_SUCH_DOMAIN, VMM_ERROR
    16      NO_SUCH_DOMAIN, VMM_ERROR
    16 from VirtualMailManager.domain import Domain
    17 from VirtualMailManager.domain import Domain
   347     def get_info(self):
   348     def get_info(self):
   348         """Returns a dict with some information about the Account.
   349         """Returns a dict with some information about the Account.
   349 
   350 
   350         The keys of the dict are: 'address', 'gid', 'home', 'imap'
   351         The keys of the dict are: 'address', 'gid', 'home', 'imap'
   351         'mail_location', 'name', 'pop3', 'sieve', 'smtp', transport', 'uid',
   352         'mail_location', 'name', 'pop3', 'sieve', 'smtp', transport', 'uid',
   352         'uq_bytes', 'uq_messages', 'ql_bytes', and 'ql_messages'.
   353         'uq_bytes', 'uq_messages', 'ql_bytes', 'ql_messages', and
       
   354         'ql_domaindefault'.
   353         """
   355         """
   354         self._chk_state()
   356         self._chk_state()
   355         dbc = self._dbh.cursor()
   357         dbc = self._dbh.cursor()
   356         dbc.execute('SELECT name, CASE WHEN bytes IS NULL THEN 0 ELSE bytes '
   358         dbc.execute('SELECT name, CASE WHEN bytes IS NULL THEN 0 ELSE bytes '
   357                     'END, CASE WHEN messages IS NULL THEN 0 ELSE messages END '
   359                     'END, CASE WHEN messages IS NULL THEN 0 ELSE messages END '
   364             info.update(self._get_info_serviceset())
   366             info.update(self._get_info_serviceset())
   365             info['address'] = self._addr
   367             info['address'] = self._addr
   366             info['gid'] = self._domain.gid
   368             info['gid'] = self._domain.gid
   367             info['home'] = '%s/%s' % (self._domain.directory, self._uid)
   369             info['home'] = '%s/%s' % (self._domain.directory, self._uid)
   368             info['mail_location'] = self._mail.mail_location
   370             info['mail_location'] = self._mail.mail_location
   369             info['ql_bytes'] = self._qlimit.bytes
   371             if self._qlimit:
   370             info['ql_messages'] = self._qlimit.messages
   372                 info['ql_bytes'] = self._qlimit.bytes
   371             info['transport'] = self._transport.transport
   373                 info['ql_messages'] = self._qlimit.messages
       
   374                 info['ql_domaindefault'] = False
       
   375             else:
       
   376                 info['ql_bytes'] = self._domain.quotalimit.bytes
       
   377                 info['ql_messages'] = self._domain.quotalimit.messages
       
   378                 info['ql_domaindefault'] = True
       
   379             info['transport'] = self._get_info_transport()
   372             info['uid'] = self._uid
   380             info['uid'] = self._uid
   373             return info
   381             return info
   374         # nearly impossibleā€½
   382         # nearly impossibleā€½
   375         raise AErr(_(u"Could not fetch information for account: '%s'") %
   383         raise AErr(_(u"Could not fetch information for account: '%s'") %
   376                    self._addr, NO_SUCH_ACCOUNT)
   384                    self._addr, NO_SUCH_ACCOUNT)