PageRenderTime 59ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/tine20/Felamimail/Model/Folder.php

https://github.com/corneliusweiss/Tine-2.0-Open-Source-Groupware-and-CRM
PHP | 231 lines | 96 code | 21 blank | 114 comment | 10 complexity | f27b6f120c7c43acc40175a0207a6f30 MD5 | raw file
  1. <?php
  2. /**
  3. * class to hold Folder data
  4. *
  5. * @package Felamimail
  6. * @subpackage Model
  7. * @license http://www.gnu.org/licenses/agpl.html AGPL Version 3
  8. * @author Philipp Schüle <p.schuele@metaways.de>
  9. * @copyright Copyright (c) 2009-2012 Metaways Infosystems GmbH (http://www.metaways.de)
  10. *
  11. * @todo rename unreadcount -> unseen
  12. */
  13. /**
  14. * class to hold Folder data
  15. *
  16. * @package Felamimail
  17. * @subpackage Model
  18. *
  19. * @property string account_id
  20. * @property string localname
  21. * @property string globalname
  22. * @property boolean has_children
  23. * @property boolean is_selectable
  24. * @property boolean supports_condstore
  25. * @property integer imap_lastmodseq
  26. */
  27. class Felamimail_Model_Folder extends Tinebase_Record_Abstract
  28. {
  29. /**
  30. * imap status: ok
  31. *
  32. */
  33. const IMAP_STATUS_OK = 'ok';
  34. /**
  35. * imap status: disconnected
  36. *
  37. */
  38. const IMAP_STATUS_DISCONNECT = 'disconnect';
  39. /**
  40. * cache status: empty
  41. *
  42. */
  43. const CACHE_STATUS_EMPTY = 'empty';
  44. /**
  45. * cache status: complete
  46. *
  47. */
  48. const CACHE_STATUS_COMPLETE = 'complete';
  49. /**
  50. * cache status: updating
  51. *
  52. */
  53. const CACHE_STATUS_UPDATING = 'updating';
  54. /**
  55. * cache status: incomplete
  56. *
  57. */
  58. const CACHE_STATUS_INCOMPLETE = 'incomplete';
  59. /**
  60. * cache status: invalid
  61. *
  62. */
  63. const CACHE_STATUS_INVALID = 'invalid';
  64. /**
  65. * meta folder trash constant
  66. */
  67. const FOLDER_TRASH = '_trash_';
  68. /**
  69. * meta folder sent constant
  70. */
  71. const FOLDER_SENT = '_sent_';
  72. /**
  73. * meta folder drafts constant
  74. */
  75. const FOLDER_DRAFTS = '_drafts_';
  76. /**
  77. * meta folder templates constant
  78. */
  79. const FOLDER_TEMPLATES = '_templates_';
  80. /**
  81. * key in $_validators/$_properties array for the field which
  82. * represents the identifier
  83. *
  84. * @var string
  85. */
  86. protected $_identifier = 'id';
  87. /**
  88. * application the record belongs to
  89. *
  90. * @var string
  91. */
  92. protected $_application = 'Felamimail';
  93. /**
  94. * list of zend validator
  95. *
  96. * this validators get used when validating user generated content with Zend_Input_Filter
  97. *
  98. * @var array
  99. */
  100. protected $_validators = array(
  101. 'id' => array(Zend_Filter_Input::ALLOW_EMPTY => true),
  102. 'localname' => array(Zend_Filter_Input::ALLOW_EMPTY => false),
  103. 'globalname' => array(Zend_Filter_Input::ALLOW_EMPTY => false), // global name is the path from root folder
  104. 'parent' => array(Zend_Filter_Input::ALLOW_EMPTY => true), // global name of parent folder
  105. 'account_id' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::DEFAULT_VALUE => 'default'),
  106. 'delimiter' => array(Zend_Filter_Input::ALLOW_EMPTY => true),
  107. 'is_selectable' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::DEFAULT_VALUE => 1),
  108. 'has_children' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::DEFAULT_VALUE => 0),
  109. 'supports_condstore' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::DEFAULT_VALUE => 0),
  110. 'recent' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::DEFAULT_VALUE => 0),
  111. 'system_folder' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::DEFAULT_VALUE => 0),
  112. // imap values
  113. 'imap_status' => array(
  114. Zend_Filter_Input::ALLOW_EMPTY => true,
  115. Zend_Filter_Input::DEFAULT_VALUE => self::IMAP_STATUS_OK,
  116. array('InArray', array(self::IMAP_STATUS_OK, self::IMAP_STATUS_DISCONNECT)),
  117. ),
  118. 'imap_uidvalidity' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::DEFAULT_VALUE => 0),
  119. 'imap_totalcount' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::DEFAULT_VALUE => 0),
  120. 'imap_timestamp' => array(Zend_Filter_Input::ALLOW_EMPTY => true),
  121. // used for CONDSTORE flag sync
  122. 'imap_lastmodseq' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::DEFAULT_VALUE => 1),
  123. // cache values
  124. 'cache_status' => array(
  125. Zend_Filter_Input::ALLOW_EMPTY => true,
  126. Zend_Filter_Input::DEFAULT_VALUE => self::CACHE_STATUS_EMPTY,
  127. array('InArray', array(
  128. self::CACHE_STATUS_EMPTY,
  129. self::CACHE_STATUS_COMPLETE,
  130. self::CACHE_STATUS_INCOMPLETE,
  131. self::CACHE_STATUS_UPDATING
  132. )),
  133. ),
  134. 'cache_uidvalidity' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::DEFAULT_VALUE => 0),
  135. 'cache_totalcount' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::DEFAULT_VALUE => 0),
  136. 'cache_recentcount' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::DEFAULT_VALUE => 0),
  137. 'cache_unreadcount' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::DEFAULT_VALUE => 0),
  138. 'cache_timestamp' => array(Zend_Filter_Input::ALLOW_EMPTY => true),
  139. 'cache_job_lowestuid' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::DEFAULT_VALUE => 0),
  140. 'cache_job_startuid' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::DEFAULT_VALUE => 0),
  141. // estimated number of actions when updating cache
  142. 'cache_job_actions_est' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::DEFAULT_VALUE => 0),
  143. // number of actions done when updating cache
  144. 'cache_job_actions_done' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::DEFAULT_VALUE => 0),
  145. // quota information
  146. 'quota_usage' => array(Zend_Filter_Input::ALLOW_EMPTY => true),
  147. 'quota_limit' => array(Zend_Filter_Input::ALLOW_EMPTY => true),
  148. );
  149. /**
  150. * name of fields containing datetime or or an array of datetime information
  151. *
  152. * @var array list of datetime fields
  153. */
  154. protected $_datetimeFields = array(
  155. 'cache_timestamp',
  156. 'imap_timestamp',
  157. );
  158. /**
  159. * encode foldername given by user (convert to UTF7-IMAP)
  160. *
  161. * @param string $_folderName
  162. * @return string
  163. */
  164. public static function encodeFolderName($_folderName)
  165. {
  166. if (extension_loaded('mbstring')) {
  167. $result = mb_convert_encoding($_folderName, "UTF7-IMAP", "utf-8");
  168. } else if (extension_loaded('imap')) {
  169. $result = imap_utf7_encode(iconv('utf-8', 'ISO-8859-1', $_folderName));
  170. } else {
  171. // fallback
  172. $result = Tinebase_Helper::replaceSpecialChars($_folderName);
  173. }
  174. return $result;
  175. }
  176. /**
  177. * decode foldername given by IMAP server (convert from UTF7-IMAP to UTF8)
  178. *
  179. * @param string $_folderName
  180. * @return string
  181. */
  182. public static function decodeFolderName($_folderName)
  183. {
  184. if (extension_loaded('mbstring')) {
  185. $result = mb_convert_encoding($_folderName, "utf-8", "UTF7-IMAP");
  186. } else if (extension_loaded('imap')) {
  187. $result = iconv('ISO-8859-1', 'utf-8', imap_utf7_decode($_folderName));
  188. } else {
  189. // fallback
  190. $result = Tinebase_Helper::replaceSpecialChars($_folderName);
  191. }
  192. return $result;
  193. }
  194. /**
  195. * extract localname and parent globalname
  196. *
  197. * @param string $_folderName
  198. * @return array
  199. */
  200. public static function extractLocalnameAndParent($_folderName, $_delimiter)
  201. {
  202. $globalNameParts = ($_delimiter && $_delimiter != '') ? explode($_delimiter, $_folderName) : array($_folderName);
  203. $localname = array_pop($globalNameParts);
  204. $parent = (count($globalNameParts) > 0) ? implode($_delimiter, $globalNameParts) : '';
  205. return array(
  206. 'localname' => $localname,
  207. 'parent' => $parent,
  208. );
  209. }
  210. }