add timeout for reading mails
This commit is contained in:
@@ -220,12 +220,17 @@ class ProxyIMAPClient(IMAPClient):
|
||||
def _create_IMAP4(self):
|
||||
"""Remplace la méthode d'IMAPClient pour injecter ProxyIMAP4_TLS."""
|
||||
if self.ssl:
|
||||
# self._timeout peut être un float (secondes) ou un objet avec
|
||||
# un attribut 'connect' (ex : urllib3 Timeout). On gère les deux.
|
||||
_timeout = self._timeout
|
||||
if _timeout is not None and not isinstance(_timeout, (int, float)):
|
||||
_timeout = getattr(_timeout, "connect", None)
|
||||
return ProxyIMAP4_TLS(
|
||||
host=self.host,
|
||||
port=self.port,
|
||||
ssl_context=self.ssl_context,
|
||||
proxy=self._proxy,
|
||||
timeout=getattr(self._timeout, "connect", None),
|
||||
timeout=_timeout,
|
||||
)
|
||||
# Connexion non-SSL à travers le proxy (rare, mais supporté)
|
||||
# On monkey-patch juste la connexion TCP
|
||||
|
||||
@@ -31,6 +31,10 @@ EMAIL_ADDRESS_REGEX = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b'
|
||||
# 日期格式
|
||||
DATE_FORMAT = "%d-%b-%Y"
|
||||
|
||||
# Timeouts GMX (en secondes)
|
||||
IMAP_SOCKET_TIMEOUT = 300 # timeout socket pour chaque opération IMAP
|
||||
FUTURE_TIMEOUT = 600 # durée max allouée à la lecture d'une boîte mail
|
||||
|
||||
# GMX域名列表(用于判断是否需要使用代理)
|
||||
GMX_DOMAINS = (
|
||||
"gmx.com", "gmx.net", "gmx.de", "gmx.at",
|
||||
@@ -134,6 +138,7 @@ class MailReader:
|
||||
proxy=self.proxy,
|
||||
use_uid=True,
|
||||
ssl=True,
|
||||
timeout=IMAP_SOCKET_TIMEOUT,
|
||||
)
|
||||
return self._read_emails_internal(imap, mails_messages)
|
||||
except Exception as exc:
|
||||
@@ -394,10 +399,6 @@ def need_to_check_email(mail: str, successful_items) -> bool:
|
||||
"""判断是否需要检查邮件"""
|
||||
print("successful_items size is " + str(len(successful_items)))
|
||||
|
||||
# 特殊处理
|
||||
if mail == "saigecong1990@pissmail.com":
|
||||
return True
|
||||
|
||||
# 过滤已验证的项目
|
||||
filtered_items = [item for item in successful_items if item.email == mail]
|
||||
|
||||
@@ -439,9 +440,11 @@ def find_links_to_validate_from_mail_list(
|
||||
# 等待所有任务完成
|
||||
for future in futures:
|
||||
try:
|
||||
future.result()
|
||||
future.result(timeout=FUTURE_TIMEOUT)
|
||||
except TimeoutError:
|
||||
print("⏱️ Timeout ({} s) dépassé pour une boîte mail — lecture ignorée.".format(FUTURE_TIMEOUT))
|
||||
except Exception as e:
|
||||
print("Error processing mail: {}".format(e))
|
||||
print("Error processing mail: {},login: {}, password: {}".format(e,mail.mail, mail.password))
|
||||
|
||||
# ── Résumé des comptes GMX en échec ──────────────────────
|
||||
if failed_gmx:
|
||||
@@ -484,7 +487,10 @@ def find_links_to_validate_from_mail_list(
|
||||
if __name__ == '__main__':
|
||||
# 读取联系人列表
|
||||
contact_to_book_list = read_contacts(
|
||||
file_name="~/Desktop/contact_list_2026-03-05.xlsx")
|
||||
file_name="~/Desktop/contact_list_inbox_lv_100.xlsx")
|
||||
# file_name="~/Desktop/contact_list_2026-04-02.xlsx")
|
||||
# file_name="~/Desktop/contact_list_2026-04-01.xlsx")
|
||||
# file_name="~/Desktop/contact_list_2026-03-28.xlsx")
|
||||
# file_name="~/Desktop/contact_list_2025-11-28.xlsx")
|
||||
# file_name="~/Desktop/contact_list_2025-11-06.xlsx")
|
||||
|
||||
@@ -512,7 +518,7 @@ if __name__ == '__main__':
|
||||
_to_add = False
|
||||
if _to_add:
|
||||
filter_mail.append(mail_pojo)
|
||||
# filter_mail = [MailAddress("birgitnaya@gmx.net", "XEeUF3Y1yaO")]
|
||||
# filter_mail = [MailAddress("munozshawn1992@aol.com", "leivqvcwyacrgbzp")]
|
||||
|
||||
# ── Mode de lecture : GMX_ONLY=true → uniquement les comptes GMX ──
|
||||
gmx_only = os.environ.get("GMX_ONLY", "false").strip().lower() == "true"
|
||||
|
||||
Reference in New Issue
Block a user