38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const inboxDir = path.join(__dirname, 'mail/sanguo-quant/inboxes/pangtong');
|
|
const aggregatedFile = path.join(__dirname, 'mail/sanguo-quant/inboxes/pangtong.json');
|
|
|
|
// 读取聚合文件
|
|
const content = fs.readFileSync(aggregatedFile, 'utf-8');
|
|
const messages = JSON.parse(content);
|
|
|
|
// 确保目录存在
|
|
if (!fs.existsSync(inboxDir)) {
|
|
fs.mkdirSync(inboxDir, { recursive: true });
|
|
}
|
|
|
|
// 将每个未读消息保存为单独文件
|
|
let count = 0;
|
|
messages.forEach((msg, index) => {
|
|
// 如果没有 isRead 字段,根据 read 字段转换
|
|
if (typeof msg.isRead === 'undefined') {
|
|
msg.isRead = msg.read || false;
|
|
}
|
|
|
|
// 分配一个唯一 ID
|
|
const msgId = `jiangwei-reply-${Date.now()}-${index}`;
|
|
const filename = path.join(inboxDir, `${msgId}.json`);
|
|
|
|
// 保存单独文件
|
|
fs.writeFileSync(filename, JSON.stringify(msg, null, 2));
|
|
if (!msg.isRead) {
|
|
count++;
|
|
console.log(`✅ 已提取未读消息: ${filename}`);
|
|
}
|
|
});
|
|
|
|
console.log(`\n🎉 提取完成!共提取 ${count} 个未读消息到正确目录: ${inboxDir}`);
|