<?php

include("global.inc");

if (($delall || $delete) && TRASH && $folder != TRASH)
{
    $tofolder = TRASH;
    $delall = 0;
    $delete = 0;
    $move = 1;
}

$tofolder = $tofolder == "INBOX" ? "INBOX" : construct_folder_str($tofolder);

if ($move)
{
        $msgs = $msglist ? implode($msglist, ",") : $msgnum;
        if(!imap_mail_move($mailbox, $msgs, $tofolder))
        {
            echo "ERROR<br>";
        }
}

if ($delall)
{
        for($i = 0; $i < count($msglist); $i++)
        {
            imap_delete($mailbox, $msglist[$i]);
        }
}

if ($delete)
{
        imap_delete($mailbox, $msgnum);
}

imap_expunge($mailbox);
imap_close($mailbox);

header("Location: index.php?folder=" . urlencode($folder));  

?>


