VirtualMailManager/Alias.py
changeset 155 eb866ebb9f2e
parent 147 e3fd0b67ae50
child 162 0ac9ef587769
equal deleted inserted replaced
154:6e6488722807 155:eb866ebb9f2e
    52 
    52 
    53     def _setAddr(self):
    53     def _setAddr(self):
    54         dom = Domain(self._dbh, self._addr._domainname)
    54         dom = Domain(self._dbh, self._addr._domainname)
    55         self._gid = dom.getID()
    55         self._gid = dom.getID()
    56         if self._gid == 0:
    56         if self._gid == 0:
    57             raise VMMAE(_(u"The domain “%s” doesn't exist yet.") %\
    57             raise VMMAE(_(u"The domain “%s” doesn't exist.") %\
    58                     self._addr._domainname, ERR.NO_SUCH_DOMAIN)
    58                     self._addr._domainname, ERR.NO_SUCH_DOMAIN)
    59 
    59 
    60     def _checkExpansion(self, limit):
    60     def _checkExpansion(self, limit):
    61         dbc = self._dbh.cursor()
    61         dbc = self._dbh.cursor()
    62         dbc.execute('SELECT count(gid) FROM alias where gid=%s AND address=%s',
    62         dbc.execute('SELECT count(gid) FROM alias where gid=%s AND address=%s',
    71 """) % {'address': self._addr, 'count': curEx}
    71 """) % {'address': self._addr, 'count': curEx}
    72             raise VMMAE(errmsg, ERR.ALIAS_EXCEEDS_EXPANSION_LIMIT)
    72             raise VMMAE(errmsg, ERR.ALIAS_EXCEEDS_EXPANSION_LIMIT)
    73 
    73 
    74     def save(self, expansion_limit):
    74     def save(self, expansion_limit):
    75         if self._dest is None:
    75         if self._dest is None:
    76            raise VMMAE(_(u"No destination address for alias denoted."),
    76            raise VMMAE(_(u"No destination address specified for alias."),
    77                ERR.ALIAS_MISSING_DEST)
    77                ERR.ALIAS_MISSING_DEST)
    78         if self._isNew:
    78         if self._isNew:
    79             self._checkExpansion(expansion_limit)
    79             self._checkExpansion(expansion_limit)
    80             dbc = self._dbh.cursor()
    80             dbc = self._dbh.cursor()
    81             dbc.execute("INSERT INTO alias (gid, address, destination) VALUES\
    81             dbc.execute("INSERT INTO alias (gid, address, destination) VALUES\
    95         dbc.close()
    95         dbc.close()
    96         if len(destinations) > 0:
    96         if len(destinations) > 0:
    97             targets = [destination[0] for destination in destinations]
    97             targets = [destination[0] for destination in destinations]
    98             return targets
    98             return targets
    99         else:
    99         else:
   100             raise VMMAE(_(u"The alias “%s” doesn't exists.") % self._addr,
   100             raise VMMAE(_(u"The alias “%s” doesn't exist.") % self._addr,
   101                     ERR.NO_SUCH_ALIAS)
   101                     ERR.NO_SUCH_ALIAS)
   102 
   102 
   103     def delete(self):
   103     def delete(self):
   104         dbc = self._dbh.cursor()
   104         dbc = self._dbh.cursor()
   105         if self._dest is None:
   105         if self._dest is None:
   112         dbc.close()
   112         dbc.close()
   113         if rowcount > 0:
   113         if rowcount > 0:
   114             self._dbh.commit()
   114             self._dbh.commit()
   115         else:
   115         else:
   116             if self._dest is None:
   116             if self._dest is None:
   117                 msg = _(u"The alias “%s” doesn't exists.") % self._addr
   117                 msg = _(u"The alias “%s” doesn't exist.") % self._addr
   118             else:
   118             else:
   119                 msg = _(u"The alias “%(a)s” with destination “%(d)s” doesn't\
   119                 msg = _(u"The alias “%(a)s” with destination “%(d)s” doesn't\
   120  exists.") % {'a': self._addr, 'd': self._dest}
   120  exist.") % {'a': self._addr, 'd': self._dest}
   121             raise VMMAE(msg, ERR.NO_SUCH_ALIAS)
   121             raise VMMAE(msg, ERR.NO_SUCH_ALIAS)
   122 
   122