MAILBOX_RESP = re.compile(r'\((?P<flags>.*?)\) "(?P<delimiter>.*)" (?P<name>.*)')
UIDVAL_RESP = re.compile(r'(?P<name>.*) \(UIDVALIDITY (?P<uidval>.*)\)')
-ACLS_RESP = re.compile(r'(?P<name>.*) \(UIDVALIDITY (?P<uidval>.*)\)')
+ACLS_RESP = re.compile(r'(?P<user>.*) (?P<acls>.*)')
class MailIterator:
"""This class communicates with the e-mail server."""
def __init__(self, server, username, password):
"""Creates a connection and a user session."""
-
+
# connect to server
try:
self.mail_con = imaplib.IMAP4_SSL(server)
except:
self.logged_in = False
raise UserWarning("Could not log in as user " + username)
-
+
# list mailboxes
try:
_result, mailboxes = self.mail_con.list()
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):
_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):