VirtualMailManager/handler.py
changeset 618 d8736bb80bdc
parent 611 8e9b0046bc8f
child 637 ca6621caff2f
child 675 d24f094d1cb5
equal deleted inserted replaced
617:9eecf0160c39 618:d8736bb80bdc
   709             return alias.get_destinations()
   709             return alias.get_destinations()
   710         if not self._is_other_address(alias.address, TYPE_ALIAS):
   710         if not self._is_other_address(alias.address, TYPE_ALIAS):
   711             raise VMMError(_(u"The alias '%s' does not exist.") %
   711             raise VMMError(_(u"The alias '%s' does not exist.") %
   712                            alias.address, NO_SUCH_ALIAS)
   712                            alias.address, NO_SUCH_ALIAS)
   713 
   713 
   714     def alias_delete(self, aliasaddress, targetaddress=None):
   714     def alias_delete(self, aliasaddress, targetaddresses=None):
   715         """Deletes the `Alias` *aliasaddress* with all its destinations from
   715         """Deletes the `Alias` *aliasaddress* with all its destinations from
   716         the database. If *targetaddress* is not ``None``, only this
   716         the database. If *targetaddresses* is not ``None``, only the given
   717         destination will be removed from the alias."""
   717         destinations will be removed from the alias."""
   718         alias = self._get_alias(aliasaddress)
   718         alias = self._get_alias(aliasaddress)
   719         if targetaddress is None:
   719         error = None
       
   720         if targetaddresses is None:
   720             alias.delete()
   721             alias.delete()
   721         else:
   722         else:
   722             alias.del_destination(DestinationEmailAddress(targetaddress,
   723             destinations = [DestinationEmailAddress(addr, self._dbh)
   723                                                           self._dbh))
   724                             for addr in targetaddresses]
       
   725             warnings = []
       
   726             try:
       
   727                 alias.del_destinations(destinations, warnings)
       
   728             except VMMError, err:
       
   729                 error = err
       
   730             if warnings:
       
   731                 self._warnings.append(_('Ignored destination addresses:'))
       
   732                 self._warnings.extend(('  * %s' % w for w in warnings))
       
   733             if error:
       
   734                 raise error
   724 
   735 
   725     def catchall_add(self, domain, *targetaddresses):
   736     def catchall_add(self, domain, *targetaddresses):
   726         """Creates a new `CatchallAlias` entry for the given *domain* with
   737         """Creates a new `CatchallAlias` entry for the given *domain* with
   727         the given *targetaddresses*."""
   738         the given *targetaddresses*."""
   728         catchall = self._get_catchall(domain)
   739         catchall = self._get_catchall(domain)
   742     def catchall_info(self, domain):
   753     def catchall_info(self, domain):
   743         """Returns an iterator object for all destinations (`EmailAddress`
   754         """Returns an iterator object for all destinations (`EmailAddress`
   744         instances) for the `CatchallAlias` with the given *domain*."""
   755         instances) for the `CatchallAlias` with the given *domain*."""
   745         return self._get_catchall(domain).get_destinations()
   756         return self._get_catchall(domain).get_destinations()
   746 
   757 
   747     def catchall_delete(self, domain, targetaddress=None):
   758     def catchall_delete(self, domain, targetaddresses=None):
   748         """Deletes the `CatchallAlias` for domain *domain* with all its
   759         """Deletes the `CatchallAlias` for domain *domain* with all its
   749         destinations from the database. If *targetaddress* is not ``None``,
   760         destinations from the database.  If *targetaddresses* is not
   750         only this destination will be removed from the alias."""
   761         ``None``,  only those destinations will be removed from the alias."""
   751         catchall = self._get_catchall(domain)
   762         catchall = self._get_catchall(domain)
   752         if targetaddress is None:
   763         error = None
       
   764         if targetaddresses is None:
   753             catchall.delete()
   765             catchall.delete()
   754         else:
   766         else:
   755             catchall.del_destination(DestinationEmailAddress(targetaddress,
   767             destinations = [DestinationEmailAddress(addr, self._dbh)
   756                                                              self._dbh))
   768                             for addr in targetaddresses]
       
   769             warnings = []
       
   770             try:
       
   771                 catchall.del_destinations(destinations, warnings)
       
   772             except VMMError, err:
       
   773                 error = err
       
   774             if warnings:
       
   775                 self._warnings.append(_('Ignored destination addresses:'))
       
   776                 self._warnings.extend(('  * %s' % w for w in warnings))
       
   777             if error:
       
   778                 raise error
   757 
   779 
   758     def user_info(self, emailaddress, details=None):
   780     def user_info(self, emailaddress, details=None):
   759         """Wrapper around Account.get_info(...)"""
   781         """Wrapper around Account.get_info(...)"""
   760         if details not in (None, 'du', 'aliases', 'full'):
   782         if details not in (None, 'du', 'aliases', 'full'):
   761             raise VMMError(_(u"Invalid argument: '%s'") % details,
   783             raise VMMError(_(u"Invalid argument: '%s'") % details,