/** * @param $randomTemplate * @param User $owner * @param Contact $contact * @param EmailOrigin $origin * * @return EmailUser */ protected function addEmailUser($randomTemplate, $owner, $contact, $origin) { $emailUser = $this->emailEntityBuilder->emailUser($this->templates[$randomTemplate]['Subject'], $owner->getEmail(), $contact->getPrimaryEmail()->getEmail(), new \DateTime('now'), new \DateTime('now'), new \DateTime('now')); $this->setSecurityContext($owner); $emailUser->setFolder($origin->getFolder(FolderType::SENT)); $emailUser->setOwner($owner); $emailUser->setOrganization($owner->getOrganization()); $emailBody = $this->emailEntityBuilder->body("Hi,\n" . $this->templates[$randomTemplate]['Text'], false, true); $emailUser->getEmail()->setEmailBody($emailBody); $emailUser->getEmail()->setMessageId(sprintf('<id.%s@%s', uniqid(), '@bap.migration.generated>')); return $emailUser; }
/** * Get origin's folder * * @param string $email * @param EmailOrigin $origin * @return EmailFolder */ protected function getFolder($email, EmailOrigin $origin) { $folder = $origin->getFolder(FolderType::SENT); //In case when 'useremailorigin' origin doesn't have folder, get folder from internal origin if (!$folder && $origin instanceof UserEmailOrigin) { $originKey = InternalEmailOrigin::BAP . $email; if (array_key_exists($originKey, $this->origins)) { unset($this->origins[$originKey]); } $origin = $this->getEmailOrigin($email, null, InternalEmailOrigin::BAP, false); return $origin->getFolder(FolderType::SENT); } return $folder; }