VirtualMailManager/Alias.py
changeset 133 2d5c4745efec
parent 129 4ffb50de00d5
child 138 617f27715b01
equal deleted inserted replaced
132:fa22bd13b4d1 133:2d5c4745efec
    35         self._setAddr()
    35         self._setAddr()
    36         if not self._dest is None:
    36         if not self._dest is None:
    37             self._exists()
    37             self._exists()
    38         if self._isNew and VMM.VirtualMailManager.accountExists(self._dbh,
    38         if self._isNew and VMM.VirtualMailManager.accountExists(self._dbh,
    39                 self._addr):
    39                 self._addr):
    40             raise VMMAE(_(u"There is already an account with address »%s«.") %\
    40             raise VMMAE(_(u"There is already an account with address “%s”.") %\
    41                     self._addr, ERR.ACCOUNT_EXISTS)
    41                     self._addr, ERR.ACCOUNT_EXISTS)
    42         if self._isNew and VMM.VirtualMailManager.relocatedExists(self._dbh,
    42         if self._isNew and VMM.VirtualMailManager.relocatedExists(self._dbh,
    43                 self._addr):
    43                 self._addr):
    44             raise VMMAE(
    44             raise VMMAE(
    45               _(u"There is already a relocated user with the address »%s«.") %\
    45               _(u"There is already a relocated user with the address “%s”.") %\
    46                     self._addr, ERR.RELOCATED_EXISTS)
    46                     self._addr, ERR.RELOCATED_EXISTS)
    47 
    47 
    48     def _exists(self):
    48     def _exists(self):
    49         dbc = self._dbh.cursor()
    49         dbc = self._dbh.cursor()
    50         dbc.execute("SELECT gid FROM alias WHERE gid=%s AND address=%s\
    50         dbc.execute("SELECT gid FROM alias WHERE gid=%s AND address=%s\
    56 
    56 
    57     def _setAddr(self):
    57     def _setAddr(self):
    58         dom = Domain(self._dbh, self._addr._domainname)
    58         dom = Domain(self._dbh, self._addr._domainname)
    59         self._gid = dom.getID()
    59         self._gid = dom.getID()
    60         if self._gid == 0:
    60         if self._gid == 0:
    61             raise VMMAE(_(u"The domain »%s« doesn't exist yet.") %\
    61             raise VMMAE(_(u"The domain “%s” doesn't exist yet.") %\
    62                     self._addr._domainname, ERR.NO_SUCH_DOMAIN)
    62                     self._addr._domainname, ERR.NO_SUCH_DOMAIN)
    63 
    63 
    64     def _checkExpansion(self, limit):
    64     def _checkExpansion(self, limit):
    65         dbc = self._dbh.cursor()
    65         dbc = self._dbh.cursor()
    66         dbc.execute('SELECT count(gid) FROM alias where gid=%s AND address=%s',
    66         dbc.execute('SELECT count(gid) FROM alias where gid=%s AND address=%s',
    67                 self._gid, self._addr._localpart)
    67                 self._gid, self._addr._localpart)
    68         curEx = dbc.fetchone()[0]
    68         curEx = dbc.fetchone()[0]
    69         dbc.close()
    69         dbc.close()
    70         if curEx == limit:
    70         if curEx == limit:
    71             errmsg = _(u"""Can't add new destination to alias »%(address)s«.
    71             errmsg = _(u"""Can't add new destination to alias “%(address)s”.
    72 Currently this alias expands into %(count)i recipients.
    72 Currently this alias expands into %(count)i recipients.
    73 One more destination will render this alias unusable.
    73 One more destination will render this alias unusable.
    74 Hint: Increase Postfix' virtual_alias_expansion_limit
    74 Hint: Increase Postfix' virtual_alias_expansion_limit
    75 """) % {'address': self._addr, 'count': curEx}
    75 """) % {'address': self._addr, 'count': curEx}
    76             raise VMMAE(errmsg, ERR.ALIAS_EXCEEDS_EXPANSION_LIMIT)
    76             raise VMMAE(errmsg, ERR.ALIAS_EXCEEDS_EXPANSION_LIMIT)
    86  (%s, %s, %s)", self._gid, self._addr._localpart, str(self._dest))
    86  (%s, %s, %s)", self._gid, self._addr._localpart, str(self._dest))
    87             self._dbh.commit()
    87             self._dbh.commit()
    88             dbc.close()
    88             dbc.close()
    89         else:
    89         else:
    90             raise VMMAE(
    90             raise VMMAE(
    91                _(u"The alias »%(a)s« with destination »%(d)s« already exists.")\
    91                _(u"The alias “%(a)s” with destination “%(d)s” already exists.")\
    92                        % {'a': self._addr, 'd': self._dest}, ERR.ALIAS_EXISTS)
    92                        % {'a': self._addr, 'd': self._dest}, ERR.ALIAS_EXISTS)
    93 
    93 
    94     def getInfo(self):
    94     def getInfo(self):
    95         dbc = self._dbh.cursor()
    95         dbc = self._dbh.cursor()
    96         dbc.execute('SELECT destination FROM alias WHERE gid=%s AND address=%s',
    96         dbc.execute('SELECT destination FROM alias WHERE gid=%s AND address=%s',
   101             targets = []
   101             targets = []
   102             for destination in destinations:
   102             for destination in destinations:
   103                 targets.append(destination[0])
   103                 targets.append(destination[0])
   104             return targets
   104             return targets
   105         else:
   105         else:
   106             raise VMMAE(_(u"The alias »%s« doesn't exists.") % self._addr,
   106             raise VMMAE(_(u"The alias “%s” doesn't exists.") % self._addr,
   107                     ERR.NO_SUCH_ALIAS)
   107                     ERR.NO_SUCH_ALIAS)
   108 
   108 
   109     def delete(self):
   109     def delete(self):
   110         dbc = self._dbh.cursor()
   110         dbc = self._dbh.cursor()
   111         if self._dest is None:
   111         if self._dest is None:
   118         dbc.close()
   118         dbc.close()
   119         if rowcount > 0:
   119         if rowcount > 0:
   120             self._dbh.commit()
   120             self._dbh.commit()
   121         else:
   121         else:
   122             if self._dest is None:
   122             if self._dest is None:
   123                 msg = _(u"The alias »%s« doesn't exists.") % self._addr
   123                 msg = _(u"The alias “%s” doesn't exists.") % self._addr
   124             else:
   124             else:
   125                 msg = _(u"The alias »%(a)s« with destination »%(d)s« doesn't\
   125                 msg = _(u"The alias “%(a)s” with destination “%(d)s” doesn't\
   126  exists.") % {'a': self._addr, 'd': self._dest}
   126  exists.") % {'a': self._addr, 'd': self._dest}
   127             raise VMMAE(msg, ERR.NO_SUCH_ALIAS)
   127             raise VMMAE(msg, ERR.NO_SUCH_ALIAS)
   128 
   128