Skip to content

Commit

Permalink
Fixed issues related to subscribed children/unsubscribed parent
Browse files Browse the repository at this point in the history
  • Loading branch information
josaphatim committed Feb 19, 2024
1 parent 8a8ea50 commit d84c465
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 31 deletions.
29 changes: 17 additions & 12 deletions modules/imap/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function prepare_imap_message_list($msgs, $mod, $type) {
* @return string
*/
if (!hm_exists('format_imap_folder_section')) {
function format_imap_folder_section($folders, $id, $output_mod) {
function format_imap_folder_section($folders, $id, $output_mod, $with_input = false) {
$results = '<ul class="inner_list">';
$manage = $output_mod->get('imap_folder_manage_link');
foreach ($folders as $folder_name => $folder) {
Expand All @@ -124,25 +124,30 @@ function format_imap_folder_section($folders, $id, $output_mod) {
$results .= '<i class="bi bi-folder2-open"></i> ';
}
if (!$folder['noselect']) {
if (!$folder['clickable']) {
$attrs = 'tabindex="0"';
if (!$with_input && isset($folder['subscribed']) && !$folder['subscribed']) {
$attrs .= ' class="folder-disabled"';
}
} else {
$attrs = 'data-id="imap_'.intval($id).'_'.$output_mod->html_safe($folder_name).
'" href="?page=message_list&amp;list_path='.
urlencode('imap_'.intval($id).'_'.$output_mod->html_safe($folder_name)).'"';
}
if (strlen($output_mod->html_safe($folder['basename']))>15) {
$results .= '<a data-id="imap_'.$id.'_'.$output_mod->html_safe($folder_name).
'" href="?page=message_list&amp;list_path='.
urlencode('imap_'.$id.'_'.$output_mod->html_safe($folder_name)).
'"title="'.$output_mod->html_safe($folder['basename']).
$results .= '<a ' . $attrs .
' title="'.$output_mod->html_safe($folder['basename']).
'">'.substr($output_mod->html_safe($folder['basename']),0,15).'...</a>';
}
else{
$results .= '<a data-id="imap_'.$id.'_'.$output_mod->html_safe($folder_name).
'" href="?page=message_list&amp;list_path='.
urlencode('imap_'.$id.'_'.$output_mod->html_safe($folder_name)).
'">'.$output_mod->html_safe($folder['basename']).'</a>';
else {
$results .= '<a ' . $attrs. '>'.$output_mod->html_safe($folder['basename']).'</a>';
}
}
else {
$results .= $output_mod->html_safe($folder['basename']);
}
if (isset($folder['subscribed'])) {
$results .= '<input type="checkbox" value="1" class="folder_subscription" id="'.$output_mod->html_safe($folder_name).'" name="'.$folder_name.'" '.($folder['subscribed']? 'checked="checked"': '').($folder['name'] == 'INBOX'? ' disabled="disabled"': '').' />';
if ($with_input) {
$results .= '<input type="checkbox" value="1" class="folder_subscription" id="'.$output_mod->html_safe($folder_name).'" name="'.$folder_name.'" '.($folder['subscribed']? 'checked="checked"': '').($folder['special']? ' disabled="disabled"': '').' />';
}
$results .= '<span class="unread_count unread_imap_'.$id.'_'.$output_mod->html_safe($folder_name).'"></span></li>';
}
Expand Down
4 changes: 3 additions & 1 deletion modules/imap/handler_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -721,17 +721,18 @@ public function process() {
$prefetched[] = $form['imap_server_id'];
$this->session->set('imap_prefetched_ids', array_unique($prefetched, SORT_NUMERIC));
}
$with_subscription = isset($this->request->post['subscription_state']) && $this->request->post['subscription_state'];
if ($page_cache) {
$this->out('imap_expanded_folder_data', $page_cache);
$this->out('imap_expanded_folder_id', $form['imap_server_id']);
$this->out('imap_expanded_folder_path', $path);
$this->out('with_input', $with_subscription);
return;
}
$cache = Hm_IMAP_List::get_cache($this->cache, $form['imap_server_id']);
$imap = Hm_IMAP_List::connect($form['imap_server_id'], $cache);
if (imap_authed($imap)) {
$only_subscribed = $this->user_config->get('only_subscribed_folders_setting', false);
$with_subscription = isset($this->request->post['subscription_state']) && $this->request->post['subscription_state'];
if ($with_subscription) {
$only_subscribed = false;
}
Expand All @@ -743,6 +744,7 @@ public function process() {
$this->out('imap_expanded_folder_data', $msgs);
$this->out('imap_expanded_folder_id', $form['imap_server_id']);
$this->out('imap_expanded_folder_path', $path);
$this->out('with_input', $with_subscription);
}
else {
Hm_Msgs::add(sprintf('ERRCould not authenticate to the selected %s server (%s)', $imap->server_type, $this->user_config->get('imap_servers')[$form['imap_server_id']]['user']));
Expand Down
37 changes: 27 additions & 10 deletions modules/imap/hm-imap.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,12 +427,13 @@ public function get_mailbox_list($lsub=false, $mailbox='', $keyword='*') {
$can_have_kids = true;
$has_kids = false;
$marked = false;
$special = false;
$folder_sort_by = 'ARRIVAL';
$check_for_new = false;

/* full folder name, includes an absolute path of parent folders */
if ($vals[(count($vals) - 1)] == ')' && $lsub) {
$folder = $this->utf7_decode($vals[6]);
if ($lsub && in_array("\HasChildren", $vals)) {
$folder = $this->utf7_decode($vals[array_search(".", $vals) + 1]);
} else {
$folder = $this->utf7_decode($vals[(count($vals) - 1)]);
}
Expand Down Expand Up @@ -490,7 +491,6 @@ public function get_mailbox_list($lsub=false, $mailbox='', $keyword='*') {

/* special use mailbox extension */
if ($this->is_supported('SPECIAL-USE')) {
$special = false;
foreach ($this->special_use_mailboxes as $name => $value) {
if (stristr($flags, $name)) {
$special = $name;
Expand Down Expand Up @@ -522,12 +522,22 @@ public function get_mailbox_list($lsub=false, $mailbox='', $keyword='*') {
/* store the results in the big folder list struct */
if (strtolower($folder) == 'inbox') {
$inbox = true;
$special = true;
}
$folders[$folder] = array('parent' => $parent, 'delim' => $delim, 'name' => $folder,
'name_parts' => $folder_parts, 'basename' => $base_name,
'realname' => $folder, 'namespace' => $namespace, 'marked' => $marked,
'noselect' => $no_select, 'can_have_kids' => $can_have_kids,
'has_kids' => $has_kids);
$folders[$folder] = array(
'parent' => $parent,
'delim' => $delim,
'name' => $folder,
'name_parts' => $folder_parts,
'basename' => $base_name,
'realname' => $folder,
'namespace' => $namespace,
'marked' => $marked,
'noselect' => $no_select,
'can_have_kids' => $can_have_kids,
'has_kids' => $has_kids,
'special' => (bool) $special
);

/* store a parent list used below */
if ($parent && !in_array($parent, $parents)) {
Expand Down Expand Up @@ -2144,7 +2154,7 @@ public function get_mailbox_page($mailbox, $sort, $rev, $filter, $offset=0, $lim
* @param string $level mailbox name or empty string for the top level
* @return array list of matching folders
*/
public function get_folder_list_by_level($level='', $only_subscribed=false, $with_subscription_state = false) {
public function get_folder_list_by_level($level='', $only_subscribed=false, $with_input = false) {
$result = array();
$folders = $this->get_mailbox_list($only_subscribed, $level, '%');
foreach ($folders as $name => $folder) {
Expand All @@ -2156,12 +2166,19 @@ public function get_folder_list_by_level($level='', $only_subscribed=false, $wit
'noselect' => $folder['noselect'],
'id' => bin2hex($folder['basename']),
'name_parts' => $folder['name_parts'],
'clickable' => !$with_input,
);
if ($with_input) {
$result[$name]['special'] = $folder['special'];
}
}
if ($with_subscription_state) {
if ($only_subscribed || $with_input) {
$subscribed_folders = array_column($this->get_mailbox_list(true), 'name');
foreach ($result as $key => $folder) {
$result[$key]['subscribed'] = in_array($folder['name'], $subscribed_folders);
if (!$with_input) {
$result[$key]['clickable'] = $result[$key]['subscribed'];
}
}
}
return $result;
Expand Down
3 changes: 2 additions & 1 deletion modules/imap/output_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -764,8 +764,9 @@ class Hm_Output_filter_expanded_folder_data extends Hm_Output_Module {
protected function output() {
$res = '';
$folder_data = $this->get('imap_expanded_folder_data', array());
$with_input = $this->get('with_input', false);
if (!empty($folder_data)) {
$res .= format_imap_folder_section($folder_data, $this->get('imap_expanded_folder_id'), $this);
$res .= format_imap_folder_section($folder_data, $this->get('imap_expanded_folder_id'), $this, $with_input);
$this->out('imap_expanded_folder_formatted', $res);
}
}
Expand Down
2 changes: 2 additions & 0 deletions modules/imap/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,5 @@
.fade-in {
animation-name: fadeIn;
}


4 changes: 3 additions & 1 deletion modules/imap_folders/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -813,13 +813,15 @@ protected function 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 = '<span class="tooltip_restore" restore_aria_label="Restore default value"><i class="bi bi-arrow-repeat refresh_list reset_default_value_checkbox"></i></span>';
}
return '<tr class="general_setting"><td><label for="only_subscribed_folders">'.
$this->trans('Showing subscribed folders only').'</label></td>'.
'<td><input type="checkbox" '.$checked.' id="only_subscribed_folders" name="only_subscribed_folders" value="1" /></td></tr>';
'<td><input type="checkbox" '.$checked.' id="only_subscribed_folders" name="only_subscribed_folders" value="1" class="form-check-input" />'.$reset.'</td></tr>';
}
}

Expand Down
10 changes: 5 additions & 5 deletions modules/imap_folders/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@
),
'allowed_get' => array(),
'allowed_post' => array(
'parent' => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
'new_folder' => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
'special_folder_type' => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
'imap_service_name' => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
'parent' => FILTER_DEFAULT,
'new_folder' => FILTER_DEFAULT,
'special_folder_type' => FILTER_DEFAULT,
'imap_service_name' => FILTER_DEFAULT,
'subscription_state' => FILTER_VALIDATE_BOOLEAN,
'folder' => FILTER_VALIDATE_BOOLEAN,
'folder' => FILTER_DEFAULT,
'only_subscribed_folders' => FILTER_VALIDATE_BOOLEAN,
)
);
3 changes: 2 additions & 1 deletion modules/imap_folders/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,11 @@ var folder_subscribe = function(name, state) {
{'name': 'subscription_state', 'value': state},
{'name': 'folder', 'value': name}],
function(res) {
var el = $('#'+name);
if (!res.imap_folder_subscription) {
var el = $('#'+name);
el.prop('checked', !el.prop('checked'));
} else {
el.prev().toggleClass('folder-disabled');
Hm_Folders.reload_folders(true);
}
}
Expand Down

0 comments on commit d84c465

Please sign in to comment.