Skip to content

Commit 83a6c98

Browse files
committed
Fixed issues
1 parent ad64b2b commit 83a6c98

2 files changed

Lines changed: 22 additions & 16 deletions

File tree

src/classes/Handlers/ImapHandler.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,26 @@ export default class ImapHandler {
2727
return;
2828
}
2929
this.imap.on("exists", async (data) => {
30-
if (!this.imap.mailbox) {
31-
return;
32-
}
33-
const newCount = data.count - data.prevCount;
34-
const messages = await this.imap.fetchAll(
35-
`${this.imap.mailbox.exists - newCount + 1}:*`,
36-
{ envelope: true, source: true },
37-
);
38-
for (const message of messages) {
39-
if (!message.source) {
40-
continue;
41-
}
42-
const parsedMail = await simpleParser(message.source);
43-
this.client.emit("mail", parsedMail);
44-
}
30+
const lock = await this.imap.getMailboxLock("INBOX");
31+
try {
32+
if (!this.imap.mailbox) {
33+
return;
34+
}
35+
const newCount = data.count - data.prevCount;
36+
const messages = await this.imap.fetchAll(
37+
`${this.imap.mailbox.exists - newCount + 1}:*`,
38+
{ envelope: true, source: true },
39+
);
40+
for (const message of messages) {
41+
if (!message.source) {
42+
continue;
43+
}
44+
const parsedMail = await simpleParser(message.source);
45+
this.client.emit("mail", parsedMail);
46+
}
47+
} finally {
48+
lock.release();
49+
}
4550
});
4651
} finally {
4752
lock.release();

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"#utils/*": ["utils/*"],
2222
"#client": ["classes/Ryneczek.ts"],
2323
"#types/": ["types/*"],
24-
"#prisma": ["../prisma/generated/prisma/client"]
24+
"#prisma": ["../prisma/generated/prisma/client"],
25+
"#agents/*": ["agents/*"]
2526
}
2627
},
2728
"include": ["src/**/*"],

0 commit comments

Comments
 (0)