What needs to be done?
Description
The current IMAP implementation does not enforce read-only semantics when a mailbox is selected using the EXAMINE command.
According to the IMAP specification, a mailbox opened with EXAMINE must be treated as read-only, meaning that any mutating operations should be restricted.
However, the current implementation allows state-changing commands such as EXPUNGE and CLOSE to proceed even when the mailbox is in read-only mode. This behavior is explicitly noted as a gap in:
selection.go (CLOSE handling)
message.go (EXPUNGE handling)
Expected Behavior
When a mailbox is selected using EXAMINE:
- The session must be marked as read-only
- The following commands must be restricted:
🔴 EXPUNGE
- Must fail in read-only mode
- Should return an appropriate tagged response (e.g.,
NO)
🔴 CLOSE
- Must not remove messages
- Should behave safely without altering mailbox state
🔴 Other mutating commands (if applicable)
- Commands like
STORE, APPEND, COPY, etc., should also be reviewed and restricted if they modify mailbox state
Current Behavior
EXPUNGE executes even in read-only mode
CLOSE may remove messages despite EXAMINE
- No consistent enforcement of read-only state across command handlers
Scope of Work
- Introduce a read-only flag in the session/mailbox state when
EXAMINE is used
- Update command handlers to check this flag before performing mutations
- Ensure all mutating commands respect read-only mode
- Return proper IMAP responses for restricted operations
Suggested Approach
1. Update mailbox/session state:
session.readOnly = true // when EXAMINE is used
2. Add guard checks in mutating commands:
if session.readOnly {
return NO response (e.g., "Mailbox is read-only")
}
3. Audit all commands that modify mailbox state:
| Command |
Action Required |
| EXPUNGE |
Return NO in read-only mode |
| CLOSE |
Skip expunge step; do not alter state |
| STORE |
Return NO in read-only mode |
| APPEND |
Return NO in read-only mode |
| COPY |
Review and restrict if state is modified |
Acceptance Criteria
Additional Notes
- This change is important for protocol compliance and client compatibility
- Many IMAP clients rely on correct read-only enforcement for safe operations
- The implementation should be consistent across all command handlers
References
# [TASK] Enforce read-only semantics for EXAMINE-selected mailboxes
Description
The current IMAP implementation does not enforce read-only semantics when a mailbox is selected using the EXAMINE command.
According to the IMAP specification, a mailbox opened with EXAMINE must be treated as read-only, meaning that any mutating operations should be restricted.
However, the current implementation allows state-changing commands such as EXPUNGE and CLOSE to proceed even when the mailbox is in read-only mode. This behavior is explicitly noted as a gap in:
selection.go:223 (CLOSE handling)
message.go:1575 (EXPUNGE handling)
Expected Behavior
When a mailbox is selected using EXAMINE:
- The session must be marked as read-only
- The following commands must be restricted:
🔴 EXPUNGE
- Must fail in read-only mode
- Should return an appropriate tagged response (e.g.,
NO)
🔴 CLOSE
- Must not remove messages
- Should behave safely without altering mailbox state
🔴 Other mutating commands (if applicable)
- Commands like
STORE, APPEND, COPY, etc., should also be reviewed and restricted if they modify mailbox state
Current Behavior
EXPUNGE executes even in read-only mode
CLOSE may remove messages despite EXAMINE
- No consistent enforcement of read-only state across command handlers
Scope of Work
- Introduce a read-only flag in the session/mailbox state when
EXAMINE is used
- Update command handlers to check this flag before performing mutations
- Ensure all mutating commands respect read-only mode
- Return proper IMAP responses for restricted operations
Suggested Approach
1. Update mailbox/session state:
session.readOnly = true // when EXAMINE is used
2. Add guard checks in mutating commands:
if session.readOnly {
return NO response (e.g., "Mailbox is read-only")
}
3. Audit all commands that modify mailbox state:
| Command |
Action Required |
EXPUNGE |
Return NO in read-only mode |
CLOSE |
Skip expunge step; do not alter state |
STORE |
Return NO in read-only mode |
APPEND |
Return NO in read-only mode |
COPY |
Review and restrict if state is modified |
Acceptance Criteria
Additional Notes
- This change is important for protocol compliance and client compatibility
- Many IMAP clients rely on correct read-only enforcement for safe operations
- The implementation should be consistent across all command handlers
References
What needs to be done?
Description
The current IMAP implementation does not enforce read-only semantics when a mailbox is selected using the
EXAMINEcommand.According to the IMAP specification, a mailbox opened with
EXAMINEmust be treated as read-only, meaning that any mutating operations should be restricted.However, the current implementation allows state-changing commands such as
EXPUNGEandCLOSEto proceed even when the mailbox is in read-only mode. This behavior is explicitly noted as a gap in:selection.go(CLOSE handling)message.go(EXPUNGE handling)Expected Behavior
When a mailbox is selected using
EXAMINE:🔴 EXPUNGE
NO)🔴 CLOSE
🔴 Other mutating commands (if applicable)
STORE,APPEND,COPY, etc., should also be reviewed and restricted if they modify mailbox stateCurrent Behavior
EXPUNGEexecutes even in read-only modeCLOSEmay remove messages despiteEXAMINEScope of Work
EXAMINEis usedSuggested Approach
1. Update mailbox/session state:
2. Add guard checks in mutating commands:
3. Audit all commands that modify mailbox state:
Acceptance Criteria
EXAMINEis strictly read-onlyEXPUNGEfails with appropriateNOresponseCLOSEdoes not remove messagesSELECT(read-write) remains unchangedAdditional Notes
References
- RFC 3501 — IMAP4rev1, Section 6.3.2 (EXAMINE Command)
# [TASK] Enforce read-only semantics for EXAMINE-selected mailboxesselection.go:223— CLOSE handling gap notedmessage.go:1575— EXPUNGE handling gap notedDescription
The current IMAP implementation does not enforce read-only semantics when a mailbox is selected using the
EXAMINEcommand.According to the IMAP specification, a mailbox opened with
EXAMINEmust be treated as read-only, meaning that any mutating operations should be restricted.However, the current implementation allows state-changing commands such as
EXPUNGEandCLOSEto proceed even when the mailbox is in read-only mode. This behavior is explicitly noted as a gap in:selection.go:223(CLOSE handling)message.go:1575(EXPUNGE handling)Expected Behavior
When a mailbox is selected using
EXAMINE:🔴 EXPUNGE
NO)🔴 CLOSE
🔴 Other mutating commands (if applicable)
STORE,APPEND,COPY, etc., should also be reviewed and restricted if they modify mailbox stateCurrent Behavior
EXPUNGEexecutes even in read-only modeCLOSEmay remove messages despiteEXAMINEScope of Work
EXAMINEis usedSuggested Approach
1. Update mailbox/session state:
2. Add guard checks in mutating commands:
3. Audit all commands that modify mailbox state:
EXPUNGENOin read-only modeCLOSESTORENOin read-only modeAPPENDNOin read-only modeCOPYAcceptance Criteria
EXAMINEis strictly read-onlyEXPUNGEfails with appropriateNOresponseCLOSEdoes not remove messagesSELECT(read-write) remains unchangedAdditional Notes
References
selection.go— CLOSE handling gap notedmessage.go— EXPUNGE handling gap noted