Esempio n. 1
0
        )

def description():
    return """Create a mailbox or sub-folder of an existing mailbox."""

def execute(*args, **kw):
    try:
        mailbox = conf.cli_args.pop(0)
    except IndexError, errmsg:
        log.error(_("Invalid argument"))
        sys.exit(1)

    if not conf.metadata == None:
        if len(conf.metadata.split('=')) == 2:
            annotation = conf.metadata.split('=')[0]
            annotation_value = conf.metadata.split('=')[1]
        else:
            log.error(_("Invalid argument for metadata"))
            sys.exit(1)

    imap = IMAP()
    imap.connect()

    admin_login = conf.get('cyrus-imap', 'admin_login')

    imap.cm(mailbox)

    if not conf.metadata == None:
        imap.set_metadata(mailbox, conf.metadata.split('=')[0], conf.metadata.split('=')[1])

Esempio n. 2
0

def description():
    return """Create a mailbox or sub-folder of an existing mailbox."""


def execute(*args, **kw):
    try:
        mailbox = conf.cli_args.pop(0)
    except IndexError, errmsg:
        log.error(_("Invalid argument"))
        sys.exit(1)

    if not conf.metadata == None:
        if len(conf.metadata.split('=')) == 2:
            annotation = conf.metadata.split('=')[0]
            annotation_value = conf.metadata.split('=')[1]
        else:
            log.error(_("Invalid argument for metadata"))
            sys.exit(1)

    imap = IMAP()
    imap.connect()

    imap.create_folder(mailbox, partition=conf.partition)

    if not conf.metadata == None:
        imap.set_metadata(mailbox,
                          conf.metadata.split('=')[0],
                          conf.metadata.split('=')[1])
    if len(folder.split('@')) > 1:
        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(folder)
        for folder in folders:
            imap.set_metadata(folder, metadata_path, metadata_value)
        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)