IMAP Mailbox Data Harvesting
IMAP provides richer mailbox access than POP3 — multiple folders, server-side SEARCH, and non-destructive read-only access via EXAMINE. The approach is: list all folders, assess message counts, run server-side searches for high-value subjects, triage by headers, then fetch full bodies only for confirmed high-value messages. Always use EXAMINE instead of SELECT to avoid marking messages as read.
Connect and List All Folders
a1 OK Logged in. * LIST (\HasNoChildren) "." INBOX * LIST (\HasNoChildren) "." Sent * LIST (\HasNoChildren) "." Drafts * LIST (\HasNoChildren) "." IT-Notifications * LIST (\HasNoChildren) "." VPN-Credentials a2 OK List completed.
Custom folder names like IT-Notifications and VPN-Credentials are immediate targets. Sent folders often contain outbound mail with internal system references and credentials shared between staff.
Get Message Counts Per Folder
* STATUS INBOX (MESSAGES 47 UNSEEN 12) * STATUS Sent (MESSAGES 312) * STATUS VPN-Credentials (MESSAGES 3)
Server-Side Search for High-Value Subjects
IMAP SEARCH runs on the server — far faster than pulling all headers locally. Search by subject keyword across the mailbox:
* SEARCH 3 14 27 * SEARCH 8 * SEARCH * SEARCH 41 * SEARCH 3
Message IDs 3, 8, 14, 27, and 41 matched high-value subject keywords. Fetch headers for these specific messages before pulling full bodies:
Fetch Headers for Targeted Messages
* 3 FETCH (BODY[HEADER.FIELDS (FROM TO SUBJECT DATE)] {142}
From: IT Support <[email protected]>
To: [email protected]
Subject: Your temporary password is ready
Date: Mon, 28 Mar 2026 09:00:00 +0000
)
Fetch Full Message Bodies
After header triage confirms high-value content, fetch full bodies for targeted message IDs using BODY.PEEK to preserve unseen status:
From: IT Support <[email protected]> Subject: Your temporary password is ready Hi John, Your temporary password is: TempP@ss2026! Please log in at https://vpn.company.com and change it immediately.
Search Sent Folder for Outbound Credentials
The Sent folder often contains credentials shared via email between staff — passwords sent to new users, VPN keys, and API tokens:
* SEARCH 12 45 67 * SEARCH 12 * SEARCH 45 89
Extract Internal Hostnames from Received Headers
Received: from dc01.company.local (dc01.company.local [10.10.10.10]) Received: from mail01.company.local (mail01.company.local [10.10.10.50])
Internal hostnames and IPs from Received headers map infrastructure without scanning. dc01.company.local at 10.10.10.10 is a domain controller — test for Kerberos attacks and credential reuse immediately.
Save All Messages to Disk
For full offline analysis of a high-value mailbox, dump all messages from INBOX to local files:
Saved 47 messages
Your temporary password is: TempP@ss2026! VPN PSK: SuperSecretPSK2026 API Key: sk-prod-xK2aB1cD3eF4gH5i
Important
Always use EXAMINE instead of SELECT. EXAMINE is read-only and does not mark messages as read or alter any mailbox flags. STORE and EXPUNGE are destructive — never use them during an assessment.
References
-
RFC 3501 — IMAP4rev1www.rfc-editor.org/rfc/rfc3501 (opens in new tab)
EXAMINE, SEARCH, FETCH, and BODY.PEEK command reference
Was this helpful?
Your feedback helps improve this page.