Back to index

d-push  2.0
streamimporter.php
Go to the documentation of this file.
00001 <?php
00002 /***********************************************
00003 * File      :   streamimporter.php
00004 * Project   :   Z-Push
00005 * Descr     :   sends changes directly to the wbxml stream
00006 *
00007 * Created   :   01.10.2007
00008 *
00009 * Copyright 2007 - 2011 Zarafa Deutschland GmbH
00010 *
00011 * This program is free software: you can redistribute it and/or modify
00012 * it under the terms of the GNU Affero General Public License, version 3,
00013 * as published by the Free Software Foundation with the following additional
00014 * term according to sec. 7:
00015 *
00016 * According to sec. 7 of the GNU Affero General Public License, version 3,
00017 * the terms of the AGPL are supplemented with the following terms:
00018 *
00019 * "Zarafa" is a registered trademark of Zarafa B.V.
00020 * "Z-Push" is a registered trademark of Zarafa Deutschland GmbH
00021 * The licensing of the Program under the AGPL does not imply a trademark license.
00022 * Therefore any rights, title and interest in our trademarks remain entirely with us.
00023 *
00024 * However, if you propagate an unmodified version of the Program you are
00025 * allowed to use the term "Z-Push" to indicate that you distribute the Program.
00026 * Furthermore you may use our trademarks where it is necessary to indicate
00027 * the intended purpose of a product or service provided you use it in accordance
00028 * with honest practices in industrial or commercial matters.
00029 * If you want to propagate modified versions of the Program under the name "Z-Push",
00030 * you may only do so if you have a written permission by Zarafa Deutschland GmbH
00031 * (to acquire a permission please contact Zarafa at trademark@zarafa.com).
00032 *
00033 * This program is distributed in the hope that it will be useful,
00034 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00035 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00036 * GNU Affero General Public License for more details.
00037 *
00038 * You should have received a copy of the GNU Affero General Public License
00039 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00040 *
00041 * Consult LICENSE file for details
00042 ************************************************/
00043 
00044 class ImportChangesStream implements IImportChanges {
00045     private $encoder;
00046     private $objclass;
00047     private $seenObjects;
00048     private $importedMsgs;
00049 
00058     public function ImportChangesStream(&$encoder, $class) {
00059         $this->encoder = &$encoder;
00060         $this->objclass = $class;
00061         $this->classAsString = (is_object($class))?get_class($class):'';
00062         $this->seenObjects = array();
00063         $this->importedMsgs = 0;
00064     }
00065 
00069     public function Config($state, $flags = 0) { return true; }
00070     public function GetState() { return false;}
00071     public function LoadConflicts($contentparameters, $state) { return true; }
00072 
00082     public function ImportMessageChange($id, $message) {
00083         // ignore other SyncObjects
00084         if(!($message instanceof $this->classAsString))
00085             return false;
00086 
00087         // prevent sending the same object twice in one request
00088         if (in_array($id, $this->seenObjects)) {
00089             ZLog::Write(LOGLEVEL_DEBUG, sprintf("Object '%s' discarded! Object already sent in this request.", $id));
00090             return true;
00091         }
00092 
00093         $this->importedMsgs++;
00094         $this->seenObjects[] = $id;
00095 
00096         // checks if the next message may cause a loop or is broken
00097         if (ZPush::GetDeviceManager(false) && ZPush::GetDeviceManager()->DoNotStreamMessage($id, $message)) {
00098             ZLog::Write(LOGLEVEL_DEBUG, sprintf("ImportChangesStream->ImportMessageChange('%s'): message ignored and requested to be removed from mobile", $id));
00099             return $this->ImportMessageDeletion($id);
00100         }
00101 
00102         if ($message->flags === false || $message->flags === SYNC_NEWMESSAGE)
00103             $this->encoder->startTag(SYNC_ADD);
00104         else
00105             $this->encoder->startTag(SYNC_MODIFY);
00106 
00107             $this->encoder->startTag(SYNC_SERVERENTRYID);
00108                 $this->encoder->content($id);
00109             $this->encoder->endTag();
00110             $this->encoder->startTag(SYNC_DATA);
00111                 $message->Encode($this->encoder);
00112             $this->encoder->endTag();
00113         $this->encoder->endTag();
00114 
00115         return true;
00116     }
00117 
00126     public function ImportMessageDeletion($id) {
00127         $this->importedMsgs++;
00128         $this->encoder->startTag(SYNC_REMOVE);
00129             $this->encoder->startTag(SYNC_SERVERENTRYID);
00130                 $this->encoder->content($id);
00131             $this->encoder->endTag();
00132         $this->encoder->endTag();
00133 
00134         return true;
00135     }
00136 
00147     public function ImportMessageReadFlag($id, $flags) {
00148         if(!($this->objclass instanceof SyncMail))
00149             return false;
00150 
00151         $this->importedMsgs++;
00152 
00153         $this->encoder->startTag(SYNC_MODIFY);
00154             $this->encoder->startTag(SYNC_SERVERENTRYID);
00155                 $this->encoder->content($id);
00156             $this->encoder->endTag();
00157             $this->encoder->startTag(SYNC_DATA);
00158                 $this->encoder->startTag(SYNC_POOMMAIL_READ);
00159                     $this->encoder->content($flags);
00160                 $this->encoder->endTag();
00161             $this->encoder->endTag();
00162         $this->encoder->endTag();
00163 
00164         return true;
00165     }
00166 
00176     public function ImportMessageMove($id, $newfolder) {
00177         return true;
00178     }
00179 
00188     public function ImportFolderChange($folder) {
00189         // checks if the next message may cause a loop or is broken
00190         if (ZPush::GetDeviceManager(false) && ZPush::GetDeviceManager()->DoNotStreamMessage($folder->serverid, $folder)) {
00191             ZLog::Write(LOGLEVEL_DEBUG, sprintf("ImportChangesStream->ImportFolderChange('%s'): folder ignored as requested by DeviceManager.", $folder->serverid));
00192             return true;
00193         }
00194 
00195         // send a modify flag if the folder is already known on the device
00196         if (isset($folder->flags) && $folder->flags === SYNC_NEWMESSAGE)
00197             $this->encoder->startTag(SYNC_FOLDERHIERARCHY_ADD);
00198         else
00199             $this->encoder->startTag(SYNC_FOLDERHIERARCHY_UPDATE);
00200 
00201         $folder->Encode($this->encoder);
00202         $this->encoder->endTag();
00203 
00204         return true;
00205     }
00206 
00216     public function ImportFolderDeletion($id, $parent = false) {
00217         $this->encoder->startTag(SYNC_FOLDERHIERARCHY_REMOVE);
00218             $this->encoder->startTag(SYNC_FOLDERHIERARCHY_SERVERENTRYID);
00219                 $this->encoder->content($id);
00220             $this->encoder->endTag();
00221         $this->encoder->endTag();
00222 
00223         return true;
00224     }
00225 
00232     public function GetImportedMessages() {
00233         return $this->importedMsgs;
00234     }
00235 }
00236 ?>