VirtualMailManager/Alias.py
changeset 52 c152d7714802
parent 48 0d5f58f8b8f5
child 76 14c0a092d7d2
--- a/VirtualMailManager/Alias.py	Wed Aug 20 02:22:43 2008 +0000
+++ b/VirtualMailManager/Alias.py	Thu Aug 21 01:23:31 2008 +0000
@@ -13,20 +13,25 @@
 __revision__ = 'rev '+'$Rev$'.split()[1]
 __date__ = '$Date$'.split()[1]
 
-from Exceptions import VMMAliasException
+from Exceptions import VMMAliasException as VMMAE
 from Domain import Domain
 import constants.ERROR as ERR
+import VirtualMailManager as VMM
 
 class Alias:
     """Class to manage e-mail accounts."""
     def __init__(self, dbh, address, destination=None):
         if address == destination:
-            raise VMMAliasException(
-                _(u'Address and destination are identical.'),
+            raise VMMAE(_(u"Address and destination are identical."),
                 ERR.ALIAS_ADDR_DEST_IDENTICAL)
         self._dbh = dbh
-        self._addr = address
-        self._dest = destination
+        self._addr = VMM.VirtualMailManager.chkEmailAddress(address)
+        if destination is None:
+            self._dest = None
+        elif destination.count('@'):
+            self._dest = VMM.VirtualMailManager.chkEmailAddress(destination)
+        else:
+            self._dest = VMM.VirtualMailManager.chkLocalpart(destination)
         self._localpart = None
         self._gid = 0
         self._isNew = False
@@ -34,9 +39,8 @@
         if not self._dest is None:
             self._exists()
         if self._isAccount():
-            raise VMMAliasException(
-            _(u"There is already an account with address '%s'") % self._addr,
-                ERR.ACCOUNT_EXISTS)
+            raise VMMAE(_(u"There is already an account with address »%s«.") %
+                    self._addr, ERR.ACCOUNT_EXISTS)
 
     def _exists(self):
         dbc = self._dbh.cursor()
@@ -65,13 +69,12 @@
         dom = Domain(self._dbh, d)
         self._gid = dom.getID()
         if self._gid == 0:
-            raise VMMAliasException(_(u"Domain '%s' doesn't exist.") % d,
+            raise VMMAE(_(u"The domain »%s« doesn't exist yet.") % d,
                 ERR.NO_SUCH_DOMAIN)
 
     def save(self):
         if self._dest is None:
-           raise VMMAliasException(
-               _('No destination address for alias denoted.'),
+           raise VMMAE(_(u"No destination address for alias denoted."),
                ERR.ALIAS_MISSING_DEST)
         if self._isNew:
             dbc = self._dbh.cursor()
@@ -80,8 +83,8 @@
             self._dbh.commit()
             dbc.close()
         else:
-            raise VMMAliasException(_("Alias already exists."),
-                ERR.ALIAS_EXISTS)
+            raise VMMAE(_(u"The alias »%s« already exists.") % self._addr,
+                    ERR.ALIAS_EXISTS)
 
     def getInfo(self):
         dbc = self._dbh.cursor()
@@ -95,8 +98,8 @@
                 targets.append(destination[0])
             return targets
         else:
-            raise VMMAliasException(_("Alias doesn't exists"),
-                ERR.NO_SUCH_ALIAS)
+            raise VMMAE(_(u"The alias »%s« doesn't exists.") % self._addr,
+                    ERR.NO_SUCH_ALIAS)
 
     def delete(self):
         dbc = self._dbh.cursor()
@@ -111,6 +114,6 @@
         if rowcount > 0:
             self._dbh.commit()
         else:
-            raise VMMAliasException(_("Alias doesn't exists"),
-                ERR.NO_SUCH_ALIAS)
+            raise VMMAE(_(u"The alias »%s« doesn't exists.") % self._addr,
+                    ERR.NO_SUCH_ALIAS)