stalwartlabs / jmap-client

JMAP client library for Rust
Apache License 2.0
64 stars 8 forks source link

Support "Scheduled" role, or generic string roles #7

Closed kahnclusions closed 1 year ago

kahnclusions commented 1 year ago

First I wanted to say this is a really awesome project! I've been testing against Fastmail's API and I noticed they add a non-standard "Scheduled" mailbox role that causes the parsing to fail. It would be nice to support this role, or support generic string roles in addition to the defined Roles.

You can send the following request to https://api.fastmail.com/jmap/api/ and see the roles returned:

{
  "using": [
    "urn:ietf:params:jmap:core",
    "urn:ietf:params:jmap:mail"
  ],
  "methodCalls": [[
    "Mailbox/get",
    {
      "accountId": "redacted",
      "ids": null,
      "properties": ["role"]
    },
    "0"
  ]]
}
{
  "methodResponses": [
    [
      "Mailbox/get",
      {
        "list": [
          {
            "role": "inbox",
            "id": "redacted"
          },
          {
            "role": "archive",
            "id": "redacted"
          },
          {
            "role": "drafts",
            "id": "redacted"
          },
          {
            "role": "scheduled", <--- this one
            "id": "redacted"
          },
          {
            "id": "redacted",
            "role": "sent"
          },
          {
            "role": "junk",
            "id": "redacted"
          },
          {
            "role": "trash",
            "id": "redacted"
          }
        ],
        "state": "11870",
        "accountId": "redacted",
        "notFound": []
      },
      "0"
    ]
  ],
  "sessionState": "redacted",
  "latestClientVersion": ""
}

An easy solution is to add support for the Scheduled role, but it might be more forward-thinking to support arbitrary string roles in addition to the "standard" ones.

https://github.com/stalwartlabs/jmap-client/blob/main/src/mailbox/mod.rs#L116-L135

#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default)]
#[serde(rename_all = "lowercase")]
pub enum Role {
    ...
    #[serde(rename = "scheduled", alias = "SCHEDULED")]
    Scheduled,
    ...
}
mdecimus commented 1 year ago

Hi,

It seems that Fastmail is generating non-compliant responses according to RFC8621:

      The value MUST be one of the Mailbox attribute names listed in the
      IANA "IMAP Mailbox Name Attributes" registry at
      <https://www.iana.org/assignments/imap-mailbox-name-attributes/>,
      as established in [[RFC8457](https://datatracker.ietf.org/doc/html/rfc8457)], converted to lowercase.

I have just checked the list and scheduled is not a IANA registered mailbox attribute.

In any case, I have just released version 0.3.0 which deserializes unknown roles as Role::Other(String).

kahnclusions commented 1 year ago

Cool, that solves the issue 👍