VirtualMailManager/Account.py
changeset 3 a9b44e04bf01
parent 0 bb0aa2102206
child 4 f3c30b7421b9
equal deleted inserted replaced
2:9b39f828aa8a 3:a9b44e04bf01
     2 # -*- coding: UTF-8 -*-
     2 # -*- coding: UTF-8 -*-
     3 # opyright 2007-2008 VEB IT
     3 # opyright 2007-2008 VEB IT
     4 # See COPYING for distribution information.
     4 # See COPYING for distribution information.
     5 # $Id$
     5 # $Id$
     6 
     6 
     7 """Virtual Mail Manager's Account class to manage email accounts."""
     7 """Virtual Mail Manager's Account class to manage e-mail accounts."""
     8 
     8 
     9 __author__ = 'Pascal Volk <p.volk@veb-it.de>'
     9 __author__ = 'Pascal Volk <p.volk@veb-it.de>'
    10 __version__ = 'rev '+'$Rev$'.split()[1]
    10 __version__ = 'rev '+'$Rev$'.split()[1]
    11 __date__ = '$Date$'.split()[1]
    11 __date__ = '$Date$'.split()[1]
    12 
    12 
    13 from Exceptions import VMMAccountException
    13 from Exceptions import VMMAccountException
    14 from Domain import Domain
    14 from Domain import Domain
    15 import constants.ERROR as ERR
    15 import constants.ERROR as ERR
    16 
    16 
    17 class Account:
    17 class Account:
    18     """Class to manage email accounts."""
    18     """Class to manage e-mail accounts."""
    19     def __init__(self, dbh, basedir, address, password=None):
    19     def __init__(self, dbh, basedir, address, password=None):
    20         self._dbh = dbh
    20         self._dbh = dbh
    21         self._base = basedir
    21         self._base = basedir
    22         self._base = None
    22         self._base = None
    23         self._addr = address
    23         self._addr = address
    29         self._home = None
    29         self._home = None
    30         self._setAddr(address)
    30         self._setAddr(address)
    31         self._exists()
    31         self._exists()
    32         if self._isAlias():
    32         if self._isAlias():
    33             raise VMMAccountException(
    33             raise VMMAccountException(
    34             ('There is already an alias with address «%s»' % address,
    34             ('There is already an alias with address »%s«' % address,
    35                 ERR.ALIAS_EXISTS))
    35                 ERR.ALIAS_EXISTS))
    36 
    36 
    37     def _exists(self):
    37     def _exists(self):
    38         dbc = self._dbh.cursor()
    38         dbc = self._dbh.cursor()
    39         dbc.execute("SELECT uid FROM users WHERE gid=%s AND local_part=%s",
    39         dbc.execute("SELECT uid FROM users WHERE gid=%s AND local_part=%s",
    61         self._localpart, d = address.split('@')
    61         self._localpart, d = address.split('@')
    62         dom = Domain(self._dbh, d, self._base)
    62         dom = Domain(self._dbh, d, self._base)
    63         self._gid = dom.getID()
    63         self._gid = dom.getID()
    64         self._base = dom.getDir()
    64         self._base = dom.getDir()
    65         if self._gid == 0:
    65         if self._gid == 0:
    66             raise VMMAccountException(("Domain %s doesn't exist." % d,
    66             raise VMMAccountException(("Domain »%s« doesn't exist." % d,
    67                 ERR.NO_SUCH_DOMAIN))
    67                 ERR.NO_SUCH_DOMAIN))
    68 
    68 
    69     def _setID(self):
    69     def _setID(self):
    70         dbc = self._dbh.cursor()
    70         dbc = self._dbh.cursor()
    71         dbc.execute("SELECT nextval('users_uid')")
    71         dbc.execute("SELECT nextval('users_uid')")