18 from VirtualMailManager.cli import get_winsize, prog, w_err, w_std |
18 from VirtualMailManager.cli import get_winsize, prog, w_err, w_std |
19 from VirtualMailManager.common import human_size, size_in_bytes, \ |
19 from VirtualMailManager.common import human_size, size_in_bytes, \ |
20 version_str, format_domain_default |
20 version_str, format_domain_default |
21 from VirtualMailManager.constants import __copyright__, __date__, \ |
21 from VirtualMailManager.constants import __copyright__, __date__, \ |
22 __version__, ACCOUNT_EXISTS, ALIAS_EXISTS, ALIASDOMAIN_ISDOMAIN, \ |
22 __version__, ACCOUNT_EXISTS, ALIAS_EXISTS, ALIASDOMAIN_ISDOMAIN, \ |
23 DOMAIN_ALIAS_EXISTS, INVALID_ARGUMENT, EX_MISSING_ARGS, RELOCATED_EXISTS |
23 DOMAIN_ALIAS_EXISTS, INVALID_ARGUMENT, EX_MISSING_ARGS, \ |
|
24 RELOCATED_EXISTS, TYPE_ACCOUNT, TYPE_ALIAS, TYPE_RELOCATED |
24 from VirtualMailManager.errors import VMMError |
25 from VirtualMailManager.errors import VMMError |
25 from VirtualMailManager.password import list_schemes |
26 from VirtualMailManager.password import list_schemes |
26 from VirtualMailManager.serviceset import SERVICES |
27 from VirtualMailManager.serviceset import SERVICES |
27 |
28 |
28 __all__ = ( |
29 __all__ = ( |
30 'alias_info', 'aliasdomain_add', 'aliasdomain_delete', 'aliasdomain_info', |
31 'alias_info', 'aliasdomain_add', 'aliasdomain_delete', 'aliasdomain_info', |
31 'aliasdomain_switch', 'catchall_add', 'catchall_info', 'catchall_delete', |
32 'aliasdomain_switch', 'catchall_add', 'catchall_info', 'catchall_delete', |
32 'config_get', 'config_set', 'configure', |
33 'config_get', 'config_set', 'configure', |
33 'domain_add', 'domain_delete', 'domain_info', 'domain_quota', |
34 'domain_add', 'domain_delete', 'domain_info', 'domain_quota', |
34 'domain_services', 'domain_transport', 'domain_note', 'get_user', 'help_', |
35 'domain_services', 'domain_transport', 'domain_note', 'get_user', 'help_', |
35 'list_domains', 'list_pwschemes', 'relocated_add', 'relocated_delete', |
36 'list_domains', 'list_pwschemes', 'list_users', 'list_aliases', |
|
37 'list_relocated', 'list_addresses', 'relocated_add', 'relocated_delete', |
36 'relocated_info', 'user_add', 'user_delete', 'user_info', 'user_name', |
38 'relocated_info', 'user_add', 'user_delete', 'user_info', 'user_name', |
37 'user_password', 'user_quota', 'user_services', 'user_transport', |
39 'user_password', 'user_quota', 'user_services', 'user_transport', |
38 'user_note', 'version', |
40 'user_note', 'version', |
39 ) |
41 ) |
40 |
42 |
487 w_std(key, len(key) * '-') |
489 w_std(key, len(key) * '-') |
488 w_std('\n'.join(txt_wrpr.wrap(' '.join(value))), '') |
490 w_std('\n'.join(txt_wrpr.wrap(' '.join(value))), '') |
489 |
491 |
490 txt_wrpr.initial_indent, txt_wrpr.subsequent_indent = old_ii, old_si |
492 txt_wrpr.initial_indent, txt_wrpr.subsequent_indent = old_ii, old_si |
491 txt_wrpr.width = txt_wrpr.width + 8 |
493 txt_wrpr.width = txt_wrpr.width + 8 |
|
494 |
|
495 |
|
496 def list_addresses(ctx, limit=None): |
|
497 """List all addresses / search addresses by pattern. The output can be |
|
498 limited with TYPE_ACCOUNT, TYPE_ALIAS and TYPE_RELOCATED, which can be |
|
499 bitwise ORed as a combination. Not specifying a limit is the same as |
|
500 combining all three.""" |
|
501 if limit is None: |
|
502 limit = TYPE_ACCOUNT | TYPE_ALIAS | TYPE_RELOCATED |
|
503 matching = ctx.argc > 2 |
|
504 if matching: |
|
505 gids, addresses = ctx.hdlr.address_list(limit, ctx.args[2].lower()) |
|
506 else: |
|
507 gids, addresses = ctx.hdlr.address_list(limit) |
|
508 _print_address_list(limit, gids, addresses, matching) |
|
509 |
|
510 |
|
511 def list_users(ctx): |
|
512 """list all user accounts / search user accounts by pattern""" |
|
513 return list_addresses(ctx, TYPE_ACCOUNT) |
|
514 |
|
515 def list_aliases(ctx): |
|
516 """list all aliases / search aliases by pattern""" |
|
517 return list_addresses(ctx, TYPE_ALIAS) |
|
518 |
|
519 def list_relocated(ctx): |
|
520 """list all relocated records / search relocated records by pattern""" |
|
521 return list_addresses(ctx, TYPE_RELOCATED) |
492 |
522 |
493 |
523 |
494 def relocated_add(ctx): |
524 def relocated_add(ctx): |
495 """create a new record for a relocated user""" |
525 """create a new record for a relocated user""" |
496 if ctx.argc < 3: |
526 if ctx.argc < 3: |
809 'fqdn transport [force]', |
839 'fqdn transport [force]', |
810 _(u'update the transport of the specified domain')), |
840 _(u'update the transport of the specified domain')), |
811 'domainnote': cmd('domainnote', 'do', domain_note, |
841 'domainnote': cmd('domainnote', 'do', domain_note, |
812 'fqdn note', |
842 'fqdn note', |
813 _(u'update the note of the given domain')), |
843 _(u'update the note of the given domain')), |
|
844 # List commands |
814 'listdomains': cmd('listdomains', 'ld', list_domains, '[pattern]', |
845 'listdomains': cmd('listdomains', 'ld', list_domains, '[pattern]', |
815 _(u'list all domains or search for domains by pattern')), |
846 _(u'list all domains or search for domains by pattern')), |
|
847 'listaddresses': cmd('listaddresses', 'll', list_addresses, '[pattern]', |
|
848 _(u'list all addresses or search for addresses by pattern')), |
|
849 'listusers': cmd('listusers', 'lu', list_users, '[pattern]', |
|
850 _(u'list all user accounts or search for accounts by pattern')), |
|
851 'listaliases': cmd('listaliases', 'la', list_aliases, '[pattern]', |
|
852 _(u'list all aliases or search for aliases by pattern')), |
|
853 'listrelocated': cmd('listrelocated', 'lr', list_relocated, '[pattern]', |
|
854 _(u'list all relocated entries or search for entries by pattern')), |
816 # Relocated commands |
855 # Relocated commands |
817 'relocatedadd': cmd('relocatedadd', 'ra', relocated_add, |
856 'relocatedadd': cmd('relocatedadd', 'ra', relocated_add, |
818 'address newaddress', |
857 'address newaddress', |
819 _(u'create a new record for a relocated user')), |
858 _(u'create a new record for a relocated user')), |
820 'relocateddelete': cmd('relocateddelete', 'rd', relocated_delete, |
859 'relocateddelete': cmd('relocateddelete', 'rd', relocated_delete, |
985 else: |
1024 else: |
986 w_std(_('\tNone')) |
1025 w_std(_('\tNone')) |
987 print |
1026 print |
988 |
1027 |
989 |
1028 |
|
1029 def _print_address_list(which, dids, addresses, matching): |
|
1030 """Print a list of (matching) addresses.""" |
|
1031 _trans = { TYPE_ACCOUNT : _('user accounts') |
|
1032 , TYPE_ALIAS : _('aliases') |
|
1033 , TYPE_RELOCATED : _('relocated entries') |
|
1034 , TYPE_ACCOUNT | TYPE_ALIAS |
|
1035 : _('user accounts and aliases') |
|
1036 , TYPE_ACCOUNT | TYPE_RELOCATED |
|
1037 : _('user accounts and relocated entries') |
|
1038 , TYPE_ALIAS | TYPE_RELOCATED |
|
1039 : _('aliases and relocated entries') |
|
1040 , TYPE_ACCOUNT | TYPE_ALIAS | TYPE_RELOCATED : _('addresses') |
|
1041 } |
|
1042 try: |
|
1043 if matching: |
|
1044 title = _(u'Matching %s') % _trans[which] |
|
1045 else: |
|
1046 title = _(u'Existing %s') % _trans[which] |
|
1047 w_std(title, '-' * len(title)) |
|
1048 except KeyError: |
|
1049 raise VMMError(_("Invalid address type for list: '%s'") % which, |
|
1050 INVALID_ARGUMENT) |
|
1051 if addresses: |
|
1052 if which & (which - 1) == 0: |
|
1053 # only one type is requested, so no type indicator |
|
1054 _trans = { TYPE_ACCOUNT : _('') |
|
1055 , TYPE_ALIAS : _('') |
|
1056 , TYPE_RELOCATED : _('') |
|
1057 } |
|
1058 else: |
|
1059 _trans = { TYPE_ACCOUNT : _('u') |
|
1060 , TYPE_ALIAS : _('a') |
|
1061 , TYPE_RELOCATED : _('r') |
|
1062 } |
|
1063 for did in dids: |
|
1064 for addr, atype, aliasdomain in addresses[did]: |
|
1065 if aliasdomain: |
|
1066 leader = '[%s-]' % _trans[atype] |
|
1067 else: |
|
1068 leader = '[%s+]' % _trans[atype] |
|
1069 w_std('\t%s %s' % (leader, addr)) |
|
1070 else: |
|
1071 w_std(_('\tNone')) |
|
1072 print |
|
1073 |
|
1074 |
990 def _print_aliasdomain_info(info): |
1075 def _print_aliasdomain_info(info): |
991 """Print alias domain information.""" |
1076 """Print alias domain information.""" |
992 title = _(u'Alias domain information') |
1077 title = _(u'Alias domain information') |
993 for key in ('alias', 'domain'): |
1078 for key in ('alias', 'domain'): |
994 if info[key].startswith('xn--'): |
1079 if info[key].startswith('xn--'): |