VirtualMailManager/handler.py
branchv0.6.x
changeset 505 3da8c919584f
parent 493 30365a87650d
child 508 18870919ec48
equal deleted inserted replaced
504:f180ead60568 505:3da8c919584f
    19 from subprocess import Popen, PIPE
    19 from subprocess import Popen, PIPE
    20 
    20 
    21 from VirtualMailManager.account import Account
    21 from VirtualMailManager.account import Account
    22 from VirtualMailManager.alias import Alias
    22 from VirtualMailManager.alias import Alias
    23 from VirtualMailManager.aliasdomain import AliasDomain
    23 from VirtualMailManager.aliasdomain import AliasDomain
       
    24 from VirtualMailManager.catchall import CatchallAlias
    24 from VirtualMailManager.common import exec_ok, lisdir
    25 from VirtualMailManager.common import exec_ok, lisdir
    25 from VirtualMailManager.config import Config as Cfg
    26 from VirtualMailManager.config import Config as Cfg
    26 from VirtualMailManager.constants import MIN_GID, MIN_UID, \
    27 from VirtualMailManager.constants import MIN_GID, MIN_UID, \
    27      ACCOUNT_EXISTS, ALIAS_EXISTS, CONF_NOFILE, CONF_NOPERM, CONF_WRONGPERM, \
    28      ACCOUNT_EXISTS, ALIAS_EXISTS, CONF_NOFILE, CONF_NOPERM, CONF_WRONGPERM, \
    28      DATABASE_ERROR, DOMAINDIR_GROUP_MISMATCH, DOMAIN_INVALID, \
    29      DATABASE_ERROR, DOMAINDIR_GROUP_MISMATCH, DOMAIN_INVALID, \
   256         """Return an Alias instances for the given address (str)."""
   257         """Return an Alias instances for the given address (str)."""
   257         address = EmailAddress(address)
   258         address = EmailAddress(address)
   258         self._db_connect()
   259         self._db_connect()
   259         return Alias(self._dbh, address)
   260         return Alias(self._dbh, address)
   260 
   261 
       
   262     def _get_catchall(self, domain):
       
   263         """Return a CatchallAlias instances for the given domain (str)."""
       
   264         self._db_connect()
       
   265         return CatchallAlias(self._dbh, domain)
       
   266 
   261     def _get_relocated(self, address):
   267     def _get_relocated(self, address):
   262         """Return a Relocated instances for the given address (str)."""
   268         """Return a Relocated instances for the given address (str)."""
   263         address = EmailAddress(address)
   269         address = EmailAddress(address)
   264         self._db_connect()
   270         self._db_connect()
   265         return Relocated(self._dbh, address)
   271         return Relocated(self._dbh, address)
   669             alias.delete()
   675             alias.delete()
   670         else:
   676         else:
   671             alias.del_destination(DestinationEmailAddress(targetaddress,
   677             alias.del_destination(DestinationEmailAddress(targetaddress,
   672                                                           self._dbh))
   678                                                           self._dbh))
   673 
   679 
       
   680     def catchall_add(self, domain, *targetaddresses):
       
   681         """Creates a new `CatchallAlias` entry for the given *domain* with
       
   682         the given *targetaddresses*."""
       
   683         catchall = self._get_catchall(domain)
       
   684         destinations = [DestinationEmailAddress(addr, self._dbh) \
       
   685                 for addr in targetaddresses]
       
   686         warnings = []
       
   687         destinations = catchall.add_destinations(destinations, warnings)
       
   688         if warnings:
       
   689             self._warnings.append(_('Ignored destination addresses:'))
       
   690             self._warnings.extend(('  * %s' % w for w in warnings))
       
   691         for destination in destinations:
       
   692             if destination.gid and \
       
   693                not self._chk_other_address_types(destination, TYPE_RELOCATED):
       
   694                 self._warnings.append(_(u"The destination account/alias '%s' "
       
   695                                         u"does not exist.") % destination)
       
   696 
       
   697     def catchall_info(self, domain):
       
   698         """Returns an iterator object for all destinations (`EmailAddress`
       
   699         instances) for the `CatchallAlias` with the given *domain*."""
       
   700         return self._get_catchall(domain)
       
   701 
       
   702     def catchall_delete(self, domain, targetaddress=None):
       
   703         """Deletes the `CatchallAlias` for domain *domain* with all its
       
   704         destinations from the database. If *targetaddress* is not ``None``,
       
   705         only this destination will be removed from the alias."""
       
   706         catchall = self._get_catchall(domain)
       
   707         if targetaddress is None:
       
   708             catchall.delete()
       
   709         else:
       
   710             catchall.del_destination(DestinationEmailAddress(targetaddress,
       
   711                                                              self._dbh))
       
   712 
   674     def user_info(self, emailaddress, details=None):
   713     def user_info(self, emailaddress, details=None):
   675         """Wrapper around Account.get_info(...)"""
   714         """Wrapper around Account.get_info(...)"""
   676         if details not in (None, 'du', 'aliases', 'full'):
   715         if details not in (None, 'du', 'aliases', 'full'):
   677             raise VMMError(_(u"Invalid argument: '%s'") % details,
   716             raise VMMError(_(u"Invalid argument: '%s'") % details,
   678                            INVALID_ARGUMENT)
   717                            INVALID_ARGUMENT)