VirtualMailManager/handler.py
branchv0.6.x
changeset 375 4cbaf8d229f9
parent 373 1016a17684c1
child 380 5aaf2dd6b146
equal deleted inserted replaced
374:ecdba68c7a2c 375:4cbaf8d229f9
   244 
   244 
   245     def _get_account(self, address):
   245     def _get_account(self, address):
   246         """Return an Account instances for the given address (str)."""
   246         """Return an Account instances for the given address (str)."""
   247         address = EmailAddress(address)
   247         address = EmailAddress(address)
   248         self._db_connect()
   248         self._db_connect()
   249         self._is_other_address(address, TYPE_ACCOUNT)
       
   250         return Account(self._dbh, address)
   249         return Account(self._dbh, address)
   251 
   250 
   252     def _get_alias(self, address):
   251     def _get_alias(self, address):
   253         """Return an Alias instances for the given address (str)."""
   252         """Return an Alias instances for the given address (str)."""
   254         address = EmailAddress(address)
   253         address = EmailAddress(address)
   255         self._db_connect()
   254         self._db_connect()
   256         self._is_other_address(address, TYPE_ALIAS)
       
   257         return Alias(self._dbh, address)
   255         return Alias(self._dbh, address)
   258 
   256 
   259     def _get_relocated(self, address):
   257     def _get_relocated(self, address):
   260         """Return a Relocated instances for the given address (str)."""
   258         """Return a Relocated instances for the given address (str)."""
   261         address = EmailAddress(address)
   259         address = EmailAddress(address)
   262         self._db_connect()
   260         self._db_connect()
   263         self._is_other_address(address, TYPE_RELOCATED)
       
   264         return Relocated(self._dbh, address)
   261         return Relocated(self._dbh, address)
   265 
   262 
   266     def _get_domain(self, domainname):
   263     def _get_domain(self, domainname):
   267         """Return a Domain instances for the given domain name (str)."""
   264         """Return a Domain instances for the given domain name (str)."""
   268         self._db_connect()
   265         self._db_connect()
   551         """Wrapper around Account.set_password() and Account.save()."""
   548         """Wrapper around Account.set_password() and Account.save()."""
   552         acc = self._get_account(emailaddress)
   549         acc = self._get_account(emailaddress)
   553         if acc:
   550         if acc:
   554             raise VMMError(_(u"The account '%s' already exists.") %
   551             raise VMMError(_(u"The account '%s' already exists.") %
   555                            acc.address, ACCOUNT_EXISTS)
   552                            acc.address, ACCOUNT_EXISTS)
       
   553         other = self._is_other_address(acc.address, TYPE_ACCOUNT)
   556         acc.set_password(password)
   554         acc.set_password(password)
   557         acc.save()
   555         acc.save()
   558         self._make_account_dirs(acc)
   556         self._make_account_dirs(acc)
   559 
   557 
   560     def alias_add(self, aliasaddress, *targetaddresses):
   558     def alias_add(self, aliasaddress, *targetaddresses):
   561         """Creates a new `Alias` entry for the given *aliasaddress* with
   559         """Creates a new `Alias` entry for the given *aliasaddress* with
   562         the given *targetaddresses*."""
   560         the given *targetaddresses*."""
   563         alias = self._get_alias(aliasaddress)
   561         alias = self._get_alias(aliasaddress)
       
   562         if not alias:
       
   563             self._is_other_address(alias.address, TYPE_ALIAS)
   564         destinations = [DestinationEmailAddress(addr, self._dbh) \
   564         destinations = [DestinationEmailAddress(addr, self._dbh) \
   565                 for addr in targetaddresses]
   565                 for addr in targetaddresses]
   566         warnings = []
   566         warnings = []
   567         destinations = alias.add_destinations(destinations, warnings)
   567         destinations = alias.add_destinations(destinations, warnings)
   568         if warnings:
   568         if warnings:
   709     def relocated_add(self, emailaddress, targetaddress):
   709     def relocated_add(self, emailaddress, targetaddress):
   710         """Creates a new `Relocated` entry in the database. If there is
   710         """Creates a new `Relocated` entry in the database. If there is
   711         already a relocated user with the given *emailaddress*, only the
   711         already a relocated user with the given *emailaddress*, only the
   712         *targetaddress* for the relocated user will be updated."""
   712         *targetaddress* for the relocated user will be updated."""
   713         relocated = self._get_relocated(emailaddress)
   713         relocated = self._get_relocated(emailaddress)
       
   714         if not relocated:
       
   715             self._is_other_address(relocated.address, TYPE_RELOCATED)
   714         destination = DestinationEmailAddress(targetaddress, self._dbh)
   716         destination = DestinationEmailAddress(targetaddress, self._dbh)
   715         relocated.set_destination(destination)
   717         relocated.set_destination(destination)
   716         if destination.gid and \
   718         if destination.gid and \
   717            not self._chk_other_address_types(destination, TYPE_RELOCATED):
   719            not self._chk_other_address_types(destination, TYPE_RELOCATED):
   718             self._warnings.append(_(u"The destination account/alias '%s' "
   720             self._warnings.append(_(u"The destination account/alias '%s' "