alecpl
2011-12-07 b6da0b76afb5697685c35b8584631294cfc7b12f
program/steps/settings/folders.inc
@@ -30,13 +30,13 @@
{
    $mbox = get_input_value('_mbox', RCUBE_INPUT_POST, true, 'UTF7-IMAP');
    if (strlen($mbox)) {
        $result = $IMAP->subscribe(array($mbox));
        $result = $RCMAIL->imap->subscribe(array($mbox));
        // Handle virtual (non-existing) folders
        if (!$result && $IMAP->get_error_code() == -1 &&
            $IMAP->get_response_code() == rcube_imap::TRYCREATE
        if (!$result && $RCMAIL->imap->get_error_code() == -1 &&
            $RCMAIL->imap->get_response_code() == rcube_imap::TRYCREATE
        ) {
            $result = $IMAP->create_mailbox($mbox, true);
            $result = $RCMAIL->imap->create_mailbox($mbox, true);
            if ($result) {
                // @TODO: remove 'virtual' class of folder's row
            }
@@ -62,7 +62,7 @@
{
    $mbox = get_input_value('_mbox', RCUBE_INPUT_POST, true, 'UTF7-IMAP');
    if (strlen($mbox)) {
        $result = $IMAP->unsubscribe(array($mbox));
        $result = $RCMAIL->imap->unsubscribe(array($mbox));
        if ($result)
            $OUTPUT->show_message('folderunsubscribed', 'confirmation');
        else
@@ -76,8 +76,16 @@
    $mbox_utf8 = get_input_value('_mbox', RCUBE_INPUT_POST, true);
    $mbox      = rcube_charset_convert($mbox_utf8, RCMAIL_CHARSET, 'UTF7-IMAP');
    if (strlen($mbox))
        $deleted = $IMAP->delete_mailbox($mbox);
    if (strlen($mbox)) {
        $plugin = $RCMAIL->plugins->exec_hook('folder_delete', array('name' => $mbox));
        if (!$plugin['abort']) {
            $deleted = $RCMAIL->imap->delete_mailbox($plugin['name']);
        }
        else {
            $deleted = $plugin['result'];
        }
    }
    if ($OUTPUT->ajax_call && $deleted) {
        // Remove folder and subfolders rows
@@ -118,19 +126,19 @@
{
    $mbox_utf8 = get_input_value('_mbox', RCUBE_INPUT_POST, true);
    $mbox      = rcube_charset_convert($mbox_utf8, RCMAIL_CHARSET, 'UTF7-IMAP');
    $delimiter = $IMAP->get_hierarchy_delimiter();
    $delimiter = $RCMAIL->imap->get_hierarchy_delimiter();
    $trash_regexp = '/^' . preg_quote($CONFIG['trash_mbox'] . $delimiter, '/') . '/';
    // we should only be purging trash (or their subfolders)
    if (!strlen($CONFIG['trash_mbox']) || $mbox == $CONFIG['trash_mbox']
        || preg_match($trash_regexp, $mbox)
    ) {
        $success = $IMAP->clear_mailbox($mbox);
        $success = $RCMAIL->imap->clear_mailbox($mbox);
        $delete = true;
    }
    // copy to Trash
    else {
        $success = $IMAP->move_message('1:*', $CONFIG['trash_mbox'], $mbox);
        $success = $RCMAIL->imap->move_message('1:*', $CONFIG['trash_mbox'], $mbox);
        $delete = false;
    }
@@ -156,7 +164,7 @@
{
    $name = trim(get_input_value('_mbox', RCUBE_INPUT_POST, true));
    $size = $IMAP->get_mailbox_size($name);
    $size = $RCMAIL->imap->get_mailbox_size($name);
    // @TODO: check quota and show percentage usage of specified mailbox?
@@ -175,7 +183,7 @@
// build table with all folders listed by server
function rcube_subscription_form($attrib)
{
    global $RCMAIL, $IMAP, $CONFIG, $OUTPUT;
    global $RCMAIL, $CONFIG, $OUTPUT;
    list($form_start, $form_end) = get_form_tags($attrib, 'folders');
    unset($attrib['form']);
@@ -192,12 +200,12 @@
    }
    // get folders from server
    $IMAP->clear_cache('mailboxes', true);
    $RCMAIL->imap->clear_cache('mailboxes', true);
    $a_unsubscribed = $IMAP->list_unsubscribed();
    $a_subscribed   = $IMAP->list_mailboxes();
    $delimiter      = $IMAP->get_hierarchy_delimiter();
    $namespace      = $IMAP->get_namespace();
    $a_unsubscribed = $RCMAIL->imap->list_unsubscribed();
    $a_subscribed   = $RCMAIL->imap->list_mailboxes('', '*', null, null, true); // unsorted
    $delimiter      = $RCMAIL->imap->get_hierarchy_delimiter();
    $namespace      = $RCMAIL->imap->get_namespace();
    $a_js_folders   = array();
    $seen           = array();
    $list_folders   = array();
@@ -205,7 +213,7 @@
    // pre-process folders list
    foreach ($a_unsubscribed as $i => $folder) {
        $folder_id     = $folder;
        $folder        = $IMAP->mod_mailbox($folder);
        $folder        = $RCMAIL->imap->mod_mailbox($folder);
        $foldersplit   = explode($delimiter, $folder);
        $name          = rcube_charset_convert(array_pop($foldersplit), 'UTF7-IMAP');
        $parent_folder = join($delimiter, $foldersplit);
@@ -243,6 +251,13 @@
    unset($seen);
    // add drop-target representing 'root'
    $table->add_row(array('id' => 'mailboxroot', 'class' => 'virtual root'));
    $table->add('name', ' ');
    $table->add(null, ' ');
    $a_js_folders['mailboxroot'] = array('', '', true);
    $checkbox_subscribe = new html_checkbox(array(
        'name'    => '_subscribed[]',
        'title'   => rcube_label('changesubscription'),
@@ -252,7 +267,8 @@
    // create list of available folders
    foreach ($list_folders as $i => $folder) {
        $idx        = $i + 1;
        $subscribed = in_array($folder['id'], $a_subscribed);
        $sub_key    = array_search($folder['id'], $a_subscribed);
        $subscribed = $sub_key !== false;
        $protected  = ($CONFIG['protect_default_folders'] == true && in_array($folder['id'], $CONFIG['default_imap_folders']));
        $noselect   = false;
        $classes    = array($i%2 ? 'even' : 'odd');
@@ -267,8 +283,8 @@
        }
        if (!$protected) {
            $opts = $IMAP->mailbox_options($folder['id']);
            $noselect = in_array('\\Noselect', $opts);
            $attrs = $RCMAIL->imap->mailbox_attributes($folder['id']);
            $noselect = in_array('\\Noselect', $attrs);
        }
        $disabled = (($protected && $subscribed) || $noselect);
@@ -293,6 +309,16 @@
            $fname = $parts[0] . $delimiter;
            foreach ($namespace['other'] as $item) {
                if ($item[0] === $fname) {
                    $disabled = true;
                    break;
                }
            }
        }
        // check if the folder is shared, then disable subscription option on it
        if (!$disabled && $folder['virtual'] && !empty($namespace)) {
            $tmp_ns = array_merge((array)$namespace['other'], (array)$namespace['shared']);
            foreach ($tmp_ns as $item) {
                if (strpos($folder['id'], $item[0]) === 0) {
                    $disabled = true;
                    break;
                }
@@ -340,10 +366,19 @@
    global $RCMAIL;
    $delimiter = $RCMAIL->imap->get_hierarchy_delimiter();
    $rename    = $RCMAIL->imap->rename_mailbox($oldname, $newname);
    $plugin = $RCMAIL->plugins->exec_hook('folder_rename', array(
        'oldname' => $oldname, 'newname' => $newname));
    if (!$plugin['abort']) {
        $renamed =  $RCMAIL->imap->rename_mailbox($oldname, $newname);
    }
    else {
        $renamed = $plugin['result'];
    }
    // update per-folder options for modified folder and its subfolders
    if ($rename !== false) {
    if ($renamed) {
        $a_threaded = (array) $RCMAIL->config->get('message_threading', array());
        $oldprefix  = '/^' . preg_quote($oldname . $delimiter, '/') . '/';
@@ -368,7 +403,7 @@
$OUTPUT->set_pagetitle(rcube_label('folders'));
$OUTPUT->include_script('list.js');
$OUTPUT->set_env('quota', $IMAP->get_capability('QUOTA'));
$OUTPUT->set_env('quota', $RCMAIL->imap->get_capability('QUOTA'));
// add some labels to client
$OUTPUT->add_label('deletefolderconfirm', 'purgefolderconfirm', 'folderdeleting',