diff --git a/app/services/mail_store.py b/app/services/mail_store.py index 208c697..6916bb7 100644 --- a/app/services/mail_store.py +++ b/app/services/mail_store.py @@ -112,6 +112,19 @@ class MailStore: logging.info(f"提取完成x3: 纯文本={len(body_text)}字节, HTML={len(body_html)}字节, 附件数={len(attachments)}") + # 创建邮件记录前的检查 + if sender is None: + logging.error("发件人无效,无法保存邮件") + return False, "发件人无效" + + if not recipients or isinstance(recipients, str) and not recipients.strip(): + logging.error("收件人无效,无法保存邮件") + return False, "收件人无效" + + # 处理邮件主题 + if email_subject is None: + email_subject = "无主题" # 或者使用其他默认值 + # 保存到数据库 session = self.db_session_factory() try: @@ -181,7 +194,7 @@ class MailStore: # 创建邮件记录 email_obj = Email( - mailbox_id=mailbox_id, # 确保始终有邮箱ID + mailbox_id=mailbox_id, sender=sender, recipients=str(recipients), subject=email_subject,