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) => {