← back to George Gmail

trash-cron-drift-noise.js

36 lines

// trash-cron-drift-noise.js — one-shot cleanup of the benign cron-drift CRITICAL
// alert flood in info@ (security-monitor:n8nserver1, Jun 12 2026). Re-baselined at
// 14:23 UTC so no new ones fire; this just clears the ~20 already-sent copies.
// Scoped: info account ONLY, subject must match the cron-drift alert. Dry-run unless --go.
const fs = require("fs");
const { google } = require("googleapis");
const ENV = "/Users/macstudio3/Projects/Designer-Wallcoverings/DW-MCP/.env";
const env = {};
fs.readFileSync(ENV, "utf8").split("\n").forEach(l => { const m = l.match(/^([^#=]+)=(.+)/); if (m) env[m[1].trim()] = m[2].trim(); });

const GO = process.argv.includes("--go");
const QUERY = 'subject:"cron file drift" from:steve@designerwallcoverings.com newer_than:3d';

(async () => {
  const oc = new google.auth.OAuth2(env.GMAIL_CLIENT_ID, env.GMAIL_CLIENT_SECRET, "http://localhost:9850/oauth2callback");
  oc.setCredentials({ refresh_token: env.INFO_REFRESH_TOKEN });
  const gm = google.gmail({ version: "v1", auth: oc });

  const ids = []; let pageToken = null;
  do {
    const r = await gm.users.messages.list({ userId: "me", q: QUERY, maxResults: 500, pageToken: pageToken || undefined });
    (r.data.messages || []).forEach(m => ids.push(m.id));
    pageToken = r.data.nextPageToken || null;
  } while (pageToken);

  console.log(`info@ — matched ${ids.length} cron-drift alert message(s) for query: ${QUERY}`);
  if (ids.length === 0) { console.log("nothing to trash"); return; }
  if (!GO) { console.log("DRY RUN — re-run with --go to trash. Sample IDs:", ids.slice(0, 5).join(", ")); return; }

  await gm.users.messages.batchModify({
    userId: "me",
    requestBody: { ids, addLabelIds: ["TRASH"], removeLabelIds: ["INBOX", "UNREAD"] }
  });
  console.log(`✓ trashed ${ids.length} cron-drift alert(s) from info@`);
})().catch(e => { console.error("ERR", e.message); process.exit(1); });