def execute(*args, **kw):
    """
        List deleted mailboxes
    """
    imap = IMAP()
    imap.connect()

    auth = Auth()
    auth.connect()

    domains = auth.list_domains()

    folders = []
    for domain in list(set(domains.keys())):
        folders.extend(imap.lm("DELETED/*@%s" % (domain)))

    folders.extend(imap.lm("DELETED/*"))

    print "Deleted folders:"

    for folder in folders:
        mbox_parts = imap.parse_mailfolder(folder)

        if not conf.raw:
            print "%s (Deleted at %s)" % (imap_utf7.decode(folder).encode('utf-8'), datetime.datetime.fromtimestamp(int(mbox_parts['hex_timestamp'], 16)))
        else:
            print "%s (Deleted at %s)" % (folder, datetime.datetime.fromtimestamp(int(mbox_parts['hex_timestamp'], 16)))
예제 #2
0
    def teardown_class(self):
        time.sleep(2)

        res_attr = conf.get('cyrus-sasl', 'result_attribute')

        exec("ac_folders = %s" % (conf.get_raw(conf.get('kolab', 'primary_domain'), 'autocreate_folders')))
        expected_number_of_folders = len(ac_folders.keys()) + 1

        users = []

        result = wap_client.users_list()
        for user in result['list'].keys():
            user_info = wap_client.user_info(user)
            users.append(user_info)
            result = wap_client.user_delete({'user': user})

        imap = IMAP()
        imap.connect()

        for user in users:
            if len(user[res_attr].split('@')) > 1:
                localpart = user[res_attr].split('@')[0]
                domain = user[res_attr].split('@')[1]

            folders = []
            folders.extend(imap.lm('user/%s' % (user[res_attr])))
            folders.extend(imap.lm('user/%s/*@%s' % (localpart,domain)))
예제 #3
0
def execute(*args, **kw):
    """
        List deleted mailboxes
    """

    try:
        domain = conf.cli_args.pop(0)
    except:
        domain = utils.ask_question(_("Domain"))

    imap = IMAP()
    imap.connect()

    auth = Auth()
    auth.connect()

    domains = auth.list_domains()

    folders = []
    for primary,secondaries in domains:
        if not domain == primary and not domain in secondaries:
            continue

        folders.extend(imap.lm("user/%%@%s" % (primary)))
        for secondary in secondaries:
            folders.extend(imap.lm("user/%%@%s" % (secondary)))

    print "Deleted folders:"

    for folder in folders:
        if not conf.raw:
            print imap_utf7.decode(folder)
        else:
            print folder
예제 #4
0
    def test_003_folders_metadata_set(self):
        imap = IMAP()
        imap.connect()

        exec("ac_folders = %s" % (conf.get_raw(
            conf.get('kolab', 'primary_domain'), 'autocreate_folders')))

        folders = []
        folders.extend(imap.lm('user/%(local)s@%(domain)s' % (self.user)))
        folders.extend(imap.lm('user/%(local)s/*@%(domain)s' % (self.user)))

        for folder in folders:
            metadata = imap.get_metadata(folder)

            folder_name = '/'.join(folder.split('/')[2:]).split('@')[0]
            if folder_name in ac_folders:
                if 'annotations' in ac_folders[folder_name]:
                    for _annotation in ac_folders[folder_name]['annotations']:
                        if _annotation.startswith('/private/'):
                            continue

                        _annotation_value = ac_folders[folder_name][
                            'annotations'][_annotation]
                        self.assertTrue(
                            _annotation in metadata[metadata.keys().pop()])
                        self.assertEqual(
                            _annotation_value,
                            metadata[metadata.keys().pop()][_annotation])
예제 #5
0
def execute(*args, **kw):
    """
        List deleted mailboxes
    """
    imap = IMAP()
    imap.connect()

    auth = Auth()
    auth.connect()

    domains = auth.list_domains()

    folders = []
    for domain in list(set(domains.keys())):
        folders.extend(imap.lm("DELETED/*@%s" % (domain)))

    folders.extend(imap.lm("DELETED/*"))

    print "Deleted folders:"

    for folder in folders:
        utf8_folder = imap_utf7.decode(folder).encode('utf-8')
        mbox_parts = imap.parse_mailfolder(utf8_folder)
        ts = datetime.datetime.fromtimestamp(int(mbox_parts['hex_timestamp'], 16))

        if not conf.raw:
            print "%s (Deleted at %s)" % (utf8_folder, ts)
        else:
            print "%s (Deleted at %s)" % (folder, ts)
예제 #6
0
    def test_001_two_johns(self):
        from tests.functional.user_add import user_add
        user_add("John", "Doe")
        user_add("John", "Doe")

        time.sleep(3)

        auth = Auth()
        auth.connect()

        max_tries = 20
        while max_tries > 0:
            recipient1 = auth.find_recipient('*****@*****.**')
            recipient2 = auth.find_recipient('*****@*****.**')

            if not recipient1 or not recipient2:
                time.sleep(1)
                max_tries -= 1
            else:
                break

        imap = IMAP()
        imap.connect()

        folders = imap.lm('user/[email protected]')
        self.assertEqual(len(folders), 1, "No INBOX found for first John")

        folders = imap.lm('user/[email protected]')
        self.assertEqual(len(folders), 1, "No INBOX found for second John")
예제 #7
0
def execute(*args, **kw):
    """
        List deleted mailboxes
    """

    try:
        domain = conf.cli_args.pop(0)
    except:
        domain = utils.ask_question(_("Domain"))

    imap = IMAP()
    imap.connect()

    auth = Auth()
    auth.connect()

    domains = auth.list_domains()

    folders = []
    for primary,secondaries in domains:
        if not domain == primary and not domain in secondaries:
            continue

        folders.extend(imap.lm("user/%%@%s" % (primary)))
        for secondary in secondaries:
            folders.extend(imap.lm("user/%%@%s" % (secondary)))

    print "Deleted folders:"

    for folder in folders:
        if not conf.raw:
            print imap_utf7.decode(folder)
        else:
            print folder
예제 #8
0
    def test_001_two_johns(self):
        from tests.functional.user_add import user_add
        user_add("John", "Doe")
        user_add("John", "Doe")

        time.sleep(3)

        auth = Auth()
        auth.connect()

        max_tries = 20
        while max_tries > 0:
            recipient1 = auth.find_recipient('*****@*****.**')
            recipient2 = auth.find_recipient('*****@*****.**')

            if not recipient1 or not recipient2:
                time.sleep(1)
                max_tries -= 1
            else:
                break

        imap = IMAP()
        imap.connect()

        folders = imap.lm('user/[email protected]')
        self.assertEqual(len(folders), 1, "No INBOX found for first John")

        folders = imap.lm('user/[email protected]')
        self.assertEqual(len(folders), 1, "No INBOX found for second John")
예제 #9
0
    def test_005_user_folders_metadata_set(self):
        imap = IMAP()
        imap.connect()

        ac_folders = conf.get_raw('kolab', 'autocreate_folders')
        exec("ac_folders = %s" % (ac_folders))

        folders = []
        folders.extend(imap.lm('user/%(local)s@%(domain)s' % (self.user)))
        folders.extend(imap.lm('user/%(local)s/*@%(domain)s' % (self.user)))

        for folder in folders:
            metadata = imap.get_metadata(folder)
            print metadata

            folder_name = '/'.join(folder.split('/')[2:]).split('@')[0]
            if ac_folders.has_key(folder_name):
                if ac_folders[folder_name].has_key('annotations'):
                    for _annotation in ac_folders[folder_name]['annotations'].keys():
                        if _annotation.startswith('/private'):
                            continue

                        _annotation_value = ac_folders[folder_name]['annotations'][_annotation]
                        self.assertTrue(metadata[metadata.keys().pop()].has_key(_annotation))
                        self.assertEqual(_annotation_value, metadata[metadata.keys().pop()][_annotation])
예제 #10
0
    def test_001_inbox_created(self):
        imap = IMAP()
        imap.connect()

        folders = imap.lm('user/%(local)s@%(domain)s' % (self.john))
        self.assertEqual(len(folders), 1)
        
        folders = imap.lm('user/%(local)s@%(domain)s' % (self.jane))
        self.assertEqual(len(folders), 1)
예제 #11
0
    def test_001_inbox_created(self):
        imap = IMAP()
        imap.connect()

        folders = imap.lm('user/%(local)s@%(domain)s' % (self.john))
        self.assertEqual(len(folders), 1)

        folders = imap.lm('user/%(local)s@%(domain)s' % (self.jane))
        self.assertEqual(len(folders), 1)
예제 #12
0
def execute(*args, **kw):
    """
        Synchronize or display changes
    """

    imap = IMAP()

    if not conf.connect_server == None:
        imap.connect(server=conf.connect_server)
    else:
        imap.connect()

    auth = Auth()
    auth.connect()

    domains = auth.list_domains()

    folders = imap.lm()

    imap_domains_not_domains = []

    for folder in folders:
        if len(folder.split('@')) > 1 and not folder.startswith('DELETED'):
            _folder_domain = folder.split('@')[-1]
            if not _folder_domain in list(set(domains.keys() + domains.values())):
                imap_domains_not_domains.append(folder.split('@')[-1])

    imap_domains_not_domains = list(set(imap_domains_not_domains))

    log.debug(_("Domains in IMAP not in LDAP: %r") % (imap_domains_not_domains), level=8)

    if len(imap_domains_not_domains) > 0:
        for domain in imap_domains_not_domains:
            folders = []

            folders.extend(imap.lm('shared/%%@%s' % (domain)))
            folders.extend(imap.lm('user/%%@%s' % (domain)))

            for folder in folders:
                if conf.delete:
                    if conf.dry_run:
                        if not folder.split('/')[0] == 'shared':
                            log.warning(_("No recipients for '%s' (would have deleted the mailbox if not for --dry-run)!") % ('/'.join(folder.split('/')[1:])))
                        else:
                            continue
                    else:
                        if not '/'.join(folder.split('/')[0]) == 'shared':
                            log.info(_("Deleting mailbox '%s' because it has no recipients") % (folder))
                            try:
                                imap.dm(folder)
                            except Exception, errmsg:
                                log.error(_("An error occurred removing mailbox %r: %r") % (folder, errmsg))
                        else:
                            log.info(_("Not automatically deleting shared folder '%s'") % (folder))
                else:
                    log.warning(_("No recipients for '%s' (use --delete to delete)!") % ('/'.join(folder.split('/')[1:])))
예제 #13
0
def execute(*args, **kw):
    """
        List mailboxes
    """

    try:
        aci_subject = conf.cli_args.pop(0)
    except:
        aci_subject = None

    imap = IMAP()
    imap.connect()

    folders = imap.lm()

    for folder in folders:
        acls = imap.list_acls(folder)

        if not aci_subject == None:
            if aci_subject in acls.keys():
                log.debug(_("Deleting ACL %s for subject %s on folder %s") % (
                        acls[aci_subject],
                        aci_subject,
                        folder
                    ), level=8)

                imap.set_acl(folder, aci_subject, '')

        #else:
            #for _aci_subject in acls.keys():
                # connect to auth(!)
                # find recipient result_attr=aci_subject
                # if no entry, expire acl
예제 #14
0
def execute(*args, **kw):
    """
        List mailboxes
    """

    try:
        aci_subject = conf.cli_args.pop(0)
    except:
        aci_subject = None

    imap = IMAP()
    imap.connect()

    folders = imap.lm()

    for folder in folders:
        acls = imap.list_acls(folder)

        if not aci_subject == None:
            if aci_subject in acls.keys():
                log.debug(_("Deleting ACL %s for subject %s on folder %s") %
                          (acls[aci_subject], aci_subject, folder),
                          level=8)

                imap.set_acl(folder, aci_subject, '')
예제 #15
0
    def test_001_inbox_created(self):
        time.sleep(2)
        imap = IMAP()
        imap.connect()

        folders = imap.lm('user/%(local)s@%(domain)s' % (self.user))
        self.assertEqual(len(folders), 1)
예제 #16
0
    def test_001_inbox_created(self):
        time.sleep(2)
        imap = IMAP()
        imap.connect()

        folders = imap.lm('user/%(local)s@%(domain)s' % (self.user))
        self.assertEqual(len(folders), 1)
예제 #17
0
def execute(*args, **kw):
    """
        List mailboxes
    """

    searches = []

    # See if conf.cli_args components make sense.
    for arg in conf.cli_args:
        if arg == '*':
            searches.append(arg)
        if arg.startswith('user'):
            searches.append(arg)
        if arg.startswith('shared'):
            searches.append(arg)
        if arg.startswith('DELETED'):
            searches.append(arg)
        if arg.startswith('news'):
            searches.append(arg)

    if len(searches) == 0:
        searches = [ '' ]

    imap = IMAP()
    imap.connect()

    folders = []

    for search in searches:
        log.debug(_("Appending folder search for %r") % (search), level=8)
        folders.extend(imap.lm(search))

    for folder in folders:
        print folder
예제 #18
0
def execute(*args, **kw):
    """
        Delete a message from a mail folder
    """

    try:
        folder = conf.cli_args.pop(0)

        try:
            uid = conf.cli_args.pop(0)
        except:
            log.error(_("Specify a UID"))
            sys.exit(1)
    except:
        log.error(_("Specify a folder"))
        sys.exit(1)

    imap = IMAP()
    imap.connect()

    _folder = imap.lm(folder)

    if _folder == None or _folder == []:
        log.error(_("No such folder"))
        sys.exit(1)

    imap.set_acl(folder, 'cyrus-admin', 'lrswt')

    imap.select(folder)

    imap.store(uid, '+FLAGS', '\\Deleted')
예제 #19
0
def execute(*args, **kw):
    """
        List deleted mailboxes
    """
    imap = IMAP()
    imap.connect()

    auth = Auth()
    auth.connect()

    domains = auth.list_domains()

    folders = []
    for domain in domains.keys():
        print "%s: %d" % (domain,len(imap.lm("user/%%@%s" % (domain))))

    null_realm = len(imap.lm("user/%%"))

    if null_realm > 0:
        print "null: %d" % (null_realm)
예제 #20
0
def purge_imap():
    time.sleep(2)

    imap = IMAP()
    imap.connect()

    for folder in imap.lm():
        try:
            imap.dm(folder)
        except:
            pass
예제 #21
0
def execute(*args, **kw):
    """
        List deleted mailboxes
    """
    imap = IMAP()
    imap.connect()

    auth = Auth()
    auth.connect()

    domains = auth.list_domains()

    folders = []
    for domain in domains.keys():
        print "%s: %d" % (domain, len(imap.lm("user/%%@%s" % (domain))))

    null_realm = len(imap.lm("user/%%"))

    if null_realm > 0:
        print "null: %d" % (null_realm)
예제 #22
0
    def test_004_user_additional_folders_created(self):
        time.sleep(2)
        imap = IMAP()
        imap.connect()

        ac_folders = conf.get_raw('kolab', 'autocreate_folders')
        exec("ac_folders = %s" % (ac_folders))

        folders = imap.lm('user/%(local)s/*@%(domain)s' % (self.user))

        self.assertEqual(len(folders), len(ac_folders.keys()))
예제 #23
0
def purge_imap():
    time.sleep(2)

    imap = IMAP()
    imap.connect()

    for folder in imap.lm():
        try:
            imap.dm(folder)
        except:
            pass
예제 #24
0
    def test_004_user_additional_folders_created(self):
        time.sleep(2)
        imap = IMAP()
        imap.connect()

        ac_folders = conf.get_raw('kolab', 'autocreate_folders')
        exec("ac_folders = %s" % (ac_folders))

        folders = imap.lm('user/%(local)s/*@%(domain)s' % (self.user))

        self.assertEqual(len(folders), len(ac_folders.keys()))
예제 #25
0
    def test_006_user_subscriptions(self):
        imap = IMAP()
        imap.connect(login=False)
        login = conf.get('cyrus-imap', 'admin_login')
        password = conf.get('cyrus-imap', 'admin_password')
        imap.login_plain(login, password, '*****@*****.**')

        folders = imap.lm()
        self.assertTrue("INBOX" in folders)

        folders = imap.imap.lsub()
        self.assertTrue("Calendar" in folders)
예제 #26
0
    def test_003_folder_types_set(self):
        imap = IMAP()
        imap.connect()

        exec("ac_folders = %s" % (conf.get_raw(conf.get('kolab', 'primary_domain'), 'autocreate_folders')))

        folders = []
        folders.extend(imap.lm('user/%(local)s@%(domain)s' % (self.user)))
        folders.extend(imap.lm('user/%(local)s/*@%(domain)s' % (self.user)))

        for folder in folders:
            annotation = imap.getannotation(folder)
            print annotation

            folder_name = '/'.join(folder.split('/')[2:]).split('@')[0]
            if ac_folders.has_key(folder_name):
                if ac_folders[folder_name].has_key('annotations'):
                    for _annotation in ac_folders[folder_name]['annotations'].keys():
                        _annotation_value = ac_folders[folder_name]['annotations'][_annotation]
                        self.assertTrue(annotation[annotation.keys().pop()].has_key(_annotation))
                        self.assertEqual(_annotation_value, annotation[annotation.keys().pop()][_annotation])
예제 #27
0
    def test_006_user_subscriptions(self):
        imap = IMAP()
        imap.connect(login=False)
        login = conf.get('cyrus-imap', 'admin_login')
        password = conf.get('cyrus-imap', 'admin_password')
        imap.login_plain(login, password, '*****@*****.**')

        folders = imap.lm()
        self.assertTrue("INBOX" in folders)

        folders = imap.imap.lsub()
        self.assertTrue("Calendar" in folders)
예제 #28
0
    def test_002_autocreate_folders_created(self):
        time.sleep(2)
        imap = IMAP()
        imap.connect()

        exec("ac_folders = %s" % (conf.get_raw(conf.get('kolab', 'primary_domain'), 'autocreate_folders')))

        folders = imap.lm('user/%(local)s/*@%(domain)s' % (self.user))

        print folders
        print ac_folders.keys()

        self.assertEqual(len(folders), len(ac_folders.keys()))
예제 #29
0
def execute(*args, **kw):
    """
        List messages in a folder
    """

    try:
        folder = conf.cli_args.pop(0)

    except:
        log.error(_("Specify a folder"))
        sys.exit(1)

    imap = IMAP()
    imap.connect()

    _folder = imap.lm(imap_utf7.encode(folder))

    if _folder == None or _folder == []:
        log.error(_("No such folder"))
        sys.exit(1)

    imap.set_acl(folder, 'cyrus-admin', 'lrs')

    imap.select(imap_utf7.encode(folder))

    if conf.list_deleted:
        typ, data = imap.search(None, 'ALL')
    else:
        typ, data = imap.search(None, '(ALL UNDELETED)')

    num_messages = len(data[0].split())

    for num in data[0].split():
        typ, flags = imap.fetch(num, 'FLAGS')
        flags = flags[0].split()
        if len(flags) >= 3:
            # Any flags are set
            if flags[2] == '(\\Deleted))':
                print num, '\Deleted'
            elif flags[2] == '(\\Deleted':
                print num, '\Deleted'
            elif '\\Deleted' in flags[3:]:
                print num, '\Deleted'
            elif '\\Deleted))' in flags[3:]:
                print num, '\Deleted'
            else:
                print num
        else:
            print num

    imap.set_acl(folder, 'cyrus-admin', '')
예제 #30
0
    def test_002_autocreate_folders_created(self):
        time.sleep(2)
        imap = IMAP()
        imap.connect()

        exec("ac_folders = %s" % (conf.get_raw(
            conf.get('kolab', 'primary_domain'), 'autocreate_folders')))

        folders = imap.lm('user/%(local)s/*@%(domain)s' % (self.user))

        print folders
        print ac_folders.keys()

        self.assertEqual(len(folders), len(ac_folders.keys()))
예제 #31
0
    def test_001_user_rename(self):
        """
            Rename user "Doe, John" to "Sixpack, Joe" and verify the recipient
            policy is applied, and the IMAP INBOX folder for the user is
            renamed.
        """
        auth = Auth()
        auth.connect()
        recipient = auth.find_recipient('*****@*****.**')
        user_info = wap_client.user_info(recipient)

        if not user_info.has_key('mailhost'):
            from tests.functional.synchronize import synchronize_once
            synchronize_once()

        imap = IMAP()
        imap.connect()
        folders = imap.lm('user/[email protected]')
        self.assertEqual(len(folders), 1)

        auth = Auth()
        auth.connect()
        recipient = auth.find_recipient("%(local)s@%(domain)s" % (self.user))

        user_info = wap_client.user_info(recipient)
        user_info['sn'] = 'Sixpack'
        user_info['givenname'] = 'Joe'
        user_info['uid'] = 'sixpack'
        user_edit = wap_client.user_edit(recipient, user_info)

        time.sleep(2)

        print imap.lm()

        user_info = wap_client.user_info('uid=sixpack,ou=People,dc=example,dc=org')
        if not user_info['mail'] == '*****@*****.**':
            from tests.functional.synchronize import synchronize_once
            synchronize_once()
            user_info = wap_client.user_info('uid=sixpack,ou=People,dc=example,dc=org')

        self.assertEqual(user_info['mail'], '*****@*****.**')

        print imap.lm()

        folders = imap.lm('user/[email protected]')
        self.assertEqual(len(folders), 0, "INBOX for john.doe still exists")

        folders = imap.lm('user/[email protected]')
        self.assertEqual(len(folders), 1, "INBOX for joe.sixpack does not exist")
예제 #32
0
    def test_001_user_rename(self):
        """
            Rename user "Doe, John" to "Sixpack, Joe" and verify the recipient
            policy is applied, and the IMAP INBOX folder for the user is
            renamed.
        """
        auth = Auth()
        auth.connect()
        recipient = auth.find_recipient('*****@*****.**')
        user_info = wap_client.user_info(recipient)

        if 'mailhost' not in user_info:
            from tests.functional.synchronize import synchronize_once
            synchronize_once()

        imap = IMAP()
        imap.connect()
        folders = imap.lm('user/[email protected]')
        self.assertEqual(len(folders), 1)

        auth = Auth()
        auth.connect()
        recipient = auth.find_recipient("%(local)s@%(domain)s" % (self.user))

        user_info = wap_client.user_info(recipient)
        user_info['sn'] = 'Sixpack'
        user_info['givenname'] = 'Joe'
        user_info['uid'] = 'sixpack'
        user_edit = wap_client.user_edit(recipient, user_info)

        time.sleep(2)

        print imap.lm()

        user_info = wap_client.user_info('uid=sixpack,ou=People,dc=example,dc=org')
        if not user_info['mail'] == '*****@*****.**':
            from tests.functional.synchronize import synchronize_once
            synchronize_once()
            user_info = wap_client.user_info('uid=sixpack,ou=People,dc=example,dc=org')

        self.assertEqual(user_info['mail'], '*****@*****.**')

        print imap.lm()

        folders = imap.lm('user/[email protected]')
        self.assertEqual(len(folders), 0, "INBOX for john.doe still exists")

        folders = imap.lm('user/[email protected]')
        self.assertEqual(len(folders), 1, "INBOX for joe.sixpack does not exist")
예제 #33
0
def execute(*args, **kw):
    """
        List mailboxes
    """

    searches = []

    # See if conf.cli_args components make sense.
    for arg in conf.cli_args:
        if arg == '*':
            searches.append(arg)
        if arg.startswith('user'):
            searches.append(arg)
        if arg.startswith('shared'):
            searches.append(arg)
        if arg.startswith('DELETED'):
            searches.append(arg)
        if arg.startswith('news'):
            searches.append(arg)

    if len(searches) == 0:
        searches = [ '' ]

    imap = IMAP()

    if not conf.connect_server == None:
        imap.connect(server=conf.connect_server)
    else:
        imap.connect()

    folders = []

    for search in searches:
        log.debug(_("Appending folder search for %r") % (search), level=8)
        folders.extend(imap.lm(imap_utf7.encode(search)))

    for folder in folders:
        if not conf.raw:
            print imap_utf7.decode(folder)
        else:
            print folder
예제 #34
0
def execute(*args, **kw):
    """
        List mailboxes
    """

    auth = Auth()
    domains = auth.list_domains()

    imap = IMAP()
    imap.connect()

    domain_folders = {}

    subjects = []
    # Placeholder for subjects that would have already been deleted
    subjects_deleted = []

    for domain in domains.keys():
        domain_folders[domain] = imap.lm("user/%%@%s" % (domain))

    for domain in domain_folders.keys():
        auth = Auth(domain=domain)
        auth.connect(domain)

        for folder in domain_folders[domain]:
            user = folder.replace('user/', '')

            try:
                recipient = auth.find_recipient(user)
            except ldap.NO_SUCH_OBJECT, errmsg:
                if not user in subjects_deleted and conf.dryrun:
                    subjects_deleted.append(user)

                if conf.dryrun:
                    log.info(
                        _("Would have deleted folder 'user/%s' (dryrun)") %
                        (user))
                else:
                    log.info(_("Deleting folder 'user/%s'") % (user))
                continue

            if len(recipient) == 0 or recipient == []:
                if not user in subjects_deleted and conf.dryrun:
                    subjects_deleted.append(user)

                if conf.dryrun:
                    log.info(
                        _("Would have deleted folder 'user/%s' (dryrun)") %
                        (user))
                else:
                    log.info(_("Deleting folder 'user/%s'") % (user))
                    try:
                        imap.dm(folder)
                    except:
                        log.error(
                            _("Error deleting folder 'user/%s'") % (user))
            else:
                log.debug(_("Valid recipient found for 'user/%s'") % (user),
                          level=6)

                if not user in subjects:
                    subjects.append(user)
예제 #35
0
def execute(*args, **kw):
    """
        List quota for a mailbox
    """

    try:
        quota_folder = conf.cli_args.pop(0)
    except IndexError, e:
        quota_folder = '*'

    imap = IMAP()
    imap.connect()

    folders = []

    quota_folders = imap.lm(quota_folder)
    for quota_folder in quota_folders:
        try:
            (used, quota) = imap.get_quota(quota_folder)
            if not used == None and not quota == None:
                if quota == 0:
                    print >> sys.stderr, _("The quota for folder %s is set to literally allow 0KB of storage.") % (quota_folder)
                    print "%d (Used: %d, Percentage: %s)" % (quota, used, u'\u221E')
                else:
                    percentage = round(((float)(used)/(float)(quota)) * 100.0, 1)
                    print "%d (Used: %d, Percentage: %d)" % (quota, used, percentage)
            else:
                print "No quota"
        except:
            try:
                (quota_root, used, quota) = imap.get_quota_root(quota_folder)
예제 #36
0
from pykolab.imap import IMAP
from pykolab.translate import _

log = pykolab.getLogger('pykolab.cli')
conf = pykolab.getConf()

def __init__():
    commands.register('delete_mailbox', execute, description=description(), aliases=['dm'])

def description():
    return """Delete a mailbox or sub-folder. Note that the mailbox or folder is removed recursively."""

def execute(*args, **kw):
    """
        Delete mailbox
    """

    try:
        delete_folder = conf.cli_args.pop(0)
    except IndexError, e:
        print >> sys.stderr, _("No mailbox specified")
        sys.exit(1)

    imap = IMAP()

    imap.connect()
    delete_folders = imap.lm(delete_folder)
    for delete_folder in delete_folders:
        imap.delete_mailfolder(delete_folder)

예제 #37
0

def execute(*args, **kw):
    try:
        folder = conf.cli_args.pop(0)
        try:
            quota = conf.cli_args.pop(0)
        except IndexError, errmsg:
            quota = utils.ask_question(_("New quota"))

    except IndexError, errmsg:
        folder = utils.ask_question(_("Folder name"))
        quota = utils.ask_question(_("New quota"))

    if len(folder.split('@')) > 1:
        domain = folder.split('@')[1]
    else:
        domain = conf.get('kolab', 'primary_domain')

    imap = IMAP()
    imap.connect(domain=domain)

    if not imap.has_folder(folder):
        print >> sys.stderr, _("No such folder %r") % (folder)
        sys.exit(1)

    for _folder in imap.lm(imap.folder_utf7(folder)):
        imap.set_quota(_folder, quota)
        print >> sys.stdout, "Quota for folder '%s' set to %d" % (_folder,
                                                                  int(quota))
예제 #38
0
        domain = folder.split('@')[1]
    elif not conf.user == None and len(conf.user.split('@')) > 1:
        domain = conf.user.split('@')[1]
    else:
        domain = conf.get('kolab', 'primary_domain')

    imap = IMAP()

    if not conf.user == None:
        imap.connect(domain=domain, login=False)

        backend = conf.get(domain, 'imap_backend')
        if backend == None:
            backend = conf.get('kolab', 'imap_backend')

        admin_login = conf.get(backend, 'admin_login')
        admin_password = conf.get(backend, 'admin_password')

        imap.login_plain(admin_login, admin_password, conf.user)
    else:
        imap.connect(domain=domain)

    if not imap.has_folder(folder):
        print >> sys.stderr, _("No such folder %r") % (folder)

    else:
        folders = imap.lm(imap_utf7.encode(folder))
        for folder in folders:
            imap.set_metadata(imap_utf7.decode(folder), metadata_path,
                              metadata_value)
예제 #39
0
def description():
    return """Delete an ACL entry for a folder."""

def execute(*args, **kw):
    try:
        folder = conf.cli_args.pop(0)
        try:
            identifier = conf.cli_args.pop(0)
        except IndexError, errmsg:
            identifier = utils.ask_question(_("ACI Subject"))

    except IndexError, errmsg:
        folder = utils.ask_question(_("Folder name"))
        quota = utils.ask_question(_("ACI Subject"))

    if len(folder.split('@')) > 1:
        domain = folder.split('@')[1]
    else:
        domain = conf.get('kolab', 'primary_domain')

    imap = IMAP()
    imap.connect(domain=domain)

    if not imap.has_folder(folder):
        print >> sys.stderr, _("No such folder %r") % (folder)

    else:
        folders = imap.lm(folder)
        for folder in folders:
            imap.set_acl(folder, identifier, '')
예제 #40
0
def execute(*args, **kw):
    """
        Synchronize or display changes
    """

    imap = IMAP()

    if not conf.connect_server == None:
        imap.connect(server=conf.connect_server)
    else:
        imap.connect()

    auth = Auth()
    auth.connect()

    result_attribute = conf.get('cyrus-sasl', 'result_attribute')
    if result_attribute is None:
        result_attribute = 'mail'

    domains = auth.list_domains()
    folders = imap.lm()

    imap_domains_not_domains = []

    for folder in folders:
        if len(folder.split('@')) > 1 and not folder.startswith('DELETED'):
            _folder_domain = folder.split('@')[-1]
            if not _folder_domain in list(
                    set(domains.keys() + domains.values())):
                imap_domains_not_domains.append(folder.split('@')[-1])

    imap_domains_not_domains = list(set(imap_domains_not_domains))

    log.debug(_("Domains in IMAP not in LDAP: %r") %
              (imap_domains_not_domains),
              level=8)

    if len(imap_domains_not_domains) > 0:
        for domain in imap_domains_not_domains:
            folders = []

            folders.extend(imap.lm('shared/%%@%s' % (domain)))
            folders.extend(imap.lm('user/%%@%s' % (domain)))

            for folder in folders:
                r_folder = folder
                if not folder.startswith('shared/'):
                    r_folder = '/'.join(folder.split('/')[1:])

                if conf.delete:
                    if conf.dry_run:
                        if not folder.startswith('shared/'):
                            log.warning(
                                _("No recipients for '%s' (would have deleted the mailbox if not for --dry-run)!"
                                  ) % (r_folder))
                        else:
                            continue
                    else:
                        if not folder.startswith('shared/'):
                            log.info(
                                _("Deleting mailbox '%s' because it has no recipients"
                                  ) % (folder))
                            try:
                                imap.dm(folder)
                            except Exception, errmsg:
                                log.error(
                                    _("An error occurred removing mailbox %r: %r"
                                      ) % (folder, errmsg))
                        else:
                            log.info(
                                _("Not automatically deleting shared folder '%s'"
                                  ) % (folder))
                else:
                    log.warning(
                        _("No recipients for '%s' (use --delete to delete)!") %
                        (r_folder))
    backend = conf.get(domain, 'imap_backend')
    if backend == None:
        backend = conf.get('kolab', 'imap_backend')

    admin_login = conf.get(backend, 'admin_login')
    admin_password = conf.get(backend, 'admin_password')

    imap.login_plain(admin_login, admin_password, user)

    if not imap.has_folder(folder_pattern):
        print >> sys.stderr, \
                _("Cannot subscribe user to folder %r:") % (folder_pattern), \
                _("No such folder")
        sys.exit(1)

    _folders = imap.lm(folder_pattern)
    _subscribed_folders = imap.lsub()
    unsubscribed_folders = []

    for _folder in _folders:
        if _folder in _subscribed_folders:
            imap.unsubscribe(_folder)
            unsubscribed_folders.append(_folder)

    if len(unsubscribed_folders) > 0:
        print _("Successfully unsubscribed user %s from the following folders:") % (
                user
            )

        print "\n".join(unsubscribed_folders)
    else:
예제 #42
0
    return """Configure quota for a folder."""

def execute(*args, **kw):
    try:
        folder = conf.cli_args.pop(0)
        try:
            quota = conf.cli_args.pop(0)
        except IndexError, errmsg:
            quota = utils.ask_question(_("New quota"))

    except IndexError, errmsg:
        folder = utils.ask_question(_("Folder name"))
        quota = utils.ask_question(_("New quota"))

    if len(folder.split('@')) > 1:
        domain = folder.split('@')[1]
    else:
        domain = conf.get('kolab', 'primary_domain')

    imap = IMAP()
    imap.connect(domain=domain)

    if not imap.has_folder(folder):
        print >> sys.stderr, _("No such folder %r") % (folder)
        sys.exit(1)

    for _folder in imap.lm(folder):
        imap.set_quota(_folder, quota)
        print >> sys.stdout, "Quota for folder '%s' set to %d" % (_folder, quota)

    backend = conf.get(domain, 'imap_backend')
    if backend == None:
        backend = conf.get('kolab', 'imap_backend')

    admin_login = conf.get(backend, 'admin_login')
    admin_password = conf.get(backend, 'admin_password')

    imap.login_plain(admin_login, admin_password, user)

    if not imap.has_folder(folder_pattern):
        print >> sys.stderr, \
                _("Cannot subscribe user to folder %r:") % (folder_pattern), \
                _("No such folder")
        sys.exit(1)

    _folders = imap.lm(folder_pattern)
    _subscribed_folders = imap.lsub()
    unsubscribed_folders = []

    for _folder in _folders:
        if _folder in _subscribed_folders:
            imap.unsubscribe(_folder)
            unsubscribed_folders.append(_folder)

    if len(unsubscribed_folders) > 0:
        print _("Successfully unsubscribed user %s from the following folders:"
                ) % (user)

        print "\n".join(unsubscribed_folders)
    else:
        print >> sys.stderr, _(