allow listing only special use mailboxes

This commit is contained in:
Andris Reinman 2018-09-10 14:13:14 +03:00
parent 50eac42965
commit ca852d6290
5 changed files with 35 additions and 32 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1 +1 @@
define({ "name": "wildduck", "version": "1.0.0", "description": "WildDuck API docs", "title": "WildDuck API", "url": "https://api.wildduck.email", "sampleUrl": false, "defaultVersion": "0.0.0", "apidoc": "0.3.0", "generator": { "name": "apidoc", "time": "2018-09-10T07:46:13.698Z", "url": "http://apidocjs.com", "version": "0.17.6" } });
define({ "name": "wildduck", "version": "1.0.0", "description": "WildDuck API docs", "title": "WildDuck API", "url": "https://api.wildduck.email", "sampleUrl": false, "defaultVersion": "0.0.0", "apidoc": "0.3.0", "generator": { "name": "apidoc", "time": "2018-09-10T11:13:03.088Z", "url": "http://apidocjs.com", "version": "0.17.6" } });

View file

@ -1 +1 @@
{ "name": "wildduck", "version": "1.0.0", "description": "WildDuck API docs", "title": "WildDuck API", "url": "https://api.wildduck.email", "sampleUrl": false, "defaultVersion": "0.0.0", "apidoc": "0.3.0", "generator": { "name": "apidoc", "time": "2018-09-10T07:46:13.698Z", "url": "http://apidocjs.com", "version": "0.17.6" } }
{ "name": "wildduck", "version": "1.0.0", "description": "WildDuck API docs", "title": "WildDuck API", "url": "https://api.wildduck.email", "sampleUrl": false, "defaultVersion": "0.0.0", "apidoc": "0.3.0", "generator": { "name": "apidoc", "time": "2018-09-10T11:13:03.088Z", "url": "http://apidocjs.com", "version": "0.17.6" } }

View file

@ -32,6 +32,7 @@ module.exports = (db, server, mailboxHandler) => {
* }
*
* @apiParam {String} user Users unique ID
* @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.
*
* @apiSuccess {Boolean} success Indicates successful response
@ -50,6 +51,9 @@ module.exports = (db, server, mailboxHandler) => {
* @apiExample {curl} Example usage:
* curl -i http://localhost:8080/users/59fc66a03e54454869460e45/mailboxes?counters=true
*
* @apiExample {curl} Special Use Only
* curl -i http://localhost:8080/users/59fc66a03e54454869460e45/mailboxes?specialUse=true
*
* @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK
* {
@ -95,6 +99,10 @@ module.exports = (db, server, mailboxHandler) => {
.lowercase()
.length(24)
.required(),
specialUse: Joi.boolean()
.truthy(['Y', 'true', 'yes', 'on', 1])
.falsy(['N', 'false', 'no', 'off', 0, ''])
.default(false),
counters: Joi.boolean()
.truthy(['Y', 'true', 'yes', 'on', 1])
.falsy(['N', 'false', 'no', 'off', 0, ''])
@ -106,11 +114,9 @@ module.exports = (db, server, mailboxHandler) => {
})
});
if (req.query.counters) {
req.params.counters = req.query.counters;
}
req.query.user = req.params.user;
const result = Joi.validate(req.params, schema, {
const result = Joi.validate(req.query, schema, {
abortEarly: false,
convert: true
});
@ -180,31 +186,28 @@ module.exports = (db, server, mailboxHandler) => {
mailboxes = [];
}
let list = new Map();
if (result.value.specialUse) {
mailboxes = mailboxes.filter(mailboxData => mailboxData.path === 'INBOX' || mailboxData.specialUse);
}
mailboxes = mailboxes
.map(mailbox => {
list.set(mailbox.path, mailbox);
return mailbox;
})
.sort((a, b) => {
if (a.path === 'INBOX') {
return -1;
}
if (b.path === 'INBOX') {
return 1;
}
if (a.path.indexOf('INBOX/') === 0 && b.path.indexOf('INBOX/') !== 0) {
return -1;
}
if (a.path.indexOf('INBOX/') !== 0 && b.path.indexOf('INBOX/') === 0) {
return 1;
}
if (a.subscribed !== b.subscribed) {
return (a.subscribed ? 0 : 1) - (b.subscribed ? 0 : 1);
}
return a.path.localeCompare(b.path);
});
mailboxes = mailboxes.map(mailboxData => mailboxData).sort((a, b) => {
if (a.path === 'INBOX') {
return -1;
}
if (b.path === 'INBOX') {
return 1;
}
if (a.path.indexOf('INBOX/') === 0 && b.path.indexOf('INBOX/') !== 0) {
return -1;
}
if (a.path.indexOf('INBOX/') !== 0 && b.path.indexOf('INBOX/') === 0) {
return 1;
}
if (a.subscribed !== b.subscribed) {
return (a.subscribed ? 0 : 1) - (b.subscribed ? 0 : 1);
}
return a.path.localeCompare(b.path);
});
let responses = [];