VirtualMailManager/Account.py
branchv0.6.x
changeset 227 87db9f1f95ea
parent 225 a51809f7940b
child 228 a7b000ca4ac9
equal deleted inserted replaced
226:311eee429f67 227:87db9f1f95ea
     6 
     6 
     7 import VirtualMailManager.constants.ERROR as ERR
     7 import VirtualMailManager.constants.ERROR as ERR
     8 from VirtualMailManager.Domain import Domain
     8 from VirtualMailManager.Domain import Domain
     9 from VirtualMailManager.EmailAddress import EmailAddress
     9 from VirtualMailManager.EmailAddress import EmailAddress
    10 from VirtualMailManager.errors import AccountError as AccE
    10 from VirtualMailManager.errors import AccountError as AccE
    11 from VirtualMailManager.MailLocation import MailLocation
    11 from VirtualMailManager.maillocation import MailLocation, MAILDIR_NAME, \
       
    12      MBOX_NAME, MDBOX_NAME, SDBOX_NAME
    12 from VirtualMailManager.Transport import Transport
    13 from VirtualMailManager.Transport import Transport
    13 
    14 
    14 
    15 
    15 _ = lambda msg: msg
    16 _ = lambda msg: msg
    16 
    17 
    73         dbc.execute("SELECT nextval('users_uid')")
    74         dbc.execute("SELECT nextval('users_uid')")
    74         self._uid = dbc.fetchone()[0]
    75         self._uid = dbc.fetchone()[0]
    75         dbc.close()
    76         dbc.close()
    76 
    77 
    77     def _prepare(self, maillocation):
    78     def _prepare(self, maillocation):
       
    79         if not maillocation.lower() in map(lambda x: x.lower(), (MAILDIR_NAME,
       
    80                                            MBOX_NAME, MDBOX_NAME, SDBOX_NAME)):
       
    81             raise AccE(_(u'Unknown mail_location directory name: %r') %
       
    82                        maillocation, ERR.UNKNOWN_MAILLOCATION_NAME)
    78         self._setID()
    83         self._setID()
    79         self._mid = MailLocation(self._dbh, maillocation=maillocation).getID()
    84         self._mid = MailLocation(type_=maillocation).mid
    80 
    85 
    81     def _switchState(self, state, dcvers, service):
    86     def _switchState(self, state, dcvers, service):
    82         if not isinstance(state, bool):
    87         if not isinstance(state, bool):
    83             return False
    88             return False
    84         if not service in (None, 'all', 'imap', 'pop3', 'sieve', 'smtp'):
    89         if not service in (None, 'all', 'imap', 'pop3', 'sieve', 'smtp'):
   190         dbc.close()
   195         dbc.close()
   191         if info is None:
   196         if info is None:
   192             raise AccE(_(u"The account “%s” doesn't exist.") % self._addr,
   197             raise AccE(_(u"The account “%s” doesn't exist.") % self._addr,
   193                     ERR.NO_SUCH_ACCOUNT)
   198                     ERR.NO_SUCH_ACCOUNT)
   194         else:
   199         else:
   195             keys = ['name', 'uid', 'gid', 'maildir', 'transport', 'smtp',
   200             keys = ['name', 'uid', 'gid', 'mid', 'transport', 'smtp',
   196                     'pop3', 'imap', sieve_col]
   201                     'pop3', 'imap', sieve_col]
   197             info = dict(zip(keys, info))
   202             info = dict(zip(keys, info))
   198             for service in ('smtp', 'pop3', 'imap', sieve_col):
   203             for service in ('smtp', 'pop3', 'imap', sieve_col):
   199                 if bool(info[service]):
   204                 if bool(info[service]):
   200                     # TP: A service (pop3/imap/…) is enabled/usable for a user
   205                     # TP: A service (pop3/imap/…) is enabled/usable for a user
   201                     info[service] = _('enabled')
   206                     info[service] = _('enabled')
   202                 else:
   207                 else:
   203                     # TP: A service (pop3/imap) isn't enabled/usable for a user
   208                     # TP: A service (pop3/imap) isn't enabled/usable for a user
   204                     info[service] = _('disabled')
   209                     info[service] = _('disabled')
   205             info['address'] = self._addr
   210             info['address'] = self._addr
   206             info['maildir'] = '%s/%s/%s' % (self._base, info['uid'],
   211             info['home'] = '%s/%s' % (self._base, info['uid'])
   207                     MailLocation(self._dbh,
   212             info['mail_location'] = MailLocation(mid=info['mid']).mail_location
   208                         mid=info['maildir']).getMailLocation())
       
   209             info['transport'] = Transport(self._dbh,
   213             info['transport'] = Transport(self._dbh,
   210                                           tid=info['transport']).transport
   214                                           tid=info['transport']).transport
   211             return info
   215             return info
   212 
   216 
   213     def getAliases(self):
   217     def getAliases(self):