[local-sync] fix(folder-list): Support children when parent has no attribs

This commit is contained in:
Ben Gotow 2016-12-05 16:20:17 -08:00
parent 1e3b346c94
commit aed1d59916
2 changed files with 165 additions and 147 deletions

View file

@ -1,158 +1,167 @@
{ {
"boxes": { "boxes": {
"2016": { "2016": {
"attribs": ["\\HasNoChildren"], "attribs": ["\\HasNoChildren"],
"delimiter": "/", "delimiter": "/",
"children": null, "children": null,
"parent": null "parent": null
}, },
"INBOX": { "INBOX": {
"attribs": ["\\HasNoChildren"], "attribs": ["\\HasNoChildren"],
"delimiter": "/", "delimiter": "/",
"children": null, "children": null,
"parent": null "parent": null
}, },
"Archive": { "Archive": {
"attribs": ["\\HasNoChildren", "\\Archive"], "attribs": ["\\HasNoChildren", "\\Archive"],
"delimiter": "/", "delimiter": "/",
"children": null, "children": null,
"parent": null, "parent": null,
"special_use_attrib": "\\Archive" "special_use_attrib": "\\Archive"
}, },
"Arts": { "Arts": {
"attribs": ["\\HasNoChildren"], "attribs": ["\\HasNoChildren"],
"delimiter": "/", "delimiter": "/",
"children": null, "children": null,
"parent": null "parent": null
}, },
"Boîte de réception": { "Boîte de réception": {
"attribs": ["\\HasNoChildren"], "attribs": ["\\HasNoChildren"],
"delimiter": "/", "delimiter": "/",
"children": null, "children": null,
"parent": null "parent": null
}, },
"Drafts": { "Drafts": {
"attribs": ["\\HasNoChildren", "\\Drafts"], "attribs": ["\\HasNoChildren", "\\Drafts"],
"delimiter": "/", "delimiter": "/",
"children": null, "children": null,
"parent": null, "parent": null,
"special_use_attrib": "\\Drafts" "special_use_attrib": "\\Drafts"
}, },
"Fondue": { "Fondue": {
"children": { "children": {
"Savoyarde": { "Savoyarde": {
"attribs": ["\\HasNoChildren"], "attribs": ["\\HasNoChildren"],
"delimiter": "/", "delimiter": "/",
"children": null, "children": null,
"parent": "[Circular]" "parent": "[Circular]"
} }
} }
}, },
"Housse": { "Housse": {
"children": { "children": {
"De": { "De": {
"children": { "children": {
"Bateau": { "Bateau": {
"attribs": ["\\HasNoChildren"], "attribs": ["\\HasNoChildren"],
"delimiter": "/", "delimiter": "/",
"children": null, "children": null,
"parent": "[Circular]" "parent": "[Circular]"
}, },
"Rateau": { "Rateau": {
"attribs": ["\\HasNoChildren"], "attribs": ["\\HasNoChildren"],
"delimiter": "/", "delimiter": "/",
"children": null, "children": null,
"parent": "[Circular]" "parent": "[Circular]"
} }
} }
} }
} }
}, },
"JJJJJJJ JJJJJJJJ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1": { "JJJJJJJ JJJJJJJJ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1": {
"attribs": ["\\HasNoChildren"], "attribs": ["\\HasNoChildren"],
"delimiter": "/", "delimiter": "/",
"children": null, "children": null,
"parent": null "parent": null
}, },
"N1-Snoozed": { "N1-Snoozed": {
"attribs": ["\\HasNoChildren"], "attribs": ["\\HasNoChildren"],
"delimiter": "/", "delimiter": "/",
"children": null, "children": null,
"parent": null "parent": null
}, },
"Over the top": { "Over the top": {
"attribs": ["\\HasNoChildren"], "attribs": ["\\HasNoChildren"],
"delimiter": "/", "delimiter": "/",
"children": null, "children": null,
"parent": null "parent": null
}, },
"Sent": { "Sent": {
"attribs": ["\\HasNoChildren", "\\Sent"], "attribs": ["\\HasNoChildren", "\\Sent"],
"delimiter": "/", "delimiter": "/",
"children": null, "children": null,
"parent": null, "parent": null,
"special_use_attrib": "\\Sent" "special_use_attrib": "\\Sent"
}, },
"Spam": { "Spam": {
"attribs": ["\\HasNoChildren", "\\Junk"], "attribs": ["\\HasNoChildren", "\\Junk"],
"delimiter": "/", "delimiter": "/",
"children": null, "children": null,
"parent": null, "parent": null,
"special_use_attrib": "\\Junk" "special_use_attrib": "\\Junk"
}, },
"Taxes": { "Taxes": {
"attribs": ["\\HasNoChildren"], "attribs": ["\\HasNoChildren"],
"delimiter": "/", "delimiter": "/",
"children": null, "children": null,
"parent": null "parent": null
}, },
"Trash": { "Trash": {
"attribs": ["\\HasNoChildren", "\\Trash"], "attribs": ["\\HasNoChildren", "\\Trash"],
"delimiter": "/", "delimiter": "/",
"children": null, "children": null,
"parent": null, "parent": null,
"special_use_attrib": "\\Trash" "special_use_attrib": "\\Trash"
} }
}, },
"expectedFolders": [{ "expectedFolders": [{
"role": "trash", "name": "Trash",
"name": "Trash" "role": "trash"
}, { }, {
"role": null, "name": "Taxes",
"name": "Taxes" "role": null
}, { }, {
"role": "spam", "name": "Spam",
"name": "Spam" "role": "spam"
}, { }, {
"role": "sent", "name": "Sent",
"name": "Sent" "role": "sent"
}, { }, {
"role": null, "name": "Over the top",
"name": "Over the top" "role": null
}, { }, {
"role": null, "name": "N1-Snoozed",
"name": "N1-Snoozed" "role": null
}, { }, {
"role": null, "name": "JJJJJJJ JJJJJJJJ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"name": "JJJJJJJ JJJJJJJJ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1" "role": null
}, { }, {
"role": "drafts", "name": "Housse/De/Rateau",
"name": "Drafts" "role": null
}, { }, {
"role": null, "name": "Housse/De/Bateau",
"name": "Boîte de réception" "role": null
}, { }, {
"role": null, "name": "Fondue/Savoyarde",
"name": "Arts" "role": null
}, { }, {
"role": null, "name": "Drafts",
"name": "Archive" "role": "drafts"
}, { }, {
"role": "inbox", "name": "Boîte de réception",
"name": "INBOX" "role": null
}, { }, {
"role": null, "name": "Arts",
"name": "2016" "role": null
}, {
"name": "Archive",
"role": null
}, {
"name": "INBOX",
"role": "inbox"
}, {
"name": "2016",
"role": null
}], }],
"expectedLabels": [] "expectedLabels": []
} }

View file

@ -66,17 +66,26 @@ class FetchFolderList {
const next = []; const next = [];
Object.keys(boxes).forEach((boxName) => { Object.keys(boxes).forEach((boxName) => {
stack.push([boxName, boxes[boxName]]); stack.push([[boxName], boxes[boxName]]);
}); });
while (stack.length > 0) { while (stack.length > 0) {
const [boxName, box] = stack.pop(); const [boxPath, box] = stack.pop();
if (!box.attribs) { if (!box.attribs) {
// Some boxes seem to come back as partial objects. Not sure why, but if (box.children) {
// I also can't access them via openMailbox. Possible node-imap i8n issue? // In Fastmail, folders which are just containers for other folders
continue; // have no attributes at all, just a children property. Add appropriate
// attribs so we can carry on.
box.attribs = ['\\HasChildren', '\\NoSelect'];
} else {
// Some boxes seem to come back as partial objects. Not sure why.
continue;
}
} }
const boxName = boxPath.join(box.delimiter);
this._logger.info({ this._logger.info({
box_name: boxName, box_name: boxName,
attributes: JSON.stringify(box.attribs), attributes: JSON.stringify(box.attribs),
@ -85,7 +94,7 @@ class FetchFolderList {
if (box.children && box.attribs.includes('\\HasChildren')) { if (box.children && box.attribs.includes('\\HasChildren')) {
Object.keys(box.children).forEach((subname) => { Object.keys(box.children).forEach((subname) => {
stack.push([`${boxName}${box.delimiter}${subname}`, box.children[subname]]); stack.push([[].concat(boxPath, [subname]), box.children[subname]]);
}); });
} }