VirtualMailManager/VirtualMailManager.py
changeset 34 6d74e20c5b3b
parent 32 ceb700bc4a80
child 35 22cc616aef61
equal deleted inserted replaced
33:bee57f4616a2 34:6d74e20c5b3b
    71             self.__chkenv()
    71             self.__chkenv()
    72 
    72 
    73     def __chkCfgFile(self):
    73     def __chkCfgFile(self):
    74         """Checks the configuration file, returns bool"""
    74         """Checks the configuration file, returns bool"""
    75         if not os.path.isfile(self.__cfgFileName):
    75         if not os.path.isfile(self.__cfgFileName):
    76             raise VMMException((_("The file »%s« does not exists.") %
    76             raise VMMException((_(u"The file »%s« does not exists.") %
    77                 self.__cfgFileName, ERR.CONF_NOFILE))
    77                 self.__cfgFileName, ERR.CONF_NOFILE))
    78         fstat = os.stat(self.__cfgFileName)
    78         fstat = os.stat(self.__cfgFileName)
    79         try:
    79         try:
    80             fmode = self.__getFileMode()
    80             fmode = self.__getFileMode()
    81         except:
    81         except:
   138         if len(localpart) > 64:
   138         if len(localpart) > 64:
   139             raise VMMException((_('The local part is too long'),
   139             raise VMMException((_('The local part is too long'),
   140                 ERR.LOCALPART_TOO_LONG))
   140                 ERR.LOCALPART_TOO_LONG))
   141         if re.compile(RE_LOCALPART).search(localpart):
   141         if re.compile(RE_LOCALPART).search(localpart):
   142             raise VMMException((
   142             raise VMMException((
   143                 _('The local part »%s« contains invalid characters.') %
   143                 _(u'The local part »%s« contains invalid characters.') %
   144                 localpart, ERR.LOCALPART_INVALID))
   144                 localpart, ERR.LOCALPART_INVALID))
   145         return localpart
   145         return localpart
   146 
   146 
   147     def __idn2ascii(self, domainname):
   147     def __idn2ascii(self, domainname):
   148         """Converts an idn domainname in punycode.
   148         """Converts an idn domainname in punycode.
   188 
   188 
   189     def __chkEmailAddress(self, address):
   189     def __chkEmailAddress(self, address):
   190         try:
   190         try:
   191             localpart, domain = address.split('@')
   191             localpart, domain = address.split('@')
   192         except ValueError:
   192         except ValueError:
   193             raise VMMException((_("Missing '@' sign in e-mail address »%s«.") %
   193             raise VMMException((_(u"Missing '@' sign in e-mail address »%s«.") %
   194                 address, ERR.INVALID_ADDRESS))
   194                 address, ERR.INVALID_ADDRESS))
   195         except AttributeError:
   195         except AttributeError:
   196             raise VMMException((_("»%s« looks not like an e-mail address.") %
   196             raise VMMException((_(u"»%s« looks not like an e-mail address.") %
   197                 address, ERR.INVALID_ADDRESS))
   197                 address, ERR.INVALID_ADDRESS))
   198         domain = self.__chkDomainname(domain)
   198         domain = self.__chkDomainname(domain)
   199         localpart = self.__chkLocalpart(localpart)
   199         localpart = self.__chkLocalpart(localpart)
   200         return '%s@%s' % (localpart, domain)
   200         return '%s@%s' % (localpart, domain)
   201 
   201 
   407         """
   407         """
   408         try:
   408         try:
   409             if not section:
   409             if not section:
   410                 self.__Cfg.configure(self.__cfgSections)
   410                 self.__Cfg.configure(self.__cfgSections)
   411             elif section not in self.__cfgSections:
   411             elif section not in self.__cfgSections:
   412                 raise VMMException((_("Invalid section: »%s«") % section,
   412                 raise VMMException((_(u"Invalid section: »%s«") % section,
   413                     ERR.INVALID_SECTION))
   413                     ERR.INVALID_SECTION))
   414             else:
   414             else:
   415                 self.__Cfg.configure([section])
   415                 self.__Cfg.configure([section])
   416         except:
   416         except:
   417             raise
   417             raise
   421         dom.save()
   421         dom.save()
   422         self.__domdirmake(dom.getDir(), dom.getID())
   422         self.__domdirmake(dom.getDir(), dom.getID())
   423 
   423 
   424     def domain_transport(self, domainname, transport, force=None):
   424     def domain_transport(self, domainname, transport, force=None):
   425         if force is not None and force != 'force':
   425         if force is not None and force != 'force':
   426             raise VMMDomainException((_('Invalid argument: »%s«') % force,
   426             raise VMMDomainException((_(u'Invalid argument: »%s«') % force,
   427                 ERR.INVALID_OPTION))
   427                 ERR.INVALID_OPTION))
   428         dom = self.__getDomain(domainname, None)
   428         dom = self.__getDomain(domainname, None)
   429         if force is None:
   429         if force is None:
   430             dom.updateTransport(transport)
   430             dom.updateTransport(transport)
   431         else:
   431         else:
   432             dom.updateTransport(transport, force=True)
   432             dom.updateTransport(transport, force=True)
   433 
   433 
   434     def domain_delete(self, domainname, force=None):
   434     def domain_delete(self, domainname, force=None):
   435         if not force is None and force not in ['deluser','delalias','delall']:
   435         if not force is None and force not in ['deluser','delalias','delall']:
   436             raise VMMDomainException((_('Invalid argument: »%s«') % force,
   436             raise VMMDomainException((_(u'Invalid argument: »%s«') % force,
   437                 ERR.INVALID_OPTION))
   437                 ERR.INVALID_OPTION))
   438         dom = self.__getDomain(domainname)
   438         dom = self.__getDomain(domainname)
   439         gid = dom.getID()
   439         gid = dom.getID()
   440         domdir = dom.getDir()
   440         domdir = dom.getDir()
   441         if self.__Cfg.getboolean('misc', 'forcedel') or force == 'delall':
   441         if self.__Cfg.getboolean('misc', 'forcedel') or force == 'delall':