equal
deleted
inserted
replaced
4 |
4 |
5 """Virtual Mail Manager's Domain class to manage e-mail domains.""" |
5 """Virtual Mail Manager's Domain class to manage e-mail domains.""" |
6 |
6 |
7 from random import choice |
7 from random import choice |
8 |
8 |
9 from VirtualMailManager import chk_domainname |
9 from VirtualMailManager import check_domainname |
10 from VirtualMailManager.constants.ERROR import \ |
10 from VirtualMailManager.constants.ERROR import \ |
11 ACCOUNT_AND_ALIAS_PRESENT, ACCOUNT_PRESENT, ALIAS_PRESENT, \ |
11 ACCOUNT_AND_ALIAS_PRESENT, ACCOUNT_PRESENT, ALIAS_PRESENT, \ |
12 DOMAIN_ALIAS_EXISTS, DOMAIN_EXISTS, NO_SUCH_DOMAIN |
12 DOMAIN_ALIAS_EXISTS, DOMAIN_EXISTS, NO_SUCH_DOMAIN |
13 from VirtualMailManager.Exceptions import VMMDomainException as VMMDE |
13 from VirtualMailManager.Exceptions import VMMDomainException as VMMDE |
14 from VirtualMailManager.Transport import Transport |
14 from VirtualMailManager.Transport import Transport |
27 dbh -- a pyPgSQL.PgSQL.connection |
27 dbh -- a pyPgSQL.PgSQL.connection |
28 domainname -- name of the domain (str) |
28 domainname -- name of the domain (str) |
29 transport -- default vmm.cfg/misc/transport (str) |
29 transport -- default vmm.cfg/misc/transport (str) |
30 """ |
30 """ |
31 self._dbh = dbh |
31 self._dbh = dbh |
32 self._name = chk_domainname(domainname) |
32 self._name = check_domainname(domainname) |
33 self._basedir = basedir |
33 self._basedir = basedir |
34 if transport is not None: |
34 if transport is not None: |
35 self._transport = Transport(self._dbh, transport=transport) |
35 self._transport = Transport(self._dbh, transport=transport) |
36 else: |
36 else: |
37 self._transport = transport |
37 self._transport = transport |
279 return aliasdomains |
279 return aliasdomains |
280 |
280 |
281 |
281 |
282 def search(dbh, pattern=None, like=False): |
282 def search(dbh, pattern=None, like=False): |
283 if pattern is not None and like is False: |
283 if pattern is not None and like is False: |
284 pattern = chk_domainname(pattern) |
284 pattern = check_domainname(pattern) |
285 sql = 'SELECT gid, domainname, is_primary FROM domain_name' |
285 sql = 'SELECT gid, domainname, is_primary FROM domain_name' |
286 if pattern is None: |
286 if pattern is None: |
287 pass |
287 pass |
288 elif like: |
288 elif like: |
289 sql += " WHERE domainname LIKE '%s'" % pattern |
289 sql += " WHERE domainname LIKE '%s'" % pattern |
315 def get_gid(dbh, domainname): |
315 def get_gid(dbh, domainname): |
316 """Returns the *GID* of the domain *domainname*. |
316 """Returns the *GID* of the domain *domainname*. |
317 |
317 |
318 Raises an `VMMDomainException` if the domain does not exist. |
318 Raises an `VMMDomainException` if the domain does not exist. |
319 """ |
319 """ |
320 domainname = chk_domainname(domainname) |
320 domainname = check_domainname(domainname) |
321 dbc = dbh.cursor() |
321 dbc = dbh.cursor() |
322 dbc.execute('SELECT gid FROM domain_name WHERE domainname=%s', domainname) |
322 dbc.execute('SELECT gid FROM domain_name WHERE domainname=%s', domainname) |
323 gid = dbc.fetchone() |
323 gid = dbc.fetchone() |
324 dbc.close() |
324 dbc.close() |
325 if gid: |
325 if gid: |