public function testArrayUniqueRecursive() { $array = array('testValue1', 'testValue2', 'testValue3'); $expected = array('testValue1', 'testValue2', 'testValue3'); $this->assertEquals($expected, ArrayUtil::arrayUniqueRecursive($array)); $array = array('testValue1', 'testValue2', 'testValue2'); $expected = array('testValue1', 'testValue2'); $this->assertEquals($expected, ArrayUtil::arrayUniqueRecursive($array)); $array = array('testValue1', 'testValue1', 'testValue1'); $expected = array('testValue1'); $this->assertEquals($expected, ArrayUtil::arrayUniqueRecursive($array)); $array = array(array('testKey1' => 'testValue1', 'testKey2' => 'testValue2', 'testKey3' => 'textValue3')); $expected = array(array('testKey1' => 'testValue1', 'testKey2' => 'testValue2', 'testKey3' => 'textValue3')); $this->assertEquals($expected, ArrayUtil::arrayUniqueRecursive($array)); $array = array(array('testKey1' => 'testValue1', 'testKey2' => 'testValue1', 'testKey3' => 'textValue3')); $expected = array(array('testKey1' => 'testValue1', 'testKey3' => 'textValue3')); $this->assertEquals($expected, ArrayUtil::arrayUniqueRecursive($array)); }
/** * Get recipient details from email message. * Have to cover two cases: when message is CC-ed or BCC-ed to dropbox, * and when email message is forwarded to dropbox. * 1. If message is CC-ed or BCC-ed to dropbox, recipients can be exctracted from "To" field of email message * 2. If message is forwarded, then email from which message is forwarded to dropbox is recipient * @param ImapMessage $emailMessage * @param array $emailRecipient */ public static function resolveEmailRecipientsFromEmailMessage(ImapMessage $emailMessage) { // Check if email is forwarded or not. if (self::isMessageForwarded($emailMessage)) { // Somebody sent email to Zurmo user, the user forwarded it to dropbox, so the user is a recipient $emailRecipients = array(array('email' => $emailMessage->fromEmail, 'name' => $emailMessage->fromName, 'type' => EmailMessageRecipient::TYPE_TO)); } else { $emailRecipients = array(); // Zurmo user sent email, so recipients are in 'To' and 'CC' fields if (!empty($emailMessage->to)) { foreach ($emailMessage->to as $key => $value) { $emailMessage->to[$key]['type'] = EmailMessageRecipient::TYPE_TO; if ($value['email'] == Yii::app()->imap->imapUsername) { unset($emailMessage->to[$key]); } } $emailRecipients = array_merge($emailRecipients, $emailMessage->to); } if (!empty($emailMessage->cc)) { foreach ($emailMessage->cc as $key => $value) { $emailMessage->cc[$key]['type'] = EmailMessageRecipient::TYPE_CC; if ($value['email'] == Yii::app()->imap->imapUsername) { unset($emailMessage->cc[$key]); } } $emailRecipients = array_merge($emailRecipients, $emailMessage->cc); } } if (count($emailRecipients) == 0) { throw new NotSupportedException(); } $emailRecipients = ArrayUtil::arrayUniqueRecursive($emailRecipients); //After removing duplicates email get removed if its the same as name foreach ($emailRecipients as $key => $emailRecipient) { if (!isset($emailRecipient['email'])) { $emailRecipients[$key]['email'] = $emailRecipient['name']; } } return $emailRecipients; }
public static function arrayUniqueRecursive($array) { $result = array_map("unserialize", array_unique(array_map("serialize", $array))); foreach ($result as $key => $value) { if (is_array($value)) { $result[$key] = ArrayUtil::arrayUniqueRecursive($value); } } return $result; }
/** * Get recipient details from email message. * Have to cover two cases: when message is CC-ed or BCC-ed to dropbox, * and when email message is forwarded to dropbox. * 1. If message is CC-ed or BCC-ed to dropbox, recipients can be exctracted from "To" field of email message * 2. If message is forwarded, then email from which message is forwarded to dropbox is recipient * @param ImapMessage $emailMessage * @param array $emailRecipient */ public static function resolveEmailRecipientsFromEmailMessage(ImapMessage $emailMessage) { // Check if email is forwarded or not. if (self::isMessageForwarded($emailMessage)) { // Somebody sent email to Zurmo user, the user forwarded it to dropbox, so the user is a recipient $emailRecipients = array(array('email' => $emailMessage->fromEmail, 'name' => $emailMessage->fromName, 'type' => EmailMessageRecipient::TYPE_TO)); } else { // Zurmo user sent email, so recipients are in 'To' and 'CC' fields foreach ($emailMessage->to as $key => $value) { $emailMessage->to[$key]['type'] = EmailMessageRecipient::TYPE_TO; if ($value['email'] == Yii::app()->imap->imapUsername) { unset($emailMessage->to[$key]); } } $emailRecipients = $emailMessage->to; if (!empty($emailMessage->cc)) { foreach ($emailMessage->cc as $key => $value) { $emailMessage->cc[$key]['type'] = EmailMessageRecipient::TYPE_CC; if ($value['email'] == Yii::app()->imap->imapUsername) { unset($emailMessage->cc[$key]); } } $emailRecipients = ArrayUtil::arrayUniqueRecursive(array_merge($emailRecipients, $emailMessage->cc)); } } return $emailRecipients; }