VirtualMailManager/Alias.py
branchv0.6.x
changeset 213 1a9fee6b93bc
parent 203 4d601240b7db
child 215 33f727efa7c4
equal deleted inserted replaced
212:77ac6f572855 213:1a9fee6b93bc
    21 class Alias(object):
    21 class Alias(object):
    22     """Class to manage e-mail aliases."""
    22     """Class to manage e-mail aliases."""
    23     __slots__ = ('_addr', '_dests', '_gid', '_dbh')
    23     __slots__ = ('_addr', '_dests', '_gid', '_dbh')
    24 
    24 
    25     def __init__(self, dbh, address):
    25     def __init__(self, dbh, address):
    26         if not isinstance(address, EmailAddress):
    26         assert isinstance(address, EmailAddress)
    27             raise TypeError("Argument 'address' is not an EmailAddress")
       
    28         self._addr = address
    27         self._addr = address
    29         self._dbh = dbh
    28         self._dbh = dbh
    30         self._gid = get_gid(self._dbh, self._addr.domainname)
    29         self._gid = get_gid(self._dbh, self._addr.domainname)
    31         self._dests = []
    30         self._dests = []
    32 
    31 
    88         """Returns the number of destinations of the alias."""
    87         """Returns the number of destinations of the alias."""
    89         return len(self._dests)
    88         return len(self._dests)
    90 
    89 
    91     def addDestination(self, destination, expansion_limit):
    90     def addDestination(self, destination, expansion_limit):
    92         """Adds the ``destination`` `EmailAddress` to the alias."""
    91         """Adds the ``destination`` `EmailAddress` to the alias."""
    93         if not isinstance(destination, EmailAddress):
    92         assert isinstance(destination, EmailAddress)
    94             raise TypeError("Argument 'destination' is not an EmailAddress")
       
    95         if self._addr == destination:
    93         if self._addr == destination:
    96             raise VMMAE(_(u"Address and destination are identical."),
    94             raise VMMAE(_(u"Address and destination are identical."),
    97                         ALIAS_ADDR_DEST_IDENTICAL)
    95                         ALIAS_ADDR_DEST_IDENTICAL)
    98         if destination in self._dests:
    96         if destination in self._dests:
    99             raise VMMAE(_(
    97             raise VMMAE(_(
   109         dbc.close()
   107         dbc.close()
   110         self._dests.append(destination)
   108         self._dests.append(destination)
   111 
   109 
   112     def delDestination(self, destination):
   110     def delDestination(self, destination):
   113         """Deletes the specified ``destination`` address from the alias."""
   111         """Deletes the specified ``destination`` address from the alias."""
   114         if not isinstance(destination, EmailAddress):
   112         assert isinstance(destination, EmailAddress)
   115             raise TypeError("Argument 'destination' is not an EmailAddress")
       
   116         if not self._dests:
   113         if not self._dests:
   117             raise VMMAE(_(u"The alias %r doesn't exist.") % str(self._addr),
   114             raise VMMAE(_(u"The alias %r doesn't exist.") % str(self._addr),
   118                         NO_SUCH_ALIAS)
   115                         NO_SUCH_ALIAS)
   119         if not destination in self._dests:
   116         if not destination in self._dests:
   120             raise VMMAE(_(u"The address %(d)r isn't a destination of \
   117             raise VMMAE(_(u"The address %(d)r isn't a destination of \