VirtualMailManager/VirtualMailManager.py
changeset 50 927b0705d31a
parent 49 9bd033177377
child 51 f5ca21303871
equal deleted inserted replaced
49:9bd033177377 50:927b0705d31a
   143         """
   143         """
   144         tmp = []
   144         tmp = []
   145         for label in domainname.split('.'):
   145         for label in domainname.split('.'):
   146             if len(label) == 0:
   146             if len(label) == 0:
   147                 continue
   147                 continue
   148             #tmp.append(ToASCII(unicode(label, ENCODING_IN)))
       
   149             tmp.append(ToASCII(label))
   148             tmp.append(ToASCII(label))
   150         return '.'.join(tmp)
   149         return '.'.join(tmp)
   151     idn2ascii = staticmethod(idn2ascii)
   150     idn2ascii = staticmethod(idn2ascii)
   152 
   151 
   153     def ace2idna(domainname):
   152     def ace2idna(domainname):
   227                 destination = VirtualMailManager.chkLocalpart(destination)
   226                 destination = VirtualMailManager.chkLocalpart(destination)
   228         self.__dbConnect()
   227         self.__dbConnect()
   229         return Alias(self.__dbh, address, destination)
   228         return Alias(self.__dbh, address, destination)
   230 
   229 
   231     def __getDomain(self, domainname, transport=None):
   230     def __getDomain(self, domainname, transport=None):
   232         domainname = VirtualMailManager.chkDomainname(domainname)
       
   233         if transport is None:
   231         if transport is None:
   234             transport = self.__Cfg.get('misc', 'transport')
   232             transport = self.__Cfg.get('misc', 'transport')
   235         self.__dbConnect()
   233         self.__dbConnect()
   236         return Domain(self.__dbh, domainname,
   234         return Domain(self.__dbh, domainname,
   237                 self.__Cfg.get('domdir', 'base'), transport)
   235                 self.__Cfg.get('domdir', 'base'), transport)
   425         try:
   423         try:
   426             return self.__Cfg.getboolean('config', 'done')
   424             return self.__Cfg.getboolean('config', 'done')
   427         except ValueError, e:
   425         except ValueError, e:
   428             raise VMMConfigException(_(u"""Configurtion error: "%s"
   426             raise VMMConfigException(_(u"""Configurtion error: "%s"
   429 (in section "connfig", option "done") see also: vmm.cfg(5)\n""") % str(e),
   427 (in section "connfig", option "done") see also: vmm.cfg(5)\n""") % str(e),
   430     ERR.CONF_ERROR)
   428                   ERR.CONF_ERROR)
   431 
   429 
   432     def configure(self, section=None):
   430     def configure(self, section=None):
   433         """Starts interactive configuration.
   431         """Starts interactive configuration.
   434 
   432 
   435         Configures in interactive mode options in the given section.
   433         Configures in interactive mode options in the given section.
   504         Keyword arguments:
   502         Keyword arguments:
   505         aliasname -- the alias name of the domain (str)
   503         aliasname -- the alias name of the domain (str)
   506         domainname -- name of the target domain (str)
   504         domainname -- name of the target domain (str)
   507         """
   505         """
   508         dom = self.__getDomain(domainname)
   506         dom = self.__getDomain(domainname)
   509         # XXX chk by DomainAlias!!!
       
   510         aliasname = VirtualMailManager.chkDomainname(aliasname)
       
   511         dom.saveAlias(aliasname)
   507         dom.saveAlias(aliasname)
   512 
   508 
   513     def domain_alias_delete(self, aliasname):
   509     def domain_alias_delete(self, aliasname):
   514         """Deletes the specified alias name.
   510         """Deletes the specified alias name.
   515         
   511         
   516         Keyword arguments:
   512         Keyword arguments:
   517         aliasname -- the alias name of the domain (str)
   513         aliasname -- the alias name of the domain (str)
   518         """
   514         """
   519         from Domain import deleteAlias
   515         from Domain import deleteAlias
   520         aliasname = VirtualMailManager.chkDomainname(aliasname)
       
   521         # XXX chk by DomainAlias!!!
       
   522         self.__dbConnect()
   516         self.__dbConnect()
   523         deleteAlias(self.__dbh, aliasname)
   517         deleteAlias(self.__dbh, aliasname)
   524 
   518 
   525     def domain_list(self, pattern=None):
   519     def domain_list(self, pattern=None):
   526         from Domain import search
   520         from Domain import search
   535                 elif pattern.endswith('%'):
   529                 elif pattern.endswith('%'):
   536                     domain = pattern[:-1]
   530                     domain = pattern[:-1]
   537                 re.compile(RE_DOMAIN_SRCH)
   531                 re.compile(RE_DOMAIN_SRCH)
   538                 if not re.match(RE_DOMAIN_SRCH, domain):
   532                 if not re.match(RE_DOMAIN_SRCH, domain):
   539                     raise VMMException(
   533                     raise VMMException(
   540                     _(u"The pattern '%s' contains invalid characters.") %
   534                     _(u"The pattern »%s« contains invalid characters.") %
   541                     pattern, ERR.DOMAIN_INVALID)
   535                     pattern, ERR.DOMAIN_INVALID)
   542             else:
       
   543                 pattern = VirtualMailManager.chkDomainname(pattern)
       
   544                 # XXX chk by domain if not like
       
   545         self.__dbConnect()
   536         self.__dbConnect()
   546         return search(self.__dbh, pattern=pattern, like=like)
   537         return search(self.__dbh, pattern=pattern, like=like)
   547 
   538 
   548     def user_add(self, emailaddress, password):
   539     def user_add(self, emailaddress, password):
   549         acc = self.__getAccount(emailaddress, password)
   540         acc = self.__getAccount(emailaddress, password)