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.
This commit is contained in:
holger krekel
2026-08-11 20:11:41 +02:00
parent cc229372e4
commit 6beced4f51

View File

@@ -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: