diff --git a/application/Espo/Core/Mail/Importer.php b/application/Espo/Core/Mail/Importer.php index 8f5acf0edb..b020dcdda0 100644 --- a/application/Espo/Core/Mail/Importer.php +++ b/application/Espo/Core/Mail/Importer.php @@ -71,7 +71,7 @@ class Importer return $this->filtersMatcher; } - public function importMessage($message, $assignedUserId = null, $teamsIdList = [], $userIdList = [], $filterList = []) + public function importMessage($message, $assignedUserId = null, $teamsIdList = [], $userIdList = [], $filterList = [], $fetchOnlyHeader = false) { try { $email = $this->getEntityManager()->getEntity('Email'); @@ -166,28 +166,33 @@ class Importer $inlineIds = array(); - if ($message->isMultipart()) { - foreach (new \RecursiveIteratorIterator($message) as $part) { - $this->importPartDataToEmail($email, $part, $inlineIds); + if (!$fetchOnlyHeader) { + if ($message->isMultipart()) { + foreach (new \RecursiveIteratorIterator($message) as $part) { + $this->importPartDataToEmail($email, $part, $inlineIds); + } + } else { + $this->importPartDataToEmail($email, $message, $inlineIds, 'text/plain'); + } + + if (!$email->get('body') && $email->get('bodyPlain')) { + $email->set('body', $email->get('bodyPlain')); + } + + $body = $email->get('body'); + if (!empty($body)) { + foreach ($inlineIds as $cid => $attachmentId) { + $body = str_replace('cid:' . $cid, '?entryPoint=attachment&id=' . $attachmentId, $body); + } + $email->set('body', $body); + } + + if ($this->getFiltersMatcher()->matchBody($email, $filterList)) { + return false; } } else { - $this->importPartDataToEmail($email, $message, $inlineIds, 'text/plain'); - } - - if (!$email->get('body') && $email->get('bodyPlain')) { - $email->set('body', $email->get('bodyPlain')); - } - - $body = $email->get('body'); - if (!empty($body)) { - foreach ($inlineIds as $cid => $attachmentId) { - $body = str_replace('cid:' . $cid, '?entryPoint=attachment&id=' . $attachmentId, $body); - } - $email->set('body', $body); - } - - if ($this->getFiltersMatcher()->matchBody($email, $filterList)) { - return false; + $email->set('body', '(Not fetched)'); + $email->set('isHtml', false); } $parentFound = false; diff --git a/application/Espo/Resources/i18n/en_US/Settings.json b/application/Espo/Resources/i18n/en_US/Settings.json index df35159a08..b3f895e75c 100644 --- a/application/Espo/Resources/i18n/en_US/Settings.json +++ b/application/Espo/Resources/i18n/en_US/Settings.json @@ -57,8 +57,8 @@ "userThemesDisabled": "Disable User Themes", "emailMessageMaxSize": "Email Max Size (Mb)", "massEmailMaxPerHourCount": "Max count of emails sent per hour", - "personalEmailMaxPortionSize": "Max email portion size for a personal account fetching", - "inboundEmailMaxPortionSize": "Max email portion size for a group account fetching", + "personalEmailMaxPortionSize": "Max email portion size for personal account fetching", + "inboundEmailMaxPortionSize": "Max email portion size for group account fetching", "maxEmailAccountCount": "Max count of personal email accounts per user", "authTokenLifetime": "Auth Token Lifetime (hours)", "authTokenMaxIdleTime": "Auth Token Max Idle Time (hours)", @@ -76,7 +76,7 @@ "recordsPerPageSmall": "Number of records initially displayed in relationship panels.", "outboundEmailIsShared": "Allow users to sent emails via this SMTP.", "followCreatedEntities": "Users will automatically follow records they created.", - "emailMessageMaxSize": "All inbound emails exceeding a specified size will be skipped.", + "emailMessageMaxSize": "All inbound emails exceeding a specified size will be fetched w/o body and attachments.", "authTokenLifetime": "Defines how long tokens can exist.\n0 - means no expiration.", "authTokenMaxIdleTime": "Defines how long since the last access tokens can exist.\n0 - means no expiration.", "userThemesDisabled": "If checked then users won't be able to select another theme." diff --git a/application/Espo/Services/EmailAccount.php b/application/Espo/Services/EmailAccount.php index c0d4bd3d1e..14145e2b0c 100644 --- a/application/Espo/Services/EmailAccount.php +++ b/application/Espo/Services/EmailAccount.php @@ -269,10 +269,10 @@ class EmailAccount extends Record $lastUID = $storage->getUniqueId($id); } + $fetchOnlyHeader = false; if ($maxSize) { if ($storage->getSize($id) > $maxSize * 1024 * 1024) { - $k++; - continue; + $fetchOnlyHeader = true; } } @@ -284,7 +284,7 @@ class EmailAccount extends Record $flags = $message->getFlags(); } try { - $email = $importer->importMessage($message, null, $teamIdList, [$userId], $filterCollection); + $email = $importer->importMessage($message, null, $teamIdList, [$userId], $filterCollection, $fetchOnlyHeader); } catch (\Exception $e) { $GLOBALS['log']->error('EmailAccount '.$emailAccount->id.' (Import Message): [' . $e->getCode() . '] ' .$e->getMessage()); } diff --git a/application/Espo/Services/InboundEmail.php b/application/Espo/Services/InboundEmail.php index 17e4337db2..0285b7e2ba 100644 --- a/application/Espo/Services/InboundEmail.php +++ b/application/Espo/Services/InboundEmail.php @@ -276,10 +276,10 @@ class InboundEmail extends \Espo\Services\Record $lastUID = $storage->getUniqueId($id); } + $fetchOnlyHeader = false; if ($maxSize) { if ($storage->getSize($id) > $maxSize * 1024 * 1024) { - $k++; - continue; + $fetchOnlyHeader = true; } } @@ -300,7 +300,7 @@ class InboundEmail extends \Espo\Services\Record } if (!$toSkip) { try { - $email = $importer->importMessage($message, $userId, $teamIdList, $userIdList, $filterCollection); + $email = $importer->importMessage($message, $userId, $teamIdList, $userIdList, $filterCollection, $fetchOnlyHeader); } catch (\Exception $e) { $GLOBALS['log']->error('InboundEmail '.$emailAccount->id.' (Import Message): [' . $e->getCode() . '] ' .$e->getMessage()); }