import { ImapFlow } from 'imapflow';

const client = new ImapFlow({
  host: 'imap.gmail.com',
  port: 993,
  secure: true,
  auth: {
    user: process.env.GMAIL_EMAIL || 'garfield.heron@gmail.com',
    pass: process.env.GMAIL_APP_PASSWORD || 'ldmk duee movy hruy',
  },
  logger: false,
});

try {
  console.log('Connecting to Gmail IMAP...');
  await client.connect();
  console.log('Connected!');
  
  const mailbox = await client.mailboxOpen('INBOX');
  console.log('Mailbox opened:', mailbox.path, 'messages:', mailbox.exists);
  
  const criteria = { or: [{ subject: 'test' }, { from: 'test' }] };
  const uids = await client.search(criteria, { uid: true });
  console.log('Search results:', uids);
  
  await client.logout();
  console.log('Done');
} catch (err) {
  console.error('ERROR:', err.message);
  console.error(err.stack);
  process.exit(1);
}
