Skip to content

imap: compare selected mailbox names case-sensitively - #22868

Closed
1rhino2 wants to merge 1 commit into
curl:masterfrom
1rhino2:imap-mailbox-case-sensitive
Closed

1rhino2 wants to merge 1 commit into
curl:masterfrom
1rhino2:imap-mailbox-case-sensitive

Conversation

@1rhino2

@1rhino2 1rhino2 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

When an authenticated IMAP connection is reused, libcurl checks whether the requested mailbox is already selected. The previous comparison was case-insensitive for every mailbox, so a request for private could reuse a connection with Private selected and skip SELECT.

RFC 9051 section 5.1 requires non-INBOX mailbox names to be case-sensitive. This changes the selected-mailbox check to compare exact names, while retaining case-insensitive handling for the reserved INBOX name.

The existing IMAP reuse test now covers a case-changing mailbox request and verifies that both SELECT commands are sent.

Closes HackerOne report #3976342.

Validation:

  • cmake --build /home/bobbeh/koth/loot/curl-mail-round2-20260828/build-master-clean -j2 passed.
  • git diff --check passed.
  • The focused test runner could not execute because this build lacks tests/server/servers and curlinfo; no test pass is claimed for that runner.

@github-actions github-actions Bot added the tests label Sep 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The mailbox selection reuse logic now matches RFC 9051’s case-sensitivity requirements (with correct INBOX exception) and the updated test explicitly verifies the intended behavioral change.

Pull request overview

This PR fixes IMAP connection reuse logic so libcurl only skips SELECT when the already-selected mailbox name matches exactly, except for the special INBOX mailbox which remains case-insensitive per RFC 9051. This prevents incorrect reuse when the requested mailbox differs only by case (e.g., Private vs private), which previously could result in operating on the wrong mailbox selection state.

Changes:

  • Make selected-mailbox reuse comparison case-sensitive for non-INBOX mailbox names in lib/imap.c.
  • Preserve case-insensitive handling specifically for INBOX.
  • Update the IMAP reuse test to cover a case-change mailbox request and verify that two SELECT commands are sent.
File summaries
File Description
lib/imap.c Updates the selected-mailbox equality check to be exact-match except for case-insensitive INBOX.
tests/data/test804 Adjusts the reuse regression test to request Private then private and validates both SELECTs occur.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@bagder bagder closed this in 12cfc83 Sep 8, 2026
@bagder

bagder commented Sep 8, 2026

Copy link
Copy Markdown
Member

Thanks!

vszakats added a commit that referenced this pull request Sep 28, 2026
A recent patch introduced a test using an irregular IMAP folder, which
isn't the test number, but a string, causing a Perl warning.

Fixing warnings in runtests log when running test 804:
```
Argument "" isn't numeric in numeric gt (>) at /home/runner/work/curl/curl/tests/ftpserver.pl line 445.
Argument "" isn't numeric in numeric gt (>) at /home/runner/work/curl/curl/tests/ftpserver.pl line 445.
```
Ref: https://github.com/curl/curl/actions/runs/36429133995/job/108950479015#step:50:1589

Follow-up to 12cfc83 #22868
Follow-up to 3a29ee4

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

Labels

Development

Successfully merging this pull request may close these issues.

3 participants