From ced41f6e6b5694a8eae7d927fa920059cdc27b4b Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Mon, 26 Apr 2010 10:24:20 -0400 Subject: [PATCH] Update turba's activesync support to correctly deal with ghosted properties Unsupported fields on the device are no longer wiped in Turba during sync --- turba/lib/Api.php | 7 ++++ turba/lib/Driver.php | 107 ++++++++++++++++++++++++++------------------------- 2 files changed, 62 insertions(+), 52 deletions(-) diff --git a/turba/lib/Api.php b/turba/lib/Api.php index b62dce21c..11c27c34e 100644 --- a/turba/lib/Api.php +++ b/turba/lib/Api.php @@ -1069,6 +1069,13 @@ class Turba_Api extends Horde_Registry_Api break; case 'activesync': $content = $driver->fromASContact($content); + /* Must check for ghosted properties for activesync requests */ + foreach ($content as $attribute => $value) { + if ($attribute != '__key') { + $object->setValue($attribute, $value); + } + } + break; default: diff --git a/turba/lib/Driver.php b/turba/lib/Driver.php index 22c6abfaa..071c695a4 100644 --- a/turba/lib/Driver.php +++ b/turba/lib/Driver.php @@ -2435,81 +2435,84 @@ class Turba_Driver $charset = Horde_Nls::getCharset(); $formattedname = false; - /* Name */ - $hash['name'] = Horde_String::convertCharset($message->fileas, 'utf-8', $charset); - $hash['lastname'] = Horde_String::convertCharset($message->lastname, 'utf-8', $charset); - $hash['firstname'] = Horde_String::convertCharset($message->firstname, 'utf-8', $charset); - $hash['middlenames'] = Horde_String::convertCharset($message->middlename, 'utf-8', $charset); - $hash['namePrefix'] = Horde_String::convertCharset($message->title, 'utf-8', $charset); - $hash['nameSuffix'] = Horde_String::convertCharset($message->suffix, 'utf-8', $charset); + $textMap = array( + 'fileas' => 'name', + 'lastname' => 'lastname', + 'firstname' => 'firstname', + 'middlename' => 'middlenames', + 'title' => 'namePrefix', + 'suffix' => 'nameSuffix', + 'homestreet' => 'homeStreet', + 'homecity' => 'homeCity', + 'homestate' => 'homeProvince', + 'homepostalcode' => 'homePostalCode', + 'homecountry' => 'homeCountry', + 'businessstreet' => 'workStreet', + 'businesscity' => 'workCity', + 'businessstate' => 'workProvince', + 'businesspostalcode' => 'workPostalCode', + 'businesscountry' => 'workCountry', + 'jobtitle' => 'title', + 'companyname' => 'company', + 'department' => 'department', + 'spouse' => 'spouse', + 'body' => 'notes', + 'webpage' => 'website', + 'assistantname' => 'assistant' + ); + foreach ($textMap as $asField => $turbaField) { + if (!$message->isGhosted($asField)) { + $hash[$turbaField] = Horde_String::convertCharset($message->{$asField}, 'utf-8', $charset); + } + } - // picture ($message->picture *should* already be base64 encdoed) - $hash['photo'] = base64_decode($message->picture); - - /* Home */ - $hash['homeStreet'] = Horde_String::convertCharset($message->homestreet, 'utf-8', $charset); - $hash['homeCity'] = Horde_String::convertCharset($message->homecity, 'utf-8', $charset); - $hash['homeProvince'] = Horde_String::convertCharset($message->homestate, 'utf-8', $charset); - $hash['homePostalCode'] = $message->homepostalcode; - $hash['homeCountry'] = Horde_String::convertCharset($message->homecountry, 'utf-8', $charset); - - /* Business */ - $hash['workStreet'] = Horde_String::convertCharset($message->businessstreet, 'utf-8', $charset); - $hash['workCity'] = Horde_String::convertCharset($message->businesscity, 'utf-8', $charset); - $hash['workProvince'] = Horde_String::convertCharset($message->businessstate, 'utf-8', $charset); - $hash['workPostalCode'] = $message->businesspostalcode; - $hash['workCountry'] = Horde_String::convertCharset($message->businesscountry, 'utf-8', $charset); - - $hash['homePhone'] = $message->homephonenumber; - $hash['workPhone'] = $message->businessphonenumber; - $hash['fax'] = $message->businessfaxnumber; - $hash['pager'] = $message->pagernumber; - $hash['cellPhone'] = $message->mobilephonenumber; + $nonTextMap = array( + 'homephonenumber' => 'homePhone', + 'businessphonenumber' => 'workPhone', + 'businessfaxnumber' => 'fax', + 'pagernumber' => 'pager', + 'mobilephonenumber' => 'cellPhone' + ); + foreach ($nonTextMap as $asField => $turbaField) { + if (!$message->isGhosted($asField)) { + $hash[$turbaField] = $message->{$asField}; + } + } - /* Email addresses */ - $hash['email'] = Horde_iCalendar_vcard::getBareEmail($message->email1address); + /* Requires special handling */ - /* Job title */ - $hash['title'] = Horde_String::convertCharset($message->jobtitle, 'utf-8', $charset); + // picture ($message->picture *should* already be base64 encdoed) + if (!$message->isGhosted('picture')) { + $hash['photo'] = base64_decode($message->picture); + } - $hash['company'] = Horde_String::convertCharset($message->companyname, 'utf-8', $charset); - $hash['department'] = Horde_String::convertCharset($message->department, 'utf-8', $charset); + /* Email addresses */ + if (!$message->isGhosted('email1address')) { + $hash['email'] = Horde_iCalendar_vcard::getBareEmail($message->email1address); + } /* Categories */ if (count($message->categories)) { $hash['category']['value'] = Horde_String::convertCharset(implode(';', $message->categories), 'utf-8', $charset); $hash['category']['new'] = true; + } elseif (!$message->isGhosted('categories')) { + $hash['category']['value'] = ''; } - /* Children */ - // @TODO - - /* Spouse */ - $hash['spouse'] = Horde_String::convertCharset($message->spouse, 'utf-8', $charset); - - /* Notes */ - $hash['notes'] = Horde_String::convertCharset($message->body, 'utf-8', $charset); - - /* webpage */ - $hash['website'] = Horde_String::convertCharset($message->webpage, 'utf-8', $charset); - /* Birthday and Anniversary */ if (!empty($message->birthday)) { $bday = new Horde_Date($message->birthday); $hash['birthday'] = $bday->format('Y-m-d'); - } else { + } elseif (!$message->isGhosted('birthday')) { $hash['birthday'] = null; } if (!empty($message->anniversary)) { $anniversary = new Horde_Date($message->anniversary); $hash['anniversary'] = $anniversary->format('Y-m-d'); - } else { + } elseif (!$message->isGhosted('anniversary')) { $hash['anniversary'] = null; } - /* Assistant */ - $hash['assistant'] = Horde_String::convertCharset($message->assistantname, 'utf-8', $charset); - return $hash; } -- 2.11.0