Start implementing other endpoints
This commit is contained in:
parent
93f943aa80
commit
cbcc339d50
3 changed files with 21 additions and 7 deletions
|
@ -4,11 +4,12 @@ use boitalettres::errors::Error as BalError;
|
||||||
use boitalettres::proto::{Request, Response};
|
use boitalettres::proto::{Request, Response};
|
||||||
use imap_codec::types::core::{Tag, 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::mailbox::{Mailbox as MailboxCodec, ListMailbox};
|
||||||
use imap_codec::types::sequence::SequenceSet;
|
use imap_codec::types::sequence::SequenceSet;
|
||||||
use imap_codec::types::fetch_attributes::MacroOrFetchAttributes;
|
use imap_codec::types::fetch_attributes::MacroOrFetchAttributes;
|
||||||
|
|
||||||
use crate::mailstore::Mailstore;
|
use crate::mailstore::Mailstore;
|
||||||
|
use crate::mailbox::Mailbox;
|
||||||
use crate::service::Session;
|
use crate::service::Session;
|
||||||
|
|
||||||
pub struct Command {
|
pub struct Command {
|
||||||
|
@ -43,23 +44,34 @@ impl Command {
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut session = match self.session.lock() {
|
let mut session = match self.session.lock() {
|
||||||
Err(_) => return Response::bad("[AUTHENTICATIONFAILED] Unable to acquire mutex."),
|
Err(_) => return Response::bad("[AUTHENTICATIONFAILED] Unable to acquire lock on session."),
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
};
|
};
|
||||||
session.creds = Some(creds);
|
session.creds = Some(creds);
|
||||||
|
drop(session);
|
||||||
|
|
||||||
Response::ok("Logged in")
|
Response::ok("Logged in")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn lsub(&self, reference: Mailbox, mailbox_wildcard: ListMailbox) -> Result<Response, BalError> {
|
pub async fn lsub(&self, reference: MailboxCodec, mailbox_wildcard: ListMailbox) -> Result<Response, BalError> {
|
||||||
Response::bad("Not implemented")
|
Response::bad("Not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn list(&self, reference: Mailbox, mailbox_wildcard: ListMailbox) -> Result<Response, BalError> {
|
pub async fn list(&self, reference: MailboxCodec, mailbox_wildcard: ListMailbox) -> Result<Response, BalError> {
|
||||||
Response::bad("Not implemented")
|
Response::bad("Not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn select(&self, mailbox: Mailbox) -> Result<Response, BalError> {
|
pub async fn select(&self, mailbox: MailboxCodec) -> Result<Response, BalError> {
|
||||||
|
|
||||||
|
let mut session = match self.session.lock() {
|
||||||
|
Err(_) => return Response::no("[SELECTFAILED] Unable to acquire lock on session."),
|
||||||
|
Ok(s) => s,
|
||||||
|
};
|
||||||
|
|
||||||
|
let mb = Mailbox::new(session.creds.as_ref().unwrap(), "TestMailbox".to_string()).unwrap();
|
||||||
|
session.selected = Some(mb);
|
||||||
|
drop(session);
|
||||||
|
|
||||||
Response::bad("Not implemented")
|
Response::bad("Not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ pub struct Mailbox {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Mailbox {
|
impl Mailbox {
|
||||||
pub async fn new(creds: &Credentials, name: String) -> Result<Self> {
|
pub fn new(creds: &Credentials, name: String) -> Result<Self> {
|
||||||
let uid_index = Bayou::<UidIndex>::new(creds, name.clone())?;
|
let uid_index = Bayou::<UidIndex>::new(creds, name.clone())?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
|
|
|
@ -12,6 +12,7 @@ use tower::Service;
|
||||||
use crate::command;
|
use crate::command;
|
||||||
use crate::login::Credentials;
|
use crate::login::Credentials;
|
||||||
use crate::mailstore::Mailstore;
|
use crate::mailstore::Mailstore;
|
||||||
|
use crate::mailbox::Mailbox;
|
||||||
|
|
||||||
pub struct Instance {
|
pub struct Instance {
|
||||||
pub mailstore: Arc<Mailstore>,
|
pub mailstore: Arc<Mailstore>,
|
||||||
|
@ -39,6 +40,7 @@ impl<'a> Service<&'a AddrStream> for Instance {
|
||||||
|
|
||||||
pub struct Session {
|
pub struct Session {
|
||||||
pub creds: Option<Credentials>,
|
pub creds: Option<Credentials>,
|
||||||
|
pub selected: Option<Mailbox>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Connection {
|
pub struct Connection {
|
||||||
|
@ -47,7 +49,7 @@ pub struct Connection {
|
||||||
}
|
}
|
||||||
impl Connection {
|
impl Connection {
|
||||||
pub fn new(mailstore: Arc<Mailstore>) -> Self {
|
pub fn new(mailstore: Arc<Mailstore>) -> Self {
|
||||||
Self { mailstore, session: Arc::new(Mutex::new(Session { creds: None })) }
|
Self { mailstore, session: Arc::new(Mutex::new(Session { creds: None, selected: None, })) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Service<Request> for Connection {
|
impl Service<Request> for Connection {
|
||||||
|
|
Loading…
Reference in a new issue