mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-01-09 01:18:44 +08:00
60 lines
1.6 KiB
JavaScript
60 lines
1.6 KiB
JavaScript
'use strict';
|
|
|
|
let imapHandler = require('../handler/imap-handler');
|
|
|
|
// tag GETQUOTA ""
|
|
|
|
module.exports = {
|
|
state: ['Authenticated', 'Selected'],
|
|
|
|
schema: [{
|
|
name: 'quotaroot',
|
|
type: 'string'
|
|
}],
|
|
|
|
handler(command, callback) {
|
|
|
|
let quotaRoot = Buffer.from(command.attributes[0] && command.attributes[0].value || '', 'binary').toString();
|
|
|
|
if (typeof this._server.onGetQuota !== 'function') {
|
|
return callback(null, {
|
|
response: 'NO',
|
|
message: command.command + ' not implemented'
|
|
});
|
|
}
|
|
|
|
this._server.onGetQuota(quotaRoot, this.session, (err, data) => {
|
|
if (err) {
|
|
return callback(err);
|
|
}
|
|
|
|
if (typeof quota === 'string') {
|
|
return callback(null, {
|
|
response: 'NO',
|
|
code: data.toUpperCase()
|
|
});
|
|
}
|
|
|
|
// * QUOTA "" (STORAGE 220676 15728640)
|
|
this.send(imapHandler.compiler({
|
|
tag: '*',
|
|
command: 'QUOTA',
|
|
attributes: [data.root || '', [{
|
|
type: 'atom',
|
|
value: 'STORAGE'
|
|
}, {
|
|
type: 'atom',
|
|
value: String(Math.ceil((Number(data.storageUsed) || 0) / 1024))
|
|
}, {
|
|
type: 'atom',
|
|
value: String(Math.ceil((Number(data.quota) || 0) / 1024))
|
|
}]]
|
|
}));
|
|
|
|
callback(null, {
|
|
response: 'OK',
|
|
message: 'Success'
|
|
});
|
|
});
|
|
}
|
|
};
|