diff --git a/lib/kolab_sync_data_email.php b/lib/kolab_sync_data_email.php --- a/lib/kolab_sync_data_email.php +++ b/lib/kolab_sync_data_email.php @@ -50,6 +50,8 @@ 'to' => 'to', ); + static $memory_accumulated = 0; + /** * Special folder type/name map * @@ -288,6 +290,7 @@ else if ($airSyncBaseType == Syncroton_Command_Sync::BODY_TYPE_MIME) { // Check if we have enough memory to handle the message $messageBody = $this->message_mem_check($message, $headers->size); + static::$memory_accumulated += $headers->size; if (empty($messageBody)) { $messageBody = $this->storage->get_raw_body($message->uid); @@ -1661,6 +1664,14 @@ } } + + private function mem_check($need) + { + $mem_limit = parse_bytes(ini_get('memory_limit')); + $memory = static::$memory_accumulated; + return $mem_limit > 0 && $memory + $need > $mem_limit ? false : true; + } + /** * Checks if the message can be processed, depending on its size and * memory_limit, otherwise throws an exception or returns fake body. @@ -1675,7 +1686,7 @@ // as streams). It also happens when parsing the plain/html text body // in getMessagePartBody() though the footprint there is probably lower. - if (!rcube_utils::mem_check($size * 5)) { + if (!$this->mem_check($size * 5)) { // If we already rised the memory we throw an exception, so the message // will be synchronized in the next run (then we might have enough memory) if ($memory_rised) { @@ -1693,7 +1704,7 @@ if (ini_set('memory_limit', $memory_needed) !== false) { // Memory has been rised, check again - if (rcube_utils::mem_check($size * 5)) { + if ($this->mem_check($size * 5)) { return; } }