VirtualMailManager/VirtualMailManager.py
changeset 80 5dedc673524e
parent 78 8f1e501b1bb1
child 83 cc195af37de0
equal deleted inserted replaced
79:0ae7597eed11 80:5dedc673524e
   192  domain_name WHERE domainname = '%(_domainname)s') AND address =\
   192  domain_name WHERE domainname = '%(_domainname)s') AND address =\
   193  '%(_localpart)s'" % address.__dict__
   193  '%(_localpart)s'" % address.__dict__
   194         return VirtualMailManager._exists(dbh, sql)
   194         return VirtualMailManager._exists(dbh, sql)
   195     relocatedExists = staticmethod(relocatedExists)
   195     relocatedExists = staticmethod(relocatedExists)
   196 
   196 
   197     def __getAccount(self, address, password=None):
       
   198         self.__dbConnect()
       
   199         address = EmailAddress(address)
       
   200         if not password is None:
       
   201             password = self.__pwhash(password)
       
   202         return Account(self.__dbh, address, password)
       
   203 
       
   204     def _readpass(self):
   197     def _readpass(self):
   205         mismatched = True
   198         mismatched = True
   206         while mismatched:
   199         while mismatched:
   207             clear0 = getpass(prompt=_('Enter new password: '))
   200             clear0 = getpass(prompt=_('Enter new password: '))
   208             clear1 = getpass(prompt=_('Retype new password: '))
   201             clear1 = getpass(prompt=_('Retype new password: '))
   214                         % _('Sorry, empty passwords are not permitted'))
   207                         % _('Sorry, empty passwords are not permitted'))
   215                 continue
   208                 continue
   216             mismatched = False
   209             mismatched = False
   217         return clear0
   210         return clear0
   218 
   211 
       
   212     def __getAccount(self, address, password=None):
       
   213         self.__dbConnect()
       
   214         address = EmailAddress(address)
       
   215         if not password is None:
       
   216             password = self.__pwhash(password)
       
   217         return Account(self.__dbh, address, password)
       
   218 
   219     def __getAlias(self, address, destination=None):
   219     def __getAlias(self, address, destination=None):
   220         self.__dbConnect()
   220         self.__dbConnect()
   221         address = EmailAddress(address)
   221         address = EmailAddress(address)
   222         if destination is not None:
   222         if destination is not None:
   223             destination = EmailAddress(destination)
   223             destination = EmailAddress(destination)
   224         return Alias(self.__dbh, address, destination)
   224         return Alias(self.__dbh, address, destination)
       
   225 
       
   226     def __getRelocated(self,address, destination=None):
       
   227         self.__dbConnect()
       
   228         address = EmailAddress(address)
       
   229         if destination is not None:
       
   230             destination = EmailAddress(destination)
       
   231         return Relocated(self.__dbh, address, destination)
   225 
   232 
   226     def __getDomain(self, domainname, transport=None):
   233     def __getDomain(self, domainname, transport=None):
   227         if transport is None:
   234         if transport is None:
   228             transport = self.__Cfg.get('misc', 'transport')
   235             transport = self.__Cfg.get('misc', 'transport')
   229         self.__dbConnect()
   236         self.__dbConnect()
   493         if self.__Cfg.getboolean('domdir', 'delete'):
   500         if self.__Cfg.getboolean('domdir', 'delete'):
   494             self.__domDirDelete(domdir, gid)
   501             self.__domDirDelete(domdir, gid)
   495 
   502 
   496     def domainInfo(self, domainname, details=None):
   503     def domainInfo(self, domainname, details=None):
   497         if details not in [None, 'accounts', 'aliasdomains', 'aliases', 'full',
   504         if details not in [None, 'accounts', 'aliasdomains', 'aliases', 'full',
   498                 'detailed']:
   505                 'relocated', 'detailed']:
   499             raise VMMDomainException(_(u'Invalid argument: »%s«') % details,
   506             raise VMMDomainException(_(u'Invalid argument: »%s«') % details,
   500                 ERR.INVALID_OPTION)
   507                 ERR.INVALID_OPTION)
   501         if details == 'detailed':
   508         if details == 'detailed':
   502             details = 'full'
   509             details = 'full'
   503             warning = _(u"""\
   510             warning = _(u"""\
   517             return (dominfo, dom.getAccounts())
   524             return (dominfo, dom.getAccounts())
   518         elif details == 'aliasdomains':
   525         elif details == 'aliasdomains':
   519             return (dominfo, dom.getAliaseNames())
   526             return (dominfo, dom.getAliaseNames())
   520         elif details == 'aliases':
   527         elif details == 'aliases':
   521             return (dominfo, dom.getAliases())
   528             return (dominfo, dom.getAliases())
       
   529         elif details == 'relocated':
       
   530             return(dominfo, dom.getRelocated())
   522         else:
   531         else:
   523             return (dominfo, dom.getAliaseNames(), dom.getAccounts(),
   532             return (dominfo, dom.getAliaseNames(), dom.getAccounts(),
   524                     dom.getAliases())
   533                     dom.getAliases(), dom.getRelocated())
   525 
   534 
   526     def aliasDomainAdd(self, aliasname, domainname):
   535     def aliasDomainAdd(self, aliasname, domainname):
   527         """Adds an alias domain to the domain.
   536         """Adds an alias domain to the domain.
   528 
   537 
   529         Keyword arguments:
   538         Keyword arguments:
   661 
   670 
   662     def userEnable(self, emailaddress, service=None):
   671     def userEnable(self, emailaddress, service=None):
   663         acc = self.__getAccount(emailaddress)
   672         acc = self.__getAccount(emailaddress)
   664         acc.enable(service)
   673         acc.enable(service)
   665 
   674 
       
   675     def relocatedAdd(self, emailaddress, targetaddress):
       
   676         relocated = self.__getRelocated(emailaddress, targetaddress)
       
   677         relocated.save()
       
   678 
       
   679     def relocatedInfo(self, emailaddress):
       
   680         relocated = self.__getRelocated(emailaddress)
       
   681         return relocated.getInfo()
       
   682 
       
   683     def relocatedDelete(self, emailaddress):
       
   684         relocated = self.__getRelocated(emailaddress)
       
   685         relocated.delete()
       
   686 
   666     def __del__(self):
   687     def __del__(self):
   667         if not self.__dbh is None and self.__dbh._isOpen:
   688         if not self.__dbh is None and self.__dbh._isOpen:
   668             self.__dbh.close()
   689             self.__dbh.close()