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(b'(?P<user>.*) (?P<acls>.*)')
+ACLS_RESP = re.compile(b'(?P<user>\S+) (?P<acls>\S+)')
+
+#imaplib.Debug = 4
class MailIterator:
"""This class communicates with the e-mail server."""
inbox_acls = ACLS_RESP.findall(inbox_acls[0][6:])
logging.debug("Retrieved acls from INBOX are %s", inbox_acls)
for acl_ref in inbox_acls:
- if acl_ref[0] != user:
+ if acl_ref[0].decode('iso-8859-1') != user:
try:
self.mail_con.deleteacl("INBOX", acl_ref[0])
logging.debug("Reset acls on INBOX for user %s", acl_ref[0].decode('iso-8859-1'))
pattern += mailbox[1]
if re.compile(pattern).match(mailbox[2]):
result, data = self.mail_con.delete(mailbox[2])
- if result == "OK":
- logging.debug("Deleted mailbox %s", mailbox[2])
- else:
+ logging.debug("Deleted mailbox %s", mailbox[2])
+ if result != "OK":
logging.warning("Could not delete mailbox %s: %s", mailbox[2], data[0])
return
if mailbox != "INBOX":
result, data = self.mail_con.create(mailbox)
- if result == "OK":
- logging.debug("Creating mailbox %s", mailbox)
- else:
- logging.warning("Could not create mailbox %s: %s", mailbox, data[0])
+ logging.debug("Creating mailbox %s", mailbox)
+ if result != "OK":
+ logging.warning("Could not create mailbox %s: %s", mailbox, data[0].decode('iso-8859-1'))
return
"""Inject a message into a mailbox."""
result, data = self.mail_con.append(mailbox, "\\Seen", internal_date, message.encode())
- if result == "OK":
- logging.debug("Appending message to mailbox %s", mailbox)
- else:
- logging.warning("Could not append the e-mail %s: %s", message, data[0])
+ logging.debug("Appending message to mailbox %s", mailbox)
+ if result != "OK":
+ logging.warning("Could not append an e-mail to the mailbox %s: %s.", mailbox, data[0].decode('iso-8859-1'))
+ #logging.debug("Email content:\n%s", message)
return
\ No newline at end of file