Aleksander Machniak
2014-04-01 dc0b500e78aae13349b848303302a213ed3a1e65
plugins/archive/archive.php
@@ -6,22 +6,22 @@
 * Plugin that adds a new button to the mailbox toolbar
 * to move messages to a (user selectable) archive folder.
 *
 * @version 2.0
 * @version 2.2
 * @license GNU GPLv3+
 * @author Andre Rodier, Thomas Bruederli
 * @author Andre Rodier, Thomas Bruederli, Aleksander Machniak
 */
class archive extends rcube_plugin
{
  public $task = 'mail|settings';
  function init()
  {
    $rcmail = rcmail::get_instance();
    // There is no "Archived flags"
    // $GLOBALS['IMAP_FLAGS']['ARCHIVED'] = 'Archive';
    // register special folder type
    rcube_storage::$folder_types[] = 'archive';
    if ($rcmail->task == 'mail' && ($rcmail->action == '' || $rcmail->action == 'show')
        && ($archive_folder = $rcmail->config->get('archive_mbox'))) {
        && ($archive_folder = $rcmail->config->get('archive_mbox'))
    ) {
      $skin_path = $this->local_skin_path();
      if (is_file($this->home . "/$skin_path/archive.css"))
        $this->include_stylesheet("$skin_path/archive.css");
@@ -48,12 +48,6 @@
      // set env variables for client
      $rcmail->output->set_env('archive_folder', $archive_folder);
      $rcmail->output->set_env('archive_type', $rcmail->config->get('archive_type',''));
      // add archive folder to the list of default mailboxes
      if (($default_folders = $rcmail->config->get('default_folders')) && !in_array($archive_folder, $default_folders)) {
        $default_folders[] = $archive_folder;
        $rcmail->config->set('default_folders', $default_folders);
      }
    }
    else if ($rcmail->task == 'mail') {
      // handler for ajax request
@@ -99,7 +93,7 @@
        return true;
      } else if (!empty($item['folders']))
        if ($this->_mod_folder_name($list[$idx]['folders'], $folder, $new_name))
        return true;
          return true;
    }
    return false;
  }
@@ -121,8 +115,17 @@
    $storage->set_folder(($current_mbox = rcube_utils::get_input_value('_mbox', RCUBE_INPUT_POST)));
    $result  = array('reload' => false, 'update' => false, 'errors' => array());
    $uids    = explode(',', rcube_utils::get_input_value('_uid', RCUBE_INPUT_POST));
    $folders = array();
    $uids    = rcube_utils::get_input_value('_uid', RCUBE_INPUT_POST);
    $search_request = get_input_value('_search', RCUBE_INPUT_GPC);
    if ($uids == '*') {
      $index = $storage->index(null, rcmail_sort_column(), rcmail_sort_order());
      $uids  = $index->get();
    }
    else {
      $uids = explode(',', $uids);
    }
    foreach ($uids as $uid) {
      if (!$archive_folder || !($message = $rcmail->storage->get_message($uid))) {
@@ -208,6 +211,11 @@
      $rcmail->output->show_message($this->gettext('archived'), 'confirmation');
    }
    // refresh saved search set after moving some messages
    if ($search_request && $rcmail->storage->get_search_set()) {
        $_SESSION['search'] = $rcmail->storage->refresh_search();
    }
    if ($_POST['_from'] == 'show' && !empty($result['update'])) {
      if ($next = get_input_value('_next_uid', RCUBE_INPUT_GPC)) {
        $rcmail->output->command('show_message', $next);
@@ -254,7 +262,7 @@
      $archive_type->add($this->gettext('archivetypefolder'), 'folder');
      $args['blocks']['archive'] = array(
        'name' => Q(rcube_label('settingstitle', 'archive')),
        'name' => Q($this->gettext('settingstitle')),
        'options' => array('archive_type' => array(
            'title' => $this->gettext('archivetype'),
            'content' => $archive_type->show($rcmail->config->get('archive_type'))
@@ -272,7 +280,6 @@
  function save_prefs($args)
  {
    if ($args['section'] == 'folders') {
      $args['prefs']['archive_mbox'] = rcube_utils::get_input_value('_archive_mbox', rcube_utils::INPUT_POST);
      $args['prefs']['archive_type'] = rcube_utils::get_input_value('_archive_type', rcube_utils::INPUT_POST);
      return $args;
    }