VirtualMailManager/VirtualMailManager.py
changeset 136 fb61f64e6351
parent 133 2d5c4745efec
child 138 617f27715b01
equal deleted inserted replaced
135:32ad0c79a6ef 136:fb61f64e6351
     6 
     6 
     7 from constants.VERSION import *
     7 from constants.VERSION import *
     8 
     8 
     9 import os
     9 import os
    10 import re
    10 import re
    11 import sys
       
    12 import locale
       
    13 from encodings.idna import ToASCII, ToUnicode
    11 from encodings.idna import ToASCII, ToUnicode
    14 from getpass import getpass
    12 from getpass import getpass
    15 from shutil import rmtree
    13 from shutil import rmtree
    16 from subprocess import Popen, PIPE
    14 from subprocess import Popen, PIPE
    17 
    15 
    18 from pyPgSQL import PgSQL # python-pgsql - http://pypgsql.sourceforge.net
    16 from pyPgSQL import PgSQL # python-pgsql - http://pypgsql.sourceforge.net
    19 
    17 
    20 import constants.ERROR as ERR
    18 import constants.ERROR as ERR
       
    19 from __main__ import ENCODING, w_std
    21 from ext.Postconf import Postconf
    20 from ext.Postconf import Postconf
    22 from Account import Account
    21 from Account import Account
    23 from Alias import Alias
    22 from Alias import Alias
    24 from AliasDomain import AliasDomain
    23 from AliasDomain import AliasDomain
    25 from Config import Config as Cfg
    24 from Config import Config as Cfg
    32 RE_ASCII_CHARS = """^[\x20-\x7E]*$"""
    31 RE_ASCII_CHARS = """^[\x20-\x7E]*$"""
    33 RE_DOMAIN = """^(?:[a-z0-9-]{1,63}\.){1,}[a-z]{2,6}$"""
    32 RE_DOMAIN = """^(?:[a-z0-9-]{1,63}\.){1,}[a-z]{2,6}$"""
    34 RE_DOMAIN_SRCH = """^[a-z0-9-\.]+$"""
    33 RE_DOMAIN_SRCH = """^[a-z0-9-\.]+$"""
    35 RE_LOCALPART = """[^\w!#$%&'\*\+-\.\/=?^_`{\|}~]"""
    34 RE_LOCALPART = """[^\w!#$%&'\*\+-\.\/=?^_`{\|}~]"""
    36 RE_MBOX_NAMES = """^[\x20-\x25\x27-\x7E]*$"""
    35 RE_MBOX_NAMES = """^[\x20-\x25\x27-\x7E]*$"""
    37 locale.setlocale(locale.LC_ALL, '')
       
    38 ENCODING = locale.nl_langinfo(locale.CODESET)
       
    39 
    36 
    40 class VirtualMailManager(object):
    37 class VirtualMailManager(object):
    41     """The main class for vmm"""
    38     """The main class for vmm"""
    42     __slots__ = ('__Cfg', '__cfgFileName', '__cfgSections', '__dbh', '__scheme',
    39     __slots__ = ('__Cfg', '__cfgFileName', '__cfgSections', '__dbh', '__scheme',
    43             '__warnings', '_postconf')
    40             '__warnings', '_postconf')
    58             self.__Cfg.load()
    55             self.__Cfg.load()
    59             self.__Cfg.check()
    56             self.__Cfg.check()
    60             self.__cfgSections = self.__Cfg.getsections()
    57             self.__cfgSections = self.__Cfg.getsections()
    61             self.__scheme = self.__Cfg.get('misc', 'passwdscheme')
    58             self.__scheme = self.__Cfg.get('misc', 'passwdscheme')
    62             self._postconf = Postconf(self.__Cfg.get('bin', 'postconf'))
    59             self._postconf = Postconf(self.__Cfg.get('bin', 'postconf'))
    63         if not sys.argv[1] in ['cf', 'configure']:
    60         if not os.sys.argv[1] in ['cf', 'configure']:
    64             self.__chkenv()
    61             self.__chkenv()
    65 
    62 
    66     def __findCfgFile(self):
    63     def __findCfgFile(self):
    67         for path in ['/root', '/usr/local/etc', '/etc']:
    64         for path in ['/root', '/usr/local/etc', '/etc']:
    68             tmp = os.path.join(path, 'vmm.cfg')
    65             tmp = os.path.join(path, 'vmm.cfg')
   202             (address._domainname, address._localpart)
   199             (address._domainname, address._localpart)
   203         return VirtualMailManager._exists(dbh, sql)
   200         return VirtualMailManager._exists(dbh, sql)
   204     relocatedExists = staticmethod(relocatedExists)
   201     relocatedExists = staticmethod(relocatedExists)
   205 
   202 
   206     def _readpass(self):
   203     def _readpass(self):
       
   204         readp_msg0 = _(u'Enter new password: ').encode(ENCODING, 'replace')
       
   205         readp_msg1 = _(u'Retype new password: ').encode(ENCODING, 'replace')
   207         mismatched = True
   206         mismatched = True
   208         while mismatched:
   207         while mismatched:
   209             clear0 = getpass(prompt=_('Enter new password: '))
   208             clear0 = getpass(prompt=readp_msg0)
   210             clear1 = getpass(prompt=_('Retype new password: '))
   209             clear1 = getpass(prompt=readp_msg1)
   211             if clear0 != clear1:
   210             if clear0 != clear1:
   212                 msg = _('Sorry, passwords do not match')
   211                 w_std(_(u'Sorry, passwords do not match'))
   213                 sys.stderr.write('%s\n' % msg.encode(ENCODING, 'replace'))
       
   214                 continue
   212                 continue
   215             if len(clear0) < 1 or len(clear1) < 1:
   213             if len(clear0) < 1 or len(clear1) < 1:
   216                 msg = _('Sorry, empty passwords are not permitted')
   214                 w_std(_(u'Sorry, empty passwords are not permitted'))
   217                 sys.stderr.write('%s\n' % msg.encode(ENCODING, 'replace'))
       
   218                 continue
   215                 continue
   219             mismatched = False
   216             mismatched = False
   220         return clear0
   217         return clear0
   221 
   218 
   222     def __getAccount(self, address, password=None):
   219     def __getAccount(self, address, password=None):