tree.txt 1.3 KB

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