fix: make sure webserver works & message is marked as read Closes #3

This commit is contained in:
Saahil 2024-10-01 00:51:16 +00:00 committed by GitHub
parent 4c3dd2b17b
commit 2d7d68905f
2 changed files with 11 additions and 12 deletions

View file

@ -1,5 +1,4 @@
default:
dev
dev: dev:
npm run dev npm run dev

View file

@ -57,7 +57,10 @@ manageCode = (codeOrUrl) ->
} }
openInbox = (cb) -> openInbox = (cb) ->
imap.openBox 'INBOX', true, cb || ((err, box) -> if err then throw err) # WHY DOES the t/f actually matter?
# =(
# @see https://github.com/mscdex/node-imap/issues/430#issuecomment-59636298
imap.openBox 'INBOX', false, cb || ((err, box) -> if err then throw err)
# https://github.com/mscdex/node-imap/issues/764#issuecomment-1716322864 # https://github.com/mscdex/node-imap/issues/764#issuecomment-1716322864
imap.connect() imap.connect()
@ -78,7 +81,6 @@ imap.on 'mail', (numNewMsgs) ->
console.log "New email" console.log "New email"
f = imap.fetch(results, { bodies: '', markSeen: true }) f = imap.fetch(results, { bodies: '', markSeen: true })
f.on 'message', (mstream) -> f.on 'message', (mstream) ->
mstream.on 'body', (stream) -> mstream.on 'body', (stream) ->
simpleParser stream, (err, mail) -> simpleParser stream, (err, mail) ->
if err then throw err if err then throw err
@ -102,17 +104,15 @@ imap.on 'mail', (numNewMsgs) ->
when 'login@hackclub.com' then parseLogin(mail) when 'login@hackclub.com' then parseLogin(mail)
when 'sprig@hackclub.com' then parseSprig(mail) when 'sprig@hackclub.com' then parseSprig(mail)
# console.log mail.text # console.log mail.text
stream.once 'end', ->
mstream.on 'attributes', (attrs) -> mstream.on 'attributes', (attrs) ->
console.log 'Attributes:', attrs console.log 'Attributes:', attrs
uid = attrs.uid uid = attrs.uid
imap.addFlags uid, ['\\Seen'], (err) -> imap.addFlags(uid, ['\\Seen'], (err) -> if err then throw err else console.log 'Marked as seen 2')
if err then throw err
f.on 'end', -> f.on 'end', ->
console.log "Done fetching all messages" console.log "Done fetching all messages ", results
imap.setFlags results, ['\\Seen'], (err) -> imap.setFlags results, ['\\Seen'], (err) ->
if err then throw err if err then throw err
console.log('Marked as read')
else else
console.log "No new email" console.log "No new email"