Skip to content

Commit

Permalink
Avoid deadlock in IMAP IDLE, fix buglet in thread name logic
Browse files Browse the repository at this point in the history
  • Loading branch information
BjarniRunar committed Jul 28, 2019
1 parent 6e61761 commit 94b4b58
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion mailpile/mail_source/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,14 @@ def sync_mail(self):
batch = min(self._loop_count * 20, self.RESCAN_BATCH_SIZE)
errors = rescanned = 0
all_completed = True
ostate = self._state

if not self._check_interrupt(clear=False):
self._state = 'Waiting... (disco)'
discovered = self.discover_mailboxes()
else:
discovered = 0

ostate = self._state
plan = self._sorted_mailboxes()
self.event.data['plan'] = [[m._key, _('Pending'), m.name] for m in plan]
event_plan = dict((mp[0], mp) for mp in self.event.data['plan'])
Expand Down
16 changes: 9 additions & 7 deletions mailpile/mail_source/imap.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ def get_line():
raise self._conn.abort('socket error: %s' % val)

def quit(self):
self._can_idle = False
with self._lock:
try:
if self._conn and self._conn.file:
Expand Down Expand Up @@ -907,13 +908,6 @@ def logged_in_cb(conn, ev, capabilities):
if self.conn is not None:
raise IOError('Woah, we lost a race.')
self.capabilities = capabilities
if 'IDLE' in capabilities:
self.conn = SharedImapConn(
self.session, conn,
idle_mailbox='INBOX',
idle_callback=self._idle_callback)
else:
self.conn = SharedImapConn(self.session, conn)

if 'NAMESPACE' in capabilities:
ok, data = self.timed_imap(conn.namespace)
Expand All @@ -925,6 +919,14 @@ def logged_in_cb(conn, ev, capabilities):
'shared': shr if (shr != 'NIL') else []
}

if 'IDLE' in capabilities:
self.conn = SharedImapConn(
self.session, conn,
idle_mailbox='INBOX',
idle_callback=self._idle_callback)
else:
self.conn = SharedImapConn(self.session, conn)

if self.event:
self._log_status(_('Connected to IMAP server %s'
) % my_config.host)
Expand Down

0 comments on commit 94b4b58

Please sign in to comment.