diff --git a/README.md b/README.md index a3be1c8..67dd00b 100644 Binary files a/README.md and b/README.md differ diff --git a/config.py b/config.py index 2d1d648..2561363 100644 --- a/config.py +++ b/config.py @@ -15,12 +15,19 @@ class Config: def __init__(self): # 默认配置 self.default_config = { - "TEMP_MAIL": "demo", + "TEMP_MAIL": "", # 设置为空字符串,表示可选 "TEMP_MAIL_EXT": "@mailto.plus", "TEMP_MAIL_EPIN": "", "DOMAIN": "mailto.plus", "BROWSER_USER_AGENT": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", - "MAIL_SERVER": "https://tempmail.plus" + "MAIL_SERVER": "https://tempmail.plus", + # IMAP 相关配置 + "USE_IMAP": False, # 是否使用 IMAP + "IMAP_HOST": "", + "IMAP_PORT": 993, + "IMAP_USERNAME": "", + "IMAP_PASSWORD": "", + "IMAP_USE_SSL": True } # 获取应用程序的根目录路径 @@ -53,7 +60,7 @@ class Config: try: # 使用session发送请求,减少超时时间 response = self.session.get( - "https://cursorapi.nosqli.com/admin/api.mail/getRandom", + "https://cursorapi.nosqli.com/admin/api.mail/gettestapi", timeout=10, allow_redirects=True ) @@ -73,21 +80,29 @@ class Config: # 设置配置项 self.imap = False - self.temp_mail = config.get("TEMP_MAIL", self.default_config["TEMP_MAIL"]).strip() - self.temp_mail_ext = config.get("TEMP_MAIL_EXT", self.default_config["TEMP_MAIL_EXT"]).strip() - self.temp_mail_epin = config.get("TEMP_MAIL_EPIN", self.default_config["TEMP_MAIL_EPIN"]).strip() - self.domain = config.get("DOMAIN", self.default_config["DOMAIN"]).strip() - self.browser_user_agent = config.get("BROWSER_USER_AGENT", self.default_config["BROWSER_USER_AGENT"]).strip() - self.mail_server = config.get("MAIL_SERVER", self.default_config["MAIL_SERVER"]).strip() - - # 如果临时邮箱为null则加载IMAP - if self.temp_mail == "null": + + # 处理 TEMP_MAIL,如果为 null 则启用 IMAP + temp_mail = config.get("TEMP_MAIL") + if temp_mail is None or temp_mail == "null": self.imap = True - self.imap_server = config.get("IMAP_SERVER", "").strip() - self.imap_port = config.get("IMAP_PORT", "").strip() - self.imap_user = config.get("IMAP_USER", "").strip() - self.imap_pass = config.get("IMAP_PASS", "").strip() - self.imap_dir = config.get("IMAP_DIR", "inbox").strip() + self.temp_mail = "null" + else: + self.temp_mail = str(temp_mail).strip() + + # 设置其他基础配置 + self.temp_mail_ext = str(config.get("TEMP_MAIL_EXT", self.default_config["TEMP_MAIL_EXT"])).strip() + self.temp_mail_epin = str(config.get("TEMP_MAIL_EPIN", self.default_config["TEMP_MAIL_EPIN"])).strip() + self.domain = str(config.get("DOMAIN", self.default_config["DOMAIN"])).strip() + self.browser_user_agent = str(config.get("BROWSER_USER_AGENT", self.default_config["BROWSER_USER_AGENT"])).strip() + self.mail_server = str(config.get("MAIL_SERVER", self.default_config["MAIL_SERVER"])).strip() + + # 如果启用了 IMAP,设置 IMAP 配置 + if self.imap: + self.imap_server = str(config.get("IMAP_SERVER", "")).strip() + self.imap_port = str(config.get("IMAP_PORT", "")).strip() + self.imap_user = str(config.get("IMAP_USER", "")).strip() + self.imap_pass = str(config.get("IMAP_PASS", "")).strip() + self.imap_dir = str(config.get("IMAP_DIR", "inbox")).strip() self.check_config() diff --git a/cursor_pro_keep_alive.py b/cursor_pro_keep_alive.py index 3627c49..4eafd05 100644 --- a/cursor_pro_keep_alive.py +++ b/cursor_pro_keep_alive.py @@ -230,13 +230,16 @@ def handle_verification_code(tab, email_handler): while retry_count < max_retries: try: + print(f"\n[调试] 开始第 {retry_count + 1} 次验证码处理") if tab.ele("Account Settings", timeout=3): print_status("注册成功 - 已进入账户设置页面", "success") return True if tab.ele("@data-index=0", timeout=3): print_status("正在获取邮箱验证码...") + print(f"[调试] 开始获取验证码{email_handler}") code = get_verification_code_with_retry(email_handler) + print(f"[调试] 获取到的验证码: {code}") if not code: print_status("获取验证码失败", "error") return False @@ -246,6 +249,7 @@ def handle_verification_code(tab, email_handler): # 快速输入验证码 for i, digit in enumerate(code): + print(f"[调试] 输入第 {i+1} 位: {digit}") tab.ele(f"@data-index={i}").input(digit) time.sleep(0.1) @@ -254,10 +258,12 @@ def handle_verification_code(tab, email_handler): return True retry_count += 1 + print(f"[调试] 未找到验证码输入框,重试次数: {retry_count}") time.sleep(1) except Exception as e: print_status(f"验证码处理过程出错: {str(e)}", "error") + print(f"[调试] 错误详情: {str(e)}") retry_count += 1 if retry_count < max_retries: time.sleep(1) @@ -760,8 +766,8 @@ if __name__ == "__main__": print_status("浏览器初始化完成", "success") - print_status("正在初始化邮箱验证模块...") - email_handler = EmailVerificationHandler() + + print_step_header("配置信息") login_url = "https://authenticator.cursor.sh" @@ -779,6 +785,11 @@ if __name__ == "__main__": print_status(f"生成的邮箱账号: {account}") auto_update_cursor_auth = True + print_status("正在初始化邮箱验证模块...") + # 使用生成的account初始化email_handler + email_handler = EmailVerificationHandler(account=account) + + print_status("初始化邮箱验证模块成功", "success") tab = browser.latest_tab tab.run_js("try { turnstile.reset() } catch(e) { }") diff --git a/get_email_code.py b/get_email_code.py index 2d45cdf..1a65e73 100644 --- a/get_email_code.py +++ b/get_email_code.py @@ -9,11 +9,12 @@ import json class EmailVerificationHandler: - def __init__(self): + def __init__(self, account=None): config = Config() self.imap = config.get_imap() self.username = config.get_temp_mail() self.epin = config.get_temp_mail_epin() + self.account = account # 添加account属性,用于存储随机生成的邮箱 # 创建新的session并设置基本配置 self.session = requests.Session() @@ -56,25 +57,38 @@ class EmailVerificationHandler: mail.login(self.imap['imap_user'], self.imap['imap_pass']) mail.select(self.imap['imap_dir']) - status, messages = mail.search(None, 'FROM', '"no-reply@cursor.sh"') + # 使用分开的参数方式搜索,更准确 + status, messages = mail.search(None, 'TO', f'"{self.account}"', 'FROM', '"no-reply@cursor.sh"') + if status != 'OK': return None mail_ids = messages[0].split() if not mail_ids: - # 没有获取到,就在获取一次 + # 没有获取到,就再获取一次 return self._get_mail_code_by_imap(retry=retry + 1) - latest_mail_id = mail_ids[-1] + latest_id = mail_ids[-1] # 获取邮件内容 - status, msg_data = mail.fetch(latest_mail_id, '(RFC822)') + status, msg_data = mail.fetch(latest_id, '(RFC822)') if status != 'OK': return None raw_email = msg_data[0][1] email_message = email.message_from_bytes(raw_email) + # 严格验证收件人 + to_addresses = email_message.get_all('to', []) + found_match = False + for addr in to_addresses: + if self.account.lower() in addr.lower(): + found_match = True + break + + if not found_match: + return self._get_mail_code_by_imap(retry=retry + 1) + # 提取邮件正文 body = self._extract_imap_body(email_message) if body: @@ -83,16 +97,13 @@ class EmailVerificationHandler: if code_match: code = code_match.group() # 删除邮件 - mail.store(latest_mail_id, '+FLAGS', '\\Deleted') + mail.store(latest_id, '+FLAGS', '\\Deleted') mail.expunge() mail.logout() - # print(f"找到的验证码: {code}") return code - # print("未找到验证码") mail.logout() return None except Exception as e: - print(f"发生错误: {e}") return None def _extract_imap_body(self, email_message): @@ -177,6 +188,4 @@ class EmailVerificationHandler: if __name__ == "__main__": - email_handler = EmailVerificationHandler() - code = email_handler.get_verification_code() - print(code) + pass diff --git a/last_account.json b/last_account.json index 6c7e878..c46d1f4 100644 --- a/last_account.json +++ b/last_account.json @@ -1,4 +1,4 @@ { "email": "12132ed@qq.com", - "last_used": "2025-02-09 23:13:26" + "last_used": "2025-02-10 16:52:55" } \ No newline at end of file diff --git a/logo.py b/logo.py index 1778769..60a70a4 100644 --- a/logo.py +++ b/logo.py @@ -30,7 +30,7 @@ def print_logo(): ██║ ╚████║╚██████╔╝███████║╚██████╔╝███████╗██║ ╚═╝ ╚═══╝ ╚═════╝ ╚══════╝ ╚══▀▀═╝ ╚══════╝╚═╝{Fore.CYAN} - {Fore.YELLOW}CURSOR PROFESSIONAL TOOLS - ENTERPRISE EDITION V8.0.1{Fore.CYAN} + {Fore.YELLOW}CURSOR PROFESSIONAL TOOLS - ENTERPRISE EDITION V8.0.2{Fore.CYAN} ════════════════════════════════════════════════════════════════════════════ diff --git a/test_email.py b/test_email.py deleted file mode 100644 index 1ce067d..0000000 --- a/test_email.py +++ /dev/null @@ -1,43 +0,0 @@ -import requests -import json -import urllib3 - -# 禁用SSL警告 -urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) - -def test_specific_email(): - print("开始测试指定邮箱API...") - - # 创建session并配置 - session = requests.Session() - session.verify = False - session.trust_env = False - - # 测试URL - test_url = "https://tempmail.plus/api/mails?email=ademyyk@mailto.plus&limit=20&epin=" - - try: - # 不使用代理直接测试 - print("\n1. 直接连接测试...") - response = session.get(test_url) - print(f"状态码: {response.status_code}") - print(f"响应内容: {json.dumps(response.json(), indent=2, ensure_ascii=False)}") - - except Exception as e: - print(f"\n直接连接出错: {e}") - - # 如果直接连接失败,尝试使用代理 - try: - print("\n2. 尝试使用代理...") - proxies = { - 'http': 'http://127.0.0.1:7890', - 'https': 'http://127.0.0.1:7890' - } - response = session.get(test_url, proxies=proxies) - print(f"状态码: {response.status_code}") - print(f"响应内容: {json.dumps(response.json(), indent=2, ensure_ascii=False)}") - except Exception as e: - print(f"\n代理连接也出错: {e}") - -if __name__ == "__main__": - test_specific_email() \ No newline at end of file diff --git a/test_mail_api.py b/test_mail_api.py deleted file mode 100644 index 43e4777..0000000 --- a/test_mail_api.py +++ /dev/null @@ -1,29 +0,0 @@ -import requests -import json - -# 禁用 SSL 警告 -import urllib3 -urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) - -def test_mail_api(): - print("开始测试邮箱API...") - - try: - # 发送请求 - response = requests.get( - 'https://cursorapi.nosqli.com/admin/api.mail/getRandom', - verify=False, - proxies={"http": None, "https": None}, - timeout=10 - ) - - # 打印响应 - print("\n状态码:", response.status_code) - print("\n响应内容:") - print(json.dumps(response.json(), indent=2, ensure_ascii=False)) - - except Exception as e: - print(f"\n请求失败: {str(e)}") - -if __name__ == "__main__": - test_mail_api() \ No newline at end of file