Example #1
1
 /**
  * @param resource $imapConnection
  * @param array    $messages
  * @param bool     $clean
  *
  * @return bool Return <em>true</em> if <strong>all</strong> messages exist in the inbox.
  */
 public function checkMessages($imapConnection, array $messages, $clean = true)
 {
     $bodies = array_map(function ($message) {
         return $message->getText() . "\r\n";
     }, $messages);
     $host = $_ENV['AVISOTA_TEST_IMAP_HOST'] ?: getenv('AVISOTA_TEST_IMAP_HOST');
     $hits = 0;
     for ($i = 0; $i < 30 && $hits < count($bodies); $i++) {
         // wait for the mail server
         sleep(2);
         imap_gc($imapConnection, IMAP_GC_ENV);
         $status = imap_status($imapConnection, '{' . $host . '}', SA_MESSAGES);
         for ($j = $status->messages; $j > 0; $j--) {
             $body = imap_body($imapConnection, $j);
             if (in_array($body, $bodies)) {
                 $hits++;
                 if ($clean) {
                     imap_delete($imapConnection, $j);
                 }
             }
         }
         imap_expunge($imapConnection);
     }
     return $hits;
 }
Example #2
0
 /**
  * Disconnect from IMAP server
  *
  * @throws IMAP_Exception
  */
 public function disconnect()
 {
     if (function_exists('imap_gc')) {
         imap_gc($this->_getIMAPConnection(), IMAP_GC_ELT);
         imap_gc($this->_getIMAPConnection(), IMAP_GC_ENV);
         imap_gc($this->_getIMAPConnection(), IMAP_GC_TEXTS);
     }
     imap_close($this->_getIMAPConnection());
     $this->_checkErrors();
 }
Example #3
0
 public function clearCache()
 {
     if ($this->closed) {
         return true;
     }
     return imap_gc($this->resource, IMAP_GC_ELT | IMAP_GC_TEXTS | IMAP_GC_ENV);
 }
Example #4
0
<?php

echo "Checking with no parameters\n";
imap_gc();
echo "Checking with incorrect parameter type\n";
imap_gc('', false);
imap_gc(false, false);
require_once dirname(__FILE__) . '/imap_include.inc';
$stream_id = imap_open($default_mailbox, $username, $password) or die("Cannot connect to mailbox {$default_mailbox}: " . imap_last_error());
imap_gc($stream_id, -1);
Example #5
0
 public function clearCache()
 {
     imap_gc(IMAP_GC_ENV);
 }