feat: mail content add attachment list (#2942)
This commit is contained in:
parent
78e730ef73
commit
31020639ff
|
|
@ -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`。
|
||||
|
|
|
|||
|
|
@ -1197,7 +1197,7 @@ type 为 all 时,category 参数不支持 cost 和 free
|
|||
|
||||
### 邮件列表
|
||||
|
||||
> 仅支持 IMAP 协议
|
||||
> 仅支持 IMAP 协议,邮件密码等设置见 [邮件设置](/install/#其他应用配置)
|
||||
|
||||
<Route author="kt286" example="/mail/imap/rss@rsshub.app" path="/mail/imap/:email" :paramsDesc="['邮箱账号']" />
|
||||
|
||||
|
|
|
|||
|
|
@ -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 += `<h3>附件(${mail.attachments.length})</h3>`;
|
||||
mail.attachments.forEach((attachment) => {
|
||||
content += `<p>${attachment.filename}</p>`;
|
||||
});
|
||||
}
|
||||
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);
|
||||
})
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in New Issue