Example #1
0
 /**
  * Called when a message has been changed on the mobile.
  * This functionality is not available for emails.
  *
  * @param string              $folderid            id of the folder
  * @param string              $id                  id of the message
  * @param SyncXXX             $message             the SyncObject containing a message
  * @param ContentParameters   $contentParameters
  *
  * @access public
  * @return array                        same return value as StatMessage()
  * @throws StatusException              could throw specific SYNC_STATUS_* exceptions
  */
 public function ChangeMessage($folderid, $id, $message, $contentParameters)
 {
     ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendCardDAV->ChangeMessage('%s', '%s')", $folderid, $id));
     $vcard_text = $this->ParseToVCard($message);
     if ($vcard_text === false) {
         ZLog::Write(LOGLEVEL_ERROR, sprintf("BackendCardDAV->ChangeMessage - Error converting message to vCard"));
     } else {
         ZLog::Write(LOGLEVEL_WBXML, sprintf("BackendCardDAV->ChangeMessage - vCard\n%s\n", $vcard_text));
         $updated = false;
         if (strlen($id) == 0) {
             //no id, new vcard
             try {
                 $addressbookId = $this->getAddressbookFromUrl($this->default_url);
                 if ($addressbookId === false) {
                     $addressbookId = $this->getAddressbookFromUrl($this->addressbooks[0]);
                     $this->server->set_url($this->addressbooks[0]);
                 } else {
                     $this->server->set_url($this->default_url);
                 }
                 $updated = $this->server->add($vcard_text);
                 if ($updated !== false) {
                     $id = $addressbookId . "-" . $updated;
                 }
             } catch (Exception $ex) {
                 ZLog::Write(LOGLEVEL_ERROR, sprintf("BackendCardDAV->ChangeMessage - Error adding vcard '%s' : %s", $id, $ex->getMessage()));
             }
         } else {
             //id, update vcard
             $vcardId = $this->getVcardId($id);
             $addressbookUrl = $this->getAddressbookFromId($this->getAddressbookIdFromVcard($id));
             if ($addressbookUrl !== false) {
                 try {
                     $this->server->set_url($addressbookUrl);
                     $updated = $this->server->update($vcard_text, $vcardId);
                 } catch (Exception $ex) {
                     ZLog::Write(LOGLEVEL_ERROR, sprintf("BackendCardDAV->ChangeMessage - Error updating vcard '%s' : %s", $id, $ex->getMessage()));
                 }
             }
         }
         if ($updated !== false) {
             ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendCardDAV->ChangeMessage - vCard updated"));
         } else {
             ZLog::Write(LOGLEVEL_ERROR, sprintf("BackendCardDAV->ChangeMessage - vCard not updated"));
         }
     }
     return $this->StatMessage($folderid, $id);
 }
 /**
  * Updates a CardDAV server contact
  *
  * @param  integer   $carddav_contact_id CardDAV contact id
  * @param  string    $vcard              The new vCard
  * @return boolean
  */
 private function carddav_update($carddav_contact_id, $vcard)
 {
     $vcard = $this->vcard_check($vcard);
     $contact = $this->get_carddav_addressbook_contact($carddav_contact_id);
     $server = current(carddav::get_carddav_server($this->carddav_server_id));
     $arr = parse_url($server['url']);
     $carddav_slow = $this->rc->config->get('carddav_slow_backends', array());
     if (isset($carddav_slow[strtolower($arr['host'])])) {
         $carddav_backend = new carddav_backend($server['url'], '', (int) $carddav_slow[strtolower($arr['host'])], false);
     } else {
         $carddav_backend = new carddav_backend($server['url']);
     }
     if ($this->rc->decrypt($server['password']) == '%p') {
         $server['password'] = $this->rcpassword;
     }
     $carddav_backend->set_auth($server['username'], $this->rc->decrypt($server['password']), $server['authtype']);
     if ($carddav_backend->check_connection()) {
         $carddav_backend->update($vcard, $contact['vcard_id']);
         $this->carddav_addressbook_sync($server, $carddav_contact_id, $contact['vcard_id']);
         return true;
     }
     return false;
 }