This commit is contained in:
huangzhenpc
2025-03-05 14:11:54 +08:00
parent dcb10e4ca9
commit 8b29dd701b
2 changed files with 17 additions and 5 deletions

View File

@@ -5,6 +5,7 @@ from .utils import (get_latest_emails, get_latest_email_with_code,
get_allowed_domains, get_allowed_domains_with_time,
get_all_emails)
import redis
import json
def create_app():
app = Flask(__name__)
@@ -64,11 +65,22 @@ def create_app():
app.logger.error(f"Error in list_emails_page: {str(e)}")
return "获取邮件列表失败", 500
@app.route('/web/email/<recipient>')
def view_email_page(recipient):
@app.route('/web/email/<message_id>')
def view_email_page(message_id):
try:
email = get_latest_email_with_code(recipient)
if email:
# 直接从 Redis 获取邮件数据
email_key = f"email:{message_id}"
email_data = redis_client.hgetall(email_key)
if email_data:
# 转换字节数据为字符串
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])
except:
pass
return render_template('email_detail.html', email=email)
return "邮件不存在", 404
except Exception as e:

View File

@@ -22,7 +22,7 @@
<ul class="email-list">
{% for email in emails %}
<li class="email-item">
<a href="{{ url_for('view_email_page', recipient=email.message_id) }}">
<a href="{{ url_for('view_email_page', message_id=email.message_id) }}">
<div class="email-subject">{{ email.subject }}</div>
<div class="email-meta">
发件人: {{ email.sender }} |