This file is indexed.

/usr/share/php/Horde/ActiveSync/Connector/Exporter.php is in php-horde-activesync 2.19.2-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
<?php
/**
 * Horde_ActiveSync_Connector_Exporter::
 *
 * Portions of this class were ported from the Z-Push project:
 *   File      :   wbxml.php
 *   Project   :   Z-Push
 *   Descr     :   WBXML mapping file
 *
 *   Created   :   01.10.2007
 *
 *   © Zarafa Deutschland GmbH, www.zarafaserver.de
 *   This file is distributed under GPL-2.0.
 *   Consult COPYING file for details
 *
 * @license   http://www.horde.org/licenses/gpl GPLv2
 *            NOTE: According to sec. 8 of the GENERAL PUBLIC LICENSE (GPL),
 *            Version 2, the distribution of the Horde_ActiveSync module in or
 *            to the United States of America is excluded from the scope of this
 *            license.
 * @copyright 2009-2014 Horde LLC (http://www.horde.org)
 * @author    Michael J Rubinsky <mrubinsk@horde.org>
 * @package   ActiveSync
 */
/**
 * Horde_ActiveSync_Connector_Exporter:: Outputs necessary wbxml to device.
 *
 * @license   http://www.horde.org/licenses/gpl GPLv2
 *            NOTE: According to sec. 8 of the GENERAL PUBLIC LICENSE (GPL),
 *            Version 2, the distribution of the Horde_ActiveSync module in or
 *            to the United States of America is excluded from the scope of this
 *            license.
 * @copyright 2009-2014 Horde LLC (http://www.horde.org)
 * @author    Michael J Rubinsky <mrubinsk@horde.org>
 * @package   ActiveSync
 */
class Horde_ActiveSync_Connector_Exporter
{
    /**
     * The wbxml encoder
     *
     * @var Horde_ActiveSync_Wbxml_Encoder
     */
    protected $_encoder;

    /**
     * Local cache of object ids we have already dealt with.
     *
     * @var array
     */
    protected $_seenObjects = array();

    /**
     * Array of folder objects that have changed.
     * Used when exporting folder structure changes since they are not streamed
     * from this object.
     *
     * @var array
     */
    public $changed = array();

    /**
     * Array of folder ids that have been deleted on the server.
     *
     * @var array
     */
    public $deleted = array();

    /**
     * Tracks the total number of folder changes
     *
     * @var integer
     */
    public $count = 0;

    /**
     * Local cache of changes to send.
     *
     * @var array
     */
    protected $_changes = array();

    /**
     * Counter of changes sent.
     *
     * @var integer
     */
    protected $_step = 0;

    /**
     * Currently syncing collection.
     *
     * @var array
     */
    protected $_currentCollection;

    /**
     * The ActiveSync server object.
     *
     * @var Horde_ActiveSync
     */
    protected $_as;

    /**
     * Process id for logging.
     *
     * @var integer
     */
    protected $_procid;

    /**
     * Const'r
     *
     * @param Horde_ActiveSync $as                    The ActiveSync server.
     * @param Horde_ActiveSync_Wbxml_Encoder $encoder The encoder
     *
     * @return Horde_ActiveSync_Connector_Exporter
     */
    public function __construct(
        Horde_ActiveSync $as,
        Horde_ActiveSync_Wbxml_Encoder $encoder = null)
    {
        $this->_as = $as;
        $this->_encoder = $encoder;
        $this->_logger = $as->logger;
        $this->_procid = getmypid();
    }

    /**
     * Set the changes to send to the client.
     *
     * @param array $changes  The changes array returned from the collection
     *                        handler.
     * @param array $collection  The collection we are currently syncing.
     */
    public function setChanges($changes, $collection)
    {
        $this->_changes = $changes;
        $this->_seenObjects = array();
        $this->_step = 0;
        $this->_currentCollection = $collection;
    }

    /**
     * Sends the next change in the set to the client.
     *
     * @return boolean|Horde_Exception True if more changes can be sent false if
     *                                 all changes were sent, Horde_Exception if
     *                                 there was an error sending an item.
     */
    public function sendNextChange()
    {
        if (empty($this->_currentCollection)) {
            if ($this->_step < count($this->_changes)) {
                $change = $this->_changes[$this->_step];
                switch($change['type']) {
                case Horde_ActiveSync::CHANGE_TYPE_CHANGE:
                    // Folder add/change.
                    if ($folder = $this->_as->driver->getFolder($change['serverid'])) {
                        // @TODO BC HACK. Need to ensure we have a _serverid here.
                        // REMOVE IN H6.
                        if (empty($folder->_serverid)) {
                            $folder->_serverid = $folder->serverid;
                        }
                        $stat = $this->_as->driver->statFolder(
                            $change['id'],
                            $folder->parentid,
                            $folder->displayname,
                            $folder->_serverid,
                            $folder->type);
                        $this->folderChange($folder);
                    } else {
                        $this->_logger->err(sprintf(
                            '[%s] Error stating %s: ignoring.',
                            $this->_procid, $change['id']));
                        $stat = array('id' => $change['id'], 'mod' => $change['id'], 0);
                    }
                    // Update the state.
                    $this->_as->state->updateState(
                        Horde_ActiveSync::CHANGE_TYPE_FOLDERSYNC, $stat);
                    break;

                case Horde_ActiveSync::CHANGE_TYPE_DELETE:
                    $this->folderDeletion($change['id']);
                    $this->_as->state->updateState(
                        Horde_ActiveSync::CHANGE_TYPE_DELETE, $change);
                    break;
                }
                $this->_step++;
                return true;
            } else {
                return false;
            }
        } else {
            if ($this->_step < count($this->_changes)) {
                $change = $this->_changes[$this->_step];

                // Ignore this change, no UID value, keep trying until we get a
                // good entry or we run out of entries.
                while (empty($change['id']) && $this->_step < count($this->_changes) - 1) {
                    $this->_logger->err('Missing UID value for an entry in: ' . $this->_currentCollection['id']);
                    $this->_step++;
                    $change = $this->_changes[$this->_step];
                }

                // Actually export the change by calling the appropriate
                // method to output the correct wbxml for this change.
                if (empty($change['ignore'])) {
                    switch($change['type']) {
                    case Horde_ActiveSync::CHANGE_TYPE_CHANGE:
                        try {
                            $message = $this->_as->driver->getMessage(
                                $this->_currentCollection['serverid'],
                                $change['id'],
                                $this->_currentCollection);
                            $message->flags = (isset($change['flags'])) ? $change['flags'] : 0;
                            $this->messageChange($change['id'], $message);
                        } catch (Horde_Exception_NotFound $e) {
                            $this->_logger->err(sprintf(
                                '[%s] Message gone or error reading message from server: %s',
                                $this->_procid, $e->getMessage()));
                            $this->_as->state->updateState($change['type'], $change);
                            $this->_step++;
                            return $e;
                        } catch (Horde_ActiveSync_Exception $e) {
                            $this->_logger->err(sprintf(
                                '[%s] Unknown backend error skipping message: %s',
                                $this->_procid,
                                $e->getMessage()));
                            $this->_as->state->updateState($change['type'], $change);
                            $this->_step++;
                            return $e;
                        }
                        break;

                    case Horde_ActiveSync::CHANGE_TYPE_DELETE:
                        $this->messageDeletion($change['id']);
                        break;

                    case Horde_ActiveSync::CHANGE_TYPE_SOFTDELETE:
                        $this->messageDeletion($change['id'], true);
                        break;

                    case Horde_ActiveSync::CHANGE_TYPE_FLAGS:
                        // Read flag.
                        $message = Horde_ActiveSync::messageFactory('Mail');
                        $message->flags = Horde_ActiveSync::CHANGE_TYPE_CHANGE;
                        $message->read = isset($change['flags']['read']) ? $change['flags']['read'] : false;

                        // "Flagged" flag.
                        if (isset($change['flags']['flagged']) && $this->_as->device->version >= Horde_ActiveSync::VERSION_TWELVE) {
                            $flag = Horde_ActiveSync::messageFactory('Flag');
                            $flag->flagstatus = $change['flags']['flagged'] == 1
                                ? Horde_ActiveSync_Message_Flag::FLAG_STATUS_ACTIVE
                                : Horde_ActiveSync_Message_Flag::FLAG_STATUS_CLEAR;
                            $message->flag = $flag;
                        }

                        // Categories
                        if (!empty($change['categories']) && $this->_as->device->version > Horde_ActiveSync::VERSION_TWELVEONE) {
                            $message->categories = $change['categories'];
                        }

                        // Verbs
                        if ($this->_as->device->version >= Horde_ActiveSync::VERSION_FOURTEEN) {
                            if (isset($change['flags'][Horde_ActiveSync::CHANGE_REPLY_STATE])) {
                                $message->lastverbexecuted = Horde_ActiveSync_Message_Mail::VERB_REPLY_SENDER;
                                $message->lastverbexecutiontime = new Horde_Date($change['flags'][Horde_ActiveSync::CHANGE_REPLY_STATE]);
                            } elseif (isset($change['flags'][Horde_ActiveSync::CHANGE_REPLYALL_STATE])) {
                                $message->lastverbexecuted = Horde_ActiveSync_Message_Mail::VERB_REPLY_ALL;
                                $message->lastverbexecutiontime = new Horde_Date($change['flags'][Horde_ActiveSync::CHANGE_REPLYALL_STATE]);
                            } elseif (isset($change['flags'][Horde_ActiveSync::CHANGE_FORWARD_STATE])) {
                                $message->lastverbexecuted = Horde_ActiveSync_Message_Mail::VERB_FORWARD;
                                $message->lastverbexecutiontime = new Horde_Date($change['flags'][Horde_ActiveSync::CHANGE_FORWARD_STATE]);
                            }
                        }

                        // Export it.
                        $this->messageChange($change['id'], $message);
                        break;

                    case Horde_ActiveSync::CHANGE_TYPE_MOVE:
                        $this->messageMove($change['id'], $change['parent']);
                        break;
                    }
                }

                // Update the state.
                $this->_as->state->updateState($change['type'], $change);
                $this->_step++;
                return true;
            } else {
                return false;
            }
        }
    }

    /**
     * Send a message change over the wbxml stream
     *
     * @param string $id                              The uid of the message
     * @param Horde_ActiveSync_Message_Base $message  The message object
     */
    public function messageChange($id, Horde_ActiveSync_Message_Base $message)
    {
        // Just ignore any messages that are not from this collection and
        // prevent sending the same object twice in one request.
        if ($message->getClass() != $this->_currentCollection['class'] ||
            in_array($id, $this->_seenObjects)) {
            $this->_logger->notice(sprintf(
                '[%s] IGNORING message %s since it looks like it was already sent or does not belong to this collection. Class: %s, CurrentClass: %s',
                $this->_procid,
                $id,
                $message->getClass(),
                $this->_currentCollection['class']));
            return;
        }

        // Remember this message
        $this->_seenObjects[] = $id;

        // Specify if this is an ADD or a MODIFY change?
        if ($message->flags === false || $message->flags === Horde_ActiveSync::FLAG_NEWMESSAGE) {
            $this->_encoder->startTag(Horde_ActiveSync::SYNC_ADD);
        } else {
            $this->_encoder->startTag(Horde_ActiveSync::SYNC_MODIFY);
        }

        // Send the message
        $this->_encoder->startTag(Horde_ActiveSync::SYNC_SERVERENTRYID);
        $this->_encoder->content($id);
        $this->_encoder->endTag();
        $this->_encoder->startTag(Horde_ActiveSync::SYNC_DATA);
        $message->encodeStream($this->_encoder);
        $this->_encoder->endTag();
        $this->_encoder->endTag();
    }

    /**
     * Stream a message deletion to the PIM
     *
     * @param string $id  The uid of the message we are deleting.
     * @param boolean $soft  If true, send a SOFTDELETE, otherwise a REMOVE.
     */
    public function messageDeletion($id, $soft = false)
    {
        if ($soft) {
            $this->_encoder->startTag(Horde_ActiveSync::SYNC_SOFTDELETE);
        } else {
            $this->_encoder->startTag(Horde_ActiveSync::SYNC_REMOVE);
        }
        $this->_encoder->startTag(Horde_ActiveSync::SYNC_SERVERENTRYID);
        $this->_encoder->content($id);
        $this->_encoder->endTag();
        $this->_encoder->endTag();
    }

    /**
     * Move a message to a different folder.
     *
     * @param Horde_ActiveSync_Message_Base $message  The message
     */
    function messageMove($message)
    {
    }

    /**
     * Add a folder change to the cache (used during FolderSync requests).
     *
     * @param Horde_ActiveSync_Message_Folder $folder
     */
    public function folderChange(Horde_ActiveSync_Message_Folder $folder)
    {
        $this->changed[] = $folder;
        $this->count++;
    }

    /**
     * Add a folder deletion to the cache (used during FolderSync Requests).
     *
     * @param string $id  The folder id
     */
    public function folderDeletion($id)
    {
        $this->deleted[] = $id;
        $this->count++;
    }

}