+ node = _mime_node_create (parent, sub);
+
+ if (child == parent->next_child && parent->next_part_num != -1) {
+ /* We're traversing in depth-first order. Record the child's
+ * depth-first numbering. */
+ node->part_num = parent->next_part_num;
+ node->next_part_num = node->part_num + 1;
+
+ /* Prepare the parent for its next depth-first child. */
+ parent->next_child++;
+ parent->next_part_num = -1;
+
+ if (node->nchildren == 0) {
+ /* We've reached a leaf, so find the parent that has more
+ * children and set it up to number its next child. */
+ mime_node_t *iter = node->parent;
+ while (iter && iter->next_child == iter->nchildren)
+ iter = iter->parent;
+ if (iter)
+ iter->next_part_num = node->part_num + 1;
+ }
+ }
+
+ return node;