function bayesspam_rebuild_corpus_hook($args)
{
    if ($GLOBALS['bayesdbhandle'] == null) {
        return;
    }
    $res = $GLOBALS['bayesdbhandle']->query('SELECT CASE (LastRebuild<(NOW() - INTERVAL ' . $GLOBALS['bayes_autorebuild_timeout'] . ' MINUTE)) WHEN 1 THEN 1 ELSE 0 END as Rebuild FROM ' . $GLOBALS['bayesdbprefix'] . 'users WHERE UserName=\'' . $GLOBALS['bayes_username'] . '\'');
    $row = $res->fetchRow();
    if ($row['Rebuild']) {
        if ($args[0] == 'webmail_bottom' && $GLOBALS['bayesspam_rebuild_on_login']) {
            bayesspam_rebuild_corpus();
        }
        if ($args[0] == 'left_main_after' && $GLOBALS['bayesspam_rebuild_on_refresh']) {
            bayesspam_rebuild_corpus();
        }
    }
}
} elseif ($_REQUEST['action'] == 'ignore_rem' && isset($_REQUEST['ignore_rem'])) {
    for ($i = 0; $i <= count($GLOBALS['bayesspam_ignore_folders']); $i++) {
        removePref($GLOBALS['data_dir'], $GLOBALS['username'], 'bayesspam_ignore_folders_' . $i);
    }
    $GLOBALS['bayesspam_ignore_folders'] = array_diff($GLOBALS['bayesspam_ignore_folders'], array($_REQUEST['ignore_rem']));
    $temp = array();
    foreach ($GLOBALS['bayesspam_ignore_folders'] as $value) {
        $temp[] = $value;
    }
    $GLOBALS['bayesspam_ignore_folders'] = $temp;
    array_merge($GLOBALS['bayesspam_ignore_folders'], array());
    for ($i = 0; $i < count($GLOBALS['bayesspam_ignore_folders']); $i++) {
        setPref($GLOBALS['data_dir'], $GLOBALS['username'], 'bayesspam_ignore_folders_' . $i, $GLOBALS['bayesspam_ignore_folders'][$i]);
    }
} elseif ($_REQUEST['action'] == 'rebuild') {
    bayesspam_rebuild_corpus();
} elseif ($_REQUEST['action'] == 'empty') {
    bayesspam_nuke_db();
}
bayesspam_load();
$res = $GLOBALS['bayesdbhandle']->query("SELECT nonspamCount FROM " . $GLOBALS['bayesdbprefix'] . "users WHERE UserName='******'bayes_username'] . "'");
if (!DB::isError($res)) {
    $row = $res->fetchRow();
    $nonspamCount = $row['nonspamCount'];
} else {
    echo $res->getDebugInfo();
}
$res = $GLOBALS['bayesdbhandle']->query("SELECT spamCount FROM " . $GLOBALS['bayesdbprefix'] . "users WHERE UserName='******'bayes_username'] . "'");
if (!DB::isError($res)) {
    $row = $res->fetchRow();
    $spamCount = $row['spamCount'];
function bayesspam_rebuild_corpus_do()
{
    include_once SM_PATH . 'plugins/bayesspam/bayesspam_functions.php';
    bayesspam_rebuild_corpus();
}