/** * get an instance of the class designed for objectId (based on it's template type) * @param int $objectId * @return object */ public static function getCustomClassByObjectId($objectId) { $type = Objects::getType($objectId); return Objects::getCustomClassByType($type, $objectId); }
$deleteMailIds = array(); foreach ($mailConf['cores'] as $coreName => $core) { if (empty($core['mails'])) { continue; } $_GET['core'] = $coreName; $_SERVER['SERVER_NAME'] = $coreName . '.casebox.org'; include $site_path . DIRECTORY_SEPARATOR . 'config.php'; include $site_path . DIRECTORY_SEPARATOR . 'lib/language.php'; $templateIds = Templates::getIdsByType('comment'); if (empty($templateIds)) { \CB\debug('receive comments cron: no comment template defined'); continue; } $templateId = array_shift($templateIds); $commentsObj = Objects::getCustomClassByType('comment'); foreach ($core['mails'] as $mail) { if (!Objects::idExists($mail['pid'])) { \CB\debug('receive comments cron: target id not found for mail "' . $mail['subject'] . '"'); continue; } $emailFrom = extractEmailFromText($mail['from']); // user email $emailTo = extractEmailFromText($mail['to']); // <*****@*****.**> $userId = DM\User::getIdByEmail($emailFrom); $_SESSION['user'] = array('id' => $userId); $data = array('id' => null, 'pid' => $mail['pid'], 'oid' => $userId, 'cid' => $userId, 'template_id' => $templateId, 'data' => array('_title' => removeContentExtraBlock($mail['content'], $emailFrom, $emailTo)), 'sys_data' => array('mailId' => $mail['id'])); try { $commentId = $commentsObj->create($data); //add attachments
/* end of get email date /**/ /* get contents and attachments */ $parts = getMailContentAndAtachment($mail); $content = null; $attachments = array(); foreach ($parts as $p) { //content, filename, content-type if (!$p['attachment'] && !$content) { $content = $p['content']; } else { $attachments[] = $p; } } /* end of get contents and attachments */ /* creating email object in corresponding case and adding attachments if any */ $obj = Objects::getCustomClassByType('email'); $objectId = $obj->create(array('pid' => $pid, 'user_id' => $user_id, 'name' => $subject, 'template_id' => $email_template_id, 'date' => $time, 'cid' => $user_id, 'data' => array('_title' => $subject, '_date_start' => $time, '_content' => $content, 'from' => $mail->from), 'sys_data' => array('old_id' => $mailbox->getUniqueId($k)))); if (!empty($attachments)) { saveObjectAttachments($objectId, $attachments); } /* end of creating email object in corresponding case and adding attachments if any */ $mailbox->setFlags($k, array(Zend\Mail\Storage::FLAG_SEEN)); $processed_ids[] = $mailbox->getUniqueId($k); /* keep alive each 10 messages*/ if ($i == 10) { $i = 0; $mailbox->noop(); // keep alive } /*end of keep alive each 10 messages*/ DB\dbQuery('UPDATE crons