Add digest command to email processor
Read-only summary of recent decisions, grouped by action with [auto]/[user] markers. Supports --recent N for multi-day lookback.
This commit is contained in:
@@ -19,6 +19,8 @@ Subcommands:
|
||||
python main.py review all <action> # act on all pending
|
||||
python main.py review accept # accept all suggestions
|
||||
python main.py stats # show decision history
|
||||
python main.py digest # today's processed emails
|
||||
python main.py digest --recent 3 # last 3 days
|
||||
|
||||
Action mapping (what each classification does to the email):
|
||||
delete -> himalaya message delete <id> (moves to Trash)
|
||||
@@ -633,6 +635,56 @@ def cmd_stats():
|
||||
print(f"\nKnown labels: {', '.join(sorted(labels))}")
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Subcommand: digest
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def cmd_digest(days=1):
|
||||
"""Print a compact summary of recently processed emails, grouped by action.
|
||||
|
||||
Shows both auto and user decisions with a marker to distinguish them.
|
||||
"""
|
||||
grouped = decision_store.get_recent_decisions(days)
|
||||
|
||||
if not grouped:
|
||||
period = "today" if days == 1 else f"last {days} days"
|
||||
print(f"No processed emails in this period ({period}).")
|
||||
return
|
||||
|
||||
period_label = "today" if days == 1 else f"last {days} days"
|
||||
print(f"Email digest ({period_label})")
|
||||
print("=" * 40)
|
||||
|
||||
# Map action names to display labels
|
||||
action_labels = {
|
||||
"delete": "Deleted",
|
||||
"archive": "Archived",
|
||||
"keep": "Kept",
|
||||
"mark_read": "Marked read",
|
||||
}
|
||||
|
||||
total = 0
|
||||
auto_count = 0
|
||||
user_count = 0
|
||||
|
||||
for action, entries in sorted(grouped.items()):
|
||||
label = action_labels.get(action, action.replace("label:", "Labeled ").title())
|
||||
print(f"\n{label} ({len(entries)}):")
|
||||
for entry in entries:
|
||||
source = entry.get("source", "?")
|
||||
sender = entry.get("sender", "unknown")
|
||||
subject = entry.get("subject", "(no subject)")
|
||||
print(f" [{source}] {sender}")
|
||||
print(f" {subject}")
|
||||
total += 1
|
||||
if source == "auto":
|
||||
auto_count += 1
|
||||
else:
|
||||
user_count += 1
|
||||
|
||||
print(f"\nTotal: {total} emails processed ({auto_count} auto, {user_count} user)")
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Entry point & argument parsing
|
||||
#
|
||||
@@ -695,7 +747,10 @@ if __name__ == "__main__":
|
||||
elif subcommand == "stats":
|
||||
cmd_stats()
|
||||
|
||||
elif subcommand == "digest":
|
||||
cmd_digest(days=recent if recent else 1)
|
||||
|
||||
else:
|
||||
print(f"Unknown subcommand: {subcommand}")
|
||||
print("Usage: python main.py [scan|review|stats] [--recent N] [--dry-run]")
|
||||
print("Usage: python main.py [scan|review|stats|digest] [--recent N] [--dry-run]")
|
||||
sys.exit(1)
|
||||
|
||||
Reference in New Issue
Block a user