/** * Тест метода getParserBySubject * */ public function testGetParserBySubject() { // Создаем отправителя $source = new EmailSource(); $source->setName("test"); $source->setEmailList("*****@*****.**"); $source->save(); // Создаем правильный парсер $parser1 = new EmailParser(); $parser1->setEmailSourceId($source->getId()); $parser1->setName("parser1"); $parser1->setSubjectRegexp("описание операции \\(Снятие наличных\\/Платеж\\)"); $parser1->save(); // Создаем неправильный парсер $parser2 = new EmailParser(); $parser2->setEmailSourceId($source->getId()); $parser2->setName("parser2"); $parser2->setSubjectRegexp("это неправильный регексп"); $parser2->save(); $testParser = $source->getParserBySubject("fwd: описание операции (Снятие наличных/Платеж) xxx"); $this->assertModels($parser1, $testParser); }
/** * Тесты каскадов * */ public function testCascade() { $source = new EmailSource(); $source->setName('name'); $source->setEmailList('email'); $source->save(); $id = $source->getId(); $parser = new EmailParser(); $parser->setName('parser'); $parser->setEmailSourceId($id); $parser->setSubjectRegexp("subj"); $parser->save(); $parserId = $parser->getId(); $source->delete(); $findParser = Doctrine::getTable("EmailParser")->find($parserId); $this->assertEquals($findParser, null); }
/** * Распарсить email и получить массив данных * * @param mixed $forced_operation_id если установлен - id операции устанавливаемый в ручную * @return array|int в случае ошибки */ public function getData($forced_operation_id = false) { // Последние 4 цифры карты preg_match('/' . $this->_parser->getAccountRegexp() . '/im', $this->_mail, $matches); $lastFourDigits = isset($matches[1]) ? $matches[1] : false; // Сумма платежа preg_match('/' . $this->_parser->getTotalRegexp() . '/im', $this->_mail, $matches); $amount = isset($matches[1]) ? $matches[1] : false; // Вычищаем левые символы в сумме $amount = preg_replace("/[^\\d\\.]+/", "", $amount); // Детали операции preg_match('/' . $this->_parser->getDescriptionRegexp() . '/im', $this->_mail, $matches); if (isset($matches[0])) { unset($matches[0]); } $description = count($matches) ? implode(" ", $matches) : ""; // Направление движения средств (тип) $type = $this->_parser->getType() ? Operation::TYPE_PROFIT : Operation::TYPE_EXPENSE; $operationData = array('email' => $this->_to, 'amount' => (string) $amount, 'description' => trim($description), 'type' => (string) $type, 'account' => (string) $lastFourDigits, 'source' => substr($this->_parser->getEmailSource()->getName(), 0, 4) . $lastFourDigits, 'id' => $forced_operation_id ? $forced_operation_id : uniqid()); return $operationData; }
/** * Получить данные из текста письма */ public function testGetDataFromMailPart() { // Создаем отправителя $source = new EmailSource(); $source->setName($this->_source); $source->setEmailList("anytest@test.tst, " . $this->_from); $source->save(); $sourceId = $source->getId(); // Создаем парсер $parser = new EmailParser(); $parser->setEmailSourceId($sourceId); $parser->setName($this->_subject); $parser->setSubjectRegexp("описание операции \\(Снятие наличных\\/Платеж\\)"); $parser->setAccountRegexp("Номер карты: (\\d\\d\\d\\d)"); $parser->setTotalRegexp("списано средств: ([\\d\\.,]+) "); $parser->setDescriptionRegexp("Описание: (.+)"); $parser->setType($this->_type); $parser->save(); $email = new myCreateEmailImport($this->_getEmailData()); $email->addPart('qwerty'); $mailArray = myParseEmailImport::getEmailData((string) $email); $getEmail = new myParseEmailImport($mailArray['body'], $parser, $mailArray['to']); $this->assertEquals($this->_getParseData(), $getEmail->getData($this->_operationId)); // Проверим, работает ли регексп чистки суммы $this->_amount = '123,-400x.a00'; $parser->setTotalRegexp("списано средств: ([\\d\\.,a-zA-Z\\-]+) "); $parser->save(); $email = new myCreateEmailImport($this->_getEmailData()); $mailArray = myParseEmailImport::getEmailData((string) $email); $getEmail = new myParseEmailImport($mailArray['body'], $parser, $mailArray['to']); $data = $getEmail->getData($this->_operationId); $this->assertEquals('123400.00', $data['amount']); }
protected function parse($email) { parent::parse($email); $this->getSCFields(); }
/** * Создать отправителя и парсер * * @return EmailParser */ private function _createSourceAndParser() { // Создаем отправителя $source = new EmailSource(); $source->setName($this->_source); $source->setEmailList("anytest@test.tst, " . $this->_from); $source->save(); $sourceId = $source->getId(); // Создаем парсер $parser = new EmailParser(); $parser->setEmailSourceId($sourceId); $parser->setName($this->_subject); $parser->setSubjectRegexp("описание операции \\(Снятие наличных\\/Платеж\\)"); // MySQL regexp! $parser->setAccountRegexp("Номер карты: (\\d\\d\\d\\d)"); $parser->setTotalRegexp("списано средств: ([\\d\\.,]+) "); $parser->setDescriptionRegexp("Описание: (.+)"); $parser->setType($this->_type); $parser->save(); return $parser; }
/** * @return bool Whether or not an MX record exists for the * email address's host name. */ protected function checkDNS() { $mxRecordExists = checkdnsrr(trim($this->parser->getParsedDomainPart()), 'MX'); if (!$mxRecordExists) { $this->warnings[] = self::DNSWARN_NO_RECORD; $this->addTLDWarnings(); } return $mxRecordExists; }
public function configure() { $this->widgetSchema['type'] = new sfWidgetFormChoice(array('choices' => EmailParser::getTypeChoices())); $this->validatorSchema['description_regexp'] = new sfValidatorString(array('max_length' => 255, 'required' => false)); $this->widgetSchema['sample'] = new sfWidgetFormTextarea(); }
/** * @param string $text An email as text. * * @return Email */ public static function read($text) { $parser = new EmailParser(); return $parser->parse($text); }