fix: 修复 IMAP 邮件内容获取问题
- 使用 body: '.' 获取邮件完整内容,替代 source(某些 IMAP 服务器不支持) - 添加详细的 fetch 结果日志,记录返回的字段名 - 改进邮件获取失败时的日志输出
This commit is contained in:
parent
c11e9fbc64
commit
5430f51885
|
|
@ -208,13 +208,21 @@ async function scanEmails(
|
|||
}
|
||||
|
||||
try {
|
||||
const msg = await client.fetchOne(uid, { source: true, uid: true }, { uid: true })
|
||||
if (!msg || !('source' in msg) || !(msg as any).source) {
|
||||
console.log(`[Scan] 邮件 ${uid} 无内容,跳过`)
|
||||
// 使用 body 获取邮件内容,source 在某些 IMAP 服务器上可能不返回内容
|
||||
const msg = await client.fetchOne(uid, { uid: true, bodyStructure: true, body: '.' }, { uid: true })
|
||||
if (!msg) {
|
||||
console.log(`[Scan] 邮件 ${uid} 获取失败,跳过`)
|
||||
continue
|
||||
}
|
||||
|
||||
const parsed = await simpleParser((msg as any).source as Buffer)
|
||||
// 优先使用 source,其次使用 body
|
||||
const rawSource = (msg as any).source || (msg as any).body
|
||||
if (!rawSource) {
|
||||
console.log(`[Scan] 邮件 ${uid} 无内容,跳过 (keys: ${Object.keys(msg).join(',')})`)
|
||||
continue
|
||||
}
|
||||
|
||||
const parsed = await simpleParser(rawSource as Buffer)
|
||||
const subject = parsed.subject || ''
|
||||
const date = parsed.date ? formatBeijingTime(parsed.date) : formatBeijingTime()
|
||||
const msgId = parsed.messageId || String(uid)
|
||||
|
|
|
|||
Loading…
Reference in New Issue