VirtualMailManager/Alias.py
branchv0.6.x
changeset 290 e2785e04f92e
parent 281 59ff7c719697
child 295 18086c6a2521
equal deleted inserted replaced
289:142f188f7552 290:e2785e04f92e
    38         self.__load_dests()
    38         self.__load_dests()
    39 
    39 
    40     def __load_dests(self):
    40     def __load_dests(self):
    41         """Loads all known destination addresses into the _dests list."""
    41         """Loads all known destination addresses into the _dests list."""
    42         dbc = self._dbh.cursor()
    42         dbc = self._dbh.cursor()
    43         dbc.execute(
    43         dbc.execute('SELECT destination FROM alias WHERE gid = %s AND '
    44                 'SELECT destination FROM alias WHERE gid=%s AND address=%s',
    44                     'address = %s', self._gid, self._addr.localpart)
    45                     self._gid, self._addr.localpart)
       
    46         dests = iter(dbc.fetchall())
    45         dests = iter(dbc.fetchall())
    47         if dbc.rowcount > 0:
    46         if dbc.rowcount > 0:
    48             self._dests.extend(EmailAddress(dest[0]) for dest in dests)
    47             self._dests.extend(EmailAddress(dest[0]) for dest in dests)
    49         dbc.close()
    48         dbc.close()
    50 
    49 
    79         its destination addresses will be deleted.
    78         its destination addresses will be deleted.
    80 
    79 
    81         """
    80         """
    82         dbc = self._dbh.cursor()
    81         dbc = self._dbh.cursor()
    83         if not destination:
    82         if not destination:
    84             dbc.execute("DELETE FROM alias WHERE gid=%s AND address=%s",
    83             dbc.execute('DELETE FROM alias WHERE gid = %s AND address = %s',
    85                         self._gid, self._addr.localpart)
    84                         self._gid, self._addr.localpart)
    86         else:
    85         else:
    87             dbc.execute("DELETE FROM alias WHERE gid=%s AND address=%s AND \
    86             dbc.execute('DELETE FROM alias WHERE gid = %s AND address = %s '
    88  destination=%s",
    87                         'AND destination = %s', self._gid,
    89                         self._gid, self._addr.localpart, str(destination))
    88                         self._addr.localpart, str(destination))
    90         if dbc.rowcount > 0:
    89         if dbc.rowcount > 0:
    91             self._dbh.commit()
    90             self._dbh.commit()
    92         dbc.close()
    91         dbc.close()
    93 
    92 
    94     def __len__(self):
    93     def __len__(self):
   139         assert isinstance(destination, EmailAddress)
   138         assert isinstance(destination, EmailAddress)
   140         if not self._dests:
   139         if not self._dests:
   141             raise AErr(_(u"The alias '%s' doesn't exist.") % self._addr,
   140             raise AErr(_(u"The alias '%s' doesn't exist.") % self._addr,
   142                        NO_SUCH_ALIAS)
   141                        NO_SUCH_ALIAS)
   143         if not destination in self._dests:
   142         if not destination in self._dests:
   144             raise AErr(_(u"The address '%(d)s' isn't a destination of \
   143             raise AErr(_(u"The address '%(addr)s' isn't a destination of "
   145 the alias '%(a)s'.") %
   144                          u"the alias '%(alias)s'.") % {'addr': self._addr,
   146                        {'a': self._addr, 'd': destination},
   145                        'alias': destination}, NO_SUCH_ALIAS)
   147                        NO_SUCH_ALIAS)
       
   148         self.__delete(destination)
   146         self.__delete(destination)
   149         self._dests.remove(destination)
   147         self._dests.remove(destination)
   150 
   148 
   151     def get_destinations(self):
   149     def get_destinations(self):
   152         """Returns an iterator for all destinations of the alias."""
   150         """Returns an iterator for all destinations of the alias."""