mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-09-05 23:47:50 +08:00
fix: 修复 IMAP fetch 方法返回生成器导致的 TypeError (#764)
修复了在 K8s 环境中运行时出现的错误:
File "/usr/local/lib/python3.12/site-packages/twisted/mail/imap4.py", line 1685, in __cbManualSearch
lastSequenceId = result and result[-1][0]
TypeError: 'generator' object is not subscriptable
问题原因:
- fetch 方法返回了生成器对象
- Twisted IMAP4 库在处理 SEARCH 命令时需要对结果进行索引访问
- 生成器不支持索引操作
解决方案:
- 将 fetch 方法的返回值从生成器改为列表
- 保持 fetchGenerator 方法的分批获取逻辑(batch_size=20)
- 确保内存占用可控的同时支持所有 IMAP 操作
This commit is contained in:
@@ -135,16 +135,16 @@ class SimpleMailbox:
|
|||||||
|
|
||||||
def fetch(self, messages, uid):
|
def fetch(self, messages, uid):
|
||||||
"""边查边返回邮件"""
|
"""边查边返回邮件"""
|
||||||
def email_generator():
|
result = []
|
||||||
for range_item in messages.ranges:
|
for range_item in messages.ranges:
|
||||||
start, end = range_item
|
start, end = range_item
|
||||||
_logger.info(f"Fetching messages: {self.name}, range: {start}-{end}")
|
_logger.info(f"Fetching messages: {self.name}, range: {start}-{end}")
|
||||||
|
|
||||||
for email_data in self.fetchGenerator(start, end):
|
for email_data in self.fetchGenerator(start, end):
|
||||||
yield email_data
|
result.append(email_data)
|
||||||
|
|
||||||
# 返回生成器,让IMAP4服务器逐个处理
|
# 返回列表而不是生成器,以支持 IMAP SEARCH 等需要索引访问的操作
|
||||||
return email_generator()
|
return result
|
||||||
|
|
||||||
def fetchGenerator(self, start, end):
|
def fetchGenerator(self, start, end):
|
||||||
"""通用的邮件获取生成器,边查边返回"""
|
"""通用的邮件获取生成器,边查边返回"""
|
||||||
|
|||||||
Reference in New Issue
Block a user