Back to index

d-push  2.0
mapiphpwrapper.php
Go to the documentation of this file.
00001 <?php
00002 /***********************************************
00003 * File      :   mapiphpwrapper.php
00004 * Project   :   Z-Push
00005 * Descr     :   The ICS importer is very MAPI specific
00006 *               and needs to be wrapped, because we
00007 *               want all MAPI code to be separate from
00008 *               the rest of z-push. To do so all
00009 *               MAPI dependency are removed in this class.
00010 *               All the other importers are based on
00011 *               IChanges, not MAPI.
00012 *
00013 * Created   :   14.02.2011
00014 *
00015 * Copyright 2007 - 2011 Zarafa Deutschland GmbH
00016 *
00017 * This program is free software: you can redistribute it and/or modify
00018 * it under the terms of the GNU Affero General Public License, version 3,
00019 * as published by the Free Software Foundation with the following additional
00020 * term according to sec. 7:
00021 *
00022 * According to sec. 7 of the GNU Affero General Public License, version 3,
00023 * the terms of the AGPL are supplemented with the following terms:
00024 *
00025 * "Zarafa" is a registered trademark of Zarafa B.V.
00026 * "Z-Push" is a registered trademark of Zarafa Deutschland GmbH
00027 * The licensing of the Program under the AGPL does not imply a trademark license.
00028 * Therefore any rights, title and interest in our trademarks remain entirely with us.
00029 *
00030 * However, if you propagate an unmodified version of the Program you are
00031 * allowed to use the term "Z-Push" to indicate that you distribute the Program.
00032 * Furthermore you may use our trademarks where it is necessary to indicate
00033 * the intended purpose of a product or service provided you use it in accordance
00034 * with honest practices in industrial or commercial matters.
00035 * If you want to propagate modified versions of the Program under the name "Z-Push",
00036 * you may only do so if you have a written permission by Zarafa Deutschland GmbH
00037 * (to acquire a permission please contact Zarafa at trademark@zarafa.com).
00038 *
00039 * This program is distributed in the hope that it will be useful,
00040 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00041 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00042 * GNU Affero General Public License for more details.
00043 *
00044 * You should have received a copy of the GNU Affero General Public License
00045 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00046 *
00047 * Consult LICENSE file for details
00048 ************************************************/
00049 
00057 class PHPWrapper {
00058     private $importer;
00059     private $mapiprovider;
00060     private $store;
00061     private $contentparameters;
00062 
00063 
00074     public function PHPWrapper($session, $store, $importer) {
00075         $this->importer = &$importer;
00076         $this->store = $store;
00077         $this->mapiprovider = new MAPIProvider($session, $this->store);
00078     }
00079 
00089     public function ConfigContentParameters($contentparameters) {
00090         $this->contentparameters = $contentparameters;
00091     }
00092 
00096     public function Config($stream, $flags = 0) {}
00097     public function GetLastError($hresult, $ulflags, &$lpmapierror) {}
00098     public function UpdateState($stream) { }
00099 
00110     public function ImportMessageChange($props, $flags, &$retmapimessage) {
00111         $sourcekey = $props[PR_SOURCE_KEY];
00112         $parentsourcekey = $props[PR_PARENT_SOURCE_KEY];
00113         $entryid = mapi_msgstore_entryidfromsourcekey($this->store, $parentsourcekey, $sourcekey);
00114 
00115         if(!$entryid)
00116             return SYNC_E_IGNORE;
00117 
00118         $mapimessage = mapi_msgstore_openentry($this->store, $entryid);
00119         try {
00120             $message = $this->mapiprovider->GetMessage($mapimessage, $this->contentparameters);
00121         }
00122         catch (SyncObjectBrokenException $mbe) {
00123             $brokenSO = $mbe->GetSyncObject();
00124             if (!$brokenSO) {
00125                 ZLog::Write(LOGLEVEL_ERROR, sprintf("PHPWrapper->ImportMessageChange(): Catched SyncObjectBrokenException but broken SyncObject available"));
00126             }
00127             else {
00128                 if (!isset($brokenSO->id)) {
00129                     $brokenSO->id = "Unknown ID";
00130                     ZLog::Write(LOGLEVEL_ERROR, sprintf("PHPWrapper->ImportMessageChange(): Catched SyncObjectBrokenException but no ID of object set"));
00131                 }
00132                 ZPush::GetDeviceManager()->AnnounceIgnoredMessage(false, $brokenSO->id, $brokenSO);
00133             }
00134             // tell MAPI to ignore the message
00135             return SYNC_E_IGNORE;
00136         }
00137 
00138 
00139         // substitute the MAPI SYNC_NEW_MESSAGE flag by a z-push proprietary flag
00140         if ($flags == SYNC_NEW_MESSAGE) $message->flags = SYNC_NEWMESSAGE;
00141         else $message->flags = $flags;
00142 
00143         $this->importer->ImportMessageChange(bin2hex($sourcekey), $message);
00144 
00145         // Tell MAPI it doesn't need to do anything itself, as we've done all the work already.
00146         return SYNC_E_IGNORE;
00147     }
00148 
00158     public function ImportMessageDeletion($flags, $sourcekeys) {
00159         foreach($sourcekeys as $sourcekey) {
00160             $this->importer->ImportMessageDeletion(bin2hex($sourcekey));
00161         }
00162     }
00163 
00172     public function ImportPerUserReadStateChange($readstates) {
00173         foreach($readstates as $readstate) {
00174             $this->importer->ImportMessageReadFlag(bin2hex($readstate["sourcekey"]), $readstate["flags"] & MSGFLAG_READ);
00175         }
00176     }
00177 
00185     public function ImportMessageMove($sourcekeysrcfolder, $sourcekeysrcmessage, $message, $sourcekeydestmessage, $changenumdestmessage) {
00186         // Never called
00187     }
00188 
00197     function ImportFolderChange($props) {
00198         $sourcekey = $props[PR_SOURCE_KEY];
00199         $entryid = mapi_msgstore_entryidfromsourcekey($this->store, $sourcekey);
00200         $mapifolder = mapi_msgstore_openentry($this->store, $entryid);
00201         $folder = $this->mapiprovider->GetFolder($mapifolder);
00202 
00203         // do not import folder if there is something "wrong" with it
00204         if ($folder === false)
00205             return 0;
00206 
00207         $this->importer->ImportFolderChange($folder);
00208         return 0;
00209     }
00210 
00220     function ImportFolderDeletion($flags, $sourcekeys) {
00221         foreach ($sourcekeys as $sourcekey) {
00222             $this->importer->ImportFolderDeletion(bin2hex($sourcekey));
00223         }
00224         return 0;
00225     }
00226 }
00227 
00228 ?>