Commit ca4b5ed9 authored by Sebastian Kummer's avatar Sebastian Kummer

Merge pull request #478 in ZP/z-push from develop to release/2.3

* commit 'fe2bcf98':
  ZP-1110 Add KOE_CAPABILITY_SIGNATURES configuration option (default true).
  ZP-1160 Check if the Representing_ENTRY_ID is set in the properties before accessing it.
  ZP-1159 Fix typo.
  ZP-1159 Add maxLength parameter to Request::GetInputAsBase64(), log 10KB in an WBXML exception case and 4KB in the happy case.
  ZP-1159 Unset $start & $end to free memory immediately.
  ZP-1159 Improve memory consumption when sending emails with attachments.
parents c6f5e8f0 fe2bcf98
......@@ -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);
......
......@@ -265,7 +265,7 @@ class MAPIProvider {
//set attendee's status and type if they're available and if we are the organizer
$storeprops = $this->GetStoreProps();
if (isset($row[PR_RECIPIENT_TRACKSTATUS]) && $messageprops[$appointmentprops["representingentryid"]] == $storeprops[PR_MAILBOX_OWNER_ENTRYID])
if (isset($row[PR_RECIPIENT_TRACKSTATUS]) && isset($messageprops[$appointmentprops["representingentryid"]]) && $messageprops[$appointmentprops["representingentryid"]] == $storeprops[PR_MAILBOX_OWNER_ENTRYID])
$attendee->attendeestatus = $row[PR_RECIPIENT_TRACKSTATUS];
if (isset($row[PR_RECIPIENT_TYPE]))
$attendee->attendeetype = $row[PR_RECIPIENT_TYPE];
......
......@@ -309,6 +309,8 @@
define('KOE_CAPABILITY_SENDAS', true);
// Secondary Contact folders (own and shared)
define('KOE_CAPABILITY_SECONDARYCONTACTS', true);
// Copy WebApp signature into KOE
define('KOE_CAPABILITY_SIGNATURES', true);
// To synchronize the GAB KOE, the GAB store and folderid need to be specified.
// Use the gab-sync script to generate this data. The name needs to
......
......@@ -691,12 +691,14 @@ class Request {
* With POST request (our case), you can open and read
* multiple times "php://input"
*
* @param int $maxLength max. length to be returned. Default: return all
*
* @access public
* @return string - base64 encoded wbxml
*/
public static function GetInputAsBase64() {
public static function GetInputAsBase64($maxLength = -1) {
$input = fopen('php://input', 'r');
$wbxml = base64_encode(stream_get_contents($input));
$wbxml = base64_encode(stream_get_contents($input, $maxLength));
fclose($input);
return $wbxml;
}
......
......@@ -112,13 +112,15 @@ abstract class RequestProcessor {
}
}
catch (Exception $ex) {
ZLog::Write(LOGLEVEL_FATAL, "WBXML debug data: " . Request::GetInputAsBase64(), false);
// Log 10 KB of the WBXML data
ZLog::Write(LOGLEVEL_FATAL, "WBXML 10K debug data: " . Request::GetInputAsBase64(10240), false);
throw $ex;
}
// also log WBXML in happy case
if (ZLog::IsWbxmlDebugEnabled()) {
ZLog::Write(LOGLEVEL_WBXML, "WBXML-IN : ". Request::GetInputAsBase64(), false);
// Log 4 KB in the happy case
ZLog::Write(LOGLEVEL_WBXML, "WBXML-IN : ". Request::GetInputAsBase64(4096), false);
}
}
......
......@@ -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