diff --git a/README.md b/README.md index 3de9c1a..097b6f7 100644 --- a/README.md +++ b/README.md @@ -11,16 +11,16 @@ This reads codes from email; it does not generate them (that is `pyotp`'s job). `requirements.txt`: ``` -aiomail @ git+ssh://git@git.rethinkstudios.io/rethink-public/aiomail.git@v0.1.0 +aiomail @ git+ssh://git@git.rethinkstudios.io/rethink-public/aiomail.git@v0.1.1 # OAuth token providers (Microsoft / Google) need the extra: -aiomail[oauth] @ git+ssh://git@git.rethinkstudios.io/rethink-public/aiomail.git@v0.1.0 +aiomail[oauth] @ git+ssh://git@git.rethinkstudios.io/rethink-public/aiomail.git@v0.1.1 ``` Direct: ```bash -pip install "aiomail @ git+ssh://git@git.rethinkstudios.io/rethink-public/aiomail.git@v0.1.0" -pip install "aiomail[oauth] @ git+ssh://git@git.rethinkstudios.io/rethink-public/aiomail.git@v0.1.0" +pip install "aiomail @ git+ssh://git@git.rethinkstudios.io/rethink-public/aiomail.git@v0.1.1" +pip install "aiomail[oauth] @ git+ssh://git@git.rethinkstudios.io/rethink-public/aiomail.git@v0.1.1" ``` Requires `aioimaplib` and `beautifulsoup4` (pulled transitively). The `oauth` diff --git a/src/aiomail/client.py b/src/aiomail/client.py index 376b2c6..995347b 100644 --- a/src/aiomail/client.py +++ b/src/aiomail/client.py @@ -67,7 +67,12 @@ class IMAPClient: return True except Exception as exc: log.warning("connect attempt %d/%d failed: %s", attempt + 1, self.max_retries, exc) - self._mail = None + if self._mail is not None: + try: + await self._mail.logout() + except Exception as teardown: + log.debug("logout error ignored during failed connect: %s", teardown) + self._mail = None await asyncio.sleep(2 * (attempt + 1)) return False diff --git a/src/aiomail/oauth.py b/src/aiomail/oauth.py index 3b7c18b..c10c9de 100644 --- a/src/aiomail/oauth.py +++ b/src/aiomail/oauth.py @@ -6,6 +6,7 @@ without aiohttp raises a clear error only when a provider is instantiated. credentials (client_id, refresh_token) are always supplied by the caller. """ +import asyncio import logging import time from typing import Optional, Sequence @@ -85,8 +86,6 @@ class _RefreshTokenProvider: except Exception as exc: log.warning("token request to %s failed: %s", endpoint, exc) if attempt < self.max_retries - 1: - import asyncio - await asyncio.sleep(2 ** attempt) self._failures += 1