This commit is contained in:
huangzhenpc
2025-03-05 13:48:45 +08:00
parent 8855475bbb
commit 1ba7434348
2 changed files with 46 additions and 4 deletions

View File

@@ -302,4 +302,44 @@ def get_allowed_domains_with_time():
return domain_info
except Exception as e:
logger.error(f'Error fetching allowed domains with time: {e}')
return {}
return {}
def get_all_emails(count=50):
"""
获取所有邮件
:param count: 返回的邮件数量限制
:return: 邮件列表
"""
try:
# 获取所有邮件键
pattern = 'email:*'
email_keys = redis_client.keys(pattern)
# 获取每个邮件的详细信息
emails = []
for key in email_keys:
email_data = redis_client.hgetall(key)
if email_data:
# 转换字节数据为字符串
email = {k.decode(): v.decode() for k, v in email_data.items()}
# 解析 JSON 字符串字段
if 'recipients' in email:
email['recipients'] = json.loads(email['recipients'])
if 'attachments' in email:
email['attachments'] = json.loads(email['attachments'])
if 'headers' in email:
email['headers'] = json.loads(email['headers'])
if 'peer' in email:
email['peer'] = json.loads(email['peer'])
emails.append(email)
# 按时间戳排序
emails.sort(key=lambda x: x.get('timestamp', ''), reverse=True)
# 限制返回数量
return emails[:count]
except Exception as e:
logger.error(f"Error getting all emails: {str(e)}")
return []