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', '')
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
def folder_utf7(self, folder): from pykolab import imap_utf7 return imap_utf7.encode(folder)
def calendar(user): return imap_utf7.encode( "user/{username}/[email protected]".format(username=user))
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)