* 'VirtualMailManager/constants/VERSION.py'
- Updated version from 0.5-dev to 0.5
* 'NEWS'
- Added to repository
# -*- coding: UTF-8 -*-# Copyright 2008 VEB IT# See COPYING for distribution information.# $Id$"""Virtual Mail Manager's Relocated class to manage relocated users."""fromconstants.VERSIONimportVERSION__author__='Pascal Volk <p.volk@veb-it.de>'__version__=VERSION__revision__='rev '+'$Rev$'.split()[1]__date__='$Date$'.split()[1]fromExceptionsimportVMMRelocatedExceptionasVMMREfromDomainimportDomainfromEmailAddressimportEmailAddressimportconstants.ERRORasERRimportVirtualMailManagerasVMMclassRelocated:"""Class to manage e-mail addresses of relocated users."""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:raiseVMMRE(_(u"Address and destination are identical."),ERR.RELOCATED_ADDR_DEST_IDENTICAL)self._dbh=dbhself._gid=0self._isNew=Falseself._setAddr()self._exists()ifself._isNewandVMM.VirtualMailManager.accountExists(self._dbh,self._addr):raiseVMMRE(_(u"There is already an account with address »%s«.")%\self._addr,ERR.ACCOUNT_EXISTS)ifself._isNewandVMM.VirtualMailManager.aliasExists(self._dbh,self._addr):raiseVMMRE(_(u"There is already an alias with the address »%s«.")%\self._addr,ERR.ALIAS_EXISTS)def_exists(self):dbc=self._dbh.cursor()dbc.execute("SELECT gid FROM relocated WHERE gid = %s AND address = %s",self._gid,self._addr._localpart)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:raiseVMMRE(_(u"The domain »%s« doesn't exist yet.")%\self._addr._domainname,ERR.NO_SUCH_DOMAIN)defsave(self):ifself._destisNone:raiseVMMRE(_(u"No destination address for relocated user denoted."),ERR.RELOCATED_MISSING_DEST)ifself._isNew:dbc=self._dbh.cursor()dbc.execute("INSERT INTO relocated VALUES (%s, %s, %s)",self._gid,self._addr._localpart,str(self._dest))self._dbh.commit()dbc.close()else:raiseVMMRE(_(u"The relocated user »%s« already exists.")%self._addr,ERR.RELOCATED_EXISTS)defgetInfo(self):dbc=self._dbh.cursor()dbc.execute('SELECT destination FROM relocated WHERE gid=%s\ AND address=%s',self._gid,self._addr._localpart)destination=dbc.fetchone()dbc.close()ifdestinationisnotNone:returndestination[0]else:raiseVMMRE(_(u"The relocated user »%s« doesn't exists.")%self._addr,ERR.NO_SUCH_RELOCATED)defdelete(self):dbc=self._dbh.cursor()dbc.execute("DELETE FROM relocated WHERE gid = %s AND address = %s",self._gid,self._addr._localpart)rowcount=dbc.rowcountdbc.close()ifrowcount>0:self._dbh.commit()else:raiseVMMRE(_(u"The relocated user »%s« doesn't exists.")%self._addr,ERR.NO_SUCH_RELOCATED)