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 Alias class to manage email aliases.""" |
7 """Virtual Mail Manager's Alias class to manage e-mail aliases.""" |
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 VMMAliasException |
13 from Exceptions import VMMAliasException |
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 Alias: |
17 class Alias: |
18 """Class to manage email accounts.""" |
18 """Class to manage e-mail accounts.""" |
19 def __init__(self, dbh, address, basedir, destination=None): |
19 def __init__(self, dbh, address, basedir, destination=None): |
20 if address == destination: |
20 if address == destination: |
21 raise VMMAliasException(('Address and destination are identical.', |
21 raise VMMAliasException(('Address and destination are identical.', |
22 ERR.ALIAS_ADDR_DEST_IDENTICAL)) |
22 ERR.ALIAS_ADDR_DEST_IDENTICAL)) |
23 self._dbh = dbh |
23 self._dbh = dbh |
29 self._setAddr(basedir) |
29 self._setAddr(basedir) |
30 if not self._dest is None: |
30 if not self._dest is None: |
31 self._exists() |
31 self._exists() |
32 if self._isAccount(): |
32 if self._isAccount(): |
33 raise VMMAliasException( |
33 raise VMMAliasException( |
34 ('There is already an account with address «%s»' % self._addr, |
34 ('There is already an account with address »%s«' % self._addr, |
35 ERR.ACCOUNT_EXISTS)) |
35 ERR.ACCOUNT_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 id FROM alias WHERE gid=%s AND address=%s\ |
39 dbc.execute("SELECT id FROM alias WHERE gid=%s AND address=%s\ |
60 def _setAddr(self, basedir): |
60 def _setAddr(self, basedir): |
61 self._localpart, d = self._addr.split('@') |
61 self._localpart, d = self._addr.split('@') |
62 dom = Domain(self._dbh, d, basedir) |
62 dom = Domain(self._dbh, d, basedir) |
63 self._gid = dom.getID() |
63 self._gid = dom.getID() |
64 if self._gid == 0: |
64 if self._gid == 0: |
65 raise VMMAliasException(("Domain «%s» doesn't exist." % d, |
65 raise VMMAliasException(("Domain »%s« doesn't exist." % d, |
66 ERR.NO_SUCH_DOMAIN)) |
66 ERR.NO_SUCH_DOMAIN)) |
67 |
67 |
68 def save(self): |
68 def save(self): |
69 if self._dest is None: |
69 if self._dest is None: |
70 raise VMMAliasException(('No destination address for alias denoted.', |
70 raise VMMAliasException(('No destination address for alias denoted.', |