source: trunk/zpush/backend/zarafa/mapiphpwrapper.php @ 7589

Revision 7589, 7.8 KB checked in by douglas, 11 years ago (diff)

Ticket #3209 - Integrar módulo de sincronização Z-push ao Expresso

Line 
1<?php
2/***********************************************
3* File      :   mapiphpwrapper.php
4* Project   :   Z-Push
5* Descr     :   The ICS importer is very MAPI specific
6*               and needs to be wrapped, because we
7*               want all MAPI code to be separate from
8*               the rest of z-push. To do so all
9*               MAPI dependency are removed in this class.
10*               All the other importers are based on
11*               IChanges, not MAPI.
12*
13* Created   :   14.02.2011
14*
15* Copyright 2007 - 2012 Zarafa Deutschland GmbH
16*
17* This program is free software: you can redistribute it and/or modify
18* it under the terms of the GNU Affero General Public License, version 3,
19* as published by the Free Software Foundation with the following additional
20* term according to sec. 7:
21*
22* According to sec. 7 of the GNU Affero General Public License, version 3,
23* the terms of the AGPL are supplemented with the following terms:
24*
25* "Zarafa" is a registered trademark of Zarafa B.V.
26* "Z-Push" is a registered trademark of Zarafa Deutschland GmbH
27* The licensing of the Program under the AGPL does not imply a trademark license.
28* Therefore any rights, title and interest in our trademarks remain entirely with us.
29*
30* However, if you propagate an unmodified version of the Program you are
31* allowed to use the term "Z-Push" to indicate that you distribute the Program.
32* Furthermore you may use our trademarks where it is necessary to indicate
33* the intended purpose of a product or service provided you use it in accordance
34* with honest practices in industrial or commercial matters.
35* If you want to propagate modified versions of the Program under the name "Z-Push",
36* you may only do so if you have a written permission by Zarafa Deutschland GmbH
37* (to acquire a permission please contact Zarafa at trademark@zarafa.com).
38*
39* This program is distributed in the hope that it will be useful,
40* but WITHOUT ANY WARRANTY; without even the implied warranty of
41* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42* GNU Affero General Public License for more details.
43*
44* You should have received a copy of the GNU Affero General Public License
45* along with this program.  If not, see <http://www.gnu.org/licenses/>.
46*
47* Consult LICENSE file for details
48************************************************/
49
50/**
51 * This is the PHP wrapper which strips MAPI information from
52 * the import interface of ICS. We get all the information about messages
53 * from MAPI here which are sent to the next importer, which will
54 * convert the data into WBXML which is streamed to the PDA
55 */
56
57class PHPWrapper {
58    private $importer;
59    private $mapiprovider;
60    private $store;
61    private $contentparameters;
62
63
64    /**
65     * Constructor of the PHPWrapper
66     *
67     * @param ressource         $session
68     * @param ressource         $store
69     * @param IImportChanges    $importer       incoming changes from ICS are forwarded here
70     *
71     * @access public
72     * @return
73     */
74    public function PHPWrapper($session, $store, $importer) {
75        $this->importer = &$importer;
76        $this->store = $store;
77        $this->mapiprovider = new MAPIProvider($session, $this->store);
78    }
79
80    /**
81     * Configures additional parameters used for content synchronization
82     *
83     * @param ContentParameters         $contentparameters
84     *
85     * @access public
86     * @return boolean
87     * @throws StatusException
88     */
89    public function ConfigContentParameters($contentparameters) {
90        $this->contentparameters = $contentparameters;
91    }
92
93    /**
94     * Implement MAPI interface
95     */
96    public function Config($stream, $flags = 0) {}
97    public function GetLastError($hresult, $ulflags, &$lpmapierror) {}
98    public function UpdateState($stream) { }
99
100    /**
101     * Imports a single message
102     *
103     * @param array         $props
104     * @param long          $flags
105     * @param object        $retmapimessage
106     *
107     * @access public
108     * @return long
109     */
110    public function ImportMessageChange($props, $flags, &$retmapimessage) {
111        $sourcekey = $props[PR_SOURCE_KEY];
112        $parentsourcekey = $props[PR_PARENT_SOURCE_KEY];
113        $entryid = mapi_msgstore_entryidfromsourcekey($this->store, $parentsourcekey, $sourcekey);
114
115        if(!$entryid)
116            return SYNC_E_IGNORE;
117
118        $mapimessage = mapi_msgstore_openentry($this->store, $entryid);
119        try {
120            $message = $this->mapiprovider->GetMessage($mapimessage, $this->contentparameters);
121        }
122        catch (SyncObjectBrokenException $mbe) {
123            $brokenSO = $mbe->GetSyncObject();
124            if (!$brokenSO) {
125                ZLog::Write(LOGLEVEL_ERROR, sprintf("PHPWrapper->ImportMessageChange(): Catched SyncObjectBrokenException but broken SyncObject available"));
126            }
127            else {
128                if (!isset($brokenSO->id)) {
129                    $brokenSO->id = "Unknown ID";
130                    ZLog::Write(LOGLEVEL_ERROR, sprintf("PHPWrapper->ImportMessageChange(): Catched SyncObjectBrokenException but no ID of object set"));
131                }
132                ZPush::GetDeviceManager()->AnnounceIgnoredMessage(false, $brokenSO->id, $brokenSO);
133            }
134            // tell MAPI to ignore the message
135            return SYNC_E_IGNORE;
136        }
137
138
139        // substitute the MAPI SYNC_NEW_MESSAGE flag by a z-push proprietary flag
140        if ($flags == SYNC_NEW_MESSAGE) $message->flags = SYNC_NEWMESSAGE;
141        else $message->flags = $flags;
142
143        $this->importer->ImportMessageChange(bin2hex($sourcekey), $message);
144
145        // Tell MAPI it doesn't need to do anything itself, as we've done all the work already.
146        return SYNC_E_IGNORE;
147    }
148
149    /**
150     * Imports a list of messages to be deleted
151     *
152     * @param long          $flags
153     * @param array         $sourcekeys     array with sourcekeys
154     *
155     * @access public
156     * @return
157     */
158    public function ImportMessageDeletion($flags, $sourcekeys) {
159        foreach($sourcekeys as $sourcekey) {
160            $this->importer->ImportMessageDeletion(bin2hex($sourcekey));
161        }
162    }
163
164    /**
165     * Imports a list of messages to be deleted
166     *
167     * @param mixed         $readstates     sourcekeys and message flags
168     *
169     * @access public
170     * @return
171     */
172    public function ImportPerUserReadStateChange($readstates) {
173        foreach($readstates as $readstate) {
174            $this->importer->ImportMessageReadFlag(bin2hex($readstate["sourcekey"]), $readstate["flags"] & MSGFLAG_READ);
175        }
176    }
177
178    /**
179     * Imports a message move
180     * this is never called by ICS
181     *
182     * @access public
183     * @return
184     */
185    public function ImportMessageMove($sourcekeysrcfolder, $sourcekeysrcmessage, $message, $sourcekeydestmessage, $changenumdestmessage) {
186        // Never called
187    }
188
189    /**
190     * Imports a single folder change
191     *
192     * @param mixed         $props     sourcekey of the changed folder
193     *
194     * @access public
195     * @return
196     */
197    function ImportFolderChange($props) {
198        $sourcekey = $props[PR_SOURCE_KEY];
199        $entryid = mapi_msgstore_entryidfromsourcekey($this->store, $sourcekey);
200        $mapifolder = mapi_msgstore_openentry($this->store, $entryid);
201        $folder = $this->mapiprovider->GetFolder($mapifolder);
202
203        // do not import folder if there is something "wrong" with it
204        if ($folder === false)
205            return 0;
206
207        $this->importer->ImportFolderChange($folder);
208        return 0;
209    }
210
211    /**
212     * Imports a list of folders which are to be deleted
213     *
214     * @param long          $flags
215     * @param mixed         $sourcekeys array with sourcekeys
216     *
217     * @access public
218     * @return
219     */
220    function ImportFolderDeletion($flags, $sourcekeys) {
221        foreach ($sourcekeys as $sourcekey) {
222            $this->importer->ImportFolderDeletion(bin2hex($sourcekey));
223        }
224        return 0;
225    }
226}
227
228?>
Note: See TracBrowser for help on using the repository browser.