2016-06-30 01:13:48 +08:00
|
|
|
const SyncbackTask = require('./syncback-task')
|
2016-06-30 02:44:30 +08:00
|
|
|
const TaskHelpers = require('./task-helpers')
|
2016-06-30 01:11:53 +08:00
|
|
|
|
2016-06-30 01:13:48 +08:00
|
|
|
class MoveToFolderIMAP extends SyncbackTask {
|
2016-06-29 05:07:54 +08:00
|
|
|
description() {
|
|
|
|
return `MoveToFolder`;
|
|
|
|
}
|
|
|
|
|
|
|
|
run(db, imap) {
|
2016-06-30 02:44:30 +08:00
|
|
|
const threadId = this.syncbackRequestObject().props.threadId
|
|
|
|
const toFolderId = this.syncbackRequestObject().props.folderId
|
|
|
|
|
2016-06-30 07:25:51 +08:00
|
|
|
const eachMsg = ({message, box}) => {
|
2016-07-01 00:29:21 +08:00
|
|
|
return db.Folder.findById(toFolderId).then((category) => {
|
|
|
|
return box.moveFromBox(message.folderImapUID, category.name)
|
2016-06-30 05:00:47 +08:00
|
|
|
})
|
2016-06-30 02:44:30 +08:00
|
|
|
}
|
|
|
|
|
2016-06-30 03:04:46 +08:00
|
|
|
return TaskHelpers.forEachMessageInThread({threadId, db, imap, callback: eachMsg})
|
2016-06-29 05:07:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = MoveToFolderIMAP
|