wildduck/imap-core/lib/commands/uid-expunge.js

57 lines
1.5 KiB
JavaScript
Raw Normal View History

2017-03-06 05:45:50 +08:00
'use strict';
2017-06-03 14:51:58 +08:00
const imapTools = require('../imap-tools');
2017-03-06 05:45:50 +08:00
module.exports = {
state: 'Selected',
2017-06-03 14:51:58 +08:00
schema: [
{
name: 'range',
type: 'sequence'
}
],
2017-03-06 05:45:50 +08:00
handler(command, callback) {
// Check if EXPUNGE method is set
if (typeof this._server.onExpunge !== 'function') {
return callback(null, {
response: 'NO',
message: 'EXPUNGE not implemented'
});
}
// Do nothing if in read only mode
if (this.selected.readOnly) {
return callback(null, {
response: 'OK'
});
}
2017-06-03 14:51:58 +08:00
let range = (command.attributes[0] && command.attributes[0].value) || '';
2017-03-06 05:45:50 +08:00
if (!imapTools.validateSequnce(range)) {
return callback(new Error('Invalid sequence set for UID EXPUNGE'));
}
let messages = imapTools.getMessageRange(this.selected.uidList, range, true);
2017-06-03 14:51:58 +08:00
this._server.onExpunge(
this.selected.mailbox,
{
isUid: true,
messages
},
this.session,
(err, success) => {
if (err) {
return callback(err);
}
callback(null, {
response: success === true ? 'OK' : 'NO',
code: typeof success === 'string' ? success.toUpperCase() : false
});
2017-03-06 05:45:50 +08:00
}
2017-06-03 14:51:58 +08:00
);
2017-03-06 05:45:50 +08:00
}
};