VirtualMailManager/Alias.py
changeset 88 b3debcfea7bc
parent 82 6c85915f3815
child 89 752d3b57ebb6
equal deleted inserted replaced
87:f9090d1a0730 88:b3debcfea7bc
    64         self._gid = dom.getID()
    64         self._gid = dom.getID()
    65         if self._gid == 0:
    65         if self._gid == 0:
    66             raise VMMAE(_(u"The domain »%s« doesn't exist yet.") %\
    66             raise VMMAE(_(u"The domain »%s« doesn't exist yet.") %\
    67                     self._addr._domainname, ERR.NO_SUCH_DOMAIN)
    67                     self._addr._domainname, ERR.NO_SUCH_DOMAIN)
    68 
    68 
    69     def save(self):
    69     def _checkExpansion(self, limit):
       
    70         dbc = self._dbh.cursor()
       
    71         dbc.execute('SELECT count(gid) FROM alias where gid=%s AND address=%s',
       
    72                 self._gid, self._addr._localpart)
       
    73         curEx = dbc.fetchone()[0]
       
    74         dbc.close()
       
    75         if curEx == limit:
       
    76             errmsg = _(u"""Can't add new destination to alias »%(address)s«.
       
    77 Currently this alias expands into %(count)i recipients.
       
    78 One destination more will render this alias unusable.
       
    79 Hint: Increase Postfix' virtual_alias_expansion_limit
       
    80 """) % {'address': self._addr, 'count': curEx}
       
    81             raise VMMAE(errmsg, ERR.ALIAS_EXCEEDS_EXPANSION_LIMIT)
       
    82 
       
    83     def save(self, expansion_limit):
    70         if self._dest is None:
    84         if self._dest is None:
    71            raise VMMAE(_(u"No destination address for alias denoted."),
    85            raise VMMAE(_(u"No destination address for alias denoted."),
    72                ERR.ALIAS_MISSING_DEST)
    86                ERR.ALIAS_MISSING_DEST)
    73         if self._isNew:
    87         if self._isNew:
       
    88             self._checkExpansion(expansion_limit)
    74             dbc = self._dbh.cursor()
    89             dbc = self._dbh.cursor()
    75             dbc.execute("INSERT INTO alias (gid, address, destination) VALUES\
    90             dbc.execute("INSERT INTO alias (gid, address, destination) VALUES\
    76  (%s, %s, %s)", self._gid, self._addr._localpart, str(self._dest))
    91  (%s, %s, %s)", self._gid, self._addr._localpart, str(self._dest))
    77             self._dbh.commit()
    92             self._dbh.commit()
    78             dbc.close()
    93             dbc.close()