From 9d8e836fdd86bdb6985a6576ed0b6886b14aa5ea Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Sat, 1 Apr 2023 16:29:17 +0200 Subject: [PATCH] show some text instead of nothing on empty quota list some providers say that they support QUOTA in the IMAP CAPABILITY, but return an empty list without any quota information then. in our "Connectivity", this looks a bit of an error. i have not seen this error often - only for testrun.org - if it is usual, we could also just say "not supported" (as we do in case QUOTA is not returned). a translations seems not to be needed for now, it seems unusual, and all other errors are not translated as well. --- CHANGELOG.md | 1 + src/scheduler/connectivity.rs | 118 ++++++++++++++++++---------------- 2 files changed, 64 insertions(+), 55 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34bce4108..024008417 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ ### Fixes - Fix python bindings README documentation on installing the bindings from source. +- Show a warning if quota list is empty #4261 ## [1.112.5] - 2023-04-02 diff --git a/src/scheduler/connectivity.rs b/src/scheduler/connectivity.rs index 49f3ba55e..4ea09b1a5 100644 --- a/src/scheduler/connectivity.rs +++ b/src/scheduler/connectivity.rs @@ -398,64 +398,72 @@ impl Context { if let Some(quota) = &*quota { match "a.recent { Ok(quota) => { - let roots_cnt = quota.len(); - for (root_name, resources) in quota { - use async_imap::types::QuotaResourceName::*; - for resource in resources { - ret += "
  • "; + if quota.len() > 0 { + for (root_name, resources) in quota { + use async_imap::types::QuotaResourceName::*; + for resource in resources { + ret += "
  • "; - // root name is empty eg. for gmail and redundant eg. for riseup. - // therefore, use it only if there are really several roots. - if roots_cnt > 1 && !root_name.is_empty() { - ret += - &format!("{}: ", &*escaper::encode_minimal(root_name)); - } else { - info!(self, "connectivity: root name hidden: \"{}\"", root_name); + // root name is empty eg. for gmail and redundant eg. for riseup. + // therefore, use it only if there are really several roots. + if quota.len() > 1 && !root_name.is_empty() { + ret += &format!( + "{}: ", + &*escaper::encode_minimal(root_name) + ); + } else { + info!( + self, + "connectivity: root name hidden: \"{}\"", root_name + ); + } + + let messages = stock_str::messages(self).await; + let part_of_total_used = stock_str::part_of_total_used( + self, + &resource.usage.to_string(), + &resource.limit.to_string(), + ) + .await; + ret += &match &resource.name { + Atom(resource_name) => { + format!( + "{}: {}", + &*escaper::encode_minimal(resource_name), + part_of_total_used + ) + } + Message => { + format!("{part_of_total_used}: {messages}") + } + Storage => { + // do not use a special title needed for "Storage": + // - it is usually shown directly under the "Storage" headline + // - by the units "1 MB of 10 MB used" there is some difference to eg. "Messages: 1 of 10 used" + // - the string is not longer than the other strings that way (minus title, plus units) - + // additional linebreaks on small displays are unlikely therefore + // - most times, this is the only item anyway + let usage = &format_size(resource.usage * 1024, BINARY); + let limit = &format_size(resource.limit * 1024, BINARY); + stock_str::part_of_total_used(self, usage, limit).await + } + }; + + let percent = resource.get_usage_percentage(); + let color = if percent >= QUOTA_ERROR_THRESHOLD_PERCENTAGE { + "red" + } else if percent >= QUOTA_WARN_THRESHOLD_PERCENTAGE { + "yellow" + } else { + "green" + }; + ret += &format!("
    {percent}%
    "); + + ret += "
  • "; } - - let messages = stock_str::messages(self).await; - let part_of_total_used = stock_str::part_of_total_used( - self, - &resource.usage.to_string(), - &resource.limit.to_string(), - ) - .await; - ret += &match &resource.name { - Atom(resource_name) => { - format!( - "{}: {}", - &*escaper::encode_minimal(resource_name), - part_of_total_used - ) - } - Message => { - format!("{part_of_total_used}: {messages}") - } - Storage => { - // do not use a special title needed for "Storage": - // - it is usually shown directly under the "Storage" headline - // - by the units "1 MB of 10 MB used" there is some difference to eg. "Messages: 1 of 10 used" - // - the string is not longer than the other strings that way (minus title, plus units) - - // additional linebreaks on small displays are unlikely therefore - // - most times, this is the only item anyway - let usage = &format_size(resource.usage * 1024, BINARY); - let limit = &format_size(resource.limit * 1024, BINARY); - stock_str::part_of_total_used(self, usage, limit).await - } - }; - - let percent = resource.get_usage_percentage(); - let color = if percent >= QUOTA_ERROR_THRESHOLD_PERCENTAGE { - "red" - } else if percent >= QUOTA_WARN_THRESHOLD_PERCENTAGE { - "yellow" - } else { - "green" - }; - ret += &format!("
    {percent}%
    "); - - ret += ""; } + } else { + ret += format!("
  • Warning: {domain} claims to support quota but gives no information
  • ").as_str(); } } Err(e) => {