const Imap = require('imap'); const { simpleParser } = require('mailparser'); const imap = new Imap({ user: 'cococlawdy@gmail.com', password: 'wvfi htti cusm ypal', host: 'imap.gmail.com', port: 993, tls: true, tlsOptions: { rejectUnauthorized: false } }); function openInbox(cb) { imap.openBox('INBOX', true, cb); } imap.once('ready', function() { openInbox(function(err, box) { if (err) throw err; // Search for all emails from the last 7 days imap.search([['SINCE', new Date(Date.now() - 7 * 24 * 60 * 60 * 1000)]], function(err, results) { if (err) throw err; if (!results || !results.length) { console.log('No messages found'); imap.end(); return; } console.log(`Found ${results.length} messages from last 7 days`); const f = imap.fetch(results, { bodies: '' }); f.on('message', function(msg, seqno) { msg.on('body', function(stream, info) { simpleParser(stream, async (err, parsed) => { if (err) throw err; // Look for audition/guide related emails const fromText = parsed.from?.text?.toLowerCase() || ''; const subject = parsed.subject?.toLowerCase() || ''; const text = parsed.text?.toLowerCase() || ''; if (fromText.includes('dick') || fromText.includes('whimsy') || subject.includes('audition') || subject.includes('guide') || subject.includes('test') || subject.includes('prep101') || text.includes('audition') || text.includes('guide')) { console.log('\n=== RELEVANT EMAIL ==='); console.log('Seq:', seqno); console.log('From:', parsed.from.text); console.log('Subject:', parsed.subject); console.log('Date:', parsed.date); console.log('Text:', parsed.text?.substring(0, 1000)); if (parsed.attachments && parsed.attachments.length > 0) { console.log('Attachments:', parsed.attachments.map(a => a.filename).join(', ')); } console.log('======================\n'); } }); }); }); f.once('end', function() { console.log('\nDone scanning messages'); imap.end(); }); }); }); }); imap.once('error', function(err) { console.error('IMAP Error:', err); }); imap.once('end', function() { console.log('Connection ended'); }); imap.connect();