Skip to content

Commit

Permalink
More changes for move option
Browse files Browse the repository at this point in the history
Existing device fixup
Mark message as processed in case move fails
  • Loading branch information
FlyingDiver committed Apr 29, 2018
1 parent cfcc9e9 commit 595f4e0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
29 changes: 15 additions & 14 deletions BetterEmail.indigoPlugin/Contents/Server Plugin/IMAPServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, device):
self.connectIMAP()
self.needsync = False
self.exitIDLE = False
self.idleThread = Thread(target=self.idleIMAP)
self.idleThread = Thread(target=self.idleIMAPThread)
self.idleThread.start()

def __str__(self):
Expand Down Expand Up @@ -145,8 +145,8 @@ def connectIMAP(self):
##########################################################################################
# run IDLE loop in separate thread. When this function exits, the IDLE thread terminates

def idleIMAP(self):
self.logger.debug(self.device.name + u": idleIMAP() called")
def idleIMAPThread(self):
self.logger.debug(self.device.name + u": idleIMAPThread() called")

def idleEvent(args):
self.logger.debug(self.device.name + u": IDLE Event Received")
Expand All @@ -170,7 +170,6 @@ def idleEvent(args):
def checkMsgs(self):

self.logger.debug(u"{}: Doing checkMsgs".format(self.device.name))
self.connection.select("INBOX")
typ, msg_ids = self.connection.search(None, 'ALL')
self.logger.debug(self.device.name + u": msg_ids = " + str(msg_ids))
if msg_ids == None:
Expand All @@ -187,8 +186,8 @@ def checkMsgs(self):
continue
except Exception, e:
self.logger.error(self.device.name + u': Error fetching FLAGS for Message # ' + messageNum + ": " + str(e))
pass

continue
try:
self.logger.debug(self.device.name + u": Fetching Message # " + messageNum)
typ, data = self.connection.fetch(messageNum, '(RFC822)')
Expand Down Expand Up @@ -296,17 +295,19 @@ def checkMsgs(self):
if self.imapProps['postProcess'] == 'delete':
self.logger.debug(u"{}: Deleting message # {}".format(self.device.name, messageNum))
t, resp = self.connection.store(messageNum, '+FLAGS', r'(\Deleted)')
elif self.imapProps['postProcess'] == 'move':
self.logger.debug(u"{}: Moving message # {}".format(self.device.name, messageNum))
result = self.connection.copy(messageNum, self.imapProps['moveFolder'])
if result[0] == 'OK':
t, resp = self.connection.store(messageNum, '+FLAGS', r'(\Deleted)')
else:
self.logger.debug(u"{}: Error moving message # {}: {}".format(self.device.name, messageNum, result))

else:
# Mark the message as successfully processed
t, resp = self.connection.store(messageNum, '+FLAGS', r'($IndigoProcessed)')

if self.imapProps['postProcess'] == 'move':
self.logger.debug(u"{}: Copying message # {} to {}".format(self.device.name, messageNum, self.imapProps['moveFolder']))
result = self.connection.copy(messageNum, self.imapProps['moveFolder'])
if result[0] == 'OK':
self.logger.debug(u"{}: Deleting message # {}".format(self.device.name, messageNum))
t, resp = self.connection.store(messageNum, '+FLAGS', r'(\Deleted)')
else:
self.logger.error(u"{}: Error moving message # {}: {}".format(self.device.name, messageNum, result))


self.connection.expunge()
self.logger.debug(u"{}: checkMsgs complete".format(self.device.name))
7 changes: 6 additions & 1 deletion BetterEmail.indigoPlugin/Contents/Server Plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from IMAPServer import IMAPServer
from POPServer import POPServer

kCurDevVersCount = 3 # current version of plugin devices
kCurDevVersCount = 4 # current version of plugin devices

################################################################################
class Plugin(indigo.PluginBase):
Expand Down Expand Up @@ -216,6 +216,11 @@ def deviceStartComm(self, device):
newProps["useIDLE"] = "True"
self.logger.debug(device.name + u": created useIDLE property")

postProcess = device.pluginProps.get('postProcess', "unknown")
if postProcess == "unknown":
newProps["postProcess"] = "delete"
self.logger.debug(device.name + u": created postProcess property")

pollingFrequency = device.pluginProps.get('pollingFrequency', "unknown")
if pollingFrequency == "unknown":
newProps["pollingFrequency"] = device.pluginProps.get('pollingFrequency', 15)
Expand Down

0 comments on commit 595f4e0

Please sign in to comment.