Esempio n. 1
0
File: tree.php Progetto: jprice/EHCP
/**
 * Recursively walk the tree of trash mailboxes and delete all folders and messages
 *
 * @param int index the place in the tree to start, usually 0
 * @param stream imap_stream the IMAP connection to send commands to
 * @param array tree the tree to walk
 * @return void
 */
function walkTreeInPreOrderEmptyTrash($index, $imap_stream, $tree)
{
    global $trash_folder;
    if ($tree[$index]['doIHaveChildren']) {
        for ($j = 0; $j < count($tree[$index]['subNodes']); $j++) {
            walkTreeInPreOrderEmptyTrash($tree[$index]['subNodes'][$j], $imap_stream, $tree);
        }
        if ($tree[$index]['value'] != $trash_folder) {
            sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
        } else {
            $mbx_response = sqimap_mailbox_select($imap_stream, $trash_folder);
            if ($mbx_response['EXISTS'] > 0) {
                sqimap_messages_flag($imap_stream, 1, '*', 'Deleted', true);
                // CLOSE === EXPUNGE and UNSELECT
                sqimap_run_command($imap_stream, 'CLOSE', false, $response, $message);
            }
        }
    } else {
        if ($tree[$index]['value'] != $trash_folder) {
            sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
        } else {
            $mbx_response = sqimap_mailbox_select($imap_stream, $trash_folder);
            if ($mbx_response['EXISTS'] > 0) {
                sqimap_messages_flag($imap_stream, 1, '*', 'Deleted', true);
                // CLOSE === EXPUNGE and UNSELECT
                sqimap_run_command($imap_stream, 'CLOSE', false, $response, $message);
            }
        }
    }
}
Esempio n. 2
0
function walkTreeInPreOrderEmptyTrash($index, $imap_stream, $tree)
{
    global $trash_folder;
    if ($tree[$index]['doIHaveChildren']) {
        for ($j = 0; $j < count($tree[$index]['subNodes']); $j++) {
            walkTreeInPreOrderEmptyTrash($tree[$index]['subNodes'][$j], $imap_stream, $tree);
        }
        if ($tree[$index]['value'] != $trash_folder) {
            sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
        } else {
            $mbx_response = sqimap_mailbox_select($imap_stream, $trash_folder);
            if ($mbx_response['EXISTS'] > 0) {
                sqimap_messages_flag($imap_stream, 1, '*', 'Deleted', true);
                sqimap_mailbox_expunge($imap_stream, $trash_folder, true);
            }
        }
    } else {
        if ($tree[$index]['value'] != $trash_folder) {
            sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
        } else {
            $mbx_response = sqimap_mailbox_select($imap_stream, $trash_folder);
            if ($mbx_response['EXISTS'] > 0) {
                sqimap_messages_flag($imap_stream, 1, '*', 'Deleted', true);
                sqimap_mailbox_expunge($imap_stream, $trash_folder, true);
            }
        }
    }
}
Esempio n. 3
0
 *    so lets go through the list of subfolders and remove them before removing the
 *    parent.
 */
/** First create the top node in the tree **/
$numboxes = count($boxes);
for ($i = 0; $i < $numboxes; $i++) {
    if ($boxes[$i]['unformatted'] == $mailbox && strlen($boxes[$i]['unformatted']) == strlen($mailbox)) {
        $foldersTree[0]['value'] = $mailbox;
        $foldersTree[0]['doIHaveChildren'] = false;
        continue;
    }
}
/*
 * Now create the nodes for subfolders of the parent folder
 * You can tell that it is a subfolder by tacking the mailbox delimiter
 *    on the end of the $mailbox string, and compare to that.
 */
$j = 0;
for ($i = 0; $i < $numboxes; $i++) {
    if (substr($boxes[$i]['unformatted'], 0, strlen($mailbox . $delimiter)) == $mailbox . $delimiter) {
        addChildNodeToTree($boxes[$i]['unformatted'], $boxes[$i]['unformatted-dm'], $foldersTree);
    }
}
// now lets go through the tree and delete the folders
walkTreeInPreOrderEmptyTrash(0, $imap_stream, $foldersTree);
sqimap_logout($imap_stream);
// close session properly before redirecting
session_write_close();
$location = get_location();
// force_refresh = 1 in case trash contains deleted mailboxes
header("Location: {$location}/left_main.php?force_refresh=1");