Add some more commands
This commit is contained in:
parent
c03be0a8c3
commit
93f943aa80
2 changed files with 35 additions and 11 deletions
|
@ -2,23 +2,27 @@ use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use boitalettres::errors::Error as BalError;
|
use boitalettres::errors::Error as BalError;
|
||||||
use boitalettres::proto::{Request, Response};
|
use boitalettres::proto::{Request, Response};
|
||||||
use imap_codec::types::core::AString;
|
use imap_codec::types::core::{Tag, AString};
|
||||||
use imap_codec::types::response::{Capability, Data};
|
use imap_codec::types::response::{Capability, Data};
|
||||||
|
use imap_codec::types::mailbox::{Mailbox, ListMailbox};
|
||||||
|
use imap_codec::types::sequence::SequenceSet;
|
||||||
|
use imap_codec::types::fetch_attributes::MacroOrFetchAttributes;
|
||||||
|
|
||||||
use crate::mailstore;
|
use crate::mailstore::Mailstore;
|
||||||
use crate::service;
|
use crate::service::Session;
|
||||||
|
|
||||||
pub struct Command {
|
pub struct Command {
|
||||||
mailstore: Arc<mailstore::Mailstore>,
|
tag: Tag,
|
||||||
session: Arc<Mutex<service::Session>>,
|
mailstore: Arc<Mailstore>,
|
||||||
|
session: Arc<Mutex<Session>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Command {
|
impl Command {
|
||||||
pub fn new(mailstore: Arc<mailstore::Mailstore>, session: Arc<Mutex<service::Session>>) -> Self {
|
pub fn new(tag: Tag, mailstore: Arc<Mailstore>, session: Arc<Mutex<Session>>) -> Self {
|
||||||
Self { mailstore, session }
|
Self { tag, mailstore, session }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn capability(self) -> Result<Response, BalError> {
|
pub async fn capability(&self) -> Result<Response, BalError> {
|
||||||
let capabilities = vec![Capability::Imap4Rev1, Capability::Idle];
|
let capabilities = vec![Capability::Imap4Rev1, Capability::Idle];
|
||||||
let body = vec![Data::Capability(capabilities)];
|
let body = vec![Data::Capability(capabilities)];
|
||||||
let r = Response::ok("Pre-login capabilities listed, post-login capabilities have more.")?
|
let r = Response::ok("Pre-login capabilities listed, post-login capabilities have more.")?
|
||||||
|
@ -26,7 +30,7 @@ impl Command {
|
||||||
Ok(r)
|
Ok(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn login(self, username: AString, password: AString) -> Result<Response, BalError> {
|
pub async fn login(&self, username: AString, password: AString) -> Result<Response, BalError> {
|
||||||
let (u, p) = match (String::try_from(username), String::try_from(password)) {
|
let (u, p) = match (String::try_from(username), String::try_from(password)) {
|
||||||
(Ok(u), Ok(p)) => (u, p),
|
(Ok(u), Ok(p)) => (u, p),
|
||||||
_ => return Response::bad("Invalid characters"),
|
_ => return Response::bad("Invalid characters"),
|
||||||
|
@ -46,4 +50,20 @@ impl Command {
|
||||||
|
|
||||||
Response::ok("Logged in")
|
Response::ok("Logged in")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn lsub(&self, reference: Mailbox, mailbox_wildcard: ListMailbox) -> Result<Response, BalError> {
|
||||||
|
Response::bad("Not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn list(&self, reference: Mailbox, mailbox_wildcard: ListMailbox) -> Result<Response, BalError> {
|
||||||
|
Response::bad("Not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn select(&self, mailbox: Mailbox) -> Result<Response, BalError> {
|
||||||
|
Response::bad("Not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn fetch(&self, sequence_set: SequenceSet, attributes: MacroOrFetchAttributes, uid: bool) -> Result<Response, BalError> {
|
||||||
|
Response::bad("Not implemented")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,12 +61,16 @@ impl Service<Request> for Connection {
|
||||||
|
|
||||||
fn call(&mut self, req: Request) -> Self::Future {
|
fn call(&mut self, req: Request) -> Self::Future {
|
||||||
tracing::debug!("Got request: {:#?}", req);
|
tracing::debug!("Got request: {:#?}", req);
|
||||||
let cmd = command::Command::new(self.mailstore.clone(), self.session.clone());
|
let cmd = command::Command::new(req.tag, self.mailstore.clone(), self.session.clone());
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
match req.body {
|
match req.body {
|
||||||
CommandBody::Capability => cmd.capability().await,
|
CommandBody::Capability => cmd.capability().await,
|
||||||
CommandBody::Login { username, password } => cmd.login(username, password).await,
|
CommandBody::Login { username, password } => cmd.login(username, password).await,
|
||||||
_ => Response::bad("Error in IMAP command received by server."),
|
CommandBody::Lsub { reference, mailbox_wildcard } => cmd.lsub(reference, mailbox_wildcard).await,
|
||||||
|
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."),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue