Skip to content

Commit

Permalink
Directly use Horde_Imap_Client_Data_Namespace objects
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed May 27, 2014
1 parent 0a632e4 commit f8e275b
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 47 deletions.
10 changes: 5 additions & 5 deletions imp/lib/Basic/Folders.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@ protected function _init()
for ($i = 0; $i < $iMax; ++$i) {
$old_name = IMP_Mailbox::formFrom($old_names[$i]);
$old_ns = $old_name->namespace_info;
$new = trim($new_names[$i], $old_ns['delimiter']);
$new = trim($new_names[$i], $old_ns->delimiter);

/* If this is a personal namespace, then anything goes as
* far as the input. Just append the personal namespace to
* it. */
if (($old_ns['type'] == Horde_Imap_Client::NS_PERSONAL) ||
($old_ns['name'] &&
(stripos($new_names[$i], $old_ns['name']) !== 0))) {
$new = $old_ns['name'] . $new;
if (($old_ns->type === $old_ns::NS_PERSONAL) ||
(strlen($old_ns->name) &&
(stripos($new_names[$i], $old_ns->name) !== 0))) {
$new = $old_ns->name . $new;
}

$old_name->rename($new);
Expand Down
18 changes: 8 additions & 10 deletions imp/lib/Basic/Mailbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,17 +321,15 @@ protected function _init()
if ($mailbox->inbox) {
$rss_box = '';
} else {
$rss_box = $mailbox;
$ns_info = $imp_imap->getNamespace($mailbox);
if ($ns_info !== null) {
if (!empty($ns_info['name']) &&
($ns_info['type'] == Horde_Imap_Client::NS_PERSONAL) &&
substr($mailbox, 0, strlen($ns_info['name'])) == $ns_info['name']) {
$rss_box = substr($mailbox, strlen($ns_info['name']));
}
$rss_box = str_replace(rawurlencode($ns_info['delimiter']), '/', rawurlencode($ns_info['delimiter'] . $rss_box));
} else {
$ns_info = $mailbox->namespace_info;
if (is_null($ns_info)) {
$rss_box = null;
} else {
$rss_box = str_replace(
rawurlencode($ns_info->delimiter),
'/',
rawurlencode($ns_info->delimiter . (($ns_info->type == $ns_info::NS_PERSONAL) ? $ns_info->stripNamespace($mailbox) : $mailbox))
);
}
}

Expand Down
16 changes: 8 additions & 8 deletions imp/lib/Ftree/Account/Imap.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,23 @@ public function getList($query = null)
* step through the name to make sure all subfolders exist
* in the tree. */
if (strlen($val['delimiter'])) {
/* Strip personal namespace. */
if (!empty($ns_info['name']) &&
(strpos($mbox, $ns_info['name']) === 0)) {
$parts = explode($val['delimiter'], substr($mbox, strlen($ns_info['name'])));
$parts[0] = $ns_info['name'] . $parts[0];
/* Strip personal namespace (if non-empty). */
if (($ns_info->type === $ns_info::NS_PERSONAL) &&
strlen($ns_info->name)) {
$parts = explode($val['delimiter'], $ns_info->stripNamespace($mbox));
$parts[0] = $ns_info->name . $parts[0];
} else {
$parts = explode($val['delimiter'], $mbox);
}

switch ($ns_info['type']) {
case Horde_Imap_Client::NS_OTHER:
switch ($ns_info->type) {
case $ns_info::NS_OTHER:
if ($prefs->getValue('tree_view')) {
$parent = self::OTHER_KEY;
}
break;

case Horde_Imap_Client::NS_SHARED:
case $ns_info::NS_SHARED:
if ($prefs->getValue('tree_view')) {
$parent = self::SHARED_KEY;
}
Expand Down
5 changes: 3 additions & 2 deletions imp/lib/Ftree/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
* element.
* @property-read boolean $namespace True if this is a namespace container
* element.
* @property-read array $namespace_info Namespace info.
* @property-read Horde_Imap_Client_Data_Namespace $namespace_info Namespace
* info.
* @property-read boolean $namespace_other True if this is an 'Other'
* namespace.
* @property-read boolean $namespace_shared True if this is a 'Shared'
Expand Down Expand Up @@ -115,7 +116,7 @@ public function __get($name)
case 'level':
return ($this->base_elt)
? 0
: substr_count($this->_id, $this->namespace_info['delimiter']);
: substr_count($this->_id, $this->namespace_info->delimiter);

case 'mbox_ob':
return IMP_Mailbox::get($this->_id);
Expand Down
41 changes: 20 additions & 21 deletions imp/lib/Mailbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
* namespace information appended.
* @property-read string $namespace_delimiter The delimiter for this
* namespace.
* @property-read array $namespace_info See IMP_Imap::getNamespace().
* @property-read Horde_Imap_Client_Data_Namespace $namespace_info Namespace
* info.
* @property-read boolean $nonimap Is this a non-IMAP element?
* @property-read IMP_Mailbox $parent The parent element. Returns null if no
* parent. (Base of tree is returned as
Expand Down Expand Up @@ -473,14 +474,14 @@ public function __get($key)
* If a non-default namespace is empty, then we must always use
* default namespace. */
if (!is_null($empty_ns) &&
($def_ns['name'] == $empty_ns['name'])) {
($def_ns->name == $empty_ns->name)) {
return $this;
}

$ns_info = $this->namespace_info;

if (is_null($ns_info) || !is_null($empty_ns)) {
return self::get($def_ns['name'] . $this->_mbox);
return self::get($def_ns->name . $this->_mbox);
}

return $this;
Expand Down Expand Up @@ -1297,8 +1298,8 @@ public function createMailboxName($new)
} else {
$ns_info = $this->namespace_info;
$new = strlen($this)
? ($this->_mbox . $ns_info['delimiter'] . $new)
: $ns_info['name'] . $new;
? ($this->_mbox . $ns_info->delimiter . $new)
: $ns_info->name . $new;
}

return self::get($new);
Expand Down Expand Up @@ -1396,13 +1397,13 @@ static public function prefFrom($mbox)
$empty_ns = $imp_imap->getNamespace('');

if (!is_null($empty_ns) &&
(strpos($mbox, $empty_ns['delimiter']) === 0)) {
(strpos($mbox, $empty_ns->delimiter) === 0)) {
/* Prefixed with delimiter => from empty namespace. */
return substr($mbox, strlen($empty_ns['delimiter']));
return substr($mbox, strlen($empty_ns->delimiter));
} elseif ($imp_imap->getNamespace($mbox, true) === null) {
/* No namespace prefix => from personal namespace. */
$def_ns = $imp_imap->getNamespace($imp_imap::NS_DEFAULT);
return $def_ns['name'] . $mbox;
return $def_ns->name . $mbox;
}

return $mbox;
Expand Down Expand Up @@ -1430,14 +1431,14 @@ static public function prefTo($mbox)
$imp_imap = $injector->getInstance('IMP_Factory_Imap')->create();
$def_ns = $imp_imap->getNamespace($imp_imap::NS_DEFAULT);

if ($ns['name'] == $def_ns['name']) {
if ($ns->name == $def_ns->name) {
/* From personal namespace => strip namespace. */
$ret = substr($mbox_str, strlen($def_ns['name']));
$ret = substr($mbox_str, strlen($def_ns->name));
} else {
$empty_ns = $imp_imap->getNamespace('');
if ($ns['name'] == $empty_ns['name']) {
if ($ns->name == $empty_ns->name) {
/* From empty namespace => prefix with delimiter. */
$ret = $empty_ns['delimiter'] . $mbox_str;
$ret = $empty_ns->delimiter . $mbox_str;
}
}
}
Expand Down Expand Up @@ -1531,16 +1532,14 @@ protected function _getDisplay($notranslate = false)

if (!is_null($ns_info)) {
/* Return translated namespace information. */
if (!empty($ns_info['translation']) && $this->namespace) {
$cache->setDisplay($this->_mbox, $ns_info['translation']);
return $ns_info['translation'];
if (strlen($ns_info->translation) && $this->namespace) {
$cache->setDisplay($this->_mbox, $ns_info->translation);
return $ns_info->translation;
}

/* Strip namespace information. */
if (!empty($ns_info['name']) &&
($ns_info['type'] == Horde_Imap_Client::NS_PERSONAL) &&
(substr($this->_mbox, 0, strlen($ns_info['name'])) == $ns_info['name'])) {
$out = substr($this->_mbox, strlen($ns_info['name']));
/* Strip personal namespace information. */
if ($ns_info->type === $ns_info::NS_PERSONAL) {
$out = $ns_info->stripNamespace($this->_mbox);
}
}

Expand Down Expand Up @@ -1594,7 +1593,7 @@ protected function _getDisplay($notranslate = false)
(($key != 'INBOX') || ($this->_mbox == $out)) &&
strpos($this->_mbox, $key) === 0) {
$len = strlen($key);
if ((strlen($this->_mbox) == $len) || ($this->_mbox[$len] == (is_null($ns_info) ? '' : $ns_info['delimiter']))) {
if ((strlen($this->_mbox) == $len) || ($this->_mbox[$len] == (is_null($ns_info) ? '' : $ns_info->delimiter))) {
$out = substr_replace($this->_mbox, $val, 0, $len);
break;
}
Expand Down
2 changes: 1 addition & 1 deletion imp/rss.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
$request_parts = explode('/-/', $request);
if (!empty($request_parts[0])) {
$ns_info = $mailbox->imp_imap->getNamespace(IMP_Imap::NS_DEFAULT);
$mailbox = IMP_Mailbox::get(preg_replace('/\//', $ns_info['delimiter'], trim($request_parts[0], '/')))->namespace_append;
$mailbox = IMP_Mailbox::get(preg_replace('/\//', $ns_info->delimiter, trim($request_parts[0], '/')))->namespace_append;

/* Make sure mailbox exists or else exit immediately. */
if (!$mailbox->exists) {
Expand Down

0 comments on commit f8e275b

Please sign in to comment.