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

Method wait_for_email

src/services/base.py:166–240  ·  view source on GitHub ↗

等待并获取邮件(可选实现) Args: email: 邮箱地址 email_id: 邮箱服务中的 ID timeout: 超时时间(秒) check_interval: 检查间隔(秒) expected_sender: 期望的发件人(包含检查) expected_subject: 期望的主题(包含检查) Returns: 邮件信息字典,如果超时返回 None

(
        self,
        email: str,
        email_id: str = None,
        timeout: int = 120,
        check_interval: int = 3,
        expected_sender: str = None,
        expected_subject: str = None
    )

Source from the content-addressed store, hash-verified

164 return None
165
166 def wait_for_email(
167 self,
168 email: str,
169 email_id: str = None,
170 timeout: int = 120,
171 check_interval: int = 3,
172 expected_sender: str = None,
173 expected_subject: str = None
174 ) -> Optional[Dict[str, Any]]:
175 """
176 等待并获取邮件(可选实现)
177
178 Args:
179 email: 邮箱地址
180 email_id: 邮箱服务中的 ID
181 timeout: 超时时间(秒)
182 check_interval: 检查间隔(秒)
183 expected_sender: 期望的发件人(包含检查)
184 expected_subject: 期望的主题(包含检查)
185
186 Returns:
187 邮件信息字典,如果超时返回 None
188 """
189 import time
190 from datetime import datetime
191
192 start_time = time.time()
193 last_email_id = None
194
195 while time.time() - start_time < timeout:
196 try:
197 emails = self.list_emails()
198 for email_info in emails:
199 email_data = email_info.get("email", {})
200 current_email_id = email_info.get("id")
201
202 # 检查是否是新的邮件
203 if last_email_id and current_email_id == last_email_id:
204 continue
205
206 # 检查邮箱地址
207 if email_data.get("address") != email:
208 continue
209
210 # 获取邮件列表
211 messages = self.get_email_messages(email_id or current_email_id)
212 for message in messages:
213 # 检查发件人
214 if expected_sender and expected_sender not in message.get("from", ""):
215 continue
216
217 # 检查主题
218 if expected_subject and expected_subject not in message.get("subject", ""):
219 continue
220
221 # 返回邮件信息
222 return {
223 "id": message.get("id"),

Callers

nothing calls this directly

Calls 5

list_emailsMethod · 0.95
get_email_messagesMethod · 0.95
warningMethod · 0.80
sleepMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected