Skip to content

Commit

Permalink
fix(api): Added quota information to account info response
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Dec 19, 2023
1 parent ea8a02f commit 6341400
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 17 deletions.
10 changes: 10 additions & 0 deletions lib/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,16 @@ class Account {
});
}

async getQuota() {
await this.loadAccountData(this.account, true);

return await this.call({
cmd: 'getQuota',
account: this.account,
timeout: this.timeout
});
}

async createMailbox(path) {
await this.loadAccountData(this.account, true);

Expand Down
22 changes: 22 additions & 0 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,28 @@ class Connection {
});
}

async getQuota() {
this.checkIMAPConnection();
try {
let result = await this.imapClient.getQuota();
return (result && result.storage) || false;
} catch (err) {
if (err.serverResponseCode) {
let error = new Error('Quota request failed');
error.info = {
response: err.response && typeof err.response === 'string' && err.response.replace(/^[^\s]*\s*/, '')
};
error.code = err.serverResponseCode;
error.statusCode = 400;
throw error;
} else if (err.responseStatus === 'NO') {
return false;
} else {
throw err;
}
}
}

async createMailbox(path) {
this.checkIMAPConnection();
try {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"ace-builds": "1.32.2",
"base32.js": "0.1.0",
"bull-arena": "4.1.0",
"bullmq": "4.15.4",
"bullmq": "4.16.0",
"compare-versions": "6.1.0",
"dotenv": "16.3.1",
"encoding-japanese": "2.0.0",
Expand Down Expand Up @@ -94,7 +94,7 @@
"node-gettext": "3.0.0",
"nodemailer": "6.9.7",
"pino": "8.17.1",
"prom-client": "15.0.0",
"prom-client": "15.1.0",
"psl": "1.9.0",
"pubface": "1.0.6",
"punycode": "2.3.1",
Expand All @@ -112,7 +112,7 @@
"devDependencies": {
"chai": "4.3.10",
"eerawlog": "1.5.1",
"eslint": "8.55.0",
"eslint": "8.56.0",
"eslint-config-nodemailer": "1.2.0",
"eslint-config-prettier": "9.1.0",
"grunt": "1.6.1",
Expand Down
2 changes: 1 addition & 1 deletion sbom.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -1873,6 +1873,7 @@ async function onCommand(worker, message) {
case 'moveMessages':
case 'deleteMessage':
case 'deleteMessages':
case 'getQuota':
case 'createMailbox':
case 'renameMailbox':
case 'deleteMailbox':
Expand Down
16 changes: 8 additions & 8 deletions static/licenses.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!doctype html><html><head><meta charset="utf-8"><title>EmailEngine Licenses</title><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous"></head><body>
<div class="container-fluid">
<h1>EmailEngine v2.39.3</h1><p>EmailEngine includes code from the following software packages:</p>
<h1>EmailEngine v2.39.4</h1><p>EmailEngine includes code from the following software packages:</p>
<table class="table table-sm">
<tr><thead class="thead-dark"><th>Package</th><th>Version</th><th>License</th><th>Publisher</th><th>Publisher's Email</th><th>Package URL</th></tr>
<tbody>
Expand Down Expand Up @@ -236,7 +236,7 @@ <h1>EmailEngine v2.39.3</h1><p>EmailEngine includes code from the following soft
</tr>
<tr>
<td><a href="https://npmjs.com/package/@eslint/js">@eslint/js</a></td>
<td>8.55.0</td>
<td>8.56.0</td>
<td>MIT</td>
<td></td>
<td></td>
Expand Down Expand Up @@ -1616,7 +1616,7 @@ <h1>EmailEngine v2.39.3</h1><p>EmailEngine includes code from the following soft
</tr>
<tr>
<td><a href="https://npmjs.com/package/bullmq">bullmq</a></td>
<td>4.15.4</td>
<td>4.16.0</td>
<td>MIT</td>
<td>Taskforce.sh Inc.</td>
<td></td>
Expand Down Expand Up @@ -2735,7 +2735,7 @@ <h1>EmailEngine v2.39.3</h1><p>EmailEngine includes code from the following soft
</tr>
<tr>
<td><a href="https://npmjs.com/package/eslint">eslint</a></td>
<td>8.55.0</td>
<td>8.56.0</td>
<td>MIT</td>
<td>Nicholas C. Zakas</td>
<td>nicholas+npm@nczconsulting.com</td>
Expand Down Expand Up @@ -3005,7 +3005,7 @@ <h1>EmailEngine v2.39.3</h1><p>EmailEngine includes code from the following soft
</tr>
<tr>
<td><a href="https://npmjs.com/package/fastq">fastq</a></td>
<td>1.15.0</td>
<td>1.16.0</td>
<td>ISC</td>
<td>Matteo Collina</td>
<td>hello@matteocollina.com</td>
Expand Down Expand Up @@ -6225,7 +6225,7 @@ <h1>EmailEngine v2.39.3</h1><p>EmailEngine includes code from the following soft
</tr>
<tr>
<td><a href="https://npmjs.com/package/prom-client">prom-client</a></td>
<td>15.0.0</td>
<td>15.1.0</td>
<td>Apache-2.0</td>
<td>Simon Nyberg</td>
<td></td>
Expand Down Expand Up @@ -6455,7 +6455,7 @@ <h1>EmailEngine v2.39.3</h1><p>EmailEngine includes code from the following soft
</tr>
<tr>
<td><a href="https://npmjs.com/package/readable-stream">readable-stream</a></td>
<td>4.4.2</td>
<td>4.5.1</td>
<td>MIT</td>
<td></td>
<td></td>
Expand Down Expand Up @@ -6525,7 +6525,7 @@ <h1>EmailEngine v2.39.3</h1><p>EmailEngine includes code from the following soft
</tr>
<tr>
<td><a href="https://npmjs.com/package/regenerator-runtime">regenerator-runtime</a></td>
<td>0.14.0</td>
<td>0.14.1</td>
<td>MIT</td>
<td>Ben Newman</td>
<td>bn@cs.stanford.edu</td>
Expand Down
10 changes: 5 additions & 5 deletions translations/messages.pot
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
msgid ""
msgstr ""
"Content-Type: text/plain; charset=ascii\n"
"POT-Creation-Date: 2023-12-15 12:45+0000\n"
"POT-Creation-Date: 2023-12-19 11:03+0000\n"

#: views/config/license.hbs:48
msgid "%d day"
msgid_plural "%d days"
msgstr[0] ""
msgstr[1] ""

#: views/redirect.hbs:1
msgid "Click <a href=\"%s\">here</a> to continue&mldr;"
msgstr ""

#: views/unsubscribe.hbs:1
#: views/unsubscribe.hbs:79
msgid "Unsubscribe"
Expand Down Expand Up @@ -53,10 +57,6 @@ msgstr ""
msgid "Enter your email address"
msgstr ""

#: views/redirect.hbs:1
msgid "Click <a href=\"%s\">here</a> to continue&mldr;"
msgstr ""

#: views/accounts/register/imap.hbs:11
msgid "Your name"
msgstr ""
Expand Down
25 changes: 25 additions & 0 deletions workers/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2872,6 +2872,10 @@ When making API calls remember that requests against the same account are queued
result.counters = accountData.counters;
}

if (request.query.quota) {
result.quota = await accountObject.getQuota();
}

return result;
} catch (err) {
request.logger.error({ msg: 'API request failed', err });
Expand Down Expand Up @@ -2906,6 +2910,15 @@ When making API calls remember that requests against the same account are queued

params: Joi.object({
account: accountIdSchema.required()
}),

query: Joi.object({
quota: Joi.boolean()
.truthy('Y', 'true', '1')
.falsy('N', 'false', 0)
.default(false)
.description('If true, then include quota information in the response')
.label('AccountQuota')
})
},

Expand Down Expand Up @@ -2957,11 +2970,23 @@ When making API calls remember that requests against the same account are queued
.valid(...['imap'].concat(Object.keys(OAUTH_PROVIDERS)).concat('oauth2'))
.example('outlook')
.description('Account type')
.label('AccountType')
.required(),
app: Joi.string().max(256).example('AAABhaBPHscAAAAH').description('OAuth2 application ID'),

counters: accountCountersSchema,

quota: Joi.object({
usage: Joi.number().example(8547884032).description('How many bytes has the account stored in emails'),
limit: Joi.number().example(16106127360).description('How many bytes can the account store emails'),
status: Joi.string().example('53%').description('Textual information about the usage')
})
.label('AccountQuota')
.allow(false)
.description(
'Account quota information if query argument quota=true. This value will be false if the server does not provide quota information.'
),

syncTime: Joi.date().iso().example('2021-02-17T13:43:18.860Z').description('Last sync time'),

lastError: lastErrorSchema.allow(null)
Expand Down
14 changes: 14 additions & 0 deletions workers/imap.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,19 @@ class ConnectionHandler {
return await accountData.connection.uploadMessage(message.data);
}

async getQuota(message) {
if (!this.accounts.has(message.account)) {
return NO_ACTIVE_HANDLER_RESP;
}

let accountData = this.accounts.get(message.account);
if (!accountData.connection) {
return NO_ACTIVE_HANDLER_RESP;
}

return await accountData.connection.getQuota();
}

async createMailbox(message) {
if (!this.accounts.has(message.account)) {
return NO_ACTIVE_HANDLER_RESP;
Expand Down Expand Up @@ -607,6 +620,7 @@ class ConnectionHandler {
case 'deleteMessage':
case 'deleteMessages':
case 'getRawMessage':
case 'getQuota':
case 'createMailbox':
case 'renameMailbox':
case 'deleteMailbox':
Expand Down

0 comments on commit 6341400

Please sign in to comment.