16 import re |
16 import re |
17 |
17 |
18 from shutil import rmtree |
18 from shutil import rmtree |
19 from subprocess import Popen, PIPE |
19 from subprocess import Popen, PIPE |
20 |
20 |
21 from pyPgSQL import PgSQL # python-pgsql - http://pypgsql.sourceforge.net |
21 from pyPgSQL import PgSQL # python-pgsql - http://pypgsql.sourceforge.net |
22 |
22 |
23 import VirtualMailManager.constants.ERROR as ERR |
23 import VirtualMailManager.constants.ERROR as ERR |
24 from VirtualMailManager import ENCODING, ace2idna, exec_ok |
24 from VirtualMailManager import ENCODING, ace2idna, exec_ok |
25 from VirtualMailManager.Account import Account |
25 from VirtualMailManager.Account import Account |
26 from VirtualMailManager.Alias import Alias |
26 from VirtualMailManager.Alias import Alias |
33 from VirtualMailManager.Transport import Transport |
33 from VirtualMailManager.Transport import Transport |
34 from VirtualMailManager.ext.Postconf import Postconf |
34 from VirtualMailManager.ext.Postconf import Postconf |
35 |
35 |
36 |
36 |
37 SALTCHARS = './0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' |
37 SALTCHARS = './0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' |
38 RE_DOMAIN_SRCH = """^[a-z0-9-\.]+$""" |
38 RE_DOMAIN_SEARCH = """^[a-z0-9-\.]+$""" |
39 RE_MBOX_NAMES = """^[\x20-\x25\x27-\x7E]*$""" |
39 RE_MBOX_NAMES = """^[\x20-\x25\x27-\x7E]*$""" |
40 |
40 |
41 |
41 |
42 class Handler(object): |
42 class Handler(object): |
43 """Wrapper class to simplify the access on all the stuff from |
43 """Wrapper class to simplify the access on all the stuff from |
509 self.__dbConnect() |
509 self.__dbConnect() |
510 aliasDom = AliasDomain(self._dbh, aliasname, None) |
510 aliasDom = AliasDomain(self._dbh, aliasname, None) |
511 aliasDom.delete() |
511 aliasDom.delete() |
512 |
512 |
513 def domainList(self, pattern=None): |
513 def domainList(self, pattern=None): |
514 from Domain import search |
514 from VirtualMailManager.Domain import search |
515 like = False |
515 like = False |
516 if pattern is not None: |
516 if pattern and (pattern.startswith('%') or pattern.endswith('%')): |
517 if pattern.startswith('%') or pattern.endswith('%'): |
517 like = True |
518 like = True |
518 if not re.match(RE_DOMAIN_SEARCH, pattern.strip('%')): |
519 domain = pattern.strip('%') |
519 raise VMMError( |
520 if not re.match(RE_DOMAIN_SRCH, domain): |
520 _(u"The pattern '%s' contains invalid characters.") % |
521 raise VMMError( |
521 pattern, ERR.DOMAIN_INVALID) |
522 _(u"The pattern '%s' contains invalid characters.") % |
|
523 pattern, ERR.DOMAIN_INVALID) |
|
524 self.__dbConnect() |
522 self.__dbConnect() |
525 return search(self._dbh, pattern=pattern, like=like) |
523 return search(self._dbh, pattern=pattern, like=like) |
526 |
524 |
527 def userAdd(self, emailaddress, password): |
525 def userAdd(self, emailaddress, password): |
528 if password is None or (isinstance(password, basestring) and |
526 if password is None or (isinstance(password, basestring) and |
624 if details in ('aliases', 'full'): |
622 if details in ('aliases', 'full'): |
625 return (info, acc.getAliases()) |
623 return (info, acc.getAliases()) |
626 return info |
624 return info |
627 |
625 |
628 def userByID(self, uid): |
626 def userByID(self, uid): |
629 from Handler.Account import getAccountByID |
627 from VirtualMailManager.Account import getAccountByID |
630 self.__dbConnect() |
628 self.__dbConnect() |
631 return getAccountByID(uid, self._dbh) |
629 return getAccountByID(uid, self._dbh) |
632 |
630 |
633 def userPassword(self, emailaddress, password): |
631 def userPassword(self, emailaddress, password): |
634 if password is None or (isinstance(password, basestring) and |
632 if password is None or (isinstance(password, basestring) and |