From db490718c51fc9dd6cffbf24658853c4ef911e0a Mon Sep 17 00:00:00 2001 From: jahv Date: Tue, 29 Apr 2025 10:07:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=82=AE=E4=BB=B6=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=94=AF=E6=8C=81=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E6=9C=80=E8=BF=913=E5=88=86=E9=92=9F=E5=86=85?= =?UTF-8?q?=E7=9A=84=E9=82=AE=E4=BB=B6=EF=BC=8C=E5=B9=B6=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86=E4=BF=A1=E6=81=AF=E3=80=82?= =?UTF-8?q?=E5=90=8C=E6=97=B6=EF=BC=8C=E6=B7=BB=E5=8A=A0=E4=BA=86=E4=B8=BB?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=85=A5=E5=8F=A3=E4=BB=A5=E4=BE=BF=E4=BA=8E?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E8=BF=90=E8=A1=8C=E5=92=8C=E6=B5=8B=E8=AF=95?= =?UTF-8?q?TempMailPlusTab=E7=B1=BB=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- email_tabs/tempmail_plus_tab.py | 60 +++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/email_tabs/tempmail_plus_tab.py b/email_tabs/tempmail_plus_tab.py index 4fbea0d..2f2b8cf 100644 --- a/email_tabs/tempmail_plus_tab.py +++ b/email_tabs/tempmail_plus_tab.py @@ -1,5 +1,6 @@ import requests import re +import datetime from typing import Optional from .email_tab_interface import EmailTabInterface @@ -39,10 +40,10 @@ class TempMailPlusTab(EmailTabInterface): pass def check_for_cursor_email(self) -> bool: - """Check if there is a verification email from Cursor + """Check if there is a new email within the last 3 minutes Returns: - bool: True if verification email exists, False otherwise + bool: True if new email within 3 minutes exists, False otherwise """ try: params = { @@ -59,13 +60,21 @@ class TempMailPlusTab(EmailTabInterface): data = response.json() if data.get('result') and data.get('mail_list'): + current_time = datetime.datetime.now() for mail in data['mail_list']: - if 'cursor.sh' in mail.get('from_mail', '') and mail.get('is_new') == True: - self._cached_mail_id = mail.get('mail_id') # 缓存mail_id - return True + if mail.get('is_new') == True: + # 检查邮件时间是否在3分钟内 + try: + mail_time = datetime.datetime.strptime(mail.get('time', ''), '%Y-%m-%d %H:%M:%S') + time_diff = (current_time - mail_time).total_seconds() / 60 # 转换为分钟 + if time_diff <= 3: # 3分钟内的邮件 + self._cached_mail_id = mail.get('mail_id') # 缓存mail_id + return True + except ValueError: + continue return False except Exception as e: - print(f"检查Cursor邮件失败: {str(e)}") + print(f"检查新邮件失败: {str(e)}") return False def get_verification_code(self) -> str: @@ -106,4 +115,41 @@ class TempMailPlusTab(EmailTabInterface): return "" except Exception as e: print(f"获取验证码失败: {str(e)}") - return "" \ No newline at end of file + return "" + +if __name__ == "__main__": + import os + import time + import sys + + from config import get_config + + config = get_config() + + try: + email = config.get('TempMailPlus', 'email') + epin = config.get('TempMailPlus', 'epin') + + print(f"配置的邮箱: {email}") + + # 初始化TempMailPlusTab + mail_tab = TempMailPlusTab(email, epin) + + # 检查是否有Cursor的邮件 + print("正在检查Cursor验证邮件...") + if mail_tab.check_for_cursor_email(): + print("找到Cursor验证邮件") + + # 获取验证码 + verification_code = mail_tab.get_verification_code() + if verification_code: + print(f"获取到的验证码: {verification_code}") + else: + print("未能获取到验证码") + else: + print("未找到Cursor验证邮件") + + except configparser.Error as e: + print(f"读取配置文件错误: {str(e)}") + except Exception as e: + print(f"发生错误: {str(e)}") \ No newline at end of file