Skip to content

Commit

Permalink
bcmath is not a default installed PHP extension, so can't assume it i…
Browse files Browse the repository at this point in the history
…s available
  • Loading branch information
slusarz committed Jan 8, 2014
1 parent ddeaee3 commit de06253
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 deletions.
20 changes: 16 additions & 4 deletions framework/Compress/lib/Horde/Compress/Tnef.php
Expand Up @@ -362,10 +362,18 @@ protected function _extractMapiAttributes($data, &$attachment_data)
break;
case self::MAPI_APPOINTMENT_START_WHOLE:
file_put_contents('/tmp/filetime', $value);
$attachment_data[0]['start_utc'] = new Horde_Date(Horde_Mapi::filetimeToUnixtime($value), 'UTC');
try {
$attachment_data[0]['start_utc'] = new Horde_Date(Horde_Mapi::filetimeToUnixtime($value), 'UTC');
} catch (Horde_Mapi_Exception $e) {
throw new Horde_Compress_Exception($e);
}
break;
case self::MAPI_APPOINTMENT_END_WHOLE:
$attachment_data[0]['end_utc'] = new Horde_Date(Horde_Mapi::filetimeToUnixtime($value), 'UTC');
try {
$attachment_data[0]['end_utc'] = new Horde_Date(Horde_Mapi::filetimeToUnixtime($value), 'UTC');
} catch (Horde_Mapi_Exception $e) {
throw new Horde_Compress_Exception($e);
}
break;
case self::MAPI_APPOINTMENT_DURATION:
$attachment_data[0]['duration'] = $value;
Expand Down Expand Up @@ -628,8 +636,12 @@ protected function _parseRecurrence($value)
}

// What Timezone are these in?
$startDate = new Horde_Date(Horde_Mapi::filetimeToUnixtime($this->_geti($value, 32)));
$endDate = new Horde_Date(Horde_Mapi::filetimeToUnixtime($this->_geti($value, 32)));
try {
$startDate = new Horde_Date(Horde_Mapi::filetimeToUnixtime($this->_geti($value, 32)));
$endDate = new Horde_Date(Horde_Mapi::filetimeToUnixtime($this->_geti($value, 32)));
} catch (Horde_Mapi_Exception $e) {
throw new Horde_Compress_Exception($e);
}

$rrule = new Horde_Date_Recurrence($startDate);
switch ($pattern) {
Expand Down
10 changes: 9 additions & 1 deletion framework/Compress/test/Horde/Compress/TnefTest.php
Expand Up @@ -18,7 +18,15 @@ public function testMeetingInvitation()
{
$tnef = Horde_Compress::factory('Tnef');
$data = base64_decode(file_get_contents(__DIR__ . '/fixtures/TnefMeetingRequest.txt'));
$tnef_data = $tnef->decompress($data);
try {
$tnef_data = $tnef->decompress($data);
} catch (Horde_Compress_Exception $e) {
if (($prev = $e->getPrevious()) &&
($prev instanceof Horde_Mapi_Exception)) {
$this->markTestSkipped();
}
throw $e;
}
$this->assertEquals($tnef_data[0]['type'], 'text');
$this->assertEquals($tnef_data[0]['subtype'], 'calendar');
$this->assertEquals($tnef_data[0]['name'], 'Meeting');
Expand Down
11 changes: 10 additions & 1 deletion framework/Mapi/lib/Horde/Mapi.php
Expand Up @@ -141,6 +141,7 @@ static public function createGoid($uid, $options = array())
* MAPI property.
*
* @return integer The unix timestamp.
* @throws Horde_Mapi_Exception
*/
static public function filetimeToUnixtime($ft)
{
Expand Down Expand Up @@ -169,6 +170,10 @@ static protected function _flipEndian($str)
// convert hex string to BC-int
static protected function _hexToBcint($str)
{
if (!extension_loaded('bcmath')) {
throw new Horde_Mapi_Exception('bcmath extension not loaded.');
}

$hex = array(
'0'=>'0', '1'=>'1', '2'=>'2', '3'=>'3', '4'=>'4',
'5'=>'5', '6'=>'6', '7'=>'7', '8'=>'8', '9'=>'9',
Expand All @@ -190,11 +195,15 @@ static protected function _hexToBcint($str)

static protected function _win64ToUnix($bci)
{
if (!extension_loaded('bcmath')) {
throw new Horde_Mapi_Exception('bcmath extension not loaded.');
}

// Unix epoch as a Windows file date-time value
$magicnum = '116444735995904000';
$t = bcsub($bci, $magicnum); // Cast to Unix epoch
return bcdiv($t, '10000000', 0); // Convert from ticks to seconds
}


}
}
3 changes: 3 additions & 0 deletions framework/Mapi/package.xml
Expand Up @@ -72,6 +72,9 @@
<max>3.0.0alpha1</max>
<exclude>3.0.0alpha1</exclude>
</package>
<extension>
<name>bcmath</name>
</extension>
</required>
</dependencies>
<phprelease>
Expand Down
7 changes: 4 additions & 3 deletions framework/Mapi/test/Horde/Mapi/MapiTest.php
Expand Up @@ -21,11 +21,12 @@ class Horde_Mapi_MapiTest extends PHPUnit_Framework_TestCase

public function testFiletimeToUnixTime()
{
if (!extension_loaded('bcmath')) {
$data = file_get_contents(__DIR__ . '/fixtures/filetime');
try {
$this->assertEquals(Horde_Mapi::filetimeToUnixtime($data), 1387818000);
} catch (Horde_Mapi_Exception $e) {
$this->markTestSkipped("bcmath extension isn't loaded");
}
$data = file_get_contents(__DIR__ . '/fixtures/filetime');
$this->assertEquals(Horde_Mapi::filetimeToUnixtime($data), 1387818000);
}

/**
Expand Down

0 comments on commit de06253

Please sign in to comment.