VirtualMailManager/handler.py
branchv0.6.x
changeset 441 1af5fe0683ce
parent 426 933b9debbec1
child 444 95275b61ff8a
equal deleted inserted replaced
440:1a08fe35b496 441:1af5fe0683ce
    26 from VirtualMailManager.constants import MIN_GID, MIN_UID, \
    26 from VirtualMailManager.constants import MIN_GID, MIN_UID, \
    27      ACCOUNT_EXISTS, ALIAS_EXISTS, CONF_NOFILE, CONF_NOPERM, CONF_WRONGPERM, \
    27      ACCOUNT_EXISTS, ALIAS_EXISTS, CONF_NOFILE, CONF_NOPERM, CONF_WRONGPERM, \
    28      DATABASE_ERROR, DOMAINDIR_GROUP_MISMATCH, DOMAIN_INVALID, \
    28      DATABASE_ERROR, DOMAINDIR_GROUP_MISMATCH, DOMAIN_INVALID, \
    29      FOUND_DOTS_IN_PATH, INVALID_ARGUMENT, MAILDIR_PERM_MISMATCH, \
    29      FOUND_DOTS_IN_PATH, INVALID_ARGUMENT, MAILDIR_PERM_MISMATCH, \
    30      NOT_EXECUTABLE, NO_SUCH_ACCOUNT, NO_SUCH_ALIAS, NO_SUCH_BINARY, \
    30      NOT_EXECUTABLE, NO_SUCH_ACCOUNT, NO_SUCH_ALIAS, NO_SUCH_BINARY, \
    31      NO_SUCH_DIRECTORY, NO_SUCH_RELOCATED, RELOCATED_EXISTS, VMM_ERROR
    31      NO_SUCH_DIRECTORY, NO_SUCH_RELOCATED, RELOCATED_EXISTS, UNKNOWN_SERVICE, \
    32 from VirtualMailManager.domain import Domain, get_gid
    32      VMM_ERROR
       
    33 from VirtualMailManager.domain import Domain
    33 from VirtualMailManager.emailaddress import DestinationEmailAddress, \
    34 from VirtualMailManager.emailaddress import DestinationEmailAddress, \
    34      EmailAddress
    35      EmailAddress
    35 from VirtualMailManager.errors import \
    36 from VirtualMailManager.errors import \
    36      DomainError, NotRootError, PermissionError, VMMError
    37      DomainError, NotRootError, PermissionError, VMMError
    37 from VirtualMailManager.mailbox import new as new_mailbox
    38 from VirtualMailManager.mailbox import new as new_mailbox
    38 from VirtualMailManager.pycompat import all, any
    39 from VirtualMailManager.pycompat import all, any
    39 from VirtualMailManager.quotalimit import QuotaLimit
    40 from VirtualMailManager.quotalimit import QuotaLimit
    40 from VirtualMailManager.relocated import Relocated
    41 from VirtualMailManager.relocated import Relocated
       
    42 from VirtualMailManager.serviceset import ServiceSet, SERVICES
    41 from VirtualMailManager.transport import Transport
    43 from VirtualMailManager.transport import Transport
    42 
    44 
    43 
    45 
    44 _ = lambda msg: msg
    46 _ = lambda msg: msg
    45 _db_mod = None
    47 _db_mod = None
   431         else:
   433         else:
   432             dom.set_transport(Transport(self._dbh, transport=transport))
   434             dom.set_transport(Transport(self._dbh, transport=transport))
   433         dom.set_quotalimit(QuotaLimit(self._dbh,
   435         dom.set_quotalimit(QuotaLimit(self._dbh,
   434                            bytes=long(self._cfg.dget('misc.quota_bytes')),
   436                            bytes=long(self._cfg.dget('misc.quota_bytes')),
   435                            messages=self._cfg.dget('misc.quota_messages')))
   437                            messages=self._cfg.dget('misc.quota_messages')))
       
   438         dom.set_serviceset(ServiceSet(self._dbh,
       
   439                                       imap=self._cfg.dget('account.imap'),
       
   440                                       pop3=self._cfg.dget('account.pop3'),
       
   441                                       sieve=self._cfg.dget('account.sieve'),
       
   442                                       smtp=self._cfg.dget('account.smtp')))
   436         dom.set_directory(self._cfg.dget('misc.base_directory'))
   443         dom.set_directory(self._cfg.dget('misc.base_directory'))
   437         dom.save()
   444         dom.save()
   438         self._make_domain_dir(dom)
   445         self._make_domain_dir(dom)
   439 
   446 
   440     def domain_quotalimit(self, domainname, bytes_, messages=0, force=None):
   447     def domain_quotalimit(self, domainname, bytes_, messages=0, force=None):
   449         quotalimit = QuotaLimit(self._dbh, bytes=bytes_, messages=messages)
   456         quotalimit = QuotaLimit(self._dbh, bytes=bytes_, messages=messages)
   450         if force is None:
   457         if force is None:
   451             dom.update_quotalimit(quotalimit)
   458             dom.update_quotalimit(quotalimit)
   452         else:
   459         else:
   453             dom.update_quotalimit(quotalimit, force=True)
   460             dom.update_quotalimit(quotalimit, force=True)
       
   461 
       
   462     def domain_services(self, domainname, force=None, *services):
       
   463         """Wrapper around Domain.update_serviceset()."""
       
   464         kwargs = dict.fromkeys(SERVICES, False)
       
   465         if force is not None and force != 'force':
       
   466             raise DomainError(_(u"Invalid argument: '%s'") % force,
       
   467                               INVALID_ARGUMENT)
       
   468         for service in set(services):
       
   469             if service not in SERVICES:
       
   470                 raise DomainError(_(u"Unknown service: '%s'") % service,
       
   471                                   UNKNOWN_SERVICE)
       
   472             kwargs[service] = True
       
   473 
       
   474         dom = self._get_domain(domainname)
       
   475         serviceset = ServiceSet(self._dbh, **kwargs)
       
   476         dom.update_serviceset(serviceset, (True, False)[not force])
   454 
   477 
   455     def domain_transport(self, domainname, transport, force=None):
   478     def domain_transport(self, domainname, transport, force=None):
   456         """Wrapper around Domain.update_transport()"""
   479         """Wrapper around Domain.update_transport()"""
   457         if force is not None and force != 'force':
   480         if force is not None and force != 'force':
   458             raise DomainError(_(u"Invalid argument: '%s'") % force,
   481             raise DomainError(_(u"Invalid argument: '%s'") % force,