/**
  * Tries to guess the account being used by comparing recipients
  * adresses with adresses found in the mail accounts configured for the
  * user. If the account could not be guessed, tdard mail account for
  * the user will be returned. If this was not successfull, null is returned.
  *
  * @param array $addressList
  *
  * @return null|\Conjoon\Data\Entity\Mail\MailAccountEntity
  */
 protected function guessAccountUsed(array $addressList)
 {
     $accounts = $this->accountService->getMailAccounts();
     $addresses = array();
     $matching = array();
     for ($i = 0, $len = count($accounts); $i < $len; $i++) {
         $add = $accounts[$i]->getAddress();
         $addresses[] = $add;
         $matching[$add] = $accounts[$i];
     }
     for ($i = 0, $len = count($addressList); $i < $len; $i++) {
         if (in_array($addressList[$i]['address'], $addresses)) {
             return $matching[$addressList[$i]['address']];
         }
     }
     return $this->accountService->getStandardMailAccount();
 }
Пример #2
0
 /**
  * @param string $cc
  * @param string $to
  * @param \Conjoon\Data\Entity\Mail\MailAccountEntity $usedAccount The mail account
  *        which is most likely used to answer to this message
  *
  * @return array
  */
 protected function buildCcAddressList(array $cc, array $to, \Conjoon\Data\Entity\Mail\MailAccountEntity $usedAccount = null)
 {
     if (!$this->replyAll) {
         return array();
     }
     $accounts = $this->accountService->getMailAccounts();
     $filterAddressList = array();
     for ($i = 0, $len = count($accounts); $i < $len; $i++) {
         if ($usedAccount && $usedAccount->getId() == $accounts[$i]->getId()) {
             $filterAddressList[] = $accounts[$i]->getAddress();
             break;
         }
     }
     $merge = array();
     for ($i = 0, $len = max(count($cc), count($to)); $i < $len; $i++) {
         if (isset($cc[$i]) && !in_array($cc[$i]['address'], $filterAddressList)) {
             $merge[] = $cc[$i];
         }
         if (isset($to[$i]) && !in_array($to[$i]['address'], $filterAddressList)) {
             $merge[] = $to[$i];
         }
     }
     return $merge;
 }