Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Fixed jmap quota display #1296

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions modules/imap/handler_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -758,14 +758,32 @@ public function process() {
$this->out('can_share_folders', stripos($imap->get_capability(), 'ACL') !== false);
if (imap_authed($imap)) {
$quota_root = $imap->get_quota_root($folder ? $folder : 'INBOX');
if ($quota_root && isset($quota_root[0]['name'])) {
$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($imap instanceof Hm_JMAP) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please unify the interface/data scheme for both IMAP and JSON, so the corresponding methods in those classes return the same data structure, then the handler can just use it and not distinguish between the two. This will be particularly helpful in the light of the upcoming EWS support which will use a 3rd set of data representation.

if (!empty($quota_root["methodResponses"][0][1]["list"])) {
$quota = $quota_root["methodResponses"][0][1]["list"][0];

if ($quota) {
$used = floatval($quota['used']);
$max = floatval($quota['hardLimit']);
if ($max > 0) {
$quotaPercentage = ceil(($used / $max) * 100);
$quotaMaxInMB = $max / (1024 * 1024);

$this->out('quota', $quotaPercentage);
$this->out('quota_max', $quotaMaxInMB);
}
}
}
}else {
if ($quota_root && isset($quota_root[0]['name'])) {
$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);
}
}
}
}
Expand Down
27 changes: 25 additions & 2 deletions modules/imap/hm-jmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ class Hm_JMAP {
);
private $default_caps = array(
'urn:ietf:params:jmap:core',
'urn:ietf:params:jmap:mail'
'urn:ietf:params:jmap:mail',
'urn:ietf:params:jmap:quota'
);

public $selected_mailbox;
Expand Down Expand Up @@ -376,6 +377,28 @@ public function get_folder_list_by_level($level=false) {
return $this->parse_folder_list_by_level($level);
}

public function get_quota_root($mailbox) {
if (!is_array($this->session)) {
throw new Exception("Not authenticated. Please authenticate first.");
}
$methods = [
[
"Quota/get",
[
"accountId"=> (string)$this->account_id,
"name" => $this->session['username'],
"scope" => "folder",
"folder" => $mailbox
],
"0"
]
];
$response = $this->send_command($this->session['apiUrl'], $methods, 'POST');
return $response;
}
public function get_capability() {
//TODO: Implement
}
/**
* Return cached data
* @return array
Expand Down Expand Up @@ -452,7 +475,7 @@ public function get_folder_list() {
$methods = array(array(
'Mailbox/get',
array(
'accountId' => $this->account_id,
'accountId' => (string)$this->account_id,
'ids' => NULL
),
'fl'
Expand Down