# HG changeset patch # User Pascal Volk # Date 1201981697 0 # Node ID 7e3ce56f49e6ae0908a33e0a3eb8922599290a01 # Parent 96761c442dcf5f8bad1d3b72ed8cc80b204c9b8c * 'create_tables.pgsql' - Renamed table maildir to maillocation - Added transport id (tid) to table domains, for default transport * 'VirtualMailManager/MailLocation.py' * 'VirtualMailManager/Transport.py' - Added to repository * 'VirtualMailManager/constants/ERROR.py' - Added error codes for MailLocation and Transport classes * 'VirtualMailManager/Exceptions.py' - Added exception classes for MailLocation and Transport diff -r 96761c442dcf -r 7e3ce56f49e6 ChangeLog --- a/ChangeLog Fri Jan 18 20:25:05 2008 +0000 +++ b/ChangeLog Sat Feb 02 19:48:17 2008 +0000 @@ -1,4 +1,15 @@ === 0.0.0 === +2008-02-02 Pascal Volk + + * create_tables: Renamed table maildir to maillocation + Added transport id to table domains, for default transport + * VirtualMailManager/Transport.py: + * VirtualMailManager/MailLocation.py: Added to repository + * VirtualMailManager/constants/ERROR.py: Added error codes for MailLocation + and Transport classes + * VirtualMailManager/Exceptions.py: Added exception classes for MailLocation + and Transport + 2008-01-18 Pascal Volk * create_tables.pgsql: Removed unneeded sequences 'alias_id' and diff -r 96761c442dcf -r 7e3ce56f49e6 VirtualMailManager/Account.py --- a/VirtualMailManager/Account.py Fri Jan 18 20:25:05 2008 +0000 +++ b/VirtualMailManager/Account.py Sat Feb 02 19:48:17 2008 +0000 @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: UTF-8 -*- -# opyright 2007-2008 VEB IT +# Copyright 2007-2008 VEB IT # See COPYING for distribution information. # $Id$ diff -r 96761c442dcf -r 7e3ce56f49e6 VirtualMailManager/Alias.py --- a/VirtualMailManager/Alias.py Fri Jan 18 20:25:05 2008 +0000 +++ b/VirtualMailManager/Alias.py Sat Feb 02 19:48:17 2008 +0000 @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: UTF-8 -*- -# opyright 2007-2008 VEB IT +# Copyright 2007-2008 VEB IT # See COPYING for distribution information. # $Id$ diff -r 96761c442dcf -r 7e3ce56f49e6 VirtualMailManager/Config.py --- a/VirtualMailManager/Config.py Fri Jan 18 20:25:05 2008 +0000 +++ b/VirtualMailManager/Config.py Sat Feb 02 19:48:17 2008 +0000 @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: UTF-8 -*- -# opyright 2007-2008 VEB IT +# Copyright 2007-2008 VEB IT # See COPYING for distribution information. # $Id$ diff -r 96761c442dcf -r 7e3ce56f49e6 VirtualMailManager/Domain.py --- a/VirtualMailManager/Domain.py Fri Jan 18 20:25:05 2008 +0000 +++ b/VirtualMailManager/Domain.py Sat Feb 02 19:48:17 2008 +0000 @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: UTF-8 -*- -# opyright 2007-2008 VEB IT +# Copyright 2007-2008 VEB IT # See COPYING for distribution information. # $Id$ diff -r 96761c442dcf -r 7e3ce56f49e6 VirtualMailManager/Exceptions.py --- a/VirtualMailManager/Exceptions.py Fri Jan 18 20:25:05 2008 +0000 +++ b/VirtualMailManager/Exceptions.py Sat Feb 02 19:48:17 2008 +0000 @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: UTF-8 -*- -# opyright 2007-2008 VEB IT +# Copyright 2007-2008 VEB IT # See COPYING for distribution information. # $Id$ @@ -43,6 +43,17 @@ VMMException.__init__(self, msg) class VMMAliasException(VMMException): - """Ausnahmeklasse für Aliasausnamhem""" + """Exception class for Alias exceptions""" def __init__(self, msg): VMMException.__init__(self, msg) + +class VMMMailLocationException(VMMException): + """Exception class for MailLocation exceptions""" + def __init__(self, msg): + VMMException.__init__(self, msg) + +class VMMTransportException(VMMException): + """Exception class for Transport exceptions""" + def __init__(self, msg): + VMMException.__init__(self, msg) + diff -r 96761c442dcf -r 7e3ce56f49e6 VirtualMailManager/MailLocation.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/VirtualMailManager/MailLocation.py Sat Feb 02 19:48:17 2008 +0000 @@ -0,0 +1,85 @@ +#!/usr/bin/env python +# -*- coding: UTF-8 -*- +# Copyright 2008 VEB IT +# See COPYING for distribution information. +# $Id$ + +"""Virtual Mail Manager's MailLocation class to manage the mail_location +for accounts.""" + +from constants.VERSION import VERSION + +__author__ = 'Pascal Volk ' +__version__ = VERSION +__revision__ = 'rev '+'$Rev$'.split()[1] +__date__ = '$Date$'.split()[1] + + +from Exceptions import VMMMailLocationException as MLE +import constants.ERROR as ERR + +class MailLocation: + """A wrapper class thats provide access to the maillocation table""" + def __init__(self, dbh, mid=None, maillocation=None): + """Creates a new MailLocation instance. + + Either mid or maillocation must be specified. + + Keyword arguments: + dbh -- a pyPgSQL.PgSQL.connection + mid -- the id of a maillocation (long) + maillocation -- the value of the maillocation (str) + """ + self._dbh = dbh + if mid is None and maillocation is None: + raise MLE(('Either mid or maillocation must be specified.', + ERR.MAILLOCATION_INIT)) + elif mid is not None: + try: + self.__id = long(tid) + except ValueError: + raise MLE(('mid must be an int/long.', ERR.MAILLOCATION_INIT)) + self._loadByID() + else: + self.__maillocation = maillocation + self._loadByName() + + def _loadByID(self): + dbc = self._dbh.cursor() + dbc.execute('SELECT maillocation FROM maillocation WHERE mid = %s', + self.__id) + result = dbc.fetchone() + dbc.close() + if result is not None: + self.__maillocation = result[0] + else: + raise MLE(('Unknown mid specified.', ERR.UNKNOWN_MAILLOCATION_ID)) + + def _loadByName(self): + dbc = self._dbh.cursor() + dbc.execute('SELECT mid FROM maillocation WHERE maillocation = %s', + self.__maillocation) + result = dbc.fetchone() + dbc.close() + if result is not None: + self.__id = result[0] + else: + self._save() + + def _save(self): + dbc = self._dbh.cursor() + dbc.execute("SELECT nextval('maillocation_id')") + self.__id = dbc.fetchone()[0] + dbc.execute('INSERT INTO maillocation(mid,maillocation) VALUES(%s,%s)', + self.__id, self.__maillocation) + self._dbh.commit() + dbc.close() + + def getID(self): + """Returns the unique ID of the maillocation.""" + return self.__id + + def getMailLocation(self): + """Returns the value of maillocation, ex: 'Maildir'""" + return self.__maillocation + diff -r 96761c442dcf -r 7e3ce56f49e6 VirtualMailManager/Transport.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/VirtualMailManager/Transport.py Sat Feb 02 19:48:17 2008 +0000 @@ -0,0 +1,85 @@ +#!/usr/bin/env python +# -*- coding: UTF-8 -*- +# Copyright 2008 VEB IT +# See COPYING for distribution information. +# $Id$ + +"""Virtual Mail Manager's Transport class to manage the transport for +domains and accounts.""" + +from constants.VERSION import VERSION + +__author__ = 'Pascal Volk ' +__version__ = VERSION +__revision__ = 'rev '+'$Rev$'.split()[1] +__date__ = '$Date$'.split()[1] + +from Exceptions import VMMTransportException +import constants.ERROR as ERR + +class Transport: + """A wrapper class thats provide access to the transport table""" + def __init__(self, dbh, tid=None, transport=None): + """Creates a new Transport instance. + + Either tid or transport must be specified. + + Keyword arguments: + dbh -- a pyPgSQL.PgSQL.connection + tid -- the id of a transport (long) + transport -- the value of the transport (str) + """ + self._dbh = dbh + if tid is None and transport is None: + raise VMMTransportException( + ('Either tid or transport must be specified.', + ERR.TRANSPORT_INIT)) + elif tid is not None: + try: + self.__id = long(tid) + except ValueError: + raise VMMTransportException(('tid must be an int/long.', + ERR.TRANSPORT_INIT)) + self._loadByID() + else: + self.__transport = transport + self._loadByName() + + def _loadByID(self): + dbc = self._dbh.cursor() + dbc.execute('SELECT transport FROM transport WHERE tid = %s', self.__id) + result = dbc.fetchone() + dbc.close() + if result is not None: + self.__transport = result[0] + else: + raise VMMTransportException(('Unknown tid specified.', + ERR.UNKNOWN_TRANSPORT_ID)) + + def _loadByName(self): + dbc = self._dbh.cursor() + dbc.execute('SELECT tid FROM transport WHERE transport = %s', + self.__transport) + result = dbc.fetchone() + dbc.close() + if result is not None: + self.__id = result[0] + else: + self._save() + + def _save(self): + dbc = self._dbh.cursor() + dbc.execute("SELECT nextval('transport_id')") + self.__id = dbc.fetchone()[0] + dbc.execute('INSERT INTO transport (tid, transport) VALUES (%s, %s)', + self.__id, self.__transport) + self._dbh.commit() + dbc.close() + + def getID(self): + """Returns the unique ID of the transport.""" + return self.__id + + def getTransport(self): + """Returns the value of transport, ex: 'dovecot:'""" + return self.__transport diff -r 96761c442dcf -r 7e3ce56f49e6 VirtualMailManager/VirtualMailManager.py --- a/VirtualMailManager/VirtualMailManager.py Fri Jan 18 20:25:05 2008 +0000 +++ b/VirtualMailManager/VirtualMailManager.py Sat Feb 02 19:48:17 2008 +0000 @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: UTF-8 -*- -# opyright 2007-2008 VEB IT +# Copyright 2007-2008 VEB IT # See COPYING for distribution information. # $Id$ @@ -32,6 +32,7 @@ RE_ASCII_CHARS = """^[\x20-\x7E]*$""" RE_DOMAIN = """^(?:[a-z0-9-]{1,63}\.){1,}[a-z]{2,6}$""" RE_LOCALPART = """[^\w!#$%&'\*\+-\.\/=?^_`{\|}~]""" +RE_MAILLOCATION = """^[\w]{1,20}$""" re.compile(RE_ASCII_CHARS) re.compile(RE_DOMAIN) diff -r 96761c442dcf -r 7e3ce56f49e6 VirtualMailManager/__init__.py --- a/VirtualMailManager/__init__.py Fri Jan 18 20:25:05 2008 +0000 +++ b/VirtualMailManager/__init__.py Sat Feb 02 19:48:17 2008 +0000 @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: UTF-8 -*- -# opyright 2007-2008 VEB IT +# Copyright 2007-2008 VEB IT # See COPYING for distribution information. # $Id$ # package placeholder diff -r 96761c442dcf -r 7e3ce56f49e6 VirtualMailManager/constants/ERROR.py --- a/VirtualMailManager/constants/ERROR.py Fri Jan 18 20:25:05 2008 +0000 +++ b/VirtualMailManager/constants/ERROR.py Sat Feb 02 19:48:17 2008 +0000 @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: UTF-8 -*- -# opyright 2007-2008 VEB IT +# Copyright 2007-2008 VEB IT # See COPYING for distribution information. # $Id$ @@ -27,9 +27,13 @@ LOCALPART_INVALID = 40 LOCALPART_TOO_LONG = 41 MAILDIR_PERM_MISMATCH = 42 -NOT_EXECUTABLE = 43 -NO_SUCH_ACCOUNT = 44 -NO_SUCH_ALIAS = 45 -NO_SUCH_BINARY = 46 -NO_SUCH_DIRECTORY = 47 -NO_SUCH_DOMAIN = 48 +MAILLOCATION_INIT = 43 +NOT_EXECUTABLE = 44 +NO_SUCH_ACCOUNT = 45 +NO_SUCH_ALIAS = 46 +NO_SUCH_BINARY = 47 +NO_SUCH_DIRECTORY = 48 +NO_SUCH_DOMAIN = 49 +TRANSPORT_INIT = 50 +UNKNOWN_MAILLOCATION_ID = 51 +UNKNOWN_TRANSPORT_ID = 52 diff -r 96761c442dcf -r 7e3ce56f49e6 VirtualMailManager/constants/EXIT.py --- a/VirtualMailManager/constants/EXIT.py Fri Jan 18 20:25:05 2008 +0000 +++ b/VirtualMailManager/constants/EXIT.py Sat Feb 02 19:48:17 2008 +0000 @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: UTF-8 -*- -# opyright 2007-2008 VEB IT +# Copyright 2007-2008 VEB IT # See COPYING for distribution information. # $Id$ diff -r 96761c442dcf -r 7e3ce56f49e6 VirtualMailManager/constants/VERSION.py --- a/VirtualMailManager/constants/VERSION.py Fri Jan 18 20:25:05 2008 +0000 +++ b/VirtualMailManager/constants/VERSION.py Sat Feb 02 19:48:17 2008 +0000 @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: UTF-8 -*- -# opyright 2007-2008 VEB IT +# Copyright 2007-2008 VEB IT # See COPYING for distribution information. # $Id$ diff -r 96761c442dcf -r 7e3ce56f49e6 VirtualMailManager/constants/__init__.py --- a/VirtualMailManager/constants/__init__.py Fri Jan 18 20:25:05 2008 +0000 +++ b/VirtualMailManager/constants/__init__.py Sat Feb 02 19:48:17 2008 +0000 @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: UTF-8 -*- -# opyright 2007-2008 VEB IT +# Copyright 2007-2008 VEB IT # See COPYING for distribution information. # $Id$ # package placeholder diff -r 96761c442dcf -r 7e3ce56f49e6 create_tables.pgsql --- a/create_tables.pgsql Fri Jan 18 20:25:05 2008 +0000 +++ b/create_tables.pgsql Sat Feb 02 19:48:17 2008 +0000 @@ -3,22 +3,22 @@ CREATE SEQUENCE transport_id; CREATE TABLE transport ( tid bigint NOT NULL DEFAULT nextval('transport_id'), - transport varchar(268) NOT NULL, -- smtp:[255-char.host.name:50025] + transport varchar(270) NOT NULL, -- smtps:[255-char.host.name:50025] CONSTRAINT pkey_transport PRIMARY KEY (tid), CONSTRAINT ukey_transport UNIQUE (transport) ); -- Insert default transport INSERT INTO transport(transport) VALUES ('dovecot:'); -CREATE SEQUENCE maildir_id; -CREATE TABLE maildir( - mid bigint NOT NULL DEFAULT nextval('maildir_id'), - maildir varchar(20) NOT NULL, - CONSTRAINT pkey_maildir PRIMARY KEY (mid), - CONSTRAINT ukey_maildir UNIQUE (maildir) +CREATE SEQUENCE maillocation_id; +CREATE TABLE maillocation( + mid bigint NOT NULL DEFAULT nextval('maillocation_id'), + maillocation varchar(20) NOT NULL, + CONSTRAINT pkey_maillocation PRIMARY KEY (mid), + CONSTRAINT ukey_maillocation UNIQUE (maillocation) ); -- Insert default Maildir-folder name -INSERT INTO maildir(maildir) VALUES ('Maildir'); +INSERT INTO maillocation(maillocation) VALUES ('Maildir'); CREATE SEQUENCE domains_gid START WITH 70000 @@ -36,10 +36,13 @@ CREATE TABLE domains ( gid bigint NOT NULL DEFAULT nextval('domains_gid'), + tid bigint NOT NULL DEFAULT 1, -- defualt transport domainname varchar(255) NOT NULL, domaindir varchar(40) NOT NULL, --/srv/mail/$RAND/4294967294 CONSTRAINT pkey_domains PRIMARY KEY (gid), - CONSTRAINT ukey_domains UNIQUE (domainname) + CONSTRAINT ukey_domains UNIQUE (domainname), + CONSTRAINT fkey_domains_tid_transport FOREIGN KEY (tid) + REFERENCES transport (tid) ); CREATE TABLE users ( @@ -55,8 +58,8 @@ CONSTRAINT ukey_users_uid UNIQUE (uid), CONSTRAINT fkey_users_gid_domains FOREIGN KEY (gid) REFERENCES domains (gid), - CONSTRAINT fkey_users_mid_maildir FOREIGN KEY (mid) - REFERENCES maildir (mid), + CONSTRAINT fkey_users_mid_maillocation FOREIGN KEY (mid) + REFERENCES maillocation (mid), CONSTRAINT fkey_users_tid_transport FOREIGN KEY (tid) REFERENCES transport (tid) ); @@ -105,10 +108,10 @@ CREATE OR REPLACE VIEW postfix_maildir AS SELECT local_part || '@' || domains.domainname AS address, - domains.domaindir||'/'||uid||'/'||maildir.maildir||'/' AS maildir + domains.domaindir||'/'||uid||'/'||maillocation.maillocation||'/' AS maildir FROM users LEFT JOIN domains USING (gid) - LEFT JOIN maildir USING (mid); + LEFT JOIN maillocation USING (mid); CREATE OR REPLACE VIEW postfix_relocated AS SELECT address || '@' || domains.domainname AS address, destination