Skip to content

feat(tools/mail-source/imap): land the concrete CLI for the IMAP stub - #1466

Merged
onlyarnav merged 4 commits into
apache:mainfrom
liwenjie200543:feat/mail-source-imap-cli
Oct 2, 2026
Merged

onlyarnav merged 4 commits into
apache:mainfrom
liwenjie200543:feat/mail-source-imap-cli

Conversation

@liwenjie200543

Copy link
Copy Markdown
Contributor

Implements the mail-source contract's IMAP adapter per
tools/mail-source/imap/README.md, closing #303.

What changed

  • New uv-managed package tools/mail-source/imap/ (stdlib only — imaplib
    • email), registered as a workspace member.
  • Six console scripts, one per contract operation: imap-source-threads,
    imap-source-read, imap-source-drafts, imap-source-sent,
    imap-source-create-draft, imap-source-thread-url.
  • Threads are canonicalised on the root RFC-5322 Message-ID
    (thread_id_kind: rfc5322-message-id); create_draft attaches to the
    chronologically last message on the thread per
    tools/gmail/threading.md and only ever APPENDs — drafts, never sends.
  • Decline-don't-fake exit codes per the contract: 0 ok, 2 configuration
    error, 3 capability declined (e.g. a read-only shared role mailbox
    without a writable Drafts folder — the skill's resolution chain falls
    through to the next backend), 4 server-side failure.
  • Recipients come from the calling skill (--to / --cc), which resolves
    security_cc per the contract; the adapter never invents a recipient and
    never hardcodes an organization address.
  • The stub README becomes the concrete adapter doc (environment variables,
    run/test/lint instructions, adopter declaration); the contract's
    capability-matrix row drops its stub caveat.

How checked

  • PYTHONPATH=src;tests python -m pytest in tools/mail-source/imap/ —
    24 cases against a fake IMAP backend with the same method surface as the
    real client (no network): threading canonicalisation, per-operation
    behaviour, drafts/sent declines, APPEND-refusal decline, config parsing,
    archive-URL template and imap:// fallback.
  • ruff check + ruff format --check + strict mypy clean.
  • CLI smoke: imap-source-thread-url end-to-end (template + fallback),
    config-error path exits 2, connection-refused exits 4.

Gen-AI disclosure

Authored with ZCode (GLM) under
docs/ai-contribution-policy.md;
every line reviewed and the checks above run locally by me before posting.

Implements the mail-source contract's IMAP adapter per tools/mail-source/imap/README.md
and issue apache#303: six stdlib-only console scripts (list_recent_threads, read_thread,
list_drafts, list_sent_since, create_draft, thread_url) with UID-based access,
root-Message-ID thread canonicalisation, threading headers per the shared gmail
threading rule, and the decline-don't-fake exit-code contract (0/2/3/4) for
read-only shared role mailboxes.

Tests run against a fake IMAP backend with the same method surface; ruff and
strict mypy are clean. The package is registered as a workspace member and the
contract's capability-matrix note drops its stub caveat.

Generated-by: ZCode (GLM, coding agent)

Authored-by: liwenjie200543 <liwenjie200543@users.noreply.github.com>
Comment thread tools/mail-source/imap/src/imap_source/mailbox.py Fixed
Comment thread tools/mail-source/imap/src/imap_source/mailbox.py Fixed
Comment thread tools/mail-source/imap/src/imap_source/mailbox.py Fixed
Comment thread tools/mail-source/imap/src/imap_source/mailbox.py Fixed
Comment thread tools/mail-source/imap/src/imap_source/mailbox.py Fixed
Comment thread tools/mail-source/imap/src/imap_source/mailbox.py Fixed
Required by the prek uv-lock hook after adding tools/mail-source/imap to
[tool.uv.workspace] members.

Generated-by: ZCode (GLM, coding agent)

Authored-by: liwenjie200543 <liwenjie200543@users.noreply.github.com>
@github-actions github-actions Bot added the contract:mail-source Tool capability: inbound-mail ingestion (mbox / IMAP / ...) label Sep 29, 2026
…otocol stubs

Clears the CodeQL code-scanning findings on mailbox.py: the _QUOTED
pattern was left behind when the unquote() helper went away, and the
Protocol methods' bare '...' bodies read as no-effect statements.

Generated-by: ZCode (GLM, coding agent)

Authored-by: liwenjie200543 <liwenjie200543@users.noreply.github.com>
…otocol stubs

Clears the CodeQL code-scanning findings on mailbox.py: the _QUOTED
pattern was left behind when the unquote() helper went away, and the
Protocol methods' bare '...' bodies read as no-effect statements.

Generated-by: ZCode (GLM, coding agent)

Authored-by: liwenjie200543 <liwenjie200543@users.noreply.github.com>

@Kaap10 Kaap10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Really clean and thorough implementation of the IMAP adapter (#303).

Appreciate keeping it strictly to the Python stdlib (imaplib / email) without pulling in external dependencies, and supporting IMAP_SOURCE_PASSWORD_FILE so secrets don't leak in ps process lists.

The "decline, don't fake" exit codes and draft-only APPEND behavior align perfectly with the contract.

@onlyarnav onlyarnav left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@onlyarnav
onlyarnav merged commit 3c86798 into apache:main Oct 2, 2026
51 checks passed
onlyarnav added a commit to liwenjie200543/magpie that referenced this pull request Oct 2, 2026
Resolve workspace member conflict in pyproject.toml after apache#1466.

Co-authored-by: Arnav <imarnavpurohit@gmail.com>
onlyarnav added a commit to liwenjie200543/magpie that referenced this pull request Oct 2, 2026
Resolve workspace member conflict in pyproject.toml after apache#1466.

Co-authored-by: Arnav <imarnavpurohit@gmail.com>
@potiuk potiuk added family:ci .github workflows, prek, validators family:docs Docs, MISSION.md, READMEs family:tools tools/* labels Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contract:mail-source Tool capability: inbound-mail ingestion (mbox / IMAP / ...) family:ci .github workflows, prek, validators family:docs Docs, MISSION.md, READMEs family:tools tools/*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants