public function testOnlyToSendSomeEmails() { $messages = $this->imap->getMessages(); foreach ($messages as $message) { $message->delete(); } $this->sendMockMails(); }
/** * Test mailbox creation. */ public function testCreateMailBox() { $imap = $this->getMock('Fetch\\Imap', array('open', 'createMailbox')); $imap->expects($this->once())->method('createMailbox')->with($this->anything(), $this->equalTo('{imap.example.com:143/novalidate-cert}mailbox')); $server = new Server('imap.example.com'); $server->setImap($imap); $server->createMailBox('mailbox'); }
/** * @dataProvider flagsDataProvider * @param string $expected server string with %host% placeholder * @param integer $port to use (needed to test behavior on port 143 and 993 from constructor) * @param array $flags to set/unset ($flag => $value) */ public function testFlags($expected, $port, $flags) { $host = 'example.com'; $server = new Server($host, $port); foreach ($flags as $flag => $value) { $server->setFlag($flag, $value); } $this->assertEquals(str_replace('%host%', $host, $expected), $server->getServerString()); }
public function testFilledFeed() { $time = time(); $messages = array($this->createMessage('message1', 'Eerste bericht', 1, $time), $this->createMessage('message2', 'Tweede bericht', 2, $time), $this->createMessage('message3', 'Derde bericht', 3, $time)); $this->server->expects($this->any())->method('search')->will($this->returnValue($messages)); $this->obj->createFeed('/tmp', 'feed.xml', 'http://www.example.com', 3); $files = array('feed.xml', '1.html', '2.html', '3.html'); foreach ($files as $file) { $this->assertFileEquals(__DIR__ . '/' . $file, '/tmp/' . $file); @unlink('/tmp/' . $file); } }
/** * This function is used to move a mail to the given mailbox. * * @param $mailbox * * @return bool */ public function moveToMailBox($mailbox) { $currentBox = $this->imapConnection->getMailBox(); $this->imapConnection->setMailBox($this->mailbox); $returnValue = imap_mail_copy($this->imapStream, $this->uid, $mailbox, CP_UID | CP_MOVE); imap_expunge($this->imapStream); $this->mailbox = $mailbox; $this->imapConnection->setMailBox($currentBox); return $returnValue; }
protected function execute(InputInterface $input, OutputInterface $output) { $dir = $input->getOption('dir'); $limit = '- ' . $input->getOption('limit') . ' day'; if (!is_dir($dir)) { throw new RuntimeException('Dir does not exist'); } $url = rtrim($input->getOption('url'), '/') . '/'; $filename = $input->getOption('filename'); $feedFile = $dir . '/' . $filename; $server = new Server($input->getOption('hostname'), $input->getOption('port'), $input->getOption('type')); $server->setAuthentication($input->getOption('username'), $input->getOption('password')); $feed = new Feed(); $channel = new Channel(); $channel->title($input->getOption('title'))->description($input->getOption('description'))->url($url . $filename)->appendTo($feed); $generator = new EmailFeedGenerator($server, $feed, $channel); $generator->createFeed($dir, $filename, $url, $limit); $output->writeln('Succesfully generated ' . $feedFile); }
/** * 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; }
public function import() { $imap = new Server($this->server, $this->port); $imap->setAuthentication($this->username, $this->password); $imap->setMailBox($this->mailbox); $dataProvider = new DataProvider(); $purchaseService = new PurchaseService($dataProvider); $user_service = new UserService($dataProvider, new Client()); $user = $user_service->getById($this->backend_users_id); $importer = new ImporterService(); $importer->addImporter(new MailItauCardImport($imap, $purchaseService)); $importer->addImporter(new MailItauDebitImport($imap, $purchaseService)); $importer->addImporter(new MailItauWithdrawImport($imap, $purchaseService)); $importer->addImporter(new MailItauUniclassDebitImport($imap, $purchaseService)); if ($this->is_first_time) { $importer->import(null, $user); $this->is_first_time = false; $this->save(); } else { $importer->import(10, $user); } }
/** * @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; } } } }
/** * @throws ParameterException */ public function init() { $this->checkConfiguration(); $this->initCalled = true; if ($this->fetchServer === null) { $this->fetchServer = $this->createServer($this->server, $this->port); $this->fetchServer->setAuthentication($this->email, $this->password); } $serverCustom = new ServerCustom($this->fetchServer); if ($this->filename) { $this->lastUidPersist = new LastUidPersistFile($this->filename); } $this->processor = new Processor($serverCustom, $this->newEmailWatcher, $this->lastUidPersist); }
public static function getServer() { $server = new Server(TESTING_SERVER_HOST, 143); $server->setAuthentication(TEST_USER, TEST_PASSWORD); return $server; }
/** * @codeCoverageIgnore */ public function setImapStream() { parent::setImapStream(); }