diff --git a/application/Espo/Core/Mail/Importer.php b/application/Espo/Core/Mail/Importer.php index f1fc23c672..681d226f1b 100644 --- a/application/Espo/Core/Mail/Importer.php +++ b/application/Espo/Core/Mail/Importer.php @@ -18,7 +18,7 @@ class Importer return $this->entityManager; } - protected function importMessage($message, $userId, $teamsIds = array()) + public function importMessage($message, $userId, $teamsIds = array()) { try { $email = $this->getEntityManager()->getEntity('Email'); @@ -82,9 +82,9 @@ class Importer protected function checkIsDuplicate($email) { - if ($email->has('messageIdInternal')) { + if ($email->get('messageIdInternal')) { $duplicate = $this->getEntityManager()->getRepository('Email')->where(array( - 'messageIdInternal' => $email->has('messageIdInternal') + 'messageIdInternal' => $email->get('messageIdInternal') ))->findOne(); if ($duplicate) { return true; diff --git a/application/Espo/Modules/Crm/Services/InboundEmail.php b/application/Espo/Modules/Crm/Services/InboundEmail.php index 307f3392e3..1357758724 100644 --- a/application/Espo/Modules/Crm/Services/InboundEmail.php +++ b/application/Espo/Modules/Crm/Services/InboundEmail.php @@ -183,7 +183,7 @@ class InboundEmail extends \Espo\Services\Record } } - if ($k == self::PORTION - 1) { + if ($k == self::PORTION_LIMIT - 1) { break; } $k++; diff --git a/application/Espo/Resources/metadata/entityDefs/Email.json b/application/Espo/Resources/metadata/entityDefs/Email.json index fca4e16760..c6eac7e5d6 100644 --- a/application/Espo/Resources/metadata/entityDefs/Email.json +++ b/application/Espo/Resources/metadata/entityDefs/Email.json @@ -54,12 +54,12 @@ }, "messageId": { "type": "varchar", - "maxLength": 36, + "maxLength": 255, "readOlny": true }, "messageIdInternal": { "type": "varchar", - "maxLength": 36, + "maxLength": 300, "readOlny": true, "index": true }, diff --git a/application/Espo/Services/EmailAccount.php b/application/Espo/Services/EmailAccount.php index 807c1dc14c..8708b549ab 100644 --- a/application/Espo/Services/EmailAccount.php +++ b/application/Espo/Services/EmailAccount.php @@ -133,9 +133,9 @@ class EmailAccount extends Record $ids = $storage->getIdsFromUID(); - print_r($ids); + $k = 0; - foreach ($ids as $k => $id) { + foreach ($ids as $i => $id) { $message = $storage->getMessage($id); $importer->importMessage($message, $userId, array($teamId)); @@ -144,19 +144,18 @@ class EmailAccount extends Record $lastUID = $storage->getUniqueId($id); $lastDate = $message->date; } - if ($k == self::PORTION - 1) { + + if ($k == self::PORTION_LIMIT - 1) { break; } + $k++; } $fetchData['lastUID'][$folder] = $lastUID; $fetchData['lastDate'][$folder] = $lastDate; $emailAccount->set('fetchData', json_encode($fetchData)); - $this->getEntityManager()->saveEntity($emailAccount); - - print_r($fetchData); - + $this->getEntityManager()->saveEntity($emailAccount); } return true;