From 9ce1038d0a8748ec373234778cc85b3e03267853 Mon Sep 17 00:00:00 2001 From: Plamen Dimitrov Date: Fri, 6 Jul 2012 09:31:33 +0200 Subject: [PATCH] INBOX acls reset parsing with regex --- mail_iterator.py | 21 +++++++++++---------- 1 files changed, 11 insertions(+), 10 deletions(-) diff --git a/mail_iterator.py b/mail_iterator.py index 1c4550c..3c260c3 100644 --- a/mail_iterator.py +++ b/mail_iterator.py @@ -9,7 +9,7 @@ import re MAILBOX_RESP = re.compile(r'\((?P.*?)\) "(?P.*)" (?P.*)') UIDVAL_RESP = re.compile(r'(?P.*) \(UIDVALIDITY (?P.*)\)') -ACLS_RESP = re.compile(r'(?P.*) \(UIDVALIDITY (?P.*)\)') +ACLS_RESP = re.compile(r'(?P.*) (?P.*)') class MailIterator: """This class communicates with the e-mail server.""" @@ -24,7 +24,7 @@ class MailIterator: def __init__(self, server, username, password): """Creates a connection and a user session.""" - + # connect to server try: self.mail_con = imaplib.IMAP4_SSL(server) @@ -40,7 +40,7 @@ class MailIterator: except: self.logged_in = False raise UserWarning("Could not log in as user " + username) - + # list mailboxes try: _result, mailboxes = self.mail_con.list() @@ -51,7 +51,7 @@ class MailIterator: mailbox = MAILBOX_RESP.match(mailbox.decode('iso-8859-1')).groups() self.mailboxes.append(mailbox) self.mailboxes = sorted(self.mailboxes, key=lambda box: box[2], reverse=True) - + return def __del__(self): @@ -66,14 +66,15 @@ class MailIterator: _result, inbox_acls = self.mail_con.getacl("INBOX") except: print("Could not get the acls of INBOX.") - inbox_acls = inbox_acls[0].split(' ')[1:] - for acl_user in inbox_acls: - if acl_user != user: + inbox_acls = ACLS_RESP.findall(inbox_acls[0][6:]) + #print(inbox_acls) + for acl_ref in inbox_acls: + if acl_ref[0] != user: try: - self.mail_con.setacl("INBOX", acl_user, "") - print("Reset acls on INBOX for user %s" % acl_user) + self.mail_con.setacl("INBOX", acl_ref[0], "") + print("Reset acls on INBOX for user %s" % acl_ref[0]) except: - print("Could not reset acls on INBOX for user %s" % acl_user) + print("Could not reset acls on INBOX for user %s" % acl_ref[0]) return def add_acls(self, mailbox, mailbox_list, original_user, target_user): -- 1.7.1