Bug 835149 - [email/IMAP] folder list sync breaks if IMAP server (ex: courier) returns folders in non-hierarchy order. r=squib, a=approval-gaia-v1 by sicking.

cherry-picked c721f35db7e372f316a162f1ec00c2d13ea8a1fb from gaia/master
which was landed in merge 622ae151f123ff2ca12d0335c40bb8e7a8442737

https://bugzilla.mozilla.org/show_bug.cgi?id=835149#c5