JMAP keywords are stored and returned with their original case: "Foo" and "foo" become two keywords

Issue Description

Custom keywords keep the case they were written with. The same keyword in upper and lower case ends up as two different keywords on one message, hasKeyword matches only the exact case, and JMAP returns mixed-case keywords. IMAP clients that use capitalised flags therefore create “duplicate” labels for JMAP clients, and removing a label by its lowercase name leaves the capitalised one behind.

Expected Behavior

RFC 8621, section 4.1.1: “For compatibility with IMAP, a keyword is a case-insensitive string … Because JSON is case sensitive, servers MUST return keywords in lowercase.”

So Pm.Remind.T0900 and pm.remind.t0900 are the same keyword, it is returned as pm.remind.t0900, and hasKeyword matches it in any case.

Actual Behavior

  1. Import a message with "keywords": {"Pm.Remind.T0900": true}:
["Email/import", {"accountId": "c", "emails": {"i": {"blobId": "...", "mailboxIds": {"a": true},
  "keywords": {"Pm.Remind.T0900": true}}}}, "i"]
  1. Query and read it:
Request Result
Email/query {"hasKeyword": "pm.remind.t0900"} not found
Email/query {"hasKeyword": "Pm.Remind.T0900"} found
Email/get keywords {"Pm.Remind.T0900": true}
  1. Add the lowercase form:
curl -s -u "[email protected]:$PASS1" -H 'Content-Type: application/json' https://mail.example.com/jmap/ -d '{
  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
  "methodCalls": [
    ["Email/set", {"accountId": "c", "update": {"qiaaaaec": {"keywords/pm.remind.t0900": true}}}, "u"],
    ["Email/get", {"accountId": "c", "ids": ["qiaaaaec"], "properties": ["keywords"]}, "g"]]}'
{"methodResponses": [
  ["Email/set", {"accountId": "c", "oldState": "srqca", "newState": "sruca", "updated": {"qiaaaaec": null}}, "u"],
  ["Email/get", {"accountId": "c", "state": "sruca", "list": [{"keywords": {"pm.remind.t0900": true,
    "Pm.Remind.T0900": true}, "id": "qiaaaaec"}], "notFound": []}, "g"]]}

Two keywords on one message where the RFC expects one.

Reproduction Steps

The exact requests and responses are under Actual Behavior.

Stalwart Version

v0.16.x

Installation Method

Docker

Database Backend

RocksDB

Blob Storage

RocksDB

Search Engine

Internal

Directory Backend

Internal

Additional Context

Where it seems to come from:

crates/types/src/keyword.rs: Keyword::parse(), from_other() and from_boxed_other() keep Keyword::Other as given. Lowercasing Other values there (and treating existing mixed-case stored values as equal on read) would follow the RFC. Two smaller related points in the same file:

  • the system keywords $MailFlagBit0..2 serialize in mixed case, which is also returned to JMAP clients;
  • MAX_LENGTH is 128, while RFC 8621 allows 1-255 characters.

Stalwart v0.16.27, Docker image stalwartlabs/stalwart:v0.16-alpine, default setup from the bootstrap wizard.

I have reviewed the documentation and FAQ and confirm that my issue is NOT addressed there.

on

I have searched this support forum (open and closed topics) and confirm this is not a duplicate.

on

I understand that topics in this category are triaged by a bot first but a human reply will follow up. If I’d prefer a human-only reply, I’ll add the no-ai tag to my topic.

on

This is an accurate bug report confirming behavior that deviates from RFC 8621’s case-insensitive/lowercase requirement for keywords, and the code you cited (Keyword::parse, from_other, from_boxed_other in crates/types/src/keyword.rs) matches what’s in the current source, i.e. Other values are stored verbatim without lowercasing.

Thanks for the detailed report and source pointers. This is a legitimate bug against RFC 8621 behavior (keywords should be case-insensitive and returned in lowercase), confirmed in the current source you referenced. I can’t fix or triage this myself, so I’ll leave it for a human maintainer to review and respond.

This is an automated reply from the Stalwart Help Bot. Other community members may follow up if this answer is incomplete or wrong.

Fixed in v1.0.0, expected this week.