feat: AI并行处理 + 修复邮件丢失
- _ai_processor 改用 ThreadPoolExecutor(5 workers) 并行调用AI - _tg_worker 每轮排空所有待发TG消息(原来每轮只取1条) - fetch_unseen_emails 单封FETCH失败不再丢弃整个批次,跳过继续
This commit is contained in:
@@ -115,24 +115,28 @@ def fetch_unseen_emails(account: EmailAccount) -> list[Email]:
|
||||
emails = []
|
||||
|
||||
for uid in uids:
|
||||
_, msg_data = conn.uid("FETCH", uid, "RFC822")
|
||||
if msg_data[0] is None:
|
||||
logger.warning("UID %s FETCH 返回空,跳过", uid)
|
||||
try:
|
||||
_, msg_data = conn.uid("FETCH", uid, "RFC822")
|
||||
if msg_data[0] is None:
|
||||
logger.warning("UID %s FETCH 返回空,跳过", uid)
|
||||
continue
|
||||
raw_email = msg_data[0][1]
|
||||
msg = email.message_from_bytes(raw_email)
|
||||
|
||||
subject = _decode_str(msg.get("Subject", ""))
|
||||
sender = _decode_address_header(msg.get("From", ""))
|
||||
recipient = _decode_address_header(msg.get("To", ""))
|
||||
reply_to = _decode_address_header(msg.get("Reply-To", ""))
|
||||
date_str = msg.get("Date", "")
|
||||
body = _get_text_from_msg(msg)
|
||||
body_len = len(body)
|
||||
|
||||
logger.info(" 邮件: [%s] from=%s to=%s reply-to=%s (%d 字符)", subject, sender, recipient, reply_to, body_len)
|
||||
emails.append(Email(uid=uid, subject=subject, sender=sender, recipient=recipient,
|
||||
body=body, date=date_str, reply_to=reply_to, account_email=account.username))
|
||||
except Exception as e:
|
||||
logger.error("UID %s FETCH 失败,跳过: %s", uid, e)
|
||||
continue
|
||||
raw_email = msg_data[0][1]
|
||||
msg = email.message_from_bytes(raw_email)
|
||||
|
||||
subject = _decode_str(msg.get("Subject", ""))
|
||||
sender = _decode_address_header(msg.get("From", ""))
|
||||
recipient = _decode_address_header(msg.get("To", ""))
|
||||
reply_to = _decode_address_header(msg.get("Reply-To", ""))
|
||||
date_str = msg.get("Date", "")
|
||||
body = _get_text_from_msg(msg)
|
||||
body_len = len(body)
|
||||
|
||||
logger.info(" 邮件: [%s] from=%s to=%s reply-to=%s (%d 字符)", subject, sender, recipient, reply_to, body_len)
|
||||
emails.append(Email(uid=uid, subject=subject, sender=sender, recipient=recipient,
|
||||
body=body, date=date_str, reply_to=reply_to, account_email=account.username))
|
||||
|
||||
conn.logout()
|
||||
logger.info("共获取 %d 封新邮件", len(emails))
|
||||
|
||||
Reference in New Issue
Block a user