-
Notifications
You must be signed in to change notification settings - Fork 86
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
Implement unsolicited message handling while IDLEing #130
Conversation
Fixes #128 |
I had to change around the logic for the "read_response" after "terminate" because there could've been multiple messages sent from the server, so we need to iterate over all of them, but I also need to know when to stop, and the only cue to stop is the |
I'm also not sure about making the unsolicited responses be empty by default, because I found it surprising. However, from an engineering perspective, it makes sense because if someone doesn't handle them then they build up in memory. This could be solved by a bounded channel with a sane default, as well, to impose an upper limit. For now, I think dumping all unsolicited responses unless otherwise requested is easier and works fine, though. |
The test failure appears to be unrelated to any code I wrote. |
had an error related to match being one shorter than the client expected. I'm wondering if me doing the matching for the |
FYI, I've been running this for the past week without any crashes or problems. I'm using it as my main ingestion pipeline for my mail now. |
I've been away on vacation for the past few weeks, so haven't had a chance to look. Will try to take a look once I get the time! Thanks for writing this up! :D |
@@ -46,7 +46,7 @@ where | |||
match map(resp)? { | |||
MapOrNot::Map(t) => things.push(t), | |||
MapOrNot::Not(resp) => match handle_unilateral(resp, unsolicited) { | |||
Some(Response::Fetch(..)) => continue, | |||
// Some(Response::Fetch(..)) => continue, |
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 this change?
} | ||
} | ||
Err(err) => return Err(err), | ||
Ok(_) => { |
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.
I don't understand this clause at all. Why do we need this nested loop construct? And why do we need to terminate the IDLE for each iteration?
@@ -202,7 +199,7 @@ pub fn parse_mailbox( | |||
if let imap_proto::Status::Ok = status { | |||
} else { | |||
// how can this happen for a Response::Data? | |||
unreachable!(); | |||
unreachable!("Received something other than OK from mailbox 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.
This should probably include status
for convenience.
return Err(Error::Bad(information.unwrap_or("").to_owned())) | ||
} | ||
imap_proto::Status::No => { | ||
return Err(Error::Bad(information.unwrap_or("").to_owned())) |
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.
Don't we also have Error::No
?
} | ||
Err(err) => return Err(err), | ||
Ok(_) => { | ||
let _ = parse::parse_idle(&buffer, &mut self.unsolicited_responses_tx)?; |
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.
Specifically, shouldn't this use the return value from parse_idle
to know whether or not DONE
was sent?
} | ||
Ok((rest, data)) => { | ||
lines = rest; | ||
if let Some(resp) = handle_unilateral(data, unsolicited) { |
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.
We should probably rename handle_unilateral
to try_handle_unilateral
to make it clearer that Some
is returned if it wasn't handled. That's orthogonal to your change though :)
Unseen(u32), | ||
} | ||
|
||
impl<'a> From<imap_proto::types::ResponseCode<'a>> for ResponseCode { |
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.
I wonder if ToOwned
is the trait to implement here.
// Set the new filter mask, and remove unwanted responses from the current queue. | ||
pub(crate) fn request( | ||
&mut self, | ||
receiver: &mpsc::Receiver<UnsolicitedResponse>, |
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.
I'm not sure I understand what this receiver is? Where does it come from?
mask: EnumSet<UnsolicitedResponseCategory>, | ||
) { | ||
self.allow = mask; | ||
for message in receiver.try_iter() { |
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.
This also seems pretty strange -- what about future messages? Are they never forwarded then?
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.
I copied a lot of stuff from the existing branch, assuming that it was already reviewed. About 20% of it is mine. Frankly, I might rewrite it. I've noticed that some messages are missed if they come in too quickly.
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.
Long time no see :) Did you ever get around to doing this rewrite?
Hi @norcalli -- a gentle ping on this :) |
@jonhoo hey sorry for the late reply, gonna take a look at this today. |
@norcalli just so you i'd be interested in your PR landing but my Rust-Fu is not good enough yet to help much. |
@norcalli Another gentle ping on this :) |
@norcalli I'd like to try to push out 3.0.0 soon — want to give this another stab? |
Replaced by #186. |
Adapted from #114
This change is![Reviewable](https://camo.githubusercontent.com/1541c4039185914e83657d3683ec25920c672c6c5c7ab4240ee7bff601adec0b/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)