';
+ }
+}
+
+class Hm_Output_folders_folder_subscription extends Hm_Output_Module {
+ protected function output() {
+ if ($this->get('only_subscribed_folders_setting', 0) && ($server = $this->get('folder_server')) !== NULL) {
+ $res = '
';
+ $res .= '
';
+ $res .= '
';
+ return $res;
+ }
+ }
+}
+
+/**
+ * @subpackage imap_folders/handler
+ */
+class Hm_Handler_get_only_subscribed_folders_setting extends Hm_Handler_Module {
+ public function process() {
+ $this->out('only_subscribed_folders_setting', $this->user_config->get('only_subscribed_folders_setting', 0));
+ }
+}
+
+/**
+ * @subpackage imap_folders/output
+ */
+class Hm_Output_folders_folder_subscription_button extends Hm_Output_Module {
+ protected function output() {
+ if ($this->get('only_subscribed_folders_setting', 0)) {
+ $server = $this->get('folder_server');
+ $results = '
';
+ return $results;
+ }
}
}
@@ -691,6 +767,16 @@ protected function output() {
}
}
+/**
+ * @subpackage imap_folders/output
+ */
+class Hm_Output_folders_subscription_content_start extends Hm_Output_Module {
+ protected function output() {
+ $res = '
'.$this->trans('Folders subscription').'
';
+ return $res;
+ }
+}
+
/**
* @subpackage imap_folders/output
*/
@@ -720,6 +806,25 @@ protected function output() {
}
}
+/**
+ * Option to enable/disable showing only subscribed folders
+ * @subpackage imap/output
+ */
+class Hm_Output_imap_only_subscribed_folders_setting extends Hm_Output_Module {
+ protected function output() {
+ $checked = '';
+ $reset = '';
+ $settings = $this->get('user_settings', array());
+ if (array_key_exists('only_subscribed_folders', $settings) && $settings['only_subscribed_folders']) {
+ $checked = ' checked="checked"';
+ $reset = '
';
+ }
+ return '
| '.
+ ''.$reset.' |
';
+ }
+}
+
if (!hm_exists('get_sieve_linked_mailbox')) {
function get_sieve_linked_mailbox ($imap_account, $module) {
if (!$module->module_is_supported('sievefilters') && $module->user_config->get('enable_sieve_filter_setting', true)) {
diff --git a/modules/imap_folders/setup.php b/modules/imap_folders/setup.php
index 66e979d412..8f769bf14a 100644
--- a/modules/imap_folders/setup.php
+++ b/modules/imap_folders/setup.php
@@ -17,12 +17,14 @@
add_handler('folders', 'folders_server_id', true, 'imap_folders', 'load_user_data', 'after');
add_handler('folders', 'special_folders', true, 'imap_folders', 'folders_server_id', 'after');
add_output('folders', 'folders_content_start', true, 'imap_folders', 'content_section_start', 'after');
-add_output('folders', 'folders_server_select', true, 'imap_folders', 'folders_content_start', 'after');
+add_output('folders', 'folders_server_select', true, 'imap_folders', 'folders_folder_subscription_button', 'after');
add_output('folders', 'folders_create_dialog', true, 'imap_folders', 'folders_server_select', 'after');
add_output('folders', 'folders_rename_dialog', true, 'imap_folders', 'folders_create_dialog', 'after');
add_output('folders', 'folders_delete_dialog', true, 'imap_folders', 'folders_rename_dialog', 'after');
+add_output('folders', 'folders_folder_subscription_button', true, 'imap_folders', 'folders_content_start', 'after');
add_handler('ajax_imap_folder_expand', 'add_folder_manage_link', true, 'imap_folders', 'imap_folder_expand', 'after');
+add_handler('folders', 'get_only_subscribed_folders_setting', true, 'imap_folders');
// Commented out during development
add_output('folders', 'folders_trash_dialog', true, 'imap_folders', 'folders_delete_dialog', 'after');
@@ -30,6 +32,7 @@
add_output('folders', 'folders_archive_dialog', true, 'imap_folders', 'folders_sent_dialog', 'after');
add_output('folders', 'folders_draft_dialog', true, 'imap_folders', 'folders_archive_dialog', 'after');
add_output('folders', 'folders_junk_dialog', true, 'imap_folders', 'folders_draft_dialog', 'after');
+add_output('folders', 'folders_folder_subscription', true, 'imap_folders', 'folders_server_select', 'after');
add_handler('compose', 'special_folders', true, 'imap_folders', 'load_user_data', 'after');
@@ -69,25 +72,47 @@
add_handler('ajax_hm_folders', 'imap_folder_check', true, 'imap_folders', 'load_user_data', 'after');
add_output('ajax_hm_folders', 'folders_page_link', true, 'imap_folders', 'settings_menu_end', 'before');
+add_handler('settings', 'process_only_subscribed_folders_setting', true, 'imap', 'date', 'after');
+add_output('settings', 'imap_only_subscribed_folders_setting', true, 'imap', 'original_folder_setting', 'after');
+
+setup_base_page('folders_subscription', 'core');
+add_handler('folders_subscription', 'folders_server_id', true, 'imap_folders', 'load_user_data', 'after');
+add_handler('folders_subscription', 'special_folders', true, 'imap_folders', 'folders_server_id', 'after');
+add_handler('folders_subscription', 'get_only_subscribed_folders_setting', true, 'imap_folders');
+add_output('folders_subscription', 'folders_subscription_content_start', true, 'imap_folders', 'content_section_start', 'after');
+add_output('folders_subscription', 'folders_server_select', true, 'imap_folders', 'folders_subscription_content_start', 'after');
+add_output('folders_subscription', 'folders_folder_subscription', true, 'imap_folders', 'folders_server_select', 'after');
+
+setup_base_ajax_page('ajax_imap_folder_subscription', 'core');
+add_handler('ajax_imap_folder_subscription', 'load_imap_servers_from_config', true, 'imap', 'load_user_data', 'after');
+add_handler('ajax_imap_folder_subscription', 'process_imap_folder_subscription', true, 'imap_folders', 'load_imap_servers_from_config', 'after');
+add_handler('ajax_imap_folder_subscription', 'save_user_data', true, 'core', 'process_special_folder', 'after');
+
return array(
'allowed_pages' => array(
'folders',
+ 'folders_subscription',
'ajax_imap_folders_delete',
'ajax_imap_folders_create',
'ajax_imap_folders_rename',
'ajax_imap_special_folder',
'ajax_imap_clear_special_folder',
- 'ajax_imap_accept_special_folders'
+ 'ajax_imap_accept_special_folders',
+ 'ajax_imap_folder_subscription'
),
'allowed_output' => array(
'imap_folders_success' => array(FILTER_VALIDATE_INT, false),
- 'imap_special_name' => array(FILTER_DEFAULT, false)
+ 'imap_special_name' => array(FILTER_DEFAULT, false),
+ 'imap_folder_subscription' => array(FILTER_DEFAULT, false),
),
'allowed_get' => array(),
'allowed_post' => array(
'parent' => FILTER_DEFAULT,
'new_folder' => FILTER_DEFAULT,
'special_folder_type' => FILTER_DEFAULT,
- 'imap_service_name' => FILTER_DEFAULT
+ 'imap_service_name' => FILTER_DEFAULT,
+ 'subscription_state' => FILTER_VALIDATE_BOOLEAN,
+ 'folder' => FILTER_DEFAULT,
+ 'only_subscribed_folders' => FILTER_VALIDATE_BOOLEAN,
)
);
diff --git a/modules/imap_folders/site.css b/modules/imap_folders/site.css
index 2ea2004d31..3d9d0558cc 100644
--- a/modules/imap_folders/site.css
+++ b/modules/imap_folders/site.css
@@ -9,3 +9,15 @@
#draft_val, #sent_val, #trash_val, #junk_val { padding-left: 20px; }
.manage_folder_icon { vertical-align: -3px; opacity: .3 }
.manage_folder_link { color: #999 !important; }
+
+.folder_subscription_btn { position: absolute; right: 20px; top: 20px; }
+.folders_subscription { padding-left: 10px; width: 100%; display: inline-block; }
+.folders_subscription input { float: right; }
+
+@media (min-width: 687px) {
+ .folders_subscription { width: 30% }
+}
+
+@media (min-width: 1201px) {
+ .folders_subscription { width: 25% }
+}
diff --git a/modules/imap_folders/site.js b/modules/imap_folders/site.js
index 7d33448a35..8fd8e21988 100644
--- a/modules/imap_folders/site.js
+++ b/modules/imap_folders/site.js
@@ -1,6 +1,6 @@
'use strict';
-var folder_page_folder_list = function(container, title, link_class, target, id_dest) {
+var folder_page_folder_list = function(container, title, link_class, target, id_dest, subscription = false) {
var id = $('#imap_server_folder').val();
var folder_location = $('.'+container);
$('li', folder_location).not('.'+title).remove();
@@ -9,7 +9,7 @@ var folder_page_folder_list = function(container, title, link_class, target, id_
$('.imap_folder_link', folders).addClass(link_class).removeClass('imap_folder_link');
folder_location.prepend(folders);
folder_location.show();
- $('.'+link_class, folder_location).on("click", function() { return expand_folders_page_list($(this).data('target'), container, link_class, target, id_dest); });
+ $('.'+link_class, folder_location).on("click", function() { return expand_folders_page_list($(this).data('target'), container, link_class, target, id_dest, subscription); });
$('a', folder_location).not('.'+link_class).not('.close').off('click');
$('a', folder_location).not('.'+link_class).not('.close').on("click", function() { set_folders_page_value($(this).data('id'), container, target, id_dest); return false; });
$('.close', folder_location).on("click", function() {
@@ -22,17 +22,17 @@ var folder_page_folder_list = function(container, title, link_class, target, id_
return false;
};
-
-var expand_folders_page_list = function(path, container, link_class, target, id_dest) {
+var expand_folders_page_list = function(path, container, link_class, target, id_dest, lsub) {
var detail = Hm_Utils.parse_folder_path(path, 'imap');
var list = $('.imap_'+detail.server_id+'_'+Hm_Utils.clean_selector(detail.folder), $('.'+container));
if ($('li', list).length === 0) {
- $('.expand_link', list).html('-');
+ $('.expand_link', list).html('
');
if (detail) {
Hm_Ajax.request(
[{'name': 'hm_ajax_hook', 'value': 'ajax_imap_folder_expand'},
{'name': 'imap_server_id', 'value': detail.server_id},
- {'name': 'folder', 'value': detail.folder}],
+ {'name': 'folder', 'value': detail.folder},
+ {'name': 'subscription_state', 'value': lsub}],
function(res) {
if (res.imap_expanded_folder_path) {
var folder_location = $('.'+container);
@@ -41,9 +41,12 @@ var expand_folders_page_list = function(path, container, link_class, target, id_
$('.'+Hm_Utils.clean_selector(res.imap_expanded_folder_path), folder_location).append(folders);
$('.imap_folder_link', folder_location).addClass(link_class).removeClass('imap_folder_link');
$('.'+link_class, folder_location).off('click');
- $('.'+link_class, folder_location).on("click", function() { return expand_folders_page_list($(this).data('target'), container, link_class, target, id_dest); });
+ $('.'+link_class, folder_location).on("click", function() { return expand_folders_page_list($(this).data('target'), container, link_class, target, id_dest, lsub); });
$('a', folder_location).not('.'+link_class).not('.close').off('click');
$('a', folder_location).not('.'+link_class).not('.close').on("click", function() { set_folders_page_value($(this).data('id'), container, target, id_dest); return false; });
+ if (lsub) {
+ $('.folder_subscription').on("change", function() { folder_subscribe(this.id, $('#'+this.id).is(':checked')); return false; });
+ }
}
}
);
@@ -214,6 +217,23 @@ var assign_special_folder = function(id, folder, type, callback) {
);
};
+var folder_subscribe = function(name, state) {
+ Hm_Ajax.request(
+ [{'name': 'hm_ajax_hook', 'value': 'ajax_imap_folder_subscription'},
+ {'name': 'subscription_state', 'value': state},
+ {'name': 'folder', 'value': name}],
+ function(res) {
+ var el = $('#'+name);
+ if (!res.imap_folder_subscription) {
+ el.prop('checked', !el.prop('checked'));
+ } else {
+ el.prev().toggleClass('folder-disabled');
+ Hm_Folders.reload_folders(true);
+ }
+ }
+ );
+};
+
var folder_page_create = function() {
var par = $('#create_parent').val();
var folder = $('#create_value').val().trim();
@@ -244,12 +264,24 @@ var folder_page_create = function() {
};
$(function() {
- if (hm_page_name() == 'folders') {
+ if (hm_page_name() == 'folders' || hm_page_name() == 'folders_subscription') {
$('#imap_server_folder').on("change", function() {
$(this).parent().parent().submit();
});
+ }
+ if (hm_page_name() == 'folders') {
$('.settings_subtitle').on("click", function() { return Hm_Utils.toggle_page_section($(this).data('target')); });
}
+ if (hm_page_name() == 'folders_subscription') {
+ $('.subscribe_parent_folder').on("click", function() { return folder_page_folder_list('subscribe_parent_folder_select', 'subscribe_title', 'imap_parent_folder_link', '', 'subscribe_parent', true); });
+ $('.subscribe_parent_folder').trigger('click');
+ $($('.subscribe_parent_folder_select .imap_parent_folder_link')[0]).trigger('click');
+ const selected_imap_server = $('#imap_server_folder').val();
+ const email_folder_server = $(`.email_folders .imap_${selected_imap_server}_ .inner_list`);
+ if (email_folder_server && $(email_folder_server[0]).children().length) {
+ $($('.subscribe_parent_folder_select .imap_parent_folder_link')[0]).trigger('click');
+ }
+ }
$('.select_parent_folder').on("click", function() { return folder_page_folder_list('parent_folder_select', 'parent_title', 'imap_parent_folder_link', 'selected_parent', 'create_parent'); });
$('.select_rename_folder').on("click", function() { return folder_page_folder_list('rename_folder_select', 'rename_title', 'imap_rename_folder_link', 'selected_rename', 'rename_source'); });
$('.select_delete_folder').on("click", function() { return folder_page_folder_list('delete_folder_select', 'delete_title', 'imap_delete_folder_link', 'selected_delete', 'delete_source'); });