jonhoo / rust-imap

IMAP client library for Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Client::status does not work

comex opened this issue · comments

commented

Client::status does not parse the response correctly and always returns a default Mailbox object.

Suppose I call session.status("INBOX", "(UIDNEXT UIDVALIDITY)"). This causes the following to be sent:

a2 STATUS "INBOX" (UIDNEXT UIDVALIDITY)

The server (Dovecot) responds:

* STATUS INBOX (UIDNEXT 7 UIDVALIDITY 1616297529)

Client::status calls parse_mailbox, which parses the above into the following imap_proto::Response:

MailboxData(Status { mailbox: "INBOX", status: [UidNext(7), UidValidity(1616297529)] }))

But parse_mailbox only accepts these attributes if seen as a ResponseCode within Response::Data. When it encounters a Response::MailboxData containing MailboxDatum::Status, it always treats it as unsolicited:

            Ok((rest, Response::MailboxData(m))) => {
                lines = rest;

                match m {
                    MailboxDatum::Status { mailbox, status } => {
                        unsolicited
                            .send(UnsolicitedResponse::Status {
                                mailbox: mailbox.into(),
                                attributes: status,
                            })
                            .unwrap();
                    }

Yup, you're exactly right — a STATUS response can only be returned as part of a STATUS command, and never as a unilateral response (RFC ref). Want to take a stab at fixing this up in a PR?