diff --git a/inbox2matrix.ts b/inbox2matrix.ts index 13f6b82..d60b2fa 100644 --- a/inbox2matrix.ts +++ b/inbox2matrix.ts @@ -14,45 +14,21 @@ function openInbox(cb) { imap.once('ready', function() { openInbox(function(err, box) { if (err) throw err; - var f = imap.seq.fetch('*', { - bodies: 'HEADER.FIELDS (FROM TO SUBJECT DATE)', - struct: true - }); - f.on('message', function(msg, seqno) { - console.log('Message #%d', seqno); - var prefix = '(#' + seqno + ') '; - msg.on('body', function(stream, info) { - var buffer = ''; - stream.on('data', function(chunk) { - buffer += chunk.toString('utf8'); - }); - stream.once('end', function() { - console.log(prefix + 'Parsed header: %s', inspect(Imap.parseHeader(buffer))); - }); - }); - msg.once('attributes', function(attrs) { - console.log(prefix + 'Attributes: %s', inspect(attrs, false, 8)); - }); - msg.once('end', function() { - console.log(prefix + 'Finished'); - }); - }); - f.once('error', function(err) { - console.log('Fetch error: ' + err); - }); - f.once('end', function() { - console.log('Done fetching all messages!'); - imap.end(); - }); + console.log('ready'); }); }); imap.once('mail', (numNewMsgs : number) => { - console.log(numNewMsgs); + console.log(`You have ${numNewMsgs} mail`); +}); + +imap.once('update', (seqno : number, info : object) => { + console.log(info); }); imap.once('error', function(err) { console.log(err); + imap.end(); }); imap.once('end', function() {