Skip to content

Commit

Permalink
Merge pull request #1102 from Baraka24/imap_quota
Browse files Browse the repository at this point in the history
[ENH]Imap quota: cypht show space used/available
  • Loading branch information
kroky authored Jul 8, 2024
2 parents 1bd9fd8 + 394c9fc commit 50b4966
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
7 changes: 6 additions & 1 deletion modules/imap/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ function prepare_imap_message_list($msgs, $mod, $type) {
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');
$quota = $output_mod->get('quota');
$quota_max = $output_mod->get('quota_max');
foreach ($folders as $folder_name => $folder) {
$folder_name = bin2hex($folder_name);
$results .= '<li class="imap_'.$id.'_'.$output_mod->html_safe($folder_name).'">';
Expand Down Expand Up @@ -152,7 +154,10 @@ function format_imap_folder_section($folders, $id, $output_mod, $with_input = fa
$results .= '<span class="unread_count unread_imap_'.$id.'_'.$output_mod->html_safe($folder_name).'"></span></li>';
}
if ($manage) {
$results .= '<li class="manage_folders_li"><i class="bi bi-gear-wide me-1"></i><a class="manage_folder_link" href="'.$manage.'">'.$output_mod->trans('Manage Folders').'</a>';
$results .= '<li class="manage_folders_li"><i class="bi bi-gear-wide me-1"></i><a class="manage_folder_link" href="'.$manage.'">'.$output_mod->trans('Manage Folders').'</a></li>';
}
if ($quota) {
$results .= '<li class="manage_folders_li"><div class="progress bg-secondary border"><div class="progress-bar bg-light" style="width:'.$quota.'%"></div></div>'.$quota.'% used on '.$quota_max.' MB</li>';
}
$results .= '</ul>';
return $results;
Expand Down
16 changes: 14 additions & 2 deletions modules/imap/handler_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -722,15 +722,27 @@ public function process() {
$this->session->set('imap_prefetched_ids', array_unique($prefetched, SORT_NUMERIC));
}
$with_subscription = isset($this->request->post['subscription_state']) && $this->request->post['subscription_state'];
$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)) {
$quota_root = $imap->get_quota_root($folder ? $folder : 'INBOX');
$quota = $imap->get_quota($quota_root[0]['name']);
if ($quota) {
$current = floatval($quota[0]['current']);
$max = floatval($quota[0]['max']);
if ($max > 0) {
$this->out('quota', ceil(($current / $max) * 100));
$this->out('quota_max', $max / 1024);
}
}
}
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);
if ($with_subscription) {
Expand Down
2 changes: 1 addition & 1 deletion modules/imap/output_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,7 @@ protected function output() {
</div>';
}
$res .= '</div>';

return $res;
}
}
Expand Down

0 comments on commit 50b4966

Please sign in to comment.