VirtualMailManager/Alias.py
branchv0.6.x
changeset 215 33f727efa7c4
parent 213 1a9fee6b93bc
child 216 0c8c053b451c
equal deleted inserted replaced
214:84e6e898e6c5 215:33f727efa7c4
    66             raise VMMAE(errmsg % {'address': str(self._addr), 'count': dcount,
    66             raise VMMAE(errmsg % {'address': str(self._addr), 'count': dcount,
    67                                   'limit': limit},
    67                                   'limit': limit},
    68                         ALIAS_EXCEEDS_EXPANSION_LIMIT)
    68                         ALIAS_EXCEEDS_EXPANSION_LIMIT)
    69 
    69 
    70     def __delete(self, destination=None):
    70     def __delete(self, destination=None):
    71         """Deletes a destination from the alias, if ``destination`` is not
    71         """Deletes a destination from the alias, if ``destination`` is
    72         ``None``. If ``destination`` is None, the alias with all it's
    72         not ``None``.  If ``destination`` is None, the alias with all
    73         destination addresses will be deleted."""
    73         it's destination addresses will be deleted.
       
    74 
       
    75         """
    74         dbc = self._dbh.cursor()
    76         dbc = self._dbh.cursor()
    75         if not destination:
    77         if not destination:
    76             dbc.execute("DELETE FROM alias WHERE gid=%s AND address=%s",
    78             dbc.execute("DELETE FROM alias WHERE gid=%s AND address=%s",
    77                         self._gid, self._addr.localpart)
    79                         self._gid, self._addr.localpart)
    78         else:
    80         else:
    85 
    87 
    86     def __len__(self):
    88     def __len__(self):
    87         """Returns the number of destinations of the alias."""
    89         """Returns the number of destinations of the alias."""
    88         return len(self._dests)
    90         return len(self._dests)
    89 
    91 
    90     def addDestination(self, destination, expansion_limit):
    92     def add_destination(self, destination, expansion_limit):
    91         """Adds the ``destination`` `EmailAddress` to the alias."""
    93         """Adds the ``destination`` `EmailAddress` to the alias."""
    92         assert isinstance(destination, EmailAddress)
    94         assert isinstance(destination, EmailAddress)
    93         if self._addr == destination:
    95         if self._addr == destination:
    94             raise VMMAE(_(u"Address and destination are identical."),
    96             raise VMMAE(_(u"Address and destination are identical."),
    95                         ALIAS_ADDR_DEST_IDENTICAL)
    97                         ALIAS_ADDR_DEST_IDENTICAL)
   105                     self._gid, self._addr.localpart, str(destination))
   107                     self._gid, self._addr.localpart, str(destination))
   106         self._dbh.commit()
   108         self._dbh.commit()
   107         dbc.close()
   109         dbc.close()
   108         self._dests.append(destination)
   110         self._dests.append(destination)
   109 
   111 
   110     def delDestination(self, destination):
   112     def del_destination(self, destination):
   111         """Deletes the specified ``destination`` address from the alias."""
   113         """Deletes the specified ``destination`` address from the alias."""
   112         assert isinstance(destination, EmailAddress)
   114         assert isinstance(destination, EmailAddress)
   113         if not self._dests:
   115         if not self._dests:
   114             raise VMMAE(_(u"The alias %r doesn't exist.") % str(self._addr),
   116             raise VMMAE(_(u"The alias %r doesn't exist.") % str(self._addr),
   115                         NO_SUCH_ALIAS)
   117                         NO_SUCH_ALIAS)
   119                         {'a': str(self._addr), 'd': str(destination)},
   121                         {'a': str(self._addr), 'd': str(destination)},
   120                         NO_SUCH_ALIAS)
   122                         NO_SUCH_ALIAS)
   121         self.__delete(destination)
   123         self.__delete(destination)
   122         self._dests.remove(destination)
   124         self._dests.remove(destination)
   123 
   125 
   124     def getDestinations(self):
   126     def get_destinations(self):
   125         """Returns an iterator for all destinations of the alias."""
   127         """Returns an iterator for all destinations of the alias."""
   126         if not self._dests:
   128         if not self._dests:
   127             raise VMMAE(_(u"The alias %r doesn't exist.") % str(self._addr),
   129             raise VMMAE(_(u"The alias %r doesn't exist.") % str(self._addr),
   128                         NO_SUCH_ALIAS)
   130                         NO_SUCH_ALIAS)
   129         return iter(self._dests)
   131         return iter(self._dests)