Should be used for access of mailbox acls instead of attribute"""
# translate the mailbox to internal stored format
- internal_mailbox = mailbox.replace("INBOX/", "user/" + original_user + "/")
+ internal_mailbox = mailbox.replace("INBOX", "user/" + original_user)
internal_mailbox = internal_mailbox.replace(".", "^")
internal_mailbox = internal_mailbox.replace("/", ".")
logging.debug("Get acls for mailbox %s translated as %s", mailbox, internal_mailbox)
except KeyError:
# no rights for the mailbox were found and warn if acl file loaded
if len(self._file_acls) > 0:
- logging.warning("Could not find the acls for mailbox %s %s", mailbox, self._file_acls.keys())
+ logging.warning("Could not find the acls for mailbox %s", mailbox)
mb_acls = {}
return mb_acls
# retrieve mailbox list if a mailbox list file is specified
if args.mboxlistfile != "":
- storage.load_mailbox_list(args.mboxlistfile, args.ouser)
+ storage.load_mailbox_list(args.mboxlistfile)
# delete olf IMAP folders if no append requested
if not args.append:
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
self.dummy_filename = "test_acls.dump"
self.dummy_file = open(self.dummy_filename, "w")
self.dummy_file.write("user.00schneider\t0 default 00schneider\tlrswipkxtecda\t\n"
+ "user.mit^punkt\t0 default mit.punkt\tlrswipkxtecda\tinternaldate_test\tlr\t\n"
"user.mit^punkt.Gesendete Objekte\t0 default mit.punkt\tlrswipktecda\t\n"
"user.00schneider.Gesendete Objekte\t0 default 00schneider\tlrswipkxtecda\t\n"
"user.00schneider.ibx_sub\t0 default 00schneider\tlrswpkxtecda\t\n"
os.unlink(self.dummy_filename)
def test_mboxlist_parsed_line1(self):
-
"""Test whether a line was parsed correctly."""
+
self.file_iter.load_mailbox_list(self.dummy_filename)
self.assertEqual(len(self.file_iter.get_mailbox_acls("INBOX/Gesendete Objekte", "00schneider")), 1)
self.assertIn("00schneider", self.file_iter.get_mailbox_acls("INBOX/Gesendete Objekte", "00schneider"))
self.assertEqual(self.file_iter.get_mailbox_acls("INBOX/Gesendete Objekte", "00schneider")["00schneider"], "lrswipkxtecda", "Wrong acls were parsed for a user.")
def test_mboxlist_parsed_line2(self):
-
"""Test whether a line was parsed correctly."""
+
self.file_iter.load_mailbox_list(self.dummy_filename)
+ self.assertEqual(len(self.file_iter.get_mailbox_acls("INBOX", "mit.punkt")), 2)
self.assertEqual(len(self.file_iter.get_mailbox_acls("INBOX/Gesendete Objekte", "mit.punkt")), 1)
self.assertIn("mit.punkt", self.file_iter.get_mailbox_acls("INBOX/Gesendete Objekte", "mit.punkt"))
self.assertEqual(self.file_iter.get_mailbox_acls("INBOX/Gesendete Objekte", "mit.punkt")["mit.punkt"], "lrswipktecda", "Wrong acls were parsed for a user.")