示例#1
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')
示例#2
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', '')