Example #1
0
}
// argv/argc needs to be enabled in CLI mode
if (SAPI_CLI && ini_get('register_argc_argv') == 'Off') {
    fatal('Eventum requires the ini setting register_argc_argv to be enabled to run this script.', 'Please refer to the PHP manual for more details on how to change this ini setting.');
}
$config = getParams();
// check for the required parameters
if (!$config['fix-lock'] && (empty($config['username']) || empty($config['hostname']))) {
    if (SAPI_CLI) {
        fatal('Wrong number of parameters given. Expected parameters related to the email account:', ' 1 - username', ' 2 - hostname', ' 3 - mailbox (only required if IMAP account)', 'Example: php download_emails.php user example.com INBOX');
    } else {
        fatal('Wrong number of parameters given. Expected parameters related to email account:', 'download_emails.php?username=<i>username</i>&hostname=<i>hostname</i>&mailbox=<i>mailbox</i>');
    }
}
// get the account ID early since we need it also for unlocking.
$account_id = Email_Account::getAccountID($config['username'], $config['hostname'], $config['mailbox']);
if (!$account_id && !$config['fix-lock']) {
    fatal('Could not find a email account with the parameter provided.', 'Please verify your email account settings and try again.');
}
if ($config['fix-lock']) {
    // if there is no account id, unlock all accounts
    if (!$account_id) {
        $prj_ids = array_keys(Project::getAll());
        foreach ($prj_ids as $prj_id) {
            $ema_ids = Email_Account::getAssocList($prj_id);
            foreach ($ema_ids as $ema_id => $ema_title) {
                $lockfile = 'download_emails_' . $ema_id;
                if (Lock::release($lockfile)) {
                    msg("Removed lock file '{$lockfile}'.");
                }
            }
// check for the required parameters
if ($fix_lock != true && (empty($username) || empty($hostname))) {
    if ($type == 'cli') {
        echo "Error: Wrong number of parameters given. Expected parameters related to the email account:\n";
        echo " 1 - username\n";
        echo " 2 - hostname\n";
        echo " 3 - mailbox (only required if IMAP account)\n";
        echo "Example: php -q download_emails.php user example.com INBOX\n";
    } else {
        echo "Error: Wrong number of parameters given. Expected parameters related to email account:<br />\n";
        echo "download_emails.php?username=<i>username</i>&hostname=<i>hostname</i>&mailbox=<i>mailbox</i><br />";
    }
    exit;
}
// get the account ID since we need it for locking.
$account_id = Email_Account::getAccountID($username, $hostname, $mailbox);
if ($account_id == 0 && $fix_lock != true) {
    echo "Error: Could not find a email account with the parameter provided. Please verify your email account settings and try again.\n";
    exit;
}
if ($fix_lock == true) {
    // if there is no account id, unlock all accounts
    if (empty($account_id)) {
        $prj_ids = array_keys(Project::getAll());
        foreach ($prj_ids as $prj_id) {
            $ema_ids = Email_Account::getAssocList($prj_id);
            foreach ($ema_ids as $ema_id => $ema_title) {
                Lock::release('download_emails_' . $ema_id);
            }
        }
    } else {