mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-12 12:40:08 +08:00
51 lines
1.7 KiB
JavaScript
51 lines
1.7 KiB
JavaScript
const SyncbackTask = require('./syncback-task')
|
|
const TaskHelpers = require('./task-helpers')
|
|
|
|
class MoveToFolderIMAP extends SyncbackTask {
|
|
description() {
|
|
return `MoveToFolder`;
|
|
}
|
|
|
|
run(db, imap) {
|
|
const threadId = this.syncbackRequestObject().props.threadId
|
|
const toFolderId = this.syncbackRequestObject().props.folderId
|
|
|
|
const eachMsg = ({message}) => {
|
|
return imap.move(message.CategoryId, toFolderId)
|
|
}
|
|
|
|
return TaskHelpers.forEachMessageInThread({threadId, db, imap, callback: eachMsg})
|
|
|
|
// for (const {message, category} of msgGenerator) {
|
|
// imap.moveAsync(messageId)
|
|
// }
|
|
// const {Category, Thread} = db;
|
|
// const threadId = this.syncbackRequestObject().props.threadId
|
|
// const toFolderId = this.syncbackRequestObject().props.folderId
|
|
//
|
|
// const thread = Thread.findById(threadId);
|
|
// const toFolder = Category.findById(toFolderId);
|
|
//
|
|
// const msgsInCategories = {};
|
|
//
|
|
// thread.getMessages((messages) => {
|
|
// for (const message of messages) {
|
|
// if (!msgsInCategories[message.CategoryId]) {
|
|
// msgsInCategories[message.CategoryId] = [message.messageId];
|
|
// } else {
|
|
// msgsInCategories.push(message.messageId);
|
|
// }
|
|
// }
|
|
// for (const categoryId of Object.keys(msgsInCategories)) {
|
|
// Category.findById(categoryId).then((category) => {
|
|
// imap.openBox(category, false);
|
|
// for (const messageId of msgsInCategories[categoryId]) {
|
|
// imap.moveAsync(messageId, toCategoryName);
|
|
// }
|
|
// imap.closeBox();
|
|
// })
|
|
// }
|
|
// })
|
|
}
|
|
}
|
|
module.exports = MoveToFolderIMAP
|