/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabpop3account.php

https://github.com/ewandor/horde · PHP · 195 lines · 103 code · 24 blank · 68 comment · 11 complexity · e79e44a2ce8028de8213f180ee540452 MD5 · raw file

  1. <?php
  2. /**
  3. * Represents external pop3 account information.
  4. *
  5. * PHP version 5
  6. *
  7. * @category Kolab
  8. * @package Kolab_Server
  9. * @author Gunnar Wrobel <wrobel@pardus.de>
  10. * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
  11. * @link http://pear.horde.org/index.php?package=Kolab_Server
  12. */
  13. /**
  14. * This class provides a representation of pop3 mail accounts.
  15. *
  16. * Copyright 2008-2012 Horde LLC (http://www.horde.org/)
  17. *
  18. * See the enclosed file COPYING for license information (LGPL). If you
  19. * did not receive this file, see http://www.horde.org/licenses/lgpl21.
  20. *
  21. * @category Kolab
  22. * @package Kolab_Server
  23. * @author Gunnar Wrobel <wrobel@pardus.de>
  24. * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
  25. * @link http://pear.horde.org/index.php?package=Kolab_Server
  26. */
  27. class Horde_Kolab_Server_Object_Kolabpop3account extends Horde_Kolab_Server_Object_Top
  28. {
  29. /** Define attributes specific to this object type */
  30. /** Server the account resides on */
  31. const ATTRIBUTE_SERVER = 'externalPop3AccountServer';
  32. /** User name for the account */
  33. const ATTRIBUTE_LOGINNAME = 'externalPop3AccountLoginName';
  34. /** Password for the account */
  35. const ATTRIBUTE_PASSWORD = 'externalPop3EncryptedAccountPassword';
  36. /** Description of the account */
  37. const ATTRIBUTE_DESCRIPTION = 'externalPop3AccountDescription';
  38. /** Mail address of the account */
  39. const ATTRIBUTE_MAIL = 'externalPop3AccountMail';
  40. /** Port to connect to */
  41. const ATTRIBUTE_PORT = 'externalPop3AccountPort';
  42. /** Use SSL when fetching mail from the account? */
  43. const ATTRIBUTE_USESSL = 'externalPop3AccountUseSSL';
  44. /** Use TLS when fetching mail from the account? */
  45. const ATTRIBUTE_USETLS = 'externalPop3AccountUseTLS';
  46. /** Login method for the external account */
  47. const ATTRIBUTE_LOGINMETHOD = 'externalPop3AccountLoginMethod';
  48. /** Validate the server certificate when connecting via SSL/TLS? */
  49. const ATTRIBUTE_CHECKCERTIFICATE = 'externalPop3AccountCheckServerCertificate';
  50. /** Should the fetched mail be deleted on the external account or not? */
  51. const ATTRIBUTE_KEEPMAILONSERVER = 'externalPop3AccountKeepMailOnServer';
  52. /** The uid of the owner of this account */
  53. const ATTRIBUTE_OWNERUID = 'externalPop3AccountOwnerUid';
  54. /** The specific object class of this object type */
  55. const OBJECTCLASS_KOLABEXTERNALPOP3ACCOUNT = 'kolabExternalPop3Account';
  56. /**
  57. * A structure to initialize the attribute structure for this class.
  58. *
  59. * @var array
  60. */
  61. static public $init_attributes = array(
  62. 'defined' => array(
  63. self::ATTRIBUTE_SERVER,
  64. self::ATTRIBUTE_LOGINNAME,
  65. self::ATTRIBUTE_PASSWORD,
  66. self::ATTRIBUTE_DESCRIPTION,
  67. self::ATTRIBUTE_MAIL,
  68. self::ATTRIBUTE_PORT,
  69. self::ATTRIBUTE_USESSL,
  70. self::ATTRIBUTE_USETLS,
  71. self::ATTRIBUTE_LOGINMETHOD,
  72. self::ATTRIBUTE_CHECKCERTIFICATE,
  73. self::ATTRIBUTE_KEEPMAILONSERVER,
  74. ),
  75. 'derived' => array(
  76. self::ATTRIBUTE_OWNERUID => array(
  77. 'method' => 'getParentUid',
  78. ),
  79. ),
  80. 'collapsed' => array(
  81. self::ATTRIBUTE_OWNERUID => array(
  82. 'base' => array(
  83. self::ATTRIBUTE_OWNERUID
  84. ),
  85. 'method' => 'removeAttribute',
  86. ),
  87. ),
  88. 'required' => array(
  89. self::ATTRIBUTE_MAIL,
  90. self::ATTRIBUTE_SERVER,
  91. self::ATTRIBUTE_LOGINNAME,
  92. self::ATTRIBUTE_PASSWORD,
  93. ),
  94. 'object_classes' => array(
  95. self::OBJECTCLASS_KOLABEXTERNALPOP3ACCOUNT,
  96. ),
  97. );
  98. /**
  99. * Generates an ID for the given information.
  100. *
  101. * @param array &$info The data of the object.
  102. *
  103. * @return string|PEAR_Error The ID.
  104. */
  105. public function generateId(array &$info)
  106. {
  107. if (!isset($info[self::ATTRIBUTE_OWNERUID])) {
  108. $uid = $this->get(self::ATTRIBUTE_OWNERUID);
  109. if (empty($uid)) {
  110. throw new Horde_Kolab_Server_Exception("No parent object provided!",
  111. Horde_Kolab_Server_Exception::INVALID_INFORMATION);
  112. }
  113. } else {
  114. if (is_array($info[self::ATTRIBUTE_OWNERUID])) {
  115. $uid = $info[self::ATTRIBUTE_OWNERUID][0];
  116. } else {
  117. $uid = $info[self::ATTRIBUTE_OWNERUID];
  118. }
  119. }
  120. $object = $this->server->fetch($uid);
  121. if (!$object->exists()) {
  122. throw new Horde_Kolab_Server_Exception(sprintf("The parent object %s does not exist!",
  123. $uid),
  124. Horde_Kolab_Server_Exception::INVALID_INFORMATION);
  125. }
  126. if (!isset($info[self::ATTRIBUTE_MAIL])) {
  127. $mail = $this->get(self::ATTRIBUTE_MAIL);
  128. if (empty($mail)) {
  129. throw new Horde_Kolab_Server_Exception("No mail given!",
  130. Horde_Kolab_Server_Exception::INVALID_INFORMATION);
  131. }
  132. } else {
  133. if (is_array($info[self::ATTRIBUTE_MAIL])) {
  134. $mail = $info[self::ATTRIBUTE_MAIL][0];
  135. } else {
  136. $mail = $info[self::ATTRIBUTE_MAIL];
  137. }
  138. }
  139. $base = substr($uid, 0, strpos($uid, $this->server->getBaseUid()) - 1);
  140. unset($info[self::ATTRIBUTE_OWNERUID]);
  141. return self::ATTRIBUTE_MAIL . '=' . $this->server->structure->quoteForUid($mail) . ',' . $base;
  142. }
  143. /**
  144. * Returns the set of search operations supported by this object type.
  145. *
  146. * @return array An array of supported search operations.
  147. */
  148. static public function getSearchOperations()
  149. {
  150. $searches = array(
  151. /* 'pop3AccountsForMail', */
  152. );
  153. return $searches;
  154. }
  155. /**
  156. * Returns the UIDs of the pop3 accounts for the user with the given mail
  157. * address.
  158. *
  159. * @param Horde_Kolab_Server $server The server to query.
  160. * @param string $mail Search objects with this mail alias.
  161. *
  162. * @return mixed The UIDs or false if there was no result.
  163. *
  164. * @throws Horde_Kolab_Server_Exception
  165. */
  166. static public function pop3AccountsForMail($server, $mail)
  167. {
  168. $uid = $server->uidForMail($mail, Horde_Kolab_Server_Object::RESULT_SINGLE);
  169. return self::objectsForUid($server, $uid, self::OBJECTCLASS_KOLABEXTERNALPOP3ACCOUNT);
  170. }
  171. }