From c127c5ca2445d2351f90dee2c15e440d34e080fe Mon Sep 17 00:00:00 2001 From: Rodolphe Breard Date: Sat, 5 Jan 2019 16:28:51 +0100 Subject: [PATCH] Close sessions once the disconnect events shows up --- src/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 9e9c0ca..4908559 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -79,7 +79,9 @@ impl SmtpIn { /// already exists, creates it. fn dispatch(&mut self, input: &str) -> Result<(), Error> { let entry = Entry::from_str(input)?; - let channel = match self.sessions.get(&entry.session_id) { + let id = entry.session_id; + let disconnect = entry.event == Event::LinkDisconnect; + let channel = match self.sessions.get(&id) { Some((r, _)) => r, None => { let (handlers_tx, handlers_rx) = mpsc::channel(); @@ -97,6 +99,9 @@ impl SmtpIn { } }; channel.send(entry)?; + if disconnect { + let _ = self.sessions.remove(&id); + } Ok(()) }