VirtualMailManager/cli/subcommands.py
branchv0.6.x
changeset 506 fb0ffde628d6
parent 487 fb0af82ab4af
child 510 1fa354bbdb90
equal deleted inserted replaced
505:3da8c919584f 506:fb0ffde628d6
    25 from VirtualMailManager.serviceset import SERVICES
    25 from VirtualMailManager.serviceset import SERVICES
    26 
    26 
    27 __all__ = (
    27 __all__ = (
    28     'Command', 'RunContext', 'cmd_map', 'usage', 'alias_add', 'alias_delete',
    28     'Command', 'RunContext', 'cmd_map', 'usage', 'alias_add', 'alias_delete',
    29     'alias_info', 'aliasdomain_add', 'aliasdomain_delete', 'aliasdomain_info',
    29     'alias_info', 'aliasdomain_add', 'aliasdomain_delete', 'aliasdomain_info',
    30     'aliasdomain_switch', 'config_get', 'config_set', 'configure',
    30     'aliasdomain_switch', 'catchall_add', 'catchall_info', 'catchall_delete',
       
    31     'config_get', 'config_set', 'configure',
    31     'domain_add', 'domain_delete',  'domain_info', 'domain_quota',
    32     'domain_add', 'domain_delete',  'domain_info', 'domain_quota',
    32     'domain_services', 'domain_transport', 'get_user', 'help_', 'list_domains',
    33     'domain_services', 'domain_transport', 'get_user', 'help_', 'list_domains',
    33     'list_pwschemes', 'relocated_add', 'relocated_delete', 'relocated_info',
    34     'list_pwschemes', 'relocated_add', 'relocated_delete', 'relocated_info',
    34     'user_add', 'user_delete', 'user_info', 'user_name', 'user_password',
    35     'user_add', 'user_delete', 'user_info', 'user_name', 'user_password',
    35     'user_quota', 'user_services', 'user_transport', 'version',
    36     'user_quota', 'user_services', 'user_transport', 'version',
   169                                  u'domain name.'), ctx.scmd)
   170                                  u'domain name.'), ctx.scmd)
   170     elif ctx.argc < 4:
   171     elif ctx.argc < 4:
   171         usage(EX_MISSING_ARGS, _(u'Missing destination domain name.'),
   172         usage(EX_MISSING_ARGS, _(u'Missing destination domain name.'),
   172               ctx.scmd)
   173               ctx.scmd)
   173     ctx.hdlr.aliasdomain_switch(ctx.args[2].lower(), ctx.args[3].lower())
   174     ctx.hdlr.aliasdomain_switch(ctx.args[2].lower(), ctx.args[3].lower())
       
   175 
       
   176 
       
   177 def catchall_add(ctx):
       
   178     """create a new catchall alias e-mail address"""
       
   179     if ctx.argc < 3:
       
   180         usage(EX_MISSING_ARGS, _(u'Missing domain and destination.'),
       
   181               ctx.scmd)
       
   182     elif ctx.argc < 4:
       
   183         usage(EX_MISSING_ARGS, _(u'Missing destination address.'), ctx.scmd)
       
   184     ctx.hdlr.catchall_add(ctx.args[2].lower(), *ctx.args[3:])
       
   185 
       
   186 
       
   187 def catchall_delete(ctx):
       
   188     """delete the specified destination or all of the catchall destination"""
       
   189     if ctx.argc < 3:
       
   190         usage(EX_MISSING_ARGS, _(u'Missing domain.'), ctx.scmd)
       
   191     elif ctx.argc < 4:
       
   192         ctx.hdlr.catchall_delete(ctx.args[2].lower())
       
   193     else:
       
   194         ctx.hdlr.catchall_delete(ctx.args[2].lower(), ctx.args[3])
       
   195 
       
   196 
       
   197 def catchall_info(ctx):
       
   198     """show the catchall destination(s) of the specified domain"""
       
   199     if ctx.argc < 3:
       
   200         usage(EX_MISSING_ARGS, _(u'Missing domain.'), ctx.scmd)
       
   201     address = ctx.args[2].lower()
       
   202     _print_catchall_info(address, ctx.hdlr.catchall_info(address))
   174 
   203 
   175 
   204 
   176 def config_get(ctx):
   205 def config_get(ctx):
   177     """show the actual value of the configuration option"""
   206     """show the actual value of the configuration option"""
   178     if ctx.argc < 3:
   207     if ctx.argc < 3:
   712     'aliasdomaininfo': cmd('aliasdomaininfo', 'adi', aliasdomain_info, 'fqdn',
   741     'aliasdomaininfo': cmd('aliasdomaininfo', 'adi', aliasdomain_info, 'fqdn',
   713                          _(u'show the destination of the given alias domain')),
   742                          _(u'show the destination of the given alias domain')),
   714     'aliasdomainswitch': cmd('aliasdomainswitch', 'ads', aliasdomain_switch,
   743     'aliasdomainswitch': cmd('aliasdomainswitch', 'ads', aliasdomain_switch,
   715                              'fqdn destination', _(u'assign the given alias '
   744                              'fqdn destination', _(u'assign the given alias '
   716                              'domain to an other domain')),
   745                              'domain to an other domain')),
       
   746     # CatchallAlias commands
       
   747     'catchalladd': cmd('catchalladd', 'caa', catchall_add,
       
   748                        'domain destination ...',
       
   749                        _(u'add one or more catch-all destinations for a '
       
   750                          u'domain')),
       
   751     'catchalldelete': cmd('catchalldelete', 'cad', catchall_delete,
       
   752                        'domain [destination]',
       
   753                        _(u'delete the specified catch-all destination or all '
       
   754                          u'of a domain\'s destinations')),
       
   755     'catchallinfo': cmd('catchallinfo', 'cai', catchall_info, 'domain',
       
   756                      _(u'show the catch-all destination(s) of the specified domain')),
   717     # Domain commands
   757     # Domain commands
   718     'domainadd': cmd('domainadd', 'da', domain_add, 'fqdn [transport]',
   758     'domainadd': cmd('domainadd', 'da', domain_add, 'fqdn [transport]',
   719                      _(u'create a new domain')),
   759                      _(u'create a new domain')),
   720     'domaindelete': cmd('domaindelete', 'dd', domain_delete, 'fqdn [force]',
   760     'domaindelete': cmd('domaindelete', 'dd', domain_delete, 'fqdn [force]',
   721                       _(u'delete the given domain and all its alias domains')),
   761                       _(u'delete the given domain and all its alias domains')),
   845     w_std(_(u'\tMail for %s will be redirected to:') % alias)
   885     w_std(_(u'\tMail for %s will be redirected to:') % alias)
   846     w_std(*(u'\t     * %s' % dest for dest in destinations))
   886     w_std(*(u'\t     * %s' % dest for dest in destinations))
   847     print
   887     print
   848 
   888 
   849 
   889 
       
   890 def _print_catchall_info(domain, destinations):
       
   891     """Print the catchall destinations of a domain"""
       
   892     title = _(u'Catch-all information')
       
   893     w_std(title, u'-' * len(title))
       
   894     w_std(_(u'\tMail to unknown localparts in domain %s will be sent to:')
       
   895           % domain)
       
   896     w_std(*(u'\t     * %s' % dest for dest in destinations))
       
   897     print
       
   898 
       
   899 
   850 def _print_relocated_info(**kwargs):
   900 def _print_relocated_info(**kwargs):
   851     """Print the old and new addresses of a relocated user."""
   901     """Print the old and new addresses of a relocated user."""
   852     title = _(u'Relocated information')
   902     title = _(u'Relocated information')
   853     w_std(title, u'-' * len(title))
   903     w_std(title, u'-' * len(title))
   854     w_std(_(u"\tUser '%(addr)s' has moved to '%(dest)s'") % kwargs, '')
   904     w_std(_(u"\tUser '%(addr)s' has moved to '%(dest)s'") % kwargs, '')