36bb3d7c |
1 | So what is this tree stuff? |
2 | =========================== |
3 | |
4 | In order to get correct folder deletion across the board for all |
5 | different RFC2060 compliant IMAP servers, deleting of folders |
6 | needed to work by deleting subfolders (inferiors) first, working |
7 | up to the top folder that is desired to be deleted. |
8 | |
9 | The best way to do this was to use a tree, and walk the thing in |
10 | preorder to get subfolders first (leaves), working our way up the |
11 | tree. I chose to use an array for the tree structure. |
12 | |
13 | The array has the following elements: |
14 | $tree[0]["value"] = <full folder name> |
15 | $tree[0]["doIHaveChildren"] = boolean |
16 | $tree[0]["subNodes"] = indexes of the array that are |
17 | child nodes of this node |
18 | |
19 | The trickiest part was finding the correct parent node when creating |
20 | a new node in the tree. Check the documentation in the code for |
21 | more info on this. |
22 | |
1e63b430 |
23 | Basically all we had to do was loop through each of the items that |
36bb3d7c |
24 | need to be in the tree (folders, subfolders), find their parent, |
25 | let their parent know it has a new child, and insert the values |
26 | into the child. |
27 | |
28 | Once the tree is generated, a simple preorder or postorder walk |
29 | of the tree can be done doing whatever function you desire (delete, |
30 | create, etc). |
31 | |
32 | Preorder walking gives you the tree from the leaves up. Postorder |
33 | walks the tree from the root node down to the leaves. |