VirtualMailManager/Handler.py
branchv0.6.x
changeset 197 d2712e8c724e
parent 196 65a3163bd113
child 208 efa1327b721f
equal deleted inserted replaced
196:65a3163bd113 197:d2712e8c724e
   175                 address.domainname, address.localpart)
   175                 address.domainname, address.localpart)
   176         return Handler._exists(dbh, sql)
   176         return Handler._exists(dbh, sql)
   177     relocatedExists = staticmethod(relocatedExists)
   177     relocatedExists = staticmethod(relocatedExists)
   178 
   178 
   179     def __getAccount(self, address, password=None):
   179     def __getAccount(self, address, password=None):
   180         self.__dbConnect()
       
   181         address = EmailAddress(address)
   180         address = EmailAddress(address)
   182         if not password is None:
   181         if not password is None:
   183             password = self.__pwhash(password)
   182             password = self.__pwhash(password)
       
   183         self.__dbConnect()
   184         return Account(self._dbh, address, password)
   184         return Account(self._dbh, address, password)
   185 
   185 
   186     def __getAlias(self, address):
   186     def __getAlias(self, address):
   187         self.__dbConnect()
       
   188         address = EmailAddress(address)
   187         address = EmailAddress(address)
       
   188         self.__dbConnect()
   189         return Alias(self._dbh, address)
   189         return Alias(self._dbh, address)
   190 
   190 
   191     def __getRelocated(self, address, destination=None):
   191     def __getRelocated(self, address):
   192         self.__dbConnect()
       
   193         address = EmailAddress(address)
   192         address = EmailAddress(address)
   194         if destination is not None:
   193         self.__dbConnect()
   195             destination = EmailAddress(destination)
   194         return Relocated(self._dbh, address)
   196         return Relocated(self._dbh, address, destination)
       
   197 
   195 
   198     def __getDomain(self, domainname, transport=None):
   196     def __getDomain(self, domainname, transport=None):
   199         if transport is None:
   197         if transport is None:
   200             transport = self._Cfg.dget('misc.transport')
   198             transport = self._Cfg.dget('misc.transport')
   201         self.__dbConnect()
   199         self.__dbConnect()
   657    Please use the service name “sieve” instead.'))
   655    Please use the service name “sieve” instead.'))
   658         acc = self.__getAccount(emailaddress)
   656         acc = self.__getAccount(emailaddress)
   659         acc.enable(self._Cfg.dget('misc.dovecot_version'), service)
   657         acc.enable(self._Cfg.dget('misc.dovecot_version'), service)
   660 
   658 
   661     def relocatedAdd(self, emailaddress, targetaddress):
   659     def relocatedAdd(self, emailaddress, targetaddress):
   662         relocated = self.__getRelocated(emailaddress, targetaddress)
   660         """Creates a new `Relocated` entry in the database. If there is
   663         relocated.save()
   661         already a relocated user with the given *emailaddress*, only the
       
   662         *targetaddress* for the relocated user will be updated."""
       
   663         relocated = self.__getRelocated(emailaddress)
       
   664         relocated.setDestination(EmailAddress(targetaddress))
   664 
   665 
   665     def relocatedInfo(self, emailaddress):
   666     def relocatedInfo(self, emailaddress):
       
   667         """Returns the target address of the relocated user with the given
       
   668         *emailaddress*."""
   666         relocated = self.__getRelocated(emailaddress)
   669         relocated = self.__getRelocated(emailaddress)
   667         return relocated.getInfo()
   670         return relocated.getInfo()
   668 
   671 
   669     def relocatedDelete(self, emailaddress):
   672     def relocatedDelete(self, emailaddress):
       
   673         """Deletes the relocated user with the given *emailaddress* from
       
   674         the database."""
   670         relocated = self.__getRelocated(emailaddress)
   675         relocated = self.__getRelocated(emailaddress)
   671         relocated.delete()
   676         relocated.delete()
   672 
   677 
   673     def __del__(self):
   678     def __del__(self):
   674         if isinstance(self._dbh, PgSQL.Connection) and self._dbh._isOpen:
   679         if isinstance(self._dbh, PgSQL.Connection) and self._dbh._isOpen: