diff --git a/remove_emails_from_destination.py b/remove_emails_from_destination.py new file mode 100644 index 0000000..81e5907 --- /dev/null +++ b/remove_emails_from_destination.py @@ -0,0 +1,79 @@ +""" +脚本:从 DESTINATION_EMAIL_LIST 集合中批量删除指定邮箱地址 +用法: + 直接修改下方 EMAIL_LIST_TO_REMOVE 列表,然后运行脚本。 + 或在代码中调用 remove_emails_from_destination(email_list) 函数。 +""" + +import logging +from typing import List + +from src.db.mongo_manager import MONGO_STORE_MANAGER +from src.pojo.mail.mail_pojo import MailAddress + +logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") +logger = logging.getLogger(__name__) + + +def remove_emails_from_destination(email_list: List[str]) -> None: + """ + 从 DESTINATION_EMAIL_LIST 集合中删除给定的邮箱地址列表。 + + Args: + email_list (List[str]): 需要删除的邮箱地址字符串列表 + """ + if not email_list: + logger.warning("传入的邮箱列表为空,无需删除。") + return + + success_count = 0 + fail_count = 0 + + for email in email_list: + email = email.strip() + if not email: + continue + try: + # remove_email_from_destination_email_list 需要一个 MailAddress 对象 + # password 字段对删除操作无影响,传空字符串即可 + mail_address = MailAddress(mail=email, password="") + MONGO_STORE_MANAGER.remove_email_from_destination_email_list(mail_address) + logger.info(f"已删除邮箱: {email}") + success_count += 1 + except Exception as e: + logger.error(f"删除邮箱 {email} 时出错: {e}") + fail_count += 1 + + logger.info(f"删除完成 — 成功: {success_count},失败: {fail_count},共处理: {success_count + fail_count} 条") + + +# ────────────────────────────────────────────── +# 直接运行时,修改下方列表即可批量删除 +# ────────────────────────────────────────────── +EMAIL_LIST_TO_REMOVE: List[str] = [ + "susannekaar@gmx.net", + "dianataya@gmx.net", + "sophiezhoz@gmx.net", + "claudiavimu@gmx.net", + "leoniekeyk@gmx.net", + "katjamoem@gmx.net", + "annechoa@gmx.net", + "manuelacoep@gmx.net", + "kathrinbeet@gmx.net", + "katjapoyu@gmx.net", + "klausciluwe@gmx.net", + "petraneak@gmx.net", + "leahpona@gmx.net", + "jenniferhoko@gmx.net", + "phillippkemikv@gmx.net", + "sandrasika@gmx.net", + "leoniekala@gmx.net", + "sabinekiav@gmx.net", + "marinabaes@gmx.net", + "ulrikegevo@gmx.net", + "claudiadare@gmx.net" +] + +if __name__ == "__main__": + remove_emails_from_destination(EMAIL_LIST_TO_REMOVE) +