aboutsummaryrefslogtreecommitdiff
path: root/src/session.rs
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2022-06-13 18:01:07 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2022-06-13 18:01:07 +0200
commit12b379e7c3f832be5fd650ce3abc33b7d0b9fed8 (patch)
treed7c5e9dd63f54c90aae967fc0058d31b9deba120 /src/session.rs
parent7113809cb7b9f0e73d942b295e693675301d1565 (diff)
downloadaerogramme-12b379e7c3f832be5fd650ce3abc33b7d0b9fed8.tar.gz
aerogramme-12b379e7c3f832be5fd650ce3abc33b7d0b9fed8.zip
Handle select
Diffstat (limited to 'src/session.rs')
-rw-r--r--src/session.rs22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/session.rs b/src/session.rs
index 78d5ffc..d689e72 100644
--- a/src/session.rs
+++ b/src/session.rs
@@ -66,17 +66,21 @@ impl Manager {
}
}
+pub struct User {
+ pub name: String,
+ pub creds: Credentials,
+}
+
pub struct Instance {
rx: mpsc::Receiver<Message>,
pub mailstore: Arc<Mailstore>,
- pub creds: Option<Credentials>,
pub selected: Option<Mailbox>,
- pub username: Option<String>,
+ pub user: Option<User>,
}
impl Instance {
fn new(mailstore: Arc<Mailstore>, rx: mpsc::Receiver<Message>) -> Self {
- Self { mailstore, rx, creds: None, selected: None, username: None, }
+ Self { mailstore, rx, selected: None, user: None, }
}
//@FIXME add a function that compute the runner's name from its local info
@@ -96,12 +100,20 @@ impl Instance {
CommandBody::List { reference, mailbox_wildcard } => cmd.list(reference, mailbox_wildcard).await,
CommandBody::Select { mailbox } => cmd.select(mailbox).await,
CommandBody::Fetch { sequence_set, attributes, uid } => cmd.fetch(sequence_set, attributes, uid).await,
- _ => Response::bad("Error in IMAP command received by server."),
+ _ => Response::bad("Error in IMAP command received by server.").map_err(anyhow::Error::new),
};
+ let wrapped_res = res.or_else(|e| match e.downcast::<BalError>() {
+ Ok(be) => Err(be),
+ Err(ae) => {
+ tracing::warn!(error=%ae, "internal.error");
+ Response::bad("Internal error")
+ }
+ });
+
//@FIXME I think we should quit this thread on error and having our manager watch it,
// and then abort the session as it is corrupted.
- msg.tx.send(res).unwrap_or_else(|e| tracing::warn!("failed to send imap response to manager: {:#?}", e));
+ msg.tx.send(wrapped_res).unwrap_or_else(|e| tracing::warn!("failed to send imap response to manager: {:#?}", e));
}
//@FIXME add more info about the runner