VirtualMailManager/Account.py
changeset 134 6ca3d22e5dd0
parent 133 2d5c4745efec
child 138 617f27715b01
equal deleted inserted replaced
133:2d5c4745efec 134:6ca3d22e5dd0
    80             raise AccE(_(u"Unknown service “%s”.") % service,
    80             raise AccE(_(u"Unknown service “%s”.") % service,
    81                     ERR.UNKNOWN_SERVICE)
    81                     ERR.UNKNOWN_SERVICE)
    82         if self._uid < 1:
    82         if self._uid < 1:
    83             raise AccE(_(u"The account “%s” doesn't exists.") % self._addr,
    83             raise AccE(_(u"The account “%s” doesn't exists.") % self._addr,
    84                     ERR.NO_SUCH_ACCOUNT)
    84                     ERR.NO_SUCH_ACCOUNT)
    85         sieve_col = 'sieve' if dcvers > 11 else 'managesieve'
    85         if dcvers > 11:
       
    86             sieve_col = 'sieve'
       
    87         else:
       
    88             sieve_col = 'managesieve'
    86         if service in ('smtp', 'pop3', 'imap'):
    89         if service in ('smtp', 'pop3', 'imap'):
    87             sql = 'UPDATE users SET %s = %s WHERE uid = %d' % (service, state,
    90             sql = 'UPDATE users SET %s = %s WHERE uid = %d' % (service, state,
    88                     self._uid)
    91                     self._uid)
    89         elif service == 'sieve':
    92         elif service == 'sieve':
    90             sql = 'UPDATE users SET %s = %s WHERE uid = %d' % (sieve_col,
    93             sql = 'UPDATE users SET %s = %s WHERE uid = %d' % (sieve_col,
   129     def disable(self, dcvers, service=None):
   132     def disable(self, dcvers, service=None):
   130         self._switchState(False, dcvers, service)
   133         self._switchState(False, dcvers, service)
   131 
   134 
   132     def save(self, maillocation, dcvers, smtp, pop3, imap, sieve):
   135     def save(self, maillocation, dcvers, smtp, pop3, imap, sieve):
   133         if self._uid < 1:
   136         if self._uid < 1:
   134             sieve_col = 'sieve' if dcvers > 11 else 'managesieve'
   137             if dcvers > 11:
       
   138                 sieve_col = 'sieve'
       
   139             else:
       
   140                 sieve_col = 'managesieve'
   135             self._prepare(maillocation)
   141             self._prepare(maillocation)
   136             sql = "INSERT INTO users (local_part, passwd, uid, gid, mid, tid,\
   142             sql = "INSERT INTO users (local_part, passwd, uid, gid, mid, tid,\
   137  smtp, pop3, imap, %s) VALUES ('%s', '%s', %d, %d, %d, %d, %s, %s, %s, %s)" % (
   143  smtp, pop3, imap, %s) VALUES ('%s', '%s', %d, %d, %d, %d, %s, %s, %s, %s)" % (
   138                 sieve_col, self._addr._localpart, self._passwd, self._uid,
   144                 sieve_col, self._addr._localpart, self._passwd, self._uid,
   139                 self._gid, self._mid, self._tid, smtp, pop3, imap, sieve)
   145                 self._gid, self._mid, self._tid, smtp, pop3, imap, sieve)
   165         if dbc.rowcount > 0:
   171         if dbc.rowcount > 0:
   166             self._dbh.commit()
   172             self._dbh.commit()
   167         dbc.close()
   173         dbc.close()
   168 
   174 
   169     def getInfo(self, dcvers):
   175     def getInfo(self, dcvers):
   170         sieve_col = 'sieve' if dcvers > 11 else 'managesieve'
   176         if dcvers > 11:
       
   177             sieve_col = 'sieve'
       
   178         else:
       
   179             sieve_col = 'managesieve'
   171         sql = 'SELECT name, uid, gid, mid, tid, smtp, pop3, imap, %s\
   180         sql = 'SELECT name, uid, gid, mid, tid, smtp, pop3, imap, %s\
   172  FROM users WHERE uid = %d' % (sieve_col, self._uid)
   181  FROM users WHERE uid = %d' % (sieve_col, self._uid)
   173         dbc = self._dbh.cursor()
   182         dbc = self._dbh.cursor()
   174         dbc.execute(sql)
   183         dbc.execute(sql)
   175         info = dbc.fetchone()
   184         info = dbc.fetchone()