You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.0 KiB
JavaScript
49 lines
1.0 KiB
JavaScript
"use strict";
|
|
|
|
const lastItem = require("last-item");
|
|
const createNamedTreeBuilder = require("./named-tree-builder");
|
|
|
|
const specialUseAttributes = new Set([
|
|
'\\All',
|
|
'\\Archive',
|
|
'\\Drafts',
|
|
'\\Flagged',
|
|
'\\Important',
|
|
'\\Junk',
|
|
'\\Sent',
|
|
'\\Trash'
|
|
]);
|
|
|
|
// TODO: Eventually make this progressively updateable so that the results of multiple LIST commands can be combined over time?
|
|
|
|
module.exports = function createBoxTreeBuilder() {
|
|
let treeBuilder = createNamedTreeBuilder({
|
|
childrenKey: "children",
|
|
parentKey: "parent",
|
|
treatRootAsParent: false
|
|
});
|
|
|
|
return {
|
|
add: function (item) {
|
|
let { flags, delimiter } = item;
|
|
|
|
let path = (delimiter != null)
|
|
? item.name.split(delimiter)
|
|
: [ item.name ];
|
|
|
|
treeBuilder.add(path, {
|
|
name: lastItem(path),
|
|
path: path,
|
|
attributes: flags,
|
|
delimiter: delimiter,
|
|
specialUseAttribute: flags.find((attribute) => specialUseAttributes.has(attribute)),
|
|
children: null,
|
|
parent: null
|
|
});
|
|
},
|
|
done: function () {
|
|
return treeBuilder.done().children;
|
|
}
|
|
};
|
|
};
|