jonhoo / rust-imap

IMAP client library for Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Envelope parsing fails

kyazdani42 opened this issue · comments

commented

Hello,

I'm building a simple imap/maildir synchronizer, and i cannot manage to fetch the ENVELOPE.
with:

let messages = session.fetch("1:*", "(UID ENVELOPE)")?;

i get this error

I tried to follow the code, and i'm pretty sure it happens inside the read_response_onto function, in src/client.rs.
I can fetch the body, header and uid without running into any issues, and i'm trying to get data from this proxy which doesn't support TLS at the moment.
The session is initialized from a std::net::TcpStream passed into Client::new().

I don't really know IMAP well, and i'm not knowledgeable about stream parsing yet, so i could not go further with the debugging.

Thanks a lot for the great work you do for the rust community, i really appreciate it :) !

EDIT:
I ran the integration tests and those are working just fine, so i guess it might be an issue with the response from the imap proxy.

Hmm, that's interesting. It looks like it fails to parse this line from the server:

* 6 FETCH (UID 6 ENVELOPE ("Mon, 20 May 2019 14:03:14 +0200" "=?utf-8?q?Activation_de_votre_compte_sur_ALUMNI_42_|_Votre_communaut?= =?utf-8?q?=C3=A9_de__en_ligne?=" (("42 Alumni" NIL "alumni" "42.fr")) () () (("Kiyan Yazdani" NIL "yazdani.kiyan" "protonmail.com")) () () "" "c20696ea107c2a8a35cafa5fcd2966df@swift.generated"))

This seems like it's probably an issue with the IMAP protocol parser (imap-proto). cc @djc

It looks to me like this response does not adhere to the spec. In particular, RFC 3501 states:

address         = "(" addr-name SP addr-adl SP addr-mailbox SP
                  addr-host ")"

envelope        = "(" env-date SP env-subject SP env-from SP
                  env-sender SP env-reply-to SP env-to SP env-cc SP
                  env-bcc SP env-in-reply-to SP env-message-id ")"

env-bcc         = "(" 1*address ")" / nil

env-cc          = "(" 1*address ")" / nil

env-date        = nstring

env-from        = "(" 1*address ")" / nil

env-in-reply-to = nstring

env-message-id  = nstring

env-reply-to    = "(" 1*address ")" / nil

env-sender      = "(" 1*address ")" / nil

env-subject     = nstring

env-to          = "(" 1*address ")" / nil

nil             = "NIL"

Here, the fourth member of the envelope (which should be env-sender) is encoded as (), but the definition of env-sender is "(" 1*address ")" / nil: it's supposed to be either a single address or NIL -- if it starts with (, the parser expects an address specification similar to the one in env-from.

Huh, interesting, yes, I agree that the message does not appear to adhere to the spec.

@kyazdani42 This then seems like a bug with https://github.com/emersion/hydroxide, so I suggest you file a bug with them and point them here for the details :)

it's supposed to be either a single address

1* means at least one, but maybe more, I think. But yes, server bug.

1* means at least one, but maybe more, I think.

Correct -- imap-proto supports one or more addresses here.

commented

should be all good ! Closing this :)
thanks everyone