VirtualMailManager/Account.py
changeset 155 eb866ebb9f2e
parent 145 ead2a7e9f8be
child 156 a849843115e9
equal deleted inserted replaced
154:6e6488722807 155:eb866ebb9f2e
    54 
    54 
    55     def _setAddr(self):
    55     def _setAddr(self):
    56         dom = Domain(self._dbh, self._addr._domainname)
    56         dom = Domain(self._dbh, self._addr._domainname)
    57         self._gid = dom.getID()
    57         self._gid = dom.getID()
    58         if self._gid == 0:
    58         if self._gid == 0:
    59             raise AccE(_(u"The domain “%s” doesn't exist yet.") %\
    59             raise AccE(_(u"The domain “%s” doesn't exist.") %\
    60                     self._addr._domainname, ERR.NO_SUCH_DOMAIN)
    60                     self._addr._domainname, ERR.NO_SUCH_DOMAIN)
    61         self._base = dom.getDir()
    61         self._base = dom.getDir()
    62         self._tid = dom.getTransportID()
    62         self._tid = dom.getTransportID()
    63 
    63 
    64     def _setID(self):
    64     def _setID(self):
    76             return False
    76             return False
    77         if not service in (None, 'all', 'imap', 'pop3', 'sieve', 'smtp'):
    77         if not service in (None, 'all', 'imap', 'pop3', 'sieve', 'smtp'):
    78             raise AccE(_(u"Unknown service “%s”.") % service,
    78             raise AccE(_(u"Unknown service “%s”.") % service,
    79                     ERR.UNKNOWN_SERVICE)
    79                     ERR.UNKNOWN_SERVICE)
    80         if self._uid < 1:
    80         if self._uid < 1:
    81             raise AccE(_(u"The account “%s” doesn't exists.") % self._addr,
    81             raise AccE(_(u"The account “%s” doesn't exist.") % self._addr,
    82                     ERR.NO_SUCH_ACCOUNT)
    82                     ERR.NO_SUCH_ACCOUNT)
    83         if dcvers > 11:
    83         if dcvers > 11:
    84             sieve_col = 'sieve'
    84             sieve_col = 'sieve'
    85         else:
    85         else:
    86             sieve_col = 'managesieve'
    86             sieve_col = 'managesieve'
   149             raise AccE(_(u'The account “%s” already exists.') % self._addr,
   149             raise AccE(_(u'The account “%s” already exists.') % self._addr,
   150                     ERR.ACCOUNT_EXISTS)
   150                     ERR.ACCOUNT_EXISTS)
   151 
   151 
   152     def modify(self, what, value):
   152     def modify(self, what, value):
   153         if self._uid == 0:
   153         if self._uid == 0:
   154             raise AccE(_(u"The account “%s” doesn't exists.") % self._addr,
   154             raise AccE(_(u"The account “%s” doesn't exist.") % self._addr,
   155                     ERR.NO_SUCH_ACCOUNT)
   155                     ERR.NO_SUCH_ACCOUNT)
   156         if what not in ['name', 'password', 'transport']:
   156         if what not in ['name', 'password', 'transport']:
   157             return False
   157             return False
   158         dbc = self._dbh.cursor()
   158         dbc = self._dbh.cursor()
   159         if what == 'password':
   159         if what == 'password':
   180         dbc = self._dbh.cursor()
   180         dbc = self._dbh.cursor()
   181         dbc.execute(sql)
   181         dbc.execute(sql)
   182         info = dbc.fetchone()
   182         info = dbc.fetchone()
   183         dbc.close()
   183         dbc.close()
   184         if info is None:
   184         if info is None:
   185             raise AccE(_(u"The account “%s” doesn't exists.") % self._addr,
   185             raise AccE(_(u"The account “%s” doesn't exist.") % self._addr,
   186                     ERR.NO_SUCH_ACCOUNT)
   186                     ERR.NO_SUCH_ACCOUNT)
   187         else:
   187         else:
   188             keys = ['name', 'uid', 'gid', 'maildir', 'transport', 'smtp',
   188             keys = ['name', 'uid', 'gid', 'maildir', 'transport', 'smtp',
   189                     'pop3', 'imap', sieve_col]
   189                     'pop3', 'imap', sieve_col]
   190             info = dict(zip(keys, info))
   190             info = dict(zip(keys, info))
   213             aliases = [alias[0] for alias in addresses]
   213             aliases = [alias[0] for alias in addresses]
   214         return aliases
   214         return aliases
   215 
   215 
   216     def delete(self, delalias):
   216     def delete(self, delalias):
   217         if self._uid < 1:
   217         if self._uid < 1:
   218             raise AccE(_(u"The account “%s” doesn't exists.") % self._addr,
   218             raise AccE(_(u"The account “%s” doesn't exist.") % self._addr,
   219                     ERR.NO_SUCH_ACCOUNT)
   219                     ERR.NO_SUCH_ACCOUNT)
   220         dbc = self._dbh.cursor()
   220         dbc = self._dbh.cursor()
   221         if delalias == 'delalias':
   221         if delalias == 'delalias':
   222             dbc.execute('DELETE FROM users WHERE uid= %s', self._uid)
   222             dbc.execute('DELETE FROM users WHERE uid= %s', self._uid)
   223             u_rc = dbc.rowcount
   223             u_rc = dbc.rowcount