Commit 1ed4aeb9 authored by Sebastian Kummer's avatar Sebastian Kummer

ZP-843 Fixed warnings if there is no stream (property empty).

Released under the Affero GNU General Public License (AGPL) version 3.
parent 3b7ea727
......@@ -2378,15 +2378,20 @@ class MAPIProvider {
}
$stream = mapi_openproperty($mapimessage, $property, IID_IStream, 0, 0);
$stat = mapi_stream_stat($stream);
$streamsize = $stat['cb'];
if ($stream) {
$stat = mapi_stream_stat($stream);
$streamsize = $stat['cb'];
}
else {
$streamsize = 0;
}
//set the properties according to supported AS version
if (Request::GetProtocolVersion() >= 12.0) {
$message->asbody = new SyncBaseBody();
$message->asbody->type = $bpReturnType;
if ($bpReturnType == SYNC_BODYPREFERENCE_RTF) {
$body = mapi_stream_read($stream, $streamsize);
$body = $this->mapiReadStream($stream, $streamsize);
$message->asbody->data = StringStreamWrapper::Open(base64_encode($body));
}
elseif (isset($message->internetcpid) && $bpReturnType == SYNC_BODYPREFERENCE_HTML) {
......@@ -2395,7 +2400,7 @@ class MAPIProvider {
$message->asbody->data = MAPIStreamWrapper::Open($stream);
}
else {
$body = mapi_stream_read($stream, $streamsize);
$body = $this->mapiReadStream($stream, $streamsize);
$message->asbody->data = StringStreamWrapper::Open(Utils::ConvertCodepageStringToUtf8($message->internetcpid, $body));
}
}
......@@ -2405,7 +2410,7 @@ class MAPIProvider {
$message->asbody->estimatedDataSize = $streamsize;
}
else {
$body = mapi_stream_read($stream, $streamsize);
$body = $this->mapiReadStream($stream, $streamsize);
$message->body = str_replace("\n","\r\n", w2u(str_replace("\r", "", $body)));
$message->bodysize = $streamsize;
$message->bodytruncated = 0;
......@@ -2414,6 +2419,22 @@ class MAPIProvider {
return true;
}
/**
* Reads from a mapi stream, if it's set. If not, returns an empty string.
*
* @param resource $stream
* @param int $size
*
* @access private
* @return string
*/
private function mapiReadStream($stream, $size) {
if (!$stream || $size == 0) {
return "";
}
return mapi_stream_read($stream, $streamsize);
}
/**
* A wrapper for mapi_inetmapi_imtoinet function
*
......
......@@ -75,8 +75,13 @@ class MAPIStreamWrapper {
$this->mapistream = $contextOptions[self::PROTOCOL]['stream'];
// get the data length from mapi
$stat = mapi_stream_stat($this->mapistream);
$this->streamlength = $stat["cb"];
if ($this->mapistream) {
$stat = mapi_stream_stat($this->mapistream);
$this->streamlength = $stat["cb"];
}
else {
$this->streamlength = 0;
}
ZLog::Write(LOGLEVEL_DEBUG, sprintf("MAPIStreamWrapper::stream_open(): initialized mapistream: %s streamlength: %d", $this->mapistream, $this->streamlength));
......@@ -97,7 +102,12 @@ class MAPIStreamWrapper {
// read 4 additional bytes from the stream so we can always truncate correctly
if ($this->toTruncate)
$len += 4;
$data = mapi_stream_read($this->mapistream, $len);
if ($this->mapistream) {
$data = mapi_stream_read($this->mapistream, $len);
}
else {
$data = "";
}
$this->position += strlen($data);
// we need to truncate UTF8 compatible if ftruncate() was called
......
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