VirtualMailManager/handler.py
branchv0.6.x
changeset 390 660b42391c8e
parent 381 98223e5c95e0
child 407 3162ff959375
equal deleted inserted replaced
389:5f7e9f778b29 390:660b42391c8e
    34      EmailAddress
    34      EmailAddress
    35 from VirtualMailManager.errors import \
    35 from VirtualMailManager.errors import \
    36      DomainError, NotRootError, PermissionError, VMMError
    36      DomainError, NotRootError, PermissionError, VMMError
    37 from VirtualMailManager.mailbox import new as new_mailbox
    37 from VirtualMailManager.mailbox import new as new_mailbox
    38 from VirtualMailManager.pycompat import all, any
    38 from VirtualMailManager.pycompat import all, any
       
    39 from VirtualMailManager.quotalimit import QuotaLimit
    39 from VirtualMailManager.relocated import Relocated
    40 from VirtualMailManager.relocated import Relocated
    40 from VirtualMailManager.transport import Transport
    41 from VirtualMailManager.transport import Transport
    41 
    42 
    42 
    43 
    43 _ = lambda msg: msg
    44 _ = lambda msg: msg
   420         import __builtin__
   421         import __builtin__
   421         assert 'cfg_dget' not in __builtin__.__dict__
   422         assert 'cfg_dget' not in __builtin__.__dict__
   422         __builtin__.__dict__['cfg_dget'] = self._cfg.dget
   423         __builtin__.__dict__['cfg_dget'] = self._cfg.dget
   423 
   424 
   424     def domain_add(self, domainname, transport=None):
   425     def domain_add(self, domainname, transport=None):
   425         """Wrapper around Domain.set_transport() and Domain.save()"""
   426         """Wrapper around Domain's set_quotalimit, set_transport and save."""
   426         dom = self._get_domain(domainname)
   427         dom = self._get_domain(domainname)
   427         if transport is None:
   428         if transport is None:
   428             dom.set_transport(Transport(self._dbh,
   429             dom.set_transport(Transport(self._dbh,
   429                               transport=self._cfg.dget('misc.transport')))
   430                               transport=self._cfg.dget('misc.transport')))
   430         else:
   431         else:
   431             dom.set_transport(Transport(self._dbh, transport=transport))
   432             dom.set_transport(Transport(self._dbh, transport=transport))
       
   433         dom.set_quotalimit(QuotaLimit(self._dbh,
       
   434                            bytes=self._cfg.dget('misc.quota_bytes'),
       
   435                            messages=self._cfg.dget('misc.quota_messages')))
   432         dom.set_directory(self._cfg.dget('misc.base_directory'))
   436         dom.set_directory(self._cfg.dget('misc.base_directory'))
   433         dom.save()
   437         dom.save()
   434         self._make_domain_dir(dom)
   438         self._make_domain_dir(dom)
       
   439 
       
   440     def domain_quotalimit(self, domainname, bytes_, messages=0, force=None):
       
   441         """Wrapper around Domain.update_quotalimit()."""
       
   442         if not all(isinstance(i, (int, long)) for i in (bytes_, messages)):
       
   443             raise TypeError("'bytes_' and 'messages' have to be "
       
   444                             "integers or longs.")
       
   445         if force is not None and force != 'force':
       
   446             raise DomainError(_(u"Invalid argument: '%s'") % force,
       
   447                               INVALID_ARGUMENT)
       
   448         dom = self._get_domain(domainname)
       
   449         quotalimit = QuotaLimit(self._dbh, bytes=bytes_, messages=messages)
       
   450         if force is None:
       
   451             dom.update_quotalimit(quotalimit)
       
   452         else:
       
   453             dom.update_quotalimit(quotalimit, force=True)
   435 
   454 
   436     def domain_transport(self, domainname, transport, force=None):
   455     def domain_transport(self, domainname, transport, force=None):
   437         """Wrapper around Domain.update_transport()"""
   456         """Wrapper around Domain.update_transport()"""
   438         if force is not None and force != 'force':
   457         if force is not None and force != 'force':
   439             raise DomainError(_(u"Invalid argument: '%s'") % force,
   458             raise DomainError(_(u"Invalid argument: '%s'") % force,
   672         if not acc:
   691         if not acc:
   673             raise VMMError(_(u"The account '%s' doesn't exist.") %
   692             raise VMMError(_(u"The account '%s' doesn't exist.") %
   674                            acc.address, NO_SUCH_ACCOUNT)
   693                            acc.address, NO_SUCH_ACCOUNT)
   675         acc.modify('name', name)
   694         acc.modify('name', name)
   676 
   695 
       
   696     def user_quotalimit(self, emailaddress, bytes_, messages=0):
       
   697         """Wrapper for Account.update_quotalimit(QuotaLimit)."""
       
   698         if not all(isinstance(i, (int, long)) for i in (bytes_, messages)):
       
   699             raise TypeError("'bytes_' and 'messages' have to be "
       
   700                             "integers or longs.")
       
   701         acc = self._get_account(emailaddress)
       
   702         if not acc:
       
   703             raise VMMError(_(u"The account '%s' doesn't exist.") %
       
   704                            acc.address, NO_SUCH_ACCOUNT)
       
   705         acc.update_quotalimit(QuotaLimit(self._dbh, bytes=bytes_,
       
   706                                          messages=messages))
       
   707 
   677     def user_transport(self, emailaddress, transport):
   708     def user_transport(self, emailaddress, transport):
   678         """Wrapper for Account.modify('transport', ...)."""
   709         """Wrapper for Account.update_transport(Transport)."""
   679         if not isinstance(transport, basestring) or not transport:
   710         if not isinstance(transport, basestring) or not transport:
   680             raise VMMError(_(u"Could not accept transport: '%s'") % transport,
   711             raise VMMError(_(u"Could not accept transport: '%s'") % transport,
   681                            INVALID_ARGUMENT)
   712                            INVALID_ARGUMENT)
   682         acc = self._get_account(emailaddress)
   713         acc = self._get_account(emailaddress)
   683         if not acc:
   714         if not acc:
   684             raise VMMError(_(u"The account '%s' doesn't exist.") %
   715             raise VMMError(_(u"The account '%s' doesn't exist.") %
   685                            acc.address, NO_SUCH_ACCOUNT)
   716                            acc.address, NO_SUCH_ACCOUNT)
   686         acc.modify('transport', transport)
   717         acc.update_transport(Transport(self._dbh, transport=transport))
   687 
   718 
   688     def user_disable(self, emailaddress, services=None):
   719     def user_disable(self, emailaddress, services=None):
   689         """Wrapper for Account.disable(*services)"""
   720         """Wrapper for Account.disable(*services)"""
   690         if services is None:
   721         if services is None:
   691             services = []
   722             services = []