예제 #1
0
파일: ics.php 프로젝트: nnaannoo/paskot
 function Config(&$importer, $mclass, $restrict, $syncstate, $flags, $truncation)
 {
     // Because we're using ICS, we need to wrap the given importer to make it suitable to pass
     // to ICS. We do this in two steps: first, wrap the importer with our own PHP importer class
     // which removes all MAPI dependency, and then wrap that class with a C++ wrapper so we can
     // pass it to ICS
     $exporterflags = 0;
     if ($this->_folderid) {
         // PHP wrapper
         $phpimportproxy = new PHPContentsImportProxy($this->_session, $this->_store, $this->_folderid, $importer, $truncation);
         // ICS c++ wrapper
         $mapiimporter = mapi_wrap_importcontentschanges($phpimportproxy);
         $exporterflags |= SYNC_NORMAL | SYNC_READ_STATE;
         // Initial sync, we don't want deleted items. If the initial sync is chunked
         // we check the change ID of the syncstate (0 at initial sync)
         // On subsequent syncs, we do want to receive delete events.
         if (strlen($syncstate) == 0 || bin2hex(substr($syncstate, 4, 4)) == "00000000") {
             debugLog("synching inital data");
             $exporterflags |= SYNC_NO_SOFT_DELETIONS | SYNC_NO_DELETIONS;
         }
     } else {
         $phpimportproxy = new PHPHierarchyImportProxy($this->_store, $importer);
         $mapiimporter = mapi_wrap_importhierarchychanges($phpimportproxy);
     }
     if ($flags & BACKEND_DISCARD_DATA) {
         $exporterflags |= SYNC_CATCHUP;
     }
     // Put the state information in a stream that can be used by ICS
     $stream = mapi_stream_create();
     if (strlen($syncstate) > 0) {
         mapi_stream_write($stream, $syncstate);
     } else {
         mapi_stream_write($stream, hex2bin("0000000000000000"));
     }
     $this->statestream = $stream;
     // only set a restriction if the device has set a filtertype, except for Zarafa versions before 7 - see Mantis #368
     switch ($mclass) {
         case "Email":
             $restriction = $restrict || !checkMapiExtVersion('7') ? $this->_getEmailRestriction($this->_getCutOffDate($restrict)) : false;
             break;
         case "Calendar":
             $restriction = $restrict || !checkMapiExtVersion('7') ? $this->_getCalendarRestriction($this->_getCutOffDate($restrict)) : false;
             break;
         default:
         case "Contacts":
         case "Tasks":
             $restriction = false;
             break;
     }
     if ($this->_folderid) {
         $includeprops = false;
     } else {
         $includeprops = array(PR_SOURCE_KEY, PR_DISPLAY_NAME);
     }
     if ($this->exporter === false) {
         debugLog("ExportChangesICS->Config failed. Exporter not available.");
         return false;
     }
     $ret = mapi_exportchanges_config($this->exporter, $stream, $exporterflags, $mapiimporter, $restriction, $includeprops, false, 1);
     if ($ret) {
         $changes = mapi_exportchanges_getchangecount($this->exporter);
         if ($changes || !($flags & BACKEND_DISCARD_DATA)) {
             debugLog("Exporter configured successfully. " . $changes . " changes ready to sync.");
         }
     } else {
         debugLog("Exporter could not be configured: result: " . sprintf("%X", mapi_last_hresult()));
     }
     return $ret;
 }
예제 #2
0
 function Config(&$importer, $mclass, $restrict, $syncstate, $flags, $truncation, $bodypreference, $optionbodypreference, $mimesupport = 0)
 {
     // Because we're using ICS, we need to wrap the given importer to make it suitable to pass
     // to ICS. We do this in two steps: first, wrap the importer with our own PHP importer class
     // which removes all MAPI dependency, and then wrap that class with a C++ wrapper so we can
     // pass it to ICS
     $exporterflags = 0;
     //		debugLog("Importer: ".$importer. " mclass: ".$mclass." restrict: ".$restrict." syncstate: ".bin2hex($syncstate)." flags: ".$flags." truncation: ".$truncation. " bodypreference: ".$bodypreference);
     if ($this->_folderid) {
         // PHP wrapper
         // CHANGED dw2412 Support Protocol Version 12 (added bodypreference)
         //	    	debugLog("Config: mclass=".$mclass);
         $phpimportproxy = new PHPContentsImportProxy($this->_session, $this->_store, $this->_folderid, $importer, $truncation, $bodypreference, $optionbodypreference, $mimesupport, $mclass);
         // ICS c++ wrapper
         $mapiimporter = mapi_wrap_importcontentschanges($phpimportproxy);
         $exporterflags |= SYNC_NORMAL | SYNC_READ_STATE;
         // Initial sync, we don't want deleted items. If the initial sync is chunked
         // we check the change ID of the syncstate (0 at initial sync)
         // On subsequent syncs, we do want to receive delete events.
         if (strlen($syncstate) == 0 || bin2hex(substr($syncstate, 4, 4)) == "00000000") {
             //                debugLog("syncing inital data");
             $exporterflags |= SYNC_NO_SOFT_DELETIONS | SYNC_NO_DELETIONS;
         }
         $msgstore_props = mapi_getprops($this->_store, array(PR_IPM_OUTBOX_ENTRYID));
         $folder_entryid = mapi_msgstore_entryidfromsourcekey($this->_store, $this->_folderid);
         if ($folder_entryid == $msgstore_props[PR_IPM_OUTBOX_ENTRYID]) {
             if (strlen($syncstate) != 0 && bin2hex(substr($syncstate, 4, 4)) != "00000000") {
                 debugLog("ExportICS->Config: Ignoring deletions in Outbox.");
                 $exporterflags |= SYNC_NO_SOFT_DELETIONS | SYNC_NO_DELETIONS;
                 $this->_smsoutboxinitialsync = false;
             } else {
                 $this->_smsoutboxinitialsync = true;
             }
             $this->_smsoutboxsync = true;
         } else {
             $this->_smsoutboxsync = false;
         }
     } else {
         $phpimportproxy = new PHPHierarchyImportProxy($this->_store, $importer);
         $mapiimporter = mapi_wrap_importhierarchychanges($phpimportproxy);
     }
     if ($flags & BACKEND_DISCARD_DATA) {
         $exporterflags |= SYNC_CATCHUP;
     }
     // Put the state information in a stream that can be used by ICS
     $stream = mapi_stream_create();
     if (strlen($syncstate) > 0) {
         mapi_stream_write($stream, $syncstate);
     } else {
         mapi_stream_write($stream, hex2bin("0000000000000000"));
     }
     $this->statestream = $stream;
     //	debugLog("ExportChangesICS->Config: ".($this->_folderid ? "Have Folder" : "No Folder"). " " . $mclass . " state: ". bin2hex($syncstate) . " restriction " . $restrict);
     switch ($mclass) {
         case "SMS":
             //                $restriction = $this->_getSMSRestriction($this->_getCutOffDate($restrict));
             //				break;
         //                $restriction = $this->_getSMSRestriction($this->_getCutOffDate($restrict));
         //				break;
         case "Email":
             $restriction = $this->_getEmailRestriction($this->_getCutOffDate($restrict));
             break;
         case "Calendar":
             $restriction = $this->_getCalendarRestriction($this->_getCutOffDate($restrict));
             break;
         default:
         case "Contacts":
         case "Tasks":
             $restriction = false;
             break;
     }
     if ($this->_folderid) {
         $includeprops = false;
     } else {
         $includeprops = array(PR_SOURCE_KEY, PR_DISPLAY_NAME);
     }
     if ($this->exporter === false) {
         debugLog("ExportChangesICS->Config failed. Exporter not available.");
         return false;
     }
     //	debugLog("HEREA1");
     //	debugLog("Exporter: ". $this->exporter." Stream: ". $stream ." Exporterflags: ".$exporterflags." Mapiimporter: ".$mapiimporter." Restriction: ".print_r($restriction,true)." Includeprops: ". print_r($includeprops,true));
     $ret = mapi_exportchanges_config($this->exporter, $stream, $exporterflags, $mapiimporter, $restriction, $includeprops, false, 1);
     //	debugLog("HEREA2");
     if ($ret) {
         $changes = mapi_exportchanges_getchangecount($this->exporter);
         if ($changes || !($flags & BACKEND_DISCARD_DATA)) {
             debugLog("Exporter configured successfully. " . $changes . " changes ready to sync.");
         }
     } else {
         debugLog("Exporter could not be configured: result: " . sprintf("%X", mapi_last_hresult()));
     }
     return $ret;
 }
예제 #3
0
 /**
  * Sets the importer the exporter will sent it's changes to
  * and initializes the Exporter
  *
  * @param object        &$importer  Implementation of IImportChanges
  *
  * @access public
  * @return boolean
  * @throws StatusException
  */
 public function InitializeExporter(&$importer)
 {
     // Because we're using ICS, we need to wrap the given importer to make it suitable to pass
     // to ICS. We do this in two steps: first, wrap the importer with our own PHP importer class
     // which removes all MAPI dependency, and then wrap that class with a C++ wrapper so we can
     // pass it to ICS
     // this should never happen!
     if ($this->exporter === false || !isset($this->statestream) || !isset($this->flags) || !isset($this->exporterflags) || $this->folderid && !isset($this->contentParameters)) {
         throw new StatusException("ExportChangesICS->InitializeExporter(): Error, exporter or essential data not available", SYNC_FSSTATUS_CODEUNKNOWN, null, LOGLEVEL_ERROR);
     }
     // PHP wrapper
     $phpwrapper = new PHPWrapper($this->session, $this->store, $importer);
     // with a folderid we are going to get content
     if ($this->folderid) {
         $phpwrapper->ConfigContentParameters($this->contentParameters);
         // ICS c++ wrapper
         $mapiimporter = mapi_wrap_importcontentschanges($phpwrapper);
         $includeprops = false;
     } else {
         $mapiimporter = mapi_wrap_importhierarchychanges($phpwrapper);
         $includeprops = array(PR_SOURCE_KEY, PR_DISPLAY_NAME);
     }
     if (!$mapiimporter) {
         throw new StatusException(sprintf("ExportChangesICS->InitializeExporter(): Error, mapi_wrap_import_*_changes() failed: 0x%X", mapi_last_hresult()), SYNC_FSSTATUS_CODEUNKNOWN, null, LOGLEVEL_WARN);
     }
     $ret = mapi_exportchanges_config($this->exporter, $this->statestream, $this->exporterflags, $mapiimporter, $this->restriction, $includeprops, false, 1);
     if (!$ret) {
         throw new StatusException(sprintf("ExportChangesICS->InitializeExporter(): Error, mapi_exportchanges_config() failed: 0x%X", mapi_last_hresult()), SYNC_FSSTATUS_CODEUNKNOWN, null, LOGLEVEL_WARN);
     }
     $changes = mapi_exportchanges_getchangecount($this->exporter);
     if ($changes || !($this->flags & BACKEND_DISCARD_DATA)) {
         ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExportChangesICS->InitializeExporter() successfully. %d changes ready to sync.", $changes));
     }
     return $ret;
 }
예제 #4
0
 function Config(&$importer, $mclass, $restrict, $syncstate, $flags, $truncation)
 {
     // Because we're using ICS, we need to wrap the given importer to make it suitable to pass
     // to ICS. We do this in two steps: first, wrap the importer with our own PHP importer class
     // which removes all MAPI dependency, and then wrap that class with a C++ wrapper so we can
     // pass it to ICS
     $exporterflags = 0;
     if ($this->_folderid) {
         // PHP wrapper
         $phpimportproxy = new PHPContentsImportProxy($this->_session, $this->_store, $this->_folderid, $importer, $truncation);
         // ICS c++ wrapper
         $mapiimporter = mapi_wrap_importcontentschanges($phpimportproxy);
         $exporterflags |= SYNC_NORMAL | SYNC_READ_STATE;
         // Initial sync, we don't want deleted items. On subsequent syncs, we do want to receive delete
         // events.
         if (strlen($syncstate) == 0) {
             $exporterflags |= SYNC_NO_SOFT_DELETIONS;
         }
     } else {
         $phpimportproxy = new PHPHierarchyImportProxy($this->_store, $importer);
         $mapiimporter = mapi_wrap_importhierarchychanges($phpimportproxy);
     }
     if ($flags & BACKEND_DISCARD_DATA) {
         $exporterflags |= SYNC_CATCHUP;
     }
     // Put the state information in a stream that can be used by ICS
     $stream = mapi_stream_create();
     if (strlen($syncstate) > 0) {
         mapi_stream_write($stream, $syncstate);
     } else {
         mapi_stream_write($stream, hex2bin("0000000000000000"));
     }
     $this->statestream = $stream;
     switch ($mclass) {
         case "Email":
             $restriction = $this->_getEmailRestriction($this->_getCutOffDate($restrict));
             break;
         case "Calendar":
             $restriction = $this->_getCalendarRestriction($this->_getCutOffDate($restrict));
             break;
         default:
         case "Contacts":
         case "Tasks":
             $restriction = false;
             break;
     }
     $ret = mapi_exportchanges_config($this->exporter, $stream, $exporterflags, $mapiimporter, $restriction, false, false, 1);
     if ($ret) {
         debugLog("Exporter configured successfully. " . mapi_exportchanges_getchangecount($this->exporter) . " changes ready to sync.");
     } else {
         debugLog("Exporter could not be configured: result: " . mapi_last_hresult());
     }
     return $ret;
 }