"""Closes the connection and the user session."""
return
- def _message_read(self, filename):
+ @classmethod
+ def _message_read(cls, filename):
"""Retrieves a message from the message file."""
try:
with open(filename, "r") as msgfile:
raise
return message
- def load_mailbox_list(self, mboxlistfile = ""):
+ @classmethod
+ def load_mailbox_list(cls, mboxlistfile = ""):
+ """Load the list of mailboxes and acl rights for each from file."""
mboxdb = {}
if mboxlistfile != "":
try:
for line in acl_file:
acls = {}
linedata = MBOXFILE_LINE.match(line).groups()
- #!!! test this condition
if len(linedata) == 0:
- logging.warning("Illegal line in mailbox list dump: %s" % line)
+ logging.warning("Illegal line in mailbox list dump: %s", line)
continue
key = linedata[0]
aclstr = linedata[1]
while(aclstr != ""):
acldata = ACL_STRING.match(aclstr).groups()
if len(acldata) == 0:
- logging.error("Illegal acl string in mailbox list dump: %s" % line)
+ logging.error("Illegal acl string in mailbox list dump: %s", line)
continue
aclstr = acldata[2]
- acls[acldata[0]]=acldata[1]
+ acls[acldata[0]] = acldata[1]
mboxdb[key] = acls
except IOError:
- logging.warning("Could not open mboxlist file %s" % mboxlistfile)
+ logging.warning("Could not open mboxlist file %s", mboxlistfile)
return mboxdb
def load_mails(self, filepath, mailpath):
"""Loads all e-mails from file hierarchy.
This recursive generator always returns a tuple of
the next found (e-mail, mailbox to store, internaldate)."""
- logging.debug("Entered directory %s -> %s" % (filepath, mailpath))
+ logging.debug("Entered directory %s -> %s", filepath, mailpath)
try:
filepath = os.path.abspath(filepath)
os.chdir(filepath)
except OSError:
- logging.warning("Can't open the directory %s" % filepath)
+ logging.warning("Can't open the directory %s", filepath)
return
# mark mailboxes that should be created
self.created_mailboxes.append(mailpath)
new_filepath = filepath + "/" + subpath
if (os.path.isfile(new_filepath)):
if os.path.getsize(new_filepath) == 0:
- logging.info("Skipping empty file %s" % subpath)
+ logging.info("Skipping empty file %s", subpath)
else:
if MAIL_FILENAME.match(subpath):
- logging.info("Injecting file %s" % subpath)
+ logging.info("Injecting file %s", subpath)
try:
message = self._message_read(new_filepath)
# suggest file modification date for internaldate
yield (message, mailpath, os.path.getmtime(new_filepath))
except IOError:
- logging.warning("Could not retrieve mail from the file %s" % new_filepath)
+ logging.warning("Could not retrieve mail from the file %s", new_filepath)
else:
if os.path.isdir(new_filepath):
# cyrus ^ vs . storage replacement
subpath = subpath.replace("^", ".")
new_mailpath = mailpath + "/" + subpath
- logging.debug("Inserting mails from directory %s into mailbox %s" % (new_filepath, new_mailpath))
+ logging.debug("Inserting mails from directory %s into mailbox %s", new_filepath, new_mailpath)
# load_mails($mboxdbref, $origuser, $targetuser)
rcrs_generator = self.load_mails(new_filepath, new_mailpath)
# you enter the generator in the for loop
for rcr in rcrs_generator:
yield rcr
- logging.debug("Done with directory %s and mailbox %s" % (new_filepath, new_mailpath))
+ logging.debug("Done with directory %s and mailbox %s", new_filepath, new_mailpath)
# mark mailboxes that need acl update
self.acl_mailboxes.append(mailpath)
return
\ No newline at end of file