VirtualMailManager/Alias.py
branchv0.6.x
changeset 198 02d467e4fbab
parent 196 65a3163bd113
child 203 4d601240b7db
equal deleted inserted replaced
197:d2712e8c724e 198:02d467e4fbab
     6     VirtualMailManager.Alias
     6     VirtualMailManager.Alias
     7 
     7 
     8     Virtual Mail Manager's Alias class to manage e-mail aliases.
     8     Virtual Mail Manager's Alias class to manage e-mail aliases.
     9 """
     9 """
    10 
    10 
    11 from VirtualMailManager.Domain import Domain
    11 from VirtualMailManager.Domain import get_gid
    12 from VirtualMailManager.EmailAddress import EmailAddress
    12 from VirtualMailManager.EmailAddress import EmailAddress
    13 from VirtualMailManager.Exceptions import VMMAliasException as VMMAE
    13 from VirtualMailManager.Exceptions import VMMAliasException as VMMAE
    14 from VirtualMailManager.constants.ERROR import ALIAS_ADDR_DEST_IDENTICAL, \
    14 from VirtualMailManager.constants.ERROR import ALIAS_ADDR_DEST_IDENTICAL, \
    15      ALIAS_EXCEEDS_EXPANSION_LIMIT, ALIAS_EXISTS, NO_SUCH_ALIAS, NO_SUCH_DOMAIN
    15      ALIAS_EXCEEDS_EXPANSION_LIMIT, ALIAS_EXISTS, NO_SUCH_ALIAS
    16 
    16 
    17 
    17 
    18 _ = lambda msg: msg
    18 _ = lambda msg: msg
    19 
    19 
    20 
    20 
    26         if isinstance(address, EmailAddress):
    26         if isinstance(address, EmailAddress):
    27             self._addr = address
    27             self._addr = address
    28         else:
    28         else:
    29             raise TypeError("Argument 'address' is not an EmailAddress")
    29             raise TypeError("Argument 'address' is not an EmailAddress")
    30         self._dbh = dbh
    30         self._dbh = dbh
    31         self._gid = 0
    31         self._gid = get_gid(self._dbh, self._addr.domainname)
    32         self._dests = []
    32         self._dests = []
    33 
    33 
    34         self.__set_gid()
       
    35         self.__load_dests()
    34         self.__load_dests()
    36 
       
    37     def __set_gid(self):
       
    38         """Sets the alias' _gid based on its _addr.domainname."""
       
    39         dom = Domain(self._dbh, self._addr.domainname)
       
    40         self._gid = dom.getID()
       
    41         if self._gid == 0:
       
    42             raise VMMAE(_(u"The domain ā€œ%sā€ doesn't exist.") %
       
    43                         self._addr.domainname, NO_SUCH_DOMAIN)
       
    44 
    35 
    45     def __load_dests(self):
    36     def __load_dests(self):
    46         """Loads all known destination addresses into the _dests list."""
    37         """Loads all known destination addresses into the _dests list."""
    47         dbc = self._dbh.cursor()
    38         dbc = self._dbh.cursor()
    48         dbc.execute(
    39         dbc.execute(