diff --git a/docs/install/README.md b/docs/install/README.md index b4bfe5471..b718dea8f 100644 --- a/docs/install/README.md +++ b/docs/install/README.md @@ -412,4 +412,4 @@ RSSHub 支持 `memory` 和 `redis` 两种缓存方式 - 邮箱 邮件列表路由: - - `EMAIL_CONFIG_{email}`: 邮箱设置,替换 {email} 为 邮箱账号,邮件账户的 `@` 替换为 `.`,例如 `EMAIL_CONFIG_xxx.qq.com`。内容格式为 `password=密码&host=服务器&port=端口`,例如 `password=123456&host=imap.qq.com&port=993`。 + - `EMAIL_CONFIG_{email}`: 邮箱设置,替换 `{email}` 为 邮箱账号,邮件账户的 `@` 替换为 `.`,例如 `EMAIL_CONFIG_xxx.qq.com`。内容格式为 `password=密码&host=服务器&port=端口`,例如 `password=123456&host=imap.qq.com&port=993`。 diff --git a/docs/other.md b/docs/other.md index ad255e56f..948520b7f 100644 --- a/docs/other.md +++ b/docs/other.md @@ -1197,7 +1197,7 @@ type 为 all 时,category 参数不支持 cost 和 free ### 邮件列表 -> 仅支持 IMAP 协议 +> 仅支持 IMAP 协议,邮件密码等设置见 [邮件设置](/install/#其他应用配置) diff --git a/lib/routes/mail/imap.js b/lib/routes/mail/imap.js index c07972878..937470dfe 100644 --- a/lib/routes/mail/imap.js +++ b/lib/routes/mail/imap.js @@ -37,21 +37,34 @@ module.exports = async (ctx) => { imap.close(); }); + const ParserMail = async (data) => { + const mail = await parser(data); + let content = mail.html || mail.textAsHtml; + if (mail.attachments.length > 0) { + content += `

附件(${mail.attachments.length})

`; + mail.attachments.forEach((attachment) => { + content += `

${attachment.filename}

`; + }); + } + return content; + }; + const items = await Promise.all( mails.reverse().map(async (item) => { - const cache = await ctx.cache.get(item.envelope['message-id']); + const guid = item.envelope['message-id'] || `mail_${new Date(item.envelope.date).getTime()}`; + const cache = await ctx.cache.get(guid); if (cache) { return Promise.resolve(JSON.parse(cache)); } - const description = await parser(item['body[]']); + const description = await ParserMail(item['body[]']); const single = { title: item.envelope.subject, - description: description.html || description.textAsHtml, - guid: item.envelope['message-id'] || item.envelope.date, + description, + guid, pubDate: item.envelope.date, author: `${item.envelope.from[0].name}(${item.envelope.from[0].address})`, }; - ctx.cache.set(item.envelope['message-id'], JSON.stringify(single)); + ctx.cache.set(guid, JSON.stringify(single)); return Promise.resolve(single); }) );