Bug 1636665 - Support petabyte in imap folder quote size and percentage calculations. r=mkmelin

This commit is contained in:
Ping Chen 2020-07-02 19:23:43 +03:00
Родитель 3c32b522c4
Коммит b3ca7aea8c
14 изменённых файлов: 93 добавлений и 26 удалений

Просмотреть файл

@ -10,6 +10,7 @@
/* import-globals-from folderPane.js */
/* import-globals-from mailWindow.js */
/* import-globals-from msgMail3PaneWindow.js */
/* global BigInt */
var { MailViewConstants } = ChromeUtils.import(
"resource:///modules/MailViewManager.jsm"
@ -140,14 +141,17 @@ function UpdateStatusQuota(folder) {
return;
}
let quotaUsagePercentage = q =>
Number((100n * BigInt(q.usage)) / BigInt(q.limit));
let folderQuota = folder.getQuota();
// If folderQuota not empty, find the index of the element with highest
// percent usage and determine if it is above the panel display threshold.
if (folderQuota.length > 0) {
let highest = folderQuota.reduce((acc, current) =>
acc.usage / acc.limit > current.usage / current.limit ? acc : current
quotaUsagePercentage(acc) > quotaUsagePercentage(current) ? acc : current
);
let percent = Math.round((100 * highest.usage) / highest.limit);
let percent = quotaUsagePercentage(highest);
if (
percent <
Services.prefs.getIntPref("mail.quota.mainwindow_threshold.show")

Просмотреть файл

@ -514,6 +514,8 @@ byteAbbreviation2=%.*f bytes
kiloByteAbbreviation2=%.*f KB
megaByteAbbreviation2=%.*f MB
gigaByteAbbreviation2=%.*f GB
teraByteAbbreviation2=%.*f TB
petaByteAbbreviation2=%.*f PB
## LOCALIZATION NOTE(folderWithAccount):
## This is used to show folder name together with an account name.

Просмотреть файл

@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* import-globals-from retention.js */
/* global BigInt */
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
var { Gloda } = ChromeUtils.import("resource:///modules/gloda/Gloda.jsm");
@ -90,7 +91,7 @@ var gFolderPropsSink = {
let percentage = document.createElement("span");
percentage.textContent = bundle.getFormattedString("quotaPercentUsed", [
Math.round((100 * quota.usage) / quota.limit),
Number((100n * BigInt(quota.usage)) / BigInt(quota.limit)),
]);
li.appendChild(percentage);

Просмотреть файл

@ -27,6 +27,8 @@ function test_formatFileSize(aArgs) {
kb: "kiloByteAbbreviation2",
mb: "megaByteAbbreviation2",
gb: "gigaByteAbbreviation2",
tb: "teraByteAbbreviation2",
pb: "petaByteAbbreviation2",
};
let actual = gMessenger.formatFileSize(aArgs.bytes, aArgs.useKB);
@ -78,8 +80,62 @@ var test_data = [
{
bytes: 1000 * 1024 * 1024 * 1024,
useKB: false,
mantissa: "1.0",
units: "tb",
},
{
bytes: 1024 * 1024 * 1024 * 1024,
useKB: false,
mantissa: "1.0",
units: "tb",
},
{
bytes: 10 * 1024 * 1024 * 1024 * 1024,
useKB: false,
mantissa: "10.0",
units: "tb",
},
{
bytes: 999 * 1024 * 1024 * 1024 * 1024,
useKB: false,
mantissa: "999",
units: "tb",
},
{
bytes: 1000 * 1024 * 1024 * 1024 * 1024,
useKB: false,
mantissa: "1.0",
units: "pb",
},
{
bytes: 1000 * 1024 * 1024 * 1024 * 1024,
useKB: false,
mantissa: "1.0",
units: "pb",
},
{
bytes: 1024 * 1024 * 1024 * 1024 * 1024,
useKB: false,
mantissa: "1.0",
units: "pb",
},
{
bytes: 10 * 1024 * 1024 * 1024 * 1024 * 1024,
useKB: false,
mantissa: "10.0",
units: "pb",
},
{
bytes: 999 * 1024 * 1024 * 1024 * 1024 * 1024,
useKB: false,
mantissa: "999",
units: "pb",
},
{
bytes: 1000 * 1024 * 1024 * 1024 * 1024 * 1024,
useKB: false,
mantissa: "1000",
units: "gb",
units: "pb",
},
{ bytes: 0, useKB: true, mantissa: "0", units: "kb" },

Просмотреть файл

@ -407,6 +407,8 @@ nsresult FormatFileSize(int64_t size, bool useKB, nsAString& formattedSize) {
"kiloByteAbbreviation2",
"megaByteAbbreviation2",
"gigaByteAbbreviation2",
"teraByteAbbreviation2",
"petaByteAbbreviation2",
};
nsresult rv;

Просмотреть файл

@ -67,7 +67,7 @@ interface nsIImapMailFolderSink : nsISupports {
**/
void setFolderQuotaData(
in unsigned long aAction, in ACString aFolderQuotaRoot,
in unsigned long aFolderQuotaUsed, in unsigned long aFolderQuotaLimit);
in unsigned long long aFolderQuotaUsed, in unsigned long long aFolderQuotaLimit);
/// Should we download all the rfc822 headers of messages, instead of subset.
readonly attribute boolean shouldDownloadAllHeaders;

Просмотреть файл

@ -35,12 +35,12 @@ interface nsIMsgQuota : nsISupports {
* or storage in KB (1024 octets).
*/
attribute unsigned long usage;
attribute unsigned long long usage;
/**
* Maximum amount of usage permitted by the server for this quota root
* resource.
*/
attribute unsigned long limit;
attribute unsigned long long limit;
};
/**

Просмотреть файл

@ -159,8 +159,8 @@ static nsresult RecursiveCopy(nsIFile* srcDir, nsIFile* destDir) {
//
NS_IMPL_ISUPPORTS(nsMsgQuota, nsIMsgQuota)
nsMsgQuota::nsMsgQuota(const nsACString& aName, const uint32_t& aUsage,
const uint32_t& aLimit)
nsMsgQuota::nsMsgQuota(const nsACString& aName, const uint64_t& aUsage,
const uint64_t& aLimit)
: mName(aName), mUsage(aUsage), mLimit(aLimit) {}
nsMsgQuota::~nsMsgQuota() {}
@ -179,22 +179,22 @@ NS_IMETHODIMP nsMsgQuota::SetName(const nsACString& aName) {
return NS_OK;
}
NS_IMETHODIMP nsMsgQuota::GetUsage(uint32_t* aUsage) {
NS_IMETHODIMP nsMsgQuota::GetUsage(uint64_t* aUsage) {
*aUsage = mUsage;
return NS_OK;
}
NS_IMETHODIMP nsMsgQuota::SetUsage(uint32_t aUsage) {
NS_IMETHODIMP nsMsgQuota::SetUsage(uint64_t aUsage) {
mUsage = aUsage;
return NS_OK;
}
NS_IMETHODIMP nsMsgQuota::GetLimit(uint32_t* aLimit) {
NS_IMETHODIMP nsMsgQuota::GetLimit(uint64_t* aLimit) {
*aLimit = mLimit;
return NS_OK;
}
NS_IMETHODIMP nsMsgQuota::SetLimit(uint32_t aLimit) {
NS_IMETHODIMP nsMsgQuota::SetLimit(uint64_t aLimit) {
mLimit = aLimit;
return NS_OK;
}
@ -8007,7 +8007,7 @@ NS_IMETHODIMP nsImapMailFolder::SetFolderQuotaCommandIssued(bool aCmdIssued) {
NS_IMETHODIMP nsImapMailFolder::SetFolderQuotaData(
uint32_t aAction, const nsACString& aFolderQuotaRoot,
uint32_t aFolderQuotaUsage, uint32_t aFolderQuotaLimit) {
uint64_t aFolderQuotaUsage, uint64_t aFolderQuotaLimit) {
switch (aAction) {
case kInvalidateQuota:
// Reset to initialize evaluation of a new quotaroot imap response. This

Просмотреть файл

@ -200,14 +200,14 @@ class nsMsgQuota final : public nsIMsgQuota {
NS_DECL_ISUPPORTS
NS_DECL_NSIMSGQUOTA
nsMsgQuota(const nsACString& aName, const uint32_t& aUsage,
const uint32_t& aLimit);
nsMsgQuota(const nsACString& aName, const uint64_t& aUsage,
const uint64_t& aLimit);
protected:
~nsMsgQuota();
nsCString mName;
uint32_t mUsage, mLimit;
uint64_t mUsage, mLimit;
};
class nsImapMailFolder : public nsMsgDBFolder,

Просмотреть файл

@ -8365,7 +8365,7 @@ bool nsImapProtocol::TryToLogon() {
void nsImapProtocol::UpdateFolderQuotaData(nsImapQuotaAction aAction,
nsCString& aQuotaRoot,
uint32_t aUsed, uint32_t aMax) {
uint64_t aUsed, uint64_t aMax) {
NS_ASSERTION(m_imapMailFolderSink, "m_imapMailFolderSink is null!");
m_imapMailFolderSink->SetFolderQuotaData(aAction, aQuotaRoot, aUsed, aMax);

Просмотреть файл

@ -369,7 +369,7 @@ class nsImapProtocol : public nsIImapProtocol,
// Quota support
void UpdateFolderQuotaData(nsImapQuotaAction aAction, nsCString& aQuotaRoot,
uint32_t aUsed, uint32_t aMax);
uint64_t aUsed, uint64_t aMax);
bool GetPreferPlainText() { return m_preferPlainText; }

Просмотреть файл

@ -2589,7 +2589,7 @@ void nsImapServerResponseParser::quota_data() {
fServerConnection.UpdateFolderQuotaData(kInvalidateQuota, quotaroot, 0, 0);
} else if (!PL_strcasecmp(fNextToken, "QUOTA")) {
// Should have one QUOTA response per QUOTAROOT.
uint32_t usage, limit;
uint64_t usage, limit;
AdvanceToNextToken();
if (ContinueParse()) {
nsCString quotaroot;
@ -2607,12 +2607,12 @@ void nsImapServerResponseParser::quota_data() {
while (ContinueParse() && !fAtEndOfLine) {
resource.Adopt(CreateAstring());
AdvanceToNextToken();
usage = atoi(fNextToken);
usage = atoll(fNextToken);
AdvanceToNextToken();
nsAutoCString limitToken(fNextToken);
if (fNextToken[strlen(fNextToken) - 1] == ')')
limitToken.SetLength(strlen(fNextToken) - 1);
limit = atoi(limitToken.get());
limit = atoll(limitToken.get());
// Some servers don't define a quotaroot name which we displays as
// blank.
nsCString quotaRootResource(quotaroot);

Просмотреть файл

@ -331,7 +331,7 @@ NS_SYNCRUNNABLEATTRIBUTE(ImapMailFolderSink, AclFlags, uint32_t)
NS_SYNCRUNNABLEATTRIBUTE(ImapMailFolderSink, UidValidity, int32_t)
NS_SYNCRUNNABLEATTRIBUTE(ImapMailFolderSink, FolderQuotaCommandIssued, bool)
NS_SYNCRUNNABLEMETHOD4(ImapMailFolderSink, SetFolderQuotaData, uint32_t,
const nsACString&, uint32_t, uint32_t)
const nsACString&, uint64_t, uint64_t)
NS_SYNCRUNNABLEMETHOD1(ImapMailFolderSink, GetShouldDownloadAllHeaders, bool*)
NS_SYNCRUNNABLEMETHOD1(ImapMailFolderSink, GetOnlineDelimiter, char*)
NS_SYNCRUNNABLEMETHOD0(ImapMailFolderSink, OnNewIdleMessages)

Просмотреть файл

@ -288,7 +288,7 @@ mailnews.search_date_separator=
# leading zeros for day and month values, not used if mailnews.search_date_format is not zero
mailnews.search_date_leading_zeros=true
# offline msg
# offline msg
nocachedbodybody2=The body of this message has not been downloaded from \
the server for reading offline. To read this message, \
you must reconnect to the network, choose Offline from \
@ -353,10 +353,10 @@ macBiffNotification_messages_extra=%1$S new messages from %2$S and %3$S more.
# Used to separate names/email addresses in a list. Note the trailing space ', '
macBiffNotification_separator=,\u0020
# LOCALIZATION NOTE(newMailNotification_message): %1$S is the name of the account %2$S is the number of new messages
# LOCALIZATION NOTE(newMailNotification_message): %1$S is the name of the account %2$S is the number of new messages
newMailNotification_message=%1$S received %2$S new message
# LOCALIZATION NOTE(newMailNotification_messages): %1$S is the name of the account %2$S is the number of new messages
# LOCALIZATION NOTE(newMailNotification_messages): %1$S is the name of the account %2$S is the number of new messages
newMailNotification_messages=%1$S received %2$S new messages
# LOCALIZATION NOTE(newMailAlert_message):
@ -416,6 +416,8 @@ byteAbbreviation2=%.*f bytes
kiloByteAbbreviation2=%.*f KB
megaByteAbbreviation2=%.*f MB
gigaByteAbbreviation2=%.*f GB
teraByteAbbreviation2=%.*f TB
petaByteAbbreviation2=%.*f PB
# Error message if message for a message id wasn't found
errorOpenMessageForMessageIdTitle=Error opening message-id