From 6beced4f51985306c00fbd7f8716137e66243d38 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Tue, 11 Aug 2026 20:11:41 +0200 Subject: [PATCH] test: avoid another source of random failures with direct_imap failing to connect on first try also core src/imap.rs retries connecting (2s with backoff) but direct_imap is only used in (CI) tests and we can just keep trying every second until pytest timeout hits. --- python/src/deltachat/direct_imap.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/python/src/deltachat/direct_imap.py b/python/src/deltachat/direct_imap.py index 5f6323399..b180edde0 100644 --- a/python/src/deltachat/direct_imap.py +++ b/python/src/deltachat/direct_imap.py @@ -7,6 +7,7 @@ import imaplib import io import pathlib import ssl +import time from contextlib import contextmanager from typing import List, TYPE_CHECKING @@ -42,10 +43,14 @@ class DirectImap: host = user.rsplit("@")[-1] pw = self.account.get_config("mail_pw") - self.conn = MailBox(host, port, ssl_context=ssl.create_default_context()) - self.conn.login(user, pw) - - self.select_folder("INBOX") + while True: + try: + self.conn = MailBox(host, port, ssl_context=ssl.create_default_context()) + self.conn.login(user, pw) + self.select_folder("INBOX") + return + except (OSError, ssl.SSLError, imaplib.IMAP4.error): + time.sleep(1) def shutdown(self): try: