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 db.Category.findById(toFolderId).then((category) => { return imap.move(message.categoryUID, category.name) }) } return TaskHelpers.forEachMessageInThread({threadId, db, imap, callback: eachMsg}) } } module.exports = MoveToFolderIMAP