mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-01-08 17:07:44 +08:00
Include mailbox size in mailbox listing
This commit is contained in:
parent
b8af48c13f
commit
7af4641e7c
1 changed files with 48 additions and 0 deletions
|
@ -34,6 +34,7 @@ module.exports = (db, server, mailboxHandler) => {
|
||||||
* @apiParam {String} user Users unique ID
|
* @apiParam {String} user Users unique ID
|
||||||
* @apiParam {Boolean} [specialUse=false] Should the response include only folders with specialUse flag set.
|
* @apiParam {Boolean} [specialUse=false] Should the response include only folders with specialUse flag set.
|
||||||
* @apiParam {Boolean} [counters=false] Should the response include counters (total + unseen). Counters come with some overhead.
|
* @apiParam {Boolean} [counters=false] Should the response include counters (total + unseen). Counters come with some overhead.
|
||||||
|
* @apiParam {Boolean} [sizes=false] Should the response include mailbox size in bytes. Size numbers come with a lot of overhead as an aggregated query is ran.
|
||||||
*
|
*
|
||||||
* @apiSuccess {Boolean} success Indicates successful response
|
* @apiSuccess {Boolean} success Indicates successful response
|
||||||
* @apiSuccess {Object[]} results List of user mailboxes
|
* @apiSuccess {Object[]} results List of user mailboxes
|
||||||
|
@ -107,6 +108,10 @@ module.exports = (db, server, mailboxHandler) => {
|
||||||
.truthy(['Y', 'true', 'yes', 'on', '1', 1])
|
.truthy(['Y', 'true', 'yes', 'on', '1', 1])
|
||||||
.falsy(['N', 'false', 'no', 'off', '0', 0, ''])
|
.falsy(['N', 'false', 'no', 'off', '0', 0, ''])
|
||||||
.default(false),
|
.default(false),
|
||||||
|
sizes: Joi.boolean()
|
||||||
|
.truthy(['Y', 'true', 'yes', 'on', '1', 1])
|
||||||
|
.falsy(['N', 'false', 'no', 'off', '0', 0, ''])
|
||||||
|
.default(false),
|
||||||
sess: Joi.string().max(255),
|
sess: Joi.string().max(255),
|
||||||
ip: Joi.string().ip({
|
ip: Joi.string().ip({
|
||||||
version: ['ipv4', 'ipv6'],
|
version: ['ipv4', 'ipv6'],
|
||||||
|
@ -138,6 +143,9 @@ module.exports = (db, server, mailboxHandler) => {
|
||||||
|
|
||||||
let user = new ObjectID(result.value.user);
|
let user = new ObjectID(result.value.user);
|
||||||
let counters = result.value.counters;
|
let counters = result.value.counters;
|
||||||
|
let sizes = result.value.sizes;
|
||||||
|
|
||||||
|
let sizeValues = false;
|
||||||
|
|
||||||
let userData;
|
let userData;
|
||||||
try {
|
try {
|
||||||
|
@ -166,6 +174,37 @@ module.exports = (db, server, mailboxHandler) => {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sizes) {
|
||||||
|
try {
|
||||||
|
sizeValues = await db.database
|
||||||
|
.collection('messages')
|
||||||
|
.aggregate([
|
||||||
|
{
|
||||||
|
$match: {
|
||||||
|
user
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$project: {
|
||||||
|
mailbox: '$mailbox',
|
||||||
|
size: '$size'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$group: {
|
||||||
|
_id: '$mailbox',
|
||||||
|
mailboxSize: {
|
||||||
|
$sum: '$size'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
])
|
||||||
|
.toArray();
|
||||||
|
} catch (err) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mailboxes;
|
let mailboxes;
|
||||||
try {
|
try {
|
||||||
mailboxes = await db.database
|
mailboxes = await db.database
|
||||||
|
@ -224,6 +263,15 @@ module.exports = (db, server, mailboxHandler) => {
|
||||||
subscribed: mailboxData.subscribed
|
subscribed: mailboxData.subscribed
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (sizeValues) {
|
||||||
|
for (let sizeValue of sizeValues) {
|
||||||
|
if (mailboxData._id.equals(sizeValue._id)) {
|
||||||
|
response.size = sizeValue.mailboxSize;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!counters) {
|
if (!counters) {
|
||||||
responses.push(response);
|
responses.push(response);
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in a new issue