Loading content...
Email has become the backbone of professional and personal communication, with many users receiving hundreds of messages daily. Without robust organizational tools, the inbox becomes an overwhelming river of information where important messages drown in noise. IMAP addresses this challenge through two complementary mechanisms: folders (called mailboxes in IMAP terminology) for organizing messages by location, and flags for marking message states and attributes.
Unlike local file organization where you alone decide the structure, IMAP folders exist on the server—visible and synchronized across all your devices. Mark a message as 'Flagged' on your phone, and it appears starred on your desktop. Move an email to 'Receipts' from webmail, and your email client on your laptop sees it there too.
This page provides a deep exploration of IMAP's organizational capabilities: how folder hierarchies work, the standardized special-use folders that every email system should provide, the semantics of system and custom flags, and real-world patterns for effective email organization.
This page covers: mailbox hierarchy structure and naming, special-use folder designations (Sent, Drafts, Trash, Archive), system flags and their precise meanings, custom keywords for extended workflows, subscription management, and strategies for email organization that leverage IMAP's capabilities effectively.
IMAP organizes messages into mailboxes (what users call folders). These mailboxes form a hierarchical namespace, similar to a file system's directory structure, but with protocol-specific rules and behaviors.
Hierarchy Separators
Unlike file systems that universally use / (Unix) or \ (Windows), IMAP allows servers to define their own hierarchy separator character. Common separators include:
. (period) — Dovecot, Cyrus, many Unix servers/ (slash) — Gmail, some enterprise servers\ (backslash) — Rare, some Windows-based serversClients discover the separator using the LIST command:
a001 LIST "" ""
* LIST (\Noselect) "." ""
a001 OK LIST completed
The separator . means mailbox paths like Archive.2024.ProjectA.
12345678910111213141516171819202122232425262728293031323334353637
# List all mailboxes showing hierarchya001 LIST "" "*" * LIST (\HasNoChildren) "." "INBOX"* LIST (\HasNoChildren \Drafts) "." "Drafts"* LIST (\HasNoChildren \Sent) "." "Sent"* LIST (\HasNoChildren \Trash) "." "Trash"* LIST (\HasNoChildren \Junk) "." "Junk"* LIST (\HasChildren) "." "Archive"* LIST (\HasNoChildren) "." "Archive.2022"* LIST (\HasNoChildren) "." "Archive.2023"* LIST (\HasNoChildren) "." "Archive.2024"* LIST (\HasChildren) "." "Projects"* LIST (\HasNoChildren) "." "Projects.AlphaRelease"* LIST (\HasNoChildren) "." "Projects.BetaTesting"* LIST (\HasChildren) "." "Projects.ClientWork"* LIST (\HasNoChildren) "." "Projects.ClientWork.ClientA"* LIST (\HasNoChildren) "." "Projects.ClientWork.ClientB"a001 OK LIST completed # Visualization of this hierarchy:## INBOX# Drafts (\Drafts)# Sent (\Sent)# Trash (\Trash)# Junk (\Junk)# Archive# ├── 2022# ├── 2023# └── 2024# Projects# ├── AlphaRelease# ├── BetaTesting# └── ClientWork# ├── ClientA# └── ClientBMailbox Attributes
Each mailbox in the LIST response includes attributes describing its properties:
Namespace Prefixes
Many servers organize mailboxes into namespaces, revealed by the NAMESPACE command:
a001 NAMESPACE
* NAMESPACE (("" ".")) (("#shared." ".")) (("#public." "."))
a001 OK NAMESPACE completed
This shows three namespaces:
"") — User's own mailboxes#shared.) — Mailboxes shared by other users#public.) — Organization-wide public foldersIMAP uses a modified UTF-7 encoding for mailbox names to support international characters. The folder 'Café Orders' would be encoded as 'Caf&AOk-_Orders'. Most email clients handle this automatically, but if you're debugging IMAP sessions or writing tools, be aware of this encoding requirement.
Every email system needs certain standard folders: a place for drafts, for sent messages, for trash. But what should these folders be named? 'Sent' or 'Sent Items' or 'Sent Messages'? Different email systems historically used different names, causing interoperability problems.
The SPECIAL-USE extension (RFC 6154) solves this by assigning semantic attributes to folders, regardless of their display names. A folder can be named 'Envoyés' in French but carry the \Sent attribute that clients recognize.
| Attribute | Purpose | Typical Names |
|---|---|---|
| \All | Contains all user messages (virtual folder) | All Mail, All Messages |
| \Archive | Long-term storage of completed messages | Archive, Archives |
| \Drafts | Messages being composed but not yet sent | Drafts, Draft |
| \Flagged | Messages marked as important (virtual) | Starred, Flagged |
| \Important | Messages determined to be important | Important, Priority |
| \Junk | Spam or junk messages | Junk, Spam, Junk Email |
| \Sent | Copies of sent messages | Sent, Sent Items, Sent Mail |
| \Trash | Deleted messages awaiting permanent deletion | Trash, Deleted Items, Bin |
1234567891011121314151617181920212223242526272829
# Check if server supports SPECIAL-USEa001 CAPABILITY* CAPABILITY IMAP4rev1 ... SPECIAL-USE ...a001 OK CAPABILITY completed # List mailboxes with special-use attributesa001 LIST "" "*" RETURN (SPECIAL-USE) * LIST (\HasNoChildren) "." "INBOX"* LIST (\HasNoChildren \Drafts) "." "Drafts"* LIST (\HasNoChildren \Sent) "." "Sent"* LIST (\HasNoChildren \Trash) "." "Trash"* LIST (\HasNoChildren \Junk) "." "Spam"* LIST (\HasNoChildren \Archive) "." "Archive"a001 OK LIST completed # Gmail's special-use foldersa001 LIST "" "*"* LIST (\HasNoChildren \All) "/" "[Gmail]/All Mail"* LIST (\HasNoChildren \Drafts) "/" "[Gmail]/Drafts"* LIST (\HasNoChildren \Important) "/" "[Gmail]/Important"* LIST (\HasNoChildren \Sent) "/" "[Gmail]/Sent Mail"* LIST (\HasNoChildren \Junk) "/" "[Gmail]/Spam"* LIST (\HasNoChildren \Flagged) "/" "[Gmail]/Starred"* LIST (\HasNoChildren \Trash) "/" "[Gmail]/Trash" # Creating a folder with special-use attributea001 CREATE "Archives" (USE (\Archive))a001 OK CREATE completedHow Email Clients Use Special-Use
When you click 'Send' in your email client, the client needs to know where to save the sent copy. Without special-use:
With special-use:
This works seamlessly across languages and email providers.
Some special-use folders are 'virtual'—they don't physically store messages but show views of messages stored elsewhere. Gmail's 'All Mail' (\All) contains every message in the account and is virtual; messages actually reside in specific labels/folders. The 'Starred' (\Flagged) folder shows all messages with the \Flagged flag from any folder.
IMAP defines a set of system flags—standard markers that track message status. Unlike folder organization (where messages are), flags describe message state (what's been done with them). Understanding flag semantics is essential for proper email client behavior.
The Standard System Flags:
123456789101112131415161718192021222324252627282930
# When user opens email (client fetches body, auto-sets \Seen)a001 FETCH 47 (BODY[TEXT])* 47 FETCH (BODY[TEXT] {1234}... FLAGS (\Seen)) # To preview without marking as read, use BODY.PEEKa001 FETCH 47 (BODY.PEEK[TEXT])* 47 FETCH (BODY[TEXT] {1234}...)# \Seen flag NOT set # User clicks star buttona001 STORE 47 +FLAGS (\Flagged)* 47 FETCH (FLAGS (\Seen \Flagged)) # User clicks reply, then sends reply successfullya002 STORE 47 +FLAGS (\Answered)* 47 FETCH (FLAGS (\Seen \Flagged \Answered)) # User deletes message (two-step process typically)# Step 1: Move to Trasha003 MOVE 47 "Trash"* OK [COPYUID 1704067200 47 892] MOVE completed # Later: Empty Trash (mark all as \Deleted, then EXPUNGE)a004 SELECT "Trash"a005 STORE 1:* +FLAGS (\Deleted)a006 EXPUNGE* 1 EXPUNGE* 1 EXPUNGE...a006 OK EXPUNGE completedA common source of confusion: setting \Deleted doesn't delete the message! It marks it for future deletion. Until EXPUNGE runs, the message is still there and can be recovered. Some clients auto-expunge on folder close (CLOSE command), others require explicit action. Users who 'delete' but never empty trash may find their quota filled with 'deleted' messages.
Two additional system flags—\Draft and \Recent—have distinct semantics worth detailed exploration.
\Draft — Work in Progress
The \Draft flag indicates a message is still being composed and hasn't been sent yet.
1234567891011121314151617181920212223242526272829
# User starts composing email# Client saves draft immediatelya001 APPEND "Drafts" (\Draft \Seen) {523}+ OKFrom: alice@example.comTo: bob@example.comSubject: Project UpdateContent-Type: text/plain Draft content here...a001 OK [APPENDUID 1704067200 901] APPEND completed# Draft saved with UID 901 # User continues editing, client auto-saves every 60 seconds# Delete old drafta002 UID STORE 901 +FLAGS (\Deleted)a003 UID EXPUNGE 901 # Save new versiona004 APPEND "Drafts" (\Draft \Seen) {1047}+ OK[Updated message content]a004 OK [APPENDUID 1704067200 902] APPEND completed # User finishes and sends# After successful SMTP send:a005 UID STORE 902 +FLAGS (\Deleted)a006 UID EXPUNGE 902# Draft is gone; sent copy saved to Sent folder\Recent — Session Freshness Indicator
The \Recent flag has unique semantics—it's controlled entirely by the server and cannot be set by clients.
\Recent Rules:
Practical Implications:
The \Recent flag was designed for an era when users had a single email client. With multi-device access, \Recent became unreliable—whichever device connected first would clear it. Modern clients use UIDNEXT (the next UID to be assigned) to determine new messages: any message with UID >= last known UIDNEXT is new. This works reliably regardless of which device checked first.
Beyond system flags, IMAP supports keywords—custom flags defined by users or applications. Keywords enable workflows and organizational schemes not possible with system flags alone.
Keyword Capabilities:
The server's PERMANENTFLAGS response indicates keyword support:
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft \*)]
The \* indicates the server accepts new keywords. Without \*, only system flags can be stored.
| Keyword | Purpose | Used By |
|---|---|---|
| $Forwarded | Message has been forwarded | Thunderbird, Apple Mail, most clients |
| $MDNSent | Read receipt was sent | Various clients |
| $SubmitPending | Message submission pending | Some clients |
| $Submitted | Message has been submitted | Some clients |
| $Junk | Manually marked as junk | SpamAssassin integration |
| $NotJunk | Marked as not junk (ham) | SpamAssassin integration |
| $Phishing | Suspected phishing message | Security tools |
123456789101112131415161718192021222324252627
# Check PERMANENTFLAGS to see allowed flags/keywordsa001 SELECT INBOX* FLAGS (\Answered \Flagged \Deleted \Seen \Draft $Forwarded $MDNSent)* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft $Forwarded $MDNSent \*)]... # User forwards a messagea002 STORE 47 +FLAGS ($Forwarded)* 47 FETCH (FLAGS (\Seen \Answered $Forwarded)) # Custom workflow: Mark for follow-up tomorrowa003 STORE 47 +FLAGS ($FollowUp $Tomorrow)* 47 FETCH (FLAGS (\Seen \Answered $Forwarded $FollowUp $Tomorrow)) # Search by keyworda004 SEARCH KEYWORD $FollowUp* SEARCH 47 89 156 # Remove workflow keyword when completea005 STORE 47 -FLAGS ($FollowUp $Tomorrow)* 47 FETCH (FLAGS (\Seen \Answered $Forwarded)) # Gmail labels exposed as keywords# Note: Gmail's implementation is uniquea001 SELECT "[Gmail]/All Mail"* FLAGS (\Answered \Flagged \Deleted \Seen \Draft work personal $Important)# Custom labels appear as keywords in some contextsKeyword Naming Conventions:
$ are non-standard but commonly used\ are reserved for system flagsUse Cases for Custom Keywords:
Keywords and folders solve different problems. A message can have multiple keywords but exists in only one folder. Use keywords for cross-cutting attributes (priority, status, action required) and folders for categorical organization (by project, sender, topic). Effective email organization often combines both.
As mailbox hierarchies grow, users may not want to see every folder in their client. IMAP's subscription mechanism lets users choose which folders appear in their folder list without deleting them.
How Subscription Works:
Each mailbox can be subscribed or unsubscribed. The subscription state is stored on the server, synchronized across devices. Clients can show only subscribed mailboxes (LSUB command) or all mailboxes (LIST command).
12345678910111213141516171819202122232425262728293031
# Subscribe to a mailboxa001 SUBSCRIBE "Archive/2024"a001 OK SUBSCRIBE completed # Unsubscribe from a mailboxa002 UNSUBSCRIBE "Archive/2020"a002 OK UNSUBSCRIBE completed # List only subscribed mailboxesa003 LSUB "" "*"* LSUB () "." "INBOX"* LSUB () "." "Drafts"* LSUB () "." "Sent"* LSUB () "." "Trash"* LSUB () "." "Archive"* LSUB () "." "Archive.2023"* LSUB () "." "Archive.2024"* LSUB () "." "Projects"a003 OK LSUB completed # Compare with full LIST to see unsubscribed foldersa004 LIST "" "*"# Shows all mailboxes including unsubscribed like Archive.2020, Archive.2021 # Modern alternative: LIST-EXTENDED with SUBSCRIBEDa005 LIST "" "*" RETURN (SUBSCRIBED)* LIST (\HasNoChildren \Subscribed) "." "INBOX"* LIST (\HasNoChildren \Subscribed \Drafts) "." "Drafts"* LIST (\HasNoChildren) "." "Archive.2019" # Not subscribed* LIST (\HasNoChildren \Subscribed) "." "Archive.2024" # Subscribed...Subscription Strategies:
Auto-Subscription Behavior:
When creating new mailboxes:
a001 CREATE "Projects/NewProject"
a001 OK CREATE completed
a002 SUBSCRIBE "Projects/NewProject"
a002 OK SUBSCRIBE completed
Unsubscribing from a folder doesn't prevent messages from being delivered there (via server-side rules) or stored there. It only hides the folder from LSUB listings. A server rule can continue filing messages into an unsubscribed folder; you just won't easily see them in your client.
With IMAP's folder and flag capabilities understood, let's examine practical strategies for effective email organization. The goal is a system that reduces inbox overload, ensures important messages don't get lost, and enables efficient retrieval.
Folder Hierarchy Patterns:
# Pattern 1: Role-Based OrganizationINBOX├── Action Required # Needs your response/action├── Waiting For # Waiting for someone else├── Reference # Information you might need later├── Archive # Completed items│ ├── 2024│ ├── 2023│ └── 2022└── [System folders: Drafts, Sent, Trash, Junk] # Pattern 2: Project-Based OrganizationINBOX├── Projects│ ├── ProjectA│ ├── ProjectB│ └── ClientWork│ ├── ClientX│ └── ClientY├── Admin # HR, facilities, etc.├── Subscriptions # Newsletters, updates└── Archive # Pattern 3: GTD (Getting Things Done) StyleINBOX # Collect everything here├── @Action # Requires your action├── @Waiting # Delegated, waiting for response├── @Someday # Maybe later├── @Reference # Information filing└── Archive # Pattern 4: Hybrid (Projects + Status)INBOX├── Active Projects│ ├── ProjectA│ └── ProjectB├── Action Required # Cross-project urgent items├── Clients│ ├── ClientX│ └── ClientY├── Reference│ ├── Policies│ └── Procedures├── Receipts # Financial records└── Archive/YYYYFlag Usage Patterns:
| Purpose | Approach | Why |
|---|---|---|
| Need to reply | \Flagged + keep in INBOX | High visibility until handled |
| Important reference | \Flagged + file to Reference | Flagged items easy to find via SEARCH FLAGGED |
| Read for later | Mark unread (remove \Seen) | Appears bold, counts as unread |
| Processed | \Seen + archive to folder | Cleared from INBOX view |
| In-progress response | \Draft in Drafts folder | Standard draft handling |
Don't over-organize into too many folders—you'll spend more time filing than working. IMAP's SEARCH is powerful: 'SEARCH FROM alice SUBJECT report' finds messages instantly across folders. Maintain a simple structure and rely on search for precise retrieval. Many productive users have just INBOX, Archive, and system folders.
IMAP's folder and flag system provides a robust foundation for email organization that scales from individuals to enterprises. Let's consolidate the key insights:
What's Next:
The final page of this module provides a comprehensive comparison: IMAP vs POP3. We'll systematically examine the differences between these two protocols, when to use each, and why IMAP has become the dominant choice for modern email access.
You now understand IMAP's organizational mechanisms: hierarchical mailbox structures, special-use folder identification, system and custom flags, and subscription management. These tools enable effective email organization that synchronizes across all your devices, from folder structure to message states.