fetch only header for emails w/ exceeding size
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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."
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user