File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ( ) ;
Original file line number Diff line number Diff line change 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/**/*" ],
You can’t perform that action at this time.
0 commit comments