Commit a41f7564 authored by Sebastian Kummer's avatar Sebastian Kummer

Merge pull request #473 in ZP/z-push from...

Merge pull request #473 in ZP/z-push from bugfix/ZP-1159-sendmail-with-attachments-uses-too to develop

* commit '6c76315d':
  ZP-1159 Unset $start & $end to free memory immediately.
  ZP-1159 Improve memory consumption when sending emails with attachments.
parents 0a92884b 6c76315d
......@@ -441,8 +441,25 @@ class BackendKopano implements IBackend, ISearchProvider {
if (preg_match("/^X-Push-Sender:\s(.*?)$/im", $sm->mime, $senderEmail)) {
$sendAsEmail = trim($senderEmail[1]);
ZLog::Write(LOGLEVEL_DEBUG, sprintf("KopanoBackend->SendMail(): Send-As '%s' requested by KOE", $sendAsEmail));
$sm->mime = preg_replace("/^From: .*?$/im", "From: ". $sendAsEmail, $sm->mime, 1);
$sendingAsSomeone = true;
$originalFrom = array();
if (preg_match("/^(From:\s.*?)$/im", $sm->mime, $originalFrom)) {
// find the occurence of the From header and replace it
// preg_replace() uses additional 3x the length of $sm->mime to perform,
// mb_ereg_replace() requires only 1x addtional memory, but replaces ALL occurences.
// The below is different than concatenating in one line and also only uses 1x additional memory
$fromPosition = strpos($sm->mime, $originalFrom[1]);
$start = substr($sm->mime, 0, $fromPosition);
$end = substr($sm->mime, $fromPosition + strlen($originalFrom[1]));
$sm->mime = $start;
$sm->mime .= "From: ". $sendAsEmail;
$sm->mime .= $end;
unset($start, $end);
$sendingAsSomeone = true;
}
else {
ZLog::Write(LOGLEVEL_DEBUG, "KopanoBackend->SendMail(): Could not find FROM header to replace for send-as");
}
}
// serverside Send-As - shared folder with DeviceManager::FLD_FLAGS_REPLYASUSER flag
elseif (isset($sm->source->folderid)) {
......@@ -462,10 +479,6 @@ class BackendKopano implements IBackend, ISearchProvider {
}
}
// by splitting the message in several lines we can easily grep later
foreach(preg_split("/((\r)?\n)/", $sm->mime) as $rfc822line)
ZLog::Write(LOGLEVEL_WBXML, "RFC822: ". $rfc822line);
$sendMailProps = MAPIMapping::GetSendMailProperties();
$sendMailProps = getPropIdsFromStrings($this->defaultstore, $sendMailProps);
......
......@@ -316,7 +316,18 @@ class WBXMLDecoder extends WBXMLDefs {
ZLog::Write(LOGLEVEL_WBXML,"I " . $spaces . "</" . $tag . ">");
break;
case EN_TYPE_CONTENT:
ZLog::Write(LOGLEVEL_WBXML,"I " . $spaces . " " . $el[EN_CONTENT]);
// as we concatenate the string here, the entire content is copied.
// when sending an email with an attachment this single log line (which is never logged in INFO)
// requires easily additional 20 MB of RAM. See https://jira.z-hub.io/browse/ZP-1159
$messagesize = strlen($el[EN_CONTENT]);
if ($messagesize > 10240) {
$content = substr($el[EN_CONTENT], 0, 10240) . sprintf(" <log message with %d bytes truncated>", $messagesize);
}
else {
$content = $el[EN_CONTENT];
}
// Log but make sure it's not truncated again (will be slightly bigger than 10KB)
ZLog::Write(LOGLEVEL_WBXML,"I " . $spaces . " " . $content, false);
break;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment