improvement while reading mails
This commit is contained in:
@@ -2,6 +2,7 @@ import datetime
|
||||
import logging
|
||||
import time
|
||||
import os
|
||||
from typing import Optional
|
||||
|
||||
from pymongo import MongoClient
|
||||
|
||||
@@ -22,6 +23,7 @@ DESTINATION_EMAIL_LIST = "DESTINATION_EMAIL_LIST"
|
||||
LINKS_TO_VALIDATE = "LINKS_TO_VALIDATE"
|
||||
INVALID_EMAIL_LIST = "INVALID_EMAIL_LIST"
|
||||
CONTACT_LIST_SERIAL_MAP = "CONTACT_LIST_SERIAL_MAP"
|
||||
MAIL_READ_LOG = "MAIL_READ_LOG" # 记录每个邮箱上次读取时间
|
||||
|
||||
|
||||
class MongoDbManager:
|
||||
@@ -264,5 +266,29 @@ class MongoDbManager:
|
||||
collection_to_use = self.db[LINKS_TO_VALIDATE]
|
||||
collection_to_use.delete_one({"_id": linkPojo.email})
|
||||
|
||||
# ── Mail read-time tracking ────────────────────────────────────
|
||||
|
||||
def get_last_mail_read_time(self, mail: str) -> Optional[datetime.datetime]:
|
||||
"""返回指定邮箱上次被读取的 UTC 时间,若从未读取则返回 None。"""
|
||||
try:
|
||||
doc = self.db[MAIL_READ_LOG].find_one({"_id": mail})
|
||||
if doc and "last_read_at" in doc:
|
||||
return doc["last_read_at"]
|
||||
except Exception as err:
|
||||
self.logger.warning("get_last_mail_read_time error: %s", err)
|
||||
return None
|
||||
|
||||
def update_mail_read_time(self, mail: str) -> None:
|
||||
"""将指定邮箱的上次读取时间更新为当前 UTC 时间。"""
|
||||
try:
|
||||
self.db[MAIL_READ_LOG].replace_one(
|
||||
{"_id": mail},
|
||||
{"_id": mail, "last_read_at": datetime.datetime.utcnow()},
|
||||
upsert=True,
|
||||
)
|
||||
except Exception as err:
|
||||
self.logger.warning("update_mail_read_time error: %s", err)
|
||||
|
||||
|
||||
MONGO_STORE_MANAGER = MongoDbManager()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user