/framework/ActiveSync/lib/Horde/ActiveSync/Connector/Exporter.php

https://github.com/ewandor/horde · PHP · 215 lines · 80 code · 23 blank · 112 comment · 8 complexity · bd7ac2294531c9059a02c3ae73aea631 MD5 · raw file

  1. <?php
  2. /**
  3. * Connector class for exporting ActiveSync messages to the wbxml output stream.
  4. * Contains code written by the Z-Push project. Original file header preserved
  5. * below.
  6. *
  7. * Copyright 2010-2012 Horde LLC (http://www.horde.org/)
  8. *
  9. * @author Michael J. Rubinsky <mrubinsk@horde.org>
  10. * @package ActiveSync
  11. */
  12. /**
  13. * File : streamimporter.php
  14. * Project : Z-Push
  15. * Descr : Stream import classes
  16. *
  17. * Created : 01.10.2007
  18. *
  19. * © Zarafa Deutschland GmbH, www.zarafaserver.de
  20. * This file is distributed under GPL-2.0.
  21. * Consult COPYING file for details
  22. */
  23. class Horde_ActiveSync_Connector_Exporter
  24. {
  25. /**
  26. * The wbxml encoder
  27. *
  28. * @var Horde_ActiveSync_Wbxml_Encoder
  29. */
  30. protected $_encoder;
  31. /**
  32. * The collection class for what we are exporting
  33. *
  34. * @var string
  35. */
  36. protected $_class;
  37. /**
  38. * Local cache of object ids we have already dealt with.
  39. *
  40. * @var array
  41. */
  42. protected $_seenObjects = array();
  43. /**
  44. * Array of object ids that have changed.
  45. * Used when exporting folder structure changes since they are not streamed
  46. * from this object.
  47. *
  48. * @var array
  49. */
  50. public $changed = array();
  51. /**
  52. * Array of folder ids that have been deleted on the server.
  53. *
  54. * @var array
  55. */
  56. public $deleted = array();
  57. /**
  58. * Tracks the total number of folder changes
  59. *
  60. * @var integer
  61. */
  62. public $count = 0;
  63. /**
  64. * Const'r
  65. *
  66. * @param Horde_ActiveSync_Wbxml_Encoder $encoder The encoder
  67. * @param string $class The collection class
  68. *
  69. * @return Horde_ActiveSync_Connector_Exporter
  70. */
  71. public function __construct($encoder = null, $class = null)
  72. {
  73. $this->_encoder = $encoder;
  74. $this->_class = $class;
  75. }
  76. /**
  77. * Send a message change over the wbxml stream
  78. *
  79. * @param string $id The uid of the message
  80. * @param Horde_ActiveSync_Message_Base $message The message object
  81. *
  82. * @return boolean
  83. */
  84. public function messageChange($id, $message)
  85. {
  86. /* Just ignore any messages that are not from this collection */
  87. if ($message->getClass() != $this->_class) {
  88. return true;
  89. }
  90. /* Prevent sending the same object twice in one request */
  91. if (in_array($id, $this->_seenObjects)) {
  92. return true;
  93. }
  94. /* Remember this message */
  95. $this->_seenObjects[] = $id;
  96. /* Specify if this is an ADD or a MODIFY change? */
  97. if ($message->flags === false || $message->flags === Horde_ActiveSync::FLAG_NEWMESSAGE) {
  98. $this->_encoder->startTag(Horde_ActiveSync::SYNC_ADD);
  99. } else {
  100. $this->_encoder->startTag(Horde_ActiveSync::SYNC_MODIFY);
  101. }
  102. /* Send the message */
  103. $this->_encoder->startTag(Horde_ActiveSync::SYNC_SERVERENTRYID);
  104. $this->_encoder->content($id);
  105. $this->_encoder->endTag();
  106. $this->_encoder->startTag(Horde_ActiveSync::SYNC_DATA);
  107. $message->encodeStream($this->_encoder);
  108. $this->_encoder->endTag();
  109. $this->_encoder->endTag();
  110. return true;
  111. }
  112. /**
  113. * Stream a message deletion to the PIM
  114. *
  115. * @param string $id The uid of the message we are deleting.
  116. *
  117. * @return boolean
  118. */
  119. public function messageDeletion($id)
  120. {
  121. $this->_encoder->startTag(Horde_ActiveSync::SYNC_REMOVE);
  122. $this->_encoder->startTag(Horde_ActiveSync::SYNC_SERVERENTRYID);
  123. $this->_encoder->content($id);
  124. $this->_encoder->endTag();
  125. $this->_encoder->endTag();
  126. return true;
  127. }
  128. /**
  129. * Change a message's READ flag.
  130. *
  131. * @param string $id The uid
  132. * @param integer $flags The flag
  133. *
  134. * @return boolean
  135. */
  136. public function messageReadFlag($id, $flags)
  137. {
  138. /* This only applies to mail folders */
  139. if ($this->_class != "syncmail") {
  140. return true;
  141. }
  142. /* Encode and stream */
  143. $this->_encoder->startTag(Horde_ActiveSync::SYNC_MODIFY);
  144. $this->_encoder->startTag(Horde_ActiveSync::SYNC_SERVERENTRYID);
  145. $this->_encoder->content($id);
  146. $this->_encoder->endTag();
  147. $this->_encoder->startTag(Horde_ActiveSync::SYNC_DATA);
  148. $this->_encoder->startTag(SYNC_POOMMAIL_READ);
  149. $this->_encoder->content($flags);
  150. $this->_encoder->endTag();
  151. $this->_encoder->endTag();
  152. $this->_encoder->endTag();
  153. return true;
  154. }
  155. /**
  156. * Move a message to a different folder.
  157. * @TODO
  158. * @param Horde_ActiveSync_Message_Base $message The message
  159. *
  160. * @return boolean
  161. */
  162. function messageMove($message)
  163. {
  164. return true;
  165. }
  166. /**
  167. * Add a folder change to the cache. (used during FolderSync Requests).
  168. *
  169. * @param Horde_ActiveSync_Message_Folder $folder
  170. *
  171. * @return boolean
  172. */
  173. public function folderChange($folder)
  174. {
  175. array_push($this->changed, $folder);
  176. $this->count++;
  177. return true;
  178. }
  179. /**
  180. * Add a folder deletion to the cache (used during FolderSync Requests).
  181. *
  182. * @param string $id The folder id
  183. *
  184. * @return boolean
  185. */
  186. public function folderDeletion($id)
  187. {
  188. array_push($this->deleted, $id);
  189. $this->count++;
  190. return true;
  191. }
  192. }