function bayesspam_button_action($id)
{
    if ($GLOBALS['bayesdbhandle'] == null) {
        return;
    }
    if (!isset($id) || !is_array($id)) {
        return;
    }
    sqgetGlobalVar('markSpam', $markSpam, SQ_POST);
    sqgetGlobalVar('markHam', $markHam, SQ_POST);
    if (isset($markSpam)) {
        for ($i = 0; $i < count($id); $i++) {
            bayesspam_learn_single($GLOBALS['imapConnection'], $GLOBALS['mailbox'], $id[$i], 'spam');
        }
        if ($GLOBALS['bayesspam_delete']) {
            sqimap_msgs_list_delete($GLOBALS['imapConnection'], $GLOBALS['mailbox'], $id);
            sqimap_mailbox_expunge($GLOBALS['imapConnection'], $GLOBALS['mailbox']);
        } else {
            if (sqimap_mailbox_exists($GLOBALS['imapConnection'], $GLOBALS['bayesspam_folder'])) {
                if ($GLOBALS['mailbox'] == $GLOBALS['bayesspam_folder']) {
                    sqimap_msgs_list_move($GLOBALS['imapConnection'], $id, $GLOBALS['trash_folder']);
                } else {
                    sqimap_msgs_list_move($GLOBALS['imapConnection'], $id, $GLOBALS['bayesspam_folder']);
                }
                sqimap_mailbox_expunge($GLOBALS['imapConnection'], $GLOBALS['mailbox']);
                foreach ($id as $i) {
                    for ($a = 0; $a < count($GLOBALS['aMailbox']['UIDSET'][0]); $a++) {
                        if ($GLOBALS['aMailbox']['UIDSET'][0][$a] == $i) {
                            unset($GLOBALS['aMailbox']['UIDSET'][0][$a]);
                        }
                    }
                    foreach ($GLOBALS['aMailbox']['MSG_HEADERS'] as $m) {
                        if ($m['UID'] == $i) {
                            unset($GLOBALS['aMailbox']['MSG_HEADERS'][$i]);
                        }
                    }
                }
                // reindex the arrays
                $GLOBALS['aMailbox']['MSG_HEADERS'] = array_values($GLOBALS['aMailbox']['MSG_HEADERS']);
                $GLOBALS['aMailbox']['UIDSET'][0] = array_values($GLOBALS['aMailbox']['UIDSET'][0]);
                $GLOBALS['aMailbox']['EXISTS'] -= count($id);
                // Change the startMessage number if the mailbox was changed
                if ($GLOBALS['aMailbox']['PAGEOFFSET'] - 1 >= $GLOBALS['aMailbox']['EXISTS']) {
                    $GLOBALS['aMailbox']['PAGEOFFSET'] = $GLOBALS['aMailbox']['PAGEOFFSET'] > $GLOBALS['aMailbox']['LIMIT'] ? $GLOBALS['aMailbox']['PAGEOFFSET'] - $GLOBALS['aMailbox']['LIMIT'] : 1;
                    $GLOBALS['aMailbox']['OFFSET'] = $GLOBALS['aMailbox']['PAGEOFFSET'] - 1;
                }
            }
        }
    } else {
        if (isset($markHam)) {
            for ($i = 0; $i < count($id); $i++) {
                bayesspam_learn_single($GLOBALS['imapConnection'], $GLOBALS['mailbox'], $id[$i], 'nonspam');
            }
        }
    }
}
<?php

/* Path for SquirrelMail required files. */
define('SM_PATH', '../../');
include_once SM_PATH . 'include/validate.php';
include_once SM_PATH . 'functions/imap.php';
include_once SM_PATH . 'functions/plugin.php';
include_once SM_PATH . 'functions/page_header.php';
include_once SM_PATH . 'functions/html.php';
include_once SM_PATH . 'plugins/bayesspam/config.php';
if (!isset($_REQUEST)) {
    $_REQUEST['bayes_type'] = $HTTP_GET_VARS['bayes_type'];
    $_REQUEST['mailbox'] = $HTTP_GET_VARS['mailbox'];
    $_REQUEST['passed_id'] = $HTTP_GET_VARS['passed_id'];
    $_REQUEST['startMessage'] = $HTTP_GET_VARS['startMessage'];
    $_REQUEST['show_more'] = $HTTP_GET_VARS['show_more'];
}
if ($_REQUEST['bayes_type'] == 'spam' || $_REQUEST['bayes_type'] == 'nonspam') {
    $key = $_COOKIE['key'];
    $onetimepad = $_SESSION['onetimepad'];
    $username = $_SESSION['username'];
    $delimiter = $_SESSION['delimiter'];
    $imapConnection = sqimap_login($username, $key, $GLOBALS['imapServerAddress'], $GLOBALS['imapPort'], 10, $onetimepad);
    // the 10 is to hide the output
    sqimap_mailbox_select($imapConnection, $_REQUEST['mailbox']);
    bayesspam_learn_single($imapConnection, $_REQUEST['mailbox'], $_REQUEST['passed_id'], $_REQUEST['bayes_type']);
}
header('Location: ../../src/read_body.php?mailbox=' . $_REQUEST['mailbox'] . '&passed_id=' . $_REQUEST['passed_id'] . '&startMessage=' . $_REQUEST['startMessage'] . '&show_more=' . $_REQUEST['show_more']);