VirtualMailManager/handler.py
changeset 611 8e9b0046bc8f
parent 605 b994444f7dee
child 618 d8736bb80bdc
equal deleted inserted replaced
610:b6c4e77046b9 611:8e9b0046bc8f
    53 OTHER_TYPES = {
    53 OTHER_TYPES = {
    54     TYPE_ACCOUNT: (_(u'an account'), ACCOUNT_EXISTS),
    54     TYPE_ACCOUNT: (_(u'an account'), ACCOUNT_EXISTS),
    55     TYPE_ALIAS: (_(u'an alias'), ALIAS_EXISTS),
    55     TYPE_ALIAS: (_(u'an alias'), ALIAS_EXISTS),
    56     TYPE_RELOCATED: (_(u'a relocated user'), RELOCATED_EXISTS),
    56     TYPE_RELOCATED: (_(u'a relocated user'), RELOCATED_EXISTS),
    57 }
    57 }
       
    58 
    58 
    59 
    59 class Handler(object):
    60 class Handler(object):
    60     """Wrapper class to simplify the access on all the stuff from
    61     """Wrapper class to simplify the access on all the stuff from
    61     VirtualMailManager"""
    62     VirtualMailManager"""
    62     __slots__ = ('_cfg', '_cfg_fname', '_db_connect', '_dbh', '_warnings')
    63     __slots__ = ('_cfg', '_cfg_fname', '_db_connect', '_dbh', '_warnings')
   619                     checkp = lpattern.strip('%')
   620                     checkp = lpattern.strip('%')
   620                 else:
   621                 else:
   621                     checkp = lpattern
   622                     checkp = lpattern
   622                 if len(checkp) > 0 and re.search(RE_LOCALPART, checkp):
   623                 if len(checkp) > 0 and re.search(RE_LOCALPART, checkp):
   623                     raise VMMError(_(u"The pattern '%s' contains invalid "
   624                     raise VMMError(_(u"The pattern '%s' contains invalid "
   624                                      u"characters.") % pattern, LOCALPART_INVALID)
   625                                      u"characters.") % pattern,
       
   626                                    LOCALPART_INVALID)
   625             else:
   627             else:
   626                 # else just match on domains
   628                 # else just match on domains
   627                 # (or should that be local part, I don't know…)
   629                 # (or should that be local part, I don't know…)
   628                 dpattern = parts[0]
   630                 dpattern = parts[0]
   629                 dlike = dpattern.startswith('%') or dpattern.endswith('%')
   631                 dlike = dpattern.startswith('%') or dpattern.endswith('%')
   656         """Creates a new `Alias` entry for the given *aliasaddress* with
   658         """Creates a new `Alias` entry for the given *aliasaddress* with
   657         the given *targetaddresses*."""
   659         the given *targetaddresses*."""
   658         alias = self._get_alias(aliasaddress)
   660         alias = self._get_alias(aliasaddress)
   659         if not alias:
   661         if not alias:
   660             self._is_other_address(alias.address, TYPE_ALIAS)
   662             self._is_other_address(alias.address, TYPE_ALIAS)
   661         destinations = [DestinationEmailAddress(addr, self._dbh) \
   663         destinations = [DestinationEmailAddress(addr, self._dbh)
   662                 for addr in targetaddresses]
   664                         for addr in targetaddresses]
   663         warnings = []
   665         warnings = []
   664         destinations = alias.add_destinations(destinations, warnings)
   666         destinations = alias.add_destinations(destinations, warnings)
   665         if warnings:
   667         if warnings:
   666             self._warnings.append(_('Ignored destination addresses:'))
   668             self._warnings.append(_('Ignored destination addresses:'))
   667             self._warnings.extend(('  * %s' % w for w in warnings))
   669             self._warnings.extend(('  * %s' % w for w in warnings))
   722 
   724 
   723     def catchall_add(self, domain, *targetaddresses):
   725     def catchall_add(self, domain, *targetaddresses):
   724         """Creates a new `CatchallAlias` entry for the given *domain* with
   726         """Creates a new `CatchallAlias` entry for the given *domain* with
   725         the given *targetaddresses*."""
   727         the given *targetaddresses*."""
   726         catchall = self._get_catchall(domain)
   728         catchall = self._get_catchall(domain)
   727         destinations = [DestinationEmailAddress(addr, self._dbh) \
   729         destinations = [DestinationEmailAddress(addr, self._dbh)
   728                 for addr in targetaddresses]
   730                         for addr in targetaddresses]
   729         warnings = []
   731         warnings = []
   730         destinations = catchall.add_destinations(destinations, warnings)
   732         destinations = catchall.add_destinations(destinations, warnings)
   731         if warnings:
   733         if warnings:
   732             self._warnings.append(_('Ignored destination addresses:'))
   734             self._warnings.append(_('Ignored destination addresses:'))
   733             self._warnings.extend(('  * %s' % w for w in warnings))
   735             self._warnings.extend(('  * %s' % w for w in warnings))