Beispiel #1
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testGettersAndSetters()
 {
     $message = $this->getMockBuilder('Oro\\Bundle\\ImapBundle\\Mail\\Storage\\Message')->disableOriginalConstructor()->getMock();
     $id = new ItemId('testId', 'testChangeKey');
     $sentAt = new \DateTime('now');
     $receivedAt = new \DateTime('now');
     $internalDate = new \DateTime('now');
     $flags = ["\\Test"];
     $obj = new Email($message);
     $obj->setId($id)->setSubject('testSubject')->setFrom('testFrom')->addToRecipient('testToRecipient')->addCcRecipient('testCcRecipient')->addBccRecipient('testBccRecipient')->setSentAt($sentAt)->setReceivedAt($receivedAt)->setInternalDate($internalDate)->setImportance(1)->setMessageId('testMessageId')->setMultiMessageId(['testMessageId1', 'testMessageId2'])->setXMessageId('testXMessageId')->setXThreadId('testXThreadId');
     $this->assertEquals($id, $obj->getId());
     $this->assertEquals('testSubject', $obj->getSubject());
     $this->assertEquals('testFrom', $obj->getFrom());
     $toRecipients = $obj->getToRecipients();
     $this->assertEquals('testToRecipient', $toRecipients[0]);
     $ccRecipients = $obj->getCcRecipients();
     $this->assertEquals('testCcRecipient', $ccRecipients[0]);
     $bccRecipients = $obj->getBccRecipients();
     $this->assertEquals('testBccRecipient', $bccRecipients[0]);
     $this->assertEquals($sentAt, $obj->getSentAt());
     $this->assertEquals($receivedAt, $obj->getReceivedAt());
     $this->assertEquals($internalDate, $obj->getInternalDate());
     $this->assertEquals(1, $obj->getImportance());
     $this->assertEquals('testMessageId', $obj->getMessageId());
     $this->assertEquals('testXMessageId', $obj->getXMessageId());
     $this->assertEquals('testXThreadId', $obj->getXThreadId());
     $this->assertCount(2, $obj->getMultiMessageId());
     $this->assertInternalType('array', $obj->getMultiMessageId());
     $srcBodyContent = $this->getMockBuilder('Oro\\Bundle\\ImapBundle\\Mail\\Storage\\Content')->disableOriginalConstructor()->getMock();
     $srcBody = $this->getMockBuilder('Oro\\Bundle\\ImapBundle\\Mail\\Storage\\Body')->disableOriginalConstructor()->getMock();
     $srcBody->expects($this->at(0))->method('getContent')->with($this->equalTo(Body::FORMAT_TEXT))->will($this->returnValue($srcBodyContent));
     $srcBodyContent->expects($this->once())->method('getDecodedContent')->will($this->returnValue('testContent'));
     $body = new EmailBody();
     $body->setContent('testContent')->setBodyIsText(true);
     $message->expects($this->once())->method('getBody')->will($this->returnValue($srcBody));
     $this->assertEquals($body, $obj->getBody());
     $message->expects($this->exactly(2))->method('getFlags')->will($this->returnValue($flags));
     $this->assertTrue($obj->hasFlag("\\Test"));
     $this->assertFalse($obj->hasFlag("\\Test2"));
     $srcAttachmentContent = $this->getMockBuilder('Oro\\Bundle\\ImapBundle\\Mail\\Storage\\Content')->disableOriginalConstructor()->getMock();
     $srcAttachmentFileName = $this->getMockBuilder('Oro\\Bundle\\ImapBundle\\Mail\\Storage\\Value')->disableOriginalConstructor()->getMock();
     $srcAttachment = $this->getMockBuilder('Oro\\Bundle\\ImapBundle\\Mail\\Storage\\Attachment')->disableOriginalConstructor()->getMock();
     $srcAttachment->expects($this->once())->method('getFileName')->will($this->returnValue($srcAttachmentFileName));
     $srcAttachment->expects($this->once())->method('getContent')->will($this->returnValue($srcAttachmentContent));
     $srcAttachmentFileName->expects($this->once())->method('getValue')->will($this->returnValue('fileName'));
     $srcAttachmentContent->expects($this->once())->method('getContent')->will($this->returnValue('content'));
     $srcAttachmentContent->expects($this->once())->method('getContentType')->will($this->returnValue('contentType'));
     $srcAttachmentContent->expects($this->once())->method('getContentTransferEncoding')->will($this->returnValue('contentTransferEncoding'));
     $attachment = new EmailAttachment();
     $attachment->setFileName('fileName')->setContent('content')->setContentType('contentType')->setContentTransferEncoding('contentTransferEncoding');
     $message->expects($this->once())->method('getAttachments')->will($this->returnValue(array($srcAttachment)));
     $attachments = $obj->getAttachments();
     $this->assertCount(1, $attachments);
     $this->assertEquals($attachment, $attachments[0]);
 }
Beispiel #2
0
 /**
  * Creates Email DTO for the given email message
  *
  * @param Message $msg
  *
  * @return Email
  */
 public function convertToEmail(Message $msg)
 {
     $headers = $msg->getHeaders();
     $email = new Email($msg);
     $email->setId(new ItemId(intval($headers->get('UID')->getFieldValue()), $this->connector->getUidValidity()))->setSubject($this->getString($headers, 'Subject'))->setFrom($this->getString($headers, 'From'))->setSentAt($this->getDateTime($headers, 'Date'))->setReceivedAt($this->getReceivedAt($headers))->setInternalDate($this->getDateTime($headers, 'InternalDate'))->setImportance($this->getImportance($headers))->setMessageId($this->getString($headers, 'Message-ID'))->setXMessageId($this->getString($headers, 'X-GM-MSG-ID'))->setXThreadId($this->getString($headers, 'X-GM-THR-ID'));
     foreach ($this->getRecipients($headers, 'To') as $val) {
         $email->addToRecipient($val);
     }
     foreach ($this->getRecipients($headers, 'Cc') as $val) {
         $email->addCcRecipient($val);
     }
     foreach ($this->getRecipients($headers, 'Bcc') as $val) {
         $email->addBccRecipient($val);
     }
     return $email;
 }
Beispiel #3
0
 /**
  * Creates Email DTO for the given email message
  *
  * @param Message $msg
  *
  * @return Email
  *
  * @throws \RuntimeException if the given message cannot be converted to {@see Email} object
  */
 public function convertToEmail(Message $msg)
 {
     $headers = $msg->getHeaders();
     $email = new Email($msg);
     try {
         $email->setId(new ItemId(intval($headers->get('UID')->getFieldValue()), $this->connector->getUidValidity()))->setSubject($this->getString($headers, 'Subject'))->setFrom($this->getString($headers, 'From'))->setSentAt($this->getDateTime($headers, 'Date'))->setReceivedAt($this->getReceivedAt($headers))->setInternalDate($this->getDateTime($headers, 'InternalDate'))->setImportance($this->getImportance($headers))->setRefs($this->getReferences($headers, 'References'))->setXMessageId($this->getString($headers, 'X-GM-MSG-ID'))->setXThreadId($this->getString($headers, 'X-GM-THR-ID'))->setMessageId($this->getMessageId($headers, 'Message-ID'))->setMultiMessageId($this->getMultiMessageId($headers, 'Message-ID'))->setAcceptLanguageHeader($this->getAcceptLanguageHeader($headers));
         foreach ($this->getRecipients($headers, 'To') as $val) {
             $email->addToRecipient($val);
         }
         foreach ($this->getRecipients($headers, 'Cc') as $val) {
             $email->addCcRecipient($val);
         }
         foreach ($this->getRecipients($headers, 'Bcc') as $val) {
             $email->addBccRecipient($val);
         }
         return $email;
     } catch (\Exception $e) {
         throw new \RuntimeException(sprintf('Cannot parse email message. Subject: %s. Error: %s', $email->getSubject(), $e->getMessage()), 0, $e);
     }
 }