+function sqimap_utf7_decode_mbx_tree(&$mbx_tree) {
+ if (strtoupper($mbx_tree->mailboxname_full) == 'INBOX')
+ $mbx_tree->mailboxname_sub = _("INBOX");
+ else
+ $mbx_tree->mailboxname_sub = imap_utf7_decode_local($mbx_tree->mailboxname_sub);
+ if ($mbx_tree->mbxs) {
+ $iCnt = count($mbx_tree->mbxs);
+ for ($i=0;$i<$iCnt;++$i) {
+ $mbxs_tree->mbxs[$i] = sqimap_utf7_decode_mbx_tree($mbx_tree->mbxs[$i]);
+ }
+ }
+}
+
+
+function sqimap_tree_to_ref_array(&$mbx_tree,&$aMbxs) {
+ if ($mbx_tree)
+ $aMbxs[] =& $mbx_tree;
+ if ($mbx_tree->mbxs) {
+ $iCnt = count($mbx_tree->mbxs);
+ for ($i=0;$i<$iCnt;++$i) {
+ sqimap_tree_to_ref_array($mbx_tree->mbxs[$i],$aMbxs);
+ }
+ }
+}
+
+function sqimap_get_status_mbx_tree($imap_stream,&$mbx_tree) {
+ global $unseen_notify, $unseen_type, $trash_folder,$move_to_trash;
+ $aMbxs = $aQuery = $aTag = array();
+ sqimap_tree_to_ref_array($mbx_tree,$aMbxs);
+ // remove the root node
+ array_shift($aMbxs);
+
+ if($unseen_notify == 3) {
+ $cnt = count($aMbxs);
+ for($i=0;$i<$cnt;++$i) {
+ $oMbx =& $aMbxs[$i];
+ if (!$oMbx->is_noselect) {
+ $mbx = $oMbx->mailboxname_full;
+ if ($unseen_type == 2 ||
+ ($move_to_trash && $oMbx->mailboxname_full == $trash_folder)) {
+ $query = 'STATUS ' . sqimap_encode_mailbox_name($mbx) . ' (MESSAGES UNSEEN)';
+ } else {
+ $query = 'STATUS ' . sqimap_encode_mailbox_name($mbx) . ' (UNSEEN)';
+ }
+ sqimap_prepare_pipelined_query($query,$tag,$aQuery,false);
+ } else {
+ $oMbx->unseen = $oMbx->total = false;
+ $tag = false;
+ }
+ $oMbx->tag = $tag;
+ $aMbxs[$i] =& $oMbx;
+ }
+ // execute all the queries at once
+ $aResponse = sqimap_run_pipelined_command ($imap_stream, $aQuery, false, $aServerResponse, $aServerMessage);
+ $cnt = count($aMbxs);
+ for($i=0;$i<$cnt;++$i) {
+ $oMbx =& $aMbxs[$i];
+ $tag = $oMbx->tag;
+ if ($tag && $aServerResponse[$tag] == 'OK') {
+ $sResponse = implode('', $aResponse[$tag]);
+ if (preg_match('/UNSEEN\s+([0-9]+)/i', $sResponse, $regs)) {
+ $oMbx->unseen = $regs[1];
+ }
+ if (preg_match('/MESSAGES\s+([0-9]+)/i', $sResponse, $regs)) {
+ $oMbx->total = $regs[1];
+ }
+ }
+ unset($oMbx->tag);
+ }
+ } else if ($unseen_notify == 2) { // INBOX only
+ $cnt = count($aMbxs);
+ for($i=0;$i<$cnt;++$i) {
+ $oMbx =& $aMbxs[$i];
+ if (strtoupper($oMbx->mailboxname_full) == 'INBOX' ||
+ ($move_to_trash && $oMbx->mailboxname_full == $trash_folder)) {
+ if ($unseen_type == 2 ||
+ ($oMbx->mailboxname_full == $trash_folder && $move_to_trash)) {
+ $aStatus = sqimap_status_messages($imap_stream,$oMbx->mailboxname_full);
+ $oMbx->unseen = $aStatus['UNSEEN'];
+ $oMbx->total = $aStatus['MESSAGES'];
+ } else {
+ $oMbx->unseen = sqimap_unseen_messages($imap_stream,$oMbx->mailboxname_full);
+ }
+ $aMbxs[$i] =& $oMbx;
+ if (!$move_to_trash && $trash_folder) {
+ break;
+ } else {
+ // trash comes after INBOX
+ if ($oMbx->mailboxname_full == $trash_folder) {
+ break;
+ }
+ }
+ }
+ }
+ }
+}
+