Email Summarizer — Python CLI by Joshua KushnirEmail Summarizer — Python CLI by Joshua Kushnir

Email Summarizer — Python CLI

Joshua Kushnir

Joshua Kushnir

A small Python CLI that turns a noisy inbox into a one-page digest using OpenAI. Point it at .eml files or a live IMAP inbox; get back a prioritized list of what actually needs your attention.

What it does

Each email gets a structured summary: TL;DR headline, 2-3 sentence body, priority, category, and an explicit action_required flag. Output as a colored terminal table, a markdown digest you can paste into a standup, or JSON for further processing.
Email Digest (3 messages) ┏━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳──────────────────────────────────────────┳━━━━━━━━┓ ┃ Priority ┃ From ┃ Headline ┃ Action ┃ ┡━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇──────────────────────────────────────────╇━━━━━━━━┩ │ HIGH │ Priya Shah │ Q3 priorities, headcount & migration ETA │ YES │ │ LOW │ TLDR Newsletter │ Apple's $500B chip bet, OpenAI Agents v2 │ — │ │ LOW │ GitHub │ PR #14 opened on JoshuaKushnir/ai-chatbot│ — │ └──────────┴──────────────────────┴──────────────────────────────────────────┴────────┘

How it works

Parse.eml files via Python's email package; IMAP via imaplib over SSL
Summarize — each message goes to OpenAI Chat Completions with response_format=json_object and a system prompt that locks the output schema (headline, summary, action_required, priority, category)
Renderrich for terminal tables, a hand-rolled markdown renderer, and raw JSON for piping into other tools
Bodies are truncated to 6000 chars before sending, so a single noisy newsletter can't blow up token usage.

Technical patterns

Structured JSON outputs from OpenAI. Every model response is locked to a strict schema. No free-form text parsing.
Dual input sources. Local .eml files for offline testing and demos; live IMAP over SSL for production inboxes. Same pipeline, same output.
Three output formats. Rich terminal tables for quick scanning, markdown for pasting into standups or docs, JSON for piping into other tools.
57 pytest tests. Covers .eml parsing (plain, HTML, multipart), all three renderers, summarize with mocked OpenAI client, CLI parser, IMAP env validation, and glob expansion.

Stack

Python 3.10+
OpenAI Chat Completions (gpt-4o-mini) with response_format=json_object
Rich for terminal output
imaplib for live inbox access
pytest for testing (57 tests)
Like this project

Posted May 20, 2026

A Python CLI that turns a noisy inbox into a prioritized digest using OpenAI structured outputs.