Skip to content

Commit

Permalink
Revert getNamespaces() return to old behavior without 'ob_return' option
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed May 28, 2014
1 parent 10d378e commit dc28531
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 42 deletions.
7 changes: 1 addition & 6 deletions framework/Imap_Client/doc/Horde/Imap/Client/UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,8 @@ Upgrading to 2.21.0

- getNamespaces()

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

Add optional parameter to allow a Horde_Imap_Client_Namespace_List
object to be returned, instead of an array of Data objects.
object to be returned, instead of an array.
(This will become the default action in 3.0.)


Expand Down
94 changes: 60 additions & 34 deletions framework/Imap_Client/lib/Horde/Imap/Client/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -655,9 +655,22 @@ abstract protected function _noop();
* Horde_Imap_Client_Namespace_List object instead of an
* array.
*
* @return mixed An array of namespace objects (@deprecated), or an
* Horde_Imap_Client_Namespace_List object if 'ob_return'
* is true.
* @return mixed A Horde_Imap_Client_Namespace_List object if
* 'ob_return', is true. Otherwise, an array of namespace
* objects (@deprecated) 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>
*
* @throws Horde_Imap_Client_Exception
*/
Expand All @@ -672,46 +685,59 @@ public function getNamespaces(
);

if (isset($this->_init['namespace'][$sig])) {
return empty($opts['ob_return'])
? iterator_to_array($this->_init['namespace'][$sig])
: $this->_init['namespace'][$sig];
}

$this->login();
$ns = $this->_init['namespace'][$sig];
} else {
$this->login();

$ns = $this->_getNamespaces();

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

$ns = $this->_getNamespaces();
if (!count($ns)) {
/* This accurately determines the namespace information of the
* base namespace if the NAMESPACE command is not supported.
* See: RFC 3501 [6.3.8] */
$mbox = $this->listMailboxes('', Horde_Imap_Client::MBOX_ALL, array('delimiter' => true));
$first = reset($mbox);

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

if (!count($ns)) {
/* This accurately determines the namespace information of the
* base namespace if the NAMESPACE command is not supported.
* See: RFC 3501 [6.3.8] */
$mbox = $this->listMailboxes('', Horde_Imap_Client::MBOX_ALL, array('delimiter' => true));
$first = reset($mbox);
$this->_init['namespace'][$sig] = $ns;
$this->_setInit('namespace', $this->_init['namespace']);
}

$ob = new Horde_Imap_Client_Data_Namespace();
$ob->delimiter = $first['delimiter'];
$ns[''] = $ob;
if (!empty($opts['ob_return'])) {
return $ns;
}

$this->_setInit('namespace', array_merge($this->_init['namespace'], array($sig => $ns)));
/* @todo Remove for 3.0 */
$out = array();
foreach ($ns as $key => $val) {
$out[$key] = array(
'delimiter' => $val->delimiter,
'hidden' => $val->hidden,
'name' => $val->name,
'translation' => $val->translation,
'type' => $val->type
);
}

return empty($opts['ob_return'])
? iterator_to_array($ns)
: $ns;
return $out;
}

/**
Expand Down
2 changes: 0 additions & 2 deletions framework/Imap_Client/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [mms] Horde_Imap_Client_Base#getNamespaces() can now return a Horde_Imap_Client_Namespace_List object instead of an array.
* [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 @@ -2441,7 +2440,6 @@
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [mms] Horde_Imap_Client_Base#getNamespaces() can now return a Horde_Imap_Client_Namespace_List object instead of an array.
* [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 dc28531

Please sign in to comment.