/** * Associate emails with correct users */ private function _associateEmails($emails) { //Pull all IDS from #__people WHERE owner_id EQUALS current logged in user $people = UsersHelper::getPeopleEmails(); //If any emails match up with our TO then we automatically insert them as notes and store any attachments if (count($emails) > 0) { foreach ($emails as $email_key => $email) { $this->structure = $email['structure']; $address = $email['headers']->to[0]->mailbox . "@" . $email['headers']->to[0]->host; if ($key = array_search($address, $people)) { $data = array(); $data['note'] = $email['message']; $data['owner_id'] = UsersHelper::getUserId(); $data['person_id'] = $key; $model = new Note(); $model->store($data); $attachments = $this->getAttachments($email['overview']->msgno); if (count($attachments) > 0) { $email['attachments'] = $attachments; $this->_storeAttachments($email['attachments'], $key); } $this->_delete($email['overview']->msgno); unset($emails[$email_key]); } } } return $emails; }