print failed gmx mails
This commit is contained in:
@@ -81,10 +81,12 @@ def find_from_mail(param) -> str:
|
|||||||
class MailReader:
|
class MailReader:
|
||||||
"""邮件读取器类"""
|
"""邮件读取器类"""
|
||||||
|
|
||||||
def __init__(self, login: str, password: str, proxy: Optional[ProxyConfig] = None):
|
def __init__(self, login: str, password: str, proxy: Optional[ProxyConfig] = None,
|
||||||
|
failed_gmx_list: Optional[List[str]] = None):
|
||||||
self.login = login
|
self.login = login
|
||||||
self.password = password
|
self.password = password
|
||||||
self.proxy = proxy
|
self.proxy = proxy
|
||||||
|
self.failed_gmx_list = failed_gmx_list if failed_gmx_list is not None else []
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def show_folders(imap) -> List[str]:
|
def show_folders(imap) -> List[str]:
|
||||||
@@ -117,7 +119,7 @@ class MailReader:
|
|||||||
def _read_emails_with_proxy_retry(
|
def _read_emails_with_proxy_retry(
|
||||||
self,
|
self,
|
||||||
mails_messages: List[MailPojo],
|
mails_messages: List[MailPojo],
|
||||||
max_retries: int = 3,
|
max_retries: int = 8,
|
||||||
) -> List[MailPojo]:
|
) -> List[MailPojo]:
|
||||||
"""通过 ProxyIMAPClient 读取 GMX 邮件,失败时最多重试 max_retries 次。"""
|
"""通过 ProxyIMAPClient 读取 GMX 邮件,失败时最多重试 max_retries 次。"""
|
||||||
imap_server = get_imap_server(self.login)
|
imap_server = get_imap_server(self.login)
|
||||||
@@ -141,6 +143,7 @@ class MailReader:
|
|||||||
|
|
||||||
print("[GMX-Proxy] Toutes les tentatives ont échoué pour {} : {}".format(
|
print("[GMX-Proxy] Toutes les tentatives ont échoué pour {} : {}".format(
|
||||||
self.login, last_error))
|
self.login, last_error))
|
||||||
|
self.failed_gmx_list.append(self.login)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def _read_emails_internal(self, imap, mails_messages: List[MailPojo]) -> List[MailPojo]:
|
def _read_emails_internal(self, imap, mails_messages: List[MailPojo]) -> List[MailPojo]:
|
||||||
@@ -409,16 +412,17 @@ def find_links_to_validate_from_mail_list(
|
|||||||
mail_list: List[MailAddress],
|
mail_list: List[MailAddress],
|
||||||
logger,
|
logger,
|
||||||
proxy: Optional[ProxyConfig] = None,
|
proxy: Optional[ProxyConfig] = None,
|
||||||
) -> None:
|
) -> List[str]:
|
||||||
"""从邮件列表中查找需要验证的链接"""
|
"""从邮件列表中查找需要验证的链接,返回读取失败的GMX账户列表"""
|
||||||
if not mail_list:
|
if not mail_list:
|
||||||
return
|
return []
|
||||||
|
|
||||||
# 检查时间前开始检查邮件
|
# 检查时间前开始检查邮件
|
||||||
contact_to_book_list = MONGO_STORE_MANAGER.get_all_contact_to_book_list()
|
contact_to_book_list = MONGO_STORE_MANAGER.get_all_contact_to_book_list()
|
||||||
successful_items = MONGO_STORE_MANAGER.get_all_successful_items_for_day()
|
successful_items = MONGO_STORE_MANAGER.get_all_successful_items_for_day()
|
||||||
|
|
||||||
mails_messages = []
|
mails_messages = []
|
||||||
|
failed_gmx: List[str] = []
|
||||||
|
|
||||||
# 使用线程池处理邮件
|
# 使用线程池处理邮件
|
||||||
with ThreadPoolExecutor(max_workers=100) as executor:
|
with ThreadPoolExecutor(max_workers=100) as executor:
|
||||||
@@ -427,7 +431,8 @@ def find_links_to_validate_from_mail_list(
|
|||||||
for mail in mail_list:
|
for mail in mail_list:
|
||||||
# 检查是否需要读取邮件
|
# 检查是否需要读取邮件
|
||||||
if need_to_check_email(mail.mail, successful_items):
|
if need_to_check_email(mail.mail, successful_items):
|
||||||
mail_reader = MailReader(mail.mail, mail.password, proxy=proxy)
|
mail_reader = MailReader(mail.mail, mail.password, proxy=proxy,
|
||||||
|
failed_gmx_list=failed_gmx)
|
||||||
future = executor.submit(mail_reader.read_emails, mails_messages)
|
future = executor.submit(mail_reader.read_emails, mails_messages)
|
||||||
futures.append(future)
|
futures.append(future)
|
||||||
|
|
||||||
@@ -438,6 +443,14 @@ def find_links_to_validate_from_mail_list(
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Error processing mail: {}".format(e))
|
print("Error processing mail: {}".format(e))
|
||||||
|
|
||||||
|
# ── Résumé des comptes GMX en échec ──────────────────────
|
||||||
|
if failed_gmx:
|
||||||
|
print("\n[GMX-Proxy] ⚠️ {} compte(s) GMX non lus :".format(len(failed_gmx)))
|
||||||
|
for addr in failed_gmx:
|
||||||
|
print(" ✗ {}".format(addr))
|
||||||
|
else:
|
||||||
|
print("\n[GMX-Proxy] ✅ Tous les comptes GMX ont été lus avec succès.")
|
||||||
|
|
||||||
# 刷新成功的项目
|
# 刷新成功的项目
|
||||||
_refreshed_successful_items = MONGO_STORE_MANAGER.get_all_successful_items_for_day()
|
_refreshed_successful_items = MONGO_STORE_MANAGER.get_all_successful_items_for_day()
|
||||||
|
|
||||||
@@ -464,6 +477,8 @@ def find_links_to_validate_from_mail_list(
|
|||||||
else:
|
else:
|
||||||
logger.info("do not need to click url --> {}".format(mail.mail_address))
|
logger.info("do not need to click url --> {}".format(mail.mail_address))
|
||||||
|
|
||||||
|
return failed_gmx
|
||||||
|
|
||||||
|
|
||||||
# 主函数
|
# 主函数
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@@ -498,6 +513,15 @@ if __name__ == '__main__':
|
|||||||
if _to_add:
|
if _to_add:
|
||||||
filter_mail.append(mail_pojo)
|
filter_mail.append(mail_pojo)
|
||||||
# filter_mail = [MailAddress("birgitnaya@gmx.net", "XEeUF3Y1yaO")]
|
# filter_mail = [MailAddress("birgitnaya@gmx.net", "XEeUF3Y1yaO")]
|
||||||
|
|
||||||
|
# ── Mode de lecture : GMX_ONLY=true → uniquement les comptes GMX ──
|
||||||
|
gmx_only = os.environ.get("GMX_ONLY", "false").strip().lower() == "true"
|
||||||
|
if gmx_only:
|
||||||
|
filter_mail = [m for m in filter_mail if is_gmx_account(m.mail)]
|
||||||
|
print("[Mode] Lecture GMX uniquement ({} comptes)".format(len(filter_mail)))
|
||||||
|
else:
|
||||||
|
print("[Mode] Lecture de tous les comptes ({} comptes)".format(len(filter_mail)))
|
||||||
|
|
||||||
# 配置代理(GMX账号必须通过代理读取)
|
# 配置代理(GMX账号必须通过代理读取)
|
||||||
gmx_proxy = ProxyConfig(
|
gmx_proxy = ProxyConfig(
|
||||||
host=os.environ.get("GMX_PROXY_HOST", ""),
|
host=os.environ.get("GMX_PROXY_HOST", ""),
|
||||||
@@ -507,4 +531,12 @@ if __name__ == '__main__':
|
|||||||
password=os.environ.get("GMX_PROXY_PASSWORD"),
|
password=os.environ.get("GMX_PROXY_PASSWORD"),
|
||||||
)
|
)
|
||||||
# 处理邮件
|
# 处理邮件
|
||||||
find_links_to_validate_from_mail_list(filter_mail, logger, proxy=gmx_proxy)
|
failed = find_links_to_validate_from_mail_list(filter_mail, logger, proxy=gmx_proxy)
|
||||||
|
|
||||||
|
# ── Afficher les comptes GMX non lus ─────────────────────
|
||||||
|
if failed:
|
||||||
|
print("\n===== Comptes GMX non lus ({}) =====".format(len(failed)))
|
||||||
|
for addr in failed:
|
||||||
|
print(" ✗ {}".format(addr))
|
||||||
|
else:
|
||||||
|
print("\n===== Tous les comptes GMX ont été lus avec succès =====")
|
||||||
|
|||||||
Reference in New Issue
Block a user