From a1273f1097898a27c5740351ce7b73a2a7a2147c Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Wed, 4 Aug 2021 10:02:39 -0400 Subject: [PATCH] fix(mail): add support for messages quota Fixes #5365 --- SoObjects/Mailer/SOGoMailAccount.m | 23 +++++++++++++++---- UI/MailerUI/English.lproj/Localizable.strings | 1 + .../js/Mailer/Account.service.js | 13 ++++++++--- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/SoObjects/Mailer/SOGoMailAccount.m b/SoObjects/Mailer/SOGoMailAccount.m index a1f29f6e5..fdc6f868d 100644 --- a/SoObjects/Mailer/SOGoMailAccount.m +++ b/SoObjects/Mailer/SOGoMailAccount.m @@ -289,11 +289,24 @@ static NSString *inboxFolderName = @"INBOX"; if (quota != 0 && inboxQuota != nil) { // A soft quota ratio is imposed for all users - quota = quota * [(NSNumber*)[inboxQuota objectForKey: @"maxQuota"] intValue]; - inboxQuota = [NSDictionary dictionaryWithObjectsAndKeys: - [NSNumber numberWithLong: (long)(quota+0.5)], @"maxQuota", - [NSNumber numberWithLong: [[inboxQuota objectForKey: @"usedSpace"] longLongValue]], @"usedSpace", - nil]; + if ([[inboxQuota allKeys] containsObject: @"maxQuota"]) + { + // Storage quota + quota = quota * [(NSNumber*)[inboxQuota objectForKey: @"maxQuota"] intValue]; + inboxQuota = [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithLong: (long)(quota+0.5)], @"maxQuota", + [NSNumber numberWithLong: [[inboxQuota objectForKey: @"usedSpace"] longLongValue]], @"usedSpace", + nil]; + } + else if ([[inboxQuota allKeys] containsObject: @"maxMessages"]) + { + // Messages quota + quota = quota * [(NSNumber*)[inboxQuota objectForKey: @"maxMessages"] intValue]; + inboxQuota = [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithLong: (long)(quota+0.5)], @"maxMessages", + [NSNumber numberWithLong: [[inboxQuota objectForKey: @"messagesCount"] longLongValue]], @"messagesCount", + nil]; + } } } diff --git a/UI/MailerUI/English.lproj/Localizable.strings b/UI/MailerUI/English.lproj/Localizable.strings index 0a065b513..73934f7bb 100644 --- a/UI/MailerUI/English.lproj/Localizable.strings +++ b/UI/MailerUI/English.lproj/Localizable.strings @@ -319,6 +319,7 @@ "Operation failed" = "Operation failed"; "Quota" = "Quota:"; "quotasFormat" = "%{0}% used on %{1} MB"; +"messageQuotasFormat" = "%{0}% of %{1} msgs"; "Unable to move/delete folder." = "Unable to move/delete folder."; /* Alternative operation when folder cannot be deleted */ diff --git a/UI/WebServerResources/js/Mailer/Account.service.js b/UI/WebServerResources/js/Mailer/Account.service.js index c9c4bd957..5195272f6 100644 --- a/UI/WebServerResources/js/Mailer/Account.service.js +++ b/UI/WebServerResources/js/Mailer/Account.service.js @@ -439,9 +439,16 @@ Account.prototype.updateQuota = function(data) { var percent, format, description; - percent = (Math.round(data.usedSpace * 10000 / data.maxQuota) / 100); - format = l("quotasFormat"); - description = format.formatted(percent, Math.round(data.maxQuota/10.24)/100); + if (data.maxQuota) { + percent = (Math.round(data.usedSpace * 10000 / data.maxQuota) / 100); + format = l("quotasFormat"); + description = format.formatted(percent, Math.round(data.maxQuota/10.24)/100); + } + else if (data.maxMessages) { + percent = (Math.round(data.messagesCount * 10000 / data.maxMessages) / 100); + format = l("messageQuotasFormat"); + description = format.formatted(percent, data.maxMessages); + } this.$quota = { percent: percent, description: description }; };