Changeset 5758 in subversion


Ignore:
Timestamp:
Jan 12, 2012 5:51:05 AM (16 months ago)
Author:
alec
Message:

Removed globals $DB, $USER, $IMAP
Added abstract class rcube_storage, a parent for rcube_imap class

Removed rcmail methods:
imap_init() > storage_init() or get_storage()
imap_connect() > storage_connect()

Renamed session variables:
imap_host, imap_port, imap_ssl > storage_*

Renamed storage (rcube_imap) methods:
set_default_mailboxes > set_default_folders
set_mailbox > set_folder
get_mailbox_name > get_folder
mailbox_status > folder_status
get_mailbox_size > folder_size
list_mailboxes > list_folders_subscribed
list_unsubscribed > list_folders
create_mailbox > create_folder
rename_mailbox > rename_folder
delete_mailbox > delete_folder
mailbox_exists > folder_exists
mailbox_namespace > folder_namespace
mod_mailbox > mod_folder
mailbox_attributes > folder_attributes
mailbox_data > folder_data
mailbox_info > folder_info
mailbox_sync > folder_sync
expunge > expunge_folder
clear_mailbox > clear_folder
get_headers > get_message_headers
list_headers > list_messages
messagecount > count
message_index > index
message_index_direct > index_direct

Removed storage (rcube_imap) methods:
reconnect
get_response_str

Removed storage (rcube_imap) public properties:
page_size > get_pagesize(), set_pagesize()
list_page > get_page(), set_page()
threading > get_threading()
search_set > get_search_set()

Renamed config option default_imap_folders > default_folders

Location:
branches/devel-framework/roundcubemail
Files:
1 added
32 edited

Legend:

Unmodified
Added
Removed
  • branches/devel-framework/roundcubemail/bin/msgexport.sh

    r5716 r5758  
    3232        global $IMAP; 
    3333 
    34         $IMAP->set_mailbox($mbox); 
     34        $IMAP->set_folder($mbox); 
     35 
     36    $index = $IMAP->index($mbox, null, 'ASC'); 
     37    $count = $index->countMessages(); 
     38    $index = $index->get(); 
    3539 
    3640        vputs("Getting message list of {$mbox}..."); 
    37         vputs($IMAP->messagecount()." messages\n"); 
     41        vputs("$count messages\n"); 
    3842 
    3943        if ($filename) 
     
    4953                $out = STDOUT; 
    5054 
    51         for ($count = $IMAP->messagecount(), $i=1; $i <= $count; $i++) 
     55        for ($i = 0; $i < $count; $i++) 
    5256        { 
    53                 $headers = $IMAP->get_headers($i, null, false); 
     57                $headers = $IMAP->get_message_headers($index[$i]); 
    5458                $from = current(rcube_mime::decode_address_list($headers->from, 1, false)); 
    5559 
    5660                fwrite($out, sprintf("From %s %s UID %d\n", $from['mailto'], $headers->date, $headers->uid)); 
    57                 fwrite($out, $IMAP->conn->fetchPartHeader($mbox, $i)); 
    58                 fwrite($out, $IMAP->conn->handlePartBody($mbox, $i)); 
     61                fwrite($out, $IMAP->print_raw_body($headers->uid)); 
    5962                fwrite($out, "\n\n\n"); 
    6063 
    61                 progress_update($i, $count); 
     64                progress_update($i+1, $count); 
    6265        } 
    6366        vputs("\ncomplete.\n"); 
     
    117120 
    118121        $filename = null; 
    119         $mailboxes = $args['mbox'] == '*' ? $IMAP->list_mailboxes(null) : array($args['mbox']); 
     122        $mailboxes = $args['mbox'] == '*' ? $IMAP->list_folders(null) : array($args['mbox']); 
    120123 
    121124        foreach ($mailboxes as $mbox) 
  • branches/devel-framework/roundcubemail/index.php

    r5690 r5758  
    4949 
    5050// check DB connections and exit on failure 
    51 if ($err_str = $DB->is_error()) { 
     51if ($err_str = $RCMAIL->db->is_error()) { 
    5252  raise_error(array( 
    5353    'code' => 603, 
     
    129129  } 
    130130  else { 
    131     $error_code = (isset($RCMAIL->imap) && is_object($RCMAIL->imap)) ? $RCMAIL->imap->get_error_code() : 1; 
     131    $error_code = is_object($RCMAIL->storage) ? $RCMAIL->storage->get_error_code() : 1; 
    132132 
    133133    $OUTPUT->show_message($error_code < -1 ? 'imaperror' : (!$auth['valid'] ? 'invalidrequest' : 'loginfailed'), 'warning'); 
     
    140140// end session (after optional referer check) 
    141141else if ($RCMAIL->task == 'logout' && isset($_SESSION['user_id']) && (!$RCMAIL->config->get('referer_check') || rcube_check_referer())) { 
    142   $userdata = array('user' => $_SESSION['username'], 'host' => $_SESSION['imap_host'], 'lang' => $RCMAIL->user->language); 
     142  $userdata = array( 
     143    'user' => $_SESSION['username'], 
     144    'host' => $_SESSION['storage_host'], 
     145    'lang' => $RCMAIL->user->language, 
     146  ); 
    143147  $OUTPUT->show_message('loggedout'); 
    144148  $RCMAIL->logout_actions(); 
  • branches/devel-framework/roundcubemail/installer/rcube_install.php

    r5662 r5758  
    4242    'imap_root' => 'imap_ns_personal', 
    4343    'pagesize' => 'mail_pagesize', 
     44    'default_imap_folders' => 'default_folders', 
    4445  ); 
    4546 
     
    180181        $value = '%p'; 
    181182      } 
    182       else if ($prop == 'default_imap_folders') { 
     183      else if ($prop == 'default_folders') { 
    183184            $value = array(); 
    184             foreach ($this->config['default_imap_folders'] as $_folder) { 
     185            foreach ($this->config['default_folders'] as $_folder) { 
    185186              switch ($_folder) { 
    186187              case 'Drafts': $_folder = $this->config['drafts_mbox']; break; 
  • branches/devel-framework/roundcubemail/program/include/main.inc

    r5733 r5758  
    11941194 
    11951195  // get mailbox list 
    1196   $mbox_name = $RCMAIL->imap->get_mailbox_name(); 
     1196  $mbox_name = $RCMAIL->storage->get_folder(); 
    11971197 
    11981198  // build the folders tree 
    11991199  if (empty($a_mailboxes)) { 
    12001200    // get mailbox list 
    1201     $a_folders = $RCMAIL->imap->list_mailboxes('', $attrib['folder_name'], $attrib['folder_filter']); 
    1202     $delimiter = $RCMAIL->imap->get_hierarchy_delimiter(); 
     1201    $a_folders = $RCMAIL->storage->list_folders_subscribed('', $attrib['folder_name'], $attrib['folder_filter']); 
     1202    $delimiter = $RCMAIL->storage->get_hierarchy_delimiter(); 
    12031203    $a_mailboxes = array(); 
    12041204 
     
    12511251 
    12521252  if ($p['unsubscribed']) 
    1253     $list = $RCMAIL->imap->list_unsubscribed('', $p['folder_name'], $p['folder_filter'], $p['folder_rights']); 
     1253    $list = $RCMAIL->storage->list_folders('', $p['folder_name'], $p['folder_filter'], $p['folder_rights']); 
    12541254  else 
    1255     $list = $RCMAIL->imap->list_mailboxes('', $p['folder_name'], $p['folder_filter'], $p['folder_rights']); 
    1256  
    1257   $delimiter = $RCMAIL->imap->get_hierarchy_delimiter(); 
     1255    $list = $RCMAIL->storage->list_folders_subscribed('', $p['folder_name'], $p['folder_filter'], $p['folder_rights']); 
     1256 
     1257  $delimiter = $RCMAIL->storage->get_hierarchy_delimiter(); 
    12581258 
    12591259  foreach ($list as $folder) { 
     
    12861286  if (!$path) { 
    12871287    $n_folder = $folder; 
    1288     $folder = $RCMAIL->imap->mod_mailbox($folder); 
     1288    $folder = $RCMAIL->storage->mod_folder($folder); 
    12891289 
    12901290    if ($n_folder != $folder) { 
     
    13411341  $maxlength = intval($attrib['maxlength']); 
    13421342  $realnames = (bool)$attrib['realnames']; 
    1343   $msgcounts = $RCMAIL->imap->get_cache('messagecount'); 
     1343  $msgcounts = $RCMAIL->storage->get_cache('messagecount'); 
    13441344 
    13451345  $out = ''; 
     
    14331433 
    14341434    // skip folders in which it isn't possible to create subfolders 
    1435     if (!empty($opts['skip_noinferiors']) && ($attrs = $RCMAIL->imap->mailbox_attributes($folder['id'])) 
     1435    if (!empty($opts['skip_noinferiors']) && ($attrs = $RCMAIL->storage->folder_attributes($folder['id'])) 
    14361436        && in_array('\\Noinferiors', $attrs) 
    14371437    ) { 
     
    15021502 
    15031503    $protect_folders = $RCMAIL->config->get('protect_default_folders'); 
    1504     $default_folders = (array) $RCMAIL->config->get('default_imap_folders'); 
    1505     $delimiter       = $RCMAIL->imap->get_hierarchy_delimiter(); 
     1504    $default_folders = (array) $RCMAIL->config->get('default_folders'); 
     1505    $delimiter       = $RCMAIL->storage->get_hierarchy_delimiter(); 
    15061506    $path            = explode($delimiter, $path); 
    15071507    $result          = array(); 
     
    15461546  global $RCMAIL; 
    15471547 
    1548   $quota = $RCMAIL->imap->get_quota(); 
     1548  $quota = $RCMAIL->storage->get_quota(); 
    15491549  $quota = $RCMAIL->plugins->exec_hook('quota', $quota); 
    15501550 
     
    15921592    global $RCMAIL; 
    15931593 
    1594     $err_code = $RCMAIL->imap->get_error_code(); 
    1595     $res_code = $RCMAIL->imap->get_response_code(); 
    1596  
    1597     if ($res_code == rcube_imap::NOPERM) { 
     1594    $err_code = $RCMAIL->storage->get_error_code(); 
     1595    $res_code = $RCMAIL->storage->get_response_code(); 
     1596 
     1597    if ($res_code == rcube_storage::NOPERM) { 
    15981598        $RCMAIL->output->show_message('errornoperm', 'error'); 
    15991599    } 
    1600     else if ($res_code == rcube_imap::READONLY) { 
     1600    else if ($res_code == rcube_storage::READONLY) { 
    16011601        $RCMAIL->output->show_message('errorreadonly', 'error'); 
    16021602    } 
    1603     else if ($err_code && ($err_str = $RCMAIL->imap->get_error_str())) { 
     1603    else if ($err_code && ($err_str = $RCMAIL->storage->get_error_str())) { 
    16041604        // try to detect access rights problem and display appropriate message 
    16051605        if (stripos($err_str, 'Permission denied') !== false) 
     
    19671967  $d = preg_replace('/^[^\.]+\./', '', $n); 
    19681968  // %h - IMAP host 
    1969   $h = $_SESSION['imap_host'] ? $_SESSION['imap_host'] : $host; 
     1969  $h = $_SESSION['storage_host'] ? $_SESSION['storage_host'] : $host; 
    19701970  // %z - IMAP domain without first part, e.g. %h=imap.domain.tld, %z=domain.tld 
    19711971  $z = preg_replace('/^[^\.]+\./', '', $h); 
  • branches/devel-framework/roundcubemail/program/include/rcmail.php

    r5690 r5758  
    8787 
    8888  /** 
    89    * Instance of rcube_imap class. 
    90    * 
    91    * @var rcube_imap 
    92    */ 
    93   public $imap; 
     89   * Instance of rcube_storage class. 
     90   * 
     91   * @var rcube_storage 
     92   */ 
     93  public $storage; 
    9494 
    9595  /** 
     
    172172    // connect to database 
    173173    $this->get_dbh(); 
    174  
    175     // set global object for backward compatibility 
    176     $GLOBALS['DB'] = $this->db; 
    177174 
    178175    // start session 
     
    242239    if (is_object($user)) { 
    243240      $this->user = $user; 
    244  
    245       // set global object for backward compatibility 
    246       $GLOBALS['USER'] = $this->user; 
    247241 
    248242      // overwrite config with user preferences 
     
    425419    } 
    426420    else if ($id && $ldap_config[$id]) { 
    427       $contacts = new rcube_ldap($ldap_config[$id], $this->config->get('ldap_debug'), $this->config->mail_domain($_SESSION['imap_host'])); 
     421      $contacts = new rcube_ldap($ldap_config[$id], $this->config->get('ldap_debug'), $this->config->mail_domain($_SESSION['storage_host'])); 
    428422    } 
    429423    else if ($id === '0') { 
     
    585579 
    586580  /** 
    587    * Create global IMAP object and connect to server 
    588    * 
    589    * @param boolean True if connection should be established 
    590    */ 
    591   public function imap_init($connect = false) 
     581   * Initialize and get storage object 
     582   * 
     583   * @return rcube_storage Storage object 
     584   */ 
     585  public function get_storage() 
    592586  { 
    593587    // already initialized 
    594     if (is_object($this->imap)) 
     588    if (!is_object($this->storage)) { 
     589      $this->storage_init(); 
     590    } 
     591 
     592    return $this->storage; 
     593  } 
     594 
     595 
     596  /** 
     597   * Initialize storage object 
     598   */ 
     599  public function storage_init() 
     600  { 
     601    // already initialized 
     602    if (is_object($this->storage)) { 
    595603      return; 
    596  
    597     $this->imap = new rcube_imap(); 
    598     $this->imap->skip_deleted = $this->config->get('skip_deleted'); 
    599  
    600     // enable caching of imap data 
    601     $imap_cache     = $this->config->get('imap_cache'); 
     604    } 
     605 
     606    $driver = $this->config->get('storage_driver', 'imap'); 
     607    $driver_class = "rcube_$driver"; 
     608 
     609    if (!class_exists($driver_class)) { 
     610      raise_error(array( 
     611        'code' => 700, 'type' => 'php', 
     612        'file' => __FILE__, 'line' => __LINE__, 
     613        'message' => "Storage driver class ($driver) not found!"), 
     614        true, true); 
     615    } 
     616 
     617    // Initialize storage object 
     618    $this->storage = new $driver_class; 
     619 
     620    // enable caching of mail data 
     621    $storage_cache  = $this->config->get("$driver_cache"); 
    602622    $messages_cache = $this->config->get('messages_cache'); 
    603623    // for backward compatybility 
    604     if ($imap_cache === null && $messages_cache === null && $this->config->get('enable_caching')) { 
    605         $imap_cache     = 'db'; 
     624    if ($storage_cache === null && $messages_cache === null && $this->config->get('enable_caching')) { 
     625        $storage_cache  = 'db'; 
    606626        $messages_cache = true; 
    607627    } 
    608628 
    609     if ($imap_cache) 
    610         $this->imap->set_caching($imap_cache); 
     629    if ($storage_cache) 
     630        $this->storage->set_caching($storage_cache); 
    611631    if ($messages_cache) 
    612         $this->imap->set_messages_caching(true); 
     632        $this->storage->set_messages_caching(true); 
    613633 
    614634    // set pagesize from config 
     
    617637        $pagesize = $this->config->get('pagesize', 50); 
    618638    } 
    619     $this->imap->set_pagesize($pagesize); 
    620  
    621     // set connection options 
     639    $this->storage->set_pagesize($pagesize); 
     640 
     641    // set class options 
    622642    $options = array( 
    623       'auth_type'   => $this->config->get('imap_auth_type', 'check'), 
    624       'auth_cid'    => $this->config->get('imap_auth_cid'), 
    625       'auth_pw'     => $this->config->get('imap_auth_pw'), 
    626       'debug'       => (bool) $this->config->get('imap_debug', 0), 
    627       'force_caps'  => (bool) $this->config->get('imap_force_caps'), 
    628       'timeout'     => (int) $this->config->get('imap_timeout', 0), 
     643      'auth_type'   => $this->config->get("$driver_auth_type", 'check'), 
     644      'auth_cid'    => $this->config->get("$driver_auth_cid"), 
     645      'auth_pw'     => $this->config->get("$driver_auth_pw"), 
     646      'debug'       => (bool) $this->config->get("$driver_debug", 0), 
     647      'force_caps'  => (bool) $this->config->get("$driver_force_caps"), 
     648      'timeout'     => (int) $this->config->get("$driver_timeout", 0), 
     649      'skip_deleted' => (bool) $this->config->get('skip_deleted'), 
    629650    ); 
    630651 
    631     $this->imap->set_options($options); 
    632  
    633     // set global object for backward compatibility 
    634     $GLOBALS['IMAP'] = $this->imap; 
    635  
    636     $hook = $this->plugins->exec_hook('imap_init', array('fetch_headers' => $this->imap->fetch_add_headers)); 
    637     if ($hook['fetch_headers']) 
    638       $this->imap->fetch_add_headers = $hook['fetch_headers']; 
    639  
    640     // support this parameter for backward compatibility but log warning 
    641     if ($connect) { 
    642       $this->imap_connect(); 
    643       raise_error(array( 
    644         'code' => 800, 'type' => 'imap', 
    645         'file' => __FILE__, 'line' => __LINE__, 
    646         'message' => "rcube::imap_init(true) is deprecated, use rcube::imap_connect() instead"), 
    647         true, false); 
    648     } 
    649   } 
    650  
    651  
    652   /** 
    653    * Connect to IMAP server with stored session data 
    654    * 
    655    * @return bool True on success, false on error 
    656    */ 
    657   public function imap_connect() 
    658   { 
    659     if (!$this->imap) 
    660       $this->imap_init(); 
    661  
    662     if ($_SESSION['imap_host'] && !$this->imap->conn->connected()) { 
    663       if (!$this->imap->connect($_SESSION['imap_host'], $_SESSION['username'], $this->decrypt($_SESSION['password']), $_SESSION['imap_port'], $_SESSION['imap_ssl'])) { 
     652    $hook = $this->plugins->exec_hook("$driver_init", $options); 
     653 
     654    $this->storage->set_options($options); 
     655    $this->set_storage_prop(); 
     656  } 
     657 
     658 
     659  /** 
     660   * Connect to the mail storage server with stored session data 
     661   * 
     662   * @return bool True on success, False on error 
     663   */ 
     664  public function storage_connect() 
     665  { 
     666    $storage = $this->get_storage(); 
     667 
     668    if ($_SESSION['storage_host'] && !$storage->is_connected()) { 
     669      $host = $_SESSION['storage_host']; 
     670      $user = $_SESSION['username']; 
     671      $port = $_SESSION['storage_port']; 
     672      $ssl  = $_SESSION['storage_ssl']; 
     673      $pass = $this->decrypt($_SESSION['password']); 
     674 
     675      if (!$storage->connect($host, $user, $pass, $port, $ssl)) { 
    664676        if ($this->output) 
    665           $this->output->show_message($this->imap->get_error_code() == -1 ? 'imaperror' : 'sessionerror', 'error'); 
     677          $this->output->show_message($storage->get_error_code() == -1 ? 'imaperror' : 'sessionerror', 'error'); 
    666678      } 
    667679      else { 
    668         $this->set_imap_prop(); 
    669         return $this->imap->conn; 
     680        $this->set_storage_prop(); 
     681        return $storage->is_connected(); 
    670682      } 
    671683    } 
     
    745757 
    746758  /** 
    747    * Perfom login to the IMAP server and to the webmail service. 
     759   * Perfom login to the mail server and to the webmail service. 
    748760   * This will also create a new user entry if auto_create_user is configured. 
    749761   * 
    750    * @param string IMAP user name 
    751    * @param string IMAP password 
    752    * @param string IMAP host 
     762   * @param string Mail storage (IMAP) user name 
     763   * @param string Mail storage (IMAP) password 
     764   * @param string Mail storage (IMAP) host 
    753765   * 
    754766   * @return boolean True on success, False on failure 
     
    786798    if ($a_host['host']) { 
    787799      $host = $a_host['host']; 
    788       $imap_ssl = (isset($a_host['scheme']) && in_array($a_host['scheme'], array('ssl','imaps','tls'))) ? $a_host['scheme'] : null; 
     800      $ssl = (isset($a_host['scheme']) && in_array($a_host['scheme'], array('ssl','imaps','tls'))) ? $a_host['scheme'] : null; 
    789801      if (!empty($a_host['port'])) 
    790         $imap_port = $a_host['port']; 
    791       else if ($imap_ssl && $imap_ssl != 'tls' && (!$config['default_port'] || $config['default_port'] == 143)) 
    792         $imap_port = 993; 
    793     } 
    794  
    795     $imap_port = $imap_port ? $imap_port : $config['default_port']; 
     802        $port = $a_host['port']; 
     803      else if ($ssl && $ssl != 'tls' && (!$config['default_port'] || $config['default_port'] == 143)) 
     804        $port = 993; 
     805    } 
     806 
     807    if (!$port) { 
     808        $port = $config['default_port']; 
     809    } 
    796810 
    797811    /* Modify username with domain if required 
     
    806820    } 
    807821 
    808     // Convert username to lowercase. If IMAP backend 
     822    // Convert username to lowercase. If storage backend 
    809823    // is case-insensitive we need to store always the same username (#1487113) 
    810824    if ($config['login_lc']) { 
     
    831845      $username = $user->data['username']; 
    832846 
    833     if (!$this->imap) 
    834       $this->imap_init(); 
    835  
    836     // try IMAP login 
    837     if (!($imap_login = $this->imap->connect($host, $username, $pass, $imap_port, $imap_ssl))) { 
     847    if (!$this->storage) 
     848      $this->storage_init(); 
     849 
     850    // try to log in 
     851    if (!($login = $this->storage->connect($host, $username, $pass, $port, $ssl))) { 
    838852      // try with lowercase 
    839853      $username_lc = mb_strtolower($username); 
     
    843857          $username_lc = $user->data['username']; 
    844858 
    845         if ($imap_login = $this->imap->connect($host, $username_lc, $pass, $imap_port, $imap_ssl)) 
     859        if ($login = $this->storage->connect($host, $username_lc, $pass, $port, $ssl)) 
    846860          $username = $username_lc; 
    847861      } 
    848862    } 
    849863 
    850     // exit if IMAP login failed 
    851     if (!$imap_login) 
     864    // exit if login failed 
     865    if (!$login) { 
    852866      return false; 
     867    } 
    853868 
    854869    // user already registered -> update user's record 
     
    882897      // Configure environment 
    883898      $this->set_user($user); 
    884       $this->set_imap_prop(); 
     899      $this->set_storage_prop(); 
    885900      $this->session_configure(); 
    886901 
     
    890905      // create default folders on first login 
    891906      if ($config['create_default_folders'] && (!empty($created) || empty($user->data['last_login']))) { 
    892         $this->imap->create_default_folders(); 
     907        $this->storage->create_default_folders(); 
    893908      } 
    894909 
    895910      // set session vars 
    896       $_SESSION['user_id']   = $user->ID; 
    897       $_SESSION['username']  = $user->data['username']; 
    898       $_SESSION['imap_host'] = $host; 
    899       $_SESSION['imap_port'] = $imap_port; 
    900       $_SESSION['imap_ssl']  = $imap_ssl; 
    901       $_SESSION['password']  = $this->encrypt($pass); 
    902       $_SESSION['login_time'] = mktime(); 
     911      $_SESSION['user_id']      = $user->ID; 
     912      $_SESSION['username']     = $user->data['username']; 
     913      $_SESSION['storage_host'] = $host; 
     914      $_SESSION['storage_port'] = $port; 
     915      $_SESSION['storage_ssl']  = $ssl; 
     916      $_SESSION['password']     = $this->encrypt($pass); 
     917      $_SESSION['login_time']   = mktime(); 
    903918 
    904919      if (isset($_REQUEST['_timezone']) && $_REQUEST['_timezone'] != '_default_') 
     
    908923 
    909924      // force reloading complete list of subscribed mailboxes 
    910       $this->imap->clear_cache('mailboxes', true); 
     925      $this->storage->clear_cache('mailboxes', true); 
    911926 
    912927      return true; 
     
    918933 
    919934  /** 
    920    * Set root dir and last stored mailbox 
     935   * Set storage parameters. 
    921936   * This must be done AFTER connecting to the server! 
    922937   */ 
    923   public function set_imap_prop() 
    924   { 
    925     $this->imap->set_charset($this->config->get('default_charset', RCMAIL_CHARSET)); 
    926  
    927     if ($default_folders = $this->config->get('default_imap_folders')) { 
    928       $this->imap->set_default_mailboxes($default_folders); 
     938  private function set_storage_prop() 
     939  { 
     940    $storage = $this->get_storage(); 
     941 
     942    $storage->set_charset($this->config->get('default_charset', RCMAIL_CHARSET)); 
     943 
     944    if ($default_folders = $this->config->get('default_folders')) { 
     945      $storage->set_default_folders($default_folders); 
    929946    } 
    930947    if (isset($_SESSION['mbox'])) { 
    931       $this->imap->set_mailbox($_SESSION['mbox']); 
     948      $storage->set_folder($_SESSION['mbox']); 
    932949    } 
    933950    if (isset($_SESSION['page'])) { 
    934       $this->imap->set_page($_SESSION['page']); 
     951      $storage->set_page($_SESSION['page']); 
    935952    } 
    936953  } 
     
    958975      list($user, $domain) = explode('@', get_input_value('_user', RCUBE_INPUT_POST)); 
    959976      if (!empty($domain)) { 
    960         foreach ($default_host as $imap_host => $mail_domains) { 
     977        foreach ($default_host as $storage_host => $mail_domains) { 
    961978          if (is_array($mail_domains) && in_array($domain, $mail_domains)) { 
    962             $host = $imap_host; 
     979            $host = $storage_host; 
    963980            break; 
    964981          } 
     
    11681185        return; 
    11691186 
    1170       $this->imap_connect(); 
     1187      $this->storage_connect(); 
    11711188    } 
    11721189 
    11731190    if ($config['logout_purge'] && !empty($config['trash_mbox'])) { 
    1174       $this->imap->clear_mailbox($config['trash_mbox']); 
     1191      $this->storage->clear_folder($config['trash_mbox']); 
    11751192    } 
    11761193 
    11771194    if ($config['logout_expunge']) { 
    1178       $this->imap->expunge('INBOX'); 
     1195      $this->storage->expunge_folder('INBOX'); 
    11791196    } 
    11801197 
     
    12081225    } 
    12091226 
    1210     if (is_object($this->imap)) 
    1211       $this->imap->close(); 
     1227    if (is_object($this->storage)) 
     1228      $this->storage->close(); 
    12121229 
    12131230    // before closing the database connection, write session data 
     
    16081625  private function fix_namespace_settings($user) 
    16091626  { 
    1610     $prefix     = $this->imap->get_namespace('prefix'); 
     1627    $prefix     = $this->storage->get_namespace('prefix'); 
    16111628    $prefix_len = strlen($prefix); 
    16121629 
     
    16191636 
    16201637    // Build namespace prefix regexp 
    1621     $ns     = $this->imap->get_namespace(); 
     1638    $ns     = $this->storage->get_namespace(); 
    16221639    $regexp = array(); 
    16231640 
     
    16431660    } 
    16441661 
    1645     if (!empty($prefs['default_imap_folders'])) { 
    1646       foreach ($prefs['default_imap_folders'] as $idx => $name) { 
     1662    if (!empty($prefs['default_folders'])) { 
     1663      foreach ($prefs['default_folders'] as $idx => $name) { 
    16471664        if ($name != 'INBOX' && !preg_match($regexp, $name)) { 
    1648           $prefs['default_imap_folders'][$idx] = $prefix.$name; 
     1665          $prefs['default_folders'][$idx] = $prefix.$name; 
    16491666        } 
    16501667      } 
     
    16961713    // save updated preferences and reset imap settings (default folders) 
    16971714    $user->save_prefs($prefs); 
    1698     $this->set_imap_prop(); 
     1715    $this->set_storage_prop(); 
    16991716  } 
    17001717 
  • branches/devel-framework/roundcubemail/program/include/rcube_config.php

    r5733 r5758  
    7373            $this->prop[$folder] = rcube_charset_convert($this->prop[$folder], RCMAIL_CHARSET, 'UTF7-IMAP'); 
    7474 
    75         if (!empty($this->prop['default_imap_folders'])) 
    76             foreach ($this->prop['default_imap_folders'] as $n => $folder) 
    77                 $this->prop['default_imap_folders'][$n] = rcube_charset_convert($folder, RCMAIL_CHARSET, 'UTF7-IMAP'); 
     75        if (!empty($this->prop['default_folders'])) 
     76            foreach ($this->prop['default_folders'] as $n => $folder) 
     77                $this->prop['default_folders'][$n] = rcube_charset_convert($folder, RCMAIL_CHARSET, 'UTF7-IMAP'); 
    7878 
    7979        // set PHP error logging according to config 
  • branches/devel-framework/roundcubemail/program/include/rcube_imap.php

    r5744 r5758  
    3131 * @version    2.0 
    3232 */ 
    33 class rcube_imap 
     33class rcube_imap extends rcube_storage 
    3434{ 
    35     public $skip_deleted = false; 
    36     public $page_size = 10; 
    37     public $list_page = 1; 
    38     public $threading = false; 
    39     public $fetch_add_headers = ''; 
    40     public $get_all_headers = false; 
    41  
    4235    /** 
    4336     * Instance of rcube_imap_generic 
     
    5245     * @var rcube_imap_cache 
    5346     */ 
    54     private $mcache; 
     47    protected $mcache; 
    5548 
    5649    /** 
     
    5952     * @var rcube_cache 
    6053     */ 
    61     private $cache; 
     54    protected $cache; 
    6255 
    6356    /** 
     
    6659     * @var array 
    6760     */ 
    68     private $icache = array(); 
    69  
    70     private $mailbox = 'INBOX'; 
    71     private $delimiter = NULL; 
    72     private $namespace = NULL; 
    73     private $sort_field = ''; 
    74     private $sort_order = 'DESC'; 
    75     private $default_charset = 'ISO-8859-1'; 
    76     private $struct_charset = NULL; 
    77     private $default_folders = array('INBOX'); 
    78     private $uid_id_map = array(); 
    79     private $msg_headers = array(); 
    80     public  $search_set = NULL; 
    81     public  $search_string = ''; 
    82     private $search_charset = ''; 
    83     private $search_sort_field = ''; 
    84     private $search_threads = false; 
    85     private $search_sorted = false; 
    86     private $options = array('auth_method' => 'check'); 
    87     private $host, $user, $pass, $port, $ssl; 
    88     private $caching = false; 
    89     private $messages_caching = false; 
    90  
    91     /** 
    92      * All (additional) headers used (in any way) by Roundcube 
    93      * Not listed here: DATE, FROM, TO, CC, REPLY-TO, SUBJECT, CONTENT-TYPE, LIST-POST 
    94      * (used for messages listing) are hardcoded in rcube_imap_generic::fetchHeaders() 
    95      * 
    96      * @var array 
    97      * @see rcube_imap::fetch_add_headers 
    98      */ 
    99     private $all_headers = array( 
    100         'IN-REPLY-TO', 
    101         'BCC', 
    102         'MESSAGE-ID', 
    103         'CONTENT-TRANSFER-ENCODING', 
    104         'REFERENCES', 
    105         'X-DRAFT-INFO', 
    106         'MAIL-FOLLOWUP-TO', 
    107         'MAIL-REPLY-TO', 
    108         'RETURN-PATH', 
    109     ); 
    110  
    111     const UNKNOWN       = 0; 
    112     const NOPERM        = 1; 
    113     const READONLY      = 2; 
    114     const TRYCREATE     = 3; 
    115     const INUSE         = 4; 
    116     const OVERQUOTA     = 5; 
    117     const ALREADYEXISTS = 6; 
    118     const NONEXISTENT   = 7; 
    119     const CONTACTADMIN  = 8; 
     61    protected $icache = array(); 
     62 
     63    protected $list_page = 1; 
     64    protected $delimiter; 
     65    protected $namespace; 
     66    protected $sort_field = ''; 
     67    protected $sort_order = 'DESC'; 
     68    protected $struct_charset; 
     69    protected $uid_id_map = array(); 
     70    protected $msg_headers = array(); 
     71    protected $search_set; 
     72    protected $search_string = ''; 
     73    protected $search_charset = ''; 
     74    protected $search_sort_field = ''; 
     75    protected $search_threads = false; 
     76    protected $search_sorted = false; 
     77    protected $options = array('auth_method' => 'check'); 
     78    protected $host, $user, $pass, $port, $ssl; 
     79    protected $caching = false; 
     80    protected $messages_caching = false; 
     81    protected $threading = false; 
    12082 
    12183 
     
    12385     * Object constructor. 
    12486     */ 
    125     function __construct() 
     87    public function __construct() 
    12688    { 
    12789        $this->conn = new rcube_imap_generic(); 
     
    144106     * @param  integer  $port    Port to connect to 
    145107     * @param  string   $use_ssl SSL schema (either ssl or tls) or null if plain connection 
     108     * 
    146109     * @return boolean  TRUE on success, FALSE on failure 
    147      * @access public 
    148      */ 
    149     function connect($host, $user, $pass, $port=143, $use_ssl=null) 
     110     */ 
     111    public function connect($host, $user, $pass, $port=143, $use_ssl=null) 
    150112    { 
    151113        // check for OpenSSL support in PHP build 
     
    213175 
    214176    /** 
    215      * Close IMAP connection 
     177     * Close IMAP connection. 
    216178     * Usually done on script shutdown 
    217      * 
    218      * @access public 
    219      */ 
    220     function close() 
     179     */ 
     180    public function close() 
    221181    { 
    222182        $this->conn->closeConnection(); 
     
    227187 
    228188    /** 
    229      * Close IMAP connection and re-connect 
    230      * This is used to avoid some strange socket errors when talking to Courier IMAP 
    231      * 
    232      * @access public 
    233      */ 
    234     function reconnect() 
    235     { 
    236         $this->conn->closeConnection(); 
    237         $connected = $this->connect($this->host, $this->user, $this->pass, $this->port, $this->ssl); 
    238  
    239         // issue SELECT command to restore connection status 
    240         if ($connected && strlen($this->mailbox)) 
    241             $this->conn->select($this->mailbox); 
     189     * Checks IMAP connection. 
     190     * 
     191     * @return boolean  TRUE on success, FALSE on failure 
     192     */ 
     193    public function is_connected() 
     194    { 
     195        return $this->conn && $this->conn->connected(); 
    242196    } 
    243197 
     
    248202     * @return int Error code 
    249203     */ 
    250     function get_error_code() 
     204    public function get_error_code() 
    251205    { 
    252206        return $this->conn->errornum; 
     
    255209 
    256210    /** 
    257      * Returns message of last error 
    258      * 
    259      * @return string Error message 
    260      */ 
    261     function get_error_str() 
     211     * Returns text of last error 
     212     * 
     213     * @return string Error string 
     214     */ 
     215    public function get_error_str() 
    262216    { 
    263217        return $this->conn->error; 
     
    270224     * @return int Response code 
    271225     */ 
    272     function get_response_code() 
     226    public function get_response_code() 
    273227    { 
    274228        switch ($this->conn->resultcode) { 
     
    296250 
    297251    /** 
    298      * Returns last command response 
    299      * 
    300      * @return string Response 
    301      */ 
    302     function get_response_str() 
    303     { 
    304         return $this->conn->result; 
    305     } 
    306  
    307  
    308     /** 
    309      * Set options to be used in rcube_imap_generic::connect() 
    310      * 
    311      * @param array $opt Options array 
    312      */ 
    313     function set_options($opt) 
    314     { 
    315         $this->options = array_merge($this->options, (array)$opt); 
    316     } 
    317  
    318  
    319     /** 
    320252     * Activate/deactivate debug mode 
    321253     * 
    322254     * @param boolean $dbg True if IMAP conversation should be logged 
    323      * @access public 
    324      */ 
    325     function set_debug($dbg = true) 
     255     */ 
     256    public function set_debug($dbg = true) 
    326257    { 
    327258        $this->options['debug'] = $dbg; 
     
    331262 
    332263    /** 
    333      * Set default message charset 
    334      * 
    335      * This will be used for message decoding if a charset specification is not available 
    336      * 
    337      * @param  string $cs Charset string 
    338      * @access public 
    339      */ 
    340     function set_charset($cs) 
    341     { 
    342         $this->default_charset = $cs; 
    343     } 
    344  
    345  
    346     /** 
    347      * This list of folders will be listed above all other folders 
    348      * 
    349      * @param  array $arr Indexed list of folder names 
    350      * @access public 
    351      */ 
    352     function set_default_mailboxes($arr) 
    353     { 
    354         if (is_array($arr)) { 
    355             $this->default_folders = $arr; 
    356  
    357             // add inbox if not included 
    358             if (!in_array('INBOX', $this->default_folders)) 
    359                 array_unshift($this->default_folders, 'INBOX'); 
    360         } 
    361     } 
    362  
    363  
    364     /** 
    365      * Set internal mailbox reference. 
    366      * 
    367      * All operations will be perfomed on this mailbox/folder 
    368      * 
    369      * @param  string $mailbox Mailbox/Folder name 
    370      * @access public 
    371      */ 
    372     function set_mailbox($mailbox) 
    373     { 
    374         if ($this->mailbox == $mailbox) 
     264     * Set internal folder reference. 
     265     * All operations will be perfomed on this folder. 
     266     * 
     267     * @param  string $folder Folder name 
     268     */ 
     269    public function set_folder($folder) 
     270    { 
     271        if ($this->folder == $folder) 
    375272            return; 
    376273 
    377         $this->mailbox = $mailbox; 
    378  
    379         // clear messagecount cache for this mailbox 
    380         $this->_clear_messagecount($mailbox); 
    381     } 
    382  
    383  
    384     /** 
    385      * Set internal list page 
    386      * 
    387      * @param  number $page Page number to list 
    388      * @access public 
    389      */ 
    390     function set_page($page) 
    391     { 
    392         $this->list_page = (int)$page; 
    393     } 
    394  
    395  
    396     /** 
    397      * Set internal page size 
    398      * 
    399      * @param  number $size Number of messages to display on one page 
    400      * @access public 
    401      */ 
    402     function set_pagesize($size) 
    403     { 
    404         $this->page_size = (int)$size; 
     274        $this->folder = $folder; 
     275 
     276        // clear messagecount cache for this folder 
     277        $this->clear_messagecount($folder); 
    405278    } 
    406279 
     
    416289     *                      4 - true if sorted, bool 
    417290     */ 
    418     function set_search_set($set) 
     291    public function set_search_set($set) 
    419292    { 
    420293        $set = (array)$set; 
     
    434307     * @return array Search set 
    435308     */ 
    436     function get_search_set() 
    437     { 
     309    public function get_search_set() 
     310    { 
     311        if (empty($this->search_set)) { 
     312            return null; 
     313        } 
     314 
    438315        return array( 
    439316            $this->search_string, 
     
    447324 
    448325    /** 
    449      * Returns the currently used mailbox name 
    450      * 
    451      * @return  string Name of the mailbox/folder 
    452      * @access  public 
    453      */ 
    454     function get_mailbox_name() 
    455     { 
    456         return $this->mailbox; 
    457     } 
    458  
    459  
    460     /** 
    461326     * Returns the IMAP server's capability 
    462327     * 
    463328     * @param   string  $cap Capability name 
     329     * 
    464330     * @return  mixed   Capability value or TRUE if supported, FALSE if not 
    465      * @access  public 
    466      */ 
    467     function get_capability($cap) 
     331     */ 
     332    public function get_capability($cap) 
    468333    { 
    469334        return $this->conn->getCapability(strtoupper($cap)); 
     
    472337 
    473338    /** 
    474      * Sets threading flag to the best supported THREAD algorithm 
    475      * 
    476      * @param  boolean  $enable TRUE to enable and FALSE 
    477      * @return string   Algorithm or false if THREAD is not supported 
    478      * @access public 
    479      */ 
    480     function set_threading($enable=false) 
    481     { 
    482         $this->threading = false; 
    483  
    484         if ($enable && ($caps = $this->get_capability('THREAD'))) { 
    485             if (in_array('REFS', $caps)) 
    486                 $this->threading = 'REFS'; 
    487             else if (in_array('REFERENCES', $caps)) 
    488                 $this->threading = 'REFERENCES'; 
    489             else if (in_array('ORDEREDSUBJECT', $caps)) 
    490                 $this->threading = 'ORDEREDSUBJECT'; 
    491         } 
    492  
    493         return $this->threading; 
    494     } 
    495  
    496  
    497     /** 
    498      * Checks the PERMANENTFLAGS capability of the current mailbox 
     339     * Checks the PERMANENTFLAGS capability of the current folder 
    499340     * and returns true if the given flag is supported by the IMAP server 
    500341     * 
    501342     * @param   string  $flag Permanentflag name 
     343     * 
    502344     * @return  boolean True if this flag is supported 
    503      * @access  public 
    504      */ 
    505     function check_permflag($flag) 
     345     */ 
     346    public function check_permflag($flag) 
    506347    { 
    507348        $flag = strtoupper($flag); 
     
    517358     * @access  public 
    518359     */ 
    519     function get_hierarchy_delimiter() 
     360    public function get_hierarchy_delimiter() 
    520361    { 
    521362        return $this->delimiter; 
     
    529370     * 
    530371     * @return  array  Namespace data 
    531      * @access  public 
    532      */ 
    533     function get_namespace($name=null) 
     372     */ 
     373    public function get_namespace($name = null) 
    534374    { 
    535375        $ns = $this->namespace; 
     
    546386    /** 
    547387     * Sets delimiter and namespaces 
    548      * 
    549      * @access private 
    550      */ 
    551     private function set_env() 
     388     */ 
     389    protected function set_env() 
    552390    { 
    553391        if ($this->delimiter !== null && $this->namespace !== null) { 
     
    615453        } 
    616454 
    617         // Find personal namespace prefix for mod_mailbox() 
     455        // Find personal namespace prefix for mod_folder() 
    618456        // Prefix can be removed when there is only one personal namespace 
    619457        if (is_array($this->namespace['personal']) && count($this->namespace['personal']) == 1) { 
     
    627465 
    628466    /** 
    629      * Get message count for a specific mailbox 
    630      * 
    631      * @param  string  $mailbox Mailbox/folder name 
     467     * Get message count for a specific folder 
     468     * 
     469     * @param  string  $folder  Folder name 
    632470     * @param  string  $mode    Mode for count [ALL|THREADS|UNSEEN|RECENT] 
    633471     * @param  boolean $force   Force reading from server and update cache 
    634472     * @param  boolean $status  Enables storing folder status info (max UID/count), 
    635      *                          required for mailbox_status() 
     473     *                          required for folder_status() 
     474     * 
    636475     * @return int     Number of messages 
    637      * @access public 
    638      */ 
    639     function messagecount($mailbox='', $mode='ALL', $force=false, $status=true) 
    640     { 
    641         if (!strlen($mailbox)) { 
    642             $mailbox = $this->mailbox; 
    643         } 
    644  
    645         return $this->_messagecount($mailbox, $mode, $force, $status); 
    646     } 
    647  
    648  
    649     /** 
    650      * Private method for getting nr of messages 
    651      * 
    652      * @param string  $mailbox Mailbox name 
     476     */ 
     477    public function count($folder='', $mode='ALL', $force=false, $status=true) 
     478    { 
     479        if (!strlen($folder)) { 
     480            $folder = $this->folder; 
     481        } 
     482 
     483        return $this->messagecount($folder, $mode, $force, $status); 
     484    } 
     485 
     486 
     487    /** 
     488     * protected method for getting nr of messages 
     489     * 
     490     * @param string  $folder  Folder name 
    653491     * @param string  $mode    Mode for count [ALL|THREADS|UNSEEN|RECENT] 
    654492     * @param boolean $force   Force reading from server and update cache 
    655493     * @param boolean $status  Enables storing folder status info (max UID/count), 
    656      *                         required for mailbox_status() 
     494     *                         required for folder_status() 
     495     * 
    657496     * @return int Number of messages 
    658      * @access  private 
    659      * @see     rcube_imap::messagecount() 
    660      */ 
    661     private function _messagecount($mailbox, $mode='ALL', $force=false, $status=true) 
     497     * @see rcube_imap::count() 
     498     */ 
     499    protected function messagecount($folder, $mode='ALL', $force=false, $status=true) 
    662500    { 
    663501        $mode = strtoupper($mode); 
    664502 
    665503        // count search set 
    666         if ($this->search_string && $mailbox == $this->mailbox && ($mode == 'ALL' || $mode == 'THREADS') && !$force) { 
     504        if ($this->search_string && $folder == $this->folder && ($mode == 'ALL' || $mode == 'THREADS') && !$force) { 
    667505            if ($mode == 'ALL') 
    668506                return $this->search_set->countMessages(); 
     
    671509        } 
    672510 
    673         $a_mailbox_cache = $this->get_cache('messagecount'); 
     511        $a_folder_cache = $this->get_cache('messagecount'); 
    674512 
    675513        // return cached value 
    676         if (!$force && is_array($a_mailbox_cache[$mailbox]) && isset($a_mailbox_cache[$mailbox][$mode])) 
    677             return $a_mailbox_cache[$mailbox][$mode]; 
    678  
    679         if (!is_array($a_mailbox_cache[$mailbox])) 
    680             $a_mailbox_cache[$mailbox] = array(); 
     514        if (!$force && is_array($a_folder_cache[$folder]) && isset($a_folder_cache[$folder][$mode])) 
     515            return $a_folder_cache[$folder][$mode]; 
     516 
     517        if (!is_array($a_folder_cache[$folder])) 
     518            $a_folder_cache[$folder] = array(); 
    681519 
    682520        if ($mode == 'THREADS') { 
    683             $res   = $this->fetch_threads($mailbox, $force); 
     521            $res   = $this->fetch_threads($folder, $force); 
    684522            $count = $res->count(); 
    685523 
    686524            if ($status) { 
    687525                $msg_count = $res->countMessages(); 
    688                 $this->set_folder_stats($mailbox, 'cnt', $msg_count); 
    689                 $this->set_folder_stats($mailbox, 'maxuid', $msg_count ? $this->id2uid($msg_count, $mailbox) : 0); 
     526                $this->set_folder_stats($folder, 'cnt', $msg_count); 
     527                $this->set_folder_stats($folder, 'maxuid', $msg_count ? $this->id2uid($msg_count, $folder) : 0); 
    690528            } 
    691529        } 
    692530        // RECENT count is fetched a bit different 
    693531        else if ($mode == 'RECENT') { 
    694             $count = $this->conn->countRecent($mailbox); 
     532            $count = $this->conn->countRecent($folder); 
    695533        } 
    696534        // use SEARCH for message counting 
    697         else if ($this->skip_deleted) { 
     535        else if (!empty($this->options['skip_deleted'])) { 
    698536            $search_str = "ALL UNDELETED"; 
    699537            $keys       = array('COUNT'); 
     
    715553            // get message count using (E)SEARCH 
    716554            // not very performant but more precise (using UNDELETED) 
    717             $index = $this->conn->search($mailbox, $search_str, true, $keys); 
     555            $index = $this->conn->search($folder, $search_str, true, $keys); 
    718556            $count = $index->count(); 
    719557 
    720558            if ($mode == 'ALL') { 
    721                 // Cache index data, will be used in message_index_direct() 
     559                // Cache index data, will be used in index_direct() 
    722560                $this->icache['undeleted_idx'] = $index; 
    723561 
    724562                if ($status) { 
    725                     $this->set_folder_stats($mailbox, 'cnt', $count); 
    726                     $this->set_folder_stats($mailbox, 'maxuid', $index->max()); 
     563                    $this->set_folder_stats($folder, 'cnt', $count); 
     564                    $this->set_folder_stats($folder, 'maxuid', $index->max()); 
    727565                } 
    728566            } 
     
    730568        else { 
    731569            if ($mode == 'UNSEEN') 
    732                 $count = $this->conn->countUnseen($mailbox); 
     570                $count = $this->conn->countUnseen($folder); 
    733571            else { 
    734                 $count = $this->conn->countMessages($mailbox); 
     572                $count = $this->conn->countMessages($folder); 
    735573                if ($status) { 
    736                     $this->set_folder_stats($mailbox,'cnt', $count); 
    737                     $this->set_folder_stats($mailbox, 'maxuid', $count ? $this->id2uid($count, $mailbox) : 0); 
     574                    $this->set_folder_stats($folder,'cnt', $count); 
     575                    $this->set_folder_stats($folder, 'maxuid', $count ? $this->id2uid($count, $folder) : 0); 
    738576                } 
    739577            } 
    740578        } 
    741579 
    742         $a_mailbox_cache[$mailbox][$mode] = (int)$count; 
     580        $a_folder_cache[$folder][$mode] = (int)$count; 
    743581 
    744582        // write back to cache 
    745         $this->update_cache('messagecount', $a_mailbox_cache); 
     583        $this->update_cache('messagecount', $a_folder_cache); 
    746584 
    747585        return (int)$count; 
     
    751589    /** 
    752590     * Public method for listing headers 
    753      * convert mailbox name with root dir first 
    754      * 
    755      * @param   string   $mailbox    Mailbox/folder name 
     591     * 
     592     * @param   string   $folder     Folder name 
    756593     * @param   int      $page       Current page to list 
    757594     * @param   string   $sort_field Header field to sort by 
     
    760597     * 
    761598     * @return  array    Indexed array with message header objects 
    762      * @access  public 
    763      */ 
    764     public function list_headers($mailbox='', $page=NULL, $sort_field=NULL, $sort_order=NULL, $slice=0) 
    765     { 
    766         if (!strlen($mailbox)) { 
    767             $mailbox = $this->mailbox; 
    768         } 
    769  
    770         return $this->_list_headers($mailbox, $page, $sort_field, $sort_order, $slice); 
    771     } 
    772  
    773  
    774     /** 
    775      * Private method for listing message headers 
    776      * 
    777      * @param   string   $mailbox    Mailbox name 
     599     */ 
     600    public function list_messages($folder='', $page=NULL, $sort_field=NULL, $sort_order=NULL, $slice=0) 
     601    { 
     602        if (!strlen($folder)) { 
     603            $folder = $this->folder; 
     604        } 
     605 
     606        return $this->_list_messages($folder, $page, $sort_field, $sort_order, $slice); 
     607    } 
     608 
     609 
     610    /** 
     611     * protected method for listing message headers 
     612     * 
     613     * @param   string   $folder     Folder name 
    778614     * @param   int      $page       Current page to list 
    779615     * @param   string   $sort_field Header field to sort by 
     
    782618     * 
    783619     * @return  array    Indexed array with message header objects 
    784      * @see     rcube_imap::list_headers 
    785      */ 
    786     private function _list_headers($mailbox='', $page=NULL, $sort_field=NULL, $sort_order=NULL, $slice=0) 
    787     { 
    788         if (!strlen($mailbox)) { 
     620     * @see     rcube_imap::list_messages 
     621     */ 
     622    protected function _list_messages($folder='', $page=NULL, $sort_field=NULL, $sort_order=NULL, $slice=0) 
     623    { 
     624        if (!strlen($folder)) { 
    789625            return array(); 
    790626        } 
     
    794630 
    795631        // use saved message set 
    796         if ($this->search_string && $mailbox == $this->mailbox) { 
    797             return $this->_list_header_set($mailbox, $page, $slice); 
     632        if ($this->search_string && $folder == $this->folder) { 
     633            return $this->list_header_set($folder, $page, $slice); 
    798634        } 
    799635 
    800636        if ($this->threading) { 
    801             return $this->_list_thread_headers($mailbox, $page, $slice); 
     637            return $this->list_thread_headers($folder, $page, $slice); 
    802638        } 
    803639 
    804640        // get UIDs of all messages in the folder, sorted 
    805         $index = $this->message_index($mailbox, $this->sort_field, $this->sort_order); 
     641        $index = $this->index($folder, $this->sort_field, $this->sort_order); 
    806642 
    807643        if ($index->isEmpty()) { 
     
    819655        // fetch reqested messages headers 
    820656        $a_index = $index->get(); 
    821         $a_msg_headers = $this->fetch_headers($mailbox, $a_index); 
     657        $a_msg_headers = $this->fetch_headers($folder, $a_index); 
    822658 
    823659        return array_values($a_msg_headers); 
     
    826662 
    827663    /** 
    828      * Private method for listing message headers using threads 
    829      * 
    830      * @param   string   $mailbox    Mailbox/folder name 
     664     * protected method for listing message headers using threads 
     665     * 
     666     * @param   string   $folder     Folder name 
    831667     * @param   int      $page       Current page to list 
    832668     * @param   int      $slice      Number of slice items to extract from result array 
     
    835671     * @see     rcube_imap::list_headers 
    836672     */ 
    837     private function _list_thread_headers($mailbox, $page, $slice=0) 
     673    protected function list_thread_headers($folder, $page, $slice=0) 
    838674    { 
    839675        // get all threads (not sorted) 
    840676        if ($mcache = $this->get_mcache_engine()) 
    841             $threads = $mcache->get_thread($mailbox); 
     677            $threads = $mcache->get_thread($folder); 
    842678        else 
    843             $threads = $this->fetch_threads($mailbox); 
    844  
    845         return $this->_fetch_thread_headers($mailbox, $threads, $page, $slice); 
    846     } 
    847  
     679            $threads = $this->fetch_threads($folder); 
     680 
     681        return $this->fetch_thread_headers($folder, $threads, $page, $slice); 
     682    } 
    848683 
    849684    /** 
    850685     * Method for fetching threads data 
    851686     * 
    852      * @param  string $mailbox  Folder name 
    853      * @param  bool   $force    Use IMAP server, no cache 
     687     * @param  string $folder  Folder name 
     688     * @param  bool   $force   Use IMAP server, no cache 
    854689     * 
    855690     * @return rcube_imap_thread Thread data object 
    856691     */ 
    857     function fetch_threads($mailbox, $force = false) 
     692    function fetch_threads($folder, $force = false) 
    858693    { 
    859694        if (!$force && ($mcache = $this->get_mcache_engine())) { 
    860695            // don't store in self's internal cache, cache has it's own internal cache 
    861             return $mcache->get_thread($mailbox); 
     696            return $mcache->get_thread($folder); 
    862697        } 
    863698 
    864699        if (empty($this->icache['threads'])) { 
    865700            // get all threads 
    866             $result = $this->conn->thread($mailbox, $this->threading, 
    867                 $this->skip_deleted ? 'UNDELETED' : '', true); 
     701            $result = $this->conn->thread($folder, $this->threading, 
     702                $this->options['skip_deleted'] ? 'UNDELETED' : '', true); 
    868703 
    869704            // add to internal (fast) cache 
     
    876711 
    877712    /** 
    878      * Private method for fetching threaded messages headers 
    879      * 
    880      * @param string              $mailbox    Mailbox name 
     713     * protected method for fetching threaded messages headers 
     714     * 
     715     * @param string              $folder     Folder name 
    881716     * @param rcube_result_thread $threads    Threads data object 
    882717     * @param int                 $page       List page number 
     
    884719     * 
    885720     * @return array  Messages headers 
    886      * @access  private 
    887      */ 
    888     private function _fetch_thread_headers($mailbox, $threads, $page, $slice=0) 
     721     */ 
     722    protected function fetch_thread_headers($folder, $threads, $page, $slice=0) 
    889723    { 
    890724        // Sort thread structure 
     
    903737 
    904738        // fetch reqested headers from server 
    905         $a_msg_headers = $this->fetch_headers($mailbox, $a_index); 
     739        $a_msg_headers = $this->fetch_headers($folder, $a_index); 
    906740 
    907741        unset($a_index); 
    908742 
    909743        // Set depth, has_children and unread_children fields in headers 
    910         $this->_set_thread_flags($a_msg_headers, $threads); 
     744        $this->set_thread_flags($a_msg_headers, $threads); 
    911745 
    912746        return array_values($a_msg_headers); 
     
    915749 
    916750    /** 
    917      * Private method for setting threaded messages flags: 
     751     * protected method for setting threaded messages flags: 
    918752     * depth, has_children and unread_children 
    919753     * 
     
    922756     * 
    923757     * @return array Message headers array indexed by message UID 
    924      * @access private 
    925      */ 
    926     private function _set_thread_flags(&$headers, $threads) 
     758     */ 
     759    protected function set_thread_flags(&$headers, $threads) 
    927760    { 
    928761        $parents = array(); 
     
    948781 
    949782    /** 
    950      * Private method for listing a set of message headers (search results) 
    951      * 
    952      * @param   string   $mailbox  Mailbox/folder name 
     783     * protected method for listing a set of message headers (search results) 
     784     * 
     785     * @param   string   $folder   Folder name 
    953786     * @param   int      $page     Current page to list 
    954787     * @param   int      $slice    Number of slice items to extract from result array 
    955788     * 
    956789     * @return  array    Indexed array with message header objects 
    957      * @access  private 
    958      */ 
    959     private function _list_header_set($mailbox, $page, $slice=0) 
    960     { 
    961         if (!strlen($mailbox) || empty($this->search_set) || $this->search_set->isEmpty()) { 
     790     */ 
     791    protected function list_header_set($folder, $page, $slice=0) 
     792    { 
     793        if (!strlen($folder) || empty($this->search_set) || $this->search_set->isEmpty()) { 
    962794            return array(); 
    963795        } 
     
    965797        // use saved messages from searching 
    966798        if ($this->threading) { 
    967             return $this->_list_thread_header_set($mailbox, $page, $slice); 
     799            return $this->list_thread_header_set($folder, $page, $slice); 
    968800        } 
    969801 
     
    1013845            // fetch headers 
    1014846            $a_index       = $index->get(); 
    1015             $a_msg_headers = $this->fetch_headers($mailbox, $a_index); 
     847            $a_msg_headers = $this->fetch_headers($folder, $a_index); 
    1016848 
    1017849            return array_values($a_msg_headers); 
     
    1024856        if (($cnt > 300 && $cnt > $this->page_size) || !$this->sort_field) { 
    1025857            // use memory less expensive (and quick) method for big result set 
    1026             $index = clone $this->message_index('', $this->sort_field, $this->sort_order); 
     858            $index = clone $this->index('', $this->sort_field, $this->sort_order); 
    1027859            // get messages uids for one page... 
    1028860            $index->slice($start_msg, min($cnt-$from, $this->page_size)); 
     
    1033865            // ...and fetch headers 
    1034866            $a_index       = $index->get(); 
    1035             $a_msg_headers = $this->fetch_headers($mailbox, $a_index); 
     867            $a_msg_headers = $this->fetch_headers($folder, $a_index); 
    1036868 
    1037869            return array_values($a_msg_headers); 
     
    1040872            // for small result set we can fetch all messages headers 
    1041873            $a_index       = $index->get(); 
    1042             $a_msg_headers = $this->fetch_headers($mailbox, $a_index, false); 
     874            $a_msg_headers = $this->fetch_headers($folder, $a_index, false); 
    1043875 
    1044876            // return empty array if no messages found 
     
    1063895 
    1064896    /** 
    1065      * Private method for listing a set of threaded message headers (search results) 
    1066      * 
    1067      * @param   string   $mailbox    Mailbox/folder name 
     897     * protected method for listing a set of threaded message headers (search results) 
     898     * 
     899     * @param   string   $folder     Folder name 
    1068900     * @param   int      $page       Current page to list 
    1069901     * @param   int      $slice      Number of slice items to extract from result array 
    1070902     * 
    1071903     * @return  array    Indexed array with message header objects 
    1072      * @access  private 
    1073      * @see     rcube_imap::list_header_set() 
    1074      */ 
    1075     private function _list_thread_header_set($mailbox, $page, $slice=0) 
     904     * @see rcube_imap::list_header_set() 
     905     */ 
     906    protected function list_thread_header_set($folder, $page, $slice=0) 
    1076907    { 
    1077908        // update search_set if previous data was fetched with disabled threading 
     
    1082913        } 
    1083914 
    1084         return $this->_fetch_thread_headers($mailbox, clone $this->search_set, $page, $slice); 
     915        return $this->fetch_thread_headers($folder, clone $this->search_set, $page, $slice); 
    1085916    } 
    1086917 
     
    1089920     * Fetches messages headers (by UID) 
    1090921     * 
    1091      * @param  string  $mailbox  Mailbox name 
     922     * @param  string  $folder   Folder name 
    1092923     * @param  array   $msgs     Message UIDs 
    1093924     * @param  bool    $sort     Enables result sorting by $msgs 
     
    1095926     * 
    1096927     * @return array Messages headers indexed by UID 
    1097      * @access private 
    1098      */ 
    1099     function fetch_headers($mailbox, $msgs, $sort = true, $force = false) 
     928     */ 
     929    function fetch_headers($folder, $msgs, $sort = true, $force = false) 
    1100930    { 
    1101931        if (empty($msgs)) 
     
    1103933 
    1104934        if (!$force && ($mcache = $this->get_mcache_engine())) { 
    1105             $headers = $mcache->get_messages($mailbox, $msgs); 
     935            $headers = $mcache->get_messages($folder, $msgs); 
    1106936        } 
    1107937        else { 
    1108938            // fetch reqested headers from server 
    1109939            $headers = $this->conn->fetchHeaders( 
    1110                 $mailbox, $msgs, true, false, $this->get_fetch_headers()); 
     940                $folder, $msgs, true, false, $this->get_fetch_headers()); 
    1111941        } 
    1112942 
     
    1130960 
    1131961    /** 
    1132      * Returns current status of mailbox 
     962     * Returns current status of folder 
    1133963     * 
    1134964     * We compare the maximum UID to determine the number of 
    1135965     * new messages because the RECENT flag is not reliable. 
    1136966     * 
    1137      * @param string $mailbox Mailbox/folder name 
     967     * @param string $folder Folder name 
     968     * 
    1138969     * @return int   Folder status 
    1139970     */ 
    1140     public function mailbox_status($mailbox = null) 
    1141     { 
    1142         if (!strlen($mailbox)) { 
    1143             $mailbox = $this->mailbox; 
    1144         } 
    1145         $old = $this->get_folder_stats($mailbox); 
     971    public function folder_status($folder = null) 
     972    { 
     973        if (!strlen($folder)) { 
     974            $folder = $this->folder; 
     975        } 
     976        $old = $this->get_folder_stats($folder); 
    1146977 
    1147978        // refresh message count -> will update 
    1148         $this->_messagecount($mailbox, 'ALL', true); 
     979        $this->messagecount($folder, 'ALL', true); 
    1149980 
    1150981        $result = 0; 
     
    1154985        } 
    1155986 
    1156         $new = $this->get_folder_stats($mailbox); 
     987        $new = $this->get_folder_stats($folder); 
    1157988 
    1158989        // got new messages 
     
    11741005     * @TODO: move to separate DB table (cache?) 
    11751006     * 
    1176      * @param string $mailbox Mailbox name 
     1007     * @param string $folder  Folder name 
    11771008     * @param string $name    Data name 
    11781009     * @param mixed  $data    Data value 
    11791010     */ 
    1180     private function set_folder_stats($mailbox, $name, $data) 
    1181     { 
    1182         $_SESSION['folders'][$mailbox][$name] = $data; 
     1011    protected function set_folder_stats($folder, $name, $data) 
     1012    { 
     1013        $_SESSION['folders'][$folder][$name] = $data; 
    11831014    } 
    11841015 
     
    11871018     * Gets folder statistic data 
    11881019     * 
    1189      * @param string $mailbox Mailbox name 
     1020     * @param string $folder Folder name 
    11901021     * 
    11911022     * @return array Stats data 
    11921023     */ 
    1193     private function get_folder_stats($mailbox) 
    1194     { 
    1195         if ($_SESSION['folders'][$mailbox]) 
    1196             return (array) $_SESSION['folders'][$mailbox]; 
     1024    protected function get_folder_stats($folder) 
     1025    { 
     1026        if ($_SESSION['folders'][$folder]) 
     1027            return (array) $_SESSION['folders'][$folder]; 
    11971028        else 
    11981029            return array(); 
     
    12031034     * Return sorted list of message UIDs 
    12041035     * 
    1205      * @param string $mailbox    Mailbox to get index from 
     1036     * @param string $folder     Folder to get index from 
    12061037     * @param string $sort_field Sort column 
    12071038     * @param string $sort_order Sort order [ASC, DESC] 
     
    12091040     * @return rcube_result_index|rcube_result_thread List of messages (UIDs) 
    12101041     */ 
    1211     public function message_index($mailbox='', $sort_field=NULL, $sort_order=NULL) 
     1042    public function index($folder = '', $sort_field = NULL, $sort_order = NULL) 
    12121043    { 
    12131044        if ($this->threading) 
    1214             return $this->thread_index($mailbox, $sort_field, $sort_order); 
     1045            return $this->thread_index($folder, $sort_field, $sort_order); 
    12151046 
    12161047        $this->set_sort_order($sort_field, $sort_order); 
    12171048 
    1218         if (!strlen($mailbox)) { 
    1219             $mailbox = $this->mailbox; 
     1049        if (!strlen($folder)) { 
     1050            $folder = $this->folder; 
    12201051        } 
    12211052 
     
    12231054        if ($this->search_string) { 
    12241055            if ($this->search_threads) { 
    1225                 $this->search($mailbox, $this->search_string, $this->search_charset, $this->sort_field); 
     1056                $this->search($folder, $this->search_string, $this->search_charset, $this->sort_field); 
    12261057            } 
    12271058 
     
    12291060            if (!$this->sort_field || $this->search_sorted) { 
    12301061                if ($this->sort_field && $this->search_sort_field != $this->sort_field) { 
    1231                     $this->search($mailbox, $this->search_string, $this->search_charset, $this->sort_field); 
     1062                    $this->search($folder, $this->search_string, $this->search_charset, $this->sort_field); 
    12321063                } 
    12331064                $index = $this->search_set; 
    12341065            } 
    12351066            else { 
    1236                 $index = $this->conn->index($mailbox, $this->search_set->get(), 
    1237                     $this->sort_field, $this->skip_deleted, true, true); 
     1067                $index = $this->conn->index($folder, $this->search_set->get(), 
     1068                    $this->sort_field, $this->options['skip_deleted'], true, true); 
    12381069            } 
    12391070 
     
    12471078        // check local cache 
    12481079        if ($mcache = $this->get_mcache_engine()) { 
    1249             $index = $mcache->get_index($mailbox, $this->sort_field, $this->sort_order); 
     1080            $index = $mcache->get_index($folder, $this->sort_field, $this->sort_order); 
    12501081        } 
    12511082        // fetch from IMAP server 
    12521083        else { 
    1253             $index = $this->message_index_direct( 
    1254                 $mailbox, $this->sort_field, $this->sort_order); 
     1084            $index = $this->index_direct( 
     1085                $folder, $this->sort_field, $this->sort_order); 
    12551086        } 
    12561087 
     
    12631094     * Doesn't uses cache by default. 
    12641095     * 
    1265      * @param string $mailbox    Mailbox to get index from 
     1096     * @param string $folder     Folder to get index from 
    12661097     * @param string $sort_field Sort column 
    12671098     * @param string $sort_order Sort order [ASC, DESC] 
     
    12701101     * @return rcube_result_index Sorted list of message UIDs 
    12711102     */ 
    1272     public function message_index_direct($mailbox, $sort_field = null, $sort_order = null, $skip_cache = true) 
     1103    public function index_direct($folder, $sort_field = null, $sort_order = null, $skip_cache = true) 
    12731104    { 
    12741105        if (!$skip_cache && ($mcache = $this->get_mcache_engine())) { 
    1275             $index = $mcache->get_index($mailbox, $sort_field, $sort_order); 
     1106            $index = $mcache->get_index($folder, $sort_field, $sort_order); 
    12761107        } 
    12771108        // use message index sort as default sorting 
    12781109        else if (!$sort_field) { 
    1279             if ($this->skip_deleted && !empty($this->icache['undeleted_idx']) 
    1280                 && $this->icache['undeleted_idx']->getParameters('MAILBOX') == $mailbox 
     1110            if ($this->options['skip_deleted'] && !empty($this->icache['undeleted_idx']) 
     1111                && $this->icache['undeleted_idx']->getParameters('MAILBOX') == $folder 
    12811112            ) { 
    12821113                $index = $this->icache['undeleted_idx']; 
    12831114            } 
    12841115            else { 
    1285                 $index = $this->conn->search($mailbox, 
    1286                     'ALL' .($this->skip_deleted ? ' UNDELETED' : ''), true); 
     1116                $index = $this->conn->search($folder, 
     1117                    'ALL' .($this->options['skip_deleted'] ? ' UNDELETED' : ''), true); 
    12871118            } 
    12881119        } 
     
    12901121        else { 
    12911122            if ($this->get_capability('SORT')) { 
    1292                 $index = $this->conn->sort($mailbox, $sort_field, 
    1293                     $this->skip_deleted ? 'UNDELETED' : '', true); 
     1123                $index = $this->conn->sort($folder, $sort_field, 
     1124                    $this->options['skip_deleted'] ? 'UNDELETED' : '', true); 
    12941125            } 
    12951126 
    12961127            if (empty($index) || $index->isError()) { 
    1297                 $index = $this->conn->index($mailbox, "1:*", $sort_field, 
    1298                     $this->skip_deleted, false, true); 
     1128                $index = $this->conn->index($folder, "1:*", $sort_field, 
     1129                    $this->options['skip_deleted'], false, true); 
    12991130            } 
    13001131        } 
     
    13111142     * Return index of threaded message UIDs 
    13121143     * 
    1313      * @param string $mailbox    Mailbox to get index from 
     1144     * @param string $folder     Folder to get index from 
    13141145     * @param string $sort_field Sort column 
    13151146     * @param string $sort_order Sort order [ASC, DESC] 
     
    13171148     * @return rcube_result_thread Message UIDs 
    13181149     */ 
    1319     function thread_index($mailbox='', $sort_field=NULL, $sort_order=NULL) 
    1320     { 
    1321         if (!strlen($mailbox)) { 
    1322             $mailbox = $this->mailbox; 
     1150    public function thread_index($folder='', $sort_field=NULL, $sort_order=NULL) 
     1151    { 
     1152        if (!strlen($folder)) { 
     1153            $folder = $this->folder; 
    13231154        } 
    13241155 
    13251156        // we have a saved search result, get index from there 
    1326         if ($this->search_string && $this->search_threads && $mailbox == $this->mailbox) { 
     1157        if ($this->search_string && $this->search_threads && $folder == $this->folder) { 
    13271158            $threads = $this->search_set; 
    13281159        } 
    13291160        else { 
    13301161            // get all threads (default sort order) 
    1331             $threads = $this->fetch_threads($mailbox); 
     1162            $threads = $this->fetch_threads($folder); 
    13321163        } 
    13331164 
     
    13441175     * @param rcube_result_thread $threads  Threads result set 
    13451176     */ 
    1346     private function sort_threads($threads) 
     1177    protected function sort_threads($threads) 
    13471178    { 
    13481179        if ($threads->isEmpty()) { 
     
    13551186 
    13561187        if ($this->sort_field && ($this->sort_field != 'date' || $this->get_capability('THREAD') != 'REFS')) { 
    1357             $index = $this->message_index_direct($this->mailbox, $this->sort_field, $this->sort_order, false); 
     1188            $index = $this->index_direct($this->folder, $this->sort_field, $this->sort_order, false); 
    13581189 
    13591190            if (!$index->isEmpty()) { 
     
    13721203     * Invoke search request to IMAP server 
    13731204     * 
    1374      * @param  string  $mailbox    Mailbox name to search in 
     1205     * @param  string  $folder     Folder name to search in 
    13751206     * @param  string  $str        Search criteria 
    13761207     * @param  string  $charset    Search charset 
    13771208     * @param  string  $sort_field Header field to sort by 
    1378      * @access public 
     1209     * 
    13791210     * @todo: Search criteria should be provided in non-IMAP format, eg. array 
    13801211     */ 
    1381     function search($mailbox='', $str='ALL', $charset=NULL, $sort_field=NULL) 
    1382     { 
    1383         if (!$str) 
     1212    public function search($folder='', $str='ALL', $charset=NULL, $sort_field=NULL) 
     1213    { 
     1214        if (!$str) { 
    13841215            $str = 'ALL'; 
     1216        } 
     1217 
     1218        if (!strlen($folder)) { 
     1219            $folder = $this->folder; 
     1220        } 
     1221 
     1222        $results = $this->search_index($folder, $str, $charset, $sort_field); 
     1223 
     1224        $this->set_search_set(array($str, $results, $charset, $sort_field, 
     1225            $this->threading || $this->search_sorted ? true : false)); 
     1226    } 
     1227 
     1228 
     1229    /** 
     1230     * Direct (real and simple) SEARCH request (without result sorting and caching). 
     1231     * 
     1232     * @param  string  $mailbox Mailbox name to search in 
     1233     * @param  string  $str     Search string 
     1234     * 
     1235     * @return rcube_result_index  Search result (UIDs) 
     1236     */ 
     1237    public function search_once($mailbox = null, $str = 'ALL') 
     1238    { 
     1239        if (!$str) { 
     1240            return 'ALL'; 
     1241        } 
    13851242 
    13861243        if (!strlen($mailbox)) { 
     
    13881245        } 
    13891246 
    1390         $results = $this->_search_index($mailbox, $str, $charset, $sort_field); 
    1391  
    1392         $this->set_search_set(array($str, $results, $charset, $sort_field, 
    1393             $this->threading || $this->search_sorted ? true : false)); 
    1394     } 
    1395  
    1396  
    1397     /** 
    1398      * Private search method 
    1399      * 
    1400      * @param string $mailbox    Mailbox name 
     1247        $index = $this->conn->search($mailbox, $str, true); 
     1248 
     1249        return $index; 
     1250    } 
     1251 
     1252 
     1253    /** 
     1254     * protected search method 
     1255     * 
     1256     * @param string $folder     Folder name 
    14011257     * @param string $criteria   Search criteria 
    14021258     * @param string $charset    Charset 
     
    14061262     * @see rcube_imap::search() 
    14071263     */ 
    1408     private function _search_index($mailbox, $criteria='ALL', $charset=NULL, $sort_field=NULL) 
     1264    protected function search_index($folder, $criteria='ALL', $charset=NULL, $sort_field=NULL) 
    14091265    { 
    14101266        $orig_criteria = $criteria; 
    14111267 
    1412         if ($this->skip_deleted && !preg_match('/UNDELETED/', $criteria)) 
     1268        if ($this->options['skip_deleted'] && !preg_match('/UNDELETED/', $criteria)) 
    14131269            $criteria = 'UNDELETED '.$criteria; 
    14141270 
    14151271        if ($this->threading) { 
    1416             $threads = $this->conn->thread($mailbox, $this->threading, $criteria, true, $charset); 
     1272            $threads = $this->conn->thread($folder, $this->threading, $criteria, true, $charset); 
    14171273 
    14181274            // Error, try with US-ASCII (RFC5256: SORT/THREAD must support US-ASCII and UTF-8, 
    14191275            // but I've seen that Courier doesn't support UTF-8) 
    14201276            if ($threads->isError() && $charset && $charset != 'US-ASCII') 
    1421                 $threads = $this->conn->thread($mailbox, $this->threading, 
     1277                $threads = $this->conn->thread($folder, $this->threading, 
    14221278                    $this->convert_criteria($criteria, $charset), true, 'US-ASCII'); 
    14231279 
     
    14271283        if ($sort_field && $this->get_capability('SORT')) { 
    14281284            $charset  = $charset ? $charset : $this->default_charset; 
    1429             $messages = $this->conn->sort($mailbox, $sort_field, $criteria, true, $charset); 
     1285            $messages = $this->conn->sort($folder, $sort_field, $criteria, true, $charset); 
    14301286 
    14311287            // Error, try with US-ASCII (RFC5256: SORT/THREAD must support US-ASCII and UTF-8, 
    14321288            // but I've seen Courier with disabled UTF-8 support) 
    14331289            if ($messages->isError() && $charset && $charset != 'US-ASCII') 
    1434                 $messages = $this->conn->sort($mailbox, $sort_field, 
     1290                $messages = $this->conn->sort($folder, $sort_field, 
    14351291                    $this->convert_criteria($criteria, $charset), true, 'US-ASCII'); 
    14361292 
     
    14411297        } 
    14421298 
    1443         $messages = $this->conn->search($mailbox, 
     1299        $messages = $this->conn->search($folder, 
    14441300            ($charset ? "CHARSET $charset " : '') . $criteria, true); 
    14451301 
    14461302        // Error, try with US-ASCII (some servers may support only US-ASCII) 
    14471303        if ($messages->isError() && $charset && $charset != 'US-ASCII') 
    1448             $messages = $this->conn->search($mailbox, 
     1304            $messages = $this->conn->search($folder, 
    14491305                $this->convert_criteria($criteria, $charset), true); 
    14501306 
     
    14521308 
    14531309        return $messages; 
    1454     } 
    1455  
    1456  
    1457     /** 
    1458      * Direct (real and simple) SEARCH request to IMAP server, 
    1459      * without result sorting and caching 
    1460      * 
    1461      * @param  string  $mailbox Mailbox name to search in 
    1462      * @param  string  $str     Search string 
    1463      * @param  boolean $ret_uid True if UIDs should be returned 
    1464      * 
    1465      * @return rcube_result_index  Search result (UIDs) 
    1466      */ 
    1467     function search_once($mailbox='', $str='ALL') 
    1468     { 
    1469         if (!$str) 
    1470             return 'ALL'; 
    1471  
    1472         if (!strlen($mailbox)) { 
    1473             $mailbox = $this->mailbox; 
    1474         } 
    1475  
    1476         $index = $this->conn->search($mailbox, $str, true); 
    1477  
    1478         return $index; 
    14791310    } 
    14801311 
     
    14861317     * @param  string  $charset      Original charset 
    14871318     * @param  string  $dest_charset Destination charset (default US-ASCII) 
     1319     * 
    14881320     * @return string  Search string 
    1489      * @access private 
    1490      */ 
    1491     private function convert_criteria($str, $charset, $dest_charset='US-ASCII') 
     1321     */ 
     1322    protected function convert_criteria($str, $charset, $dest_charset='US-ASCII') 
    14921323    { 
    14931324        // convert strings to US_ASCII 
     
    15181349     * @return array Current search set 
    15191350     */ 
    1520     function refresh_search() 
     1351    public function refresh_search() 
    15211352    { 
    15221353        if (!empty($this->search_string)) { 
     
    15311362     * Return message headers object of a specific message 
    15321363     * 
    1533      * @param int     $id       Message sequence ID or UID 
    1534      * @param string  $mailbox  Mailbox to read from 
     1364     * @param int     $id       Message UID 
     1365     * @param string  $folder   Folder to read from 
    15351366     * @param bool    $force    True to skip cache 
    15361367     * 
    15371368     * @return rcube_mail_header Message headers 
    15381369     */ 
    1539     function get_headers($uid, $mailbox = null, $force = false) 
    1540     { 
    1541         if (!strlen($mailbox)) { 
    1542             $mailbox = $this->mailbox; 
     1370    public function get_message_headers($uid, $folder = null, $force = false) 
     1371    { 
     1372        if (!strlen($folder)) { 
     1373            $folder = $this->folder; 
    15431374        } 
    15441375 
    15451376        // get cached headers 
    15461377        if (!$force && $uid && ($mcache = $this->get_mcache_engine())) { 
    1547             $headers = $mcache->get_message($mailbox, $uid); 
     1378            $headers = $mcache->get_message($folder, $uid); 
    15481379        } 
    15491380        else { 
    15501381            $headers = $this->conn->fetchHeader( 
    1551                 $mailbox, $uid, true, true, $this->get_fetch_headers()); 
     1382                $folder, $uid, true, true, $this->get_fetch_headers()); 
    15521383        } 
    15531384 
     
    15611392     * 
    15621393     * @param int     $uid      Message UID to fetch 
    1563      * @param string  $mailbox  Mailbox to read from 
     1394     * @param string  $folder   Folder to read from 
    15641395     * 
    15651396     * @return object rcube_mail_header Message data 
    15661397     */ 
    1567     function get_message($uid, $mailbox = null) 
    1568     { 
    1569         if (!strlen($mailbox)) { 
    1570             $mailbox = $this->mailbox; 
     1398    public function get_message($uid, $folder = null) 
     1399    { 
     1400        if (!strlen($folder)) { 
     1401            $folder = $this->folder; 
    15711402        } 
    15721403 
     
    15781409        } 
    15791410 
    1580         $headers = $this->get_headers($uid, $mailbox); 
     1411        $headers = $this->get_message_headers($uid, $folder); 
    15811412 
    15821413        // message doesn't exist? 
     
    15881419            return $headers; 
    15891420 
    1590         $this->_msg_uid = $uid; 
     1421        $this->msg_uid = $uid; 
    15911422 
    15921423        if (empty($headers->bodystructure)) { 
    1593             $headers->bodystructure = $this->conn->getStructure($mailbox, $uid, true); 
     1424            $headers->bodystructure = $this->conn->getStructure($folder, $uid, true); 
    15941425        } 
    15951426 
     
    16031434            $this->struct_charset = $headers->charset; 
    16041435        else 
    1605             $this->struct_charset = $this->_structure_charset($structure); 
     1436            $this->struct_charset = $this->structure_charset($structure); 
    16061437 
    16071438        $headers->ctype = strtolower($headers->ctype); 
     
    16231454        } 
    16241455 
    1625         $struct = $this->_structure_part($structure, 0, '', $headers); 
     1456        $struct = $this->structure_part($structure, 0, '', $headers); 
    16261457 
    16271458        // don't trust given content-type 
     
    16441475     * @param int    $count 
    16451476     * @param string $parent 
    1646      * @access private 
    1647      */ 
    1648     private function _structure_part($part, $count=0, $parent='', $mime_headers=null) 
     1477     */ 
     1478    protected function structure_part($part, $count=0, $parent='', $mime_headers=null) 
    16491479    { 
    16501480        $struct = new rcube_message_part; 
     
    16981528            // headers for parts on all levels 
    16991529            if ($mime_part_headers) { 
    1700                 $mime_part_headers = $this->conn->fetchMIMEHeaders($this->mailbox, 
    1701                     $this->_msg_uid, $mime_part_headers); 
     1530                $mime_part_headers = $this->conn->fetchMIMEHeaders($this->folder, 
     1531                    $this->msg_uid, $mime_part_headers); 
    17021532            } 
    17031533 
     
    17071537                    break; 
    17081538                $tmp_part_id = $struct->mime_id ? $struct->mime_id.'.'.($i+1) : $i+1; 
    1709                 $struct->parts[] = $this->_structure_part($part[$i], ++$count, $struct->mime_id, 
     1539                $struct->parts[] = $this->structure_part($part[$i], ++$count, $struct->mime_id, 
    17101540                    $mime_part_headers[$tmp_part_id]); 
    17111541            } 
     
    17841614                if (!is_array($part[8][$i])) 
    17851615                    break; 
    1786                 $struct->parts[] = $this->_structure_part($part[8][$i], ++$count, $struct->mime_id); 
     1616                $struct->parts[] = $this->structure_part($part[8][$i], ++$count, $struct->mime_id); 
    17871617            } 
    17881618        } 
     
    18011631            if (empty($mime_headers)) { 
    18021632                $mime_headers = $this->conn->fetchPartHeader( 
    1803                     $this->mailbox, $this->_msg_uid, true, $struct->mime_id); 
     1633                    $this->folder, $this->msg_uid, true, $struct->mime_id); 
    18041634            } 
    18051635 
     
    18251655            if ($struct->ctype_primary == 'message' && empty($struct->parts)) { 
    18261656                if (is_array($part[8]) && $di != 8) 
    1827                     $struct->parts[] = $this->_structure_part($part[8], ++$count, $struct->mime_id); 
     1657                    $struct->parts[] = $this->structure_part($part[8], ++$count, $struct->mime_id); 
    18281658            } 
    18291659        } 
    18301660 
    18311661        // normalize filename property 
    1832         $this->_set_part_filename($struct, $mime_headers); 
     1662        $this->set_part_filename($struct, $mime_headers); 
    18331663 
    18341664        return $struct; 
     
    18411671     * @param  rcube_message_part $part    Part object 
    18421672     * @param  string             $headers Part's raw headers 
    1843      * @access private 
    1844      */ 
    1845     private function _set_part_filename(&$part, $headers=null) 
     1673     */ 
     1674    protected function set_part_filename(&$part, $headers=null) 
    18461675    { 
    18471676        if (!empty($part->d_parameters['filename'])) 
     
    18641693                if (!$headers) { 
    18651694                    $headers = $this->conn->fetchPartHeader( 
    1866                         $this->mailbox, $this->_msg_uid, true, $part->mime_id); 
     1695                        $this->folder, $this->msg_uid, true, $part->mime_id); 
    18671696                } 
    18681697                $filename_mime = ''; 
     
    18831712                if (!$headers) { 
    18841713                    $headers = $this->conn->fetchPartHeader( 
    1885                             $this->mailbox, $this->_msg_uid, true, $part->mime_id); 
     1714                            $this->folder, $this->msg_uid, true, $part->mime_id); 
    18861715                } 
    18871716                $filename_encoded = ''; 
     
    19021731                if (!$headers) { 
    19031732                    $headers = $this->conn->fetchPartHeader( 
    1904                         $this->mailbox, $this->_msg_uid, true, $part->mime_id); 
     1733                        $this->folder, $this->msg_uid, true, $part->mime_id); 
    19051734                } 
    19061735                $filename_mime = ''; 
     
    19211750                if (!$headers) { 
    19221751                    $headers = $this->conn->fetchPartHeader( 
    1923                         $this->mailbox, $this->_msg_uid, true, $part->mime_id); 
     1752                        $this->folder, $this->msg_uid, true, $part->mime_id); 
    19241753                } 
    19251754                $filename_encoded = ''; 
     
    19671796     * 
    19681797     * @param  array $structure Message structure 
     1798     * 
    19691799     * @return string Charset name 
    1970      * @access private 
    1971      */ 
    1972     private function _structure_charset($structure) 
     1800     */ 
     1801    protected function structure_charset($structure) 
    19731802    { 
    19741803        while (is_array($structure)) { 
     
    19921821     * @return string Message/part body if not printed 
    19931822     */ 
    1994     function get_message_part($uid, $part=1, $o_part=NULL, $print=NULL, $fp=NULL, $skip_charset_conv=false) 
     1823    public function get_message_part($uid, $part=1, $o_part=NULL, $print=NULL, $fp=NULL, $skip_charset_conv=false) 
    19951824    { 
    19961825        // get part data if not provided 
    19971826        if (!is_object($o_part)) { 
    1998             $structure = $this->conn->getStructure($this->mailbox, $uid, true); 
     1827            $structure = $this->conn->getStructure($this->folder, $uid, true); 
    19991828            $part_data = rcube_imap_generic::getStructurePartData($structure, $part); 
    20001829 
     
    20071836 
    20081837        if ($o_part && $o_part->size) { 
    2009             $body = $this->conn->handlePartBody($this->mailbox, $uid, true, 
     1838            $body = $this->conn->handlePartBody($this->folder, $uid, true, 
    20101839                $part ? $part : 'TEXT', $o_part->encoding, $print, $fp); 
    20111840        } 
     
    20391868 
    20401869    /** 
    2041      * Fetch message body of a specific message from the server 
    2042      * 
    2043      * @param  int    $uid  Message UID 
    2044      * @return string $part Message/part body 
    2045      * @see    rcube_imap::get_message_part() 
    2046      */ 
    2047     function get_body($uid, $part=1) 
    2048     { 
    2049         $headers = $this->get_headers($uid); 
    2050         return rcube_charset_convert($this->get_message_part($uid, $part, NULL), 
    2051             $headers->charset ? $headers->charset : $this->default_charset); 
    2052     } 
    2053  
    2054  
    2055     /** 
    20561870     * Returns the whole message source as string (or saves to a file) 
    20571871     * 
     
    20611875     * @return string Message source string 
    20621876     */ 
    2063     function get_raw_body($uid, $fp=null) 
    2064     { 
    2065         return $this->conn->handlePartBody($this->mailbox, $uid, 
     1877    public function get_raw_body($uid, $fp=null) 
     1878    { 
     1879        return $this->conn->handlePartBody($this->folder, $uid, 
    20661880            true, null, null, false, $fp); 
    20671881    } 
     
    20721886     * 
    20731887     * @param int $uid  Message UID 
     1888     * 
    20741889     * @return string Message headers string 
    20751890     */ 
    2076     function get_raw_headers($uid) 
    2077     { 
    2078         return $this->conn->fetchPartHeader($this->mailbox, $uid, true); 
     1891    public function get_raw_headers($uid) 
     1892    { 
     1893        return $this->conn->fetchPartHeader($this->folder, $uid, true); 
    20791894    } 
    20801895 
     
    20851900     * @param int $uid Message UID 
    20861901     */ 
    2087     function print_raw_body($uid) 
    2088     { 
    2089         $this->conn->handlePartBody($this->mailbox, $uid, true, NULL, NULL, true); 
     1902    public function print_raw_body($uid) 
     1903    { 
     1904        $this->conn->handlePartBody($this->folder, $uid, true, NULL, NULL, true); 
    20901905    } 
    20911906 
     
    20961911     * @param mixed   $uids       Message UIDs as array or comma-separated string, or '*' 
    20971912     * @param string  $flag       Flag to set: SEEN, UNDELETED, DELETED, RECENT, ANSWERED, DRAFT, MDNSENT 
    2098      * @param string  $mailbox    Folder name 
     1913     * @param string  $folder    Folder name 
    20991914     * @param boolean $skip_cache True to skip message cache clean up 
    21001915     * 
    21011916     * @return boolean  Operation status 
    21021917     */ 
    2103     function set_flag($uids, $flag, $mailbox=null, $skip_cache=false) 
    2104     { 
    2105         if (!strlen($mailbox)) { 
    2106             $mailbox = $this->mailbox; 
     1918    public function set_flag($uids, $flag, $folder=null, $skip_cache=false) 
     1919    { 
     1920        if (!strlen($folder)) { 
     1921            $folder = $this->folder; 
    21071922        } 
    21081923 
    21091924        $flag = strtoupper($flag); 
    2110         list($uids, $all_mode) = $this->_parse_uids($uids, $mailbox); 
     1925        list($uids, $all_mode) = $this->parse_uids($uids); 
    21111926 
    21121927        if (strpos($flag, 'UN') === 0) 
    2113             $result = $this->conn->unflag($mailbox, $uids, substr($flag, 2)); 
     1928            $result = $this->conn->unflag($folder, $uids, substr($flag, 2)); 
    21141929        else 
    2115             $result = $this->conn->flag($mailbox, $uids, $flag); 
     1930            $result = $this->conn->flag($folder, $uids, $flag); 
    21161931 
    21171932        if ($result) { 
     
    21211936                $status = strpos($flag, 'UN') !== 0; 
    21221937                $mflag  = preg_replace('/^UN/', '', $flag); 
    2123                 $mcache->change_flag($mailbox, $all_mode ? null : explode(',', $uids), 
     1938                $mcache->change_flag($folder, $all_mode ? null : explode(',', $uids), 
    21241939                    $mflag, $status); 
    21251940            } 
     
    21271942            // clear cached counters 
    21281943            if ($flag == 'SEEN' || $flag == 'UNSEEN') { 
    2129                 $this->_clear_messagecount($mailbox, 'SEEN'); 
    2130                 $this->_clear_messagecount($mailbox, 'UNSEEN'); 
     1944                $this->clear_messagecount($folder, 'SEEN'); 
     1945                $this->clear_messagecount($folder, 'UNSEEN'); 
    21311946            } 
    21321947            else if ($flag == 'DELETED') { 
    2133                 $this->_clear_messagecount($mailbox, 'DELETED'); 
     1948                $this->clear_messagecount($folder, 'DELETED'); 
    21341949            } 
    21351950        } 
     
    21401955 
    21411956    /** 
    2142      * Remove message flag for one or several messages 
    2143      * 
    2144      * @param mixed  $uids    Message UIDs as array or comma-separated string, or '*' 
    2145      * @param string $flag    Flag to unset: SEEN, DELETED, RECENT, ANSWERED, DRAFT, MDNSENT 
    2146      * @param string $mailbox Folder name 
    2147      * 
    2148      * @return int   Number of flagged messages, -1 on failure 
    2149      * @see set_flag 
    2150      */ 
    2151     function unset_flag($uids, $flag, $mailbox=null) 
    2152     { 
    2153         return $this->set_flag($uids, 'UN'.$flag, $mailbox); 
    2154     } 
    2155  
    2156  
    2157     /** 
    2158      * Append a mail message (source) to a specific mailbox 
    2159      * 
    2160      * @param string  $mailbox Target mailbox 
     1957     * Append a mail message (source) to a specific folder 
     1958     * 
     1959     * @param string  $folder  Target folder 
    21611960     * @param string  $message The message source string or filename 
    21621961     * @param string  $headers Headers string if $message contains only the body 
     
    21651964     * @return int|bool Appended message UID or True on success, False on error 
    21661965     */ 
    2167     function save_message($mailbox, &$message, $headers='', $is_file=false) 
    2168     { 
    2169         if (!strlen($mailbox)) { 
    2170             $mailbox = $this->mailbox; 
    2171         } 
    2172  
    2173         // make sure mailbox exists 
    2174         if ($this->mailbox_exists($mailbox)) { 
     1966    public function save_message($folder, &$message, $headers='', $is_file=false) 
     1967    { 
     1968        if (!strlen($folder)) { 
     1969            $folder = $this->folder; 
     1970        } 
     1971 
     1972        // make sure folder exists 
     1973        if ($this->folder_exists($folder)) { 
    21751974            if ($is_file) 
    2176                 $saved = $this->conn->appendFromFile($mailbox, $message, $headers); 
     1975                $saved = $this->conn->appendFromFile($folder, $message, $headers); 
    21771976            else 
    2178                 $saved = $this->conn->append($mailbox, $message); 
     1977                $saved = $this->conn->append($folder, $message); 
    21791978        } 
    21801979 
    21811980        if ($saved) { 
    2182             // increase messagecount of the target mailbox 
    2183             $this->_set_messagecount($mailbox, 'ALL', 1); 
     1981            // increase messagecount of the target folder 
     1982            $this->set_messagecount($folder, 'ALL', 1); 
    21841983        } 
    21851984 
     
    21891988 
    21901989    /** 
    2191      * Move a message from one mailbox to another 
     1990     * Move a message from one folder to another 
    21921991     * 
    21931992     * @param mixed  $uids      Message UIDs as array or comma-separated string, or '*' 
    2194      * @param string $to_mbox   Target mailbox 
    2195      * @param string $from_mbox Source mailbox 
     1993     * @param string $to_mbox   Target folder 
     1994     * @param string $from_mbox Source folder 
     1995     * 
    21961996     * @return boolean True on success, False on error 
    21971997     */ 
    2198     function move_message($uids, $to_mbox, $from_mbox='') 
     1998    public function move_message($uids, $to_mbox, $from_mbox='') 
    21991999    { 
    22002000        if (!strlen($from_mbox)) { 
    2201             $from_mbox = $this->mailbox; 
     2001            $from_mbox = $this->folder; 
    22022002        } 
    22032003 
     
    22062006        } 
    22072007 
    2208         list($uids, $all_mode) = $this->_parse_uids($uids, $from_mbox); 
     2008        list($uids, $all_mode) = $this->parse_uids($uids); 
    22092009 
    22102010        // exit if no message uids are specified 
     
    22122012            return false; 
    22132013 
    2214         // make sure mailbox exists 
    2215         if ($to_mbox != 'INBOX' && !$this->mailbox_exists($to_mbox)) { 
     2014        // make sure folder exists 
     2015        if ($to_mbox != 'INBOX' && !$this->folder_exists($to_mbox)) { 
    22162016            if (in_array($to_mbox, $this->default_folders)) { 
    2217                 if (!$this->create_mailbox($to_mbox, true)) { 
     2017                if (!$this->create_folder($to_mbox, true)) { 
    22182018                    return false; 
    22192019                } 
     
    22372037 
    22382038        // send expunge command in order to have the moved message 
    2239         // really deleted from the source mailbox 
     2039        // really deleted from the source folder 
    22402040        if ($moved) { 
    2241             $this->_expunge($from_mbox, false, $uids); 
    2242             $this->_clear_messagecount($from_mbox); 
    2243             $this->_clear_messagecount($to_mbox); 
     2041            $this->expunge_message($uids, $from_mbox, false); 
     2042            $this->clear_messagecount($from_mbox); 
     2043            $this->clear_messagecount($to_mbox); 
    22442044        } 
    22452045        // moving failed 
     
    22532053 
    22542054            // remove message ids from search set 
    2255             if ($this->search_set && $from_mbox == $this->mailbox) { 
     2055            if ($this->search_set && $from_mbox == $this->folder) { 
    22562056                // threads are too complicated to just remove messages from set 
    22572057                if ($this->search_threads || $all_mode) 
     
    22712071 
    22722072    /** 
    2273      * Copy a message from one mailbox to another 
     2073     * Copy a message from one folder to another 
    22742074     * 
    22752075     * @param mixed  $uids      Message UIDs as array or comma-separated string, or '*' 
    2276      * @param string $to_mbox   Target mailbox 
    2277      * @param string $from_mbox Source mailbox 
     2076     * @param string $to_mbox   Target folder 
     2077     * @param string $from_mbox Source folder 
     2078     * 
    22782079     * @return boolean True on success, False on error 
    22792080     */ 
    2280     function copy_message($uids, $to_mbox, $from_mbox='') 
     2081    public function copy_message($uids, $to_mbox, $from_mbox='') 
    22812082    { 
    22822083        if (!strlen($from_mbox)) { 
    2283             $from_mbox = $this->mailbox; 
    2284         } 
    2285  
    2286         list($uids, $all_mode) = $this->_parse_uids($uids, $from_mbox); 
     2084            $from_mbox = $this->folder; 
     2085        } 
     2086 
     2087        list($uids, $all_mode) = $this->parse_uids($uids); 
    22872088 
    22882089        // exit if no message uids are specified 
     
    22912092        } 
    22922093 
    2293         // make sure mailbox exists 
    2294         if ($to_mbox != 'INBOX' && !$this->mailbox_exists($to_mbox)) { 
     2094        // make sure folder exists 
     2095        if ($to_mbox != 'INBOX' && !$this->folder_exists($to_mbox)) { 
    22952096            if (in_array($to_mbox, $this->default_folders)) { 
    2296                 if (!$this->create_mailbox($to_mbox, true)) { 
     2097                if (!$this->create_folder($to_mbox, true)) { 
    22972098                    return false; 
    22982099                } 
     
    23072108 
    23082109        if ($copied) { 
    2309             $this->_clear_messagecount($to_mbox); 
     2110            $this->clear_messagecount($to_mbox); 
    23102111        } 
    23112112 
     
    23152116 
    23162117    /** 
    2317      * Mark messages as deleted and expunge mailbox 
     2118     * Mark messages as deleted and expunge them 
    23182119     * 
    23192120     * @param mixed  $uids    Message UIDs as array or comma-separated string, or '*' 
    2320      * @param string $mailbox Source mailbox 
     2121     * @param string $folder  Source folder 
    23212122     * 
    23222123     * @return boolean True on success, False on error 
    23232124     */ 
    2324     function delete_message($uids, $mailbox='') 
    2325     { 
    2326         if (!strlen($mailbox)) { 
    2327             $mailbox = $this->mailbox; 
    2328         } 
    2329  
    2330         list($uids, $all_mode) = $this->_parse_uids($uids, $mailbox); 
     2125    public function delete_message($uids, $folder='') 
     2126    { 
     2127        if (!strlen($folder)) { 
     2128            $folder = $this->folder; 
     2129        } 
     2130 
     2131        list($uids, $all_mode) = $this->parse_uids($uids); 
    23312132 
    23322133        // exit if no message uids are specified 
     
    23342135            return false; 
    23352136 
    2336         $deleted = $this->conn->flag($mailbox, $uids, 'DELETED'); 
     2137        $deleted = $this->conn->flag($folder, $uids, 'DELETED'); 
    23372138 
    23382139        if ($deleted) { 
    23392140            // send expunge command in order to have the deleted message 
    2340             // really deleted from the mailbox 
    2341             $this->_expunge($mailbox, false, $uids); 
    2342             $this->_clear_messagecount($mailbox); 
    2343             unset($this->uid_id_map[$mailbox]); 
     2141            // really deleted from the folder 
     2142            $this->expunge_message($uids, $folder, false); 
     2143            $this->clear_messagecount($folder); 
     2144            unset($this->uid_id_map[$folder]); 
    23442145 
    23452146            // unset threads internal cache 
     
    23472148 
    23482149            // remove message ids from search set 
    2349             if ($this->search_set && $mailbox == $this->mailbox) { 
     2150            if ($this->search_set && $folder == $this->folder) { 
    23502151                // threads are too complicated to just remove messages from set 
    23512152                if ($this->search_threads || $all_mode) 
     
    23562157 
    23572158            // remove cached messages 
    2358             $this->clear_message_cache($mailbox, $all_mode ? null : explode(',', $uids)); 
     2159            $this->clear_message_cache($folder, $all_mode ? null : explode(',', $uids)); 
    23592160        } 
    23602161 
     
    23642165 
    23652166    /** 
    2366      * Clear all messages in a specific mailbox 
    2367      * 
    2368      * @param string $mailbox Mailbox name 
    2369      * 
    2370      * @return int Above 0 on success 
    2371      */ 
    2372     function clear_mailbox($mailbox=null) 
    2373     { 
    2374         if (!strlen($mailbox)) { 
    2375             $mailbox = $this->mailbox; 
    2376         } 
    2377  
    2378         // SELECT will set messages count for clearFolder() 
    2379         if ($this->conn->select($mailbox)) { 
    2380             $cleared = $this->conn->clearFolder($mailbox); 
    2381         } 
    2382  
    2383         // make sure the cache is cleared as well 
    2384         if ($cleared) { 
    2385             $this->clear_message_cache($mailbox); 
    2386             $a_mailbox_cache = $this->get_cache('messagecount'); 
    2387             unset($a_mailbox_cache[$mailbox]); 
    2388             $this->update_cache('messagecount', $a_mailbox_cache); 
    2389         } 
    2390  
    2391         return $cleared; 
    2392     } 
    2393  
    2394  
    2395     /** 
    23962167     * Send IMAP expunge command and clear cache 
    23972168     * 
    2398      * @param string  $mailbox     Mailbox name 
     2169     * @param mixed   $uids        Message UIDs as array or comma-separated string, or '*' 
     2170     * @param string  $folder      Folder name 
    23992171     * @param boolean $clear_cache False if cache should not be cleared 
    24002172     * 
    2401      * @return boolean True on success 
    2402      */ 
    2403     function expunge($mailbox='', $clear_cache=true) 
    2404     { 
    2405         if (!strlen($mailbox)) { 
    2406             $mailbox = $this->mailbox; 
    2407         } 
    2408  
    2409         return $this->_expunge($mailbox, $clear_cache); 
    2410     } 
    2411  
    2412  
    2413     /** 
    2414      * Send IMAP expunge command and clear cache 
    2415      * 
    2416      * @param string  $mailbox     Mailbox name 
    2417      * @param boolean $clear_cache False if cache should not be cleared 
    2418      * @param mixed   $uids        Message UIDs as array or comma-separated string, or '*' 
    2419      * @return boolean True on success 
    2420      * @access private 
    2421      * @see rcube_imap::expunge() 
    2422      */ 
    2423     private function _expunge($mailbox, $clear_cache=true, $uids=NULL) 
     2173     * @return boolean True on success, False on failure 
     2174     */ 
     2175    public function expunge_message($uids, $folder = null, $clear_cache = true) 
    24242176    { 
    24252177        if ($uids && $this->get_capability('UIDPLUS')) 
    2426             list($uids, $all_mode) = $this->_parse_uids($uids, $mailbox); 
     2178            list($uids, $all_mode) = $this->parse_uids($uids); 
    24272179        else 
    24282180            $uids = null; 
    24292181 
    2430         // force mailbox selection and check if mailbox is writeable 
     2182        if (!strlen($folder)) { 
     2183            $folder = $this->folder; 
     2184        } 
     2185 
     2186        // force folder selection and check if folder is writeable 
    24312187        // to prevent a situation when CLOSE is executed on closed 
    2432         // or EXPUNGE on read-only mailbox 
    2433         $result = $this->conn->select($mailbox); 
     2188        // or EXPUNGE on read-only folder 
     2189        $result = $this->conn->select($folder); 
    24342190        if (!$result) { 
    24352191            return false; 
    24362192        } 
    24372193        if (!$this->conn->data['READ-WRITE']) { 
    2438             $this->conn->setError(rcube_imap_generic::ERROR_READONLY, "Mailbox is read-only"); 
     2194            $this->conn->setError(rcube_imap_generic::ERROR_READONLY, "Folder is read-only"); 
    24392195            return false; 
    24402196        } 
     
    24442200            $result = $this->conn->close(); 
    24452201        else 
    2446             $result = $this->conn->expunge($mailbox, $uids); 
     2202            $result = $this->conn->expunge($folder, $uids); 
    24472203 
    24482204        if ($result && $clear_cache) { 
    2449             $this->clear_message_cache($mailbox, $all_mode ? null : explode(',', $uids)); 
    2450             $this->_clear_messagecount($mailbox); 
     2205            $this->clear_message_cache($folder, $all_mode ? null : explode(',', $uids)); 
     2206            $this->clear_messagecount($folder); 
    24512207        } 
    24522208 
    24532209        return $result; 
    2454     } 
    2455  
    2456  
    2457     /** 
    2458      * Parse message UIDs input 
    2459      * 
    2460      * @param mixed  $uids    UIDs array or comma-separated list or '*' or '1:*' 
    2461      * @param string $mailbox Mailbox name 
    2462      * @return array Two elements array with UIDs converted to list and ALL flag 
    2463      * @access private 
    2464      */ 
    2465     private function _parse_uids($uids, $mailbox) 
    2466     { 
    2467         if ($uids === '*' || $uids === '1:*') { 
    2468             if (empty($this->search_set)) { 
    2469                 $uids = '1:*'; 
    2470                 $all = true; 
    2471             } 
    2472             // get UIDs from current search set 
    2473             else { 
    2474                 $uids = join(',', $this->search_set->get()); 
    2475             } 
    2476         } 
    2477         else { 
    2478             if (is_array($uids)) 
    2479                 $uids = join(',', $uids); 
    2480  
    2481             if (preg_match('/[^0-9,]/', $uids)) 
    2482                 $uids = ''; 
    2483         } 
    2484  
    2485         return array($uids, (bool) $all); 
    24862210    } 
    24872211 
     
    24922216 
    24932217    /** 
    2494      * Public method for listing subscribed folders 
     2218     * Public method for listing subscribed folders. 
    24952219     * 
    24962220     * @param   string  $root      Optional root folder 
     
    25012225     * 
    25022226     * @return  array   List of folders 
    2503      * @access  public 
    2504      */ 
    2505     function list_mailboxes($root='', $name='*', $filter=null, $rights=null, $skip_sort=false) 
     2227     */ 
     2228    public function list_folders_subscribed($root='', $name='*', $filter=null, $rights=null, $skip_sort=false) 
    25062229    { 
    25072230        $cache_key = $root.':'.$name; 
     
    25182241        } 
    25192242 
    2520         $a_mboxes = $this->_list_mailboxes($root, $name, $filter, $rights); 
     2243        $a_mboxes = $this->_list_folders_subscribed($root, $name, $filter, $rights); 
    25212244 
    25222245        if (!is_array($a_mboxes)) { 
     
    25342257        } 
    25352258 
    2536         // sort mailboxes (always sort for cache) 
     2259        // sort folders (always sort for cache) 
    25372260        if (!$skip_sort || $this->cache) { 
    2538             $a_mboxes = $this->_sort_mailbox_list($a_mboxes); 
    2539         } 
    2540  
    2541         // write mailboxlist to cache 
     2261            $a_mboxes = $this->sort_folder_list($a_mboxes); 
     2262        } 
     2263 
     2264        // write folders list to cache 
    25422265        $this->update_cache($cache_key, $a_mboxes); 
    25432266 
     
    25472270 
    25482271    /** 
    2549      * Private method for mailbox listing (LSUB) 
     2272     * protected method for folders listing (LSUB) 
    25502273     * 
    25512274     * @param   string  $root   Optional root folder 
     
    25552278     * 
    25562279     * @return  array   List of subscribed folders 
    2557      * @see     rcube_imap::list_mailboxes() 
    2558      * @access  private 
    2559      */ 
    2560     private function _list_mailboxes($root='', $name='*', $filter=null, $rights=null) 
     2280     * @see     rcube_imap::list_folders_subscribed() 
     2281     */ 
     2282    protected function _list_folders_subscribed($root='', $name='*', $filter=null, $rights=null) 
    25612283    { 
    25622284        $a_defaults = $a_out = array(); 
    25632285 
    2564         // Give plugins a chance to provide a list of mailboxes 
    2565         $data = rcmail::get_instance()->plugins->exec_hook('mailboxes_list', 
     2286        // Give plugins a chance to provide a list of folders 
     2287        $data = rcmail::get_instance()->plugins->exec_hook('folders_list', 
    25662288            array('root' => $root, 'name' => $name, 'filter' => $filter, 'mode' => 'LSUB')); 
    25672289 
     
    25772299            // #1486225: Some dovecot versions returns wrong result using LIST-EXTENDED 
    25782300            if (!$config->get('imap_force_lsub') && $this->get_capability('LIST-EXTENDED')) { 
    2579                 // This will also set mailbox options, LSUB doesn't do that 
     2301                // This will also set folder options, LSUB doesn't do that 
    25802302                $a_folders = $this->conn->listMailboxes($root, $name, 
    25812303                    NULL, array('SUBSCRIBED')); 
     
    26042326                        ) { 
    26052327                            // Some servers returns \Noselect for existing folders 
    2606                             if (!$this->mailbox_exists($folder)) { 
     2328                            if (!$this->folder_exists($folder)) { 
    26072329                                $this->conn->unsubscribe($folder); 
    26082330                                unset($a_folders[$idx]); 
     
    26232345 
    26242346    /** 
    2625      * Get a list of all folders available on the IMAP server 
     2347     * Get a list of all folders available on the server 
    26262348     * 
    26272349     * @param string  $root      IMAP root dir 
     
    26332355     * @return array Indexed array with folder names 
    26342356     */ 
    2635     function list_unsubscribed($root='', $name='*', $filter=null, $rights=null, $skip_sort=false) 
     2357    public function list_folders($root='', $name='*', $filter=null, $rights=null, $skip_sort=false) 
    26362358    { 
    26372359        $cache_key = $root.':'.$name; 
     
    26482370        } 
    26492371 
    2650         // Give plugins a chance to provide a list of mailboxes 
    2651         $data = rcmail::get_instance()->plugins->exec_hook('mailboxes_list', 
     2372        // Give plugins a chance to provide a list of folders 
     2373        $data = rcmail::get_instance()->plugins->exec_hook('folders_list', 
    26522374            array('root' => $root, 'name' => $name, 'filter' => $filter, 'mode' => 'LIST')); 
    26532375 
     
    26572379        else { 
    26582380            // retrieve list of folders from IMAP server 
    2659             $a_mboxes = $this->_list_unsubscribed($root, $name); 
     2381            $a_mboxes = $this->_list_folders($root, $name); 
    26602382        } 
    26612383 
     
    26812403        // filter folders and sort them 
    26822404        if (!$skip_sort) { 
    2683             $a_mboxes = $this->_sort_mailbox_list($a_mboxes); 
    2684         } 
    2685  
    2686         // write mailboxlist to cache 
     2405            $a_mboxes = $this->sort_folder_list($a_mboxes); 
     2406        } 
     2407 
     2408        // write folders list to cache 
    26872409        $this->update_cache($cache_key, $a_mboxes); 
    26882410 
     
    26922414 
    26932415    /** 
    2694      * Private method for mailbox listing (LIST) 
     2416     * protected method for folders listing (LIST) 
    26952417     * 
    26962418     * @param   string  $root   Optional root folder 
     
    26982420     * 
    26992421     * @return  array   List of folders 
    2700      * @see     rcube_imap::list_unsubscribed() 
    2701      */ 
    2702     private function _list_unsubscribed($root='', $name='*') 
     2422     * @see     rcube_imap::list_folders() 
     2423     */ 
     2424    protected function _list_folders($root='', $name='*') 
    27032425    { 
    27042426        $result = $this->conn->listMailboxes($root, $name); 
     
    27582480     * Filter the given list of folders according to access rights 
    27592481     */ 
    2760     private function filter_rights($a_folders, $rights) 
     2482    protected function filter_rights($a_folders, $rights) 
    27612483    { 
    27622484        $regex = '/('.$rights.')/'; 
     
    27772499     * @return mixed Quota info or False if not supported 
    27782500     */ 
    2779     function get_quota() 
    2780     { 
    2781         if ($this->get_capability('QUOTA')) 
     2501    public function get_quota() 
     2502    { 
     2503        if ($this->get_capability('QUOTA')) { 
    27822504            return $this->conn->getQuota(); 
     2505        } 
    27832506 
    27842507        return false; 
     
    27872510 
    27882511    /** 
    2789      * Get mailbox size (size of all messages in a mailbox) 
    2790      * 
    2791      * @param string $mailbox Mailbox name 
    2792      * 
    2793      * @return int Mailbox size in bytes, False on error 
    2794      */ 
    2795     function get_mailbox_size($mailbox) 
     2512     * Get folder size (size of all messages in a folder) 
     2513     * 
     2514     * @param string $folder Folder name 
     2515     * 
     2516     * @return int Folder size in bytes, False on error 
     2517     */ 
     2518    public function folder_size($folder) 
    27962519    { 
    27972520        // @TODO: could we try to use QUOTA here? 
    2798         $result = $this->conn->fetchHeaderIndex($mailbox, '1:*', 'SIZE', false); 
     2521        $result = $this->conn->fetchHeaderIndex($folder, '1:*', 'SIZE', false); 
    27992522 
    28002523        if (is_array($result)) 
     
    28062529 
    28072530    /** 
    2808      * Subscribe to a specific mailbox(es) 
    2809      * 
    2810      * @param array $a_mboxes Mailbox name(s) 
     2531     * Subscribe to a specific folder(s) 
     2532     * 
     2533     * @param array $folders Folder name(s) 
     2534     * 
    28112535     * @return boolean True on success 
    28122536     */ 
    2813     function subscribe($a_mboxes) 
    2814     { 
    2815         if (!is_array($a_mboxes)) 
    2816             $a_mboxes = array($a_mboxes); 
    2817  
     2537    public function subscribe($folders) 
     2538    { 
    28182539        // let this common function do the main work 
    2819         return $this->_change_subscription($a_mboxes, 'subscribe'); 
    2820     } 
    2821  
    2822  
    2823     /** 
    2824      * Unsubscribe mailboxes 
    2825      * 
    2826      * @param array $a_mboxes Mailbox name(s) 
     2540        return $this->change_subscription($folders, 'subscribe'); 
     2541    } 
     2542 
     2543 
     2544    /** 
     2545     * Unsubscribe folder(s) 
     2546     * 
     2547     * @param array $a_mboxes Folder name(s) 
     2548     * 
    28272549     * @return boolean True on success 
    28282550     */ 
    2829     function unsubscribe($a_mboxes) 
    2830     { 
    2831         if (!is_array($a_mboxes)) 
    2832             $a_mboxes = array($a_mboxes); 
    2833  
     2551    public function unsubscribe($folders) 
     2552    { 
    28342553        // let this common function do the main work 
    2835         return $this->_change_subscription($a_mboxes, 'unsubscribe'); 
    2836     } 
    2837  
    2838  
    2839     /** 
    2840      * Create a new mailbox on the server and register it in local cache 
    2841      * 
    2842      * @param string  $mailbox   New mailbox name 
    2843      * @param boolean $subscribe True if the new mailbox should be subscribed 
     2554        return $this->change_subscription($folders, 'unsubscribe'); 
     2555    } 
     2556 
     2557 
     2558    /** 
     2559     * Create a new folder on the server and register it in local cache 
     2560     * 
     2561     * @param string  $folder    New folder name 
     2562     * @param boolean $subscribe True if the new folder should be subscribed 
    28442563     * 
    28452564     * @return boolean True on success 
    28462565     */ 
    2847     function create_mailbox($mailbox, $subscribe=false) 
    2848     { 
    2849         $result = $this->conn->createFolder($mailbox); 
     2566    public function create_folder($folder, $subscribe=false) 
     2567    { 
     2568        $result = $this->conn->createFolder($folder); 
    28502569 
    28512570        // try to subscribe it 
     
    28552574 
    28562575            if ($subscribe) 
    2857                 $this->subscribe($mailbox); 
     2576                $this->subscribe($folder); 
    28582577        } 
    28592578 
     
    28632582 
    28642583    /** 
    2865      * Set a new name to an existing mailbox 
    2866      * 
    2867      * @param string $mailbox  Mailbox to rename 
    2868      * @param string $new_name New mailbox name 
     2584     * Set a new name to an existing folder 
     2585     * 
     2586     * @param string $folder   Folder to rename 
     2587     * @param string $new_name New folder name 
    28692588     * 
    28702589     * @return boolean True on success 
    28712590     */ 
    2872     function rename_mailbox($mailbox, $new_name) 
     2591    public function rename_folder($folder, $new_name) 
    28732592    { 
    28742593        if (!strlen($new_name)) { 
     
    28792598 
    28802599        // get list of subscribed folders 
    2881         if ((strpos($mailbox, '%') === false) && (strpos($mailbox, '*') === false)) { 
    2882             $a_subscribed = $this->_list_mailboxes('', $mailbox . $delm . '*'); 
    2883             $subscribed   = $this->mailbox_exists($mailbox, true); 
     2600        if ((strpos($folder, '%') === false) && (strpos($folder, '*') === false)) { 
     2601            $a_subscribed = $this->_list_folders_subscribed('', $folder . $delm . '*'); 
     2602            $subscribed   = $this->folder_exists($folder, true); 
    28842603        } 
    28852604        else { 
    2886             $a_subscribed = $this->_list_mailboxes(); 
    2887             $subscribed   = in_array($mailbox, $a_subscribed); 
    2888         } 
    2889  
    2890         $result = $this->conn->renameFolder($mailbox, $new_name); 
     2605            $a_subscribed = $this->_list_folders_subscribed(); 
     2606            $subscribed   = in_array($folder, $a_subscribed); 
     2607        } 
     2608 
     2609        $result = $this->conn->renameFolder($folder, $new_name); 
    28912610 
    28922611        if ($result) { 
    28932612            // unsubscribe the old folder, subscribe the new one 
    28942613            if ($subscribed) { 
    2895                 $this->conn->unsubscribe($mailbox); 
     2614                $this->conn->unsubscribe($folder); 
    28962615                $this->conn->subscribe($new_name); 
    28972616            } 
    28982617 
    2899             // check if mailbox children are subscribed 
     2618            // check if folder children are subscribed 
    29002619            foreach ($a_subscribed as $c_subscribed) { 
    2901                 if (strpos($c_subscribed, $mailbox.$delm) === 0) { 
     2620                if (strpos($c_subscribed, $folder.$delm) === 0) { 
    29022621                    $this->conn->unsubscribe($c_subscribed); 
    2903                     $this->conn->subscribe(preg_replace('/^'.preg_quote($mailbox, '/').'/', 
     2622                    $this->conn->subscribe(preg_replace('/^'.preg_quote($folder, '/').'/', 
    29042623                        $new_name, $c_subscribed)); 
    29052624 
     
    29102629 
    29112630            // clear cache 
    2912             $this->clear_message_cache($mailbox); 
     2631            $this->clear_message_cache($folder); 
    29132632            $this->clear_cache('mailboxes', true); 
    29142633        } 
     
    29192638 
    29202639    /** 
    2921      * Remove mailbox from server 
    2922      * 
    2923      * @param string $mailbox Mailbox name 
     2640     * Remove folder from server 
     2641     * 
     2642     * @param string $folder Folder name 
    29242643     * 
    29252644     * @return boolean True on success 
    29262645     */ 
    2927     function delete_mailbox($mailbox) 
     2646    function delete_folder($folder) 
    29282647    { 
    29292648        $delm = $this->get_hierarchy_delimiter(); 
    29302649 
    29312650        // get list of folders 
    2932         if ((strpos($mailbox, '%') === false) && (strpos($mailbox, '*') === false)) 
    2933             $sub_mboxes = $this->list_unsubscribed('', $mailbox . $delm . '*'); 
     2651        if ((strpos($folder, '%') === false) && (strpos($folder, '*') === false)) 
     2652            $sub_mboxes = $this->list_unsubscribed('', $folder . $delm . '*'); 
    29342653        else 
    29352654            $sub_mboxes = $this->list_unsubscribed(); 
    29362655 
    29372656        // send delete command to server 
    2938         $result = $this->conn->deleteFolder($mailbox); 
     2657        $result = $this->conn->deleteFolder($folder); 
    29392658 
    29402659        if ($result) { 
    2941             // unsubscribe mailbox 
    2942             $this->conn->unsubscribe($mailbox); 
     2660            // unsubscribe folder 
     2661            $this->conn->unsubscribe($folder); 
    29432662 
    29442663            foreach ($sub_mboxes as $c_mbox) { 
    2945                 if (strpos($c_mbox, $mailbox.$delm) === 0) { 
     2664                if (strpos($c_mbox, $folder.$delm) === 0) { 
    29462665                    $this->conn->unsubscribe($c_mbox); 
    29472666                    if ($this->conn->deleteFolder($c_mbox)) { 
     
    29512670            } 
    29522671 
    2953             // clear mailbox-related cache 
    2954             $this->clear_message_cache($mailbox); 
     2672            // clear folder-related cache 
     2673            $this->clear_message_cache($folder); 
    29552674            $this->clear_cache('mailboxes', true); 
    29562675        } 
     
    29632682     * Create all folders specified as default 
    29642683     */ 
    2965     function create_default_folders() 
     2684    public function create_default_folders() 
    29662685    { 
    29672686        // create default folders if they do not exist 
    29682687        foreach ($this->default_folders as $folder) { 
    2969             if (!$this->mailbox_exists($folder)) 
    2970                 $this->create_mailbox($folder, true); 
    2971             else if (!$this->mailbox_exists($folder, true)) 
     2688            if (!$this->folder_exists($folder)) 
     2689                $this->create_folder($folder, true); 
     2690            else if (!$this->folder_exists($folder, true)) 
    29722691                $this->subscribe($folder); 
    29732692        } 
     
    29782697     * Checks if folder exists and is subscribed 
    29792698     * 
    2980      * @param string   $mailbox      Folder name 
     2699     * @param string   $folder       Folder name 
    29812700     * @param boolean  $subscription Enable subscription checking 
    29822701     * 
    29832702     * @return boolean TRUE or FALSE 
    29842703     */ 
    2985     function mailbox_exists($mailbox, $subscription=false) 
    2986     { 
    2987         if ($mailbox == 'INBOX') { 
     2704    public function folder_exists($folder, $subscription=false) 
     2705    { 
     2706        if ($folder == 'INBOX') { 
    29882707            return true; 
    29892708        } 
     
    29912710        $key  = $subscription ? 'subscribed' : 'existing'; 
    29922711 
    2993         if (is_array($this->icache[$key]) && in_array($mailbox, $this->icache[$key])) 
     2712        if (is_array($this->icache[$key]) && in_array($folder, $this->icache[$key])) 
    29942713            return true; 
    29952714 
    29962715        if ($subscription) { 
    2997             $a_folders = $this->conn->listSubscribed('', $mailbox); 
     2716            $a_folders = $this->conn->listSubscribed('', $folder); 
    29982717        } 
    29992718        else { 
    3000             $a_folders = $this->conn->listMailboxes('', $mailbox); 
    3001         } 
    3002  
    3003         if (is_array($a_folders) && in_array($mailbox, $a_folders)) { 
    3004             $this->icache[$key][] = $mailbox; 
     2719            $a_folders = $this->conn->listMailboxes('', $folder); 
     2720        } 
     2721 
     2722        if (is_array($a_folders) && in_array($folder, $a_folders)) { 
     2723            $this->icache[$key][] = $folder; 
    30052724            return true; 
    30062725        } 
     
    30132732     * Returns the namespace where the folder is in 
    30142733     * 
    3015      * @param string $mailbox Folder name 
     2734     * @param string $folder Folder name 
    30162735     * 
    30172736     * @return string One of 'personal', 'other' or 'shared' 
    3018      * @access public 
    3019      */ 
    3020     function mailbox_namespace($mailbox) 
    3021     { 
    3022         if ($mailbox == 'INBOX') { 
     2737     */ 
     2738    public function folder_namespace($folder) 
     2739    { 
     2740        if ($folder == 'INBOX') { 
    30232741            return 'personal'; 
    30242742        } 
     
    30282746                foreach ($namespace as $ns) { 
    30292747                    if ($len = strlen($ns[0])) { 
    3030                         if (($len > 1 && $mailbox == substr($ns[0], 0, -1)) 
    3031                             || strpos($mailbox, $ns[0]) === 0 
     2748                        if (($len > 1 && $folder == substr($ns[0], 0, -1)) 
     2749                            || strpos($folder, $ns[0]) === 0 
    30322750                        ) { 
    30332751                            return $type; 
     
    30482766     * of the folders tree. 
    30492767     * 
    3050      * @param string $mailbox Folder name 
     2768     * @param string $folder Folder name 
    30512769     * @param string $mode    Mode name (out/in) 
    30522770     * 
    30532771     * @return string Folder name 
    30542772     */ 
    3055     function mod_mailbox($mailbox, $mode = 'out') 
    3056     { 
    3057         if (!strlen($mailbox)) { 
    3058             return $mailbox; 
     2773    public function mod_folder($folder, $mode = 'out') 
     2774    { 
     2775        if (!strlen($folder)) { 
     2776            return $folder; 
    30592777        } 
    30602778 
     
    30632781 
    30642782        if (!$prefix_len) { 
    3065             return $mailbox; 
     2783            return $folder; 
    30662784        } 
    30672785 
    30682786        // remove prefix for output 
    30692787        if ($mode == 'out') { 
    3070             if (substr($mailbox, 0, $prefix_len) === $prefix) { 
    3071                 return substr($mailbox, $prefix_len); 
     2788            if (substr($folder, 0, $prefix_len) === $prefix) { 
     2789                return substr($folder, $prefix_len); 
    30722790            } 
    30732791        } 
    30742792        // add prefix for input (e.g. folder creation) 
    30752793        else { 
    3076             return $prefix . $mailbox; 
    3077         } 
    3078  
    3079         return $mailbox; 
     2794            return $prefix . $folder; 
     2795        } 
     2796 
     2797        return $folder; 
    30802798    } 
    30812799 
     
    30842802     * Gets folder attributes from LIST response, e.g. \Noselect, \Noinferiors 
    30852803     * 
    3086      * @param string $mailbox Folder name 
     2804     * @param string $folder Folder name 
    30872805     * @param bool   $force   Set to True if attributes should be refreshed 
    30882806     * 
    30892807     * @return array Options list 
    30902808     */ 
    3091     function mailbox_attributes($mailbox, $force=false) 
     2809    public function folder_attributes($folder, $force=false) 
    30922810    { 
    30932811        // get attributes directly from LIST command 
    3094         if (!empty($this->conn->data['LIST']) && is_array($this->conn->data['LIST'][$mailbox])) { 
    3095             $opts = $this->conn->data['LIST'][$mailbox]; 
     2812        if (!empty($this->conn->data['LIST']) && is_array($this->conn->data['LIST'][$folder])) { 
     2813            $opts = $this->conn->data['LIST'][$folder]; 
    30962814        } 
    30972815        // get cached folder attributes 
    30982816        else if (!$force) { 
    30992817            $opts = $this->get_cache('mailboxes.attributes'); 
    3100             $opts = $opts[$mailbox]; 
     2818            $opts = $opts[$folder]; 
    31012819        } 
    31022820 
    31032821        if (!is_array($opts)) { 
    3104             $this->conn->listMailboxes('', $mailbox); 
    3105             $opts = $this->conn->data['LIST'][$mailbox]; 
     2822            $this->conn->listMailboxes('', $folder); 
     2823            $opts = $this->conn->data['LIST'][$folder]; 
    31062824        } 
    31072825 
     
    31112829 
    31122830    /** 
    3113      * Gets connection (and current mailbox) data: UIDVALIDITY, EXISTS, RECENT, 
     2831     * Gets connection (and current folder) data: UIDVALIDITY, EXISTS, RECENT, 
    31142832     * PERMANENTFLAGS, UIDNEXT, UNSEEN 
    31152833     * 
    3116      * @param string $mailbox Folder name 
     2834     * @param string $folder Folder name 
    31172835     * 
    31182836     * @return array Data 
    31192837     */ 
    3120     function mailbox_data($mailbox) 
    3121     { 
    3122         if (!strlen($mailbox)) 
    3123             $mailbox = $this->mailbox !== null ? $this->mailbox : 'INBOX'; 
    3124  
    3125         if ($this->conn->selected != $mailbox) { 
    3126             if ($this->conn->select($mailbox)) 
    3127                 $this->mailbox = $mailbox; 
     2838    public function folder_data($folder) 
     2839    { 
     2840        if (!strlen($folder)) 
     2841            $folder = $this->folder !== null ? $this->folder : 'INBOX'; 
     2842 
     2843        if ($this->conn->selected != $folder) { 
     2844            if ($this->conn->select($folder)) 
     2845                $this->folder = $folder; 
    31282846            else 
    31292847                return null; 
     
    31342852        // add (E)SEARCH result for ALL UNDELETED query 
    31352853        if (!empty($this->icache['undeleted_idx']) 
    3136             && $this->icache['undeleted_idx']->getParameters('MAILBOX') == $mailbox 
     2854            && $this->icache['undeleted_idx']->getParameters('MAILBOX') == $folder 
    31372855        ) { 
    31382856            $data['UNDELETED'] = $this->icache['undeleted_idx']; 
     
    31462864     * Returns extended information about the folder 
    31472865     * 
    3148      * @param string $mailbox Folder name 
     2866     * @param string $folder Folder name 
    31492867     * 
    31502868     * @return array Data 
    31512869     */ 
    3152     function mailbox_info($mailbox) 
    3153     { 
    3154         if ($this->icache['options'] && $this->icache['options']['name'] == $mailbox) { 
     2870    public function folder_info($folder) 
     2871    { 
     2872        if ($this->icache['options'] && $this->icache['options']['name'] == $folder) { 
    31552873            return $this->icache['options']; 
    31562874        } 
     
    31622880        // check if the folder is a namespace prefix 
    31632881        if (!empty($namespace)) { 
    3164             $mbox = $mailbox . $this->delimiter; 
     2882            $mbox = $folder . $this->delimiter; 
    31652883            foreach ($namespace as $ns) { 
    31662884                if (!empty($ns)) { 
     
    31762894        // check if the folder is other user virtual-root 
    31772895        if (!$options['is_root'] && !empty($namespace) && !empty($namespace['other'])) { 
    3178             $parts = explode($this->delimiter, $mailbox); 
     2896            $parts = explode($this->delimiter, $folder); 
    31792897            if (count($parts) == 2) { 
    31802898                $mbox = $parts[0] . $this->delimiter; 
     
    31882906        } 
    31892907 
    3190         $options['name']       = $mailbox; 
    3191         $options['attributes'] = $this->mailbox_attributes($mailbox, true); 
    3192         $options['namespace']  = $this->mailbox_namespace($mailbox); 
    3193         $options['rights']     = $acl && !$options['is_root'] ? (array)$this->my_rights($mailbox) : array(); 
    3194         $options['special']    = in_array($mailbox, $this->default_folders); 
     2908        $options['name']       = $folder; 
     2909        $options['attributes'] = $this->folder_attributes($folder, true); 
     2910        $options['namespace']  = $this->folder_namespace($folder); 
     2911        $options['rights']     = $acl && !$options['is_root'] ? (array)$this->my_rights($folder) : array(); 
     2912        $options['special']    = in_array($folder, $this->default_folders); 
    31952913 
    31962914        // Set 'noselect' and 'norename' flags 
     
    32272945     * Synchronizes messages cache. 
    32282946     * 
    3229      * @param string $mailbox Folder name 
    3230      */ 
    3231     public function mailbox_sync($mailbox) 
     2947     * @param string $folder Folder name 
     2948     */ 
     2949    public function folder_sync($folder) 
    32322950    { 
    32332951        if ($mcache = $this->get_mcache_engine()) { 
    3234             $mcache->synchronize($mailbox); 
     2952            $mcache->synchronize($folder); 
    32352953        } 
    32362954    } 
     
    32422960     * @return string Space-separated list of header names 
    32432961     */ 
    3244     private function get_fetch_headers() 
    3245     { 
    3246         $headers = explode(' ', $this->fetch_add_headers); 
    3247         $headers = array_map('strtoupper', $headers); 
    3248  
    3249         if ($this->messages_caching || $this->get_all_headers) 
     2962    protected function get_fetch_headers() 
     2963    { 
     2964        if (!empty($this->options['fetch_headers'])) { 
     2965            $headers = explode(' ', $this->options['fetch_headers']); 
     2966            $headers = array_map('strtoupper', $headers); 
     2967        } 
     2968        else { 
     2969            $headers = array(); 
     2970        } 
     2971 
     2972        if ($this->messages_caching || $this->options['all_headers']) { 
    32502973            $headers = array_merge($headers, $this->all_headers); 
     2974        } 
    32512975 
    32522976        return implode(' ', array_unique($headers)); 
     
    32592983 
    32602984    /** 
    3261      * Changes the ACL on the specified mailbox (SETACL) 
    3262      * 
    3263      * @param string $mailbox Mailbox name 
     2985     * Changes the ACL on the specified folder (SETACL) 
     2986     * 
     2987     * @param string $folder  Folder name 
    32642988     * @param string $user    User name 
    32652989     * @param string $acl     ACL string 
    32662990     * 
    32672991     * @return boolean True on success, False on failure 
    3268      * 
    3269      * @access public 
    32702992     * @since 0.5-beta 
    32712993     */ 
    3272     function set_acl($mailbox, $user, $acl) 
     2994    public function set_acl($folder, $user, $acl) 
    32732995    { 
    32742996        if ($this->get_capability('ACL')) 
    3275             return $this->conn->setACL($mailbox, $user, $acl); 
     2997            return $this->conn->setACL($folder, $user, $acl); 
    32762998 
    32772999        return false; 
     
    32823004     * Removes any <identifier,rights> pair for the 
    32833005     * specified user from the ACL for the specified 
    3284      * mailbox (DELETEACL) 
    3285      * 
    3286      * @param string $mailbox Mailbox name 
     3006     * folder (DELETEACL) 
     3007     * 
     3008     * @param string $folder  Folder name 
    32873009     * @param string $user    User name 
    32883010     * 
    32893011     * @return boolean True on success, False on failure 
    3290      * 
    3291      * @access public 
    32923012     * @since 0.5-beta 
    32933013     */ 
    3294     function delete_acl($mailbox, $user) 
     3014    public function delete_acl($folder, $user) 
    32953015    { 
    32963016        if ($this->get_capability('ACL')) 
    3297             return $this->conn->deleteACL($mailbox, $user); 
     3017            return $this->conn->deleteACL($folder, $user); 
    32983018 
    32993019        return false; 
     
    33023022 
    33033023    /** 
    3304      * Returns the access control list for mailbox (GETACL) 
    3305      * 
    3306      * @param string $mailbox Mailbox name 
     3024     * Returns the access control list for folder (GETACL) 
     3025     * 
     3026     * @param string $folder Folder name 
    33073027     * 
    33083028     * @return array User-rights array on success, NULL on error 
    3309      * @access public 
    33103029     * @since 0.5-beta 
    33113030     */ 
    3312     function get_acl($mailbox) 
     3031    public function get_acl($folder) 
    33133032    { 
    33143033        if ($this->get_capability('ACL')) 
    3315             return $this->conn->getACL($mailbox); 
     3034            return $this->conn->getACL($folder); 
    33163035 
    33173036        return NULL; 
     
    33213040    /** 
    33223041     * Returns information about what rights can be granted to the 
    3323      * user (identifier) in the ACL for the mailbox (LISTRIGHTS) 
    3324      * 
    3325      * @param string $mailbox Mailbox name 
     3042     * user (identifier) in the ACL for the folder (LISTRIGHTS) 
     3043     * 
     3044     * @param string $folder  Folder name 
    33263045     * @param string $user    User name 
    33273046     * 
    33283047     * @return array List of user rights 
    3329      * @access public 
    33303048     * @since 0.5-beta 
    33313049     */ 
    3332     function list_rights($mailbox, $user) 
     3050    public function list_rights($folder, $user) 
    33333051    { 
    33343052        if ($this->get_capability('ACL')) 
    3335             return $this->conn->listRights($mailbox, $user); 
     3053            return $this->conn->listRights($folder, $user); 
    33363054 
    33373055        return NULL; 
     
    33413059    /** 
    33423060     * Returns the set of rights that the current user has to 
    3343      * mailbox (MYRIGHTS) 
    3344      * 
    3345      * @param string $mailbox Mailbox name 
     3061     * folder (MYRIGHTS) 
     3062     * 
     3063     * @param string $folder Folder name 
    33463064     * 
    33473065     * @return array MYRIGHTS response on success, NULL on error 
    3348      * @access public 
    33493066     * @since 0.5-beta 
    33503067     */ 
    3351     function my_rights($mailbox) 
     3068    public function my_rights($folder) 
    33523069    { 
    33533070        if ($this->get_capability('ACL')) 
    3354             return $this->conn->myRights($mailbox); 
     3071            return $this->conn->myRights($folder); 
    33553072 
    33563073        return NULL; 
     
    33613078     * Sets IMAP metadata/annotations (SETMETADATA/SETANNOTATION) 
    33623079     * 
    3363      * @param string $mailbox Mailbox name (empty for server metadata) 
     3080     * @param string $folder  Folder name (empty for server metadata) 
    33643081     * @param array  $entries Entry-value array (use NULL value as NIL) 
    33653082     * 
    33663083     * @return boolean True on success, False on failure 
    3367      * @access public 
    33683084     * @since 0.5-beta 
    33693085     */ 
    3370     function set_metadata($mailbox, $entries) 
     3086    public function set_metadata($folder, $entries) 
    33713087    { 
    33723088        if ($this->get_capability('METADATA') || 
    3373             (!strlen($mailbox) && $this->get_capability('METADATA-SERVER')) 
     3089            (!strlen($folder) && $this->get_capability('METADATA-SERVER')) 
    33743090        ) { 
    3375             return $this->conn->setMetadata($mailbox, $entries); 
     3091            return $this->conn->setMetadata($folder, $entries); 
    33763092        } 
    33773093        else if ($this->get_capability('ANNOTATEMORE') || $this->get_capability('ANNOTATEMORE2')) { 
     
    33803096                $entries[$entry] = array($ent, $attr, $value); 
    33813097            } 
    3382             return $this->conn->setAnnotation($mailbox, $entries); 
     3098            return $this->conn->setAnnotation($folder, $entries); 
    33833099        } 
    33843100 
     
    33903106     * Unsets IMAP metadata/annotations (SETMETADATA/SETANNOTATION) 
    33913107     * 
    3392      * @param string $mailbox Mailbox name (empty for server metadata) 
     3108     * @param string $folder  Folder name (empty for server metadata) 
    33933109     * @param array  $entries Entry names array 
    33943110     * 
    33953111     * @return boolean True on success, False on failure 
    3396      * 
    3397      * @access public 
    33983112     * @since 0.5-beta 
    33993113     */ 
    3400     function delete_metadata($mailbox, $entries) 
     3114    public function delete_metadata($folder, $entries) 
    34013115    { 
    34023116        if ($this->get_capability('METADATA') ||  
    3403             (!strlen($mailbox) && $this->get_capability('METADATA-SERVER')) 
     3117            (!strlen($folder) && $this->get_capability('METADATA-SERVER')) 
    34043118        ) { 
    3405             return $this->conn->deleteMetadata($mailbox, $entries); 
     3119            return $this->conn->deleteMetadata($folder, $entries); 
    34063120        } 
    34073121        else if ($this->get_capability('ANNOTATEMORE') || $this->get_capability('ANNOTATEMORE2')) { 
     
    34103124                $entries[$idx] = array($ent, $attr, NULL); 
    34113125            } 
    3412             return $this->conn->setAnnotation($mailbox, $entries); 
     3126            return $this->conn->setAnnotation($folder, $entries); 
    34133127        } 
    34143128 
     
    34203134     * Returns IMAP metadata/annotations (GETMETADATA/GETANNOTATION) 
    34213135     * 
    3422      * @param string $mailbox Mailbox name (empty for server metadata) 
     3136     * @param string $folder  Folder name (empty for server metadata) 
    34233137     * @param array  $entries Entries 
    34243138     * @param array  $options Command options (with MAXSIZE and DEPTH keys) 
    34253139     * 
    34263140     * @return array Metadata entry-value hash array on success, NULL on error 
    3427      * 
    3428      * @access public 
    34293141     * @since 0.5-beta 
    34303142     */ 
    3431     function get_metadata($mailbox, $entries, $options=array()) 
     3143    public function get_metadata($folder, $entries, $options=array()) 
    34323144    { 
    34333145        if ($this->get_capability('METADATA') ||  
    3434             (!strlen($mailbox) && $this->get_capability('METADATA-SERVER')) 
     3146            (!strlen($folder) && $this->get_capability('METADATA-SERVER')) 
    34353147        ) { 
    3436             return $this->conn->getMetadata($mailbox, $entries, $options); 
     3148            return $this->conn->getMetadata($folder, $entries, $options); 
    34373149        } 
    34383150        else if ($this->get_capability('ANNOTATEMORE') || $this->get_capability('ANNOTATEMORE2')) { 
     
    34483160            // @TODO: Honor MAXSIZE and DEPTH options 
    34493161            foreach ($queries as $attrib => $entry) 
    3450                 if ($result = $this->conn->getAnnotation($mailbox, $entry, $attrib)) 
     3162                if ($result = $this->conn->getAnnotation($folder, $entry, $attrib)) 
    34513163                    $res = array_merge_recursive($res, $result); 
    34523164 
     
    34663178     * @return array Entry-attribute list, NULL if not supported (?) 
    34673179     */ 
    3468     private function md2annotate($entry) 
     3180    protected function md2annotate($entry) 
    34693181    { 
    34703182        if (substr($entry, 0, 7) == '/shared') { 
    34713183            return array(substr($entry, 7), 'value.shared'); 
    34723184        } 
    3473         else if (substr($entry, 0, 8) == '/private') { 
     3185        else if (substr($entry, 0, 8) == '/protected') { 
    34743186            return array(substr($entry, 8), 'value.priv'); 
    34753187        } 
     
    34883200     * 
    34893201     * @param string $type Cache type (@see rcmail::get_cache) 
    3490      * @access public 
    3491      */ 
    3492     function set_caching($type) 
     3202     */ 
     3203    public function set_caching($type) 
    34933204    { 
    34943205        if ($type) { 
     
    35063217     * Getter for IMAP cache object 
    35073218     */ 
    3508     private function get_cache_engine() 
     3219    protected function get_cache_engine() 
    35093220    { 
    35103221        if ($this->caching && !$this->cache) { 
     
    35203231     * 
    35213232     * @param string $key Cache key 
     3233     * 
    35223234     * @return mixed 
    3523      * @access public 
    3524      */ 
    3525     function get_cache($key) 
     3235     */ 
     3236    public function get_cache($key) 
    35263237    { 
    35273238        if ($cache = $this->get_cache_engine()) { 
     
    35353246     * @param string $key  Cache key 
    35363247     * @param mixed  $data Data 
    3537      * @access public 
    3538      */ 
    3539     function update_cache($key, $data) 
     3248     */ 
     3249    protected function update_cache($key, $data) 
    35403250    { 
    35413251        if ($cache = $this->get_cache_engine()) { 
     
    35503260     * @param boolean $prefix_mode Enable it to clear all keys starting 
    35513261     *                             with prefix specified in $key 
    3552      * @access public 
    3553      */ 
    3554     function clear_cache($key=null, $prefix_mode=false) 
     3262     */ 
     3263    public function clear_cache($key = null, $prefix_mode = false) 
    35553264    { 
    35563265        if ($cache = $this->get_cache_engine()) { 
     
    35693278     * @param boolean $set Flag 
    35703279     */ 
    3571     function set_messages_caching($set) 
     3280    public function set_messages_caching($set) 
    35723281    { 
    35733282        if ($set) { 
     
    35863295     * Getter for messages cache object 
    35873296     */ 
    3588     private function get_mcache_engine() 
     3297    protected function get_mcache_engine() 
    35893298    { 
    35903299        if ($this->messages_caching && !$this->mcache) { 
     
    35923301            if ($dbh = $rcmail->get_dbh()) { 
    35933302                $this->mcache = new rcube_imap_cache( 
    3594                     $dbh, $this, $rcmail->user->ID, $this->skip_deleted); 
     3303                    $dbh, $this, $rcmail->user->ID, $this->options['skip_deleted']); 
    35953304            } 
    35963305        } 
     
    36033312     * Clears the messages cache. 
    36043313     * 
    3605      * @param string $mailbox Folder name 
     3314     * @param string $folder Folder name 
    36063315     * @param array  $uids    Optional message UIDs to remove from cache 
    36073316     */ 
    3608     function clear_message_cache($mailbox = null, $uids = null) 
     3317    protected function clear_message_cache($folder = null, $uids = null) 
    36093318    { 
    36103319        if ($mcache = $this->get_mcache_engine()) { 
    3611             $mcache->clear($mailbox, $uids); 
     3320            $mcache->clear($folder, $uids); 
    36123321        } 
    36133322    } 
     
    36153324 
    36163325    /* -------------------------------- 
    3617      *         private methods 
     3326     *         protected methods 
    36183327     * --------------------------------*/ 
    36193328 
     
    36233332     * @param string $sort_field Sort column 
    36243333     * @param string $sort_order Sort order 
    3625      * @access private 
    3626      */ 
    3627     private function set_sort_order($sort_field, $sort_order) 
     3334     */ 
     3335    protected function set_sort_order($sort_field, $sort_order) 
    36283336    { 
    36293337        if ($sort_field != null) 
     
    36353343 
    36363344    /** 
    3637      * Sort mailboxes first by default folders and then in alphabethical order 
    3638      * 
    3639      * @param array $a_folders Mailboxes list 
    3640      * @access private 
    3641      */ 
    3642     private function _sort_mailbox_list($a_folders) 
     3345     * Sort folders first by default folders and then in alphabethical order 
     3346     * 
     3347     * @param array $a_folders Folders list 
     3348     */ 
     3349    protected function sort_folder_list($a_folders) 
    36433350    { 
    36443351        $a_out = $a_defaults = $folders = array(); 
     
    36703377            $a_out[] = (string) $folder; 
    36713378            unset($folders[$key]); 
    3672             $this->_rsort($folder, $delimiter, $folders, $a_out); 
     3379            $this->rsort($folder, $delimiter, $folders, $a_out); 
    36733380        } 
    36743381 
     
    36783385 
    36793386    /** 
    3680      * @access private 
    3681      */ 
    3682     private function _rsort($folder, $delimiter, &$list, &$out) 
     3387     * Recursive method for sorting folders 
     3388     */ 
     3389    protected function rsort($folder, $delimiter, &$list, &$out) 
    36833390    { 
    36843391        while (list($key, $name) = each($list)) { 
     
    36873394                $out[] = (string) $name; 
    36883395                    unset($list[$key]); 
    3689                     $this->_rsort($name, $delimiter, $list, $out); 
     3396                    $this->rsort($name, $delimiter, $list, $out); 
    36903397                } 
    36913398        } 
     
    36983405     * 
    36993406     * @param int    $id       Message (sequence) ID 
    3700      * @param string $mailbox  Mailbox name 
     3407     * @param string $folder   Folder name 
    37013408     * 
    37023409     * @return int Message UID 
    37033410     */ 
    3704     public function id2uid($id, $mailbox = null) 
    3705     { 
    3706         if (!strlen($mailbox)) { 
    3707             $mailbox = $this->mailbox; 
    3708         } 
    3709  
    3710         if ($uid = array_search($id, (array)$this->uid_id_map[$mailbox])) { 
     3411    public function id2uid($id, $folder = null) 
     3412    { 
     3413        if (!strlen($folder)) { 
     3414            $folder = $this->folder; 
     3415        } 
     3416 
     3417        if ($uid = array_search($id, (array)$this->uid_id_map[$folder])) { 
    37113418            return $uid; 
    37123419        } 
    37133420 
    3714         $uid = $this->conn->ID2UID($mailbox, $id); 
    3715  
    3716         $this->uid_id_map[$mailbox][$uid] = $id; 
     3421        $uid = $this->conn->ID2UID($folder, $id); 
     3422 
     3423        $this->uid_id_map[$folder][$uid] = $id; 
    37173424 
    37183425        return $uid; 
     
    37213428 
    37223429    /** 
    3723      * Subscribe/unsubscribe a list of mailboxes and update local cache 
    3724      * @access private 
    3725      */ 
    3726     private function _change_subscription($a_mboxes, $mode) 
     3430     * Subscribe/unsubscribe a list of folders and update local cache 
     3431     */ 
     3432    protected function change_subscription($folders, $mode) 
    37273433    { 
    37283434        $updated = false; 
    37293435 
    3730         if (is_array($a_mboxes)) 
    3731             foreach ($a_mboxes as $i => $mailbox) { 
    3732                 $a_mboxes[$i] = $mailbox; 
     3436        if (!empty($folders)) { 
     3437            foreach ((array)$folders as $i => $folder) { 
     3438                $folders[$i] = $folder; 
    37333439 
    37343440                if ($mode == 'subscribe') 
    3735                     $updated = $this->conn->subscribe($mailbox); 
     3441                    $updated = $this->conn->subscribe($folder); 
    37363442                else if ($mode == 'unsubscribe') 
    3737                     $updated = $this->conn->unsubscribe($mailbox); 
    3738             } 
    3739  
    3740         // clear cached mailbox list(s) 
     3443                    $updated = $this->conn->unsubscribe($folder); 
     3444            } 
     3445        } 
     3446 
     3447        // clear cached folders list(s) 
    37413448        if ($updated) { 
    37423449            $this->clear_cache('mailboxes', true); 
     
    37483455 
    37493456    /** 
    3750      * Increde/decrese messagecount for a specific mailbox 
    3751      * @access private 
    3752      */ 
    3753     private function _set_messagecount($mailbox, $mode, $increment) 
     3457     * Increde/decrese messagecount for a specific folder 
     3458     */ 
     3459    protected function set_messagecount($folder, $mode, $increment) 
    37543460    { 
    37553461        $mode = strtoupper($mode); 
    3756         $a_mailbox_cache = $this->get_cache('messagecount'); 
    3757  
    3758         if (!is_array($a_mailbox_cache[$mailbox]) || !isset($a_mailbox_cache[$mailbox][$mode]) || !is_numeric($increment)) 
     3462        $a_folder_cache = $this->get_cache('messagecount'); 
     3463 
     3464        if (!is_array($a_folder_cache[$folder]) || !isset($a_folder_cache[$folder][$mode]) || !is_numeric($increment)) 
    37593465            return false; 
    37603466 
    37613467        // add incremental value to messagecount 
    3762         $a_mailbox_cache[$mailbox][$mode] += $increment; 
     3468        $a_folder_cache[$folder][$mode] += $increment; 
    37633469 
    37643470        // there's something wrong, delete from cache 
    3765         if ($a_mailbox_cache[$mailbox][$mode] < 0) 
    3766             unset($a_mailbox_cache[$mailbox][$mode]); 
     3471        if ($a_folder_cache[$folder][$mode] < 0) 
     3472            unset($a_folder_cache[$folder][$mode]); 
    37673473 
    37683474        // write back to cache 
    3769         $this->update_cache('messagecount', $a_mailbox_cache); 
     3475        $this->update_cache('messagecount', $a_folder_cache); 
    37703476 
    37713477        return true; 
     
    37743480 
    37753481    /** 
    3776      * Remove messagecount of a specific mailbox from cache 
    3777      * @access private 
    3778      */ 
    3779     private function _clear_messagecount($mailbox, $mode=null) 
    3780     { 
    3781         $a_mailbox_cache = $this->get_cache('messagecount'); 
    3782  
    3783         if (is_array($a_mailbox_cache[$mailbox])) { 
     3482     * Remove messagecount of a specific folder from cache 
     3483     */ 
     3484    protected function clear_messagecount($folder, $mode=null) 
     3485    { 
     3486        $a_folder_cache = $this->get_cache('messagecount'); 
     3487 
     3488        if (is_array($a_folder_cache[$folder])) { 
    37843489            if ($mode) { 
    3785                 unset($a_mailbox_cache[$mailbox][$mode]); 
     3490                unset($a_folder_cache[$folder][$mode]); 
    37863491            } 
    37873492            else { 
    3788                 unset($a_mailbox_cache[$mailbox]); 
    3789             } 
    3790             $this->update_cache('messagecount', $a_mailbox_cache); 
     3493                unset($a_folder_cache[$folder]); 
     3494            } 
     3495            $this->update_cache('messagecount', $a_folder_cache); 
    37913496        } 
    37923497    } 
     
    38033508 
    38043509}  // end class rcube_imap 
    3805  
    3806  
    3807 /** 
    3808  * Class representing a message part 
    3809  * 
    3810  * @package Mail 
    3811  */ 
    3812 class rcube_message_part 
    3813 { 
    3814     var $mime_id = ''; 
    3815     var $ctype_primary = 'text'; 
    3816     var $ctype_secondary = 'plain'; 
    3817     var $mimetype = 'text/plain'; 
    3818     var $disposition = ''; 
    3819     var $filename = ''; 
    3820     var $encoding = '8bit'; 
    3821     var $charset = ''; 
    3822     var $size = 0; 
    3823     var $headers = array(); 
    3824     var $d_parameters = array(); 
    3825     var $ctype_parameters = array(); 
    3826  
    3827     function __clone() 
    3828     { 
    3829         if (isset($this->parts)) 
    3830             foreach ($this->parts as $idx => $part) 
    3831                 if (is_object($part)) 
    3832                         $this->parts[$idx] = clone $part; 
    3833     } 
    3834 } 
    3835  
    3836  
    3837 /** 
    3838  * Class for sorting an array of rcube_mail_header objects in a predetermined order. 
    3839  * 
    3840  * @package Mail 
    3841  * @author Eric Stadtherr 
    3842  */ 
    3843 class rcube_header_sorter 
    3844 { 
    3845     private $uids = array(); 
    3846  
    3847  
    3848     /** 
    3849      * Set the predetermined sort order. 
    3850      * 
    3851      * @param array $index  Numerically indexed array of IMAP UIDs 
    3852      */ 
    3853     function set_index($index) 
    3854     { 
    3855         $index = array_flip($index); 
    3856  
    3857         $this->uids = $index; 
    3858     } 
    3859  
    3860     /** 
    3861      * Sort the array of header objects 
    3862      * 
    3863      * @param array $headers Array of rcube_mail_header objects indexed by UID 
    3864      */ 
    3865     function sort_headers(&$headers) 
    3866     { 
    3867         uksort($headers, array($this, "compare_uids")); 
    3868     } 
    3869  
    3870     /** 
    3871      * Sort method called by uksort() 
    3872      * 
    3873      * @param int $a Array key (UID) 
    3874      * @param int $b Array key (UID) 
    3875      */ 
    3876     function compare_uids($a, $b) 
    3877     { 
    3878         // then find each sequence number in my ordered list 
    3879         $posa = isset($this->uids[$a]) ? intval($this->uids[$a]) : -1; 
    3880         $posb = isset($this->uids[$b]) ? intval($this->uids[$b]) : -1; 
    3881  
    3882         // return the relative position as the comparison value 
    3883         return $posa - $posb; 
    3884     } 
    3885 } 
  • branches/devel-framework/roundcubemail/program/include/rcube_imap_cache.php

    r5658 r5758  
    199199        if ($data === null) { 
    200200            // Get mailbox data (UIDVALIDITY, counters, etc.) for status check 
    201             $mbox_data = $this->imap->mailbox_data($mailbox); 
     201            $mbox_data = $this->imap->folder_data($mailbox); 
    202202            $data      = $this->get_index_data($mailbox, $sort_field, $sort_order, $mbox_data); 
    203203 
     
    260260        if ($index === null) { 
    261261            // Get mailbox data (UIDVALIDITY, counters, etc.) for status check 
    262             $mbox_data = $this->imap->mailbox_data($mailbox); 
     262            $mbox_data = $this->imap->folder_data($mailbox); 
    263263 
    264264            if ($mbox_data['EXISTS']) { 
     
    372372        // Get the message from IMAP server 
    373373        if (empty($message) && $update) { 
    374             $message = $this->imap->get_headers($uid, $mailbox, true); 
     374            $message = $this->imap->get_message_headers($uid, $mailbox, true); 
    375375            // cache will be updated in close(), see below 
    376376        } 
     
    741741 
    742742        // Get mailbox data (UIDVALIDITY, counters, etc.) for status check 
    743         $mbox_data = $this->imap->mailbox_data($mailbox); 
     743        $mbox_data = $this->imap->folder_data($mailbox); 
    744744 
    745745        // @TODO: Think about skipping validation checks. 
     
    902902 
    903903        // Get mailbox data (UIDVALIDITY, HIGHESTMODSEQ, counters, etc.) 
    904         $mbox_data = $this->imap->mailbox_data($mailbox); 
     904        $mbox_data = $this->imap->folder_data($mailbox); 
    905905 
    906906        if (empty($mbox_data)) { 
     
    987987        // Get VANISHED 
    988988        if ($qresync) { 
    989             $mbox_data = $this->imap->mailbox_data($mailbox); 
     989            $mbox_data = $this->imap->folder_data($mailbox); 
    990990 
    991991            // Removed messages 
     
    11041104    { 
    11051105        if (empty($mbox_data)) { 
    1106             $mbox_data = $this->imap->mailbox_data($mailbox); 
     1106            $mbox_data = $this->imap->folder_data($mailbox); 
    11071107        } 
    11081108 
    11091109        if ($mbox_data['EXISTS']) { 
    11101110            // fetch sorted sequence numbers 
    1111             $index = $this->imap->message_index_direct($mailbox, $sort_field, $sort_order); 
     1111            $index = $this->imap->index_direct($mailbox, $sort_field, $sort_order); 
    11121112        } 
    11131113        else { 
  • branches/devel-framework/roundcubemail/program/include/rcube_message.php

    r5716 r5758  
    7777        $this->uid  = $uid; 
    7878        $this->app  = rcmail::get_instance(); 
    79         $this->imap = $this->app->imap; 
    80         $this->imap->get_all_headers = true; 
    81  
    82         $this->headers = $this->imap->get_message($uid); 
     79        $this->storage = $this->app->get_storage(); 
     80        $this->storage->set_options(array('all_headers' => true)); 
     81 
     82        $this->headers = $this->storage->get_message($uid); 
    8383 
    8484        if (!$this->headers) 
     
    9595            'prefer_html' => $this->app->config->get('prefer_html'), 
    9696            'get_url' => rcmail_url('get', array( 
    97                 '_mbox' => $this->imap->get_mailbox_name(), '_uid' => $uid)) 
     97                '_mbox' => $this->storage->get_folder(), '_uid' => $uid)) 
    9898        ); 
    9999 
     
    103103        } 
    104104        else { 
    105             $this->body = $this->imap->get_body($uid); 
     105            $this->body = $this->storage->get_body($uid); 
    106106        } 
    107107 
     
    177177            } 
    178178            // get from IMAP 
    179             return $this->imap->get_message_part($this->uid, $mime_id, $part, NULL, $fp); 
     179            return $this->storage->get_message_part($this->uid, $mime_id, $part, NULL, $fp); 
    180180        } else 
    181181            return null; 
     
    212212            $mimetype = strtolower($part->ctype_primary . '/' . $part->ctype_secondary); 
    213213            if ($mimetype == 'text/html') { 
    214                 return $this->imap->get_message_part($this->uid, $mime_id, $part); 
     214                return $this->storage->get_message_part($this->uid, $mime_id, $part); 
    215215            } 
    216216        } 
     
    235235 
    236236            if ($mimetype == 'text/plain') { 
    237                 return $this->imap->get_message_part($this->uid, $mime_id, $part); 
     237                return $this->storage->get_message_part($this->uid, $mime_id, $part); 
    238238            } 
    239239            else if ($mimetype == 'text/html') { 
    240                 $out = $this->imap->get_message_part($this->uid, $mime_id, $part); 
     240                $out = $this->storage->get_message_part($this->uid, $mime_id, $part); 
    241241 
    242242                // remove special chars encoding 
     
    591591        // @TODO: attachment may be huge, hadle it via file 
    592592        if (!isset($part->body)) 
    593             $part->body = $this->imap->get_message_part($this->uid, $part->mime_id, $part); 
     593            $part->body = $this->storage->get_message_part($this->uid, $part->mime_id, $part); 
    594594 
    595595        $parts = array(); 
     
    627627        // @TODO: messages may be huge, hadle body via file 
    628628        if (!isset($part->body)) 
    629             $part->body = $this->imap->get_message_part($this->uid, $part->mime_id, $part); 
     629            $part->body = $this->storage->get_message_part($this->uid, $part->mime_id, $part); 
    630630 
    631631        $parts = array(); 
  • branches/devel-framework/roundcubemail/program/include/rcube_template.php

    r5647 r5758  
    805805                    case 'config': 
    806806                        $value = $this->config[$name]; 
    807                         if (is_array($value) && $value[$_SESSION['imap_host']]) { 
    808                             $value = $value[$_SESSION['imap_host']]; 
     807                        if (is_array($value) && $value[$_SESSION['storage_host']]) { 
     808                            $value = $value[$_SESSION['storage_host']]; 
    809809                        } 
    810810                        break; 
  • branches/devel-framework/roundcubemail/program/steps/mail/check_recent.inc

    r5563 r5758  
    2020*/ 
    2121 
    22 $current = $RCMAIL->imap->get_mailbox_name(); 
     22$current = $RCMAIL->storage->get_folder(); 
    2323$check_all = !empty($_GET['_refresh']) || (bool)$RCMAIL->config->get('check_all_folders'); 
    2424 
    2525// list of folders to check 
    2626if ($check_all) { 
    27     $a_mailboxes = $RCMAIL->imap->list_mailboxes('', '*', 'mail'); 
     27    $a_mailboxes = $RCMAIL->storage->list_folders_subscribed('', '*', 'mail'); 
    2828} 
    2929else { 
     
    3838    if ($is_current) { 
    3939        // Synchronize mailbox cache, handle flag changes 
    40         $RCMAIL->imap->mailbox_sync($mbox_name); 
     40        $RCMAIL->storage->folder_sync($mbox_name); 
    4141    } 
    4242 
    4343    // Get mailbox status 
    44     $status = $RCMAIL->imap->mailbox_status($mbox_name); 
     44    $status = $RCMAIL->storage->folder_status($mbox_name); 
    4545 
    4646    if ($status & 1) { 
     
    5959            && $_SESSION['search_request'] == $search_request 
    6060        ) { 
    61             $_SESSION['search'] = $RCMAIL->imap->refresh_search(); 
     61            $_SESSION['search'] = $RCMAIL->storage->refresh_search(); 
    6262        } 
    6363 
     
    6969            continue; 
    7070 
    71         // get overall message count; allow caching because rcube_imap::mailbox_status() did a refresh 
    72         $all_count = $RCMAIL->imap->messagecount(null, $RCMAIL->imap->threading ? 'THREADS' : 'ALL'); 
     71        // get overall message count; allow caching because rcube_storage::folder_status() did a refresh 
     72        $all_count = $RCMAIL->storage->count(null, $RCMAIL->storage->get_threading() ? 'THREADS' : 'ALL'); 
     73 
     74        $page      = $RCMAIL->storage->get_page(); 
     75        $page_size = $RCMAIL->storage->get_pagesize(); 
    7376 
    7477        // check current page if we're not on the first page 
    75         if ($all_count && $RCMAIL->imap->list_page > 1) { 
    76             $remaining = $all_count - $RCMAIL->imap->page_size * ($RCMAIL->imap->list_page - 1); 
     78        if ($all_count && $page > 1) { 
     79            $remaining = $all_count - $page_size * ($page - 1); 
    7780            if ($remaining <= 0) { 
    78                 $RCMAIL->imap->set_page($RCMAIL->imap->list_page-1); 
    79                 $_SESSION['page'] = $RCMAIL->imap->list_page; 
     81                $page -= 1; 
     82                $RCMAIL->storage->set_page($page); 
     83                $_SESSION['page'] = $page; 
    8084            } 
    8185        } 
    8286 
    8387        $OUTPUT->set_env('messagecount', $all_count); 
    84         $OUTPUT->set_env('pagecount', ceil($all_count/$RCMAIL->imap->page_size)); 
     88        $OUTPUT->set_env('pagecount', ceil($all_count/$page_size)); 
    8589        $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($all_count), $mbox_name); 
    86         $OUTPUT->set_env('current_page', $all_count ? $RCMAIL->imap->list_page : 1); 
     90        $OUTPUT->set_env('current_page', $all_count ? $page : 1); 
    8791 
    8892        // remove old rows (and clear selection if new list is empty) 
     
    9094 
    9195        if ($all_count) { 
    92             $a_headers = $RCMAIL->imap->list_headers($mbox_name, null, $_SESSION['sort_col'], $_SESSION['sort_order']); 
     96            $a_headers = $RCMAIL->storage->list_messages($mbox_name, null, $_SESSION['sort_col'], $_SESSION['sort_order']); 
    9397            // add message rows 
    9498            rcmail_js_message_list($a_headers, false); 
  • branches/devel-framework/roundcubemail/program/steps/mail/compose.inc

    r5723 r5758  
    5757    'id'      => $COMPOSE_ID, 
    5858    'param'   => request2param(RCUBE_INPUT_GET), 
    59     'mailbox' => $RCMAIL->imap->get_mailbox_name(), 
     59    'mailbox' => $RCMAIL->storage->get_folder(), 
    6060  ); 
    6161  $COMPOSE =& $_SESSION['compose_data_'.$COMPOSE_ID]; 
     
    135135} 
    136136// set current mailbox in client environment 
    137 $OUTPUT->set_env('mailbox', $RCMAIL->imap->get_mailbox_name()); 
     137$OUTPUT->set_env('mailbox', $RCMAIL->storage->get_folder()); 
    138138$OUTPUT->set_env('sig_above', $RCMAIL->config->get('sig_above', false)); 
    139139$OUTPUT->set_env('top_posting', $RCMAIL->config->get('top_posting', false)); 
     
    148148// get reference message and set compose mode 
    149149if ($msg_uid = $COMPOSE['param']['draft_uid']) { 
    150   $RCMAIL->imap->set_mailbox($CONFIG['drafts_mbox']); 
     150  $RCMAIL->storage->set_folder($CONFIG['drafts_mbox']); 
    151151  $compose_mode = RCUBE_COMPOSE_DRAFT; 
    152152} 
     
    180180  // make sure message is marked as read 
    181181  if ($MESSAGE && $MESSAGE->headers && empty($MESSAGE->headers->flags['SEEN'])) 
    182     $RCMAIL->imap->set_flag($msg_uid, 'SEEN'); 
     182    $RCMAIL->storage->set_flag($msg_uid, 'SEEN'); 
    183183 
    184184  if (!empty($MESSAGE->headers->charset)) 
    185     $RCMAIL->imap->set_charset($MESSAGE->headers->charset); 
     185    $RCMAIL->storage->set_charset($MESSAGE->headers->charset); 
    186186 
    187187  if ($compose_mode == RCUBE_COMPOSE_REPLY) 
     
    10521052    $path = tempnam($temp_dir, 'rcmAttmnt'); 
    10531053    if ($fp = fopen($path, 'w')) { 
    1054       $RCMAIL->imap->get_raw_body($message->uid, $fp); 
     1054      $RCMAIL->storage->get_raw_body($message->uid, $fp); 
    10551055      fclose($fp); 
    10561056    } else 
    10571057      return false; 
    10581058  } else { 
    1059     $data = $RCMAIL->imap->get_raw_body($message->uid); 
     1059    $data = $RCMAIL->storage->get_raw_body($message->uid); 
    10601060  } 
    10611061 
     
    14291429  global $RCMAIL; 
    14301430 
    1431   if ($RCMAIL->imap->mailbox_exists($folder, true)) { 
     1431  if ($RCMAIL->storage->folder_exists($folder, true)) { 
    14321432    return true; 
    14331433  } 
     
    14351435  // folder may exist but isn't subscribed (#1485241) 
    14361436  if ($create) { 
    1437     if (!$RCMAIL->imap->mailbox_exists($folder)) 
    1438       return $RCMAIL->imap->create_mailbox($folder, true); 
     1437    if (!$RCMAIL->storage->folder_exists($folder)) 
     1438      return $RCMAIL->storage->create_folder($folder, true); 
    14391439    else 
    1440       return $RCMAIL->imap->subscribe($folder); 
     1440      return $RCMAIL->storage->subscribe($folder); 
    14411441  } 
    14421442 
  • branches/devel-framework/roundcubemail/program/steps/mail/copy.inc

    r5563 r5758  
    3030    $mbox = get_input_value('_mbox', RCUBE_INPUT_POST, true); 
    3131 
    32     $copied = $RCMAIL->imap->copy_message($uids, $target, $mbox); 
     32    $copied = $RCMAIL->storage->copy_message($uids, $target, $mbox); 
    3333 
    3434    if (!$copied) { 
  • branches/devel-framework/roundcubemail/program/steps/mail/folders.inc

    r5563 r5758  
    2828if ($RCMAIL->action == 'expunge') { 
    2929 
    30     $success = $RCMAIL->imap->expunge($mbox); 
     30    $success = $RCMAIL->storage->expunge_folder($mbox); 
    3131 
    3232    // reload message list if current mailbox 
     
    4949else if ($RCMAIL->action == 'purge') 
    5050{ 
    51     $delimiter = $RCMAIL->imap->get_hierarchy_delimiter(); 
     51    $delimiter = $RCMAIL->storage->get_hierarchy_delimiter(); 
    5252    $trash_regexp = '/^' . preg_quote($CONFIG['trash_mbox'] . $delimiter, '/') . '/'; 
    5353    $junk_regexp  = '/^' . preg_quote($CONFIG['junk_mbox'] . $delimiter, '/') . '/'; 
     
    5757        || preg_match($trash_regexp, $mbox) || preg_match($junk_regexp, $mbox) 
    5858    ) { 
    59         $success = $RCMAIL->imap->clear_mailbox($mbox); 
     59        $success = $RCMAIL->storage->clear_folder($mbox); 
    6060 
    6161        if ($success) { 
  • branches/devel-framework/roundcubemail/program/steps/mail/func.inc

    r5745 r5758  
    3030 
    3131// actions that do not require imap connection here 
    32 $NOIMAP_ACTIONS = array('addcontact', 'autocomplete', 'upload', 'display-attachment', 'remove-attachment', 'get'); 
     32$NOSTORAGE_ACTIONS = array('addcontact', 'autocomplete', 'upload', 'display-attachment', 'remove-attachment', 'get'); 
    3333 
    3434// always instantiate imap object (but not yet connect to server) 
    35 $RCMAIL->imap_init(); 
     35$RCMAIL->storage_init(); 
    3636 
    3737// log in to imap server 
    38 if (!in_array($RCMAIL->action, $NOIMAP_ACTIONS) && !$RCMAIL->imap_connect()) { 
     38if (!in_array($RCMAIL->action, $NOSTORAGE_ACTIONS) && !$RCMAIL->storage_connect()) { 
    3939  $RCMAIL->kill_session(); 
    4040 
     
    4848// set imap properties and session vars 
    4949if (strlen(trim($mbox = get_input_value('_mbox', RCUBE_INPUT_GPC, true)))) 
    50   $RCMAIL->imap->set_mailbox(($_SESSION['mbox'] = $mbox)); 
    51 else if ($RCMAIL->imap) 
    52   $_SESSION['mbox'] = $RCMAIL->imap->get_mailbox_name(); 
     50  $RCMAIL->storage->set_folder(($_SESSION['mbox'] = $mbox)); 
     51else if ($RCMAIL->storage) 
     52  $_SESSION['mbox'] = $RCMAIL->storage->get_folder(); 
    5353 
    5454if (!empty($_GET['_page'])) 
    55   $RCMAIL->imap->set_page(($_SESSION['page'] = intval($_GET['_page']))); 
     55  $RCMAIL->storage->set_page(($_SESSION['page'] = intval($_GET['_page']))); 
    5656 
    5757// set default sort col/order to session 
     
    7070  $RCMAIL->user->save_prefs(array('message_threading' => $a_threading)); 
    7171} 
    72 $RCMAIL->imap->set_threading($a_threading[$_SESSION['mbox']]); 
     72$RCMAIL->storage->set_threading($a_threading[$_SESSION['mbox']]); 
    7373 
    7474// set message set for search result 
     
    7676    && $_SESSION['search_request'] == $_REQUEST['_search'] 
    7777) { 
    78   $RCMAIL->imap->set_search_set($_SESSION['search']); 
     78  $RCMAIL->storage->set_search_set($_SESSION['search']); 
    7979  $OUTPUT->set_env('search_request', $_REQUEST['_search']); 
    8080  $OUTPUT->set_env('search_text', $_SESSION['last_text_search']); 
     
    8383// set main env variables, labels and page title 
    8484if (empty($RCMAIL->action) || $RCMAIL->action == 'list') { 
    85   $mbox_name = $RCMAIL->imap->get_mailbox_name(); 
     85  $mbox_name = $RCMAIL->storage->get_folder(); 
    8686 
    8787  if (empty($RCMAIL->action)) { 
     
    9090      $search_request = md5($mbox_name.$_SESSION['search_filter']); 
    9191 
    92       $RCMAIL->imap->search($mbox_name, $_SESSION['search_filter'], RCMAIL_CHARSET, $_SESSION['sort_col']); 
    93       $_SESSION['search'] = $RCMAIL->imap->get_search_set(); 
     92      $RCMAIL->storage->search($mbox_name, $_SESSION['search_filter'], RCMAIL_CHARSET, $_SESSION['sort_col']); 
     93      $_SESSION['search'] = $RCMAIL->storage->get_search_set(); 
    9494      $_SESSION['search_request'] = $search_request; 
    9595      $OUTPUT->set_env('search_request', $search_request); 
     
    100100  } 
    101101 
     102  $threading = (bool) $RCMAIL->storage->get_threading(); 
     103 
    102104  // set current mailbox and some other vars in client environment 
    103105  $OUTPUT->set_env('mailbox', $mbox_name); 
    104   $OUTPUT->set_env('pagesize', $RCMAIL->imap->page_size); 
    105   $OUTPUT->set_env('quota', $RCMAIL->imap->get_capability('QUOTA')); 
    106   $OUTPUT->set_env('delimiter', $RCMAIL->imap->get_hierarchy_delimiter()); 
    107   $OUTPUT->set_env('threading', (bool) $RCMAIL->imap->threading); 
    108   $OUTPUT->set_env('threads', $RCMAIL->imap->threading || $RCMAIL->imap->get_capability('THREAD')); 
     106  $OUTPUT->set_env('pagesize', $RCMAIL->storage->get_pagesize()); 
     107  $OUTPUT->set_env('quota', $RCMAIL->storage->get_capability('QUOTA')); 
     108  $OUTPUT->set_env('delimiter', $RCMAIL->storage->get_hierarchy_delimiter()); 
     109  $OUTPUT->set_env('threading', $threading); 
     110  $OUTPUT->set_env('threads', $threading || $RCMAIL->storage->get_capability('THREAD')); 
    109111  $OUTPUT->set_env('preview_pane_mark_read', $RCMAIL->config->get('preview_pane_mark_read', 0)); 
    110112 
     
    131133      'copy', 'move', 'quota'); 
    132134 
    133   $OUTPUT->set_pagetitle(rcmail_localize_foldername($RCMAIL->imap->mod_mailbox($mbox_name))); 
     135  $OUTPUT->set_pagetitle(rcmail_localize_foldername($RCMAIL->storage->mod_folder($mbox_name))); 
    134136} 
    135137 
     
    162164  $_SESSION['list_attrib'] = $attrib; 
    163165 
    164   $mbox = $RCMAIL->imap->get_mailbox_name(); 
    165   $delim = $RCMAIL->imap->get_hierarchy_delimiter(); 
     166  $mbox = $RCMAIL->storage->get_folder(); 
     167  $delim = $RCMAIL->storage->get_hierarchy_delimiter(); 
    166168 
    167169  // show 'to' instead of 'from' in sent/draft messages 
     
    219221  } 
    220222 
    221   $mbox = $RCMAIL->imap->get_mailbox_name(); 
    222   $delim = $RCMAIL->imap->get_hierarchy_delimiter(); 
     223  $mbox = $RCMAIL->storage->get_folder(); 
     224  $delim = $RCMAIL->storage->get_hierarchy_delimiter(); 
    223225 
    224226  // make sure 'threads' and 'subject' columns are present 
     
    318320  } 
    319321 
    320   if ($RCMAIL->imap->threading) { 
     322  if ($RCMAIL->storage->get_threading()) { 
    321323    $OUTPUT->command('init_threads', (array) $roots, $mbox); 
    322324  } 
     
    431433  global $RCMAIL; 
    432434 
    433   if ($page===NULL) 
    434     $page = $RCMAIL->imap->list_page; 
    435  
    436   $start_msg = ($page-1) * $RCMAIL->imap->page_size + 1; 
     435  if ($page === NULL) { 
     436    $page = $RCMAIL->storage->get_page(); 
     437  } 
     438 
     439  $page_size = $RCMAIL->storage->get_pagesize(); 
     440  $start_msg = ($page-1) * $page_size + 1; 
    437441 
    438442  if ($count!==NULL) 
    439443    $max = $count; 
    440444  else if ($RCMAIL->action) 
    441     $max = $RCMAIL->imap->messagecount(NULL, $RCMAIL->imap->threading ? 'THREADS' : 'ALL'); 
     445    $max = $RCMAIL->storage->count(NULL, $RCMAIL->storage->get_threading() ? 'THREADS' : 'ALL'); 
    442446 
    443447  if ($max==0) 
    444448    $out = rcube_label('mailboxempty'); 
    445449  else 
    446     $out = rcube_label(array('name' => $RCMAIL->imap->threading ? 'threadsfromto' : 'messagesfromto', 
     450    $out = rcube_label(array('name' => $RCMAIL->storage->get_threading() ? 'threadsfromto' : 'messagesfromto', 
    447451            'vars' => array('from'  => $start_msg, 
    448             'to'    => min($max, $start_msg + $RCMAIL->imap->page_size - 1), 
     452            'to'    => min($max, $start_msg + $page_size - 1), 
    449453            'count' => $max))); 
    450454 
     
    469473{ 
    470474  global $RCMAIL; 
    471   return rcmail_localize_foldername($RCMAIL->imap->get_mailbox_name()); 
     475  return rcmail_localize_foldername($RCMAIL->storage->get_folder()); 
    472476} 
    473477 
     
    480484 
    481485  if ($count === null) 
    482     $unseen = $RCMAIL->imap->messagecount($mbox_name, 'UNSEEN', $force); 
     486    $unseen = $RCMAIL->storage->count($mbox_name, 'UNSEEN', $force); 
    483487  else 
    484488    $unseen = $count; 
     
    591595  $html = preg_replace_callback('/(<[\/]*)([^\s>]+)/', 'rcmail_html_tag_callback', $html); 
    592596 
    593   // charset was converted to UTF-8 in rcube_imap::get_message_part(), 
     597  // charset was converted to UTF-8 in rcube_storage::get_message_part(), 
    594598  // change/add charset specification in HTML accordingly, 
    595599  // washtml cannot work without that 
     
    10111015          $out .= html::span('part-notice', rcube_label('messagetoobig'). ' ' 
    10121016            . html::a('?_task=mail&_action=get&_download=1&_uid='.$MESSAGE->uid.'&_part='.$part->mime_id 
    1013               .'&_mbox='. urlencode($RCMAIL->imap->get_mailbox_name()), rcube_label('download'))); 
     1017              .'&_mbox='. urlencode($RCMAIL->storage->get_folder()), rcube_label('download'))); 
    10141018          continue; 
    10151019        } 
     
    10571061      $out .= html::span('part-notice', rcube_label('messagetoobig'). ' ' 
    10581062        . html::a('?_task=mail&_action=get&_download=1&_uid='.$MESSAGE->uid.'&_part=0' 
    1059           .'&_mbox='. urlencode($RCMAIL->imap->get_mailbox_name()), rcube_label('download'))); 
     1063          .'&_mbox='. urlencode($RCMAIL->storage->get_folder()), rcube_label('download'))); 
    10601064    } 
    10611065    else { 
     
    14781482 
    14791483  if ($message->headers->mdn_to && empty($message->headers->flags['MDNSENT']) && 
    1480     ($RCMAIL->imap->check_permflag('MDNSENT') || $RCMAIL->imap->check_permflag('*'))) 
     1484    ($RCMAIL->storage->check_permflag('MDNSENT') || $RCMAIL->storage->check_permflag('*'))) 
    14811485  { 
    14821486    $identity = $RCMAIL->user->get_identity(); 
     
    15341538    if ($sent) 
    15351539    { 
    1536       $RCMAIL->imap->set_flag($message->uid, 'MDNSENT'); 
     1540      $RCMAIL->storage->set_flag($message->uid, 'MDNSENT'); 
    15371541      return true; 
    15381542    } 
     
    15971601  // Set env variables for messageerror.html template 
    15981602  if ($RCMAIL->action == 'show') { 
    1599     $mbox_name = $RCMAIL->imap->get_mailbox_name(); 
     1603    $mbox_name = $RCMAIL->storage->get_folder(); 
    16001604    $RCMAIL->output->set_env('mailbox', $mbox_name); 
    16011605    $RCMAIL->output->set_env('uid', null); 
  • branches/devel-framework/roundcubemail/program/steps/mail/get.inc

    r5633 r5758  
    3737 
    3838// Now we need IMAP connection 
    39 if (!$RCMAIL->imap_connect()) { 
     39if (!$RCMAIL->storage_connect()) { 
    4040  // Get action is often executed simultanously. 
    4141  // Some servers have MAXPERIP or other limits. 
     
    118118        $out = '<body>' . rcube_label('messagetoobig'). ' ' 
    119119          . html::a('?_task=mail&_action=get&_download=1&_uid='.$MESSAGE->uid.'&_part='.$part->mime_id 
    120             .'&_mbox='. urlencode($RCMAIL->imap->get_mailbox_name()), rcube_label('download')) . '</body></html>'; 
     120            .'&_mbox='. urlencode($RCMAIL->storage->get_folder()), rcube_label('download')) . '</body></html>'; 
    121121      } 
    122122      else { 
     
    158158          stream_filter_register('rcube_content', 'rcube_content_filter') or die('Failed to register content filter'); 
    159159          stream_filter_append($stdout, 'rcube_content'); 
    160           $RCMAIL->imap->get_message_part($MESSAGE->uid, $part->mime_id, $part, false, $stdout); 
     160          $RCMAIL->storage->get_message_part($MESSAGE->uid, $part->mime_id, $part, false, $stdout); 
    161161        } 
    162162      } 
     
    166166          echo $part->body; 
    167167        else if ($part->size) 
    168           $RCMAIL->imap->get_message_part($MESSAGE->uid, $part->mime_id, $part, true); 
     168          $RCMAIL->storage->get_message_part($MESSAGE->uid, $part->mime_id, $part, true); 
    169169      } 
    170170    } 
  • branches/devel-framework/roundcubemail/program/steps/mail/getunread.inc

    r5563 r5758  
    2020*/ 
    2121 
    22 $a_folders = $RCMAIL->imap->list_mailboxes('', '*', 'mail'); 
     22$a_folders = $RCMAIL->storage->list_folders_subscribed('', '*', 'mail'); 
    2323 
    2424if (!empty($a_folders)) 
    2525{ 
    26   $current = $RCMAIL->imap->get_mailbox_name(); 
     26  $current = $RCMAIL->storage->get_folder(); 
    2727  $inbox = ($current == 'INBOX'); 
    2828  $check_all = (bool)$RCMAIL->config->get('check_all_folders'); 
     
    3434      $unseen = $unseen_old; 
    3535    else 
    36       $unseen = $RCMAIL->imap->messagecount($mbox_row, 'UNSEEN', $unseen_old === null); 
     36      $unseen = $RCMAIL->storage->count($mbox_row, 'UNSEEN', $unseen_old === null); 
    3737 
    3838    if ($unseen || $unseen_old === null) { 
  • branches/devel-framework/roundcubemail/program/steps/mail/headers.inc

    r5563 r5758  
    2121if ($uid = get_input_value('_uid', RCUBE_INPUT_POST)) 
    2222{ 
    23     $source = $RCMAIL->imap->get_raw_headers($uid); 
     23    $source = $RCMAIL->storage->get_raw_headers($uid); 
    2424 
    2525    if ($source !== false) { 
  • branches/devel-framework/roundcubemail/program/steps/mail/list.inc

    r5563 r5758  
    5252  $RCMAIL->user->save_prefs($save_arr); 
    5353 
    54 $mbox_name = $RCMAIL->imap->get_mailbox_name(); 
     54$mbox_name = $RCMAIL->storage->get_folder(); 
     55$threading = (bool) $RCMAIL->storage->get_threading(); 
    5556 
    5657// Synchronize mailbox cache, handle flag changes 
    57 $RCMAIL->imap->mailbox_sync($mbox_name); 
     58$RCMAIL->storage->folder_sync($mbox_name); 
    5859 
    5960// initialize searching result if search_filter is used 
     
    6162{ 
    6263  $search_request = md5($mbox_name.$_SESSION['search_filter']); 
    63   $RCMAIL->imap->search($mbox_name, $_SESSION['search_filter'], RCMAIL_CHARSET, $sort_col); 
    64   $_SESSION['search'] = $RCMAIL->imap->get_search_set(); 
     64  $RCMAIL->storage->search($mbox_name, $_SESSION['search_filter'], RCMAIL_CHARSET, $sort_col); 
     65  $_SESSION['search'] = $RCMAIL->storage->get_search_set(); 
    6566  $_SESSION['search_request'] = $search_request; 
    6667  $OUTPUT->set_env('search_request', $search_request); 
     
    6869 
    6970// fetch message headers 
    70 if ($count = $RCMAIL->imap->messagecount($mbox_name, $RCMAIL->imap->threading ? 'THREADS' : 'ALL', !empty($_REQUEST['_refresh']))) 
    71   $a_headers = $RCMAIL->imap->list_headers($mbox_name, NULL, $sort_col, $sort_order); 
     71if ($count = $RCMAIL->storage->count($mbox_name, $threading ? 'THREADS' : 'ALL', !empty($_REQUEST['_refresh']))) 
     72  $a_headers = $RCMAIL->storage->list_messages($mbox_name, NULL, $sort_col, $sort_order); 
    7273 
    7374// update search set (possible change of threading mode) 
     
    7576    && $_SESSION['search_request'] == $_REQUEST['_search'] 
    7677) { 
    77   $_SESSION['search'] = $RCMAIL->imap->get_search_set(); 
     78  $_SESSION['search'] = $RCMAIL->storage->get_search_set(); 
    7879} 
    7980// remove old search data 
     
    9293 
    9394// update message count display 
    94 $pages = ceil($count/$RCMAIL->imap->page_size); 
     95$pages = ceil($count/$RCMAIL->storage->get_pagesize()); 
    9596$OUTPUT->set_env('messagecount', $count); 
    9697$OUTPUT->set_env('pagecount', $pages); 
    97 $OUTPUT->set_env('threading', (bool) $RCMAIL->imap->threading); 
    98 $OUTPUT->set_env('current_page', $count ? $RCMAIL->imap->list_page : 1); 
     98$OUTPUT->set_env('threading', $threading); 
     99$OUTPUT->set_env('current_page', $count ? $RCMAIL->storage->get_page() : 1); 
    99100$OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($count), $mbox_name); 
    100101$OUTPUT->command('set_mailboxname', rcmail_get_mailbox_name_text()); 
     
    109110else { 
    110111  // handle IMAP errors (e.g. #1486905) 
    111   if ($err_code = $RCMAIL->imap->get_error_code()) { 
     112  if ($err_code = $RCMAIL->storage->get_error_code()) { 
    112113    rcmail_display_server_error(); 
    113114  } 
  • branches/devel-framework/roundcubemail/program/steps/mail/mark.inc

    r5563 r5758  
    3131  'unflagged' => 'UNFLAGGED'); 
    3232 
     33$threading = (bool) $RCMAIL->storage->get_threading(); 
     34 
    3335if (($uids = get_input_value('_uid', RCUBE_INPUT_POST)) && ($flag = get_input_value('_flag', RCUBE_INPUT_POST))) 
    3436{ 
     
    3739  if ($flag == 'DELETED' && $CONFIG['skip_deleted'] && $_POST['_from'] != 'show') { 
    3840    // count messages before changing anything 
    39     $old_count = $RCMAIL->imap->messagecount(NULL, $RCMAIL->imap->threading ? 'THREADS' : 'ALL'); 
    40     $old_pages = ceil($old_count / $RCMAIL->imap->page_size); 
     41    $old_count = $RCMAIL->storage->count(NULL, $threading ? 'THREADS' : 'ALL'); 
     42    $old_pages = ceil($old_count / $RCMAIL->storage->get_pagesize()); 
    4143    $count = sizeof(explode(',', $uids)); 
    4244  } 
    4345 
    44   $marked = $RCMAIL->imap->set_flag($uids, $flag); 
     46  $marked = $RCMAIL->storage->set_flag($uids, $flag); 
    4547 
    4648  if (!$marked) { 
     
    5860  if ($flag == 'DELETED' && $CONFIG['read_when_deleted'] && !empty($_POST['_ruid'])) { 
    5961    $ruids = get_input_value('_ruid', RCUBE_INPUT_POST); 
    60     $read = $RCMAIL->imap->set_flag($ruids, 'SEEN'); 
     62    $read = $RCMAIL->storage->set_flag($ruids, 'SEEN'); 
    6163 
    6264    if ($read && !$CONFIG['skip_deleted']) 
     
    6567 
    6668  if ($flag == 'SEEN' || $flag == 'UNSEEN' || ($flag == 'DELETED' && !$CONFIG['skip_deleted'])) { 
    67     rcmail_send_unread_count($RCMAIL->imap->get_mailbox_name()); 
     69    rcmail_send_unread_count($RCMAIL->storage->get_folder()); 
    6870  } 
    6971  else if ($flag == 'DELETED' && $CONFIG['skip_deleted']) { 
     
    7476        $OUTPUT->command('command', 'list'); 
    7577    } else { 
     78      $search_request = get_input_value('_search', RCUBE_INPUT_GPC); 
    7679      // refresh saved search set after moving some messages 
    77       if (($search_request = get_input_value('_search', RCUBE_INPUT_GPC)) && $RCMAIL->imap->search_set) { 
    78         $_SESSION['search'] = $RCMAIL->imap->refresh_search(); 
     80      if ($search_request && $RCMAIL->storage->get_search_set()) { 
     81        $_SESSION['search'] = $RCMAIL->storage->refresh_search(); 
    7982      } 
    8083 
    81       $msg_count      = $RCMAIL->imap->messagecount(NULL, $RCMAIL->imap->threading ? 'THREADS' : 'ALL'); 
    82       $pages          = ceil($msg_count / $RCMAIL->imap->page_size); 
    83       $nextpage_count = $old_count - $RCMAIL->imap->page_size * $RCMAIL->imap->list_page; 
    84       $remaining      = $msg_count - $RCMAIL->imap->page_size * ($RCMAIL->imap->list_page - 1); 
     84      $msg_count      = $RCMAIL->storage->count(NULL, $threading ? 'THREADS' : 'ALL'); 
     85      $page_size      = $RCMAIL->storage->get_pagesize(); 
     86      $page           = $RCMAIL->storage->get_page(); 
     87      $pages          = ceil($msg_count / $page_size); 
     88      $nextpage_count = $old_count - $page_size * $page; 
     89      $remaining      = $msg_count - $page_size * ($page - 1); 
    8590 
    8691      // jump back one page (user removed the whole last page) 
    87       if ($RCMAIL->imap->list_page > 1 && $remaining == 0) { 
    88         $RCMAIL->imap->set_page($RCMAIL->imap->list_page-1); 
    89         $_SESSION['page'] = $RCMAIL->imap->list_page; 
     92      if ($page > 1 && $remaining == 0) { 
     93        $page -= 1; 
     94        $RCMAIL->storage->set_page($page); 
     95        $_SESSION['page'] = $page; 
    9096        $jump_back = true; 
    9197      } 
     
    9399      // update message count display 
    94100      $OUTPUT->set_env('messagecount', $msg_count); 
    95       $OUTPUT->set_env('current_page', $RCMAIL->imap->list_page); 
     101      $OUTPUT->set_env('current_page', $page); 
    96102      $OUTPUT->set_env('pagecount', $pages); 
    97103 
    98104      // update mailboxlist 
    99       $mbox = $RCMAIL->imap->get_mailbox_name(); 
    100       $unseen_count = $msg_count ? $RCMAIL->imap->messagecount($mbox, 'UNSEEN') : 0; 
     105      $mbox = $RCMAIL->storage->get_folder(); 
     106      $unseen_count = $msg_count ? $RCMAIL->storage->count($mbox, 'UNSEEN') : 0; 
    101107      $old_unseen = rcmail_get_unseen_count($mbox); 
    102108 
     
    107113      $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($msg_count), $mbox); 
    108114 
    109       if ($RCMAIL->imap->threading) 
     115      if ($threading) { 
    110116            $count = get_input_value('_count', RCUBE_INPUT_POST); 
     117      } 
    111118 
    112119      // add new rows from next page (if any) 
     
    115122        $sort_order = isset($_SESSION['sort_order']) ? $_SESSION['sort_order'] : $CONFIG['message_sort_order']; 
    116123 
    117         $a_headers = $RCMAIL->imap->list_headers($mbox, NULL, $sort_col, $sort_order, 
     124        $a_headers = $RCMAIL->storage->list_messages($mbox, NULL, $sort_col, $sort_order, 
    118125            $jump_back ? NULL : $count); 
    119126 
  • branches/devel-framework/roundcubemail/program/steps/mail/move_del.inc

    r5563 r5758  
    2525 
    2626// count messages before changing anything 
    27 $old_count = $RCMAIL->imap->messagecount(NULL, $RCMAIL->imap->threading ? 'THREADS' : 'ALL'); 
    28 $old_pages = ceil($old_count / $RCMAIL->imap->page_size); 
     27$threading = (bool) $RCMAIL->storage->get_threading(); 
     28$old_count = $RCMAIL->storage->count(NULL, $threading ? 'THREADS' : 'ALL'); 
     29$old_pages = ceil($old_count / $RCMAIL->storage->get_pagesize()); 
    2930 
    3031// move messages 
     
    3435    $mbox = get_input_value('_mbox', RCUBE_INPUT_POST, true); 
    3536 
    36     $moved = $RCMAIL->imap->move_message($uids, $target, $mbox); 
     37    $moved = $RCMAIL->storage->move_message($uids, $target, $mbox); 
    3738 
    3839    if (!$moved) { 
     
    5556    $mbox = get_input_value('_mbox', RCUBE_INPUT_POST, true); 
    5657 
    57     $del = $RCMAIL->imap->delete_message($uids, $mbox); 
     58    $del = $RCMAIL->storage->delete_message($uids, $mbox); 
    5859 
    5960    if (!$del) { 
     
    7677} 
    7778 
     79$search_request = get_input_value('_search', RCUBE_INPUT_GPC); 
     80 
    7881// refresh saved search set after moving some messages 
    79 if (($search_request = get_input_value('_search', RCUBE_INPUT_GPC)) && $RCMAIL->imap->search_set) { 
    80     $_SESSION['search'] = $RCMAIL->imap->refresh_search(); 
     82if ($search_request && $RCMAIL->storage->get_search_set()) { 
     83    $_SESSION['search'] = $RCMAIL->storage->refresh_search(); 
    8184} 
    8285 
     
    9093else 
    9194{ 
    92   $msg_count      = $RCMAIL->imap->messagecount(NULL, $RCMAIL->imap->threading ? 'THREADS' : 'ALL'); 
    93   $pages          = ceil($msg_count / $RCMAIL->imap->page_size); 
    94   $nextpage_count = $old_count - $RCMAIL->imap->page_size * $RCMAIL->imap->list_page; 
    95   $remaining      = $msg_count - $RCMAIL->imap->page_size * ($RCMAIL->imap->list_page - 1); 
     95  $msg_count      = $RCMAIL->storage->count(NULL, $threading ? 'THREADS' : 'ALL'); 
     96  $page_size      = $RCMAIL->storage->get_pagesize(); 
     97  $page           = $RCMAIL->storage->get_page(); 
     98  $pages          = ceil($msg_count / $page_size); 
     99  $nextpage_count = $old_count - $page_size * $page; 
     100  $remaining      = $msg_count - $page_size * ($page - 1); 
    96101 
    97102  // jump back one page (user removed the whole last page) 
    98   if ($RCMAIL->imap->list_page > 1 && $remaining == 0) { 
    99     $RCMAIL->imap->set_page($RCMAIL->imap->list_page-1); 
    100     $_SESSION['page'] = $RCMAIL->imap->list_page; 
     103  if ($page > 1 && $remaining == 0) { 
     104    $page -= 1; 
     105    $RCMAIL->storage->set_page($page); 
     106    $_SESSION['page'] = $page; 
    101107    $jump_back = true; 
    102108  } 
     
    104110  // update message count display 
    105111  $OUTPUT->set_env('messagecount', $msg_count); 
    106   $OUTPUT->set_env('current_page', $RCMAIL->imap->list_page); 
     112  $OUTPUT->set_env('current_page', $page); 
    107113  $OUTPUT->set_env('pagecount', $pages); 
    108114 
    109115  // update mailboxlist 
    110   $mbox = $RCMAIL->imap->get_mailbox_name(); 
    111   $unseen_count = $msg_count ? $RCMAIL->imap->messagecount($mbox, 'UNSEEN') : 0; 
     116  $mbox = $RCMAIL->storage->get_folder(); 
     117  $unseen_count = $msg_count ? $RCMAIL->storage->count($mbox, 'UNSEEN') : 0; 
    112118  $old_unseen = rcmail_get_unseen_count($mbox); 
    113119 
     
    124130  $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($msg_count), $mbox); 
    125131 
    126   if ($RCMAIL->imap->threading) 
     132  if ($threading) { 
    127133    $count = get_input_value('_count', RCUBE_INPUT_POST); 
     134  } 
    128135 
    129136  // add new rows from next page (if any) 
     
    132139    $sort_order = isset($_SESSION['sort_order']) ? $_SESSION['sort_order'] : $CONFIG['message_sort_order']; 
    133140 
    134     $a_headers = $RCMAIL->imap->list_headers($mbox, NULL, $sort_col, $sort_order, 
     141    $a_headers = $RCMAIL->storage->list_messages($mbox, NULL, $sort_col, $sort_order, 
    135142      $jump_back ? NULL : $count); 
    136143 
  • branches/devel-framework/roundcubemail/program/steps/mail/pagenav.inc

    r5563 r5758  
    2121 
    2222$uid   = get_input_value('_uid', RCUBE_INPUT_GET); 
    23 $index = $RCMAIL->imap->message_index(null, $_SESSION['sort_col'], $_SESSION['sort_order']); 
     23$index = $RCMAIL->storage->index(null, $_SESSION['sort_col'], $_SESSION['sort_order']); 
    2424$cnt   = $index->countMessages(); 
    2525 
  • branches/devel-framework/roundcubemail/program/steps/mail/search.inc

    r5563 r5758  
    1919 
    2020// reset list_page and old search results 
    21 $RCMAIL->imap->set_page(1); 
    22 $RCMAIL->imap->set_search_set(NULL); 
     21$RCMAIL->storage->set_page(1); 
     22$RCMAIL->storage->set_search_set(NULL); 
    2323$_SESSION['page'] = 1; 
    2424 
     
    108108// execute IMAP search 
    109109if ($search_str) 
    110   $RCMAIL->imap->search($mbox, $search_str, $imap_charset, $_SESSION['sort_col']); 
     110  $RCMAIL->storage->search($mbox, $search_str, $imap_charset, $_SESSION['sort_col']); 
    111111 
    112112// save search results in session 
     
    115115 
    116116if ($search_str) { 
    117   $_SESSION['search'] = $RCMAIL->imap->get_search_set(); 
     117  $_SESSION['search'] = $RCMAIL->storage->get_search_set(); 
    118118  $_SESSION['last_text_search'] = $str; 
    119119} 
     
    122122 
    123123// Get the headers 
    124 $result_h = $RCMAIL->imap->list_headers($mbox, 1, $_SESSION['sort_col'], $_SESSION['sort_order']); 
    125 $count = $RCMAIL->imap->messagecount($mbox, $RCMAIL->imap->threading ? 'THREADS' : 'ALL'); 
     124$result_h = $RCMAIL->storage->list_messages($mbox, 1, $_SESSION['sort_col'], $_SESSION['sort_order']); 
     125$count = $RCMAIL->storage->count($mbox, $RCMAIL->storage->get_threading() ? 'THREADS' : 'ALL'); 
    126126 
    127127 
     
    130130  rcmail_js_message_list($result_h); 
    131131  if ($search_str) 
    132     $OUTPUT->show_message('searchsuccessful', 'confirmation', array('nr' => $RCMAIL->imap->messagecount(NULL, 'ALL'))); 
     132    $OUTPUT->show_message('searchsuccessful', 'confirmation', array('nr' => $RCMAIL->storage->count(NULL, 'ALL'))); 
    133133} 
    134134// handle IMAP errors (e.g. #1486905) 
    135 else  if ($err_code = $RCMAIL->imap->get_error_code()) { 
     135else  if ($err_code = $RCMAIL->storage->get_error_code()) { 
    136136  rcmail_display_server_error(); 
    137137} 
     
    143143$OUTPUT->set_env('search_request', $search_str ? $search_request : ''); 
    144144$OUTPUT->set_env('messagecount', $count); 
    145 $OUTPUT->set_env('pagecount', ceil($count/$RCMAIL->imap->page_size)); 
     145$OUTPUT->set_env('pagecount', ceil($count/$RCMAIL->storage->get_pagesize())); 
    146146$OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($count, 1), $mbox); 
    147147$OUTPUT->send(); 
    148  
    149  
  • branches/devel-framework/roundcubemail/program/steps/mail/sendmail.inc

    r5716 r5758  
    635635  // set replied/forwarded flag 
    636636  if ($COMPOSE['reply_uid']) 
    637     $RCMAIL->imap->set_flag($COMPOSE['reply_uid'], 'ANSWERED', $COMPOSE['mailbox']); 
     637    $RCMAIL->storage->set_flag($COMPOSE['reply_uid'], 'ANSWERED', $COMPOSE['mailbox']); 
    638638  else if ($COMPOSE['forward_uid']) 
    639     $RCMAIL->imap->set_flag($COMPOSE['forward_uid'], 'FORWARDED', $COMPOSE['mailbox']); 
     639    $RCMAIL->storage->set_flag($COMPOSE['forward_uid'], 'FORWARDED', $COMPOSE['mailbox']); 
    640640 
    641641} // End of SMTP Delivery Block 
     
    650650if ($store_target) { 
    651651  // check if folder is subscribed 
    652   if ($RCMAIL->imap->mailbox_exists($store_target, true)) 
     652  if ($RCMAIL->storage->folder_exists($store_target, true)) 
    653653    $store_folder = true; 
    654654  // folder may be existing but not subscribed (#1485241) 
    655   else if (!$RCMAIL->imap->mailbox_exists($store_target)) 
    656     $store_folder = $RCMAIL->imap->create_mailbox($store_target, true); 
    657   else if ($RCMAIL->imap->subscribe($store_target)) 
     655  else if (!$RCMAIL->storage->folder_exists($store_target)) 
     656    $store_folder = $RCMAIL->storage->create_folder($store_target, true); 
     657  else if ($RCMAIL->storage->subscribe($store_target)) 
    658658    $store_folder = true; 
    659659 
     
    685685            TRUE, FALSE); 
    686686    else { 
    687       $saved = $RCMAIL->imap->save_message($store_target, $msg, $headers, $mailbody_file ? true : false); 
     687      $saved = $RCMAIL->storage->save_message($store_target, $msg, $headers, $mailbody_file ? true : false); 
    688688    } 
    689689 
     
    709709    // delete previous saved draft 
    710710    // @TODO: use message UID (remember to check UIDVALIDITY) to skip this SEARCH