Fix bug where folder creation could fail if personal namespace contained more than one entry (#5403)

+ small code improvements
pull/5393/head^2
Aleksander Machniak 8 years ago
parent 99cb08c41c
commit 32e5a6bbcf

@ -47,6 +47,7 @@ CHANGELOG Roundcube Webmail
- Fix E_DEPRECATED warning when using Auth_SASL::factory() (#5401) - Fix E_DEPRECATED warning when using Auth_SASL::factory() (#5401)
- Fix bug where names of downloaded files could be malformed when derived from the message subject (#5404) - Fix bug where names of downloaded files could be malformed when derived from the message subject (#5404)
- Fix so "All" messages selection is resetted on search reset (#5413) - Fix so "All" messages selection is resetted on search reset (#5413)
- Fix bug where folder creation could fail if personal namespace contained more than one entry (#5403)
RELEASE 1.2.1 RELEASE 1.2.1
------------- -------------

@ -1473,7 +1473,7 @@ class rcmail extends rcube
$prefix = ''; $prefix = '';
if (!$path) { if (!$path) {
$n_folder = $folder; $n_folder = $folder;
$folder = $this->storage->mod_folder($folder); $folder = $this->storage->mod_folder($folder);
if ($n_folder != $folder) { if ($n_folder != $folder) {
$prefix = substr($n_folder, 0, -strlen($folder)); $prefix = substr($n_folder, 0, -strlen($folder));
@ -1507,10 +1507,11 @@ class rcmail extends rcube
if (!isset($arrFolders[$currentFolder])) { if (!isset($arrFolders[$currentFolder])) {
$arrFolders[$currentFolder] = array( $arrFolders[$currentFolder] = array(
'id' => $path, 'id' => $path,
'name' => rcube_charset::convert($currentFolder, 'UTF7-IMAP'), 'name' => rcube_charset::convert($currentFolder, 'UTF7-IMAP'),
'virtual' => $virtual, 'virtual' => $virtual,
'folders' => array()); 'folders' => array()
);
} }
else { else {
$arrFolders[$currentFolder]['virtual'] = $virtual; $arrFolders[$currentFolder]['virtual'] = $virtual;

@ -454,7 +454,8 @@ class rcube_imap extends rcube_storage
return isset($ns[$name]) ? $ns[$name] : null; return isset($ns[$name]) ? $ns[$name] : null;
} }
unset($ns['prefix']); unset($ns['prefix_in'], $ns['prefix_out']);
return $ns; return $ns;
} }
@ -528,10 +529,24 @@ class rcube_imap extends rcube_storage
} }
} }
// Find personal namespace prefix for mod_folder() // Find personal namespace prefix(es) for self::mod_folder()
// Prefix can be removed when there is only one personal namespace if (is_array($this->namespace['personal']) && !empty($this->namespace['personal'])) {
if (is_array($this->namespace['personal']) && count($this->namespace['personal']) == 1) { // There can be more than one namespace root,
$this->namespace['prefix'] = $this->namespace['personal'][0][0]; // - for prefix_out get the first one but only
// if there is only one root
// - for prefix_in get the first one but only
// if there is no non-prefixed namespace root (#5403)
$roots = array();
foreach ($this->namespace['personal'] as $ns) {
$roots[] = $ns[0];
}
if (!in_array('', $roots)) {
$this->namespace['prefix_in'] = $roots[0];
}
if (count($roots) == 1) {
$this->namespace['prefix_out'] = $roots[0];
}
} }
$_SESSION['imap_namespace'] = $this->namespace; $_SESSION['imap_namespace'] = $this->namespace;
@ -3478,26 +3493,23 @@ class rcube_imap extends rcube_storage
} }
/** /**
* Modify folder name according to namespace. * Modify folder name according to personal namespace prefix.
* For output it removes prefix of the personal namespace if it's possible. * For output it removes prefix of the personal namespace if it's possible.
* For input it adds the prefix. Use it before creating a folder in root * For input it adds the prefix. Use it before creating a folder in root
* of the folders tree. * of the folders tree.
* *
* @param string $folder Folder name * @param string $folder Folder name
* @param string $mode Mode name (out/in) * @param string $mode Mode name (out/in)
* *
* @return string Folder name * @return string Folder name
*/ */
public function mod_folder($folder, $mode = 'out') public function mod_folder($folder, $mode = 'out')
{ {
if (!strlen($folder)) { $prefix = $this->namespace['prefix_' . $mode]; // see set_env()
return $folder;
}
$prefix = $this->namespace['prefix']; // see set_env() if ($prefix === null || $prefix === ''
$prefix_len = strlen($prefix); || !($prefix_len = strlen($prefix)) || !strlen($folder)
) {
if (!$prefix_len) {
return $folder; return $folder;
} }
@ -3506,13 +3518,12 @@ class rcube_imap extends rcube_storage
if (substr($folder, 0, $prefix_len) === $prefix) { if (substr($folder, 0, $prefix_len) === $prefix) {
return substr($folder, $prefix_len); return substr($folder, $prefix_len);
} }
}
// add prefix for input (e.g. folder creation) return $folder;
else {
return $prefix . $folder;
} }
return $folder; // add prefix for input (e.g. folder creation)
return $prefix . $folder;
} }
/** /**

Loading…
Cancel
Save