echo '<input type="hidden" name="account_id" value="' . $account_id . '" />';
echo '<input type="hidden" name="close" value="false" />';
echo '<input type="hidden" name="return_to" value="' . $return_to . '" />';
echo '<input type="hidden" name="link_back" value="' . $link_back . '" />';
$tabtable = new tabtable('filters_list', $ml_filters, '600', '300', '100', '', true);
$tabtable->print_head();
echo '<table border="0" cellpadding="0" cellspacing="8" class="normal"><tr><td>';
if (isset($_REQUEST['delete_filter'])) {
    $email->delete_filter($_REQUEST['delete_filter']);
}
if (isset($_REQUEST['move_up_id']) && $_REQUEST['move_dn_id'] != 0) {
    $email->move_up($_REQUEST['move_up_id'], $_REQUEST['move_dn_id'], $_REQUEST['move_up_pr'], $_REQUEST['move_dn_pr']);
}
if ($email->get_all_folders($account_id, true) > 0) {
    echo '<a class="normal" href="filter.php?id=' . $account_id . '">' . $cmdAdd . '</a><br /><br />';
    $count = $email->get_filters($account_id);
    if ($count > 0) {
        echo '<table border="0" cellpadding="2" cellspacing="0"><tr>';
        echo '<td><h3>' . $ml_field . '</h3></td>';
        echo '<td><h3>' . $ml_contains . '</h3></td>';
        echo '<td><h3>' . $ml_folder . '</h3></td>';
        echo '<td>&nbsp;</td>';
        echo '<td>&nbsp;</td>';
        echo '<td>&nbsp;</td></tr>';
        $last_id = 0;
        $last_pr = 0;
        while ($email->next_record()) {
            switch ($email->f("field")) {
                case "sender":
                    $field = "E-mail";
                    break;
$radio_list->add_option('UNANSWERED', $cmdNo);
echo '</td></tr>';
echo '</table>';
echo '</td></tr>';
echo '<tr><td colspan="2">';
$button = new button($cmdSearch, 'javascript:document.forms[0].submit();');
echo '</td></tr>';
echo '</table>';
$tabtable->print_foot();
if ($query != '') {
    $messages_display = '';
    $msg_count = $mail->search($em_settings['sort_field'], $em_settings['sort_order'], $query);
    $mail->get_messages($first_row, $max_rows);
    $filters = array();
    //if there are new messages get the filters
    $email->get_filters($account['id']);
    while ($email->next_record()) {
        $filter["field"] = $email->f("field");
        $filter["folder"] = $email->f("folder");
        $filter["keyword"] = $email->f("keyword");
        $filters[] = $filter;
    }
    while ($mail->next_message(true)) {
        $continue = false;
        //check if message is new and apply users filters to new messages only in the inbox folder.
        if ($mail->f('new') == 1) {
            if (strtolower($mailbox) == "inbox") {
                for ($i = 0; $i < sizeof($filters); $i++) {
                    if ($filters[$i]["folder"]) {
                        $field = $mail->f($filters[$i]["field"]);
                        if (!is_array($field)) {