xf
This commit is contained in:
34
app/utils.py
34
app/utils.py
@@ -354,4 +354,36 @@ def get_all_emails(count=50):
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting all emails: {str(e)}", exc_info=True)
|
||||
return []
|
||||
return []
|
||||
|
||||
|
||||
def get_email_by_id(message_id):
|
||||
"""
|
||||
根据 message_id 获取邮件数据
|
||||
:param message_id: 邮件的唯一标识
|
||||
:return: 邮件数据字典或 None
|
||||
"""
|
||||
try:
|
||||
email_key = f"email:{message_id}"
|
||||
email_data = redis_client.hgetall(email_key)
|
||||
if not email_data:
|
||||
logger.warning(f"No data found for key: {email_key}")
|
||||
return None
|
||||
|
||||
# 转换字节数据为字符串
|
||||
email = {k.decode(): v.decode() for k, v in email_data.items()}
|
||||
|
||||
# 解析 JSON 字符串字段
|
||||
for field in ['recipients', 'attachments', 'headers', 'peer']:
|
||||
if field in email:
|
||||
try:
|
||||
email[field] = json.loads(email[field])
|
||||
logger.debug(f"Successfully parsed {field} field")
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to parse {field} field: {str(e)}")
|
||||
|
||||
return email
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting email by ID {message_id}: {str(e)}")
|
||||
return None
|
||||
Reference in New Issue
Block a user