调试错误
This commit is contained in:
@@ -34,6 +34,12 @@ class MailStore:
|
|||||||
async def save_email(self, message, sender, recipients, raw_data=None):
|
async def save_email(self, message, sender, recipients, raw_data=None):
|
||||||
"""保存邮件到数据库和文件系统"""
|
"""保存邮件到数据库和文件系统"""
|
||||||
logging.info(f"开始保存邮件: 发件人={sender}, 收件人={recipients}")
|
logging.info(f"开始保存邮件: 发件人={sender}, 收件人={recipients}")
|
||||||
|
if recipients is None:
|
||||||
|
logging.warning("收件人列表为None,将使用空列表")
|
||||||
|
recipients_list = []
|
||||||
|
else:
|
||||||
|
recipients_list = recipients.split(",") # 假设是以逗号分隔的字符串
|
||||||
|
logging.debug(f"解析后的收件人列表: {recipients_list}")
|
||||||
try:
|
try:
|
||||||
# 解析邮件内容
|
# 解析邮件内容
|
||||||
email_subject = None
|
email_subject = None
|
||||||
@@ -44,24 +50,29 @@ class MailStore:
|
|||||||
# 提取邮件主题
|
# 提取邮件主题
|
||||||
if hasattr(message, 'subject') and message.subject:
|
if hasattr(message, 'subject') and message.subject:
|
||||||
email_subject = message.subject
|
email_subject = message.subject
|
||||||
|
logging.debug(f"提取的邮件主题: {email_subject}")
|
||||||
|
|
||||||
# 提取邮件内容
|
# 提取邮件内容
|
||||||
if hasattr(message, 'get_body'):
|
if hasattr(message, 'get_body'):
|
||||||
try:
|
try:
|
||||||
for part in message.walk():
|
for part in message.walk():
|
||||||
content_type = part.get_content_type()
|
content_type = part.get_content_type()
|
||||||
|
logging.debug(f"处理邮件部分: {content_type}")
|
||||||
|
|
||||||
if content_type == "text/plain":
|
if content_type == "text/plain":
|
||||||
body_text = part.get_payload(decode=True).decode(part.get_content_charset() or 'utf-8', errors='replace')
|
body_text = part.get_payload(decode=True).decode(part.get_content_charset() or 'utf-8', errors='replace')
|
||||||
|
logging.debug(f"提取的纯文本内容长度: {len(body_text)}")
|
||||||
|
|
||||||
elif content_type == "text/html":
|
elif content_type == "text/html":
|
||||||
body_html = part.get_payload(decode=True).decode(part.get_content_charset() or 'utf-8', errors='replace')
|
body_html = part.get_payload(decode=True).decode(part.get_content_charset() or 'utf-8', errors='replace')
|
||||||
|
logging.debug(f"提取的HTML内容长度: {len(body_html)}")
|
||||||
|
|
||||||
# 处理附件
|
# 处理附件
|
||||||
if part.get_filename():
|
if part.get_filename():
|
||||||
file_name = part.get_filename()
|
file_name = part.get_filename()
|
||||||
content = part.get_payload(decode=True)
|
content = part.get_payload(decode=True)
|
||||||
attachments.append((file_name, content))
|
attachments.append((file_name, content))
|
||||||
|
logging.debug(f"提取的附件: {file_name}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"获取邮件内容时出错: {str(e)}")
|
logging.error(f"获取邮件内容时出错: {str(e)}")
|
||||||
|
|
||||||
@@ -85,13 +96,6 @@ class MailStore:
|
|||||||
# 查找收件人对应的邮箱
|
# 查找收件人对应的邮箱
|
||||||
mailbox_id = None
|
mailbox_id = None
|
||||||
|
|
||||||
# 处理recipients为None的情况
|
|
||||||
if recipients is None:
|
|
||||||
logging.warning("收件人列表为None,将使用空列表")
|
|
||||||
recipients_list = []
|
|
||||||
else:
|
|
||||||
recipients_list = recipients if isinstance(recipients, list) else [recipients]
|
|
||||||
|
|
||||||
# 确保收件人列表不为空
|
# 确保收件人列表不为空
|
||||||
if not recipients_list:
|
if not recipients_list:
|
||||||
logging.error("收件人列表为空,无法确定邮箱")
|
logging.error("收件人列表为空,无法确定邮箱")
|
||||||
@@ -100,6 +104,7 @@ class MailStore:
|
|||||||
# 尝试找到或创建收件人邮箱
|
# 尝试找到或创建收件人邮箱
|
||||||
for recipient in recipients_list:
|
for recipient in recipients_list:
|
||||||
# 跳过空收件人
|
# 跳过空收件人
|
||||||
|
logging.debug(f"处理收件人: {recipient}")
|
||||||
if not recipient or '@' not in recipient:
|
if not recipient or '@' not in recipient:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user