Пример #1
0
 /**
  * Test opening connection.
  */
 public function testGetImapStream()
 {
     $imap = $this->getMock('Fetch\\Imap', array('open'));
     $imap->expects($this->once())->method('open')->with($this->equalTo('{imap.example.com:143/novalidate-cert}'), $this->equalTo('username'), $this->equalTo('password'), $this->equalTo(0), $this->equalTo(1), $this->equalTo(array()))->will($this->returnValue('SUCCESS'));
     $server = new Server('imap.example.com');
     $server->setImap($imap);
     $server->setAuthentication('username', 'password');
     $this->assertEquals('SUCCESS', $server->getImapStream());
 }
Пример #2
0
 /**
  * @dataProvider connectionDataProvider
  * @param integer $port    to use (needed to test behavior on port 143 and 993 from constructor)
  * @param array   $flags   to set/unset ($flag => $value)
  * @param string  $message Assertion message
  */
 public function testConnection($port, $flags, $message)
 {
     $server = new Server(TESTING_SERVER_HOST, $port);
     $server->setAuthentication(TEST_USER, TEST_PASSWORD);
     foreach ($flags as $flag => $value) {
         $server->setFlag($flag, $value);
     }
     $imapSteam = $server->getImapStream();
     $this->assertInternalType('resource', $imapSteam, $message);
 }
Пример #3
0
 /**
  * This constructor takes in the uid for the message and the Imap class representing the mailbox the
  * message should be opened from. This constructor should generally not be called directly, but rather retrieved
  * through the apprioriate Imap functions.
  *
  * @param int    $messageUniqueId
  * @param Server $mailbox
  */
 public function __construct($messageUniqueId, Server $connection)
 {
     $this->imapConnection = $connection;
     $this->mailbox = $connection->getMailBox();
     $this->uid = $messageUniqueId;
     $this->imapStream = $this->imapConnection->getImapStream();
     if ($this->loadMessage() !== true) {
         throw new \RuntimeException('Message with ID ' . $messageUniqueId . ' not found.');
     }
 }
Пример #4
0
 /**
  * Get message : max number of message and stop if find uid message
  *
  * @param int $uid
  * @param int $limit
  *
  * @return array
  */
 public function getMessageUntil($uid, $limit = 10)
 {
     $messages = array();
     $numMessages = $this->server->numMessages();
     if ($numMessages > $limit) {
         $numLimit = $numMessages - $limit;
     } else {
         $numLimit = 0;
     }
     $stream = $this->server->getImapStream();
     for ($i = $numMessages; $i > $numLimit; $i--) {
         $newUid = $this->getMessage($stream, $i);
         if ($newUid === $uid) {
             break;
         }
         $messages[] = $this->createMessage($newUid);
     }
     return $messages;
 }
 /**
  * @param int|null $limit
  * @param User $user
  */
 public function import($limit = 3, User $user)
 {
     // making the work of Fetch package
     $messages = imap_sort($this->imap->getImapStream(), SORTARRIVAL, 1, SE_UID, $this->getImapSearch($user));
     if ($limit != null) {
         $messages = array_slice($messages, 0, $limit);
     }
     foreach ($messages as &$message) {
         $message = new Message($message, $this->imap);
     }
     unset($message);
     foreach ($messages as $message) {
         $data = $this->parseData($message);
         foreach ($data as $purchase) {
             try {
                 $this->purchase_service->save($purchase, $user);
             } catch (\Exception $e) {
                 continue;
             }
         }
     }
 }
 public function tearDown()
 {
     $this->conn->close();
     imap_close($this->imap->getImapStream());
 }