Commit 98f0ab56 authored by Sebastian Kummer's avatar Sebastian Kummer

ZP-1065 Make MAPIUtils::GetError() public so it can used in other

places, remove duplicated getNativeBodyType and getError from
MAPIProvider - use the ones in MAPIUtils.

Released under the Affero GNU General Public License (AGPL) version 3.
parent 8f2565d4
...@@ -315,10 +315,10 @@ class MAPIProvider { ...@@ -315,10 +315,10 @@ class MAPIProvider {
} }
if (!isset($message->nativebodytype)) { if (!isset($message->nativebodytype)) {
$message->nativebodytype = $this->getNativeBodyType($messageprops); $message->nativebodytype = MAPIUtils::GetNativeBodyType($messageprops);
} }
elseif ($message->nativebodytype == SYNC_BODYPREFERENCE_UNDEFINED) { elseif ($message->nativebodytype == SYNC_BODYPREFERENCE_UNDEFINED) {
$nbt = $this->getNativeBodyType($messageprops); $nbt = MAPIUtils::GetNativeBodyType($messageprops);
ZLog::Write(LOGLEVEL_INFO, sprintf("MAPIProvider->getAppointment(): native body type is undefined. Set it to %d.", $nbt)); ZLog::Write(LOGLEVEL_INFO, sprintf("MAPIProvider->getAppointment(): native body type is undefined. Set it to %d.", $nbt));
$message->nativebodytype = $nbt; $message->nativebodytype = $nbt;
} }
...@@ -832,7 +832,7 @@ class MAPIProvider { ...@@ -832,7 +832,7 @@ class MAPIProvider {
if (!isset($message->internetcpid)) $message->internetcpid = (defined('STORE_INTERNET_CPID')) ? constant('STORE_INTERNET_CPID') : INTERNET_CPID_WINDOWS1252; if (!isset($message->internetcpid)) $message->internetcpid = (defined('STORE_INTERNET_CPID')) ? constant('STORE_INTERNET_CPID') : INTERNET_CPID_WINDOWS1252;
$this->setFlag($mapimessage, $message); $this->setFlag($mapimessage, $message);
if (!isset($message->contentclass)) $message->contentclass = DEFAULT_EMAIL_CONTENTCLASS; if (!isset($message->contentclass)) $message->contentclass = DEFAULT_EMAIL_CONTENTCLASS;
if (!isset($message->nativebodytype)) $message->nativebodytype = $this->getNativeBodyType($messageprops); if (!isset($message->nativebodytype)) $message->nativebodytype = MAPIUtils::GetNativeBodyType($messageprops);
// reply, reply to all, forward flags // reply, reply to all, forward flags
if (isset($message->lastverbexecuted) && $message->lastverbexecuted) { if (isset($message->lastverbexecuted) && $message->lastverbexecuted) {
...@@ -2598,107 +2598,6 @@ class MAPIProvider { ...@@ -2598,107 +2598,6 @@ class MAPIProvider {
} }
} }
/**
* Calculates the native body type of a message using available properties. Refer to oxbbody.
*
* @param array $messageprops
*
* @access private
* @return int
*/
private function getNativeBodyType($messageprops) {
//check if the properties are set and get the error code if needed
if (!isset($messageprops[PR_BODY])) $messageprops[PR_BODY] = $this->getError(PR_BODY, $messageprops);
if (!isset($messageprops[PR_RTF_COMPRESSED])) $messageprops[PR_RTF_COMPRESSED] = $this->getError(PR_RTF_COMPRESSED, $messageprops);
if (!isset($messageprops[PR_HTML])) $messageprops[PR_HTML] = $this->getError(PR_HTML, $messageprops);
if (!isset($messageprops[PR_RTF_IN_SYNC])) $messageprops[PR_RTF_IN_SYNC] = $this->getError(PR_RTF_IN_SYNC, $messageprops);
if ( // 1
($messageprops[PR_BODY] == MAPI_E_NOT_FOUND) &&
($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_FOUND) &&
($messageprops[PR_HTML] == MAPI_E_NOT_FOUND))
return SYNC_BODYPREFERENCE_PLAIN;
elseif ( // 2
($messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) &&
($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_FOUND) &&
($messageprops[PR_HTML] == MAPI_E_NOT_FOUND))
return SYNC_BODYPREFERENCE_PLAIN;
elseif ( // 3
($messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) &&
($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) &&
($messageprops[PR_HTML] == MAPI_E_NOT_FOUND))
return SYNC_BODYPREFERENCE_RTF;
elseif ( // 4
($messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) &&
($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) &&
($messageprops[PR_HTML] == MAPI_E_NOT_ENOUGH_MEMORY) &&
($messageprops[PR_RTF_IN_SYNC]))
return SYNC_BODYPREFERENCE_RTF;
elseif ( // 5
($messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) &&
($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) &&
($messageprops[PR_HTML] == MAPI_E_NOT_ENOUGH_MEMORY) &&
(!$messageprops[PR_RTF_IN_SYNC]))
return SYNC_BODYPREFERENCE_HTML;
elseif ( // 6
($messageprops[PR_RTF_COMPRESSED] != MAPI_E_NOT_FOUND || $messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) &&
($messageprops[PR_HTML] != MAPI_E_NOT_FOUND || $messageprops[PR_HTML] == MAPI_E_NOT_ENOUGH_MEMORY) &&
($messageprops[PR_RTF_IN_SYNC]))
return SYNC_BODYPREFERENCE_RTF;
elseif ( // 7
($messageprops[PR_RTF_COMPRESSED] != MAPI_E_NOT_FOUND || $messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) &&
($messageprops[PR_HTML] != MAPI_E_NOT_FOUND || $messageprops[PR_HTML] == MAPI_E_NOT_ENOUGH_MEMORY) &&
(!$messageprops[PR_RTF_IN_SYNC]))
return SYNC_BODYPREFERENCE_HTML;
elseif ( // 8
($messageprops[PR_BODY] != MAPI_E_NOT_FOUND || $messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) &&
($messageprops[PR_RTF_COMPRESSED] != MAPI_E_NOT_FOUND || $messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) &&
($messageprops[PR_RTF_IN_SYNC]))
return SYNC_BODYPREFERENCE_RTF;
elseif ( // 9.1
($messageprops[PR_BODY] != MAPI_E_NOT_FOUND || $messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) &&
($messageprops[PR_RTF_COMPRESSED] != MAPI_E_NOT_FOUND || $messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) &&
(!$messageprops[PR_RTF_IN_SYNC]))
return SYNC_BODYPREFERENCE_PLAIN;
elseif ( // 9.2
($messageprops[PR_RTF_COMPRESSED] != MAPI_E_NOT_FOUND || $messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) &&
($messageprops[PR_BODY] == MAPI_E_NOT_FOUND) &&
($messageprops[PR_HTML] == MAPI_E_NOT_FOUND))
return SYNC_BODYPREFERENCE_RTF;
elseif ( // 9.3
($messageprops[PR_BODY] != MAPI_E_NOT_FOUND || $messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) &&
($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_FOUND) &&
($messageprops[PR_HTML] == MAPI_E_NOT_FOUND))
return SYNC_BODYPREFERENCE_PLAIN;
elseif ( // 9.4
($messageprops[PR_HTML] != MAPI_E_NOT_FOUND || $messageprops[PR_HTML] == MAPI_E_NOT_ENOUGH_MEMORY) &&
($messageprops[PR_BODY] == MAPI_E_NOT_FOUND) &&
($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_FOUND))
return SYNC_BODYPREFERENCE_HTML;
else // 10
return SYNC_BODYPREFERENCE_PLAIN;
}
/**
* Returns the error code for a given property. Helper for getNativeBodyType function.
*
* @param int $tag
* @param array $messageprops
*
* @access private
* @return int (MAPI_ERROR_CODE)
*/
private function getError($tag, $messageprops) {
$prBodyError = mapi_prop_tag(PT_ERROR, mapi_prop_id($tag));
if(isset($messageprops[$prBodyError]) && mapi_is_error($messageprops[$prBodyError])) {
if($messageprops[$prBodyError] == MAPI_E_NOT_ENOUGH_MEMORY_32BIT ||
$messageprops[$prBodyError] == MAPI_E_NOT_ENOUGH_MEMORY_64BIT) {
return MAPI_E_NOT_ENOUGH_MEMORY;
}
}
return MAPI_E_NOT_FOUND;
}
/** /**
* Sets properties for an email message. * Sets properties for an email message.
* *
......
...@@ -472,10 +472,10 @@ class MAPIUtils { ...@@ -472,10 +472,10 @@ class MAPIUtils {
*/ */
public static function GetNativeBodyType($messageprops) { public static function GetNativeBodyType($messageprops) {
//check if the properties are set and get the error code if needed //check if the properties are set and get the error code if needed
if (!isset($messageprops[PR_BODY])) $messageprops[PR_BODY] = self::getError(PR_BODY, $messageprops); if (!isset($messageprops[PR_BODY])) $messageprops[PR_BODY] = self::GetError(PR_BODY, $messageprops);
if (!isset($messageprops[PR_RTF_COMPRESSED])) $messageprops[PR_RTF_COMPRESSED] = self::getError(PR_RTF_COMPRESSED, $messageprops); if (!isset($messageprops[PR_RTF_COMPRESSED])) $messageprops[PR_RTF_COMPRESSED] = self::GetError(PR_RTF_COMPRESSED, $messageprops);
if (!isset($messageprops[PR_HTML])) $messageprops[PR_HTML] = self::getError(PR_HTML, $messageprops); if (!isset($messageprops[PR_HTML])) $messageprops[PR_HTML] = self::GetError(PR_HTML, $messageprops);
if (!isset($messageprops[PR_RTF_IN_SYNC])) $messageprops[PR_RTF_IN_SYNC] = self::getError(PR_RTF_IN_SYNC, $messageprops); if (!isset($messageprops[PR_RTF_IN_SYNC])) $messageprops[PR_RTF_IN_SYNC] = self::GetError(PR_RTF_IN_SYNC, $messageprops);
if ( // 1 if ( // 1
($messageprops[PR_BODY] == MAPI_E_NOT_FOUND) && ($messageprops[PR_BODY] == MAPI_E_NOT_FOUND) &&
...@@ -544,15 +544,16 @@ class MAPIUtils { ...@@ -544,15 +544,16 @@ class MAPIUtils {
} }
/** /**
* Returns the error code for a given property. Helper for getNativeBodyType function. * Returns the error code for a given property.
* Helper for MAPIUtils::GetNativeBodyType() function but also used in other places.
* *
* @param int $tag * @param int $tag
* @param array $messageprops * @param array $messageprops
* *
* @access private * @access public
* @return int (MAPI_ERROR_CODE) * @return int (MAPI_ERROR_CODE)
*/ */
private static function getError($tag, $messageprops) { public static function GetError($tag, $messageprops) {
$prBodyError = mapi_prop_tag(PT_ERROR, mapi_prop_id($tag)); $prBodyError = mapi_prop_tag(PT_ERROR, mapi_prop_id($tag));
if(isset($messageprops[$prBodyError]) && mapi_is_error($messageprops[$prBodyError])) { if(isset($messageprops[$prBodyError]) && mapi_is_error($messageprops[$prBodyError])) {
if($messageprops[$prBodyError] == MAPI_E_NOT_ENOUGH_MEMORY_32BIT || if($messageprops[$prBodyError] == MAPI_E_NOT_ENOUGH_MEMORY_32BIT ||
......
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