Changeset d08333e in github


Ignore:
Timestamp:
May 5, 2011 8:46:54 AM (2 years ago)
Author:
alecpl <alec@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
de0a3f9
Parents:
4764079
Message:
  • Fix problems with subfolders of INBOX folder on some IMAP servers (#1487725)
  • Fix handling of folders that doesn't belong to any namespace (#1487637)
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • CHANGELOG

    r4764079 rd08333e  
    22=========================== 
    33 
     4- Fix problems with subfolders of INBOX folder on some IMAP servers (#1487725) 
     5- Fix handling of folders that doesn't belong to any namespace (#1487637) 
    46- Fix bug where messages were deleted instead moved to trash folder after Shift key was used (#1487902) 
    57- Enable multiselection for attachments uploading in capable browsers (#1485969) 
  • SQL/mssql.upgrade.sql

    re6bb836 rd08333e  
    9898GO 
    9999 
    100 -- Updates from version 0.5.1 
     100-- Updates from version 0.5.2 
    101101 
    102102ALTER TABLE [dbo].[contacts] ADD [words] [text] COLLATE Latin1_General_CI_AI NULL  
    103103GO 
    104 CREATE  INDEX [IX_contactgroupmembers_contact_id] ON [dbo].[contactgroupmembers]([contact_id]) ON [PRIMARY] 
     104CREATE INDEX [IX_contactgroupmembers_contact_id] ON [dbo].[contactgroupmembers]([contact_id]) ON [PRIMARY] 
    105105GO 
     106DELETE FROM [dbo].[messages] 
     107GO 
     108DELETE FROM [dbo].[cache] 
     109GO 
  • SQL/mysql.update.sql

    r09b0e36 rd08333e  
    134134TRUNCATE TABLE `messages`; 
    135135 
    136 -- Updates from version 0.5.1 
     136-- Updates from version 0.5.2 
    137137 
    138138ALTER TABLE `contacts` ADD `words` TEXT NULL AFTER `vcard`; 
    139139ALTER TABLE `contacts` CHANGE `vcard` `vcard` LONGTEXT /*!40101 CHARACTER SET utf8 */ NULL DEFAULT NULL; 
    140140ALTER TABLE `contactgroupmembers` ADD INDEX `contactgroupmembers_contact_index` (`contact_id`); 
     141 
     142TRUNCATE TABLE `messages`; 
     143TRUNCATE TABLE `cache`; 
  • SQL/postgres.update.sql

    r8381ec1 rd08333e  
    9191TRUNCATE messages; 
    9292 
    93 -- Updates from version 0.5.1 
     93-- Updates from version 0.5.2 
    9494 
    9595ALTER TABLE contacts ADD words TEXT NULL; 
    9696CREATE INDEX contactgroupmembers_contact_id_idx ON contactgroupmembers (contact_id); 
     97 
     98TRUNCATE messages; 
     99TRUNCATE cache; 
  • SQL/sqlite.update.sql

    re6bb836 rd08333e  
    184184 
    185185 
    186 -- Updates from version 0.5.1 
     186-- Updates from version 0.5.2 
    187187 
    188188CREATE TABLE contacts_tmp ( 
     
    222222 
    223223DELETE FROM messages; 
     224DELETE FROM cache; 
    224225CREATE INDEX ix_contactgroupmembers_contact_id ON contactgroupmembers (contact_id); 
  • UPGRADING

    r111a6fc3 rd08333e  
    49491. Check .htaccess settings (some php settings could become required) 
    50502. If you're using build-in addressbook, run indexing script /bin/indexcontacts.sh. 
     513. When upgrading from version older than 0.6-beta you should make sure 
     52   your folder settings contain namespace prefix. For example Courier users 
     53   should add INBOX. prefix to folder names in main configuration file. 
  • config/main.inc.php.dist

    r4ae996c rd08333e  
    375375// store draft message is this mailbox 
    376376// leave blank if draft messages should not be stored 
     377// NOTE: Use folder names with namespace prefix (INBOX. on Courier-IMAP) 
    377378$rcmail_config['drafts_mbox'] = 'Drafts'; 
    378379 
    379380// store spam messages in this mailbox 
     381// NOTE: Use folder names with namespace prefix (INBOX. on Courier-IMAP) 
    380382$rcmail_config['junk_mbox'] = 'Junk'; 
    381383 
    382384// store sent message is this mailbox 
    383385// leave blank if sent messages should not be stored 
     386// NOTE: Use folder names with namespace prefix (INBOX. on Courier-IMAP) 
    384387$rcmail_config['sent_mbox'] = 'Sent'; 
    385388 
    386389// move messages to this folder when deleting them 
    387390// leave blank if they should be deleted directly 
     391// NOTE: Use folder names with namespace prefix (INBOX. on Courier-IMAP) 
    388392$rcmail_config['trash_mbox'] = 'Trash'; 
    389393 
    390394// display these folders separately in the mailbox list. 
    391395// these folders will also be displayed with localized names 
     396// NOTE: Use folder names with namespace prefix (INBOX. on Courier-IMAP) 
    392397$rcmail_config['default_imap_folders'] = array('INBOX', 'Drafts', 'Sent', 'Junk', 'Trash'); 
    393398 
  • installer/config.php

    re490642 rd08333e  
    362362<div>Store sent messages in this folder</div> 
    363363 
    364 <p class="hint">Leave blank if sent messages should not be stored</p> 
     364<p class="hint">Leave blank if sent messages should not be stored. Note: folder must include namespace prefix if any.</p> 
    365365</dd> 
    366366 
     
    375375<div>Move messages to this folder when deleting them</div> 
    376376 
    377 <p class="hint">Leave blank if they should be deleted directly</p> 
     377<p class="hint">Leave blank if they should be deleted directly. Note: folder must include namespace prefix if any.</p> 
    378378</dd> 
    379379 
     
    388388<div>Store draft messages in this folder</div> 
    389389 
    390 <p class="hint">Leave blank if they should not be stored</p> 
     390<p class="hint">Leave blank if they should not be stored. Note: folder must include namespace prefix if any.</p> 
    391391</dd> 
    392392 
     
    400400?> 
    401401<div>Store spam messages in this folder</div> 
     402 
     403<p class="hint">Note: folder must include namespace prefix if any.</p> 
     404</dd> 
     405 
    402406</dd> 
    403407</dl> 
  • program/include/main.inc

    r2a38001 rd08333e  
    12291229    $list = $RCMAIL->imap->list_mailboxes(); 
    12301230 
    1231   foreach ($list as $folder) 
     1231  $delimiter = $RCMAIL->imap->get_hierarchy_delimiter(); 
     1232 
     1233  foreach ($list as $folder) { 
    12321234    if (empty($p['exceptions']) || !in_array($folder, $p['exceptions'])) 
    1233       rcmail_build_folder_tree($a_mailboxes, $folder, $RCMAIL->imap->get_hierarchy_delimiter()); 
     1235      rcmail_build_folder_tree($a_mailboxes, $folder, $delimiter); 
     1236  } 
    12341237 
    12351238  $select = new html_select($p); 
    1236    
     1239 
    12371240  if ($p['noselection']) 
    12381241    $select->add($p['noselection'], ''); 
    1239      
     1242 
    12401243  rcmail_render_folder_tree_select($a_mailboxes, $mbox, $p['maxlength'], $select, $p['realnames']); 
    1241    
     1244 
    12421245  return $select; 
    12431246} 
     
    12521255{ 
    12531256  global $RCMAIL; 
     1257 
     1258  // Handle namespace prefix 
     1259  $prefix = ''; 
     1260  if (!$path) { 
     1261    $n_folder = $folder; 
     1262    $folder = $RCMAIL->imap->mod_mailbox($folder); 
     1263 
     1264    if ($n_folder != $folder) { 
     1265      $prefix = substr($n_folder, 0, -strlen($folder)); 
     1266    } 
     1267  } 
    12541268 
    12551269  $pos = strpos($folder, $delm); 
     
    12731287  } 
    12741288 
    1275   $path .= $currentFolder; 
    1276  
    1277   // Check \Noselect option (if options are in cache) 
    1278   if (!$virtual && ($opts = $RCMAIL->imap->mailbox_options($path))) { 
    1279     $virtual = in_array('\\Noselect', $opts); 
    1280   } 
     1289  $path .= $prefix.$currentFolder; 
    12811290 
    12821291  if (!isset($arrFolders[$currentFolder])) { 
     1292    // Check \Noselect option (if options are in cache) 
     1293    if (!$virtual && ($opts = $RCMAIL->imap->mailbox_options($path))) { 
     1294      $virtual = in_array('\\Noselect', $opts); 
     1295    } 
     1296 
    12831297    $arrFolders[$currentFolder] = array( 
    12841298      'id' => $path, 
  • program/include/rcmail.php

    r63e9927 rd08333e  
    736736    // user already registered -> update user's record 
    737737    if (is_object($user)) { 
     738      // fix some old settings according to namespace prefix 
     739      $this->fix_namespace_settings($user); 
     740 
    738741      // create default folders on first login 
    739742      if (!$user->data['last_login'] && $config['create_default_folders']) 
    740743        $this->imap->create_default_folders(); 
     744      // update last login timestamp 
    741745      $user->touch(); 
    742746    } 
     
    14541458  } 
    14551459 
     1460  /** 
     1461   * Fixes some user preferences according to namespace handling change. 
     1462   * Old Roundcube versions were using folder names with removed namespace prefix. 
     1463   * Now we need to add the prefix on servers where personal namespace has prefix. 
     1464   * 
     1465   * @param rcube_user $user User object 
     1466   */ 
     1467  private function fix_namespace_settings($user) 
     1468  { 
     1469    $prefix     = $this->imap->get_namespace('prefix'); 
     1470    $prefix_len = strlen($prefix); 
     1471 
     1472    if (!$prefix_len) 
     1473      return; 
     1474 
     1475    $prefs = $user->get_prefs(); 
     1476    if (empty($prefs) || $prefs['namespace_fixed']) 
     1477      return; 
     1478 
     1479    // Build namespace prefix regexp 
     1480    $ns     = $this->imap->get_namespace(); 
     1481    $regexp = array(); 
     1482 
     1483    foreach ($ns as $entry) { 
     1484      if (!empty($entry)) { 
     1485        foreach ($entry as $item) { 
     1486          if (strlen($item[0])) { 
     1487            $regexp[] = preg_quote($item[0], '/'); 
     1488          } 
     1489        } 
     1490      } 
     1491    } 
     1492    $regexp = '/^('. implode('|', $regexp).')/'; 
     1493 
     1494    // Fix preferences 
     1495    $opts = array('drafts_mbox', 'junk_mbox', 'sent_mbox', 'trash_mbox', 'archive_mbox'); 
     1496    foreach ($opts as $opt) { 
     1497      if ($value = $prefs[$opt]) { 
     1498        if ($value != 'INBOX' && !preg_match($regexp, $value)) { 
     1499          $prefs[$opt] = $prefix.$value; 
     1500        } 
     1501      } 
     1502    } 
     1503 
     1504    if (!empty($prefs['default_imap_folders'])) { 
     1505      foreach ($prefs['default_imap_folders'] as $idx => $name) { 
     1506        if ($name != 'INBOX' && !preg_match($regexp, $name)) { 
     1507          $prefs['default_imap_folders'][$idx] = $prefix.$name; 
     1508        } 
     1509      } 
     1510    } 
     1511 
     1512    if (!empty($prefs['search_mods'])) { 
     1513      $folders = array(); 
     1514      foreach ($prefs['search_mods'] as $idx => $value) { 
     1515        if ($idx != 'INBOX' && $idx != '*' && !preg_match($regexp, $idx)) { 
     1516          $idx = $prefix.$idx; 
     1517        } 
     1518        $folders[$idx] = $value; 
     1519      } 
     1520      $prefs['search_mods'] = $folders; 
     1521    } 
     1522 
     1523    if (!empty($prefs['message_threading'])) { 
     1524      $folders = array(); 
     1525      foreach ($prefs['message_threading'] as $idx => $value) { 
     1526        if ($idx != 'INBOX' && !preg_match($regexp, $idx)) { 
     1527          $idx = $prefix.$idx; 
     1528        } 
     1529        $folders[$prefix.$idx] = $value; 
     1530      } 
     1531      $prefs['message_threading'] = $folders; 
     1532    } 
     1533 
     1534    if (!empty($prefs['collapsed_folders'])) { 
     1535      $folders     = explode('&&', $prefs['collapsed_folders']); 
     1536      $count       = count($folders); 
     1537      $folders_str = ''; 
     1538 
     1539      if ($count) { 
     1540          $folders[0]        = substr($folders[0], 1); 
     1541          $folders[$count-1] = substr($folders[$count-1], 0, -1); 
     1542      } 
     1543 
     1544      foreach ($folders as $value) { 
     1545        if ($value != 'INBOX' && !preg_match($regexp, $value)) { 
     1546          $value = $prefix.$value; 
     1547        } 
     1548        $folders_str .= '&'.$value.'&'; 
     1549      } 
     1550      $prefs['collapsed_folders'] = $folders_str; 
     1551    } 
     1552 
     1553    $prefs['namespace_fixed'] = true; 
     1554 
     1555    // save updated preferences and reset imap settings (default folders) 
     1556    $user->save_prefs($prefs); 
     1557    $this->set_imap_prop(); 
     1558  } 
     1559 
    14561560} 
  • program/include/rcube_imap.php

    r8abc176 rd08333e  
    340340     * All operations will be perfomed on this mailbox/folder 
    341341     * 
    342      * @param  string $new_mbox Mailbox/Folder name 
     342     * @param  string $mailbox Mailbox/Folder name 
    343343     * @access public 
    344344     */ 
    345     function set_mailbox($new_mbox) 
    346     { 
    347         $mailbox = $this->mod_mailbox($new_mbox); 
    348  
     345    function set_mailbox($mailbox) 
     346    { 
    349347        if ($this->mailbox == $mailbox) 
    350348            return; 
     
    365363    function select_mailbox($mailbox=null) 
    366364    { 
    367         $mailbox = strlen($mailbox) ? $this->mod_mailbox($mailbox) : $this->mailbox; 
     365        if (!strlen($mailbox)) { 
     366            $mailbox = $this->mailbox; 
     367        } 
    368368 
    369369        $selected = $this->conn->select($mailbox); 
     
    452452    function get_mailbox_name() 
    453453    { 
    454         return $this->conn->connected() ? $this->mod_mailbox($this->mailbox, 'out') : ''; 
     454        return $this->conn->connected() ? $this->mailbox : ''; 
    455455    } 
    456456 
     
    524524     * Get namespace 
    525525     * 
     526     * @param string $name Namespace array index: personal, other, shared, prefix 
     527     * 
    526528     * @return  array  Namespace data 
    527529     * @access  public 
    528530     */ 
    529     function get_namespace() 
    530     { 
    531         return $this->namespace; 
     531    function get_namespace($name=null) 
     532    { 
     533        $ns = $this->namespace; 
     534 
     535        if ($name) { 
     536            return isset($ns[$name]) ? $ns[$name] : null; 
     537        } 
     538 
     539        unset($ns['prefix']); 
     540        return $ns; 
    532541    } 
    533542 
     
    610619        } 
    611620 
     621        // Find personal namespace prefix for mod_mailbox() 
     622        // Prefix can be removed when there is only one personal namespace 
     623        if (is_array($this->namespace['personal']) && count($this->namespace['personal']) == 1) { 
     624            $this->namespace['prefix'] = $this->namespace['personal'][0][0]; 
     625        } 
     626 
    612627        $_SESSION['imap_namespace'] = $this->namespace; 
    613628        $_SESSION['imap_delimiter'] = $this->delimiter; 
     
    618633     * Get message count for a specific mailbox 
    619634     * 
    620      * @param  string  $mbox_name Mailbox/folder name 
    621      * @param  string  $mode      Mode for count [ALL|THREADS|UNSEEN|RECENT] 
    622      * @param  boolean $force     Force reading from server and update cache 
    623      * @param  boolean $status    Enables storing folder status info (max UID/count), 
    624      *                            required for mailbox_status() 
     635     * @param  string  $mailbox Mailbox/folder name 
     636     * @param  string  $mode    Mode for count [ALL|THREADS|UNSEEN|RECENT] 
     637     * @param  boolean $force   Force reading from server and update cache 
     638     * @param  boolean $status  Enables storing folder status info (max UID/count), 
     639     *                          required for mailbox_status() 
    625640     * @return int     Number of messages 
    626641     * @access public 
    627642     */ 
    628     function messagecount($mbox_name='', $mode='ALL', $force=false, $status=true) 
    629     { 
    630         $mailbox = strlen($mbox_name) ? $this->mod_mailbox($mbox_name) : $this->mailbox; 
     643    function messagecount($mailbox='', $mode='ALL', $force=false, $status=true) 
     644    { 
     645        if (!strlen($mailbox)) { 
     646            $mailbox = $this->mailbox; 
     647        } 
     648 
    631649        return $this->_messagecount($mailbox, $mode, $force, $status); 
    632650    } 
     
    645663     * @see     rcube_imap::messagecount() 
    646664     */ 
    647     private function _messagecount($mailbox='', $mode='ALL', $force=false, $status=true) 
     665    private function _messagecount($mailbox, $mode='ALL', $force=false, $status=true) 
    648666    { 
    649667        $mode = strtoupper($mode); 
    650  
    651         if (!strlen($mailbox)) 
    652             $mailbox = $this->mailbox; 
    653668 
    654669        // count search set 
     
    777792     * convert mailbox name with root dir first 
    778793     * 
    779      * @param   string   $mbox_name  Mailbox/folder name 
     794     * @param   string   $mailbox    Mailbox/folder name 
    780795     * @param   int      $page       Current page to list 
    781796     * @param   string   $sort_field Header field to sort by 
     
    785800     * @access  public 
    786801     */ 
    787     function list_headers($mbox_name='', $page=NULL, $sort_field=NULL, $sort_order=NULL, $slice=0) 
    788     { 
    789         $mailbox = strlen($mbox_name) ? $this->mod_mailbox($mbox_name) : $this->mailbox; 
     802    function list_headers($mailbox='', $page=NULL, $sort_field=NULL, $sort_order=NULL, $slice=0) 
     803    { 
     804        if (!strlen($mailbox)) { 
     805            $mailbox = $this->mailbox; 
     806        } 
     807 
    790808        return $this->_list_headers($mailbox, $page, $sort_field, $sort_order, false, $slice); 
    791809    } 
     
    13471365     * new messages because the RECENT flag is not reliable. 
    13481366     * 
    1349      * @param string $mbox_name Mailbox/folder name 
     1367     * @param string $mailbox Mailbox/folder name 
    13501368     * @return int   Folder status 
    13511369     */ 
    1352     function mailbox_status($mbox_name = null) 
    1353     { 
    1354         $mailbox = strlen($mbox_name) ? $this->mod_mailbox($mbox_name) : $this->mailbox; 
     1370    function mailbox_status($mailbox = null) 
     1371    { 
     1372        if (!strlen($mailbox)) { 
     1373            $mailbox = $this->mailbox; 
     1374        } 
    13551375        $old = $this->get_folder_stats($mailbox); 
    13561376 
     
    13791399     * @TODO: move to separate DB table (cache?) 
    13801400     * 
    1381      * @param string $mbox_name Mailbox name 
    1382      * @param string $name      Data name 
    1383      * @param mixed  $data      Data value 
    1384      */ 
    1385     private function set_folder_stats($mbox_name, $name, $data) 
    1386     { 
    1387         $_SESSION['folders'][$mbox_name][$name] = $data; 
     1401     * @param string $mailbox Mailbox name 
     1402     * @param string $name    Data name 
     1403     * @param mixed  $data    Data value 
     1404     */ 
     1405    private function set_folder_stats($mailbox, $name, $data) 
     1406    { 
     1407        $_SESSION['folders'][$mailbox][$name] = $data; 
    13881408    } 
    13891409 
     
    13921412     * Gets folder statistic data 
    13931413     * 
    1394      * @param string $mbox_name Mailbox name 
     1414     * @param string $mailbox Mailbox name 
     1415     * 
    13951416     * @return array Stats data 
    13961417     */ 
    1397     private function get_folder_stats($mbox_name) 
    1398     { 
    1399         if ($_SESSION['folders'][$mbox_name]) 
    1400             return (array) $_SESSION['folders'][$mbox_name]; 
     1418    private function get_folder_stats($mailbox) 
     1419    { 
     1420        if ($_SESSION['folders'][$mailbox]) 
     1421            return (array) $_SESSION['folders'][$mailbox]; 
    14011422        else 
    14021423            return array(); 
     
    14071428     * Return sorted array of message IDs (not UIDs) 
    14081429     * 
    1409      * @param string $mbox_name  Mailbox to get index from 
     1430     * @param string $mailbox    Mailbox to get index from 
    14101431     * @param string $sort_field Sort column 
    14111432     * @param string $sort_order Sort order [ASC, DESC] 
    14121433     * @return array Indexed array with message IDs 
    14131434     */ 
    1414     function message_index($mbox_name='', $sort_field=NULL, $sort_order=NULL) 
     1435    function message_index($mailbox='', $sort_field=NULL, $sort_order=NULL) 
    14151436    { 
    14161437        if ($this->threading) 
    1417             return $this->thread_index($mbox_name, $sort_field, $sort_order); 
     1438            return $this->thread_index($mailbox, $sort_field, $sort_order); 
    14181439 
    14191440        $this->_set_sort_order($sort_field, $sort_order); 
    14201441 
    1421         $mailbox = strlen($mbox_name) ? $this->mod_mailbox($mbox_name) : $this->mailbox; 
     1442        if (!strlen($mailbox)) { 
     1443            $mailbox = $this->mailbox; 
     1444        } 
    14221445        $key = "{$mailbox}:{$this->sort_field}:{$this->sort_order}:{$this->search_string}.msgi"; 
    14231446 
     
    15201543     * Return sorted array of threaded message IDs (not UIDs) 
    15211544     * 
    1522      * @param string $mbox_name  Mailbox to get index from 
     1545     * @param string $mailbox    Mailbox to get index from 
    15231546     * @param string $sort_field Sort column 
    15241547     * @param string $sort_order Sort order [ASC, DESC] 
    15251548     * @return array Indexed array with message IDs 
    15261549     */ 
    1527     function thread_index($mbox_name='', $sort_field=NULL, $sort_order=NULL) 
     1550    function thread_index($mailbox='', $sort_field=NULL, $sort_order=NULL) 
    15281551    { 
    15291552        $this->_set_sort_order($sort_field, $sort_order); 
    15301553 
    1531         $mailbox = strlen($mbox_name) ? $this->mod_mailbox($mbox_name) : $this->mailbox; 
     1554        if (!strlen($mailbox)) { 
     1555            $mailbox = $this->mailbox; 
     1556        } 
    15321557        $key = "{$mailbox}:{$this->sort_field}:{$this->sort_order}:{$this->search_string}.thi"; 
    15331558 
     
    16941719     * Invoke search request to IMAP server 
    16951720     * 
    1696      * @param  string  $mbox_name  Mailbox name to search in 
     1721     * @param  string  $mailbox    Mailbox name to search in 
    16971722     * @param  string  $str        Search criteria 
    16981723     * @param  string  $charset    Search charset 
     
    17011726     * @access public 
    17021727     */ 
    1703     function search($mbox_name='', $str=NULL, $charset=NULL, $sort_field=NULL) 
     1728    function search($mailbox='', $str=NULL, $charset=NULL, $sort_field=NULL) 
    17041729    { 
    17051730        if (!$str) 
    17061731            return false; 
    17071732 
    1708         $mailbox = strlen($mbox_name) ? $this->mod_mailbox($mbox_name) : $this->mailbox; 
     1733        if (!strlen($mailbox)) { 
     1734            $mailbox = $this->mailbox; 
     1735        } 
    17091736 
    17101737        $results = $this->_search_index($mailbox, $str, $charset, $sort_field); 
     
    18001827     * without result sorting and caching 
    18011828     * 
    1802      * @param  string  $mbox_name Mailbox name to search in 
    1803      * @param  string  $str       Search string 
    1804      * @param  boolean $ret_uid   True if UIDs should be returned 
     1829     * @param  string  $mailbox Mailbox name to search in 
     1830     * @param  string  $str     Search string 
     1831     * @param  boolean $ret_uid True if UIDs should be returned 
    18051832     * @return array   Search results as list of message IDs or UIDs 
    18061833     * @access public 
    18071834     */ 
    1808     function search_once($mbox_name='', $str=NULL, $ret_uid=false) 
     1835    function search_once($mailbox='', $str=NULL, $ret_uid=false) 
    18091836    { 
    18101837        if (!$str) 
    18111838            return false; 
    18121839 
    1813         $mailbox = strlen($mbox_name) ? $this->mod_mailbox($mbox_name) : $this->mailbox; 
     1840        if (!strlen($mailbox)) { 
     1841            $mailbox = $this->mailbox; 
     1842        } 
    18141843 
    18151844        return $this->conn->search($mailbox, $str, $ret_uid); 
     
    19802009     * Return message headers object of a specific message 
    19812010     * 
    1982      * @param int     $id        Message ID 
    1983      * @param string  $mbox_name Mailbox to read from 
    1984      * @param boolean $is_uid    True if $id is the message UID 
    1985      * @param boolean $bodystr   True if we need also BODYSTRUCTURE in headers 
     2011     * @param int     $id       Message ID 
     2012     * @param string  $mailbox Mailbox to read from 
     2013     * @param boolean $is_uid   True if $id is the message UID 
     2014     * @param boolean $bodystr  True if we need also BODYSTRUCTURE in headers 
    19862015     * @return object Message headers representation 
    19872016     */ 
    1988     function get_headers($id, $mbox_name=NULL, $is_uid=true, $bodystr=false) 
    1989     { 
    1990         $mailbox = strlen($mbox_name) ? $this->mod_mailbox($mbox_name) : $this->mailbox; 
     2017    function get_headers($id, $mailbox=null, $is_uid=true, $bodystr=false) 
     2018    { 
     2019        if (!strlen($mailbox)) { 
     2020            $mailbox = $this->mailbox; 
     2021        } 
    19912022        $uid = $is_uid ? $id : $this->_id2uid($id, $mailbox); 
    19922023 
     
    25302561     * @param mixed   $uids       Message UIDs as array or comma-separated string, or '*' 
    25312562     * @param string  $flag       Flag to set: SEEN, UNDELETED, DELETED, RECENT, ANSWERED, DRAFT, MDNSENT 
    2532      * @param string  $mbox_name  Folder name 
     2563     * @param string  $mailbox    Folder name 
    25332564     * @param boolean $skip_cache True to skip message cache clean up 
     2565     * 
    25342566     * @return boolean  Operation status 
    25352567     */ 
    2536     function set_flag($uids, $flag, $mbox_name=NULL, $skip_cache=false) 
    2537     { 
    2538         $mailbox = strlen($mbox_name) ? $this->mod_mailbox($mbox_name) : $this->mailbox; 
     2568    function set_flag($uids, $flag, $mailbox=null, $skip_cache=false) 
     2569    { 
     2570        if (!strlen($mailbox)) { 
     2571            $mailbox = $this->mailbox; 
     2572        } 
    25392573 
    25402574        $flag = strtoupper($flag); 
     
    25732607     * Remove message flag for one or several messages 
    25742608     * 
    2575      * @param mixed  $uids      Message UIDs as array or comma-separated string, or '*' 
    2576      * @param string $flag      Flag to unset: SEEN, DELETED, RECENT, ANSWERED, DRAFT, MDNSENT 
    2577      * @param string $mbox_name Folder name 
     2609     * @param mixed  $uids    Message UIDs as array or comma-separated string, or '*' 
     2610     * @param string $flag    Flag to unset: SEEN, DELETED, RECENT, ANSWERED, DRAFT, MDNSENT 
     2611     * @param string $mailbox Folder name 
     2612     * 
    25782613     * @return int   Number of flagged messages, -1 on failure 
    25792614     * @see set_flag 
    25802615     */ 
    2581     function unset_flag($uids, $flag, $mbox_name=NULL) 
    2582     { 
    2583         return $this->set_flag($uids, 'UN'.$flag, $mbox_name); 
     2616    function unset_flag($uids, $flag, $mailbox=null) 
     2617    { 
     2618        return $this->set_flag($uids, 'UN'.$flag, $mailbox); 
    25842619    } 
    25852620 
     
    25882623     * Append a mail message (source) to a specific mailbox 
    25892624     * 
    2590      * @param string  $mbox_name Target mailbox 
    2591      * @param string  $message   The message source string or filename 
    2592      * @param string  $headers   Headers string if $message contains only the body 
    2593      * @param boolean $is_file   True if $message is a filename 
     2625     * @param string  $mailbox Target mailbox 
     2626     * @param string  $message The message source string or filename 
     2627     * @param string  $headers Headers string if $message contains only the body 
     2628     * @param boolean $is_file True if $message is a filename 
    25942629     * 
    25952630     * @return boolean True on success, False on error 
    25962631     */ 
    2597     function save_message($mbox_name, &$message, $headers='', $is_file=false) 
    2598     { 
    2599         $mailbox = $this->mod_mailbox($mbox_name); 
     2632    function save_message($mailbox, &$message, $headers='', $is_file=false) 
     2633    { 
     2634        if (!strlen($mailbox)) { 
     2635            $mailbox = $this->mailbox; 
     2636        } 
    26002637 
    26012638        // make sure mailbox exists 
    2602         if ($this->mailbox_exists($mbox_name)) { 
     2639        if ($this->mailbox_exists($mailbox)) { 
    26032640            if ($is_file) 
    26042641                $saved = $this->conn->appendFromFile($mailbox, $message, $headers); 
     
    26262663    function move_message($uids, $to_mbox, $from_mbox='') 
    26272664    { 
    2628         $fbox = $from_mbox; 
    2629         $tbox = $to_mbox; 
    2630         $to_mbox = $this->mod_mailbox($to_mbox); 
    2631         $from_mbox = strlen($from_mbox) ? $this->mod_mailbox($from_mbox) : $this->mailbox; 
    2632  
    2633         if ($to_mbox === $from_mbox) 
     2665        if (!strlen($from_mbox)) { 
     2666            $from_mbox = $this->mailbox; 
     2667        } 
     2668 
     2669        if ($to_mbox === $from_mbox) { 
    26342670            return false; 
     2671        } 
    26352672 
    26362673        list($uids, $all_mode) = $this->_parse_uids($uids, $from_mbox); 
     
    26412678 
    26422679        // make sure mailbox exists 
    2643         if ($to_mbox != 'INBOX' && !$this->mailbox_exists($tbox)) { 
    2644             if (in_array($tbox, $this->default_folders)) 
    2645                 $this->create_mailbox($tbox, true); 
     2680        if ($to_mbox != 'INBOX' && !$this->mailbox_exists($to_mbox)) { 
     2681            if (in_array($to_mbox, $this->default_folders)) 
     2682                $this->create_mailbox($to_mbox, true); 
    26462683            else 
    26472684                return false; 
    26482685        } 
    26492686 
     2687        $config = rcmail::get_instance()->config; 
     2688        $to_trash = $to_mbox == $config->get('trash_mbox'); 
     2689 
    26502690        // flag messages as read before moving them 
    2651         $config = rcmail::get_instance()->config; 
    2652         if ($config->get('read_when_deleted') && $tbox == $config->get('trash_mbox')) { 
     2691        if ($to_trash && $config->get('read_when_deleted')) { 
    26532692            // don't flush cache (4th argument) 
    2654             $this->set_flag($uids, 'SEEN', $fbox, true); 
     2693            $this->set_flag($uids, 'SEEN', $from_mbox, true); 
    26552694        } 
    26562695 
     
    26662705        } 
    26672706        // moving failed 
    2668         else if ($config->get('delete_always', false) && $tbox == $config->get('trash_mbox')) { 
    2669             $moved = $this->delete_message($uids, $fbox); 
     2707        else if ($to_trash && $config->get('delete_always', false)) { 
     2708            $moved = $this->delete_message($uids, $from_mbox); 
    26702709        } 
    26712710 
     
    27092748    function copy_message($uids, $to_mbox, $from_mbox='') 
    27102749    { 
    2711         $fbox = $from_mbox; 
    2712         $tbox = $to_mbox; 
    2713         $to_mbox = $this->mod_mailbox($to_mbox); 
    2714         $from_mbox = $from_mbox ? $this->mod_mailbox($from_mbox) : $this->mailbox; 
     2750        if (!strlen($from_mbox)) { 
     2751            $from_mbox = $this->mailbox; 
     2752        } 
    27152753 
    27162754        list($uids, $all_mode) = $this->_parse_uids($uids, $from_mbox); 
     
    27222760 
    27232761        // make sure mailbox exists 
    2724         if ($to_mbox != 'INBOX' && !$this->mailbox_exists($tbox)) { 
    2725             if (in_array($tbox, $this->default_folders)) 
    2726                 $this->create_mailbox($tbox, true); 
     2762        if ($to_mbox != 'INBOX' && !$this->mailbox_exists($to_mbox)) { 
     2763            if (in_array($to_mbox, $this->default_folders)) 
     2764                $this->create_mailbox($to_mbox, true); 
    27272765            else 
    27282766                return false; 
     
    27432781     * Mark messages as deleted and expunge mailbox 
    27442782     * 
    2745      * @param mixed  $uids      Message UIDs as array or comma-separated string, or '*' 
    2746      * @param string $mbox_name Source mailbox 
     2783     * @param mixed  $uids    Message UIDs as array or comma-separated string, or '*' 
     2784     * @param string $mailbox Source mailbox 
     2785     * 
    27472786     * @return boolean True on success, False on error 
    27482787     */ 
    2749     function delete_message($uids, $mbox_name='') 
    2750     { 
    2751         $mailbox = strlen($mbox_name) ? $this->mod_mailbox($mbox_name) : $this->mailbox; 
     2788    function delete_message($uids, $mailbox='') 
     2789    { 
     2790        if (!strlen($mailbox)) { 
     2791            $mailbox = $this->mailbox; 
     2792        } 
    27522793 
    27532794        list($uids, $all_mode) = $this->_parse_uids($uids, $mailbox); 
     
    27972838     * Clear all messages in a specific mailbox 
    27982839     * 
    2799      * @param string $mbox_name Mailbox name 
     2840     * @param string $mailbox Mailbox name 
     2841     * 
    28002842     * @return int Above 0 on success 
    28012843     */ 
    2802     function clear_mailbox($mbox_name=NULL) 
    2803     { 
    2804         $mailbox = strlen($mbox_name) ? $this->mod_mailbox($mbox_name) : $this->mailbox; 
     2844    function clear_mailbox($mailbox=null) 
     2845    { 
     2846        if (!strlen($mailbox)) { 
     2847            $mailbox = $this->mailbox; 
     2848        } 
    28052849 
    28062850        // SELECT will set messages count for clearFolder() 
     
    28242868     * Send IMAP expunge command and clear cache 
    28252869     * 
    2826      * @param string  $mbox_name   Mailbox name 
     2870     * @param string  $mailbox     Mailbox name 
    28272871     * @param boolean $clear_cache False if cache should not be cleared 
     2872     * 
    28282873     * @return boolean True on success 
    28292874     */ 
    2830     function expunge($mbox_name='', $clear_cache=true) 
    2831     { 
    2832         $mailbox = strlen($mbox_name) ? $this->mod_mailbox($mbox_name) : $this->mailbox; 
     2875    function expunge($mailbox='', $clear_cache=true) 
     2876    { 
     2877        if (!strlen($mailbox)) { 
     2878            $mailbox = $this->mailbox; 
     2879        } 
     2880 
    28332881        return $this->_expunge($mailbox, $clear_cache); 
    28342882    } 
     
    29252973     * Translate UID to message ID 
    29262974     * 
    2927      * @param int    $uid       Message UID 
    2928      * @param string $mbox_name Mailbox name 
     2975     * @param int    $uid     Message UID 
     2976     * @param string $mailbox Mailbox name 
     2977     * 
    29292978     * @return int   Message ID 
    29302979     */ 
    2931     function get_id($uid, $mbox_name=NULL) 
    2932     { 
    2933         $mailbox = strlen($mbox_name) ? $this->mod_mailbox($mbox_name) : $this->mailbox; 
     2980    function get_id($uid, $mailbox=null) 
     2981    { 
     2982        if (!strlen($mailbox)) { 
     2983            $mailbox = $this->mailbox; 
     2984        } 
     2985 
    29342986        return $this->_uid2id($uid, $mailbox); 
    29352987    } 
     
    29392991     * Translate message number to UID 
    29402992     * 
    2941      * @param int    $id        Message ID 
    2942      * @param string $mbox_name Mailbox name 
     2993     * @param int    $id      Message ID 
     2994     * @param string $mailbox Mailbox name 
     2995     * 
    29432996     * @return int   Message UID 
    29442997     */ 
    2945     function get_uid($id, $mbox_name=NULL) 
    2946     { 
    2947         $mailbox = strlen($mbox_name) ? $this->mod_mailbox($mbox_name) : $this->mailbox; 
     2998    function get_uid($id, $mailbox=null) 
     2999    { 
     3000        if (!strlen($mailbox)) { 
     3001            $mailbox = $this->mailbox; 
     3002        } 
     3003 
    29483004        return $this->_id2uid($id, $mailbox); 
    29493005    } 
     
    29583014     * Public method for listing subscribed folders 
    29593015     * 
    2960      * Converts mailbox name with root dir first 
    2961      * 
    29623016     * @param   string  $root   Optional root folder 
    29633017     * @param   string  $filter Optional filter for mailbox listing 
     3018     * 
    29643019     * @return  array   List of mailboxes/folders 
    29653020     * @access  public 
     
    29673022    function list_mailboxes($root='', $filter='*') 
    29683023    { 
    2969         $a_out = array(); 
    29703024        $a_mboxes = $this->_list_mailboxes($root, $filter); 
    29713025 
    2972         foreach ($a_mboxes as $idx => $mbox_row) { 
    2973             if (strlen($name = $this->mod_mailbox($mbox_row, 'out'))) 
    2974                 $a_out[] = $name; 
    2975             unset($a_mboxes[$idx]); 
    2976         } 
    2977  
    29783026        // INBOX should always be available 
    2979         if (!in_array('INBOX', $a_out)) 
    2980             array_unshift($a_out, 'INBOX'); 
     3027        if (!in_array('INBOX', $a_mboxes)) 
     3028            array_unshift($a_mboxes, 'INBOX'); 
    29813029 
    29823030        // sort mailboxes 
    2983         $a_out = $this->_sort_mailbox_list($a_out); 
    2984  
    2985         return $a_out; 
     3031        $a_mboxes = $this->_sort_mailbox_list($a_mboxes); 
     3032 
     3033        return $a_mboxes; 
    29863034    } 
    29873035 
     
    30183066            if (!$config->get('imap_force_lsub') && $this->get_capability('LIST-EXTENDED')) { 
    30193067                // This will also set mailbox options, LSUB doesn't do that 
    3020                 $a_folders = $this->conn->listMailboxes($this->mod_mailbox($root), $filter, 
     3068                $a_folders = $this->conn->listMailboxes($root, $filter, 
    30213069                    NULL, array('SUBSCRIBED')); 
    30223070 
     
    30343082            // retrieve list of folders from IMAP server using LSUB 
    30353083            else { 
    3036                 $a_folders = $this->conn->listSubscribed($this->mod_mailbox($root), $filter); 
     3084                $a_folders = $this->conn->listSubscribed($root, $filter); 
    30373085            } 
    30383086        } 
     
    30663114        else { 
    30673115            // retrieve list of folders from IMAP server 
    3068             $a_mboxes = $this->conn->listMailboxes($this->mod_mailbox($root), $filter); 
    3069         } 
    3070  
    3071         $a_folders = array(); 
    3072         if (!is_array($a_mboxes)) 
     3116            $a_mboxes = $this->conn->listMailboxes($root, $filter); 
     3117        } 
     3118 
     3119        if (!is_array($a_mboxes)) { 
    30733120            $a_mboxes = array(); 
    3074  
    3075         // modify names with root dir 
    3076         foreach ($a_mboxes as $idx => $mbox_name) { 
    3077             if (strlen($name = $this->mod_mailbox($mbox_name, 'out'))) 
    3078                 $a_folders[] = $name; 
    3079             unset($a_mboxes[$idx]); 
    30803121        } 
    30813122 
    30823123        // INBOX should always be available 
    3083         if (!in_array('INBOX', $a_folders)) 
    3084             array_unshift($a_folders, 'INBOX'); 
     3124        if (!in_array('INBOX', $a_mboxes)) 
     3125            array_unshift($a_mboxes, 'INBOX'); 
    30853126 
    30863127        // filter folders and sort them 
    3087         $a_folders = $this->_sort_mailbox_list($a_folders); 
    3088         return $a_folders; 
     3128        $a_mboxes = $this->_sort_mailbox_list($a_mboxes); 
     3129 
     3130        return $a_mboxes; 
    30893131    } 
    30903132 
     
    31083150     * Get mailbox size (size of all messages in a mailbox) 
    31093151     * 
    3110      * @param string $name Mailbox name 
     3152     * @param string $mailbox Mailbox name 
     3153     * 
    31113154     * @return int Mailbox size in bytes, False on error 
    31123155     */ 
    3113     function get_mailbox_size($name) 
    3114     { 
    3115         $name = $this->mod_mailbox($name); 
    3116  
     3156    function get_mailbox_size($mailbox) 
     3157    { 
    31173158        // @TODO: could we try to use QUOTA here? 
    3118         $result = $this->conn->fetchHeaderIndex($name, '1:*', 'SIZE', false); 
     3159        $result = $this->conn->fetchHeaderIndex($mailbox, '1:*', 'SIZE', false); 
    31193160 
    31203161        if (is_array($result)) 
     
    31603201     * Create a new mailbox on the server and register it in local cache 
    31613202     * 
    3162      * @param string  $name      New mailbox name 
     3203     * @param string  $mailbox   New mailbox name 
    31633204     * @param boolean $subscribe True if the new mailbox should be subscribed 
    3164      * @param boolean True on success 
    3165      */ 
    3166     function create_mailbox($name, $subscribe=false) 
    3167     { 
    3168         $result   = false; 
    3169         $abs_name = $this->mod_mailbox($name); 
    3170         $result   = $this->conn->createFolder($abs_name); 
     3205     * 
     3206     * @return boolean True on success 
     3207     */ 
     3208    function create_mailbox($mailbox, $subscribe=false) 
     3209    { 
     3210        $result = $this->conn->createFolder($mailbox); 
    31713211 
    31723212        // try to subscribe it 
    31733213        if ($result && $subscribe) 
    3174             $this->subscribe($name); 
     3214            $this->subscribe($mailbox); 
    31753215 
    31763216        return $result; 
     
    31813221     * Set a new name to an existing mailbox 
    31823222     * 
    3183      * @param string $mbox_name Mailbox to rename 
    3184      * @param string $new_name  New mailbox name 
     3223     * @param string $mailbox Mailbox to rename 
     3224     * @param string $new_name New mailbox name 
    31853225     * 
    31863226     * @return boolean True on success 
    31873227     */ 
    3188     function rename_mailbox($mbox_name, $new_name) 
    3189     { 
    3190         $result = false; 
    3191  
    3192         // make absolute path 
    3193         $mailbox  = $this->mod_mailbox($mbox_name); 
    3194         $abs_name = $this->mod_mailbox($new_name); 
    3195         $delm     = $this->get_hierarchy_delimiter(); 
     3228    function rename_mailbox($mailbox, $new_name) 
     3229    { 
     3230        if (!strlen($new_name)) { 
     3231            return false; 
     3232        } 
     3233 
     3234        $delm = $this->get_hierarchy_delimiter(); 
    31963235 
    31973236        // get list of subscribed folders 
    31983237        if ((strpos($mailbox, '%') === false) && (strpos($mailbox, '*') === false)) { 
    3199             $a_subscribed = $this->_list_mailboxes('', $mbox_name . $delm . '*'); 
    3200             $subscribed   = $this->mailbox_exists($mbox_name, true); 
     3238            $a_subscribed = $this->_list_mailboxes('', $mailbox . $delm . '*'); 
     3239            $subscribed   = $this->mailbox_exists($mailbox, true); 
    32013240        } 
    32023241        else { 
     
    32053244        } 
    32063245 
    3207         if (strlen($abs_name)) 
    3208             $result = $this->conn->renameFolder($mailbox, $abs_name); 
     3246        $result = $this->conn->renameFolder($mailbox, $new_name); 
    32093247 
    32103248        if ($result) { 
     
    32123250            if ($subscribed) { 
    32133251                $this->conn->unsubscribe($mailbox); 
    3214                 $this->conn->subscribe($abs_name); 
     3252                $this->conn->subscribe($new_name); 
    32153253            } 
    32163254 
     
    32203258                    $this->conn->unsubscribe($c_subscribed); 
    32213259                    $this->conn->subscribe(preg_replace('/^'.preg_quote($mailbox, '/').'/', 
    3222                         $abs_name, $c_subscribed)); 
     3260                        $new_name, $c_subscribed)); 
    32233261                } 
    32243262            } 
     
    32363274     * Remove mailbox from server 
    32373275     * 
    3238      * @param string $mbox_name Mailbox name 
     3276     * @param string $mailbox Mailbox name 
    32393277     * 
    32403278     * @return boolean True on success 
    32413279     */ 
    3242     function delete_mailbox($mbox_name) 
    3243     { 
    3244         $result  = false; 
    3245         $mailbox = $this->mod_mailbox($mbox_name); 
    3246         $delm    = $this->get_hierarchy_delimiter(); 
     3280    function delete_mailbox($mailbox) 
     3281    { 
     3282        $delm = $this->get_hierarchy_delimiter(); 
    32473283 
    32483284        // get list of folders 
     
    32953331     * Checks if folder exists and is subscribed 
    32963332     * 
    3297      * @param string   $mbox_name    Folder name 
     3333     * @param string   $mailbox      Folder name 
    32983334     * @param boolean  $subscription Enable subscription checking 
     3335     * 
    32993336     * @return boolean TRUE or FALSE 
    33003337     */ 
    3301     function mailbox_exists($mbox_name, $subscription=false) 
    3302     { 
    3303         if ($mbox_name == 'INBOX') 
     3338    function mailbox_exists($mailbox, $subscription=false) 
     3339    { 
     3340        if ($mailbox == 'INBOX') { 
    33043341            return true; 
     3342        } 
    33053343 
    33063344        $key  = $subscription ? 'subscribed' : 'existing'; 
    3307         $mbox = $this->mod_mailbox($mbox_name); 
    3308  
    3309         if (is_array($this->icache[$key]) && in_array($mbox, $this->icache[$key])) 
     3345 
     3346        if (is_array($this->icache[$key]) && in_array($mailbox, $this->icache[$key])) 
    33103347            return true; 
    33113348 
    33123349        if ($subscription) { 
    3313             $a_folders = $this->conn->listSubscribed('', $mbox); 
     3350            $a_folders = $this->conn->listSubscribed('', $mailbox); 
    33143351        } 
    33153352        else { 
    3316             $a_folders = $this->conn->listMailboxes('', $mbox); 
    3317         } 
    3318  
    3319         if (is_array($a_folders) && in_array($mbox, $a_folders)) { 
    3320             $this->icache[$key][] = $mbox; 
     3353            $a_folders = $this->conn->listMailboxes('', $mailbox); 
     3354        } 
     3355 
     3356        if (is_array($a_folders) && in_array($mailbox, $a_folders)) { 
     3357            $this->icache[$key][] = $mailbox; 
    33213358            return true; 
    33223359        } 
     
    33293366     * Returns the namespace where the folder is in 
    33303367     * 
    3331      * @param string $mbox_name Folder name 
     3368     * @param string $mailbox Folder name 
    33323369     * 
    33333370     * @return string One of 'personal', 'other' or 'shared' 
    33343371     * @access public 
    33353372     */ 
    3336     function mailbox_namespace($mbox_name) 
    3337     { 
    3338         if ($mbox_name == 'INBOX') { 
     3373    function mailbox_namespace($mailbox) 
     3374    { 
     3375        if ($mailbox == 'INBOX') { 
    33393376            return 'personal'; 
    33403377        } 
     
    33443381                foreach ($namespace as $ns) { 
    33453382                    if (strlen($ns[0])) { 
    3346                         if ((strlen($ns[0])>1 && $mbox_name == substr($ns[0], 0, -1)) 
    3347                             || strpos($mbox_name, $ns[0]) === 0 
     3383                        if ((strlen($ns[0])>1 && $mailbox == substr($ns[0], 0, -1)) 
     3384                            || strpos($mailbox, $ns[0]) === 0 
    33483385                        ) { 
    33493386                            return $type; 
     
    33593396 
    33603397    /** 
    3361      * Modify folder name for input/output according to root dir and namespace 
    3362      * 
    3363      * @param string  $mbox_name Folder name 
    3364      * @param string  $mode      Mode 
     3398     * Modify folder name according to namespace. 
     3399     * For output it removes prefix of the personal namespace if it's possible. 
     3400     * For input it adds the prefix. Use it before creating a folder in root 
     3401     * of the folders tree. 
     3402     * 
     3403     * @param string $mailbox Folder name 
     3404     * @param string $mode    Mode name (out/in) 
     3405     * 
    33653406     * @return string Folder name 
    33663407     */ 
    3367     function mod_mailbox($mbox_name, $mode='in') 
    3368     { 
    3369         if (!strlen($mbox_name)) 
    3370             return ''; 
    3371  
    3372         if ($mode == 'in') { 
    3373             // If folder contains namespace prefix, don't modify it 
    3374             if (is_array($this->namespace['shared'])) { 
    3375                 foreach ($this->namespace['shared'] as $ns) { 
    3376                     if ($ns[0] && strpos($mbox_name, $ns[0]) === 0) { 
    3377                         return $mbox_name; 
    3378                     } 
    3379                 } 
    3380             } 
    3381             if (is_array($this->namespace['other'])) { 
    3382                 foreach ($this->namespace['other'] as $ns) { 
    3383                     if ($ns[0] && strpos($mbox_name, $ns[0]) === 0) { 
    3384                         return $mbox_name; 
    3385                     } 
    3386                 } 
    3387             } 
    3388             if (is_array($this->namespace['personal'])) { 
    3389                 foreach ($this->namespace['personal'] as $ns) { 
    3390                     if ($ns[0] && strpos($mbox_name, $ns[0]) === 0) { 
    3391                         return $mbox_name; 
    3392                     } 
    3393                 } 
    3394                 // Add prefix if first personal namespace is non-empty 
    3395                 if ($mbox_name != 'INBOX' && $this->namespace['personal'][0][0]) { 
    3396                     return $this->namespace['personal'][0][0].$mbox_name; 
    3397                 } 
    3398             } 
    3399         } 
     3408    function mod_mailbox($mailbox, $mode = 'out') 
     3409    { 
     3410        if (!strlen($mailbox)) { 
     3411            return $mailbox; 
     3412        } 
     3413 
     3414        $prefix     = $this->namespace['prefix']; // see set_env() 
     3415        $prefix_len = strlen($prefix); 
     3416 
     3417        if (!$prefix_len) { 
     3418            return $mailbox; 
     3419        } 
     3420 
     3421        // remove prefix for output 
     3422        if ($mode == 'out') { 
     3423            if (substr($mailbox, 0, $prefix_len) === $prefix) { 
     3424                return substr($mailbox, $prefix_len); 
     3425            } 
     3426        } 
     3427        // add prefix for input (e.g. folder creation) 
    34003428        else { 
    3401             // Remove prefix if folder is from first ("non-empty") personal namespace 
    3402             if (is_array($this->namespace['personal'])) { 
    3403                 if ($prefix = $this->namespace['personal'][0][0]) { 
    3404                     if (strpos($mbox_name, $prefix) === 0) { 
    3405                         return substr($mbox_name, strlen($prefix)); 
    3406                     } 
    3407                 } 
    3408             } 
    3409         } 
    3410  
    3411         return $mbox_name; 
     3429            return $prefix . $mailbox; 
     3430        } 
     3431 
     3432        return $mailbox; 
    34123433    } 
    34133434 
     
    34163437     * Gets folder options from LIST response, e.g. \Noselect, \Noinferiors 
    34173438     * 
    3418      * @param string $mbox_name Folder name 
    3419      * @param bool   $force     Set to True if options should be refreshed 
    3420      *                          Options are available after LIST command only 
     3439     * @param string $mailbox Folder name 
     3440     * @param bool   $force   Set to True if options should be refreshed 
     3441     *                        Options are available after LIST command only 
    34213442     * 
    34223443     * @return array Options list 
    34233444     */ 
    3424     function mailbox_options($mbox_name, $force=false) 
    3425     { 
    3426         $mbox = $this->mod_mailbox($mbox_name); 
    3427  
    3428         if ($mbox == 'INBOX') { 
     3445    function mailbox_options($mailbox, $force=false) 
     3446    { 
     3447        if ($mailbox == 'INBOX') { 
    34293448            return array(); 
    34303449        } 
    34313450 
    3432         if (!is_array($this->conn->data['LIST']) || !is_array($this->conn->data['LIST'][$mbox])) { 
     3451        if (!is_array($this->conn->data['LIST']) || !is_array($this->conn->data['LIST'][$mailbox])) { 
    34333452            if ($force) { 
    3434                 $this->conn->listMailboxes('', $mbox_name); 
     3453                $this->conn->listMailboxes('', $mailbox); 
    34353454            } 
    34363455            else { 
     
    34393458        } 
    34403459 
    3441         $opts = $this->conn->data['LIST'][$mbox]; 
     3460        $opts = $this->conn->data['LIST'][$mailbox]; 
    34423461 
    34433462        return is_array($opts) ? $opts : array(); 
     
    34803499    function set_acl($mailbox, $user, $acl) 
    34813500    { 
    3482         $mailbox = $this->mod_mailbox($mailbox); 
    3483  
    34843501        if ($this->get_capability('ACL')) 
    34853502            return $this->conn->setACL($mailbox, $user, $acl); 
     
    35043521    function delete_acl($mailbox, $user) 
    35053522    { 
    3506         $mailbox = $this->mod_mailbox($mailbox); 
    3507  
    35083523        if ($this->get_capability('ACL')) 
    35093524            return $this->conn->deleteACL($mailbox, $user); 
     
    35243539    function get_acl($mailbox) 
    35253540    { 
    3526         $mailbox = $this->mod_mailbox($mailbox); 
    3527  
    35283541        if ($this->get_capability('ACL')) 
    35293542            return $this->conn->getACL($mailbox); 
     
    35463559    function list_rights($mailbox, $user) 
    35473560    { 
    3548         $mailbox = $this->mod_mailbox($mailbox); 
    3549  
    35503561        if ($this->get_capability('ACL')) 
    35513562            return $this->conn->listRights($mailbox, $user); 
     
    35673578    function my_rights($mailbox) 
    35683579    { 
    3569         $mailbox = $this->mod_mailbox($mailbox); 
    3570  
    35713580        if ($this->get_capability('ACL')) 
    35723581            return $this->conn->myRights($mailbox); 
     
    35883597    function set_metadata($mailbox, $entries) 
    35893598    { 
    3590         if ($mailbox) 
    3591             $mailbox = $this->mod_mailbox($mailbox); 
    3592  
    35933599        if ($this->get_capability('METADATA') || 
    35943600            (!strlen($mailbox) && $this->get_capability('METADATA-SERVER')) 
     
    36213627    function delete_metadata($mailbox, $entries) 
    36223628    { 
    3623         if ($mailbox) 
    3624             $mailbox = $this->mod_mailbox($mailbox); 
    3625  
    36263629        if ($this->get_capability('METADATA') ||  
    36273630            (!strlen($mailbox) && $this->get_capability('METADATA-SERVER')) 
     
    36553658    function get_metadata($mailbox, $entries, $options=array()) 
    36563659    { 
    3657         if ($mailbox) 
    3658             $mailbox = $this->mod_mailbox($mailbox); 
    3659  
    36603660        if ($this->get_capability('METADATA') ||  
    36613661            !strlen(($mailbox) && $this->get_capability('METADATA-SERVER')) 
     
    45984598 
    45994599    /** 
    4600      * @param int    $uid       Message UID 
    4601      * @param string $mbox_name Mailbox name 
     4600     * @param int    $uid     Message UID 
     4601     * @param string $mailbox Mailbox name 
    46024602     * @return int Message (sequence) ID 
    46034603     * @access private 
    46044604     */ 
    4605     private function _uid2id($uid, $mbox_name=NULL) 
    4606     { 
    4607         if (!strlen($mbox_name)) 
    4608             $mbox_name = $this->mailbox; 
    4609  
    4610         if (!isset($this->uid_id_map[$mbox_name][$uid])) { 
    4611             if (!($id = $this->get_cache_uid2id($mbox_name.'.msg', $uid))) 
    4612                 $id = $this->conn->UID2ID($mbox_name, $uid); 
    4613  
    4614             $this->uid_id_map[$mbox_name][$uid] = $id; 
    4615         } 
    4616  
    4617         return $this->uid_id_map[$mbox_name][$uid]; 
    4618     } 
    4619  
    4620  
    4621     /** 
    4622      * @param int    $id        Message (sequence) ID 
    4623      * @param string $mbox_name Mailbox name 
     4605    private function _uid2id($uid, $mailbox=NULL) 
     4606    { 
     4607        if (!strlen($mailbox)) { 
     4608            $mailbox = $this->mailbox; 
     4609        } 
     4610 
     4611        if (!isset($this->uid_id_map[$mailbox][$uid])) { 
     4612            if (!($id = $this->get_cache_uid2id($mailbox.'.msg', $uid))) 
     4613                $id = $this->conn->UID2ID($mailbox, $uid); 
     4614 
     4615            $this->uid_id_map[$mailbox][$uid] = $id; 
     4616        } 
     4617 
     4618        return $this->uid_id_map[$mailbox][$uid]; 
     4619    } 
     4620 
     4621 
     4622    /** 
     4623     * @param int    $id      Message (sequence) ID 
     4624     * @param string $mailbox Mailbox name 
     4625     * 
    46244626     * @return int Message UID 
    46254627     * @access private 
    46264628     */ 
    4627     private function _id2uid($id, $mbox_name=NULL) 
    4628     { 
    4629         if (!strlen($mbox_name)) 
    4630             $mbox_name = $this->mailbox; 
    4631  
    4632         if ($uid = array_search($id, (array)$this->uid_id_map[$mbox_name])) 
     4629    private function _id2uid($id, $mailbox=null) 
     4630    { 
     4631        if (!strlen($mailbox)) { 
     4632            $mailbox = $this->mailbox; 
     4633        } 
     4634 
     4635        if ($uid = array_search($id, (array)$this->uid_id_map[$mailbox])) { 
    46334636            return $uid; 
    4634  
    4635         if (!($uid = $this->get_cache_id2uid($mbox_name.'.msg', $id))) 
    4636             $uid = $this->conn->ID2UID($mbox_name, $id); 
    4637  
    4638         $this->uid_id_map[$mbox_name][$uid] = $id; 
     4637        } 
     4638 
     4639        if (!($uid = $this->get_cache_id2uid($mailbox.'.msg', $id))) { 
     4640            $uid = $this->conn->ID2UID($mailbox, $id); 
     4641        } 
     4642 
     4643        $this->uid_id_map[$mailbox][$uid] = $id; 
    46394644 
    46404645        return $uid; 
     
    46514656 
    46524657        if (is_array($a_mboxes)) 
    4653             foreach ($a_mboxes as $i => $mbox_name) { 
    4654                 $mailbox = $this->mod_mailbox($mbox_name); 
     4658            foreach ($a_mboxes as $i => $mailbox) { 
    46554659                $a_mboxes[$i] = $mailbox; 
    46564660 
    4657                 if ($mode=='subscribe') 
     4661                if ($mode == 'subscribe') 
    46584662                    $updated = $this->conn->subscribe($mailbox); 
    4659                 else if ($mode=='unsubscribe') 
     4663                else if ($mode == 'unsubscribe') 
    46604664                    $updated = $this->conn->unsubscribe($mailbox); 
    46614665            } 
     
    46684672 
    46694673            // modify cached list 
    4670             if ($mode=='subscribe') 
     4674            if ($mode == 'subscribe') 
    46714675                $a_mailbox_cache = array_merge($a_mailbox_cache, $a_mboxes); 
    4672             else if ($mode=='unsubscribe') 
     4676            else if ($mode == 'unsubscribe') 
    46734677                $a_mailbox_cache = array_diff($a_mailbox_cache, $a_mboxes); 
    46744678 
     
    46854689     * @access private 
    46864690     */ 
    4687     private function _set_messagecount($mbox_name, $mode, $increment) 
    4688     { 
    4689         $a_mailbox_cache = false; 
    4690         $mailbox = strlen($mbox_name) ? $mbox_name : $this->mailbox; 
     4691    private function _set_messagecount($mailbox, $mode, $increment) 
     4692    { 
    46914693        $mode = strtoupper($mode); 
    4692  
    46934694        $a_mailbox_cache = $this->get_cache('messagecount'); 
    46944695 
     
    47144715     * @access private 
    47154716     */ 
    4716     private function _clear_messagecount($mbox_name='', $mode=null) 
    4717     { 
    4718         $mailbox = strlen($mbox_name) ? $mbox_name : $this->mailbox; 
    4719  
     4717    private function _clear_messagecount($mailbox, $mode=null) 
     4718    { 
    47204719        $a_mailbox_cache = $this->get_cache('messagecount'); 
    47214720 
  • program/steps/mail/func.inc

    rc08b18c4 rd08333e  
    131131      'copy', 'move', 'quota'); 
    132132 
    133   $OUTPUT->set_pagetitle(rcmail_localize_foldername($mbox_name)); 
     133  $OUTPUT->set_pagetitle(rcmail_localize_foldername($IMAP->mod_mailbox($mbox_name))); 
    134134} 
    135135 
  • program/steps/settings/edit_folder.inc

    rbbce3ed rd08333e  
    5555        $options = array(); 
    5656        $path    = $parent_imap; 
     57 
     58        // allow creating subfolders of INBOX folder 
     59        if ($path == 'INBOX') { 
     60            $path = $RCMAIL->imap->mod_mailbox($path, 'in'); 
     61        } 
     62    } 
     63 
     64    // remove personal namespace prefix 
     65    if (strlen($path)) { 
     66        $path_id = $path; 
     67        $path    = $RCMAIL->imap->mod_mailbox($path.$delimiter); 
     68        if ($path[strlen($path)-1] == $delimiter) { 
     69            $path = substr($path, 0, -1); 
     70        } 
    5771    } 
    5872 
     
    94108 
    95109    if (strlen($path)) { 
    96         if ($options['norename'] || $options['namespace'] != 'personal') { 
     110        if (!empty($options) && ($options['norename'] || $options['namespace'] != 'personal')) { 
    97111            // prevent user from moving folder 
    98112            $hidden_path = new html_hiddenfield(array('name' => '_parent', 'value' => $path)); 
     
    101115        else { 
    102116            $radio1 = new html_radiobutton(array('name' => '_parent', 'value' => '')); 
    103             $radio2 = new html_radiobutton(array('name' => '_parent', 'value' => $path)); 
    104             $selected  = isset($_POST['_parent']) ? $_POST['_parent'] : $path; 
     117            $radio2 = new html_radiobutton(array('name' => '_parent', 'value' => $path_id)); 
     118            $selected  = isset($_POST['_parent']) ? $_POST['_parent'] : $path_id; 
    105119 
    106120            $html_path = str_replace($delimiter, ' &raquo; ', rcmail_localize_folderpath($path)); 
  • program/steps/settings/folders.inc

    rbbb1427 rd08333e  
    127127        for ($x=sizeof($folderlist)-1; $x>=0; $x--) { 
    128128            if (preg_match($regexp, $folderlist[$x])) { 
    129                 $oldfolder = $oldname . $delimiter . preg_replace($regexp, '', $folderlist[$x]); 
    130                 $foldersplit = explode($delimiter, $folderlist[$x]); 
    131                 $level = count($foldersplit) - 1; 
     129                $oldfolder   = $oldname . $delimiter . preg_replace($regexp, '', $folderlist[$x]); 
     130                $foldersplit = explode($delimiter, $IMAP->mod_mailbox($folderlist[$x])); 
     131                $level       = count($foldersplit) - 1; 
    132132                $display_rename = str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $level)  
    133133                    . rcube_charset_convert($foldersplit[$level], 'UTF7-IMAP'); 
    134  
    135134                $before = isset($folderlist[$x+1]) ? rcube_charset_convert($folderlist[$x+1], 'UTF7-IMAP') : false; 
    136135 
     
    140139        } 
    141140 
     141        $index       = array_search($name, $folderlist); 
     142        $name        = $IMAP->mod_mailbox($name); 
    142143        $foldersplit = explode($delimiter, $name); 
    143         $level = count($foldersplit) - 1; 
     144        $level       = count($foldersplit) - 1; 
    144145        $display_rename = str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $level) . rcube_charset_convert($foldersplit[$level], 'UTF7-IMAP'); 
    145         $index = array_search($name, $folderlist); 
    146         $before = $index !== false && isset($folderlist[$index+1]) ? rcube_charset_convert($folderlist[$index+1], 'UTF7-IMAP') : false; 
    147  
    148         $OUTPUT->command('replace_folder_row', $oldname_utf8, 
    149             rcube_charset_convert($name, 'UTF7-IMAP'), $display_rename, $before); 
     146        $before         = $index !== false && isset($folderlist[$index+1]) ? rcube_charset_convert($folderlist[$index+1], 'UTF7-IMAP') : false; 
     147 
     148        $OUTPUT->command('replace_folder_row', $oldname_utf8, $name_utf8, $display_rename, $before); 
    150149    } 
    151150    else if (!$rename) { 
     
    244243    // pre-process folders list 
    245244    foreach ($a_unsubscribed as $i => $folder) { 
    246         $foldersplit = explode($delimiter, $folder); 
    247         $name = rcube_charset_convert(array_pop($foldersplit), 'UTF7-IMAP'); 
     245        $folder_id     = $folder; 
     246        $folder        = $IMAP->mod_mailbox($folder); 
     247        $foldersplit   = explode($delimiter, $folder); 
     248        $name          = rcube_charset_convert(array_pop($foldersplit), 'UTF7-IMAP'); 
    248249        $parent_folder = join($delimiter, $foldersplit); 
    249         $level = count($foldersplit); 
     250        $level         = count($foldersplit); 
    250251 
    251252        // add any necessary "virtual" parent folders 
    252         if ($parent_folder && !$seen[$parent_folder]) { 
     253        if ($parent_folder && !isset($seen[$parent_folder])) { 
    253254            for ($i=1; $i<=$level; $i++) { 
    254255                    $ancestor_folder = join($delimiter, array_slice($foldersplit, 0, $i)); 
     
    264265            } 
    265266        } 
    266      
     267 
     268        // Handle properly INBOX.INBOX situation 
     269        if (isset($seen[$folder])) { 
     270            continue; 
     271        } 
     272 
    267273        $seen[$folder]++; 
    268274 
    269275        $list_folders[] = array( 
    270             'id'    => $folder, 
     276            'id'    => $folder_id, 
    271277            'name'  => $name, 
    272278            'level' => $level, 
     
    355361            if ($key == $oldname) { 
    356362                unset($a_threaded[$key]); 
    357                 $a_threaded[$newname] = true; 
     363                $a_threaded[$newname] = true; 
    358364            } 
    359365            else if (preg_match($oldprefix, $key)) { 
    360366                unset($a_threaded[$key]); 
    361                 $a_threaded[preg_replace($oldprefix, $newname.$delimiter, $key)] = true; 
     367                    $a_threaded[preg_replace($oldprefix, $newname.$delimiter, $key)] = true; 
    362368            } 
    363369        } 
  • program/steps/settings/save_folder.inc

    rbbce3ed rd08333e  
    6565    else if (strlen($path)) { 
    6666        $name_imap = $path . $delimiter . $name_imap; 
     67    } 
     68    else { 
     69        $name_imap = $RCMAIL->imap->mod_mailbox($name, 'in');  
    6770    } 
    6871 
Note: See TracChangeset for help on using the changeset viewer.