Attachment Test 4: scan_attachments.py Smoke Test

Status: PASSED 2026-03-16

Tests count_attachments() in scan_attachments.py with fabricated MIME messages. No live IMAP needed.

Refactor

Extracted the counting logic from scan_attachments() into a new count_attachments(raw_messages) function that returns (summary, filenames, total_emails, total_with_attachments). scan_attachments() now fetches raw bytes from IMAP and passes them to count_attachments(), then prints the results. The __main__ block is unchanged.

Output

PASS — all 4 cases passed

Cases Covered

1. Single PDF attachmentsummary['application/pdf'] == 1, filename recorded correctly.

2. Plain email, no attachmentstotal_with_attachments == 0, summary empty.

3. Inline image (Content-Disposition: inline) → NOT counted. total_with_attachments == 0.

4. Two attachments in one emailtotal_with_attachments == 2, both filenames recorded.

How to Run

cd ~/py/envoy && python3 test_scan_attachments.py
version 2  ·  created 2026-03-16  ·  updated 2026-03-16  ·  status passed