VirtualMailManager/Account.py
branchv0.6.x
changeset 306 504fd29b4712
parent 302 32b4a39b5640
child 316 31d8931dc535
equal deleted inserted replaced
305:3c62f581d17a 306:504fd29b4712
    73         dbc.close()
    73         dbc.close()
    74         if result:
    74         if result:
    75             self._uid, _mid, _tid = result
    75             self._uid, _mid, _tid = result
    76             if _tid != self._transport.tid:
    76             if _tid != self._transport.tid:
    77                 self._transport = Transport(self._dbh, tid=_tid)
    77                 self._transport = Transport(self._dbh, tid=_tid)
    78             self._mail = MailLocation(mid=_mid)
    78             self._mail = MailLocation(self._dbh, mid=_mid)
    79             self._new = False
    79             self._new = False
    80 
    80 
    81     def _set_uid(self):
    81     def _set_uid(self):
    82         """Set the unique ID for the new Account."""
    82         """Set the unique ID for the new Account."""
    83         assert self._uid == 0
    83         assert self._uid == 0
    89     def _prepare(self, maillocation):
    89     def _prepare(self, maillocation):
    90         """Check and set different attributes - before we store the
    90         """Check and set different attributes - before we store the
    91         information in the database.
    91         information in the database.
    92         """
    92         """
    93         if maillocation.dovecot_version > cfg_dget('misc.dovecot_version'):
    93         if maillocation.dovecot_version > cfg_dget('misc.dovecot_version'):
    94             raise AErr(_(u"The mail_location prefix '%(prefix)s' requires "
    94             raise AErr(_(u"The mailbox format '%(mbfmt)s' requires Dovecot "
    95                          u"Dovecot >= v%(version)s") %
    95                          u">= v%(version)s") % {'mbfmt': maillocation.mbformat,
    96                        {'prefix': maillocation.prefix,
    96                        'version': version_str(maillocation.dovecot_version)},
    97                         'version': version_str(maillocation.dovecot_version)},
       
    98                        INVALID_MAIL_LOCATION)
    97                        INVALID_MAIL_LOCATION)
    99         if not maillocation.postfix and \
    98         if not maillocation.postfix and \
   100           self._transport.transport.lower() in ('virtual:', 'virtual'):
    99           self._transport.transport.lower() in ('virtual:', 'virtual'):
   101             raise AErr(_(u"Invalid transport '%(transport)s' for mail_location"
   100             raise AErr(_(u"Invalid transport '%(transport)s' for mailbox "
   102                          u" prefix '%(prefix)s'") %
   101                          u"format '%(mbfmt)s'") %
   103                        {'transport': self._transport,
   102                        {'transport': self._transport,
   104                         'prefix': maillocation.prefix}, INVALID_MAIL_LOCATION)
   103                         'mbfmt': maillocation.mbformat}, INVALID_MAIL_LOCATION)
   105         self._mail = maillocation
   104         self._mail = maillocation
   106         self._set_uid()
   105         self._set_uid()
   107 
   106 
   108     def _switch_state(self, state, service):
   107     def _switch_state(self, state, service):
   109         """Switch the state of the Account's services on or off. See
   108         """Switch the state of the Account's services on or off. See
   246                        ACCOUNT_MISSING_PASSWORD)
   245                        ACCOUNT_MISSING_PASSWORD)
   247         if cfg_dget('misc.dovecot_version') >= 0x10200b02:
   246         if cfg_dget('misc.dovecot_version') >= 0x10200b02:
   248             sieve_col = 'sieve'
   247             sieve_col = 'sieve'
   249         else:
   248         else:
   250             sieve_col = 'managesieve'
   249             sieve_col = 'managesieve'
   251         self._prepare(MailLocation(directory=cfg_dget('mailbox.root'),
   250         self._prepare(MailLocation(self._dbh, mbfmt=cfg_dget('mailbox.format'),
   252                                    mbfmt=cfg_dget('mailbox.format')))
   251                                    directory=cfg_dget('mailbox.root')))
   253         sql = "INSERT INTO users (local_part, passwd, uid, gid, mid, tid,\
   252         sql = "INSERT INTO users (local_part, passwd, uid, gid, mid, tid,\
   254  smtp, pop3, imap, %s) VALUES ('%s', '%s', %d, %d, %d, %d, %s, %s, %s, %s)" % (
   253  smtp, pop3, imap, %s) VALUES ('%s', '%s', %d, %d, %d, %d, %s, %s, %s, %s)" % (
   255             sieve_col, self._addr.localpart, pwhash(self._passwd,
   254             sieve_col, self._addr.localpart, pwhash(self._passwd,
   256                                                     user=self._addr),
   255                                                     user=self._addr),
   257             self._uid, self._domain.gid, self._mail.mid, self._transport.tid,
   256             self._uid, self._domain.gid, self._mail.mid, self._transport.tid,