Ejemplo n.º 1
0
 /**
  *  get db object by record
  *  @param  row
  *  @return TahScan object
  */
 public function mapRow($row)
 {
     $object = new Inbox();
     $object->setId($row['id']);
     $object->setParentId($row['parent_id']);
     $object->setFromEmail($row['from_email']);
     $object->setToEmail($row['to_email']);
     $object->setFromName($row['from_name']);
     $object->setToName($row['to_name']);
     $object->setSubject($row['subject']);
     $object->setBodySnippet($row['body_snippet']);
     $object->setEmailCreateTime(strtotime($row['email_create_time']));
     $object->setMessageId($row['message_id']);
     $object->setReferenceMessageIds($row['reference_message_ids']);
     $object->setProperties(unserialize($row['properties']));
     return $object;
 }
Ejemplo n.º 2
0
 /**
  *
  */
 private function makeInbox($info)
 {
     $heads = \Ydin\ArrayKit\Dot::factory($info['headers']);
     if (false !== strstr($heads('from'), '<')) {
         // has name
         $fromName = strip_tags($heads('from'));
         $fromEmail = trim(strstr($heads('from'), '<'), '<>');
     } else {
         $fromName = '';
         $fromEmail = $heads('from');
     }
     if (false !== strstr($heads('to'), '<')) {
         // has name
         $toName = strip_tags($heads('to'));
         $toEmail = trim(strstr($heads('to'), '<'), '<>');
     } else {
         $toName = '';
         $toEmail = $heads('to');
     }
     $inbox = new \Inbox();
     $inbox->setMessageId($heads('message-id'));
     $inbox->setReferenceMessageIds($heads('references'));
     $inbox->setFromEmail($fromEmail);
     $inbox->setToEmail($toEmail);
     $inbox->setFromName($fromName);
     $inbox->setToName($toName);
     $inbox->setSubject($heads('subject'));
     $date = $this->timezoneConvert($heads('date'), 'UTC', conf('app.timezone'));
     $inbox->setEmailCreateTime(strtotime($date));
     $inbox->setProperty('googleMessageId', $info['googleMessageId']);
     $inbox->setProperty('headers', $info['headers']);
     $inbox->setProperty('data', $info['data']);
     if ($info['body']) {
         $inbox->setBodySnippet($info['body']);
     }
     /*
     foreach ($info['data'] as $item) {
         if ( 'text/plain' === $item['mimeType'] && isset($item['content']) ) {
             $inbox->setBodySnippet($item['content']);
         }
     }
     */
     $referenceMessageIds = $inbox->getReferenceMessageIds();
     if (!$referenceMessageIds) {
         $parentId = 0;
     } else {
         $tmp = explode(" ", $referenceMessageIds);
         $firstReferenceMessageId = $tmp[0];
         $inboxes = new \Inboxes();
         $theInbox = $inboxes->getInboxByMessageId($firstReferenceMessageId);
         if ($theInbox) {
             $parentId = $theInbox->getId();
         } else {
             // 找不到 message id, 這可能是一個大問題
             // 但也有可能只是一個小問題 -> 新信件 比 舊信件 先被匯入
             // 之後需要想辦法重新串起來
             $parentId = -1;
         }
     }
     $inbox->setParentId($parentId);
     return $inbox;
 }