-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add structured results for all values using imap-proto #58
Conversation
Great work. I'll test and review your branch too. |
src/error.rs
Outdated
&String::from(self.description()), | ||
&data.join("\n") | ||
), | ||
Error::NoResponse(ref data) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two patterns can be merged Error::NoResponse(ref data) | Error::BadResponse(ref data)
.
status => Err((status, None)), | ||
}) | ||
} | ||
IResult::Done(..) => None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IResult::Done(..) | IResult::Incomplete(..) =>
I'm testing this PR against a real-world Exchange server. The #[test]
fn parse_response() {
use imap_proto::parse_response;
let resp = parse_response(b"* 2 FETCH (BODY[TEXT] {6620}\r\n").unwrap();
eprintln!("{:?}", resp);
} Update: |
@sanmai-NL hmm, that looks like an issue for https://github.com/djc/imap-proto, no? |
That looks like an unbalanced parenthesis, or is that just the start of the message? What is the parser result you are expecting? It definitely doesn't look like a well-formed message. |
Ah, never mind, this just happens because |
djc/imap-proto@5b9dc9b adds support for |
@sanmai-NL can you confirm that the updated |
Not yet unfortunately. There's progress though:
It seems this can be resolved by not letting the IMAP protocol parser process actual data returned for a successful |
@sanmai-NL I'm not sure I understand what you mean -- can you elaborate? |
The IMAP protocol parser cannot parse "Content-Transfer-Encoding: quoted-printable". That seems logical, since that's actual data not protocol messages. |
Ahh, I see, it's trying to parse the contents of the |
No, that's not the case. |
You can use @staktrace's |
@sanmai-NL that doesn't seem right -- The one place I could see this error stemming from is if I don't think this library should be responsible for parsing message responses. Instead, just the raw bytes of the body should be returned. Currently, this is only exposed through RFC822 responses (under the |
@jonhoo: Yes I like your take on it better. It is indeed the responsibility of Also agree that it's better if |
It seems like you're talking past each other. It seems to me neither |
@djc, |
@sanmai-NL |
@djc, yeah, that's what it means. @jonhoo: As @djc suggests there's still some work to do around |
You should probably not rely on line endings anymore. Instead, keep a buffer and (a) grow it if the parser returns Incomplete, and (b) split it if the parser returns Done. BytesMut from the bytes crate should help doing this efficiently. |
I believe this should be fixed in 5a3ee10. |
In my test everything works. 🙂 |
@mattnenterprise I believe this is now in the state where it can be reviewed and merged. It does change the API a fair bit, so it will require a major version bump, but I think it's the right direction to take the interface in. |
@jonhoo: I’m trying to review -- haven’t done that before. I just started a review but it appears I only get to see an old revision, in which I so far am not able to get the |
I think the easiest way to review is to go to the "Files changed" tab, and then start adding comments. When you add the first comment, you can select "start a review", and then you can use the "Review changes" button in the top right to approve/reject the change at the end..
I'm not sure what you mean by the "IMAP response message"? The PR in its current form does not actually parse out |
@jonhoo:
What I meant is that it appears as though the IMAP response is being parsed and returned, yet not the You pointed out the Ok([Fetch { message: 1, flags: [], uid: None, rfc822: None }]) Update: The seems to be due to a difference in Another problem is that the |
Confirmed: |
@sanmai-NL the code (and |
ping @mattnenterprise again |
Cargo.toml
Outdated
@@ -28,6 +28,9 @@ path = "src/lib.rs" | |||
native-tls = "0.1" | |||
regex = "0.2" | |||
bufstream = "0.1" | |||
#imap-proto = "0.1" | |||
imap-proto = { git = "https://github.com/djc/imap-proto.git" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this use the git repo for this dependency instead of the one at crates.io ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, the required changes from imap-proto
have since been released. Removed in e687e85
ping @mattnenterprise |
@jonhoo Why did the coverage go to 0% ? Also this looks good to merge once that gets figured out. |
Coverage went to 0% because of a Travis CI change: travis-ci/travis-ci#9061. The fix is to add Do note that this significantly changes the API, so a major version bump would be needed. |
Tests currently fail due to djc/imap-proto#2. LSUB is also broken due to djc/imap-proto#4 (but we don't have tests for that atm).
All tests now pass
I have bumped it from 0.6.0 -> 0.7.0 as we are still on major version zero. If we believe the API should be considered stable now then we can always bump up to 1.0.0. |
@mattnenterprise I don't know that the |
This PR modifies all methods on
Client
that return data from the server so that they return it in a structured format instead of as raw, multi-line strings. The resulting interface is much less error-prone, and saves clients from doing parsing themselves, as outlined in #28. It does this by usingimap-proto
to parse the server responses and then constructing appropriate types.This PR does not yet provide a non-UTF-8 API (#54), as that will depend on the resolution to djc/imap-proto#5. It does, however, fix #28.
One particularly important thing introduced in this PR is the
ZeroCopy
type (insrc/types/mod.rs
), and it's a little finicky, so it deserves some special attention.imap-proto
returns values that point into the original bytes that were parsed. This allows it to not copy strings and other large values unnecessarily. However, it also means that it's tricky to expose those values outside of aClient
(since the lifetime of the returned reference would be ill-defined).ZeroCopy
is a way around that, and operates similar to theowning-ref
crate. It stores aVec<u8>
, and its parsed output, inside a single struct, and then derefs to the parsed struct. This is safe as long as the parsed struct never gives out references that outlive&self
. Essentially, all accessor methods must be of the form: