Skip to content

Commit

Permalink
Functioning list messages and list mailboxes API endpoints for Gmail API
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed May 8, 2024
1 parent 0ec46a6 commit eaf1ff7
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 50 deletions.
48 changes: 25 additions & 23 deletions lib/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,20 @@ class Account {
let accountData = await this.loadAccountData(this.account, false);

let mailboxListing;
if (accountData.state === 'connected' || query.counters) {
if (await this.isApiClient(accountData)) {
mailboxListing = await this.listMailboxes(query);

if (mailboxListing && mailboxListing.error) {
let error = Boom.boomify(new Error(mailboxListing.error), { statusCode: mailboxListing.statusCode || 500 });
if (mailboxListing.code) {
error.output.payload.code = mailboxListing.code;
}
throw error;
}

// just pass through, do nothing
return mailboxListing;
} else if (accountData.state === 'connected' || query.counters) {
// run LIST
mailboxListing = await this.listMailboxes(query);
if (mailboxListing && mailboxListing.error) {
Expand Down Expand Up @@ -944,13 +957,14 @@ class Account {
unseen: true
};
}

return await this.call({
let x = await this.call({
cmd: 'listMailboxes',
account: this.account,
options,
timeout: this.timeout
});

return x;
}

async moveMessage(message, target) {
Expand Down Expand Up @@ -1402,16 +1416,6 @@ class Account {

await this.loadAccountData(this.account, true);

let path = normalizePath(query.path);
let encodedMailboxData = await this.redis.hgetBuffer(this.getMailboxListKey(), path);
if (!encodedMailboxData) {
let message = 'Mailbox record was not found';
let error = Boom.boomify(new Error(message), { statusCode: 404 });
error.output.payload.path = query.path;
throw error;
}

// mailbox seems to exist, so call parent to resolve open connection
return await this.call(
Object.assign(
{
Expand Down Expand Up @@ -1809,16 +1813,6 @@ class Account {

await this.loadAccountData(this.account, true);

let path = normalizePath(query.path);
let encodedMailboxData = await this.redis.hgetBuffer(this.getMailboxListKey(), path);
if (!encodedMailboxData) {
let message = 'Mailbox record was not found';
let error = Boom.boomify(new Error(message), { statusCode: 404 });
error.output.payload.path = query.path;
throw error;
}

// mailbox seems to exist, so call parent to resolve open connection
return await this.call(
Object.assign(
{
Expand Down Expand Up @@ -2203,6 +2197,14 @@ class Account {
cached
};
}

async isApiClient(accountData) {
if (accountData.oauth2?.provider) {
let app = await oauth2Apps.get(accountData.oauth2.provider);
return app?.baseScopes === 'api';
}
return false;
}
}

module.exports = { Account };
1 change: 0 additions & 1 deletion lib/api-client/gmail-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ class GmailClient extends BaseClient {

return a.path.toLowerCase().localeCompare(b.path.toLowerCase());
});
console.log(555, mailboxes);

return mailboxes;
}
Expand Down
52 changes: 26 additions & 26 deletions translations/messages.pot
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
msgid ""
msgstr ""
"Content-Type: text/plain; charset=ascii\n"
"POT-Creation-Date: 2024-05-07 12:38+0000\n"
"POT-Creation-Date: 2024-05-08 10:50+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 @@ -57,27 +53,8 @@ msgstr ""
msgid "Enter your email address"
msgstr ""

#: views/accounts/register/imap.hbs:11
msgid "Your name"
msgstr ""

#: views/accounts/register/imap.hbs:17
msgid "Enter your full name"
msgstr ""

#: views/accounts/register/imap.hbs:31
#: views/accounts/register/imap-server.hbs:35
#: views/accounts/register/imap-server.hbs:114
msgid "Password"
msgstr ""

#: views/accounts/register/imap.hbs:37
msgid "Enter your account password"
msgstr ""

#: views/accounts/register/imap.hbs:51
#: views/accounts/register/imap-server.hbs:192
msgid "Continue"
#: views/redirect.hbs:1
msgid "Click <a href=\"%s\">here</a> to continue&mldr;"
msgstr ""

#: views/accounts/register/index.hbs:2
Expand All @@ -97,6 +74,12 @@ msgstr ""
msgid "Username"
msgstr ""

#: views/accounts/register/imap-server.hbs:35
#: views/accounts/register/imap-server.hbs:114
#: views/accounts/register/imap.hbs:31
msgid "Password"
msgstr ""

#: views/accounts/register/imap-server.hbs:41
#: views/accounts/register/imap-server.hbs:46
#: views/accounts/register/imap-server.hbs:120
Expand Down Expand Up @@ -157,6 +140,11 @@ msgstr ""
msgid "Test settings"
msgstr ""

#: views/accounts/register/imap-server.hbs:192
#: views/accounts/register/imap.hbs:51
msgid "Continue"
msgstr ""

#: views/accounts/register/imap-server.hbs:200
msgid "Continue without testing"
msgstr ""
Expand Down Expand Up @@ -189,6 +177,18 @@ msgstr ""
msgid "HTTP error!"
msgstr ""

#: views/accounts/register/imap.hbs:11
msgid "Your name"
msgstr ""

#: views/accounts/register/imap.hbs:17
msgid "Enter your full name"
msgstr ""

#: views/accounts/register/imap.hbs:37
msgid "Enter your account password"
msgstr ""

#: lib/routes-ui.js:581
msgid "Invalid API key for OpenAI"
msgstr ""
Expand Down

0 comments on commit eaf1ff7

Please sign in to comment.