$gateway_db_select = 3;
include "../includes/dbconnection.php";
require_once "../includes/function.php";
require_once '../includes/phpmailer/imap.inc.php';
$log = "Searching for all bad emails...\n";
$imap = new IMAPMAIL();
if (!$imap->open("mail.etelegate.com", "143")) {
    $log .= $imap->get_error();
    print $log;
    exit;
}
$imap->login("ReturnedEmails+etelegate.com", "etelcs88");
$log .= $imap->error;
$response = $imap->open_mailbox("INBOX");
$log .= $imap->error;
$emailList = $imap->search_mailbox("SINCE " . date("d-M-Y", time() - 48 * 60 * 60) . " OR OR SUBJECT \"delayed 48 hours\" SUBJECT \"Undeliverable: Welcome to Gkard\" SUBJECT \"Mail delivery failed\"");
//echo $response=$imap->delete_message(9);
//echo $response=$imap->rollback_delete(9);
if (is_array($emailList)) {
    foreach ($emailList as $emailId) {
        $log .= " Checking Email #{$emailId}...\n";
        $content = $imap->get_message($emailId);
        //explode("",$content);
        //print_r($content);
        $matches = NULL;
        preg_match_all("/([A-Z0-9._-]+@[A-Z0-9.-]+\\.[A-Z]{2,6})/i", $content, &$matches);
        //print_r(array_unique($matches[1]));
        $foundEmails = $matches[1];
        $email = NULL;
        if ($foundEmails[2] == '*****@*****.**') {
            $email = $foundEmails[5];
Beispiel #2
0
 /**
  * @param int $pageNumber
  * @param Folder $folder
  * @return WebMailMessageCollection
  */
 function &LoadMessageHeaders($pageNumber, &$folder)
 {
     $webMailMessageCollection = null;
     if ($this->_imapMail->open_mailbox($folder->FullName, false)) {
         if ($folder->SyncType == FOLDERSYNC_DirectMode) {
             if ($folder->MessageCount < 1) {
                 $newcoll = new WebMailMessageCollection();
                 return $newcoll;
             }
             $msgCount = $folder->MessageCount;
             $messageIndexSet = array();
             $isSortSupport = $this->_imapMail->IsSortSupport();
             if ($isSortSupport) {
                 $order_by = $this->GetOrderByForImapSort();
                 $messageSortedIndexSet = array();
                 $messageSortedIndexSet = $this->_imapMail->search_mailbox('', 'UTF-8', $order_by);
                 $msgCount = count($messageSortedIndexSet);
             }
             for ($i = $msgCount - ($pageNumber - 1) * $this->Account->MailsPerPage, $t = $msgCount - $pageNumber * $this->Account->MailsPerPage; $i > $t; $i--) {
                 if ($isSortSupport) {
                     if ($i < 1) {
                         break;
                     }
                     $messageIndexSet[] = $messageSortedIndexSet[$i - 1];
                 } else {
                     if ($i == 0) {
                         break;
                     }
                     $messageIndexSet[] = $i;
                 }
             }
             $webMailMessageCollection =& $this->LoadMessageHeadersInOneRequest($folder, $messageIndexSet);
         } else {
             $paramsMessages = $this->_imapMail->getParamsMessages();
             $imapFlags = array();
             $imapUids = array();
             $imapSizes = array();
             if (!is_array($paramsMessages)) {
                 return $webMailMessageCollection;
             }
             foreach ($paramsMessages as $key => $value) {
                 $imapFlags[$key] = $value["flag"];
                 $imapUids[$key] = $value["uid"];
                 $imapSizes[$key] = $value["size"];
             }
             if (count($paramsMessages) < 1) {
                 $newcoll = new WebMailMessageCollection();
                 return $newcoll;
             }
             $msgCount = count($imapUids);
             $messageIndexSet = array();
             //$imapNFlags = $imapNSizes = array();
             for ($i = $msgCount - ($pageNumber - 1) * $this->Account->MailsPerPage; $i > $msgCount - $pageNumber * $this->Account->MailsPerPage; $i--) {
                 if ($i == 0) {
                     break;
                 }
                 $messageIndexSet[] = $imapUids[$i];
                 //$imapNFlags[$imapUids[$i]] = $imapFlags[$i];
                 //$imapNSizes[$imapUids[$i]] = $imapSizes[$i];
             }
             $webMailMessageCollection =& $this->LoadMessageHeadersInOneRequest($folder, $messageIndexSet, true);
         }
     }
     return $webMailMessageCollection;
 }
$email_accounts[4] = array("user" => "etel", "pass" => "po4rl3ph", "type" => "General Sales", "category" => 6, "gw_ID" => 3);
$log = "Searching for new emails...\n";
echo 'working...';
foreach ($email_accounts as $account) {
    $imap = new IMAPMAIL();
    if (!$imap->open("mail.etelegate.com", "143")) {
        $log .= $imap->get_error();
        print $log;
        continue;
    }
    $log .= "-Logging in as " . $account['user'] . "...\n";
    $imap->login($account['user'], $account['pass']);
    $log .= $imap->error;
    $response = $imap->open_mailbox("INBOX");
    $log .= $imap->error;
    $emailList = $imap->search_mailbox("UNSEEN SINCE " . date("d-M-Y", time() - 24 * 60 * 60));
    if (is_array($emailList)) {
        $log .= " Found " . sizeof($emailList) . " emails...\n";
        foreach ($emailList as $emailId) {
            echo '.';
            flush();
            $category = $account['type'];
            $log .= " Checking Email #{$emailId}...\n";
            $response = $imap->fetch_mail($emailId, "BODY[HEADER.FIELDS (SUBJECT FROM TO DATE)]");
            //print $response."<BR>";
            $response_ar = explode("\n", $response);
            $emailInfo = array();
            foreach ($response_ar as $line) {
                $line = str_replace($remove_array, "", $line);
                if (substr($line, 0, strlen("From: ")) == "From: ") {
                    $emailInfo['From'] = trim(quote_smart(substr($line, strlen("From: "))));