wildduck/imap-core/lib/commands/unsubscribe.js

55 lines
1.4 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
// tag UNSUBSCRIBE "mailbox"
module.exports = {
state: ['Authenticated', 'Selected'],
2017-06-03 14:51:58 +08:00
schema: [
{
name: 'path',
2017-06-03 14:51:58 +08:00
type: 'string'
}
],
2017-03-06 05:45:50 +08:00
handler(command, callback) {
let path = imapTools.normalizeMailbox((command.attributes[0] && command.attributes[0].value) || '', !this.acceptUTF8Enabled);
2017-03-06 05:45:50 +08:00
// Check if UNSUBSCRIBE method is set
if (typeof this._server.onUnsubscribe !== 'function') {
return callback(null, {
response: 'NO',
message: 'UNSUBSCRIBE not implemented'
});
}
if (!path) {
2017-03-06 05:45:50 +08:00
// nothing to check for if mailbox is not defined
return callback(null, {
response: 'NO',
code: 'NONEXISTENT'
});
}
if (path === 'INBOX') {
2017-03-06 05:45:50 +08:00
return callback(null, {
response: 'NO',
message: 'Can not unsubscribe from INBOX'
});
}
this._server.onUnsubscribe(path, this.session, (err, success) => {
2017-03-06 05:45:50 +08:00
if (err) {
return callback(err);
}
callback(null, {
response: success === true ? 'OK' : 'NO',
code: typeof success === 'string' ? success.toUpperCase() : false
});
});
}
};