mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-14 05:41:05 +08:00
34 lines
1.2 KiB
JavaScript
34 lines
1.2 KiB
JavaScript
const TaskHelpers = {
|
|
messagesForThreadByCategory: function messagesForThreadByCategory(db, threadId) {
|
|
const msgsInCategories = {};
|
|
|
|
return db.Thread.findById(threadId).then((thread) =>
|
|
thread.getMessages().each((message) => {
|
|
if (!msgsInCategories[message.CategoryId]) {
|
|
msgsInCategories[message.CategoryId] = [message];
|
|
} else {
|
|
msgsInCategories.push(message);
|
|
}
|
|
})
|
|
).then(() => msgsInCategories)
|
|
},
|
|
|
|
forEachMessageInThread: function forEachMessageInThread({threadId, db, imap, callback}) {
|
|
console.log("FOR EACH MESSAGE IN THREAD")
|
|
return TaskHelpers.messagesForThreadByCategory(db, threadId)
|
|
.then((msgsInCategories) => {
|
|
const cids = Object.keys(msgsInCategories);
|
|
console.log(`Messages in categories: ${cids}`)
|
|
return db.Category.findAll({where: {id: cids}})
|
|
.each((category) =>
|
|
imap.openBox(category.name, {readOnly: false}).then(() => {
|
|
console.log(`Category Box open: ${category.id} | ${category.name}`);
|
|
return Promise.all(msgsInCategories[category.id].map((message) =>
|
|
callback({message, category})
|
|
)).then(() => imap.closeBoxAsync())
|
|
})
|
|
)
|
|
})
|
|
},
|
|
}
|
|
module.exports = TaskHelpers
|