Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
odi-um committed Jul 17, 2015
2 parents 931da37 + 9830227 commit 9e7404e
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 6 deletions.
26 changes: 26 additions & 0 deletions Infrastructure/Message/Zend/AbstractMessageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace Diamante\EmailProcessingBundle\Infrastructure\Message\Zend;

use Diamante\EmailProcessingBundle\Model\Message\MessageSender;
use Diamante\EmailProcessingBundle\Model\Message\MessageRecipient;

abstract class AbstractMessageProvider
{
Expand Down Expand Up @@ -55,6 +56,31 @@ public function processTo($headers)
return $messageTo;
}

/**
* @param $headers
* @return string
*/
public function processRecipients($headers)
{
$processAddressTypes = ['to', 'cc', 'from'];
$recipients = [];

foreach ($processAddressTypes as $type) {
if (!$headers->get($type)) {
continue;
}
/**
* @var string $email
* @var \Zend\Mail\Address $address
*/
foreach ($headers->get($type)->getAddressList() as $email => $address) {
$recipients[] = new MessageRecipient($address->getEmail(), null);
}
}

return $recipients;
}

/**
* Retrieves Message Reference
*
Expand Down
3 changes: 2 additions & 1 deletion Infrastructure/Message/Zend/ImapMessageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ public function fetchMessagesToProcess()
$messageReference = $this->processMessageReference($headers);
$messageAttachments = $this->processAttachments($imapMessage);
$isFailed = $this->isFailed($headers);
$recipients = $this->processRecipients($headers);

$messages[] = new Message($uniqueMessageId, $messageId, $messageSubject, $messageContent,
$messageFrom, $messageTo, $messageReference, $messageAttachments, $isFailed);
$messageFrom, $messageTo, $messageReference, $messageAttachments, $isFailed, $recipients);
}
} catch (\Exception $e) {
throw new MessageProcessingException($e->getMessage());
Expand Down
3 changes: 2 additions & 1 deletion Infrastructure/Message/Zend/RawMessageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ public function fetchMessagesToProcess()
$messageTo = $this->processTo($headers);
$messageReference = $this->processMessageReference($headers);
$messageAttachments = $this->processAttachments($zendMailMessage);
$recipients = $this->processRecipients($headers);

$message = new Message($uniqueMessageId, $messageId, $messageSubject, $messageContent,
$messageFrom, $messageTo, $messageReference, $messageAttachments);
$messageFrom, $messageTo, $messageReference, $messageAttachments, $recipients);
return array($message);
}

Expand Down
40 changes: 38 additions & 2 deletions Model/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ class Message
*/
private $to;

/**
* @var array
*/
private $recipients;

/**
* @var array
*/
Expand All @@ -74,6 +79,7 @@ class Message
* @param null $reference
* @param array $attachments
* @param bool $isFailed
* @param array $recipients
*/
public function __construct(
$uniqueId,
Expand All @@ -84,7 +90,8 @@ public function __construct(
$to,
$reference = null,
array $attachments = null,
$isFailed = false
$isFailed = false,
$recipients = null
) {
$this->uniqueId = $uniqueId;
$this->messageId = $messageId;
Expand All @@ -95,6 +102,7 @@ public function __construct(
$this->reference = $reference;
$this->attachments = $attachments;
$this->isFailed = $isFailed;
$this->recipients = $recipients;
}

/**
Expand Down Expand Up @@ -176,4 +184,32 @@ public function isFailed()
{
return $this->isFailed;
}
}

/**
* Retrieve emails of recipients
*
* @return array|null
*/
public function getRecipients()
{
return $this->recipients;
}

/**
* Add recipient/recipients to the message
*
* @param $recipients
*/
public function addRecipients($recipients)
{
if (!is_array($recipients)) {
$recipients = [$recipients];
}

foreach ($recipients as $recipient) {
$this->recipients[] = $recipient;
}

$this->recipients = array_unique($this->recipients);
}
}
27 changes: 27 additions & 0 deletions Model/Message/MessageRecipient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/*
* Copyright (c) 2014 Eltrino LLC (http://eltrino.com)
*
* Licensed under the Open Software License (OSL 3.0).
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://opensource.org/licenses/osl-3.0.php
*
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@eltrino.com so we can send you a copy immediately.
*/

namespace Diamante\EmailProcessingBundle\Model\Message;

class MessageRecipient extends MessageSender
{
public function __construct($email, $name)
{
if (!$name) {
$name = strstr($email, '@', true);
}
parent::__construct($email, $name);
}
}
5 changes: 3 additions & 2 deletions Model/Message/MessageSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function __construct($email, $name)
protected function parseName($name)
{
if (!empty($name)) {
$name = trim($name, "\"");
$name = $this->canonicalizeName($name);

if (strpos($name," ")) {
Expand All @@ -59,8 +60,8 @@ protected function parseName($name)
$lastName = "";
}

$this->firstName = $firstName;
$this->lastName = $lastName;
$this->firstName = ucfirst($firstName);
$this->lastName = ucfirst($lastName);
}
}

Expand Down

0 comments on commit 9e7404e

Please sign in to comment.