Skip to content

[TASK] Enforce read-only semantics for EXAMINE-selected mailboxes #250

Description

@Aravinda-HWK

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

  • Mailbox opened via EXAMINE is strictly read-only
  • EXPUNGE fails with appropriate NO response
  • CLOSE does not remove messages
  • No state mutation occurs in read-only mode
  • Behavior aligns with IMAP RFC expectations
  • Existing functionality for SELECT (read-write) remains unchanged

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

  • Mailbox opened via EXAMINE is strictly read-only
  • EXPUNGE fails with appropriate NO response
  • CLOSE does not remove messages
  • No state mutation occurs in read-only mode
  • Behavior aligns with IMAP RFC expectations
  • Existing functionality for SELECT (read-write) remains unchanged

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions