„speedup commit“ ;-)
* 'VirtualMailManager/Account.py'
- Account.__init__() checks only the existence of an alias or relocated
record if there is no account with the supplied address yet
* 'VirtualMailManager/Alias.py'
- Alias.__init__() checks only the existence of an account or relocated
record if there is no alias with the supplied address yet
* 'VirtualMailManager/Relocated.py'
- Relocated.__init__() checks only the existence of an account or alias
record if there is no relocated user with the supplied address yet
* 'create_optional_types_and_functions.pgsql'
- Modified the 2nd part of postfix_smtpd_sender_login_map() in order to
save 0.3 ms
# -*- coding: UTF-8 -*-# Copyright 2007-2008 VEB IT# See COPYING for distribution information.# $Id$"""Virtual Mail Manager's Alias class to manage e-mail aliases."""fromconstants.VERSIONimportVERSION__author__='Pascal Volk <p.volk@veb-it.de>'__version__=VERSION__revision__='rev '+'$Rev$'.split()[1]__date__='$Date$'.split()[1]fromExceptionsimportVMMAliasExceptionasVMMAEfromDomainimportDomainfromEmailAddressimportEmailAddressimportconstants.ERRORasERRimportVirtualMailManagerasVMMclassAlias:"""Class to manage e-mail aliases."""def__init__(self,dbh,address,destination=None):ifisinstance(address,EmailAddress):self._addr=addresselse:raiseTypeError("Argument 'address' is not an EmailAddress")ifdestinationisNone:self._dest=Noneelifisinstance(destination,EmailAddress):self._dest=destinationelse:raiseTypeError("Argument 'destination' is not an EmailAddress")ifaddress==destination:raiseVMMAE(_(u"Address and destination are identical."),ERR.ALIAS_ADDR_DEST_IDENTICAL)self._dbh=dbhself._gid=0self._isNew=Falseself._setAddr()ifnotself._destisNone:self._exists()ifself._isNewandVMM.VirtualMailManager.accountExists(self._dbh,self._addr):raiseVMMAE(_(u"There is already an account with address »%s«.")%\self._addr,ERR.ACCOUNT_EXISTS)ifself._isNewandVMM.VirtualMailManager.relocatedExists(self._dbh,self._addr):raiseVMMAE(_(u"There is already a relocated user with the address »%s«.")%\self._addr,ERR.RELOCATED_EXISTS)def_exists(self):dbc=self._dbh.cursor()dbc.execute("SELECT gid FROM alias WHERE gid=%s AND address=%s\ AND destination=%s",self._gid,self._addr._localpart,str(self._dest))gid=dbc.fetchone()dbc.close()ifgidisNone:self._isNew=Truedef_setAddr(self):dom=Domain(self._dbh,self._addr._domainname)self._gid=dom.getID()ifself._gid==0:raiseVMMAE(_(u"The domain »%s« doesn't exist yet.")%\self._addr._domainname,ERR.NO_SUCH_DOMAIN)defsave(self):ifself._destisNone:raiseVMMAE(_(u"No destination address for alias denoted."),ERR.ALIAS_MISSING_DEST)ifself._isNew:dbc=self._dbh.cursor()dbc.execute("INSERT INTO alias (gid, address, destination) VALUES\ (%s, %s, %s)",self._gid,self._addr._localpart,str(self._dest))self._dbh.commit()dbc.close()else:raiseVMMAE(_(u"The alias »%(a)s« with destination »%(d)s« already exists.")\%{'a':self._addr,'d':self._dest},ERR.ALIAS_EXISTS)defgetInfo(self):dbc=self._dbh.cursor()dbc.execute('SELECT destination FROM alias WHERE gid=%s AND address=%s',self._gid,self._addr._localpart)destinations=dbc.fetchall()dbc.close()iflen(destinations)>0:targets=[]fordestinationindestinations:targets.append(destination[0])returntargetselse:raiseVMMAE(_(u"The alias »%s« doesn't exists.")%self._addr,ERR.NO_SUCH_ALIAS)defdelete(self):dbc=self._dbh.cursor()ifself._destisNone:dbc.execute("DELETE FROM alias WHERE gid=%s AND address=%s",self._gid,self._addr._localpart)else:dbc.execute("DELETE FROM alias WHERE gid=%s AND address=%s AND \ destination=%s",self._gid,self._addr._localpart,str(self._dest))rowcount=dbc.rowcountdbc.close()ifrowcount>0:self._dbh.commit()else:ifself._destisNone:msg=u"The alias »%s« doesn't exists."%self._addrelse:msg=u"The alias »%(a)s« with destination »%(d)s« doesn't\ exists."%{'a':self._addr,'d':self._dest}raiseVMMAE(_(msg),ERR.NO_SUCH_ALIAS)