<?php

define("IEM_CRON_JOB", true);
define("IEM_NO_CONTROLLER", true);
define("IEM_CLI_MODE", true);

//require_once dirname(dirname(dirname(dirname("")))) . "/index.php"; // LOL
require_once dirname(dirname(dirname(dirname(__FILE__)))) . "/index.php";
require_once IEM_PUBLIC_PATH . "/functions/api/settings.php";

$settings_api = new Settings_API();
if( $settings_api->NeedDatabaseUpgrade() ) {
    exit;
}

unset( $settings_api );

if( !SENDSTUDIO_SAFE_MODE && strpos(SENDSTUDIO_DISABLED_FUNCTIONS, "set_time_limit") === false ) {
    set_time_limit(0);
}

if( !defined("SENDSTUDIO_IS_SETUP") || !SENDSTUDIO_IS_SETUP ) {
    exit;
}

if( SENDSTUDIO_CRON_ENABLED != 1 ) {
    exit;
}

require_once SENDSTUDIO_FUNCTION_DIRECTORY . "/sendstudio_functions.php";
$path = IEM_ADDONS_PATH . "/fbl/api/fbl.php";
if( !is_file($path) ) {
    return false;
}

require_once $path;

$pp = (empty( $argv ) || 2 <= count( $argv ) ? (int)$argv[1] : 800);
$folder = (empty( $argv ) || 3 <= count($argv) ? $argv[2] : "INBOX");

$api = new Fbl_API();
$api->folder = $folder;
$api->process_all($pp);

?>