Skip to content

Commit

Permalink
[mms] Horde_Imap_Client_Base#getNamespaces() now returns Horde_Imap_C…
Browse files Browse the repository at this point in the history
…lient_Data_Namespace objects instead of an array.

Start moving some code from Horde_Imap_Client 3 that is not BC-breaking
  • Loading branch information
slusarz committed May 27, 2014
1 parent a55b82f commit 5c22f76
Show file tree
Hide file tree
Showing 8 changed files with 358 additions and 53 deletions.
19 changes: 19 additions & 0 deletions framework/Imap_Client/doc/Horde/Imap/Client/UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,25 @@
This lists the API changes between releases of the package.


Upgrading to 2.21.0
===================

- Horde_Imap_Client

These constants have been deprecated:
- NS_PERSONAL
- NS_OTHER
- NS_SHARED

- Horde_Imap_Client_Base

- getNamespaces()

Returns Horde_Imap_Client_Data_Namespace objects instead of an array.
(Existing code should not need to change, as this object is backward
compatibile with the previous array data structure.)


Upgrading to 2.20.0
===================

Expand Down
2 changes: 1 addition & 1 deletion framework/Imap_Client/lib/Horde/Imap/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class Horde_Imap_Client
/* @since 2.11.0 */
const FETCH_DOWNGRADED = 16;

/* Namespace constants. */
/* Namespace constants. @deprecated */
const NS_PERSONAL = 1;
const NS_OTHER = 2;
const NS_SHARED = 3;
Expand Down
48 changes: 17 additions & 31 deletions framework/Imap_Client/lib/Horde/Imap/Client/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -651,20 +651,9 @@ abstract protected function _noop();
* the server. The namespaces must be UTF-8
* strings.
*
* @return array An array of namespace information with the name as the
* key (UTF-8) and the following values:
* <pre>
* - delimiter: (string) The namespace delimiter.
* - hidden: (boolean) Is this a hidden namespace?
* - name: (string) The namespace name (UTF-8).
* - translation: (string) Returns the translated name of the namespace
* (UTF-8). Requires RFC 5255 and a previous call to
* setLanguage().
* - type: (integer) The namespace type. Either:
* - Horde_Imap_Client::NS_PERSONAL
* - Horde_Imap_Client::NS_OTHER
* - Horde_Imap_Client::NS_SHARED
* </pre>
* @return array An array with the name as the key (UTF-8; @deprecated)
* and a Horde_Imap_Client_Data_Namespace object as the
* value.
*
* @throws Horde_Imap_Client_Exception
*/
Expand All @@ -686,16 +675,16 @@ public function getNamespaces(array $additional = array())

/* Skip namespaces if we have already auto-detected them. Also, hidden
* namespaces cannot be empty. */
$to_process = array_diff(array_filter($additional, 'strlen'), array_keys($ns));;
$to_process = array_diff(array_filter($additional, 'strlen'), array_map('strlen', $ns));
if (!empty($to_process)) {
foreach ($this->listMailboxes($to_process, Horde_Imap_Client::MBOX_ALL, array('delimiter' => true)) as $val) {
$ns[$val] = array(
'delimiter' => $val['delimiter'],
'hidden' => true,
'name' => $val,
'translation' => '',
'type' => Horde_Imap_Client::NS_SHARED
);
$ob = new Horde_Imap_Client_Data_Namespace();
$ob->delimiter = $val['delimiter'];
$ob->hidden = true;
$ob->name = $val;
$ob->type = $ob::NS_SHARED;
// @todo: Remove key in 3.0
$ns[$val] = $ob;
}
}

Expand All @@ -705,13 +694,11 @@ public function getNamespaces(array $additional = array())
* See: RFC 3501 [6.3.8] */
$mbox = $this->listMailboxes('', Horde_Imap_Client::MBOX_ALL, array('delimiter' => true));
$first = reset($mbox);
$ns[''] = array(
'delimiter' => $first['delimiter'],
'hidden' => false,
'name' => '',
'translation' => '',
'type' => Horde_Imap_Client::NS_PERSONAL
);

$ob = new Horde_Imap_Client_Data_Namespace();
$ob->delimiter = $first['delimiter'];
// @todo: Remove key in 3.0
$ns[''] = $ob;
}

$this->_setInit('namespace', array_merge($this->_init['namespace'], array($sig => $ns)));
Expand All @@ -722,8 +709,7 @@ public function getNamespaces(array $additional = array())
/**
* Get the NAMESPACE information from the IMAP server.
*
* @return array An array of namespace information. See getNamespaces()
* for format.
* @return array An array of Horde_Imap_Client_Data_Namespace objects.
*
* @throws Horde_Imap_Client_Exception
*/
Expand Down
151 changes: 151 additions & 0 deletions framework/Imap_Client/lib/Horde/Imap/Client/Data/Namespace.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?php
/**
* Copyright 2013-2014 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @copyright 2013-2014 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Imap_Client
*/

/**
* Namespace data.
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2013-2014 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Imap_Client
* @since 2.21.0
*
* @property string $delimiter The namespace delimiter.
* @property boolean $hidden Is this a hidden namespace?
* @property string $name The namespace name (UTF-8).
* @property string $translation Returns the translated name of the namespace
* (UTF-8).
* @property integer $type The namespace type. Either self::NS_PERSONAL,
* self::NS_OTHER, or self::NS_SHARED.
*/
class Horde_Imap_Client_Data_Namespace implements ArrayAccess, Serializable
{
/* Namespace type constants. */
const NS_PERSONAL = 1;
const NS_OTHER = 2;
const NS_SHARED = 3;

/**
* Data object.
*
* @var array
*/
protected $_data = array();

/**
*/
public function __get($name)
{
if (isset($this->_data[$name])) {
return $this->_data[$name];
}

switch ($name) {
case 'delimiter':
case 'name':
case 'translation':
return '';

case 'hidden':
return false;

case 'type':
return self::NS_PERSONAL;
}

return null;
}

/**
*/
public function __set($name, $value)
{
switch ($name) {
case 'delimiter':
case 'name':
case 'translation':
$this->_data[$name] = strval($value);
break;

case 'hidden':
$this->_data[$name] = (bool)$value;
break;

case 'type':
$this->_data[$name] = intval($value);
break;
}
}

/**
*/
public function __isset($name)
{
return isset($this->_data[$name]);
}

/**
*/
public function __toString()
{
return $this->name;
}

/* ArrayAccess methods (for BC). @deprecated */

/**
*/
public function offsetExists($offset)
{
return !is_null($this->$offset);
}

/**
*/
public function offsetGet($offset)
{
return $this->$offset;
}

/**
*/
public function offsetSet($offset, $value)
{
$this->$offset = $value;
}

/**
*/
public function offsetUnset($offset)
{
unset($this->_data[$offset]);
}

/* Serializable methods. */

/**
*/
public function serialize()
{
return json_encode($this->_data);
}

/**
*/
public function unserialize($data)
{
$this->_data = json_decode($data, true);
}

}
21 changes: 10 additions & 11 deletions framework/Imap_Client/lib/Horde/Imap/Client/Socket.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ protected function _parseNamespace(
)
{
$namespace_array = array(
Horde_Imap_Client::NS_PERSONAL,
Horde_Imap_Client::NS_OTHER,
Horde_Imap_Client::NS_SHARED
Horde_Imap_Client_Data_Namespace::NS_PERSONAL,
Horde_Imap_Client_Data_Namespace::NS_OTHER,
Horde_Imap_Client_Data_Namespace::NS_SHARED
);

$c = array();
Expand All @@ -306,21 +306,20 @@ protected function _parseNamespace(
while ($data->next() !== false) {
$ob = Horde_Imap_Client_Mailbox::get($data->next(), true);

$c[strval($ob)] = array(
'delimiter' => $data->next(),
'hidden' => false,
'name' => strval($ob),
'translation' => '',
'type' => $val
);
$ns = new Horde_Imap_Client_Data_Namespace();
$ns->delimiter = $data->next();
$ns->name = strval($ob);
$ns->type = $val;
// @todo: Remove key in 3.0
$c[strval($ob)] = $ns;

// RFC 4466: NAMESPACE extensions
while (($ext = $data->next()) !== false) {
switch (strtoupper($ext)) {
case 'TRANSLATION':
// RFC 5255 [3.4] - TRANSLATION extension
$data->next();
$c[strval($ob)]['translation'] = $data->next();
$ns->translation = $data->next();
$data->next();
break;
}
Expand Down
18 changes: 12 additions & 6 deletions framework/Imap_Client/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@
<email>slusarz@horde.org</email>
<active>yes</active>
</lead>
<date>2014-05-21</date>
<date>2014-05-26</date>
<version>
<release>2.20.1</release>
<api>2.20.0</api>
<release>2.21.0</release>
<api>2.21.0</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [mms] Horde_Imap_Client_Base#getNamespaces() now returns Horde_Imap_Client_Data_Namespace objects instead of an array.
* [mms] Use the new command length limitations defined in RFC 7162.
* [mms] A noop() call before authentication will now correctly throw an exception on a connection issue (Bug #13205).
</notes>
Expand Down Expand Up @@ -92,6 +93,7 @@
<file name="Envelope.php" role="php" />
<file name="Fetch.php" role="php" />
<file name="Format.php" role="php" />
<file name="Namespace.php" role="php" />
<file name="Sync.php" role="php" />
<file name="Thread.php" role="php" />
</dir> <!-- /lib/Horde/Imap/Client/Data -->
Expand Down Expand Up @@ -256,6 +258,7 @@
<file name="NumberTest.php" role="test" />
<file name="StringTest.php" role="test" />
</dir> <!-- /test/Horde/Imap/Client/Data/Format -->
<file name="NamespaceTest.php" role="test" />
</dir> <!-- /test/Horde/Imap/Client/Data -->
<dir name="fixtures">
<file name="bug_10503.txt" role="test" />
Expand Down Expand Up @@ -473,6 +476,7 @@
<install as="Horde/Imap/Client/Data/Envelope.php" name="lib/Horde/Imap/Client/Data/Envelope.php" />
<install as="Horde/Imap/Client/Data/Fetch.php" name="lib/Horde/Imap/Client/Data/Fetch.php" />
<install as="Horde/Imap/Client/Data/Format.php" name="lib/Horde/Imap/Client/Data/Format.php" />
<install as="Horde/Imap/Client/Data/Namespace.php" name="lib/Horde/Imap/Client/Data/Namespace.php" />
<install as="Horde/Imap/Client/Data/Sync.php" name="lib/Horde/Imap/Client/Data/Sync.php" />
<install as="Horde/Imap/Client/Data/Thread.php" name="lib/Horde/Imap/Client/Data/Thread.php" />
<install as="Horde/Imap/Client/Data/Fetch/Pop3.php" name="lib/Horde/Imap/Client/Data/Fetch/Pop3.php" />
Expand Down Expand Up @@ -563,6 +567,7 @@
<install as="Horde/Imap/Client/Cache/HashtableTest.php" name="test/Horde/Imap/Client/Cache/HashtableTest.php" />
<install as="Horde/Imap/Client/Cache/MongoTest.php" name="test/Horde/Imap/Client/Cache/MongoTest.php" />
<install as="Horde/Imap/Client/Cache/TestBase.php" name="test/Horde/Imap/Client/Cache/TestBase.php" />
<install as="Horde/Imap/Client/Data/NamespaceTest.php" name="test/Horde/Imap/Client/Data/NamespaceTest.php" />
<install as="Horde/Imap/Client/Data/Format/AstringTest.php" name="test/Horde/Imap/Client/Data/Format/AstringTest.php" />
<install as="Horde/Imap/Client/Data/Format/AtomTest.php" name="test/Horde/Imap/Client/Data/Format/AtomTest.php" />
<install as="Horde/Imap/Client/Data/Format/DateTest.php" name="test/Horde/Imap/Client/Data/Format/DateTest.php" />
Expand Down Expand Up @@ -2418,14 +2423,15 @@
</release>
<release>
<version>
<release>2.20.1</release>
<api>2.20.0</api></version>
<release>2.21.0</release>
<api>2.21.0</api></version>
<stability>
<release>stable</release>
<api>stable</api></stability>
<date>2014-05-21</date>
<date>2014-05-26</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [mms] Horde_Imap_Client_Base#getNamespaces() now returns Horde_Imap_Client_Data_Namespace objects instead of an array.
* [mms] Use the new command length limitations defined in RFC 7162.
* [mms] A noop() call before authentication will now correctly throw an exception on a connection issue (Bug #13205).
</notes>
Expand Down

0 comments on commit 5c22f76

Please sign in to comment.