MCPcopy Create free account
hub / github.com/Tron521/codex-console-temp / get_verification_code

Method get_verification_code

src/services/freemail.py:180–263  ·  view source on GitHub ↗

从 Freemail 邮箱获取验证码 Args: email: 邮箱地址 email_id: 未使用,保留接口兼容 timeout: 超时时间(秒) pattern: 验证码正则 otp_sent_at: OTP 发送时间戳(暂未使用) Returns: 验证码字符串,超时返回 None

(
        self,
        email: str,
        email_id: str = None,
        timeout: int = 120,
        pattern: str = OTP_CODE_PATTERN,
        otp_sent_at: Optional[float] = None,
    )

Source from the content-addressed store, hash-verified

178 raise EmailServiceError(f"创建邮箱失败: {e}")
179
180 def get_verification_code(
181 self,
182 email: str,
183 email_id: str = None,
184 timeout: int = 120,
185 pattern: str = OTP_CODE_PATTERN,
186 otp_sent_at: Optional[float] = None,
187 ) -> Optional[str]:
188 """
189 从 Freemail 邮箱获取验证码
190
191 Args:
192 email: 邮箱地址
193 email_id: 未使用,保留接口兼容
194 timeout: 超时时间(秒)
195 pattern: 验证码正则
196 otp_sent_at: OTP 发送时间戳(暂未使用)
197
198 Returns:
199 验证码字符串,超时返回 None
200 """
201 logger.info(f"正在从 Freemail 邮箱 {email} 获取验证码...")
202
203 start_time = time.time()
204 seen_mail_ids: set = set()
205
206 while time.time() - start_time < timeout:
207 try:
208 mails = self._make_request("GET", "/api/emails", params={"mailbox": email, "limit": 20})
209 if not isinstance(mails, list):
210 time.sleep(3)
211 continue
212
213 for mail in mails:
214 mail_id = mail.get("id")
215 if not mail_id or mail_id in seen_mail_ids:
216 continue
217
218 seen_mail_ids.add(mail_id)
219
220 sender = str(mail.get("sender", "")).lower()
221 subject = str(mail.get("subject", ""))
222 preview = str(mail.get("preview", ""))
223
224 content = f"{sender}\n{subject}\n{preview}"
225
226 if "openai" not in content.lower():
227 continue
228
229 # 尝试直接使用 Freemail 提取的验证码
230 v_code = mail.get("verification_code")
231 if v_code:
232 logger.info(f"从 Freemail 邮箱 {email} 找到验证码: {v_code}")
233 self.update_status(True)
234 return v_code
235
236 # 如果没有直接提供,通过正则匹配 preview
237 match = re.search(pattern, content)

Callers

nothing calls this directly

Calls 7

_make_requestMethod · 0.95
setFunction · 0.85
infoMethod · 0.80
sleepMethod · 0.80
warningMethod · 0.80
getMethod · 0.45
update_statusMethod · 0.45

Tested by

no test coverage detected