dsh/mailgo:fix/imap-fetch-body-panic
main
backendutil.FetchBodyStructure 对两类消息返回 nil,buildIMAPMessage 未处理 nil,go-imap 在 send() 协程格式化 FETCH 响应时 nil 指针解引用 panic,连接中途断开:
backendutil.FetchBodyStructure
buildIMAPMessage
send()
malformed MIME header line
multipart: NextPart: EOF
internal/imap_server/backend.go
internal/imap_server/integration_test.go
TestFetchBodyMalformedMIME
根因:backendutil.FetchBodyStructure 对部分消息返回 nil(典型场景: - message/rfc822 附件为 base64 编码时库内不解码,把编码文本当嵌套 消息头解析报错(转发邮件场景,如 .mail-monitor/forward.py 转发) - multipart 缺少结束边界(截断)时 extended 解析报错) buildIMAPMessage 未处理 nil,go-imap 格式化 FETCH 响应时在 send() 协程 nil 指针解引用 panic,连接中断——Thunderbird 只取到崩溃前已 发送的几封邮件,手机客户端一直卡在"正在获取邮件"。 修复: - BodyStructure 解析失败时降级为 text/plain 单段结构,杜绝 nil - FetchBodySection 返回 nil 时跳过该 section,不再写入 nil literal - 新增集成测试 TestFetchBodyMalformedMIME 覆盖两类畸形 MIME
No dependencies set.
The note is not visible to the blocked user.
问题现象
根因
backendutil.FetchBodyStructure对两类消息返回 nil,buildIMAPMessage未处理 nil,go-imap 在send()协程格式化 FETCH 响应时 nil 指针解引用 panic,连接中途断开:malformed MIME header line错误。实测生产数据 kevin INBOX id=58、dsh Sent id=59(由 .mail-monitor/forward.py 生成)multipart: NextPart: EOF。实测 ~25 封 go_blog/Gitea 通知邮件受影响修复
internal/imap_server/backend.go:internal/imap_server/integration_test.go:新增TestFetchBodyMalformedMIME回归测试(覆盖 base64 rfc822 附件 + 截断 multipart)验证