xf
This commit is contained in:
38
app/utils.py
38
app/utils.py
@@ -307,32 +307,28 @@ def get_allowed_domains_with_time():
|
||||
|
||||
def get_all_emails(count=50):
|
||||
"""
|
||||
获取所有邮件
|
||||
获取所有邮件,直接从 email:* 键获取
|
||||
:param count: 返回的邮件数量限制
|
||||
:return: 邮件列表
|
||||
"""
|
||||
try:
|
||||
# 获取时间索引键
|
||||
time_keys = redis_client.keys('time:*')
|
||||
# 按时间倒序排序
|
||||
time_keys.sort(reverse=True)
|
||||
# 限制数量
|
||||
time_keys = time_keys[:count]
|
||||
|
||||
# 直接获取所有邮件键
|
||||
email_keys = redis_client.keys('email:*')
|
||||
emails = []
|
||||
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()}
|
||||
emails.append(email)
|
||||
|
||||
return emails
|
||||
|
||||
|
||||
# 获取每个邮件的数据
|
||||
for email_key in email_keys:
|
||||
email_data = redis_client.hgetall(email_key)
|
||||
if email_data:
|
||||
# 转换字节数据为字符串
|
||||
email = {k.decode(): v.decode() for k, v in email_data.items()}
|
||||
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 []
|
||||
Reference in New Issue
Block a user