Skip to content

Commit

Permalink
Fix a bug where folder creation failed since upgrading to the newest …
Browse files Browse the repository at this point in the history
…imapclient release.
  • Loading branch information
Thomi Richards committed Jul 26, 2015
1 parent 48ac2d2 commit 77fd82e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions gmailfilter/actions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

import imapclient
import logging

"""Classes that manipulate mails."""
Expand Down Expand Up @@ -32,15 +33,14 @@ def __init__(self, target_folder):
self._target_folder = target_folder

def process(self, conn, message):
# TODO: optimise this by trying the copy, and if we get 'NO' with
# 'TRYCREATE' then, and only then try and create the folder. Removes the
# overhead of the existance check for every message,
if not conn.folder_exists(self._target_folder):
try:
conn.copy(message.uid(), self._target_folder)
except imapclient.IMAPClient.Error as e:
status = conn.create_folder(self._target_folder)
assert status.lower() == b"success", "Unable to create folder %s" % self._target_folder
conn.copy(message.uid(), self._target_folder)

assert status.lower() == "success", "Unable to create folder %s" % self._target_folder

conn.copy(message.uid(), self._target_folder)
# TODO: Maybe provide logging facilities in parent 'Action' class?
conn.delete_messages(message.uid())
logging.info("Moving message %r to %s" % (message, self._target_folder))
Expand Down

0 comments on commit 77fd82e

Please sign in to comment.