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 if (!empty($mail['attachments'])) { saveObjectAttachments($commentId, $mail['attachments']); } } catch (Exception $e) { \CB\debug('Cannot create comment from ' . $mail['from'], $data); } $deleteMailIds[] = $mail['id']; } } if (!empty($mailConf['mailbox'])) { deleteMails($mailConf['mailbox'], $deleteMailIds); } // \CB\Solr\Client::runBackgroundCron(); } function processMails(&$mailServer) { $rez = '';
$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 SET last_action = CURRENT_TIMESTAMP WHERE cron_id = $1', $cron_id) or die('error updating crons last action'); }