[object Object]

← back to Claude Mail

claude-mail: add read-only inbox/sent audit diagnostics

ec9022a6eb18abd2d8033ec70012a916c86611b9 · 2026-06-25 15:30:06 -0700 · Steve

Files touched

Diff

commit ec9022a6eb18abd2d8033ec70012a916c86611b9
Author: Steve <steve@designerwallcoverings.com>
Date:   Thu Jun 25 15:30:06 2026 -0700

    claude-mail: add read-only inbox/sent audit diagnostics
---
 inbox-audit.js | 24 ++++++++++++++++++++++++
 sent-audit.js  | 21 +++++++++++++++++++++
 2 files changed, 45 insertions(+)

diff --git a/inbox-audit.js b/inbox-audit.js
new file mode 100644
index 0000000..e9fe149
--- /dev/null
+++ b/inbox-audit.js
@@ -0,0 +1,24 @@
+'use strict';
+// READ-ONLY: list all INBOX messages with uid, \Seen flag, from, subject, date, body snippet.
+const { ImapFlow } = require('imapflow');
+const { cfg } = require('./lib');
+(async () => {
+  const c = new ImapFlow({ host: cfg.imapHost, port: cfg.imapPort, secure: true,
+    auth: { user: cfg.user, pass: cfg.pass }, logger: false });
+  await c.connect();
+  const lock = await c.getMailboxLock('INBOX');
+  try {
+    const all = await c.search({ all: true });
+    console.log(`INBOX total: ${all.length}`);
+    for await (const msg of c.fetch(all, { uid: true, flags: true, envelope: true, bodyStructure: false, source: true })) {
+      const seen = msg.flags && msg.flags.has('\\Seen') ? 'SEEN ' : 'UNSEEN';
+      const from = msg.envelope?.from?.[0]?.address || '?';
+      const subj = msg.envelope?.subject || '(no subj)';
+      const date = msg.envelope?.date ? new Date(msg.envelope.date).toISOString() : '?';
+      // crude body extract
+      let body = '';
+      try { const { simpleParser } = require('mailparser'); const p = await simpleParser(msg.source); body = (p.text||'').replace(/\s+/g,' ').trim().slice(0,200); } catch {}
+      console.log(`\n[uid ${msg.uid}] ${seen} | ${date}\n  from: ${from}\n  subj: ${subj}\n  body: ${body}`);
+    }
+  } finally { lock.release(); await c.logout().catch(()=>{}); }
+})().catch(e => { console.error('AUDIT FAILED:', e.message); process.exit(1); });
diff --git a/sent-audit.js b/sent-audit.js
new file mode 100644
index 0000000..6246b87
--- /dev/null
+++ b/sent-audit.js
@@ -0,0 +1,21 @@
+'use strict';
+const { ImapFlow } = require('imapflow');
+const { simpleParser } = require('mailparser');
+const { cfg } = require('./lib');
+(async () => {
+  const c = new ImapFlow({ host: cfg.imapHost, port: cfg.imapPort, secure: true,
+    auth: { user: cfg.user, pass: cfg.pass }, logger: false });
+  await c.connect();
+  for (const box of ['Sent','INBOX.Sent']) {
+    let lock; try { lock = await c.getMailboxLock(box); } catch { continue; }
+    try {
+      const all = await c.search({ all: true });
+      console.log(`\n===== ${box}: ${all.length} msgs =====`);
+      for await (const m of c.fetch(all.slice(-12), { uid:true, source:true })) {
+        const p = await simpleParser(m.source);
+        console.log(`\n--- to=${p.to?.text} | ${p.date?.toISOString?.()||''}\n  subj: ${p.subject}\n  body: ${(p.text||'').replace(/\s+/g,' ').trim().slice(0,400)}`);
+      }
+    } finally { lock.release(); }
+  }
+  await c.logout().catch(()=>{});
+})().catch(e=>{console.error('SENT AUDIT FAILED:',e.message);process.exit(1);});

← 261df12 claude-mail: tolerate spaces/case in secret phrase; restore  ·  back to Claude Mail  ·  claude-mail: self-heal — page Steve via CNCP+macOS+George wh d59fd42 →