Exemplo n.º 1
0
 /**
  * Permanently removes the given support emails from the associated email
  * server.
  *
  * @access  public
  * @param   array $sup_ids The list of support emails
  * @return  integer 1 if the removal worked, -1 otherwise
  */
 function expungeEmails($sup_ids)
 {
     $accounts = array();
     $stmt = "SELECT\n                    sup_id,\n                    sup_message_id,\n                    sup_ema_id\n                 FROM\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "support_email\n                 WHERE\n                    sup_id IN (" . implode(', ', Misc::escapeInteger($sup_ids)) . ")";
     $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC);
     if (PEAR::isError($res)) {
         Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
         return -1;
     } else {
         for ($i = 0; $i < count($res); $i++) {
             // don't remove emails from the imap/pop3 server if the email
             // account is set to leave a copy of the messages on the server
             $account_details = Email_Account::getDetails($res[$i]['sup_ema_id']);
             if (!$account_details['leave_copy']) {
                 // try to re-use an open connection to the imap server
                 if (!in_array($res[$i]['sup_ema_id'], array_keys($accounts))) {
                     $accounts[$res[$i]['sup_ema_id']] = Support::connectEmailServer(Email_Account::getDetails($res[$i]['sup_ema_id']));
                 }
                 $mbox = $accounts[$res[$i]['sup_ema_id']];
                 if ($mbox !== FALSE) {
                     // now try to find the UID of the current message-id
                     $matches = @imap_search($mbox, 'TEXT "' . $res[$i]['sup_message_id'] . '"');
                     if (count($matches) > 0) {
                         for ($y = 0; $y < count($matches); $y++) {
                             $headers = imap_headerinfo($mbox, $matches[$y]);
                             // if the current message also matches the message-id header, then remove it!
                             if ($headers->message_id == $res[$i]['sup_message_id']) {
                                 @imap_delete($mbox, $matches[$y]);
                                 @imap_expunge($mbox);
                                 break;
                             }
                         }
                     }
                 }
             }
             // remove the email record from the table
             Support::removeEmail($res[$i]['sup_id']);
         }
         return 1;
     }
 }
Exemplo n.º 2
0
    if (SAPI_CLI) {
        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'", "as the 4th parameter or you may unlock ALL accounts by running this script with '--fix-lock'", 'as the only parameter.');
    } 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) {