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 Dec 19, 2023
1 parent 4256a6b commit f98f689
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 26 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 .= ' <img class="folder_icon" src="'.Hm_Image_Sources::$folder.'" alt="" width="16" height="16" />';
}
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_'.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)).
'"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_'.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)).
'">'.$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 @@ -705,17 +705,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 @@ -727,6 +728,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 @@ -423,12 +423,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 @@ -486,7 +487,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 @@ -518,12 +518,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 @@ -2140,7 +2150,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 @@ -2152,12 +2162,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 @@ -713,8 +713,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
4 changes: 3 additions & 1 deletion modules/imap/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
.snooze_date_picker { display: block; padding: 8px 15px; color: #333; font-size: 1rem; cursor: pointer; }
.unsnooze { color: teal; }
.header_x-snoozed .unsnooze { margin-left: 20px; }

.folder-disabled { opacity: .4; }

/* Popup container - can be anything you want */
.popup {
Expand Down Expand Up @@ -216,3 +216,5 @@
.fade-in {
animation-name: fadeIn;
}


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 f98f689

Please sign in to comment.