From 7113809cb7b9f0e73d942b295e693675301d1565 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Mon, 13 Jun 2022 12:25:19 +0200 Subject: Improve SELECT --- src/command.rs | 14 +++++++++++++- src/mailbox.rs | 2 +- src/session.rs | 3 ++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/command.rs b/src/command.rs index a9b39e4..0b576b2 100644 --- a/src/command.rs +++ b/src/command.rs @@ -41,7 +41,9 @@ impl<'a> Command<'a> { }; self.session.creds = Some(creds); + self.session.username = Some(u.clone()); + tracing::info!(username=%u, "connected"); Response::ok("Logged in") } @@ -54,10 +56,20 @@ impl<'a> Command<'a> { } pub async fn select(&mut self, mailbox: MailboxCodec) -> Result { + let (name, creds) = match (String::try_from(mailbox), self.session.creds.as_ref()) { + (Ok(n), Some(c)) => (n, c), + (_, None) => return Response::no("You must be connected to use SELECT"), + (Err(e), _) => { + tracing::warn!("Unable to decode mailbox name: {:#?}", e); + return Response::bad("Unable to decode mailbox name") + }, + }; - let mb = Mailbox::new(self.session.creds.as_ref().unwrap(), "TestMailbox".to_string()).unwrap(); + let mb = Mailbox::new(creds, name.clone()).unwrap(); self.session.selected = Some(mb); + let user = self.session.username.as_ref().unwrap(); + tracing::info!(username=%user, mailbox=%name, "mailbox-selected"); Response::bad("Not implemented") } diff --git a/src/mailbox.rs b/src/mailbox.rs index 204b487..af71b91 100644 --- a/src/mailbox.rs +++ b/src/mailbox.rs @@ -10,7 +10,7 @@ use crate::uidindex::*; pub struct Mailbox { bucket: String, - name: String, + pub name: String, key: Key, k2v: K2vClient, diff --git a/src/session.rs b/src/session.rs index 4e8b301..78d5ffc 100644 --- a/src/session.rs +++ b/src/session.rs @@ -72,10 +72,11 @@ pub struct Instance { pub mailstore: Arc, pub creds: Option, pub selected: Option, + pub username: Option, } impl Instance { fn new(mailstore: Arc, rx: mpsc::Receiver) -> Self { - Self { mailstore, rx, creds: None, selected: None, } + Self { mailstore, rx, creds: None, selected: None, username: None, } } //@FIXME add a function that compute the runner's name from its local info -- cgit v1.2.3