# HG changeset patch # User Pascal Volk # Date 1267390294 0 # Node ID d0c16e70a9fb564a39be2a94e8665a341db33772 # Parent 371ae0b4443d319d3eade4fa7c5982dcf193feff VMM/Domain: get_gid() return 0 instead of raising an Exception, if the domain wasn't found in the database. diff -r 371ae0b4443d -r d0c16e70a9fb VirtualMailManager/Alias.py --- a/VirtualMailManager/Alias.py Sat Feb 27 21:36:55 2010 +0000 +++ b/VirtualMailManager/Alias.py Sun Feb 28 20:51:34 2010 +0000 @@ -12,8 +12,8 @@ from VirtualMailManager.EmailAddress import EmailAddress from VirtualMailManager.errors import AliasError as AErr from VirtualMailManager.pycompat import all -from VirtualMailManager.constants.ERROR import ALIAS_ADDR_DEST_IDENTICAL, \ - ALIAS_EXCEEDS_EXPANSION_LIMIT, ALIAS_EXISTS, NO_SUCH_ALIAS +from VirtualMailManager.constants.ERROR import \ + ALIAS_EXCEEDS_EXPANSION_LIMIT, NO_SUCH_ALIAS, NO_SUCH_DOMAIN _ = lambda msg: msg @@ -28,6 +28,9 @@ self._addr = address self._dbh = dbh self._gid = get_gid(self._dbh, self._addr.domainname) + if not self._gid: + raise AErr(_(u"The domain %r doesn't exist.") % + self._addr.domainname, NO_SUCH_DOMAIN) self._dests = [] self.__load_dests() diff -r 371ae0b4443d -r d0c16e70a9fb VirtualMailManager/Domain.py --- a/VirtualMailManager/Domain.py Sat Feb 27 21:36:55 2010 +0000 +++ b/VirtualMailManager/Domain.py Sun Feb 28 20:51:34 2010 +0000 @@ -313,9 +313,10 @@ return order, domdict def get_gid(dbh, domainname): - """Returns the *GID* of the domain *domainname*. + """Returns the group id of the domain *domainname*. - Raises an `DomainError` if the domain does not exist. + If the domain couldn't be found in the database 0 will be returned. + """ domainname = check_domainname(domainname) dbc = dbh.cursor() @@ -324,6 +325,4 @@ dbc.close() if gid: return gid[0] - else: - raise DomErr(_(u"The domain ā€œ%sā€ doesn't exist.") % domainname, - NO_SUCH_DOMAIN) + return 0 diff -r 371ae0b4443d -r d0c16e70a9fb VirtualMailManager/Handler.py --- a/VirtualMailManager/Handler.py Sat Feb 27 21:36:55 2010 +0000 +++ b/VirtualMailManager/Handler.py Sun Feb 28 20:51:34 2010 +0000 @@ -547,16 +547,9 @@ self.__warnings.append(_('Ignored destination addresses:')) self.__warnings.extend((' * %s' % w for w in warnings)) for destination in destinations: - try: - gid = get_gid(self._dbh, destination.domainname) - except DomainError, e: - if e.code == ERR.NO_SUCH_DOMAIN: - continue - else: - raise - if gid > 0 and \ - (not Handler.accountExists(self._dbh, destination) and - not Handler.aliasExists(self._dbh, destination)): + gid = get_gid(self._dbh, destination.domainname) + if gid and (not Handler.accountExists(self._dbh, destination) and + not Handler.aliasExists(self._dbh, destination)): self.__warnings.append( _(u"The destination account/alias %r doesn't exist.") % str(destination)) diff -r 371ae0b4443d -r d0c16e70a9fb VirtualMailManager/Relocated.py --- a/VirtualMailManager/Relocated.py Sat Feb 27 21:36:55 2010 +0000 +++ b/VirtualMailManager/Relocated.py Sun Feb 28 20:51:34 2010 +0000 @@ -11,7 +11,7 @@ from VirtualMailManager.Domain import get_gid from VirtualMailManager.EmailAddress import EmailAddress from VirtualMailManager.errors import RelocatedError as RErr -from VirtualMailManager.constants.ERROR import \ +from VirtualMailManager.constants.ERROR import NO_SUCH_DOMAIN, \ NO_SUCH_RELOCATED, RELOCATED_ADDR_DEST_IDENTICAL, RELOCATED_EXISTS @@ -34,6 +34,9 @@ self._addr = address self._dbh = dbh self._gid = get_gid(self._dbh, self._addr.domainname) + if not self._gid: + raise RErr(_(u"The domain %r doesn't exist.") % + self._addr.domainname, NO_SUCH_DOMAIN) self._dest = None self.__load()