示例#1
0
    } else {
        fatal('Another instance of the script is still running for the specified account. ', "If this is not accurate, you may fix it by running this script with 'fix-lock=1'", "in the query string or you may unlock ALL accounts by running this script with 'fix-lock=1'", 'as the only parameter.');
    }
    exit;
}
// clear the lock in all cases of termination
function cleanup_lock()
{
    global $account_id;
    Lock::release('download_emails_' . $account_id);
}
register_shutdown_function('cleanup_lock');
$account = Email_Account::getDetails($account_id);
$mbox = Support::connectEmailServer($account);
if ($mbox == false) {
    $uri = Support::getServerURI($account);
    $login = $account['ema_username'];
    $error = imap_last_error();
    fatal("{$error}\n", "Could not connect to the email server '{$uri}' with login: '******'.", 'Please verify your email account settings and try again.');
}
// if we only want new emails
if ($account['ema_get_only_new']) {
    $new_emails = Support::getNewEmails($mbox);
    foreach ($new_emails as $new_email) {
        Support::getEmailInfo($mbox, $account, $new_email);
    }
} else {
    $total_emails = Support::getTotalEmails($mbox);
    if ($total_emails > 0) {
        for ($i = 1; $i <= $total_emails; $i++) {
            Support::getEmailInfo($mbox, $account, $i);
示例#2
0
 /**
  * Method used to connect to the provided email server.
  *
  * @access  public
  * @param   array $info The email server information
  * @return  resource The email server connection
  */
 function connectEmailServer($info)
 {
     $mbox = @imap_open(Support::getServerURI($info), $info['ema_username'], $info['ema_password']);
     if ($mbox === FALSE) {
         $errors = @imap_errors();
         if (strstr(strtolower($errors[0]), 'certificate failure')) {
             $mbox = @imap_open(Support::getServerURI($info, TRUE), $info['ema_username'], $info['ema_password']);
         } else {
             Error_Handler::logError('Error while connecting to the email server - ' . $errors[0], __FILE__, __LINE__);
         }
     }
     return $mbox;
 }