/**
  * @param Message $message
  *
  * @return mixed
  */
 public function newEmail(Message $message)
 {
     $date = new \DateTime();
     $date->setTimeStamp($message->getDate());
     echo 'Subject : ' . $message->getSubject() . "\n";
     echo 'Uid     : ' . $message->getUid() . "\n";
     echo 'Date    : ' . $date->format('Y/m/d H:i:s') . "\n";
 }
 /**
  * @param Message $message
  *
  * @return Purchase[]
  */
 protected function parseData(Message $message)
 {
     $dom = new \DOMDocument();
     $dom->loadHTML($message->getMessageBody(true));
     $nodes = $dom->getElementsByTagName('p');
     $purchase = new Purchase\Purchase();
     $purchase->date = new Date();
     $purchase->place = 'Pagamento';
     $matches = [];
     preg_match('/no valor de R\\$ (.*)/', $nodes->item(2)->nodeValue, $matches);
     $purchase->amount = (new Currency($matches[1]))->getValue();
     return [$purchase];
 }
 /**
  * @param Message $message
  *
  * @return Purchase[]
  */
 protected function parseData(Message $message)
 {
     $dom = new \DOMDocument();
     $dom->loadHTML($message->getMessageBody(true));
     $nodes = $dom->getElementsByTagName('p');
     $purchase = new Purchase\Purchase();
     $matches = [];
     preg_match('/((?:(?:[0-2]?\\d{1})|(?:[3][01]{1}))[-:\\/.](?:[0]?[1-9]|[1][012])[-:\\/.](?:(?:[1]{1}\\d{1}\\d{1}\\d{1})|(?:[2]{1}\\d{3})))(?![\\d])/', $nodes->item(2)->nodeValue, $matches);
     $purchase->date = new Date(join('-', array_reverse(explode('/', $matches[1]))));
     preg_match('/local: (.*?),/', str_replace('.', ',', str_replace("\n", ' ', $nodes->item(2)->nodeValue)), $matches);
     $purchase->place = trim($matches[1]);
     preg_match('/R\\$ (.*), no dia/', $nodes->item(2)->nodeValue, $matches);
     $purchase->amount = (new Currency($matches[1]))->getValue();
     return [$purchase];
 }
 /**
  * @param Message $message
  *
  * @return Purchase[]
  */
 protected function parseData(Message $message)
 {
     $dom = new \DOMDocument();
     $dom->loadHTML($message->getMessageBody(true));
     $nodes = $dom->getElementsByTagName('tr');
     $data = array();
     for ($i = 5; $i <= $nodes->length; $i++) {
         if (strstr($nodes->item($i)->nodeValue, 'R$')) {
             $date = $nodes->item($i)->childNodes->item(0)->nodeValue;
             $date = new \DateTime(trim($date));
             $place = $nodes->item($i)->childNodes->item(1)->nodeValue;
             $amount = $nodes->item($i)->childNodes->item(2)->nodeValue;
             $purchase = new \shina\controlmybudget\Purchase\Purchase();
             $purchase->date = $date;
             $purchase->place = trim($place);
             $purchase->amount = (double) str_replace('R$', '', str_replace(',', '.', str_replace('.', '', trim($amount))));
             $data[] = $purchase;
         } else {
             break;
         }
     }
     return $data;
 }
Beispiel #5
0
 public function testGetImapBox()
 {
     $server = ServerTest::getServer();
     $message = new \Fetch\Message('3', $server);
     $this->assertEquals($server, $message->getImapBox(), 'getImapBox returns Server used to create Message.');
 }
Beispiel #6
0
 public function testTypeIdToString()
 {
     $types = array();
     $types[0] = 'text';
     $types[1] = 'multipart';
     $types[2] = 'message';
     $types[3] = 'application';
     $types[4] = 'audio';
     $types[5] = 'image';
     $types[6] = 'video';
     $types[7] = 'other';
     $types[8] = 'other';
     $types[32] = 'other';
     foreach ($types as $id => $type) {
         $this->assertEquals($type, Message::typeIdToString($id));
     }
 }
 private function createItem(Message $message)
 {
     $item = new Item();
     $item->title(utf8_encode($message->getSubject()))->description(utf8_encode($message->getMessageBody()))->url($this->url . $message->getUid() . '.html')->pubDate($message->getDate())->guid($message->getUid())->appendTo($this->channel);
     file_put_contents($this->dir . '/' . $message->getUid() . '.html', $message->getMessageBody(true));
 }
Beispiel #8
0
 public function testCharsetConvert()
 {
     $this->assertSame('Привет', Message::charsetConvert(implode(array_map('chr', [0xf0, 0xd2, 0xc9, 0xd7, 0xc5, 0xd4])), 'koi8-r', 'utf-8'));
     $this->assertSame('test', Message::charsetConvert('test', 'unk1', 'unk1'), 'Same charsets not try converting');
     $this->assertSame('', Message::charsetConvert('', 'unk1', 'unk1'), 'Empty text not try converting');
     $this->assertSame(null, Message::charsetConvert('test', 'unk1', 'utf-8'), 'Null when source charset is unknown');
     $this->assertSame(null, Message::charsetConvert('test', 'utf-8', 'unk1'), 'Null when destination charset is unknown');
 }