Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Jul 4, 2024
1 parent cea28f6 commit f73002f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 29 deletions.
16 changes: 12 additions & 4 deletions lib/api-client/gmail-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,13 @@ class GmailClient extends BaseClient {
.join('/')
.replace(/^INBOX(\/|$)/gi, 'INBOX');

for (let label of Object.keys(SYSTEM_LABELS)) {
if (SYSTEM_LABELS[label].toLowerCase() === path.toLowerCase()) {
path = label;
break;
}
}

for (let label of Object.keys(SYSTEM_NAMES)) {
if (SYSTEM_NAMES[label].toLowerCase() === path.toLowerCase()) {
path = label;
Expand Down Expand Up @@ -1954,7 +1961,7 @@ class GmailClient extends BaseClient {
}

Object.defineProperty(attachment, 'content', {
value: (await this.getAttachment(attachment.id)).toString(),
value: (await this.getAttachment(attachment.id))?.data?.toString(),
enumerable: false
});
}
Expand Down Expand Up @@ -2115,7 +2122,7 @@ class GmailClient extends BaseClient {

if (!attachment.content && attachment.contentId && messageInfo.text.html.indexOf(`cid:${attachment.contentId.replace(/^<|>$/g, '')}`) >= 0) {
try {
attachment.content = (await this.getAttachment(attachment.id)).toString('base64');
attachment.content = (await this.getAttachment(attachment.id))?.data?.toString('base64');
} catch (err) {
this.logger.error({ msg: 'Failed to load attachment content', attachment, err });
}
Expand Down Expand Up @@ -2145,7 +2152,8 @@ class GmailClient extends BaseClient {
if (['text/calendar', 'application/ics'].includes(attachment.contentType)) {
if (!attachment.content) {
try {
attachment.content = (await this.getAttachment(attachment.id)).toString('base64');
let calendarBuf = (await this.getAttachment(attachment.id))?.data;
attachment.content = calendarBuf.toString('base64');
} catch (err) {
this.logger.error({ msg: 'Failed to load attachment content', attachment, err });
}
Expand Down Expand Up @@ -2355,7 +2363,7 @@ class GmailClient extends BaseClient {
// already downloaded in a previous step
continue;
} else {
attachment.content = (await this.getAttachment(attachment.id)).toString('base64');
attachment.content = (await this.getAttachment(attachment.id))?.data?.toString('base64');
}

attachmentList.set(contentId, {
Expand Down
12 changes: 10 additions & 2 deletions lib/imap-connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -1620,11 +1620,19 @@ class IMAPConnection extends BaseClient {
options = options || {};
this.checkIMAPConnection();

if (!this.mailboxes.has(normalizePath(options.path))) {
let path = normalizePath(options.path);
if (['\\Junk', '\\Sent', '\\Trash', '\\Inbox', '\\Drafts', '\\All'].includes(path)) {
let resolvedPath = await this.getSpecialUseMailbox('\\Sent');
if (resolvedPath) {
path = resolvedPath.path;
}
}

if (!this.mailboxes.has(path)) {
return false; //?
}

let mailbox = this.mailboxes.get(normalizePath(options.path));
let mailbox = this.mailboxes.get(path);

let listing = await mailbox.listMessages(options, true, true);
return listing;
Expand Down
40 changes: 19 additions & 21 deletions lib/schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,27 +322,30 @@ const settingsSchema = {

enableApiProxy: Joi.boolean().truthy('Y', 'true', '1', 'on').falsy('N', 'false', 0, '').description('Enable support for reverse proxies'),

documentStoreEnabled: Joi.boolean().truthy('Y', 'true', '1', 'on').falsy('N', 'false', 0, '').description('Enable Document Store syncing'),
documentStoreEnabled: Joi.boolean().truthy('Y', 'true', '1', 'on').falsy('N', 'false', 0, '').description('Deprecated. Enable Document Store syncing'),
documentStoreUrl: Joi.string()
.uri({
scheme: ['http', 'https'],
allowRelative: false
})
.allow('')
.example('https://localhost:9200')
.description('Document Store URL'),
documentStoreIndex: Joi.string().empty('').max(1024).description('Document Store index name'),
documentStoreAuthEnabled: Joi.boolean().truthy('Y', 'true', '1', 'on').falsy('N', 'false', 0, '').description('Enable Document Store authentication'),
documentStoreUsername: Joi.string().empty('').max(1024).description('Document Store username'),
documentStorePassword: Joi.string().empty('').max(1024).description('Document Store password'),
.description('Deprecated. Document Store URL'),
documentStoreIndex: Joi.string().empty('').max(1024).description('Deprecated. Document Store index name'),
documentStoreAuthEnabled: Joi.boolean()
.truthy('Y', 'true', '1', 'on')
.falsy('N', 'false', 0, '')
.description('Deprecated. Enable Document Store authentication'),
documentStoreUsername: Joi.string().empty('').max(1024).description('Deprecated. Document Store username'),
documentStorePassword: Joi.string().empty('').max(1024).description('Deprecated. Document Store password'),
documentStoreGenerateEmbeddings: Joi.boolean()
.truthy('Y', 'true', '1', 'on')
.falsy('N', 'false', 0, '')
.description('If true, then generates vector embeddings for the email and stores these in the Document Store'),
.description('Deprecated. If true, then generates vector embeddings for the email and stores these in the Document Store'),
documentStorePreProcessingEnabled: Joi.boolean()
.truthy('Y', 'true', '1', 'on')
.falsy('N', 'false', 0, '')
.description('Enable Document Store pre-processing'),
.description('Deprecated. Enable Document Store pre-processing'),

locale: Joi.string()
.max(100)
Expand All @@ -361,13 +364,13 @@ const settingsSchema = {
.allow('')
.max(512 * 1024)
.example('return true; // passes all emails')
.description('Filter function for Document Store pre-processing (JavaScript)'),
.description('Deprecated. Filter function for Document Store pre-processing (JavaScript)'),

documentStorePreProcessingMap: Joi.string()
.allow('')
.max(512 * 1024)
.example('return payload; // returns unmodified data')
.description('Mapping function for Document Store pre-processing (JavaScript)')
.description('Deprecated. Mapping function for Document Store pre-processing (JavaScript)')
};

const addressSchema = Joi.object({
Expand Down Expand Up @@ -778,7 +781,7 @@ const messageEntrySchema = Joi.object({
}).description('Encoded message part sizes')
}).label('TextInfo'),

preview: Joi.string().description('Text preview for messages loaded from Document Store')
preview: Joi.string().description('Text preview for messages loaded from Document Store or Gmail API')
}).label('MessageListEntry');

const messageSpecialUseSchema = Joi.string()
Expand All @@ -791,10 +794,7 @@ const messageDetailsSchema = Joi.object({
id: Joi.string().example('AAAAAgAACrI').description('Message ID').label('MessageEntryId'),
uid: Joi.number().integer().example(12345).description('UID of the message').label('MessageUid'),
emailId: Joi.string().example('1694937972638499881').description('Globally unique ID (if server supports it)').label('MessageEmailId'),
threadId: Joi.string()
.example('1694936993596975454')
.description('Thread ID (if server supports it). Always set for messages retrieved from Document Store.')
.label('MessageThreadId'),
threadId: Joi.string().example('1694936993596975454').description('Thread ID (if server supports it)').label('MessageThreadId'),
date: Joi.date().iso().example('2021-03-22T13:13:31.000Z').description('Date (internal)'),
draft: Joi.boolean().example(false).description('Is this message marked as a draft'),
unseen: Joi.boolean().example(true).description('Is this message unseen'),
Expand Down Expand Up @@ -830,9 +830,7 @@ const messageDetailsSchema = Joi.object({
.unknown(),

text: Joi.object({
id: Joi.string()
.example('AAAAAgAACqiTkaExkaEykA')
.description('Pointer to message text content. The value is `null` for messages retrieved from Document Store.'),
id: Joi.string().example('AAAAAgAACqiTkaExkaEykA').description('Pointer to message text content'),
encodedSize: Joi.object({
plain: Joi.number().integer().example(1013).description('How many bytes for plain text'),
html: Joi.number().integer().example(1013).description('How many bytes for html content')
Expand Down Expand Up @@ -989,7 +987,7 @@ const documentStoreSchema = Joi.boolean()
.empty('')
.truthy('Y', 'true', '1')
.falsy('N', 'false', 0)
.description('If enabled then fetch the data from the Document Store instead of IMAP')
.description('Deprecated. If enabled then fetch the data from the Document Store instead of IMAP')
.label('UseDocumentStore');

const searchSchema = Joi.object({
Expand Down Expand Up @@ -1084,13 +1082,13 @@ const accountSchemas = {
.iso()
.allow(null)
.example('2021-07-08T07:06:34.336Z')
.description('Sync messages to document store starting from provided date. If not set, all emails are synced.'),
.description('Deprecated. Sync messages to document store starting from provided date. If not set, all emails are synced.'),

notifyFrom: Joi.date()
.iso()
.allow(null)
.example('2021-07-08T07:06:34.336Z')
.description('Send webhooks for messages starting from provided date. The default is the account creation date.'),
.description('Send webhooks for messages starting from provided date. The default is the account creation date. Only applies for IMAP accounts.'),

subconnections: Joi.array()
.items(Joi.string().max(256))
Expand Down
9 changes: 7 additions & 2 deletions workers/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4392,7 +4392,11 @@ When making API calls remember that requests against the same account are queued
}),

query: Joi.object({
path: Joi.string().required().example('INBOX').description('Mailbox folder path').label('Path'),
path: Joi.string()
.required()
.example('INBOX')
.description('Mailbox folder path. Can use special use labels like "\\Sent".')
.label('SpecialPath'),

cursor: Joi.string()
.trim()
Expand Down Expand Up @@ -4507,7 +4511,8 @@ When making API calls remember that requests against the same account are queued
otherwise: Joi.required()
})
.example('INBOX')
.description('Mailbox folder path'),
.description('Mailbox folder path. Can use special use labels like "\\Sent".')
.label('SpecialPathDs'),

cursor: Joi.string()
.trim()
Expand Down

0 comments on commit f73002f

Please sign in to comment.