6 * A plugin which can enable or disable the use of imap subscriptions.
7 * It includes a toggle on the settings page under "Server Settings".
8 * The preference can also be locked
10 * Add it to the plugins list in config/main.inc.php to enable the user option
11 * The user option can be hidden and set globally by adding 'use_subscriptions'
12 * to the the 'dont_override' configure line:
13 * $rcmail_config['dont_override'] = array('use_subscriptions');
14 * and then set the global preference
15 * $rcmail_config['use_subscriptions'] = true; // or false
17 * Roundcube caches folder lists. When a user changes this option or visits
18 * their folder list, this cache is refreshed. If the option is on the
19 * 'dont_override' list and the global option has changed, don't expect
20 * to see the change until the folder list cache is refreshed.
25 class subscriptions_option extends rcube_plugin
27 public $task = 'mail|settings';
31 $this->add_texts('localization/', false);
32 $dont_override = rcmail::get_instance()->config->get('dont_override', array());
33 if (!in_array('use_subscriptions', $dont_override)) {
34 $this->add_hook('user_preferences', array($this, 'settings_blocks'));
35 $this->add_hook('save_preferences', array($this, 'save_prefs'));
37 $this->add_hook('list_mailboxes', array($this, 'list_mailboxes'));
38 $this->add_hook('manage_folders', array($this, 'manage_folders'));
41 function settings_blocks($args)
43 if ($args['section'] == 'server') {
44 $use_subscriptions = rcmail::get_instance()->config->get('use_subscriptions');
45 $field_id = 'rcmfd_use_subscriptions';
46 $checkbox = new html_checkbox(array('name' => '_use_subscriptions', 'id' => $field_id, 'value' => 1));
48 $args['blocks']['main']['options']['use_subscriptions'] = array(
49 'title' => html::label($field_id, Q($this->gettext('useimapsubscriptions'))),
50 'content' => $checkbox->show($use_subscriptions?1:0),
57 function save_prefs($args)
59 if ($args['section'] == 'server') {
60 $rcmail = rcmail::get_instance();
61 $use_subscriptions = $rcmail->config->get('use_subscriptions');
63 $args['prefs']['use_subscriptions'] = isset($_POST['_use_subscriptions']) ? true : false;
65 // if the use_subscriptions preference changes, flush the folder cache
66 if (($use_subscriptions && !isset($_POST['_use_subscriptions'])) ||
67 (!$use_subscriptions && isset($_POST['_use_subscriptions']))) {
68 $rcmail->imap_init(true);
69 $rcmail->imap->clear_cache('mailboxes');
75 function list_mailboxes($args)
77 $rcmail = rcmail::get_instance();
78 if (!$rcmail->config->get('use_subscriptions', true)) {
79 $args['folders'] = iil_C_ListMailboxes($rcmail->imap->conn, $rcmail->imap->mod_mailbox($args['root']), $args['filter']);
84 function manage_folders($args)
86 $rcmail = rcmail::get_instance();
87 if (!$rcmail->config->get('use_subscriptions', true)) {
88 $args['table']->remove_column('subscribed');