+
+ /** Next, we get all subscribed folders **/
+ fputs($imapConnection, "1 LSUB \"\" *\n");
+ $str = imapReadData($imapConnection, "1", true, $response, $message);
+ $dm = findMailboxDelimeter($imapConnection);
+ for ($i = 0;$i < count($str); $i++) {
+ $mailbox = chop($str[$i]);
+ if (substr(findMailboxName($mailbox), 0, 1) != ".") {
+ $boxes[$g]["RAW"] = $mailbox;
+
+ // Get the mailbox name and format it. If there is a $dm at the end of it, remove it.
+ $mailbox = findMailboxName($mailbox);
+ $periodCount = countCharInString($mailbox, $dm);
+ if (substr($mailbox, -1) == $dm)
+ $periodCount = $periodCount - 1;
+
+ // indent the correct number of spaces.
+ for ($j = 0;$j < $periodCount;$j++)
+ $boxes[$g]["FORMATTED"] = $boxes[$g]["FORMATTED"] . " ";
+
+ $boxes[$g]["FORMATTED"] = $boxes[$g]["FORMATTED"] . readShortMailboxName($mailbox, $dm);
+ $boxes[$g]["UNFORMATTED"] = $mailbox;
+ $boxes[$g]["ID"] = $g;
+ $g++;
+ }
+ }
+
+ $original = $boxes;
+
+ for ($i = 0; $i < count($original); $i++) {
+ $boxes[$i]["UNFORMATTED"] = strtolower($boxes[$i]["UNFORMATTED"]);
+ }
+
+ $boxes = ary_sort($boxes, "UNFORMATTED", 1);
+
+ for ($i = 0; $i < count($original); $i++) {
+ for ($j = 0; $j < count($original); $j++) {
+ if ($boxes[$i]["ID"] == $original[$j]["ID"]) {
+ $boxes[$i]["UNFORMATTED"] = $original[$j]["UNFORMATTED"];
+ $boxes[$i]["FORMATTED"] = $original[$j]["FORMATTED"];
+ $boxes[$i]["RAW"] = $original[$j]["RAW"];
+ }
+ }
+ }
+
+ for ($i = 0; $i < count($boxes); $i++) {
+ if ($boxes[$i]["UNFORMATTED"] == $special_folders[0]) {
+ $boxesnew[0]["FORMATTED"] = $boxes[$i]["FORMATTED"];
+ $boxesnew[0]["UNFORMATTED"] = trim($boxes[$i]["UNFORMATTED"]);
+ $boxesnew[0]["RAW"] = trim($boxes[$i]["RAW"]);
+ $boxes[$i]["USED"] = true;
+ }
+ }
+ if ($list_special_folders_first == true) {
+ for ($i = 0; $i < count($boxes); $i++) {
+ for ($j = 1; $j < count($special_folders); $j++) {
+ if (substr($boxes[$i]["UNFORMATTED"], 0, strlen($special_folders[$j])) == $special_folders[$j]) {
+ $pos = count($boxesnew);
+ $boxesnew[$pos]["FORMATTED"] = $boxes[$i]["FORMATTED"];
+ $boxesnew[$pos]["RAW"] = trim($boxes[$i]["RAW"]);
+ $boxesnew[$pos]["UNFORMATTED"] = trim($boxes[$i]["UNFORMATTED"]);
+ $boxes[$i]["USED"] = true;
+ }
+ }
+ }
+ }
+ for ($i = 0; $i < count($boxes); $i++) {
+ if (($boxes[$i]["UNFORMATTED"] != $special_folders[0]) &&
+ ($boxes[$i]["UNFORMATTED"] != ".mailboxlist") &&
+ ($boxes[$i]["USED"] == false)) {
+ $pos = count($boxesnew);
+ $boxesnew[$pos]["FORMATTED"] = $boxes[$i]["FORMATTED"];
+ $boxesnew[$pos]["RAW"] = trim($boxes[$i]["RAW"]);
+ $boxesnew[$pos]["UNFORMATTED"] = trim($boxes[$i]["UNFORMATTED"]);
+ $boxes[$i]["USED"] = true;
+ }
+ }
+
+ $boxes = $boxesnew;