/** * Sets the properties in a MAPI object according to an Sync object and a property mapping * * @param mixed $mapimessage * @param SyncObject $message * @param array $mapping * * @access private * @return */ private function setPropsInMAPI($mapimessage, $message, $mapping) { $mapiprops = $this->getPropIdsFromStrings($mapping); $unsetVars = $message->getUnsetVars(); $propsToDelete = array(); $propsToSet = array(); foreach ($mapiprops as $asprop => $mapiprop) { if (isset($message->{$asprop})) { // UTF8->windows1252.. this is ok for all numerical values if (mapi_prop_type($mapiprop) != PT_BINARY && mapi_prop_type($mapiprop) != PT_MV_BINARY) { if (is_array($message->{$asprop})) { $value = array_map("u2wi", $message->{$asprop}); } else { $value = u2wi($message->{$asprop}); } } else { $value = $message->{$asprop}; } // Make sure the php values are the correct type switch (mapi_prop_type($mapiprop)) { case PT_BINARY: case PT_STRING8: settype($value, "string"); break; case PT_BOOLEAN: settype($value, "boolean"); break; case PT_SYSTIME: case PT_LONG: settype($value, "integer"); break; } // decode base64 value if ($mapiprop == PR_RTF_COMPRESSED) { $value = base64_decode($value); if (strlen($value) == 0) { continue; } // PDA will sometimes give us an empty RTF, which we'll ignore. // Note that you can still remove notes because when you remove notes it gives // a valid compressed RTF with nothing in it. } // if an "empty array" is to be saved, it the mvprop should be deleted - fixes Mantis #468 if (is_array($value) && empty($value)) { $propsToDelete[] = $mapiprop; ZLog::Write(LOGLEVEL_DEBUG, sprintf("MAPIProvider->setPropsInMAPI(): Property '%s' to be deleted as it is an empty array", $asprop)); } else { // all properties will be set at once $propsToSet[$mapiprop] = $value; } } elseif (in_array($asprop, $unsetVars)) { $propsToDelete[] = $mapiprop; } } mapi_setprops($mapimessage, $propsToSet); if (mapi_last_hresult()) { Zlog::Write(LOGLEVEL_WARN, sprintf("Failed to set properties, trying to set them separately. Error code was:%x", mapi_last_hresult())); $this->setPropsIndividually($mapimessage, $propsToSet, $mapiprops); } mapi_deleteprops($mapimessage, $propsToDelete); //clean up unset($unsetVars, $propsToDelete); }