Exemple #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);
 }
 /**
  * Adds a CardDAV server contact
  *
  * @param  string  $vcard vCard
  * @return boolean
  */
 private function carddav_add($vcard)
 {
     $sync = true;
     if ($this->rc->action == 'copy') {
         $this->counter++;
         $cids = get_input_value('_cid', RCUBE_INPUT_POST);
         $cids = explode(',', $cids);
         if ($this->counter < count($cids)) {
             $sync = false;
         }
     }
     $vcard = $this->vcard_check($vcard);
     $server = current(carddav::get_carddav_server($this->carddav_server_id));
     $arr = parse_url($server['url']);
     $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()) {
         $vcard_id = $carddav_backend->add($vcard);
         if ($sync && $this->rc->action != 'import') {
             if ($this->rc->action == 'copy') {
                 $vcard_id = false;
             }
             $this->carddav_addressbook_sync($server, false, $vcard_id);
             $cid = $this->rc->db->insert_id(get_table_name($this->db_name));
             return $cid;
         } else {
             return true;
         }
     }
     return false;
 }