diff --git a/app/__init__.py b/app/__init__.py index 16a62a8..8a6f396 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -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/') - def view_email_page(recipient): + @app.route('/web/email/') + 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: diff --git a/app/templates/email_list.html b/app/templates/email_list.html index 8443424..a908f0c 100644 --- a/app/templates/email_list.html +++ b/app/templates/email_list.html @@ -22,7 +22,7 @@