Skip to content

Commit eaf1ff7

Browse files
committed
Functioning list messages and list mailboxes API endpoints for Gmail API
1 parent 0ec46a6 commit eaf1ff7

File tree

3 files changed

+51
-50
lines changed

3 files changed

+51
-50
lines changed

lib/account.js

+25-23
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,20 @@ class Account {
827827
let accountData = await this.loadAccountData(this.account, false);
828828

829829
let mailboxListing;
830-
if (accountData.state === 'connected' || query.counters) {
830+
if (await this.isApiClient(accountData)) {
831+
mailboxListing = await this.listMailboxes(query);
832+
833+
if (mailboxListing && mailboxListing.error) {
834+
let error = Boom.boomify(new Error(mailboxListing.error), { statusCode: mailboxListing.statusCode || 500 });
835+
if (mailboxListing.code) {
836+
error.output.payload.code = mailboxListing.code;
837+
}
838+
throw error;
839+
}
840+
841+
// just pass through, do nothing
842+
return mailboxListing;
843+
} else if (accountData.state === 'connected' || query.counters) {
831844
// run LIST
832845
mailboxListing = await this.listMailboxes(query);
833846
if (mailboxListing && mailboxListing.error) {
@@ -944,13 +957,14 @@ class Account {
944957
unseen: true
945958
};
946959
}
947-
948-
return await this.call({
960+
let x = await this.call({
949961
cmd: 'listMailboxes',
950962
account: this.account,
951963
options,
952964
timeout: this.timeout
953965
});
966+
967+
return x;
954968
}
955969

956970
async moveMessage(message, target) {
@@ -1402,16 +1416,6 @@ class Account {
14021416

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

1405-
let path = normalizePath(query.path);
1406-
let encodedMailboxData = await this.redis.hgetBuffer(this.getMailboxListKey(), path);
1407-
if (!encodedMailboxData) {
1408-
let message = 'Mailbox record was not found';
1409-
let error = Boom.boomify(new Error(message), { statusCode: 404 });
1410-
error.output.payload.path = query.path;
1411-
throw error;
1412-
}
1413-
1414-
// mailbox seems to exist, so call parent to resolve open connection
14151419
return await this.call(
14161420
Object.assign(
14171421
{
@@ -1809,16 +1813,6 @@ class Account {
18091813

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

1812-
let path = normalizePath(query.path);
1813-
let encodedMailboxData = await this.redis.hgetBuffer(this.getMailboxListKey(), path);
1814-
if (!encodedMailboxData) {
1815-
let message = 'Mailbox record was not found';
1816-
let error = Boom.boomify(new Error(message), { statusCode: 404 });
1817-
error.output.payload.path = query.path;
1818-
throw error;
1819-
}
1820-
1821-
// mailbox seems to exist, so call parent to resolve open connection
18221816
return await this.call(
18231817
Object.assign(
18241818
{
@@ -2203,6 +2197,14 @@ class Account {
22032197
cached
22042198
};
22052199
}
2200+
2201+
async isApiClient(accountData) {
2202+
if (accountData.oauth2?.provider) {
2203+
let app = await oauth2Apps.get(accountData.oauth2.provider);
2204+
return app?.baseScopes === 'api';
2205+
}
2206+
return false;
2207+
}
22062208
}
22072209

22082210
module.exports = { Account };

lib/api-client/gmail-client.js

-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ class GmailClient extends BaseClient {
255255

256256
return a.path.toLowerCase().localeCompare(b.path.toLowerCase());
257257
});
258-
console.log(555, mailboxes);
259258

260259
return mailboxes;
261260
}

translations/messages.pot

+26-26
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
msgid ""
22
msgstr ""
33
"Content-Type: text/plain; charset=ascii\n"
4-
"POT-Creation-Date: 2024-05-07 12:38+0000\n"
4+
"POT-Creation-Date: 2024-05-08 10:50+0000\n"
55

66
#: views/config/license.hbs:48
77
msgid "%d day"
88
msgid_plural "%d days"
99
msgstr[0] ""
1010
msgstr[1] ""
1111

12-
#: views/redirect.hbs:1
13-
msgid "Click <a href=\"%s\">here</a> to continue&mldr;"
14-
msgstr ""
15-
1612
#: views/unsubscribe.hbs:1
1713
#: views/unsubscribe.hbs:79
1814
msgid "Unsubscribe"
@@ -57,27 +53,8 @@ msgstr ""
5753
msgid "Enter your email address"
5854
msgstr ""
5955

60-
#: views/accounts/register/imap.hbs:11
61-
msgid "Your name"
62-
msgstr ""
63-
64-
#: views/accounts/register/imap.hbs:17
65-
msgid "Enter your full name"
66-
msgstr ""
67-
68-
#: views/accounts/register/imap.hbs:31
69-
#: views/accounts/register/imap-server.hbs:35
70-
#: views/accounts/register/imap-server.hbs:114
71-
msgid "Password"
72-
msgstr ""
73-
74-
#: views/accounts/register/imap.hbs:37
75-
msgid "Enter your account password"
76-
msgstr ""
77-
78-
#: views/accounts/register/imap.hbs:51
79-
#: views/accounts/register/imap-server.hbs:192
80-
msgid "Continue"
56+
#: views/redirect.hbs:1
57+
msgid "Click <a href=\"%s\">here</a> to continue&mldr;"
8158
msgstr ""
8259

8360
#: views/accounts/register/index.hbs:2
@@ -97,6 +74,12 @@ msgstr ""
9774
msgid "Username"
9875
msgstr ""
9976

77+
#: views/accounts/register/imap-server.hbs:35
78+
#: views/accounts/register/imap-server.hbs:114
79+
#: views/accounts/register/imap.hbs:31
80+
msgid "Password"
81+
msgstr ""
82+
10083
#: views/accounts/register/imap-server.hbs:41
10184
#: views/accounts/register/imap-server.hbs:46
10285
#: views/accounts/register/imap-server.hbs:120
@@ -157,6 +140,11 @@ msgstr ""
157140
msgid "Test settings"
158141
msgstr ""
159142

143+
#: views/accounts/register/imap-server.hbs:192
144+
#: views/accounts/register/imap.hbs:51
145+
msgid "Continue"
146+
msgstr ""
147+
160148
#: views/accounts/register/imap-server.hbs:200
161149
msgid "Continue without testing"
162150
msgstr ""
@@ -189,6 +177,18 @@ msgstr ""
189177
msgid "HTTP error!"
190178
msgstr ""
191179

180+
#: views/accounts/register/imap.hbs:11
181+
msgid "Your name"
182+
msgstr ""
183+
184+
#: views/accounts/register/imap.hbs:17
185+
msgid "Enter your full name"
186+
msgstr ""
187+
188+
#: views/accounts/register/imap.hbs:37
189+
msgid "Enter your account password"
190+
msgstr ""
191+
192192
#: lib/routes-ui.js:581
193193
msgid "Invalid API key for OpenAI"
194194
msgstr ""

0 commit comments

Comments
 (0)