Skip to content

Add SORT command support (RFC 5256) #813

@odrobnik

Description

@odrobnik

Summary

Requesting implementation of the IMAP SORT command (RFC 5256) in swift-nio-imap.

Current state

Some groundwork already exists:

Component Status
Capability parsing Capability.context(.sort), Capability.sort(_:), SortKind
Response parsing SortData model + parseSortData in GrammarParser.swift (line ~2388)
Response encoding writeSortData in EncodeBuffer
Command encoding ❌ No .sort / .uidSort cases in Command enum
Sort criteria model ❌ No SortKey / SortCriterion type (DATE, FROM, SUBJECT, SIZE, etc.)
Command parser ❌ No parseSort in command parser

So the response side is ready, but there's no way to send a SORT command.

What's needed

  1. Sort criteria type — e.g. SortCriterion enum with cases for date, from, subject, to, cc, size, arrival, plus reverse(_:) modifier. RFC 5256 §3:

    sort-key = "ARRIVAL" / "CC" / "DATE" / "FROM" / "REVERSE" SP sort-key / "SIZE" / "SUBJECT" / "TO" / "DISPLAYFROM" / "DISPLAYTO"
    
  2. Command cases.sort and .uidSort on Command:

    case sort(criteria: [SortCriterion], charset: String, key: SearchKey, returnOptions: [SearchReturnOption])
    case uidSort(criteria: [SortCriterion], charset: String, key: SearchKey, returnOptions: [SearchReturnOption])
  3. Command encoding — Wire format: SORT (DATE REVERSE SUBJECT) UTF-8 UNSEEN

  4. Command parser (for server-side / testing) — Parse the SORT command from wire format.

Motivation

SORT is widely supported (iCloud, Dovecot, many others) and is the most-requested missing IMAP feature in our client library SwiftMail — see Cocoanetics/SwiftMail#11. The response-side support is already in place, so this is primarily about the command side.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions