Skip to content

Commit

Permalink
feat(mailbox): add "Get Quota" operation
Browse files Browse the repository at this point in the history
(cherry picked from commit e5152ae)
  • Loading branch information
jreyesr authored and umanamente committed Aug 15, 2024
1 parent 4764925 commit 62abb23
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nodes/Imap/operations/mailbox/OperationsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import { IResourceDef } from "../../utils/CommonDefinitions";
import { resourceMailbox } from "./ResourceName";
import { createMailboxOperation } from "./functions/MailboxCreate";
import { getMailboxListOperation } from "./functions/MailboxGetList";
import {getMailboxQuotaOperation} from "./functions/MailboxGetQuota";
import { getMailboxStatusOperation } from "./functions/MailboxGetStatus";
import { renameMailboxOperation } from "./functions/MailboxRename";

export const mailboxResourceDefinitions: IResourceDef = {
resource: resourceMailbox,
operationDefs: [
getMailboxListOperation,
getMailboxQuotaOperation,
getMailboxStatusOperation,
createMailboxOperation,
renameMailboxOperation,
Expand Down
34 changes: 34 additions & 0 deletions nodes/Imap/operations/mailbox/functions/MailboxGetQuota.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
import {ImapFlow} from 'imapflow';
import { IResourceOperationDef } from '../../../utils/CommonDefinitions';
import { getMailboxPathFromNodeParameter, parameterSelectMailbox } from '../../../utils/SearchFieldParameters';

export const getMailboxQuotaOperation: IResourceOperationDef = {
operation: {
name: 'Get Quota',
value: 'getMailboxQuota',
description: 'Get quota (space usage) of an account',
},
parameters: [
{
...parameterSelectMailbox,
description: 'Select the mailbox',
hint: "Leave as INBOX unless your email provider supports per-folder quotas"
},
],
async executeImapAction(context: IExecuteFunctions, itemIndex: number, client: ImapFlow): Promise<INodeExecutionData[] | null> {
let returnData: INodeExecutionData[] = [];
const mailboxPath = getMailboxPathFromNodeParameter(context, itemIndex);

let info = await client.getQuota(mailboxPath);
if (info === false || info === undefined) {
// do nothing, returnData is left as an empty array (0 items)
} else {
let item_json = JSON.parse(JSON.stringify(info));
returnData.push({
json: item_json,
});
}
return returnData;
},
};

0 comments on commit 62abb23

Please sign in to comment.