Changeset View
Changeset View
Standalone View
Standalone View
lib/kolab_sync_data_email.php
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | protected $mapping = array( | ||||
//'messageClass' => 'messageclass', | //'messageClass' => 'messageclass', | ||||
'replyTo' => 'replyto', | 'replyTo' => 'replyto', | ||||
//'read' => 'read', | //'read' => 'read', | ||||
'subject' => 'subject', | 'subject' => 'subject', | ||||
//'threadTopic' => 'threadtopic', | //'threadTopic' => 'threadtopic', | ||||
'to' => 'to', | 'to' => 'to', | ||||
); | ); | ||||
static $memory_accumulated = 0; | |||||
/** | /** | ||||
* Special folder type/name map | * Special folder type/name map | ||||
* | * | ||||
* @var array | * @var array | ||||
*/ | */ | ||||
protected $folder_types = array( | protected $folder_types = array( | ||||
2 => 'Inbox', | 2 => 'Inbox', | ||||
3 => 'Drafts', | 3 => 'Drafts', | ||||
▲ Show 20 Lines • Show All 222 Lines • ▼ Show 20 Lines | // $result['ConversationIndex'] = 'CA2CFA8A23'; | ||||
$real_length = $headers->size; | $real_length = $headers->size; | ||||
$truncateAt = 0; | $truncateAt = 0; | ||||
$body_length = 0; | $body_length = 0; | ||||
$isTruncated = 1; | $isTruncated = 1; | ||||
} | } | ||||
else if ($airSyncBaseType == Syncroton_Command_Sync::BODY_TYPE_MIME) { | else if ($airSyncBaseType == Syncroton_Command_Sync::BODY_TYPE_MIME) { | ||||
// Check if we have enough memory to handle the message | // Check if we have enough memory to handle the message | ||||
$messageBody = $this->message_mem_check($message, $headers->size); | $messageBody = $this->message_mem_check($message, $headers->size); | ||||
static::$memory_accumulated += $headers->size; | |||||
if (empty($messageBody)) { | if (empty($messageBody)) { | ||||
$messageBody = $this->storage->get_raw_body($message->uid); | $messageBody = $this->storage->get_raw_body($message->uid); | ||||
} | } | ||||
// make the source safe (Bug #2715, #2757) | // make the source safe (Bug #2715, #2757) | ||||
$messageBody = kolab_sync_message::recode_message($messageBody); | $messageBody = kolab_sync_message::recode_message($messageBody); | ||||
▲ Show 20 Lines • Show All 1,357 Lines • ▼ Show 20 Lines | public function get_invitation_event($messageId) | ||||
foreach ($ical_objects as $mime_id => $event) { | foreach ($ical_objects as $mime_id => $event) { | ||||
if ($event['_type'] == 'event') { | if ($event['_type'] == 'event') { | ||||
return $event; | return $event; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
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 | * Checks if the message can be processed, depending on its size and | ||||
* memory_limit, otherwise throws an exception or returns fake body. | * memory_limit, otherwise throws an exception or returns fake body. | ||||
*/ | */ | ||||
protected function message_mem_check($message, $size, $result = null) | protected function message_mem_check($message, $size, $result = null) | ||||
{ | { | ||||
static $memory_rised; | static $memory_rised; | ||||
// @FIXME: we need up to 5x more memory than the body | // @FIXME: we need up to 5x more memory than the body | ||||
// Note: Biggest memory multiplication happens in recode_message() | // Note: Biggest memory multiplication happens in recode_message() | ||||
// and the Syncroton engine (which also does not support passing bodies | // and the Syncroton engine (which also does not support passing bodies | ||||
// as streams). It also happens when parsing the plain/html text body | // as streams). It also happens when parsing the plain/html text body | ||||
// in getMessagePartBody() though the footprint there is probably lower. | // 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 | // 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) | // will be synchronized in the next run (then we might have enough memory) | ||||
if ($memory_rised) { | if ($memory_rised) { | ||||
throw new Syncroton_Exception_MemoryExhausted; | throw new Syncroton_Exception_MemoryExhausted; | ||||
} | } | ||||
$memory_rised = true; | $memory_rised = true; | ||||
$memory_max = 512; // maximum in MB | $memory_max = 512; // maximum in MB | ||||
$memory_limit = round(parse_bytes(ini_get('memory_limit')) / 1024 / 1024); // current limit (in MB) | $memory_limit = round(parse_bytes(ini_get('memory_limit')) / 1024 / 1024); // current limit (in MB) | ||||
$memory_add = round($size * 5 / 1024 / 1024); // how much we need (in MB) | $memory_add = round($size * 5 / 1024 / 1024); // how much we need (in MB) | ||||
$memory_needed = min($memory_limit + $memory_add, $memory_max) . "M"; | $memory_needed = min($memory_limit + $memory_add, $memory_max) . "M"; | ||||
if ($memory_limit < $memory_max) { | if ($memory_limit < $memory_max) { | ||||
$this->logger->debug("Setting memory_limit=$memory_needed"); | $this->logger->debug("Setting memory_limit=$memory_needed"); | ||||
if (ini_set('memory_limit', $memory_needed) !== false) { | if (ini_set('memory_limit', $memory_needed) !== false) { | ||||
// Memory has been rised, check again | // Memory has been rised, check again | ||||
if (rcube_utils::mem_check($size * 5)) { | if ($this->mem_check($size * 5)) { | ||||
return; | return; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
$this->logger->warn("Not enough memory. Using fake email body."); | $this->logger->warn("Not enough memory. Using fake email body."); | ||||
if ($result !== null) { | if ($result !== null) { | ||||
Show All 19 Lines |