X-Git-Url: http://developer.intra2net.com/git/?a=blobdiff_plain;f=src%2Ffile_iterator.py;h=506b4d2c8bb8b9c38153a70e877b3529c0750111;hb=796663490012d53329d5f062385a26897e6d5291;hp=edf6be78e64d0a207dedf2b754f4cd33ff1bbc45;hpb=4208892f8826b7b6be3a38d82224811abd679e1e;p=imap-restore-mail diff --git a/src/file_iterator.py b/src/file_iterator.py index edf6be7..506b4d2 100644 --- a/src/file_iterator.py +++ b/src/file_iterator.py @@ -32,14 +32,14 @@ class FileIterator: # mailboxes to update during file traversal acl_mailboxes = None # acls retrieved from a file - file_acls = None + _file_acls = None def __init__(self): """Creates a connection and a user session.""" self.created_mailboxes = [] self.acl_mailboxes = [] - self.file_acls = {} + self._file_acls = {} @classmethod def _message_read(cls, filename): @@ -54,7 +54,28 @@ class FileIterator: return message - def load_mailbox_list(self, mboxlistfile, original_user): + def get_mailbox_acls(self, mailbox, original_user): + """Get the acls loaded from a file for a given mailbox. + 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 = internal_mailbox.replace(".", "^") + internal_mailbox = internal_mailbox.replace("/", ".") + logging.debug("Get acls for mailbox %s translated as %s", mailbox, internal_mailbox) + + # retrieve from internal dicitonary attribute of file acls + try: + mb_acls = self._file_acls[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()) + mb_acls = {} + + return mb_acls + + def load_mailbox_list(self, mboxlistfile): """Load the list of mailboxes and acl rights for each from file.""" try: @@ -71,10 +92,8 @@ class FileIterator: aclstr = linedata[1] # changes acls key encoding to internal cyrus format and makes it absolute (as folder). - key = linedata[0].replace("INBOX/", "user/" + original_user + "/") - key = key.replace(".", "^") - key = key.replace("/", ".") - + key = linedata[0] + # loop through acl rights string and build dictionary of users and rights while(aclstr != ""): try: @@ -83,10 +102,10 @@ class FileIterator: logging.warning("Illegal acl string in mailbox list dump: %s", line) aclstr = "" continue - aclstr = acldata[2] acls[acldata[0]] = acldata[1] + aclstr = acldata[2] - self.file_acls[key] = acls + self._file_acls[key] = acls except IOError: logging.warning("Could not open mboxlist file %s", mboxlistfile)