#!/usr/bin/env node /** * Fetches a pool of disposable email addresses from Guerrilla Mail API * and writes them to scripts/test-emails.txt (one per line). * * Usage: node scripts/fetch-test-emails.mjs [count] * Default count: 10 */ import { writeFileSync } from 'fs'; import { fileURLToPath } from 'url'; import { dirname, join } from 'path'; const COUNT = parseInt(process.argv[2] ?? '10', 10); const OUT = join(dirname(fileURLToPath(import.meta.url)), 'test-emails.txt'); const API = 'http://api.guerrillamail.com/ajax.php'; async function fetchEmail() { const url = `${API}?f=get_email_address&ip=127.0.0.1&agent=resetea-test-script`; const res = await fetch(url); if (!res.ok) throw new Error(`HTTP ${res.status}`); const data = await res.json(); if (!data.email_addr) throw new Error(`Unexpected response: ${JSON.stringify(data)}`); return data.email_addr; } async function main() { const emails = new Set(); let attempts = 0; const maxAttempts = COUNT * 3; process.stdout.write(`Fetching ${COUNT} addresses`); while (emails.size < COUNT && attempts < maxAttempts) { attempts++; try { const addr = await fetchEmail(); if (!emails.has(addr)) { emails.add(addr); process.stdout.write('.'); } // Small delay to avoid hammering the API await new Promise(r => setTimeout(r, 300)); } catch (e) { process.stderr.write(`\n[warn] ${e.message}`); } } process.stdout.write('\n'); const lines = [...emails].join('\n') + '\n'; writeFileSync(OUT, lines, 'utf8'); console.log(`Saved ${emails.size} addresses → ${OUT}`); } main().catch(e => { console.error(e.message); process.exit(1); });