Skip to content

Commit

Permalink
fix: new imap
Browse files Browse the repository at this point in the history
  • Loading branch information
abuaboud committed Feb 21, 2024
1 parent 9a7e1d5 commit e1e1696
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
23 changes: 12 additions & 11 deletions packages/pieces/community/imap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,27 @@ export const imapAuth = PieceAuth.CustomAuth({
}),
},
validate: async ({ auth }) => {
const imapConfig = imapCommon.constructConfig(
auth as {
host: string;
username: string;
password: string;
port: number;
tls: boolean;
}
);
const imapClient = new ImapFlow({ ...imapConfig, logger: false });
try {
const imapConfig = imapCommon.constructConfig(
auth as {
host: string;
username: string;
password: string;
port: number;
tls: boolean;
}
);
const imapClient = new ImapFlow({ ...imapConfig, logger: false });
await imapClient.connect();
await imapClient.noop();
await imapClient.logout();
return { valid: true };
} catch (e) {
return {
valid: false,
error: JSON.stringify(e),
};
} finally {
await imapClient.logout();
}
},
required: true,
Expand Down
4 changes: 1 addition & 3 deletions packages/pieces/community/imap/src/lib/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ export const imapCommon = {
value: mailbox.path,
};
});
} catch (error) {
throw error;
} finally {
await imapClient.logout();
}
Expand Down Expand Up @@ -88,7 +86,7 @@ export const imapCommon = {
);
const imapClient = new ImapFlow({ ...imapConfig, logger: false });
await imapClient.connect();
let lock = await imapClient.getMailboxLock(mailbox);
const lock = await imapClient.getMailboxLock(mailbox);
try {
const res = imapClient.fetch(
{
Expand Down

0 comments on commit e1e1696

Please sign in to comment.