From de688f6c22a15881f98b74ad4fe379fb5c8959ec Mon Sep 17 00:00:00 2001 From: huangzhenpc Date: Wed, 5 Mar 2025 10:56:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/__init__.py | 21 ++++++++++++++++++++- app/init.py | 28 ---------------------------- 2 files changed, 20 insertions(+), 29 deletions(-) delete mode 100644 app/init.py diff --git a/app/__init__.py b/app/__init__.py index c9f6cb1..c1a9043 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,6 +1,9 @@ -from flask import Flask, request, jsonify +from flask import Flask, request, jsonify, render_template from .config import Config from .utils import get_latest_emails, get_latest_email_with_code, add_allowed_domain, remove_allowed_domain, get_allowed_domains, get_allowed_domains_with_time +import redis +from .smtp_server import start_smtp_server +import threading def create_app(): app = Flask(__name__) @@ -51,4 +54,20 @@ def create_app(): domains_with_time = get_allowed_domains_with_time() return jsonify(domains_with_time), 200 + @app.route('/') + def list_emails_page(): + emails = get_latest_emails(count=50) + return render_template('email_list.html', emails=emails) + + @app.route('/email/') + def view_email_page(recipient): + email = get_latest_email_with_code(recipient) + if email: + return render_template('email_detail.html', email=email) + return "邮件不存在", 404 + + smtp_thread = threading.Thread(target=start_smtp_server, args=(app,)) + smtp_thread.daemon = True + smtp_thread.start() + return app \ No newline at end of file diff --git a/app/init.py b/app/init.py deleted file mode 100644 index 5b066af..0000000 --- a/app/init.py +++ /dev/null @@ -1,28 +0,0 @@ -from flask import Flask, request, jsonify, render_template -from .utils import get_latest_emails, get_latest_email_with_code, add_allowed_domain, remove_allowed_domain, get_allowed_domains, get_allowed_domains_with_time -import redis -from .config import Config -from .smtp_server import start_smtp_server -import threading - -def create_app(): - app = Flask(__name__) - app.config.from_object(Config) - - # 现有的路由保持不变... - - @app.route('/') - def list_emails(): - # 获取所有邮件 - emails = get_latest_emails(count=50) # 获取最新50封邮件 - return render_template('email_list.html', emails=emails) - - @app.route('/email/') - def view_email(email_id): - # 获取单个邮件详情 - email = get_latest_email_with_code(email_id) - if email: - return render_template('email_detail.html', email=email) - return "邮件不存在", 404 - - return app \ No newline at end of file