xf
This commit is contained in:
41
app/utils.py
41
app/utils.py
@@ -312,33 +312,26 @@ def get_all_emails(count=50):
|
|||||||
:return: 邮件列表
|
:return: 邮件列表
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# 获取所有邮件键
|
# 获取时间索引键
|
||||||
pattern = 'email:*'
|
time_keys = redis_client.keys('time:*')
|
||||||
email_keys = redis_client.keys(pattern)
|
# 按时间倒序排序
|
||||||
|
time_keys.sort(reverse=True)
|
||||||
|
# 限制数量
|
||||||
|
time_keys = time_keys[:count]
|
||||||
|
|
||||||
# 获取每个邮件的详细信息
|
|
||||||
emails = []
|
emails = []
|
||||||
for key in email_keys:
|
for time_key in time_keys:
|
||||||
email_data = redis_client.hgetall(key)
|
# 从时间索引获取邮件键
|
||||||
if email_data:
|
email_key = redis_client.get(time_key)
|
||||||
# 转换字节数据为字符串
|
if email_key:
|
||||||
email = {k.decode(): v.decode() for k, v in email_data.items()}
|
# 获取邮件数据
|
||||||
# 解析 JSON 字符串字段
|
email_data = redis_client.hgetall(email_key)
|
||||||
if 'recipients' in email:
|
if email_data:
|
||||||
email['recipients'] = json.loads(email['recipients'])
|
# 转换字节数据为字符串
|
||||||
if 'attachments' in email:
|
email = {k.decode(): v.decode() for k, v in email_data.items()}
|
||||||
email['attachments'] = json.loads(email['attachments'])
|
emails.append(email)
|
||||||
if 'headers' in email:
|
|
||||||
email['headers'] = json.loads(email['headers'])
|
|
||||||
if 'peer' in email:
|
|
||||||
email['peer'] = json.loads(email['peer'])
|
|
||||||
emails.append(email)
|
|
||||||
|
|
||||||
# 按时间戳排序
|
return emails
|
||||||
emails.sort(key=lambda x: x.get('timestamp', ''), reverse=True)
|
|
||||||
|
|
||||||
# 限制返回数量
|
|
||||||
return emails[:count]
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error getting all emails: {str(e)}")
|
logger.error(f"Error getting all emails: {str(e)}")
|
||||||
|
|||||||
Reference in New Issue
Block a user