Skip to content

Commit

Permalink
Gracefully handle start_tls exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
icgood committed May 19, 2021
1 parent 5f1bdf4 commit 511321c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions pymap/imap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from base64 import b64encode, b64decode
from collections.abc import Awaitable, Iterable
from contextlib import closing, AsyncExitStack
from ssl import SSLError
from typing import TypeVar, Union, Optional
from uuid import uuid4

Expand Down Expand Up @@ -283,7 +284,7 @@ async def start_tls(self) -> None:
new_writer = StreamWriter(new_transport, new_protocol,
self.reader, loop)
self._reset_streams(self.reader, new_writer)
self._print('%s <->| %s', b'<TLS handshake>')
self._print('%s <->| %s', '<TLS handshake>')

async def send_error_disconnect(self) -> None:
_, exc, _ = sys.exc_info()
Expand Down Expand Up @@ -414,7 +415,13 @@ async def run(self, state: ConnectionState) -> None:
break
if isinstance(cmd, StartTLSCommand) \
and isinstance(response, ResponseOk):
await self.start_tls()
try:
await self.start_tls()
except ConnectionError:
break
except SSLError as exc:
self._print('%s <->| %s', f'<TLS: {exc.reason}>')
return
finally:
await state.do_cleanup()
current_command.reset(prev_cmd)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
license = f.read()

setup(name='pymap',
version='0.24.6',
version='0.24.7',
author='Ian Good',
author_email='ian@icgood.net',
description='Lightweight, asynchronous IMAP serving in Python.',
Expand Down

0 comments on commit 511321c

Please sign in to comment.