xf
This commit is contained in:
33
app/utils.py
33
app/utils.py
@@ -312,33 +312,26 @@ def get_all_emails(count=50):
|
||||
:return: 邮件列表
|
||||
"""
|
||||
try:
|
||||
# 获取所有邮件键
|
||||
pattern = 'email:*'
|
||||
email_keys = redis_client.keys(pattern)
|
||||
# 获取时间索引键
|
||||
time_keys = redis_client.keys('time:*')
|
||||
# 按时间倒序排序
|
||||
time_keys.sort(reverse=True)
|
||||
# 限制数量
|
||||
time_keys = time_keys[:count]
|
||||
|
||||
# 获取每个邮件的详细信息
|
||||
emails = []
|
||||
for key in email_keys:
|
||||
email_data = redis_client.hgetall(key)
|
||||
for time_key in time_keys:
|
||||
# 从时间索引获取邮件键
|
||||
email_key = redis_client.get(time_key)
|
||||
if email_key:
|
||||
# 获取邮件数据
|
||||
email_data = redis_client.hgetall(email_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]
|
||||
return emails
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting all emails: {str(e)}")
|
||||
|
||||
Reference in New Issue
Block a user